-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Here is an error I have torn my hair out over, but I found the problem and a fix.
Symptom/reproduction steps:
- I start the PET core as usual.
- I can type at this point.
- I hit the HELP key to go to the menu.
- I leave the menu
- Keyboard does not work any more. Not even the HELP key to get into the menu.
By going backs some commits I found a working state, so going forward, I noticed the issue started when making a somewhat large menu / options change.
Through the ILA, by tracing the QNICE PC, I found that it was stuck in a loop, involving address 2be8.
It seems to be stuck here:
010004 ; If any write cache of any virtual drive is dirty then
010005 ; we need to assume that the 512-byte hardware buffer is
010006 ; currently in use by HANDLE_DEV. See also the comment about
010007 ; us not following the QNICE best practice here and the
010008 ; @TODO that we might want to refactor this in future.
010009 2BDE FFB0 1B71 RSUB VD_ACTIVE, 1 ; any vdrives at all?
010010 2BE0 FFAA 0017 RBRA _ROSMS_1, !C ; no, so no danger of corruptn
010011 2BE2 0800 MOVE R8, R0 ; R0: amount of vdrives
010012 2BE3 B820 XOR R8, R8 ; vdrive id
010013 2BE4 0FA4 700C _ROSMS_0 MOVE VD_CACHE_DIRTY, R9
010014 2BE6 FFB0 1C48 RSUB VD_DRV_READ, 1 ; get dirty flag for curr. drv
010015 2BE8 CFA0 0000 CMP 0, R8 ; dirty?
010016 2BEA FFAB 0007 RBRA _ROSMS_NOWR, !Z ; yes: do not save
010017 2BEC 1FA0 0001 ADD 1, R8 ; no: check next vdrive
010018 2BEE C020 CMP R0, R8 ; done?
010019 2BEF FFAB FFF3 RBRA _ROSMS_0, !Z
; no: next iteration
010020 2BF1 FFA0 0006 RBRA _ROSMS_1, 1 ; yes: detect changes & save
010021
010022 2BF3 0FA0 3A51 _ROSMS_NOWR MOVE LOG_STR_CFG_NO, R8
010023 2BF5 FF90 0008 ASUB puts, 1
010024 2BF7 FFA0 006E RBRA _ROSMS_RET, 1
This loop expects R8 to be preserved over the subroutine call to VD_DRV_READ, but it returns its result in it so it doesn't.
I will try to use R1 to keep the current vdrive number instead of R8. I need to copy it to R8 every time through the loop, though.
diff --git a/M2M/rom/options.asm b/M2M/rom/options.asm
index 755a7f8..7a161b7 100644
--- a/M2M/rom/options.asm
+++ b/M2M/rom/options.asm
@@ -686,13 +686,14 @@ ROSM_SAVE SYSCALL(enter, 1)
RSUB VD_ACTIVE, 1 ; any vdrives at all?
RBRA _ROSMS_1, !C ; no, so no danger of corruptn
MOVE R8, R0 ; R0: amount of vdrives
- XOR R8, R8 ; vdrive id
-_ROSMS_0 MOVE VD_CACHE_DIRTY, R9
+ XOR R1, R1 ; R1: current vdrive id
+_ROSMS_0 MOVE R1, R8
+ MOVE VD_CACHE_DIRTY, R9
RSUB VD_DRV_READ, 1 ; get dirty flag for curr. drv
CMP 0, R8 ; dirty?
RBRA _ROSMS_NOWR, !Z ; yes: do not save
- ADD 1, R8 ; no: check next vdrive
- CMP R0, R8 ; done?
+ ADD 1, R1 ; no: check next vdrive
+ CMP R0, R1 ; done?
RBRA _ROSMS_0, !Z ; no: next iteration
RBRA _ROSMS_1, 1 ; yes: detect changes & saveI tried this and it fixed the issue.
This code only runs if there is a config file to save. My theory as to why this is a problem suddently is that I didn't have a config file for a while. But I did regenerate a default config for the new menu items/options and put it on the sdcard. It's invalid with the old menus so this code doesn't run, but with the new ones it does. If I never updated that petcfg file I would not have noticed this...
(See also discord thread https://discord.com/channels/719326990221574164/1282765235639549993/1346210058752491601 )