Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "Exec Resources"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
Line 67: Line 67:
   
 
if (!(CIAResource = IExec->OpenResource(CIABNAME)))
 
if (!(CIAResource = IExec->OpenResource(CIABNAME)))
printf("Cannot open %s\n", CIABNAME);
+
printf("Cannot open %s\n", CIABNAME);
 
else
 
else
 
{
 
{
Line 73: Line 73:
 
mask = AbleICR(CIAResource, 0);
 
mask = AbleICR(CIAResource, 0);
   
IDOS->Printf("\nThe CIA interrupt enable mask: %x \n", mask);
+
IDOS->Printf("\nThe CIA interrupt enable mask: 0x%x \n", mask);
 
}
 
}
 
}
 
}

Revision as of 23:19, 23 May 2012

WIP.png This page is currently being updated to AmigaOS 4.x. Some of the information contained here may not yet be applicable in part or totally.

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 currently seven standard resources in the Amiga system. The following lists the name of each 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 later in this chapter, 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 chapter.

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>
 
struct Library *CIAResource = NULL;
 
void main()
{
 
WORD mask = 0;
 
if (!(CIAResource = IExec->OpenResource(CIABNAME)))
    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.