shithub: pokered

Download patch

ref: 6a31663c960a5c1da9dbbf12d49e0252860b96d0
parent: bcc4380d40767983a0b253d486bb3c82f0f1fd07
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Tue Apr 27 11:49:59 EDT 2021

Use {interpolation} to generate sequences of RAM labels

Fixes #319

--- a/constants/gfx_constants.asm
+++ b/constants/gfx_constants.asm
@@ -17,6 +17,9 @@
 HP_BAR_YELLOW EQU 1
 HP_BAR_RED    EQU 2
 
+; wOAMBuffer
+NUM_SPRITE_OAM_STRUCTS EQU 40
+
 ; hAutoBGTransferEnabled
 TRANSFERTOP    EQU 0
 TRANSFERMIDDLE EQU 1
--- a/constants/map_object_constants.asm
+++ b/constants/map_object_constants.asm
@@ -38,6 +38,8 @@
 	const SPRITESTATEDATA2_0F                   ; f
 SPRITESTATEDATA2_LENGTH EQU const_value
 
+NUM_SPRITESTATEDATA_STRUCTS EQU 16
+
 ; different kinds of people events
 ITEM    EQU $80
 TRAINER EQU $40
--- a/engine/battle/misc.asm
+++ b/engine/battle/misc.asm
@@ -113,7 +113,7 @@
 	ld hl, wBoxSpecies
 	jr .getSpecies
 .enemyParty
-	ld hl, wEnemyPartyMons
+	ld hl, wEnemyPartySpecies
 .getSpecies
 	ld d, 0
 	add hl, de
--- a/engine/battle/read_trainer_party.asm
+++ b/engine/battle/read_trainer_party.asm
@@ -5,7 +5,7 @@
 	and a
 	ret nz
 
-; set [wEnemyPartyCount] to 0, [wEnemyPartyMons] to FF
+; set [wEnemyPartyCount] to 0, [wEnemyPartySpecies] to FF
 ; XXX first is total enemy pokemon?
 ; XXX second is species of first pokemon?
 	ld hl, wEnemyPartyCount
--- a/engine/events/give_pokemon.asm
+++ b/engine/events/give_pokemon.asm
@@ -7,7 +7,7 @@
 	ld a, [wPartyCount]
 	cp PARTY_LENGTH
 	jr c, .addToParty
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 	cp MONS_PER_BOX
 	jr nc, .boxFull
 ; add to box
--- a/engine/items/item_effects.asm
+++ b/engine/items/item_effects.asm
@@ -120,7 +120,7 @@
 	ld a, [wPartyCount] ; is party full?
 	cp PARTY_LENGTH
 	jr nz, .canUseBall
-	ld a, [wNumInBox] ; is box full?
+	ld a, [wBoxCount] ; is box full?
 	cp MONS_PER_BOX
 	jp z, BoxFullCannotThrowBall
 
@@ -2638,7 +2638,7 @@
 INCLUDE "data/items/key_items.asm"
 
 SendNewMonToBox:
-	ld de, wNumInBox
+	ld de, wBoxCount
 	ld a, [de]
 	inc a
 	ld [de], a
@@ -2657,7 +2657,7 @@
 	call GetMonHeader
 	ld hl, wBoxMonOT
 	ld bc, NAME_LENGTH
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 	dec a
 	jr z, .asm_e7ee
 	dec a
@@ -2668,7 +2668,7 @@
 	ld d, h
 	ld e, l
 	pop hl
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 	dec a
 	ld b, a
 .asm_e7db
@@ -2689,7 +2689,7 @@
 	ld de, wBoxMonOT
 	ld bc, NAME_LENGTH
 	call CopyData
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 	dec a
 	jr z, .asm_e82a
 	ld hl, wBoxMonNicks
@@ -2702,7 +2702,7 @@
 	ld d, h
 	ld e, l
 	pop hl
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 	dec a
 	ld b, a
 .asm_e817
@@ -2723,7 +2723,7 @@
 	ld a, NAME_MON_SCREEN
 	ld [wNamingScreenType], a
 	predef AskName
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 	dec a
 	jr z, .asm_e867
 	ld hl, wBoxMons
@@ -2736,7 +2736,7 @@
 	ld d, h
 	ld e, l
 	pop hl
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 	dec a
 	ld b, a
 .asm_e854
