| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include <stdio.h> |
| 8 |
#include "config.h" |
| 9 |
#include "acme.h" |
| 10 |
#include "gighyp.h" |
| 11 |
#include "io.h" |
| 12 |
#include "pet2iso.h" |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
static void complain(char a, char b) |
| 19 |
{ |
| 20 |
IO_put_string("; ToACME: ."); |
| 21 |
if (a) |
| 22 |
IO_put_byte(a); |
| 23 |
if (b) |
| 24 |
IO_put_byte(b); |
| 25 |
IO_put_string(" cannot be converted\n"); |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
static int process_po_b(char second) |
| 31 |
{ |
| 32 |
int flags = 0; |
| 33 |
|
| 34 |
switch (second) { |
| 35 |
case 'a': |
| 36 |
IO_put_string(ACME_set_pc); |
| 37 |
break; |
| 38 |
case 'y': |
| 39 |
IO_put_string(ACME_po_byte); |
| 40 |
flags |= FLAG_INSERT_SPACE; |
| 41 |
break; |
| 42 |
default: |
| 43 |
complain('b', second); |
| 44 |
} |
| 45 |
return flags; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
static int process_po_e(char second) |
| 51 |
{ |
| 52 |
int flags = 0; |
| 53 |
|
| 54 |
switch (second) { |
| 55 |
case 'i': |
| 56 |
IO_put_string(ACME_endif); |
| 57 |
break; |
| 58 |
case 'l': |
| 59 |
IO_put_string(ACME_else); |
| 60 |
break; |
| 61 |
case 'n': |
| 62 |
IO_put_string(ACME_po_eof); |
| 63 |
flags |= FLAG_INSERT_SPACE; |
| 64 |
break; |
| 65 |
case 'q': |
| 66 |
break; |
| 67 |
default: |
| 68 |
complain('e', second); |
| 69 |
} |
| 70 |
return flags; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
static int process_po_t(char second) |
| 76 |
{ |
| 77 |
int flags = 0; |
| 78 |
|
| 79 |
switch (second) { |
| 80 |
case 'x': |
| 81 |
IO_put_string(ACME_po_pet); |
| 82 |
flags |= FLAG_INSERT_SPACE; |
| 83 |
break; |
| 84 |
case 's': |
| 85 |
IO_put_string(ACME_po_scr); |
| 86 |
flags |= FLAG_INSERT_SPACE; |
| 87 |
break; |
| 88 |
default: |
| 89 |
complain('t', second); |
| 90 |
} |
| 91 |
return flags; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
#define ARE(a, b) ((first == a) && (second == b)) |
| 96 |
|
| 97 |
static int process_pseudo_opcode(void) |
| 98 |
{ |
| 99 |
int first, |
| 100 |
second; |
| 101 |
|
| 102 |
|
| 103 |
first = PET2ISO(IO_get_byte()); |
| 104 |
if ((first == SPACE) || (first == ';') || (first == '\0')) { |
| 105 |
complain(first, '\0'); |
| 106 |
return 0; |
| 107 |
} |
| 108 |
|
| 109 |
second = PET2ISO(IO_get_byte()); |
| 110 |
if ((second == SPACE) || (second == ';') || (second == '\0')) { |
| 111 |
complain(first, second); |
| 112 |
return 0; |
| 113 |
} |
| 114 |
IO_get_byte(); |
| 115 |
|
| 116 |
if (first == 'b') { |
| 117 |
process_po_b(second); |
| 118 |
return FLAG_INSERT_SPACE; |
| 119 |
} |
| 120 |
if (first == 'e') |
| 121 |
return process_po_e(second); |
| 122 |
|
| 123 |
if (first == 't') |
| 124 |
return process_po_t(second); |
| 125 |
|
| 126 |
if (ARE('.', '.')) { |
| 127 |
IO_put_string(ACME_macro_call); |
| 128 |
return FLAG_INSERT_SPACE | FLAG_SKIP_OPENING; |
| 129 |
} |
| 130 |
if (ARE('m', 'a')) { |
| 131 |
IO_put_string(ACME_po_macro); |
| 132 |
return FLAG_INSERT_SPACE | FLAG_SKIP_OPENING | FLAG_ADD_LEFT_BRACE; |
| 133 |
} |
| 134 |
if (ARE('o', 'b')) { |
| 135 |
IO_put_string(ACME_po_to); |
| 136 |
return FLAG_INSERT_SPACE | FLAG_ADD_CBM; |
| 137 |
} |
| 138 |
if (ARE('s', 'y')) { |
| 139 |
IO_put_string(ACME_po_sl); |
| 140 |
IO_put_string("\"symboldump.txt\";"); |
| 141 |
return 0; |
| 142 |
} |
| 143 |
if (ARE('i', 'f')) { |
| 144 |
IO_put_string(ACME_po_if); |
| 145 |
return FLAG_INSERT_SPACE | FLAG_ADD_LEFT_BRACE; |
| 146 |
} |
| 147 |
if (ARE('g', 'l')) |
| 148 |
return 0; |
| 149 |
|
| 150 |
if (ARE('a', 'p')) |
| 151 |
IO_put_string(ACME_po_source); |
| 152 |
else if (ARE('r', 't')) |
| 153 |
IO_put_string(ACME_endmacro); |
| 154 |
else if (ARE('w', 'o')) |
| 155 |
IO_put_string(ACME_po_word); |
| 156 |
else |
| 157 |
complain(first, second); |
| 158 |
return FLAG_INSERT_SPACE; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
static void real_opcode(void) |
| 164 |
{ |
| 165 |
IO_put_byte(PET2ISO(GotByte)); |
| 166 |
IO_get_byte(); |
| 167 |
if ((GotByte == SPACE) || (GotByte == ';') || (GotByte == '\0')) |
| 168 |
return; |
| 169 |
|
| 170 |
IO_put_byte(PET2ISO(GotByte)); |
| 171 |
IO_get_byte(); |
| 172 |
if ((GotByte == SPACE) || (GotByte == ';') || (GotByte == '\0')) |
| 173 |
return; |
| 174 |
|
| 175 |
IO_put_byte(PET2ISO(GotByte)); |
| 176 |
IO_get_byte(); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
void hypra_main(void) |
| 182 |
{ |
| 183 |
int indent; |
| 184 |
|
| 185 |
IO_set_input_padding(0); |
| 186 |
IO_process_load_address(); |
| 187 |
ACME_switch_to_pet(); |
| 188 |
|
| 189 |
while (!IO_reached_eof) { |
| 190 |
|
| 191 |
if (IO_get_le16() == 0) |
| 192 |
IO_put_string("; ToACME: Found BASIC end marker.\n"); |
| 193 |
IO_get_le16(); |
| 194 |
|
| 195 |
IO_get_byte(); |
| 196 |
indent = 0; |
| 197 |
if ((GotByte != SPACE) && (GotByte != ';') && (GotByte != '\0')) |
| 198 |
indent = GigaHypra_label_definition(); |
| 199 |
|
| 200 |
while (GotByte == SPACE) |
| 201 |
IO_get_byte(); |
| 202 |
|
| 203 |
if ((GotByte != ';') && (GotByte != '\0')) { |
| 204 |
GigaHypra_indent(indent); |
| 205 |
|
| 206 |
if (GotByte == '.') { |
| 207 |
GigaHypra_argument(process_pseudo_opcode()); |
| 208 |
} else { |
| 209 |
real_opcode(); |
| 210 |
GigaHypra_argument(FLAG_INSERT_SPACE); |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
if (GotByte == ';') |
| 215 |
GigaHypra_comment(); |
| 216 |
|
| 217 |
IO_put_byte('\n'); |
| 218 |
} |
| 219 |
} |