Use HIGH() and LOW()

This commit is contained in:
Rangi 2020-07-07 11:10:29 -04:00
parent bbc257476f
commit 45ed05decf
22 changed files with 89 additions and 87 deletions

View file

@ -25,10 +25,10 @@
const Ch8 ; 7
; HW sound channel register base addresses
HW_CH1_BASE EQU (rNR10 % $100)
HW_CH2_BASE EQU ((rNR21 % $100) - 1)
HW_CH3_BASE EQU (rNR30 % $100)
HW_CH4_BASE EQU ((rNR41 % $100) - 1)
HW_CH1_BASE EQU LOW(rNR10)
HW_CH2_BASE EQU LOW(rNR21) - 1
HW_CH3_BASE EQU LOW(rNR30)
HW_CH4_BASE EQU LOW(rNR41) - 1
; HW sound channel enable bit masks
HW_CH1_ENABLE_MASK EQU %00010001

View file

@ -35,6 +35,8 @@ BRN EQU 4
FRZ EQU 5
PAR EQU 6
MAX_STAT_VALUE EQU 999
; volatile statuses 1
STORING_ENERGY EQU 0 ; Bide
THRASHING_ABOUT EQU 1 ; e.g. Thrash

View file

@ -4182,8 +4182,8 @@ GetDamageVarsForPlayerAttack:
; if the enemy has used Light Screen, double the enemy's special
sla c
rl b
; reflect and light screen boosts do not cap the stat at 999, so weird things will happen during stats scaling if
; a Pokemon with 512 or more Defense has used Reflect, or if a Pokemon with 512 or more Special has used Light Screen
; reflect and light screen boosts do not cap the stat at MAX_STAT_VALUE, so weird things will happen during stats scaling
; if a Pokemon with 512 or more Defense has used Reflect, or if a Pokemon with 512 or more Special has used Light Screen
.specialAttackCritCheck
ld hl, wBattleMonSpecial
ld a, [wCriticalHitOrOHKO]
@ -4295,8 +4295,8 @@ GetDamageVarsForEnemyAttack:
; if the player has used Light Screen, double the player's special
sla c
rl b
; reflect and light screen boosts do not cap the stat at 999, so weird things will happen during stats scaling if
; a Pokemon with 512 or more Defense has used Reflect, or if a Pokemon with 512 or more Special has used Light Screen
; reflect and light screen boosts do not cap the stat at MAX_STAT_VALUE, so weird things will happen during stats scaling
; if a Pokemon with 512 or more Defense has used Reflect, or if a Pokemon with 512 or more Special has used Light Screen
.specialAttackCritCheck
ld hl, wEnemyMonSpecial
ld a, [wCriticalHitOrOHKO]
@ -4508,14 +4508,14 @@ CalculateDamage:
jr nz, .cap
ldh a, [hQuotient + 2]
cp (MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) / $100
cp HIGH(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1)
jr c, .dont_cap_2
cp (MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) / $100 + 1
cp HIGH(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) + 1
jr nc, .cap
ldh a, [hQuotient + 3]
cp (MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) % $100
cp LOW(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1)
jr nc, .cap
.dont_cap_2
@ -4533,21 +4533,21 @@ CalculateDamage:
jr c, .cap
ld a, [hl]
cp (MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) / $100
cp HIGH(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1)
jr c, .dont_cap_3
cp (MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) / $100 + 1
cp HIGH(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) + 1
jr nc, .cap
inc hl
ld a, [hld]
cp (MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) % $100
cp LOW(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1)
jr c, .dont_cap_3
.cap
ld a, (MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE) / $100
ld a, HIGH(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE)
ld [hli], a
ld a, (MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE) % $100
ld a, LOW(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE)
ld [hld], a
.dont_cap_3
@ -6526,14 +6526,14 @@ CalculateModifiedStat:
call Divide
pop hl
ldh a, [hDividend + 3]
sub 999 % $100
sub LOW(MAX_STAT_VALUE)
ldh a, [hDividend + 2]
sbc 999 / $100
sbc HIGH(MAX_STAT_VALUE)
jp c, .storeNewStatValue
; cap the stat at 999
ld a, 999 / $100
; cap the stat at MAX_STAT_VALUE (999)
ld a, HIGH(MAX_STAT_VALUE)
ldh [hDividend + 2], a
ld a, 999 % $100
ld a, LOW(MAX_STAT_VALUE)
ldh [hDividend + 3], a
.storeNewStatValue
ldh a, [hDividend + 2]
@ -6573,7 +6573,7 @@ ApplyBadgeStatBoosts:
ret
; multiply stat at hl by 1.125
; cap stat at 999
; cap stat at MAX_STAT_VALUE
.applyBoostToStat
ld a, [hli]
ld d, a
@ -6591,13 +6591,13 @@ ApplyBadgeStatBoosts:
adc d
ld [hli], a
ld a, [hld]
sub 999 % $100
sub LOW(MAX_STAT_VALUE)
ld a, [hl]
sbc 999 / $100
sbc HIGH(MAX_STAT_VALUE)
ret c
ld a, 999 / $100
ld a, HIGH(MAX_STAT_VALUE)
ld [hli], a
ld a, 999 % $100
ld a, LOW(MAX_STAT_VALUE)
ld [hld], a
ret

