-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
416 lines (314 loc) · 16.7 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <limits.h>
/* An option that only makes sense for the Linux; more precisely, switching
between direct terminal or ncurses output: */
#define USE_NCURSES
// CMake will be here... Someday...
#include "defines.h" // Constants, defines, ...
#include "internal.h" // Core and memory data.
#include "opmatrix.h" // Opcodes matrix.
#include "bios.c" // QuasiBIOS functions.
#include "memory_op.c" // Memory opcodes.
#include "arithm_op.c" // Math opcodes (both for integers and float-point digits).
#include "logic_op.c" // Logical opcodes.
#include "jumps_op.c" // Jump, call and branch opcodes.
#include "other_op.c" // Other opcodes: int, reti, nop, brkp, stf, clf, ...
// ====================
// Emulator/VM
// ====================
void opcodeCall( opcode_pointer opcode ) {
#if 0
// Debug tracing (seems to be temporal):
printf( " [Trace 0x%04X: \"%5s ", proc.instructionptr, opcodes_matrix[ (int) curopc.id ].name );
//for ( int i = 0; i < argLengths.argsAmount - 1; i++ )
// printf( "%5Xh, ", curopc.args[ i ] );
//if ( argLengths.argsAmount > 0 )
// printf( "%5Xh", curopc.args[ argLengths.argsAmount - 1 ] );
puts( "\"]" );
opcode();
printf( " [\\Post regs: ra 0x%X; a0..a2 {0x%X, 0x%X, 0x%X}; t0..t2 {0x%X, 0x%X, 0x%X}; sf 0x%X; flags:", proc.ra, proc.a0, proc.a1, proc.a2, proc.t0, proc.t1, proc.t2, proc.sf );
if ( proc.flags & ZF )
putchar( 'Z' );
if ( proc.flags & SF )
putchar( 'S' );
if ( proc.flags & CF )
putchar( 'C' );
if ( proc.flags & OF )
putchar( 'O' );
if ( proc.flags & IF )
putchar( 'I' );
if ( proc.flags & TF )
putchar( 'T' );
if ( proc.flags & FDDF )
printf( "<fddp>" );
if ( proc.flags & FINF )
printf( "<finf>" );
if ( proc.flags & FXXF )
printf( "<fnan>" );
if ( proc.flags & RlModeF )
printf( "{REAL}" );
puts( "]" );
//if ( getch() == 'Q' )
// proc.flags |= EndEmulF;
#else
opcode();
#endif
}
void printFlags( void ) {
}
void queueInstruction( opcode_pointer opcode, const uint32 opcargs[ static const 4 ] ) {
if ( proc.instructionptr == 0 ) {
int16_t opcodeIndex = findOpcodeMatrixIndex( opcode );
if ( opcodeIndex >= 0 ) {
opcode_structtype_length argLengths = opcode_structtype_lengths[ opcodes_matrix[ opcodeIndex ].structType ];
uint32 startMemCell = proc.protectedModeMemStart;
uint32 newSrcMem = ( opcodeIndex << 26 );
uint32 curBitOffset = 6;
//printf( "OpcIdx. newSrcMem 0x%08X as ( 0x%x ) << 26\n", newSrcMem, opcodeIndex );
for ( int i = 0; i < argLengths.argsAmount; i++ ) {
uint16_t curLength = argLengths.lengths[ i ];
curBitOffset += curLength;
if ( opcargs[ i ] >= (uint32) ( 1 << curLength ) ) {
printf( "queueInstruction(). Warning: in opcode \"%s\" (args[%i] == 0x%04X) >= (field max length 0x%04X). Skipping.\n", opcodes_matrix[ (int) opcodeIndex ].name, i, opcargs[ i ], ( 1 << curLength ) );
getch();
} else {
uint32 newBitMask = ( ( opcargs[ i ] & ( ( 1 << curLength ) - 1 ) ) << ( 32 - curBitOffset ) );
newSrcMem |= newBitMask;
//printf( "arg[%i]. newSrcMem 0x%08X as ( 0x%X & 0x%04X ) << %i == 0x%04X\n", i, newSrcMem, opcargs[ i ], ( ( 1 << curLength ) - 1 ), ( 32 - curBitOffset ), newBitMask );
}
}
* (uint32 *) &mem[ startMemCell ] = newSrcMem;
printf( " 0x%04X: ", startMemCell );
for ( int i = 0; i < RISC_INSTRUCTION_LENGTH; i++ )
printf( "%02X ", mem[ startMemCell + i ] & 0xFF );
printf( "[Queue: opcode %-2u \"%s\", orig args %Xh %Xh %Xh %Xh)]\n", opcodeIndex, opcodes_matrix[ (int) opcodeIndex ].name, opcargs[ 0 ], opcargs[ 1 ], opcargs[ 2 ], opcargs[ 3 ] );
proc.protectedModeMemStart += RISC_INSTRUCTION_LENGTH;
} else {
printf( "queueInstruction(). Warning: unknown opcode (%i). Args[] == { %u, %u, %u, %u }.", opcodeIndex, opcargs[ 0 ], opcargs[ 1 ], opcargs[ 2 ], opcargs[ 3 ] );
getch();
}
} else {
puts( "queueInstruction(). Warning: tried to add an opcode during VM execution." );
}
} // of void queueInstruction( opcode_pointer opcode, const uint32 opcargs[ static const 4 ] ) {}
void setMemoryArray( uint32 address, char *source, uint16 amount ) {
memcpy( &mem[ address ], source, amount );
}
void setMemoryString( uint32 address, char *source ) {
strcpy( &mem[ address ], source );
}
int main( void ) {
proc.protectedModeMemStart = MEM_PROG_KERNEL_START;
proc.flags = IF | RlModeF;
#ifdef LINUX_NCURSES
initscr();
noecho();
#endif
// Tracer initialization and code:
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, MEM_INTERRUPTS_START } );
queueInstruction( op_store_dw_addr, ( uint32[ 4 ] ){ MEM_INTERRUPT_VECTOR_TABLE_EXCEPTIONS_START + findInterruptMatrixIndex( except_trace ) * 4, RgA0 } );
for ( int i = 0; i < opcodes_matrix_size; i++ )
setMemoryArray( MEM_INTERRUPTS_MEM_OPCODENAMES_START + i * 4, getOpcodeData( i )->name, 4 );
//for ( int i = MEM_INTERRUPTS_MEM_OPCODENAMES_START; i < MEM_INTERRUPTS_MEM_OPCODENAMES_END; i++ )
// putchar( mem[ i ] );
//getch();
setMemoryArray( MEM_INTERRUPTS_MEM_OPCODENAMES_START - 16, "[Trace] 0x\x0", 11 );
setMemoryArray( MEM_INTERRUPTS_MEM_OPCODENAMES_START - 5, " \x0", 5 );
uint32 savedInstructionPos = proc.protectedModeMemStart;
proc.protectedModeMemStart = MEM_INTERRUPTS_START + findInterruptMatrixIndex( except_trace ) * 4 - 8;
// 256 bytes: 56 opcodes, 8 variables of type int32.
uint32 interruptMemory = proc.protectedModeMemStart + 56 * 4;
//queueInstruction( op_brkp, ( uint32[ 4 ] ){ 0 } );
queueInstruction( op_store_dw_addr, ( uint32[ 4 ] ){ interruptMemory, RgRetAddr } );
queueInstruction( op_store_dw_addr, ( uint32[ 4 ] ){ interruptMemory + 4, RgA0 } );
queueInstruction( op_store_dw_addr, ( uint32[ 4 ] ){ interruptMemory + 8, RgA1 } );
queueInstruction( op_store_dw_addr, ( uint32[ 4 ] ){ interruptMemory + 12, RgA2 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, interruptMemory + 16 } );
queueInstruction( op_store_word, ( uint32[ 4 ] ){ RgA0, RgSavedFlags } );
queueInstruction( op_load_dw_addr, ( uint32[ 4 ] ){ RgA0, MEM_KERNELVARS_BIOS_SCREEN } );
queueInstruction( op_store_dw_addr, ( uint32[ 4 ] ){ interruptMemory + 20, RgA0 } );
//queueInstruction( op_brkp, ( uint32[ 4 ] ){ 0 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, 4 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 80 + 54 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_videomemory ) } ); // Moves cursor (subfunc 4h).
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, MEM_INTERRUPTS_MEM_OPCODENAMES_START - 16 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 0 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_print ) } ); // Prints a string ("[Trace] ").
//queueInstruction( op_load_dw_addr, ( uint32[ 4 ] ){ RgA0, MEM_KERNELVARS_TRACE_CUROPCODE_PREVADDR } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, MEM_KERNELVARS_TRACE_CUROPCODE_PREVADDR } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 4 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA2, 16 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_printdigit ) } ); // Prints a digit (return address).
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, MEM_INTERRUPTS_MEM_OPCODENAMES_START - 3 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 0 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_print ) } ); // Prints some spaces.
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA2, MEM_KERNELVARS_TRACE_CUROPCODE } );
queueInstruction( op_load_word, ( uint32[ 4 ] ){ RgA0, RgA2 } );
queueInstruction( op_shl_const, ( uint32[ 4 ] ){ RgA0, RgA0, 2 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, MEM_INTERRUPTS_MEM_OPCODENAMES_START } );
queueInstruction( op_add, ( uint32[ 4 ] ){ RgA0, RgA0, RgA1 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 0 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_print ) } ); // Prints a string (opcode name).
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, MEM_INTERRUPTS_MEM_OPCODENAMES_START - 5 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 0 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_print ) } ); // Prints a string (four spaces here).
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 2 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_print ) } ); // Prints a newline.
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_getkey ) } ); // Waits for the keystroke.
queueInstruction( op_load_dw_addr, ( uint32[ 4 ] ){ RgA0, interruptMemory + 20 } );
queueInstruction( op_store_dw_addr, ( uint32[ 4 ] ){ MEM_KERNELVARS_BIOS_SCREEN, RgA0 } ); // Reverts X/Y screen coords back.
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, interruptMemory + 16 } );
queueInstruction( op_load_word, ( uint32[ 4 ] ){ RgSavedFlags, RgA0 } );
queueInstruction( op_load_dw_addr, ( uint32[ 4 ] ){ RgA2, interruptMemory + 12 } );
queueInstruction( op_load_dw_addr, ( uint32[ 4 ] ){ RgA1, interruptMemory + 8 } );
queueInstruction( op_load_dw_addr, ( uint32[ 4 ] ){ RgA0, interruptMemory + 4 } );
queueInstruction( op_load_dw_addr, ( uint32[ 4 ] ){ RgRetAddr, interruptMemory } );
//queueInstruction( op_brkp, ( uint32[ 4 ] ){ 0 } );
queueInstruction( op_int_ret, ( uint32[ 4 ] ){ 0 } );
//queueInstruction( op_call_reg, ( uint32[ 4 ] ){ 0, 1, 0 } );
proc.protectedModeMemStart = savedInstructionPos;
//queueInstruction( op_clearflag, ( uint32[ 4 ] ){ RlModeF } );
// Test program:
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, 100 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 28 } );
queueInstruction( op_sub, ( uint32[ 4 ] ){ RgA0, RgA0, RgA1 } ); // 'H'
queueInstruction( op_add_const, ( uint32[ 4 ] ){ RgA1, RgA1, 77 } ); // 'i'
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgT3, 0x60000 } );
queueInstruction( op_store_lbyte, ( uint32[ 4 ] ){ RgT3, RgA0 } );
queueInstruction( op_store_lbyte, ( uint32[ 4 ] ){ RgT3, RgA1 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, '!' } ); // '!'
queueInstruction( op_store_lbyte, ( uint32[ 4 ] ){ RgT3, RgA0 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, 0 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 2 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_videomemory ) } ); // Videomemory output.
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, 4 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 999 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_videomemory ) } ); // Moves cursor (subfunc 4h).
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, 0x60000 } );
//queueInstruction( op_setflag, ( uint32[ 4 ] ){ TF } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 0 } );
queueInstruction( op_jmp_near, ( uint32[ 4 ] ){ 3 } );
queueInstruction( op_nop, ( uint32[ 4 ] ){ 0 } ); // Will be skipped;
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, 0xABCD } ); // Will be skipped.
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_print ) } ); // Prints a string (subtype 0h).
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 2 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_print ) } ); // A newline character (subtype 2h).
//queueInstruction( op_clearflag, ( uint32[ 4 ] ){ TF } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgT1, 1000 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgT0, 4 } );
queueInstruction( op_div, ( uint32[ 4 ] ){ RgT1, RgT0, RgT0, RgZero } ); // Eval (1000 / 4).
queueInstruction( op_store_dw_addr, ( uint32[ 4 ] ){ 0x60000, RgT0 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, 0x60000 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA2, 10 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_printdigit ) } ); // Prints a (1000 / 4) = "250".
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, 4 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 80 * 24 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_videomemory ) } ); // Moves cursor (subfunc 4h).
setMemoryString( 0x60020, "(Press 'q' to exit...)" );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA0, 0x60020 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 0 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_print ) } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( bios_getkey ) } ); // Waits for the keystroke.
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 'q' } );
queueInstruction( op_beq_near, ( uint32[ 4 ] ){ RgA0, RgA1, 4 } );
queueInstruction( op_mov_const, ( uint32[ 4 ] ){ RgA1, 'Q' } );
queueInstruction( op_beq_near, ( uint32[ 4 ] ){ RgA0, RgA1, 2 } );
queueInstruction( op_jmp_near, ( uint32[ 4 ] ){ 0xFFFF - 5 } );
queueInstruction( op_int, ( uint32[ 4 ] ){ FINDINT( except_end_emulation ) } ); // Ends emulation (via quasiBIOS).
puts( "================" );
proc.protectedModeMemStart += ( 1024 - proc.protectedModeMemStart ) % 1024;
proc.instructionptr = MEM_PROG_KERNEL_START;
const int MAX_EXIT_DOWNCOUNTER = 386;
int exit_countdown = MAX_EXIT_DOWNCOUNTER;
//uint32 last_opcode_id_exitcheck = 0;
uint32 traceExceptionIndex = FINDINT( except_trace );
uint32 prevInstructionPtr = proc.instructionptr;
while ( !( proc.flags & EndEmulF ) ) {
if ( proc.instructionptr >= MAX_MEM ) {
printf( "main(). Instruction pointer is out-of-bounds (0x%08X, max mem 0x%08X).\n", proc.instructionptr, MAX_MEM );
proc.flags |= EndEmulF;
} else if ( !( proc.flags & RlModeF ) && proc.instructionptr <= MEM_KERNEL_END ) {
int tmp = proc.a0;
proc.a0 = proc.instructionptr;
curopc.args[ 0 ] = findInterruptMatrixIndex( except_not_real_mode );
op_int();
proc.a0 = tmp;
} else {
// Parsing:
curopc.srcmem.t32 = * (uint32 *) &mem[ proc.instructionptr ];
curopc.id = ( curopc.srcmem.t32 >> 26 );
opcode_data *opcode = getOpcodeData( curopc.id );
opcode_structtype_length argLengths = opcode_structtype_lengths[ opcodes_matrix[ (int) curopc.id ].structType ];
uint32 curSrcMem = ( curopc.srcmem.t32 << 6 );
//printf( "OpcIdx. curSrcMem 0x%08X (at 0x%04X)\n", curSrcMem, proc.instructionptr );
for ( int i = 0; i < argLengths.argsAmount; i++ ) {
uint_fast8_t curLength = argLengths.lengths[ i ];
curopc.args[ i ] = ( curSrcMem >> ( 32 - curLength ) );
curSrcMem = ( curSrcMem << curLength );
//printf( "arg %i: 0x%04X. curSrcMem 0x%08X >> %i\n", i, curopc.args[ i ], curSrcMem, 32 - curLength );
}
for ( int i = argLengths.argsAmount; i < 4; i++ )
curopc.args[ i ] = 0;
opcodeCall( opcode->address );
// Trace interrupt call:
if ( ( proc.flags & ( TF | EndEmulF ) ) == TF ) {
mem[ MEM_KERNELVARS_TRACE_CUROPCODE ] = curopc.id;
mem[ MEM_KERNELVARS_TRACE_CUROPCODE_ARGSAMOUNT ] = argLengths.argsAmount;
mem[ MEM_KERNELVARS_TRACE_CUROPCODE_ARGSTYPE ] = opcodes_matrix[ (int) curopc.id ].structType;
* (uint32 *) &mem[ MEM_KERNELVARS_TRACE_CUROPCODE_PREVADDR ] = prevInstructionPtr;
for ( int i = 0; i < 4; i++ )
* (uint32 *) &mem[ MEM_KERNELVARS_TRACE_OPCARG_START + i * 4 ] = curopc.args[ i ];
//printf( " [TF. ID %i, uint[ %i ] args type %i.\n", mem[ MEM_KERNELVARS_TRACE_CUROPCODE ], mem[ MEM_KERNELVARS_TRACE_CUROPCODE_ARGSAMOUNT ], mem[ MEM_KERNELVARS_TRACE_CUROPCODE_ARGSTYPE ] );
if ( proc.instructionptr != prevInstructionPtr )
proc.instructionptr -= RISC_INSTRUCTION_LENGTH;
int tmp = curopc.args[ 0 ];
curopc.args[ 0 ] = traceExceptionIndex;
opcodeCall( op_int );
curopc.args[ 0 ] = tmp;
}
}
if ( proc.flags & PostTF )
proc.flags = ( proc.flags & ~PostTF ) | TF;
// Videopage handling:
if ( ( proc.flags & VUF ) && BIOS_OUTPUT_VIDEOPAGE == ( ( *screenvar & 0xFF0000 ) >> 16 ) ) {
clrscr();
char outline[ 82 ] = { 0 };
for ( int i = 0; i < 25; i++ ) {
memcpy( outline, &mem[ MEM_VIDEOPAGE_START + i * 80 ], 80 );
#ifdef LINUX_OS
// It's strange, but "fwrite()" on Linux seems to output only non-null characters.
for ( int j = 0; j < 80; j++ )
if ( outline[ j ] < ' ' )
outline[ j ] = ' ';
printf( "%s", outline );
#else
fwrite( outline, 80, sizeof( char ), stdout );
#endif
puts( "|" );
}
// Lower screen border:
memset( outline, '-', 80 );
outline[ 80 ] = '/';
puts( outline );
proc.flags &= ~VUF;
}
if ( proc.instructionptr == prevInstructionPtr )
proc.instructionptr += RISC_INSTRUCTION_LENGTH;
prevInstructionPtr = proc.instructionptr;
proc.zero = 0;
// Emergency exit check:
if ( --exit_countdown <= 0 ) {
printf( "main(). Exit downcounter (%i) reaches zero.\n", MAX_EXIT_DOWNCOUNTER );
proc.flags |= EndEmulF;
}
} // of while ( !( proc.flags & EndEmulF ) ) {}
#ifdef LINUX_NCURSES
printf( "\nPress any key to exit from the ncurses mode... " );
getch();
endwin();
#endif
return 0;
}