shithub: pokecrystal

Download patch

ref: b50dd57cbb8e163cd269255c8f754e5631760a03
parent: 2d3a94b7c4ba033bdbfa382611a18b71a68349d4
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Thu Apr 23 12:10:46 EDT 2020

Miscellaneous updates and corrections

--- a/audio/sfx.asm
+++ b/audio/sfx.asm
@@ -3327,7 +3327,7 @@
 	note B_, 16
 	sound_ret
 
-	db $fd
+	db sound_loop_cmd
 
 Sfx_DexFanfare200229:
 	channel_count 4
--- a/docs/design_flaws.md
+++ b/docs/design_flaws.md
@@ -617,7 +617,7 @@
  	add hl, bc
  	add hl, bc
 +	add hl, bc
-+	b = bank
++	; b = bank
 +	ld a, BANK(PokedexDataPointerTable)
 +	call GetFarByte
 +	ld b, a
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -6219,7 +6219,7 @@
 ; Fill stats
 	ld de, wEnemyMonMaxHP
 	ld b, FALSE
-	ld hl, wEnemyMonDVs - (MON_DVS - MON_STAT_EXP + 1) ; wLinkBattleRNs + 7 ; ?
+	ld hl, wEnemyMonDVs - (MON_DVS - MON_STAT_EXP + 1)
 	predef CalcMonStats
 
 ; If we're in a trainer battle,
@@ -8401,7 +8401,7 @@
 	ld a, BANK(sLinkBattleStats)
 	call GetSRAMBank
 
-	call AddLastMobileBattleToLinkRecord
+	call AddLastLinkBattleToLinkRecord
 	call ReadAndPrintLinkBattleRecord
 
 	call CloseSRAM
@@ -8442,6 +8442,9 @@
 	cp LINK_MOBILE
 	ret
 
+LINK_BATTLE_RECORD_LENGTH EQUS "(sLinkBattleRecord1End - sLinkBattleRecord1)" ; 18
+NUM_LINK_BATTLE_RECORDS EQUS "((sLinkBattleStatsEnd - sLinkBattleRecord) / LINK_BATTLE_RECORD_LENGTH)" ; 5
+
 _DisplayLinkRecord:
 	ld a, BANK(sLinkBattleStats)
 	call GetSRAMBank
@@ -8467,7 +8470,7 @@
 	call ClearSprites
 	call .PrintBattleRecord
 	hlcoord 0, 8
-	ld b, 5
+	ld b, NUM_LINK_BATTLE_RECORDS
 	ld de, sLinkBattleRecord + 2
 .loop
 	push bc
@@ -8484,7 +8487,7 @@
 	ld h, d
 	ld l, e
 	ld de, wd002
-	ld bc, 10
+	ld bc, NAME_LENGTH - 1
 	call CopyBytes
 	ld a, "@"
 	ld [de], a
@@ -8521,7 +8524,7 @@
 	call PlaceString
 .next
 	pop hl
-	ld bc, 18
+	ld bc, LINK_BATTLE_RECORD_LENGTH
 	add hl, bc
 	ld d, h
 	ld e, l
@@ -8694,7 +8697,7 @@
 	ld hl, wRoamMon3Species
 	ret
 
-AddLastMobileBattleToLinkRecord:
+AddLastLinkBattleToLinkRecord:
 	ld hl, wOTPlayerID
 	ld de, wStringBuffer1
 	ld bc, 2
@@ -8702,10 +8705,10 @@
 	ld hl, wOTPlayerName
 	ld bc, NAME_LENGTH - 1
 	call CopyBytes
-	ld hl, sLinkBattleResults
+	ld hl, sLinkBattleStats - (LINK_BATTLE_RECORD_LENGTH - 6)
 	call .StoreResult
 	ld hl, sLinkBattleRecord
-	ld d, 5
+	ld d, NUM_LINK_BATTLE_RECORDS
 .loop
 	push hl
 	inc hl
@@ -8716,17 +8719,17 @@
 	and a
 	jr z, .copy
 	push de
-	ld bc, 12
+	ld bc, LINK_BATTLE_RECORD_LENGTH - 6
 	ld de, wStringBuffer1
 	call CompareBytesLong
 	pop de
 	pop hl
 	jr c, .done
-	ld bc, 18
+	ld bc, LINK_BATTLE_RECORD_LENGTH
 	add hl, bc
 	dec d
 	jr nz, .loop
-	ld bc, -18
+	ld bc, -LINK_BATTLE_RECORD_LENGTH
 	add hl, bc
 	push hl
 
@@ -8734,7 +8737,7 @@
 	ld d, h
 	ld e, l
 	ld hl, wStringBuffer1
-	ld bc, 12
+	ld bc, LINK_BATTLE_RECORD_LENGTH - 6
 	call CopyBytes
 	ld b, 6
 	xor a
@@ -8749,16 +8752,17 @@
 	call .StoreResult
 	call .FindOpponentAndAppendRecord
 	ret
+
 .StoreResult:
 	ld a, [wBattleResult]
 	and $f
 	cp LOSE
-	ld bc, sLinkBattleWins + 1 - sLinkBattleResults
+	ld bc, (sLinkBattleRecord1Wins - sLinkBattleRecord1) + 1
 	jr c, .okay ; WIN
-	ld bc, sLinkBattleLosses + 1 - sLinkBattleResults
+	ld bc, (sLinkBattleRecord1Losses - sLinkBattleRecord1) + 1
 	jr z, .okay ; LOSE
 	; DRAW
-	ld bc, sLinkBattleDraws + 1 - sLinkBattleResults
+	ld bc, (sLinkBattleRecord1Draws - sLinkBattleRecord1) + 1
 .okay
 	add hl, bc
 	call .CheckOverflow
@@ -8780,8 +8784,8 @@
 	ret
 
 .FindOpponentAndAppendRecord:
-	ld b, 5
-	ld hl, sLinkBattleRecord + 17
+	ld b, NUM_LINK_BATTLE_RECORDS
+	ld hl, sLinkBattleRecord1End - 1
 	ld de, wd002
 .loop3
 	push bc
@@ -8799,7 +8803,7 @@
 	ld a, c
 	ld [de], a
 	inc de
-	ld bc, 18
+	ld bc, LINK_BATTLE_RECORD_LENGTH
 	add hl, bc
 	pop bc
 	dec b
@@ -8848,26 +8852,26 @@
 .done2
 	push bc
 	ld a, b
-	ld bc, 18
+	ld bc, LINK_BATTLE_RECORD_LENGTH
 	ld hl, sLinkBattleRecord
 	call AddNTimes
 	push hl
 	ld de, wd002
-	ld bc, 18
+	ld bc, LINK_BATTLE_RECORD_LENGTH
 	call CopyBytes
 	pop hl
 	pop bc
 	push hl
 	ld a, c
-	ld bc, 18
+	ld bc, LINK_BATTLE_RECORD_LENGTH
 	ld hl, sLinkBattleRecord
 	call AddNTimes
 	pop de
 	push hl
-	ld bc, 18
+	ld bc, LINK_BATTLE_RECORD_LENGTH
 	call CopyBytes
 	ld hl, wd002
-	ld bc, 18
+	ld bc, LINK_BATTLE_RECORD_LENGTH
 	pop de
 	call CopyBytes
 	ret
--- a/macros/code.asm
+++ b/macros/code.asm
@@ -51,7 +51,7 @@
 ; input: a = a signed 6-bit value
 ; output: a = d * sin(a * pi/32)
 	and %111111
-	cp  %100000
+	cp %100000
 	jr nc, .negative\@
 	call .apply\@
 	ld a, h
--- a/macros/wram.asm
+++ b/macros/wram.asm
@@ -238,6 +238,7 @@
 \1Wins::   dw
 \1Losses:: dw
 \1Draws::  dw
+\1End::
 ENDM
 
 trademon: MACRO
--- a/sram.asm
+++ b/sram.asm
@@ -125,12 +125,10 @@
 sBox:: box sBox
 ; b160
 
-	ds $f4
+	ds $100
 
 
 SECTION "Link Battle Data", SRAM
-
-sLinkBattleResults:: ds $c
 
 sLinkBattleStats::
 sLinkBattleWins::   dw ; b260
--- a/wram.asm
+++ b/wram.asm
@@ -2851,15 +2851,15 @@
 
 wVisitedSpawns:: flag_array NUM_SPAWNS ; dca5
 
-wDigWarpNumber:: db ; dcaa
-wDigMapGroup::   db ; dcab
-wDigMapNumber::  db ; dcac
+wDigWarpNumber:: db ; dca9
+wDigMapGroup::   db ; dcaa
+wDigMapNumber::  db ; dcab
 
 ; used on maps like second floor pokécenter, which are reused, so we know which
 ; map to return to
-wBackupWarpNumber:: db ; dcad
-wBackupMapGroup::   db ; dcae
-wBackupMapNumber::  db ; dcaf
+wBackupWarpNumber:: db ; dcac
+wBackupMapGroup::   db ; dcad
+wBackupMapNumber::  db ; dcae
 
 	ds 3