home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_27_1988_Transactor_Publishing.d64
/
shellram.sda
/
DPRINTF.A
< prev
next >
Wrap
Text File
|
2023-02-26
|
7KB
|
519 lines
;
; shellram
;
; By: Adrian Pepper
; Toronto, Ontario
;
; based on, but heavily modified from
; the Pro-Line/Spinnaker
; C POWER/POWER C shell for the
; Commodore 64 home computer.
;
; The shell was modified to reduce
; the size of the code, and arrange
; things so memory page 22 (hex $16)
; will be free for use as a "RAMdisk
; Interface Page", for use with the
; Commodore 1764 256K RAM expander
; for the Commodore 64
;
; This (basically) allows all programs
; designed to run under the shell to
; operate with the RAM disk
;
;
; dprintf.a - printf implementation
; routines
;
;
; It must be in the shell to save C
; program size. It would be nice to be
; able to link in the version from the
; distribution library disk, but several
; problems prevent this, so this version
; is provided here.
;
; also getnum routine used by shell
;
.ref stdoufl
;
.ref argstk
;
.ref chkout
.ref clrchn
.ref chrout
;
.def dprintf
.def dsprint
.def dfprint
;
.def getnum
;
.ref c$funct{CBM-@}init
.ref prfbuf ; must be forced above $1600 to $16ff page
; ; also we combine with 'strac' to save space
;
fltbuf=$0100 ; basic routine floating point conversion buffer
; ; lives in this precarious place!
;
dsprint jsr c$funct{CBM-@}init ; sprintf
lda argstk,x
sta $fb ; ptr to output str in fb,fc
inx
lda argstk,x
sta $fc
inx
stx $4c
lda #$00
jmp esprint
;
dprintf jsr c$funct{CBM-@}init ; printf
stx $4c
lda #$02
bne t0160f
;
dfprint jsr c$funct{CBM-@}init ; fprintf
lda argstk,x
inx
inx
stx $4c
t0160f cmp #2
bne t0170f
ldx stdoufl
bne t0170f
jsr clrchn
jmp eprintf
t0170f tax
jsr chkout
eprintf lda #$01
esprint sta $4d ; flag; 0 means sprintf
ldx $4c
lda argstk,x
inx
sta $fd ; fmt str addr in fd,fe
lda argstk,x
inx
sta $fe
stx $4c
ldy #$ff
prfmnlp iny
lda ($fd),y
bne t0190f
ldy $4d
bne t0180f
sta ($fb),y
t0180f jmp clrchn
t0190f cmp #'%
bne prfnper
jsr prfperc
lda ($fd),y
cmp #'d
bne prfnotd
jsr prfd
jmp prfparg
prfnotd cmp #'u
bne prfnotu
jsr prfu
jmp prfparg
prfnotu cmp #'x
bne prfnotx
jsr prfx
jmp prfparg
prfnotx cmp #'o
bne prfnoto
jsr prfo
jmp prfparg
prfnoto cmp #'c
bne prfnotc
jsr prfc
jmp prfparg
prfnotc cmp #'s
bne prfnots
jsr prfs
jmp prfparg
prfnots cmp #'f
bne prfnotf
jsr prff
jmp prfparg
prfnotf cmp #'g
bne prfnotg
jsr prfg
jmp prfparg
prfnotg cmp #0
beq prfnulb
jsr prfpfc
jmp prfmnlp
prfnulb dey
jmp prfmnlp
prfnper jsr prfpfc
jmp prfmnlp
prfpfc sty $51
ldy $4d
beq t0200f
ldy $51
jmp chrout
t0200f sta ($fb),y
inc $fb
bne t0210f
inc $fc
t0210f ldy $51
rts
prfgarg sty $4b
ldx $4c
lda argstk,x
sta $5a
inx
lda argstk,x
sta $5b
inx
stx $4c
lda #$00
sta $58
rts
prfu lda #$01
bne t0220f
prfd lda #$00
t0220f sta $51
jsr prfgarg
sta $54
lda $5b
bpl t0240f
ldy $51
bne t0240f
eor #$ff
sta $5b
lda $5a
eor #$ff
sta $5a
inc $5a
bne t0230f
inc $5b
t0230f lda #'-
sta prfbuf
inc $54
t0240f ldx #$04
t0250b ldy #$00
t0260b lda $5a
sec
sbc t0310f,x
sta $51
lda $5b
sbc t0320f,x
bcc t0270f
sta $5b
lda $51
sta $5a
iny
bne t0260b
t0270f tya
beq t0280f
sta $58
t0280f lda $58
beq t0290f
lda prfhext,y
ldy $54
sta prfbuf,y
inc $54
t0290f dex
bpl t0250b
ldx $54
prfnrts ldy $4b
lda $58
bne t0300f
lda #'0
sta prfbuf,x
inx
t0300f rts
t0310f .byte $01,$0a,$64,$e8,$10
t0320f .byte $00,$00,$00,$03,$27
prfg lda $1
pha
ora #$01
sta $1
sty $4b
clc
lda #$3c
adc $4c
ldy #$03
jsr $bba2
jsr $bddd
ldy #$00
ldx #$00
prfglp lda fltbuf,y
beq t0340f
cmp #$20
beq t0330f
sta prfbuf,x
inx
t0330f iny
jmp prfglp
t0340f clc
lda $4c
adc #$05
sta $4c
ldy $4b
pla
sta $1
rts
prff lda $1
pha
ora #$01
sta $1
sty $4b
clc
lda #$3c
adc $4c
ldy #$03
jsr $bba2
jsr $bddd
lda #0
sta $56
sta $55
sta $53
lda $50
bne t0350f
inc $56
t0350f bpl t0360f
lda #6
sta $50
t0360f ldy #0
ldx #0
prfflp lda fltbuf,y
beq t0400f
cmp #$20
beq t0390f
cmp #$45
bne t0370f
jsr prfexp
lda #0
sta $55
inc $53
lda #$45
t0370f sta $51
lda $55
beq t0375f
lda $50
beq t0390f
dec $50
t0375f lda $51
cmp #$2e
bne t0380f
lda $56
bne t0400f
inc $55
t0380f lda $51
sta prfbuf,x
inx
t0390f iny
jmp prfflp
t0400f clc
lda $4c
adc #5
sta $4c
ldy $4b
pla
sta $1
prfexp lda $56
bne t0430f
lda $53
bne t0430f
lda $55
bne t0410f
lda #$2e
sta prfbuf,x
inx
t0410f lda $50
beq t0430f
lda #$30
t0420b sta prfbuf,x
inx
dec $50
bne t0420b
t0430f rts
prfx jsr prfgarg
ldx #0
lda #4
sta $5c
t0440b lda $5b
lsr a
lsr a
lsr a
lsr a
tay
bne t0450f
lda $58
beq t0460f
t0450f lda prfhext,y
sta prfbuf,x
inx
stx $58
t0460f ldy #4
t0470b asl $5a
rol $5b
dey
bne t0470b
dec $5c
bne t0440b
jmp prfnrts
prfhext .byte "0123456789abcdef"
prfo jsr prfgarg
ldx #0
lda $5b
bpl t0480f
lda #$31
sta prfbuf
inx
stx $58
t0480f lda #$05
sta $5c
t0490b lda $5b
lsr a
lsr a
lsr a
lsr a
and #7
tay
bne t0500f
lda $58
beq t0510f
t0500f lda prfhext,y
sta prfbuf,x
inx
stx $58
t0510f ldy #$03
t0520b asl $5a
rol $5b
dey
bne t0520b
dec $5c
bne t0490b
jmp prfnrts
prfc ldx $4c
lda argstk,x
sta prfbuf
inx
inx
stx $4c
ldx #1
rts
prfs sty $4b
ldx $4c
lda argstk,x
sta $20
inx
lda argstk,x
sta $21
inx
stx $4c
ldy #0
t0530b lda $50
beq t0540f
lda ($20),y
beq t0540f
sta prfbuf,y
iny
dec $50
bne t0530b
t0540f tya
tax
ldy $4b
rts
prfperc lda #0 ; printf, percent found{CBM-N}
sta $4e
iny
lda ($fd),y
cmp #$2d
bne t0550f
inc $4e
iny
t0550f lda ($fd),y
cmp #$30
beq t0560f
lda #$20
t0560f sta $52
jsr prfgfld
sta $4f
lda ($fd),y
cmp #'.
bne t0570f
iny
jsr prfgfld
jmp t0580f
t0570f lda #$ff
t0580f sta $50
lda ($fd),y
cmp #$4c
bne t0590f
iny
t0590f rts
prfgfld lda ($fd),y
cmp #'*
bne t0600f
ldx $4c
lda argstk,x
inx
inx
stx $4c
iny
rts
;
t0600f jmp pfgnum ;; and return
;
prfparg stx $54
lda $4e
bne t0630f
jsr prfout
t0630f ldx #0
t0640f cpx $54
beq t0650f
lda prfbuf,x
jsr prfpfc
inx
bne t0640f
t0650f lda $4e
beq t0660f
jsr prfout
t0660f jmp prfmnlp
prfout sec
lda $4f
sbc $54
bcc t0680f
tax
beq t0680f
t0670f lda $52
jsr prfpfc
dex
bne t0670f
t0680f rts
;
;
; getnum - turn ptr in x,y to (small) number in a
; uses $fd,$fe, $5a,$5b (and y and a)
;
getnum = *
stx $fd
sty $fe
ldy #0
;
; pfgnum - special entry for printf use only
; assumes $fd,$fe and y set up already
;
pfgnum lda #$00
sta $5a
t0610b lda ($fd),y
eor #'0 ;; assumes ascii
cmp #10
bcs t0620f
sta $5b
lda $5a
asl $5a
asl $5a
adc $5a
asl a
adc $5b
sta $5a
iny
bne t0610b
t0620f lda $5a
rts