[Simh] Pointer Question
Michael Mondy
michael.mondy at coffeebird.net
Sun Dec 16 17:05:04 EST 2012
On Sun, Dec 16, 2012 at 11:05:17AM -0700, Bill Beech (NJ7P) wrote:
> Guys,
>
> I am having trouble with pointers. I would like to be able to
> register I/O devices with my bus manager. Currently I have only
> multibus.c performing this function.
>
> Here are some snippets of the code:
> [snip]
>
> I would like to be able to call reg_dev with an I/O routine address
> and the port number, and have it place the address into
> dev_table[port] IFF dev_table[port] is currently nulldev.
>
> I know I am messing up the pointers horribly. If I remove the
> ".routine(0, 0)" it errors with dissimilar variables. I have tried
> all sorts of casts to no avail.
>
> Thanks for your help and don't laugh too hard!
>
> Bill
>
You were on the right track. Here's a corrected version. Note that this is actually an compilable and exeeutable example...
It'll print:
Port 00 is now assigned
Port 04 is already assigned
Port FF is now assigned (oddly table entry was null)
#include <stdio.h>
/* Internal I/O address space functions */
typedef int int32;
// typedef int32 (*svc_rtn_t)();
int32 nulldev();
#if 0
extern int32 i8251s(int32 io, int32 data);
extern int32 i8251d(int32 io, int32 data);
extern int32 i8255a(int32 io, int32 data);
extern int32 i8255b(int32 io, int32 data);
extern int32 i8255c(int32 io, int32 data);
extern int32 i8255s(int32 io, int32 data);
#else
#define factory(FN) int32 FN(int32 io, int32 data) {printf("<FN>\n"); return -1; }
factory(i8251s)
factory(i8251d)
factory(i8255a)
factory(i8255b)
factory(i8255c)
factory(i8255s)
#endif
/* This is the I/O configuration table. There are 256 possible
device addresses, if a device is plugged to a port it's routine
address is here, 'nulldev' means no device is available
*/
struct idev {
int32 (*routine)();
};
struct idev dev_table[256] = {
{&nulldev}, {&nulldev}, {&nulldev}, {&nulldev}, /* 000H .. 003H */
/* ......... */
{&i8255a},{&i8255b},{&i8255c},{&i8255s}, /* 0E4H */
{&nulldev}, {&nulldev}, {&nulldev}, {&nulldev}, /* 0E8H */
{&i8251d},{&i8251s},{&i8251d},{&i8251s}, /* 0ECH */
{&nulldev}, {&nulldev}, {&nulldev}, {&nulldev}, /* 0F0H */
{&nulldev}, {&nulldev}, {&nulldev}, {&nulldev}, /* 0F4H */
{&nulldev}, {&nulldev}, {&nulldev}, {&nulldev}, /* 0F8H */
{&nulldev}, {&nulldev}, {&nulldev}, {&nulldev} /* 0FCH */
};
int32 nulldev(int32 flag, int32 data)
{
// SET_XACK(0); /* set no XACK */
if (flag == 0)
return (0xFF);
return 0;
}
/*this mess gives only a warning in this state */
int32 reg_dev(int32 (*routine)(), int32 port)
{
if (dev_table[port].routine == NULL) {
printf("Port %02X is now assigned (oddly table entry was null)\n", port);
dev_table[port].routine = routine;
} else if (dev_table[port].routine != &nulldev) { /* port already assigned */
printf("Port %02X is already assigned\n", port);
} else {
printf("Port %02X is now assigned\n", port);
dev_table[port].routine = routine;
}
}
int32 my_routine()
{
printf("my_routine()\n");
}
main()
{
reg_dev(my_routine, 0);
reg_dev(my_routine, 4);
reg_dev(my_routine, 255);
}
-- Mike
More information about the Simh
mailing list