Copyright (c) Hyperion Entertainment and contributors.
Difference between revisions of "Resources"
Jump to navigation
Jump to search
Steven Solie (talk | contribs) |
|||
(8 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | == Introduction == |
||
− | {{NeedUpdate}} |
||
+ | Resources are responsible for low-level hardware control, see [[Exec Resources]] to have a better insight of what it is and how it's used. |
||
− | [[Introduction to Amiga System Resources]] |
||
+ | |||
+ | == System Resources == |
||
[[BattClock Resource]] |
[[BattClock Resource]] |
||
Line 10: | Line 12: | ||
[[Disk Resource]] |
[[Disk Resource]] |
||
+ | |||
+ | [[DMA Resource]] |
||
[[FileSystem Resource]] |
[[FileSystem Resource]] |
||
Line 17: | Line 21: | ||
[[Potgo Resource]] |
[[Potgo Resource]] |
||
+ | [[PerformanceMonitor Resource]] |
||
+ | [[Xena 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 & resources/filesysres.h<br /> |
||
− | & resources/filesysres.i<br /> |
||
− | AutoDocs & filesysres.doc<br /> |
||
− | Libraries & 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() & 7.8cmAllocate one of the serial or parallel misc resources.<br /> |
||
− | FreeMiscResource() & 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 "owns" |
||
− | * 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 "include:" |
||
− | INCLUDE "exec/types.i" |
||
− | INCLUDE "resources/misc.i" |
||
− | INCLUDE "dos/dos.i" |
||
− | |||
− | 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 "misc.resource" |
||
− | 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 <exec/types.h> |
||
− | #include <exec/memory.h> |
||
− | #include <dos/dos.h> |
||
− | #include <resources/misc.h> |
||
− | |||
− | #include <clib/exec_protos.h> |
||
− | #include <clib/misc_protos.h> |
||
− | |||
− | #include <stdio.h> |
||
− | |||
− | #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("Cannot open %s\n",MISCNAME); |
||
− | else |
||
− | { |
||
− | /* Allocate both pieces of the serial hardware */ |
||
− | if ((owner = AllocMiscResource(MR_SERIALPORT,"Serial Port Hog")) == NULL) |
||
− | { |
||
− | if ((owner = AllocMiscResource(MR_SERIALBITS,"Serial Port Hog")) == NULL) |
||
− | { |
||
− | /* Wait for CTRL-C to be pressed */ |
||
− | printf("\nWaiting for CTRL-C...\n"); |
||
− | Wait(SIGBREAKF_CTRL_C); |
||
− | |||
− | /* We're back */ |
||
− | |||
− | /* Deallocate the serial port register */ |
||
− | FreeMiscResource(MR_SERIALBITS); |
||
− | } |
||
− | else |
||
− | printf("\nUnable to allocate MR_SERIALBITS because %s owns it\n",owner); |
||
− | |||
− | /* Deallocate the serial port */ |
||
− | FreeMiscResource(MR_SERIALPORT); |
||
− | } |
||
− | else |
||
− | printf("\nUnable to allocate MR_SERIALPORT because %s owns it\n",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 <exec/types.h> |
||
− | #include <exec/execbase.h> |
||
− | |||
− | #include <clib/exec_protos.h> |
||
− | |||
− | void FlushDevice(char *); |
||
− | |||
− | extern struct ExecBase *SysBase; |
||
− | |||
− | void FlushDevice(char *name) |
||
− | { |
||
− | struct Device *devpoint; |
||
− | |||
− | Forbid(); |
||
− | |||
− | if (devpoint=(struct Device *)FindName(&SysBase->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 & resources/misc.h<br /> |
||
− | & resources/misc.i<br /> |
||
− | AutoDocs & 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() & 8.7cmAllocate bits in the POTGO register.<br /> |
||
− | FreePotBits() & 8.7cmFree previously allocated bits in the POTGO register.<br /> |
||
− | WritePotgo() & 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 <exec/types.h> |
||
− | #include <exec/memory.h> |
||
− | #include <dos/dos.h> |
||
− | #include <resources/potgo.h> |
||
− | #include <hardware/custom.h> |
||
− | |||
− | #include <clib/exec_protos.h> |
||
− | #include <clib/potgo_protos.h> |
||
− | |||
− | #include <stdio.h> |
||
− | |||
− | #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<<15 |
||
− | #define DATRY 1L<<14 |
||
− | #define OUTRX 1L<<13 |
||
− | #define DATRX 1L<<12 |
||
− | |||
− | extern struct Custom far custom; |
||
− | |||
− | void main(int argc,char **argv) |
||
− | { |
||
− | UNLESS (PotgoBase=(struct PotgoBase *)OpenResource("potgo.resource")) |
||
− | 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("Pot bits are already allocated! %lx\n",potbits); |
||
− | FreePotBits(potbits); |
||
− | return; |
||
− | } |
||
− | |||
− | /* Set all ones in the register (masked by potbits) */ |
||
− | WritePotgo(0xFFFFFFFFL,potbits); |
||
− | |||
− | printf("\nPlug a mouse into the second port. This program will indicate when\n"); |
||
− | printf("the right or middle button (if the mouse is so equipped) is pressed.\n"); |
||
− | printf("Stop the program with Control-C. Press return now to begin.\n"); |
||
− | |||
− | getchar(); |
||
− | |||
− | UNTIL (SIGBREAKF_CTRL_C & 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("POTINP = $%lx\n",value & 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 & resources/potgo.h<br /> |
||
− | & resources/potgo.i<br /> |
||
− | & utility/hooks.h<br /> |
||
− | & utility/hooks.i<br /> |
||
− | AutoDocs & potgo.doc<br /> |
Latest revision as of 21:51, 18 October 2023
Introduction
Resources are responsible for low-level hardware control, see Exec Resources to have a better insight of what it is and how it's used.