Annotation of uae/src/genp2c.c, revision 1.1.1.5

1.1       root        1:  /*
                      2:   * UAE - The Un*x Amiga Emulator
                      3:   *
                      4:   * Generator for planar to chunky conversions
                      5:   *
                      6:   * Copyright 1997 Bernd Schmidt
                      7:   */
                      8: 
                      9: 
                     10: #include <stdio.h>
                     11: 
                     12: #include "sysconfig.h"
                     13: #include "sysdeps.h"
                     14: 
1.1.1.3   root       15: /* We can't include custom.h here.  */
                     16: #define MAX_WORDS_PER_LINE 50
                     17: 
1.1       root       18: 
                     19: static char *gen_ind (char *a, int b)
                     20: {
                     21:     char buf[200];
                     22:     sprintf (buf, "%d(%s)", b, a);
                     23:     return strdup (buf);
                     24: }
                     25: 
                     26: static char *gen_indx (char *a, int b, char *c, int d)
                     27: {
                     28:     char buf[200];
                     29:     sprintf (buf, "%d(%s,%s,%d)", b, a, c, d);
                     30:     return strdup (buf);
                     31: }
                     32: 
                     33: static char *gen_indsx (char *a, char *sym, int b, char *c, int d)
                     34: {
                     35:     char buf[200];
                     36:     sprintf (buf, "%s+%d(%s,%s,%d)", sym, b, a, c, d);
                     37:     return strdup (buf);
                     38: }
                     39: 
                     40: #define reg(a) "%" a
                     41: #define ind(a,b) #b"("a")"
                     42: #define imm(a) "$"#a
1.1.1.2   root       43: #ifdef USE_UNDERSCORE
                     44: #define sym(a) "_"#a
                     45: #else
1.1       root       46: #define sym(a) #a
1.1.1.2   root       47: #endif
1.1       root       48: #define indx(a,b,c,d) #b"("a","c","#d")"
                     49: #define indsx(a,s,b,c,d) s"+"#b"("a","c","#d")"
                     50: 
                     51: static int labelno = 0;
                     52: 
                     53: static int get_label (void)
                     54: {
                     55:     return labelno++;
                     56: }
                     57: static void declare_label (int nr)
                     58: {
                     59:     printf (".L%d:\n", nr);
                     60: }
                     61: static int new_label (void)
                     62: {
                     63:     int nr = get_label ();
                     64:     declare_label (nr);
                     65:     return nr;
                     66: }
                     67: static void gen_label (int nr) { printf (".L%d", nr); }
                     68: static void jnz (int nr) { printf ("\tjnz "); gen_label (nr); printf ("\n"); }
                     69: static void jnc (int nr) { printf ("\tjnc "); gen_label (nr); printf ("\n"); }
                     70: static void jc (int nr) { printf ("\tjc "); gen_label (nr); printf ("\n"); }
                     71: static void jmp (int nr) { printf ("\tjmp "); gen_label (nr); printf ("\n"); }
                     72: static void movl (char *src, char *dst) { printf ("\tmovl %s,%s\n", src, dst); }
                     73: static void movw (char *src, char *dst) { printf ("\tmovl %s,%s\n", src, dst); }
                     74: static void movb (char *src, char *dst) { printf ("\tmovl %s,%s\n", src, dst); }
                     75: static void movzbl (char *src, char *dst) { printf ("\tmovzbl %s,%s\n", src, dst); }
                     76: static void leal (char *src, char *dst) { printf ("\tleal %s,%s\n", src, dst); }
                     77: static void addl (char *src, char *dst) { printf ("\taddl %s,%s\n", src, dst); }
                     78: static void subl (char *src, char *dst) { printf ("\tsubl %s,%s\n", src, dst); }
                     79: static void cmpl (char *src, char *dst) { printf ("\tcmpl %s,%s\n", src, dst); }
                     80: static void andl (unsigned long mask, char *dst) { printf ("\tandl $0x%0lx,%s\n", mask, dst); }
                     81: static void orl (char *src, char *dst) { printf ("\torl %s,%s\n", src, dst); }
                     82: static void imull (unsigned long val, char *dst) { printf ("\timull $0x%08lx,%s\n", val, dst); }
                     83: static void decl (char *dst) { printf ("\tdecl %s\n", dst); }
                     84: static void incl (char *dst) { printf ("\tincl %s\n", dst); }
