aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/psxgpu
diff options
context:
space:
mode:
authorspicyjpeg <thatspicyjpeg@gmail.com>2022-10-21 13:24:54 +0200
committerspicyjpeg <thatspicyjpeg@gmail.com>2022-10-21 13:24:54 +0200
commitb1632d7df0e840692612461a80d0e05d6a3228ed (patch)
tree2f804b26c5befa1ed360db034910c8107b8c3ee6 /libpsn00b/psxgpu
parent982df5fe197c4db2be4bffe59a05c837b7508365 (diff)
downloadpsn00bsdk-b1632d7df0e840692612461a80d0e05d6a3228ed.tar.gz
Rewrite psxsio with new API, fix compiler warnings
Diffstat (limited to 'libpsn00b/psxgpu')
-rw-r--r--libpsn00b/psxgpu/common.c68
1 files changed, 37 insertions, 31 deletions
diff --git a/libpsn00b/psxgpu/common.c b/libpsn00b/psxgpu/common.c
index 9eb4ea4..9f45f10 100644
--- a/libpsn00b/psxgpu/common.c
+++ b/libpsn00b/psxgpu/common.c
@@ -38,6 +38,9 @@ static volatile uint16_t _last_hblank;
/* Private interrupt handlers */
+#define _ENTER_CRITICAL() uint16_t mask = IRQ_MASK; IRQ_MASK = 0;
+#define _EXIT_CRITICAL() IRQ_MASK = mask;
+
static void _vblank_handler(void) {
_vblank_counter++;
@@ -51,9 +54,10 @@ static void _gpu_dma_handler(void) {
__asm__ volatile("");
if (--_queue_length) {
- volatile QueueEntry *entry = &_draw_queue[_queue_head++];
- _queue_head %= QUEUE_LENGTH;
+ int head = _queue_head;
+ _queue_head = (head + 1) % QUEUE_LENGTH;
+ volatile QueueEntry *entry = &_draw_queue[head];
entry->func(entry->arg1, entry->arg2, entry->arg3);
} else {
GPU_GP1 = 0x04000000; // Disable DMA request
@@ -145,19 +149,22 @@ int VSync(int mode) {
}
void *VSyncHaltFunction(void (*func)(void)) {
+ //_ENTER_CRITICAL();
+
void *old_callback = _vsync_halt_func;
_vsync_halt_func = func;
+ //_EXIT_CRITICAL();
return old_callback;
}
void *VSyncCallback(void (*func)(void)) {
- EnterCriticalSection();
+ _ENTER_CRITICAL();
void *old_callback = _vsync_callback;
_vsync_callback = func;
- ExitCriticalSection();
+ _EXIT_CRITICAL();
return old_callback;
}
@@ -176,37 +183,36 @@ int EnqueueDrawOp(
// to checking if DMA is busy; disabling them afterwards would create a
// race condition where the DMA transfer could end while interrupts are
// being disabled. Interrupts are disabled through the IRQ_MASK register
- // rather than by calling EnterCriticalSection() for performance reasons.
- uint16_t mask = IRQ_MASK;
- IRQ_MASK = 0;
+ // rather than via syscalls for performance reasons.
+ _ENTER_CRITICAL();
+ int length = _queue_length;
- if (_queue_length) {
- int length = _queue_length;
-
- if (length >= QUEUE_LENGTH) {
- IRQ_MASK = mask;
- _sdk_log("draw queue overflow, dropping commands\n");
- return -1;
- }
+ if (!length) {
+ _queue_length = 1;
+ _EXIT_CRITICAL();
- volatile QueueEntry *entry = &_draw_queue[_queue_tail++];
- _queue_tail %= QUEUE_LENGTH;
- _queue_length = length + 1;
-
- entry->func = func;
- entry->arg1 = arg1;
- entry->arg2 = arg2;
- entry->arg3 = arg3;
+ func(arg1, arg2, arg3);
+ return 0;
+ }
+ if (length >= QUEUE_LENGTH) {
+ _EXIT_CRITICAL();
- IRQ_MASK = mask;
- return length;
+ _sdk_log("draw queue overflow, dropping commands\n");
+ return -1;
}
- _queue_length = 1;
+ int tail = _queue_tail;
+ _queue_tail = (tail + 1) % QUEUE_LENGTH;
+ _queue_length = length + 1;
+
+ volatile QueueEntry *entry = &_draw_queue[tail];
+ entry->func = func;
+ entry->arg1 = arg1;
+ entry->arg2 = arg2;
+ entry->arg3 = arg3;
- IRQ_MASK = mask;
- func(arg1, arg2, arg3);
- return 0;
+ _EXIT_CRITICAL();
+ return length;
}
int DrawSync(int mode) {
@@ -236,12 +242,12 @@ int DrawSync(int mode) {
}
void *DrawSyncCallback(void (*func)(void)) {
- EnterCriticalSection();
+ _ENTER_CRITICAL();
void *old_callback = _drawsync_callback;
_drawsync_callback = func;
- ExitCriticalSection();
+ _EXIT_CRITICAL();
return old_callback;
}