fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
1/*****************************************************************************
2 * pce *
3 *****************************************************************************/
4
5/*****************************************************************************
6 * File name: src/arch/sim405/msg.c *
7 * Created: 2018-12-24 by Hampa Hug <hampa@hampa.ch> *
8 * Copyright: (C) 2018 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 "sim405.h"
26
27#include <cpu/ppc405/ppc405.h>
28#include <devices/memory.h>
29#include <lib/msg.h>
30
31
32static
33int s405_msg_emu_disk_commit (sim405_t *sim, const char *msg, const char *val)
34{
35 int r;
36 unsigned drv;
37
38 if (strcmp (val, "all") == 0) {
39 pce_log (MSG_INF, "commiting all drives\n");
40
41 if (dsks_commit (sim->dsks)) {
42 pce_log (MSG_ERR,
43 "*** commit failed for at least one disk\n"
44 );
45 return (1);
46 }
47
48 return (0);
49 }
50
51 r = 0;
52
53 while (*val != 0) {
54 if (msg_get_prefix_uint (&val, &drv, ":", " \t")) {
55 pce_log (MSG_ERR, "*** commit error: bad drive (%s)\n",
56 val
57 );
58
59 return (1);
60 }
61
62 pce_log (MSG_INF, "commiting drive %u\n", drv);
63
64 if (dsks_set_msg (sim->dsks, drv, "commit", NULL)) {
65 pce_log (MSG_ERR, "*** commit error for drive %u\n",
66 drv
67 );
68
69 r = 1;
70 }
71 }
72
73 return (r);
74}
75
76static
77int s405_msg_emu_ser_clock (sim405_t *sim, const char *msg, const char *val)
78{
79 unsigned p, v;
80
81 if (msg_get_prefix_uint (&val, &p, ":", " \t")) {
82 return (1);
83 }
84
85 if (msg_get_uint (val, &v)) {
86 return (1);
87 }
88
89 if (p > 1) {
90 pce_log (MSG_ERR, "*** bad serial port (%u)\n", p);
91 return (1);
92 }
93
94 pce_log (MSG_INF, "setting serial port %u clock multiplier to %u\n", p, v);
95
96 e8250_set_clock_mul (&sim->serport[p]->uart, v);
97
98 return (0);
99}
100
101static
102int s405_msg_emu_ser_multichar (sim405_t *sim, const char *msg, const char *val)
103{
104 unsigned p, v;
105
106 if (msg_get_prefix_uint (&val, &p, ":", " \t")) {
107 return (1);
108 }
109
110 if (msg_get_uint (val, &v)) {
111 return (1);
112 }
113
114 if (p > 1) {
115 pce_log (MSG_ERR, "*** bad serial port (%u)\n", p);
116 return (1);
117 }
118
119 pce_log (MSG_INF, "setting serial port %u multichar to %u\n", p, v);
120
121 e8250_set_multichar (&sim->serport[p]->uart, v, v);
122
123 return (0);
124}
125
126int s405_set_msg (sim405_t *sim, const char *msg, const char *val)
127{
128 /* a hack, for debugging only */
129 if (sim == NULL) {
130 sim = par_sim;
131 }
132
133 if (msg == NULL) {
134 return (1);
135 }
136
137 if (val == NULL) {
138 val = "";
139 }
140
141 if (msg_is_prefix ("term", msg)) {
142 return (1);
143 }
144
145 if (msg_is_message ("emu.disk.commit", msg)) {
146 return (s405_msg_emu_disk_commit (sim, msg, val));
147 }
148 else if (msg_is_message ("emu.ser.clock", msg)) {
149 return (s405_msg_emu_ser_clock (sim, msg, val));
150 }
151 else if (msg_is_message ("emu.ser.multichar", msg)) {
152 return (s405_msg_emu_ser_multichar (sim, msg, val));
153 }
154 else if (msg_is_message ("emu.stop", msg)) {
155 sim->brk = PCE_BRK_STOP;
156 return (0);
157 }
158 else if (msg_is_message ("emu.exit", msg)) {
159 sim->brk = PCE_BRK_ABORT;
160 return (0);
161 }
162
163 pce_log (MSG_INF, "unhandled message (\"%s\", \"%s\")\n", msg, val);
164
165 return (1);
166}