Jump to content
JohnGill

hexes game update September

Recommended Posts

Hi all,

I've been wading through the dullest of dull bits of coding in the ongoing saga of my first ever game dev.

I've just finished getting the player's stat bar "blobs" to function correctly. The routine reads the appropriate byte from the player's stats stored in one of the memory banks (health, gold, fatigue etc...) and draws the correct number of blobs, in the correct colour, in the correct place on screen, including splitting over 2 rows if necessary, including quarter / half / 3-quarter blobs. I wrote a simple version of the mod (%) function to do the fractional blobs which worked first time (OH JOY OF JOY!). Then wasted about 2 hours bashing my head against the desk trying to fix a bug which boiled down to me putting "0" where I should have put "#0". (NO JOY! REALLY NO JOY!)

Unfortunately the game looks no different to how it did a month ago, but now I can get on with some more creative aspects of the game!

Oh, and I've now got a working title for the game - 
"THE MYSTERY OF THE QUIET ISLE" which kinda sums it well I think 🙂 

Onwards and upwards!

Bitmap in Untitled-1.png

Bitmap in Untitled-2.png

  • Like 3

Share this post


Link to post
Share on other sites

This message will spoil your feeling of triumph, but it will help your code.

The number four is a power-of-two.  Therefore, you can use shifts to multiply and divide by that number:

    lsr a
    lsr a   ; .A / 4

The remainder of that division is the two bits that were shifted out of the accumulator; in other words:

    and #(4 - 1)    ; .A % 4

If you define the four "blob" characters next to each other in your font, then you can add the remainder number to your code number for the "empty/full" blob.  You immediately will have the code number that will show the desired blob on the screen.

  • Like 2

Share this post


Link to post
Share on other sites
33 minutes ago, Greg King said:

This message will spoil your feeling of triumph, but it will help your code.

The number four is a power-of-two.  Therefore, you can use shifts to multiply and divide by that number:


    lsr a
    lsr a   ; .A / 4

 

The remainder of that division is the two bits that were shifted out of the accumulator; in other words:


    and #(4 - 1)    ; .A % 4

 

If you define the four "blob" characters next to each other in your font, then you can add the remainder number to your code number for the "empty/full" blob.  You immediately will have the code number that will show the desired blob on the screen.

A much neater solution, thanks Greg!

Share this post


Link to post
Share on other sites

And to combo /MOD in a single routine (byte passed in A, whole values return in A, modulus return in X:
;  /4-> A +Mod-> X, Y not touched.
DIV4M: PHA : AND #3 : TAX : PLA : ASL : ASL : RTS

 

  • Like 1

Share this post


Link to post
Share on other sites

If I was given a penny for every time a bug was caused by a missing # then I’d have angrily thrown about £3.50 out of the window by now.


Sent from my iPhone using Tapatalk

  • Like 1
  • Haha 2

Share this post


Link to post
Share on other sites
16 hours ago, Greg King said:

and #(4 - 1)    ; .A % 4

Is this in general true for MOD?

So does this apply for any DIVISOR or if not, in which boundaries of the DIVISOR it is true?

and #(DIV-1) ; .A % DIV ... for all DIV=2^n where n>=1;n<=7

I tried with my good old Windows calculator ...

21 AND 4 should equal 21 % 5. but it does not. The output is 4 and not 1. Not sure how that works or does it just work by chance with 4?

/Edit ... not for any Divisor, but for any Divisor with the power of 2. So 2,4,8,16,32,64,128 ... 

Edited by SerErris

Share this post


Link to post
Share on other sites
15 hours ago, BruceMcF said:

And to combo /MOD in a single routine (byte passed in A, whole values return in A, modulus return in X:
;  /4-> A +Mod-> X, Y not touched.
DIV4M: PHA : AND #3 : TAX : PLA : ASL : ASL : RTS

Another one of those bugs that we must smack over and over and over again:  Bruce shifted in the wrong direction. 😉

  • Haha 2

Share this post


Link to post
Share on other sites
On 9/13/2020 at 2:25 AM, Greg King said:

Another one of those bugs that we must smack over and over and over again:  Bruce shifted in the wrong direction. 😉

It's merely necessary to run the Assembler in "Do What I Mean" mode, and "viola", no bug:

DIV4M: PHA : AND #3 : TAX : PLA : LSR : LSR : RTS

Edit: Note that DWIM mode doesn't always help: in the original effort to port the eForth DOES> to xForth, I had a confused mental model of DOES> and so it was crashing because what "I meant it to do" IMPLIED crashing the inner interpreter. It was only rereading Brad Rodrigez's excellent Moving Forth series on the DOES> that I realized I was trying to cram three different "execution times" into two.

That is, with "CREATE ... DOES>" you write a word that CREATES a word that DOES> something, so there is the time you are compiling the creating word, the time you are running the creating word, and the time you are running the word that was created.

I was doing "time 2" stuff at "time 1", which can't ever work no matter how perfectly the Assembler executes "Do What I Mean" mode.

Edited by BruceMcF
  • Haha 2

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.


×
×
  • Create New...

Important Information

Please review our Terms of Use