2011-02-06 22:27:31 +00:00
|
|
|
;
|
|
|
|
; Oliver Schmidt, 2011-01-26
|
|
|
|
;
|
|
|
|
; int __fastcall__ exec (const char* progname, const char* cmdline);
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _exec
|
|
|
|
.import pushname, popname
|
|
|
|
.import popax, done, _exit
|
2011-02-06 22:27:31 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "zeropage.inc"
|
|
|
|
.include "errno.inc"
|
|
|
|
.include "apple2.inc"
|
|
|
|
.include "mli.inc"
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Wrong file type
|
2013-05-09 11:56:54 +00:00
|
|
|
typerr: lda #$4A ; "Incompatible file format"
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Cleanup name
|
2013-05-09 11:56:54 +00:00
|
|
|
oserr: jsr popname ; Preserves A
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Set __oserror
|
2013-05-09 11:56:54 +00:00
|
|
|
jmp __mappederrno
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
_exec:
|
|
|
|
; Get and push name
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr popax
|
|
|
|
jsr pushname
|
|
|
|
bne oserr
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Set pushed name
|
2013-05-09 11:56:54 +00:00
|
|
|
lda sp
|
|
|
|
ldx sp+1
|
|
|
|
sta mliparam + MLI::INFO::PATHNAME
|
|
|
|
stx mliparam + MLI::INFO::PATHNAME+1
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Get file_type and aux_type
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #GET_INFO_CALL
|
|
|
|
ldx #GET_INFO_COUNT
|
|
|
|
jsr callmli
|
|
|
|
bcs oserr
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; If we get here the program file at least exists so we copy
|
|
|
|
; the loader stub right now and patch it later to set params
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #size - 1
|
|
|
|
: lda source,x
|
|
|
|
sta target,x
|
2011-02-06 22:27:31 +00:00
|
|
|
dex
|
2013-05-09 11:56:54 +00:00
|
|
|
bpl :-
|
2011-02-11 23:22:26 +00:00
|
|
|
|
2011-02-06 22:27:31 +00:00
|
|
|
; Check program file type
|
2013-05-09 11:56:54 +00:00
|
|
|
lda mliparam + MLI::INFO::FILE_TYPE
|
|
|
|
cmp #$FF ; SYS file?
|
|
|
|
bne binary ; No, check for BIN file
|
2011-02-06 22:27:31 +00:00
|
|
|
|
2011-02-11 23:22:26 +00:00
|
|
|
; ProDOS TechRefMan, chapter 5.1.5.1:
|
|
|
|
; "The complete or partial pathname of the system program
|
|
|
|
; is stored at $280, starting with a length byte."
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #$00
|
|
|
|
lda (sp),y
|
2011-02-11 23:22:26 +00:00
|
|
|
tay
|
2013-05-09 11:56:54 +00:00
|
|
|
: lda (sp),y
|
|
|
|
sta $0280,y
|
2011-02-11 23:22:26 +00:00
|
|
|
dey
|
2013-05-09 11:56:54 +00:00
|
|
|
bpl :-
|
2011-02-11 23:22:26 +00:00
|
|
|
|
2011-02-06 22:27:31 +00:00
|
|
|
; SYS programs replace BASIC.SYSTEM so set in the ProDOS system bit map
|
|
|
|
; protection for pages $80 - $BF just in case BASIC.SYSTEM is there now
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #$0F ; Start with protection for pages $B8 - $BF
|
|
|
|
lda #%00000001 ; Protect only system global page
|
|
|
|
: sta $BF60,x ; Set protection for 8 pages
|
|
|
|
lda #$00 ; Protect no page
|
2011-02-06 22:27:31 +00:00
|
|
|
dex
|
2013-05-09 11:56:54 +00:00
|
|
|
bpl :-
|
|
|
|
bmi prodos ; Branch always
|
2011-02-06 22:27:31 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
binary: cmp #$06 ; BIN file?
|
|
|
|
bne typerr ; No, wrong file type
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Set BIN program load addr
|
2013-05-09 11:56:54 +00:00
|
|
|
lda mliparam + MLI::INFO::AUX_TYPE
|
|
|
|
ldx mliparam + MLI::INFO::AUX_TYPE+1
|
|
|
|
sta data_buffer
|
|
|
|
stx data_buffer+1
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Check ProDOS system bit map for presence of BASIC.SYSTEM
|
2013-05-09 11:56:54 +00:00
|
|
|
lda $BF6F ; Protection for pages $B8 - $BF
|
|
|
|
cmp #%00000001 ; Exactly system global page is protected
|
|
|
|
beq setvec
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Get highest available mem addr from BASIC.SYSTEM
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx HIMEM+1 ; High byte
|
|
|
|
bne setbuf ; Branch always
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; BIN programs are supposed to quit through one of the two DOS
|
|
|
|
; vectors so we set up those to point to the ProDOS dispatcher
|
2013-05-09 11:56:54 +00:00
|
|
|
setvec: ldx #$03 - 1 ; Size of JMP opcode
|
|
|
|
: lda dosvec,x
|
|
|
|
sta DOSWARM,x ; DOS warm start
|
|
|
|
sta DOSWARM + 3,x ; DOS cold start
|
2011-02-06 22:27:31 +00:00
|
|
|
dex
|
2013-05-09 11:56:54 +00:00
|
|
|
bpl :-
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; No BASIC.SYSTEM so use addr of ProDOS system global page
|
2013-05-09 11:56:54 +00:00
|
|
|
prodos: ldx #>$BF00 ; High byte
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; The I/O buffer needs to be page aligned
|
2013-05-09 11:56:54 +00:00
|
|
|
setbuf: lda #$00 ; Low byte
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; The I/O buffer needs four pages
|
|
|
|
dex
|
|
|
|
dex
|
|
|
|
dex
|
|
|
|
dex
|
|
|
|
|
|
|
|
; Set I/O buffer
|
2013-05-09 11:56:54 +00:00
|
|
|
sta mliparam + MLI::OPEN::IO_BUFFER
|
|
|
|
stx mliparam + MLI::OPEN::IO_BUFFER+1
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; PATHNAME already set
|
|
|
|
.assert MLI::OPEN::PATHNAME = MLI::INFO::PATHNAME, error
|
|
|
|
|
|
|
|
; Lower file level to avoid program file
|
|
|
|
; being closed by C libary shutdown code
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx LEVEL
|
|
|
|
stx level
|
|
|
|
beq :+
|
|
|
|
dec LEVEL
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Open file
|
2013-05-09 11:56:54 +00:00
|
|
|
: lda #OPEN_CALL
|
|
|
|
ldx #OPEN_COUNT
|
|
|
|
jsr callmli
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Restore file level
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx level
|
|
|
|
stx LEVEL
|
|
|
|
bcc :+
|
|
|
|
jmp oserr
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Get and save fd
|
2013-05-09 11:56:54 +00:00
|
|
|
: lda mliparam + MLI::OPEN::REF_NUM
|
|
|
|
sta read_ref
|
|
|
|
sta close_ref
|
2011-02-06 22:27:31 +00:00
|
|
|
|
2011-02-11 23:22:26 +00:00
|
|
|
.ifdef __APPLE2ENH__
|
|
|
|
; Calling the 80 column firmware needs the ROM switched
|
|
|
|
; in, otherwise it copies the F8 ROM to the LC (@ $CEF4)
|
2013-05-09 11:56:54 +00:00
|
|
|
bit $C082
|
2011-02-11 23:22:26 +00:00
|
|
|
|
|
|
|
; ProDOS TechRefMan, chapter 5.3.1.3:
|
|
|
|
; "80-column text cards -- and other Apple IIe features -- can
|
|
|
|
; be turned off using the following sequence of instructions:"
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #$15
|
|
|
|
jsr $C300
|
2011-02-11 23:22:26 +00:00
|
|
|
|
|
|
|
; Switch in LC bank 2 for R/O
|
2013-05-09 11:56:54 +00:00
|
|
|
bit $C080
|
2011-02-11 23:22:26 +00:00
|
|
|
.endif
|
|
|
|
|
2011-02-06 22:27:31 +00:00
|
|
|
; Call loader stub after C libary shutdown
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #<target
|
|
|
|
ldx #>target
|
2014-01-26 17:10:01 +00:00
|
|
|
sta done+1
|
|
|
|
stx done+2
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Initiate C libary shutdown
|
2013-05-09 11:56:54 +00:00
|
|
|
jmp _exit
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
.bss
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
level : .res 1
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
.rodata
|
|
|
|
|
|
|
|
; Read whole program file
|
2013-05-09 11:56:54 +00:00
|
|
|
source: jsr $BF00
|
|
|
|
.byte READ_CALL
|
|
|
|
.word read_param
|
|
|
|
bcs :+
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Close program file
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr $BF00
|
|
|
|
.byte CLOSE_CALL
|
|
|
|
.word close_param
|
|
|
|
bcs :+
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
; Go for it ...
|
2013-05-09 11:56:54 +00:00
|
|
|
jmp (data_buffer)
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
read_param = * - source + target
|
2013-05-09 11:56:54 +00:00
|
|
|
.byte $04 ; PARAM_COUNT
|
2011-02-06 22:27:31 +00:00
|
|
|
read_ref = * - source + target
|
2013-05-09 11:56:54 +00:00
|
|
|
.byte $00 ; REF_NUM
|
2011-02-06 22:27:31 +00:00
|
|
|
data_buffer = * - source + target
|
2013-05-09 11:56:54 +00:00
|
|
|
.addr $2000 ; DATA_BUFFER
|
|
|
|
.word $FFFF ; REQUEST_COUNT
|
|
|
|
.word $0000 ; TRANS_COUNT
|
2011-02-06 22:27:31 +00:00
|
|
|
|
|
|
|
close_param = * - source + target
|
2013-05-09 11:56:54 +00:00
|
|
|
.byte $01 ; PARAM_COUNT
|
2011-02-06 22:27:31 +00:00
|
|
|
close_ref = * - source + target
|
2013-05-09 11:56:54 +00:00
|
|
|
.byte $00 ; REF_NUM
|
2011-02-06 22:27:31 +00:00
|
|
|
|
2012-01-02 11:09:25 +00:00
|
|
|
; Quit to ProDOS dispatcher
|
|
|
|
quit = * - source + target
|
2013-05-09 11:56:54 +00:00
|
|
|
: jsr $BF00
|
|
|
|
.byte $65 ; QUIT
|
|
|
|
.word quit_param
|
2012-01-02 11:09:25 +00:00
|
|
|
|
2011-02-06 22:27:31 +00:00
|
|
|
quit_param = * - source + target
|
2013-05-09 11:56:54 +00:00
|
|
|
.byte $04 ; PARAM_COUNT
|
|
|
|
.byte $00 ; QUIT_TYPE
|
|
|
|
.word $0000 ; RESERVED
|
|
|
|
.byte $00 ; RESERVED
|
|
|
|
.word $0000 ; RESERVED
|
2011-02-06 22:27:31 +00:00
|
|
|
|
2012-01-02 11:09:25 +00:00
|
|
|
size = * - source
|
2011-02-06 22:27:31 +00:00
|
|
|
|
2012-01-02 11:09:25 +00:00
|
|
|
target = DOSWARM - size
|
2011-02-06 22:27:31 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
dosvec: jmp quit
|