*** simulator.c.orig Thu Nov 25 10:11:18 1999 --- simulator.c Sat Dec 4 14:47:41 1999 *************** *** 250,258 **** unsigned char value_address_bus; unsigned char value_data_bus; unsigned char value_alu; /* contents of memories */ ! unsigned short contents_micro_mem[64] = { 0x00ac, 0x0002, --- 250,259 ---- unsigned char value_address_bus; unsigned char value_data_bus; unsigned char value_alu; + unsigned char value_cond; /* contents of memories */ ! unsigned int contents_micro_mem[64] = { 0x00ac, 0x0002, *************** *** 364,370 **** 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }; ! unsigned char mops[16]; char *hex[256] = { --- 365,380 ---- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }; ! unsigned char mops[21]; ! ! #define N 0 ! #define Z 1 ! #define C 2 ! #define V 3 ! ! unsigned char cond_master[4]; ! unsigned char cond_slave[4]; ! unsigned char cond_alu[4]; char *hex[256] = { *************** *** 486,496 **** void micro_mem(void) { ! rectangle(20, 160, 120, 400); ! string(80, 160 + 9, "Micro Mem"); downarrow(80, 160); mop(40, 615, "1"); ! mop(120, 615, "15"); XFillArc(display, win, gc, 66, 615, 4, 4, 0, 360 * 64); XFillArc(display, win, gc, 80, 615, 4, 4, 0, 360 * 64); XFillArc(display, win, gc, 95, 615, 4, 4, 0, 360 * 64); --- 496,506 ---- void micro_mem(void) { ! rectangle(20, 160, 147, 400); ! string(95, 160 + 9, "Micro Mem"); downarrow(80, 160); mop(40, 615, "1"); ! mop(120, 615, "20"); XFillArc(display, win, gc, 66, 615, 4, 4, 0, 360 * 64); XFillArc(display, win, gc, 80, 615, 4, 4, 0, 360 * 64); XFillArc(display, win, gc, 95, 615, 4, 4, 0, 360 * 64); *************** *** 503,509 **** { int y = 160 + 7 * row + 25; int col; ! for(col = 0; col < 15; col++) { int x = 20 + 7 * col + 5; if(contents_micro_mem[row] & (1 << (col + 1))) --- 513,519 ---- { int y = 160 + 7 * row + 25; int col; ! for(col = 0; col < 20; col++) { int x = 20 + 7 * col + 5; if(contents_micro_mem[row] & (1 << (col + 1))) *************** *** 615,623 **** mop(ABX + 45, ypos - 110, "5"); downline(ABX + 45, ypos - 95, ypos - 65); smallstring(ABX + 52, ypos - 67, mops[5] ? "1" : "0"); ! mop(ABX + 70, ypos + 55, "6"); upline(ABX + 70, ypos + 40, ypos + 15); ! smallstring(ABX + 75, ypos + 27, mops[6] ? "1" : "0"); smallstring(ABX + 50, ypos + 28, "ld"); mop(ABX + 110, ypos + 55, "7"); upline(ABX + 110, ypos + 40, ypos + 15); --- 625,633 ---- mop(ABX + 45, ypos - 110, "5"); downline(ABX + 45, ypos - 95, ypos - 65); smallstring(ABX + 52, ypos - 67, mops[5] ? "1" : "0"); ! /* mop(ABX + 70, ypos + 55, "6"); */ upline(ABX + 70, ypos + 40, ypos + 15); ! /* smallstring(ABX + 75, ypos + 27, mops[6] ? "1" : "0"); */ smallstring(ABX + 50, ypos + 28, "ld"); mop(ABX + 110, ypos + 55, "7"); upline(ABX + 110, ypos + 40, ypos + 15); *************** *** 650,655 **** --- 660,727 ---- } void + conditional_reg(void) + { + int xpos = ABX + 20; + int ypos = ABY2 - 95; + int ypcpos = (ABY1 + ABY2) / 2; + + rectangle(xpos, ypos, 80, 150); + smallstring(xpos + 55, ypcpos + 27, value_cond ? "1" : "0"); + hline(xpos - 8, ypcpos + 40, xpos + 50); + vline(xpos - 8, ypcpos + 40, ypcpos + 150); + hline(xpos - 8, ypcpos + 150, xpos); + + mop(xpos + 110, ypos + 10, "6"); + leftline(xpos + 95, ypos + 10, xpos + 80); + smallstring(xpos + 85, ypos + 5, mops[6] ? "1" : "0"); + mop(xpos + 110, ypos + 43, "20"); + leftline(xpos + 95, ypos + 43, xpos + 80); + smallstring(xpos + 85, ypos + 38, mops[20] ? "1" : "0"); + mop(xpos + 110, ypos + 76, "19"); + leftline(xpos + 95, ypos + 76, xpos + 80); + smallstring(xpos + 85, ypos + 71, mops[19] ? "1" : "0"); + mop(xpos + 110, ypos + 109, "18"); + leftline(xpos + 95, ypos + 109, xpos + 80); + smallstring(xpos + 85, ypos + 104, mops[18] ? "1" : "0"); + mop(xpos + 110, ypos + 142, "17"); + leftline(xpos + 95, ypos + 142, xpos + 80); + smallstring(xpos + 85, ypos + 137, mops[17] ? "1" : "0"); + mop(xpos + 110, ypos + 187, "16"); + leftline(xpos + 95, ypos + 187, xpos + 80); + smallstring(xpos + 85, ypos + 180, mops[16] ? "1" : "0"); + + registr(xpos, ypos + 170, 20, 30, "N"); + vline(xpos + 10, ypos + 150, ypos + 170); + smallstring(xpos, ypos + 165, cond_slave[N] ? "1" : "0"); + smallstring(xpos, ypos + 215, cond_alu[N] ? "1" : "0"); + registr(xpos + 20, ypos + 170, 20, 30, "Z"); + vline(xpos + 30, ypos + 150, ypos + 170); + smallstring(xpos + 20, ypos + 165, cond_slave[Z] ? "1" : "0"); + smallstring(xpos + 20, ypos + 215, cond_alu[Z] ? "1" : "0"); + registr(xpos + 40, ypos + 170, 20, 30, "C"); + vline(xpos + 50, ypos + 150, ypos + 170); + smallstring(xpos + 40, ypos + 165, cond_slave[C] ? "1" : "0"); + smallstring(xpos + 40, ypos + 215, cond_alu[C] ? "1" : "0"); + registr(xpos + 60, ypos + 170, 20, 30, "V"); + vline(xpos + 70, ypos + 150, ypos + 170); + smallstring(xpos + 60, ypos + 165, cond_slave[V] ? "1" : "0"); + smallstring(xpos + 60, ypos + 215, cond_alu[V] ? "1" : "0"); + + /* draw the connections from ALU to conditional register */ + hline(xpos - 79, ypos + 340, xpos + 10); + vline(xpos + 10, ypos + 340, ypos + 200); + hline(xpos - 84, ypos + 345, xpos + 30); + vline(xpos + 30, ypos + 345, ypos + 200); + hline(xpos - 89, ypos + 350, xpos + 50); + vline(xpos + 50, ypos + 350, ypos + 200); + hline(xpos - 94, ypos + 355, xpos + 70); + vline(xpos + 70, ypos + 355, ypos + 200); + + + } + + void main_mem(void) { int xpos = DBX + 30; *************** *** 692,700 **** void evaluate_combinatorial(void) { ! unsigned short allmops = contents_micro_mem[contents_micro_pc_slave]; int i; ! for(i = 0; i < 16; i++) mops[i] = (allmops >> i) & 1; /* figure out what the address bus is */ --- 764,772 ---- void evaluate_combinatorial(void) { ! unsigned int allmops = contents_micro_mem[contents_micro_pc_slave]; int i; ! for(i = 0; i < 21; i++) mops[i] = (allmops >> i) & 1; /* figure out what the address bus is */ *************** *** 705,716 **** else value_address_bus = 0; - /* possibly propagate address bus to PC */ - if(mops[6]) - contents_pc_master = value_address_bus; - else if(mops[7]) - contents_pc_master = contents_pc_slave + 1; - /* figure out what the data bus is */ if(mops[3] && !mops[4]) value_data_bus = contents_main_mem[value_address_bus]; --- 777,782 ---- *************** *** 734,739 **** --- 800,808 ---- if(mops[11]) contents_r0_master = value_data_bus; + cond_alu[C] = 0; + cond_alu[V] = 0; + /* figure out the value of the alu */ switch((mops[13] << 2) | (mops[14] << 1) | (mops[15] << 0)) { *************** *** 741,756 **** value_alu = contents_r0_slave; break; case 1: value_alu = contents_r1_slave << 1; break; case 2: value_alu = contents_r1_slave >> 1; break; case 3: ! value_alu = contents_r0_slave + contents_r1_slave; break; case 4: ! value_alu = contents_r0_slave - contents_r1_slave; break; case 5: value_alu = contents_r0_slave & contents_r1_slave; --- 810,831 ---- value_alu = contents_r0_slave; break; case 1: + cond_alu[C] = (contents_r1_slave >> 7) & 0x1; value_alu = contents_r1_slave << 1; break; case 2: + cond_alu[C] = contents_r1_slave & 0x1; value_alu = contents_r1_slave >> 1; break; case 3: ! i = contents_r0_slave + contents_r1_slave; ! cond_alu[C] = (i >> 8) & 0x1; ! value_alu = i; break; case 4: ! i = contents_r0_slave - contents_r1_slave; ! cond_alu[C] = (i >> 8) & 0x1; ! value_alu = i; break; case 5: value_alu = contents_r0_slave & contents_r1_slave; *************** *** 763,771 **** --- 838,869 ---- break; } + cond_alu[N] = ((value_alu >> 7) & 0x1); + cond_alu[Z] = (value_alu == 0); + /* possibly propagate alu to r1 */ if(mops[12]) contents_r1_master = value_alu; + + /* conditional register */ + value_cond = ((cond_slave[N] && mops[17]) || + (cond_slave[Z] && mops[18]) || + (cond_slave[C] && mops[19]) || + (cond_slave[V] && mops[20]) || + mops[6]); + + if (mops[16]) { + cond_master[N] = cond_alu[N]; + cond_master[Z] = cond_alu[Z]; + cond_master[C] = cond_alu[C]; + cond_master[V] = cond_alu[V]; + } + + /* possibly propagate address bus to PC */ + if(value_cond) + contents_pc_master = value_address_bus; + else if(mops[7]) + contents_pc_master = contents_pc_slave + 1; } void *************** *** 776,781 **** --- 874,883 ---- contents_pc_slave = contents_pc_master; contents_micro_pc_slave = contents_micro_pc_master; contents_address_reg_slave = contents_address_reg_master; + cond_slave[N] = cond_master[N]; + cond_slave[Z] = cond_master[Z]; + cond_slave[C] = cond_master[C]; + cond_slave[V] = cond_master[V]; } void *************** *** 788,793 **** --- 890,896 ---- alu_and_registrs(DBX, DBY2 + 20, 300, 100); pc(); address_reg(); + conditional_reg(); main_mem(); XFlush(display); } *************** *** 810,818 **** } for(i = 0; i < 64; i++) { ! unsigned short word = 0; int j; ! for(j = 1; j <= 15; j++) { if(getc(infile) == '1') word |= (1 << j); --- 913,921 ---- } for(i = 0; i < 64; i++) { ! unsigned int word = 0; int j; ! for(j = 1; j <= 20; j++) { if(getc(infile) == '1') word |= (1 << j);