home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
cpm
/
cpm3
/
writeccp.lbr
/
WRITECCP.MZC
/
WRITECCP.MAC
Wrap
Text File
|
1987-10-26
|
7KB
|
328 lines
; This program originated as EXCWTSYS.MAC from the Executive
; technical reference. It has been modified to write only
; CCP.COM to the system tracks on drive A. (G Peace - 12/84)
.z80
dmabank equ 0fd4ah
idellen equ 0002h
idevlen equ 0080h
idevshd equ 00a2h
idevtbl equ 0022h
idrvlen equ 0080h
idrvtbl equ 0002h
idvilen equ 000ah
idvslen equ 0100h
ishdlen equ 0040h
ivers equ 0
sys equ 0
wsec equ 005dh
open equ 15
read equ 20
setdma equ 26
pmsg equ 9
bdos equ 5
getdev equ 3ch ;bios fcn: hl=devtbl
getdrv equ 42h ;bios fcn: hl=drvtbl
move equ 4bh ;bios fcn: move
xmove equ 57h ;bios fcn: set banks for move
start: ld sp,stack ; pt to a stack
ld bc,codelen ; len of our code
ld de,himem ; destination
ld hl,ourcode ; from here
ldir ; move a hunk to non-rom area
ld bc,secend-sec1 ; init entire area 1st
ld de,sec1 ; i/o area
ld hl,initial ; what to init it with
ldir ; all cleared out
ld de,startmsg ; tell what we're going to do
call msg
ld de,ccp ; 3rd file to read in
ld hl,ccpsec
call dofile
; track 1
ld hl,track1
ld de,0001h
ld a,4
call write
ld de,donemsg ; that is it!
call msg
; all done
exit:
jp 0 ; warm boot
; call the bios with rtn addr (lo) in a
bios: ld (biosl),a ; set lo of bios addr
ld a,(2) ; get hi of addr
ld (biosh),a
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; modified code follows
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
biosjp: jp 0 ; really jp to bios entry
biosl equ biosjp+1 ; lo of bios fcn addr
biosh equ biosl+1 ; and hi of addr
msg: ld c,pmsg ; let bdos issue a message
jp bdos ; pt'ed to by de
; write
; write all or part of a sector to disk
; a # sectors to write
; e track #
; d sector number-1 (0=1)
; hl ptr to dma address
; write5
; same, but sets a to 5 (full track)
write5: ld a,5 ; set to full track
write: or a ; see if anything to write
ret z ; no, all done
ld b,a ; save # sectors to write
ld (wtaddr),hl ; set dma addr
ld a,d ; get sector number
inc a ; adj properly
ld (wtsec),a
ld a,e ; get track number
ld (wttrk),a
ld a,b ; restore # sectors to write
ld bc,iolen ; length of i/o init area
ld de,dmabank ; in ho common ram
ld hl,wtparms ; to do some track
ldir ; this is it
ld b,a ; get # sectors to write
ld a,wsec ;and the offset to write it
call torom
or a ; any errors writing?
ret z ; no, all done writing
jp wterr ; yes, then abort
; dofile
; open then read in a file
; if "optional"<>0 then file is optional
; a returned=#sectors actually read in
; de ptr to fcb to use
; hl dma address starting
dofile: ; open then read this file
push hl ; save dma addr
ld (thefcb),de ; and ptr to fcb
ld hl,1 ; copy fname and ftype
add hl,de ; from fcb+1
ld de,fname ; copy in this file name
ld bc,8
ldir
inc de ; bump over the '.'
ld bc,3 ; for file type
ldir
ld de,(thefcb) ; pt to file
ld c,open ; open the file
call bdos
inc a ; ff=not found
pop de ; restore starting dma addr
jp z,badopen ; open error
ld b,-1 ; init # sectors read count
rdloop: inc b ; bump # sectors read
push de
push bc ; save sector count
ld c,setdma ; set dma addr
call bdos
ld de,(thefcb) ; crnt fcb
ld c,read
call bdos ; read one more 128 byte sector
pop bc ; restore sector count
pop de
ld hl,128 ; advance dma addr too
add hl,de
ex de,hl
or a ; see if done or error
jr z,rdloop ; not done yet
dec a ; 1=done
jr nz,badread ; no, error
or b ; pass back # sectors read in
ret ; all done reading, no errors
wterr: ld de,wtmsg ; write error (no fname)
abort: call msg
jp exit ; and all done
badopen:
ld de,openmsg ; issue msg
jr fabort
badread:
ld de,readmsg ; issus msg
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; fall through
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; common open/read error handler
; if "optional" then return a=0 and done, else error msg.
fabort: ; error opening then reading a file
call msg ; issue msg
ld de,fname ; then say file name
call msg
ld a,(optional) ; is this file optional
or a
jp z,exit ; no, abort now
xor a ; yes, pass back a=0
ret ; and done with file
; torom
; a=rom routine address
; aka ourcode (before it is moved)
ourcode: ; code which is moved above 4000h
ld (thecall+1),a ; alter the call
in a,(sys)
or 80h ; turn on rom
out (sys),a
xcall: call 100h ; call the rom
push af ; save
in a,(sys)
and 07fh ; turn rom off
out (sys),a
pop af
ret ; and all done
codelen equ $-ourcode ; length to move up
himem equ 5000h ; move the code here
torom equ himem ; routine to call to rom
thecall equ torom+(xcall-ourcode) ; the call instruction
stack equ himem+400h ; someplace also in non-rom
; misc variables etc....
optional: db 0 ; non-zero if file is optional
wtfm: db 0 ; ? write fontm (0=no)
wtfa: db 0 ; ? write fonta (0=no)
wtrom: db 0 ; ? write rom's ram (0=no)
thefcb: dw 0 ; ptr to current fcb
startmsg:
db 0dh,0ah
db 'WRITECCP will write CCP.COM to drive A, track1, sector 1'
db 0dh,0ah,'$'
donemsg:
db 0dh,0ah
db 'System tracks aok',0dh,0ah,'$'
fname: ds 8 ; common name for messages
db '.'
ftype: ds 3
db 0dh,0ah,07h,'$'
readmsg:
db 0dh,0ah,'Error reading $'
openmsg:
db 0dh,0ah,'Unable to open $'
wtmsg: db 0dh,0ah,'Error writing system tracks',0dh,0ah,'$'
ldrmsg: db 0dh,0ah,'Error: cpmldr.com is too long'
db 7,0dh,0ah,'$'
; this is set of parms passed to the rom
; to write 1-5 sectors
wtparms:
db 1 ; bank
wtaddr: dw 0 ; addr
wtsec: db 1 ; sector
wttrk: dw 0 ; track
db 0 ; unit 'A'
db 0ch ; type
iolen equ $-wtparms ; length to move up there
ccp:
db 0,'CCP COM'
dw 0,0,00,0,0,0,0,0,0,0,0,
initial: ; do not change this
db 'ReservedReserved' ; oh well, fill the unused
; areas on the system
; tracks with something
sec1 equ $ ; start of i/o areas ( 3 tracks long)
sec2 equ sec1+1024
sec3 equ sec2+1024
sec4 equ sec3+1024
sec5 equ sec4+1024
track0 equ sec1
sec6 equ sec5+1024 ; sector 1 track 1
sec7 equ sec6+1024
sec8 equ sec7+1024
sec9 equ sec8+1024
sec10 equ sec9+1024
track1 equ sec6 ; secec1ec1u sec10+1024 ; sector 1 track 2
sec12 equ sec11+1024
sec13 equ sec12+1024
sec14 equ sec13+1024
sec15 equ sec14+1024
track2 equ sec11
secend equ sec15+1024
bootsec equ sec1 ; excbsec2+ sec 1 trk 0
ldrsec equ sec2 ; cpmldr sec 2 trk 0
ccpsec equ sec6 ; ccp sec 1 tk 1
oursec equ sec10 ; where special stuff goes
fmsec equ sec11 ; where main font begins
fasec equ sec13 ; where alt font begins
romsec equ sec15 ; rom's ram override
end
u sec11 ; where main font beg