Ejemplo n.º 1
0
void init_keyboard(void){
	key_done=0;
	key_debug=0;   
	install_keyboard();		
	new_int=1;
	NeedsPoll = keyboard_needs_poll();
}
Ejemplo n.º 2
0
void TKeyHandler::update()
{
	if (keyboard_needs_poll())
		poll_keyboard();

	// detect key changes ...
	// (note that changes in-between updates are not seen by this so it's not 100% accurate)
	int i;
	for ( i = 0; i < KEY_MAX; ++i ) {
		// keep record of prev and new states
		keyold[i] = keynew[i];
		keynew[i] = key[i];

		// detect changes
		keyhit[i] = 0;
		keyreleased[i] = 0;

		if (keynew[i] != keyold[i]) {
			if (keynew[i])
				keyhit[i] = 1;
			else
				keyreleased[i] = 1;
		}

	}

	Nbuf = Nbackbuf;
	for ( i = 0; i < Nbuf; ++i ) {
		keybuf[i] = keybackbuf[i];
	}
	// reset the back-buffer for reading new stuf.
	Nbackbuf = 0;

}
Ejemplo n.º 3
0
int uip_vgamode(void)
{
  int depth, rate;
  unsigned long screenbase;

  for (rate = 60; rate <= 70; rate += 10) {
    for (depth = 15; depth <= 16; depth++) {
      LOG_VERBOSE(("Trying mode 640x480 depth %d rate %d", depth, rate));
      set_color_depth(depth);
      request_refresh_rate(rate);
      if ((set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 480 * 2) < 0)) {
        LOG_VERBOSE(("Mode not supported"));
        continue;
      }
      if (SCREEN_W != 640 || SCREEN_H != 480) {
        LOG_CRITICAL(("Screen not approriate for depth %d rate %d",
                      depth, rate));
        continue;
      }
      goto WHEE;
    }
  }
  LOG_CRITICAL(("Failed to find suitable mode"));
  return 1;
WHEE:
  uip_vga = 1;
  if (uip_forceredshift != -1 && uip_forcegreenshift != -1 &&
      uip_forceblueshift != -1) {
    uip_uipinfo->redshift = uip_forceredshift;
    uip_uipinfo->greenshift = uip_forcegreenshift;
    uip_uipinfo->blueshift = uip_forceblueshift;
  } else {
    uip_uipinfo->redshift = ui_topbit(makecol(255, 0, 0)) - 4;
    uip_uipinfo->greenshift = ui_topbit(makecol(0, 255, 0)) - 4;
    uip_uipinfo->blueshift = ui_topbit(makecol(0, 0, 255)) - 4;
  }
  if ((uip_bank0 = create_video_bitmap(640, 480)) == NULL ||
      (uip_bank1 = create_video_bitmap(640, 480)) == NULL) {
    uip_textmode();
    LOG_CRITICAL(("Failed to allocate memory pages"));
    return 1;
  }
  if (is_linear_bitmap(uip_bank0) == 0 ||
      is_linear_bitmap(uip_bank1) == 0 ||
      is_video_bitmap(uip_bank0) == 0 || is_video_bitmap(uip_bank1) == 0) {
    uip_textmode();
    LOG_CRITICAL(("Allocated bitmaps not suitable or linear addressing mode "
                  "not supported by hardware"));
    return 1;
  }
  /* don't you just hate MS platforms? */
  __djgpp_nearptr_enable();
  __dpmi_get_segment_base_address(uip_bank0->seg, &screenbase);
  uip_uipinfo->screenmem0 = (uint8 *)(screenbase + uip_bank0->line[0] -
                                      __djgpp_base_address);
  __dpmi_get_segment_base_address(uip_bank1->seg, &screenbase);
  uip_uipinfo->screenmem1 = (uint8 *)(screenbase + uip_bank1->line[0] -
                                      __djgpp_base_address);
  uip_uipinfo->linewidth = 2 * VIRTUAL_W;       /* 16 bit */
  uip_displaybank(0);           /* set current to 0th bank */
  uip_clearscreen();            /* clear bank */
  ui_setupscreen();             /* setup bank */
  uip_displaybank(-1);          /* toggle bank */
  uip_clearscreen();            /* clear bank */
  ui_setupscreen();             /* setup bank */
  if (install_keyboard() == -1) {
    uip_textmode();
    LOG_CRITICAL(("Unable to initialise keyboard"));
    return 1;
  }
  if (uip_bank0->y_ofs != 0 || uip_bank1->y_ofs != 480) {
    uip_textmode();
    LOG_CRITICAL(("sorry, I don't understand this video layout"));
    return 1;
  }
  keyboard_lowlevel_callback = uip_keyboardhandler;
  uip_keypoll = keyboard_needs_poll()? 1 : 0;
  return 0;
}
Ejemplo n.º 4
0
    void OpenLayerInput::pollKeyInput()
    {
        int unicode, scancode;

        if (keyboard_needs_poll())
        {
            poll_keyboard();
        }

        while (keypressed())
        {
            unicode = ureadkey(&scancode);
            Key keyObj = convertToKey(scancode, unicode);

            KeyInput keyInput(keyObj, KeyInput::Pressed);

            keyInput.setNumericPad(isNumericPad(scancode));
            keyInput.setShiftPressed(key_shifts & KB_SHIFT_FLAG);
            keyInput.setAltPressed(key_shifts & KB_ALT_FLAG);
            keyInput.setControlPressed(key_shifts & KB_CTRL_FLAG);
#ifdef KB_COMMAND_FLAG
            keyInput.setMetaPressed(key_shifts & (KB_COMMAND_FLAG |
                                                  KB_LWIN_FLAG |
                                                  KB_RWIN_FLAG));
#else
            keyInput.setMetaPressed(key_shifts & (KB_LWIN_FLAG |
                                                  KB_RWIN_FLAG));
#endif


            mKeyQueue.push(keyInput);

            mPressedKeys[scancode] = keyInput;
        }

        if (key[KEY_ALT] && mPressedKeys.find(KEY_ALT) == mPressedKeys.end())
        {
            KeyInput keyInput(convertToKey(KEY_ALT, 0), KeyInput::Pressed);
            mKeyQueue.push(keyInput);
            mPressedKeys[KEY_ALT] = keyInput;
        }

        if (key[KEY_ALTGR] && mPressedKeys.find(KEY_ALTGR) == mPressedKeys.end())
        {
            KeyInput keyInput(convertToKey(KEY_ALTGR, 0), KeyInput::Pressed);
            mKeyQueue.push(keyInput);
            mPressedKeys[KEY_ALTGR] = keyInput;
        }

        if (key[KEY_LSHIFT] && mPressedKeys.find(KEY_LSHIFT) == mPressedKeys.end())
        {
            KeyInput keyInput(convertToKey(KEY_LSHIFT, 0), KeyInput::Pressed);
            mKeyQueue.push(keyInput);
            mPressedKeys[KEY_LSHIFT] = keyInput;
        }
    
        if (key[KEY_RSHIFT] && mPressedKeys.find(KEY_RSHIFT) == mPressedKeys.end())
        {
            KeyInput keyInput(convertToKey(KEY_RSHIFT, 0), KeyInput::Pressed);
            mKeyQueue.push(keyInput);
            mPressedKeys[KEY_RSHIFT] = keyInput;
        }
		
        if (key[KEY_LCONTROL] && mPressedKeys.find(KEY_LCONTROL) == mPressedKeys.end())
        {
            KeyInput keyInput(convertToKey(KEY_LCONTROL, 0), KeyInput::Pressed);
            mKeyQueue.push(keyInput);
            mPressedKeys[KEY_LCONTROL] = keyInput;
        }

        if (key[KEY_RCONTROL] && mPressedKeys.find(KEY_RCONTROL) == mPressedKeys.end())
        {
            KeyInput keyInput(convertToKey(KEY_RCONTROL, 0), KeyInput::Pressed);
            mKeyQueue.push(keyInput);
            mPressedKeys[KEY_RCONTROL] = keyInput;
        }

        // Check for released keys
        std::map<int, KeyInput>::iterator iter, tempIter;
        for (iter = mPressedKeys.begin(); iter != mPressedKeys.end(); )
        {
            if (!key[iter->first])
            {
                KeyInput keyInput(iter->second.getKey(), KeyInput::Released);
                keyInput.setNumericPad(iter->second.isNumericPad());
                keyInput.setShiftPressed(iter->second.isShiftPressed());
                keyInput.setAltPressed(iter->second.isAltPressed());
                keyInput.setControlPressed(iter->second.isControlPressed());

                mKeyQueue.push(keyInput);

                tempIter = iter;
                iter++;
                mPressedKeys.erase(tempIter);
            }
            else
            {
                iter++;
            }
        }
    }
Ejemplo n.º 5
0
void Application::Run()
{
    //
    // keyboard
    //

    if (keyboard_needs_poll())
        poll_keyboard();

    for (int k = 0; k < 256; k++)
    {
        if (key[k])
        {
            OnKeyPress(k);

            if (!prevKeyState[k])
                OnKeyPressed(k);
        }
        else if (!key[k])
        {
            if (prevKeyState[k])
                OnKeyReleased(k);
        }
    }

    memcpy(prevKeyState,(char*)key,256);

    //
    // mouse
    //

    if (mouse_needs_poll())
        poll_mouse();

    for (int button = 0; button < (numMouseButtons); button++)
    {
        if ((mouse_b & (1 << button)) != 0)
        {
            mouseButtons[button] = true;
        }
        else
        {
            mouseButtons[button] = false;
        }

        if (mouseButtons[button] && (!prevMouseButtons[button]))
        {
            OnMousePressed(button, mouse_x, mouse_y);

            mousePressedLocs[button].x = mouse_x;
            mousePressedLocs[button].y = mouse_y;
        }
        else if ((!mouseButtons[button]) && prevMouseButtons[button])
        {
            OnMouseReleased(button, mouse_x, mouse_y);

            if ((mousePressedLocs[button].x == mouse_x) &&
                    (mousePressedLocs[button].y == mouse_y))
            {
                OnMouseClick(button,mouse_x,mouse_y);
            }
        }
    }

    memcpy(prevMouseButtons,mouseButtons,sizeof(bool)*(numMouseButtons+1));

    if ((mouse_x != prevMouseX) || (mouse_y != prevMouseY))
    {
        OnMouseMove(mouse_x,mouse_y);

        prevMouseX = mouse_x;
        prevMouseY = mouse_y;
    }

    // mouse wheel
    if (mouse_z > prevMouseZ)
    {
        OnMouseWheelUp( mouse_x, mouse_y );
        prevMouseZ = mouse_z;
    }
    else if (mouse_z < prevMouseZ)
    {
        OnMouseWheelDown( mouse_x, mouse_y );
        prevMouseZ = mouse_z;
    }

    //
    // run the game
    //

    show_mouse(NULL);
    RunGame();
    show_mouse(canvas);

    //
    // render canvas to the screen
    //

    blit(canvas,screen,0,0,0,0,screen->w,screen->h);

    //
    // sound polling (to ensure sounds currently playing will keep playing)
    //
    SoundOGG::PollSounds();

    //
    // handle timing
    //

    HandleTiming();
}
Ejemplo n.º 6
0
int main(int argc, char* argv[])
{
	// init allegro and add keyboard and optional mouse support
	allegro_init();
	install_timer();
	install_keyboard();
	if (ENABLE_MOUSE_SUPPORT)
	{
		install_mouse();
	}

	// set the video mode
	set_color_depth(WINDOW_COLOR_DEPTH);
	set_gfx_mode(
		(WINDOW_USE_FULLSCREEN) ?
			GFX_AUTODETECT_FULLSCREEN :
			GFX_AUTODETECT_WINDOWED,
		WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0);
	// set the window caption text
	set_window_title(WINDOW_CAPTION);

	// create the back buffer bitmap
	backbuffer = create_bitmap(SCREEN_W, SCREEN_H);

	// seed the random number generator
	srand(time(0));

	// lock the static functions and variables we need for handling timing and closing the window via the [X] button
	LOCK_FUNCTION(my_allegro_close_button_handler);
	LOCK_FUNCTION(my_allegro_timer_speed_controller);
	LOCK_VARIABLE(allegrotimerspeedcounter);

	// set the callback function for the close-button to our global handler function
	set_close_button_callback(my_allegro_close_button_handler);

	// set our FPS lock timing global function
	install_int_ex(my_allegro_timer_speed_controller, BPS_TO_TIMER(FRAME_LOCK_RATE));

	// setup the game
	if (!setup_game())
	{
		fprintf(stderr, "The game initialization has failed. Cannot continue!\n");
		exit(1);
	}

	// main loop
	bool gameover = false;
	while(!gameover)
	{
		// if our global is ever false
		if (!mainthreadisrunning)
		{
			gameover = true;
		}

		// we only draw when the FPS should be locked
		if (allegrotimerspeedcounter > 0)
		{
			// we only update during our FPS lock time
			while (allegrotimerspeedcounter > 0)
			{
				// ensure the keyboard data is current
				if (keyboard_needs_poll())
				{
					poll_keyboard();
				}

				// ensure the mosue data is current
				if (ENABLE_MOUSE_SUPPORT)
				{
					if (mouse_needs_poll())
					{
						poll_mouse();
					}
				}

				// update
				update_game();

				// decrement the global timing var so that we can leave the update loop!
				allegrotimerspeedcounter--;
			}

			// start rendering the scene
			render_game();

			if (ENABLE_MOUSE_SUPPORT)
			{
				show_mouse(backbuffer);
			}

			// make it all visible
			blit(backbuffer, screen, 0, 0, 0, 0, backbuffer->w, backbuffer->h);
		}
		else
		{
			// a little rest to keep CPU usage down ^-^
			rest(1);
		}
	}

	// shutdown the game
	shutdown_game();

	// clean up the back buffer
	if (backbuffer)
	{
		if (ENABLE_MOUSE_SUPPORT)
		{
			show_mouse(0);
		}
		destroy_bitmap(backbuffer);
	}

	return 0;
}