Copyright (c) Hyperion Entertainment and contributors.

Exec Resources

From AmigaOS Documentation Wiki
Jump to navigation Jump to search

Introduction

The Amiga’s low-level hardware control functions are collectively referred to as “Resources”. Most applications will never need to use the hardware at the resource level—the Amiga’s device interface is much more convenient and provides for multitasking. However, some high performance applications, such as MIDI time stamping, may require direct access to the Amiga hardware registers.

The Amiga Resources

There are many standard resources in the Amiga system. Each system may have different resources available depending on the hardware platform. The following lists some resources including the name of the resource and its function.

battclock.resource grants access to the battery-backed clock chip.
battmem.resource grants access to non-volatile RAM.
cia.resource grants access to the interrupts and timer bits of the 8520 CIA (Complex Interface Adapter) chips.
disk.resource grants temporary exclusive access to the disk hardware.
FileSystem.resource grants access to the file system.
misc.resource grants exclusive access to functional blocks of chip registers. At present, definitions have been made for the serial and parallel hardware only.
potgo.resource manages the bits of the proportional I/O pins on the game controller ports.
xena.resource grants access to the Xena chip.

The resources allow you direct access to the hardware in a way that is compatible with multitasking. They also allow you to temporarily bar other tasks from using the resource. You may then use the associated hardware directly for your special purposes. If applicable, you must return the resource back to the system for other tasks to use when you are finished with it.

See the Amiga Hardware Reference Manual for detailed information on the actual hardware involved.

Look Before You Leap
Resources are just one step above direct hardware manipulation. You are advised to try the higher level device and library approach before resorting to the hardware.

Resource Interface

Resources provide functions that you call to do low-level operations with the hardware they access. In order to use the functions of a resource, you must obtain a pointer to the resource. This is done by calling the OpenResource() function with the resource name as its argument.

OpenResource() returns a pointer to the resource you request or NULL if it does not exist.

#include <resources/filesysres.h>
 
struct FileSysResource *FileSysResBase = NULL;
 
if (!(FileSysResBase = IExec->OpenResource(FSRNAME)))
    IDOS->Printf("Cannot open %s\n", FSRNAME);

There is no CloseResource() function. When you are done with a resource, you are done with it. However, as you will see below, some resources provide functions to allocate parts of the hardware they access. In those cases, you will have to free those parts for anyone else to use them.

Each resource has at least one include file in the resources subdirectory of the include directory. Some of the include files contain only the name of the resource; others list structures and bit definitions used by the resource. The include files will be listed at the end of this article.

Calling a resource function is the same as calling any other function on the Amiga. You have to know what parameters it accepts and the return value, if any. The Autodocs for each resource lists the functions and their requirements.

#include <hardware/cia.h>
#include <resources/cia.h>
 
#include <proto/exec.h>
#include <proto/dos.h>
 
struct Library *CIAResource = NULL;
 
ing main()
{
int16 mask = 0;
 
if (!(CIAResource = IExec->OpenResource(CIABNAME)))
    IDOS->Printf("Cannot open %s\n", CIABNAME);
else
   {
    /* What is the interrupt enable mask? */
     mask = AbleICR(CIAResource, 0);
 
    IDOS->Printf("\nThe CIA interrupt enable mask: 0x%x \n", mask);
   }
}
Looks Can Be Deceiving
Some resources may look like libraries and act like libraries, but be assured they are not libraries.