home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Emulation / Atari800 / atari_svgalib.c < prev    next >
C/C++ Source or Header  |  1998-02-05  |  19KB  |  1,001 lines

  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <fcntl.h>
  4.  
  5. #include <vga.h>
  6. #include <vgagl.h>
  7.  
  8. static char *rcsid = "$Id: atari_svgalib.c,v 1.9 1997/04/13 21:21:51 david Exp $";
  9.  
  10. #include "config.h"
  11. #include "atari.h"
  12. #include "colours.h"
  13. #include "monitor.h"
  14. #include "nas.h"
  15. #include "platform.h"
  16.  
  17. #ifdef JOYMOUSE
  18. #include <vgamouse.h>
  19.  
  20. #define CENTER_X 16384
  21. #define CENTER_Y 16384
  22. #define THRESHOLD 15
  23. #endif
  24.  
  25. #ifdef LINUX_JOYSTICK
  26. #include <linux/joystick.h>
  27.  
  28. static int js0;
  29. static int js1;
  30.  
  31. static int js0_centre_x;
  32. static int js0_centre_y;
  33. static int js1_centre_x;
  34. static int js1_centre_y;
  35.  
  36. static struct JS_DATA_TYPE js_data;
  37. #endif
  38.  
  39. static int    lookup[256];
  40.  
  41. #define FALSE 0
  42. #define TRUE 1
  43.  
  44. static int vgamouse_stick;
  45. static int vgamouse_strig;
  46. static int trig0;
  47. static int stick0;
  48. static int consol;
  49.  
  50. extern double deltatime;
  51.  
  52. /*
  53.    Interlace variables
  54. */
  55.  
  56. static int first_lno = 24;
  57. static int ypos_inc = 1;
  58. static int svga_ptr_inc = 320;
  59. static int scrn_ptr_inc = ATARI_MODULO;
  60.  
  61. void Atari_Initialise (int *argc, char *argv[])
  62. {
  63.   int    VGAMODE = G320x200x256;
  64.  
  65.   int fd;
  66.   int status;
  67.  
  68.   int i;
  69.   int j;
  70.  
  71. #ifdef NAS
  72.   NAS_Initialise (argc, argv);
  73. #endif
  74.  
  75. #ifdef VOXWARE
  76.   Voxware_Initialise (argc, argv);
  77. #endif
  78.  
  79.   for (i=j=1;i<*argc;i++)
  80.     {
  81.       if (strcmp(argv[i],"-interlace") == 0)
  82.     {
  83.       ypos_inc = 2;
  84.       svga_ptr_inc = 320 + 320;
  85.       scrn_ptr_inc = ATARI_WIDTH + ATARI_WIDTH;
  86.     }
  87.       else
  88.     {
  89.       if (strcmp(argv[i],"-help") == 0)
  90.         {
  91.           printf ("\t-interlace    Generate screen with interlace\n");
  92.         }
  93.  
  94.       argv[j++] = argv[i];
  95.     }
  96.     }
  97.  
  98.   *argc = j;
  99.  
  100. #ifdef JOYMOUSE
  101.   if (mouse_init("/dev/mouse", MOUSE_PS2, MOUSE_DEFAULTSAMPLERATE) == -1)
  102.     {
  103.       perror ("/dev/mouse");
  104.       exit (1);
  105.     }
  106.  
  107.   mouse_setposition (CENTER_X, CENTER_Y);
  108. #endif
  109.  
  110. #ifdef LINUX_JOYSTICK
  111.   js0 = open ("/dev/js0", O_RDONLY, 0777);
  112.   if (js0 != -1)
  113.     {
  114.       int status;
  115.  
  116.       status = read (js0, &js_data, JS_RETURN);
  117.       if (status != JS_RETURN)
  118.     {
  119.       perror ("/dev/js0");
  120.       exit (1);
  121.     }
  122.  
  123.       js0_centre_x = js_data.x;
  124.       js0_centre_y = js_data.y;
  125.     }
  126.  
  127.   js1 = open ("/dev/js1", O_RDONLY, 0777);
  128.   if (js1 != -1)
  129.     {
  130.       int status;
  131.  
  132.       status = read (js1, &js_data, JS_RETURN);
  133.       if (status != JS_RETURN)
  134.     {
  135.       perror ("/dev/js1");
  136.       exit (1);
  137.     }
  138.  
  139.       js1_centre_x = js_data.x;
  140.       js1_centre_y = js_data.y;
  141.     }
  142. #endif
  143.  
  144.   vga_init ();
  145.  
  146.   if (!vga_hasmode(VGAMODE))
  147.     {
  148.       printf ("Mode not available\n");
  149.       exit (1);
  150.     }
  151.  
  152.   vga_setmode (VGAMODE);
  153.  
  154.   gl_setcontextvga (VGAMODE);
  155.  
  156.   for (i=0;i<256;i++)
  157.     {
  158.       int    rgb = colortable[i];
  159.       int    red;
  160.       int    green;
  161.       int    blue;
  162.  
  163.       red = (rgb & 0x00ff0000) >> 18;
  164.       green = (rgb & 0x0000ff00) >> 10;
  165.       blue = (rgb & 0x000000ff) >> 2;
  166.  
  167.       gl_setpalettecolor (i, red, green, blue);
  168.     }
  169.  
  170.   trig0 = 1;
  171.   stick0 = 15;
  172.   consol = 7;
  173. }
  174.  
  175. int Atari_Exit (int run_monitor)
  176. {
  177.   int restart;
  178.  
  179.   vga_setmode (TEXT);
  180.  
  181.   if (run_monitor)
  182.     restart = monitor ();
  183.   else
  184.     restart = FALSE;
  185.  
  186.   if (restart)
  187.     {
  188.       int VGAMODE = G320x200x256;
  189.       int status;
  190.       int i;
  191.  
  192.       if (!vga_hasmode(VGAMODE))
  193.     {
  194.       printf ("Mode not available\n");
  195.       exit (1);
  196.     }
  197.  
  198.       vga_setmode (VGAMODE);
  199.  
  200.       gl_setcontextvga (VGAMODE);
  201.  
  202.       for (i=0;i<256;i++)
  203.     {
  204.       int    rgb = colortable[i];
  205.       int    red;
  206.       int    green;
  207.       int    blue;
  208.  
  209.       red = (rgb & 0x00ff0000) >> 18;
  210.       green = (rgb & 0x0000ff00) >> 10;
  211.       blue = (rgb & 0x000000ff) >> 2;
  212.  
  213.       gl_setpalettecolor (i, red, green, blue);
  214.     }
  215.     }
  216.   else
  217.     {
  218. #ifdef JOYMOUSE
  219.       mouse_close();
  220. #endif
  221.  
  222. #ifdef LINUX_JOYSTICK
  223.       if (js0 != -1)
  224.     close (js0);
  225.  
  226.       if (js1 != -1)
  227.     close (js1);
  228. #endif
  229.  
  230. #ifdef NAS
  231.       NAS_Exit ();
  232. #endif
  233.  
  234. #ifdef VOXWARE
  235.       Voxware_Exit ();
  236. #endif
  237.     }
  238.  
  239.   return restart;
  240. }
  241.  
  242. void Atari_DisplayScreen (UBYTE *screen)
  243. {
  244.   static int lace = 0;
  245.  
  246.   UBYTE *svga_ptr;
  247.   UBYTE *scrn_ptr;
  248.   int ypos;
  249.  
  250. /*
  251.  * This single command will replace all this function but doesn't allow
  252.  * the interlace option - maybe the interlace option should dropped.
  253.  *
  254.  * gl_putboxpart (0, 0, 320, 200, 384, 240, screen, 32, first_lno);
  255.  */
  256.  
  257.   svga_ptr = graph_mem;
  258.   scrn_ptr = &screen[first_lno*ATARI_WIDTH+32];
  259.  
  260.   if (ypos_inc == 2)
  261.     {
  262.       if (lace)
  263.     {
  264.       svga_ptr += 320;
  265.       scrn_ptr += ATARI_WIDTH;
  266.     }
  267.  
  268.       lace = 1 - lace;
  269.     }
  270.  
  271.   for (ypos=0;ypos<200;ypos+=ypos_inc)
  272.     {
  273.       memcpy (svga_ptr, scrn_ptr, 320);
  274.       svga_ptr += svga_ptr_inc;
  275.       scrn_ptr += scrn_ptr_inc;
  276.     }
  277.  
  278. #ifdef JOYMOUSE
  279.   vgamouse_stick = 0xff;
  280.  
  281.   if (mouse_update() != 0)
  282.     {
  283.       int x;
  284.       int y;
  285.  
  286.       x = mouse_getx();
  287.       y = mouse_gety();
  288.  
  289.       if (x < (CENTER_X - THRESHOLD))
  290.         vgamouse_stick &= 0xfb;
  291.       else if (x > (CENTER_X + THRESHOLD))
  292.         vgamouse_stick &= 0xf7;
  293.           
  294.       if (y < (CENTER_Y - THRESHOLD))
  295.         vgamouse_stick &= 0xfe;
  296.       else if (y > (CENTER_Y + THRESHOLD))
  297.         vgamouse_stick &= 0xfd;
  298.           
  299.       mouse_setposition(CENTER_X, CENTER_Y);
  300.     }
  301.  
  302.   if (mouse_getbutton())
  303.     vgamouse_strig = 0;
  304.   else
  305.     vgamouse_strig = 1;
  306. #endif
  307.  
  308. #ifdef NAS
  309.   NAS_UpdateSound ();
  310. #endif
  311.  
  312. #ifdef VOXWARE
  313.   Voxware_UpdateSound ();
  314. #endif
  315.  
  316.   consol = 7;
  317. }
  318.  
  319. static int special_keycode = -1;
  320.  
  321. int Atari_Keyboard (void)
  322. {
  323.   int    keycode;
  324.  
  325.   trig0 = 1;
  326.  
  327.   if (special_keycode != -1)
  328.     {
  329.       keycode = special_keycode;
  330.       special_keycode = -1;
  331.     }
  332.   else
  333.     keycode = vga_getkey();
  334.  
  335.   switch (keycode)
  336.     {
  337.     case 0x01 :
  338.       keycode = AKEY_CTRL_a;
  339.       break;
  340.     case 0x02 :
  341.       keycode = AKEY_CTRL_b;
  342.       break;
  343. /*
  344.    case 0x03 :
  345.    keycode = AKEY_CTRL_c;
  346.    break;
  347. */
  348.     case 0x04 :
  349.       keycode = AKEY_CTRL_d;
  350.       break;
  351.     case 0x05 :
  352.       keycode = AKEY_CTRL_e;
  353.       break;
  354.     case 0x06 :
  355.       keycode = AKEY_CTRL_f;
  356.       break;
  357.     case 0x07 :
  358.       keycode = AKEY_CTRL_g;
  359.       break;
  360.     case 0x08 :
  361.       keycode = AKEY_CTRL_h;
  362.       break;
  363.     case 0x09 :
  364.       keycode = AKEY_CTRL_i;
  365.       break;
  366. /*
  367.    case 0x0a :
  368.    keycode = AKEY_CTRL_j;
  369.    break;
  370. */
  371.     case 0x0b :
  372.       keycode = AKEY_CTRL_k;
  373.       break;
  374.     case 0x0c :
  375.       keycode = AKEY_CTRL_l;
  376.       break;
  377. /*
  378.    case 0x0d :
  379.    keycode = AKEY_CTRL_m;
  380.    break;
  381. */
  382.     case 0x0e :
  383.       keycode = AKEY_CTRL_n;
  384.       break;
  385.     case 0x0f :
  386.       keycode = AKEY_CTRL_o;
  387.       break;
  388.     case 0x10 :
  389.       keycode = AKEY_CTRL_p;
  390.       break;
  391.     case 0x11 :
  392.       keycode = AKEY_CTRL_q;
  393.       break;
  394.     case 0x12 :
  395.       keycode = AKEY_CTRL_r;
  396.       break;
  397.     case 0x13 :
  398.       keycode = AKEY_CTRL_s;
  399.       break;
  400.     case 0x14 :
  401.       keycode = AKEY_CTRL_t;
  402.       break;
  403.     case 0x15 :
  404.       keycode = AKEY_CTRL_u;
  405.       break;
  406.     case 0x16 :
  407.       keycode = AKEY_CTRL_v;
  408.       break;
  409.     case 0x17 :
  410.       keycode = AKEY_CTRL_w;
  411.       break;
  412.     case 0x18 :
  413.       keycode = AKEY_CTRL_x;
  414.       break;
  415.     case 0x19 :
  416.       keycode = AKEY_CTRL_y;
  417.       break;
  418.     case 0x1a :
  419.       keycode = AKEY_CTRL_z;
  420.       break;
  421.     case ' ' :
  422.       keycode = AKEY_SPACE;
  423.       break;
  424.     case '`' :
  425.       keycode = AKEY_CAPSTOGGLE;
  426.       break;
  427.     case '~' :
  428.       keycode = AKEY_CAPSLOCK;
  429.       break;
  430.     case '!' :
  431.       keycode = AKEY_EXCLAMATION;
  432.       break;
  433.     case '"' :
  434.       keycode = AKEY_DBLQUOTE;
  435.       break;
  436.     case '#' :
  437.       keycode = AKEY_HASH;
  438.       break;
  439.     case '$' :
  440.       keycode = AKEY_DOLLAR;
  441.       break;
  442.     case '%' :
  443.       keycode = AKEY_PERCENT;
  444.       break;
  445.     case '&' :
  446.       keycode = AKEY_AMPERSAND;
  447.       break;
  448.     case '\'' :
  449.       keycode = AKEY_QUOTE;
  450.       break;
  451.     case '@' :
  452.       keycode = AKEY_AT;
  453.       break;
  454.     case '(' :
  455.       keycode = AKEY_PARENLEFT;
  456.       break;
  457.     case ')' :
  458.       keycode = AKEY_PARENRIGHT;
  459.       break;
  460.     case '[' :
  461.       keycode = AKEY_BRACKETLEFT;
  462.       break;
  463.     case ']' :
  464.       keycode = AKEY_BRACKETRIGHT;
  465.       break;
  466.     case '<' :
  467.       keycode = AKEY_LESS;
  468.       break;
  469.     case '>' :
  470.       keycode = AKEY_GREATER;
  471.       break;
  472.     case '=' :
  473.       keycode = AKEY_EQUAL;
  474.       break;
  475.     case '?' :
  476.       keycode = AKEY_QUESTION;
  477.       break;
  478.     case '-' :
  479.       keycode = AKEY_MINUS;
  480.       break;
  481.     case '+' :
  482.       keycode = AKEY_PLUS;
  483.       break;
  484.     case '*' :
  485.       keycode = AKEY_ASTERISK;
  486.       break;
  487.     case '/' :
  488.       keycode = AKEY_SLASH;
  489.       break;
  490.     case ':' :
  491.       keycode = AKEY_COLON;
  492.       break;
  493.     case ';' :
  494.       keycode = AKEY_SEMICOLON;
  495.       break;
  496.     case ',' :
  497.       keycode = AKEY_COMMA;
  498.       break;
  499.     case '.' :
  500.       keycode = AKEY_FULLSTOP;
  501.       break;
  502.     case '_' :
  503.       keycode = AKEY_UNDERSCORE;
  504.       break;
  505.     case '{' :
  506.       keycode = AKEY_NONE;
  507.       break;
  508.     case '}' :
  509.       keycode = AKEY_NONE;
  510.       break;
  511.     case '^' :
  512.       keycode = AKEY_CIRCUMFLEX;
  513.       break;
  514.     case '\\' :
  515.       keycode = AKEY_BACKSLASH;
  516.       break;
  517.     case '|' :
  518.       keycode = AKEY_BAR;
  519.       break;
  520.     case '0' :
  521.       keycode = AKEY_0;
  522.       break;
  523.     case '1' :
  524.       keycode = AKEY_1;
  525.       break;
  526.     case '2' :
  527.       keycode = AKEY_2;
  528.       break;
  529.     case '3' :
  530.       keycode = AKEY_3;
  531.       break;
  532.     case '4' :
  533.       keycode = AKEY_4;
  534.       break;
  535.     case '5' :
  536.       keycode = AKEY_5;
  537.       break;
  538.     case '6' :
  539.       keycode = AKEY_6;
  540.       break;
  541.     case '7' :
  542.       keycode = AKEY_7;
  543.       break;
  544.     case '8' :
  545.       keycode = AKEY_8;
  546.       break;
  547.     case '9' :
  548.       keycode = AKEY_9;
  549.       break;
  550.     case 'a' :
  551.       keycode = AKEY_a;
  552.       break;
  553.     case 'b' :
  554.       keycode = AKEY_b;
  555.       break;
  556.     case 'c' :
  557.       keycode = AKEY_c;
  558.       break;
  559.     case 'd' :
  560.       keycode = AKEY_d;
  561.       break;
  562.     case 'e' :
  563.       keycode = AKEY_e;
  564.       break;
  565.     case 'f' :
  566.       keycode = AKEY_f;
  567.       break;
  568.     case 'g' :
  569.       keycode = AKEY_g;
  570.       break;
  571.     case 'h' :
  572.       keycode = AKEY_h;
  573.       break;
  574.     case 'i' :
  575.       keycode = AKEY_i;
  576.       break;
  577.     case 'j' :
  578.       keycode = AKEY_j;
  579.       break;
  580.     case 'k' :
  581.       keycode = AKEY_k;
  582.       break;
  583.     case 'l' :
  584.       keycode = AKEY_l;
  585.       break;
  586.     case 'm' :
  587.       keycode = AKEY_m;
  588.       break;
  589.     case 'n' :
  590.       keycode = AKEY_n;
  591.       break;
  592.     case 'o' :
  593.       keycode = AKEY_o;
  594.       break;
  595.     case 'p' :
  596.       keycode = AKEY_p;
  597.       break;
  598.     case 'q' :
  599.       keycode = AKEY_q;
  600.       break;
  601.     case 'r' :
  602.       keycode = AKEY_r;
  603.       break;
  604.     case 's' :
  605.       keycode = AKEY_s;
  606.       break;
  607.     case 't' :
  608.       keycode = AKEY_t;
  609.       break;
  610.     case 'u' :
  611.       keycode = AKEY_u;
  612.       break;
  613.     case 'v' :
  614.       keycode = AKEY_v;
  615.       break;
  616.     case 'w' :
  617.       keycode = AKEY_w;
  618.       break;
  619.     case 'x' :
  620.       keycode = AKEY_x;
  621.       break;
  622.     case 'y' :
  623.       keycode = AKEY_y;
  624.       break;
  625.     case 'z' :
  626.       keycode = AKEY_z;
  627.       break;
  628.     case 'A' :
  629.       keycode = AKEY_A;
  630.       break;
  631.     case 'B' :
  632.       keycode = AKEY_B;
  633.       break;
  634.     case 'C' :
  635.       keycode = AKEY_C;
  636.       break;
  637.     case 'D' :
  638.       keycode = AKEY_D;
  639.       break;
  640.     case 'E' :
  641.       keycode = AKEY_E;
  642.       break;
  643.     case 'F' :
  644.       keycode = AKEY_F;
  645.       break;
  646.     case 'G' :
  647.       keycode = AKEY_G;
  648.       break;
  649.     case 'H' :
  650.       keycode = AKEY_H;
  651.       break;
  652.     case 'I' :
  653.       keycode = AKEY_I;
  654.       break;
  655.     case 'J' :
  656.       keycode = AKEY_J;
  657.       break;
  658.     case 'K' :
  659.       keycode = AKEY_K;
  660.       break;
  661.     case 'L' :
  662.       keycode = AKEY_L;
  663.       break;
  664.     case 'M' :
  665.       keycode = AKEY_M;
  666.       break;
  667.     case 'N' :
  668.       keycode = AKEY_N;
  669.       break;
  670.     case 'O' :
  671.       keycode = AKEY_O;
  672.       break;
  673.     case 'P' :
  674.       keycode = AKEY_P;
  675.       break;
  676.     case 'Q' :
  677.       keycode = AKEY_Q;
  678.       break;
  679.     case 'R' :
  680.       keycode = AKEY_R;
  681.       break;
  682.     case 'S' :
  683.       keycode = AKEY_S;
  684.       break;
  685.     case 'T' :
  686.       keycode = AKEY_T;
  687.       break;
  688.     case 'U' :
  689.       keycode = AKEY_U;
  690.       break;
  691.     case 'V' :
  692.       keycode = AKEY_V;
  693.       break;
  694.     case 'W' :
  695.       keycode = AKEY_W;
  696.       break;
  697.     case 'X' :
  698.       keycode = AKEY_X;
  699.       break;
  700.     case 'Y' :
  701.       keycode = AKEY_Y;
  702.       break;
  703.     case 'Z' :
  704.       keycode = AKEY_Z;
  705.       break;
  706.     case 0x7f :    /* Backspace */
  707.       keycode = AKEY_BACKSPACE;
  708.       break;
  709.     case '\n' :
  710.       keycode = AKEY_RETURN;
  711.       break;
  712.     case 0x1b :
  713.       {
  714.     char    buff[10];
  715.     int    nc;
  716.     
  717.     nc = 0;
  718.     while (((keycode = vga_getkey()) != 0) && (nc < 8))
  719.       buff[nc++] = keycode;
  720.     buff[nc++] = '\0';
  721.  
  722.     if (nc == 1)
  723.       {
  724.         keycode = AKEY_ESCAPE;
  725.       }
  726.     else if (strcmp(buff, "\133\133\101") == 0)    /* F1 */
  727.           keycode = AKEY_UI;
  728.     else if (strcmp(buff, "\133\133\102") == 0)    /* F2 */
  729.       {
  730.         consol &= 0x03;
  731.         keycode = AKEY_NONE;
  732.       }
  733.     else if (strcmp(buff, "\133\133\103") == 0)    /* F3 */
  734.       {
  735.         consol &= 0x05;
  736.         keycode = AKEY_NONE;
  737.       }
  738.     else if (strcmp(buff, "\133\133\104") == 0)    /* F4 */
  739.       {
  740.         consol &= 0x06;
  741.         keycode = AKEY_NONE;
  742.       }
  743.         else if (strcmp(buff, "[28~") == 0) /* Shift F5 */
  744.           keycode = AKEY_COLDSTART;
  745.     else if (strcmp(buff, "\133\133\105") == 0)    /* F5 */
  746.           keycode = AKEY_WARMSTART;
  747.     else if (strcmp(buff, "\133\061\067\176") == 0)    /* F6 */
  748.       {
  749.         keycode = AKEY_PIL;
  750.       }
  751.     else if (strcmp(buff, "\133\061\070\176") == 0)    /* F7 */
  752.       {
  753.         keycode = AKEY_BREAK;
  754.       }
  755.     else if (strcmp(buff, "\133\061\071\176") == 0)    /* F8 */
  756.       {
  757.         keycode = AKEY_NONE;
  758.       }
  759.     else if (strcmp(buff, "\133\062\060\176") == 0)    /* F9 */
  760.       {
  761.         keycode = AKEY_EXIT;
  762.       }
  763.     else if (strcmp(buff, "\133\062\061\176") == 0)    /* F10 */
  764.       {
  765.         keycode = AKEY_NONE;
  766.         if (deltatime == 0.0)
  767.           deltatime = (1.0 / 8.0);
  768.         else
  769.           deltatime = 0.0;
  770.       }
  771.     else if (strcmp(buff, "\133\062\063\176") == 0)    /* F11 */
  772.       {
  773.         if (first_lno > 0)
  774.           first_lno--;
  775.         keycode = AKEY_NONE;
  776.       }
  777.     else if (strcmp(buff, "\133\062\064\176") == 0)    /* F12 */
  778.       {
  779.         if (first_lno < (ATARI_HEIGHT - 200))
  780.           first_lno++;
  781.         keycode = AKEY_NONE;
  782.       }
  783.     else if (strcmp(buff, "\141\000") == 0)
  784.       keycode = AKEY_CTRL_A;
  785.     else if (strcmp(buff, "\142\000") == 0)
  786.       keycode = AKEY_CTRL_B;
  787.     else if (strcmp(buff, "\143\000") == 0)
  788.       keycode = AKEY_CTRL_C;
  789.     else if (strcmp(buff, "\144\000") == 0)
  790.       keycode = AKEY_CTRL_D;
  791.     else if (strcmp(buff, "\145\000") == 0)
  792.       keycode = AKEY_CTRL_E;
  793.     else if (strcmp(buff, "\146\000") == 0)
  794.       keycode = AKEY_CTRL_F;
  795.     else if (strcmp(buff, "\147\000") == 0)
  796.       keycode = AKEY_CTRL_G;
  797.     else if (strcmp(buff, "\150\000") == 0)
  798.       keycode = AKEY_CTRL_H;
  799.     else if (strcmp(buff, "\151\000") == 0)
  800.       keycode = AKEY_CTRL_I;
  801.     else if (strcmp(buff, "\152\000") == 0)
  802.       keycode = AKEY_CTRL_J;
  803.     else if (strcmp(buff, "\153\000") == 0)
  804.       keycode = AKEY_CTRL_K;
  805.     else if (strcmp(buff, "\154\000") == 0)
  806.       keycode = AKEY_CTRL_L;
  807.     else if (strcmp(buff, "\155\000") == 0)
  808.       keycode = AKEY_CTRL_M;
  809.     else if (strcmp(buff, "\156\000") == 0)
  810.       keycode = AKEY_CTRL_N;
  811.     else if (strcmp(buff, "\157\000") == 0)
  812.       keycode = AKEY_CTRL_O;
  813.     else if (strcmp(buff, "\160\000") == 0)
  814.       keycode = AKEY_CTRL_P;
  815.     else if (strcmp(buff, "\161\000") == 0)
  816.       keycode = AKEY_CTRL_Q;
  817.     else if (strcmp(buff, "\162\000") == 0)
  818.       keycode = AKEY_CTRL_R;
  819.     else if (strcmp(buff, "\163\000") == 0)
  820.       keycode = AKEY_CTRL_S;
  821.     else if (strcmp(buff, "\164\000") == 0)
  822.       keycode = AKEY_CTRL_T;
  823.     else if (strcmp(buff, "\165\000") == 0)
  824.       keycode = AKEY_CTRL_U;
  825.     else if (strcmp(buff, "\166\000") == 0)
  826.       keycode = AKEY_CTRL_V;
  827.     else if (strcmp(buff, "\167\000") == 0)
  828.       keycode = AKEY_CTRL_W;
  829.     else if (strcmp(buff, "\170\000") == 0)
  830.       keycode = AKEY_CTRL_X;
  831.     else if (strcmp(buff, "\171\000") == 0)
  832.       keycode = AKEY_CTRL_Y;
  833.     else if (strcmp(buff, "\172\000") == 0)
  834.       keycode = AKEY_CTRL_Z;
  835.     else if (strcmp(buff, "\133\062\176") == 0)    /* Keypad 0 */
  836.       {
  837.         trig0 = 0;
  838.         keycode = AKEY_NONE;
  839.       }
  840.     else if (strcmp(buff, "\133\064\176") == 0)    /* Keypad 1 */
  841.       {
  842.         stick0 = STICK_LL;
  843.         keycode = AKEY_NONE;
  844.       }
  845.     else if (strcmp(buff, "\133\102") == 0)        /* Keypad 2 */
  846.       {
  847.         stick0 = STICK_BACK;
  848.         keycode = AKEY_DOWN;
  849.       }
  850.     else if (strcmp(buff, "\133\066\176") == 0)    /* Keypad 3 */
  851.       {
  852.         stick0 = STICK_LR;
  853.         keycode = AKEY_NONE;
  854.       }
  855.     else if (strcmp(buff, "\133\104") == 0)        /* Keypad 4 */
  856.       {
  857.         stick0 = STICK_LEFT;
  858.         keycode = AKEY_LEFT;
  859.       }
  860.     else if (strcmp(buff, "\133\107") == 0)        /* Keypad 5 */
  861.       {
  862.         stick0 = STICK_CENTRE;
  863.         keycode = AKEY_NONE;
  864.       }
  865.     else if (strcmp(buff, "\133\103") == 0)        /* Keypad 6 */
  866.       {
  867.         stick0 = STICK_RIGHT;
  868.         keycode = AKEY_RIGHT;
  869.       }
  870.     else if (strcmp(buff, "\133\061\176") == 0)    /* Keypad 7 */
  871.       {
  872.         stick0 = STICK_UL;
  873.         keycode = AKEY_NONE;
  874.       }
  875.     else if (strcmp(buff, "\133\101") == 0)        /* Keypad 8 */
  876.       {
  877.         stick0 = STICK_FORWARD;
  878.         keycode = AKEY_UP;
  879.       }
  880.     else if (strcmp(buff, "\133\065\176") == 0)    /* Keypad 9 */
  881.       {
  882.         stick0 = STICK_UR;
  883.         keycode = AKEY_NONE;
  884.       }
  885.     else
  886.       {
  887.         int    i;
  888.         printf ("Unknown key (%s): 0x1b ", buff);
  889.         for (i=0;i<nc;i++) printf ("0x%02x ", buff[i]);
  890.         printf ("\n");
  891.         keycode = AKEY_NONE;
  892.       }
  893.       }
  894.       break;
  895.     default :
  896.       printf ("Unknown Keycode: %d\n", keycode);
  897.     case 0 :
  898.       keycode = AKEY_NONE;
  899.       break;
  900.     }
  901.   
  902.   return keycode;
  903. }
  904.  
  905. #ifdef LINUX_JOYSTICK
  906. void read_joystick (int js, int centre_x, int centre_y)
  907. {
  908.   const int threshold = 50;
  909.   int status;
  910.  
  911.   stick0 = 0x0f;
  912.  
  913.   status = read (js, &js_data, JS_RETURN);
  914.   if (status != JS_RETURN)
  915.     {
  916.       perror ("/dev/js");
  917.       exit (1);
  918.     }
  919.  
  920.   if (js_data.x < (centre_x - threshold))
  921.     stick0 &= 0xfb;
  922.   if (js_data.x > (centre_x + threshold))
  923.     stick0 &= 0xf7;
  924.   if (js_data.y < (centre_y - threshold))
  925.     stick0 &= 0xfe;
  926.   if (js_data.y > (centre_y + threshold))
  927.     stick0 &= 0xfd;
  928. }
  929. #endif
  930.  
  931. int Atari_PORT (int num)
  932. {
  933.   if (num == 0)
  934.     {
  935. #ifdef JOYMOUSE
  936.       stick0 = vgamouse_stick;
  937. #endif
  938.  
  939. #ifdef LINUX_JOYSTICK
  940.       read_joystick (js0, js0_centre_x, js0_centre_y);
  941. #endif
  942.       return 0xf0 | stick0;
  943.     }
  944.   else
  945.     return 0xff;
  946. }
  947.  
  948. int Atari_TRIG (int num)
  949. {
  950.   if (num == 0)
  951.     {
  952. #ifdef JOYMOUSE
  953.       trig0 = vgamouse_strig;
  954. #endif
  955.  
  956. #ifdef LINUX_JOYSTICK
  957.       int status;
  958.  
  959.       status = read (js0, &js_data, JS_RETURN);
  960.       if (status != JS_RETURN)
  961.     {
  962.       perror ("/dev/js0");
  963.       exit (1);
  964.     }
  965.  
  966.       if (js_data.buttons & 0x01)
  967.     trig0 = 0;
  968.       else
  969.     trig0 = 1;
  970.  
  971.       if (js_data.buttons & 0x02)
  972.     special_keycode = ' ';
  973. /*
  974.       trig0 = (js_data.buttons & 0x0f) ? 0 : 1;
  975. */
  976. #endif
  977.     return trig0;
  978.     }
  979.   else
  980.     return 1;
  981. }
  982.  
  983. int Atari_POT (int num)
  984. {
  985.   return 228;
  986. }
  987.  
  988. int Atari_CONSOL (void)
  989. {
  990.   return consol;
  991. }
  992.  
  993. void Atari_Set_LED(int on)
  994. {
  995. }
  996.  
  997. UBYTE Atari_Keyboard_State(void)
  998. {
  999.     return 0xff;
  1000. }
  1001.