diff options
| author | coco875 <59367621+coco875@users.noreply.github.com> | 2024-09-17 17:32:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-17 09:32:50 -0600 |
| commit | 203090e5913f79df01ee273e40dea03b294f061e (patch) | |
| tree | 2ee78c50742b20238c07610b8ba9f7f93c3a80e1 /src/os | |
| parent | d36d7dcd604d0f85b6b547a85e9b7a4fe3e59b5c (diff) | |
update with the decomp (#97)
* Update menus.c (#634)
* Update common_data.yml (#635)
* Renames for screenId and other changes (#636)
* screenId renames
* Rename surface map to collision mesh (#637)
* Rename some stack vars (#638)
* Fix syntax error (#639)
* Rename some stack vars
* Update collision.c
* Collision Documentation (#640)
* Collision related renames
* update doxygen (#649)
* change bool (#644)
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* Update (#642)
* Delete trig_tables_bss.c (#650)
* fix typo audio (#656)
* fix typo src actor (#657)
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* fix typo include (#658)
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* fix course (#659)
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* fix typo debug (#660)
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* fix typo data (#661)
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* replace number with const (#665)
* fix typo buffers (#655)
* fix typo buffers
* tweak ld file
* rename to sMemoryPool
* add a warning
---------
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* fix typo src (#654)
* fix typo src
* fix non matcing
* Update code_80091750.c
---------
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* fix typo racing (#653)
* fix typo racing
* get it match
* replace G_LINE3D to G_QUAD
---------
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* fix typo src (#652)
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* fix ending typo (#651)
* Action more info when it doesn't match and fix first diff (#662)
* Update linux-compile.yml
* fix first-diff
* Update first-diff.py
---------
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* document texture of kart (#663)
* document texture of kart
* change screenPlayerId to screenId
* some documentation around object
* Revert "some documentation around object"
This reverts commit cbb39078e036bf2a417bed67359e910213acab28.
* more rename
---------
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* Make evaluate_collision_players_palm_tree better (#667)
This matches just the same as before, but using those two casts instead of
shifts seems more likely to be accurate to the original source code
Signed-off-by: Gabriel Ravier <gabravier@gmail.com>
* add fedora instruciton (#666)
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* start documenting animation (#668)
* start documenting animation
* Update course_data.c
* change comment
* update libultra asm (#648)
* update libultra asm
* fix gcc __osThreadTail
---------
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* Document Vehicles (#641)
* start doc collision
* fix merge
* finish rename fonction related to vehicle
* document around waypoint of vehicle
* make some modification
* make some change and rename one
* copy_ to oldPos
* doc smoke ferry and train
* some rename
* fix some renaming
* precise index
* rename a funciton
* simplify waypoint_vehicles
* change some name
* change some name
* rename move_to_point_direction
* fix some conflict
* Update code_80005FD0.c
* Update code_80005FD0.h
---------
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* Label a save info loop (#645)
* save info
* more gcc progress
* fix a value and do a rename (#669)
* update clang and add action (#664)
* update clang and add action
* try clang on course folder only
* forget two file
* Update course_displaylists.inc.c
* forget few other file
* Update course_vertices.inc.c
* format all code while get it match
* second pass
* format other dir
* disable clang format on bad ido code
* fix some tabulation
* revert format on tool dir
* Update clang-format.yml
* ignore gbi.h
* add some read me instruction
* fix error
* format and fixing error
* Update README.md
---------
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* Update linkonly_generator.py (#670)
* some rename for torch (#588)
* rename gBombKartSpawns, and fix cup ID
* Update doxygen_syms.md
* rename for gCourseIndexInCup and his constant
* rename to gCupSelectedCourseIndex
* forget a change in constant
* fix compilation issue
* Update Dockerfile to latest Ubuntu LTS + fixed missing cmake (#674)
* Fix color font matrix function (#676)
* Fix label variables used in menus (#675)
* Fix label variables used in menus
* split D_800F2BDC and clang format menu.c
---------
Co-authored-by: coco875 <pereira.jannin@gmail.com>
* Fix some libultra struct types (#677)
* Uintptr (#671)
* Update render_courses.c
* Update math_util.c
* Update math_util.c
* Update math_util.h
* Update render_courses.c
* Clang suggest (#678)
* add clang suggestion
* Update clang-format-suggest.yml
* Update clang-format-suggest.yml
* simplify
* switch to ubuntu
* Update clang-format-suggest.yml
* update ubuntu
---------
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* Clang pr (#679)
* Create clang-pr.yml
* Update clang-pr.yml
* Update osCreateMesgQueue.c
* Update osCreateMesgQueue.c
* Update clang-pr.yml
* Update clang-pr.yml
* Update clang-format.yml
* clang format (#680)
Co-authored-by: MegaMech <7255464+MegaMech@users.noreply.github.com>
* some rename in ceremony (#647)
* rename ceremony
* apply some suggestion
* some rename
---------
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* clang format (#681)
Co-authored-by: MegaMech <7255464+MegaMech@users.noreply.github.com>
* Rename Object Timing Related Code (#673)
* start making models extraction with blender
* finishing extract model
* Update fast64
* extract course
* Update fast64
* Update fast64
* simplify import of course_displaylists and course_textures and remplace adress with texture
* Update fast64
* change data format and simplify the thread queue
* move in a blender folder
* remove fast64
* re add fast64
* add model_extract and fast64_blender in makefile
* multithread with make file split the models into multiple json and add course segment
* Update fast64
* remove old model_extract
* remove the error when he don't find blender
* start rename around course section
* rename around object
* update submodule fast64
* fix compilation issue and add some model to extract
* Update fast64
* remove fast64
* re add fast64
* update submodule
* fix compilation issue
* add other collision gfx and prepare reorganise file
* re arrange json
* Create README.MD
* Update README.MD
* Update README.MD
* update fast64
* rename to initiate_next_state
* Revert "Merge branch '3d-objects' into general-object"
This reverts commit f5347b38cc75af4d10ee3726dc1524c1c71d6849, reversing
changes made to a353c4d954fb5b50c8b48fe3f9d67c95ccaab299.
* revert the revert...
* revert 3d-models PR
* finish some revert
* Update code_80005FD0.c
* fix code_80091750.c
* Update code_80091750.c
* rename isTimerRunning to isTimerActive and set_object_timer_running to set_object_timer_state
* rename to initialize_next_state
* rename to object_next_state
---------
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* extract models with blender (#577)
* start making models extraction with blender
* finishing extract model
* Update fast64
* extract course
* Update fast64
* Update fast64
* simplify import of course_displaylists and course_textures and remplace adress with texture
* Update fast64
* change data format and simplify the thread queue
* move in a blender folder
* remove fast64
* re add fast64
* add model_extract and fast64_blender in makefile
* multithread with make file split the models into multiple json and add course segment
* Update fast64
* remove old model_extract
* remove the error when he don't find blender
* start rename around course section
* update submodule fast64
* fix compilation issue and add some model to extract
* Update fast64
* remove fast64
* re add fast64
* update submodule
* fix compilation issue
* add other collision gfx and prepare reorganise file
* re arrange json
* Create README.MD
* Update README.MD
* Update README.MD
* update fast64
---------
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
* other
* fix some error of compilation
* finish fix all error
---------
Signed-off-by: Gabriel Ravier <gabravier@gmail.com>
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
Co-authored-by: Gabriel Ravier <gabravier@gmail.com>
Co-authored-by: MisterSheeple <27652712+MisterSheeple@users.noreply.github.com>
Co-authored-by: AloXado320 <38191089+AloXado320@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: MegaMech <7255464+MegaMech@users.noreply.github.com>
Diffstat (limited to 'src/os')
| -rw-r--r-- | src/os/__osDequeueThread.c | 33 | ||||
| -rw-r--r-- | src/os/__osDevMgrMain.c | 4 | ||||
| -rw-r--r-- | src/os/__osLeoInterrupt.c | 2 | ||||
| -rw-r--r-- | src/os/__osViSwapContext.c | 6 | ||||
| -rw-r--r-- | src/os/controller.h | 4 | ||||
| -rw-r--r-- | src/os/leointerrupt.c | 185 | ||||
| -rw-r--r-- | src/os/libultra_internal.h | 16 | ||||
| -rw-r--r-- | src/os/osContInit.c | 66 | ||||
| -rw-r--r-- | src/os/osContInternal.h | 43 | ||||
| -rw-r--r-- | src/os/osContStartReadData.c | 87 | ||||
| -rw-r--r-- | src/os/osCreateMesgQueue.c | 5 | ||||
| -rw-r--r-- | src/os/osCreatePiManager.c | 4 | ||||
| -rw-r--r-- | src/os/osEepromRead.c | 6 | ||||
| -rw-r--r-- | src/os/osEepromWrite.c | 9 | ||||
| -rw-r--r-- | src/os/osViSwapBuffer.c | 2 |
15 files changed, 122 insertions, 350 deletions
diff --git a/src/os/__osDequeueThread.c b/src/os/__osDequeueThread.c index 8a9a8f483..009114aab 100644 --- a/src/os/__osDequeueThread.c +++ b/src/os/__osDequeueThread.c @@ -1,23 +1,24 @@ #include "libultra_internal.h" -NO_REORDER OSThread* __osThreadTail = NULL; -NO_REORDER u32 __osTest = -1; -NO_REORDER OSThread* __osRunQueue = (OSThread*) &__osThreadTail; -NO_REORDER OSThread* __osActiveQueue = (OSThread*) &__osThreadTail; -OSThread* __osRunningThread = NULL; -OSThread* __osFaultedThread = NULL; +struct __osThreadTail __osThreadTail = { NULL, -1 }; +OSThread* __osRunQueue = (OSThread*) &__osThreadTail; +OSThread* __osActiveQueue = (OSThread*) &__osThreadTail; +OSThread* __osRunningThread = { 0 }; +OSThread* __osFaultedThread = { 0 }; -void __osDequeueThread(OSThread** queue, OSThread* thread) { - register OSThread** a2; - register OSThread* a3; - a2 = queue; - a3 = *a2; - while (a3 != NULL) { - if (a3 == thread) { - *a2 = thread->next; +void __osDequeueThread(register OSThread** queue, register OSThread* t) { + register OSThread* pred; + register OSThread* succ; + + pred = (OSThread*) queue; + succ = pred->next; + + while (succ != NULL) { + if (succ == t) { + pred->next = t->next; return; } - a2 = &a3->next; - a3 = *a2; + pred = succ; + succ = pred->next; } } diff --git a/src/os/__osDevMgrMain.c b/src/os/__osDevMgrMain.c index 5a7ecfb45..4fa057fd5 100644 --- a/src/os/__osDevMgrMain.c +++ b/src/os/__osDevMgrMain.c @@ -64,11 +64,11 @@ void __osDevMgrMain(void* args) { break; case 15: osRecvMesg(sp34->accessQueue, &dummy, OS_MESG_BLOCK); - ret = sp34->epiDmaCallback(mb->piHandle, OS_READ, mb->devAddr, mb->dramAddr, mb->size); + ret = sp34->edma_func(mb->piHandle, OS_READ, mb->devAddr, mb->dramAddr, mb->size); break; case 16: osRecvMesg(sp34->accessQueue, &dummy, OS_MESG_BLOCK); - ret = sp34->epiDmaCallback(mb->piHandle, OS_WRITE, mb->devAddr, mb->dramAddr, mb->size); + ret = sp34->edma_func(mb->piHandle, OS_WRITE, mb->devAddr, mb->dramAddr, mb->size); break; case 10: osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); diff --git a/src/os/__osLeoInterrupt.c b/src/os/__osLeoInterrupt.c index d0629ce55..69bbeb889 100644 --- a/src/os/__osLeoInterrupt.c +++ b/src/os/__osLeoInterrupt.c @@ -9,6 +9,8 @@ extern u8 leoDiskStack[OS_PIM_STACKSIZE]; // technically should have a OS_LEO_ST extern u32 D_800EA5F0; +u8 leoDiskStack[OS_PIM_STACKSIZE]; // technically should have a OS_LEO_STACKSIZE or something.. + s32 __osLeoInterrupt() { u32 stat; volatile u32 pistat; diff --git a/src/os/__osViSwapContext.c b/src/os/__osViSwapContext.c index 0fef03ce6..66d89edfa 100644 --- a/src/os/__osViSwapContext.c +++ b/src/os/__osViSwapContext.c @@ -23,10 +23,10 @@ void __osViSwapContext() { } else { s1->x.scale = s0->comRegs.xScale; } - if (s1->state & 4) { + if (s1->unk00 & 4) { sp34 = (u32) (s0->fldRegs[field].yScale & 0xfff); - s1->y.scale = s1->y.factor * sp34; - s1->y.scale |= s0->fldRegs[field].yScale & ~0xfff; + s1->unk2c = s1->unk24 * sp34; + s1->unk2c |= s0->fldRegs[field].yScale & ~0xfff; } else { s1->y.scale = s0->fldRegs[field].yScale; } diff --git a/src/os/controller.h b/src/os/controller.h index f1ff34661..257e3db8e 100644 --- a/src/os/controller.h +++ b/src/os/controller.h @@ -149,8 +149,8 @@ s32 __osPfsReleasePages(OSPfs* pfs, __OSInode* inode, u8 start_page, u16* sum, u s32 __osBlockSum(OSPfs* pfs, u8 page_no, u16* sum, u8 bank); s32 __osContRamRead(OSMesgQueue* mq, int channel, u16 address, u8* buffer); s32 __osContRamWrite(OSMesgQueue* mq, int channel, u16 address, u8* buffer, int force); -void __osContGetInitData(u8* pattern, OSContStatus* data); -void __osPackRequestData(u8 cmd); +void __osContGetInitData(u8* bitpattern, OSContStatus* status); +void __osPackRequestData(u8 command); void __osPfsRequestData(u8 cmd); void __osPfsGetInitData(u8* pattern, OSContStatus* data); u8 __osContAddressCrc(u16 addr); diff --git a/src/os/leointerrupt.c b/src/os/leointerrupt.c deleted file mode 100644 index 1690fe474..000000000 --- a/src/os/leointerrupt.c +++ /dev/null @@ -1,185 +0,0 @@ -#include "libultra_internal.h" -#include <PR/rcp.h> -#include "bstring.h" -#include "piint.h" -#include "osint.h" - -u8 leoDiskStack[OS_PIM_STACKSIZE]; // technically should have a OS_LEO_STACKSIZE or something.. - -#ifdef VERSION_SH - -//! @todo so many magic constants :'( -static void __osLeoResume(void); -static void __osLeoAbnormalResume(void); - -s32 __osLeoInterrupt() { - u32 stat; - volatile u32 pi_stat; - u32 bm_stat; - __OSTranxInfo* info; - __OSBlockInfo* blockInfo; - stat = 0; - info = &__osDiskHandle->transferInfo; - blockInfo = &info->block[info->blockNum]; - pi_stat = IO_READ(PI_STATUS_REG); - if (pi_stat & PI_STATUS_DMA_BUSY) { - __OSGlobalIntMask = __OSGlobalIntMask & ~SR_IBIT4; // cartridge interrupt - blockInfo->errStatus = LEO_ERROR_29; - __osLeoResume(); - return 1; - } - WAIT_ON_IOBUSY(pi_stat); - stat = IO_READ(LEO_STATUS); - if (stat & LEO_STATUS_MECHANIC_INTERRUPT) { - WAIT_ON_IOBUSY(pi_stat); - IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR); - blockInfo->errStatus = LEO_ERROR_GOOD; - return 0; - } - if (info->cmdType == LEO_CMD_TYPE_2) { - return 1; - } - if (stat & LEO_STATUS_BUFFER_MANAGER_ERROR) { - WAIT_ON_IOBUSY(pi_stat); - stat = IO_READ(LEO_STATUS); - blockInfo->errStatus = LEO_ERROR_22; - __osLeoResume(); - IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); - __OSGlobalIntMask |= OS_IM_PI; - return 1; - } - if (info->cmdType == LEO_CMD_TYPE_1) { - if ((stat & LEO_STATUS_DATA_REQUEST) == 0) { - if (info->sectorNum + 1 != info->transferMode * 85) { - blockInfo->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - return 1; - } - IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); - __OSGlobalIntMask |= OS_IM_PI; - blockInfo->errStatus = LEO_ERROR_GOOD; - __osLeoResume(); - return 1; - } - blockInfo->dramAddr = (void*) ((u32) blockInfo->dramAddr + blockInfo->sectorSize); - info->sectorNum++; - osEPiRawStartDma(__osDiskHandle, OS_WRITE, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize); - return 1; - } - if (info->cmdType == LEO_CMD_TYPE_0) { - if (info->transferMode == LEO_SECTOR_MODE) { - if ((s32) blockInfo->C1ErrNum + 17 < info->sectorNum) { - blockInfo->errStatus = LEO_ERROR_GOOD; - __osLeoAbnormalResume(); - return 1; - } - if ((stat & LEO_STATUS_DATA_REQUEST) == 0) { - blockInfo->errStatus = LEO_ERROR_23; - __osLeoAbnormalResume(); - return 1; - } - } else { - blockInfo->dramAddr = (void*) ((u32) blockInfo->dramAddr + blockInfo->sectorSize); - } - bm_stat = IO_READ(LEO_BM_STATUS); - if ((bm_stat & LEO_BM_STATUS_C1SINGLE && bm_stat & LEO_BM_STATUS_C1DOUBLE) || bm_stat & LEO_BM_STATUS_MICRO) { - if (blockInfo->C1ErrNum > 3) { - if (info->transferMode != LEO_SECTOR_MODE || info->sectorNum > 0x52) { - blockInfo->errStatus = LEO_ERROR_23; - __osLeoAbnormalResume(); - return 1; - } - } else { - int errNum = blockInfo->C1ErrNum; - blockInfo->C1ErrSector[errNum] = info->sectorNum + 1; - } - blockInfo->C1ErrNum++; - } - if (stat & LEO_STATUS_C2_TRANSFER) { - if (info->sectorNum != 87) { - blockInfo->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - } - if (info->transferMode == LEO_TRACK_MODE && info->blockNum == 0) { - info->blockNum = 1; - info->sectorNum = -1; - info->block[1].dramAddr = (void*) ((u32) info->block[1].dramAddr - info->block[1].sectorSize); - - blockInfo->errStatus = LEO_ERROR_22; - } else { - IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); - __OSGlobalIntMask |= OS_IM_PI; - info->cmdType = LEO_CMD_TYPE_2; - blockInfo->errStatus = LEO_ERROR_GOOD; - } - osEPiRawStartDma(__osDiskHandle, OS_READ, LEO_C2_BUFF, blockInfo->C2Addr, blockInfo->sectorSize * 4); - return 1; - } - - if (info->sectorNum == -1 && info->transferMode == LEO_TRACK_MODE && info->blockNum == 1) { - __OSBlockInfo* bptr = &info->block[0]; - if (bptr->C1ErrNum == 0) { - if (((u32*) bptr->C2Addr)[0] | ((u32*) bptr->C2Addr)[1] | ((u32*) bptr->C2Addr)[2] | - ((u32*) bptr->C2Addr)[3]) { - bptr->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - return 1; - } - } - bptr->errStatus = 0; - __osLeoResume(); - } - info->sectorNum++; - if (stat & LEO_STATUS_DATA_REQUEST) { - if (info->sectorNum > 0x54) { - blockInfo->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - return 1; - } - osEPiRawStartDma(__osDiskHandle, 0, LEO_SECTOR_BUFF, blockInfo->dramAddr, blockInfo->sectorSize); - blockInfo->errStatus = LEO_ERROR_GOOD; - return 1; - } - if (info->sectorNum <= 0x54) { - blockInfo->errStatus = LEO_ERROR_24; - __osLeoAbnormalResume(); - return 1; - } - return 1; - } - blockInfo->errStatus = LEO_ERROR_4; - __osLeoAbnormalResume(); - return 1; -} - -static void __osLeoAbnormalResume(void) { - __OSTranxInfo* info; - u32 pi_stat; - info = &__osDiskHandle->transferInfo; - WAIT_ON_IOBUSY(pi_stat); - IO_WRITE(LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET); - WAIT_ON_IOBUSY(pi_stat); - IO_WRITE(LEO_BM_CTL, info->bmCtlShadow); - __osLeoResume(); - IO_WRITE(PI_STATUS_REG, PI_STATUS_CLR_INTR); - __OSGlobalIntMask |= OS_IM_PI; -} - -static void __osLeoResume(void) { - __OSEventState* es; - OSMesgQueue* mq; - s32 last; - es = &__osEventStateTab[OS_EVENT_PI]; - mq = es->messageQueue; - if (mq == NULL || MQ_IS_FULL(mq)) { - return; - } - last = (mq->first + mq->validCount) % mq->msgCount; - mq->msg[last] = es->message; - mq->validCount++; - if (mq->mtqueue->next != NULL) { - __osEnqueueThread(&D_80334898, __osPopThread(&mq->mtqueue)); - } -} - -#endif diff --git a/src/os/libultra_internal.h b/src/os/libultra_internal.h index b6ae5dd06..8b775d3e1 100644 --- a/src/os/libultra_internal.h +++ b/src/os/libultra_internal.h @@ -10,14 +10,10 @@ typedef struct __OSEventState { } __OSEventState; #endif -typedef struct // __osThreadTail -{ - /* 0x00 */ OSThread* next; - /* 0x04 */ OSPri priority; - /* 0x08 */ OSThread* queue; - /* 0x0c */ OSThread* tlnext; - -} OSThreadTail; +extern struct __osThreadTail { + OSThread* next; + OSPri priority; +} __osThreadTail; /* * This define is needed because the original definitions in __osDequeueThread.c are declared @@ -35,10 +31,10 @@ typedef struct { } OSThread_ListHead; // Original OSThread_ListHead definitions -extern OSThread* __osThreadTail; +extern OSThread* __osRunningThread; extern OSThread* __osActiveQueue; +extern OSThread* __osFaultedThread; extern OSThread* __osRunQueue; -extern OSThread* __osRunningThread; // Original EEPROM definitions extern u32 D_80365E00[15]; diff --git a/src/os/osContInit.c b/src/os/osContInit.c index ccd7583d5..04cb65ddf 100644 --- a/src/os/osContInit.c +++ b/src/os/osContInit.c @@ -1,5 +1,5 @@ #include "libultra_internal.h" -#include "osContInternal.h" +#include "controller.h" void __osPackRequestData(u8); void __osContGetInitData(u8*, OSContStatus*); @@ -9,6 +9,7 @@ u32 _osContInitialized = 0; extern u64 osClockRate; // these probably belong in EEPROMlongread or something +ALIGNED16 OSPifRam __osContPifRam; u8 __osContLastCmd; u8 _osContNumControllers; OSTimer D_80196548; @@ -34,9 +35,9 @@ s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* status) { //! @todo figure out what it means _osContNumControllers = 4; __osPackRequestData(0); - ret = __osSiRawStartDma(OS_WRITE, _osContCmdBuf); + ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); osRecvMesg(mq, &mesg, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, _osContCmdBuf); + ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); osRecvMesg(mq, &mesg, OS_MESG_BLOCK); __osContGetInitData(bitpattern, status); __osContLastCmd = 0; @@ -45,48 +46,49 @@ s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* status) { return ret; } void __osContGetInitData(u8* bitpattern, OSContStatus* status) { - OSContPackedRequest* cmdBufPtr; - OSContPackedRequest response; + u8* ptr; + __OSContRequesFormat response; s32 i; - u8 sp7; + u8 bits; - sp7 = 0; - cmdBufPtr = &(_osContCmdBuf[0].request); - for (i = 0; i < _osContNumControllers; i++, cmdBufPtr++, status++) { - response = *(OSContPackedRequest*) cmdBufPtr; - status->errnum = (response.rxLen & 0xc0) >> 4; + bits = 0; + ptr = (u8*) __osContPifRam.ramarray; + for (i = 0; i < _osContNumControllers; i++, ptr += sizeof(response), status++) { + response = *((__OSContRequesFormat*) (ptr)); + status->errnum = CHNL_ERR(response); if (status->errnum == 0) { - status->type = response.data2 << 8 | response.data1; - status->status = response.data3; + status->type = response.typel << 8 | response.typeh; + status->status = response.status; - sp7 |= 1 << i; + bits |= 1 << i; } } - *bitpattern = sp7; + + *bitpattern = bits; } void __osPackRequestData(u8 command) { - OSContPackedRequest* cmdBufPtr; - OSContPackedRequest request; + u8* ptr; + __OSContRequesFormat requestHeader; s32 i; - // some kind of weird zeroing code - for (i = 0; i < 0x10; i++) { - *((u32*) &_osContCmdBuf + i) = 0; + for (i = 0; i < ARRLEN(__osContPifRam.ramarray) + 1; i++) { + __osContPifRam.ramarray[i] = 0; } - _osContPifCtrl = 1; - cmdBufPtr = &_osContCmdBuf[0].request; - request.padOrEnd = 255; - request.txLen = 1; - request.rxLen = 3; - request.command = command; - request.data1 = 255; - request.data2 = 255; - request.data3 = 255; - request.data4 = 255; + __osContPifRam.pifstatus = CONT_CMD_EXE; + ptr = (u8*) __osContPifRam.ramarray; + requestHeader.dummy = CONT_CMD_NOP; + requestHeader.txsize = CONT_CMD_RESET_TX; + requestHeader.rxsize = CONT_CMD_RESET_RX; + requestHeader.cmd = command; + requestHeader.typeh = CONT_CMD_NOP; + requestHeader.typel = CONT_CMD_NOP; + requestHeader.status = CONT_CMD_NOP; + requestHeader.dummy1 = CONT_CMD_NOP; for (i = 0; i < _osContNumControllers; i++) { - *cmdBufPtr++ = request; + *(__OSContRequesFormat*) ptr = requestHeader; + ptr += sizeof(requestHeader); } - cmdBufPtr->padOrEnd = 254; + *ptr = CONT_CMD_END; } diff --git a/src/os/osContInternal.h b/src/os/osContInternal.h deleted file mode 100644 index 3b6fc3d47..000000000 --- a/src/os/osContInternal.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef _ULTRA64_CONTROLLER_INTERNAL_H_ -#define _ULTRA64_CONTROLLER_INTERNAL_H_ - -typedef struct { - u8 padOrEnd; - u8 txLen; - u8 rxLen; // includes errno - u8 command; - u16 button; - s8 rawStickX; - s8 rawStickY; -} OSContPackedRead; - -typedef struct { - u8 padOrEnd; - u8 txLen; - u8 rxLen; - u8 command; - u8 data1; - u8 data2; - u8 data3; - u8 data4; -} OSContPackedRequest; - -typedef union { - OSContPackedRead read; - OSContPackedRequest request; - u32 as_raw[2]; -} OSContPackedStruct; - -#ifdef AVOID_UB -// Fix the OSContPackedStruct array -extern OSContPackedStruct _osContCmdBuf[8]; - -// And fix the last element -#define _osContPifCtrl _osContCmdBuf[7].as_raw[1] -#else -// Original OSContPackedStruct definitions -extern OSContPackedStruct _osContCmdBuf[7]; -extern u32 _osContPifCtrl; -#endif - -#endif diff --git a/src/os/osContStartReadData.c b/src/os/osContStartReadData.c index dd80ee70c..f559a6347 100644 --- a/src/os/osContStartReadData.c +++ b/src/os/osContStartReadData.c @@ -1,16 +1,7 @@ #include "libultra_internal.h" -#include "osContInternal.h" +#include "controller.h" #include <macros.h> -#ifndef AVOID_UB -ALIGNED8 OSContPackedStruct _osContCmdBuf[7]; -UNUSED static u32 unused; // padding between these two variables -u32 _osContPifCtrl; -#else -// Reordered gcc vars above will disturb the aliasing done to access all 8 members of this array, hence AVOID_UB. -ALIGNED8 OSContPackedStruct _osContCmdBuf[8]; -#endif - extern u8 __osContLastCmd; extern u8 _osContNumControllers; @@ -18,56 +9,66 @@ void __osPackReadData(void); s32 osContStartReadData(OSMesgQueue* mesg) { s32 ret = 0; s32 i; + __osSiGetAccess(); - if (__osContLastCmd != 1) { + + if (__osContLastCmd != CONT_CMD_READ_BUTTON) { __osPackReadData(); - ret = __osSiRawStartDma(OS_WRITE, _osContCmdBuf); + ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); osRecvMesg(mesg, NULL, OS_MESG_BLOCK); } - for (i = 0; i < 0x10; i++) { - *((u32*) &_osContCmdBuf + i) = 255; + + for (i = 0; i < ARRLEN(__osContPifRam.ramarray) + 1; i++) { + __osContPifRam.ramarray[i] = CONT_CMD_NOP; } - _osContPifCtrl = 0; - ret = __osSiRawStartDma(OS_READ, _osContCmdBuf); - __osContLastCmd = 1; + __osContPifRam.pifstatus = 0; + ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); + __osContLastCmd = CONT_CMD_READ_BUTTON; + __osSiRelAccess(); + return ret; } void osContGetReadData(OSContPad* pad) { - OSContPackedRead* cmdBufPtr; - OSContPackedRead response; + u8* ptr = (u8*) __osContPifRam.ramarray; + __OSContReadFormat readformat; s32 i; - cmdBufPtr = &_osContCmdBuf[0].read; - for (i = 0; i < _osContNumControllers; i++, cmdBufPtr++, pad++) { - response = *cmdBufPtr; - pad->errno = (response.rxLen & 0xc0) >> 4; - if (pad->errno == 0) { - pad->button = response.button; - pad->stick_x = response.rawStickX; - pad->stick_y = response.rawStickY; + + for (i = 0; i < _osContNumControllers; i++, ptr += sizeof(readformat), pad++) { + readformat = *(__OSContReadFormat*) ptr; + pad->errno = CHNL_ERR(readformat); + + if (pad->errno != 0) { + continue; } - }; + + pad->button = readformat.button; + pad->stick_x = readformat.stick_x; + pad->stick_y = readformat.stick_y; + } } void __osPackReadData() { - OSContPackedRead* cmdBufPtr; - OSContPackedRead request; + u8* ptr = (u8*) __osContPifRam.ramarray; + __OSContReadFormat readformat; s32 i; - cmdBufPtr = &_osContCmdBuf[0].read; - for (i = 0; i < 0x10; i++) { - *((u32*) &_osContCmdBuf + i) = 0; + + for (i = 0; i < ARRLEN(__osContPifRam.ramarray) + 1; i++) { + __osContPifRam.ramarray[i] = 0; } - _osContPifCtrl = 1; - request.padOrEnd = 255; - request.txLen = 1; - request.rxLen = 4; - request.command = 1; - request.button = 65535; - request.rawStickX = -1; - request.rawStickY = -1; + __osContPifRam.pifstatus = CONT_CMD_EXE; + readformat.dummy = CONT_CMD_NOP; + readformat.txsize = CONT_CMD_READ_BUTTON_TX; + readformat.rxsize = CONT_CMD_READ_BUTTON_RX; + readformat.cmd = CONT_CMD_READ_BUTTON; + readformat.button = 0xFFFF; + readformat.stick_x = -1; + readformat.stick_y = -1; + for (i = 0; i < _osContNumControllers; i++) { - *cmdBufPtr++ = request; + *(__OSContReadFormat*) ptr = readformat; + ptr += sizeof(readformat); } - cmdBufPtr->padOrEnd = 254; + *ptr = CONT_CMD_END; } diff --git a/src/os/osCreateMesgQueue.c b/src/os/osCreateMesgQueue.c index 1b5c011da..865a49b2b 100644 --- a/src/os/osCreateMesgQueue.c +++ b/src/os/osCreateMesgQueue.c @@ -1,11 +1,10 @@ #include "libultra_internal.h" void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msgBuf, s32 count) { - mq->mtqueue = (OSThread*) &__osThreadTail; //? - mq->fullqueue = (OSThread*) &__osThreadTail; + mq->mtqueue = (OSThread*) &__osThreadTail.next; + mq->fullqueue = (OSThread*) &__osThreadTail.next; mq->validCount = 0; mq->first = 0; mq->msgCount = count; mq->msg = msgBuf; - return; } diff --git a/src/os/osCreatePiManager.c b/src/os/osCreatePiManager.c index b76cc0f7b..cfbd61196 100644 --- a/src/os/osCreatePiManager.c +++ b/src/os/osCreatePiManager.c @@ -44,8 +44,8 @@ void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgC __osPiDevMgr.cmdQueue = cmdQ; __osPiDevMgr.eventQueue = &__osPiMesgQueue; __osPiDevMgr.accessQueue = &gOsPiMessageQueue; - __osPiDevMgr.piDmaCallback = osPiRawStartDma; - __osPiDevMgr.epiDmaCallback = osEPiRawStartDma; + __osPiDevMgr.dma_func = osPiRawStartDma; + __osPiDevMgr.edma_func = osEPiRawStartDma; osCreateThread(&piMgrThread, 0, __osDevMgrMain, (void*) &__osPiDevMgr, &piMgrStack[0x400], pri); osStartThread(&piMgrThread); __osRestoreInt(int_disabled); diff --git a/src/os/osEepromRead.c b/src/os/osEepromRead.c index a6545ce4f..e9f45d072 100644 --- a/src/os/osEepromRead.c +++ b/src/os/osEepromRead.c @@ -35,7 +35,7 @@ s32 osEepromRead(OSMesgQueue* mq, u8 address, u8* buffer) { ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); osRecvMesg(mq, NULL, OS_MESG_BLOCK); - for (i = 0; i < ARRAY_COUNT(__osEepPifRam.ramarray) + 1; i++) { + for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) { __osEepPifRam.ramarray[i] = CONT_CMD_NOP; } __osEepPifRam.pifstatus = 0; @@ -66,7 +66,7 @@ void __osPackEepReadData(u8 address) { __OSContEepromFormat eepromformat; s32 i; - for (i = 0; i < ARRAY_COUNT(__osEepPifRam.ramarray) + 1; i++) { + for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) { __osEepPifRam.ramarray[i] = CONT_CMD_NOP; } __osEepPifRam.pifstatus = CONT_CMD_EXE; @@ -75,7 +75,7 @@ void __osPackEepReadData(u8 address) { eepromformat.rxsize = CONT_CMD_READ_EEPROM_RX; eepromformat.cmd = CONT_CMD_READ_EEPROM; eepromformat.address = address; - for (i = 0; i < ARRAY_COUNT(eepromformat.data); i++) { + for (i = 0; i < ARRLEN(eepromformat.data); i++) { eepromformat.data[i] = 0; } diff --git a/src/os/osEepromWrite.c b/src/os/osEepromWrite.c index faa99d91d..03eaf63e9 100644 --- a/src/os/osEepromWrite.c +++ b/src/os/osEepromWrite.c @@ -1,5 +1,4 @@ #include "libultra_internal.h" -#include "osContInternal.h" #include "controller.h" #include "macros.h" @@ -37,7 +36,7 @@ s32 osEepromWrite(OSMesgQueue* mq, u8 address, u8* buffer) { ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); osRecvMesg(mq, NULL, OS_MESG_BLOCK); - for (i = 0; i < ARRAY_COUNT(__osEepPifRam.ramarray) + 1; i++) { + for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) { __osEepPifRam.ramarray[i] = CONT_CMD_NOP; } @@ -61,7 +60,7 @@ void __osPackEepWriteData(u8 address, u8* buffer) { __OSContEepromFormat eepromformat; s32 i; - for (i = 0; i < ARRAY_COUNT(__osEepPifRam.ramarray) + 1; i++) { + for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) { __osEepPifRam.ramarray[i] = CONT_CMD_NOP; } __osEepPifRam.pifstatus = CONT_CMD_EXE; @@ -71,7 +70,7 @@ void __osPackEepWriteData(u8 address, u8* buffer) { eepromformat.cmd = CONT_CMD_WRITE_EEPROM; eepromformat.address = address; - for (i = 0; i < ARRAY_COUNT(eepromformat.data); i++) { + for (i = 0; i < ARRLEN(eepromformat.data); i++) { eepromformat.data[i] = *buffer++; } @@ -89,7 +88,7 @@ s32 __osEepStatus(OSMesgQueue* mq, OSContStatus* data) { u8* ptr = (u8*) __osEepPifRam.ramarray; __OSContRequesFormat requestformat; - for (i = 0; i < ARRAY_COUNT(__osEepPifRam.ramarray) + 1; i++) { + for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) { __osEepPifRam.ramarray[i] = 0; } __osEepPifRam.pifstatus = CONT_CMD_EXE; diff --git a/src/os/osViSwapBuffer.c b/src/os/osViSwapBuffer.c index f8db8084e..d830f35a9 100644 --- a/src/os/osViSwapBuffer.c +++ b/src/os/osViSwapBuffer.c @@ -6,6 +6,6 @@ void osViSwapBuffer(void* vaddr) { u32 int_disabled = __osDisableInt(); __osViNext->buffer = vaddr; //! @todo figure out what this flag means - __osViNext->state |= 0x10; + __osViNext->unk00 |= 0x10; __osRestoreInt(int_disabled); } |
