Skip to content

Commit 6303b29

Browse files
Rangi42FredrIQitsdarsh
authored
Implement the newbox PC storage system (#608)
(Squashed from the `newbox` branch) Many thanks to FIQ for rewriting the backend to (a) navigate all the boxes without saving, and (b) store 16 boxes instead of 14 (320 Pokémon instead of 280)! Also for a Gen 3+-style frontend with colored icons and Menu/Swap/Item modes. And to darsh for writing BSP scripts so that Prism's `bspcomp` can patch old save files as far back as 2019. The `box_struct` is no longer a subset of `party_struct`; instead, `party_struct` is encoded to `savemon_struct` on deposit and decoded on withdraw. (They still begin with mostly the same fields, but `savemon_struct` stores a single PP Up byte and has 7-bit encoded nickname and OT fields with a checksum in the 8th bits. This means that PP as well as HP and status will be restored on deposit.) Long-term plans include using redrawn icons by choosh based on Crystal Clear, with the same palettes as full-size sprites; and rearranging more of the struct fields to allow 10-bit mon, move, and item IDs (up to 510 of each), 20-bit OT ID (6 digits, 000000-999999), or even 5-bit IVs (0-31 instead of 0-15). Fixes #510 Co-authored-by: Fredrik Ljungdahl <fredde1994@gmail.com> Co-authored-by: itsdarsh <twitteruserdarsh@gmail.com>
1 parent dbdc9c6 commit 6303b29

File tree

111 files changed

+13609
-5272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+13609
-5272
lines changed

.github/workflows/main.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
mv polishedcrystal-3.0.0-beta.gbc build/polishedcrystal-3.0.0-faithful-debug-beta.gbc
4040
mv polishedcrystal-3.0.0-beta.sym build/polishedcrystal-3.0.0-faithful-debug-beta.sym
4141
make tidy
42+
make bsp
43+
mv polishedcrystal-3.0.0-beta.bsp build/polishedcrystal-3.0.0-beta.bsp
4244
popd
4345
- name: Delete old release
4446
id: delete_release
@@ -145,3 +147,13 @@ jobs:
145147
asset_path: ./polishedcrystal/build/polishedcrystal-3.0.0-faithful-debug-beta.sym
146148
asset_name: polishedcrystal-3.0.0-beta-${{ env.SHORT_SHA }}-faithful-debug.sym
147149
asset_content_type: text/plain
150+
- name: Upload BSP
151+
id: upload-bsp
152+
uses: actions/upload-release-asset@v1.0.1
153+
env:
154+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155+
with:
156+
upload_url: ${{ steps.create_release.outputs.upload_url }}
157+
asset_path: ./polishedcrystal/build/polishedcrystal-3.0.0-beta.bsp
158+
asset_name: polishedcrystal-3.0.0-beta-${{ env.SHORT_SHA }}.bsp
159+
asset_content_type: application/octet-stream

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.map
44
*.sym
55
*.exe
6+
*.bsp
67
*.h.gch
78
*.pyc
89
*$py.class

CREDITS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Pokémon Polished Crystal would never have been finished without the help of man
1515
* luckytyphlosion for performance optimizations to the game engine, and a 60FPS overworld.
1616
* The TPP Anniversary Crystal 251 dev team for making their code publically usable (specifically: the Move Relearner, automatic box switching, Gen VI money loss, and caught data stats page code).
1717
* Sanqui for the music player with piano roll visualization.
18-
* ax6 for porting the xorshift+ PRNG from Prism.
18+
* ax6 for porting the xorshift+ PRNG from Prism as well as developing bsp and related patching functions originally for Prism.
1919
* MeroMero for the in-battle color inversion code, Smeargle color code, and some move animations.
2020
* kroc for the no-RTC code.
2121
* VictoriaLacroix for the Running Shoes routine.

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ gfx/misc.o
5858

5959

6060
.SUFFIXES:
61-
.PHONY: clean tidy crystal faithful nortc debug monochrome freespace tools
61+
.PHONY: clean tidy crystal faithful nortc debug monochrome freespace tools bsp
6262
.SECONDEXPANSION:
6363
.PRECIOUS: %.2bpp %.1bpp
6464
.SECONDARY:
@@ -82,15 +82,17 @@ clean: tidy
8282
find gfx \( -name '*.[12]bpp' -o -name '*.2bpp.vram[012]' -o -name '*.2bpp.vram[012]p' \) -delete
8383
find gfx/pokemon -mindepth 1 \( -name 'bitmask.asm' -o -name 'frames.asm' -o -name 'front.animated.tilemap' -o -name 'front.dimensions' \) -delete
8484
find data/tilesets -name '*_collision.bin' -delete
85+
$(MAKE) clean -C tools/
8586

8687
tidy:
87-
rm -f $(crystal_obj) $(wildcard $(NAME)-*.gbc) $(wildcard $(NAME)-*.map) $(wildcard $(NAME)-*.sym)
88-
$(MAKE) clean -C tools/
88+
rm -f $(crystal_obj) $(wildcard $(NAME)-*.gbc) $(wildcard $(NAME)-*.map) $(wildcard $(NAME)-*.sym) $(wildcard $(NAME)-*.bsp)
8989

9090
freespace: ROM_NAME = $(NAME)-$(VERSION)
91-
freespace: crystal
91+
freespace: crystal tools/bankends
9292
tools/bankends $(ROM_NAME).map > bank_ends.txt
9393

94+
bsp: $(NAME)-$(VERSION).bsp
95+
9496

9597
define DEP
9698
$1: $2 $$(shell tools/scan_includes $2)
@@ -109,6 +111,10 @@ endif
109111
$(RGBDS_DIR)rgbfix $(RGBFIX_FLAGS) $@
110112
tools/bankends -q $(ROM_NAME).map
111113

114+
.bsp: tools/bspcomp
115+
%.bsp: $(wildcard bsp/*.txt)
116+
cd bsp; ../tools/bspcomp patch.txt ../$@; cd ..
117+
112118

113119
gfx/battle/lyra_back.2bpp: rgbgfx += -h
114120

@@ -163,6 +169,8 @@ gfx/pokegear/pokegear_sprites.2bpp: tools/gfx += --trim-whitespace
163169

164170
gfx/pokemon/%/back.2bpp: rgbgfx += -h
165171

172+
gfx/pc/obj.2bpp: gfx/pc/modes.2bpp gfx/pc/bags.2bpp ; cat $^ > $@
173+
166174
gfx/slots/slots_1.2bpp: tools/gfx += --trim-whitespace
167175
gfx/slots/slots_2.2bpp: tools/gfx += --interleave --png=$<
168176
gfx/slots/slots_3.2bpp: tools/gfx += --interleave --png=$< --remove-duplicates --keep-whitespace --remove-xflip

audio/music_player.asm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ endc
108108
MusicPlayer::
109109
call ClearTileMap
110110

111+
ld a, LOW(LCDMusicPlayer)
112+
ldh [hFunctionTargetLo], a
113+
ld a, HIGH(LCDMusicPlayer)
114+
ldh [hFunctionTargetHi], a
115+
111116
; Load palette
112117
ld hl, rIE
113118
set LCD_STAT, [hl]

bsp/apply_party_patches.txt

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
ApplyPartyPatches:
2+
; #1: callback, will receive party pointer, nickname pointer, OT pointer, location (0 = party, 1 = box, 2 = daycare)
3+
push #e
4+
push #d
5+
push #c
6+
push #b
7+
push #a
8+
set #a, #1
9+
set #1, 5
10+
call GetGameDataOffsetConstant
11+
set #1, #result
12+
call GetGameDataPointer
13+
seek #result
14+
readbyte #temp
15+
add #1, #result, 8
16+
add #2, #result, 0x16a
17+
add #3, #result, 0x128
18+
set #4, #zero
19+
callnz #temp, .apply_to_list
20+
set #1, 6
21+
call GetGameDataOffsetConstant
22+
set #1, #result
23+
call GetGameDataPointer
24+
seek #result
25+
readbyte #temp
26+
shiftleft #temp, 31 ; nonzero if bit 0 is set
27+
callnz #temp, .daycare_mon
28+
set #1, 7
29+
call GetGameDataOffsetConstant
30+
set #1, #result
31+
call GetGameDataPointer
32+
seek #result
33+
readbyte #temp
34+
shiftleft #temp, 31
35+
; there are two extra bytes for the daycare lady we need to skip
36+
; (#1 should end up on sBreedmon2, not sBreedmon2Item)
37+
readhalfword #result ; move file pointer ahead
38+
pos #result
39+
callnz #temp, .daycare_mon
40+
set #b, sBox1_v6
41+
call .boxes
42+
set #b, sBox8_v6
43+
call .boxes
44+
pop #a
45+
pop #b
46+
pop #c
47+
pop #d
48+
pop #e
49+
return
50+
51+
.boxes
52+
set #c, 7
53+
.box_loop
54+
seek #b
55+
readbyte #temp
56+
add #1, #b, 22
57+
add #2, #b, 882
58+
add #3, #b, 662
59+
set #4, 1
60+
callnz #temp, .apply_to_list
61+
add #b, BOX_SIZE_v6
62+
decrement #c
63+
jumpnz #c, .box_loop
64+
return
65+
66+
.daycare_mon
67+
add #1, #result, 23
68+
add #2, #result, 1
69+
add #3, #result, 12
70+
set #4, 2
71+
rotateleft #temp, 1
72+
.apply_to_list
73+
set #d, #temp
74+
set #e, #4
75+
.loop
76+
push #3
77+
push #2
78+
push #1
79+
set #4, #e
80+
call #a
81+
pop #1
82+
set #4, PARTYMON_STRUCT_LENGTH
83+
jumpz #e, .length_OK
84+
set #4, BOXMON_STRUCT_LENGTH
85+
.length_OK
86+
add #1, #4
87+
pop #2
88+
add #2, NAME_LENGTH
89+
pop #3
90+
add #3, NAME_LENGTH
91+
decrement #d
92+
jumpnz #d, .loop
93+
return

bsp/constants.txt

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
; size constants
2+
define BANK_SIZE, 0x4000
3+
define BANKS, 0x80
4+
define ROM_SIZE, 0x200000
5+
define HASH_SIZE, 20
6+
define SAVE_SIZE, 0x8000
7+
8+
; SRAM pointers
9+
define sPartyMail, 0x0600
10+
define sMailbox, 0x0835
11+
define sBackupMailbox, 0x0a0c
12+
define sSaveVersion, 0x0be2
13+
define sBackupOptions, 0x1200
14+
define sBackupCheckValue1, 0x1207
15+
define sBackupGameData, 0x1208
16+
define sBackupChecksum, 0x1f0d
17+
define sBackupCheckValue2, 0x1f0f
18+
define sOptions, 0x2000
19+
define sCheckValue1, 0x2007
20+
define sGameData, 0x2008
21+
define sChecksum, 0x2d0d
22+
define sCheckValue2, 0x2d0f
23+
define sNewBox1, 0x2d10
24+
define sBackupNewBox1, 0x2f20
25+
define sLinkBattleRecord, 0x3266
26+
define sByteBeforeHallOfFame, 0x32bf
27+
define sBoxMons1, 0x4000
28+
define sBoxMons1UsedEntries, 0x5fc6
29+
define sBoxMons2, 0x6000
30+
define sBoxMons2UsedEntries, 0x7fc6
31+
32+
; game data offsets
33+
define PLAYER_NAME_OFFSET, 0x003
34+
define ITEMS_OFFSET, 0x38d
35+
define MEDICINE_OFFSET, 0x425
36+
define BALLS_OFFSET, 0x471
37+
define BERRIES_OFFSET, 0x4a5
38+
define PC_ITEMS_OFFSET, 0x4e5
39+
define BOX_NAMES_OFFSET, 0x6e1
40+
define MAP_GROUP_OFFSET, 0x834
41+
define PARTY_COUNT_OFFSET, 0x856
42+
define PARTY_MON_OT_OFFSET, 0x97e
43+
define POKEDEX_CAUGHT_OFFSET, 0xa0b
44+
define DAYCARE_MAN_OFFSET, 0xa6a
45+
define BREED_MON_1_NICK_OFFSET, 0xa6b
46+
define BREED_MON_1_OT_OFFSET, 0xa76
47+
define DAYCARE_LADY_OFFSET, 0xaa1
48+
define BREED_MON_2_NICK_OFFSET, 0xaa4
49+
define BREED_MON_2_OT_OFFSET, 0Xaaf
50+
define EGG_MON_NICK_OFFSET, 0xada
51+
define MAGIKARP_RECORD_HOLDER_NAME_OFFSET, 0xb6b
52+
53+
; SRAM sizes
54+
define GAME_DATA_SIZE, 0xb7b
55+
define BOX_SIZE, 0x3d4
56+
57+
; struct lengths
58+
define PARTYMON_STRUCT_LENGTH, 48
59+
define BOXMON_STRUCT_LENGTH, 32
60+
define NAME_LENGTH, 11
61+
define BOX_NAME_LENGTH, 9
62+
define PLAYER_NAME_LENGTH, 8
63+
64+
; pokemon struct offsets
65+
define MOVES_OFFSET, 2
66+
define FORM_OFFSET, 21
67+
define PP_OFFSET, 22
68+
define CAUGHTBALL_OFFSET, 28
69+
70+
; pokemon struct constants
71+
define NUM_MOVES, 4
72+
define PP_MASK, 0x3f
73+
define PP_UP_MASK, 0xc0
74+
define FORM_MASK, 0x1f
75+
76+
; pokemon constants
77+
define GYARADOS, 0x82
78+
79+
; move constants
80+
define RAGE, 0x63
81+
define SELFDESTRUCT, 0x78 ; becomes Trick Room
82+
define FRESH_SNACK, 0x87
83+
define EXPLOSION, 0x99
84+
define FACADE, 0xab
85+
define MILK_DRINK, 0xd0 ; becomes Shell Smash
86+
define RETURN, 0xd8
87+
88+
; event flags
89+
define EVENT_GOT_SHUCKIE, 74
90+
define EVENT_MANIA_TOOK_SHUCKIE_OR_LET_YOU_KEEP_HIM, 75

0 commit comments

Comments
 (0)