summaryrefslogtreecommitdiff
path: root/src/libultra_code_O2/osContStartReadData.c
diff options
context:
space:
mode:
authorRandom <28494085+Random06457@users.noreply.github.com>2020-10-03 17:22:44 +0200
committerGitHub <noreply@github.com>2020-10-03 11:22:44 -0400
commit174af7384d1cfcbf15da02d9069bf02bdc433c20 (patch)
treee4fb18346f71047c123ec4d34a80ae7e4d8ab9ea /src/libultra_code_O2/osContStartReadData.c
parent6136ee6debd570a63fc695a6f4664553303f2324 (diff)
libultra cleanup (#215)
* cleanup libultra * fixes - use quotes instead of <> for includes - add macros for zelda specific thread priorities - fix Makefile - properly format the remaining pfs structs * fix button macros + add CHECK_BTN_ANY/CHECK_BTN_ALL * remove ULTRA_ABS * fix includes * update z_player.c/z_lib.c + run format.sh * merge upstream/master * fix include in En_Goroiwa * fix includes
Diffstat (limited to 'src/libultra_code_O2/osContStartReadData.c')
-rw-r--r--src/libultra_code_O2/osContStartReadData.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/libultra_code_O2/osContStartReadData.c b/src/libultra_code_O2/osContStartReadData.c
new file mode 100644
index 000000000..59ead072c
--- /dev/null
+++ b/src/libultra_code_O2/osContStartReadData.c
@@ -0,0 +1,54 @@
+#include "global.h"
+
+s32 osContStartReadData(OSMesgQueue* mq) {
+ s32 ret;
+ __osSiGetAccess();
+ if (__osContLastPoll != 1) {
+ __osPackReadData();
+ __osSiRawStartDma(OS_WRITE, &__osPifInternalBuff);
+ osRecvMesg(mq, NULL, OS_MESG_BLOCK);
+ }
+ ret = __osSiRawStartDma(OS_READ, &__osPifInternalBuff);
+ __osContLastPoll = CONT_CMD_READ_BUTTON;
+ __osSiRelAccess();
+ return ret;
+}
+
+void osContGetReadData(OSContPad* contData) {
+ u8* bufptr;
+ __OSContReadHeader read;
+ s32 i;
+ bufptr = (u8*)(&__osPifInternalBuff);
+ for (i = 0; i < __osMaxControllers; i++, bufptr += sizeof(read), contData++) {
+ read = *((__OSContReadHeader*)bufptr);
+ contData->errno = (read.rxsize & 0xC0) >> 4;
+ if (contData->errno == 0) {
+ contData->button = read.button;
+ contData->stick_x = read.joyX;
+ contData->stick_y = read.joyY;
+ }
+ };
+}
+
+void __osPackReadData() {
+ u8* bufptr;
+ __OSContReadHeader read;
+ s32 i;
+ bufptr = (u8*)(&__osPifInternalBuff);
+ for (i = 0; i < 0xF; i++) {
+ __osPifInternalBuff.ram[i] = 0;
+ }
+ __osPifInternalBuff.status = 1;
+ read.align = 0xFF;
+ read.txsize = 1;
+ read.rxsize = 4;
+ read.poll = CONT_CMD_READ_BUTTON;
+ read.button = 0xFFFF;
+ read.joyX = 0xFF;
+ read.joyY = 0xFF;
+ for (i = 0; i < __osMaxControllers; i++) {
+ *((__OSContReadHeader*)bufptr) = read;
+ bufptr += sizeof(read);
+ }
+ *((u8*)bufptr) = CONT_CMD_END;
+}