RPGHacker / asar

(Now) official repository of the SNES assembler Asar, originally created by Alcaro
Other
204 stars 43 forks source link

INC with "non-static" label #265

Closed hellow554 closed 2 years ago

hellow554 commented 2 years ago

I have the following (simplified) code:

; file: vars.asm
base $1E00
Temp0: skip 1
Temp1: skip 1
; ...
LairsCleared: skip 2

; ...
; in a different file with the correct org
LairRevealHook:
    INC #LairsClreared

this gives me the following error:

hooks/lair_reveal.asm:6: error: (Eno_labels_here): Can't use non-static labels here.
    in block: [INC #LairsCleared]

Is this an imperfection of the label analyzer or am I missing something?

INC $1E0A works as intended btw.

RPGHacker commented 2 years ago

I think you're just using INC incorrectly here. What you probably want is:

INC LairsClreared

Not sure what INC #LairsClreared would even do. That looks like a pseudo-opcode to me. Like "increment accumulator $1E0A times".

Alcaro commented 2 years ago

INC #LairsCleared means 'insert the INC A instruction [numeric value of LairsCleared] times'.

INC #2 is a normal thing to say. INC #\<label> is not, unless you want to insert $1E00 instructions and waste a quarter of a bank and tens of thousands of cpu cycles.

The solution is remove the #.

hellow554 commented 2 years ago

You're somewhat right. Now the error is:

hooks/lair_reveal.asm:6: error: (Eunknown_command): Unknown command.
    in block: [INC LairsCleared]
RPGHacker commented 2 years ago

Do you have a simple test patch that reproduces the issue?

I wasn't able to reproduce it with the following test code:

base $1E00
LairsCleared: skip 2

inc LairsCleared

This assembled without issues.

EDIT: Also, could you specify what version of Asar you're testing in?

hellow554 commented 2 years ago

INC.w LairsCleared works though. I try to come up with a simple test.

Version: both master and beta_2

hellow554 commented 2 years ago

Testcase:

org $8000
base $1E00
LairsCleared: skip 2

org $A08000

inc LairsCleared
RPGHacker commented 2 years ago

I think that makes sense to fail. Asar considers LairsCleared to be in a different bank from where the inc is ($001E00 vs $A08000). So it tries to assemble inc.l which doesn't exist. So the explicit .w being required here makes sense (although admittedly the error message could be a lot clearer here - I think we might already have a TODO for that somewhere?).

Configuring the label optimizer might make it possible to remove necessity for the explicit .w, though.

hellow554 commented 2 years ago

Configuring the label optimizer might make it possible to remove necessity for the explicit .w, though.

You mean because $1E00 is accessible in the $A0 bank it can be reduced to a word access automatically?

Closing as resolved, thanks! :)

randomdude999 commented 2 years ago

use optimize address ram and put your label in bank 7e, then asar will reduce it to a word access automatically. or you can juse optimize address mirrors which will reduce all accesses to $00-3f:0000-7fff to words automatically.

yeah, asar throwing "unknown command" on invalid instruction widths is a long-known issue.