8x16 and whatever else unreg wants to know

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

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

Re: 8x16 sprite is really a 16x32 pixel image?

Post by tokumaru »

Yes, this is correct. I like to think about it this way: the carry flag, in subtractions, is actually a value that can be borrowed if necessary. After the subtraction (CMP acts just like SEC + SBC, except it doesn't change A), if the carry is still set, a borrow wasn't necessary, so the value in A was large enough for you to subtract from it as much as you did (it's >= the value you subtracted). If the carry is clear, a borrow was necessary and the value in A wasn't large enough (it's < than the subtracted value).
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 sprite is really a 16x32 pixel image?

Post by unregistered »

tokumaru wrote:Yes, this is correct. I like to think about it this way: the carry flag, in subtractions, is actually a value that can be borrowed if necessary. After the subtraction (CMP acts just like SEC + SBC, except it doesn't change A), if the carry is still set, a borrow wasn't necessary, so the value in A was large enough for you to subtract from it as much as you did (it's >= the value you subtracted). If the carry is clear, a borrow was necessary and the value in A wasn't large enough (it's < than the subtracted value).
Ah yes, I was correct in my guess!! Thank you so much tokumaru! :D :)

edited text
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 sprite is really a 16x32 pixel image?

Post by unregistered »

I have a loop in my code.

If I have to run one line of code only on the first time through my loop

Code: Select all

lda t6+1
and then at all other times I'll need to run this line instead:

Code: Select all

lda t6
How would be a good way to set that up... something simple maybe? :) And these lines of code will be in the middle of my large loop. I'm trying to use one of those temp variables Kasumi recommended me.
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: 8x16 sprite is really a 16x32 pixel image?

Post by Kasumi »

It sorta depends on how long the loop is/what registers you need.

I'd just do the obvious and double the loop code if it's shortish. (Yeah, I realize you said it was long)

Code: Select all

lda t6+1
;loop stuff
looplabel:
lda t6
;loop stuff
If it's long, I might just store whatever is in t6 or t6+1 into a new temp variable or a register and then just always use the new temp variable or register.

Code: Select all

ldy t6+1
looplabel:
tya
;loopstuff
ldy t6
;conditional on whether you loop to looplabel again
Or... alternatively, depending on your conditional not requiring the use of A:

Code: Select all

lda t6+1
looplabel:
;loopstuff
lda t6
;conditional on whether you loop to looplabel again
Edit:
Or this:

Code: Select all

lda t6+1
jmp skiploadt6
looplabel:
lda t6
skiploadt6:
;loop stuff
;conditional on whether you loop to looplabel
That one is probably best, because it doesn't add setup time to each loop after the first like the others. It just came to mind third.

Or I might do something totally different depending on the setup of the loop. But there's some ideas.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 sprite is really a 16x32 pixel image?

Post by unregistered »

Kasumi wrote: Edit:
Or this:

Code: Select all

lda t6+1
jmp skiploadt6
looplabel:
lda t6
skiploadt6:
;loop stuff
;conditional on whether you loop to looplabel
That one is probably best, because it doesn't add setup time to each loop after the first like the others. It just came to mind third.
This one rocks!! (I just figured it out! :o) Thank you Kasumi!!! :D They are all good though, thanks very much! :D

[color=#FFFF00][b]...NESDEV's improvements[/b][/color] wrote:

Code: Select all

...

Code: Select all

...etc.
AND GOODNESS!! THIS FORUM JUST KEEPS GETTING BETTER AND BETTER, THANKS YALL! :D Edit: It's kindof slow right now...but maybe that's because there's been lot of my time coding these days. :?
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 sprite is really a 16x32 pixel image?

Post by unregistered »

unregistered [color=#FF0000]un -[/color] wrote:
Kasumi wrote: Edit:
Or this:

Code: Select all

lda t6+1
jmp skiploadt6
looplabel:
lda t6
skiploadt6:
;loop stuff
;conditional on whether you loop to looplabel
That one is probably best, because it doesn't add setup time to each loop after the first like the others. It just came to mind third.
This one rocks!! (I just figured it out! :o) Thank you Kasumi!!! :D They are all good though, thanks very much! :D
Kasumi wrote:If it's long, I might just store whatever is in t6 or t6+1 into a new temp variable or a register and then just always use the new temp variable or register.

Ahhh, I see now... after rereading and understanding your dark orange text up there... now, now... thank you so much Kasumi!!! :D Brilliant! I'm a step closer now! I'm in for some more gettin' dirty coding, I think. :D
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

Code: Select all

lda t6      ;pla ;<--------------------------------------
;on every 8th run do this instead:
lda t6+1


Is there a simple way to do this? I'm trying to make a simple solution.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re:

Post by thefox »

unregistered wrote:

Code: Select all

lda t6      ;pla ;<--------------------------------------
;on every 8th run do this instead:
lda t6+1


Is there a simple way to do this? I'm trying to make a simple solution.
Have a counter that counts upwards each run. Calculate counter AND 7, if result is zero, lda t6+1, otherwise lda t6. If counter starts at zero this will load t6+1 on the first run too. If you don't want that you can initialize the counter to a different value.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: 8x16 sprite is really a 16x32 pixel image?

Post by tepples »

This should be close:

Code: Select all

  ldx t6
  lda runCount
  and #$07
  bne :+
  ldx t6+1
:
  txa
bogax
Posts: 34
Joined: Wed Jul 30, 2008 12:03 am

Re:

Post by bogax »

Another one

Code: Select all

 lda #$80
 sta counter

LOOP
 lda t6
 lsr counter
 bne SKIP
 ror counter
 lda t6+1 
SKIP
 .
 .
I would point out that in Kasumi's code

Code: Select all

lda t6+1
jmp skiploadt6
looplabel:
lda t6
skiploadt6:
;loop stuff
;conditional on whether you loop to looplabel
There's the possibility of using a branch instead of
a jmp if that seems desirable eg if you know
t6+1 will never be 0 you could bne
saves a byte, might cost you a cycle at a page boundary,
more relocatable
unregistered wrote:

Code: Select all

lda t6      ;pla ;<--------------------------------------
;on every 8th run do this instead:
lda t6+1


Is there a simple way to do this? I'm trying to make a simple solution.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: Re:

Post by thefox »

bogax wrote:There's the possibility of using a branch instead of
a jmp if that seems desirable eg if you know
t6+1 will never be 0 you could bne
saves a byte, might cost you a cycle at a page boundary,
more relocatable
Using branch also loses some maintainability (in case the code above changes so that the zero flags value isn't a constant anymore). I tend to avoid this optimization. It sure would be nice to be able to do runtime assertions... (I'm considering implementing something like that in NintendulatorDX).
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: 8x16 sprite is really a 16x32 pixel image?

Post by tepples »

Emulator-side runtime assertions are implemented in FCEUX.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: 8x16 sprite is really a 16x32 pixel image?

Post by thefox »

tepples wrote:Emulator-side runtime assertions are implemented in FCEUX.
Not what I'm looking for. I don't want to specify the conditions manually and have to update them every time the addresses change. What I'm thinking about doing is a macro that outputs the assert expressions in a separate file (easily done with CC65). Something like this:

Code: Select all

runTimeAssert "A == 0 && C"
runTimeAssert "current_bank == 0x12"
Et cetera.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: 8x16 sprite is really a 16x32 pixel image?

Post by rainwarrior »

You could implement an assert macro that reads or writes to a specific address, executes a bad opcode, or something else that is not dependent on the program counter. This would let you keep the same "assert" breakpoint from build to build.

Alternatively, you could try to auto-generate the .dbg file FCEUX uses based on compile symbols. This would be better, since you could then have asserts without any extra code in the ROM.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

new question

Post by unregistered »

Code: Select all

0002D                           	attNextRowStart .dsb 1 ;thank you !!!! :D
0002E                           	every8thRun .dsb 1  ;will stay at 0 until the 8th attribute table block, the start of a new row, is to b
0002F                               atttablerownums: .db $00, $20, $40,$60,$80,$a0,$c0,$e0 
00037                           	tA .dsb 2
There's the ^ code that shows the addresses.

Code: Select all

00:C26D:E6 37     INC $0037 = #$05
00:C26F:A6 37     LDX $0037 = #$05
00:C271:B5 2F     LDA $2F,X @ $003D = #$00
00:C273:85 2D     STA $002D = #$00
WHY IS $002D AT #$00????????? :shock: :?

edit: Thank yall for helping with my last question. I'm tired, it is time to get away from this right now for me. Will elaborate my thanks soon, I promise. : )
Post Reply