summaryrefslogtreecommitdiff
path: root/z180/msgbuf-s.180
diff options
context:
space:
mode:
authorLeo C2014-10-23 02:22:01 +0200
committerLeo C2014-10-23 02:22:01 +0200
commit6a4e9540b950d871ea8fa072b195490a231b251d (patch)
tree2078c1bcf0abe120c28f0e0f9a1404162bb29c85 /z180/msgbuf-s.180
parent424b184a9bab3b1b8fe93fbc9e8a6e9d566904c8 (diff)
downloadz180-stamp-6a4e9540b950d871ea8fa072b195490a231b251d.zip
new fifos msg in, msg out, console in, console out
Diffstat (limited to 'z180/msgbuf-s.180')
-rw-r--r--z180/msgbuf-s.180129
1 files changed, 129 insertions, 0 deletions
diff --git a/z180/msgbuf-s.180 b/z180/msgbuf-s.180
new file mode 100644
index 0000000..2c67527
--- /dev/null
+++ b/z180/msgbuf-s.180
@@ -0,0 +1,129 @@
+ page 255
+ .z80
+
+ global msg_fifo
+ global msginit
+ global msg.out,msg.sout,msg.co
+
+ extrn buf.init
+
+ include config.inc
+ include z180reg.inc
+
+;--------------------------------------------------------------
+
+ dseg
+
+ mkbuf msg_fifo, 0
+
+
+;--------------------------------------------------------------
+
+ cseg
+
+;
+; Init buffer
+;
+
+msginit:
+ ld ix,msg_fifo
+ ld a,msg_fb_len-1
+ jp buf.init
+
+
+;--------------------------------------------------------------
+
+msg.sts:
+ push ix
+ ld ix,msg_fifo ;
+
+ ld a,(ix+o.in_idx) ;
+ inc a
+ and (ix+o.mask)
+ sub (ix+o.out_idx) ;
+ pop ix
+ ret z
+ or 0ffh
+ ret
+
+;--------------------------------------------------------------
+
+msg.out:
+ push ix
+ ld ix,msg_fifo ;
+
+ push bc
+ ld b,a ;save char
+ ld a,(ix+o.in_idx) ;
+ inc a
+ and (ix+o.mask)
+bp.wait:
+ cp (ix+o.out_idx) ;
+ jr z,bp.wait
+ ld c,a
+ ld a,b
+ out (PMSG),a
+ ld (ix+o.in_idx),c
+
+ pop bc
+ pop ix
+ ret
+
+;--------------------------------------------------------------
+;
+; (hl): data
+
+msg.sout:
+ push ix
+ ld ix,msg_fifo ;
+ push bc
+
+ ld b,(hl) ;count
+ inc hl
+obs_1:
+ ld a,(ix+o.out_idx) ;
+ sub (ix+o.in_idx) ;
+ dec a
+ and (ix+o.mask)
+ cp b
+ jr c,obs_1
+
+ ld c,(hl) ;port address
+ inc hl
+ ld a,b
+ otir
+ add (ix+o.in_idx)
+ and (ix+o.mask)
+ ld (ix+o.in_idx),a
+ pop bc
+ pop ix
+ ret
+
+;----------------------------------------------------------------------
+
+msg.co:
+ push af
+ push hl
+ ld (buf_char),a
+ ld hl,buf
+ call msg.sout
+ pop hl
+ pop af
+ ret
+
+
+buf:
+ db buf_end - $ - 2 ;output string length
+ db PMSG ;output port
+ db 081h ; message start token
+ db buf_end - $ - 1 ; message length
+ db 1 ; command
+ db 1 ; subcommand
+buf_char:
+ db 0 ; pay load
+buf_end:
+
+;----------------------------------------------------------------------
+
+ end
+