Expose JT entry point for restoring system state

This commit is contained in:
Joshua Bell 2019-01-20 15:04:52 -08:00
parent 4763b829aa
commit 10d84c1e11
5 changed files with 55 additions and 116 deletions

View File

@ -129,6 +129,10 @@ Restore from overlay routine
Set DHR color or monochrome mode, respectively. DHR monochrome mode is supported natively on the Apple IIgs, and via the AppleColor card and Le Chat Mauve, and is used by default by DeskTop. Desk Accessories that display images or exit DeskTop can can toggle the mode.
#### `JUMP_TABLE_RESTORE_SYS` ($4048) *
Used when exiting DeskTop; exit DHR mode, restores DHR mode to color, restores detached devices and reformats /RAM if needed, and banks in ROM and main ZP.
<!-- ============================================================ -->
## DeskTop API

View File

@ -54,29 +54,8 @@ start:
lda #$FE ; "BASIC.SYSTEM not found"
bne fail
;; Restore devices DeskTop may have removed
: jsr restore_device_list
jsr JUMP_TABLE_COLOR_MODE
;; Restore to normal state
sta ALTZPOFF
lda ROMIN2
jsr SETVID
jsr SETKBD
jsr INIT
jsr HOME
sta TXTSET
sta LOWSCR
sta LORES
sta MIXCLR
sta DHIRESOFF
sta CLRALTCHAR
sta CLR80VID
sta CLR80COL
;; Reformat /RAM if it was restored
jsr maybe_reformat_ram
;; Restore system state: devices, /RAM, ROM/ZP banks.
: jsr JUMP_TABLE_RESTORE_SYS
;; Load BS
MLI_CALL OPEN, open_params
@ -225,46 +204,3 @@ fail: return #1
lda LCBANK1
rts
.endproc
;;; ============================================================
.proc restore_device_list
ldx devlst_backup
inx
: copy devlst_backup,x, DEVLST-1,x
dex
bpl :-
rts
.endproc
;;; ============================================================
.proc maybe_reformat_ram
ram_unit_number = (1<<7 | 3<<4 | DT_RAM)
;; Search DEVLST to see if S3D2 RAM was restored
ldx DEVCNT
: lda DEVLST,x
cmp #ram_unit_number
beq format
dex
bpl :-
rts
;; NOTE: Assumes driver (in DEVADR) was not modified
;; when detached.
;; /RAM FORMAT call; see ProDOS 8 TRM 5.2.2.4 for details
format: copy #DRIVER_COMMAND_FORMAT, DRIVER_COMMAND
copy #ram_unit_number, DRIVER_UNIT_NUMBER
copy16 #$2000, DRIVER_BUFFER
lda LCBANK1
lda LCBANK1
jsr driver
sta ROMIN2
rts
RAMSLOT := DEVADR + $16 ; Slot 3, Drive 2
driver: jmp (RAMSLOT)
.endproc

View File

@ -63,6 +63,7 @@ JUMP_TABLE_CUR_WATCH := $403C ; Changes mouse cursor to watch
JUMP_TABLE_RESTORE_OVL := $403F ; Restore from overlay routine
JUMP_TABLE_COLOR_MODE := $4042 ; Set DHR color mode (IIgs, AppleColor, Le Chat Mauve) *
JUMP_TABLE_MONO_MODE := $4045 ; Set DHR mono mode (IIgs, AppleColor, Le Chat Mauve) *
JUMP_TABLE_RESTORE_SYS := $4048 ; Exit DHR, restore devices and /RAM, bank in ROM and ZP. *
;;; ============================================================
;;; Error codes used for alerts which are not ProDOS errors
@ -167,10 +168,6 @@ path_table := $DFB3 ; window address table
selected_file_list := $DF22 ; indexes of selected file (global, not w/in window, up to 127)
file_table := $DD9F ; file address table
;;; Copy of DEVLST before DeskTop modifies it. Used when exiting or
;;; invoking to restore devices.
devlst_backup := $E196
last_menu_click_params := $E25A
;;; Icon (file/volume) entries - length 27 bytes, maximum of 127

