Computer Science Canada

Frustrations Toward the Parallel Port

Author:  Radorii Reikane [ Tue Jun 12, 2007 3:46 pm ]
Post subject:  Frustrations Toward the Parallel Port

Top of the morning to you all. It seems that this is the only place I can find to seek out Turing Help on the web. I looked around for a topic that had the same problem as me, but nothing turned out well. So therefore, I shall now seek the help I may (or may not) need.

I'm currently in a Computer Engineering/Programming class at my high school right now. The engineering part of it was nice, I learned a few new tricks such as ping, msconfig, and how to take a computer apart without any sort of medical malpractice. As fun as that was (actually, it was a nightmare since my not-so fellow classmates are the worst people I could ever imagine), that is now closed up and the programming starts. We are using Turing, which is a bore, since I already learned about it (and Java) in two other classes. Then my teacher proved to be much-less-than-entertaining with it, so I decided to ignore whatever assignments/exercises he gave and I did what I wanted.

So what did I end up making? Why Pong of course! Everyone loves Pong. I thought since the last time I used Turing, I wasn't really able to churn out a game, so something simple would have been great to start off.

Then came the ISU project. Integration where we all use a parallel port to make Turing do something to an old-fashioned electronics breadboard. Everyone else was doing some "Traffic Light" sort of thing using the parallelput command. My immediate thought was "This is too boring". So I wondered if that fabled "Joystick Game using Turing" would do.

At first, I had the problem of it not picking up the Parallel Port/I-O Device, but that was resovled quickly. But now, I am left in a bit of a jam. You see, I know Turing is able to pick up the Parallel Port and the power from the breadboard, since it doesn't crash at the parallelget command, but it seems even there, it just won't work! I've got pins 10, 11, 12, and 13 reserved, with (for example) "power to pin 10 means the player one paddle moves up" or something like that. ... But when I run the game with the parallel port working, it won't accept any power from the breadboards, and even if pin 10 isn't plugged in, the player one paddle moves up. I've recently learned that I might also need a buffer chip before sending the power to their pins through the peripheral, but that isn't the point. What concerns me is that even if only the ground pin is plugged into the breadboard, the player one paddle will still go up without any input at all and the other types of inputs remain inactive. That fact that it is doing that means my syntax is messed up. The book I read on turning was very vague with how to use IF Statements in Combination with parallelget in the first place, so I hope you good people can steer me in the correct direction!

So I swiped a copy of Turing off my school's network using the old "copypaste onto a USB Drive" method and brought it here. This is the full code for the game. I've shrunken the irrelevant working parts of the game and bolded the stuff that is of issue. Please give it a look over and if you know what is wrong, please say.

Quote:

setscreen ("graphics")
View.Set ("offscreenonly")
var control : array char of boolean
var ballx, bally, dir, on, skipper, score, level, bouncecombo, landcombo, pgoals, egoals, levelup, messup, difficulty, ruleset, intro, menu, ctype, mode, endgame, boostspeed, joystick : int := 0
var timeplayed : real := 0
var titlefont : int := Font.New ("sans serif:100:bold")
% Dir Settings:
% 1 := Left Up
% 2 := Right Up
% 3 := Left Down
% 4 := Right Down
% Joystick Inputs
% Pin 10 (Value of 64) is Player One UP.
% Pin 11 (Value of 128) is Player One DOWN.
% Pin 12 (Value of 32) is Player Two UP.
% Pin 13 (Value of 16) is Player Two DOWN.
loop
ballx := 0
bally := 0
dir := 0
on := 0
skipper := 0
score := 0
level := 0
bouncecombo := 0
landcombo := 0
pgoals := 0
egoals := 0
levelup := 0
messup := 0
difficulty := 0
intro := 0
menu := 0
ctype := 0
mode := 0
endgame := 0
ruleset := 0
timeplayed := 0
boostspeed := 0
% -------------
difficulty := 75
menu := 0
ctype := 0
mode := 1
loop % Loop the Entire Game
% Title Screen
loop
Input.KeyDown (control)
colorback (7)
color (0)
cls
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put " Start Game "
if mode = 1 then
put " Mode - VS COM "
else
put " Mode - VS MAN "
end if
if ctype = 0 then
put " Control - Keyboard "
else
put " Control - Joystick "
end if
if ruleset = 0 then
put " Rules: Slow -To100 "
level := 0
elsif ruleset = 1 then
put " Rules: Mild -To100 "
level := 49
elsif ruleset = 2 then
put " Rules: Fast -To100 "
level := 74
elsif ruleset = 3 then
put " Rules: Slow-10Goal "
level := 0
elsif ruleset = 4 then
put " Rules: Mild-10Goal "
level := 49
elsif ruleset = 5 then
put " Rules: Fast-10Goal "
level := 74
end if
if mode = 2 then
if ctype = 0 then
put " (Player 2 uses the 8 and 2 Keys on the Numpad)"
else
put ""
end if
else
put ""
end if
put " Radorii Reikane 2007"
put ""
colorback (0)
if menu = 0 then
locate (18, 25 + 3)
put " " ..
locate (18, 46 + 3)
put " " ..
elsif menu = 1 then
locate (19, 25 + 3)
put " " ..
locate (19, 46 + 3)
put " " ..
elsif menu = 2 then
locate (20, 25 + 3)
put " " ..
locate (20, 46 + 3)
put " " ..
elsif menu = 3 then
locate (21, 25 + 3)
put " " ..
locate (21, 46 + 3)
put " " ..
end if
Font.Draw ("PONG", 119, 220, titlefont, 0)
View.Update
Time.Delay (100)
Draw.Cls
if control (' ') then
if menu = 0 then
exit
elsif menu = 1 then
if mode = 1 then
mode := 2
else
mode := 1
end if
elsif menu = 2 then
if ctype = 0 then
ctype := 1
else
ctype := 0
end if
elsif menu = 3 then
if ruleset = 0 then
ruleset := 1
elsif ruleset = 1 then
ruleset := 2
elsif ruleset = 2 then
ruleset := 3
elsif ruleset = 3 then
ruleset := 4
elsif ruleset = 4 then
ruleset := 5
elsif ruleset = 5 then
ruleset := 0
end if
end if
elsif control (KEY_DOWN_ARROW) then
if menu not= 3 then
menu := menu + 1
end if
elsif control (KEY_UP_ARROW) then
if menu not= 0 then
menu := menu - 1
end if
end if
end loop
if mode = 1 then
colorback (7)
color (0)
cls
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put " Start Game "
if mode = 1 then
put " Mode - VS COM "
else
put " Mode - VS MAN "
end if
if ctype = 0 then
put " Control - Keyboard "
else
put " Control - Joystick "
end if
if ruleset = 0 then
put " Rules: Slow -To100 "
elsif ruleset = 1 then
put " Rules: Mild -To100 "
elsif ruleset = 2 then
put " Rules: Fast -To100 "
elsif ruleset = 3 then
put " Rules: Slow-10Goal "
elsif ruleset = 4 then
put " Rules: Mild-10Goal "
elsif ruleset = 5 then
put " Rules: Fast-10Goal "
end if
put ""
put " Radorii Reikane 2007"
Font.Draw ("PONG", 119, 220, titlefont, 0)
put ""
colorback (7)
color (0)
locate (1, 1)
put "Please Wait"
colorback (0)
locate (2, 1)
for i : 1 .. 80
Time.Delay (10)
put " " ..
View.Update
end for
colorback (0)
cls
Draw.Cls
% Difficulty
loop
Input.KeyDown (control)
colorback (7)
color (0)
cls
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put ""
put " Easy COM "
put " Medi COM "
put " Hard COM "
put ""
put ""
put ""
colorback (0)
if menu = 0 then
locate (19, 25 + 3)
put " " ..
locate (19, 46 + 3)
put " " ..
elsif menu = 1 then
locate (20, 25 + 3)
put " " ..
locate (20, 46 + 3)
put " " ..
else
locate (21, 25 + 3)
put " " ..
locate (21, 46 + 3)
put " " ..
end if
Font.Draw ("PONG", 119, 220, titlefont, 0)
View.Update
Time.Delay (100)
Draw.Cls
if control (' ') then
colorback (7)
color (0)
cls
Draw.Cls
colorback (7)
cls
Font.Draw ("PONG", 119, 220, titlefont, 0)
if menu = 0 then
difficulty := 75
colorback (7)
color (0)
locate (1, 1)
put "Please Wait"
colorback (0)
locate (2, 1)
for i : 1 .. 80
Time.Delay (10)
put " " ..
View.Update
end for
colorback (0)
cls
Draw.Cls
exit
elsif menu = 1 then
difficulty := 85
colorback (7)
color (0)
locate (1, 1)
put "Please Wait"
colorback (0)
locate (2, 1)
for i : 1 .. 80
Time.Delay (10)
put " " ..
View.Update
end for
colorback (0)
cls
Draw.Cls
exit
elsif menu = 2 then
difficulty := 95
colorback (7)
color (0)
locate (1, 1)
put "Please Wait"
colorback (0)
locate (2, 1)
for i : 1 .. 80
Time.Delay (10)
put " " ..
View.Update
end for
colorback (0)
cls
Draw.Cls
exit
end if
elsif control (KEY_DOWN_ARROW) then
if menu not= 2 then
menu := menu + 1
end if
elsif control (KEY_UP_ARROW) then
if menu not= 0 then
menu := menu - 1
end if
end if
end loop
end if
% Game Screen
var ppad, epad : int := 10
loop
if on = 0 then % If the game has not started, determine the position of the ball.
ballx := Rand.Int (1, 2)
if ballx = 1 then
ballx := 40
else
ballx := 41
end if
loop
randint (bally, 6, 20)
exit when bally > 6 and bally < 20
end loop
end if

