Split, match and link OSMessage

This commit is contained in:
Phillip Stephens 2022-12-17 22:48:45 -08:00
parent e924a90c59
commit 7a4e74e0e0
7 changed files with 275 additions and 147 deletions

View File

@ -10,153 +10,6 @@ lbl_803F22E0:
.section .text, "ax"
.global sub_80382810
sub_80382810:
/* 80382810 0037F770 7C 08 02 A6 */ mflr r0
/* 80382814 0037F774 90 01 00 04 */ stw r0, 4(r1)
/* 80382818 0037F778 94 21 FF D8 */ stwu r1, -0x28(r1)
/* 8038281C 0037F77C 93 E1 00 24 */ stw r31, 0x24(r1)
/* 80382820 0037F780 3B E5 00 00 */ addi r31, r5, 0
/* 80382824 0037F784 93 C1 00 20 */ stw r30, 0x20(r1)
/* 80382828 0037F788 3B C4 00 00 */ addi r30, r4, 0
/* 8038282C 0037F78C 93 A1 00 1C */ stw r29, 0x1c(r1)
/* 80382830 0037F790 3B A3 00 00 */ addi r29, r3, 0
/* 80382834 0037F794 48 00 1D 91 */ bl OSInitThreadQueue
/* 80382838 0037F798 38 7D 00 08 */ addi r3, r29, 8
/* 8038283C 0037F79C 48 00 1D 89 */ bl OSInitThreadQueue
/* 80382840 0037F7A0 93 DD 00 10 */ stw r30, 0x10(r29)
/* 80382844 0037F7A4 38 00 00 00 */ li r0, 0
/* 80382848 0037F7A8 93 FD 00 14 */ stw r31, 0x14(r29)
/* 8038284C 0037F7AC 90 1D 00 18 */ stw r0, 0x18(r29)
/* 80382850 0037F7B0 90 1D 00 1C */ stw r0, 0x1c(r29)
/* 80382854 0037F7B4 80 01 00 2C */ lwz r0, 0x2c(r1)
/* 80382858 0037F7B8 83 E1 00 24 */ lwz r31, 0x24(r1)
/* 8038285C 0037F7BC 83 C1 00 20 */ lwz r30, 0x20(r1)
/* 80382860 0037F7C0 83 A1 00 1C */ lwz r29, 0x1c(r1)
/* 80382864 0037F7C4 38 21 00 28 */ addi r1, r1, 0x28
/* 80382868 0037F7C8 7C 08 03 A6 */ mtlr r0
/* 8038286C 0037F7CC 4E 80 00 20 */ blr
.global sub_80382870
sub_80382870:
/* 80382870 0037F7D0 7C 08 02 A6 */ mflr r0
/* 80382874 0037F7D4 90 01 00 04 */ stw r0, 4(r1)
/* 80382878 0037F7D8 94 21 FF D8 */ stwu r1, -0x28(r1)
/* 8038287C 0037F7DC 93 E1 00 24 */ stw r31, 0x24(r1)
/* 80382880 0037F7E0 3B E5 00 00 */ addi r31, r5, 0
/* 80382884 0037F7E4 93 C1 00 20 */ stw r30, 0x20(r1)
/* 80382888 0037F7E8 93 A1 00 1C */ stw r29, 0x1c(r1)
/* 8038288C 0037F7EC 3B A4 00 00 */ addi r29, r4, 0
/* 80382890 0037F7F0 93 81 00 18 */ stw r28, 0x18(r1)
/* 80382894 0037F7F4 3B 83 00 00 */ addi r28, r3, 0
/* 80382898 0037F7F8 4B FF ED C9 */ bl OSDisableInterrupts
/* 8038289C 0037F7FC 3B C3 00 00 */ addi r30, r3, 0
/* 803828A0 0037F800 57 FF 07 FE */ clrlwi r31, r31, 0x1f
/* 803828A4 0037F804 48 00 00 24 */ b lbl_803828C8
lbl_803828A8:
/* 803828A8 0037F808 2C 1F 00 00 */ cmpwi r31, 0
/* 803828AC 0037F80C 40 82 00 14 */ bne lbl_803828C0
/* 803828B0 0037F810 7F C3 F3 78 */ mr r3, r30
/* 803828B4 0037F814 4B FF ED D5 */ bl OSRestoreInterrupts
/* 803828B8 0037F818 38 60 00 00 */ li r3, 0
/* 803828BC 0037F81C 48 00 00 5C */ b lbl_80382918
lbl_803828C0:
/* 803828C0 0037F820 7F 83 E3 78 */ mr r3, r28
/* 803828C4 0037F824 48 00 28 49 */ bl OSSleepThread
lbl_803828C8:
/* 803828C8 0037F828 80 DC 00 14 */ lwz r6, 0x14(r28)
/* 803828CC 0037F82C 80 9C 00 1C */ lwz r4, 0x1c(r28)
/* 803828D0 0037F830 7C 06 20 00 */ cmpw r6, r4
/* 803828D4 0037F834 40 81 FF D4 */ ble lbl_803828A8
/* 803828D8 0037F838 80 1C 00 18 */ lwz r0, 0x18(r28)
/* 803828DC 0037F83C 38 7C 00 08 */ addi r3, r28, 8
/* 803828E0 0037F840 80 BC 00 10 */ lwz r5, 0x10(r28)
/* 803828E4 0037F844 7C 80 22 14 */ add r4, r0, r4
/* 803828E8 0037F848 7C 04 33 D6 */ divw r0, r4, r6
/* 803828EC 0037F84C 7C 00 31 D6 */ mullw r0, r0, r6
/* 803828F0 0037F850 7C 00 20 50 */ subf r0, r0, r4
/* 803828F4 0037F854 54 00 10 3A */ slwi r0, r0, 2
/* 803828F8 0037F858 7F A5 01 2E */ stwx r29, r5, r0
/* 803828FC 0037F85C 80 9C 00 1C */ lwz r4, 0x1c(r28)
/* 80382900 0037F860 38 04 00 01 */ addi r0, r4, 1
/* 80382904 0037F864 90 1C 00 1C */ stw r0, 0x1c(r28)
/* 80382908 0037F868 48 00 28 F1 */ bl OSWakeupThread
/* 8038290C 0037F86C 7F C3 F3 78 */ mr r3, r30
/* 80382910 0037F870 4B FF ED 79 */ bl OSRestoreInterrupts
/* 80382914 0037F874 38 60 00 01 */ li r3, 1
lbl_80382918:
/* 80382918 0037F878 80 01 00 2C */ lwz r0, 0x2c(r1)
/* 8038291C 0037F87C 83 E1 00 24 */ lwz r31, 0x24(r1)
/* 80382920 0037F880 83 C1 00 20 */ lwz r30, 0x20(r1)
/* 80382924 0037F884 83 A1 00 1C */ lwz r29, 0x1c(r1)
/* 80382928 0037F888 83 81 00 18 */ lwz r28, 0x18(r1)
/* 8038292C 0037F88C 38 21 00 28 */ addi r1, r1, 0x28
/* 80382930 0037F890 7C 08 03 A6 */ mtlr r0
/* 80382934 0037F894 4E 80 00 20 */ blr
.global sub_80382938
sub_80382938:
/* 80382938 0037F898 7C 08 02 A6 */ mflr r0
/* 8038293C 0037F89C 90 01 00 04 */ stw r0, 4(r1)
/* 80382940 0037F8A0 94 21 FF D8 */ stwu r1, -0x28(r1)
/* 80382944 0037F8A4 93 E1 00 24 */ stw r31, 0x24(r1)
/* 80382948 0037F8A8 3B E3 00 00 */ addi r31, r3, 0
/* 8038294C 0037F8AC 93 C1 00 20 */ stw r30, 0x20(r1)
/* 80382950 0037F8B0 3B C5 00 00 */ addi r30, r5, 0
/* 80382954 0037F8B4 93 A1 00 1C */ stw r29, 0x1c(r1)
/* 80382958 0037F8B8 93 81 00 18 */ stw r28, 0x18(r1)
/* 8038295C 0037F8BC 3B 84 00 00 */ addi r28, r4, 0
/* 80382960 0037F8C0 4B FF ED 01 */ bl OSDisableInterrupts
/* 80382964 0037F8C4 3B A3 00 00 */ addi r29, r3, 0
/* 80382968 0037F8C8 57 DE 07 FE */ clrlwi r30, r30, 0x1f
/* 8038296C 0037F8CC 48 00 00 24 */ b lbl_80382990
lbl_80382970:
/* 80382970 0037F8D0 2C 1E 00 00 */ cmpwi r30, 0
/* 80382974 0037F8D4 40 82 00 14 */ bne lbl_80382988
/* 80382978 0037F8D8 7F A3 EB 78 */ mr r3, r29
/* 8038297C 0037F8DC 4B FF ED 0D */ bl OSRestoreInterrupts
/* 80382980 0037F8E0 38 60 00 00 */ li r3, 0
/* 80382984 0037F8E4 48 00 00 70 */ b lbl_803829F4
lbl_80382988:
/* 80382988 0037F8E8 38 7F 00 08 */ addi r3, r31, 8
/* 8038298C 0037F8EC 48 00 27 81 */ bl OSSleepThread
lbl_80382990:
/* 80382990 0037F8F0 80 1F 00 1C */ lwz r0, 0x1c(r31)
/* 80382994 0037F8F4 2C 00 00 00 */ cmpwi r0, 0
/* 80382998 0037F8F8 41 82 FF D8 */ beq lbl_80382970
/* 8038299C 0037F8FC 28 1C 00 00 */ cmplwi r28, 0
/* 803829A0 0037F900 41 82 00 18 */ beq lbl_803829B8
/* 803829A4 0037F904 80 1F 00 18 */ lwz r0, 0x18(r31)
/* 803829A8 0037F908 80 7F 00 10 */ lwz r3, 0x10(r31)
/* 803829AC 0037F90C 54 00 10 3A */ slwi r0, r0, 2
/* 803829B0 0037F910 7C 03 00 2E */ lwzx r0, r3, r0
/* 803829B4 0037F914 90 1C 00 00 */ stw r0, 0(r28)
lbl_803829B8:
/* 803829B8 0037F918 80 BF 00 18 */ lwz r5, 0x18(r31)
/* 803829BC 0037F91C 7F E3 FB 78 */ mr r3, r31
/* 803829C0 0037F920 80 9F 00 14 */ lwz r4, 0x14(r31)
/* 803829C4 0037F924 38 A5 00 01 */ addi r5, r5, 1
/* 803829C8 0037F928 7C 05 23 D6 */ divw r0, r5, r4
/* 803829CC 0037F92C 7C 00 21 D6 */ mullw r0, r0, r4
/* 803829D0 0037F930 7C 00 28 50 */ subf r0, r0, r5
/* 803829D4 0037F934 90 1F 00 18 */ stw r0, 0x18(r31)
/* 803829D8 0037F938 80 9F 00 1C */ lwz r4, 0x1c(r31)
/* 803829DC 0037F93C 38 04 FF FF */ addi r0, r4, -1
/* 803829E0 0037F940 90 1F 00 1C */ stw r0, 0x1c(r31)
/* 803829E4 0037F944 48 00 28 15 */ bl OSWakeupThread
/* 803829E8 0037F948 7F A3 EB 78 */ mr r3, r29
/* 803829EC 0037F94C 4B FF EC 9D */ bl OSRestoreInterrupts
/* 803829F0 0037F950 38 60 00 01 */ li r3, 1
lbl_803829F4:
/* 803829F4 0037F954 80 01 00 2C */ lwz r0, 0x2c(r1)
/* 803829F8 0037F958 83 E1 00 24 */ lwz r31, 0x24(r1)
/* 803829FC 0037F95C 83 C1 00 20 */ lwz r30, 0x20(r1)
/* 80382A00 0037F960 83 A1 00 1C */ lwz r29, 0x1c(r1)
/* 80382A04 0037F964 83 81 00 18 */ lwz r28, 0x18(r1)
/* 80382A08 0037F968 38 21 00 28 */ addi r1, r1, 0x28
/* 80382A0C 0037F96C 7C 08 03 A6 */ mtlr r0
/* 80382A10 0037F970 4E 80 00 20 */ blr
OnReset:
/* 80382A14 0037F974 7C 08 02 A6 */ mflr r0
/* 80382A18 0037F978 2C 03 00 00 */ cmpwi r3, 0

