home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
enterprs
/
c128
/
text
/
examples.arc
/
INSTALL.A
< prev
next >
Wrap
Text File
|
1989-12-01
|
16KB
|
383 lines
;install.asm
;===========================================
; CS-DOS Command: install[/bank] patternlist
;===========================================
;
; Revised: 21Mar90 - If bank is not specified, defaults are as follows:
;
; Load Address -> $xx01 - Bank 0
; < $1c00 - bank 15
; >=$4000 - bank 1
; Otherwise bank 0
;Zero page image of REU registers. If RAMdisk is in the 128,
;then only 'zrda' is significant.
zrimg = $0060 ; Command register
z128 = $0061 ; C128 address
zrda = $0063 ; REU address+bank
zxfer = $0066 ; transfer length
la = $00b8 ; logical address of current input file
poker = $0016 ; two byte temp
parm = $0026 ; temp
ccl = $0027 ; temp
status = $0090 ; I/O status byte
cl = $1bf7 ; Drive letter for filename returned by int16
rdadr = $1bf5 ; RAM disk start address if in 128, or page if in 1750
rdmax = $1bf1 ; Highest RAM address+1 available to the RAM disk
rflag = $1bf0 ; bit 7 is true if RAM disk is in the 1750
rdbnk = $1bf3 ; Bank where RAM disk is if its in the 128
sw1 = $1bfc ; Command line switch 1
tx = $1bfe ; Bit 6 is true if the RAMdisk is enabled
int04 = $1704 ; Fetch first character of parameter .x
int05 = $1705 ; Fetch next character after int04
int0a = $170a ; Find an unused LA (.a) and SA (.y)
int0e = $170e ; Program terminate
int16 = $1716 ; Find 1st matching file for parameter .x
int17 = $1717 ; Find subsequent matches after int16
int21 = $1721 ; Function interrupt
int3f = $173f ; Open %x for input using burst read if possible
chrout = $ffd2
primm = $ff7d
setnam = $ffbd
getcfg = $ff6b
setlfs = $ffba
fnbank = $00c7
open = $ffc0
close = $ffc3
chkin = $ffc6
chrin = $ffcf
clrchn = $ffcc
star = $0b00
.wor star
* = star
jmp start
dw Date
start bit tx ; Abort if RAM disk isn't enabled
bvs inst ; it is..continue
jsr primm
.asc 13,"No RAM disk is installed",13, 0
ex3 lda #3
jmp int0e
inst lda #13 ; We're in bank 15, and shell did a clrchn
jsr chrout
instal ldx #1 ; start with %1 and work up
stx parm
jsr int04 ; test for parameter
bcs nprm ; none there
jmp in0 ; got one. do it
nprm jsr primm
.asc 13,"Syntax: install[/bank] programlist",13
.asc 13,"Purpose: makes external commands resident.",13, 0
ex1 lda #1
.byt $2c
ex0 lda #0
jmp int0e
in0 jsr int04 ; 1st test for parameter
bcs ex0 ; none there...quit
jsr int16 ; get 1st matching filename
bcc inok ; got one
jmp nxtp ; else try next parameter
inok lda cl ; get drive letter file is on
sta ccl ; save it since int17 might erase it
inagn lda ccl ; make a copy of the filename at $1b23
sta $1b23 ; and echo the filename to the screen
ldx $1bce ; change colors
stx $f1
jsr chrout
lda #":"
sta $1b24
jsr chrout
ldy #2
in1 lda $1b01,y ; echo the name
cmp #$a0
beq in2
jsr chrout
sta $1b23,y
iny
cpy #18
bcc in1
in2 lda #0 ; make name asciiz
sta $1b23,y
sta $1b01,y
in3 lda #" " ; tab(16)
jsr chrout
iny
cpy #19
bcc in3
ldx $1bcb ; change colors (assume prg for now)
lda $1b00 ; confirm type=prg
cmp #130 ; prg=$82
beq inag0 ; ok. continue
ldx $1bca ; different color for SEQ
cmp #129 ; seq=$81
beq inag0 ; ok. continue
ldx $1bc9
stx $f1
jsr primm
.asc "not PRG or SEQ. Can't install",13, 0
jmp nxtm
inag0 stx $f1 ; change colors for screen
ldx #$81 ; check if it exists on RAM disk
ldy #6
jsr int21
bcs in4 ; it doesn't..add it
jsr primm
.asc "Already installed!",13, 0
nxtm jsr int17 ; get next match
bcs nxtp ; no more. try next parameter
jmp inagn ; go again
nxtp inc parm
ldx parm
jmp in0
in4 ldy #8
jsr int21 ; goto end of the RAM disk
bcc inn4 ; ok
jsr primm
.asc 13,"RAM disk corrupt. Can't install", 0
ex4 lda #4
jmp int0e
inn4 ldy #0 ; make link zero for now in case install fails
sty $1b60
sty $1b61
inn5 lda zrda,y ; copy shell's REU register image
sta szrda,y ; We'll need it later to adjust the pointer
iny ; if we succeed
cpy #3
bne inn5
dey ; .y=2
in5 lda $1b01,y ; move filename to RAMdisk
sta $1b60,y
iny
cmp #0
bne in5
sty bufsiz ; initialize stash subroutine
sty BankPtr ; Save offset of config from $1b60
lda $1b00 ; recall type
and #%10111111 ; get rid of scratch protect flag
cmp #129 ; seq?
bne prog ; no executable
ldx sw1 ; type or exec?
cpx #"t"
bne exec
ora #64
exec jmp bank
prog lda sw1 ; get bank
cmp #$30 ; must be 0-9 or a-f
bcc use15 ; error. use bank 15
cmp #$3a ; is it 0-9?
bcc usea ; ok. use it
sbc #55 ; convert a-z to 10-15
cmp #16
bcs use15
usea and #$0f
.byt $2c
use15 lda #15
tax
sta $ff03
jsr getcfg
bank jsr stash ; save Bank in RAM disk (or type flag for batch files)
lda #0 ; now open the file
sta $ff00
ldx #$81
jsr int3f ; open for burst read
bcc GetLoadAddr
derr jsr primm
.asc "disk error?",13, 0
de jsr clrchn
lda la
jsr close
jmp nxtm
toobig jsr primm
.asc "File too large",13, 0
jmp de
GetLoadAddr jsr $1779
bcs derr
sta LoadAddr
jsr stash
jsr $1779
bcs derr
sta LoadAddr+1
jsr stash
jsr AdjustBank
ina jsr $1779 ; fetch char
bcs derr
jsr stash ; stash it
bcs toobig ; past end of ramdisk
in9 bit status
bmi derr
bvc ina
jsr flush
lda #0 ; eof. stash two zeros
jsr stash
jsr stash
sec ; and calculate the file size
lda zrda
sbc szrda
sta poker
lda zrda+1
sbc szrda+1
sta poker+1
lda zrda+2
sbc szrda+2
bne toobig ; too big if length is a 3 byte quantity
jsr flush
sec ; less the two zeros is the true size
lda poker
sta $1b60
lda poker+1
sta $1b61
zip ldy #2
zip1 lda szrda,y ; recall start of entry and adjust the pointer
sta zrda,y
dey
bpl zip1
ldy #2
sty bufsiz
jsr flush
jsr primm
.asc "installed",13, 0
jmp de
;-------------------------
; Stash byte to RAM drive
;-------------------------
stash sty stsy+1
ldy bufsiz
sta $1b60,y ; put in buffer for now
iny
inc bufsiz
cpy #32
bcs flush ; until buffer overflows, then flush it to the REU
stsy ldy #0
clc
rts
flush pha
bit rflag ; in 1750?
bpl inram ; no. in the 128
lda bufsiz ; 1st check for overflow before proceeding
clc
adc zrda
bcc proc ; no. proceed
ldy zrda+1
cpy #$ff
bne proc
ldy zrda+2
iny
cpy rdmax+1
bcc proc
rts ; overflow...can't flush
proc lda bufsiz
sta zxfer
lda #0
sta zxfer+1
lda #%10010000
sta zrimg
lda $d030
pha
and #%11111110
sta $d030
bit $df00 ; clear flags
ldy #9
flsh lda zrimg,y
sta $df01,y
dey
bpl flsh
wfls bit $df00 ; wait for Xfer to complete
bvc wfls
pla
sta $d030
zb clc ; bump REU pointer
lda zrda
adc bufsiz
sta zrda
bcc flx
inc zrda+1
bne flx
inc zrda+2
flx lda #0
sta bufsiz
pla
jmp stsy
inram clc ; 1st check for overflow
lda bufsiz
adc zrda
ldy zrda+1
bcc iinr
iny
iinr cpy rdmax+1 ; check high byte of ram+buffer+1
bcc inra ; ok
beq iiin ; maybe
rts ; overflow, can't flush
iiin cmp rdmax ; now low byte
bcc inra
beq inra
rts
inra lda rdbnk+1 ; flush buffer to 128 bank
sta $ff00 ; We're in common RAM, so any bank is ok
ldy #0
inr lda $1b60,y ; do it
sta (zrda),y
iny
cpy bufsiz
bcc inr
lda #0
sta $ff00 ; back to bank 15
beq zb ; always
LoadAddr dw 0
BankPtr db 0
AdjustBank lda sw1 ; Don't adjust if user specified the bank
bne AdjustDone
ldy BankPtr ; Offset to config
lda $1b60,y
bmi AdjustDone ; Its a seq file, no need to adjust
lda LoadAddr ; Otherwise force bank 0 for $xx01
cmp #1
beq Bank0
lda LoadAddr+1
cmp #$1c ; And bank 15 for < $1c00
bcc Bank15
cmp #$40
bcc Bank0 ; And bank 0 for $1c00 to $3fff
lda #$7f ; But bank 1 for $4000 and higher
db $2c
Bank0 lda #$3f
db $2c
Bank15 lda #0
sta $1b60,y
AdjustDone rts
bufsiz .byt 0
szrda .byt 0, 0, 0
.end