Exemplo n.º 1
0
void setterm() /**/
{
struct ttyinfo ti;
#ifdef FIONREAD
long val;
#endif

#ifdef CLOBBERS_TYPEAHEAD
#ifdef FIONREAD
	ioctl(SHTTY, FIONREAD, &val);
	if (val) return;
#endif
#endif
	inittty();
	ti = shttyinfo;
#ifdef TIO
	ti.tio.c_lflag &= ~(ICANON|ECHO
#ifdef FLUSHO
		|FLUSHO
#endif
		);
	ti.tio.c_cc[VQUIT] =
#ifdef VDISCARD
		ti.tio.c_cc[VDISCARD] = 
#endif
#ifdef VSUSP
		ti.tio.c_cc[VSUSP] =
#endif
#ifdef VDSUSP
		ti.tio.c_cc[VDSUSP] =
#endif
#ifdef VSWTCH
		ti.tio.c_cc[VSWTCH] =
#endif
		VDISABLEVAL;
	ti.tio.c_cc[VMIN] = 1;
	ti.tio.c_cc[VTIME] = 0;
	ti.tio.c_iflag &= ~(INLCR|ICRNL);
#else
	ti.sgttyb.sg_flags = (ti.sgttyb.sg_flags | CBREAK) & ~ECHO;
	ti.lmodes &= ~LFLUSHO;
	ti.tchars.t_quitc =
		ti.ltchars.t_suspc =
		ti.ltchars.t_flushc =
		ti.ltchars.t_dsuspc = ti.ltchars.t_lnextc = -1;
#endif
#ifdef TTY_NEEDS_DRAINING
	drainoutput();
#endif
	settyinfo(&ti);
}
Exemplo n.º 2
0
Arquivo: main.c Projeto: ysei/pdp6
int
main()
{
	SDL_Event ev;
	SDL_MouseButtonEvent *mbev;
	SDL_MouseMotionEvent *mmev;
	SDL_Surface *op_surf, *ind_surf, *extra_surf;
	SDL_Rect op_panel = { 0, 274, 1280, 210 };
	SDL_Rect ind_panel = { 0, 64, 1280, 210 };
	SDL_Rect extra_panel = { 0, 0, 1280, 210 };
	int i;
	Light *l;
	Switch *sw;

//	void testinst(Apr*);
//	testinst(&apr);

	if(SDL_Init(SDL_INIT_VIDEO) < 0){
error:
		fprintf(stderr, "error: %s\n", SDL_GetError());
		return 1;
	}
	screen = SDL_SetVideoMode(1280, 484, 32, SDL_DOUBLEBUF);
	if(screen == NULL)
		goto error;

	if((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) != IMG_INIT_PNG){
		fprintf(stderr, "error: init SDL_Image: %s\n", IMG_GetError());
		return 1;
	}

	op_surf = IMG_Load("op_panel.png");
	if(op_surf == NULL){
		fprintf(stderr, "Couldn't load op_panel.png\n");
		return 1;
	}
	ind_surf = IMG_Load("ind_panel.png");
	if(ind_surf == NULL){
		fprintf(stderr, "Couldn't load ind_panel.png\n");
		return 1;
	}
	extra_surf = IMG_Load("extra_panel.png");
	if(extra_surf == NULL){
		fprintf(stderr, "Couldn't load extra_panel.png\n");
		return 1;
	}

	keysurf[0] = IMG_Load("key_n.png");
	if(keysurf[0] == NULL){
		fprintf(stderr, "Couldn't load key_n.png\n");
		return 1;
	}
	keysurf[1] = IMG_Load("key_d.png");
	if(keysurf[1] == NULL){
		fprintf(stderr, "Couldn't load key_d.png\n");
		return 1;
	}
	keysurf[2] = IMG_Load("key_u.png");
	if(keysurf[2] == NULL){
		fprintf(stderr, "Couldn't load key_u.png\n");
		return 1;
	}

	lampsurf[0] = IMG_Load("lamp_off.png");
	if(lampsurf[0] == NULL){
		fprintf(stderr, "Couldn't load lamp_off.png\n");
		return 1;
	}
	lampsurf[1] = IMG_Load("lamp_on.png");
	if(lampsurf[1] == NULL){
		fprintf(stderr, "Couldn't load lamp_on.png\n");
		return 1;
	}

	switchsurf[0] = IMG_Load("switch_d.png");
	if(switchsurf[0] == NULL){
		fprintf(stderr, "Couldn't load switch_d.png\n");
		return 1;
	}
	switchsurf[1] = IMG_Load("switch_u.png");
	if(switchsurf[1] == NULL){
		fprintf(stderr, "Couldn't load switch_u.png\n");
		return 1;
	}

	l = op_lights;
	ir_lght   = l; l += 18;
	mi_lght   = l; l += 36;
	pc_lght   = l; l += 18;
	ma_lght   = l; l += 18;
	pih_lght  = l; l += 7;
	pir_lght  = l; l += 7;
	pio_lght  = l; l += 7;
	rest_lght = l;
	sw = switches;
	data_sw      = sw; sw += 36;
	ma_sw        = sw; sw += 18;
	rest_sw      = sw; sw += 4;
	rim_maint_sw = sw;
	l = ind_lights;
	mb_lght   = l; l += 36;
	ar_lght   = l; l += 36;
	mq_lght   = l; l += 36;
	fe_lght   = l; l += 9;
	sc_lght   = l; l += 9;
	ff_lght   = l;
	l = extra_lights;
	membus_lght = l; l += 36;
	pr_lght     = l; l += 8;
	rlr_lght    = l; l += 8;
	rla_lght    = l;
	for(i = 0; i < nelem(keys); i++){
		keys[i].r.x += op_panel.x;
		keys[i].r.y += op_panel.y;
	}
	for(i = 0; i < nelem(op_lights); i++){
		op_lights[i].r.x += op_panel.x;
		op_lights[i].r.y += op_panel.y;
	}
	for(i = 0; i < nelem(ind_lights); i++){
		ind_lights[i].r.x += ind_panel.x;
		ind_lights[i].r.y += ind_panel.y;
	}
	for(i = 0; i < nelem(extra_lights); i++){
		extra_lights[i].r.x += extra_panel.x;
		extra_lights[i].r.y += extra_panel.y;
	}
	for(i = 0; i < nelem(switches)-1; i++){
		switches[i].r.x += op_panel.x;
		switches[i].r.y += op_panel.y;
	}
	rim_maint_sw->r.x += extra_panel.x;
	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:
				mmev = (SDL_MouseMotionEvent*)&ev;
				mouse(0, mmev->state,
				      mmev->x, mmev->y);
				break;
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				mbev = (SDL_MouseButtonEvent*)&ev;
				mouse(mbev->button, mbev->state,
				      mbev->x, mbev->y);
				break;
			case SDL_QUIT:
				dumpmem();
				SDL_Quit();
				return 0;
			case SDL_USEREVENT:
				print("user\n");
				break;
			}
		setlights(apr.ir, ir_lght, 18);
		setlights(apr.mi, mi_lght, 36);
		setlights(apr.pc, pc_lght, 18);
		setlights(apr.ma, ma_lght, 18);
		setlights(apr.pih, pih_lght, 7);
		setlights(apr.pio, pio_lght, 7);
		setlights(apr.pir, pir_lght, 7);
		rest_lght[4].state = apr.run;
		rest_lght[5].state = apr.mc_stop;
		rest_lght[6].state = apr.pi_active;
		rest_lght[0].state = apr.sw_addr_stop   = rest_sw[0].state;
		rest_lght[1].state = apr.sw_repeat      = rest_sw[1].state;
		rest_lght[2].state = apr.sw_mem_disable = rest_sw[2].state;
		rest_lght[3].state = apr.sw_power       = rest_sw[3].state;
		apr.sw_rim_maint = rim_maint_sw->state;
		apr.data = getswitches(data_sw, 36);
		apr.mas = getswitches(ma_sw, 18);
		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;

		setlights(apr.mb, mb_lght, 36);
		setlights(apr.ar, ar_lght, 36);
		setlights(apr.mq, mq_lght, 36);
		setlights(apr.fe, fe_lght, 9);
		setlights(apr.sc, sc_lght, 9);
		ff_lght[0].state = apr.key_ex_st;
		ff_lght[1].state = apr.key_ex_sync;
		ff_lght[2].state = apr.key_dep_st;
		ff_lght[3].state = apr.key_dep_sync;
		ff_lght[4].state = apr.key_rd_wr;
		ff_lght[5].state = apr.mc_rd;
		ff_lght[6].state = apr.mc_wr;
		ff_lght[7].state = apr.mc_rq;

		ff_lght[8].state = apr.if1a;
		ff_lght[9].state = apr.af0;
		ff_lght[10].state = apr.af3;
		ff_lght[11].state = apr.af3a;
		ff_lght[12].state = apr.et4_ar_pse;
		ff_lght[13].state = apr.f1a;
		ff_lght[14].state = apr.f4a;
		ff_lght[15].state = apr.f6a;

		ff_lght[16].state = apr.sf3;
		ff_lght[17].state = apr.sf5a;
		ff_lght[18].state = apr.sf7;
		ff_lght[19].state = apr.ar_com_cont;
		ff_lght[20].state = apr.blt_f0a;
		ff_lght[21].state = apr.blt_f3a;
		ff_lght[22].state = apr.blt_f5a;
		ff_lght[23].state = apr.iot_f0a;

		ff_lght[24].state = apr.fpf1;
		ff_lght[25].state = apr.fpf2;
		ff_lght[26].state = apr.faf1;
		ff_lght[27].state = apr.faf2;
		ff_lght[28].state = apr.faf3;
		ff_lght[29].state = apr.faf4;
		ff_lght[30].state = apr.fmf1;
		ff_lght[31].state = apr.fmf2;

		ff_lght[32].state = apr.fdf1;
		ff_lght[33].state = apr.fdf2;
		ff_lght[34].state = apr.ir & H6 && apr.mq & F1 && !apr.nrf3;
		ff_lght[35].state = apr.nrf1;
		ff_lght[36].state = apr.nrf2;
		ff_lght[37].state = apr.nrf3;
		ff_lght[38].state = apr.fsf1;
		ff_lght[39].state = apr.chf7;

		ff_lght[40].state = apr.dsf1;
		ff_lght[41].state = apr.dsf2;
		ff_lght[42].state = apr.dsf3;
		ff_lght[43].state = apr.dsf4;
		ff_lght[44].state = apr.dsf5;
		ff_lght[45].state = apr.dsf6;
		ff_lght[46].state = apr.dsf7;
		ff_lght[47].state = apr.dsf8;

		ff_lght[48].state = apr.dsf9;
		ff_lght[49].state = apr.msf1;
		ff_lght[50].state = apr.mpf1;
		ff_lght[51].state = apr.mpf2;
		ff_lght[52].state = apr.mc_split_cyc_sync;
		ff_lght[53].state = apr.mc_stop_sync;
		ff_lght[54].state = apr.shf1;
		ff_lght[55].state = apr.sc == 0777;

		ff_lght[56].state = apr.chf1;
		ff_lght[57].state = apr.chf2;
		ff_lght[58].state = apr.chf3;
		ff_lght[59].state = apr.chf4;
		ff_lght[60].state = apr.chf5;
		ff_lght[61].state = apr.chf6;
		ff_lght[62].state = apr.lcf1;
		ff_lght[63].state = apr.dcf1;

		ff_lght[64].state = apr.pi_ov;
		ff_lght[65].state = apr.pi_cyc;
		ff_lght[66].state = !!apr.pi_req;
		ff_lght[67].state = apr.iot_go;
		ff_lght[68].state = apr.a_long;
		ff_lght[69].state = apr.ma == apr.mas;
		ff_lght[70].state = apr.uuo_f1;
		ff_lght[71].state = apr.cpa_pdl_ov;

		ff_lght[72].state = !apr.ex_user;
		ff_lght[73].state = apr.cpa_illeg_op;
		ff_lght[74].state = apr.ex_ill_op;
		ff_lght[75].state = apr.ex_uuo_sync;
		ff_lght[76].state = apr.ex_pi_sync;
		ff_lght[77].state = apr.mq36;

		ff_lght[78].state = apr.key_rim_sbr;
		ff_lght[79].state = apr.ar_cry0_xor_cry1;
		ff_lght[80].state = apr.ar_cry0;
		ff_lght[81].state = apr.ar_cry1;
		ff_lght[82].state = apr.ar_ov_flag;
		ff_lght[83].state = apr.ar_cry0_flag;
		ff_lght[84].state = apr.ar_cry1_flag;
		ff_lght[85].state = apr.ar_pc_chg_flag;

		ff_lght[86].state = apr.cpa_non_exist_mem;
		ff_lght[87].state = apr.cpa_clock_enable;
		ff_lght[88].state = apr.cpa_clock_flag;
		ff_lght[89].state = apr.cpa_pc_chg_enable;
		ff_lght[90].state = apr.cpa_arov_enable;
		ff_lght[91].state = !!(apr.cpa_pia&4);
		ff_lght[92].state = !!(apr.cpa_pia&2);
		ff_lght[93].state = !!(apr.cpa_pia&1);

		setlights(membus0, membus_lght, 36);
		setlights(apr.pr, pr_lght, 8);
		setlights(apr.rlr, rlr_lght, 8);
		setlights(apr.rla, rla_lght, 8);

		SDL_BlitSurface(op_surf, NULL, screen, &op_panel);
		SDL_BlitSurface(ind_surf, NULL, screen, &ind_panel);
		SDL_BlitSurface(extra_surf, NULL, screen, &extra_panel);
		for(i = 0; i < nelem(keys); i++)
			SDL_BlitSurface(keys[i].surfs[keys[i].state],
			                NULL, screen, &keys[i].r);
		for(i = 0; i < nelem(op_lights); i++)
			SDL_BlitSurface(op_lights[i].surfs[op_lights[i].state && apr.sw_power],
			                NULL, screen, &op_lights[i].r);
		for(i = 0; i < nelem(ind_lights); i++)
			SDL_BlitSurface(ind_lights[i].surfs[ind_lights[i].state && apr.sw_power],
			                NULL, screen, &ind_lights[i].r);
		for(i = 0; i < nelem(extra_lights); i++)
			SDL_BlitSurface(extra_lights[i].surfs[extra_lights[i].state && apr.sw_power],
			                NULL, screen, &extra_lights[i].r);
		for(i = 0; i < nelem(switches); i++)
			SDL_BlitSurface(switches[i].surfs[switches[i].state],
			                NULL, screen, &switches[i].r);
		SDL_Flip(screen);
	}
}