stack-machine/asm/lib/rs232.txt

55 lines
886 B
Plaintext

include "../include/memory-map.txt"
# Read from serial port w/ remote echo. Ignores CRs.
#
# char read_char()
# {
# uint32_t in;
# char c;
#
# do {
# while (((in = *(uint32_t*)rs232_fifo) & 0x100) == 0)
# /* wait for input */;
# c = in & 0xff;
# } while (c == '\r');
#
# write_char(c);
# return c;
# }
read_char:
immed rs232_fifo
load
dup; immed 0x100; and
jump .got_char rel ne drop
jump read_char rel drop
.got_char:
immed 0xff; and
dup; immed 13; sub
jump .ignore_cr rel eq drop
dup
call write_char
return
.ignore_cr:
jump read_char rel drop
write_char:
dup; immed 10; sub
jump .not_nl rel ne drop
immed 13
pushpc
.not_nl:
immed rs232_status
load byte; immed 2; and
jump .not_nl rel ne drop
immed rs232_fifo
store byte
return
newline:
immed 10
jump write_char
# ^^^ Tail call