home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_27_1988_Transactor_Publishing.d64 / shellram.sda / DPRINTF.A < prev    next >
Text File  |  2023-02-26  |  7KB  |  519 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. ; dprintf.a - printf implementation
  26. ;   routines
  27. ;
  28. ;
  29. ;  It must be in the shell to save C
  30. ; program size.  It would be nice to be
  31. ; able to link in the version from the
  32. ; distribution library disk, but several
  33. ; problems prevent this, so this version
  34. ; is provided here.
  35. ;
  36. ;  also getnum routine used by shell
  37. ;
  38.  .ref stdoufl
  39. ;
  40.  .ref argstk
  41. ;
  42.  .ref chkout
  43.  .ref clrchn
  44.  .ref chrout
  45. ;
  46.  .def dprintf
  47.  .def dsprint
  48.  .def dfprint
  49. ;
  50.  .def getnum
  51. ;
  52.  .ref c$funct{CBM-@}init
  53.  .ref prfbuf  ; must be forced above $1600 to $16ff page
  54. ;             ; also we combine with 'strac' to save space
  55. ;
  56. fltbuf=$0100  ; basic routine floating point conversion buffer
  57. ;             ;  lives in this precarious place!
  58. ;
  59. dsprint jsr c$funct{CBM-@}init  ; sprintf
  60.  lda argstk,x
  61.  sta $fb ; ptr to output str in fb,fc
  62.  inx
  63.  lda argstk,x
  64.  sta $fc
  65.  inx
  66.  stx $4c
  67.  lda #$00
  68.  jmp esprint
  69. ;
  70. dprintf jsr c$funct{CBM-@}init  ; printf
  71.  stx $4c
  72.  lda #$02
  73.  bne t0160f
  74. ;
  75. dfprint jsr c$funct{CBM-@}init  ; fprintf
  76.  lda argstk,x
  77.  inx
  78.  inx
  79.  stx $4c
  80. t0160f cmp #2
  81.  bne t0170f
  82.  ldx stdoufl
  83.  bne t0170f
  84.  jsr clrchn
  85.  jmp eprintf
  86. t0170f tax
  87.  jsr chkout
  88. eprintf lda #$01
  89. esprint sta   $4d ; flag; 0 means sprintf
  90.  ldx $4c
  91.  lda argstk,x
  92.  inx
  93.  sta   $fd ; fmt str addr in fd,fe
  94.  lda argstk,x
  95.  inx
  96.  sta  $fe
  97.  stx $4c
  98.  ldy #$ff
  99. prfmnlp iny
  100.  lda ($fd),y
  101.  bne t0190f
  102.  ldy $4d
  103.  bne t0180f
  104.  sta ($fb),y
  105. t0180f jmp clrchn
  106. t0190f cmp #'%
  107.  bne prfnper
  108.  jsr prfperc
  109.  lda ($fd),y
  110.  cmp #'d
  111.  bne prfnotd
  112.  jsr prfd
  113.  jmp prfparg
  114. prfnotd cmp #'u
  115.  bne prfnotu
  116.  jsr prfu
  117.  jmp prfparg
  118. prfnotu cmp #'x
  119.  bne prfnotx
  120.  jsr prfx
  121.  jmp prfparg
  122. prfnotx cmp #'o
  123.  bne prfnoto
  124.  jsr prfo
  125.  jmp prfparg
  126. prfnoto cmp #'c
  127.  bne prfnotc
  128.  jsr prfc
  129.  jmp prfparg
  130. prfnotc cmp #'s
  131.  bne prfnots
  132.  jsr prfs
  133.  jmp prfparg
  134. prfnots cmp #'f
  135.  bne prfnotf
  136.  jsr prff
  137.  jmp prfparg
  138. prfnotf cmp #'g
  139.  bne prfnotg
  140.  jsr  prfg
  141.  jmp  prfparg
  142. prfnotg cmp #0
  143.  beq prfnulb
  144.  jsr prfpfc
  145.  jmp prfmnlp
  146. prfnulb dey
  147.  jmp prfmnlp
  148. prfnper jsr prfpfc
  149.  jmp prfmnlp
  150. prfpfc sty $51
  151.  ldy $4d
  152.  beq t0200f
  153.  ldy $51
  154.  jmp chrout
  155. t0200f sta ($fb),y
  156.  inc $fb
  157.  bne t0210f
  158.  inc $fc
  159. t0210f ldy $51
  160.  rts
  161. prfgarg sty $4b
  162.  ldx $4c
  163.  lda argstk,x
  164.  sta  $5a
  165.  inx
  166.  lda argstk,x
  167.  sta  $5b
  168.  inx
  169.  stx $4c
  170.  lda #$00
  171.  sta  $58
  172.  rts
  173. prfu lda #$01
  174.  bne t0220f
  175. prfd lda #$00
  176. t0220f sta  $51
  177.  jsr prfgarg
  178.  sta  $54
  179.  lda  $5b
  180.  bpl t0240f
  181.  ldy $51
  182.  bne t0240f
  183.  eor #$ff
  184.  sta $5b
  185.  lda $5a
  186.  eor #$ff
  187.  sta  $5a
  188.  inc $5a
  189.  bne t0230f
  190.  inc $5b
  191. t0230f lda  #'-
  192.  sta prfbuf
  193.  inc $54
  194. t0240f ldx #$04
  195. t0250b ldy #$00
  196. t0260b lda  $5a
  197.  sec
  198.  sbc t0310f,x
  199.  sta  $51
  200.  lda  $5b
  201.  sbc t0320f,x
  202.  bcc t0270f
  203.  sta  $5b
  204.  lda  $51
  205.  sta  $5a
  206.  iny
  207.  bne t0260b
  208. t0270f tya
  209.  beq t0280f
  210.  sta  $58
  211. t0280f lda  $58
  212.  beq t0290f
  213.  lda prfhext,y
  214.  ldy $54
  215.  sta prfbuf,y
  216.  inc $54
  217. t0290f dex
  218.  bpl t0250b
  219.  ldx $54
  220. prfnrts ldy $4b
  221.  lda  $58
  222.  bne t0300f
  223.  lda  #'0
  224.  sta prfbuf,x
  225.  inx
  226. t0300f rts
  227. t0310f .byte $01,$0a,$64,$e8,$10
  228. t0320f .byte $00,$00,$00,$03,$27
  229. prfg lda  $1
  230.  pha
  231.  ora #$01
  232.  sta  $1
  233.  sty $4b
  234.  clc
  235.  lda #$3c
  236.  adc $4c
  237.  ldy #$03
  238.  jsr $bba2
  239.  jsr $bddd
  240.  ldy #$00
  241.  ldx #$00
  242. prfglp lda fltbuf,y
  243.  beq t0340f
  244.  cmp #$20
  245.  beq t0330f
  246.  sta prfbuf,x
  247.  inx
  248. t0330f iny
  249.  jmp prfglp
  250. t0340f clc
  251.  lda  $4c
  252.  adc #$05
  253.  sta $4c
  254.  ldy $4b
  255.  pla
  256.  sta $1
  257.  rts
  258. prff lda $1
  259.  pha
  260.  ora #$01
  261.  sta  $1
  262.  sty $4b
  263.  clc
  264.  lda #$3c
  265.  adc $4c
  266.  ldy #$03
  267.  jsr $bba2
  268.  jsr $bddd
  269.  lda #0
  270.  sta  $56
  271.  sta  $55
  272.  sta  $53
  273.  lda  $50
  274.  bne t0350f
  275.  inc $56
  276. t0350f bpl t0360f
  277.  lda #6
  278.  sta  $50
  279. t0360f ldy #0
  280.  ldx #0
  281. prfflp lda fltbuf,y
  282.  beq t0400f
  283.  cmp #$20
  284.  beq t0390f
  285.  cmp #$45
  286.  bne t0370f
  287.  jsr prfexp
  288.  lda #0
  289.  sta  $55
  290.  inc $53
  291.  lda #$45
  292. t0370f sta $51
  293.  lda  $55
  294.  beq t0375f
  295.  lda  $50
  296.  beq t0390f
  297.  dec $50
  298. t0375f lda $51
  299.  cmp #$2e
  300.  bne t0380f
  301.  lda  $56
  302.  bne t0400f
  303.  inc $55
  304. t0380f lda $51
  305.  sta prfbuf,x
  306.  inx
  307. t0390f iny
  308.  jmp prfflp
  309. t0400f clc
  310.  lda $4c
  311.  adc #5
  312.  sta $4c
  313.  ldy $4b
  314.  pla
  315.  sta $1
  316. prfexp lda $56
  317.  bne t0430f
  318.  lda $53
  319.  bne t0430f
  320.  lda $55
  321.  bne t0410f
  322.  lda #$2e
  323.  sta prfbuf,x
  324.  inx
  325. t0410f lda $50
  326.  beq t0430f
  327.  lda #$30
  328. t0420b sta prfbuf,x
  329.  inx
  330.  dec $50
  331.  bne t0420b
  332. t0430f rts
  333. prfx jsr prfgarg
  334.  ldx #0
  335.  lda #4
  336.  sta  $5c
  337. t0440b lda $5b
  338.  lsr a
  339.  lsr a
  340.  lsr a
  341.  lsr a
  342.  tay
  343.  bne t0450f
  344.  lda  $58
  345.  beq t0460f
  346. t0450f lda prfhext,y
  347.  sta prfbuf,x
  348.  inx
  349.  stx $58
  350. t0460f ldy #4
  351. t0470b asl $5a
  352.  rol $5b
  353.  dey
  354.  bne t0470b
  355.  dec $5c
  356.  bne t0440b
  357.  jmp prfnrts
  358. prfhext .byte "0123456789abcdef"
  359. prfo jsr prfgarg
  360.  ldx #0
  361.  lda $5b
  362.  bpl t0480f
  363.  lda #$31
  364.  sta prfbuf
  365.  inx
  366.  stx $58
  367. t0480f lda #$05
  368.  sta  $5c
  369. t0490b lda  $5b
  370.  lsr a
  371.  lsr a
  372.  lsr a
  373.  lsr a
  374.  and #7
  375.  tay 
  376.  bne t0500f
  377.  lda $58
  378.  beq t0510f
  379. t0500f lda prfhext,y
  380.  sta prfbuf,x
  381.  inx
  382.  stx $58
  383. t0510f ldy #$03
  384. t0520b asl $5a
  385.  rol $5b
  386.  dey
  387.  bne t0520b
  388.  dec $5c
  389.  bne t0490b
  390.  jmp prfnrts
  391. prfc ldx $4c
  392.  lda argstk,x
  393.  sta prfbuf
  394.  inx
  395.  inx
  396.  stx $4c
  397.  ldx #1
  398.  rts
  399. prfs sty $4b
  400.  ldx $4c
  401.  lda argstk,x
  402.  sta  $20
  403.  inx
  404.  lda argstk,x
  405.  sta  $21
  406.  inx
  407.  stx $4c
  408.  ldy #0
  409. t0530b lda $50
  410.  beq t0540f
  411.  lda ($20),y
  412.  beq t0540f
  413.  sta prfbuf,y
  414.  iny
  415.  dec $50
  416.  bne t0530b
  417. t0540f tya
  418.  tax
  419.  ldy $4b
  420.  rts
  421. prfperc lda #0 ; printf, percent found{CBM-N}
  422.  sta  $4e
  423.  iny
  424.  lda ($fd),y
  425.  cmp #$2d
  426.  bne t0550f
  427.  inc $4e
  428.  iny
  429. t0550f lda ($fd),y
  430.  cmp #$30
  431.  beq t0560f
  432.  lda #$20
  433. t0560f sta  $52
  434.  jsr prfgfld
  435.  sta  $4f
  436.  lda ($fd),y
  437.  cmp #'.
  438.  bne t0570f
  439.  iny
  440.  jsr prfgfld
  441.  jmp t0580f
  442. t0570f lda #$ff
  443. t0580f sta  $50
  444.  lda ($fd),y
  445.  cmp #$4c
  446.  bne t0590f
  447.  iny
  448. t0590f rts
  449. prfgfld lda ($fd),y
  450.  cmp #'*
  451.  bne t0600f
  452.  ldx $4c
  453.  lda argstk,x
  454.  inx
  455.  inx
  456.  stx $4c
  457.  iny
  458.  rts
  459. ;
  460. t0600f jmp pfgnum ;; and return
  461. ;
  462. prfparg stx $54
  463.  lda $4e
  464.  bne t0630f
  465.  jsr prfout
  466. t0630f ldx #0
  467. t0640f cpx $54
  468.  beq t0650f
  469.  lda prfbuf,x
  470.  jsr prfpfc
  471.  inx
  472.  bne t0640f
  473. t0650f lda $4e
  474.  beq t0660f
  475.  jsr prfout
  476. t0660f jmp prfmnlp
  477. prfout sec
  478.  lda  $4f
  479.  sbc $54
  480.  bcc t0680f
  481.  tax
  482.  beq t0680f
  483. t0670f lda $52
  484.  jsr prfpfc
  485.  dex
  486.  bne t0670f
  487. t0680f rts
  488. ;
  489. ;
  490. ; getnum - turn ptr in x,y to (small) number in a
  491. ;   uses $fd,$fe, $5a,$5b (and y and a)
  492. ;
  493. getnum = *
  494.  stx $fd
  495.  sty $fe
  496.  ldy #0
  497. ;
  498. ; pfgnum - special entry for printf use only
  499. ;  assumes $fd,$fe and y set up already
  500. ;
  501. pfgnum lda #$00
  502.  sta  $5a
  503. t0610b lda ($fd),y
  504.  eor #'0  ;; assumes ascii
  505.  cmp #10
  506.  bcs t0620f
  507.  sta  $5b
  508.  lda  $5a
  509.  asl $5a
  510.  asl $5a
  511.  adc $5a
  512.  asl a
  513.  adc $5b
  514.  sta $5a
  515.  iny
  516.  bne t0610b
  517. t0620f lda $5a
  518.  rts
  519.