home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_27_1988_Transactor_Publishing.d64 / shellram.sda / SHELLSTR.A < prev    next >
Text File  |  2023-02-26  |  4KB  |  261 lines

  1. ;
  2. ; shellram
  3. ;
  4. ;  By: Adrian Pepper
  5. ;      Toronto, Ontario
  6. ;
  7. ;  based on, but heavily modified from
  8. ;  the Pro-Line/Spinnaker
  9. ;    C POWER/POWER C shell for the
  10. ;  Commodore 64 home computer.
  11. ;
  12. ;  The shell was modified to reduce
  13. ;  the size of the code, and arrange
  14. ;  things so memory page 22 (hex $16)
  15. ;  will be free for use as a "RAMdisk
  16. ;  Interface Page", for use with the
  17. ;  Commodore 1764 256K RAM expander
  18. ;  for the Commodore 64
  19. ;
  20. ;  This (basically) allows all programs
  21. ;  designed to run under the shell to
  22. ;  operate with the RAM disk
  23. ;
  24. ;
  25. ; shellstr.a
  26. ;
  27. ;   routines for doing
  28. ;    string manipulation
  29. ;
  30. ;  use of these routines accounts for a
  31. ;  lot of the space saving
  32. ;
  33. ;
  34.  .ref wrkdev
  35. ;
  36. ; kernal routines, etc
  37. ;
  38.  .ref setlfs
  39.  .ref setnam
  40.  .ref open
  41.  .ref chkin
  42.  .ref clrchn
  43.  .ref chrin
  44.  .ref chrout
  45. ;
  46. ;
  47. ; shellstr - utility routines to work
  48. ;  with a zero-terminated "string
  49. ;  accumulator" at a fixed address
  50. ;
  51. ;
  52.  .ref strac  ;; same as prfbuf, remember
  53.  .ref kwrkfil
  54.  .ref ksysfil
  55. ;
  56.  .def strclr
  57.  .def strend
  58.  .def strload
  59.  .def strapnd
  60.  .def streq
  61.  .def stropen
  62.  .def strfopn
  63.  .def strechn
  64.  .def stretst
  65.  .def strout
  66.  .def strbout
  67. ;
  68. ;
  69. ; strclr - zero work string buffer
  70. ;  input regs: none
  71. ;  a is always set to zero
  72. ;
  73. strclr lda #0
  74.  sta strac
  75.  rts
  76. ;
  77. ;
  78. ; strend - set x to length of strac
  79. ;  x should be set before call
  80. ;   (in case multiple strings are in
  81. ;    strac)
  82. ;
  83. ; output: x - length of strac
  84. ;
  85. strend lda strac,x
  86.  inx
  87.  cmp #0
  88.  bne strend
  89.  dex   ; point back at end
  90.  rts
  91. ;
  92. ;
  93. ; strapnd - copy string at (x,y) to
  94. ;  end of strac
  95. ;
  96. ; output: x new length of strac
  97. ;         y length of string (x,y)+1
  98. ;         a always 0
  99. ;         $57,$58 used to store x,y
  100. ;
  101. strapnd stx $57
  102.  sty $58
  103.  ldx #0
  104.  jsr strend
  105.  ldy #0
  106. t0100b lda ($57),y
  107.  iny
  108.  sta strac,x
  109.  inx
  110.  cmp #0
  111.  bne t0100b
  112. ;jsr strbout
  113.  dex ; point at '\0' terminator
  114. ;lda #'_
  115. ;jsr chrout
  116. ;lda #$0d
  117. ;jsr chrout
  118.  rts
  119. ;
  120. ;
  121. ; strload - copy string at (x,y) to
  122. ;  strac
  123. ;
  124. ; output: x new length of strac
  125. ;         y length of string (x,y)+1
  126. ;         a always 0
  127. ;         $57,$58 used to store x,y
  128. ;
  129. strload jsr strclr
  130.  jmp strapnd  ;; and return
  131. ;
  132. ;
  133. ; streq - compare string at (x,y) to
  134. ;  strac for equality
  135. ;
  136. ; output:
  137. ;  z cc - equal/not
  138. ;  x - unchanged
  139. ;  y - index of differing char
  140. ;  a - char of (x,y) that differed (or '\0')
  141. ;  $57,$58 - x,y
  142. ;
  143. streq stx $57
  144.  sty $58
  145.  ldy #0
  146. t0200b lda ($57),y
  147.  cmp strac,y
  148.  bne t0210f  ;; return not equal
  149.  iny
  150.  cmp #0
  151.  bne t0200b  ;; or fall through, return equal
  152. t0210f rts  ;; equal
  153. ;
  154. ;
  155. ; stropen - open strac
  156. ;
  157. ; a,x,y are used as a call to setlfs
  158. ; strac is assumed as a '\0' terminated
  159. ; string, and used for call to setnam
  160. ;
  161. ; all registers plus strac should be
  162. ;  considered scratched
  163. ;
  164. stropen jsr setlfs
  165.  ldx #0
  166.  jsr strend
  167.  txa  ;; length of strac in a
  168.  ldx #<strac
  169.  ldy #>strac  ;; setup for setnam
  170.  jsr setnam
  171.  jmp open  ;; and return, with carry
  172. ;
  173. ;
  174. ; strfopn - open strac as a file
  175. ;
  176. ; a,x,y are used as a call to setlfs
  177. ; strac is assumed as a '\0' terminated
  178. ; string, and used for call to setnam
  179. ;
  180. ; if open fails, an error message is
  181. ;  copied to strac, and carry is set
  182. ;
  183. ; all registers plus strac should be
  184. ;  considered scratched
  185. ;
  186. strfopn stx savdev
  187.  jsr stropen
  188.  ldx savdev
  189.  jmp strechn
  190. savdev .bss 1
  191. ;
  192. ;
  193. ; strechn - read error channel for device
  194. ;  given in x
  195. ;
  196. ; replaces strac with error channel line
  197. ;
  198. ; error line won't be printed, though
  199. ; carry will be set if error line is non-zero
  200. ;
  201. strechn lda #<kwrkfil
  202.  cpx wrkdev
  203.  beq t0595f
  204.  lda #<ksysfil
  205. t0595f tax
  206.  jsr chkin
  207.  jsr strget
  208.  jmp stretst
  209. ;
  210. ;
  211. ; strget - read a line from current
  212. ;  chkin file,
  213. ;  then do a clrchn
  214. ;
  215. strget ldy #0
  216. t0700b jsr chrin
  217.  sta strac,y
  218.  iny
  219.  bcs t0710f
  220.  cmp #$0d
  221.  bne t0700b
  222. ; should check eof
  223. t0710f lda #0
  224.  sta strac,y
  225.  jmp clrchn  ;; and return
  226. ;
  227. ;
  228. ; stretst - set carry if non-zero error
  229. ;
  230. stretst lda strac ;; set carry if non-zero error
  231.  cmp #'0
  232.  bne t0810f
  233.  lda strac+1
  234.  cmp #'0
  235.  clc ;; assume good
  236.  beq t0820f
  237. t0810f sec  ;; error return
  238. t0820f rts  ;; error return
  239. ;
  240. ;
  241. ;
  242. ; strout, strbout
  243. ;  strout outputs string at (x,y),
  244. ;  using $57,$58 as pointer
  245. ;
  246. ; strbout calls strout with strac
  247. ;
  248. ; all registers are scratched
  249. ;
  250. strbout ldx #<strac
  251.  ldy #>strac
  252. strout stx $57
  253.  sty $58
  254.  ldy #0
  255. t0900b lda ($57),y
  256.  beq t0910f
  257.  jsr chrout
  258.  iny
  259.  bne t0900b
  260. t0910f rts
  261.