diff --git a/contrib/toacme/docs/CHANGES b/contrib/toacme/docs/CHANGES index b0bef06..3be0307 100644 --- a/contrib/toacme/docs/CHANGES +++ b/contrib/toacme/docs/CHANGES @@ -1,4 +1,8 @@ +2006-10-04 + Release 0.10 + Adjusted support for illegals to latest changes in ACME. + 2006-03-12 Release 0.9 Improved "Giga Assembler" mode. Thanks to Andreas Paul for his help. diff --git a/contrib/toacme/src/ab.c b/contrib/toacme/src/ab.c index c2ea6a2..0d06a31 100644 --- a/contrib/toacme/src/ab.c +++ b/contrib/toacme/src/ab.c @@ -1,13 +1,9 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2005 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // -// stuff needed for both "AssBlaster 3.x" and "F8-AssBlaster" -// +// stuff needed for both "AssBlaster 3.x" and "Flash8-AssBlaster" - -// Includes -// #include <stdio.h> #include "ab.h" #include "acme.h" @@ -16,7 +12,12 @@ // Constants -// + +// Generate error/warning messages +const char error_unknown_addressing[] = "Conversion failed: AssBlaster file contains unknown addressing mode.\n"; +const char error_unknown_compression[] = "Conversion failed: AssBlaster file contains unknown number compression.\n"; +const char warning_unknown_number_format[] = "Warning: AssBlaster file uses unknown number format. Fallback to hexadecimal.\n"; + #define SCREENCODE_UPARROW (0x1e) // replacement characters for problematic label names #define AB_LABELSPECIAL_NUL ('O') // AssBlaster uses only lower case @@ -33,10 +34,10 @@ // 0x41-0x5f upper case screen codes (used for comments) // 0x60-0x7f unused ? #define AB_FIRST_MNEMONIC 0x80 -// 0x80-0xec differ between AssBlaster 3.x and F8-AssBlaster +// 0x80-0xec differ between AssBlaster 3.x and Flash8-AssBlaster // 0xed-0xfe unused ? // 0xff end-of-line -#define AB_PSEUDOOFFSET_MACRODEF 5 // in AB3.x and F8-AB +#define AB_PSEUDOOFFSET_MACRODEF 5 // in AB3 and F8AB #define AB_PSEUDOOFFSET_MACROCALL 7 // indices in PO table #define AB_PSEUDOOFFSET_OUTFILE 10 // are equal // after mnemonic or pseudo opcode, numbers may follow: @@ -44,7 +45,7 @@ // Pre- and postfixes for addressing modes // Don't care whether argument is 8, 16 or 24 bits wide -const char* ab_address_modes[][2] = { +const char* addressing_modes[][2] = { {"", "" }, // ($00=%.....) implied {" ", "" }, // ($01=%....1) absolute {" ", ",x" }, // ($02=%...1.) absolute,x @@ -59,7 +60,7 @@ const char* ab_address_modes[][2] = { {" (", ")" }, // ($0b=%.1.11) indirect // above: used by both AB3 and F8AB (except $0a, which is no longer // used by F8AB. But it's indistinguishable from $01 anyway). - // FIXME - what does AB3 with the other unused addressing modes? + // FIXME - what does AB3 do with the other unused addressing modes? // I think old AB3 sources may also use mode 0c! // below: used by F8AB only {NULL, NULL }, // ($0c=%.11..) unused (indirect-x) @@ -67,6 +68,7 @@ const char* ab_address_modes[][2] = { {NULL, NULL }, // ($0e=%.111.) unused (absolute) {NULL, NULL }, // ($0f=%.1111) unused (absolute-x) {" ", "" }, // ($10=%1....) MVP/MVN in F8AB: arg1.arg2 +#define MVP_MVN_ADDRMODE 0x10 {NULL, NULL }, // ($11=%1...1) unused (indirect) {NULL, NULL }, // ($12=%1..1.) unused (indirect long) {" [", "],y" }, // ($13=%1..11) indirect-y long @@ -78,33 +80,25 @@ const char* ab_address_modes[][2] = { // as "arg1.arg2" instead of "arg1,arg2". Therefore the following // constant is used to fix it on-the-fly. }; -#define AB_MVP_MVN_ADDRMODE 0x10 // Variables -// struct ab_t* conf; // Functions -// - -// Generate error/warning messages // -const char error_unknown_addressing[] = "Conversion failed: AssBlaster file contains unknown addressing mode.\n"; -const char error_unknown_compression[] = "Conversion failed: AssBlaster file contains unknown number compression.\n"; -const char warning_unknown_number_format[] = "Warning: AssBlaster file uses unknown number format. Fallback to hexadecimal.\n"; -void ab_generate_errors(int ErrBits) { - if(ErrBits & AB_ERRBIT_UNKNOWN_ADDRMODE) { +static void generate_errors(int err_bits) { + if(err_bits & AB_ERRBIT_UNKNOWN_ADDRMODE) { fputs(error_unknown_addressing, stderr); fprintf(global_output_stream, "; ToACME: %s", error_unknown_addressing); } - if(ErrBits & AB_ERRBIT_UNKNOWN_NUMBER_COMPRESSION) { + if(err_bits & AB_ERRBIT_UNKNOWN_NUMBER_COMPRESSION) { fputs(error_unknown_compression, stderr); fprintf(global_output_stream, "; ToACME: %s", error_unknown_compression); } - if(ErrBits & AB_ERRBIT_UNKNOWN_NUMBER_FORMAT) { + if(err_bits & AB_ERRBIT_UNKNOWN_NUMBER_FORMAT) { fputs(warning_unknown_number_format, stderr); fprintf(global_output_stream, "; ToACME: %s", warning_unknown_number_format); } @@ -112,10 +106,9 @@ void ab_generate_errors(int ErrBits) { // Convert macro/label name character. // AssBlaster allows '^', '[' and ']' in names, so replace these chars. -// -char ab_conv_name_char(char b) { - b = SCR2ISO(b); - switch(b) { +static char conv_name_char(char byte) { + byte = SCR2ISO(byte); + switch(byte) { case 0x40: return(AB_LABELSPECIAL_NUL); case '[': @@ -127,69 +120,63 @@ char ab_conv_name_char(char b) { case '^': return(AB_LABELSPECIAL_UP); default: - return(b); + return(byte); } } // Output binary representation of value -// -void ab_output_binary(unsigned long int v) { - int m = 128; +void AB_output_binary(unsigned long int value) { + int mask = 128; - if(v > 0xff) - ab_output_binary(v >> 8); - v &= 0xff; - while(m) { - PutByte((v & m) ? '1' : '0'); - m >>= 1; + if(value > 0xff) + AB_output_binary(value >> 8); + value &= 0xff; + while(mask) { + IO_put_byte((value & mask) ? '1' : '0'); + mask >>= 1; } } // Output hex representation of value -// -void ab_output_hexadecimal(unsigned long int v) { - if(v > 0xff) - ab_output_hexadecimal(v >> 8); - io_put_low_byte_hex(v); +void AB_output_hexadecimal(unsigned long int value) { + if(value > 0xff) + AB_output_hexadecimal(value >> 8); + IO_put_low_byte_hex(value); } // Convert and send macro/label name (until illegal character comes along) -// -void ab_pipe_global_name(void) { +static void pipe_global_name(void) { while((GotByte < 0x20) || ((GotByte >= '0') && (GotByte <= '9'))) { - PutByte(ab_conv_name_char(GotByte)); - GetByte(); + IO_put_byte(conv_name_char(GotByte)); + IO_get_byte(); } } // Convert and send label name (until illegal character comes along) // Level 1 -void ab_pipe_name(void) { +static void pipe_name(void) { // Dieser kleine Hack macht alle lokalen ABL-Labels // Auch unter ACME lokal. nur mit '^' global markierte // Labels werden auch global �bernommen ... if(GotByte == SCREENCODE_UPARROW) - GetByte(); // global: ^witharrow => witharrow + IO_get_byte(); // global: ^witharrow => witharrow else - PutByte('.'); // local: allothers => .allothers - ab_pipe_global_name(); // this does exactly what is needed + IO_put_byte('.'); // local: allothers => .allothers + pipe_global_name(); // this does exactly what is needed } // Parse quoted strings -// -void ab_parse_quoted(void) {// now GotByte = unhandled opening quote - - PutByte('"'); - GetByte(); +static void parse_quoted(void) {// now GotByte = unhandled opening quote + IO_put_byte('"'); + IO_get_byte(); while((GotByte != AB_ENDOFLINE) && (GotByte != '"')) { - PutByte(SCR2ISO(GotByte)); - GetByte(); + IO_put_byte(SCR2ISO(GotByte)); + IO_get_byte(); } - PutByte('"'); - + IO_put_byte('"'); // Closing quote is handled, but EndOfLine must remain unhandled if(GotByte == '"') - GetByte(); + IO_get_byte(); } // Parse label names, quoted strings, operators, literal values etc. @@ -199,8 +186,8 @@ void ab_parse_quoted(void) {// now GotByte = unhandled opening quote // after macro names (at definitions and calls) and in the MVP/MVN addressing // mode. The kluge variable "dot_replacement" is used to replace the '.' // character with the correct character for ACME. -int ab_parse_unspecified(int dot_replacement) { - int ErrBits = 0; +static int parse_unspecified(char dot_replacement) { + int err_bits = 0; while((GotByte != AB_ENDOFLINE) && (GotByte != AB_COMMENT)) { // kluge: replace '.' character with current replacement and @@ -210,45 +197,44 @@ int ab_parse_unspecified(int dot_replacement) { dot_replacement = '.'; // in future, keep } if(GotByte & AB_NUMVAL_FLAGBIT) - ErrBits |= conf->number_parser(); + err_bits |= conf->number_parser(); else { if(GotByte < 0x20) - ab_pipe_name(); + pipe_name(); else { if(GotByte == '"') - ab_parse_quoted(); + parse_quoted(); else { - PutByte(SCR2ISO(GotByte)); - GetByte(); + IO_put_byte(SCR2ISO(GotByte)); + IO_get_byte(); } } } } - return(ErrBits); + return(err_bits); } // Parse macro call or start of definition (beware of full stops). // Returns error bits. -// -int ab_parse_macro_stuff(void) { // now GotByte = unhandled byte +static int parse_macro_stuff(void) { // now GotByte = unhandled byte // I guess local macros are useless, so don't // do the scope fixing as for macro names! - ab_pipe_global_name(); - return(ab_parse_unspecified(' ')); // output macro arguments + pipe_global_name(); + return(parse_unspecified(SPACE)); // output macro arguments } // Process mnemonics (real opcodes). Returns error bits. // Level 1 -int ab_parse_mnemo(int mnemonic_offset) { +static int parse_mnemo(int mnemonic_offset) { const char *mnemonic, *pre, *post; - int AddressingMode, + int addressing_mode, dot_replacement = '.', - ErrBits = 0; + err_bits = 0; - AddressingMode = GetByte(); // get addressing mode - GetByte(); // and fetch next (not handled here) + addressing_mode = IO_get_byte(); // get addressing mode + IO_get_byte(); // and fetch next (not handled here) mnemonic = conf->mnemonics[mnemonic_offset]; if(mnemonic == NULL) { fputs("Found unused mnemo code in input file.\n", stderr); @@ -256,10 +242,10 @@ int ab_parse_mnemo(int mnemonic_offset) { } fprintf(global_output_stream, "\t\t%s", mnemonic); // determine prefix and postfix of addressing mode - if(AddressingMode < conf->address_mode_count) { - pre = ab_address_modes[AddressingMode][0]; - post = ab_address_modes[AddressingMode][1]; - if(AddressingMode == AB_MVP_MVN_ADDRMODE) + if(addressing_mode < conf->address_mode_count) { + pre = addressing_modes[addressing_mode][0]; + post = addressing_modes[addressing_mode][1]; + if(addressing_mode == MVP_MVN_ADDRMODE) dot_replacement = ','; // replace '.' with ',' } else { pre = NULL; @@ -268,79 +254,78 @@ int ab_parse_mnemo(int mnemonic_offset) { // if addressing mode is invalid, set error bit // output prefix (or space if invalid) if((pre == NULL) || (post == NULL)) { - ErrBits |= AB_ERRBIT_UNKNOWN_ADDRMODE; - fprintf(stderr, "Found an unknown addressing mode bit pattern ($%x). Please tell my programmer.\n", AddressingMode); + err_bits |= AB_ERRBIT_UNKNOWN_ADDRMODE; + fprintf(stderr, "Found an unknown addressing mode bit pattern ($%x). Please tell my programmer.\n", addressing_mode); } if(pre) - PutString(pre); + IO_put_string(pre); else - PutByte(' '); - ErrBits |= ab_parse_unspecified(dot_replacement); // output arg + IO_put_byte(SPACE); + err_bits |= parse_unspecified(dot_replacement); // output arg if(post) { - PutString(post); + IO_put_string(post); } - return(ErrBits); + return(err_bits); } // Process pseudo opcodes. Returns error bits. // Level 1 -int ab_parse_pseudo_opcode(int pseudo_offset) { - const char* String; - int ErrBits = 0; +static int parse_pseudo_opcode(int pseudo_offset) { + const char* pseudo_opcode; + int err_bits = 0; - GetByte(); // and fetch next (not handled here) - PutString("\t\t"); - String = conf->pseudo_opcodes[pseudo_offset]; - if(String) - PutString(String); + IO_get_byte(); // and fetch next (not handled here) + IO_put_string("\t\t"); + pseudo_opcode = conf->pseudo_opcodes[pseudo_offset]; + if(pseudo_opcode) + IO_put_string(pseudo_opcode); // check for special cases switch(pseudo_offset) { case AB_PSEUDOOFFSET_MACROCALL: // (in ACME: '+') // ACME does not like spaces after the macro call char - ErrBits |= ab_parse_macro_stuff(); + err_bits |= parse_macro_stuff(); break; case AB_PSEUDOOFFSET_MACRODEF: // macro definition - PutByte(' ');// but here a space looks good :) - ErrBits |= ab_parse_macro_stuff(); - PutString(" {"); + IO_put_byte(SPACE);// but here a space looks good :) + err_bits |= parse_macro_stuff(); + IO_put_string(" {"); break; case AB_PSEUDOOFFSET_OUTFILE: // outfile selection - PutByte(' ');// but here a space looks good :) - ErrBits |= ab_parse_unspecified('.'); // output arg(s) - PutString(PseudoTrail_ToFile); + IO_put_byte(SPACE);// but here a space looks good :) + err_bits |= parse_unspecified('.'); // output arg(s) + IO_put_string(ACME_cbmformat); break; default: // all other pseudo opcodes - if((String) + if((pseudo_opcode) && (GotByte != AB_ENDOFLINE) && (GotByte != AB_COMMENT)) - PutByte(' ');// but here a space looks good :) - ErrBits |= ab_parse_unspecified('.'); // output pseudo opcode's arg(s) + IO_put_byte(SPACE);// but here a space looks good :) + err_bits |= parse_unspecified('.'); // output pseudo opcode's arg(s) } - return(ErrBits); + return(err_bits); } -// Main routine for AssBlaster conversion (works for both AB3.x and F8-AB). +// Main routine for AssBlaster conversion (works for both AB3 and F8AB). // Call with first byte of first line pre-read (in GotByte)! -// -void ab_main(struct ab_t* client_config) { - int ErrBits; +void AB_main(struct ab_t* client_config) { + int err_bits; const char *comment_indent; conf = client_config; - acme_SwitchToPet(); + ACME_switch_to_pet(); // convert lines until EndOfFile - while(!ReachedEOF) { - ErrBits = 0; // no errors yet (in this line) + while(!IO_reached_eof) { + err_bits = 0; // no errors yet (in this line) comment_indent = "\t"; if(GotByte < AB_FIRST_MNEMONIC) { switch(GotByte) { case 0: // empty line - GetByte(); // skip this byte + IO_get_byte(); // skip this byte break; case AB_COMMENT: // early comment @@ -349,55 +334,55 @@ void ab_main(struct ab_t* client_config) { case AB_SPACE: // empty line or late comment comment_indent = "\t\t\t\t"; - GetByte(); // skip this space + IO_get_byte(); // skip this space // output whatever found - ErrBits |= ab_parse_unspecified('.'); + err_bits |= parse_unspecified('.'); break; default: // implied label definition - ab_pipe_name(); + pipe_name(); } } else if(GotByte < conf->first_pseudo_opcode) { - ErrBits |= ab_parse_mnemo(GotByte - AB_FIRST_MNEMONIC); + err_bits |= parse_mnemo(GotByte - AB_FIRST_MNEMONIC); } else if(GotByte < conf->first_unused_byte_value) { - ErrBits |= ab_parse_pseudo_opcode(GotByte - conf->first_pseudo_opcode); + err_bits |= parse_pseudo_opcode(GotByte - conf->first_pseudo_opcode); } else if(GotByte != AB_ENDOFLINE) { fprintf(global_output_stream, "; ToACME: AssBlaster file used unknown code ($%x). ", GotByte); - GetByte(); // fetch next - ErrBits |= ab_parse_unspecified('.'); // output remainder + IO_get_byte(); // fetch next + err_bits |= parse_unspecified('.');// output remainder } // everything might be followed by a comment, so check if(GotByte == AB_COMMENT) { // skip empty comments by checking next byte - if(GetByte() != AB_ENDOFLINE) { + if(IO_get_byte() != AB_ENDOFLINE) { // something's there, so pipe until end of line - PutString(comment_indent); - PutByte(';'); + IO_put_string(comment_indent); + IO_put_byte(';'); do - PutByte(SCR2ISO(GotByte)); - while(GetByte() != AB_ENDOFLINE); + IO_put_byte(SCR2ISO(GotByte)); + while(IO_get_byte() != AB_ENDOFLINE); } } // now check whether line generated any errors - if(ErrBits) - ab_generate_errors(ErrBits); + if(err_bits) + generate_errors(err_bits); // if not at end-of-line, something's fishy if(GotByte != AB_ENDOFLINE) { if(GotByte == '\0') - PutString("; ToACME: found $00 - looks like end-of-file marker."); + IO_put_string("; ToACME: found $00 - looks like end-of-file marker."); else { fputs("Found data instead of end-of-line indicator!?.\n", stderr); - PutString("; ToACME: Garbage at end-of-line:"); + IO_put_string("; ToACME: Garbage at end-of-line:"); do - PutByte(SCR2ISO(GotByte)); - while(GetByte() != AB_ENDOFLINE); + IO_put_byte(SCR2ISO(GotByte)); + while(IO_get_byte() != AB_ENDOFLINE); } } - PutByte('\n'); + IO_put_byte('\n'); // read first byte of next line - GetByte(); + IO_get_byte(); } } diff --git a/contrib/toacme/src/ab.h b/contrib/toacme/src/ab.h index a808fb4..3163964 100644 --- a/contrib/toacme/src/ab.h +++ b/contrib/toacme/src/ab.h @@ -1,20 +1,15 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // -// stuff needed for both "AssBlaster 3.x" and "F8-AssBlaster" -// +// stuff needed for both "AssBlaster 3.x" and "Flash8-AssBlaster" #ifndef ab_H #define ab_H - -// Includes -// #include "config.h" -// Types -// +// Definition of "Type of AssBlaster" structure struct ab_t { int (*number_parser)(void); const char** pseudo_opcodes; @@ -26,22 +21,18 @@ struct ab_t { // Constants -// #define AB_ENDOFLINE 0xff // meaning of internal error word. errors are collected until *after* a line // has been finished so the warning messages don't interfere with the generated // source code. -#define AB_ERRBIT_UNKNOWN_ADDRMODE 0x01 -#define AB_ERRBIT_UNKNOWN_NUMBER_COMPRESSION 0x02 // invalid contents of SIZEMASK -#define AB_ERRBIT_UNKNOWN_NUMBER_FORMAT 0x04 // invalid contents of FORMATMASK - - +#define AB_ERRBIT_UNKNOWN_ADDRMODE (1u) +#define AB_ERRBIT_UNKNOWN_NUMBER_COMPRESSION (1u << 1) // SIZEMASK invalid +#define AB_ERRBIT_UNKNOWN_NUMBER_FORMAT (1u << 2) // FORMATMASK invalid // Prototypes -// -extern void ab_output_binary(unsigned long int v); -extern void ab_output_hexadecimal(unsigned long int v); -extern void ab_main(struct ab_t* client_config); +extern void AB_output_binary(unsigned long int value); +extern void AB_output_hexadecimal(unsigned long int value); +extern void AB_main(struct ab_t* client_config); #endif diff --git a/contrib/toacme/src/ab3.c b/contrib/toacme/src/ab3.c index bcea856..734cb53 100644 --- a/contrib/toacme/src/ab3.c +++ b/contrib/toacme/src/ab3.c @@ -1,13 +1,9 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // AssBlaster 3.x stuff -// - -// Includes -// #include <stdlib.h> #include <stdio.h> #include "config.h" @@ -19,10 +15,11 @@ // Constants -// + +#define AB3_ADDRESSING_MODES 12 // Mnemonic table in AssBlaster 3.x order -const char* ab3_mnemonics[] = { +static const char* mnemonic_table[] = { NULL, // $80 unused MnemonicCPX, // $81 MnemonicCPY, // $82 @@ -30,37 +27,24 @@ const char* ab3_mnemonics[] = { MnemonicLDY, // $84 MnemonicSTX, // $85 MnemonicSTY, // $86 -// start of illegals -// There are no official mnemonics for undocumented opcodes, but f8ab seems -// to confuse its ASR and ARR mnemonics. See below what they do. - MnemonicSAX, // $87 sta + stx totally broken in AB3! aka AAX -// SAX is called AAX in f8ab, but it is totally broken: it generates wrong -// opcodes, one addressing mode actually generates the same opcode as LDX abs8 - "!illegal ASR", // $88 0x6b (asr #8) aka ARR -// opcode 0x6b does an AND, then *rotates* A to the right and sets flags. -// ARR would be a much better name. Possibly confused. - "!illegal ARR", // $89 0x4b (arr #8) aka ASR, ALR -// opcode 0x4b does an AND, then *shifts* A to the right. -// ASR would be a much better name. Possibly confused. - "!illegal AXS", // $8a 0xcb (axs #8) aka SBX, SAX -// opcode 0xcb does X=(A&X)-# - MnemonicDCP, // $8b dec + cmp - "!illegal DOP", // $8c 0x64 (double nop, skip byte) aka SKB -// ...0x04,0x14,0x34,0x44,0x54,0x64,0x74,x80,0x82,0x89,0xc2,0xd4,0xe2,0xf4 - MnemonicISC, // $8d inc + sbc aka ISB - "!illegal KIL", // $8e 0x62 (kill/crash/hal)t aka JAM, CRA, HLT -// ...0x02,0x12,0x22,0x32,0x42,0x52,0x62,0x72,0x92,0xb2,0xd2,0xf2 - "!illegal LAR", // $8f lar never used in AB3? aka LAE, LAS -// in case opcode 0xbb was meant - that's a uselessly complex operation - MnemonicLAX, // $90 lda + ldx partially broken in AB3! -// LAX abs16,y generates opcode 0xbb (useless) instead of 0xbf. - MnemonicRLA, // $91 rol + and - MnemonicRRA, // $92 ror + adc - MnemonicSLO, // $93 asl + ora - MnemonicSRE, // $94 lsr + eor - "!illegal TOP", // $95 0x5c (triple nop, skip word) aka SKW -// ...0x0c, 0x1c, 0x3c, 0x5c, 0x7c, 0xdc, 0xfc -// end of illegals +//============================= start of illegals ============================= + MnemonicSAX, // $87 (AAX in AB3) broken in AB3, see docs + MnemonicASR, // $88 broken in AB3, see docs + MnemonicARR, // $89 broken in AB3, see docs + MnemonicSBX, // $8a (AXS in AB3) + MnemonicDCP, // $8b + MnemonicDOP, // $8c different opcodes, same action + MnemonicISC, // $8d + MnemonicJAM, // $8e (KIL in AB3) different opcodes, same action + "!error \"See the ToACME docs about the illegal opcode LAR.\";", + // $8f broken in AB3? see docs + MnemonicLAX, // $90 broken in AB3, see docs + MnemonicRLA, // $91 + MnemonicRRA, // $92 + MnemonicSLO, // $93 + MnemonicSRE, // $94 + MnemonicTOP, // $95 different opcodes, same action +//============================== end of illegals ============================== MnemonicADC, // $96 MnemonicAND, // $97 MnemonicASL, // $98 @@ -80,7 +64,7 @@ const char* ab3_mnemonics[] = { MnemonicORA, // $b4 MnemonicPHA, MnemonicPHP, MnemonicPLA, MnemonicPLP, // $b5-$b8 MnemonicROL, MnemonicROR, // $b9-$ba - MnemonicRTI, MnemonicRTS, // ($bf-$c0 in F8-AB) $bb-$bc + MnemonicRTI, MnemonicRTS, // ($bf-$c0 in F8AB) $bb-$bc MnemonicSBC, // $bd MnemonicSEC, MnemonicSED, MnemonicSEI, // $bc-$c0 MnemonicSTA, // $c1 @@ -89,26 +73,28 @@ const char* ab3_mnemonics[] = { }; // PseudoOpcode table in AssBlaster 3.x order -const char* ab3_pseudo_opcodes[] = { +static const char* pseudo_opcode_table[] = { +#define AB3_FIRST_PSEUDO_OPCODE 0xc8 NULL, // (la) $c8 // NULL because ACME does not need a pseudo opcode for label defs - PseudoOp_SetPC, // (ba) $c9 - PseudoOp_Byte, // (by) $ca - PseudoOp_Fill, // (br) $cb - PseudoOp_PetTxt, // (tx) $cc - PseudoOp_MacroDef, // (md) $cd (see AB_PSEUDOOFFSET_MACRODEF) - PseudoOp_EndMacroDef, // (me) $ce - PseudoOp_MacroCall, // (ma) $cf (see AB_PSEUDOOFFSET_MACROCALL) - PseudoOp_EOF, // (st) $d0 - PseudoOp_ScrTxt, // (ts) $d1 - PseudoOp_ToFile, // (to) $d2 (see AB_PSEUDOOFFSET_OUTFILE) - PseudoOp_Word, // (wo) $d3 + ACME_set_pc, // (ba) $c9 + ACME_po_byte, // (by) $ca + ACME_po_fill, // (br) $cb + ACME_po_pet, // (tx) $cc + ACME_po_macro, // (md) $cd (see AB_PSEUDOOFFSET_MACRODEF) + ACME_endmacro, // (me) $ce + ACME_macro_call, // (ma) $cf (see AB_PSEUDOOFFSET_MACROCALL) + ACME_po_eof, // (st) $d0 + ACME_po_scr, // (ts) $d1 + ACME_po_to, // (to) $d2 (see AB_PSEUDOOFFSET_OUTFILE) + ACME_po_word, // (wo) $d3 "; ToACME: Cannot convert \\kc.\n", // (kc) $d4 +#define AB3_FIRST_UNUSED_CODE 0xd5 + // 0xd5-0xfe are unused in AB3 }; // Parse AssBlaster's packed number format. Returns error bits. -// //#define AB_NUMVAL_FLAGBIT 0x80 // 10000000 indicates packed number #define AB3_NUMVAL_ADD_1 0x40 // 01000000 #define AB3_NUMVAL_ADD_256 0x20 // 00100000 @@ -120,90 +106,93 @@ const char* ab3_pseudo_opcodes[] = { #define AB3_NUMVAL__SIZE_0 0x01 // 00000001 #define AB3_NUMVAL__SIZE_1 0x04 // 00000100 #define AB3_NUMVAL__SIZE_2 0x00 // 00000000 -int ab3_parse_number(void) { // now GotByte = first byte of packed number - int Flags = GotByte, - ErrBits = 0; - unsigned long int Value = 0, - Add = 0; +static int parse_number(void) { // now GotByte = first byte of packed number + int flags = GotByte, + err_bits = 0; + unsigned long int value = 0, + add = 0; // decode value - if(Flags & AB3_NUMVAL_ADD_1) - Add += 1; - if(Flags & AB3_NUMVAL_ADD_256) - Add += 256; - switch(Flags & AB3_NUMVAL_SIZEMASK) { + if(flags & AB3_NUMVAL_ADD_1) + add += 1; + if(flags & AB3_NUMVAL_ADD_256) + add += 256; + switch(flags & AB3_NUMVAL_SIZEMASK) { case AB3_NUMVAL__SIZE_0:// no bytes follow (0, 1, 256, 257) - Value = Add; + value = add; break; case AB3_NUMVAL__SIZE_1:// one byte follows (2 to 511) - Value = Add + GetByte(); + value = add + IO_get_byte(); break; case AB3_NUMVAL__SIZE_2:// two bytes follow (512 to 65535) - Value = Add + GetLE16(); + value = add + IO_get_le16(); break; default: // unknown number compression // remember to generate error - ErrBits |= AB_ERRBIT_UNKNOWN_NUMBER_COMPRESSION; + err_bits |= AB_ERRBIT_UNKNOWN_NUMBER_COMPRESSION; } // continue parsing on next byte - GetByte(); + IO_get_byte(); // decode output format - switch(Flags & AB3_NUMVAL_FORMATMASK) { + switch(flags & AB3_NUMVAL_FORMATMASK) { case AB3_NUMVAL__FORMAT_BIN: - PutByte('%'); - ab_output_binary(Value); + IO_put_byte('%'); + AB_output_binary(value); break; case AB3_NUMVAL__FORMAT_DEC: - fprintf(global_output_stream, "%lu", Value); + fprintf(global_output_stream, "%lu", value); break; case AB3_NUMVAL__FORMAT_HEX: -hex_fallback: PutByte('$'); - ab_output_hexadecimal(Value); +hex_fallback: IO_put_byte('$'); + AB_output_hexadecimal(value); break; default: // unknown output format // remember to warn - ErrBits |= AB_ERRBIT_UNKNOWN_NUMBER_FORMAT; + err_bits |= AB_ERRBIT_UNKNOWN_NUMBER_FORMAT; goto hex_fallback; } - return(ErrBits); + return(err_bits); } // config struct for shared ab code struct ab_t ab3_conf = { - ab3_parse_number, - ab3_pseudo_opcodes, - ab3_mnemonics, - 12, // number of addressing modes - // meaning of input bytes (0x80-0xec differ between AB 3.x and F8-AB) - // 0x80 unused, then 56 legals + 15 illegals = 71 - 0xc8, // first pseudo opcode - 0xd5, // first unused byte value - // 0xd5-0xfe are unused in AB 3.x + parse_number, + pseudo_opcode_table, + mnemonic_table, + AB3_ADDRESSING_MODES, + // meaning of input bytes (0x80-0xec differ between AB3 and F8AB) + AB3_FIRST_PSEUDO_OPCODE, + AB3_FIRST_UNUSED_CODE, }; // main -// void ab3_main(void) { - input_set_padding(AB_ENDOFLINE); - PutString( + IO_set_input_padding(AB_ENDOFLINE); + IO_put_string( "; ToACME: Adding pseudo opcode to enable undocumented (\"illegal\") opcodes:\n" -"!cpu 6510\n" +"\t!cpu 6510\n" +"; ToACME: AssBlaster's support for illegal opcodes is somewhat broken.\n" +"; ToACME: Make sure you read the ToACME docs to know what you'll have to\n" +"; ToACME: look out for.\n" +"; ToACME: Should work: DCP, DOP, ISC, JAM (was called KIL in AssBlaster),\n" +"; ToACME: RLA, RRA, SBX (was called AXS in AssBlaster), SLO, SRE, TOP.\n" +"; ToACME: Trouble: ARR, ASR, LAX, SAX (was called AAX in AssBlaster).\n" ); - io_process_load_address(); + IO_process_load_address(); // first byte after load address should be AB_ENDOFLINE in AB3 sources - if(GetByte() == AB_ENDOFLINE) { - GetByte(); // skip it and pre-read first valid byte + if(IO_get_byte() == AB_ENDOFLINE) { + IO_get_byte(); // skip it and pre-read first valid byte fputs("Input has AB3 header.\n", stderr); } else fputs("Input does not have any known AB3 header.\n", stderr); - ab_main(&ab3_conf); + AB_main(&ab3_conf); } diff --git a/contrib/toacme/src/acme.c b/contrib/toacme/src/acme.c index 61f5afd..566dc37 100644 --- a/contrib/toacme/src/acme.c +++ b/contrib/toacme/src/acme.c @@ -1,53 +1,45 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // ACME syntax -// -// Includes -// #include "acme.h" #include "io.h" // Constants -// // Pseudo opcodes -const char PseudoOp_Byte[] = "!byte"; -const char PseudoOp_Else[] = "} else {"; -const char PseudoOp_EndIf[] = "}; (end of conditional assembly)\n"; -const char PseudoOp_EndMacroDef[] = "}; (end of macro definition)\n"; -const char PseudoOp_EOF[] = "!eof"; -const char PseudoOp_Fill[] = "!fill"; -const char PseudoOp_If[] = "!if"; -const char PseudoOp_LabelDump[] = "!sl"; -const char PseudoOp_MacroCall[] = "+"; -const char PseudoOp_MacroDef[] = "!macro"; -const char PseudoOp_PetTxt[] = "!pet"; -const char PseudoOp_ScrTxt[] = "!scr"; -const char PseudoOp_SetPC[] = "*="; -const char PseudoOp_Source[] = "!src"; -const char PseudoOp_ToFile[] = "!to"; -const char PseudoTrail_ToFile[] = ", cbm"; -const char PseudoOp_Word[] = "!word"; -// Pseudo opcodes for 65816 (used by F8-AssBlaster) -const char PseudoOp_al[] = "!al"; -const char PseudoOp_as[] = "!as"; -const char PseudoOp_rl[] = "!rl"; -const char PseudoOp_rs[] = "!rs"; +const char ACME_po_to[] = "!to"; +const char ACME_cbmformat[] = ", cbm"; +const char ACME_po_sl[] = "!sl"; +const char ACME_set_pc[] = "*="; +const char ACME_po_source[] = "!src"; +const char ACME_po_byte[] = "!byte"; +const char ACME_po_word[] = "!word"; +const char ACME_po_fill[] = "!fill"; +const char ACME_po_pet[] = "!pet"; +const char ACME_po_scr[] = "!scr"; +const char ACME_po_macro[] = "!macro"; +const char ACME_endmacro[] = "}; (end of macro definition)\n"; +const char ACME_macro_call[] = "+"; +const char ACME_po_if[] = "!if"; +const char ACME_else[] = "} else {"; +const char ACME_endif[] = "}; (end of conditional assembly)\n"; +const char ACME_po_eof[] = "!eof"; +// Pseudo opcodes for 65816 (used by Flash8-AssBlaster) +const char ACME_po_al[] = "!al"; +const char ACME_po_as[] = "!as"; +const char ACME_po_rl[] = "!rl"; +const char ACME_po_rs[] = "!rs"; // Functions -// - // Output pseudo opcode to make ACME use PetSCII encoding -// -void acme_SwitchToPet(void) { - - PutString( +void ACME_switch_to_pet(void) { + IO_put_string( "; ToACME: Adding pseudo opcode to use PetSCII encoding by default:\n" "!convtab pet\n" ); diff --git a/contrib/toacme/src/acme.h b/contrib/toacme/src/acme.h index 2ce83b0..66c319b 100644 --- a/contrib/toacme/src/acme.h +++ b/contrib/toacme/src/acme.h @@ -1,44 +1,41 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // ACME syntax -// #ifndef acme_H #define acme_H // Constants -// -// pseudo opcodes -extern const char PseudoOp_Byte[]; -extern const char PseudoOp_Else[]; -extern const char PseudoOp_EndIf[]; -extern const char PseudoOp_EndMacroDef[]; -extern const char PseudoOp_EOF[]; -extern const char PseudoOp_Fill[]; -extern const char PseudoOp_If[]; -extern const char PseudoOp_LabelDump[]; -extern const char PseudoOp_MacroCall[]; -extern const char PseudoOp_MacroDef[]; -extern const char PseudoOp_PetTxt[]; -extern const char PseudoOp_ScrTxt[]; -extern const char PseudoOp_SetPC[]; -extern const char PseudoOp_Source[]; -extern const char PseudoOp_ToFile[]; -extern const char PseudoTrail_ToFile[]; -extern const char PseudoOp_Word[]; +// pseudo opcodes and related keywords +extern const char ACME_po_to[]; +extern const char ACME_cbmformat[]; +extern const char ACME_po_sl[]; +extern const char ACME_set_pc[]; +extern const char ACME_po_source[]; +extern const char ACME_po_byte[]; +extern const char ACME_po_word[]; +extern const char ACME_po_fill[]; +extern const char ACME_po_pet[]; +extern const char ACME_po_scr[]; +extern const char ACME_po_macro[]; +extern const char ACME_endmacro[]; +extern const char ACME_macro_call[]; +extern const char ACME_po_if[]; +extern const char ACME_else[]; +extern const char ACME_endif[]; +extern const char ACME_po_eof[]; // pseudo opcodes for 65816 cpu -extern const char PseudoOp_al[]; -extern const char PseudoOp_as[]; -extern const char PseudoOp_rl[]; -extern const char PseudoOp_rs[]; +extern const char ACME_po_al[]; +extern const char ACME_po_as[]; +extern const char ACME_po_rl[]; +extern const char ACME_po_rs[]; // Prototypes -// -extern void acme_SwitchToPet(void); +extern void ACME_switch_to_pet(void); #endif diff --git a/contrib/toacme/src/config.h b/contrib/toacme/src/config.h index 239ac95..abf9e8c 100644 --- a/contrib/toacme/src/config.h +++ b/contrib/toacme/src/config.h @@ -1,21 +1,21 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // Configurable stuff // ...this file gets included by almost all others, even *.h files -// #ifndef config_H #define config_H // Constants -// +#define SPACE 0x20 +#define SHIFTSPACE 0xa0 + #ifndef FALSE typedef int bool; #define FALSE 0 #define TRUE 1 #endif - #endif diff --git a/contrib/toacme/src/f8ab.c b/contrib/toacme/src/f8ab.c index 09bee84..35fa6b0 100644 --- a/contrib/toacme/src/f8ab.c +++ b/contrib/toacme/src/f8ab.c @@ -1,13 +1,9 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // -// F8-AssBlaster stuff -// +// Flash8-AssBlaster stuff - -// Includes -// #include <stdlib.h> #include <stdio.h> #include "config.h" @@ -19,10 +15,11 @@ // Constants -// -// Mnemonic table in F8-AssBlaster order (without: MnemonicJML, MnemonicWDM) -const char* f8ab_mnemonics[] = { +#define F8AB_ADDRESSING_MODES 23 // (FIXME - check back later!) + +// Mnemonic table in Flash8-AssBlaster order (without: JML, WDM) +static const char* mnemonic_table[] = { MnemonicADC, // $80 6502 MnemonicAND, // $81 6502 MnemonicASL, // $82 6502 @@ -46,16 +43,16 @@ const char* f8ab_mnemonics[] = { MnemonicCOP, // $94 65816 MnemonicCPX, // $95 6502 MnemonicCPY, // $96 6502 - MnemonicDEC, // $97 F8AB uses DEA as the 65816's "DEC-implicit" + MnemonicDEC, // $97 F8AB uses DEA as the 65816's "DEC implied" MnemonicDEC, // $98 6502 MnemonicDEX, // $99 6502 MnemonicDEY, // $9a 6502 MnemonicEOR, // $9b 6502 - MnemonicINC, // $9c F8AB uses INA as the 65816's "INC-implicit" + MnemonicINC, // $9c F8AB uses INA as the 65816's "INC implied" MnemonicINC, // $9d 6502 MnemonicINX, // $9e 6502 - // seems as if F8AB does not know MnemonicJML (65816)... MnemonicINY, // $9f 6502 + // MnemonicJML (65816) seems to be unknown to F8AB ... MnemonicJMP, // $a0 6502 MnemonicJSL, // $a1 65816 ...but it *does* know JSL? Strange. MnemonicJSR, // $a2 6502 @@ -114,38 +111,41 @@ const char* f8ab_mnemonics[] = { MnemonicTYA, // $d7 6502 MnemonicTYX, // $d8 65816 MnemonicWAI, // $d9 65816 - // seems as if F8AB does not know MnemonicWDM (65816) + // MnemonicWDM (65816) seems to be unknown to F8AB. MnemonicXBA, // $da 65816 MnemonicXCE, // $db 65816 }; -// PseudoOpcode table in F8-AssBlaster order -const char* f8ab_pseudo_opcodes[] = { +// PseudoOpcode table in Flash8-AssBlaster order +static const char* pseudo_opcode_table[] = { +#define F8AB_FIRST_PSEUDO_OPCODE 0xdc NULL, // (la) $dc // NULL because ACME does not need a pseudo opcode for label defs - PseudoOp_SetPC, // (ba) $dd - PseudoOp_Byte, // (by) $de - PseudoOp_Fill, // (br) $df - PseudoOp_PetTxt, // (tx) $e0 - PseudoOp_MacroDef, // (md) $e1 (see AB_PSEUDOOFFSET_MACRODEF) - PseudoOp_EndMacroDef, // (de) $e2 - PseudoOp_MacroCall, // (ma) $e3 (see AB_PSEUDOOFFSET_MACROCALL) - PseudoOp_EOF, // (st) $e4 -// PseudoOp_ScrTxt is not available in F8AB. Huh?! + ACME_set_pc, // (ba) $dd + ACME_po_byte, // (by) $de + ACME_po_fill, // (br) $df + ACME_po_pet, // (tx) $e0 + ACME_po_macro, // (md) $e1 (see AB_PSEUDOOFFSET_MACRODEF) + ACME_endmacro, // (de) $e2 + ACME_macro_call, // (ma) $e3 (see AB_PSEUDOOFFSET_MACROCALL) + ACME_po_eof, // (st) $e4 +// ACME_po_scr is not available in F8AB. Huh?! "; ToACME: Cannot convert \\wa.\n", // (wa) $e5 - PseudoOp_ToFile, // (on) $e6 (see AB_PSEUDOOFFSET_OUTFILE) - PseudoOp_Word, // (wo) $e7 + ACME_po_to, // (on) $e6 (see AB_PSEUDOOFFSET_OUTFILE) + ACME_po_word, // (wo) $e7 "; ToACME: Cannot convert \\kc.\n", // (kc) $e8 - PseudoOp_rl, // (rl) $e9 - PseudoOp_rs, // (rs) $ea - PseudoOp_al, // (al) $eb - PseudoOp_as, // (as) $ec + ACME_po_rl, // (rl) $e9 + ACME_po_rs, // (rs) $ea + ACME_po_al, // (al) $eb + ACME_po_as, // (as) $ec +#define F8AB_FIRST_UNUSED_CODE 0xed + // 0xed-0xfe are unused in F8AB + // (FIXME - true? I only checked 0xed) }; // Parse AssBlaster's packed number format. Returns error bits. -// //#define AB_NUMVAL_FLAGBIT 0x80 // 10000000 indicates packed number #define F8AB_NUMVAL_ADD_65536 0x40 // 01000000 #define F8AB_NUMVAL_ADD_256 0x20 // 00100000 @@ -160,111 +160,110 @@ const char* f8ab_pseudo_opcodes[] = { #define F8AB_NUMVAL__SIZE_1 0x01 // 00000001 #define F8AB_NUMVAL__SIZE_2 0x02 // 00000010 #define F8AB_NUMVAL__SIZE_3 0x03 // 00000011 -int f8ab_parse_number(void) { // now GotByte = first byte of packed number - int Flags = GotByte, - ErrBits = 0; - unsigned long int Value = 0, - Add = 0; +static int parse_number(void) { // now GotByte = first byte of packed number + int flags = GotByte, + err_bits = 0; + unsigned long int value = 0, + add = 0; // decode value - if(Flags & F8AB_NUMVAL_ADD_65536) - Add += 65536; - if(Flags & F8AB_NUMVAL_ADD_256) - Add += 256; - if(Flags & F8AB_NUMVAL_ADD_1) - Add += 1; - switch(Flags & F8AB_NUMVAL_SIZEMASK) { + if(flags & F8AB_NUMVAL_ADD_65536) + add += 65536; + if(flags & F8AB_NUMVAL_ADD_256) + add += 256; + if(flags & F8AB_NUMVAL_ADD_1) + add += 1; + switch(flags & F8AB_NUMVAL_SIZEMASK) { case F8AB_NUMVAL__SIZE_0:// no bytes follow (0, 1, 256, 257) - Value = Add; + value = add; break; case F8AB_NUMVAL__SIZE_1:// one byte follows (2 to 511) - Value = Add + GetByte(); + value = add + IO_get_byte(); break; case F8AB_NUMVAL__SIZE_2:// two bytes follow (512 to 65535) - Value = Add + GetLE16(); + value = add + IO_get_le16(); break; case F8AB_NUMVAL__SIZE_3:// three bytes follow (anything else) - Value = Add + GetByte() + (GetLE16() << 8); + value = add + IO_get_le24(); } // continue parsing on next byte - GetByte(); + IO_get_byte(); // decode output format - switch(Flags & F8AB_NUMVAL_FORMATMASK) { + switch(flags & F8AB_NUMVAL_FORMATMASK) { case F8AB_NUMVAL__FORMAT_BIN: - PutByte('%'); - ab_output_binary(Value); + IO_put_byte('%'); + AB_output_binary(value); break; case F8AB_NUMVAL__FORMAT_DEC: - fprintf(global_output_stream, "%lu", Value); + fprintf(global_output_stream, "%lu", value); break; case F8AB_NUMVAL__FORMAT_HEX: -hex_fallback: PutByte('$'); - ab_output_hexadecimal(Value); +hex_fallback: IO_put_byte('$'); + AB_output_hexadecimal(value); break; default: // unknown output format // remember to warn - ErrBits |= AB_ERRBIT_UNKNOWN_NUMBER_FORMAT; + err_bits |= AB_ERRBIT_UNKNOWN_NUMBER_FORMAT; goto hex_fallback; } - return(ErrBits); + return(err_bits); } // config struct for shared ab code struct ab_t f8ab_conf = { - f8ab_parse_number, - f8ab_pseudo_opcodes, - f8ab_mnemonics, - 23, // number of addressing modes (FIXME - check back later!) - // meaning of input bytes (0x80-0xec differ between AB 3.x and F8-AB) - // 0x80: mnemos (56 6502 + 8 65c02 + 26 65816 + jml/jsl = 92) - 0xdc, // first pseudo opcode - 0xed, // first unused byte value - // 0xed-0xfe are unused in F8-AB (FIXME - true? I only checked 0xed) + parse_number, + pseudo_opcode_table, + mnemonic_table, + F8AB_ADDRESSING_MODES, + // meaning of input bytes (0x80-0xec differ between AB3 and F8AB) + F8AB_FIRST_PSEUDO_OPCODE, + F8AB_FIRST_UNUSED_CODE, }; // main -// void f8ab_main(void) { const char* header_message; header_message = "Input does not have any known F8AB header.\n"; - input_set_padding(AB_ENDOFLINE); - PutString( + IO_set_input_padding(AB_ENDOFLINE); + IO_put_string( "; ToACME: Adding pseudo opcode to enable 65816 opcodes:\n" -"!cpu 65816\n" +"\t!cpu 65816\n" "; ToACME: Adding two macros to fix F8AB's non-standard argument order\n" "; ToACME: concerning MVP/MVN. While the commands are assembled with\n" "; ToACME: the destination bank byte first, the WDC docs say that in\n" "; ToACME: source codes, the source bank byte is given first.\n" -"!macro F8AB_BROKEN_MVP .dest,.source {mvp .source,.dest}\n" -"!macro F8AB_BROKEN_MVN .dest,.source {mvn .source,.dest}\n" +"; ToACME: In other words: The macros make sure that assembling this\n" +"; ToACME: source with ACME will produce the same binary F8AB produced.\n" +"\t!macro F8AB_BROKEN_MVP .dest, .source {mvp .source, .dest}\n" +"\t!macro F8AB_BROKEN_MVN .dest, .source {mvn .source, .dest}\n" ); - io_process_load_address(); + IO_process_load_address(); // most AB files have this format: // load_address_low, load_address_high, AB_ENDOFLINE, actual content // newer versions of F8AB seem to use this: // $ff, $00, $00, $03, AB_ENDOFLINE, actual content - if(GetByte() == AB_ENDOFLINE) { - GetByte(); // skip it and pre-read first valid byte + if(IO_get_byte() == AB_ENDOFLINE) { + IO_get_byte(); // skip it and pre-read first valid byte header_message = "Input has F8AB 1.0 header.\n"; } else { if((GotByte == 0) - && (GetByte() == 3) - && (GetByte() == AB_ENDOFLINE)) { - GetByte();// skip and pre-read first valid byte + && (IO_get_byte() == 3) + && (IO_get_byte() == AB_ENDOFLINE)) { + IO_get_byte();// skip and pre-read first valid byte header_message = "Input has F8AB 1.2 header.\n"; } } fputs(header_message, stderr); - ab_main(&f8ab_conf); + AB_main(&f8ab_conf); } diff --git a/contrib/toacme/src/giga.c b/contrib/toacme/src/giga.c index 070809b..2714e92 100644 --- a/contrib/toacme/src/giga.c +++ b/contrib/toacme/src/giga.c @@ -1,13 +1,9 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2005 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // "GigaAss" stuff -// - -// Includes -// #include <stdio.h> #include "config.h" #include "acme.h" @@ -18,34 +14,30 @@ // Constants -// // token-to-(pseudo)opcode conversion table (FIXME) const char* giga_token[] = { "FIXME-CALL", // $a0 .CALL - PseudoOp_MacroDef, // $a1 .MACRO (see MACRO_DEF_TOKEN below) - PseudoOp_EndMacroDef, // $a2 .ENDMACRO + ACME_po_macro, // $a1 .MACRO (see MACRO_DEF_TOKEN below) + ACME_endmacro, // $a2 .ENDMACRO NULL, // $a3 .GLOBAL (ACME does not need a pseudo NULL, // $a4 .EQUATE opcode for label definitions) - // bis hier wird nicht einger�ckt - // ab hier wird einger�ckt - PseudoOp_Byte, // $a5 .BYTE - PseudoOp_Word, // $a6 .WORD - PseudoOp_Fill, // $a7 .DS - PseudoOp_PetTxt, // $a8 .TEXT (see MACRO_TEXT below) - // bis hier wird einger�ckt - // ab hier wird nicht einger�ckt - PseudoOp_ToFile, // $a9 .OBJECT (see MACRO_OUTFILE below) - PseudoOp_SetPC, // $aa .BASE + // these are indented in the output file + ACME_po_byte, // $a5 .BYTE + ACME_po_word, // $a6 .WORD + ACME_po_fill, // $a7 .DS + ACME_po_pet, // $a8 .TEXT (see MACRO_TEXT below) + ACME_po_to, // $a9 .OBJECT (see MACRO_OUTFILE below) + ACME_set_pc, // $aa .BASE "FIXME-CODE", // $ab .CODE "FIXME-ON", // $ac .ON "FIXME-GOTO", // $ad .GOTO - PseudoOp_If, // $ae .IF - PseudoOp_Else, // $af .ELSE - PseudoOp_EndIf, // $b0 .ENDIF - PseudoOp_LabelDump, // $b1 .SYMBOLS + ACME_po_if, // $ae .IF + ACME_else, // $af .ELSE + ACME_endif, // $b0 .ENDIF + ACME_po_sl, // $b1 .SYMBOLS "FIXME-LISTING", // $b2 .LISTING - PseudoOp_EOF, // $b3 .END + ACME_po_eof, // $b3 .END "FIXME-STOP", // $b4 .STOP "FIXME-PAGE", // $b5 .PAGE "FIXME-NOCODE", // $b6 .NOCODE @@ -58,66 +50,63 @@ const char* giga_token[] = { "FIXME-$bd", // $bd "FIXME-$be", // $be "FIXME-$bf", // $bf - // bis hier wird nicht einger�ckt - // ab hier wird einger�ckt - MnemonicCPX, // $c0 - MnemonicCPY, // $c1 - MnemonicLDX, // $c2 - MnemonicLDY, // $c3 - MnemonicCMP, // $c4 - MnemonicADC, // $c5 - MnemonicAND, // $c6 - MnemonicDEC, // $c7 - MnemonicEOR, // $c8 - MnemonicINC, // $c9 - MnemonicLDA, // $ca - MnemonicASL, // $cb - MnemonicBIT, // $cc - MnemonicLSR, // $cd - MnemonicORA, // $ce - MnemonicROL, // $cf - MnemonicROR, // $d0 - MnemonicSBC, // $d1 - MnemonicSTA, // $d2 - MnemonicSTX, // $d3 - MnemonicSTY, // $d4 - MnemonicJMP, // $d5 - MnemonicJSR, // $d6 - MnemonicTXA, // $d7 - MnemonicTAX, // $d8 - MnemonicTYA, // $d9 - MnemonicTAY, // $da - MnemonicTSX, // $db - MnemonicTXS, // $dc - MnemonicPHP, // $dd - MnemonicPLP, // $de - MnemonicPHA, // $df - MnemonicPLA, // $e0 - MnemonicBRK, // $e1 - MnemonicRTI, // $e2 - MnemonicRTS, // $e3 - MnemonicNOP, // $e4 - MnemonicCLC, // $e5 - MnemonicSEC, // $e6 - MnemonicCLI, // $e7 - MnemonicSEI, // $e8 - MnemonicCLV, // $e9 - MnemonicCLD, // $ea - MnemonicSED, // $eb - MnemonicDEY, // $ec - MnemonicINY, // $ed - MnemonicDEX, // $ee - MnemonicINX, // $ef - MnemonicBPL, // $f0 - MnemonicBMI, // $f1 - MnemonicBVC, // $f2 - MnemonicBVS, // $f3 - MnemonicBCC, // $f4 - MnemonicBCS, // $f5 - MnemonicBNE, // $f6 - MnemonicBEQ, // $f7 - // bis hier wird einger�ckt - // ab hier wird nicht einger�ckt + // these are indented in the output file + MnemonicCPX, // $c0 + MnemonicCPY, // $c1 + MnemonicLDX, // $c2 + MnemonicLDY, // $c3 + MnemonicCMP, // $c4 + MnemonicADC, // $c5 + MnemonicAND, // $c6 + MnemonicDEC, // $c7 + MnemonicEOR, // $c8 + MnemonicINC, // $c9 + MnemonicLDA, // $ca + MnemonicASL, // $cb + MnemonicBIT, // $cc + MnemonicLSR, // $cd + MnemonicORA, // $ce + MnemonicROL, // $cf + MnemonicROR, // $d0 + MnemonicSBC, // $d1 + MnemonicSTA, // $d2 + MnemonicSTX, // $d3 + MnemonicSTY, // $d4 + MnemonicJMP, // $d5 + MnemonicJSR, // $d6 + MnemonicTXA, // $d7 + MnemonicTAX, // $d8 + MnemonicTYA, // $d9 + MnemonicTAY, // $da + MnemonicTSX, // $db + MnemonicTXS, // $dc + MnemonicPHP, // $dd + MnemonicPLP, // $de + MnemonicPHA, // $df + MnemonicPLA, // $e0 + MnemonicBRK, // $e1 + MnemonicRTI, // $e2 + MnemonicRTS, // $e3 + MnemonicNOP, // $e4 + MnemonicCLC, // $e5 + MnemonicSEC, // $e6 + MnemonicCLI, // $e7 + MnemonicSEI, // $e8 + MnemonicCLV, // $e9 + MnemonicCLD, // $ea + MnemonicSED, // $eb + MnemonicDEY, // $ec + MnemonicINY, // $ed + MnemonicDEX, // $ee + MnemonicINX, // $ef + MnemonicBPL, // $f0 + MnemonicBMI, // $f1 + MnemonicBVC, // $f2 + MnemonicBVS, // $f3 + MnemonicBCC, // $f4 + MnemonicBCS, // $f5 + MnemonicBNE, // $f6 + MnemonicBEQ, // $f7 "FIXME-$f8", // $f8 "FIXME-$f9", // $f9 "FIXME-$fa", // $fa @@ -130,8 +119,6 @@ const char* giga_token[] = { // Functions -// - // I don't know whether it's correct, but I had to start somewhere #define FIRST_TOKEN 0xa0 @@ -139,14 +126,13 @@ const char* giga_token[] = { #define MACRO_TEXT 0xa8 // ugly kluge for giga string specialties #define MACRO_OUTFILE 0xa9 // ugly kluge for adding outfile format // Process opcode or pseudo opcode (tokenized) -// -int giga_Tokenized(void) { +static int process_tokenized(void) { const char* token; int flags = 0; if(GotByte < FIRST_TOKEN) { // macro call? - PutByte('+'); // add macro call character + IO_put_byte('+'); // add macro call character // fprintf(global_output_stream, "small value:$%x", GotByte); } else { switch(GotByte) { @@ -166,8 +152,8 @@ int giga_Tokenized(void) { flags |= FLAG_INSERT_SPACE; token = giga_token[GotByte - FIRST_TOKEN]; if(token != NULL) - PutString(token); - GetByte(); + IO_put_string(token); + IO_get_byte(); } return(flags); } @@ -177,43 +163,37 @@ int giga_Tokenized(void) { // [...] // Main routine for GigaAss conversion -// void giga_main(void) { int indent; - input_set_padding(0); - io_process_load_address(); - acme_SwitchToPet(); + IO_set_input_padding(0); + IO_process_load_address(); + ACME_switch_to_pet(); // loop: once for every line in the file - while(!ReachedEOF) { + while(!IO_reached_eof) { // skip link pointer (if it's zero, report as end marker) - if(GetLE16() == 0) - PutString("; ToACME: Found BASIC end marker.\n"); - - GetLE16(); // skip line number - + if(IO_get_le16() == 0) + IO_put_string("; ToACME: Found BASIC end marker.\n"); + IO_get_le16(); // skip line number // process line - GetByte(); - if((GotByte == ' ') || (GotByte == ';') || (GotByte == '\0') || (GotByte > 0x7f)) + IO_get_byte(); + if((GotByte == SPACE) || (GotByte == ';') + || (GotByte == '\0') || (GotByte > 0x7f)) indent = 0; else - indent = gigahypra_LabelDef(); - + indent = GigaHypra_label_definition(); // skip spaces - while(GotByte == ' ') - GetByte(); - + while(GotByte == SPACE) + IO_get_byte(); // if there is an opcode, process it if((GotByte != ';') && (GotByte != '\0')) { - gigahypra_Indent(indent); - gigahypra_Opcode(giga_Tokenized()); + GigaHypra_indent(indent); + GigaHypra_argument(process_tokenized()); } - // skip comment, if there is one if(GotByte == ';') - gigahypra_ConvComment(); - + GigaHypra_comment(); // end of line - PutByte('\n'); + IO_put_byte('\n'); } } diff --git a/contrib/toacme/src/gighyp.c b/contrib/toacme/src/gighyp.c index edf2709..d956f67 100644 --- a/contrib/toacme/src/gighyp.c +++ b/contrib/toacme/src/gighyp.c @@ -1,119 +1,110 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2005 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // stuff needed for both "Hypra-Ass" and "Giga-Ass" -// - -// Includes -// #include "acme.h" #include "gighyp.h" #include "io.h" #include "pet2iso.h" -// Process comment (GotByte == ';') -// -void gigahypra_ConvComment(void) { - +// called with GotByte == ';' +void GigaHypra_comment(void) { // check whether anything follows (empty comments => empty lines) - if(GetByte()) { - PutByte(';'); + if(IO_get_byte()) { + IO_put_byte(';'); do - PutByte(PET2ISO(GotByte)); - while(GetByte()); + IO_put_byte(PET2ISO(GotByte)); + while(IO_get_byte()); } } // Process operator -// -void gigahypra_Operator(void) {// '!' was last read - char Middle; +void GigaHypra_operator(void) {// '!' was last read + char middle = PET2ISO(IO_get_byte()); - Middle = PET2ISO(GetByte()); - if((Middle != ';') && (Middle != 0)) { - if(GetByte() == '!') { - switch(Middle) { + if((middle != ';') && (middle != '\0')) { + if(IO_get_byte() == '!') { + switch(middle) { case 'n': - PutByte('!'); + IO_put_byte('!'); break; case 'o': - PutByte('|'); + IO_put_byte('|'); break; case 'a': - PutByte('&'); + IO_put_byte('&'); break; case '=': - PutByte('='); + IO_put_byte('='); break; case '<': - PutString(" < "); + IO_put_string(" < "); break; case '>': - PutString(" > "); + IO_put_string(" > "); break; default: - PutByte('!'); - PutByte(Middle); - PutByte('!'); + IO_put_byte('!'); + IO_put_byte(middle); + IO_put_byte('!'); } - GetByte(); + IO_get_byte(); } else { - PutByte('!'); - PutByte(Middle); + IO_put_byte('!'); + IO_put_byte(middle); } } else - PutByte('!'); + IO_put_byte('!'); // exit with unused byte pre-read } // output one or two TABs -// -void gigahypra_Indent(int indent) { +void GigaHypra_indent(int indent) { if(indent < 8) - PutByte('\t'); - PutByte('\t'); + IO_put_byte('\t'); + IO_put_byte('\t'); } // Process opcode and arguments -// -void gigahypra_Opcode(int flags) { +void GigaHypra_argument(int flags) { int paren = 0; // number of open parentheses (to close) // if needed, add separating space between opcode and argument - if((flags & FLAG_INSERT_SPACE) && (GotByte != ' ') && (GotByte != ';') && (GotByte != '\0')) - PutByte(' '); + if((flags & FLAG_INSERT_SPACE) && (GotByte != SPACE) + && (GotByte != ';') && (GotByte != '\0')) + IO_put_byte(SPACE); // character loop while((GotByte != ';') && (GotByte != '\0')) { if(GotByte == '!') - gigahypra_Operator(); + GigaHypra_operator(); if(GotByte == '"') { // don't parse inside quotes - PutByte(GotByte); - GetByte(); + IO_put_byte(GotByte); + IO_get_byte(); while((GotByte != '\0') && (GotByte != '"')) { if((GotByte == 0x5f) && (flags & FLAG_CHANGE_LEFTARROW)) - PutString("\", 13,\""); + IO_put_string("\", 13,\""); else - PutByte(PET2ISO(GotByte)); - GetByte(); + IO_put_byte(PET2ISO(GotByte)); + IO_get_byte(); } - PutByte('"'); + IO_put_byte('"'); if(GotByte == '"') { - GetByte(); + IO_get_byte(); if((GotByte == '\0') && (flags & FLAG_ADD_ZERO)) - PutString(", 0"); + IO_put_string(", 0"); } } else { // most characters go here @@ -125,7 +116,7 @@ void gigahypra_Opcode(int flags) { flags |= FLAG_SKIP_CLOSING; } else { paren++; - PutByte(PET2ISO(GotByte)); + IO_put_byte(PET2ISO(GotByte)); } break; @@ -134,37 +125,36 @@ void gigahypra_Opcode(int flags) { flags &= ~FLAG_SKIP_CLOSING; else { paren--; - PutByte(PET2ISO(GotByte)); + IO_put_byte(PET2ISO(GotByte)); } break; - case '�': // shift-space - PutByte(' '); // space + case SHIFTSPACE: + IO_put_byte(SPACE); break; default: - PutByte(PET2ISO(GotByte)); + IO_put_byte(PET2ISO(GotByte)); } - GetByte(); + IO_get_byte(); } } if(flags & FLAG_ADD_CBM) - PutString(PseudoTrail_ToFile); + IO_put_string(ACME_cbmformat); if(flags & FLAG_ADD_LEFT_BRACE) - PutByte('{'); + IO_put_byte('{'); } // Convert and send label name. // Returns length (for proper indentation). -// -int gigahypra_LabelDef(void) { +int GigaHypra_label_definition(void) { int count = 0; do { - PutByte(PET2ISO(GotByte)); + IO_put_byte(PET2ISO(GotByte)); count++; - GetByte(); - } while((GotByte != ' ') && (GotByte != ';') && (GotByte != 0)); + IO_get_byte(); + } while((GotByte != SPACE) && (GotByte != ';') && (GotByte != '\0')); return(count); } diff --git a/contrib/toacme/src/gighyp.h b/contrib/toacme/src/gighyp.h index 7cda911..1c3ba2a 100644 --- a/contrib/toacme/src/gighyp.h +++ b/contrib/toacme/src/gighyp.h @@ -1,20 +1,15 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // stuff needed for both "Hypra-Ass" and "Giga-Ass" -// #ifndef gigahypra_H #define gigahypra_H - -// Includes -// #include "config.h" // Constants -// #define FLAG_INSERT_SPACE (1u << 0) // insert space before arg #define FLAG_ADD_LEFT_BRACE (1u << 1) // add '{' at end of statement #define FLAG_ADD_CBM (1u << 2) // add file format indicator @@ -27,12 +22,11 @@ // Prototypes -// -extern void gigahypra_ConvComment(void); -extern void gigahypra_Operator(void); -extern void gigahypra_Indent(int indent); -extern void gigahypra_Opcode(int flags); -extern int gigahypra_LabelDef(void); +extern void GigaHypra_comment(void); +extern void GigaHypra_operator(void); +extern void GigaHypra_indent(int indent); +extern void GigaHypra_argument(int flags); +extern int GigaHypra_label_definition(void); #endif diff --git a/contrib/toacme/src/hypra.c b/contrib/toacme/src/hypra.c index acf3ed5..b1dc02e 100644 --- a/contrib/toacme/src/hypra.c +++ b/contrib/toacme/src/hypra.c @@ -1,13 +1,9 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // "HypraAss" stuff -// - -// Includes -// #include <stdio.h> #include "config.h" #include "acme.h" @@ -17,214 +13,204 @@ // Functions -// +// complain about unknown pseudo opcodes +static void complain(char a, char b) { + IO_put_string("; ToACME: ."); + if(a) + IO_put_byte(a); + if(b) + IO_put_byte(b); + IO_put_string(" cannot be converted\n"); +} -// Process pseudo opcode -// -int hypra_PseudoOpcode(void) {// '.' was last read - int a, - b = '\0', - flags = FLAG_INSERT_SPACE; - bool fBlah = TRUE; +// handle ".ba" and ".by" +static int process_po_b(char second) { + int flags = 0; - a = PET2ISO(GetByte()); - if((a != ' ') && (a != ';') && (a != '\0')) { - b = PET2ISO(GetByte()); - if((b != ' ') && (b != ';') && (b != '\0')) { - switch(a) { + switch(second) { - case '.': - if(b == '.') { // "..." = macro call - fBlah = FALSE; - PutString(PseudoOp_MacroCall); - flags |= FLAG_SKIP_OPENING; - } - break; + case 'a': // ".ba" = set base address + IO_put_string(ACME_set_pc); + break; - case 'a': - if(b == 'p') { // ".ap" = append source file - fBlah = FALSE; - PutString(PseudoOp_Source); - } - break; + case 'y': // ".by" = insert bytes + IO_put_string(ACME_po_byte); + flags |= FLAG_INSERT_SPACE; + break; - case 'b': - if(b == 'a') { // ".ba" = set base address - fBlah = FALSE; - PutString(PseudoOp_SetPC); - } - if(b == 'y') { // ".by" = insert bytes - fBlah = FALSE; - PutString(PseudoOp_Byte); - } - break; + default: + complain('b', second); - case 'e': - switch(b) { - - case 'i': // ".ei" = endif - fBlah = FALSE; - PutString(PseudoOp_EndIf); - break; - - case 'l': // ".el" = else - fBlah = FALSE; - PutString(PseudoOp_Else); - break; - - case 'n': // ".en" = end - fBlah = FALSE; - PutString(PseudoOp_EOF); - break; - - case 'q': // ".eq" = label def - fBlah = FALSE; - flags &= ~FLAG_INSERT_SPACE; - break; - } - break; - - case 'g': - if(b == 'l') // ".gl" = global label def - fBlah = FALSE; - flags &= ~FLAG_INSERT_SPACE; - break; - - case 'i': - if(b == 'f') { // ".if" = conditional assembly - fBlah = FALSE; - PutString(PseudoOp_If); - flags |= FLAG_ADD_LEFT_BRACE; - } - break; - - case 'm': - if(b == 'a') { // ".ma" = macro definition - fBlah = FALSE; - PutString(PseudoOp_MacroDef); - flags |= FLAG_SKIP_OPENING | FLAG_ADD_LEFT_BRACE; - } - break; - - case 'o': - if(b == 'b') { // ".ob" = output to file - fBlah = FALSE; - PutString(PseudoOp_ToFile); - flags |= FLAG_ADD_CBM; - } - break; - - case 'r': - if(b == 't') { // ".rt" = end of macro def - fBlah = FALSE; - PutString(PseudoOp_EndMacroDef); - } - break; - - case 's': - if(b == 'y') { // ".sy" = symbol dump - fBlah = FALSE; - PutString(PseudoOp_LabelDump); - PutString("\"symboldump.txt\";"); - } - break; - - case 't': - if(b == 'x') { // ".tx" = insert string - fBlah = FALSE; - PutString(PseudoOp_PetTxt); - } - if(b == 's') { // ".ts" = screen code string - fBlah = FALSE; - PutString(PseudoOp_ScrTxt); - } - break; - - case 'w': - if(b == 'o') { // ".wo" = insert words - fBlah = FALSE; - PutString(PseudoOp_Word); - } - break; - - } - GetByte();// exit with unused byte pre-read - } else - fBlah = TRUE; - } else - fBlah = TRUE; - if(fBlah) { - PutString("; ToACME: ."); - if(a) - PutByte(a); - if(b) - PutByte(b); - PutString(" cannot be converted\n"); } return(flags); } -// Process ocpode -// -void hypra_RealOpcode(void) {// character was last read +// handle ".ei", ".el", ".en" and ".eq" +static int process_po_e(char second) { + int flags = 0; - PutByte(PET2ISO(GotByte)); - GetByte(); - if((GotByte == ' ') || (GotByte == ';') || (GotByte == '\0')) + switch(second) { + + case 'i': // ".ei" = endif + IO_put_string(ACME_endif); + break; + + case 'l': // ".el" = else + IO_put_string(ACME_else); + break; + + case 'n': // ".en" = end + IO_put_string(ACME_po_eof); + flags |= FLAG_INSERT_SPACE; + break; + + case 'q': // ".eq" = label def + break; + + default: + complain('e', second); + + } + return(flags); +} + +// handle ".tx" and ".ts" +static int process_po_t(char second) { + int flags = 0; + + switch(second) { + + case 'x': // ".tx" = insert string + IO_put_string(ACME_po_pet); + flags |= FLAG_INSERT_SPACE; + break; + + case 's': // ".ts" = screen code string + IO_put_string(ACME_po_scr); + flags |= FLAG_INSERT_SPACE; + break; + + default: + complain('t', second); + + } + return(flags); +} + +#define ARE(a, b) ((first == a) && (second == b)) +// Process pseudo opcode +static int process_pseudo_opcode(void) {// '.' was last read + int first, + second; + + // get first byte. if illegal, complain and exit immediately + first = PET2ISO(IO_get_byte()); + if((first == SPACE) || (first == ';') || (first == '\0')) { + complain(first, '\0'); + return(0); + } + // get second byte. if illegal, complain and exit immediately + second = PET2ISO(IO_get_byte()); + if((second == SPACE) || (second == ';') || (second == '\0')) { + complain(first, second); + return(0); + } + IO_get_byte();// pre-read unused byte + // check pseudo opcodes (switch/case was actually harder to read) + if(first == 'b') { // handle ".ba" and ".by" + process_po_b(second); + return(FLAG_INSERT_SPACE); + } + if(first == 'e') // handle ".ei", ".el", ".en" and ".eq" + return(process_po_e(second)); + if(first == 't') // handle ".tx" and ".ts" + return(process_po_t(second)); + if(ARE('.', '.')) { // "..." = macro call + IO_put_string(ACME_macro_call); + return(FLAG_INSERT_SPACE | FLAG_SKIP_OPENING); + } + if(ARE('m', 'a')) { // ".ma" = macro definition + IO_put_string(ACME_po_macro); + return(FLAG_INSERT_SPACE|FLAG_SKIP_OPENING|FLAG_ADD_LEFT_BRACE); + } + if(ARE('o', 'b')) { // ".ob" = output to file + IO_put_string(ACME_po_to); + return(FLAG_INSERT_SPACE | FLAG_ADD_CBM); + } + if(ARE('s', 'y')) { // ".sy" = symbol dump + IO_put_string(ACME_po_sl); + IO_put_string("\"symboldump.txt\";"); + return(0); + } + if(ARE('i', 'f')) { // ".if" = cond. assembly + IO_put_string(ACME_po_if); + return(FLAG_INSERT_SPACE | FLAG_ADD_LEFT_BRACE); + } + if(ARE('g', 'l')) // ".gl" = global label def + return(0); + if(ARE('a', 'p')) // ".ap" = append source + IO_put_string(ACME_po_source); + else if(ARE('r', 't')) // ".rt" = end of macro def + IO_put_string(ACME_endmacro); + else if(ARE('w', 'o')) // ".wo" = insert words + IO_put_string(ACME_po_word); + else + complain(first, second); + return(FLAG_INSERT_SPACE); +} + +// Process opcode +static void real_opcode(void) {// character was last read + IO_put_byte(PET2ISO(GotByte)); + IO_get_byte(); + if((GotByte == SPACE) || (GotByte == ';') || (GotByte == '\0')) return; - PutByte(PET2ISO(GotByte)); - GetByte(); - if((GotByte == ' ') || (GotByte == ';') || (GotByte == '\0')) + IO_put_byte(PET2ISO(GotByte)); + IO_get_byte(); + if((GotByte == SPACE) || (GotByte == ';') || (GotByte == '\0')) return; - PutByte(PET2ISO(GotByte)); - GetByte();// exit with unused byte pre-read + IO_put_byte(PET2ISO(GotByte)); + IO_get_byte();// exit with unused byte pre-read return; } // Main routine for HypraAss conversion -// void hypra_main(void) { int indent; - input_set_padding(0); - io_process_load_address(); - acme_SwitchToPet(); + IO_set_input_padding(0); + IO_process_load_address(); + ACME_switch_to_pet(); // loop: once for every line in the file - while(!ReachedEOF) { + while(!IO_reached_eof) { // skip link pointer (if it's zero, report as end marker) - if(GetLE16() == 0) - PutString("; ToACME: Found BASIC end marker.\n"); - - GetLE16(); // skip line number - + if(IO_get_le16() == 0) + IO_put_string("; ToACME: Found BASIC end marker.\n"); + IO_get_le16(); // skip line number // process line - GetByte(); + IO_get_byte(); indent = 0; - if((GotByte != ' ') && (GotByte != ';') && (GotByte != '\0')) - indent = gigahypra_LabelDef(); - + if((GotByte != SPACE) && (GotByte != ';') && (GotByte != '\0')) + indent = GigaHypra_label_definition(); // skip spaces - while(GotByte == ' ') - GetByte(); - + while(GotByte == SPACE) + IO_get_byte(); // if there is an opcode, process it if((GotByte != ';') && (GotByte != '\0')) { - gigahypra_Indent(indent); + GigaHypra_indent(indent); // branch to relevant routine if(GotByte == '.') - gigahypra_Opcode(hypra_PseudoOpcode()); + GigaHypra_argument(process_pseudo_opcode()); else { - hypra_RealOpcode(); - gigahypra_Opcode(FLAG_INSERT_SPACE); + real_opcode(); + GigaHypra_argument(FLAG_INSERT_SPACE); } } - // skip comment, if there is one if(GotByte == ';') - gigahypra_ConvComment(); - + GigaHypra_comment(); // end of line - PutByte('\n'); + IO_put_byte('\n'); } } diff --git a/contrib/toacme/src/io.c b/contrib/toacme/src/io.c index f853e27..06a414d 100644 --- a/contrib/toacme/src/io.c +++ b/contrib/toacme/src/io.c @@ -1,104 +1,98 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // input/output -// - -// Includes -// #include <stdio.h> #include "config.h" #include "io.h" // Variables -// -int PaddingValue; +int padding_value; FILE *global_input_stream; FILE *global_output_stream; int GotByte = 0; -bool ReachedEOF = FALSE; +bool IO_reached_eof = FALSE; // Input functions -// - // Set byte sent after EOF -// -inline void input_set_padding(int pad) { - - PaddingValue = pad; +inline void IO_set_input_padding(int pad) { + padding_value = pad; } // Fetch and buffer byte -// -int GetByte(void) { +int IO_get_byte(void) { int w; - if(ReachedEOF) - GotByte = PaddingValue; + if(IO_reached_eof) + GotByte = padding_value; else { w = getc(global_input_stream); if(w == EOF) - ReachedEOF = TRUE; + IO_reached_eof = TRUE; GotByte = w; } return(GotByte); } // Read little-endian 16-bit value -// -unsigned int GetLE16(void) { - return(GetByte() | (GetByte() << 8)); +unsigned int IO_get_le16(void) { + unsigned int result = IO_get_byte(); + + // CAUTION! using + // return(IO_get_byte() | (IO_get_byte() << 8)); + // would be compiler-dependent + return(result | (IO_get_byte() << 8)); +} + +// Read little-endian 24-bit value +unsigned int IO_get_le24(void) { + unsigned int result = IO_get_le16(); + + // CAUTION! see above + return(result | (IO_get_byte() << 16)); } // Output functions -// - // output string -// -inline void PutString(const char string[]) { +inline void IO_put_string(const char string[]) { fputs(string, global_output_stream); } // Write byte to output file -// -inline void PutByte(const char b) { +inline void IO_put_byte(char b) { putc(b, global_output_stream); } // output low nibble of argument as hexadecimal digit -// -void put_low_nibble_hex(int v) { +static void put_low_nibble_hex(int v) { putc("0123456789abcdef"[v & 15], global_output_stream); } // output low byte of argument as two hexadecimal digits -// -void io_put_low_byte_hex(int v) { +void IO_put_low_byte_hex(int v) { put_low_nibble_hex(v >> 4); put_low_nibble_hex(v); } // output low 16 bits of arg as four hexadecimal digits -// -void io_put_low_16b_hex(int w) { - io_put_low_byte_hex(w >> 8); - io_put_low_byte_hex(w); +void IO_put_low_16b_hex(int w) { + IO_put_low_byte_hex(w >> 8); + IO_put_low_byte_hex(w); } // read load address from input file and write as comment to output file -// -void io_process_load_address(void) { +void IO_process_load_address(void) { int load_address; - load_address = GetLE16(); - PutString("; ToACME: Original source code file had load address $"); - io_put_low_16b_hex(load_address); - PutByte('\n'); + load_address = IO_get_le16(); + IO_put_string("; ToACME: Original source code file had load address $"); + IO_put_low_16b_hex(load_address); + IO_put_byte('\n'); } diff --git a/contrib/toacme/src/io.h b/contrib/toacme/src/io.h index f69fa40..5c1876d 100644 --- a/contrib/toacme/src/io.h +++ b/contrib/toacme/src/io.h @@ -1,37 +1,32 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // input/output -// #ifndef io_H #define io_H - -// Includes -// #include <stdio.h> #include "config.h" // Variables -// extern int GotByte; -extern bool ReachedEOF; +extern bool IO_reached_eof; extern FILE *global_input_stream; extern FILE *global_output_stream; // Prototypes -// -extern void input_set_padding(const int); -extern int GetByte(void); -extern unsigned int GetLE16(void); // get little-endian 16-bit value -extern void PutString(const char string[]); -extern void PutByte(const char b); -extern void io_put_low_byte_hex(int v); -extern void io_put_low_16b_hex(int w); -extern void io_process_load_address(void); +extern void IO_set_input_padding(int); +extern int IO_get_byte(void); +extern unsigned int IO_get_le16(void);// get little-endian 16-bit value +extern unsigned int IO_get_le24(void);// get little-endian 24-bit value +extern void IO_put_string(const char string[]); +extern void IO_put_byte(char b); +extern void IO_put_low_byte_hex(int v); +extern void IO_put_low_16b_hex(int w); +extern void IO_process_load_address(void); #endif diff --git a/contrib/toacme/src/main.c b/contrib/toacme/src/main.c index 477efb0..58909e9 100644 --- a/contrib/toacme/src/main.c +++ b/contrib/toacme/src/main.c @@ -1,5 +1,5 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -14,11 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// - -// Includes -// #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -30,10 +26,8 @@ #include "version.h" -// Main program -// +// Guess what int main(int argc, char *argv[]) { - // handle "toacme -h" and "toacme --help" just like "toacme" if(argc == 2) { if((strcmp(argv[1], "-h") == 0) @@ -76,7 +70,7 @@ int main(int argc, char *argv[]) { version_main(); // and then tidy up and exit fclose(global_output_stream); - PLATFORM_SETFILETYPE(argv[3], FILETYPE_TEXT); + PLATFORM_SETFILETYPE_TEXT(argv[3]); fclose(global_input_stream); return(EXIT_SUCCESS); } diff --git a/contrib/toacme/src/mnemo.c b/contrib/toacme/src/mnemo.c index 4a02a96..7008c1e 100644 --- a/contrib/toacme/src/mnemo.c +++ b/contrib/toacme/src/mnemo.c @@ -1,9 +1,8 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // assembler mnemonics -// // Mnemonics of legal 6502 instructions const char MnemonicADC[] = "adc"; @@ -64,14 +63,21 @@ const char MnemonicTXS[] = "txs"; const char MnemonicTYA[] = "tya"; // Mnemonics of undocumented ("illegal") 6502 instructions -const char MnemonicSLO[] = " Slo"; -const char MnemonicRLA[] = " Rla"; -const char MnemonicSRE[] = " Sre"; -const char MnemonicRRA[] = " Rra"; -const char MnemonicSAX[] = " Sax"; -const char MnemonicLAX[] = " Lax"; -const char MnemonicDCP[] = " Dcp"; -const char MnemonicISC[] = " Isc"; +const char MnemonicSLO[] = " SLO"; +const char MnemonicRLA[] = " RLA"; +const char MnemonicSRE[] = " SRE"; +const char MnemonicRRA[] = " RRA"; +const char MnemonicSAX[] = " SAX"; +const char MnemonicLAX[] = " LAX"; +const char MnemonicDCP[] = " DCP"; +const char MnemonicISC[] = " ISC"; +const char MnemonicANC[] = " ANC"; +const char MnemonicARR[] = " ARR"; +const char MnemonicASR[] = " ASR"; +const char MnemonicSBX[] = " SBX"; +const char MnemonicDOP[] = " DOP"; +const char MnemonicTOP[] = " TOP"; +const char MnemonicJAM[] = " JAM"; // Mnemonics of 65c02 instructions const char MnemonicBRA[] = "bra"; diff --git a/contrib/toacme/src/mnemo.h b/contrib/toacme/src/mnemo.h index 658428d..2955de4 100644 --- a/contrib/toacme/src/mnemo.h +++ b/contrib/toacme/src/mnemo.h @@ -1,9 +1,8 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // 6502 mnemonics -// #ifndef mnemo_H #define mnemo_H @@ -33,10 +32,11 @@ extern const char MnemonicTSX[], MnemonicTXA[], MnemonicTAY[]; extern const char MnemonicTYA[], MnemonicTAX[], MnemonicTXS[]; // Mnemonics of undocumented ("illegal") 6502 instructions -extern const char MnemonicSLO[], MnemonicRLA[]; -extern const char MnemonicSRE[], MnemonicRRA[]; -extern const char MnemonicSAX[], MnemonicLAX[]; -extern const char MnemonicDCP[], MnemonicISC[]; +extern const char MnemonicANC[], MnemonicARR[], MnemonicASR[]; +extern const char MnemonicDCP[], MnemonicDOP[], MnemonicISC[]; +extern const char MnemonicJAM[], MnemonicLAX[], MnemonicRLA[]; +extern const char MnemonicRRA[], MnemonicSAX[], MnemonicSBX[]; +extern const char MnemonicSLO[], MnemonicSRE[], MnemonicTOP[]; // Mnemonics of 65c02 instructions extern const char MnemonicBRA[]; diff --git a/contrib/toacme/src/obj.c b/contrib/toacme/src/obj.c index ae33af2..4ed7249 100644 --- a/contrib/toacme/src/obj.c +++ b/contrib/toacme/src/obj.c @@ -1,13 +1,9 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2005 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // disassembly stuff -// - -// Includes -// #include <stdio.h> #include "config.h" #include "acme.h" @@ -16,47 +12,46 @@ // Constants -// // 6502 code table (mnemonics only) *illegals* const char* mnemo_of_code[] = { -MnemonicBRK, MnemonicORA, NULL, MnemonicSLO, // $00-$03 -NULL, MnemonicORA, MnemonicASL, MnemonicSLO, // $04-$07 -MnemonicPHP, MnemonicORA, MnemonicASL, NULL, // $08-$0b -NULL, MnemonicORA, MnemonicASL, MnemonicSLO, // $0c-$0f -MnemonicBPL, MnemonicORA, NULL, MnemonicSLO, // $10-$13 -NULL, MnemonicORA, MnemonicASL, MnemonicSLO, // $14-$17 -MnemonicCLC, MnemonicORA, NULL, MnemonicSLO, // $18-$1b -NULL, MnemonicORA, MnemonicASL, MnemonicSLO, // $1c-$1f -MnemonicJSR, MnemonicAND, NULL, MnemonicRLA, // $20-$23 +MnemonicBRK, MnemonicORA, " JAM;0x02", MnemonicSLO, // $00-$03 +" DOP;0x04", MnemonicORA, MnemonicASL, MnemonicSLO, // $04-$07 +MnemonicPHP, MnemonicORA, MnemonicASL, "!by$0b;ANC#", // $08-$0b +" TOP;0x0c", MnemonicORA, MnemonicASL, MnemonicSLO, // $0c-$0f +MnemonicBPL, MnemonicORA, " JAM;0x12", MnemonicSLO, // $10-$13 +" DOP;0x14", MnemonicORA, MnemonicASL, MnemonicSLO, // $14-$17 +MnemonicCLC, MnemonicORA, " NOP;0x1a", MnemonicSLO, // $18-$1b +" TOP;0x1c", MnemonicORA, MnemonicASL, MnemonicSLO, // $1c-$1f +MnemonicJSR, MnemonicAND, " JAM;0x22", MnemonicRLA, // $20-$23 MnemonicBIT, MnemonicAND, MnemonicROL, MnemonicRLA, // $24-$27 -MnemonicPLP, MnemonicAND, MnemonicROL, NULL, // $28-$2b +MnemonicPLP, MnemonicAND, MnemonicROL, "!by$2b;ANC#", // $28-$2b MnemonicBIT, MnemonicAND, MnemonicROL, MnemonicRLA, // $2c-$2f -MnemonicBMI, MnemonicAND, NULL, MnemonicRLA, // $30-$33 -NULL, MnemonicAND, MnemonicROL, MnemonicRLA, // $34-$37 -MnemonicSEC, MnemonicAND, NULL, MnemonicRLA, // $38-$3b -NULL, MnemonicAND, MnemonicROL, MnemonicRLA, // $3c-$3f -MnemonicRTI, MnemonicEOR, NULL, MnemonicSRE, // $40-$43 -NULL, MnemonicEOR, MnemonicLSR, MnemonicSRE, // $44-$47 -MnemonicPHA, MnemonicEOR, MnemonicLSR, NULL, // $48-$4b +MnemonicBMI, MnemonicAND, " JAM;0x32", MnemonicRLA, // $30-$33 +" DOP;0x34", MnemonicAND, MnemonicROL, MnemonicRLA, // $34-$37 +MnemonicSEC, MnemonicAND, " NOP;0x3a", MnemonicRLA, // $38-$3b +" TOP;0x3c", MnemonicAND, MnemonicROL, MnemonicRLA, // $3c-$3f +MnemonicRTI, MnemonicEOR, " JAM;0x42", MnemonicSRE, // $40-$43 +" DOP;0x44", MnemonicEOR, MnemonicLSR, MnemonicSRE, // $44-$47 +MnemonicPHA, MnemonicEOR, MnemonicLSR, MnemonicASR, // $48-$4b MnemonicJMP, MnemonicEOR, MnemonicLSR, MnemonicSRE, // $4c-$4f -MnemonicBVC, MnemonicEOR, NULL, MnemonicSRE, // $50-$53 -NULL, MnemonicEOR, MnemonicLSR, MnemonicSRE, // $54-$57 -MnemonicCLI, MnemonicEOR, NULL, MnemonicSRE, // $58-$5b -NULL, MnemonicEOR, MnemonicLSR, MnemonicSRE, // $5c-$5f -MnemonicRTS, MnemonicADC, NULL, MnemonicRRA, // $60-$63 -NULL, MnemonicADC, MnemonicROR, MnemonicRRA, // $64-$67 -MnemonicPLA, MnemonicADC, MnemonicROR, NULL, // $68-$6b +MnemonicBVC, MnemonicEOR, " JAM;0x52", MnemonicSRE, // $50-$53 +" DOP;0x54", MnemonicEOR, MnemonicLSR, MnemonicSRE, // $54-$57 +MnemonicCLI, MnemonicEOR, " NOP;0x5a", MnemonicSRE, // $58-$5b +" TOP;0x5c", MnemonicEOR, MnemonicLSR, MnemonicSRE, // $5c-$5f +MnemonicRTS, MnemonicADC, " JAM;0x62", MnemonicRRA, // $60-$63 +" DOP;0x64", MnemonicADC, MnemonicROR, MnemonicRRA, // $64-$67 +MnemonicPLA, MnemonicADC, MnemonicROR, MnemonicARR, // $68-$6b MnemonicJMP, MnemonicADC, MnemonicROR, MnemonicRRA, // $6c-$6f -MnemonicBVS, MnemonicADC, NULL, MnemonicRRA, // $70-$73 -NULL, MnemonicADC, MnemonicROR, MnemonicRRA, // $74-$77 -MnemonicSEI, MnemonicADC, NULL, MnemonicRRA, // $78-$7b -NULL, MnemonicADC, MnemonicROR, MnemonicRRA, // $7c-$7f -NULL, MnemonicSTA, NULL, MnemonicSAX, // $80-$83 +MnemonicBVS, MnemonicADC, " JAM;0x72", MnemonicRRA, // $70-$73 +" DOP;0x74", MnemonicADC, MnemonicROR, MnemonicRRA, // $74-$77 +MnemonicSEI, MnemonicADC, " NOP;0x7a", MnemonicRRA, // $78-$7b +" TOP;0x7c", MnemonicADC, MnemonicROR, MnemonicRRA, // $7c-$7f +" DOP;0x80", MnemonicSTA, " DOP;0x82", MnemonicSAX, // $80-$83 MnemonicSTY, MnemonicSTA, MnemonicSTX, MnemonicSAX, // $84-$87 -MnemonicDEY, NULL, MnemonicTXA, NULL, // $88-$8b +MnemonicDEY, " DOP;0x89", MnemonicTXA, NULL, // $88-$8b MnemonicSTY, MnemonicSTA, MnemonicSTX, MnemonicSAX, // $8c-$8f -MnemonicBCC, MnemonicSTA, NULL, NULL, // $90-$93 +MnemonicBCC, MnemonicSTA, " JAM;0x92", NULL, // $90-$93 MnemonicSTY, MnemonicSTA, MnemonicSTX, MnemonicSAX, // $94-$97 MnemonicTYA, MnemonicSTA, MnemonicTXS, NULL, // $98-$9b NULL, MnemonicSTA, NULL, NULL, // $9c-$9f @@ -64,42 +59,40 @@ MnemonicLDY, MnemonicLDA, MnemonicLDX, MnemonicLAX, // $a0-$a3 MnemonicLDY, MnemonicLDA, MnemonicLDX, MnemonicLAX, // $a4-$a7 MnemonicTAY, MnemonicLDA, MnemonicTAX, NULL, // $a8-$ab MnemonicLDY, MnemonicLDA, MnemonicLDX, MnemonicLAX, // $ac-$af -MnemonicBCS, MnemonicLDA, NULL, MnemonicLAX, // $b0-$b3 +MnemonicBCS, MnemonicLDA, " JAM;0xb2", MnemonicLAX, // $b0-$b3 MnemonicLDY, MnemonicLDA, MnemonicLDX, MnemonicLAX, // $b4-$b7 MnemonicCLV, MnemonicLDA, MnemonicTSX, NULL, // $b8-$bb MnemonicLDY, MnemonicLDA, MnemonicLDX, MnemonicLAX, // $bc-$bf -MnemonicCPY, MnemonicCMP, NULL, MnemonicDCP, // $c0-$c3 +MnemonicCPY, MnemonicCMP, " DOP;0xc2", MnemonicDCP, // $c0-$c3 MnemonicCPY, MnemonicCMP, MnemonicDEC, MnemonicDCP, // $c4-$c7 -MnemonicINY, MnemonicCMP, MnemonicDEX, NULL, // $c8-$cb +MnemonicINY, MnemonicCMP, MnemonicDEX, MnemonicSBX, // $c8-$cb MnemonicCPY, MnemonicCMP, MnemonicDEC, MnemonicDCP, // $cc-$cf -MnemonicBNE, MnemonicCMP, NULL, MnemonicDCP, // $d0-$d3 -NULL, MnemonicCMP, MnemonicDEC, MnemonicDCP, // $d4-$d7 -MnemonicCLD, MnemonicCMP, NULL, MnemonicDCP, // $d8-$db -NULL, MnemonicCMP, MnemonicDEC, MnemonicDCP, // $dc-$df -MnemonicCPX, MnemonicSBC, NULL, MnemonicISC, // $e0-$e3 +MnemonicBNE, MnemonicCMP, " JAM;0xd2", MnemonicDCP, // $d0-$d3 +" DOP;0xd4", MnemonicCMP, MnemonicDEC, MnemonicDCP, // $d4-$d7 +MnemonicCLD, MnemonicCMP, " NOP;0xda", MnemonicDCP, // $d8-$db +" TOP;0xdc", MnemonicCMP, MnemonicDEC, MnemonicDCP, // $dc-$df +MnemonicCPX, MnemonicSBC, " DOP;0xe2", MnemonicISC, // $e0-$e3 MnemonicCPX, MnemonicSBC, MnemonicINC, MnemonicISC, // $e4-$e7 -MnemonicINX, MnemonicSBC, MnemonicNOP, NULL, // $e8-$eb +MnemonicINX, MnemonicSBC, MnemonicNOP, "!by$eb;SBC#", // $e8-$eb MnemonicCPX, MnemonicSBC, MnemonicINC, MnemonicISC, // $ec-$ef -MnemonicBEQ, MnemonicSBC, NULL, MnemonicISC, // $f0-$f3 -NULL, MnemonicSBC, MnemonicINC, MnemonicISC, // $f4-$f7 -MnemonicSED, MnemonicSBC, NULL, MnemonicISC, // $f8-$fb -NULL, MnemonicSBC, MnemonicINC, MnemonicISC, // $fc-$ff +MnemonicBEQ, MnemonicSBC, " JAM;0xf2", MnemonicISC, // $f0-$f3 +" DOP;0xf4", MnemonicSBC, MnemonicINC, MnemonicISC, // $f4-$f7 +MnemonicSED, MnemonicSBC, " NOP;0xfa", MnemonicISC, // $f8-$fb +" TOP;0xfc", MnemonicSBC, MnemonicINC, MnemonicISC, // $fc-$ff }; // output 2-digit hex argument with correct addressing mode -// static void put_argument2(const char pre[], int byte, const char post[]) { - PutString(pre); - io_put_low_byte_hex(byte); - PutString(post); + IO_put_string(pre); + IO_put_low_byte_hex(byte); + IO_put_string(post); } // output 4-digit hex argument with correct addressing mode -// static void put_argument4(const char pre[], int word, const char post[]) { - PutString(pre); - io_put_low_16b_hex(word); - PutString(post); + IO_put_string(pre); + IO_put_low_16b_hex(word); + IO_put_string(post); } static int pc; // needed by "relative" addressing mode handler @@ -114,58 +107,59 @@ static int am_implied(void) { } // addressing mode handler functions for 2-byte-instructions static int am_immediate(void) { - put_argument2(" #$", GetByte(), ""); + put_argument2(" #$", IO_get_byte(), ""); if(GotByte > 15) { fprintf(global_output_stream, " ; (= %d", GotByte); if((GotByte > 31) && (GotByte != 127)) fprintf(global_output_stream, " = '%c'", GotByte); - PutByte(')'); + IO_put_byte(')'); } return(2); } static int am_absolute8(void) { - put_argument2(" $", GetByte(), ""); + put_argument2(" $", IO_get_byte(), ""); return(2); } static int am_abs_x8(void) { - put_argument2(" $", GetByte(), ",x"); + put_argument2(" $", IO_get_byte(), ",x"); return(2); } static int am_abs_y8(void) { - put_argument2(" $", GetByte(), ",y"); + put_argument2(" $", IO_get_byte(), ",y"); return(2); } static int am_indirect_x(void) { - put_argument2(" ($", GetByte(), ",x)"); + put_argument2(" ($", IO_get_byte(), ",x)"); return(2); } static int am_indirect_y(void) { - put_argument2(" ($", GetByte(), "),y"); + put_argument2(" ($", IO_get_byte(), "),y"); return(2); } static int am_relative(void) { - put_argument4(" L", pc + 2 + (signed char) GetByte(), ""); + put_argument4(" L", pc + 2 + (signed char) IO_get_byte(), ""); return(2); } // addressing mode handler functions for 3-byte-instructions static int am_absolute16(void) { - put_argument4(" L", GetLE16(), ""); + put_argument4(" L", IO_get_le16(), ""); return(3); } static int am_abs_x16(void) { - put_argument4(" L", GetLE16(), ",x"); + put_argument4(" L", IO_get_le16(), ",x"); return(3); } static int am_abs_y16(void) { - put_argument4(" L", GetLE16(), ",y"); + put_argument4(" L", IO_get_le16(), ",y"); return(3); } static int am_indirect16(void) { - put_argument4(" (L", GetLE16(), ")"); + put_argument4(" (L", IO_get_le16(), ")"); return(3); } // 6502 code table (addressing mode handler functions) +// all ANC/DOP/TOP are given as "implied", so the argument is not processed int (*addressing_mode_of_code[])(void) = { am_implied, am_indirect_x, am_implied, am_indirect_x, // $00-$03 am_implied, am_absolute8, am_absolute8, am_absolute8, // $04-$07 @@ -185,7 +179,7 @@ am_implied, am_abs_y16, am_implied, am_abs_y16, // $38-$3b am_implied, am_abs_x16, am_abs_x16, am_abs_x16, // $3c-$3f am_implied, am_indirect_x, am_implied, am_indirect_x, // $40-$43 am_implied, am_absolute8, am_absolute8, am_absolute8, // $44-$47 -am_implied, am_immediate, am_implied, am_implied, // $48-$4b +am_implied, am_immediate, am_implied, am_immediate, // $48-$4b am_absolute16, am_absolute16, am_absolute16, am_absolute16, // $4c-$4f am_relative, am_indirect_y, am_implied, am_indirect_y, // $50-$53 am_implied, am_abs_x8, am_abs_x8, am_abs_x8, // $54-$57 @@ -193,7 +187,7 @@ am_implied, am_abs_y16, am_implied, am_abs_y16, // $58-$5b am_implied, am_abs_x16, am_abs_x16, am_abs_x16, // $5c-$5f am_implied, am_indirect_x, am_implied, am_indirect_x, // $60-$63 am_implied, am_absolute8, am_absolute8, am_absolute8, // $64-$67 -am_implied, am_immediate, am_implied, am_implied, // $68-$6b +am_implied, am_immediate, am_implied, am_immediate, // $68-$6b am_indirect16, am_absolute16, am_absolute16, am_absolute16, // $6c-$6f am_relative, am_indirect_y, am_implied, am_indirect_y, // $70-$73 am_implied, am_abs_x8, am_abs_x8, am_abs_x8, // $74-$77 @@ -217,7 +211,7 @@ am_implied, am_abs_y16, am_implied, am_implied, // $b8-$bb am_abs_x16, am_abs_x16, am_abs_y16, am_abs_y16, // $bc-$bf am_immediate, am_indirect_x, am_implied, am_indirect_x, // $c0-$c3 am_absolute8, am_absolute8, am_absolute8, am_absolute8, // $c4-$c7 -am_implied, am_immediate, am_implied, am_implied, // $c8-$cb +am_implied, am_immediate, am_implied, am_immediate, // $c8-$cb am_absolute16, am_absolute16, am_absolute16, am_absolute16, // $cc-$cf am_relative, am_indirect_y, am_implied, am_indirect_y, // $d0-$d3 am_implied, am_abs_x8, am_abs_x8, am_abs_x8, // $d4-$d7 @@ -234,33 +228,29 @@ am_implied, am_abs_x16, am_abs_x16, am_abs_x16, // $fc-$ff }; // output mnemonic of given byte -// -void output_mnemonic(int byte) { +static void output_mnemonic(int byte) { const char* mnemo = mnemo_of_code[byte]; if(mnemo) - PutString(mnemo); + IO_put_string(mnemo); else put_argument2("$", byte, ""); } // Main routine for disassembly -// void obj_main(void) { - - input_set_padding(0); - + IO_set_input_padding(0); // process load address - pc = GetLE16(); + pc = IO_get_le16(); put_argument4("\t\t*=$", pc, "\n"); - GetByte(); - while(!ReachedEOF) { + IO_get_byte(); + while(!IO_reached_eof) { put_argument4("L", pc, "\t\t"); output_mnemonic(GotByte); pc += addressing_mode_of_code[GotByte](); - PutByte('\n'); - GetByte(); + IO_put_byte('\n'); + IO_get_byte(); } // report end-of-file - PutString("; ToACME: Reached end-of-file.\n"); + IO_put_string("; ToACME: Reached end-of-file.\n"); } diff --git a/contrib/toacme/src/pet2iso.c b/contrib/toacme/src/pet2iso.c index c30f0ce..4e2d846 100644 --- a/contrib/toacme/src/pet2iso.c +++ b/contrib/toacme/src/pet2iso.c @@ -1,21 +1,16 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // Converting CBM PetSCII code to ISO 8859/1 -// - -// Includes -// #include "pet2iso.h" // Constants -// // Conversion table -const char Pet2ISO_Table[256] = { +const char PET2ISO_table[256] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, diff --git a/contrib/toacme/src/pet2iso.h b/contrib/toacme/src/pet2iso.h index 2cae39d..78ee48f 100644 --- a/contrib/toacme/src/pet2iso.h +++ b/contrib/toacme/src/pet2iso.h @@ -1,22 +1,17 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // Converting CBM PetSCII code to ISO 8859/1 -// #ifndef pet2iso_H #define pet2iso_H - -// Includes -// #include "config.h" // Constants -// -extern const char Pet2ISO_Table[256]; // Conversion table -#define PET2ISO(v) (Pet2ISO_Table[(unsigned char) v]) +extern const char PET2ISO_table[256]; // Conversion table +#define PET2ISO(v) (PET2ISO_table[(unsigned char) v]) #endif diff --git a/contrib/toacme/src/platform.c b/contrib/toacme/src/platform.c index 56449e1..366833e 100644 --- a/contrib/toacme/src/platform.c +++ b/contrib/toacme/src/platform.c @@ -1,13 +1,9 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // Platform specific stuff -// - -// Includes -// #include "platform.h" @@ -19,13 +15,13 @@ #define OS_FILE 0x00008 // constant to call relevant SWI // Setting the created files' types -void Platform_SetFileType(const char *Filename, int Filetype) { - _kernel_swi_regs RegSet; +void Platform_set_file_type_text(const char *filename) { + _kernel_swi_regs register_set; - RegSet.r[0] = 18;// = SetFileType - RegSet.r[1] = (int) Filename; - RegSet.r[2] = Filetype; - _kernel_swi(OS_FILE, &RegSet, &RegSet); + register_set.r[0] = 18;// = SetFileType + register_set.r[1] = (int) filename; + register_set.r[2] = 0xfff; + _kernel_swi(OS_FILE, ®ister_set, ®ister_set); } #else diff --git a/contrib/toacme/src/platform.h b/contrib/toacme/src/platform.h index 4b0aa18..c42066d 100644 --- a/contrib/toacme/src/platform.h +++ b/contrib/toacme/src/platform.h @@ -1,9 +1,8 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // Platform specific stuff -// #ifndef platform_H #define platform_H @@ -11,15 +10,14 @@ // check for RISC OS #ifdef __riscos__ #define PLATFORM_VERSION "Ported to RISC OS by Marco Baye." -extern void Platform_SetFileType(const char *Filename, int Filetype); -#define PLATFORM_SETFILETYPE(a, b) Platform_SetFileType(a, b); -#define FILETYPE_TEXT 0xfff // File types used +#define PLATFORM_SETFILETYPE_TEXT(a) Platform_set_file_type_text(a); +extern void Platform_set_file_type_text(const char *filename); #endif // all other platforms #ifndef PLATFORM_VERSION #define PLATFORM_VERSION "Platform independent version." -#define PLATFORM_SETFILETYPE(a, b) +#define PLATFORM_SETFILETYPE_TEXT(a) #endif // fix umlaut for DOS version diff --git a/contrib/toacme/src/scr2iso.c b/contrib/toacme/src/scr2iso.c index 88ae551..31a0d3c 100644 --- a/contrib/toacme/src/scr2iso.c +++ b/contrib/toacme/src/scr2iso.c @@ -1,21 +1,16 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // Converting CBM screen code to ISO 8859/1 -// - -// Includes -// #include "scr2iso.h" // Constants -// // Conversion table -const char Scr2ISO_Table[256] = { +const char SCR2ISO_table[256] = { 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, diff --git a/contrib/toacme/src/scr2iso.h b/contrib/toacme/src/scr2iso.h index 3c1d3e0..fc55764 100644 --- a/contrib/toacme/src/scr2iso.h +++ b/contrib/toacme/src/scr2iso.h @@ -1,22 +1,17 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // Converting CBM screen code to ISO 8859/1 -// #ifndef scr2iso_H #define scr2iso_H - -// Includes -// #include "config.h" // Constants -// -extern const char Scr2ISO_Table[256]; // Conversion table -#define SCR2ISO(v) (Scr2ISO_Table[(unsigned char) v]) +extern const char SCR2ISO_table[256]; // Conversion table +#define SCR2ISO(v) (SCR2ISO_table[(unsigned char) v]) #endif diff --git a/contrib/toacme/src/version.c b/contrib/toacme/src/version.c index 8b08d1a..a0e633d 100644 --- a/contrib/toacme/src/version.c +++ b/contrib/toacme/src/version.c @@ -1,17 +1,15 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // Version -// -#define RELEASE_NUMBER "0.9" // change before release (FIXME) -#define CHANGE_DATE "12 Mar" // change before release + +#define RELEASE_NUMBER "0.10" // change before release (FIXME) +#define CHANGE_DATE "4 Oct" // change before release #define CHANGE_YEAR "2006" // change before release #define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/" +#define FILE_TAG ";ACME 0.93" // check before release - -// Includes -// #include <stdio.h> #include <string.h> #include "io.h" @@ -19,15 +17,12 @@ // Variables -// void (*client_main)(void) = NULL; // Functions -// // show version info and usage -// void version_show_info(const char program_name[]) { printf( "\n" @@ -58,15 +53,13 @@ HOME_PAGE"\n" , program_name); } -// Check id string. Returns whether illegal. -// extern void ab3_main(void); extern void f8ab_main(void); extern void giga_main(void); extern void hypra_main(void); extern void obj_main(void); +// Check id string. Returns whether illegal. int version_parse_id(const char id[]) { - if(strcmp(id, "ab3") == 0) client_main = ab3_main; else if(strcmp(id, "f8ab") == 0) @@ -81,10 +74,9 @@ int version_parse_id(const char id[]) { } // do the actual work -// void version_main(void) { - PutString( -";ACME 0.88\n" + IO_put_string( +FILE_TAG "\n" "; ToACME: Converted by ToACME, release " RELEASE_NUMBER ".\n" ); client_main(); diff --git a/contrib/toacme/src/version.h b/contrib/toacme/src/version.h index b6ade28..d4ff85f 100644 --- a/contrib/toacme/src/version.h +++ b/contrib/toacme/src/version.h @@ -1,15 +1,13 @@ // ToACME - converts other source codes to ACME format. -// Copyright (C) 1999-2003 Marco Baye +// Copyright (C) 1999-2006 Marco Baye // Have a look at "main.c" for further info // // version -// #ifndef version_H #define version_H // Prototypes -// extern void version_show_info(const char[]); extern int version_parse_id(const char[]); extern void version_main(void);