Identify more bit flags (#465)

* Identify more bit flags

* Space
This commit is contained in:
Sylvie 2024-09-24 09:33:33 -04:00 committed by GitHub
parent c3f297e98b
commit b5d2540e7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 40 additions and 27 deletions

View file

@ -3,7 +3,7 @@ IndigoPlateauStatues::
ld hl, IndigoPlateauStatuesText1 ld hl, IndigoPlateauStatuesText1
call PrintText call PrintText
ld a, [wXCoord] ld a, [wXCoord]
bit 0, a bit 0, a ; even or odd?
ld hl, IndigoPlateauStatuesText2 ld hl, IndigoPlateauStatuesText2
jr nz, .ok jr nz, .ok
ld hl, IndigoPlateauStatuesText3 ld hl, IndigoPlateauStatuesText3

View file

@ -269,7 +269,7 @@ GetPartyMonSpriteID:
ld d, 0 ld d, 0
add hl, de add hl, de
ld a, [hl] ld a, [hl]
bit 0, c bit 0, c ; even or odd?
jr nz, .skipSwap jr nz, .skipSwap
swap a ; use lower nybble if pokedex num is even swap a ; use lower nybble if pokedex num is even
.skipSwap .skipSwap

View file

@ -61,7 +61,7 @@ PredefShakeScreenHorizontally:
ldh a, [hMutateWX] ldh a, [hMutateWX]
xor b xor b
ldh [hMutateWX], a ldh [hMutateWX], a
bit 7, a bit 7, a ; negative?
jr z, .skipZeroing jr z, .skipZeroing
xor a ; zero a if it's negative xor a ; zero a if it's negative
.skipZeroing .skipZeroing

View file

@ -4,9 +4,9 @@ PrepareOakSpeech:
ld a, [wOptions] ld a, [wOptions]
push af push af
; Retrieve BIT_DEBUG_MODE set in DebugMenu for StartNewGameDebug. ; Retrieve BIT_DEBUG_MODE set in DebugMenu for StartNewGameDebug.
; BUG: StartNewGame carries over bit 5 from previous save files, ; BUG: StartNewGame carries over BIT_ALWAYS_ON_BIKE from previous save files,
; which causes CheckForceBikeOrSurf to not return. ; which causes CheckForceBikeOrSurf to not return.
; To fix this in debug builds, reset bit 5 here or in StartNewGame. ; To fix this in debug builds, reset BIT_ALWAYS_ON_BIKE here or in StartNewGame.
; In non-debug builds, the instructions can be removed. ; In non-debug builds, the instructions can be removed.
ld a, [wStatusFlags6] ld a, [wStatusFlags6]
push af push af

View file

@ -187,7 +187,7 @@ LoadMapSpriteTilePatterns:
jr nz, .loadWhileLCDOn jr nz, .loadWhileLCDOn
pop af pop af
pop hl pop hl
set 3, h ; add $80 tiles to hl set 3, h ; add $800 ($80 tiles) to hl (1 << 3 == $8)
push hl push hl
ld h, d ld h, d
ld l, e ld l, e
@ -200,7 +200,7 @@ LoadMapSpriteTilePatterns:
.loadWhileLCDOn .loadWhileLCDOn
pop af pop af
pop hl pop hl
set 3, h ; add $80 tiles to hl set 3, h ; add $800 ($80 tiles) to hl (1 << 3 == $8)
ld b, a ld b, a
swap c swap c
call CopyVideoData ; load tile pattern data for sprite when walking call CopyVideoData ; load tile pattern data for sprite when walking

View file

@ -641,7 +641,7 @@ CanWalkOntoTile:
add SPRITESTATEDATA2_YDISPLACEMENT add SPRITESTATEDATA2_YDISPLACEMENT
ld l, a ld l, a
ld a, [hli] ; x#SPRITESTATEDATA2_YDISPLACEMENT (initialized at $8, keep track of where a sprite did go) ld a, [hli] ; x#SPRITESTATEDATA2_YDISPLACEMENT (initialized at $8, keep track of where a sprite did go)
bit 7, d ; check if going upwards (d=$ff) bit 7, d ; check if going upwards (d == -1)
jr nz, .upwards jr nz, .upwards
add d add d
; bug: these tests against $5 probably were supposed to prevent ; bug: these tests against $5 probably were supposed to prevent
@ -658,7 +658,7 @@ CanWalkOntoTile:
.checkHorizontal .checkHorizontal
ld d, a ld d, a
ld a, [hl] ; x#SPRITESTATEDATA2_XDISPLACEMENT (initialized at $8, keep track of where a sprite did go) ld a, [hl] ; x#SPRITESTATEDATA2_XDISPLACEMENT (initialized at $8, keep track of where a sprite did go)
bit 7, e ; check if going left (e=$ff) bit 7, e ; check if going left (e == -1)
jr nz, .left jr nz, .left
add e add e
cp $5 ; compare, but no conditional jump like in the vertical check above (bug?) cp $5 ; compare, but no conditional jump like in the vertical check above (bug?)

View file

@ -294,6 +294,13 @@ _GetTileAndCoordsInFrontOfPlayer:
ld [wTileInFrontOfPlayer], a ld [wTileInFrontOfPlayer], a
ret ret
; hPlayerFacing
const_def
const BIT_FACING_DOWN ; 0
const BIT_FACING_UP ; 1
const BIT_FACING_LEFT ; 2
const BIT_FACING_RIGHT ; 3
GetTileTwoStepsInFrontOfPlayer: GetTileTwoStepsInFrontOfPlayer:
xor a xor a
ldh [hPlayerFacing], a ldh [hPlayerFacing], a
@ -306,7 +313,7 @@ GetTileTwoStepsInFrontOfPlayer:
jr nz, .notFacingDown jr nz, .notFacingDown
; facing down ; facing down
ld hl, hPlayerFacing ld hl, hPlayerFacing
set 0, [hl] set BIT_FACING_DOWN, [hl]
lda_coord 8, 13 lda_coord 8, 13
inc d inc d
jr .storeTile jr .storeTile
@ -315,7 +322,7 @@ GetTileTwoStepsInFrontOfPlayer:
jr nz, .notFacingUp jr nz, .notFacingUp
; facing up ; facing up
ld hl, hPlayerFacing ld hl, hPlayerFacing
set 1, [hl] set BIT_FACING_UP, [hl]
lda_coord 8, 5 lda_coord 8, 5
dec d dec d
jr .storeTile jr .storeTile
@ -324,7 +331,7 @@ GetTileTwoStepsInFrontOfPlayer:
jr nz, .notFacingLeft jr nz, .notFacingLeft
; facing left ; facing left
ld hl, hPlayerFacing ld hl, hPlayerFacing
set 2, [hl] set BIT_FACING_LEFT, [hl]
lda_coord 4, 9 lda_coord 4, 9
dec e dec e
jr .storeTile jr .storeTile
@ -333,7 +340,7 @@ GetTileTwoStepsInFrontOfPlayer:
jr nz, .storeTile jr nz, .storeTile
; facing right ; facing right
ld hl, hPlayerFacing ld hl, hPlayerFacing
set 3, [hl] set BIT_FACING_RIGHT, [hl]
lda_coord 12, 9 lda_coord 12, 9
inc e inc e
.storeTile .storeTile
@ -385,7 +392,7 @@ CheckForBoulderCollisionWithSprites:
ld de, $f ld de, $f
ld hl, wSprite01StateData2MapY ld hl, wSprite01StateData2MapY
ldh a, [hPlayerFacing] ldh a, [hPlayerFacing]
and $3 ; facing up or down? and (1 << BIT_FACING_UP) | (1 << BIT_FACING_DOWN)
jr z, .pushingHorizontallyLoop jr z, .pushingHorizontallyLoop
.pushingVerticallyLoop .pushingVerticallyLoop
inc hl inc hl
@ -396,6 +403,7 @@ CheckForBoulderCollisionWithSprites:
ld a, [hli] ld a, [hli]
ld b, a ld b, a
ldh a, [hPlayerFacing] ldh a, [hPlayerFacing]
assert BIT_FACING_DOWN == 0
rrca rrca
jr c, .pushingDown jr c, .pushingDown
; pushing up ; pushing up
@ -421,7 +429,7 @@ CheckForBoulderCollisionWithSprites:
jr nz, .nextSprite2 jr nz, .nextSprite2
ld b, [hl] ld b, [hl]
ldh a, [hPlayerFacing] ldh a, [hPlayerFacing]
bit 2, a bit BIT_FACING_LEFT, a
jr nz, .pushingLeft jr nz, .pushingLeft
; pushing right ; pushing right
ldh a, [hPlayerXCoord] ldh a, [hPlayerXCoord]

View file

@ -15,7 +15,7 @@ LoadSpinnerArrowTiles::
ld hl, GymSpinnerArrows ld hl, GymSpinnerArrows
.gotSpinnerArrows .gotSpinnerArrows
ld a, [wSimulatedJoypadStatesIndex] ld a, [wSimulatedJoypadStatesIndex]
bit 0, a bit 0, a ; even or odd?
jr nz, .alternateGraphics jr nz, .alternateGraphics
ld de, 6 * 4 ld de, 6 * 4
add hl, de add hl, de

View file

@ -2002,7 +2002,7 @@ LoadPlayerSpriteGraphicsCommon::
jr nc, .noCarry jr nc, .noCarry
inc d inc d
.noCarry .noCarry
set 3, h set 3, h ; add $800 ($80 tiles) to hl (1 << 3 == $8)
lb bc, BANK(RedSprite), $0c lb bc, BANK(RedSprite), $0c
jp CopyVideoData jp CopyVideoData

View file

@ -252,7 +252,7 @@ HandlePartyMenuInput::
jp nz, .swappingPokemon jp nz, .swappingPokemon
pop af pop af
ldh [hTileAnimations], a ldh [hTileAnimations], a
bit 1, b bit BIT_B_BUTTON, b
jr nz, .noPokemonChosen jr nz, .noPokemonChosen
ld a, [wPartyCount] ld a, [wPartyCount]
and a and a

View file

@ -30,7 +30,7 @@ Serial::
ldh [rDIV], a ldh [rDIV], a
.waitLoop .waitLoop
ldh a, [rDIV] ldh a, [rDIV]
bit 7, a bit 7, a ; wait until rDIV has incremented from $3 to $80 or more
jr nz, .waitLoop jr nz, .waitLoop
ld a, START_TRANSFER_EXTERNAL_CLOCK ld a, START_TRANSFER_EXTERNAL_CLOCK
ldh [rSC], a ldh [rSC], a

View file

@ -1,3 +1,8 @@
; wSpriteLoadFlags bits, streamed from compressed sprite data
const_def
const BIT_USE_SPRITE_BUFFER_2 ; 0
const BIT_LAST_SPRITE_CHUNK ; 1
; bankswitches and runs _UncompressSpriteData ; bankswitches and runs _UncompressSpriteData
; bank is given in a, sprite input stream is pointed to in wSpriteInputPtr ; bank is given in a, sprite input stream is pointed to in wSpriteInputPtr
UncompressSpriteData:: UncompressSpriteData::
@ -47,7 +52,7 @@ _UncompressSpriteData::
add a add a
ld [wSpriteWidth], a ld [wSpriteWidth], a
call ReadNextInputBit call ReadNextInputBit
ld [wSpriteLoadFlags], a ; initialite bit1 to 0 and bit0 to the first input bit ld [wSpriteLoadFlags], a ; initialize bit1 to 0 and bit0 to the first input bit
; this will load two chunks of data to sSpriteBuffer1 and sSpriteBuffer2 ; this will load two chunks of data to sSpriteBuffer1 and sSpriteBuffer2
; bit 0 decides in which one the first chunk is placed ; bit 0 decides in which one the first chunk is placed
; fall through ; fall through
@ -58,13 +63,13 @@ _UncompressSpriteData::
UncompressSpriteDataLoop:: UncompressSpriteDataLoop::
ld hl, sSpriteBuffer1 ld hl, sSpriteBuffer1
ld a, [wSpriteLoadFlags] ld a, [wSpriteLoadFlags]
bit 0, a bit BIT_USE_SPRITE_BUFFER_2, a
jr z, .useSpriteBuffer1 ; check which buffer to use jr z, .useSpriteBuffer1 ; check which buffer to use
ld hl, sSpriteBuffer2 ld hl, sSpriteBuffer2
.useSpriteBuffer1 .useSpriteBuffer1
call StoreSpriteOutputPointer call StoreSpriteOutputPointer
ld a, [wSpriteLoadFlags] ld a, [wSpriteLoadFlags]
bit 1, a bit BIT_LAST_SPRITE_CHUNK, a
jr z, .startDecompression ; check if last iteration jr z, .startDecompression ; check if last iteration
call ReadNextInputBit ; if last chunk, read 1-2 bit unpacking mode call ReadNextInputBit ; if last chunk, read 1-2 bit unpacking mode
and a and a
@ -196,10 +201,10 @@ MoveToNextBufferPosition::
xor a xor a
ld [wSpriteCurPosX], a ld [wSpriteCurPosX], a
ld a, [wSpriteLoadFlags] ld a, [wSpriteLoadFlags]
bit 1, a bit BIT_LAST_SPRITE_CHUNK, a
jr nz, .done ; test if there is one more sprite to go jr nz, .done ; test if there is one more sprite to go
xor $1 xor 1 << BIT_USE_SPRITE_BUFFER_2
set 1, a set BIT_LAST_SPRITE_CHUNK, a
ld [wSpriteLoadFlags], a ld [wSpriteLoadFlags], a
jp UncompressSpriteDataLoop jp UncompressSpriteDataLoop
.done .done
@ -540,7 +545,7 @@ ReverseNybble::
; resets sprite buffer pointers to buffer 1 and 2, depending on wSpriteLoadFlags ; resets sprite buffer pointers to buffer 1 and 2, depending on wSpriteLoadFlags
ResetSpriteBufferPointers:: ResetSpriteBufferPointers::
ld a, [wSpriteLoadFlags] ld a, [wSpriteLoadFlags]
bit 0, a bit BIT_USE_SPRITE_BUFFER_2, a
jr nz, .buffer2Selected jr nz, .buffer2Selected
ld de, sSpriteBuffer1 ld de, sSpriteBuffer1
ld hl, sSpriteBuffer2 ld hl, sSpriteBuffer2

View file

@ -27,7 +27,7 @@ VictoryRoad2FCheckBoulderEventScript:
call VictoryRoad2FReplaceTileBlockScript call VictoryRoad2FReplaceTileBlockScript
pop af pop af
.not_on_switch .not_on_switch
bit 7, a CheckEventReuseA EVENT_VICTORY_ROAD_2_BOULDER_ON_SWITCH2
ret z ret z
ld a, $1d ld a, $1d
lb bc, 7, 11 lb bc, 7, 11