| 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 | // Input stuff |
| 7 | #ifndef input_H |
| 8 | #define input_H |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | #include <string.h> |
| 12 | |
| 13 | // type definitions |
| 14 | |
| 15 | // values for input_t component "Src.State" |
| 16 | enum inputstate_t { |
| 17 | INPUTSTATE_NORMAL, // everything's fine |
| 18 | INPUTSTATE_AGAIN, // re-process last byte |
| 19 | INPUTSTATE_SKIPBLANKS, // shrink multiple spaces |
| 20 | INPUTSTATE_LF, // send start-of-line after end-of-statement |
| 21 | INPUTSTATE_CR, // same, but also remember to skip LF |
| 22 | INPUTSTATE_SKIPLF, // skip LF if that's next |
| 23 | INPUTSTATE_COMMENT, // skip characters until newline or EOF |
| 24 | INPUTSTATE_EOB, // send end-of-block after end-of-statement |
| 25 | INPUTSTATE_EOF, // send end-of-file after end-of-statement |
| 26 | }; |
| 27 | |
| 28 | |
| 29 | |
| 30 | typedef struct { |
| 31 | const char* original_filename;// during RAM reads, too |
| 32 | int line_number; // in file (on RAM reads, too) |
| 33 | bool source_is_ram; // TRUE if RAM, FALSE if file |
| 34 | enum inputstate_t state; // state of input |
| 35 | union { |
| 36 | FILE* fd; // file descriptor |
| 37 | char* ram_ptr; // RAM read ptr (loop or macro block) |
| 38 | } src; |
| 39 | char *string_source; |
| 40 | int string_source_length; |
| 41 | int string_source_position; |
| 42 | } input_t; |
| 43 | |
| 44 | // Constants |
| 45 | extern const char FILE_READBINARY[]; |
| 46 | // Special characters |
| 47 | // The program *heavily* relies on CHAR_EOS (end of statement) being 0x00! |
| 48 | #define CHAR_EOS (0) // end of statement (in high-level format) |
| 49 | #define CHAR_SOB '{' // start of block |
| 50 | #define CHAR_EOB '}' // end of block |
| 51 | #define CHAR_SOL (10) // start of line (in high-level format) |
| 52 | #define CHAR_EOF (13) // end of file (in high-level format) |
| 53 | // If the characters above are changed, don't forget to adjust Byte_flags[]! |
| 54 | |
| 55 | |
| 56 | // Variables |
| 57 | extern input_t* Input_now; // current input structure |
| 58 | |
| 59 | |
| 60 | // Prototypes |
| 61 | |
| 62 | // register pseudo opcodes |
| 63 | extern void Input_init(void); |
| 64 | // Let current input point to start of file |
| 65 | extern void Input_new_file(char *); |
| 66 | // get next byte from currently active byte source in shortened high-level |
| 67 | // format. When inside quotes, use GetQuotedByte() instead! |
| 68 | extern char GetByte(void); |
| 69 | // get next byte from currently active byte source in un-shortened high-level |
| 70 | // format. Complains if CHAR_EOS (end of statement) is read. |
| 71 | extern char GetQuotedByte(void); |
| 72 | // Skip remainder of statement, for example on error |
| 73 | extern void Input_skip_remainder(void); |
| 74 | // Ensure that the remainder of the current statement is empty, for example |
| 75 | // after mnemonics using implied addressing. |
| 76 | extern void Input_ensure_EOS(void); |
| 77 | // Skip or store block (starting with next byte, so call directly after |
| 78 | // reading opening brace). |
| 79 | // If "Store" is TRUE, the block is read into GlobalDynaBuf, then a copy |
| 80 | // is made and a pointer to that is returned. |
| 81 | // If "Store" is FALSE, NULL is returned. |
| 82 | // After calling this function, GotByte holds '}'. Unless EOF was found first, |
| 83 | // but then a serious error would have been thrown. |
| 84 | extern char* Input_skip_or_store_block(bool store); |
| 85 | // Read bytes and add to GlobalDynaBuf until the given terminator (or CHAR_EOS) |
| 86 | // is found. Act upon single and double quotes by entering (and leaving) quote |
| 87 | // mode as needed (So the terminator does not terminate when inside quotes). |
| 88 | extern void Input_until_terminator(char terminator); |
| 89 | // Append to GlobalDynaBuf while characters are legal for keywords. |
| 90 | // Throws "missing string" error if none. Returns number of characters added. |
| 91 | extern int Input_append_keyword_to_global_dynabuf(void); |
| 92 | // Check whether GotByte is a dot. |
| 93 | // If not, store global zone value. |
| 94 | // If yes, store current zone value and read next byte. |
| 95 | // Then jump to Input_read_keyword(), which returns length of keyword. |
| 96 | extern int Input_read_zone_and_keyword(zone_t*); |
| 97 | // Clear dynamic buffer, then append to it until an illegal (for a keyword) |
| 98 | // character is read. Zero-terminate the string. Return its length (without |
| 99 | // terminator). |
| 100 | // Zero lengths will produce a "missing string" error. |
| 101 | extern int Input_read_keyword(void); |
| 102 | // Clear dynamic buffer, then append to it until an illegal (for a keyword) |
| 103 | // character is read. Zero-terminate the string, then convert to lower case. |
| 104 | // Return its length (without terminator). |
| 105 | // Zero lengths will produce a "missing string" error. |
| 106 | extern int Input_read_and_lower_keyword(void); |
| 107 | // Try to read a file name. If "allow_library" is TRUE, library access by using |
| 108 | // <...> quoting is possible as well. The file name given in the assembler |
| 109 | // source code is converted from UNIX style to platform style. |
| 110 | // Returns whether error occurred (TRUE on error). Filename in GlobalDynaBuf. |
| 111 | // Errors are handled and reported, but caller should call |
| 112 | // Input_skip_remainder() then. |
| 113 | extern bool Input_read_filename(bool library_allowed); |
| 114 | // Try to read a comma, skipping spaces before and after. Return TRUE if comma |
| 115 | // found, otherwise FALSE. |
| 116 | extern bool Input_accept_comma(void); |
| 117 | // read optional info about parameter length |
| 118 | extern int Input_get_force_bit(void); |
| 119 | |
| 120 | |
| 121 | #endif |