Go to the first, previous, next, last section, table of contents.


Opening And Closing ahi.device For Low-level Access

Not too hard. Just open ahi.device unit AHI_NO_UNIT and initialize AHIBase. After that you can access all the functions of the device just as if you had opened a standard shared library.

Assembler

For the assembler programmer there are two handy macros: OPENAHI and CLOSEAHI. Here is a small example how to use them:

        OPENAHI 4                  ;Open at least version 4.
        lea     _AHIBase(pc),a0
        move.l  d0,(a0)
        beq     error

; AHI's functions can now be called as normal library functions:
        move.l  _AHIBase(pc),a6
        moveq   #AHI_INVALID_ID,d0
        jsr     _LVOAHI_NextAudioID(a6)

error:
        CLOSEAHI
        rts

Note that you have to execute the CLOSEAHI macro even if OPENAHI failed!

C

For the C programmer, here is how it should be done:

struct Library    *AHIBase;
struct MsgPort    *AHImp=NULL;
struct AHIRequest *AHIio=NULL;
BYTE               AHIDevice=-1;

if(AHImp=CreateMsgPort())
{
  if(AHIio=(struct AHIRequest *)CreateIORequest(
      AHImp,sizeof(struct AHIRequest)))
  {
    AHIio->ahir_Version=4;  // Open at least version 4.
    if(!(AHIDevice=OpenDevice(AHINAME,AHI_NO_UNIT,
        (struct IORequest *)AHIio,NULL)))
    {
      AHIBase=(struct Library *)AHIio->ahir_Std.io_Device;

// AHI's functions can now be called as normal library functions:
      AHI_NextAudioID(AHI_INVALID_ID);

      CloseDevice((struct IORequest *)AHIio);
      AHIDevice=-1; // Good habit, IMHO.
    }
    DeleteIORequest((struct IORequest *)AHIio);
    AHIio=NULL;
  }
  DeleteMsgPort(AHImp);
  AHImp=NULL;
}


Go to the first, previous, next, last section, table of contents.