fox32rom: Don't use the stack pointer for the event stack

Previously this used a very hacky way to push and pop events on the
event stack. This especially caused issues since it disabled and
enabled interrupts, and these routines are called in an interrupt
handler, which breaks things in some cases :p
This commit is contained in:
ry755 2022-01-30 00:53:25 -08:00 committed by Ry
parent 7c3794ed45
commit b8195a079d

View File

@ -37,21 +37,38 @@ wait_for_event:
; outputs: ; outputs:
; none ; none
push_event: push_event:
icl
push r6 push r6
mov r6, rsp
mov rsp, [event_stack_pointer]
push r0
push r1
push r2
push r3
push r4
push r5
mov [event_stack_pointer], rsp
mov rsp, r6
pop r6
ise
mov r6, [event_stack_pointer]
; TODO: check to make sure we don't accidentally clobber the system stack by pushing too many events
; push r0
sub r6, 4
mov [r6], r0
; push r1
sub r6, 4
mov [r6], r1
; push r2
sub r6, 4
mov [r6], r2
; push r3
sub r6, 4
mov [r6], r3
; push r4
sub r6, 4
mov [r6], r4
; push r5
sub r6, 4
mov [r6], r5
mov [event_stack_pointer], r6
pop r6
ret ret
; pop an event from the event stack ; pop an event from the event stack
@ -66,21 +83,37 @@ pop_event:
cmp [event_stack_pointer], event_stack_pointer cmp [event_stack_pointer], event_stack_pointer
ifz jmp pop_event_empty ifz jmp pop_event_empty
icl
push r6 push r6
mov r6, rsp
mov rsp, [event_stack_pointer]
pop r5
pop r4
pop r3
pop r2
pop r1
pop r0
mov [event_stack_pointer], rsp
mov rsp, r6
pop r6
ise
mov r6, [event_stack_pointer]
; pop r5
mov r5, [r6]
add r6, 4
; pop r4
mov r4, [r6]
add r6, 4
; pop r3
mov r3, [r6]
add r6, 4
; pop r2
mov r2, [r6]
add r6, 4
; pop r1
mov r1, [r6]
add r6, 4
; pop r0
mov r0, [r6]
add r6, 4
mov [event_stack_pointer], r6
pop r6
ret ret
pop_event_empty: pop_event_empty:
mov r0, empty_event_type mov r0, empty_event_type