Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "Resources"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
Line 16: Line 16:
   
 
[[Potgo Resource]]
 
[[Potgo Resource]]
 
 
 
== FileSystem Resource ==
 
 
The FileSystem resource returns the filesystems that are available on the Amiga. It has no functions. Opening the FileSystem resource returns a pointer to a List structure containing the current filesystems in the Amiga.
 
 
Additional programming information on the FileSystem resource can be found in the include files and the Autodocs for the FileSystem resource in the ''Amiga ROM Kernel Reference Manual: Includes and Autodocs'' and the “Expansion” chapter of the ''Amiga ROM Kernel Reference Manual: Libraries''.
 
 
|ll|
 
 
2c'''FileSystem Resource Information'''<br />
 
Includes &amp; resources/filesysres.h<br />
 
&amp; resources/filesysres.i<br />
 
AutoDocs &amp; filesysres.doc<br />
 
Libraries &amp; expansion.library<br />
 
 
 
== Misc Resource ==
 
 
The misc resource oversees usage of the serial data port, the serial communication bits, the parallel data and handshake port, and the parallel communication bits. Before using serial or parallel port hardware, it first must be acquired from the misc resource.
 
 
The misc resource provides two functions for allocating and freeing the serial and parallel hardware.
 
 
ll
 
 
2c'''Misc Resource Functions'''<br />
 
AllocMiscResource() &amp; 7.8cmAllocate one of the serial or parallel misc resources.<br />
 
FreeMiscResource() &amp; 7.8cmDeallocate one of the serial or parallel misc resources.<br />
 
 
 
Once you’ve successfully allocated one of the misc resources, you are free to write directly to its hardware locations. Information on the serial and parallel hardware can be found in the ''Amiga Hardware Reference Manual'' and the hardware/custom.h include file.
 
 
The two examples below are assembly and ’C’ versions of the same code for locking the serial misc resources and waiting for CTRL-C to be pressed before releasing them.
 
 
=== Assembly Example of Allocating Misc Resources ===
 
 
<pre>* Alloc_Misc.a
 
*
 
* Assembly language fragment that grabs the two parts of the serial
 
* resource (using misc.resource). If it gets the resource, it will
 
* wait for CTRL-C to be pressed before releasing.
 
*
 
* While we are waiting, the query_serial program should be run. It will try
 
* to open the serial device and if unsuccessful, will return the name of the
 
* owner. It will be us, Serial Port Hog!
 
*
 
* When a task has successfully obtained the serial resource, it &quot;owns&quot;
 
* the hardware registers that control the serial port. No other tasks
 
* are allowed to interfere.
 
*
 
* Assemble with Adapt
 
* HX68 Allocate_Misc.a to Allocate_Misc.o
 
*
 
* Link
 
* Blink FROM Allocate_Misc.o TO Allocate_Misc LIB LIB:amiga.lib
 
*
 
 
INCDIR &quot;include:&quot;
 
INCLUDE &quot;exec/types.i&quot;
 
INCLUDE &quot;resources/misc.i&quot;
 
INCLUDE &quot;dos/dos.i&quot;
 
 
xref _AbsExecBase ; We get this from outside...
 
xref _LVOOpenResource ; We get this from outside...
 
xref _LVOWait ; We get this from outside...
 
 
;
 
; Open Exec and the misc.resource, check for success
 
;
 
move.l _AbsExecBase,a6 ;Prepare to use exec
 
lea.l MiscName(pc),a1
 
jsr _LVOOpenResource(a6) ;Open &quot;misc.resource&quot;
 
move.l d0,d7 ;Stash resource base
 
bne.s resource_ok
 
moveq #RETURN_FAIL,d0
 
rts
 
 
resource_ok exg.l d7,a6 ;Put resource base in A6
 
 
;
 
; We now have a pointer to a resource.
 
; Call one of the resource's library-like vectors.
 
;
 
move.l #MR_SERIALBITS,d0 ;We want these bits
 
lea.l MyName(pc),a1 ;This is our name
 
jsr MR_ALLOCMISCRESOURCE(a6)
 
tst.l d0
 
bne.s no_bits ;Someone else has it...
 
move.l #MR_SERIALPORT,d0
 
lea.l MyName(pc),a1
 
jsr MR_ALLOCMISCRESOURCE(a6)
 
tst.l d0
 
bne.s no_port ;Someone else has it...
 
;
 
; We just stole the serial port registers; wait.
 
; Nobody else can use the serial port, including the serial.device!
 
;
 
exg.l d7,a6 ;use exec again
 
move.l #SIGBREAKF_CTRL_C,d0
 
jsr _LVOWait(a6) ;Wait for CTRL-C
 
exg.l d7,a6 ;Get resource base back
 
;
 
; Free 'em up
 
;
 
move.l #MR_SERIALPORT,d0
 
jsr MR_FREEMISCRESOURCE(a6)
 
