Jump to content
IGNORED

sprite flipper question


ultima

Recommended Posts

I was on RT's site looking at the sprite flipping example and got a question about this

   dim _Bit2_Flip_p1 = a
   dim _Bit3_Flip_p0 = a

   player0:
   %01111110
   %11111111
   %00011111
   %00000111
   %00011111
   %11111111
   %01111110
end

   player1:
   %10101010
   %11111111
   %10000011
   %10101011
   %11111111
   %10010011
   %11011011
   %10010011
   %01111110
end

   COLUBK = 0

   player0x = 68 : player1x = player0x + 20

   player0y = 55 : player1y = 55



__Main_Loop

   COLUP0 = $1E : COLUP1 = $AE

   if joy0left then _Bit3_Flip_p0{3} = 0 : _Bit2_Flip_p1{2} = 0
   if joy0right then _Bit3_Flip_p0{3} = 1 : _Bit2_Flip_p1{2} = 1


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Note from SpiceWare:
   rem  `
   rem  `  REFPx registers ignore everything except the value in bit 3.
   rem  `
   REFP0 = _Bit3_Flip_p0


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Note from SpiceWare:
   rem  `
   rem  `  Multiplying by 2 will shift all bits to the left one
   rem  `  position, so what was in bit 2 ends up in bit 3.
   rem  `
   REFP1 = _Bit2_Flip_p1 * 2


   drawscreen


   goto __Main_Loop

this section:


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Note from SpiceWare:
   rem  `
   rem  `  Multiplying by 2 will shift all bits to the left one
   rem  `  position, so what was in bit 2 ends up in bit 3.
   rem  `
   REFP1 = _Bit2_Flip_p1 * 2

is using multiplication so my question is would it have any impact on the number of cycles by just adding _Bit2_Flip_p1 to itself? I modified it and compiled it and found it still takes the same amount of bytes and produces the same result via:

REFP1 = _Bit2_Flip_p1 + _Bit2_Flip_p1

I also found that by changing this it also produces the same effect and uses 7 bytes less

   if  joy0left then _Bit3_Flip_p0 = %00000000 : _Bit2_Flip_p1 = %00000000
   if joy0right then _Bit3_Flip_p0 = %00000100 : _Bit2_Flip_p1 = %00000100
   rem  `  REFPx registers ignore everything except the value in bit 3.
   REFP0 = _Bit3_Flip_p0 + _Bit3_Flip_p0
   rem  `  Multiplying by 2 will shift all bits to the left one
   rem  `  position, so what was in bit 2 ends up in bit 3.
   REFP1 = _Bit2_Flip_p1 + _Bit2_Flip_p1

although I am not sure if it saves anything on cycle counting

Edited by ultima
Link to comment
Share on other sites

I was just looking at that section of the bB page yesterday and wondering if I should replace that program with this:

_

   dim _Bit6_Flip_P0 = a
   dim _Bit7_Flip_P1 = a

   player0:
   %01111110
   %11111111
   %00011111
   %00000111
   %00011111
   %11111111
   %01111110
end

   player1:
   %10101010
   %11111111
   %10000011
   %10101011
   %11111111
   %10010011
   %11011011
   %10010011
   %01111110
end

   COLUBK = 0

   player0x = 68 : player1x = player0x + 20

   player0y = 55 : player1y = 55



__Main_Loop


   COLUP0 = $1E : COLUP1 = $AE


   if joy0left then _Bit6_Flip_P0{6} = 0 : _Bit7_Flip_P1{7} = 0
   if joy0right then _Bit6_Flip_P0{6} = 1 : _Bit7_Flip_P1{7} = 1


   ;****************************************************************
   ;
   ;  Flips player0 sprite when necessary.
   ;
   REFP0=0

   if _Bit6_Flip_P0{6} then REFP0=8


   ;****************************************************************
   ;
   ;  Flips player1 sprite when necessary.
   ;
   REFP1=0

   if _Bit7_Flip_P1{7} then REFP1=8


   drawscreen


   goto __Main_Loop
_

Seems like it might be easier for people to understand

Link to comment
Share on other sites

sorry I will simplify the question. Is addition faster than multiplication?

 

example:

(moosegizzards * 2) is the same as (moosegizzards + moosegizzards)

 

so I am figuring that in 6502 asm that one of these statements will compile a smaller faster solution.

 

 

Edited by ultima
Link to comment
Share on other sites

Multiplying by 2 can be accomplished by a left shift (ASL) and is most likely faster than adding a memory location to itself. You could verify this with stella by simply implementing both solutions and then comparing the cycle count in the debugger. If you put a label just before and just after each section of code it should be easy to determine which asm instructions correspond to which basic statements.

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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