-
Notifications
You must be signed in to change notification settings - Fork 84
/
tstfnd.src
224 lines (170 loc) · 2.8 KB
/
tstfnd.src
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
.page
.subttl 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
sec
lda sector
sbc lstsec
sta sector
beq fndn0
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
lda #1 ;r0:= 1
sta r0
its1 lda dirtrk ;track:= dirtrk-r0
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 lda dirtrk ;track:= dirtrk+r0
clc
adc r0
sta track
inc r0 ;r0:= r0+1
cmp maxtrk ;if track >=maxtrk then cmder2(systs)
bcc its3
lda #systs
jsr cmder2
its3 jsr setbam ;set ptr
lda (bmpnt),y ;if @b{.y}=0 then goto its1
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
; 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
; for .x:=7 to 0 do;
ac10 ldx #7 ;count the bits
ac20 lda (bmpnt),y ;if @b{.y} & bmask{x}
and bmask,x
beq ac30
inc temp ;then temp:=temp+1
ac30 dex ;end .x
bpl ac20
dey ;end .y
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
; .a=track # ,returns #sectors on this track
maxsec ldx nzones
max1 cmp trknum-1,x
dex
bcs max1
lda numsec,x
rts
; .end