BACKENDS: ATARI: Call original keyboard/mouse routines

This helps to solve the issue when one pushes 'Return' immediately after
Hatari's start. This issue appeared after introducing the
interrupt-driven audio mixer.

Not sure whether this was a real bug but it's much cleaner
implementation now anyway.
This commit is contained in:
Miro Kropacek 2024-02-24 03:52:58 +01:00
parent f41a678ba1
commit 01a2d2edab
2 changed files with 31 additions and 67 deletions

View File

@ -23,7 +23,9 @@
.global SYM(atari_kbdvec)
.global SYM(atari_mousevec)
.global SYM(atari_vkbderr)
.global SYM(atari_old_kbdvec)
.global SYM(atari_old_mousevec)
.extern SYM(g_atari_ikbd_mouse_buttons_state)
.extern SYM(g_atari_ikbd_mouse_delta_x)
@ -33,39 +35,15 @@
.extern SYM(g_atari_ikbd_scancodes_mask)
.extern SYM(g_atari_ikbb_scancodes_head)
.extern SYM(g_atari_old_kbdvec)
.text
.ascii "XBRA"
.ascii "SCUM"
SYM(atari_old_kbdvec):
dc.l 0
SYM(atari_kbdvec):
tst.w (vkbderr_count,pc)
bne.b kbdvec_end
movem.l d1/a0,-(sp)
lea pressed_keys,a0
clr.l d1
move.b d0,d1
bpl.b key_pressed | bit 7 cleared
key_released:
and.b #0x7f,d1
tst.b (a0,d1.l) | pressed before?
bne.b key_released_ok
| if we get a sudden release key event,
| let the original handler process it
move.l SYM(g_atari_old_kbdvec),a0
tst.l a0
beq.b kbdvec_end
jmp (a0)
key_released_ok:
clr.b (a0,d1.l) | mark as released
bra.b kbdvec_process
key_pressed:
addq.b #1,(a0,d1.l) | mark as pressed
kbdvec_process:
lea SYM(g_atari_ikbd_scancodes),a0
move.w SYM(g_atari_ikbb_scancodes_head),d1
@ -77,17 +55,17 @@ kbdvec_process:
and.w SYM(g_atari_ikbd_scancodes_mask),d1
move.w d1,SYM(g_atari_ikbb_scancodes_head)
kbdvec_end:
rts
SYM(atari_vkbderr):
addq.w #1,vkbderr_count
movem.l (sp)+,d1/a0
move.l (atari_old_kbdvec,pc),-(sp)
rts
.ascii "XBRA"
.ascii "SCUM"
SYM(atari_old_mousevec):
dc.l 0
SYM(atari_mousevec):
clr.w vkbderr_count
movem.l d0/a0,-(sp)
move.b (a0)+,SYM(g_atari_ikbd_mouse_buttons_state)
@ -98,14 +76,7 @@ SYM(atari_mousevec):
move.b (a0)+,d0
ext.w d0
add.w d0,SYM(g_atari_ikbd_mouse_delta_y)
movem.l (sp)+,d0/a0
move.l (atari_old_mousevec,pc),-(sp)
rts
// place it within reach of 32K (PC relative)
vkbderr_count:
dc.w 0
.bss
pressed_keys:
ds.b 128

View File

@ -66,7 +66,9 @@
extern "C" void atari_kbdvec(void *);
extern "C" void atari_mousevec(void *);
extern "C" void atari_vkbderr(void);
typedef void (*KBDVEC)(void *);
extern "C" KBDVEC atari_old_kbdvec;
extern "C" KBDVEC atari_old_mousevec;
extern "C" void atari_200hz_init();
extern "C" void atari_200hz_shutdown();
@ -78,11 +80,6 @@ extern void nf_print(const char* msg);
static bool s_tt = false;
static int s_app_id = -1;
typedef void (*KBDVEC)(void *);
KBDVEC g_atari_old_kbdvec = nullptr;
static void (*s_vkbderr)(void) = nullptr;
static KBDVEC s_mousevec = nullptr;
static bool exit_already_called = false;
static void critical_restore() {
@ -98,12 +95,11 @@ static void critical_restore() {
Supexec(asm_screen_falcon_restore);
Supexec(atari_200hz_shutdown);
if (g_atari_old_kbdvec && s_vkbderr && s_mousevec) {
if (atari_old_kbdvec && atari_old_mousevec) {
_KBDVECS *kbdvecs = Kbdvbase();
((uintptr *)kbdvecs)[-1] = (uintptr)g_atari_old_kbdvec;
kbdvecs->vkbderr = s_vkbderr;
kbdvecs->mousevec = s_mousevec;
g_atari_old_kbdvec = s_mousevec = nullptr;
((uintptr *)kbdvecs)[-1] = (uintptr)atari_old_kbdvec;
kbdvecs->mousevec = atari_old_mousevec;
atari_old_kbdvec = atari_old_mousevec = nullptr;
}
// don't call GEM cleanup in the critical handler: it seems that v_clsvwk()
@ -166,12 +162,10 @@ OSystem_Atari::OSystem_Atari() {
}
_KBDVECS *kbdvecs = Kbdvbase();
g_atari_old_kbdvec = (KBDVEC)(((uintptr *)kbdvecs)[-1]);
s_vkbderr = kbdvecs->vkbderr;
s_mousevec = kbdvecs->mousevec;
atari_old_kbdvec = (KBDVEC)(((uintptr *)kbdvecs)[-1]);
atari_old_mousevec = kbdvecs->mousevec;
((uintptr *)kbdvecs)[-1] = (uintptr)atari_kbdvec;
kbdvecs->vkbderr = atari_vkbderr;
kbdvecs->mousevec = atari_mousevec;
Supexec(atari_200hz_init);
@ -231,12 +225,11 @@ OSystem_Atari::~OSystem_Atari() {
_timerInitialized = false;
}
if (g_atari_old_kbdvec && s_vkbderr && s_mousevec) {
if (atari_old_kbdvec && atari_old_mousevec) {
_KBDVECS *kbdvecs = Kbdvbase();
((uintptr *)kbdvecs)[-1] = (uintptr)g_atari_old_kbdvec;
kbdvecs->vkbderr = s_vkbderr;
kbdvecs->mousevec = s_mousevec;
g_atari_old_kbdvec = s_mousevec = nullptr;
((uintptr *)kbdvecs)[-1] = (uintptr)atari_old_kbdvec;
kbdvecs->mousevec = atari_old_mousevec;
atari_old_kbdvec = atari_old_mousevec = nullptr;
}
if (s_app_id != -1) {