Debian Codegraph @

contrib/toacme/src/giga.c

raw symbols SCIP
1 // ToACME - converts other source codes to ACME format.
2 // Copyright (C) 1999-2006 Marco Baye
3 // Have a look at "main.c" for further info
4 //
5 // "GigaAss" stuff
6
7 #include <stdio.h>
8 #include "config.h"
9 #include "acme.h"
10 #include "gighyp.h"
11 #include "mnemo.h"
12 #include "io.h"
13 #include "pet2iso.h"
14
15
16 // constants
17
18 // token-to-(pseudo)opcode conversion table (FIXME)
19 const char *giga_token[] = {
20 "FIXME-CALL", // $a0 .CALL
21 ACME_po_macro, // $a1 .MACRO (see MACRO_DEF_TOKEN below)
22 ACME_endmacro, // $a2 .ENDMACRO
23 NULL, // $a3 .GLOBAL (ACME does not need a pseudo
24 NULL, // $a4 .EQUATE opcode for label definitions)
25 // these are indented in the output file
26 ACME_po_byte, // $a5 .BYTE
27 ACME_po_word, // $a6 .WORD
28 ACME_po_fill, // $a7 .DS
29 ACME_po_pet, // $a8 .TEXT (see MACRO_TEXT below)
30 ACME_po_to, // $a9 .OBJECT (see MACRO_OUTFILE below)
31 ACME_set_pc, // $aa .BASE
32 "FIXME-CODE", // $ab .CODE
33 "FIXME-ON", // $ac .ON
34 "FIXME-GOTO", // $ad .GOTO
35 ACME_po_if, // $ae .IF
36 ACME_else, // $af .ELSE
37 ACME_endif, // $b0 .ENDIF
38 ACME_po_sl, // $b1 .SYMBOLS
39 "FIXME-LISTING", // $b2 .LISTING
40 ACME_po_eof, // $b3 .END
41 "FIXME-STOP", // $b4 .STOP
42 "FIXME-PAGE", // $b5 .PAGE
43 "FIXME-NOCODE", // $b6 .NOCODE
44 "FIXME-START", // $b7 .START
45 "FIXME-NOEXP", // $b8 .NOEXP
46 "FIXME-$b9", // $b9
47 "FIXME-$ba", // $ba
48 "FIXME-$bb", // $bb
49 "FIXME-$bc", // $bc
50 "FIXME-$bd", // $bd
51 "FIXME-$be", // $be
52 "FIXME-$bf", // $bf
53 // these are indented in the output file
54 MnemonicCPX, // $c0
55 MnemonicCPY, // $c1
56 MnemonicLDX, // $c2
57 MnemonicLDY, // $c3
58 MnemonicCMP, // $c4
59 MnemonicADC, // $c5
60 MnemonicAND, // $c6
61 MnemonicDEC, // $c7
62 MnemonicEOR, // $c8
63 MnemonicINC, // $c9
64 MnemonicLDA, // $ca
65 MnemonicASL, // $cb
66 MnemonicBIT, // $cc
67 MnemonicLSR, // $cd
68 MnemonicORA, // $ce
69 MnemonicROL, // $cf
70 MnemonicROR, // $d0
71 MnemonicSBC, // $d1
72 MnemonicSTA, // $d2
73 MnemonicSTX, // $d3
74 MnemonicSTY, // $d4
75 MnemonicJMP, // $d5
76 MnemonicJSR, // $d6
77 MnemonicTXA, // $d7
78 MnemonicTAX, // $d8
79 MnemonicTYA, // $d9
80 MnemonicTAY, // $da
81 MnemonicTSX, // $db
82 MnemonicTXS, // $dc
83 MnemonicPHP, // $dd
84 MnemonicPLP, // $de
85 MnemonicPHA, // $df
86 MnemonicPLA, // $e0
87 MnemonicBRK, // $e1
88 MnemonicRTI, // $e2
89 MnemonicRTS, // $e3
90 MnemonicNOP, // $e4
91 MnemonicCLC, // $e5
92 MnemonicSEC, // $e6
93 MnemonicCLI, // $e7
94 MnemonicSEI, // $e8
95 MnemonicCLV, // $e9
96 MnemonicCLD, // $ea
97 MnemonicSED, // $eb
98 MnemonicDEY, // $ec
99 MnemonicINY, // $ed
100 MnemonicDEX, // $ee
101 MnemonicINX, // $ef
102 MnemonicBPL, // $f0
103 MnemonicBMI, // $f1
104 MnemonicBVC, // $f2
105 MnemonicBVS, // $f3
106 MnemonicBCC, // $f4
107 MnemonicBCS, // $f5
108 MnemonicBNE, // $f6
109 MnemonicBEQ, // $f7
110 "FIXME-$f8", // $f8
111 "FIXME-$f9", // $f9
112 "FIXME-$fa", // $fa
113 "FIXME-$fb", // $fb
114 "FIXME-$fc", // $fc
115 "FIXME-$fd", // $fd
116 "FIXME-$fe", // $fe
117 "FIXME-$ff", // $ff
118 };
119
120
121 // functions
122
123 // I don't know whether it's correct, but I had to start somewhere
124 #define FIRST_TOKEN 0xa0
125 #define MACRO_DEF_TOKEN 0xa1 // ugly kluge to add '{' at end of statement
126 #define MACRO_TEXT 0xa8 // ugly kluge for giga string specialties
127 #define MACRO_OUTFILE 0xa9 // ugly kluge for adding outfile format
128 // process opcode or pseudo opcode (tokenized)
129 static int process_tokenized(void)
130 {
131 const char *token;
132 int flags = 0;
133
134 if (GotByte < FIRST_TOKEN) {
135 // macro call?
136 IO_put_byte('+'); // add macro call character
137 // fprintf(global_output_stream, "small value:$%x", GotByte);
138 } else {
139 switch (GotByte) {
140 case MACRO_DEF_TOKEN:
141 flags |= FLAG_ADD_LEFT_BRACE;
142 break;
143 case MACRO_TEXT:
144 flags |= FLAG_ADD_ZERO | FLAG_CHANGE_LEFTARROW;
145 break;
146 case MACRO_OUTFILE:
147 flags |= FLAG_ADD_CBM;
148 }
149 flags |= FLAG_INSERT_SPACE;
150 token = giga_token[GotByte - FIRST_TOKEN];
151 if (token != NULL)
152 IO_put_string(token);
153 IO_get_byte();
154 }
155 return flags;
156 }
157
158
159 // When tokens are known, maybe use the PseudoOpcode function from hypra?
160 // ...for now deleted
161 // [...]
162
163 // main routine for GigaAss conversion
164 void giga_main(void)
165 {
166 int indent;
167
168 IO_set_input_padding(0);
169 IO_process_load_address();
170 ACME_switch_to_pet();
171 // loop: once for every line in the file
172 while (!IO_reached_eof) {
173 // skip link pointer (if it's zero, report as end marker)
174 if (IO_get_le16() == 0)
175 IO_put_string("; ToACME: Found BASIC end marker.\n");
176 IO_get_le16(); // skip line number
177 // process line
178 IO_get_byte();
179 if ((GotByte == SPACE) || (GotByte == ';')
180 || (GotByte == '\0') || (GotByte > 0x7f))
181 indent = 0;
182 else
183 indent = GigaHypra_label_definition();
184 // skip spaces
185 while (GotByte == SPACE)
186 IO_get_byte();
187 // if there is an opcode, process it
188 if ((GotByte != ';') && (GotByte != '\0')) {
189 GigaHypra_indent(indent);
190 GigaHypra_argument(process_tokenized());
191 }
192 // skip comment, if there is one
193 if (GotByte == ';')
194 GigaHypra_comment();
195 // end of line
196 IO_put_byte('\n');
197 }
198 }