1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-11 19:59:29 +00:00
oot/src/libultra_code/osContStartReadData.c
silv3rwing07 5aef81071e
padmgr and related (#71)
* In process of moving changes over from old repo

* Merged in changes

* Finished import of padmgr changes from old repo

* Adjusted some volatile

* Improving padmgr volatile situation

* Almost matched osReadMempak

* Working on osMempakDataCRC

* Explanations and equivalents but no matches for osMempakAddrCRC and osMempakDataCRC

* OK after merge

* Matched osMempakAddrCRC and osMempakDataCRC

* Matched osReadMempak

* Updated PadMgr function names to be less like original code

* Changed variable names to make them further from original code

* Changed names and it stopped matching

* Undid clang-format steamrollering whitespace memes

* Cleaned up Input names

* More formatting changes

* Moved padmgr to z64.h, deleted padmgr.h
2020-04-14 13:17:25 -04:00

56 lines
1.5 KiB
C

#include <ultra64.h>
#include <global.h>
#include <ultra64/controller.h>
s32 osContStartReadData(OSMesgQueue* mq) {
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) {
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.input.button;
pad->stick_x = slot.input.x;
pad->stick_y = slot.input.y;
}
};
}
void __osPackReadData() {
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.input.button = 0xFFFF;
slot.input.x = 0xFF;
slot.input.y = 0xFF;
for (i = 0; i < _osCont_numControllers; i++) {
*slot_ptr++ = slot;
}
slot_ptr->hdr.slot_type = 0xFE;
}