forked from jonbstanley/Tek405xEmulator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TEKTRONIX4051.js
1715 lines (1355 loc) · 57.5 KB
/
TEKTRONIX4051.js
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
/*
*
* JSMSX - MSX Emulator in Javascript
* Copyright (c) 2006 Marcus Granado <mrc.gran(@)gmail.com>
*
* Portions of the initial code was inspired by the work of
* Arnon Cardoso's Java MSX Emulator and
* Adam Davidson & Andrew Pollard's Z80 class of the Spectrum Java Emulator
* after reading this thread: http://www.msx.org/forumtopic4176.html
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
* The full license is available at http://www.gnu.org/licenses/gpl.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Completely revamped to support the hardware of the Tektronix 4051 by Dave Roberts.
* Other contributors: Jon Stanley
*
*/
function TEKTRONIX4051( windowObj, canvasObj ) {
// Hardware components
var display = new TekDisplay(this, canvasObj);
var keyboard = new TekKeyboard(this, windowObj);
var cpu = new TekCpu(this);
var rom = new Tek4051Rom;
var ram = new Array(32*1024);
var romexp = new ROMexp;
var storage = new Storage();
var osc;
var ctx;
// MC6820 PIA notation
// * CRA = Control Register A
// * CRB = Control Register B
// * ORA = Output Register A
// * ORB = Output Register B
// * IRA = Input Register A
// * IRB = Input Register B
// * DDRA = Data Direction Register A
// * DDRB = Data Direction Register B
var PIA_U561_CRA = 0x00;
var PIA_U561_CRB = 0x00;
var PIA_U561_ORA = 0x00;
var PIA_U561_ORB = 0x00;
var PIA_U561_IRA = 0x00;
var PIA_U561_IRB = 0x00;
var PIA_U561_DDRA = 0x00;
var PIA_U561_DDRB = 0x00;
var PIA_U565_CRA = 0x00;
var PIA_U565_CRB = 0x00;
var PIA_U565_ORA = 0x00;
var PIA_U565_ORB = 0x00;
var PIA_U565_IRA = 0x00;
var PIA_U565_IRB = 0x00;
var PIA_U565_DDRA = 0x00;
var PIA_U565_DDRB = 0x00;
var PIA_U361_CRA = 0x00;
var PIA_U361_CRB = 0x00;
var PIA_U361_ORA = 0x00;
var PIA_U361_ORB = 0x00;
var PIA_U361_IRA = 0x00;
var PIA_U361_IRB = 0x00;
var PIA_U361_DDRA = 0x00;
var PIA_U361_DDRB = 0x00;
var PIA_U461_CRA = 0x00;
var PIA_U461_CRB = 0x00;
var PIA_U461_ORA = 0x00;
var PIA_U461_ORB = 0x00;
var PIA_U461_IRA = 0x00;
var PIA_U461_IRB = 0x00;
var PIA_U461_DDRA = 0x00;
var PIA_U461_DDRB = 0x00;
var PIA_U265_CRA = 0x00;
var PIA_U265_CRB = 0x00;
var PIA_U265_ORA = 0x00;
var PIA_U265_ORB = 0x00;
var PIA_U265_IRA = 0x00;
var PIA_U265_IRB = 0x00;
var PIA_U265_DDRA = 0x00;
var PIA_U265_DDRB = 0x00;
var GPIB_DATA_IN = 0x00; // Data from GPIB to 4051.
var GPIB_DATA_OUT = 0x00; // Data from 4051 to GPIB.
var GPIB_TALK = 0; // 4051 is talking on the GPIB.
var GPIB_LISTEN = 0; // 4051 is listening to the GPIB.
var GPIB_EOI_OUT = 0; // End Or Identify. [TALKER].
var GPIB_IFC_OUT = 0; // Interface Clear. [CONTROLLER].
var GPIB_ATN_OUT = 0; // Attention. [CONTROLLER].
var GPIB_NRFD_OUT = 0; // Not Ready For Data. [LISTENERS].
var GPIB_DAV_OUT = 0; // Data Valid. [TALKER].
var GPIB_NDAC_OUT = 0; // Not Data Accepted. [LISTENER].
var GPIB_EOI_IN = 0; // End Or Identify. [TALKER].
var GPIB_NRFD_IN = 0; // Not Ready For Data. [LISTENERS].
var GPIB_SRQ_IN = 0; // Service Request. [CONTROLLER].
var GPIB_DAV_IN = 0; // Data Valid. [TALKER].
var GPIB_NDAC_IN = 1; // Not Data Accepted. [LISTENER].
var GPIB_REN_OUT = 0; // Remote Enable. [CONTROLLER].
this.exesbytes = []; // An empty array initially.
this.sbyteslength = 0; // Initially no bytes stored in the empty array!
this.sbytesindex = -1; // Initially no program has been stored.
var GPIB_STATE = 0; // No file loaded.
var GPIB_RDTIME_STATE = 0;
var GPIB_RDTIME = "";
var GPIB_RDTIME_INDEX = 0;
var LAST_CMD = 0;
var ADDR_PRIMARY = 0;
var ADDR_SECONDARY = 0;
var ADDR_TAPE = 5; // Web storage "tape drive" address
var current_fnumstr = 0;
var bin_data_length = 0;
var bin_byte_cnt = 0;
var bin_data_type = 0;
this.KBD_TTY_0 = 1;
this.KBD_SHIFT_0 = 1;
this.KBD_CTRL_0 = 1;
// 0-disable; 1-enable
var BANK_SWITCH_SELECTOR = 0;
var BSX_ADDRESS = 0;
var beep = new Audio( "beep.mp3" );
var click = new Audio( "click.mp3" );
this.audioOn = true;
// Random number generator mod
var RND_KC_BODGE0 = 0;
var RND_KC_BODGE1 = 0;
// Random number generator mod
// ***************
// *** ***
// *** print ***
// *** ***
// ***************
this.print = function( str ) {
console.print(str);
} // End of function print.
// *****************
// *** ***
// *** println ***
// *** ***
// *****************
this.println = function( str ) {
this.logbuf.textContent += str + "\n";
} // End of function println.
// ******************
// *** ***
// *** printHex ***
// *** ***
// ******************
this.printHex1 = function( n ) {
var nn = n & 0x000F; // Isolate the least significant 4 bits.
switch( nn ) {
case 0x0 : return '0';
case 0x1 : return '1';
case 0x2 : return '2';
case 0x3 : return '3';
case 0x4 : return '4';
case 0x5 : return '5';
case 0x6 : return '6';
case 0x7 : return '7';
case 0x8 : return '8';
case 0x9 : return '9';
case 0xA : return 'A';
case 0xB : return 'B';
case 0xC : return 'C';
case 0xD : return 'D';
case 0xE : return 'E';
case 0xF : return 'F';
default : break;
} // End switch nn.
} // End of function printHex1.
this.printHex2 = function( n ) {
byte = "";
byte += this.printHex1( n >>> 4 ); // Hi nibble.
byte += this.printHex1( n ); // Lo nibble.
return byte;
} // End of function printHex2.
this.printHex4 = function( n ) {
word = "";
word += this.printHex2( n >>> 8 ); // Hi word.
word += this.printHex2( n ); // Lo word.
return word;
} // End of function printHex4.
this.programLoaded = function() {
GPIB_STATE = 3; // File loaded and seen the correct primary and secondary GPIB addresses.
if( this.sbyteslength > 0 )
this.sbytesindex = 0; // Start at the beginning of the desired 'program' to be loaded.
}
/*
function GPIBlog(tekobj) {
var flagstr = "";
var gpibstr = "";
// GPIB signals
GPIB_IFC_OUT ? flagstr += "IF " : flagstr += "-- ";
GPIB_REN_OUT ? flagstr += "RN " : flagstr += "-- ";
GPIB_ATN_OUT ? flagstr += "AT " : flagstr += "-- ";
GPIB_SRQ_IN ? flagstr += "SQ " : flagstr += "-- ";
(GPIB_EOI_OUT || GPIB_EOI_IN) ? flagstr += "EI " : flagstr += "-- ";
(GPIB_DAV_OUT || GPIB_DAV_IN) ? flagstr += "DA " : flagstr += "-- ";
(GPIB_NRFD_OUT || GPIB_NRFD_IN) ? flagstr += "NR " : flagstr += "-- ";
(GPIB_NDAC_OUT || GPIB_NDAC_IN) ? flagstr += "ND " : flagstr += " ";
// GPIB comands
if (GPIB_ATN_OUT) {
if ((GPIB_DATA_OUT > 0x20) && (GPIB_DATA_OUT < 0x40)) {
gpibstr = tekobj.printHex2(GPIB_DATA_OUT) + " MLA";
}
if ((GPIB_DATA_OUT > 0x40) && (GPIB_DATA_OUT < 0x60)) {
gpibstr = tekobj.printHex2(GPIB_DATA_OUT) + " MTA";
}else if ((GPIB_DATA_OUT > 0x5F) && (GPIB_DATA_OUT < 0x80)) {
gpibstr = tekobj.printHex2(GPIB_DATA_OUT) + " MSA";
}
}else{
if (GPIB_LISTEN && GPIB_DAV_IN) {
gpibstr = tekobj.printHex2(GPIB_DATA_IN) + " data in";
}
if (GPIB_TALK && GPIB_DAV_OUT) {
gpibstr = tekobj.printHex2(GPIB_DATA_OUT) + " data out";
}
}
console.log(flagstr + gpibstr);
}
*/
// **********************
// *** ***
// *** PROCESS_GPIB ***
// *** ***
// **********************
this.PROCESS_GPIB = function() {
// GPIBlog(this);
/*
console.log( 'PROCESS_GPIB:' );
if( GPIB_TALK ) console.log( ' TALK -' );
if( GPIB_LISTEN ) console.log( ' LISTEN -' );
console.log( ' IFC=' ); this.printHex1( GPIB_IFC_OUT );
console.log( ' REN=' ); this.printHex1( GPIB_REN_OUT );
console.log( ' ATN=' ); this.printHex1( GPIB_ATN_OUT );
console.log( ' SRQ=' ); this.printHex1( GPIB_SRQ_IN );
if( GPIB_TALK ) {
console.log( ' DATA=0x' ); this.printHex2( GPIB_DATA_OUT );
console.log( ' EOI=' ); this.printHex1( GPIB_EOI_OUT );
console.log( ' DAV=' ); this.printHex1( GPIB_DAV_OUT );
console.log( ' NRFD=' ); this.printHex1( GPIB_NRFD_IN );
console.log( ' NDAC=' ); this.printHex1( GPIB_NDAC_IN );
} // End if GPIB_TALK.
if( GPIB_LISTEN ) {
console.log( ' DATA=0x' ); this.printHex2( GPIB_DATA_IN );
console.log( ' EOI=' ); this.printHex1( GPIB_EOI_IN );
console.log( ' DAV=' ); this.printHex1( GPIB_DAV_IN );
console.log( ' NRFD=' ); this.printHex1( GPIB_NRFD_OUT );
console.log( ' NDAC=' ); this.printHex1( GPIB_NDAC_OUT );
} */ // End if GPIB_LISTEN.
// Process data from the 4051 to the GPIB.
if( GPIB_TALK ) {
if( (GPIB_DAV_OUT == 1) && (GPIB_NDAC_IN == 1) ) {
/*
if ( GPIB_EOI_OUT == 1 ) {
console.log( "EOI signalled! (" + this.printHex2(GPIB_DATA_OUT) + ")" );
}
*/
// Some GPIB command data for me to process.
if( GPIB_ATN_OUT == 1 ) {
// Its a PRIMARY listen (MLA) or talk (MTA) address
if ( (GPIB_DATA_OUT > 0x20) && (GPIB_DATA_OUT < 0x60) ) {
ADDR_PRIMARY = GPIB_DATA_OUT;
// Look for the GPIB Primary Address (device #1 - emulator).
if( GPIB_DATA_OUT == 0x41 ) { // 0x41 == 65 == GPIB Device #1 Primary Talk Address.
// State '1' means that the file has been loaded and is awaiting the correct GPIB Primary Address.
//
if( GPIB_STATE == 1 ) {
GPIB_STATE = 2; // File has been loaded and I have now seen the correct GPIB Primary Address.
// State '0' means that a file has not been loaded - so I should just ignore the GPIB Primary Address.
//
} else if( GPIB_STATE == 0 ) {
// Ignore as no file is loaded.
// I have seen a correct GPIB Primary Address - but potentially out of context!
//
} else if( GPIB_STATE >= 2 ) {
GPIB_STATE = 1; // Go back to the 'file loaded' state as obviously something has gone wrong with the protocol.
} // End if.
} // End if correct GPIB Primary Address.
// Enable clock response on address 2
/*
if( GPIB_DATA_OUT == 0x42 ) {
//
GPIB_RDTIME_STATE = 1;
//
}
*/
if ( GPIB_DATA_OUT == 0x5F ) { // 0x5F == 95 == UNTALK.
if( GPIB_STATE == 0 ) {
// Ignore as no file loaded.
} else {
GPIB_STATE = 1; // Force to 'waiting for the correct GPIB Primary Address'.
GPIB_RDTIME_STATE = 0;
} // End if.
ADDR_PRIMARY = 0;
ADDR_SECONDARY = 0;
} // End if looking for GPIB 'UNTALK' command.
// Its a SECONDARY address command
}else if ( (GPIB_DATA_OUT > 0x5F) && (GPIB_DATA_OUT < 0x80) ) { // Secondary address
ADDR_SECONDARY = GPIB_DATA_OUT;
// console.log("Primary address: " + this.printHex2(ADDR_PRIMARY));
// console.log("Secondary address: " + this.printHex2(ADDR_SECONDARY));
if (ADDR_PRIMARY && ADDR_SECONDARY) {
// SAVE command (storage)
if ( ADDR_SECONDARY == 0x61 ) {
if (ADDR_PRIMARY == (ADDR_TAPE + 0x20)) {
// console.log("Saving to file: " + current_fnumstr);
storage.saveToTapeReady();
} // End ADDR_PRIMARY
} // End of SAVE
// CLOSE command (storage)
if (ADDR_SECONDARY == 0x62) {
if (ADDR_PRIMARY == (ADDR_TAPE + 0x20)) {
// console.log("Closing current file...");
storage.closeFile();
// console.log("Done.");
} // End ADDR_PRIMARY
} // End of CLOSE
// OLD/APPEND command (storage)
if ( ADDR_SECONDARY == 0x64 ) {
// console.log("Primary address = " + this.printHex2(ADDR_PRIMARY));
// console.log("OLD/APPEND command.");
if ( ADDR_PRIMARY == 0x41 ) { // GPIB primary address = MTA1
// console.log("Reset index on loaded file.");
this.programLoaded();
} // End ADDR_PRIMARY == 0x01
if ( ADDR_PRIMARY == (ADDR_TAPE + 0x40) ) {
if (current_fnumstr) {
// console.log("Reading ASCII file: " + current_fnumstr);
storage.readFromTape(current_fnumstr, 'A');
if (current_fnumstr != '0') this.programLoaded();
}
} // End ADDR_PRIMARY
} // End of OLD/APPEND
// BSAVE comand (save binary program)
if ( ADDR_SECONDARY == 0x71 ) {
if (ADDR_PRIMARY == (ADDR_TAPE + 0x20)) {
storage.saveToTapeReady();
} // End ADDR_PRIMARY
} // End BSAVE command
} // ADDR_PRIMARY && ADDR_SECONDARY
//console.log( 'PROCESS_GPIB: COMMAND=0x' ); this.printHex2( GPIB_DATA_OUT ); this.println('');
if( GPIB_DATA_OUT == 0x6D ) {
//
if ( ADDR_PRIMARY == 0x42 ) {
// if( GPIB_RDTIME_STATE == 1 ) {
//
var d = new Date();
//
var m = [ "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ];
//
GPIB_RDTIME = "";
//
var i;
//
i = d.getDate(); if( i < 10) GPIB_RDTIME += "0"; GPIB_RDTIME += ("" + i);
GPIB_RDTIME += "-";
GPIB_RDTIME += m[ d.getMonth() ];
GPIB_RDTIME += "-";
i = d.getFullYear() % 100; if( i < 10) GPIB_RDTIME += "0"; GPIB_RDTIME += ("" + i);
GPIB_RDTIME += " ";
i = d.getHours(); if( i < 10) GPIB_RDTIME += "0"; GPIB_RDTIME += ("" + i);
GPIB_RDTIME += ":";
i = d.getMinutes(); if( i < 10) GPIB_RDTIME += "0"; GPIB_RDTIME += ("" + i);
GPIB_RDTIME += ":";
i = d.getSeconds(); if( i < 10) GPIB_RDTIME += "0"; GPIB_RDTIME += ("" + i);
//
GPIB_RDTIME_INDEX = 0; // First character of the DATE/TIME string.
//
//console.log( 'PROCESS_GPIB: RDTIME = ' + GPIB_RDTIME );
//
GPIB_RDTIME_STATE = 2;
//
} // End if GPIB_RDTIME_STATE
//
} // End if GPIB_DATA_OUT == 0x6D
} // End decoding GPIB byte during ATN
} // End GPIB_ATN_OUT = 1
// Send some parameter or data
if( GPIB_ATN_OUT == 0 ) {
//console.log("Primary address: " + this.printHex2(ADDR_PRIMARY));
//console.log("Secondary address: " + this.printHex2(ADDR_SECONDARY));
//console.log("GPIB data out: " + this.printHex2(GPIB_DATA_OUT));
if ( ADDR_PRIMARY && ADDR_SECONDARY) {
// console.log("Primary and secondary address set.");
// SAVE command (storage)
if ( (ADDR_PRIMARY == (ADDR_TAPE + 0x20)) && (ADDR_SECONDARY == 0x61) ) {
if (current_fnumstr) {
storage.saveToTapeBin(GPIB_DATA_OUT);
if (GPIB_EOI_OUT) storage.saveToTapeDone(current_fnumstr, 'A');
}
}
// PRINT command (storage)
if ( (ADDR_PRIMARY == (ADDR_TAPE + 0x20)) && (ADDR_SECONDARY == 0x6C) ) {
storage.printToFile(GPIB_DATA_OUT);
if (GPIB_DATA_OUT == '0x0D') storage.writeToFileDone();
}
// WRITE command (storage)
if ( (ADDR_PRIMARY == (ADDR_TAPE + 0x20)) && (ADDR_SECONDARY == 0x6F) ) {
//console.log(this.printHex2(GPIB_DATA_OUT));
//console.log("Writing...");
storage.writeToFile(GPIB_DATA_OUT);
if (bin_byte_cnt == 0) {
bin_data_type = ((GPIB_DATA_OUT&0xE0)>>5) + 2;
bin_data_length = (GPIB_DATA_OUT&0x1F)*256;
}
//console.log("Data len1: " + bin_data_length);
if (bin_byte_cnt == 1) {
bin_data_length = bin_data_length + GPIB_DATA_OUT;
if (bin_data_type == 4) bin_data_length++; // Text data has one extra byte?
}
//console.log("Data len2: " + bin_data_length);
bin_byte_cnt++;
if (bin_byte_cnt == bin_data_length+2) {
bin_byte_cnt = 0;
bin_data_length = 0;
bin_data_type = 0;
storage.writeToFileDone();
//console.log("Write complete.");
}
}
// BSAVE command (storage)
if ( ADDR_SECONDARY == 0x71 ) {
if ( ADDR_PRIMARY == (ADDR_TAPE + 0x20) ) {
if (current_fnumstr) {
storage.saveToTapeBin(GPIB_DATA_OUT);
if (GPIB_EOI_OUT) storage.saveToTapeDone(current_fnumstr, 'B');
}
}
}
// DIR command (send file name)
if ( ADDR_SECONDARY == 0x73 ) {
storage.setDirEntry(GPIB_DATA_OUT);
}
// FIND command (storage)
if ( (ADDR_PRIMARY == (ADDR_TAPE + 0x20)) && (ADDR_SECONDARY == 0x7B) ) {
// Preceding space singals new file number
if (GPIB_DATA_OUT == 0x20) current_fnumstr = "";
// CR signals end of data
if (GPIB_DATA_OUT == 0x0D) {
storage.findFile(current_fnumstr);
// console.log("Set file number to: " + current_fnumstr);
}
// Add numeric digits to file number string
if (GPIB_DATA_OUT > 0x29 && GPIB_DATA_OUT < 0x3A) {
current_fnumstr += String.fromCharCode(GPIB_DATA_OUT);
// Clear file counters
bin_byte_cnt = 0;
bin_data_len = 0;
}
} // END of FIND command
} // END of ADDR_PRIMARY && ADDR_SECONDARY
} // End of GPIB_ATN_OUT = 0
} // End GPIB_DAV_OUT / GPIB_NDAC_IN (outbound data to process).
GPIB_NDAC_IN = GPIB_DAV_OUT ^ 0x01; // Invert before return.
} // End of GPIB_TALK.
if( GPIB_LISTEN ) {
if( GPIB_ATN_OUT == 0 ) {
if ( ADDR_PRIMARY && ADDR_SECONDARY) {
// PWD command (Emulator does not support direcories. This simply returns '/root'/)
if ( ADDR_SECONDARY == 0x69 ) {
if ( ADDR_PRIMARY == (ADDR_TAPE+0x40) ) {
GPIB_STATE = 9; // Signal we are ready to read the directory name
}
} // End of DIR command
// INPUT command (storage)
if ( (ADDR_SECONDARY == 0x6A ) || (ADDR_SECONDARY == 0x6D) ) {
if ( ADDR_PRIMARY == (ADDR_TAPE+0x40) ) {
GPIB_STATE = 5; // Signal we are ready to read ASCII data
}
} // End of INPUT command
// READ command (storage)
if ( ADDR_SECONDARY == 0x6E ) {
if ( ADDR_PRIMARY == (ADDR_TAPE+0x40) ) {
GPIB_STATE = 6; // Signal we are ready to read BINARY data
}
} // End of READ command
// BOLD command (storage)
if ( ADDR_SECONDARY == 0x71 ) {
if ( ADDR_PRIMARY == (ADDR_TAPE+0x40) ) {
GPIB_STATE = 7; // Signal we are ready to read BINARY PROGRAM
}
} // End of BOLD command
// TLIST command (storage)
if ( ADDR_SECONDARY == 0x73 ) {
if ( ADDR_PRIMARY == (ADDR_TAPE+0x40) ) {
GPIB_STATE = 8; // Signal we are ready to get the next directory entry
}
} // End of BOLD command
} // End of ADDR_PRIMARY && ADDR_SECONDARY
} // End of GPIB_ATN_OUT = 0
} // End of GPIB_LISTEN.
// GPIB_NDAC_IN = GPIB_DAV_OUT ^ 0x01; // Invert before return.
} // End of function PROCESS_GPIB.
// *******************
// *** ***
// *** POLL_GPIB ***
// *** ***
// *******************
this.POLL_GPIB = function() {
if( GPIB_LISTEN ) {
// Read a program into emulator memory
if( (GPIB_NDAC_OUT == 0) && (GPIB_NRFD_OUT == 1) && (GPIB_DAV_IN == 0) && (GPIB_STATE == 3) ) {
// Are there any (more) characters to send?
if( (this.sbytesindex >= 0) && (this.sbytesindex < this.sbyteslength) ) {
// Send a new data byte to the 4015.
//
GPIB_DATA_IN = this.sbytes[ this.sbytesindex ];
//console.log(" *** GPIB_DATA_IN " + GPIB_DATA_IN);
//console.log(" ** index = " + this.sbytesindex);
// Is this the 'last' character?
//
if( this.sbytesindex == (this.sbyteslength - 1) ) GPIB_EOI_IN = 1;
else GPIB_EOI_IN = 0;
// Bump the index.
//
this.sbytesindex++;
//if( GPIB_EOI_IN == 1 ) { this.print('POLL_GPIB: EOI set with DATA=0x'); this.printHex2( GPIB_DATA_IN ); //this.println(''); }
GPIB_DAV_IN = 1; // Signify that you have new data.
//console.log( 'GPIB: >>>>>>>>>>>>>>>>>>>>>>>>>> Send new data to the 4051 and set the DAV flag...' );
//console.log( 'GPIB: >>>>>>>>>>>>>>>>>>>>>>>>>> Data was 0x' ); this.printHex2( GPIB_DATA_IN ); this.println( '.' );
if( GPIB_EOI_IN == 1 ) {
//console.log( 'GPIB: >>>>>>>>>>>>>>>>>>>>>>>>>> Setting EOI flag...' );
// Check to see if PIA U265 CRA CA1 input is set for an active high-going edge interrupt.
//
if( ( (PIA_U265_CRA >>> 0) & 0x03 ) == 0x03 ) {
// YES
//console.log( 'GPIB: >>>>>>>>>>>>>>>>>>>>>>>>>> Setting PIA U265 IRQA1...' );
//Set IRQA1 interrupt bit in PIA U265 CRA.
// PIA_U265_CRA |= 0x80; @@@ Disable for now...
} // End if is the PIA permitted to generate an interrupt.
} // End if should we set the EOI flag.
} // End if any more character to send of the program.
// Read in date and time
} else if( (GPIB_NDAC_OUT == 0) && (GPIB_NRFD_OUT == 1) && (GPIB_DAV_IN == 0) && (GPIB_RDTIME_STATE == 2) ) {
// Send a data byte to the 4051.
//
GPIB_DATA_IN = GPIB_RDTIME.charCodeAt( GPIB_RDTIME_INDEX ) & 0x7F;
// Is this the 'last' character?
//
if( GPIB_RDTIME_INDEX == (GPIB_RDTIME.length - 1) ) GPIB_EOI_IN = 1;
else GPIB_EOI_IN = 0;
// Bump the index.
//
GPIB_RDTIME_INDEX++;
//console.log('POLL_GPIB: RDTIME DATA=0x'); this.printHex2( GPIB_DATA_IN ); this.println('');
//@@@ if( GPIB_EOI_IN == 1 ) { this.print('POLL_GPIB: RDTIME_EOI set with DATA=0x'); this.printHex2( GPIB_DATA_IN ); this.println(''); }
if( GPIB_EOI_IN == 1 ) GPIB_RDTIME_STATE = 0;
GPIB_DAV_IN = 1; // Signify that you have new data.
// Read ASCII data from storage (INPUT)
} else if( (GPIB_NDAC_OUT == 0) && (GPIB_NRFD_OUT == 1) && (GPIB_DAV_IN == 0) && (GPIB_STATE == 5) ) {
//console.log("INPUT sec address: " + this.printHex2(ADDR_SECONDARY));
if (ADDR_SECONDARY == 0x6A) {
var value = storage.copyFromFile();
GPIB_DATA_IN = value & 0xFF;
GPIB_EOI_IN = (value & 0x0100) >> 8;
//console.log("Data: " + this.printHex2(GPIB_DATA_IN));
//console.log("Receive EOI: " + this.printHex2(GPIB_EOI_IN));
// Is this the 'last' character?
if (GPIB_DATA_IN == 0x80) {
GPIB_EOI_IN = 1;
}else{
GPIB_EOI_IN = 0;
}
}
if (ADDR_SECONDARY == 0x6D) {
GPIB_DATA_IN = storage.inputFromFile();
// Is this the 'last' character?
if (GPIB_DATA_IN == 0x0D) {
GPIB_EOI_IN = 1;
}else{
GPIB_EOI_IN = 0;
}
}
if( GPIB_EOI_IN == 1 ) GPIB_STATE = 0;
GPIB_DAV_IN = 1; // Signify that you have new data.
// Read BINARY data from storage (READ)
} else if( (GPIB_NDAC_OUT == 0) && (GPIB_NRFD_OUT == 1) && (GPIB_DAV_IN == 0) && (GPIB_STATE == 6) ) {
// Read a data byte from the 4051.
GPIB_DATA_IN = storage.readFromFile();
//console.log(this.printHex2(GPIB_DATA_IN));
if (bin_byte_cnt == 0) {
bin_data_type = ((GPIB_DATA_IN&0xE0)>>5)+2;
bin_data_length = (GPIB_DATA_IN&0x1F)*256;
}
//console.log("Data len1: " + bin_data_length);
if (bin_byte_cnt == 1) {
bin_data_length = bin_data_length + GPIB_DATA_IN;
if (bin_data_type == 4) bin_data_length++; // Text data has one extra byte?
//console.log("Data len2: " + bin_data_length);
}
bin_byte_cnt++;
if (bin_byte_cnt == bin_data_length+2) {
bin_byte_cnt = 0;
bin_data_length = 0;
bin_data_type = 0;
GPIB_EOI_IN = 1;
//console.log("Write complete.");
}else{
GPIB_EOI_IN = 0;
}
if( GPIB_EOI_IN == 1 ) GPIB_STATE = 0;
GPIB_DAV_IN = 1; // Signify that you have new data.
// Read BINARY PROGRAM from storage
} else if( (GPIB_NDAC_OUT == 0) && (GPIB_NRFD_OUT == 1) && (GPIB_DAV_IN == 0) && (GPIB_STATE == 7) ) {
// Send a data byte to the 4051.
//
var value = storage.readBinProg() & 0xFF;
if (value == -1) {
GPIB_EOI_IN = 1; // Error - signal EOI to terminate
}else{
GPIB_DATA_IN = value & 0xFF;
GPIB_EOI_IN = value & 0x0100; // Is EOI bit set ?
//console.log(this.printHex2(GPIB_DATA_IN));
}
if( GPIB_EOI_IN == 1 ) GPIB_STATE = 3;
// Possibly GPIB_STATE = 3 - program loaded
GPIB_DAV_IN = 1; // Signify that you have new data.
// Read directory entry (TLIST) from storage (via INPUT @5,19)
} else if( (GPIB_NDAC_OUT == 0) && (GPIB_NRFD_OUT == 1) && (GPIB_DAV_IN == 0) && (GPIB_STATE == 8) ) {
if (ADDR_SECONDARY == 0x73) {
GPIB_DATA_IN = storage.getDirEntry();
//console.log(this.printHex2(GPIB_DATA_IN));
// Is this the 'last' character?
if (GPIB_DATA_IN == 0x0D) {
GPIB_EOI_IN = 1;
}else{
GPIB_EOI_IN = 0;
}
}
if( GPIB_EOI_IN == 1 ) GPIB_STATE = 0;
GPIB_DAV_IN = 1; // Signify that you have new data.
// Read the directory name from storage (via INPUT @5,9)
} else if( (GPIB_NDAC_OUT == 0) && (GPIB_NRFD_OUT == 1) && (GPIB_DAV_IN == 0) && (GPIB_STATE == 9) ) {
if (ADDR_SECONDARY == 0x69) {
GPIB_DATA_IN = storage.getDirectory();
//console.log(this.printHex2(GPIB_DATA_IN));
// Is this the 'last' character?
if (GPIB_DATA_IN == 0x0D) {
GPIB_EOI_IN = 1;
}else{
GPIB_EOI_IN = 0;
}
}
if( GPIB_EOI_IN == 1 ) GPIB_STATE = 0;
GPIB_DAV_IN = 1; // Signify that you have new data.
} else if( (GPIB_NDAC_OUT == 1) && (GPIB_DAV_IN == 1) ) {
GPIB_DAV_IN = 0; // Clear the data available flag.
GPIB_EOI_IN = 0; // Clear the EOI flag. WARNING: This needs to be here to permit a <BREAK> to occur when commanded by the human!
//console.log( 'GPIB: >>>>>>>>>>>>>>>>>>>>>>>>>> Cleared the EOI and DAV flag...' );
} else {
// TODO:
} // End if.
} // End if GPIB_LISTEN.
} // End of function POLL_GPIB.
// ***************
// *** ***
// *** PEEKB ***
// *** ***
// ***************
this.peekb = function( address ) {
// Is this a read from an I/O device?
if( (address >= 0x8780) && (address <= 0x87FF) ) {
// YES
switch( address ) {
// **************
// *** U561 ***
// **************
case 0x878C : if( PIA_U561_CRA & 0x04 ) {
PIA_U561_CRA &= 0x3F; // Clear both interrupt bits.
display.SCREEN( 'SOT' );
return (PIA_U561_IRA & (PIA_U561_DDRA ^ 0xFF)) | (PIA_U561_ORA & PIA_U561_DDRA);
} else
return PIA_U561_DDRA;
break;
case 0x878D : return PIA_U561_CRA;
break;
case 0x878E : if( PIA_U561_CRB & 0x04 ) {
PIA_U561_CRB &= 0x3F; // Clear both interrupt bits.
return (PIA_U561_IRB & (PIA_U561_DDRB ^ 0xFF)) | (PIA_U561_ORB & PIA_U561_DDRB);
} else
return PIA_U561_DDRB;
break;
case 0x878F : return PIA_U561_CRB;
break;
// **************
// *** U565 ***
// **************
case 0x8794 : if( PIA_U565_CRA & 0x04 ) {
PIA_U565_CRA &= 0x3F; // Clear both interrupt bits.
// 0x8794 must be XXXX01XX VPULSE-1 = '0', DRBUSY-0 = '1'.
display.SCREEN( 'ADOT' );
return (PIA_U565_IRA & (PIA_U565_DDRA ^ 0xFF)) | (PIA_U565_ORA & PIA_U565_DDRA);
} else
return PIA_U565_DDRA;
break;
case 0x8795 : return PIA_U565_CRA;
break;
case 0x8796 : if( PIA_U565_CRB & 0x04 ) {
PIA_U565_CRB &= 0x3F; // Clear both interrupt bits.
return (PIA_U565_IRB & (PIA_U565_DDRB ^ 0xFF)) | (PIA_U565_ORB & PIA_U565_DDRB);
} else
return PIA_U565_DDRB;
break;
case 0x8797 : return PIA_U565_CRB;
break;
// **************
// *** U361 ***
// **************
case 0x8798 : if( PIA_U361_CRA & 0x04 ) {
PIA_U361_CRA &= 0x3F; // Clear both interrupt bits.
return (PIA_U361_IRA & (PIA_U361_DDRA ^ 0xFF)) | (PIA_U361_ORA & PIA_U361_DDRA);
} else
return PIA_U361_DDRA;
break;
case 0x8799 : return PIA_U361_CRA;
break;
case 0x879A : if( PIA_U361_CRB & 0x04 ) {
PIA_U361_CRB &= 0x3F; // Clear both interrupt bits.
return (PIA_U361_IRB & (PIA_U361_DDRB ^ 0xFF)) | (PIA_U361_ORB & PIA_U361_DDRB);
} else
return PIA_U361_DDRB;
break;
case 0x879B : return PIA_U361_CRB;
break;
// **************
// *** U461 ***
// **************
/***** Random number generator mod
case 0x87A8 : if( PIA_U461_CRA & 0x04 ) {
PIA_U461_CRA &= 0x3F; // Clear both interrupt bits.
// this.print('Reading U461 DRA value='); this.printHex2( (PIA_U461_IRA & (PIA_U461_DDRA ^ 0xFF)) | (PIA_U461_ORA & PIA_U461_DDRA) ); this.println('');
// PIA_U461_IRA &= 0x7F; // TTY-0 = 0
return (PIA_U461_IRA & (PIA_U461_DDRA ^ 0xFF)) | (PIA_U461_ORA & PIA_U461_DDRA);
} else
return PIA_U461_DDRA;
break;
*/
// Random number generator mod
case 0x87A8 : if( PIA_U461_CRA & 0x04 ) {
PIA_U461_CRA &= 0x3F; // Clear both interrupt bits.
if( cpu.getLastPC() == 0x9716 ) {
if( RND_KC_BODGE1 > 0 ) {
RND_KC_BODGE1 = (RND_KC_BODGE1 - 1) & 0x3F; // Decrement if a count in progress.
} else {
RND_KC_BODGE1 = RND_KC_BODGE0; // Take a snapshot.
} // End if.