-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathfrets
301 lines (301 loc) · 4.19 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
.PAGE 'FRETS'
;
; MARK A TRACK, SECTOR FREE IN BAM
;
JFRETS
JSR GETHED ; GET THE HEAD NUMBER
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
INC NDBL,X
BNE FRERTS
INC NDBH,X
FRERTS
JMP ADDHED ; ADD THE HEAD NUMBER (RTS)
DTYBAM
LDX DRVNUM
LDA #1
STA MDIRTY,X ; SET DIRTY FLAG
RTS
;
; MARK TRACK, SECTOR USED
;
JUSED
JSR GETHED ; GET THE HEAD NUMBER
USEDT0
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
STA (BMPNT),Y ; SAVE IT
LDA NDBL,X
BNE USEDT1
DEC NDBH,X
USEDT1
DEC NDBL,X
USEDT2
LDA NDBH,X
BNE USERTS
LDA NDBL,X
CMP #3
BCS USERTS ; > 2 BLOCKS FREE
LDA #DSKFUL
JSR ERRMSG
USERTS
JMP ADDHED ; ADD THE HEAD NUMBER (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
SEC ; SKIP # OF BLOCKS
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
CMP MAXTRK
BCC SM11 ; TRACK < MAXTRK
SM10
LDA #BADTS ; BAD TRACK OR SECTOR
JSR CMDER2
SM11
JSR JOB2X
LDY DRVNUM
LDA HDRS+2,X
CMP HSTRK,Y
BNE SM20
LDA HDRS+3,X
CMP HSSEC,Y
BNE SM20
JSR RDBAM ; READ THE FIRST BAM
SM20
LDY #LOTRK ; LOW TRACK OFFSET
LDA TRACK
CMP (BMPNT),Y
BCS SM40 ; TRACK >= LOW TRACK
JSR PRVBAM ; READ THE PREVIOUS BAM
JMP SM20
SM40
LDA TRACK
LDY #HITRK ; HIGH TRACK OFFSET
CMP (BMPNT),Y
BCC SM50 ; TRACK < HIGH TRACK
JSR NXTBAM ; READ THE NEXT BAM
JMP SM20
SM50
JMP BAMIDX ; GET THE BAM INDEX (RTS)
;
; .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
LDY DRVNUM
LDA BAMTRK,Y
STA HDRS+2,X
LDA BAMSEC,Y
STA HDRS+3,X
JMP DOREAD
;
; READ THE NEXT BAM IN
;
NXTBAM
JSR SCRBAM
JSR JOB2X
LDY #0
LDA (BMPNT),Y
STA HDRS+2,X
INY
LDA (BMPNT),Y
STA HDRS+3,X
JMP DOREAD
;
; READ THE PREVIOUS BAM IN
;
PRVBAM
JSR SCRBAM ; WRITE THE CURRENT BAM IF NEEDED
JSR JOB2X
PRVBA1
LDY #2
LDA (BMPNT),Y ; GET THE TRACK
STA HDRS+2,X
INY
LDA (BMPNT),Y ; GET THE SECTOR AND HEAD
STA HDRS+3,X
JMP DOREAD ; READ IT IN
;
; .Y = BTSIZE*(TRACK-LOTRK)+MAPOFF+HEAD*BAMSIZ
;
BAMIDX
LDA TRACK
MBAM2
SEC
LDY #LOTRK
SBC (BMPNT),Y
STA ACCUM+1
LDA BTSIZE
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
MB35
LDY HEAD
BEQ MB50
CLC
MB40
ADC BAMSIZ
DEY
BNE MB40
MB50
TAY
RTS
;
; CLEAR THE BAM AREA
;
CLRBAM
LDY #0
TYA
CLB1
STA (BMPNT),Y
INY
BNE CLB1
RTS
;
; READ THE DIRECTORY HEADER
;
RDDIR
JSR SETBJ
JSR SCRBAM ; SCRUB BAM
LDX DRVNUM
LDA HSTRK,X ; START OF HEADER
STA TRACK
LDA HSSEC,X
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
;
; ADD THE HEAD NUMBER TO THE SECTOR NUMBER
;
ADDHED
LDA HEAD
ASL A
ASL A
ASL A
ASL A
ASL A
ORA SECTOR
STA SECTOR
RTS
;
; EXTRACT THE HEAD NUMBER FORM THE SECTOR
;
GETHED
LDA SECTOR
AND #%11100000 ; MASK OUT THE SECTOR
LSR A
LSR A
LSR A
LSR A
LSR A
STA HEAD ; CURRENT HEAD
PHA ; SAVE THE HEAD NUMBER
LDA SECTOR
AND #%00011111 ; MASK OUT THE HEAD
STA SECTOR ; CURRENT SECTOR
PLA ; RETURN WITH .A = HEAD
RTS
.END