comparison lwasm/cycle.c @ 378:b0ec15f95563

Add missed file in 35d4213e6657
author William Astle <lost@l-w.ca>
date Mon, 13 Jul 2015 20:56:48 -0600
parents
children 4fd16faa4d93
comparison
equal deleted inserted replaced
377:67373a053c49 378:b0ec15f95563
1 /*
2 cycle.c
3
4 Copyright (c) 2015 Erik Gavriluk
5 Dual-licensed BSD 3-CLAUSE and GPL as per below.
6 Thanks to John Kowalksi for cycle count verification.
7
8 This file is part of LWTOOLS.
9
10 LWTOOLS is free software: you can redistribute it and/or modify it under the
11 terms of the GNU General Public License as published by the Free Software
12 Foundation, either version 3 of the License, or (at your option) any later
13 version.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 more details.
19
20 You should have received a copy of the GNU General Public License along with
21 this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #include "lwasm.h"
25
26 typedef struct
27 {
28 int opc;
29 int cycles_6809;
30 int cycles_6309;
31 cycle_flags flags;
32 } cycletable_t;
33
34 static cycletable_t cycletable[] =
35 {
36 { 0x3a, 3, 1, 0 }, // ABX
37
38 { 0x89, 2, 2, 0 }, // ADCA
39 { 0x99, 4, 3, 0 },
40 { 0xa9, 4, 4, CYCLE_ADJ },
41 { 0xb9, 5, 4, 0 },
42
43 { 0xc9, 2, 2, 0 }, // ADCB
44 { 0xd9, 4, 3, 0 },
45 { 0xe9, 4, 4, CYCLE_ADJ },
46 { 0xf9, 5, 4, 0 },
47
48 { 0x1089, 5, 4, 0 }, // ADCD
49 { 0x1099, 7, 5, 0 },
50 { 0x10a9, 7, 6, CYCLE_ADJ },
51 { 0x10b9, 8, 6, 0 },
52
53 { 0x8b, 2, 2, 0 }, // ADDA
54 { 0x9b, 4, 3, 0 },
55 { 0xab, 4, 4, CYCLE_ADJ },
56 { 0xbb, 5, 4, 0 },
57
58 { 0xcb, 2, 2, 0 }, // ADDB
59 { 0xdb, 4, 3, 0 },
60 { 0xeb, 4, 4, CYCLE_ADJ },
61 { 0xfb, 5, 4, 0 },
62
63 { 0xc3, 4, 3, 0 }, // ADDD
64 { 0xd3, 6, 4, 0 },
65 { 0xe3, 6, 5, CYCLE_ADJ },
66 { 0xf3, 7, 5, 0 },
67
68 { 0x118b, 3, 3, 0 }, // ADDE
69 { 0x119b, 5, 4, 0 },
70 { 0x11ab, 5, 5, CYCLE_ADJ },
71 { 0x11bb, 6, 5, 0 },
72
73 { 0x11cb, 3, 3, 0 }, // ADDF
74 { 0x11db, 5, 4, 0 },
75 { 0x11eb, 5, 5, CYCLE_ADJ },
76 { 0x11fb, 6, 5, 0 },
77
78 { 0x1031, 4, 4, 0 }, // ADCR
79 { 0x1030, 4, 4, 0 }, // ADDR
80 { 0x1034, 4, 4, 0 }, // ANDR
81 { 0x1037, 4, 4, 0 }, // CMPR
82 { 0x1036, 4, 4, 0 }, // EORR
83 { 0x1035, 4, 4, 0 }, // ORR
84 { 0x1033, 4, 4, 0 }, // SBCR
85 { 0x1032, 4, 4, 0 }, // SUBR
86
87 { 0x108b, 5, 4, 0 }, // ADDW
88 { 0x109b, 7, 5, 0 },
89 { 0x10ab, 7, 6, CYCLE_ADJ },
90 { 0x10bb, 8, 6, 0 },
91
92 { 0x02, 6, 6, 0 }, // AIM
93 { 0x62, 7, 7, CYCLE_ADJ },
94 { 0x72, 7, 7, 0 },
95
96 { 0x84, 2, 2, 0 }, // ANDA
97 { 0x94, 4, 3, 0 },
98 { 0xa4, 4, 4, CYCLE_ADJ },
99 { 0xb4, 5, 4, 0 },
100
101 { 0xc4, 2, 2, 0 }, // ANDB
102 { 0xd4, 4, 3, 0 },
103 { 0xe4, 4, 4, CYCLE_ADJ },
104 { 0xf4, 5, 4, 0 },
105
106 { 0x1c, 3, 2, 0 }, // ANDCC
107
108 { 0x1084, 5, 4, 0 }, // ANDD
109 { 0x1094, 7, 5, 0 },
110 { 0x10a4, 7, 6, CYCLE_ADJ },
111 { 0x10b4, 8, 6, 0 },
112
113 { 0x48, 2, 1, 0 }, // ASL
114 { 0x58, 2, 1, 0 },
115 { 0x1048, 3, 2, 0 },
116 { 0x08, 6, 5, 0 },
117 { 0x68, 6, 6, CYCLE_ADJ },
118 { 0x78, 7, 6, 0 },
119
120 { 0x47, 2, 1, 0 }, // ASR
121 { 0x57, 2, 1, 0 },
122 { 0x1047, 3, 2, 0 },
123 { 0x07, 6, 6, 0 },
124 { 0x67, 6, 6, CYCLE_ADJ },
125 { 0x77, 7, 6, 0 },
126
127 { 0x1130, 7, 6, 0 }, // BAND
128 { 0x1131, 7, 6, 0 }, // BIAND
129 { 0x1132, 7, 6, 0 }, // BOR
130 { 0x1133, 7, 6, 0 }, // BIOR
131 { 0x1134, 7, 6, 0 }, // BEOR
132 { 0x1135, 7, 6, 0 }, // BIEOR
133
134 { 0x85, 2, 2, 0 }, // BITA
135 { 0x95, 4, 3, 0 },
136 { 0xa5, 4, 4, CYCLE_ADJ },
137 { 0xb5, 5, 4, 0 },
138
139 { 0xc5, 2, 2, 0 }, // BITB
140 { 0xd5, 4, 3, 0 },
141 { 0xe5, 4, 4, CYCLE_ADJ },
142 { 0xf5, 5, 4, 0 },
143
144 { 0x1085, 5, 4, 0 }, // BITD
145 { 0x1095, 7, 5, 0 },
146 { 0x10a5, 7, 6, CYCLE_ADJ },
147 { 0x10b5, 8, 6, 0 },
148
149 { 0x113c, 4, 4, 0 }, // BITMD
150
151 { 0x20, 3, 3, 0 }, // BRA
152 { 0x21, 3, 3, 0 },
153 { 0x22, 3, 3, 0 },
154 { 0x23, 3, 3, 0 },
155 { 0x24, 3, 3, 0 },
156 { 0x25, 3, 3, 0 },
157 { 0x26, 3, 3, 0 },
158 { 0x27, 3, 3, 0 },
159 { 0x28, 3, 3, 0 },
160 { 0x29, 3, 3, 0 },
161 { 0x2a, 3, 3, 0 },
162 { 0x2b, 3, 3, 0 },
163 { 0x2c, 3, 3, 0 },
164 { 0x2d, 3, 3, 0 },
165 { 0x2e, 3, 3, 0 },
166 { 0x2f, 3, 3, 0 },
167
168 { 0x8d, 7, 6, 0 }, // BSR
169
170 { 0x4f, 2, 1, 0 }, // CLR
171 { 0x5f, 2, 1, 0 },
172 { 0x104f, 3, 2, 0 },
173 { 0x114f, 3, 2, 0 },
174 { 0x115f, 3, 2, 0 },
175 { 0x105f, 3, 2, 0 },
176 { 0x0f, 6, 5, 0 },
177 { 0x6f, 6, 6, CYCLE_ADJ },
178 { 0x7f, 7, 6, 0 },
179
180 { 0x81, 2, 2, 0 }, // CMPA
181 { 0x91, 4, 3, 0 },
182 { 0xa1, 4, 4, CYCLE_ADJ },
183 { 0xb1, 5, 4, 0 },
184
185 { 0xc1, 2, 2, 0 }, // CMPB
186 { 0xd1, 4, 3, 0 },
187 { 0xe1, 4, 4, CYCLE_ADJ },
188 { 0xf1, 5, 4, 0 },
189
190 { 0x1083, 5, 4, 0 }, // CMPD
191 { 0x1093, 7, 5, 0 },
192 { 0x10a3, 7, 6, CYCLE_ADJ },
193 { 0x10b3, 8, 6, 0 },
194
195 { 0x1081, 3, 3, 0 }, // CMPE
196 { 0x1091, 5, 4, 0 },
197 { 0x10a1, 5, 5, CYCLE_ADJ },
198 { 0x10b1, 6, 5, 0 },
199
200 { 0x10c1, 3, 3, 0 }, // CMPF
201 { 0x10d1, 5, 4, 0 },
202 { 0x10e1, 5, 5, CYCLE_ADJ },
203 { 0x10f1, 6, 5, 0 },
204
205 { 0x118c, 5, 4, 0 }, // CMPS
206 { 0x119c, 7, 5, 0 },
207 { 0x11ac, 7, 6, CYCLE_ADJ },
208 { 0x11bc, 8, 6, 0 },
209
210 { 0x1183, 5, 4, 0 }, // CMPU
211 { 0x1193, 7, 5, 0 },
212 { 0x11a3, 7, 6, CYCLE_ADJ },
213 { 0x11b3, 8, 6, 0 },
214
215 { 0x1181, 5, 4, 0 }, // CMPW
216 { 0x1191, 7, 5, 0 },
217 { 0x11a1, 7, 6, CYCLE_ADJ },
218 { 0x11b1, 8, 6, 0 },
219
220 { 0x8c, 4, 3, 0 }, // CMPX
221 { 0x9c, 6, 4, 0 },
222 { 0xac, 6, 5, CYCLE_ADJ },
223 { 0xbc, 7, 5, 0 },
224
225 { 0x108c, 5, 4, 0 }, // CMPY
226 { 0x109c, 7, 5, 0 },
227 { 0x10ac, 7, 6, CYCLE_ADJ },
228 { 0x10bc, 8, 6, 0 },
229
230 { 0x43, 2, 1, 0 }, // COMA
231 { 0x53, 2, 1, 0 }, // COMB
232 { 0x1043, 3, 2, 0 }, // COMD
233 { 0x1143, 3, 2, 0 }, // COME
234 { 0x1153, 3, 2, 0 }, // COMF
235 { 0x1053, 3, 2, 0 }, // COMW
236
237 { 0x03, 6, 5, 0 }, // COM
238 { 0x63, 6, 6, CYCLE_ADJ },
239 { 0x73, 7, 6, 0 },
240
241 { 0x3c, 22, 20, 0 }, // CWAI
242
243 { 0x19, 2, 1, 0 }, // DAA
244
245 { 0x4a, 2, 1, 0 }, // DECA
246 { 0x5a, 2, 1, 0 }, // DECB
247 { 0x104a, 3, 2, 0 }, // DECD
248 { 0x114a, 3, 2, 0 }, // DECE
249 { 0x115a, 3, 2, 0 }, // DECF
250 { 0x105a, 3, 2, 0 }, // DECW
251
252 { 0x0a, 6, 5, 0 }, // DEC
253 { 0x6a, 6, 6, CYCLE_ADJ },
254 { 0x7a, 7, 6, 0 },
255
256 { 0x118d, 25, 25, 0 }, // DIVD
257 { 0x119d, 27, 26, 0 },
258 { 0x11ad, 27, 27, CYCLE_ADJ },
259 { 0x11bd, 28, 27, 0 },
260
261 { 0x118e, 34, 34, 0 }, // DIVQ
262 { 0x119e, 36, 35, 0 },
263 { 0x11ae, 36, 36, 0 },
264 { 0x11be, 37, 36, 0 },
265
266 { 0x05, 6, 6, 0 }, // EIM
267 { 0x65, 7, 7, CYCLE_ADJ },
268 { 0x75, 7, 7, 0 },
269
270 { 0x88, 2, 2, 0 }, // EORA
271 { 0x98, 4, 3, 0 },
272 { 0xa8, 4, 4, CYCLE_ADJ },
273 { 0xb8, 5, 4, 0 },
274
275 { 0xc8, 2, 2, 0 }, // EORB
276 { 0xd8, 4, 3, 0 },
277 { 0xe8, 4, 4, CYCLE_ADJ },
278 { 0xf8, 5, 4, 0 },
279
280 { 0x1088, 5, 4, 0 }, // EORD
281 { 0x1098, 7, 5, 0 },
282 { 0x10a8, 7, 6, CYCLE_ADJ },
283 { 0x10b8, 8, 6, 0 },
284
285 { 0x1e, 8, 5, 0 }, // EXG
286
287 { 0x4c, 2, 1, 0 }, // INCA
288 { 0x5c, 2, 1, 0 }, // INCB
289 { 0x104c, 3, 2, 0 }, // INCD
290 { 0x114c, 3, 2, 0 }, // INCE
291 { 0x115c, 3, 2, 0 }, // INCF
292 { 0x105c, 3, 2, 0 }, // INCW
293
294 { 0x0c, 6, 5, 0 }, // INC
295 { 0x6c, 6, 6, CYCLE_ADJ },
296 { 0x7c, 7, 6, 0 },
297
298 { 0x0e, 3, 2, 0 }, // JMP
299 { 0x6e, 3, 3, CYCLE_ADJ },
300 { 0x7e, 4, 3, 0 },
301
302 { 0x9d, 7, 6, 0 }, // JSR
303 { 0xad, 7, 6, CYCLE_ADJ },
304 { 0xbd, 8, 7, 0 },
305
306 { 0x16, 5, 4, 0 }, // LBRA
307 { 0x17, 9, 7, 0 }, // LBSR
308 { 0x1022, 5, 5, 0 }, // LBRN
309 { 0x1023, 5, 6, 0 }, // remaining long branches are estimated on 6809 only:
310 { 0x1024, 5, 6, 0 }, // 6809: 5 cycles, +1 cycle if the branch is taken
311 { 0x1025, 5, 6, 0 }, // 6309 native: always 5 cycles
312 { 0x1026, 5, 6, 0 },
313 { 0x1027, 5, 6, 0 },
314 { 0x1028, 5, 6, 0 },
315 { 0x1029, 5, 6, 0 },
316 { 0x102a, 5, 6, 0 },
317 { 0x102b, 5, 6, 0 },
318 { 0x102c, 5, 6, 0 },
319 { 0x102d, 5, 6, 0 },
320 { 0x102e, 5, 6, 0 },
321 { 0x102f, 5, 6, 0 },
322
323 { 0x86, 2, 2, 0 }, // LDA
324 { 0x96, 4, 3, 0 },
325 { 0xa6, 4, 4, CYCLE_ADJ },
326 { 0xb6, 5, 4, 0 },
327
328 { 0xc6, 2, 2, 0 }, // LDB
329 { 0xd6, 4, 3 },
330 { 0xe6, 4, 4, CYCLE_ADJ },
331 { 0xf6, 5, 4, 0 },
332
333 { 0x1136, 7, 6, 0 }, // LDBT
334
335 { 0xcc, 3, 3, 0 }, // LDD
336 { 0xdc, 5, 4, 0 },
337 { 0xec, 5, 5, CYCLE_ADJ },
338 { 0xfc, 6, 5, 0 },
339
340 { 0x1186, 3, 3, 0 }, // LDE
341 { 0x1196, 5, 4, 0 },
342 { 0x11a6, 5, 5, CYCLE_ADJ },
343 { 0x11b6, 6, 5, 0 },
344
345 { 0x11c6, 3, 3, 0 }, // LDF
346 { 0x11d6, 5, 4, 0 },
347 { 0x11e6, 5, 5, CYCLE_ADJ },
348 { 0x11f6, 6, 5, 0 },
349
350 { 0xcd, 5, 5, 0 }, // LDQ
351 { 0x10dc, 8, 7, 0 },
352 { 0x10ec, 8, 8, CYCLE_ADJ },
353 { 0x10fc, 9, 8, 0 },
354
355 { 0x10ce, 4, 4, 0 }, // LDS
356 { 0x10de, 6, 5, 0 },
357 { 0x10ee, 6, 6, CYCLE_ADJ },
358 { 0x10fe, 7, 6, 0 },
359
360 { 0xce, 3, 3, 0 }, // LDU
361 { 0xde, 5, 4, 0 },
362 { 0xee, 5, 5, CYCLE_ADJ },
363 { 0xfe, 6, 5, 0 },
364
365 { 0x1086, 4, 4, 0 }, // LDW
366 { 0x1096, 6, 5, 0 },
367 { 0x10a6, 6, 6, CYCLE_ADJ },
368 { 0x10b6, 7, 6, 0 },
369
370 { 0x8e, 3, 3, 0 }, // LDX
371 { 0x9e, 5, 4, 0 },
372 { 0xae, 5, 5, CYCLE_ADJ },
373 { 0xbe, 6, 5, 0 },
374
375 { 0x108e, 4, 4, 0 }, // LDY
376 { 0x109e, 6, 5, 0 },
377 { 0x10ae, 6, 6, CYCLE_ADJ },
378 { 0x10be, 7, 6, 0 },
379
380 { 0x113d, 5, 5, 0 }, // LDMD
381
382 { 0x30, 4, 4, CYCLE_ADJ }, // LEA
383 { 0x31, 4, 4, CYCLE_ADJ },
384 { 0x32, 4, 4, CYCLE_ADJ },
385 { 0x33, 4, 4, CYCLE_ADJ },
386
387 { 0x44, 2, 1, 0 }, // LSRA
388 { 0x54, 2, 1, 0 }, // LSRB
389 { 0x1044, 3, 2, 0 }, // LSRD
390 { 0x1054, 3, 2, 0 }, // LSRW
391
392 { 0x04, 6, 5, 0 }, // LSR
393 { 0x64, 6, 6, CYCLE_ADJ },
394 { 0x74, 7, 6, 0 },
395
396 { 0x3d, 11, 10, 0 }, // MUL
397
398 { 0x118f, 28, 28, 0 }, // MULD
399 { 0x119f, 30, 29, 0 },
400 { 0x11af, 30, 30, CYCLE_ADJ },
401 { 0x11bf, 31, 30, 0 },
402
403 { 0x40, 2, 1, 0 }, // NEGA
404 { 0x50, 2, 1, 0 }, // NEGB
405 { 0x1040, 3, 2, 0 }, // NEGD
406
407 { 0x00, 6, 5, 0 }, // NEG
408 { 0x60, 6, 6, CYCLE_ADJ },
409 { 0x70, 7, 6, 0 },
410
411 { 0x12, 2, 1, 0 }, // NOP
412
413 { 0x01, 6, 6, 0 }, // OIM
414 { 0x61, 7, 7, CYCLE_ADJ },
415 { 0x71, 7, 7, 0 },
416
417 { 0x8a, 2, 2, 0 }, // ORA
418 { 0x9a, 4, 3, 0 },
419 { 0xaa, 4, 4, CYCLE_ADJ },
420 { 0xba, 5, 4, 0 },
421
422 { 0xca, 2, 2, 0 }, // ORB
423 { 0xda, 4, 3, 0 },
424 { 0xea, 4, 4, CYCLE_ADJ },
425 { 0xfa, 5, 4, 0 },
426
427 { 0x1a, 3, 2, 0 }, // ORCC
428
429 { 0x108a, 5, 4, 0 }, // ORD
430 { 0x109a, 7, 5, 0 },
431 { 0x10aa, 7, 6, CYCLE_ADJ },
432 { 0x10ba, 8, 6, 0 },
433
434 { 0x34, 5, 4, CYCLE_ADJ }, // PSHS
435 { 0x36, 5, 4, CYCLE_ADJ }, // PSHU
436 { 0x35, 5, 4, CYCLE_ADJ }, // PULS
437 { 0x37, 5, 4, CYCLE_ADJ }, // PULU
438 { 0x1038, 6, 6, 0 }, // PSHSW
439 { 0x103a, 6, 6, 0 }, // PSHUW
440 { 0x1039, 6, 6, 0 }, // PULSW
441 { 0x103b, 6, 6, 0 }, // PULUW
442
443 { 0x49, 2, 1, 0 }, // ROLA
444 { 0x59, 2, 1, 0 }, // ROLB
445 { 0x1049, 3, 2, 0 }, // ROLD
446 { 0x1059, 3, 2, 0 }, // ROLW
447
448 { 0x09, 6, 5, 0 }, // ROL
449 { 0x69, 6, 6, CYCLE_ADJ },
450 { 0x79, 7, 6, 0 },
451
452 { 0x46, 2, 1, 0 }, // RORA
453 { 0x56, 2, 1, 0 }, // RORB
454 { 0x1046, 3, 2, 0 }, // RORD
455 { 0x1056, 3, 2, 0 }, // RORW
456
457 { 0x06, 6, 5, 0 }, // ROR
458 { 0x66, 6, 6, CYCLE_ADJ },
459 { 0x76, 7, 6, 0 },
460
461 { 0x3b, 6, 17, CYCLE_ESTIMATED }, // RTI
462
463 { 0x39, 5, 4, 0 }, // RTS
464
465 { 0x82, 2, 2, 0 }, // SBCA
466 { 0x92, 4, 3, 0 },
467 { 0xa2, 4, 4, CYCLE_ADJ },
468 { 0xb2, 5, 4, 0 },
469
470 { 0xc2, 2, 2, 0 }, // SBCB
471 { 0xd2, 4, 3, 0 },
472 { 0xe2, 4, 4, CYCLE_ADJ },
473 { 0xf2, 5, 4, 0 },
474
475 { 0x1082, 5, 4, 0 }, // SBCD
476 { 0x1092, 7, 5, 0 },
477 { 0x10a2, 7, 6, CYCLE_ADJ },
478 { 0x10b2, 8, 6, 0 },
479
480 { 0x1d, 2, 1, 0 }, // SEX
481 { 0x14, 4, 4, 0 }, // SEXW
482
483 { 0x97, 4, 3, 0 }, // STA
484 { 0xa7, 4, 4, CYCLE_ADJ },
485 { 0xb7, 5, 4, 0 },
486
487 { 0xd7, 4, 3, 0 }, // STB
488 { 0xe7, 4, 4, CYCLE_ADJ },
489 { 0xf7, 5, 4, 0 },
490
491 { 0x1137, 8, 7, 0 }, // STBT
492
493 { 0xdd, 5, 4, 0 }, // STD
494 { 0xed, 5, 5, CYCLE_ADJ },
495 { 0xfd, 6, 5, 0 },
496
497 { 0x1197, 5, 4, 0 }, // STE
498 { 0x11a7, 5, 5, CYCLE_ADJ },
499 { 0x11b7, 6, 5, 0 },
500
501 { 0x11d7, 5, 4, 0 }, // STF
502 { 0x11e7, 5, 5, CYCLE_ADJ },
503 { 0x11f7, 6, 5, 0 },
504
505 { 0x10dd, 8, 7, 0 }, // STQ
506 { 0x10ed, 8, 8, CYCLE_ADJ },
507 { 0x10fd, 9, 8, 0 },
508
509 { 0x10df, 6, 5, 0 }, // STS
510 { 0x10ef, 6, 6, CYCLE_ADJ },
511 { 0x10ff, 7, 6, 0 },
512
513 { 0xdf, 5, 4, 0 }, // STU
514 { 0xef, 5, 5, CYCLE_ADJ },
515 { 0xff, 6, 5, 0 },
516
517 { 0x1097, 6, 5, 0 }, // STW
518 { 0x10a7, 6, 6, CYCLE_ADJ },
519 { 0x10b7, 7, 6, 0 },
520
521 { 0x9f, 5, 4, 0 }, // STX
522 { 0xaf, 5, 5, CYCLE_ADJ },
523 { 0xbf, 6, 5, 0 },
524
525 { 0x109f, 6, 5, 0 }, // STY
526 { 0x10af, 6, 6, CYCLE_ADJ },
527 { 0x10bf, 7, 6, 0 },
528
529 { 0x80, 2, 2, 0 }, // SUBA
530 { 0x90, 4, 3, 0 },
531 { 0xa0, 4, 4, CYCLE_ADJ },
532 { 0xb0, 5, 4, 0 },
533
534 { 0xc0, 2, 2, 0 }, // SUBB
535 { 0xd0, 4, 3, 0 },
536 { 0xe0, 4, 4, CYCLE_ADJ },
537 { 0xf0, 5, 4, 0 },
538
539 { 0x83, 4, 3, 0 }, // SUBD
540 { 0x93, 6, 4, 0 },
541 { 0xa3, 6, 5, CYCLE_ADJ },
542 { 0xb3, 7, 5, 0 },
543
544 { 0x1180, 3, 3, 0 }, // SUBE
545 { 0x1190, 5, 4, 0 },
546 { 0x11a0, 5, 5, CYCLE_ADJ },
547 { 0x11b0, 6, 5, 0 },
548
549 { 0x11c0, 3, 3, 0 }, // SUBF
550 { 0x11d0, 5, 4, 0 },
551 { 0x11e0, 5, 5, CYCLE_ADJ },
552 { 0x11f0, 6, 5, 0 },
553
554 { 0x1080, 5, 4, 0 }, // SUBW
555 { 0x1090, 7, 5, 0 },
556 { 0x10a0, 7, 6, CYCLE_ADJ },
557 { 0x10b0, 8, 6, 0 },
558
559 { 0x3f, 19, 21, 0 }, // SWI
560 { 0x103f, 20, 22, 0 }, // SWI2
561 { 0x113f, 20, 22, 0 }, // SWI3
562
563 { 0x13, 2, 1, CYCLE_ESTIMATED }, // SYNC
564
565 { 0x1f, 6, 4, 0 }, // TFR
566
567 { 0x0b, 6, 6, CYCLE_ESTIMATED }, // TIM
568 { 0x6b, 7, 7, CYCLE_ADJ | CYCLE_ESTIMATED },
569 { 0x7b, 5, 5, CYCLE_ESTIMATED },
570
571 { 0x1138, 6, 6, CYCLE_ESTIMATED }, // TFM
572 { 0x1139, 6, 6, CYCLE_ESTIMATED },
573 { 0x113a, 6, 6, CYCLE_ESTIMATED },
574 { 0x113b, 6, 6, CYCLE_ESTIMATED },
575
576 { 0x4d, 2, 1, 0 }, // TSTA
577 { 0x5d, 2, 1, 0 }, // TSTB
578 { 0x104d, 3, 2, 0 }, // TSTD
579 { 0x114d, 3, 2, 0 }, // TSTE
580 { 0x115d, 3, 2, 0 }, // TSTF
581 { 0x105d, 3, 2, 0 }, // TSTW
582
583 { 0x0d, 6, 4, 0 }, // TST
584 { 0x6d, 6, 5, CYCLE_ADJ },
585 { 0x7d, 7, 5, 0 },
586
587 { -1, -1 }
588 };
589
590 typedef struct
591 {
592 int cycles_6809_indexed;
593 int cycles_6309_indexed;
594 int cycles_6809_indirect;
595 int cycles_6309_indirect;
596 } indtab_t;
597
598 static indtab_t indtab[] =
599 {
600 { 2, 1, -1, -1, }, // 0000 ,R+
601 { 3, 2, 6, 6, }, // 0001 ,R++ [,R++]
602 { 2, 1, -1, -1, }, // 0010 ,-R
603 { 3, 2, 6, 6, }, // 0011 ,--R [,--R]
604 { 0, 0, 3, 3, }, // 0100 ,R [,R]
605 { 1, 1, 4, 4, }, // 0101 B,R [B,R]
606 { 1, 1, 4, 4, }, // 0110 A,R [A,R]
607 { 1, 1, 1, 1, }, // 0111 E,R [E,R]
608 { 1, 1, 4, 4, }, // 1000 n,R [n,R]
609 { 4, 3, 7, 7, }, // 1001 n,R [n,R] (16 bit)
610 { 1, 1, 1, 1, }, // 1010 F,R [F,R]
611 { 4, 2, 4, 4, }, // 1011 D,R [D,R]
612 { 1, 1, 4, 4, }, // 1100 n,PC [n,PC]
613 { 5, 3, 8, 8, }, // 1101 n,PC [n,PC] (16 bit)
614 { 4, 1, 4, 4, }, // 1110 W,R [W,R]
615 { -1, -1, 5, 5, }, // 1111 [n] (16 bit)
616 };
617
618 /* calculates additional ticks from post byte in both indexed and indirect modes */
619 int lwasm_cycle_calc_ind(line_t *cl)
620 {
621 int pb = cl->pb;
622
623 if ((pb & 0x80) == 0) /* 5 bit offset */
624 return 1;
625
626 if (pb & 0x10) /* indirect */
627 return CURPRAGMA(cl, PRAGMA_6809) ? indtab[pb & 0xf].cycles_6809_indirect : indtab[pb & 0xf].cycles_6309_indirect;
628 else
629 return CURPRAGMA(cl, PRAGMA_6809) ? indtab[pb & 0xf].cycles_6809_indexed : indtab[pb & 0xf].cycles_6309_indexed;
630 }
631
632 /* calculate additional ticks from post byte in rlist (PSHS A,B,X...) */
633 int lwasm_cycle_calc_rlist(line_t *cl)
634 {
635 int i, cycles = 0;
636
637 for (i = 0; i < 8; i++)
638 {
639 // 1 cycle for 8 bit regs CC-DP (bits 0-3)
640 // otherwise 2
641 if (cl->pb & 1 << i)
642 cycles += (i <= 3) ? 1 : 2;
643 }
644
645 return cycles;
646 }
647
648 void lwasm_cycle_update_count(line_t *cl, int opc)
649 {
650 int i;
651 for (i = 0; 1; i++)
652 {
653 if (cycletable[i].opc == -1) return;
654
655 if (cycletable[i].opc == opc)
656 {
657 cl->cycle_base = CURPRAGMA(cl, PRAGMA_6809) ? cycletable[i].cycles_6809 : cycletable[i].cycles_6309;
658 cl->cycle_flags = cycletable[i].flags;
659 cl->cycle_adj = 0;
660
661 // long branches are estimated on 6809
662 if (CURPRAGMA(cl, PRAGMA_6809) && (opc >= 0x1023 && opc <= 0x102f))
663 cl->cycle_flags |= CYCLE_ESTIMATED;
664
665 return;
666 }
667 }
668 }