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

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

unix.superglobalmegacorp.com

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