home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 13 / MA_Cover_13.bin / source / c / gbe / amiga.c next >
Encoding:
C/C++ Source or Header  |  1999-11-13  |  17.8 KB  |  829 lines

  1. /*
  2.  *  gbe - gameboy emulator
  3.  *  Copyright (C) 1999  Chuck Mason, Steven Fuller
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18.  *
  19.  *
  20.  *  Chuck Mason <chuckjr@sinclair.net>
  21.  *  Steven Fuller <relnev@atdot.org>
  22.  */
  23.  
  24. #ifdef BUILD_AMIGA
  25.  
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <assert.h>
  29. #include <string.h>
  30. #include <time.h>
  31. #include <ctype.h>
  32. #include <unistd.h>
  33. #include <signal.h>
  34.  
  35. #include "joypad.h"
  36. #include "mem.h"
  37. #include "regs.h"
  38.  
  39. #include <exec/types.h>
  40. #include <exec/nodes.h>
  41. #include <exec/lists.h>
  42. #include <exec/memory.h>
  43.  
  44. #include <powerup/ppcproto/intuition.h>
  45. #include <powerup/ppclib/interface.h>
  46. #include <powerup/ppclib/time.h>
  47. #include <powerup/gcclib/powerup_protos.h>
  48. #include <powerup/ppcproto/exec.h>
  49. #include <powerup/ppcinline/graphics.h>
  50. #include <powerup/ppcproto/dos.h>
  51. #include <powerup/ppcproto/lowlevel.h>
  52. #include <powerup/ppcproto/asl.h>
  53.  
  54. #include <cybergraphx/cybergraphics.h>
  55. #include <powerup/ppcinline/cybergraphics.h>
  56.  
  57. #define AGA  0
  58. #define CGFX 1
  59.  
  60. /* Misc variables */
  61. ULONG rgbtab[1+3*256+1];
  62. struct IntuitionBase *IntuitionBase;
  63. struct GfxBase *GfxBase;
  64. struct Library *AslBase;
  65. struct Library *CyberGfxBase;
  66. struct Library *LowLevelBase;
  67. struct Screen *screen=NULL;
  68. struct Window *window=NULL;
  69. UWORD *EmptyPointer;
  70. struct ScreenModeRequester *screenreq;
  71. struct BitMap agabitmap;
  72.  
  73. /* CGFX variables */
  74. unsigned long pixfmt;
  75. unsigned char *baseaddress;
  76. int bpr;
  77.  
  78. int xoffset, yoffset;
  79. int width = 320, height = 256, screentype;
  80. unsigned char *agabuf;
  81.  
  82. int use_pad = 0;
  83. int use_cgfx = 0;
  84. int use_req = 0;
  85. int use_highcolor = 0;
  86.  
  87. static unsigned long
  88.       gbe_window_width  = 0,
  89.       gbe_window_height = 0;
  90.  
  91. static char *gfx_buffer = (char *)NULL;
  92. static short *gfx_buffer_high = (char *)NULL;
  93.  
  94. #define twomerges1(a, b, c, d, shift, mask) \
  95.      { \
  96.      temp1 = b; \
  97.      temp2 = d; \
  98.      temp1 >>= shift; \
  99.      temp2 >>= shift; \
  100.      temp1 ^= a; \
  101.      temp2 ^= c; \
  102.      temp1 &= mask; \
  103.      temp2 &= mask; \
  104.      a ^= temp1; \
  105.      c ^= temp2; \
  106.      temp1 <<= shift; \
  107.      temp2 <<= shift; \
  108.      b ^= temp1; \
  109.      d ^= temp2; \
  110.      }
  111.  
  112. void c2p(void *chunky, void *bitplanes, int chunkyx, int chunkyy, int xoffset, int yoffset, int bitplanesize)
  113. {
  114.      ULONG     *c;
  115.      ULONG     temp1, temp2;
  116.      ULONG     *p0, *p1, *p2, *p3, *p4, *p5, *p6, *p7;
  117.      ULONG     d0, d1, d2, d3, d4, d5, d6, d7;
  118.      ULONG     t0, t1, t2, t3, t4, t5, t6, t7;
  119.      ULONG     xadd, addx;
  120.      int  i,j=0;
  121.  
  122.      c = (ULONG *) chunky;
  123.      p0 = (ULONG *) (&(((char *) bitplanes)[(yoffset*chunkyx + yoffset*xoffset*2 + xoffset) >> 3]));
  124.      p1 = (ULONG *) (&(((char *) p0)[bitplanesize]));
  125.      p2 = (ULONG *) (&(((char *) p1)[bitplanesize]));
  126.      p3 = (ULONG *) (&(((char *) p2)[bitplanesize]));
  127.      p4 = (ULONG *) (&(((char *) p3)[bitplanesize]));
  128.      p5 = (ULONG *) (&(((char *) p4)[bitplanesize]));
  129.      p6 = (ULONG *) (&(((char *) p5)[bitplanesize]));
  130.      p7 = (ULONG *) (&(((char *) p6)[bitplanesize]));
  131.  
  132.      addx=chunkyx / (sizeof (ULONG) *8);
  133.      xadd=xoffset * 2 / (sizeof (ULONG) * 8);
  134.      i = chunkyx * chunkyy / (sizeof (ULONG) * 8);
  135.  
  136.      d0 = *c++;
  137.      d1 = *c++;
  138.      d2 = *c++;
  139.      d3 = *c++;
  140.      d4 = *c++;
  141.      d5 = *c++;
  142.      d6 = *c++;
  143.      d7 = *c++;
  144.  
  145.      twomerges1(d0, d4, d1, d5, 16, 0x0000ffff);
  146.      twomerges1(d2, d6, d3, d7, 16, 0x0000ffff);
  147.  
  148.      twomerges1(d0, d2, d1, d3, 8, 0x00ff00ff);
  149.      twomerges1(d4, d6, d5, d7, 8, 0x00ff00ff);
  150.  
  151.      twomerges1(d0, d1, d2, d3, 4, 0x0f0f0f0f);
  152.      twomerges1(d4, d5, d6, d7, 4, 0x0f0f0f0f);
  153.  
  154.      twomerges1(d0, d4, d1, d5, 2, 0x33333333);
  155.      twomerges1(d2, d6, d3, d7, 2, 0x33333333);
  156.  
  157.      twomerges1(d0, d2, d1, d3, 1, 0x55555555);
  158.      twomerges1(d4, d6, d5, d7, 1, 0x55555555);
  159.  
  160.      t0 = d7;
  161.      t1 = d5;
  162.      t2 = d3;
  163.      t3 = d1;
  164.      t4 = d6;
  165.      t5 = d4;
  166.      t6 = d2;
  167.      t7 = d0;
  168.  
  169.      while (--i)
  170.      {
  171.           d0 = *c++;
  172.           d1 = *c++;
  173.           d2 = *c++;
  174.           d3 = *c++;
  175.           d4 = *c++;
  176.           d5 = *c++;
  177.           d6 = *c++;
  178.           d7 = *c++;
  179.  
  180.           *p0++ = t0;
  181.  
  182.           twomerges1(d0, d4, d1, d5, 16, 0x0000ffff);
  183.           twomerges1(d2, d6, d3, d7, 16, 0x0000ffff);
  184.  
  185.           *p1++ = t1;
  186.  
  187.           twomerges1(d0, d2, d1, d3, 8, 0x00ff00ff);
  188.           twomerges1(d4, d6, d5, d7, 8, 0x00ff00ff);
  189.  
  190.           *p2++ = t2;
  191.  
  192.           twomerges1(d0, d1, d2, d3, 4, 0x0f0f0f0f);
  193.           twomerges1(d4, d5, d6, d7, 4, 0x0f0f0f0f);
  194.  
  195.           *p3++ = t3;
  196.  
  197.           twomerges1(d0, d4, d1, d5, 2, 0x33333333);
  198.           twomerges1(d2, d6, d3, d7, 2, 0x33333333);
  199.  
  200.           *p4++ = t4;
  201.  
  202.           twomerges1(d0, d2, d1, d3, 1, 0x55555555);
  203.           twomerges1(d4, d6, d5, d7, 1, 0x55555555);
  204.  
  205.           *p5++ = t5;
  206.           *p6++ = t6;
  207.           *p7++ = t7;
  208.  
  209.           t0 = d7;
  210.           t1 = d5;
  211.           t2 = d3;
  212.           t3 = d1;
  213.           t4 = d6;
  214.           t5 = d4;
  215.           t6 = d2;
  216.           t7 = d0;
  217.  
  218.           j++;
  219.  
  220.           if (j==addx)
  221.           {
  222.             p0+=xadd;
  223.             p1+=xadd;
  224.             p2+=xadd;
  225.             p3+=xadd;
  226.             p4+=xadd;
  227.             p5+=xadd;
  228.             p6+=xadd;
  229.             p7+=xadd;
  230.             j=0;
  231.           }
  232.      }
  233.  
  234.      *p0++ = t0;
  235.      *p1++ = t1;
  236.      *p2++ = t2;
  237.      *p3++ = t3;
  238.      *p4++ = t4;
  239.      *p5++ = t5;
  240.      *p6++ = t6;
  241.      *p7++ = t7;
  242. }
  243.  
  244. int open_libraries()
  245. {
  246.   IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 39);
  247.   if (IntuitionBase==NULL)
  248.     return -1;
  249.  
  250.   GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 39);
  251.   if (GfxBase==NULL)
  252.   {
  253.     CloseLibrary(IntuitionBase);
  254.     return -1;
  255.   }
  256.  
  257.   AslBase = OpenLibrary("asl.library", 39);
  258.   if (AslBase==NULL)
  259.   {
  260.     CloseLibrary(GfxBase);
  261.     CloseLibrary(IntuitionBase);
  262.     return -1;
  263.   }
  264.  
  265.   CyberGfxBase = OpenLibrary("cybergraphics.library", 40);
  266.   LowLevelBase = OpenLibrary("lowlevel.library", 39);
  267.  
  268.   return 0;
  269. }
  270.  
  271. void close_libraries()
  272. {
  273.   if (LowLevelBase != NULL)
  274.     CloseLibrary(LowLevelBase);
  275.   if (CyberGfxBase != NULL)
  276.     CloseLibrary(CyberGfxBase);
  277.   CloseLibrary(AslBase);
  278.   CloseLibrary(GfxBase);
  279.   CloseLibrary(IntuitionBase);
  280. }
  281.  
  282. void close_screen()
  283. {
  284.   CloseWindow(window);
  285.   CloseScreen(screen);
  286. }
  287.  
  288. int open_screen()
  289. {
  290.   unsigned long dispid;
  291.   unsigned char *temp;
  292.   int i, depth = 8;
  293.  
  294.   if (use_req == 1)
  295.   {
  296.     screenreq = AllocAslRequestTags(ASL_ScreenModeRequest, TAG_END);
  297.  
  298.     if (AslRequest(screenreq, TAG_END))
  299.     {
  300.       dispid=screenreq->sm_DisplayID;
  301.       width=screenreq->sm_DisplayWidth;
  302.       FreeAslRequest(screenreq);
  303.     }
  304.     else
  305.     {
  306.       FreeAslRequest(screenreq);
  307.       return -1;
  308.     }
  309.  
  310.     if (width != 320)
  311.     {
  312.       printf("You must choose a width of 320 pixels\n");
  313.       return -1;
  314.     }
  315.  
  316.     screentype = AGA;
  317.  
  318.     if (CyberGfxBase != NULL)
  319.     {
  320.       if (IsCyberModeID(dispid))
  321.       {
  322.         depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, dispid);
  323.  
  324.         if ((depth != 8) && (depth != 15))
  325.         {
  326.           printf("You must choose a 8bit or 15bit screenmode\n");
  327.           return -1;
  328.         }
  329.         else
  330.           screentype = CGFX;
  331.       }
  332.     }
  333.   }
  334.   else
  335.   {
  336.     if (CyberGfxBase != NULL)
  337.     {
  338.       if (use_highcolor == 1)
  339.       {
  340.         depth = 15;
  341.         if ((dispid=BestCModeIDTags(CYBRBIDTG_NominalWidth, width,
  342.                                     CYBRBIDTG_NominalHeight, height,
  343.                                     CYBRBIDTG_Depth, depth,
  344.                                     TAG_DONE))==INVALID_ID)
  345.         {
  346.           printf("Could NOT get best mode ID!\n");
  347.           return -1;   
  348.         }
  349.       }
  350.       else
  351.       {
  352.         depth = 8;
  353.         if ((dispid=BestCModeIDTags(CYBRBIDTG_NominalWidth, width,
  354.                                     CYBRBIDTG_NominalHeight, height,
  355.                                     CYBRBIDTG_Depth, depth,
  356.                                     TAG_DONE))==INVALID_ID)
  357.         {
  358.           printf("Could NOT get best mode ID!\n");
  359.           return -1;   
  360.         }
  361.       }
  362.       screentype = CGFX;
  363.     }
  364.     else
  365.     {
  366.       dispid = 0x00021000; /* PAL Lores */
  367.       screentype = AGA;
  368.     }
  369.   }
  370.  
  371.   if (screentype == AGA)
  372.   {
  373.     /* Allocate resources */
  374.     temp = (unsigned char*)AllocRaster(width, height*8);
  375.     memset(temp, 0, width*height);
  376.  
  377.     InitBitMap(&agabitmap, 8, width, height); 
  378.  
  379.     for(i=0; i<8; i++)
  380.       agabitmap.Planes[i] = temp + i * RASSIZE(width, height);
  381.  
  382.     /* Open screen */
  383.     screen = OpenScreenTags(NULL,
  384.              SA_BitMap,(int)&agabitmap,
  385.              SA_Width,width,
  386.              SA_Height,height,
  387.              SA_Depth,8,
  388.              SA_Quiet,TRUE,
  389.              SA_ShowTitle,FALSE,
  390.              SA_Type,CUSTOMSCREEN,
  391.              SA_DisplayID,dispid,
  392.              TAG_DONE);
  393.  
  394.     /* Could the screen be opened? */
  395.     if(screen == NULL)
  396.     {
  397.       printf("The screen could NOT be opened!\n");
  398.       return -1;
  399.     }
  400.   }
  401.   else
  402.   {
  403.     /* Open screen */
  404.     screen = OpenScreenTags(NULL,
  405.              SA_Width,width,
  406.              SA_Height,height,
  407.              SA_Depth,8,
  408.              SA_Quiet,TRUE,
  409.              SA_ShowTitle,FALSE,
  410.              SA_Type,CUSTOMSCREEN,
  411.              SA_DisplayID,dispid,
  412.              TAG_DONE);
  413.  
  414.     /* Could the screen be opened? */
  415.     if(screen == NULL)
  416.     {
  417.       printf("The screen could NOT be opened!\n");
  418.       return -1;
  419.     }
  420.  
  421.     /* Get CGFX screenmode information */
  422.     UnLockBitMap(LockBitMapTags(screen->RastPort.BitMap,
  423.                                 LBMI_PIXFMT, (ULONG)&pixfmt,
  424.                                 LBMI_BASEADDRESS, (ULONG)&baseaddress,
  425.                                 LBMI_BYTESPERROW, (ULONG)&bpr,
  426.                                 TAG_END));
  427.   }
  428.  
  429.   /* Open window */
  430.   window=OpenWindowTags(NULL,
  431.          WA_CustomScreen,(int)screen,
  432.          WA_Width,width,
  433.          WA_Height,height,
  434.          WA_IDCMP,IDCMP_RAWKEY,
  435.          WA_Backdrop,TRUE,
  436.          WA_Borderless,TRUE,
  437.          WA_Activate,TRUE,
  438.          TAG_DONE);
  439.  
  440.   /* Could the window be opened? */
  441.   if(window == NULL)
  442.   {
  443.     CloseScreen(screen);
  444.     printf("The window could NOT be opened!\n");
  445.     return -1;
  446.   }
  447.  
  448.   if (depth == 8)
  449.   {
  450.     use_highcolor = 0;
  451.  
  452.     /* Set a 3:3:2 palette */
  453.     for(i=0; i<256; i++)
  454.     {
  455.       rgbtab[1+i*3+0]=((i & 0xe0))<<24;
  456.       rgbtab[1+i*3+1]=((i & 0x1c) << 3)<<24;
  457.       rgbtab[1+i*3+2]=((i & 0x03) << 6)<<24;
  458.     }
  459.  
  460.     rgbtab[0]=(256<<16)|0;
  461.     rgbtab[1+256*3]=0;
  462.     LoadRGB32(&screen->ViewPort, rgbtab);
  463.   }
  464.   else
  465.   {
  466.     use_highcolor = 1;
  467.     FillPixelArray(&screen->RastPort, 0, 0, width, height, 0L);
  468.   }
  469.  
  470.   /* Hide the pointer */
  471.   EmptyPointer = AllocVec(512, MEMF_CHIP|MEMF_CLEAR);
  472.   SetPointer(window, EmptyPointer, 1, 1, 0, 0);
  473.  
  474.   /* Force CD32 pad (if required) */
  475.   if ((LowLevelBase != NULL) && (use_pad == 1))
  476.     SetJoyPortAttrs(1, SJA_Type, SJA_TYPE_GAMECTLR, TAG_END);
  477.  
  478.   if (screentype == AGA)
  479.   {
  480.     agabuf = (unsigned char *)malloc(width*height);
  481.     memset(agabuf, 0, width*height);
  482.   }
  483.  
  484.   return 0;
  485. }
  486.  
  487. int gbe_init_amiga(char *display)
  488. {
  489.   if (open_libraries() < 0)
  490.   {
  491.     return 0;
  492.   }
  493.   else
  494.   {
  495.     if (open_screen() < 0)
  496.     {
  497.       close_libraries();
  498.       return 0;
  499.     }
  500.   }
  501.  
  502.   if (use_highcolor == 1)
  503.     return 2;
  504.   else
  505.     return 1;
  506. }
  507.  
  508. int gbe_close_amiga()
  509. {
  510.   close_screen();
  511.   if (screentype == AGA)
  512.   {
  513.     free(agabuf);
  514.     FreeRaster(agabitmap.Planes[0], width, height*8);
  515.   }
  516.   close_libraries();
  517.  
  518.   return 1;
  519. }
  520.  
  521. int gbe_create_window_amiga(char *title, int width, int height)
  522. {
  523.   gbe_window_width = width;
  524.   gbe_window_height = height;
  525.   xoffset = (320-width)/2;
  526.   yoffset = (256-height)/2;
  527.  
  528.   if (use_highcolor == 1)
  529.   {
  530.     gbe_window_width *= 2;
  531.     xoffset *= 2;
  532.   }
  533.  
  534.   /* AmigaOS is all good, allocate buffer */
  535.   gfx_buffer = (char *)malloc(width * height * 2);
  536.   if(!gfx_buffer) {
  537.     printf("unable to alloc buffer!\n");
  538.     return 0;
  539.   }
  540.  
  541.   gfx_buffer_high = (short *)gfx_buffer;
  542.  
  543.   return 1;
  544. }
  545.  
  546. int gbe_poll_events_amiga()
  547. {
  548.   ULONG imCode, imClass, portstate;
  549.   struct IntuiMessage *imsg = NULL;
  550.  
  551.   if ((use_pad == 0) || (LowLevelBase == NULL))
  552.   {
  553.  
  554.   /* Check for IDCMP messages */
  555.   if ((imsg=(struct IntuiMessage *)GetMsg(window->UserPort)))
  556.   {
  557.     imClass=imsg->Class;
  558.     imCode=imsg->Code;
  559.  
  560.     ReplyMsg((struct Message *)imsg);
  561.  
  562.     /* KeyPress and KeyReleases */
  563.     if(imClass==IDCMP_RAWKEY)
  564.     {
  565.       if(imCode<128) /* Key is being pressed */
  566.       {
  567.         switch(imCode)
  568.         {
  569.           case 69: /* ESC */
  570.             joypad_press(GBE_O_ESCAPE);
  571.             break;
  572.  
  573.           case 16: /* Q */
  574.             joypad_press(GBE_START);
  575.             break;
  576.  
  577.           case 17: /* W */
  578.             joypad_press(GBE_SELECT);
  579.             break;
  580.  
  581.           case 32: /* A */
  582.             joypad_press(GBE_A);
  583.             break;
  584.  
  585.           case 33: /* S */
  586.             joypad_press(GBE_B);
  587.             break;
  588.  
  589.           case 78: /* RIGHT */
  590.             joypad_press(GBE_RIGHT);
  591.             break;
  592.  
  593.           case 79: /* LEFT */
  594.             joypad_press(GBE_LEFT);
  595.             break;
  596.  
  597.           case 77: /* DOWN */
  598.             joypad_press(GBE_DOWN);
  599.             break;
  600.  
  601.           case 76: /* UP */
  602.             joypad_press(GBE_UP);
  603.             break;
  604.  
  605.           default:
  606.             break;
  607.         } /* switch(imCode) */
  608.       }
  609.       else /* (imCode>127), Key released */
  610.       {
  611.         imCode-=128; /* Remove "Key released" bit */
  612.         switch(imCode)
  613.         {
  614.           case 69: /* ESC */
  615.             joypad_release(GBE_O_ESCAPE);
  616.             break;
  617.  
  618.           case 16: /* Q */
  619.             joypad_release(GBE_START);
  620.             break;
  621.  
  622.           case 17: /* W */
  623.             joypad_release(GBE_SELECT);
  624.             break;
  625.  
  626.           case 32: /* A */
  627.             joypad_release(GBE_A);
  628.             break;
  629.  
  630.           case 33: /* S */
  631.             joypad_release(GBE_B);
  632.             break;
  633.  
  634.           case 78: /* RIGHT */
  635.             joypad_release(GBE_RIGHT);
  636.             break;
  637.  
  638.           case 79: /* LEFT */
  639.             joypad_release(GBE_LEFT);
  640.             break;
  641.  
  642.           case 77: /* DOWN */
  643.             joypad_release(GBE_DOWN);
  644.             break;
  645.  
  646.           case 76: /* UP */
  647.             joypad_release(GBE_UP);
  648.             break;
  649.  
  650.           default:
  651.             break;
  652.         } /* switch(imCode) */
  653.       } /* (imCode>127), Key released */
  654.     } /* imClass=IDCMP_RAWKEY */
  655.   } /* Check for IDCMP messages */
  656.  
  657.   }
  658.   else
  659.   {
  660.  
  661.   /* Check for IDCMP messages */
  662.   if ((imsg=(struct IntuiMessage *)GetMsg(window->UserPort)))
  663.   {
  664.     imClass=imsg->Class;
  665.     imCode=imsg->Code;
  666.  
  667.     ReplyMsg((struct Message *)imsg);
  668.  
  669.     /* KeyPress and KeyReleases */
  670.     if(imClass==IDCMP_RAWKEY)
  671.     {
  672.       if(imCode<128) /* Key is being pressed */
  673.       {
  674.         switch(imCode)
  675.         {
  676.           case 69: /* ESC */
  677.             joypad_press(GBE_O_ESCAPE);
  678.             break;
  679.  
  680.           default:
  681.             break;
  682.         } /* switch(imCode) */
  683.       }
  684.       else /* (imCode>127), Key released */
  685.       {
  686.         imCode-=128; /* Remove "Key released" bit */
  687.         switch(imCode)
  688.         {
  689.           case 69: /* ESC */
  690.             joypad_release(GBE_O_ESCAPE);
  691.             break;
  692.  
  693.           default:
  694.             break;
  695.         } /* switch(imCode) */
  696.       } /* (imCode>127), Key released */
  697.     } /* imClass=IDCMP_RAWKEY */
  698.   } /* Check for IDCMP messages */
  699.  
  700.   /* Read port 1 (joyport) */
  701.   portstate = ReadJoyPort(1);
  702.  
  703.   if (portstate&JPF_JOY_RIGHT) /* RIGHT */
  704.     joypad_press(GBE_RIGHT);
  705.   else
  706.     joypad_release(GBE_RIGHT);
  707.  
  708.   if (portstate&JPF_JOY_LEFT) /* LEFT */
  709.     joypad_press(GBE_LEFT);
  710.   else
  711.     joypad_release(GBE_LEFT);
  712.  
  713.   if (portstate&JPF_JOY_DOWN) /* DOWN */
  714.     joypad_press(GBE_DOWN);
  715.   else
  716.     joypad_release(GBE_DOWN);
  717.  
  718.   if (portstate&JPF_JOY_UP) /* UP */
  719.     joypad_press(GBE_UP);
  720.   else
  721.     joypad_release(GBE_UP);
  722.  
  723.   if (portstate&JPF_BUTTON_GREEN) /* Q */
  724.     joypad_press(GBE_START);
  725.   else
  726.     joypad_release(GBE_START);
  727.  
  728.   if (portstate&JPF_BUTTON_YELLOW) /* W */
  729.     joypad_press(GBE_SELECT);
  730.   else
  731.     joypad_release(GBE_SELECT);
  732.  
  733.   if (portstate&JPF_BUTTON_RED) /* A */
  734.     joypad_press(GBE_A);
  735.   else
  736.     joypad_release(GBE_A);
  737.  
  738.   if (portstate&JPF_BUTTON_BLUE) /* S */
  739.     joypad_press(GBE_B);
  740.   else
  741.     joypad_release(GBE_B);
  742.  
  743.   }
  744.  
  745.   return 1;
  746. }
  747.  
  748. int gbe_blit_amiga()
  749. {
  750.   unsigned char *src, *dst;
  751.   int i;
  752.  
  753.   if (screen != NULL)
  754.   {
  755.     if (screentype == AGA)
  756.     {
  757.       c2p((void *)gfx_buffer, (void *)agabitmap.Planes[0], gbe_window_width, gbe_window_height, xoffset, yoffset, RASSIZE(width, height));
  758.     }
  759.     else
  760.     {
  761.       if ((use_cgfx == 1) && (use_highcolor == 0))
  762.       {
  763.           WritePixelArray(gfx_buffer, 0, 0, gbe_window_width, &screen->RastPort, xoffset, yoffset, gbe_window_width, gbe_window_height, RECTFMT_LUT8);
  764.       }
  765.       else
  766.       {
  767.         /* Init pointers */
  768.         dst = baseaddress+(yoffset*bpr)+(xoffset);
  769.         src = gfx_buffer;
  770.  
  771.         /* Perform copy */
  772.         for (i=0; i<gbe_window_height; i++)
  773.         {
  774.           memcpy(dst, src, gbe_window_width);
  775.           dst += bpr;
  776.           src += gbe_window_width;
  777.         }
  778.       }
  779.     }
  780.   }
  781.  
  782.   return 1;
  783. }
  784.  
  785. int gbe_plot_amiga(int x, int y, int color)
  786. {
  787.   if (use_highcolor)
  788.     gfx_buffer_high[(y * (gbe_window_width >> 1)) + (x)] = color & 0xFFFF;
  789.   else
  790.     gfx_buffer[(y * (gbe_window_width)) + (x)] = color & 0xFF;
  791.  
  792.   return 1;
  793. }
  794.  
  795. #else
  796.  
  797. int gbe_init_amiga(char *display)
  798. {
  799.      return 0;
  800. }
  801.  
  802. int gbe_close_amiga()
  803. {
  804.      return 1;
  805. }
  806.  
  807. int gbe_create_window_amiga(char *title, int width, int height)
  808. {
  809.      return 1;
  810. }
  811.  
  812.  
  813. int gbe_poll_events_amiga()
  814. {
  815.      return 1;
  816. }
  817.  
  818. int gbe_blit_amiga()
  819. {
  820.      return 1;
  821. }
  822.  
  823. int gbe_plot_amiga(int x, int y, int color)
  824. {
  825.      return 1;
  826. }
  827.  
  828. #endif
  829.