Compare commits

...
9 Commits
Author SHA1 Message Date
kichikuou d7deaec972 Version 2.9.1 2023-06-22 08:52:49 +09:00
kichikuou 30467371f4 debugger_dap: Handle SDL messages while paused in the debugger
So that you can move around the window while the game is paused.

Now DAP messages read from stdin are once posted to the SDL message
queue, and then inserted into the debugger command queue in the main
thread.
2023-06-20 11:07:28 +09:00
kichikuou e9a30f7493 Debugger: Fix crash when breakpoint condition was not met 2023-06-19 21:33:51 +09:00
kichikuou d9e42dd4bb Add a hack to fix Daiakuji's magenta battle background issue 2023-06-19 17:23:03 +09:00
kichikuou 0e06cc1e22 Simplify sdl_copyAreaSP16_shadow 2023-06-19 17:18:31 +09:00
kichikuou 89423c94f1 ShGraph: Use exact color match in PlayAnimeData and ChangeNotColor 2023-06-19 17:18:31 +09:00
kichikuou c694d2282c Fix CX (sprite copy) in 24-bit color games with 16-bit CGs
System3.x uses the following bit expansion when converting RGB565 to
RGB888:

  RRRRR GGGGGG BBBBB => RRRRRRRR GGGGGGGG BBBBBBBB
  12345 123456 12345    12345123 12345612 12345123

However, SDL's blit functions use a slightly different mapping, so
sometimes expanded color did not match the color key specified in the CX
command.