--- a/engine/link/cable_club.asm
+++ b/engine/link/cable_club.asm
@@ -648,7 +648,7 @@
 	ld de, wPartySpecies
 	call TradeCenter_PrintPartyListNames
 	hlcoord 2, 9
-	ld de, wEnemyPartyMons
+	ld de, wEnemyPartySpecies
 	; fall through
 
 TradeCenter_PrintPartyListNames:
@@ -701,8 +701,8 @@
 	ld bc, NAME_LENGTH
 	call CopyData
 	ld a, [wTradingWhichEnemyMon]
-	ld hl, wEnemyPartyMons
-	ld c, a
+	ld hl, wEnemyPartySpecies
+	ld c, a
 	ld b, 0
 	add hl, bc
 	ld a, [hl]
@@ -798,7 +798,7 @@
 	ld a, [wTradingWhichEnemyMon]
 	ld c, a
 	ld [wWhichPokemon], a
-	ld hl, wEnemyPartyMons
+	ld hl, wEnemyPartySpecies
 	ld d, 0
 	ld e, a
 	add hl, de
@@ -818,7 +818,7 @@
 	ld a, $1
 	ld [wForceEvolution], a
 	ld a, [wTradingWhichEnemyMon]
-	ld hl, wEnemyPartyMons
+	ld hl, wEnemyPartySpecies
 	ld b, 0
 	ld c, a
 	add hl, bc
--- a/engine/menus/save.asm
+++ b/engine/menus/save.asm
@@ -580,7 +580,7 @@
 	ld c, a
 	ld b, 0
 	add hl, bc
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 	ld [hl], a
 
 	ret
--- a/engine/movie/oak_speech/init_player_data.asm
+++ b/engine/movie/oak_speech/init_player_data.asm
@@ -14,7 +14,7 @@
 
 	ld hl, wPartyCount
 	call InitializeEmptyList
-	ld hl, wNumInBox
+	ld hl, wBoxCount
 	call InitializeEmptyList
 	ld hl, wNumBagItems
 	call InitializeEmptyList
--- a/engine/pokemon/add_mon.asm
+++ b/engine/pokemon/add_mon.asm
@@ -348,7 +348,7 @@
 	ld hl, wDayCareMon
 	jr z, .findMonDataSrc
 	; else it's PARTY_TO_BOX
-	ld hl, wNumInBox
+	ld hl, wBoxCount
 	ld a, [hl]
 	cp MONS_PER_BOX
 	jr nz, .partyOrBoxNotFull
@@ -385,7 +385,7 @@
 	; if it's PARTY_TO_BOX
 	ld hl, wBoxMons
 	ld bc, wBoxMon2 - wBoxMon1 ; $21
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 .addMonOffset
 	dec a
 	call AddNTimes
@@ -435,7 +435,7 @@
 	ld a, [wPartyCount]
 	jr nz, .addOToffset
 	ld hl, wBoxMonOT
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 .addOToffset
 	dec a
 	call SkipFixedLengthTextEntries
@@ -466,7 +466,7 @@
 	ld a, [wPartyCount]
 	jr nz, .addNickOffset
 	ld hl, wBoxMonNicks
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 .addNickOffset
 	dec a
 	call SkipFixedLengthTextEntries
--- a/engine/pokemon/bills_pc.asm
+++ b/engine/pokemon/bills_pc.asm
@@ -212,7 +212,7 @@
 	call PrintText
 	jp BillsPCMenu
 .partyLargeEnough
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 	cp MONS_PER_BOX
 	jr nz, .boxNotFull
 	ld hl, BoxFullText
@@ -254,7 +254,7 @@
 	jp BillsPCMenu
 
 BillsPCWithdraw:
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 	and a
 	jr nz, .boxNotEmpty
 	ld hl, NoMonText
@@ -268,7 +268,7 @@
 	call PrintText
 	jp BillsPCMenu
 .partyNotFull
-	ld hl, wNumInBox
+	ld hl, wBoxCount
 	call DisplayMonListMenu
 	jp c, BillsPCMenu
 	call DisplayDepositWithdrawMenu
@@ -291,7 +291,7 @@
 	jp BillsPCMenu
 
 BillsPCRelease:
-	ld a, [wNumInBox]
+	ld a, [wBoxCount]
 	and a
 	jr nz, .loop
 	ld hl, NoMonText
@@ -298,7 +298,7 @@
 	call PrintText
 	jp BillsPCMenu
 .loop
-	ld hl, wNumInBox
+	ld hl, wBoxCount
 	call DisplayMonListMenu
 	jp c, BillsPCMenu
 	ld hl, OnceReleasedText
--- a/engine/pokemon/remove_mon.asm
+++ b/engine/pokemon/remove_mon.asm
@@ -3,7 +3,7 @@
 	ld a, [wRemoveMonFromBox]
 	and a
 	jr z, .usePartyCount
-	ld hl, wNumInBox
+	ld hl, wBoxCount
 .usePartyCount
 	ld a, [hl]
 	dec a
--- a/sram.asm
+++ b/sram.asm
@@ -21,25 +21,30 @@
 sMainDataCheckSum:: ds 1
 
 
+; The PC boxes will not fit into one SRAM bank,
+; so they use multiple SECTIONs
+box_n = 0
+boxes: MACRO
+rept \1
+box_n = box_n + 1
+sBox{d:box_n}:: ds wBoxDataEnd - wBoxDataStart
+endr
+ENDM
+
 SECTION "Saved Boxes 1", SRAM ; BANK 2
 
-sBox1:: ds wBoxDataEnd - wBoxDataStart
-sBox2:: ds wBoxDataEnd - wBoxDataStart
-sBox3:: ds wBoxDataEnd - wBoxDataStart
-sBox4:: ds wBoxDataEnd - wBoxDataStart
-sBox5:: ds wBoxDataEnd - wBoxDataStart
-sBox6:: ds wBoxDataEnd - wBoxDataStart
+; sBox1 - sBox6
+	boxes 6
 sBank2AllBoxesChecksum:: ds 1
 sBank2IndividualBoxChecksums:: ds 6
 
-
 SECTION "Saved Boxes 2", SRAM ; BANK 3
 
-sBox7::  ds wBoxDataEnd - wBoxDataStart
-sBox8::  ds wBoxDataEnd - wBoxDataStart
-sBox9::  ds wBoxDataEnd - wBoxDataStart
-sBox10:: ds wBoxDataEnd - wBoxDataStart
-sBox11:: ds wBoxDataEnd - wBoxDataStart
-sBox12:: ds wBoxDataEnd - wBoxDataStart
+; sBox7 - sBox12
+	boxes 6
 sBank3AllBoxesChecksum:: ds 1
 sBank3IndividualBoxChecksums:: ds 6
+
+; All 12 boxes fit within 2 SRAM banks
+	assert box_n == NUM_BOXES, \
+		"boxes: Expected {d:NUM_BOXES} total boxes, got {d:box_n}"
--- a/vram.asm
+++ b/vram.asm
@@ -2,30 +2,30 @@
 
 UNION
 ; generic
-vChars0:: ds $800
-vChars1:: ds $800
-vChars2:: ds $800
-vBGMap0:: ds $400
-vBGMap1:: ds $400
+vChars0:: ds $80 tiles
+vChars1:: ds $80 tiles
+vChars2:: ds $80 tiles
+vBGMap0:: ds BG_MAP_WIDTH * BG_MAP_HEIGHT
+vBGMap1:: ds BG_MAP_WIDTH * BG_MAP_HEIGHT
 
 NEXTU
 ; battle/menu
-vSprites::  ds $800
-vFont::     ds $800
-vFrontPic:: ds 7 * 7 * $10
-vBackPic::  ds 7 * 7 * $10
+vSprites::  ds $80 tiles
+vFont::     ds $80 tiles
+vFrontPic:: ds 7 * 7 tiles
+vBackPic::  ds 7 * 7 tiles
 
 NEXTU
 ; overworld
-vNPCSprites::  ds $800
-vNPCSprites2:: ds $800
-vTileset::     ds $800
+vNPCSprites::  ds $80 tiles
+vNPCSprites2:: ds $80 tiles
+vTileset::     ds $80 tiles
 
 NEXTU
 ; title
-	ds $800
-vTitleLogo::  ds $800
-	ds 7 * 7 * $10
-vTitleLogo2:: ds $1e0
+	ds $80 tiles
+vTitleLogo::  ds $80 tiles
+	ds 7 * 7 tiles
+vTitleLogo2:: ds 30 tiles
 
 ENDU
--- a/wram.asm
+++ b/wram.asm
@@ -175,22 +175,11 @@
 ; - D
 ; - E
 ; - F
-wSpritePlayerStateData1::  spritestatedata1 wSpritePlayerStateData1
-wSprite01StateData1::      spritestatedata1 wSprite01StateData1
-wSprite02StateData1::      spritestatedata1 wSprite02StateData1
-wSprite03StateData1::      spritestatedata1 wSprite03StateData1
-wSprite04StateData1::      spritestatedata1 wSprite04StateData1
-wSprite05StateData1::      spritestatedata1 wSprite05StateData1
-wSprite06StateData1::      spritestatedata1 wSprite06StateData1
-wSprite07StateData1::      spritestatedata1 wSprite07StateData1
-wSprite08StateData1::      spritestatedata1 wSprite08StateData1
-wSprite09StateData1::      spritestatedata1 wSprite09StateData1
-wSprite10StateData1::      spritestatedata1 wSprite10StateData1
-wSprite11StateData1::      spritestatedata1 wSprite11StateData1
-wSprite12StateData1::      spritestatedata1 wSprite12StateData1
-wSprite13StateData1::      spritestatedata1 wSprite13StateData1
-wSprite14StateData1::      spritestatedata1 wSprite14StateData1
-wSprite15StateData1::      spritestatedata1 wSprite15StateData1
+wSpritePlayerStateData1::  spritestatedata1 wSpritePlayerStateData1 ; player is struct 0
+; wSprite02StateData1 - wSprite15StateData1
+for n, 1, NUM_SPRITESTATEDATA_STRUCTS
+wSprite{02d:n}StateData1:: spritestatedata1 wSprite{02d:n}StateData1
+endr
 
 wSpriteStateData2::
 ; more data for all sprites on the current map
@@ -213,23 +202,16 @@
 ; - D: picture ID
 ; - E: sprite image base offset (in video ram, player always has value 1, used to compute sprite image index)
 ; - F
-wSpritePlayerStateData2::  spritestatedata2 wSpritePlayerStateData2
-wSprite01StateData2::      spritestatedata2 wSprite01StateData2
-wSprite02StateData2::      spritestatedata2 wSprite02StateData2
-wSprite03StateData2::      spritestatedata2 wSprite03StateData2
-wSprite04StateData2::      spritestatedata2 wSprite04StateData2
-wSprite05StateData2::      spritestatedata2 wSprite05StateData2
-wSprite06StateData2::      spritestatedata2 wSprite06StateData2
-wSprite07StateData2::      spritestatedata2 wSprite07StateData2
-wSprite08StateData2::      spritestatedata2 wSprite08StateData2
-wSprite09StateData2::      spritestatedata2 wSprite09StateData2
-wSprite10StateData2::      spritestatedata2 wSprite10StateData2
-wSprite11StateData2::      spritestatedata2 wSprite11StateData2
-wSprite12StateData2::      spritestatedata2 wSprite12StateData2
-wSprite13StateData2::      spritestatedata2 wSprite13StateData2
-wSprite14StateData2::      spritestatedata2 wSprite14StateData2
-wSprite15StateData2::      spritestatedata2 wSprite15StateData2
+wSpritePlayerStateData2::  spritestatedata2 wSpritePlayerStateData2 ; player is struct 0
+; wSprite02StateData2 - wSprite15StateData2
+for n, 1, NUM_SPRITESTATEDATA_STRUCTS
+wSprite{02d:n}StateData2:: spritestatedata2 wSprite{02d:n}StateData2
+endr
 
+; The high byte of a pointer to anywhere within wSpriteStateData1 can be incremented
+; to reach within wSpriteStateData2, and vice-versa for decrementing.
+assert HIGH(wSpriteStateData1) + 1 == HIGH(wSpriteStateData2)
+assert LOW(wSpriteStateData1) == 0
 
 wSpriteDataEnd::
 
@@ -238,7 +220,10 @@
 
 wOAMBuffer::
 ; buffer for OAM data. Copied to OAM by DMA
-	ds 4 * 40
+; wOAMBufferSprite00 - wOAMBufferSprite39
+for n, NUM_SPRITE_OAM_STRUCTS
+wOAMBufferSprite{02d:n}:: ds 4
+endr
 wOAMBufferEnd::
 
 wTileMap::
@@ -2027,7 +2012,7 @@
 
 wMoves::
 ; list of moves for FormatMovesString
-	ds 4
+	ds NUM_MOVES
 
 wMoveNum::
 	ds 1
