a2d/desktop/loader.s

663 lines
14 KiB
ArmAsm
Raw Normal View History

2018-01-05 05:57:50 +00:00
.setcpu "6502"
2017-09-17 18:18:47 +00:00
2017-12-31 02:02:15 +00:00
.include "apple2.inc"
.include "../inc/apple2.inc"
.include "../inc/auxmem.inc"
.include "../inc/prodos.inc"
2018-01-07 19:45:52 +00:00
DESKTOP_INIT := $0800 ; init location
L7ECA := $7ECA ; ???
2018-01-05 05:57:50 +00:00
;;; ==================================================
2018-01-05 05:57:50 +00:00
;;; Patch self in as ProDOS QUIT routine (LCBank2 $D100)
;;; and invoke QUIT. Note that only $200 bytes are copied.
2018-01-05 05:57:50 +00:00
.proc install_as_quit
.org $2000
2018-01-05 05:57:50 +00:00
src := quit_routine
dst := SELECTOR
2018-01-05 05:57:50 +00:00
lda LCBANK2
lda LCBANK2
2017-09-17 18:18:47 +00:00
ldy #$00
2018-01-05 05:57:50 +00:00
loop: lda src,y
sta dst,y
lda src+$100,y
sta dst+$100,y
dey
bne loop
2017-12-31 20:04:22 +00:00
lda ROMIN2
2018-01-05 05:57:50 +00:00
MLI_CALL QUIT, quit_params
.proc quit_params
params: .byte 4
.byte 0
.word 0
.byte 0
.word 0
.endproc
.endproc ; install_as_quit
;;; ==================================================
2018-01-05 05:57:50 +00:00
;;; New QUIT routine. Gets relocated to $1000 by ProDOS before
;;; being executed.
.proc quit_routine
.org $1000
self:
2018-01-05 05:57:50 +00:00
jmp start
2018-01-05 05:57:50 +00:00
reinstall_flag: ; set once prefix saved and reinstalled
.byte 0
2018-01-05 05:57:50 +00:00
.byte "Mouse Desk"
.byte 0
splash_string:
2018-01-05 05:57:50 +00:00
PASCAL_STRING "Loading Apple II DeskTop"
pathname:
2018-01-05 05:57:50 +00:00
PASCAL_STRING "DeskTop2"
.proc read_params
params: .byte 4
ref_num:.byte 0
2018-01-05 08:26:13 +00:00
buffer: .addr $1E00 ; so the $200 byte mark ends up at $2000
request:.word $0400
trans: .word 0
.endproc
.proc close_params
params: .byte 1
ref_num:.byte 0 ; close all
.endproc
.proc prefix_params
params: .byte 1
buffer: .addr prefix_buffer
.endproc
.proc open_params
params: .byte 3
path: .addr pathname
buffer: .addr $1A00
ref_num:.byte 0
.endproc
start: lda ROMIN2
;; Show a splash message on 80 column text screen
2017-12-31 02:02:15 +00:00
jsr SETVID
jsr SETKBD
2017-12-31 20:04:22 +00:00
sta CLR80VID
sta SETALTCHAR
sta CLR80COL
2017-12-31 02:02:15 +00:00
jsr SLOT3ENTRY
jsr HOME
lda #$00 ; IIgs specific ???
sta SHADOW
2017-09-17 18:18:47 +00:00
lda #$40
2017-09-17 21:52:46 +00:00
sta RAMWRTON
sta $0100 ; ???
sta $0101 ; ???
2017-09-17 18:18:47 +00:00
sta RAMWRTOFF
lda #12 ; VTAB 12
sta CV
2017-12-31 02:02:15 +00:00
jsr VTAB
lda #80 ; HTAB (80-width)/2
sec ; to center
sbc splash_string
2017-09-17 18:18:47 +00:00
lsr a
sta CH
2017-09-17 18:18:47 +00:00
ldy #$00
: lda splash_string+1,y
2017-09-17 18:18:47 +00:00
ora #$80
2017-09-17 21:52:46 +00:00
jsr COUT
iny
cpy splash_string
bne :-
;; Close all open files (???)
MLI_CALL CLOSE, close_params
;; Initialize system memory bitmap
ldx #BITMAP_SIZE-1
lda #$01 ; Protect ProDOS global page
sta BITMAP,x
2017-09-17 18:18:47 +00:00
dex
lda #$00
L109F: sta BITMAP,x
2017-09-17 18:18:47 +00:00
dex
2018-01-05 06:00:08 +00:00
bpl L109F
lda #%11001111 ; Protect ZP, stack, Text Page 1
sta BITMAP
lda reinstall_flag
bne no_reinstall
;; Re-install quit routine (with prefix memorized)
L10AF: MLI_CALL GET_PREFIX, prefix_params
beq :+
jmp crash
: lda #$FF
sta reinstall_flag
lda IRQ_VECTOR
sta irq_saved
lda IRQ_VECTOR+1
sta irq_saved+1
2017-12-31 20:04:22 +00:00
lda LCBANK2
lda LCBANK2
ldy #0
: lda self,y
sta SELECTOR,y
lda self+$100,y
sta SELECTOR+$100,y
2017-09-17 18:18:47 +00:00
dey
bne :-
2017-12-31 20:04:22 +00:00
lda ROMIN2
jmp done_reinstall
no_reinstall:
lda irq_saved
sta IRQ_VECTOR
lda irq_saved+1
sta IRQ_VECTOR+1
done_reinstall:
;; Set the prefix, read the first $400 bytes of this system
;; file in (at $1E00), and invoke $200 bytes into it (at $2000)
MLI_CALL SET_PREFIX, prefix_params
beq :+
jmp prompt_for_system_disk
: MLI_CALL OPEN, open_params
beq :+
jmp crash
: lda open_params::ref_num
sta read_params::ref_num
MLI_CALL READ, read_params
beq :+
jmp crash
: MLI_CALL CLOSE, close_params
beq :+
jmp crash
: jmp $2000 ; Invoke system file
;; Display a string, and wait for Return keypress
prompt_for_system_disk:
jsr SLOT3ENTRY ; 80 column mode
2017-12-31 02:02:15 +00:00
jsr HOME
lda #12 ; VTAB 12
sta CV
2017-12-31 02:02:15 +00:00
jsr VTAB
lda #80 ; HTAB (80 - width)/2
sec ; to center the string
sbc disk_prompt
2017-09-17 18:18:47 +00:00
lsr a
sta CH
2017-09-17 18:18:47 +00:00
ldy #$00
: lda disk_prompt+1,y
2017-09-17 18:18:47 +00:00
ora #$80
jsr COUT
iny
cpy disk_prompt
bne :-
wait: sta KBDSTRB
: lda KBD
bpl :-
2017-09-17 18:18:47 +00:00
and #$7F
cmp #$0D ; Return
bne wait
jmp start
2017-09-17 18:18:47 +00:00
disk_prompt:
2018-01-05 05:57:50 +00:00
PASCAL_STRING "Insert the system disk and Press Return."
irq_saved:
.addr 0
crash: sta $6 ; Crash?
jmp MONZ
prefix_buffer:
.res 64, 0
;; ???
L11D0:
2017-09-17 21:52:46 +00:00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00
.endproc ; quit_routine
;;; ==================================================
2018-01-07 19:45:52 +00:00
;;; This chunk is invoked at $2000 after the quit handler has been invoked
;;; and updated itself. Using the segment_*_tables below, this loads the
;;; DeskTop application into various parts of main, aux, and bank-switched
;;; memory, then invokes the DeskTop initialization routine.
2018-01-05 08:26:13 +00:00
.proc install_segments
.org $2000
2018-01-05 08:26:13 +00:00
jmp start
.proc open_params
params: .byte 3
path: .addr pathname
buffer: .addr $3000
ref_num:.byte 0
.endproc
.proc read_params
params: .byte 4
ref_num:.byte 0
buffer: .addr 0
request:.word 0
trans: .word 0
.endproc
.proc close_params
params: .byte 1
ref_num:.byte 0
.endproc
2018-01-05 05:57:50 +00:00
2018-01-05 08:26:13 +00:00
.proc set_mark_params
params: .byte 2
ref_num:.byte 0
pos: .faraddr $580 ; This many bytes before the good stuff.
.endproc
pathname:
2018-01-05 05:57:50 +00:00
PASCAL_STRING "DeskTop2"
2018-01-05 08:26:13 +00:00
;;; Consecutive segments are loaded, |size| bytes are loaded at |addr|
;;; then relocated to |dest| according to |type|.
2018-01-07 19:45:52 +00:00
;;; Segments are:
;;; $4000 aux - A2D GUI library and DeskTop code
;;; $D000 aux/banked - DeskTop code callable from main, and resources
;;; $FB00 aux/banked - more DeskTop resources (icons, strings, etc)
;;; $4000 main - more DeskTop code
;;; $0800 main - DeskTop initialization code; later overwritten by DAs
;;; $0290 main - Routine to invoke other programs
2018-01-05 08:26:13 +00:00
segment_addr_table:
.word $3F00,$4000,$4000,$4000,$0800,$0290
segment_dest_table:
.addr $4000,$D000,$FB00,$4000,$0800,$0290
segment_size_table:
.word $8000,$1D00,$0500,$7F00,$0800,$0160
segment_type_table: ; 0 = main, 1 = aux, 2 = banked (aux)
.byte 1,2,2,0,0,0
2018-01-05 08:26:13 +00:00
num_segments:
.byte 6
start:
;; Configure system bitmap - everything is available
ldx #BITMAP_SIZE-1
lda #0
: sta BITMAP+1,x
2017-09-17 21:52:46 +00:00
dex
2018-01-05 08:26:13 +00:00
bpl :-
;; Open this system file
2017-09-17 18:18:47 +00:00
php
sei
2018-01-05 08:26:13 +00:00
MLI_CALL OPEN, open_params
2017-09-17 18:18:47 +00:00
plp
and #$FF
2018-01-05 08:26:13 +00:00
beq :+
brk ; crash
: lda open_params::ref_num
sta set_mark_params::ref_num
sta read_params::ref_num
2017-09-17 21:52:46 +00:00
php
sei
2018-01-05 08:26:13 +00:00
MLI_CALL SET_MARK, set_mark_params
2017-09-17 18:18:47 +00:00
plp
and #$FF
2018-01-05 08:26:13 +00:00
beq :+
brk ; crash
: lda #0
sta segment_num
loop: lda segment_num
cmp num_segments
bne continue
;; Close and invoke... $800 ???
2017-09-17 18:18:47 +00:00
php
sei
2018-01-05 08:26:13 +00:00
MLI_CALL CLOSE, close_params
2017-09-17 18:18:47 +00:00
plp
and #$FF
2018-01-05 08:26:13 +00:00
beq :+
brk ; crash
2018-01-07 19:45:52 +00:00
: jmp DESKTOP_INIT
2017-09-17 18:18:47 +00:00
2018-01-05 08:26:13 +00:00
continue:
asl a
2017-09-17 18:18:47 +00:00
tax
2018-01-05 08:26:13 +00:00
lda segment_addr_table,x
sta read_params::buffer
lda segment_addr_table+1,x
sta read_params::buffer+1
lda segment_size_table,x
sta read_params::request
lda segment_size_table+1,x
sta read_params::request+1
2017-09-17 18:18:47 +00:00
php
sei
2018-01-05 08:26:13 +00:00
MLI_CALL READ, read_params
2017-09-17 18:18:47 +00:00
plp
2018-01-07 19:45:52 +00:00
and #$FF ; ???
2018-01-05 08:26:13 +00:00
beq :+
brk ; crash
: ldx segment_num
lda segment_type_table,x
beq next_segment ; type 0 = main, so done
cmp #2
beq :+
jsr aux_segment
jmp next_segment
: jsr banked_segment
2017-09-17 18:18:47 +00:00
2018-01-05 08:26:13 +00:00
next_segment:
inc segment_num
jmp loop
2017-09-17 18:18:47 +00:00
2018-01-05 08:26:13 +00:00
segment_num: .byte 0
;; Handle bank-switched memory segment
.proc banked_segment
2018-01-07 19:45:52 +00:00
src := $6
dst := $8
2017-09-17 18:18:47 +00:00
sta ALTZPON
lda LCBANK1
lda LCBANK1
2018-01-07 19:45:52 +00:00
lda #$80 ; ???
2017-09-17 18:18:47 +00:00
sta $0100
sta $0101
2018-01-07 19:45:52 +00:00
lda #0
sta src
sta dst
2018-01-05 08:26:13 +00:00
lda segment_num
2017-09-17 18:18:47 +00:00
asl a
tax
2018-01-05 08:26:13 +00:00
lda segment_dest_table+1,x
2018-01-07 19:45:52 +00:00
sta dst+1
2018-01-05 08:26:13 +00:00
lda read_params::buffer+1
2018-01-07 19:45:52 +00:00
sta src+1
2017-09-17 18:18:47 +00:00
clc
2018-01-05 08:26:13 +00:00
adc segment_size_table+1,x
sta max_page
2018-01-05 08:26:13 +00:00
lda segment_size_table,x
beq :+
inc max_page
2018-01-07 19:45:52 +00:00
: ldy #0
2018-01-07 19:45:52 +00:00
loop: lda (src),y
sta (dst),y
2017-09-17 18:18:47 +00:00
iny
bne loop
2018-01-07 19:45:52 +00:00
inc src+1
inc dst+1
lda src+1
cmp max_page
bne loop
2018-01-07 19:45:52 +00:00
2017-09-17 18:18:47 +00:00
sta ALTZPOFF
2017-12-31 20:04:22 +00:00
lda ROMIN2
2017-09-17 18:18:47 +00:00
rts
max_page:
.byte 0
.endproc
2018-01-05 08:26:13 +00:00
;; Handle aux memory segment
.proc aux_segment
2018-01-07 19:45:52 +00:00
src := $6
dst := $8
lda #0
sta src
sta dst
2018-01-05 08:26:13 +00:00
lda segment_num
2017-09-17 18:18:47 +00:00
asl a
tax
2018-01-05 08:26:13 +00:00
lda segment_dest_table+1,x
2018-01-07 19:45:52 +00:00
sta dst+1
2018-01-05 08:26:13 +00:00
lda read_params::buffer+1
2018-01-07 19:45:52 +00:00
sta src+1
2017-09-17 18:18:47 +00:00
clc
2018-01-05 08:26:13 +00:00
adc segment_size_table+1,x
sta max_page
2017-09-17 18:18:47 +00:00
sta RAMRDOFF
sta RAMWRTON
2018-01-07 19:45:52 +00:00
ldy #0
loop: lda (src),y
sta (dst),y
2017-09-17 18:18:47 +00:00
iny
bne loop
2018-01-07 19:45:52 +00:00
inc src+1
inc dst+1
lda src+1
cmp max_page
bne loop
2017-09-17 18:18:47 +00:00
sta RAMWRTOFF
rts
max_page:
.byte 0
.endproc
2018-01-05 08:26:13 +00:00
;; Padding
.res $2200 - *,0
.endproc ; install_segments
;;; ==================================================
;;; Not sure where this could be invoked from
.proc rest
L02B4 := $02B4
L02B6 := $02B6
L02C3 := $02C3
L02C5 := $02C5
L02E6 := $02E6
L035F := $035F
L0393 := $0393
L03B3 := $03B3
L03C1 := $03C1
L03E5 := $03E5
;; Test for OpenApple+ClosedApple+P
2017-09-17 18:18:47 +00:00
pha
2017-12-31 20:04:22 +00:00
lda BUTN0
and BUTN1
2018-01-05 08:26:13 +00:00
bpl L2210
2017-12-31 20:04:22 +00:00
lda KBD
cmp #('P' | $80)
2018-01-05 08:26:13 +00:00
beq L2214
L2210: pla
2017-09-17 18:18:47 +00:00
jmp L7ECA
;; Invoked if OA+CA+P is held
2018-01-05 08:26:13 +00:00
L2214: sta KBDSTRB
2017-12-31 20:04:22 +00:00
sta SET80COL
sta SET80VID
sta DHIRESON
lda TXTCLR
lda HIRES
2017-09-17 18:18:47 +00:00
sta ALTZPOFF
2017-12-31 20:04:22 +00:00
sta ROMIN2
2017-09-17 18:18:47 +00:00
lda #$00
sta $03C5
jmp L035F
2017-09-17 18:18:47 +00:00
ldy #$00
lda $03CF,y
2018-01-05 08:26:13 +00:00
beq L2242
2017-09-17 18:18:47 +00:00
jsr L03C1
iny
jmp L02B6
2018-01-05 08:26:13 +00:00
L2242: rts
2017-09-17 18:18:47 +00:00
ldy #$00
lda $03DE,y
2018-01-05 08:26:13 +00:00
beq L2251
2017-09-17 18:18:47 +00:00
jsr L03C1
iny
jmp L02C5
2018-01-05 08:26:13 +00:00
L2251: rts
2017-09-17 18:18:47 +00:00
ldx #$00
2018-01-05 08:26:13 +00:00
L2254: lda $02E0,x
2017-09-17 18:18:47 +00:00
jsr L03C1
inx
cpx #$06
2018-01-05 08:26:13 +00:00
bne L2254
2017-09-17 18:18:47 +00:00
rts
.byte $1B,$47,$30,$35,$36,$30 ; ???
jsr $02D2
2017-09-17 18:18:47 +00:00
ldy #$00
sty $03CC
lda #$01
sta $03C9
lda #$00
sta $03C6
sta $03C7
2018-01-05 08:26:13 +00:00
L227B: lda #$08
2017-09-17 18:18:47 +00:00
sta $03CB
lda $03C5
sta $03C8
2018-01-05 08:26:13 +00:00
L2286: lda $03C8
2017-09-17 18:18:47 +00:00
jsr L0393
lda $03CC
lsr a
tay
2017-12-31 20:04:22 +00:00
sta LOWSCR
2018-01-05 08:26:13 +00:00
bcs L2299
2017-12-31 20:04:22 +00:00
sta HISCR
2018-01-05 08:26:13 +00:00
L2299: lda ($06),y
2017-09-17 18:18:47 +00:00
and $03C9
cmp #$01
ror $03CA
inc $03C8
dec $03CB
2018-01-05 08:26:13 +00:00
bne L2286
2017-09-17 18:18:47 +00:00
lda $03CA
eor #$FF
2017-12-31 20:04:22 +00:00
sta LOWSCR
2017-09-17 18:18:47 +00:00
jsr L03C1
lda $03C6
cmp #$2F
2018-01-05 08:26:13 +00:00
bne L22C4
2017-09-17 18:18:47 +00:00
lda $03C7
cmp #$02
2018-01-05 08:26:13 +00:00
beq L22DB
L22C4: asl $03C9
bpl L22D1
2017-09-17 18:18:47 +00:00
lda #$01
sta $03C9
inc $03CC
2018-01-05 08:26:13 +00:00
L22D1: inc $03C6
bne L227B
2017-09-17 18:18:47 +00:00
inc $03C7
2018-01-05 08:26:13 +00:00
bne L227B
L22DB: sta LOWSCR
2017-09-17 18:18:47 +00:00
rts
jsr L03B3
jsr L02B4
2018-01-05 08:26:13 +00:00
L22E5: jsr L02E6
2017-09-17 18:18:47 +00:00
lda #$0D
jsr L03C1
lda #$0A
jsr L03C1
lda $03C8
sta $03C5
cmp #$C0
2018-01-05 08:26:13 +00:00
bcc L22E5
2017-09-17 18:18:47 +00:00
lda #$0D
jsr L03C1
lda #$0D
jsr L03C1
jsr L02C3
sta ALTZPON
lda LCBANK1
lda LCBANK1
rts
pha
and #$C7
eor #$08
sta $07
and #$F0
lsr a
lsr a
lsr a
sta $06
pla
and #$38
asl a
asl a
eor $06
asl a
rol $07
asl a
rol $07
eor $06
sta $06
rts
lda #>$C100
sta COUT_HOOK+1
lda #<$C100
sta COUT_HOOK
2017-09-17 18:18:47 +00:00
lda #$8D
jsr L03E5
rts
jsr COUT
rts
2018-01-05 08:26:13 +00:00
L2345: .byte $00,$00,$00,$00,$00,$00,$00,$00
2017-09-17 21:52:46 +00:00
.byte $00,$00,$1B,$65,$1B,$54,$31,$36
.byte $09,$4C,$20,$44,$8D,$09,$5A,$8D
.byte $00,$1B,$4E,$1B,$54,$32,$34,$00
.byte $4C,$00,$C1,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00
.endproc ; rest