1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-13 12:59:59 +00:00
oot/src/libultra_code/osContStartReadData.c

57 lines
1.5 KiB
C
Raw Normal View History

2020-03-17 04:31:30 +00:00
#include <ultra64.h>
#include <global.h>
#include <ultra64/controller.h>
2020-03-22 21:19:43 +00:00
s32 osContStartReadData(OSMesgQueue* mq) {
2020-03-17 04:31:30 +00:00
s32 ret;
2020-03-22 21:19:43 +00:00
__osSiGetAccess(); // __osSiGetAccess
if (_osCont_lastPollType != 1) {
2020-03-17 04:31:30 +00:00
__osPackReadData();
__osSiRawStartDma(OS_WRITE, &_osPifInternalBuff);
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
}
ret = __osSiRawStartDma(OS_READ, &_osPifInternalBuff);
_osCont_lastPollType = 1;
__osSiRelAccess();
return ret;
}
2020-03-22 21:19:43 +00:00
void osContGetReadData(OSContPad* pad) {
PIF_IO_slot_t* slot_ptr;
2020-03-17 04:31:30 +00:00
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.input.button;
pad->stick_x = slot.input.x;
pad->stick_y = slot.input.y;
2020-03-17 04:31:30 +00:00
}
};
}
2020-03-22 21:19:43 +00:00
void __osPackReadData() {
PIF_IO_slot_t* slot_ptr;
2020-03-17 04:31:30 +00:00
PIF_IO_slot_t slot;
s32 i;
slot_ptr = _osPifInternalBuff.slots;
2020-03-22 21:19:43 +00:00
for (i = 0; i < 0xF; i++) {
2020-03-17 04:31:30 +00:00
_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.input.button = 0xFFFF;
slot.input.x = 0xFF;
slot.input.y = 0xFF;
2020-03-22 21:19:43 +00:00
for (i = 0; i < _osCont_numControllers; i++) {
2020-03-17 04:31:30 +00:00
*slot_ptr++ = slot;
}
slot_ptr->hdr.slot_type = 0xFE;
}