ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
worker_6502.c
Go to the documentation of this file.
1#include "../tester.h"
2
3void execute6502( Environment * _environment, char * _asm_filename, Variable * _variable ) {
4
5 char * binaryFileNameRoot = get_temporary_filename( _environment );
6 char * mapFileNameRoot = get_temporary_filename( _environment );
7
8 char binaryFileName[MAX_TEMPORARY_STORAGE];
9 sprintf( binaryFileName, "%s.bin", binaryFileNameRoot );
10 char mapFileName[MAX_TEMPORARY_STORAGE];
11 sprintf( mapFileName, "%s.lbl", mapFileNameRoot );
12
13 char commandLine[4*MAX_TEMPORARY_STORAGE];
14 sprintf( commandLine, "cl65 -g -Ln %s --start-addr 32768 -t none -o %s %s", mapFileName, binaryFileName, _asm_filename );
15 // printf( "%s\n", commandLine );
16 (void)!system( commandLine );
17 sprintf( commandLine, "run6502 -l 8000 %s -R 8000 -X 0000 -D", binaryFileName );
18 // printf( "%s\n", commandLine );
19 (void)!system( commandLine );
20
21 unsigned char memory[0xffff];
22 memset( memory, 0, 0xffff );
23
24 FILE * dumpFile = fopen( "run6502.dump", "rb" );
25 if ( dumpFile ) {
26 (void)!fread( &memory[0], 1, 0xffff, dumpFile );
27 fclose( dumpFile );
28 }
29
30 FILE * mapFile = fopen( mapFileName, "r" );
31 if ( mapFile ) {
32 while( ! feof( mapFile ) ) {
33 char type[32];
34 unsigned int address;
35 char name[256];
36
37 (void)!fscanf( mapFile, "%s %x .%s", type, &address, name );
38
39 Variable * v = _variable;
40 while ( v ) {
41 if ( strcmp( v->name, name ) == 0 ) {
42 switch( VT_BITWIDTH( v->type ) ) {
43 case 0: {
44 switch( v->type ) {
45 case VT_FLOAT: {
46 int value[4];
47 value[0] = memory[address];
48 value[1] = memory[address+1];
49 value[2] = memory[address+2];
50 value[3] = memory[address+3];
51 cpu_float_single_from_int_array_to_double( _environment, &value[0], &v->valueFloating );
52 break;
53 }
54 }
55 }
56 break;
57 case 8:
58 v->value = memory[address];
59 break;
60 case 16:
61 v->value = memory[address] | ( memory[address+1] << 8 );
62 break;
63 case 24:
64 v->value = memory[address] | ( memory[address+1] << 8 ) | ( memory[address+2] << 16 );
65 break;
66 case 32:
67 v->value = memory[address] | ( memory[address+1] << 8 ) | ( memory[address+2] << 16 ) | ( memory[address+3] << 24 );
68 break;
69 }
70 }
71 v = v->next;
72 }
73
74 // printf( "%s = %x [%2.2x]\n", name, address, (unsigned char) memory[address] );
75
76 }
77 }
78
79 remove( binaryFileName );
80 remove( mapFileName );
81 remove( "run6502.dump" );
82
83}
void cpu_float_single_from_int_array_to_double(Environment *_environment, int _value[], double *_result)
Definition 6502.c:8709
char * get_temporary_filename(Environment *_environment)
char * name
Definition _optimizer.c:672
double valueFloating
Definition ugbc.h:1046
struct _Variable * next
Definition ugbc.h:1225
char * name
Definition ugbc.h:979
VariableType type
Definition ugbc.h:988
int value
Definition ugbc.h:1025
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_FLOAT
Definition ugbc.h:522
#define VT_BITWIDTH(t)
Definition ugbc.h:595
void execute6502(Environment *_environment, char *_asm_filename, Variable *_variable)
Definition worker_6502.c:3