summaryrefslogtreecommitdiff
path: root/src/libultra_code/osContInit.c
diff options
context:
space:
mode:
authorLucas Shaw <49287729+shawlucas@users.noreply.github.com>2020-06-17 04:16:30 -0700
committerGitHub <noreply@github.com>2020-06-17 07:16:30 -0400
commitb86edcf92c1c6882f0bb9dd051eb6a1b0582de8b (patch)
tree1a2405029a7b41cc6420060094dc158b03d2b5a2 /src/libultra_code/osContInit.c
parent229e0c8629b5a3c984a8a2c5ed5aba2aa59d32d7 (diff)
Matched some controller files (#178)
* osPfsIsPlug.c and osContSetCh.c OK * update * __osPfsGetStatus.c OK * removed unused asm * Updated all libultra controller files to use new structs instead of the temporary structs. Added os_pfs.h * controller updates * fixed header guard * Made suggested changes
Diffstat (limited to 'src/libultra_code/osContInit.c')
-rw-r--r--src/libultra_code/osContInit.c104
1 files changed, 52 insertions, 52 deletions
diff --git a/src/libultra_code/osContInit.c b/src/libultra_code/osContInit.c
index 33cc136b8..8a0bd6b10 100644
--- a/src/libultra_code/osContInit.c
+++ b/src/libultra_code/osContInit.c
@@ -1,90 +1,90 @@
#include <ultra64.h>
#include <global.h>
-
#include <ultra64/controller.h>
-pif_data_buffer_t _osPifInternalBuff;
-u8 _osCont_lastPollType;
-u8 _osCont_numControllers; // always 4
+OSPifRam __osPifInternalBuff;
+u8 __osContLastPoll;
+u8 __osMaxControllers; // always 4
-// Not sure if the following is a struct together with the last two variables
-u16 unk_80175812;
-u32 unk_80175814;
-u8 unk_80175818[0x20];
+OSTimer __osEepromTimer;
+OSMesgQueue __osEepromTimerMsgQ;
+OSMesg __osEepromTimerMsg;
-u32 gOsContInitialized = 0;
-OSMesgQueue _osContMesgQueue;
-OSMesg _osContMesgBuff[4];
+u32 gOSContInitialized = 0;
#define HALF_SECOND OS_USEC_TO_CYCLES(500000)
-s32 osContInit(OSMesgQueue* mq, u8* ctl_present_bitfield, OSContStatus* status) {
+s32 osContInit(OSMesgQueue* mq, u8* ctlBitfield, OSContStatus* status) {
OSMesg mesg;
s32 ret = 0;
OSTime currentTime;
OSTimer timer;
OSMesgQueue timerqueue;
- if (gOsContInitialized) {
+ if (gOSContInitialized) {
return 0;
}
- gOsContInitialized = 1;
+ gOSContInitialized = 1;
currentTime = osGetTime();
if (HALF_SECOND > currentTime) {
osCreateMesgQueue(&timerqueue, &mesg, 1);
osSetTimer(&timer, HALF_SECOND - currentTime, 0, &timerqueue, &mesg);
osRecvMesg(&timerqueue, &mesg, OS_MESG_BLOCK);
}
- _osCont_numControllers = 4;
- __osPackRequestData(0);
- ret = __osSiRawStartDma(OS_WRITE, &_osPifInternalBuff);
+ __osMaxControllers = MAXCONTROLLERS;
+ __osPackRequestData(CONT_CMD_REQUEST_STATUS);
+ ret = __osSiRawStartDma(OS_WRITE, &__osPifInternalBuff);
osRecvMesg(mq, &mesg, OS_MESG_BLOCK);
- ret = __osSiRawStartDma(OS_READ, &_osPifInternalBuff);
+ ret = __osSiRawStartDma(OS_READ, &__osPifInternalBuff);
osRecvMesg(mq, &mesg, OS_MESG_BLOCK);
- __osContGetInitData(ctl_present_bitfield, status);
- _osCont_lastPollType = 0;
+ __osContGetInitData(ctlBitfield, status);
+ __osContLastPoll = CONT_CMD_REQUEST_STATUS;
__osSiCreateAccessQueue();
- osCreateMesgQueue(&_osContMesgQueue, _osContMesgBuff, 1);
+ osCreateMesgQueue(&__osEepromTimerMsgQ, &__osEepromTimerMsg, 1);
return ret;
}
-void __osContGetInitData(u8* ctl_present_bitfield, OSContStatus* status) {
- PIF_IO_slot_t* slot_ptr;
- PIF_IO_slot_t slot;
+void __osContGetInitData(u8* ctlBitfield, OSContStatus* status) {
+ u8* bufptr;
+ __OSContRequestHeader req;
s32 i;
- u8 bitfield_temp;
- bitfield_temp = 0;
- slot_ptr = _osPifInternalBuff.slots;
- for (i = 0; i < _osCont_numControllers; i++, slot_ptr++, status++) {
- slot = *slot_ptr;
- status->errno = (slot.hdr.status_hi_bytes_rec_lo & 0xc0) >> 4;
- if (status->errno == 0) {
- status->type = slot.ctl_type_hi << 8 | slot.ctl_type_lo;
- status->status = slot.ctl_status;
- bitfield_temp |= 1 << i;
+ u8 bitfieldTemp = 0;
+ bufptr = (u8*)(&__osPifInternalBuff);
+ for (i = 0; i < __osMaxControllers; i++, bufptr += sizeof(req), status++) {
+ req = *((__OSContRequestHeader*)bufptr);
+ status->errno = (req.rxsize & 0xC0) >> 4;
+ if (status->errno) {
+ continue;
}
+ status->type = req.typel << 8 | req.typeh;
+ status->status = req.status;
+ bitfieldTemp |= 1 << i;
}
- *ctl_present_bitfield = bitfield_temp;
+ *ctlBitfield = bitfieldTemp;
}
-void __osPackRequestData(u8 command) {
- PIF_IO_slot_t* slot_ptr;
- PIF_IO_slot_t slot;
+void __osPackRequestData(u8 poll) {
+ u8* bufptr;
+ __OSContRequestHeader req;
s32 i;
for (i = 0; i < 0xF; i++) {
- _osPifInternalBuff.words[i] = 0;
+ __osPifInternalBuff.ram[i] = 0;
}
- _osPifInternalBuff.status_control = 1;
- slot.hdr.slot_type = 0xFF;
- slot.hdr.bytes_send = 1;
- slot.hdr.status_hi_bytes_rec_lo = 3;
- slot.hdr.command = command;
- slot.ctl_type_lo = 0xFF;
- slot.ctl_type_hi = 0xFF;
- slot.ctl_status = 0xFF;
- slot.dummy = 0xFF;
- slot_ptr = _osPifInternalBuff.slots;
- for (i = 0; i < _osCont_numControllers; i++) {
- *slot_ptr++ = slot;
+ __osPifInternalBuff.status = 1;
+
+ bufptr = &__osPifInternalBuff;
+
+ req.align = 0xFF;
+ req.txsize = 1;
+ req.rxsize = 3;
+ req.poll = poll;
+ req.typeh = 0xFF;
+ req.typel = 0xFF;
+ req.status = 0xFF;
+ req.align1 = 0xFF;
+
+ for (i = 0; i < __osMaxControllers; i++) {
+ *((__OSContRequestHeader*)bufptr) = req;
+ bufptr += sizeof(req);
}
- slot_ptr->hdr.slot_type = 254;
+ *((u8*)bufptr) = 254;
}