-
Notifications
You must be signed in to change notification settings - Fork 82
/
fndrel.src
173 lines (151 loc) · 3.65 KB
/
fndrel.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
.messg "fndrel"
.subttl "fndrel"
.page
;********************************
;*
;* find relative file
;*
;* version 10
;*
;*
;* inputs
;* recl - 1byte=lo record #
;* rech - 1byte=hi record #
;* rs - 1byte=record size
;* recptr - 1byte=first byte
;* wanted from record
;*
;* outputs
;* ssnum - 1byte=side sector #
;* ssind - 1byte=index into ss
;* relptr - 1byte=ptr to first
;* byte wanted
;*
;********************************
;
;
fndrel jsr mulply ; result=rn*rs+rp
jsr div254 ; divide by 254
lda accum+1 ; save remainder
sta relptr
jsr div120 ; divide by 120
inc relptr
inc relptr
jsr hugerel
beq fndre1 ; br, big
lda result ; save quotient
sta ssnum
lda accum+1 ; save remainder
asl a ; calc index into ss
clc
adc #16 ; skip link table
sta ssind
rts
fndre1
lda accum+1
asl a
clc
adc #16
sta ssind ; steps to figure grpnum
jsr div006
lda accum+1
sta ssnum
lda result
sta grpnum
rts
; multiply
; result=recnum*rs+recptr
; destroys a,x
mulply jsr zerres ; result=0
sta accum+3 ; a=0
ldx lindx ; get index
lda recl,x
sta accum+1
lda rech,x
sta accum+2
bne mul25 ; adjust for rec #1 &...
lda accum+1 ; ...#0 = 1st rec
beq mul50
mul25 lda accum+1
sec
sbc #1
sta accum+1
bcs mul50
dec accum+2
mul50
lda rs,x ; copy recsiz
sta temp
mul100 lsr temp ; do an add ?
bcc mul200 ; no
jsr addres ; result=result+accum+1,2,3
mul200 jsr accx2 ; 2*(accum+1,2,3)
lda temp ; done ?
bne mul100 ; no
lda recptr ; add in last bit
clc
adc result
sta result
bcc mul400 ; skip no carry
inc result+1
bne mul400
inc result+2
mul400 rts
; divide
; result=quotient ,accum+1=remainder
; destroys a,x
div254 lda #254 ; divide by 254
.byte skip2 ; skip two bytes
div120 lda #120 ; divide by 120
.byte skip2
div006
lda #6 ; divide by 6
sta temp ; 8 bit divisor
lda #0
sta accum+1
sta accum+2
ldx #24
divid1
asl result
rol result+1
rol result+2
rol accum+1
rol accum+2
lda accum+1
sec
sbc temp
tay ; save result
lda accum+2
sbc #0
bcc divid2 ; br, if temp > dividend
inc result
sta accum+2
sty accum+1
divid2
dex
bne divid1
rts
; zero result
zerres lda #0
sta result
sta result+1
sta result+2
rts
; multiply accum by 4
accx4 jsr accx2
;
; multiply accum by 2
accx2 clc
acc200 rol accum+1
rol accum+2
rol accum+3
rts
; add accum to result
; result=result+accum+1,2,3
addres clc
ldx #$fd
add100 lda result+3,x
adc accum+4,x
sta result+3,x
inx
bne add100
rts