-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
2264 lines (2152 loc) · 70.3 KB
/
Copy pathindex.html
File metadata and controls
2264 lines (2152 loc) · 70.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BDP-1 Emulator</title>
<style>
:root {
--bg: #d4d4d4;
--panel: #ececec;
--panel-dk: #c0c0c0;
--ink: #111;
--header-bg: #1f3a6b;
--header-fg: #fff;
--led-off: #2a0808;
--led-off-bd:#3a1010;
--led-on: #ff3030;
--led-on-bd: #ff7070;
--led-on-glow:#ff2020;
--screen-bg: #0a0a0a;
--term-bg: #000;
--term-fg: #ffcc00;
--tool-bg: #f0f0f0;
--btn-bg: #f8f8f8;
--btn-bd: #888;
--sel-bg: #222;
--sel-fg: #ffd84d;
--mem-cur: #ffe680;
--mem-cur-bd:#c89000;
}
html, body {
background: var(--bg);
color: var(--ink);
font-family: 'Cascadia Mono', 'Menlo', 'Courier New', monospace;
margin: 0;
padding: 0;
font-size: 13px;
line-height: 1.3;
}
body {
padding: 12px;
box-sizing: border-box;
height: 100vh;
overflow: hidden;
}
.layout {
display: grid;
grid-template-columns: max-content max-content 1fr;
gap: 12px;
height: 100%;
}
.col { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
/* A panel marked .fill stretches to fill the column, with its content
(the div after .panel-title) growing to fill the panel. */
.fill {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.fill > div:not(.panel-title) {
flex: 1;
min-height: 0;
}
.fill > .panel-body {
display: flex;
flex-direction: column;
}
.fill > .panel-body > textarea {
flex: 1;
min-height: 0;
resize: none;
}
/* ---------- Header (msu blue banner) ---------- */
.header, .toolbar { flex: 0 0 auto; }
.header {
background: var(--header-bg);
color: var(--header-fg);
display: flex;
align-items: stretch;
padding: 0;
overflow: hidden;
}
.logo-msu {
display: flex;
gap: 2px;
padding: 6px;
background: var(--header-bg);
}
.logo-msu span {
width: 28px; height: 28px;
background: #fff;
color: var(--header-bg);
display: flex; align-items: center; justify-content: center;
font-family: 'Helvetica Neue', Arial, sans-serif;
font-weight: 700;
font-size: 18px;
font-style: italic;
}
.header-title {
flex: 1;
display: flex;
align-items: baseline;
gap: 14px;
padding: 6px 16px;
font-size: 26px;
font-style: italic;
font-family: 'Helvetica Neue', Arial, sans-serif;
font-weight: 500;
letter-spacing: 0.04em;
}
.header-sub {
font-size: 15px;
font-style: italic;
font-weight: 400;
color: rgba(255, 255, 255, 0.75);
letter-spacing: 0.02em;
}
.panel-title-link {
font-weight: 400;
font-size: 12px;
letter-spacing: 0.02em;
color: #1f3a6b;
text-decoration: none;
padding: 0 4px;
}
.panel-title-link:hover { text-decoration: underline; }
.header-readme {
display: none;
align-self: center;
margin-left: auto;
padding: 0 16px;
font-size: 13px;
color: rgba(255, 255, 255, 0.85);
text-decoration: none;
letter-spacing: 0.04em;
}
.header-readme:hover { text-decoration: underline; }
/* ---------- Toolbar ---------- */
.toolbar {
background: var(--tool-bg);
padding: 8px;
display: flex;
gap: 6px;
flex-wrap: wrap;
align-items: center;
border-bottom: 1px solid var(--btn-bd);
}
.toolbar select, .toolbar button {
font-family: inherit;
font-size: 13px;
border: 1px solid var(--btn-bd);
padding: 3px 10px;
cursor: pointer;
}
.toolbar select {
background: var(--sel-bg);
color: var(--sel-fg);
padding: 3px 6px;
}
.toolbar button {
background: var(--btn-bg);
color: var(--ink);
min-width: 56px;
}
.toolbar button:hover:not(:disabled) { background: #fff; }
.toolbar button:active:not(:disabled) { background: #ddd; }
.toolbar button:disabled { color: #aaa; cursor: default; }
.toolbar .status {
margin-left: auto;
font-size: 12px;
padding: 2px 8px;
color: #333;
}
.toolbar .status.halted { color: #b50; }
.toolbar .status.running { color: #0a0; }
.toolbar .status.error { color: #c00; }
/* ---------- Panels ---------- */
.panel {
background: var(--panel);
border: 1px solid var(--btn-bd);
}
.panel-title {
background: var(--panel-dk);
padding: 4px 8px;
font-weight: 700;
font-size: 13px;
letter-spacing: 0.05em;
border-bottom: 1px solid var(--btn-bd);
display: flex;
align-items: center;
justify-content: space-between;
}
.panel-body { padding: 8px; }
/* ---------- Register panel (black with red LEDs) ---------- */
.regpanel {
background: #000;
color: #ccc;
padding: 10px 12px;
}
.reg-row, .mem-row {
display: grid;
grid-template-columns: 2em auto 3em 2.5em 7em;
align-items: center;
gap: 8px;
padding: 2px 6px;
white-space: nowrap;
}
.mem-row { grid-template-columns: 2.8em auto 3em 2.5em 7em; }
.reg-row .v, .mem-row .v { text-align: right; }
.reg-row .asm, .mem-row .asm {
color: #888;
font-size: 12px;
text-align: left;
}
.reg-row.pc, .mem-row.pc {
background: rgba(255, 216, 77, 0.18);
box-shadow: inset 0 0 0 1px #ffd84d;
}
.reg-row.pc .name, .mem-row.pc .addr { color: #ffd84d; }
.reg-row.pc .v, .mem-row.pc .v { color: #ffe680; }
.reg-row.pc .asm, .mem-row.pc .asm { color: #ffd84d; }
/* peek: highlight a memory cell that something is pointing at (mouse hover) */
.mem-row.peek {
background: rgba(120, 200, 255, 0.18);
box-shadow: inset 0 0 0 1px #78c8ff;
}
.mem-row.peek.pc { box-shadow: inset 0 0 0 1px #ffd84d, inset 0 0 0 2px #78c8ff; }
.mem-row.peek .addr { color: #78c8ff; }
/* hex span is clickable/hover-able */
.v.hex { cursor: pointer; }
.v.hex:hover { color: #78c8ff; }
/* IR row: hide hex/dec, let ASM take the remaining columns */
.asm-only .v { display: none; }
.asm-only .asm { grid-column: 3 / -1; color: #ddd; }
.reg-row .name, .mem-row .addr {
color: #ddd;
font-weight: 600;
letter-spacing: 0.05em;
}
.mem-row .addr { color: #888; }
.mem-row .addr:hover { color: #ffd84d; text-decoration: underline; }
.reg-row .v, .mem-row .v {
color: #ddd;
font-variant-numeric: tabular-nums;
text-align: right;
}
.leds { display: inline-flex; gap: 4px; align-items: center; }
.leds .gap { display: inline-block; width: 6px; }
/* Bit cells — square, slightly rounded, no glow */
.led {
width: 18px;
height: 18px;
border-radius: 3px;
background: #2a1010;
border: 1px solid #4a1818;
cursor: pointer;
box-sizing: border-box;
transition: background 60ms, border-color 60ms;
}
.led:hover { border-color: #7a2828; }
.led.on {
background: #d83030;
border-color: #f05050;
}
/* ---------- Memory scroll ---------- */
#memory {
overflow-y: auto;
background: #000;
padding: 10px 12px;
}
/* Divider above IP/IR/DR */
.reg-row.sep { border-top: 1px solid #333; margin-top: 4px; padding-top: 4px; }
/* Read-only LEDs (IP/IR/DR) — visually subdued cursor */
.led.ro { cursor: default; }
.led.ro:hover { border-color: #4a1818; }
#memory::-webkit-scrollbar { width: 12px; }
#memory::-webkit-scrollbar-track { background: #111; }
#memory::-webkit-scrollbar-thumb { background: #444; }
#memory::-webkit-scrollbar-thumb:hover { background: #666; }
/* ---------- Screen ---------- */
.screen-wrap {
background: var(--screen-bg);
padding: 10px;
display: flex;
justify-content: center;
}
canvas#screen {
image-rendering: pixelated;
display: block;
background: #000;
}
/* ---------- Terminal-style output ---------- */
.terminal {
background: var(--term-bg);
color: var(--term-fg);
padding: 10px;
height: 10em;
overflow-y: auto;
white-space: pre-wrap;
word-break: break-word;
font-size: 13px;
}
/* ---------- Program editor ---------- */
textarea#program {
width: 100%;
box-sizing: border-box;
background: #fff;
color: #111;
border: 1px solid var(--btn-bd);
padding: 6px 8px;
font-family: inherit;
font-size: 13px;
}
.ed-controls { display: flex; gap: 6px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.ed-controls button, .ed-controls select {
font-family: inherit;
font-size: 13px;
border: 1px solid var(--btn-bd);
background: var(--btn-bg);
padding: 3px 10px;
cursor: pointer;
}
.ed-controls select { background: var(--sel-bg); color: var(--sel-fg); padding: 3px 6px; }
.err {
color: #c00;
font-size: 12px;
margin-top: 4px;
white-space: pre-wrap;
}
/* ---------- Tabs in PROGRAM panel ---------- */
.panel-title .tabs { display: inline-flex; gap: 2px; margin-left: 8px; }
.panel-title .tab {
background: var(--btn-bg);
border: 1px solid var(--btn-bd);
padding: 2px 10px;
font: inherit;
font-size: 12px;
cursor: pointer;
color: #555;
}
.panel-title .tab.active {
background: var(--header-bg);
color: var(--header-fg);
border-color: var(--header-bg);
}
.panel-title .tab:hover:not(.active) { background: #fff; }
.tab-body[hidden] { display: none; }
/* ---------- Punch card view ---------- */
.card-body {
display: grid;
grid-template-columns: auto 1fr;
gap: 10px;
padding: 8px;
overflow: auto;
min-height: 0;
}
.punch-card {
background: #efdfa8;
color: #2b1a05;
border: 1px solid #8a6610;
padding: 10px 14px 12px;
box-shadow: 0 1px 3px rgba(0,0,0,0.22), inset 0 0 0 1px #e2c977;
font-family: 'Cascadia Mono', 'Menlo', 'Courier New', monospace;
font-size: 12px;
width: 356px;
box-sizing: border-box;
justify-self: start;
position: relative;
overflow: hidden;
/* faint horizontal ruled lines like a real card form */
background-image:
linear-gradient(rgba(122, 88, 30, 0.06) 1px, transparent 1px);
background-size: 100% 24px;
background-position: 0 56px;
}
/* Notched top-right corner — covers the corner with page color and
paints the diagonal border via the rotated square's bottom edge. */
.punch-card::after {
content: '';
position: absolute;
top: -22px;
right: -22px;
width: 44px;
height: 44px;
background: var(--bg);
transform: rotate(45deg);
border-bottom: 1px solid #8a6610;
pointer-events: none;
}
.card-brand {
text-align: center;
font-size: 9px;
letter-spacing: 0.22em;
color: #7a5818;
padding-bottom: 6px;
border-bottom: 1px dashed #b69b5d;
margin-bottom: 6px;
text-transform: uppercase;
/* leave room so the notched corner doesn't overlap the brand text */
padding-right: 36px;
}
.card-footer {
text-align: center;
font-size: 9px;
letter-spacing: 0.22em;
color: #7a5818;
margin-top: 8px;
padding-top: 6px;
border-top: 1px dashed #b69b5d;
text-transform: uppercase;
}
.card-header,
.punch-row {
display: grid;
/* fixed widths so toggling cells never reflows the row */
grid-template-columns: 3em 11.5em 10em;
gap: 12px;
align-items: end;
padding: 0 4px 6px;
}
.card-header {
border-bottom: 1px dashed #b69b5d;
margin-bottom: 4px;
font-size: 10px;
letter-spacing: 0.1em;
color: #6b5320;
text-transform: uppercase;
}
.card-bits-h {
display: inline-flex;
gap: 3px;
align-items: end;
}
.card-bits-h .bit-col {
display: inline-flex;
flex-direction: column;
align-items: center;
width: 12px;
line-height: 1;
}
.card-bits-h .bit-col small {
font-size: 7px;
color: #9a7530;
letter-spacing: 0;
margin-top: 1px;
}
.card-bits-h .bits-gap { width: 5px; display: inline-block; }
.card-note-h { font-style: italic; }
.punch-row {
align-items: center;
padding: 1px 4px;
}
.punch-row .paddr {
color: #6b5320;
font-size: 11px;
}
.punch-holes { display: inline-flex; gap: 3px; align-items: center; }
.punch-holes .gap { display: inline-block; width: 5px; }
.hole {
width: 12px; height: 18px;
border: 1px solid #b69257;
border-radius: 5px;
background: #faf0d2;
cursor: pointer;
box-sizing: border-box;
transition: background 60ms;
position: relative;
}
.hole:hover { border-color: #5a3812; }
.hole.on {
background: #2a1500;
border-color: #1a0d00;
box-shadow: inset 0 1px 2px rgba(0,0,0,0.55);
}
/* subtle "punched" highlight along the top edge */
.hole.on::after {
content: '';
position: absolute;
top: 0; left: 1px; right: 1px;
height: 2px;
background: rgba(255, 220, 150, 0.18);
border-radius: 5px 5px 0 0;
pointer-events: none;
}
.punch-note {
font-family: 'Marker Felt', 'Bradley Hand', 'Comic Sans MS', cursive;
font-size: 14px;
color: #2a5cb8;
line-height: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* operand bytes get a different "data" treatment */
.punch-note.operand {
color: #7a5818;
font-style: italic;
cursor: help;
}
/* row hover-highlighted because something points at it */
.punch-row.peek {
background: rgba(220, 170, 50, 0.32);
box-shadow: inset 0 0 0 1px #8a6610;
}
.card-controls {
display: flex;
gap: 6px;
margin-top: 10px;
padding-top: 8px;
border-top: 1px dashed #b69b5d;
}
.card-controls button {
background: #fff8e0;
color: #2b1a05;
border: 1px solid #8a6610;
font-family: inherit;
font-size: 12px;
padding: 3px 10px;
cursor: pointer;
letter-spacing: 0.05em;
}
.card-controls button:hover { background: #fff; }
.card-controls button:active { background: #e8d59a; }
/* Cheat-sheet (stapled reference card) */
.cheat-sheet {
background: #efdfa8;
color: #2b1a05;
border: 1px solid #8a6610;
padding: 8px 10px;
font-family: 'Cascadia Mono', 'Menlo', 'Courier New', monospace;
font-size: 10px;
min-width: 11.5em;
align-self: start;
box-shadow: 0 1px 3px rgba(0,0,0,0.22), inset 0 0 0 1px #e2c977;
}
.cheat-brand, .cheat-footer {
text-align: center;
font-size: 8px;
letter-spacing: 0.18em;
color: #7a5818;
text-transform: uppercase;
padding: 2px 0;
line-height: 1.4;
}
.cheat-brand { border-bottom: 1px dashed #b69b5d; margin-bottom: 6px; }
.cheat-footer { border-top: 1px dashed #b69b5d; margin-top: 6px; }
.cheat-sheet h4 {
margin: 5px 0 1px;
font-size: 9px;
letter-spacing: 0.1em;
color: #6b5320;
text-transform: uppercase;
font-weight: 700;
}
.cheat-sheet h4:first-of-type { margin-top: 0; }
.cheat-sheet table { border-collapse: collapse; width: auto; }
.cheat-sheet td { padding: 0 4px 0 0; vertical-align: top; white-space: nowrap; }
.cheat-sheet td.bits { color: #8a6610; font-size: 9px; }
/* the vertical R-encoding key at the bottom */
.cheat-regkey { display: inline-grid; grid-template-columns: auto auto; gap: 0 6px; font-size: 9px; }
.cheat-regkey .lab { color: #8a6610; }
/* ---------- HLL (ByteTran) tab ---------- */
.hll-body {
display: grid;
grid-template-columns: 1fr auto;
gap: 10px;
padding: 8px;
min-height: 0;
}
.hll-edit {
display: flex;
flex-direction: column;
gap: 6px;
min-height: 0;
}
.hll-pane { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.hll-label {
font-size: 10px;
letter-spacing: 0.1em;
color: #888;
padding: 2px 0;
}
#hll-src {
flex: 1;
min-height: 0;
background: #fff;
color: #111;
border: 1px solid var(--btn-bd);
padding: 6px 8px;
font-family: inherit;
font-size: 13px;
resize: none;
}
.hll-out {
flex: 1;
min-height: 0;
overflow: auto;
margin: 0;
background: #111;
color: #9c9;
border: 1px solid var(--btn-bd);
padding: 6px 8px;
font-family: inherit;
font-size: 12px;
white-space: pre;
}
.hll-out.err { color: #f88; }
.hll-help {
background: #fafafa;
border: 1px solid var(--btn-bd);
padding: 8px 10px;
font-size: 11px;
min-width: 16em;
max-width: 22em;
overflow: auto;
}
.hll-help h4 {
margin: 6px 0 2px;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #555;
}
.hll-help code {
background: #eee;
padding: 0 3px;
border-radius: 2px;
}
.hll-help pre {
background: #fff;
border: 1px solid #ddd;
padding: 4px 6px;
margin: 4px 0;
font-size: 11px;
white-space: pre-wrap;
}
::selection { background: #ffd84d; color: #000; }
/* ---------- Mobile / narrow screens ---------- */
@media (max-width: 900px) {
body {
height: auto;
overflow: auto;
padding: 8px;
}
.layout {
grid-template-columns: 1fr;
height: auto;
}
.col { min-width: 0; }
.fill { flex: 0 0 auto; }
.header-title { font-size: 20px; padding: 6px 12px; }
.header-sub { font-size: 13px; }
.header-readme { display: inline-block; }
.panel-title .panel-title-link { display: none; }
.toolbar { gap: 4px; }
.toolbar button { min-width: 0; padding: 3px 8px; }
.screen-wrap { padding: 6px; }
canvas#screen { width: 100% !important; height: auto !important; max-width: 320px; aspect-ratio: 1 / 1; }
#memory { max-height: 60vh; overflow: auto; }
.card-body, .hll-body {
grid-template-columns: 1fr;
}
.cheat, .hll-help {
min-width: 0;
max-width: none;
width: 100%;
box-sizing: border-box;
}
.punch-card { margin: 0 auto; }
textarea#program, #hll-src { min-height: 240px; }
.hll-out { min-height: 160px; }
.reg-row, .mem-row {
grid-template-columns: 2.8em auto 3em 2.5em 1fr;
gap: 6px;
}
.panel-title { flex-wrap: wrap; gap: 4px; }
}
</style>
</head>
<body>
<div class="layout">
<!-- COLUMN 1: header + toolbar + registers + screen -->
<div class="col">
<div class="header">
<div class="logo-msu"><span>m</span><span>s</span><span>u</span></div>
<div class="header-title">BDP-1<span class="header-sub">Byte Data Processor</span></div>
<a class="header-readme" href="https://github.com/msu/bdp/blob/master/README.md" target="_blank" rel="noopener">README</a>
</div>
<div class="toolbar">
<select id="speed">
<option value="1">1 Hz</option>
<option value="10">10 Hz</option>
<option value="60" selected>60 Hz</option>
<option value="200">200 Hz</option>
<option value="1000">1 KHz</option>
</select>
<button id="btn-run">run</button>
<button id="btn-step">step</button>
<button id="btn-stop" disabled>stop</button>
<button id="btn-reset">reset</button>
<span class="status" id="status">READY</span>
</div>
<div class="panel">
<div class="panel-title">REGISTERS</div>
<div class="regpanel" id="registers"></div>
</div>
<div class="panel">
<div class="panel-title">SCREEN <span style="font-weight:normal;color:#666">16x16 / RGB332</span></div>
<div class="screen-wrap">
<canvas id="screen" width="16" height="16" style="width:320px;height:320px"></canvas>
</div>
</div>
</div>
<!-- COLUMN 2: memory -->
<div class="col">
<div class="panel fill">
<div class="panel-title">MEMORY</div>
<div id="memory"></div>
</div>
</div>
<!-- COLUMN 3: program then output -->
<div class="col">
<div class="panel fill">
<div class="panel-title">
PROGRAM
<span class="tabs">
<button class="tab active" data-tab="card">CARD</button>
<button class="tab" data-tab="asm">ASM</button>
<button class="tab" data-tab="hll">ByteTran</button>
</span>
<a class="panel-title-link" href="https://github.com/msu/bdp/blob/master/README.md" target="_blank" rel="noopener">README</a>
</div>
<!-- ASM mode -->
<div class="panel-body tab-body" data-tab="asm" hidden>
<textarea id="program" spellcheck="false"></textarea>
<div class="ed-controls">
<button id="btn-assemble">ASSEMBLE & LOAD</button>
<select id="examples">
<option value="">-- examples --</option>
<option value="rand-pixels">RANDOM PIXELS</option>
<option value="count">COUNT TO 10</option>
<option value="sweep">COLOR SWEEP</option>
<option value="subroutine">JSR DEMO</option>
<option value="indirect">INDIRECT ARRAY SUM</option>
<option value="moire">XOR MOIRE</option>
</select>
</div>
<div class="err" id="asm-err"></div>
</div>
<!-- CARD mode: punch card + cheat sheet -->
<div class="tab-body card-body" data-tab="card">
<div class="punch-card">
<div class="card-brand">M S U · BDP-1 PROGRAM CARD · FORM 8-BIT</div>
<div class="card-header">
<span class="card-addr-h">ADDR</span>
<span class="card-bits-h">
<span class="bit-col">7<small>128</small></span>
<span class="bit-col">6<small>64</small></span>
<span class="bit-col">5<small>32</small></span>
<span class="bit-col">4<small>16</small></span>
<span class="bits-gap"></span>
<span class="bit-col">3<small>8</small></span>
<span class="bit-col">2<small>4</small></span>
<span class="bit-col">1<small>2</small></span>
<span class="bit-col">0<small>1</small></span>
</span>
<span class="card-note-h">decoded</span>
</div>
<div id="punch-rows"></div>
<div class="card-controls">
<button id="btn-load-card">LOAD CARD</button>
<button id="btn-clear-card">NEW CARD</button>
</div>
<div class="card-footer">DO NOT FOLD, SPINDLE, OR MUTILATE</div>
</div>
<div class="cheat-sheet" id="cheat-sheet"></div>
</div>
<!-- ByteTran mode -->
<div class="tab-body hll-body" data-tab="hll" hidden>
<div class="hll-edit">
<div class="hll-pane">
<div class="hll-label">SOURCE</div>
<textarea id="hll-src" spellcheck="false"></textarea>
</div>
<div class="hll-pane">
<div class="hll-label">COMPILED ASSEMBLY (read-only)</div>
<pre id="hll-asm" class="hll-out"></pre>
</div>
<div class="ed-controls">
<button id="btn-compile">COMPILE & LOAD</button>
<select id="hll-examples">
<option value="">-- examples --</option>
<option value="bt-count">COUNT 0..N</option>
<option value="bt-fib">FIBONACCI</option>
<option value="bt-echo">ECHO</option>
</select>
</div>
</div>
<div class="hll-help" id="hll-help"></div>
</div>
</div>
<div class="panel">
<div class="panel-title">OUTPUT</div>
<div class="terminal" id="output"></div>
</div>
</div>
</div>
<script>
// ============================================================
// BDP-1 STATE
// ============================================================
const MEM_SIZE = 256;
const REG_NAMES = ['A', 'B', 'C', 'D'];
const state = {
mem: new Uint8Array(MEM_SIZE),
reg: new Uint8Array(4),
pc: 0,
halted: false,
screen: new Uint8Array(256),
output: '',
error: null,
};
function readByte(a) { return state.mem[a & 0xFF]; }
function writeByte(a, v) { state.mem[a & 0xFF] = v & 0xFF; }
// ============================================================
// INTERPRETER
// ============================================================
function step() {
if (state.halted) return;
const instr = readByte(state.pc);
const top = (instr >> 4) & 0xF;
const bot = instr & 0xF;
let nextPC = (state.pc + 1) & 0xFF;
let didJump = false;
switch (top) {
case 0x0: { // SYS (single)
if (bot === 0x0) state.halted = true;
else if (bot === 0x1) state.output += state.reg[0] + ' ';
else if (bot === 0x2) {
const s = window.prompt('RINT - enter unsigned integer (0..255):', '0');
const n = parseInt(s, 10);
state.reg[0] = (isNaN(n) ? 0 : n) & 0xFF;
}
else if ((bot & 0xC) === 0x8) state.reg[bot & 0x3] = (Math.random() * 256) | 0;
else if (bot === 0xF) { /* NOOP */ }
else state.error = 'bad SYS op ' + bot.toString(2);
break;
}
case 0x1: { // GFX (single)
if (bot === 0x0) state.screen.fill(0);
else if (bot === 0x1) {
const x = state.reg[1] & 0xF, y = state.reg[2] & 0xF;
state.screen[y * 16 + x] = state.reg[3];
}
else state.error = 'bad GFX op';
break;
}
case 0x2: { // MOV reg, reg (single) SSDD
const ss = (bot >> 2) & 0x3, dd = bot & 0x3;
state.reg[dd] = state.reg[ss];
break;
}
case 0x3: { // MOV reg, [reg] (single) PPDD — indirect load
const pp = (bot >> 2) & 0x3, dd = bot & 0x3;
state.reg[dd] = readByte(state.reg[pp]);
break;
}
case 0x4: { // MOV [reg], reg (single) PPSS — indirect store
const pp = (bot >> 2) & 0x3, ss = bot & 0x3;
writeByte(state.reg[pp], state.reg[ss]);
break;
}
case 0x5: { // RMATH (single) — accumulator: bot = OORR, A is dest
const op = (bot >> 2) & 0x3;
const v = state.reg[bot & 0x3];
if (op === 0x0) state.reg[0] = (state.reg[0] + v) & 0xFF;
else if (op === 0x1) state.reg[0] = (state.reg[0] - v) & 0xFF;
else if (op === 0x2) state.reg[0] = (state.reg[0] * v) & 0xFF;
else state.reg[0] = v === 0 ? 0 : ((state.reg[0] / v) | 0) & 0xFF;
break;
}
case 0x6: { // Unary register ops (single) — bot = OORR
// OO = 00 INC, 01 DEC, 10 NEG, 11 ZERO
const op = (bot >> 2) & 0x3;
const rr = bot & 0x3;
if (op === 0x0) state.reg[rr] = (state.reg[rr] + 1) & 0xFF;
else if (op === 0x1) state.reg[rr] = (state.reg[rr] - 1) & 0xFF;
else if (op === 0x2) state.reg[rr] = (256 - state.reg[rr]) & 0xFF;
else state.reg[rr] = 0;
break;
}
case 0x7: { // RLOGIC (single) — accumulator: bot = OORR, A is dest
const op = (bot >> 2) & 0x3;
const v = state.reg[bot & 0x3];
if (op === 0x0) state.reg[0] = state.reg[0] & v;
else if (op === 0x1) state.reg[0] = state.reg[0] | v;
else if (op === 0x2) state.reg[0] = state.reg[0] ^ v;
else state.reg[0] = v >= 8 ? 0 : ((state.reg[0] << v) & 0xFF);
break;
}
case 0x8: { // MEM (double)
const arg = readByte(nextPC);
nextPC = (nextPC + 1) & 0xFF;
const rr = bot & 0x3, op = (bot >> 2) & 0x3;
if (op === 0x0) state.reg[rr] = readByte(arg);
else if (op === 0x1) state.reg[rr] = arg;
else if (op === 0x2) writeByte(arg, state.reg[rr]);
else state.error = 'bad MEM op';
break;
}
case 0x9: { // MATH (double)
const arg = readByte(nextPC);
nextPC = (nextPC + 1) & 0xFF;
const rr = bot & 0x3, op = (bot >> 2) & 0x3, v = readByte(arg);
if (op === 0x0) state.reg[rr] = (state.reg[rr] + v) & 0xFF;
else if (op === 0x1) state.reg[rr] = (state.reg[rr] - v) & 0xFF;
else if (op === 0x2) state.reg[rr] = (state.reg[rr] * v) & 0xFF;
else state.reg[rr] = v === 0 ? 0 : ((state.reg[rr] / v) | 0) & 0xFF;
break;
}
case 0xA: { // JUMP (double)
const arg = readByte(nextPC);
nextPC = (nextPC + 1) & 0xFF;
const a = state.reg[0];
const isZero = a === 0, isNeg = (a & 0x80) !== 0, isPos = !isZero && !isNeg;
if (bot === 0x0) { state.pc = arg; didJump = true; }
else if (bot === 0x1 && isZero) { state.pc = arg; didJump = true; }
else if (bot === 0x2 && isPos) { state.pc = arg; didJump = true; }
else if (bot === 0x3 && isNeg) { state.pc = arg; didJump = true; }
else if (bot === 0x4) { writeByte(arg, nextPC); state.pc = (arg + 1) & 0xFF; didJump = true; }
else if (bot === 0x5) { state.pc = readByte(arg); didJump = true; }
break;
}
case 0xB: { // LOGIC (double)
const arg = readByte(nextPC);
nextPC = (nextPC + 1) & 0xFF;
const rr = bot & 0x3, op = (bot >> 2) & 0x3, v = readByte(arg);
if (op === 0x0) state.reg[rr] = state.reg[rr] & v;
else if (op === 0x1) state.reg[rr] = state.reg[rr] | v;
else if (op === 0x2) state.reg[rr] = state.reg[rr] ^ v;
else state.reg[rr] = v >= 8 ? 0 : ((state.reg[rr] << v) & 0xFF);
break;
}
default:
state.error = 'unknown top nibble ' + top.toString(2).padStart(4, '0');
}
if (!didJump) state.pc = nextPC;
if (state.error) state.halted = true;
}
// ============================================================
// DISASSEMBLER (single byte, with optional operand from next byte)
// ============================================================
const _RR = ['A', 'B', 'C', 'D'];
function disasmByte(b, next) {
const top = (b >> 4) & 0xF;
const bot = b & 0xF;
const hex2 = n => n.toString(16).toUpperCase().padStart(2, '0');
const arg = () => hex2(next & 0xFF);
switch (top) {
case 0x0: // SYS
if (bot === 0x0) return 'HALT';
if (bot === 0x1) return 'WINT';
if (bot === 0x2) return 'RINT';
if ((bot & 0xC) === 0x8) return 'RAND ' + _RR[bot & 3];
if (bot === 0xF) return 'NOOP';
return '';