Skip to content

Commit

Permalink
etc intr_dma.c
Browse files Browse the repository at this point in the history
  • Loading branch information
sozud committed Mar 14, 2024
1 parent 9fadd77 commit 6719d3f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
5 changes: 3 additions & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,10 @@ def build_35():
add_lib_263(spu_srcs, "build/3.5/spu", "./psy-q/3.5/PSX/LIB/LIBSPU.LIB", "-DVERSION=35", "3.5")

etc_srcs = [
'src/etc/vmode.c',
'src/etc/pad.c',
'src/etc/intr_dma.c',
'src/etc/intr_vb.c'
'src/etc/pad.c',
'src/etc/vmode.c',
]

add_lib_263(etc_srcs, "build/3.5/etc", "./psy-q/3.5/PSX/LIB/LIBETC.LIB", "-DVERSION=35", "3.5")
Expand Down
77 changes: 77 additions & 0 deletions src/etc/intr_dma.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "../types.h"

typedef void (*Callback)();

Callback setIntrDMA(int index, Callback callback);
void trapIntrDMA(void);
void memclr(int* ptr, int size);

extern void InterruptCallback(int, void*);
static volatile u_long* D_8002D37C = 0x1F8010F4; /* 0x1F8010F4 - DMA Interrupt Register */
static Callback D_8002D380[8] = {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
static unsigned long* D_8002D3A0 = 0x1f801080;

void* startIntrDMA(void) {
memclr(&D_8002D380, 8);
*D_8002D37C = 0;
InterruptCallback(3, &trapIntrDMA);
return &setIntrDMA;
}

static void trapIntrDMA(void) {
u32 mask;
int i;

while ((mask = (*D_8002D37C >> 24) & 0x7f) != 0) {
for (i = 0; mask != 0 && i < 7; i++, mask >>= 1) {
if (mask & 1) {
*D_8002D37C &= (0xffffff | (1 << (i + 24)));
if (D_8002D380[i] != NULL) {
D_8002D380[i]();
}
}
}
}

if ((*D_8002D37C & 0xFF000000) == 0x80000000 || *D_8002D37C & 0x8000) {
printf("DMA bus error: code=%08x\n", *D_8002D37C);
for (i = 0; i < 7; i++) {
printf("MADR[%d]=%08x\n", i, D_8002D3A0[4 * i]);
}
}
}

static Callback setIntrDMA(int index, Callback callback) {
Callback prev = D_8002D380[index];
if (callback != prev) {
if (callback != NULL) {
D_8002D380[index] = callback;
*D_8002D37C =
(*D_8002D37C & 0xFFFFFF) | 0x800000 | ((1 << (index + 16)));
} else {
D_8002D380[index] = 0;
*D_8002D37C =
((*D_8002D37C & 0xFFFFFF) | 0x800000) & ~(1 << (index + 16));
}
}
return prev;
}

static void memclr(int* ptr, int size) {
int i;
int* e = ptr;

for (i = size - 1; i != -1; i--) {
*e = 0;
e++;
}
}

0 comments on commit 6719d3f

Please sign in to comment.