Jump to content
Coolcrab

Score, variables and mathematics question

Recommended Posts

I am quite confused about math in batari. I want to set the score to a certain value as X+n*Y. With n being the nth level that the player is in.

So lets say the game starts with score=1000, then in the next level I would like it to be set to 1050, then 1100, 1150, etc.

 

I tried doing this as: if score then m=m+1 : score = 1000 + 64 * m

But that doesn't work. I assume that this doesn't work because it only lets you do one operation after the equal sign?

You also can't make the m go up by 50 at a time, as it will go over 265 very fast. (And as far as I understand that is the limit for all variables apart from score?)

 

Is there some way to do this? I want something that ads roughly 50 each time.

Share this post


Link to post
Share on other sites

Hmm, I'm sill not sure. This would still overflow the a if its over 256 right?

   if s{3} then dec a = a + $20

   score = score + a

Share this post


Link to post
Share on other sites

If nobody pops up with a better idea, you might have to do a loop.

 

Maybe something like this:


   score = 1000
   for temp5 = 0 to m
   score = score + 50
   next
  • Like 1

Share this post


Link to post
Share on other sites

Multiplying by arbitrary numbers and mixing in BCD numbers can get a bit complicated on the 6502. I like the iterative adding loop RT, as it's small and simple.

 

An alternative way to do it, is to do each step of the multiplication on new frames, by adding something like the following to your vblank or game loop code...

 

 dim fifties=m
 if fifties>0 then fifties=fifties-1:score=score+50

Then a simple "fifties=fifties+level" (or "fifties=fifties+(level*3)") whenever you want to add to the score should work fine.

 

The main bit of care you need to take is when you change "fifties", you should add to it rather than setting it, in case it's currently in the process of draining. You also might need to take a bit of care not to overflow it too, if you allow a lot of quick scoring.

 

I rather like the rolling score effect this results in. I did something similar in 21 Blue.

  • Like 1

Share this post


Link to post
Share on other sites
On 12/5/2017 at 1:36 PM, Coolcrab said:

Hmm, I'm sill not sure. This would still overflow the a if its over 256 right?

   if s{3} then dec a = a + $20

   score = score + a

What is the $ sign in front of the 20 for?

 

I recall somewhere reading that it's simple to change the indivibual numbers in the score/it has it's own built in 3 variables? But I can't find where I read that anywhere.

 

I simply want to be able to toggle individual numbers in the score off and on without affecting the overall score or other numbers in it. I know this is easy but I can't remember where I saw how to do it. Please help

Share this post


Link to post
Share on other sites

To be safe I always keep my score related math to: "score = score + var"  or "score = score - var".  Basically, perform your more complicated math on var beforehand.

 

 

 

 

Share this post


Link to post
Share on other sites
Posted (edited)
2 hours ago, freshbrood said:

What is the $ sign in front of the 20 for?

 

I recall somewhere reading that it's simple to change the indivibual numbers in the score/it has it's own built in 3 variables? But I can't find where I read that anywhere.

 

I simply want to be able to toggle individual numbers in the score off and on without affecting the overall score or other numbers in it. I know this is easy but I can't remember where I saw how to do it. Please help


The $ indicates a hexadecimal number


In decimal the digits are 0..9
in hexidecimal the digits are 0..15 except we don't use decimal numbers for 10..15 we use A..F
So the hexidecimal digits are 0..F
normally you'd get a carry from the lo digit to the hi digit at F in hexadecimal
1 + F = $10 which is 16 in decimal
With bcd (binary coded decimal) the digits only go from 0..9 and the carry comes from any number over 9 
So $20 is hexadecimal for (decimal) 32 (2 * 16) which is interpreted as 20 decimal in bcd (normally 20 decimal would be $14 in hexadecimal ie 1*16 + 4)


The score is six bcd digits in three bytes except they are backwards in memory score[0] to score[2] from HIGHEST to lowest
each bcd digit is a 4 bit nibble
RT has some stuff about dealing with nibbles

Edited by bogax
  • Thanks 1

Share this post


Link to post
Share on other sites
11 hours ago, freshbrood said:

What is the $ sign in front of the 20 for?

 

Have you looked at these sections:

 

Decimal Numbers

 

Hexadecimal Numbers

 

What is a BCD Compliant Number?

 

 

11 hours ago, freshbrood said:

I recall somewhere reading that it's simple to change the individual numbers in the score/it has it's own built in 3 variables? But I can't find where I read that anywhere.

 

I simply want to be able to toggle individual numbers in the score off and on without affecting the overall score or other numbers in it. I know this is easy but I can't remember where I saw how to do it. Please help

 

That nybble example program that bogax linked to should help.

  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks. Also I noticed in batari only 7 pixels of the score numbers display, at least in the first number on the right. The editor allows for changing all 8 pixels but the furthest left column doesn't display. 

 

Is there any way to get all 8 pixels of the score # to show in batari? 

Share this post


Link to post
Share on other sites
2 minutes ago, freshbrood said:

Thanks. Also I noticed in batari only 7 pixels of the score numbers display, at least in the first number on the right. The editor allows for changing all 8 pixels but the furthest left column doesn't display. 

 

Is there any way to get all 8 pixels of the score # to show in batari? 

The far left and right columns of the score font can sometimes bleed into other digits.  It's a safety padding thing :)

  • Thanks 1

Share this post


Link to post
Share on other sites
17 minutes ago, Gemintronic said:

The far left and right columns of the score font can sometimes bleed into other digits.  It's a safety padding thing :)

Annnnd I also just noticed that it does not seem centered in batari, but off by a few pixels (about one digit) to the right. 

 

Is there any way to center it and/or make sure all 8 pixels display? -in batari standars kernel?

Share this post


Link to post
Share on other sites
1 minute ago, freshbrood said:

Annnnd I also just noticed that it does not seem centered in batari, but off by a few pixels (about one digit) to the right. 

 

Is there any way to center it and/or make sure all 8 pixels display? -in batari standars kernel?

That can't be helped, either, and for the same reason. The score kernel manages to draw the score, and part of the playfield on either side of the score to be the pfscore bars. There's not quite enough time to do everything, so a small amount of the score gets cut off as you have seen, and the bB score fonts are designed with this limitation in mind. The placement of the score is a result of where the graphics updates need to happen in the score kernel based on the rest of the timing, so any shifting of this will cause digit corruption. So - known issue, but there's no real fix for it. It's just a quirk of bB.  🙂 

  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites

You can think of the CPU as an artist with a small set of crayons labeled player0, player1, missile0, missile1, ball and playfield.  The artist can only draw by dragging a crayon line by line across the paper.  When he reaches the far end of the page he can go down a row and start draggin' those crayons again.  To further constrain him each crayon can only be dragged so far.  So, if he runs out of player0 crayon he must choose another available crayon for a longer run.  Any other action by the artist makes the crayon stop dragging BUT the next place he could draw still moves across the page.  That includes the thought process to switch crayons.  The bB score kernel switches between player0 and player1 to get 6 digits.  It also needs to start drawing the score as close to the center as possible.  All this requires the CPUs full attention before even trying to process game logic.

 

This is a bad explanation by someone who doesn't understand what he's talking about.  Should check out this book:

https://www.amazon.com/Racing-Beam-Computer-Platform-Studies/dp/026201257X

 

More accurate description here:

https://atariage.com/forums/topic/32481-session-21-sprites/

 

Share this post


Link to post
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.

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...