1
0
mirror of https://github.com/aap/pdp6.git synced 2026-01-13 15:27:46 +00:00

experimented, fixed bugs, implemented basic tty

This commit is contained in:
aap 2016-05-01 00:12:29 +02:00
parent bda85e8902
commit 79ef7a3af8
9 changed files with 283 additions and 38 deletions

View File

@ -1,4 +1,4 @@
SRC=main.c apr.c mem.c io.c
SRC=main.c apr.c mem.c tty.c
# clang
#CFLAGS= -Wno-shift-op-parentheses -Wno-logical-op-parentheses \
# -Wno-bitwise-op-parentheses

49
apr.c
View File

@ -1,5 +1,10 @@
#include "pdp6.h"
#include "inst.h"
#include <unistd.h>
word iobus0, iobus1;
void (*iobusmap[128])(void);
u8 ioreq[128];
#define DBG_AR print("AR: %012llo\n", apr->ar)
#define DBG_MB print("MB: %012llo\n", apr->mb)
@ -7,7 +12,7 @@
#define DBG_MA print("MA: %06o\n", apr->ma)
#define DBG_IR print("IR: %06o\n", apr->ir)
int dotrace = 1;
int dotrace = 0;
int pulsestepping = 0;
Apr apr;
@ -158,7 +163,6 @@ swap(word *a, word *b)
#define IOT_CONI (apr->ir_iot && apr->io_inst == CONI)
#define IOT_CONSZ (apr->ir_iot && apr->io_inst == CONSZ)
#define IOT_CONSO (apr->ir_iot && apr->io_inst == CONSO)
#define IOT_CONI (apr->ir_iot && apr->io_inst == CONI)
#define IOT_BLK (apr->ir_iot && (apr->io_inst == BLKI || apr->io_inst == BLKO))
#define IOT_OUTGOING (apr->ir_iot && (apr->io_inst == DATAO || apr->io_inst == CONO))
#define IOT_STATUS (apr->ir_iot && \
@ -172,7 +176,7 @@ decodeir(Apr *apr)
apr->io_inst = apr->ir & 0700340;
// 5-7
iobus1 &= ~037777000000;
iobus1 &= ~037777000000LL;
iobus1 |= apr->ir & H3 ? IOBUS_IOS3_1 : IOBUS_IOS3_0;
iobus1 |= apr->ir & H4 ? IOBUS_IOS4_1 : IOBUS_IOS4_0;
iobus1 |= apr->ir & H5 ? IOBUS_IOS5_1 : IOBUS_IOS5_0;
@ -253,7 +257,7 @@ void
ar_cry(Apr *apr)
{
// 6-10
apr->ar_cry0_xor_cry1 = AR_OV_SET && ~MEMAC;
apr->ar_cry0_xor_cry1 = AR_OV_SET && !MEMAC;
}
void
@ -341,7 +345,7 @@ recalc_req(void)
req = 0;
for(i = 0; i < 128; i++)
req |= ioreq[i];
iobus1 = iobus1&~0177 | req&0177;
iobus1 = iobus1&~0177LL | req&0177;
}
void
@ -421,7 +425,7 @@ relocate(Apr *apr)
apr->rla += apr->rlr;
// 7-2, 7-10
membus0 &= ~0007777777761;
membus0 &= ~0007777777761LL;
membus0 |= ma_fmc_select ? MEMBUS_MA_FMC_SEL1 : MEMBUS_MA_FMC_SEL0;
membus0 |= (apr->ma&01777) << 4;
membus0 |= ((word)apr->rla&017) << 14;
@ -1699,11 +1703,11 @@ pulse(fpt3){
apr->fe |= apr->sc; // 6-15
apr->sc = 0; // 6-15
// 6-3, 6-4
if(apr->mb & F0) apr->mb |= 0377000000000;
else apr->mb &= ~0377000000000;
if(apr->mb & F0) apr->mb |= 0377000000000LL;
else apr->mb &= ~0377000000000LL;
// 6-9, 6-4
if(apr->ar & F0) apr->ar |= 0377000000000;
else apr->ar &= ~0377000000000;
if(apr->ar & F0) apr->ar |= 0377000000000LL;
else apr->ar &= ~0377000000000LL;
nextpulse(apr, fpt4); // 6-23
}
@ -2076,8 +2080,6 @@ pulse(pi_sync){
nextpulse(apr, iat0); // 5-3
if(IA_NOT_INT)
nextpulse(apr, apr->if1a ? it1 : at1); // 5-3
/* no longer needed */
apr->ia_inh = 0;
}
// 5-1
@ -2411,6 +2413,9 @@ pulse(et1){
if(PI_RST)
clear_pih(apr); // 8-4
// 6-3
if(apr->ir_acbm)
apr->mb &= apr->ar;
// 6-8
if(apr->ir_boole && (apr->ir_boole_op == 06 ||
apr->ir_boole_op == 011 ||
@ -2432,9 +2437,6 @@ pulse(et1){
if(HWT_AR_0 || IOT_STATUS || IOT_DATAI)
apr->ar = 0;
// 6-3
if(apr->ir_acbm)
apr->mb &= ~apr->ar;
if(HWT_SWAP || FWT_SWAP || apr->inst == BLT)
SWAPLTRT(apr->mb);
@ -3056,6 +3058,7 @@ aprmain(void *p)
if(c == 'x')
pulsestepping = 0;
}
//usleep(50000);
for(i = 0; i < apr->ncurpulses; i++)
apr->clist[i](apr);
@ -3071,7 +3074,7 @@ aprmain(void *p)
if(apr->extpulse & 2){
apr->extpulse &= ~2;
apr->run = 0;
// cleared after PI SYNC
// hack: cleared when the pulse list was empty
apr->ia_inh = 1;
}
@ -3097,6 +3100,10 @@ aprmain(void *p)
iobus1 &= ~IOBUS_PULSES;
}
if(iobus1 & IOBUS_IOB_RESET){
int d;
for(d = 0; d < nelem(iobusmap); d++)
if(iobusmap[d])
iobusmap[d]();
iobus1 &= ~IOBUS_IOB_RESET;
}
@ -3124,8 +3131,14 @@ aprmain(void *p)
if(apr->mc_rq && !apr->mc_stop)
nextpulse(apr, mc_non_exist_mem); // 7-9
}
if(i)
print("--------------\n");
if(i){
// wakepanel();
trace("--------------\n");
}else{
/* no longer needed */
apr->ia_inh = 0;
}
}
print("power off\n");
return NULL;