1.1.1.4   root       85: static void bswapl (char *dst) { printf ("\tbswap %s\n", dst); }
1.1       root       86: static void shrl (int count, char *dst) { printf ("\tshrl $%d,%s\n", count, dst); }
                     87: static void shll (int count, char *dst) { printf ("\tshll $%d,%s\n", count, dst); }
                     88: static void pushl (char *src) { printf ("\tpushl %s\n", src); }
                     89: static void popl (char *dst) { printf ("\tpopl %s\n", dst); }
                     90: static void ret (void) { printf ("\tret\n"); }
1.1.1.2   root       91: static void align (int a) { printf ("\t.p2align %d,0x90\n", a); }
                     92: 
1.1       root       93: static void shiftleftl (int count, char *dst)
                     94: {
                     95:     if (count == 0)
                     96:        return;
                     97:     if (count < 0)
                     98:        shrl (-count, dst);
                     99:     else {
                    100:        char *indb0;
                    101:        switch (count) {
                    102:         case 1:
                    103:            addl (dst, dst);
                    104:            break;
                    105:         case 2: case 3:
                    106:            indb0 = gen_indx ("", 0, dst, 1 << count);
                    107:            leal (indb0, dst);
                    108:            free (indb0);
                    109:            break;
                    110:         default:
                    111:            shll (count, dst);
                    112:        }
                    113:     }
                    114: }
                    115: 
                    116: static void declare_fn (char *name)
                    117: {
                    118:     printf ("\t.globl %s\n", name);
1.1.1.2   root      119: /*    printf ("\t.type %s,@function\n", name); */
1.1       root      120:     align (5);
                    121:     printf ("%s:\n", name);
                    122: }
                    123: 
                    124: #define esi reg("esi")
                    125: #define edi reg("edi")
                    126: #define ebp reg("ebp")
                    127: #define esp reg("esp")
                    128: #define eax reg("eax")
                    129: #define ebx reg("ebx")
                    130: #define ecx reg("ecx")
                    131: #define edx reg("edx")
                    132: 
                    133: /* Modes:
                    134:  * 0: normal
                    135:  * 1: only generate every second plane, set memory
                    136:  * 2: only generate every second plane, starting at second plane, or to memory
                    137:  */
                    138: 
                    139: /* Normal code: one pixel per bit */
                    140: static void gen_x86_set_hires_h_toobad_k6_too_slow_someone_try_this_with_a_ppro (int pl, int mode)
                    141: {
                    142:     int plmul = mode == 0 ? 1 : 2;
                    143:     int ploff = mode == 2 ? 1 : 0;
                    144:     int i;
                    145:     int loop;
                    146:     char buf[40];
                    147:     char *indb0;
                    148: 
1.1.1.2   root      149:     sprintf (buf, sym (set_hires_h_%d_%d), pl, mode);
1.1       root      150:     declare_fn (buf);
                    151: 
                    152:     pushl (ebp);
                    153:     pushl (esi);
                    154:     pushl (edi);
                    155:     pushl (ebx);
                    156: 
                    157:     if (pl == 0) {
                    158:        movl (ind (esp, 20), ebp);
                    159:        movl (ind (esp, 24), esi);
                    160:     }
                    161:     movl (imm (0), edi);
                    162: 
                    163:     loop = get_label ();
                    164:     jmp (loop);
                    165:     align (5);
                    166:     declare_label (loop);
                    167: 
                    168:     if (pl > 0)
                    169:       movl (ind (esp, 24), esi);
                    170:     if (mode == 2) {
                    171:        if (pl > 0)
                    172:          movl (ind (esp, 20), ebp);
                    173:        movl (indx (ebp, 0, edi, 8), ecx);
                    174:        movl (indx (ebp, 4, edi, 8), ebx);
                    175:     }
                    176:     for (i = 0; i <= pl; i+=2) {
                    177:        int realpl = i * plmul + ploff;
                    178:        char *data1 = (i == 0 && mode != 2 ? ecx : edx);
                    179:        char *data2 = (i == 0 && mode != 2 ? ebx : eax);
                    180: 
                    181:        if (i < pl) {
                    182:            indb0 = gen_indx (esi, (realpl + plmul)*MAX_WORDS_PER_LINE*2, edi, 1);
                    183:            movzbl (indb0, ebp);
                    184:            free (indb0);
                    185:            imull (0x08040201, ebp);
                    186:        }
                    187: 
                    188:        indb0 = gen_indx (esi, realpl*MAX_WORDS_PER_LINE*2, edi, 1);
                    189:        movzbl (indb0, data2);
                    190:        free (indb0);
                    191: 
                    192:        if (i == pl || i == pl - 1)
                    193:            incl (edi);
                    194:        imull (0x08040201, data2);
                    195:        if (i < pl) {
                    196:            movl (ebp, esi);
                    197:            andl (0x08080808, ebp);
                    198:            shiftleftl (realpl + plmul - 7, esi);
                    199:        }
                    200:        movl (data2, data1);
                    201:        andl (0x08080808, data2);
                    202:        shiftleftl (realpl - 7, data1);
                    203:        if (i < pl) {
                    204:            andl (0x01010101 << (realpl + plmul), esi);
                    205:        }
                    206:        andl (0x01010101 << realpl, data1);
                    207:        shiftleftl (realpl - 3, data2);
                    208:        if (i < pl) {
                    209:            shiftleftl (realpl + plmul - 3, ebp);
                    210:        }
                    211:        if (i < pl) {
                    212:            orl (esi, ecx);
                    213:            movl (ind (esp, 24), esi);
                    214:            orl (ebp, ebx);
                    215:        }
                    216:        if (i > 0 || mode == 2) {
                    217:            orl (edx, ecx);
                    218:            orl (eax, ebx);
                    219:        }
                    220:     }
                    221:     if (pl > 0)
                    222:       movl (ind (esp, 20), ebp);
                    223:     cmpl (ind (esp, 28), edi);
                    224:     movl (ecx, indx (ebp, -8, edi, 8));
                    225:     movl (ebx, indx (ebp, -4, edi, 8));
                    226:     jc (loop);
                    227: 
                    228:     popl (reg ("ebx"));
                    229:     popl (reg ("edi"));
                    230:     popl (reg ("esi"));
                    231:     popl (reg ("ebp"));
                    232:     ret ();
                    233:     printf ("\n\n");
                    234: }
                    235: 
                    236: static void gen_x86_set_hires_h (int pl, int mode)
                    237: {
                    238:     int plmul = mode == 0 ? 1 : 2;
                    239:     int ploff = mode == 2 ? 1 : 0;
                    240:     int i;
                    241:     int loop;
                    242:     char buf[40];
                    243:     char *indb0;
                    244: 
1.1.1.2   root      245:     sprintf (buf, sym (set_hires_h_%d_%d), pl, mode);
1.1       root      246:     declare_fn (buf);
                    247: 
                    248:     pushl (ebp);
                    249:     pushl (esi);
                    250:     pushl (edi);
                    251:     pushl (ebx);
                    252: 
                    253:     if (pl == 0) {
                    254:        movl (ind (esp, 20), ebp);
                    255:        movl (ind (esp, 24), esi);
                    256:     }
                    257:     movl (imm (0), edi);
                    258: 
                    259:     loop = get_label ();
                    260:     jmp (loop);
                    261:     align (5);
                    262:     declare_label (loop);
                    263: 
                    264:     if (pl > 0)
                    265:       movl (ind (esp, 24), esi);
                    266:     if (mode == 2) {
                    267:        if (pl > 0)
                    268:          movl (ind (esp, 20), ebp);
                    269:        movl (indx (ebp, 0, edi, 8), ecx);
                    270:        movl (indx (ebp, 4, edi, 8), ebx);
                    271:     }
                    272:     for (i = 0; i <= pl; i+=2) {
                    273:        int realpl = i * plmul + ploff;
                    274:        char *data1 = (i == 0 && mode != 2 ? ecx : edx);
                    275:        char *data2 = (i == 0 && mode != 2 ? ebx : eax);
                    276: 
                    277:        if (i < pl) {
                    278:            indb0 = gen_indx (esi, (realpl + plmul)*MAX_WORDS_PER_LINE*2, edi, 1);
                    279:            movzbl (indb0, ebp);
                    280:            free (indb0);
                    281:        }
                    282:        indb0 = gen_indx (esi, realpl*MAX_WORDS_PER_LINE*2, edi, 1);
                    283:        movzbl (indb0, data2);
                    284:        free (indb0);
                    285:        if (i < pl) {
                    286:            indb0 = gen_indsx ("", sym (hirestab_h), 0, ebp, 8);
                    287:            movl (indb0, esi);
                    288:            free (indb0);
                    289:            indb0 = gen_indsx ("", sym (hirestab_h), 4, ebp, 8);
                    290:            movl (indb0, ebp);
                    291:            free (indb0);
                    292:        }
                    293:        if (i == pl || i == pl - 1)
                    294:          incl (edi);
                    295:        indb0 = gen_indsx ("", sym (hirestab_h), 0, data2, 8);
                    296:        movl (indb0, data1);
                    297:        free (indb0);
                    298:        indb0 = gen_indsx ("", sym (hirestab_h), 4, data2, 8);
                    299:        movl (indb0, data2);
                    300:        free (indb0);
                    301:        switch (realpl) {
                    302:         case 0:
                    303:            if (i < pl) {
                    304:                addl (esi, esi);
                    305:                addl (ebp, ebp);
                    306:                if (plmul == 2) {
                    307:                    addl (esi, esi);
                    308:                    addl (ebp, ebp);
                    309:                }
                    310:            }
                    311:            break;
                    312:         case 1:
                    313:            if (i < pl) {
                    314:                indb0 = gen_indx ("", 0, esi, 4*plmul);
                    315:                leal (indb0, esi);
                    316:                free (indb0);
                    317:                indb0 = gen_indx ("", 0, ebp, 4*plmul);
                    318:                leal (indb0, ebp);
                    319:                free (indb0);
                    320:            }
                    321:            addl (data1, data1);
                    322:            addl (data2, data2);
                    323:            break;
                    324:         case 2:
                    325:            if (i < pl) {
                    326:                if (plmul == 1)
                    327:                    leal (indx ("", 0, esi, 8), esi);
                    328:                else
                    329:                    shll (4, esi);
                    330:            }
                    331:            addl (data1, data1);
                    332:            addl (data2, data2);
                    333:            if (i < pl) {
                    334:                if (plmul == 1)
                    335:                    leal (indx ("", 0, ebp, 8), ebp);
                    336:                else
                    337:                    shll (4, ebp);
                    338:            }
                    339:            addl (data1, data1);
                    340:            addl (data2, data2);
                    341:            break;
                    342:         case 3:
                    343:            if (i < pl)
                    344:              shll (3 + plmul, esi);
                    345:            indb0 = gen_indx ("", 0, data1, 8);
                    346:            leal (indb0, data1);
                    347:            free (indb0);
                    348:            if (i < pl)
                    349:              shll (3 + plmul, ebp);
                    350:            indb0 = gen_indx ("", 0, data2, 8);
                    351:            leal (indb0, data2);
                    352:            free (indb0);
                    353:            break;
                    354:         case 4: case 5: case 6: case 7:
                    355:            shll (realpl, data1);
                    356:            shll (realpl, data2);
                    357:            if (i < pl) {
                    358:                shll (realpl+plmul, esi);
                    359:                shll (realpl+plmul, ebp);
                    360:            }
                    361:            break;
                    362:        }
1.1.1.5 ! root      363: 
1.1       root      364:        if (i < pl) {
                    365:            orl (esi, ecx);
                    366:            orl (ebp, ebx);
                    367:            if (i + 2 <= pl)
                    368:              movl (ind (esp, 24), esi);
                    369:        }
                    370:        if (i + 2 > pl && pl > 0)
                    371:          movl (ind (esp, 20), ebp);
                    372:        if (i > 0 || mode == 2) {
                    373:            orl (data1, ecx);
                    374:            orl (data2, ebx);
                    375:        }
                    376:     }
                    377: 
                    378:     cmpl (ind (esp, 28), edi);
                    379:     movl (ecx, indx (ebp, -8, edi, 8));
                    380:     movl (ebx, indx (ebp, -4, edi, 8));
                    381:     jc (loop);
                    382: 
                    383:     popl (reg ("ebx"));
                    384:     popl (reg ("edi"));
                    385:     popl (reg ("esi"));
                    386:     popl (reg ("ebp"));
                    387:     ret ();
                    388:     printf ("\n\n");
                    389: }
                    390: 
