Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match counter #3

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ def build_35():

add_lib_263(gs_srcs, "build/3.5/gs", "./psy-q/3.5/PSX/LIB/LIBGS.LIB", "-DVERSION=35", "3.5")

api_srcs = [
'src/api/counter.c'
]

add_lib_263(api_srcs, "build/3.5/api", "./psy-q/3.5/PSX/LIB/LIBAPI.LIB", "-DVERSION=35", "3.5")


def build_36():
snd_srcs = [
# 'src/snd/next.c',
Expand Down
82 changes: 82 additions & 0 deletions src/api/counter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "../types.h"

typedef struct {
u16 rootCounter;
s16 unk2;
s16 mode;
s16 : 16;
s16 target;
s32 : 32;
} Counter;

// https://psx-spx.consoledev.net/timers/
static volatile s32 *_interrupt_status_register = 0x1F801070;

static volatile Counter* _counters = 0x1F801100;

static volatile s32 _interrupt_status_masks[4] = {
0x00000010,
0x00000020,
0x00000040,
0x00000001
};

s32 SetRCnt(s32 spec, s16 target, s32 flags) {
s32 i = spec & 0xFFFF;
s32 final_mode = 0x48;
if (i >= 3) {
return 0;
}
_counters[i].mode = 0;
_counters[i].target = target;

if (i < 2u) {
if (flags & 0x10) {
final_mode = 0x49;
}
if (!(flags & 1)) {
final_mode |= 0x100;
}
} else if (i == 2u) { // nb: `else` is redundant here
if (!(flags & 1)) {
final_mode = 0x248;
}
}
if ((flags & 0x1000) != 0) {
final_mode |= 0x10;
}

_counters[i].mode = final_mode;
return 1;
}

long GetRCnt(long spec) {
s32 i = spec & 0xFFFF;
if (i >= 3) {
return 0;
}
return _counters[i].rootCounter;
}

s32 StartRCnt(s32 spec) {
s32 i = spec & 0xFFFF;
long* mask = _interrupt_status_masks;
_interrupt_status_register[1] |= mask[i];
return i < 3;
}

long StopRCnt(long spec) {
s32 i = spec & 0xFFFF;
long* mask = _interrupt_status_masks;
_interrupt_status_register[1] &= ~mask[i];
return 1;
}

long ResetRCnt(long spec) {
s32 i = spec & 0xFFFF;
if (i >= 3) {
return 0;
}
_counters[i].rootCounter = 0;
return 1;
}
Loading