View File

@ -65,9 +65,10 @@ JT_CUR_WATCH: jmp set_watch_cursor
JT_RESTORE_OVL: jmp restore_dynamic_routine
JT_COLOR_MODE: jmp set_color_mode ; *
JT_MONO_MODE: jmp set_mono_mode ; *
JT_RESTORE_SYS: jmp restore_system ; *
.assert JUMP_TABLE_MAIN_LOOP = JT_MAIN_LOOP, error, "Jump table mismatch"
.assert JUMP_TABLE_MONO_MODE = JT_MONO_MODE, error, "Jump table mismatch"
.assert JUMP_TABLE_RESTORE_SYS = JT_RESTORE_SYS, error, "Jump table mismatch"
;; Main Loop
.proc enter_main_loop
@ -2158,11 +2159,8 @@ start:
MLI_RELAY_CALL READ, read_params
MLI_RELAY_CALL CLOSE, close_params
;; Restore devices, stack, graphics, and /RAM
jsr restore_device_list
sta ALTZPOFF
jsr exit_dhr_mode ; sets ROMIN2
jsr maybe_reformat_ram
;; Restore system state: devices, /RAM, ROM/ZP banks.
jsr restore_system
quit: jmp quit_code_addr
@ -2172,6 +2170,45 @@ fail: jsr ShowAlert
.endproc
cmd_quit := cmd_quit_impl::start
;;; ============================================================
;;; Exit DHR, restore device list, reformat /RAM.
;;; Returns with ALTZPOFF and ROM banked in.
.proc restore_system
jsr restore_device_list
;; Switch back to main ZP, preserving return address.
pla
tax
pla
sta ALTZPOFF
pha
txa
pha
;; Switch back to color DHR mode
jsr set_color_mode
;; Exit graphics mode entirely
lda ROMIN2
jsr SETVID
jsr SETKBD
jsr INIT
jsr HOME
sta TXTSET
sta LOWSCR
sta LORES
sta MIXCLR
sta DHIRESOFF
sta CLRALTCHAR
sta CLR80VID
sta CLR80COL
;; Restore /RAM if possible.
jmp maybe_reformat_ram
.endproc
;;; ============================================================
.proc cmd_view_by_icon
@ -3525,12 +3562,8 @@ check_drive_flags:
;; also invoked by launcher code
.proc reset_and_invoke
;; Restore devices, stack, graphics, and /RAM
jsr restore_device_list
sta ALTZPOFF
jsr exit_dhr_mode ; sets ROMIN2
jsr maybe_reformat_ram
;; Restore system state: devices, /RAM, ROM/ZP banks.
jsr restore_system
;; also used by launcher code
target := *+1
@ -3538,12 +3571,6 @@ check_drive_flags:
.endproc
reset_and_invoke_target := reset_and_invoke::target
;;; ============================================================
.proc restore_state_for_exit
.endproc
;;; ============================================================
active_window_view_by:
@ -9366,30 +9393,6 @@ open: MLI_RELAY_CALL OPEN, open_params
done: rts
.endproc
;;; ============================================================
;;; Invoked when exiting or launching another program.
.proc exit_dhr_mode
jsr set_color_mode
lda ROMIN2
jsr SETVID
jsr SETKBD
jsr INIT
jsr HOME
sta TXTSET
sta LOWSCR
sta LORES
sta MIXCLR
sta DHIRESOFF
sta CLRALTCHAR
sta CLR80VID
sta CLR80COL
rts
.endproc
.proc set_color_mode
;; AppleColor Card - Mode 2 (Color 140x192)
sta SET80VID

View File

@ -950,10 +950,9 @@ entries_read_this_block:
;;; ============================================================
;; Backup copy of DEVLST made before detaching ramdisk
devlst_backup_:
.assert * = devlst_backup, error, "Entry point mismatch"
.res 10, 0
;;; Backup copy of DEVLST made before detaching ramdisk
devlst_backup:
.res 14, 0
;; index is device number (in DEVLST), value is icon number
device_to_icon_map: