Skip to content

Commit

Permalink
Virtual Console patch for Polished Crystal (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
vulcandth authored Jun 6, 2022
1 parent 4863d51 commit e1b26db
Show file tree
Hide file tree
Showing 19 changed files with 829 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
*.link text
Makefile text

# Declare files that will always have CRLF line endings on checkout.
*.patch.template text eol=crlf linguist-language=INI

# hexdump binary files
*.png binary diff=hex
*.lz binary diff=hex
Expand Down
54 changes: 50 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,24 @@ jobs:
git clone https://github.com/Rangi42/polishedcrystal.git
pushd polishedcrystal
mkdir build
make -j4
make -j4 vc
mv polishedcrystal-3.0.0-beta.gbc build/
mv polishedcrystal-3.0.0-beta.patch build/
mv polishedcrystal-3.0.0-beta.sym build/
make tidy
make -j4 faithful
make -j4 faithful vc
mv polishedcrystal-faithful-3.0.0-beta.gbc build/
mv polishedcrystal-faithful-3.0.0-beta.patch build/
mv polishedcrystal-faithful-3.0.0-beta.sym build/
make tidy
make -j4 noir
make -j4 noir vc
mv polishedcrystal-noir-3.0.0-beta.gbc build/
mv polishedcrystal-noir-3.0.0-beta.patch build/
mv polishedcrystal-noir-3.0.0-beta.sym build/
make tidy
make -j4 debug
make -j4 debug vc
mv polishedcrystal-debug-3.0.0-beta.gbc build/polisheddebug-3.0.0-beta.gbc
mv polishedcrystal-debug-3.0.0-beta.patch build/polisheddebug-3.0.0-beta.patch
mv polishedcrystal-debug-3.0.0-beta.sym build/polisheddebug-3.0.0-beta.sym
make tidy
make bsp
Expand Down Expand Up @@ -74,6 +78,8 @@ jobs:
The **.sym** assets are "symbol files". They're useful for debugging, or for [discovering cheat codes](https://github.com/pret/pokecrystal/wiki/Discovering-GameShark-cheat-codes), although cheats are *not* officially supported and may cause bugs or crashes. (Do ***not*** ask the developers for cheat codes.)
The **.patch** assets are 3DS Virtual Console patches to enable trading and battling over Wi-Fi. You can bundle the .gbc and corresponding .patch into a playable .cia file using [poke-cia](https://github.com/vulcandth/poke-cia).
The **.bsp** asset is a [BSP](https://github.com/aaaaaa123456789/bsp) save file patch in case you need to upgrade a save file from an older 3.0.0 beta build, using a patcher like the one for [Pokémon Prism](http://pokemonprism.com/patcher.html).
The **polisheddebug** assets are ROMs and symbol files with extra features to help debug the game. Do ***not*** download these to just play with; use them to help the developers diagnose and fix bugs, or create new features.
Expand All @@ -89,6 +95,16 @@ jobs:
asset_path: ./polishedcrystal/build/polishedcrystal-3.0.0-beta.gbc
asset_name: polishedcrystal-3.0.0-beta-${{ env.SHORT_SHA }}.gbc
asset_content_type: application/octet-stream
- name: Upload PATCH
id: upload-patch
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./polishedcrystal/build/polishedcrystal-3.0.0-beta.patch
asset_name: polishedcrystal-3.0.0-beta-${{ env.SHORT_SHA }}.patch
asset_content_type: application/octet-stream
- name: Upload SYM
id: upload-sym
uses: actions/[email protected]
Expand All @@ -109,6 +125,16 @@ jobs:
asset_path: ./polishedcrystal/build/polishedcrystal-faithful-3.0.0-beta.gbc
asset_name: polishedcrystal-faithful-3.0.0-beta-${{ env.SHORT_SHA }}.gbc
asset_content_type: application/octet-stream
- name: Upload faithful PATCH
id: upload-faithful-patch
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./polishedcrystal/build/polishedcrystal-faithful-3.0.0-beta.patch
asset_name: polishedcrystal-faithful-3.0.0-beta-${{ env.SHORT_SHA }}.patch
asset_content_type: application/octet-stream
- name: Upload faithful SYM
id: upload-faithful-sym
uses: actions/[email protected]
Expand All @@ -129,6 +155,16 @@ jobs:
asset_path: ./polishedcrystal/build/polishedcrystal-noir-3.0.0-beta.gbc
asset_name: polishedcrystal-noir-3.0.0-beta-${{ env.SHORT_SHA }}.gbc
asset_content_type: application/octet-stream
- name: Upload noir PATCH
id: upload-noir-patch
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./polishedcrystal/build/polishedcrystal-noir-3.0.0-beta.patch
asset_name: polishedcrystal-noir-3.0.0-beta-${{ env.SHORT_SHA }}.patch
asset_content_type: application/octet-stream
- name: Upload noir SYM
id: upload-noir-sym
uses: actions/[email protected]
Expand All @@ -149,6 +185,16 @@ jobs:
asset_path: ./polishedcrystal/build/polisheddebug-3.0.0-beta.gbc
asset_name: polisheddebug-3.0.0-beta-${{ env.SHORT_SHA }}.gbc
asset_content_type: application/octet-stream
- name: Upload debug PATCH
id: upload-debug-patch
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./polishedcrystal/build/polisheddebug-3.0.0-beta.patch
asset_name: polisheddebug-3.0.0-beta-${{ env.SHORT_SHA }}.patch
asset_content_type: application/octet-stream
- name: Upload debug SYM
id: upload-debug-sym
uses: actions/[email protected]
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ data/tilesets/*_collision.bin
# compiled roms
*.gbc
*.pocket
*.patch

# compiled patch
*.bsp
Expand Down
41 changes: 31 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ Q :=

.SECONDEXPANSION:

RGBASM_FLAGS = -E -Weverything -Wnumeric-string=2 -Wtruncation=1
RGBLINK_FLAGS = -n $(ROM_NAME).sym -m $(ROM_NAME).map -l layout.link -p $(FILLER)
RGBFIX_FLAGS = -csjv -t $(TITLE) -i $(MCODE) -n $(ROMVERSION) -p $(FILLER) -k 01 -l 0x33 -m 0x10 -r 3
RGBASM_FLAGS = -E -Weverything -Wnumeric-string=2 -Wtruncation=1
RGBASM_VC_FLAGS =
RGBLINK_FLAGS = -n $(ROM_NAME).sym -m $(ROM_NAME).map -p $(FILLER)
RGBLINK_VC_FLAGS = -n $(ROM_NAME)_vc.sym -m $(ROM_NAME)_vc.map -p $(FILLER)
RGBFIX_FLAGS = -csjv -t $(TITLE) -i $(MCODE) -n $(ROMVERSION) -p $(FILLER) -k 01 -l 0x33 -m 0x10 -r 3

ifeq ($(filter faithful,$(MAKECMDGOALS)),faithful)
MODIFIERS := $(MODIFIERS)-faithful
Expand Down Expand Up @@ -60,8 +62,11 @@ ifeq ($(filter huffman,$(MAKECMDGOALS)),huffman)
Q := @
RGBASM_FLAGS += -DHUFFMAN
endif
ifeq ($(filter vc,$(MAKECMDGOALS)),vc)
RGBASM_VC_FLAGS += $(RGBASM_FLAGS) -DVIRTUAL_CONSOLE
endif

crystal_obj := \
rom_obj := \
main.o \
home.o \
ram.o \
Expand All @@ -81,21 +86,24 @@ gfx/sprites.o \
gfx/items.o \
gfx/misc.o

crystal_obj := $(rom_obj:.o=.o)
crystal_vc_obj :=$(rom_obj:.o=_vc.o)

.SUFFIXES:
.PHONY: clean tidy crystal faithful nortc pocket debug monochrome freespace tools bsp huffman
.PHONY: clean tidy crystal faithful nortc pocket debug monochrome freespace tools bsp huffman vc
.PRECIOUS: %.2bpp %.1bpp
.SECONDARY:
.DEFAULT_GOAL: crystal

crystal: $$(ROM_NAME).$$(EXTENSION)
crystal: $$(ROM_NAME).$$(EXTENSION)
faithful: crystal
nortc: crystal
monochrome: crystal
noir: crystal
hgss: crystal
debug: crystal
pocket: crystal
vc: $$(ROM_NAME).patch

tools:
$(MAKE) -C tools/
Expand All @@ -109,8 +117,8 @@ clean: tidy
$(MAKE) clean -C tools/

tidy:
$(RM) $(crystal_obj) $(wildcard $(NAME)-*.gbc) $(wildcard $(NAME)-*.pocket) $(wildcard $(NAME)-*.bsp) \
$(wildcard $(NAME)-*.map) $(wildcard $(NAME)-*.sym) rgbdscheck.o
$(RM) $(crystal_obj) $(crystal_vc_obj) $(wildcard $(NAME)-*.gbc) $(wildcard $(NAME)-*.pocket) $(wildcard $(NAME)-*.bsp) \
$(wildcard $(NAME)-*.map) $(wildcard $(NAME)-*.sym) $(wildcard $(NAME)-*.patch) rgbdscheck.o

freespace: crystal tools/bankends
tools/bankends $(ROM_NAME).map > bank_ends.txt
Expand All @@ -128,18 +136,31 @@ $1: $2 $$(shell tools/scan_includes $2) | rgbdscheck.o
$Q$$(RGBDS_DIR)rgbasm $$(RGBASM_FLAGS) -L -o $$@ $$<
endef

define VCDEP
$1: $2 $$(shell tools/scan_includes $2) | rgbdscheck.o
$Q$$(RGBDS_DIR)rgbasm $$(RGBASM_VC_FLAGS) -L -o $$@ $$<
endef

ifeq (,$(filter clean tidy tools,$(MAKECMDGOALS)))
$(info $(shell $(MAKE) -C tools))
$(foreach obj, $(crystal_obj), $(eval $(call DEP,$(obj),$(obj:.o=.asm))))
$(foreach obj, $(crystal_vc_obj), $(eval $(call VCDEP,$(obj),$(obj:_vc.o=.asm))))
endif

$(ROM_NAME).patch: $(ROM_NAME)_vc.gbc $(ROM_NAME).$(EXTENSION) vc.patch.template
tools/make_patch $(ROM_NAME)_vc.sym $^ $@

.$(EXTENSION): tools/bankends
%.$(EXTENSION): $(crystal_obj)
$Q$(RGBDS_DIR)rgblink $(RGBLINK_FLAGS) -o $@ $^
$(ROM_NAME).$(EXTENSION): $(crystal_obj) layout.link
$Q$(RGBDS_DIR)rgblink $(RGBLINK_FLAGS) -l layout.link -o $@ $(filter %.o,$^)
$Q$(RGBDS_DIR)rgbfix $(RGBFIX_FLAGS) $@
$Qtools/bankends -q $(ROM_NAME).map >&2

$(ROM_NAME)_vc.gbc: $(crystal_vc_obj) layout.link
$Q$(RGBDS_DIR)rgblink $(RGBLINK_VC_FLAGS) -l layout.link -o $@ $(filter %.o,$^)
$Q$(RGBDS_DIR)rgbfix $(RGBFIX_FLAGS) $@
$Qtools/bankends -q $(ROM_NAME)_vc.map >&2

.bsp: tools/bspcomp
%.bsp: $(wildcard bsp/*.txt)
$Qcd bsp; ../tools/bspcomp patch.txt ../$@; cd ..
Expand Down
16 changes: 16 additions & 0 deletions engine/battle/core.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5582,6 +5582,7 @@ LinkBattleSendReceiveAction:
; of linking we are performing.
call .StageForSend
ld [wLinkBattleSentAction], a
vc_hook Wireless_start_exchange
call PlaceWaitingText
ld a, [wLinkBattleSentAction]
ld [wPlayerLinkAction], a
Expand All @@ -5595,20 +5596,35 @@ LinkBattleSendReceiveAction:
inc a
jr z, .waiting

vc_hook Wireless_end_exchange
vc_patch Wireless_net_delay_3
if DEF(VIRTUAL_CONSOLE)
ld b, 26
else
ld b, 10
endc
vc_patch_end
.receive
call DelayFrame
call LinkTransfer
dec b
jr nz, .receive

vc_hook Wireless_start_send_zero_bytes
vc_patch Wireless_net_delay_4
if DEF(VIRTUAL_CONSOLE)
ld b, 26
else
ld b, 10
endc
vc_patch_end
.acknowledge
call DelayFrame
call LinkDataReceived
dec b
jr nz, .acknowledge

vc_hook Wireless_end_send_zero_bytes
ld a, [wOtherPlayerLinkAction]
ld [wBattleAction], a
ret
Expand Down
Loading

0 comments on commit e1b26db

Please sign in to comment.