Jump to content



0

OK, I'm stumped about paddles


14 replies to this topic

#1 atari2600land ONLINE  

atari2600land

    Quadrunner

  • 6,491 posts
  • All hail the zyzzyva!
  • Location:Salem, Oregon

Posted Sat Apr 19, 2008 4:51 PM

I searched under 'paddles' and couldn't find anything worthy. I bet this is a simple question, though.
How do you make the controller be a paddle in bB? I'm not talking about the fire buttons, I'm talking about left and right paddle movement.

#2 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,543 posts
  • Location:Georgia, USA

Posted Sat Apr 19, 2008 10:49 PM

View Postatari2600land, on Sat Apr 19, 2008 6:51 PM, said:

I searched under 'paddles' and couldn't find anything worthy. I bet this is a simple question, though.
How do you make the controller be a paddle in bB? I'm not talking about the fire buttons, I'm talking about left and right paddle movement.
There's no commands in batari Basic to "make the controller be" anything-- you just use the appropriate commands to read whichever controller you're interested in.

(1) If you want to read the paddles in your batari Basic program, you must specify the "kernel_option" to read the paddles:

   set kernel_options no_blank_lines readpaddle
Note that the "readpaddle" option *cannot* be used by itself-- you *must* specify the "no_blank_lines" option as well-- so that means you can't use missile0 if you're going to read the paddles, since using the "no_blank_lines" option means you lose the use of missile0. Also, the "kernel_options" work only with the standard kernel, so you can't read the paddles if you're using the multisprite kernel.

(2) To read a particular paddle, you must set "currentpaddle" to the number of the paddle you want to read:

   currentpaddle = 0
Note that there are two controller ports, and the paddles come in pairs-- two paddles are connected to one plug-- so you can have either two paddles plugged into one port (and something else, like a joystick, plugged into the other port), or you can have four paddles plugged into two ports. Paddles 0 and 1 are the two paddles plugged into the left controller port, and paddles 2 and 3 are the two paddles plugged into the right controller port.

(3) After you set "currentpaddle" to the number of the paddle you want to read, you must call "drawscreen":

   drawscreen
That doesn't mean you have to call "drawscreen" right away, but the paddle you've selected gets read during "drawscreen," so you won't be able to tell what the value of the selected paddle is until after the "drawscreen" routine has finished.

(4) To get the value of the selected paddle, you must check the "paddle" variable, either inside an "if" statement, or more likely by setting some other variable to it:

   if paddle = 10 then do_something : rem * not very useful
   player0x = paddle : rem * more useful
Note that the value of "paddle" will be between 0 and 77, inclusive (the online help manual says "from about 0-80," but if I use the score to display the value of "paddle," it indicates that the highest value returned is 77).

(5) Since the value of "paddle" will be between 0 and 76, that means you'll probably want to use a formula to convert the value of the paddle into a suitable screen coordinate, depending on whether you're using the paddle to move an object in the vertical or horizontal direction, and whether you want the object to move the full range of that direction, or restrict it to some portion of the screen. You'll also want to take the size of the object into account, since that affects what its minimum and maximum coordinates can be. For example, if you want to move a sprite horizontally (its "x" coordinate), and you want the sprite to move across the full width of the screen but with no wraparound, and the sprite is 8 pixels wide drawn at the single-width size, then its "x" coordinate can range from 1 (farthest left) to 161 - 8 = 153 (farthest right). Since "paddle" can be 0 to 76, that means you would probably want to use the following formula:

   player0x = 2 * paddle + 1
   if player0x > 153 then player0x = 153
(6) You can read only one paddle at a time, so if you want to read two paddles, you'll need to use two drawscreens:

   currentpaddle = 0
   drawscreen
   player0x = 2 * paddle + 1
   if player0x > 153 then player0x = 153
   currentpaddle = 1
   drawscreen
   player1x = 2 * paddle + 1
   if player1x > 153 then player1x = 153
(7) Chances are you won't want to actually put two "drawscreen" statements in your loop, so you could use "currentpaddle" as a way of telling your program which paddle to process after "drawscreen" has finished:

   set kernel_options no_blank_lines readpaddle
loop
   currentpaddle = currentpaddle + 1 : rem * to get the next paddle
   if currentpaddle = 2 then currentpaddle = 0 : rem * to read 0, then 1, then 0 again, etc.
   drawscreen
   on currentpaddle goto paddle_0 paddle_1
comeback
   rem * do some more stuff if you want
   goto loop
paddle_0
   player0x = 2 * paddle + 1
   if player0x > 153 then player0x = 153
   goto comeback
paddle_1
   player1x = 2 * paddle + 1
   if player1x > 153 then player1x = 153
   goto comeback
Michael

Edited by SeaGtGruff, Sat Apr 19, 2008 11:05 PM.


#3 atari2600land ONLINE  

atari2600land

    Quadrunner

  • 6,491 posts
  • All hail the zyzzyva!
  • Location:Salem, Oregon

Posted Sat Apr 19, 2008 11:02 PM

Thank you for the very detailed tutorial about how to use paddles. I haven't seen anything like that before in the bB forums.
-Chris

#4 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,543 posts
  • Location:Georgia, USA

Posted Sat Apr 19, 2008 11:06 PM

View Postatari2600land, on Sun Apr 20, 2008 1:02 AM, said:

Thank you for the very detailed tutorial about how to use paddles. I haven't seen anything like that before in the bB forums.
-Chris
I just corrected an error in it-- I should have said 0 to 77, not 0 to 76! :) I had a bug in my test program that displayed the paddle value in the score-- it was coming out 1 less than the actual value. :-o

Michael

#5 SpiceWare OFFLINE  

SpiceWare

    Quadrunner

  • 5,987 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Sun Apr 20, 2008 10:33 AM

   currentpaddle = currentpaddle + 1 : rem * to get the next paddle
   if currentpaddle = 2 then currentpaddle = 0 : rem * to read 0, then 1, then 0 again, etc.

For just 2 paddles I'd use
   currentpaddle = 1 - currentpaddle : rem * to get the next paddle


#6 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,543 posts
  • Location:Georgia, USA

Posted Sun Apr 20, 2008 11:05 AM

View PostSpiceWare, on Sun Apr 20, 2008 12:33 PM, said:

   currentpaddle = currentpaddle + 1 : rem * to get the next paddle
   if currentpaddle = 2 then currentpaddle = 0 : rem * to read 0, then 1, then 0 again, etc.

For just 2 paddles I'd use
   currentpaddle = 1 - currentpaddle : rem * to get the next paddle
Great idea! Another alternative would be

   currentpaddle = currentpaddle ^ 1
which I think saves 1 byte and 2 cycles. My only lame-ass excuse for the method I used in my original post is that my dog ate my homework... er, I mean, I wanted to give an example that could be modified for other situations-- e.g., a joystick is in the left controller port, and a pair of paddles is in the right controller port:

   set kernel_options no_blank_lines readpaddle
   currentpaddle = 1
loop
   currentpaddle = currentpaddle + 1
   if currentpaddle = 4 then currentpaddle = 2 : rem * read 2, 3, 2, 3, etc.
   drawscreen
   a = currentpaddle - 2
   on a goto paddle_2 paddle_3
comeback
   rem * do something else
   goto loop
paddle_2
   rem * do something
   goto comeback
paddle_3
   rem * do something
   goto comeback
That's my story, and I'm stickin' to it! :)

Michael

#7 SpiceWare OFFLINE  

SpiceWare

    Quadrunner

  • 5,987 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Sun Apr 20, 2008 12:44 PM

For paddles 2 & 3
   currentpaddle =  5 - currentpaddle

This does require that currentpaddle be initialized to either 2 or 3.

Is ^ EOR? If so then currentpaddle = currentpaddle ^ 1 would toggle between 2 and 3 as well.

Edited by SpiceWare, Sun Apr 20, 2008 12:45 PM.


#8 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,543 posts
  • Location:Georgia, USA

Posted Sun Apr 20, 2008 2:17 PM

View PostSpiceWare, on Sun Apr 20, 2008 2:44 PM, said:

For paddles 2 & 3
   currentpaddle =  5 - currentpaddle

This does require that currentpaddle be initialized to either 2 or 3.

Is ^ EOR? If so then currentpaddle = currentpaddle ^ 1 would toggle between 2 and 3 as well.
Yes it is, and yes it would! Thanks for that! It's especially handy since it works for either 0/1 or 2/3, depending on whether you initialize currentpaddle to 0 (or 1) or 2 (or 3). Now what have you got for 0/1/2/3? The best I can think of right now is

   currentpaddle = (currentpaddle + 1) & 3
