2018-01-07 19:45:52 +00:00
|
|
|
.setcpu "6502"
|
|
|
|
|
|
|
|
.include "apple2.inc"
|
|
|
|
.include "../inc/apple2.inc"
|
|
|
|
.include "../inc/prodos.inc"
|
2018-02-07 02:42:20 +00:00
|
|
|
.include "../macros.inc"
|
2018-01-07 19:45:52 +00:00
|
|
|
|
2018-03-05 05:36:00 +00:00
|
|
|
;;; ============================================================
|
2018-01-07 19:45:52 +00:00
|
|
|
;;; Segment loaded into MAIN $290-$3EF
|
2018-03-05 05:36:00 +00:00
|
|
|
;;; ============================================================
|
2018-01-07 19:45:52 +00:00
|
|
|
|
|
|
|
;;; Used to invoke other programs (system, binary, BASIC)
|
|
|
|
|
|
|
|
.proc invoker
|
|
|
|
.org $290
|
|
|
|
|
|
|
|
PREFIX := $220
|
|
|
|
FILENAME := $280 ; File to invoke, set by caller
|
|
|
|
|
|
|
|
start:
|
|
|
|
jmp begin
|
|
|
|
|
2018-03-05 05:36:00 +00:00
|
|
|
;;; ============================================================
|
2018-01-07 19:45:52 +00:00
|
|
|
|
|
|
|
default_start_address := $2000
|
|
|
|
|
2018-02-28 02:38:18 +00:00
|
|
|
DEFINE_SET_PREFIX_PARAMS set_prefix_params, PREFIX
|
2018-01-07 19:45:52 +00:00
|
|
|
|
|
|
|
prefix_length:
|
|
|
|
.byte 0
|
|
|
|
|
2018-02-28 02:38:18 +00:00
|
|
|
DEFINE_OPEN_PARAMS open_params, FILENAME, $800, 1
|
|
|
|
DEFINE_READ_PARAMS read_params, default_start_address, $9F00
|
|
|
|
DEFINE_CLOSE_PARAMS close_params
|
|
|
|
DEFINE_GET_FILE_INFO_PARAMS get_info_params, FILENAME
|
2018-01-07 19:45:52 +00:00
|
|
|
|
|
|
|
.res 3
|
|
|
|
|
|
|
|
bs_path:
|
|
|
|
PASCAL_STRING "BASIC.SYSTEM"
|
|
|
|
|
2018-02-28 02:38:18 +00:00
|
|
|
DEFINE_QUIT_PARAMS quit_params, $EE, FILENAME
|
2018-01-07 19:45:52 +00:00
|
|
|
|
2018-03-05 05:36:00 +00:00
|
|
|
;;; ============================================================
|
2018-01-07 19:45:52 +00:00
|
|
|
|
|
|
|
set_prefix:
|
|
|
|
MLI_CALL SET_PREFIX, set_prefix_params
|
|
|
|
beq :+
|
|
|
|
pla
|
|
|
|
pla
|
|
|
|
jmp exit
|
|
|
|
: rts
|
|
|
|
|
2018-03-05 05:36:00 +00:00
|
|
|
;;; ============================================================
|
2018-01-07 19:45:52 +00:00
|
|
|
|
|
|
|
open: MLI_CALL OPEN, open_params
|
|
|
|
rts
|
|
|
|
|
2018-03-05 05:36:00 +00:00
|
|
|
;;; ============================================================
|
2018-01-07 19:45:52 +00:00
|
|
|
|
|
|
|
begin: lda ROMIN2
|
|
|
|
|
2018-02-07 02:42:20 +00:00
|
|
|
copy16 #default_start_address, jmp_addr
|
2018-01-07 19:45:52 +00:00
|
|
|
|
|
|
|
;; clear system memory bitmap
|
|
|
|
ldx #BITMAP_SIZE-2
|
|
|
|
lda #0
|
|
|
|
: sta BITMAP,x
|
|
|
|
dex
|
|
|
|
bne :-
|
|
|
|
|
|
|
|
jsr set_prefix
|
|
|
|
lda PREFIX
|
|
|
|
sta prefix_length
|
|
|
|
MLI_CALL GET_FILE_INFO, get_info_params
|
|
|
|
beq :+
|
|
|
|
jmp exit
|
2018-02-28 02:38:18 +00:00
|
|
|
: lda get_info_params::file_type
|
2018-01-07 19:45:52 +00:00
|
|
|
cmp #FT_S16
|
2018-01-08 05:53:39 +00:00
|
|
|
bne not_s16
|
2018-01-07 19:45:52 +00:00
|
|
|
jsr update_bitmap
|
|
|
|
jmp quit_call
|
2018-01-08 05:53:39 +00:00
|
|
|
not_s16:
|
2018-01-07 19:45:52 +00:00
|
|
|
|
2018-01-20 17:47:56 +00:00
|
|
|
cmp #FT_BINARY
|
2018-01-08 05:53:39 +00:00
|
|
|
bne not_binary
|
2018-02-28 02:38:18 +00:00
|
|
|
lda get_info_params::aux_type
|
2018-01-07 19:45:52 +00:00
|
|
|
sta jmp_addr
|
2018-02-28 02:38:18 +00:00
|
|
|
sta read_params::data_buffer
|
|
|
|
lda get_info_params::aux_type+1
|
2018-01-07 19:45:52 +00:00
|
|
|
sta jmp_addr+1
|
2018-02-28 02:38:18 +00:00
|
|
|
sta read_params::data_buffer+1
|
2018-01-08 05:53:39 +00:00
|
|
|
cmp #$0C ; If loading at page < $0C
|
|
|
|
bcs :+
|
|
|
|
lda #$BB ; ... use a high address buffer ($BB)
|
2018-02-28 02:38:18 +00:00
|
|
|
sta open_params::io_buffer+1
|
2018-01-08 05:53:39 +00:00
|
|
|
bne load_target ; always
|
|
|
|
: lda #$08 ; ... otherwise a low address buffer ($08)
|
2018-02-28 02:38:18 +00:00
|
|
|
sta open_params::io_buffer+1
|
2018-01-08 05:53:39 +00:00
|
|
|
bne load_target ; always
|
|
|
|
not_binary:
|
2018-01-07 19:45:52 +00:00
|
|
|
|
2018-01-08 05:53:39 +00:00
|
|
|
cmp #FT_BASIC ; BASIC?
|
2018-01-07 19:45:52 +00:00
|
|
|
bne load_target
|
|
|
|
|
|
|
|
;; Invoke BASIC.SYSTEM as path instead.
|
2018-02-28 02:38:18 +00:00
|
|
|
copy16 #bs_path, open_params::pathname
|
2018-01-07 19:45:52 +00:00
|
|
|
|
|
|
|
;; Try opening BASIC.SYSTEM with current prefix.
|
|
|
|
check_for_bs:
|
|
|
|
jsr open
|
|
|
|
beq found_bs
|
|
|
|
ldy PREFIX ; Pop a path segment to try
|
|
|
|
: lda PREFIX,y ; parent directory.
|
|
|
|
cmp #'/'
|
|
|
|
beq update_prefix
|
|
|
|
dey
|
|
|
|
cpy #1
|
|
|
|
bne :-
|
|
|
|
jmp exit
|
|
|
|
|
|
|
|
update_prefix: ; Update prefix and try again.
|
|
|
|
dey
|
|
|
|
sty PREFIX
|
|
|
|
jsr set_prefix
|
|
|
|
jmp check_for_bs
|
|
|
|
|
|
|
|
found_bs:
|
|
|
|
lda prefix_length
|
|
|
|
sta PREFIX
|
|
|
|
jmp do_read
|
|
|
|
|
|
|
|
load_target:
|
|
|
|
jsr open
|
|
|
|
bne exit
|
|
|
|
do_read:
|
|
|
|
lda open_params::ref_num
|
|
|
|
sta read_params::ref_num
|
|
|
|
MLI_CALL READ, read_params
|
|
|
|
bne exit
|
|
|
|
MLI_CALL CLOSE, close_params
|
|
|
|
bne exit
|
|
|
|
|
2018-01-08 05:53:39 +00:00
|
|
|
;; If it's BASIC, set prefix and copy filename to interpreter buffer.
|
2018-02-28 02:38:18 +00:00
|
|
|
lda get_info_params::file_type
|
2018-01-07 19:45:52 +00:00
|
|
|
cmp #FT_BASIC
|
|
|
|
bne update_stack
|
|
|
|
jsr set_prefix
|
|
|
|
ldy FILENAME
|
|
|
|
: lda FILENAME,y
|
|
|
|
sta $2006,y
|
|
|
|
dey
|
|
|
|
bpl :-
|
|
|
|
|
|
|
|
;; Set return address to the QUIT call below
|
|
|
|
update_stack:
|
|
|
|
lda #>(quit_call-1)
|
|
|
|
pha
|
|
|
|
lda #<(quit_call-1)
|
|
|
|
pha
|
|
|
|
jsr update_bitmap
|
|
|
|
|
|
|
|
jmp_addr := *+1
|
|
|
|
jmp default_start_address
|
|
|
|
|
|
|
|
quit_call:
|
|
|
|
MLI_CALL QUIT, quit_params
|
|
|
|
|
|
|
|
;; Update system bitmap
|
|
|
|
update_bitmap:
|
|
|
|
lda #%00000001 ; ProDOS global page
|
|
|
|
sta BITMAP+BITMAP_SIZE-1
|
|
|
|
lda #%11001111 ; ZP, Stack, Text Page 1
|
|
|
|
sta BITMAP
|
|
|
|
rts
|
|
|
|
|
|
|
|
exit: rts
|
|
|
|
|
|
|
|
;; Pad to $160 bytes
|
|
|
|
.res $160 - (* - start), 0
|
|
|
|
.endproc ; invoker
|