diff --git a/src/common.h b/src/common.h index 175936a..0e32d87 100644 --- a/src/common.h +++ b/src/common.h @@ -65,6 +65,14 @@ inline void strcpy_s(char* dst, size_t n, const char* src) #endif // !WIN32 +static inline bool is_1byte_message(uint8_t c) { + return c == ' ' || (0xa1 <= c && c <= 0xdd); +} + +static inline bool is_2byte_message(uint8_t c) { + return (0x81 <= c && c <= 0x9f) || 0xe0 <= c; +} + // resource.cpp SDL_RWops* open_resource(const char* name, const char* type); diff --git a/src/fileio.cpp b/src/fileio.cpp index 4bb0e6c..ed8f215 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -128,7 +128,7 @@ void FILEIO::Fgets(char *dest, int length) if(p < length + 1) { dest[p++] = c; } - if((0x81 <= c && c <= 0x9f) || 0xe0 <= c) { + if(is_2byte_message(c)) { if(p < length + 1) { dest[p++] = Fgetc(); } diff --git a/src/sys/ags_text.cpp b/src/sys/ags_text.cpp index ca61060..29e9b10 100644 --- a/src/sys/ags_text.cpp +++ b/src/sys/ags_text.cpp @@ -40,7 +40,7 @@ void AGS::draw_text(const char* string) while(string[p] != '\0') { // 文字コード取得 uint16 code = (uint8)string[p++]; - if((0x81 <= code && code <= 0x9f) || 0xe0 <= code) { + if(is_2byte_message(code)) { code = (code << 8) | (uint8)string[p++]; } if(draw_hankaku) { diff --git a/src/sys/nact.cpp b/src/sys/nact.cpp index eb66dec..107e0bf 100644 --- a/src/sys/nact.cpp +++ b/src/sys/nact.cpp @@ -278,8 +278,7 @@ void NACT::execute() cmd_z(); break; default: - if(cmd == 0x20 || (0xa1 <= cmd && cmd <= 0xdd)) { - // message (1 byte) + if(is_1byte_message(cmd)) { char string[3]; string[0] = cmd; string[1] = '\0'; @@ -313,8 +312,7 @@ void NACT::execute() string[2] = '\0'; } output_console(string); - } else if((0x81 <= cmd && cmd <= 0x9f) || 0xe0 <= cmd) { - // message (2 bytes) + } else if(is_2byte_message(cmd)) { char string[3]; string[0] = cmd; string[1] = getd(); diff --git a/src/sys/nact_sys1.cpp b/src/sys/nact_sys1.cpp index 0348d9a..5df7f7f 100644 --- a/src/sys/nact_sys1.cpp +++ b/src/sys/nact_sys1.cpp @@ -204,9 +204,9 @@ void NACT_Sys1::cmd_branch() } else if(cmd == 'Z') { cali(); cali(); - } else if(cmd == 0x20 || (0xa1 <= cmd && cmd <= 0xdd)) { + } else if(is_1byte_message(cmd)) { // message (1 byte) - } else if((0x81 <= cmd && cmd <= 0x9f) || 0xe0 <= cmd) { + } else if(is_2byte_message(cmd)) { // message (2 bytes) getd(); } else { diff --git a/src/sys/nact_sys2.cpp b/src/sys/nact_sys2.cpp index 4802f0f..ee4a018 100644 --- a/src/sys/nact_sys2.cpp +++ b/src/sys/nact_sys2.cpp @@ -171,9 +171,9 @@ void NACT_Sys2::cmd_branch() } else if(cmd == 'M') { for(;;) { uint8 val = getd(); - if(val == 0x20 || (0xa1 <= val && val <= 0xdd)) { + if(is_1byte_message(val)) { // message (1 byte) - } else if((0x81 <= val && val <= 0x9f) || 0xe0 <= val) { + } else if(is_2byte_message(val)) { // message (2 bytes) getd(); } else if(val == ':') { @@ -255,9 +255,9 @@ void NACT_Sys2::cmd_branch() } else if(cmd == 'Z') { cali(); cali(); - } else if(cmd == 0x20 || (0xa1 <= cmd && cmd <= 0xdd)) { + } else if(is_1byte_message(cmd)) { // message (1 byte) - } else if((0x81 <= cmd && cmd <= 0x9f) || 0xe0 <= cmd) { + } else if(is_2byte_message(cmd)) { // message (2 bytes) getd(); } else { @@ -1082,8 +1082,7 @@ void NACT_Sys2::cmd_m() int d, p = 0; while((d = getd()) != ':') { - if((0x81 <= d && d <= 0x9f) || 0xe0 <= d) { - // 2bytes + if(is_2byte_message(d)) { string[p++] = d; string[p++] = getd(); } else { @@ -1474,7 +1473,7 @@ void NACT_Sys2::cmd_y() int len = cmd - 220, p = 0, q = 0; uint8 d; while((d = (uint8)tvar[param - 1][p]) != '\0') { - if((0x81 <= d && d <= 0x9f) || 0xe0 <= d) { + if(is_2byte_message(d)) { string[p] = tvar[param - 1][p]; p++; } diff --git a/src/sys/nact_sys3.cpp b/src/sys/nact_sys3.cpp index 2b477a6..d4a73e4 100644 --- a/src/sys/nact_sys3.cpp +++ b/src/sys/nact_sys3.cpp @@ -798,8 +798,7 @@ void NACT_Sys3::cmd_m() int d, p = 0; while((d = getd()) != ':') { - if((0x81 <= d && d <= 0x9f) || 0xe0 <= d) { - // 2bytes + if(is_2byte_message(d)) { string[p++] = d; string[p++] = getd(); } else { @@ -1385,7 +1384,7 @@ void NACT_Sys3::cmd_y() } else { uint8 code = tvar[param - 1][s++]; string[d++] = code; - if((0x81 <= code && code <= 0x9f) || 0xe0 <= code) { + if(is_2byte_message(code)) { string[d++] = tvar[param - 1][s++]; } } diff --git a/src/win/nact_win.cpp b/src/win/nact_win.cpp index 516b16a..25935dd 100644 --- a/src/win/nact_win.cpp +++ b/src/win/nact_win.cpp @@ -69,7 +69,7 @@ INT_PTR CALLBACK TextDialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lPara pnt = cnt = 0; while(string[pnt] != '\0') { unsigned char dat = string[pnt]; - if((0x81 <= dat && dat <= 0x9f) || 0xe0 <= dat) { + if(is_2byte_message(dat)) { pnt++; } pnt++;