summaryrefslogtreecommitdiff
path: root/miniemu/main.c
blob: 124d9c33a0aa15e079125faf6f117800771a4c0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "const.h"
#include "cpu.h"
#include "memory.h"
#include "io.h"
#include "opcodes.h"

int main( int argc, char *argv[] )
{
	Cpu cpu;
	Memory memory;
	int retcode;
	
	if( argc != 2 ) {
		print( "USAGE: miniemu <memory.bin>" );
		return 1;
	}
	
	memory_init( &memory, DEFAULT_MEMORY_SIZE );
	cpu_init( &cpu, &memory );
	
	print( "EMULATOR STARTED" );
	
	print( "LOADING MEMORY DUMP" );
	memory_read_from_file( &memory, argv[1] );

	cpu_debug( &cpu, 1 );
	
	while( !cpu_stopped( &cpu ) ) {
		print( "CPU" );
		cpu_print_dump( &cpu );
		
		print( "MEMORY" );
		memory_print_dump( &memory );
		
		cpu_step( &cpu );
	}
	
	retcode = cpu_has_errors( &cpu );
		
	print( "CPU" );
	cpu_print_dump( &cpu );
	
	print( "MEMORY" );
	memory_print_dump( &memory );
		
	cpu_done( &cpu );
	memory_done( &memory );

	print( "EMULATOR TERMINATED" );

	return retcode;
}