150
asm/Dolphin/os/OSMessage.s Normal file
View File

@ -0,0 +1,150 @@
.include "macros.inc"
.section .text, "ax"
.global OSInitMessageQueue
OSInitMessageQueue:
/* 80382810 0037F770 7C 08 02 A6 */ mflr r0
/* 80382814 0037F774 90 01 00 04 */ stw r0, 4(r1)
/* 80382818 0037F778 94 21 FF D8 */ stwu r1, -0x28(r1)
/* 8038281C 0037F77C 93 E1 00 24 */ stw r31, 0x24(r1)
/* 80382820 0037F780 3B E5 00 00 */ addi r31, r5, 0
/* 80382824 0037F784 93 C1 00 20 */ stw r30, 0x20(r1)
/* 80382828 0037F788 3B C4 00 00 */ addi r30, r4, 0
/* 8038282C 0037F78C 93 A1 00 1C */ stw r29, 0x1c(r1)
/* 80382830 0037F790 3B A3 00 00 */ addi r29, r3, 0
/* 80382834 0037F794 48 00 1D 91 */ bl OSInitThreadQueue
/* 80382838 0037F798 38 7D 00 08 */ addi r3, r29, 8
/* 8038283C 0037F79C 48 00 1D 89 */ bl OSInitThreadQueue
/* 80382840 0037F7A0 93 DD 00 10 */ stw r30, 0x10(r29)
/* 80382844 0037F7A4 38 00 00 00 */ li r0, 0
/* 80382848 0037F7A8 93 FD 00 14 */ stw r31, 0x14(r29)
/* 8038284C 0037F7AC 90 1D 00 18 */ stw r0, 0x18(r29)
/* 80382850 0037F7B0 90 1D 00 1C */ stw r0, 0x1c(r29)
/* 80382854 0037F7B4 80 01 00 2C */ lwz r0, 0x2c(r1)
/* 80382858 0037F7B8 83 E1 00 24 */ lwz r31, 0x24(r1)
/* 8038285C 0037F7BC 83 C1 00 20 */ lwz r30, 0x20(r1)
/* 80382860 0037F7C0 83 A1 00 1C */ lwz r29, 0x1c(r1)
/* 80382864 0037F7C4 38 21 00 28 */ addi r1, r1, 0x28
/* 80382868 0037F7C8 7C 08 03 A6 */ mtlr r0
/* 8038286C 0037F7CC 4E 80 00 20 */ blr
.global OSSendMessage
OSSendMessage:
/* 80382870 0037F7D0 7C 08 02 A6 */ mflr r0
/* 80382874 0037F7D4 90 01 00 04 */ stw r0, 4(r1)
/* 80382878 0037F7D8 94 21 FF D8 */ stwu r1, -0x28(r1)
/* 8038287C 0037F7DC 93 E1 00 24 */ stw r31, 0x24(r1)
/* 80382880 0037F7E0 3B E5 00 00 */ addi r31, r5, 0
/* 80382884 0037F7E4 93 C1 00 20 */ stw r30, 0x20(r1)
/* 80382888 0037F7E8 93 A1 00 1C */ stw r29, 0x1c(r1)
/* 8038288C 0037F7EC 3B A4 00 00 */ addi r29, r4, 0
/* 80382890 0037F7F0 93 81 00 18 */ stw r28, 0x18(r1)
/* 80382894 0037F7F4 3B 83 00 00 */ addi r28, r3, 0
/* 80382898 0037F7F8 4B FF ED C9 */ bl OSDisableInterrupts
/* 8038289C 0037F7FC 3B C3 00 00 */ addi r30, r3, 0
/* 803828A0 0037F800 57 FF 07 FE */ clrlwi r31, r31, 0x1f
/* 803828A4 0037F804 48 00 00 24 */ b lbl_803828C8
lbl_803828A8:
/* 803828A8 0037F808 2C 1F 00 00 */ cmpwi r31, 0
/* 803828AC 0037F80C 40 82 00 14 */ bne lbl_803828C0
/* 803828B0 0037F810 7F C3 F3 78 */ mr r3, r30
/* 803828B4 0037F814 4B FF ED D5 */ bl OSRestoreInterrupts
/* 803828B8 0037F818 38 60 00 00 */ li r3, 0
/* 803828BC 0037F81C 48 00 00 5C */ b lbl_80382918
lbl_803828C0:
/* 803828C0 0037F820 7F 83 E3 78 */ mr r3, r28
/* 803828C4 0037F824 48 00 28 49 */ bl OSSleepThread
lbl_803828C8:
/* 803828C8 0037F828 80 DC 00 14 */ lwz r6, 0x14(r28)
/* 803828CC 0037F82C 80 9C 00 1C */ lwz r4, 0x1c(r28)
/* 803828D0 0037F830 7C 06 20 00 */ cmpw r6, r4
/* 803828D4 0037F834 40 81 FF D4 */ ble lbl_803828A8
/* 803828D8 0037F838 80 1C 00 18 */ lwz r0, 0x18(r28)
/* 803828DC 0037F83C 38 7C 00 08 */ addi r3, r28, 8
/* 803828E0 0037F840 80 BC 00 10 */ lwz r5, 0x10(r28)
/* 803828E4 0037F844 7C 80 22 14 */ add r4, r0, r4
/* 803828E8 0037F848 7C 04 33 D6 */ divw r0, r4, r6
/* 803828EC 0037F84C 7C 00 31 D6 */ mullw r0, r0, r6
/* 803828F0 0037F850 7C 00 20 50 */ subf r0, r0, r4
/* 803828F4 0037F854 54 00 10 3A */ slwi r0, r0, 2
/* 803828F8 0037F858 7F A5 01 2E */ stwx r29, r5, r0
/* 803828FC 0037F85C 80 9C 00 1C */ lwz r4, 0x1c(r28)
/* 80382900 0037F860 38 04 00 01 */ addi r0, r4, 1
/* 80382904 0037F864 90 1C 00 1C */ stw r0, 0x1c(r28)
/* 80382908 0037F868 48 00 28 F1 */ bl OSWakeupThread
/* 8038290C 0037F86C 7F C3 F3 78 */ mr r3, r30
/* 80382910 0037F870 4B FF ED 79 */ bl OSRestoreInterrupts
/* 80382914 0037F874 38 60 00 01 */ li r3, 1
lbl_80382918:
/* 80382918 0037F878 80 01 00 2C */ lwz r0, 0x2c(r1)
/* 8038291C 0037F87C 83 E1 00 24 */ lwz r31, 0x24(r1)
/* 80382920 0037F880 83 C1 00 20 */ lwz r30, 0x20(r1)
/* 80382924 0037F884 83 A1 00 1C */ lwz r29, 0x1c(r1)
/* 80382928 0037F888 83 81 00 18 */ lwz r28, 0x18(r1)
/* 8038292C 0037F88C 38 21 00 28 */ addi r1, r1, 0x28
/* 80382930 0037F890 7C 08 03 A6 */ mtlr r0
/* 80382934 0037F894 4E 80 00 20 */ blr
.global OSReceiveMessage
OSReceiveMessage:
/* 80382938 0037F898 7C 08 02 A6 */ mflr r0
/* 8038293C 0037F89C 90 01 00 04 */ stw r0, 4(r1)
/* 80382940 0037F8A0 94 21 FF D8 */ stwu r1, -0x28(r1)
/* 80382944 0037F8A4 93 E1 00 24 */ stw r31, 0x24(r1)
/* 80382948 0037F8A8 3B E3 00 00 */ addi r31, r3, 0
/* 8038294C 0037F8AC 93 C1 00 20 */ stw r30, 0x20(r1)
/* 80382950 0037F8B0 3B C5 00 00 */ addi r30, r5, 0
/* 80382954 0037F8B4 93 A1 00 1C */ stw r29, 0x1c(r1)
/* 80382958 0037F8B8 93 81 00 18 */ stw r28, 0x18(r1)
/* 8038295C 0037F8BC 3B 84 00 00 */ addi r28, r4, 0
/* 80382960 0037F8C0 4B FF ED 01 */ bl OSDisableInterrupts
/* 80382964 0037F8C4 3B A3 00 00 */ addi r29, r3, 0
/* 80382968 0037F8C8 57 DE 07 FE */ clrlwi r30, r30, 0x1f
/* 8038296C 0037F8CC 48 00 00 24 */ b lbl_80382990
lbl_80382970:
/* 80382970 0037F8D0 2C 1E 00 00 */ cmpwi r30, 0
/* 80382974 0037F8D4 40 82 00 14 */ bne lbl_80382988
/* 80382978 0037F8D8 7F A3 EB 78 */ mr r3, r29
/* 8038297C 0037F8DC 4B FF ED 0D */ bl OSRestoreInterrupts
/* 80382980 0037F8E0 38 60 00 00 */ li r3, 0
/* 80382984 0037F8E4 48 00 00 70 */ b lbl_803829F4
lbl_80382988:
/* 80382988 0037F8E8 38 7F 00 08 */ addi r3, r31, 8
/* 8038298C 0037F8EC 48 00 27 81 */ bl OSSleepThread
lbl_80382990:
/* 80382990 0037F8F0 80 1F 00 1C */ lwz r0, 0x1c(r31)
/* 80382994 0037F8F4 2C 00 00 00 */ cmpwi r0, 0
/* 80382998 0037F8F8 41 82 FF D8 */ beq lbl_80382970
/* 8038299C 0037F8FC 28 1C 00 00 */ cmplwi r28, 0
/* 803829A0 0037F900 41 82 00 18 */ beq lbl_803829B8
/* 803829A4 0037F904 80 1F 00 18 */ lwz r0, 0x18(r31)
/* 803829A8 0037F908 80 7F 00 10 */ lwz r3, 0x10(r31)
/* 803829AC 0037F90C 54 00 10 3A */ slwi r0, r0, 2
/* 803829B0 0037F910 7C 03 00 2E */ lwzx r0, r3, r0
/* 803829B4 0037F914 90 1C 00 00 */ stw r0, 0(r28)
lbl_803829B8:
/* 803829B8 0037F918 80 BF 00 18 */ lwz r5, 0x18(r31)
/* 803829BC 0037F91C 7F E3 FB 78 */ mr r3, r31
/* 803829C0 0037F920 80 9F 00 14 */ lwz r4, 0x14(r31)
/* 803829C4 0037F924 38 A5 00 01 */ addi r5, r5, 1
/* 803829C8 0037F928 7C 05 23 D6 */ divw r0, r5, r4
/* 803829CC 0037F92C 7C 00 21 D6 */ mullw r0, r0, r4
/* 803829D0 0037F930 7C 00 28 50 */ subf r0, r0, r5
/* 803829D4 0037F934 90 1F 00 18 */ stw r0, 0x18(r31)
/* 803829D8 0037F938 80 9F 00 1C */ lwz r4, 0x1c(r31)
/* 803829DC 0037F93C 38 04 FF FF */ addi r0, r4, -1
/* 803829E0 0037F940 90 1F 00 1C */ stw r0, 0x1c(r31)
/* 803829E4 0037F944 48 00 28 15 */ bl OSWakeupThread
/* 803829E8 0037F948 7F A3 EB 78 */ mr r3, r29
/* 803829EC 0037F94C 4B FF EC 9D */ bl OSRestoreInterrupts
/* 803829F0 0037F950 38 60 00 01 */ li r3, 1
lbl_803829F4:
/* 803829F4 0037F954 80 01 00 2C */ lwz r0, 0x2c(r1)
/* 803829F8 0037F958 83 E1 00 24 */ lwz r31, 0x24(r1)
/* 803829FC 0037F95C 83 C1 00 20 */ lwz r30, 0x20(r1)
/* 80382A00 0037F960 83 A1 00 1C */ lwz r29, 0x1c(r1)
/* 80382A04 0037F964 83 81 00 18 */ lwz r28, 0x18(r1)
/* 80382A08 0037F968 38 21 00 28 */ addi r1, r1, 0x28
/* 80382A0C 0037F96C 7C 08 03 A6 */ mtlr r0
/* 80382A10 0037F970 4E 80 00 20 */ blr

