-
Notifications
You must be signed in to change notification settings - Fork 84
/
frets
315 lines (315 loc) · 4.12 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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
.PAGE 'FRETS'
.SKIP
; MARK A TRACK,SECTOR AS FREE IN BAM
WFREE
JSR FIXBAM
;
FRETS
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 USE10
;
INC NDBL,X
BNE FRE10
INC NDBH,X
FRE10
FRERTS RTS
;
DTYBAM
LDX DRVNUM
LDA #1
STA MDIRTY,X ;SET DIRTY FLAG
RTS
;
; MARK TRACK,SECTOR,(BMPNT) AS USED
;
WUSED
JSR FIXBAM
;
USEDTS ;CALC IN DEX INTO BAM
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 USE20
;
LDA NDBL,X
BNE USE10
DEC NDBH,X
USE10
DEC NDBL,X
USE20
LDA NDBH,X
BNE USERTS
LDA NDBL,X
CMP #3
BCS USERTS
;
LDA #DSKFUL
JSR ERRMSG
USERTS RTS
;
; CALCULATES INDEX INTO BAM
; FOR FRETS AND USEDTS
;
FREUSE
JSR SETBAM
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
;
FIXBAM ;WRITE THE BAM ACCORDING TO WBAM FLAG
LDA #$FF
BIT WBAM
BEQ FBAM10 ;TEST FLAGS
BPL FBAM10
BVS FBAM10
;
LDA #0
STA WBAM ;CLEAR FLAG
JMP DOWRIT
;
FBAM10
RTS
;
;
; CLEAR THE BAM AREA
;
CLRBAM
JSR SETBPT
LDY #0
TYA
CLB1
STA (BMPNT)Y
INY
BNE CLB1
RTS
;
SETBAM ;SET BAM IMAGE IN MEMORY
LDA T0 ;SAVE TEMPS
PHA
LDA T1
PHA
LDX DRVNUM
LDA NODRV,X
BEQ SBM10
;
LDA #NODRIV ;NO DRIVE
JSR CMDER3
SBM10
JSR BAM2A
STA T0 ;T0:= INDEX INTO BUF0
TXA
ASL A
STA T1 ;T1:= 2*DRVNUM
TAX
LDA TRACK
CMP TBAM,X ;CHECK BAM TABLE FOR TRACK
BEQ SBM30 ;IT'S IN
;
INX
STX T1 ;CHECK NEXT ENTRY
CMP TBAM,X
BEQ SBM30 ;IT'S IN
;
JSR SWAP ;SWAP TRACK BAM IN TABLE
SBM30
LDA T1
LDX DRVNUM
STA UBAM,X ;SET LAST USED PTR
ASL A
ASL A
CLC
ADC #<BAM ;SET ACTUAL PTR
STA BMPNT
LDA #>BAM
ADC #0
STA BMPNT+1
LDY #0
PLA
STA T1
PLA
STA T0
RTS
;
;
SWAP ;SWAP IMAGES OF BAM
LDX T0
JSR REDBAM ;READ BAM IF NOT IN
LDA DRVNUM
TAX
ASL A
ORA UBAM,X ;SWAP OUT LEAST USED IMAGE
EOR #1
AND #3
STA T1
JSR PUTBAM ;PUT TO BAM
LDA JOBNUM
ASL A
TAX
LDA TRACK
ASL A
ASL A
STA BUFTAB,X ;SET PTR
LDA T1
ASL A
ASL A
TAY
SWAP3 ;TRANSFER BAM TO MEM IMAGE
LDA (BUFTAB,X)
STA BAM,Y
LDA #0
STA (BUFTAB,X) ;CLEAR BAM
INC BUFTAB,X
INY
TYA
AND #3
BNE SWAP3
;
LDX T1
LDA TRACK
STA TBAM,X ;SET TRACK # FOR IMAGE
;
LDA WBAM
BNE SWAP4 ;DON'T WRITE NOW
JMP DOWRIT
SWAP4
ORA #$80 ;SET PENDING WRITE FLAG
STA WBAM
RTS
;
PUTBAM ;PUT MEM IMAGE TO BAM
TAY
LDA TBAM,Y
BEQ SWAP2 ;NO IMAGE HERE
;
PHA ;SAVE TRACK #
LDA #0
STA TBAM,Y ;CLEAR TRACK FLAG
LDA JOBNUM
ASL A
TAX
PLA
ASL A
ASL A
STA BUFTAB,X ;SET PTR IN BAM
TYA
ASL A
ASL A
TAY
SWAP1 ;TRANSFER IMAGE TO BAM
LDA BAM,Y
STA (BUFTAB,X)
LDA #0
STA BAM,Y ;CLEAR IMAGE
INC BUFTAB,X
INY
TYA
AND #3
BNE SWAP1
SWAP2
RTS
;
;
CLNBAM ;CLEAN TRACK # FOR IMAGES
LDA DRVNUM
ASL A
TAX
LDA #0
STA TBAM,X
INX
STA TBAM,X
RTS
;
;
;
REDBAM ;READ IN BAM IF NOT PRESENT
LDA BUF0,X
CMP #$FF
BNE RBM20 ;IT IS IN MEMORY
TXA
PHA ;SAVE CHANNEL PTR
JSR GETBUF ;GO FIND A BUFFER
TAX
BPL RBM10
;
LDA #NOCHNL ;NO BUFFERS AROUND
JSR CMDERR
RBM10
STX JOBNUM ;SAVE JOBNUM ASSIGNED
PLA
TAY
TXA
ORA #$80
STA BUF0,Y ;SET AS INACTIVE FOR STEALING
;READ IN BAM
ASL A
TAX
LDA DIRTRK
STA HDRS,X
LDA #0
STA HDRS+1,X
JMP DOREAD
RBM20
AND #$F ;SET BAM'S JOBNUM
STA JOBNUM
RTS
;
;SET BAM POINTER IN BUF0/1 TABLES
;
BAM2A ;LEAVE IN .A
LDA #BLINDX
LDX DRVNUM
BNE B2X10
;
CLC
ADC #MXCHNS+1
B2X10
RTS
;
BAM2X ;LEAVE IN .X
JSR BAM2A
TAX
RTS
;
;
.END