Try for more robust daemon and cool Apple II commands from DOS 3.3

This commit is contained in:
dschmenk 2013-08-24 11:09:02 -07:00
parent 9971e7c348
commit 1a5d470f48
4 changed files with 896 additions and 854 deletions

Binary file not shown.

View File

@ -312,9 +312,12 @@ int keycode[256] = {
MOD_SHIFT | KEY_GRAVE, // ~ code 7E
KEY_DELETE // DELETE code 7F
};
#define RUN 0
#define STOP 1
#define RESET 2
int accel[32] = { 0, 1, 4, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
-21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -4, -1};
volatile int stop = FALSE, isdaemon = FALSE;
volatile int state = RUN, isdaemon = FALSE;
struct input_event evkey, evrelx, evrely, evsync;
void sendkeycodedown(int fd, int code)
@ -519,6 +522,36 @@ void finreq(int a2fd, int status, int result)
a2req->next = a2reqfree;
a2reqfree = a2req;
}
void flushreqs(int a2fd, int status, int result)
{
char finbuf[2];
struct a2request *a2req;
while (a2req = a2reqlist)
{
/*
* Send result to socket.
*/
if (a2req->fd)
{
if (a2req->type == 0x90) /* read bytes */
write(a2req->fd, a2req->buffer, a2req->count);
finbuf[0] = status;
finbuf[1] = result;
write(a2req->fd, finbuf, 2);
}
if (a2req->buffer)
{
free(a2req->buffer);
a2req->buffer = NULL;
}
/*
* Update lists.
*/
a2reqlist = a2req->next;
a2req->next = a2reqfree;
a2reqfree = a2req;
}
}
void main(int argc, char **argv)
{
struct uinput_user_dev uidev;
@ -679,7 +712,7 @@ void main(int argc, char **argv)
else
{
prlog("a2pi: Bad Sync ACK\n");
stop = TRUE;
state = RESET;
}
}
newtio.c_cc[VMIN] = 3; /* blocking read until 3 chars received */
@ -699,6 +732,11 @@ void main(int argc, char **argv)
die("error: bind socket");
if (listen(srvfd, 1) < 0)
die("error: listen socket");
/*
* Come basck here on RESET.
*/
reset:
state = RUN;
reqfd = 0;
FD_ZERO(&openset);
FD_SET(a2fd, &openset);
@ -708,7 +746,7 @@ void main(int argc, char **argv)
* Event loop
*/
prlog("a2pid: Enter event loop\n");
while (!stop)
while (state == RUN)
{
memcpy(&readset, &openset, sizeof(openset));
if (select(maxfd + 1, &readset, NULL, NULL, NULL) > 0)
@ -728,12 +766,13 @@ void main(int argc, char **argv)
iopkt[0] = 0x81; /* acknowledge */
write(a2fd, iopkt, 1);
tcflush(a2fd, TCIFLUSH);
flushreqs(a2fd, -1, -1);
break;
case 0x82: /* keyboard event */
// printf("Keyboard Event: 0x%02X:%c\n", iopkt[1], iopkt[2] & 0x7F);
sendkey(kbdfd, iopkt[1], iopkt[2]);
if (iopkt[2] == 0x9B && iopkt[1] == 0xC0)
stop = TRUE;
state = STOP;
break;
case 0x84: /* mouse move event */
// printf("Mouse XY Event: %d,%d\n", (signed char)iopkt[1], (signed char)iopkt[2]);
@ -760,18 +799,18 @@ void main(int argc, char **argv)
a2reqlist->buffer[a2reqlist->xfer++] = iopkt[0];
else
{
stop = TRUE;
state = RESET;
break;
}
}
}
else
stop = TRUE;
state = RESET;
newtio.c_cc[VMIN] = 3; /* blocking read until 3 chars received */
tcsetattr(a2fd, TCSANOW, &newtio);
}
else
stop = TRUE;
state = RESET;
break;
case 0x92: /* acknowledge write bytes */
if (a2reqlist) /* better have an outstanding request */
@ -787,15 +826,15 @@ void main(int argc, char **argv)
if (write(a2fd, a2reqlist->buffer + a2reqlist->xfer, c) == c)
a2reqlist->xfer += c;
else
stop = TRUE;
state = RESET;
}
else
stop = TRUE;
state = RESET;
newtio.c_cc[VMIN] = 3; /* blocking read until 3 chars received */
tcsetattr(a2fd, TCSANOW, &newtio);
}
else
stop = TRUE;
state = RESET;
break;
case 0x94: /* acknowledge call */
if (a2reqlist) /* better have an outstanding request */
@ -804,12 +843,12 @@ void main(int argc, char **argv)
newtio.c_cc[VMIN] = 1; /* blocking read until 1 char received */
tcsetattr(a2fd, TCSANOW, &newtio);
if (!writeword(a2fd, a2reqlist->addr, 0x95))
stop = TRUE;
state = RESET;
newtio.c_cc[VMIN] = 3; /* blocking read until 3 chars received */
tcsetattr(a2fd, TCSANOW, &newtio);
}
else
stop = TRUE;
state = RESET;
break;
case 0x9E: /* request complete ok */
case 0x9F: /* request complete error */
@ -829,7 +868,7 @@ void main(int argc, char **argv)
}
}
else
stop = TRUE;
state = RESET;
break;
default:
prlog("a2pid: Unknown Event\n");
@ -840,7 +879,7 @@ void main(int argc, char **argv)
else
{
prlog("a2pid: error read serial port ????\n");
stop = TRUE;
state = RESET;
}
}
/*
@ -920,19 +959,21 @@ void main(int argc, char **argv)
break;
default:
prlog("a2pid: Unknown Request\n");
stop = TRUE;
}
}
else
{
prlog("a2pid: error read socket ????");
stop = TRUE;
state = RESET;
}
}
}
}
flushreqs(a2fd, -1, -1);
if (reqfd > 0)
close(reqfd);
if (state == RESET)
goto reset;
shutdown(srvfd, SHUT_RDWR);
close(srvfd);
tcsetattr(a2fd, TCSANOW, &oldtio);

View File

@ -41,6 +41,7 @@ int main(int argc, char **argv)
if (addr + len > MAXSIZE)
len = MAXSIZE - addr;
memptr = membuff;
printf("Loading");
while (len)
{
printf(".");

View File

@ -60,7 +60,7 @@ int main(int argc, char **argv)
len = 0;
}
}
printf("\nCalling Apple II...");
printf("\nRunning...");
fflush(stdout);
a2call(pifd, entry, &result);
a2close(pifd);