View file

@ -399,11 +399,12 @@ StatModifierUpEffect:
inc d ; de = unmodified (original) stat
.checkIf999
pop bc
; check if stat is already 999
ld a, [hld]
sub 999 % $100 ; check if stat is already 999
sub LOW(MAX_STAT_VALUE)
jr nz, .recalculateStat
ld a, [hl]
sbc 999 / $100
sbc HIGH(MAX_STAT_VALUE)
jp z, RestoreOriginalStatModifier
.recalculateStat ; recalculate affected stat
; paralysis and burn penalties, as well as badge boosts are ignored
@ -431,15 +432,15 @@ StatModifierUpEffect:
ld b, $4
call Divide
pop hl
; cap at 999
; cap at MAX_STAT_VALUE (999)
ldh a, [hProduct + 3]
sub 999 % $100
sub LOW(MAX_STAT_VALUE)
ldh a, [hProduct + 2]
sbc 999 / $100
sbc HIGH(MAX_STAT_VALUE)
jp c, UpdateStat
ld a, 999 / $100
ld a, HIGH(MAX_STAT_VALUE)
ldh [hMultiplicand + 1], a
ld a, 999 % $100
ld a, LOW(MAX_STAT_VALUE)
ldh [hMultiplicand + 2], a
UpdateStat:

View file

@ -236,7 +236,7 @@ WriteMonPartySpriteOAM:
; make a copy at wMonPartySpritesSavedOAM.
push af
ld c, $10
ld h, wOAMBuffer / $100
ld h, HIGH(wOAMBuffer)
ldh a, [hPartyMonIndex]
swap a
ld l, a

View file

@ -1,7 +1,7 @@
WriteDMACodeToHRAM::
; Since no other memory is available during OAM DMA,
; DMARoutine is copied to HRAM and executed there.
ld c, hDMARoutine % $100
ld c, LOW(hDMARoutine)
ld b, DMARoutineEnd - DMARoutine
ld hl, DMARoutine
.copy
@ -14,7 +14,7 @@ WriteDMACodeToHRAM::
DMARoutine:
; initiate DMA
ld a, wOAMBuffer / $100
ld a, HIGH(wOAMBuffer)
ldh [rDMA], a
; wait for DMA to finish

View file

@ -18,7 +18,7 @@ PrepareOAMData::
.spriteLoop
ldh [hSpriteOffset2], a
ld d, wSpriteStateData1 / $100
ld d, HIGH(wSpriteStateData1)
ldh a, [hSpriteOffset2]
ld e, a
ld a, [de] ; c1x0
@ -79,7 +79,7 @@ PrepareOAMData::
ldh a, [hOAMBufferOffset]
ld e, a
ld d, wOAMBuffer / $100
ld d, HIGH(wOAMBuffer)
.tileLoop
ldh a, [hSpriteScreenY] ; temp for sprite Y position
@ -141,13 +141,13 @@ PrepareOAMData::
.nextSprite
ldh a, [hSpriteOffset2]
add $10
cp $100 % $100
cp LOW($100)
jp nz, .spriteLoop
; Clear unused OAM.
ldh a, [hOAMBufferOffset]
ld l, a
ld h, wOAMBuffer / $100
ld h, HIGH(wOAMBuffer)
ld de, $4
ld b, $a0
ld a, [wd736]

View file

@ -12,10 +12,10 @@ AddItemToInventory_::
push hl
push hl
ld d, PC_ITEM_CAPACITY ; how many items the PC can hold
ld a, wNumBagItems & $FF
ld a, LOW(wNumBagItems)
cp l
jr nz, .checkIfInventoryFull
ld a, wNumBagItems >> 8
ld a, HIGH(wNumBagItems)
cp h
jr nz, .checkIfInventoryFull
; if the destination is the bag