To avoid this, convert to RGB888 by ourselves when drawing 16-bit CGs.
2023-06-19 17:18:17 +09:00
kichikuou 39e94afc44 Specify pixel format explicitly when creating SDL surfaces 2023-06-18 14:47:50 +09:00
kichikuou e37a491908 Refactor keycode definitions 2023-05-21 10:46:22 +09:00
28 changed files with 579 additions and 600 deletions
+2 -2
View File
@@ -16,8 +16,8 @@ android {
}
minSdkVersion 19
targetSdkVersion 31
versionCode 14
versionName "2.9.0" + gitRevision()
versionCode 15
versionName "2.9.1" + gitRevision()
externalNativeBuild {
cmake {
arguments "-DANDROID_APP_PLATFORM=android-16", "-DANDROID_STL=c++_static"
+1 -1
View File
@@ -1,5 +1,5 @@
#cmakedefine PACKAGE "@PACKAGE@"
#define VERSION "2.9.0"
#define VERSION "2.9.1"
#cmakedefine CMAKE_SYSTEM_NAME "@CMAKE_SYSTEM_NAME@"
+3 -3
View File
@@ -22,7 +22,7 @@ Game Compatibility
| DALK | Supported | From ALICEの館4・5・6 |
| 闘神都市 | Supported | From ALICEの館4・5・6 |
| Dr.STOP | Supported | From ALICEの館4・5・6 |
| 人間狩り | Unsupported | From ALICEの館4・5・6 / アリスCD |
| 人間狩り | Supported | From ALICEの館4・5・6 / アリスCD |
| 女の子図鑑 | Unknown | From ALICEの館4・5・6 |
| 恋のおわり | Unknown | |
| 王道勇者 | Supported | |
@@ -71,13 +71,13 @@ Game Compatibility
| [扉] | Supported | From アリスCD |
| 叩き殺し太郎 | Supported | From アリスCD |
| バルーンぽっぷ | Supported | From アリスCD |
| 高速ひよこ2 | Unsupported | From アリスCD |
| 高速ひよこ2 | Supported | From アリスCD |
| おせろっと | Supported | From アリスCD |
| マスカレイド | Supported | From アリスCD |
| キャロル ~聖なる鐘が響く夜~ | Supported | From アリスCD, Online match is not supported |
| できるかなー? | Supported | From アリスCD |
| Child Assassin | Supported | From アリスCD |
| Klavier | Supported | From アリスCD |
| 弱肉狂食 | Unsupported | From アリスCD |
| 弱肉狂食 | Supported | From アリスCD |
| 眼鏡大戦2 | Supported | From アリスCD |
| 妄想くん | Supported | From アリスCD |
-1
View File
@@ -7,7 +7,6 @@
#include "menu.h"
#include "input.h"
#include "nact.h"
#include "key.h"
#include "night.h"
#include "sprite.h"
-1
View File
@@ -33,7 +33,6 @@
#include "menu.h"
#include "input.h"
#include "nact.h"
#include "key.h"
#include "sact.h"
#include "sprite.h"
#include "ngraph.h"
+1 -2
View File
@@ -34,7 +34,6 @@
#include "menu.h"
#include "input.h"
#include "nact.h"
#include "key.h"
#include "sact.h"
#include "sprite.h"
#include "sactsound.h"
@@ -389,7 +388,7 @@ static void cb_waitkey_backlog(agsevent_t *e) {
switch (e->type) {
case AGSEVENT_KEY_RELEASE:
switch (e->code) {
case KEY_ESC:
case KEY_ESCAPE:
sblog_end();
sact.waittype = KEYWAIT_MESSAGE;
break;
-1
View File
@@ -31,7 +31,6 @@
#include "nact.h"
#include "ags.h"
#include "input.h"
#include "key.h"
#include "sact.h"
#include "sprite.h"
#include "ngraph.h"
+9 -5
View File
@@ -37,6 +37,7 @@
#include "ags.h"
#include "music.h"
#include "sdl_core.h"
#include "hacks.h"
#define SLOT 40
@@ -166,14 +167,14 @@ static void ChangeNotColor() {
case 24:
case 32:
{
uint32_t pic24s = PIX24(*src, *(src+1), *(src+2)) & 0xf0f0f0;
uint32_t pic24d = PIX24(*dst, *(dst+1), *(dst+2)) & 0xf0f0f0;
uint32_t pic24s = PIX24(*src, *(src+1), *(src+2));
uint32_t pic24d = PIX24(*dst, *(dst+1), *(dst+2));
uint32_t *yl;
for (y = 0; y < height; y++) {
yl = (uint32_t *)(dp + y * dib->bytes_per_line);
for (x = 0; x < width; x++) {
if ((*yl & 0xf0f0f0) != pic24s) {
if (*yl != pic24s) {
*yl = pic24d;
}
yl++;
@@ -182,6 +183,9 @@ static void ChangeNotColor() {
break;
}
}
// The CX command after ChangeNotColor (in FIGHT.ADV) must use a precise
// calculation.
daiakuji_cx_hack = true;
}
/*
@@ -585,14 +589,14 @@ static void copy_sprite(int sx, int sy, int width, int height, int dx, int dy, i
case 24:
case 32:
{
uint32_t pic24 = PIX24(r, g, b) & 0xf0f0f0;
uint32_t pic24 = PIX24(r, g, b);
uint32_t *yls, *yld;
for (y = 0; y < height; y++) {
yls = (uint32_t *)(sp + y * dib->bytes_per_line);
yld = (uint32_t *)(dp + y * dib->bytes_per_line);
for (x = 0; x < width; x++) {
if ((*yls & 0xf0f0f0) != pic24) {
if (*yls != pic24) {
*yld = *yls;
}
yls++; yld++;
+2 -1
View File
@@ -37,6 +37,7 @@
#include "modules.h"
#include "sdl_core.h"
#include "sdl_private.h"
#include "input.h"
#include "menu.h"
// キー変換テーブル
@@ -162,7 +163,7 @@ static void GetKeyStatus(void) {
}
*var = 0;
for (i = 0; i < 256; i++) {
for (i = 0; i < NUM_KEYCODES; i++) {
*var |= (keymap[no -1][i] * RawKeyInfo[i]);
}
+1 -1
View File
@@ -140,7 +140,7 @@ void gr_drawimage16(surface_t *ds, cgdata *cg, int x, int y) {
yl = (uint32_t *)(dp + y * ds->bytes_per_line);
for (x = 0; x < dw; x++) {
pic16 = *sp;
*yl = PIX24(PIXR16(pic16), PIXG16(pic16), PIXB16(pic16));
*yl = rgb565_to_rgb888(pic16);
yl++; sp++;
}
sp += (cg->width - dw);
-7
View File
@@ -142,10 +142,3 @@ else() # non-emscripten, non-android
add_test(NAME src_tests COMMAND src_tests)
configure_file(testdata/test.gr ${CMAKE_CURRENT_BINARY_DIR}/testdata/test.gr COPYONLY)
endif()
# FIXME: set up dependency for xsystem35 on this
if (NOT EMSCRIPTEN AND NOT ANDROID)
add_custom_target(sdl_keytable.h
COMMAND perl ../tools/xsyskey.pl ${SDL2_INCLUDE_DIRS} > sdl_keytable.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
+7
View File
@@ -87,4 +87,11 @@ extern int cg_fflg;
extern int *cg_loadCountVar;
extern int cg_brightness;
static inline uint32_t rgb565_to_rgb888(uint16_t rgb) {
uint32_t r = rgb >> 11;
uint32_t g = (rgb >> 5) & 0x3f;
uint32_t b = rgb & 0x1f;
return (r << 19) | (r >> 2 << 16) | (g << 10) | (g >> 4 << 8) | (b << 3) | (b >> 2);
}
#endif /* !__CG__ */
+12 -1
View File
@@ -27,6 +27,7 @@
#include "xsystem35.h"
#include "scenario.h"
#include "ags.h"
#include "hacks.h"
void commandCC() {
int src_x = getCaliValue();
@@ -69,7 +70,16 @@ void commandCX() {
switch(mode) {
case 0:
ags_copyArea_shadow(src_x, src_y, width, height, dst_x, dst_y);
// In Daiakuji, the image after the blending is used as a source image
// for sprite copy (CX 1). SDL's SIMD blending implementation has some
// error (blending #ff00ff and #ff00ff results in #fd00fd), so the
// resulting color may not match the colorkey of CX 1. To workaround
// this, specify a small alpha mod so that SDL will use a "slow path"
// that does accurate calculation.
if (daiakuji_cx_hack)
ags_copyArea_shadow_withrate(src_x, src_y, width, height, dst_x, dst_y, 254);
else
ags_copyArea_shadow(src_x, src_y, width, height, dst_x, dst_y);
ags_updateArea(dst_x, dst_y, width, height);
break;
case 1:
@@ -94,6 +104,7 @@ void commandCX() {
DEBUG_COMMAND_YET("CX %d,%d,%d,%d,%d,%d,%d,%d:", mode, src_x, src_y, width, height, dst_x, dst_y, col);
break;
}
daiakuji_cx_hack = false;
DEBUG_COMMAND("CX %d,%d,%d,%d,%d,%d,%d,%d:", mode, src_x, src_y, width, height, dst_x, dst_y, col);
}
+5 -3
View File
@@ -360,21 +360,23 @@ void dbg_delete_breakpoints_in_page(int page) {
}
uint8_t dbg_handle_breakpoint(int page, int addr) {
uint8_t restore_op = BREAKPOINT;
for (Breakpoint *bp = breakpoints; bp; bp = bp->next) {
if (bp->phys->page != page || bp->phys->addr != addr)
continue;
restore_op = bp->phys->restore_op;
if (bp->condition && !eval_condition(bp->condition))
continue;
dbg_state = bp->no == INTERNAL_BREAKPOINT_NO ?
DBG_STOPPED_NEXT : DBG_STOPPED_BREAKPOINT;
uint8_t restore_op = bp->phys->restore_op;
dbg_main(bp->no); // this may destroy bp
return restore_op;
}
SYSERROR("Illegal BREAKPOINT instruction");
return BREAKPOINT;
if (restore_op == BREAKPOINT)
SYSERROR("Illegal BREAKPOINT instruction");
return restore_op;
}
static void set_stack_frame(StackFrame *frame, int page, int addr, boolean is_return_addr) {
+2
View File
@@ -47,6 +47,7 @@ void dbg_main(int bp_no);
void dbg_onsleep(void);
uint8_t dbg_handle_breakpoint(int page, int addr);
boolean dbg_console_vprintf(int lv, const char *format, va_list ap);
void dbg_post_command(void *data);
#else // ENABLE_DEBUGGER
@@ -57,6 +58,7 @@ boolean dbg_console_vprintf(int lv, const char *format, va_list ap);
#define dbg_onsleep()
#define dbg_handle_breakpoint(page, addr) BREAKPOINT
#define dbg_console_vprintf(lv, format, ap) false
#define dbg_post_command(data)
#endif // ENABLE_DEBUGGER
+26 -12
View File
@@ -567,13 +567,13 @@ static int read_command_thread(void *data) {
}
char *buf = malloc(content_length);
fread(buf, content_length, 1, stdin);
msgq_enqueue(queue, buf);
sdl_post_debugger_command(buf);
content_length = -1;
} else {
fprintf(stderr, "Unknown Debug Adapter Protocol header: %s", header);
}
}
msgq_enqueue(queue, NULL); // EOF
sdl_post_debugger_command(NULL); // end of messages
return 0;
}
@@ -588,11 +588,16 @@ static void dbg_dap_init(const char *path) {
SDL_CreateThread(read_command_thread, "Debugger", NULL);
while (!initialized) {
char *msg = msgq_dequeue(queue);
if (!msg)
break;
handle_message(msg);
while (!initialized && !nact->is_quit) {
SDL_Event e;
SDL_WaitEvent(&e);
sdl_handle_event(&e);
while (!msgq_isempty(queue)) {
char *msg = msgq_dequeue(queue);
if (!msg)
return;
handle_message(msg);
}
}
}
@@ -605,11 +610,16 @@ static void dbg_dap_repl(int bp_no) {
dbg_state = DBG_RUNNING;
boolean continue_repl = true;
while (continue_repl) {
char *msg = msgq_dequeue(queue);
if (!msg)
break;
continue_repl = handle_message(msg);
while (continue_repl && !nact->is_quit) {
SDL_Event e;
SDL_WaitEvent(&e);
sdl_handle_event(&e);
while (!msgq_isempty(queue)) {
char *msg = msgq_dequeue(queue);
if (!msg)
return;
continue_repl = handle_message(msg);
}
}
}
@@ -624,6 +634,10 @@ static void dbg_dap_onsleep(void) {
dbg_main(0);
}
void dbg_post_command(void *data) {
msgq_enqueue(queue, data);
}
DebuggerImpl dbg_dap_impl = {
.init = dbg_dap_init,
.quit = dbg_dap_quit,
+2
View File
@@ -33,6 +33,8 @@
/* defined by cmdy.c */
extern boolean Y3waitFlags;
bool daiakuji_cx_hack;
void enable_hack_by_gameid(const char *gameid) {
if (!strcmp(gameid, "toushin2"))
nact->game = GAME_TT2;
+4
View File
@@ -20,6 +20,8 @@
#ifndef __HACKS_H_
#define __HACKS_H_
#include <stdbool.h>
enum gameId {
GAME_UNKNOWN = 0,
GAME_TT2,
@@ -31,4 +33,6 @@ enum gameId {
void enable_hack_by_gameid(const char *gameid);
void enable_hack_by_title(const char *game_title_utf8);
extern bool daiakuji_cx_hack;
#endif // __HACKS_H_
+117
View File
@@ -41,6 +41,123 @@
#define KEYWAIT_CANCELABLE 1
#define KEYWAIT_SKIPPABLE 2
// System3.x key codes (IG command, etc.)
// These are originated from Windows virtual key codes (VK_*).
#define NUM_KEYCODES 256
enum keycode {
KEY_MOUSE_LEFT = 0x01, // マウスの左ボタン
KEY_MOUSE_RIGHT = 0x02, // マウスの右ボタン
KEY_CONTROL = 0x03, // コントロール ブレーク処理に使用
KEY_MOUSE_MIDDLE = 0x04, // マウスの中央ボタン (3つボタンのマウス)
KEY_BACKSPACE = 0x08, // BackSpaceキー
KEY_TAB = 0x09, // Tabキー
KEY_CLEAR = 0x0c, // Clearキー
KEY_RETURN = 0x0d, // Enterキー
KEY_SHIFT = 0x10, // Shiftキー
KEY_CTRL = 0x11, // Ctrlキー
KEY_ALT = 0x12, // Altキー
KEY_PAUSE = 0x13, // Pauseキー
KEY_CAPSLOCK = 0x14, // Caps Lockキー
KEY_KANAKAN = 0x15, // 英数カナキー
KEY_ESCAPE = 0x1b, // Escキー
KEY_SPACE = 0x20, // Spaceキー
KEY_PAGEUP = 0x21, // Page Upキー
KEY_PAGEDOWN = 0x22, // Page Downキー
KEY_END = 0x23, // Endキー
KEY_HOME = 0x24, // Homeキー
KEY_LEFT = 0x25, // ←キー
KEY_UP = 0x26, // ↑キー
KEY_RIGHT = 0x27, // →キー
KEY_DOWN = 0x28, // ↓キー
KEY_SELECT = 0x29, // Selectキー
KEY_EXECUTE = 0x2b, // Executeキー
KEY_PRINTSCREEN = 0x2c, // Print Screenキー (Windows 3.0以降用)
KEY_INSERT = 0x2d, // Insキー
KEY_DELETE = 0x2e, // Delキー
KEY_HELP = 0x2f, // Helpキー
KEY_0 = 0x30, // 0キー
KEY_1 = 0x31, // 1キー
KEY_2 = 0x32, // 2キー
KEY_3 = 0x33, // 3キー
KEY_4 = 0x34, // 4キー
KEY_5 = 0x35, // 5キー
KEY_6 = 0x36, // 6キー
KEY_7 = 0x37, // 7キー
KEY_8 = 0x38, // 8キー
KEY_9 = 0x39, // 9キー
KEY_PAD_EQUALS = 0x3d,
KEY_A = 0x41, // Aキー
KEY_B = 0x42, // Bキー
KEY_C = 0x43, // Cキー
KEY_D = 0x44, // Dキー
KEY_E = 0x45, // Eキー
KEY_F = 0x46, // Fキー
KEY_G = 0x47, // Gキー
KEY_H = 0x48, // Hキー
KEY_I = 0x49, // Iキー
KEY_J = 0x4a, // Jキー
KEY_K = 0x4b, // Kキー
KEY_L = 0x4c, // Lキー
KEY_M = 0x4d, // Mキー
KEY_N = 0x4e, // Nキー
KEY_O = 0x4f, // Oキー
KEY_P = 0x50, // Pキー
KEY_Q = 0x51, // Qキー
KEY_R = 0x52, // Rキー
KEY_S = 0x53, // Sキー
KEY_T = 0x54, // Tキー
KEY_U = 0x55, // Uキー
KEY_V = 0x56, // Vキー
KEY_W = 0x57, // Wキー
KEY_X = 0x58, // Xキー
KEY_Y = 0x59, // Yキー
KEY_Z = 0x5a, // Zキー
KEY_PAD_0 = 0x60, // テンキーの0キー
KEY_PAD_1 = 0x61, // テンキーの1キー
KEY_PAD_2 = 0x62, // テンキーの2キー
KEY_PAD_3 = 0x63, // テンキーの3キー
KEY_PAD_4 = 0x64, // テンキーの4キー
KEY_PAD_5 = 0x65, // テンキーの5キー
KEY_PAD_6 = 0x66, // テンキーの6キー
KEY_PAD_7 = 0x67, // テンキーの7キー
KEY_PAD_8 = 0x68, // テンキーの8キー
KEY_PAD_9 = 0x69, // テンキーの9キー
KEY_PAD_MULTIPLY = 0x6a, // テンキーの*キー
KEY_PAD_PLUS = 0x6b, // テンキーの+キー
KEY_SEPARATOR = 0x6c, // Separatorキー
KEY_PAD_MINUS = 0x6d, // テンキーの-キー
KEY_PAD_PERIOD = 0x6e, // テンキーの.キー
KEY_PAD_DIVIDE = 0x6f, // テンキーの/キー
KEY_F1 = 0x70, // F1キー
KEY_F2 = 0x71, // F2キー
KEY_F3 = 0x72, // F3キー
KEY_F4 = 0x73, // F4キー
KEY_F5 = 0x74, // F5キー
KEY_F6 = 0x75, // F6キー
KEY_F7 = 0x76, // F7キー
KEY_F8 = 0x77, // F8キー
KEY_F9 = 0x78, // F9キー
KEY_F10 = 0x79, // F10キー
KEY_F11 = 0x7a, // F11キー
KEY_F12 = 0x7b, // F12キー
KEY_F13 = 0x7c, // F13キー
KEY_F14 = 0x7d, // F14キー
KEY_F15 = 0x7e, // F15キー
KEY_F16 = 0x7f, // F16キー
KEY_F17 = 0x80, // F17キー
KEY_F18 = 0x81, // F18キー
KEY_F19 = 0x82, // F19キー
KEY_F20 = 0x83, // F20キー
KEY_F21 = 0x84, // F21キー
KEY_F22 = 0x85, // F22キー
KEY_F23 = 0x86, // F23キー
KEY_F24 = 0x87, // F24キー
KEY_NUMLOCK = 0x90, // Num Lockキー
KEY_SCROLLLOCK = 0x91, // Scroll Lockキー
};
extern boolean RawKeyInfo[NUM_KEYCODES];
extern int sys_keywait(int msec, unsigned flags);
extern int sys_getMouseInfo(MyPoint *p, boolean is_dibgeo);
extern int sys_getInputInfo(void);
-153
View File
@@ -1,153 +0,0 @@
/*
* key.h keycode definition
*
* Copyright (C) 2000- Masaki Chikama (Wren) <masaki-c@is.aist-nara.ac.jp>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* $Id: key.h,v 1.2 2000/08/11 18:55:51 chikama Exp $ */
#ifndef __KEYCODE__
#define __KEYCODE__
#define KEY_UNDEFINED (0x00)
#define KEY_MOUSE_LEFT (0x01)
#define KEY_MOUSE_RIGHT (0x02)
#define KEY_CONTROL (0x03)
#define KEY_MOUSE_MIDDLE (0x04)
#define KEY_BS (0x08)
#define KEY_BACKSPACE (0x08)
#define KEY_TAB (0x09)
#define KEY_CLEAR (0x0c)
#define KEY_ENTER (0x0d)
#define KEY_PAD_ENTER (0x0d)
#define KEY_RETURN (0x0d)
#define KEY_SHIFT (0x10)
#define KEY_LSHIFT (0x10)
#define KEY_RSHIFT (0x10)
#define KEY_CTRL (0x11)
#define KEY_LCTRL (0x11)
#define KEY_RCTRL (0x11)
#define KEY_ALT (0x12)
#define KEY_LALT (0x12)
#define KEY_RALT (0x12)
#define KEY_PAUSE (0x13)
#define KEY_CAPSLOCK (0x14)
#define KEY_KANAKAN (0x15)
#define KEY_ESC (0x1b)
#define KEY_ESCAPE (0x1b)
#define KEY_SPACE (0x20)
#define KEY_PAGEUP (0x21)
#define KEY_PAGEDOWN (0x22)
#define KEY_END (0x23)
#define KEY_HOME (0x24)
#define KEY_LEFT (0x25)
#define KEY_UP (0x26)
#define KEY_RIGHT (0x27)
#define KEY_DOWN (0x28)
#define KEY_SELECT (0x29)
#define KEY_EXECUTE (0x2b)
#define KEY_PRINTSCREEN (0x2c)
#define KEY_INS (0x2d)
#define KEY_INSERT (0x2d)
#define KEY_DEL (0x2e)
#define KEY_DELETE (0x2e)
#define KEY_HELP (0x2f)
#define KEY_0 (0x30)
#define KEY_1 (0x31)
#define KEY_2 (0x32)
#define KEY_3 (0x33)
#define KEY_4 (0x34)
#define KEY_5 (0x35)
#define KEY_6 (0x36)
#define KEY_7 (0x37)
#define KEY_8 (0x38)
#define KEY_9 (0x39)
#define KEY_PAD_EQUALS (0x3d)
#define KEY_A (0x41)
#define KEY_B (0x42)
#define KEY_C (0x43)
#define KEY_D (0x44)
#define KEY_E (0x45)
#define KEY_F (0x46)
#define KEY_G (0x47)
#define KEY_H (0x48)
#define KEY_I (0x49)
#define KEY_J (0x4a)
#define KEY_K (0x4b)
#define KEY_L (0x4c)
#define KEY_M (0x4d)
#define KEY_N (0x4e)
#define KEY_O (0x4f)
#define KEY_P (0x50)
#define KEY_Q (0x51)
#define KEY_R (0x52)
#define KEY_S (0x53)
#define KEY_T (0x54)
#define KEY_U (0x55)
#define KEY_V (0x56)
#define KEY_W (0x57)
#define KEY_X (0x58)
#define KEY_Y (0x59)
#define KEY_Z (0x5a)
#define KEY_PAD_0 (0x60)
#define KEY_PAD_1 (0x61)
#define KEY_PAD_2 (0x62)
#define KEY_PAD_3 (0x63)
#define KEY_PAD_4 (0x64)
#define KEY_PAD_5 (0x65)
#define KEY_PAD_6 (0x66)
#define KEY_PAD_7 (0x67)
#define KEY_PAD_8 (0x68)
#define KEY_PAD_9 (0x69)
#define KEY_PAD_STAR (0x6a)
#define KEY_PAD_MULTIPLY (0x6a)
#define KEY_PAD_PLUS (0x6b)
#define KEY_PAD_SEP (0x6c)
#define KEY_PAD_MINUS (0x6d)
#define KEY_PAD_DOT (0x6e)
#define KEY_PAD_PERIOD (0x6e)
#define KEY_PAD_SLASH (0x6f)
#define KEY_PAD_DIVIDE (0x6f)
#define KEY_F1 (0x70)
#define KEY_F2 (0x71)
#define KEY_F3 (0x72)
#define KEY_F4 (0x73)
#define KEY_F5 (0x74)
#define KEY_F6 (0x75)
#define KEY_F7 (0x76)
#define KEY_F8 (0x77)
#define KEY_F9 (0x78)
#define KEY_F10 (0x79)
#define KEY_F11 (0x7a)
#define KEY_F12 (0x7b)
#define KEY_F13 (0x7c)
#define KEY_F14 (0x7d)
#define KEY_F15 (0x7e)
#define KEY_F16 (0x7f)
#define KEY_F17 (0x80)
#define KEY_F18 (0x81)
#define KEY_F19 (0x82)
#define KEY_F20 (0x83)
#define KEY_F21 (0x84)
#define KEY_F22 (0x85)
#define KEY_F23 (0x86)
#define KEY_F24 (0x87)
#define KEY_NUMLOCK (0x90)
#define KEY_SCROLL_LOCK (0x91)
#define KEY_SCROLLOCK (0x91)
#endif /* __KEYCODE__ */
+3 -1
View File
@@ -25,6 +25,7 @@
#include "config.h"
#include <sys/types.h>
#include <SDL_events.h>
#include <SDL_surface.h>
#include "portab.h"
#include "ags.h"
@@ -106,10 +107,11 @@ extern MyPoint sdl_translateMouseCoords(int x, int y);
/* misc */
extern void sdl_mainIteration();
extern boolean RawKeyInfo[];
extern uint32_t sdl_getTicks(void);
extern void sdl_sleep(int msec);
extern void sdl_wait_vsync();
extern boolean sdl_inputString(struct inputstring_param *);
extern void sdl_post_debugger_command(void *data);
extern void sdl_handle_event(SDL_Event *e);
#endif /* !__SDL_CORE__ */
+2 -9
View File
@@ -207,14 +207,7 @@ void sdl_copyArea(int sx, int sy, int w, int h, int dx, int dy) {
void sdl_copyAreaSP(int sx, int sy, int w, int h, int dx, int dy, uint8_t sp) {
sdl_pal_check();
Uint32 col = sp;
if (sdl_dib->format->BitsPerPixel > 8) {
col = SDL_MapRGB(sdl_dib->format,
sdl_col[sp].r & 0xf8,
sdl_col[sp].g & 0xfc,
sdl_col[sp].b & 0xf8);
}
Uint32 col = palette_color(sp);
SDL_SetColorKey(sdl_dib, SDL_TRUE, col);
SDL_Rect r_src = {sx, sy, w, h};
@@ -321,7 +314,7 @@ SDL_Rect sdl_drawString(int x, int y, const char *str_utf8, uint8_t col) {
* 指定範囲にパレット col を rate の割合で重ねる CK1
*/
void sdl_wrapColor(int sx, int sy, int w, int h, uint8_t c, int rate) {
SDL_Surface *s = SDL_CreateRGBSurface(0, w, h, sdl_dib->format->BitsPerPixel, 0, 0, 0, 0);
SDL_Surface *s = SDL_CreateRGBSurfaceWithFormat(0, w, h, sdl_dib->format->BitsPerPixel, sdl_dib->format->format);
assert(s->format->BitsPerPixel > 8);
SDL_Rect r_src = {0, 0, w, h};
+318 -186
View File
@@ -33,14 +33,13 @@
#include "portab.h"
#include "system.h"
#include "debugger.h"
#include "nact.h"
#include "sdl_core.h"
#include "sdl_private.h"
#include "key.h"
#include "menu.h"
#include "input.h"
#include "msgskip.h"
#include "sdl_keytable.h"
static void sdl_getEvent(void);
static void keyEventProsess(SDL_KeyboardEvent *e, boolean pressed);
@@ -49,6 +48,7 @@ static uint32_t custom_event_type = (uint32_t)-1;
enum CustomEventCode {
SIMULATE_RIGHT_BUTTON,
DEBUGGER_COMMAND,
};
/* pointer の状態 */
@@ -59,6 +59,128 @@ boolean RawKeyInfo[256];
/* SDL Joystick */
static int joyinfo=0;
static int sdl_keytable[SDL_NUM_SCANCODES] = {
[SDL_SCANCODE_A] = KEY_A,
[SDL_SCANCODE_B] = KEY_B,
[SDL_SCANCODE_C] = KEY_C,
[SDL_SCANCODE_D] = KEY_D,
[SDL_SCANCODE_E] = KEY_E,
[SDL_SCANCODE_F] = KEY_F,
[SDL_SCANCODE_G] = KEY_G,
[SDL_SCANCODE_H] = KEY_H,
[SDL_SCANCODE_I] = KEY_I,
[SDL_SCANCODE_J] = KEY_J,
[SDL_SCANCODE_K] = KEY_K,
[SDL_SCANCODE_L] = KEY_L,
[SDL_SCANCODE_M] = KEY_M,
[SDL_SCANCODE_N] = KEY_N,
[SDL_SCANCODE_O] = KEY_O,
[SDL_SCANCODE_P] = KEY_P,
[SDL_SCANCODE_Q] = KEY_Q,
[SDL_SCANCODE_R] = KEY_R,
[SDL_SCANCODE_S] = KEY_S,
[SDL_SCANCODE_T] = KEY_T,
[SDL_SCANCODE_U] = KEY_U,
[SDL_SCANCODE_V] = KEY_V,
[SDL_SCANCODE_W] = KEY_W,
[SDL_SCANCODE_X] = KEY_X,
[SDL_SCANCODE_Y] = KEY_Y,
[SDL_SCANCODE_Z] = KEY_Z,
[SDL_SCANCODE_1] = KEY_1,
[SDL_SCANCODE_2] = KEY_2,
[SDL_SCANCODE_3] = KEY_3,
[SDL_SCANCODE_4] = KEY_4,
[SDL_SCANCODE_5] = KEY_5,
[SDL_SCANCODE_6] = KEY_6,
[SDL_SCANCODE_7] = KEY_7,
[SDL_SCANCODE_8] = KEY_8,
[SDL_SCANCODE_9] = KEY_9,
[SDL_SCANCODE_0] = KEY_0,
[SDL_SCANCODE_RETURN] = KEY_RETURN,
[SDL_SCANCODE_ESCAPE] = KEY_ESCAPE,
[SDL_SCANCODE_BACKSPACE] = KEY_BACKSPACE,
[SDL_SCANCODE_TAB] = KEY_TAB,
[SDL_SCANCODE_SPACE] = KEY_SPACE,
// SDL_SCANCODE_MINUS
// SDL_SCANCODE_EQUALS
// SDL_SCANCODE_LEFTBRACKET
// SDL_SCANCODE_RIGHTBRACKET
// SDL_SCANCODE_BACKSLASH
// SDL_SCANCODE_NONUSHASH
// SDL_SCANCODE_SEMICOLON
// SDL_SCANCODE_APOSTROPHE
// SDL_SCANCODE_GRAVE
// SDL_SCANCODE_COMMA
// SDL_SCANCODE_PERIOD
// SDL_SCANCODE_SLASH
[SDL_SCANCODE_CAPSLOCK] = KEY_CAPSLOCK,
[SDL_SCANCODE_F1] = KEY_F1,
[SDL_SCANCODE_F2] = KEY_F2,
[SDL_SCANCODE_F3] = KEY_F3,
[SDL_SCANCODE_F4] = KEY_F4,
[SDL_SCANCODE_F5] = KEY_F5,
[SDL_SCANCODE_F6] = KEY_F6,
[SDL_SCANCODE_F7] = KEY_F7,
[SDL_SCANCODE_F8] = KEY_F8,
[SDL_SCANCODE_F9] = KEY_F9,
[SDL_SCANCODE_F10] = KEY_F10,
[SDL_SCANCODE_F11] = KEY_F11,
[SDL_SCANCODE_F12] = KEY_F12,
[SDL_SCANCODE_PRINTSCREEN] = KEY_PRINTSCREEN,
[SDL_SCANCODE_SCROLLLOCK] = KEY_SCROLLLOCK,
[SDL_SCANCODE_PAUSE] = KEY_PAUSE,
[SDL_SCANCODE_INSERT] = KEY_INSERT,
[SDL_SCANCODE_HOME] = KEY_HOME,
[SDL_SCANCODE_PAGEUP] = KEY_PAGEUP,
[SDL_SCANCODE_DELETE] = KEY_DELETE,
[SDL_SCANCODE_END] = KEY_END,
[SDL_SCANCODE_PAGEDOWN] = KEY_PAGEDOWN,
[SDL_SCANCODE_RIGHT] = KEY_RIGHT,
[SDL_SCANCODE_LEFT] = KEY_LEFT,
[SDL_SCANCODE_DOWN] = KEY_DOWN,
[SDL_SCANCODE_UP] = KEY_UP,
[SDL_SCANCODE_KP_DIVIDE] = KEY_PAD_DIVIDE,
[SDL_SCANCODE_KP_MULTIPLY] = KEY_PAD_MULTIPLY,
[SDL_SCANCODE_KP_MINUS] = KEY_PAD_MINUS,
[SDL_SCANCODE_KP_PLUS] = KEY_PAD_PLUS,
[SDL_SCANCODE_KP_ENTER] = KEY_RETURN,
[SDL_SCANCODE_KP_1] = KEY_PAD_1,
[SDL_SCANCODE_KP_2] = KEY_PAD_2,
[SDL_SCANCODE_KP_3] = KEY_PAD_3,
[SDL_SCANCODE_KP_4] = KEY_PAD_4,
[SDL_SCANCODE_KP_5] = KEY_PAD_5,
[SDL_SCANCODE_KP_6] = KEY_PAD_6,
[SDL_SCANCODE_KP_7] = KEY_PAD_7,
[SDL_SCANCODE_KP_8] = KEY_PAD_8,
[SDL_SCANCODE_KP_9] = KEY_PAD_9,
[SDL_SCANCODE_KP_0] = KEY_PAD_0,
[SDL_SCANCODE_KP_PERIOD] = KEY_PAD_PERIOD,
[SDL_SCANCODE_KP_EQUALS] = KEY_PAD_EQUALS,
[SDL_SCANCODE_F13] = KEY_F13,
[SDL_SCANCODE_F14] = KEY_F14,
[SDL_SCANCODE_F15] = KEY_F15,
[SDL_SCANCODE_F16] = KEY_F16,
[SDL_SCANCODE_F17] = KEY_F17,
[SDL_SCANCODE_F18] = KEY_F18,
[SDL_SCANCODE_F19] = KEY_F19,
[SDL_SCANCODE_F20] = KEY_F20,
[SDL_SCANCODE_F21] = KEY_F21,
[SDL_SCANCODE_F22] = KEY_F22,
[SDL_SCANCODE_F23] = KEY_F23,
[SDL_SCANCODE_F24] = KEY_F24,
[SDL_SCANCODE_EXECUTE] = KEY_EXECUTE,
[SDL_SCANCODE_HELP] = KEY_HELP,
[SDL_SCANCODE_SELECT] = KEY_SELECT,
[SDL_SCANCODE_CLEAR] = KEY_CLEAR,
[SDL_SCANCODE_SEPARATOR] = KEY_SEPARATOR,
[SDL_SCANCODE_LCTRL] = KEY_CTRL,
[SDL_SCANCODE_LSHIFT] = KEY_SHIFT,
[SDL_SCANCODE_LALT] = KEY_ALT,
[SDL_SCANCODE_RCTRL] = KEY_CTRL,
[SDL_SCANCODE_RSHIFT] = KEY_SHIFT,
[SDL_SCANCODE_RALT] = KEY_ALT,
};
void sdl_event_init(void) {
if (custom_event_type == (uint32_t)-1)
custom_event_type = SDL_RegisterEvents(1);
@@ -113,190 +235,195 @@ static void rance4v2_hack(void) {
nact->wait_vsync = FALSE;
}
void sdl_handle_event(SDL_Event *e) {
if (sdl_custom_event_handler && sdl_custom_event_handler(e))
return;
switch (e->type) {
case SDL_QUIT:
menu_quitmenu_open();
break;
case SDL_WINDOWEVENT:
switch (e->window.event) {
case SDL_WINDOWEVENT_EXPOSED:
sdl_dirty = TRUE;
break;
}
break;
#ifdef _WIN32
case SDL_SYSWMEVENT:
win_menu_onsyswmevent(e->syswm.msg);
break;
#endif
case SDL_APP_DIDENTERFOREGROUND:
sdl_dirty = TRUE;
break;
case SDL_KEYDOWN:
keyEventProsess(&e->key, TRUE);
break;
case SDL_KEYUP:
keyEventProsess(&e->key, FALSE);
switch (e->key.keysym.sym) {
case SDLK_F1:
msgskip_activate(!msgskip_isActivated());
break;
case SDLK_F4:
sdl_setFullscreen(!sdl_fs_on);
break;
}
break;
case SDL_MOUSEMOTION:
mousex = e->motion.x;
mousey = e->motion.y;
send_agsevent(AGSEVENT_MOUSE_MOTION, 0);
break;
case SDL_MOUSEWHEEL:
{
int y = e->wheel.y * (e->wheel.direction == SDL_MOUSEWHEEL_FLIPPED ? -1 : 1);
if (y > 0)
mouse_wheel_up += y;
else if (y < 0)
mouse_wheel_down -= y;
send_agsevent(AGSEVENT_MOUSE_WHEEL, y);
break;
}
case SDL_MOUSEBUTTONDOWN:
mouseb |= (1 << e->button.button);
RawKeyInfo[mouse_to_rawkey(e->button.button)] = TRUE;
send_agsevent(AGSEVENT_BUTTON_PRESS, mouse_to_agsevent(e->button.button));
break;
case SDL_MOUSEBUTTONUP:
mouseb &= (0xffffffff ^ (1 << e->button.button));
RawKeyInfo[mouse_to_rawkey(e->button.button)] = FALSE;
send_agsevent(AGSEVENT_BUTTON_RELEASE, mouse_to_agsevent(e->button.button));
if (e->button.button == 2) {
menu_open();
}
break;
case SDL_FINGERDOWN:
if (SDL_GetNumTouchFingers(e->tfinger.touchId) >= 2) {
mouseb &= ~(1 << SDL_BUTTON_LEFT);
mouseb |= 1 << SDL_BUTTON_RIGHT;
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_LEFT)] = FALSE;
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_RIGHT)] = TRUE;
send_agsevent(AGSEVENT_BUTTON_PRESS, AGSEVENT_BUTTON_RIGHT);
} else {
// SDL_RendererEventWatch clamps touch locations outside of the
// viewport to 0.0-1.0. Treat such events as right-clicks.
int button;
if (e->tfinger.x == 0.0f || e->tfinger.x == 1.0f || e->tfinger.y == 0.0f || e->tfinger.y == 1.0f) {
button = SDL_BUTTON_RIGHT;
} else {
button = SDL_BUTTON_LEFT;
mousex = e->tfinger.x * view_w;
mousey = e->tfinger.y * view_h;
send_agsevent(AGSEVENT_MOUSE_MOTION, 0);
}
mouseb |= 1 << button;
RawKeyInfo[mouse_to_rawkey(button)] = TRUE;
send_agsevent(AGSEVENT_BUTTON_PRESS, mouse_to_agsevent(button));
}
break;
case SDL_FINGERUP:
if (SDL_GetNumTouchFingers(e->tfinger.touchId) == 0) {
int ags_button = (mouseb & 1 << SDL_BUTTON_LEFT) ? AGSEVENT_BUTTON_LEFT : AGSEVENT_BUTTON_RIGHT;
mouseb &= ~(1 << SDL_BUTTON_LEFT | 1 << SDL_BUTTON_RIGHT);
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_LEFT)] = FALSE;
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_RIGHT)] = FALSE;
mousex = e->tfinger.x * view_w;
mousey = e->tfinger.y * view_h;
send_agsevent(AGSEVENT_BUTTON_RELEASE, ags_button);
}
break;
case SDL_FINGERMOTION:
mousex = e->tfinger.x * view_w;
mousey = e->tfinger.y * view_h;
send_agsevent(AGSEVENT_MOUSE_MOTION, 0);
break;
case SDL_JOYDEVICEADDED:
sdl_joy_open(e->jdevice.which);
break;
case SDL_JOYAXISMOTION:
if (abs(e->jaxis.value) < 0x4000) {
joyinfo &= e->jaxis.axis == 0 ? ~0xc : ~3;
} else {
int i = (e->jaxis.axis == 0 ? 2 : 0) +
(e->jaxis.value > 0 ? 1 : 0);
joyinfo |= 1 << i;
}
break;
case SDL_JOYBALLMOTION:
break;
case SDL_JOYHATMOTION:
joyinfo &= ~(SYS35KEY_UP | SYS35KEY_DOWN | SYS35KEY_LEFT | SYS35KEY_RIGHT);
switch (e->jhat.value) {
case SDL_HAT_UP: joyinfo |= SYS35KEY_UP; break;
case SDL_HAT_DOWN: joyinfo |= SYS35KEY_DOWN; break;
case SDL_HAT_LEFT: joyinfo |= SYS35KEY_LEFT; break;
case SDL_HAT_RIGHT: joyinfo |= SYS35KEY_RIGHT; break;
case SDL_HAT_LEFTUP: joyinfo |= SYS35KEY_LEFT | SYS35KEY_UP; break;
case SDL_HAT_RIGHTUP: joyinfo |= SYS35KEY_RIGHT | SYS35KEY_UP; break;
case SDL_HAT_LEFTDOWN: joyinfo |= SYS35KEY_LEFT | SYS35KEY_DOWN; break;
case SDL_HAT_RIGHTDOWN: joyinfo |= SYS35KEY_RIGHT | SYS35KEY_DOWN; break;
}
break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
if (e->jbutton.button < 4) {
int i = 1 << (e->jbutton.button+4);
if (e->jbutton.state == SDL_PRESSED)
joyinfo |= i;
else
joyinfo &= ~i;
} else {
if (e->jbutton.state == SDL_RELEASED) {
}
}
break;
default:
if (e->type == custom_event_type) {
switch (e->user.code) {
case SIMULATE_RIGHT_BUTTON:
if ((intptr_t)e->user.data1) {
mouseb |= 1 << SDL_BUTTON_RIGHT;
RawKeyInfo[KEY_MOUSE_RIGHT] = TRUE;
send_agsevent(AGSEVENT_BUTTON_PRESS, AGSEVENT_BUTTON_RIGHT);
} else {
mouseb &= ~(1 << SDL_BUTTON_RIGHT);
RawKeyInfo[KEY_MOUSE_RIGHT] = FALSE;
send_agsevent(AGSEVENT_BUTTON_RELEASE, AGSEVENT_BUTTON_RIGHT);
}
break;
case DEBUGGER_COMMAND:
dbg_post_command(e->user.data1);
break;
}
}
break;
}
}
/* Event処理 */
static void sdl_getEvent(void) {
static int cmd_count_of_prev_input = -1;
SDL_Event e;
boolean m2b = FALSE, msg_skip = FALSE;
boolean had_input = false;
SDL_Event e;
while (SDL_PollEvent(&e)) {
had_input = true;
if (sdl_custom_event_handler && sdl_custom_event_handler(&e))
continue;
switch (e.type) {
case SDL_QUIT:
menu_quitmenu_open();
break;
case SDL_WINDOWEVENT:
switch (e.window.event) {
case SDL_WINDOWEVENT_EXPOSED:
sdl_dirty = TRUE;
break;
}
break;
#ifdef _WIN32
case SDL_SYSWMEVENT:
win_menu_onsyswmevent(e.syswm.msg);
break;
#endif
case SDL_APP_DIDENTERFOREGROUND:
sdl_dirty = TRUE;
break;
case SDL_KEYDOWN:
keyEventProsess(&e.key, TRUE);
break;
case SDL_KEYUP:
keyEventProsess(&e.key, FALSE);
switch (e.key.keysym.sym) {
case SDLK_F1:
msg_skip = TRUE;
break;
case SDLK_F4:
sdl_setFullscreen(!sdl_fs_on);
break;
}
break;
case SDL_MOUSEMOTION:
mousex = e.motion.x;
mousey = e.motion.y;
send_agsevent(AGSEVENT_MOUSE_MOTION, 0);
break;
case SDL_MOUSEWHEEL:
{
int y = e.wheel.y * (e.wheel.direction == SDL_MOUSEWHEEL_FLIPPED ? -1 : 1);
if (y > 0)
mouse_wheel_up += y;
else if (y < 0)
mouse_wheel_down -= y;
send_agsevent(AGSEVENT_MOUSE_WHEEL, y);
break;
}
case SDL_MOUSEBUTTONDOWN:
mouseb |= (1 << e.button.button);
RawKeyInfo[mouse_to_rawkey(e.button.button)] = TRUE;
send_agsevent(AGSEVENT_BUTTON_PRESS, mouse_to_agsevent(e.button.button));
break;
case SDL_MOUSEBUTTONUP:
mouseb &= (0xffffffff ^ (1 << e.button.button));
RawKeyInfo[mouse_to_rawkey(e.button.button)] = FALSE;
send_agsevent(AGSEVENT_BUTTON_RELEASE, mouse_to_agsevent(e.button.button));
if (e.button.button == 2) {
m2b = TRUE;
}
break;
case SDL_FINGERDOWN:
if (SDL_GetNumTouchFingers(e.tfinger.touchId) >= 2) {
mouseb &= ~(1 << SDL_BUTTON_LEFT);
mouseb |= 1 << SDL_BUTTON_RIGHT;
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_LEFT)] = FALSE;
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_RIGHT)] = TRUE;
send_agsevent(AGSEVENT_BUTTON_PRESS, AGSEVENT_BUTTON_RIGHT);
} else {
// SDL_RendererEventWatch clamps touch locations outside of the
// viewport to 0.0-1.0. Treat such events as right-clicks.
int button;
if (e.tfinger.x == 0.0f || e.tfinger.x == 1.0f || e.tfinger.y == 0.0f || e.tfinger.y == 1.0f) {
button = SDL_BUTTON_RIGHT;
} else {
button = SDL_BUTTON_LEFT;
mousex = e.tfinger.x * view_w;
mousey = e.tfinger.y * view_h;
send_agsevent(AGSEVENT_MOUSE_MOTION, 0);
}
mouseb |= 1 << button;
RawKeyInfo[mouse_to_rawkey(button)] = TRUE;
send_agsevent(AGSEVENT_BUTTON_PRESS, mouse_to_agsevent(button));
}
break;
case SDL_FINGERUP:
if (SDL_GetNumTouchFingers(e.tfinger.touchId) == 0) {
int ags_button = (mouseb & 1 << SDL_BUTTON_LEFT) ? AGSEVENT_BUTTON_LEFT : AGSEVENT_BUTTON_RIGHT;
mouseb &= ~(1 << SDL_BUTTON_LEFT | 1 << SDL_BUTTON_RIGHT);
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_LEFT)] = FALSE;
RawKeyInfo[mouse_to_rawkey(SDL_BUTTON_RIGHT)] = FALSE;
mousex = e.tfinger.x * view_w;
mousey = e.tfinger.y * view_h;
send_agsevent(AGSEVENT_BUTTON_RELEASE, ags_button);
}
break;
case SDL_FINGERMOTION:
mousex = e.tfinger.x * view_w;
mousey = e.tfinger.y * view_h;
send_agsevent(AGSEVENT_MOUSE_MOTION, 0);
break;
case SDL_JOYDEVICEADDED:
sdl_joy_open(e.jdevice.which);
break;
case SDL_JOYAXISMOTION:
if (abs(e.jaxis.value) < 0x4000) {
joyinfo &= e.jaxis.axis == 0 ? ~0xc : ~3;
} else {
int i = (e.jaxis.axis == 0 ? 2 : 0) +
(e.jaxis.value > 0 ? 1 : 0);
joyinfo |= 1 << i;
}
break;
case SDL_JOYBALLMOTION:
break;
case SDL_JOYHATMOTION:
joyinfo &= ~(SYS35KEY_UP | SYS35KEY_DOWN | SYS35KEY_LEFT | SYS35KEY_RIGHT);
switch (e.jhat.value) {
case SDL_HAT_UP: joyinfo |= SYS35KEY_UP; break;
case SDL_HAT_DOWN: joyinfo |= SYS35KEY_DOWN; break;
case SDL_HAT_LEFT: joyinfo |= SYS35KEY_LEFT; break;
case SDL_HAT_RIGHT: joyinfo |= SYS35KEY_RIGHT; break;
case SDL_HAT_LEFTUP: joyinfo |= SYS35KEY_LEFT | SYS35KEY_UP; break;
case SDL_HAT_RIGHTUP: joyinfo |= SYS35KEY_RIGHT | SYS35KEY_UP; break;
case SDL_HAT_LEFTDOWN: joyinfo |= SYS35KEY_LEFT | SYS35KEY_DOWN; break;
case SDL_HAT_RIGHTDOWN: joyinfo |= SYS35KEY_RIGHT | SYS35KEY_DOWN; break;
}
break;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
if (e.jbutton.button < 4) {
int i = 1 << (e.jbutton.button+4);
if (e.jbutton.state == SDL_PRESSED)
joyinfo |= i;
else
joyinfo &= ~i;
} else {
if (e.jbutton.state == SDL_RELEASED) {
}
}
break;
default:
if (e.type == custom_event_type) {
switch (e.user.code) {
case SIMULATE_RIGHT_BUTTON:
if ((intptr_t)e.user.data1) {
mouseb |= 1 << SDL_BUTTON_RIGHT;
RawKeyInfo[KEY_MOUSE_RIGHT] = TRUE;
send_agsevent(AGSEVENT_BUTTON_PRESS, AGSEVENT_BUTTON_RIGHT);
} else {
mouseb &= ~(1 << SDL_BUTTON_RIGHT);
RawKeyInfo[KEY_MOUSE_RIGHT] = FALSE;
send_agsevent(AGSEVENT_BUTTON_RELEASE, AGSEVENT_BUTTON_RIGHT);
}
break;
}
}
break;
}
sdl_handle_event(&e);
}
if (had_input) {
cmd_count_of_prev_input = nact->cmd_count;
@@ -305,12 +432,6 @@ static void sdl_getEvent(void) {
if (nact->game == GAME_RANCE4_V2)
rance4v2_hack();
}
if (m2b) {
menu_open();
}
if (msg_skip) msgskip_activate(!msgskip_isActivated());
}
/* キー情報の取得 */
@@ -331,7 +452,7 @@ int sdl_getKeyInfo() {
((RawKeyInfo[KEY_RIGHT] || RawKeyInfo[KEY_PAD_6]) << 3) |
(RawKeyInfo[KEY_RETURN] << 4) |
(RawKeyInfo[KEY_SPACE ] << 5) |
(RawKeyInfo[KEY_ESC] << 6) |
(RawKeyInfo[KEY_ESCAPE] << 6) |
(RawKeyInfo[KEY_TAB] << 7));
return rt;
@@ -368,6 +489,17 @@ int sdl_getJoyInfo(void) {
return joyinfo;
}
void sdl_post_debugger_command(void *data) {
SDL_Event event = {
.user = {
.type = custom_event_type,
.code = DEBUGGER_COMMAND,
.data1 = data
}
};
SDL_PushEvent(&event);
}
#ifdef __EMSCRIPTEN__
EMSCRIPTEN_KEEPALIVE
void simulate_right_button(int pressed) {
+44 -79
View File
@@ -34,8 +34,6 @@
#include "alpha_plane.h"
#include "image.h"
static unsigned char shlv_tbl[256*256];
/*
* dib内での拡大・縮小コピー
*/
@@ -47,7 +45,7 @@ void sdl_scaledCopyArea(int sx, int sy, int sw, int sh, int dx, int dy, int dw,
SDL_Surface *src = sdl_dib;
SDL_Surface *dst = sdl_dib;
ss = SDL_CreateRGBSurface(0, dw, dh, dst->format->BitsPerPixel, 0, 0, 0, 0);
ss = SDL_CreateRGBSurfaceWithFormat(0, dw, dh, dst->format->BitsPerPixel, dst->format->format);
if (dst->format->BitsPerPixel == 8) {
memcpy(ss->format->palette->colors, dst->format->palette->colors,
@@ -142,40 +140,43 @@ void sdl_drawImage16_fromData(cgdata *cg, int dx, int dy, int brightness, bool a
int w = cg->width;
int h = cg->height;
SDL_Surface *s;
if (cg->alpha && alpha_blend) {
unsigned short *p_src = (uint16_t *)cg->pic;
uint32_t *p_ds, *p_dst;
if (cg->alpha) {
uint8_t *a_src = cg->alpha;
uint8_t *adata = GETOFFSET_ALPHA(sdl_dibinfo, dx, dy);
int x, y, l;
s = SDL_CreateRGBSurfaceWithFormat(0, w, h, 32, SDL_PIXELFORMAT_ARGB8888);
p_ds = s->pixels;
l = s->pitch/4;
for (y = 0; y < h; y++) {
p_dst = p_ds;
for (int i = 0; i < h; i++) {
memcpy(adata, a_src, w);
for (x = 0; x < w; x++) {
*p_dst++ = *a_src++ << 24 | PIX24(PIXR16(*p_src), PIXG16(*p_src), PIXB16(*p_src));
p_src++;
}
p_ds += l;
adata += sdl_dibinfo->width;
a_src += cg->width;
}
}
SDL_Surface *s;
if (cg->alpha && alpha_blend) {
uint16_t *p_src = (uint16_t *)cg->pic;
uint8_t *a_src = cg->alpha;
s = SDL_CreateRGBSurfaceWithFormat(0, w, h, 32, SDL_PIXELFORMAT_ARGB8888);
for (int y = 0; y < h; y++) {
uint32_t *dst = (uint32_t *)(((uint8_t *)s->pixels) + y * s->pitch);
for (int x = 0; x < w; x++) {
*dst++ = rgb565_to_rgb888(*p_src++) | *a_src++ << 24;
}
}
} else if (sdl_dibinfo->depth > 16) {
// Convert to RGB888 by ourselves. SDL blit functions use a slightly
// different mapping, so the color expanded by SDL may not match the
// color key specified in the CX command.
uint16_t *src = (uint16_t *)cg->pic;
s = SDL_CreateRGBSurfaceWithFormat(0, w, h, 32, SDL_PIXELFORMAT_RGB888);
for (int y = 0; y < h; y++) {
uint32_t *dst = (uint32_t *)(((uint8_t *)s->pixels) + y * s->pitch);
for (int x = 0; x < w; x++) {
*dst++ = rgb565_to_rgb888(*src++);
}
}
} else {
s = SDL_CreateRGBSurfaceWithFormatFrom(
cg->pic, cg->width, cg->height, 16, cg->width * 2, SDL_PIXELFORMAT_RGB565);
if (cg->alpha) {
uint8_t *a_src = cg->alpha;
uint8_t *adata = GETOFFSET_ALPHA(sdl_dibinfo, dx, dy);
for (int i = 0; i < h; i++) {
memcpy(adata, a_src, w);
adata += sdl_dibinfo->width;
a_src += cg->width;
}
}
}
if (brightness != 255)
@@ -203,65 +204,31 @@ void sdl_drawImage24_fromData(cgdata *cg, int x, int y, int brightness) {
SDL_FreeSurface(s);
}
/*
* 16bit専用の dib の指定領域コピー alphaつき
*/
void sdl_shadow_init(void) {
int i, j;
unsigned char *c = shlv_tbl;
for (i = 0; i < 255; i++) {
for (j = 0; j < 256; j++) {
*(c++) = (unsigned char)(i * j / 255);
}
}
}
void sdl_copyAreaSP16_shadow(int sx, int sy, int w, int h, int dx, int dy, int lv) {
uint8_t *adata = GETOFFSET_ALPHA(sdl_dibinfo, sx, sy);
uint8_t *p_src, *p_dst, *p_ds;
SDL_Surface *s = SDL_CreateRGBSurfaceWithFormat(0, w, h, 32, SDL_PIXELFORMAT_ARGB8888);
int x, y;
SDL_Rect r_src = {sx, sy, w, h};
SDL_Rect r_tmp = { 0, 0, w, h};
SDL_BlitSurface(sdl_dib, &r_src, s, &r_tmp);
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
p_ds = s->pixels + 3;
uint8_t *p_ds = s->pixels + 3;
#else
p_ds = s->pixels;
uint8_t *p_ds = s->pixels;
#endif
switch(lv) {
case 255:
for (y = 0; y < h; y++) {
p_src = adata;
p_dst = p_ds;
for (x = 0; x < w; x++) {
*p_dst = *(p_src++);
p_dst += 4;
}
adata += sdl_dibinfo->width;
p_ds += s->pitch;
uint8_t *adata = GETOFFSET_ALPHA(sdl_dibinfo, sx, sy);
for (int y = 0; y < h; y++) {
uint8_t *p_src = adata;
uint8_t *p_dst = p_ds;
for (int x = 0; x < w; x++) {
*p_dst = *(p_src++);
p_dst += 4;
}
break;
default:
{
unsigned char *lvtbl = shlv_tbl + lv * 256;
for (y = 0; y < h; y++) {
p_src = adata;
p_dst = p_ds;
for (x = 0; x < w; x++) {
*p_dst = lvtbl[(int)(*(p_src++))];
p_dst += 4;
}
adata += sdl_dibinfo->width;
p_ds += s->pitch;
}
}
break;
adata += sdl_dibinfo->width;
p_ds += s->pitch;
}
if (lv < 255)
SDL_SetSurfaceAlphaMod(s, lv);
SDL_Rect r_dst = {dx, dy, w, h};
SDL_BlitSurface(s, &r_tmp, sdl_dib, &r_dst);
@@ -334,9 +301,7 @@ void sdl_getPixel(int x, int y, Palette *cell) {
* dib から領域の切り出し
*/
void* sdl_saveRegion(int x, int y, int w, int h) {
SDL_Surface *s = SDL_CreateRGBSurface(0, w, h, sdl_dib->format->BitsPerPixel,
sdl_dib->format->Rmask, sdl_dib->format->Gmask,
sdl_dib->format->Bmask, sdl_dib->format->Amask);
SDL_Surface *s = SDL_CreateRGBSurfaceWithFormat(0, w, h, sdl_dib->format->BitsPerPixel, sdl_dib->format->format);
if (sdl_dib->format->BitsPerPixel == 8)
memcpy(s->format->palette->colors, sdl_dib->format->palette->colors,
sizeof(SDL_Color) * sdl_dib->format->palette->ncolors);
-73
View File
@@ -1,73 +0,0 @@
static int sdl_keytable[SDL_NUM_SCANCODES] = {
0, KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED,
KEY_A, KEY_B, KEY_C, KEY_D,
KEY_E, KEY_F, KEY_G, KEY_H,
KEY_I, KEY_J, KEY_K, KEY_L,
KEY_M, KEY_N, KEY_O, KEY_P,
KEY_Q, KEY_R, KEY_S, KEY_T,
KEY_U, KEY_V, KEY_W, KEY_X,
KEY_Y, KEY_Z, KEY_1, KEY_2,
KEY_3, KEY_4, KEY_5, KEY_6,
KEY_7, KEY_8, KEY_9, KEY_0,
KEY_RETURN, KEY_ESCAPE, KEY_BACKSPACE, KEY_TAB,
KEY_SPACE, 45, 46, 47,
48, 49, 50, 51,
52, 53, 54, 55,
56, KEY_CAPSLOCK, KEY_F1, KEY_F2,
KEY_F3, KEY_F4, KEY_F5, KEY_F6,
KEY_F7, KEY_F8, KEY_F9, KEY_F10,
KEY_F11, KEY_F12, KEY_PRINTSCREEN, 71,
KEY_PAUSE, KEY_INSERT, KEY_HOME, KEY_PAGEUP,
KEY_DELETE, KEY_END, KEY_PAGEDOWN, KEY_RIGHT,
KEY_LEFT, KEY_DOWN, KEY_UP, 83,
KEY_PAD_DIVIDE, KEY_PAD_MULTIPLY, KEY_PAD_MINUS, KEY_PAD_PLUS,
KEY_PAD_ENTER, KEY_PAD_1, KEY_PAD_2, KEY_PAD_3,
KEY_PAD_4, KEY_PAD_5, KEY_PAD_6, KEY_PAD_7,
KEY_PAD_8, KEY_PAD_9, KEY_PAD_0, KEY_PAD_PERIOD,
0 /* SDL_NONUSBACKSLASH */, 0 /* SDL_APPLICATION */, 0 /* SDL_POWER */, KEY_PAD_EQUALS,
KEY_F13, KEY_F14, KEY_F15, KEY_F16,
KEY_F17, KEY_F18, KEY_F19, KEY_F20,
KEY_F21, KEY_F22, KEY_F23, KEY_F24,
KEY_EXECUTE, KEY_HELP, 0 /* SDL_MENU */, KEY_SELECT,
0 /* SDL_STOP */, 0 /* SDL_AGAIN */, 0 /* SDL_UNDO */, 0 /* SDL_CUT */,
0 /* SDL_COPY */, 0 /* SDL_PASTE */, 0 /* SDL_FIND */, 0 /* SDL_MUTE */,
0 /* SDL_VOLUMEUP */, 0 /* SDL_VOLUMEDOWN */, 0 /* SDL_LOCKINGCAPSLOCK */, 0 /* SDL_LOCKINGNUMLOCK */,
0 /* SDL_LOCKINGSCROLLLOCK */, 0 /* SDL_PAD_COMMA */, 0 /* SDL_PAD_EQUALSAS400 */, 0 /* SDL_INTERNATIONAL1 */,
0 /* SDL_INTERNATIONAL2 */, 0 /* SDL_INTERNATIONAL3 */, 0 /* SDL_INTERNATIONAL4 */, 0 /* SDL_INTERNATIONAL5 */,
0 /* SDL_INTERNATIONAL6 */, 0 /* SDL_INTERNATIONAL7 */, 0 /* SDL_INTERNATIONAL8 */, 0 /* SDL_INTERNATIONAL9 */,
0 /* SDL_LANG1 */, 0 /* SDL_LANG2 */, 0 /* SDL_LANG3 */, 0 /* SDL_LANG4 */,
0 /* SDL_LANG5 */, 0 /* SDL_LANG6 */, 0 /* SDL_LANG7 */, 0 /* SDL_LANG8 */,
0 /* SDL_LANG9 */, 0 /* SDL_ALTERASE */, 0 /* SDL_SYSREQ */, 0 /* SDL_CANCEL */,
KEY_CLEAR, 0 /* SDL_PRIOR */, 0 /* SDL_RETURN2 */, 0 /* SDL_SEPARATOR */,
0 /* SDL_OUT */, 0 /* SDL_OPER */, 0 /* SDL_CLEARAGAIN */, 0 /* SDL_CRSEL */,
0 /* SDL_EXSEL */, KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED,
KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED,
KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED,
0 /* SDL_PAD_00 */, 0 /* SDL_PAD_000 */, 0 /* SDL_THOUSANDSSEPARATOR */, 0 /* SDL_DECIMALSEPARATOR */,
0 /* SDL_CURRENCYUNIT */, 0 /* SDL_CURRENCYSUBUNIT */, 0 /* SDL_PAD_LEFTPAREN */, 0 /* SDL_PAD_RIGHTPAREN */,
0 /* SDL_PAD_LEFTBRACE */, 0 /* SDL_PAD_RIGHTBRACE */, 0 /* SDL_PAD_TAB */, 0 /* SDL_PAD_BACKSPACE */,
0 /* SDL_PAD_A */, 0 /* SDL_PAD_B */, 0 /* SDL_PAD_C */, 0 /* SDL_PAD_D */,
0 /* SDL_PAD_E */, 0 /* SDL_PAD_F */, 0 /* SDL_PAD_XOR */, 0 /* SDL_PAD_POWER */,
0 /* SDL_PAD_PERCENT */, 0 /* SDL_PAD_LESS */, 0 /* SDL_PAD_GREATER */, 0 /* SDL_PAD_AMPERSAND */,
0 /* SDL_PAD_DBLAMPERSAND */, 0 /* SDL_PAD_VERTICALBAR */, 0 /* SDL_PAD_DBLVERTICALBAR */, 0 /* SDL_PAD_COLON */,
0 /* SDL_PAD_HASH */, 0 /* SDL_PAD_SPACE */, 0 /* SDL_PAD_AT */, 0 /* SDL_PAD_EXCLAM */,
0 /* SDL_PAD_MEMSTORE */, 0 /* SDL_PAD_MEMRECALL */, 0 /* SDL_PAD_MEMCLEAR */, 0 /* SDL_PAD_MEMADD */,
0 /* SDL_PAD_MEMSUBTRACT */, 0 /* SDL_PAD_MEMMULTIPLY */, 0 /* SDL_PAD_MEMDIVIDE */, 0 /* SDL_PAD_PLUSMINUS */,
0 /* SDL_PAD_CLEAR */, 0 /* SDL_PAD_CLEARENTRY */, 0 /* SDL_PAD_BINARY */, 0 /* SDL_PAD_OCTAL */,
0 /* SDL_PAD_DECIMAL */, 0 /* SDL_PAD_HEXADECIMAL */, KEY_UNDEFINED, KEY_UNDEFINED,
KEY_RCTRL, KEY_RSHIFT, KEY_RALT, 0 /* SDL_LGUI */,
KEY_RCTRL, KEY_RSHIFT, KEY_RALT, 0 /* SDL_RGUI */,
KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED,
KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED,
KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED,
KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED,
KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED,
KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED, KEY_UNDEFINED,
KEY_UNDEFINED, 0 /* SDL_MODE */, 0 /* SDL_AUDIONEXT */, 0 /* SDL_AUDIOPREV */,
0 /* SDL_AUDIOSTOP */, 0 /* SDL_AUDIOPLAY */, 0 /* SDL_AUDIOMUTE */, 0 /* SDL_MEDIASELECT */,
0 /* SDL_WWW */, 0 /* SDL_MAIL */, 0 /* SDL_CALCULATOR */, 0 /* SDL_COMPUTER */,
0 /* SDL_AC_SEARCH */, 0 /* SDL_AC_HOME */, 0 /* SDL_AC_BACK */, 0 /* SDL_AC_FORWARD */,
0 /* SDL_AC_STOP */, 0 /* SDL_AC_REFRESH */, 0 /* SDL_AC_BOOKMARKS */, 0 /* SDL_BRIGHTNESSDOWN */,
0 /* SDL_BRIGHTNESSUP */, 0 /* SDL_DISPLAYSWITCH */, 0 /* SDL_KBDILLUMTOGGLE */, 0 /* SDL_KBDILLUMDOWN */,
0 /* SDL_KBDILLUMUP */, 0 /* SDL_EJECT */, 0 /* SDL_SLEEP */, 0 /* SDL_APP1 */,
0 /* SDL_APP2 */, };
-1
View File
@@ -54,7 +54,6 @@ struct sdl_private_data {
void sdl_event_init(void);
void sdl_cursor_init(void);
void sdl_shadow_init(void);
int sdl_nearest_color(int r, int g, int b);
boolean sdl_joy_open(int index);
+18 -7
View File
@@ -86,8 +86,6 @@ int sdl_Initialize(const char *render_driver) {
sdl_setWindowSize(SYS35_DEFAULT_WIDTH, SYS35_DEFAULT_HEIGHT);
sdl_shadow_init();
#ifdef __EMSCRIPTEN__
// Prevent SDL from calling emscripten_exit_fullscreen on visibilitychange
emscripten_set_visibilitychange_callback(NULL, 0, NULL);
@@ -162,12 +160,25 @@ static void makeDIB(int width, int height, int depth) {
if (sdl_dib) {
SDL_FreeSurface(sdl_dib);
}
// Graphic routines in modules/ assume 4 bytes/pixel mode for 24-bit surfaces.
if (depth == 24)
depth = 32;
sdl_dib = SDL_CreateRGBSurface(0, width, height, depth, 0, 0, 0, 0);
uint32_t format;
switch (depth) {
case 8:
format = SDL_PIXELFORMAT_INDEX8;
break;
case 16:
format = SDL_PIXELFORMAT_RGB565;
break;
case 24:
format = SDL_PIXELFORMAT_RGB888;
// Graphic routines in modules/ assume 4 bytes/pixel mode for 24-bit surfaces.
depth = 32;
break;
default:
SYSERROR("invalid pixel depth %d", depth);
}
sdl_dib = SDL_CreateRGBSurfaceWithFormat(0, width, height, depth, format);
if (sdl_dib->format->BitsPerPixel == 8) {
memset(sdl_dib->format->palette->colors, 0, sizeof(SDL_Color)*256);
-50
View File
@@ -1,50 +0,0 @@
#! /usr/bin/perl
@key_list=();
%keyh_list=();
open(FX,"<key.h") || exit;
while(<FX>) {
if( /^#define KEY_([^\s]*)\s+[(]([^)]*)[)]/ ) {
$key_list[eval($2)]="$1";
$keyh_list{$1}=eval($2);
}
}
close(fp);
@sdlk_list=();
open(FS,"<$ARGV[0]/SDL_scancode.h") || exit;
while(<FS>) {
if( /SDL_SCANCODE_([^\s]+)\s+=\s*([^,]*),/ ) {
$sdlk_list[eval($2)]="$1";
}
}
close(FS);
print "static int sdl_keytable[SDL_NUM_SCANCODES] = {\n\t";
for( $i = 0 ; $i < scalar(@sdlk_list) ; $i ++ ) {
#print "$i @sdlk_list[$i] $keyh_list{@sdlk_list[$i]}\n";
$x = @sdlk_list[$i];
if( length($x) == 0 ) {
print "KEY_UNDEFINED, ";
} elsif ( $keyh_list{$x} ) {
print "KEY_@key_list[$keyh_list{$x}], ";
} elsif ( $x =~ /[a-z]/ ) {
print "KEY_".uc($x).", ";
} elsif ( $x =~ /KP_/ ) {
$x =~ s/^KP_/PAD_/;
if ( $keyh_list{$x} ) {
print "KEY_$x, ";
} else {
print "0 /* SDL_$x */, ";
}
} elsif ( $i < 0x61) {
print "$i, ";
} else {
print "0 /* SDL_$x */, ";
}
if(($i % 4) == 3 ) {
print "\n\t";
}
}
print "};\n";