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"
19 FILE* f = fopen(fname,
"r");
21 ERROR(
"An error occured opening the file %s!\n", fname);
22 ERROR(
"Error opening file: %s\n", strerror(errno));
36 while (x = fgetc(f), x !=
'\n' && x != EOF);
40 if (list == NULL)
goto ERR_MEM;
45 while (x = fgetc(f), x != EOF) {
46 if (x ==
'\r')
continue;
47 if (x ==
';' || x ==
'\n') {
53 if (ptr != 3)
goto ERR_MALFORMED;
54 memcpy(curr->
mnem, buff, 3);
57 if (ptr != 2 && ptr != 0)
goto ERR_MALFORMED;
72 if (curr->
next == NULL)
goto ERR_MEM;
87 for (curr = list; curr->
next != NULL && curr->
next->
next != NULL; curr = curr->
next);
95 ERROR(
"Malformed instruction line:column: %d : %d\n", row + 1, rowindex + 1);
96 ERROR(
"Malformed instructions/opcodes file: %s\n", fname);
100 ERROR(
"Memory allocation error in instruction_load()!\n");
113 for (ptr = list; ptr != NULL; ptr = ptr->
next) {
123 while (list->
next != NULL) {
133 printf(
"%s", instr->
mnem);
142 for (; list != NULL; list = list->
next) {
const char * ADRM_NAMES[]
Human-readable names of address modes.
@ ADRM_COUNT
Total number of addressing modes.
void instruction_free(Instruction *list)
free all memory associated with an Instruction* list
void instruction_print_all(Instruction *list)
debug-print all instructions in a list
char mnem[4]
3-letter mnemonic of an instruction + trailing 0
struct Instruction * next
Next instruction pointer on NULL.
void instruction_print(Instruction *instr)
fancy-print one instruction data
Instruction * instruction_load(char *fname)
Load instruction data from CSV file.
AddressMode enum and related data.
int util_match_string(char *first, char *second, int count)
case-insensitive memcmp
linked list member holding instruction data
Instruction data and related operations.
logging and fancy-printing
unsigned char opcs[ADRM_COUNT]
Different combinarions of this instruction. Invalid ones are set to OPC_INVALID.
int number_char_to_digit(char c)
Convert a hex char to a digit.
Instruction * instruction_find(Instruction *list, char *mnem)
find the Instruction entry for a given mnemonic
Number module to parse numbers.
various utility functions
@ OPC_INVALID
An invalid opcode to signal invalid / non-existent variations.
#define ERROR(...)
Fancy-print an error (cause of faliure). Works like printf.