home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / gbuk.lha / src / amiga / AMIGA1.C next >
C/C++ Source or Header  |  1996-11-06  |  4KB  |  177 lines

  1. #include    <stdlib.h>
  2. #include    <string.h>
  3. #include    <stdio.h>
  4. #include    <time.h>
  5. #include    "gfxfunc.h"
  6. #include    "prefs.h"
  7. #include    "GB.h"
  8. #include    "system.h"
  9. #include    "method1.h"
  10.  
  11. #define    SOUND    0
  12.  
  13. byte    SourceColor1(int n)
  14. {
  15.     if(n<4){
  16.         return BPal[n];
  17.     }else if(n<8){
  18.         return BPal[n-4]+4;
  19.     }else if(n<12){
  20.         return SPal0[n-8]+8;
  21.     }else{
  22.         return SPal1[n-12]+12;
  23.     }
  24. }
  25.  
  26. int InitMachine1(void)
  27. {
  28.     SetupMethod2();
  29. #if    SOUND
  30.     if(!SetupSound())GXQuitCode("Couldnt set up sound\n");
  31. #endif
  32.     return 1;
  33. }
  34. void TrashMachine1(void)
  35. {
  36.     FreeMethod2();
  37. }
  38.  
  39. void RefreshScreen1(void)
  40. {
  41.     int    j;
  42.     static byte BPal_old[4]={0,0,0,0};            /* Background palette                           */
  43.     static byte SPal0_old[4]={0,0,0,0};
  44.     static byte SPal1_old[4]={0,0,0,0};  /* Sprite palettes                              */
  45.     byte    *from;
  46.     GXPALETTE    palette[16],*to;
  47.  
  48.     RefreshScreenMethod2();
  49. #if    SOUND
  50.     UpdateSound();
  51. #endif
  52.     //    Update the palette
  53.     if( *((long *)BPal) != *((long *)BPal_old) )goto changed;
  54.     if( *((long *)SPal0) != *((long *)SPal0_old) )goto changed;
  55.     if( *((long *)SPal1) != *((long *)SPal1_old) )goto changed;
  56.  
  57.     return;
  58. changed:
  59.     GXPrintf("Changing palette!!!\n");
  60.     *((long *)BPal_old) = *((long *)BPal);    
  61.     *((long *)SPal0_old) = *((long *)SPal0);
  62.     *((long *)SPal1_old) = *((long *)SPal1);
  63.  
  64.     to=palette;
  65.     from=BPal;
  66.     for(j=0; j<4; j++)*to++=GameBoyPalette[*from++];
  67.     from=BPal;
  68.     for(j=0; j<4; j++)*to++=GameBoyPalette[(*from++) + 4];
  69.     from=SPal0;
  70.     for(j=0; j<4; j++)*to++=GameBoyPalette[(*from++) + 8];
  71.     from=SPal1;
  72.     for(j=0; j<4; j++)*to++=GameBoyPalette[(*from++) + 12];
  73.     GXSetPaletteRange(palette, 16, 16);
  74.  
  75. }
  76.  
  77. typedef struct{
  78.     void    *mac_ChrGen;    //
  79.     void    *mac_WndTab;    //
  80.     void    *mac_RAM;        //
  81.     void    *mac_BgdTab;    //
  82.     short    mac_Y;
  83.     short    mac_SCROLLX;    //
  84.     short    mac_SCROLLY;    //
  85.     short    mac_WNDPOSX;    //
  86.     short    mac_WNDPOSY;    //
  87.     byte    mac_LCDCONT;    //
  88. }MYMACHINEDATA;
  89.  
  90. void RefreshLine1(byte Y)
  91. {
  92.     MYMACHINEDATA    m;
  93.  
  94.     if( BackgroundOn|| WindowOn){    
  95.         m.mac_ChrGen=ChrGen;
  96.         m.mac_WndTab=WndTab;
  97.         m.mac_RAM=RAM;
  98.         m.mac_BgdTab=BgdTab;
  99.         m.mac_Y=Y;
  100.         m.mac_SCROLLY=SCROLLY;
  101.         m.mac_SCROLLX=SCROLLX;
  102.         m.mac_WNDPOSX=WNDPOSX;
  103.         m.mac_WNDPOSY=WNDPOSY;
  104.         m.mac_LCDCONT=LCDCONT;
  105.         RefreshLineMethod2(&m);
  106.     }
  107. }
  108.  
  109. void RefreshSprites1(void)
  110. {
  111.     if(SpritesOn){
  112.         RefreshSpritesMethod2(RAM);
  113.     }
  114. }
  115.  
  116. typedef struct{
  117.     long    Frequency;
  118. }SOUNDDATA;
  119.  
  120. SOUNDDATA    SoundData[5];
  121.  
  122.  
  123. void Sound1(byte R,byte V)
  124. {
  125. #if    SOUND
  126.     SOUNDDATA    *snd;
  127.  
  128.     {
  129.         static int flag=1;
  130.         
  131.         if(flag){
  132.             flag=0;
  133.             memset(SoundData, 0, sizeof(SoundData));
  134.         }
  135.     }
  136.     
  137.     switch(R){
  138. /*
  139.     case    0x02:
  140.         snd=&SoundData[0];
  141.         snd->Frequency=(snd->Frequency&0xff00)|V;
  142. //        GXPrintf("Channel 0: Frequency %d    **    %x\n",snd->Frequency,snd->Frequency);
  143.         break;
  144.     case    0x03:
  145.         snd=&SoundData[0];
  146.         snd->Frequency=(snd->Frequency&0x00ff)|( (V&7) << 8);
  147.         GXPrintf("Channel 0: Frequency %d    **    %x\n",snd->Frequency,snd->Frequency);
  148.         break;
  149. */
  150.     case    0x08:
  151.         snd=&SoundData[1];
  152.         snd->Frequency=(snd->Frequency&0xff00)|V;
  153. //        GXPrintf("Channel 1: Frequency %d    **    %x\n",snd->Frequency,snd->Frequency);
  154.         break;
  155.     case    0x09:
  156.         snd=&SoundData[1];
  157.         snd->Frequency=(snd->Frequency&0x00ff)|( (V&7) << 8);
  158.         GXPrintf("Channel 1: Frequency %d    **    %x\n",snd->Frequency,snd->Frequency);
  159.         break;
  160.     case    0x0d:
  161.         snd=&SoundData[2];
  162.         snd->Frequency=(snd->Frequency&0xff00)|V;
  163. //        GXPrintf("Channel 2: Frequency %d    **    %x\n",snd->Frequency,snd->Frequency);
  164.         break;
  165.     case    0x0e:
  166.         snd=&SoundData[2];
  167.         snd->Frequency=(snd->Frequency&0x00ff)|( (V&7) << 8);
  168.         GXPrintf("Channel 2: Frequency %d    **    %x\n",snd->Frequency,snd->Frequency);
  169.         break;
  170.     default:
  171.         break;
  172.     }
  173.     LowLevelSound(R,V);
  174. #endif
  175. }
  176. byte SIOSend1(byte V){return 0;}
  177. byte SIOReceive1(byte *V){return 0;}