View file

@ -255,9 +255,9 @@ CableClub_DoBattleOrTradeAgain:
ld hl, wEnemyMons + (SERIAL_PREAMBLE_BYTE - 1)
dec c
jr nz, .unpatchEnemyMonsLoop
ld a, wEnemyMonOT % $100
ld a, LOW(wEnemyMonOT)
ld [wUnusedCF8D], a
ld a, wEnemyMonOT / $100
ld a, HIGH(wEnemyMonOT)
ld [wUnusedCF8D + 1], a
xor a
ld [wTradeCenterPointerTableIndex], a

View file

@ -23,9 +23,9 @@ InitPlayerData2:
START_MONEY EQU $3000
ld hl, wPlayerMoney + 1
ld a, START_MONEY / $100
ld a, HIGH(START_MONEY)
ld [hld], a
xor a
xor a ; LOW(START_MONEY)
ld [hli], a
inc hl
ld [hl], a

View file

@ -126,13 +126,13 @@ ENDC
ld [wTitleMonSpecies], a
call LoadTitleMonSprite
ld a, (vBGMap0 + $300) / $100
ld a, HIGH(vBGMap0 + $300)
call TitleScreenCopyTileMapToVRAM
call SaveScreenTilesToBuffer1
ld a, $40
ldh [hWY], a
call LoadScreenTilesFromBuffer2
ld a, vBGMap0 / $100
ld a, HIGH(vBGMap0)
call TitleScreenCopyTileMapToVRAM
ld b, SET_PAL_TITLE_SCREEN
call RunPaletteCommand
@ -205,7 +205,7 @@ ENDC
and a
jr nz, .scrollTitleScreenGameVersionLoop
ld a, vBGMap1 / $100
ld a, HIGH(vBGMap1)
call TitleScreenCopyTileMapToVRAM
call LoadScreenTilesFromBuffer2
call PrintGameVersionOnTitleScreen
@ -241,9 +241,9 @@ ENDC
inc a
ldh [hAutoBGTransferEnabled], a
call ClearScreen
ld a, vBGMap0 / $100
ld a, HIGH(vBGMap0)
call TitleScreenCopyTileMapToVRAM
ld a, vBGMap1 / $100
ld a, HIGH(vBGMap1)
call TitleScreenCopyTileMapToVRAM
call Delay3
call LoadGBPal
@ -258,7 +258,7 @@ ENDC
farjp DoClearSaveDialogue
TitleScreenPickNewMon:
ld a, vBGMap0 / $100
ld a, HIGH(vBGMap0)
call TitleScreenCopyTileMapToVRAM
.loop

View file

@ -237,7 +237,7 @@ Trade_ShowPlayerMon:
ld c, 10
call TextBoxBorder
call Trade_PrintPlayerMonInfoText
ld b, vBGMap0 / $100
ld b, HIGH(vBGMap0)
call CopyScreenTileBufferToVRAM
call ClearScreen
ld a, [wTradedPlayerMonSpecies]
@ -266,7 +266,7 @@ Trade_ShowPlayerMon:
Trade_DrawOpenEndOfLinkCable:
call Trade_ClearTileMap
ld b, vBGMap0 / $100
ld b, HIGH(vBGMap0)
call CopyScreenTileBufferToVRAM
ld b, SET_PAL_GENERIC
call RunPaletteCommand

View file

@ -56,7 +56,7 @@ ShakeElevatorRedrawRow:
add hl, de
ld a, h
and $3
or vBGMap0 / $100
or HIGH(vBGMap0)
ld d, a
ld a, l
pop hl

View file

