fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
at master 245 lines 5.1 kB view raw
1/***************************************************************************** 2 * pce * 3 *****************************************************************************/ 4 5/***************************************************************************** 6 * File name: src/arch/vic20/msg.c * 7 * Created: 2020-04-18 by Hampa Hug <hampa@hampa.ch> * 8 * Copyright: (C) 2020 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 "msg.h" 25#include "vic20.h" 26 27#include <string.h> 28 29#include <lib/log.h> 30#include <lib/monitor.h> 31#include <lib/msg.h> 32#include <lib/string.h> 33#include <lib/sysdep.h> 34 35 36extern monitor_t par_mon; 37 38 39typedef struct { 40 const char *msg; 41 42 int (*set_msg) (vic20_t *sim, const char *msg, const char *val); 43} v20_msg_list_t; 44 45 46static 47int v20_set_msg_emu_config_save (vic20_t *sim, const char *msg, const char *val) 48{ 49 if (ini_write (val, sim->cfg)) { 50 return (1); 51 } 52 53 return (0); 54} 55 56static 57int v20_set_msg_emu_cpu_speed (vic20_t *sim, const char *msg, const char *val) 58{ 59 unsigned v; 60 61 if (msg_get_uint (val, &v)) { 62 return (1); 63 } 64 65 v20_set_speed (sim, v); 66 67 return (0); 68} 69 70static 71int v20_set_msg_emu_cpu_speed_step (vic20_t *sim, const char *msg, const char *val) 72{ 73 int t; 74 unsigned v; 75 76 if (msg_get_sint (val, &t)) { 77 return (1); 78 } 79 80 if (t >= 0) { 81 v = sim->speed + t; 82 } 83 else { 84 if (-t >= sim->speed) { 85 v = 1; 86 } 87 else { 88 v = sim->speed + t; 89 } 90 } 91 92 v20_set_speed (sim, v); 93 94 return (0); 95} 96 97static 98int v20_set_msg_emu_exit (vic20_t *sim, const char *msg, const char *val) 99{ 100 sim->brk = PCE_BRK_ABORT; 101 102 mon_set_terminate (&par_mon, 1); 103 104 return (0); 105} 106 107static 108int v20_set_msg_emu_reset (vic20_t *sim, const char *msg, const char *val) 109{ 110 v20_reset (sim); 111 112 return (0); 113} 114 115static 116int v20_set_msg_emu_stop (vic20_t *sim, const char *msg, const char *val) 117{ 118 if (sim->trm != NULL) { 119 trm_set_msg_trm (sim->trm, "term.release", "1"); 120 } 121 122 sim->brk = PCE_BRK_STOP; 123 124 return (0); 125} 126 127static 128int v20_set_msg_emu_video_brightness (vic20_t *sim, const char *msg, const char *val) 129{ 130 int v; 131 132 if (msg_get_sint (val, &v)) { 133 return (1); 134 } 135 136 v20_video_set_brightness (&sim->video, v / 100.0); 137 138 return (0); 139} 140 141static 142int v20_set_msg_emu_video_framedrop (vic20_t *sim, const char *msg, const char *val) 143{ 144 unsigned v; 145 146 if (msg_get_uint (val, &v)) { 147 return (1); 148 } 149 150 v20_video_set_framedrop (&sim->video, v); 151 152 return (0); 153} 154 155static 156int v20_set_msg_emu_video_hue (vic20_t *sim, const char *msg, const char *val) 157{ 158 int v; 159 160 if (msg_get_sint (val, &v)) { 161 return (1); 162 } 163 164 v20_video_set_hue (&sim->video, (double) v); 165 166 return (0); 167} 168 169static 170int v20_set_msg_emu_video_saturation (vic20_t *sim, const char *msg, const char *val) 171{ 172 int v; 173 174 if (msg_get_sint (val, &v)) { 175 return (1); 176 } 177 178 v20_video_set_saturation (&sim->video, v / 100.0); 179 180 return (0); 181} 182 183static v20_msg_list_t set_msg_list[] = { 184 { "emu.config.save", v20_set_msg_emu_config_save }, 185 { "emu.cpu.speed", v20_set_msg_emu_cpu_speed }, 186 { "emu.cpu.speed.step", v20_set_msg_emu_cpu_speed_step }, 187 { "emu.exit", v20_set_msg_emu_exit }, 188 { "emu.reset", v20_set_msg_emu_reset }, 189 { "emu.stop", v20_set_msg_emu_stop }, 190 { "emu.video.brightness", v20_set_msg_emu_video_brightness }, 191 { "emu.video.framedrop", v20_set_msg_emu_video_framedrop }, 192 { "emu.video.hue", v20_set_msg_emu_video_hue }, 193 { "emu.video.saturation", v20_set_msg_emu_video_saturation }, 194 { NULL, NULL } 195}; 196 197 198int v20_set_msg (vic20_t *sim, const char *msg, const char *val) 199{ 200 int r; 201 v20_msg_list_t *lst; 202 203 /* a hack, for debugging only */ 204 if (sim == NULL) { 205 sim = par_sim; 206 } 207 208 if (msg == NULL) { 209 return (1); 210 } 211 212 if (val == NULL) { 213 val = ""; 214 } 215 216 lst = set_msg_list; 217 218 while (lst->msg != NULL) { 219 if (msg_is_message (lst->msg, msg)) { 220 return (lst->set_msg (sim, msg, val)); 221 } 222 223 lst += 1; 224 } 225 226 if ((r = cas_set_msg (&sim->cas, msg, val)) >= 0) { 227 return (r); 228 } 229 230 if (sim->trm != NULL) { 231 r = trm_set_msg_trm (sim->trm, msg, val); 232 233 if (r >= 0) { 234 return (r); 235 } 236 } 237 238 if (msg_is_prefix ("term", msg)) { 239 return (1); 240 } 241 242 pce_log (MSG_INF, "unhandled message (\"%s\", \"%s\")\n", msg, val); 243 244 return (1); 245}