summaryrefslogtreecommitdiff
path: root/assembly/rrxing2/util.S
diff options
context:
space:
mode:
authorcheapie <cheapiephp@gmail.com>2026-11-06 09:36:50 -0600
committercheapie <cheapiephp@gmail.com>2026-11-06 09:36:50 -0600
commit799584fe24f68372c9c39f75006ae518243e3013 (patch)
tree10f441668111f2116e6da47d2dbd259c0e3643a7 /assembly/rrxing2/util.S
parent747374b7e56717d39d6f5dbef7e1c04cbf0c5355 (diff)
downloadrvcontroller-799584fe24f68372c9c39f75006ae518243e3013.tar
rvcontroller-799584fe24f68372c9c39f75006ae518243e3013.tar.gz
rvcontroller-799584fe24f68372c9c39f75006ae518243e3013.tar.bz2
rvcontroller-799584fe24f68372c9c39f75006ae518243e3013.tar.xz
rvcontroller-799584fe24f68372c9c39f75006ae518243e3013.zip
More rrxing2 work
Diffstat (limited to 'assembly/rrxing2/util.S')
-rw-r--r--assembly/rrxing2/util.S24
1 files changed, 24 insertions, 0 deletions
diff --git a/assembly/rrxing2/util.S b/assembly/rrxing2/util.S
index 9dda1ab..4d55c6b 100644
--- a/assembly/rrxing2/util.S
+++ b/assembly/rrxing2/util.S
@@ -1,3 +1,8 @@
+# Railroad Crossing 2 for RVController - Utility Functions and Macros
+# A product of Scheiße & Broken Signalling Systems, a Cheapie Systems company
+# This is free and unencumbered software released into the public domain.
+# See http://unlicense.org/ for more information
+
.macro digiline_send channel msg
la a0,(\channel)
la a1,(\msg)
@@ -33,6 +38,7 @@
.endm
set_timer:
+# Expects a number of seconds in a0
li t0,0x80
csrs mie,t0 # unmask timer interrupt
ld t1,2(gp) # read mtime
@@ -41,3 +47,21 @@ sltu t0,t1,a0 # check if it overflowed
add t2,t2,t0 # add the overflow into the high half if there was any
sd t1,10(gp) # set mtimecmp to the target value
ret
+
+hexdump:
+# Expects a pointer to the output location in a0 and a number in a1, always outputs 8 digits
+li t0,7
+1: li t1,0xf
+slli t2,t0,2 # Multiply digit number by 4 to get shift amount
+sll t1,t1,t2 # Shift mask over to the necessary digit
+and t1,t1,a1 # Get the necessary digit
+srl t1,t1,t2 # Move it to the ones place
+addi t1,t1,0x30 # Try converting it to an ASCII digit
+li t2,0x3a
+blt t1,t2,2f # If it's out of range...
+addi t1,t1,7 # ...turn it into a letter
+2: sb t1,0(a0) # Write out the digit
+addi a0,a0,1 # Advance the pointer
+addi t0,t0,-1
+bgez t0,1b
+ret