From 231d03b548ab6a02c5c94ff82445bf0210a770df Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Thu, 27 Dec 2018 12:55:56 -0800 Subject: [PATCH] RBH DA: Restore devices and reformat /RAM. Fixes #98 --- desk.acc/run.basic.here.s | 49 +++++++++++++++++++++++++++++++++++++-- desktop.inc | 4 ++++ desktop/desktop_res.s | 3 ++- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/desk.acc/run.basic.here.s b/desk.acc/run.basic.here.s index 035720c..568c509 100644 --- a/desk.acc/run.basic.here.s +++ b/desk.acc/run.basic.here.s @@ -50,8 +50,11 @@ start: lda #$FE ; "BASIC.SYSTEM not found" bne fail + ;; Restore devices DeskTop may have removed +: jsr restore_device_list + ;; Restore to normal state -: sta ALTZPOFF + sta ALTZPOFF lda ROMIN2 jsr SETVID jsr SETKBD @@ -66,7 +69,8 @@ start: sta CLR80VID sta CLR80COL - ;; TODO: restore /RAM? + ;; Reformat /RAM if it was restored + jsr maybe_reformat_ram ;; Set PREFIX MLI_CALL SET_PREFIX, set_prefix_params @@ -221,3 +225,44 @@ fail: return #1 .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 diff --git a/desktop.inc b/desktop.inc index 023b2e6..cdb9325 100644 --- a/desktop.inc +++ b/desktop.inc @@ -171,6 +171,10 @@ 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 diff --git a/desktop/desktop_res.s b/desktop/desktop_res.s index ff0c7be..5de38da 100644 --- a/desktop/desktop_res.s +++ b/desktop/desktop_res.s @@ -989,7 +989,8 @@ entries_read_this_block: ;;; ============================================================ ;; Backup copy of DEVLST made before detaching ramdisk -devlst_backup: +devlst_backup_: + .assert * = devlst_backup, error, "Entry point mismatch" .res 10, 0 ;; index is device number (in DEVLST), value is icon number