OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.6/] [tools/] [src/] [librw11/] [Rw11CntlPC11.cpp] - Blame information for rev 40

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 wfjm
// $Id: Rw11CntlPC11.cpp 515 2013-05-04 17:28:59Z mueller $
2
//
3
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
//
5
// This program is free software; you may redistribute and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, either version 2, or at your option any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
// for complete details.
13
// 
14
// Revision History: 
15
// Date         Rev Version  Comment
16
// 2013-05-03   515   1.0    Initial version
17
// ---------------------------------------------------------------------------
18
 
19
/*!
20
  \file
21
  \version $Id: Rw11CntlPC11.cpp 515 2013-05-04 17:28:59Z mueller $
22
  \brief   Implemenation of Rw11CntlPC11.
23
*/
24
 
25
#include "boost/bind.hpp"
26
#include "boost/foreach.hpp"
27
#define foreach_ BOOST_FOREACH
28
 
29
#include "librtools/RosFill.hpp"
30
#include "librtools/RosPrintBvi.hpp"
31
#include "librtools/RosPrintf.hpp"
32
#include "librtools/Rexception.hpp"
33
#include "librtools/RlogMsg.hpp"
34
 
35
#include "Rw11CntlPC11.hpp"
36
 
37
using namespace std;
38
 
39
/*!
40
  \class Retro::Rw11CntlPC11
41
  \brief FIXME_docs
42
*/
43
 
