Skip to content

Commit

Permalink
Merge pull request #6 from zurachu/debug_mode_with_button
Browse files Browse the repository at this point in the history
Debug mode with button
  • Loading branch information
zurachu authored Jul 16, 2017
2 parents e74b10d + 12d9b33 commit f0428d9
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 64 deletions.
3 changes: 2 additions & 1 deletion common.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ typedef struct tagGLOBAL_SAVE_DATA {

// セーブデータ構造体
typedef struct tagSAVE_DATA {
int gameMode; // ゲーム状態
int gameMode; // ゲーム状態(セーブ時のみ、16bit目にデバッグモードフラグを保存)
int msglen; // メッセージ長さ
char msg[12*8*2+4]; // メッセージバッファ
unsigned short flag[FLAG_NUM]; // フラグ
Expand All @@ -85,6 +85,7 @@ typedef struct tagSAVE_DATA {
extern GLOBAL_SAVE_DATA global;
extern SAVE_DATA play;
extern unsigned short reg[];
extern BOOL debug_mode;
extern int msgView, speed, wait;

void pceth2_Init();
Expand Down
137 changes: 82 additions & 55 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@

BOOL file_load = FALSE; // ファイルを開けたかどうか

BOOL debug_mode = FALSE;
int speed, wait, msgView;

static PrecisionTimer s_frame_timer;
static unsigned long s_frame_us, s_proc_us;

void pceth2_initGraphicAndSound();
int pceth2_readScript(SCRIPT_DATA *s);
void pceth2_waitKey();
void pceth2_startDebugMenu();

//=============================================================================
//=============================================================================
Expand All @@ -75,7 +78,11 @@ void pceth2_waitKey();
void pceAppInit(void)
{
FramObject_Init();


if(pcePadGetDirect() & PAD_C) {
debug_mode = TRUE;
}

/*{{2005/06/09 Naoyuki Sawa*/
if(ufe_setup() != 0) // UFE初期化
{
Expand Down Expand Up @@ -113,12 +120,12 @@ void pceAppInit(void)
// アーカイブ読み込み
file_load = fpk_InitHandle(ARCHIVE_FILE_NAME);
if (file_load) {
#ifdef _DEBUG
pceth2_Init();
pceth2_loadScript(&play.scData, DEBUG_FILE_NAME); // 2005/06/13追加
#else
pceth2_TitleInit();
#endif
if(debug_mode) {
pceth2_Init();
pceth2_startDebugMenu();
} else {
pceth2_TitleInit();
}
}
}

Expand Down Expand Up @@ -185,22 +192,30 @@ void pceAppProc(int cnt)
}

if (pcePadGet() & PAD_D) {
if (play.gameMode == GM_TITLE) {
pceAppReqExit(0);
if(debug_mode) {
if(!strncmp(play.scData.name, DEBUG_FILE_NAME, 6)) { // デバッグメニュースクリプト中
pceAppReqExit(0);
} else {
pceth2_startDebugMenu();
}
} else {
pceth2_TitleInit();
if (play.gameMode == GM_TITLE) {
pceAppReqExit(0);
} else {
pceth2_TitleInit();
}
}
}

#ifdef _DEBUG
pceLCDPaint(0, 0, 82, DISP_X, 6);
pceFontSetType(2);
pceFontSetPos(0, 82);
pceFontSetTxColor(3);
pceFontSetBkColor(FC_SPRITE);
pceFontPrintf("%6lu/%6luus FREE:%8d", s_proc_us, s_frame_us, pceHeapGetMaxFreeSize());
Ldirect_Update();
#endif
if(debug_mode) {
pceLCDPaint(0, 0, 82, DISP_X, 6);
pceFontSetType(2);
pceFontSetPos(0, 82);
pceFontSetTxColor(3);
pceFontSetBkColor(FC_SPRITE);
pceFontPrintf("%6lu/%6luus FREE:%8d", s_proc_us, s_frame_us, pceHeapGetMaxFreeSize());
Ldirect_Update();
}

Ldirect_Trans();

Expand Down Expand Up @@ -265,14 +280,6 @@ int pceAppNotify(int type, int param)
*/
void pceth2_Init()
{
int i;

pceth2_setPageTop();
pceth2_clearMessage();

msgView = 1;
speed = 0;

memset(play, 0, sizeof(SAVE_DATA));

MONTH = START_MONTH; // 月
Expand All @@ -283,6 +290,23 @@ void pceth2_Init()

memset(reg, 0, REG_NUM); // レジスタ

pceth2_initGraphicAndSound();

pceth2_loadEVScript(&play.evData);

// play.gameMode = GM_EVSCRIPT;
}

void pceth2_initGraphicAndSound()
{
int i;

pceth2_setPageTop();
pceth2_clearMessage();

msgView = 1;
speed = 0;

for (i = 0; i <= GRP_NUM; i++) {
pceth2_clearGraphic(i);
}
Expand All @@ -291,11 +315,7 @@ void pceth2_Init()

Stop_PieceMML();

pceth2_loadEVScript(&play.evData);

Ldirect_Update();

// play.gameMode = GM_EVSCRIPT;
}

/*
Expand Down Expand Up @@ -385,32 +405,32 @@ int pceth2_readScript(SCRIPT_DATA *s)

// 最後まで読んだら終了
if (s->p >= s->size) {
#ifdef _DEBUG // デバッグモードの場合デバッグメニューに戻る
pceth2_loadScript(&play.scData, DEBUG_FILE_NAME);
#else
switch(play.gameMode)
{
case GM_EVSCRIPT:
if (!pceth2_initMapSelect()) { // マップ選択肢があればマップ選択へ
JUMP = 0; // 2005/06/20 まるしすさん案:1e, 4, 1が来たらgotoの初期化
if (TIME > EV_NIGHT) { // 一日終了
TIME = EV_MORNING;
DAY++;
pceth2_calenderInit(); // カレンダー
} else {
pceth2_loadEVScript(); // 次のEVスクリプトを読む
if(debug_mode) { // デバッグモードの場合デバッグメニューに戻る
pceth2_startDebugMenu();
} else {
switch(play.gameMode)
{
case GM_EVSCRIPT:
if (!pceth2_initMapSelect()) { // マップ選択肢があればマップ選択へ
JUMP = 0; // 2005/06/20 まるしすさん案:1e, 4, 1が来たらgotoの初期化
if (TIME > EV_NIGHT) { // 一日終了
TIME = EV_MORNING;
DAY++;
pceth2_calenderInit(); // カレンダー
} else {
pceth2_loadEVScript(); // 次のEVスクリプトを読む
}
// if (play.evData.size == 0) { // 読めなかったら終了
// pceAppReqExit(0);
// }
}
// if (play.evData.size == 0) { // 読めなかったら終了
// pceAppReqExit(0);
// }
}
break;
case GM_SCRIPT:
pceth2_closeScript(&play.scData);
play.gameMode = GM_EVSCRIPT;
break;
break;
case GM_SCRIPT:
pceth2_closeScript(&play.scData);
play.gameMode = GM_EVSCRIPT;
break;
}
}
#endif
return 0;
}

Expand Down Expand Up @@ -448,3 +468,10 @@ int pceth2_readScript(SCRIPT_DATA *s)
Ldirect_Update();
return 0;
}

void pceth2_startDebugMenu()
{
pceth2_initGraphicAndSound();
pceth2_loadScript(&play.scData, DEBUG_FILE_NAME);
play.gameMode = GM_SCRIPT;
}
1 change: 1 addition & 0 deletions pceth2_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void pceth2_clearMessage(void)
void pceth2_putKanji(const char *str)
{
FontFuchi_Printf("%c%c", *str, *(str + 1));
Ldirect_VBuffView(TRUE);
*(play.msg + play.msglen++) = *str;
*(play.msg + play.msglen++) = *(str + 1);
*(play.msg + play.msglen) = '\0';
Expand Down
30 changes: 22 additions & 8 deletions pceth2_sav.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
GLOBAL_SAVE_DATA global;
SAVE_DATA play;

static int const s_debug_mode_flag = 0x100; ///< @see common.h SAVE_DATA::gameMode

//=============================================================================
// グローバルセーブファイル
Expand Down Expand Up @@ -85,7 +86,12 @@ BOOL pceth2_readSaveData(int num)
char buf[FNAMELEN_SAV + 1];

sprintf(buf, "pceth2_%d.sav", num);
return (File_ReadTo((unsigned char*)&play, buf) == sizeof(SAVE_DATA));
if(File_ReadTo((unsigned char*)&play, buf) == sizeof(SAVE_DATA)) {
debug_mode = play.gameMode & s_debug_mode_flag;
play.gameMode &= ~s_debug_mode_flag;
return TRUE;
}
return FALSE;
}


Expand Down Expand Up @@ -182,9 +188,9 @@ void pceth2_TitleInit()
int pceth2_backTitle(SCRIPT_DATA *s)
{
s->p++;
#ifndef _DEBUG // デバッグ版は何もしない
pceth2_TitleInit();
#endif
if(!debug_mode) { // デバッグ版は何もしない
pceth2_TitleInit();
}

return 0;
}
Expand Down Expand Up @@ -238,13 +244,18 @@ static void pceth2_drawSaveMenu()
FontFuchi_PutStr("セーブ・ロード\n");

for (i = 0; i < SAVE_FILE_NUM; i++) {
FontFuchi_Printf("%c %d.",((i == global.save_index)? '>' : ' '), i);
FontFuchi_Printf("%c %d. ",((i == global.save_index)? '>' : ' '), i);
sprintf(buf, "pceth2_%d.sav", i);
if (pceFileOpen(&pfa, buf, FOMD_RD) == 0) {
pceFileReadSct(&pfa, NULL, 0, sizeof(SAVE_DATA));
month = ((SAVE_DATA*)pfa.aptr)->flag[0];
day = ((SAVE_DATA*)pfa.aptr)->flag[1];
FontFuchi_Printf("%2d月%2d日 %s曜日", month, day, date[pceth2_getDate(month, day)]);
if(((SAVE_DATA*)pfa.aptr)->gameMode & s_debug_mode_flag) {
FontFuchi_PutStr(((SAVE_DATA*)pfa.aptr)->scData.name);
} else {
month = ((SAVE_DATA*)pfa.aptr)->flag[0];
day = ((SAVE_DATA*)pfa.aptr)->flag[1];
FontFuchi_Printf("%1d月%2d日 %s曜日", month, day, date[pceth2_getDate(month, day)]);
}
pceFileClose(&pfa);
}
FontFuchi_PutStr("\n");
}
Expand Down Expand Up @@ -310,6 +321,9 @@ void pceth2_SaveMenu()
}
} else if (phase == 1) { // セーブ
play.gameMode = last_gameMode; // セーブ用に一瞬戻す
if(debug_mode) {
play.gameMode |= s_debug_mode_flag;
}
pceth2_writeSaveData(global.save_index);
play.gameMode = GM_SAVE;
pceth2_drawSaveMenu();
Expand Down

0 comments on commit f0428d9

Please sign in to comment.