How can "beq [label]" produce an out of range error?

203 views Asked by At

I am trying to compile this code snippet, and can't for the life of me understand the assembler error:

[...]
.macro collflag flags
    RW_forced a8i16
    lda EXRAM, x
    and flags
    RW_forced a16i16
.endmac

[...]

col_r:
    RW_forced a16i16
    lda lamus_vx
    bmi col_l
    beq col_d
    lda lamus_tile
    inc a
    tax
    collflag #PROPS_WALL_LEFT
    beq :+
    jmp r_detected  ; Collision detected - right
:   lda lamus_y
    and #$0300
    beq col_d
    txa
    add #32
    tax
    collflag #PROPS_WALL_LEFT
    beq col_d
    ; Collision detected - right

On this code extract, I get this assembler error:

metroix.s(264): Error: Range error (130 not in [-128..127])

the line 264 would refer to:

    beq col_d

The RW_forced are implemented in a libray and really all they should be doing is outputting sep/rep instructions and .a8/.a16 macros that should work. But here's their implementation, which looks fine to me:

/**
  Macro: RW_assume
  Assume known accumulator/index register widths without emitting any instructions

  Parameter:
  >:in:    widths    Register widths         a8/a16/i8/i16/a8i8/a16i16/a8i16/a16i8
*/
.macro RW_assume widths
.if .blank({widths})
  SFX_error "RW_assume: Missing required parameter"
.else
  RW_init
  .if .xmatch({widths},{a8})
    SFX_RW_a_size .set 1
    .a8
  .elseif .xmatch({widths},{a16})
    SFX_RW_a_size .set 0
    .a16
  .elseif .xmatch({widths},{i8})
    SFX_RW_i_size .set 1
    .i8
  .elseif .xmatch({widths},{i16})
    SFX_RW_i_size .set 0
    .i16
  .elseif .xmatch({widths},{a8i8})
    RW_assume a8
    RW_assume i8
  .elseif .xmatch({widths},{a16i16})
    RW_assume a16
    RW_assume i16
  .elseif .xmatch({widths},{a8i16})
    RW_assume a8
    RW_assume i16
  .elseif .xmatch({widths},{a16i8})
    RW_assume a16
    RW_assume i8
  .else
    SFX_error "RW_assume: Illegal parameter"
  .endif
.endif
.endmac

/**
  Macro: RW_forced
  Force set accumulator/index register widths (ie. always emit rep/sep instructions)

  Parameter:
  >:in:    widths    Register widths         a8/a16/i8/i16/a8i8/a16i16/a8i16/a16i8
*/
.macro RW_forced widths
.if .blank({widths})
  SFX_error "RW_forced: Missing required parameter"
.else
  .if .xmatch({widths},{a8i8})
    sep #$30
  .elseif .xmatch({widths},{a16i16})
    rep #$30
  .elseif .xmatch({widths},{a8i16})
    sep #$20
    rep #$10
  .elseif .xmatch({widths},{a16i8})
    rep #$20
    sep #$10
  .else
    SFX_error "RW_forced: Illegal parameter"
  .endif
  RW_assume widths
.endif
.endmac

My question is, how on earth is beq col_d or anything around it out of range? Where even is the 130? Is this a bug in the assembler?

For reference, if I change EITHER callflag call with another version without the RW_forced calls, the code assembles (but is wrong).

0

There are 0 answers