| 1 |
// |
| 2 |
// ACME - a crossassembler for producing 6502/65c02/65816 code. |
| 3 |
// Copyright (C) 1998-2006 Marco Baye |
| 4 |
// Have a look at "acme.c" for further info |
| 5 |
// |
| 6 |
// Global stuff - things that are needed by several modules |
| 7 |
#ifndef global_H |
| 8 |
#define global_H |
| 9 |
|
| 10 |
#include <stdio.h> |
| 11 |
#include <stdlib.h> |
| 12 |
#include <setjmp.h> |
| 13 |
#include "config.h" |
| 14 |
|
| 15 |
|
| 16 |
// Constants |
| 17 |
|
| 18 |
#define SF_FOUND_BLANK (1u) // statement had space or tab |
| 19 |
#define SF_IMPLIED_LABEL (2u) // statement had implied label def |
| 20 |
extern const char s_65816[]; |
| 21 |
extern const char s_and[]; |
| 22 |
extern const char s_asl[]; |
| 23 |
extern const char s_asr[]; |
| 24 |
extern const char s_brl[]; |
| 25 |
extern const char s_cbm[]; |
| 26 |
extern const char s_eor[]; |
| 27 |
extern const char s_error[]; |
| 28 |
extern const char s_lsr[]; |
| 29 |
extern const char s_scrxor[]; |
| 30 |
// Error messages during assembly |
| 31 |
extern const char exception_cannot_open_input_file[]; |
| 32 |
extern const char exception_missing_string[]; |
| 33 |
extern const char exception_no_left_brace[]; |
| 34 |
extern const char exception_no_memory_left[]; |
| 35 |
extern const char exception_no_right_brace[]; |
| 36 |
//extern const char exception_not_yet[]; |
| 37 |
extern const char exception_number_out_of_range[]; |
| 38 |
extern const char exception_pc_undefined[]; |
| 39 |
extern const char exception_syntax[]; |
| 40 |
// Byte flags table |
| 41 |
extern const char Byte_flags[]; |
| 42 |
#define BYTEFLAGS(c) (Byte_flags[(unsigned char) c]) |
| 43 |
#define STARTS_KEYWORD (1u << 7) // Byte is allowed to start a keyword |
| 44 |
#define CONTS_KEYWORD (1u << 6) // Byte is allowed in a keyword |
| 45 |
#define BYTEIS_UPCASE (1u << 5) // Byte is upper case and can be |
| 46 |
// converted to lower case by OR-ing this bit(!) |
| 47 |
#define BYTEIS_SYNTAX (1u << 4) // special character for input syntax |
| 48 |
#define FOLLOWS_ANON (1u << 3) // preceding '-' are backward label |
| 49 |
// bits 2, 1 and 0 are unused |
| 50 |
|
| 51 |
|
| 52 |
// Variables |
| 53 |
|
| 54 |
extern node_t* pseudo_opcode_tree;// tree to hold pseudo opcodes |
| 55 |
// structures |
| 56 |
enum eos_t { |
| 57 |
SKIP_REMAINDER, // skip remainder of line - (after errors) |
| 58 |
ENSURE_EOS, // make sure there's nothing left in statement |
| 59 |
PARSE_REMAINDER, // parse what's left |
| 60 |
AT_EOS_ANYWAY, // actually, same as PARSE_REMAINDER |
| 61 |
}; |
| 62 |
extern int pass_count; |
| 63 |
extern int Process_verbosity;// Level of additional output |
| 64 |
extern char GotByte;// Last byte read (processed) |
| 65 |
// Global counters |
| 66 |
extern int pass_undefined_count;// "NeedValue" type errors in current pass |
| 67 |
extern int pass_real_errors; // Errors yet |
| 68 |
extern signed long max_errors; // errors before giving up |
| 69 |
extern FILE* msg_stream; // set to stdout by --errors_to_stdout |
| 70 |
extern jmp_buf exception_env; |
| 71 |
extern char* error_message; |
| 72 |
//extern int cbm_load_address; |
| 73 |
|
| 74 |
// Macros for skipping a single space character |
| 75 |
#define SKIPSPACE() do {if(GotByte == ' ') GetByte();} while(0) |
| 76 |
#define NEXTANDSKIPSPACE() do {if(GetByte() == ' ') GetByte();} while(0) |
| 77 |
|
| 78 |
|
| 79 |
// Prototypes |
| 80 |
|
| 81 |
// Allocate memory and die if not available |
| 82 |
extern inline void* safe_malloc(size_t); |
| 83 |
// Parse block, beginning with next byte. |
| 84 |
// End reason (either CHAR_EOB or CHAR_EOF) can be found in GotByte afterwards |
| 85 |
// Has to be re-entrant. |
| 86 |
extern void Parse_until_eob_or_eof(void); |
| 87 |
// Skip space. If GotByte is CHAR_SOB ('{'), parse block and return TRUE. |
| 88 |
// Otherwise (if there is no block), return FALSE. |
| 89 |
// Don't forget to call EnsureEOL() afterwards. |
| 90 |
extern int Parse_optional_block(void); |
| 91 |
// Output a warning. |
| 92 |
// This means the produced code looks as expected. But there has been a |
| 93 |
// situation that should be reported to the user, for example ACME may have |
| 94 |
// assembled a 16-bit parameter with an 8-bit value. |
| 95 |
extern void Throw_warning(const char*); |
| 96 |
// Output a warning if in first pass. See above. |
| 97 |
extern void Throw_first_pass_warning(const char*); |
| 98 |
// Output an error. |
| 99 |
// This means something went wrong in a way that implies that the output |
| 100 |
// almost for sure won't look like expected, for example when there was a |
| 101 |
// syntax error. The assembler will try to go on with the assembly though, so |
| 102 |
// the user gets to know about more than one of his typos at a time. |
| 103 |
extern void Throw_error(const char*); |
| 104 |
// Output a serious error, stopping assembly. |
| 105 |
// Serious errors are those that make it impossible to go on with the |
| 106 |
// assembly. Example: "!fill" without a parameter - the program counter cannot |
| 107 |
// be set correctly in this case, so proceeding would be of no use at all. |
| 108 |
extern void Throw_serious_error(const char*); |
| 109 |
// Handle bugs |
| 110 |
extern void Bug_found(const char*, int); |
| 111 |
|
| 112 |
|
| 113 |
#endif |