View File

@ -815,6 +815,7 @@ LIBS = [
"Dolphin/os/OSFont",
["Dolphin/os/OSInterrupt", True],
["Dolphin/os/OSLink", True],
["Dolphin/os/OSMessage", True],
"Dolphin/os/OSMemory",
["Dolphin/os/OSMutex", True],
"Dolphin/os/OSReboot",

View File

@ -158,6 +158,7 @@ void OSFatal(GXColor fg, GXColor bg, const char* msg);
#include <dolphin/os/OSFastCast.h>
#include <dolphin/os/OSFont.h>
#include <dolphin/os/OSInterrupt.h>
#include <dolphin/os/OSMessage.h>
#include <dolphin/os/OSModule.h>
#include <dolphin/os/OSMutex.h>
#include <dolphin/os/OSReset.h>

View File

@ -0,0 +1,34 @@
#ifndef _DOLPHIN_OSMESSAGE
#define _DOLPHIN_OSMESSAGE
#ifdef __cplusplus
extern "C" {
#endif
#include <dolphin/os/OSThread.h>
typedef struct OSMessageQueue OSMessageQueue;
typedef void* OSMessage;
struct OSMessageQueue {
OSThreadQueue queueSend;
OSThreadQueue queueReceive;
OSMessage* msgArray;
s32 msgCount;
s32 firstIndex;
s32 usedCount;
};
// Flags to turn blocking on/off when sending/receiving message
#define OS_MESSAGE_NOBLOCK 0
#define OS_MESSAGE_BLOCK 1
void OSInitMessageQueue(OSMessageQueue* mq, OSMessage* msgArray, s32 msgCount);
BOOL OSSendMessage(OSMessageQueue* mq, OSMessage msg, s32 flags);
BOOL OSJamMessage(OSMessageQueue* mq, OSMessage msg, s32 flags);
BOOL OSReceiveMessage(OSMessageQueue* mq, OSMessage* msg, s32 flags);
#ifdef __cplusplus
}
#endif
#endif // _DOLPHIN_OSMESSAGE

View File

@ -34,4 +34,5 @@ SECTIONS
FORCEFILES
{
OSMessage.o /* How is this even in the binary? */
}

View File

@ -0,0 +1,88 @@
#include <dolphin/os.h>
void OSInitMessageQueue(OSMessageQueue* mq, OSMessage* msgArray, s32 msgCount) {
OSInitThreadQueue(&mq->queueSend);
OSInitThreadQueue(&mq->queueReceive);
mq->msgArray = msgArray;
mq->msgCount = msgCount;
mq->firstIndex = 0;
mq->usedCount = 0;
}
BOOL OSSendMessage(OSMessageQueue* mq, OSMessage msg, s32 flags) {
BOOL enabled;
s32 lastIndex;
enabled = OSDisableInterrupts();
while (mq->msgCount <= mq->usedCount) {
if (!(flags & OS_MESSAGE_BLOCK)) {
OSRestoreInterrupts(enabled);
return FALSE;
} else {
OSSleepThread(&mq->queueSend);
}
}
lastIndex = (mq->firstIndex + mq->usedCount) % mq->msgCount;
mq->msgArray[lastIndex] = msg;
mq->usedCount++;
OSWakeupThread(&mq->queueReceive);
OSRestoreInterrupts(enabled);
return TRUE;
}
BOOL OSReceiveMessage(OSMessageQueue* mq, OSMessage* msg, s32 flags) {
BOOL enabled;
enabled = OSDisableInterrupts();
while (mq->usedCount == 0) {
if (!(flags & OS_MESSAGE_BLOCK)) {
OSRestoreInterrupts(enabled);
return FALSE;
} else {
OSSleepThread(&mq->queueReceive);
}
}
if (msg != NULL) {
*msg = mq->msgArray[mq->firstIndex];
}
mq->firstIndex = (mq->firstIndex + 1) % mq->msgCount;
mq->usedCount--;
OSWakeupThread(&mq->queueSend);
OSRestoreInterrupts(enabled);
return TRUE;
}
#if 0
BOOL OSJamMessage(OSMessageQueue* mq, OSMessage msg, s32 flags) {
BOOL enabled;
enabled = OSDisableInterrupts();
while (mq->msgCount <= mq->usedCount)
{
if (!(flags & OS_MESSAGE_BLOCK)) {
OSRestoreInterrupts(enabled);
return FALSE;
} else {
OSSleepThread(&mq->queueSend);
}
}
mq->firstIndex = (mq->firstIndex + mq->msgCount - 1) % mq->msgCount;
mq->msgArray[mq->firstIndex] = msg;
mq->usedCount++;
OSWakeupThread(&mq->queueReceive);
OSRestoreInterrupts(enabled);
return TRUE;
}
#endif