home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / chip_20022115.iso / amiga / chipgame / scummvm_aga.lha / ScummVM_AGA / src / sdl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-01-05  |  30.9 KB  |  1,354 lines

  1. /* ScummVM - Scumm Interpreter
  2.  * Copyright (C) 2001  Ludvig Strigeus
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17.  *
  18.  * $Header: /cvsroot/scummvm/scummvm/sdl.cpp,v 1.18 2001/11/09 19:08:47 strigeus Exp $
  19.  *
  20.  */
  21.  
  22. //#define NEED_SDL_HEADERS
  23.  
  24. #include <exec/types.h>
  25. #include <exec/memory.h>
  26. #include <dos/dos.h>
  27. #include <intuition/intuition.h>
  28. #include <graphics/displayinfo.h>
  29. #include <graphics/gfx.h>
  30. #include <libraries/asl.h>
  31.  
  32. #include <proto/dos.h>
  33. #include <proto/intuition.h>
  34. #include <proto/graphics.h>
  35.  
  36. #include <proto/lowlevel.h>
  37. #include <clib/exec_protos.h>
  38. #include <proto/asl.h>
  39.  
  40. #include "stdafx.h"
  41. #include "scumm.h"
  42. #include "gui.h"
  43. #include "sdl.h"   // Include SDL Types...
  44.  
  45. #if defined(USE_IMUSE)
  46. #include "sound.h"
  47. #endif
  48.  
  49. //#define SCALEUP_2x2
  50.  
  51. #define ENTER 0x44
  52. #define ESC   0x45
  53. #define PAUSE 0x19
  54. #define RIGHT 0x4E
  55. #define LEFT  0x4F
  56.  
  57. Scumm scumm;
  58. ScummDebugger debugger;
  59. Gui gui;
  60.  
  61. #if defined(USE_IMUSE)
  62. SoundEngine sound;
  63. #endif
  64.  
  65. //static SDL_Surface *screen;
  66. UWORD *BLANKPointer;
  67. static char *screen;
  68. static struct Screen *scr;
  69. static struct Window *win;
  70.  
  71. void updatePalette(Scumm *s) {
  72.  
  73.     ULONG colorsAGA[770];
  74.  
  75.     int first = s->_palDirtyMin;
  76.     int num = s->_palDirtyMax - first + 1;
  77.     int i,j;
  78.     byte *data = s->_currentPalette;
  79.  
  80.     data += first*3;
  81.     j=1;
  82.     for (i=0; i<num; i++,data+=3) {
  83.         colorsAGA[j] = (data[0]<<2)<<24;
  84.         colorsAGA[j+1] = (data[1]<<2)<<24;
  85.         colorsAGA[j+2] = (data[2]<<2)<<24;
  86.         //colors[i].unused = 0;
  87.         if (first!=0)
  88.         SetRGB32(&scr->ViewPort,first+i,colorsAGA[j],colorsAGA[j+1],colorsAGA[j+2]);
  89.  
  90.         j+=3;
  91.     }
  92.     colorsAGA[((num*3)+1)]=0x00000000; // Terminator: NEEDED
  93.     colorsAGA[0]=num<<16;
  94.  
  95.     // Conversion de la palette 8Bits en palette 32Bits pour LoadRGB32()
  96.     if (first==0)
  97.         LoadRGB32(&scr->ViewPort,colorsAGA);
  98.  
  99.     s->_palDirtyMax = -1;
  100.     s->_palDirtyMin = 0x3E8;
  101. }
  102.  
  103. /* void updatePalette(Scumm *s) {
  104.     SDL_Color colors[256];
  105.     int first = s->_palDirtyMin;
  106.     int num = s->_palDirtyMax - first + 1;
  107.     int i;
  108.     byte *data = s->_currentPalette;
  109.  
  110.     data += first*3;
  111.     for (i=0; i<num; i++,data+= 3) {
  112.         colors[i].r = data[0]<<2;
  113.         colors[i].g = data[1]<<2;
  114.         colors[i].b = data[2]<<2;
  115.         colors[i].unused = 0;
  116.     }
  117.     
  118.     SDL_SetColors(screen, colors, first, num);
  119.     
  120.     s->_palDirtyMax = -1;
  121.     s->_palDirtyMin = 0x3E8;
  122. }
  123. */
  124.  
  125. int mapKey(int key, byte mod) {
  126.     /*
  127.     if (key>=SDLK_F1 && key<=SDLK_F9) {
  128.         return key - SDLK_F1 + 315;
  129.     } else if (key>='a' && key<='z' && mod&KMOD_SHIFT) {
  130.         key&=~0x20;
  131.     } else if (key>=SDLK_NUMLOCK && key<=SDLK_EURO)
  132.         return 0;
  133.     return key;
  134.     */
  135.     return 0;
  136. }
  137.  
  138. /*int mapKey(int key, byte mod) {
  139.     if (key>=SDLK_F1 && key<=SDLK_F9) {
  140.         return key - SDLK_F1 + 315;
  141.     } else if (key>='a' && key<='z' && mod&KMOD_SHIFT) {
  142.         key&=~0x20;
  143.     } else if (key>=SDLK_NUMLOCK && key<=SDLK_EURO)
  144.         return 0;
  145.     return key;
  146. }
  147. */
  148.  
  149. void waitForTimer(Scumm *s)
  150. {
  151.     //SDL_Event event;
  152.     byte dontPause = true;
  153.     
  154.     WORD mx, my;
  155.     int key;
  156.     struct IntuiMessage *msg;
  157.  
  158.     do
  159.     {
  160.        //s->_rightBtnPressed |= 0;
  161.        //s->_leftBtnPressed |= 0;
  162.        while (msg = (struct IntuiMessage *)GetMsg(win->UserPort))
  163.        {
  164.            mx = msg->MouseX;
  165.            my = msg->MouseY;
  166.            ReplyMsg((struct Message *)msg);
  167.            //printf("Switch\n");
  168.            switch (msg->Class)
  169.            {
  170.              case IDCMP_VANILLAKEY:
  171.  
  172.               s->_keyPressed=msg->Code;
  173.  
  174.               if ((msg->Code > '0') && (msg->Code <= '9'))
  175.                 { s->_saveLoadSlot = msg->Code - '0';
  176.               if (msg->Qualifier&IEQUALIFIER_RSHIFT)
  177.                  {
  178.  
  179.                         sprintf(s->_saveLoadName, "Quicksave %d", s->_saveLoadSlot);
  180.                         //printf("ShiftDROIT+Chiffre => %s\n",s->_saveLoadName);
  181.                         s->_saveLoadFlag = 1;    }
  182.                     else if (msg->Qualifier&=IEQUALIFIER_LSHIFT)
  183.                         s->_saveLoadFlag = 2;
  184.                     s->_saveLoadCompatible = false;
  185.  
  186.  
  187.              }
  188.              break;
  189.  
  190.              case IDCMP_RAWKEY:
  191.                   // F1 - F9 Pressed
  192.                   key=msg->Code;
  193.                   if ((key >= 0x50) && (key <= 0x58))
  194.                   {
  195.                     s->_keyPressed=0;
  196.                     printf("Warning: Function keys disabled \n");
  197.                     /*key+=202;
  198.                     s->_keyPressed=(key-282+315);
  199.                     printf("Fonction: key=%d\n",key);
  200.                     */
  201.                   }
  202.                   else s->_keyPressed=0;
  203.  
  204.  
  205.              break;
  206.  
  207.              case IDCMP_MOUSEMOVE:
  208.                 int newx,newy;
  209.                 newx=mx;newy=my;
  210.                 //printf("MouseMove: mx=%d, my=%d, s->mouse.x=%d, s->mouse.y=%d\n",mx,my,s->mouse.x,s->mouse.y);
  211.                 if (newx != s->mouse.x || newy != s->mouse.y)
  212.                  {
  213.                     s->mouse.x = newx;
  214.                     s->mouse.y = newy;
  215.                     s->drawMouse();
  216.                     updateScreen(s);
  217.                   }
  218.              break;
  219.  
  220.              case IDCMP_ACTIVEWINDOW:
  221.                 //printf("Active\n");
  222.                 //active=TRUE;
  223.              break;
  224.  
  225.              case IDCMP_INACTIVEWINDOW:
  226.                 //active=FALSE;
  227.                 //printf("Inactive\n");
  228.              break;
  229.  
  230.              case IDCMP_MOUSEBUTTONS:
  231.                 if (msg->Code==MENUUP)
  232.                 {
  233.  
  234.                     s->_rightBtnPressed |= 1;
  235.                  }
  236.                  else if (msg->Code==SELECTUP)
  237.                     {
  238.                     s->_leftBtnPressed |= 1;}
  239.              break;
  240.            }
  241.        }
  242.         //if (!(s->_fastMode&2))
  243.       //SDL_Delay(dontPause ? 10 : 100);
  244.         Delay(dontPause ? 1 : 10);
  245.      } while (!dontPause);
  246. }
  247.  
  248. /*void waitForTimer(Scumm *s) {
  249.     SDL_Event event;
  250.     byte dontPause = true;
  251.  
  252.     do {
  253.         while (SDL_PollEvent(&event)) {
  254.             switch(event.type) {
  255.             case SDL_KEYDOWN:
  256.                 s->_keyPressed = mapKey(event.key.keysym.sym, event.key.keysym.mod);
  257.                 if (event.key.keysym.sym >= '0' && event.key.keysym.sym<='9')
  258.                     {
  259.                     de 0 α 9: + shift: on sauve...
  260.                     s->_saveLoadSlot = event.key.keysym.sym - '0';
  261.                     if (event.key.keysym.mod&KMOD_SHIFT) {
  262.                         sprintf(s->_saveLoadName, "Quicksave %d", s->_saveLoadSlot);
  263.                         s->_saveLoadFlag = 1;
  264.                         de 0 α 9 + ctrl: on charge/sauve
  265.                     } else if (event.key.keysym.mod&KMOD_CTRL)
  266.                         s->_saveLoadFlag = 2;
  267.                     s->_saveLoadCompatible = false;
  268.                 }
  269.                 z+ctrl: on quitte
  270.                 if (event.key.keysym.sym=='z' && event.key.keysym.mod&KMOD_CTRL) {
  271.                     exit(1);
  272.                 }
  273.                 f+ctrl: fastmode
  274.                 if (event.key.keysym.sym=='f' && event.key.keysym.mod&KMOD_CTRL) {
  275.                     s->_fastMode ^= 1;
  276.                 }
  277.                 g+ctrl:fastmode
  278.                 if (event.key.keysym.sym=='g' && event.key.keysym.mod&KMOD_CTRL) {
  279.                     s->_fastMode ^= 2;
  280.                 }
  281.                 d+ctrl:debgguer
  282.                 if (event.key.keysym.sym=='d' && event.key.keysym.mod&KMOD_CTRL) {
  283.                     debugger.attach(s);
  284.                 }
  285.                 s+ctrl: resource
  286.                 if (event.key.keysym.sym=='s' && event.key.keysym.mod&KMOD_CTRL) {
  287.                     s->resourceStats();
  288.                 }
  289.  
  290.                 break;
  291.             case SDL_MOUSEMOTION: {
  292.                 int newx,newy;
  293. #if !defined(SCALEUP_2x2)
  294.                 newx = event.motion.x;
  295.                 newy = event.motion.y;
  296. #else
  297.                 newx = event.motion.x>>1;
  298.                 newy = event.motion.y>>1;
  299. #endif
  300.                 if (newx != s->mouse.x || newy != s->mouse.y) {
  301.                     s->mouse.x = newx;
  302.                     s->mouse.y = newy;
  303.                     s->drawMouse();
  304.                     updateScreen(s);
  305.                 }
  306.                 break;
  307.                 }
  308.             case SDL_MOUSEBUTTONDOWN:
  309.                 if (event.button.button==SDL_BUTTON_LEFT)
  310.                     s->_leftBtnPressed |= 1;
  311.                 else if (event.button.button==SDL_BUTTON_RIGHT)
  312.                     s->_rightBtnPressed |= 1;
  313.                 break;
  314. #if 0
  315.             case SDL_ACTIVEEVENT:
  316.                 if (event.active.state & SDL_APPINPUTFOCUS) {
  317.                     dontPause = event.active.gain;
  318.                 }
  319.                 break;
  320. #endif
  321.             case SDL_QUIT:
  322.                 exit(1);
  323.                 break;
  324.             }
  325.         }
  326.  
  327.         if (!(s->_fastMode&2))
  328.             SDL_Delay(dontPause ? 10 : 100);
  329.     } while (!dontPause);
  330.  
  331. }
  332. */
  333.  
  334. #define MAX_DIRTY_RECTS 40
  335. SDL_Rect dirtyRects[MAX_DIRTY_RECTS];
  336. int numDirtyRects;
  337. bool fullRedraw;
  338.  
  339. int old_mouse_x, old_mouse_y;
  340. int old_mouse_h, old_mouse_w;
  341. bool has_mouse,hide_mouse;
  342.  
  343. #define BAK_WIDTH 40
  344. #define BAK_HEIGHT 24
  345. byte old_backup[BAK_WIDTH*BAK_HEIGHT*2];
  346.  
  347.  
  348. void addDirtyRect(int x, int y, int w, int h) {
  349.     SDL_Rect *r;
  350.     if (numDirtyRects==MAX_DIRTY_RECTS)
  351.         fullRedraw = true;
  352.     else if (!fullRedraw) {
  353.         r = &dirtyRects[numDirtyRects++];
  354. #if defined(SCALEUP_2x2)
  355.         r->x = x*2;
  356.         r->y = y*2;
  357.         r->w = w*2;
  358.         r->h = h*2;
  359. #else
  360.         r->x = x;
  361.         r->y = y;
  362.         r->w = w;
  363.         r->h = h;
  364. #endif
  365.     }
  366. }
  367.  
  368. void addDirtyRectClipped(int x, int y, int w, int h) {
  369.     if (x<0) { w += x; x=0; }
  370.     if (y<0) { h += y; y=0; }
  371.     if (w >= 320-x) w = 320-x;
  372.     if (h >= 200-y) h = 200-y;
  373.     if (w>0 && h>0)
  374.         addDirtyRect(x,y,w,h);
  375. }
  376.  
  377. /* Copy part of bitmap */
  378. // AGA version...
  379. void blitToScreen(Scumm *s, byte *src,int x, int y, int w, int h) {
  380.     byte *dst;
  381.     int i;
  382.  
  383.     hide_mouse = true;
  384.     if (has_mouse) {
  385.         s->drawMouse();
  386.     }
  387.  
  388.     //if (SDL_LockSurface(screen)==-1)
  389.     //      error("SDL_LockSurface failed: %s.\n", SDL_GetError());
  390.  
  391. #if !defined(SCALEUP_2x2)
  392.     // Addresse du pixel en dst
  393.     dst = (byte*)screen + y*320 + x;
  394.     addDirtyRect(x,y,w,h);
  395.     do {
  396.         memcpy(dst, src, w);
  397.         dst += 320;
  398.         src += 320;
  399.     } while (--h);
  400.     // AJOUT
  401.     //WriteChunkyPixels(win->RPort,x,y,x+w,y+h,(UBYTE *)screen+y*320+x,320);
  402. #else
  403.     dst = (byte*)screen + y*640*2 + x*2;
  404.     addDirtyRect(x,y,w,h);        
  405.     do {
  406.         i=0;
  407.         do {
  408.             dst[i*2] = dst[i*2+1] = src[i];
  409.         } while (++i!=w);
  410.         memcpy(dst+640, dst, w*2);
  411.         dst += 640*2;
  412.         src += 320;
  413.     } while (--h);
  414.  
  415. #endif
  416.  
  417.     //SDL_UnlockSurface(screen);
  418. }
  419. /*
  420. void blitToScreen(Scumm *s, byte *src,int x, int y, int w, int h) {
  421.     byte *dst;
  422.     int i;
  423.  
  424.     hide_mouse = true;
  425.     if (has_mouse) {
  426.         s->drawMouse();
  427.     }
  428.  
  429.     if (SDL_LockSurface(screen)==-1)
  430.         error("SDL_LockSurface failed: %s.\n", SDL_GetError());
  431.  
  432. #if !defined(SCALEUP_2x2)
  433.     // Addresse du pixel en dst
  434.     dst = (byte*)screen->pixels + y*320 + x;
  435.     addDirtyRect(x,y,w,h);
  436.     do {
  437.         memcpy(dst, src, w);
  438.         dst += 320;
  439.         src += 320;
  440.     } while (--h);
  441.     // AGA WriteChunkyPixels(win->RPort,x,y,x+w,y+h,320);
  442. #else
  443.     dst = (byte*)screen->pixels + y*640*2 + x*2;
  444.     addDirtyRect(x,y,w,h);
  445.     do {
  446.         i=0;
  447.         do {
  448.             dst[i*2] = dst[i*2+1] = src[i];
  449.         } while (++i!=w);
  450.         memcpy(dst+640, dst, w*2);
  451.         dst += 640*2;
  452.         src += 320;
  453.     } while (--h);
  454.  
  455. #endif
  456.  
  457.     SDL_UnlockSurface(screen);
  458. }
  459. */
  460.  
  461. void updateScreen(Scumm *s) {
  462.     int k;
  463.     if (s->_fastMode&2)
  464.         return;
  465.  
  466.     if (hide_mouse) {
  467.         hide_mouse = false;
  468.         s->drawMouse();
  469.     }
  470.     
  471.     if(s->_palDirtyMax != -1) {
  472.         updatePalette(s);
  473.     }
  474.     if (fullRedraw) {
  475.         //SDL_UpdateRect(screen, 0,0,0,0);
  476.         WriteChunkyPixels(win->RPort,0,0,319,199,(UBYTE *)screen,320);
  477. #if defined(SHOW_AREA)
  478.         debug(2,"update area 100 %%");
  479. #endif
  480.     } else if (numDirtyRects) {
  481. #if defined(SHOW_AREA)
  482.         int area = 0,i;
  483.         for (i=0; i<numDirtyRects; i++)
  484.             area += (dirtyRects[i].w * dirtyRects[i].h);
  485.         debug(2,"update area %f %%", (float)area/640);
  486. #endif
  487.  
  488.         // SDL_UpdateRects(screen, numDirtyRects, dirtyRects);
  489.         for (k=0; k<numDirtyRects; k++)
  490.             WriteChunkyPixels(win->RPort,dirtyRects[k].x,dirtyRects[k].y,dirtyRects[k].x+dirtyRects[k].w,dirtyRects[k].y+dirtyRects[k].h,(UBYTE *)screen+dirtyRects[k].y*320+dirtyRects[k].x,320);
  491.  
  492.     }
  493.  
  494.     numDirtyRects = 0;
  495. }
  496.  
  497. /*void updateScreen(Scumm *s) {
  498.  
  499.     if (s->_fastMode&2)
  500.         return;
  501.  
  502.     if (hide_mouse) {
  503.         hide_mouse = false;
  504.         s->drawMouse();
  505.     }
  506.  
  507.     if(s->_palDirtyMax != -1) {
  508.         updatePalette(s);
  509.     }
  510.     if (fullRedraw) {
  511.         SDL_UpdateRect(screen, 0,0,0,0);
  512. #if defined(SHOW_AREA)
  513.         debug(2,"update area 100 %%");
  514. #endif
  515.     } else if (numDirtyRects) {
  516. #if defined(SHOW_AREA)
  517.         int area = 0,i;
  518.         for (i=0; i<numDirtyRects; i++)
  519.             area += (dirtyRects[i].w * dirtyRects[i].h);
  520.         debug(2,"update area %f %%", (float)area/640);
  521. #endif
  522.  
  523.         SDL_UpdateRects(screen, numDirtyRects, dirtyRects);
  524.     }
  525.  
  526.     numDirtyRects = 0;
  527. }
  528. */
  529. void drawMouse(Scumm *s, int xdraw, int ydraw, int w, int h, byte *buf, bool visible) {
  530.     //printf("drawMouse(1)\n");
  531.     int x,y;
  532.     byte *dst,*bak;
  533.     byte color;
  534.  
  535.     if (hide_mouse)
  536.         visible = false;
  537.  
  538.     //if (SDL_LockSurface(screen)==-1)
  539.     //      error("SDL_LockSurface failed: %s.\n", SDL_GetError());
  540.  
  541. #if defined(SCALEUP_2x2)
  542.  
  543.     if (has_mouse) {
  544.         dst = (byte*)screen->pixels + old_mouse_y*640*2 + old_mouse_x*2;
  545.         bak = old_backup;
  546.  
  547.         for (y=0; y<old_mouse_h; y++,bak+=BAK_WIDTH*2,dst+=640*2) {
  548.             if ( (uint)(old_mouse_y + y) < 200) {
  549.                 for (x=0; x<old_mouse_w; x++) {
  550.                     if ((uint)(old_mouse_x + x) < 320) {
  551.                         dst[x*2+640] = dst[x*2] = bak[x*2];
  552.                         dst[x*2+640+1] = dst[x*2+1] = bak[x*2+1];
  553.                     }
  554.                 }
  555.             }
  556.         }
  557.     }
  558.  
  559.     if (visible) {
  560.         dst = (byte*)screen->pixels + ydraw*640*2 + xdraw*2;
  561.         bak = old_backup;
  562.  
  563.         for (y=0; y<h; y++,dst+=640*2,bak+=BAK_WIDTH*2,buf+=w) {
  564.             if ((uint)(ydraw+y)<200) {
  565.                 for (x=0; x<w; x++) {
  566.                     if ((uint)(xdraw+x)<320) {
  567.                         bak[x*2] = dst[x*2];
  568.                         bak[x*2+1] = dst[x*2+1];
  569.                         if ((color=buf[x])!=0xFF) {
  570.                             dst[x*2] = color;
  571.                             dst[x*2+1] = color;
  572.                             dst[x*2+640] = color;
  573.                             dst[x*2+1+640] = color;
  574.                         }
  575.                     }
  576.                 }
  577.             }
  578.         }
  579.     }
  580. #else
  581.     if (has_mouse) {
  582.         dst = (byte*)screen + old_mouse_y*320 + old_mouse_x;
  583.         bak = old_backup;
  584.  
  585.         for (y=0; y<h; y++,bak+=BAK_WIDTH,dst+=320) {
  586.             if ( (uint)(old_mouse_y + y) < 200) {
  587.                 for (x=0; x<w; x++) {
  588.                     if ((uint)(old_mouse_x + x) < 320) {
  589.                         dst[x] = bak[x];
  590.                     }
  591.                 }
  592.             }
  593.         }
  594.     }
  595.     if (visible) {
  596.         dst = (byte*)screen + ydraw*320 + xdraw;
  597.         bak = old_backup;
  598.  
  599.         for (y=0; y<h; y++,dst+=320,bak+=BAK_WIDTH,buf+=w) {
  600.             if ((uint)(ydraw+y)<200) {
  601.                 for (x=0; x<w; x++) {
  602.                     if ((uint)(xdraw+x)<320) {
  603.                         bak[x] = dst[x];
  604.                         if ((color=buf[x])!=0xFF) {
  605.                             dst[x] = color;
  606.                         }
  607.                     }
  608.                 }
  609.             }
  610.         }
  611.     }
  612.  
  613.  
  614. #endif    
  615.  
  616.     //SDL_UnlockSurface(screen);
  617.  
  618.     if (has_mouse) {
  619.         has_mouse = false;
  620.         addDirtyRectClipped(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h);
  621.     }
  622.  
  623.     if (visible) {
  624.         has_mouse = true;
  625.         addDirtyRectClipped(xdraw, ydraw, w, h);
  626.         old_mouse_x = xdraw;
  627.         old_mouse_y = ydraw;
  628.         old_mouse_w = w;
  629.         old_mouse_h = h;
  630.     }
  631. }
  632.  
  633. /*void drawMouse(Scumm *s, int xdraw, int ydraw, int w, int h, byte *buf, bool visible) {
  634.     int x,y;
  635.     byte *dst,*bak;
  636.     byte color;
  637.                            m
  638.     if (hide_mouse)
  639.         visible = false;
  640.  
  641.     if (SDL_LockSurface(screen)==-1)
  642.         error("SDL_LockSurface failed: %s.\n", SDL_GetError());
  643.  
  644. #if defined(SCALEUP_2x2)
  645.  
  646.     if (has_mouse) {
  647.         dst = (byte*)screen->pixels + old_mouse_y*640*2 + old_mouse_x*2;
  648.         bak = old_backup;
  649.  
  650.         for (y=0; y<old_mouse_h; y++,bak+=BAK_WIDTH*2,dst+=640*2) {
  651.             if ( (uint)(old_mouse_y + y) < 200) {
  652.                 for (x=0; x<old_mouse_w; x++) {
  653.                     if ((uint)(old_mouse_x + x) < 320) {
  654.                         dst[x*2+640] = dst[x*2] = bak[x*2];
  655.                         dst[x*2+640+1] = dst[x*2+1] = bak[x*2+1];
  656.                     }
  657.                 }
  658.             }
  659.         }
  660.     }
  661.  
  662.     if (visible) {
  663.         dst = (byte*)screen->pixels + ydraw*640*2 + xdraw*2;
  664.         bak = old_backup;
  665.  
  666.         for (y=0; y<h; y++,dst+=640*2,bak+=BAK_WIDTH*2,buf+=w) {
  667.             if ((uint)(ydraw+y)<200) {
  668.                 for (x=0; x<w; x++) {
  669.                     if ((uint)(xdraw+x)<320) {
  670.                         bak[x*2] = dst[x*2];
  671.                         bak[x*2+1] = dst[x*2+1];
  672.                         if ((color=buf[x])!=0xFF) {
  673.                             dst[x*2] = color;
  674.                             dst[x*2+1] = color;
  675.                             dst[x*2+640] = color;
  676.                             dst[x*2+1+640] = color;
  677.                         }
  678.                     }
  679.                 }
  680.             }
  681.         }
  682.     }
  683. #else
  684.     if (has_mouse) {
  685.         dst = (byte*)screen->pixels + old_mouse_y*320 + old_mouse_x;
  686.         bak = old_backup;
  687.  
  688.         for (y=0; y<h; y++,bak+=BAK_WIDTH,dst+=320) {
  689.             if ( (uint)(old_mouse_y + y) < 200) {
  690.                 for (x=0; x<w; x++) {
  691.                     if ((uint)(old_mouse_x + x) < 320) {
  692.                         dst[x] = bak[x];
  693.                     }
  694.                 }
  695.             }
  696.         }
  697.     }
  698.     if (visible) {
  699.         dst = (byte*)screen->pixels + ydraw*320 + xdraw;
  700.         bak = old_backup;
  701.  
  702.         for (y=0; y<h; y++,dst+=320,bak+=BAK_WIDTH,buf+=w) {
  703.             if ((uint)(ydraw+y)<200) {
  704.                 for (x=0; x<w; x++) {
  705.                     if ((uint)(xdraw+x)<320) {
  706.                         bak[x] = dst[x];
  707.                         if ((color=buf[x])!=0xFF) {
  708.                             dst[x] = color;
  709.                         }
  710.                     }
  711.                 }
  712.             }
  713.         }
  714.     }
  715.  
  716.  
  717. #endif
  718.  
  719.     SDL_UnlockSurface(screen);
  720.  
  721.     if (has_mouse) {
  722.         has_mouse = false;
  723.         addDirtyRectClipped(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h);
  724.     }
  725.  
  726.     if (visible) {
  727.         has_mouse = true;
  728.         addDirtyRectClipped(xdraw, ydraw, w, h);
  729.         old_mouse_x = xdraw;
  730.         old_mouse_y = ydraw;
  731.         old_mouse_w = w;
  732.         old_mouse_h = h;
  733.     }
  734. }*/
  735.  
  736. void drawMouse(Scumm *s, int xdraw, int ydraw, int color, byte *mask, bool visible) {
  737.  
  738.     int x,y;
  739.     uint32 bits;
  740.     byte *dst,*bak;
  741.  
  742.     if (hide_mouse)
  743.         visible = false;
  744.  
  745.     //if (SDL_LockSurface(screen)==-1)
  746.     //      error("SDL_LockSurface failed: %s.\n", SDL_GetError());
  747.  
  748. #if defined(SCALEUP_2x2)
  749.  
  750.     if (has_mouse) {
  751.         dst = (byte*)screen + old_mouse_y*640*2 + old_mouse_x*2;
  752.         bak = old_backup;
  753.  
  754.         for (y=0; y<16; y++,bak+=48,dst+=640*2) {
  755.             if ( (uint)(old_mouse_y + y) < 200) {
  756.                 for (x=0; x<24; x++) {
  757.                     if ((uint)(old_mouse_x + x) < 320) {
  758.                         dst[x*2+640] = dst[x*2] = bak[x*2];
  759.                         dst[x*2+640+1] = dst[x*2+1] = bak[x*2+1];
  760.                     }
  761.                 }
  762.             }
  763.         }
  764.     }
  765.  
  766.     if (visible) {
  767.         dst = (byte*)screen + ydraw*640*2 + xdraw*2;
  768.         bak = old_backup;
  769.  
  770.         for (y=0; y<16; y++,dst+=640*2,bak+=48) {
  771.             bits = mask[3] | (mask[2]<<8) | (mask[1]<<16);
  772.             mask += 4;
  773.             if ((uint)(ydraw+y)<200) {
  774.                 for (x=0; x<24; x++,bits<<=1) {
  775.                     if ((uint)(xdraw+x)<320) {
  776.                         bak[x*2] = dst[x*2];
  777.                         bak[x*2+1] = dst[x*2+1];
  778.                         if (bits&(1<<23)) {
  779.                             dst[x*2] = color;
  780.                             dst[x*2+1] = color;
  781.                             dst[x*2+640] = color;
  782.                             dst[x*2+1+640] = color;
  783.                         }
  784.                     }
  785.                 }
  786.             }
  787.         }
  788.     }
  789. #else
  790.     if (has_mouse) {
  791.         dst = (byte*)screen + old_mouse_y*320 + old_mouse_x;
  792.         bak = old_backup;
  793.  
  794.         for (y=0; y<16; y++,bak+=24,dst+=320) {
  795.             if ( (uint)(old_mouse_y + y) < 200) {
  796.                 for (x=0; x<24; x++) {
  797.                     if ((uint)(old_mouse_x + x) < 320) {
  798.                         dst[x] = bak[x];
  799.                     }
  800.                 }
  801.             }
  802.         }
  803.     }
  804.     if (visible) {
  805.         dst = (byte*)screen + ydraw*320 + xdraw;
  806.         bak = old_backup;
  807.  
  808.         for (y=0; y<16; y++,dst+=320,bak+=24) {
  809.             bits = mask[3] | (mask[2]<<8) | (mask[1]<<16);
  810.             mask += 4;
  811.             if ((uint)(ydraw+y)<200) {
  812.                 for (x=0; x<24; x++,bits<<=1) {
  813.                     if ((uint)(xdraw+x)<320) {
  814.                         bak[x] = dst[x];
  815.                         if (bits&(1<<23)) {
  816.                             dst[x] = color;
  817.                         }
  818.                     }
  819.                 }
  820.             }
  821.         }
  822.     }
  823.  
  824.  
  825. #endif    
  826.  
  827.     //SDL_UnlockSurface(screen);
  828.  
  829.     if (has_mouse) {
  830.         has_mouse = false;
  831.         addDirtyRectClipped(old_mouse_x, old_mouse_y, 24, 16);
  832.     }
  833.  
  834.     if (visible) {
  835.         has_mouse = true;
  836.         addDirtyRectClipped(xdraw, ydraw, 24, 16);
  837.         old_mouse_x = xdraw;
  838.         old_mouse_y = ydraw;
  839.     }
  840.  
  841. }
  842.  
  843. /*void drawMouse(Scumm *s, int xdraw, int ydraw, int color, byte *mask, bool visible) {
  844.     int x,y;
  845.     uint32 bits;
  846.     byte *dst,*bak;
  847.  
  848.     if (hide_mouse)
  849.         visible = false;
  850.  
  851.     if (SDL_LockSurface(screen)==-1)
  852.         error("SDL_LockSurface failed: %s.\n", SDL_GetError());
  853.  
  854. #if defined(SCALEUP_2x2)
  855.  
  856.     if (has_mouse) {
  857.         dst = (byte*)screen->pixels + old_mouse_y*640*2 + old_mouse_x*2;
  858.         bak = old_backup;
  859.  
  860.         for (y=0; y<16; y++,bak+=48,dst+=640*2) {
  861.             if ( (uint)(old_mouse_y + y) < 200) {
  862.                 for (x=0; x<24; x++) {
  863.                     if ((uint)(old_mouse_x + x) < 320) {
  864.                         dst[x*2+640] = dst[x*2] = bak[x*2];
  865.                         dst[x*2+640+1] = dst[x*2+1] = bak[x*2+1];
  866.                     }
  867.                 }
  868.             }
  869.         }
  870.     }
  871.  
  872.     if (visible) {
  873.         dst = (byte*)screen->pixels + ydraw*640*2 + xdraw*2;
  874.         bak = old_backup;
  875.  
  876.         for (y=0; y<16; y++,dst+=640*2,bak+=48) {
  877.             bits = mask[3] | (mask[2]<<8) | (mask[1]<<16);
  878.             mask += 4;
  879.             if ((uint)(ydraw+y)<200) {
  880.                 for (x=0; x<24; x++,bits<<=1) {
  881.                     if ((uint)(xdraw+x)<320) {
  882.                         bak[x*2] = dst[x*2];
  883.                         bak[x*2+1] = dst[x*2+1];
  884.                         if (bits&(1<<23)) {
  885.                             dst[x*2] = color;
  886.                             dst[x*2+1] = color;
  887.                             dst[x*2+640] = color;
  888.                             dst[x*2+1+640] = color;
  889.                         }
  890.                     }
  891.                 }
  892.             }
  893.         }
  894.     }
  895. #else
  896.     if (has_mouse) {
  897.         dst = (byte*)screen->pixels + old_mouse_y*320 + old_mouse_x;
  898.         bak = old_backup;
  899.  
  900.         for (y=0; y<16; y++,bak+=24,dst+=320) {
  901.             if ( (uint)(old_mouse_y + y) < 200) {
  902.                 for (x=0; x<24; x++) {
  903.                     if ((uint)(old_mouse_x + x) < 320) {
  904.                         dst[x] = bak[x];
  905.                     }
  906.                 }
  907.             }
  908.         }
  909.     }
  910.     if (visible) {
  911.         dst = (byte*)screen->pixels + ydraw*320 + xdraw;
  912.         bak = old_backup;
  913.  
  914.         for (y=0; y<16; y++,dst+=320,bak+=24) {
  915.             bits = mask[3] | (mask[2]<<8) | (mask[1]<<16);
  916.             mask += 4;
  917.             if ((uint)(ydraw+y)<200) {
  918.                 for (x=0; x<24; x++,bits<<=1) {
  919.                     if ((uint)(xdraw+x)<320) {
  920.                         bak[x] = dst[x];
  921.                         if (bits&(1<<23)) {
  922.                             dst[x] = color;
  923.                         }
  924.                     }
  925.                 }
  926.             }
  927.         }
  928.     }
  929.  
  930.  
  931. #endif
  932.  
  933.     SDL_UnlockSurface(screen);
  934.  
  935.     if (has_mouse) {
  936.         has_mouse = false;
  937.         addDirtyRectClipped(old_mouse_x, old_mouse_y, 24, 16);
  938.     }
  939.  
  940.     if (visible) {
  941.         has_mouse = true;
  942.         addDirtyRectClipped(xdraw, ydraw, 24, 16);
  943.         old_mouse_x = xdraw;
  944.         old_mouse_y = ydraw;
  945.     }
  946.  
  947. }*/
  948.  
  949. #define SAMPLES_PER_SEC 22050
  950. #define BUFFER_SIZE (8192)
  951. #define BITS_PER_SAMPLE 16
  952.  
  953. struct MixerChannel {
  954.     void *_sfx_sound;
  955.     uint32 _sfx_pos;
  956.     uint32 _sfx_size;
  957.     uint32 _sfx_fp_speed;
  958.     uint32 _sfx_fp_pos;
  959.  
  960.     void mix(int16 *data, uint32 len);
  961.     void clear();
  962. };
  963.  
  964. #define NUM_MIXER 4
  965.  
  966. static MixerChannel mixer_channel[NUM_MIXER];
  967.  
  968. MixerChannel *find_channel() {
  969.     printf("find_channel()\n");
  970.     /*
  971.     int i;
  972.     MixerChannel *mc = mixer_channel;
  973.     for(i=0; i<NUM_MIXER; i++,mc++) {
  974.         if (!mc->_sfx_sound)
  975.             return mc;
  976.     }
  977. */
  978.     return NULL;
  979. }
  980.  
  981. /*MixerChannel *find_channel() {
  982.     int i;
  983.     MixerChannel *mc = mixer_channel;
  984.     for(i=0; i<NUM_MIXER; i++,mc++) {
  985.         if (!mc->_sfx_sound)
  986.             return mc;
  987.     }
  988.     return NULL;
  989. }*/
  990.  
  991.  
  992. bool isSfxFinished() {
  993.     printf("isSfxFinished()\n");
  994.     /*
  995.     int i;
  996.     for(i=0; i<NUM_MIXER; i++)
  997.         if (mixer_channel[i]._sfx_sound)
  998.             return false;
  999.     */
  1000.     return true;
  1001. }
  1002.  
  1003. /*bool isSfxFinished() {
  1004.     int i;
  1005.     for(i=0; i<NUM_MIXER; i++)
  1006.         if (mixer_channel[i]._sfx_sound)
  1007.             return false;
  1008.     return true;
  1009. }*/
  1010.  
  1011. void playSfxSound(void *sound, uint32 size, uint rate) {
  1012. printf("playSfxSound()\n");
  1013. /*      MixerChannel *mc = find_channel();
  1014.  
  1015.     if (!mc) {
  1016.         warning("No mixer channel available");
  1017.         return;
  1018.     }
  1019.  
  1020.     mc->_sfx_sound = sound;
  1021.     mc->_sfx_pos = 0;
  1022.     mc->_sfx_fp_speed = (1<<16) * rate / 22050;
  1023.     mc->_sfx_fp_pos = 0;
  1024.  
  1025.     while (size&0xFFFF0000) size>>=1, rate>>=1;
  1026.     mc->_sfx_size = size * 22050 / rate;  */
  1027. }
  1028.  
  1029. /*void playSfxSound(void *sound, uint32 size, uint rate) {
  1030.     MixerChannel *mc = find_channel();
  1031.  
  1032.     if (!mc) {
  1033.         warning("No mixer channel available");
  1034.         return;
  1035.     }
  1036.  
  1037.     mc->_sfx_sound = sound;
  1038.     mc->_sfx_pos = 0;
  1039.     mc->_sfx_fp_speed = (1<<16) * rate / 22050;
  1040.     mc->_sfx_fp_pos = 0;
  1041.  
  1042.     while (size&0xFFFF0000) size>>=1, rate>>=1;
  1043.     mc->_sfx_size = size * 22050 / rate;
  1044. }*/
  1045.  
  1046. void MixerChannel::mix(int16 *data, uint32 len) {
  1047.     printf("MixerChannel::mix()\n");
  1048.     /*int8 *s;
  1049.     int i;
  1050.     uint32 fp_pos, fp_speed;
  1051.  
  1052.     if (!_sfx_sound)
  1053.         return;
  1054.     if (len > _sfx_size)
  1055.         len = _sfx_size;
  1056.     _sfx_size -= len;
  1057.  
  1058.     s = (int8*)_sfx_sound + _sfx_pos;
  1059.     fp_pos = _sfx_fp_pos;
  1060.     fp_speed = _sfx_fp_speed;
  1061.  
  1062.     do {
  1063.         fp_pos += fp_speed;
  1064.         *data++ += (*s<<6);
  1065.         s += fp_pos >> 16;
  1066.         fp_pos &= 0x0000FFFF;
  1067.     } while (--len);
  1068.  
  1069.     _sfx_pos = s - (int8*)_sfx_sound;
  1070.     _sfx_fp_speed = fp_speed;
  1071.     _sfx_fp_pos = fp_pos;
  1072.  
  1073.     if (!_sfx_size)
  1074.         clear();*/
  1075. }
  1076.  
  1077. /*void MixerChannel::mix(int16 *data, uint32 len) {
  1078.     int8 *s;
  1079.     int i;
  1080.     uint32 fp_pos, fp_speed;
  1081.  
  1082.     if (!_sfx_sound)
  1083.         return;
  1084.     if (len > _sfx_size)
  1085.         len = _sfx_size;
  1086.     _sfx_size -= len;
  1087.  
  1088.     s = (int8*)_sfx_sound + _sfx_pos;
  1089.     fp_pos = _sfx_fp_pos;
  1090.     fp_speed = _sfx_fp_speed;
  1091.  
  1092.     do {
  1093.         fp_pos += fp_speed;
  1094.         *data++ += (*s<<6);
  1095.         s += fp_pos >> 16;
  1096.         fp_pos &= 0x0000FFFF;
  1097.     } while (--len);
  1098.  
  1099.     _sfx_pos = s - (int8*)_sfx_sound;
  1100.     _sfx_fp_speed = fp_speed;
  1101.     _sfx_fp_pos = fp_pos;
  1102.  
  1103.     if (!_sfx_size)
  1104.         clear();
  1105. }*/
  1106.  
  1107. void MixerChannel::clear() {
  1108. printf("MixerChannel::clear()\n");
  1109. /*      free(_sfx_sound);
  1110.     _sfx_sound = NULL;
  1111.   */
  1112. }
  1113.  
  1114. /*void MixerChannel::clear() {
  1115.     free(_sfx_sound);
  1116.     _sfx_sound = NULL;
  1117. }*/
  1118.  
  1119. void fill_sound(void *userdata, Uint8 *stream, int len) {
  1120. printf("fill_sound()\n");
  1121. /*      int i;
  1122.  
  1123. #if defined(USE_IMUSE)
  1124.     sound.generate_samples((int16*)stream, len>>1);
  1125. #else
  1126.     memset(stream, 0, len);
  1127. #endif
  1128.     
  1129.     for(i=NUM_MIXER-1; i>=0;i--) {
  1130.         mixer_channel[i].mix((int16*)stream, len>>1);
  1131.     } */
  1132. }
  1133.  
  1134. /*void fill_sound(void *userdata, Uint8 *stream, int len) {
  1135.     int i;
  1136.  
  1137. #if defined(USE_IMUSE)
  1138.     sound.generate_samples((int16*)stream, len>>1);
  1139. #else
  1140.     memset(stream, 0, len);
  1141. #endif
  1142.  
  1143.     for(i=NUM_MIXER-1; i>=0;i--) {
  1144.         mixer_channel[i].mix((int16*)stream, len>>1);
  1145.     }
  1146. }*/
  1147.  
  1148. void initGraphics(Scumm *s, bool fullScreen) {
  1149.  
  1150.     printf("ScummAGA v0.2 (based on ScummVM 0.3 alpha)\n");
  1151.  
  1152.     struct ScreenModeRequester *ScreenRequest;
  1153.  
  1154.     if (ScreenRequest=(struct ScreenModeRequester *)AllocAslRequestTags(
  1155.                                  ASL_ScreenModeRequest,
  1156.                                  ASLSM_TitleText, (ULONG) "Pick 320x200 Screenmode ",
  1157.                                  ASLSM_PositiveText, (ULONG) "Ok",
  1158.                                  ASLSM_NegativeText, (ULONG) "Cancel",
  1159.                                  //ASLSM_InitialInfoOpened, TRUE,
  1160.                                  ASLSM_MinWidth, 320,
  1161.                                  ASLSM_MinHeight, 200,
  1162.                                  ASLSM_MinDepth, 8,
  1163.                                  ASLSM_MaxDepth, 8,
  1164.                                  TAG_DONE))
  1165.     {
  1166.     if (!AslRequestTags(ScreenRequest,    ASLSM_TitleText, (ULONG) "Pick 8Bit 320x200 Screenmode ",
  1167.                                  ASLSM_PositiveText, (ULONG) "Ok",
  1168.                                  ASLSM_NegativeText, (ULONG) "Cancel",
  1169.                                  //ASLSM_InitialInfoOpened, TRUE,
  1170.                                  ASLSM_MinWidth, 320,
  1171.                                  ASLSM_MinHeight, 200,
  1172.                                  ASLSM_MinDepth, 8,
  1173.                                  ASLSM_MaxDepth, 8,
  1174.                                  TAG_DONE))
  1175.         {
  1176.         printf("Error: Invalid ScreenMode\n");
  1177.         exit(-1);
  1178.         }
  1179.     }
  1180.     printf("Allocating Chunky Buffer...\n");
  1181.     screen=(char *)malloc(64000);
  1182.  
  1183.     printf("Opening Screen...\n");
  1184.     scr = OpenScreenTags(NULL, SA_Depth,8,
  1185.                              SA_DisplayID,ScreenRequest->sm_DisplayID, //593920,
  1186.                              SA_Type,CUSTOMSCREEN,
  1187.                              TAG_END);
  1188.   if (scr)
  1189.   {
  1190.         win = OpenWindowTags(NULL,
  1191.                              WA_Flags, WFLG_BORDERLESS|WFLG_ACTIVATE|WFLG_RMBTRAP|WFLG_REPORTMOUSE,
  1192.                              WA_IDCMP, IDCMP_RAWKEY|IDCMP_VANILLAKEY|IDCMP_MOUSEMOVE|IDCMP_MOUSEBUTTONS|IDCMP_ACTIVEWINDOW|IDCMP_INACTIVEWINDOW,
  1193.                              WA_CustomScreen, (int)scr,
  1194.                              //WA_Width,320,
  1195.                              //WA_Height,200,
  1196.                              TAG_END);
  1197.   if (win)
  1198.   {
  1199.     // Small Tip to Remove Intuition mouse pointer
  1200.     if (BLANKPointer=(UWORD *)AllocVec(100,MEMF_CHIP|MEMF_CLEAR))
  1201.     {
  1202.        SetPointer(win,BLANKPointer,0,0,0,0);
  1203.        SetMouseQueue(win, 5);
  1204.        ReportMouse(true, win);
  1205.     }
  1206.  
  1207.   }
  1208. }
  1209.     /* Clean up on exit */
  1210.     // Problems with this function with my GCC Setup...
  1211.      //atexit(SDL_Quit);
  1212.  
  1213.     char buf[512], *gameName;
  1214.  
  1215.     sprintf(buf, "ScummVM - %s", gameName = s->getGameName());
  1216.     free(gameName);
  1217.  
  1218.     /*desired.freq = SAMPLES_PER_SEC;
  1219.     desired.format = AUDIO_S16SYS;
  1220.     desired.channels = 1;
  1221.     desired.samples = 2048;
  1222.     desired.callback = fill_sound;
  1223.     SDL_OpenAudio(&desired, NULL);
  1224.     SDL_PauseAudio(0);
  1225.     */
  1226.  
  1227.     /*SDL_WM_SetCaption(buf,buf);
  1228.     SDL_ShowCursor(SDL_DISABLE);
  1229.     */
  1230.  
  1231. /*#if !defined(SCALEUP_2x2)
  1232.     screen = SDL_SetVideoMode(320, 200, 8, fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN) : SDL_SWSURFACE);
  1233. #else
  1234.     screen = SDL_SetVideoMode(640, 400, 8, fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN) : SDL_SWSURFACE);
  1235. #endif
  1236. */
  1237.     printf("%d %d, %d %d, %d %d %d, %d %d %d %d %d\n",
  1238.         sizeof(int8), sizeof(uint8),
  1239.         sizeof(int16), sizeof(uint16),
  1240.         sizeof(int32), sizeof(uint32),
  1241.         sizeof(void*),
  1242.         sizeof(Box), sizeof(MouseCursor),sizeof(CodeHeader),
  1243.         sizeof(ImageHeader),
  1244.         sizeof(Scumm)
  1245.     );
  1246.    //Delay(200);
  1247. }
  1248.  
  1249. /*void initGraphics(Scumm *s, bool fullScreen) {
  1250.     SDL_AudioSpec desired;
  1251.  
  1252.     if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)==-1) {
  1253.         error("Could not initialize SDL: %s.\n", SDL_GetError());
  1254.         exit(1);
  1255.     }
  1256.  
  1257.      atexit(SDL_Quit);
  1258.  
  1259.     char buf[512], *gameName;
  1260.     
  1261.     sprintf(buf, "ScummVM - %s", gameName = s->getGameName());
  1262.     free(gameName);
  1263.  
  1264.     desired.freq = SAMPLES_PER_SEC;
  1265.     desired.format = AUDIO_S16SYS;
  1266.     desired.channels = 1;
  1267.     desired.samples = 2048;
  1268.     desired.callback = fill_sound;
  1269.     SDL_OpenAudio(&desired, NULL);
  1270.     SDL_PauseAudio(0);
  1271.  
  1272.  
  1273.     SDL_WM_SetCaption(buf,buf);
  1274.     SDL_ShowCursor(SDL_DISABLE);
  1275.  
  1276. #if !defined(SCALEUP_2x2)
  1277.     screen = SDL_SetVideoMode(320, 200, 8, fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN) : SDL_SWSURFACE);
  1278. #else
  1279.     screen = SDL_SetVideoMode(640, 400, 8, fullScreen ? (SDL_SWSURFACE | SDL_FULLSCREEN) : SDL_SWSURFACE);
  1280. #endif
  1281.  
  1282.     printf("%d %d, %d %d, %d %d %d, %d %d %d %d %d\n", 
  1283.         sizeof(int8), sizeof(uint8),
  1284.         sizeof(int16), sizeof(uint16),
  1285.         sizeof(int32), sizeof(uint32),
  1286.         sizeof(void*),
  1287.         sizeof(Box), sizeof(MouseCursor),sizeof(CodeHeader),
  1288.         sizeof(ImageHeader),
  1289.         sizeof(Scumm)
  1290.     );
  1291. }
  1292. */
  1293. #undef main
  1294. int main(int argc, char* argv[]) {
  1295.     int delta,tmp;
  1296.     ULONG keypressed;
  1297. /*#if defined(USE_IMUSE)
  1298.     sound.initialize(NULL);
  1299.     scumm._soundDriver = &sound;
  1300. #endif*/
  1301.     // FASTMODE !!
  1302.     scumm._fastMode=true;
  1303.  
  1304.     scumm._gui = &gui;
  1305.     scumm.scummMain(argc, argv);
  1306.  
  1307.     gui.init(&scumm);
  1308.  
  1309.     delta = 0;
  1310.     do {
  1311.         updateScreen(&scumm);
  1312.  
  1313.         if (gui._active) {
  1314.             printf("Appel GUI...\n");
  1315.             gui.loop();
  1316.             tmp = 5;
  1317.         } else {
  1318.             tmp = delta = scumm.scummLoop(delta);
  1319.             tmp += tmp>>1;
  1320.             
  1321.             if (scumm._fastMode)
  1322.                 tmp=1;
  1323.         }
  1324.         
  1325.         while(tmp>0) {
  1326.             waitForTimer(&scumm);
  1327.             tmp--;
  1328.         }
  1329.  
  1330.         keypressed=GetKey();
  1331.  
  1332.     } while(keypressed!=ESC); // While(1);
  1333.  
  1334.     printf("Fin Main() de sdl.cpp\n");
  1335.     printf("Freeing ressources...\n");
  1336.     FreeVec(BLANKPointer);
  1337.     free(screen);
  1338.     CloseWindow(win);
  1339.     CloseScreen(scr);
  1340.  
  1341.  
  1342.     /*
  1343.     tt=GetKey();
  1344.     switch (tt)
  1345.     {
  1346.        case ESC:
  1347.         printf("Esc pressed...\n");
  1348.         break;
  1349.     }
  1350.     */
  1351.     return 0;
  1352. }
  1353.  
  1354.