From 2c3242fd4d99570256ad5e26daeaf26ab482c722 Mon Sep 17 00:00:00 2001 From: aap Date: Tue, 25 Oct 2016 20:30:28 +0200 Subject: [PATCH] membus pulses; pt thread --- code/main.s | 12 +++++- src/apr.c | 14 +++---- src/main.c | 4 +- src/mem.c | 8 ++-- src/pdp6.h | 3 ++ src/pt.c | 115 ++++++++++++++++++++++++++++------------------------ 6 files changed, 90 insertions(+), 66 deletions(-) diff --git a/code/main.s b/code/main.s index db499df..f58af13 100644 --- a/code/main.s +++ b/code/main.s @@ -3,6 +3,8 @@ AC1==1 AC2==2 PDP==17 +PTP==100 + EXTERNAL PUTC,PUTS EXTERNAL GETCH,GETC @@ -19,10 +21,18 @@ START: PUSHJ PDP,PUTS PUSHJ PDP,GETC - JRST .-1 +; CONO PTP,20 + PUSHJ PDP,PTPUT + JRST .-2 HALT +PTPUT: + CONSZ PTP,20 + JRST .-1 + DATAO PTP,AC1 + POPJ PDP, + MSG: ASCIZ /Hello, world! yo! > / diff --git a/src/apr.c b/src/apr.c index bf69c31..9760a6e 100644 --- a/src/apr.c +++ b/src/apr.c @@ -3061,12 +3061,15 @@ aprmain(void *p) } iobus1_last = iobus1; + membus0_last = membus0; + for(i = 0; i < apr->ncurpulses; i++) apr->clist[i](apr); + /* find out which bits were turned on */ iobus1_pulse = (iobus1_last ^ iobus1) & iobus1; iobus1_pulse &= ~037777000177LL; - + membus0_pulse = (membus0_last ^ membus0) & membus0; /* This is simplified, we have no IOT RESET, * IOT INIT SET UP or IOT FINAL SETUP really. @@ -3112,15 +3115,12 @@ aprmain(void *p) /* Pulses to memory */ - if(membus0 & (MEMBUS_WR_RS | MEMBUS_RQ_CYC)){ + if(membus0_pulse & (MEMBUS_WR_RS | MEMBUS_RQ_CYC)){ wakemem(); - /* Normally this should still be asserted but it - * is interpreted as a pulse every loop iteration here. - * Clearing it is a hack */ - membus0 &= ~MEMBUS_RQ_CYC; + membus0 &= ~MEMBUS_WR_RS; } - /* Pulses from memory */ + /* Pulses from memory */ if(membus0 & MEMBUS_MAI_ADDR_ACK){ membus0 &= ~MEMBUS_MAI_ADDR_ACK; apr->extpulse &= ~EXT_NONEXIT_MEM; diff --git a/src/main.c b/src/main.c index d6e7d1c..00b4a7a 100644 --- a/src/main.c +++ b/src/main.c @@ -79,7 +79,7 @@ mustloadimg(const char *path) { SDL_Surface *s; s = IMG_Load(path); - if(s == NULL) + if(s == nil) err("Couldn't load %s", path); return s; } @@ -146,7 +146,7 @@ poweron(void) { pthread_t apr_thread; apr.sw_power = 1; - pthread_create(&apr_thread, NULL, aprmain, &apr); + pthread_create(&apr_thread, nil, aprmain, &apr); } #define KEYPULSE(k) (apr.k && !oldapr.k) diff --git a/src/mem.c b/src/mem.c index 4418110..078665e 100644 --- a/src/mem.c +++ b/src/mem.c @@ -6,6 +6,7 @@ word memory[256*1024]; hword maxmem = 64*1024; word fmem[16]; word membus0, membus1; +word membus0_last, membus0_pulse; word *hold; void @@ -71,7 +72,7 @@ void wakemem(void) { hword a; - if(membus0 & MEMBUS_RQ_CYC){ + if(membus0_pulse & MEMBUS_RQ_CYC){ a = membus0>>4 & 037777; if(membus0 & MEMBUS_MA21_1) a |= 0040000; if(membus0 & MEMBUS_MA20_1) a |= 0100000; @@ -87,12 +88,11 @@ wakemem(void) membus1 = *hold & FW; membus0 |= MEMBUS_MAI_RD_RS; if(!(membus0 & MEMBUS_WR_RQ)) - hold = NULL; + hold = nil; } } if(membus0 & MEMBUS_WR_RS && hold){ *hold = membus1 & FW; - membus0 &= ~MEMBUS_WR_RS; - hold = NULL; + hold = nil; } } diff --git a/src/pdp6.h b/src/pdp6.h index 124ba58..05edf73 100644 --- a/src/pdp6.h +++ b/src/pdp6.h @@ -246,6 +246,9 @@ enum { }; /* 0 is cable 1 & 2 (above bits); 1 is cable 3 & 4 (data) */ extern word membus0, membus1; +/* record the state of membus0 of the last pulse step + * to recognize pulses or edges */ +extern word membus0_last, membus0_pulse; // 7-10 enum { diff --git a/src/pt.c b/src/pt.c index b858122..75e0c35 100644 --- a/src/pt.c +++ b/src/pt.c @@ -7,6 +7,8 @@ #include #include +/* TODO? implement motor delays */ + Ptp ptp; Ptr ptr; @@ -21,54 +23,6 @@ recalc_ptp_req(void) } } -static void -wake_ptp(void) -{ - if(IOB_RESET){ - ptp.pia = 0; - ptp.busy = 0; - ptp.flag = 0; - ptp.b = 0; - } - if(iodev == PTP){ - if(IOB_STATUS){ - if(ptp.b) iobus0 |= F30; - if(ptp.busy) iobus0 |= F31; - if(ptp.flag) iobus0 |= F32; - iobus0 |= ptp.pia & 7; - } - if(IOB_CONO_SET){ - if(iobus0 & F30) ptp.b = 1; - if(iobus0 & F31) ptp.busy = 1; - if(iobus0 & F32) ptp.flag = 1; - ptp.pia |= iobus0 & 7; - } - if(IOB_CONO_CLEAR){ - ptp.pia = 0; - ptp.busy = 0; - ptp.flag = 0; - ptp.b = 0; - } - if(IOB_DATAO_CLEAR){ - ptp.ptp = 0; - ptp.busy = 1; - ptp.flag = 0; - } - if(IOB_DATAO_SET){ - ptp.ptp = iobus0 & 0377; - if(ptp.fp){ - if(ptp.b) - putc((ptp.ptp & 077) | 0200, ptp.fp); - else - putc(ptp.ptp, ptp.fp); - } - ptp.busy = 0; - ptp.flag = 1; - } - } - recalc_ptp_req(); -} - void recalc_ptr_req(void) { @@ -80,16 +34,32 @@ recalc_ptr_req(void) } } +/* We have to punch after DATAO SET has happened. But BUSY is set by + * DATAO CLEAR. So we use this to record when SET has happened */ +int waitdatao; + void* -ptrthread(void *arg) +ptthread(void *arg) { int c; for(;;){ + if(ptp.busy && waitdatao){ + if(ptp.fp){ + if(ptp.b) + putc((ptp.ptp & 077) | 0200, ptp.fp); + else + putc(ptp.ptp, ptp.fp); + fflush(ptp.fp); + } + ptp.busy = 0; + ptp.flag = 1; + recalc_ptp_req(); + } + if(ptr.busy && ptr.motor_on){ // PTR CLR ptr.sr = 0; ptr.ptr = 0; - next: if(ptr.fp) c = getc(ptr.fp); @@ -117,6 +87,48 @@ ptrthread(void *arg) return nil; } +static void +wake_ptp(void) +{ + if(IOB_RESET){ + ptp.pia = 0; + ptp.busy = 0; + ptp.flag = 0; + ptp.b = 0; + } + if(iodev == PTP){ + if(IOB_STATUS){ + if(ptp.b) iobus0 |= F30; + if(ptp.busy) iobus0 |= F31; + if(ptp.flag) iobus0 |= F32; + iobus0 |= ptp.pia & 7; + } + if(IOB_CONO_CLEAR){ + ptp.pia = 0; + ptp.busy = 0; + ptp.flag = 0; + ptp.b = 0; + } + if(IOB_CONO_SET){ + if(iobus0 & F30) ptp.b = 1; + if(iobus0 & F31) ptp.busy = 1; + if(iobus0 & F32) ptp.flag = 1; + ptp.pia |= iobus0 & 7; + } + if(IOB_DATAO_CLEAR){ + ptp.ptp = 0; + ptp.busy = 1; + ptp.flag = 0; + waitdatao = 0; + } + if(IOB_DATAO_SET){ + ptp.ptp = iobus0 & 0377; + waitdatao = 1; + } + } + recalc_ptp_req(); +} + static void wake_ptr(void) { @@ -137,7 +149,6 @@ wake_ptr(void) } if(IOB_DATAI){ iobus0 |= ptr.ptr; -debug(" PTR: %012lo\n", iobus0); ptr.flag = 0; // actually when DATAI is negated again ptr.busy = 1; @@ -178,7 +189,7 @@ initpt(void) iobusmap[PTP] = wake_ptp; ioreq[PTR] = 0; iobusmap[PTR] = wake_ptr; - pthread_create(&thread_id, nil, ptrthread, nil); + pthread_create(&thread_id, nil, ptthread, nil); ptr.fp = fopen("../code/test.rim", "rb"); ptp.fp = fopen("../code/ptp.out", "wb");