shift_const update

Added limit verification to shift_const, macro also now define BIT_\1 constant for bit order value.
This commit is contained in:
Engezerstorung
2026-01-11 01:22:04 +01:00
parent f617232502
commit d43d05fd00
6 changed files with 33 additions and 37 deletions

View File

@@ -2,19 +2,14 @@
; height of north/south connections
DEF MAP_BORDER EQU 3
; connection directions
const_def
const EAST_F
const WEST_F
const SOUTH_F
const NORTH_F
; wCurMapConnections : \1
; connection directions : BIT_\1
bit_const_def
shift_const EAST ; $01 (BIT_EAST ; 0)
shift_const WEST ; $02 (BIT_WEST ; 1)
shift_const SOUTH ; $04 (BIT_SOUTH ; 2)
shift_const NORTH ; $08 (BIT_NORTH ; 4)
; wCurMapConnections
const_def
shift_const EAST ; 1
shift_const WEST ; 2
shift_const SOUTH ; 4
shift_const NORTH ; 8
; wWarpEntries
DEF MAX_WARP_EVENTS EQU 32

View File

@@ -14,12 +14,7 @@ DEF NPC_CHANGE_FACING EQU $E0
; player direction constants
bit_const_def
const PLAYER_DIR_BIT_RIGHT ; 0
const PLAYER_DIR_BIT_LEFT ; 1
const PLAYER_DIR_BIT_DOWN ; 2
const PLAYER_DIR_BIT_UP ; 3
DEF PLAYER_DIR_RIGHT EQU 1 << PLAYER_DIR_BIT_RIGHT
DEF PLAYER_DIR_LEFT EQU 1 << PLAYER_DIR_BIT_LEFT
DEF PLAYER_DIR_DOWN EQU 1 << PLAYER_DIR_BIT_DOWN
DEF PLAYER_DIR_UP EQU 1 << PLAYER_DIR_BIT_UP
shift_const PLAYER_DIR_RIGHT ; $01 (BIT_PLAYER_DIR_RIGHT ; 0)
shift_const PLAYER_DIR_LEFT ; $02 (BIT_PLAYER_DIR_LEFT ; 1)
shift_const PLAYER_DIR_DOWN ; $04 (BIT_PLAYER_DIR_DOWN ; 2)
shift_const PLAYER_DIR_UP ; $08 (BIT_PLAYER_DIR_UP ; 3)

View File

@@ -726,13 +726,13 @@ ItemUseSurfboard:
; uses a simulated button press to make the player move forward
.makePlayerMoveForward
ld a, [wPlayerDirection] ; direction the player is going
bit PLAYER_DIR_BIT_UP, a
bit BIT_PLAYER_DIR_UP, a
ld b, PAD_UP
jr nz, .storeSimulatedButtonPress
bit PLAYER_DIR_BIT_DOWN, a
bit BIT_PLAYER_DIR_DOWN, a
ld b, PAD_DOWN
jr nz, .storeSimulatedButtonPress
bit PLAYER_DIR_BIT_LEFT, a
bit BIT_PLAYER_DIR_LEFT, a
ld b, PAD_LEFT
jr nz, .storeSimulatedButtonPress
ld b, PAD_RIGHT

View File

@@ -29,22 +29,22 @@ UpdatePlayerSprite:
jr nz, .moving
ld a, [wPlayerMovingDirection]
; check if down
bit PLAYER_DIR_BIT_DOWN, a
bit BIT_PLAYER_DIR_DOWN, a
jr z, .checkIfUp
xor a ; ld a, SPRITE_FACING_DOWN
jr .next
.checkIfUp
bit PLAYER_DIR_BIT_UP, a
bit BIT_PLAYER_DIR_UP, a
jr z, .checkIfLeft
ld a, SPRITE_FACING_UP
jr .next
.checkIfLeft
bit PLAYER_DIR_BIT_LEFT, a
bit BIT_PLAYER_DIR_LEFT, a
jr z, .checkIfRight
ld a, SPRITE_FACING_LEFT
jr .next
.checkIfRight
bit PLAYER_DIR_BIT_RIGHT, a
bit BIT_PLAYER_DIR_RIGHT, a
jr z, .notMoving
ld a, SPRITE_FACING_RIGHT
jr .next
@@ -415,17 +415,17 @@ MakeNPCFacePlayer:
jr nz, NotYetMoving
res BIT_FACE_PLAYER, [hl]
ld a, [wPlayerDirection]
bit PLAYER_DIR_BIT_UP, a
bit BIT_PLAYER_DIR_UP, a
jr z, .notFacingDown
ld c, SPRITE_FACING_DOWN
jr .facingDirectionDetermined
.notFacingDown
bit PLAYER_DIR_BIT_DOWN, a
bit BIT_PLAYER_DIR_DOWN, a
jr z, .notFacingUp
ld c, SPRITE_FACING_UP
jr .facingDirectionDetermined
.notFacingUp
bit PLAYER_DIR_BIT_LEFT, a
bit BIT_PLAYER_DIR_LEFT, a
jr z, .notFacingRight
ld c, SPRITE_FACING_RIGHT
jr .facingDirectionDetermined

View File

@@ -2047,22 +2047,22 @@ LoadMapHeader::
ld a, [wCurMapConnections]
ld b, a
; check north
bit NORTH_F, b
bit BIT_NORTH, b
jr z, .checkSouth
ld de, wNorthConnectionHeader
call CopyMapConnectionHeader
.checkSouth
bit SOUTH_F, b
bit BIT_SOUTH, b
jr z, .checkWest
ld de, wSouthConnectionHeader
call CopyMapConnectionHeader
.checkWest
bit WEST_F, b
bit BIT_WEST, b
jr z, .checkEast
ld de, wWestConnectionHeader
call CopyMapConnectionHeader
.checkEast
bit EAST_F, b
bit BIT_EAST, b
jr z, .getObjectDataPointer
ld de, wEastConnectionHeader
call CopyMapConnectionHeader

View File

@@ -77,8 +77,14 @@ MACRO? const_export
ENDM
MACRO? shift_const
DEF \1 EQU 1 << const_value
DEF const_value += const_inc
IF (const_format != $FFFFFFFF) && ((const_inc > 0 && const_value > const_limit) || (const_inc < 0 && const_value < const_limit))
DEF failed_const_value = 1 << const_value
fail "Constant value cannot be {const_size_compare} than {const_limit}. Attempted to use constant value {const_value} to define constant \1 for shifted value {failed_const_value}."
ELSE
DEF BIT_\1 EQU const_value
DEF \1 EQU 1 << const_value
DEF const_value += const_inc
ENDC
ENDM
MACRO? const_skip