having trouble with indirect indexing

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
Kitty_Space_Program
Posts: 50
Joined: Mon Sep 21, 2020 7:42 am

having trouble with indirect indexing

Post by Kitty_Space_Program » Wed Dec 16, 2020 8:06 pm

I'm trying modify my basic screen loading code to use a variable instead of a set label, and it's not working. NESASM has always been inconsistent with its indirect indexing for me. My main concern is about if I'm doing it right. my code looks something like this:

Code: Select all

  lda #low(metaworlddata)
  sta world+0
  lda #high(metaworlddata)
  sta world+1
  ldy #$00
decode:
  ldx (world),y
  lda topleft,x
  sta $2007
  lda topright,x
  sta $2007
  iny
  sty nametableplaceholder
  tya 
  and #$0F
  bne decode

  lda nametableplaceholder; this should be at bottom but doesnt work
  cmp #$F0
  beq donewithnametable
  

  sec;this needs to be infront do not move
  sbc #$10
  tay
secondrow:
  ldx (world),y
  lda bottomleft,x
  sta $2007
  lda bottomright,x
  sta $2007
  iny
  cpy nametableplaceholder
  bne secondrow
  jmp decode
  jmp atributetableset

donewithnametable:
  sec;this needs to be infront do not move
  sbc #$10
  tay
finalloop: ;ok so some jank meant that checling for f0 at end of first row would glitch everything out so had to add this
  ldx [world],y
  lda bottomleft,x
  sta $2007
  lda bottomright,x
  sta $2007
  iny
  cpy nametableplaceholder
  bne finalloop
  ldx #$00
  ldy #$00

It is very janky and but I'm just trying to get something that works, and I does without indirect indexing ie. with a late where (world) is now. if I replace the parenthesis with [] it says incorrect addressing mode. Again, sorry for how bad my code is, at this point I just want something that works lol

lidnariq
Posts: 10241
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: having trouble with indirect indexing

Post by lidnariq » Wed Dec 16, 2020 8:07 pm

Is "world" somewhere in the bottom-most 256 bytes of RAM?

Oziphantom
Posts: 1077
Joined: Tue Feb 07, 2017 2:03 am

Re: having trouble with indirect indexing

Post by Oziphantom » Thu Dec 17, 2020 9:42 am

ldx (world),y

No, LDX doesn't have a (zp),y addressing mode only LDX abs,y and LDX zp,y you will have to
lda (world),y
tax

User avatar
Kitty_Space_Program
Posts: 50
Joined: Mon Sep 21, 2020 7:42 am

Re: having trouble with indirect indexing

Post by Kitty_Space_Program » Thu Dec 17, 2020 10:43 am

Oziphantom wrote:
Thu Dec 17, 2020 9:42 am
ldx (world),y

No, LDX doesn't have a (zp),y addressing mode
oh wow, thank you. I've been working on this for almost a week and didn't notice that. I am very dumb lol. I've fixed it, and it works (with brackets)
lidnariq wrote:
Wed Dec 16, 2020 8:07 pm
Is "world" somewhere in the bottom-most 256 bytes of RAM?
its in the zero page, yeah

User avatar
tokumaru
Posts: 11996
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: having trouble with indirect indexing

Post by tokumaru » Thu Dec 17, 2020 12:58 pm

It helps if you keep in mind that assembly programming is not just about following the syntax... Each combination of operation, register and addressing mode was deliberately implemented in the CPU by the designers, and not all combinations are available due to space/technical/budget constraints.

With time you get the hang of how versatile each operation is, and you start to intuitively plan the optimal use the CPU registers, cutting down on the amount of transfers, temporary variables and the like. When starting out, having a reference page handy is the best way to know whether a particular operation/register/addressing mode combination is available.

calima
Posts: 1301
Joined: Tue Oct 06, 2015 10:16 am

Re: having trouble with indirect indexing

Post by calima » Fri Dec 18, 2020 1:30 am

I suppose it'd help to use a proper assembler, it sounds like yours did not warn you about the wrong addressing mode...

User avatar
Kitty_Space_Program
Posts: 50
Joined: Mon Sep 21, 2020 7:42 am

Re: having trouble with indirect indexing

Post by Kitty_Space_Program » Sat Dec 19, 2020 3:34 pm

calima wrote:
Fri Dec 18, 2020 1:30 am
I suppose it'd help to use a proper assembler, it sounds like yours did not warn you about the wrong addressing mode...
It did when I used brackets. I think nesasm is a proper assembler and regardless, I couldn’t get any other ones to work since most are for windows and I’m using my grandfathers mac(since my computer is 20 years old and runs os9). At this point I don’t think I could get used to another assembler though regardless.

Pokun
Posts: 1746
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: having trouble with indirect indexing

Post by Pokun » Mon Dec 21, 2020 8:09 am

Older versions of Nesasm were known to not output warnings and errors correctly, but I think there are newer maintained versions that do? Which version are you using?


If you want to try something different I recommend Asm6, Ca65 or 64tass. Asm6 is as easy to use as Nesasm and better on some things (like error reporting) but doesn't have as powerful functions as Nesasm has. 64tass is not far behind in simplicity of use, and is much more powerful than Nesasm. Ca65 is the hardest to use but about as powerful as 64tass and also uses a linker (which may be useful for FDS for example). They should all work on a Macintosh if you can find a mac build for them.

I use Asm6f (Freem's fork of Asm6) for NES as it's easy to use and 64tass for SNES as it does 65816 direct page addressing properly, unlike Ca65.

Oziphantom
Posts: 1077
Joined: Tue Feb 07, 2017 2:03 am

Re: having trouble with indirect indexing

Post by Oziphantom » Mon Dec 21, 2020 10:57 pm

64tass will compile and run an an Amiga 1000, so a G series mac should have no problems.

Post Reply