2019-04-22 22:41:37 -04:00
|
|
|
; stdio
|
|
|
|
;
|
2019-06-02 10:50:18 -04:00
|
|
|
; Allows other modules to print to "standard out", and get data from "stamdard
|
|
|
|
; in", that is, the console through which the user is connected in a decoupled
|
|
|
|
; manner.
|
2019-04-22 22:41:37 -04:00
|
|
|
;
|
|
|
|
; *** VARIABLES ***
|
|
|
|
; Used to store formatted hex values just before printing it.
|
2019-05-17 15:43:44 -04:00
|
|
|
.equ STDIO_HEX_FMT STDIO_RAMSTART
|
|
|
|
.equ STDIO_GETC STDIO_HEX_FMT+2
|
|
|
|
.equ STDIO_PUTC STDIO_GETC+2
|
|
|
|
.equ STDIO_RAMEND STDIO_PUTC+2
|
2019-05-17 08:14:19 -04:00
|
|
|
|
2019-06-02 10:50:18 -04:00
|
|
|
; Sets GetC to the routine where HL points to and PutC to DE.
|
2019-05-17 08:14:19 -04:00
|
|
|
stdioInit:
|
|
|
|
ld (STDIO_GETC), hl
|
2019-06-02 10:50:18 -04:00
|
|
|
ld (STDIO_PUTC), de
|
2019-05-17 08:14:19 -04:00
|
|
|
ret
|
|
|
|
|
|
|
|
stdioGetC:
|
|
|
|
ld ix, (STDIO_GETC)
|
|
|
|
jp (ix)
|
|
|
|
|
|
|
|
stdioPutC:
|
|
|
|
ld ix, (STDIO_PUTC)
|
|
|
|
jp (ix)
|
2019-04-22 22:41:37 -04:00
|
|
|
|
|
|
|
; print null-terminated string pointed to by HL
|
|
|
|
printstr:
|
|
|
|
push af
|
|
|
|
push hl
|
|
|
|
|
|
|
|
.loop:
|
|
|
|
ld a, (hl) ; load character to send
|
|
|
|
or a ; is it zero?
|
|
|
|
jr z, .end ; if yes, we're finished
|
2019-05-17 08:14:19 -04:00
|
|
|
call stdioPutC
|
2019-04-22 22:41:37 -04:00
|
|
|
inc hl
|
|
|
|
jr .loop
|
|
|
|
|
|
|
|
.end:
|
|
|
|
pop hl
|
|
|
|
pop af
|
|
|
|
ret
|
|
|
|
|
|
|
|
; print A characters from string that HL points to
|
|
|
|
printnstr:
|
|
|
|
push bc
|
|
|
|
push hl
|
|
|
|
|
|
|
|
ld b, a
|
|
|
|
.loop:
|
|
|
|
ld a, (hl) ; load character to send
|
2019-05-17 08:14:19 -04:00
|
|
|
call stdioPutC
|
2019-04-22 22:41:37 -04:00
|
|
|
inc hl
|
|
|
|
djnz .loop
|
|
|
|
|
|
|
|
.end:
|
|
|
|
pop hl
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|
|
|
|
printcrlf:
|
|
|
|
ld a, ASCII_CR
|
2019-05-17 08:14:19 -04:00
|
|
|
call stdioPutC
|
2019-04-22 22:41:37 -04:00
|
|
|
ld a, ASCII_LF
|
2019-05-17 08:14:19 -04:00
|
|
|
call stdioPutC
|
2019-04-22 22:41:37 -04:00
|
|
|
ret
|
|
|
|
|
|
|
|
; Print the hex char in A
|
|
|
|
printHex:
|
|
|
|
push af
|
|
|
|
push hl
|
|
|
|
ld hl, STDIO_HEX_FMT
|
|
|
|
call fmtHexPair
|
|
|
|
ld a, 2
|
|
|
|
call printnstr
|
|
|
|
pop hl
|
|
|
|
pop af
|
|
|
|
ret
|
|
|
|
|
2019-04-23 13:29:16 -04:00
|
|
|
; Print the hex pair in HL
|
|
|
|
printHexPair:
|
|
|
|
push af
|
|
|
|
ld a, h
|
|
|
|
call printHex
|
|
|
|
ld a, l
|
|
|
|
call printHex
|
|
|
|
pop af
|
|
|
|
ret
|