rizonejoylib
This library has two parts. The first tests points against zones:
rectangles and circles on the screen, numbered from 0, for example the
buttons of a game’s control panel. SetZone defines a zone, Zone(x,y)
returns the first zone that contains a point, and ZoneTest tests one
zone or a range.
Zones are kept in zone tables. Table 0 holds 256 zones and is created
when the program starts; NewZoneTable creates the tables 1 to 15 with
up to 65535 zones each, UseZoneTable chooses the table the zone
commands work on, and FreeZoneTable frees one. All tables are freed
when the program ends.
On a 68020 or later processor the zones are tested with a faster
method, which SetZoneMode can switch off. Both methods give the same
results for the zones SetZone makes. Zone and ZoneTest are
faster than the original’s.
The second part reads the joysticks directly from the hardware: port 1
is the joystick port, port 2 the mouse port, and ports 3 and 4 the two
ports of a four player adaptor on the parallel port. ReadJoyPad reads
the extra buttons of a CD32 pad.
SetZone 0,10,10,100,50
SetZone 1,200,100,40
NPrint Zone(50,20) ; 0
NPrint Zone(210,110) ; 1
NPrint Zone(5,5) ; -1Based on the RI ZoneJoy Lib guide by Reflective Images.
Library number 64.
Commands
AllFire
The first fire buttons of the four ports as bits - bit 0 port 1, bit 1 port 2, bit 2 port 3, bit 3 port 4. A bit is set while the button is pressed.
Function, result .b. Help text: ([joybits])
2 forms:
- no arguments
.b
With joybits, only the ports whose bits are set are tested; for
example AllFire(%0011) tests ports 1 and 2.
FreeZoneTable
Frees zone table table# (1 to 15) and makes table 0 the current one. Returns -1 if it worked, else 0.
Function, result .b. Help text: table#
Arguments: .l
Table 0 becomes the current one also when another table than the
freed one was current, as the guide says; choose that table again
with UseZoneTable.
GetZoneX1
The x1 value of a zone of the current table - the left edge of a rectangle, the centre of a circle, -1 for a cleared zone.
Function, result .w. Help text: (zone) - returns the start x pos of a zone
Arguments: .w
For a zone beyond the table, or without a zone table, the result is -1.
GetZoneX2
The x2 value of a zone of the current table - the right edge of a rectangle, the radius squared of a circle, -1 for a cleared zone.
Function, result .w. Help text: (zone) - returns the end x pos of a zone
Arguments: .w
For a zone beyond the table, or without a zone table, the result is -1.
GetZoneY1
The y1 value of a zone of the current table - the top edge of a rectangle, the centre of a circle, -1 for a cleared zone.
Function, result .w. Help text: (zone) - returns the start y pos of a zone
Arguments: .w
For a zone beyond the table, or without a zone table, the result is -1.
GetZoneY2
The y2 value of a zone of the current table - the bottom edge of a rectangle, -1 for a circle or a cleared zone.
Function, result .w. Help text: (zone) - returns the end pos of a zone
Arguments: .w
For a zone beyond the table, or without a zone table, the result is -1.
JAdaptorStatus
Switches the reading of ports 3 and 4 of the four player adaptor on (-1) or off (0); while it is off, they read as nothing pressed. As a function it returns the previous setting. It is on at the start.
Statement or function, result .b. Help text: On/Off - status of four player adaptor reading
Arguments: .b
JFire
The fire buttons of a joystick port - 0 none, 1 the first button, 2 the second, 3 both. Ports 3 and 4 of the four player adaptor have one button.
Function, result .b. Help text: (port)
Arguments: .b
JHoriz
The horizontal direction of a joystick port - -1 left, 1 right, 0 none.
Function, result .b. Help text: (port)
Arguments: .b
JVert
The vertical direction of a joystick port - -1 up, 1 down, 0 none.
Function, result .b. Help text: (port)
Arguments: .b
NewZoneTable
Creates zone table table# (1 to 15) with num_zones zones (1 to 65535), all cleared, freeing a table of that number first. Returns -1 if it worked, else 0; the new table does not become the current one.
Function, result .b. Help text: table#,num_zones
Arguments: .l, .l
A table that replaces the current one stays the current table. If there is not enough memory for a table that replaces another, the table of that number no longer exists, and if it was the current table, table 0 becomes the current one.
The guide gives 65536 zones as the largest size; the library takes at most 65535.
ReadJoyPad
The extra buttons of a CD32 pad in port 1 or 2, as bits - 2 play/pause, 4 reverse, 8 forward, 16 green, 32 yellow, 64 red, 128 blue.
Function, result .w. Help text: port# --B,R,Y,G,FF,RW,PL,0
Arguments: .w
Every port number other than 2 reads port 1, the joystick port. The
guide names 1 and 2, but its own example reads the pad with
ReadJoyPad(0).
SetZone
Defines a zone of the current table - a rectangle with the corners x1,y1 and x2,y2, or a circle around x,y with radius. As a function it returns -1 if the zone was set and 0 if it was refused.
Statement or function, result .b. Help text: num,x1,y1[,x2,y2]|[,radius]
2 forms:
.l, .l, .l, .l.l, .l, .l, .l, .l
The corners of a rectangle may be given in any order; the guide’s “x2,y2 should be the bottom left” means the bottom right corner. The edges belong to the zone.
The zone is refused, and nothing is stored, in these cases:
- a zone number beyond the table or below 0
- a radius outside 0 to 255
- a rectangle whose bottom edge is -1, which marks a circle in the table
- no zone table at all
SetZoneMode
Chooses the zone test method - -1 for the 68020 method, 0 for the 68000 method. On a 68000 or 68010 the command does nothing.
Statement. Help text: mode
Arguments: .l
UseZoneTable
Makes zone table table# the current one, for all zone commands. Returns -1 if it worked and 0 if there is no such table.
Statement or function, result .b. Help text: - select a zone table for use
Arguments: .l
Zone
The number of the first zone of the current table that contains the point x,y, or -1 if there is none.
Function, result .w. Help text: (x,y)
Arguments: .w, .w
The 68000 and the 68020 mode give the same result for every zone
that SetZone makes.
Kept from the original: the distance of a point from the centre of a circle is computed in 16 bits, so a point more than 32767 pixels away from it can be found inside the circle (#1153).
ZoneInit
Clears all zones of the current zone table, or one zone, or the zones from start_num to end_num. A cleared zone contains no point.
Statement. Help text: [zone_num#]|[#start_num,#end_num] - intialize zones
3 forms:
- no arguments
.l.l, .l
ZoneMode
Returns -1 when zones are tested with the 68020 method and 0 when with the 68000 method. The 68020 method is the default on a 68020 or later processor.
Function, result .b. Help text: - returns -1 for 68020 mode or 0 for 68000 mode
No arguments.
ZoneTable
The address of the current zone table, or 0 if there is none. The table starts with the number of zones as a long; then each zone takes 8 bytes, the words x1, x2, y1 and y2.
Function, result .l. Help text: - returns address of the current zone table
No arguments.
A circle keeps its centre in x1 and y1, the radius squared in x2 and -1 in y2; a cleared zone has -1 in x1. Table 0, with its 256 zones, takes 2052 bytes.
The guide differs: it gives the order x1, y1, x2, y2 with the radius of a circle at +4, and 16 bytes for each zone.
ZoneTableNumber
The number of the current zone table.
Function, result .b. Help text: - returns the number of the current zone table
No arguments.
ZoneTableSize
The number of zones of the current zone table, or 0 if there is none.
Function, result .l. Help text: - returns size of the current zone table
No arguments.
ZoneTest
Like Zone, testing only the zone start_num, or the zones from start_num to end_num. Returns the number of the first zone that contains x,y, or -1.
Function, result .l. Help text: (start_num[,end_num],x,y)
2 forms:
.l, .w, .w.l, .l, .w, .w
In the form with a range, a start_num beyond the table, or below
0, counts as the last zone, and an end_num beyond the table or
below 0 gives -1. A single zone beyond the table gives -1.