// // Dragon cache coherency simulation // // Copyright © 2007 - 2007 alek.stevanovic@gmail.com // // 23/12/07 first version // 23/11/08 second version, Djordje Jevdjic // // include files // #include "standard.vin" #include "simpleButton.vin" // // set viewport // const int LOGICALW = 1024; const int LOGICALH = 768; setViewport(0, 0, LOGICALW, LOGICALH, 1); // // set background // bgbrush = SolidBrush(vellum); setBgBrush(bgbrush); // // fonts // hintFont = Font("Times New Roman", 16, 0); titleFont = Font("Times New Roman", 24, 0); f12B = Font("Times New Roman", 12, 1); fsmall = Font("Times New Roman", 14, 0); // // title // navybrush = SolidBrush(rgb(0, 0, 102)); title = Rectangle2(0, VCENTRE, 0, navybrush, 5, 5, LOGICALW/2, 30, whitebrush, titleFont, "Dragon Cache Coherency Protocol"); title.setTxtOff(2, 1); // // useage infomation // str = "Like real hardware, the CPUs can operate\n"; str += "in parallel - try pressing a button on each\n"; str += "CPU \"simultaneously\"."; hint = Txt(0, HLEFT | VTOP, 5, 80, blackbrush, hintFont, str); const int DIRTYBIT = 1; // const int SHAREDBIT = 2; // cache line states const int NOTHING = 0; const int RECV = 1; const int SEND = 2; const int SND_RCV = 3; const int MEMORY = 4; const int ST_E = 0; // Exclusive const int ST_M = 1; // Modified const int ST_Sc = 2; // Shared clean const int ST_Sm = 3; // Shared modified const int ST_No = 4; // Beginner empty state string statetxt[5] = { "E", "M", "Sc", "Sm", "No" }; int wValue = 0; // value written into cache int isdirty = 0; // indicates if there is a dirty cache int isshared = 0; // indicates if cache line shared int issharedstate = 0; // shared cache line state (all should be the same) int isshareddata = 0; // shared cache line data (all should be the same) int buglevel = 0; // buglevel (0 = bug free) int isbusy = 0; // counter used to signify when any of the processors is busy // (with it representing the number of busy processors) // // Number of CPUs // const int NCPU = 4; // Set the number of CPUs in the simulation for (int i=0; i