1. Michael Packard game 101
- Posted by Jacques Deschjnes <desja at QUEBECTEL.COM>
Sep 14, 1996
-
Last edited Sep 15, 1996
Hi Mr. Packard,
I like your project, I already studied the code from your home page.
Packman sprite are moving suprisingly smooth for an interpreted langage.
Please stick to the packman game, (no space invader).
I include in this message an joytsk.e file I wrote. It could be usefull
for the packman game.
Jacques Deschenes
*********** JOYSTIK.E begin here ****************
-- Include file to read the joysticks
-- by: Jacques Desch=88nes, Baie-Comeau, P.Q., Canada.
-- email: Desja at QUEBECTEL.COM
-- note: joystick is accessible by bios interrupt 15H service 84H
--
-- function registers
-- input output
-- ---------------------------------------------------------
-- reading buttons AX=3D#8400
-- DX=3D#0000 AL=3D button state
--
-- reading stick AX=3D#8400
-- DX=3D#0001 AX=3D j1(x)
-- BX=3D j1(y)
-- CX=3D j2(x)
-- DX=3D j2(y)
--
--
include machine.e
sequence reg_list -- list of register values
reg_list =3D repeat(0, 10)
constant READ_POS=3D#0001, READ_BUTTONS=3D#0000
constant INT_15=3D#15, JOYSTICK=3D#8400
-- *********************
-- * globals functions *
-- *********************
global function get_stick_pos(integer JoyNo)
-- return the position of the specified joystick
-- position is {x,y}
sequence position
position =3D repeat(0,2)
reg_list[REG_AX] =3D JOYSTICK
reg_list[REG_DX] =3D READ_POS
reg_list =3D dos_interrupt(INT_15,reg_list) -- read joystick
if JoyNo =3D 1 then
position[1] =3D reg_list[REG_AX]
position[2] =3D reg_list[REG_BX]
else
position[1] =3D reg_list[REG_CX]
position[2] =3D reg_list[REG_DX]
end if
return position
end function -- get_stick_pos
global function get_buttons(integer JoyNo)
-- return the state of the buttons of the specified joystick
-- buttons are {b1,b2} 0 pressed, 1 released
sequence buttons
atom ButtonsState
buttons =3D repeat(0,2)
reg_list[REG_AX] =3D JOYSTICK
reg_list[REG_DX] =3D READ_BUTTONS
reg_list =3D dos_interrupt(INT_15,reg_list) -- read joystick
ButtonsState=3Dfloor(reg_list[REG_AX]/16)
if JoyNo !=3D 1 then
ButtonsState=3Dfloor(ButtonsState/4)
end if
buttons[1] =3D remainder(ButtonsState,2)
ButtonsState=3Dfloor(ButtonsState/2)
buttons[2] =3D remainder(ButtonsState,2)=20
return buttons
end function -- get_buttons
global function WaitButtons(integer JoyNo)
-- wait until a joystick button is pressed, x specify which joystick
sequence b
b =3D {1,1}
while b[1] and b[2] do
b =3D get_buttons(JoyNo)
end while=20
return b
end function -- WaitButtons()
global procedure WaitButtonsRelease(integer JoyNo)
sequence b
b =3D get_buttons(JoyNo)
while b[1] =3D 0 or b[2] =3D 0 do
b =3D get_buttons(JoyNo)
end while
end procedure -- WaitButtonsRelease()
global sequence HiX, LoX, HiY, LoY
HiX =3D repeat(0,2) LoX =3D repeat(0,2) HiY=3Drepeat(0,2) LoY=3Drepeat(0=
,2)
global procedure CalJoyStk(integer JoyNo)
-- Calibrate the joystick=20
sequence b, pos integer cx, cy
printf(1,"******** Joystick calibration procedure.
*********\n\n",{})
printf(1,"Calibration of joystick %1d\n\n",{JoyNo})
printf(1,"CENTER joystick and push a button.\n",{})
b =3D WaitButtons(JoyNo)
WaitButtonsRelease(JoyNo)
pos =3D get_stick_pos(JoyNo)
cx =3D pos[1] cy =3D pos[2]
printf(1,"Center x is %d\nCenter y is %d\n",{cx,cy})
printf(1,"Push joystick UP and LEFT and push a button.\n",{})
b =3D WaitButtons(JoyNo)
WaitButtonsRelease(JoyNo)
pos =3D get_stick_pos(JoyNo)
HiX[JoyNo] =3D floor((cx+pos[1])/2) HiY[JoyNo] =3D floor((cy+pos[2])/2=
)
printf(1,"High threshold x is %d\nHigh threshold y is %d\n",
{HiX[JoyNo],HiY[JoyNo]})
printf(1,"Push joystick DOWN and RIGHT and push a button.\n",{})
b =3D WaitButtons(JoyNo)
WaitButtonsRelease(JoyNo)
pos =3D get_stick_pos(JoyNo)
LoX[JoyNo] =3D floor((cx+pos[1])/2) LoY[JoyNo] =3D floor((cy+pos[2])/2=
)
printf(1,"Low threshold x is %d\nLow threshold y is %d\n",
{LoX[JoyNo],LoY[JoyNo]})
printf(1,"Push a button to continu.",{})
b =3D WaitButtons(JoyNo)
end procedure -- CalJoyStk()