Jump to content

Photo

Splitting a variable - display to screen


13 replies to this topic

#1 Muddyfunster OFFLINE  

Muddyfunster

    Space Invader

  • 12 posts

Posted Sun Aug 27, 2017 11:37 AM

Hi All,

 

Long time lurker (many many years..), 1st time poster!..

 

I am working on an idea for a game, based on the old BBC Micro pack in title "Yellow River Kingdom". It's a game I always thought the 2600 could do and there have been many clones on other platforms. Probably not a great choice for my first effort at coding a game on the 2600, but I figured it being less "arcadey" would be easier. Oh how wrong could I be :)

 

I've programmed before (ZX Spectrum, BBC Basic, Commodore Basic) so the structures and concepts in Batari Basic are reasonably familiar. I even dabbled with Z80 assembler around 20 years ago.

 

I'll explain my game idea summary and then the problem I'm wrestling with:

 

Game Summary :

 

 

  • DPC+ kernel, idea is to use the keypad for input (open to suggestions but this seems to work in concept as user input is solely numeric)
  • You are the ruler of a village between a river and mountain range. 
  • The game is split in to Years, each year has 4 seasons (turns).
  • For each season the leader has to decicde how many of the people in the villiage to assign to 3 principle tasks
    • Guard the village from the bandits in the mountains
    • Repair and maintain the Dyke so it doesn't flood the villiage and crop fields.
    • Plant and gather crops and fish from the river.
  • After each season's selections, the logic processes the choices and a cut scene is displayed showing the outcome (bandit raid successful, bandit raid defeated, dyke leaks, etc), followed by a summary showing losses and gains.
  • Repeat  to next season / year until there is no one left or a set of as yet undetermined win conditions are met.

 

I've been testing out playfield and flow / structure ideas using the DPC+ kernel. My idea is for each element to be broken out to a new "screen". Screen 1 is the input screen, screen 2 in the results cut scene, screen 3 is the results display etc. I don't have much working code to share yet as a lot of my work so far has been with pencil and paper and stand alone sections don't do much yet.  (It was great fun experimenting with the title mini kernel though and getting that working).

 

I hit a brick wall that I've been banging my head against for a few days :

 

How do I get the input from the user on to the screen.

 

The input screen is split into 4 sections, 1 sections shows total number of people in the village, 2nd shows the number for guard duty, 3rd shows the number set for food production, 4th shows the number set for maintaining the dyke.

 

My idea was to have a variable that holds the number of "people" and variables for each function that needs people assigned, to illustrate my babbling, i'll call them "_totalpeople", "_guard", "_crops", "_dyke"

 

_totalpeople = 125

 

So now I need to allow the user to select some of those to guard the village.(my idea is to use the keypad for input maybe adapting the excellent examples here http://atariage.com/...i-basic/page-2)

 

My idea was to use sprites to represent user input (numbers) on the screen in the absence of any other easy way to represent alpha-numerics on the screen easily (if there is a way i've overlooked, i'm all ears!)

 

So the user types 40 on the keypad followed by * (for enter) and on the screen it will display "40" in "Guard" area and set the guard variable to 40.

 

_guard = 40

 

and so on.

 

where I am struggling is how to translate 40 which would be stored, probably in the score for showing the input into the _guard variable (so it can be used in the logic) and then into 3 component numbers (a "0", a "4" and a "0") so I can call the sprites to represent those numbers on the screen in the right area.

 

I can't figure out how to get the number input (as shown by keypad to score here by CurtisP : http://atariage.com/forums/topic/105865-keypads-and-batari-basic/page-2) fromthe score to my variable and then split the variable into hundreds, tens and units so i can code up a check to then place the relevant sprite detail for the digit..

 

Putting the input considerations aside, splitting the variable seems to be my biggest headache, I just can't get anything to work.

 

I looked at masking but I must admit, while I understand the principle, I couldn't get it to work. (I read through the two threads I found on here)

 

I don't want to abandon what could be a really interesting project but right now I'm pretty stumped and feel like I've bitten off a bit more than I can chew.

 

 

 

TL;DR

 

I can't figure out out how input and store a number (keypad most likely - open to other suggestions) and then split that stored number into individual digits for the purpose of displaying it using sprites / other method on the screen.

 

Any suggestions or pointers would be appreciated.

 

(Sorry for the long winded post, but I hope the context helps)

 

 

Cheers,

 

Muddyfunster.,

 

 

 

 



#2 WizardBone OFFLINE  

WizardBone

    Star Raider

  • 79 posts

Posted Sun Aug 27, 2017 1:07 PM

I'd admit I'm a little lost at what you are trying to do lol BUT, if I understand, you are looking for a way to give the player a number input so he can assign different amounts of people?
Perhaps you can use the score? Something like joyUp and down will change the score number to be, the amount of people you want to use. 

the score can be broken into three sections to toy with, no idea if ANY of this has relevance to you lol

Sounds interesting, not sure I am 100% what you are trying to do. 


Edited by WizardBone, Sun Aug 27, 2017 1:09 PM.


#3 Muddyfunster OFFLINE  

Muddyfunster

    Space Invader

  • Topic Starter
  • 12 posts

Posted Sun Aug 27, 2017 1:56 PM

Kind of :)

 

I need a way to take the input from the user (I'd not thought of using the score the way you suggested) to provide a number, then i need to split that number down into HUNDREDS, TENS, UNITS so I can "print" on screen the number using sprites.

 

The input part should be easy enough to figure out, regardless of whether I go for paddles, joystick or pad, just to increment or decrement a number. The hard part is taking that input and being able to manipulate it.

 

It all slots together in my head, but it's much harder to explain ! 



#4 WizardBone OFFLINE  

WizardBone

    Star Raider

  • 79 posts

Posted Sun Aug 27, 2017 3:08 PM

Hmmm, when you say you need to split the number down I still think about the score because youcan split that 3 ways

 

00 | 00 | 00

 

Example above, that is how it splits. And then you can access just those three parts are separate numbers or combined, if you needed. It kinda is tens, hundred, thousands, Might be able to work with it.

 

I'm trying to think of other ways though. By the sounds of how you explain, i'd just splt up the 6 digit socre in three parts. But you may think of a better way for your own methods. Hard to say hmmm

 

Edit: Are you using sprites and playfields to show player input? Because that might be hard on resources. So again I go back to score, seems the numbers are already on screen. 

 

Random terrain site explains it better than I can, you would be looking for something like below, they do not take up precious variables either. 

    _sc1 = score
   _sc2 = score+1
   _sc3 = score+2

Edited by WizardBone, Sun Aug 27, 2017 3:17 PM.


#5 Muddyfunster OFFLINE  

Muddyfunster

    Space Invader

  • Topic Starter
  • 12 posts

Posted Sun Aug 27, 2017 5:28 PM

Thanks Wizardbone. I hear what you are saying with the resource considerations and agree it's worth more investigation.

 

I still need to figure out out to get the number in the score split out. 


Edited by Muddyfunster, Sun Aug 27, 2017 5:29 PM.


#6 Muddyfunster OFFLINE  

Muddyfunster

    Space Invader

  • Topic Starter
  • 12 posts

Posted Tue Aug 29, 2017 11:22 AM

So any ideas on how to take the number in the score and split it in to three digits (Hundreds, Tens, Units) ?

 

Any guidance would be appreciated!



#7 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,082 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Tue Aug 29, 2017 11:43 AM

So any ideas on how to take the number in the score and split it in to three digits (Hundreds, Tens, Units) ?
 
Any guidance would be appreciated!


This is all I know about messing around with the score:

 

randomterrain.com/atari-2600-memories-batari-basic-commands.html#ex_score_digit_check



#8 ZackAttack OFFLINE  

ZackAttack

    Moonsweeper

  • 485 posts
  • Location:Orlando, FL US

Posted Tue Aug 29, 2017 1:29 PM

Using the bitwise and that RT linked to should work fine for the ones and hundreds digits. For the tens digit I'm assuming you want the result to be a number between 0-9 right? If so you should use a right shift instead of an and operation. In bB I believe you can do this by simply dividing by 16.

tens = _sc3/16


#9 Muddyfunster OFFLINE  

Muddyfunster

    Space Invader

  • Topic Starter
  • 12 posts

Posted Tue Aug 29, 2017 2:11 PM

Thanks both, I'll give this a try and see what happens.

 

Thanks again!



#10 Sprybug OFFLINE  

Sprybug

    Dragonstomper

  • 540 posts

Posted Thu Aug 31, 2017 1:17 AM

In Batari you can split the score into 3 sections.  It's what I did with Zippy the Porcupine to make the score display stats instead of a score.  You can do it by doing this:

 

dim _sc1 = score
dim _sc2 = score+1
dim _sc3 = score+2

 

Once you do that, you can assign values in hexadecimal to these 3 varaibles.  I used a custom score asm file to get 16 possibilities instead of just 0-9.  With that, you can define your own sprite graphics.  So with that file I made a Zippy head, an empty space, and 3 sprites for the animated ring in the score.  It was divided like this:

 

_sc1 was the Zippy head and the # of lives, so $Bx x=0-9 for lives

_sc2 was an empty space and then the animated ring, so $AC,$AD,or $AE

_sc3 was the number of rings $00-$99


Edited by Sprybug, Thu Aug 31, 2017 1:19 AM.


#11 WizardBone OFFLINE  

WizardBone

    Star Raider

  • 79 posts

Posted Sat Sep 2, 2017 6:37 PM

In Batari you can split the score into 3 sections.  It's what I did with Zippy the Porcupine to make the score display stats instead of a score.  You can do it by doing this:

 

dim _sc1 = score
dim _sc2 = score+1
dim _sc3 = score+2

 

Once you do that, you can assign values in hexadecimal to these 3 varaibles.  I used a custom score asm file to get 16 possibilities instead of just 0-9.  With that, you can define your own sprite graphics.  So with that file I made a Zippy head, an empty space, and 3 sprites for the animated ring in the score.  It was divided like this:

 

_sc1 was the Zippy head and the # of lives, so $Bx x=0-9 for lives

_sc2 was an empty space and then the animated ring, so $AC,$AD,or $AE

_sc3 was the number of rings $00-$99

haha there ya go muddy, sprybug explained it well enough. Basically what I was hinting towards earlier. Did you try it out? I been wondering if you worked it out after or not.



#12 Muddyfunster OFFLINE  

Muddyfunster

    Space Invader

  • Topic Starter
  • 12 posts

Posted Mon Sep 4, 2017 5:09 AM

Yes!, that's exactly what I was getting at, and Sprybug's explanation (along with reading the section on Random Terrain's site about 10 times) makes more sense now,.

 

I started to experiment away from my main code, just as a break out to familiarise myself with score and manipulating it. I decided to start small and just understand how it works and I've run into another issue, which I have no doubt is down to my lack of understanding of the intricacies of how Bb works. (I spent about 4 hours last night trying to figure this out  :mad: )

 

Dealing with "score" - I understand score is effectively a 24bit number and so on.

 

So,

 

score = 175 works fine:

scorecolor = $0E

score = 175

_mainloop



drawscreen

goto _mainloop 

but

 

if I try to use a variable to set the score, I get unexpected results.


scorecolor = $0E

dim people = a

people = 175
score = people

_mainloop



drawscreen

goto _mainloop

When I do that the score reads "64" instead of the expected "175".

 

I'm clearly missing something (probably something simple) but frustratingly I cannot figure out what! I read the bit about BCD compliant numbers here (randomterrain.com/atari-2600-memories-batari-basic-commands.html#ex_score_digit_check) and I've tried experimenting with 4.4 and 8.8 numbers and various other things that I read and found on here and the RT site that thought might be the key to making it work, without success. :?

 

I'd appreciate any guidance from an experienced hand!

 

 

Thanks!


Edited by Muddyfunster, Mon Sep 4, 2017 8:49 AM.


#13 bogax OFFLINE  

bogax

    Dragonstomper

  • 706 posts

Posted Mon Sep 4, 2017 7:16 AM

score is not a 24 bit binary number, its 6 BCD digits

 

(this is a complete guess) 175 as two hex digits is 10 and 15 in hex, $AF the A is 160 in decimal and the F is 15 so the number gets adjusted to 65 with a couple of carries thrown in for the tens

 

assuming you're using sprybugs naming, try setting sc2 = $01: sc3 = $75

 

somewhere on RTs page are routines (or links to routines) for putting bytes into the score

 

Varianle Testing


Edited by bogax, Mon Sep 4, 2017 7:35 AM.


#14 Muddyfunster OFFLINE  

Muddyfunster

    Space Invader

  • Topic Starter
  • 12 posts

Posted Mon Sep 4, 2017 12:24 PM

Thanks Bogax for the pointers.  :thumbsup:

 

I figured out how to get the variable into the score using the example code from the co-ordinates example on RT's site. 

  temp4 = people

  _sc2 = _sc2 & 240 : _sc3 = 0
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 100 then _sc2 = _sc2 + 1 : temp4 = temp4 - 100
   if temp4 >= 50 then _sc3 = _sc3 + 80 : temp4 = temp4 - 50
   if temp4 >= 30 then _sc3 = _sc3 + 48 : temp4 = temp4 - 30
   if temp4 >= 20 then _sc3 = _sc3 + 32 : temp4 = temp4 - 20
   if temp4 >= 10 then _sc3 = _sc3 + 16 : temp4 = temp4 - 10
   _sc3 = _sc3 | temp4

If I change the value of "people" then the score changes to the appropriate number. 

 

Every day is a school day :)






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users