From 6f758cd36c2b665a831592fa46f15aae49a88731 Mon Sep 17 00:00:00 2001 From: Lephe Date: Sun, 29 Jan 2023 21:40:50 +0100 Subject: [PATCH] defs: allow NULL callbacks in gint_call() --- include/gint/defs/call.h | 3 ++- src/dma/dma.c | 7 ++----- src/kernel/world.c | 2 +- src/render-cg/dupdate.c | 3 +-- src/render-fx/dupdate.c | 3 +-- src/usb/pipes.c | 14 +++++++------- src/usb/usb.c | 8 ++------ 7 files changed, 16 insertions(+), 24 deletions(-) diff --git a/include/gint/defs/call.h b/include/gint/defs/call.h index 1c3c67c..8870884 100644 --- a/include/gint/defs/call.h +++ b/include/gint/defs/call.h @@ -153,7 +153,8 @@ static GINLINE int gint_call(gint_call_t cb) int (*f)(int r4, int r5, int r6, int r7) = cb.function; #endif - return f(cb.args[0].i, cb.args[1].i, cb.args[2].i, cb.args[3].i); + gint_call_arg_t *args = cb.args; + return f ? f(args[0].i, args[1].i, args[2].i, args[3].i) : -1; } //--- diff --git a/src/dma/dma.c b/src/dma/dma.c index 0925217..ff78eb2 100644 --- a/src/dma/dma.c +++ b/src/dma/dma.c @@ -160,11 +160,8 @@ static void dma_interrupt_transfer_ended(int channel) if(dma_wait_ics[channel]) cpu_csleep_cancel(dma_wait_ics[channel]); - if(dma_callbacks[channel].function) - { - gint_call(dma_callbacks[channel]); - dma_callbacks[channel] = GINT_CALL_NULL; - } + gint_call(dma_callbacks[channel]); + dma_callbacks[channel] = GINT_CALL_NULL; } /* dma_channel_wait(): Wait for a particular channel's transfer to finish diff --git a/src/kernel/world.c b/src/kernel/world.c index 87ba362..7334dd7 100644 --- a/src/kernel/world.c +++ b/src/kernel/world.c @@ -149,7 +149,7 @@ int gint_world_switch(gint_call_t call) if(canary) *canary = 0xb7c0ffee; - int rc = call.function ? gint_call(call) : 0; + int rc = gint_call(call); /* The canary check needs to occur before switching in the gint world; otherwise we just crash due to the overflow. gint_panic() isn't diff --git a/src/render-cg/dupdate.c b/src/render-cg/dupdate.c index 415895d..8dfd18c 100644 --- a/src/render-cg/dupdate.c +++ b/src/render-cg/dupdate.c @@ -12,8 +12,7 @@ void dupdate(void) r61524_display(gint_vram, 0, 224, method); - gint_call_t hook = dupdate_get_hook(); - if(hook.function) gint_call(hook); + gint_call(dupdate_get_hook()); /* Switch buffers if triple buffering is enabled */ dvram_switch(); diff --git a/src/render-fx/dupdate.c b/src/render-fx/dupdate.c index 3dcb4a8..d519fb5 100644 --- a/src/render-fx/dupdate.c +++ b/src/render-fx/dupdate.c @@ -28,8 +28,7 @@ void dupdate(void) t6k11_display(gint_vram, 0, 64, 16); } - gint_call_t hook = dupdate_get_hook(); - if(hook.function) gint_call(hook); + gint_call(dupdate_get_hook()); } __attribute__((alias("dupdate"))) void _WEAK_dupdate(void); diff --git a/src/usb/pipes.c b/src/usb/pipes.c index 1836ad1..3161e2e 100644 --- a/src/usb/pipes.c +++ b/src/usb/pipes.c @@ -263,10 +263,10 @@ static void finish_transfer(struct transfer volatile *t, int pipe) t->used = 0; /* Disable the interrupt */ - if(pipe) USB.BEMPENB &= ~(1 << pipe); - - if(t->callback.function) gint_call(t->callback); + if(pipe != 0) + USB.BEMPENB &= ~(1 << pipe); + gint_call(t->callback); USB_TRACE("finish_transfer()"); } @@ -287,14 +287,14 @@ static void finish_round(struct transfer volatile *t, int pipe) t->flying = 0; /* Account for auto-transfers */ - if(t->used == pipe_bufsize(pipe)) t->used = 0; + if(t->used == pipe_bufsize(pipe)) + t->used = 0; /* At the end, free the FIFO and invoke the callback. Hold the controller until the pipe is committed */ - if(t->size == 0) - { + if(t->size == 0) { t->data = NULL; - if(t->callback.function) gint_call(t->callback); + gint_call(t->callback); } USB_TRACE("finish_round()"); diff --git a/src/usb/usb.c b/src/usb/usb.c index 29235a5..458033e 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -266,13 +266,9 @@ static void usb_interrupt_handler(void) if(USB.INTSTS0.DVSQ == 3) { usb_configure_clear_pipes(); - usb_open_status = true; - if(usb_open_callback.function) - { - gint_call(usb_open_callback); - usb_open_callback = GINT_CALL_NULL; - } + gint_call(usb_open_callback); + usb_open_callback = GINT_CALL_NULL; } } else if(USB.INTSTS0.BEMP)