Illegal instruction - ASM6 bug or something else?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
Eisetley
Posts: 8
Joined: Fri Feb 02, 2018 4:45 am

Illegal instruction - ASM6 bug or something else?

Post by Eisetley »

I have a really long subroutine handling enemy animation and AI at once. This fragment moves enemies.

Code: Select all

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: Select all

  
  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?
User avatar
gauauu
Posts: 779
Joined: Sat Jan 09, 2016 9:21 pm
Location: Central Illinois, USA
Contact:

Re: Illegal instruction - ASM6 bug or something else?

Post by gauauu »

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)
User avatar
pubby
Posts: 583
Joined: Thu Mar 31, 2016 11:15 am

Re: Illegal instruction - ASM6 bug or something else?

Post by pubby »

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.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Illegal instruction - ASM6 bug or something else?

Post by tepples »

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.
User avatar
Eisetley
Posts: 8
Joined: Fri Feb 02, 2018 4:45 am

Re: Illegal instruction - ASM6 bug or something else?

Post by Eisetley »

Are they available on ASM6? It still gives me that illegal instruction error.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Illegal instruction - ASM6 bug or something else?

Post by tepples »

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.
User avatar
Nioreh
Posts: 115
Joined: Sun Jan 22, 2012 11:46 am
Location: Stockholm, Sweden

Re: Illegal instruction - ASM6 bug or something else?

Post by Nioreh »

There is a fork of asm6 which does support illegal opcodes. It is called asm6f
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: Illegal instruction - ASM6 bug or something else?

Post by dougeff »

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.
nesdoug.com -- blog/tutorial on programming for the NES
Post Reply