From 46e413f3f17820db762674140e607b7cb920e0ba Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Thu, 11 Jul 2019 15:50:20 -0700 Subject: [PATCH] Prevent crashes in Calculator/Eyes DA using ROM FP routines During calls, MGTK uses the top half of the zero page to hold the active grafport and local variables. It normally saves/restores the ZP on each call so that the application's ZP state is preserved. Per docs, the ZP1 call with param $00 can be used to disable this; MGTK will write its state to the ZP and assume the ZP is not touched until a subsequent ZP1 call with param $80, allowing higher performance. DeskTop would normally run in this state ($00), except when DAs were invoked since they could use ROM routines (etc) and expect the top half of the ZP to be preserved during MGTK calls. But it did this with a toggle ($00, $80, run the DA, then $00 again). Confusingly, the Calc (and Eyes, c/o copy/pasta) DA would also attempt to get to a normal state when running ($80, run, $00). In rev 30532c31 I disabled DeskTop's toggling around DAs to fix an issue in the Sort Directory DA (see #119), which might have changed the overall behavior. The result is that on the IIc+ (and possibly other hardware, but not Virtual II or Laser 128EX) the Calc and Eyes DAs would crash. This change disables use of the ZP1 by DeskTop and the DAs. This will likely impair performance somewhat due to the save/restore overhead on each call, but at least this gets us to a "known good state". Fixes #157, #158 --- desk.acc/calculator.s | 7 +++---- desk.acc/eyes.s | 3 --- desktop/desktop_main.s | 4 ---- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/desk.acc/calculator.s b/desk.acc/calculator.s index 7912c81..5504b4d 100644 --- a/desk.acc/calculator.s +++ b/desk.acc/calculator.s @@ -666,7 +666,6 @@ window_title: init: sta ALTZPON lda LCBANK1 lda LCBANK1 - MGTK_CALL MGTK::SetZP1, preserve_zp_params MGTK_CALL MGTK::OpenWindow, winfo MGTK_CALL MGTK::InitPort, grafport MGTK_CALL MGTK::SetPort, grafport @@ -696,8 +695,9 @@ loop: lda adjust_txtptr_copied-1,x bne loop .endproc - lda #0 ; Turn off errors - sta ERRFLG + lda #0 + sta ERRFLG ; Turn off errors + sta SHIFT_SIGN_EXT ; Zero before using FP ops copy16 #error_hook, COUT_HOOK ; set up FP error handler @@ -772,7 +772,6 @@ ignore_click: exit: MGTK_CALL MGTK::CloseWindow, closewindow_params DESKTOP_CALL DT_REDRAW_ICONS lda ROMIN2 - MGTK_CALL MGTK::SetZP1, overwrite_zp_params .proc do_close ;; Copy following routine to ZP and invoke it diff --git a/desk.acc/eyes.s b/desk.acc/eyes.s index 471cabb..967d231 100644 --- a/desk.acc/eyes.s +++ b/desk.acc/eyes.s @@ -187,8 +187,6 @@ grow_box_bitmap: lda LCBANK1 lda LCBANK1 - ;; Don't let MGTK smash zero page - MGTK_CALL MGTK::SetZP1, preserve_zp_params lda #0 sta SHIFT_SIGN_EXT ; Must zero before using FP ops @@ -214,7 +212,6 @@ grow_box_bitmap: .proc exit MGTK_CALL MGTK::CloseWindow, winfo DESKTOP_CALL DT_REDRAW_ICONS - MGTK_CALL MGTK::SetZP1, overwrite_zp_params rts .endproc diff --git a/desktop/desktop_main.s b/desktop/desktop_main.s index a345f50..5100cfb 100644 --- a/desktop/desktop_main.s +++ b/desktop/desktop_main.s @@ -1559,10 +1559,7 @@ nope: dex ;; Invoke it jsr set_pointer_cursor jsr reset_grafport3 - ;; MGTK_RELAY_CALL MGTK::SetZP1, zp_use_flag0 - ;; MGTK_RELAY_CALL MGTK::SetZP1, zp_use_flag1 jsr DA_LOAD_ADDRESS - ;; MGTK_RELAY_CALL MGTK::SetZP1, zp_use_flag0 lda #0 sta running_da_flag @@ -15542,7 +15539,6 @@ end: MGTK_RELAY_CALL MGTK::StartDeskTop, startdesktop_params jsr desktop_main::set_mono_mode MGTK_RELAY_CALL MGTK::SetMenu, splash_menu - MGTK_RELAY_CALL MGTK::SetZP1, zp_use_flag0 MGTK_RELAY_CALL MGTK::SetCursor, watch_cursor MGTK_RELAY_CALL MGTK::ShowCursor ;; fall through