-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathtstfnd
218 lines (218 loc) · 2.71 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
218
.PAGE 'TSTFND '
;
; NEXT TRACK & SECTOR
; RETURNS NEXT AVAILABLE TRACK & SECTOR
; GIVEN CURRENT TRACK AND SECTOR
;
; ALLOCATION IS FROM DIRTRK TOWARDS
; 1 & MAXTRK, BY FULL TRACKS
;
JNXTTS
JSR GETHDR
LDA #3
STA TEMP
NXTDS
NXT1
LDA TEMP
PHA ; SAVE TEMP
JSR SETMAP
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 USEDTS
FNDN2
LDA #0
STA SECTOR
JSR GETSEC
BNE FNDN1
JMP DERR
;
; RETURNS OPTIMUM INITIAL TRACK, SECTOR
;
JINTTS
LDA R0
PHA ; SAVE TEMP VAR
LDA #1
STA R0
ITS1
LDA DIRTRK
SEC
SBC R0
STA TRACK
BCC ITS2
BEQ ITS2
JSR SETMAP ; SET THE BAM POINTER
LDA (BMPNT),Y
BNE FNDSEC
ITS2
LDA DIRTRK
CLC
ADC R0
STA TRACK
INC R0
CMP MAXTRK
BCC ITS3
LDA #SYSTS
JSR CMDER2
ITS3
JSR SETMAP ; SET THE BAM POINTER
LDA (BMPNT),Y
BEQ ITS1
FNDSEC
PLA
STA R0 ; RESTORE R0
LDA #0
STA SECTOR
JSR GETSEC
BEQ FND2
JMP USEDTS
FND2
DERR
LDA #DIRERR
JSR CMDER2
;
; SET (INDIRECT) BAM PNTR BY DRVNUM
;
SETBMP
LDX DRVNUM
LDA IPBM,X
STA BMPNT+1
LDA #0
STA BMPNT
RTS
;
; SET BAM AND FIND AVAILABLE SECTOR
; STARTING AT SECTOR
;
GETSEC
JSR SETMAP
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 ; JUMP
GS20
LDA #0
GS30
RTS ; (Z = 1), USED
;
; BIT MAP VALIDITY CHECK
;
AVCK
LDA TEMP
PHA ; SAVE TEMP
LDA #0
STA TEMP ; TEMP = 0
TYA
STA BMPNT ; SET LOW BYTE TO TRACK BAM
LDY BAMSIZ
DEY
AC10
LDX #7 ; COUNT THE BITS
AC20
LDA (BMPNT),Y
AND BMASK,X
BEQ AC30
INC TEMP
AC30
DEX
BPL AC20
DEY
BNE AC10
LDA (BMPNT),Y
CMP TEMP
BNE AC40 ; COUNTS DO NOT MATCH
LDA #0
STA BMPNT ; RESTORE PNTR
PLA
STA TEMP ; RESTORE TEMP
RTS
AC40
LDA #DIRERR
JSR CMDER2
;
; RETURNS # OF SECTORS ON TRACK
;
JMXSEC
LDX NZONES
CMP TRKNUM
BCS MAXSE2 ; TRACK > MAX TRACK
MAXSE1
CMP TRKNUM-1,X
DEX
BCS MAXSE1
BCC MAXSE3 ; JUMP
MAXSE2
CMP TRKNUM+3,X
DEX
BCS MAXSE2
MAXSE3
LDA NUMSEC,X ; GET # OF SECTORS
RTS
.END