Skip to content

Commit

Permalink
Identify more flag bits (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 authored Sep 24, 2024
1 parent 21cfdbd commit 8f1dcf0
Show file tree
Hide file tree
Showing 53 changed files with 267 additions and 193 deletions.
10 changes: 5 additions & 5 deletions audio/engine_1.asm
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Audio1_UpdateMusic::
ld a, [wMuteAudioAndPauseMusic]
and a
jr z, .applyAffects
bit 7, a
bit BIT_MUTE_AUDIO, a
jr nz, .nextChannel
set 7, a
set BIT_MUTE_AUDIO, a
ld [wMuteAudioAndPauseMusic], a
xor a ; disable all channels' output
ldh [rNR51], a
Expand Down Expand Up @@ -197,7 +197,7 @@ Audio1_sound_ret:
.dontDisable
jr .afterDisable
.returnFromCall
res 1, [hl]
res BIT_SOUND_CALL, [hl]
ld d, $0
ld a, c
add a
Expand Down Expand Up @@ -377,8 +377,8 @@ Audio1_toggle_perfect_pitch:
ld hl, wChannelFlags1
add hl, bc
ld a, [hl]
xor $1
ld [hl], a ; flip bit 0 of wChannelFlags1
xor 1 << BIT_PERFECT_PITCH
ld [hl], a
jp Audio1_sound_ret

Audio1_vibrato:
Expand Down
16 changes: 8 additions & 8 deletions audio/engine_2.asm
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Audio2_UpdateMusic::
ld a, [wMuteAudioAndPauseMusic]
and a
jr z, .applyAffects
bit 7, a
bit BIT_MUTE_AUDIO, a
jr nz, .nextChannel
set 7, a
set BIT_MUTE_AUDIO, a
ld [wMuteAudioAndPauseMusic], a
xor a ; disable all channels' output
ldh [rNR51], a
Expand Down Expand Up @@ -163,8 +163,8 @@ Audio2_PlayNextNote:
ld a, c
cp CHAN5
jr nz, .beginChecks
ld a, [wLowHealthAlarm] ; low health alarm enabled?
bit 7, a
ld a, [wLowHealthAlarm]
bit BIT_LOW_HEALTH_ALARM, a
ret nz
.beginChecks
; ---
Expand Down Expand Up @@ -208,7 +208,7 @@ Audio2_sound_ret:
.dontDisable
jr .afterDisable
.returnFromCall
res 1, [hl]
res BIT_SOUND_CALL, [hl]
ld d, $0
ld a, c
add a
Expand Down Expand Up @@ -388,8 +388,8 @@ Audio2_toggle_perfect_pitch:
ld hl, wChannelFlags1
add hl, bc
ld a, [hl]
xor $1
ld [hl], a ; flip bit 0 of wChannelFlags1
xor 1 << BIT_PERFECT_PITCH
ld [hl], a
jp Audio2_sound_ret

Audio2_vibrato:
Expand Down Expand Up @@ -978,7 +978,7 @@ Audio2_ResetCryModifiers:
cp CHAN5
jr nz, .skip
ld a, [wLowHealthAlarm]
bit 7, a
bit BIT_LOW_HEALTH_ALARM, a
jr z, .skip
xor a
ld [wFrequencyModifier], a
Expand Down
10 changes: 5 additions & 5 deletions audio/engine_3.asm
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Audio3_UpdateMusic::
ld a, [wMuteAudioAndPauseMusic]
and a
jr z, .applyAffects
bit 7, a
bit BIT_MUTE_AUDIO, a
jr nz, .nextChannel
set 7, a
set BIT_MUTE_AUDIO, a
ld [wMuteAudioAndPauseMusic], a
xor a ; disable all channels' output
ldh [rNR51], a
Expand Down Expand Up @@ -197,7 +197,7 @@ Audio3_sound_ret:
.dontDisable
jr .afterDisable
.returnFromCall
res 1, [hl]
res BIT_SOUND_CALL, [hl]
ld d, $0
ld a, c
add a
Expand Down Expand Up @@ -377,8 +377,8 @@ Audio3_toggle_perfect_pitch:
ld hl, wChannelFlags1
add hl, bc
ld a, [hl]
xor $1
ld [hl], a ; flip bit 0 of wChannelFlags1
xor 1 << BIT_PERFECT_PITCH
ld [hl], a
jp Audio3_sound_ret

Audio3_vibrato:
Expand Down
14 changes: 7 additions & 7 deletions audio/low_health_alarm.asm
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Music_DoLowHealthAlarm::
ld a, [wLowHealthAlarm]
cp $ff
cp DISABLE_LOW_HEALTH_ALARM
jr z, .disableAlarm

bit 7, a ;alarm enabled?
ret z ;nope
bit BIT_LOW_HEALTH_ALARM, a
ret z

and $7f ;low 7 bits are the timer.
and LOW_HEALTH_TIMER_MASK
jr nz, .notToneHi ;if timer > 0, play low tone.

call .playToneHi
Expand All @@ -19,15 +19,15 @@ Music_DoLowHealthAlarm::
call .playToneLo ;actually set the sound registers.

.noTone
ld a, $86
ld a, CRY_SFX_END
ld [wChannelSoundIDs + CHAN5], a ;disable sound channel?
ld a, [wLowHealthAlarm]
and $7f ;decrement alarm timer.
and LOW_HEALTH_TIMER_MASK
dec a

.resetTimer
; reset the timer and enable flag.
set 7, a
set BIT_LOW_HEALTH_ALARM, a
ld [wLowHealthAlarm], a
ret

Expand Down
8 changes: 8 additions & 0 deletions constants/audio_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,11 @@ DEF HW_CH4_DISABLE_MASK EQU (~HW_CH4_ENABLE_MASK & $ff)

; wChannelFlags2 constant (only has one flag)
DEF BIT_EXECUTE_MUSIC EQU 0 ; if in execute music

; wMuteAudioAndPauseMusic
DEF BIT_MUTE_AUDIO EQU 7

; wLowHealthAlarm
DEF BIT_LOW_HEALTH_ALARM EQU 7
DEF LOW_HEALTH_TIMER_MASK EQU %01111111
DEF DISABLE_LOW_HEALTH_ALARM EQU $ff
4 changes: 4 additions & 0 deletions constants/battle_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ DEF MAX_STAT_VALUE EQU 999
DEF ATKDEFDV_TRAINER EQU $98
DEF SPDSPCDV_TRAINER EQU $88

; wDamageMultipliers
DEF BIT_STAB_DAMAGE EQU 7
DEF EFFECTIVENESS_MASK EQU %01111111

; wPlayerBattleStatus1 or wEnemyBattleStatus1 bit flags
const_def
const STORING_ENERGY ; 0 ; Bide
Expand Down
6 changes: 6 additions & 0 deletions constants/gfx_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ DEF TRANSFERBOTTOM EQU 2
DEF REDRAW_COL EQU 1
DEF REDRAW_ROW EQU 2

; hUILayoutFlags
const_def
const BIT_PARTY_MENU_HP_BAR ; 0
const BIT_DOUBLE_SPACED_MENU ; 1
const BIT_SINGLE_SPACED_LINES ; 2

; tile list ids
; TileIDListPointerTable indexes (see data/tilemaps.asm)
const_def
Expand Down
11 changes: 9 additions & 2 deletions constants/map_object_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ DEF SPRITESTATEDATA2_LENGTH EQU const_value

DEF NUM_SPRITESTATEDATA_STRUCTS EQU 16

const_def 6
const BIT_TRAINER ; 6
const BIT_ITEM ; 7

; different kinds of people events
DEF ITEM EQU $80
DEF TRAINER EQU $40
DEF TRAINER EQU 1 << BIT_TRAINER
DEF ITEM EQU 1 << BIT_ITEM

; movement status
DEF BIT_FACE_PLAYER EQU 7

DEF WALK EQU $FE
DEF STAY EQU $FF
Expand Down
3 changes: 3 additions & 0 deletions constants/menu_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ DEF PC_ITEM_CAPACITY EQU 50
const NO_YES_MENU ; 7
DEF NUM_TWO_OPTION_MENUS EQU const_value

; wTwoOptionMenuID
DEF BIT_SECOND_MENU_OPTION_DEFAULT EQU 7

; menu exit method constants for list menus and the buy/sell/quit menu
DEF CHOSE_MENU_ITEM EQU 1 ; pressed A
DEF CANCELLED_MENU EQU 2 ; pressed B
Expand Down
24 changes: 15 additions & 9 deletions constants/oam_constants.asm
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
; OAM flags used by this game
DEF OAMFLAG_ENDOFDATA EQU %00000001 ; pseudo OAM flag, only used by game logic
DEF OAMFLAG_CANBEMASKED EQU %00000010 ; pseudo OAM flag, only used by game logic
; Pseudo-OAM flags used by game logic
const_def
const BIT_END_OF_OAM_DATA ; 0
const BIT_SPRITE_UNDER_GRASS ; 1

; Used in SpriteFacingAndAnimationTable (see data/sprites/facings.asm)
DEF FACING_END EQU 1 << BIT_END_OF_OAM_DATA
DEF UNDER_GRASS EQU 1 << BIT_SPRITE_UNDER_GRASS

; OAM attribute flags
DEF OAM_PALETTE EQU %111
DEF OAM_TILE_BANK EQU 3
DEF OAM_OBP_NUM EQU 4 ; Non CGB Mode Only
DEF OAM_X_FLIP EQU 5
DEF OAM_Y_FLIP EQU 6
DEF OAM_PRIORITY EQU 7 ; 0: OBJ above BG, 1: OBJ behind BG (colors 1-3)
DEF OAM_PALETTE EQU %111
const_def 3
const OAM_TILE_BANK ; 3
const OAM_OBP_NUM ; 4 ; Non CGB Mode Only
const OAM_X_FLIP ; 5
const OAM_Y_FLIP ; 6
const OAM_PRIORITY ; 7 ; 0: OBJ above BG, 1: OBJ behind BG (colors 1-3)

; OAM attribute masks
DEF OAM_OBP1 EQU 1 << OAM_OBP_NUM ; OBJ palette 1
Expand Down
30 changes: 30 additions & 0 deletions constants/ram_constants.asm
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
; wSlotMachineFlags
const_def 6
const BIT_SLOTS_CAN_WIN ; 6
const BIT_SLOTS_CAN_WIN_WITH_7_OR_BAR ; 7

; wMiscFlags
const_def
const BIT_SEEN_BY_TRAINER ; 0
Expand All @@ -9,6 +14,15 @@
const BIT_TRIED_PUSH_BOULDER ; 6
const BIT_PUSHED_BOULDER ; 7

; wAutoTextBoxDrawingControl
DEF BIT_NO_AUTO_TEXT_BOX EQU 0

; wTextPredefFlag
DEF BIT_TEXT_PREDEF EQU 0

; wFontLoaded
DEF BIT_FONT_LOADED EQU 0

; wOptions
DEF TEXT_DELAY_MASK EQU %111
const_def 6
Expand All @@ -24,6 +38,12 @@ DEF TEXT_DELAY_SLOW EQU %101 ; 5
const BIT_FAST_TEXT_DELAY ; 0
const BIT_TEXT_DELAY ; 1

; wCurMapTileset
DEF BIT_NO_PREVIOUS_MAP EQU 7

; wCurrentBoxNum
DEF BIT_HAS_CHANGED_BOXES EQU 7

; wObtainedBadges, wBeatGymFlags
const_def
const BIT_BOULDERBADGE ; 0
Expand Down Expand Up @@ -117,3 +137,13 @@ DEF NUM_BADGES EQU const_value
const_skip 3 ; 3-5 ; unused
const BIT_LEDGE_OR_FISHING ; 6
const BIT_SPINNING ; 7

; hFindPathFlags
const_def
const BIT_PATH_FOUND_Y ; 0
const BIT_PATH_FOUND_X ; 1

; hNPCPlayerRelativePosFlags
const_def
const BIT_PLAYER_LOWER_Y ; 0
const BIT_PLAYER_LOWER_X ; 1
8 changes: 4 additions & 4 deletions data/sprites/facings.asm
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ SpriteFacingAndAnimationTable:
; y, x, attributes
db 0, 0, $00 ; top left
db 0, 8, $00 ; top right
db 8, 0, OAMFLAG_CANBEMASKED ; bottom left
db 8, 8, OAMFLAG_CANBEMASKED | OAMFLAG_ENDOFDATA ; bottom right
db 8, 0, UNDER_GRASS ; bottom left
db 8, 8, UNDER_GRASS | FACING_END ; bottom right

.FlippedOAM:
; y, x, attributes
db 0, 8, OAM_HFLIP ; top left
db 0, 0, OAM_HFLIP ; top right
db 8, 8, OAM_HFLIP | OAMFLAG_CANBEMASKED ; bottom left
db 8, 0, OAM_HFLIP | OAMFLAG_CANBEMASKED | OAMFLAG_ENDOFDATA ; bottom right
db 8, 8, OAM_HFLIP | UNDER_GRASS ; bottom left
db 8, 0, OAM_HFLIP | UNDER_GRASS | FACING_END ; bottom right
6 changes: 3 additions & 3 deletions engine/battle/animations.asm
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ DrawFrameBlock:
ld [de], a ; store tile ID
inc de
ld a, [hli]
bit 5, a ; is horizontal flip enabled?
bit OAM_X_FLIP, a
jr nz, .disableHorizontalFlip
.enableHorizontalFlip
set 5, a
set OAM_X_FLIP, a
jr .storeFlags2
.disableHorizontalFlip
res 5, a
res OAM_X_FLIP, a
.storeFlags2
ld [de], a
inc de
Expand Down
Loading

0 comments on commit 8f1dcf0

Please sign in to comment.