1.1.1.5 ! root      391: /* Squeeze: every second bit does not generate a pixel
1.1       root      392:    Not optimized, this mode isn't useful. */
                    393: static void gen_x86_set_hires_l (int pl, int mode)
                    394: {
                    395:     int plmul = mode == 0 ? 1 : 2;
                    396:     int ploff = mode == 2 ? 1 : 0;
                    397:     int i;
                    398:     int loop;
                    399:     char buf[40];
                    400: 
1.1.1.2   root      401:     sprintf (buf, sym (set_hires_l_%d_%d), pl, mode);
1.1       root      402:     declare_fn (buf);
                    403: 
                    404:     pushl (ebp);
                    405:     pushl (esi);
                    406:     pushl (edi);
                    407:     pushl (ebx);
1.1.1.5 ! root      408: 
1.1       root      409:     movl (ind (esp, 20), ebp);
                    410:     movl (ind (esp, 24), esi);
                    411:     movl (imm (0), edi);
                    412: 
                    413:     align (5);
                    414:     loop = new_label ();
                    415: 
                    416:     if (mode == 2) {
                    417:        movl (indx (ebp, 0, edi, 1), ecx);
                    418:     }
                    419: 
                    420:     for (i = 0; i <= pl; i++) {
                    421:        int realpl = i * plmul + ploff;
                    422:        char *data1 = (i == 0 && mode != 2 ? ecx : edx);
                    423:        char *indb0;
                    424: 
                    425:        indb0 = gen_indx (esi, realpl*MAX_WORDS_PER_LINE*2, edi, 1);
                    426:        movzbl (indb0, data1);
                    427:        free (indb0);
                    428: 
                    429:        indb0 = gen_indsx ("", sym (hirestab_l), 0, data1, 4);
                    430:        movl (indb0, data1);
                    431:        free (indb0);
                    432:        if (i == pl)
                    433:            incl (edi);
                    434:        shiftleftl (realpl, data1);
                    435:        if (i > 0 || mode == 2) {
                    436:            orl (data1, ecx);
                    437:        }
                    438:     }
                    439:     cmpl (ind (esp, 28), edi);
                    440:     movl (ecx, indx (ebp, -4, edi, 4));
                    441:     jc (loop);
                    442: 
                    443:     popl (reg ("ebx"));
                    444:     popl (reg ("edi"));
                    445:     popl (reg ("esi"));
                    446:     popl (reg ("ebp"));
                    447:     ret ();
                    448:     printf ("\n\n");
                    449: }
                    450: 
                    451: /* Stretch: two pixels per bit */
                    452: static void gen_x86_set_lores_h (int pl, int mode)
                    453: {
                    454:     int plmul = mode == 0 ? 1 : 2;
                    455:     int ploff = mode == 2 ? 1 : 0;
                    456:     int i, j;
                    457:     int loop;
                    458:     char buf[40];
                    459: 
1.1.1.2   root      460:     sprintf (buf, sym (set_lores_h_%d_%d), pl, mode);
1.1       root      461:     declare_fn (buf);
                    462: 
                    463:     pushl (ebp);
                    464:     pushl (esi);
                    465:     pushl (edi);
                    466:     pushl (ebx);
1.1.1.5 ! root      467: 
1.1       root      468:     movl (ind (esp, 20), ebp);
                    469:     movl (ind (esp, 24), esi);
                    470:     movl (imm (0), edi);
                    471: 
                    472:     align (5);
                    473:     loop = new_label ();
                    474: 
                    475:     for (j = 0; j < 2; j++) {
                    476:        if (mode == 2) {
                    477:            movl (j ? ind (ebp, 8) : ind (ebp, 0), ecx);
                    478:            movl (j ? ind (ebp, 12) : ind (ebp, 4), ebx);
                    479:        }
                    480: 
                    481:        for (i = 0; i <= pl; i++) {
                    482:            int realpl = i * plmul + ploff;
                    483:            char *data1 = (i == 0 && mode != 2 ? ecx : edx);
                    484:            char *data2 = (i == 0 && mode != 2 ? ebx : eax);
                    485:            char *indb0;
1.1.1.5 ! root      486: 
1.1       root      487:            indb0 = gen_indx (esi, realpl*MAX_WORDS_PER_LINE*2, edi, 1);
                    488:            movzbl (indb0, data2);
                    489:            free (indb0);
                    490:            addl (data2, data2);
                    491:            indb0 = gen_indsx ("", sym (lorestab_h), 0 + j*8, data2, 8);
                    492:            movl (indb0, data1);
                    493:            free (indb0);
                    494:            indb0 = gen_indsx ("", sym (lorestab_h), 4 + j*8, data2, 8);
                    495:            movl (indb0, data2);
                    496:            free (indb0);
                    497:            shiftleftl (realpl, data1);
                    498:            shiftleftl (realpl, data2);
                    499:            if (i > 0 || mode == 2) {
                    500:                orl (data1, ecx);
                    501:                orl (data2, ebx);
                    502:            }
                    503:        }
                    504:        movl (ecx, j ? ind (ebp, 8) : ind (ebp, 0));
                    505:        movl (ebx, j ? ind (ebp, 12) : ind (ebp, 4));
                    506:     }
                    507:     incl (edi);
                    508:     cmpl (ind (esp, 28), edi);
                    509:     leal (ind (ebp, 16), ebp);
                    510:     jc (loop);
                    511: 
                    512:     popl (reg ("ebx"));
                    513:     popl (reg ("edi"));
                    514:     popl (reg ("esi"));
                    515:     popl (reg ("ebp"));
                    516:     ret ();
                    517:     printf ("\n\n");
                    518: }
                    519: 
                    520: 
                    521: /* Normal code: one pixel per bit */
                    522: static void gen_c_set_hires_h (int pl, int mode, int header)
                    523: {
                    524:     int plmul = mode == 0 ? 1 : 2;
                    525:     int ploff = mode == 2 ? 1 : 0;
                    526:     int i;
                    527: 
                    528:     if (header)
                    529:        printf("extern ");
                    530:     printf ("void set_hires_h_%d_%d (uae_u32 *app, uae_u8 *ptr, int len)", pl, mode);
                    531:     if (header) {
                    532:        printf (";\n");
                    533:        return;
                    534:     }
                    535: 
                    536:     printf ("\n\{\n\tint i;\n\tfor (i = 0; i < len; i++) {\n\t\tuae_u32 v1, v2;\n");
                    537: 
                    538:     if (mode == 2) {
                    539:        printf ("\t\tv1 = app[i*2 + 0]; v2 = app[i*2 + 1];\n");
                    540:     }
                    541: 
                    542:     for (i = 0; i <= pl; i++) {
                    543:        int realpl = i * plmul + ploff;
                    544:        char *asgn = (i == 0 && mode != 2 ? "=" : "|=");
1.1.1.5 ! root      545: 
1.1       root      546:        printf ("\t\t{\n");
                    547:        printf ("\t\t\tunsigned int data = *(ptr + i  + %d);\n", MAX_WORDS_PER_LINE*2*realpl);
1.1.1.5 ! root      548: 
1.1       root      549:        printf ("\t\t\tv1 %s hirestab_h[data][0] << %d;\n", asgn, realpl);
                    550:        printf ("\t\t\tv2 %s hirestab_h[data][1] << %d;\n", asgn, realpl);
                    551:        printf ("\t\t}\n");
                    552:     }
                    553:     printf ("\t\tapp[i*2 + 0] = v1;\n");
                    554:     printf ("\t\tapp[i*2 + 1] = v2;\n");
                    555:     printf ("\t}\n");
                    556:     printf ("}\n\n");
                    557: }
                    558: 
