home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Games / AGA / Shoot / Source / shootgifc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-24  |  16.3 KB  |  780 lines

  1. /* Copyright 1990 by Christopher A. Wichura.
  2.    See file GIFMachine.doc for full description of rights.
  3. */
  4.  
  5. #include <exec/types.h>
  6. #include <exec/lists.h>
  7. #include <exec/nodes.h>
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <exec/memory.h>
  12. #include <libraries/dos.h>
  13. #include <graphics/rastport.h>
  14. #include <graphics/gfxbase.h>
  15. #include <graphics/gfx.h>
  16. #include <intuition/intuition.h>
  17.  
  18. extern void ReadCodex(void);
  19. extern void getgif(void);
  20.  
  21. /* Nur fuer shoot */
  22. #include "shoot.h"
  23. extern int numtiles;
  24. extern UBYTE tiles[ TILESMAX ][ DEPTH ][ TILESHEIGHT ][ TILESWIDTH ];
  25.  
  26. void beak( char * );
  27.  
  28. int images;
  29. USHORT picinfowidth;
  30. USHORT picinfoheight;
  31. UBYTE ByteBuf;
  32. USHORT pimx, pimy;
  33. APTR pimdata;
  34. USHORT pimstart, pimlines;
  35. USHORT hires;
  36.  
  37. struct MyMem {
  38.     struct MinNode mm_Node;
  39.     ULONG mm_Size;
  40. };
  41.  
  42. /* some structures to make parsing the gif files a bit easier */
  43. struct GIFdescriptor {
  44.     UWORD gd_Width;
  45.     UWORD gd_Height;
  46.     UBYTE gd_ColInfo;
  47.     UBYTE gd_BackGround;
  48.     UBYTE gd_PixelAspect;    /* Aspect Ratio = (Pixel Aspect + 15) / 64 */
  49. };
  50.  
  51. struct ImageDesc {
  52.     UWORD id_Left;
  53.     UWORD id_Top;
  54.     UWORD id_Width;
  55.     UWORD id_Height;
  56.     UBYTE id_Info;
  57. };
  58.  
  59. struct RGB {
  60.     UBYTE rgb_Red;
  61.     UBYTE rgb_Green;
  62.     UBYTE rgb_Blue;
  63. };
  64.  
  65. #define GIF_IMAGE      0x2C
  66. #define GIF_EXTENSION  0x21
  67. #define GIF_TERMINATOR 0x3B
  68.  
  69. #define GIF_COMMENT_EXT 0xFE
  70.  
  71. #define MAXCOLOURS 4096
  72.  
  73. /* these next macros are used to get the r, g, and b values of a given
  74.    index */
  75. #define GetRed(a)    (UBYTE)(a >> 8)
  76. #define GetGreen(a)    (UBYTE)((a >> 4) & 0xF)
  77. #define GetBlue(a)    (UBYTE)(a & 0xF)
  78.  
  79. /* whenever we want to abort we will return this as our error code */
  80. #define ABORTEXITVAL 1
  81.  
  82. /* this struct is used to hold the linked list of comments found in the GIF
  83.    file so that each can be written as a seperate ANNO chunk. */
  84. struct CommentNode {
  85.     struct MinNode cn_Node;
  86.     char *cn_Comment;
  87.     ULONG cn_CommentLength;
  88. };
  89.  
  90. /* function prototypes we use */
  91. void    WarnMustUseCLI(void);
  92. void    DoPattern(char *);
  93. void    Convert(UWORD, UWORD, char *);
  94. BOOL    IsDir(char *);
  95. void    FlipWord(UWORD *);
  96. BOOL    DoImage(APTR);
  97. BOOL    DoExtension(APTR);
  98. BOOL    WriteIFF(char *, BOOL);
  99. void    PutValue(UWORD, UWORD, UWORD);
  100. UWORD    GetValue(UWORD, UWORD);
  101. int    ReadCode(APTR);
  102. void    AddPixel(UBYTE);
  103. void    StripBorder(void);
  104. BOOL    BorderCheck(UWORD, UWORD);
  105. void    DoXComp(void);
  106. void    GIFtoSHAM(void);
  107. void    InitDiff(void);
  108. ULONG    RGBdiff(UBYTE, UBYTE, UBYTE, UBYTE, UBYTE, UBYTE);
  109. void    OutDump(int);
  110. void    OutRun(int, int);
  111. void    InitMemory(void);
  112. char *    MyAlloc(ULONG);
  113. void    MyFree(char *);
  114. void    FreeAll(UWORD);
  115. void    MyExit(ULONG);
  116. void    DoXFlip(void);
  117. void    DoYFlip(void);
  118. void    ReduceTo12(void);
  119. void    DitherTo12(void);
  120. UWORD    AddColour(struct RGB *);
  121.  
  122. /* modules that want to use the Get/PutValue macros should include this
  123.    next macro to externally reference the picture storage array */
  124. #define EXTERNBITPLANE extern struct RGB **BitPlane
  125.  
  126. /* for use once colour palette has been reduced to 12 bits */
  127. #define GetValue(a, b) *((UWORD *)&BitPlane[b][a])
  128. #define PutValue(a, b, c) *((UWORD *)&BitPlane[b][a]) = c
  129.  
  130. /* Copyright 1990 by Christopher A. Wichura.
  131.    See file GIFMachine.doc for full description of rights.
  132. */
  133.  
  134. #include <workbench/startup.h>
  135.  
  136. struct GIFdescriptor gdesc;
  137.  
  138. struct RGB **BitPlane;
  139. struct RGB GlobalColourTable[256];
  140.  
  141. ULONG ImageNumber;
  142.  
  143. /* the current GIF file handle */
  144. struct FileHandle *GIFfh = NULL;
  145.  
  146. /* here we have some defines relating to our GADS call */
  147. #define ESC "\x9B"
  148. #define GIFMACH ESC "33;42mGIFMachine" ESC "32;40m"
  149.  
  150. #define ARG_TEMPLATE "GIFfiles/M/A,TO/K,ALL/S,NOBORDER/K/N,XCOMP/S,DITHER/S,XFLIP/s,YFLIP/s,DEEP/S,BUFSIZE/K/N"
  151. #define ARG_FILES  0
  152. #define ARG_TO     1
  153. #define ARG_ALL    2
  154. #define ARG_NOBORD 3
  155. #define ARG_XCOMP  4
  156. #define ARG_DITHER 5
  157. #define ARG_FLIPX  6
  158. #define ARG_FLIPY  7
  159. #define ARG_DEEP   8
  160. #define ARG_BUFSIZ 9
  161. #define ARG_sizeof 10
  162.  
  163. /* we will make the argument array global so that other modules can get at
  164.    the ARG_TO, ARG_ALL and ARG_XCOMP fields easily */
  165. struct RDArgs *ArgsPtr;
  166. char *ArgArray[ARG_sizeof];
  167. BOOL ArgToIsDir;
  168.  
  169. /* size of the read buffered i/o space */
  170. static ULONG BufSize = 2048;    /* default size is 2k */
  171.  
  172. int NoBorderLineThresh = 0;
  173.  
  174. /* some mem pointers used when we do dithering */
  175. BYTE *CurrentLineErr[3];
  176. BYTE *LastLineErr[3];
  177.  
  178. /* this flag says if we scaled the image */
  179. BOOL DidXComp;
  180.  
  181. /* we print this when the user hits the break key */
  182. char *AbortMsg = "*** User Interruption!\n";
  183.  
  184. void MyExit( result)
  185. ULONG result;
  186. {
  187.     if (GIFfh)
  188.         Close(GIFfh);
  189.  
  190.     FreeAll( (UWORD) 1 );
  191.     FreeAll( (UWORD) 0 );
  192.  
  193.     return(result);
  194. }
  195.  
  196.  
  197. /* here we have the routine that gets ready to do the conversion */
  198.  
  199. void beak( name )
  200. char *name;
  201. {
  202.     register int index;
  203.     /*char *basename;
  204.     char *ptr;*/
  205.     char sig[7];
  206.     int size;
  207.     int error;
  208.     int colours;
  209.     LONG cmdcode;
  210.     unsigned char rid;
  211.  
  212.     printf("name: %s\n", name );
  213.  
  214.     if (!(GIFfh = (struct FileHandle *) Open(name, MODE_OLDFILE))) {
  215.         printf("Error #%ld trying to open %s...\n", IoErr(), name);
  216.         goto LeaveConvert;
  217.     }
  218.  
  219.     sig[6] = NULL;
  220.  
  221.     if ((Read(GIFfh, sig, 6) != 6) || strncmp("GIF", sig, 3)) {
  222.         printf("%s is not a GIF file...\n", name);
  223.         printf("%s\n", sig );
  224.         goto LeaveConvert;
  225.     }
  226.  
  227.     if (Read(GIFfh, (char *)&gdesc, 7) != 7) {
  228.         printf("Error reading screen descriptor.\n");
  229.         goto LeaveConvert;
  230.     }
  231.  
  232.     FlipWord(&gdesc.gd_Width);
  233.     FlipWord(&gdesc.gd_Height);
  234.  
  235.     printf("Signature = \"%s\", Width = %ld, Height = %ld\n",
  236.         sig, gdesc.gd_Width, gdesc.gd_Height);
  237.  
  238.     DidXComp = 0;
  239.     colours = 1L << ((gdesc.gd_ColInfo & 7) + 1);
  240.  
  241.     if (!(gdesc.gd_ColInfo & 1L << 7)) {
  242.         printf("No global colour map supplied, using internal.\n");
  243.  
  244.         for (index = 0; index < colours; index++) {
  245.             GlobalColourTable[index].rgb_Red   =
  246.             GlobalColourTable[index].rgb_Green =
  247.             GlobalColourTable[index].rgb_Blue  = index;
  248.         }
  249.     } else {
  250.         printf("Global colour map contains %ld entries.\n", colours);
  251.  
  252.         for (index = 0; index < colours; index++) {
  253.             if (Read(GIFfh, &GlobalColourTable[index], 3) != 3) {
  254.                 printf("Error reading global colour #%ld.\n",
  255.                     index);
  256.                 goto LeaveConvert;
  257.             }
  258.         }
  259.     }
  260.  
  261.     size = ((gdesc.gd_Width + 7) / 8) + 1;
  262.     size += (size + 127) >> 7;
  263.  
  264.     size = (gdesc.gd_Width + 1) * sizeof(struct RGB);
  265.  
  266.  
  267.     ImageNumber = 1;
  268.  
  269.     /* at this point we start looking for images, extensions or the gif
  270.        terminator.  we call the appropriate routine as we find each. */
  271.  
  272.     for (error = FALSE; error == FALSE;) {
  273.         if ( Read( GIFfh, &rid, 1) == -1) {
  274.             printf("...I/O error reading GIF file.\n");
  275.             goto LeaveConvert;
  276.         }
  277.         cmdcode=rid;
  278.  
  279.         switch(cmdcode) {
  280.             case GIF_IMAGE:
  281.                 error = DoImage( (APTR) GIFfh);
  282.                 break;
  283.  
  284.             case GIF_EXTENSION:
  285.                 error = DoExtension( (APTR) GIFfh);
  286.                 break;
  287.  
  288.             case GIF_TERMINATOR:
  289.                 break;
  290.  
  291.             default:
  292.                 printf("...Unknown directive #%ld encountered.\n",
  293.                     cmdcode);
  294.                 error = TRUE;
  295.         }
  296.     }
  297.  
  298. LeaveConvert:
  299.     if (GIFfh) {
  300.         Close(GIFfh);
  301.         GIFfh = NULL;
  302.     }
  303. }
  304.  
  305. struct MinList Mem[2];
  306. UWORD CurrentMem;
  307.  
  308. char *MyAlloc(size)
  309. ULONG size;
  310. {
  311.     register struct MyMem *theMemory;
  312.     register ULONG newsize;
  313.  
  314.     newsize = size + sizeof(struct MyMem);
  315.  
  316.     if (!(theMemory = (struct MyMem *)AllocMem(newsize, MEMF_PUBLIC|MEMF_CLEAR)))
  317.         return NULL;
  318.  
  319.     AddTail((struct List *)&Mem[CurrentMem], (struct Node *)&theMemory->mm_Node);
  320.     theMemory->mm_Size = newsize;
  321.  
  322.     return (char *)theMemory + sizeof(struct MyMem);
  323. }
  324.  
  325. void MyFree(MemPtr)
  326. char *MemPtr;
  327. {
  328.     register struct MyMem *theMemory;
  329.  
  330.     theMemory = (struct MyMem *)(MemPtr - sizeof(struct MyMem));
  331.  
  332.     Remove((struct Node *)&theMemory->mm_Node);
  333.     FreeMem((char *)theMemory, theMemory->mm_Size);
  334. }
  335.  
  336. void FreeAll(memlist)
  337. UWORD memlist;
  338. {
  339.     register struct MyMem *theMemory;
  340.  
  341.     while (theMemory = (struct MyMem *)RemTail((struct List *)&Mem[memlist]))
  342.         FreeMem((char *)theMemory, theMemory->mm_Size);
  343. }
  344.  
  345. struct MinList CommentList;
  346. static UBYTE buf[256];
  347.  
  348. BOOL DoExtension(fh)
  349. APTR fh;
  350. {
  351.     register LONG size;
  352.     register LONG cmdcode;
  353.     register char *Comment;
  354.     register char *OldComment;
  355.     register int CommentLength;
  356.     register int OldCommentLength;
  357.     register struct CommentNode *cn;
  358.     unsigned char rid;
  359.  
  360.     if (Read( fh, &rid, 1) == -1) {
  361.         printf("...I/O error reading extension block function code\n");
  362.         return TRUE;
  363.     }
  364.     cmdcode=rid;
  365.  
  366.     switch(cmdcode) {
  367.         case GIF_COMMENT_EXT:
  368.             printf("...Comment extension encountered.  Contents will be stored in an ANNO chunk.\n");
  369.  
  370.             if (!(cn = (struct CommentNode *)MyAlloc(sizeof(struct CommentNode)))) {
  371.                 printf("......Out of memory allocating comment block.\n");
  372.                 return TRUE;
  373.             }
  374.  
  375.             Comment = NULL;
  376.             CommentLength = 0;
  377.  
  378.             for (;;) {
  379.                 if ((size = fgetc(fh)) == -1) {
  380.                     printf("......I/O Error reading comment block.\n");
  381.                     return TRUE;
  382.                 }
  383.  
  384.                 if (size) {
  385.                     if (fread(fh, buf, 1, size) != size) {
  386.                         printf("......I/O Error reading comment block.\n");
  387.                         return TRUE;
  388.                     }
  389.  
  390.                     OldComment = Comment;
  391.                     OldCommentLength = CommentLength;
  392.                     CommentLength += size;
  393.  
  394.                     if (!(Comment = MyAlloc(CommentLength))) {
  395.                         printf("......Out of memory allocating comment block.\n");
  396.                         return TRUE;
  397.                     }
  398.  
  399.                     if (OldCommentLength) {
  400.                         CopyMem(OldComment, Comment, OldCommentLength);
  401.                         MyFree(OldComment);
  402.                     }
  403.  
  404.                     CopyMem(buf, &Comment[OldCommentLength], size);
  405.                 } else {    /* end of comment so store it */
  406.                     cn->cn_Comment = Comment;
  407.                     cn->cn_CommentLength = CommentLength;
  408.                     AddTail((struct List *)&CommentList, (struct Node *)cn);
  409.                     return FALSE;
  410.                 }
  411.             }
  412.             break;
  413.  
  414.         default:
  415.             printf("...Extension block function code #%ld not know, skipping.\n",
  416.              cmdcode);
  417.  
  418.             /* we must skip over any data for the extension block */
  419.             for (;;) {
  420.                 if ((size = fgetc(fh)) == -1) {
  421.                     printf("...I/O Error skipping unknown extension block.\n");
  422.                     return TRUE;
  423.                 }
  424.  
  425.                 if (size == 0)
  426.                     return FALSE;
  427.  
  428.                 if (fread(fh, buf, 1, size) != size) {
  429.                     printf("...I/O Error skipping unknown extension block.\n");
  430.                     return TRUE;
  431.                 }
  432.             }
  433.             break;
  434.     }
  435. }
  436.  
  437. /* this will convert a word from LSB/MSB to MSB/LSB */
  438. void FlipWord(word)
  439. UWORD *word;
  440. {
  441.     register UBYTE swap1;
  442.     register UBYTE swap2;
  443.  
  444.     swap1 = *word & 0xFF;
  445.     swap2 = (*word & 0xFF00) >> 8;
  446.     *word = swap1 << 8 | swap2;
  447. }
  448.  
  449. /*struct GIFdescriptor gdesc;*/
  450.  
  451. static struct ImageDesc idesc;
  452. /*struct RGB GlobalColourTable[256];*/
  453. static struct RGB LocalColourTable[256];
  454. /*ULONG ImageNumber;*/
  455.  
  456. extern char *AbortMsg;
  457.  
  458. static UWORD Xpos, Ypos;
  459. static BOOL interleave;
  460.  
  461. static UBYTE LeaveStep[5]  = {1, 8, 8, 4, 2};
  462. static UBYTE LeaveFirst[5] = {0, 0, 4, 2, 1};
  463.  
  464. /* some variables used by the decompressor */
  465. UWORD ReadError;
  466. UBYTE CodeSize;
  467. UWORD EOFCode;
  468. UBYTE ReadMask;
  469. UWORD    CompDataPointer;
  470. UWORD CompDataCount;
  471. UBYTE CompData[256];
  472.  
  473. /* tables used by the decompressor */
  474. static UWORD Prefix[4096];
  475. static UBYTE Suffix[4096];
  476. static UBYTE OutCode[1025];
  477.  
  478. APTR    dagiffh;
  479. UWORD Code;
  480. APTR date;
  481.  
  482. BOOL DoImage(fh)
  483. APTR fh;
  484. {
  485.     register int index;
  486.     register int colours;
  487.  
  488.     date= (APTR) &CompData[0];
  489.     dagiffh=fh;
  490.  
  491.     printf("...Image #%ld encountered.\n", ImageNumber++);
  492.  
  493.     if (Read(fh, (char *)&idesc, 9) != 9) {
  494.         printf("......Error reading image descriptor.\n");
  495.         return TRUE;
  496.     }
  497.  
  498.     FlipWord(&idesc.id_Left);
  499.     FlipWord(&idesc.id_Top);
  500.     FlipWord(&idesc.id_Width);
  501.     FlipWord(&idesc.id_Height);
  502.  
  503.     interleave = idesc.id_Info & 1L << 6;
  504.     if (interleave)
  505.         interleave = 1;
  506.  
  507.     printf("......Xpos from %ld to %ld, Ypos from %ld to %ld, %sinterlaced.\n",
  508.         idesc.id_Left, idesc.id_Left + idesc.id_Width - 1,
  509.         idesc.id_Top, idesc.id_Top + idesc.id_Height - 1,
  510.         interleave ? "" : "not ");
  511.  
  512.     if (idesc.id_Info & 1L << 7) {
  513.         colours = 1L << ((idesc.id_Info & 7) + 1);
  514.         printf("......Local colour map contains %ld entries.\n", colours);
  515.  
  516.         for (index = 0; index < colours; index++) {
  517.             if (Read(fh, &LocalColourTable[index], 3) != 3) {
  518.                 printf("......Error reading local colour #%ld.\n",
  519.                     index);
  520.                 return TRUE;
  521.             }
  522.         }
  523.     } else {
  524.         colours = 1L << ((gdesc.gd_ColInfo & 7) + 1);
  525.         CopyMem((char *)GlobalColourTable, (char *)LocalColourTable,
  526.             sizeof(LocalColourTable));
  527.     }
  528.  
  529.     Xpos = Ypos = 0;
  530.  
  531.     /* now we are ready to read the image in so do it! */
  532.  
  533.     {
  534.         int MaxCode, ClearCode, CurCode,
  535.             OldCode, InCode, FreeCode;
  536.         int OutCount;
  537.         int FirstFree;
  538.         UBYTE InitCodeSize, FinChar, BitMask;
  539.  
  540.         printf("......Decompressing line number %5ld", Ypos);
  541.  
  542.         /* get the codesize and do general setup for decompression */
  543.         if (Read(fh, &CodeSize, 1) == -1) {
  544.             printf("\n......I/O Error during decompression.\n");
  545.             return TRUE;
  546.         }
  547.  
  548.         ClearCode = 1L << CodeSize;
  549.         EOFCode = ClearCode + 1;
  550.         FreeCode = FirstFree = ClearCode + 2;
  551.  
  552.         CodeSize++;    /* per GIF spec */
  553.         InitCodeSize = CodeSize;
  554.         MaxCode = 1L << CodeSize;
  555.         ReadError = ReadMask = OutCount = 0;
  556.         CompDataPointer = CompDataCount = 0;
  557.  
  558.         BitMask = colours - 1;
  559.  
  560.         Code = ReadCode(fh);
  561. /*        ReadCodex();*/
  562.         while( Code != EOFCode ) {
  563.             if (ReadError)
  564.                 return TRUE;
  565.  
  566.             if (Code == ClearCode) {
  567.                 CodeSize = InitCodeSize;
  568.                 MaxCode = 1L << CodeSize;
  569.                 FreeCode = FirstFree;
  570.                 FinChar = CurCode = OldCode = Code = ReadCode(fh);
  571. /*                ReadCodex();*/
  572.                 FinChar = CurCode = OldCode = Code;
  573.                 AddPixel(FinChar);
  574.             } else {
  575.                 CurCode = InCode = Code;
  576.  
  577.                 if (CurCode >= FreeCode) {
  578.                     CurCode = OldCode;
  579.                     OutCode[OutCount++] = FinChar;
  580.                 }
  581.  
  582.                 while (CurCode > BitMask) {
  583.                     if (OutCount > 1024) {
  584.                         printf("\n......Corrupt GIF file (OutCount)\n");
  585.                         return TRUE;
  586.                     }
  587.  
  588.                     OutCode[OutCount++] = Suffix[CurCode];
  589.                     CurCode = Prefix[CurCode];
  590.                 }
  591.  
  592.                 FinChar = CurCode;
  593.                 AddPixel(FinChar);
  594.  
  595.                 for (index = OutCount - 1; index >= 0; index--)
  596.                     AddPixel(OutCode[index]);
  597.                 OutCount = 0;
  598.  
  599.                 Prefix[FreeCode] = OldCode;
  600.                 Suffix[FreeCode] = FinChar;
  601.                 OldCode = InCode;
  602.  
  603.                 if (++FreeCode >= MaxCode) {
  604.                     if (CodeSize < 12) {
  605.                         CodeSize++;
  606.                         MaxCode <<= 1;
  607.                     }
  608.                 }
  609.             }
  610.  
  611.             Code = ReadCode(fh);
  612. /*            ReadCodex();*/
  613.         }
  614.     }
  615.  
  616.     if ((Code = fgetc(fh)) == -1)
  617.         return TRUE;
  618.  
  619.     /* done decompressing.  Erase decompressing message and exit */
  620.     printf("\x9B22D\x9BKed.\n");
  621.  
  622.     if (Code != 0) {
  623.         printf("......Warning:  Unaligned packet.\n");
  624.         ungetc(fh, Code);
  625.     }
  626.  
  627.     return FALSE;
  628. }
  629.  
  630. int ReadCode(fh)
  631. APTR fh;
  632. {
  633.     register int temp;
  634.     register int DstMasked;
  635.     register int DstMask;
  636.     register LONG size;
  637.     unsigned char rid;
  638.  
  639.     temp = 0;
  640.     DstMasked = 1L << CodeSize;
  641.     for (DstMask = 1; DstMask != DstMasked; DstMask <<= 1) {
  642.         if (!ReadMask) {
  643.             if (CompDataPointer == CompDataCount) {
  644.                 if (Read( fh, &rid, 1) == -1) {
  645.                     printf("\n......I/O Error during decompression.\n");
  646.                     ReadError = 1;
  647.                     return EOFCode;
  648.                 }
  649.                 size=rid;
  650.  
  651.                 if (Read(fh, (char *)CompData, size) != size) {
  652.                     printf("\n......I/O Error during decompression.\n");
  653.                     ReadError = 1;
  654.                     return EOFCode;
  655.                 }
  656.  
  657.                 CompDataCount = size;
  658.                 CompDataPointer = 0;
  659.             }
  660.  
  661.             ReadMask = 1;
  662.             ByteBuf = CompData[CompDataPointer++];
  663.         }
  664.  
  665.         if (ByteBuf & ReadMask)
  666.             temp |= DstMask;
  667.  
  668.         ReadMask <<= 1;
  669.     }
  670.  
  671.     return temp;
  672. }
  673.  
  674. void AddPixel(index)
  675. UBYTE index;
  676. {
  677.     register UWORD tile;
  678.     UWORD row;
  679.     UWORD byte;
  680.  
  681.     register UWORD manip2;
  682.     register UWORD manip;
  683.     register UBYTE schreib;
  684.  
  685. /*    SetAPen( rastport, index );*/
  686. /*    WritePixel( rastport, XStore, YStore+20 );*/
  687.  
  688.     tile = (Ypos/16)*20 + Xpos/16;
  689.  
  690.     row = Ypos & 15;
  691.     byte = (Xpos & 8)/8;
  692.  
  693.     {
  694.         manip = 1 << ( 7 - ( Xpos & 7 ) );
  695.         manip2 = 255 ^ manip;
  696.     
  697.         if( ( index & 1 ) != 0 )
  698.         {
  699.             tiles[ tile ][ 0 ][ row ][ byte ] |= manip;
  700.         }
  701.         else
  702.         {
  703.             tiles[ tile ][ 0 ][ row ][ byte ] &= manip2;
  704.         }
  705.  
  706.         if( ( index & 2 ) != 0 )
  707.         {
  708.             tiles[ tile ][ 1 ][ row ][ byte ] |= manip;
  709.         }
  710.         else
  711.         {
  712.             tiles[ tile ][ 1 ][ row ][ byte ] &= manip2;
  713.         }
  714.  
  715.         if( ( index & 4 ) != 0 )
  716.         {
  717.             tiles[ tile ][ 2 ][ row ][ byte ] |= manip;
  718.         }
  719.         else
  720.         {
  721.             tiles[ tile ][ 2 ][ row ][ byte ] &= manip2;
  722.         }
  723.  
  724.         if( ( index & 8 ) != 0 )
  725.         {
  726.             tiles[ tile ][ 3 ][ row ][ byte ] |= manip;
  727.         }
  728.         else
  729.         {
  730.             tiles[ tile ][ 3 ][ row ][ byte ] &= manip2;
  731.         }
  732.  
  733.         if( ( index & 16 ) != 0 )
  734.         {
  735.             tiles[ tile ][ 4 ][ row ][ byte ] |= manip;
  736.         }
  737.         else
  738.         {
  739.             tiles[ tile ][ 4 ][ row ][ byte ] &= manip2;
  740.         }
  741.  
  742.         if( ( index & 32 ) != 0 )
  743.         {
  744.             tiles[ tile ][ 5 ][ row ][ byte ] |= manip;
  745.         }
  746.         else
  747.         {
  748.             tiles[ tile ][ 5 ][ row ][ byte ] &= manip2;
  749.         }
  750.  
  751.         if( ( index & 64 ) != 0 )
  752.         {
  753.             tiles[ tile ][ 6 ][ row ][ byte ] |= manip;
  754.         }
  755.         else
  756.         {
  757.             tiles[ tile ][ 6 ][ row ][ byte ] &= manip2;
  758.         }
  759.  
  760.         if( ( index & 128 ) != 0 )
  761.         {
  762.             tiles[ tile ][ 7 ][ row ][ byte ] |= manip;
  763.         }
  764.         else
  765.         {
  766.             tiles[ tile ][ 7 ][ row ][ byte ] &= manip2;
  767.         }
  768.  
  769.     }
  770.  
  771.     if (++Xpos == idesc.id_Width) {
  772.         Xpos = 0;
  773.         Ypos += LeaveStep[interleave];
  774.         if (Ypos >= idesc.id_Height)
  775.             Ypos = LeaveFirst[++interleave];
  776.  
  777.         printf("\x9B5D%5ld", Ypos + idesc.id_Top);
  778.     }
  779. }
  780.