-
Notifications
You must be signed in to change notification settings - Fork 85
/
frets
256 lines (256 loc) · 3.17 KB
/
frets
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
.PAGE 'FRETS'
;
; MARK A TRACK, SECTOR FREE IN BAM
;
JFRETS
JSR SETBMP ; POINT BMPNT AT BAM
JSR FREUSE ; CALC INDEX INTO BAM
FRETS2
SEC ; FLAG FOR NO ACTION
BNE FRERTS ; FREE ALREADY
LDA (BMPNT),Y ; NOT FREE, FREE IT
ORA BMASK,X
STA (BMPNT),Y
JSR DTYBAM ; SET DIRTY FLAG
LDY TEMP
CLC
LDA (BMPNT),Y ; ADD ONE
ADC #1
STA (BMPNT),Y
LDA TRACK
CMP DIRTRK
BEQ FRERTS
INC NDBL,X
BNE FRERTS
INC NDBH,X
FRERTS
RTS
DTYBAM
LDX DRVNUM
LDA #1
STA MDIRTY,X ; SET DIRTY FLAG
RTS
;
; MARK TRACK, SECTOR USED
;
JUSED
JSR FREUSE ; CALC IN DEX INTO BAM
BEQ USERTS ; USED, NO ACTION
LDA (BMPNT),Y ; GET BITS
EOR BMASK,X ; MARK SEC USED
STA (BMPNT),Y
JSR DTYBAM
LDY TEMP
LDA (BMPNT),Y ; GET COUNT
SEC
SBC #1 ; DEC ONE (C = 0)
STA (BMPNT),Y ; SAVE IT
LDA TRACK
CMP DIRTRK
BEQ USEDT2
LDA NDBL,X
BNE USEDT1
DEC NDBH,X
USEDT1
DEC NDBL,X
USEDT2
LDA NDBH,X
BEQ USEDT3
RTS
USEDT3
LDA NDBL,X
CMP #3
BCS USERTS ; > 2 BLOCKS FREE
LDA #DSKFUL
JSR ERRMSG
USERTS
RTS
;
; CALCULATES INDEX INTO BAM
; FOR FRETS AND USEDTS
;
FREUSE
JSR SETMAP
TYA
FREUS2
STA TEMP ; SAVE INDEX
FREUS3
LDA SECTOR ; .A = SECTOR/8
LSR A
LSR A
LSR A ; FOR WHICH OF THREE BYTES
SEC
ADC TEMP ; CALC INDEX
TAY
LDA SECTOR ; BIT IN THAT BYTE
AND #7
TAX
LDA (BMPNT),Y ; GET THE BYTE
AND BMASK,X ; TEST IT
RTS ; .Z = 1 = USED, .Z = 0 = FREE
;
BMASK
.BYTE 1,2,4,8,16,32,64,128
.PAGE
SETMAP
JSR SETBJ
JSR SETBMP ; SET BAM POINTER
LDA TRACK
BEQ SM10
CMP MAXTRK
BCC SM20
SM10
LDA #BADTS
JSR CMDER2
SM20
JSR JOB2X
LDA HDRS+2,X
CMP DIRTRK
BNE SM30
LDA HDRS+3,X
BNE SM30
LDA DOS
BEQ SM30 ; 4040 BAM
JSR RDNBAM ; READ THE NEXT BAM
SM30
LDY LOTRK
LDA TRACK
CMP (BMPNT),Y
BCS SM40
JSR RDBAM ; READ 1ST BAM
SM40
LDA DOS
BEQ SM50
LDA TRACK
LDY #HITRK
CMP (BMPNT),Y
BCC SM50
JSR RDNBAM ; READ THE NEXT BAM
JMP SM40
SM50
LDA TRACK
LDY LOTRK
CMP (BMPNT),Y
BCS SM60
LDA #$67
JSR CMDER2
SM60
JMP MBAM
;
; .X = JOBNUM*8
;
JOB2X
LDA JOBNUM
ASL A
ASL A
ASL A
TAX
RTS
;
; JOBNUM = DRVNUM+BAMJOB
;
SETBJ
LDA DRVNUM
CLC
ADC #BAMJOB
STA JOBNUM
RTS
;
; READ 1ST BAM IN
;
RDBAM
JSR SCRBAM
JSR JOB2X
LDA BAMTRK
STA HDRS+2,X
LDA BAMSEC
STA HDRS+3,X
JMP DOREAD
;
; READ NEXT BAM IN
;
RDNBAM
JSR SCRBAM
JSR JOB2X
LDY #0
LDA (BMPNT),Y
STA HDRS+2,X
INY
LDA (BMPNT),Y
STA HDRS+3,X
JMP DOREAD
;
; .Y = BAMSIZ * (TRACK - BMPNT->BAM.LOTRK) + MAPOFF
;
MBAM
LDA TRACK
MBAM2
SEC
LDY LOTRK
SBC (BMPNT),Y
STA ACCUM+1
LDA BAMSIZ
STA TEMP
LDA #0
JMP MB30 ; NOW MULTIPLY
MB10
CLC
ADC ACCUM+1
BCC MB20
LDA #SYSTS
JSR CMDER2
MB20
ASL ACCUM+1
MB30
LSR TEMP
BCS MB10
BNE MB20
ADC MAPOFF ; .C = 0
TAY
RTS
;
; CLEAR THE BAM AREA
;
CLRBAM
LDY #0
TYA
CLB1
STA (BMPNT),Y
INY
BNE CLB1
RTS
RDDIR
JSR SETBJ
JSR SCRBAM ; SCRUB BAM
LDA DIRTRK
STA TRACK
LDA #0
STA SECTOR
LDA JOBNUM
JSR SETH
JMP DOREAD
;
; TURN ON ACTIVITY LED SPECIFIED
; BY DRVNUM
;
JSETLD
LDA #$E7
AND PBD2
PHA
LDA DRVNUM
BEQ LEDS0
PLA
ORA #LED1
BNE LEDS1
LEDS0
PLA
ORA #LED0
LEDS1
STA PBD2
RTS
ERROFF
LDA PBD2
AND #$FF-ERRLED
STA PBD2
RTS
.END