mirror of
https://github.com/dschmenk/apple2pi.git
synced 2025-01-11 08:30:10 +00:00
Update client code and some formatting changes
This commit is contained in:
parent
1a5d470f48
commit
5559e82d68
BIN
src/A2PI.PO
BIN
src/A2PI.PO
Binary file not shown.
130
src/a2lib.c
130
src/a2lib.c
@ -9,81 +9,81 @@
|
|||||||
|
|
||||||
int a2open(char *ipaddr)
|
int a2open(char *ipaddr)
|
||||||
{
|
{
|
||||||
struct sockaddr_in piaddr;
|
struct sockaddr_in piaddr;
|
||||||
int res;
|
int res;
|
||||||
int fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
int fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
perror("Cannot create socket");
|
perror("Cannot create socket");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(&piaddr, 0, sizeof(piaddr));
|
memset(&piaddr, 0, sizeof(piaddr));
|
||||||
piaddr.sin_family = AF_INET;
|
piaddr.sin_family = AF_INET;
|
||||||
piaddr.sin_port = htons(6502);
|
piaddr.sin_port = htons(6502);
|
||||||
res = inet_pton(AF_INET, ipaddr, &piaddr.sin_addr);
|
res = inet_pton(AF_INET, ipaddr, &piaddr.sin_addr);
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
{
|
{
|
||||||
perror("First parameter is not a valid address family");
|
perror("First parameter is not a valid address family");
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (res == 0)
|
else if (res == 0)
|
||||||
{
|
{
|
||||||
perror("Char string (second parameter does not contain valid ipaddress)");
|
perror("Char string (second parameter does not contain valid ipaddress)");
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (connect(fd, (struct sockaddr *)&piaddr, sizeof(piaddr)) < 0)
|
if (connect(fd, (struct sockaddr *)&piaddr, sizeof(piaddr)) < 0)
|
||||||
{
|
{
|
||||||
perror("Connect failed");
|
perror("Connect failed");
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
void a2close(int fd)
|
void a2close(int fd)
|
||||||
{
|
{
|
||||||
char closepkt;
|
char closepkt;
|
||||||
closepkt = 0xFF;
|
closepkt = 0xFF;
|
||||||
write(fd, &closepkt, 1);
|
write(fd, &closepkt, 1);
|
||||||
shutdown(fd, SHUT_RDWR);
|
shutdown(fd, SHUT_RDWR);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
int a2read(int fd, int address, int count, char *buffer)
|
int a2read(int fd, int address, int count, char *buffer)
|
||||||
{
|
{
|
||||||
char readpkt[8];
|
char readpkt[8];
|
||||||
readpkt[0] = 0x90; // read
|
readpkt[0] = 0x90; // read
|
||||||
readpkt[1] = address;
|
readpkt[1] = address;
|
||||||
readpkt[2] = address >> 8;
|
readpkt[2] = address >> 8;
|
||||||
readpkt[3] = count;
|
readpkt[3] = count;
|
||||||
readpkt[4] = count >> 8;
|
readpkt[4] = count >> 8;
|
||||||
write(fd, readpkt, 5);
|
write(fd, readpkt, 5);
|
||||||
read(fd, buffer, count);
|
read(fd, buffer, count);
|
||||||
read(fd, readpkt, 2);
|
read(fd, readpkt, 2);
|
||||||
return ((unsigned char)readpkt[0] == 0x9E);
|
return ((unsigned char)readpkt[0] == 0x9E);
|
||||||
}
|
}
|
||||||
int a2write(int fd, int address, int count, char *buffer)
|
int a2write(int fd, int address, int count, char *buffer)
|
||||||
{
|
{
|
||||||
char writepkt[8];
|
char writepkt[8];
|
||||||
writepkt[0] = 0x92; // write
|
writepkt[0] = 0x92; // write
|
||||||
writepkt[1] = address;
|
writepkt[1] = address;
|
||||||
writepkt[2] = address >> 8;
|
writepkt[2] = address >> 8;
|
||||||
writepkt[3] = count;
|
writepkt[3] = count;
|
||||||
writepkt[4] = count >> 8;
|
writepkt[4] = count >> 8;
|
||||||
write(fd, writepkt, 5);
|
write(fd, writepkt, 5);
|
||||||
write(fd, buffer, count);
|
write(fd, buffer, count);
|
||||||
read(fd, writepkt, 2);
|
read(fd, writepkt, 2);
|
||||||
return ((unsigned char)writepkt[0] == 0x9E);
|
return ((unsigned char)writepkt[0] == 0x9E);
|
||||||
}
|
}
|
||||||
int a2call(int fd, int address, int *result)
|
int a2call(int fd, int address, int *result)
|
||||||
{
|
{
|
||||||
char callpkt[4];
|
char callpkt[4];
|
||||||
callpkt[0] = 0x94; // call
|
callpkt[0] = 0x94; // call
|
||||||
callpkt[1] = address;
|
callpkt[1] = address;
|
||||||
callpkt[2] = address >> 8;
|
callpkt[2] = address >> 8;
|
||||||
write(fd, callpkt, 3);
|
write(fd, callpkt, 3);
|
||||||
read(fd, callpkt, 2);
|
read(fd, callpkt, 2);
|
||||||
if (result)
|
if (result)
|
||||||
*result = (unsigned char)callpkt[1];
|
*result = (unsigned char)callpkt[1];
|
||||||
return ((unsigned char)callpkt[0] == 0x9E);
|
return ((unsigned char)callpkt[0] == 0x9E);
|
||||||
}
|
}
|
||||||
|
274
src/a2mon.c
274
src/a2mon.c
@ -2,149 +2,149 @@
|
|||||||
|
|
||||||
void prbytes(int address, int count, char *data)
|
void prbytes(int address, int count, char *data)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
printf("%04X:", address);
|
printf("%04X:", address);
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
printf(" %02X", (unsigned char)data[i]);
|
printf(" %02X", (unsigned char)data[i]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
void exec(int fd, int cmd, int *address, int value, char *data, int *index)
|
void a2exec(int fd, int cmd, int *address, int value, char *data, int *index)
|
||||||
{
|
{
|
||||||
int a, c;
|
int a, c;
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case 0x00:
|
case 0x00:
|
||||||
if (value != -1)
|
if (value != -1)
|
||||||
*address = value;
|
*address = value;
|
||||||
break;
|
break;
|
||||||
case 0x90: /* read */
|
case 0x90: /* read */
|
||||||
if (value < *address)
|
if (value < *address)
|
||||||
value = *address;
|
value = *address;
|
||||||
for (a = *address; a <= value; a += 16)
|
for (a = *address; a <= value; a += 16)
|
||||||
{
|
{
|
||||||
c = a + 16 > value ? value - a + 1 : 16;
|
c = a + 16 > value ? value - a + 1 : 16;
|
||||||
a2read(fd, a, c, data);
|
a2read(fd, a, c, data);
|
||||||
prbytes(a, c, data);
|
prbytes(a, c, data);
|
||||||
}
|
}
|
||||||
*address = value + 1;
|
*address = value + 1;
|
||||||
break;
|
break;
|
||||||
case 0x92: /* write */
|
case 0x92: /* write */
|
||||||
if (*index)
|
if (*index)
|
||||||
a2write(fd, *address, *index, data);
|
a2write(fd, *address, *index, data);
|
||||||
*address += *index;
|
*address += *index;
|
||||||
*index = 0;
|
*index = 0;
|
||||||
break;
|
break;
|
||||||
case 0x94: /* call */
|
case 0x94: /* call */
|
||||||
a2call(fd, *address, NULL);
|
a2call(fd, *address, NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int parsestr(int fd, char *cmdstr)
|
int parsestr(int fd, char *cmdstr)
|
||||||
{
|
{
|
||||||
char databuf[1024];
|
char databuf[1024];
|
||||||
static int addr = 0;
|
static int addr = 0;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int parseval = -1;
|
int parseval = -1;
|
||||||
int cmd =0 ;
|
int cmd =0 ;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
switch (*cmdstr)
|
switch (*cmdstr)
|
||||||
{
|
{
|
||||||
case ':': /* write bytes */
|
case ':': /* write bytes */
|
||||||
exec(fd, cmd, &addr, parseval, databuf, &index);
|
a2exec(fd, cmd, &addr, parseval, databuf, &index);
|
||||||
cmd = 0x92;
|
cmd = 0x92;
|
||||||
parseval = -1;
|
parseval = -1;
|
||||||
break;
|
break;
|
||||||
case '.': /* read address range */
|
case '.': /* read address range */
|
||||||
exec(fd, cmd, &addr, parseval, databuf, &index);
|
a2exec(fd, cmd, &addr, parseval, databuf, &index);
|
||||||
cmd = 0x90;
|
cmd = 0x90;
|
||||||
parseval = -1;
|
parseval = -1;
|
||||||
break;
|
break;
|
||||||
case 'R': /* run */
|
case 'R': /* run */
|
||||||
case 'r':
|
case 'r':
|
||||||
exec(fd, cmd, &addr, parseval, databuf, &index);
|
a2exec(fd, cmd, &addr, parseval, databuf, &index);
|
||||||
cmd = 0x94;
|
cmd = 0x94;
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'b':
|
case 'b':
|
||||||
case 'c':
|
case 'c':
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'f':
|
case 'f':
|
||||||
*cmdstr -= 'a' - 'A';
|
*cmdstr -= 'a' - 'A';
|
||||||
case 'A':
|
case 'A':
|
||||||
case 'B':
|
case 'B':
|
||||||
case 'C':
|
case 'C':
|
||||||
case 'D':
|
case 'D':
|
||||||
case 'E':
|
case 'E':
|
||||||
case 'F':
|
case 'F':
|
||||||
*cmdstr -= 'A' - '9' - 1;
|
*cmdstr -= 'A' - '9' - 1;
|
||||||
case '0':
|
case '0':
|
||||||
case '1':
|
case '1':
|
||||||
case '2':
|
case '2':
|
||||||
case '3':
|
case '3':
|
||||||
case '4':
|
case '4':
|
||||||
case '5':
|
case '5':
|
||||||
case '6':
|
case '6':
|
||||||
case '7':
|
case '7':
|
||||||
case '8':
|
case '8':
|
||||||
case '9':
|
case '9':
|
||||||
if (parseval == -1)
|
if (parseval == -1)
|
||||||
parseval = 0;
|
parseval = 0;
|
||||||
parseval = parseval * 16 + *cmdstr - '0';
|
parseval = parseval * 16 + *cmdstr - '0';
|
||||||
break;
|
break;
|
||||||
case ' ':
|
case ' ':
|
||||||
if (parseval != -1)
|
if (parseval != -1)
|
||||||
{
|
{
|
||||||
if (cmd == 0x92)
|
if (cmd == 0x92)
|
||||||
databuf[index++] = parseval;
|
databuf[index++] = parseval;
|
||||||
else
|
else
|
||||||
exec(fd, cmd, &addr, parseval, databuf, &index);
|
a2exec(fd, cmd, &addr, parseval, databuf, &index);
|
||||||
parseval = -1;
|
parseval = -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
case '\0':
|
case '\0':
|
||||||
if (parseval != -1)
|
if (parseval != -1)
|
||||||
{
|
{
|
||||||
if (cmd == 0x92)
|
if (cmd == 0x92)
|
||||||
databuf[index++] = parseval;
|
databuf[index++] = parseval;
|
||||||
else if (cmd == 0)
|
else if (cmd == 0)
|
||||||
{
|
{
|
||||||
addr = parseval;
|
addr = parseval;
|
||||||
cmd = 0x90;
|
cmd = 0x90;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exec(fd, cmd, &addr, parseval, databuf, &index);
|
a2exec(fd, cmd, &addr, parseval, databuf, &index);
|
||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
case 'Q':
|
case 'Q':
|
||||||
case 'q':
|
case 'q':
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
cmdstr++;
|
cmdstr++;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char instr[256];
|
char instr[256];
|
||||||
int pifd = a2open(argc > 1 ? argv[1] : "127.0.0.1");
|
int pifd = a2open(argc > 1 ? argv[1] : "127.0.0.1");
|
||||||
if (pifd < 0)
|
if (pifd < 0)
|
||||||
{
|
{
|
||||||
perror("Unable to connect to Apple II Pi");
|
perror("Unable to connect to Apple II Pi");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
while (fgets(instr, 254, stdin) != NULL)
|
while (fgets(instr, 254, stdin) != NULL)
|
||||||
{
|
{
|
||||||
if (!parsestr(pifd, instr))
|
if (!parsestr(pifd, instr))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
a2close(pifd);
|
a2close(pifd);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user