2 ; Oliver Schmidt, 2011-01-26
4 ; int __fastcall__ exec (const char* progname, const char* cmdline);
8 .import pushname, popname
9 .import popax, done, _exit
11 .include "zeropage.inc"
17 typerr: lda #$4A ; "Incompatible file format"
20 oserr: jsr popname ; Preserves A
31 ; ProDOS TechRefMan, chapter 5.1.5.1:
32 ; "The complete or partial pathname of the system program
33 ; is stored at $280, starting with a length byte."
34 ; In fact BASIC.SYSTEM does the same for BLOAD and BRUN of
35 ; binary programs so we should do the same too in any case
36 ; especially as _we_ rely on it in mainargs.s for argv[0].
48 sta mliparam + MLI::INFO::PATHNAME
49 stx mliparam + MLI::INFO::PATHNAME+1
51 ; Get file_type and aux_type
57 ; If we get here the program file at least exists so we copy
58 ; the loader stub right now and patch it later to set params
65 ; Check program file type
66 lda mliparam + MLI::INFO::FILE_TYPE
68 bne binary ; No, check for BIN file
70 ; SYS programs replace BASIC.SYSTEM so set in the ProDOS system bit map
71 ; protection for pages $80 - $BF just in case BASIC.SYSTEM is there now
72 ldx #$0F ; Start with protection for pages $B8 - $BF
73 lda #%00000001 ; Protect only system global page
74 : sta $BF60,x ; Set protection for 8 pages
75 lda #$00 ; Protect no page
78 bmi prodos ; Branch always
80 binary: cmp #$06 ; BIN file?
81 bne typerr ; No, wrong file type
83 ; Set BIN program load addr
84 lda mliparam + MLI::INFO::AUX_TYPE
85 ldx mliparam + MLI::INFO::AUX_TYPE+1
89 ; Check ProDOS system bit map for presence of BASIC.SYSTEM
90 lda $BF6F ; Protection for pages $B8 - $BF
91 cmp #%00000001 ; Exactly system global page is protected
94 ; Get highest available mem addr from BASIC.SYSTEM
95 ldx HIMEM+1 ; High byte
96 bne setbuf ; Branch always
98 ; BIN programs are supposed to quit through one of the two DOS
99 ; vectors so we set up those to point to the ProDOS dispatcher
100 setvec: ldx #$03 - 1 ; Size of JMP opcode
102 sta DOSWARM,x ; DOS warm start
103 sta DOSWARM + 3,x ; DOS cold start
107 ; No BASIC.SYSTEM so use addr of ProDOS system global page
108 prodos: ldx #>$BF00 ; High byte
110 ; The I/O buffer needs to be page aligned
111 setbuf: lda #$00 ; Low byte
113 ; The I/O buffer needs four pages
120 sta mliparam + MLI::OPEN::IO_BUFFER
121 stx mliparam + MLI::OPEN::IO_BUFFER+1
123 ; PATHNAME already set
124 .assert MLI::OPEN::PATHNAME = MLI::INFO::PATHNAME, error
126 ; Lower file level to avoid program file
127 ; being closed by C libary shutdown code
145 : lda mliparam + MLI::OPEN::REF_NUM
150 ; Calling the 80 column firmware needs the ROM switched
151 ; in, otherwise it copies the F8 ROM to the LC (@ $CEF4)
154 ; ProDOS TechRefMan, chapter 5.3.1.3:
155 ; "80-column text cards -- and other Apple IIe features -- can
156 ; be turned off using the following sequence of instructions:"
160 ; Switch in LC bank 2 for R/O
164 ; Call loader stub after C libary shutdown
170 ; Initiate C libary shutdown
179 ; Read whole program file
194 read_param = * - source + target
195 .byte $04 ; PARAM_COUNT
196 read_ref = * - source + target
198 data_buffer = * - source + target
199 .addr $2000 ; DATA_BUFFER
200 .word $FFFF ; REQUEST_COUNT
201 .word $0000 ; TRANS_COUNT
203 close_param = * - source + target
204 .byte $01 ; PARAM_COUNT
205 close_ref = * - source + target
208 ; Quit to ProDOS dispatcher
209 quit = * - source + target
214 quit_param = * - source + target
215 .byte $04 ; PARAM_COUNT
216 .byte $00 ; QUIT_TYPE
217 .word $0000 ; RESERVED
219 .word $0000 ; RESERVED
223 target = DOSWARM - size