summaryrefslogtreecommitdiff
path: root/miniemu
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2018-05-01 18:34:07 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2018-05-01 18:34:07 +0200
commit22b4dd12c063090acc8a8a1297c41bde74e0de24 (patch)
treeb6ec00abb9c88162f60c02a1c2adc76a3e1bd47d /miniemu
parent669f2c250379779f1b9bb7129d5909baef3df2e0 (diff)
downloadcompilertests-22b4dd12c063090acc8a8a1297c41bde74e0de24.tar.gz
compilertests-22b4dd12c063090acc8a8a1297c41bde74e0de24.tar.bz2
quite some fixes
Diffstat (limited to 'miniemu')
-rw-r--r--miniemu/TESTS2
-rw-r--r--miniemu/cpu.c26
-rw-r--r--miniemu/cpu.h10
-rw-r--r--miniemu/main.c6
4 files changed, 27 insertions, 17 deletions
diff --git a/miniemu/TESTS b/miniemu/TESTS
deleted file mode 100644
index b233c35..0000000
--- a/miniemu/TESTS
+++ /dev/null
@@ -1,2 +0,0 @@
-test1.bin - illegal opcode
-test2.bin - sequence of nops and a terminating halt
diff --git a/miniemu/cpu.c b/miniemu/cpu.c
index 26e1469..92f8a2b 100644
--- a/miniemu/cpu.c
+++ b/miniemu/cpu.c
@@ -30,8 +30,7 @@ void cpu_reset( Cpu *cpu )
cpu->error = 0;
cpu->debug = 0;
cpu->memory->m[cpu->PC] = OPCODE_HLT;
- cpu->Z = 0;
- cpu->C = 0;
+ cpu->CCR = 0;
}
static int read_src_value( Cpu *cpu, int instruction )
@@ -146,27 +145,27 @@ static void execute_jmp( Cpu *cpu, int instruction )
break;
case OPCODE_JMP_JE:
- condition = ( cpu->Z == 1 );
+ condition = ( ( cpu->CCR & Z_FLAG ) == 1 );
break;
case OPCODE_JMP_JNE:
- condition = ( cpu->Z == 0 );
+ condition = ( ( cpu->CCR & Z_FLAG ) == 0 );
break;
case OPCODE_JMP_JB:
- condition = ( cpu->C == 1 );
+ condition = ( ( cpu->CCR & C_FLAG ) == 1 );
break;
case OPCODE_JMP_JBE:
- condition = ( cpu->C == 1 ) || ( cpu->Z == 1 );
+ condition = ( ( cpu->CCR & C_FLAG ) == 1 ) || ( ( cpu->CCR & Z_FLAG ) == 1 );
break;
case OPCODE_JMP_JA:
- condition = ( cpu->C == 0 ) && ( cpu->Z == 0 );
+ condition = ( ( cpu->CCR & C_FLAG ) == 0 ) && ( ( cpu->CCR & Z_FLAG ) == 0 );
break;
case OPCODE_JMP_JAE:
- condition = ( cpu->C == 0 );
+ condition = ( ( cpu->CCR & C_FLAG ) == 0 );
break;
case OPCODE_JMP_JSR:
@@ -277,8 +276,11 @@ static void execute_cmp( Cpu *cpu, int instruction )
value1 = read_src_value( cpu, instruction );
value2 = read_dst_value( cpu, instruction );
- cpu->Z = ( value1 - value2 == 0 );
- cpu->C = ( value1 - value2 < 0 );
+ if( value1 - value2 == 0 ) {
+ cpu->CCR |= Z_FLAG;
+ } else {
+ cpu->CCR &= ~Z_FLAG;
+ }
cpu->PC++;
}
@@ -451,7 +453,7 @@ void cpu_print_dump( Cpu *cpu )
print_register( "CX", cpu->CX );
print_register( "DX", cpu->DX );
print_register( "SP", cpu->SP );
- print_register( "Z", cpu->Z );
- print_register( "C", cpu->C );
+ print_register( "Z", cpu->CCR & Z_FLAG );
+ print_register( "C", cpu->CCR & C_FLAG );
print_register( "F", cpu->error );
}
diff --git a/miniemu/cpu.h b/miniemu/cpu.h
index f47015f..852b1c1 100644
--- a/miniemu/cpu.h
+++ b/miniemu/cpu.h
@@ -1,14 +1,18 @@
#pragma once
+typedef enum {
+ C_FLAG = 0x00, /* carry flag */
+ Z_FLAG = 0x01 /* zero flag */
+} CCRFlag;
+
typedef struct Cpu {
int PC; /* program counter */
int AX; /* accumulator register */
int BX; /* base register */
int CX; /* counter register */
int DX; /* data register */
- int SP; /* stack pointer */
- int Z; /* zero status bit */
- int C; /* carry status bit */
+ int SP; /* stack register holding address to top of stack */
+ int CCR; /* condition code register */
struct Memory *memory;
int stopped;
int error;
diff --git a/miniemu/main.c b/miniemu/main.c
index f05973e..124d9c3 100644
--- a/miniemu/main.c
+++ b/miniemu/main.c
@@ -26,6 +26,12 @@ int main( int argc, char *argv[] )
cpu_debug( &cpu, 1 );
while( !cpu_stopped( &cpu ) ) {
+ print( "CPU" );
+ cpu_print_dump( &cpu );
+
+ print( "MEMORY" );
+ memory_print_dump( &memory );
+
cpu_step( &cpu );
}