collapseos/parts/z80/stdio.asm

78 lines
1.1 KiB
NASM
Raw Normal View History

2019-04-22 22:41:37 -04:00
; stdio
;
; Allows other modules to print to "standard out", that is, the console through
; which the user is connected in a decoupled manner.
;
; *** REQUIREMENTS ***
; STDIO_GETC: a macro that follows GetC API
; STDIO_PUTC: a macro that follows GetC API
; *** VARIABLES ***
; Used to store formatted hex values just before printing it.
STDIO_HEX_FMT .equ STDIO_RAMSTART
STDIO_RAMEND .equ STDIO_HEX_FMT+2
; 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
STDIO_PUTC
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
STDIO_PUTC
inc hl
djnz .loop
.end:
pop hl
pop bc
ret
printcrlf:
ld a, ASCII_CR
STDIO_PUTC
ld a, ASCII_LF
STDIO_PUTC
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