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 3.2KB

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