From 637de45b403284c472cbf8e02aad1e5f049ec69e Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Tue, 11 Oct 2022 20:18:01 -0700 Subject: [PATCH] Match COutputStream::FlushShiftRegister, start DoFlush/WriteBits Former-commit-id: 9510f70f9dbcd763dd4026efff72d490ad649306 --- asm/Kyoto/Streams/COutputStream.s | 4 +- asm/MetroidPrime/CMapWorldInfo.s | 13 ++--- asm/MetroidPrime/CScriptMailbox.s | 3 +- asm/MetroidPrime/Player/CGameHintInfo.s | 5 +- asm/MetroidPrime/Player/CGameOptions.s | 31 +++++----- asm/MetroidPrime/Player/CGameState.s | 44 +++++++------- asm/MetroidPrime/Player/CPlayerState.s | 18 +++--- asm/MetroidPrime/Player/CWorldLayerState.s | 4 +- asm/MetroidPrime/main.s | 8 +-- include/Kyoto/Streams/COutputStream.hpp | 12 ++-- src/Kyoto/Streams/COutputStream.cpp | 68 ++++++++++++++++------ 11 files changed, 119 insertions(+), 91 deletions(-) diff --git a/asm/Kyoto/Streams/COutputStream.s b/asm/Kyoto/Streams/COutputStream.s index bd65f464..74cdd75e 100644 --- a/asm/Kyoto/Streams/COutputStream.s +++ b/asm/Kyoto/Streams/COutputStream.s @@ -13,8 +13,8 @@ __vt__13COutputStream: .section .text, "ax" -.global WriteBits__13COutputStreamFii -WriteBits__13COutputStreamFii: +.global WriteBits__13COutputStreamFUiUi +WriteBits__13COutputStreamFUiUi: /* 8033F3BC 0033C31C 94 21 FF E0 */ stwu r1, -0x20(r1) /* 8033F3C0 0033C320 7C 08 02 A6 */ mflr r0 /* 8033F3C4 0033C324 90 01 00 24 */ stw r0, 0x24(r1) diff --git a/asm/MetroidPrime/CMapWorldInfo.s b/asm/MetroidPrime/CMapWorldInfo.s index 0c592b4c..30d24b42 100644 --- a/asm/MetroidPrime/CMapWorldInfo.s +++ b/asm/MetroidPrime/CMapWorldInfo.s @@ -1156,13 +1156,13 @@ lbl_80168BD0: /* 80168C2C 00165B8C 90 E1 00 58 */ stw r7, 0x58(r1) /* 80168C30 00165B90 54 04 0F FE */ srwi r4, r0, 0x1f /* 80168C34 00165B94 90 C1 00 5C */ stw r6, 0x5c(r1) -/* 80168C38 00165B98 48 1D 67 85 */ bl WriteBits__13COutputStreamFii +/* 80168C38 00165B98 48 1D 67 85 */ bl WriteBits__13COutputStreamFUiUi /* 80168C3C 00165B9C 48 00 00 14 */ b lbl_80168C50 lbl_80168C40: /* 80168C40 00165BA0 7F 83 E3 78 */ mr r3, r28 /* 80168C44 00165BA4 38 80 00 00 */ li r4, 0 /* 80168C48 00165BA8 38 A0 00 01 */ li r5, 1 -/* 80168C4C 00165BAC 48 1D 67 71 */ bl WriteBits__13COutputStreamFii +/* 80168C4C 00165BAC 48 1D 67 71 */ bl WriteBits__13COutputStreamFUiUi lbl_80168C50: /* 80168C50 00165BB0 3B DE 00 01 */ addi r30, r30, 1 lbl_80168C54: @@ -1197,13 +1197,13 @@ lbl_80168C64: /* 80168CC0 00165C20 90 E1 00 50 */ stw r7, 0x50(r1) /* 80168CC4 00165C24 54 04 0F FE */ srwi r4, r0, 0x1f /* 80168CC8 00165C28 90 C1 00 54 */ stw r6, 0x54(r1) -/* 80168CCC 00165C2C 48 1D 66 F1 */ bl WriteBits__13COutputStreamFii +/* 80168CCC 00165C2C 48 1D 66 F1 */ bl WriteBits__13COutputStreamFUiUi /* 80168CD0 00165C30 48 00 00 14 */ b lbl_80168CE4 lbl_80168CD4: /* 80168CD4 00165C34 7F 83 E3 78 */ mr r3, r28 /* 80168CD8 00165C38 38 80 00 00 */ li r4, 0 /* 80168CDC 00165C3C 38 A0 00 01 */ li r5, 1 -/* 80168CE0 00165C40 48 1D 66 DD */ bl WriteBits__13COutputStreamFii +/* 80168CE0 00165C40 48 1D 66 DD */ bl WriteBits__13COutputStreamFUiUi lbl_80168CE4: /* 80168CE4 00165C44 3B DE 00 01 */ addi r30, r30, 1 lbl_80168CE8: @@ -1278,7 +1278,7 @@ lbl_80168D98: /* 80168DE8 00165D48 90 E1 00 40 */ stw r7, 0x40(r1) /* 80168DEC 00165D4C 54 04 0F FE */ srwi r4, r0, 0x1f /* 80168DF0 00165D50 90 C1 00 44 */ stw r6, 0x44(r1) -/* 80168DF4 00165D54 48 1D 65 C9 */ bl WriteBits__13COutputStreamFii +/* 80168DF4 00165D54 48 1D 65 C9 */ bl WriteBits__13COutputStreamFUiUi /* 80168DF8 00165D58 3B DE 00 01 */ addi r30, r30, 1 lbl_80168DFC: /* 80168DFC 00165D5C 80 01 00 60 */ lwz r0, 0x60(r1) @@ -1290,7 +1290,7 @@ lbl_80168DFC: /* 80168E14 00165D74 7C 04 00 D0 */ neg r0, r4 /* 80168E18 00165D78 7C 00 23 78 */ or r0, r0, r4 /* 80168E1C 00165D7C 54 04 0F FE */ srwi r4, r0, 0x1f -/* 80168E20 00165D80 48 1D 65 9D */ bl WriteBits__13COutputStreamFii +/* 80168E20 00165D80 48 1D 65 9D */ bl WriteBits__13COutputStreamFUiUi /* 80168E24 00165D84 80 01 00 68 */ lwz r0, 0x68(r1) /* 80168E28 00165D88 80 61 00 70 */ lwz r3, 0x70(r1) /* 80168E2C 00165D8C 54 00 10 3A */ slwi r0, r0, 2 @@ -2090,4 +2090,3 @@ lbl_803D0428: # ROM: 0x3CD428 .asciz "??(??)" .balign 4 - diff --git a/asm/MetroidPrime/CScriptMailbox.s b/asm/MetroidPrime/CScriptMailbox.s index eaf486ef..17d8b7fb 100644 --- a/asm/MetroidPrime/CScriptMailbox.s +++ b/asm/MetroidPrime/CScriptMailbox.s @@ -275,7 +275,7 @@ lbl_800E1D8C: /* 800E1D98 000DECF8 7C 04 00 D0 */ neg r0, r4 /* 800E1D9C 000DECFC 7C 00 23 78 */ or r0, r0, r4 /* 800E1DA0 000DED00 54 04 0F FE */ srwi r4, r0, 0x1f -/* 800E1DA4 000DED04 48 25 D6 19 */ bl WriteBits__13COutputStreamFii +/* 800E1DA4 000DED04 48 25 D6 19 */ bl WriteBits__13COutputStreamFUiUi /* 800E1DA8 000DED08 3B 9C 00 01 */ addi r28, r28, 1 /* 800E1DAC 000DED0C 3B BD 00 01 */ addi r29, r29, 1 lbl_800E1DB0: @@ -493,4 +493,3 @@ lbl_803CE5C0: # ROM: 0x3CB5C0 .asciz "??(??)" .balign 4 - diff --git a/asm/MetroidPrime/Player/CGameHintInfo.s b/asm/MetroidPrime/Player/CGameHintInfo.s index 52558a34..4f6a94a5 100644 --- a/asm/MetroidPrime/Player/CGameHintInfo.s +++ b/asm/MetroidPrime/Player/CGameHintInfo.s @@ -841,11 +841,11 @@ lbl_80267C20: /* 80267C28 00264B88 80 9F 00 00 */ lwz r4, 0(r31) /* 80267C2C 00264B8C 7C 65 1B 78 */ mr r5, r3 /* 80267C30 00264B90 7F C3 F3 78 */ mr r3, r30 -/* 80267C34 00264B94 48 0D 77 89 */ bl WriteBits__13COutputStreamFii +/* 80267C34 00264B94 48 0D 77 89 */ bl WriteBits__13COutputStreamFUiUi /* 80267C38 00264B98 80 9F 00 04 */ lwz r4, 4(r31) /* 80267C3C 00264B9C 7F C3 F3 78 */ mr r3, r30 /* 80267C40 00264BA0 38 A0 00 20 */ li r5, 0x20 -/* 80267C44 00264BA4 48 0D 77 79 */ bl WriteBits__13COutputStreamFii +/* 80267C44 00264BA4 48 0D 77 79 */ bl WriteBits__13COutputStreamFUiUi /* 80267C48 00264BA8 3B FF 00 0C */ addi r31, r31, 0xc lbl_80267C4C: /* 80267C4C 00264BAC 80 1D 00 04 */ lwz r0, 4(r29) @@ -1576,4 +1576,3 @@ lbl_803D53C0: # ROM: 0x3D23C0 .asciz "??(??)" .balign 4 - diff --git a/asm/MetroidPrime/Player/CGameOptions.s b/asm/MetroidPrime/Player/CGameOptions.s index 1f9bda6c..8128236b 100644 --- a/asm/MetroidPrime/Player/CGameOptions.s +++ b/asm/MetroidPrime/Player/CGameOptions.s @@ -866,7 +866,7 @@ lbl_8020F2BC: /* 8020F2C0 0020C220 7F E3 FB 78 */ mr r3, r31 /* 8020F2C4 0020C224 88 84 00 04 */ lbz r4, 4(r4) /* 8020F2C8 0020C228 38 A0 00 08 */ li r5, 8 -/* 8020F2CC 0020C22C 48 13 00 F1 */ bl WriteBits__13COutputStreamFii +/* 8020F2CC 0020C22C 48 13 00 F1 */ bl WriteBits__13COutputStreamFUiUi /* 8020F2D0 0020C230 3B BD 00 01 */ addi r29, r29, 1 lbl_8020F2D4: /* 8020F2D4 0020C234 80 1E 00 00 */ lwz r0, 0(r30) @@ -878,14 +878,14 @@ lbl_8020F2D4: /* 8020F2EC 0020C24C 7C 65 1B 78 */ mr r5, r3 /* 8020F2F0 0020C250 7F E3 FB 78 */ mr r3, r31 /* 8020F2F4 0020C254 7F A4 EB 78 */ mr r4, r29 -/* 8020F2F8 0020C258 48 13 00 C5 */ bl WriteBits__13COutputStreamFii +/* 8020F2F8 0020C258 48 13 00 C5 */ bl WriteBits__13COutputStreamFUiUi /* 8020F2FC 0020C25C 83 BE 00 48 */ lwz r29, 0x48(r30) /* 8020F300 0020C260 38 60 00 08 */ li r3, 8 /* 8020F304 0020C264 48 00 06 7D */ bl CalculateBits__Fi /* 8020F308 0020C268 7C 65 1B 78 */ mr r5, r3 /* 8020F30C 0020C26C 7F E3 FB 78 */ mr r3, r31 /* 8020F310 0020C270 7F A4 EB 78 */ mr r4, r29 -/* 8020F314 0020C274 48 13 00 A9 */ bl WriteBits__13COutputStreamFii +/* 8020F314 0020C274 48 13 00 A9 */ bl WriteBits__13COutputStreamFUiUi /* 8020F318 0020C278 80 9E 00 4C */ lwz r4, 0x4c(r30) /* 8020F31C 0020C27C 38 60 00 3C */ li r3, 0x3c /* 8020F320 0020C280 3B A4 00 1E */ addi r29, r4, 0x1e @@ -893,7 +893,7 @@ lbl_8020F2D4: /* 8020F328 0020C288 7C 65 1B 78 */ mr r5, r3 /* 8020F32C 0020C28C 7F E3 FB 78 */ mr r3, r31 /* 8020F330 0020C290 7F A4 EB 78 */ mr r4, r29 -/* 8020F334 0020C294 48 13 00 89 */ bl WriteBits__13COutputStreamFii +/* 8020F334 0020C294 48 13 00 89 */ bl WriteBits__13COutputStreamFUiUi /* 8020F338 0020C298 80 9E 00 50 */ lwz r4, 0x50(r30) /* 8020F33C 0020C29C 38 60 00 3C */ li r3, 0x3c /* 8020F340 0020C2A0 3B A4 00 1E */ addi r29, r4, 0x1e @@ -901,7 +901,7 @@ lbl_8020F2D4: /* 8020F348 0020C2A8 7C 65 1B 78 */ mr r5, r3 /* 8020F34C 0020C2AC 7F E3 FB 78 */ mr r3, r31 /* 8020F350 0020C2B0 7F A4 EB 78 */ mr r4, r29 -/* 8020F354 0020C2B4 48 13 00 69 */ bl WriteBits__13COutputStreamFii +/* 8020F354 0020C2B4 48 13 00 69 */ bl WriteBits__13COutputStreamFUiUi /* 8020F358 0020C2B8 80 9E 00 54 */ lwz r4, 0x54(r30) /* 8020F35C 0020C2BC 38 60 00 14 */ li r3, 0x14 /* 8020F360 0020C2C0 3B A4 00 0A */ addi r29, r4, 0xa @@ -909,35 +909,35 @@ lbl_8020F2D4: /* 8020F368 0020C2C8 7C 65 1B 78 */ mr r5, r3 /* 8020F36C 0020C2CC 7F E3 FB 78 */ mr r3, r31 /* 8020F370 0020C2D0 7F A4 EB 78 */ mr r4, r29 -/* 8020F374 0020C2D4 48 13 00 49 */ bl WriteBits__13COutputStreamFii +/* 8020F374 0020C2D4 48 13 00 49 */ bl WriteBits__13COutputStreamFUiUi /* 8020F378 0020C2D8 83 BE 00 58 */ lwz r29, 0x58(r30) /* 8020F37C 0020C2DC 38 60 00 7F */ li r3, 0x7f /* 8020F380 0020C2E0 48 00 06 01 */ bl CalculateBits__Fi /* 8020F384 0020C2E4 7C 65 1B 78 */ mr r5, r3 /* 8020F388 0020C2E8 7F E3 FB 78 */ mr r3, r31 /* 8020F38C 0020C2EC 7F A4 EB 78 */ mr r4, r29 -/* 8020F390 0020C2F0 48 13 00 2D */ bl WriteBits__13COutputStreamFii +/* 8020F390 0020C2F0 48 13 00 2D */ bl WriteBits__13COutputStreamFUiUi /* 8020F394 0020C2F4 83 BE 00 5C */ lwz r29, 0x5c(r30) /* 8020F398 0020C2F8 38 60 00 7F */ li r3, 0x7f /* 8020F39C 0020C2FC 48 00 05 E5 */ bl CalculateBits__Fi /* 8020F3A0 0020C300 7C 65 1B 78 */ mr r5, r3 /* 8020F3A4 0020C304 7F E3 FB 78 */ mr r3, r31 /* 8020F3A8 0020C308 7F A4 EB 78 */ mr r4, r29 -/* 8020F3AC 0020C30C 48 13 00 11 */ bl WriteBits__13COutputStreamFii +/* 8020F3AC 0020C30C 48 13 00 11 */ bl WriteBits__13COutputStreamFUiUi /* 8020F3B0 0020C310 83 BE 00 60 */ lwz r29, 0x60(r30) /* 8020F3B4 0020C314 38 60 00 FF */ li r3, 0xff /* 8020F3B8 0020C318 48 00 05 C9 */ bl CalculateBits__Fi /* 8020F3BC 0020C31C 7C 65 1B 78 */ mr r5, r3 /* 8020F3C0 0020C320 7F E3 FB 78 */ mr r3, r31 /* 8020F3C4 0020C324 7F A4 EB 78 */ mr r4, r29 -/* 8020F3C8 0020C328 48 12 FF F5 */ bl WriteBits__13COutputStreamFii +/* 8020F3C8 0020C328 48 12 FF F5 */ bl WriteBits__13COutputStreamFUiUi /* 8020F3CC 0020C32C 83 BE 00 64 */ lwz r29, 0x64(r30) /* 8020F3D0 0020C330 38 60 00 FF */ li r3, 0xff /* 8020F3D4 0020C334 48 00 05 AD */ bl CalculateBits__Fi /* 8020F3D8 0020C338 7C 65 1B 78 */ mr r5, r3 /* 8020F3DC 0020C33C 7F E3 FB 78 */ mr r3, r31 /* 8020F3E0 0020C340 7F A4 EB 78 */ mr r4, r29 -/* 8020F3E4 0020C344 48 12 FF D9 */ bl WriteBits__13COutputStreamFii +/* 8020F3E4 0020C344 48 12 FF D9 */ bl WriteBits__13COutputStreamFUiUi /* 8020F3E8 0020C348 88 1E 00 68 */ lbz r0, 0x68(r30) /* 8020F3EC 0020C34C 7F E3 FB 78 */ mr r3, r31 /* 8020F3F0 0020C350 38 A0 00 01 */ li r5, 1 @@ -945,7 +945,7 @@ lbl_8020F2D4: /* 8020F3F8 0020C358 7C 04 00 D0 */ neg r0, r4 /* 8020F3FC 0020C35C 7C 00 23 78 */ or r0, r0, r4 /* 8020F400 0020C360 54 04 0F FE */ srwi r4, r0, 0x1f -/* 8020F404 0020C364 48 12 FF B9 */ bl WriteBits__13COutputStreamFii +/* 8020F404 0020C364 48 12 FF B9 */ bl WriteBits__13COutputStreamFUiUi /* 8020F408 0020C368 88 1E 00 68 */ lbz r0, 0x68(r30) /* 8020F40C 0020C36C 7F E3 FB 78 */ mr r3, r31 /* 8020F410 0020C370 38 A0 00 01 */ li r5, 1 @@ -953,7 +953,7 @@ lbl_8020F2D4: /* 8020F418 0020C378 7C 04 00 D0 */ neg r0, r4 /* 8020F41C 0020C37C 7C 00 23 78 */ or r0, r0, r4 /* 8020F420 0020C380 54 04 0F FE */ srwi r4, r0, 0x1f -/* 8020F424 0020C384 48 12 FF 99 */ bl WriteBits__13COutputStreamFii +/* 8020F424 0020C384 48 12 FF 99 */ bl WriteBits__13COutputStreamFUiUi /* 8020F428 0020C388 88 1E 00 68 */ lbz r0, 0x68(r30) /* 8020F42C 0020C38C 7F E3 FB 78 */ mr r3, r31 /* 8020F430 0020C390 38 A0 00 01 */ li r5, 1 @@ -961,7 +961,7 @@ lbl_8020F2D4: /* 8020F438 0020C398 7C 04 00 D0 */ neg r0, r4 /* 8020F43C 0020C39C 7C 00 23 78 */ or r0, r0, r4 /* 8020F440 0020C3A0 54 04 0F FE */ srwi r4, r0, 0x1f -/* 8020F444 0020C3A4 48 12 FF 79 */ bl WriteBits__13COutputStreamFii +/* 8020F444 0020C3A4 48 12 FF 79 */ bl WriteBits__13COutputStreamFUiUi /* 8020F448 0020C3A8 88 1E 00 68 */ lbz r0, 0x68(r30) /* 8020F44C 0020C3AC 7F E3 FB 78 */ mr r3, r31 /* 8020F450 0020C3B0 38 A0 00 01 */ li r5, 1 @@ -969,7 +969,7 @@ lbl_8020F2D4: /* 8020F458 0020C3B8 7C 04 00 D0 */ neg r0, r4 /* 8020F45C 0020C3BC 7C 00 23 78 */ or r0, r0, r4 /* 8020F460 0020C3C0 54 04 0F FE */ srwi r4, r0, 0x1f -/* 8020F464 0020C3C4 48 12 FF 59 */ bl WriteBits__13COutputStreamFii +/* 8020F464 0020C3C4 48 12 FF 59 */ bl WriteBits__13COutputStreamFUiUi /* 8020F468 0020C3C8 88 1E 00 68 */ lbz r0, 0x68(r30) /* 8020F46C 0020C3CC 7F E3 FB 78 */ mr r3, r31 /* 8020F470 0020C3D0 38 A0 00 01 */ li r5, 1 @@ -977,7 +977,7 @@ lbl_8020F2D4: /* 8020F478 0020C3D8 7C 04 00 D0 */ neg r0, r4 /* 8020F47C 0020C3DC 7C 00 23 78 */ or r0, r0, r4 /* 8020F480 0020C3E0 54 04 0F FE */ srwi r4, r0, 0x1f -/* 8020F484 0020C3E4 48 12 FF 39 */ bl WriteBits__13COutputStreamFii +/* 8020F484 0020C3E4 48 12 FF 39 */ bl WriteBits__13COutputStreamFUiUi /* 8020F488 0020C3E8 80 01 00 24 */ lwz r0, 0x24(r1) /* 8020F48C 0020C3EC 83 E1 00 1C */ lwz r31, 0x1c(r1) /* 8020F490 0020C3F0 83 C1 00 18 */ lwz r30, 0x18(r1) @@ -1589,4 +1589,3 @@ lbl_805ACF60: # ROM: 0x3F9800 .float 0.25 .4byte 0 - diff --git a/asm/MetroidPrime/Player/CGameState.s b/asm/MetroidPrime/Player/CGameState.s index fe954758..ccea3ffc 100644 --- a/asm/MetroidPrime/Player/CGameState.s +++ b/asm/MetroidPrime/Player/CGameState.s @@ -694,7 +694,7 @@ lbl_801D40A8: /* 801D40AC 001D100C 7F E3 FB 78 */ mr r3, r31 /* 801D40B0 001D1010 88 84 00 04 */ lbz r4, 4(r4) /* 801D40B4 001D1014 38 A0 00 08 */ li r5, 8 -/* 801D40B8 001D1018 48 16 B3 05 */ bl WriteBits__13COutputStreamFii +/* 801D40B8 001D1018 48 16 B3 05 */ bl WriteBits__13COutputStreamFUiUi /* 801D40BC 001D101C 3B 5A 00 01 */ addi r26, r26, 1 lbl_801D40C0: /* 801D40C0 001D1020 80 1E 00 00 */ lwz r0, 0(r30) @@ -708,7 +708,7 @@ lbl_801D40C0: /* 801D40E0 001D1040 48 1B 5A ED */ bl __div2i /* 801D40E4 001D1044 7F E3 FB 78 */ mr r3, r31 /* 801D40E8 001D1048 38 A0 00 20 */ li r5, 0x20 -/* 801D40EC 001D104C 48 16 B2 D1 */ bl WriteBits__13COutputStreamFii +/* 801D40EC 001D104C 48 16 B2 D1 */ bl WriteBits__13COutputStreamFUiUi /* 801D40F0 001D1050 88 1E 02 28 */ lbz r0, 0x228(r30) /* 801D40F4 001D1054 7F E3 FB 78 */ mr r3, r31 /* 801D40F8 001D1058 38 A0 00 01 */ li r5, 1 @@ -716,7 +716,7 @@ lbl_801D40C0: /* 801D4100 001D1060 7C 04 00 D0 */ neg r0, r4 /* 801D4104 001D1064 7C 00 23 78 */ or r0, r0, r4 /* 801D4108 001D1068 54 04 0F FE */ srwi r4, r0, 0x1f -/* 801D410C 001D106C 48 16 B2 B1 */ bl WriteBits__13COutputStreamFii +/* 801D410C 001D106C 48 16 B2 B1 */ bl WriteBits__13COutputStreamFUiUi /* 801D4110 001D1070 88 1E 02 28 */ lbz r0, 0x228(r30) /* 801D4114 001D1074 7F E3 FB 78 */ mr r3, r31 /* 801D4118 001D1078 38 A0 00 01 */ li r5, 1 @@ -724,21 +724,21 @@ lbl_801D40C0: /* 801D4120 001D1080 7C 04 00 D0 */ neg r0, r4 /* 801D4124 001D1084 7C 00 23 78 */ or r0, r0, r4 /* 801D4128 001D1088 54 04 0F FE */ srwi r4, r0, 0x1f -/* 801D412C 001D108C 48 16 B2 91 */ bl WriteBits__13COutputStreamFii +/* 801D412C 001D108C 48 16 B2 91 */ bl WriteBits__13COutputStreamFUiUi /* 801D4130 001D1090 80 9E 00 84 */ lwz r4, 0x84(r30) /* 801D4134 001D1094 7F E3 FB 78 */ mr r3, r31 /* 801D4138 001D1098 38 A0 00 20 */ li r5, 0x20 -/* 801D413C 001D109C 48 16 B2 81 */ bl WriteBits__13COutputStreamFii +/* 801D413C 001D109C 48 16 B2 81 */ bl WriteBits__13COutputStreamFUiUi /* 801D4140 001D10A0 80 9E 00 A0 */ lwz r4, 0xa0(r30) /* 801D4144 001D10A4 7F E3 FB 78 */ mr r3, r31 /* 801D4148 001D10A8 83 7E 00 A4 */ lwz r27, 0xa4(r30) /* 801D414C 001D10AC 38 A0 00 20 */ li r5, 0x20 -/* 801D4150 001D10B0 48 16 B2 6D */ bl WriteBits__13COutputStreamFii +/* 801D4150 001D10B0 48 16 B2 6D */ bl WriteBits__13COutputStreamFUiUi /* 801D4154 001D10B4 38 00 FF FF */ li r0, -1 /* 801D4158 001D10B8 7F E3 FB 78 */ mr r3, r31 /* 801D415C 001D10BC 38 A0 00 20 */ li r5, 0x20 /* 801D4160 001D10C0 7F 64 00 38 */ and r4, r27, r0 -/* 801D4164 001D10C4 48 16 B2 59 */ bl WriteBits__13COutputStreamFii +/* 801D4164 001D10C4 48 16 B2 59 */ bl WriteBits__13COutputStreamFUiUi /* 801D4168 001D10C8 80 7E 00 98 */ lwz r3, 0x98(r30) /* 801D416C 001D10CC 7F E4 FB 78 */ mr r4, r31 /* 801D4170 001D10D0 80 63 00 00 */ lwz r3, 0(r3) @@ -1639,11 +1639,11 @@ PutTo__11CWorldStateFR16CMemoryStreamOut: /* 801D4DBC 001D1D1C 7C 7D 1B 78 */ mr r29, r3 /* 801D4DC0 001D1D20 80 83 00 04 */ lwz r4, 4(r3) /* 801D4DC4 001D1D24 7F C3 F3 78 */ mr r3, r30 -/* 801D4DC8 001D1D28 48 16 A5 F5 */ bl WriteBits__13COutputStreamFii +/* 801D4DC8 001D1D28 48 16 A5 F5 */ bl WriteBits__13COutputStreamFUiUi /* 801D4DCC 001D1D2C 80 9D 00 10 */ lwz r4, 0x10(r29) /* 801D4DD0 001D1D30 7F C3 F3 78 */ mr r3, r30 /* 801D4DD4 001D1D34 38 A0 00 20 */ li r5, 0x20 -/* 801D4DD8 001D1D38 48 16 A5 E5 */ bl WriteBits__13COutputStreamFii +/* 801D4DD8 001D1D38 48 16 A5 E5 */ bl WriteBits__13COutputStreamFUiUi /* 801D4DDC 001D1D3C 80 7D 00 08 */ lwz r3, 8(r29) /* 801D4DE0 001D1D40 7F C4 F3 78 */ mr r4, r30 /* 801D4DE4 001D1D44 7F E5 FB 78 */ mr r5, r31 @@ -2250,7 +2250,7 @@ lbl_801D55AC: /* 801D55B0 001D2510 7E E3 BB 78 */ mr r3, r23 /* 801D55B4 001D2514 88 84 00 04 */ lbz r4, 4(r4) /* 801D55B8 001D2518 38 A0 00 08 */ li r5, 8 -/* 801D55BC 001D251C 48 16 9E 01 */ bl WriteBits__13COutputStreamFii +/* 801D55BC 001D251C 48 16 9E 01 */ bl WriteBits__13COutputStreamFUiUi /* 801D55C0 001D2520 3A 94 00 01 */ addi r20, r20, 1 /* 801D55C4 001D2524 2C 14 00 62 */ cmpwi r20, 0x62 /* 801D55C8 001D2528 41 80 FF E4 */ blt lbl_801D55AC @@ -2260,7 +2260,7 @@ lbl_801D55D4: /* 801D55D4 001D2534 88 94 00 00 */ lbz r4, 0(r20) /* 801D55D8 001D2538 7E E3 BB 78 */ mr r3, r23 /* 801D55DC 001D253C 38 A0 00 08 */ li r5, 8 -/* 801D55E0 001D2540 48 16 9D DD */ bl WriteBits__13COutputStreamFii +/* 801D55E0 001D2540 48 16 9D DD */ bl WriteBits__13COutputStreamFUiUi /* 801D55E4 001D2544 3A B5 00 01 */ addi r21, r21, 1 /* 801D55E8 001D2548 3A 94 00 01 */ addi r20, r20, 1 /* 801D55EC 001D254C 2C 15 00 40 */ cmpwi r21, 0x40 @@ -2270,25 +2270,25 @@ lbl_801D55D4: /* 801D55FC 001D255C 80 96 00 C0 */ lwz r4, 0xc0(r22) /* 801D5600 001D2560 7C 65 1B 78 */ mr r5, r3 /* 801D5604 001D2564 7E E3 BB 78 */ mr r3, r23 -/* 801D5608 001D2568 48 16 9D B5 */ bl WriteBits__13COutputStreamFii +/* 801D5608 001D2568 48 16 9D B5 */ bl WriteBits__13COutputStreamFUiUi /* 801D560C 001D256C 38 60 00 03 */ li r3, 3 /* 801D5610 001D2570 48 00 0A A1 */ bl sub_801d60b0 /* 801D5614 001D2574 80 96 00 C4 */ lwz r4, 0xc4(r22) /* 801D5618 001D2578 7C 65 1B 78 */ mr r5, r3 /* 801D561C 001D257C 7E E3 BB 78 */ mr r3, r23 -/* 801D5620 001D2580 48 16 9D 9D */ bl WriteBits__13COutputStreamFii +/* 801D5620 001D2580 48 16 9D 9D */ bl WriteBits__13COutputStreamFUiUi /* 801D5624 001D2584 38 60 00 01 */ li r3, 1 /* 801D5628 001D2588 48 00 0A 89 */ bl sub_801d60b0 /* 801D562C 001D258C 80 96 00 C8 */ lwz r4, 0xc8(r22) /* 801D5630 001D2590 7C 65 1B 78 */ mr r5, r3 /* 801D5634 001D2594 7E E3 BB 78 */ mr r3, r23 -/* 801D5638 001D2598 48 16 9D 85 */ bl WriteBits__13COutputStreamFii +/* 801D5638 001D2598 48 16 9D 85 */ bl WriteBits__13COutputStreamFUiUi /* 801D563C 001D259C 38 60 00 64 */ li r3, 0x64 /* 801D5640 001D25A0 48 00 0A 71 */ bl sub_801d60b0 /* 801D5644 001D25A4 80 96 00 CC */ lwz r4, 0xcc(r22) /* 801D5648 001D25A8 7C 65 1B 78 */ mr r5, r3 /* 801D564C 001D25AC 7E E3 BB 78 */ mr r3, r23 -/* 801D5650 001D25B0 48 16 9D 6D */ bl WriteBits__13COutputStreamFii +/* 801D5650 001D25B0 48 16 9D 6D */ bl WriteBits__13COutputStreamFUiUi /* 801D5654 001D25B4 88 16 00 D0 */ lbz r0, 0xd0(r22) /* 801D5658 001D25B8 7E E3 BB 78 */ mr r3, r23 /* 801D565C 001D25BC 38 A0 00 01 */ li r5, 1 @@ -2296,7 +2296,7 @@ lbl_801D55D4: /* 801D5664 001D25C4 7C 04 00 D0 */ neg r0, r4 /* 801D5668 001D25C8 7C 00 23 78 */ or r0, r0, r4 /* 801D566C 001D25CC 54 04 0F FE */ srwi r4, r0, 0x1f -/* 801D5670 001D25D0 48 16 9D 4D */ bl WriteBits__13COutputStreamFii +/* 801D5670 001D25D0 48 16 9D 4D */ bl WriteBits__13COutputStreamFUiUi /* 801D5674 001D25D4 88 16 00 D0 */ lbz r0, 0xd0(r22) /* 801D5678 001D25D8 7E E3 BB 78 */ mr r3, r23 /* 801D567C 001D25DC 38 A0 00 01 */ li r5, 1 @@ -2304,7 +2304,7 @@ lbl_801D55D4: /* 801D5684 001D25E4 7C 04 00 D0 */ neg r0, r4 /* 801D5688 001D25E8 7C 00 23 78 */ or r0, r0, r4 /* 801D568C 001D25EC 54 04 0F FE */ srwi r4, r0, 0x1f -/* 801D5690 001D25F0 48 16 9D 2D */ bl WriteBits__13COutputStreamFii +/* 801D5690 001D25F0 48 16 9D 2D */ bl WriteBits__13COutputStreamFUiUi /* 801D5694 001D25F4 88 16 00 D0 */ lbz r0, 0xd0(r22) /* 801D5698 001D25F8 7E E3 BB 78 */ mr r3, r23 /* 801D569C 001D25FC 38 A0 00 01 */ li r5, 1 @@ -2312,7 +2312,7 @@ lbl_801D55D4: /* 801D56A4 001D2604 7C 04 00 D0 */ neg r0, r4 /* 801D56A8 001D2608 7C 00 23 78 */ or r0, r0, r4 /* 801D56AC 001D260C 54 04 0F FE */ srwi r4, r0, 0x1f -/* 801D56B0 001D2610 48 16 9D 0D */ bl WriteBits__13COutputStreamFii +/* 801D56B0 001D2610 48 16 9D 0D */ bl WriteBits__13COutputStreamFUiUi /* 801D56B4 001D2614 88 16 00 D0 */ lbz r0, 0xd0(r22) /* 801D56B8 001D2618 7E E3 BB 78 */ mr r3, r23 /* 801D56BC 001D261C 38 A0 00 01 */ li r5, 1 @@ -2320,7 +2320,7 @@ lbl_801D55D4: /* 801D56C4 001D2624 7C 04 00 D0 */ neg r0, r4 /* 801D56C8 001D2628 7C 00 23 78 */ or r0, r0, r4 /* 801D56CC 001D262C 54 04 0F FE */ srwi r4, r0, 0x1f -/* 801D56D0 001D2630 48 16 9C ED */ bl WriteBits__13COutputStreamFii +/* 801D56D0 001D2630 48 16 9C ED */ bl WriteBits__13COutputStreamFUiUi /* 801D56D4 001D2634 88 16 00 D0 */ lbz r0, 0xd0(r22) /* 801D56D8 001D2638 7E E3 BB 78 */ mr r3, r23 /* 801D56DC 001D263C 38 A0 00 01 */ li r5, 1 @@ -2328,11 +2328,11 @@ lbl_801D55D4: /* 801D56E4 001D2644 7C 04 00 D0 */ neg r0, r4 /* 801D56E8 001D2648 7C 00 23 78 */ or r0, r0, r4 /* 801D56EC 001D264C 54 04 0F FE */ srwi r4, r0, 0x1f -/* 801D56F0 001D2650 48 16 9C CD */ bl WriteBits__13COutputStreamFii +/* 801D56F0 001D2650 48 16 9C CD */ bl WriteBits__13COutputStreamFUiUi /* 801D56F4 001D2654 80 96 00 BC */ lwz r4, 0xbc(r22) /* 801D56F8 001D2658 7E E3 BB 78 */ mr r3, r23 /* 801D56FC 001D265C 38 A0 00 02 */ li r5, 2 -/* 801D5700 001D2660 48 16 9C BD */ bl WriteBits__13COutputStreamFii +/* 801D5700 001D2660 48 16 9C BD */ bl WriteBits__13COutputStreamFUiUi /* 801D5704 001D2664 83 CD A0 84 */ lwz r30, gpMemoryCard@sda21(r13) /* 801D5708 001D2668 3C 60 53 41 */ lis r3, 0x53415657@ha /* 801D570C 001D266C 3A 83 56 57 */ addi r20, r3, 0x53415657@l @@ -2472,7 +2472,7 @@ lbl_801D58EC: /* 801D58FC 001D285C 7C 04 00 D0 */ neg r0, r4 /* 801D5900 001D2860 7C 00 23 78 */ or r0, r0, r4 /* 801D5904 001D2864 54 04 0F FE */ srwi r4, r0, 0x1f -/* 801D5908 001D2868 48 16 9A B5 */ bl WriteBits__13COutputStreamFii +/* 801D5908 001D2868 48 16 9A B5 */ bl WriteBits__13COutputStreamFUiUi /* 801D590C 001D286C 3A 94 00 01 */ addi r20, r20, 1 lbl_801D5910: /* 801D5910 001D2870 7C 14 D0 00 */ cmpw r20, r26 diff --git a/asm/MetroidPrime/Player/CPlayerState.s b/asm/MetroidPrime/Player/CPlayerState.s index ddfee3c1..362656b3 100644 --- a/asm/MetroidPrime/Player/CPlayerState.s +++ b/asm/MetroidPrime/Player/CPlayerState.s @@ -1103,25 +1103,25 @@ PutTo__12CPlayerStateFR13COutputStream: /* 80091EDC 0008EE3C 80 83 00 04 */ lwz r4, 4(r3) /* 80091EE0 0008EE40 7F E3 FB 78 */ mr r3, r31 /* 80091EE4 0008EE44 38 A0 00 20 */ li r5, 0x20 -/* 80091EE8 0008EE48 48 2A D4 D5 */ bl WriteBits__13COutputStreamFii +/* 80091EE8 0008EE48 48 2A D4 D5 */ bl WriteBits__13COutputStreamFUiUi /* 80091EEC 0008EE4C C0 1E 00 0C */ lfs f0, 0xc(r30) /* 80091EF0 0008EE50 7F E3 FB 78 */ mr r3, r31 /* 80091EF4 0008EE54 38 A0 00 20 */ li r5, 0x20 /* 80091EF8 0008EE58 D0 01 00 08 */ stfs f0, 8(r1) /* 80091EFC 0008EE5C 80 81 00 08 */ lwz r4, 8(r1) -/* 80091F00 0008EE60 48 2A D4 BD */ bl WriteBits__13COutputStreamFii +/* 80091F00 0008EE60 48 2A D4 BD */ bl WriteBits__13COutputStreamFUiUi /* 80091F04 0008EE64 38 60 00 05 */ li r3, 5 /* 80091F08 0008EE68 48 00 04 B9 */ bl GetBitCount__12CPlayerStateFUi /* 80091F0C 0008EE6C 80 9E 00 08 */ lwz r4, 8(r30) /* 80091F10 0008EE70 7C 65 1B 78 */ mr r5, r3 /* 80091F14 0008EE74 7F E3 FB 78 */ mr r3, r31 -/* 80091F18 0008EE78 48 2A D4 A5 */ bl WriteBits__13COutputStreamFii +/* 80091F18 0008EE78 48 2A D4 A5 */ bl WriteBits__13COutputStreamFUiUi /* 80091F1C 0008EE7C 38 60 00 04 */ li r3, 4 /* 80091F20 0008EE80 48 00 04 A1 */ bl GetBitCount__12CPlayerStateFUi /* 80091F24 0008EE84 80 9E 00 20 */ lwz r4, 0x20(r30) /* 80091F28 0008EE88 7C 65 1B 78 */ mr r5, r3 /* 80091F2C 0008EE8C 7F E3 FB 78 */ mr r3, r31 -/* 80091F30 0008EE90 48 2A D4 8D */ bl WriteBits__13COutputStreamFii +/* 80091F30 0008EE90 48 2A D4 8D */ bl WriteBits__13COutputStreamFUiUi /* 80091F34 0008EE94 3C 60 80 3D */ lis r3, kPowerUpMax@ha /* 80091F38 0008EE98 3B 9E 00 28 */ addi r28, r30, 0x28 /* 80091F3C 0008EE9C 3B A3 D6 C0 */ addi r29, r3, kPowerUpMax@l @@ -1135,11 +1135,11 @@ lbl_80091F44: /* 80091F58 0008EEB8 80 9C 00 00 */ lwz r4, 0(r28) /* 80091F5C 0008EEBC 7F E3 FB 78 */ mr r3, r31 /* 80091F60 0008EEC0 7F 45 D3 78 */ mr r5, r26 -/* 80091F64 0008EEC4 48 2A D4 59 */ bl WriteBits__13COutputStreamFii +/* 80091F64 0008EEC4 48 2A D4 59 */ bl WriteBits__13COutputStreamFUiUi /* 80091F68 0008EEC8 80 9C 00 04 */ lwz r4, 4(r28) /* 80091F6C 0008EECC 7F E3 FB 78 */ mr r3, r31 /* 80091F70 0008EED0 7F 45 D3 78 */ mr r5, r26 -/* 80091F74 0008EED4 48 2A D4 49 */ bl WriteBits__13COutputStreamFii +/* 80091F74 0008EED4 48 2A D4 49 */ bl WriteBits__13COutputStreamFUiUi lbl_80091F78: /* 80091F78 0008EED8 3B 7B 00 01 */ addi r27, r27, 1 /* 80091F7C 0008EEDC 3B 9C 00 08 */ addi r28, r28, 8 @@ -1161,7 +1161,7 @@ lbl_80091FB4: /* 80091FB4 0008EF14 38 80 00 00 */ li r4, 0 lbl_80091FB8: /* 80091FB8 0008EF18 38 A0 00 01 */ li r5, 1 -/* 80091FBC 0008EF1C 48 2A D4 01 */ bl WriteBits__13COutputStreamFii +/* 80091FBC 0008EF1C 48 2A D4 01 */ bl WriteBits__13COutputStreamFUiUi /* 80091FC0 0008EF20 3B BD 00 08 */ addi r29, r29, 8 lbl_80091FC4: /* 80091FC4 0008EF24 80 1E 01 74 */ lwz r0, 0x174(r30) @@ -1175,13 +1175,13 @@ lbl_80091FC4: /* 80091FE4 0008EF44 80 9E 01 80 */ lwz r4, 0x180(r30) /* 80091FE8 0008EF48 7C 65 1B 78 */ mr r5, r3 /* 80091FEC 0008EF4C 7F E3 FB 78 */ mr r3, r31 -/* 80091FF0 0008EF50 48 2A D3 CD */ bl WriteBits__13COutputStreamFii +/* 80091FF0 0008EF50 48 2A D3 CD */ bl WriteBits__13COutputStreamFUiUi /* 80091FF4 0008EF54 38 60 01 00 */ li r3, 0x100 /* 80091FF8 0008EF58 48 00 03 C9 */ bl GetBitCount__12CPlayerStateFUi /* 80091FFC 0008EF5C 80 9E 01 84 */ lwz r4, 0x184(r30) /* 80092000 0008EF60 7C 65 1B 78 */ mr r5, r3 /* 80092004 0008EF64 7F E3 FB 78 */ mr r3, r31 -/* 80092008 0008EF68 48 2A D3 B5 */ bl WriteBits__13COutputStreamFii +/* 80092008 0008EF68 48 2A D3 B5 */ bl WriteBits__13COutputStreamFUiUi /* 8009200C 0008EF6C E3 E1 00 38 */ psq_l f31, 56(r1), 0, qr0 /* 80092010 0008EF70 CB E1 00 30 */ lfd f31, 0x30(r1) /* 80092014 0008EF74 BB 41 00 18 */ lmw r26, 0x18(r1) diff --git a/asm/MetroidPrime/Player/CWorldLayerState.s b/asm/MetroidPrime/Player/CWorldLayerState.s index a01c1feb..0e2a9b95 100644 --- a/asm/MetroidPrime/Player/CWorldLayerState.s +++ b/asm/MetroidPrime/Player/CWorldLayerState.s @@ -314,7 +314,7 @@ lbl_80234378: /* 80234380 002312E0 7F 63 DB 78 */ mr r3, r27 /* 80234384 002312E4 7F E4 FB 78 */ mr r4, r31 /* 80234388 002312E8 38 A0 00 0A */ li r5, 0xa -/* 8023438C 002312EC 48 10 B0 31 */ bl WriteBits__13COutputStreamFii +/* 8023438C 002312EC 48 10 B0 31 */ bl WriteBits__13COutputStreamFUiUi /* 80234390 002312F0 3B A0 00 00 */ li r29, 0 /* 80234394 002312F4 48 00 00 70 */ b lbl_80234404 lbl_80234398: @@ -341,7 +341,7 @@ lbl_802343BC: /* 802343E4 00231344 38 A0 00 01 */ li r5, 1 /* 802343E8 00231348 7C 00 23 78 */ or r0, r0, r4 /* 802343EC 0023134C 54 04 0F FE */ srwi r4, r0, 0x1f -/* 802343F0 00231350 48 10 AF CD */ bl WriteBits__13COutputStreamFii +/* 802343F0 00231350 48 10 AF CD */ bl WriteBits__13COutputStreamFUiUi /* 802343F4 00231354 3B 9C 00 01 */ addi r28, r28, 1 lbl_802343F8: /* 802343F8 00231358 7C 1C F8 00 */ cmpw r28, r31 diff --git a/asm/MetroidPrime/main.s b/asm/MetroidPrime/main.s index 573e3a6e..7f26fb28 100644 --- a/asm/MetroidPrime/main.s +++ b/asm/MetroidPrime/main.s @@ -3938,7 +3938,7 @@ lbl_80005EB4: /* 80005EDC 00002E3C 38 A0 00 01 */ li r5, 0x1 /* 80005EE0 00002E40 7C 00 23 78 */ or r0, r0, r4 /* 80005EE4 00002E44 54 04 0F FE */ srwi r4, r0, 31 -/* 80005EE8 00002E48 48 33 95 B5 */ bl WriteBits__13COutputStreamFii +/* 80005EE8 00002E48 48 33 95 B5 */ bl WriteBits__13COutputStreamFUiUi /* 80005EEC 00002E4C 80 6D A0 80 */ lwz r3, gpGameState@sda21(r13) /* 80005EF0 00002E50 38 81 00 B4 */ addi r4, r1, 0xb4 /* 80005EF4 00002E54 38 63 01 7C */ addi r3, r3, 0x17c @@ -3949,7 +3949,7 @@ lbl_80005EB4: /* 80005F08 00002E68 7C 04 00 D0 */ neg r0, r4 /* 80005F0C 00002E6C 7C 00 23 78 */ or r0, r0, r4 /* 80005F10 00002E70 54 04 0F FE */ srwi r4, r0, 31 -/* 80005F14 00002E74 48 33 95 89 */ bl WriteBits__13COutputStreamFii +/* 80005F14 00002E74 48 33 95 89 */ bl WriteBits__13COutputStreamFUiUi /* 80005F18 00002E78 38 61 00 B4 */ addi r3, r1, 0xb4 /* 80005F1C 00002E7C 48 33 97 39 */ bl Flush__13COutputStreamFv /* 80005F20 00002E80 38 61 00 B4 */ addi r3, r1, 0xb4 @@ -4174,7 +4174,7 @@ lbl_80005EC0: /* 80005EE8 00002E48 38 A0 00 01 */ li r5, 1 /* 80005EEC 00002E4C 7C 00 23 78 */ or r0, r0, r4 /* 80005EF0 00002E50 54 04 0F FE */ srwi r4, r0, 0x1f -/* 80005EF4 00002E54 48 33 94 C9 */ bl WriteBits__13COutputStreamFii +/* 80005EF4 00002E54 48 33 94 C9 */ bl WriteBits__13COutputStreamFUiUi /* 80005EF8 00002E58 80 6D A0 80 */ lwz r3, gpGameState@sda21(r13) /* 80005EFC 00002E5C 38 81 00 B4 */ addi r4, r1, 0xb4 /* 80005F00 00002E60 38 63 01 7C */ addi r3, r3, 0x17c @@ -4185,7 +4185,7 @@ lbl_80005EC0: /* 80005F14 00002E74 7C 04 00 D0 */ neg r0, r4 /* 80005F18 00002E78 7C 00 23 78 */ or r0, r0, r4 /* 80005F1C 00002E7C 54 04 0F FE */ srwi r4, r0, 0x1f -/* 80005F20 00002E80 48 33 94 9D */ bl WriteBits__13COutputStreamFii +/* 80005F20 00002E80 48 33 94 9D */ bl WriteBits__13COutputStreamFUiUi /* 80005F24 00002E84 38 61 00 B4 */ addi r3, r1, 0xb4 /* 80005F28 00002E88 48 33 96 4D */ bl Flush__13COutputStreamFv /* 80005F2C 00002E8C 38 61 00 B4 */ addi r3, r1, 0xb4 diff --git a/include/Kyoto/Streams/COutputStream.hpp b/include/Kyoto/Streams/COutputStream.hpp index 241961bd..3583326a 100644 --- a/include/Kyoto/Streams/COutputStream.hpp +++ b/include/Kyoto/Streams/COutputStream.hpp @@ -18,7 +18,7 @@ public: COutputStream(int len); virtual ~COutputStream(); virtual void Write(const void* ptr, u32 len); - void WriteBits(int val, int bitCount); + void WriteBits(uint val, uint bitCount); void FlushShiftRegister(); void Put(const void* ptr, size_t len) { @@ -40,22 +40,22 @@ public: void WriteChar(u8 c) { FlushShiftRegister(); - if (mBufLen <= mPosition) { + if (mBufLen <= mUnwrittenLen) { DoFlush(); } ++mNumWrites; - *(reinterpret_cast< u8* >(mBufPtr) + mPosition) = c; - ++mPosition; + *(reinterpret_cast< u8* >(mBufPtr) + mUnwrittenLen) = c; + ++mUnwrittenLen; } private: - uint mPosition; + uint mUnwrittenLen; uint mBufLen; void* mBufPtr; uint mNumWrites; uint mShiftRegister; - uint mShiftRegisterOffset; + volatile uint mShiftRegisterOffset; uchar mScratch[96]; }; diff --git a/src/Kyoto/Streams/COutputStream.cpp b/src/Kyoto/Streams/COutputStream.cpp index f291efeb..af06e9cf 100644 --- a/src/Kyoto/Streams/COutputStream.cpp +++ b/src/Kyoto/Streams/COutputStream.cpp @@ -5,7 +5,7 @@ #include COutputStream::COutputStream(int len) -: mPosition(0) +: mUnwrittenLen(0) , mBufLen(len) , mBufPtr(len > 64 ? new uchar[len] : &mScratch[32 - (uint)(mScratch) % 31]) , mNumWrites(0) @@ -22,25 +22,23 @@ void COutputStream::DoPut(const void* ptr, size_t len) { if (len == 0) { return; } - uint curLen = len; mNumWrites += len; - if (mBufLen <= len + mPosition) { - memcpy((uchar*)mBufPtr + mPosition, ptr, len); - mPosition += len; + if (mBufLen <= len + mUnwrittenLen) { + memcpy((uchar*)mBufPtr + mUnwrittenLen, ptr, len); + mUnwrittenLen += len; return; } - - while (curLen != 0) { - uint count = mBufLen - mPosition; - uint offset = curLen; - if (curLen < count) { - count = curLen; + while (len != 0) { + uint count = mBufLen - mUnwrittenLen; + uint offset = len; + if (count < len) { + len = count; } if (count != 0) { - memcpy((uchar*)mBufPtr + mPosition, (uchar*)ptr + offset, count); - mPosition += count; - curLen -= count; + memcpy((uchar*)mBufPtr + mUnwrittenLen, (uchar*)ptr + offset, len); + mUnwrittenLen += len; + len -= len; } else { DoFlush(); } @@ -53,9 +51,9 @@ void COutputStream::Flush() { } void COutputStream::DoFlush() { - if (mPosition != 0) { - Write(mBufPtr, mPosition); - mPosition = 0; + if (mUnwrittenLen != 0) { + Write(mBufPtr, mUnwrittenLen); + mUnwrittenLen = 0; } } @@ -66,8 +64,42 @@ static inline u32 min_containing_bytes(u32 v) { void COutputStream::FlushShiftRegister() { if (mShiftRegisterOffset < 32) { - DoPut(&mShiftRegister, min_containing_bytes(mShiftRegisterOffset)); + DoPut((void*)&mShiftRegister, min_containing_bytes(mShiftRegisterOffset)); mShiftRegister = 0; mShiftRegisterOffset = 32; } } + +void COutputStream::WriteBits(uint value, uint bitCount) { + + uint registerOffset = mShiftRegisterOffset; + if (registerOffset >= bitCount) { + registerOffset -= bitCount; + uint mask = 0xffffffff; + uint shiftRegister = mShiftRegister; + if (bitCount != 32) { + mask = (1 << bitCount) - 1; + } + mShiftRegister = shiftRegister | ((value & mask) << registerOffset); + mShiftRegisterOffset -= bitCount; + } else { + uint shiftAmt = bitCount - registerOffset; + uint shiftRegister = mShiftRegister; + uint mask = 0xffffffff; + if (registerOffset != 0x20) { + mask = (1 << registerOffset) - 1; + } + + shiftRegister |= (value >> shiftAmt); + shiftRegister &= mask; + mShiftRegister = shiftRegister; + mShiftRegisterOffset = 0; + FlushShiftRegister(); + uint mask2 = 0xffffffff; + if (shiftAmt != 32) { + mask2 = (1 << shiftAmt) - 1; + } + mShiftRegister = (value & mask2) << (32 - shiftAmt); + mShiftRegisterOffset -= shiftAmt; + } +}