mirror of
https://github.com/uffejakobsen/acme.git
synced 2024-12-24 16:29:23 +00:00
added comments, cleaned up some struct and variable names - no change in functionality at all
git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@27 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
parent
f1341c44fd
commit
538dd38861
@ -17,7 +17,7 @@
|
||||
|
||||
#define RELEASE "0.94.8" // update before release (FIXME)
|
||||
#define CODENAME "Zarquon" // update before release
|
||||
#define CHANGE_DATE "10 Mar" // update before release
|
||||
#define CHANGE_DATE "11 Mar" // update before release
|
||||
#define CHANGE_YEAR "2014" // update before release
|
||||
//#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/" // FIXME
|
||||
#define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME
|
||||
|
160
src/alu.c
160
src/alu.c
@ -83,79 +83,79 @@ enum operator_handle {
|
||||
OPHANDLE_EOR, // v EOR w v XOR w (FIXME:remove)
|
||||
OPHANDLE_XOR, // v XOR w
|
||||
};
|
||||
struct operator_t {
|
||||
struct operator {
|
||||
enum operator_handle handle;
|
||||
char priority_and_associativity;
|
||||
};
|
||||
#define IS_RIGHT_ASSOCIATIVE(p) ((p) & 1) // lsb of priority value signals right-associtivity
|
||||
|
||||
// operator structs (only hold handle and priority/associativity value)
|
||||
static struct operator_t ops_end = {OPHANDLE_END, 0}; // special
|
||||
static struct operator_t ops_return = {OPHANDLE_RETURN, 2}; // special
|
||||
static struct operator_t ops_closing = {OPHANDLE_CLOSING, 4}; // dyadic
|
||||
static struct operator_t ops_opening = {OPHANDLE_OPENING, 6}; // monadic
|
||||
static struct operator_t ops_or = {OPHANDLE_OR, 8}; // dyadic
|
||||
static struct operator_t ops_eor = {OPHANDLE_EOR, 10}; // (FIXME:remove)
|
||||
static struct operator_t ops_xor = {OPHANDLE_XOR, 10}; // dyadic
|
||||
static struct operator_t ops_and = {OPHANDLE_AND, 12}; // dyadic
|
||||
static struct operator_t ops_equals = {OPHANDLE_EQUALS, 14}; // dyadic
|
||||
static struct operator_t ops_notequal = {OPHANDLE_NOTEQUAL, 16}; // dyadic
|
||||
static struct operator ops_end = {OPHANDLE_END, 0}; // special
|
||||
static struct operator ops_return = {OPHANDLE_RETURN, 2}; // special
|
||||
static struct operator ops_closing = {OPHANDLE_CLOSING, 4}; // dyadic
|
||||
static struct operator ops_opening = {OPHANDLE_OPENING, 6}; // monadic
|
||||
static struct operator ops_or = {OPHANDLE_OR, 8}; // dyadic
|
||||
static struct operator ops_eor = {OPHANDLE_EOR, 10}; // (FIXME:remove)
|
||||
static struct operator ops_xor = {OPHANDLE_XOR, 10}; // dyadic
|
||||
static struct operator ops_and = {OPHANDLE_AND, 12}; // dyadic
|
||||
static struct operator ops_equals = {OPHANDLE_EQUALS, 14}; // dyadic
|
||||
static struct operator ops_notequal = {OPHANDLE_NOTEQUAL, 16}; // dyadic
|
||||
// same priority for all comparison operators (left-associative)
|
||||
static struct operator_t ops_le = {OPHANDLE_LE, 18}; // dyadic
|
||||
static struct operator_t ops_lessthan = {OPHANDLE_LESSTHAN, 18}; // dyadic
|
||||
static struct operator_t ops_ge = {OPHANDLE_GE, 18}; // dyadic
|
||||
static struct operator_t ops_greaterthan = {OPHANDLE_GREATERTHAN,18}; // dyadic
|
||||
static struct operator ops_le = {OPHANDLE_LE, 18}; // dyadic
|
||||
static struct operator ops_lessthan = {OPHANDLE_LESSTHAN, 18}; // dyadic
|
||||
static struct operator ops_ge = {OPHANDLE_GE, 18}; // dyadic
|
||||
static struct operator ops_greaterthan = {OPHANDLE_GREATERTHAN,18}; // dyadic
|
||||
// same priority for all byte extraction operators
|
||||
static struct operator_t ops_lowbyteof = {OPHANDLE_LOWBYTEOF, 20}; // monadic
|
||||
static struct operator_t ops_highbyteof = {OPHANDLE_HIGHBYTEOF, 20}; // monadic
|
||||
static struct operator_t ops_bankbyteof = {OPHANDLE_BANKBYTEOF, 20}; // monadic
|
||||
static struct operator ops_lowbyteof = {OPHANDLE_LOWBYTEOF, 20}; // monadic
|
||||
static struct operator ops_highbyteof = {OPHANDLE_HIGHBYTEOF, 20}; // monadic
|
||||
static struct operator ops_bankbyteof = {OPHANDLE_BANKBYTEOF, 20}; // monadic
|
||||
// same priority for all shift operators (left-associative, though they could be argued to be made right-associative :))
|
||||
static struct operator_t ops_sl = {OPHANDLE_SL, 22}; // dyadic
|
||||
static struct operator_t ops_asr = {OPHANDLE_ASR, 22}; // dyadic
|
||||
static struct operator_t ops_lsr = {OPHANDLE_LSR, 22}; // dyadic
|
||||
static struct operator ops_sl = {OPHANDLE_SL, 22}; // dyadic
|
||||
static struct operator ops_asr = {OPHANDLE_ASR, 22}; // dyadic
|
||||
static struct operator ops_lsr = {OPHANDLE_LSR, 22}; // dyadic
|
||||
// same priority for "+" and "-" (left-associative)
|
||||
static struct operator_t ops_add = {OPHANDLE_ADD, 24}; // dyadic
|
||||
static struct operator_t ops_subtract = {OPHANDLE_SUBTRACT, 24}; // dyadic
|
||||
static struct operator ops_add = {OPHANDLE_ADD, 24}; // dyadic
|
||||
static struct operator ops_subtract = {OPHANDLE_SUBTRACT, 24}; // dyadic
|
||||
// same priority for "*", "/" and "%" (left-associative)
|
||||
static struct operator_t ops_multiply = {OPHANDLE_MULTIPLY, 26}; // dyadic
|
||||
static struct operator_t ops_divide = {OPHANDLE_DIVIDE, 26}; // dyadic
|
||||
static struct operator_t ops_intdiv = {OPHANDLE_INTDIV, 26}; // dyadic
|
||||
static struct operator_t ops_modulo = {OPHANDLE_MODULO, 26}; // dyadic
|
||||
static struct operator ops_multiply = {OPHANDLE_MULTIPLY, 26}; // dyadic
|
||||
static struct operator ops_divide = {OPHANDLE_DIVIDE, 26}; // dyadic
|
||||
static struct operator ops_intdiv = {OPHANDLE_INTDIV, 26}; // dyadic
|
||||
static struct operator ops_modulo = {OPHANDLE_MODULO, 26}; // dyadic
|
||||
// highest "real" priorities
|
||||
static struct operator_t ops_negate = {OPHANDLE_NEGATE, 28}; // monadic
|
||||
static struct operator_t ops_powerof = {OPHANDLE_POWEROF, 29}; // dyadic, right-associative
|
||||
static struct operator_t ops_not = {OPHANDLE_NOT, 30}; // monadic
|
||||
static struct operator ops_negate = {OPHANDLE_NEGATE, 28}; // monadic
|
||||
static struct operator ops_powerof = {OPHANDLE_POWEROF, 29}; // dyadic, right-associative
|
||||
static struct operator ops_not = {OPHANDLE_NOT, 30}; // monadic
|
||||
// function calls act as if they were monadic operators
|
||||
static struct operator_t ops_int = {OPHANDLE_INT, 32}; // function
|
||||
static struct operator_t ops_float = {OPHANDLE_FLOAT, 32}; // function
|
||||
static struct operator_t ops_sin = {OPHANDLE_SIN, 32}; // function
|
||||
static struct operator_t ops_cos = {OPHANDLE_COS, 32}; // function
|
||||
static struct operator_t ops_tan = {OPHANDLE_TAN, 32}; // function
|
||||
static struct operator_t ops_arcsin = {OPHANDLE_ARCSIN, 32}; // function
|
||||
static struct operator_t ops_arccos = {OPHANDLE_ARCCOS, 32}; // function
|
||||
static struct operator_t ops_arctan = {OPHANDLE_ARCTAN, 32}; // function
|
||||
static struct operator ops_int = {OPHANDLE_INT, 32}; // function
|
||||
static struct operator ops_float = {OPHANDLE_FLOAT, 32}; // function
|
||||
static struct operator ops_sin = {OPHANDLE_SIN, 32}; // function
|
||||
static struct operator ops_cos = {OPHANDLE_COS, 32}; // function
|
||||
static struct operator ops_tan = {OPHANDLE_TAN, 32}; // function
|
||||
static struct operator ops_arcsin = {OPHANDLE_ARCSIN, 32}; // function
|
||||
static struct operator ops_arccos = {OPHANDLE_ARCCOS, 32}; // function
|
||||
static struct operator ops_arctan = {OPHANDLE_ARCTAN, 32}; // function
|
||||
|
||||
|
||||
// variables
|
||||
static struct dynabuf_t *function_dyna_buf; // dynamic buffer for fn names
|
||||
static struct operator_t **operator_stack = NULL;
|
||||
static struct dynabuf *function_dyna_buf; // dynamic buffer for fn names
|
||||
static struct operator **operator_stack = NULL;
|
||||
static int operator_stk_size = HALF_INITIAL_STACK_SIZE;
|
||||
static int operator_sp; // operator stack pointer
|
||||
static struct result_t *operand_stack = NULL; // flags and value
|
||||
static struct result_t *operand_stack = NULL; // flags and value
|
||||
static int operand_stk_size = HALF_INITIAL_STACK_SIZE;
|
||||
static int operand_sp; // value stack pointer
|
||||
static int indirect_flag; // Flag for indirect addressing
|
||||
// (indicated by useless parentheses)
|
||||
// Contains either 0 or MVALUE_INDIRECT
|
||||
enum alu_state_t {
|
||||
enum alu_state {
|
||||
STATE_EXPECT_OPERAND_OR_MONADIC_OPERATOR,
|
||||
STATE_EXPECT_DYADIC_OPERATOR,
|
||||
STATE_TRY_TO_REDUCE_STACKS,
|
||||
STATE_MAX_GO_ON, // "border value" to find the stoppers:
|
||||
STATE_ERROR, // error has occured
|
||||
STATE_END, // standard end
|
||||
STATE_END // standard end
|
||||
};
|
||||
static enum alu_state_t alu_state; // deterministic finite automaton
|
||||
static enum alu_state alu_state; // deterministic finite automaton
|
||||
// predefined stuff
|
||||
static struct node_t *operator_tree = NULL; // tree to hold operators
|
||||
static struct node_t operator_list[] = {
|
||||
@ -309,7 +309,7 @@ static intval_t my_asr(intval_t left, intval_t right)
|
||||
// label name is stored!
|
||||
static void get_label_value(zone_t zone)
|
||||
{
|
||||
struct label_t *label;
|
||||
struct label *label;
|
||||
|
||||
// if the label gets created now, mark it as unsure
|
||||
label = Label_find(zone, MVALUE_UNSURE);
|
||||
@ -482,6 +482,15 @@ static void parse_octal_value(void) // Now GotByte = "&"
|
||||
}
|
||||
|
||||
|
||||
// Parse program counter ('*')
|
||||
static void parse_program_counter(void) // Now GotByte = "*"
|
||||
{
|
||||
GetByte();
|
||||
// FIXME - read pc via function call, then move cpu struct from .h to .c file
|
||||
PUSH_INTOPERAND(CPU_state.pc.intval, CPU_state.pc.flags | MVALUE_EXISTS);
|
||||
}
|
||||
|
||||
|
||||
// Parse binary value. Apart from '0' and '1', it also accepts the characters
|
||||
// '.' and '#', this is much more readable. The current value is stored as soon
|
||||
// as a character is read that is none of those given above.
|
||||
@ -531,7 +540,7 @@ static void parse_function_call(void)
|
||||
DynaBuf_to_lower(function_dyna_buf, GlobalDynaBuf);
|
||||
// search for tree item
|
||||
if (Tree_easy_scan(function_tree, &node_body, function_dyna_buf))
|
||||
PUSH_OPERATOR((struct operator_t*) node_body);
|
||||
PUSH_OPERATOR((struct operator*) node_body);
|
||||
else
|
||||
Throw_error("Unknown function.");
|
||||
}
|
||||
@ -540,8 +549,8 @@ static void parse_function_call(void)
|
||||
// Expect operand or monadic operator (hopefully inlined)
|
||||
static void expect_operand_or_monadic_operator(void)
|
||||
{
|
||||
struct operator_t *operator;
|
||||
int perform_negation;
|
||||
struct operator *operator;
|
||||
int perform_negation;
|
||||
|
||||
SKIPSPACE();
|
||||
switch (GotByte) {
|
||||
@ -623,8 +632,7 @@ static void expect_operand_or_monadic_operator(void)
|
||||
goto now_expect_dyadic;
|
||||
|
||||
case '*': // Program counter
|
||||
GetByte(); // proceed with next char
|
||||
PUSH_INTOPERAND(CPU_state.pc.intval, CPU_state.pc.flags | MVALUE_EXISTS);
|
||||
parse_program_counter();
|
||||
// Now GotByte = char after closing quote
|
||||
goto now_expect_dyadic;
|
||||
|
||||
@ -708,61 +716,61 @@ now_expect_dyadic:
|
||||
// Expect dyadic operator (hopefully inlined)
|
||||
static void expect_dyadic_operator(void)
|
||||
{
|
||||
void *node_body;
|
||||
struct operator_t *op;
|
||||
void *node_body;
|
||||
struct operator *operator;
|
||||
|
||||
SKIPSPACE();
|
||||
switch (GotByte) {
|
||||
// Single-character dyadic operators
|
||||
case '^': // "to the power of"
|
||||
op = &ops_powerof;
|
||||
operator = &ops_powerof;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
case '+': // add
|
||||
op = &ops_add;
|
||||
operator = &ops_add;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
case '-': // subtract
|
||||
op = &ops_subtract;
|
||||
operator = &ops_subtract;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
case '*': // multiply
|
||||
op = &ops_multiply;
|
||||
operator = &ops_multiply;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
case '/': // divide
|
||||
op = &ops_divide;
|
||||
operator = &ops_divide;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
case '%': // modulo
|
||||
op = &ops_modulo;
|
||||
operator = &ops_modulo;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
case '&': // bitwise AND
|
||||
op = &ops_and;
|
||||
operator = &ops_and;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
case '|': // bitwise OR
|
||||
op = &ops_or;
|
||||
operator = &ops_or;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
// This part is commented out because there is no XOR character defined
|
||||
// case ???: // bitwise exclusive OR
|
||||
// op = &ops_xor;
|
||||
// operator = &ops_xor;
|
||||
// goto get_byte_and_push_dyadic;
|
||||
|
||||
case '=': // is equal
|
||||
op = &ops_equals;
|
||||
operator = &ops_equals;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
case ')': // closing parenthesis
|
||||
op = &ops_closing;
|
||||
operator = &ops_closing;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
// Multi-character dyadic operators
|
||||
case '!': // "!="
|
||||
if (GetByte() == '=') {
|
||||
op = &ops_notequal;
|
||||
operator = &ops_notequal;
|
||||
goto get_byte_and_push_dyadic;
|
||||
}
|
||||
|
||||
@ -772,19 +780,19 @@ static void expect_dyadic_operator(void)
|
||||
case '<': // "<", "<=", "<<" and "<>"
|
||||
switch (GetByte()) {
|
||||
case '=': // "<=", less or equal
|
||||
op = &ops_le;
|
||||
operator = &ops_le;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
case '<': // "<<", shift left
|
||||
op = &ops_sl;
|
||||
operator = &ops_sl;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
case '>': // "<>", not equal
|
||||
op = &ops_notequal;
|
||||
operator = &ops_notequal;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
default: // "<", less than
|
||||
op = &ops_lessthan;
|
||||
operator = &ops_lessthan;
|
||||
goto push_dyadic;
|
||||
|
||||
}
|
||||
@ -792,23 +800,23 @@ static void expect_dyadic_operator(void)
|
||||
case '>': // ">", ">=", ">>", ">>>" and "><"
|
||||
switch (GetByte()) {
|
||||
case '=': // ">=", greater or equal
|
||||
op = &ops_ge;
|
||||
operator = &ops_ge;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
case '<': // "><", not equal
|
||||
op = &ops_notequal;
|
||||
operator = &ops_notequal;
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
case '>': // ">>" or ">>>", shift right
|
||||
op = &ops_asr; // arithmetic shift right
|
||||
operator = &ops_asr; // arithmetic shift right
|
||||
if (GetByte() != '>')
|
||||
goto push_dyadic;
|
||||
|
||||
op = &ops_lsr; // logical shift right
|
||||
operator = &ops_lsr; // logical shift right
|
||||
goto get_byte_and_push_dyadic;
|
||||
|
||||
default: // ">", greater than
|
||||
op = &ops_greaterthan;
|
||||
operator = &ops_greaterthan;
|
||||
goto push_dyadic;
|
||||
|
||||
}
|
||||
@ -821,7 +829,7 @@ static void expect_dyadic_operator(void)
|
||||
// Now GotByte = illegal char
|
||||
// search for tree item
|
||||
if (Tree_easy_scan(operator_tree, &node_body, GlobalDynaBuf)) {
|
||||
op = node_body;
|
||||
operator = node_body;
|
||||
goto push_dyadic;
|
||||
}
|
||||
|
||||
@ -829,7 +837,7 @@ static void expect_dyadic_operator(void)
|
||||
Throw_error("Unknown operator.");
|
||||
alu_state = STATE_ERROR;
|
||||
} else {
|
||||
op = &ops_end;
|
||||
operator = &ops_end;
|
||||
goto push_dyadic;
|
||||
}
|
||||
|
||||
@ -840,7 +848,7 @@ static void expect_dyadic_operator(void)
|
||||
get_byte_and_push_dyadic:
|
||||
GetByte();
|
||||
push_dyadic:
|
||||
PUSH_OPERATOR(op);
|
||||
PUSH_OPERATOR(operator);
|
||||
alu_state = STATE_TRY_TO_REDUCE_STACKS;
|
||||
}
|
||||
|
||||
|
34
src/basics.c
34
src/basics.c
@ -24,11 +24,11 @@ static const char s_08[] = "08";
|
||||
|
||||
|
||||
// variables
|
||||
static struct dynabuf_t *user_message; // dynamic buffer (!warn/error/serious)
|
||||
static struct dynabuf *user_message; // dynamic buffer (!warn/error/serious)
|
||||
|
||||
|
||||
// helper function for !8, !16, !24 and !32 pseudo opcodes
|
||||
static enum eos_t output_objects(void (*fn)(intval_t))
|
||||
static enum eos output_objects(void (*fn)(intval_t))
|
||||
{
|
||||
do
|
||||
fn(ALU_any_int());
|
||||
@ -38,35 +38,35 @@ static enum eos_t output_objects(void (*fn)(intval_t))
|
||||
|
||||
|
||||
// Insert 8-bit values ("!08" / "!8" / "!by" / "!byte" pseudo opcode)
|
||||
static enum eos_t PO_08(void)
|
||||
static enum eos PO_08(void)
|
||||
{
|
||||
return output_objects(Output_8b);
|
||||
}
|
||||
|
||||
|
||||
// Insert 16-bit values ("!16" / "!wo" / "!word" pseudo opcode)
|
||||
static enum eos_t PO_16(void)
|
||||
static enum eos PO_16(void)
|
||||
{
|
||||
return output_objects(Output_16b);
|
||||
}
|
||||
|
||||
|
||||
// Insert 24-bit values ("!24" pseudo opcode)
|
||||
static enum eos_t PO_24(void)
|
||||
static enum eos PO_24(void)
|
||||
{
|
||||
return output_objects(Output_24b);
|
||||
}
|
||||
|
||||
|
||||
// Insert 32-bit values ("!32" pseudo opcode)
|
||||
static enum eos_t PO_32(void)
|
||||
static enum eos PO_32(void)
|
||||
{
|
||||
return output_objects(Output_32b);
|
||||
}
|
||||
|
||||
|
||||
// Include binary file
|
||||
static enum eos_t PO_binary(void)
|
||||
static enum eos PO_binary(void)
|
||||
{
|
||||
FILE *fd;
|
||||
int byte;
|
||||
@ -115,15 +115,17 @@ static enum eos_t PO_binary(void)
|
||||
}
|
||||
fclose(fd);
|
||||
// if verbose, produce some output
|
||||
if ((pass_count == 0) && (Process_verbosity > 1))
|
||||
if ((pass_count == 0) && (Process_verbosity > 1)) {
|
||||
// FIXME - read "add_to_pc" via function call so struct can be moved from .h to .c file
|
||||
printf("Loaded %d (0x%04x) bytes from file offset %ld (0x%04lx).\n",
|
||||
CPU_state.add_to_pc, CPU_state.add_to_pc, skip, skip);
|
||||
}
|
||||
return ENSURE_EOS;
|
||||
}
|
||||
|
||||
|
||||
// Reserve space by sending bytes of given value ("!fi" / "!fill" pseudo opcode)
|
||||
static enum eos_t PO_fill(void)
|
||||
static enum eos PO_fill(void)
|
||||
{
|
||||
intval_t fill = FILLVALUE_FILL,
|
||||
size = ALU_defined_int();
|
||||
@ -137,7 +139,7 @@ static enum eos_t PO_fill(void)
|
||||
|
||||
|
||||
// show user-defined message
|
||||
static enum eos_t throw_string(const char prefix[], void (*fn)(const char *))
|
||||
static enum eos throw_string(const char prefix[], void (*fn)(const char *))
|
||||
{
|
||||
struct result_t result;
|
||||
|
||||
@ -189,16 +191,16 @@ static enum eos_t throw_string(const char prefix[], void (*fn)(const char *))
|
||||
|
||||
|
||||
////
|
||||
//static enum eos_t PO_debug(void)
|
||||
//static enum eos_t PO_info(void)
|
||||
//static enum eos_t PO_print(void)
|
||||
//static enum eos PO_debug(void)
|
||||
//static enum eos PO_info(void)
|
||||
//static enum eos PO_print(void)
|
||||
//{
|
||||
// return throw_string();
|
||||
//}
|
||||
|
||||
|
||||
// throw warning as given in source code
|
||||
static enum eos_t PO_warn(void)
|
||||
static enum eos PO_warn(void)
|
||||
{
|
||||
return throw_string("!warn: ", Throw_warning);
|
||||
|
||||
@ -206,14 +208,14 @@ static enum eos_t PO_warn(void)
|
||||
|
||||
|
||||
// throw error as given in source code
|
||||
static enum eos_t PO_error(void)
|
||||
static enum eos PO_error(void)
|
||||
{
|
||||
return throw_string("!error: ", Throw_error);
|
||||
}
|
||||
|
||||
|
||||
// throw serious error as given in source code
|
||||
static enum eos_t PO_serious(void)
|
||||
static enum eos PO_serious(void)
|
||||
{
|
||||
return throw_string("!serious: ", Throw_serious_error);
|
||||
}
|
||||
|
19
src/cpu.c
19
src/cpu.c
@ -73,7 +73,8 @@ struct cpu CPU_state; // current CPU state
|
||||
|
||||
// insert byte until PC fits condition
|
||||
// FIXME - move to basics.c
|
||||
static enum eos_t PO_align(void) {
|
||||
static enum eos PO_align(void)
|
||||
{
|
||||
intval_t and,
|
||||
equal,
|
||||
fill,
|
||||
@ -116,7 +117,7 @@ int CPU_find_cpu_struct(const struct cpu_type **target)
|
||||
|
||||
// select CPU ("!cpu" pseudo opcode)
|
||||
// FIXME - move to basics.c
|
||||
static enum eos_t PO_cpu(void)
|
||||
static enum eos PO_cpu(void)
|
||||
{
|
||||
const struct cpu_type *cpu_buffer = CPU_state.type; // remember current cpu
|
||||
|
||||
@ -136,7 +137,7 @@ static const char Error_old_offset_assembly[] =
|
||||
|
||||
// "!realpc" pseudo opcode (now obsolete)
|
||||
// FIXME - move to basics.c
|
||||
static enum eos_t PO_realpc(void)
|
||||
static enum eos PO_realpc(void)
|
||||
{
|
||||
Throw_error(Error_old_offset_assembly);
|
||||
return ENSURE_EOS;
|
||||
@ -146,7 +147,7 @@ static enum eos_t PO_realpc(void)
|
||||
// start offset assembly
|
||||
// FIXME - split into PO (move to basics.c) and backend
|
||||
// TODO - add a label argument to assign the block size afterwards (for assemble-to-end-address)
|
||||
static enum eos_t PO_pseudopc(void)
|
||||
static enum eos PO_pseudopc(void)
|
||||
{
|
||||
intval_t new_pc,
|
||||
new_offset;
|
||||
@ -221,7 +222,7 @@ static void check_and_set_reg_length(int *var, int make_long)
|
||||
|
||||
|
||||
// set register length, block-wise if needed.
|
||||
static enum eos_t set_register_length(int *var, int make_long)
|
||||
static enum eos set_register_length(int *var, int make_long)
|
||||
{
|
||||
int old_size = *var;
|
||||
|
||||
@ -235,28 +236,28 @@ static enum eos_t set_register_length(int *var, int make_long)
|
||||
|
||||
|
||||
// switch to long accu ("!al" pseudo opcode)
|
||||
static enum eos_t PO_al(void)
|
||||
static enum eos PO_al(void)
|
||||
{
|
||||
return set_register_length(&CPU_state.a_is_long, TRUE);
|
||||
}
|
||||
|
||||
|
||||
// switch to short accu ("!as" pseudo opcode)
|
||||
static enum eos_t PO_as(void)
|
||||
static enum eos PO_as(void)
|
||||
{
|
||||
return set_register_length(&CPU_state.a_is_long, FALSE);
|
||||
}
|
||||
|
||||
|
||||
// switch to long index registers ("!rl" pseudo opcode)
|
||||
static enum eos_t PO_rl(void)
|
||||
static enum eos PO_rl(void)
|
||||
{
|
||||
return set_register_length(&CPU_state.xy_are_long, TRUE);
|
||||
}
|
||||
|
||||
|
||||
// switch to short index registers ("!rs" pseudo opcode)
|
||||
static enum eos_t PO_rs(void)
|
||||
static enum eos PO_rs(void)
|
||||
{
|
||||
return set_register_length(&CPU_state.xy_are_long, FALSE);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ACME - a crossassembler for producing 6502/65c02/65816 code.
|
||||
// Copyright (C) 1998-2009 Marco Baye
|
||||
// Copyright (C) 1998-2014 Marco Baye
|
||||
// Have a look at "acme.c" for further info
|
||||
//
|
||||
// Dynamic buffer stuff
|
||||
@ -24,13 +24,13 @@
|
||||
|
||||
|
||||
// Variables
|
||||
struct dynabuf_t *GlobalDynaBuf; // global dynamic buffer
|
||||
struct dynabuf *GlobalDynaBuf; // global dynamic buffer
|
||||
|
||||
|
||||
// Functions
|
||||
|
||||
// get new buffer of given size
|
||||
static void resize(struct dynabuf_t *db, size_t new_size)
|
||||
static void resize(struct dynabuf *db, size_t new_size)
|
||||
{
|
||||
char *new_buf;
|
||||
|
||||
@ -45,9 +45,9 @@ static void resize(struct dynabuf_t *db, size_t new_size)
|
||||
// Exported functions
|
||||
|
||||
// Create and init a dynamic buffer and return pointer
|
||||
struct dynabuf_t *DynaBuf_create(int initial_size)
|
||||
struct dynabuf *DynaBuf_create(int initial_size)
|
||||
{
|
||||
struct dynabuf_t *db;
|
||||
struct dynabuf *db;
|
||||
|
||||
if (initial_size < DYNABUF_MINIMUM_INITIALSIZE)
|
||||
initial_size = DYNABUF_MINIMUM_INITIALSIZE;
|
||||
@ -64,7 +64,7 @@ struct dynabuf_t *DynaBuf_create(int initial_size)
|
||||
}
|
||||
|
||||
// Enlarge buffer
|
||||
void DynaBuf_enlarge(struct dynabuf_t *db)
|
||||
void DynaBuf_enlarge(struct dynabuf *db)
|
||||
{
|
||||
resize(db, MAKE_LARGER_THAN(db->reserved));
|
||||
}
|
||||
@ -72,7 +72,7 @@ void DynaBuf_enlarge(struct dynabuf_t *db)
|
||||
// Claim enough memory to hold a copy of the current buffer contents,
|
||||
// make that copy and return it.
|
||||
// The copy must be released by calling free().
|
||||
char *DynaBuf_get_copy(struct dynabuf_t *db)
|
||||
char *DynaBuf_get_copy(struct dynabuf *db)
|
||||
{
|
||||
char *copy;
|
||||
|
||||
@ -82,13 +82,13 @@ char *DynaBuf_get_copy(struct dynabuf_t *db)
|
||||
}
|
||||
|
||||
// add char to buffer
|
||||
void DynaBuf_append(struct dynabuf_t *db, char byte)
|
||||
void DynaBuf_append(struct dynabuf *db, char byte)
|
||||
{
|
||||
DYNABUF_APPEND(db, byte);
|
||||
}
|
||||
|
||||
// Append string to buffer (without terminator)
|
||||
void DynaBuf_add_string(struct dynabuf_t *db, const char *string)
|
||||
void DynaBuf_add_string(struct dynabuf *db, const char *string)
|
||||
{
|
||||
char byte;
|
||||
|
||||
@ -98,7 +98,7 @@ void DynaBuf_add_string(struct dynabuf_t *db, const char *string)
|
||||
|
||||
// make sure DynaBuf is large enough to take "size" more bytes
|
||||
// return pointer to end of current contents
|
||||
static char *ensure_free_space(struct dynabuf_t *db, int size)
|
||||
static char *ensure_free_space(struct dynabuf *db, int size)
|
||||
{
|
||||
while ((db->reserved - db->size) < size)
|
||||
resize(db, MAKE_LARGER_THAN(db->reserved));
|
||||
@ -106,7 +106,7 @@ static char *ensure_free_space(struct dynabuf_t *db, int size)
|
||||
}
|
||||
|
||||
// add string version of int to buffer (without terminator)
|
||||
void DynaBuf_add_signed_long(struct dynabuf_t *db, signed long value)
|
||||
void DynaBuf_add_signed_long(struct dynabuf *db, signed long value)
|
||||
{
|
||||
char *write = ensure_free_space(db, INTVAL_MAXCHARACTERS + 1);
|
||||
|
||||
@ -114,7 +114,7 @@ void DynaBuf_add_signed_long(struct dynabuf_t *db, signed long value)
|
||||
}
|
||||
|
||||
// add string version of float to buffer (without terminator)
|
||||
void DynaBuf_add_double(struct dynabuf_t *db, double value)
|
||||
void DynaBuf_add_double(struct dynabuf *db, double value)
|
||||
{
|
||||
char *write = ensure_free_space(db, 40); // reserve 40 chars
|
||||
|
||||
@ -124,7 +124,7 @@ void DynaBuf_add_double(struct dynabuf_t *db, double value)
|
||||
}
|
||||
|
||||
// Convert buffer contents to lower case (target and source may be identical)
|
||||
void DynaBuf_to_lower(struct dynabuf_t *target, struct dynabuf_t *source)
|
||||
void DynaBuf_to_lower(struct dynabuf *target, struct dynabuf *source)
|
||||
{
|
||||
char *read,
|
||||
*write;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ACME - a crossassembler for producing 6502/65c02/65816 code.
|
||||
// Copyright (C) 1998-2009 Marco Baye
|
||||
// Copyright (C) 1998-2014 Marco Baye
|
||||
// Have a look at "acme.c" for further info
|
||||
//
|
||||
// Dynamic buffer stuff
|
||||
@ -25,7 +25,7 @@ do { \
|
||||
|
||||
|
||||
// dynamic buffer structure
|
||||
struct dynabuf_t {
|
||||
struct dynabuf {
|
||||
char *buffer; // pointer to buffer
|
||||
int size; // size of buffer's used portion
|
||||
int reserved; // total size of buffer
|
||||
@ -33,27 +33,27 @@ struct dynabuf_t {
|
||||
|
||||
|
||||
// variables
|
||||
extern struct dynabuf_t *GlobalDynaBuf; // global dynamic buffer
|
||||
extern struct dynabuf *GlobalDynaBuf; // global dynamic buffer
|
||||
|
||||
|
||||
// create global DynaBuf (call once on program startup)
|
||||
extern void DynaBuf_init(void);
|
||||
// create (private) DynaBuf
|
||||
extern struct dynabuf_t *DynaBuf_create(int initial_size);
|
||||
extern struct dynabuf *DynaBuf_create(int initial_size);
|
||||
// call whenever buffer is too small
|
||||
extern void DynaBuf_enlarge(struct dynabuf_t *db);
|
||||
extern void DynaBuf_enlarge(struct dynabuf *db);
|
||||
// return malloc'd copy of buffer contents
|
||||
extern char *DynaBuf_get_copy(struct dynabuf_t *db);
|
||||
extern char *DynaBuf_get_copy(struct dynabuf *db);
|
||||
// copy string to buffer (without terminator)
|
||||
extern void DynaBuf_add_string(struct dynabuf_t *db, const char *);
|
||||
extern void DynaBuf_add_string(struct dynabuf *db, const char *);
|
||||
// add string version of int to buffer (without terminator)
|
||||
extern void DynaBuf_add_signed_long(struct dynabuf_t *db, signed long value);
|
||||
extern void DynaBuf_add_signed_long(struct dynabuf *db, signed long value);
|
||||
// add string version of float to buffer (without terminator)
|
||||
extern void DynaBuf_add_double(struct dynabuf_t *db, double value);
|
||||
extern void DynaBuf_add_double(struct dynabuf *db, double value);
|
||||
// converts buffer contents to lower case
|
||||
extern void DynaBuf_to_lower(struct dynabuf_t *target, struct dynabuf_t *source);
|
||||
extern void DynaBuf_to_lower(struct dynabuf *target, struct dynabuf *source);
|
||||
// add char to buffer
|
||||
extern void DynaBuf_append(struct dynabuf_t *db, char);
|
||||
extern void DynaBuf_append(struct dynabuf *db, char);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -39,7 +39,7 @@ static struct node_t *encoder_tree = NULL; // tree to hold encoders
|
||||
char (*Encoding_encode_char)(char);
|
||||
|
||||
// Insert string(s)
|
||||
static enum eos_t encode_string(encoder_t inner_encoder, char xor)
|
||||
static enum eos encode_string(encoder_t inner_encoder, char xor)
|
||||
{
|
||||
encoder_t outer_encoder = Encoding_encode_char; // buffer encoder
|
||||
|
||||
@ -71,7 +71,7 @@ static enum eos_t encode_string(encoder_t inner_encoder, char xor)
|
||||
}
|
||||
|
||||
// Insert text string (default format)
|
||||
static enum eos_t PO_text(void)
|
||||
static enum eos PO_text(void)
|
||||
{
|
||||
return encode_string(Encoding_encode_char, 0);
|
||||
}
|
||||
@ -83,7 +83,7 @@ static char encoder_raw(char byte)
|
||||
}
|
||||
|
||||
// Insert raw string
|
||||
static enum eos_t PO_raw(void)
|
||||
static enum eos PO_raw(void)
|
||||
{
|
||||
return encode_string(encoder_raw, 0);
|
||||
}
|
||||
@ -99,7 +99,7 @@ static char encoder_pet(char byte)
|
||||
}
|
||||
|
||||
// Insert PetSCII string
|
||||
static enum eos_t PO_pet(void)
|
||||
static enum eos PO_pet(void)
|
||||
{
|
||||
return encode_string(encoder_pet, 0);
|
||||
}
|
||||
@ -119,13 +119,13 @@ static char encoder_scr(char byte)
|
||||
}
|
||||
|
||||
// Insert screencode string
|
||||
static enum eos_t PO_scr(void)
|
||||
static enum eos PO_scr(void)
|
||||
{
|
||||
return encode_string(encoder_scr, 0);
|
||||
}
|
||||
|
||||
// Insert screencode string, XOR'd
|
||||
static enum eos_t PO_scrxor(void)
|
||||
static enum eos PO_scrxor(void)
|
||||
{
|
||||
intval_t num = ALU_any_int();
|
||||
|
||||
@ -136,7 +136,7 @@ static enum eos_t PO_scrxor(void)
|
||||
}
|
||||
|
||||
// "!cbm" pseudo opcode (now obsolete)
|
||||
static enum eos_t PO_cbm(void)
|
||||
static enum eos PO_cbm(void)
|
||||
{
|
||||
Throw_error("\"!cbm\" is obsolete; use \"!ct pet\" instead.");
|
||||
return ENSURE_EOS;
|
||||
@ -149,7 +149,7 @@ static char encoder_file(char byte)
|
||||
}
|
||||
|
||||
// read encoding table from file
|
||||
static enum eos_t user_defined_encoding(void)
|
||||
static enum eos user_defined_encoding(void)
|
||||
{
|
||||
FILE *fd;
|
||||
char local_table[256],
|
||||
@ -182,7 +182,7 @@ static enum eos_t user_defined_encoding(void)
|
||||
}
|
||||
|
||||
// use one of the pre-defined encodings (raw, pet, scr)
|
||||
static enum eos_t predefined_encoding(void)
|
||||
static enum eos predefined_encoding(void)
|
||||
{
|
||||
void *node_body;
|
||||
char local_table[256],
|
||||
@ -207,7 +207,7 @@ static enum eos_t predefined_encoding(void)
|
||||
}
|
||||
|
||||
// Set current encoding ("!convtab" pseudo opcode)
|
||||
static enum eos_t PO_convtab(void)
|
||||
static enum eos PO_convtab(void)
|
||||
{
|
||||
if ((GotByte == '<') || (GotByte == '"'))
|
||||
return user_defined_encoding();
|
||||
|
30
src/flow.c
30
src/flow.c
@ -1,5 +1,5 @@
|
||||
// ACME - a crossassembler for producing 6502/65c02/65816 code.
|
||||
// Copyright (C) 1998-2009 Marco Baye
|
||||
// Copyright (C) 1998-2014 Marco Baye
|
||||
// Have a look at "acme.c" for further info
|
||||
//
|
||||
// Flow control stuff (loops, conditional assembly etc.)
|
||||
@ -117,11 +117,11 @@ static int check_condition(struct loop_condition *condition)
|
||||
|
||||
|
||||
// looping assembly ("!do"). Has to be re-entrant.
|
||||
static enum eos_t PO_do(void) // Now GotByte = illegal char
|
||||
static enum eos PO_do(void) // Now GotByte = illegal char
|
||||
{
|
||||
struct loop_condition condition1,
|
||||
condition2;
|
||||
struct input_t loop_input,
|
||||
struct input loop_input,
|
||||
*outer_input;
|
||||
char *loop_body;
|
||||
int go_on,
|
||||
@ -179,14 +179,14 @@ static enum eos_t PO_do(void) // Now GotByte = illegal char
|
||||
|
||||
|
||||
// looping assembly ("!for"). Has to be re-entrant.
|
||||
static enum eos_t PO_for(void) // Now GotByte = illegal char
|
||||
static enum eos PO_for(void) // Now GotByte = illegal char
|
||||
{
|
||||
struct input_t loop_input,
|
||||
struct input loop_input,
|
||||
*outer_input;
|
||||
struct result_t loop_counter;
|
||||
intval_t maximum;
|
||||
char *loop_body; // pointer to loop's body block
|
||||
struct label_t *label;
|
||||
struct label *label;
|
||||
zone_t zone;
|
||||
int force_bit,
|
||||
loop_start; // line number of "!for" pseudo opcode
|
||||
@ -291,7 +291,7 @@ static void parse_block_else_block(int parse_first)
|
||||
|
||||
|
||||
// conditional assembly ("!if"). Has to be re-entrant.
|
||||
static enum eos_t PO_if(void) // Now GotByte = illegal char
|
||||
static enum eos PO_if(void) // Now GotByte = illegal char
|
||||
{
|
||||
intval_t cond;
|
||||
|
||||
@ -304,10 +304,10 @@ static enum eos_t PO_if(void) // Now GotByte = illegal char
|
||||
|
||||
|
||||
// conditional assembly ("!ifdef" and "!ifndef"). Has to be re-entrant.
|
||||
static enum eos_t ifdef_ifndef(int invert) // Now GotByte = illegal char
|
||||
static enum eos ifdef_ifndef(int invert) // Now GotByte = illegal char
|
||||
{
|
||||
struct node_ra_t *node;
|
||||
struct label_t *label;
|
||||
struct label *label;
|
||||
zone_t zone;
|
||||
int defined = FALSE;
|
||||
|
||||
@ -316,7 +316,7 @@ static enum eos_t ifdef_ifndef(int invert) // Now GotByte = illegal char
|
||||
|
||||
Tree_hard_scan(&node, Label_forest, zone, FALSE);
|
||||
if (node) {
|
||||
label = (struct label_t *) node->body;
|
||||
label = (struct label *) node->body;
|
||||
// in first pass, count usage
|
||||
if (pass_count == 0)
|
||||
label->usage++;
|
||||
@ -336,21 +336,21 @@ static enum eos_t ifdef_ifndef(int invert) // Now GotByte = illegal char
|
||||
|
||||
|
||||
// conditional assembly ("!ifdef"). Has to be re-entrant.
|
||||
static enum eos_t PO_ifdef(void) // Now GotByte = illegal char
|
||||
static enum eos PO_ifdef(void) // Now GotByte = illegal char
|
||||
{
|
||||
return ifdef_ifndef(FALSE);
|
||||
}
|
||||
|
||||
|
||||
// conditional assembly ("!ifndef"). Has to be re-entrant.
|
||||
static enum eos_t PO_ifndef(void) // Now GotByte = illegal char
|
||||
static enum eos PO_ifndef(void) // Now GotByte = illegal char
|
||||
{
|
||||
return ifdef_ifndef(TRUE);
|
||||
}
|
||||
|
||||
|
||||
// macro definition ("!macro").
|
||||
static enum eos_t PO_macro(void) // Now GotByte = illegal char
|
||||
static enum eos PO_macro(void) // Now GotByte = illegal char
|
||||
{
|
||||
// In first pass, parse. In all other passes, skip.
|
||||
if (pass_count == 0) {
|
||||
@ -387,11 +387,11 @@ void Parse_and_close_file(FILE *fd, const char *filename)
|
||||
|
||||
|
||||
// include source file ("!source" or "!src"). Has to be re-entrant.
|
||||
static enum eos_t PO_source(void) // Now GotByte = illegal char
|
||||
static enum eos PO_source(void) // Now GotByte = illegal char
|
||||
{
|
||||
FILE *fd;
|
||||
char local_gotbyte;
|
||||
struct input_t new_input,
|
||||
struct input new_input,
|
||||
*outer_input;
|
||||
|
||||
// Enter new nesting level.
|
||||
|
@ -140,7 +140,7 @@ static void parse_pc_def(void) // Now GotByte = "*"
|
||||
static void parse_pseudo_opcode(void) // Now GotByte = "!"
|
||||
{
|
||||
void *node_body;
|
||||
enum eos_t (*fn)(void),
|
||||
enum eos (*fn)(void),
|
||||
then = SKIP_REMAINDER; // prepare for errors
|
||||
|
||||
GetByte(); // read next byte
|
||||
@ -149,7 +149,7 @@ static void parse_pseudo_opcode(void) // Now GotByte = "!"
|
||||
// search for tree item
|
||||
if ((Tree_easy_scan(pseudo_opcode_tree, &node_body, GlobalDynaBuf))
|
||||
&& node_body) {
|
||||
fn = (enum eos_t (*)(void)) node_body;
|
||||
fn = (enum eos (*)(void)) node_body;
|
||||
SKIPSPACE();
|
||||
// call function
|
||||
then = fn();
|
||||
@ -223,7 +223,7 @@ static void parse_backward_anon_def(int *statement_flags)
|
||||
// Parse anonymous forward label definition. Called with GotByte == ?
|
||||
static void parse_forward_anon_def(int *statement_flags)
|
||||
{
|
||||
struct label_t *counter_label;
|
||||
struct label *counter_label;
|
||||
|
||||
if (!first_label_of_statement(statement_flags))
|
||||
return;
|
||||
@ -300,6 +300,7 @@ void Parse_until_eob_or_eof(void)
|
||||
}
|
||||
} while (GotByte != CHAR_EOS); // until end-of-statement
|
||||
// adjust program counter
|
||||
// FIXME - next two lines should be a function call!
|
||||
CPU_state.pc.intval = (CPU_state.pc.intval + CPU_state.add_to_pc) & 0xffff;
|
||||
CPU_state.add_to_pc = 0;
|
||||
// go on with next byte
|
||||
|
@ -54,7 +54,8 @@ extern const char Byte_flags[];
|
||||
|
||||
extern struct node_t *pseudo_opcode_tree; // tree to hold pseudo opcodes
|
||||
// structures
|
||||
enum eos_t {
|
||||
// different ways to handle end-of-statement:
|
||||
enum eos {
|
||||
SKIP_REMAINDER, // skip remainder of line - (after errors)
|
||||
ENSURE_EOS, // make sure there's nothing left in statement
|
||||
PARSE_REMAINDER, // parse what's left
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ACME - a crossassembler for producing 6502/65c02/65816 code.
|
||||
// Copyright (C) 1998-2009 Marco Baye
|
||||
// Copyright (C) 1998-2014 Marco Baye
|
||||
// Have a look at "acme.c" for further info
|
||||
//
|
||||
// Input stuff
|
||||
@ -25,7 +25,7 @@ const char FILE_READBINARY[] = "rb";
|
||||
// if the characters above are changed, don't forget to adjust ByteFlags[]!
|
||||
|
||||
// fake input structure (for error msgs before any real input is established)
|
||||
static struct input_t outermost = {
|
||||
static struct input outermost = {
|
||||
"<none>", // file name
|
||||
0, // line number
|
||||
FALSE, // Faked file access, so no RAM read
|
||||
@ -37,11 +37,11 @@ static struct input_t outermost = {
|
||||
|
||||
|
||||
// Variables
|
||||
struct input_t *Input_now = &outermost; // current input structure
|
||||
struct input *Input_now = &outermost; // current input structure
|
||||
|
||||
|
||||
// End of source file ("!endoffile" or "!eof")
|
||||
static enum eos_t PO_eof(void)
|
||||
static enum eos PO_eof(void)
|
||||
{
|
||||
// Well, it doesn't end right here and now, but at end-of-line! :-)
|
||||
Input_ensure_EOS();
|
||||
|
12
src/input.h
12
src/input.h
@ -1,5 +1,5 @@
|
||||
// ACME - a crossassembler for producing 6502/65c02/65816 code.
|
||||
// Copyright (C) 1998-2009 Marco Baye
|
||||
// Copyright (C) 1998-2014 Marco Baye
|
||||
// Have a look at "acme.c" for further info
|
||||
//
|
||||
// Input stuff
|
||||
@ -12,8 +12,8 @@
|
||||
|
||||
// type definitions
|
||||
|
||||
// values for input_t component "src.state"
|
||||
enum inputstate_t {
|
||||
// values for input component "src.state"
|
||||
enum inputstate {
|
||||
INPUTSTATE_NORMAL, // everything's fine
|
||||
INPUTSTATE_AGAIN, // re-process last byte
|
||||
INPUTSTATE_SKIPBLANKS, // shrink multiple spaces
|
||||
@ -24,11 +24,11 @@ enum inputstate_t {
|
||||
INPUTSTATE_EOB, // send end-of-block after end-of-statement
|
||||
INPUTSTATE_EOF, // send end-of-file after end-of-statement
|
||||
};
|
||||
struct input_t {
|
||||
struct input {
|
||||
const char *original_filename; // during RAM reads, too
|
||||
int line_number, // in file (on RAM reads, too)
|
||||
source_is_ram; // TRUE if RAM, FALSE if file
|
||||
enum inputstate_t state; // state of input
|
||||
enum inputstate state; // state of input
|
||||
union {
|
||||
FILE *fd; // file descriptor
|
||||
char *ram_ptr; // RAM read ptr (loop or macro block)
|
||||
@ -49,7 +49,7 @@ extern const char FILE_READBINARY[];
|
||||
|
||||
|
||||
// Variables
|
||||
extern struct input_t *Input_now; // current input structure
|
||||
extern struct input *Input_now; // current input structure
|
||||
|
||||
|
||||
// Prototypes
|
||||
|
25
src/label.c
25
src/label.c
@ -30,7 +30,7 @@ struct node_ra_t *Label_forest[256]; // ... (because of 8-bit hash)
|
||||
// Dump label value and flags to dump file
|
||||
static void dump_one_label(struct node_ra_t *node, FILE *fd)
|
||||
{
|
||||
struct label_t *label = node->body;
|
||||
struct label *label = node->body;
|
||||
|
||||
// output name
|
||||
fprintf(fd, "%s", node->id_string);
|
||||
@ -64,10 +64,10 @@ static void dump_one_label(struct node_ra_t *node, FILE *fd)
|
||||
|
||||
// Search for label. Create if nonexistant. If created, give it flags "Flags".
|
||||
// The label name must be held in GlobalDynaBuf.
|
||||
struct label_t *Label_find(zone_t zone, int flags)
|
||||
struct label *Label_find(zone_t zone, int flags)
|
||||
{
|
||||
struct node_ra_t *node;
|
||||
struct label_t *label;
|
||||
struct label *label;
|
||||
int node_created,
|
||||
force_bits = flags & MVALUE_FORCEBITS;
|
||||
|
||||
@ -98,7 +98,7 @@ struct label_t *Label_find(zone_t zone, int flags)
|
||||
|
||||
// Assign value to label. The function acts upon the label's flag bits and
|
||||
// produces an error if needed.
|
||||
void Label_set_value(struct label_t *label, struct result_t *newvalue, int change_allowed)
|
||||
void Label_set_value(struct label *label, struct result_t *newvalue, int change_allowed)
|
||||
{
|
||||
int oldflags = label->result.flags;
|
||||
|
||||
@ -132,11 +132,11 @@ void Label_set_value(struct label_t *label, struct result_t *newvalue, int chang
|
||||
|
||||
|
||||
// (Re)set label
|
||||
static enum eos_t PO_set(void) // Now GotByte = illegal char
|
||||
static enum eos PO_set(void) // Now GotByte = illegal char
|
||||
{
|
||||
struct result_t result;
|
||||
int force_bit;
|
||||
struct label_t *label;
|
||||
struct label *label;
|
||||
zone_t zone;
|
||||
|
||||
if (Input_read_zone_and_keyword(&zone) == 0) // skips spaces before
|
||||
@ -165,7 +165,7 @@ static enum eos_t PO_set(void) // Now GotByte = illegal char
|
||||
|
||||
|
||||
// Select dump file
|
||||
static enum eos_t PO_sl(void)
|
||||
static enum eos PO_sl(void)
|
||||
{
|
||||
// bugfix: first read filename, *then* check for first pass.
|
||||
// if skipping right away, quoted colons might be misinterpreted as EOS
|
||||
@ -207,12 +207,13 @@ static struct node_t pseudo_opcodes[] = {
|
||||
void Label_implicit_definition(zone_t zone, int stat_flags, int force_bit, int change)
|
||||
{
|
||||
struct result_t result;
|
||||
struct label_t *label;
|
||||
struct label *label;
|
||||
|
||||
label = Label_find(zone, force_bit);
|
||||
// implicit label definition (label)
|
||||
if ((stat_flags & SF_FOUND_BLANK) && warn_on_indented_labels)
|
||||
Throw_first_pass_warning("Implicit label definition not in leftmost column.");
|
||||
// FIXME - read pc via function call!
|
||||
result.flags = CPU_state.pc.flags & MVALUE_DEFINED;
|
||||
result.val.intval = CPU_state.pc.intval;
|
||||
Label_set_value(label, &result, change);
|
||||
@ -224,7 +225,7 @@ void Label_implicit_definition(zone_t zone, int stat_flags, int force_bit, int c
|
||||
void Label_parse_definition(zone_t zone, int stat_flags)
|
||||
{
|
||||
struct result_t result;
|
||||
struct label_t *label;
|
||||
struct label *label;
|
||||
int force_bit = Input_get_force_bit(); // skips spaces after
|
||||
// FIXME - force bit is allowed for implicit label defs?!
|
||||
|
||||
@ -247,7 +248,7 @@ void Label_parse_definition(zone_t zone, int stat_flags)
|
||||
void Label_define(intval_t value)
|
||||
{
|
||||
struct result_t result;
|
||||
struct label_t *label;
|
||||
struct label *label;
|
||||
|
||||
result.flags = MVALUE_GIVEN;
|
||||
result.val.intval = value;
|
||||
@ -288,9 +289,9 @@ void Label_register_init(void)
|
||||
// references the *next* anonymous forward label definition. The tricky bit is,
|
||||
// each name length would need its own counter. But hey, ACME's real quick in
|
||||
// finding labels, so I'll just abuse the label system to store those counters.
|
||||
struct label_t *Label_fix_forward_name(void)
|
||||
struct label *Label_fix_forward_name(void)
|
||||
{
|
||||
struct label_t *counter_label;
|
||||
struct label *counter_label;
|
||||
unsigned long number;
|
||||
|
||||
// terminate name, find "counter" label and read value
|
||||
|
10
src/label.h
10
src/label.h
@ -1,5 +1,5 @@
|
||||
// ACME - a crossassembler for producing 6502/65c02/65816 code.
|
||||
// Copyright (C) 1998-2009 Marco Baye
|
||||
// Copyright (C) 1998-2014 Marco Baye
|
||||
// Have a look at "acme.c" for further info
|
||||
//
|
||||
// Label stuff
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
|
||||
// "label" structure type definition
|
||||
struct label_t {
|
||||
struct label {
|
||||
struct result_t result; // Expression flags and value
|
||||
int usage; // usage count
|
||||
int pass; // pass of creation (for anon counters)
|
||||
@ -28,7 +28,7 @@ extern void Label_clear_init(void);
|
||||
// register pseudo opcodes (done later)
|
||||
extern void Label_register_init(void);
|
||||
// function acts upon the label's flag bits and produces an error if needed.
|
||||
extern void Label_set_value(struct label_t *, struct result_t *, int change_allowed);
|
||||
extern void Label_set_value(struct label *, struct result_t *, int change_allowed);
|
||||
// Parse implicit label definition (can be either global or local).
|
||||
// Name must be held in GlobalDynaBuf.
|
||||
extern void Label_implicit_definition(zone_t zone, int stat_flags, int force_bit, int change);
|
||||
@ -37,7 +37,7 @@ extern void Label_implicit_definition(zone_t zone, int stat_flags, int force_bit
|
||||
extern void Label_parse_definition(zone_t zone, int stat_flags);
|
||||
// Search for label. Create if nonexistant. If created, assign flags.
|
||||
// Name must be held in GlobalDynaBuf.
|
||||
extern struct label_t *Label_find(zone_t, int flags);
|
||||
extern struct label *Label_find(zone_t, int flags);
|
||||
// set global label to value, no questions asked (for "-D" switch)
|
||||
// Name must be held in GlobalDynaBuf.
|
||||
extern void Label_define(intval_t value);
|
||||
@ -45,7 +45,7 @@ extern void Label_define(intval_t value);
|
||||
extern void Label_dump_all(FILE *fd);
|
||||
// Fix name of anonymous forward label (held in GlobalDynaBuf, NOT TERMINATED!)
|
||||
// so it references the *next* anonymous forward label definition.
|
||||
extern struct label_t *Label_fix_forward_name(void);
|
||||
extern struct label *Label_fix_forward_name(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
22
src/macro.c
22
src/macro.c
@ -1,5 +1,5 @@
|
||||
// ACME - a crossassembler for producing 6502/65c02/65816 code.
|
||||
// Copyright (C) 1998-2009 Marco Baye
|
||||
// Copyright (C) 1998-2014 Marco Baye
|
||||
// Have a look at "acme.c" for further info
|
||||
//
|
||||
// Macro stuff
|
||||
@ -30,7 +30,7 @@ static const char exception_macro_twice[] = "Macro already defined.";
|
||||
|
||||
|
||||
// macro struct type definition
|
||||
struct macro_t {
|
||||
struct macro {
|
||||
int def_line_number; // line number of definition for error msgs
|
||||
char *def_filename, // file name of definition for error msgs
|
||||
*original_name, // user-supplied name for error msgs
|
||||
@ -43,13 +43,13 @@ struct macro_t {
|
||||
// which ones are call-by-reference.
|
||||
union macro_arg_t {
|
||||
struct result_t result; // value and flags (call by value)
|
||||
struct label_t *label; // pointer to label struct (call by reference)
|
||||
struct label *label; // pointer to label struct (call by reference)
|
||||
};
|
||||
|
||||
|
||||
// Variables
|
||||
static struct dynabuf_t *user_macro_name; // original macro title
|
||||
static struct dynabuf_t *internal_name; // plus param type chars
|
||||
static struct dynabuf *user_macro_name; // original macro title
|
||||
static struct dynabuf *internal_name; // plus param type chars
|
||||
static struct node_ra_t *macro_forest[256]; // trees (because of 8b hash)
|
||||
// Dynamic argument table
|
||||
static union macro_arg_t *arg_table = NULL;
|
||||
@ -141,7 +141,7 @@ static int search_for_macro(struct node_ra_t **result, zone_t zone, int create)
|
||||
// the maximum error limit inbetween.
|
||||
static void report_redefinition(struct node_ra_t *macro_node)
|
||||
{
|
||||
struct macro_t *original_macro = macro_node->body;
|
||||
struct macro *original_macro = macro_node->body;
|
||||
|
||||
// show warning with location of current definition
|
||||
Throw_warning(exception_macro_twice);
|
||||
@ -162,7 +162,7 @@ void Macro_parse_definition(void) // Now GotByte = illegal char after "!macro"
|
||||
{
|
||||
char *formal_parameters;
|
||||
struct node_ra_t *macro_node;
|
||||
struct macro_t *new_macro;
|
||||
struct macro *new_macro;
|
||||
zone_t macro_zone = get_zone_and_title();
|
||||
|
||||
// now GotByte = first non-space after title
|
||||
@ -225,12 +225,12 @@ void Macro_parse_definition(void) // Now GotByte = illegal char after "!macro"
|
||||
void Macro_parse_call(void) // Now GotByte = dot or first char of macro name
|
||||
{
|
||||
char local_gotbyte;
|
||||
struct label_t *label;
|
||||
struct section_t new_section,
|
||||
struct label *label;
|
||||
struct section new_section,
|
||||
*outer_section;
|
||||
struct input_t new_input,
|
||||
struct input new_input,
|
||||
*outer_input;
|
||||
struct macro_t *actual_macro;
|
||||
struct macro *actual_macro;
|
||||
struct node_ra_t *macro_node,
|
||||
*label_node;
|
||||
zone_t macro_zone,
|
||||
|
@ -141,7 +141,7 @@ static const char exception_highbyte_zero[]= "Using oversized addressing mode.";
|
||||
|
||||
// Variables
|
||||
|
||||
static struct dynabuf_t *mnemo_dyna_buf; // dynamic buffer for mnemonics
|
||||
static struct dynabuf *mnemo_dyna_buf; // dynamic buffer for mnemonics
|
||||
// predefined stuff
|
||||
static struct node_t *mnemo_6502_tree = NULL; // holds 6502 mnemonics
|
||||
static struct node_t *mnemo_6510_tree = NULL; // holds 6510 extensions
|
||||
@ -588,6 +588,7 @@ static void group_only_relative8_addressing(int opcode)
|
||||
intval_t offset = 0; // dummy value, to not throw more errors than necessary
|
||||
|
||||
ALU_int_result(&target);
|
||||
// FIXME - read pc via function call instead!
|
||||
if (CPU_state.pc.flags & target.flags & MVALUE_DEFINED) {
|
||||
if ((target.intval | 0xffff) != 0xffff) {
|
||||
not_in_bank(target.intval);
|
||||
@ -621,6 +622,7 @@ static void group_only_relative16_addressing(int opcode)
|
||||
intval_t offset = 0; // dummy value, to not throw more errors than necessary
|
||||
|
||||
ALU_int_result(&target);
|
||||
// FIXME - read pc via function call instead!
|
||||
if (CPU_state.pc.flags & target.flags & MVALUE_DEFINED) {
|
||||
if ((target.intval | 0xffff) != 0xffff) {
|
||||
not_in_bank(target.intval);
|
||||
@ -821,7 +823,7 @@ static void group_jump(int index)
|
||||
}
|
||||
|
||||
// Work function
|
||||
static int check_mnemo_tree(struct node_t *tree, struct dynabuf_t *dyna_buf)
|
||||
static int check_mnemo_tree(struct node_t *tree, struct dynabuf *dyna_buf)
|
||||
{
|
||||
void *node_body;
|
||||
int code,
|
||||
|
10
src/output.c
10
src/output.c
@ -58,7 +58,7 @@ static struct output *out = &default_output;
|
||||
// predefined stuff
|
||||
static struct node_t *file_format_tree = NULL; // tree to hold output formats
|
||||
// possible file formats
|
||||
enum out_format_t {
|
||||
enum output_format {
|
||||
OUTPUT_FORMAT_UNSPECIFIED, // default (uses "plain" actually)
|
||||
OUTPUT_FORMAT_APPLE, // load address, length, code
|
||||
OUTPUT_FORMAT_CBM, // load address, code (default for "!to" pseudo opcode)
|
||||
@ -72,7 +72,7 @@ static struct node_t file_formats[] = {
|
||||
// ^^^^ this marks the last element
|
||||
};
|
||||
// chosen file format
|
||||
static enum out_format_t output_format = OUTPUT_FORMAT_UNSPECIFIED;
|
||||
static enum output_format output_format = OUTPUT_FORMAT_UNSPECIFIED;
|
||||
|
||||
|
||||
// predefined stuff
|
||||
@ -235,7 +235,7 @@ static void fill_completely(char value)
|
||||
|
||||
// define default value for empty memory ("!initmem" pseudo opcode)
|
||||
// FIXME - move to basics.c
|
||||
static enum eos_t PO_initmem(void)
|
||||
static enum eos PO_initmem(void)
|
||||
{
|
||||
intval_t content;
|
||||
|
||||
@ -275,14 +275,14 @@ int Output_set_output_format(void)
|
||||
if (!Tree_easy_scan(file_format_tree, &node_body, GlobalDynaBuf))
|
||||
return FALSE;
|
||||
|
||||
output_format = (enum out_format_t) node_body;
|
||||
output_format = (enum output_format) node_body;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// select output file and format ("!to" pseudo opcode)
|
||||
// FIXME - move to basics.c
|
||||
static enum eos_t PO_to(void)
|
||||
static enum eos PO_to(void)
|
||||
{
|
||||
// bugfix: first read filename, *then* check for first pass.
|
||||
// if skipping right away, quoted colons might be misinterpreted as EOS
|
||||
|
@ -19,7 +19,7 @@ static char untitled[] = "<untitled>";
|
||||
// ...is actually constant, but flagging it "const" results in heap of warnings
|
||||
|
||||
// fake section structure (for error msgs before any real section is in use)
|
||||
static struct section_t initial_section = {
|
||||
static struct section initial_section = {
|
||||
0, // zone value
|
||||
"during", // "type" => normally "zone Title" or
|
||||
"init", // "title" => "macro test", now "during init"
|
||||
@ -28,12 +28,12 @@ static struct section_t initial_section = {
|
||||
|
||||
|
||||
// Variables
|
||||
struct section_t *Section_now = &initial_section; // current section
|
||||
static struct section_t outer_section; // outermost section struct
|
||||
struct section *Section_now = &initial_section; // current section
|
||||
static struct section outer_section; // outermost section struct
|
||||
static zone_t zone_max; // Highest zone number yet
|
||||
|
||||
// Write given info into given zone structure and activate it
|
||||
void Section_new_zone(struct section_t *section, const char *type, char *title, int allocated)
|
||||
void Section_new_zone(struct section *section, const char *type, char *title, int allocated)
|
||||
{
|
||||
section->zone = ++zone_max;
|
||||
section->type = type;
|
||||
@ -46,18 +46,18 @@ void Section_new_zone(struct section_t *section, const char *type, char *title,
|
||||
// Tidy up: If necessary, release section title.
|
||||
// Warning - the state of the component "Allocd" may have
|
||||
// changed in the meantime, so don't rely on a local variable.
|
||||
void Section_finalize(struct section_t *section)
|
||||
void Section_finalize(struct section *section)
|
||||
{
|
||||
if (section->allocated)
|
||||
free(section->title);
|
||||
}
|
||||
|
||||
// Switch to new zone ("!zone" or "!zn"). Has to be re-entrant.
|
||||
static enum eos_t PO_zone(void)
|
||||
static enum eos PO_zone(void)
|
||||
{
|
||||
struct section_t entry_values; // buffer for outer zone
|
||||
char *new_title;
|
||||
int allocated;
|
||||
struct section entry_values; // buffer for outer zone
|
||||
char *new_title;
|
||||
int allocated;
|
||||
|
||||
// remember everything about current structure
|
||||
entry_values = *Section_now;
|
||||
@ -89,7 +89,7 @@ static enum eos_t PO_zone(void)
|
||||
}
|
||||
|
||||
// "!subzone" or "!sz" pseudo opcode (now obsolete)
|
||||
static enum eos_t PO_subzone(void)
|
||||
static enum eos PO_subzone(void)
|
||||
{
|
||||
Throw_error("\"!subzone {}\" is obsolete; use \"!zone {}\" instead.");
|
||||
// call "!zone" instead
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ACME - a crossassembler for producing 6502/65c02/65816 code.
|
||||
// Copyright (C) 1998-2009 Marco Baye
|
||||
// Copyright (C) 1998-2014 Marco Baye
|
||||
// Have a look at "acme.c" for further info
|
||||
//
|
||||
// Section stuff
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
|
||||
// "section" structure type definition
|
||||
struct section_t {
|
||||
struct section {
|
||||
zone_t zone; // current zone value
|
||||
const char *type; // "Zone", "Subzone" or "Macro"
|
||||
char *title; // zone title, subzone title or macro title
|
||||
@ -26,19 +26,19 @@ struct section_t {
|
||||
// Variables
|
||||
|
||||
// current section structure
|
||||
extern struct section_t *Section_now;
|
||||
extern struct section *Section_now;
|
||||
|
||||
|
||||
// Prototypes
|
||||
|
||||
// Write given info into given zone structure and activate it
|
||||
extern void Section_new_zone(struct section_t *, const char *type, char *title, int allocated);
|
||||
extern void Section_new_zone(struct section *section, const char *type, char *title, int allocated);
|
||||
// register pseudo opcodes
|
||||
extern void Section_init(void);
|
||||
// Setup outermost section
|
||||
extern void Section_passinit(void);
|
||||
// Tidy up: If necessary, release section title.
|
||||
extern void Section_finalize(struct section_t *section);
|
||||
extern void Section_finalize(struct section *section);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ACME - a crossassembler for producing 6502/65c02/65816 code.
|
||||
// Copyright (C) 1998-2009 Marco Baye
|
||||
// Copyright (C) 1998-2014 Marco Baye
|
||||
// Have a look at "acme.c" for further info
|
||||
//
|
||||
// Tree stuff
|
||||
@ -63,7 +63,7 @@ void Tree_add_table(struct node_t **tree, struct node_t *table_to_add)
|
||||
// tree item that matches the given data (HashValue and DynaBuf-String).
|
||||
// Store "Body" component in NodeBody and return TRUE.
|
||||
// Return FALSE if no matching item found.
|
||||
int Tree_easy_scan(struct node_t *tree, void **node_body, struct dynabuf_t *dyna_buf)
|
||||
int Tree_easy_scan(struct node_t *tree, void **node_body, struct dynabuf *dyna_buf)
|
||||
{
|
||||
struct node_t wanted; // temporary storage
|
||||
const char *p1,
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ACME - a crossassembler for producing 6502/65c02/65816 code.
|
||||
// Copyright (C) 1998-2009 Marco Baye
|
||||
// Copyright (C) 1998-2014 Marco Baye
|
||||
// Have a look at "acme.c" for further info
|
||||
//
|
||||
// Tree stuff
|
||||
@ -47,7 +47,7 @@ struct node_ra_t {
|
||||
extern void Tree_add_table(struct node_t **tree, struct node_t *table_to_add);
|
||||
// Search for a given ID string in a given tree. Store "Body" component in
|
||||
// NodeBody and return TRUE. Return FALSE if no matching item found.
|
||||
extern int Tree_easy_scan(struct node_t *tree, void **node_body, struct dynabuf_t *dyna_buf);
|
||||
extern int Tree_easy_scan(struct node_t *tree, void **node_body, struct dynabuf *dyna_buf);
|
||||
// Search for a "RAM tree" item. Save pointer to found tree item in given
|
||||
// location. If no matching item is found, check the "Create" flag: If set,
|
||||
// create new tree item, link to tree, fill with data and store its pointer.
|
||||
|
Loading…
Reference in New Issue
Block a user