#RVController ecall C Library - Assembly Portion
#A product of Advanced Mesecons Devices, a Cheapie Systems company
#This is free and unencumbered software released into the public domain.
#See http://unlicense.org/ for more information

printint:
# Number to print is already in a0
li a7,1 # Write number
ecall
ret

printstr:
# String address is already in a0
li a7,4
ecall
ret

printchar:
# Character is already in a0
li a7,11
ecall
ret

digiline_send:
# Channel pointer is already in a0, message pointer is already in a1
li a7,129
ecall
ret

digiline_bufferlevel:
li a7,133
ecall
# Result is already in a0
ret

digiline_receive:
# Arguments are already in a0-a3
li a7,135
ecall
ret

rdtime:
rdtime a0
ret

rdcycle:
rdcycle a0
ret

digiline_clearbuffer:
li a7,134
ecall
ret

lightweight_mode:
andi a0,a0,1
csrrs t0,0x800,x0
bclri t0,t0,0
or t0,t0,a0
csrrw x0,0x800,t0
ret

readint:
li a7,5
ecall
# Result is already in a0
ret

randomint:
li a7,128
# Arguments are already in a0 and a1
ecall
# Result is already in a0
ret

readstr:
li a7,8
# Arguments are already in a0 and a1
ecall
# Result is already in a0
ret

console_clearbuffer:
li a7,131
ecall
ret

console_readchar:
li a7,132
ecall
# Result is already in a0
ret

.globl printint
.globl printstr
.globl printchar
.globl digiline_send
.globl digiline_bufferlevel
.globl digiline_receive
.globl rdtime
.globl rdcycle
.globl digiline_clearbuffer
.globl lightweight_mode
.globl readint
.globl randomint
.globl readstr
.globl console_clearbuffer
.globl console_readchar
