mirror of
https://github.com/holub/mame
synced 2025-06-06 12:53:46 +03:00
console in separate class (nw)
This commit is contained in:
parent
30a0af15d9
commit
25ce0fdf9b
@ -61,6 +61,8 @@ files {
|
|||||||
MAME_DIR .. "src/frontend/mame/cheat.h",
|
MAME_DIR .. "src/frontend/mame/cheat.h",
|
||||||
MAME_DIR .. "src/frontend/mame/clifront.cpp",
|
MAME_DIR .. "src/frontend/mame/clifront.cpp",
|
||||||
MAME_DIR .. "src/frontend/mame/clifront.h",
|
MAME_DIR .. "src/frontend/mame/clifront.h",
|
||||||
|
MAME_DIR .. "src/frontend/mame/console.cpp",
|
||||||
|
MAME_DIR .. "src/frontend/mame/console.h",
|
||||||
MAME_DIR .. "src/frontend/mame/info.cpp",
|
MAME_DIR .. "src/frontend/mame/info.cpp",
|
||||||
MAME_DIR .. "src/frontend/mame/info.h",
|
MAME_DIR .. "src/frontend/mame/info.h",
|
||||||
MAME_DIR .. "src/frontend/mame/language.cpp",
|
MAME_DIR .. "src/frontend/mame/language.cpp",
|
||||||
|
@ -29,10 +29,7 @@
|
|||||||
#include "ui/moptions.h"
|
#include "ui/moptions.h"
|
||||||
#include "language.h"
|
#include "language.h"
|
||||||
#include "pluginopts.h"
|
#include "pluginopts.h"
|
||||||
|
#include "console.h"
|
||||||
#include "linenoise-ng/include/linenoise.h"
|
|
||||||
#include <atomic>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -291,95 +288,7 @@ void cli_frontend::start_execution(mame_machine_manager *manager,int argc, char
|
|||||||
m_result = manager->execute();
|
m_result = manager->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
static const char* examples[] = {
|
|
||||||
"db", "hello", "hallo", "hans", "hansekogge", "seamann", "quetzalcoatl", "quit", "power", NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
void completionHook(char const* prefix, linenoiseCompletions* lc) {
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
for (i = 0; examples[i] != NULL; ++i) {
|
|
||||||
if (strncmp(prefix, examples[i], strlen(prefix)) == 0) {
|
|
||||||
linenoiseAddCompletion(lc, examples[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void read_console(std::atomic<bool>& run, std::atomic<bool>& wait, std::string &cmdLine)
|
|
||||||
{
|
|
||||||
char const* prompt = "\x1b[1;36m[MAME]\x1b[0m> ";
|
|
||||||
|
|
||||||
while (run.load())
|
|
||||||
{
|
|
||||||
while (wait.load())
|
|
||||||
{
|
|
||||||
using namespace std::chrono_literals;
|
|
||||||
std::this_thread::sleep_for(100ms);
|
|
||||||
}
|
|
||||||
char* result = linenoise(prompt);
|
|
||||||
if (result == NULL)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* else if (!strncmp(result, "/history", 8)) {
|
|
||||||
// Display the current history.
|
|
||||||
for (int index = 0; ; ++index) {
|
|
||||||
char* hist = linenoiseHistoryLine(index);
|
|
||||||
if (hist == NULL) break;
|
|
||||||
printf("%4d: %s\n", index, hist);
|
|
||||||
free(hist);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
else if (*result == '\0') {
|
|
||||||
free(result);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cmdLine = std::string(result);
|
|
||||||
linenoiseHistoryAdd(result);
|
|
||||||
//prompt = "\x1b[1;36m[MAME]\x1b[0m \x1b[1;32m[test]\x1b[0m> ";
|
|
||||||
|
|
||||||
free(result);
|
|
||||||
wait.store(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void cli_frontend::start_console()
|
|
||||||
{
|
|
||||||
linenoiseInstallWindowChangeHandler();
|
|
||||||
std::string cmdLine = "";
|
|
||||||
const char* file = "./history";
|
|
||||||
|
|
||||||
linenoiseHistoryLoad(file);
|
|
||||||
//linenoiseSetCompletionCallback(completionHook);
|
|
||||||
printf(" _/ _/ _/_/ _/ _/ _/_/_/_/\n");
|
|
||||||
printf(" _/_/ _/_/ _/ _/ _/_/ _/_/ _/ \n");
|
|
||||||
printf(" _/ _/ _/ _/_/_/_/ _/ _/ _/ _/_/_/ \n");
|
|
||||||
printf(" _/ _/ _/ _/ _/ _/ _/ \n");
|
|
||||||
printf("_/ _/ _/ _/ _/ _/ _/_/_/_/ \n");
|
|
||||||
printf("\n");
|
|
||||||
printf("%s v%s\n%s\n\n", emulator_info::get_appname(), build_version, emulator_info::get_copyright_info());
|
|
||||||
|
|
||||||
std::atomic<bool> run(true), wait(false);
|
|
||||||
std::thread cinThread(read_console, std::ref(run), std::ref(wait), std::ref(cmdLine));
|
|
||||||
|
|
||||||
while (run.load())
|
|
||||||
{
|
|
||||||
if (wait.load())
|
|
||||||
{
|
|
||||||
//printf("command %s\n", cmdLine.c_str());
|
|
||||||
cmdLine.clear();
|
|
||||||
wait.store(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
run.store(false);
|
|
||||||
cinThread.join();
|
|
||||||
|
|
||||||
linenoiseHistorySave(file);
|
|
||||||
linenoiseHistoryFree();
|
|
||||||
}
|
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
// execute - execute a game via the standard
|
// execute - execute a game via the standard
|
||||||
// command line interface
|
// command line interface
|
||||||
@ -405,7 +314,8 @@ int cli_frontend::execute(int argc, char **argv)
|
|||||||
|
|
||||||
if (m_options.console()) {
|
if (m_options.console()) {
|
||||||
//manager->lua()->start_console();
|
//manager->lua()->start_console();
|
||||||
start_console();
|
console_frontend console(m_options, m_osd);
|
||||||
|
console.start_console();
|
||||||
} else {
|
} else {
|
||||||
start_execution(manager, argc, argv, option_errors);
|
start_execution(manager, argc, argv, option_errors);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,6 @@ private:
|
|||||||
void display_suggestions(const char *gamename);
|
void display_suggestions(const char *gamename);
|
||||||
void output_single_softlist(FILE *out, software_list_device &swlist);
|
void output_single_softlist(FILE *out, software_list_device &swlist);
|
||||||
void start_execution(mame_machine_manager *manager, int argc, char **argv, std::string &option_errors);
|
void start_execution(mame_machine_manager *manager, int argc, char **argv, std::string &option_errors);
|
||||||
void start_console();
|
|
||||||
|
|
||||||
// internal state
|
// internal state
|
||||||
emu_options & m_options;
|
emu_options & m_options;
|
||||||
|
133
src/frontend/mame/console.cpp
Normal file
133
src/frontend/mame/console.cpp
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
// license:BSD-3-Clause
|
||||||
|
// copyright-holders:Miodrag Milanovic
|
||||||
|
/***************************************************************************
|
||||||
|
|
||||||
|
console.c
|
||||||
|
|
||||||
|
Console interface frontend for MAME.
|
||||||
|
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "emu.h"
|
||||||
|
#include "console.h"
|
||||||
|
#include "linenoise-ng/include/linenoise.h"
|
||||||
|
#include "mame.h"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------
|
||||||
|
// console_frontend - constructor
|
||||||
|
//-------------------------------------------------
|
||||||
|
|
||||||
|
console_frontend::console_frontend(emu_options &options, osd_interface &osd)
|
||||||
|
: m_options(options),
|
||||||
|
m_osd(osd)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------
|
||||||
|
// ~console_frontend - destructor
|
||||||
|
//-------------------------------------------------
|
||||||
|
|
||||||
|
console_frontend::~console_frontend()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
static const char* examples[] = {
|
||||||
|
"db", "hello", "hallo", "hans", "hansekogge", "seamann", "quetzalcoatl", "quit", "power", NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
void completionHook(char const* prefix, linenoiseCompletions* lc) {
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; examples[i] != NULL; ++i) {
|
||||||
|
if (strncmp(prefix, examples[i], strlen(prefix)) == 0) {
|
||||||
|
linenoiseAddCompletion(lc, examples[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void read_console(std::atomic<bool>& run, std::atomic<bool>& wait, std::string &cmdLine)
|
||||||
|
{
|
||||||
|
char const* prompt = "\x1b[1;36m[MAME]\x1b[0m> ";
|
||||||
|
|
||||||
|
while (run.load())
|
||||||
|
{
|
||||||
|
while (wait.load())
|
||||||
|
{
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
std::this_thread::sleep_for(100ms);
|
||||||
|
}
|
||||||
|
char* result = linenoise(prompt);
|
||||||
|
if (result == NULL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* else if (!strncmp(result, "/history", 8)) {
|
||||||
|
// Display the current history.
|
||||||
|
for (int index = 0; ; ++index) {
|
||||||
|
char* hist = linenoiseHistoryLine(index);
|
||||||
|
if (hist == NULL) break;
|
||||||
|
printf("%4d: %s\n", index, hist);
|
||||||
|
free(hist);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
else if (*result == '\0') {
|
||||||
|
free(result);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cmdLine = std::string(result);
|
||||||
|
linenoiseHistoryAdd(result);
|
||||||
|
//prompt = "\x1b[1;36m[MAME]\x1b[0m \x1b[1;32m[test]\x1b[0m> ";
|
||||||
|
|
||||||
|
free(result);
|
||||||
|
wait.store(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void console_frontend::start_console()
|
||||||
|
{
|
||||||
|
linenoiseInstallWindowChangeHandler();
|
||||||
|
std::string cmdLine = "";
|
||||||
|
const char* file = "./history";
|
||||||
|
|
||||||
|
linenoiseHistoryLoad(file);
|
||||||
|
//linenoiseSetCompletionCallback(completionHook);
|
||||||
|
|
||||||
|
// Display app info
|
||||||
|
printf(" _/ _/ _/_/ _/ _/ _/_/_/_/\n");
|
||||||
|
printf(" _/_/ _/_/ _/ _/ _/_/ _/_/ _/ \n");
|
||||||
|
printf(" _/ _/ _/ _/_/_/_/ _/ _/ _/ _/_/_/ \n");
|
||||||
|
printf(" _/ _/ _/ _/ _/ _/ _/ \n");
|
||||||
|
printf("_/ _/ _/ _/ _/ _/ _/_/_/_/ \n");
|
||||||
|
printf("\n");
|
||||||
|
printf("%s v%s\n%s\n\n", emulator_info::get_appname(), build_version, emulator_info::get_copyright_info());
|
||||||
|
|
||||||
|
std::atomic<bool> run(true), wait(false);
|
||||||
|
std::thread cinThread(read_console, std::ref(run), std::ref(wait), std::ref(cmdLine));
|
||||||
|
|
||||||
|
while (run.load())
|
||||||
|
{
|
||||||
|
if (wait.load())
|
||||||
|
{
|
||||||
|
//printf("command %s\n", cmdLine.c_str());
|
||||||
|
cmdLine.clear();
|
||||||
|
wait.store(false);
|
||||||
|
} else {
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
std::this_thread::sleep_for(100ms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run.store(false);
|
||||||
|
cinThread.join();
|
||||||
|
|
||||||
|
linenoiseHistorySave(file);
|
||||||
|
linenoiseHistoryFree();
|
||||||
|
}
|
32
src/frontend/mame/console.h
Normal file
32
src/frontend/mame/console.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// license:BSD-3-Clause
|
||||||
|
// copyright-holders:Miodrag Milanovic
|
||||||
|
/***************************************************************************
|
||||||
|
|
||||||
|
console.c
|
||||||
|
|
||||||
|
Console interface frontend for MAME.
|
||||||
|
|
||||||
|
***************************************************************************/
|
||||||
|
#ifndef MAME_FRONTEND_CONSOLE_H
|
||||||
|
#define MAME_FRONTEND_CONSOLE_H
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "emu.h"
|
||||||
|
|
||||||
|
class console_frontend
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// construction/destruction
|
||||||
|
console_frontend(emu_options &options, osd_interface &osd);
|
||||||
|
~console_frontend();
|
||||||
|
|
||||||
|
void start_console();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// internal state
|
||||||
|
emu_options & m_options;
|
||||||
|
osd_interface & m_osd;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* MAME_FRONTEND_CONSOLE_H */
|
Loading…
Reference in New Issue
Block a user