diff options
Diffstat (limited to 'assembly/rrxing2/util.S')
| -rw-r--r-- | assembly/rrxing2/util.S | 24 |
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 |
