#include #include #include #include int sx=3,sy=3,inter[4]; char io1[5],io2[5],io3[5],io4[5]; void initgrph() { int gd=DETECT; int gm=DETECT; int errorcode; clrscr(); printf("PROSIM Graphical BCU Simulator\nInitializing graphics device..."); detectgraph(&gd,&gm); errorcode=graphresult(); if(errorcode!=0) { printf("\n\nError! No graphics hardware detected or insufficient run time parameters met for graphics.\nAborting...\nTry installing graphics capable adapter and/or proper device driver files.\nHave a nice day. \nPROSIM END RUN"); restorecrtmode(); exit(1); } initgraph(&gd,&gm,"e:\\tc\\bgi"); printf(" Success. Please Wait..."); } void cleanup() { closegraph(); restorecrtmode(); clrscr(); printf("PROSIM Graphical BCU Simulator.\nRUN SUCCESSFUL - END RUN\nHave a nice day... PROSIM Team.\n"); } void screen() { setfillstyle(SOLID_FILL,7); bar(0,0,getmaxx(),getmaxy()); setcolor(BLACK); rectangle(0,0,getmaxx(),getmaxy()); rectangle(1,1,getmaxx()-1,getmaxy()-1); setfillstyle(SOLID_FILL,BLUE); bar(3,3,getmaxx()-3,3+15); setfillstyle(SOLID_FILL,LIGHTGRAY); bar(3,3+17,getmaxx()-3,getmaxy()-3); settextstyle(SMALL_FONT,HORIZ_DIR,4); setcolor(15); outtextxy(sx+4,sy+2,"PROSIM Graphical BCU Simulator - Bus Control Unit Simulation Console"); } void panels() { setcolor(8); rectangle(4,getmaxy()-50,getmaxx()-4,getmaxy()-5); setfillstyle(SOLID_FILL,WHITE); bar(4+1,getmaxy()-50+1,getmaxx()-4-1,getmaxy()-5-1); rectangle(4,3+15+3,getmaxx()-4,getmaxy()-50-2); bar(4+1,3+15+3+1,getmaxx()-4-1,getmaxy()-50-2-1); } void drawoutline() { setcolor(BLACK); rectangle(25,175,25+75,175+200);/*BCU*/ rectangle(150,75,150+60,75+75);/*IOD-1*/ rectangle(150+60+40,75,150+60+40+60,75+75);/*IOD-2*/ rectangle(150+60+40+60+40,75,150+60+40+60+40+60,75+75);/*IOD-3*/ rectangle(150+60+40+60+40+60+40,75,150+60+40+60+40+60+40+60,75+75);/*IOD-4*/ } void polllines(int linecolor1,int linecolor2) { setcolor(linecolor1); line(25+75+1,175+25+20,getmaxx()-150,175+25+20); setcolor(linecolor2); line(25+75+1,175+25,getmaxx()-150-20,175+25); setcolor(linecolor2); line(getmaxx()-150-20,175+25,getmaxx()-150-20,75+75); setcolor(linecolor1); line(getmaxx()-150-20+20,175+25+20,getmaxx()-150,75+75); setcolor(linecolor1); line(getmaxx()-150-60-40,175+25+20,getmaxx()-150-60-40,75+75); line(getmaxx()-150-60-40-60-40,175+25+20,getmaxx()-150-60-40-60-40,75+75); line(getmaxx()-150-60-40-60-40-60-40,175+25+20,getmaxx()-150-60-40-60-40-60-40,75+75); setcolor(linecolor2); line(getmaxx()-150-20-60-40,175+25,getmaxx()-150-20-60-40,75+75); line(getmaxx()-150-20-60-40-60-40,175+25,getmaxx()-150-20-60-40-60-40,75+75); line(getmaxx()-150-20-60-40-60-40-60-40,175+25,getmaxx()-150-20-60-40-60-40-60-40,75+75); } void databus(int linecolor,int activeline) { setcolor(linecolor); line(25+75+1+10,250,getmaxx()-125,250); line(25+75+1+10,260,getmaxx()-125,260); line(getmaxx()-125,245,getmaxx()-115,255); line(getmaxx()-125,265,getmaxx()-115,255); line(getmaxx()-125,245,getmaxx()-125,250); line(getmaxx()-125,265,getmaxx()-125,260); line(25+75+1+10,245,25+75+1,255); line(25+75+1+10,265,25+75+1,255); line(25+75+1+10,245,25+75+1+10,250); line(25+75+1+10,265,25+75+1+10,260); line(200,250,200,150); line(200+100,250,200+100,150); line(200+200,250,200+200,150); line(200+300,250,200+300,150); setcolor(BROWN); if(activeline==1) { line(200,250,200,150); } if(activeline==2) { line(200+100,250,200+100,150); } if(activeline==3) { line(200+200,250,200+200,150); } if(activeline==4) { line(200+300,250,200+300,150); } } void busreq(int col) { setcolor(col); line(101,300,getmaxx()-110,300); } void busbusy(int col) { setcolor(col); line(101,350,getmaxx()-110,350); } void labels(void) { setcolor(BLACK); outtextxy(35,150,"Bus Control"); outtextxy(35,160,"Unit [BCU]"); outtextxy(35,200,"Poll Count"); outtextxy(35,210,"Lines"); outtextxy(35,250,"Data Bus"); outtextxy(35,295,"Bus Request"); outtextxy(35,345,"Bus Busy"); outtextxy(152,75,"I/O Device"); outtextxy(175,85,"#1"); outtextxy(158,130,"Count 00"); outtextxy(152+100,75,"I/O Device"); outtextxy(175+100,85,"#2"); outtextxy(158+100,130,"Count 01"); outtextxy(152+200,75,"I/O Device"); outtextxy(175+200,85,"#3"); outtextxy(158+200,130,"Count 10"); outtextxy(152+300,75,"I/O Device"); outtextxy(175+300,85,"#4"); outtextxy(158+300,130,"Count 11"); } void dispintr() { itoa(inter[0],io1,10); itoa(inter[1],io2,10); itoa(inter[2],io3,10); itoa(inter[3],io4,10); setfillstyle(SOLID_FILL,WHITE); setcolor(BLACK); bar(4+1,getmaxy()-50+1,getmaxx()-4-1,getmaxy()-5-1); outtextxy(7,getmaxy()-50,"The current interrupt sequence: "); outtextxy(200,getmaxy()-50,io1); outtextxy(210,getmaxy()-50,io2); outtextxy(220,getmaxy()-50,io3); outtextxy(230,getmaxy()-50,io4); } void initintr() { inter[0]=3; inter[1]=2; inter[2]=1; inter[3]=0; } void getintr() { int i,j,k,tmp[4]; char dummy[1],dummy2[5]; for(i=0;i<4;i++) tmp[i]=5; bar(4+1,getmaxy()-50+1,getmaxx()-4-1,getmaxy()-5-1); outtextxy(7,getmaxy()-50,"Enter the interrupt sequence: "); for(i=0;i<4;i++) { dummy[0]='5'; while(dummy[0]!='1'&&dummy[0]!='2'&&dummy[0]!='3'&&dummy[0]!='4') { dummy[0]=getch(); for(k=0;k<4;k++) { if(atoi(dummy)==tmp[k]) dummy[0]='5'; } } bar(200,270,300,290); dummy2=NULL; dummy2=strcat(dummy2,dummy[0]); outtextxy(200,getmaxy()-50,dummy2); tmp[i]=atoi(dummy); } for(i=0;i<4;i++) inter[i]=tmp[i]; } void main() { initgrph(); screen(); panels(); drawoutline(); polllines(BLUE,RED); databus(MAGENTA,0); busreq(BLUE); busbusy(RED); labels(); initintr(); dispintr(); getintr(); dispintr(); getch(); cleanup(); }