Efficient way to store X coarsniate and check for right x pos

Do you live and breathe hexadecimal? Do you like speaking to hardware directly?

Moderator: Programming Moderators

Post Reply
robpearmain
Posts: 62
Joined: Tue May 30, 2017 5:35 pm
Location: York
Contact:

Efficient way to store X coarsniate and check for right x pos

Post by robpearmain » Sat Jun 10, 2017 10:01 pm

The sprite documentation shows, due to possibility of writing over the border to allow an x coordinate 0-319 where the X MSB is written out when showing the sprite

What is the most efficient way of storing the x pos (9 bytes) and checking if hit 319 and if so set to 0
Rob Pearmain
Bipboi (Zx Spectrum 48k), Harry Hedgehog (ZX Spectrum [1K]), Luna C (PC), Turbotoons (PC)

ZX Spectrum 48k, +, 128k, Next (board)

SavourySnaX
Posts: 17
Joined: Mon May 29, 2017 7:31 pm

Re: Efficient way to store X coarsniate and check for right x pos

Post by SavourySnaX » Sun Jun 11, 2017 7:47 am

Well it depends on how you intend to use your sprites..

For example, if you were making a single screen/flip screen type game where your sprites remain within the physical bounds of the screen, you can get away with using a byte for X and simply adding 32 before dumping to the sprite register (keep hold of the carry and then adc with 0 (or use rla) into the 3rd byte).

If you absolutely need the full 0-319, then just use 2 bytes - its not as if memory is a problem :) (you can always use the remaining upper 7 bits for flags etc.... Comparisons in 16 bits can be performed as 2 8bit operations (or sbc hl,rp if you have the values in registers).

robpearmain
Posts: 62
Joined: Tue May 30, 2017 5:35 pm
Location: York
Contact:

Re: Efficient way to store X coarsniate and check for right x pos

Post by robpearmain » Sun Jun 11, 2017 5:07 pm

SavourySnaX wrote:
Sun Jun 11, 2017 7:47 am
Well it depends on how you intend to use your sprites..

For example, if you were making a single screen/flip screen type game where your sprites remain within the physical bounds of the screen, you can get away with using a byte for X and simply adding 32 before dumping to the sprite register (keep hold of the carry and then adc with 0 (or use rla) into the 3rd byte).

If you absolutely need the full 0-319, then just use 2 bytes - its not as if memory is a problem :) (you can always use the remaining upper 7 bits for flags etc.... Comparisons in 16 bits can be performed as 2 8bit operations (or sbc hl,rp if you have the values in registers).
Many thanks, I think if we are going to get the full use of over border sprites then the latter is a good solution

Say HL contained 319, to check if we had hit 320 when increased I guess it would be a matter doing something Like (where hl contains x)

Code: Select all

LD a,h
And 1
Jp z, not320
LD a,l
And 64
Jp z,not320
; we have hit 320
LD hl,0000
Rob Pearmain
Bipboi (Zx Spectrum 48k), Harry Hedgehog (ZX Spectrum [1K]), Luna C (PC), Turbotoons (PC)

ZX Spectrum 48k, +, 128k, Next (board)

Post Reply