% Draw the Game
if ctype = 0 then
Input.KeyDown (control)
else
joystick := 0
joystick := parallelget
end if

colorback (7)
color (0)
cls
if intro = 0 then
View.Update
Time.Delay (100)
end if
colorback (7)
locate (1, 3)
put "Score: ", score ..
if intro = 0 then
View.Update
Time.Delay (100)
end if
locate (2, 3)
put "Speed: ", level ..
if intro = 0 then
View.Update
Time.Delay (100)
end if
locate (1, 18)
put "Paddle Combo: ", bouncecombo ..
if intro = 0 then
View.Update
Time.Delay (100)
end if
locate (2, 18)
put "Goal Combo: ", landcombo ..
if intro = 0 then
View.Update
Time.Delay (100)
end if
locate (1, 40)
put "Player One Goals: ", pgoals ..
if intro = 0 then
View.Update
Time.Delay (100)
end if
locate (2, 40)
put "Player Two Goals: ", egoals ..
if intro = 0 then
View.Update
Time.Delay (100)
end if
locate (1, 65)
put "Next Level: " ..
if intro = 0 then
View.Update
Time.Delay (100)
end if
locate (2, 66)
put levelup ..
if intro = 0 then
View.Update
Time.Delay (100)
end if
locate (3, 1)
colorback (0)
color (0)
put " "
if intro = 0 then
View.Update
Time.Delay (100)
end if
locate (23, 1)
put " "
if intro = 0 then
View.Update
Time.Delay (100)
end if
locate (bally, ballx)
put " " ..
for i : 0 .. 4
locate (ppad + i, 2)
if intro = 0 then
View.Update
Time.Delay (100)
end if
put " " ..
end for
for i : 0 .. 4
if intro = 0 then
View.Update
Time.Delay (100)
end if
locate (epad + i, 79)
put " " ..
end for
locate (24, 1)
color (0)
colorback (7)
if ruleset = 0 then
put " Rules In Use: Slow Game to 100 " ..
elsif ruleset = 1 then
put " Rules In Use: Mild Game to 100 " ..
elsif ruleset = 2 then
put " Rules In Use: Fast Game to 100 " ..
elsif ruleset = 3 then
put " Rules In Use: Slow Game to 10 Goals " ..
elsif ruleset = 4 then
put " Rules In Use: Mild Game to 10 Goals " ..
elsif ruleset = 5 then
put " Rules In Use: Fast Game to 10 Goals " ..
end if
if intro = 0 then
View.Update
Time.Delay (100)
end if
if on = 0 then % If the game has not started, determine the direction of the ball and start the game.
randint (dir, 1, 4)
on := 1
intro := 1
else % Move the ball
if dir = 1 then
ballx := ballx - 1
bally := bally - 1
elsif dir = 2 then
ballx := ballx + 1
bally := bally - 1
elsif dir = 3 then
ballx := ballx - 1
bally := bally + 1
elsif dir = 4 then
ballx := ballx + 1
bally := bally + 1
end if
if bally = 4 then % Change direction if the ball hits the top of the field.
if dir = 1 then
dir := 3
elsif dir = 2 then
dir := 4
end if
elsif bally = 22 then % Change direction if the ball hits the bottom of the field.
if dir = 3 then
dir := 1
elsif dir = 4 then
dir := 2
end if
elsif ballx = 3 then % If the ball is right before the Player Paddle.
if bally >= ppad and bally <= ppad + 4 then % Change direction if the ball is on the Player Paddle.
bouncecombo := bouncecombo + 1
score := score + (bouncecombo * 50)
if levelup >= 99999 then
level := level + 1
end if
if dir = 1 then
dir := 2
elsif dir = 2 then
dir := 1
elsif dir = 3 then
dir := 4
elsif dir = 4 then
dir := 3
end if
end if
elsif ballx = 78 then % If the ball is right before the Computer Paddle.
if bally >= epad and bally <= epad + 4 then % Change direction if the ball is on the Computer Paddle.
score := score + 100
if dir = 1 then
dir := 2
elsif dir = 2 then
dir := 1
elsif dir = 3 then
dir := 4
elsif dir = 4 then
dir := 3
end if
end if
elsif ballx <= 1 or ballx >= 80 then % If the ball fell off of the field, be it on either side, restart the game.
bouncecombo := 0
if ballx >= 80 then
landcombo := landcombo + 1
pgoals := pgoals + 1
else
landcombo := 0
egoals := egoals + 1
end if
score := score + (landcombo * 1000)
on := 0
end if
if mode not= 2 then
if ballx >= 40 then % If the ball is on the computer's side of the field, move the computer paddle at full speed.
randint (messup, 0, 100)
if messup > difficulty then
if dir <= 2 then % The ball is moving up, move the computer paddle up.
if epad <= 21 - 4 then
epad := epad + 1
end if
else % The ball is moving down, move the computer paddle down.
if epad >= 5 then
epad := epad - 1
end if
end if
else
if dir <= 2 then % The ball is moving up, move the computer paddle up.
if epad >= 5 then
epad := epad - 1
end if
else % The ball is moving down, move the computer paddle down.
if epad <= 21 - 4 then
epad := epad + 1
end if
end if
end if
else % If the ball is on the player's side of the field, move the computer paddle at half speed.
if skipper = 1 then
if dir <= 2 then % The ball is moving up, move the computer paddle up.
if epad >= 6 then
epad := epad - 1
end if
else % The ball is moving down, move the computer paddle down.
if epad <= 20 - 4 then
epad := epad + 1
end if
end if
skipper := 0
else
skipper := 1
end if
end if
end if

