0000: 2f 2a 20 70 69 64 70 38 69 2e 63 3a 20 50 69 44 /* pidp8i.c: PiD
0010: 50 2d 38 2f 49 20 61 64 64 69 74 69 6f 6e 73 20 P-8/I additions
0020: 74 6f 20 74 68 65 20 50 44 50 2d 38 20 73 69 6d to the PDP-8 sim
0030: 75 6c 61 74 6f 72 0a 0a 20 20 20 43 6f 70 79 72 ulator.. Copyr
0040: 69 67 68 74 20 c2 a9 20 32 30 31 35 2d 32 30 31 ight © 2015-201
0050: 37 20 62 79 20 4f 73 63 61 72 20 56 65 72 6d 65 7 by Oscar Verme
0060: 75 6c 65 6e 2c 20 49 61 6e 20 53 63 68 6f 66 69 ulen, Ian Schofi
0070: 65 6c 64 2c 20 61 6e 64 0a 20 20 20 57 61 72 72 eld, and. Warr
0080: 65 6e 20 59 6f 75 6e 67 0a 0a 20 20 20 50 65 72 en Young.. Per
0090: 6d 69 73 73 69 6f 6e 20 69 73 20 68 65 72 65 62 mission is hereb
00a0: 79 20 67 72 61 6e 74 65 64 2c 20 66 72 65 65 20 y granted, free
00b0: 6f 66 20 63 68 61 72 67 65 2c 20 74 6f 20 61 6e of charge, to an
00c0: 79 20 70 65 72 73 6f 6e 20 6f 62 74 61 69 6e 69 y person obtaini
00d0: 6e 67 20 61 0a 20 20 20 63 6f 70 79 20 6f 66 20 ng a. copy of
00e0: 74 68 69 73 20 73 6f 66 74 77 61 72 65 20 61 6e this software an
00f0: 64 20 61 73 73 6f 63 69 61 74 65 64 20 64 6f 63 d associated doc
0100: 75 6d 65 6e 74 61 74 69 6f 6e 20 66 69 6c 65 73 umentation files
0110: 20 28 74 68 65 20 22 53 6f 66 74 77 61 72 65 22 (the "Software"
0120: 29 2c 0a 20 20 20 74 6f 20 64 65 61 6c 20 69 6e ),. to deal in
0130: 20 74 68 65 20 53 6f 66 74 77 61 72 65 20 77 69 the Software wi
0140: 74 68 6f 75 74 20 72 65 73 74 72 69 63 74 69 6f thout restrictio
0150: 6e 2c 20 69 6e 63 6c 75 64 69 6e 67 20 77 69 74 n, including wit
0160: 68 6f 75 74 20 6c 69 6d 69 74 61 74 69 6f 6e 0a hout limitation.
0170: 20 20 20 74 68 65 20 72 69 67 68 74 73 20 74 6f the rights to
0180: 20 75 73 65 2c 20 63 6f 70 79 2c 20 6d 6f 64 69 use, copy, modi
0190: 66 79 2c 20 6d 65 72 67 65 2c 20 70 75 62 6c 69 fy, merge, publi
01a0: 73 68 2c 20 64 69 73 74 72 69 62 75 74 65 2c 20 sh, distribute,
01b0: 73 75 62 6c 69 63 65 6e 73 65 2c 0a 20 20 20 61 sublicense,. a
01c0: 6e 64 2f 6f 72 20 73 65 6c 6c 20 63 6f 70 69 65 nd/or sell copie
01d0: 73 20 6f 66 20 74 68 65 20 53 6f 66 74 77 61 72 s of the Softwar
01e0: 65 2c 20 61 6e 64 20 74 6f 20 70 65 72 6d 69 74 e, and to permit
01f0: 20 70 65 72 73 6f 6e 73 20 74 6f 20 77 68 6f 6d persons to whom
0200: 20 74 68 65 0a 20 20 20 53 6f 66 74 77 61 72 65 the. Software
0210: 20 69 73 20 66 75 72 6e 69 73 68 65 64 20 74 6f is furnished to
0220: 20 64 6f 20 73 6f 2c 20 73 75 62 6a 65 63 74 20 do so, subject
0230: 74 6f 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 to the following
0240: 20 63 6f 6e 64 69 74 69 6f 6e 73 3a 0a 0a 20 20 conditions:..
0250: 20 54 68 65 20 61 62 6f 76 65 20 63 6f 70 79 72 The above copyr
0260: 69 67 68 74 20 6e 6f 74 69 63 65 20 61 6e 64 20 ight notice and
0270: 74 68 69 73 20 70 65 72 6d 69 73 73 69 6f 6e 20 this permission
0280: 6e 6f 74 69 63 65 20 73 68 61 6c 6c 20 62 65 20 notice shall be
0290: 69 6e 63 6c 75 64 65 64 20 69 6e 0a 20 20 20 61 included in. a
02a0: 6c 6c 20 63 6f 70 69 65 73 20 6f 72 20 73 75 62 ll copies or sub
02b0: 73 74 61 6e 74 69 61 6c 20 70 6f 72 74 69 6f 6e stantial portion
02c0: 73 20 6f 66 20 74 68 65 20 53 6f 66 74 77 61 72 s of the Softwar
02d0: 65 2e 0a 0a 20 20 20 54 48 45 20 53 4f 46 54 57 e... THE SOFTW
02e0: 41 52 45 20 49 53 20 50 52 4f 56 49 44 45 44 20 ARE IS PROVIDED
02f0: 22 41 53 20 49 53 22 2c 20 57 49 54 48 4f 55 54 "AS IS", WITHOUT
0300: 20 57 41 52 52 41 4e 54 59 20 4f 46 20 41 4e 59 WARRANTY OF ANY
0310: 20 4b 49 4e 44 2c 20 45 58 50 52 45 53 53 20 4f KIND, EXPRESS O
0320: 52 0a 20 20 20 49 4d 50 4c 49 45 44 2c 20 49 4e R. IMPLIED, IN
0330: 43 4c 55 44 49 4e 47 20 42 55 54 20 4e 4f 54 20 CLUDING BUT NOT
0340: 4c 49 4d 49 54 45 44 20 54 4f 20 54 48 45 20 57 LIMITED TO THE W
0350: 41 52 52 41 4e 54 49 45 53 20 4f 46 20 4d 45 52 ARRANTIES OF MER
0360: 43 48 41 4e 54 41 42 49 4c 49 54 59 2c 0a 20 20 CHANTABILITY,.
0370: 20 46 49 54 4e 45 53 53 20 46 4f 52 20 41 20 50 FITNESS FOR A P
0380: 41 52 54 49 43 55 4c 41 52 20 50 55 52 50 4f 53 ARTICULAR PURPOS
0390: 45 20 41 4e 44 20 4e 4f 4e 49 4e 46 52 49 4e 47 E AND NONINFRING
03a0: 45 4d 45 4e 54 2e 20 20 49 4e 20 4e 4f 20 45 56 EMENT. IN NO EV
03b0: 45 4e 54 20 53 48 41 4c 4c 0a 20 20 20 54 48 45 ENT SHALL. THE
03c0: 20 41 55 54 48 4f 52 53 20 4c 49 53 54 45 44 20 AUTHORS LISTED
03d0: 41 42 4f 56 45 20 42 45 20 4c 49 41 42 4c 45 20 ABOVE BE LIABLE
03e0: 46 4f 52 20 41 4e 59 20 43 4c 41 49 4d 2c 20 44 FOR ANY CLAIM, D
03f0: 41 4d 41 47 45 53 20 4f 52 20 4f 54 48 45 52 0a AMAGES OR OTHER.
0400: 20 20 20 4c 49 41 42 49 4c 49 54 59 2c 20 57 48 LIABILITY, WH
0410: 45 54 48 45 52 20 49 4e 20 41 4e 20 41 43 54 49 ETHER IN AN ACTI
0420: 4f 4e 20 4f 46 20 43 4f 4e 54 52 41 43 54 2c 20 ON OF CONTRACT,
0430: 54 4f 52 54 20 4f 52 20 4f 54 48 45 52 57 49 53 TORT OR OTHERWIS
0440: 45 2c 20 41 52 49 53 49 4e 47 0a 20 20 20 46 52 E, ARISING. FR
0450: 4f 4d 2c 20 4f 55 54 20 4f 46 20 4f 52 20 49 4e OM, OUT OF OR IN
0460: 20 43 4f 4e 4e 45 43 54 49 4f 4e 20 57 49 54 48 CONNECTION WITH
0470: 20 54 48 45 20 53 4f 46 54 57 41 52 45 20 4f 52 THE SOFTWARE OR
0480: 20 54 48 45 20 55 53 45 20 4f 52 20 4f 54 48 45 THE USE OR OTHE
0490: 52 0a 20 20 20 44 45 41 4c 49 4e 47 53 20 49 4e R. DEALINGS IN
04a0: 20 54 48 45 20 53 4f 46 54 57 41 52 45 2e 0a 0a THE SOFTWARE...
04b0: 20 20 20 45 78 63 65 70 74 20 61 73 20 63 6f 6e Except as con
04c0: 74 61 69 6e 65 64 20 69 6e 20 74 68 69 73 20 6e tained in this n
04d0: 6f 74 69 63 65 2c 20 74 68 65 20 6e 61 6d 65 73 otice, the names
04e0: 20 6f 66 20 74 68 65 20 61 75 74 68 6f 72 73 20 of the authors
04f0: 61 62 6f 76 65 20 73 68 61 6c 6c 0a 20 20 20 6e above shall. n
0500: 6f 74 20 62 65 20 75 73 65 64 20 69 6e 20 61 64 ot be used in ad
0510: 76 65 72 74 69 73 69 6e 67 20 6f 72 20 6f 74 68 vertising or oth
0520: 65 72 77 69 73 65 20 74 6f 20 70 72 6f 6d 6f 74 erwise to promot
0530: 65 20 74 68 65 20 73 61 6c 65 2c 20 75 73 65 20 e the sale, use
0540: 6f 72 20 6f 74 68 65 72 0a 20 20 20 64 65 61 6c or other. deal
0550: 69 6e 67 73 20 69 6e 20 74 68 69 73 20 53 6f 66 ings in this Sof
0560: 74 77 61 72 65 20 77 69 74 68 6f 75 74 20 70 72 tware without pr
0570: 69 6f 72 20 77 72 69 74 74 65 6e 20 61 75 74 68 ior written auth
0580: 6f 72 69 7a 61 74 69 6f 6e 20 66 72 6f 6d 20 74 orization from t
0590: 68 6f 73 65 0a 20 20 20 61 75 74 68 6f 72 73 2e hose. authors.
05a0: 0a 2a 2f 0a 0a 23 69 6e 63 6c 75 64 65 20 22 70 .*/..#include "p
05b0: 69 64 70 38 69 2e 68 22 0a 0a 23 69 6e 63 6c 75 idp8i.h"..#inclu
05c0: 64 65 20 22 2e 2e 2f 67 70 69 6f 2d 63 6f 6d 6d de "../gpio-comm
05d0: 6f 6e 2e 68 22 0a 0a 23 69 6e 63 6c 75 64 65 20 on.h"..#include
05e0: 3c 64 69 72 65 6e 74 2e 68 3e 20 2f 2f 20 66 6f <dirent.h> // fo
05f0: 72 20 55 53 42 20 73 74 69 63 6b 20 73 65 61 72 r USB stick sear
0600: 63 68 69 6e 67 0a 0a 0a 2f 2f 2f 2f 20 45 58 50 ching...//// EXP
0610: 4f 52 54 45 44 20 47 4c 4f 42 41 4c 53 20 2f 2f ORTED GLOBALS //
0620: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0630: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0640: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0650: 0a 0a 2f 2f 20 74 72 75 6c 79 20 74 65 72 72 69 ..// truly terri
0660: 62 6c 65 20 65 76 65 6e 20 66 6f 72 20 6d 65 20 ble even for me
0670: 2d 20 62 72 65 61 6b 20 6f 75 74 20 6f 66 20 73 - break out of s
0680: 69 6d 20 61 6e 64 20 73 74 61 72 74 20 6e 65 77 im and start new
0690: 20 73 63 72 69 70 74 20 69 6e 20 73 63 70 2e 63 script in scp.c
06a0: 0a 69 6e 74 20 61 77 66 75 6c 48 61 63 6b 46 6c .int awfulHackFl
06b0: 61 67 20 3d 20 30 3b 0a 0a 0a 2f 2f 2f 2f 20 49 ag = 0;...//// I
06c0: 4e 54 45 52 4e 41 4c 20 47 4c 4f 42 41 4c 53 20 NTERNAL GLOBALS
06d0: 41 4e 44 20 43 4f 4e 53 54 41 4e 54 53 20 2f 2f AND CONSTANTS //
06e0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
06f0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0700: 2f 2f 0a 0a 2f 2f 20 53 69 6e 67 6c 65 2d 73 68 //..// Single-sh
0710: 6f 74 20 66 6c 61 67 20 66 6f 72 20 74 68 65 20 ot flag for the
0720: 53 54 4f 50 20 73 77 69 74 63 68 2e 20 20 49 74 STOP switch. It
0730: 27 73 20 67 6c 6f 62 61 6c 20 62 65 63 61 75 73 's global becaus
0740: 65 20 73 65 76 65 72 61 6c 20 6f 66 0a 2f 2f 20 e several of.//
0750: 74 68 65 20 66 75 6e 63 74 69 6f 6e 73 20 62 65 the functions be
0760: 6c 6f 77 20 6e 65 65 64 20 74 6f 20 65 78 61 6d low need to exam
0770: 69 6e 65 20 6f 72 20 6d 6f 64 69 66 79 20 69 74 ine or modify it
0780: 2c 20 73 69 6e 63 65 20 6d 6f 72 65 20 74 68 61 , since more tha
0790: 6e 0a 2f 2f 20 6a 75 73 74 20 74 68 65 20 53 54 n.// just the ST
07a0: 4f 50 20 73 77 69 74 63 68 20 68 61 6e 64 6c 65 OP switch handle
07b0: 72 20 63 61 6e 20 70 75 74 20 75 73 20 69 6e 74 r can put us int
07c0: 6f 20 53 54 4f 50 20 6d 6f 64 65 2e 0a 73 74 61 o STOP mode..sta
07d0: 74 69 63 20 69 6e 74 20 73 77 53 74 6f 70 20 3d tic int swStop =
07e0: 20 30 3b 0a 0a 2f 2f 20 53 69 6e 67 6c 65 2d 73 0;..// Single-s
07f0: 68 6f 74 20 66 6c 61 67 20 66 6f 72 20 74 68 65 hot flag for the
0800: 20 53 49 4e 47 5f 49 4e 53 54 20 73 77 69 74 63 SING_INST switc
0810: 68 2e 20 20 49 74 27 73 20 67 6c 6f 62 61 6c 20 h. It's global
0820: 6f 6e 6c 79 20 74 6f 20 62 65 0a 2f 2f 20 70 61 only to be.// pa
0830: 72 61 6c 6c 65 6c 20 77 69 74 68 20 73 77 53 74 rallel with swSt
0840: 6f 70 2c 20 77 68 69 63 68 20 77 65 20 6d 6f 64 op, which we mod
0850: 69 66 79 20 69 6e 20 6d 75 63 68 20 74 68 65 20 ify in much the
0860: 73 61 6d 65 20 77 61 79 2e 0a 73 74 61 74 69 63 same way..static
0870: 20 69 6e 74 20 73 77 53 69 6e 67 49 6e 73 74 20 int swSingInst
0880: 3d 20 30 3b 0a 0a 0a 2f 2f 2f 2f 20 73 65 74 5f = 0;...//// set_
0890: 70 69 64 70 38 69 5f 6c 65 64 20 2f 2f 2f 2f 2f pidp8i_led /////
08a0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
08b0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
08c0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0a ///////////////.
08d0: 2f 2f 20 53 65 74 73 20 74 68 65 20 63 75 72 72 // Sets the curr
08e0: 65 6e 74 20 73 74 61 74 65 20 66 6f 72 20 61 20 ent state for a
08f0: 73 69 6e 67 6c 65 20 4c 45 44 20 61 74 20 74 68 single LED at th
0900: 65 20 67 69 76 65 6e 20 72 6f 77 20 61 6e 64 20 e given row and
0910: 63 6f 6c 75 6d 6e 0a 2f 2f 20 6f 6e 20 74 68 65 column.// on the
0920: 20 50 69 44 50 2d 38 2f 49 20 50 43 42 2e 20 20 PiDP-8/I PCB.
0930: 41 6c 73 6f 20 69 6e 63 72 65 6d 65 6e 74 73 20 Also increments
0940: 74 68 65 20 4c 45 44 20 6f 6e 2d 63 6f 75 6e 74 the LED on-count
0950: 20 76 61 6c 75 65 20 66 6f 72 20 0a 2f 2f 20 74 value for .// t
0960: 68 61 74 20 4c 45 44 2e 0a 2f 2f 0a 2f 2f 20 59 hat LED..//.// Y
0970: 6f 75 20 6d 61 79 20 73 61 79 2c 20 22 59 6f 75 ou may say, "You
0980: 20 63 61 6e 27 74 20 6a 75 73 74 20 75 73 65 20 can't just use
0990: 74 68 65 20 43 20 70 6f 73 74 69 6e 63 72 65 6d the C postincrem
09a0: 65 6e 74 20 6f 70 65 72 61 74 6f 72 20 68 65 72 ent operator her
09b0: 65 21 0a 2f 2f 20 4c 6f 6f 6b 20 61 74 20 74 68 e!.// Look at th
09c0: 65 20 61 73 73 65 6d 62 6c 79 20 6f 75 74 70 75 e assembly outpu
09d0: 74 21 20 20 59 6f 75 20 6d 75 73 74 20 75 73 65 t! You must use
09e0: 20 61 6e 20 61 74 6f 6d 69 63 20 69 6e 63 72 65 an atomic incre
09f0: 6d 65 6e 74 20 66 6f 72 0a 2f 2f 20 74 68 69 73 ment for.// this
0a00: 21 22 20 20 41 6e 64 20 69 6e 64 65 65 64 2c 20 !" And indeed,
0a10: 74 68 65 72 65 20 69 73 20 61 20 62 69 67 20 64 there is a big d
0a20: 69 66 66 65 72 65 6e 63 65 20 62 65 74 77 65 65 ifference betwee
0a30: 6e 20 74 68 65 20 74 77 6f 0a 2f 2f 20 6d 65 74 n the two.// met
0a40: 68 6f 64 73 3a 20 68 74 74 70 73 3a 2f 2f 67 6f hods: https://go
0a50: 64 62 6f 6c 74 2e 6f 72 67 2f 67 2f 30 51 74 30 dbolt.org/g/0Qt0
0a60: 41 70 0a 2f 2f 0a 2f 2f 20 54 68 65 20 74 68 69 Ap.//.// The thi
0a70: 6e 67 20 69 73 2c 20 62 6f 74 68 20 73 74 72 75 ng is, both stru
0a80: 63 74 75 72 65 73 20 72 65 66 65 72 72 65 64 20 ctures referred
0a90: 74 6f 20 62 79 20 70 64 69 73 5f 2a 20 61 72 65 to by pdis_* are
0aa0: 20 66 69 78 65 64 20 69 6e 20 52 41 4d 2c 0a 2f fixed in RAM,./
0ab0: 2f 20 61 6e 64 20 74 68 65 20 74 77 6f 20 74 68 / and the two th
0ac0: 72 65 61 64 73 20 69 6e 76 6f 6c 76 65 64 20 61 reads involved a
0ad0: 72 65 20 61 72 72 61 6e 67 65 64 20 69 6e 20 61 re arranged in a
0ae0: 20 73 74 72 69 63 74 20 70 72 6f 64 75 63 65 72 strict producer
0af0: 2d 61 6e 64 2d 0a 2f 2f 20 63 6f 6e 73 75 6d 65 -and-.// consume
0b00: 72 20 66 61 73 68 69 6f 6e 2c 20 73 6f 20 69 74 r fashion, so it
0b10: 20 64 6f 65 73 6e 27 74 20 61 63 74 75 61 6c 6c doesn't actuall
0b20: 79 20 6d 61 74 74 65 72 20 69 66 20 70 64 69 73 y matter if pdis
0b30: 5f 75 70 64 61 74 65 20 67 65 74 73 0a 2f 2f 20 _update gets.//
0b40: 73 77 61 70 70 65 64 20 66 6f 72 20 70 64 69 73 swapped for pdis
0b50: 5f 70 61 69 6e 74 20 77 68 69 6c 65 20 77 65 27 _paint while we'
0b60: 72 65 20 68 61 6c 66 77 61 79 20 74 68 72 6f 75 re halfway throu
0b70: 67 68 20 61 6e 20 69 6e 63 72 65 6d 65 6e 74 3a gh an increment:
0b80: 20 77 65 0a 2f 2f 20 64 65 72 65 66 65 72 65 6e we.// dereferen
0b90: 63 65 20 74 68 65 20 70 6f 69 6e 74 65 72 20 6f ce the pointer o
0ba0: 6e 6c 79 20 6f 6e 63 65 20 68 65 72 65 2c 20 73 nly once here, s
0bb0: 6f 20 77 65 27 6c 6c 20 66 69 6e 69 73 68 20 6f o we'll finish o
0bc0: 75 72 20 69 6e 63 72 65 6d 65 6e 74 0a 2f 2f 20 ur increment.//
0bd0: 77 69 74 68 69 6e 20 74 68 65 20 73 61 6d 65 20 within the same
0be0: 73 74 72 75 63 74 75 72 65 20 77 65 20 73 74 61 structure we sta
0bf0: 72 74 65 64 20 77 69 74 68 2c 20 65 76 65 6e 20 rted with, even
0c00: 69 66 20 70 64 69 73 5f 75 70 64 61 74 65 20 70 if pdis_update p
0c10: 6f 69 6e 74 73 0a 2f 2f 20 61 74 20 74 68 65 20 oints.// at the
0c20: 6f 74 68 65 72 20 64 69 73 70 6c 61 79 20 73 74 other display st
0c30: 72 75 63 74 75 72 65 20 62 65 66 6f 72 65 20 77 ructure before w
0c40: 65 20 6c 65 61 76 65 2e 0a 0a 73 74 61 74 69 63 e leave...static
0c50: 20 69 6e 6c 69 6e 65 20 76 6f 69 64 20 73 65 74 inline void set
0c60: 5f 70 69 64 70 38 69 5f 6c 65 64 20 28 64 69 73 _pidp8i_led (dis
0c70: 70 6c 61 79 20 2a 70 64 2c 20 73 69 7a 65 5f 74 play *pd, size_t
0c80: 20 72 6f 77 2c 20 73 69 7a 65 5f 74 20 63 6f 6c row, size_t col
0c90: 29 0a 7b 0a 20 20 20 20 2b 2b 70 64 2d 3e 6f 6e ).{. ++pd->on
0ca0: 5b 72 6f 77 5d 5b 63 6f 6c 5d 3b 0a 20 20 20 20 [row][col];.
0cb0: 70 64 2d 3e 63 75 72 72 5b 72 6f 77 5d 20 7c 3d pd->curr[row] |=
0cc0: 20 31 20 3c 3c 20 63 6f 6c 3b 0a 7d 0a 0a 0a 2f 1 << col;.}.../
0cd0: 2f 2f 2f 20 73 65 74 5f 70 69 64 70 38 69 5f 72 /// set_pidp8i_r
0ce0: 6f 77 5f 6c 65 64 73 20 2f 2f 2f 2f 2f 2f 2f 2f ow_leds ////////
0cf0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0d00: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0d10: 2f 2f 2f 2f 2f 2f 2f 0a 2f 2f 20 4c 69 6b 65 20 ///////.// Like
0d20: 73 65 74 5f 70 69 64 70 38 69 5f 6c 65 64 2c 20 set_pidp8i_led,
0d30: 65 78 63 65 70 74 20 74 68 61 74 20 69 74 20 74 except that it t
0d40: 61 6b 65 73 20 61 20 31 32 2d 62 69 74 20 73 74 akes a 12-bit st
0d50: 61 74 65 20 76 61 6c 75 65 20 66 6f 72 0a 2f 2f ate value for.//
0d60: 20 73 65 74 74 69 6e 67 20 61 6c 6c 20 4c 45 44 setting all LED
0d70: 73 20 6f 6e 20 74 68 65 20 67 69 76 65 6e 20 72 s on the given r
0d80: 6f 77 2e 20 20 42 65 63 61 75 73 65 20 77 65 20 ow. Because we
0d90: 63 6f 70 79 20 74 68 65 20 70 64 69 73 5f 75 70 copy the pdis_up
0da0: 64 61 74 65 0a 2f 2f 20 70 6f 69 6e 74 65 72 20 date.// pointer
0db0: 62 65 66 6f 72 65 20 6d 61 6b 69 6e 67 20 63 68 before making ch
0dc0: 61 6e 67 65 73 2c 20 69 66 20 74 68 65 20 64 69 anges, if the di
0dd0: 73 70 6c 61 79 20 73 77 61 70 20 68 61 70 70 65 splay swap happe
0de0: 6e 73 20 77 68 69 6c 65 0a 2f 2f 20 77 65 27 72 ns while.// we'r
0df0: 65 20 77 6f 72 6b 69 6e 67 2c 20 77 65 27 6c 6c e working, we'll
0e00: 20 73 69 6d 70 6c 79 20 66 69 6e 69 73 68 20 75 simply finish u
0e10: 70 64 61 74 69 6e 67 20 77 68 61 74 20 68 61 73 pdating what has
0e20: 20 62 65 63 6f 6d 65 20 74 68 65 0a 2f 2f 20 70 become the.// p
0e30: 61 69 6e 74 2d 66 72 6f 6d 20 64 69 73 70 6c 61 aint-from displa
0e40: 79 2c 20 77 68 69 63 68 20 69 73 20 77 68 61 74 y, which is what
0e50: 20 79 6f 75 20 77 61 6e 74 3b 20 79 6f 75 20 64 you want; you d
0e60: 6f 6e 27 74 20 77 61 6e 74 20 74 68 65 0a 2f 2f on't want the.//
0e70: 20 75 70 64 61 74 65 73 20 73 70 72 65 61 64 20 updates spread
0e80: 6f 76 65 72 20 62 6f 74 68 20 64 69 73 70 6c 61 over both displa
0e90: 79 73 2e 0a 0a 73 74 61 74 69 63 20 69 6e 6c 69 ys...static inli
0ea0: 6e 65 20 76 6f 69 64 20 73 65 74 5f 70 69 64 70 ne void set_pidp
0eb0: 38 69 5f 72 6f 77 5f 6c 65 64 73 20 28 64 69 73 8i_row_leds (dis
0ec0: 70 6c 61 79 20 2a 70 64 2c 20 73 69 7a 65 5f 74 play *pd, size_t
0ed0: 20 72 6f 77 2c 0a 20 20 20 20 20 20 20 20 75 69 row,. ui
0ee0: 6e 74 31 36 20 73 74 61 74 65 29 0a 7b 0a 20 20 nt16 state).{.
0ef0: 20 20 73 69 7a 65 5f 74 20 2a 70 72 6f 77 20 3d size_t *prow =
0f00: 20 70 64 2d 3e 6f 6e 5b 72 6f 77 5d 3b 0a 20 20 pd->on[row];.
0f10: 20 20 70 64 2d 3e 63 75 72 72 5b 72 6f 77 5d 20 pd->curr[row]
0f20: 3d 20 73 74 61 74 65 3b 0a 20 20 20 20 66 6f 72 = state;. for
0f30: 20 28 73 69 7a 65 5f 74 20 63 6f 6c 20 3d 20 30 (size_t col = 0
0f40: 2c 20 6d 61 73 6b 20 3d 20 31 3b 20 63 6f 6c 20 , mask = 1; col
0f50: 3c 20 4e 43 4f 4c 53 3b 20 2b 2b 63 6f 6c 2c 20 < NCOLS; ++col,
0f60: 6d 61 73 6b 20 3c 3c 3d 20 31 29 20 7b 0a 20 20 mask <<= 1) {.
0f70: 20 20 20 20 20 20 69 66 20 28 73 74 61 74 65 20 if (state
0f80: 26 20 6d 61 73 6b 29 20 2b 2b 70 72 6f 77 5b 63 & mask) ++prow[c
0f90: 6f 6c 5d 3b 0a 20 20 20 20 7d 0a 7d 0a 0a 0a 2f ol];. }.}.../
0fa0: 2f 2f 2f 20 73 65 74 5f 33 5f 70 69 64 70 38 69 /// set_3_pidp8i
0fb0: 5f 6c 65 64 73 20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f _leds //////////
0fc0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0fd0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
0fe0: 2f 2f 2f 2f 2f 2f 2f 0a 2f 2f 20 53 70 65 63 69 ///////.// Speci
0ff0: 61 6c 20 63 61 73 65 20 6f 66 20 73 65 74 5f 70 al case of set_p
1000: 69 64 70 38 69 5f 72 6f 77 5f 6c 65 64 73 20 66 idp8i_row_leds f
1010: 6f 72 20 74 68 65 20 44 46 20 61 6e 64 20 49 46 or the DF and IF
1020: 20 4c 45 44 73 3a 20 77 65 20 6f 6e 6c 79 0a 2f LEDs: we only./
1030: 2f 20 70 61 79 20 61 74 74 65 6e 74 69 6f 6e 20 / pay attention
1040: 74 6f 20 62 69 74 73 20 31 32 2c 20 31 33 2c 20 to bits 12, 13,
1050: 61 6e 64 20 31 34 20 6f 66 20 74 68 65 20 67 69 and 14 of the gi
1060: 76 65 6e 20 73 74 61 74 65 20 76 61 6c 75 65 2c ven state value,
1070: 0a 2f 2f 20 62 65 63 61 75 73 65 20 53 49 4d 48 .// because SIMH
1080: 27 73 20 50 44 50 2d 38 20 73 69 6d 75 6c 61 74 's PDP-8 simulat
1090: 6f 72 20 73 68 69 66 74 73 20 74 68 6f 73 65 20 or shifts those
10a0: 33 20 62 69 74 73 20 75 70 20 74 68 65 72 65 20 3 bits up there
10b0: 73 6f 20 69 74 20 63 61 6e 0a 2f 2f 20 73 69 6d so it can.// sim
10c0: 70 6c 79 20 4f 52 20 74 68 65 73 65 20 33 2d 62 ply OR these 3-b
10d0: 69 74 20 72 65 67 69 73 74 65 72 73 20 77 69 74 it registers wit
10e0: 68 20 50 43 20 74 6f 20 70 72 6f 64 75 63 65 20 h PC to produce
10f0: 61 20 31 35 2d 62 69 74 20 65 78 74 65 6e 64 65 a 15-bit extende
1100: 64 0a 2f 2f 20 61 64 64 72 65 73 73 2e 0a 2f 2f d.// address..//
1110: 0a 2f 2f 20 57 65 20 64 6f 6e 27 74 20 74 61 6b .// We don't tak
1120: 65 20 61 20 72 6f 77 20 70 61 72 61 6d 65 74 65 e a row paramete
1130: 72 20 62 65 63 61 75 73 65 20 77 65 20 6b 6e 6f r because we kno
1140: 77 20 77 68 69 63 68 20 72 6f 77 20 74 68 65 79 w which row they
1150: 27 72 65 20 6f 6e 2c 0a 2f 2f 20 62 75 74 20 77 're on,.// but w
1160: 65 20 64 6f 20 74 61 6b 65 20 61 20 63 6f 6c 75 e do take a colu
1170: 6d 6e 20 70 61 72 61 6d 65 74 65 72 20 73 6f 20 mn parameter so
1180: 77 65 20 63 61 6e 20 67 65 6e 65 72 61 6c 69 7a we can generaliz
1190: 65 20 66 6f 72 20 49 46 20 26 20 44 46 2e 0a 0a e for IF & DF...
11a0: 73 74 61 74 69 63 20 69 6e 6c 69 6e 65 20 76 6f static inline vo
11b0: 69 64 20 73 65 74 5f 33 5f 70 69 64 70 38 69 5f id set_3_pidp8i_
11c0: 6c 65 64 73 20 28 64 69 73 70 6c 61 79 20 2a 70 leds (display *p
11d0: 64 2c 20 73 69 7a 65 5f 74 20 63 6f 6c 2c 0a 20 d, size_t col,.
11e0: 20 20 20 20 20 20 20 75 69 6e 74 31 36 20 73 74 uint16 st
11f0: 61 74 65 29 0a 7b 0a 20 20 20 20 73 74 61 74 69 ate).{. stati
1200: 63 20 63 6f 6e 73 74 20 69 6e 74 20 72 6f 77 20 c const int row
1210: 3d 20 37 3b 20 20 20 20 20 20 20 2f 2f 20 44 46 = 7; // DF
1220: 20 61 6e 64 20 49 46 20 61 72 65 20 6f 6e 20 72 and IF are on r
1230: 6f 77 20 36 0a 20 20 20 20 73 69 7a 65 5f 74 20 ow 6. size_t
1240: 2a 70 72 6f 77 20 3d 20 70 64 2d 3e 6f 6e 5b 72 *prow = pd->on[r
1250: 6f 77 5d 3b 0a 20 20 20 20 73 69 7a 65 5f 74 20 ow];. size_t
1260: 6c 61 73 74 5f 63 6f 6c 20 3d 20 63 6f 6c 20 2b last_col = col +
1270: 20 33 3b 0a 20 20 20 20 70 64 2d 3e 63 75 72 72 3;. pd->curr
1280: 5b 72 6f 77 5d 20 7c 3d 20 73 74 61 74 65 20 3e [row] |= state >
1290: 3e 20 28 31 32 20 2d 20 63 6f 6c 29 3b 0a 20 20 > (12 - col);.
12a0: 20 20 66 6f 72 20 28 73 69 7a 65 5f 74 20 6d 61 for (size_t ma
12b0: 73 6b 20 3d 20 31 20 3c 3c 20 31 32 3b 20 63 6f sk = 1 << 12; co
12c0: 6c 20 3c 20 6c 61 73 74 5f 63 6f 6c 3b 20 2b 2b l < last_col; ++
12d0: 63 6f 6c 2c 20 6d 61 73 6b 20 3c 3c 3d 20 31 29 col, mask <<= 1)
12e0: 20 7b 0a 20 20 20 20 20 20 20 20 69 66 20 28 73 {. if (s
12f0: 74 61 74 65 20 26 20 6d 61 73 6b 29 20 2b 2b 70 tate & mask) ++p
1300: 72 6f 77 5b 63 6f 6c 5d 3b 0a 20 20 20 20 7d 0a row[col];. }.
1310: 7d 0a 0a 0a 2f 2f 2f 2f 20 73 65 74 5f 35 5f 70 }...//// set_5_p
1320: 69 64 70 38 69 5f 6c 65 64 73 20 2f 2f 2f 2f 2f idp8i_leds /////
1330: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1340: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1350: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0a 2f 2f 20 ////////////.//
1360: 4c 69 6b 65 20 73 65 74 5f 33 2e 2e 2e 20 62 75 Like set_3... bu
1370: 74 20 66 6f 72 20 74 68 65 20 35 2d 62 69 74 20 t for the 5-bit
1380: 53 43 20 72 65 67 69 73 74 65 72 2e 20 20 42 65 SC register. Be
1390: 63 61 75 73 65 20 69 74 27 73 20 6f 6e 6c 79 20 cause it's only
13a0: 75 73 65 64 0a 2f 2f 20 66 6f 72 20 74 68 61 74 used.// for that
13b0: 20 70 75 72 70 6f 73 65 2c 20 77 65 20 64 6f 6e purpose, we don
13c0: 27 74 20 6e 65 65 64 20 74 68 65 20 63 6f 6c 20 't need the col
13d0: 70 61 72 61 6d 65 74 65 72 2e 0a 0a 73 74 61 74 parameter...stat
13e0: 69 63 20 69 6e 6c 69 6e 65 20 76 6f 69 64 20 73 ic inline void s
13f0: 65 74 5f 35 5f 70 69 64 70 38 69 5f 6c 65 64 73 et_5_pidp8i_leds
1400: 20 28 64 69 73 70 6c 61 79 20 2a 70 64 2c 20 75 (display *pd, u
1410: 69 6e 74 31 36 20 73 74 61 74 65 29 0a 7b 0a 20 int16 state).{.
1420: 20 20 20 73 74 61 74 69 63 20 63 6f 6e 73 74 20 static const
1430: 69 6e 74 20 72 6f 77 20 3d 20 36 3b 20 20 20 20 int row = 6;
1440: 20 20 20 2f 2f 20 53 43 20 69 73 20 6f 6e 20 72 // SC is on r
1450: 6f 77 20 36 0a 20 20 20 20 73 69 7a 65 5f 74 20 ow 6. size_t
1460: 2a 70 72 6f 77 20 3d 20 70 64 2d 3e 6f 6e 5b 72 *prow = pd->on[r
1470: 6f 77 5d 3b 0a 20 20 20 20 73 69 7a 65 5f 74 20 ow];. size_t
1480: 6c 61 73 74 5f 63 6f 6c 20 3d 20 37 3b 0a 20 20 last_col = 7;.
1490: 20 20 70 64 2d 3e 63 75 72 72 5b 72 6f 77 5d 20 pd->curr[row]
14a0: 7c 3d 20 28 73 74 61 74 65 20 26 20 30 78 31 66 |= (state & 0x1f
14b0: 29 20 3c 3c 20 32 3b 0a 20 20 20 20 66 6f 72 20 ) << 2;. for
14c0: 28 73 69 7a 65 5f 74 20 63 6f 6c 20 3d 20 32 2c (size_t col = 2,
14d0: 20 6d 61 73 6b 20 3d 20 31 3b 20 63 6f 6c 20 3c mask = 1; col <
14e0: 20 6c 61 73 74 5f 63 6f 6c 3b 20 2b 2b 63 6f 6c last_col; ++col
14f0: 2c 20 6d 61 73 6b 20 3c 3c 3d 20 31 29 20 7b 0a , mask <<= 1) {.
1500: 20 20 20 20 20 20 20 20 69 66 20 28 73 74 61 74 if (stat
1510: 65 20 26 20 6d 61 73 6b 29 20 2b 2b 70 72 6f 77 e & mask) ++prow
1520: 5b 63 6f 6c 5d 3b 0a 20 20 20 20 7d 0a 7d 0a 0a [col];. }.}..
1530: 0a 2f 2f 2f 2f 20 67 65 74 5f 70 69 64 70 38 69 .//// get_pidp8i
1540: 5f 69 6e 69 74 69 61 6c 5f 6d 61 78 5f 73 6b 69 _initial_max_ski
1550: 70 73 20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ps /////////////
1560: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1570: 2f 2f 2f 2f 2f 2f 2f 2f 2f 0a 2f 2f 20 52 65 74 /////////.// Ret
1580: 75 72 6e 20 74 68 65 20 6e 75 6d 62 65 72 20 6f urn the number o
1590: 66 20 74 69 6d 65 73 20 77 65 20 73 68 6f 75 6c f times we shoul
15a0: 64 20 73 6b 69 70 20 75 70 64 61 74 69 6e 67 20 d skip updating
15b0: 74 68 65 20 66 72 6f 6e 74 20 70 61 6e 65 6c 0a the front panel.
15c0: 2f 2f 20 4c 45 44 73 20 74 68 65 20 66 69 72 73 // LEDs the firs
15d0: 74 20 74 69 6d 65 20 74 68 72 75 2c 20 74 6f 20 t time thru, to
15e0: 67 69 76 65 20 74 68 65 20 73 69 6d 75 6c 61 74 give the simulat
15f0: 6f 72 20 74 69 6d 65 20 74 6f 20 73 65 74 74 6c or time to settl
1600: 65 2e 0a 2f 2f 20 49 66 20 77 65 20 64 6f 6e 27 e..// If we don'
1610: 74 20 64 6f 20 74 68 69 73 2c 20 74 68 65 20 66 t do this, the f
1620: 72 6f 6e 74 20 70 61 6e 65 6c 20 4c 45 44 73 20 ront panel LEDs
1630: 63 61 6e 20 73 74 61 72 74 20 6f 75 74 20 64 69 can start out di
1640: 6d 20 61 6e 64 0a 2f 2f 20 73 6c 6f 77 6c 79 20 m and.// slowly
1650: 72 69 73 65 20 6f 72 20 74 68 65 79 20 63 61 6e rise or they can
1660: 20 6f 76 65 72 73 68 6f 6f 74 20 61 6e 64 20 74 overshoot and t
1670: 68 65 6e 20 74 61 6b 65 20 61 20 77 68 69 6c 65 hen take a while
1680: 20 74 6f 20 72 65 63 6f 76 65 72 0a 2f 2f 20 77 to recover.// w
1690: 69 74 68 20 74 68 65 20 49 50 53 2e 0a 0a 73 69 ith the IPS...si
16a0: 7a 65 5f 74 20 67 65 74 5f 70 69 64 70 38 69 5f ze_t get_pidp8i_
16b0: 69 6e 69 74 69 61 6c 5f 6d 61 78 5f 73 6b 69 70 initial_max_skip
16c0: 73 20 28 73 69 7a 65 5f 74 20 75 70 64 61 74 65 s (size_t update
16d0: 73 5f 70 65 72 5f 73 65 63 29 0a 7b 0a 20 20 20 s_per_sec).{.
16e0: 20 44 45 56 49 43 45 20 2a 70 74 68 72 6f 74 20 DEVICE *pthrot
16f0: 3d 20 66 69 6e 64 5f 64 65 76 20 28 22 49 4e 54 = find_dev ("INT
1700: 2d 54 48 52 4f 54 54 4c 45 22 29 3b 0a 20 20 20 -THROTTLE");.
1710: 20 69 66 20 28 70 74 68 72 6f 74 29 20 7b 0a 20 if (pthrot) {.
1720: 20 20 20 20 20 20 20 52 45 47 20 2a 70 74 79 70 REG *ptyp
1730: 65 72 20 3d 20 66 69 6e 64 5f 72 65 67 20 28 22 er = find_reg ("
1740: 54 48 52 4f 54 5f 54 59 50 45 22 2c 20 4e 55 4c THROT_TYPE", NUL
1750: 4c 2c 20 70 74 68 72 6f 74 29 3b 0a 20 20 20 20 L, pthrot);.
1760: 20 20 20 20 52 45 47 20 2a 70 76 61 6c 72 20 20 REG *pvalr
1770: 3d 20 66 69 6e 64 5f 72 65 67 20 28 22 54 48 52 = find_reg ("THR
1780: 4f 54 5f 56 41 4c 22 2c 20 4e 55 4c 4c 2c 20 70 OT_VAL", NULL, p
1790: 74 68 72 6f 74 29 3b 0a 20 20 20 20 20 20 20 20 throt);.
17a0: 69 66 20 28 70 74 79 70 65 72 20 26 26 20 70 76 if (ptyper && pv
17b0: 61 6c 72 29 20 7b 0a 20 20 20 20 20 20 20 20 20 alr) {.
17c0: 20 20 20 75 69 6e 74 33 32 20 2a 70 74 79 70 65 uint32 *ptype
17d0: 20 3d 20 70 74 79 70 65 72 2d 3e 6c 6f 63 3b 0a = ptyper->loc;.
17e0: 20 20 20 20 20 20 20 20 20 20 20 20 75 69 6e 74 uint
17f0: 33 32 20 2a 70 76 61 6c 20 20 3d 20 20 70 76 61 32 *pval = pva
1800: 6c 72 2d 3e 6c 6f 63 3b 0a 20 20 20 20 20 20 20 lr->loc;.
1810: 20 20 20 20 20 73 69 7a 65 5f 74 20 69 70 73 20 size_t ips
1820: 3d 20 30 3b 0a 20 20 20 20 20 20 20 20 20 20 20 = 0;.
1830: 20 73 77 69 74 63 68 20 28 2a 70 74 79 70 65 29 switch (*ptype)
1840: 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {.
1850: 20 20 20 63 61 73 65 20 53 49 4d 5f 54 48 52 4f case SIM_THRO
1860: 54 5f 4d 43 59 43 3a 20 69 70 73 20 3d 20 2a 70 T_MCYC: ips = *p
1870: 76 61 6c 20 2a 20 31 65 36 3b 20 62 72 65 61 6b val * 1e6; break
1880: 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;.
1890: 20 20 63 61 73 65 20 53 49 4d 5f 54 48 52 4f 54 case SIM_THROT
18a0: 5f 4b 43 59 43 3a 20 69 70 73 20 3d 20 2a 70 76 _KCYC: ips = *pv
18b0: 61 6c 20 2a 20 31 65 33 3b 20 62 72 65 61 6b 3b al * 1e3; break;
18c0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 . }.
18d0: 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 69 if (i
18e0: 70 73 29 20 7b 0a 20 20 20 20 20 20 20 20 20 20 ps) {.
18f0: 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 50 69 printf("Pi
1900: 44 50 2d 38 2f 49 20 69 6e 69 74 69 61 6c 20 74 DP-8/I initial t
1910: 68 72 6f 74 74 6c 65 20 3d 20 25 7a 75 20 49 50 hrottle = %zu IP
1920: 53 5c 72 5c 6e 22 2c 20 69 70 73 29 3b 0a 20 20 S\r\n", ips);.
1930: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 65 re
1940: 74 75 72 6e 20 69 70 73 20 2f 20 75 70 64 61 74 turn ips / updat
1950: 65 73 5f 70 65 72 5f 73 65 63 3b 0a 20 20 20 20 es_per_sec;.
1960: 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 }.
1970: 20 20 7d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f }. }.. /
1980: 2f 20 4e 6f 20 62 65 74 74 65 72 20 69 64 65 61 / No better idea
1990: 2c 20 73 6f 20 67 69 76 65 20 61 20 70 6c 61 75 , so give a plau
19a0: 73 69 62 6c 65 20 76 61 6c 75 65 20 66 6f 72 20 sible value for
19b0: 61 6e 20 75 6e 74 68 72 6f 74 74 6c 65 64 20 50 an unthrottled P
19c0: 69 20 31 0a 20 20 20 20 72 65 74 75 72 6e 20 32 i 1. return 2
19d0: 30 30 3b 0a 7d 0a 0a 0a 2f 2f 2f 2f 20 73 65 74 00;.}...//// set
19e0: 5f 70 69 64 70 38 69 5f 6c 65 64 73 20 2f 2f 2f _pidp8i_leds ///
19f0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1a00: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1a10: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
1a20: 0a 2f 2f 20 47 69 76 65 6e 20 61 6c 6c 20 6f 66 .// Given all of
1a30: 20 74 68 65 20 50 44 50 2d 38 27 73 20 69 6e 74 the PDP-8's int
1a40: 65 72 6e 61 6c 20 72 65 67 69 73 74 65 72 73 20 ernal registers
1a50: 74 68 61 74 20 61 66 66 65 63 74 20 74 68 65 20 that affect the
1a60: 66 72 6f 6e 74 0a 2f 2f 20 70 61 6e 65 6c 20 64 front.// panel d
1a70: 69 73 70 6c 61 79 2c 20 6d 6f 64 69 66 79 20 74 isplay, modify t
1a80: 68 65 20 47 50 49 4f 20 74 68 72 65 61 64 27 73 he GPIO thread's
1a90: 20 4c 45 44 20 73 74 61 74 65 20 76 61 6c 75 65 LED state value
1aa0: 73 20 61 63 63 6f 72 64 69 6e 67 6c 79 2e 0a 2f s accordingly../
1ab0: 2f 0a 2f 2f 20 41 6c 73 6f 20 75 70 64 61 74 65 /.// Also update
1ac0: 20 74 68 65 20 4c 45 44 20 62 72 69 67 68 74 6e the LED brightn
1ad0: 65 73 73 20 76 61 6c 75 65 73 20 62 61 73 65 64 ess values based
1ae0: 20 6f 6e 20 74 68 6f 73 65 20 6e 65 77 20 73 74 on those new st
1af0: 61 74 65 73 2e 0a 0a 76 6f 69 64 20 73 65 74 5f ates...void set_
1b00: 70 69 64 70 38 69 5f 6c 65 64 73 20 28 75 69 6e pidp8i_leds (uin
1b10: 74 33 32 20 73 50 43 2c 20 75 69 6e 74 33 32 20 t32 sPC, uint32
1b20: 73 4d 41 2c 20 75 69 6e 74 31 36 20 73 4d 42 2c sMA, uint16 sMB,
1b30: 0a 20 20 20 20 75 69 6e 74 31 36 20 73 49 52 2c . uint16 sIR,
1b40: 20 69 6e 74 33 32 20 73 4c 41 43 2c 20 69 6e 74 int32 sLAC, int
1b50: 33 32 20 73 4d 51 2c 20 69 6e 74 33 32 20 73 49 32 sMQ, int32 sI
1b60: 46 2c 20 69 6e 74 33 32 20 73 44 46 2c 0a 20 20 F, int32 sDF,.
1b70: 20 20 69 6e 74 33 32 20 73 53 43 2c 20 69 6e 74 int32 sSC, int
1b80: 33 32 20 69 6e 74 5f 72 65 71 2c 20 69 6e 74 20 32 int_req, int
1b90: 50 61 75 73 65 29 0a 7b 0a 20 20 20 20 2f 2f 20 Pause).{. //
1ba0: 42 75 6d 70 20 74 68 65 20 69 6e 73 74 72 75 63 Bump the instruc
1bb0: 74 69 6f 6e 20 63 6f 75 6e 74 2e 20 20 54 68 69 tion count. Thi
1bc0: 73 20 73 68 6f 75 6c 64 20 61 6c 77 61 79 73 20 s should always
1bd0: 62 65 20 65 71 75 61 6c 20 74 6f 20 74 68 65 0a be equal to the.
1be0: 20 20 20 20 2f 2f 20 46 65 74 63 68 20 4c 45 44 // Fetch LED
1bf0: 27 73 20 76 61 6c 75 65 2c 20 62 75 74 20 69 6e 's value, but in
1c00: 74 65 67 65 72 73 20 61 72 65 20 74 6f 6f 20 63 tegers are too c
1c10: 68 65 61 70 20 74 6f 20 67 65 74 20 63 75 74 65 heap to get cute
1c20: 20 68 65 72 65 2e 0a 20 20 20 20 2f 2f 0a 20 20 here.. //.
1c30: 20 20 2f 2f 20 4e 6f 74 65 20 74 68 61 74 20 77 // Note that w
1c40: 65 20 6f 6e 6c 79 20 75 70 64 61 74 65 20 70 64 e only update pd
1c50: 69 73 5f 75 70 64 61 74 65 20 64 69 72 65 63 74 is_update direct
1c60: 6c 79 20 6f 6e 63 65 20 69 6e 20 74 68 69 73 20 ly once in this
1c70: 77 68 6f 6c 65 0a 20 20 20 20 2f 2f 20 70 72 6f whole. // pro
1c80: 63 65 73 73 2e 20 20 54 68 69 73 20 69 73 20 69 cess. This is i
1c90: 6e 20 63 61 73 65 20 74 68 65 20 64 69 73 70 6c n case the displ
1ca0: 61 79 20 73 77 61 70 20 68 61 70 70 65 6e 73 20 ay swap happens
1cb0: 77 68 69 6c 65 20 77 65 27 72 65 0a 20 20 20 20 while we're.
1cc0: 2f 2f 20 77 6f 72 6b 69 6e 67 3a 20 77 65 20 77 // working: we w
1cd0: 61 6e 74 20 74 6f 20 66 69 6e 69 73 68 20 77 6f ant to finish wo
1ce0: 72 6b 20 6f 6e 20 74 68 65 20 73 61 6d 65 20 64 rk on the same d
1cf0: 69 73 70 6c 61 79 20 65 76 65 6e 20 74 68 6f 75 isplay even thou
1d00: 67 68 0a 20 20 20 20 2f 2f 20 69 74 27 73 20 6e gh. // it's n
1d10: 6f 77 20 63 61 6c 6c 65 64 20 74 68 65 20 70 61 ow called the pa
1d20: 69 6e 74 2d 66 72 6f 6d 20 64 69 73 70 6c 61 79 int-from display
1d30: 2c 20 73 6f 20 69 74 27 73 20 63 6f 6e 73 69 73 , so it's consis
1d40: 74 65 6e 74 2e 0a 20 20 20 20 64 69 73 70 6c 61 tent.. displa
1d50: 79 2a 20 70 64 20 3d 20 70 64 69 73 5f 75 70 64 y* pd = pdis_upd
1d60: 61 74 65 3b 0a 20 20 20 20 2b 2b 70 64 2d 3e 69 ate;. ++pd->i
1d70: 6e 73 74 5f 63 6f 75 6e 74 3b 0a 0a 20 20 20 20 nst_count;..
1d80: 2f 2f 20 52 6f 77 73 20 30 2d 34 2c 20 65 61 73 // Rows 0-4, eas
1d90: 79 20 63 61 73 65 73 3a 20 73 69 6e 67 6c 65 2d y cases: single-
1da0: 72 65 67 69 73 74 65 72 20 4c 45 44 20 73 74 72 register LED str
1db0: 69 6e 67 73 0a 20 20 20 20 73 65 74 5f 70 69 64 ings. set_pid
1dc0: 70 38 69 5f 72 6f 77 5f 6c 65 64 73 20 28 70 64 p8i_row_leds (pd
1dd0: 2c 20 30 2c 20 73 50 43 29 3b 0a 20 20 20 20 73 , 0, sPC);. s
1de0: 65 74 5f 70 69 64 70 38 69 5f 72 6f 77 5f 6c 65 et_pidp8i_row_le
1df0: 64 73 20 28 70 64 2c 20 31 2c 20 73 4d 41 29 3b ds (pd, 1, sMA);
1e00: 0a 20 20 20 20 73 65 74 5f 70 69 64 70 38 69 5f . set_pidp8i_
1e10: 72 6f 77 5f 6c 65 64 73 20 28 70 64 2c 20 32 2c row_leds (pd, 2,
1e20: 20 73 4d 42 29 3b 0a 20 20 20 20 73 65 74 5f 70 sMB);. set_p
1e30: 69 64 70 38 69 5f 72 6f 77 5f 6c 65 64 73 20 28 idp8i_row_leds (
1e40: 70 64 2c 20 33 2c 20 73 4c 41 43 20 26 20 30 37 pd, 3, sLAC & 07
1e50: 37 37 37 29 3b 0a 20 20 20 20 73 65 74 5f 70 69 777);. set_pi
1e60: 64 70 38 69 5f 72 6f 77 5f 6c 65 64 73 20 28 70 dp8i_row_leds (p
1e70: 64 2c 20 34 2c 20 73 4d 51 29 3b 0a 0a 20 20 20 d, 4, sMQ);..
1e80: 20 2f 2f 20 52 6f 77 20 35 61 3a 20 69 6e 73 74 // Row 5a: inst
1e90: 72 75 63 74 69 6f 6e 20 74 79 70 65 20 63 6f 6c ruction type col
1ea0: 75 6d 6e 2c 20 64 65 63 6f 64 65 64 20 66 72 6f umn, decoded fro
1eb0: 6d 20 68 69 67 68 20 6f 63 74 61 6c 0a 20 20 20 m high octal.
1ec0: 20 2f 2f 20 64 69 67 69 74 20 6f 66 20 49 52 20 // digit of IR
1ed0: 76 61 6c 75 65 0a 20 20 20 20 70 64 2d 3e 63 75 value. pd->cu
1ee0: 72 72 5b 35 5d 20 3d 20 30 3b 0a 20 20 20 20 75 rr[5] = 0;. u
1ef0: 69 6e 74 31 36 20 69 6e 73 74 5f 74 79 70 65 20 int16 inst_type
1f00: 3d 20 73 49 52 20 26 20 30 37 30 30 30 3b 0a 20 = sIR & 07000;.
1f10: 20 20 20 73 77 69 74 63 68 20 28 69 6e 73 74 5f switch (inst_
1f20: 74 79 70 65 29 20 7b 0a 20 20 20 20 20 20 20 20 type) {.
1f30: 63 61 73 65 20 30 30 30 30 30 3a 20 73 65 74 5f case 00000: set_
1f40: 70 69 64 70 38 69 5f 6c 65 64 20 28 70 64 2c 20 pidp8i_led (pd,
1f50: 35 2c 20 31 31 29 3b 20 62 72 65 61 6b 3b 20 2f 5, 11); break; /
1f60: 2f 20 30 30 30 20 41 4e 44 0a 20 20 20 20 20 20 / 000 AND.
1f70: 20 20 63 61 73 65 20 30 31 30 30 30 3a 20 73 65 case 01000: se
1f80: 74 5f 70 69 64 70 38 69 5f 6c 65 64 20 28 70 64 t_pidp8i_led (pd
1f90: 2c 20 35 2c 20 31 30 29 3b 20 62 72 65 61 6b 3b , 5, 10); break;
1fa0: 20 2f 2f 20 30 30 31 20 54 41 44 0a 20 20 20 20 // 001 TAD.
1fb0: 20 20 20 20 63 61 73 65 20 30 32 30 30 30 3a 20 case 02000:
1fc0: 73 65 74 5f 70 69 64 70 38 69 5f 6c 65 64 20 28 set_pidp8i_led (
1fd0: 70 64 2c 20 35 2c 20 20 39 29 3b 20 62 72 65 61 pd, 5, 9); brea
1fe0: 6b 3b 20 2f 2f 20 30 31 30 20 44 43 41 0a 20 20 k; // 010 DCA.
1ff0: 20 20 20 20 20 20 63 61 73 65 20 30 33 30 30 30 case 03000
2000: 3a 20 73 65 74 5f 70 69 64 70 38 69 5f 6c 65 64 : set_pidp8i_led
2010: 20 28 70 64 2c 20 35 2c 20 20 38 29 3b 20 62 72 (pd, 5, 8); br
2020: 65 61 6b 3b 20 2f 2f 20 30 31 31 20 49 53 5a 0a eak; // 011 ISZ.
2030: 20 20 20 20 20 20 20 20 63 61 73 65 20 30 34 30 case 040
2040: 30 30 3a 20 73 65 74 5f 70 69 64 70 38 69 5f 6c 00: set_pidp8i_l
2050: 65 64 20 28 70 64 2c 20 35 2c 20 20 37 29 3b 20 ed (pd, 5, 7);
2060: 62 72 65 61 6b 3b 20 2f 2f 20 31 30 30 20 4a 4d break; // 100 JM
2070: 53 0a 20 20 20 20 20 20 20 20 63 61 73 65 20 30 S. case 0
2080: 35 30 30 30 3a 20 73 65 74 5f 70 69 64 70 38 69 5000: set_pidp8i
2090: 5f 6c 65 64 20 28 70 64 2c 20 35 2c 20 20 36 29 _led (pd, 5, 6)
20a0: 3b 20 62 72 65 61 6b 3b 20 2f 2f 20 31 30 31 20 ; break; // 101
20b0: 4a 4d 50 0a 20 20 20 20 20 20 20 20 63 61 73 65 JMP. case
20c0: 20 30 36 30 30 30 3a 20 73 65 74 5f 70 69 64 70 06000: set_pidp
20d0: 38 69 5f 6c 65 64 20 28 70 64 2c 20 35 2c 20 20 8i_led (pd, 5,
20e0: 35 29 3b 20 62 72 65 61 6b 3b 20 2f 2f 20 31 31 5); break; // 11
20f0: 30 20 49 4f 54 0a 20 20 20 20 20 20 20 20 63 61 0 IOT. ca
2100: 73 65 20 30 37 30 30 30 3a 20 73 65 74 5f 70 69 se 07000: set_pi
2110: 64 70 38 69 5f 6c 65 64 20 28 70 64 2c 20 35 2c dp8i_led (pd, 5,
2120: 20 20 34 29 3b 20 62 72 65 61 6b 3b 20 2f 2f 20 4); break; //
2130: 31 31 31 20 4f 50 52 20 31 20 26 20 32 0a 20 20 111 OPR 1 & 2.
2140: 20 20 7d 0a 0a 20 20 20 20 2f 2f 20 52 6f 77 20 }.. // Row
2150: 35 62 3a 20 73 65 74 20 74 68 65 20 44 65 66 65 5b: set the Defe
2160: 72 20 4c 45 44 20 69 66 2e 2e 2e 0a 20 20 20 20 r LED if....
2170: 69 66 20 28 28 69 6e 73 74 5f 74 79 70 65 20 3c if ((inst_type <
2180: 3d 20 30 35 30 30 30 29 20 26 26 20 20 2f 2f 20 = 05000) && //
2190: 69 74 27 73 20 61 20 6d 65 6d 6f 72 79 20 72 65 it's a memory re
21a0: 66 65 72 65 6e 63 65 20 69 6e 73 74 72 75 63 74 ference instruct
21b0: 69 6f 6e 0a 20 20 20 20 20 20 20 20 20 20 20 20 ion.
21c0: 28 73 49 52 20 26 20 30 30 34 30 30 29 29 20 7b (sIR & 00400)) {
21d0: 20 20 20 20 20 2f 2f 20 61 6e 64 20 69 6e 64 69 // and indi
21e0: 72 65 63 74 20 61 64 64 72 65 73 73 69 6e 67 20 rect addressing
21f0: 66 6c 61 67 20 69 73 20 73 65 74 0a 20 20 20 20 flag is set.
2200: 20 20 20 20 73 65 74 5f 70 69 64 70 38 69 5f 6c set_pidp8i_l
2210: 65 64 20 28 70 64 2c 20 35 2c 20 31 29 3b 0a 20 ed (pd, 5, 1);.
2220: 20 20 20 7d 0a 0a 20 20 20 20 2f 2f 20 52 6f 77 }.. // Row
2230: 20 35 63 3a 20 54 68 65 20 46 65 74 63 68 20 4c 5c: The Fetch L
2240: 45 44 20 69 73 20 62 75 6d 70 65 64 20 6f 6e 63 ED is bumped onc
2250: 65 20 70 65 72 20 43 50 55 20 69 6e 73 74 72 75 e per CPU instru
2260: 63 74 69 6f 6e 2c 20 61 73 20 69 73 0a 20 20 20 ction, as is.
2270: 20 2f 2f 20 45 78 65 63 75 74 65 20 77 68 69 6c // Execute whil
2280: 65 20 77 65 27 72 65 20 6e 6f 74 20 69 6e 20 53 e we're not in S
2290: 54 4f 50 20 73 74 61 74 65 2e 20 20 54 68 65 79 TOP state. They
22a0: 27 72 65 20 73 65 74 20 61 74 20 64 69 66 66 65 're set at diffe
22b0: 72 65 6e 74 0a 20 20 20 20 2f 2f 20 74 69 6d 65 rent. // time
22c0: 73 2c 20 62 75 74 20 74 68 65 79 27 72 65 20 74 s, but they're t
22d0: 77 69 64 64 6c 65 64 20 73 6f 20 72 61 70 69 64 widdled so rapid
22e0: 6c 79 20 74 68 61 74 20 74 68 65 79 20 62 6f 74 ly that they bot
22f0: 68 20 6a 75 73 74 20 62 65 63 6f 6d 65 0a 20 20 h just become.
2300: 20 20 2f 2f 20 61 20 35 30 25 20 62 6c 75 72 20 // a 50% blur
2310: 69 6e 20 6e 6f 72 6d 61 6c 20 6f 70 65 72 61 74 in normal operat
2320: 69 6f 6e 2c 20 73 6f 20 77 65 20 64 6f 6e 27 74 ion, so we don't
2330: 20 6d 61 6b 65 20 74 68 65 20 43 50 55 20 63 6f make the CPU co
2340: 72 65 20 73 65 74 0a 20 20 20 20 2f 2f 20 74 68 re set. // th
2350: 65 73 65 20 22 6f 6e 2d 74 69 6d 65 2e 22 20 20 ese "on-time."
2360: 49 74 20 6a 75 73 74 20 64 6f 65 73 6e 27 74 20 It just doesn't
2370: 6d 61 74 74 65 72 2e 0a 20 20 20 20 69 66 20 28 matter.. if (
2380: 21 73 77 53 74 6f 70 29 20 73 65 74 5f 70 69 64 !swStop) set_pid
2390: 70 38 69 5f 6c 65 64 20 28 70 64 2c 20 35 2c 20 p8i_led (pd, 5,
23a0: 32 29 3b 20 20 20 20 2f 2f 20 45 78 65 63 75 74 2); // Execut
23b0: 65 0a 20 20 20 20 73 65 74 5f 70 69 64 70 38 69 e. set_pidp8i
23c0: 5f 6c 65 64 20 28 70 64 2c 20 35 2c 20 33 29 3b _led (pd, 5, 3);
23d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23e0: 20 2f 2f 20 46 65 74 63 68 0a 0a 20 20 20 20 2f // Fetch.. /
23f0: 2f 20 52 6f 77 20 36 61 3a 20 52 65 6d 61 69 6e / Row 6a: Remain
2400: 69 6e 67 20 4c 45 44 73 20 69 6e 20 75 70 70 65 ing LEDs in uppe
2410: 72 20 72 69 67 68 74 20 62 6c 6f 63 6b 0a 20 20 r right block.
2420: 20 20 70 64 2d 3e 63 75 72 72 5b 36 5d 20 3d 20 pd->curr[6] =
2430: 30 3b 0a 20 20 20 20 69 66 20 28 73 77 53 74 6f 0;. if (swSto
2440: 70 20 3d 3d 20 30 29 20 20 20 20 20 20 20 73 65 p == 0) se
2450: 74 5f 70 69 64 70 38 69 5f 6c 65 64 20 28 70 64 t_pidp8i_led (pd
2460: 2c 20 36 2c 20 37 29 3b 20 2f 2f 20 62 75 6d 70 , 6, 7); // bump
2470: 20 52 75 6e 20 4c 45 44 0a 20 20 20 20 69 66 20 Run LED. if
2480: 28 50 61 75 73 65 29 20 20 20 20 20 20 20 20 20 (Pause)
2490: 20 20 20 20 73 65 74 5f 70 69 64 70 38 69 5f 6c set_pidp8i_l
24a0: 65 64 20 28 70 64 2c 20 36 2c 20 38 29 3b 20 2f ed (pd, 6, 8); /
24b0: 2f 20 62 75 6d 70 20 50 61 75 73 65 20 4c 45 44 / bump Pause LED
24c0: 0a 20 20 20 20 69 66 20 28 69 6e 74 5f 72 65 71 . if (int_req
24d0: 20 26 20 49 4e 54 5f 49 4f 4e 29 20 73 65 74 5f & INT_ION) set_
24e0: 70 69 64 70 38 69 5f 6c 65 64 20 28 70 64 2c 20 pidp8i_led (pd,
24f0: 36 2c 20 39 29 3b 20 2f 2f 20 62 75 6d 70 20 49 6, 9); // bump I
2500: 4f 4e 20 4c 45 44 0a 0a 20 20 20 20 2f 2f 20 52 ON LED.. // R
2510: 6f 77 20 36 62 3a 20 54 68 65 20 53 74 65 70 20 ow 6b: The Step
2520: 43 6f 75 6e 74 20 4c 45 44 73 20 61 72 65 20 61 Count LEDs are a
2530: 6c 73 6f 20 6f 6e 20 72 6f 77 20 36 0a 20 20 20 lso on row 6.
2540: 20 73 65 74 5f 35 5f 70 69 64 70 38 69 5f 6c 65 set_5_pidp8i_le
2550: 64 73 20 28 70 64 2c 20 73 53 43 29 3b 0a 0a 20 ds (pd, sSC);..
2560: 20 20 20 2f 2f 20 52 6f 77 20 37 3a 20 44 46 2c // Row 7: DF,
2570: 20 49 46 2c 20 61 6e 64 20 4c 69 6e 6b 2e 0a 20 IF, and Link..
2580: 20 20 20 70 64 2d 3e 63 75 72 72 5b 37 5d 20 3d pd->curr[7] =
2590: 20 30 3b 0a 20 20 20 20 73 65 74 5f 33 5f 70 69 0;. set_3_pi
25a0: 64 70 38 69 5f 6c 65 64 73 20 28 70 64 2c 20 39 dp8i_leds (pd, 9
25b0: 2c 20 73 44 46 29 3b 0a 20 20 20 20 73 65 74 5f , sDF);. set_
25c0: 33 5f 70 69 64 70 38 69 5f 6c 65 64 73 20 28 70 3_pidp8i_leds (p
25d0: 64 2c 20 36 2c 20 73 49 46 29 3b 0a 20 20 20 20 d, 6, sIF);.
25e0: 69 66 20 28 73 4c 41 43 20 26 20 30 31 30 30 30 if (sLAC & 01000
25f0: 30 29 20 73 65 74 5f 70 69 64 70 38 69 5f 6c 65 0) set_pidp8i_le
2600: 64 20 28 70 64 2c 20 37 2c 20 35 29 3b 0a 7d 0a d (pd, 7, 5);.}.
2610: 0a 0a 2f 2f 2f 2f 20 6d 6f 75 6e 74 5f 75 73 62 ..//// mount_usb
2620: 5f 73 74 69 63 6b 5f 66 69 6c 65 20 2f 2f 2f 2f _stick_file ////
2630: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
2640: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
2650: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0a 2f 2f 20 53 65 //////////.// Se
2660: 61 72 63 68 20 66 6f 72 20 61 20 50 44 50 2d 38 arch for a PDP-8
2670: 20 6d 65 64 69 61 20 69 6d 61 67 65 20 69 6e 20 media image in
2680: 6f 6e 65 20 6f 66 20 74 68 65 20 50 69 27 73 20 one of the Pi's
2690: 55 53 42 20 61 75 74 6f 2d 6d 6f 75 6e 74 0a 2f USB auto-mount./
26a0: 2f 20 64 69 72 65 63 74 6f 72 69 65 73 20 61 6e / directories an
26b0: 64 20 61 74 74 65 6d 70 74 20 74 6f 20 41 54 54 d attempt to ATT
26c0: 41 43 48 20 69 74 20 74 6f 20 74 68 65 20 73 69 ACH it to the si
26d0: 6d 75 6c 61 74 6f 72 2e 0a 0a 73 74 61 74 69 63 mulator...static
26e0: 20 76 6f 69 64 20 6d 6f 75 6e 74 5f 75 73 62 5f void mount_usb_
26f0: 73 74 69 63 6b 5f 66 69 6c 65 20 28 69 6e 74 20 stick_file (int
2700: 64 65 76 4e 6f 2c 20 63 68 61 72 20 2a 64 65 76 devNo, char *dev
2710: 43 6f 64 65 29 0a 7b 0a 20 20 20 20 63 68 61 72 Code).{. char
2720: 20 20 20 20 73 46 6f 75 6e 64 46 69 6c 65 5b 43 sFoundFile[C
2730: 42 55 46 53 49 5a 45 5d 20 3d 20 7b 20 27 5c 30 BUFSIZE] = { '\0
2740: 27 20 7d 3b 0a 20 20 20 20 63 68 61 72 20 20 20 ' };. char
2750: 20 73 55 53 42 50 61 74 68 5b 43 42 55 46 53 49 sUSBPath[CBUFSI
2760: 5a 45 5d 3b 20 20 20 20 20 2f 2f 20 77 69 6c 6c ZE]; // will
2770: 20 62 65 20 22 2f 6d 65 64 69 61 2f 75 73 62 30 be "/media/usb0
2780: 22 20 65 74 63 0a 20 20 20 20 63 68 61 72 20 20 " etc. char
2790: 20 20 66 69 6c 65 45 78 74 65 6e 73 69 6f 6e 5b fileExtension[
27a0: 34 5d 3b 20 20 20 20 20 20 20 2f 2f 20 77 69 6c 4]; // wil
27b0: 6c 20 62 65 20 22 2e 52 58 22 20 65 74 63 0a 20 l be ".RX" etc.
27c0: 20 20 20 69 6e 74 20 20 20 20 20 69 2c 20 6a 3b int i, j;
27d0: 0a 0a 20 20 20 20 2f 2f 20 42 75 69 6c 64 20 65 .. // Build e
27e0: 78 70 65 63 74 65 64 20 66 69 6c 65 20 6e 61 6d xpected file nam
27f0: 65 20 65 78 74 65 6e 73 69 6f 6e 20 66 72 6f 6d e extension from
2800: 20 74 68 65 20 66 69 72 73 74 20 74 77 6f 20 63 the first two c
2810: 68 61 72 61 63 74 65 72 73 20 6f 66 0a 20 20 20 haracters of.
2820: 20 2f 2f 20 74 68 65 20 70 61 73 73 65 64 2d 69 // the passed-i
2830: 6e 20 64 65 76 69 63 65 20 63 6f 64 65 2e 0a 20 n device code..
2840: 20 20 20 66 69 6c 65 45 78 74 65 6e 73 69 6f 6e fileExtension
2850: 5b 30 5d 20 3d 20 27 2e 27 3b 20 20 20 20 20 20 [0] = '.';
2860: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
2870: 2f 20 65 78 74 65 6e 73 69 6f 6e 20 73 74 61 72 / extension star
2880: 74 73 20 77 69 74 68 20 61 20 2e 0a 20 20 20 20 ts with a ..
2890: 73 74 72 6e 63 70 79 20 28 66 69 6c 65 45 78 74 strncpy (fileExt
28a0: 65 6e 73 69 6f 6e 20 2b 20 31 2c 20 64 65 76 43 ension + 1, devC
28b0: 6f 64 65 2c 20 32 29 3b 20 20 20 20 2f 2f 20 65 ode, 2); // e
28c0: 78 74 65 6e 73 69 6f 6e 20 69 73 20 50 54 2c 20 xtension is PT,
28d0: 52 58 2c 20 52 4c 20 65 74 63 0a 20 20 20 20 66 RX, RL etc. f
28e0: 69 6c 65 45 78 74 65 6e 73 69 6f 6e 5b 32 5d 20 ileExtension[2]
28f0: 3d 20 27 5c 30 27 3b 20 20 20 20 20 20 20 20 20 = '\0';
2900: 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 63 68 // ch
2910: 6f 70 20 6f 66 66 20 64 65 76 69 63 65 20 6e 75 op off device nu
2920: 6d 62 65 72 0a 0a 20 20 20 20 2f 2f 20 46 6f 72 mber.. // For
2930: 67 65 74 20 74 68 65 20 70 72 69 6f 72 20 66 69 get the prior fi
2940: 6c 65 20 61 74 74 61 63 68 65 64 20 74 6f 20 74 le attached to t
2950: 68 69 73 20 50 44 50 2d 38 20 64 65 76 69 63 65 his PDP-8 device
2960: 2e 20 20 54 68 65 20 6f 6e 6c 79 20 72 65 61 73 . The only reas
2970: 6f 6e 0a 20 20 20 20 2f 2f 20 77 65 20 6b 65 65 on. // we kee
2980: 70 20 74 72 61 63 6b 20 69 73 20 73 6f 20 77 65 p track is so we
2990: 20 64 6f 6e 27 74 20 68 61 76 65 20 74 68 65 20 don't have the
29a0: 73 61 6d 65 20 6d 65 64 69 61 20 69 6d 61 67 65 same media image
29b0: 20 66 69 6c 65 20 61 74 74 61 63 68 65 64 0a 20 file attached.
29c0: 20 20 20 2f 2f 20 74 6f 20 62 6f 74 68 20 64 65 // to both de
29d0: 76 69 63 65 73 20 6f 66 20 61 20 67 69 76 65 6e vices of a given
29e0: 20 74 79 70 65 20 77 65 20 73 75 70 70 6f 72 74 type we support
29f0: 2e 20 20 54 68 61 74 20 69 73 2c 20 79 6f 75 20 . That is, you
2a00: 63 61 6e 27 74 20 68 61 76 65 0a 20 20 20 20 2f can't have. /
2a10: 2f 20 61 20 67 69 76 65 6e 20 66 6c 6f 70 70 79 / a given floppy
2a20: 20 69 6d 61 67 65 20 66 69 6c 65 20 61 74 74 61 image file atta
2a30: 63 68 65 64 20 74 6f 20 62 6f 74 68 20 52 58 30 ched to both RX0
2a40: 31 20 64 72 69 76 65 73 2c 20 62 75 74 20 79 6f 1 drives, but yo
2a50: 75 20 2a 63 61 6e 2a 0a 20 20 20 20 2f 2f 20 72 u *can*. // r
2a60: 65 70 65 61 74 65 64 6c 79 20 72 65 2d 41 54 54 epeatedly re-ATT
2a70: 41 43 48 20 74 68 65 20 73 61 6d 65 20 66 6c 6f ACH the same flo
2a80: 70 70 79 20 69 6d 61 67 65 20 74 6f 20 74 68 65 ppy image to the
2a90: 20 66 69 72 73 74 20 52 58 30 31 20 64 72 69 76 first RX01 driv
2aa0: 65 2e 0a 20 20 20 20 73 74 61 74 69 63 20 63 68 e.. static ch
2ab0: 61 72 20 6d 6f 75 6e 74 65 64 46 69 6c 65 73 5b ar mountedFiles[
2ac0: 38 5d 5b 43 42 55 46 53 49 5a 45 5d 3b 0a 20 20 8][CBUFSIZE];.
2ad0: 20 20 6d 6f 75 6e 74 65 64 46 69 6c 65 73 5b 64 mountedFiles[d
2ae0: 65 76 4e 6f 5d 5b 30 5d 20 3d 20 27 5c 30 27 3b evNo][0] = '\0';
2af0: 0a 0a 20 20 20 20 66 6f 72 20 28 69 20 3d 20 30 .. for (i = 0
2b00: 3b 20 69 20 3c 20 38 20 26 26 20 73 46 6f 75 6e ; i < 8 && sFoun
2b10: 64 46 69 6c 65 5b 30 5d 20 3d 3d 20 27 5c 30 27 dFile[0] == '\0'
2b20: 3b 20 2b 2b 69 29 20 7b 0a 20 20 20 20 20 20 20 ; ++i) {.
2b30: 20 2f 2f 20 73 65 61 72 63 68 20 61 6c 6c 20 38 // search all 8
2b40: 20 55 53 42 20 6d 6f 75 6e 74 20 70 6f 69 6e 74 USB mount point
2b50: 73 2c 20 6e 75 6d 62 65 72 65 64 20 30 2d 37 0a s, numbered 0-7.
2b60: 20 20 20 20 20 20 20 20 73 6e 70 72 69 6e 74 66 snprintf
2b70: 20 28 73 55 53 42 50 61 74 68 2c 20 73 69 7a 65 (sUSBPath, size
2b80: 6f 66 20 28 73 55 53 42 50 61 74 68 29 2c 20 22 of (sUSBPath), "
2b90: 2f 6d 65 64 69 61 2f 75 73 62 25 64 22 2c 20 69 /media/usb%d", i
2ba0: 29 3b 0a 20 20 20 20 20 20 20 20 44 49 52 20 2a );. DIR *
2bb0: 70 44 69 72 20 3d 20 6f 70 65 6e 64 69 72 20 28 pDir = opendir (
2bc0: 73 55 53 42 50 61 74 68 29 3b 0a 20 20 20 20 20 sUSBPath);.
2bd0: 20 20 20 69 66 20 28 70 44 69 72 29 20 7b 0a 20 if (pDir) {.
2be0: 20 20 20 20 20 20 20 20 20 20 20 73 74 72 75 63 struc
2bf0: 74 20 64 69 72 65 6e 74 2a 20 70 44 69 72 65 6e t dirent* pDiren
2c00: 74 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 77 t;. w
2c10: 68 69 6c 65 20 28 28 70 44 69 72 65 6e 74 20 3d hile ((pDirent =
2c20: 20 72 65 61 64 64 69 72 20 28 70 44 69 72 29 29 readdir (pDir))
2c30: 20 21 3d 20 30 29 20 7b 20 2f 2f 20 73 65 61 72 != 0) { // sear
2c40: 63 68 20 61 6c 6c 20 66 69 6c 65 73 20 69 6e 20 ch all files in
2c50: 64 69 72 65 63 74 6f 72 79 0a 20 20 20 20 20 20 directory.
2c60: 20 20 20 20 20 20 20 20 20 20 69 66 20 28 73 74 if (st
2c70: 72 73 74 72 20 28 70 44 69 72 65 6e 74 2d 3e 64 rstr (pDirent->d
2c80: 5f 6e 61 6d 65 2c 20 66 69 6c 65 45 78 74 65 6e _name, fileExten
2c90: 73 69 6f 6e 29 29 20 7b 0a 20 20 20 20 20 20 20 sion)) {.
2ca0: 20 20 20 20 20 20 20 20 20 20 20 20 20 73 6e 70 snp
2cb0: 72 69 6e 74 66 20 28 73 46 6f 75 6e 64 46 69 6c rintf (sFoundFil
2cc0: 65 2c 20 73 69 7a 65 6f 66 20 28 73 46 6f 75 6e e, sizeof (sFoun
2cd0: 64 46 69 6c 65 29 2c 20 22 25 73 2f 25 73 22 2c dFile), "%s/%s",
2ce0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
2cf0: 20 20 20 20 20 20 20 20 20 20 20 20 20 73 55 53 sUS
2d00: 42 50 61 74 68 2c 20 70 44 69 72 65 6e 74 2d 3e BPath, pDirent->
2d10: 64 5f 6e 61 6d 65 29 3b 0a 20 20 20 20 20 20 20 d_name);.
2d20: 20 20 20 20 20 20 20 20 20 20 20 20 20 66 6f 72 for
2d30: 20 28 6a 20 3d 20 30 3b 20 6a 20 3c 20 37 3b 20 (j = 0; j < 7;
2d40: 2b 2b 6a 29 20 7b 0a 20 20 20 20 20 20 20 20 20 ++j) {.
2d50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
2d60: 66 20 28 73 74 72 6e 63 6d 70 20 28 6d 6f 75 6e f (strncmp (moun
2d70: 74 65 64 46 69 6c 65 73 5b 6a 5d 2c 20 73 46 6f tedFiles[j], sFo
2d80: 75 6e 64 46 69 6c 65 2c 20 43 42 55 46 53 49 5a undFile, CBUFSIZ
2d90: 45 29 20 3d 3d 20 30 29 20 7b 0a 20 20 20 20 20 E) == 0) {.
2da0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2db0: 20 20 20 20 20 20 20 62 72 65 61 6b 3b 20 20 2f break; /
2dc0: 2f 20 61 6c 72 65 61 64 79 20 6d 6f 75 6e 74 65 / already mounte
2dd0: 64 3b 20 73 6b 69 70 20 6e 65 78 74 0a 20 20 20 d; skip next.
2de0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2df0: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 20 }.
2e00: 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 20 20 }.
2e10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2e20: 20 69 66 20 28 6a 20 3d 3d 20 37 29 20 7b 0a 20 if (j == 7) {.
2e30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2e40: 20 20 20 20 20 20 20 2f 2f 20 4d 65 64 69 61 20 // Media
2e50: 69 6d 61 67 65 20 66 69 6c 65 20 69 73 20 6e 6f image file is no
2e60: 74 20 61 6c 72 65 61 64 79 20 6d 6f 75 6e 74 65 t already mounte
2e70: 64 2c 20 73 6f 20 6c 65 61 76 65 20 77 68 69 6c d, so leave whil
2e80: 65 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e.
2e90: 20 20 20 20 20 20 20 20 20 20 2f 2f 20 6c 6f 6f // loo
2ea0: 70 20 77 69 74 68 20 70 61 74 68 20 73 65 74 20 p with path set
2eb0: 74 6f 20 6d 6f 75 6e 74 20 69 74 0a 20 20 20 20 to mount it.
2ec0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2ed0: 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 break;.
2ee0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
2ef0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
2f00: 20 20 20 20 20 65 6c 73 65 20 7b 0a 20 20 20 20 else {.
2f10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2f20: 20 20 20 20 2f 2f 20 49 74 27 73 20 6d 6f 75 6e // It's moun
2f30: 74 65 64 2c 20 73 6f 20 66 6f 72 67 65 74 20 69 ted, so forget i
2f40: 74 73 20 70 61 74 68 2c 20 65 6c 73 65 20 77 65 ts path, else we
2f50: 20 77 69 6c 6c 20 73 74 6f 70 0a 20 20 20 20 20 will stop.
2f60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2f70: 20 20 20 2f 2f 20 73 65 61 72 63 68 69 6e 67 20 // searching
2f80: 74 68 65 20 6f 74 68 65 72 20 55 53 42 20 6d 6f the other USB mo
2f90: 75 6e 74 20 70 6f 69 6e 74 73 0a 20 20 20 20 20 unt points.
2fa0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2fb0: 20 20 20 73 46 6f 75 6e 64 46 69 6c 65 5b 30 5d sFoundFile[0]
2fc0: 20 3d 20 27 5c 30 27 3b 0a 20 20 20 20 20 20 20 = '\0';.
2fd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 }.
2fe0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d }
2ff0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 0a . }..
3000: 20 20 20 20 20 20 20 20 20 20 20 20 63 6c 6f 73 clos
3010: 65 64 69 72 20 28 70 44 69 72 29 3b 0a 20 20 20 edir (pDir);.
3020: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 65 }. e
3030: 6c 73 65 20 7b 0a 20 20 20 20 20 20 20 20 20 20 lse {.
3040: 20 20 2f 2f 20 4e 6f 74 20 61 20 50 69 20 6f 72 // Not a Pi or
3050: 20 74 68 65 20 55 53 42 20 61 75 74 6f 2d 6d 6f the USB auto-mo
3060: 75 6e 74 69 6e 67 20 73 6f 66 74 77 61 72 65 20 unting software
3070: 69 73 6e 27 74 20 69 6e 73 74 61 6c 6c 65 64 0a isn't installed.
3080: 20 20 20 20 20 20 20 20 20 20 20 20 70 72 69 6e prin
3090: 74 66 20 28 22 5c 72 5c 6e 43 61 6e 6e 6f 74 20 tf ("\r\nCannot
30a0: 6f 70 65 6e 20 25 73 3a 20 25 73 5c 72 5c 6e 22 open %s: %s\r\n"
30b0: 2c 20 73 55 53 42 50 61 74 68 2c 20 73 74 72 65 , sUSBPath, stre
30c0: 72 72 6f 72 20 28 65 72 72 6e 6f 29 29 3b 0a 20 rror (errno));.
30d0: 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 retur
30e0: 6e 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 n;. }.
30f0: 20 7d 0a 0a 20 20 20 20 69 66 20 28 73 46 6f 75 }.. if (sFou
3100: 6e 64 46 69 6c 65 5b 30 5d 29 20 7b 20 20 20 20 ndFile[0]) {
3110: 20 20 20 20 20 20 20 20 2f 2f 20 6e 6f 20 66 69 // no fi
3120: 6c 65 20 66 6f 75 6e 64 2c 20 65 78 69 74 0a 20 le found, exit.
3130: 20 20 20 20 20 20 20 69 66 20 28 61 63 63 65 73 if (acces
3140: 73 20 28 73 46 6f 75 6e 64 46 69 6c 65 2c 20 52 s (sFoundFile, R
3150: 5f 4f 4b 29 20 3d 3d 20 30 29 20 7b 0a 20 20 20 _OK) == 0) {.
3160: 20 20 20 20 20 20 20 20 20 69 66 20 28 61 74 74 if (att
3170: 61 63 68 5f 63 6d 64 20 28 28 69 6e 74 33 32 29 ach_cmd ((int32)
3180: 20 30 2c 20 73 46 6f 75 6e 64 46 69 6c 65 29 20 0, sFoundFile)
3190: 3d 3d 20 53 43 50 45 5f 4f 4b 29 20 7b 20 20 20 == SCPE_OK) {
31a0: 2f 2f 20 69 73 73 75 65 20 41 54 54 41 43 48 20 // issue ATTACH
31b0: 63 6f 6d 6d 61 6e 64 0a 20 20 20 20 20 20 20 20 command.
31c0: 20 20 20 20 20 20 20 20 2f 2f 20 61 64 64 20 66 // add f
31d0: 69 6c 65 20 74 6f 20 6d 6f 75 6e 74 20 6c 69 73 ile to mount lis
31e0: 74 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 t.
31f0: 20 20 73 74 72 6e 63 70 79 20 28 6d 6f 75 6e 74 strncpy (mount
3200: 65 64 46 69 6c 65 73 5b 64 65 76 4e 6f 5d 2c 20 edFiles[devNo],
3210: 73 46 6f 75 6e 64 46 69 6c 65 2c 20 43 42 55 46 sFoundFile, CBUF
3220: 53 49 5a 45 29 3b 0a 20 20 20 20 20 20 20 20 20 SIZE);.
3230: 20 20 20 20 20 20 20 70 72 69 6e 74 66 20 28 22 printf ("
3240: 5c 72 5c 6e 4d 6f 75 6e 74 65 64 20 25 73 20 25 \r\nMounted %s %
3250: 73 5c 72 5c 6e 22 2c 20 64 65 76 43 6f 64 65 2c s\r\n", devCode,
3260: 20 6d 6f 75 6e 74 65 64 46 69 6c 65 73 5b 64 65 mountedFiles[de
3270: 76 4e 6f 5d 29 3b 0a 20 20 20 20 20 20 20 20 20 vNo]);.
3280: 20 20 20 7d 0a 20 20 20 20 20 20 20 20 20 20 20 }.
3290: 20 65 6c 73 65 20 7b 0a 20 20 20 20 20 20 20 20 else {.
32a0: 20 20 20 20 20 20 20 20 70 72 69 6e 74 66 20 28 printf (
32b0: 22 5c 72 5c 6e 53 49 4d 48 20 65 72 72 6f 72 20 "\r\nSIMH error
32c0: 6d 6f 75 6e 74 69 6e 67 20 25 73 5c 72 5c 6e 22 mounting %s\r\n"
32d0: 2c 20 64 65 76 43 6f 64 65 29 3b 0a 20 20 20 20 , devCode);.
32e0: 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 }.
32f0: 20 20 7d 0a 20 20 20 20 20 20 20 20 65 6c 73 65 }. else
3300: 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 70 {. p
3310: 72 69 6e 74 66 20 28 22 5c 72 5c 6e 43 61 6e 6e rintf ("\r\nCann
3320: 6f 74 20 72 65 61 64 20 6d 65 64 69 75 6d 20 69 ot read medium i
3330: 6d 61 67 65 20 25 73 20 66 72 6f 6d 20 55 53 42 mage %s from USB
3340: 3a 20 25 73 5c 72 5c 6e 22 2c 0a 20 20 20 20 20 : %s\r\n",.
3350: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 s
3360: 46 6f 75 6e 64 46 69 6c 65 2c 20 73 74 72 65 72 FoundFile, strer
3370: 72 6f 72 20 28 65 72 72 6e 6f 29 29 3b 0a 20 20 ror (errno));.
3380: 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 }. }.
3390: 20 20 65 6c 73 65 20 7b 0a 20 20 20 20 20 20 20 else {.
33a0: 20 70 72 69 6e 74 66 20 28 22 5c 72 5c 6e 4e 6f printf ("\r\nNo
33b0: 20 75 6e 6d 6f 75 6e 74 65 64 20 25 73 20 66 69 unmounted %s fi
33c0: 6c 65 20 66 6f 75 6e 64 5c 72 5c 6e 22 2c 20 64 le found\r\n", d
33d0: 65 76 43 6f 64 65 29 3b 0a 20 20 20 20 7d 0a 7d evCode);. }.}
33e0: 0a 0a 0a 2f 2f 2f 2f 20 68 61 6e 64 6c 65 5f 73 ...//// handle_s
33f0: 69 6e 67 5f 73 74 65 70 20 2f 2f 2f 2f 2f 2f 2f ing_step ///////
3400: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
3410: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
3420: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0a 2f 2f 20 48 ///////////.// H
3430: 61 6e 64 6c 65 20 53 49 4e 47 5f 53 54 45 50 20 andle SING_STEP
3440: 63 6f 6d 62 69 6e 61 74 69 6f 6e 73 20 61 73 20 combinations as
3450: 6e 6f 6e 73 74 61 6e 64 61 72 64 20 66 75 6e 63 nonstandard func
3460: 74 69 6f 6e 73 20 77 69 74 68 20 72 65 73 70 65 tions with respe
3470: 63 74 0a 2f 2f 20 74 6f 20 61 20 72 65 61 6c 20 ct.// to a real
3480: 50 44 50 2d 38 2c 20 73 69 6e 63 65 20 53 49 4d PDP-8, since SIM
3490: 48 20 64 6f 65 73 6e 27 74 20 74 72 79 20 74 6f H doesn't try to
34a0: 20 65 6d 75 6c 61 74 65 20 74 68 65 20 50 44 50 emulate the PDP
34b0: 2d 38 27 73 0a 2f 2f 20 73 69 6e 67 6c 65 2d 73 -8's.// single-s
34c0: 74 65 70 70 69 6e 67 20 6d 6f 64 65 20 e2 80 94 tepping mode —
34d0: 20 6e 6f 74 20 74 6f 20 62 65 20 63 6f 6e 66 75 not to be confu
34e0: 73 65 64 20 77 69 74 68 20 73 69 6e 67 6c 65 2d sed with single-
34f0: 69 6e 73 74 72 75 63 74 69 6f 6e 0a 2f 2f 20 6d instruction.// m
3500: 6f 64 65 2c 20 77 68 69 63 68 20 53 49 4d 48 20 ode, which SIMH
3510: 2a 64 6f 65 73 2a 20 65 6d 75 6c 61 74 65 20 e2 *does* emulate â
3520: 80 94 20 73 6f 20 74 68 65 20 53 49 4e 47 5f 53 €” so the SING_S
3530: 54 45 50 20 73 77 69 74 63 68 20 69 73 20 66 72 TEP switch is fr
3540: 65 65 0a 2f 2f 20 66 6f 72 20 6f 75 72 20 6e 6f ee.// for our no
3550: 6e 73 74 61 6e 64 61 72 64 20 75 73 65 73 2e 0a nstandard uses..
3560: 2f 2f 0a 2f 2f 20 54 68 69 73 20 69 73 20 73 65 //.// This is se
3570: 70 61 72 61 74 65 20 66 72 6f 6d 20 68 61 6e 64 parate from hand
3580: 6c 65 5f 66 6c 6f 77 5f 63 6f 6e 74 72 6f 6c 5f le_flow_control_
3590: 73 77 69 74 63 68 65 73 20 6f 6e 6c 79 20 62 65 switches only be
35a0: 63 61 75 73 65 0a 2f 2f 20 74 68 65 72 65 20 61 cause.// there a
35b0: 72 65 20 73 6f 20 6d 61 6e 79 20 63 61 73 65 73 re so many cases
35c0: 20 68 65 72 65 20 74 68 61 74 20 69 74 20 77 6f here that it wo
35d0: 75 6c 64 20 6f 62 73 63 75 72 65 20 74 68 65 20 uld obscure the
35e0: 6f 76 65 72 61 6c 6c 20 66 6c 6f 77 0a 2f 2f 20 overall flow.//
35f0: 6f 66 20 6f 75 72 20 63 61 6c 6c 69 6e 67 20 66 of our calling f
3600: 75 6e 63 74 69 6f 6e 20 74 6f 20 64 6f 20 61 6c unction to do al
3610: 6c 20 74 68 69 73 20 74 68 65 72 65 2e 0a 0a 73 l this there...s
3620: 74 61 74 69 63 20 70 69 64 70 38 69 5f 66 6c 6f tatic pidp8i_flo
3630: 77 5f 74 20 68 61 6e 64 6c 65 5f 73 69 6e 67 5f w_t handle_sing_
3640: 73 74 65 70 20 28 69 6e 74 20 63 6c 6f 73 65 64 step (int closed
3650: 29 0a 7b 0a 20 20 20 20 2f 2f 20 49 66 20 53 49 ).{. // If SI
3660: 4e 47 5f 53 54 45 50 20 69 73 20 6f 70 65 6e 2c NG_STEP is open,
3670: 20 77 65 20 64 6f 20 6e 6f 74 68 69 6e 67 20 68 we do nothing h
3680: 65 72 65 20 65 78 63 65 70 74 20 72 65 73 65 74 ere except reset
3690: 20 74 68 65 20 73 69 6e 67 6c 65 2d 73 68 6f 74 the single-shot
36a0: 0a 20 20 20 20 2f 2f 20 66 6c 61 67 20 69 66 20 . // flag if
36b0: 69 74 20 77 61 73 20 73 65 74 2e 0a 20 20 20 20 it was set..
36c0: 73 74 61 74 69 63 20 69 6e 74 20 73 69 6e 67 6c static int singl
36d0: 65 5f 73 68 6f 74 20 3d 20 30 3b 0a 20 20 20 20 e_shot = 0;.
36e0: 69 66 20 28 21 63 6c 6f 73 65 64 29 20 7b 0a 20 if (!closed) {.
36f0: 20 20 20 20 20 20 20 73 69 6e 67 6c 65 5f 73 68 single_sh
3700: 6f 74 20 3d 20 30 3b 0a 20 20 20 20 20 20 20 20 ot = 0;.
3710: 72 65 74 75 72 6e 20 70 66 74 5f 6e 6f 72 6d 61 return pft_norma
3720: 6c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2f l;. }.. //
3730: 20 54 68 65 72 65 20 61 72 65 20 74 77 6f 20 73 There are two s
3740: 65 74 73 20 6f 66 20 53 49 4e 47 5f 53 54 45 50 ets of SING_STEP
3750: 20 63 6f 6d 62 6f 73 3a 20 66 69 72 73 74 20 75 combos: first u
3760: 70 20 61 72 65 20 74 68 6f 73 65 20 77 68 65 72 p are those wher
3770: 65 20 74 68 65 0a 20 20 20 20 2f 2f 20 6f 74 68 e the. // oth
3780: 65 72 20 73 77 69 74 63 68 65 73 20 69 6e 76 6f er switches invo
3790: 6c 76 65 64 20 68 61 76 65 20 74 6f 20 62 65 20 lved have to be
37a0: 73 65 74 20 61 6c 72 65 61 64 79 2c 20 61 6e 64 set already, and
37b0: 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 20 69 73 the function is
37c0: 0a 20 20 20 20 2f 2f 20 74 72 69 67 67 65 72 65 . // triggere
37d0: 64 20 61 73 20 73 6f 6f 6e 20 61 73 20 53 49 4e d as soon as SIN
37e0: 47 5f 53 54 45 50 20 63 6c 6f 73 65 73 2e 20 20 G_STEP closes.
37f0: 54 68 65 73 65 20 61 72 65 20 66 75 6e 63 74 69 These are functi
3800: 6f 6e 73 20 77 65 20 64 6f 6e 27 74 0a 20 20 20 ons we don't.
3810: 20 2f 2f 20 77 61 6e 74 20 72 65 2d 65 78 65 63 // want re-exec
3820: 75 74 69 6e 67 20 72 65 70 65 61 74 65 64 6c 79 uting repeatedly
3830: 20 77 68 69 6c 65 20 53 49 4e 47 5f 53 54 45 50 while SING_STEP
3840: 20 72 65 6d 61 69 6e 73 20 63 6c 6f 73 65 64 2e remains closed.
3850: 0a 20 20 20 20 69 66 20 28 73 69 6e 67 6c 65 5f . if (single_
3860: 73 68 6f 74 20 3d 3d 20 30 29 20 7b 0a 20 20 20 shot == 0) {.
3870: 20 20 20 20 20 2f 2f 20 53 49 4e 47 5f 53 54 45 // SING_STE
3880: 50 20 73 77 69 74 63 68 20 77 61 73 20 6f 70 65 P switch was ope
3890: 6e 20 6c 61 73 74 20 77 65 20 6b 6e 65 77 2c 20 n last we knew,
38a0: 61 6e 64 20 6e 6f 77 20 69 74 27 73 20 63 6c 6f and now it's clo
38b0: 73 65 64 2c 20 73 6f 0a 20 20 20 20 20 20 20 20 sed, so.
38c0: 2f 2f 20 73 65 74 20 74 68 65 20 73 69 6e 67 6c // set the singl
38d0: 65 2d 73 68 6f 74 20 66 6c 61 67 2e 0a 20 20 20 e-shot flag..
38e0: 20 20 20 20 20 73 69 6e 67 6c 65 5f 73 68 6f 74 single_shot
38f0: 20 3d 20 31 3b 0a 0a 20 20 20 20 20 20 20 20 2f = 1;.. /
3900: 2f 20 31 2e 20 43 6f 6e 76 65 72 74 20 44 46 20 / 1. Convert DF
3910: 73 77 69 74 63 68 20 76 61 6c 75 65 73 20 74 6f switch values to
3920: 20 61 20 64 65 76 69 63 65 20 6e 75 6d 62 65 72 a device number
3930: 2c 20 77 68 69 63 68 0a 20 20 20 20 20 20 20 20 , which.
3940: 2f 2f 20 77 65 20 77 69 6c 6c 20 6d 61 70 20 74 // we will map t
3950: 6f 20 61 20 50 44 50 2d 38 20 64 65 76 69 63 65 o a PDP-8 device
3960: 20 74 79 70 65 2c 20 74 68 65 6e 20 61 74 74 65 type, then atte
3970: 6d 70 74 20 74 6f 0a 20 20 20 20 20 20 20 20 2f mpt to. /
3980: 2f 20 41 54 54 41 43 48 20 73 6f 6d 65 20 75 6e / ATTACH some un
3990: 6d 6f 75 6e 74 65 64 20 6d 65 64 69 75 6d 20 66 mounted medium f
39a0: 72 6f 6d 20 55 53 42 20 74 6f 20 74 68 61 74 20 rom USB to that
39b0: 64 65 76 69 63 65 0a 20 20 20 20 20 20 20 20 2f device. /
39c0: 2f 0a 20 20 20 20 20 20 20 20 2f 2f 20 57 65 20 /. // We
39d0: 74 72 65 61 74 20 44 46 20 3d 3d 20 30 20 61 73 treat DF == 0 as
39e0: 20 6e 6f 74 68 69 6e 67 20 74 6f 20 6d 6f 75 6e nothing to moun
39f0: 74 2c 20 73 69 6e 63 65 20 77 65 20 75 73 65 0a t, since we use.
3a00: 20 20 20 20 20 20 20 20 2f 2f 20 53 49 4e 47 5f // SING_
3a10: 53 54 45 50 20 66 6f 72 20 6f 74 68 65 72 20 74 STEP for other t
3a20: 68 69 6e 67 73 2c 20 73 6f 20 77 65 20 6e 65 65 hings, so we nee
3a30: 64 20 61 20 77 61 79 20 74 6f 0a 20 20 20 20 20 d a way to.
3a40: 20 20 20 2f 2f 20 64 65 63 69 64 65 20 77 68 69 // decide whi
3a50: 63 68 20 6d 65 61 6e 69 6e 67 20 6f 66 20 53 49 ch meaning of SI
3a60: 4e 47 5f 53 54 45 50 20 74 6f 20 74 61 6b 65 20 NG_STEP to take
3a70: 68 65 72 65 2e 0a 20 20 20 20 20 20 20 20 2f 2f here.. //
3a80: 0a 20 20 20 20 20 20 20 20 2f 2f 20 54 68 65 20 . // The
3a90: 73 68 69 66 74 20 62 79 20 39 20 69 73 20 68 6f shift by 9 is ho
3aa0: 77 20 6d 61 6e 79 20 6e 6f 6e 2d 44 46 20 62 69 w many non-DF bi
3ab0: 74 73 20 61 72 65 20 62 65 6c 6f 77 0a 20 20 20 ts are below.
3ac0: 20 20 20 20 20 2f 2f 20 44 46 20 69 6e 20 73 77 // DF in sw
3ad0: 69 74 63 68 73 74 61 74 75 73 5b 31 5d 0a 20 20 itchstatus[1].
3ae0: 20 20 20 20 20 20 2f 2f 0a 20 20 20 20 20 20 20 //.
3af0: 20 2f 2f 20 54 68 65 20 62 69 74 20 63 6f 6d 70 // The bit comp
3b00: 6c 65 6d 65 6e 74 20 69 73 20 62 65 63 61 75 73 lement is becaus
3b10: 65 20 63 6c 6f 73 65 64 20 44 46 20 73 77 69 74 e closed DF swit
3b20: 63 68 65 73 20 73 68 6f 77 0a 20 20 20 20 20 20 ches show.
3b30: 20 20 2f 2f 20 61 73 20 30 2c 20 62 65 63 61 75 // as 0, becau
3b40: 73 65 20 74 68 65 79 27 72 65 20 64 72 61 67 67 se they're dragg
3b50: 69 6e 67 20 74 68 65 20 70 75 6c 6c 2d 75 70 20 ing the pull-up
3b60: 64 6f 77 6e 2c 20 62 75 74 0a 20 20 20 20 20 20 down, but.
3b70: 20 20 2f 2f 20 77 65 20 77 61 6e 74 20 74 68 6f // we want tho
3b80: 73 65 20 74 72 65 61 74 65 64 20 61 73 20 31 73 se treated as 1s
3b90: 2c 20 61 6e 64 20 76 69 63 65 20 76 65 72 73 61 , and vice versa
3ba0: 2e 0a 20 20 20 20 20 20 20 20 75 69 6e 74 31 36 .. uint16
3bb0: 5f 74 20 63 73 73 31 20 3d 20 7e 73 77 69 74 63 _t css1 = ~switc
3bc0: 68 73 74 61 74 75 73 5b 31 5d 3b 20 0a 20 20 20 hstatus[1]; .
3bd0: 20 20 20 20 20 69 6e 74 20 73 77 44 65 76 69 63 int swDevic
3be0: 65 20 3d 20 28 63 73 73 31 20 26 20 53 53 31 5f e = (css1 & SS1_
3bf0: 44 46 5f 41 4c 4c 29 20 3e 3e 20 39 3b 0a 20 20 DF_ALL) >> 9;.
3c00: 20 20 20 20 20 20 69 66 20 28 73 77 44 65 76 69 if (swDevi
3c10: 63 65 29 20 7b 0a 20 20 20 20 20 20 20 20 20 20 ce) {.
3c20: 20 20 63 68 61 72 20 73 77 44 65 76 43 6f 64 65 char swDevCode
3c30: 5b 34 5d 20 3d 20 7b 20 27 5c 30 27 20 7d 3b 0a [4] = { '\0' };.
3c40: 20 20 20 20 20 20 20 20 20 20 20 20 73 77 69 74 swit
3c50: 63 68 20 28 73 77 44 65 76 69 63 65 29 20 7b 0a ch (swDevice) {.
3c60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
3c70: 63 61 73 65 20 31 3a 20 73 74 72 63 70 79 20 28 case 1: strcpy (
3c80: 73 77 44 65 76 43 6f 64 65 2c 20 22 70 74 72 22 swDevCode, "ptr"
3c90: 29 3b 20 62 72 65 61 6b 3b 20 2f 2f 20 50 54 52 ); break; // PTR
3ca0: 20 70 61 70 65 72 20 74 61 70 65 20 72 65 61 64 paper tape read
3cb0: 65 72 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 er.
3cc0: 20 20 20 63 61 73 65 20 32 3a 20 73 74 72 63 70 case 2: strcp
3cd0: 79 20 28 73 77 44 65 76 43 6f 64 65 2c 20 22 70 y (swDevCode, "p
3ce0: 74 70 22 29 3b 20 62 72 65 61 6b 3b 20 2f 2f 20 tp"); break; //
3cf0: 48 69 67 68 20 73 70 65 65 64 20 70 61 70 65 72 High speed paper
3d00: 20 74 61 70 65 20 70 75 6e 63 68 0a 20 20 20 20 tape punch.
3d10: 20 20 20 20 20 20 20 20 20 20 20 20 63 61 73 65 case
3d20: 20 33 3a 20 73 74 72 63 70 79 20 28 73 77 44 65 3: strcpy (swDe
3d30: 76 43 6f 64 65 2c 20 22 64 74 30 22 29 3b 20 62 vCode, "dt0"); b
3d40: 72 65 61 6b 3b 20 2f 2f 20 54 43 30 38 20 44 45 reak; // TC08 DE
3d50: 43 74 61 70 65 20 28 23 38 20 69 73 20 66 69 72 Ctape (#8 is fir
3d60: 73 74 21 29 0a 20 20 20 20 20 20 20 20 20 20 20 st!).
3d70: 20 20 20 20 20 63 61 73 65 20 34 3a 20 73 74 72 case 4: str
3d80: 63 70 79 20 28 73 77 44 65 76 43 6f 64 65 2c 20 cpy (swDevCode,
3d90: 22 64 74 31 22 29 3b 20 62 72 65 61 6b 3b 0a 20 "dt1"); break;.
3da0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 63 c
3db0: 61 73 65 20 35 3a 20 73 74 72 63 70 79 20 28 73 ase 5: strcpy (s
3dc0: 77 44 65 76 43 6f 64 65 2c 20 22 72 78 30 22 29 wDevCode, "rx0")
3dd0: 3b 20 62 72 65 61 6b 3b 20 2f 2f 20 52 58 38 45 ; break; // RX8E
3de0: 20 28 38 2f 65 20 70 65 72 69 70 68 65 72 61 6c (8/e peripheral
3df0: 21 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 !).
3e00: 20 20 20 63 61 73 65 20 36 3a 20 73 74 72 63 70 case 6: strcp
3e10: 79 20 28 73 77 44 65 76 43 6f 64 65 2c 20 22 72 y (swDevCode, "r
3e20: 78 31 22 29 3b 20 62 72 65 61 6b 3b 0a 20 20 20 x1"); break;.
3e30: 20 20 20 20 20 20 20 20 20 20 20 20 20 63 61 73 cas
3e40: 65 20 37 3a 20 73 74 72 63 70 79 20 28 73 77 44 e 7: strcpy (swD
3e50: 65 76 43 6f 64 65 2c 20 22 72 6c 30 22 29 3b 20 evCode, "rl0");
3e60: 62 72 65 61 6b 3b 20 2f 2f 20 52 4c 38 41 0a 20 break; // RL8A.
3e70: 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 20 20 }.
3e80: 20 20 20 20 20 20 20 20 20 69 66 20 28 73 77 44 if (swD
3e90: 65 76 43 6f 64 65 5b 30 5d 29 20 6d 6f 75 6e 74 evCode[0]) mount
3ea0: 5f 75 73 62 5f 73 74 69 63 6b 5f 66 69 6c 65 20 _usb_stick_file
3eb0: 28 73 77 44 65 76 69 63 65 2c 20 73 77 44 65 76 (swDevice, swDev
3ec0: 43 6f 64 65 29 3b 0a 20 20 20 20 20 20 20 20 7d Code);. }
3ed0: 0a 0a 20 20 20 20 20 20 20 20 2f 2f 20 32 2e 20 .. // 2.
3ee0: 44 6f 20 74 68 65 20 73 61 6d 65 20 77 69 74 68 Do the same with
3ef0: 20 49 46 2c 20 65 78 63 65 70 74 20 74 68 61 74 IF, except that
3f00: 20 74 68 65 20 73 77 69 74 63 68 20 76 61 6c 75 the switch valu
3f10: 65 0a 20 20 20 20 20 20 20 20 2f 2f 20 69 73 20 e. // is
3f20: 75 73 65 64 20 74 6f 20 64 65 63 69 64 65 20 77 used to decide w
3f30: 68 69 63 68 20 62 6f 6f 74 20 73 63 72 69 70 74 hich boot script
3f40: 20 74 6f 20 72 65 73 74 61 72 74 20 77 69 74 68 to restart with
3f50: 20 76 69 61 0a 20 20 20 20 20 20 20 20 2f 2f 20 via. //
3f60: 53 49 4d 48 27 73 20 44 4f 20 63 6f 6d 6d 61 6e SIMH's DO comman
3f70: 64 2e 0a 20 20 20 20 20 20 20 20 2f 2f 0a 20 20 d.. //.
3f80: 20 20 20 20 20 20 2f 2f 20 54 68 65 20 73 68 69 // The shi
3f90: 66 74 20 76 61 6c 75 65 20 6f 66 20 36 20 69 73 ft value of 6 is
3fa0: 20 62 65 63 61 75 73 65 20 74 68 65 20 49 46 20 because the IF
3fb0: 73 77 69 74 63 68 65 73 20 61 72 65 20 33 0a 20 switches are 3.
3fc0: 20 20 20 20 20 20 20 2f 2f 20 64 6f 77 6e 20 66 // down f
3fd0: 72 6f 6d 20 74 68 65 20 44 46 20 73 77 69 74 63 rom the DF switc
3fe0: 68 65 73 20 61 62 6f 76 65 2e 0a 20 20 20 20 20 hes above..
3ff0: 20 20 20 69 6e 74 20 73 77 53 63 72 69 70 74 20 int swScript
4000: 3d 20 28 63 73 73 31 20 26 20 53 53 31 5f 49 46 = (css1 & SS1_IF
4010: 5f 41 4c 4c 29 20 3e 3e 20 36 3b 0a 20 20 20 20 _ALL) >> 6;.
4020: 20 20 20 20 69 66 20 28 73 77 53 63 72 69 70 74 if (swScript
4030: 29 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 ) {.
4040: 2f 2f 20 62 75 69 6c 64 20 66 69 6c 65 6e 61 6d // build filenam
4050: 65 20 66 72 6f 6d 20 49 46 20 76 61 6c 75 65 0a e from IF value.
4060: 20 20 20 20 20 20 20 20 20 20 20 20 63 68 61 72 char
4070: 20 73 53 63 72 69 70 74 5b 32 35 36 5d 3b 0a 20 sScript[256];.
4080: 20 20 20 20 20 20 20 20 20 20 20 73 6e 70 72 69 snpri
4090: 6e 74 66 20 28 73 53 63 72 69 70 74 2c 20 73 69 ntf (sScript, si
40a0: 7a 65 6f 66 20 28 73 53 63 72 69 70 74 29 2c 20 zeof (sScript),
40b0: 22 40 42 4f 4f 54 44 49 52 40 2f 25 64 2e 73 63 "@BOOTDIR@/%d.sc
40c0: 72 69 70 74 22 2c 20 73 77 53 63 72 69 70 74 29 ript", swScript)
40d0: 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 70 72 ;. pr
40e0: 69 6e 74 66 20 28 22 5c 72 5c 6e 5c 6e 52 65 62 intf ("\r\n\nReb
40f0: 6f 6f 74 69 6e 67 20 25 73 5c 72 5c 6e 5c 72 5c ooting %s\r\n\r\
4100: 6e 22 2c 20 73 53 63 72 69 70 74 29 3b 0a 20 20 n", sScript);.
4110: 20 20 20 20 20 20 20 20 20 20 61 77 66 75 6c 48 awfulH
4120: 61 63 6b 46 6c 61 67 20 3d 20 73 77 53 63 72 69 ackFlag = swScri
4130: 70 74 3b 20 20 20 2f 2f 20 74 68 69 73 20 74 72 pt; // this tr
4140: 69 67 67 65 72 73 20 61 20 64 6f 20 63 6f 6d 6d iggers a do comm
4150: 61 6e 64 20 61 66 74 65 72 20 6c 65 61 76 69 6e and after leavin
4160: 67 20 74 68 65 20 73 69 6d 75 6c 61 74 6f 72 20 g the simulator
4170: 72 75 6e 2e 0a 20 20 20 20 20 20 20 20 20 20 20 run..
4180: 20 72 65 74 75 72 6e 20 70 66 74 5f 68 61 6c 74 return pft_halt
4190: 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 ;. }.
41a0: 7d 20 2f 2f 20 65 6e 64 20 69 66 20 73 69 6e 67 } // end if sing
41b0: 6c 65 2d 73 68 6f 74 20 66 6c 61 67 20 63 6c 65 le-shot flag cle
41c0: 61 72 0a 20 20 20 20 65 6c 73 65 20 7b 0a 20 20 ar. else {.
41d0: 20 20 20 20 20 20 2f 2f 20 4e 6f 77 20 68 61 6e // Now han
41e0: 64 6c 65 20 74 68 65 20 73 65 63 6f 6e 64 20 73 dle the second s
41f0: 65 74 20 6f 66 20 53 49 4e 47 5f 53 54 45 50 20 et of SING_STEP
4200: 73 70 65 63 69 61 6c 2d 66 75 6e 63 74 69 6f 6e special-function
4210: 0a 20 20 20 20 20 20 20 20 2f 2f 20 63 6f 6d 62 . // comb
4220: 6f 73 2c 20 62 65 69 6e 67 20 74 68 6f 73 65 20 os, being those
4230: 77 68 65 72 65 20 74 68 65 20 73 77 69 74 63 68 where the switch
4240: 65 73 20 63 61 6e 20 62 65 20 70 72 65 73 73 65 es can be presse
4250: 64 20 69 6e 20 61 6e 79 0a 20 20 20 20 20 20 20 d in any.
4260: 20 2f 2f 20 6f 72 64 65 72 2c 20 73 6f 20 74 68 // order, so th
4270: 61 74 20 77 65 20 74 61 6b 65 20 61 63 74 69 6f at we take actio
4280: 6e 20 77 68 65 6e 20 74 68 65 20 6c 61 73 74 20 n when the last
4290: 6f 6e 65 20 6f 66 20 74 68 65 20 73 65 74 0a 20 one of the set.
42a0: 20 20 20 20 20 20 20 2f 2f 20 63 6c 6f 73 65 73 // closes
42b0: 2c 20 6e 6f 20 6d 61 74 74 65 72 20 77 68 69 63 , no matter whic
42c0: 68 20 6f 6e 65 20 74 68 61 74 20 69 73 2e 20 20 h one that is.
42d0: 54 68 65 73 65 20 69 6d 6d 65 64 69 61 74 65 6c These immediatel
42e0: 79 20 65 78 69 74 0a 20 20 20 20 20 20 20 20 2f y exit. /
42f0: 2f 20 74 68 65 20 53 49 4d 48 20 69 6e 73 74 72 / the SIMH instr
4300: 75 63 74 69 6f 6e 20 69 6e 74 65 72 70 72 65 74 uction interpret
4310: 65 72 2c 20 73 6f 20 74 68 65 79 20 77 6f 6e 27 er, so they won'
4320: 74 20 72 65 2d 65 78 65 63 75 74 65 0a 20 20 20 t re-execute.
4330: 20 20 20 20 20 2f 2f 20 6d 65 72 65 6c 79 20 62 // merely b
4340: 65 63 61 75 73 65 20 74 68 65 20 68 75 6d 61 6e ecause the human
4350: 20 69 73 6e 27 74 20 66 61 73 74 20 65 6e 6f 75 isn't fast enou
4360: 67 68 20 74 6f 20 6c 69 66 74 20 68 69 73 20 66 gh to lift his f
4370: 69 6e 67 65 72 0a 20 20 20 20 20 20 20 20 2f 2f inger. //
4380: 20 62 79 20 74 68 65 20 74 69 6d 65 20 74 68 65 by the time the
4390: 20 6e 65 78 74 20 69 74 65 72 61 74 69 6f 6e 20 next iteration
43a0: 6f 66 20 74 68 61 74 20 6c 6f 6f 70 20 73 74 61 of that loop sta
43b0: 72 74 73 2e 0a 0a 20 20 20 20 20 20 20 20 2f 2f rts... //
43c0: 20 33 2e 20 53 63 61 6e 20 66 6f 72 20 68 6f 73 3. Scan for hos
43d0: 74 20 70 6f 77 65 72 6f 66 66 20 63 6f 6d 6d 61 t poweroff comma
43e0: 6e 64 20 28 53 69 6e 67 5f 53 74 65 70 20 2b 20 nd (Sing_Step +
43f0: 53 69 6e 67 5f 49 6e 73 74 20 2b 20 53 74 6f 70 Sing_Inst + Stop
4400: 29 0a 20 20 20 20 20 20 20 20 69 66 20 28 28 73 ). if ((s
4410: 77 69 74 63 68 73 74 61 74 75 73 5b 32 5d 20 26 witchstatus[2] &
4420: 20 28 53 53 32 5f 53 5f 49 4e 53 54 20 7c 20 53 (SS2_S_INST | S
4430: 53 32 5f 53 54 4f 50 29 29 20 3d 3d 20 30 29 20 S2_STOP)) == 0)
4440: 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 70 72 {. pr
4450: 69 6e 74 66 20 28 22 5c 72 5c 6e 53 68 75 74 64 intf ("\r\nShutd
4460: 6f 77 6e 5c 72 5c 6e 5c 72 5c 6e 22 29 3b 0a 20 own\r\n\r\n");.
4470: 20 20 20 20 20 20 20 20 20 20 20 61 77 66 75 6c awful
4480: 48 61 63 6b 46 6c 61 67 20 3d 20 38 3b 20 20 2f HackFlag = 8; /
4490: 2f 20 74 68 69 73 20 74 72 69 67 67 65 72 73 20 / this triggers
44a0: 61 6e 20 65 78 69 74 20 63 6f 6d 6d 61 6e 64 20 an exit command
44b0: 61 66 74 65 72 20 6c 65 61 76 69 6e 67 20 74 68 after leaving th
44c0: 65 20 73 69 6d 75 6c 61 74 6f 72 20 72 75 6e 2e e simulator run.
44d0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 . if
44e0: 28 73 70 61 77 6e 5f 63 6d 64 20 28 30 2c 20 22 (spawn_cmd (0, "
44f0: 73 75 64 6f 20 2f 62 69 6e 2f 73 79 73 74 65 6d sudo /bin/system
4500: 63 74 6c 20 70 6f 77 65 72 6f 66 66 22 29 20 21 ctl poweroff") !
4510: 3d 20 53 43 50 45 5f 4f 4b 29 20 7b 0a 20 20 20 = SCPE_OK) {.
4520: 20 20 20 20 20 20 20 20 20 20 20 20 20 70 72 69 pri
4530: 6e 74 66 20 28 22 5c 72 5c 6e 5c 72 5c 6e 70 6f ntf ("\r\n\r\npo
4540: 77 65 72 6f 66 66 20 66 61 69 6c 65 64 5c 72 5c weroff failed\r\
4550: 6e 5c 72 5c 6e 22 29 3b 0a 20 20 20 20 20 20 20 n\r\n");.
4560: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 20 }.
4570: 20 20 20 72 65 74 75 72 6e 20 70 66 74 5f 68 61 return pft_ha
4580: 6c 74 3b 0a 20 20 20 20 20 20 20 20 7d 0a 0a 20 lt;. }..
4590: 20 20 20 20 20 20 20 2f 2f 20 34 2e 20 53 63 61 // 4. Sca
45a0: 6e 20 66 6f 72 20 68 6f 73 74 20 72 65 62 6f 6f n for host reboo
45b0: 74 20 63 6f 6d 6d 61 6e 64 20 28 53 69 6e 67 5f t command (Sing_
45c0: 53 74 65 70 20 2b 20 53 69 6e 67 5f 49 6e 73 74 Step + Sing_Inst
45d0: 20 2b 20 53 74 61 72 74 29 0a 20 20 20 20 20 20 + Start).
45e0: 20 20 69 66 20 28 28 73 77 69 74 63 68 73 74 61 if ((switchsta
45f0: 74 75 73 5b 32 5d 20 26 20 28 53 53 32 5f 53 5f tus[2] & (SS2_S_
4600: 49 4e 53 54 20 7c 20 53 53 32 5f 53 54 41 52 54 INST | SS2_START
4610: 29 29 20 3d 3d 20 30 29 20 7b 0a 20 20 20 20 20 )) == 0) {.
4620: 20 20 20 20 20 20 20 70 72 69 6e 74 66 20 28 22 printf ("
4630: 5c 72 5c 6e 52 65 62 6f 6f 74 5c 72 5c 6e 5c 72 \r\nReboot\r\n\r
4640: 5c 6e 22 29 3b 0a 20 20 20 20 20 20 20 20 20 20 \n");.
4650: 20 20 61 77 66 75 6c 48 61 63 6b 46 6c 61 67 20 awfulHackFlag
4660: 3d 20 38 3b 20 20 20 20 20 20 2f 2f 20 74 68 69 = 8; // thi
4670: 73 20 74 72 69 67 67 65 72 73 20 61 6e 20 65 78 s triggers an ex
4680: 69 74 20 63 6f 6d 6d 61 6e 64 20 61 66 74 65 72 it command after
4690: 20 6c 65 61 76 69 6e 67 20 74 68 65 20 73 69 6d leaving the sim
46a0: 75 6c 61 74 6f 72 20 72 75 6e 2e 0a 20 20 20 20 ulator run..
46b0: 20 20 20 20 20 20 20 20 69 66 20 28 73 70 61 77 if (spaw
46c0: 6e 5f 63 6d 64 20 28 30 2c 20 22 73 75 64 6f 20 n_cmd (0, "sudo
46d0: 2f 62 69 6e 2f 73 79 73 74 65 6d 63 74 6c 20 72 /bin/systemctl r
46e0: 65 62 6f 6f 74 22 29 20 21 3d 20 53 43 50 45 5f eboot") != SCPE_
46f0: 4f 4b 29 20 7b 0a 20 20 20 20 20 20 20 20 20 20 OK) {.
4700: 20 20 20 20 20 20 70 72 69 6e 74 66 20 28 22 5c printf ("\
4710: 72 5c 6e 5c 72 5c 6e 72 65 62 6f 6f 74 20 66 61 r\n\r\nreboot fa
4720: 69 6c 65 64 5c 72 5c 6e 5c 72 5c 6e 22 29 3b 0a iled\r\n\r\n");.
4730: 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 20 }.
4740: 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e return
4750: 20 70 66 74 5f 68 61 6c 74 3b 0a 20 20 20 20 20 pft_halt;.
4760: 20 20 20 7d 0a 0a 20 20 20 20 20 20 20 20 23 69 }.. #i
4770: 66 20 30 0a 20 20 20 20 20 20 20 20 2f 2f 20 54 f 0. // T
4780: 68 65 73 65 20 63 6f 6d 62 6f 73 20 6f 6e 63 65 hese combos once
4790: 20 6d 65 61 6e 74 20 73 6f 6d 65 74 68 69 6e 67 meant something
47a0: 2c 20 62 75 74 20 6e 6f 20 6c 6f 6e 67 65 72 20 , but no longer
47b0: 64 6f 2e 20 20 49 66 20 79 6f 75 0a 20 20 20 20 do. If you.
47c0: 20 20 20 20 2f 2f 20 72 65 61 73 73 69 67 6e 20 // reassign
47d0: 74 68 65 6d 2c 20 74 68 69 6e 6b 20 63 61 72 65 them, think care
47e0: 66 75 6c 6c 79 20 77 68 65 74 68 65 72 20 74 68 fully whether th
47f0: 65 79 20 73 68 6f 75 6c 64 20 63 6f 6e 74 69 6e ey should contin
4800: 75 65 20 74 6f 0a 20 20 20 20 20 20 20 20 2f 2f ue to. //
4810: 20 62 65 20 68 61 6e 64 6c 65 64 20 68 65 72 65 be handled here
4820: 20 61 6e 64 20 6e 6f 74 20 61 62 6f 76 65 20 69 and not above i
4830: 6e 20 74 68 65 20 22 69 66 22 20 62 72 61 6e 63 n the "if" branc
4840: 68 2e 20 20 49 66 20 6e 6f 74 68 69 6e 67 0a 20 h. If nothing.
4850: 20 20 20 20 20 20 20 2f 2f 20 70 72 65 76 65 6e // preven
4860: 74 73 20 79 6f 75 72 20 66 75 6e 63 74 69 6f 6e ts your function
4870: 20 66 72 6f 6d 20 62 65 69 6e 67 20 72 65 2d 65 from being re-e
4880: 78 65 63 75 74 65 64 20 77 68 69 6c 65 20 53 49 xecuted while SI
4890: 4e 47 5f 53 54 45 50 0a 20 20 20 20 20 20 20 20 NG_STEP.
48a0: 2f 2f 20 72 65 6d 61 69 6e 73 20 63 6c 6f 73 65 // remains close
48b0: 64 20 61 6e 64 20 72 65 2d 65 78 65 63 75 74 69 d and re-executi
48c0: 6f 6e 20 77 6f 75 6c 64 20 62 65 20 62 61 64 2c on would be bad,
48d0: 20 6d 6f 76 65 20 74 68 65 20 74 65 73 74 0a 20 move the test.
48e0: 20 20 20 20 20 20 20 2f 2f 20 75 6e 64 65 72 20 // under
48f0: 74 68 65 20 61 65 67 69 73 20 6f 66 20 74 68 65 the aegis of the
4900: 20 73 69 6e 67 6c 65 5f 73 68 6f 74 20 66 6c 61 single_shot fla
4910: 67 2e 0a 0a 20 20 20 20 20 20 20 20 2f 2f 20 35 g... // 5
4920: 2e 20 53 69 6e 67 5f 53 74 65 70 20 2b 20 53 69 . Sing_Step + Si
4930: 6e 67 5f 49 6e 73 74 20 2b 20 4c 6f 61 64 20 41 ng_Inst + Load A
4940: 64 64 0a 20 20 20 20 20 20 20 20 69 66 20 28 28 dd. if ((
4950: 73 77 69 74 63 68 73 74 61 74 75 73 5b 32 5d 20 switchstatus[2]
4960: 26 20 28 53 53 32 5f 53 5f 49 4e 53 54 20 7c 20 & (SS2_S_INST |
4970: 53 53 32 5f 4c 5f 41 44 44 29 29 20 3d 3d 20 30 SS2_L_ADD)) == 0
4980: 29 20 7b 20 7d 0a 0a 20 20 20 20 20 20 20 20 2f ) { }.. /
4990: 2f 20 36 2e 20 53 69 6e 67 5f 53 74 65 70 20 2b / 6. Sing_Step +
49a0: 20 53 69 6e 67 5f 49 6e 73 74 20 2b 20 44 65 70 Sing_Inst + Dep
49b0: 6f 73 69 74 0a 20 20 20 20 20 20 20 20 69 66 20 osit. if
49c0: 28 28 73 77 69 74 63 68 73 74 61 74 75 73 5b 32 ((switchstatus[2
49d0: 5d 20 26 20 28 53 53 32 5f 53 5f 49 4e 53 54 20 ] & (SS2_S_INST
49e0: 7c 20 53 53 32 5f 44 45 50 29 29 20 3d 3d 20 30 | SS2_DEP)) == 0
49f0: 29 20 7b 20 7d 0a 20 20 20 20 20 20 20 20 23 65 ) { }. #e
4a00: 6e 64 69 66 0a 20 20 20 20 7d 0a 0a 20 20 20 20 ndif. }..
4a10: 72 65 74 75 72 6e 20 70 66 74 5f 6e 6f 72 6d 61 return pft_norma
4a20: 6c 3b 0a 7d 0a 0a 0a 2f 2f 2f 2f 20 73 65 74 5f l;.}...//// set_
4a30: 73 69 6e 67 6c 65 5f 69 6e 73 74 5f 66 6c 61 67 single_inst_flag
4a40: 20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ///////////////
4a50: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
4a60: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0a ///////////////.
4a70: 2f 2f 20 53 65 74 20 6f 72 20 63 6c 65 61 72 20 // Set or clear
4a80: 74 68 65 20 53 49 4e 47 5f 49 4e 53 54 20 6d 6f the SING_INST mo
4a90: 64 65 20 66 6c 61 67 73 2e 0a 0a 73 74 61 74 69 de flags...stati
4aa0: 63 20 69 6e 6c 69 6e 65 20 76 6f 69 64 20 73 65 c inline void se
4ab0: 74 5f 73 69 6e 67 6c 65 5f 69 6e 73 74 5f 66 6c t_single_inst_fl
4ac0: 61 67 20 28 69 6e 74 20 66 29 0a 7b 0a 20 20 20 ag (int f).{.
4ad0: 20 2f 2f 20 41 6c 73 6f 20 73 65 74 20 74 68 65 // Also set the
4ae0: 20 64 69 73 70 6c 61 79 73 27 20 73 69 6e 67 6c displays' singl
4af0: 65 2d 69 6e 73 74 72 75 63 74 69 6f 6e 20 6d 6f e-instruction mo
4b00: 64 65 20 66 6c 61 67 2c 20 62 65 63 61 75 73 65 de flag, because
4b10: 20 69 66 0a 20 20 20 20 2f 2f 20 77 65 27 72 65 if. // we're
4b20: 20 72 75 6e 6e 69 6e 67 20 74 68 65 20 49 4c 53 running the ILS
4b30: 20 63 6f 64 65 20 68 65 72 65 2c 20 77 65 20 68 code here, we h
4b40: 61 76 65 20 74 6f 20 75 73 65 20 4e 4c 53 20 75 ave to use NLS u
4b50: 6e 74 69 6c 20 77 65 27 72 65 0a 20 20 20 20 2f ntil we're. /
4b60: 2f 20 62 61 63 6b 20 74 6f 20 66 75 6c 6c 2d 73 / back to full-s
4b70: 70 65 65 64 2c 20 73 69 6e 63 65 20 49 4c 53 20 peed, since ILS
4b80: 64 65 70 65 6e 64 73 20 6f 6e 20 72 61 70 69 64 depends on rapid
4b90: 20 73 74 61 74 65 20 75 70 64 61 74 65 73 2e 0a state updates..
4ba0: 20 20 20 20 70 64 69 73 5f 70 61 69 6e 74 2d 3e pdis_paint->
4bb0: 63 70 75 5f 73 69 6e 67 6c 65 5f 69 6e 73 74 20 cpu_single_inst
4bc0: 3d 20 70 64 69 73 5f 75 70 64 61 74 65 2d 3e 63 = pdis_update->c
4bd0: 70 75 5f 73 69 6e 67 6c 65 5f 69 6e 73 74 20 3d pu_single_inst =
4be0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 73 77 53 . swS
4bf0: 69 6e 67 49 6e 73 74 20 3d 20 66 3b 0a 7d 0a 0a ingInst = f;.}..
4c00: 0a 2f 2f 2f 2f 20 73 65 74 5f 73 74 6f 70 5f 66 .//// set_stop_f
4c10: 6c 61 67 20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f lag ////////////
4c20: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
4c30: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
4c40: 2f 2f 2f 2f 2f 2f 2f 2f 2f 0a 2f 2f 20 53 65 74 /////////.// Set
4c50: 20 6f 72 20 63 6c 65 61 72 20 74 68 65 20 53 54 or clear the ST
4c60: 4f 50 20 6d 6f 64 65 20 66 6c 61 67 73 2e 0a 0a OP mode flags...
4c70: 76 6f 69 64 20 73 65 74 5f 73 74 6f 70 5f 66 6c void set_stop_fl
4c80: 61 67 20 28 69 6e 74 20 66 29 0a 7b 0a 20 20 20 ag (int f).{.
4c90: 20 2f 2f 20 41 6c 73 6f 20 73 65 74 20 74 68 65 // Also set the
4ca0: 20 64 69 73 70 6c 61 79 73 27 20 73 74 6f 70 20 displays' stop
4cb0: 66 6c 61 67 2c 20 73 6f 20 73 77 61 70 5f 64 69 flag, so swap_di
4cc0: 73 70 6c 61 79 73 20 6b 65 65 70 73 20 74 68 65 splays keeps the
4cd0: 0a 20 20 20 20 2f 2f 20 63 75 72 72 65 6e 74 20 . // current
4ce0: 64 69 73 70 6c 61 79 20 75 70 20 75 6e 74 69 6c display up until
4cf0: 20 77 65 20 72 65 73 75 6d 65 20 70 72 6f 63 65 we resume proce
4d00: 73 73 69 6e 67 2e 0a 20 20 20 20 70 64 69 73 5f ssing.. pdis_
4d10: 70 61 69 6e 74 2d 3e 63 70 75 5f 73 74 6f 70 70 paint->cpu_stopp
4d20: 65 64 20 3d 20 70 64 69 73 5f 75 70 64 61 74 65 ed = pdis_update
4d30: 2d 3e 63 70 75 5f 73 74 6f 70 70 65 64 20 3d 20 ->cpu_stopped =
4d40: 73 77 53 74 6f 70 20 3d 20 66 3b 0a 7d 0a 0a 0a swStop = f;.}...
4d50: 2f 2f 2f 2f 20 68 61 6e 64 6c 65 5f 66 6c 6f 77 //// handle_flow
4d60: 5f 63 6f 6e 74 72 6f 6c 5f 73 77 69 74 63 68 65 _control_switche
4d70: 73 20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f s //////////////
4d80: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
4d90: 2f 2f 2f 2f 2f 2f 2f 2f 0a 2f 2f 20 50 72 6f 63 ////////.// Proc
4da0: 65 73 73 20 61 6c 6c 20 6f 66 20 74 68 65 20 50 ess all of the P
4db0: 69 44 50 2d 38 2f 49 20 66 72 6f 6e 74 20 70 61 iDP-8/I front pa
4dc0: 6e 65 6c 20 73 77 69 74 63 68 65 73 20 74 68 61 nel switches tha
4dd0: 74 20 63 61 6e 20 61 66 66 65 63 74 20 74 68 65 t can affect the
4de0: 0a 2f 2f 20 66 6c 6f 77 20 70 61 74 68 20 6f 66 .// flow path of
4df0: 20 74 68 65 20 50 44 50 2d 38 20 73 69 6d 75 6c the PDP-8 simul
4e00: 61 74 6f 72 27 73 20 69 6e 73 74 72 75 63 74 69 ator's instructi
4e10: 6f 6e 20 69 6e 74 65 72 70 72 65 74 61 74 69 6f on interpretatio
4e20: 6e 20 6c 6f 6f 70 2c 0a 2f 2f 20 72 65 74 75 72 n loop,.// retur
4e30: 6e 69 6e 67 20 61 20 63 6f 64 65 20 74 65 6c 6c ning a code tell
4e40: 69 6e 67 20 74 68 65 20 73 69 6d 75 6c 61 74 6f ing the simulato
4e50: 72 20 6f 75 72 20 64 65 63 69 73 69 6f 6e 2e 0a r our decision..
4e60: 2f 2f 0a 2f 2f 20 54 68 65 20 73 69 6d 75 6c 61 //.// The simula
4e70: 74 6f 72 20 70 61 73 73 65 73 20 69 6e 20 70 6f tor passes in po
4e80: 69 6e 74 65 72 73 20 74 6f 20 50 44 50 2d 38 20 inters to PDP-8
4e90: 72 65 67 69 73 74 65 72 73 20 77 65 20 6d 61 79 registers we may
4ea0: 20 6d 6f 64 69 66 79 20 61 73 0a 2f 2f 20 61 20 modify as.// a
4eb0: 73 69 64 65 20 65 66 66 65 63 74 20 6f 66 20 68 side effect of h
4ec0: 61 6e 64 6c 69 6e 67 20 74 68 65 73 65 20 73 77 andling these sw
4ed0: 69 74 63 68 65 73 2e 0a 0a 70 69 64 70 38 69 5f itches...pidp8i_
4ee0: 66 6c 6f 77 5f 74 20 68 61 6e 64 6c 65 5f 66 6c flow_t handle_fl
4ef0: 6f 77 5f 63 6f 6e 74 72 6f 6c 5f 73 77 69 74 63 ow_control_switc
4f00: 68 65 73 20 28 75 69 6e 74 31 36 2a 20 70 4d 2c hes (uint16* pM,
4f10: 0a 20 20 20 20 75 69 6e 74 33 32 20 2a 70 50 43 . uint32 *pPC
4f20: 2c 20 75 69 6e 74 33 32 20 2a 70 4d 41 2c 20 69 , uint32 *pMA, i
4f30: 6e 74 33 32 20 2a 70 4d 42 2c 20 69 6e 74 33 32 nt32 *pMB, int32
4f40: 20 2a 70 4c 41 43 2c 20 69 6e 74 33 32 20 2a 70 *pLAC, int32 *p
4f50: 49 46 2c 0a 20 20 20 20 69 6e 74 33 32 20 2a 70 IF,. int32 *p
4f60: 44 46 2c 20 69 6e 74 33 32 2a 20 70 69 6e 74 5f DF, int32* pint_
4f70: 72 65 71 29 0a 7b 0a 20 20 20 20 2f 2f 20 45 78 req).{. // Ex
4f80: 69 74 20 65 61 72 6c 79 20 69 66 20 74 68 65 20 it early if the
4f90: 62 6c 69 6e 6b 20 74 68 72 65 61 64 20 68 61 73 blink thread has
4fa0: 20 6e 6f 74 20 61 74 74 61 63 68 65 64 20 69 74 not attached it
4fb0: 73 65 6c 66 20 74 6f 20 74 68 65 20 47 50 49 4f self to the GPIO
4fc0: 0a 20 20 20 20 2f 2f 20 70 65 72 69 70 68 65 72 . // peripher
4fd0: 61 6c 20 69 6e 20 74 68 65 20 50 69 2c 20 73 69 al in the Pi, si
4fe0: 6e 63 65 20 74 68 61 74 20 6d 65 61 6e 73 20 77 nce that means w
4ff0: 65 20 63 61 6e 6e 6f 74 20 73 61 66 65 6c 79 20 e cannot safely
5000: 69 6e 74 65 72 70 72 65 74 20 74 68 65 0a 20 20 interpret the.
5010: 20 20 2f 2f 20 64 61 74 61 20 69 6e 20 74 68 65 // data in the
5020: 20 73 77 69 74 63 68 73 74 61 74 75 73 20 61 72 switchstatus ar
5030: 72 61 79 2e 20 20 54 68 69 73 20 69 73 20 65 73 ray. This is es
5040: 70 65 63 69 61 6c 6c 79 20 69 6d 70 6f 72 74 61 pecially importa
5050: 6e 74 20 6f 6e 0a 20 20 20 20 2f 2f 20 6e 6f 6e nt on. // non
5060: 2d 50 69 20 68 6f 73 74 73 2c 20 73 69 6e 63 65 -Pi hosts, since
5070: 20 73 77 69 74 63 68 73 74 61 74 75 73 20 77 69 switchstatus wi
5080: 6c 6c 20 72 65 6d 61 69 6e 20 7a 65 72 6f 65 64 ll remain zeroed
5090: 2c 20 77 68 69 63 68 20 77 65 20 77 6f 75 6c 64 , which we would
50a0: 0a 20 20 20 20 2f 2f 20 69 6e 74 65 72 70 72 65 . // interpre
50b0: 74 20 61 73 20 22 61 6c 6c 20 73 77 69 74 63 68 t as "all switch
50c0: 65 73 20 61 72 65 20 70 72 65 73 73 65 64 21 22 es are pressed!"
50d0: 2c 20 63 61 75 73 69 6e 67 20 68 61 76 6f 63 2e , causing havoc.
50e0: 0a 20 20 20 20 2f 2f 0a 20 20 20 20 2f 2f 20 49 . //. // I
50f0: 74 20 77 6f 75 6c 64 20 62 65 20 63 68 65 61 70 t would be cheap
5100: 65 72 20 66 6f 72 20 6f 75 72 20 63 61 6c 6c 65 er for our calle
5110: 72 20 74 6f 20 63 68 65 63 6b 20 74 68 69 73 20 r to check this
5120: 66 6f 72 20 75 73 20 61 6e 64 20 73 6b 69 70 20 for us and skip
5130: 74 68 65 0a 20 20 20 20 2f 2f 20 63 61 6c 6c 2c the. // call,
5140: 20 62 75 74 20 74 68 65 72 65 27 73 20 6e 6f 20 but there's no
5150: 67 6f 6f 64 20 72 65 61 73 6f 6e 20 74 6f 20 65 good reason to e
5160: 78 70 6f 73 65 20 73 75 63 68 20 69 6d 70 6c 65 xpose such imple
5170: 6d 65 6e 74 61 74 69 6f 6e 73 0a 20 20 20 20 2f mentations. /
5180: 2f 20 64 65 74 61 69 6c 73 20 74 6f 20 69 74 2e / details to it.
5190: 20 20 57 65 27 72 65 20 74 72 79 69 6e 67 20 74 We're trying t
51a0: 6f 20 6b 65 65 70 20 74 68 65 20 50 44 50 2d 38 o keep the PDP-8
51b0: 20 73 69 6d 75 6c 61 74 6f 72 27 73 20 43 50 55 simulator's CPU
51c0: 20 63 6f 72 65 0a 20 20 20 20 2f 2f 20 61 73 20 core. // as
51d0: 66 72 65 65 20 6f 66 20 50 69 44 50 2d 38 2f 49 free of PiDP-8/I
51e0: 20 64 65 74 61 69 6c 73 20 61 73 20 69 73 20 70 details as is p
51f0: 72 61 63 74 69 63 61 6c 2e 0a 20 20 20 20 69 66 ractical.. if
5200: 20 28 21 70 69 64 70 38 69 5f 67 70 69 6f 5f 70 (!pidp8i_gpio_p
5210: 72 65 73 65 6e 74 29 20 72 65 74 75 72 6e 20 70 resent) return p
5220: 66 74 5f 6e 6f 72 6d 61 6c 3b 0a 0a 20 20 20 20 ft_normal;..
5230: 2f 2f 20 48 61 6e 64 6c 65 20 74 68 65 20 6e 6f // Handle the no
5240: 6e 73 74 61 6e 64 61 72 64 20 53 49 4e 47 5f 53 nstandard SING_S
5250: 54 45 50 20 2b 20 58 20 63 6f 6d 62 6f 73 2c 20 TEP + X combos,
5260: 73 6f 6d 65 20 6f 66 20 77 68 69 63 68 20 68 61 some of which ha
5270: 6c 74 0a 20 20 20 20 2f 2f 20 74 68 65 20 70 72 lt. // the pr
5280: 6f 63 65 73 73 6f 72 2e 0a 20 20 20 20 69 66 20 ocessor.. if
5290: 28 68 61 6e 64 6c 65 5f 73 69 6e 67 5f 73 74 65 (handle_sing_ste
52a0: 70 20 28 28 73 77 69 74 63 68 73 74 61 74 75 73 p ((switchstatus
52b0: 5b 32 5d 20 26 20 53 53 32 5f 53 5f 53 54 45 50 [2] & SS2_S_STEP
52c0: 29 20 3d 3d 20 30 29 20 3d 3d 20 70 66 74 5f 68 ) == 0) == pft_h
52d0: 61 6c 74 29 20 7b 0a 20 20 20 20 20 20 20 20 72 alt) {. r
52e0: 65 74 75 72 6e 20 70 66 74 5f 68 61 6c 74 3b 0a eturn pft_halt;.
52f0: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2f 20 43 68 }.. // Ch
5300: 65 63 6b 20 66 6f 72 20 53 49 4e 47 5f 49 4e 53 eck for SING_INS
5310: 54 20 73 77 69 74 63 68 20 63 6c 6f 73 65 2e 2e T switch close..
5320: 2e 0a 20 20 20 20 69 66 20 28 28 28 73 77 69 74 .. if (((swit
5330: 63 68 73 74 61 74 75 73 5b 32 5d 20 26 20 53 53 chstatus[2] & SS
5340: 32 5f 53 5f 49 4e 53 54 29 20 3d 3d 20 30 29 20 2_S_INST) == 0)
5350: 26 26 20 28 73 77 53 69 6e 67 49 6e 73 74 20 3d && (swSingInst =
5360: 3d 20 30 29 29 20 7b 0a 20 20 20 20 20 20 20 20 = 0)) {.
5370: 2f 2f 20 50 75 74 20 74 68 65 20 70 72 6f 63 65 // Put the proce
5380: 73 73 6f 72 20 69 6e 20 73 74 6f 70 20 6d 6f 64 ssor in stop mod
5390: 65 20 75 6e 74 69 6c 20 77 65 20 67 65 74 20 61 e until we get a
53a0: 20 43 4f 4e 54 20 6f 72 20 53 54 41 52 54 0a 20 CONT or START.
53b0: 20 20 20 20 20 20 20 2f 2f 20 73 77 69 74 63 68 // switch
53c0: 20 63 6c 6f 73 75 72 65 2e 20 20 54 65 63 68 6e closure. Techn
53d0: 69 63 61 6c 6c 79 20 74 68 69 73 20 69 73 20 77 ically this is w
53e0: 72 6f 6e 67 20 61 63 63 6f 72 64 69 6e 67 20 74 rong according t
53f0: 6f 20 44 45 43 27 73 0a 20 20 20 20 20 20 20 20 o DEC's.
5400: 2f 2f 20 64 6f 63 73 3a 20 77 65 27 72 65 20 73 // docs: we're s
5410: 75 70 70 6f 73 65 64 20 74 6f 20 66 69 6e 69 73 upposed to finis
5420: 68 20 65 78 65 63 75 74 69 6e 67 20 74 68 65 20 h executing the
5430: 6e 65 78 74 20 69 6e 73 74 72 75 63 74 69 6f 6e next instruction
5440: 0a 20 20 20 20 20 20 20 20 2f 2f 20 62 65 66 6f . // befo
5450: 72 65 20 77 65 20 22 63 6c 65 61 72 20 74 68 65 re we "clear the
5460: 20 52 55 4e 20 66 6c 69 70 2d 66 6c 6f 70 22 20 RUN flip-flop"
5470: 69 6e 20 44 45 43 20 74 65 72 6d 73 2c 20 77 68 in DEC terms, wh
5480: 65 72 65 61 73 0a 20 20 20 20 20 20 20 20 2f 2f ereas. //
5490: 20 77 65 27 72 65 20 74 65 73 74 69 6e 67 20 74 we're testing t
54a0: 68 65 73 65 20 73 77 69 74 63 68 65 73 20 62 65 hese switches be
54b0: 66 6f 72 65 20 77 65 20 66 65 74 63 68 20 74 68 fore we fetch th
54c0: 65 20 6e 65 78 74 0a 20 20 20 20 20 20 20 20 2f e next. /
54d0: 2f 20 69 6e 73 74 72 75 63 74 69 6f 6e 2e 20 20 / instruction.
54e0: 53 68 6f 77 20 6d 65 20 68 6f 77 20 69 74 20 6d Show me how it m
54f0: 61 74 74 65 72 73 2c 20 61 6e 64 20 49 27 6c 6c atters, and I'll
5500: 20 66 69 78 20 69 74 2e 20 3a 29 0a 20 20 20 20 fix it. :).
5510: 20 20 20 20 73 65 74 5f 73 69 6e 67 6c 65 5f 69 set_single_i
5520: 6e 73 74 5f 66 6c 61 67 20 28 31 29 3b 0a 20 20 nst_flag (1);.
5530: 20 20 20 20 20 20 73 65 74 5f 73 74 6f 70 5f 66 set_stop_f
5540: 6c 61 67 20 28 31 29 3b 0a 20 20 20 20 7d 0a 0a lag (1);. }..
5550: 20 20 20 20 2f 2f 20 2e 2e 2e 61 6e 64 20 53 49 // ...and SI
5560: 4e 47 5f 49 4e 53 54 20 73 77 69 74 63 68 20 6f NG_INST switch o
5570: 70 65 6e 0a 20 20 20 20 69 66 20 28 73 77 53 69 pen. if (swSi
5580: 6e 67 49 6e 73 74 20 26 26 20 28 73 77 69 74 63 ngInst && (switc
5590: 68 73 74 61 74 75 73 5b 32 5d 20 26 20 53 53 32 hstatus[2] & SS2
55a0: 5f 53 5f 49 4e 53 54 29 29 20 7b 0a 20 20 20 20 _S_INST)) {.
55b0: 20 20 20 20 73 65 74 5f 73 69 6e 67 6c 65 5f 69 set_single_i
55c0: 6e 73 74 5f 66 6c 61 67 20 28 30 29 3b 0a 20 20 nst_flag (0);.
55d0: 20 20 7d 0a 0a 20 20 20 20 2f 2f 20 43 68 65 63 }.. // Chec
55e0: 6b 20 66 6f 72 20 53 54 41 52 54 20 73 77 69 74 k for START swit
55f0: 63 68 20 70 72 65 73 73 2e 2e 2e 0a 20 20 20 20 ch press....
5600: 73 74 61 74 69 63 20 69 6e 74 20 73 77 53 74 61 static int swSta
5610: 72 74 20 3d 20 30 3b 0a 20 20 20 20 69 66 20 28 rt = 0;. if (
5620: 28 28 73 77 69 74 63 68 73 74 61 74 75 73 5b 32 ((switchstatus[2
5630: 5d 20 26 20 53 53 32 5f 53 54 41 52 54 29 20 3d ] & SS2_START) =
5640: 3d 20 30 29 20 26 26 20 28 73 77 53 74 61 72 74 = 0) && (swStart
5650: 20 3d 3d 20 30 29 29 20 7b 0a 20 20 20 20 20 20 == 0)) {.
5660: 20 20 2a 70 69 6e 74 5f 72 65 71 20 3d 20 2a 70 *pint_req = *p
5670: 69 6e 74 5f 72 65 71 20 26 20 7e 49 4e 54 5f 49 int_req & ~INT_I
5680: 4f 4e 3b 20 2f 2f 20 64 69 73 61 62 6c 65 20 49 ON; // disable I
5690: 4f 4e 2e 20 73 61 79 73 20 73 6f 20 69 6e 20 68 ON. says so in h
56a0: 61 6e 64 62 6f 6f 6b 2c 20 74 72 75 65 3f 0a 20 andbook, true?.
56b0: 20 20 20 20 20 20 20 2a 70 4c 41 43 20 3d 20 30 *pLAC = 0
56c0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
56d0: 20 20 20 20 20 20 20 20 20 2f 2f 20 63 6c 65 61 // clea
56e0: 72 20 4c 20 61 6e 64 20 41 43 3b 0a 20 20 20 20 r L and AC;.
56f0: 20 20 20 20 2a 70 4d 42 20 3d 20 30 3b 20 20 20 *pMB = 0;
5700: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5710: 20 20 20 20 20 20 2f 2f 20 63 6c 65 61 72 20 4d // clear M
5720: 42 2e 0a 20 20 20 20 20 20 20 20 2a 70 4d 41 20 B.. *pMA
5730: 3d 20 2a 70 50 43 20 26 20 30 37 37 37 37 3b 20 = *pPC & 07777;
5740: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 //
5750: 74 72 61 6e 73 66 65 72 20 50 43 20 69 6e 74 6f transfer PC into
5760: 20 4d 41 20 28 46 49 58 4d 45 3a 20 64 6f 65 73 MA (FIXME: does
5770: 20 49 52 20 6d 61 6b 65 20 74 68 69 73 20 75 6e IR make this un
5780: 6e 65 63 65 73 73 61 72 79 3f 29 0a 20 20 20 20 necessary?).
5790: 20 20 20 20 73 65 74 5f 73 74 6f 70 5f 66 6c 61 set_stop_fla
57a0: 67 20 28 30 29 3b 20 20 20 20 20 20 20 20 20 20 g (0);
57b0: 20 20 20 20 20 20 2f 2f 20 53 54 41 52 54 20 63 // START c
57c0: 61 6e 63 65 6c 73 20 53 54 4f 50 20 6d 6f 64 65 ancels STOP mode
57d0: 0a 20 20 20 20 20 20 20 20 73 65 74 5f 73 69 6e . set_sin
57e0: 67 6c 65 5f 69 6e 73 74 5f 66 6c 61 67 20 28 30 gle_inst_flag (0
57f0: 29 3b 20 20 20 20 20 20 20 20 20 2f 2f 20 61 6c ); // al
5800: 6c 6f 77 20 53 49 4e 47 20 49 4e 53 54 20 6d 6f low SING INST mo
5810: 64 65 20 72 65 2d 65 6e 74 72 79 0a 20 20 20 20 de re-entry.
5820: 20 20 20 20 73 77 53 74 61 72 74 20 3d 20 31 3b swStart = 1;
5830: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5840: 20 20 20 20 20 20 2f 2f 20 6d 61 6b 65 20 69 74 // make it
5850: 20 73 69 6e 67 6c 65 2d 73 68 6f 74 0a 20 20 20 single-shot.
5860: 20 7d 0a 0a 20 20 20 20 2f 2f 20 2e 2e 2e 61 6e }.. // ...an
5870: 64 20 53 54 41 52 54 20 73 77 69 74 63 68 20 72 d START switch r
5880: 65 6c 65 61 73 65 0a 20 20 20 20 69 66 20 28 73 elease. if (s
5890: 77 53 74 61 72 74 20 26 26 20 28 73 77 69 74 63 wStart && (switc
58a0: 68 73 74 61 74 75 73 5b 32 5d 20 26 20 53 53 32 hstatus[2] & SS2
58b0: 5f 53 54 41 52 54 29 29 20 7b 0a 20 20 20 20 20 _START)) {.
58c0: 20 20 20 73 77 53 74 61 72 74 20 3d 20 30 3b 0a swStart = 0;.
58d0: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2f 20 43 68 }.. // Ch
58e0: 65 63 6b 20 66 6f 72 20 43 4f 4e 54 20 73 77 69 eck for CONT swi
58f0: 74 63 68 20 70 72 65 73 73 2e 2e 2e 0a 20 20 20 tch press....
5900: 20 73 74 61 74 69 63 20 69 6e 74 20 73 77 43 6f static int swCo
5910: 6e 74 20 3d 20 30 3b 0a 20 20 20 20 69 66 20 28 nt = 0;. if (
5920: 28 28 73 77 69 74 63 68 73 74 61 74 75 73 5b 32 ((switchstatus[2
5930: 5d 20 26 20 53 53 32 5f 43 4f 4e 54 29 20 3d 3d ] & SS2_CONT) ==
5940: 20 30 29 20 26 26 20 28 73 77 43 6f 6e 74 20 3c 0) && (swCont <
5950: 20 32 29 29 20 7b 0a 20 20 20 20 20 20 20 20 69 2)) {. i
5960: 66 20 28 73 77 43 6f 6e 74 20 3d 3d 20 30 29 20 f (swCont == 0)
5970: 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f {. //
5980: 20 4f 6e 20 74 68 65 20 69 6e 69 74 69 61 6c 20 On the initial
5990: 43 4f 4e 54 20 70 72 65 73 73 2c 20 72 65 6c 65 CONT press, rele
59a0: 61 73 65 20 73 74 6f 70 20 6d 6f 64 65 20 72 65 ase stop mode re
59b0: 67 61 72 64 6c 65 73 73 0a 20 20 20 20 20 20 20 gardless.
59c0: 20 20 20 20 20 2f 2f 20 6f 66 20 68 6f 77 20 69 // of how i
59d0: 74 20 77 61 73 20 65 6e 61 62 6c 65 64 20 74 6f t was enabled to
59e0: 20 65 78 65 63 75 74 65 20 74 68 65 20 6e 65 78 execute the nex
59f0: 74 20 69 6e 73 74 72 75 63 74 69 6f 6e 2e 0a 20 t instruction..
5a00: 20 20 20 20 20 20 20 20 20 20 20 2f 2f 0a 20 20 //.
5a10: 20 20 20 20 20 20 20 20 20 20 2f 2f 20 46 49 58 // FIX
5a20: 4d 45 3a 20 41 72 65 20 77 65 20 68 61 6e 64 6c ME: Are we handl
5a30: 69 6e 67 20 4d 42 20 63 6f 72 72 65 63 74 6c 79 ing MB correctly
5a40: 3f 20 5b 39 37 33 32 37 31 61 65 33 36 5d 0a 20 ? [973271ae36].
5a50: 20 20 20 20 20 20 20 20 20 20 20 73 65 74 5f 73 set_s
5a60: 74 6f 70 5f 66 6c 61 67 20 28 30 29 3b 0a 20 20 top_flag (0);.
5a70: 20 20 20 20 20 20 20 20 20 20 73 77 43 6f 6e 74 swCont
5a80: 20 3d 20 31 3b 20 20 20 20 20 20 20 20 20 20 20 = 1;
5a90: 20 20 20 20 20 20 2f 2f 20 6d 61 6b 65 20 69 74 // make it
5aa0: 20 73 69 6e 67 6c 65 2d 73 68 6f 74 0a 20 20 20 single-shot.
5ab0: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 65 }. e
5ac0: 6c 73 65 20 69 66 20 28 73 77 43 6f 6e 74 20 3d lse if (swCont =
5ad0: 3d 20 31 29 20 7b 0a 20 20 20 20 20 20 20 20 20 = 1) {.
5ae0: 20 20 20 2f 2f 20 54 68 65 20 73 65 63 6f 6e 64 // The second
5af0: 20 74 69 6d 65 20 77 65 20 63 6f 6d 65 20 62 61 time we come ba
5b00: 63 6b 20 69 6e 20 68 65 72 65 20 77 68 69 6c 65 ck in here while
5b10: 20 74 68 65 20 43 4f 4e 54 0a 20 20 20 20 20 20 the CONT.
5b20: 20 20 20 20 20 20 2f 2f 20 73 77 69 74 63 68 20 // switch
5b30: 69 73 20 73 74 69 6c 6c 20 64 6f 77 6e 20 2d 2d is still down --
5b40: 20 74 68 65 20 68 75 6d 61 6e 20 69 73 20 74 6f the human is to
5b50: 6f 20 73 6c 6f 77 20 74 6f 0a 20 20 20 20 20 20 o slow to.
5b60: 20 20 20 20 20 20 2f 2f 20 72 65 6c 65 61 73 65 // release
5b70: 20 69 74 20 62 65 74 77 65 65 6e 20 69 74 65 72 it between iter
5b80: 61 74 69 6f 6e 73 20 2d 2d 20 77 65 20 73 74 6f ations -- we sto
5b90: 70 20 70 61 79 69 6e 67 20 61 74 74 65 6e 74 69 p paying attenti
5ba0: 6f 6e 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f on. /
5bb0: 2f 20 74 6f 20 69 74 20 75 6e 74 69 6c 20 74 68 / to it until th
5bc0: 65 20 73 77 69 74 63 68 20 6f 70 65 6e 73 3b 20 e switch opens;
5bd0: 63 68 65 63 6b 20 62 65 6c 6f 77 2e 20 20 52 65 check below. Re
5be0: 2d 65 6e 74 65 72 20 73 74 6f 70 0a 20 20 20 20 -enter stop.
5bf0: 20 20 20 20 20 20 20 20 2f 2f 20 6d 6f 64 65 20 // mode
5c00: 69 66 20 53 49 4e 47 5f 49 4e 53 54 20 69 73 20 if SING_INST is
5c10: 73 74 69 6c 6c 20 63 6c 6f 73 65 64 2c 20 65 6c still closed, el
5c20: 73 65 20 6c 65 61 76 65 20 73 74 6f 70 20 6d 6f se leave stop mo
5c30: 64 65 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f de. /
5c40: 2f 20 62 65 63 61 75 73 65 20 77 65 20 6d 75 73 / because we mus
5c50: 74 20 68 61 76 65 20 73 74 6f 70 70 65 64 20 76 t have stopped v
5c60: 69 61 20 53 54 4f 50 20 6f 72 20 48 4c 54 2e 0a ia STOP or HLT..
5c70: 20 20 20 20 20 20 20 20 20 20 20 20 73 65 74 5f set_
5c80: 73 74 6f 70 5f 66 6c 61 67 20 28 21 21 73 77 53 stop_flag (!!swS
5c90: 69 6e 67 49 6e 73 74 29 3b 0a 20 20 20 20 20 20 ingInst);.
5ca0: 20 20 20 20 20 20 73 77 43 6f 6e 74 20 3d 20 32 swCont = 2
5cb0: 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 ;. }.
5cc0: 7d 0a 0a 20 20 20 20 2f 2f 20 2e 2e 2e 61 6e 64 }.. // ...and
5cd0: 20 43 4f 4e 54 20 73 77 69 74 63 68 20 72 65 6c CONT switch rel
5ce0: 65 61 73 65 0a 20 20 20 20 69 66 20 28 73 77 43 ease. if (swC
5cf0: 6f 6e 74 20 26 26 20 28 73 77 69 74 63 68 73 74 ont && (switchst
5d00: 61 74 75 73 5b 32 5d 20 26 20 53 53 32 5f 43 4f atus[2] & SS2_CO
5d10: 4e 54 29 29 20 7b 0a 20 20 20 20 20 20 20 20 73 NT)) {. s
5d20: 77 43 6f 6e 74 20 3d 20 30 3b 0a 20 20 20 20 7d wCont = 0;. }
5d30: 0a 0a 20 20 20 20 2f 2f 20 43 68 65 63 6b 20 66 .. // Check f
5d40: 6f 72 20 4c 4f 41 44 5f 41 44 44 20 73 77 69 74 or LOAD_ADD swit
5d50: 63 68 20 70 72 65 73 73 2e 20 20 28 4e 6f 20 22 ch press. (No "
5d60: 61 6e 64 20 72 65 6c 65 61 73 65 22 20 62 65 61 and release" bea
5d70: 63 75 73 65 20 69 74 27 73 0a 20 20 20 20 2f 2f cuse it's. //
5d80: 20 68 61 72 6d 6c 65 73 73 20 69 66 20 74 68 69 harmless if thi
5d90: 73 20 6b 65 65 70 73 20 68 61 70 70 65 6e 69 6e s keeps happenin
5da0: 67 20 75 6e 74 69 6c 20 74 68 65 20 73 6c 6f 77 g until the slow
5db0: 20 68 75 6d 61 6e 20 72 65 6c 65 61 73 65 73 20 human releases
5dc0: 74 68 65 0a 20 20 20 20 2f 2f 20 73 77 69 74 63 the. // switc
5dd0: 68 2e 20 20 54 68 69 73 20 66 75 6e 63 74 69 6f h. This functio
5de0: 6e 20 69 73 20 69 64 65 6d 70 6f 74 65 6e 74 2e n is idempotent.
5df0: 29 0a 20 20 20 20 69 66 20 28 28 73 77 69 74 63 ). if ((switc
5e00: 68 73 74 61 74 75 73 5b 32 5d 20 26 20 53 53 32 hstatus[2] & SS2
5e10: 5f 4c 5f 41 44 44 29 20 3d 3d 20 30 29 20 7b 0a _L_ADD) == 0) {.
5e20: 20 20 20 20 20 20 20 20 2f 2f 20 43 6f 70 79 20 // Copy
5e30: 53 52 20 69 6e 74 6f 20 50 43 2e 20 20 57 65 27 SR into PC. We'
5e40: 72 65 20 58 4f 52 69 6e 67 20 69 6e 73 74 65 61 re XORing instea
5e50: 64 20 6f 66 20 6d 61 73 6b 69 6e 67 20 61 6e 64 d of masking and
5e60: 20 63 6f 70 79 69 6e 67 0a 20 20 20 20 20 20 20 copying.
5e70: 20 2f 2f 20 62 65 63 61 75 73 65 20 74 68 65 20 // because the
5e80: 73 77 69 74 63 68 73 74 61 74 75 73 20 62 69 74 switchstatus bit
5e90: 73 20 61 72 65 20 6f 70 70 6f 73 69 74 65 20 77 s are opposite w
5ea0: 68 61 74 20 77 65 20 77 61 6e 74 20 68 65 72 65 hat we want here
5eb0: 3a 20 77 65 0a 20 20 20 20 20 20 20 20 2f 2f 20 : we. //
5ec0: 67 65 74 20 61 20 30 20 66 72 6f 6d 20 74 68 65 get a 0 from the
5ed0: 20 47 50 49 4f 20 70 65 72 69 70 68 65 72 61 6c GPIO peripheral
5ee0: 20 77 68 65 6e 20 74 68 65 20 73 77 69 74 63 68 when the switch
5ef0: 20 69 73 20 63 6c 6f 73 65 64 2c 20 77 68 69 63 is closed, whic
5f00: 68 0a 20 20 20 20 20 20 20 20 2f 2f 20 69 73 20 h. // is
5f10: 74 68 65 20 73 77 69 74 63 68 27 73 20 22 31 22 the switch's "1"
5f20: 20 70 6f 73 69 74 69 6f 6e 2e 0a 20 20 20 20 20 position..
5f30: 20 20 20 2a 70 50 43 20 3d 20 73 77 69 74 63 68 *pPC = switch
5f40: 73 74 61 74 75 73 5b 30 5d 20 5e 20 30 37 37 37 status[0] ^ 0777
5f50: 37 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 7;.
5f60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5f70: 20 20 0a 20 20 20 20 20 20 20 20 2f 2f 20 43 6f . // Co
5f80: 70 79 20 44 46 20 73 77 69 74 63 68 20 73 65 74 py DF switch set
5f90: 74 69 6e 67 73 20 74 6f 20 44 46 20 72 65 67 69 tings to DF regi
5fa0: 73 74 65 72 0a 20 20 20 20 20 20 20 20 2f 2f 0a ster. //.
5fb0: 20 20 20 20 20 20 20 20 2f 2f 20 54 68 65 20 73 // The s
5fc0: 68 69 66 74 20 69 73 20 62 65 63 61 75 73 65 20 hift is because
5fd0: 74 68 65 20 44 46 20 70 6f 73 69 74 69 6f 6e 73 the DF positions
5fe0: 20 69 6e 73 69 64 65 20 74 68 65 20 73 77 69 74 inside the swit
5ff0: 63 68 73 74 61 74 75 73 5b 31 5d 0a 20 20 20 20 chstatus[1].
6000: 20 20 20 20 2f 2f 20 72 65 67 69 73 74 65 72 20 // register
6010: 68 61 70 70 65 6e 20 74 6f 20 62 65 20 33 20 62 happen to be 3 b
6020: 69 74 20 70 6f 73 69 74 69 6f 6e 73 20 6f 66 66 it positions off
6030: 20 6f 66 20 77 68 65 72 65 20 77 65 20 77 61 6e of where we wan
6040: 74 20 74 68 65 6d 0a 20 20 20 20 20 20 20 20 2f t them. /
6050: 2f 20 69 6e 20 44 46 20 68 65 72 65 3a 20 77 65 / in DF here: we
6060: 20 77 61 6e 74 20 74 6f 20 62 65 20 61 62 6c 65 want to be able
6070: 20 74 6f 20 6c 6f 67 69 63 61 6c 6c 79 20 4f 52 to logically OR
6080: 20 50 43 20 61 6e 64 20 44 46 20 74 6f 20 6d 61 PC and DF to ma
6090: 6b 65 0a 20 20 20 20 20 20 20 20 2f 2f 20 31 35 ke. // 15
60a0: 2d 62 69 74 20 64 61 74 61 20 61 63 63 65 73 73 -bit data access
60b0: 20 61 64 64 72 65 73 73 65 73 2e 0a 20 20 20 20 addresses..
60c0: 20 20 20 20 2f 2f 0a 20 20 20 20 20 20 20 20 2f //. /
60d0: 2f 20 57 65 20 63 6f 6d 70 6c 65 6d 65 6e 74 20 / We complement
60e0: 74 68 65 20 62 69 74 73 20 68 65 72 65 20 66 6f the bits here fo
60f0: 72 20 74 68 65 20 73 61 6d 65 20 72 65 61 73 6f r the same reaso
6100: 6e 20 77 65 20 58 4f 52 27 64 20 74 68 65 20 50 n we XOR'd the P
6110: 43 0a 20 20 20 20 20 20 20 20 2f 2f 20 76 61 6c C. // val
6120: 75 65 20 61 62 6f 76 65 2e 0a 20 20 20 20 20 20 ue above..
6130: 20 20 75 69 6e 74 31 36 5f 74 20 63 73 73 31 20 uint16_t css1
6140: 3d 20 7e 73 77 69 74 63 68 73 74 61 74 75 73 5b = ~switchstatus[
6150: 31 5d 3b 20 0a 20 20 20 20 20 20 20 20 2a 70 44 1]; . *pD
6160: 46 20 3d 20 28 63 73 73 31 20 26 20 53 53 31 5f F = (css1 & SS1_
6170: 44 46 5f 41 4c 4c 29 20 3c 3c 20 33 3b 0a 0a 20 DF_ALL) << 3;..
6180: 20 20 20 20 20 20 20 2f 2f 20 44 6f 20 74 68 65 // Do the
6190: 20 73 61 6d 65 20 66 6f 72 20 49 46 2e 20 20 54 same for IF. T
61a0: 68 65 20 6f 6e 6c 79 20 64 69 66 66 65 72 65 6e he only differen
61b0: 63 65 20 63 6f 6d 65 73 20 66 72 6f 6d 20 74 68 ce comes from th
61c0: 65 20 66 61 63 74 20 74 68 61 74 0a 20 20 20 20 e fact that.
61d0: 20 20 20 20 2f 2f 20 49 46 20 69 73 20 74 68 65 // IF is the
61e0: 20 6e 65 78 74 20 33 20 62 69 74 73 20 64 6f 77 next 3 bits dow
61f0: 6e 20 69 6e 20 73 77 69 74 63 68 73 74 61 74 75 n in switchstatu
6200: 73 5b 31 5d 2e 0a 20 20 20 20 20 20 20 20 2a 70 s[1].. *p
6210: 49 46 20 3d 20 28 63 73 73 31 20 26 20 53 53 31 IF = (css1 & SS1
6220: 5f 49 46 5f 41 4c 4c 29 20 3c 3c 20 36 3b 0a 20 _IF_ALL) << 6;.
6230: 20 20 20 7d 0a 0a 20 20 20 20 2f 2f 20 43 68 65 }.. // Che
6240: 63 6b 20 66 6f 72 20 44 45 50 20 73 77 69 74 63 ck for DEP switc
6250: 68 20 70 72 65 73 73 2e 2e 2e 0a 20 20 20 20 73 h press.... s
6260: 74 61 74 69 63 20 69 6e 74 20 73 77 44 65 70 20 tatic int swDep
6270: 3d 20 30 3b 0a 20 20 20 20 69 66 20 28 28 28 73 = 0;. if (((s
6280: 77 69 74 63 68 73 74 61 74 75 73 5b 32 5d 20 26 witchstatus[2] &
6290: 20 53 53 32 5f 44 45 50 29 20 3d 3d 20 30 29 20 SS2_DEP) == 0)
62a0: 26 26 20 28 73 77 44 65 70 20 3d 3d 20 30 29 29 && (swDep == 0))
62b0: 20 7b 0a 20 20 20 20 20 20 20 20 70 4d 5b 2a 70 {. pM[*p
62c0: 50 43 5d 20 3d 20 73 77 69 74 63 68 73 74 61 74 PC] = switchstat
62d0: 75 73 5b 30 5d 20 5e 20 30 37 37 37 37 3b 20 20 us[0] ^ 07777;
62e0: 20 20 2f 2f 20 58 4f 52 20 72 61 74 69 6f 6e 61 // XOR rationa
62f0: 6c 65 20 61 62 6f 76 65 0a 20 20 20 20 20 20 20 le above.
6300: 20 2f 2a 20 3f 3f 3f 20 69 6e 20 36 36 20 68 61 /* ??? in 66 ha
6310: 6e 64 62 6f 6f 6b 3a 20 73 74 72 69 63 74 6c 79 ndbook: strictly
6320: 20 73 70 65 61 6b 69 6e 67 2c 20 53 52 20 67 6f speaking, SR go
6330: 65 73 20 69 6e 74 6f 20 41 43 2c 0a 20 20 20 20 es into AC,.
6340: 20 20 20 20 20 20 20 74 68 65 6e 20 41 43 20 69 then AC i
6350: 6e 74 6f 20 4d 42 2e 20 44 6f 65 73 20 69 74 20 nto MB. Does it
6360: 63 6c 65 61 72 20 41 43 20 61 66 74 65 72 77 61 clear AC afterwa
6370: 72 64 73 3f 20 49 66 20 6e 6f 74 2c 20 6e 65 65 rds? If not, nee
6380: 64 73 20 66 69 78 20 2a 2f 0a 20 20 20 20 20 20 ds fix */.
6390: 20 20 2a 70 4d 42 20 3d 20 70 4d 5b 2a 70 50 43 *pMB = pM[*pPC
63a0: 5d 3b 0a 20 20 20 20 20 20 20 20 2a 70 4d 41 20 ];. *pMA
63b0: 3d 20 2a 70 50 43 20 26 20 30 37 37 37 37 3b 20 = *pPC & 07777;
63c0: 20 20 20 20 20 20 20 20 20 2f 2f 20 4d 41 20 74 // MA t
63d0: 72 61 69 6c 73 20 50 43 20 6f 6e 20 46 50 0a 20 rails PC on FP.
63e0: 20 20 20 20 20 20 20 2a 70 50 43 20 3d 20 28 2a *pPC = (*
63f0: 70 50 43 20 2b 20 31 29 20 26 20 30 37 37 37 37 pPC + 1) & 07777
6400: 3b 20 20 20 20 2f 2f 20 69 6e 63 72 65 6d 65 6e ; // incremen
6410: 74 20 50 43 0a 20 20 20 20 20 20 20 20 73 77 44 t PC. swD
6420: 65 70 20 3d 20 31 3b 20 20 20 20 20 20 20 20 20 ep = 1;
6430: 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 6d 61 // ma
6440: 6b 65 20 69 74 20 73 69 6e 67 6c 65 2d 73 68 6f ke it single-sho
6450: 74 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2f 20 t. }.. //
6460: 2e 2e 2e 61 6e 64 20 44 45 50 20 73 77 69 74 63 ...and DEP switc
6470: 68 20 72 65 6c 65 61 73 65 0a 20 20 20 20 69 66 h release. if
6480: 20 28 73 77 44 65 70 20 26 26 20 28 73 77 69 74 (swDep && (swit
6490: 63 68 73 74 61 74 75 73 5b 32 5d 20 26 20 53 53 chstatus[2] & SS
64a0: 32 5f 44 45 50 29 29 20 7b 0a 20 20 20 20 20 20 2_DEP)) {.
64b0: 20 20 73 77 44 65 70 20 3d 20 30 3b 0a 20 20 20 swDep = 0;.
64c0: 20 7d 0a 0a 20 20 20 20 2f 2f 20 43 68 65 63 6b }.. // Check
64d0: 20 66 6f 72 20 45 58 41 4d 20 73 77 69 74 63 68 for EXAM switch
64e0: 20 70 72 65 73 73 2e 2e 2e 0a 20 20 20 20 73 74 press.... st
64f0: 61 74 69 63 20 69 6e 74 20 73 77 45 78 61 6d 20 atic int swExam
6500: 3d 20 30 3b 0a 20 20 20 20 69 66 20 28 28 28 73 = 0;. if (((s
6510: 77 69 74 63 68 73 74 61 74 75 73 5b 32 5d 20 26 witchstatus[2] &
6520: 20 53 53 32 5f 45 58 41 4d 29 20 3d 3d 20 30 29 SS2_EXAM) == 0)
6530: 20 26 26 20 28 73 77 45 78 61 6d 20 3d 3d 20 30 && (swExam == 0
6540: 29 29 20 7b 0a 20 20 20 20 20 20 20 20 2a 70 4d )) {. *pM
6550: 42 20 3d 20 70 4d 5b 2a 70 50 43 5d 3b 0a 20 20 B = pM[*pPC];.
6560: 20 20 20 20 20 20 2a 70 4d 41 20 3d 20 2a 70 50 *pMA = *pP
6570: 43 20 26 20 30 37 37 37 37 3b 20 20 20 20 20 20 C & 07777;
6580: 20 20 20 20 2f 2f 20 4d 41 20 74 72 61 69 6c 73 // MA trails
6590: 20 50 43 20 6f 6e 20 46 50 0a 20 20 20 20 20 20 PC on FP.
65a0: 20 20 2a 70 50 43 20 3d 20 28 2a 70 50 43 20 2b *pPC = (*pPC +
65b0: 20 31 29 20 26 20 30 37 37 37 37 3b 20 20 20 20 1) & 07777;
65c0: 2f 2f 20 69 6e 63 72 65 6d 65 6e 74 20 50 43 0a // increment PC.
65d0: 20 20 20 20 20 20 20 20 73 77 45 78 61 6d 20 3d swExam =
65e0: 20 31 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 1;
65f0: 20 20 20 20 20 20 2f 2f 20 6d 61 6b 65 20 69 74 // make it
6600: 20 73 69 6e 67 6c 65 2d 73 68 6f 74 0a 20 20 20 single-shot.
6610: 20 7d 0a 0a 20 20 20 20 2f 2f 20 2e 2e 2e 61 6e }.. // ...an
6620: 64 20 45 58 41 4d 20 73 77 69 74 63 68 20 72 65 d EXAM switch re
6630: 6c 65 61 73 65 0a 20 20 20 20 69 66 20 28 73 77 lease. if (sw
6640: 45 78 61 6d 20 26 26 20 28 73 77 69 74 63 68 73 Exam && (switchs
6650: 74 61 74 75 73 5b 32 5d 20 26 20 53 53 32 5f 45 tatus[2] & SS2_E
6660: 58 41 4d 29 29 20 7b 0a 20 20 20 20 20 20 20 20 XAM)) {.
6670: 73 77 45 78 61 6d 20 3d 20 30 3b 0a 20 20 20 20 swExam = 0;.
6680: 7d 0a 0a 20 20 20 20 2f 2f 20 43 68 65 63 6b 20 }.. // Check
6690: 66 6f 72 20 53 54 4f 50 20 73 77 69 74 63 68 20 for STOP switch
66a0: 70 72 65 73 73 2e 20 20 4e 6f 20 22 61 6e 64 20 press. No "and
66b0: 72 65 6c 65 61 73 65 22 20 62 65 63 61 75 73 65 release" because
66c0: 20 77 65 20 67 65 74 20 6f 75 74 20 6f 66 0a 20 we get out of.
66d0: 20 20 20 2f 2f 20 53 54 4f 50 20 6d 6f 64 65 20 // STOP mode
66e0: 77 69 74 68 20 53 54 41 52 54 20 6f 72 20 43 4f with START or CO
66f0: 4e 54 2c 20 6e 6f 74 20 62 79 20 72 65 6c 65 61 NT, not by relea
6700: 73 69 6e 67 20 53 54 4f 50 2c 20 61 6e 64 20 77 sing STOP, and w
6710: 68 69 6c 65 20 69 6e 0a 20 20 20 20 2f 2f 20 53 hile in. // S
6720: 54 4f 50 20 6d 6f 64 65 2c 20 74 68 69 73 20 73 TOP mode, this s
6730: 77 69 74 63 68 27 73 20 66 75 6e 63 74 69 6f 6e witch's function
6740: 20 69 73 20 69 64 65 6d 70 6f 74 65 6e 74 2e 0a is idempotent..
6750: 20 20 20 20 69 66 20 28 28 73 77 69 74 63 68 73 if ((switchs
6760: 74 61 74 75 73 5b 32 5d 20 26 20 53 53 32 5f 53 tatus[2] & SS2_S
6770: 54 4f 50 29 20 3d 3d 20 30 29 20 7b 0a 20 20 20 TOP) == 0) {.
6780: 20 20 20 20 20 73 65 74 5f 73 74 6f 70 5f 66 6c set_stop_fl
6790: 61 67 20 28 31 29 3b 0a 20 20 20 20 7d 0a 0a 20 ag (1);. }..
67a0: 20 20 20 2f 2f 20 49 66 20 61 6e 79 20 6f 66 20 // If any of
67b0: 74 68 65 20 61 62 6f 76 65 20 70 75 74 20 75 73 the above put us
67c0: 20 69 6e 74 6f 20 53 54 4f 50 20 6d 6f 64 65 2c into STOP mode,
67d0: 20 67 6f 20 6e 6f 20 66 75 72 74 68 65 72 2e 20 go no further.
67e0: 20 49 6e 0a 20 20 20 20 2f 2f 20 70 61 72 74 69 In. // parti
67f0: 63 75 6c 61 72 2c 20 66 65 74 63 68 20 6e 6f 20 cular, fetch no
6800: 6d 6f 72 65 20 69 6e 73 74 72 75 63 74 69 6f 6e more instruction
6810: 73 2c 20 61 6e 64 20 64 6f 20 6e 6f 74 20 74 6f s, and do not to
6820: 75 63 68 20 50 43 21 0a 20 20 20 20 69 66 20 28 uch PC!. if (
6830: 73 77 53 74 6f 70 20 3d 3d 20 31 29 20 72 65 74 swStop == 1) ret
6840: 75 72 6e 20 70 66 74 5f 73 74 6f 70 3b 0a 0a 20 urn pft_stop;..
6850: 20 20 20 72 65 74 75 72 6e 20 70 66 74 5f 6e 6f return pft_no
6860: 72 6d 61 6c 3b 0a 7d 0a 0a 0a 2f 2f 2f 2f 20 67 rmal;.}...//// g
6870: 65 74 5f 73 77 69 74 63 68 5f 72 65 67 69 73 74 et_switch_regist
6880: 65 72 20 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f er /////////////
6890: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
68a0: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
68b0: 2f 2f 0a 2f 2f 20 52 65 74 75 72 6e 20 74 68 65 //.// Return the
68c0: 20 63 75 72 72 65 6e 74 20 63 6f 6e 74 65 6e 74 current content
68d0: 73 20 6f 66 20 74 68 65 20 73 77 69 74 63 68 20 s of the switch
68e0: 72 65 67 69 73 74 65 72 0a 0a 69 6e 74 33 32 20 register..int32
68f0: 67 65 74 5f 73 77 69 74 63 68 5f 72 65 67 69 73 get_switch_regis
6900: 74 65 72 20 28 76 6f 69 64 29 0a 7b 0a 20 20 20 ter (void).{.
6910: 20 72 65 74 75 72 6e 20 73 77 69 74 63 68 73 74 return switchst
6920: 61 74 75 73 5b 30 5d 20 5e 20 30 37 37 37 37 3b atus[0] ^ 07777;
6930: 0a 7d 0a 0a 0a 2f 2f 2f 2f 20 70 64 70 38 5f 63 .}...//// pdp8_c
6940: 70 75 5f 72 75 6e 6e 69 6e 67 20 2f 2f 2f 2f 2f pu_running /////
6950: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
6960: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f ////////////////
6970: 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 2f 0a 2f 2f /////////////.//
6980: 20 52 65 74 75 72 6e 73 20 74 72 75 65 20 69 66 Returns true if
6990: 20 77 65 27 72 65 20 6e 6f 74 20 69 6e 20 53 54 we're not in ST
69a0: 4f 50 20 6d 6f 64 65 2e 0a 0a 69 6e 74 20 70 64 OP mode...int pd
69b0: 70 38 5f 63 70 75 5f 72 75 6e 6e 69 6e 67 20 28 p8_cpu_running (
69c0: 76 6f 69 64 29 0a 7b 0a 20 20 20 20 72 65 74 75 void).{. retu
69d0: 72 6e 20 73 77 53 74 6f 70 20 3d 3d 20 30 3b 0a rn swStop == 0;.
69e0: 7d 0a }.