which doesn't compile as small as it could:

   LDA currentpaddle; 2 bytes, 3 cycles
   CLC; 1 byte, 2 cycles
   ADC #1; 2 bytes, 2 cycles
   AND #3; 2 bytes, 2 cycles
   STA currentpaddle; 2 bytes, 3 cycles -- total 9 bytes, 12 cycles
But it could be replaced with some inline assembly:

   asm
   INC currentpaddle; 2 bytes, 5 cycles
   LDA #3; 2 bytes, 2 cycles
   AND currentpaddle; 2 bytes, 3 cycles
   STA currentpaddle; 2 bytes, 3 cycles -- total 8 bytes, 13 cycles
end
So you could use one or the other, depending on whether you wanted to save 1 byte or 1 cycle. :ponder: I guess it might boil down to how many places you do something like that in your code, and whether they're in the same vblank period or spread around in routines that would be performed in different vblank periods.

Michael

Edited by SeaGtGruff, Sun Apr 20, 2008 2:17 PM.


#9 SpiceWare OFFLINE  

SpiceWare

    Quadrunner

  • 5,987 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Sun Apr 20, 2008 6:17 PM

that's what I'd do for 0-3.

#10 gamebotonline OFFLINE  

gamebotonline

    Combat Commando

  • 7 posts

Posted Fri Jul 11, 2008 10:33 AM

Hello everyone!

Great info so far. The only problem is, my paddles still don't seem to work in stella. Am I just hitting the wrong buttons on my keyboard? Do I need to set up stella before I can use the keyboard to simulate paddles? According to this source: http://stella.source...x.html#Keyboard the left and right arrow keys should control paddle 0. In my code nothing happens if I hit the appropriate keys. Here's the code, what do I have to do to get this bad boy to move with paddles?:

Quote

1 rem smartbranching on
include div_mul.asm
set kernel_options player1colors no_blank_lines readpaddle

player1x=78
player1y=70

currentpaddle=0

player1color:
14
24
26
28
38
12
14
24
end

loop

player1x=paddle

player1:
%0011100
%0011100
%0111110
%0111110
%0111110
%0111110
%0111110
%0111110
end

drawscreen

goto loop

Also, is there an option in batari that allows both players to be colored or pfheights and colors to be set when using paddles?

#11 SpiceWare OFFLINE  

SpiceWare

    Quadrunner

  • 5,987 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Fri Jul 11, 2008 2:25 PM

You have to tell Stella to use paddles, it defaults to joysticks.

Load up your bin

hit TAB

select GAME PROPERTIES

select CONTROLLER tab

#12 gamebotonline OFFLINE  

gamebotonline

    Combat Commando

  • 7 posts

Posted Sat Jul 12, 2008 12:31 PM

View PostSpiceWare, on Fri Jul 11, 2008 4:25 PM, said:

You have to tell Stella to use paddles, it defaults to joysticks.

Load up your bin

hit TAB

select GAME PROPERTIES

select CONTROLLER tab

haha, simple
Thanks, it works now!

#13 supercat OFFLINE  

supercat

    Quadrunner

  • 6,367 posts

Posted Sat Jul 12, 2008 12:43 PM

View PostSeaGtGruff, on Sun Apr 20, 2008 3:17 PM, said:

So you could use one or the other, depending on whether you wanted to save 1 byte or 1 cycle.

What if you do:
  currentpaddle++
  currentpaddle &= 3
I would think that would give the same result as the ASM version. If the X register is free, though, the ASM version can be improved:
  lda #3
  ldx currentpaddle
  inx
  sax currentpaddle
Seven bytes and ten cycles.

#14 atari2600land ONLINE  

atari2600land

    Quadrunner

  • 6,491 posts
  • All hail the zyzzyva!
  • Location:Salem, Oregon

Posted Fri Aug 8, 2008 3:29 PM

How do you read the fire button on the paddle?

#15 Impaler_26 OFFLINE  

Impaler_26

    Cookie Meister

  • 2,148 posts
  • Braindead
  • Location:Hueco Mundo

Posted Fri Aug 8, 2008 3:53 PM

They are equal to the joystick-directions left and right.

joy0right=fire on paddle 0
joy0left=fire on paddle 1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users