% Player Paddle Controls
if ctype = 0 then
if control (KEY_UP_ARROW) then
if ppad >= 5 then
ppad := ppad - 1
end if
elsif control (KEY_DOWN_ARROW) then
if ppad <= 21 - 4 then
ppad := ppad + 1
end if
elsif control (' ') then
boostspeed := 10
elsif control (KEY_ESC) then
endgame := 1
end if
if mode = 2 then
if control ('8') then
if epad >= 5 then
epad := epad - 1
end if
elsif control ('2') then
if epad <= 21 - 4 then
epad := epad + 1
end if
end if
end if
else
if (joystick div 64) mod 2 = 1 then
if ppad >= 5 then
ppad := ppad - 1
end if
elsif (joystick div 128) mod 2 = 1 then
if ppad <= 21 - 4 then
ppad := ppad + 1
end if
elsif control (' ') then
boostspeed := 10
elsif control (KEY_ESC) then
endgame := 1
end if
if mode = 2 then
if (joystick div 32) mod 2 = 1 then
if epad >= 5 then
epad := epad - 1
end if
elsif (joystick div 16) mod 2 = 1 then
if epad <= 21 - 4 then
epad := epad + 1
end if
end if
end if
end if

end if
% Score Controls
if score >= 99999 then
score := 99999
end if
if levelup >= 99999 then
levelup := 99999
end if
if level = 0 then
level := 1
levelup := 1000
end if
if score >= levelup then
level := level + 1
levelup := levelup + 1000
end if
if bouncecombo >= 99 then
bouncecombo := 99
end if

