From 3b09b5f613ae931c9db19b95e4cd4361f998ec0e Mon Sep 17 00:00:00 2001 From: aap Date: Wed, 26 Oct 2016 16:44:59 +0200 Subject: [PATCH] started modularizing the code somewhat --- src/apr.c | 115 ++++++++-------- src/main.c | 392 ++++++++++++++++++++++++++++------------------------- src/pdp6.h | 79 ++++++----- src/pt.c | 231 +++++++++++++++++-------------- src/tty.c | 112 +++++++-------- 5 files changed, 491 insertions(+), 438 deletions(-) diff --git a/src/apr.c b/src/apr.c index 9760a6e..8066ea2 100644 --- a/src/apr.c +++ b/src/apr.c @@ -4,8 +4,6 @@ word iobus0, iobus1; word iobus1_last, iobus1_pulse; int iodev; -void (*iobusmap[128])(void); -u8 ioreq[128]; #define DBG_AR debug("AR: %012llo\n", apr->ar) #define DBG_MB debug("MB: %012llo\n", apr->mb) @@ -333,7 +331,7 @@ recalc_req(void) int req; req = 0; for(i = 0; i < 128; i++) - req |= ioreq[i]; + req |= iobus[i].pireq; iobus1 = iobus1&~0177LL | req&0177; } @@ -347,8 +345,8 @@ recalc_cpa_req(Apr *apr) apr->ar_pc_chg_flag && apr->cpa_pc_chg_enable || apr->ar_ov_flag && apr->cpa_arov_enable) req = apr->cpa_pia; - if(ioreq[CPA] != req){ - ioreq[CPA] = req; + if(iobus[CPA].pireq != req){ + iobus[CPA].pireq = req; recalc_req(); } } @@ -637,7 +635,7 @@ pulse(mr_start){ apr->cpa_pdl_ov = 0; apr->cpa_arov_enable = 0; apr->cpa_pia = 0; - ioreq[CPA] = 0; + iobus[CPA].pireq = 0; // PI apr->pi_ov = 0; // 8-4 @@ -664,64 +662,69 @@ pulse(mr_pwr_clr){ /* CPA and PI devices */ void -wake_cpa(void) +wake_cpa(void *dev) { + Apr *apr; + + apr = dev; if(iodev != CPA) return; // 8-5 if(IOB_STATUS){ - if(apr.cpa_pdl_ov) iobus0 |= F19; - if(apr.cpa_iot_user) iobus0 |= F20; - if(apr.ex_user) iobus0 |= F21; - if(apr.cpa_illeg_op) iobus0 |= F22; - if(apr.cpa_non_exist_mem) iobus0 |= F23; - if(apr.cpa_clock_enable) iobus0 |= F25; - if(apr.cpa_clock_flag) iobus0 |= F26; - if(apr.cpa_pc_chg_enable) iobus0 |= F28; - if(apr.ar_pc_chg_flag) iobus0 |= F29; - if(apr.cpa_arov_enable) iobus0 |= F31; - if(apr.ar_ov_flag) iobus0 |= F32; - iobus0 |= apr.cpa_pia & 7; + if(apr->cpa_pdl_ov) iobus0 |= F19; + if(apr->cpa_iot_user) iobus0 |= F20; + if(apr->ex_user) iobus0 |= F21; + if(apr->cpa_illeg_op) iobus0 |= F22; + if(apr->cpa_non_exist_mem) iobus0 |= F23; + if(apr->cpa_clock_enable) iobus0 |= F25; + if(apr->cpa_clock_flag) iobus0 |= F26; + if(apr->cpa_pc_chg_enable) iobus0 |= F28; + if(apr->ar_pc_chg_flag) iobus0 |= F29; + if(apr->cpa_arov_enable) iobus0 |= F31; + if(apr->ar_ov_flag) iobus0 |= F32; + iobus0 |= apr->cpa_pia & 7; } if(IOB_CONO_SET){ - if(iobus0 & F18) apr.cpa_pdl_ov = 0; + if(iobus0 & F18) apr->cpa_pdl_ov = 0; if(iobus0 & F19) iobus1 |= IOBUS_IOB_RESET; // 8-1 - if(iobus0 & F22) apr.cpa_illeg_op = 0; - if(iobus0 & F23) apr.cpa_non_exist_mem = 0; - if(iobus0 & F24) apr.cpa_clock_enable = 0; - if(iobus0 & F25) apr.cpa_clock_enable = 1; - if(iobus0 & F26) apr.cpa_clock_flag = 0; - if(iobus0 & F27) apr.cpa_pc_chg_enable = 0; - if(iobus0 & F28) apr.cpa_pc_chg_enable = 1; - if(iobus0 & F29) apr.ar_pc_chg_flag = 0; // 6-10 - if(iobus0 & F30) apr.cpa_arov_enable = 0; - if(iobus0 & F31) apr.cpa_arov_enable = 1; - if(iobus0 & F32) apr.ar_ov_flag = 0; // 6-10 - apr.cpa_pia = iobus0 & 7; - recalc_cpa_req(&apr); + if(iobus0 & F22) apr->cpa_illeg_op = 0; + if(iobus0 & F23) apr->cpa_non_exist_mem = 0; + if(iobus0 & F24) apr->cpa_clock_enable = 0; + if(iobus0 & F25) apr->cpa_clock_enable = 1; + if(iobus0 & F26) apr->cpa_clock_flag = 0; + if(iobus0 & F27) apr->cpa_pc_chg_enable = 0; + if(iobus0 & F28) apr->cpa_pc_chg_enable = 1; + if(iobus0 & F29) apr->ar_pc_chg_flag = 0; // 6-10 + if(iobus0 & F30) apr->cpa_arov_enable = 0; + if(iobus0 & F31) apr->cpa_arov_enable = 1; + if(iobus0 & F32) apr->ar_ov_flag = 0; // 6-10 + apr->cpa_pia = iobus0 & 7; + recalc_cpa_req(apr); } // 5-2 if(IOB_DATAI) - apr.ar = apr.data; + apr->ar = apr->data; // 5-13 if(IOB_DATAO_CLEAR) - ex_clr(&apr); + ex_clr(apr); if(IOB_DATAO_SET) - ex_set(&apr); + ex_set(apr); } void -wake_pi(void) +wake_pi(void *dev) { + Apr *apr; + + apr = dev; if(iodev != PI) return; - // 8-4, 8-5 if(IOB_STATUS){ trace("PI STATUS %llo\n", iobus0); - if(apr.pi_active) iobus0 |= F28; - iobus0 |= apr.pio; + if(apr->pi_active) iobus0 |= F28; + iobus0 |= apr->pio; } // 8-4, 8-3 @@ -729,20 +732,20 @@ wake_pi(void) trace("PI CONO CLEAR %llo\n", iobus0); if(iobus0 & F23) // can call directly - pi_reset(&apr); + pi_reset(apr); } if(IOB_CONO_SET){ trace("PI CONO SET %llo\n", iobus0); if(iobus0 & F24) - set_pir(&apr, apr.pir | iobus0&0177); + set_pir(apr, apr->pir | iobus0&0177); if(iobus0 & F25) - apr.pio |= iobus0&0177; + apr->pio |= iobus0&0177; if(iobus0 & F26) - apr.pio &= ~(iobus0&0177); + apr->pio &= ~(iobus0&0177); if(iobus0 & F27) - apr.pi_active = 0; + apr->pi_active = 0; if(iobus0 & F28) - apr.pi_active = 1; + apr->pi_active = 1; } } @@ -3024,16 +3027,17 @@ nextpulse(Apr *apr, Pulse *p) } void -initapr(void) +initapr(Apr *apr) { - iobusmap[CPA] = wake_cpa; - iobusmap[PI] = wake_pi; + iobus[CPA] = (Busdev){ apr, wake_cpa, 0 }; + iobus[PI] = (Busdev){ apr, wake_pi, 0 }; } void* aprmain(void *p) { Apr *apr; + Busdev *dev; Pulse **tmp; int i; @@ -3102,14 +3106,17 @@ aprmain(void *p) if(iobus1 & IOBUS_IOS7_1) iodev |= 0004; if(iobus1 & IOBUS_IOS8_1) iodev |= 0002; if(iobus1 & IOBUS_IOS9_1) iodev |= 0001; - if(iobusmap[iodev]) - iobusmap[iodev](); + dev = &iobus[iodev]; + if(dev->wake) + dev->wake(dev->dev); } if(iobus1_pulse & IOBUS_IOB_RESET){ int d; - for(d = 0; d < nelem(iobusmap); d++) - if(iobusmap[d]) - iobusmap[d](); + for(d = 0; d < nelem(iobus); d++){ + dev = &iobus[d]; + if(dev->wake) + dev->wake(dev->dev); + } } iobus1 &= ~(IOBUS_PULSES | IOBUS_IOB_RESET); diff --git a/src/main.c b/src/main.c index 00b4a7a..bd62777 100644 --- a/src/main.c +++ b/src/main.c @@ -5,6 +5,8 @@ #include #include "args.h" +Busdev iobus[128]; + typedef struct Point Point; struct Point { @@ -142,222 +144,230 @@ getswitches(Element *sw, int n) } void -poweron(void) +poweron(Apr *apr) { pthread_t apr_thread; - apr.sw_power = 1; - pthread_create(&apr_thread, nil, aprmain, &apr); + apr->sw_power = 1; + pthread_create(&apr_thread, nil, aprmain, apr); } -#define KEYPULSE(k) (apr.k && !oldapr.k) +#define KEYPULSE(k) (apr->k && !oldapr.k) void -update(void) +updateapr(Apr *apr, Ptr *ptr) { Apr oldapr; - oldapr = apr; - setlights(apr.ir, ir_l, 18); - setlights(apr.mi, mi_l, 36); - setlights(apr.pc, pc_l, 18); - setlights(apr.ma, ma_l, 18); - setlights(apr.pih, pih_l, 7); - setlights(apr.pir, pir_l, 7); - setlights(apr.pio, pio_l, 7); - misc_l[0].state = apr.pi_active; - misc_l[1].state = apr.mc_stop; - misc_l[2].state = apr.run; - misc_l[3].state = apr.sw_repeat = misc_sw[0].state; - misc_l[4].state = apr.sw_addr_stop = misc_sw[1].state; - misc_l[5].state = apr.sw_power = misc_sw[2].state; - if(apr.sw_power && !oldapr.sw_power) - poweron(); - misc_l[6].state = apr.sw_mem_disable = misc_sw[3].state; - apr.data = getswitches(data_sw, 36); - apr.mas = getswitches(ma_sw, 18); + oldapr = *apr; + setlights(apr->ir, ir_l, 18); + setlights(apr->mi, mi_l, 36); + setlights(apr->pc, pc_l, 18); + setlights(apr->ma, ma_l, 18); + setlights(apr->pih, pih_l, 7); + setlights(apr->pir, pir_l, 7); + setlights(apr->pio, pio_l, 7); + misc_l[0].state = apr->pi_active; + misc_l[1].state = apr->mc_stop; + misc_l[2].state = apr->run; + misc_l[3].state = apr->sw_repeat = misc_sw[0].state; + misc_l[4].state = apr->sw_addr_stop = misc_sw[1].state; + misc_l[5].state = apr->sw_power = misc_sw[2].state; + if(apr->sw_power && !oldapr.sw_power) + poweron(apr); + misc_l[6].state = apr->sw_mem_disable = misc_sw[3].state; + apr->data = getswitches(data_sw, 36); + apr->mas = getswitches(ma_sw, 18); - apr.sw_rim_maint = extra_sw[0].state; - if(apr.sw_rim_maint) - apr.key_rim_sbr = 1; - apr.sw_rpt_bypass = extra_sw[1].state; - apr.sw_art3_maint = extra_sw[2].state; - apr.sw_sct_maint = extra_sw[3].state; - apr.sw_spltcyc_override = extra_sw[4].state; + apr->sw_rim_maint = extra_sw[0].state; + if(apr->sw_rim_maint) + apr->key_rim_sbr = 1; + apr->sw_rpt_bypass = extra_sw[1].state; + apr->sw_art3_maint = extra_sw[2].state; + apr->sw_sct_maint = extra_sw[3].state; + apr->sw_spltcyc_override = extra_sw[4].state; - apr.key_start = keys[0].state == 1; - apr.key_readin = keys[0].state == 2; - apr.key_inst_cont = keys[1].state == 1; - apr.key_mem_cont = keys[1].state == 2; - apr.key_inst_stop = keys[2].state == 1; - apr.key_mem_stop = keys[2].state == 2; - apr.key_io_reset = keys[3].state == 1; - apr.key_exec = keys[3].state == 2; - apr.key_dep = keys[4].state == 1; - apr.key_dep_nxt = keys[4].state == 2; - apr.key_ex = keys[5].state == 1; - apr.key_ex_nxt = keys[5].state == 2; - apr.key_rd_off = keys[6].state == 1; - apr.key_rd_on = keys[6].state == 2; - apr.key_pt_rd = keys[7].state == 1; - apr.key_pt_wr = keys[7].state == 2; - if(apr.sw_power){ + apr->key_start = keys[0].state == 1; + apr->key_readin = keys[0].state == 2; + apr->key_inst_cont = keys[1].state == 1; + apr->key_mem_cont = keys[1].state == 2; + apr->key_inst_stop = keys[2].state == 1; + apr->key_mem_stop = keys[2].state == 2; + apr->key_io_reset = keys[3].state == 1; + apr->key_exec = keys[3].state == 2; + apr->key_dep = keys[4].state == 1; + apr->key_dep_nxt = keys[4].state == 2; + apr->key_ex = keys[5].state == 1; + apr->key_ex_nxt = keys[5].state == 2; + apr->key_rd_off = keys[6].state == 1; + apr->key_rd_on = keys[6].state == 2; + apr->key_pt_rd = keys[7].state == 1; + apr->key_pt_wr = keys[7].state == 2; + if(apr->sw_power){ if(KEYPULSE(key_start) || KEYPULSE(key_readin) || KEYPULSE(key_inst_cont) || KEYPULSE(key_mem_cont) || KEYPULSE(key_io_reset) || KEYPULSE(key_exec) || KEYPULSE(key_dep) || KEYPULSE(key_dep_nxt) || KEYPULSE(key_ex) || KEYPULSE(key_ex_nxt)) - apr.extpulse |= EXT_KEY_MANUAL; + apr->extpulse |= EXT_KEY_MANUAL; if(KEYPULSE(key_inst_stop)) - apr.extpulse |= EXT_KEY_INST_STOP; - if(KEYPULSE(key_rd_on)) - ptr_setmotor(1); - if(KEYPULSE(key_rd_off)) - ptr_setmotor(0); + apr->extpulse |= EXT_KEY_INST_STOP; + if(ptr){ + if(KEYPULSE(key_rd_on)) + ptr_setmotor(ptr, 1); + if(KEYPULSE(key_rd_off)) + ptr_setmotor(ptr, 0); + } } - setlights(apr.mb, mb_l, 36); - setlights(apr.ar, ar_l, 36); - setlights(apr.mq, mq_l, 36); + setlights(apr->mb, mb_l, 36); + setlights(apr->ar, ar_l, 36); + setlights(apr->mq, mq_l, 36); - ff_l[0].state = apr.key_ex_st; - ff_l[1].state = apr.key_ex_sync; - ff_l[2].state = apr.key_dep_st; - ff_l[3].state = apr.key_dep_sync; - ff_l[4].state = apr.key_rd_wr; - ff_l[5].state = apr.mc_rd; - ff_l[6].state = apr.mc_wr; - ff_l[7].state = apr.mc_rq; + ff_l[0].state = apr->key_ex_st; + ff_l[1].state = apr->key_ex_sync; + ff_l[2].state = apr->key_dep_st; + ff_l[3].state = apr->key_dep_sync; + ff_l[4].state = apr->key_rd_wr; + ff_l[5].state = apr->mc_rd; + ff_l[6].state = apr->mc_wr; + ff_l[7].state = apr->mc_rq; - ff_l[8].state = apr.if1a; - ff_l[9].state = apr.af0; - ff_l[10].state = apr.af3; - ff_l[11].state = apr.af3a; - ff_l[12].state = apr.et4_ar_pse; - ff_l[13].state = apr.f1a; - ff_l[14].state = apr.f4a; - ff_l[15].state = apr.f6a; + ff_l[8].state = apr->if1a; + ff_l[9].state = apr->af0; + ff_l[10].state = apr->af3; + ff_l[11].state = apr->af3a; + ff_l[12].state = apr->et4_ar_pse; + ff_l[13].state = apr->f1a; + ff_l[14].state = apr->f4a; + ff_l[15].state = apr->f6a; - ff_l[16].state = apr.sf3; - ff_l[17].state = apr.sf5a; - ff_l[18].state = apr.sf7; - ff_l[19].state = apr.ar_com_cont; - ff_l[20].state = apr.blt_f0a; - ff_l[21].state = apr.blt_f3a; - ff_l[22].state = apr.blt_f5a; - ff_l[23].state = apr.iot_f0a; + ff_l[16].state = apr->sf3; + ff_l[17].state = apr->sf5a; + ff_l[18].state = apr->sf7; + ff_l[19].state = apr->ar_com_cont; + ff_l[20].state = apr->blt_f0a; + ff_l[21].state = apr->blt_f3a; + ff_l[22].state = apr->blt_f5a; + ff_l[23].state = apr->iot_f0a; - ff_l[24].state = apr.fpf1; - ff_l[25].state = apr.fpf2; - ff_l[26].state = apr.faf1; - ff_l[27].state = apr.faf2; - ff_l[28].state = apr.faf3; - ff_l[29].state = apr.faf4; - ff_l[30].state = apr.fmf1; - ff_l[31].state = apr.fmf2; + ff_l[24].state = apr->fpf1; + ff_l[25].state = apr->fpf2; + ff_l[26].state = apr->faf1; + ff_l[27].state = apr->faf2; + ff_l[28].state = apr->faf3; + ff_l[29].state = apr->faf4; + ff_l[30].state = apr->fmf1; + ff_l[31].state = apr->fmf2; - ff_l[32].state = apr.fdf1; - ff_l[33].state = apr.fdf2; - ff_l[34].state = apr.ir & H6 && apr.mq & F1 && !apr.nrf3; - ff_l[35].state = apr.nrf1; - ff_l[36].state = apr.nrf2; - ff_l[37].state = apr.nrf3; - ff_l[38].state = apr.fsf1; - ff_l[39].state = apr.chf7; + ff_l[32].state = apr->fdf1; + ff_l[33].state = apr->fdf2; + ff_l[34].state = apr->ir & H6 && apr->mq & F1 && !apr->nrf3; + ff_l[35].state = apr->nrf1; + ff_l[36].state = apr->nrf2; + ff_l[37].state = apr->nrf3; + ff_l[38].state = apr->fsf1; + ff_l[39].state = apr->chf7; - ff_l[40].state = apr.dsf1; - ff_l[41].state = apr.dsf2; - ff_l[42].state = apr.dsf3; - ff_l[43].state = apr.dsf4; - ff_l[44].state = apr.dsf5; - ff_l[45].state = apr.dsf6; - ff_l[46].state = apr.dsf7; - ff_l[47].state = apr.dsf8; + ff_l[40].state = apr->dsf1; + ff_l[41].state = apr->dsf2; + ff_l[42].state = apr->dsf3; + ff_l[43].state = apr->dsf4; + ff_l[44].state = apr->dsf5; + ff_l[45].state = apr->dsf6; + ff_l[46].state = apr->dsf7; + ff_l[47].state = apr->dsf8; - ff_l[48].state = apr.dsf9; - ff_l[49].state = apr.msf1; - ff_l[50].state = apr.mpf1; - ff_l[51].state = apr.mpf2; - ff_l[52].state = apr.mc_split_cyc_sync; - ff_l[53].state = apr.mc_stop_sync; - ff_l[54].state = apr.shf1; - ff_l[55].state = apr.sc == 0777; + ff_l[48].state = apr->dsf9; + ff_l[49].state = apr->msf1; + ff_l[50].state = apr->mpf1; + ff_l[51].state = apr->mpf2; + ff_l[52].state = apr->mc_split_cyc_sync; + ff_l[53].state = apr->mc_stop_sync; + ff_l[54].state = apr->shf1; + ff_l[55].state = apr->sc == 0777; - ff_l[56].state = apr.chf1; - ff_l[57].state = apr.chf2; - ff_l[58].state = apr.chf3; - ff_l[59].state = apr.chf4; - ff_l[60].state = apr.chf5; - ff_l[61].state = apr.chf6; - ff_l[62].state = apr.lcf1; - ff_l[63].state = apr.dcf1; + ff_l[56].state = apr->chf1; + ff_l[57].state = apr->chf2; + ff_l[58].state = apr->chf3; + ff_l[59].state = apr->chf4; + ff_l[60].state = apr->chf5; + ff_l[61].state = apr->chf6; + ff_l[62].state = apr->lcf1; + ff_l[63].state = apr->dcf1; - ff_l[64].state = apr.pi_ov; - ff_l[65].state = apr.pi_cyc; - ff_l[66].state = !!apr.pi_req; - ff_l[67].state = apr.iot_go; - ff_l[68].state = apr.a_long; - ff_l[69].state = apr.ma == apr.mas; - ff_l[70].state = apr.uuo_f1; - ff_l[71].state = apr.cpa_pdl_ov; + ff_l[64].state = apr->pi_ov; + ff_l[65].state = apr->pi_cyc; + ff_l[66].state = !!apr->pi_req; + ff_l[67].state = apr->iot_go; + ff_l[68].state = apr->a_long; + ff_l[69].state = apr->ma == apr->mas; + ff_l[70].state = apr->uuo_f1; + ff_l[71].state = apr->cpa_pdl_ov; - setlights(apr.fe, &ff_l[72], 8); + setlights(apr->fe, &ff_l[72], 8); - setlights(apr.sc, &ff_l[80], 8); + setlights(apr->sc, &ff_l[80], 8); - ff_l[88].state = !apr.ex_user; - ff_l[89].state = apr.cpa_illeg_op; - ff_l[90].state = apr.ex_ill_op; - ff_l[91].state = apr.ex_uuo_sync; - ff_l[92].state = apr.ex_pi_sync; - ff_l[93].state = apr.mq36; - ff_l[94].state = !!(apr.sc & 0400); - ff_l[95].state = !!(apr.fe & 0400); + ff_l[88].state = !apr->ex_user; + ff_l[89].state = apr->cpa_illeg_op; + ff_l[90].state = apr->ex_ill_op; + ff_l[91].state = apr->ex_uuo_sync; + ff_l[92].state = apr->ex_pi_sync; + ff_l[93].state = apr->mq36; + ff_l[94].state = !!(apr->sc & 0400); + ff_l[95].state = !!(apr->fe & 0400); - ff_l[96].state = apr.key_rim_sbr; - ff_l[97].state = apr.ar_cry0_xor_cry1; - ff_l[98].state = apr.ar_cry0; - ff_l[99].state = apr.ar_cry1; - ff_l[100].state = apr.ar_ov_flag; - ff_l[101].state = apr.ar_cry0_flag; - ff_l[102].state = apr.ar_cry1_flag; - ff_l[103].state = apr.ar_pc_chg_flag; + ff_l[96].state = apr->key_rim_sbr; + ff_l[97].state = apr->ar_cry0_xor_cry1; + ff_l[98].state = apr->ar_cry0; + ff_l[99].state = apr->ar_cry1; + ff_l[100].state = apr->ar_ov_flag; + ff_l[101].state = apr->ar_cry0_flag; + ff_l[102].state = apr->ar_cry1_flag; + ff_l[103].state = apr->ar_pc_chg_flag; - ff_l[104].state = apr.cpa_non_exist_mem; - ff_l[105].state = apr.cpa_clock_enable; - ff_l[106].state = apr.cpa_clock_flag; - ff_l[107].state = apr.cpa_pc_chg_enable; - ff_l[108].state = apr.cpa_arov_enable; - ff_l[109].state = !!(apr.cpa_pia&4); - ff_l[110].state = !!(apr.cpa_pia&2); - ff_l[111].state = !!(apr.cpa_pia&1); + ff_l[104].state = apr->cpa_non_exist_mem; + ff_l[105].state = apr->cpa_clock_enable; + ff_l[106].state = apr->cpa_clock_flag; + ff_l[107].state = apr->cpa_pc_chg_enable; + ff_l[108].state = apr->cpa_arov_enable; + ff_l[109].state = !!(apr->cpa_pia&4); + ff_l[110].state = !!(apr->cpa_pia&2); + ff_l[111].state = !!(apr->cpa_pia&1); - setlights(apr.pr, pr_l, 8); - setlights(apr.rlr, rlr_l, 8); - setlights(apr.rla, rla_l, 8); + setlights(apr->pr, pr_l, 8); + setlights(apr->rlr, rlr_l, 8); + setlights(apr->rla, rla_l, 8); setlights(iobus0, iobus_l, 36); +} - ptp_l[0].state = ptp.b; - ptp_l[1].state = ptp.busy; - ptp_l[2].state = ptp.flag; - setlights(ptp.pia, &ptp_l[3], 3); - setlights(ptp.ptp, ptpbuf_l, 8); +void +updatetty(Tty *tty) +{ + tty_l[0].state = tty->tti_busy; + tty_l[1].state = tty->tti_flag; + tty_l[2].state = tty->tto_busy; + tty_l[3].state = tty->tto_flag; + setlights(tty->pia, &tty_l[4], 3); + setlights(tty->tti, ttibuf_l, 8); +} - ptr_l[0].state = ptr.b; - ptr_l[1].state = ptr.busy; - ptr_l[2].state = ptr.flag; - setlights(ptr.pia, &ptr_l[3], 3); - setlights(ptr.ptr, ptrbuf_l, 36); +void +updatept(Ptp *ptp, Ptr *ptr) +{ + ptp_l[0].state = ptp->b; + ptp_l[1].state = ptp->busy; + ptp_l[2].state = ptp->flag; + setlights(ptp->pia, &ptp_l[3], 3); + setlights(ptp->ptp, ptpbuf_l, 8); - tty_l[0].state = tty.tti_busy; - tty_l[1].state = tty.tti_flag; - tty_l[2].state = tty.tto_busy; - tty_l[3].state = tty.tto_flag; - setlights(tty.pia, &tty_l[4], 3); - setlights(tty.tti, ttibuf_l, 8); + ptr_l[0].state = ptr->b; + ptr_l[1].state = ptr->busy; + ptr_l[2].state = ptr->flag; + setlights(ptr->pia, &ptr_l[3], 3); + setlights(ptr->ptr, ptrbuf_l, 36); - setlights(iobus0, iobus_l, 36); - - extra_l[0].state = ptr.motor_on; + extra_l[0].state = ptr->motor_on; } void @@ -428,7 +438,7 @@ drawgrid(Grid *g, SDL_Surface *s, Uint32 col) } void -drawelement(SDL_Surface *screen, Element *elt) +drawelement(SDL_Surface *screen, Element *elt, int power) { SDL_Rect r; Point p; @@ -438,7 +448,7 @@ drawelement(SDL_Surface *screen, Element *elt) r.x = p.x+0.5; r.y = p.y+0.5; if(elt->surf == lampsurf) - s = elt->state && apr.sw_power; + s = elt->state && power; else s = elt->state; SDL_BlitSurface(elt->surf[s], nil, screen, &r); @@ -527,6 +537,11 @@ usage(void) exit(1); } +Apr apr; +Tty tty; +Ptr ptr; +Ptp ptp; + int main(int argc, char *argv[]) { @@ -646,12 +661,11 @@ main(int argc, char *argv[]) extra_l = e; e += 1; - initapr(); + initapr(&apr); initmem(); - inittty(); - initpt(); -// memset(&apr, 0, sizeof apr); -// apr.extpulse = 0; + inittty(&tty); + initptr(&ptr); + initptp(&ptp); for(;;){ start = SDL_GetTicks(); @@ -671,7 +685,9 @@ main(int argc, char *argv[]) return 0; } - update(); + updateapr(&apr, &ptr); + updatetty(&tty); + updatept(&ptp, &ptr); SDL_FillRect(screen, nil, SDL_MapRGBA(screen->format, 0xe6, 0xe6, 0xe6, 0xff)); SDL_BlitSurface(indpanel1.surf, nil, screen, &indpanel1.pos); @@ -681,11 +697,11 @@ main(int argc, char *argv[]) SDL_BlitSurface(oppanel.surf, nil, screen, &oppanel.pos); for(i = 0, e = lamps; i < nelem(lamps); i++, e++) - drawelement(screen, e); + drawelement(screen, e, apr.sw_power); for(i = 0, e = keys; i < nelem(keys); i++, e++) - drawelement(screen, e); + drawelement(screen, e, apr.sw_power); for(i = 0, e = switches; i < nelem(switches); i++, e++) - drawelement(screen, e); + drawelement(screen, e, apr.sw_power); // SDL_LockSurface(screen); // drawgrid(&opgrid1, screen, 0xFFFFFF00); diff --git a/src/pdp6.h b/src/pdp6.h index 05edf73..eda3d92 100644 --- a/src/pdp6.h +++ b/src/pdp6.h @@ -215,7 +215,6 @@ struct Apr { Pulse **clist, **nlist; int ncurpulses, nnextpulses; }; -extern Apr apr; void nextpulse(Apr *apr, Pulse *p); void *aprmain(void *p); @@ -300,23 +299,58 @@ extern int iodev; #define IOB_STATUS (iobus1 & IOBUS_IOB_STATUS) #define IOB_DATAI (iobus1 & IOBUS_IOB_DATAI) -/* every entry is a function to wake up the device */ -/* TODO: how to handle multiple APRs? */ -extern void (*iobusmap[128])(void); -/* current PI req for each device */ -extern u8 ioreq[128]; +typedef struct Busdev Busdev; +struct Busdev +{ + void *dev; + void (*wake)(void *dev); + u8 pireq; +}; + +extern Busdev iobus[128]; void recalc_req(void); /* * Devices */ -void initapr(void); +/* Arithmetic Processor 166 */ #define CPA (0000>>2) #define PI (0004>>2) +void initapr(Apr *apr); -/* TTY */ +/* Paper tape punch 761 */ +#define PTP (0100>>2) +typedef struct Ptp Ptp; +struct Ptp +{ + uchar ptp; + bool busy, flag, b; + int pia; + + FILE *fp; + int waitdatao; +}; +void initptp(Ptp *ptp); + +/* Paper tape reader 760 */ +#define PTR (0104>>2) +typedef struct Ptr Ptr; +struct Ptr +{ + int motor_on; + word sr; + word ptr; + bool busy, flag, b; + int pia; + + FILE *fp; +}; +void initptr(Ptr *ptr); +void ptr_setmotor(Ptr *ptr, int m); + +/* Teletype 626 */ #define TTY (0120>>2) typedef struct Tty Tty; struct Tty @@ -327,34 +361,7 @@ struct Tty int pia; int fd; }; -extern Tty tty; -void inittty(void); - -/* Paper tape */ -#define PTP (0100>>2) -typedef struct Ptp Ptp; -struct Ptp -{ - FILE *fp; - uchar ptp; - bool busy, flag, b; - int pia; -}; -#define PTR (0104>>2) -typedef struct Ptr Ptr; -struct Ptr -{ - FILE *fp; - int motor_on; - word sr; - word ptr; - bool busy, flag, b; - int pia; -}; -extern Ptp ptp; -extern Ptr ptr; -void initpt(void); -void ptr_setmotor(int m); +void inittty(Tty *tty); diff --git a/src/pt.c b/src/pt.c index 75e0c35..5a930aa 100644 --- a/src/pt.c +++ b/src/pt.c @@ -9,188 +9,209 @@ /* TODO? implement motor delays */ -Ptp ptp; -Ptr ptr; - void -recalc_ptp_req(void) +recalc_ptp_req(Ptp *ptp) { u8 req; - req = ptp.flag ? ptp.pia : 0; - if(req != ioreq[PTP]){ - ioreq[PTP] = req; + req = ptp->flag ? ptp->pia : 0; + if(req != iobus[PTP].pireq){ + iobus[PTP].pireq = req; recalc_req(); } } void -recalc_ptr_req(void) +recalc_ptr_req(Ptr *ptr) { u8 req; - req = ptr.flag ? ptr.pia : 0; - if(req != ioreq[PTR]){ - ioreq[PTR] = req; + req = ptr->flag ? ptr->pia : 0; + if(req != iobus[PTR].pireq){ + iobus[PTR].pireq = req; recalc_req(); } } /* 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; + * DATAO CLEAR. So we use waitdatao to record when SET has happened */ void* -ptthread(void *arg) +ptpthread(void *dev) { - 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(); - } + Ptp *ptp; - if(ptr.busy && ptr.motor_on){ + ptp = dev; + for(;;){ + if(ptp->busy && ptp->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(ptp); + } + } + return nil; +} + +void* +ptrthread(void *dev) +{ + Ptr *ptr; + int c; + + ptr = dev; + for(;;){ + if(ptr->busy && ptr->motor_on){ // PTR CLR - ptr.sr = 0; - ptr.ptr = 0; + ptr->sr = 0; + ptr->ptr = 0; next: - if(ptr.fp) - c = getc(ptr.fp); + if(ptr->fp) + c = getc(ptr->fp); else c = 0; if(c == EOF) c = 0; - if(!ptr.b || c & 0200){ + if(!ptr->b || c & 0200){ // PTR STROBE - ptr.sr <<= 1; - ptr.ptr <<= 6; - ptr.sr |= 1; - ptr.ptr |= c & 077; - if(!ptr.b) - ptr.ptr |= c & 0300; + ptr->sr <<= 1; + ptr->ptr <<= 6; + ptr->sr |= 1; + ptr->ptr |= c & 077; + if(!ptr->b) + ptr->ptr |= c & 0300; } - if(!ptr.b || ptr.sr & 040){ - ptr.busy = 0; - ptr.flag = 1; + if(!ptr->b || ptr->sr & 040){ + ptr->busy = 0; + ptr->flag = 1; }else goto next; - recalc_ptr_req(); + recalc_ptr_req(ptr); } } return nil; } static void -wake_ptp(void) +wake_ptp(void *dev) { + Ptp *ptp; + + ptp = dev; if(IOB_RESET){ - ptp.pia = 0; - ptp.busy = 0; - ptp.flag = 0; - ptp.b = 0; + 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(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; + 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(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; + ptp->ptp = 0; + ptp->busy = 1; + ptp->flag = 0; + ptp->waitdatao = 0; } if(IOB_DATAO_SET){ - ptp.ptp = iobus0 & 0377; - waitdatao = 1; + ptp->ptp = iobus0 & 0377; + ptp->waitdatao = 1; } } - recalc_ptp_req(); + recalc_ptp_req(ptp); } static void -wake_ptr(void) +wake_ptr(void *dev) { + Ptr *ptr; + + ptr = dev; if(IOB_RESET){ - ptr.pia = 0; - ptr.busy = 0; - ptr.flag = 0; - ptr.b = 0; + ptr->pia = 0; + ptr->busy = 0; + ptr->flag = 0; + ptr->b = 0; } if(iodev == PTR){ if(IOB_STATUS){ - if(ptr.motor_on) iobus0 |= F27; - if(ptr.b) iobus0 |= F30; - if(ptr.busy) iobus0 |= F31; - if(ptr.flag) iobus0 |= F32; - iobus0 |= ptr.pia & 7; + if(ptr->motor_on) iobus0 |= F27; + if(ptr->b) iobus0 |= F30; + if(ptr->busy) iobus0 |= F31; + if(ptr->flag) iobus0 |= F32; + iobus0 |= ptr->pia & 7; } if(IOB_DATAI){ - iobus0 |= ptr.ptr; - ptr.flag = 0; + iobus0 |= ptr->ptr; + ptr->flag = 0; // actually when DATAI is negated again - ptr.busy = 1; + ptr->busy = 1; } if(IOB_CONO_CLEAR){ - ptr.pia = 0; - ptr.busy = 0; - ptr.flag = 0; - ptr.b = 0; + ptr->pia = 0; + ptr->busy = 0; + ptr->flag = 0; + ptr->b = 0; } if(IOB_CONO_SET){ - if(iobus0 & F30) ptr.b = 1; - if(iobus0 & F31) ptr.busy = 1; - if(iobus0 & F32) ptr.flag = 1; - ptr.pia |= iobus0 & 7; + if(iobus0 & F30) ptr->b = 1; + if(iobus0 & F31) ptr->busy = 1; + if(iobus0 & F32) ptr->flag = 1; + ptr->pia |= iobus0 & 7; } } - recalc_ptr_req(); + recalc_ptr_req(ptr); } void -ptr_setmotor(int m) +ptr_setmotor(Ptr *ptr, int m) { - if(ptr.motor_on == m) + if(ptr->motor_on == m) return; - ptr.motor_on = m; - if(ptr.motor_on) - ptr.busy = 0; - ptr.flag = 1; - recalc_ptr_req(); + ptr->motor_on = m; + if(ptr->motor_on) + ptr->busy = 0; + ptr->flag = 1; + recalc_ptr_req(ptr); } void -initpt(void) +initptp(Ptp *ptp) { pthread_t thread_id; - ioreq[PTP] = 0; - iobusmap[PTP] = wake_ptp; - ioreq[PTR] = 0; - iobusmap[PTR] = wake_ptr; - pthread_create(&thread_id, nil, ptthread, nil); + iobus[PTP] = (Busdev){ ptp, wake_ptp, 0 }; + pthread_create(&thread_id, nil, ptpthread, ptp); - ptr.fp = fopen("../code/test.rim", "rb"); - ptp.fp = fopen("../code/ptp.out", "wb"); + ptp->fp = fopen("../code/ptp.out", "wb"); +} + +void +initptr(Ptr *ptr) +{ + pthread_t thread_id; + iobus[PTR] = (Busdev){ ptr, wake_ptr, 0 }; + pthread_create(&thread_id, nil, ptrthread, ptr); + + ptr->fp = fopen("../code/test.rim", "rb"); } diff --git a/src/tty.c b/src/tty.c index f8c1b37..bbfbca1 100644 --- a/src/tty.c +++ b/src/tty.c @@ -7,27 +7,27 @@ #include #include -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); }