no_port
 
move.l #MR_SERIALBITS,d0
 
jsr MR_FREEMISCRESOURCE(a6)
 
no_bits
 
moveq #RETURN_FAIL,d0
 
rts
 
;
 
; Text area
 
;
 
MiscName dc.b 'misc.resource',0
 
MyName dc.b 'Serial Port Hog',0
 
dc.w 0
 
END</pre>
 
=== ’C’ Example of Allocating Misc Resources ===
 
 
<pre>/*
 
* Allocate_Misc.c
 
*
 
* Example of allocating a miscellaneous resource
 
* We will allocate the serial resource and wait till
 
* CTRL-C is pressed. While we are waiting, the
 
* query_serial program should be run. It will try
 
* to open the serial device and if unsuccessful, will
 
* return the name of the owner. It will be us!
 
*
 
* Compile with SAS C 5.10 lc -b1 -cfistq -v -y -L
 
*
 
* Run from CLI only
 
*/
 
 
#include &lt;exec/types.h&gt;
 
#include &lt;exec/memory.h&gt;
 
#include &lt;dos/dos.h&gt;
 
#include &lt;resources/misc.h&gt;
 
 
#include &lt;clib/exec_protos.h&gt;
 
#include &lt;clib/misc_protos.h&gt;
 
 
#include &lt;stdio.h&gt;
 
 
#ifdef LATTICE
 
int CXBRK(void) { return(0); } /* Disable SAS CTRL/C handling */
 
int chkabort(void) { return(0); } /* really */
 
#endif
 
 
struct Library *MiscBase = NULL;
 
 
void main(int argc, char **argv)
 
{
 
UBYTE *owner = NULL; /* owner of misc resource */
 
 
if (!(MiscBase= (struct Library *)OpenResource(MISCNAME)))
 
printf(&quot;Cannot open %s\n&quot;,MISCNAME);
 
else
 
{
 
/* Allocate both pieces of the serial hardware */
 
if ((owner = AllocMiscResource(MR_SERIALPORT,&quot;Serial Port Hog&quot;)) == NULL)
 
{
 
if ((owner = AllocMiscResource(MR_SERIALBITS,&quot;Serial Port Hog&quot;)) == NULL)
 
{
 
/* Wait for CTRL-C to be pressed */
 
printf(&quot;\nWaiting for CTRL-C...\n&quot;);
 
Wait(SIGBREAKF_CTRL_C);
 
 
/* We're back */
 
 
/* Deallocate the serial port register */
 
FreeMiscResource(MR_SERIALBITS);
 
}
 
else
 
printf(&quot;\nUnable to allocate MR_SERIALBITS because %s owns it\n&quot;,owner);
 
 
/* Deallocate the serial port */
 
FreeMiscResource(MR_SERIALPORT);
 
}
 
else
 
printf(&quot;\nUnable to allocate MR_SERIALPORT because %s owns it\n&quot;,owner);
 
}
 
}</pre>
 
