From de1c0bee6f4cf3f5cb038f052a283c193366553c Mon Sep 17 00:00:00 2001 From: aap Date: Sat, 31 Oct 2015 13:53:44 +0100 Subject: [PATCH] implemented instruction fetch --- Makefile | 9 +++-- apr.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- main.c | 5 ++- mem | 3 +- pdp6.h | 12 ++++-- 5 files changed, 131 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index b00b596..b377ed8 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ -SRC=main.c apr.c mem.c -CFLAGS=-Wno-shift-op-parentheses -Wno-logical-op-parentheses\ - -L/usr/local/lib -I/usr/local/include -lSDL -lSDL_image -lpthread +SRC=main.c apr.c mem.c io.c +CFLAGS= -Wno-shift-op-parentheses -Wno-logical-op-parentheses\ + -Wno-bitwise-op-parentheses\ + -L/usr/local/lib -I/usr/local/include -lSDL -lSDL_image -lpthread + + pdp6: $(SRC) pdp6.h $(CC) $(CFLAGS) $(SRC) -o pdp6 diff --git a/apr.c b/apr.c index 7656711..e13985a 100644 --- a/apr.c +++ b/apr.c @@ -30,6 +30,25 @@ set_pi_cyc(bool value) apr.ex_pi_sync = 1; // 5-13 } +void +set_pir(u8 value) +{ + int chan; + u8 req; + // 8-3 + apr.pir = value; + apr.pi_req = 0; + if(apr.pi_active){ + req = apr.pir & ~apr.pih; + for(chan = 0100; chan; chan >>= 1) + if(req & chan){ + apr.pi_req = chan; + break; + } + } + apr.pi_rq = !!apr.pi_req; // 8-4 +} + void set_mc_rq(bool value) { @@ -66,6 +85,7 @@ set_mc_rd(bool value) void set_key_rim_sbr(bool value) { + // not sure if this is correct apr.key_rim_sbr = value | apr.sw_rim_maint; // 5-2 } @@ -77,12 +97,12 @@ calcaddr(void) // 5-13 apr.ex_inh_rel = !apr.ex_user || apr.ex_pi_sync || - (apr.ma&0777760) == 0 || apr.ex_ill_op; + (apr.ma & 0777760) == 0 || apr.ex_ill_op; // 7-4 ma18_25 = apr.ma>>10 & 0377; ma_ok = ma18_25 <= apr.pr; // 7-2 - ma_fmc_select = !apr.key_rim_sbr && (apr.ma&0777760) == 0; + ma_fmc_select = !apr.key_rim_sbr && (apr.ma & 0777760) == 0; // 7-5 apr.rla = ma18_25; if(!apr.ex_inh_rel) @@ -101,15 +121,19 @@ calcaddr(void) } pulse(kt4); +pulse(it1); +pulse(at1); +pulse(iat0); pulse(mc_wr_rs); +pulse(mc_rd_rq_pulse); -// TODO: find PI REQ, A LONG +// TODO: find A LONG pulse(pi_reset){ printf("PI RESET\n"); apr.pi_active = 0; // 8-4 apr.pih = 0; // 8-4 - apr.pir = 0; // 8-4 + set_pir(0); // 8-4 apr.pio = 0; // 8-3 return NULL; } @@ -141,10 +165,13 @@ pulse(mr_clr){ set_ex_mode_sync(0); // 5-13 apr.ex_uuo_sync = 0; // 5-13 apr.ex_pi_sync = 0; // 5-13 + + apr.a_long = 0; // nowhere to be found :( // TODO: MP CLR, DS CLR /* sbr flip-flops */ apr.key_rd_wr = 0; // 5-2 + apr.if1a = 0; // 5-3 mc_rst1_ret = NULL; return NULL; } @@ -193,9 +220,87 @@ pulse(st7){ return NULL; } +/* + * Priority Interrupt + */ + +pulse(pir_stb){ + printf("PIR STB\n"); + set_pir(apr.pir | apr.pio & iobus1); // 8-3 + return NULL; +} + +pulse(pi_sync){ + printf("PI SYNC\n"); + if(!apr.pi_cyc) + pir_stb(); + // 5-3 + if(apr.pi_rq && !apr.pi_cyc) + return iat0; + // TODO: IA INH/AT INH + if(apr.if1a) + return it1; + return at1; +} + +/* + * Address + */ + +pulse(at1){ + printf("AT1\n"); + return NULL; +} + +pulse(at0){ + printf("AT0\n"); + return NULL; +} + +/* + * Instruction + */ + +pulse(iat0){ + printf("IAT0\n"); + mr_clr(); + set_pi_cyc(1); + return it1; +} + pulse(it1a){ printf("IT1A\n"); - return NULL; + apr.if1a = 0; + apr.ir |= (apr.mb & 0777740000000) >> 18; // 5-7 + if(apr.ma & 0777760) + set_key_rim_sbr(0); // 5-2 + return at0; +} + +pulse(it1){ + printf("IT1\n"); + hword n; + u8 r; + if(apr.pi_cyc){ + // 7-3 + r = apr.pi_req; + for(n = 7; !(r & 1); n--, r >>= 1); + apr.ma = 040 | n<<1; + }else + apr.ma = apr.pc; // 7-3 + if(apr.pi_ov) + apr.ma = (apr.ma+1)&0777777; // 7-3 + apr.if1a = 1; + mc_rst1_ret = it1a; + return mc_rd_rq_pulse; +} + +pulse(it0){ + printf("IT0\n"); + apr.ma = 0; + mr_clr(); + apr.if1a = 1; // 5-3 + return pi_sync; } /* @@ -359,7 +464,7 @@ pulse(key_go){ apr.key_dep_st = 0; apr.key_ex_sync = 0; apr.key_dep_sync = 0; - return NULL; + return it0; } pulse(kt4){ diff --git a/main.c b/main.c index 2581740..f3b4d28 100644 --- a/main.c +++ b/main.c @@ -353,6 +353,8 @@ Light ind_lights[] = { { lampsurf, { 407, 127, 14, 22 }, 0 }, { lampsurf, { 407, 144, 14, 22 }, 0 }, { lampsurf, { 407, 161, 14, 22 }, 0 }, + /* sbr flip-flops */ + { lampsurf, { 99, 42, 14, 22 }, 0 }, }; Light extra_lights[] = { /* MEMBUS */ @@ -828,12 +830,13 @@ error: ff_lght[31].state = apr.cpa_pia35; ff_lght[32].state = apr.pi_ov; ff_lght[33].state = apr.pi_cyc; - ff_lght[34].state = apr.pi_req; + ff_lght[34].state = apr.pi_rq; ff_lght[35].state = apr.iot_go; ff_lght[36].state = apr.a_long; ff_lght[37].state = apr.ma == apr.mas; ff_lght[38].state = apr.uuo_f1; ff_lght[39].state = apr.cpa_pdl_ov; + ff_lght[40].state = apr.if1a; setlights(membus0, membus_lght, 36); setlights(apr.pr, pr_lght, 8); diff --git a/mem b/mem index 1c50af2..5cae503 100644 --- a/mem +++ b/mem @@ -1,5 +1,4 @@ -1234 -4321 +201040001234 0 0 0 diff --git a/pdp6.h b/pdp6.h index 2a1877b..5b37946 100644 --- a/pdp6.h +++ b/pdp6.h @@ -22,10 +22,9 @@ struct Apr { word mb; word ar; word mq; - u8 pio, pir, pih; u16 sc, fe; u8 pr, rlr, rla; - bool run, pi_active; + bool run; bool sw_addr_stop, sw_repeat, sw_mem_disable, sw_power; bool sw_rim_maint; /* keys */ @@ -38,10 +37,14 @@ struct Apr { bool key_rd_off, key_rd_on; bool key_pt_rd, key_pt_wr; + /* PI */ + u8 pio, pir, pih, pi_req; + bool pi_active; + bool pi_ov, pi_cyc, pi_rq; + /* flip-flops */ bool ex_mode_sync, ex_uuo_sync, ex_pi_sync, ex_ill_op, ex_user; bool pc_chg_flag, ar_ov_flag, ar_cry0_flag, ar_cry1_flag; - bool pi_ov, pi_cyc, pi_req; bool key_ex_st, key_ex_sync; bool key_dep_st, key_dep_sync; @@ -59,6 +62,7 @@ struct Apr { bool iot_go, a_long, uuo_f1; /* sbr flip-flops */ + bool if1a; bool chf7; /* temporaries */ @@ -93,3 +97,5 @@ enum { MEMBUS_MAI_ADDR_ACK = 0400000000000, }; extern word membus0, membus1; + +extern word iobus0, iobus1;