]> Joshua Wise's Git repositories - fpgaboy.git/blobdiff - serial.inc
ARP responder
[fpgaboy.git] / serial.inc
diff --git a/serial.inc b/serial.inc
new file mode 100644 (file)
index 0000000..c3ca090
--- /dev/null
@@ -0,0 +1,100 @@
+PUTC: MACRO
+       ld a, \1
+       call putc
+       ENDM
+
+PUTS: MACRO
+       ld hl, \1
+       call puts
+       ENDM
+
+PUTSI: MACRO
+       push hl
+       call putsi
+       db \1, 0
+       pop hl
+       ENDM
+
+PUTSIL: MACRO
+       push hl
+       call putsi
+       db \1, 13, 10, 0
+       pop hl
+       ENDM
+
+PUTHEX: MACRO
+       ld a, \1
+       call puthex
+       ENDM
+
+       SECTION "serial", HOME
+
+putc:
+       push af
+.waitport:
+       ld a,[$FF53]
+       and $01
+       jr nz,.waitport
+       pop af
+       ld [$FF52],a
+       ret
+
+puts:
+       ld a, [hli]
+       cp $00
+       ret z
+       call putc
+       jr puts
+
+EX_SP_HL: MACRO
+       push de
+       di
+       add sp, 2
+       pop de
+       push hl
+       ld l, e
+       ld h, d
+       add sp, -2
+       ei
+       pop de
+       ENDM
+
+putsi:
+       pop hl
+       push af
+       push bc
+       push de
+.lp:   ld a, [hli]
+       or a
+       jr z, .done
+       call putc
+       jr .lp
+.done: pop de
+       pop bc
+       pop af
+       push hl
+       ret
+
+puthex:                                ; Put two hex nibbles to the serial console.
+       push bc
+       push hl
+       push af
+       swap a
+       and $0F
+       ld hl,hex
+       ld b,0
+       ld c,a
+       add hl,bc
+       ld a, [hl]
+       call putc
+       pop af
+       and $0F
+       ld hl,hex
+       ld c,a
+       add hl,bc
+       ld a, [hl]
+       call putc
+       pop hl
+       pop bc
+       ret
+hex:   db "0123456789ABCDEF"
This page took 0.024325 seconds and 4 git commands to generate.