Welcome, Guest. Please login or register.
Amiga Kit Amiga Store Hollywood MAL AMIStore App Store A600 Memory

AuthorTopic: Gameport Interrupts  (Read 754 times)

0 Members and 1 Guest are viewing this topic.

Offline Sidewinder

Gameport Interrupts
« on: November 11, 2004, 10:22:26 PM »
I'm attempting to develop a way to Wait() for mouse inputs rather than using a busy loop.  I was thinking about useing an interrupt handler to do this by setting a signal when there is a change to the I/O ports, but there is something wrong with my code.  Can anyone help me figure out what I'm doing wrong here?

Code: [Select]

#include <stdio.h>
#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/memory.h>
#include <hardware/intbits.h>
#include <libraries/lowlevel.h>
#include <devices/timer.h>
#include <clib/exec_protos.h>
#include <clib/lowlevel_protos.h>
#include <clib/timer_protos.h>

struct Library *LowlevelBase = NULL;
struct Library *TimerBase = NULL;
struct Interrupt *IOPortInterrupt, *PriorInterrupt;
struct Task *task;
BYTE signalBit;

void IOPortInterruptHandler(void);

int main(void)
LowlevelBase = OpenLibrary(&quot;lowlevel.library&quot;, 0L);
IOPortInterrupt = (struct Interrupt *)AllocMem(sizeof(struct Interrupt), MEMF_PUBLIC);

if (LowlevelBase && IOPortInterrupt)
struct timerequest TimerIO;
struct timeval time;
ULONG portState = 0;
ULONG lastState = 0;
ULONG signals;

if (!OpenDevice(TIMERNAME, UNIT_MICROHZ, (struct IORequest *)&TimerIO, 0))
TimerBase = (struct Library *)TimerIO.tr_node.io_Device;

IOPortInterrupt->is_Node.ln_Type = NT_INTERRUPT;
IOPortInterrupt->is_Node.ln_Pri = 0;
IOPortInterrupt->is_Node.ln_Name = &quot;PortIOInterrupt&quot;;
IOPortInterrupt->is_Data = NULL;
IOPortInterrupt->is_Code = IOPortInterruptHandler;

task = FindTask(NULL);
signalBit = AllocSignal(-1);
signals = (1L << signalBit);

PriorInterrupt = SetIntVector(INTB_PORTS, IOPortInterrupt);
SetJoyPortAttrs(1, SJA_Type, SJA_TYPE_MOUSE);


portState = ReadJoyPort(1);

if (portState != lastState)

printf(&quot;%d sec, %d micro\n&quot;, time.tv_secs, time.tv_micro);

lastState = portState;
while (GetKey() != 64); /* Press Space-Bar to Exit. */

SetJoyPortAttrs(1, SJA_Reinitialize);
SetIntVector(INTB_PORTS, PriorInterrupt);

if (LowlevelBase)

return 0;

void IOPortInterruptHandler(void)
Signal(task, (1L << signalBit));


Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
  • Total likes: 0
    • http://www.iki.fi/sintonen/
Re: Gameport Interrupts
« Reply #1 on: November 11, 2004, 10:37:47 PM »
Why make it this complex, why not use IDCMP? Another easy way would be using input.device/IND_ADDHANDLER to add an input handler.

Offline Sidewinder

Re: Gameport Interrupts
« Reply #2 on: November 11, 2004, 11:41:49 PM »

Well, mainly because I'm not really interested in the events.  I'm more interested in the data at the port and I can read the data directly with ReadJoyPort().  But I need a way to pause the program until that data at the port changes.

Offline Karlos

Re: Gameport Interrupts
« Reply #3 on: November 12, 2004, 12:07:48 AM »
Topic hijack...

I also need to investigate the possiblitiy of a low level/low latency wait for hardware interrupt that may be generated by my graphics card on completion of a rendering operation.

I know I can (assuming I know exactly which interrupt to use) send the task to sleep and then use an interrupt handler to signal it when the time comes, but is there a lower latency way?

Anybody had any real experience with this kind of thing?
int p; // A