//a=a-1 void ALU::dec(Register a) { if(!a.getValue()) { m_flags[0] = 1; } else { m_flags[0] = 0; } a.setValue(a.getValue()-1); }
//a=a*b void ALU::mul(Register a, Register b) { if(a.getValue()>UINT_MAX/b.getValue()) { m_flags[0] = 1; } else { m_flags[0] = 0; } a.setValue(a.getValue()*b.getValue()); }
//a=b-a void ALU::rsub(Register a, Register b) { if(b.getValue()<a.getValue()) { m_flags[0] = 1; } else { m_flags[0] = 0; } a.setValue(b.getValue()-a.getValue()); }
//a=a-b void ALU::sub(Register a, Register b) { if(a.getValue()<b.getValue()) { m_flags[0] = 1; } else { m_flags[0] = 0; } a.setValue(a.getValue()-b.getValue()); }
//a=a+1 void ALU::inc(Register a) { if(a.getValue()==UINT_MAX) { m_flags[0] = 1; } else { m_flags[0] = 0; } a.setValue(a.getValue()+1); }
//a=a+b void ALU::add(Register a,Register b) { if(a.getValue()>UINT_MAX-b.getValue()) { m_flags[0] = 1; } else { m_flags[0] = 0; } a.setValue(a.getValue()+b.getValue()); }
//a=b-a+c-1 void ALU::rsubc(Register a, Register b) { unsigned val = b.getValue()-a.getValue()+m_flags[0]-1; if(b.getValue()<a.getValue()-m_flags[0]+1) { m_flags[0] = 1; } else { m_flags[0] = 0; } a.setValue(val); }
//a=a+b+c void ALU::addc(Register a,Register b) { unsigned val = a.getValue()+b.getValue()+m_flags[0]; if(a.getValue()>UINT_MAX-b.getValue()-m_flags[0]) { m_flags[0] = 1; } else { m_flags[0] = 0; } a.setValue(val); }
main(int argc, char **argv) { if (argc < 3) { printf("09TO10 version 1.0\n\r" "by Robert Schmidt of Ztiff Zox Softwear 1993\n\r" "\n\r" "Converts TWEAK version 0.9 files to TWEAK version 1.0 files.\n\r" "\n\r" "Syntax: 09TO10 <oldfile> <newfile>\n\r" ); return 0; } vgaRegTable rtab; char *fname = argv[1]; FILE *f; int r; // Open file in selected mode. if (!(f=fopen(fname,"rb"))) { perror(fname); return 0; } // Read file: for (r=0; r<registers; r++) if (fread(&(rtab[r]),1,1,f) == 0) { perror(fname); return 0; } fclose(f); ofstream out(argv[2], ios::trunc|ios::binary|ios::out); Register reg; for (r=0; r<registers; r++) { reg.setPort(table[r].port); reg.setIndex(table[r].index); reg.setValue(rtab[r]); out << reg; } return 0; }
void ALU::random(Register a) { a.setValue(rand()); }
//a=1 void ALU::one(Register a) { a.setValue(1); }