1.1.1.5 ! root      559: /* Squeeze: every second bit does not generate a pixel
1.1       root      560:    Not optimized, this mode isn't useful. */
                    561: static void gen_c_set_hires_l (int pl, int mode, int header)
                    562: {
                    563:     int plmul = mode == 0 ? 1 : 2;
                    564:     int ploff = mode == 2 ? 1 : 0;
                    565:     int i;
                    566: 
                    567:     if (header)
                    568:        printf("extern ");
                    569:     printf ("void set_hires_l_%d_%d (uae_u32 *app, uae_u8 *ptr, int len)", pl, mode);
                    570:     if (header) {
                    571:        printf (";\n");
                    572:        return;
                    573:     }
                    574: 
                    575:     printf ("\n\{\n\tint i;\n\tfor (i = 0; i < len; i++) {\n\t\tuae_u32 v1;\n");
                    576: 
                    577:     if (mode == 2) {
                    578:        printf ("\t\tv1 = app[i];\n");
                    579:     }
                    580: 
                    581:     for (i = 0; i <= pl; i++) {
                    582:        int realpl = i * plmul + ploff;
                    583:        char *asgn = (i == 0 && mode != 2 ? "=" : "|=");
1.1.1.5 ! root      584: 
1.1       root      585:        printf ("\t\t{\n");
                    586:        printf ("\t\t\tunsigned int data = *(ptr + i  + %d);\n", MAX_WORDS_PER_LINE*2*realpl);
                    587: 
                    588:        printf ("\t\t\tv1 %s hirestab_l[data][0] << %d;\n", asgn, realpl);
                    589:        printf ("\t\t}\n");
                    590:     }
                    591:     printf ("\t\tapp[i] = v1;\n");
                    592:     printf ("\t}\n");
                    593:     printf ("}\n\n");
                    594: }
                    595: 
                    596: /* Stretch: two pixels per bit */
                    597: static void gen_c_set_lores_h (int pl, int mode, int header)
                    598: {
                    599:     int plmul = mode == 0 ? 1 : 2;
                    600:     int ploff = mode == 2 ? 1 : 0;
1.1.1.2   root      601:     int i;
1.1       root      602: 
                    603:     if (header)
                    604:        printf("extern ");
                    605:     printf ("void set_lores_h_%d_%d (uae_u32 *app, uae_u8 *ptr, int len)", pl, mode);
                    606:     if (header) {
                    607:        printf (";\n");
                    608:        return;
                    609:     }
                    610: 
                    611:     printf ("\n\{\n\tint i;\n\tfor (i = 0; i < len; i++) {\n\t\tuae_u32 v1, v2, v3, v4;\n");
                    612: 
                    613:     if (mode == 2) {
                    614:        printf ("\t\tv1 = app[i*4 + 0]; v2 = app[i*4 + 1]; v3 = app[i*4 + 2]; v4 = app[i*4 + 3];\n");
                    615:     }
                    616: 
                    617:     for (i = 0; i <= pl; i++) {
                    618:        int realpl = i * plmul + ploff;
                    619:        char *asgn = (i == 0 && mode != 2 ? "=" : "|=");
                    620: 
                    621:        printf ("\t\t{\n");
                    622:        printf ("\t\t\tunsigned int data = *(ptr + i  + %d);\n", MAX_WORDS_PER_LINE*2*realpl);
                    623: 
                    624:        printf ("\t\t\tv1 %s lorestab_h[data][0] << %d;\n", asgn, realpl);
                    625:        printf ("\t\t\tv2 %s lorestab_h[data][1] << %d;\n", asgn, realpl);
                    626:        printf ("\t\t\tv3 %s lorestab_h[data][2] << %d;\n", asgn, realpl);
                    627:        printf ("\t\t\tv4 %s lorestab_h[data][3] << %d;\n", asgn, realpl);
                    628:        printf ("\t\t}\n");
                    629:     }
                    630:     printf ("\t\tapp[i*4 + 0] = v1;\n");
                    631:     printf ("\t\tapp[i*4 + 1] = v2;\n");
                    632:     printf ("\t\tapp[i*4 + 2] = v3;\n");
                    633:     printf ("\t\tapp[i*4 + 3] = v4;\n");
                    634:     printf ("\t}\n");
                    635:     printf ("}\n\n");
                    636: }
                    637: 
                    638: int main(int argc, char **argv)
                    639: {
                    640:     int pl;
                    641:     int outmode;
                    642: 
                    643:     if (argc != 2)
                    644:        return 1;
                    645:     if (strcmp (argv[1], "C") == 0)
                    646:        outmode = 0;
                    647:     else if (strcmp (argv[1], "H") == 0)
                    648:        outmode = 1;
                    649:     else if (strcmp (argv[1], "x86") == 0)
                    650:        outmode = 2;
                    651:     else
                    652:        return 1;
                    653: 
                    654:     switch (outmode) {
                    655:      case 0:
                    656:        printf ("#include \"sysconfig.h\"\n");
                    657:        printf ("#include \"sysdeps.h\"\n");
                    658:        printf ("#include \"custom.h\"\n");
                    659:        printf ("#include \"p2c.h\"\n");
                    660:        break;
                    661:      case 1:
                    662:        printf ("#define MAX_WORDS_PER_LINE %d\n", MAX_WORDS_PER_LINE);
                    663:        break;
                    664:      case 2:
                    665:        printf ("#define MAX_WORDS_PER_LINE %d\n", MAX_WORDS_PER_LINE);
                    666:        printf (".text\n");
                    667:        break;
                    668:     }
                    669:     for (pl = 0; pl < 8; pl++) {
                    670:        int j;
                    671:        for (j = 0; j < (pl < 4 ? 3 : 1); j++) {
                    672:            switch (outmode) {
                    673:             case 0: case 1:
                    674:                gen_c_set_hires_h (pl, j, outmode);
                    675:                gen_c_set_hires_l (pl, j, outmode);
                    676:                gen_c_set_lores_h (pl, j, outmode);
                    677:                break;
                    678:             case 2:
                    679:                gen_x86_set_hires_h (pl, j);
                    680:                gen_x86_set_hires_l (pl, j);
                    681:                gen_x86_set_lores_h (pl, j);
                    682:                break;
                    683:            }
                    684:        }
                    685:     }
                    686: 
                    687:     return 0;
                    688: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.