Ticket #7365: agos_simon1_amiga.diff

File agos_simon1_amiga.diff, 15.2 KB (added by cyxx, 17 years ago)

simon1 amiga demo bitplane graphics display

  • agos/agos.h

     
    558558        void setUserItem(Item *item, int n, int m);
    559559
    560560        void paletteFadeOut(byte *palPtr, uint num, uint size);
    561        
     561
    562562        byte *allocateItem(uint size);
    563563        byte *allocateTable(uint size);
    564564        void alignTableMem();
     
    796796        void drawIconArray_Simon(uint i, Item *item_ptr, int line, int classMask);
    797797        void removeIconArray(uint num);
    798798
    799         void loadIconData();   
     799        void loadIconData();
    800800        void loadIconFile();
    801801        void loadMenuFile();
    802802
     
    11191119        void oe1_printPlayerHit();
    11201120        void oe1_printMonsterHit();
    11211121
    1122         int16 levelOf(Item *item); 
     1122        int16 levelOf(Item *item);
    11231123        int16 moreText(Item *i);
    11241124        void lobjFunc(Item *i, const char *f);
    11251125        uint confirmQuit();
     
    12781278
    12791279        void drawImages(VC10_state *state);
    12801280        void drawImages_Simon(VC10_state *state);
     1281        void drawImages_SimonAmiga(VC10_state *state);
    12811282        void drawImages_Feeble(VC10_state *state);
    12821283
    12831284        void scaleClip(int16 h, int16 w, int16 y, int16 x, int16 scrollY);
  • agos/vga.cpp

     
    634634                                state.flags |= kDFCompressed;
    635635                        }
    636636                }
     637                if (getPlatform() == Common::kPlatformAmiga && !(flags & 0x80)) {
     638                        // decoded data in res_ami.cpp is always uncompressed
     639                        if (state.flags & kDFCompressedFlip) {
     640                                state.flags &= ~kDFCompressedFlip;
     641                                state.flags |= kDFFlip;
     642                        }
     643                        if (state.flags & kDFCompressed) {
     644                                state.flags &= ~kDFCompressed;
     645                        }
     646                }
    637647        }
    638648
    639649        state.width = state.draw_width = width;         /* cl */
     
    654664                return;
    655665        }
    656666
     667        state.surf2_addr = getFrontBuf();
     668        state.surf2_pitch = _dxSurfacePitch;
     669
     670        state.surf_addr = getBackBuf();
     671        state.surf_pitch = _dxSurfacePitch;
     672
     673        if (getPlatform() == Common::kPlatformAmiga && getGameType() == GType_SIMON1) {
     674                drawImages_SimonAmiga(&state);
     675                return;
     676        }
     677
    657678        if (getGameType() != GType_FF && getGameType() != GType_PP) {
    658679                if (state.flags & kDFCompressedFlip) {
    659680                        state.depack_src = vc10_uncompressFlip(state.depack_src, width, height);
     
    662683                }
    663684        }
    664685
    665         state.surf2_addr = getFrontBuf();
    666         state.surf2_pitch = _dxSurfacePitch;
    667 
    668         state.surf_addr = getBackBuf();
    669         state.surf_pitch = _dxSurfacePitch;
    670 
    671686        if (getGameType() == GType_FF || getGameType() == GType_PP) {
    672687                drawImages_Feeble(&state);
    673688        } else if (getGameType() == GType_SIMON1 || getGameType() == GType_SIMON2) {
     
    11071122
    11081123        if (num == 3) {
    11091124                memset(getBackBuf(), 0, _screenWidth * _screenHeight);
    1110         } else { 
     1125        } else {
    11111126                const uint16 *vlut = &_videoWindows[num * 4];
    11121127                byte *dst = getBackBuf() + vlut[0] * 16 + vlut[1] * _dxSurfacePitch;
    11131128
  • agos/res_ami.cpp

     
    2929
    3030namespace AGOS {
    3131
    32 byte *buffer;
    33 byte *bufptr;
    34 byte *bufferout;
    35 byte *bufptrout;
    36 uint32 bufoutend;
    37 byte *clipptr;
    38 byte *clipoutptr;
    39 int clipnumber;
     32static byte *buffer;
     33static byte *bufptr;
     34static byte *bufferout;
     35static byte *bufptrout;
     36static uint32 bufoutend;
     37static byte *clipptr;
     38static byte *clipoutptr;
    4039
    4140static void uncompressplane(byte *plane, byte *outptr, uint16 length) {
    4241        debug(10, "uncompressplane: length %d", length);
    43 
    44         char x;
    45         byte y, z;
    46         while (length) {
    47                 x = *plane++;
     42        while (length != 0) {
     43                char x = *plane++;
    4844                if (x >= 0) {
    49                         x += 1;
    50                         y = *plane++;
    51                         z = *plane++;
    52                         while (x) {
     45                        x++;
     46                        byte y = *plane++;
     47                        byte z = *plane++;
     48                        while (x != 0) {
    5349                                *outptr++ = y;
    5450                                *outptr++ = z;
    55                                 length--;
    56                                 if (length == 0)
     51                                if (--length == 0)
    5752                                        break;
    5853                                x--;
    5954                        }
    6055                } else {
    61                         while (x) {
     56                        while (x != 0) {
    6257                                *outptr++ = *plane++;
    6358                                *outptr++ = *plane++;
    64                                 length--;
    65                                 if (length == 0)
     59                                if (--length == 0)
    6660                                        break;
    6761                                x++;
    6862                        }
     
    7064        }
    7165}
    7266
    73 static void convertcompressedclip(uint16 height, uint16 width) {
     67static void decodeBitPlaneData(uint16 *w, bool is32Colors, uint8 *&dst) {
     68        for (int j = 0; j < 8; j++) {
     69                byte color1 = 0;
     70                byte color2 = 0;
     71                for (int p = 0; p < 5; ++p) {
     72                        if (w[p] & 0x8000) {
     73                                color1 |= 1 << p;
     74                        }
     75                        if (w[p] & 0x4000) {
     76                                color2 |= 1 << p;
     77                        }
     78                        w[p] <<= 2;
     79                }
     80                if (is32Colors) {
     81                        *dst++ = color1;
     82                        *dst++ = color2;
     83                } else {
     84                        *dst++ = color1 * 16 + color2;
     85                }
     86        }
     87}
     88
     89static void convertcompressedclip(bool is32Colors, uint16 height, uint16 width) {
    7490        debug(10, "convertcompressedclip: height %d width %d", height, width);
    7591
    7692        byte *plane0;
    7793        byte *plane1;
    7894        byte *plane2;
    7995        byte *plane3;
     96        byte *plane4;
    8097        byte *uncbuffer;
    8198        byte *uncptr0;
    8299        byte *uncptr1;
    83100        byte *uncptr2;
    84101        byte *uncptr3;
     102        byte *uncptr4;
    85103        byte *uncbfrout;
    86104        byte *uncbfroutptr;
    87         uint16 length, i, j, k, word1, word2, word3, word4, cliplength;
    88         byte outbyte, outbyte1, x, y;
    89         char n;
    90         uncbuffer = (byte *)malloc(height * width * 4);
    91         uncbfrout = (byte *)malloc(height * width * 4);
    92        
     105        uint32 length, i, j;
     106        uint16 w[5];
     107        uncbuffer = (byte *)malloc(height * width * 5);
     108        uncbfrout = (byte *)malloc(height * width * 5);
     109
    93110        byte *free_uncbuffer = uncbuffer;
    94111        byte *free_uncbfrout = uncbfrout;
    95        
    96         length = width / 16;
    97         length *= height;
    98         plane0 = READ_BE_UINT16(clipptr) + READ_BE_UINT16(clipptr + 2) + clipptr; clipptr += 4; plane0 += 4;
    99         plane1 = READ_BE_UINT16(clipptr) + READ_BE_UINT16(clipptr + 2) + clipptr; clipptr += 4; plane1 += 4;
    100         plane2 = READ_BE_UINT16(clipptr) + READ_BE_UINT16(clipptr + 2) + clipptr; clipptr += 4; plane2 += 4;
    101         plane3 = READ_BE_UINT16(clipptr) + READ_BE_UINT16(clipptr + 2) + clipptr; clipptr += 4; plane3 += 4;
    102         plane0 -= 4;
    103         plane1 -= 8;
    104         plane2 -= 12;
    105         plane3 -= 16;
     112
     113        length = (width + 15) / 16 * height;
     114
     115        plane0 = clipptr + READ_BE_UINT16(clipptr + 0) + READ_BE_UINT16(clipptr + 2);
     116        plane1 = clipptr + READ_BE_UINT16(clipptr + 4) + READ_BE_UINT16(clipptr + 6);
     117        plane2 = clipptr + READ_BE_UINT16(clipptr + 8) + READ_BE_UINT16(clipptr + 10);
     118        plane3 = clipptr + READ_BE_UINT16(clipptr + 12) + READ_BE_UINT16(clipptr + 14);
     119        if (is32Colors) {
     120                plane4 = clipptr + READ_BE_UINT16(clipptr + 16) + READ_BE_UINT16(clipptr + 18);
     121        }
     122
    106123        uncptr0 = uncbuffer;
    107124        uncptr1 = uncptr0+(length*2);
    108125        uncptr2 = uncptr1+(length*2);
    109126        uncptr3 = uncptr2+(length*2);
     127        if (is32Colors) {
     128                uncptr4 = uncptr3+(length*2);
     129        }
    110130        uncompressplane(plane0, uncptr0, length);
    111131        uncompressplane(plane1, uncptr1, length);
    112132        uncompressplane(plane2, uncptr2, length);
    113133        uncompressplane(plane3, uncptr3, length);
     134        if (is32Colors) {
     135                uncompressplane(plane4, uncptr4, length);
     136        }
    114137        uncbfroutptr = uncbfrout;
     138
    115139        for (i = 0; i < length; i++) {
    116                 word1=READ_BE_UINT16(uncptr0); uncptr0 += 2;
    117                 word2=READ_BE_UINT16(uncptr1); uncptr1 += 2;
    118                 word3=READ_BE_UINT16(uncptr2); uncptr2 += 2;
    119                 word4=READ_BE_UINT16(uncptr3); uncptr3 += 2;
    120                 for (j = 0; j < 8; j++) {
    121                         outbyte = ((word1 / 32768) + ((word2 / 32768) * 2) + ((word3 / 32768) * 4) + ((word4 / 32768) * 8));
    122                         word1 <<= 1;
    123                         word2 <<= 1;
    124                         word3 <<= 1;
    125                         word4 <<= 1;
    126                         outbyte1 = ((word1 / 32768) + ((word2 / 32768) * 2) + ((word3 / 32768) * 4) + ((word4 / 32768) * 8));
    127                         word1 <<= 1;
    128                         word2 <<= 1;
    129                         word3 <<= 1;
    130                         word4 <<= 1;
    131                         *uncbfroutptr++ = (outbyte * 16 + outbyte1);
     140                w[0] = READ_BE_UINT16(uncptr0); uncptr0 += 2;
     141                w[1] = READ_BE_UINT16(uncptr1); uncptr1 += 2;
     142                w[2] = READ_BE_UINT16(uncptr2); uncptr2 += 2;
     143                w[3] = READ_BE_UINT16(uncptr3); uncptr3 += 2;
     144                if (is32Colors) {
     145                        w[4] = READ_BE_UINT16(uncptr4); uncptr4 += 2;
     146                } else {
     147                        w[4] = 0;
    132148                }
     149                decodeBitPlaneData(w, is32Colors, uncbfroutptr);
    133150        }
    134         uncptr0 = uncbuffer;
    135         uncptr1 = uncbfrout;
    136         uncptr2 = uncbfrout;
    137         uncptr3 = uncbfrout;
    138         for (i = 0; i < (width / 16); i++) {
    139                 for (k = 0; k < 8; k++) {
    140                         for (j = 0; j < height; j++) {
    141                                 *uncptr0++ = *uncptr1;
    142                                 uncptr1 += 8;
     151        const uint8 *src = uncbfrout;
     152        if (is32Colors) {
     153                for (i = 0; i < width / 16; ++i) {
     154                        for (j = 0; j < height; ++j) {
     155                                memcpy(clipoutptr + width * j + 16 * i, src, 16);
     156                                src += 16;
     157                                bufoutend += 16;
    143158                        }
    144                         uncptr2++;
    145                         uncptr1 = uncptr2;
    146159                }
    147                 uncptr3 += (height * 8);
    148                 uncptr2 = uncptr3;
    149                 uncptr1 = uncptr2;
    150         }
    151         length *= 8;
    152         cliplength = 0;
    153         while(1) {
    154                 if (length == 1) {
    155                         *clipoutptr++ = 0xFF; bufoutend++;
    156                         *clipoutptr++ = *uncbuffer; bufoutend++;
    157                         cliplength += 2;
    158                         break;
    159                 }
    160                 x = *uncbuffer++;
    161                 y = *uncbuffer++;
    162                 length -= 2;
    163                 if (x == y) {
    164                         n = 1;
    165                         y = *uncbuffer++;
    166                         if (length == 0) {
    167                                 *clipoutptr++ = n; bufoutend++;
    168                                 *clipoutptr++ = x; bufoutend++;
    169                                 cliplength += 2;
    170                                 break;
     160        } else {
     161                for (i = 0; i < width / 16; ++i) {
     162                        for (j = 0; j < height; ++j) {
     163                                memcpy(clipoutptr + width / 2 * j + 8 * i, src, 8);
     164                                src += 8;
     165                                bufoutend += 8;
    171166                        }
    172                         length--;
    173                         while (x == y)  {
    174                                 n++;
    175                                 y = *uncbuffer++;
    176                                 if (length == 0)
    177                                         break;
    178                                 length--;
    179                                 if(n == 127)
    180                                         break;
    181                         }
    182                         *clipoutptr++ = n; bufoutend++;
    183                         *clipoutptr++ = x; bufoutend++;
    184                         cliplength += 2;
    185                         uncbuffer--;
    186                         if (length == 0)
    187                                 break;
    188                         length++;
    189                 } else {
    190                         n =- 1;
    191                         uncptr0 = clipoutptr;
    192                         clipoutptr++;
    193                         bufoutend++;
    194                         *clipoutptr++ = x; bufoutend++;
    195                         cliplength += 2;
    196                         x = y;
    197                         y = *uncbuffer++;
    198                         if (length == 0) {
    199                                 *uncptr0 = n;
    200                                 break;
    201                         }
    202                         length--;
    203                         while (x != y) {
    204                                 if (n == -127)
    205                                         break;
    206                                 n--;
    207                                 *clipoutptr++ = x; bufoutend++;
    208                                 cliplength++;
    209                                 x = y;
    210                                 y = *uncbuffer++;
    211                                 if (length == 0)
    212                                         break;
    213                                 length--;
    214                         }
    215                         *uncptr0 = n;
    216                         if (length == 0)
    217                                 break;
    218                         uncbuffer -= 2;
    219                         length += 2;
    220167                }
    221168        }
    222         if (cliplength > (height * width / 2))
    223                 warning("Negative compression. Clip %d. %d bytes bigger.",clipnumber,(cliplength-(height*width/2)));
    224169        free(free_uncbuffer);
    225170        free(free_uncbfrout);
    226171}
    227172
    228 static void convertclip(uint32 offset, uint16 height, uint16 width) {
     173static void convertclip(bool is32Colors, uint32 offset, uint16 height, uint16 width) {
    229174        debug(10, "convertclip: height %d width %d", height, width);
    230175
    231         uint32 length, i, j;
    232         uint16 word1, word2, word3, word4;
    233         byte outbyte, outbyte1;
     176        uint32 length, i;
    234177        clipptr = offset + buffer;
    235178        clipoutptr = bufoutend + bufferout;
    236179        WRITE_BE_UINT32(bufptrout, bufoutend); bufptrout += 4;
    237         WRITE_BE_UINT16(bufptrout, height); bufptrout += 2;
     180        WRITE_BE_UINT16(bufptrout, height & ~0x8000); bufptrout += 2; // always flag the bitmap as uncompressed
    238181        WRITE_BE_UINT16(bufptrout, width); bufptrout += 2;
    239         if (height > 32000) {
    240                 convertcompressedclip((uint16)(height - 32768), width);
     182        if (height & 0x8000) {
     183                convertcompressedclip(is32Colors, height & ~0x8000, width);
    241184        } else {
    242                 width /= 16;
    243                 length = height * width;
     185                length = (width + 15) / 16 * height;
    244186                for (i = 0; i < length; i++) {
    245                         word1 = READ_BE_UINT16(clipptr); clipptr += 2;
    246                         word2 = READ_BE_UINT16(clipptr); clipptr += 2;
    247                         word3 = READ_BE_UINT16(clipptr); clipptr += 2;
    248                         word4 = READ_BE_UINT16(clipptr); clipptr += 2;
    249                         for (j = 0; j < 8; j++) {
    250                                 outbyte = ((word1 / 32768) + ((word2 / 32768) * 2) + ((word3 / 32768) * 4) + ((word4 / 32768) * 8));
    251                                 word1 <<= 1;
    252                                 word2 <<= 1;
    253                                 word3 <<= 1;
    254                                 word4 <<= 1;
    255                                 outbyte1 = ((word1 / 32768) + ((word2 / 32768) * 2) + ((word3 / 32768) * 4) + ((word4 / 32768) * 8));
    256                                 word1 <<= 1;
    257                                 word2 <<= 1;
    258                                 word3 <<= 1;
    259                                 word4 <<= 1;
    260                                 *clipoutptr++ = (outbyte * 16 + outbyte1); bufoutend++;
     187                        uint16 w[5];
     188                        w[0] = READ_BE_UINT16(clipptr); clipptr += 2;
     189                        w[1] = READ_BE_UINT16(clipptr); clipptr += 2;
     190                        w[2] = READ_BE_UINT16(clipptr); clipptr += 2;
     191                        w[3] = READ_BE_UINT16(clipptr); clipptr += 2;
     192                        if (is32Colors) {
     193                                w[4] = READ_BE_UINT16(clipptr); clipptr += 2;
     194                        } else {
     195                                w[4] = 0;
    261196                        }
     197                        decodeBitPlaneData(w, is32Colors, clipoutptr);
     198                        bufoutend += is32Colors ? 16 : 8;
    262199                }
    263200        }
    264201}
     
    272209                return;
    273210        }
    274211
     212        bool is32Colors = getGameType() == GType_SIMON1;
     213
    275214        uint32 clipoffset, outlength;
    276215        uint16 clipwidth, clipheight;
    277216        byte *clipsend;
     
    282221        memcpy(buffer, srcBuf, fileSize);
    283222        bufptr = buffer;
    284223
    285         bufferout = (byte *)malloc((int32)(fileSize * 2));
     224        bufferout = (byte *)malloc((int32)(fileSize * 4));
    286225        bufptr = buffer;
    287226        bufptrout = bufferout;
    288         clipnumber = 0;
    289227        while(1) {
    290228                clipoffset = READ_BE_UINT32(bufptr); bufptr += 4;
    291229                clipheight = READ_BE_UINT16(bufptr); bufptr += 2;
     
    294232                        break;
    295233                WRITE_BE_UINT32(bufptrout, 0); bufptrout += 4;
    296234                WRITE_BE_UINT32(bufptrout, 0); bufptrout += 4;
    297                 clipnumber++;
    298235        }
    299236
    300237        clipsend = buffer + clipoffset;
    301238        bufoutend = clipoffset;
    302239        while (bufptr <= clipsend) {
    303240                if (clipoffset != 0) {
    304                         convertclip(clipoffset, clipheight, clipwidth);
     241                        convertclip(is32Colors, clipoffset, clipheight, clipwidth);
    305242                } else {
    306243                        WRITE_BE_UINT32(bufptrout, 0); bufptrout += 4;
    307244                        WRITE_BE_UINT32(bufptrout, 0); bufptrout += 4;
     
    309246                clipoffset = READ_BE_UINT32(bufptr); bufptr += 4;
    310247                clipheight = READ_BE_UINT16(bufptr); bufptr += 2;
    311248                clipwidth = READ_BE_UINT16(bufptr); bufptr += 2;
    312                 clipnumber++;
    313249        }
    314250        outlength = bufoutend;
    315         debug(10, "convertAmiga: outlength %d",outlength);
     251        printf("convertAmiga: outlength %d\n",outlength);
    316252
    317253        byte *dstBuf = allocBlock (outlength);
    318254        memcpy(dstBuf, bufferout, outlength);
     
    320256        free(bufferout);
    321257}
    322258
     259
    323260} // End of namespace AGOS
  • agos/gfx.cpp

     
    175175
    176176        if (getGameType() != GType_FF && getGameType() != GType_PP) {
    177177                state->draw_width = state->width * 2;
    178         } 
     178        }
    179179
    180180        cur = state->x;
    181181        if (cur < 0) {
     
    384384                        dst += _screenWidth;
    385385                        src += state->width;
    386386                } while (--state->draw_height);
    387         } 
     387        }
    388388}
    389389
    390390void AGOSEngine::drawImages_Simon(VC10_state *state) {
     
    589589        }
    590590}
    591591
     592void AGOSEngine::drawImages_SimonAmiga(VC10_state *state) {
     593        uint8 *dst;
     594        const byte *src;
     595        const uint16 *vlut = &_videoWindows[_windowNum * 4];
     596
     597        if (drawImages_clip(state) == 0)
     598                return;
     599
     600        uint xoffs = ((vlut[0] - _videoWindows[16]) * 2 + state->x) * 8;
     601        uint yoffs = (vlut[1] - _videoWindows[17] + state->y);
     602
     603        state->surf2_addr += xoffs + yoffs * state->surf_pitch;
     604        state->surf_addr += xoffs + yoffs * state->surf2_pitch;
     605
     606        if (state->flags & (kDFCompressedFlip | kDFFlip)) {
     607                const uint flipw = state->width * 16;
     608                src = state->depack_src;
     609                for (int y = 0; y < state->height; ++y) {
     610                        dst = _videoBuf1 + (y + 1) * flipw;
     611                        for (uint i = 0; i < flipw; ++i) {
     612                                *--dst = *src++;
     613                        }
     614                }
     615                state->depack_src = _videoBuf1;
     616        }
     617
     618        if (state->flags & kDFMasked) {
     619//              warning("Unhandled kDFMasked");
     620        }
     621
     622        src = state->depack_src + (state->width * state->y_skip * 16) + (state->x_skip * 8);
     623        dst = state->surf_addr;
     624
     625        state->draw_width *= 2;
     626
     627        uint h = state->draw_height;
     628        do {
     629                for (uint i = 0; i != state->draw_width; i++)
     630                        if ((state->flags & kDFNonTrans) || src[i])
     631                                dst[i] = src[i];
     632                dst += _screenWidth;
     633                src += state->width * 16;
     634        } while (--h);
     635}
     636
    592637void AGOSEngine::drawImages(VC10_state *state) {
    593638        const uint16 *vlut = &_videoWindows[_windowNum * 4];
    594639