1 #include "../copyright"
2 
3 #include "fxemu.h"
4 #include "fxinst.h"
5 #include <string.h>
6 
7 #include <retro_inline.h>
8 
9 extern FxRegs_s GSU;
10 
11 /* Codes used:
12  *
13  * rn   = a GSU register (r0 - r15)
14  * #n   = 4 bit immediate value
15  * #pp  = 8 bit immediate value
16  * (yy) = 8 bit word address (0x0000 - 0x01fe)
17  * #xx  = 16 bit immediate value
18  * (xx) = 16 bit address (0x0000 - 0xffff)
19  */
20 
21 /* 00 - stop - stop GSU execution (and maybe generate an IRQ) */
fx_stop(void)22 static INLINE void fx_stop(void)
23 {
24    CF(G);
25    GSU.vCounter = 0;
26    GSU.vInstCount = GSU.vCounter;
27 
28    /* Check if we need to generate an IRQ */
29    if (!(GSU.pvRegisters[GSU_CFGR] & 0x80))
30       SF(IRQ);
31 
32    GSU.vPlotOptionReg = 0;
33    GSU.vPipe = 1;
34    CLRFLAGS;
35    R15++;
36 }
37 
38 /* 01 - nop - no operation */
fx_nop(void)39 static INLINE void fx_nop(void)
40 {
41    CLRFLAGS;
42    R15++;
43 }
44 
45 extern void fx_flushCache(void);
46 
47 /* 02 - cache - reintialize GSU cache */
fx_cache(void)48 static INLINE void fx_cache(void)
49 {
50    uint32_t c = R15 & 0xfff0;
51    if (GSU.vCacheBaseReg != c || !GSU.bCacheActive)
52    {
53       fx_flushCache();
54       GSU.vCacheBaseReg = c;
55       GSU.bCacheActive = true;
56    }
57    CLRFLAGS;
58    R15++;
59 }
60 
61 /* 03 - lsr - logic shift right */
fx_lsr(void)62 static INLINE void fx_lsr(void)
63 {
64    uint32_t v;
65    GSU.vCarry = SREG & 1;
66    v = USEX16(SREG) >> 1;
67    R15++;
68    DREG = v;
69    GSU.vSign = v;
70    GSU.vZero = v;
71    TESTR14;
72    CLRFLAGS;
73 }
74 
75 /* 04 - rol - rotate left */
fx_rol(void)76 static INLINE void fx_rol(void)
77 {
78    uint32_t v = USEX16((SREG << 1) + GSU.vCarry);
79    GSU.vCarry = (SREG >> 15) & 1;
80    R15++;
81    DREG = v;
82    GSU.vSign = v;
83    GSU.vZero = v;
84    TESTR14;
85    CLRFLAGS;
86 }
87 
88 /* 05 - bra - branch always */
fx_bra(void)89 static INLINE void fx_bra(void)
90 {
91    uint8_t v = PIPE;
92    R15++;
93    FETCHPIPE;
94    R15 += SEX8(v);
95 }
96 
97 /* Branch on condition */
98 #define BRA_COND(cond) \
99     uint8_t v = PIPE; \
100     R15++; \
101     FETCHPIPE; \
102     if (cond) \
103         R15 += SEX8(v); \
104     else \
105         R15++
106 
107 #define TEST_S (GSU.vSign & 0x8000)
108 #define TEST_Z (USEX16(GSU.vZero) == 0)
109 #define TEST_OV (GSU.vOverflow >= 0x8000 || GSU.vOverflow < -0x8000)
110 #define TEST_CY (GSU.vCarry & 1)
111 
112 /* 06 - blt - branch on less than */
fx_blt(void)113 static INLINE void fx_blt(void)
114 {
115    BRA_COND((TEST_S != 0) != (TEST_OV != 0));
116 }
117 
118 /* 07 - bge - branch on greater or equals */
fx_bge(void)119 static INLINE void fx_bge(void)
120 {
121    BRA_COND((TEST_S != 0) == (TEST_OV != 0));
122 }
123 
124 /* 08 - bne - branch on not equal */
fx_bne(void)125 static INLINE void fx_bne(void)
126 {
127    BRA_COND(!TEST_Z);
128 }
129 
130 /* 09 - beq - branch on equal */
fx_beq(void)131 static INLINE void fx_beq(void)
132 {
133    BRA_COND(TEST_Z);
134 }
135 
136 /* 0a - bpl - branch on plus */
fx_bpl(void)137 static INLINE void fx_bpl(void)
138 {
139    BRA_COND(!TEST_S);
140 }
141 
142 /* 0b - bmi - branch on minus */
fx_bmi(void)143 static INLINE void fx_bmi(void)
144 {
145    BRA_COND(TEST_S);
146 }
147 
148 /* 0c - bcc - branch on carry clear */
fx_bcc(void)149 static INLINE void fx_bcc(void)
150 {
151    BRA_COND(!TEST_CY);
152 }
153 
154 /* 0d - bcs - branch on carry set */
fx_bcs(void)155 static INLINE void fx_bcs(void)
156 {
157    BRA_COND(TEST_CY);
158 }
159 
160 /* 0e - bvc - branch on overflow clear */
fx_bvc(void)161 static INLINE void fx_bvc(void)
162 {
163    BRA_COND(!TEST_OV);
164 }
165 
166 /* 0f - bvs - branch on overflow set */
fx_bvs(void)167 static INLINE void fx_bvs(void)
168 {
169    BRA_COND(TEST_OV);
170 }
171 
172 /* 10-1f - to rn - set register n as destination register */
173 /* 10-1f(B) - move rn - move one register to another (if B flag is set) */
174 #define FX_TO(reg) \
175     if (TF(B)) \
176     { \
177         GSU.avReg[(reg)] = SREG; \
178         CLRFLAGS; \
179     } \
180     else \
181         GSU.pvDreg = &GSU.avReg[reg]; \
182     R15++
183 
184 #define FX_TO_R14(reg) \
185     if (TF(B)) \
186     { \
187         GSU.avReg[(reg)] = SREG; \
188         CLRFLAGS; \
189         READR14; \
190     } \
191     else \
192         GSU.pvDreg = &GSU.avReg[reg]; \
193     R15++
194 
195 #define FX_TO_R15(reg) \
196     if (TF(B)) \
197     { \
198         GSU.avReg[(reg)] = SREG; \
199         CLRFLAGS; \
200     } \
201     else \
202     { \
203         GSU.pvDreg = &GSU.avReg[reg]; \
204         R15++; \
205     }
206 
fx_to_r0(void)207 static INLINE void fx_to_r0(void)
208 {
209    FX_TO(0);
210 }
fx_to_r1(void)211 static INLINE void fx_to_r1(void)
212 {
213    FX_TO(1);
214 }
fx_to_r2(void)215 static INLINE void fx_to_r2(void)
216 {
217    FX_TO(2);
218 }
fx_to_r3(void)219 static INLINE void fx_to_r3(void)
220 {
221    FX_TO(3);
222 }
fx_to_r4(void)223 static INLINE void fx_to_r4(void)
224 {
225    FX_TO(4);
226 }
fx_to_r5(void)227 static INLINE void fx_to_r5(void)
228 {
229    FX_TO(5);
230 }
fx_to_r6(void)231 static INLINE void fx_to_r6(void)
232 {
233    FX_TO(6);
234 }
fx_to_r7(void)235 static INLINE void fx_to_r7(void)
236 {
237    FX_TO(7);
238 }
fx_to_r8(void)239 static INLINE void fx_to_r8(void)
240 {
241    FX_TO(8);
242 }
fx_to_r9(void)243 static INLINE void fx_to_r9(void)
244 {
245    FX_TO(9);
246 }
fx_to_r10(void)247 static INLINE void fx_to_r10(void)
248 {
249    FX_TO(10);
250 }
fx_to_r11(void)251 static INLINE void fx_to_r11(void)
252 {
253    FX_TO(11);
254 }
fx_to_r12(void)255 static INLINE void fx_to_r12(void)
256 {
257    FX_TO(12);
258 }
fx_to_r13(void)259 static INLINE void fx_to_r13(void)
260 {
261    FX_TO(13);
262 }
fx_to_r14(void)263 static INLINE void fx_to_r14(void)
264 {
265    FX_TO_R14(14);
266 }
fx_to_r15(void)267 static INLINE void fx_to_r15(void)
268 {
269    FX_TO_R15(15);
270 }
271 
272 /* 20-2f - to rn - set register n as source and destination register */
273 #define FX_WITH(reg) \
274     SF(B); \
275     GSU.pvSreg = GSU.pvDreg = &GSU.avReg[reg]; \
276     R15++
277 
fx_with_r0(void)278 static INLINE void fx_with_r0(void)
279 {
280    FX_WITH(0);
281 }
fx_with_r1(void)282 static INLINE void fx_with_r1(void)
283 {
284    FX_WITH(1);
285 }
fx_with_r2(void)286 static INLINE void fx_with_r2(void)
287 {
288    FX_WITH(2);
289 }
fx_with_r3(void)290 static INLINE void fx_with_r3(void)
291 {
292    FX_WITH(3);
293 }
fx_with_r4(void)294 static INLINE void fx_with_r4(void)
295 {
296    FX_WITH(4);
297 }
fx_with_r5(void)298 static INLINE void fx_with_r5(void)
299 {
300    FX_WITH(5);
301 }
fx_with_r6(void)302 static INLINE void fx_with_r6(void)
303 {
304    FX_WITH(6);
305 }
fx_with_r7(void)306 static INLINE void fx_with_r7(void)
307 {
308    FX_WITH(7);
309 }
fx_with_r8(void)310 static INLINE void fx_with_r8(void)
311 {
312    FX_WITH(8);
313 }
fx_with_r9(void)314 static INLINE void fx_with_r9(void)
315 {
316    FX_WITH(9);
317 }
fx_with_r10(void)318 static INLINE void fx_with_r10(void)
319 {
320    FX_WITH(10);
321 }
fx_with_r11(void)322 static INLINE void fx_with_r11(void)
323 {
324    FX_WITH(11);
325 }
fx_with_r12(void)326 static INLINE void fx_with_r12(void)
327 {
328    FX_WITH(12);
329 }
fx_with_r13(void)330 static INLINE void fx_with_r13(void)
331 {
332    FX_WITH(13);
333 }
fx_with_r14(void)334 static INLINE void fx_with_r14(void)
335 {
336    FX_WITH(14);
337 }
fx_with_r15(void)338 static INLINE void fx_with_r15(void)
339 {
340    FX_WITH(15);
341 }
342 
343 /* 30-3b - stw (rn) - store word */
344 #define FX_STW(reg) \
345     GSU.vLastRamAdr = GSU.avReg[reg]; \
346     RAM(GSU.avReg[reg]) = (uint8_t) SREG; \
347     RAM(GSU.avReg[reg] ^ 1) = (uint8_t) (SREG >> 8); \
348     CLRFLAGS; \
349     R15++
350 
fx_stw_r0(void)351 static INLINE void fx_stw_r0(void)
352 {
353    FX_STW(0);
354 }
fx_stw_r1(void)355 static INLINE void fx_stw_r1(void)
356 {
357    FX_STW(1);
358 }
fx_stw_r2(void)359 static INLINE void fx_stw_r2(void)
360 {
361    FX_STW(2);
362 }
fx_stw_r3(void)363 static INLINE void fx_stw_r3(void)
364 {
365    FX_STW(3);
366 }
fx_stw_r4(void)367 static INLINE void fx_stw_r4(void)
368 {
369    FX_STW(4);
370 }
fx_stw_r5(void)371 static INLINE void fx_stw_r5(void)
372 {
373    FX_STW(5);
374 }
fx_stw_r6(void)375 static INLINE void fx_stw_r6(void)
376 {
377    FX_STW(6);
378 }
fx_stw_r7(void)379 static INLINE void fx_stw_r7(void)
380 {
381    FX_STW(7);
382 }
fx_stw_r8(void)383 static INLINE void fx_stw_r8(void)
384 {
385    FX_STW(8);
386 }
fx_stw_r9(void)387 static INLINE void fx_stw_r9(void)
388 {
389    FX_STW(9);
390 }
fx_stw_r10(void)391 static INLINE void fx_stw_r10(void)
392 {
393    FX_STW(10);
394 }
fx_stw_r11(void)395 static INLINE void fx_stw_r11(void)
396 {
397    FX_STW(11);
398 }
399 
400 /* 30-3b(ALT1) - stb (rn) - store byte */
401 #define FX_STB(reg) \
402     GSU.vLastRamAdr = GSU.avReg[reg]; \
403     RAM(GSU.avReg[reg]) = (uint8_t) SREG; \
404     CLRFLAGS; \
405     R15++
406 
fx_stb_r0(void)407 static INLINE void fx_stb_r0(void)
408 {
409    FX_STB(0);
410 }
fx_stb_r1(void)411 static INLINE void fx_stb_r1(void)
412 {
413    FX_STB(1);
414 }
fx_stb_r2(void)415 static INLINE void fx_stb_r2(void)
416 {
417    FX_STB(2);
418 }
fx_stb_r3(void)419 static INLINE void fx_stb_r3(void)
420 {
421    FX_STB(3);
422 }
fx_stb_r4(void)423 static INLINE void fx_stb_r4(void)
424 {
425    FX_STB(4);
426 }
fx_stb_r5(void)427 static INLINE void fx_stb_r5(void)
428 {
429    FX_STB(5);
430 }
fx_stb_r6(void)431 static INLINE void fx_stb_r6(void)
432 {
433    FX_STB(6);
434 }
fx_stb_r7(void)435 static INLINE void fx_stb_r7(void)
436 {
437    FX_STB(7);
438 }
fx_stb_r8(void)439 static INLINE void fx_stb_r8(void)
440 {
441    FX_STB(8);
442 }
fx_stb_r9(void)443 static INLINE void fx_stb_r9(void)
444 {
445    FX_STB(9);
446 }
fx_stb_r10(void)447 static INLINE void fx_stb_r10(void)
448 {
449    FX_STB(10);
450 }
fx_stb_r11(void)451 static INLINE void fx_stb_r11(void)
452 {
453    FX_STB(11);
454 }
455 
456 /* 3c - loop - decrement loop counter, and branch on not zero */
fx_loop(void)457 static INLINE void fx_loop(void)
458 {
459    GSU.vSign = GSU.vZero = --R12;
460    if ((uint16_t) R12 != 0)
461       R15 = R13;
462    else
463       R15++;
464    CLRFLAGS;
465 }
466 
467 /* 3d - alt1 - set alt1 mode */
fx_alt1(void)468 static INLINE void fx_alt1(void)
469 {
470    SF(ALT1);
471    CF(B);
472    R15++;
473 }
474 
475 /* 3e - alt2 - set alt2 mode */
fx_alt2(void)476 static INLINE void fx_alt2(void)
477 {
478    SF(ALT2);
479    CF(B);
480    R15++;
481 }
482 
483 /* 3f - alt3 - set alt3 mode */
fx_alt3(void)484 static INLINE void fx_alt3(void)
485 {
486    SF(ALT1);
487    SF(ALT2);
488    CF(B);
489    R15++;
490 }
491 
492 /* 40-4b - ldw (rn) - load word from RAM */
493 #define FX_LDW(reg) \
494     uint32_t v; \
495     GSU.vLastRamAdr = GSU.avReg[reg]; \
496     v = (uint32_t) RAM(GSU.avReg[reg]); \
497     v |= ((uint32_t) RAM(GSU.avReg[reg] ^ 1)) << 8; \
498     R15++; \
499     DREG = v; \
500     TESTR14; \
501     CLRFLAGS
502 
fx_ldw_r0(void)503 static INLINE void fx_ldw_r0(void)
504 {
505    FX_LDW(0);
506 }
fx_ldw_r1(void)507 static INLINE void fx_ldw_r1(void)
508 {
509    FX_LDW(1);
510 }
fx_ldw_r2(void)511 static INLINE void fx_ldw_r2(void)
512 {
513    FX_LDW(2);
514 }
fx_ldw_r3(void)515 static INLINE void fx_ldw_r3(void)
516 {
517    FX_LDW(3);
518 }
fx_ldw_r4(void)519 static INLINE void fx_ldw_r4(void)
520 {
521    FX_LDW(4);
522 }
fx_ldw_r5(void)523 static INLINE void fx_ldw_r5(void)
524 {
525    FX_LDW(5);
526 }
fx_ldw_r6(void)527 static INLINE void fx_ldw_r6(void)
528 {
529    FX_LDW(6);
530 }
fx_ldw_r7(void)531 static INLINE void fx_ldw_r7(void)
532 {
533    FX_LDW(7);
534 }
fx_ldw_r8(void)535 static INLINE void fx_ldw_r8(void)
536 {
537    FX_LDW(8);
538 }
fx_ldw_r9(void)539 static INLINE void fx_ldw_r9(void)
540 {
541    FX_LDW(9);
542 }
fx_ldw_r10(void)543 static INLINE void fx_ldw_r10(void)
544 {
545    FX_LDW(10);
546 }
fx_ldw_r11(void)547 static INLINE void fx_ldw_r11(void)
548 {
549    FX_LDW(11);
550 }
551 
552 /* 40-4b(ALT1) - ldb (rn) - load byte */
553 #define FX_LDB(reg) \
554     uint32_t v; \
555     GSU.vLastRamAdr = GSU.avReg[reg]; \
556     v = (uint32_t) RAM(GSU.avReg[reg]); \
557     R15++; \
558     DREG = v; \
559     TESTR14; \
560     CLRFLAGS
561 
fx_ldb_r0(void)562 static INLINE void fx_ldb_r0(void)
563 {
564    FX_LDB(0);
565 }
fx_ldb_r1(void)566 static INLINE void fx_ldb_r1(void)
567 {
568    FX_LDB(1);
569 }
fx_ldb_r2(void)570 static INLINE void fx_ldb_r2(void)
571 {
572    FX_LDB(2);
573 }
fx_ldb_r3(void)574 static INLINE void fx_ldb_r3(void)
575 {
576    FX_LDB(3);
577 }
fx_ldb_r4(void)578 static INLINE void fx_ldb_r4(void)
579 {
580    FX_LDB(4);
581 }
fx_ldb_r5(void)582 static INLINE void fx_ldb_r5(void)
583 {
584    FX_LDB(5);
585 }
fx_ldb_r6(void)586 static INLINE void fx_ldb_r6(void)
587 {
588    FX_LDB(6);
589 }
fx_ldb_r7(void)590 static INLINE void fx_ldb_r7(void)
591 {
592    FX_LDB(7);
593 }
fx_ldb_r8(void)594 static INLINE void fx_ldb_r8(void)
595 {
596    FX_LDB(8);
597 }
fx_ldb_r9(void)598 static INLINE void fx_ldb_r9(void)
599 {
600    FX_LDB(9);
601 }
fx_ldb_r10(void)602 static INLINE void fx_ldb_r10(void)
603 {
604    FX_LDB(10);
605 }
fx_ldb_r11(void)606 static INLINE void fx_ldb_r11(void)
607 {
608    FX_LDB(11);
609 }
610 
611 /* 4c - plot - plot pixel with R1,R2 as x,y and the color register as the color */
fx_plot_2bit(void)612 static INLINE void fx_plot_2bit(void)
613 {
614    uint32_t x = USEX8(R1);
615    uint32_t y = USEX8(R2);
616    uint8_t* a;
617    uint8_t v, c;
618 
619    R15++;
620    CLRFLAGS;
621    R1++;
622 
623    if (GSU.vPlotOptionReg & 0x02)
624       c = (x ^ y) & 1 ? (uint8_t) (GSU.vColorReg >> 4) : (uint8_t)GSU.vColorReg;
625    else
626       c = (uint8_t) GSU.vColorReg;
627 
628    if (!(GSU.vPlotOptionReg & 0x01) && !(c & 0xf))
629       return;
630    a = GSU.apvScreen[y >> 3] + GSU.x[x >> 3] + ((y & 7) << 1);
631    v = 128 >> (x & 7);
632 
633    if (c & 0x01)
634       a[0] |= v;
635    else
636       a[0] &= ~v;
637    if (c & 0x02)
638       a[1] |= v;
639    else
640       a[1] &= ~v;
641 }
642 
643 /* 2c(ALT1) - rpix - read color of the pixel with R1,R2 as x,y */
fx_rpix_2bit(void)644 static INLINE void fx_rpix_2bit(void)
645 {
646    uint32_t x = USEX8(R1);
647    uint32_t y = USEX8(R2);
648    uint8_t* a;
649    uint8_t v;
650 
651    R15++;
652    CLRFLAGS;
653 
654    a = GSU.apvScreen[y >> 3] + GSU.x[x >> 3] + ((y & 7) << 1);
655    v = 128 >> (x & 7);
656 
657    DREG = 0;
658    DREG |= ((uint32_t)((a[0] & v) != 0)) << 0;
659    DREG |= ((uint32_t)((a[1] & v) != 0)) << 1;
660    TESTR14;
661 }
662 
663 /* 4c - plot - plot pixel with R1,R2 as x,y and the color register as the color */
fx_plot_4bit(void)664 static INLINE void fx_plot_4bit(void)
665 {
666    uint32_t x = USEX8(R1);
667    uint32_t y = USEX8(R2);
668    uint8_t* a;
669    uint8_t v, c;
670 
671    R15++;
672    CLRFLAGS;
673    R1++;
674 
675    if (GSU.vPlotOptionReg & 0x02)
676       c = (x ^ y) & 1 ? (uint8_t)(GSU.vColorReg >> 4) : (uint8_t)GSU.vColorReg;
677    else
678       c = (uint8_t)GSU.vColorReg;
679 
680    if (!(GSU.vPlotOptionReg & 0x01) && !(c & 0xf)) return;
681 
682    a = GSU.apvScreen[y >> 3] + GSU.x[x >> 3] + ((y & 7) << 1);
683    v = 128 >> (x & 7);
684 
685    if (c & 0x01)
686       a[0x00] |= v;
687    else
688       a[0x00] &= ~v;
689    if (c & 0x02)
690       a[0x01] |= v;
691    else
692       a[0x01] &= ~v;
693    if (c & 0x04)
694       a[0x10] |= v;
695    else
696       a[0x10] &= ~v;
697    if (c & 0x08)
698       a[0x11] |= v;
699    else
700       a[0x11] &= ~v;
701 }
702 
703 /* 4c(ALT1) - rpix - read color of the pixel with R1,R2 as x,y */
fx_rpix_4bit(void)704 static INLINE void fx_rpix_4bit(void)
705 {
706    uint32_t x = USEX8(R1);
707    uint32_t y = USEX8(R2);
708    uint8_t* a;
709    uint8_t v;
710 
711    R15++;
712    CLRFLAGS;
713 
714    a = GSU.apvScreen[y >> 3] + GSU.x[x >> 3] + ((y & 7) << 1);
715    v = 128 >> (x & 7);
716 
717    DREG = 0;
718    DREG |= ((uint32_t)((a[0x00] & v) != 0)) << 0;
719    DREG |= ((uint32_t)((a[0x01] & v) != 0)) << 1;
720    DREG |= ((uint32_t)((a[0x10] & v) != 0)) << 2;
721    DREG |= ((uint32_t)((a[0x11] & v) != 0)) << 3;
722    TESTR14;
723 }
724 
725 /* 8c - plot - plot pixel with R1,R2 as x,y and the color register as the color */
fx_plot_8bit(void)726 static INLINE void fx_plot_8bit(void)
727 {
728    uint32_t x = USEX8(R1);
729    uint32_t y = USEX8(R2);
730    uint8_t* a;
731    uint8_t v, c;
732 
733    R15++;
734    CLRFLAGS;
735    R1++;
736 
737    c = (uint8_t)GSU.vColorReg;
738    if (!(GSU.vPlotOptionReg & 0x10))
739    {
740       if (!(GSU.vPlotOptionReg & 0x01) && !(c & 0xf))
741          return;
742    }
743    else if (!(GSU.vPlotOptionReg & 0x01) && !c)
744       return;
745 
746    a = GSU.apvScreen[y >> 3] + GSU.x[x >> 3] + ((y & 7) << 1);
747    v = 128 >> (x & 7);
748 
749    if (c & 0x01)
750       a[0x00] |= v;
751    else
752       a[0x00] &= ~v;
753    if (c & 0x02)
754       a[0x01] |= v;
755    else
756       a[0x01] &= ~v;
757    if (c & 0x04)
758       a[0x10] |= v;
759    else
760       a[0x10] &= ~v;
761    if (c & 0x08)
762       a[0x11] |= v;
763    else
764       a[0x11] &= ~v;
765    if (c & 0x10)
766       a[0x20] |= v;
767    else
768       a[0x20] &= ~v;
769    if (c & 0x20)
770       a[0x21] |= v;
771    else
772       a[0x21] &= ~v;
773    if (c & 0x40)
774       a[0x30] |= v;
775    else
776       a[0x30] &= ~v;
777    if (c & 0x80)
778       a[0x31] |= v;
779    else
780       a[0x31] &= ~v;
781 }
782 
783 /* 4c(ALT1) - rpix - read color of the pixel with R1,R2 as x,y */
fx_rpix_8bit(void)784 static INLINE void fx_rpix_8bit(void)
785 {
786    uint32_t x = USEX8(R1);
787    uint32_t y = USEX8(R2);
788    uint8_t* a;
789    uint8_t v;
790 
791    R15++;
792    CLRFLAGS;
793 
794    a = GSU.apvScreen[y >> 3] + GSU.x[x >> 3] + ((y & 7) << 1);
795    v = 128 >> (x & 7);
796 
797    DREG = 0;
798    DREG |= ((uint32_t)((a[0x00] & v) != 0)) << 0;
799    DREG |= ((uint32_t)((a[0x01] & v) != 0)) << 1;
800    DREG |= ((uint32_t)((a[0x10] & v) != 0)) << 2;
801    DREG |= ((uint32_t)((a[0x11] & v) != 0)) << 3;
802    DREG |= ((uint32_t)((a[0x20] & v) != 0)) << 4;
803    DREG |= ((uint32_t)((a[0x21] & v) != 0)) << 5;
804    DREG |= ((uint32_t)((a[0x30] & v) != 0)) << 6;
805    DREG |= ((uint32_t)((a[0x31] & v) != 0)) << 7;
806    GSU.vZero = DREG;
807    TESTR14;
808 }
809 
810 /* 4o - plot - plot pixel with R1,R2 as x,y and the color register as the color */
811 /* 4c(ALT1) - rpix - read color of the pixel with R1,R2 as x,y */
fx_obj_func(void)812 static INLINE void fx_obj_func(void)
813 {
814 }
815 
816 /* 4d - swap - swap upper and lower byte of a register */
fx_swap(void)817 static INLINE void fx_swap(void)
818 {
819    uint8_t c = (uint8_t)SREG;
820    uint8_t d = (uint8_t)(SREG >> 8);
821    uint32_t v = (((uint32_t)c) << 8) | ((uint32_t)d);
822    R15++;
823    DREG = v;
824    GSU.vSign = v;
825    GSU.vZero = v;
826    TESTR14;
827    CLRFLAGS;
828 }
829 
830 /* 4e - color - copy source register to color register */
fx_color(void)831 static INLINE void fx_color(void)
832 {
833    uint8_t c = (uint8_t)SREG;
834    if (GSU.vPlotOptionReg & 0x04)
835       c = (c & 0xf0) | (c >> 4);
836    if (GSU.vPlotOptionReg & 0x08)
837    {
838       GSU.vColorReg &= 0xf0;
839       GSU.vColorReg |= c & 0x0f;
840    }
841    else
842       GSU.vColorReg = USEX8(c);
843    CLRFLAGS;
844    R15++;
845 }
846 
847 /* 4e(ALT1) - cmode - set plot option register */
fx_cmode(void)848 static INLINE void fx_cmode(void)
849 {
850    GSU.vPlotOptionReg = SREG;
851 
852    if (GSU.vPlotOptionReg & 0x10)
853       GSU.vScreenHeight = 256; /* OBJ Mode (for drawing into sprites) */
854    else
855       GSU.vScreenHeight = GSU.vScreenRealHeight;
856 
857    fx_computeScreenPointers();
858    CLRFLAGS;
859    R15++;
860 }
861 
862 /* 4f - not - perform exclusive exor with 1 on all bits */
fx_not(void)863 static INLINE void fx_not(void)
864 {
865    uint32_t v = ~SREG;
866    R15++;
867    DREG = v;
868    GSU.vSign = v;
869    GSU.vZero = v;
870    TESTR14;
871    CLRFLAGS;
872 }
873 
874 /* 50-5f - add rn - add, register + register */
875 #define FX_ADD(reg) \
876     int32_t s = SUSEX16(SREG) + SUSEX16(GSU.avReg[reg]); \
877     GSU.vCarry = s >= 0x10000; \
878     GSU.vOverflow = ~(SREG ^ GSU.avReg[reg]) & (GSU.avReg[reg] ^ s) & 0x8000; \
879     GSU.vSign = s; \
880     GSU.vZero = s; \
881     R15++; \
882     DREG = s; \
883     TESTR14; \
884     CLRFLAGS
885 
fx_add_r0(void)886 static INLINE void fx_add_r0(void)
887 {
888    FX_ADD(0);
889 }
fx_add_r1(void)890 static INLINE void fx_add_r1(void)
891 {
892    FX_ADD(1);
893 }
fx_add_r2(void)894 static INLINE void fx_add_r2(void)
895 {
896    FX_ADD(2);
897 }
fx_add_r3(void)898 static INLINE void fx_add_r3(void)
899 {
900    FX_ADD(3);
901 }
fx_add_r4(void)902 static INLINE void fx_add_r4(void)
903 {
904    FX_ADD(4);
905 }
fx_add_r5(void)906 static INLINE void fx_add_r5(void)
907 {
908    FX_ADD(5);
909 }
fx_add_r6(void)910 static INLINE void fx_add_r6(void)
911 {
912    FX_ADD(6);
913 }
fx_add_r7(void)914 static INLINE void fx_add_r7(void)
915 {
916    FX_ADD(7);
917 }
fx_add_r8(void)918 static INLINE void fx_add_r8(void)
919 {
920    FX_ADD(8);
921 }
fx_add_r9(void)922 static INLINE void fx_add_r9(void)
923 {
924    FX_ADD(9);
925 }
fx_add_r10(void)926 static INLINE void fx_add_r10(void)
927 {
928    FX_ADD(10);
929 }
fx_add_r11(void)930 static INLINE void fx_add_r11(void)
931 {
932    FX_ADD(11);
933 }
fx_add_r12(void)934 static INLINE void fx_add_r12(void)
935 {
936    FX_ADD(12);
937 }
fx_add_r13(void)938 static INLINE void fx_add_r13(void)
939 {
940    FX_ADD(13);
941 }
fx_add_r14(void)942 static INLINE void fx_add_r14(void)
943 {
944    FX_ADD(14);
945 }
fx_add_r15(void)946 static INLINE void fx_add_r15(void)
947 {
948    FX_ADD(15);
949 }
950 
951 /* 50-5f(ALT1) - adc rn - add with carry, register + register */
952 #define FX_ADC(reg) \
953     int32_t s = SUSEX16(SREG) + SUSEX16(GSU.avReg[reg]) + SEX16(GSU.vCarry); \
954     GSU.vCarry = s >= 0x10000; \
955     GSU.vOverflow = ~(SREG ^ GSU.avReg[reg]) & (GSU.avReg[reg] ^ s) & 0x8000; \
956     GSU.vSign = s; \
957     GSU.vZero = s; \
958     R15++; \
959     DREG = s; \
960     TESTR14; \
961     CLRFLAGS
962 
fx_adc_r0(void)963 static INLINE void fx_adc_r0(void)
964 {
965    FX_ADC(0);
966 }
fx_adc_r1(void)967 static INLINE void fx_adc_r1(void)
968 {
969    FX_ADC(1);
970 }
fx_adc_r2(void)971 static INLINE void fx_adc_r2(void)
972 {
973    FX_ADC(2);
974 }
fx_adc_r3(void)975 static INLINE void fx_adc_r3(void)
976 {
977    FX_ADC(3);
978 }
fx_adc_r4(void)979 static INLINE void fx_adc_r4(void)
980 {
981    FX_ADC(4);
982 }
fx_adc_r5(void)983 static INLINE void fx_adc_r5(void)
984 {
985    FX_ADC(5);
986 }
fx_adc_r6(void)987 static INLINE void fx_adc_r6(void)
988 {
989    FX_ADC(6);
990 }
fx_adc_r7(void)991 static INLINE void fx_adc_r7(void)
992 {
993    FX_ADC(7);
994 }
fx_adc_r8(void)995 static INLINE void fx_adc_r8(void)
996 {
997    FX_ADC(8);
998 }
fx_adc_r9(void)999 static INLINE void fx_adc_r9(void)
1000 {
1001    FX_ADC(9);
1002 }
fx_adc_r10(void)1003 static INLINE void fx_adc_r10(void)
1004 {
1005    FX_ADC(10);
1006 }
fx_adc_r11(void)1007 static INLINE void fx_adc_r11(void)
1008 {
1009    FX_ADC(11);
1010 }
fx_adc_r12(void)1011 static INLINE void fx_adc_r12(void)
1012 {
1013    FX_ADC(12);
1014 }
fx_adc_r13(void)1015 static INLINE void fx_adc_r13(void)
1016 {
1017    FX_ADC(13);
1018 }
fx_adc_r14(void)1019 static INLINE void fx_adc_r14(void)
1020 {
1021    FX_ADC(14);
1022 }
fx_adc_r15(void)1023 static INLINE void fx_adc_r15(void)
1024 {
1025    FX_ADC(15);
1026 }
1027 
1028 /* 50-5f(ALT2) - add #n - add, register + immediate */
1029 #define FX_ADD_I(imm) \
1030     int32_t s = SUSEX16(SREG) + imm; \
1031     GSU.vCarry = s >= 0x10000; \
1032     GSU.vOverflow = ~(SREG ^ imm) & (imm ^ s) & 0x8000; \
1033     GSU.vSign = s; \
1034     GSU.vZero = s; \
1035     R15++; \
1036     DREG = s; \
1037     TESTR14; \
1038     CLRFLAGS
1039 
fx_add_i0(void)1040 static INLINE void fx_add_i0(void)
1041 {
1042    FX_ADD_I(0);
1043 }
fx_add_i1(void)1044 static INLINE void fx_add_i1(void)
1045 {
1046    FX_ADD_I(1);
1047 }
fx_add_i2(void)1048 static INLINE void fx_add_i2(void)
1049 {
1050    FX_ADD_I(2);
1051 }
fx_add_i3(void)1052 static INLINE void fx_add_i3(void)
1053 {
1054    FX_ADD_I(3);
1055 }
fx_add_i4(void)1056 static INLINE void fx_add_i4(void)
1057 {
1058    FX_ADD_I(4);
1059 }
fx_add_i5(void)1060 static INLINE void fx_add_i5(void)
1061 {
1062    FX_ADD_I(5);
1063 }
fx_add_i6(void)1064 static INLINE void fx_add_i6(void)
1065 {
1066    FX_ADD_I(6);
1067 }
fx_add_i7(void)1068 static INLINE void fx_add_i7(void)
1069 {
1070    FX_ADD_I(7);
1071 }
fx_add_i8(void)1072 static INLINE void fx_add_i8(void)
1073 {
1074    FX_ADD_I(8);
1075 }
fx_add_i9(void)1076 static INLINE void fx_add_i9(void)
1077 {
1078    FX_ADD_I(9);
1079 }
fx_add_i10(void)1080 static INLINE void fx_add_i10(void)
1081 {
1082    FX_ADD_I(10);
1083 }
fx_add_i11(void)1084 static INLINE void fx_add_i11(void)
1085 {
1086    FX_ADD_I(11);
1087 }
fx_add_i12(void)1088 static INLINE void fx_add_i12(void)
1089 {
1090    FX_ADD_I(12);
1091 }
fx_add_i13(void)1092 static INLINE void fx_add_i13(void)
1093 {
1094    FX_ADD_I(13);
1095 }
fx_add_i14(void)1096 static INLINE void fx_add_i14(void)
1097 {
1098    FX_ADD_I(14);
1099 }
fx_add_i15(void)1100 static INLINE void fx_add_i15(void)
1101 {
1102    FX_ADD_I(15);
1103 }
1104 
1105 /* 50-5f(ALT3) - adc #n - add with carry, register + immediate */
1106 #define FX_ADC_I(imm) \
1107     int32_t s = SUSEX16(SREG) + imm + SUSEX16(GSU.vCarry); \
1108     GSU.vCarry = s >= 0x10000; \
1109     GSU.vOverflow = ~(SREG ^ imm) & (imm ^ s) & 0x8000; \
1110     GSU.vSign = s; \
1111     GSU.vZero = s; \
1112     R15++; \
1113     DREG = s; \
1114     TESTR14; \
1115     CLRFLAGS
1116 
fx_adc_i0(void)1117 static INLINE void fx_adc_i0(void)
1118 {
1119    FX_ADC_I(0);
1120 }
fx_adc_i1(void)1121 static INLINE void fx_adc_i1(void)
1122 {
1123    FX_ADC_I(1);
1124 }
fx_adc_i2(void)1125 static INLINE void fx_adc_i2(void)
1126 {
1127    FX_ADC_I(2);
1128 }
fx_adc_i3(void)1129 static INLINE void fx_adc_i3(void)
1130 {
1131    FX_ADC_I(3);
1132 }
fx_adc_i4(void)1133 static INLINE void fx_adc_i4(void)
1134 {
1135    FX_ADC_I(4);
1136 }
fx_adc_i5(void)1137 static INLINE void fx_adc_i5(void)
1138 {
1139    FX_ADC_I(5);
1140 }
fx_adc_i6(void)1141 static INLINE void fx_adc_i6(void)
1142 {
1143    FX_ADC_I(6);
1144 }
fx_adc_i7(void)1145 static INLINE void fx_adc_i7(void)
1146 {
1147    FX_ADC_I(7);
1148 }
fx_adc_i8(void)1149 static INLINE void fx_adc_i8(void)
1150 {
1151    FX_ADC_I(8);
1152 }
fx_adc_i9(void)1153 static INLINE void fx_adc_i9(void)
1154 {
1155    FX_ADC_I(9);
1156 }
fx_adc_i10(void)1157 static INLINE void fx_adc_i10(void)
1158 {
1159    FX_ADC_I(10);
1160 }
fx_adc_i11(void)1161 static INLINE void fx_adc_i11(void)
1162 {
1163    FX_ADC_I(11);
1164 }
fx_adc_i12(void)1165 static INLINE void fx_adc_i12(void)
1166 {
1167    FX_ADC_I(12);
1168 }
fx_adc_i13(void)1169 static INLINE void fx_adc_i13(void)
1170 {
1171    FX_ADC_I(13);
1172 }
fx_adc_i14(void)1173 static INLINE void fx_adc_i14(void)
1174 {
1175    FX_ADC_I(14);
1176 }
fx_adc_i15(void)1177 static INLINE void fx_adc_i15(void)
1178 {
1179    FX_ADC_I(15);
1180 }
1181 
1182 /* 60-6f - sub rn - subtract, register - register */
1183 #define FX_SUB(reg) \
1184     int32_t s = SUSEX16(SREG) - SUSEX16(GSU.avReg[reg]); \
1185     GSU.vCarry = s >= 0; \
1186     GSU.vOverflow = (SREG ^ GSU.avReg[reg]) & (SREG ^ s) & 0x8000; \
1187     GSU.vSign = s; \
1188     GSU.vZero = s; \
1189     R15++; \
1190     DREG = s; \
1191     TESTR14; \
1192     CLRFLAGS
1193 
fx_sub_r0(void)1194 static INLINE void fx_sub_r0(void)
1195 {
1196    FX_SUB(0);
1197 }
fx_sub_r1(void)1198 static INLINE void fx_sub_r1(void)
1199 {
1200    FX_SUB(1);
1201 }
fx_sub_r2(void)1202 static INLINE void fx_sub_r2(void)
1203 {
1204    FX_SUB(2);
1205 }
fx_sub_r3(void)1206 static INLINE void fx_sub_r3(void)
1207 {
1208    FX_SUB(3);
1209 }
fx_sub_r4(void)1210 static INLINE void fx_sub_r4(void)
1211 {
1212    FX_SUB(4);
1213 }
fx_sub_r5(void)1214 static INLINE void fx_sub_r5(void)
1215 {
1216    FX_SUB(5);
1217 }
fx_sub_r6(void)1218 static INLINE void fx_sub_r6(void)
1219 {
1220    FX_SUB(6);
1221 }
fx_sub_r7(void)1222 static INLINE void fx_sub_r7(void)
1223 {
1224    FX_SUB(7);
1225 }
fx_sub_r8(void)1226 static INLINE void fx_sub_r8(void)
1227 {
1228    FX_SUB(8);
1229 }
fx_sub_r9(void)1230 static INLINE void fx_sub_r9(void)
1231 {
1232    FX_SUB(9);
1233 }
fx_sub_r10(void)1234 static INLINE void fx_sub_r10(void)
1235 {
1236    FX_SUB(10);
1237 }
fx_sub_r11(void)1238 static INLINE void fx_sub_r11(void)
1239 {
1240    FX_SUB(11);
1241 }
fx_sub_r12(void)1242 static INLINE void fx_sub_r12(void)
1243 {
1244    FX_SUB(12);
1245 }
fx_sub_r13(void)1246 static INLINE void fx_sub_r13(void)
1247 {
1248    FX_SUB(13);
1249 }
fx_sub_r14(void)1250 static INLINE void fx_sub_r14(void)
1251 {
1252    FX_SUB(14);
1253 }
fx_sub_r15(void)1254 static INLINE void fx_sub_r15(void)
1255 {
1256    FX_SUB(15);
1257 }
1258 
1259 /* 60-6f(ALT1) - sbc rn - subtract with carry, register - register */
1260 #define FX_SBC(reg) \
1261     int32_t s = SUSEX16(SREG) - SUSEX16(GSU.avReg[reg]) - (SUSEX16(GSU.vCarry ^ 1)); \
1262     GSU.vCarry = s >= 0; \
1263     GSU.vOverflow = (SREG ^ GSU.avReg[reg]) & (SREG ^ s) & 0x8000; \
1264     GSU.vSign = s; \
1265     GSU.vZero = s; \
1266     R15++; \
1267     DREG = s; \
1268     TESTR14; \
1269     CLRFLAGS
1270 
fx_sbc_r0(void)1271 static INLINE void fx_sbc_r0(void)
1272 {
1273    FX_SBC(0);
1274 }
fx_sbc_r1(void)1275 static INLINE void fx_sbc_r1(void)
1276 {
1277    FX_SBC(1);
1278 }
fx_sbc_r2(void)1279 static INLINE void fx_sbc_r2(void)
1280 {
1281    FX_SBC(2);
1282 }
fx_sbc_r3(void)1283 static INLINE void fx_sbc_r3(void)
1284 {
1285    FX_SBC(3);
1286 }
fx_sbc_r4(void)1287 static INLINE void fx_sbc_r4(void)
1288 {
1289    FX_SBC(4);
1290 }
fx_sbc_r5(void)1291 static INLINE void fx_sbc_r5(void)
1292 {
1293    FX_SBC(5);
1294 }
fx_sbc_r6(void)1295 static INLINE void fx_sbc_r6(void)
1296 {
1297    FX_SBC(6);
1298 }
fx_sbc_r7(void)1299 static INLINE void fx_sbc_r7(void)
1300 {
1301    FX_SBC(7);
1302 }
fx_sbc_r8(void)1303 static INLINE void fx_sbc_r8(void)
1304 {
1305    FX_SBC(8);
1306 }
fx_sbc_r9(void)1307 static INLINE void fx_sbc_r9(void)
1308 {
1309    FX_SBC(9);
1310 }
fx_sbc_r10(void)1311 static INLINE void fx_sbc_r10(void)
1312 {
1313    FX_SBC(10);
1314 }
fx_sbc_r11(void)1315 static INLINE void fx_sbc_r11(void)
1316 {
1317    FX_SBC(11);
1318 }
fx_sbc_r12(void)1319 static INLINE void fx_sbc_r12(void)
1320 {
1321    FX_SBC(12);
1322 }
fx_sbc_r13(void)1323 static INLINE void fx_sbc_r13(void)
1324 {
1325    FX_SBC(13);
1326 }
fx_sbc_r14(void)1327 static INLINE void fx_sbc_r14(void)
1328 {
1329    FX_SBC(14);
1330 }
fx_sbc_r15(void)1331 static INLINE void fx_sbc_r15(void)
1332 {
1333    FX_SBC(15);
1334 }
1335 
1336 /* 60-6f(ALT2) - sub #n - subtract, register - immediate */
1337 #define FX_SUB_I(imm) \
1338     int32_t s = SUSEX16(SREG) - imm; \
1339     GSU.vCarry = s >= 0; \
1340     GSU.vOverflow = (SREG ^ imm) & (SREG ^ s) & 0x8000; \
1341     GSU.vSign = s; \
1342     GSU.vZero = s; \
1343     R15++; \
1344     DREG = s; \
1345     TESTR14; \
1346     CLRFLAGS
1347 
fx_sub_i0(void)1348 static INLINE void fx_sub_i0(void)
1349 {
1350    FX_SUB_I(0);
1351 }
fx_sub_i1(void)1352 static INLINE void fx_sub_i1(void)
1353 {
1354    FX_SUB_I(1);
1355 }
fx_sub_i2(void)1356 static INLINE void fx_sub_i2(void)
1357 {
1358    FX_SUB_I(2);
1359 }
fx_sub_i3(void)1360 static INLINE void fx_sub_i3(void)
1361 {
1362    FX_SUB_I(3);
1363 }
fx_sub_i4(void)1364 static INLINE void fx_sub_i4(void)
1365 {
1366    FX_SUB_I(4);
1367 }
fx_sub_i5(void)1368 static INLINE void fx_sub_i5(void)
1369 {
1370    FX_SUB_I(5);
1371 }
fx_sub_i6(void)1372 static INLINE void fx_sub_i6(void)
1373 {
1374    FX_SUB_I(6);
1375 }
fx_sub_i7(void)1376 static INLINE void fx_sub_i7(void)
1377 {
1378    FX_SUB_I(7);
1379 }
fx_sub_i8(void)1380 static INLINE void fx_sub_i8(void)
1381 {
1382    FX_SUB_I(8);
1383 }
fx_sub_i9(void)1384 static INLINE void fx_sub_i9(void)
1385 {
1386    FX_SUB_I(9);
1387 }
fx_sub_i10(void)1388 static INLINE void fx_sub_i10(void)
1389 {
1390    FX_SUB_I(10);
1391 }
fx_sub_i11(void)1392 static INLINE void fx_sub_i11(void)
1393 {
1394    FX_SUB_I(11);
1395 }
fx_sub_i12(void)1396 static INLINE void fx_sub_i12(void)
1397 {
1398    FX_SUB_I(12);
1399 }
fx_sub_i13(void)1400 static INLINE void fx_sub_i13(void)
1401 {
1402    FX_SUB_I(13);
1403 }
fx_sub_i14(void)1404 static INLINE void fx_sub_i14(void)
1405 {
1406    FX_SUB_I(14);
1407 }
fx_sub_i15(void)1408 static INLINE void fx_sub_i15(void)
1409 {
1410    FX_SUB_I(15);
1411 }
1412 
1413 /* 60-6f(ALT3) - cmp rn - compare, register, register */
1414 #define FX_CMP(reg) \
1415     int32_t s = SUSEX16(SREG) - SUSEX16(GSU.avReg[reg]); \
1416     GSU.vCarry = s >= 0; \
1417     GSU.vOverflow = (SREG ^ GSU.avReg[reg]) & (SREG ^ s) & 0x8000; \
1418     GSU.vSign = s; \
1419     GSU.vZero = s; \
1420     R15++; \
1421     CLRFLAGS
1422 
fx_cmp_r0(void)1423 static INLINE void fx_cmp_r0(void)
1424 {
1425    FX_CMP(0);
1426 }
fx_cmp_r1(void)1427 static INLINE void fx_cmp_r1(void)
1428 {
1429    FX_CMP(1);
1430 }
fx_cmp_r2(void)1431 static INLINE void fx_cmp_r2(void)
1432 {
1433    FX_CMP(2);
1434 }
fx_cmp_r3(void)1435 static INLINE void fx_cmp_r3(void)
1436 {
1437    FX_CMP(3);
1438 }
fx_cmp_r4(void)1439 static INLINE void fx_cmp_r4(void)
1440 {
1441    FX_CMP(4);
1442 }
fx_cmp_r5(void)1443 static INLINE void fx_cmp_r5(void)
1444 {
1445    FX_CMP(5);
1446 }
fx_cmp_r6(void)1447 static INLINE void fx_cmp_r6(void)
1448 {
1449    FX_CMP(6);
1450 }
fx_cmp_r7(void)1451 static INLINE void fx_cmp_r7(void)
1452 {
1453    FX_CMP(7);
1454 }
fx_cmp_r8(void)1455 static INLINE void fx_cmp_r8(void)
1456 {
1457    FX_CMP(8);
1458 }
fx_cmp_r9(void)1459 static INLINE void fx_cmp_r9(void)
1460 {
1461    FX_CMP(9);
1462 }
fx_cmp_r10(void)1463 static INLINE void fx_cmp_r10(void)
1464 {
1465    FX_CMP(10);
1466 }
fx_cmp_r11(void)1467 static INLINE void fx_cmp_r11(void)
1468 {
1469    FX_CMP(11);
1470 }
fx_cmp_r12(void)1471 static INLINE void fx_cmp_r12(void)
1472 {
1473    FX_CMP(12);
1474 }
fx_cmp_r13(void)1475 static INLINE void fx_cmp_r13(void)
1476 {
1477    FX_CMP(13);
1478 }
fx_cmp_r14(void)1479 static INLINE void fx_cmp_r14(void)
1480 {
1481    FX_CMP(14);
1482 }
fx_cmp_r15(void)1483 static INLINE void fx_cmp_r15(void)
1484 {
1485    FX_CMP(15);
1486 }
1487 
1488 /* 70 - merge - R7 as upper byte, R8 as lower byte (used for texture-mapping) */
fx_merge(void)1489 static INLINE void fx_merge(void)
1490 {
1491    uint32_t v = (R7 & 0xff00) | ((R8 & 0xff00) >> 8);
1492    R15++;
1493    DREG = v;
1494    GSU.vOverflow = (v & 0xc0c0) << 16;
1495    GSU.vZero = !(v & 0xf0f0);
1496    GSU.vSign = ((v | (v << 8)) & 0x8000);
1497    GSU.vCarry = (v & 0xe0e0) != 0;
1498    TESTR14;
1499    CLRFLAGS;
1500 }
1501 
1502 /* 71-7f - and rn - reister & register */
1503 #define FX_AND(reg) \
1504     uint32_t v = SREG & GSU.avReg[reg]; \
1505     R15++; \
1506     DREG = v; \
1507     GSU.vSign = v; \
1508     GSU.vZero = v; \
1509     TESTR14; \
1510     CLRFLAGS
1511 
fx_and_r1(void)1512 static INLINE void fx_and_r1(void)
1513 {
1514    FX_AND(1);
1515 }
fx_and_r2(void)1516 static INLINE void fx_and_r2(void)
1517 {
1518    FX_AND(2);
1519 }
fx_and_r3(void)1520 static INLINE void fx_and_r3(void)
1521 {
1522    FX_AND(3);
1523 }
fx_and_r4(void)1524 static INLINE void fx_and_r4(void)
1525 {
1526    FX_AND(4);
1527 }
fx_and_r5(void)1528 static INLINE void fx_and_r5(void)
1529 {
1530    FX_AND(5);
1531 }
fx_and_r6(void)1532 static INLINE void fx_and_r6(void)
1533 {
1534    FX_AND(6);
1535 }
fx_and_r7(void)1536 static INLINE void fx_and_r7(void)
1537 {
1538    FX_AND(7);
1539 }
fx_and_r8(void)1540 static INLINE void fx_and_r8(void)
1541 {
1542    FX_AND(8);
1543 }
fx_and_r9(void)1544 static INLINE void fx_and_r9(void)
1545 {
1546    FX_AND(9);
1547 }
fx_and_r10(void)1548 static INLINE void fx_and_r10(void)
1549 {
1550    FX_AND(10);
1551 }
fx_and_r11(void)1552 static INLINE void fx_and_r11(void)
1553 {
1554    FX_AND(11);
1555 }
fx_and_r12(void)1556 static INLINE void fx_and_r12(void)
1557 {
1558    FX_AND(12);
1559 }
fx_and_r13(void)1560 static INLINE void fx_and_r13(void)
1561 {
1562    FX_AND(13);
1563 }
fx_and_r14(void)1564 static INLINE void fx_and_r14(void)
1565 {
1566    FX_AND(14);
1567 }
fx_and_r15(void)1568 static INLINE void fx_and_r15(void)
1569 {
1570    FX_AND(15);
1571 }
1572 
1573 /* 71-7f(ALT1) - bic rn - reister & ~register */
1574 #define FX_BIC(reg) \
1575     uint32_t v = SREG & ~GSU.avReg[reg]; \
1576     R15++; \
1577     DREG = v; \
1578     GSU.vSign = v; \
1579     GSU.vZero = v; \
1580     TESTR14; \
1581     CLRFLAGS
1582 
fx_bic_r1(void)1583 static INLINE void fx_bic_r1(void)
1584 {
1585    FX_BIC(1);
1586 }
fx_bic_r2(void)1587 static INLINE void fx_bic_r2(void)
1588 {
1589    FX_BIC(2);
1590 }
fx_bic_r3(void)1591 static INLINE void fx_bic_r3(void)
1592 {
1593    FX_BIC(3);
1594 }
fx_bic_r4(void)1595 static INLINE void fx_bic_r4(void)
1596 {
1597    FX_BIC(4);
1598 }
fx_bic_r5(void)1599 static INLINE void fx_bic_r5(void)
1600 {
1601    FX_BIC(5);
1602 }
fx_bic_r6(void)1603 static INLINE void fx_bic_r6(void)
1604 {
1605    FX_BIC(6);
1606 }
fx_bic_r7(void)1607 static INLINE void fx_bic_r7(void)
1608 {
1609    FX_BIC(7);
1610 }
fx_bic_r8(void)1611 static INLINE void fx_bic_r8(void)
1612 {
1613    FX_BIC(8);
1614 }
fx_bic_r9(void)1615 static INLINE void fx_bic_r9(void)
1616 {
1617    FX_BIC(9);
1618 }
fx_bic_r10(void)1619 static INLINE void fx_bic_r10(void)
1620 {
1621    FX_BIC(10);
1622 }
fx_bic_r11(void)1623 static INLINE void fx_bic_r11(void)
1624 {
1625    FX_BIC(11);
1626 }
fx_bic_r12(void)1627 static INLINE void fx_bic_r12(void)
1628 {
1629    FX_BIC(12);
1630 }
fx_bic_r13(void)1631 static INLINE void fx_bic_r13(void)
1632 {
1633    FX_BIC(13);
1634 }
fx_bic_r14(void)1635 static INLINE void fx_bic_r14(void)
1636 {
1637    FX_BIC(14);
1638 }
fx_bic_r15(void)1639 static INLINE void fx_bic_r15(void)
1640 {
1641    FX_BIC(15);
1642 }
1643 
1644 /* 71-7f(ALT2) - and #n - reister & immediate */
1645 #define FX_AND_I(imm) \
1646     uint32_t v = SREG & imm; \
1647     R15++; \
1648     DREG = v; \
1649     GSU.vSign = v; \
1650     GSU.vZero = v; \
1651     TESTR14; \
1652     CLRFLAGS
1653 
fx_and_i1(void)1654 static INLINE void fx_and_i1(void)
1655 {
1656    FX_AND_I(1);
1657 }
fx_and_i2(void)1658 static INLINE void fx_and_i2(void)
1659 {
1660    FX_AND_I(2);
1661 }
fx_and_i3(void)1662 static INLINE void fx_and_i3(void)
1663 {
1664    FX_AND_I(3);
1665 }
fx_and_i4(void)1666 static INLINE void fx_and_i4(void)
1667 {
1668    FX_AND_I(4);
1669 }
fx_and_i5(void)1670 static INLINE void fx_and_i5(void)
1671 {
1672    FX_AND_I(5);
1673 }
fx_and_i6(void)1674 static INLINE void fx_and_i6(void)
1675 {
1676    FX_AND_I(6);
1677 }
fx_and_i7(void)1678 static INLINE void fx_and_i7(void)
1679 {
1680    FX_AND_I(7);
1681 }
fx_and_i8(void)1682 static INLINE void fx_and_i8(void)
1683 {
1684    FX_AND_I(8);
1685 }
fx_and_i9(void)1686 static INLINE void fx_and_i9(void)
1687 {
1688    FX_AND_I(9);
1689 }
fx_and_i10(void)1690 static INLINE void fx_and_i10(void)
1691 {
1692    FX_AND_I(10);
1693 }
fx_and_i11(void)1694 static INLINE void fx_and_i11(void)
1695 {
1696    FX_AND_I(11);
1697 }
fx_and_i12(void)1698 static INLINE void fx_and_i12(void)
1699 {
1700    FX_AND_I(12);
1701 }
fx_and_i13(void)1702 static INLINE void fx_and_i13(void)
1703 {
1704    FX_AND_I(13);
1705 }
fx_and_i14(void)1706 static INLINE void fx_and_i14(void)
1707 {
1708    FX_AND_I(14);
1709 }
fx_and_i15(void)1710 static INLINE void fx_and_i15(void)
1711 {
1712    FX_AND_I(15);
1713 }
1714 
1715 /* 71-7f(ALT3) - bic #n - reister & ~immediate */
1716 #define FX_BIC_I(imm) \
1717     uint32_t v = SREG & ~imm; \
1718     R15++; \
1719     DREG = v; \
1720     GSU.vSign = v; \
1721     GSU.vZero = v; \
1722     TESTR14; \
1723     CLRFLAGS
1724 
fx_bic_i1(void)1725 static INLINE void fx_bic_i1(void)
1726 {
1727    FX_BIC_I(1);
1728 }
fx_bic_i2(void)1729 static INLINE void fx_bic_i2(void)
1730 {
1731    FX_BIC_I(2);
1732 }
fx_bic_i3(void)1733 static INLINE void fx_bic_i3(void)
1734 {
1735    FX_BIC_I(3);
1736 }
fx_bic_i4(void)1737 static INLINE void fx_bic_i4(void)
1738 {
1739    FX_BIC_I(4);
1740 }
fx_bic_i5(void)1741 static INLINE void fx_bic_i5(void)
1742 {
1743    FX_BIC_I(5);
1744 }
fx_bic_i6(void)1745 static INLINE void fx_bic_i6(void)
1746 {
1747    FX_BIC_I(6);
1748 }
fx_bic_i7(void)1749 static INLINE void fx_bic_i7(void)
1750 {
1751    FX_BIC_I(7);
1752 }
fx_bic_i8(void)1753 static INLINE void fx_bic_i8(void)
1754 {
1755    FX_BIC_I(8);
1756 }
fx_bic_i9(void)1757 static INLINE void fx_bic_i9(void)
1758 {
1759    FX_BIC_I(9);
1760 }
fx_bic_i10(void)1761 static INLINE void fx_bic_i10(void)
1762 {
1763    FX_BIC_I(10);
1764 }
fx_bic_i11(void)1765 static INLINE void fx_bic_i11(void)
1766 {
1767    FX_BIC_I(11);
1768 }
fx_bic_i12(void)1769 static INLINE void fx_bic_i12(void)
1770 {
1771    FX_BIC_I(12);
1772 }
fx_bic_i13(void)1773 static INLINE void fx_bic_i13(void)
1774 {
1775    FX_BIC_I(13);
1776 }
fx_bic_i14(void)1777 static INLINE void fx_bic_i14(void)
1778 {
1779    FX_BIC_I(14);
1780 }
fx_bic_i15(void)1781 static INLINE void fx_bic_i15(void)
1782 {
1783    FX_BIC_I(15);
1784 }
1785 
1786 /* 80-8f - mult rn - 8 bit to 16 bit signed multiply, register * register */
1787 #define FX_MULT(reg) \
1788     uint32_t v = (uint32_t) (SEX8(SREG) * SEX8(GSU.avReg[reg])); \
1789     R15++; \
1790     DREG = v; \
1791     GSU.vSign = v; \
1792     GSU.vZero = v; \
1793     TESTR14; \
1794     CLRFLAGS
1795 
fx_mult_r0(void)1796 static INLINE void fx_mult_r0(void)
1797 {
1798    FX_MULT(0);
1799 }
fx_mult_r1(void)1800 static INLINE void fx_mult_r1(void)
1801 {
1802    FX_MULT(1);
1803 }
fx_mult_r2(void)1804 static INLINE void fx_mult_r2(void)
1805 {
1806    FX_MULT(2);
1807 }
fx_mult_r3(void)1808 static INLINE void fx_mult_r3(void)
1809 {
1810    FX_MULT(3);
1811 }
fx_mult_r4(void)1812 static INLINE void fx_mult_r4(void)
1813 {
1814    FX_MULT(4);
1815 }
fx_mult_r5(void)1816 static INLINE void fx_mult_r5(void)
1817 {
1818    FX_MULT(5);
1819 }
fx_mult_r6(void)1820 static INLINE void fx_mult_r6(void)
1821 {
1822    FX_MULT(6);
1823 }
fx_mult_r7(void)1824 static INLINE void fx_mult_r7(void)
1825 {
1826    FX_MULT(7);
1827 }
fx_mult_r8(void)1828 static INLINE void fx_mult_r8(void)
1829 {
1830    FX_MULT(8);
1831 }
fx_mult_r9(void)1832 static INLINE void fx_mult_r9(void)
1833 {
1834    FX_MULT(9);
1835 }
fx_mult_r10(void)1836 static INLINE void fx_mult_r10(void)
1837 {
1838    FX_MULT(10);
1839 }
fx_mult_r11(void)1840 static INLINE void fx_mult_r11(void)
1841 {
1842    FX_MULT(11);
1843 }
fx_mult_r12(void)1844 static INLINE void fx_mult_r12(void)
1845 {
1846    FX_MULT(12);
1847 }
fx_mult_r13(void)1848 static INLINE void fx_mult_r13(void)
1849 {
1850    FX_MULT(13);
1851 }
fx_mult_r14(void)1852 static INLINE void fx_mult_r14(void)
1853 {
1854    FX_MULT(14);
1855 }
fx_mult_r15(void)1856 static INLINE void fx_mult_r15(void)
1857 {
1858    FX_MULT(15);
1859 }
1860 
1861 /* 80-8f(ALT1) - umult rn - 8 bit to 16 bit unsigned multiply, register * register */
1862 #define FX_UMULT(reg) \
1863     uint32_t v = USEX8(SREG) * USEX8(GSU.avReg[reg]); \
1864     R15++; \
1865     DREG = v; \
1866     GSU.vSign = v; \
1867     GSU.vZero = v; \
1868     TESTR14; \
1869     CLRFLAGS
1870 
fx_umult_r0(void)1871 static INLINE void fx_umult_r0(void)
1872 {
1873    FX_UMULT(0);
1874 }
fx_umult_r1(void)1875 static INLINE void fx_umult_r1(void)
1876 {
1877    FX_UMULT(1);
1878 }
fx_umult_r2(void)1879 static INLINE void fx_umult_r2(void)
1880 {
1881    FX_UMULT(2);
1882 }
fx_umult_r3(void)1883 static INLINE void fx_umult_r3(void)
1884 {
1885    FX_UMULT(3);
1886 }
fx_umult_r4(void)1887 static INLINE void fx_umult_r4(void)
1888 {
1889    FX_UMULT(4);
1890 }
fx_umult_r5(void)1891 static INLINE void fx_umult_r5(void)
1892 {
1893    FX_UMULT(5);
1894 }
fx_umult_r6(void)1895 static INLINE void fx_umult_r6(void)
1896 {
1897    FX_UMULT(6);
1898 }
fx_umult_r7(void)1899 static INLINE void fx_umult_r7(void)
1900 {
1901    FX_UMULT(7);
1902 }
fx_umult_r8(void)1903 static INLINE void fx_umult_r8(void)
1904 {
1905    FX_UMULT(8);
1906 }
fx_umult_r9(void)1907 static INLINE void fx_umult_r9(void)
1908 {
1909    FX_UMULT(9);
1910 }
fx_umult_r10(void)1911 static INLINE void fx_umult_r10(void)
1912 {
1913    FX_UMULT(10);
1914 }
fx_umult_r11(void)1915 static INLINE void fx_umult_r11(void)
1916 {
1917    FX_UMULT(11);
1918 }
fx_umult_r12(void)1919 static INLINE void fx_umult_r12(void)
1920 {
1921    FX_UMULT(12);
1922 }
fx_umult_r13(void)1923 static INLINE void fx_umult_r13(void)
1924 {
1925    FX_UMULT(13);
1926 }
fx_umult_r14(void)1927 static INLINE void fx_umult_r14(void)
1928 {
1929    FX_UMULT(14);
1930 }
fx_umult_r15(void)1931 static INLINE void fx_umult_r15(void)
1932 {
1933    FX_UMULT(15);
1934 }
1935 
1936 /* 80-8f(ALT2) - mult #n - 8 bit to 16 bit signed multiply, register * immediate */
1937 #define FX_MULT_I(imm) \
1938     uint32_t v = (uint32_t) (SEX8(SREG) * ((int32_t) imm)); \
1939     R15++; \
1940     DREG = v; \
1941     GSU.vSign = v; \
1942     GSU.vZero = v; \
1943     TESTR14; \
1944     CLRFLAGS
1945 
fx_mult_i0(void)1946 static INLINE void fx_mult_i0(void)
1947 {
1948    FX_MULT_I(0);
1949 }
fx_mult_i1(void)1950 static INLINE void fx_mult_i1(void)
1951 {
1952    FX_MULT_I(1);
1953 }
fx_mult_i2(void)1954 static INLINE void fx_mult_i2(void)
1955 {
1956    FX_MULT_I(2);
1957 }
fx_mult_i3(void)1958 static INLINE void fx_mult_i3(void)
1959 {
1960    FX_MULT_I(3);
1961 }
fx_mult_i4(void)1962 static INLINE void fx_mult_i4(void)
1963 {
1964    FX_MULT_I(4);
1965 }
fx_mult_i5(void)1966 static INLINE void fx_mult_i5(void)
1967 {
1968    FX_MULT_I(5);
1969 }
fx_mult_i6(void)1970 static INLINE void fx_mult_i6(void)
1971 {
1972    FX_MULT_I(6);
1973 }
fx_mult_i7(void)1974 static INLINE void fx_mult_i7(void)
1975 {
1976    FX_MULT_I(7);
1977 }
fx_mult_i8(void)1978 static INLINE void fx_mult_i8(void)
1979 {
1980    FX_MULT_I(8);
1981 }
fx_mult_i9(void)1982 static INLINE void fx_mult_i9(void)
1983 {
1984    FX_MULT_I(9);
1985 }
fx_mult_i10(void)1986 static INLINE void fx_mult_i10(void)
1987 {
1988    FX_MULT_I(10);
1989 }
fx_mult_i11(void)1990 static INLINE void fx_mult_i11(void)
1991 {
1992    FX_MULT_I(11);
1993 }
fx_mult_i12(void)1994 static INLINE void fx_mult_i12(void)
1995 {
1996    FX_MULT_I(12);
1997 }
fx_mult_i13(void)1998 static INLINE void fx_mult_i13(void)
1999 {
2000    FX_MULT_I(13);
2001 }
fx_mult_i14(void)2002 static INLINE void fx_mult_i14(void)
2003 {
2004    FX_MULT_I(14);
2005 }
fx_mult_i15(void)2006 static INLINE void fx_mult_i15(void)
2007 {
2008    FX_MULT_I(15);
2009 }
2010 
2011 /* 80-8f(ALT3) - umult #n - 8 bit to 16 bit unsigned multiply, register * immediate */
2012 #define FX_UMULT_I(imm) \
2013     uint32_t v = USEX8(SREG) * ((uint32_t) imm); \
2014     R15++; \
2015     DREG = v; \
2016     GSU.vSign = v; \
2017     GSU.vZero = v; \
2018     TESTR14; \
2019     CLRFLAGS
2020 
fx_umult_i0(void)2021 static INLINE void fx_umult_i0(void)
2022 {
2023    FX_UMULT_I(0);
2024 }
fx_umult_i1(void)2025 static INLINE void fx_umult_i1(void)
2026 {
2027    FX_UMULT_I(1);
2028 }
fx_umult_i2(void)2029 static INLINE void fx_umult_i2(void)
2030 {
2031    FX_UMULT_I(2);
2032 }
fx_umult_i3(void)2033 static INLINE void fx_umult_i3(void)
2034 {
2035    FX_UMULT_I(3);
2036 }
fx_umult_i4(void)2037 static INLINE void fx_umult_i4(void)
2038 {
2039    FX_UMULT_I(4);
2040 }
fx_umult_i5(void)2041 static INLINE void fx_umult_i5(void)
2042 {
2043    FX_UMULT_I(5);
2044 }
fx_umult_i6(void)2045 static INLINE void fx_umult_i6(void)
2046 {
2047    FX_UMULT_I(6);
2048 }
fx_umult_i7(void)2049 static INLINE void fx_umult_i7(void)
2050 {
2051    FX_UMULT_I(7);
2052 }
fx_umult_i8(void)2053 static INLINE void fx_umult_i8(void)
2054 {
2055    FX_UMULT_I(8);
2056 }
fx_umult_i9(void)2057 static INLINE void fx_umult_i9(void)
2058 {
2059    FX_UMULT_I(9);
2060 }
fx_umult_i10(void)2061 static INLINE void fx_umult_i10(void)
2062 {
2063    FX_UMULT_I(10);
2064 }
fx_umult_i11(void)2065 static INLINE void fx_umult_i11(void)
2066 {
2067    FX_UMULT_I(11);
2068 }
fx_umult_i12(void)2069 static INLINE void fx_umult_i12(void)
2070 {
2071    FX_UMULT_I(12);
2072 }
fx_umult_i13(void)2073 static INLINE void fx_umult_i13(void)
2074 {
2075    FX_UMULT_I(13);
2076 }
fx_umult_i14(void)2077 static INLINE void fx_umult_i14(void)
2078 {
2079    FX_UMULT_I(14);
2080 }
fx_umult_i15(void)2081 static INLINE void fx_umult_i15(void)
2082 {
2083    FX_UMULT_I(15);
2084 }
2085 
2086 /* 90 - sbk - store word to last accessed RAM address */
fx_sbk(void)2087 static INLINE void fx_sbk(void)
2088 {
2089    RAM(GSU.vLastRamAdr) = (uint8_t)SREG;
2090    RAM(GSU.vLastRamAdr ^ 1) = (uint8_t)(SREG >> 8);
2091    CLRFLAGS;
2092    R15++;
2093 }
2094 
2095 /* 91-94 - link #n - R11 = R15 + immediate */
2096 #define FX_LINK_I(lkn) \
2097     R11 = R15 + lkn; \
2098     CLRFLAGS; \
2099     R15++
2100 
fx_link_i1(void)2101 static INLINE void fx_link_i1(void)
2102 {
2103    FX_LINK_I(1);
2104 }
fx_link_i2(void)2105 static INLINE void fx_link_i2(void)
2106 {
2107    FX_LINK_I(2);
2108 }
fx_link_i3(void)2109 static INLINE void fx_link_i3(void)
2110 {
2111    FX_LINK_I(3);
2112 }
fx_link_i4(void)2113 static INLINE void fx_link_i4(void)
2114 {
2115    FX_LINK_I(4);
2116 }
2117 
2118 /* 95 - sex - sign extend 8 bit to 16 bit */
fx_sex(void)2119 static INLINE void fx_sex(void)
2120 {
2121    uint32_t v = (uint32_t)SEX8(SREG);
2122    R15++;
2123    DREG = v;
2124    GSU.vSign = v;
2125    GSU.vZero = v;
2126    TESTR14;
2127    CLRFLAGS;
2128 }
2129 
2130 /* 96 - asr - aritmetric shift right by one */
fx_asr(void)2131 static INLINE void fx_asr(void)
2132 {
2133    uint32_t v;
2134    GSU.vCarry = SREG & 1;
2135    v = (uint32_t)(SEX16(SREG) >> 1);
2136    R15++;
2137    DREG = v;
2138    GSU.vSign = v;
2139    GSU.vZero = v;
2140    TESTR14;
2141    CLRFLAGS;
2142 }
2143 
2144 /* 96(ALT1) - div2 - aritmetric shift right by one */
fx_div2(void)2145 static INLINE void fx_div2(void)
2146 {
2147    uint32_t v;
2148    int32_t s = SEX16(SREG);
2149    GSU.vCarry = s & 1;
2150    if (s == -1)
2151       v = 0;
2152    else
2153       v = (uint32_t)(s >> 1);
2154    R15++;
2155    DREG = v;
2156    GSU.vSign = v;
2157    GSU.vZero = v;
2158    TESTR14;
2159    CLRFLAGS;
2160 }
2161 
2162 /* 97 - ror - rotate right by one */
fx_ror(void)2163 static INLINE void fx_ror(void)
2164 {
2165    uint32_t v = (USEX16(SREG) >> 1) | (GSU.vCarry << 15);
2166    GSU.vCarry = SREG & 1;
2167    R15++;
2168    DREG = v;
2169    GSU.vSign = v;
2170    GSU.vZero = v;
2171    TESTR14;
2172    CLRFLAGS;
2173 }
2174 
2175 /* 98-9d - jmp rn - jump to address of register */
2176 #define FX_JMP(reg) \
2177     R15 = GSU.avReg[reg]; \
2178     CLRFLAGS
2179 
fx_jmp_r8(void)2180 static INLINE void fx_jmp_r8(void)
2181 {
2182    FX_JMP(8);
2183 }
fx_jmp_r9(void)2184 static INLINE void fx_jmp_r9(void)
2185 {
2186    FX_JMP(9);
2187 }
fx_jmp_r10(void)2188 static INLINE void fx_jmp_r10(void)
2189 {
2190    FX_JMP(10);
2191 }
fx_jmp_r11(void)2192 static INLINE void fx_jmp_r11(void)
2193 {
2194    FX_JMP(11);
2195 }
fx_jmp_r12(void)2196 static INLINE void fx_jmp_r12(void)
2197 {
2198    FX_JMP(12);
2199 }
fx_jmp_r13(void)2200 static INLINE void fx_jmp_r13(void)
2201 {
2202    FX_JMP(13);
2203 }
2204 
2205 /* 98-9d(ALT1) - ljmp rn - set program bank to source register and jump to address of register */
2206 #define FX_LJMP(reg) \
2207     GSU.vPrgBankReg = GSU.avReg[reg] & 0x7f; \
2208     GSU.pvPrgBank = GSU.apvRomBank[GSU.vPrgBankReg]; \
2209     R15 = SREG; \
2210     GSU.bCacheActive = false; \
2211     fx_cache(); \
2212     R15--
2213 
fx_ljmp_r8(void)2214 static INLINE void fx_ljmp_r8(void)
2215 {
2216    FX_LJMP(8);
2217 }
fx_ljmp_r9(void)2218 static INLINE void fx_ljmp_r9(void)
2219 {
2220    FX_LJMP(9);
2221 }
fx_ljmp_r10(void)2222 static INLINE void fx_ljmp_r10(void)
2223 {
2224    FX_LJMP(10);
2225 }
fx_ljmp_r11(void)2226 static INLINE void fx_ljmp_r11(void)
2227 {
2228    FX_LJMP(11);
2229 }
fx_ljmp_r12(void)2230 static INLINE void fx_ljmp_r12(void)
2231 {
2232    FX_LJMP(12);
2233 }
fx_ljmp_r13(void)2234 static INLINE void fx_ljmp_r13(void)
2235 {
2236    FX_LJMP(13);
2237 }
2238 
2239 /* 9e - lob - set upper byte to zero (keep low byte) */
fx_lob(void)2240 static INLINE void fx_lob(void)
2241 {
2242    uint32_t v = USEX8(SREG);
2243    R15++;
2244    DREG = v;
2245    GSU.vSign = v << 8;
2246    GSU.vZero = v << 8;
2247    TESTR14;
2248    CLRFLAGS;
2249 }
2250 
2251 /* 9f - fmult - 16 bit to 32 bit signed multiplication, upper 16 bits only */
fx_fmult(void)2252 static INLINE void fx_fmult(void)
2253 {
2254    uint32_t v;
2255    uint32_t c = (uint32_t)(SEX16(SREG) * SEX16(R6));
2256    v = c >> 16;
2257    R15++;
2258    DREG = v;
2259    GSU.vSign = v;
2260    GSU.vZero = v;
2261    GSU.vCarry = (c >> 15) & 1;
2262    TESTR14;
2263    CLRFLAGS;
2264 }
2265 
2266 /* 9f(ALT1) - lmult - 16 bit to 32 bit signed multiplication */
fx_lmult(void)2267 static INLINE void fx_lmult(void)
2268 {
2269    uint32_t v;
2270    uint32_t c = (uint32_t)(SEX16(SREG) * SEX16(R6));
2271    R4 = c;
2272    v = c >> 16;
2273    R15++;
2274    DREG = v;
2275    GSU.vSign = v;
2276    GSU.vZero = v;
2277    /* XXX R6 or R4? */
2278    GSU.vCarry = (R4 >> 15) & 1; /* should it be bit 15 of R4 instead? */
2279    TESTR14;
2280    CLRFLAGS;
2281 }
2282 
2283 /* a0-af - ibt rn,#pp - immediate byte transfer */
2284 #define FX_IBT(reg) \
2285     uint8_t v = PIPE; \
2286     R15++; \
2287     FETCHPIPE; \
2288     R15++; \
2289     GSU.avReg[reg] = SEX8(v); \
2290     CLRFLAGS
2291 
fx_ibt_r0(void)2292 static INLINE void fx_ibt_r0(void)
2293 {
2294    FX_IBT(0);
2295 }
fx_ibt_r1(void)2296 static INLINE void fx_ibt_r1(void)
2297 {
2298    FX_IBT(1);
2299 }
fx_ibt_r2(void)2300 static INLINE void fx_ibt_r2(void)
2301 {
2302    FX_IBT(2);
2303 }
fx_ibt_r3(void)2304 static INLINE void fx_ibt_r3(void)
2305 {
2306    FX_IBT(3);
2307 }
fx_ibt_r4(void)2308 static INLINE void fx_ibt_r4(void)
2309 {
2310    FX_IBT(4);
2311 }
fx_ibt_r5(void)2312 static INLINE void fx_ibt_r5(void)
2313 {
2314    FX_IBT(5);
2315 }
fx_ibt_r6(void)2316 static INLINE void fx_ibt_r6(void)
2317 {
2318    FX_IBT(6);
2319 }
fx_ibt_r7(void)2320 static INLINE void fx_ibt_r7(void)
2321 {
2322    FX_IBT(7);
2323 }
fx_ibt_r8(void)2324 static INLINE void fx_ibt_r8(void)
2325 {
2326    FX_IBT(8);
2327 }
fx_ibt_r9(void)2328 static INLINE void fx_ibt_r9(void)
2329 {
2330    FX_IBT(9);
2331 }
fx_ibt_r10(void)2332 static INLINE void fx_ibt_r10(void)
2333 {
2334    FX_IBT(10);
2335 }
fx_ibt_r11(void)2336 static INLINE void fx_ibt_r11(void)
2337 {
2338    FX_IBT(11);
2339 }
fx_ibt_r12(void)2340 static INLINE void fx_ibt_r12(void)
2341 {
2342    FX_IBT(12);
2343 }
fx_ibt_r13(void)2344 static INLINE void fx_ibt_r13(void)
2345 {
2346    FX_IBT(13);
2347 }
fx_ibt_r14(void)2348 static INLINE void fx_ibt_r14(void)
2349 {
2350    FX_IBT(14);
2351    READR14;
2352 }
fx_ibt_r15(void)2353 static INLINE void fx_ibt_r15(void)
2354 {
2355    FX_IBT(15);
2356 }
2357 
2358 /* a0-af(ALT1) - lms rn,(yy) - load word from RAM (short address) */
2359 #define FX_LMS(reg) \
2360     GSU.vLastRamAdr = ((uint32_t) PIPE) << 1; \
2361     R15++; \
2362     FETCHPIPE; \
2363     R15++; \
2364     GSU.avReg[reg] = (uint32_t) RAM(GSU.vLastRamAdr); \
2365     GSU.avReg[reg] |= ((uint32_t) RAM(GSU.vLastRamAdr + 1)) << 8; \
2366     CLRFLAGS
2367 
fx_lms_r0(void)2368 static INLINE void fx_lms_r0(void)
2369 {
2370    FX_LMS(0);
2371 }
fx_lms_r1(void)2372 static INLINE void fx_lms_r1(void)
2373 {
2374    FX_LMS(1);
2375 }
fx_lms_r2(void)2376 static INLINE void fx_lms_r2(void)
2377 {
2378    FX_LMS(2);
2379 }
fx_lms_r3(void)2380 static INLINE void fx_lms_r3(void)
2381 {
2382    FX_LMS(3);
2383 }
fx_lms_r4(void)2384 static INLINE void fx_lms_r4(void)
2385 {
2386    FX_LMS(4);
2387 }
fx_lms_r5(void)2388 static INLINE void fx_lms_r5(void)
2389 {
2390    FX_LMS(5);
2391 }
fx_lms_r6(void)2392 static INLINE void fx_lms_r6(void)
2393 {
2394    FX_LMS(6);
2395 }
fx_lms_r7(void)2396 static INLINE void fx_lms_r7(void)
2397 {
2398    FX_LMS(7);
2399 }
fx_lms_r8(void)2400 static INLINE void fx_lms_r8(void)
2401 {
2402    FX_LMS(8);
2403 }
fx_lms_r9(void)2404 static INLINE void fx_lms_r9(void)
2405 {
2406    FX_LMS(9);
2407 }
fx_lms_r10(void)2408 static INLINE void fx_lms_r10(void)
2409 {
2410    FX_LMS(10);
2411 }
fx_lms_r11(void)2412 static INLINE void fx_lms_r11(void)
2413 {
2414    FX_LMS(11);
2415 }
fx_lms_r12(void)2416 static INLINE void fx_lms_r12(void)
2417 {
2418    FX_LMS(12);
2419 }
fx_lms_r13(void)2420 static INLINE void fx_lms_r13(void)
2421 {
2422    FX_LMS(13);
2423 }
fx_lms_r14(void)2424 static INLINE void fx_lms_r14(void)
2425 {
2426    FX_LMS(14);
2427    READR14;
2428 }
fx_lms_r15(void)2429 static INLINE void fx_lms_r15(void)
2430 {
2431    FX_LMS(15);
2432 }
2433 
2434 /* a0-af(ALT2) - sms (yy),rn - store word in RAM (short address) */
2435 /* If rn == r15, is the value of r15 before or after the extra byte is read? */
2436 #define FX_SMS(reg) \
2437     uint32_t v = GSU.avReg[reg]; \
2438     GSU.vLastRamAdr = ((uint32_t) PIPE) << 1; \
2439     R15++; \
2440     FETCHPIPE; \
2441     RAM(GSU.vLastRamAdr) = (uint8_t) v; \
2442     RAM(GSU.vLastRamAdr + 1) = (uint8_t) (v >> 8); \
2443     CLRFLAGS; \
2444     R15++
2445 
fx_sms_r0(void)2446 static INLINE void fx_sms_r0(void)
2447 {
2448    FX_SMS(0);
2449 }
fx_sms_r1(void)2450 static INLINE void fx_sms_r1(void)
2451 {
2452    FX_SMS(1);
2453 }
fx_sms_r2(void)2454 static INLINE void fx_sms_r2(void)
2455 {
2456    FX_SMS(2);
2457 }
fx_sms_r3(void)2458 static INLINE void fx_sms_r3(void)
2459 {
2460    FX_SMS(3);
2461 }
fx_sms_r4(void)2462 static INLINE void fx_sms_r4(void)
2463 {
2464    FX_SMS(4);
2465 }
fx_sms_r5(void)2466 static INLINE void fx_sms_r5(void)
2467 {
2468    FX_SMS(5);
2469 }
fx_sms_r6(void)2470 static INLINE void fx_sms_r6(void)
2471 {
2472    FX_SMS(6);
2473 }
fx_sms_r7(void)2474 static INLINE void fx_sms_r7(void)
2475 {
2476    FX_SMS(7);
2477 }
fx_sms_r8(void)2478 static INLINE void fx_sms_r8(void)
2479 {
2480    FX_SMS(8);
2481 }
fx_sms_r9(void)2482 static INLINE void fx_sms_r9(void)
2483 {
2484    FX_SMS(9);
2485 }
fx_sms_r10(void)2486 static INLINE void fx_sms_r10(void)
2487 {
2488    FX_SMS(10);
2489 }
fx_sms_r11(void)2490 static INLINE void fx_sms_r11(void)
2491 {
2492    FX_SMS(11);
2493 }
fx_sms_r12(void)2494 static INLINE void fx_sms_r12(void)
2495 {
2496    FX_SMS(12);
2497 }
fx_sms_r13(void)2498 static INLINE void fx_sms_r13(void)
2499 {
2500    FX_SMS(13);
2501 }
fx_sms_r14(void)2502 static INLINE void fx_sms_r14(void)
2503 {
2504    FX_SMS(14);
2505 }
fx_sms_r15(void)2506 static INLINE void fx_sms_r15(void)
2507 {
2508    FX_SMS(15);
2509 }
2510 
2511 /* b0-bf - from rn - set source register */
2512 /* b0-bf(B) - moves rn - move register to register, and set flags, (if B flag is set) */
2513 #define FX_FROM(reg) \
2514     if (TF(B)) \
2515     { \
2516         uint32_t v = GSU.avReg[reg]; \
2517         R15++; \
2518         DREG = v; \
2519         GSU.vOverflow = (v & 0x80) << 16; \
2520         GSU.vSign = v; \
2521         GSU.vZero = v; \
2522         TESTR14; \
2523         CLRFLAGS; \
2524     } \
2525     else \
2526     { \
2527         GSU.pvSreg = &GSU.avReg[reg]; \
2528         R15++; \
2529     }
2530 
fx_from_r0(void)2531 static INLINE void fx_from_r0(void)
2532 {
2533    FX_FROM(0);
2534 }
fx_from_r1(void)2535 static INLINE void fx_from_r1(void)
2536 {
2537    FX_FROM(1);
2538 }
fx_from_r2(void)2539 static INLINE void fx_from_r2(void)
2540 {
2541    FX_FROM(2);
2542 }
fx_from_r3(void)2543 static INLINE void fx_from_r3(void)
2544 {
2545    FX_FROM(3);
2546 }
fx_from_r4(void)2547 static INLINE void fx_from_r4(void)
2548 {
2549    FX_FROM(4);
2550 }
fx_from_r5(void)2551 static INLINE void fx_from_r5(void)
2552 {
2553    FX_FROM(5);
2554 }
fx_from_r6(void)2555 static INLINE void fx_from_r6(void)
2556 {
2557    FX_FROM(6);
2558 }
fx_from_r7(void)2559 static INLINE void fx_from_r7(void)
2560 {
2561    FX_FROM(7);
2562 }
fx_from_r8(void)2563 static INLINE void fx_from_r8(void)
2564 {
2565    FX_FROM(8);
2566 }
fx_from_r9(void)2567 static INLINE void fx_from_r9(void)
2568 {
2569    FX_FROM(9);
2570 }
fx_from_r10(void)2571 static INLINE void fx_from_r10(void)
2572 {
2573    FX_FROM(10);
2574 }
fx_from_r11(void)2575 static INLINE void fx_from_r11(void)
2576 {
2577    FX_FROM(11);
2578 }
fx_from_r12(void)2579 static INLINE void fx_from_r12(void)
2580 {
2581    FX_FROM(12);
2582 }
fx_from_r13(void)2583 static INLINE void fx_from_r13(void)
2584 {
2585    FX_FROM(13);
2586 }
fx_from_r14(void)2587 static INLINE void fx_from_r14(void)
2588 {
2589    FX_FROM(14);
2590 }
fx_from_r15(void)2591 static INLINE void fx_from_r15(void)
2592 {
2593    FX_FROM(15);
2594 }
2595 
2596 /* c0 - hib - move high-byte to low-byte */
fx_hib(void)2597 static INLINE void fx_hib(void)
2598 {
2599    uint32_t v = USEX8(SREG >> 8);
2600    R15++;
2601    DREG = v;
2602    GSU.vSign = v << 8;
2603    GSU.vZero = v << 8;
2604    TESTR14;
2605    CLRFLAGS;
2606 }
2607 
2608 /* c1-cf - or rn */
2609 #define FX_OR(reg) \
2610     uint32_t v = SREG | GSU.avReg[reg]; \
2611     R15++; \
2612     DREG = v; \
2613     GSU.vSign = v; \
2614     GSU.vZero = v; \
2615     TESTR14; \
2616     CLRFLAGS
2617 
fx_or_r1(void)2618 static INLINE void fx_or_r1(void)
2619 {
2620    FX_OR(1);
2621 }
fx_or_r2(void)2622 static INLINE void fx_or_r2(void)
2623 {
2624    FX_OR(2);
2625 }
fx_or_r3(void)2626 static INLINE void fx_or_r3(void)
2627 {
2628    FX_OR(3);
2629 }
fx_or_r4(void)2630 static INLINE void fx_or_r4(void)
2631 {
2632    FX_OR(4);
2633 }
fx_or_r5(void)2634 static INLINE void fx_or_r5(void)
2635 {
2636    FX_OR(5);
2637 }
fx_or_r6(void)2638 static INLINE void fx_or_r6(void)
2639 {
2640    FX_OR(6);
2641 }
fx_or_r7(void)2642 static INLINE void fx_or_r7(void)
2643 {
2644    FX_OR(7);
2645 }
fx_or_r8(void)2646 static INLINE void fx_or_r8(void)
2647 {
2648    FX_OR(8);
2649 }
fx_or_r9(void)2650 static INLINE void fx_or_r9(void)
2651 {
2652    FX_OR(9);
2653 }
fx_or_r10(void)2654 static INLINE void fx_or_r10(void)
2655 {
2656    FX_OR(10);
2657 }
fx_or_r11(void)2658 static INLINE void fx_or_r11(void)
2659 {
2660    FX_OR(11);
2661 }
fx_or_r12(void)2662 static INLINE void fx_or_r12(void)
2663 {
2664    FX_OR(12);
2665 }
fx_or_r13(void)2666 static INLINE void fx_or_r13(void)
2667 {
2668    FX_OR(13);
2669 }
fx_or_r14(void)2670 static INLINE void fx_or_r14(void)
2671 {
2672    FX_OR(14);
2673 }
fx_or_r15(void)2674 static INLINE void fx_or_r15(void)
2675 {
2676    FX_OR(15);
2677 }
2678 
2679 /* c1-cf(ALT1) - xor rn */
2680 #define FX_XOR(reg) \
2681     uint32_t v = SREG ^ GSU.avReg[reg]; \
2682     R15++; \
2683     DREG = v; \
2684     GSU.vSign = v; \
2685     GSU.vZero = v; \
2686     TESTR14; \
2687     CLRFLAGS
2688 
fx_xor_r1(void)2689 static INLINE void fx_xor_r1(void)
2690 {
2691    FX_XOR(1);
2692 }
fx_xor_r2(void)2693 static INLINE void fx_xor_r2(void)
2694 {
2695    FX_XOR(2);
2696 }
fx_xor_r3(void)2697 static INLINE void fx_xor_r3(void)
2698 {
2699    FX_XOR(3);
2700 }
fx_xor_r4(void)2701 static INLINE void fx_xor_r4(void)
2702 {
2703    FX_XOR(4);
2704 }
fx_xor_r5(void)2705 static INLINE void fx_xor_r5(void)
2706 {
2707    FX_XOR(5);
2708 }
fx_xor_r6(void)2709 static INLINE void fx_xor_r6(void)
2710 {
2711    FX_XOR(6);
2712 }
fx_xor_r7(void)2713 static INLINE void fx_xor_r7(void)
2714 {
2715    FX_XOR(7);
2716 }
fx_xor_r8(void)2717 static INLINE void fx_xor_r8(void)
2718 {
2719    FX_XOR(8);
2720 }
fx_xor_r9(void)2721 static INLINE void fx_xor_r9(void)
2722 {
2723    FX_XOR(9);
2724 }
fx_xor_r10(void)2725 static INLINE void fx_xor_r10(void)
2726 {
2727    FX_XOR(10);
2728 }
fx_xor_r11(void)2729 static INLINE void fx_xor_r11(void)
2730 {
2731    FX_XOR(11);
2732 }
fx_xor_r12(void)2733 static INLINE void fx_xor_r12(void)
2734 {
2735    FX_XOR(12);
2736 }
fx_xor_r13(void)2737 static INLINE void fx_xor_r13(void)
2738 {
2739    FX_XOR(13);
2740 }
fx_xor_r14(void)2741 static INLINE void fx_xor_r14(void)
2742 {
2743    FX_XOR(14);
2744 }
fx_xor_r15(void)2745 static INLINE void fx_xor_r15(void)
2746 {
2747    FX_XOR(15);
2748 }
2749 
2750 /* c1-cf(ALT2) - or #n */
2751 #define FX_OR_I(imm) \
2752     uint32_t v = SREG | imm; \
2753     R15++; \
2754     DREG = v; \
2755     GSU.vSign = v; \
2756     GSU.vZero = v; \
2757     TESTR14; \
2758     CLRFLAGS
2759 
fx_or_i1(void)2760 static INLINE void fx_or_i1(void)
2761 {
2762    FX_OR_I(1);
2763 }
fx_or_i2(void)2764 static INLINE void fx_or_i2(void)
2765 {
2766    FX_OR_I(2);
2767 }
fx_or_i3(void)2768 static INLINE void fx_or_i3(void)
2769 {
2770    FX_OR_I(3);
2771 }
fx_or_i4(void)2772 static INLINE void fx_or_i4(void)
2773 {
2774    FX_OR_I(4);
2775 }
fx_or_i5(void)2776 static INLINE void fx_or_i5(void)
2777 {
2778    FX_OR_I(5);
2779 }
fx_or_i6(void)2780 static INLINE void fx_or_i6(void)
2781 {
2782    FX_OR_I(6);
2783 }
fx_or_i7(void)2784 static INLINE void fx_or_i7(void)
2785 {
2786    FX_OR_I(7);
2787 }
fx_or_i8(void)2788 static INLINE void fx_or_i8(void)
2789 {
2790    FX_OR_I(8);
2791 }
fx_or_i9(void)2792 static INLINE void fx_or_i9(void)
2793 {
2794    FX_OR_I(9);
2795 }
fx_or_i10(void)2796 static INLINE void fx_or_i10(void)
2797 {
2798    FX_OR_I(10);
2799 }
fx_or_i11(void)2800 static INLINE void fx_or_i11(void)
2801 {
2802    FX_OR_I(11);
2803 }
fx_or_i12(void)2804 static INLINE void fx_or_i12(void)
2805 {
2806    FX_OR_I(12);
2807 }
fx_or_i13(void)2808 static INLINE void fx_or_i13(void)
2809 {
2810    FX_OR_I(13);
2811 }
fx_or_i14(void)2812 static INLINE void fx_or_i14(void)
2813 {
2814    FX_OR_I(14);
2815 }
fx_or_i15(void)2816 static INLINE void fx_or_i15(void)
2817 {
2818    FX_OR_I(15);
2819 }
2820 
2821 /* c1-cf(ALT3) - xor #n */
2822 #define FX_XOR_I(imm) \
2823     uint32_t v = SREG ^ imm; \
2824     R15++; \
2825     DREG = v; \
2826     GSU.vSign = v; \
2827     GSU.vZero = v; \
2828     TESTR14; \
2829     CLRFLAGS
2830 
fx_xor_i1(void)2831 static INLINE void fx_xor_i1(void)
2832 {
2833    FX_XOR_I(1);
2834 }
fx_xor_i2(void)2835 static INLINE void fx_xor_i2(void)
2836 {
2837    FX_XOR_I(2);
2838 }
fx_xor_i3(void)2839 static INLINE void fx_xor_i3(void)
2840 {
2841    FX_XOR_I(3);
2842 }
fx_xor_i4(void)2843 static INLINE void fx_xor_i4(void)
2844 {
2845    FX_XOR_I(4);
2846 }
fx_xor_i5(void)2847 static INLINE void fx_xor_i5(void)
2848 {
2849    FX_XOR_I(5);
2850 }
fx_xor_i6(void)2851 static INLINE void fx_xor_i6(void)
2852 {
2853    FX_XOR_I(6);
2854 }
fx_xor_i7(void)2855 static INLINE void fx_xor_i7(void)
2856 {
2857    FX_XOR_I(7);
2858 }
fx_xor_i8(void)2859 static INLINE void fx_xor_i8(void)
2860 {
2861    FX_XOR_I(8);
2862 }
fx_xor_i9(void)2863 static INLINE void fx_xor_i9(void)
2864 {
2865    FX_XOR_I(9);
2866 }
fx_xor_i10(void)2867 static INLINE void fx_xor_i10(void)
2868 {
2869    FX_XOR_I(10);
2870 }
fx_xor_i11(void)2871 static INLINE void fx_xor_i11(void)
2872 {
2873    FX_XOR_I(11);
2874 }
fx_xor_i12(void)2875 static INLINE void fx_xor_i12(void)
2876 {
2877    FX_XOR_I(12);
2878 }
fx_xor_i13(void)2879 static INLINE void fx_xor_i13(void)
2880 {
2881    FX_XOR_I(13);
2882 }
fx_xor_i14(void)2883 static INLINE void fx_xor_i14(void)
2884 {
2885    FX_XOR_I(14);
2886 }
fx_xor_i15(void)2887 static INLINE void fx_xor_i15(void)
2888 {
2889    FX_XOR_I(15);
2890 }
2891 
2892 /* d0-de - inc rn - increase by one */
2893 #define FX_INC(reg) \
2894     GSU.avReg[reg] += 1; \
2895     GSU.vSign = GSU.avReg[reg]; \
2896     GSU.vZero = GSU.avReg[reg]; \
2897     CLRFLAGS; \
2898     R15++
2899 
fx_inc_r0(void)2900 static INLINE void fx_inc_r0(void)
2901 {
2902    FX_INC(0);
2903 }
fx_inc_r1(void)2904 static INLINE void fx_inc_r1(void)
2905 {
2906    FX_INC(1);
2907 }
fx_inc_r2(void)2908 static INLINE void fx_inc_r2(void)
2909 {
2910    FX_INC(2);
2911 }
fx_inc_r3(void)2912 static INLINE void fx_inc_r3(void)
2913 {
2914    FX_INC(3);
2915 }
fx_inc_r4(void)2916 static INLINE void fx_inc_r4(void)
2917 {
2918    FX_INC(4);
2919 }
fx_inc_r5(void)2920 static INLINE void fx_inc_r5(void)
2921 {
2922    FX_INC(5);
2923 }
fx_inc_r6(void)2924 static INLINE void fx_inc_r6(void)
2925 {
2926    FX_INC(6);
2927 }
fx_inc_r7(void)2928 static INLINE void fx_inc_r7(void)
2929 {
2930    FX_INC(7);
2931 }
fx_inc_r8(void)2932 static INLINE void fx_inc_r8(void)
2933 {
2934    FX_INC(8);
2935 }
fx_inc_r9(void)2936 static INLINE void fx_inc_r9(void)
2937 {
2938    FX_INC(9);
2939 }
fx_inc_r10(void)2940 static INLINE void fx_inc_r10(void)
2941 {
2942    FX_INC(10);
2943 }
fx_inc_r11(void)2944 static INLINE void fx_inc_r11(void)
2945 {
2946    FX_INC(11);
2947 }
fx_inc_r12(void)2948 static INLINE void fx_inc_r12(void)
2949 {
2950    FX_INC(12);
2951 }
fx_inc_r13(void)2952 static INLINE void fx_inc_r13(void)
2953 {
2954    FX_INC(13);
2955 }
fx_inc_r14(void)2956 static INLINE void fx_inc_r14(void)
2957 {
2958    FX_INC(14);
2959    READR14;
2960 }
2961 
2962 /* df - getc - transfer ROM buffer to color register */
fx_getc(void)2963 static INLINE void fx_getc(void)
2964 {
2965    uint8_t c = GSU.vRomBuffer;
2966    if (GSU.vPlotOptionReg & 0x04)
2967       c = (c & 0xf0) | (c >> 4);
2968    if (GSU.vPlotOptionReg & 0x08)
2969    {
2970       GSU.vColorReg &= 0xf0;
2971       GSU.vColorReg |= c & 0x0f;
2972    }
2973    else
2974       GSU.vColorReg = USEX8(c);
2975    CLRFLAGS;
2976    R15++;
2977 }
2978 
2979 /* df(ALT2) - ramb - set current RAM bank */
fx_ramb(void)2980 static INLINE void fx_ramb(void)
2981 {
2982    GSU.vRamBankReg = SREG & (FX_RAM_BANKS - 1);
2983    GSU.pvRamBank = GSU.apvRamBank[GSU.vRamBankReg & 0x3];
2984    CLRFLAGS;
2985    R15++;
2986 }
2987 
2988 /* df(ALT3) - romb - set current ROM bank */
fx_romb(void)2989 static INLINE void fx_romb(void)
2990 {
2991    GSU.vRomBankReg = USEX8(SREG) & 0x7f;
2992    GSU.pvRomBank = GSU.apvRomBank[GSU.vRomBankReg];
2993    CLRFLAGS;
2994    R15++;
2995 }
2996 
2997 /* e0-ee - dec rn - decrement by one */
2998 #define FX_DEC(reg) \
2999     GSU.avReg[reg] -= 1; \
3000     GSU.vSign = GSU.avReg[reg]; \
3001     GSU.vZero = GSU.avReg[reg]; \
3002     CLRFLAGS; \
3003     R15++
3004 
fx_dec_r0(void)3005 static INLINE void fx_dec_r0(void)
3006 {
3007    FX_DEC(0);
3008 }
fx_dec_r1(void)3009 static INLINE void fx_dec_r1(void)
3010 {
3011    FX_DEC(1);
3012 }
fx_dec_r2(void)3013 static INLINE void fx_dec_r2(void)
3014 {
3015    FX_DEC(2);
3016 }
fx_dec_r3(void)3017 static INLINE void fx_dec_r3(void)
3018 {
3019    FX_DEC(3);
3020 }
fx_dec_r4(void)3021 static INLINE void fx_dec_r4(void)
3022 {
3023    FX_DEC(4);
3024 }
fx_dec_r5(void)3025 static INLINE void fx_dec_r5(void)
3026 {
3027    FX_DEC(5);
3028 }
fx_dec_r6(void)3029 static INLINE void fx_dec_r6(void)
3030 {
3031    FX_DEC(6);
3032 }
fx_dec_r7(void)3033 static INLINE void fx_dec_r7(void)
3034 {
3035    FX_DEC(7);
3036 }
fx_dec_r8(void)3037 static INLINE void fx_dec_r8(void)
3038 {
3039    FX_DEC(8);
3040 }
fx_dec_r9(void)3041 static INLINE void fx_dec_r9(void)
3042 {
3043    FX_DEC(9);
3044 }
fx_dec_r10(void)3045 static INLINE void fx_dec_r10(void)
3046 {
3047    FX_DEC(10);
3048 }
fx_dec_r11(void)3049 static INLINE void fx_dec_r11(void)
3050 {
3051    FX_DEC(11);
3052 }
fx_dec_r12(void)3053 static INLINE void fx_dec_r12(void)
3054 {
3055    FX_DEC(12);
3056 }
fx_dec_r13(void)3057 static INLINE void fx_dec_r13(void)
3058 {
3059    FX_DEC(13);
3060 }
fx_dec_r14(void)3061 static INLINE void fx_dec_r14(void)
3062 {
3063    FX_DEC(14);
3064    READR14;
3065 }
3066 
3067 /* ef - getb - get byte from ROM at address R14 */
fx_getb(void)3068 static INLINE void fx_getb(void)
3069 {
3070    uint32_t v = (uint32_t)GSU.vRomBuffer;
3071    R15++;
3072    DREG = v;
3073    TESTR14;
3074    CLRFLAGS;
3075 }
3076 
3077 /* ef(ALT1) - getbh - get high-byte from ROM at address R14 */
fx_getbh(void)3078 static INLINE void fx_getbh(void)
3079 {
3080    uint32_t c = USEX8(GSU.vRomBuffer);
3081    uint32_t v = USEX8(SREG) | (c << 8);
3082    R15++;
3083    DREG = v;
3084    TESTR14;
3085    CLRFLAGS;
3086 }
3087 
3088 /* ef(ALT2) - getbl - get low-byte from ROM at address R14 */
fx_getbl(void)3089 static INLINE void fx_getbl(void)
3090 {
3091    uint32_t c = USEX8(GSU.vRomBuffer);
3092    uint32_t v = (SREG & 0xff00) | c;
3093    R15++;
3094    DREG = v;
3095    TESTR14;
3096    CLRFLAGS;
3097 }
3098 
3099 /* ef(ALT3) - getbs - get sign extended byte from ROM at address R14 */
fx_getbs(void)3100 static INLINE void fx_getbs(void)
3101 {
3102    uint32_t v = SEX8(GSU.vRomBuffer);
3103    R15++;
3104    DREG = v;
3105    TESTR14;
3106    CLRFLAGS;
3107 }
3108 
3109 /* f0-ff - iwt rn,#xx - immediate word transfer to register */
3110 #define FX_IWT(reg) \
3111     uint32_t v = PIPE; \
3112     R15++; \
3113     FETCHPIPE; \
3114     R15++; \
3115     v |= USEX8(PIPE) << 8; \
3116     FETCHPIPE; \
3117     R15++; \
3118     GSU.avReg[reg] = v; \
3119     CLRFLAGS
3120 
fx_iwt_r0(void)3121 static INLINE void fx_iwt_r0(void)
3122 {
3123    FX_IWT(0);
3124 }
fx_iwt_r1(void)3125 static INLINE void fx_iwt_r1(void)
3126 {
3127    FX_IWT(1);
3128 }
fx_iwt_r2(void)3129 static INLINE void fx_iwt_r2(void)
3130 {
3131    FX_IWT(2);
3132 }
fx_iwt_r3(void)3133 static INLINE void fx_iwt_r3(void)
3134 {
3135    FX_IWT(3);
3136 }
fx_iwt_r4(void)3137 static INLINE void fx_iwt_r4(void)
3138 {
3139    FX_IWT(4);
3140 }
fx_iwt_r5(void)3141 static INLINE void fx_iwt_r5(void)
3142 {
3143    FX_IWT(5);
3144 }
fx_iwt_r6(void)3145 static INLINE void fx_iwt_r6(void)
3146 {
3147    FX_IWT(6);
3148 }
fx_iwt_r7(void)3149 static INLINE void fx_iwt_r7(void)
3150 {
3151    FX_IWT(7);
3152 }
fx_iwt_r8(void)3153 static INLINE void fx_iwt_r8(void)
3154 {
3155    FX_IWT(8);
3156 }
fx_iwt_r9(void)3157 static INLINE void fx_iwt_r9(void)
3158 {
3159    FX_IWT(9);
3160 }
fx_iwt_r10(void)3161 static INLINE void fx_iwt_r10(void)
3162 {
3163    FX_IWT(10);
3164 }
fx_iwt_r11(void)3165 static INLINE void fx_iwt_r11(void)
3166 {
3167    FX_IWT(11);
3168 }
fx_iwt_r12(void)3169 static INLINE void fx_iwt_r12(void)
3170 {
3171    FX_IWT(12);
3172 }
fx_iwt_r13(void)3173 static INLINE void fx_iwt_r13(void)
3174 {
3175    FX_IWT(13);
3176 }
fx_iwt_r14(void)3177 static INLINE void fx_iwt_r14(void)
3178 {
3179    FX_IWT(14);
3180    READR14;
3181 }
fx_iwt_r15(void)3182 static INLINE void fx_iwt_r15(void)
3183 {
3184    FX_IWT(15);
3185 }
3186 
3187 /* f0-ff(ALT1) - lm rn,(xx) - load word from RAM */
3188 #define FX_LM(reg) \
3189     GSU.vLastRamAdr = PIPE; \
3190     R15++; \
3191     FETCHPIPE; \
3192     R15++; \
3193     GSU.vLastRamAdr |= USEX8(PIPE) << 8; \
3194     FETCHPIPE; \
3195     R15++; \
3196     GSU.avReg[reg] = RAM(GSU.vLastRamAdr); \
3197     GSU.avReg[reg] |= USEX8(RAM(GSU.vLastRamAdr ^ 1)) << 8; \
3198     CLRFLAGS
3199 
fx_lm_r0(void)3200 static INLINE void fx_lm_r0(void)
3201 {
3202    FX_LM(0);
3203 }
fx_lm_r1(void)3204 static INLINE void fx_lm_r1(void)
3205 {
3206    FX_LM(1);
3207 }
fx_lm_r2(void)3208 static INLINE void fx_lm_r2(void)
3209 {
3210    FX_LM(2);
3211 }
fx_lm_r3(void)3212 static INLINE void fx_lm_r3(void)
3213 {
3214    FX_LM(3);
3215 }
fx_lm_r4(void)3216 static INLINE void fx_lm_r4(void)
3217 {
3218    FX_LM(4);
3219 }
fx_lm_r5(void)3220 static INLINE void fx_lm_r5(void)
3221 {
3222    FX_LM(5);
3223 }
fx_lm_r6(void)3224 static INLINE void fx_lm_r6(void)
3225 {
3226    FX_LM(6);
3227 }
fx_lm_r7(void)3228 static INLINE void fx_lm_r7(void)
3229 {
3230    FX_LM(7);
3231 }
fx_lm_r8(void)3232 static INLINE void fx_lm_r8(void)
3233 {
3234    FX_LM(8);
3235 }
fx_lm_r9(void)3236 static INLINE void fx_lm_r9(void)
3237 {
3238    FX_LM(9);
3239 }
fx_lm_r10(void)3240 static INLINE void fx_lm_r10(void)
3241 {
3242    FX_LM(10);
3243 }
fx_lm_r11(void)3244 static INLINE void fx_lm_r11(void)
3245 {
3246    FX_LM(11);
3247 }
fx_lm_r12(void)3248 static INLINE void fx_lm_r12(void)
3249 {
3250    FX_LM(12);
3251 }
fx_lm_r13(void)3252 static INLINE void fx_lm_r13(void)
3253 {
3254    FX_LM(13);
3255 }
fx_lm_r14(void)3256 static INLINE void fx_lm_r14(void)
3257 {
3258    FX_LM(14);
3259    READR14;
3260 }
fx_lm_r15(void)3261 static INLINE void fx_lm_r15(void)
3262 {
3263    FX_LM(15);
3264 }
3265 
3266 /* f0-ff(ALT2) - sm (xx),rn - store word in RAM */
3267 /* If rn == r15, is the value of r15 before or after the extra bytes are read? */
3268 #define FX_SM(reg) \
3269     uint32_t v = GSU.avReg[reg]; \
3270     GSU.vLastRamAdr = PIPE; \
3271     R15++; \
3272     FETCHPIPE; \
3273     R15++; \
3274     GSU.vLastRamAdr |= USEX8(PIPE) << 8; \
3275     FETCHPIPE; \
3276     RAM(GSU.vLastRamAdr) = (uint8_t) v; \
3277     RAM(GSU.vLastRamAdr ^ 1) = (uint8_t) (v >> 8); \
3278     CLRFLAGS; \
3279     R15++
3280 
fx_sm_r0(void)3281 static INLINE void fx_sm_r0(void)
3282 {
3283    FX_SM(0);
3284 }
fx_sm_r1(void)3285 static INLINE void fx_sm_r1(void)
3286 {
3287    FX_SM(1);
3288 }
fx_sm_r2(void)3289 static INLINE void fx_sm_r2(void)
3290 {
3291    FX_SM(2);
3292 }
fx_sm_r3(void)3293 static INLINE void fx_sm_r3(void)
3294 {
3295    FX_SM(3);
3296 }
fx_sm_r4(void)3297 static INLINE void fx_sm_r4(void)
3298 {
3299    FX_SM(4);
3300 }
fx_sm_r5(void)3301 static INLINE void fx_sm_r5(void)
3302 {
3303    FX_SM(5);
3304 }
fx_sm_r6(void)3305 static INLINE void fx_sm_r6(void)
3306 {
3307    FX_SM(6);
3308 }
fx_sm_r7(void)3309 static INLINE void fx_sm_r7(void)
3310 {
3311    FX_SM(7);
3312 }
fx_sm_r8(void)3313 static INLINE void fx_sm_r8(void)
3314 {
3315    FX_SM(8);
3316 }
fx_sm_r9(void)3317 static INLINE void fx_sm_r9(void)
3318 {
3319    FX_SM(9);
3320 }
fx_sm_r10(void)3321 static INLINE void fx_sm_r10(void)
3322 {
3323    FX_SM(10);
3324 }
fx_sm_r11(void)3325 static INLINE void fx_sm_r11(void)
3326 {
3327    FX_SM(11);
3328 }
fx_sm_r12(void)3329 static INLINE void fx_sm_r12(void)
3330 {
3331    FX_SM(12);
3332 }
fx_sm_r13(void)3333 static INLINE void fx_sm_r13(void)
3334 {
3335    FX_SM(13);
3336 }
fx_sm_r14(void)3337 static INLINE void fx_sm_r14(void)
3338 {
3339    FX_SM(14);
3340 }
fx_sm_r15(void)3341 static INLINE void fx_sm_r15(void)
3342 {
3343    FX_SM(15);
3344 }
3345 
3346 /*** GSU executions functions ***/
3347 
fx_run(uint32_t nInstructions)3348 uint32_t fx_run(uint32_t nInstructions)
3349 {
3350    GSU.vCounter = nInstructions;
3351    READR14;
3352    while (TF(G) && (GSU.vCounter-- > 0))
3353       FX_STEP;
3354    return nInstructions - GSU.vInstCount;
3355 }
3356 
3357 /*** Special table for the different plot configurations ***/
3358 void (*fx_apfPlotTable[])(void) =
3359 {
3360    &fx_plot_2bit, &fx_plot_4bit, &fx_plot_4bit, &fx_plot_8bit, &fx_obj_func,
3361    &fx_rpix_2bit, &fx_rpix_4bit, &fx_rpix_4bit, &fx_rpix_8bit, &fx_obj_func,
3362 };
3363 
3364 /*** Opcode table ***/
3365 void (*fx_apfOpcodeTable[])(void) =
3366 {
3367    /*
3368     * ALT0 Table
3369     */
3370    /* 00 - 0f */
3371    &fx_stop,    &fx_nop,     &fx_cache,    &fx_lsr,      &fx_rol,      &fx_bra,      &fx_bge,      &fx_blt,
3372    &fx_bne,     &fx_beq,     &fx_bpl,      &fx_bmi,      &fx_bcc,      &fx_bcs,      &fx_bvc,      &fx_bvs,
3373    /* 10 - 1f */
3374    &fx_to_r0,   &fx_to_r1,   &fx_to_r2,    &fx_to_r3,    &fx_to_r4,    &fx_to_r5,    &fx_to_r6,    &fx_to_r7,
3375    &fx_to_r8,   &fx_to_r9,   &fx_to_r10,   &fx_to_r11,   &fx_to_r12,   &fx_to_r13,   &fx_to_r14,   &fx_to_r15,
3376    /* 20 - 2f */
3377    &fx_with_r0, &fx_with_r1, &fx_with_r2,  &fx_with_r3,  &fx_with_r4,  &fx_with_r5,  &fx_with_r6,  &fx_with_r7,
3378    &fx_with_r8, &fx_with_r9, &fx_with_r10, &fx_with_r11, &fx_with_r12, &fx_with_r13, &fx_with_r14, &fx_with_r15,
3379    /* 30 - 3f */
3380    &fx_stw_r0,  &fx_stw_r1,  &fx_stw_r2,   &fx_stw_r3,   &fx_stw_r4,   &fx_stw_r5,   &fx_stw_r6,   &fx_stw_r7,
3381    &fx_stw_r8,  &fx_stw_r9,  &fx_stw_r10,  &fx_stw_r11,  &fx_loop,     &fx_alt1,     &fx_alt2,     &fx_alt3,
3382    /* 40 - 4f */
3383    &fx_ldw_r0,  &fx_ldw_r1,  &fx_ldw_r2,   &fx_ldw_r3,   &fx_ldw_r4,   &fx_ldw_r5,   &fx_ldw_r6,   &fx_ldw_r7,
3384    &fx_ldw_r8,  &fx_ldw_r9,  &fx_ldw_r10,  &fx_ldw_r11,  &fx_plot_2bit, &fx_swap,     &fx_color,    &fx_not,
3385    /* 50 - 5f */
3386    &fx_add_r0,  &fx_add_r1,  &fx_add_r2,   &fx_add_r3,   &fx_add_r4,   &fx_add_r5,   &fx_add_r6,   &fx_add_r7,
3387    &fx_add_r8,  &fx_add_r9,  &fx_add_r10,  &fx_add_r11,  &fx_add_r12,  &fx_add_r13,  &fx_add_r14,  &fx_add_r15,
3388    /* 60 - 6f */
3389    &fx_sub_r0,  &fx_sub_r1,  &fx_sub_r2,   &fx_sub_r3,   &fx_sub_r4,   &fx_sub_r5,   &fx_sub_r6,   &fx_sub_r7,
3390    &fx_sub_r8,  &fx_sub_r9,  &fx_sub_r10,  &fx_sub_r11,  &fx_sub_r12,  &fx_sub_r13,  &fx_sub_r14,  &fx_sub_r15,
3391    /* 70 - 7f */
3392    &fx_merge,   &fx_and_r1,  &fx_and_r2,   &fx_and_r3,   &fx_and_r4,   &fx_and_r5,   &fx_and_r6,   &fx_and_r7,
3393    &fx_and_r8,  &fx_and_r9,  &fx_and_r10,  &fx_and_r11,  &fx_and_r12,  &fx_and_r13,  &fx_and_r14,  &fx_and_r15,
3394    /* 80 - 8f */
3395    &fx_mult_r0, &fx_mult_r1, &fx_mult_r2,  &fx_mult_r3,  &fx_mult_r4,  &fx_mult_r5,  &fx_mult_r6,  &fx_mult_r7,
3396    &fx_mult_r8, &fx_mult_r9, &fx_mult_r10, &fx_mult_r11, &fx_mult_r12, &fx_mult_r13, &fx_mult_r14, &fx_mult_r15,
3397    /* 90 - 9f */
3398    &fx_sbk,     &fx_link_i1, &fx_link_i2,  &fx_link_i3,  &fx_link_i4,  &fx_sex,      &fx_asr,      &fx_ror,
3399    &fx_jmp_r8,  &fx_jmp_r9,  &fx_jmp_r10,  &fx_jmp_r11,  &fx_jmp_r12,  &fx_jmp_r13,  &fx_lob,      &fx_fmult,
3400    /* a0 - af */
3401    &fx_ibt_r0,  &fx_ibt_r1,  &fx_ibt_r2,   &fx_ibt_r3,   &fx_ibt_r4,   &fx_ibt_r5,   &fx_ibt_r6,   &fx_ibt_r7,
3402    &fx_ibt_r8,  &fx_ibt_r9,  &fx_ibt_r10,  &fx_ibt_r11,  &fx_ibt_r12,  &fx_ibt_r13,  &fx_ibt_r14,  &fx_ibt_r15,
3403    /* b0 - bf */
3404    &fx_from_r0, &fx_from_r1, &fx_from_r2,  &fx_from_r3,  &fx_from_r4,  &fx_from_r5,  &fx_from_r6,  &fx_from_r7,
3405    &fx_from_r8, &fx_from_r9, &fx_from_r10, &fx_from_r11, &fx_from_r12, &fx_from_r13, &fx_from_r14, &fx_from_r15,
3406    /* c0 - cf */
3407    &fx_hib,     &fx_or_r1,   &fx_or_r2,    &fx_or_r3,    &fx_or_r4,    &fx_or_r5,    &fx_or_r6,    &fx_or_r7,
3408    &fx_or_r8,   &fx_or_r9,   &fx_or_r10,   &fx_or_r11,   &fx_or_r12,   &fx_or_r13,   &fx_or_r14,   &fx_or_r15,
3409    /* d0 - df */
3410    &fx_inc_r0,  &fx_inc_r1,  &fx_inc_r2,   &fx_inc_r3,   &fx_inc_r4,   &fx_inc_r5,   &fx_inc_r6,   &fx_inc_r7,
3411    &fx_inc_r8,  &fx_inc_r9,  &fx_inc_r10,  &fx_inc_r11,  &fx_inc_r12,  &fx_inc_r13,  &fx_inc_r14,  &fx_getc,
3412    /* e0 - ef */
3413    &fx_dec_r0,  &fx_dec_r1,  &fx_dec_r2,   &fx_dec_r3,   &fx_dec_r4,   &fx_dec_r5,   &fx_dec_r6,   &fx_dec_r7,
3414    &fx_dec_r8,  &fx_dec_r9,  &fx_dec_r10,  &fx_dec_r11,  &fx_dec_r12,  &fx_dec_r13,  &fx_dec_r14,  &fx_getb,
3415    /* f0 - ff */
3416    &fx_iwt_r0,  &fx_iwt_r1,  &fx_iwt_r2,   &fx_iwt_r3,   &fx_iwt_r4,   &fx_iwt_r5,   &fx_iwt_r6,   &fx_iwt_r7,
3417    &fx_iwt_r8,  &fx_iwt_r9,  &fx_iwt_r10,  &fx_iwt_r11,  &fx_iwt_r12,  &fx_iwt_r13,  &fx_iwt_r14,  &fx_iwt_r15,
3418    /*
3419     * ALT1 Table
3420     */
3421    /* 00 - 0f */
3422    &fx_stop,    &fx_nop,     &fx_cache,    &fx_lsr,      &fx_rol,      &fx_bra,      &fx_bge,      &fx_blt,
3423    &fx_bne,     &fx_beq,     &fx_bpl,      &fx_bmi,      &fx_bcc,      &fx_bcs,      &fx_bvc,      &fx_bvs,
3424    /* 10 - 1f */
3425    &fx_to_r0,   &fx_to_r1,   &fx_to_r2,    &fx_to_r3,    &fx_to_r4,    &fx_to_r5,    &fx_to_r6,    &fx_to_r7,
3426    &fx_to_r8,   &fx_to_r9,   &fx_to_r10,   &fx_to_r11,   &fx_to_r12,   &fx_to_r13,   &fx_to_r14,   &fx_to_r15,
3427    /* 20 - 2f */
3428    &fx_with_r0, &fx_with_r1, &fx_with_r2,  &fx_with_r3,  &fx_with_r4,  &fx_with_r5,  &fx_with_r6,  &fx_with_r7,
3429    &fx_with_r8, &fx_with_r9, &fx_with_r10, &fx_with_r11, &fx_with_r12, &fx_with_r13, &fx_with_r14, &fx_with_r15,
3430    /* 30 - 3f */
3431    &fx_stb_r0,  &fx_stb_r1,  &fx_stb_r2,   &fx_stb_r3,   &fx_stb_r4,   &fx_stb_r5,   &fx_stb_r6,   &fx_stb_r7,
3432    &fx_stb_r8,  &fx_stb_r9,  &fx_stb_r10,  &fx_stb_r11,  &fx_loop,     &fx_alt1,     &fx_alt2,     &fx_alt3,
3433    /* 40 - 4f */
3434    &fx_ldb_r0,  &fx_ldb_r1,  &fx_ldb_r2,   &fx_ldb_r3,   &fx_ldb_r4,   &fx_ldb_r5,   &fx_ldb_r6,   &fx_ldb_r7,
3435    &fx_ldb_r8,  &fx_ldb_r9,  &fx_ldb_r10,  &fx_ldb_r11,  &fx_rpix_2bit, &fx_swap,     &fx_cmode,    &fx_not,
3436    /* 50 - 5f */
3437    &fx_adc_r0,  &fx_adc_r1,  &fx_adc_r2,   &fx_adc_r3,   &fx_adc_r4,   &fx_adc_r5,   &fx_adc_r6,   &fx_adc_r7,
3438    &fx_adc_r8,  &fx_adc_r9,  &fx_adc_r10,  &fx_adc_r11,  &fx_adc_r12,  &fx_adc_r13,  &fx_adc_r14,  &fx_adc_r15,
3439    /* 60 - 6f */
3440    &fx_sbc_r0,  &fx_sbc_r1,  &fx_sbc_r2,   &fx_sbc_r3,   &fx_sbc_r4,   &fx_sbc_r5,   &fx_sbc_r6,   &fx_sbc_r7,
3441    &fx_sbc_r8,  &fx_sbc_r9,  &fx_sbc_r10,  &fx_sbc_r11,  &fx_sbc_r12,  &fx_sbc_r13,  &fx_sbc_r14,  &fx_sbc_r15,
3442    /* 70 - 7f */
3443    &fx_merge,   &fx_bic_r1,  &fx_bic_r2,   &fx_bic_r3,   &fx_bic_r4,   &fx_bic_r5,   &fx_bic_r6,   &fx_bic_r7,
3444    &fx_bic_r8,  &fx_bic_r9,  &fx_bic_r10,  &fx_bic_r11,  &fx_bic_r12,  &fx_bic_r13,  &fx_bic_r14,  &fx_bic_r15,
3445    /* 80 - 8f */
3446    &fx_umult_r0, &fx_umult_r1, &fx_umult_r2, &fx_umult_r3, &fx_umult_r4, &fx_umult_r5, &fx_umult_r6, &fx_umult_r7,
3447    &fx_umult_r8, &fx_umult_r9, &fx_umult_r10, &fx_umult_r11, &fx_umult_r12, &fx_umult_r13, &fx_umult_r14, &fx_umult_r15,
3448    /* 90 - 9f */
3449    &fx_sbk,     &fx_link_i1, &fx_link_i2,  &fx_link_i3,  &fx_link_i4,  &fx_sex,      &fx_div2,     &fx_ror,
3450    &fx_ljmp_r8, &fx_ljmp_r9, &fx_ljmp_r10, &fx_ljmp_r11, &fx_ljmp_r12, &fx_ljmp_r13, &fx_lob,      &fx_lmult,
3451    /* a0 - af */
3452    &fx_lms_r0,  &fx_lms_r1,  &fx_lms_r2,   &fx_lms_r3,   &fx_lms_r4,   &fx_lms_r5,   &fx_lms_r6,   &fx_lms_r7,
3453    &fx_lms_r8,  &fx_lms_r9,  &fx_lms_r10,  &fx_lms_r11,  &fx_lms_r12,  &fx_lms_r13,  &fx_lms_r14,  &fx_lms_r15,
3454    /* b0 - bf */
3455    &fx_from_r0, &fx_from_r1, &fx_from_r2,  &fx_from_r3,  &fx_from_r4,  &fx_from_r5,  &fx_from_r6,  &fx_from_r7,
3456    &fx_from_r8, &fx_from_r9, &fx_from_r10, &fx_from_r11, &fx_from_r12, &fx_from_r13, &fx_from_r14, &fx_from_r15,
3457    /* c0 - cf */
3458    &fx_hib,     &fx_xor_r1,  &fx_xor_r2,   &fx_xor_r3,   &fx_xor_r4,   &fx_xor_r5,   &fx_xor_r6,   &fx_xor_r7,
3459    &fx_xor_r8,  &fx_xor_r9,  &fx_xor_r10,  &fx_xor_r11,  &fx_xor_r12,  &fx_xor_r13,  &fx_xor_r14,  &fx_xor_r15,
3460    /* d0 - df */
3461    &fx_inc_r0,  &fx_inc_r1,  &fx_inc_r2,   &fx_inc_r3,   &fx_inc_r4,   &fx_inc_r5,   &fx_inc_r6,   &fx_inc_r7,
3462    &fx_inc_r8,  &fx_inc_r9,  &fx_inc_r10,  &fx_inc_r11,  &fx_inc_r12,  &fx_inc_r13,  &fx_inc_r14,  &fx_getc,
3463    /* e0 - ef */
3464    &fx_dec_r0,  &fx_dec_r1,  &fx_dec_r2,   &fx_dec_r3,   &fx_dec_r4,   &fx_dec_r5,   &fx_dec_r6,   &fx_dec_r7,
3465    &fx_dec_r8,  &fx_dec_r9,  &fx_dec_r10,  &fx_dec_r11,  &fx_dec_r12,  &fx_dec_r13,  &fx_dec_r14,  &fx_getbh,
3466    /* f0 - ff */
3467    &fx_lm_r0,   &fx_lm_r1,   &fx_lm_r2,    &fx_lm_r3,    &fx_lm_r4,    &fx_lm_r5,    &fx_lm_r6,    &fx_lm_r7,
3468    &fx_lm_r8,   &fx_lm_r9,   &fx_lm_r10,   &fx_lm_r11,   &fx_lm_r12,   &fx_lm_r13,   &fx_lm_r14,   &fx_lm_r15,
3469    /*
3470     * ALT2 Table
3471     */
3472    /* 00 - 0f */
3473    &fx_stop,    &fx_nop,     &fx_cache,    &fx_lsr,      &fx_rol,      &fx_bra,      &fx_bge,      &fx_blt,
3474    &fx_bne,     &fx_beq,     &fx_bpl,      &fx_bmi,      &fx_bcc,      &fx_bcs,      &fx_bvc,      &fx_bvs,
3475    /* 10 - 1f */
3476    &fx_to_r0,   &fx_to_r1,   &fx_to_r2,    &fx_to_r3,    &fx_to_r4,    &fx_to_r5,    &fx_to_r6,    &fx_to_r7,
3477    &fx_to_r8,   &fx_to_r9,   &fx_to_r10,   &fx_to_r11,   &fx_to_r12,   &fx_to_r13,   &fx_to_r14,   &fx_to_r15,
3478    /* 20 - 2f */
3479    &fx_with_r0, &fx_with_r1, &fx_with_r2,  &fx_with_r3,  &fx_with_r4,  &fx_with_r5,  &fx_with_r6,  &fx_with_r7,
3480    &fx_with_r8, &fx_with_r9, &fx_with_r10, &fx_with_r11, &fx_with_r12, &fx_with_r13, &fx_with_r14, &fx_with_r15,
3481    /* 30 - 3f */
3482    &fx_stw_r0,  &fx_stw_r1,  &fx_stw_r2,   &fx_stw_r3,   &fx_stw_r4,   &fx_stw_r5,   &fx_stw_r6,   &fx_stw_r7,
3483    &fx_stw_r8,  &fx_stw_r9,  &fx_stw_r10,  &fx_stw_r11,  &fx_loop,     &fx_alt1,     &fx_alt2,     &fx_alt3,
3484    /* 40 - 4f */
3485    &fx_ldw_r0,  &fx_ldw_r1,  &fx_ldw_r2,   &fx_ldw_r3,   &fx_ldw_r4,   &fx_ldw_r5,   &fx_ldw_r6,   &fx_ldw_r7,
3486    &fx_ldw_r8,  &fx_ldw_r9,  &fx_ldw_r10,  &fx_ldw_r11,  &fx_plot_2bit, &fx_swap,     &fx_color,    &fx_not,
3487    /* 50 - 5f */
3488    &fx_add_i0,  &fx_add_i1,  &fx_add_i2,   &fx_add_i3,   &fx_add_i4,   &fx_add_i5,   &fx_add_i6,   &fx_add_i7,
3489    &fx_add_i8,  &fx_add_i9,  &fx_add_i10,  &fx_add_i11,  &fx_add_i12,  &fx_add_i13,  &fx_add_i14,  &fx_add_i15,
3490    /* 60 - 6f */
3491    &fx_sub_i0,  &fx_sub_i1,  &fx_sub_i2,   &fx_sub_i3,   &fx_sub_i4,   &fx_sub_i5,   &fx_sub_i6,   &fx_sub_i7,
3492    &fx_sub_i8,  &fx_sub_i9,  &fx_sub_i10,  &fx_sub_i11,  &fx_sub_i12,  &fx_sub_i13,  &fx_sub_i14,  &fx_sub_i15,
3493    /* 70 - 7f */
3494    &fx_merge,   &fx_and_i1,  &fx_and_i2,   &fx_and_i3,   &fx_and_i4,   &fx_and_i5,   &fx_and_i6,   &fx_and_i7,
3495    &fx_and_i8,  &fx_and_i9,  &fx_and_i10,  &fx_and_i11,  &fx_and_i12,  &fx_and_i13,  &fx_and_i14,  &fx_and_i15,
3496    /* 80 - 8f */
3497    &fx_mult_i0, &fx_mult_i1, &fx_mult_i2,  &fx_mult_i3,  &fx_mult_i4,  &fx_mult_i5,  &fx_mult_i6,  &fx_mult_i7,
3498    &fx_mult_i8, &fx_mult_i9, &fx_mult_i10, &fx_mult_i11, &fx_mult_i12, &fx_mult_i13, &fx_mult_i14, &fx_mult_i15,
3499    /* 90 - 9f */
3500    &fx_sbk,     &fx_link_i1, &fx_link_i2,  &fx_link_i3,  &fx_link_i4,  &fx_sex,      &fx_asr,      &fx_ror,
3501    &fx_jmp_r8,  &fx_jmp_r9,  &fx_jmp_r10,  &fx_jmp_r11,  &fx_jmp_r12,  &fx_jmp_r13,  &fx_lob,      &fx_fmult,
3502    /* a0 - af */
3503    &fx_sms_r0,  &fx_sms_r1,  &fx_sms_r2,   &fx_sms_r3,   &fx_sms_r4,   &fx_sms_r5,   &fx_sms_r6,   &fx_sms_r7,
3504    &fx_sms_r8,  &fx_sms_r9,  &fx_sms_r10,  &fx_sms_r11,  &fx_sms_r12,  &fx_sms_r13,  &fx_sms_r14,  &fx_sms_r15,
3505    /* b0 - bf */
3506    &fx_from_r0, &fx_from_r1, &fx_from_r2,  &fx_from_r3,  &fx_from_r4,  &fx_from_r5,  &fx_from_r6,  &fx_from_r7,
3507    &fx_from_r8, &fx_from_r9, &fx_from_r10, &fx_from_r11, &fx_from_r12, &fx_from_r13, &fx_from_r14, &fx_from_r15,
3508    /* c0 - cf */
3509    &fx_hib,     &fx_or_i1,   &fx_or_i2,    &fx_or_i3,    &fx_or_i4,    &fx_or_i5,    &fx_or_i6,    &fx_or_i7,
3510    &fx_or_i8,   &fx_or_i9,   &fx_or_i10,   &fx_or_i11,   &fx_or_i12,   &fx_or_i13,   &fx_or_i14,   &fx_or_i15,
3511    /* d0 - df */
3512    &fx_inc_r0,  &fx_inc_r1,  &fx_inc_r2,   &fx_inc_r3,   &fx_inc_r4,   &fx_inc_r5,   &fx_inc_r6,   &fx_inc_r7,
3513    &fx_inc_r8,  &fx_inc_r9,  &fx_inc_r10,  &fx_inc_r11,  &fx_inc_r12,  &fx_inc_r13,  &fx_inc_r14,  &fx_ramb,
3514    /* e0 - ef */
3515    &fx_dec_r0,  &fx_dec_r1,  &fx_dec_r2,   &fx_dec_r3,   &fx_dec_r4,   &fx_dec_r5,   &fx_dec_r6,   &fx_dec_r7,
3516    &fx_dec_r8,  &fx_dec_r9,  &fx_dec_r10,  &fx_dec_r11,  &fx_dec_r12,  &fx_dec_r13,  &fx_dec_r14,  &fx_getbl,
3517    /* f0 - ff */
3518    &fx_sm_r0,   &fx_sm_r1,   &fx_sm_r2,    &fx_sm_r3,    &fx_sm_r4,    &fx_sm_r5,    &fx_sm_r6,    &fx_sm_r7,
3519    &fx_sm_r8,   &fx_sm_r9,   &fx_sm_r10,   &fx_sm_r11,   &fx_sm_r12,   &fx_sm_r13,   &fx_sm_r14,   &fx_sm_r15,
3520    /*
3521     * ALT3 Table
3522     */
3523    /* 00 - 0f */
3524    &fx_stop,    &fx_nop,     &fx_cache,    &fx_lsr,      &fx_rol,      &fx_bra,      &fx_bge,      &fx_blt,
3525    &fx_bne,     &fx_beq,     &fx_bpl,      &fx_bmi,      &fx_bcc,      &fx_bcs,      &fx_bvc,      &fx_bvs,
3526    /* 10 - 1f */
3527    &fx_to_r0,   &fx_to_r1,   &fx_to_r2,    &fx_to_r3,    &fx_to_r4,    &fx_to_r5,    &fx_to_r6,    &fx_to_r7,
3528    &fx_to_r8,   &fx_to_r9,   &fx_to_r10,   &fx_to_r11,   &fx_to_r12,   &fx_to_r13,   &fx_to_r14,   &fx_to_r15,
3529    /* 20 - 2f */
3530    &fx_with_r0, &fx_with_r1, &fx_with_r2,  &fx_with_r3,  &fx_with_r4,  &fx_with_r5,  &fx_with_r6,  &fx_with_r7,
3531    &fx_with_r8, &fx_with_r9, &fx_with_r10, &fx_with_r11, &fx_with_r12, &fx_with_r13, &fx_with_r14, &fx_with_r15,
3532    /* 30 - 3f */
3533    &fx_stb_r0,  &fx_stb_r1,  &fx_stb_r2,   &fx_stb_r3,   &fx_stb_r4,   &fx_stb_r5,   &fx_stb_r6,   &fx_stb_r7,
3534    &fx_stb_r8,  &fx_stb_r9,  &fx_stb_r10,  &fx_stb_r11,  &fx_loop,     &fx_alt1,     &fx_alt2,     &fx_alt3,
3535    /* 40 - 4f */
3536    &fx_ldb_r0,  &fx_ldb_r1,  &fx_ldb_r2,   &fx_ldb_r3,   &fx_ldb_r4,   &fx_ldb_r5,   &fx_ldb_r6,   &fx_ldb_r7,
3537    &fx_ldb_r8,  &fx_ldb_r9,  &fx_ldb_r10,  &fx_ldb_r11,  &fx_rpix_2bit, &fx_swap,     &fx_cmode,    &fx_not,
3538    /* 50 - 5f */
3539    &fx_adc_i0,  &fx_adc_i1,  &fx_adc_i2,   &fx_adc_i3,   &fx_adc_i4,   &fx_adc_i5,   &fx_adc_i6,   &fx_adc_i7,
3540    &fx_adc_i8,  &fx_adc_i9,  &fx_adc_i10,  &fx_adc_i11,  &fx_adc_i12,  &fx_adc_i13,  &fx_adc_i14,  &fx_adc_i15,
3541    /* 60 - 6f */
3542    &fx_cmp_r0,  &fx_cmp_r1,  &fx_cmp_r2,   &fx_cmp_r3,   &fx_cmp_r4,   &fx_cmp_r5,   &fx_cmp_r6,   &fx_cmp_r7,
3543    &fx_cmp_r8,  &fx_cmp_r9,  &fx_cmp_r10,  &fx_cmp_r11,  &fx_cmp_r12,  &fx_cmp_r13,  &fx_cmp_r14,  &fx_cmp_r15,
3544    /* 70 - 7f */
3545    &fx_merge,   &fx_bic_i1,  &fx_bic_i2,   &fx_bic_i3,   &fx_bic_i4,   &fx_bic_i5,   &fx_bic_i6,   &fx_bic_i7,
3546    &fx_bic_i8,  &fx_bic_i9,  &fx_bic_i10,  &fx_bic_i11,  &fx_bic_i12,  &fx_bic_i13,  &fx_bic_i14,  &fx_bic_i15,
3547    /* 80 - 8f */
3548    &fx_umult_i0, &fx_umult_i1, &fx_umult_i2, &fx_umult_i3, &fx_umult_i4, &fx_umult_i5, &fx_umult_i6, &fx_umult_i7,
3549    &fx_umult_i8, &fx_umult_i9, &fx_umult_i10, &fx_umult_i11, &fx_umult_i12, &fx_umult_i13, &fx_umult_i14, &fx_umult_i15,
3550    /* 90 - 9f */
3551    &fx_sbk,     &fx_link_i1, &fx_link_i2,  &fx_link_i3,  &fx_link_i4,  &fx_sex,      &fx_div2,     &fx_ror,
3552    &fx_ljmp_r8, &fx_ljmp_r9, &fx_ljmp_r10, &fx_ljmp_r11, &fx_ljmp_r12, &fx_ljmp_r13, &fx_lob,      &fx_lmult,
3553    /* a0 - af */
3554    &fx_lms_r0,  &fx_lms_r1,  &fx_lms_r2,   &fx_lms_r3,   &fx_lms_r4,   &fx_lms_r5,   &fx_lms_r6,   &fx_lms_r7,
3555    &fx_lms_r8,  &fx_lms_r9,  &fx_lms_r10,  &fx_lms_r11,  &fx_lms_r12,  &fx_lms_r13,  &fx_lms_r14,  &fx_lms_r15,
3556    /* b0 - bf */
3557    &fx_from_r0, &fx_from_r1, &fx_from_r2,  &fx_from_r3,  &fx_from_r4,  &fx_from_r5,  &fx_from_r6,  &fx_from_r7,
3558    &fx_from_r8, &fx_from_r9, &fx_from_r10, &fx_from_r11, &fx_from_r12, &fx_from_r13, &fx_from_r14, &fx_from_r15,
3559    /* c0 - cf */
3560    &fx_hib,     &fx_xor_i1,  &fx_xor_i2,   &fx_xor_i3,   &fx_xor_i4,   &fx_xor_i5,   &fx_xor_i6,   &fx_xor_i7,
3561    &fx_xor_i8,  &fx_xor_i9,  &fx_xor_i10,  &fx_xor_i11,  &fx_xor_i12,  &fx_xor_i13,  &fx_xor_i14,  &fx_xor_i15,
3562    /* d0 - df */
3563    &fx_inc_r0,  &fx_inc_r1,  &fx_inc_r2,   &fx_inc_r3,   &fx_inc_r4,   &fx_inc_r5,   &fx_inc_r6,   &fx_inc_r7,
3564    &fx_inc_r8,  &fx_inc_r9,  &fx_inc_r10,  &fx_inc_r11,  &fx_inc_r12,  &fx_inc_r13,  &fx_inc_r14,  &fx_romb,
3565    /* e0 - ef */
3566    &fx_dec_r0,  &fx_dec_r1,  &fx_dec_r2,   &fx_dec_r3,   &fx_dec_r4,   &fx_dec_r5,   &fx_dec_r6,   &fx_dec_r7,
3567    &fx_dec_r8,  &fx_dec_r9,  &fx_dec_r10,  &fx_dec_r11,  &fx_dec_r12,  &fx_dec_r13,  &fx_dec_r14,  &fx_getbs,
3568    /* f0 - ff */
3569    &fx_lm_r0,   &fx_lm_r1,   &fx_lm_r2,    &fx_lm_r3,    &fx_lm_r4,    &fx_lm_r5,    &fx_lm_r6,    &fx_lm_r7,
3570    &fx_lm_r8,   &fx_lm_r9,   &fx_lm_r10,   &fx_lm_r11,   &fx_lm_r12,   &fx_lm_r13,   &fx_lm_r14,   &fx_lm_r15,
3571 };
3572