EQU BDOS,$0005
EQU DESTINATION,$0083 ; Location to load at.
EQU JUMPTO,$0085 ; Location to jump to.
.ORG $100
BOOTLOADER:
LD DE,$0080 ; DMA area.
LD C,$1A
CALL BDOS
LD DE,$005C ; The FCB from the command line.
LD C,$0F ; Open the file.
CALL BDOS ; Load the first record.
AND $FC ; Mask lower two bits.
JR NZ,BOOTERROR
LD DE,$005C
LD C,$14 ; Serial Read.
CALL BDOS
AND $FC ; Mask lower two bits. Last test, next error is EOF.
JR NZ,BOOTERROR
LD DE,(DESTINATION) ; The file tells us where we want to send the file.
LD (FILEDEST),DE
LD HL,(JUMPTO) ; The file tells is the place to execute from.
LD (EXECUTEFROM),HL
FILELOOP: ; Here's where we load in and transfer all the sectors until the file is read.
LD DE,(FILEDEST)
LD HL,$0080
LD BC,$80
LDIR
LD (FILEDEST),DE
LD DE,$005C
LD C,$014
CALL BDOS
AND A
JR Z,FILELOOP ; Only continue while A=00.
DEC A ; And of file = 01.
JR NZ,BOOTERROR ; if it wasn't 01, then it's an error.
LD HL,(EXECUTEFROM)
JP (HL)
DB 'Variables:'
FILEDEST: DW $0000 ; File destination counter.
EXECUTEFROM: DW $0000 ; Jump point.
BOOTERROR:
LD DE,ERROR
LD C,$09
CALL BDOS
JP $0000
ERROR: db 'Oops, something went wrong. Try BOOTLOAD <filename> then Enter.',$0A,$0D,'$'