if landcombo >= 99 then
landcombo := 99
end if
if pgoals >= 999 then
pgoals := 999
end if
if egoals >= 999 then
egoals := 999
end if
if ruleset >= 3 then
if pgoals >= 10 or egoals >= 10 then
endgame := 1
end if
end if
if level >= 100 then
level := 100
if ruleset <= 2 then
endgame := 1
end if
end if
% Update the buffering
View.Update
timeplayed := timeplayed + 0.01
boostspeed := boostspeed + level
if control (KEY_LEFT_ARROW) and control (KEY_RIGHT_ARROW) then
boostspeed := boostspeed - boostspeed + 50
end if
if boostspeed >= 100 then
boostspeed := 100
end if
Time.Delay (100 - boostspeed)
boostspeed := 0
%End the Game
if endgame = 1 then
colorback (0)
for i : 1 .. 25
locate (i, 1)
for a : 1 .. 80
put " " ..
View.Update
Time.Delay (0)
end for
end for
cls
color (7)
Draw.Cls
Font.Draw ("Results", 90, 220, titlefont, black)
locate (14, 1)
View.Update
Time.Delay (50)
if ruleset = 0 then
put " Rules In Use: Slow Game to 100 " ..
elsif ruleset = 1 then
put " Rules In Use: Mild Game to 100 " ..
elsif ruleset = 2 then
put " Rules In Use: Fast Game to 100 " ..
elsif ruleset = 3 then
put " Rules In Use: Slow Game to 10 Goals " ..
elsif ruleset = 4 then
put " Rules In Use: Mild Game to 10 Goals " ..
elsif ruleset = 5 then
put " Rules In Use: Fast Game to 10 Goals " ..
end if
View.Update
Time.Delay (50)
put ""
put " Player One Goals: " ..
View.Update
Time.Delay (50)
put pgoals
View.Update
Time.Delay (50)
put ""
put " Player Two Goals: " ..
View.Update
Time.Delay (50)
put egoals
View.Update
Time.Delay (50)
put ""
put " Time Played: " ..
View.Update
Time.Delay (50)
put timeplayed, " game sec."
View.Update
Time.Delay (50)
put ""
put ""
put " Winner: " ..
View.Update
Time.Delay (50)
if pgoals = egoals then
put "Draw"
elsif pgoals > egoals then
put "Player One"
else
put "Player Two " ..
if mode = 1 then
put "(Computer)"
end if
end if
View.Update
Time.Delay (100)
locate (24, 1)
put " Press Space to return to the title screen." ..
View.Update
color (0)
loop
Input.KeyDown (control)
if control (' ') then
exit
end if
end loop
colorback (0)
color (7)
locate (1, 1)
put "Please Wait"
colorback (7)
locate (2, 1)
for i : 1 .. 80
Time.Delay (10)
put " " ..
View.Update
end for
exit
end if
end loop
if endgame = 1 then
exit
end if
end loop
end loop



Seriously... Who uses Parallel Ports anymore?


: