hexes game update September

Chat about anything CX16 related that doesn't fit elsewhere
Post Reply
JohnGill
Posts: 66
Joined: Thu Jun 25, 2020 11:45 am

hexes game update September

Post by JohnGill »


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
Greg King
Posts: 162
Joined: Wed Jul 08, 2020 1:14 pm

hexes game update September

Post by Greg King »


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.

JohnGill
Posts: 66
Joined: Thu Jun 25, 2020 11:45 am

hexes game update September

Post by JohnGill »



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!

BruceMcF
Posts: 1336
Joined: Fri Jul 03, 2020 4:27 am

hexes game update September

Post by BruceMcF »


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

 

izb
Posts: 31
Joined: Thu May 21, 2020 10:04 am

hexes game update September

Post by izb »

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
SerErris
Posts: 172
Joined: Sat Aug 08, 2020 9:18 am

hexes game update September

Post by SerErris »



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

User avatar
desertfish
Posts: 1097
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

hexes game update September

Post by desertfish »


The mod trick only works for powers of two because of how binary numbers work.

BruceMcF
Posts: 1336
Joined: Fri Jul 03, 2020 4:27 am

hexes game update September

Post by BruceMcF »


Yes, for any power of 2, b/a, a=2^n, mod := b &  (a-1), if b>0, quotient := (b >> n)

Greg King
Posts: 162
Joined: Wed Jul 08, 2020 1:14 pm

hexes game update September

Post by Greg King »



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

BruceMcF
Posts: 1336
Joined: Fri Jul 03, 2020 4:27 am

hexes game update September

Post by BruceMcF »



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.

Post Reply