home *** CD-ROM | disk | FTP | other *** search
- ;
- ; Z3LIB Module Name: Z3PRGLD
- ; Author: Richard Conn
- ; Z3LIB Version Number: 1.3
- ; Module Version Number: 1.1
- ;
- public prgload
-
- ;
- ; OS Equates
- ;
- bdos equ 5
- tpa equ 100h
-
- ;
- ; PRGLOAD loads the program indicated by the first 12 bytes pted to
- ; by DE into memory at 100H and transfers control to it.
- ; If file does not exist, PRGLOAD returns; if file does exist, PRGLOAD
- ; clears the stack of its return address and transfers control to the program
- ; after loading it with the cleared stack as the program's stack.
- ;
- prgload:
- push de ;save ptr to FCB (DE)
- ld hl,(bdos+1) ;get base address of BDOS
- ld a,h ;9 pages below BDOS (1st page below CCP)
- sub 9
- ld h,a
- ld l,80h ;HL pts to load address
- ld (ldadr),hl ;set load address
- ld de,40h ;set FCB address
- add hl,de
- ld (ldfcb),hl ;address of FCB
- pop de ;pt to original FCB
- ld (hl),0 ;set first byte to 0 (current disk)
- inc hl ;pt to name
- inc de ;pt to name
- ld b,11 ;11 bytes
- call moveb ;do copy
- ld b,24 ;fill next 24 bytes (to R2) with zeroes
- call zero ;initialize LDFCB
- ld hl,(ldfcb) ;pt to FCB
- ex de,hl ;... in DE
- ld c,15 ;try to open file
- call bdos
- cp 0ffh ;error?
- ret z ;abort if error
- ;
- ; Copy Loader Program into TBUFF Area
- ;
- pop af ;clear stack
- ld de,loader ;pt to loader program
- ld hl,(ldadr) ;pt to loader address
- ld b,64 ;copy 64 bytes
- call moveb ;do the copy
- ld de,100h ;initial DMA address
- ld hl,(ldadr) ;transfer control to the loader program
- jp (hl) ;transfer control to the loader program
- ;
- ; Copy HL to DE for B bytes
- ;
- moveb:
- ld a,(de) ;get byte
- ld (hl),a ;put byte
- inc hl ;pt to next
- inc de
- dec b ;count down
- jp nz,moveb
- ret
- ;
- ; Zero FCB fields pted to by HL
- ;
- zero:
- ld (hl),0 ;store zero
- inc hl ;pt to next
- dec b ;count down
- jp nz,zero
- ret
- ;
- ; Loader Program
- ; Upon execution, the address of LOADER is LDADR
- ; The FCB used by LOADER is at LDFCB
- ;
- loader:
- ld c,26 ;set DMA
- push de ;save address
- call bdos ;perform BDOS function
- ldfcb equ $+1
- ld de,0 ;pt to FCB
- ld c,20 ;read next record
- call bdos
- pop hl ;get DMA address
- or a ;0=OK
- jp nz,tpa ;done with load, so run program
- ld de,80h ;advance to next record
- add hl,de
- ex de,hl ;DMA address in DE
- ldadr equ $+1
- jp 0 ;continue load
- ;
- ; Memory Marker - For Easy Location of Module End
- ;
- db '**** ZCPR3 PRGLOAD ****'
-
- end