Move call stacks from NACT to Scenario

This commit is contained in:
kichikuou
2024-12-10 08:35:23 +09:00
parent e79f24d8b9
commit d10ae21ff4
7 changed files with 61 additions and 97 deletions
+2 -1
View File
@@ -59,7 +59,8 @@ NACT::NACT(int sys_ver, uint32 crc32_a, uint32 crc32_b, const Config& config)
// シナリオ管理
sco.page_jump(0, 2);
label_depth = page_depth = 0;
sco.label_stack_clear();
sco.page_stack_clear();
// 変数初期化
memset(var, 0, sizeof(var));
-6
View File
@@ -76,7 +76,6 @@
#define M_X var[57]
#define M_Y var[58]
#define MAX_STACK 100
#define MAX_MENU 64
#define MAX_VERB 128
#define MAX_OBJ 256
@@ -117,11 +116,6 @@ protected:
// アドレス、ページ管理
int prev_addr;
int label_depth;
int label_stack[MAX_STACK];
int page_depth;
int page_stack[MAX_STACK];
int addr_stack[MAX_STACK];
// 変数
uint16 var[512];
+3 -28
View File
@@ -243,20 +243,9 @@ void NACT_Sys1::cmd_label_jump()
void NACT_Sys1::cmd_label_call()
{
int next_addr = sco.getw();
sco.label_call(next_addr);
output_console("\n\\%x:", next_addr);
if(next_addr == 0) {
// リターン
if(label_depth == 0) {
// fatal_error = true;
return;
}
sco.jump_to(label_stack[--label_depth]);
} else {
label_stack[label_depth++] = sco.addr();
sco.jump_to(next_addr);
}
}
void NACT_Sys1::cmd_page_jump()
@@ -269,24 +258,10 @@ void NACT_Sys1::cmd_page_jump()
void NACT_Sys1::cmd_page_call()
{
int next_page = cali(), next_addr;
int next_page = cali();
sco.page_call(next_page);
output_console("\n%%%d:", next_page);
if(next_page == 0) {
// リターン
if(page_depth == 0) {
// fatal_error = true;
return;
}
next_page = page_stack[--page_depth];
next_addr = addr_stack[page_depth];
} else {
page_stack[page_depth] = sco.page();
addr_stack[page_depth++] = sco.addr();
next_addr = 2;
}
sco.page_jump(next_page, next_addr);
}
void NACT_Sys1::cmd_set_menu()
+3 -28
View File
@@ -281,20 +281,9 @@ void NACT_Sys2::cmd_label_jump()
void NACT_Sys2::cmd_label_call()
{
int next_addr = sco.getw();
sco.label_call(next_addr);
output_console("\n\\%x:", next_addr);
if(next_addr == 0) {
// リターン
if(label_depth == 0) {
// fatal_error = true;
return;
}
sco.jump_to(label_stack[--label_depth]);
} else {
label_stack[label_depth++] = sco.addr();
sco.jump_to(next_addr);
}
}
void NACT_Sys2::cmd_page_jump()
@@ -307,24 +296,10 @@ void NACT_Sys2::cmd_page_jump()
void NACT_Sys2::cmd_page_call()
{
int next_page = cali(), next_addr;
int next_page = cali();
sco.page_call(next_page);
output_console("\n%%%d:", next_page);
if(next_page == 0) {
// リターン
if(page_depth == 0) {
// fatal_error = true;
return;
}
next_page = page_stack[--page_depth];
next_addr = addr_stack[page_depth];
} else {
page_stack[page_depth] = sco.page();
addr_stack[page_depth++] = sco.addr();
next_addr = 2;
}
sco.page_jump(next_page, next_addr);
}
void NACT_Sys2::cmd_set_menu()
+9 -34
View File
@@ -56,20 +56,9 @@ void NACT_Sys3::cmd_label_jump()
void NACT_Sys3::cmd_label_call()
{
int next_addr = sco.getw();
sco.label_call(next_addr);
output_console("\n\\%x:", next_addr);
if(next_addr == 0) {
// リターン
if(label_depth == 0) {
// fatal_error = true;
return;
}
sco.jump_to(label_stack[--label_depth]);
} else {
label_stack[label_depth++] = sco.addr();
sco.jump_to(next_addr);
}
}
void NACT_Sys3::cmd_page_jump()
@@ -82,24 +71,10 @@ void NACT_Sys3::cmd_page_jump()
void NACT_Sys3::cmd_page_call()
{
int next_page = cali(), next_addr;
int next_page = cali();
sco.page_call(next_page);
output_console("\n%%%d:", next_page);
if(next_page == 0) {
// リターン
if(page_depth == 0) {
// fatal_error = true;
return;
}
next_page = page_stack[--page_depth];
next_addr = addr_stack[page_depth];
} else {
page_stack[page_depth] = sco.page();
addr_stack[page_depth++] = sco.addr();
next_addr = 2;
}
sco.page_jump(next_page, next_addr);
}
void NACT_Sys3::cmd_set_menu()
@@ -1223,23 +1198,23 @@ void NACT_Sys3::cmd_y()
break;
case 80:
if(param == 0) {
RND = label_depth;
RND = sco.label_stack_size();
} else if(param == 1) {
RND = page_depth;
RND = sco.page_stack_size();
}
break;
case 81:
if(param == 0) {
label_depth = label_depth ? label_depth - 1 : 0;
sco.label_stack_pop();
} else if(param == 1) {
page_depth = page_depth ? page_depth - 1 : 0;
sco.page_stack_pop();
}
break;
case 82:
if(param == 0) {
label_depth = 0;
sco.label_stack_clear();
} else if(param == 1) {
page_depth = 0;
sco.page_stack_clear();
}
break;
case 100:
+31
View File
@@ -29,3 +29,34 @@ void Scenario::get_syseng_string(char* buf, int size, Encoding *enc, uint8_t ter
}
buf[i] = '\0';
}
void Scenario::label_call(int label)
{
if (label == 0) {
if (label_stack.empty()) {
WARNING("Label stack underflow");
return;
}
jump_to(label_stack.back());
label_stack.pop_back();
} else {
label_stack.push_back(addr());
jump_to(label);
}
}
void Scenario::page_call(int target_page)
{
if (target_page == 0) {
if (page_stack.empty()) {
WARNING("Page stack underflow");
return;
}
auto& pair = page_stack.back();
page_jump(pair.first, pair.second);
page_stack.pop_back();
} else {
page_stack.emplace_back(page(), addr());
page_jump(target_page, 2);
}
}
+13
View File
@@ -1,6 +1,7 @@
#ifndef _SCENARIO_H_
#define _SCENARIO_H_
#include <utility>
#include <vector>
#include <stdint.h>
#include "dri.h"
@@ -43,11 +44,23 @@ public:
void skip_string(Encoding *enc, uint8_t terminator);
void get_syseng_string(char* buf, int size, Encoding *enc, uint8_t terminator);
void label_call(int label);
size_t label_stack_size() const { return label_stack.size(); }
void label_stack_pop() { label_stack.pop_back(); }
void label_stack_clear() { label_stack.clear(); }
void page_call(int page);
size_t page_stack_size() const { return page_stack.size(); }
void page_stack_pop() { page_stack.pop_back(); }
void page_stack_clear() { page_stack.clear(); }
private:
Dri adisk;
std::vector<uint8_t> data_;
int page_;
int addr_;
std::vector<int> label_stack;
std::vector<std::pair<int, int>> page_stack;
};
#endif // _SCENARIO_H_