w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RtclRw11.cpp
Go to the documentation of this file.
1// $Id: RtclRw11.cpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2013-2019 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2019-02-23 1114 1.0.7 use std::bind instead of lambda
8// 2018-12-17 1087 1.0.6 use std::lock_guard instead of boost
9// 2018-12-15 1082 1.0.5 use lambda instead of boost::bind
10// 2017-04-16 876 1.0.4 add CpuCommands()
11// 2017-04-07 868 1.0.3 M_dump: use GetArgsDump and Dump detail
12// 2017-04-02 866 1.0.2 add M_set; handle default disk scheme
13// 2015-03-28 660 1.0.1 add M_get
14// 2014-12-25 621 1.1 adopt to 4k word ibus window
15// 2013-03-06 495 1.0 Initial version
16// 2013-01-27 478 0.1 First Draft
17// ---------------------------------------------------------------------------
18
23#include <ctype.h>
24
25#include <iostream>
26#include <string>
27#include <functional>
28
32#include "RtclRw11CpuW11a.hpp"
33#include "librw11/Rw11Cpu.hpp"
34#include "librw11/Rw11Cntl.hpp"
36
37#include "RtclRw11.hpp"
38
39using namespace std;
40using namespace std::placeholders;
41
47// all method definitions in namespace Retro
48namespace Retro {
49
50//------------------------------------------+-----------------------------------
52
53RtclRw11::RtclRw11(Tcl_Interp* interp, const char* name)
54 : RtclProxyOwned<Rw11>("Rw11", interp, name, new Rw11()),
55 fspServ(),
56 fGets(),
57 fSets()
58{
59 AddMeth("get", bind(&RtclRw11::M_get, this, _1));
60 AddMeth("set", bind(&RtclRw11::M_set, this, _1));
61 AddMeth("start", bind(&RtclRw11::M_start, this, _1));
62 AddMeth("dump", bind(&RtclRw11::M_dump, this, _1));
63 AddMeth("$default", bind(&RtclRw11::M_default, this, _1));
64
65 Rw11* pobj = &Obj();
66 fGets.Add<bool> ("started", bind(&Rw11::IsStarted, pobj));
67 fGets.Add<const string&> ("diskscheme", bind(&Rw11VirtDisk::DefaultScheme));
68
69 fSets.Add<const string&> ("diskscheme",
71 fGets.Add<Tcl_Obj*> ("cpus",
72 bind(&RtclRw11::CpuCommands, this));
73}
74
75//------------------------------------------+-----------------------------------
77
79{}
80
81//------------------------------------------+-----------------------------------
83
85{
86 string parent;
87 if (!args.GetArg("parent", parent)) return kERR;
88
89 // locate RlinkServer proxy and object -> setup W11->Server linkage
91 "RlinkServer", parent);
92
93 if (pprox == nullptr)
94 return args.Quit(string("-E: object '") + parent +
95 "' not found or not type RlinkServer");
96
97 // make RtclRlinkRw11 object be co-owner of RlinkServer object
98 fspServ = dynamic_cast<RtclRlinkServer*>(pprox)->ObjSPtr();
99
100 // set RlinkServer in Rw11 (make Rw11 also co-owner)
102
103 // now configure cpu's
104 string type;
105 int count = 1;
106 if (!args.GetArg("type", type)) return kERR;
107 if (!args.GetArg("?count", count, 1, 1)) return kERR;
108 if (!args.AllDone()) return kERR;
109
110 // 'factory section', create concrete w11Cpu objects
111 if (type == "w11a") { // w11a --------------------------
112 RtclRw11CpuW11a* pobj = new RtclRw11CpuW11a(args.Interp(), "cpu0");
113 // configure cpu
114 pobj->Obj().Setup(0,0,0x4000); // ind=0,base=0,ibase=0x4000
115 // install in w11
116 Obj().AddCpu(dynamic_pointer_cast<Rw11Cpu>(pobj->ObjSPtr()));
117
118 } else { // unknown cpu type --------------
119 return args.Quit(string("-E: unknown cpu type '") + type + "'");
120 }
121
122 return kOK;
123}
124
125//------------------------------------------+-----------------------------------
127
129{
130 // synchronize with server thread
131 lock_guard<RlinkConnect> lock(Obj().Connect());
132 return fGets.M_get(args);
133}
134
135//------------------------------------------+-----------------------------------
137
139{
140 // synchronize with server thread
141 lock_guard<RlinkConnect> lock(Obj().Connect());
142 return fSets.M_set(args);
143}
144
145//------------------------------------------+-----------------------------------
147
149{
150 if (!args.AllDone()) return kERR;
151 if (Obj().IsStarted()) return args.Quit("-E: already started");
152 Obj().Start();
153 return kOK;
154}
155
156//------------------------------------------+-----------------------------------
158
160{
161 int detail=0;
162 if (!GetArgsDump(args, detail)) return kERR;
163 if (!args.AllDone()) return kERR;
164
165 ostringstream sos;
166 Obj().Dump(sos, 0, "", detail);
167 args.SetResult(sos);
168 return kOK;
169}
170
171//------------------------------------------+-----------------------------------
173
175{
176 if (!args.AllDone()) return kERR;
177 ostringstream sos;
178
179 sos << "cpu type base : cntl type ibbase probe lam boot" << endl;
180
181 for (size_t i=0; i<Obj().NCpu(); i++) {
182 Rw11Cpu& cpu(Obj().Cpu(i));
183 sos << " " << i << " "
184 << " " << RosPrintf(cpu.Type().c_str(),"-s",4)
185 << " " << RosPrintf(cpu.Base(),"x",4)
186 << endl;
187
188 vector<string> cntlnames;
189 cpu.ListCntl(cntlnames);
190 for (auto& cname : cntlnames) {
191 Rw11Cntl& cntl(cpu.Cntl(cname));
192 const Rw11Probe& pstat(cntl.ProbeStatus());
193 sos << " " << RosPrintf(cntl.Name().c_str(),"-s",4)
194 << " " << RosPrintf(cntl.Type().c_str(),"-s",5)
195 << " " << RosPrintf(cntl.Base(),"o0",6)
196 << " ir=" << pstat.IndicatorInt() << "," << pstat.IndicatorRem();
197 if (cntl.Lam() > 0) sos << " " << RosPrintf(cntl.Lam(),"d",3);
198 else sos << " -";
199 uint16_t aload;
200 uint16_t astart;
201 vector<uint16_t> code;
202 bool bootok = cntl.BootCode(0, code, aload, astart);
203 sos << " " << (bootok ? "y" : "n");
204 sos << endl;
205 }
206 }
207
208 args.AppendResultLines(sos);
209 return kOK;
210}
211
212//------------------------------------------+-----------------------------------
214
216{
217 Tcl_Obj* rlist = Tcl_NewListObj(0,nullptr);
218 for (size_t i=0; i<Obj().NCpu(); i++) {
219 string ccmd = string("cpu") + to_string(i);
220 RtclOPtr pele(Tcl_NewStringObj(ccmd.data(), ccmd.length()));
221 Tcl_ListObjAppendElement(nullptr, rlist, pele);
222 }
223 return rlist;
224}
225
226
227} // end namespace Retro
FIXME_docs.
Definition: RtclArgs.hpp:41
void AppendResultLines(const std::string &str)
FIXME_docs.
Definition: RtclArgs.cpp:484
bool GetArg(const char *name, Tcl_Obj *&pval)
FIXME_docs.
Definition: RtclArgs.cpp:114
int Quit(const std::string &str)
FIXME_docs.
Definition: RtclArgs.ipp:157
void SetResult(const std::string &str)
FIXME_docs.
Definition: RtclArgs.ipp:76
Tcl_Interp * Interp() const
FIXME_docs.
Definition: RtclArgs.ipp:28
bool AllDone()
FIXME_docs.
Definition: RtclArgs.cpp:447
void AddMeth(const std::string &name, methfo_t &&methfo)
FIXME_docs.
bool GetArgsDump(RtclArgs &args, int &detail)
FIXME_docs.
RtclProxyBase * FindProxy(const std::string &type, const std::string &name)
FIXME_docs.
static RtclContext & Find(Tcl_Interp *interp)
FIXME_docs.
int M_get(RtclArgs &args)
FIXME_docs.
Definition: RtclGetList.cpp:73
void Add(const std::string &name, get_uptr_t &&upget)
FIXME_docs.
Definition: RtclGetList.cpp:52
Implemenation (inline) of RtclOPtr.
Definition: RtclOPtr.hpp:23
Implemenation (all inline) of class RtclProxyOwned.
const std::shared_ptr< Rw11 > & ObjSPtr()
FIXME_docs.
const std::shared_ptr< TO > & ObjSPtr()
FIXME_docs.
TO & Obj()
FIXME_docs.
int M_start(RtclArgs &args)
FIXME_docs.
Definition: RtclRw11.cpp:148
int M_set(RtclArgs &args)
FIXME_docs.
Definition: RtclRw11.cpp:138
virtual int ClassCmdConfig(RtclArgs &args)
FIXME_docs.
Definition: RtclRw11.cpp:84
RtclRw11(Tcl_Interp *interp, const char *name)
Constructor.
Definition: RtclRw11.cpp:53
~RtclRw11()
Destructor.
Definition: RtclRw11.cpp:78
Tcl_Obj * CpuCommands()
FIXME_docs.
Definition: RtclRw11.cpp:215
int M_default(RtclArgs &args)
FIXME_docs.
Definition: RtclRw11.cpp:174
int M_dump(RtclArgs &args)
FIXME_docs.
Definition: RtclRw11.cpp:159
int M_get(RtclArgs &args)
FIXME_docs.
Definition: RtclRw11.cpp:128
std::shared_ptr< RlinkServer > fspServ
Definition: RtclRw11.hpp:52
RtclGetList fGets
Definition: RtclRw11.hpp:53
RtclSetList fSets
Definition: RtclRw11.hpp:54
void Add(const std::string &name, set_uptr_t &&upset)
FIXME_docs.
Definition: RtclSetList.cpp:52
int M_set(RtclArgs &args)
FIXME_docs.
Definition: RtclSetList.cpp:73
FIXME_docs.
Definition: Rw11Cntl.hpp:42
const Rw11Probe & ProbeStatus() const
FIXME_docs.
Definition: Rw11Cntl.ipp:136
const std::string & Type() const
FIXME_docs.
Definition: Rw11Cntl.ipp:72
uint16_t Base() const
FIXME_docs.
Definition: Rw11Cntl.ipp:88
int Lam() const
FIXME_docs.
Definition: Rw11Cntl.ipp:96
virtual bool BootCode(size_t unit, std::vector< uint16_t > &code, uint16_t &aload, uint16_t &astart)
FIXME_docs.
Definition: Rw11Cntl.cpp:93
const std::string & Name() const
FIXME_docs.
Definition: Rw11Cntl.ipp:80
void Setup(size_t ind, uint16_t base, uint16_t ibase)
FIXME_docs.
Definition: Rw11CpuW11a.cpp:47
FIXME_docs.
Definition: Rw11Cpu.hpp:66
uint16_t Base() const
FIXME_docs.
Definition: Rw11Cpu.ipp:78
void ListCntl(std::vector< std::string > &list) const
FIXME_docs.
Definition: Rw11Cpu.cpp:292
Rw11Cntl & Cntl(const std::string &name) const
FIXME_docs.
Definition: Rw11Cpu.cpp:304
const std::string & Type() const
FIXME_docs.
Definition: Rw11Cpu.ipp:62
static void SetDefaultScheme(const std::string &scheme)
FIXME_docs.
static const std::string & DefaultScheme()
FIXME_docs.
FIXME_docs.
Definition: Rw11.hpp:31
size_t NCpu() const
FIXME_docs.
Definition: Rw11.ipp:54
void Start()
FIXME_docs.
Definition: Rw11.cpp:101
void AddCpu(const std::shared_ptr< Rw11Cpu > &spcpu)
FIXME_docs.
Definition: Rw11.cpp:75
void SetServer(const std::shared_ptr< RlinkServer > &spserv)
FIXME_docs.
Definition: Rw11.cpp:64
virtual void Dump(std::ostream &os, int ind=0, const char *text=0, int detail=0) const
FIXME_docs.
Definition: Rw11.cpp:117
bool IsStarted() const
FIXME_docs.
Definition: Rw11.ipp:62
RosPrintfS< bool > RosPrintf(bool value, const char *form=0, int width=0, int prec=0)
Creates a print object for the formatted output of a bool value.
Definition: RosPrintf.ipp:38
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47
static const int kERR
Definition: RtclBvi.cpp:38
static const int kOK
Definition: RtclBvi.cpp:37
FIXME_docs.
Definition: Rw11Probe.hpp:23
char IndicatorInt() const
FIXME_docs.
Definition: Rw11Probe.cpp:63
char IndicatorRem() const
FIXME_docs.
Definition: Rw11Probe.cpp:73