Joystick position: Difference between revisions
m
syntax highlighting fixup automation
(Added Wren) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 22:
=={{header|Action!}}==
<
BYTE lastTrig=[255]
Line 89:
OD
CH=$FF
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Joystick_position.png Screenshot from Atari 8-bit computer]
=={{header|Applesoft BASIC}}==
<
110 P2 = PDL(2) : IF P2 <> O2 THEN O2 = P2 : VTAB 23 : HTAB 33 : PRINT P2; TAB(37);
120 B2 = FNB(2) : IF B2 <> N2 THEN N2 = B2 : VTAB 24 : HTAB 15 : PRINT P$(B2);
Line 131:
550 ROT = 0 : SCALE = 7 : XDRAW 1 AT X1, Y1
560 O0 = -1 : O1 = O0 : O2 = O0 : O3 = O0
570 RETURN</
=={{header|AutoHotkey}}==
Line 139:
[http://i.imgur.com/KsbrpK4.png Image link]
<
; #Include, Gdip.ahk
Line 357:
Exit:
Gdip_Shutdown(pToken)
ExitApp</
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<
VDU 5
Line 383:
VDU 10,13
NEXT
ENDPROC</
=={{header|C}}==
<
#include <stdlib.h>
Line 442:
system("clear");
return 1;
}</
{{out}}
Line 457:
This program maps the values from both registers to bits 0 through 4 of a single byte so that logic is evaluated identical to the C-64 example below.
<
6 rem for rosetta code
10 print chr$(147);:poke 37154,peek(37154) and 127
Line 480:
80 if (ox=x) and (oy=y) then goto 100
85 poke sc+ox+oy*22,32
100 goto 25</
===Commodore 64===
Line 486:
On the Commodore 64, both joystick ports can be read from registers on the CIA#1 6526 chip. This will report binary input from the joystick control ports in bits 0 through 4 (four directions plus a single fire or action button.) Control Port 1 is read from location 56321 and Control Port 2 is read from location 56320.
<
6 rem for rosetta code
8 rem black bkg, white text, dk. grey border
Line 509:
85 poke sc+x+y*40,c:if (ox=x) and (oy=y) then goto 100
90 poke sc+ox+oy*40,32
100 goto 20</
===Commodore Plus/4===
Line 515:
The Commodore Plus/4 has the JOY(''n'') function available in BASIC v3.5 to read the position of a joystick plugged into control port ''n''. The return value is a number 1 through 8 corresponding to each unique direction in a clockwise order, beginning with "up" returning a value of "1". Bit 7 of the return value will report the status of the fire button.
<
6 rem for rosetta code
8 rem black bkg, white text, dk. grey border
Line 541:
85 poke sc+x+y*40,c:if (ox=x) and (oy=y) then goto 100
90 poke sc+ox+oy*40,32
100 goto 20</
===Commodore 128===
Line 547:
BASIC 7.0 retains the same functionality of BASIC 3.5 on the Plus/4 for reading the joystick port(s). The C128 can take advantage of dual screen output.
<
6 rem for rosetta code
8 rem black bkg, white text, dk. grey border
Line 573:
85 poke sc+x+y*40,c:if (ox=x) and (oy=y)then goto 100
90 poke sc+ox+oy*40,32
100 goto 20</
=={{header|Delphi}}==
{{libheader|mmSystem}}
Form application version.
<syntaxhighlight lang="delphi">
unit uMain;
Line 650:
end.
</syntaxhighlight>
Form resource:
<syntaxhighlight lang="delphi">
object Form1: TForm1
Left = 0
Line 689:
end
end
</syntaxhighlight>
{{out}}
Result preview [https://ibb.co/tc0xH3q]
Line 695:
=={{header|FreeBASIC}}==
<
Dim As Single x, y
Line 724:
End If
Next a
Loop</
Line 730:
{{libheader|termbox-go}}
{{libheader|joystick(go)}}
<
import (
Line 832:
}
}
}</
=={{header|GUISS}}==
Graphical User Interface Support Script only makes use of installed applications. So for this task, we use the joystick calibration routine, which shows a joystick position indicator:
<
Button:Properties,Button:Test</
=={{header|Haskell}}==
Half-solution of the problem, exhibits X and Y coordinates of the joystick; works on Windows (Haskell Platform):
<
import Graphics.Win32.Key
import Control.Monad.RWS.Strict (liftIO)
Line 865:
(Just (x:y:_)) -> (-y, x)
_ -> ( 0, 0)
</syntaxhighlight>
=={{header|IS-BASIC}}==
<
110 DO
120 LET J=JOY(0) OR JOY(1) OR JOY(2)
Line 877:
170 IF J BAND 8 THEN PRINT "up ";
180 IF J BAND 16 THEN PRINT "fire ";
190 LOOP</
=={{header|Julia}}==
<
#------------ input code ----------------------#
Line 956:
yield()
end
</syntaxhighlight>
=={{header|Liberty BASIC}}==
<
nomainwin
Line 1,030:
close #m
unloadbmp "plus"
end</
=={{header|Locomotive Basic}}==
<
20 a=JOY(0) ' read state of first joystick
30 IF d THEN q$="*" ELSE q$=" "
Line 1,045:
110 IF a<16 THEN LOCATE 1,1:PRINT " ":PRINT " "
120 MOVE x-8,y+8:TAG:PRINT "X";:TAGOFF
130 GOTO 20</
Output (this version supports drawing with the cursor):
Line 1,052:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
=={{header|OCaml}}==
Line 1,059:
{{libheader|ocaml-sfml}}
<
let buttons_string b =
String.concat " " (List.map string_of_int b)
Line 1,112:
proc_event joyd
in
loop ((0.0, 0.0), [])</
Run with the command:
Line 1,121:
First, joy.e:
<!--<
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span>
<span style="color: #000080;font-style:italic;">-- Joystick library for Euphoria (Windows)
Line 1,184:
<span style="color: #008080;">return</span> <span style="color: #0000FF;">{}</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<!--</
And a test program:
<!--<
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">joy</span><span style="color: #0000FF;">.</span><span style="color: #000000;">ew</span>
Line 1,222:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</
=={{header|PicoLisp}}==
Line 1,228:
{{libheader|GLUT}}
Note: The code is not yet tested with a real joystick (I don't have one), it was just simulated with dummy functions. Can somebody having a joystick please test it, and remove this message?
<
(setq *JoyX 0.0 *JoyY 0.0)
Line 1,267:
# Exit upon mouse click
(mouseFunc '((Btn State X Y) (bye)))
(glutMainLoop)</
=={{header|PureBasic}}==
This is limited to only digital joysticks.
<
MessageRequester("Error!", "Need to connect a joystick", #PB_MessageRequester_Ok)
End
Line 1,342:
Delay(10)
Until event = #PB_Event_CloseWindow
EndIf</
[[File:JoystickPosition-PureBasic.png]]
=={{header|Python}}==
{{libheader|Pygame}}
<
import pygame
Line 1,419:
# Write the display
pygame.display.flip()
clk.tick(40) # Limit to <=40 FPS</
=={{header|Raku}}==
Line 1,426:
Linux only terminal based joystick testing utility. Reads events from the joystick asynchronously, allows a main processing loop if desired. This uses the main loop to check for and compensate for a resized terminal but not really anything else. Hit control-c to exit; needs one extra event from the the joystick to exit completely. Only shows the first 3 axes, no matter how many are available. Tested with an Logitech extreme joystick and an Xbox controller.
<syntaxhighlight lang="raku"
# Joysticks generally show up in the /dev/input/ directory as js(n) where n is
Line 1,530:
($rows, $cols) = qx/stty size/.words;
}
</syntaxhighlight>
=={{header|Tcl}}==
{{libheader|Tk}}
{{libheader|mkLibsdl}} <!-- from http://mkextensions.sourceforge.net/ -->
<
package require mkLibsdl
Line 1,577:
.c create line {120 115 120 125} -tags xhairV
.c create line {115 120 125 120} -tags xhairH
joystick event eval {display [joystick event peek]}</
<!-- I think it can also be done with Tcl3d as that has SDL Joystick bindings, but damned if I can figure out the API in a reasonable amount of effort. It's definitely not Tclish (but what would you expect with something mashed together with SWIG? Once a stinky C API, always a stinky C API…) -->
Line 1,585:
We also allow movement of the cross-hair using the keyboard direction keys for those who don't have a suitable device.
<
import "graphics" for Canvas, Color
import "dome" for Window
Line 1,659:
}
var Game = Main.new(600, 600)</
=={{header|ZX Spectrum Basic}}==
Assuming a Kempston joystick interface, fairly standard at the time. Rewriting for the Sinclair Interface 2 involves changing line 80 to 80 LET t=IN 61438, replacing all numbers in the next five lines with 191-said number and reversing each pair of directions.
<
20 LET xm=0: LET xx=31: REM screen limits
30 LET ym=0: LET yx=18
Line 1,680:
150 PRINT AT yc,xc;"+"
160 LET o$=" ": REM five spaces to blank output line again
170 GO TO 60</
{{Out}}
|