Propeller PONG - for the Quick Start board
cavelamb
Posts: 720
First there was PONG, then came the rest of the industry.
Besides being something to mess with, I wanted to see how code running in different cogs would interact.
ESPECIALLY something like a keyboard driver.
Those kind of things take time and I was curious about how well they could hook up.
I'm tossing this little ditty up on the board for a discussion piece.
By the way, MY keypad driver is still too flaky to trust here, so I'm instead using a cut down version
of one from the Object Exchange. ButtonMenu111212a.
PONG (sorta)
Bat the ball back and forth and score a point when your opponent misses.
The end buttons on the QS board are the paddles.
It is SUPPOSED to speed up each pass, but that's where it ran into trouble.
With the speed up running, it would start missing the keys after about 4 passes (one way each).
I (obviously) don't claim this is pretty code, nor even presentable (other than as a student).
But it does play - sorta. :^)
It will be interesting to see what my betters make of it.
So, without further fanfare,
PONG
and the Touch pad driver
Besides being something to mess with, I wanted to see how code running in different cogs would interact.
ESPECIALLY something like a keyboard driver.
Those kind of things take time and I was curious about how well they could hook up.
I'm tossing this little ditty up on the board for a discussion piece.
By the way, MY keypad driver is still too flaky to trust here, so I'm instead using a cut down version
of one from the Object Exchange. ButtonMenu111212a.
PONG (sorta)
Bat the ball back and forth and score a point when your opponent misses.
The end buttons on the QS board are the paddles.
It is SUPPOSED to speed up each pass, but that's where it ran into trouble.
With the speed up running, it would start missing the keys after about 4 passes (one way each).
I (obviously) don't claim this is pretty code, nor even presentable (other than as a student).
But it does play - sorta. :^)
It will be interesting to see what my betters make of it.
So, without further fanfare,
PONG
CON { Pong01.spin - March 9, 2911 - Richard Lamb} _CLKMODE=XTAL2 _xinfreq = 5_000_000 Right = 1 Left = 2 ButtonR = 0 ButtonL = 7 SpeedStart = 150 SpeedInc = -0 ' -33 locks out the buttons after about 4 passes! SpeedMax = 100 OBJ Touch: "TouchButtons" VAR LONG MS001, Buttons, delay BYTE ledByte, button[8] BYTE PointsRight, PointsLeft,First, Last, LED BYTE SpeedBall, X,Y,Z, A, B, C BYTE Server, Direction PUB SetUp delay := clkfreq / 100 ' used by Buttons object Touch.start( @delay, @Button ) ' send address of Buttons MS001 := CLKFREQ / 1_000 ' define 1 millisec outa[ 16..23 ] := $00 ' 000000 ' dira[ 16..23 ] := $FF ' 111111 ' Pong '========================================================= ' PUB Pong ClearAll ChangeDirection Server := Left Repeat BallMove if Direction == Right ' to the Right if Button[ButtonR] == 1 ' we hit it! speed up and return if SpeedBall > SpeedMax SpeedBall := SpeedBall+SpeedInc ChangeDirection else ScoreRight ' missed it by that much.. elseIf Direction == Left ' to the left if Button[ButtonL] == 1 if SpeedBall > SpeedMax SpeedBall := SpeedBall+SpeedInc changeDirection else ScoreLeft A++ Pri ScoreRight PointsRight++ if PointsRight == 4 ' winner! Repeat 10 outa [16..23] := 011111 waitMS(50) outa [16..23] := 000000 waitMS(50) ClearAll else 'show score Repeat 10 Repeat x from 23-PointsRight to 23 outa[x] ~~ waitMS(50) outa [16..23] := 000000 waitMS(50) SpeedBall := SpeedStart Pri ScoreLeft PointsLeft++ if PointsLeft == 4 ' winner! Repeat 10 outa [16..23] := 111000 waitMS(50) outa [16..23] := 000000 waitMS(50) ClearAll else Repeat 10 Repeat x from 16 to 16+PointsLeft outa[x] ~~ waitMS(50) outa [16..23] := 000000 waitMS(50) SpeedBall := SpeedStart Pri ClearAll PointsLeft := -1 PointsRight := -1 SpeedBall := SpeedStart PUB ChangeDirection If Direction == Right Direction := Left else Direction := Right PUB BallMove If Direction == Left First:= 16 Last := 23 else First:=23 Last :=16 repeat Led FROM First to Last outa [LED] := 1 WaitMS(SpeedBall) outa [LED] := 0 WaitMS(100) PUB WaitMS(W) 'wait for W milliseconds W := W*MS001 WaitCNT (W+cnt)
and the Touch pad driver
{cut down version of the pad code in ButtonMenu111212a.} CON BUTTON_PINS = $FF PUB Start(delayAndBytesPtr, buttonPtr) buttonAddress := buttonPtr cognew(@Entry, delayAndBytesPtr) ' Launch a new cog to read samples DAT org Entry rdlong WaitTime, par mov addressBase, par 'add addressBase, #4 mov outa, #BUTTON_PINS ' set TestPins high, but keep as inputs mov Wait, cnt ' preset the counter add Wait, WaitTime Loop mov counter, resetLoop mov stickybuttons, temp mov temp, zero innerLoop or dira, #BUTTON_PINS ' set TestPins as outputs (high) andn dira, #BUTTON_PINS ' set TestPins as inputs (floating) mov reading, #BUTTON_PINS ' create a mask of applicable pins waitcnt wait, waitTime ' wait for the voltage to decay andn reading, ina ' clear decayed pins from the mask or temp, reading or stickybuttons, temp djnz counter, #innerLoop mov addressTemp, buttonAddress 'wrbyte stickybuttons, addressTemp 'add addressTemp, one mov bitCount, #8 :Bit shr stickybuttons, one wc ' shift off the bit to write mov temp2, zero muxc temp2, one ' make temp2 either one or zero wrbyte temp2, addressTemp add addressTemp, one djnz bitCount, #:Bit jmp #Loop zero long 0 one long 1 resetLoop long 4 temp long 0 counter long 0 buttonAddress long 0 reading res 1 waitTime res 1 wait res 1 stickybuttons res 1 addressBase res 1 addressTemp res 1 temp2 res 1 bitCount res 1