Jump to content
IGNORED

OK, I'm stumped about paddles


atari2600land

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

   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

Link to comment
Share on other sites

   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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 2 months later...

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.sourceforge.net/docs/index.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?:

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 weeks later...

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