Wednesday, 27 December 2017
Wednesday, 6 December 2017
csirac "emulator"
I am dabbling with a CSIRAC "emulator", very basic so far. There is a Windows 98 program but it is a little
wonky under Wine, so this.
Using Frank Hirst's Principles and Operations... and the programming manual
(also in the emulator zip) as guide. Not sure about the tape mechanism, but
I guess a file to load the programs at least.
/* csirac rustic "emulator" with hello world program
*
* not all src and dest codes decoded yet, and no tape functions
*
*/
#include -stdio.h- //these dashes should be lt and gt but blogger won't show them
//#define DEBUG
int A,B,C,D[15],Src,Dest,S=0,K=0,M , Value ,Reg1=0,Reg2=45 ;
int Store[1024] ={
//0123456789SSSSSDDDDD
0b00000010010000000010, //0 M 13 T H
0b00000000000000000100, //1 A= M 0
0b00000010001100000101, //2 A = A + PE
0b00000000000010000000, //3 M 0 = A
0b00000010000000000110, //4 A - M 8 (stop value)
0b00000000000101011001, //5 SKIP IF 0 src=10 (ZA) dest=25 (CS)
0b00000000001010010111, //6 JMP 0 src=20 (Z) dest = 23 (S)
0b00000010111111111111, //7 HALT
0b00000101010000000010, //8 P20-P11 = 21 (stop value)
0x48, 0x45, 0x4C, 0x4C, 0x4F, 0x20, 0x57, 0x4F, 0x52, 0x4C, 0x44, 0x0d, //9
0b00000000000000000000, //21 spare
0b00000000000000000000, //22 spare
0b00000000000000000000, //23 spare
0b00000000000000000000, //24 spare
};
int main (void) {
while (S < 1024){
Dest=0b11111 & Store[S];
if (Dest > 1024) break ;
Src=0b11111 & ( Store[S] >> 5 );
if (Src > 1024 ) break ;
K=Store[S] >>10;
if (Src==0) Value = Store[K] ;
//if (Src==1) Value = ;
if (Src==2) Value = Reg1 ;
if (Src==3) Value = Reg2 ;
if (Src==4) Value = A;
if (Src==5 ) Value = A >> 20 ;
if (Src==6 ) Value = A /2 ;
if (Src==7 ) Value = A*2;
if (Src==8 ) Value = 0b00001111 & A ;
if (Src==9 ) { Value = A ; A = 0 ; }
if (Src==10 ) { if (A == 0) Value = 0 ; else Value = 1 ; }
if (Src==11 ) Value = B ;
if (Src==12 ) { if ((B >> 20) == 1 ) Value = 99; else Value =0 ; } ;
if (Src==13 ) Value = B >> 1 ;
if (Src==14 ) Value = C ;
if (Src==15 ) Value = C >> 20 ;
if (Src==20) Value =0;
if (Src==23) Value =S;
if (Src==24) Value=0b00000000010000000000;
if (Src==25) Value=0b00000000000000000001;
if (Src==26) Value = K;
if (Dest==0) Store[K]=Value;
if (Dest==2) { printf ("%c", Value);
#ifdef DEBUG
printf("\n");
#endif
}
if (Dest==4) A = Value;
if (Dest==5) A = A + Value;
if (Dest==6) A = A - Value;
if (Dest==7) A = A & Value;
if (Dest==8) A = A | Value;
if (Dest==9) A = A ^ Value;
if (Dest==16) C = C - Value;
if (Dest==23) { S = Value - 1 ; if (S > 1024 ) break;}
if (Dest==25) if (Value==0) S++;
if (Dest==26) K = Value;
if ((Src == 31) && (Dest==31)) { printf("\n\n*Halt*\n\n");break; }
S++;
#ifdef DEBUG
printf("A=%d Src=%d Dest=%d K=%d S=%d Store[%d]=%d\n",A,Src,Dest,K,S,S,Store[S] );
#endif
}
printf ("\n");
#ifdef DEBUG
// display memory store
for (S=0;S <=20 ;S++) { printf("%d = %d\n",S,Store[S]); }
#endif
return 0;
}
Subscribe to:
Comments (Atom)