44
// all method definitions in namespace Retro
45
namespace Retro {
46
 
47
//------------------------------------------+-----------------------------------
48
// constants definitions
49
 
50
const uint16_t Rw11CntlPC11::kIbaddr;
51
const int      Rw11CntlPC11::kLam;
52
 
53
const uint16_t Rw11CntlPC11::kRCSR;
54
const uint16_t Rw11CntlPC11::kRBUF;
55
const uint16_t Rw11CntlPC11::kPCSR;
56
const uint16_t Rw11CntlPC11::kPBUF;
57
 
58
const uint16_t Rw11CntlPC11::kUnit_PR;
59
const uint16_t Rw11CntlPC11::kUnit_PP;
60
 
61
const uint16_t Rw11CntlPC11::kProbeOff;
62
const bool     Rw11CntlPC11::kProbeInt;
63
const bool     Rw11CntlPC11::kProbeRem;
64
 
65
const uint16_t Rw11CntlPC11::kRCSR_M_ERROR;
66
const uint16_t Rw11CntlPC11::kPCSR_M_ERROR;
67
const uint16_t Rw11CntlPC11::kPBUF_M_RBUSY;
68
const uint16_t Rw11CntlPC11::kPBUF_M_PVAL;
69
const uint16_t Rw11CntlPC11::kPBUF_M_BUF;
70
 
71
//------------------------------------------+-----------------------------------
72
//! Default constructor
73
 
74
Rw11CntlPC11::Rw11CntlPC11()
75
  : Rw11CntlBase<Rw11UnitPC11,2>("pc11"),
76
    fPC_pbuf(0)
77
{
78
  // must here because Unit have a back-pointer (not available at Rw11CntlBase)
79
  for (size_t i=0; i<NUnit(); i++) {
80
    fspUnit[i].reset(new Rw11UnitPC11(this, i));
81
  }
82
}
83
 
84
//------------------------------------------+-----------------------------------
85
//! Destructor
86
 
87
Rw11CntlPC11::~Rw11CntlPC11()
88
{}
89
 
90
//------------------------------------------+-----------------------------------
91
//! FIXME_docs
92
 
93
void Rw11CntlPC11::Config(const std::string& name, uint16_t base, int lam)
94
{
95
  ConfigCntl(name, base, lam, kProbeOff, kProbeInt, kProbeRem);
96
  return;
97
}
98
 
99
//------------------------------------------+-----------------------------------
100
//! FIXME_docs
101
 
102
void Rw11CntlPC11::Start()
103
{
104
  if (fStarted || fLam<0 || !fEnable || !fProbe.Found())
105
    throw Rexception("Rw11CntlPC11::Start",
106
                     "Bad state: started, no lam, not enable, not found");
107
 
108
  // setup primary info clist
109
  fPrimClist.Clear();
110
  Cpu().AddIbrb(fPrimClist, fBase);
111
  fPC_pbuf = Cpu().AddRibr(fPrimClist, fBase+kPBUF);
112
 
113
  // add attn handler
114
  Server().AddAttnHandler(boost::bind(&Rw11CntlPC11::AttnHandler, this, _1),
115
                          uint16_t(1)<<fLam, (void*)this);
116
 
117
  fStarted = true;
118
  return;
119
}
120
 
121
//------------------------------------------+-----------------------------------
122
//! FIXME_docs
123
 
124
bool Rw11CntlPC11::BootCode(size_t unit, std::vector<uint16_t>& code,
125
                            uint16_t& aload, uint16_t& astart)
126
{
127
  uint16_t kBOOT_START = 0017476;
128
  uint16_t bootcode[] = {      // papertape lda loader, from dec-11-l2pc-po
129
    0000000,                   // C000:   halt
130
    0010706,                   // astart: mov     pc,sp
131
    0024646,                   //         cmp     -(sp),-(sp)
132
    0010705,                   //         mov     pc,r5
133
    0062705, 0000112,          //         add     #000112,r5
134
    0005001,                   //         clr     r1
135
    0013716, 0177570,          // B000:   mov     @#cp.dsr,(sp)
136
    0006016,                   //         ror     (sp)
137
    0103402,                   //         bcs     B001
138
    0005016,                   //         clr     (sp)
139
    0000403,                   //         br      B002
140
    0006316,                   // B001:   asl     (sp)
141
    0001001,                   //         bne     B002
142
    0010116,                   //         mov     r1,(sp)
143
    0005000,                   // B002:   clr     r0
144
    0004715,                   //         jsr     pc,(r5)
145
    0105303,                   //         decb    r3
146
    0001374,                   //         bne     B002
147
    0004715,                   //         jsr     pc,(r5)
148
    0004767, 0000074,          //         jsr     pc,R000
149
    0010402,                   //         mov     r4,r2
150
    0162702, 0000004,          //         sub     #000004,r2
151
    0022702, 0000002,          //         cmp     #000002,r2
152
    0001441,                   //         beq     B007
153
    0004767, 0000054,          //         jsr     pc,R000
154
    0061604,                   //         add     (sp),r4
155
    0010401,                   //         mov     r4,r1
156
    0004715,                   // B003:   jsr     pc,(r5)
157
    0002004,                   //         bge     B005
158
    0105700,                   //         tstb    r0
159
    0001753,                   //         beq     B002
160
    0000000,                   // B004:   halt
161
    0000751,                   //         br      B002
162
    0110321,                   // B005:   movb    r3,(r1)+
163
    0000770,                   //         br      B003
164
    0016703, 0000152,          // ldchr:  mov     p.prcs,r3
165
    0105213,                   //         incb    (r3)
166
    0105713,                   // B006:   tstb    (r3)
167
    0100376,                   //         bpl     B006
168
    0116303, 0000002,          //         movb    000002(r3),r3
169
    0060300,                   //         add     r3,r0
170
    0042703, 0177400,          //         bic     #177400,r3
171
    0005302,                   //         dec     r2
172
    0000207,                   //         rts     pc
173
    0012667, 0000046,          // R000:   mov     (sp)+,D000
174
    0004715,                   //         jsr     pc,(r5)
175
    0010304,                   //         mov     r3,r4
176
    0004715,                   //         jsr     pc,(r5)
177
    0000303,                   //         swap    r3
178
    0050304,                   //         bis     r3,r4
179
    0016707, 0000030,          //         mov     D000,pc
180
    0004767, 0177752,          // B007:   jsr     pc,R000
181
    0004715,                   //         jsr     pc,(r5)
182
    0105700,                   //         tstb    r0
183
    0001342,                   //         bne     B004
184
    0006204,                   //         asr     r4
185
    0103002,                   //         bcc     B008
186
    0000000,                   //         halt
187
    0000700,                   //         br      B000
188
    0006304,                   // B008:   asl     r4
189
    0061604,                   //         add     (sp),r4
190
    0000114,                   //         jmp     (r4)
191
    0000000,                   // D000:   .word   000000
192
    0012767, 0000352, 0000020, // L000:   mov     #000352,B009+2
193
    0012767, 0000765, 0000034, //         mov     #000765,D001
194
    0000167, 0177532,          //         jmp     C000
195
    0016701, 0000026,          // bstart: mov     p.prcs,r1
196
    0012702, 0000352,          // B009:   mov     #000352,r2
197
    0005211,                   //         inc     (r1)
198
    0105711,                   // B010:   tstb    (r1)
199
    0100376,                   //         bpl     B010
200
    0116162, 0000002, 0157400, //         movb    000002(r1),157400(r2)
201
    0005267, 0177756,          //         inc     B009+2
202
    0000765,                   // D001:   br      B009
203
    0177550                    // p.prcs: .word   177550
204
  };
205
 
206
  code.clear();
207
  foreach_ (uint16_t& w, bootcode) code.push_back(w);
208
  aload  = kBOOT_START;
209
  astart = kBOOT_START+2;
210
  return true;
211
}
212
 
213
//------------------------------------------+-----------------------------------
214
//! FIXME_docs
215
 
216
void Rw11CntlPC11::UnitSetup(size_t ind)
217
{
218
  Rw11UnitPC11& unit = *fspUnit[ind];
219
  SetOnline(ind, unit.Virt());              // online if stream attached
220
  return;
221
}
222
 
223
//------------------------------------------+-----------------------------------
224
//! FIXME_docs
225
 
226
void Rw11CntlPC11::Dump(std::ostream& os, int ind, const char* text) const
227
{
228
  RosFill bl(ind);
229
  os << bl << (text?text:"--") << "Rw11CntlPC11 @ " << this << endl;
230
  os << bl << "  fPC_pbuf:        " << fPC_pbuf << endl;
231
 
232
  Rw11CntlBase<Rw11UnitPC11,2>::Dump(os, ind, " ^");
233
  return;
234
}
235
 
236
//------------------------------------------+-----------------------------------
237
//! FIXME_docs
238
 
239
int Rw11CntlPC11::AttnHandler(const RlinkServer::AttnArgs& args)
240
{
241
  RlinkCommandList* pclist;
242
  size_t off;
243
 
244
  GetPrimInfo(args, pclist, off);
245
 
246
  uint16_t pbuf = (*pclist)[off+fPC_pbuf].Data();
247
  bool pval     = pbuf & kPBUF_M_PVAL;
248
  bool rbusy    = pbuf & kPBUF_M_RBUSY;
249
  uint8_t ochr  = pbuf & kPBUF_M_BUF;
250
 
251
  if (fTraceLevel>0) {
252
    RlogMsg lmsg(LogFile());
253
    lmsg << "-I PC11." << Name()
254
         << " pbuf=" << RosPrintBvi(pbuf,8)
255
         << " pval=" << pval
256
         << " rbusy=" << rbusy;
257
    if (pval) {
258
      lmsg << " char=";
259
      if (ochr>=040 && ochr<0177) {
260
        lmsg << "'" << char(ochr) << "'";
261
      } else {
262
        lmsg << RosPrintBvi(ochr,8);
263
      }
264
    }
265
  }
266
 
267
  if (pval) {
268
    RerrMsg emsg;
269
    bool rc = fspUnit[kUnit_PP]->VirtWrite(&ochr, 1, emsg);
270
    if (!rc) {
271
      RlogMsg lmsg(LogFile());
272
      lmsg << emsg;
273
      SetOnline(1, false);
274
    }
275
  }
276
 
277
  if (rbusy) {
278
    uint8_t ichr = 0;
279
    RerrMsg emsg;
280
    int irc = fspUnit[kUnit_PR]->VirtRead(&ichr, 1, emsg);
281
    if (irc < 0) {
282
      RlogMsg lmsg(LogFile());
283
      lmsg << emsg;
284
    }
285
    if (irc <= 0) {
286
      SetOnline(0, false);
287
    } else {
288
      RlinkCommandList clist;
289
      Cpu().AddWibr(clist, fBase+kRBUF, ichr);
290
      Server().Exec(clist);
291
    }
292
  }
293
 
294
  return 0;
295
}
296
 
297
//------------------------------------------+-----------------------------------
298
//! FIXME_docs
299
 
300
void Rw11CntlPC11::SetOnline(size_t ind, bool online)
301
{
302
  Rw11Cpu& cpu  = Cpu();
303
  RlinkCommandList clist;
304
  cpu.AddIbrb(clist, fBase);
305
  if (ind == kUnit_PR) {                    // reader on/offline
306
    uint16_t rcsr  = online ? 0 : kRCSR_M_ERROR;
307
    cpu.AddWibr(clist, fBase+kRCSR, rcsr);
308
  } else {                                  // puncher on/offline
309
    uint16_t pcsr  = online ? 0 : kPCSR_M_ERROR;
310
    cpu.AddWibr(clist, fBase+kPCSR, pcsr);
311
  }
312
  Server().Exec(clist);
313
  return;
314
}
315
 
316
} // end namespace Retro

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.