diff --git a/tools/gb-payload-generator/include/inccustom/customcrystal11_en.inc b/tools/gb-payload-generator/include/inccustom/customcrystal11_en.inc index 8e6a5a9..29c3d23 100644 --- a/tools/gb-payload-generator/include/inccustom/customcrystal11_en.inc +++ b/tools/gb-payload-generator/include/inccustom/customcrystal11_en.inc @@ -27,3 +27,4 @@ DEF TREECKO_NAME EQUS "TREECKO@@@@" DEF GROVYLE_NAME EQUS "GROVYLE@@@@" DEF SCEPTILE_NAME EQUS "SCEPTILE@@@" DEF TORCHIC_NAME EQUS "TORCHIC@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customcrystalAU_en.inc b/tools/gb-payload-generator/include/inccustom/customcrystalAU_en.inc index 8e6a5a9..29c3d23 100644 --- a/tools/gb-payload-generator/include/inccustom/customcrystalAU_en.inc +++ b/tools/gb-payload-generator/include/inccustom/customcrystalAU_en.inc @@ -27,3 +27,4 @@ DEF TREECKO_NAME EQUS "TREECKO@@@@" DEF GROVYLE_NAME EQUS "GROVYLE@@@@" DEF SCEPTILE_NAME EQUS "SCEPTILE@@@" DEF TORCHIC_NAME EQUS "TORCHIC@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customcrystal_de.inc b/tools/gb-payload-generator/include/inccustom/customcrystal_de.inc index 4bd4500..3dd0ab4 100644 --- a/tools/gb-payload-generator/include/inccustom/customcrystal_de.inc +++ b/tools/gb-payload-generator/include/inccustom/customcrystal_de.inc @@ -26,4 +26,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "GECKARBOR@@" DEF GROVYLE_NAME EQUS "REPTAIN@@@@" DEF SCEPTILE_NAME EQUS "GEWALDRO@@@" -DEF TORCHIC_NAME EQUS "FLEMMLI@@@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "FLEMMLI@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customcrystal_en.inc b/tools/gb-payload-generator/include/inccustom/customcrystal_en.inc index 8e6a5a9..29c3d23 100644 --- a/tools/gb-payload-generator/include/inccustom/customcrystal_en.inc +++ b/tools/gb-payload-generator/include/inccustom/customcrystal_en.inc @@ -27,3 +27,4 @@ DEF TREECKO_NAME EQUS "TREECKO@@@@" DEF GROVYLE_NAME EQUS "GROVYLE@@@@" DEF SCEPTILE_NAME EQUS "SCEPTILE@@@" DEF TORCHIC_NAME EQUS "TORCHIC@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customcrystal_fr.inc b/tools/gb-payload-generator/include/inccustom/customcrystal_fr.inc index 486f741..055e170 100644 --- a/tools/gb-payload-generator/include/inccustom/customcrystal_fr.inc +++ b/tools/gb-payload-generator/include/inccustom/customcrystal_fr.inc @@ -26,4 +26,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "ARCKO@@@@@@" DEF GROVYLE_NAME EQUS "MASSKO@@@@@" DEF SCEPTILE_NAME EQUS "JUNGKO@@@@@" -DEF TORCHIC_NAME EQUS "POUSSIFEU@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "POUSSIFEU@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customcrystal_it.inc b/tools/gb-payload-generator/include/inccustom/customcrystal_it.inc index 8f507d5..9324c75 100644 --- a/tools/gb-payload-generator/include/inccustom/customcrystal_it.inc +++ b/tools/gb-payload-generator/include/inccustom/customcrystal_it.inc @@ -27,4 +27,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "TREECKO@@@@" DEF GROVYLE_NAME EQUS "GROVYLE@@@@" DEF SCEPTILE_NAME EQUS "SCEPTILE@@@" -DEF TORCHIC_NAME EQUS "TORCHIC@@@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "TORCHIC@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customcrystal_jp.inc b/tools/gb-payload-generator/include/inccustom/customcrystal_jp.inc index 9cd2410..9c638e5 100644 --- a/tools/gb-payload-generator/include/inccustom/customcrystal_jp.inc +++ b/tools/gb-payload-generator/include/inccustom/customcrystal_jp.inc @@ -29,4 +29,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "キモリ@@@" DEF GROVYLE_NAME EQUS "ジュプトル@" DEF SCEPTILE_NAME EQUS "ジュカイン@" -DEF TORCHIC_NAME EQUS "アチャモ@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "アチャモ@@" +DEF TextHeight EQU 0x2 diff --git a/tools/gb-payload-generator/include/inccustom/customcrystal_sp.inc b/tools/gb-payload-generator/include/inccustom/customcrystal_sp.inc index e455b48..ffb3789 100644 --- a/tools/gb-payload-generator/include/inccustom/customcrystal_sp.inc +++ b/tools/gb-payload-generator/include/inccustom/customcrystal_sp.inc @@ -26,4 +26,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "TREECKO@@@@" DEF GROVYLE_NAME EQUS "GROVYLE@@@@" DEF SCEPTILE_NAME EQUS "SCEPTILE@@@" -DEF TORCHIC_NAME EQUS "TORCHIC@@@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "TORCHIC@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customgold11_jp.inc b/tools/gb-payload-generator/include/inccustom/customgold11_jp.inc index 4b6851f..cac90ca 100644 --- a/tools/gb-payload-generator/include/inccustom/customgold11_jp.inc +++ b/tools/gb-payload-generator/include/inccustom/customgold11_jp.inc @@ -26,4 +26,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "キモリ@@@" DEF GROVYLE_NAME EQUS "ジュプトル@" DEF SCEPTILE_NAME EQUS "ジュカイン@" -DEF TORCHIC_NAME EQUS "アチャモ@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "アチャモ@@" +DEF TextHeight EQU 0x2 diff --git a/tools/gb-payload-generator/include/inccustom/customgold_de.inc b/tools/gb-payload-generator/include/inccustom/customgold_de.inc index 045fbc1..f7a9885 100644 --- a/tools/gb-payload-generator/include/inccustom/customgold_de.inc +++ b/tools/gb-payload-generator/include/inccustom/customgold_de.inc @@ -24,4 +24,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "GECKARBOR@@" DEF GROVYLE_NAME EQUS "REPTAIN@@@@" DEF SCEPTILE_NAME EQUS "GEWALDRO@@@" -DEF TORCHIC_NAME EQUS "FLEMMLI@@@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "FLEMMLI@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customgold_en.inc b/tools/gb-payload-generator/include/inccustom/customgold_en.inc index c416b8c..28b1aed 100644 --- a/tools/gb-payload-generator/include/inccustom/customgold_en.inc +++ b/tools/gb-payload-generator/include/inccustom/customgold_en.inc @@ -24,4 +24,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "TREECKO@@@@" DEF GROVYLE_NAME EQUS "GROVYLE@@@@" DEF SCEPTILE_NAME EQUS "SCEPTILE@@@" -DEF TORCHIC_NAME EQUS "TORCHIC@@@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "TORCHIC@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customgold_fr.inc b/tools/gb-payload-generator/include/inccustom/customgold_fr.inc index 65b611c..068c140 100644 --- a/tools/gb-payload-generator/include/inccustom/customgold_fr.inc +++ b/tools/gb-payload-generator/include/inccustom/customgold_fr.inc @@ -24,4 +24,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "ARCKO@@@@@@" DEF GROVYLE_NAME EQUS "MASSKO@@@@@" DEF SCEPTILE_NAME EQUS "JUNGKO@@@@@" -DEF TORCHIC_NAME EQUS "POUSSIFEU@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "POUSSIFEU@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customgold_it.inc b/tools/gb-payload-generator/include/inccustom/customgold_it.inc index 3aa8012..91d083d 100644 --- a/tools/gb-payload-generator/include/inccustom/customgold_it.inc +++ b/tools/gb-payload-generator/include/inccustom/customgold_it.inc @@ -24,4 +24,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "TREECKO@@@@" DEF GROVYLE_NAME EQUS "GROVYLE@@@@" DEF SCEPTILE_NAME EQUS "SCEPTILE@@@" -DEF TORCHIC_NAME EQUS "TORCHIC@@@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "TORCHIC@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customgold_jp.inc b/tools/gb-payload-generator/include/inccustom/customgold_jp.inc index 4b6851f..cac90ca 100644 --- a/tools/gb-payload-generator/include/inccustom/customgold_jp.inc +++ b/tools/gb-payload-generator/include/inccustom/customgold_jp.inc @@ -26,4 +26,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "キモリ@@@" DEF GROVYLE_NAME EQUS "ジュプトル@" DEF SCEPTILE_NAME EQUS "ジュカイン@" -DEF TORCHIC_NAME EQUS "アチャモ@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "アチャモ@@" +DEF TextHeight EQU 0x2 diff --git a/tools/gb-payload-generator/include/inccustom/customgold_kor.inc b/tools/gb-payload-generator/include/inccustom/customgold_kor.inc index 34b523d..9dff365 100644 --- a/tools/gb-payload-generator/include/inccustom/customgold_kor.inc +++ b/tools/gb-payload-generator/include/inccustom/customgold_kor.inc @@ -24,4 +24,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "나무지기@@@" DEF GROVYLE_NAME EQUS "나무돌이@@@" DEF SCEPTILE_NAME EQUS "나무킹@@@@@" -DEF TORCHIC_NAME EQUS "아차모@@@@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "아차모@@@@@" +DEF TextHeight EQU 0x2 diff --git a/tools/gb-payload-generator/include/inccustom/customgold_sp.inc b/tools/gb-payload-generator/include/inccustom/customgold_sp.inc index fcfdda6..d209856 100644 --- a/tools/gb-payload-generator/include/inccustom/customgold_sp.inc +++ b/tools/gb-payload-generator/include/inccustom/customgold_sp.inc @@ -24,4 +24,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "TREECKO@@@@" DEF GROVYLE_NAME EQUS "GROVYLE@@@@" DEF SCEPTILE_NAME EQUS "SCEPTILE@@@" -DEF TORCHIC_NAME EQUS "TORCHIC@@@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "TORCHIC@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customsilver11_jp.inc b/tools/gb-payload-generator/include/inccustom/customsilver11_jp.inc index 4b6851f..cac90ca 100644 --- a/tools/gb-payload-generator/include/inccustom/customsilver11_jp.inc +++ b/tools/gb-payload-generator/include/inccustom/customsilver11_jp.inc @@ -26,4 +26,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "キモリ@@@" DEF GROVYLE_NAME EQUS "ジュプトル@" DEF SCEPTILE_NAME EQUS "ジュカイン@" -DEF TORCHIC_NAME EQUS "アチャモ@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "アチャモ@@" +DEF TextHeight EQU 0x2 diff --git a/tools/gb-payload-generator/include/inccustom/customsilver_de.inc b/tools/gb-payload-generator/include/inccustom/customsilver_de.inc index 045fbc1..f7a9885 100644 --- a/tools/gb-payload-generator/include/inccustom/customsilver_de.inc +++ b/tools/gb-payload-generator/include/inccustom/customsilver_de.inc @@ -24,4 +24,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "GECKARBOR@@" DEF GROVYLE_NAME EQUS "REPTAIN@@@@" DEF SCEPTILE_NAME EQUS "GEWALDRO@@@" -DEF TORCHIC_NAME EQUS "FLEMMLI@@@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "FLEMMLI@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customsilver_en.inc b/tools/gb-payload-generator/include/inccustom/customsilver_en.inc index ebae0d1..28b1aed 100644 --- a/tools/gb-payload-generator/include/inccustom/customsilver_en.inc +++ b/tools/gb-payload-generator/include/inccustom/customsilver_en.inc @@ -25,3 +25,4 @@ DEF TREECKO_NAME EQUS "TREECKO@@@@" DEF GROVYLE_NAME EQUS "GROVYLE@@@@" DEF SCEPTILE_NAME EQUS "SCEPTILE@@@" DEF TORCHIC_NAME EQUS "TORCHIC@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customsilver_fr.inc b/tools/gb-payload-generator/include/inccustom/customsilver_fr.inc index 65b611c..068c140 100644 --- a/tools/gb-payload-generator/include/inccustom/customsilver_fr.inc +++ b/tools/gb-payload-generator/include/inccustom/customsilver_fr.inc @@ -24,4 +24,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "ARCKO@@@@@@" DEF GROVYLE_NAME EQUS "MASSKO@@@@@" DEF SCEPTILE_NAME EQUS "JUNGKO@@@@@" -DEF TORCHIC_NAME EQUS "POUSSIFEU@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "POUSSIFEU@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customsilver_it.inc b/tools/gb-payload-generator/include/inccustom/customsilver_it.inc index 3aa8012..91d083d 100644 --- a/tools/gb-payload-generator/include/inccustom/customsilver_it.inc +++ b/tools/gb-payload-generator/include/inccustom/customsilver_it.inc @@ -24,4 +24,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "TREECKO@@@@" DEF GROVYLE_NAME EQUS "GROVYLE@@@@" DEF SCEPTILE_NAME EQUS "SCEPTILE@@@" -DEF TORCHIC_NAME EQUS "TORCHIC@@@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "TORCHIC@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/include/inccustom/customsilver_jp.inc b/tools/gb-payload-generator/include/inccustom/customsilver_jp.inc index 4b6851f..cac90ca 100644 --- a/tools/gb-payload-generator/include/inccustom/customsilver_jp.inc +++ b/tools/gb-payload-generator/include/inccustom/customsilver_jp.inc @@ -26,4 +26,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "キモリ@@@" DEF GROVYLE_NAME EQUS "ジュプトル@" DEF SCEPTILE_NAME EQUS "ジュカイン@" -DEF TORCHIC_NAME EQUS "アチャモ@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "アチャモ@@" +DEF TextHeight EQU 0x2 diff --git a/tools/gb-payload-generator/include/inccustom/customsilver_kor.inc b/tools/gb-payload-generator/include/inccustom/customsilver_kor.inc index 7cdc65b..771c662 100644 --- a/tools/gb-payload-generator/include/inccustom/customsilver_kor.inc +++ b/tools/gb-payload-generator/include/inccustom/customsilver_kor.inc @@ -24,4 +24,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "나무지기@@@" DEF GROVYLE_NAME EQUS "나무돌이@@@" DEF SCEPTILE_NAME EQUS "나무킹@@@@@" -DEF TORCHIC_NAME EQUS "아차모@@@@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "아차모@@@@@" +DEF TextHeight EQU 0x2 diff --git a/tools/gb-payload-generator/include/inccustom/customsilver_sp.inc b/tools/gb-payload-generator/include/inccustom/customsilver_sp.inc index fcfdda6..d209856 100644 --- a/tools/gb-payload-generator/include/inccustom/customsilver_sp.inc +++ b/tools/gb-payload-generator/include/inccustom/customsilver_sp.inc @@ -24,4 +24,5 @@ DEF MAILWRITER_SIZE = $32 DEF TREECKO_NAME EQUS "TREECKO@@@@" DEF GROVYLE_NAME EQUS "GROVYLE@@@@" DEF SCEPTILE_NAME EQUS "SCEPTILE@@@" -DEF TORCHIC_NAME EQUS "TORCHIC@@@@" \ No newline at end of file +DEF TORCHIC_NAME EQUS "TORCHIC@@@@" +DEF TextHeight EQU 0x1 diff --git a/tools/gb-payload-generator/src/gen2specific/specificPayloadGen2.asm b/tools/gb-payload-generator/src/gen2specific/specificPayloadGen2.asm index 64ecd6a..f0d4101 100644 --- a/tools/gb-payload-generator/src/gen2specific/specificPayloadGen2.asm +++ b/tools/gb-payload-generator/src/gen2specific/specificPayloadGen2.asm @@ -13,15 +13,15 @@ SECTION "Main", ROM0 Main: db 0xFD -LOAD "Payload", WRAM0[0xC800] +LOAD "Payload", WRAM0[0xC900] Payload: .loopTransfer - ld hl, 0xC5DC ; perfect place to store incoming packets. TODO: on first pass, this will interpret the generic payload as part of an incoming packet. Check if this interferes with anything. + ld hl, 0xC6DC ; perfect place to store incoming packets. TODO: on first pass, this will interpret the generic payload as part of an incoming packet. Check if this interferes with anything. .searchCounter ld a, [hli] bit 7, a jr nz, .searchCounter ; first byte should be a packet counter, with a value between 0x00-0x7F. Also skips preamble bytes. - ld [0xC5DC], a ; Put this at the start of the received data, to ensure we'll be sending it back if we're running a command. + ld [0xC6DC], a ; Put this at the start of the received data, to ensure we'll be sending it back if we're running a command. push af ; we'll retrieve this later ld a, [hli] ; load command byte ld b, [hl] ; load argument byte 1 @@ -38,7 +38,7 @@ Payload: ld a, [hli] ld h, [hl] ld l, a - ld de, 0xC5D3 + ld de, 0xC6D3 pop bc ; sneaky way to load the counter into the checksum push de ld c, 1 @@ -74,14 +74,14 @@ Payload: call .changeInterruptsAndCommunicate jr .loopTransfer .changeInterruptsAndCommunicate - call 0xC690 ; leftover from the universal payload, only allow serial interrupt and call Serial_ExchangeBytes + call 0xC85E ; leftover from the universal payload, only allow serial interrupt and call Serial_ExchangeBytes ld a, IE_SERIAL | IE_TIMER | IE_VBLANK ; enable vblank interrupt so that a sound effect can play ldh [rIE], a ret VerifySecondaryPayload: ; checks if payload matches expected size and passes verification. ld c, b - ld de, 0xC900 - ld hl, 0xC5D0 + ld de, 0xCA00 + ld hl, 0xC6D0 push de call Payload.changeInterruptsAndCommunicate pop hl @@ -143,7 +143,7 @@ RunSecondaryPayload: ; loads new payload of size b, aligns it, verifies it, then jp hl ReplaceTextBox: hlcoord 2, 10 - ld bc, 1 << 8 | 14 + ld bc, TextHeight << 8 | 14 ; Korean and Japanese text can have a height of 2 tiles ld a, 0x10 ; predef ID for LinkTextboxAtHL call Predef .writeCommunicating diff --git a/tools/gb-payload-generator/src/gen2universal/universalPayloadGen2.asm b/tools/gb-payload-generator/src/gen2universal/universalPayloadGen2.asm index 7c5f266..5c2c7fd 100644 --- a/tools/gb-payload-generator/src/gen2universal/universalPayloadGen2.asm +++ b/tools/gb-payload-generator/src/gen2universal/universalPayloadGen2.asm @@ -31,22 +31,22 @@ PartyData: .tid ds 2, '' .partyData - db 1 - db '' + db 1 ; mask the next character for the Korean version + db '' ; reset write location to a consistent offset ds 171, '' ds 34, 'A' - dw SerialPatchListPayload + 0x100 + dw SerialPatchListPayload + 0x100 ; stack smash for Crystal db '' ds 10, 'A' - dw SerialPatchListPayload - db 1 - db '@' + dw SerialPatchListPayload ; stack smash for non-KOR Gold/Silver + db 1 ; mask the next character for the Korean version + db '@' ; stop text printing and return to overwritten pointer on non-KOR Gold/Silver/Crystal db '' ds 69, '' db '' ds 14, 'A' - dw SerialPatchListKoreanPayload - db '@' + dw SerialPatchListKoreanPayload ; stack smash for KOR Gold/Silver + db '@' ; stop text printing and return to overwritten pointer on KOR Gold/Silver .end ds LINKDATASIZE_GEN2 - (PartyData.end - PartyDataPreamble), 0 @@ -87,26 +87,26 @@ SerialPatchListPayload: ; on GS: this gets loaded in 0xC5D0. On C: this gets loa xor a ld [hld], a ld [hld], a - inc a + inc a ; prepare a for Bankswitch. Technically not needed on legit carts, but better to not rely on MBC quirks ld [hl], 6 ; This disables music from playing ld hl, PlaceWaitingText rst FarCall ; call 01:4000 pop hl - ld bc, .end - .fetchPC ; both .end and .fetchPC share the same misalignment, if any. + ld bc, .end - .fetchPC ; both .end and .fetchPC share the same misalignment, if any add hl, bc ; hl now points to the first byte of SerialPatchListAligned. - ld de, SerialPatchListAligned + ld de, SerialPatchListAligned ; 0xC800 ld bc, SerialPatchListAligned.end - SerialPatchListAligned push de -.alignPayload ; copy remainder of payload to safer location, then jump towards it. +.alignPayload ; copy remainder of payload to 0xC800, then jump towards it. ld a, [hli] ld [de], a inc de dec c ret z - jr .alignPayload + jr .alignPayload ; this entire procedure ensures that the payload gets stored in a consistent location across all versions. .end ENDL -LOAD "serialPatchAligned", WRAM0[SerialPatchAlignedAddress] +LOAD "serialPatchAligned", WRAM0[SerialPatchAlignedAddress] ; 0xC800 SerialPatchListAligned: ld a, HIGH(SerialPatchListPayload.end) sub a, h ; sneaky hack. If we're on GS, this will set the z flag, allowing us to easily determine which version we're running. @@ -125,7 +125,7 @@ SerialPatchListAligned: ld hl, 0x14E ; locate cartridge checksum ld a, [hli] ld b, [hl] - ld hl, SerialPatchPreamble + 0x102 ; prepare to send cartridge checksum + ld hl, SerialPatchPreamble + 0x102 ; prepare to send cartridge checksum (0xC6D2) ld [hli], a ld [hl], b inc hl @@ -136,37 +136,29 @@ SerialPatchListAligned: ld a, SERIAL_PREAMBLE_BYTE ; we can't be sure that the first two bytes contain a preamble, so manually add it. ld [hli], a ld [hld], a - ld de, SpecificPayloadAddress ; receive payload at this address - push hl - push de + ld de, SpecificPayloadAddress ; receive payload at 0xC900 ld c, CHECKSUMPACKET_SIZE call .callSerial_ExchangeBytes ; send checksum to PTGB, bc = 0000 on exit - pop de - pop hl + ld e, c ; reset de to 0xC900 push de - dec c ; serial patch list size - push bc + dec c ; bc =,00FF call .callSerial_ExchangeBytes ; receive specific payload from PTGB - pop bc + ld e, c ; reset de to 0xC900 pop hl push hl - push hl - pop de .findNotPreamble ; we can't be sure if the payload arrived in the exact desired position. Because of this, let's align the payload. ld a, [hli] cp SERIAL_PREAMBLE_BYTE jr z, .findNotPreamble .alignPayload ; now that we have found the first non-preamble value, let's align it properly. ld [de], a - inc de - dec c ; we're only aligning stuff within the 0xC500 space + inc e ; exit if de is back to 0xC900 ld a, [hli] jr nz, .alignPayload - pop hl - ld a, [hl] ; check first non-preamble byte of payload. If 00, resend checksum (incorrect calculated checksum). If FF, an error has occured (correct calculated checksum, but the cartridge checksum is not recognized), so safely reset instead. If any other values, jump to new payload! + ld a, [de] ; check first non-preamble byte of payload. If 00, resend checksum (incorrect calculated checksum). If FF, an error has occured (correct calculated checksum, but the cartridge checksum is not recognized), so safely reset instead. If any other values, jump to new payload! and a, a jr z, .sendChecksum - push hl ; What I wouldn't give for a conditional jp hl + push de inc a ret nz pop af ; hCGB has a version-specific address, so retrieve the z flag we used earlier.