This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Want to do something like TEST in x86...

Want to do something like TEST in x86...
by on (#41786)
Basically, when I load in from a save I obviously want inventory backed up and you to have the items you gained when you restart.

Right now I'm doing this for keys picked up. Each bit represents a key and if you have the key, it displays an icon for the key:

Code:
DetermineInventory:
   LDA backedUpKeyPickups
   AND #%00000001
      BEQ .k2
      JSR DrawKeyOne
.k2:
   LDA backedUpKeyPickups
   AND #%00000010
      BEQ .k3
      JSR DrawKeyTwo


But is there any way at all I could do that without having to LDA or is that simply impossible?

by on (#41788)
If the DrawKeyOne routine changes A, then no, there's no way around it (other than PHA/PLA around the JSR).

Assuming DrawKeyOne doesn't change A, there are a few approaches you can take:

You can use BIT, but because BIT lacks an immediate mode, you'd have to have a small LUT somewhere:

Code:
Bit0:  .db %00000001
Bit1:  .db %00000010
Bit2:  .db %00000100
Bit3:  .db %00001000
Bit4:  .db %00010000
Bit5:  .db %00100000
Bit6:  .db %01000000
Bit7:  .db %10000000


DetermineInventory:
  LDA backedUpKeyPickups
  BIT Bit0
    BEQ .k2
    JSR DrawKeyOne
.k2:
  BIT Bit1
  etc



Or you could shift out into the C flag:

Code:
DetermineInventory:
  LDA backedUpKeyPickups
  LSR A
    BCC .k2
    JSR DrawKeyOne
.k2:
  LSR A
    BCC .k3
  etc



But again, you need to have the number in A for each check regardless of what you use. So you'll probably have to LDA every time.