@ -23,7 +23,7 @@ UpdatePlayerSprite:
ret
.lowerLeftTileIsMapTile
call DetectCollisionBetweenSprites
ld h, wSpriteStateData1 / $100
ld h, HIGH(wSpriteStateData1)
ld a, [wWalkCounter]
and a
jr nz, .moving
@ -395,7 +395,7 @@ UpdateSpriteMovementDelay:
ld l, a
ld [hl], $1 ; c1x1 = 1 (mark as ready to move)
notYetMoving:
ld h, wSpriteStateData1 / $100
ld h, HIGH(wSpriteStateData1)
ldh a, [hCurrentSpriteOffset]
add wSpritePlayerStateData1AnimFrameCounter - wSpritePlayerStateData1
ld l, a
@ -450,7 +450,7 @@ InitializeSpriteStatus:
; calculates the sprite's screen position form its map position and the player position
InitializeSpriteScreenPosition:
ld h, wSpriteStateData2 / $100
ld h, HIGH(wSpriteStateData2)
ldh a, [hCurrentSpriteOffset]
add wSpritePlayerStateData2MapY - wSpritePlayerStateData2
ld l, a
@ -478,7 +478,7 @@ CheckSpriteAvailability:
ldh a, [hIsHiddenMissableObject]
and a
jp nz, .spriteInvisible
ld h, wSpriteStateData2 / $100
ld h, HIGH(wSpriteStateData2)
ldh a, [hCurrentSpriteOffset]
add wSpritePlayerStateData2MovementByte1 - wSpritePlayerStateData2
ld l, a
@ -526,7 +526,7 @@ CheckSpriteAvailability:
cp d
jr c, .spriteVisible ; standing on tile with ID >=MAP_TILESET_SIZE (top right tile)
.spriteInvisible
ld h, wSpriteStateData1 / $100
ld h, HIGH(wSpriteStateData1)
ldh a, [hCurrentSpriteOffset]
add wSpritePlayerStateData1ImageIndex - wSpritePlayerStateData1
ld l, a
@ -580,7 +580,7 @@ UpdateSpriteImage:
; e: X movement delta (-1, 0 or 1)
; set carry on failure, clears carry on success
CanWalkOntoTile:
ld h, wSpriteStateData2 / $100
ld h, HIGH(wSpriteStateData2)
ldh a, [hCurrentSpriteOffset]
add wSpritePlayerStateData2MovementByte1 - wSpritePlayerStateData2
ld l, a
@ -608,7 +608,7 @@ CanWalkOntoTile:
ld a, [hl] ; $c2x6 (movement byte 1)
inc a
jr z, .impassable ; if $ff, no movement allowed (however, changing direction is)
ld h, wSpriteStateData1 / $100
ld h, HIGH(wSpriteStateData1)
ldh a, [hCurrentSpriteOffset]
add wSpritePlayerStateData1YPixels - wSpritePlayerStateData1
ld l, a
@ -627,14 +627,14 @@ CanWalkOntoTile:
call DetectCollisionBetweenSprites
pop bc
pop de
ld h, wSpriteStateData1 / $100
ld h, HIGH(wSpriteStateData1)
ldh a, [hCurrentSpriteOffset]
add $c
ld l, a
ld a, [hl] ; c1xc (directions in which sprite collision would occur)
and b ; check against chosen direction (1,2,4 or 8)
jr nz, .impassable ; collision between sprites, don't go there
ld h, wSpriteStateData2 / $100
ld h, HIGH(wSpriteStateData2)
ldh a, [hCurrentSpriteOffset]
add wSpritePlayerStateData2YDisplacement - wSpritePlayerStateData2
ld l, a
@ -665,7 +665,7 @@ CanWalkOntoTile:
and a ; clear carry (marking success)
ret
.impassable
ld h, wSpriteStateData1 / $100
ld h, HIGH(wSpriteStateData1)
ldh a, [hCurrentSpriteOffset]
inc a
ld l, a
@ -691,7 +691,7 @@ CanWalkOntoTile:
; this is always the lower left tile of the 2x2 tile blocks all sprites are snapped to
; hl: output pointer
GetTileSpriteStandsOn:
ld h, wSpriteStateData1 / $100
ld h, HIGH(wSpriteStateData1)
ldh a, [hCurrentSpriteOffset]
add wSpritePlayerStateData1YPixels - wSpritePlayerStateData1
ld l, a

View file

@ -53,9 +53,9 @@ UpdateNonPlayerSprite:
DetectCollisionBetweenSprites:
nop
ld h, wSpriteStateData1 / $100
ld h, HIGH(wSpriteStateData1)
ldh a, [hCurrentSpriteOffset]
add wSpriteStateData1 % $100
add LOW(wSpriteStateData1)
ld l, a
ld a, [hl] ; a = [$c1i0] (picture) (0 if slot is unused)

View file

