ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/vt102/vt102
(Generate patch)

Comparing vt102/vt102 (file contents):
Revision 1.13 by root, Wed Dec 3 02:13:26 2014 UTC vs.
Revision 1.21 by root, Wed Dec 3 08:57:58 2014 UTC

21#use common::sense; 21#use common::sense;
22 22
23my $VT102 = 1; 23my $VT102 = 1;
24my $VT131 = 0; 24my $VT131 = 0;
25my $AVO = 1; 25my $AVO = 1;
26my $KBD = 1;
27 26
28shift, ($VT102 = 0), ($AVO = 0) if $ARGV[0] =~ /^-?-vt100$/; 27shift, ($VT102 = 0), ($AVO = 0) if $ARGV[0] =~ /^-?-vt100$/;
29shift, ($VT102 = 0) if $ARGV[0] =~ /^-?-vt100\+avo$/; 28shift, ($VT102 = 0) if $ARGV[0] =~ /^-?-vt100\+avo$/;
30shift if $ARGV[0] =~ /^-?-vt102$/; 29shift if $ARGV[0] =~ /^-?-vt102$/;
31shift, ($VT131 = 1) if $ARGV[0] =~ /^-?-vt131$/; 30shift, ($VT131 = 1) if $ARGV[0] =~ /^-?-vt131$/;
32 31
32# vt100 wps = word processing roms
33# vt101 = vt102 - avo, but custom rom? really?
34# vt103 = vt100 + tu58 tape drive
35# vt125 = vt100 + gpo graphics processor
36# vt132 = vt100 + avo, stp
37# vt180 = vt100 + z80 cp/m
38
33if ($ARGV[0] =~ /^-/) { 39if ($ARGV[0] =~ /^-/) {
34 die <<EOF; 40 die <<EOF;
35 41
36VT102, A VT100/101/102/131 SIMULATOR 42VT102, A VT100/102/131 SIMULATOR
37 43
38Usage: 44Usage:
39 45
40 $0 [option] [program [args]] 46 $0 [option] [program [args]]
41 47
73} 79}
74 80
75############################################################################# 81#############################################################################
76# ROM/hardware init 82# ROM/hardware init
77 83
84my $PTY; # the pty we allocated, if any
85my $KBD = 1;
86
78my $ROMS = do { 87my $ROMS = do {
79 binmode DATA; 88 binmode DATA;
80 local $/; 89 local $/;
81 <DATA> 90 <DATA>
82}; 91};
83 92
840x6801 == length $ROMS or die "corrupted rom image"; 930x6801 == length $ROMS or die "corrupted rom image";
85
86binmode STDOUT;
87 94
88my @M = (0xff) x 65536; # main memory, = (0xff) x 65536; 95my @M = (0xff) x 65536; # main memory, = (0xff) x 65536;
89 96
90# populate mem with rom contents 97# populate mem with rom contents
91if ($VT102) { 98if ($VT102) {
97} 104}
98 105
99############################################################################# 106#############################################################################
100# 8085 CPU registers and I/O support 107# 8085 CPU registers and I/O support
101 108
102my $PTY; # the pty we allocated, if any
103
104# 8080/8085 registers 109# 8080/8085 registers
105# b, c, d, e, h, l, a
106my ($A, $B, $C, $D, $E, $H, $L, $A); 110my ($A, $B, $C, $D, $E, $H, $L);
107my ($PC, $SP, $IFF, $FA, $FZ, $FS, $FP, $FC); 111my ($PC, $SP, $IFF, $FA, $FZ, $FS, $FP, $FC);
108 112
109my $RST = 0; # 8080 pending interrupts 113my $RST = 0; # 8080 pending interrupts
110my $INTMASK = 7; # 8085 half interrupts 114my $INTMASK = 7; # 8085 half interrupts
111my $INTPEND = 0; # 8085 half interrupts 115my $INTPEND = 0; # 8085 half interrupts
112
113my $x; # dummy temp for instructions
114 116
115my $CLK; # rather inexact clock 117my $CLK; # rather inexact clock
116 118
117############################################################################# 119#############################################################################
118# the dreaded NVR1400 chip. not needed to get it going, but provided anyway 120# the dreaded NVR1400 chip. not needed to get it going, but provided anyway
132 sub { $NVR[$_[0]] = 0x3fff; }, # 5 erase 134 sub { $NVR[$_[0]] = 0x3fff; }, # 5 erase
133 sub { $NVRDATA = $NVR[$_[0]]; }, # 6 read 135 sub { $NVRDATA = $NVR[$_[0]]; }, # 6 read
134 sub { }, # 7 standby 136 sub { }, # 7 standby
135); 137);
136 138
137my @bitidx; 139my @NVR_BITIDX;
138$bitidx[1 << $_] = 9 - $_ for 0..9; 140$NVR_BITIDX[1 << $_] = 9 - $_ for 0..9;
139 141
140# the nvr1400 state machine. what a monster 142# the nvr1400 state machine. what a monster
141sub nvr() { 143sub nvr() {
142 my $a1 = $bitidx[(~$NVRADDR ) & 0x3ff]; 144 my $a1 = $NVR_BITIDX[(~$NVRADDR ) & 0x3ff];
143 my $a0 = $bitidx[(~$NVRADDR >> 10) & 0x3ff]; 145 my $a0 = $NVR_BITIDX[(~$NVRADDR >> 10) & 0x3ff];
144 146
145# printf "NVR %02x A %020b %d %d D %02x\n", $NVRLATCH, $NVRADDR & 0xfffff, $a1, $a0, $NVRDATA; 147# printf "NVR %02x A %020b %d %d D %02x\n", $NVRLATCH, $NVRADDR & 0xfffff, $a1, $a0, $NVRDATA;
146 148
147 $NVRCMD[($NVRLATCH >> 1) & 7]($a1 * 10 + $a0, $NVRLATCH & 1) 149 $NVRCMD[($NVRLATCH >> 1) & 7]($a1 * 10 + $a0, $NVRLATCH & 1)
148} 150}
295sub in_1b { 0xff } # vt102 unknown 297sub in_1b { 0xff } # vt102 unknown
296 298
297############################################################################# 299#############################################################################
298# 8085 cpu opcodes and flag handling 300# 8085 cpu opcodes and flag handling
299 301
302my $x; # dummy scratchpad for opcodes
303
300sub sf { # set flags (ZSC - AP not implemented) 304sub sf { # set flags (ZSC - AP not implemented)
301 $FS = $_[0] & 0x080; 305 $FS = $_[0] & 0x080;
302 $FZ = !($_[0] & 0x0ff); 306 $FZ = !($_[0] & 0x0ff);
303 $FC = $_[0] & 0x100; 307 $FC = $_[0] & 0x100;
304 308
402$op[0xb0 + $_] = 'sf8 $A |= ' . $reg[$_] for 0..7; # ora 406$op[0xb0 + $_] = 'sf8 $A |= ' . $reg[$_] for 0..7; # ora
403$op[0xb8 + $_] = 'sf $x = $A - ' . $reg[$_] for 0..7; # cmp 407$op[0xb8 + $_] = 'sf $x = $A - ' . $reg[$_] for 0..7; # cmp
404# possible todo: optimize ora a, maybe xra a 408# possible todo: optimize ora a, maybe xra a
405 409
406$op[0xc6] = 'sf $A += IMM8'; # adi 410$op[0xc6] = 'sf $A += IMM8'; # adi
407# ce ADI NYI 411# ce ACI NYI, apparently unused
408$op[0xd6] = 'sf $A -= IMM8'; # sui 412$op[0xd6] = 'sf $A -= IMM8'; # sui
409# de SBI NYI 413# de SBI NYI, apparently unused
410$op[0xe6] = 'sf8 $A &= IMM8'; # ani 414$op[0xe6] = 'sf8 $A &= IMM8'; # ani
411$op[0xee] = 'sf8 $A ^= IMM8'; # xri 415$op[0xee] = 'sf8 $A ^= IMM8'; # xri
412$op[0xf6] = 'sf8 $A |= IMM8'; # ori 416$op[0xf6] = 'sf8 $A |= IMM8'; # ori
413$op[0xfe] = 'sf $A - IMM8'; # cpi 417$op[0xfe] = 'sf $A - IMM8'; # cpi
414 418
432$op[0xc9] = 'JMP POP + POP * 256'; # ret 436$op[0xc9] = 'JMP POP + POP * 256'; # ret
433 437
434$op[0xc7 + $_ * 8] = "JMP $_ * 8" for 0..7; # rst 438$op[0xc7 + $_ * 8] = "JMP $_ * 8" for 0..7; # rst
435 439
436$op[0xe9] = 'JMP $H * 256 + $L'; # pchl 440$op[0xe9] = 'JMP $H * 256 + $L'; # pchl
437# f9 SPHL NYI 441# f9 SPHL NYI, apparently unused
438 442
439$op[0x37] = '$FC = 1 '; # stc 443$op[0x37] = '$FC = 1 '; # stc
440$op[0x3f] = '$FC = !$FC'; # cmc 444$op[0x3f] = '$FC = !$FC'; # cmc
441 445
442$op[0xd3] = 'OUT'; # out 446$op[0xd3] = 'OUT'; # out
443$op[0xdb] = 'IN'; # in 447$op[0xdb] = 'IN'; # in
444 448
445$op[0xeb] = '($D, $E, $H, $L) = ($H, $L, $D, $E)'; # xchg 449$op[0xeb] = '($D, $E, $H, $L) = ($H, $L, $D, $E)'; # xchg
446 450
447# e3 xthl NYI # @ 917b, hl <-> (sp) 451# e3 xthl NYI # @ 917b in e69, hl <-> (sp)
448 452
449$op[0x20] = '$A = $INTPEND * 16 + $INTMASK + ($IFF && 8)'; # rim (incomplete) 453$op[0x20] = '$A = $INTPEND * 16 + $INTMASK + ($IFF && 8)'; # rim (incomplete)
450$op[0x30] = '$INTMASK = $A & 7 if $A & 8'; # sim (incomplete) 454$op[0x30] = '$INTMASK = $A & 7 if $A & 8'; # sim (incomplete)
451 455
452$op[0xf3] = '$IFF = 0'; # DI 456$op[0xf3] = '$IFF = 0'; # DI
487 $M[$PC], $op[$M[$PC]]; 491 $M[$PC], $op[$M[$PC]];
488} 492}
489 493
490############################################################################# 494#############################################################################
491# video emulation 495# video emulation
496
497binmode STDOUT;
492 498
493my @CHARMAP = ( 499my @CHARMAP = (
494 " " , "\x{29eb}", "\x{2592}", "\x{2409}", 500 " " , "\x{29eb}", "\x{2592}", "\x{2409}",
495 "\x{240c}", "\x{240d}", "\x{240a}", "\x{00b0}", 501 "\x{240c}", "\x{240d}", "\x{240a}", "\x{00b0}",
496 "\x{00b1}", "\x{2424}", "\x{240b}", "\x{2518}", 502 "\x{00b1}", "\x{2424}", "\x{240b}", "\x{2518}",
684my $slave = $PTY->slave; 690my $slave = $PTY->slave;
685 691
686$PTY->set_winsize (24, 80); 692$PTY->set_winsize (24, 80);
687 693
688unless (fork) { 694unless (fork) {
695 $ENV{LC_ALL} = "C";
689 $ENV{TERM} = $VT102 ? "vt102" : "vt100"; 696 $ENV{TERM} = $VT102 ? "vt102" : "vt100";
690 697
691 close $PTY; 698 close $PTY;
692 699
693 open STDIN , "<&", $slave; 700 open STDIN , "<&", $slave;
707 714
708############################################################################# 715#############################################################################
709# the actual hardware simulator 716# the actual hardware simulator
710 717
711my @ICACHE; # compiled instruction cache 718my @ICACHE; # compiled instruction cache
719
720my $POWERSAVE; # powersave counter
721
722my $RIN; # libev for the less well-off
723
724(vec $RIN, 0, 1) = 1 if $KBD;
725(vec $RIN, fileno $PTY, 1) = 1 if $PTY;
712 726
713while () { 727while () {
714 # execute extended basic blocks 728 # execute extended basic blocks
715 $PC = ($ICACHE[$PC] ||= do { 729 $PC = ($ICACHE[$PC] ||= do {
716 my $pc = $PC; 730 my $pc = $PC;
747 eval "use integer; sub { $insn }" or die "$insn: $@" 761 eval "use integer; sub { $insn }" or die "$insn: $@"
748 })->(); 762 })->();
749 763
750 ++$CLK; 764 ++$CLK;
751 765
752 # things we do from time too time only 766 # things we do from time to time only
753 unless ($CLK & 0xf) { 767 unless ($CLK & 0xf) {
754 # do I/O 768 # do I/O
755 769
756 unless ($CLK & 0xfff) { 770 unless ($CLK & 0xfff) {
757 771 if (select $x = $RIN, undef, undef, $POWERSAVE < 100 ? 0 : 0.2) {
758 # pty/serial I/O 772 # pty/serial I/O
759 unless ((@PUSARTRECV >= 128) || @KQUEUE || !$PTY) { 773 if ($PTY && (vec $x, fileno $PTY, 1) && (@PUSARTRECV < 128) && !@KQUEUE) {
760 my $rin = ""; (vec $rin, fileno $PTY, 1) = 1; 774 my $rin = ""; (vec $rin, fileno $PTY, 1) = 1;
761 775
762 if (select $rin, undef, undef, 0) { 776 if (select $rin, undef, undef, 0) {
763 sysread $PTY, my $buf, 256; 777 sysread $PTY, my $buf, 256;
778
779 # linux don't do cs7 and/or parity anymore, so we need to filter
780 # out xoff characters to avoid freezes.
764 push @PUSARTRECV, unpack "C*", $buf; 781 push @PUSARTRECV, grep { ($_ & 0x7f) != 0x13 } unpack "C*", $buf;
782 }
765 } 783 }
766 }
767 784
768 # keyboard input 785 # keyboard input
769 if ($KBD) { 786 if ($KBD && (vec $x, 0, 1)) {
770 while (select my $rin = "\x01", undef, undef, 0) { 787 while (select my $rin = "\x01", undef, undef, 0) {
771 sysread STDIN, $STDIN_BUF, 1, length $STDIN_BUF 788 sysread STDIN, $STDIN_BUF, 1, length $STDIN_BUF
772 or last; 789 or last;
790 }
791
792 stdin_parse if length $STDIN_BUF;
793 $POWERSAVE = 0;
773 } 794 }
774 795
775 stdin_parse if length $STDIN_BUF; 796 $POWERSAVE = 0;
797 } else {
798 ++$POWERSAVE;
776 } 799 }
777 } 800 }
778 801
779 # kick off various interrupts 802 # kick off various interrupts
780 803
801 # 6.5 vt125 mb7 read ready (something modem?) 824 # 6.5 vt125 mb7 read ready (something modem?)
802 # 7.5 vt125 mb7 vblank h(?) 825 # 7.5 vt125 mb7 vblank h(?)
803 # trap vt125 mbi init h(?) 826 # trap vt125 mbi init h(?)
804 my $vec; 827 my $vec;
805 828
806 $x = $INTPEND & ~$INTMASK; 829 my $pend = $INTPEND & ~$INTMASK;
807 830
808 if ($x & 1) { $vec = 0x2c; $INTPEND &= ~1; 831 if ($pend & 1) { $vec = 0x2c; $INTPEND &= ~1;
809 } elsif ($x & 2) { $vec = 0x34; $INTPEND &= ~2; 832 } elsif ($pend & 2) { $vec = 0x34; $INTPEND &= ~2;
810 } elsif ($x & 4) { $vec = 0x3c; $INTPEND &= ~4; 833 } elsif ($pend & 4) { $vec = 0x3c; $INTPEND &= ~4;
811# } elsif ($RST ) { $vec = $RST * 8; $RST = 0; # the vt102 firmware doesn't like combined interrupts 834# } elsif ($RST ) { $vec = $RST * 8; $RST = 0; # the vt102 firmware doesn't like combined interrupts
812 } elsif ($RST & 1) { $vec = 0x08; $RST &= ~1; # separate is better for vt102 835 } elsif ($RST & 1) { $vec = 0x08; $RST &= ~1; # separate is better for vt102
813 } elsif ($RST & 2) { $vec = 0x10; $RST &= ~2; 836 } elsif ($RST & 2) { $vec = 0x10; $RST &= ~2;
814 } elsif ($RST & 4) { $vec = 0x20; $RST &= ~4; 837 } elsif ($RST & 4) { $vec = 0x20; $RST &= ~4;
815 } else { 838 } else {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines