Annotation of frontvm/src/input.c, revision 1.1

1.1     ! root        1: 
        !             2: #include <SDL_endian.h>
        !             3: #include <SDL_mouse.h>
        !             4: 
        !             5: #include "main.h"
        !             6: #include "input.h"
        !             7: #include "../m68000.h"
        !             8: #include "shortcut.h"
        !             9: #include "screen.h"
        !            10: 
        !            11: INPUT input;
        !            12: 
        !            13: void Call_GetMouseInput ()
        !            14: {
        !            15:        short *mouse_mov, *mouse_abs;
        !            16:        unsigned long params;
        !            17:        
        !            18:        params = GetReg (REG_A7);
        !            19:        params -= SIZE_WORD;
        !            20:        /* Pointer passed to struct:
        !            21:         *   word mouse_motion_x
        !            22:         *   word mouse_motion_y
        !            23:         *   word mouse_buttons
        !            24:         */
        !            25: 
        !            26:        mouse_mov = (short*)(STRam + STMemory_ReadLong (params+SIZE_WORD));
        !            27:        mouse_abs = (short*)(STRam + STMemory_ReadLong (params+SIZE_WORD+SIZE_LONG));
        !            28: 
        !            29:        /* lazy lazy lazy lazy */
        !            30:        if ((abs (input.motion_x) > 100) || (abs (input.motion_y) > 100)) {
        !            31:                        //printf ("That fucking input bug! %d,%d\n", input.motion_x, input.motion_y);
        !            32:                        input.motion_x = input.motion_y = 0;
        !            33:        }
        !            34:        
        !            35:        mouse_mov[0] = SDL_SwapBE16 (SDL_SwapBE16 (mouse_mov[0]) + input.motion_x);
        !            36:        mouse_mov[1] = SDL_SwapBE16 (SDL_SwapBE16 (mouse_mov[1]) + input.motion_y);
        !            37:        
        !            38:        mouse_abs[0] = SDL_SwapBE16 (320*input.abs_x/screen_w);
        !            39:        mouse_abs[1] = SDL_SwapBE16 (200*input.abs_y/screen_h);
        !            40:        
        !            41:        //if (input.mbuf_head != input.mbuf_tail) {
        !            42:        //      mouse_mov[2] = SDL_SwapBE16 (0xf8 | input.mousebut_buf [input.mbuf_head++]);
        !            43:        //      input.mbuf_head %= SIZE_KEYBUF;
        !            44:        //} else {
        !            45:                mouse_mov[2] = SDL_SwapBE16 (0xf8 | input.cur_mousebut_state);
        !            46:        //}
        !            47:        
        !            48:        input.motion_x = input.motion_y = 0;
        !            49: }
        !            50: 
        !            51: void Call_GetKeyboardEvent ()
        !            52: {
        !            53:        if ((input.buf_head) != (input.buf_tail)) {
        !            54:                SetReg (REG_D0, input.key_buf [input.buf_head++]);
        !            55:                input.buf_head %= SIZE_KEYBUF;
        !            56:        } else {
        !            57:                SetReg (REG_D0, 0);
        !            58:        }
        !            59: }
        !            60: 
        !            61: 
        !            62: 
        !            63: 
        !            64: /* Interrupt as required */
        !            65: void Input_Update ()
        !            66: {
        !            67:        if ((input.buf_head != input.buf_tail) ||
        !            68:            (input.motion_x) ||
        !            69:            (input.motion_y) ||
        !            70:            (input.mbuf_head != input.mbuf_tail)) {
        !            71:                //FlagException (1);
        !            72:        }
        !            73: }
        !            74: 
        !            75: void Input_PressSTKey (unsigned char ScanCode, BOOL bPress)
        !            76: {
        !            77:        if (!bPress) ScanCode |= 0x80;
        !            78:        input.key_buf [input.buf_tail++] = ScanCode;
        !            79:        input.buf_tail %= SIZE_KEYBUF;
        !            80: }
        !            81: 
        !            82: static void do_mouse_grab ()
        !            83: {
        !            84:        /* grab mouse on right-button hold for correct controls */
        !            85:        if (input.cur_mousebut_state & 0x1) {
        !            86:                SDL_WM_GrabInput (SDL_GRAB_ON);
        !            87:        } else {
        !            88:                SDL_WM_GrabInput (SDL_GRAB_OFF);
        !            89:        }
        !            90: }
        !            91: 
        !            92: void Input_MousePress (int button)
        !            93: {
        !            94:        if (button == SDL_BUTTON_RIGHT) input.cur_mousebut_state |= 0x1;
        !            95:        else if (button == SDL_BUTTON_LEFT) input.cur_mousebut_state |= 0x2;
        !            96:        else {
        !            97:                return;
        !            98:        }
        !            99:        do_mouse_grab ();
        !           100:        
        !           101:        input.mousebut_buf [input.mbuf_tail++] = input.cur_mousebut_state;
        !           102:        input.mbuf_tail %= SIZE_MOUSEBUF;
        !           103: }
        !           104: 
        !           105: void Input_MouseRelease (int button)
        !           106: {
        !           107:        if (button == SDL_BUTTON_RIGHT) input.cur_mousebut_state &= ~0x1;
        !           108:        else if (button == SDL_BUTTON_LEFT) input.cur_mousebut_state &= ~0x2;
        !           109:        else return;
        !           110:        input.mousebut_buf [input.mbuf_tail++] = input.cur_mousebut_state;
        !           111:        input.mbuf_tail %= SIZE_MOUSEBUF;
        !           112: 
        !           113:        do_mouse_grab ();
        !           114: }
        !           115: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.