home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_27_1988_Transactor_Publishing.d64
/
shellram.sda
/
SHELLSTR.A
< prev
next >
Wrap
Text File
|
2023-02-26
|
4KB
|
261 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
;
;
; shellstr.a
;
; routines for doing
; string manipulation
;
; use of these routines accounts for a
; lot of the space saving
;
;
.ref wrkdev
;
; kernal routines, etc
;
.ref setlfs
.ref setnam
.ref open
.ref chkin
.ref clrchn
.ref chrin
.ref chrout
;
;
; shellstr - utility routines to work
; with a zero-terminated "string
; accumulator" at a fixed address
;
;
.ref strac ;; same as prfbuf, remember
.ref kwrkfil
.ref ksysfil
;
.def strclr
.def strend
.def strload
.def strapnd
.def streq
.def stropen
.def strfopn
.def strechn
.def stretst
.def strout
.def strbout
;
;
; strclr - zero work string buffer
; input regs: none
; a is always set to zero
;
strclr lda #0
sta strac
rts
;
;
; strend - set x to length of strac
; x should be set before call
; (in case multiple strings are in
; strac)
;
; output: x - length of strac
;
strend lda strac,x
inx
cmp #0
bne strend
dex ; point back at end
rts
;
;
; strapnd - copy string at (x,y) to
; end of strac
;
; output: x new length of strac
; y length of string (x,y)+1
; a always 0
; $57,$58 used to store x,y
;
strapnd stx $57
sty $58
ldx #0
jsr strend
ldy #0
t0100b lda ($57),y
iny
sta strac,x
inx
cmp #0
bne t0100b
;jsr strbout
dex ; point at '\0' terminator
;lda #'_
;jsr chrout
;lda #$0d
;jsr chrout
rts
;
;
; strload - copy string at (x,y) to
; strac
;
; output: x new length of strac
; y length of string (x,y)+1
; a always 0
; $57,$58 used to store x,y
;
strload jsr strclr
jmp strapnd ;; and return
;
;
; streq - compare string at (x,y) to
; strac for equality
;
; output:
; z cc - equal/not
; x - unchanged
; y - index of differing char
; a - char of (x,y) that differed (or '\0')
; $57,$58 - x,y
;
streq stx $57
sty $58
ldy #0
t0200b lda ($57),y
cmp strac,y
bne t0210f ;; return not equal
iny
cmp #0
bne t0200b ;; or fall through, return equal
t0210f rts ;; equal
;
;
; stropen - open strac
;
; a,x,y are used as a call to setlfs
; strac is assumed as a '\0' terminated
; string, and used for call to setnam
;
; all registers plus strac should be
; considered scratched
;
stropen jsr setlfs
ldx #0
jsr strend
txa ;; length of strac in a
ldx #<strac
ldy #>strac ;; setup for setnam
jsr setnam
jmp open ;; and return, with carry
;
;
; strfopn - open strac as a file
;
; a,x,y are used as a call to setlfs
; strac is assumed as a '\0' terminated
; string, and used for call to setnam
;
; if open fails, an error message is
; copied to strac, and carry is set
;
; all registers plus strac should be
; considered scratched
;
strfopn stx savdev
jsr stropen
ldx savdev
jmp strechn
savdev .bss 1
;
;
; strechn - read error channel for device
; given in x
;
; replaces strac with error channel line
;
; error line won't be printed, though
; carry will be set if error line is non-zero
;
strechn lda #<kwrkfil
cpx wrkdev
beq t0595f
lda #<ksysfil
t0595f tax
jsr chkin
jsr strget
jmp stretst
;
;
; strget - read a line from current
; chkin file,
; then do a clrchn
;
strget ldy #0
t0700b jsr chrin
sta strac,y
iny
bcs t0710f
cmp #$0d
bne t0700b
; should check eof
t0710f lda #0
sta strac,y
jmp clrchn ;; and return
;
;
; stretst - set carry if non-zero error
;
stretst lda strac ;; set carry if non-zero error
cmp #'0
bne t0810f
lda strac+1
cmp #'0
clc ;; assume good
beq t0820f
t0810f sec ;; error return
t0820f rts ;; error return
;
;
;
; strout, strbout
; strout outputs string at (x,y),
; using $57,$58 as pointer
;
; strbout calls strout with strac
;
; all registers are scratched
;
strbout ldx #<strac
ldy #>strac
strout stx $57
sty $58
ldy #0
t0900b lda ($57),y
beq t0910f
jsr chrout
iny
bne t0900b
t0910f rts