-
Notifications
You must be signed in to change notification settings - Fork 84
/
tstfnd
217 lines (217 loc) · 2.76 KB
/
tstfnd
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
.PAGE ' TSTFND '
; NEXT TRACK & SECTOR
; RETURNS NEXT AVAILABLE TRACK & SECTOR
; GIVEN CURRENT T & S
;
; ALLOCATION IS FROM TRACK 18
; TOWARDS 1 & 35, BY FULL TRACKS
NXTTS
JSR GETHDR
LDA #3
STA TEMP
LDA #1 ;SET NO WRITE BAM
ORA WBAM
STA WBAM
NXTDS
NXT1
LDA TEMP
PHA ;SAVE TEMP
JSR SETBAM
PLA
STA TEMP ;RESTORE TEMP
LDA (BMPNT),Y
BNE FNDNXT
LDA TRACK
CMP DIRTRK
BEQ NXTERR
BCC NXT2
INC TRACK
LDA TRACK
CMP MAXTRK
BNE NXT1
LDX DIRTRK
DEX
STX TRACK
LDA #0
STA SECTOR
DEC TEMP
BNE NXT1
NXTERR LDA #DSKFUL
JSR CMDERR
NXT2 DEC TRACK
BNE NXT1
LDX DIRTRK
INX
STX TRACK
LDA #0
STA SECTOR
DEC TEMP
BNE NXT1
BEQ NXTERR
;
; FIND THE NEXT OPTIMUM SECTOR
; NEXT SECTOR=CURRENT SECTOR+N
;
FNDNXT LDA SECTOR
CLC
ADC SECINC
STA SECTOR
LDA TRACK
JSR MAXSEC
STA LSTSEC
STA CMD
CMP SECTOR
BCS FNDN0
.SKIP
SEC
LDA SECTOR
SBC LSTSEC
STA SECTOR
BEQ FNDN0
.SKIP
DEC SECTOR
FNDN0
JSR GETSEC
BEQ FNDN2
FNDN1
JMP WUSED
FNDN2
LDA #0
STA SECTOR
JSR GETSEC
BNE FNDN1
JMP DERR
;
;
; RETURNS OPTIMUM INITIAL TRACK,SECTOR
;
INTTS
LDA #1
ORA WBAM
STA WBAM
LDA R0
PHA ;SAVE TEMP VAR
;R0:= 1
LDA #1
STA R0
ITS1 ;TRACK:= DIRTRK-R0
LDA DIRTRK
SEC
SBC R0
STA TRACK
;IF T>0
BCC ITS2
BEQ ITS2
;THEN BEGIN
JSR SETBAM ;SET THE BAM POINTER
;IF @B[.Y] THEN GOTO FNDSEC
LDA (BMPNT),Y
BNE FNDSEC
;END
ITS2 ;TRACK:= DIRTRK+R0
LDA DIRTRK
CLC
ADC R0
STA TRACK
;R0:= R0+1
INC R0
;IF TRACK >=MAXTRK THEN CMDER2(SYSTS)
CMP MAXTRK
BCC ITS3
;
LDA #SYSTS
JSR CMDER2
ITS3
JSR SETBAM ;SET PTR
;IF @B[.Y]=0 THEN GOTO ITS1
LDA (BMPNT)Y
BEQ ITS1
FNDSEC
PLA
STA R0 ;RESTORE R0
LDA #0
STA SECTOR
JSR GETSEC
BEQ FND2
JMP WUSED
;
FND2
DERR
LDA #DIRERR
JSR CMDER2
;
;
; SET BAM AND FIND AVAILABLE SECTOR
; STARTING AT SECTOR
;
GETSEC
JSR SETBAM
TYA
PHA ;SAVE .Y
JSR AVCK ;CHECK BITS & COUNT
;
LDA TRACK
JSR MAXSEC
STA LSTSEC ;SAVE MAX SECTOR #
PLA
STA TEMP ;TEMP:= OLD .Y FOR FREUS3
GS10
LDA SECTOR
CMP LSTSEC
BCS GS20
;
JSR FREUS3
BNE GS30
;
INC SECTOR
BNE GS10 ;BRA
GS20
LDA #0
GS30
RTS ;(Z=1): USED
.SKIP
;BIT MAP VALIDITY CHECK
AVCK
LDA TEMP
PHA ;SAVE TEMP
LDA #0
STA TEMP ;TEMP:=0
;FOR .Y:=BAMSIZ TO 1 DO;
LDY BAMSIZ
DEY
AC10 ;FOR .X:=7 TO 0 DO;
LDX #7 ;COUNT THE BITS
AC20 ;IF @B[.Y] & BMASK[X]
; THEN TEMP:=TEMP+1
LDA (BMPNT)Y
AND BMASK,X
BEQ AC30
INC TEMP
AC30 ;END .X
DEX
BPL AC20
;END .Y
DEY
BNE AC10
;IF @B[.Y] <> TEMP
; THEN CMDER2(DIRERR);
LDA (BMPNT)Y
CMP TEMP
BNE AC40 ;COUNTS DO NOT MATCH
;
PLA
STA TEMP ;RESTORE TEMP
RTS
AC40
LDA #DIRERR
JSR CMDER2
.SKIP
; .A=TRACK # ,RETURNS #SECTORS ON THIS TRACK
MAXSEC LDX NZONES
MAX1 CMP TRKNUM-1,X
DEX
BCS MAX1
LDA NUMSEC,X
RTS
;
.END