@ -294,7 +294,7 @@ SlotMachine_StopWheel1Early:
; Stop early if the middle symbol is not a cherry.
inc hl
ld a, [hl]
cp SLOTSCHERRY >> 8
cp HIGH(SLOTSCHERRY)
jr nz, .stopWheel
ret
; It looks like this was intended to make the wheel stop when a 7 symbol was
@ -303,7 +303,7 @@ SlotMachine_StopWheel1Early:
ld c, $3
.loop
ld a, [hli]
cp SLOTS7 >> 8
cp HIGH(SLOTS7)
jr c, .stopWheel ; condition never true
dec c
jr nz, .loop
@ -330,7 +330,7 @@ SlotMachine_StopWheel2Early:
.sevenAndBarMode
call SlotMachine_FindWheel1Wheel2Matches
ld a, [de]
cp (SLOTSBAR >> 8) + 1
cp HIGH(SLOTSBAR) + 1
ret nc
.stopWheel
xor a
@ -427,7 +427,7 @@ SlotMachine_CheckForMatches:
jr nz, .acceptMatch
; if 7/bar matches aren't enabled and the match was a 7/bar symbol, roll wheel
ld a, [hl]
cp (SLOTSBAR >> 8) + 1
cp HIGH(SLOTSBAR) + 1
jr c, .rollWheel3DownByOneSymbol
.acceptMatch
ld a, [hl]
@ -702,7 +702,7 @@ SlotMachine_PayCoinsToPlayer:
.skip1
ld [wAnimCounter], a
ld a, [wSlotMachineWinningSymbol]
cp (SLOTSBAR >> 8) + 1
cp HIGH(SLOTSBAR) + 1
ld c, 8
jr nc, .skip2
srl c ; c = 4 (make the the coins transfer faster if the symbol was 7 or bar)

View file

@ -1242,7 +1242,7 @@ StringCmp::
; c = X coordinate of upper left corner of sprite
; de = base address of 4 tile number and attribute pairs
WriteOAMBlock::
ld h, wOAMBuffer / $100
ld h, HIGH(wOAMBuffer)
swap a ; multiply by 16
ld l, a
call .writeOneEntry ; upper left

View file

@ -82,9 +82,9 @@ rLCDC_DEFAULT EQU %11100011
ld a, CONNECTION_NOT_ESTABLISHED
ldh [hSerialConnectionStatus], a
ld h, vBGMap0 / $100
ld h, HIGH(vBGMap0)
call ClearBgMap
ld h, vBGMap1 / $100
ld h, HIGH(vBGMap1)
call ClearBgMap
ld a, rLCDC_DEFAULT

View file

@ -197,17 +197,17 @@ CalcStat::
ldh [hMultiplicand+1], a ; HP: (((Base + IV) * 2 + ceil(Sqrt(stat exp)) / 4) * Level) / 100 + Level + 10
.noCarry4
ldh a, [hMultiplicand+1] ; check for overflow (>999)
cp 999 / $100 + 1
cp HIGH(MAX_STAT_VALUE) + 1
jr nc, .overflow
cp 999 / $100
cp HIGH(MAX_STAT_VALUE)
jr c, .noOverflow
ldh a, [hMultiplicand+2]
cp 999 % $100 + 1
cp LOW(MAX_STAT_VALUE) + 1
jr c, .noOverflow
.overflow
ld a, 999 / $100 ; overflow: cap at 999
ld a, HIGH(MAX_STAT_VALUE) ; overflow: cap at 999
ldh [hMultiplicand+1], a
ld a, 999 % $100
ld a, LOW(MAX_STAT_VALUE)
ldh [hMultiplicand+2], a
.noOverflow
pop bc

View file

@ -20,8 +20,8 @@ UncompressSpriteData::
; initializes necessary data to load a sprite and runs UncompressSpriteDataLoop
_UncompressSpriteData::
ld hl, sSpriteBuffer1
ld c, (2*SPRITEBUFFERSIZE) % $100
ld b, (2*SPRITEBUFFERSIZE) / $100
ld c, LOW(2 * SPRITEBUFFERSIZE)
ld b, HIGH(2 * SPRITEBUFFERSIZE)
xor a
call FillMemory ; clear sprite buffer 1 and 2
ld a, $1

View file

@ -141,8 +141,7 @@ ENDM
; stored in big endian
tempo: MACRO
db $ED
db \1 / $100
db \1 % $100
db HIGH(\1), LOW(\1)
ENDM
; arguments: left output enable mask, right output enable mask

View file

@ -182,9 +182,9 @@ SafariZoneGate_TextPointers:
call PrintText
ld a, 30
ld [wNumSafariBalls], a
ld a, 502 / $100
ld a, HIGH(502)
ld [wSafariSteps], a
ld a, 502 % $100
ld a, LOW(502)
ld [wSafariSteps + 1], a
ld a, D_UP
ld c, 3