It is currently Fri May 25, 2018 2:20 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Mon May 02, 2016 3:22 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 6291
Location: Canada
To JoeGTake2:

I don't see anything directly wrong with your code logic (aside from the missing quadrant selection, of course), but I will ask why the addr variable in your example appears to be big endian, and the attributeToChangeAddress is little endian? Is that intentional? Also it doesn't match the name attributeAddressToChange used later; i'm assuming they're supposed to be the same variable?

What specifically was wrong with your code when you tested it? Did it appear to do nothing? Did you put a breakpoint on that $2007 write to see what was going through?


Top
 Profile  
 
PostPosted: Mon May 02, 2016 3:56 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2053
Location: DIGDUG
OMG, addr+1 is the small byte in your code? Now it makes sense to me. Ok.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Mon May 02, 2016 8:01 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2053
Location: DIGDUG
Here's a mixture of the original code and mine...
NOTE:addr is the low byte, addr+1 is the high byte

Also NOTE: new_bits = 0-3 = the palette of a given 16x16 block (for anyone out there who doesn't know).

Code:
    LDA addr
    LSR
    LSR
    CMP #$20
    AND #%00000111
    STA temp

    LDA addr+1
    ROL
    ASL
    ASL
    ASL
    ORA #$C0
    ORA temp
    STA attrib_addr

    LDA addr+1
    ORA #$03
    STA attrib_addr+1


   Bit $2002
   Lda attrib_addr+1
   Sta $2006
   Lda attrib_addr
   Sta $2006
   Lda $2007 ;junk
   Lda $2007 ;data
   Sta temp

   Lda addr
   And #$40 ;top or bottom?
   BNE BOTTOM

TOP:
   Lda addr
   And #02
   BNE TOP_R

TOP_L:
   Lda temp ;our data
   And #$fc ; mask out bits
   ora new_bits ;in right 2 bit position
   Sta temp
   Jmp END

TOP_R:
   Lda temp ;our data
   And #$f3 ; mask out bits
   Sta temp
   Lda new_bits ;in right 2 bit position
   Asl a
   Asl a
   Ora temp
   Sta temp
   Jmp END

BOTTOM:
   Lda addr
   And #02
   BNE BOT_R

BOT_L:
   Lda temp ;our data
   And #$cf ; mask out bits
   Sta temp
   Lda new_bits ;in right 2 bit position
   Asl a
   Asl a
   Asl a
   Asl a
   Ora temp
   Sta temp
   Jmp END

BOT_R:
   Lda temp ;our data
   And #$3f ; mask out bits
   Sta temp
   Lda new_bits ;in right 2 bit position
   lsr a
   Ror a
   Ror a
   Ora temp
   Sta temp

END: ;put new data in attrib table
   Lda attrib_addr+1
   Sta $2006
   Lda attrib_addr
   Sta $2006
   Lda temp
   Sta $2007


Tested. It works.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Tue May 03, 2016 8:12 am 
Offline

Joined: Tue Jul 01, 2014 4:02 pm
Posts: 285
Thanks so much for all the help and explanation. This is *close* to working.

It seemed to give a false positive. For instance, I directly loaded 20 84 respectively into the addr bytes and ran the routine. It worked exactly as expected. But then dropped 20 - 86 into the bytes, and got the same output as 20 84...anomalous, for sure.

For kicks, I tried 21 84, that also worked. As did 21 44. And 20 c4. But in some instances, changing the input value had similar anomalous effects.

After much playing to see what direct values i got to work and which ones didn't, it seems the bottom rows behave as expected, but the top rows do not. I'm playing with it a bit, but that said...anything stick out?


Top
 Profile  
 
PostPosted: Tue May 03, 2016 9:52 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2053
Location: DIGDUG
It worked for me.

You'll need to either post the code or the ROM, or perhaps step through the code in a debugger.

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Tue May 03, 2016 9:59 am 
Offline

Joined: Tue Jul 01, 2014 4:02 pm
Posts: 285
Sorry - I debugged. It absolutely works. corrupted variable on my end...fixed and now flawless. :-)

You guys rock. Glad to know I wasn't *too* far off. Can't thank you guys enough for your constant feedback!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group