1 /* pdp11_rk.c: RK11/RKV11 cartridge disk simulator
3 Copyright (c) 1993-2005, Robert M Supnik
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the "Software"),
7 to deal in the Software without restriction, including without limitation
8 the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 and/or sell copies of the Software, and to permit persons to whom the
10 Software is furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of Robert M Supnik shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from Robert M Supnik.
26 rk RK11/RKV11/RK05 cartridge disk
28 16-Aug-05 RMS Fixed C++ declaration and cast problems
29 07-Jul-05 RMS Removed extraneous externs
30 30-Sep-04 RMS Revised Unibus interface
31 24-Jan-04 RMS Added increment inhibit, overrun detection, formatting
32 29-Dec-03 RMS Added RKV11 support
33 29-Sep-02 RMS Added variable address support to bootstrap
34 Added vector change/display support
35 Revised mapping mnemonics
37 26-Jan-02 RMS Revised bootstrap to conform to M9312
38 06-Jan-02 RMS Revised enable/disable support
39 30-Nov-01 RMS Added read only unit, extended SET/SHOW support
40 24-Nov-01 RMS Converted FLG to array
41 09-Nov-01 RMS Added bus map support
42 07-Sep-01 RMS Revised device disable and interrupt mechanisms
43 26-Apr-01 RMS Added device enable/disable support
44 25-Mar-01 RMS Fixed block fill calculation
45 15-Feb-01 RMS Corrected bootstrap string
46 29-Jun-96 RMS Added unit disable support
48 The RK11 is an eight drive cartridge disk subsystem. An RK05 drive
49 consists of 203 cylinders, each with 2 surfaces containing 12 sectors
52 The most complicated part of the RK11 controller is the concept of
53 interrupt "polling". While only one read or write can occur at a
54 time, the controller supports multiple seeks. When a seek completes,
55 if done is set the drive attempts to interrupt. If an interrupt is
56 already pending, the interrupt is "queued" until it can be processed.
57 When an interrupt occurs, RKDS<15:13> is loaded with the number of the
60 To implement this structure, and to assure that read/write interrupts
61 take priority over seek interrupts, the controller contains an
62 interrupt queue, rkintq, with a bit for a controller interrupt and
63 then one for each drive. In addition, the drive number of the last
64 non-seeking drive is recorded in last_drv.
67 #include "pdp11_defs.h"
71 #define RK_NUMWD 256 /* words/sector */
72 #define RK_NUMSC 12 /* sectors/surface */
73 #define RK_NUMSF 2 /* surfaces/cylinder */
74 #define RK_NUMCY 203 /* cylinders/drive */
75 #define RK_NUMTR (RK_NUMCY * RK_NUMSF) /* tracks/drive */
76 #define RK_NUMDR 8 /* drives/controller */
78 #define RK_SIZE (RK_NUMCY * RK_NUMSF * RK_NUMSC * RK_NUMWD)
80 #define RK_CTLI 1 /* controller int */
81 #define RK_SCPI(x) (2u << (x)) /* drive int */
82 #define RK_MAXFR (1 << 16) /* max transfer */
84 /* Flags in the unit flags word */
86 #define UNIT_V_HWLK (UNIT_V_UF + 0) /* hwre write lock */
87 #define UNIT_V_SWLK (UNIT_V_UF + 1) /* swre write lock */
88 #define UNIT_HWLK (1u << UNIT_V_HWLK)
89 #define UNIT_SWLK (1u << UNIT_V_SWLK)
90 #define UNIT_WPRT (UNIT_HWLK|UNIT_SWLK|UNIT_RO) /* write prot */
92 /* Parameters in the unit descriptor */
94 #define CYL u3 /* current cylinder */
95 #define FUNC u4 /* function */
99 #define RKDS_SC 0000017 /* sector counter */
100 #define RKDS_ON_SC 0000020 /* on sector */
101 #define RKDS_WLK 0000040 /* write locked */
102 #define RKDS_RWS 0000100 /* rd/wr/seek ready */
103 #define RKDS_RDY 0000200 /* drive ready */
104 #define RKDS_SC_OK 0000400 /* SC valid */
105 #define RKDS_INC 0001000 /* seek incomplete */
106 #define RKDS_UNSAFE 0002000 /* unsafe */
107 #define RKDS_RK05 0004000 /* RK05 */
108 #define RKDS_PWR 0010000 /* power low */
109 #define RKDS_ID 0160000 /* drive ID */
114 #define RKER_WCE 0000001 /* write check */
115 #define RKER_CSE 0000002 /* checksum */
116 #define RKER_NXS 0000040 /* nx sector */
117 #define RKER_NXC 0000100 /* nx cylinder */
118 #define RKER_NXD 0000200 /* nx drive */
119 #define RKER_TE 0000400 /* timing error */
120 #define RKER_DLT 0001000 /* data late */
121 #define RKER_NXM 0002000 /* nx memory */
122 #define RKER_PGE 0004000 /* programming error */
123 #define RKER_SKE 0010000 /* seek error */
124 #define RKER_WLK 0020000 /* write lock */
125 #define RKER_OVR 0040000 /* overrun */
126 #define RKER_DRE 0100000 /* drive error */
127 #define RKER_IMP 0177743 /* implemented */
128 #define RKER_SOFT (RKER_WCE+RKER_CSE) /* soft errors */
129 #define RKER_HARD 0177740 /* hard errors */
133 #define RKCS_M_FUNC 0000007 /* function */
134 #define RKCS_CTLRESET 0
140 #define RKCS_DRVRESET 6
142 #define RKCS_V_FUNC 1
143 #define RKCS_MEX 0000060 /* memory extension */
145 #define RKCS_SSE 0000400 /* stop on soft err */
146 #define RKCS_FMT 0002000 /* format */
147 #define RKCS_INH 0004000 /* inhibit increment */
148 #define RKCS_SCP 0020000 /* search complete */
149 #define RKCS_HERR 0040000 /* hard error */
150 #define RKCS_ERR 0100000 /* error */
151 #define RKCS_REAL 0026776 /* kept here */
152 #define RKCS_RW 0006576 /* read/write */
153 #define GET_FUNC(x) (((x) >> RKCS_V_FUNC) & RKCS_M_FUNC)
157 #define RKDA_V_SECT 0 /* sector */
158 #define RKDA_M_SECT 017
159 #define RKDA_V_TRACK 4 /* track */
160 #define RKDA_M_TRACK 0777
161 #define RKDA_V_CYL 5 /* cylinder */
162 #define RKDA_M_CYL 0377
163 #define RKDA_V_DRIVE 13 /* drive */
164 #define RKDA_M_DRIVE 07
165 #define RKDA_DRIVE (RKDA_M_DRIVE << RKDA_V_DRIVE)
166 #define GET_SECT(x) (((x) >> RKDA_V_SECT) & RKDA_M_SECT)
167 #define GET_CYL(x) (((x) >> RKDA_V_CYL) & RKDA_M_CYL)
168 #define GET_TRACK(x) (((x) >> RKDA_V_TRACK) & RKDA_M_TRACK)
169 #define GET_DRIVE(x) (((x) >> RKDA_V_DRIVE) & RKDA_M_DRIVE)
170 #define GET_DA(x) ((GET_TRACK (x) * RK_NUMSC) + GET_SECT (x))
174 #define RKBA_IMP 0177776 /* implemented */
177 #define MAX(x,y) (((x) > (y))? (x): (y))
179 extern uint16
*M
; /* memory */
180 extern int32 int_req
[IPL_HLVL
];
182 uint16
*rkxb
= NULL
; /* xfer buffer */
183 int32 rkcs
= 0; /* control/status */
184 int32 rkds
= 0; /* drive status */
185 int32 rkba
= 0; /* memory address */
186 int32 rkda
= 0; /* disk address */
187 int32 rker
= 0; /* error status */
188 int32 rkwc
= 0; /* word count */
189 int32 rkintq
= 0; /* interrupt queue */
190 int32 last_drv
= 0; /* last r/w drive */
191 int32 rk_stopioe
= 1; /* stop on error */
192 int32 rk_swait
= 10; /* seek time */
193 int32 rk_rwait
= 10; /* rotate time */
196 t_stat
rk_rd (int32
*data
, int32 PA
, int32 access
);
197 t_stat
rk_wr (int32 data
, int32 PA
, int32 access
);
198 int32
rk_inta (void);
199 t_stat
rk_svc (UNIT
*uptr
);
200 t_stat
rk_reset (DEVICE
*dptr
);
202 void rk_set_done (int32 error
);
203 void rk_clr_done (void);
204 t_stat
rk_boot (int32 unitno
, DEVICE
*dptr
);
206 /* RK11 data structures
208 rk_dev RK device descriptor
210 rk_reg RK register list
211 rk_mod RK modifier list
215 IOBA_RK
, IOLN_RK
, &rk_rd
, &rk_wr
,
216 1, IVCL (RK
), VEC_RK
, { &rk_inta
}
220 { UDATA (&rk_svc
, UNIT_FIX
+UNIT_ATTABLE
+UNIT_DISABLE
+
221 UNIT_ROABLE
, RK_SIZE
) },
222 { UDATA (&rk_svc
, UNIT_FIX
+UNIT_ATTABLE
+UNIT_DISABLE
+
223 UNIT_ROABLE
, RK_SIZE
) },
224 { UDATA (&rk_svc
, UNIT_FIX
+UNIT_ATTABLE
+UNIT_DISABLE
+
225 UNIT_ROABLE
, RK_SIZE
) },
226 { UDATA (&rk_svc
, UNIT_FIX
+UNIT_ATTABLE
+UNIT_DISABLE
+
227 UNIT_ROABLE
, RK_SIZE
) },
228 { UDATA (&rk_svc
, UNIT_FIX
+UNIT_ATTABLE
+UNIT_DISABLE
+
229 UNIT_ROABLE
, RK_SIZE
) },
230 { UDATA (&rk_svc
, UNIT_FIX
+UNIT_ATTABLE
+UNIT_DISABLE
+
231 UNIT_ROABLE
, RK_SIZE
) },
232 { UDATA (&rk_svc
, UNIT_FIX
+UNIT_ATTABLE
+UNIT_DISABLE
+
233 UNIT_ROABLE
, RK_SIZE
) },
234 { UDATA (&rk_svc
, UNIT_FIX
+UNIT_ATTABLE
+UNIT_DISABLE
+
235 UNIT_ROABLE
, RK_SIZE
) }
239 { ORDATA (RKCS
, rkcs
, 16) },
240 { ORDATA (RKDA
, rkda
, 16) },
241 { ORDATA (RKBA
, rkba
, 16) },
242 { ORDATA (RKWC
, rkwc
, 16) },
243 { ORDATA (RKDS
, rkds
, 16) },
244 { ORDATA (RKER
, rker
, 16) },
245 { ORDATA (INTQ
, rkintq
, 9) },
246 { ORDATA (DRVN
, last_drv
, 3) },
247 { FLDATA (INT
, IREQ (RK
), INT_V_RK
) },
248 { FLDATA (ERR
, rkcs
, CSR_V_ERR
) },
249 { FLDATA (DONE
, rkcs
, CSR_V_DONE
) },
250 { FLDATA (IE
, rkcs
, CSR_V_IE
) },
251 { DRDATA (STIME
, rk_swait
, 24), PV_LEFT
},
252 { DRDATA (RTIME
, rk_rwait
, 24), PV_LEFT
},
253 { FLDATA (STOP_IOE
, rk_stopioe
, 0) },
254 { ORDATA (DEVADDR
, rk_dib
.ba
, 32), REG_HRO
},
255 { ORDATA (DEVVEC
, rk_dib
.vec
, 16), REG_HRO
},
260 { UNIT_HWLK
, 0, "write enabled", "WRITEENABLED", NULL
},
261 { UNIT_HWLK
, UNIT_HWLK
, "write locked", "LOCKED", NULL
},
262 { MTAB_XTD
|MTAB_VDV
, 020, "ADDRESS", "ADDRESS",
263 &set_addr
, &show_addr
, NULL
},
264 { MTAB_XTD
|MTAB_VDV
, 0, "VECTOR", "VECTOR",
265 &set_vec
, &show_vec
, NULL
},
270 "RK", rk_unit
, rk_reg
, rk_mod
,
271 RK_NUMDR
, 8, 24, 1, 8, 16,
272 NULL
, NULL
, &rk_reset
,
273 &rk_boot
, NULL
, NULL
,
274 &rk_dib
, DEV_DISABLE
| DEV_UBUS
| DEV_Q18
277 /* I/O dispatch routine, I/O addresses 17777400 - 17777416
279 17777400 RKDS read only, constructed from "id'd drive"
280 plus current drive status flags
281 17777402 RKER read only, set as operations progress,
282 cleared by INIT or CONTROL RESET
283 17777404 RKCS read/write
284 17777406 RKWC read/write
285 17777410 RKBA read/write
286 17777412 RKDA read/write
287 17777414 RKMR read/write, unimplemented
288 17777416 RKDB read only, unimplemented
291 t_stat
rk_rd (int32
*data
, int32 PA
, int32 access
)
295 switch ((PA
>> 1) & 07) { /* decode PA<3:1> */
297 case 0: /* RKDS: read only */
298 rkds
= (rkds
& RKDS_ID
) | RKDS_RK05
| RKDS_SC_OK
|
299 (rand () % RK_NUMSC
); /* random sector */
300 uptr
= rk_dev
.units
+ GET_DRIVE (rkda
); /* selected unit */
301 if (uptr
->flags
& UNIT_ATT
) /* attached? */
302 rkds
= rkds
| RKDS_RDY
;
303 if (!sim_is_active (uptr
)) /* idle? */
304 rkds
= rkds
| RKDS_RWS
;
305 if (uptr
->flags
& UNIT_WPRT
) rkds
= rkds
| RKDS_WLK
;
306 if (GET_SECT (rkda
) == (rkds
& RKDS_SC
)) rkds
= rkds
| RKDS_ON_SC
;
310 case 1: /* RKER: read only */
311 *data
= rker
& RKER_IMP
;
315 rkcs
= rkcs
& RKCS_REAL
;
316 if (rker
) rkcs
= rkcs
| RKCS_ERR
; /* update err flags */
317 if (rker
& RKER_HARD
) rkcs
= rkcs
| RKCS_HERR
;
326 *data
= rkba
& RKBA_IMP
;
339 t_stat
rk_wr (int32 data
, int32 PA
, int32 access
)
341 switch ((PA
>> 1) & 07) { /* decode PA<3:1> */
343 case 0: /* RKDS: read only */
346 case 1: /* RKER: read only */
350 rkcs
= rkcs
& RKCS_REAL
;
351 if (access
== WRITEB
) data
= (PA
& 1)?
352 (rkcs
& 0377) | (data
<< 8): (rkcs
& ~0377) | data
;
353 if ((data
& CSR_IE
) == 0) { /* int disable? */
354 rkintq
= 0; /* clr int queue */
355 CLR_INT (RK
); /* clr int request */
357 else if ((rkcs
& (CSR_DONE
+ CSR_IE
)) == CSR_DONE
) {
358 rkintq
= rkintq
| RK_CTLI
; /* queue ctrl int */
359 SET_INT (RK
); /* set int request */
361 rkcs
= (rkcs
& ~RKCS_RW
) | (data
& RKCS_RW
);
362 if ((rkcs
& CSR_DONE
) && (data
& CSR_GO
)) /* new function? */
367 if (access
== WRITEB
) data
= (PA
& 1)?
368 (rkwc
& 0377) | (data
<< 8): (rkwc
& ~0377) | data
;
373 if (access
== WRITEB
) data
= (PA
& 1)?
374 (rkba
& 0377) | (data
<< 8): (rkba
& ~0377) | data
;
375 rkba
= data
& RKBA_IMP
;
379 if ((rkcs
& CSR_DONE
) == 0) return SCPE_OK
;
380 if (access
== WRITEB
) data
= (PA
& 1)?
381 (rkda
& 0377) | (data
<< 8): (rkda
& ~0377) | data
;
390 /* Initiate new function */
394 int32 i
, sect
, cyl
, func
;
397 func
= GET_FUNC (rkcs
); /* get function */
398 if (func
== RKCS_CTLRESET
) { /* control reset? */
399 rker
= 0; /* clear errors */
403 rkintq
= 0; /* clr int queue */
404 CLR_INT (RK
); /* clr int request */
407 rker
= rker
& ~RKER_SOFT
; /* clear soft errors */
408 if (rker
== 0) rkcs
= rkcs
& ~RKCS_ERR
; /* redo summary */
409 rkcs
= rkcs
& ~RKCS_SCP
; /* clear sch compl*/
410 rk_clr_done (); /* clear done */
411 last_drv
= GET_DRIVE (rkda
); /* get drive no */
412 uptr
= rk_dev
.units
+ last_drv
; /* select unit */
413 if (uptr
->flags
& UNIT_DIS
) { /* not present? */
414 rk_set_done (RKER_NXD
);
417 if (((uptr
->flags
& UNIT_ATT
) == 0) || /* not att or busy? */
418 sim_is_active (uptr
)) {
419 rk_set_done (RKER_DRE
);
422 if ((rkcs
& RKCS_FMT
) && /* format and */
423 (func
!= RKCS_READ
) && (func
!= RKCS_WRITE
)) { /* not read or write? */
424 rk_set_done (RKER_PGE
);
427 if ((func
== RKCS_WRITE
) && /* write and locked? */
428 (uptr
->flags
& UNIT_WPRT
)) {
429 rk_set_done (RKER_WLK
);
432 if (func
== RKCS_WLK
) { /* write lock? */
433 uptr
->flags
= uptr
->flags
| UNIT_SWLK
;
437 if (func
== RKCS_DRVRESET
) { /* drive reset? */
438 uptr
->flags
= uptr
->flags
& ~UNIT_SWLK
;
443 sect
= GET_SECT (rkda
);
444 cyl
= GET_CYL (rkda
);
446 if (sect
>= RK_NUMSC
) { /* bad sector? */
447 rk_set_done (RKER_NXS
);
450 if (cyl
>= RK_NUMCY
) { /* bad cyl? */
451 rk_set_done (RKER_NXC
);
454 i
= abs (cyl
- uptr
->CYL
) * rk_swait
; /* seek time */
455 if (func
== RKCS_SEEK
) { /* seek? */
456 rk_set_done (0); /* set done */
457 sim_activate (uptr
, MAX (RK_MIN
, i
)); /* schedule */
459 else sim_activate (uptr
, i
+ rk_rwait
);
460 uptr
->FUNC
= func
; /* save func */
461 uptr
->CYL
= cyl
; /* put on cylinder */
465 /* Service unit timeout
467 If seek in progress, complete seek command
468 Else complete data transfer command
470 The unit control block contains the function and disk address for
474 t_stat
rk_svc (UNIT
*uptr
)
476 int32 i
, drv
, err
, awc
, wc
, cma
, cda
, t
;
477 int32 da
, cyl
, track
, sect
;
481 drv
= (int32
) (uptr
- rk_dev
.units
); /* get drv number */
482 if (uptr
->FUNC
== RKCS_SEEK
) { /* seek */
483 rkcs
= rkcs
| RKCS_SCP
; /* set seek done */
484 if (rkcs
& CSR_IE
) { /* ints enabled? */
485 rkintq
= rkintq
| RK_SCPI (drv
); /* queue request */
486 if (rkcs
& CSR_DONE
) SET_INT (RK
);
489 rkintq
= 0; /* clear queue */
490 CLR_INT (RK
); /* clear interrupt */
495 if ((uptr
->flags
& UNIT_ATT
) == 0) { /* attached? */
496 rk_set_done (RKER_DRE
);
497 return IORETURN (rk_stopioe
, SCPE_UNATT
);
499 sect
= GET_SECT (rkda
); /* get sector, cyl */
500 cyl
= GET_CYL (rkda
);
501 if (sect
>= RK_NUMSC
) { /* bad sector? */
502 rk_set_done (RKER_NXS
);
505 if (cyl
>= RK_NUMCY
) { /* bad cyl? */
506 rk_set_done (RKER_NXC
);
509 ma
= ((rkcs
& RKCS_MEX
) << (16 - RKCS_V_MEX
)) | rkba
; /* get mem addr */
510 da
= GET_DA (rkda
) * RK_NUMWD
; /* get disk addr */
511 wc
= 0200000 - rkwc
; /* get wd cnt */
512 if ((da
+ wc
) > (int32
) uptr
->capac
) { /* overrun? */
513 wc
= uptr
->capac
- da
; /* trim transfer */
514 rker
= rker
| RKER_OVR
; /* set overrun err */
517 err
= fseek (uptr
->fileref
, da
* sizeof (int16
), SEEK_SET
);
518 if (wc
&& (err
== 0)) { /* seek ok? */
519 switch (uptr
->FUNC
) { /* case on function */
521 case RKCS_READ
: /* read */
522 if (rkcs
& RKCS_FMT
) { /* format? */
523 for (i
= 0, cda
= da
; i
< wc
; i
++) { /* fill buffer with cyl #s */
524 if (cda
>= (int32
) uptr
->capac
) { /* overrun? */
525 rker
= rker
| RKER_OVR
; /* set overrun err */
526 wc
= i
; /* trim transfer */
529 rkxb
[i
] = (cda
/ RK_NUMWD
) / (RK_NUMSF
* RK_NUMSC
);
530 cda
= cda
+ RK_NUMWD
; /* next sector */
532 } /* end if format */
533 else { /* normal read */
534 i
= fxread (rkxb
, sizeof (int16
), wc
, uptr
->fileref
);
535 err
= ferror (uptr
->fileref
); /* read file */
536 for ( ; i
< wc
; i
++) rkxb
[i
] = 0; /* fill buf */
538 if (rkcs
& RKCS_INH
) { /* incr inhibit? */
539 if (t
= Map_WriteW (ma
, 2, &rkxb
[wc
- 1])) { /* store last */
540 rker
= rker
| RKER_NXM
; /* NXM? set flag */
541 wc
= 0; /* no transfer */
544 else { /* normal store */
545 if (t
= Map_WriteW (ma
, wc
<< 1, rkxb
)) { /* store buf */
546 rker
= rker
| RKER_NXM
; /* NXM? set flag */
547 wc
= wc
- t
; /* adj wd cnt */
550 break; /* end read */
552 case RKCS_WRITE
: /* write */
553 if (rkcs
& RKCS_INH
) { /* incr inhibit? */
554 if (t
= Map_ReadW (ma
, 2, &comp
)) { /* get 1st word */
555 rker
= rker
| RKER_NXM
; /* NXM? set flag */
556 wc
= 0; /* no transfer */
558 for (i
= 0; i
< wc
; i
++) rkxb
[i
] = comp
; /* all words same */
560 else { /* normal fetch */
561 if (t
= Map_ReadW (ma
, wc
<< 1, rkxb
)) { /* get buf */
562 rker
= rker
| RKER_NXM
; /* NXM? set flg */
563 wc
= wc
- t
; /* adj wd cnt */
566 if (wc
) { /* any xfer? */
567 awc
= (wc
+ (RK_NUMWD
- 1)) & ~(RK_NUMWD
- 1); /* clr to */
568 for (i
= wc
; i
< awc
; i
++) rkxb
[i
] = 0; /* end of blk */
569 fxwrite (rkxb
, sizeof (int16
), awc
, uptr
->fileref
);
570 err
= ferror (uptr
->fileref
);
572 break; /* end write */
574 case RKCS_WCHK
: /* write check */
575 i
= fxread (rkxb
, sizeof (int16
), wc
, uptr
->fileref
);
576 if (err
= ferror (uptr
->fileref
)) { /* read error? */
577 wc
= 0; /* no transfer */
580 for ( ; i
< wc
; i
++) rkxb
[i
] = 0; /* fill buf */
581 awc
= wc
; /* save wc */
582 for (wc
= 0, cma
= ma
; wc
< awc
; wc
++) { /* loop thru buf */
583 if (Map_ReadW (cma
, 2, &comp
)) { /* mem wd */
584 rker
= rker
| RKER_NXM
; /* NXM? set flg */
587 if (comp
!= rkxb
[wc
]) { /* match to disk? */
588 rker
= rker
| RKER_WCE
; /* no, err */
589 if (rkcs
& RKCS_SSE
) break;
591 if (!(rkcs
& RKCS_INH
)) cma
= cma
+ 2; /* next mem addr */
593 break; /* end wcheck */
595 default: /* read check */
600 rkwc
= (rkwc
+ wc
) & 0177777; /* final word count */
601 if (!(rkcs
& RKCS_INH
)) ma
= ma
+ (wc
<< 1); /* final byte addr */
602 rkba
= ma
& RKBA_IMP
; /* lower 16b */
603 rkcs
= (rkcs
& ~RKCS_MEX
) | ((ma
>> (16 - RKCS_V_MEX
)) & RKCS_MEX
);
604 if ((uptr
->FUNC
== RKCS_READ
) && (rkcs
& RKCS_FMT
)) /* read format? */
605 da
= da
+ (wc
* RK_NUMWD
); /* count by sectors */
606 else da
= da
+ wc
+ (RK_NUMWD
- 1); /* count by words */
607 track
= (da
/ RK_NUMWD
) / RK_NUMSC
;
608 sect
= (da
/ RK_NUMWD
) % RK_NUMSC
;
609 rkda
= (rkda
& RKDA_DRIVE
) | (track
<< RKDA_V_TRACK
) | (sect
<< RKDA_V_SECT
);
612 if (err
!= 0) { /* error? */
613 perror ("RK I/O error");
614 clearerr (uptr
->fileref
);
620 /* Interrupt state change routines
622 rk_set_done set done and possibly errors
623 rk_clr_done clear done
624 rk_inta acknowledge intererupt
627 void rk_set_done (int32 error
)
629 rkcs
= rkcs
| CSR_DONE
; /* set done */
631 rker
= rker
| error
; /* update error */
632 if (rker
) rkcs
= rkcs
| RKCS_ERR
; /* update err flags */
633 if (rker
& RKER_HARD
) rkcs
= rkcs
| RKCS_HERR
;
635 if (rkcs
& CSR_IE
) { /* int enable? */
636 rkintq
= rkintq
| RK_CTLI
; /* set ctrl int */
637 SET_INT (RK
); /* request int */
640 rkintq
= 0; /* clear queue */
646 void rk_clr_done (void)
648 rkcs
= rkcs
& ~CSR_DONE
; /* clear done */
649 rkintq
= rkintq
& ~RK_CTLI
; /* clear ctl int */
650 CLR_INT (RK
); /* clear int req */
658 for (i
= 0; i
<= RK_NUMDR
; i
++) { /* loop thru intq */
659 if (rkintq
& (1u << i
)) { /* bit i set? */
660 rkintq
= rkintq
& ~(1u << i
); /* clear bit i */
661 if (rkintq
) SET_INT (RK
); /* queue next */
662 rkds
= (rkds
& ~RKDS_ID
) | /* id drive */
663 (((i
== 0)? last_drv
: i
- 1) << RKDS_V_ID
);
664 return rk_dib
.vec
; /* return vector */
667 rkintq
= 0; /* clear queue */
668 return 0; /* passive release */
673 t_stat
rk_reset (DEVICE
*dptr
)
679 rkda
= rkba
= rker
= rkds
= 0;
680 rkintq
= last_drv
= 0;
682 for (i
= 0; i
< RK_NUMDR
; i
++) {
683 uptr
= rk_dev
.units
+ i
;
685 uptr
->CYL
= uptr
->FUNC
= 0;
686 uptr
->flags
= uptr
->flags
& ~UNIT_SWLK
;
688 if (rkxb
== NULL
) rkxb
= (uint16
*) calloc (RK_MAXFR
, sizeof (uint16
));
689 if (rkxb
== NULL
) return SCPE_MEM
;
693 /* Device bootstrap */
695 #define BOOT_START 02000 /* start */
696 #define BOOT_ENTRY (BOOT_START + 002) /* entry */
697 #define BOOT_UNIT (BOOT_START + 010) /* unit number */
698 #define BOOT_CSR (BOOT_START + 032) /* CSR */
699 #define BOOT_LEN (sizeof (boot_rom) / sizeof (int16))
701 static const uint16 boot_rom
[] = {
703 0012706, BOOT_START
, /* MOV #boot_start, SP */
704 0012700, 0000000, /* MOV #unit, R0 ; unit number */
705 0010003, /* MOV R0, R3 */
706 0000303, /* SWAB R3 */
707 0006303, /* ASL R3 */
708 0006303, /* ASL R3 */
709 0006303, /* ASL R3 */
710 0006303, /* ASL R3 */
711 0006303, /* ASL R3 */
712 0012701, 0177412, /* MOV #RKDA, R1 ; csr */
713 0010311, /* MOV R3, (R1) ; load da */
714 0005041, /* CLR -(R1) ; clear ba */
715 0012741, 0177000, /* MOV #-256.*2, -(R1) ; load wc */
716 0012741, 0000005, /* MOV #READ+GO, -(R1) ; read & go */
717 0005002, /* CLR R2 */
718 0005003, /* CLR R3 */
719 0012704, BOOT_START
+020, /* MOV #START+20, R4 */
720 0005005, /* CLR R5 */
721 0105711, /* TSTB (R1) */
722 0100376, /* BPL .-2 */
723 0105011, /* CLRB (R1) */
727 t_stat
rk_boot (int32 unitno
, DEVICE
*dptr
)
730 extern int32 saved_PC
;
732 for (i
= 0; i
< BOOT_LEN
; i
++) M
[(BOOT_START
>> 1) + i
] = boot_rom
[i
];
733 M
[BOOT_UNIT
>> 1] = unitno
& RK_M_NUMDR
;
734 M
[BOOT_CSR
>> 1] = (rk_dib
.ba
& DMASK
) + 012;
735 saved_PC
= BOOT_ENTRY
;