-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
73 lines (49 loc) · 2.09 KB
/
main.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include "thread.h"
#define MAX_ENTITIES 3
int main ( int argc, char *argv[] )
{
int i, j;
thread_t *entities[ MAX_ENTITIES ];
instruction_t prog1[ ] = { INSTR_FMT1( INCX ), INSTR_FMT3( BXNE, 2, 0 ),
INSTR_FMT1( INCY ), INSTR_FMT3( BYNE, 2, 2 ),
INSTR_FMT1( DECX ), INSTR_FMT3( BXNE, 0, 4 ),
INSTR_FMT1( DECY ), INSTR_FMT3( BYNE, 0, 6 ),
INSTR_FMT2( JUMP, 0 ) };
instruction_t prog2[ ] = { INSTR_FMT1( INCX ), INSTR_FMT1( INCX ),
INSTR_FMT1( INCY ), INSTR_FMT1( INCY ),
INSTR_FMT1( DECX ), INSTR_FMT1( DECX ),
INSTR_FMT1( DECY ), INSTR_FMT1( DECY ),
INSTR_FMT2( JUMP, 0 ) };
instruction_t prog3[ ] = { INSTR_FMT2( JUMP, 0 ) };
extern void display_environment( thread_t **, int );
entities[ 0 ] = thread_create( );
entities[ 0 ]->load( entities[ 0 ], Avatar, prog2, sizeof( prog2 ), 0, 0 );
entities[ 1 ] = thread_create( );
entities[ 1 ]->load( entities[ 1 ], Virus, prog2, sizeof( prog2 ), 5, 5 );
entities[ 2 ] = thread_create( );
entities[ 2 ]->load( entities[ 2 ], Goal, prog3, sizeof( prog3 ), 9, 9 );
for ( i = 0 ; i < 100 ; i++ )
{
for ( j = 0 ; j < MAX_ENTITIES ; j++ )
{
// printf("Entity %d -- PC: %4d, CYC: %6d, X: %4d, Y: %4d\n",
// entities[ j ]->entity,
// entities[ j ]->registers.pc, entities[ j ]->registers.cyc,
// entities[ j ]->registers.x, entities[ j ]->registers.y );
entities[ j ]->step( entities[ j ] );
}
display_environment( entities, MAX_ENTITIES );
}
for ( j = 0 ; j < MAX_ENTITIES ; j++ )
{
thread_destroy( entities[ j ] );
}
return 0;
}
// Game Loop
// Pre-game, show environment, user defines avatar's program.
// Start-game, interpret each of the entities
// Iterate entities to interp
// Iterate entities to check for collision
// Draw environment