• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Script] Implementing version control in pokered for the cable club

This function implements a simple version control check for the cable club in asm projects that use pokered disassembly. I've linked it within the context of one of my own hacks (wherein it does the check upon selecting the "COLOSSEUM" option), but it is generic enough that it can easily be adapted for other projects.

You can see the full asm file in the github repository here.

Here is the commented code to implement it.
Code:
ShinPokemonHandshake:
;joenote - do a security handshake that checks the version of the other linked game.
;The other game must send back the same sequence of numbers given under HandshakeList.
;Otherwise the handshake fails and the connection is cancelled.
	push af	
	push hl
	;wUnknownSerialCounter is two bytes. Write the default of 03 00 to it.
	;This acts as a timeout counter for when two linked gameboys are trying to sync up.
	;We set it to its default because if it is left as zero then the syncing can get stuck in an infinite loop.
	ld hl, wUnknownSerialCounter
	ld a, $3
	ld [hli], a
	xor a
	ld [hl], a
	;wSerialExchangeNybbleSendData holds the nybble (a half-byte of 0 to f) to send to the other game.
	;Let's send a 0 across the link to make sure the other game can communicate.
	ld [wSerialExchangeNybbleSendData], a
	call Serial_PrintWaitingTextAndSyncAndExchangeNybble
	;wSerialExchangeNybbleReceiveData holds the nybble recieved from the other game.
	;This defaults to FF to indicate that no information was recieved.
	ld a, [wSerialExchangeNybbleReceiveData]
	and a
	;Since a 0 was sent, a 0 should also be recieved if communicating with a game that supports this handshake check.
	;If zero is not recieved, then there is a communication error and the handshake fails.
	jr nz, .fail
	;Else we have proper communication. Time to check to make sure the version control passcode matches.
	ld hl, HandshakeList
.loop
	ld a, [hl]	;load a digit of the version control passcode
	cp $ff	;has the end been reached?
	jr z, .pass	;handshake check passes if the end has been reached
	ld [wSerialExchangeNybbleSendData], a	;load the digit to be sent over link
	ld a, $ff
	ld [wSerialExchangeNybbleReceiveData], a	;default the recieved data to FF
	;This function syncs up with the other game.
	;The nybble in wSerialExchangeNybbleSendData is sent to the other game's wSerialExchangeNybbleReceiveData.
	;And the nybble in the other game's wSerialExchangeNybbleSendData is sent to your wSerialExchangeNybbleReceiveData.
	call Serial_SyncAndExchangeNybble
	ld a, [wSerialExchangeNybbleReceiveData]
	cp [hl]	
	jr nz, .fail	;the handshake fails if the digit recieved does not match the digit sent
	inc hl	;otherwise increment to the next digit and loop.
	jr .loop	
.fail
	pop hl
	pop af
	jp LinkMenu.choseCancel
.pass
	pop hl
	pop af
	jp LinkMenu.next
HandshakeList:	
;This serves as a version control passcode.
;Each digit of the passcode is one nybble.
;FF is used as an end-of-list marker.
	db $1
	db $1
	db $7
	db $a
	db $ff
 
Back
Top