1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-23 13:54:44 +00:00
oot/src/libultra_code/osContStartReadData.c

59 lines
1.6 KiB
C
Raw Normal View History

2020-03-17 04:31:30 +00:00
#include <ultra64.h>
#include <global.h>
#include <ultra64/controller.h>
s32 osContStartReadData(OSMesgQueue *mq) //func_80100EF0
{
s32 ret;
__osSiGetAccess(); //__osSiGetAccess
if (_osCont_lastPollType != 1)
{
__osPackReadData();
__osSiRawStartDma(OS_WRITE, &_osPifInternalBuff);
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
}
ret = __osSiRawStartDma(OS_READ, &_osPifInternalBuff);
_osCont_lastPollType = 1;
__osSiRelAccess();
return ret;
}
void osContGetReadData(OSContPad *pad) { //func_80100F74
PIF_IO_slot_t *slot_ptr;
PIF_IO_slot_t slot;
s32 i;
slot_ptr = _osPifInternalBuff.slots;
for (i = 0; i < _osCont_numControllers; i++, slot_ptr++, pad++) {
slot = *slot_ptr;
pad->errno = (slot.hdr.status_hi_bytes_rec_lo & 0xc0) >> 4;
if (pad->errno == 0) {
pad->button = slot.button;
pad->stick_x = slot.rawStickX;
pad->stick_y = slot.rawStickY;
}
};
}
void __osPackReadData() { //func_80101000
PIF_IO_slot_t *slot_ptr;
PIF_IO_slot_t slot;
s32 i;
slot_ptr = _osPifInternalBuff.slots;
for(i = 0; i < 0xF; i++) {
_osPifInternalBuff.words[i] = 0;
}
_osPifInternalBuff.status_control = 1;
slot.hdr.slot_type = 0xFF;
slot.hdr.bytes_send = 1;
slot.hdr.status_hi_bytes_rec_lo = 4;
slot.hdr.command = 1;
slot.button = 0xFFFF;
slot.rawStickX = 0xFF;
slot.rawStickY = 0xFF;
for(i = 0; i < _osCont_numControllers; i++) {
*slot_ptr++ = slot;
}
slot_ptr->hdr.slot_type = 0xFE;
}