| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include "config.h" |
| 8 |
#include "acme.h" |
| 9 |
#include "gighyp.h" |
| 10 |
#include "io.h" |
| 11 |
#include "pet2iso.h" |
| 12 |
#include "mnemo.h" |
| 13 |
#include <string.h> |
| 14 |
|
| 15 |
|
| 16 |
const char *TokenOpcode_Table[] = { |
| 17 |
MnemonicLDA, MnemonicSTA, MnemonicLDX, MnemonicLDY, MnemonicCMP, MnemonicADC, MnemonicAND, MnemonicSTX, |
| 18 |
MnemonicSTY, MnemonicINC, MnemonicCPX, MnemonicASL, MnemonicBIT, MnemonicLSR, MnemonicORA, MnemonicROL, |
| 19 |
MnemonicROR, MnemonicSBC, MnemonicCPY, MnemonicDEC, MnemonicEOR, MnemonicJMP, MnemonicJSR, MnemonicTXA, |
| 20 |
MnemonicTAX, MnemonicTYA, MnemonicTAY, MnemonicTSX, MnemonicTXS, MnemonicINY, MnemonicPLP, MnemonicPHA, |
| 21 |
MnemonicPLA, MnemonicINX, MnemonicDEY, MnemonicRTS, MnemonicNOP, MnemonicCLC, MnemonicSEC, MnemonicCLI, |
| 22 |
MnemonicSEI, MnemonicCLV, MnemonicCLD, MnemonicSED, MnemonicRTI, MnemonicPHP, MnemonicDEX, MnemonicBRK, |
| 23 |
MnemonicBPL, MnemonicBMI, MnemonicBVC, MnemonicBVS, MnemonicBCC, MnemonicBCS, MnemonicBNE, MnemonicBEQ, |
| 24 |
}; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
struct Instructs process_pseudo_opcode(void) |
| 30 |
{ |
| 31 |
int erstesZeichen, |
| 32 |
flags = FLAG_INSERT_SPACE; |
| 33 |
char txtOpcode[20]; |
| 34 |
bool isFound = FALSE; |
| 35 |
struct Instructs instructs; |
| 36 |
|
| 37 |
erstesZeichen = IO_get_byte(); |
| 38 |
switch (erstesZeichen) { |
| 39 |
case 0x90: |
| 40 |
isFound = TRUE; |
| 41 |
IO_put_string(ACME_set_pc); |
| 42 |
break; |
| 43 |
case 0x91: |
| 44 |
isFound = TRUE; |
| 45 |
IO_put_string(ACME_po_pet); |
| 46 |
flags |= FLAG_TASK_WITH_COMMA; |
| 47 |
strncpy(txtOpcode, ACME_po_pet, 19); |
| 48 |
break; |
| 49 |
case 0x8f: |
| 50 |
isFound = TRUE; |
| 51 |
flags &= ~FLAG_INSERT_SPACE; |
| 52 |
break; |
| 53 |
case 0xa2: |
| 54 |
isFound = TRUE; |
| 55 |
IO_put_string(ACME_po_source); |
| 56 |
flags |= FLAG_TASK_WITH_COMMA; |
| 57 |
strncpy(txtOpcode, ACME_po_source, 19); |
| 58 |
break; |
| 59 |
default: |
| 60 |
|
| 61 |
break; |
| 62 |
} |
| 63 |
|
| 64 |
if (!isFound) { |
| 65 |
char hexString[255]; |
| 66 |
|
| 67 |
IO_put_string("; ToACME: ."); |
| 68 |
if (erstesZeichen) { |
| 69 |
sprintf(hexString, "0x%X", erstesZeichen); |
| 70 |
IO_put_string(hexString); |
| 71 |
} |
| 72 |
IO_put_string(" cannot be converted\n"); |
| 73 |
} else { |
| 74 |
IO_get_byte(); |
| 75 |
} |
| 76 |
|
| 77 |
instructs.flags = flags; |
| 78 |
strcpy(instructs.txtOpcode, txtOpcode); |
| 79 |
return instructs; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
static void process_real_opcode(void) |
| 84 |
{ |
| 85 |
if (GotByte > 0x80 && GotByte < 0xc7) { |
| 86 |
IO_put_string(TokenOpcode_Table[GotByte - 0x81]); |
| 87 |
IO_get_byte(); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
void top_main(void) |
| 94 |
{ |
| 95 |
int indent; |
| 96 |
|
| 97 |
IO_set_input_padding(0); |
| 98 |
IO_process_load_address(); |
| 99 |
ACME_switch_to_pet(); |
| 100 |
|
| 101 |
while (!IO_reached_eof) { |
| 102 |
|
| 103 |
if (IO_get_le16() == 0) |
| 104 |
IO_put_string("; ToACME: Found BASIC end marker.\n"); |
| 105 |
|
| 106 |
IO_get_le16(); |
| 107 |
|
| 108 |
|
| 109 |
IO_get_byte(); |
| 110 |
indent = 0; |
| 111 |
if ((GotByte != ' ') && (GotByte != ';') && (GotByte != '\0')) |
| 112 |
indent = GigaHypra_label_definition(); |
| 113 |
|
| 114 |
|
| 115 |
while (GotByte == ' ') |
| 116 |
IO_get_byte(); |
| 117 |
|
| 118 |
|
| 119 |
if ((GotByte != ';') && (GotByte != '\0')) { |
| 120 |
GigaHypra_indent(indent); |
| 121 |
|
| 122 |
if (GotByte == '.') { |
| 123 |
GigaHypra_argument_with_instructs(process_pseudo_opcode(), indent); |
| 124 |
} else { |
| 125 |
process_real_opcode(); |
| 126 |
GigaHypra_argument(FLAG_INSERT_SPACE); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
if (GotByte == ';') |
| 132 |
GigaHypra_comment(); |
| 133 |
|
| 134 |
|
| 135 |
IO_put_byte('\n'); |
| 136 |
} |
| 137 |
} |