mirror of
https://github.com/dschmenk/apple2pi.git
synced 2024-11-27 17:51:42 +00:00
Fix early exit from Apple II connect and install permissions
This commit is contained in:
parent
26d6b31a92
commit
da4e1efd8c
BIN
src/A2PI.PO
BIN
src/A2PI.PO
Binary file not shown.
106
src/a2tty.c
Executable file
106
src/a2tty.c
Executable file
@ -0,0 +1,106 @@
|
||||
#include "a2lib.c"
|
||||
#include <termios.h>
|
||||
#define RUN 0
|
||||
#define STOP 1
|
||||
|
||||
int a2cin(int fd, char cin)
|
||||
{
|
||||
unsigned char cinpkt[2];
|
||||
cinpkt[0] = 0x96; // keyboard input
|
||||
cinpkt[1] = cin;
|
||||
return (write(fd, cinpkt, 2));
|
||||
}
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct termios oldtio,newtio;
|
||||
fd_set readset, openset;
|
||||
unsigned char iopkt[2];
|
||||
int state = RUN, echochr = 0;
|
||||
int pifd = a2open(argc > 1 ? argv[1] : "127.0.0.1");
|
||||
if (pifd < 0)
|
||||
{
|
||||
perror("Unable to connect to Apple II Pi");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
/*
|
||||
* Are we running interactively?
|
||||
*/
|
||||
if (isatty(STDIN_FILENO))
|
||||
{
|
||||
/*
|
||||
* Change input setting to work better as a terminal.
|
||||
*/
|
||||
tcgetattr(STDIN_FILENO, &oldtio); /* save current port settings */
|
||||
bzero(&newtio, sizeof(newtio));
|
||||
newtio.c_cflag = /*BAUDRATE | CRTSCTS |*/ CS8 | CLOCAL | CREAD;
|
||||
newtio.c_iflag = IGNPAR;
|
||||
newtio.c_oflag = 0;
|
||||
newtio.c_lflag = 0; /* set input mode (non-canonical, no echo,...) */
|
||||
newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
|
||||
newtio.c_cc[VMIN] = 1; /* blocking read until 1 char received */
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &newtio);
|
||||
/*
|
||||
* Prepare for select().
|
||||
*/
|
||||
echofd = 0;
|
||||
FD_ZERO(&openset);
|
||||
FD_SET(pifd, &openset);
|
||||
FD_SET(STDIN_FILENO, &openset);
|
||||
/*
|
||||
* Event loop
|
||||
*/
|
||||
while (state == RUN)
|
||||
{
|
||||
memcpy(&readset, &openset, sizeof(openset));
|
||||
if (select(pifd + 1, &readset, NULL, NULL, NULL) > 0)
|
||||
{
|
||||
/*
|
||||
* Apple II character output.
|
||||
*/
|
||||
if (FD_ISSET(pifd, &readset))
|
||||
{
|
||||
if (read(pifd, iopkt, 2) == 2)
|
||||
{
|
||||
/*
|
||||
* Acknowledgement.
|
||||
*/
|
||||
}
|
||||
else
|
||||
/*
|
||||
* Some kind of client/server error.
|
||||
*/
|
||||
state = STOP;
|
||||
}
|
||||
if (FD_ISSET(STDIN_FILENO, &readset))
|
||||
{
|
||||
if (read(STDIN_FILENO, iopkt, 1) == 1)
|
||||
{
|
||||
/*
|
||||
* Chain input character to child.
|
||||
*/
|
||||
}
|
||||
else
|
||||
/*
|
||||
* stdin probably closed.
|
||||
*/
|
||||
state = STOP;
|
||||
}
|
||||
if (FD_ISSET(fdecho, &readset))
|
||||
{
|
||||
if (read(STDIN_FILENO, iopkt, 1) == 1)
|
||||
{
|
||||
/*
|
||||
* Send stdout as cin to Apple II.
|
||||
*/
|
||||
if (opkt[0] == 0x04) // Ctrl-D
|
||||
state = STOP;
|
||||
a2cin(pifd, iopkt[0] | 0x80);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldtio);
|
||||
a2close(pifd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -22,5 +22,6 @@ if [ -f /etc/rc.local ] ; then
|
||||
if ! grep a2pid /etc/rc.local > /dev/null ; then
|
||||
mv /etc/rc.local /etc/rc.local.bak
|
||||
sed -e '/^exit/i\# Start Apple II Pi' -e '/^exit/i\/usr/local/bin/a2serclk' -e '/^exit/i\/usr/local/bin/a2pid --daemon' /etc/rc.local.bak > /etc/rc.local
|
||||
chmod +x /etc/rc.local
|
||||
fi
|
||||
fi
|
Loading…
Reference in New Issue
Block a user