@@ -2236,20 +2221,26 @@
 
 wPartyDataStart::
 
-wPartyCount::   ds 1
-wPartySpecies:: ds PARTY_LENGTH
-wPartyEnd::     ds 1
+wPartyCount:: ds 1
+wPartySpecies:: ds PARTY_LENGTH + 1
 
 wPartyMons::
-wPartyMon1:: party_struct wPartyMon1
-wPartyMon2:: party_struct wPartyMon2
-wPartyMon3:: party_struct wPartyMon3
-wPartyMon4:: party_struct wPartyMon4
-wPartyMon5:: party_struct wPartyMon5
-wPartyMon6:: party_struct wPartyMon6
+; wPartyMon1 - wPartyMon6
+for n, 1, PARTY_LENGTH + 1
+wPartyMon{d:n}:: party_struct wPartyMon{d:n}
+endr
 
-wPartyMonOT::    ds NAME_LENGTH * PARTY_LENGTH
-wPartyMonNicks:: ds NAME_LENGTH * PARTY_LENGTH
+wPartyMonOT::
+; wPartyMon1OT - wPartyMon6OT
+for n, 1, PARTY_LENGTH + 1
+wPartyMon{d:n}OT:: ds NAME_LENGTH
+endr
+
+wPartyMonNicks::
+; wPartyMon1Nick - wPartyMon6Nick
+for n, 1, PARTY_LENGTH + 1
+wPartyMon{d:n}Nick:: ds NAME_LENGTH
+endr
 wPartyMonNicksEnd::
 
 wPartyDataEnd::
@@ -3071,19 +3062,26 @@
 	ds 9
 
 wEnemyPartyCount:: ds 1
-wEnemyPartyMons::  ds PARTY_LENGTH + 1
+wEnemyPartySpecies:: ds PARTY_LENGTH + 1
 
 wEnemyMons::
-wEnemyMon1:: party_struct wEnemyMon1
-wEnemyMon2:: party_struct wEnemyMon2
-wEnemyMon3:: party_struct wEnemyMon3
-wEnemyMon4:: party_struct wEnemyMon4
-wEnemyMon5:: party_struct wEnemyMon5
-wEnemyMon6:: party_struct wEnemyMon6
+; wEnemyMon1 - wEnemyMon6
+for n, 1, PARTY_LENGTH + 1
+wEnemyMon{d:n}:: party_struct wEnemyMon{d:n}
+endr
 
-wEnemyMonOT::    ds NAME_LENGTH * PARTY_LENGTH
-wEnemyMonNicks:: ds NAME_LENGTH * PARTY_LENGTH
+wEnemyMonOT::
+; wEnemyMon1OT - wEnemyMon6OT
+for n, 1, PARTY_LENGTH + 1
+wEnemyMon{d:n}OT:: ds NAME_LENGTH
+endr
 
+wEnemyMonNicks::
+; wEnemyMon1Nick - wEnemyMon6Nick
+for n, 1, PARTY_LENGTH + 1
+wEnemyMon{d:n}Nick:: ds NAME_LENGTH
+endr
+
 ENDU
 
 
@@ -3139,15 +3137,27 @@
 
 wBoxDataStart::
 
-wNumInBox::  ds 1
+wBoxCount:: ds 1
 wBoxSpecies:: ds MONS_PER_BOX + 1
 
 wBoxMons::
-wBoxMon1:: box_struct wBoxMon1
-wBoxMon2:: ds BOX_STRUCT_LENGTH * (MONS_PER_BOX - 1)
 
-wBoxMonOT::    ds NAME_LENGTH * MONS_PER_BOX
-wBoxMonNicks:: ds NAME_LENGTH * MONS_PER_BOX
+; wBoxMon1 - wBoxMon20
+for n, 1, MONS_PER_BOX + 1
+wBoxMon{d:n}:: box_struct wBoxMon{d:n}
+endr
+
+wBoxMonOT::
+; wBoxMon1OT - wBoxMon20OT
+for n, 1, MONS_PER_BOX + 1
+wBoxMon{d:n}OT:: ds NAME_LENGTH
+endr
+
+wBoxMonNicks::
+; wBoxMon1Nick - wBoxMon20Nick
+for n, 1, MONS_PER_BOX + 1
+wBoxMon{d:n}Nick:: ds NAME_LENGTH
+endr
 wBoxMonNicksEnd::
 
 wBoxDataEnd::