ref: 77d0e5ff84cc61ae625da19f184094241eddd4dc
parent: 46c2a38c7c55ff01e8787dfd624cb1c771248b6c
author: xCrystal <rgr.crystal@gmail.com>
date: Wed Apr 1 12:16:43 EDT 2015
Rename battle files and split move effects Part 3 b.asm, b_2.asm, c.asm, and d.asm
--- a/engine/battle/b.asm
+++ /dev/null
@@ -1,18 +1,0 @@
-DisplayEffectiveness: ; 2fb7b (b:7b7b)
- ld a, [wDamageMultipliers]
- and a, $7F
- cp a, $0A
- ret z
- ld hl, SuperEffectiveText
- jr nc, .done
- ld hl, NotVeryEffectiveText
-.done
- jp PrintText
-
-SuperEffectiveText: ; 2fb8e (b:7b8e)
- TX_FAR _SuperEffectiveText
- db "@"
-
-NotVeryEffectiveText: ; 2fb93 (b:7b93)
- TX_FAR _NotVeryEffectiveText
- db "@"
--- a/engine/battle/b_2.asm
+++ /dev/null
@@ -1,129 +1,0 @@
-; scales both uncompressed sprite chunks by two in every dimension (creating 2x2 output pixels per input pixel)
-; assumes that input sprite chunks are 4x4 tiles, and the rightmost and bottommost 4 pixels will be ignored
-; resulting in a 7*7 tile output sprite chunk
-ScaleSpriteByTwo: ; 2fe40 (b:7e40)
- ld de, S_SPRITEBUFFER1 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped
- ld hl, S_SPRITEBUFFER0 + SPRITEBUFFERSIZE - 1 ; end of destination buffer
- call ScaleLastSpriteColumnByTwo ; last tile column is special case
- call ScaleFirstThreeSpriteColumnsByTwo ; scale first 3 tile columns
- ld de, S_SPRITEBUFFER2 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped
- ld hl, S_SPRITEBUFFER1 + SPRITEBUFFERSIZE - 1 ; end of destination buffer
- call ScaleLastSpriteColumnByTwo ; last tile column is special case
-
-ScaleFirstThreeSpriteColumnsByTwo: ; 2fe55 (b:7e55)
- ld b, $3 ; 3 tile columns
-.columnLoop
- ld c, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows
-.columnInnerLoop
- push bc
- ld a, [de]
- ld bc, -(7*8)+1 ; $ffc9, scale lower nybble and seek to previous output column
- call ScalePixelsByTwo
- ld a, [de]
- dec de
- swap a
- ld bc, 7*8+1-2 ; $37, scale upper nybble and seek back to current output column and to the next 2 rows
- call ScalePixelsByTwo
- pop bc
- dec c
- jr nz, .columnInnerLoop
- dec de
- dec de
- dec de
- dec de
- ld a, b
- ld bc, -7*8 ; $ffc8, skip one output column (which has already been written along with the current one)
- add hl, bc
- ld b, a
- dec b
- jr nz, .columnLoop
- ret
-
-ScaleLastSpriteColumnByTwo: ; 2fe7d (b:7e7d)
- ld a, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows
- ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b
- ld bc, -1 ; $ffff
-.columnInnerLoop
- ld a, [de]
- dec de
- swap a ; only high nybble contains information
- call ScalePixelsByTwo
- ld a, [H_SPRITEINTERLACECOUNTER] ; $ff8b
- dec a
- ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b
- jr nz, .columnInnerLoop
- dec de ; skip last 4 rows of new column
- dec de
- dec de
- dec de
- ret
-
-; scales the given 4 bits in a (4x1 pixels) to 2 output bytes (8x2 pixels)
-; hl: destination pointer
-; bc: destination pointer offset (added after the two bytes have been written)
-ScalePixelsByTwo: ; 2fe97 (b:7e97)
- push hl
- and $f
- ld hl, DuplicateBitsTable
- add l
- ld l, a
- jr nc, .noCarry
- inc h
-.noCarry
- ld a, [hl]
- pop hl
- ld [hld], a ; write output byte twice to make it 2 pixels high
- ld [hl], a
- add hl, bc ; add offset
- ret
-
-; repeats each input bit twice
-DuplicateBitsTable: ; 2fea8 (b:7ea8)
- db $00, $03, $0c, $0f
- db $30, $33, $3c, $3f
- db $c0, $c3, $cc, $cf
- db $f0, $f3, $fc, $ff
-
-PayDayEffect_ ; 2feb8 (b:7eb8)
- xor a
- ld hl, wcd6d
- ld [hli], a
- ld a, [H_WHOSETURN]
- and a
- ld a, [wBattleMonLevel]
- jr z, .asm_2fec8
- ld a, [wEnemyMonLevel]
-.asm_2fec8
- add a
- ld [H_DIVIDEND + 3], a
- xor a
- ld [H_DIVIDEND], a
- ld [H_DIVIDEND + 1], a
- ld [H_DIVIDEND + 2], a
- ld a, $64
- ld [H_DIVISOR], a
- ld b, $4
- call Divide
- ld a, [H_QUOTIENT + 3]
- ld [hli], a
- ld a, [H_REMAINDER]
- ld [H_DIVIDEND + 3], a
- ld a, $a
- ld [H_DIVISOR], a
- ld b, $4
- call Divide
- ld a, [H_QUOTIENT + 3]
- swap a
- ld b, a
- ld a, [H_REMAINDER]
- add b
- ld [hl], a
- ld de, wTotalPayDayMoney + 2
- ld c, $3
- predef AddBCDPredef
- ld hl, CoinsScatteredText
- jp PrintText
-
-CoinsScatteredText: ; 2ff04 (b:7f04)
- TX_FAR _CoinsScatteredText
- db "@"
--- a/engine/battle/c.asm
+++ /dev/null
@@ -1,58 +1,0 @@
-MistEffect_: ; 33f2b (c:7f2b)
- ld hl, W_PLAYERBATTSTATUS2
- ld a, [$fff3]
- and a
- jr z, .asm_33f36
- ld hl, W_ENEMYBATTSTATUS2
-.asm_33f36
- bit ProtectedByMist, [hl] ; is mon protected by mist?
- jr nz, .asm_33f4a
- set ProtectedByMist, [hl] ; mon is now protected by mist
- callab PlayCurrentMoveAnimation
- ld hl, ShroudedInMistText
- jp PrintText
-.asm_33f4a
- ld hl, PrintButItFailedText_
- ld b, BANK(PrintButItFailedText_)
- jp Bankswitch
-
-ShroudedInMistText: ; 33f52 (c:7f52)
- TX_FAR _ShroudedInMistText
- db "@"
-
-OneHitKOEffect_: ; 33f57 (c:7f57)
- ld hl, W_DAMAGE
- xor a
- ld [hli], a
- ld [hl], a ; set the damage output to zero
- dec a
- ld [wCriticalHitOrOHKO], a
- ld hl, wBattleMonSpeed + 1
- ld de, wEnemyMonSpeed + 1
- ld a, [H_WHOSETURN] ; $fff3
- and a
- jr z, .asm_33f72
- ld hl, wEnemyMonSpeed + 1
- ld de, wBattleMonSpeed + 1
-.asm_33f72
- ld a, [de]
- dec de
- ld b, a
- ld a, [hld]
- sub b
- ld a, [de]
- ld b, a
- ld a, [hl]
- sbc b
- jr c, .asm_33f8a
- ld hl, W_DAMAGE
- ld a, $ff
- ld [hli], a
- ld [hl], a
- ld a, $2
- ld [wCriticalHitOrOHKO], a
- ret
-.asm_33f8a
- ld a, $1
- ld [W_MOVEMISSED], a
- ret
--- a/engine/battle/d.asm
+++ /dev/null
@@ -1,23 +1,0 @@
-; display "[player] VS [enemy]" text box with pokeballs representing their parties next to the names
-DisplayLinkBattleVersusTextBox: ; 372d6 (d:72d6)
- call LoadTextBoxTilePatterns
- hlCoord 3, 4
- ld b, $7
- ld c, $c
- call TextBoxBorder
- hlCoord 4, 5
- ld de, wPlayerName
- call PlaceString
- hlCoord 4, 10
- ld de, wLinkEnemyTrainerName
- call PlaceString
-; place bold "VS" tiles between the names
- hlCoord 9, 8
- ld a, $69
- ld [hli], a
- ld [hl], $6a
- xor a
- ld [wUpdateSpritesEnabled], a
- callab SetupPlayerAndEnemyPokeballs
- ld c, 150
- jp DelayFrames
--- /dev/null
+++ b/engine/battle/display_effectiveness.asm
@@ -1,0 +1,18 @@
+DisplayEffectiveness: ; 2fb7b (b:7b7b)
+ ld a, [wDamageMultipliers]
+ and a, $7F
+ cp a, $0A
+ ret z
+ ld hl, SuperEffectiveText
+ jr nc, .done
+ ld hl, NotVeryEffectiveText
+.done
+ jp PrintText
+
+SuperEffectiveText: ; 2fb8e (b:7b8e)
+ TX_FAR _SuperEffectiveText
+ db "@"
+
+NotVeryEffectiveText: ; 2fb93 (b:7b93)
+ TX_FAR _NotVeryEffectiveText
+ db "@"
--- /dev/null
+++ b/engine/battle/link_battle_versus_text.asm
@@ -1,0 +1,23 @@
+; display "[player] VS [enemy]" text box with pokeballs representing their parties next to the names
+DisplayLinkBattleVersusTextBox: ; 372d6 (d:72d6)
+ call LoadTextBoxTilePatterns
+ hlCoord 3, 4
+ ld b, $7
+ ld c, $c
+ call TextBoxBorder
+ hlCoord 4, 5
+ ld de, wPlayerName
+ call PlaceString
+ hlCoord 4, 10
+ ld de, wLinkEnemyTrainerName
+ call PlaceString
+; place bold "VS" tiles between the names
+ hlCoord 9, 8
+ ld a, $69
+ ld [hli], a
+ ld [hl], $6a
+ xor a
+ ld [wUpdateSpritesEnabled], a
+ callab SetupPlayerAndEnemyPokeballs
+ ld c, 150
+ jp DelayFrames
--- /dev/null
+++ b/engine/battle/moveEffects/mist_effect.asm
@@ -1,0 +1,21 @@
+MistEffect_: ; 33f2b (c:7f2b)
+ ld hl, W_PLAYERBATTSTATUS2
+ ld a, [$fff3]
+ and a
+ jr z, .asm_33f36
+ ld hl, W_ENEMYBATTSTATUS2
+.asm_33f36
+ bit ProtectedByMist, [hl] ; is mon protected by mist?
+ jr nz, .asm_33f4a
+ set ProtectedByMist, [hl] ; mon is now protected by mist
+ callab PlayCurrentMoveAnimation
+ ld hl, ShroudedInMistText
+ jp PrintText
+.asm_33f4a
+ ld hl, PrintButItFailedText_
+ ld b, BANK(PrintButItFailedText_)
+ jp Bankswitch
+
+ShroudedInMistText: ; 33f52 (c:7f52)
+ TX_FAR _ShroudedInMistText
+ db "@"
--- /dev/null
+++ b/engine/battle/moveEffects/one_hit_ko_effect.asm
@@ -1,0 +1,36 @@
+OneHitKOEffect_: ; 33f57 (c:7f57)
+ ld hl, W_DAMAGE
+ xor a
+ ld [hli], a
+ ld [hl], a ; set the damage output to zero
+ dec a
+ ld [wCriticalHitOrOHKO], a
+ ld hl, wBattleMonSpeed + 1
+ ld de, wEnemyMonSpeed + 1
+ ld a, [H_WHOSETURN] ; $fff3
+ and a
+ jr z, .asm_33f72
+ ld hl, wEnemyMonSpeed + 1
+ ld de, wBattleMonSpeed + 1
+.asm_33f72
+ ld a, [de]
+ dec de
+ ld b, a
+ ld a, [hld]
+ sub b
+ ld a, [de]
+ ld b, a
+ ld a, [hl]
+ sbc b
+ jr c, .asm_33f8a
+ ld hl, W_DAMAGE
+ ld a, $ff
+ ld [hli], a
+ ld [hl], a
+ ld a, $2
+ ld [wCriticalHitOrOHKO], a
+ ret
+.asm_33f8a
+ ld a, $1
+ ld [W_MOVEMISSED], a
+ ret
--- /dev/null
+++ b/engine/battle/moveEffects/pay_day_effect.asm
@@ -1,0 +1,43 @@
+PayDayEffect_ ; 2feb8 (b:7eb8)
+ xor a
+ ld hl, wcd6d
+ ld [hli], a
+ ld a, [H_WHOSETURN]
+ and a
+ ld a, [wBattleMonLevel]
+ jr z, .asm_2fec8
+ ld a, [wEnemyMonLevel]
+.asm_2fec8
+ add a
+ ld [H_DIVIDEND + 3], a
+ xor a
+ ld [H_DIVIDEND], a
+ ld [H_DIVIDEND + 1], a
+ ld [H_DIVIDEND + 2], a
+ ld a, $64
+ ld [H_DIVISOR], a
+ ld b, $4
+ call Divide
+ ld a, [H_QUOTIENT + 3]
+ ld [hli], a
+ ld a, [H_REMAINDER]
+ ld [H_DIVIDEND + 3], a
+ ld a, $a
+ ld [H_DIVISOR], a
+ ld b, $4
+ call Divide
+ ld a, [H_QUOTIENT + 3]
+ swap a
+ ld b, a
+ ld a, [H_REMAINDER]
+ add b
+ ld [hl], a
+ ld de, wTotalPayDayMoney + 2
+ ld c, $3
+ predef AddBCDPredef
+ ld hl, CoinsScatteredText
+ jp PrintText
+
+CoinsScatteredText: ; 2ff04 (b:7f04)
+ TX_FAR _CoinsScatteredText
+ db "@"
--- /dev/null
+++ b/engine/battle/scale_sprites.asm
@@ -1,0 +1,85 @@
+; scales both uncompressed sprite chunks by two in every dimension (creating 2x2 output pixels per input pixel)
+; assumes that input sprite chunks are 4x4 tiles, and the rightmost and bottommost 4 pixels will be ignored
+; resulting in a 7*7 tile output sprite chunk
+ScaleSpriteByTwo: ; 2fe40 (b:7e40)
+ ld de, S_SPRITEBUFFER1 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped
+ ld hl, S_SPRITEBUFFER0 + SPRITEBUFFERSIZE - 1 ; end of destination buffer
+ call ScaleLastSpriteColumnByTwo ; last tile column is special case
+ call ScaleFirstThreeSpriteColumnsByTwo ; scale first 3 tile columns
+ ld de, S_SPRITEBUFFER2 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped
+ ld hl, S_SPRITEBUFFER1 + SPRITEBUFFERSIZE - 1 ; end of destination buffer
+ call ScaleLastSpriteColumnByTwo ; last tile column is special case
+
+ScaleFirstThreeSpriteColumnsByTwo: ; 2fe55 (b:7e55)
+ ld b, $3 ; 3 tile columns
+.columnLoop
+ ld c, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows
+.columnInnerLoop
+ push bc
+ ld a, [de]
+ ld bc, -(7*8)+1 ; $ffc9, scale lower nybble and seek to previous output column
+ call ScalePixelsByTwo
+ ld a, [de]
+ dec de
+ swap a
+ ld bc, 7*8+1-2 ; $37, scale upper nybble and seek back to current output column and to the next 2 rows
+ call ScalePixelsByTwo
+ pop bc
+ dec c
+ jr nz, .columnInnerLoop
+ dec de
+ dec de
+ dec de
+ dec de
+ ld a, b
+ ld bc, -7*8 ; $ffc8, skip one output column (which has already been written along with the current one)
+ add hl, bc
+ ld b, a
+ dec b
+ jr nz, .columnLoop
+ ret
+
+ScaleLastSpriteColumnByTwo: ; 2fe7d (b:7e7d)
+ ld a, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows
+ ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b
+ ld bc, -1 ; $ffff
+.columnInnerLoop
+ ld a, [de]
+ dec de
+ swap a ; only high nybble contains information
+ call ScalePixelsByTwo
+ ld a, [H_SPRITEINTERLACECOUNTER] ; $ff8b
+ dec a
+ ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b
+ jr nz, .columnInnerLoop
+ dec de ; skip last 4 rows of new column
+ dec de
+ dec de
+ dec de
+ ret
+
+; scales the given 4 bits in a (4x1 pixels) to 2 output bytes (8x2 pixels)
+; hl: destination pointer
+; bc: destination pointer offset (added after the two bytes have been written)
+ScalePixelsByTwo: ; 2fe97 (b:7e97)
+ push hl
+ and $f
+ ld hl, DuplicateBitsTable
+ add l
+ ld l, a
+ jr nc, .noCarry
+ inc h
+.noCarry
+ ld a, [hl]
+ pop hl
+ ld [hld], a ; write output byte twice to make it 2 pixels high
+ ld [hl], a
+ add hl, bc ; add offset
+ ret
+
+; repeats each input bit twice
+DuplicateBitsTable: ; 2fea8 (b:7ea8)
+ db $00, $03, $0c, $0f
+ db $30, $33, $3c, $3f
+ db $c0, $c3, $cc, $cf
+ db $f0, $f3, $fc, $ff
--- a/main.asm
+++ b/main.asm
@@ -5307,7 +5307,7 @@
SECTION "Battle (bank B)", ROMX, BANK[$B]
-INCLUDE "engine/battle/b.asm"
+INCLUDE "engine/battle/display_effectiveness.asm"
TrainerInfoTextBoxTileGraphics: INCBIN "gfx/trainer_info.2bpp"
BlankLeaderNames: INCBIN "gfx/blank_leader_names.2bpp"
@@ -5315,7 +5315,8 @@
BadgeNumbersTileGraphics: INCBIN "gfx/badge_numbers.2bpp"
INCLUDE "engine/items/tmhm.asm"
-INCLUDE "engine/battle/b_2.asm"
+INCLUDE "engine/battle/scale_sprites.asm"
+INCLUDE "engine/battle/moveEffects/pay_day_effect.asm"
INCLUDE "engine/game_corner_slots2.asm"
@@ -5385,7 +5386,8 @@
SECTION "Battle (bank C)", ROMX, BANK[$C]
-INCLUDE "engine/battle/c.asm"
+INCLUDE "engine/battle/moveEffects/mist_effect.asm"
+INCLUDE "engine/battle/moveEffects/one_hit_ko_effect.asm"
SECTION "Pics 5", ROMX, BANK[PICS_5]
@@ -5449,7 +5451,7 @@
SECTION "Battle (bank D)", ROMX, BANK[$D]
INCLUDE "engine/titlescreen2.asm"
-INCLUDE "engine/battle/d.asm"
+INCLUDE "engine/battle/link_battle_versus_text.asm"
INCLUDE "engine/slot_machine.asm"
INCLUDE "engine/overworld/pewter_guys.asm"
INCLUDE "engine/multiply_divide.asm"