From 3ee2a36d38c5e2aa3406abeeea12f72ce3a3a74c Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Sat, 28 Oct 2023 06:29:41 +0100 Subject: [PATCH] mish: Removed globals. Removed big horrible global used by mish commands, now use the parameter made for it. Signed-off-by: Michel Pollet --- nuklear/mii_emu.c | 3 +- nuklear/mii_mish.c | 64 +++++++++++++++++++++++-------------------- nuklear/mii_mish_dd.c | 7 ++--- src/mii.h | 8 ++++++ 4 files changed, 47 insertions(+), 35 deletions(-) diff --git a/nuklear/mii_emu.c b/nuklear/mii_emu.c index dcbe3ed..1f4a320 100644 --- a/nuklear/mii_emu.c +++ b/nuklear/mii_emu.c @@ -117,7 +117,7 @@ main( struct nk_colorf bg; mii_init(&g_mii); - int idx = 0; + int idx = 1; uint32_t flags = MII_INIT_DEFAULT; int r = mii_argv_parse(&g_mii, argc, argv, &idx, &flags); if (r == 0) { @@ -126,6 +126,7 @@ main( exit(1); mii_prepare(&g_mii, flags); mish_prepare(1); + mish_set_command_parameter(MISH_FCC('m','i','i',' '), &g_mii); printf("MISH_TELNET_PORT = %s\n", getenv("MISH_TELNET_PORT")); memset(&win, 0, sizeof(win)); diff --git a/nuklear/mii_mish.c b/nuklear/mii_mish.c index c8c9c0c..a7226d5 100644 --- a/nuklear/mii_mish.c +++ b/nuklear/mii_mish.c @@ -19,7 +19,6 @@ #include "mii_65c02_ops.h" #include "mii_65c02_disasm.h" -extern mii_t g_mii; void _mii_mish_text( @@ -29,7 +28,7 @@ _mii_mish_text( { // load 0x400, calculate the 24 line addresses from the code in video // and show the 40 or 80 chars, depending on col80 - mii_t * mii = &g_mii; + mii_t * mii = param; uint16_t a = 0x400; int page2 = mii_read_one(mii, SWPAGE2); // int col80 = mii_read_one(mii, SW80COL); @@ -53,7 +52,7 @@ _mii_mish_cmd( const char * argv[]) { const char * state[] = { "RUNNING", "STOPPED", "STEP" }; - mii_t * mii = &g_mii; + mii_t * mii = param; if (!argv[1]) { show_state: printf("mii: %s Target speed: %.3fMHz Current: %.3fMHz\n", @@ -131,6 +130,11 @@ show_state: mii->state = MII_STOPPED; goto show_state; } + if (!strcmp(argv[1], "quit") || !strcmp(argv[1], "exit")) { + mii->state = MII_TERMINATE; + printf("mii: terminating\n"); + return; + } printf("mii: unknown command %s\n", argv[1]); } @@ -140,7 +144,7 @@ _mii_mish_bp( int argc, const char * argv[]) { - mii_t * mii = &g_mii; + mii_t * mii = param; if (!argv[1] || !strcmp(argv[1], "list")) { printf("breakpoints: map %04x\n", mii->debug.bp_map); for (int i = 0; i < (int)sizeof(mii->debug.bp_map)*8; i++) { @@ -206,7 +210,7 @@ _mii_mish_il( if (addr >= 0xffff) addr = 0xfff0; } - mii_t * mii = &g_mii; + mii_t * mii = param; for (int li = 0; li < 20; li++) { uint8_t op[16]; @@ -231,7 +235,7 @@ _mii_mish_dm( if (addr >= 0xffff) addr = 0xfff0; } - mii_t * mii = &g_mii; + mii_t * mii = param; if (!strcmp(argv[0], "dm")) { printf("dm: %04x\n", addr); for (int i = 0; i < 8; i++) { @@ -266,7 +270,7 @@ _mii_mish_step( const char * argv[]) { if (argv[0][0] == 's') { - mii_t * mii = &g_mii; + mii_t * mii = param; if (argv[1]) { int n = strtol(argv[1], NULL, 10); mii->trace.step_inst = n; @@ -276,7 +280,7 @@ _mii_mish_step( return; } if (argv[0][0] == 'n') { - mii_t * mii = &g_mii; + mii_t * mii = param; // read current opcode, find how how many bytes it take, // then put a temporary breakpoint to the next PC. // all of that if this is not a relative branch of course, in @@ -304,21 +308,19 @@ _mii_mish_step( return; } if (argv[0][0] == 'c') { - mii_t * mii = &g_mii; + mii_t * mii = param; mii->trace.step_inst = 0; mii->state = MII_RUNNING; return; } if (argv[0][0] == 'h') { - mii_t * mii = &g_mii; + mii_t * mii = param; mii->trace.step_inst = 0; mii->state = MII_STOPPED; return; } } -extern int g_mii_audio_record_fd; - #include static void @@ -327,28 +329,29 @@ _mii_mish_audio( int argc, const char * argv[]) { + mii_t * mii = param; if (argc < 2) { printf("audio: missing argument\n"); return; } if (!strcmp(argv[1], "record")) { - if (g_mii_audio_record_fd != -1) { - close(g_mii_audio_record_fd); - g_mii_audio_record_fd = -1; + if (mii->speaker.debug_fd != -1) { + close(mii->speaker.debug_fd); + mii->speaker.debug_fd = -1; printf("audio: stop recording\n"); } else { - g_mii_audio_record_fd = open("audio.raw", + mii->speaker.debug_fd = open("audio.raw", O_WRONLY | O_CREAT | O_TRUNC, 0644); printf("audio: start recording\n"); } } else if (!strcmp(argv[1], "mute")) { if (argv[2] && !strcmp(argv[2], "off")) - g_mii.speaker.muted = false; + mii->speaker.muted = false; else if (argv[2] && !strcmp(argv[2], "on")) - g_mii.speaker.muted = true; + mii->speaker.muted = true; else if (!argv[2] || (argv[2] && !strcmp(argv[2], "toggle"))) - g_mii.speaker.muted = !g_mii.speaker.muted; - printf("audio: %s\n", g_mii.speaker.muted ? "muted" : "unmuted"); + mii->speaker.muted = !mii->speaker.muted; + printf("audio: %s\n", mii->speaker.muted ? "muted" : "unmuted"); } else if (!strcmp(argv[1], "volume")) { if (argc < 3) { printf("audio: missing volume\n"); @@ -358,9 +361,9 @@ _mii_mish_audio( float vol = atof(argv[2]); if (vol < 0) vol = 0; else if (vol > 10) vol = 10; - mii_speaker_volume(&g_mii.speaker, vol); + mii_speaker_volume(&mii->speaker, vol); printf("audio: volume %.3f (amp: %.4f)\n", - vol, g_mii.speaker.vol_multiplier); + vol, mii->speaker.vol_multiplier); } else { printf("audio: unknown command %s\n", argv[1]); } @@ -378,9 +381,10 @@ MISH_CMD_HELP(mii, " poke : poke a value in memory (respect SW)", " peek : peek a value in memory (respect SW)", " speed : set speed in MHz", - " stop : stop the cpu" + " stop : stop the cpu", + " quit|exit : quit the emulator" ); -MISH_CMD_REGISTER(mii, _mii_mish_cmd); +MII_MISH(mii, _mii_mish_cmd); MISH_CMD_NAMES(bp, "bp"); MISH_CMD_HELP(bp, @@ -389,7 +393,7 @@ MISH_CMD_HELP(bp, " +[r|w][s] [size]: add at for read/write, sticky", " - : disable (don't clear) breakpoint " ); -MISH_CMD_REGISTER(bp, _mii_mish_bp); +MII_MISH(bp, _mii_mish_bp); MISH_CMD_NAMES(il, "il"); MISH_CMD_HELP(il, @@ -397,7 +401,7 @@ MISH_CMD_HELP(il, " : list next 20 instructions.", " [addr]: start at address addr" ); -MISH_CMD_REGISTER(il, _mii_mish_il); +MII_MISH(il, _mii_mish_il); MISH_CMD_NAMES(dm, "dm","db","dw","da"); MISH_CMD_HELP(dm, @@ -408,7 +412,7 @@ MISH_CMD_HELP(dm, " da []: dump one address.", " [addr]: start at address addr" ); -MISH_CMD_REGISTER(dm, _mii_mish_dm); +MII_MISH(dm, _mii_mish_dm); MISH_CMD_NAMES(step, "s","step","n","next","cont","h","halt"); MISH_CMD_HELP(step, @@ -417,14 +421,14 @@ MISH_CMD_HELP(step, " n|next : step one instruction, skip subroutines.", " cont : continue execution." ); -MISH_CMD_REGISTER(step, _mii_mish_step); +MII_MISH(step, _mii_mish_step); MISH_CMD_NAMES(text, "text"); MISH_CMD_HELP(text, "mii: show text page [buggy]", " : that's it" ); -MISH_CMD_REGISTER(text, _mii_mish_text); +MII_MISH(text, _mii_mish_text); MISH_CMD_NAMES(audio, "audio"); MISH_CMD_HELP(audio, @@ -433,4 +437,4 @@ MISH_CMD_HELP(audio, " mute: mute/unmute audio.", " volume: set volume (0.0 to 1.0)." ); -MISH_CMD_REGISTER(audio, _mii_mish_audio); +MII_MISH(audio, _mii_mish_audio); diff --git a/nuklear/mii_mish_dd.c b/nuklear/mii_mish_dd.c index 42d7052..c605f92 100644 --- a/nuklear/mii_mish_dd.c +++ b/nuklear/mii_mish_dd.c @@ -13,8 +13,6 @@ #include "mii.h" -extern mii_t g_mii; - static void _mii_mish_dd( @@ -22,8 +20,9 @@ _mii_mish_dd( int argc, const char * argv[]) { + mii_t * mii = param; if (!argv[1] || !strcmp(argv[1], "list")) { - mii_dd_t *d = g_mii.dd.drive; + mii_dd_t *d = mii->dd.drive; printf(" ID %-16s %-20s\n", "Card", "Name"); while (d) { printf("%d:%d %-16s %-20s : %s\n", @@ -43,4 +42,4 @@ MISH_CMD_HELP(dd, "mii: disk commands", " |list: list all disk drives" ); -MISH_CMD_REGISTER(dd, _mii_mish_dd); \ No newline at end of file +MII_MISH(dd, _mii_mish_dd); diff --git a/src/mii.h b/src/mii.h index 6fd7984..07153d8 100644 --- a/src/mii.h +++ b/src/mii.h @@ -278,3 +278,11 @@ uint8_t mii_register_trap( mii_t *mii, mii_trap_handler_cb cb); + +/* + * this is used if libmish is active, to register the 'mii' commands + */ + +#define MII_MISH_KIND MISH_FCC('m','i','i',' ') +#define MII_MISH(_name,_cmd) \ + MISH_CMD_REGISTER_KIND(_name, _cmd, 0, MII_MISH_KIND)