1
0
mirror of https://github.com/aap/pdp6.git synced 2026-02-12 11:07:34 +00:00

started modularizing the code somewhat

This commit is contained in:
aap
2016-10-26 16:44:59 +02:00
parent 2c3242fd4d
commit 3b09b5f613
5 changed files with 491 additions and 438 deletions

112
src/tty.c
View File

@@ -7,27 +7,27 @@
#include <pthread.h>
#include <poll.h>
Tty tty;
void
recalc_tty_req(void)
recalc_tty_req(Tty *tty)
{
u8 req;
req = tty.tto_flag || tty.tti_flag ? tty.pia : 0;
if(req != ioreq[TTY]){
ioreq[TTY] = req;
req = tty->tto_flag || tty->tti_flag ? tty->pia : 0;
if(req != iobus[TTY].pireq){
iobus[TTY].pireq = req;
recalc_req();
}
}
void*
ttythread(void *arg)
ttythread(void *dev)
{
int sockfd, newsockfd, portno, clilen;
char buf;
struct sockaddr_in serv_addr, cli_addr;
int n;
Tty *tty;
tty = dev;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0){
perror("error: socket");
@@ -47,16 +47,16 @@ ttythread(void *arg)
while(newsockfd = accept(sockfd, (struct sockaddr*)&cli_addr, &clilen)){
printf("TTY attached\n");
tty.fd = newsockfd;
while(n = read(tty.fd, &buf, 1), n > 0){
tty.tti_busy = 1;
tty->fd = newsockfd;
while(n = read(tty->fd, &buf, 1), n > 0){
tty->tti_busy = 1;
//fprintf(stderr, "(got.%c)", buf);
tty.tti = buf|0200;
tty.tti_busy = 0;
tty.tti_flag = 1;
recalc_tty_req();
tty->tti = buf|0200;
tty->tti_busy = 0;
tty->tti_flag = 1;
recalc_tty_req(tty);
}
tty.fd = -1;
tty->fd = -1;
close(newsockfd);
}
if(newsockfd < 0){
@@ -67,67 +67,69 @@ ttythread(void *arg)
}
static void
wake_tty(void)
wake_tty(void *dev)
{
Tty *tty;
tty = dev;
if(IOB_RESET){
tty.pia = 0;
tty.tto_busy = 0;
tty.tto_flag = 0;
tty.tto = 0;
tty.tti_busy = 0;
tty.tti_flag = 0;
tty.tti = 0;
tty->pia = 0;
tty->tto_busy = 0;
tty->tto_flag = 0;
tty->tto = 0;
tty->tti_busy = 0;
tty->tti_flag = 0;
tty->tti = 0;
}
if(iodev == TTY){
if(IOB_STATUS){
if(tty.tti_busy) iobus0 |= F29;
if(tty.tti_flag) iobus0 |= F30;
if(tty.tto_busy) iobus0 |= F31;
if(tty.tto_flag) iobus0 |= F32;
iobus0 |= tty.pia & 7;
if(tty->tti_busy) iobus0 |= F29;
if(tty->tti_flag) iobus0 |= F30;
if(tty->tto_busy) iobus0 |= F31;
if(tty->tto_flag) iobus0 |= F32;
iobus0 |= tty->pia & 7;
}
if(IOB_DATAI){
iobus0 |= tty.tti;
tty.tti_flag = 0;
iobus0 |= tty->tti;
tty->tti_flag = 0;
}
if(IOB_CONO_CLEAR)
tty.pia = 0;
tty->pia = 0;
if(IOB_CONO_SET){
if(iobus0 & F25) tty.tti_busy = 0;
if(iobus0 & F26) tty.tti_flag = 0;
if(iobus0 & F27) tty.tto_busy = 0;
if(iobus0 & F28) tty.tto_flag = 0;
if(iobus0 & F29) tty.tti_busy = 1;
if(iobus0 & F30) tty.tti_flag = 1;
if(iobus0 & F31) tty.tto_busy = 1;
if(iobus0 & F32) tty.tto_flag = 1;
tty.pia |= iobus0 & 7;
if(iobus0 & F25) tty->tti_busy = 0;
if(iobus0 & F26) tty->tti_flag = 0;
if(iobus0 & F27) tty->tto_busy = 0;
if(iobus0 & F28) tty->tto_flag = 0;
if(iobus0 & F29) tty->tti_busy = 1;
if(iobus0 & F30) tty->tti_flag = 1;
if(iobus0 & F31) tty->tto_busy = 1;
if(iobus0 & F32) tty->tto_flag = 1;
tty->pia |= iobus0 & 7;
}
if(IOB_DATAO_CLEAR){
tty.tto = 0;
tty.tto_busy = 1;
tty.tto_flag = 0;
tty->tto = 0;
tty->tto_busy = 1;
tty->tto_flag = 0;
}
if(IOB_DATAO_SET){
tty.tto = iobus0 & 0377;
if(tty.fd >= 0){
tty.tto &= ~0200;
write(tty.fd, &tty.tto, 1);
tty->tto = iobus0 & 0377;
if(tty->fd >= 0){
tty->tto &= ~0200;
write(tty->fd, &tty->tto, 1);
}
// TTO DONE
tty.tto_busy = 0;
tty.tto_flag = 1;
tty->tto_busy = 0;
tty->tto_flag = 1;
}
}
recalc_tty_req();
recalc_tty_req(tty);
}
void
inittty(void)
inittty(Tty *tty)
{
pthread_t thread_id;
tty.fd = -1;
ioreq[TTY] = 0;
pthread_create(&thread_id, nil, ttythread, nil);
iobusmap[TTY] = wake_tty;
tty->fd = -1;
iobus[TTY] = (Busdev){ tty, wake_tty, 0 };
pthread_create(&thread_id, nil, ttythread, tty);
}