2016-12-28 20:32:00 +00:00
|
|
|
// ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code.
|
2020-04-14 00:28:31 +00:00
|
|
|
// Copyright (C) 1998-2020 Marco Baye
|
2012-02-27 21:14:46 +00:00
|
|
|
// Have a look at "acme.c" for further info
|
|
|
|
//
|
|
|
|
// Global stuff - things that are needed by several modules
|
2014-11-22 01:36:02 +00:00
|
|
|
// 19 Nov 2014 Merged Johann Klasek's report listing generator patch
|
2014-11-23 23:40:01 +00:00
|
|
|
// 23 Nov 2014 Merged Martin Piper's "--msvc" error output patch
|
2012-02-27 21:14:46 +00:00
|
|
|
#ifndef global_H
|
|
|
|
#define global_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-11-22 01:36:02 +00:00
|
|
|
#include <string.h>
|
2012-02-27 21:14:46 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2013-06-26 23:01:00 +00:00
|
|
|
#define LOCAL_PREFIX '.' // FIXME - this is not yet used consistently!
|
2017-10-29 23:29:07 +00:00
|
|
|
#define CHEAP_PREFIX '@' // prefix character for cheap locals
|
2012-02-27 21:14:46 +00:00
|
|
|
|
|
|
|
// Constants
|
|
|
|
|
|
|
|
#define SF_FOUND_BLANK (1u << 0) // statement had space or tab
|
|
|
|
#define SF_IMPLIED_LABEL (1u << 1) // statement had implied label def
|
|
|
|
extern const char s_and[];
|
|
|
|
extern const char s_asl[];
|
|
|
|
extern const char s_asr[];
|
2014-11-23 23:40:01 +00:00
|
|
|
extern const char s_bra[];
|
2012-02-27 21:14:46 +00:00
|
|
|
extern const char s_brl[];
|
|
|
|
extern const char s_cbm[];
|
|
|
|
extern const char s_eor[];
|
|
|
|
extern const char s_error[];
|
|
|
|
extern const char s_lsr[];
|
|
|
|
extern const char s_scrxor[];
|
2014-12-04 11:26:42 +00:00
|
|
|
extern char s_untitled[];
|
|
|
|
extern const char s_Zone[];
|
|
|
|
#define s_zone (s_subzone + 3) // Yes, I know I'm sick
|
|
|
|
extern const char s_subzone[];
|
2014-12-16 08:21:44 +00:00
|
|
|
extern const char s_pet[];
|
|
|
|
extern const char s_raw[];
|
|
|
|
extern const char s_scr[];
|
2014-12-04 11:26:42 +00:00
|
|
|
// error messages during assembly
|
2012-02-27 21:14:46 +00:00
|
|
|
extern const char exception_cannot_open_input_file[];
|
|
|
|
extern const char exception_missing_string[];
|
2017-10-21 19:59:56 +00:00
|
|
|
extern const char exception_negative_size[];
|
2012-02-27 21:14:46 +00:00
|
|
|
extern const char exception_no_left_brace[];
|
|
|
|
extern const char exception_no_memory_left[];
|
|
|
|
extern const char exception_no_right_brace[];
|
|
|
|
//extern const char exception_not_yet[];
|
|
|
|
extern const char exception_number_out_of_range[];
|
|
|
|
extern const char exception_pc_undefined[];
|
|
|
|
extern const char exception_syntax[];
|
2014-12-04 11:26:42 +00:00
|
|
|
// byte flags table
|
2012-02-27 21:14:46 +00:00
|
|
|
extern const char Byte_flags[];
|
|
|
|
#define BYTEFLAGS(c) (Byte_flags[(unsigned char) c])
|
|
|
|
#define STARTS_KEYWORD (1u << 7) // Byte is allowed to start a keyword
|
|
|
|
#define CONTS_KEYWORD (1u << 6) // Byte is allowed in a keyword
|
|
|
|
#define BYTEIS_UPCASE (1u << 5) // Byte is upper case and can be
|
|
|
|
// converted to lower case by OR-ing this bit(!)
|
|
|
|
#define BYTEIS_SYNTAX (1u << 4) // special character for input syntax
|
|
|
|
#define FOLLOWS_ANON (1u << 3) // preceding '-' are backward label
|
2014-06-02 00:47:46 +00:00
|
|
|
// bits 2, 1 and 0 are currently unused
|
2012-02-27 21:14:46 +00:00
|
|
|
|
2017-10-29 23:29:07 +00:00
|
|
|
// TODO - put in runtime struct:
|
2012-02-27 21:14:46 +00:00
|
|
|
extern int pass_count;
|
|
|
|
extern char GotByte; // Last byte read (processed)
|
|
|
|
extern int pass_undefined_count; // "NeedValue" type errors in current pass
|
|
|
|
extern int pass_real_errors; // Errors yet
|
2017-10-29 23:29:07 +00:00
|
|
|
// configuration
|
|
|
|
struct config {
|
|
|
|
char pseudoop_prefix; // '!' or '.'
|
|
|
|
int process_verbosity; // level of additional output
|
2020-04-14 00:28:31 +00:00
|
|
|
int warn_on_indented_labels; // actually bool: warn if indented label is encountered
|
|
|
|
int warn_on_old_for; // actually bool: warn if "!for" with old syntax is found
|
|
|
|
int warn_on_type_mismatch; // actually bool: use type-checking system
|
2017-10-29 23:29:07 +00:00
|
|
|
signed long max_errors; // errors before giving up
|
|
|
|
int format_msvc; // actually bool, enabled by --msvc
|
|
|
|
int format_color; // actually bool, enabled by --color
|
2020-04-14 00:28:31 +00:00
|
|
|
FILE *msg_stream; // defaults to stderr, changed to stdout by --use-stdout
|
|
|
|
int honor_leading_zeroes; // actually bool, TRUE, disabled by --ignore-zeroes
|
|
|
|
int segment_warning_is_error; // actually bool, FALSE, enabled by --strict-segments
|
2017-10-29 23:29:07 +00:00
|
|
|
};
|
|
|
|
extern struct config config;
|
2012-02-27 21:14:46 +00:00
|
|
|
|
2014-11-22 01:36:02 +00:00
|
|
|
// report stuff
|
|
|
|
#define REPORT_ASCBUFSIZE 1024
|
|
|
|
#define REPORT_BINBUFSIZE 9 // eight are shown, then "..."
|
|
|
|
struct report {
|
|
|
|
FILE *fd; // report file descriptor (NULL => no report)
|
|
|
|
struct input *last_input;
|
|
|
|
size_t asc_used;
|
|
|
|
size_t bin_used;
|
|
|
|
int bin_address; // address at start of bin_buf[]
|
|
|
|
char asc_buf[REPORT_ASCBUFSIZE]; // source bytes
|
|
|
|
char bin_buf[REPORT_BINBUFSIZE]; // output bytes
|
|
|
|
};
|
2017-10-16 17:01:44 +00:00
|
|
|
extern struct report *report; // TODO - put in "part" struct
|
2014-11-22 01:36:02 +00:00
|
|
|
|
2012-02-27 21:14:46 +00:00
|
|
|
// Macros for skipping a single space character
|
|
|
|
#define SKIPSPACE() \
|
|
|
|
do { \
|
|
|
|
if (GotByte == ' ') \
|
|
|
|
GetByte(); \
|
|
|
|
} while (0)
|
|
|
|
#define NEXTANDSKIPSPACE() \
|
|
|
|
do { \
|
|
|
|
if (GetByte() == ' ') \
|
|
|
|
GetByte(); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
|
// Prototypes
|
|
|
|
|
2017-10-29 23:29:07 +00:00
|
|
|
// set configuration to default values
|
|
|
|
extern void config_default(struct config *conf);
|
2014-12-04 11:26:42 +00:00
|
|
|
// allocate memory and die if not available
|
2012-02-27 21:14:46 +00:00
|
|
|
extern void *safe_malloc(size_t);
|
|
|
|
// Parse block, beginning with next byte.
|
|
|
|
// End reason (either CHAR_EOB or CHAR_EOF) can be found in GotByte afterwards
|
|
|
|
// Has to be re-entrant.
|
|
|
|
extern void Parse_until_eob_or_eof(void);
|
|
|
|
// Skip space. If GotByte is CHAR_SOB ('{'), parse block and return TRUE.
|
|
|
|
// Otherwise (if there is no block), return FALSE.
|
|
|
|
// Don't forget to call EnsureEOL() afterwards.
|
|
|
|
extern int Parse_optional_block(void);
|
2016-10-08 12:19:12 +00:00
|
|
|
// error/warning counter so macro calls can find out whether to show a call stack
|
|
|
|
extern int Throw_get_counter(void);
|
2012-02-27 21:14:46 +00:00
|
|
|
// Output a warning.
|
|
|
|
// This means the produced code looks as expected. But there has been a
|
|
|
|
// situation that should be reported to the user, for example ACME may have
|
|
|
|
// assembled a 16-bit parameter with an 8-bit value.
|
|
|
|
extern void Throw_warning(const char *);
|
|
|
|
// Output a warning if in first pass. See above.
|
|
|
|
extern void Throw_first_pass_warning(const char *);
|
|
|
|
// Output an error.
|
|
|
|
// This means something went wrong in a way that implies that the output
|
|
|
|
// almost for sure won't look like expected, for example when there was a
|
|
|
|
// syntax error. The assembler will try to go on with the assembly though, so
|
|
|
|
// the user gets to know about more than one of his typos at a time.
|
|
|
|
extern void Throw_error(const char *);
|
|
|
|
// Output a serious error, stopping assembly.
|
|
|
|
// Serious errors are those that make it impossible to go on with the
|
|
|
|
// assembly. Example: "!fill" without a parameter - the program counter cannot
|
|
|
|
// be set correctly in this case, so proceeding would be of no use at all.
|
|
|
|
extern void Throw_serious_error(const char *);
|
2014-12-04 11:26:42 +00:00
|
|
|
// handle bugs
|
2012-02-27 21:14:46 +00:00
|
|
|
extern void Bug_found(const char *, int);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|