Final adjustments to gen 2, to prepare for testing

This commit is contained in:
TimoVM 2026-06-09 07:43:42 +02:00
parent 9d4cc290ae
commit bb35527da2
26 changed files with 74 additions and 58 deletions

View File

@ -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

View File

@ -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

View File

@ -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@@@@"
DEF TORCHIC_NAME EQUS "FLEMMLI@@@@"
DEF TextHeight EQU 0x1

View File

@ -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

View File

@ -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@@"
DEF TORCHIC_NAME EQUS "POUSSIFEU@@"
DEF TextHeight EQU 0x1

View File

@ -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@@@@"
DEF TORCHIC_NAME EQUS "TORCHIC@@@@"
DEF TextHeight EQU 0x1

View File

@ -29,4 +29,5 @@ DEF MAILWRITER_SIZE = $32
DEF TREECKO_NAME EQUS "キモリ@@@"
DEF GROVYLE_NAME EQUS "ジュプトル@"
DEF SCEPTILE_NAME EQUS "ジュカイン@"
DEF TORCHIC_NAME EQUS "アチャモ@@"
DEF TORCHIC_NAME EQUS "アチャモ@@"
DEF TextHeight EQU 0x2

View File

@ -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@@@@"
DEF TORCHIC_NAME EQUS "TORCHIC@@@@"
DEF TextHeight EQU 0x1

View File

@ -26,4 +26,5 @@ DEF MAILWRITER_SIZE = $32
DEF TREECKO_NAME EQUS "キモリ@@@"
DEF GROVYLE_NAME EQUS "ジュプトル@"
DEF SCEPTILE_NAME EQUS "ジュカイン@"
DEF TORCHIC_NAME EQUS "アチャモ@@"
DEF TORCHIC_NAME EQUS "アチャモ@@"
DEF TextHeight EQU 0x2

View File

@ -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@@@@"
DEF TORCHIC_NAME EQUS "FLEMMLI@@@@"
DEF TextHeight EQU 0x1

View File

@ -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@@@@"
DEF TORCHIC_NAME EQUS "TORCHIC@@@@"
DEF TextHeight EQU 0x1

View File

@ -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@@"
DEF TORCHIC_NAME EQUS "POUSSIFEU@@"
DEF TextHeight EQU 0x1

View File

@ -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@@@@"
DEF TORCHIC_NAME EQUS "TORCHIC@@@@"
DEF TextHeight EQU 0x1

View File

@ -26,4 +26,5 @@ DEF MAILWRITER_SIZE = $32
DEF TREECKO_NAME EQUS "キモリ@@@"
DEF GROVYLE_NAME EQUS "ジュプトル@"
DEF SCEPTILE_NAME EQUS "ジュカイン@"
DEF TORCHIC_NAME EQUS "アチャモ@@"
DEF TORCHIC_NAME EQUS "アチャモ@@"
DEF TextHeight EQU 0x2

View File

@ -24,4 +24,5 @@ DEF MAILWRITER_SIZE = $32
DEF TREECKO_NAME EQUS "나무지기@@@"
DEF GROVYLE_NAME EQUS "나무돌이@@@"
DEF SCEPTILE_NAME EQUS "나무킹@@@@@"
DEF TORCHIC_NAME EQUS "아차모@@@@@"
DEF TORCHIC_NAME EQUS "아차모@@@@@"
DEF TextHeight EQU 0x2

View File

@ -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@@@@"
DEF TORCHIC_NAME EQUS "TORCHIC@@@@"
DEF TextHeight EQU 0x1

View File

@ -26,4 +26,5 @@ DEF MAILWRITER_SIZE = $32
DEF TREECKO_NAME EQUS "キモリ@@@"
DEF GROVYLE_NAME EQUS "ジュプトル@"
DEF SCEPTILE_NAME EQUS "ジュカイン@"
DEF TORCHIC_NAME EQUS "アチャモ@@"
DEF TORCHIC_NAME EQUS "アチャモ@@"
DEF TextHeight EQU 0x2

View File

@ -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@@@@"
DEF TORCHIC_NAME EQUS "FLEMMLI@@@@"
DEF TextHeight EQU 0x1

View File

@ -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

View File

@ -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@@"
DEF TORCHIC_NAME EQUS "POUSSIFEU@@"
DEF TextHeight EQU 0x1

View File

@ -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@@@@"
DEF TORCHIC_NAME EQUS "TORCHIC@@@@"
DEF TextHeight EQU 0x1

View File

@ -26,4 +26,5 @@ DEF MAILWRITER_SIZE = $32
DEF TREECKO_NAME EQUS "キモリ@@@"
DEF GROVYLE_NAME EQUS "ジュプトル@"
DEF SCEPTILE_NAME EQUS "ジュカイン@"
DEF TORCHIC_NAME EQUS "アチャモ@@"
DEF TORCHIC_NAME EQUS "アチャモ@@"
DEF TextHeight EQU 0x2

View File

@ -24,4 +24,5 @@ DEF MAILWRITER_SIZE = $32
DEF TREECKO_NAME EQUS "나무지기@@@"
DEF GROVYLE_NAME EQUS "나무돌이@@@"
DEF SCEPTILE_NAME EQUS "나무킹@@@@@"
DEF TORCHIC_NAME EQUS "아차모@@@@@"
DEF TORCHIC_NAME EQUS "아차모@@@@@"
DEF TextHeight EQU 0x2

View File

@ -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@@@@"
DEF TORCHIC_NAME EQUS "TORCHIC@@@@"
DEF TextHeight EQU 0x1

View File

@ -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

View File

@ -31,22 +31,22 @@ PartyData:
.tid
ds 2, '<NEXT>'
.partyData
db 1
db '<LINE>'
db 1 ; mask the next character for the Korean version
db '<LINE>' ; reset write location to a consistent offset
ds 171, '<NEXT>'
ds 34, 'A'
dw SerialPatchListPayload + 0x100
dw SerialPatchListPayload + 0x100 ; stack smash for Crystal
db '<NEXT>'
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 '<KOR_LINE>'
ds 69, '<KOR_NEXT>'
db '<KOR_LF>'
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.