Closed bcampbell closed 3 months ago
That is correct, and the result of a compromise.
$0000
- it places it at $2000
; that is, sta $1
(85 01
) actually writes to $2001
in memory, not $0001
as it would on other 6502-class chips. (Similarly, its stack is at $2100
.)As established above, we cannot distinguish between sta $FF
and sta $00FF
. This leads to two questions: "How to handle immediate values $00
-$FF
?" and "How to handle immediate values $2000
-$20FF
?".
$0000
-$00FF
with an immediate address.$00
-$FF
generates zero page opcodes, but $2000
-$20FF
generates absolute opcodes, we can similarly no longer write to $0000
-$00FF
with an immediate address.$2000
-$20FF
generates zero page opcodes, but $00
-$FF
generates absolute opcodes, all addresses resolve to their fastest access method correctly. It's the most LLVM-friendly way to implement this; however, this option causes some confusion to programmers used to non-HuC6280 types of 6502 development.I chose the last option, and so the above disassembly works as intended; that is, a zero-page write to $01
is sta $2001
, not sta $1
. There's also a test (llvm/test/MC/MOS/zeropage-huc6280.s
) which demonstrates the behaviour at assembly level.
In addition, as to LLVM a number is a number, hardcoding distinguishing between two-character and four-character immediates would fall apart as soon as arithmetic gets involved.
I suppose another option would be to adapt WDC-style modifiers to the HuC6280, so for example lda <$00
would always resolve to the zero-page opcode lda $00
. This is supported by the assembler (I think), but not the current choice of the disassembler.
Ahh, got it - thanks very much for the detailed explanation. I did wonder if it might have been something along those lines. The more I find out about the HuC6280, the more it diverges from my mental model of it being just a fast 6502 with extra bells and whistles bolted on :-)
Using llvm-objdump to show disassemble of .elf files compiled for pc engine seem to give some odd results. In the example below, at the line for
e00d
, thesta
operand seems wrong... It shows $2000 when it should be $00?The same stub program compiled for the c64 seems to disassemble as I'd expect: