a2d/desktop/loader.s

654 lines
16 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/prodos.inc"
2018-02-07 02:42:20 +00:00
.include "../macros.inc"
2017-12-31 02:02:15 +00:00
2018-01-07 19:45:52 +00:00
DESKTOP_INIT := $0800 ; init location
L7ECA := $7ECA ; ???
2018-01-05 05:57:50 +00:00
2018-03-05 05:36:00 +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
2018-02-26 04:28:23 +00:00
DEFINE_QUIT_PARAMS quit_params
2018-01-05 05:57:50 +00:00
.endproc ; install_as_quit
2018-03-05 05:36:00 +00:00
;;; ============================================================
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:
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"
2018-02-26 04:28:23 +00:00
filename:
2018-01-05 05:57:50 +00:00
PASCAL_STRING "DeskTop2"
2018-02-26 04:28:23 +00:00
DEFINE_READ_PARAMS read_params, $1E00, $400 ; so the $200 byte mark ends up at $2000
DEFINE_CLOSE_PARAMS close_params
DEFINE_SET_PREFIX_PARAMS prefix_params, prefix_buffer
DEFINE_OPEN_PARAMS open_params, filename, $1A00
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
: sta BITMAP,x
2017-09-17 18:18:47 +00:00
dex
bpl :-
lda #%11001111 ; Protect ZP, stack, Text Page 1
sta BITMAP
lda reinstall_flag
bne no_reinstall
;; Re-install quit routine (with prefix memorized)
MLI_CALL GET_PREFIX, prefix_params
beq :+
jmp crash
: lda #$FF
sta reinstall_flag
2018-02-07 02:42:20 +00:00
copy16 IRQ_VECTOR, irq_saved
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:
2018-02-07 02:42:20 +00:00
copy16 irq_saved, IRQ_VECTOR
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 :-
and #CHAR_MASK
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
.endproc ; quit_routine
2018-03-05 05:36:00 +00:00
;;; ============================================================
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
;; Pad to be at $200 into the file
.res $200 - (.sizeof(install_as_quit) + .sizeof(quit_routine)), 0
2018-01-05 08:26:13 +00:00
.org $2000
2018-01-05 08:26:13 +00:00
jmp start
2018-02-26 04:28:23 +00:00
DEFINE_OPEN_PARAMS open_params, filename, $3000
2018-01-05 08:26:13 +00:00
2018-02-26 04:28:23 +00:00
DEFINE_READ_PARAMS read_params, 0, 0
2018-01-05 05:57:50 +00:00
2018-02-26 04:28:23 +00:00
DEFINE_CLOSE_PARAMS close_params
DEFINE_SET_MARK_PARAMS set_mark_params, $580 ; This many bytes before the good stuff.
2018-01-05 08:26:13 +00:00
2018-02-26 04:28:23 +00:00
filename:
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:
2018-01-29 05:18:00 +00:00
;;; $4000 aux - MGTK and DeskTop code
2018-01-07 19:45:52 +00:00
;;; $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 DeskTop init routine
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-02-26 04:28:23 +00:00
copy16 segment_addr_table,x, read_params::data_buffer
copy16 segment_size_table,x, read_params::request_count
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-02-26 04:28:23 +00:00
lda read_params::data_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-02-26 04:28:23 +00:00
lda read_params::data_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
2018-11-17 05:13:52 +00:00
PAD_TO $2200
2018-01-05 08:26:13 +00:00
.endproc ; install_segments
2018-03-05 05:36:00 +00:00
;;; ============================================================
2018-01-05 08:26:13 +00:00
;;; Not sure where this could be invoked from
.proc dump_screen
.org $280
SLOT1 := $C100
TAB := $09
LF := $0A
CR := $0D
ESC := $1B
hbasl := $6
2018-03-15 03:53:20 +00:00
screen_width := 560
screen_height := 192
2018-02-05 05:05:31 +00:00
;; Test for OpenApple+SolidApple+P
2017-09-17 18:18:47 +00:00
pha
2017-12-31 20:04:22 +00:00
lda BUTN0
and BUTN1
bpl :+
2017-12-31 20:04:22 +00:00
lda KBD
cmp #('P' | $80)
beq invoke
: pla
jmp L7ECA ; ???
2017-09-17 18:18:47 +00:00
invoke: 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
lda #0
sta y_row
jmp print_screen
2017-09-17 18:18:47 +00:00
.proc send_spacing
ldy #0
: lda spacing_sequence,y
beq done
jsr cout
2017-09-17 18:18:47 +00:00
iny
jmp :-
done: rts
.endproc
2017-09-17 18:18:47 +00:00
.proc send_restore_state
2017-09-17 18:18:47 +00:00
ldy #$00
: lda restore_state,y
beq done
jsr cout
2017-09-17 18:18:47 +00:00
iny
jmp :-
done: rts
.endproc
2017-09-17 18:18:47 +00:00
.proc send_init_graphics
ldx #0
: lda init_graphics,x
jsr cout
2017-09-17 18:18:47 +00:00
inx
cpx #6
bne :-
2017-09-17 18:18:47 +00:00
rts
init_graphics:
.byte ESC,"G0560" ; Graphics, 560 data bytes
.endproc
2017-09-17 18:18:47 +00:00
.proc send_row
;; Tell printer to expect graphics
jsr send_init_graphics
ldy #0
sty col_num
lda #1
sta mask
lda #0
sta x_coord
sta x_coord+1
col_loop:
lda #8 ; 8 vertical pixels per row
sta count
lda y_row
sta y_coord
;; Accumulate 8 pixels
y_loop: lda y_coord
jsr compute_hbasl ; Row address in screen
lda col_num
lsr a ; Even or odd column?
2017-09-17 18:18:47 +00:00
tay
sta PAGE2OFF ; By default, read main mem $2000-$3FFF
bcs :+ ; But even columns come from aux, so...
sta PAGE2ON ; Read aux mem $2000-$3FFF
: lda (hbasl),y ; Grab the whole byte
and mask ; Isolate the pixel we care about
cmp #1 ; Set carry if non-zero
ror accum ; And slide it into place
inc y_coord
dec count
bne y_loop
;; Send the 8 pixels to the printer.
lda accum ; Now output it
eor #$FF ; Invert pixels (screen vs. print)
sta PAGE2OFF ; Read main mem $2000-$3FFF
jsr cout ; And actually print
;; Done all pixels across?
lda x_coord
cmp #<(screen_width-1)
bne :+
lda x_coord+1
cmp #>(screen_width-1)
beq done
;; Next pixel to the right
: asl mask
bpl :+ ; Only 7 pixels per column
lda #1
sta mask
inc col_num
: inc x_coord
bne col_loop
inc x_coord+1
bne col_loop
done: sta PAGE2OFF ; Read main mem $2000-$3FFF
2017-09-17 18:18:47 +00:00
rts
.endproc
.proc print_screen
;; Init printer
jsr pr_num_1
jsr send_spacing
2017-09-17 18:18:47 +00:00
;; Print a row (560x8), CR+LF
loop: jsr send_row
lda #CR
jsr cout
lda #LF
jsr cout
lda y_coord
sta y_row
2018-03-15 03:53:20 +00:00
cmp #screen_height
bcc loop
;; Finish up
lda #CR
jsr cout
lda #CR
jsr cout
jsr send_restore_state
2017-09-17 18:18:47 +00:00
sta ALTZPON
lda LCBANK1
lda LCBANK1
rts
.endproc
2017-09-17 18:18:47 +00:00
;; Given y-coordinate in A, compute HBASL-equivalent
.proc compute_hbasl
pha
2017-09-17 18:18:47 +00:00
and #$C7
eor #$08
sta $07
and #$F0
lsr a
lsr a
lsr a
sta hbasl
2017-09-17 18:18:47 +00:00
pla
and #$38
asl a
asl a
eor hbasl
2017-09-17 18:18:47 +00:00
asl a
rol hbasl+1
2017-09-17 18:18:47 +00:00
asl a
rol hbasl+1
eor hbasl
sta hbasl
2017-09-17 18:18:47 +00:00
rts
.endproc
2017-09-17 18:18:47 +00:00
.proc pr_num_1
lda #>SLOT1
sta COUT_HOOK+1
lda #<SLOT1
sta COUT_HOOK
lda #(CR | $80)
jsr invoke_slot1
2017-09-17 18:18:47 +00:00
rts
.endproc
2017-09-17 18:18:47 +00:00
.proc cout
jsr COUT
2017-09-17 18:18:47 +00:00
rts
.endproc
y_row: .byte 0 ; y-coordinate of row start (0, 8, ...)
x_coord:.word 0 ; x-coordinate of pixels being accumulated
y_coord:.byte 0 ; iterates y_row to y_row+7
mask: .byte 0 ; mask for pixel being processed
accum: .byte 0 ; accumulates pixels for output
count: .byte 0 ; 8...1 while a row is output
col_num:.byte 0 ; 0...79
2017-09-17 18:18:47 +00:00
.byte 0, 0
spacing_sequence:
.byte ESC,'e' ; 107 DPI (horizontal)
.byte ESC,"T16" ; distance between lines (16/144")
.byte TAB,$4C,$20,$44,$8D ; ???
.byte TAB,$5A,$8D ; ???
.byte 0
restore_state:
.byte ESC,'N' ; 80 DPI (horizontal)
.byte ESC,"T24" ; distance between lines (24/144")
.byte 0
invoke_slot1:
jmp SLOT1
2018-11-17 05:13:52 +00:00
PAD_TO $400
.endproc ; dump_screen
.assert .sizeof(install_as_quit) + .sizeof(quit_routine) + .sizeof(install_segments) + .sizeof(dump_screen) = $580, error, "Size mismatch"