s502 assembler
A very simple assembler for the 6502 line of processors written in C
|
Go to the documentation of this file. 1 #include "debugmalloc.h"
20 ERROR(
"Memory allocation error in state_new()");
31 strcpy(ret->
outfile,
"out.bin");
35 FAIL(
"state_new() failed!\n");
43 if (s->
instr == NULL)
return -1;
62 printf(
"6502 compiler program\nMade by Laszlo Barath in 2020\n\n");
63 printf(
"Useage:\n> %s [args] <inputfile>\n", pname);
65 printf(
"Arguments:\n");
66 printf(
"\t--output (-o):\tSpecify output file. Expects a file name (max %d chars). Default is 'out.bin'.\n",
STATE_MAX_STRING_LEN - 1);
67 printf(
"\t--define (-d):\tSpecify a constant. Expects a name (max %d chars) and a (decimal) number.\n",
MAP_MAX_KEY_LEN - 1);
68 printf(
"\t--log (-l):\tSet log level. Expects a number in range 1-5. Default is 1.\n");
69 printf(
"\t--help (-h):\tprints this message. Expects no parameters.\n");
77 printf(
"Use the '-h' or --help switches to get more info!\n");
82 for (
int i = 1; i < argc; i++) {
83 if (!strcmp(argv[i],
"-o") || !strcmp(argv[i],
"--out")) {
86 ERROR(
"Argument '%s' excepts parameter(s)!\n", argv[i]);
90 char* param = argv[++i];
95 if (param[0] ==
'-') {
96 ERROR(
"Output file name can not start with a dash ('-')!\n");
100 }
else if (!strcmp(argv[i],
"-l") || !strcmp(argv[i],
"--log")) {
103 ERROR(
"Argument '%s' excepts parameter(s)!\n", argv[i]);
107 char* param = argv[++i];
109 if (sscanf(param,
"%d", &level) != 1) {
110 ERROR(
"Can not parse log level!\n");
114 }
else if (!strcmp(argv[i],
"-d") || !strcmp(argv[i],
"--define")) {
116 if (i == argc - 2 || i == argc - 1) {
117 ERROR(
"Argument '%s' excepts parameter(s)!\n", argv[i]);
121 char*
name = argv[++i];
122 char*
value = argv[++i];
124 if (sscanf(
value,
"%d", &num) != 1) {
125 ERROR(
"Can not parse value of define '%s': '%s'!\n",
name,
value);
133 }
else if (!strcmp(argv[i],
"-h") || !strcmp(argv[i],
"--help")) {
143 if (argv[i][0] ==
'-') {
144 ERROR(
"Input file name ('%s') can not start with a dash ('-')!\n", argv[i]);
151 ERROR(
"No input file was given!\n");
Map * labels
label locations
void tokenslist_free(TokensList *list)
free ALL memory associated with the TokensList object
int map_set(Map *map, char *name, int value)
Sets a key in the map.
char infile[STATE_MAX_STRING_LEN]
input file name
void instruction_free(Instruction *list)
free all memory associated with an Instruction* list
Instruction * instr
instruction data
int logging_level(int level)
pseudo-global accessor
TokensList * tokens
tokens
Compiler pseudo-global state.
int state_load_instr(State *s, char *fname)
load instructions from a file
Map * defines
defined constants
void print_short_help()
print the "use --help" text
State * state_new()
Create a new State object.
char outfile[STATE_MAX_STRING_LEN]
output file name
void state_free(State *s)
free a State object and all associated memory
Instruction * instruction_load(char *fname)
Load instruction data from CSV file.
int state_parse_commandline(State *s, int argc, char **argv)
parse command line arguments and update state
void map_free(Map *map)
Free the map with all associated memory.
char name[MAP_MAX_KEY_LEN]
key of the entry
logging and fancy-printing
@ MAP_MAX_KEY_LEN
Key buffer size for Map.
@ STATE_MAX_STRING_LEN
max string length for input/output files
void print_help(char *pname)
print some help on the useage of the program
#define FAIL(...)
Fancy-print a fail (failed step). Works like printf.
#define ERROR(...)
Fancy-print an error (cause of faliure). Works like printf.
Map * map_new()
Create a new map with 0 elements.
int value
the value the entry holds