The example below will try to open the serial device and execute the SDCMD_QUERY command. If it cannot open the serial device, it will do an AllocMiscResource() on the serial port and return the name of the owner.
 
 
<sub>b</sub>oxTake Over Everything.There are two serial.device resources to take over, MR_SERIALBITS and MR_SERIALPORT. You should get both resources when you take over the serial port to prevent other tasks from using them. The parallel.device also has two resources to take over. See the resources/misc.h include file for the relevant definitions and structures.
 
 
Under V1.3 and earlier versions of the Amiga system software the MR_GETMISCRESOURCE routine will always fail if the serial device has been used at all by another task (even if that task has finished using the resource. In other words, once a printer driver or communication package has been activated, it will keep the associated resource locked up preventing your task from using it. Under these conditions, you must get the resource back from the system yourself.
 
 
You do this by calling the function FlushDevice():
 
 
<pre>/*
 
* A safe way to expunge ONLY a certain device. The serial.device holds
 
* on to the misc serial resource until a general expunge occurs.
 
* This code attempts to flush ONLY the named device out of memory and
 
* nothing else. If it fails, no status is returned since it would have
 
* no valid use after the Permit().
 
*/
 
 
#include &lt;exec/types.h&gt;
 
#include &lt;exec/execbase.h&gt;
 
 
#include &lt;clib/exec_protos.h&gt;
 
 
void FlushDevice(char *);
 
 
extern struct ExecBase *SysBase;
 
 
void FlushDevice(char *name)
 
{
 
struct Device *devpoint;
 
 
Forbid();
 
 
if (devpoint=(struct Device *)FindName(&amp;SysBase-&gt;DeviceList,name) )
 
RemDevice(devpoint);
 
 
Permit();
 
}</pre>
 
Additional programming information on the misc resource can be found in the include files and the Autodocs for the misc resource.
 
 
|ll|
 
 
2c'''Misc Resource Information'''<br />
 
Includes &amp; resources/misc.h<br />
 
&amp; resources/misc.i<br />
 
AutoDocs &amp; misc.doc<br />
 
 
 
== Potgo Resource ==
 
 
 
 
The potgo resource is used to get control of the hardware POTGO register connected to the proportional I/O pins on the game controller ports. There are two registers, POTGO (write-only) and POTINP (read-only). These pins could also be used for digital I/O.
 
 
The potgo resource provides three functions for working with the POTGO hardware.
 
 
ll
 
 
2c'''Potgo Resource Functions'''<br />
 
AllocPotBits() &amp; 8.7cmAllocate bits in the POTGO register.<br />
 
FreePotBits() &amp; 8.7cmFree previously allocated bits in the POTGO register.<br />
 
WritePotgo() &amp; 8.7cmSet and clear bits in the POTGO register. The bits must have been allocated before calling this function.<br />
 
 
 
The example program shown below demonstrates how to use the ptogo resource to track mouse button presses on port 1.
 
 
<pre>/*
 
* Read_Potinp.c
 
*
 
* An example of using the potgo.resource to read pins 9 and 5 of
 
* port 1 (the non-mouse port). This bypasses the gameport.device.
 
* When the right or middle button on a mouse plugged into port 1 is pressed,
 
* the read value will change.
 
*
 
* Use of port 0 (mouse) is unaffected.
 
*
 
* Compile with SAS C 5.10 lc -b1 -cfistq -v -y -L
 
*
 
* Run from CLI only
 
*/
 
 
#include &lt;exec/types.h&gt;
 
#include &lt;exec/memory.h&gt;
 
#include &lt;dos/dos.h&gt;
 
#include &lt;resources/potgo.h&gt;
 
#include &lt;hardware/custom.h&gt;
 
 
#include &lt;clib/exec_protos.h&gt;
 
#include &lt;clib/potgo_protos.h&gt;
 
 
#include &lt;stdio.h&gt;
 
 
#ifdef LATTICE
 
int CXBRK(void) {return(0);} /* Disable SAS Ctrl-C checking */
 
int chkabort(void) { return(0); } /* really */
 
#endif
 
 
struct PotgoBase *PotgoBase;
 
ULONG potbits;
 
UWORD value;
 
 
#define UNLESS(x) if(!(x))
 
#define UNTIL(x) while(!(x))
 
 
#define OUTRY 1L&lt;&lt;15
 
#define DATRY 1L&lt;&lt;14
 
#define OUTRX 1L&lt;&lt;13
 
#define DATRX 1L&lt;&lt;12
 
 
extern struct Custom far custom;
 
 
void main(int argc,char **argv)
 
{
 
UNLESS (PotgoBase=(struct PotgoBase *)OpenResource(&quot;potgo.resource&quot;))
 
return;
 
 
potbits=AllocPotBits(OUTRY|DATRY|OUTRX|DATRX);
 
 
/* Get the bits for the right and middle mouse buttons on the alternate mouse port. */
 
 
if (potbits != (OUTRY|DATRY|OUTRX|DATRX))
 
{
 
printf(&quot;Pot bits are already allocated! %lx\n&quot;,potbits);
 
FreePotBits(potbits);
 
return;
 
}
 
 
/* Set all ones in the register (masked by potbits) */
 
WritePotgo(0xFFFFFFFFL,potbits);
 
 
printf(&quot;\nPlug a mouse into the second port. This program will indicate when\n&quot;);
 
printf(&quot;the right or middle button (if the mouse is so equipped) is pressed.\n&quot;);
 
printf(&quot;Stop the program with Control-C. Press return now to begin.\n&quot;);
 
 
getchar();
 
 
UNTIL (SIGBREAKF_CTRL_C &amp; SetSignal(0L,0L))
 
/* until CTRL-C is pressed */
 
{
 
/* Read word at $DFF016 */
 
value = custom.potinp;
 
 
/* Show what was read (restricted to our allocated bits) */
 
printf(&quot;POTINP = $%lx\n&quot;,value &amp; potbits);
 
}
 
 
FreePotBits(potbits);
 
}</pre>
 
Additional programming information on the potgo resource can be found in the include files and the Autodocs for the potgo resource.
 
 
|ll|
 
 
2c'''Potgo Resource Information'''<br />
 
Includes &amp; resources/potgo.h<br />
 
&amp; resources/potgo.i<br />
 
&amp; utility/hooks.h<br />
 
&amp; utility/hooks.i<br />
 
AutoDocs &amp; potgo.doc<br />
 

Revision as of 23:30, 16 April 2012

Warning.png This page is not yet fully updated to AmigaOS 4.x some of the information contained here may not be applicable in part or totally.

Introduction to Amiga System Resources

BattClock Resource

BattMem Resource

CIA Resource

Disk Resource

FileSystem Resource

Misc Resource

Potgo Resource