]> cloudbase.mooo.com Git - z180-stamp.git/blob - z180/msgbuf.180
my_getchar() parameter: allow return without new character
[z180-stamp.git] / z180 / msgbuf.180
1 page 255
2 .z80
3
4 global msg_fifo
5 global msginit
6 global msg.out,msg.sout,msg.co
7
8 extrn buf.init
9
10 include config.inc
11 include z180reg.inc
12
13 ;--------------------------------------------------------------
14
15 dseg
16
17 mkbuf msg_fifo, 0
18
19
20 ;--------------------------------------------------------------
21
22 cseg
23
24 ;
25 ; Init buffer
26 ;
27
28 msginit:
29 ld ix,msg_fifo
30 ld a,msg_fb_len-1
31 jp buf.init
32
33
34 ;--------------------------------------------------------------
35
36 msg.sts:
37 push ix
38 ld ix,msg_fifo ;
39
40 ld a,(ix+o.in_idx) ;
41 inc a
42 and (ix+o.mask)
43 sub (ix+o.out_idx) ;
44 pop ix
45 ret z
46 or 0ffh
47 ret
48
49 ;--------------------------------------------------------------
50
51 msg.out:
52 push ix
53 ld ix,msg_fifo ;
54
55 push bc
56 ld b,a ;save char
57 ld a,(ix+o.in_idx) ;
58 inc a
59 and (ix+o.mask)
60 bp.wait:
61 cp (ix+o.out_idx) ;
62 jr z,bp.wait
63 ld c,a
64 ld a,b
65 out (PMSG),a
66 ld (ix+o.in_idx),c
67
68 pop bc
69 pop ix
70 ret
71
72 ;--------------------------------------------------------------
73 ;
74 ; (hl): data
75
76 msg.sout:
77 push ix
78 ld ix,msg_fifo ;
79 push bc
80
81 ld b,(hl) ;count
82 inc hl
83 obs_1:
84 ld a,(ix+o.out_idx) ;
85 sub (ix+o.in_idx) ;
86 dec a
87 and (ix+o.mask)
88 cp b
89 jr c,obs_1
90
91 ld c,(hl) ;port address
92 inc hl
93 ld a,b
94 otir
95 add (ix+o.in_idx)
96 and (ix+o.mask)
97 ld (ix+o.in_idx),a
98 pop bc
99 pop ix
100 ret
101
102 ;----------------------------------------------------------------------
103
104 msg.co:
105 push af
106 push hl
107 ld (buf_char),a
108 ld hl,buf
109 call msg.sout
110 pop hl
111 pop af
112 ret
113
114
115 buf:
116 db buf_end - $ - 2 ;output string length
117 db PMSG ;output port
118 db 081h ; message start token
119 db buf_end - $ - 1 ; message length
120 db 1 ; command
121 db 1 ; subcommand
122 buf_char:
123 db 0 ; pay load
124 buf_end:
125
126 ;----------------------------------------------------------------------
127
128 end
129