You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fndrel.src 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. .page 'fndrel'
  2. ;********************************
  3. ;*
  4. ;* find relative file
  5. ;*
  6. ;* version 2.5
  7. ;*
  8. ;*
  9. ;* inputs
  10. ;* recl - 1byte=lo record #
  11. ;* rech - 1byte=hi record #
  12. ;* rs - 1byte=record size
  13. ;* recptr - 1byte=first byte
  14. ;* wanted from record
  15. ;*
  16. ;* outputs
  17. ;* ssnum - 1byte=side sector #
  18. ;* ssind - 1byte=index into ss
  19. ;* relptr - 1byte=ptr to first
  20. ;* byte wanted
  21. ;*
  22. ;********************************
  23. ;
  24. ;
  25. ;
  26. ;
  27. ;
  28. ;
  29. fndrel jsr mulply ; result=rn*rs+rp
  30. jsr div254 ; divide by 254
  31. lda accum+1 ; save remainder
  32. sta relptr
  33. jsr div120 ; divide by 120
  34. inc relptr
  35. inc relptr
  36. lda result ; save quotient
  37. sta ssnum
  38. lda accum+1 ; save remainder
  39. asl a ; calc index into ss
  40. clc
  41. adc #16 ; skip link table
  42. sta ssind
  43. rts
  44. ;
  45. ;
  46. ;
  47. ; multiply
  48. ;
  49. ; result=recnum*rs+recptr
  50. ;
  51. ; destroys a,x
  52. ;
  53. mulply jsr zerres ; result=0
  54. sta accum+3 ; a=0
  55. ldx lindx ; get index
  56. lda recl,x
  57. sta accum+1
  58. lda rech,x
  59. sta accum+2
  60. bne mul25 ; adjust for rec #1 &...
  61. lda accum+1 ; ...#0 = 1st rec
  62. beq mul50
  63. mul25 lda accum+1
  64. sec
  65. sbc #1
  66. sta accum+1
  67. bcs mul50
  68. dec accum+2
  69. mul50
  70. lda rs,x ; copy recsiz
  71. sta temp
  72. mul100 lsr temp ; do an add ?
  73. bcc mul200 ; no
  74. jsr addres ; result=result+accum+1,2,3
  75. mul200 jsr accx2 ; 2*(accum+1,2,3)
  76. lda temp ; done ?
  77. bne mul100 ; no
  78. lda recptr ; add in last bit
  79. clc
  80. adc result
  81. sta result
  82. bcc mul400 ; skip no carry
  83. inc result+1
  84. bne mul400
  85. inc result+2
  86. mul400 rts
  87. ;
  88. ;
  89. ;
  90. ; divide
  91. ;
  92. ; result=quotient ,accum+1=remainder
  93. ;
  94. ; destroys a,x
  95. ;
  96. div254 lda #254 ; divide by 254
  97. .byte $2c ; skip two bytes
  98. div120 lda #120 ; divide by 120
  99. sta temp ; save divisor
  100. ldx #3 ; swap accum+1,2,3 with
  101. div100 lda accum,x ; result,1,2
  102. pha
  103. lda result-1,x
  104. sta accum,x
  105. pla
  106. sta result-1,x
  107. dex
  108. bne div100
  109. jsr zerres ; result=0
  110. div150 ldx #0
  111. div200 lda accum+1,x ; divide by 256
  112. sta accum,x
  113. inx
  114. cpx #4 ; done ?
  115. bcc div200 ; no
  116. lda #0 ; zero hi byte
  117. sta accum+3
  118. bit temp ; a div120 ?
  119. bmi div300 ; no
  120. asl accum ; only divide by 128
  121. php ; save carry
  122. lsr accum ; normalize
  123. plp ; restore carry
  124. jsr acc200 ; 2*(x/256)=x/128
  125. div300 jsr addres ; total a quotient
  126. jsr accx2 ; a=2*a
  127. bit temp ; a div120 ?
  128. bmi div400 ; no
  129. jsr accx4 ; a=4*(2*a)=8*a
  130. div400 lda accum ; add in remainder
  131. clc
  132. adc accum+1
  133. sta accum+1
  134. bcc div500
  135. inc accum+2
  136. bne div500
  137. inc accum+3
  138. div500 lda accum+3 ; test < 256
  139. ora accum+2
  140. bne div150 ; crunch some more
  141. lda accum+1 ; is remainder < divisor
  142. sec
  143. sbc temp
  144. bcc div700 ; yes
  145. inc result ; no - fix result
  146. bne div600
  147. inc result+1
  148. bne div600
  149. inc result+2
  150. div600 sta accum+1 ; new remainder
  151. div700 rts
  152. ;
  153. ;
  154. ;
  155. ; zero result
  156. ;
  157. zerres lda #0
  158. sta result
  159. sta result+1
  160. sta result+2
  161. rts
  162. ;
  163. ;
  164. ;
  165. ; multiply accum by 4
  166. ;
  167. accx4 jsr accx2
  168. ;
  169. ; multiply accum by 2
  170. ;
  171. accx2 clc
  172. acc200 rol accum+1
  173. rol accum+2
  174. rol accum+3
  175. rts
  176. ;
  177. ;
  178. ;
  179. ; add accum to result
  180. ;
  181. ; result=result+accum+1,2,3
  182. ;
  183. addres clc
  184. ldx #$fd
  185. add100 lda result+3,x
  186. adc accum+4,x
  187. sta result+3,x
  188. inx
  189. bne add100
  190. rts
  191. ;
  192. ;
  193. ;
  194. ;
  195. ; .end