home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_24_1988_Transactor_Publishing.d64 / concat.a < prev    next >
Text File  |  2023-02-26  |  4KB  |  303 lines

  1. argstk = $033c
  2. sysdev = $17fa
  3. sysdrv = $17fb
  4. wrkdev = $17fc
  5. wrkdrv = $17fd
  6. s2000 = $2000
  7. ;
  8. setlfs = $ffba
  9. setnam = $ffbd
  10. open = $ffc0
  11. close = $ffc3
  12. chkin = $ffc6
  13. chkout = $ffc9
  14. clrchn = $ffcc
  15. chrin = $ffcf
  16. chrout = $ffd2
  17. readst = $ffb7
  18. load = $ffd5
  19. getin = $ffe4
  20. ;
  21. ;
  22. ;
  23. ; * = $1800  ;; use link -s $1800
  24. ;
  25. usrprog = *
  26.  jsr clrchn
  27.  lda #15
  28.  ldx wrkdev
  29.  tay
  30.  jsr setlfs
  31.  lda #3
  32.  ldx #<sm$r
  33.  ldy #>sm$r
  34.  jsr setnam
  35.  jsr open
  36. ;
  37.  lda #0
  38.  sta dstnam+2
  39. ;
  40.  lda argstk+2
  41.  sta $4b
  42.  lda argstk+3
  43.  sta $4c
  44. ;
  45.  inc argstk  ;; goes to zero when done
  46.  jsr getarg
  47.  bne arglp
  48.  jmp usage
  49. ;
  50. arglp = *
  51.  jsr getarg
  52.  beq done
  53.  lda ($4d),y
  54.  cmp #'-
  55.  bne nodash
  56. dashlp iny
  57.  lda ($4d),y
  58.  beq t0130f
  59.  jmp dashlp
  60. t0120f jmp usage
  61.  jmp dashlp
  62. t0130f jmp arglp
  63. ;
  64. nodash = *
  65.  lda dstnam+2
  66.  bne sources
  67.  jsr opndst
  68.  bcc arglp
  69.  jmp bad
  70. ;
  71. sources = *
  72.  jsr opnsrc
  73.  bcs bad
  74.  jsr tcopy   ; copies 3 to 2, closes 3
  75.  lda #3
  76.  jsr close
  77.  jmp arglp
  78. ;
  79. done = *
  80.  lda dstnam+2
  81.  bne okay
  82. ;
  83. bad = *
  84.  lda #3
  85.  jsr close
  86. ;
  87. okay = *
  88.  lda #2
  89.  jsr close
  90.  jsr chkchn ; but ignore result
  91.  jsr clrchn
  92.  lda #15
  93.  jmp close  ; and return to shell
  94. ;
  95. ;
  96. ;
  97. ;
  98. ; getarg - put next arg pointer into ($4d,$4e)
  99. ;  y is set to zero
  100. ;  argv is incremented
  101. ;  argc is decremented
  102. ;
  103. getarg = *
  104.  ldy #1
  105.  lda ($4b),y
  106.  sta $4e
  107.  dey
  108.  lda ($4b),y
  109.  sta $4d
  110.  clc
  111.  lda $4b
  112.  adc #2
  113.  sta $4b
  114.  bcc t0200f
  115.  inc $4c
  116. t0200f dec argstk
  117.  rts
  118. ;
  119. ;
  120. ; opndst - open destination file from current arg
  121. ;
  122. opndst = *
  123.  lda #2
  124.  ldx wrkdev
  125.  tay
  126.  jsr setlfs
  127.  lda wrkdrv
  128.  clc
  129.  adc #'0
  130.  sta dstnam
  131.  ldy #0
  132.  ldx #2
  133. t0310b lda ($4d),y
  134.  sta dstnam,x  ;; file name including '\0' is stored
  135.  beq t0320f
  136.  iny
  137.  inx
  138.  bne t0310b
  139. t0320f stx dstlen
  140.  lda #',
  141.  sta dstnam,x
  142.  inx
  143.  lda #'w
  144.  sta dstnam,x
  145.  inx
  146.  lda #0
  147.  sta dstnam,x
  148.  txa
  149.  ldx #<dstnam
  150.  ldy #>dstnam
  151.  jsr setnam
  152.  jsr open    ; 2,work,2,dstnam,w
  153.  jsr chkchn
  154.  bcc t0330f
  155.  ldx #<scnoof
  156.  ldy #>scnoof
  157.  jmp outstr  ; and return
  158. t0330f rts  ;; carry clear; okay
  159. ;
  160. ;
  161. ;
  162. opnsrc lda #3
  163.  ldx wrkdev
  164.  tay
  165.  jsr setlfs
  166.  ldy #$ff
  167. t0410b iny
  168.  lda ($4d),y
  169.  bne t0410b
  170.  tya
  171.  ldx $4d
  172.  ldy $4e
  173.  jsr setnam
  174.  jsr open   ; 3,work,3,source
  175.  jsr chkchn
  176.  bcc t0420f
  177.  ldx #<scno
  178.  ldy #>scno
  179.  jsr outstr
  180.  ldx $4d
  181.  ldy $4e
  182.  jsr outstr
  183.  ldx #<snl
  184.  ldy #>snl
  185.  jmp outstr  ; and return
  186. t0420f rts
  187. ;
  188. ; tcopy - copy (opened) 3 to 2
  189. ;
  190. tcopy = *
  191.  ldx #3
  192.  jsr chkin
  193.  ldx #<buff
  194.  ldy #>buff
  195.  lda #254
  196.  jsr getblk
  197.  pha  ; save readst
  198.  ldx #2
  199.  jsr chkout
  200.  tya ; transfer count
  201.  ldx #<buff
  202.  ldy #>buff
  203.  jsr putblk
  204.  pla  ; get back readst
  205.  beq tcopy
  206. ;
  207.  jsr clrchn
  208.  lda #3
  209.  jmp close   ; and return
  210. char .bss 1
  211. ;
  212. ; getblk max (x,y)
  213. ;
  214. ;  returns readst
  215. ;    y is count
  216. ;
  217. ; c64 kernal is such block must be
  218. ;  at least 1 char
  219. ;
  220. getblk = *
  221.  stx $22
  222.  sty $23
  223.  sta $24
  224.  ldy #0
  225. t0510 jsr chrin
  226.  sta ($22),y
  227.  iny
  228.  jsr readst
  229.  bne t0520
  230.  cpy $24
  231.  bne t0510
  232. t0520 rts
  233. ;
  234. ;
  235. putblk = *
  236.  stx $22
  237.  sty $23
  238.  sta $24
  239.  ldy #0
  240.  beq t0540
  241. t0530 lda ($22),y
  242.  jsr chrout
  243.  iny
  244. t0540 cpy $24
  245.  bne t0530
  246.  rts
  247. ;
  248. ;
  249. ; chkchn - check error channel
  250. ;
  251. chkchn ldx #15
  252.  jsr chkin
  253.  jsr chrin
  254.  cmp #'0
  255.  bne t0730f
  256.  jsr chrin
  257.  cmp #'0
  258. t0730f php
  259. t0740b jsr chrin
  260.  cmp #$0d
  261.  bne t0740b
  262.  jsr clrchn
  263.  plp
  264.  clc
  265.  beq t0750f
  266.  sec  ;; carry indicates error
  267. t0750f rts  ;; carry clear; okay
  268. ;
  269. ;
  270. ;
  271. ; usage - give error message
  272. ;
  273. usage ldx #<susage
  274.  ldy #>susage
  275. ;
  276. ; sets carry, since all messages are errors
  277. ;
  278. outstr stx $4b
  279.  sty $4c
  280.  ldy #0
  281. t1000b lda ($4b),y
  282.  beq t1010f
  283.  jsr chrout
  284.  iny
  285.  bne t1000b
  286. t1010f sec
  287.  rts
  288. ;
  289. ;
  290. susage .byte "usage: concat filename" 
  291.  .byte " [filename...]"
  292.  .byte $0d, $0d, $00
  293. scnoof .byte "cannot open output file"
  294.  .byte $0d, $0d, $00
  295. scno .byte "cannot open: "
  296.  .byte $00
  297. sm$r .byte "m-r"
  298. snl .byte $0d, $0d, $00
  299. dstlen .byte $00
  300. dstnam .byte "0:"
  301.  .bss 22
  302. buff = *
  303.