Place the sprites of 2 sections for number scores at $0250

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
belltone
Posts: 19
Joined: Wed Sep 09, 2015 6:00 pm

Place the sprites of 2 sections for number scores at $0250

Post by belltone »

I want to draw scores on the screen so that you can make the function of scoring.

I would like to take sprites number scores for 2 sections but I only available to the very mario sprites from 1 section.

Code: Select all

LoadScores:
  LDA #$20
  STA $2006
  LDA #$20
  STA $2006
  LDX #$00
LoadScoresLoops:
  LDA scores, x
  STA $2007, x
  INX
  CPX #$80
  BNE LoadScoresLoops

Code: Select all

scores:
  .db $40, $00, $00, $40
  .db $40, $01, $00, $48
  .db $48, $02, $00, $40
  .db $48, $03, $00, $48
I would like to place the sprites of 2 sections for number scores at $0250
Attachments
image.jpg
User avatar
dougeff
Posts: 2876
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Place the sprites of 2 sections for number scores at $02

Post by dougeff »

That's code for drawing BG tiles. $2006/2007 writes accesses the BG screen.

Sprites are stored in a separate OAM memory (256 bytes... 4 bytes x 64 sprites).

See the wiki...
http://wiki.nesdev.com/w/index.php/PPU_OAM
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
dougeff
Posts: 2876
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Place the sprites of 2 sections for number scores at $02

Post by dougeff »

On second thought, perhaps it would be better to draw the score as a BG element, in which case 2006/2007 would be appropriate...

Can I nit pick your code?

The second LDA #$20 is redundant, A already = $20.

The size of your 'scores' array 16 ($10) bytes, so the CPX line should be CPX #$10.

If you are just drawing BG tiles, then the score array should just be a list of tile numbers...presumably, you want a functioning scoreboard, so it would be an array in the RAM, not an array of constants in the ROM.

And it should be STA $2007. Not STA $2007, x.
nesdoug.com -- blog/tutorial on programming for the NES
belltone
Posts: 19
Joined: Wed Sep 09, 2015 6:00 pm

Re: Place the sprites of 2 sections for number scores at $02

Post by belltone »

I did scoring sprites numbers were taken from section 1, but how to take out a second:

Code: Select all

Scores:
  LDA $021B
  CLC
  ADC #$01
  CMP #$F4
  BNE NumberDone
Ten:
  LDA ten		
  CLC
  ADC #$01
  STA ten
  CMP #DECIMAL_COUNT
  BNE NumberDone
Hundred:
  LDA #CLEAR_COUNT
  STA ten
  LDA hundred
  CLC
  ADC #$01
  STA hundred
  CMP #DECIMAL_COUNT
  BNE NumberDone
Thousand:
  LDA #CLEAR_COUNT
  STA hundred
  LDA thousand
  CLC
  ADC #$01
  STA thousand
  CMP #DECIMAL_COUNT
  BNE NumberDone
  LDA #CLEAR_COUNT
  STA thousand
NumberDone:
Attachments
scores.zip
(38.98 KiB) Downloaded 72 times
User avatar
dougeff
Posts: 2876
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Place the sprites of 2 sections for number scores at $02

Post by dougeff »

And, you're loading the array to the nametable BEFORE the big loop that loads the entire background, so even if you had written the corrected code as I described, it would have been overwritten with the -load background- loops.

If you edited your code, like this...

Code: Select all

LoadScores:
  LDA #$20
  STA $2006
  STA $2006
  LDX #$00
LoadScoresLoops:
  LDA scores, x
  STA $2007
  INX
  CPX #4
  BNE LoadScoresLoops
And moved to the line after "BNE OutsideLoop"

And changed the array to (what I assume is just the tile numbers)...

scores:
.db $01, $02, $03, $04

it looks like this...
Attachments
week.png
week.png (1.65 KiB) Viewed 2134 times
Last edited by dougeff on Wed Mar 02, 2016 8:28 pm, edited 1 time in total.
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
dougeff
Posts: 2876
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Place the sprites of 2 sections for number scores at $02

Post by dougeff »

And, I can't follow exactly what your score calculation is doing...

LDA $021B ...what is $021b? That's in the Sprite Buffer, so that seems odd to me. Are you checking the X coordinate of a sprite, and seeing if it's equal to #$f4 for some reason?

If CLEAR_COUNT is equal to zero, then why not just type 0. It's faster.

Again, the score should probably be an array in the RAM. I could write it for you, but I think you will learn more figuring this out for yourself.

And, one more nit pick...you have too many similar labels. 'score' 'scores' and 'Scores' ...too easy to confuse and type the wrong one...and you get a bug that you can't find.
nesdoug.com -- blog/tutorial on programming for the NES
belltone
Posts: 19
Joined: Wed Sep 09, 2015 6:00 pm

Re: Place the sprites of 2 sections for number scores at $02

Post by belltone »

How can I manage the coordinates of these figures on the screen, I would like them to move a little down, but I go out in the middle of the screen.
User avatar
dougeff
Posts: 2876
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Place the sprites of 2 sections for number scores at $02

Post by dougeff »

When you write to the PPU between $2000-$23ff, you are writing tiles to the main BG screen (nametable #0). The two LDA #, STA $2006 selects the starting address...which is like choosing a spot on a map in which to start writing. The positions go like this...

$2000, $2001, $2002, etc up to $201f. - top most line of screen
$2020, $2021, $2022, etc up to $203f. - 2nd line
$2040...
$2060...
etc, down to
$23a0-23bf - the bottom line on the screen

$23c0-23ff - defines the color palette used for different sections of the screen.

If you think of the X position (left to right) as going from 0-255, and the Y position (top to bottom) as going from 0-239...you can locate the position on the screen with this formula...

nametable selection NN (2 bits)
Y coordinate YYYYY (the 5 upper bits)
X coordinate XXXXX (the 5 upper bits)

PPU address (in binary) = 0010 NNYY YYYX XXXX

Upper byte = 20 + (N << 2) + (Y >> 6)
Lower byte = ((Y << 2) AND e0) + (X >> 3)

Or, you can use a tool like NES Screen Tool, and it will calculate the Address for you...(on the bottom line, where it says "off", you add that number to $2000). Download it from here...

https://shiru.untergrund.net/software.shtml


see this topic for similar answers...

viewtopic.php?f=10&t=13860
nesdoug.com -- blog/tutorial on programming for the NES
Post Reply