home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_01_1983_Transactor_Publishing.d64 / bmbstringthing < prev    next >
Text File  |  2023-02-26  |  3KB  |  163 lines

  1. ;general purpose routines for the pet/cbm system
  2. ;requires a 257 character buffer
  3. ;starting at a page boundary
  4. ;
  5. ;for 32k basic 4.0 only
  6. ;
  7. chkcom = $bef5 ;check for comma
  8. varpar = $bd98 ;evaluate expression
  9. fltint = $c92d ;floating pt to int
  10. synerr = $bf00 ;?syntax error
  11. len1 = $00  ;work space
  12. len2 = $88  ;    ''
  13. temp1 = $01 ;    ''
  14. temp2 = $89 ;    ''
  15. varptr = $44 ;current varaible pointer
  16. integ = $11 ;int value for sys
  17. curfil = $d2 ;current file number
  18. buffer = $7e00 ;block get buffer, must be sealed
  19. ;                       ;off with poke53,126:clr
  20. status = $96 ;st storage
  21. aryend = $2e ;end of arrays
  22. * = $7f02 ;starts 2 byts in due to buffer
  23. ;
  24. ; vector table
  25. jmp blkget ;block get  - sys 32514
  26. jmp instrg ;instring   - sys 32517
  27. jmp postrg ;pos search - sys 32520
  28. ;
  29. chkpar jsr chkcom ;check for comma and
  30. jsr varpar ;set up pointer to string
  31. ldy #00
  32. rts
  33. findab jsr chkpar ;find first string
  34. lda (varptr),y
  35. sta len1 ;store string 1 length
  36. iny
  37. lda (varptr),y
  38. sta temp1 ;string 1 address low
  39. iny
  40. lda (varptr),y
  41. sta temp1+1 ;string 1 address hi
  42. findb jsr chkpar ;find another string
  43. lda (varptr),y
  44. sta len2 ;store string 2 length
  45. iny
  46. lda (varptr),y
  47. sta temp2 ;string 2 address low
  48. iny
  49. lda (varptr),y
  50. sta temp2+1 ;string 2 address hi
  51. rts
  52. kilstr sec ;get rid of old string
  53. lda temp2+1
  54. cmp aryend+1 ;string in text?
  55. bcc nokill ;yes, exit
  56. lda temp2
  57. cmp aryend
  58. bcc nokill
  59. lda len2
  60. clc
  61. adc temp2
  62. sta temp2
  63. bcc nohiin
  64. inc temp2+1
  65. nohiin ldy #01
  66. lda len2
  67. sta (temp2),y
  68. iny
  69. lda #$ff
  70. sta (temp2),y ;old string dead
  71. nokill rts
  72. ;
  73. findi jsr chkpar ;evaluate numeric
  74. jsr fltint
  75. lda integ+1
  76. beq r1
  77. jmp synerr
  78. r1 lda integ
  79. rts
  80. ;
  81. ;**        block get routine       **
  82. blkget jsr findi ;get file number
  83. sta curfil
  84. lda #<buffer ;get buffer address
  85. sta temp1
  86. lda #>buffer
  87. sta temp1+1
  88. jsr findb ;find string variable
  89. jsr kilstr ;kill old string
  90. ldx curfil
  91. jsr $ffc6 ;set input device
  92. inloop jsr $ffe4 ;get a character
  93. tax ;save char in .x
  94. cmp #$0d ;carriage return?
  95. beq varset ;yes, stop input
  96. ldy #$00
  97. sta (temp1),y ;store char in buffer
  98. inc temp1 ;increment length
  99. ldy temp1 ;get length
  100. cpy #255 ;max ?
  101. beq preset
  102. ldy status ;more chars?
  103. beq inloop ;yes, continue
  104. preset txa ;get char from .x
  105. bne varset ;last char chr$(0)?
  106. dec temp1 ;yes, dec length
  107. varset jsr $ffcc ;close channel
  108. ldy #$00
  109. lda temp1
  110. sta (varptr),y ;stor len in pointer
  111. iny
  112. lda #<buffer
  113. sta (varptr),y ;store pointer low
  114. iny
  115. lda #>buffer
  116. sta (varptr),y ;store pointer hi
  117. rts
  118. ;
  119. ;**          instring routine          **
  120. instrg jsr findab ;find both variables
  121. jsr findi ;get insert position
  122. dec integ
  123. lda temp2
  124. clc
  125. adc integ
  126. sta temp2
  127. bcc i1
  128. inc temp2+1
  129. i1 ldy #$00
  130. i2 lda (temp1),y
  131. sta (temp2),y ;transfer bytes
  132. iny
  133. cpy len1 ;end of insert
  134. bne i2 ;no, do more
  135. rts
  136. ;
  137. ;**        position search routine       **
  138. postrg jsr findab ;find both variables
  139. lda #$00
  140. tax ;x reg = 0
  141. sta $b6 ;reset position
  142. loopp ldy #$00  ;zeroize offset
  143. p1 lda (temp1),y  ;get char at a$,y
  144. cmp (temp2),y ;same as char at b$,y ?
  145. bne bump ;no, move to next a$ char
  146. iny ;yes, increment y
  147. cpy len1 ;same as len of a$?
  148. bne p1 ;no, more chars to compare
  149. inc $b6 ;yes, bump position
  150. lda $b6 ;and store it
  151. sta $00 ;in location 0
  152. rts
  153. bump inc temp2  ;move to next char in b$
  154. bne p2
  155. inc temp2+1
  156. p2 inc $b6  ;bump position
  157. lda $b6
  158. cmp len2 ;end of b$ ?
  159. bne loopp ;no, do more compares
  160. stx $00 ;not found
  161. rts
  162. .end
  163.