-
Notifications
You must be signed in to change notification settings - Fork 0
/
cio.m65
193 lines (148 loc) · 2.46 KB
/
cio.m65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
;
; Some basic CIO helper routines
;
; Zero-page equates
BUFPTRL = $CB
BUFPTRH = $CC
BUFPTR = $CB
; jmp to a callback for handling an error
CIO_ERRJMP:
jmp warmsv
CIO_ERR_CALLBACK = CIO_ERRJMP + 1
; Checks for err after cio call and runs callback if necessary
cio_checkerr
rts
tya
and #~10000000
beq @nocioerr
jmp CIO_ERRJMP
@nocioerr
rts
; Opens IOCB#X ($10, $20, etc) with aux1 in A
; With device name buffer ptr in BUFPTR
CIO_OPEN:
; Aux byte
sta ICAX1, X
; Command
lda #OPEN
sta ICCOM, X
; Buffer
lda BUFPTRL
sta ICBAL, X
lda BUFPTRH
sta ICBAH, X
lda #$FF
sta ICBLL, X
sta ICBLH, X
; CIO Call
jsr CIOV
jsr cio_checkerr
rts
; Closes IOCB#X ($10, $20, etc)
CIO_CLOSE:
; Command
lda #CLOSE
sta ICCOM, X
; CIO Call
jsr CIOV
jsr cio_checkerr
rts
; Reads buf from channel in x for a bytes
CIO_GET:
; Buflen
sta ICBLL, X
lda #0
sta ICBLH, X
; Command
lda #GETCHR
sta ICCOM, X
; Buffer
lda BUFPTRL
sta ICBAL, X
lda BUFPTRH
sta ICBAH, X
; CIO Call
jsr CIOV
jsr cio_checkerr
rts
; Writes buf to channel in x
CIO_WRITE:
; Command
lda #PUTREC
sta ICCOM, X
; Buffer
lda BUFPTRL
sta ICBAL, X
lda BUFPTRH
sta ICBAH, X
lda #$FF
sta ICBLL, X
sta ICBLH, X
; CIO Call
jsr CIOV
jsr cio_checkerr
rts
; Writes A bytes of buf to channel in X
CIO_PUT:
; Buf len
sta ICBLL, X
lda #00
sta ICBLH, X
; Command
lda #PUTCHR
sta ICCOM, X
; Buffer
lda BUFPTRL
sta ICBAL, X
lda BUFPTRH
sta ICBAH, X
; CIO Call
jsr CIOV
jsr cio_checkerr
rts
; Performs an arbitrary cio Call
; A is Command
; x is iocb, y is aux1
CIO_ARBITRARY:
; Command
sta ICCOM, X
; Aux bytes
tya
sta ICAX1, X
lda #00
sta ICAX2, X
; Buffer
lda BUFPTRL
sta ICBAL, X
lda BUFPTRH
sta ICBAH, X
lda #$FF
sta ICBLL, X
sta ICBLH, X
; CIO Call
jsr CIOV
jsr cio_checkerr
rts
; Performs an arbitrary cio Call
; stack has Command
; x is iocb, a is aux, y is aux2
CIO_ARBITRARY_2AUX:
sta ICAX1, X
; Command
pla
sta ICCOM, X
; Aux bytes
tya
sta ICAX2, X
; Buffer
lda BUFPTRL
sta ICBAL, X
lda BUFPTRH
sta ICBAH, X
lda #$FF
sta ICBLL, X
sta ICBLH, X
; CIO Call
jsr CIOV
jsr cio_checkerr
rts