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
34 sta mliparam + MLI::INFO::PATHNAME
35 stx mliparam + MLI::INFO::PATHNAME+1
37 ; Get file_type and aux_type
43 ; If we get here the program file at least exists so we copy
44 ; the loader stub right now and patch it later to set params
51 ; Check program file type
52 lda mliparam + MLI::INFO::FILE_TYPE
54 bne binary ; No, check for BIN file
56 ; ProDOS TechRefMan, chapter 5.1.5.1:
57 ; "The complete or partial pathname of the system program
58 ; is stored at $280, starting with a length byte."
67 ; SYS programs replace BASIC.SYSTEM so set in the ProDOS system bit map
68 ; protection for pages $80 - $BF just in case BASIC.SYSTEM is there now
69 ldx #$0F ; Start with protection for pages $B8 - $BF
70 lda #%00000001 ; Protect only system global page
71 : sta $BF60,x ; Set protection for 8 pages
72 lda #$00 ; Protect no page
75 bmi prodos ; Branch always
77 binary: cmp #$06 ; BIN file?
78 bne typerr ; No, wrong file type
80 ; Set BIN program load addr
81 lda mliparam + MLI::INFO::AUX_TYPE
82 ldx mliparam + MLI::INFO::AUX_TYPE+1
86 ; Check ProDOS system bit map for presence of BASIC.SYSTEM
87 lda $BF6F ; Protection for pages $B8 - $BF
88 cmp #%00000001 ; Exactly system global page is protected
91 ; Get highest available mem addr from BASIC.SYSTEM
92 ldx HIMEM+1 ; High byte
93 bne setbuf ; Branch always
95 ; BIN programs are supposed to quit through one of the two DOS
96 ; vectors so we set up those to point to the ProDOS dispatcher
97 setvec: ldx #$03 - 1 ; Size of JMP opcode
99 sta DOSWARM,x ; DOS warm start
100 sta DOSWARM + 3,x ; DOS cold start
104 ; No BASIC.SYSTEM so use addr of ProDOS system global page
105 prodos: ldx #>$BF00 ; High byte
107 ; The I/O buffer needs to be page aligned
108 setbuf: lda #$00 ; Low byte
110 ; The I/O buffer needs four pages
117 sta mliparam + MLI::OPEN::IO_BUFFER
118 stx mliparam + MLI::OPEN::IO_BUFFER+1
120 ; PATHNAME already set
121 .assert MLI::OPEN::PATHNAME = MLI::INFO::PATHNAME, error
123 ; Lower file level to avoid program file
124 ; being closed by C libary shutdown code
142 : lda mliparam + MLI::OPEN::REF_NUM
147 ; Calling the 80 column firmware needs the ROM switched
148 ; in, otherwise it copies the F8 ROM to the LC (@ $CEF4)
151 ; ProDOS TechRefMan, chapter 5.3.1.3:
152 ; "80-column text cards -- and other Apple IIe features -- can
153 ; be turned off using the following sequence of instructions:"
157 ; Switch in LC bank 2 for R/O
161 ; Call loader stub after C libary shutdown
167 ; Initiate C libary shutdown
176 ; Read whole program file
191 read_param = * - source + target
192 .byte $04 ; PARAM_COUNT
193 read_ref = * - source + target
195 data_buffer = * - source + target
196 .addr $2000 ; DATA_BUFFER
197 .word $FFFF ; REQUEST_COUNT
198 .word $0000 ; TRANS_COUNT
200 close_param = * - source + target
201 .byte $01 ; PARAM_COUNT
202 close_ref = * - source + target
205 ; Quit to ProDOS dispatcher
206 quit = * - source + target
211 quit_param = * - source + target
212 .byte $04 ; PARAM_COUNT
213 .byte $00 ; QUIT_TYPE
214 .word $0000 ; RESERVED
216 .word $0000 ; RESERVED
220 target = DOSWARM - size