Jump to content
IGNORED

Displaying the score


Kevin Holditch

Recommended Posts

I was wondering if someone could help me. I've started to write my own Atari 2600 game and I'm starting out by working out an algorithm to display the score. So far I've mapped all of the numbers from 0-9 out in consecutive memory using 8 bytes for each number. To display the any number from 0-9 I simply multiply the number by 8 (by bit shifting left 3 times) and then I know where in memory to start drawing the number from. I then loop round for 8 lines loading each line of memory into the background register to draw the number.

 

This all works great but the problem comes when I want to draw a 2,3 or even 4 digit number. I am having trouble working out how to extract the tens, hundreds, thousands from the number. I need to be able to do this so I can draw each digit using the routine described above. Thanks in advance for any help.

Link to comment
Share on other sites

...I am having trouble working out how to extract the tens, hundreds, thousands from the number. I need to be able to do this so I can draw each digit using the routine described above. Thanks in advance for any help.

The usual way to do this is to keep your score in Binary Coded Decimal format, or BCD for short.

 

The 6507/6502 has a native BCD mode that you just need to turn on (SED) when adding or subtracting from the score, and turn off (CLD) when you're done. When it's enabled, for example, if a score byte is $09 and you add 1 it will become $10 instead of $0A.

 

If you used BCD mode with all score additions and subtractions, extracting a lower decimal digit from a score byte is just a matter of an "AND #$0f" and extracting the higher decimal digit is just a matter of 4 "LSR"s. Rinse and repeat for any other score digits you may have.

Link to comment
Share on other sites

...I am having trouble working out how to extract the tens, hundreds, thousands from the number. I need to be able to do this so I can draw each digit using the routine described above. Thanks in advance for any help.

The usual way to do this is to keep your score in Binary Coded Decimal format, or BCD for short.

 

The 6507/6502 has a native BCD mode that you just need to turn on (SED) when adding or subtracting from the score, and turn off (CLD) when you're done. When it's enabled, for example, if a score byte is $09 and you add 1 it will become $10 instead of $0A.

 

Using BCD, extracting the lower digit is just a matter of an "AND #$0f" and extracting the higher digit is just a matter of 4 "LSR"s. Rinse and repeat for any other score digits you may have.

 

 

Thanks very much for such a quick response. I can see how it would be quite easy (in Atari 2600 terms where nothing is that easy) to do it now. Thanks again.

Edited by Kevin Holditch
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...