Illegal instruction - ASM6 bug or something else?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Illegal instruction - ASM6 bug or something else?
by on (#212940)
I have a really long subroutine handling enemy animation and AI at once. This fragment moves enemies.
Code:
MoveEnemy:
  DEC Mob8Steps - 1, x

  LDA Mob8Direction - 1, x
  CMP #Mob_Dir_South
  BNE +
  INC EnemyRam, y
  RTS
  +
  CMP #Mob_Dir_North
  BNE +
  DEC EnemyRam, y
  RTS
  +
  CMP #Mob_Dir_East
  BNE +
  INC EnemyRam + 3, y
  RTS
  +
  ;;;west
  DEC EnemyRam + 3, y
  RTS


For some reason anywhere I try to use y register when addressing (INC EnemyRam + 3, y, STX EnemyRam + 3, y etc.) I get an error. I have to do it like this and it's completely redundant:

Code:
 
  DEC Mob8Steps - 1, x
 
  LDA Mob8Direction - 1, x
  CMP #Mob_Dir_South
  BNE +
  TYA
  TAX
  INC EnemyRam, x
  JMP AnimateEnemyUpdateRegisters
  +
  CMP #Mob_Dir_North
  BNE +
  TYA
  TAX
  DEC EnemyRam, x
  JMP AnimateEnemyUpdateRegisters
  +
  CMP #Mob_Dir_East
  BNE +
  TYA
  TAX
  INC EnemyRam + 3, x
  JMP AnimateEnemyUpdateRegisters
  +
  ;;;west
  TYA
  TAX
  DEC EnemyRam + 3, x
  JMP AnimateEnemyUpdateRegisters


What's wrong?
Re: Illegal instruction - ASM6 bug or something else?
by on (#212941)
Some instructions (including INC and DEC) have an absolute X addressing mode but not absolute Y. It's just the way the 6502 is.

I recommend keeping this 6502 reference page bookmarked, to be able to quickly check what addressing modes each instruction supports (and how many clock cycles)
Re: Illegal instruction - ASM6 bug or something else?
by on (#212942)
For some strange reason the unofficial instructions isc and dcp have ',y' addressing modes even though inc and dec do not. You can use isc and dcp here if you don't mind being a 6502 bad boy and breaking compat on some emulators.
Re: Illegal instruction - ASM6 bug or something else?
by on (#212943)
pubby ninja'd me, but I'll post anyway because I have a link:

The read-modify-write instructions (ASL, LSR, ROL, ROR, INC, DEC) have dd,X and aaaa,X modes but not aaaa,Y, (dd),Y, or (dd,X). If you're not planning to reuse the code on any 65C02 or 65816 platform (Lynx, TG16, or Super NES), you could try the unofficial RMW+ALU instructions, which have all the modes that STA has.
Re: Illegal instruction - ASM6 bug or something else?
by on (#212944)
Are they available on ASM6? It still gives me that illegal instruction error.
Re: Illegal instruction - ASM6 bug or something else?
by on (#212947)
If you were using ca65, you'd use .setcpu "6502X" before any RMW+ALU instructions. For ASM6, you may have to edit the assembler's source code and recompile it to enable support. Or make macros in your assembly language source code that emit byte statements.
Re: Illegal instruction - ASM6 bug or something else?
by on (#212987)
There is a fork of asm6 which does support illegal opcodes. It is called asm6f
Re: Illegal instruction - ASM6 bug or something else?
by on (#213001)
With standard asm6 you could make macros (I think, I'm away from my computer)...

Or else put in a .byte .db command and just use the hex value of the illegal opcode.