home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / atari / atari800-0.8.6 / atari_svgalib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-10  |  16.1 KB  |  936 lines

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