Skip to content

Commit

Permalink
Merge pull request #58 from LuigiBlood/libleo
Browse files Browse the repository at this point in the history
leoTimer match
  • Loading branch information
RevoSucks authored Aug 1, 2023
2 parents d1f69bd + 9d19238 commit 6776202
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/libleo/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ extern void leoSetUA_MEDIUM_CHANGED(void);
extern int leoC2_Correction(void);
extern s32 leoVerifyRTC(u8 yearhi, u8 yearlo);
extern u8 __locReadTimer(__LOCTime* time);
extern u8 __locSetTimer(__LOCTime* time);
extern s32 __leoSetReset(void);
extern s32 __osLeoInterrupt(void);
extern u16 leoLba_to_vzone(u32 lba);
Expand Down
2 changes: 2 additions & 0 deletions splat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ segments:
- [0x7BFA0, bin, rom_rodata_7BFA0]
- [0x7BFC0, .rodata, gb_tower]
- [0x7C000, bin, rom_rodata_7C000]
- [0x7EDF0, .rodata, libleo/leotimer]
- [0x7EE10, bin, rom_rodata_7EE10]
- [0x7EE90, .rodata, libultra/gu/sinf]
- [0x7EEE0, bin, rom_rodata_7EEE0]
- [0x7EF30, .rodata, libultra/al/reverb]
Expand Down
101 changes: 98 additions & 3 deletions src/libleo/leotimer.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include <ultra64.h>
#include "libleo/internal.h"

static const u8 ymdupper[6] = {99,12,31,23,59,59};
static const u8 dayupper[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

void leoReadTimer(void) {
UNUSED u8* filler;
UNUSED u8 padding[4];
UNUSED u8* rdparam;
UNUSED u8 data[4];
__LOCTime time;
u8 sense_code = __locReadTimer(&time);
LEOcur_command->data.time.yearlo = time.year;
Expand All @@ -25,7 +28,99 @@ void leoReadTimer(void) {
LEOcur_command->header.status = 0;
}

#pragma GLOBAL_ASM("asm/nonmatchings/libleo/leotimer/leoSetTimer.s")
void leoSetTimer(void) {
UNUSED LEOCmdReadTimer rd_timer;
u8* p_tmp = &LEOcur_command->data.time.yearlo;
u32 year;
u32 month;
u32 temp;
u32 ymd;
u8 result;
__LOCTime time;

//Verify values (if they're correct BCD or within limits)

for (ymd = 0; ymd < 6; ymd++) {
temp = *p_tmp;

//Verify right nybble (only right nybble for some reason)
if ((temp & 0xF) > 9) {
//nybble is above 0x9 therefore the BCD value is invalid
LEOcur_command->header.sense = LEO_SENSE_ILLEGAL_TIMER_VALUE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}

//Convert BCD value to binary value
temp = temp - ((temp >> 4) * 6);

switch (ymd) {
case 2:
//Day value check
if ((dayupper[month] < temp) && ((temp != 0x1D) || (year & 3))) {
LEOcur_command->header.sense = LEO_SENSE_ILLEGAL_TIMER_VALUE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
case 1:
//Month value cannot be 0
if (temp == 0) {
LEOcur_command->header.sense = LEO_SENSE_ILLEGAL_TIMER_VALUE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
default:
//Verify max value of each time info
if (ymdupper[ymd] < temp) {
LEOcur_command->header.sense = LEO_SENSE_ILLEGAL_TIMER_VALUE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
}

year = month;
month = temp;
p_tmp++;
}

//Every value has been ymd good, now set the values in hardware

//Prepare the time info to use
time.year = LEOcur_command->data.time.yearlo;
time.month = LEOcur_command->data.time.month;
time.day = LEOcur_command->data.time.day;
time.hour = LEOcur_command->data.time.hour;
time.minute = LEOcur_command->data.time.minute;
time.second = LEOcur_command->data.time.second;

//Set the new time
result = __locSetTimer(&time);
if (result != 0) {
LEOcur_command->header.sense = result;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
//Get the time
result = __locReadTimer(&time);
if (result != 0) {
LEOcur_command->header.sense = result;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
//Check if the time is set correctly
if ((time.year != LEOcur_command->data.time.yearlo)
|| (time.month != LEOcur_command->data.time.month)
|| (time.day != LEOcur_command->data.time.day)
|| (time.hour != LEOcur_command->data.time.hour)
|| (time.minute != LEOcur_command->data.time.minute)
|| (time.second != LEOcur_command->data.time.second)) {
LEOcur_command->header.sense = LEO_SENSE_ILLEGAL_TIMER_VALUE;
LEOcur_command->header.status = LEO_STATUS_CHECK_CONDITION;
return;
}
LEOcur_command->header.status = LEO_STATUS_GOOD;
}


u8 __locReadTimer(__LOCTime* time) {
u32 data;
Expand Down
2 changes: 2 additions & 0 deletions tools/symbol_addrs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ read_id_cmd = 0x80079590;
leo_disk_id_lba = 0x8007DAF0;
leo_sys_read_cmd = 0x80079560;
leo_sys_form_lbas = 0x8007DA40;
ymdupper = 0x8007E1F0;
dayupper = 0x8007E1F8;
LEO_sys_data = 0x800FF9F0;
LEOdrive_flag = 0x801006D4;
LEOtgt_param = 0x801006E0;
Expand Down

0 comments on commit 6776202

Please sign in to comment.