home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / gbuk.lha / src / amiga / AMIGA2.C < prev    next >
C/C++ Source or Header  |  1997-02-08  |  6KB  |  230 lines

  1. #include    <stdlib.h>
  2. #include    <string.h>
  3. #include    <stdio.h>
  4. #include    <time.h>
  5. #include    "GB.h"
  6. #include    "system.h"
  7. #include    "method2.h"
  8. #include    "gfxfunc.h"
  9. #include    "prefs.h"
  10.  
  11. void RefreshLineSub(byte Y);
  12.  
  13.  
  14. //#define WIDTH  176
  15. //#define HEIGHT 160
  16.  
  17. #define WIDTH  256
  18. #define HEIGHT 256
  19.  
  20. #define    XOFFSET    ((WIDTH-160)/2)
  21.  
  22. byte    *XBuf, XPal[16];
  23. byte DefaultPalette[]={    0,0,0,                 /* Overscan colour */
  24.                         0xFF,0xFF,0xFF,        /* Background colours */
  25.                         0xB0,0xB0,0xB0,
  26.                         0x60,0x60,0x60,
  27.                         0x00,0x00,0x00,
  28.                         0xFF,0xFF,0xFF,        /* Sprite colours */
  29.                         0xB0,0xB0,0xB0,
  30.                         0x60,0x60,0x60,
  31.                         0x00,0x00,0x00,
  32.                         0xFF,0xFF,0xFF,        /* Window colours */
  33.                         0xB0,0xB0,0xB0,
  34.                         0x60,0x60,0x60,
  35.                         0x00,0x00,0x00 };
  36. byte    Palette[256];
  37.  
  38. byte    SourceColor2(int n)
  39. {
  40.     return n;
  41. }
  42.  
  43.  
  44. int InitMachine2(void)
  45. {
  46.     char    *error;
  47.     int        i;
  48.  
  49.     //    INITIALIZE WORK BUFFER
  50.     XBuf=(byte *)GXGetMem(sizeof(byte)*HEIGHT*WIDTH, MEMF_ZERO|MEMF_ABORT);
  51.     for (i=0; i<16; ++i){
  52.         XPal[i]=i+16;
  53.     }
  54.     return 1;
  55. }
  56. void TrashMachine2(void)
  57. {
  58.     if(XBuf){
  59.         GXFreeMem(XBuf);
  60.         XBuf=0;
  61.     }
  62. }
  63.  
  64. void RefreshScreen2(void)
  65. {
  66.     CopyToScreen(XBuf+XOFFSET, 160, 144, WIDTH);
  67. }
  68.  
  69.  
  70. void RefreshLine2(byte Y)
  71. {
  72.   byte Offset,*P,*T,*R,D0,X1,X2;
  73.   unsigned D1;
  74.   byte Pal[4];
  75.   int    MyScroll;
  76.   int    n;
  77.   byte  *map;
  78.   int   nmap;
  79.  
  80.   R=XBuf+WIDTH*Y+XOFFSET;
  81.   Pal[0]=XPal[BPal[0]];Pal[1]=XPal[BPal[1]];
  82.   Pal[2]=XPal[BPal[2]];Pal[3]=XPal[BPal[3]];
  83.  
  84.     if( ((LCDCONT&0x81)!=0x81) || (!BackgroundOn) ) { 
  85.     memset(R,XPal[0],160);R+=160; 
  86.   }else{
  87.     MyScroll=SCROLLX;        
  88.     Offset=Y+SCROLLY;
  89.     T=BgdTab+((word)(Offset&0xF8)<<2);
  90.     Offset=(Offset&0x07)<<1;
  91.  
  92.     R-=(MyScroll&0x07);
  93.     X1=(MyScroll/8);
  94.  
  95.     for(n=21; n; n--)
  96.     {
  97.       D0=*(T+( X1 & 31));
  98.       if( !(LCDCONT&0x10)  ) D0+=0x80;
  99.       P=ChrGen+(((int)D0)<<4)+Offset;
  100.       D0=*P;D1=(word)*(P+1)<<1;
  101.       R[0]=Pal[((D1&0x100)|(D0&0x80))>>7];
  102.       R[1]=Pal[((D1&0x080)|(D0&0x40))>>6];
  103.       R[2]=Pal[((D1&0x040)|(D0&0x20))>>5];
  104.       R[3]=Pal[((D1&0x020)|(D0&0x10))>>4];
  105.       R[4]=Pal[((D1&0x010)|(D0&0x08))>>3];
  106.       R[5]=Pal[((D1&0x008)|(D0&0x04))>>2];
  107.       R[6]=Pal[((D1&0x004)|(D0&0x02))>>1];
  108.       R[7]=Pal[((D1&0x002)|(D0&0x01))];
  109.       R+=8;
  110.       X1++;
  111.     }
  112.     R+=(MyScroll&0x07)-8;
  113.   }
  114. //    R+=160;
  115.   X1=(WNDPOSX>7)? WNDPOSX-7:0;
  116.  
  117.     if(!WindowOn)return;
  118.  
  119.   if(((LCDCONT&0xA0)==0xA0)&&(WNDPOSY<=Y)&&(X1<160))
  120.   {
  121.     R-=160-X1;
  122.     Offset=Y-WNDPOSY;
  123.     T=WndTab+((word)(Offset&0xF8)<<2);
  124.     Offset=(Offset&0x07)<<1;
  125.     Pal[0]=XPal[BPal[0]+8];Pal[1]=XPal[BPal[1]+8];
  126.     Pal[2]=XPal[BPal[2]+8];Pal[3]=XPal[BPal[3]+8];
  127.     {
  128.      for(X1>>=3;X1<(160>>3);X1++)
  129.      {
  130. //    QuitCode("Plotting window\n");
  131.       D0=*(T++)+0x80;
  132.       P=RAM+0x8800+((word)D0<<4)+Offset;
  133.       D0=*P;D1=(word)*(P+1)<<1;
  134.       R[0]=Pal[((D1&0x100)|(D0&0x80))>>7];
  135.       R[1]=Pal[((D1&0x080)|(D0&0x40))>>6];
  136.       R[2]=Pal[((D1&0x040)|(D0&0x20))>>5];
  137.       R[3]=Pal[((D1&0x020)|(D0&0x10))>>4];
  138.       R[4]=Pal[((D1&0x010)|(D0&0x08))>>3];
  139.       R[5]=Pal[((D1&0x008)|(D0&0x04))>>2];
  140.       R[6]=Pal[((D1&0x004)|(D0&0x02))>>1];
  141.       R[7]=Pal[((D1&0x002)|(D0&0x01))];
  142.       R+=8;
  143.      }
  144.     }
  145.   }
  146. }
  147.  
  148. void RefreshSprites2(void)
  149. {
  150.   register byte *P,*T,*S,I,J,K,N,D0;
  151.   register offset DY;
  152.   register unsigned D1;
  153.   byte Pal[4];
  154.  
  155.     if(!SpritesOn)return;
  156.  
  157.   N=LCDCONT&0x04? 16:8;
  158.  
  159.   for(S=RAM+0xFE9C,J=40;J;S-=4,J--)
  160.     if(S[0]&&(S[0]<160)&&S[1]&&(S[1]<168))
  161.     {
  162.       if(S[0]<16){ 
  163.           D0=0;
  164.           K=16-S[0];
  165.           I=(K<N)? N-K:0; 
  166.       }else{ 
  167.           D0=S[0]-16;                        //start y coordinate
  168.           K=0;
  169.           I=(160-S[0]<N)? 160-S[0]:N;     //lines to draw??
  170.       }
  171.       P=XBuf+D0*WIDTH+XOFFSET+S[1]-(S[3]&0x20? 1:8);
  172.       DY=2;
  173.       if(S[3]&0x40){    //if tiles y flipped, moved to end of data and read 
  174.           DY=-DY;            //backwards
  175.           K=N-K-1;         //=tile height - 1 normally    
  176.       }
  177.  
  178.       //T=S[3]&0x10? SPal1:SPal0;
  179.       //Pal[0]=XPal[T[0]+4];Pal[1]=XPal[T[1]+4];
  180.       //Pal[2]=XPal[T[2]+4];Pal[3]=XPal[T[3]+4];
  181.  
  182.       if(S[3]&0x10){
  183.           Pal[0]=SPal1[0]+12;
  184.           Pal[1]=SPal1[1]+12;
  185.           Pal[2]=SPal1[2]+12;
  186.           Pal[3]=SPal1[3]+12;
  187.       }else{
  188.           Pal[0]=SPal0[0]+8;
  189.           Pal[1]=SPal0[1]+8;
  190.           Pal[2]=SPal0[2]+8;
  191.           Pal[3]=SPal0[3]+8;
  192.       }
  193.     
  194.  
  195.       T=RAM+0x8000+((long)((N>8)? S[2]&0xFE:S[2])<<4)+(K<<1);
  196.  
  197.       if(S[3]&0x20)
  198.         for(;I;I--,P+=WIDTH,T+=DY)    //i=height to draw
  199.         {                        
  200.           D0=*T;D1=*(T+1);K=D0|D1;D1<<=1;
  201.           if(K&0x80) P[0]=Pal[((D1&0x100)|(D0&0x80))>>7];
  202.           if(K&0x40) P[-1]=Pal[((D1&0x080)|(D0&0x40))>>6];
  203.           if(K&0x20) P[-2]=Pal[((D1&0x040)|(D0&0x20))>>5];
  204.           if(K&0x10) P[-3]=Pal[((D1&0x020)|(D0&0x10))>>4];
  205.           if(K&0x08) P[-4]=Pal[((D1&0x010)|(D0&0x08))>>3];
  206.           if(K&0x04) P[-5]=Pal[((D1&0x008)|(D0&0x04))>>2];
  207.           if(K&0x02) P[-6]=Pal[((D1&0x004)|(D0&0x02))>>1];
  208.           if(K&0x01) P[-7]=Pal[((D1&0x002)|(D0&0x01))];
  209.         }
  210.       else
  211.         for(;I;I--,P+=WIDTH,T+=DY)
  212.         {
  213.           D0=*T;D1=*(T+1);K=D0|D1;D1<<=1;
  214.           if(K&0x80) P[0]=Pal[((D1&0x100)|(D0&0x80))>>7];
  215.           if(K&0x40) P[1]=Pal[((D1&0x080)|(D0&0x40))>>6];
  216.           if(K&0x20) P[2]=Pal[((D1&0x040)|(D0&0x20))>>5];
  217.           if(K&0x10) P[3]=Pal[((D1&0x020)|(D0&0x10))>>4];
  218.           if(K&0x08) P[4]=Pal[((D1&0x010)|(D0&0x08))>>3];
  219.           if(K&0x04) P[5]=Pal[((D1&0x008)|(D0&0x04))>>2];
  220.           if(K&0x02) P[6]=Pal[((D1&0x004)|(D0&0x02))>>1];
  221.           if(K&0x01) P[7]=Pal[((D1&0x002)|(D0&0x01))];
  222.         }
  223.     }
  224. }
  225. void Sound2(byte R,byte V){}
  226. byte SIOSend2(byte V){return 0;}
  227. byte SIOReceive2(byte *V){return 0;}
  228.  
  229.  
  230.