home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_24_1988_Transactor_Publishing.d64
/
sd4.bud
< prev
next >
Wrap
Text File
|
2023-02-26
|
22KB
|
1,047 lines
;**************************************
;* sdir *
;* *
;* universal scrolling *
;* directory reader *
;* for c-128 and *
;* 1541, 1571 or 1581 *
;* *
;* ver 4.0 *
;* *
;* <c> 1987 m. garamszeghy *
;* 87-09-01 *
;* *
;**************************************
;
;--- boot entry = SYS 4864 ($1300)= init
;
;--- activate from basic by
; sd "pattern",u<disk device#>,p<printer device#>,w<printer width>
;
;
;------------ zero page pointers
;
p1 =$fa
p2 =$fc
p3 =$fe
;
;------------ addresses
;
bottom =$e4 ; screen windows
top =$e5
left =$e6
right =$e7
;
flag80 =$00d7 ; screen width flag =40 or 80
basbuf =$0200 ; basic input buffer
icrunch =$0304 ; crunch basic command line
eof =$1210 ; end of basic text pointer
bashi =$1212 ; top of basic pointer
ocrunch =$430d ; normal basic crunch vector
;
; --- work space storage
;
dirent =$0d00 ; number of directory entries
prn =$0d02 ; printer device
psec =$0d03 ; printer secondary address
width =$0d04 ; printer width
drive =$0d05 ; disk drive device number
;
scrollp =$0d06 ; scroll pointer
dirp =$0d07 ; directory pointer
lastkey =$0d09 ; last key press
;
;
dirbuf =$c000 ; directory buffer
combuf =$0c00 ; disk command and error buffer
nambuf =$0d60 ; disk name buffer
pattern =$0d20 ; directory pattern
frebuf =$0db8 ; blocks free buffer
filbuf =$0da0 ; files found buffer
;
work1 =$0d10 ; temporary storage
work2 =$0d12
work3 =$0d14
work4 =$0d16
work5 =$0d18
;
comlen =$0d0a ; length of disk command
errlen =$0d0b ; length of error message
stat =$0d0c ; error status flag
len =$0d0d ; file name length
;
mmu =$ff00 ; registers
;
setlfs =$ffba ; kernal routines
setnam =$ffbd
open =$ffc0
close =$ffc3
closeall =$ffe7
chkin =$ffc6
chkout =$ffc9
clrchn =$ffcc
chrin =$ffcf
getin =$ffe4
chrout =$ffd2
status =$ffb7
write =$ff7d
plot =$fff0
stop =$ffe1
setbank =$ff68
kload =$ffd5
pfkey =$ff65
;
convfp =$84c9 ; basic rom routines
convasc =$8e44
;
;
;
;
.org $1300 ; unused bank 0 ram
.obj "0:sd4"
.fast
jmp init ; bypass defaults
;
;
; default system values
;
unit =*
.byt 8 ; default disk drive device number
prtr =*
.byt 4 ; default device number for printer
prtrsec =*
.byt 4 ; default printer sec address (CARDCO, transparent)
cols =*
.byt 96 ; default printer width in increments of 32
compress =*
.byt 15 ; set compressed print (values for EPSON printer)
compoff =*
.byt 18 ; turn off compressed print
expand =*
.byt 14 ; set expanded print
exoff =*
.byt 20 ; expanded off
;
;
init =* ; boot entry point
ldx #0 ; clear screen
stx p1+2
jsr setwindow
jsr bootmessage ; and greetings
lda #$cf ; set top of basic to $bfff
sta bashi+1
lda #$ff
sta bashi
lda <sdir ; set basic crunch pointer
sta icrunch ; to point to custom routine
lda >sdir
sta icrunch+1
jsr write
.byt 13,13
.asc "syntax: sd ":.byt 34:.asc "pattern":.byt 34:.asc ",u<device#>"
.byt 13,0
lda <key ; redefine <f3> key
sta p1
lda >key
sta p1+1
lda #p1
ldy #4
ldx #3
jmp pfkey ; go back to basic
;
key =*
.byt 13:.asc "sd":.byt 13 ; redefine f3
;
bootmessage =*
jsr write
.asc "sdir 4.0 <c>1987 m. garamszeghy"
.byt 0
rts
;
endsdir =* ; exit routine and return to basic
lda #0
sta mmu
jsr closeall ; close all channels
end2 =*
ldx #0 ; clear screen, reset window
jmp setwindow ; and bye
;
pat =*
.asc "$0:" ; default directory pattern
;
sdir =* ; main entry point
lda basbuf ; check for sdir command
cmp #"s"
bne notsdir ; exit to normal basic crunch if no match
lda basbuf+1
cmp #"d"
beq letsgo ; complete match
;
notsdir =* ; exit to main basic crunch routine
jmp ocrunch
;
letsgo =*
lda #0
sta mmu ; make sure in bank 15
tay
z1 sta dirent,y ; clear all pointers
iny
bne z1
;
jsr clrchn ; reset default i/o
jsr closeall
ldx #0
jsr setwindow ; clear screen
ldx #3
jsr setwindow ; title block
jsr bootmessage
ldx #1
jsr setwindow ; data window
;
; -- set defaults
;
lda unit ; default disk drive device #
sta drive
lda cols ; # printer columns
sta width
lda prtr ; printer device #
sta prn
lda prtrsec ; printer secondary address
sta psec
;
ldy #0 ; default dir pattern
- lda pat,y
sta pattern,y
iny
cpy #3
bne -
dey ; default pattern length
sty len
;
ldy #0 ; re-set index
z3 lda basbuf,y ; parse rest of command buffer for parameters
bne + ; end of command on 0
jmp nomatch
+ cmp #34 ; check for quote
beq match
cmp #"u" ; check for "u"
beq chkunit ; get unit number
cmp #"p" ; check for "p"
beq chkprn ; get printer #
cmp #"w" ; check for "w"
beq chkwid ; get printer width
;
nb =*
iny ; next byte
bne z3 ; and try again
beq nomatch
;
chkunit =* ; check for unit number
jsr nparse ; parse ascii string
bne z4 ; valid value
lda unit ; else get default
z4 sta drive
bne nb ; go back for more
;
chkprn =* ; check for printer number
jsr nparse
bne z5
lda prtr ; default
z5 sta prn
bne nb
;
chkwid =* ; check printer column width
jsr nparse
and #7 ; mask lo bits
tax
lda widths,x ; look in table
sta width ; and save it
jmp nb
;
widths =* ; width table
.byt 64, 64, 64, 96, 128, 160, 192, 64
;
nparse =* ; parse ascii number to hex digit
iny
lda basbuf,y ; get next char
and #15 ; mask lo nibble
cmp #1
bne eparse ; single digit
iny
lda basbuf,y ; second digit
and #3 ; isolate low 2 bits
clc
adc #10 ; make into teen
eparse =*
rts ; return
;
match =*
ldx #0 ; reset filename pointer
getnext =*
iny
lda basbuf,y ; transfer match to pattern buffer
sta work3
beq eol ; end of line
cmp #34 ; end of quote
beq eol
sta pattern+3,x
inx
bne getnext
eol =*
cpx #0 ; check for valid pattern length
beq nomatch
inx ; increase by 1
txa
clc
adc len ; new pattern length
sta len
lda work3
bne nb
;
nomatch =*
lda #0
sta basbuf ; clear keyboard buffer
;
lda #14
ldx drive
ldy #15 ; open command channel
jsr setlfs
lda #0
jsr setnam
jsr open
bcc dir
jmp error1 ; abort on error
;
;---- execute directory
;
dir =*
lda #"i" ; send "i0" command to drive
sta combuf
lda #"0"
sta combuf+1
lda #2
sta comlen
jsr sendcom
lda stat ; abort on error
beq d1
jmp endsdir
d1 jsr readcom ; read error channel
lda combuf
cmp #"0"
beq cont
x1 jsr error1 ; abort on error
jmp endsdir
;
cont =*
jsr setdir ; init buffer pointers
ldx #1
jsr setwindow ; set display window
jsr write
.asc "working..." ; status message
.byt 0
;
lda #1
ldx drive
ldy #0
jsr setlfs ; open directory channel as #1
lda len
ldx <pattern
ldy >pattern
jsr setnam
lda #0
tax
jsr setbank
jsr open
jsr readcom ; check errors
lda combuf
cmp #"0"
bne x1
;
ldx #1 ; set input channel
jsr chkin
ldy #0 ; reset pointer
sty dirent ; clear # of filenames
sty dirent+1
;
readnam =* ; read disk name
r1 jsr readbyte ; get a disk byte
bcc r2
jmp getout ; exit if no more, else
;
r2 cmp #34 ; check for quote
bne r1 ; and wait
;
nextnam =* ; read name bytes
jsr readbyte
cmp #34 ; check for closing quote
beq nextnam ; skip
sta nambuf,y ; stash disk name
iny
cpy #22 ; check for end of header
bne nextnam
;
nextfil =* ; read filenames
lda #32 ; fill entry position with spaces
ldy #0
n1 jsr stashbyte
iny
cpy #32
bne n1
n2 jsr readbyte
bcc n3
jmp getout ; end of dir
n3 bne n2 ; looking for zero byte
jsr readbyte ; bypass 2 bytes
jsr readbyte
bcc n4
jmp getout
n4 jsr readbyte ; get lo byte of file length
sta work4
jsr readbyte ; get hi byte
ldx work4 ; recover lo byte
jsr convert
ldy #22
n5 lda 234,y ; get # blocks in ascii
beq n6 ; end on zero byte
jsr stashbyte ; save byte in bank 0 buffer
iny ; next byte
bne n5
n6 ldy #0 ; set to dir entry position
n7 jsr readbyte
bcc n8
jmp getout
n8 cmp #34 ; check for leading quote
bne n7
n9 jsr readbyte; get another char
bcc n10
jmp getout
n10 cmp #34
beq n9 ; skip trailing quote
jsr stashbyte
iny
cpy #22 ; read 22 bytes
bne n9
jsr add32 ; increment p2 by 32 bytes
inc dirent ; increment # of dir entries lo byte
bne n11
inc dirent+1 ; and hi byte if required
n11 jmp nextfil ; get next file
;
free =*
.asc "blocks free "
;
;
getout =* ; end dir read
jsr clrchn ; restore i/o
lda #1 ; close directory channel
jsr close
ldy #22
g1 jsr getbyte ; move blocks free to blocks free buffer
sta frebuf-22,y
iny
cpy #32
bne g1
ldy #0
g2 lda free,y ; blocks free message to buffer
sta frebuf+5,y
iny
cpy #12
bne g2
lda #$ff ; end of dir marker
ldy #0
jsr stashbyte
;
exitdir =*
ldx #3
jsr setwindow
jsr bootmessage
ldx #4
jsr setwindow ; set to disk name window
ldy #0
g3 lda nambuf,y ; print disk name
jsr chrout
iny
cpy #24
bne g3
lda dirent+1 ; calc # of files found
ldx dirent
jsr convert
ldy #0 ; reset counter
jsr carret
g4 lda $100,y
beq g5
sta filbuf,y ; save for later
jsr chrout
iny
bne g4
g5 ldy #0
g6 lda flifnd,y
beq g7
jsr chrout
sta filbuf+5,y
iny
bne g6
flifnd =*
.asc " files"
.byt 32,32,32,32,0
;
g7 tay
g8 lda frebuf,y ; print blocks free
jsr chrout
iny
cpy #18
bne g8
;
ldx #1
lda dirent ; check for no files found
bne g9
lda dirent+1
bne g9
jsr setwindow ; set display window
jsr write
.asc "no files found"
.byt 13,0
jsr presskey ; exit if no files
jmp endsdir
;
g9 inx ; menu window
lda flag80 ; check for 80 column
bne g10
jmp dispdir
g10 jsr setwindow
jsr write
.byt 176
.asc "{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}": .byt 174,13
.asc "{SHIFT--} <up>,<dn> - scroll list {SHIFT--}": .byt 13
.asc "{SHIFT--} <home> - top of list {SHIFT--}": .byt 13
.asc "{SHIFT--} <esc> - exit to basic {SHIFT--}": .byt 13
.asc "{SHIFT--} <return> - bload prg {SHIFT--}": .byt 13
.asc "{SHIFT--} - read seq {SHIFT--}": .byt 13
.asc "{SHIFT--} - change 1581 dir {SHIFT--}": .byt 13
.asc "{SHIFT--} c= m - merge seq {SHIFT--}": .byt 13
.asc "{SHIFT--} c= p - print dir {SHIFT--}": .byt 13
.asc "{SHIFT--} c= r - 1581 root dir {SHIFT--}": .byt 13
.asc "{SHIFT--} c= s - scratch file {SHIFT--}": .byt 13
.asc "{SHIFT--} c= v - validate disk {SHIFT--}": .byt 13,173
.asc "{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}{SHIFT-*}": .byt 189,0
;
;
dispdir =* ; display and scroll directory
jsr setdir ; set pointers to directory buffer
;
dirmenu =* ; directory menu
ldx #0
stx work2
stx scrollp
stx dirp
stx dirp+1
inx ; display window
jsr setwindow
dispmore =*
ldy #0
w1 jsr getbyte ; display a filename
cmp #$ff
bne w2
jmp dm
w2 jsr chrout
iny
cpy #28
bne w1
jsr add32 ; point to next filename
inc work2 ; increment pointer
lda work2
cmp #20 ; check for full screen
beq dm
jsr carret ; carriage return
jmp dispmore
dm =*
jsr setdir
jsr downout
jmp kloop2
;
downout =*
printrvs =*
lda #18 ; set <rvs> on
jsr chrout
printnorm =*
ldy #0
ldx scrollp
clc
jsr plot ; go to start of line
ldy #0
w4 jsr getbyte ; get from bank 0
jsr chrout
iny
cpy #31
bne w4
lda #146 ; set <rvs> off
jmp chrout
;
scrolldown =*
jsr printnorm ; display normally
ldx dirp ; check lo byte of counter
inx
cpx dirent
bne q1
jmp downout ; dont do anything
q1 stx dirp
ldx scrollp
cpx #19
beq q2
inx
stx scrollp
jmp q3
q2 jsr carret
q3 jsr add32
jmp downout
;
;
kloop2 =* ; main key loop
k0 jsr getin ; get a key
beq k0
sta lastkey
cmp #27 ; <esc> to exit
bne k1
jmp endsdir
k1 cmp #19 ; <home> to start
bne k2
jmp dispdir
k2 cmp #13 ; <return> to load, etc
bne k3
jmp load
k3 cmp #167 ; C= m to merge seq file
bne k4
jmp load
k4 cmp #175 ; C= p to print dir
bne k5
jmp printdir
k5 cmp #145 ; <cursor up>
beq up
cmp #17 ; <cursor down>
bne k6
jmp down
k6 cmp #174 ; C= s to delete file
bne k7
jmp load
k7 cmp #178 ; C= r for 1581 root dir
bne k8
ldx #2 ; reset and go again
stx len
jmp dir
k8 cmp #190 ; c= v for validate
bne k9
jmp val
k9 jmp kloop2
;
up =*
jsr scrollup
jmp kloop2
;
down =*
jsr scrolldown
jmp kloop2
;
scrollup =*
jsr printnorm
ldx dirp
dex ; check lo byte of counter
cpx #$ff
bne s1
jmp downout
s1 stx dirp
ldx scrollp
beq s2
dex
stx scrollp
jmp s3
s2 lda #27 ; escape insert line sequence
jsr chrout
lda "i"
jsr chrout
s3 sec
lda p2
sbc #32
sta p2
bcs s4
dec p2+1
s4 jmp downout
;
load =*
ldy #16 ; calc len of filename
s5 jsr getbyte
and #$7f
cmp #32
bne s6
dey
bne s5
s6 iny
sty work1 ; save fn len
lda lastkey ; check for C= s to scratch
cmp #174
bne s7
ldy #0
s8 lda scratch,y ; set up scratch command
sta combuf,y
iny
cpy #3
bne s8
jmp transfer ; transfer filename and execute
;
s7 ldy #17
jsr getbyte ; look for cbm partition on 1581
cmp "c"
bne notsubdir
root =*
ldy #0
s9 lda subdir,y ; set up "/0:" command
sta combuf,y
iny
cpy #3
bne s9
dey ; reset directory pattern
sty len
;
transfer =*
ldy #0 ; transfer filename to combuf
t1 jsr getbyte
sta combuf+3,y
iny
cpy work1
bne t1
clc
lda work1 ; set command length
adc #3
sta comlen
jsr sendcom ; send command
jmp cont ; and read dir over again
;
subdir =*
.asc "/0:" ; dos command prefix for change subdir
;
;
scratch =*
.asc "s0:" ; dos command prefix for scratch
;
validate =*
.asc "v0:" ; dos validate command
val =*
ldy #0
v1 lda validate,y
sta combuf,y
iny
cpy #3
bne v1
sty comlen
jsr sendcom
jmp cont
;
notsubdir =*
ldx #0
jsr setwindow
lda #1
ldx drive
ldy #3
jsr setlfs ; open file for load
lda work1 ; filename length
ldx p2
ldy p2+1
jsr setnam ; set filename
lda #0
tax
jsr setbank ; set bank
ldy #17
jsr getbyte
cmp #"p" ; check for program file
bne readsq ; and read file if not
clc
lda #0
jsr kload ; load file
stx eof ; save eof pointers
sty eof+1
bcs ns1
jmp endsdir
;
ns1 jsr readcom
jmp dispdir
;
readsq =* ; read or merge seq file
jsr open
ldx #1
jsr chkin
lda lastkey
cmp #167 ; check for C= M to merge a file
bne go
ldy #17
jsr getbyte
cmp #"s"
bne go
jmp end2 ; merge then exit
go =*
jsr chrin ; display file
jsr chrout
jsr stop ; test stop key
bpl nogo ; abort if pressed
jsr status
beq go
nogo =*
jsr clrchn
lda #1
jsr close
jsr presskey
ldx #0 ; clear screen
jsr setwindow
jmp exitdir ; back to main menu
;
;---- print hard copy of directory
;
printdir =*
lda #6
ldx prn ; printer device#
ldy psec ; printer secondary address
jsr setlfs ; open printer file
lda #0
jsr setnam
jsr open
clc
ldx #6
jsr chkout ; select printer for output
bcc pd1
jmp endprint ; end if error
pd1 jsr setdir
lda expand ; set expanded print
jsr chrout
ldy #0
pd2 lda nambuf,y
jsr chrout
iny
cpy #32
bne pd2
jsr carret
jsr carret
lda exoff ; turn off expanded
jsr chrout
lda compress ; set compressed print
jsr chrout
ldy width
jsr preq
jsr carret
;
nexttwo =* ; print file names , width/32 to a line
ldy #0
nt1 jsr getbyte ; get a byte
cmp #$ff
beq exitloop
jsr chrout
iny
cpy width ; check screen width
bne nt1
jsr carret
clc
lda p2
adc width
sta p2
bcc nexttwo
inc p2+1
jmp nexttwo
;
exitloop =* ; end print out
jsr carret
ldy width
jsr preq
jsr carret
lda compoff ; turn off compressed print
jsr chrout
ldy #0
el1 lda filbuf,y ; number of files found and bytes free
jsr chrout
iny
cpy #48
bne el1
jsr carret
;
endprint =*
jsr clrchn
lda #6
jsr close
jmp dispdir
;
setdir =* ; reset dir pointers
lda <dirbuf
sta p2
sta p3
lda >dirbuf
sta p2+1
sta p3+1
rts
;
;
;
;--------- subroutines
;
;
;
;---- convert digit to ascii string
;
convert =* ; convert 2 digit integer to ascii
sta $64 ; before calling lda with high byte
stx $65 ; ldx with low byte
ldx #$90
sec
jsr $8c75
jsr $8e44 ; ascii will be at $100 ended by 0 byte
rts
;
;---- set screen windows
;
setwindow =* ; window with <clear>
lda bottoms,x
sta bottom
lda tops,x
sta top
lda flag80 ; check screen width
beq sw1 ; skip rest if 40 col
lda lefts,x
sta left
lda rights,x
sta right
;
sw1 lda #147 ; clear screen
jmp chrout
; ldx with window number
; ; before calling
bottoms =*
.byt 24,22,24,24,2 ; 0= full screen
tops =* ; 1= data window
.byt 0,3,5,24,0 ; 2= menu window
lefts =* ; 3= title window
.byt 0,0,45,0,0 ; 4= status window
rights =*
.byt 79,44,79,44,44
;
;
;---- write prompt messages
;
error1 =*
jsr clrchn
ldx #1
jsr setwindow
jsr write
.byt 13,13
.asc "error:"
.byt 13,0
lda errlen
beq er2
ldy #0
er1 lda combuf,y
jsr chrout
iny
cpy errlen
bne er1
er2 lda #64
sta stat ; error flag
;
presskey =*
jsr write
.byt 13,13
.asc "press a key ..."
.byt 13,0
pk1 jsr getin
beq pk1
rts
;
;
;
;------------ disk i/o routines
;
;---- read error channel
;
; error message will be returned in combuf
; length of message in errlen
;
readcom =*
clc
ldx #14 ; command channel
jsr chkin
bcs error1 ; abort on error
ldy #0
rc1 jsr chrin
sta combuf,y
cmp #13
beq rc2
iny
bne rc1
rc2 sty errlen
jsr clrchn
rts
;
;---- send disk command
;
; before calling:
;
; sta comlen with length of command string
; (combuf) with command
;
sendcom =*
ldx #14 ; file #
clc
jsr chkout
bcs diskerror ; abort on error
ldy #0
sc1 lda combuf,y
jsr chrout
iny
cpy comlen
bne sc1
jmp clrchn
;
diskerror =*
jsr clrchn
jmp error1
;
;--- read a disk byte
;
readbyte =* ; read a disk byte
sec
jsr status ; read disk status byte
bne rb1 ; not 0, then abort with carry set
clc ; clear carry for byte ok
jsr chrin ; read byte and
rb1 rts ; return
;
stashbyte =* ; save a byte in bank 0
ldx #$3f
stx mmu ; go to bank 0
sta (p2),y ; save data
ldx #0
stx mmu ; back to default bank
rts ; and return
;
getbyte =* ; get a byte from bank 0
ldx #$3f
stx mmu ; go to bank 0
lda (p2),y ; get data
ldx #0
stx mmu ; back to default bank
rts ; and return
;
add32 =* ; add 32 to zero page pointers
clc
lda p2
adc #32
sta p2
bcc a1
inc p2+1
a1 rts
;
carret =* ; send carriage return
lda #13
jmp chrout
;
preq =* ; print .y = signs
lda "="
jsr chrout
dey
bne preq
rts