fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
1/*****************************************************************************
2 * pce *
3 *****************************************************************************/
4
5/*****************************************************************************
6 * File name: src/arch/spectrum/msg.c *
7 * Created: 2022-02-02 by Hampa Hug <hampa@hampa.ch> *
8 * Copyright: (C) 2022-2024 Hampa Hug <hampa@hampa.ch> *
9 *****************************************************************************/
10
11/*****************************************************************************
12 * This program is free software. You can redistribute it and / or modify it *
13 * under the terms of the GNU General Public License version 2 as published *
14 * by the Free Software Foundation. *
15 * *
16 * This program is distributed in the hope that it will be useful, but *
17 * WITHOUT ANY WARRANTY, without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
19 * Public License for more details. *
20 *****************************************************************************/
21
22
23#include "main.h"
24#include "spectrum.h"
25#include "msg.h"
26
27#include <string.h>
28
29#include <drivers/block/block.h>
30
31#include <lib/console.h>
32#include <lib/inidsk.h>
33#include <lib/log.h>
34#include <lib/monitor.h>
35#include <lib/msg.h>
36
37
38typedef struct {
39 const char *msg;
40
41 int (*set_msg) (spectrum_t *sim, const char *msg, const char *val);
42} spec_msg_list_t;
43
44
45extern monitor_t par_mon;
46extern spectrum_t *par_sim;
47
48
49static
50int spec_set_msg_emu_cpu_speed (spectrum_t *sim, const char *msg, const char *val)
51{
52 unsigned v;
53
54 if (msg_get_uint (val, &v)) {
55 return (1);
56 }
57
58 spec_set_speed (sim, v);
59
60 return (0);
61}
62
63static
64int spec_set_msg_emu_cpu_speed_step (spectrum_t *sim, const char *msg, const char *val)
65{
66 int v;
67
68 if (msg_get_sint (val, &v)) {
69 return (1);
70 }
71
72 v += (int) sim->speed;
73
74 if (v <= 0) {
75 v = 1;
76 }
77
78 spec_set_speed (sim, v);
79
80 return (0);
81}
82
83static
84int spec_set_msg_emu_exit (spectrum_t *sim, const char *msg, const char *val)
85{
86 sim->brk = PCE_BRK_ABORT;
87
88 mon_set_terminate (&par_mon, 1);
89
90 return (0);
91}
92
93static
94int spec_set_msg_emu_reset (spectrum_t *sim, const char *msg, const char *val)
95{
96 spec_reset (sim);
97
98 return (0);
99}
100
101static
102int spec_set_msg_emu_stop (spectrum_t *sim, const char *msg, const char *val)
103{
104 sim->brk = PCE_BRK_STOP;
105
106 return (0);
107}
108
109
110static spec_msg_list_t set_msg_list[] = {
111 { "emu.cpu.speed", spec_set_msg_emu_cpu_speed },
112 { "emu.cpu.speed.step", spec_set_msg_emu_cpu_speed_step },
113 { "emu.exit", spec_set_msg_emu_exit },
114 { "emu.reset", spec_set_msg_emu_reset },
115 { "emu.stop", spec_set_msg_emu_stop },
116 { NULL, NULL }
117};
118
119
120int spec_set_msg (spectrum_t *sim, const char *msg, const char *val)
121{
122 int r;
123 spec_msg_list_t *lst;
124
125 /* a hack, for debugging only */
126 if (sim == NULL) {
127 sim = par_sim;
128 }
129
130 if (msg == NULL) {
131 return (1);
132 }
133
134 if (val == NULL) {
135 val = "";
136 }
137
138 lst = set_msg_list;
139
140 while (lst->msg != NULL) {
141 if (msg_is_message (lst->msg, msg)) {
142 return (lst->set_msg (sim, msg, val));
143 }
144
145 lst += 1;
146 }
147
148 if ((r = cas_set_msg (&sim->cas, msg, val)) >= 0) {
149 return (r);
150 }
151
152 if (sim->term != NULL) {
153 if ((r = trm_set_msg_trm (sim->term, msg, val)) >= 0) {
154 return (r);
155 }
156 }
157
158 if (msg_is_prefix ("term", msg)) {
159 return (1);
160 }
161
162 pce_log (MSG_INF, "unhandled message (\"%s\", \"%s\")\n", msg, val);
163
164 return (1);
165}