5
io.c
View File

@ -1,5 +0,0 @@
#include "pdp6.h"
word iobus0, iobus1;
void (*iobusmap[128])(void);
u8 ioreq[128];

32
main.c
View File

@ -2,6 +2,8 @@
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <pthread.h>
#include <time.h>
#include <unistd.h>
SDL_Surface *screen;
@ -669,6 +671,18 @@ mouse(int button, int state, int x, int y)
}
}
void
wakepanel(void)
{
SDL_Event user_event;
user_event.type = SDL_USEREVENT;
user_event.user.code = 1;
user_event.user.data1 = NULL;
user_event.user.data2 = NULL;
SDL_PushEvent(&user_event);
}
int
main()
{
@ -804,10 +818,25 @@ error:
rim_maint_sw->r.y += extra_panel.y;
initmem();
inittty();
memset(&apr, 0xff, sizeof apr);
apr.extpulse = 0;
/* int frm = 0;
time_t tm, tm2;
tm = time(nil);*/
for(;;){
/*
frm++;
tm2 = time(nil);
if((tm2 - tm) > 5){
print("fps: %f\n", (float)frm/(tm2-tm));
tm = tm2;
frm = 0;
}
*/
// usleep(1000);
while(SDL_PollEvent(&ev))
switch(ev.type){
case SDL_MOUSEMOTION:
@ -825,6 +854,9 @@ error:
dumpmem();
SDL_Quit();
return 0;
case SDL_USEREVENT:
print("user\n");
break;
}
setlights(apr.ir, ir_lght, 18);
setlights(apr.mi, mi_lght, 36);

36
mem
View File

@ -1,11 +1,25 @@
1000: 200000001011
1001: 150000001012
1002: 254200000000
1003: 202400000000
1004: 576400000000
1005: 201600000000
1006: 576200000000
1007: 204500000000
1010: 573300000000
1011: 204600000000
1012: 203400000000
40: 254200000000
41: 254200000000
1000: 254000001102
1101: 777700001000
1102: 200740001101
1103: 260740001112
1104: 260740001120
1105: 201000000012
1106: 260740001120
1107: 201000000141
1110: 260740001120
1111: 254200000000
1112: 712240000000
1113: 606000000040
1114: 254000001112
1115: 712040000000
1116: 620000000200
1117: 263740000000
1120: 712240000001
1121: 602040000020
1122: 254000001120
1123: 435000000200
1124: 712140000000
1125: 263740000000
1126: 000000000141

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

14
pdp6.h
View File

@ -13,7 +13,8 @@ typedef uint32_t hword;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
typedef char bool;
typedef unsigned char uchar;
typedef uchar bool;
enum Mask {
FW = 0777777777777,
@ -96,7 +97,7 @@ enum {
typedef struct Apr Apr;
typedef void Pulse(Apr *apr);
#define pulse(p) void p(Apr *apr)
#define pulse(p) static void p(Apr *apr)
struct Apr {
hword ir;
@ -143,7 +144,8 @@ struct Apr {
bool cpa_iot_user, cpa_illeg_op, cpa_non_exist_mem,
cpa_clock_enable, cpa_clock_flag, cpa_pc_chg_enable, cpa_pdl_ov,
cpa_arov_enable, cpa_pia;
cpa_arov_enable;
int cpa_pia;
bool iot_go;
@ -270,6 +272,7 @@ enum {
/* 0 is cable 1 & 2 (data); 1 is cable 3 & 4 (above bits) */
extern word iobus0, iobus1;
#define IOB_RESET (iobus1 & IOBUS_IOB_RESET)
#define IOB_DATAO_CLEAR (iobus1 & IOBUS_DATAO_CLEAR)
#define IOB_DATAO_SET (iobus1 & IOBUS_DATAO_SET)
#define IOB_CONO_CLEAR (iobus1 & IOBUS_CONO_CLEAR)
@ -282,3 +285,8 @@ extern word iobus0, iobus1;
extern void (*iobusmap[128])(void);
/* current PI req for each device */
extern u8 ioreq[128];
void recalc_req(void);
void inittty(void);
//void wakepanel(void);

140
tty.c Normal file
View File

@ -0,0 +1,140 @@
#include "pdp6.h"
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <pthread.h>
#include <poll.h>
/*
* This device is not accurately modeled after the schematics.
*/
#define TTY (0120>>2)
typedef struct Tty Tty;
struct Tty
{
uchar tto, tti;
bool tto_busy, tto_flag;
bool tti_busy, tti_flag;
int pia;
int fd;
};
Tty tty;
void
recalc_tty_req(void)
{
u8 req;
req = tty.tto_flag || tty.tti_flag ? tty.pia : 0;
if(req != ioreq[TTY]){
ioreq[TTY] = req;
recalc_req();
}
}
void*
ttythread(void *arg)
{
int sockfd, newsockfd, portno, clilen;
char buf;
struct sockaddr_in serv_addr, cli_addr;
int n;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0){
perror("ERROR opening socket");
exit(1);
}
memset(&serv_addr, 0, sizeof(serv_addr));
portno = 6666;
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(portno);
if(bind(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0){
perror("ERROR on bind");
exit(1);
}
listen(sockfd,5);
clilen = sizeof(cli_addr);
pthread_t thread_id;
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 = buf|0200;
tty.tti_flag = 1;
recalc_tty_req();
}
tty.fd = -1;
close(newsockfd);
}
if(newsockfd < 0){
perror("ERROR on accept");
exit(1);
}
return nil;
}
static void
wake_tty(void)
{
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;
ioreq[TTY] = 0;
}
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(IOB_DATAI)
apr.ar = tty.tti;
if(IOB_CONO_CLEAR)
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(IOB_DATAO_CLEAR)
tty.tto = 0;
if(IOB_DATAO_SET){
tty.tto = iobus0 & 0377;
tty.tto_busy = 1;
if(tty.tto & 0200 && tty.fd >= 0){
tty.tto &= ~0200;
write(tty.fd, &tty.tto, 1);
}
tty.tto_busy = 0;
tty.tto_flag = 1;
}
recalc_tty_req();
}
void
inittty(void)
{
pthread_t thread_id;
tty.fd = -1;
ioreq[TTY] = 0;
pthread_create(&thread_id, nil, ttythread, nil);
iobusmap[TTY] = wake_tty;
}

43
ttytest.s Normal file
View File

@ -0,0 +1,43 @@
P=17
TTY=120
PDLLEN=100
.=40
JRST 4,
JRST 4,
.=1000
ENTRY: JRST START
PDL: .=.+PDLLEN
SP: -PDLLEN,,PDL-1
START:
MOVE P,SP
PUSHJ P,GETCH
PUSHJ P,PUTCHR
MOVEI 0,"\n
PUSHJ P,PUTCHR
MOVEI 0,"a
PUSHJ P,PUTCHR
JRST 4,
GETCH:
CONI TTY,0
TRNN 0,40
JRST .-2
DATAI TTY,0
TRZ 0,200
POPJ P,
PUTCHR:
CONI TTY,1
TRNE 1,20
JRST .-2
IORI 0,200
DATAO TTY,0
POPJ P,
STR:
"a