Allow to activate all printf's via macro.
This commit is contained in:
parent
ee1dfafeeb
commit
95e16e6af0
109
src/a2pid.c
109
src/a2pid.c
|
@ -36,7 +36,7 @@ char deftty[] = "/dev/serial0"; /* Default for Raspberry Pi */
|
|||
* Apple II request entry
|
||||
*/
|
||||
#define MAX_XFER 64
|
||||
#define AWAIT_COMPLETE 0x100
|
||||
#define AWAIT_COMPLETE 0x100
|
||||
struct a2request {
|
||||
int idx;
|
||||
int type;
|
||||
|
@ -49,10 +49,10 @@ struct a2request {
|
|||
/*
|
||||
* Client info
|
||||
*/
|
||||
#define CLIENT_OPEN 1
|
||||
#define CLIENT_CLOSING 2
|
||||
#define CLIENT_COUT 4
|
||||
#define MAX_CLIENT 8
|
||||
#define CLIENT_OPEN 1
|
||||
#define CLIENT_CLOSING 2
|
||||
#define CLIENT_COUT 4
|
||||
#define MAX_CLIENT 8
|
||||
|
||||
struct {
|
||||
int fd;
|
||||
|
@ -77,14 +77,14 @@ int vdrvfd[2];
|
|||
/*
|
||||
* Daemon states.
|
||||
*/
|
||||
#define RUN 0
|
||||
#define STOP 1
|
||||
#define RESET 2
|
||||
#define RUN 0
|
||||
#define STOP 1
|
||||
#define RESET 2
|
||||
volatile int state = RUN, isdaemon = FALSE;
|
||||
void prlog(char *str)
|
||||
{
|
||||
if (!isdaemon)
|
||||
puts(str);
|
||||
puts(str);
|
||||
}
|
||||
static void sig_bye(int signo)
|
||||
{
|
||||
|
@ -103,12 +103,16 @@ int vdrvopen(char *path)
|
|||
char filename[256];
|
||||
strcpy(filename, path);
|
||||
strcat(filename, "A2VD1.PO");
|
||||
//printf("vdrv: open %s\n", filename);
|
||||
#ifdef TRACE
|
||||
printf("vdrv: open %s\n", filename);
|
||||
#endif
|
||||
if ((vdrvfd[0] = open(filename, O_RDWR, 0)) < 0)
|
||||
vdrvfd[0] = 0;
|
||||
strcpy(filename, path);
|
||||
strcat(filename, "A2VD2.PO");
|
||||
//printf("vdrv: open %s\n", filename);
|
||||
#ifdef TRACE
|
||||
printf("vdrv: open %s\n", filename);
|
||||
#endif
|
||||
if ((vdrvfd[1] = open(filename, O_RDWR, 0)) < 0)
|
||||
vdrvfd[1] = 0;
|
||||
return vdrvfd[0] + vdrvfd[1];
|
||||
|
@ -316,7 +320,7 @@ void sendrelxy(int fd, int x, int y)
|
|||
write(fd, &evsync, sizeof(evsync));
|
||||
}
|
||||
/*****************************************************************\
|
||||
* *
|
||||
* *
|
||||
* Request queue management *
|
||||
* *
|
||||
\*****************************************************************/
|
||||
|
@ -632,6 +636,9 @@ void main(int argc, char **argv)
|
|||
if (!pathmatch(&devtty, ttypattern))
|
||||
die("error: serial port not found");
|
||||
prlog("a2pid: Open serial port\n");
|
||||
#ifdef TRACE
|
||||
printf("a2pid: open %s\n", devtty);
|
||||
#endif
|
||||
a2fd = open(devtty, O_RDWR | O_NOCTTY);
|
||||
if (a2fd < 0)
|
||||
die("error: serial port open");
|
||||
|
@ -723,7 +730,9 @@ reset:
|
|||
rdycnt--;
|
||||
if (read(a2fd, iopkt, 3) == 3)
|
||||
{
|
||||
// printf("a2pi: A2 Event [0x%02X] [0x%02X] [0x%02X]\n", iopkt[0], iopkt[1], iopkt[2]);
|
||||
#ifdef TRACE
|
||||
printf("a2pi: A2 Event [0x%02X] [0x%02X] [0x%02X]\n", iopkt[0], iopkt[1], iopkt[2]);
|
||||
#endif
|
||||
switch (iopkt[0])
|
||||
{
|
||||
case 0x80: /* sync */
|
||||
|
@ -734,23 +743,31 @@ reset:
|
|||
flushreqs(a2fd, 0, -1, -1);
|
||||
break;
|
||||
case 0x82: /* keyboard event */
|
||||
// printf("Keyboard Event: 0x%02X:%c\n", iopkt[1], iopkt[2] & 0x7F);
|
||||
#ifdef TRACE
|
||||
printf("Keyboard Event: 0x%02X:%c\n", iopkt[1], iopkt[2] & 0x7F);
|
||||
#endif
|
||||
sendkey(kbdfd, iopkt[1], iopkt[2]);
|
||||
//if (iopkt[2] == 0x9B && iopkt[1] == 0xC0)
|
||||
//state = STOP;
|
||||
break;
|
||||
case 0x84: /* mouse move event */
|
||||
//printf("Mouse XY Event: %d,%d\n", (signed char)iopkt[1], (signed char)iopkt[2]);
|
||||
#ifdef TRACE
|
||||
printf("Mouse XY Event: %d,%d\n", (signed char)iopkt[1], (signed char)iopkt[2]);
|
||||
#endif
|
||||
sendrelxy(moufd, (signed char)iopkt[1], (signed char)iopkt[2]);
|
||||
break;
|
||||
case 0x86: /* mouse button event */
|
||||
// printf("Mouse Button %s Event 0x%02X\n", iopkt[2] ? "[PRESS]" : "[RELEASE]", iopkt[1]);
|
||||
sendbttn(moufd, iopkt[1], iopkt[2]);
|
||||
#ifdef TRACE
|
||||
printf("Mouse Button %s Event 0x%02X\n", iopkt[2] ? "[PRESS]" : "[RELEASE]", iopkt[1]);
|
||||
#endif
|
||||
sendbttn(moufd, iopkt[1], iopkt[2]);
|
||||
break;
|
||||
case 0x90: /* acknowledge read bytes request*/
|
||||
if (a2reqlist) /* better have an outstanding request */
|
||||
{
|
||||
//printf("a2pid: read %d of %d bytes from 0x%04X\n", a2reqlist->xfer, a2reqlist->count, a2reqlist->addr);
|
||||
#ifdef TRACE
|
||||
printf("a2pid: read %d of %d bytes from 0x%04X\n", a2reqlist->xfer, a2reqlist->count, a2reqlist->addr);
|
||||
#endif
|
||||
newtio.c_cc[VMIN] = 1; /* blocking read until 1 char received */
|
||||
tcsetattr(a2fd, TCSANOW, &newtio);
|
||||
c = a2reqlist->count - a2reqlist->xfer > MAX_XFER
|
||||
|
@ -780,7 +797,9 @@ reset:
|
|||
case 0x92: /* acknowledge write bytes */
|
||||
if (a2reqlist) /* better have an outstanding request */
|
||||
{
|
||||
//printf("a2pid: wrote %d of %d bytes to 0x%04X\n", a2reqlist->xfer, a2reqlist->count, a2reqlist->addr);
|
||||
#ifdef TRACE
|
||||
printf("a2pid: wrote %d of %d bytes to 0x%04X\n", a2reqlist->xfer, a2reqlist->count, a2reqlist->addr);
|
||||
#endif
|
||||
newtio.c_cc[VMIN] = 1; /* blocking read until 1 char received */
|
||||
tcsetattr(a2fd, TCSANOW, &newtio);
|
||||
c = a2reqlist->count - a2reqlist->xfer > MAX_XFER
|
||||
|
@ -810,7 +829,9 @@ reset:
|
|||
case 0x94: /* acknowledge call */
|
||||
if (a2reqlist) /* better have an outstanding request */
|
||||
{
|
||||
//printf("a2pid: call address 0x%04X\n", a2reqlist->addr);
|
||||
#ifdef TRACE
|
||||
printf("a2pid: call address 0x%04X\n", a2reqlist->addr);
|
||||
#endif
|
||||
newtio.c_cc[VMIN] = 1; /* blocking read until 1 char received */
|
||||
tcsetattr(a2fd, TCSANOW, &newtio);
|
||||
if (!writeword(a2fd, a2reqlist->addr, iopkt[0] + 1))
|
||||
|
@ -825,7 +846,9 @@ reset:
|
|||
case 0x96: /* send input char to Apple II */
|
||||
if (a2reqlist) /* better have an outstanding request */
|
||||
{
|
||||
//printf("a2pid: call address 0x%04X\n", a2reqlist->addr);
|
||||
#ifdef TRACE
|
||||
printf("a2pid: call address 0x%04X\n", a2reqlist->addr);
|
||||
#endif
|
||||
newtio.c_cc[VMIN] = 1; /* blocking read until 1 char received */
|
||||
tcsetattr(a2fd, TCSANOW, &newtio);
|
||||
if (!writeword(a2fd, a2reqlist->addr, 0x97))
|
||||
|
@ -847,7 +870,9 @@ reset:
|
|||
case 0x9F: /* request complete error */
|
||||
if (a2reqlist) /* better have an outstanding request */
|
||||
{
|
||||
//printf("a2pid: complete request 0x%02X:0x%02X\n", (unsigned char)iopkt[0], (unsigned char)iopkt[1]);
|
||||
#ifdef TRACE
|
||||
printf("a2pid: complete request 0x%02X:0x%02X\n", (unsigned char)iopkt[0], (unsigned char)iopkt[1]);
|
||||
#endif
|
||||
if ((a2reqlist->type == 0x90 || a2reqlist->type == 0x92)
|
||||
&& (a2reqlist->count > a2reqlist->xfer))
|
||||
{
|
||||
|
@ -856,7 +881,9 @@ reset:
|
|||
}
|
||||
else
|
||||
{
|
||||
//printf("a2pid: finish request 0x%02X:0x%02X\n", (unsigned char)iopkt[0], (unsigned char)iopkt[1]);
|
||||
#ifdef TRACE
|
||||
printf("a2pid: finish request 0x%02X:0x%02X\n", (unsigned char)iopkt[0], (unsigned char)iopkt[1]);
|
||||
#endif
|
||||
finreq(a2fd, (unsigned char)iopkt[0], (unsigned char)iopkt[1]);
|
||||
}
|
||||
}
|
||||
|
@ -865,7 +892,9 @@ reset:
|
|||
break;
|
||||
case 0xA0: /* virtual drive 1 STATUS call */
|
||||
case 0xA2: /* virtual drive 2 STATUS call */
|
||||
//printf("vdrive: STATUS unit:%d\n", (iopkt[0] >> 1) & 0x01);
|
||||
#ifdef TRACE
|
||||
printf("vdrive: STATUS unit:%d\n", (iopkt[0] >> 1) & 0x01);
|
||||
#endif
|
||||
iopkt[3] = iopkt[0] + 1; /* ack */
|
||||
write(a2fd, &iopkt[3], 1);
|
||||
iopkt[0] = vdrvstat(a2fd, (iopkt[0] >> 1) & 0x01);
|
||||
|
@ -874,12 +903,16 @@ reset:
|
|||
{
|
||||
iopkt[0] = a2reqlist->type;
|
||||
write(a2fd, iopkt, 1);
|
||||
//printf("vdrive: status resend request %04X\n", a2reqlist->type);
|
||||
#ifdef TRACE
|
||||
printf("vdrive: status resend request %04X\n", a2reqlist->type);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case 0xA4: /* virtual drive 1 READ call */
|
||||
case 0xA6: /* virtual drive 2 READ call */
|
||||
//printf("vdrive: READ unit:%d block:%d\n", (iopkt[0] >> 1) & 0x01, iopkt[1] | (iopkt[2] << 8));
|
||||
#ifdef TRACE
|
||||
printf("vdrive: READ unit:%d block:%d\n", (iopkt[0] >> 1) & 0x01, iopkt[1] | (iopkt[2] << 8));
|
||||
#endif
|
||||
iopkt[3] = iopkt[0] + 1; /* ack */
|
||||
write(a2fd, &iopkt[3], 1);
|
||||
iopkt[0] = vdrvread(a2fd, (iopkt[0] >> 1) & 0x01, iopkt[1] | (iopkt[2] << 8));
|
||||
|
@ -888,12 +921,16 @@ reset:
|
|||
{
|
||||
iopkt[0] = a2reqlist->type;
|
||||
write(a2fd, iopkt, 1);
|
||||
//printf("vdrive: read resend request %04X\n", a2reqlist->type);
|
||||
#ifdef TRACE
|
||||
printf("vdrive: read resend request %04X\n", a2reqlist->type);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case 0xA8: /* virtual drive 1 WRITE call */
|
||||
case 0xAA: /* virtual drive 2 WRITE call */
|
||||
//printf("vdrive: WRITE unit:%d block:%d\n", (iopkt[0] >> 1) & 0x01, iopkt[1] | (iopkt[2] << 8));
|
||||
#ifdef TRACE
|
||||
printf("vdrive: WRITE unit:%d block:%d\n", (iopkt[0] >> 1) & 0x01, iopkt[1] | (iopkt[2] << 8));
|
||||
#endif
|
||||
iopkt[3] = iopkt[0] + 1; /* ack */
|
||||
write(a2fd, &iopkt[3], 1);
|
||||
newtio.c_cc[VMIN] = 1; /* blocking read until command packet received */
|
||||
|
@ -906,11 +943,15 @@ reset:
|
|||
{
|
||||
iopkt[0] = a2reqlist->type;
|
||||
write(a2fd, iopkt, 1);
|
||||
//printf("vdrive: write resend request %04X\n", a2reqlist->type);
|
||||
#ifdef TRACE
|
||||
printf("vdrive: write resend request %04X\n", a2reqlist->type);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case 0xAC: /* virtual clock TIME call */
|
||||
//printf("vclock: TIME\n");
|
||||
#ifdef TRACE
|
||||
printf("vclock: TIME\n");
|
||||
#endif
|
||||
iopkt[0] = 0xAD; /* ack */
|
||||
write(a2fd, iopkt, 1);
|
||||
write(a2fd, prodos_time(), 4);
|
||||
|
@ -918,7 +959,9 @@ reset:
|
|||
{
|
||||
iopkt[0] = a2reqlist->type;
|
||||
write(a2fd, iopkt, 1);
|
||||
//printf("vclock: resend request %04X\n", a2reqlist->type);
|
||||
#ifdef TRACE
|
||||
printf("vclock: resend request %04X\n", a2reqlist->type);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -975,7 +1018,9 @@ reset:
|
|||
rdycnt--;
|
||||
if (read(a2client[i].fd, iopkt, 1) == 1)
|
||||
{
|
||||
// printf("a2pi: Client Request [0x%02X]\n", iopkt[0]);
|
||||
#ifdef TRACE
|
||||
printf("a2pi: Client Request [0x%02X]\n", iopkt[0]);
|
||||
#endif
|
||||
switch (iopkt[0])
|
||||
{
|
||||
case 0x90: /* read bytes */
|
||||
|
|
Loading…
Reference in New Issue