1 |
root |
1.1 |
#!/opt/bin/perl |
2 |
|
|
|
3 |
root |
1.2 |
# |
4 |
|
|
# Copyright(C) 2014 Marc Alexander Lehmann <vt102@schmorp.de> |
5 |
|
|
# |
6 |
|
|
# vt102 is free software; you can redistribute it and/or modify it under |
7 |
|
|
# the terms of the GNU General Public License as published by the Free |
8 |
|
|
# Software Foundation; either version 3, or (at your option) any later |
9 |
|
|
# version. |
10 |
|
|
# |
11 |
|
|
# vt102 is distributed in the hope that it will be useful, but WITHOUT |
12 |
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 |
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
14 |
|
|
# for more details. |
15 |
|
|
# |
16 |
|
|
|
17 |
|
|
# If this file contains embedded ROMs, the above copyright notice does |
18 |
|
|
# not apply to them. |
19 |
|
|
|
20 |
root |
1.26 |
use 5.010; |
21 |
root |
1.9 |
use strict; |
22 |
root |
1.26 |
use integer; |
23 |
root |
1.9 |
#use common::sense; |
24 |
root |
1.1 |
|
25 |
root |
1.3 |
my $VT102 = 1; |
26 |
root |
1.10 |
my $VT131 = 0; |
27 |
|
|
my $AVO = 1; |
28 |
root |
1.1 |
|
29 |
root |
1.13 |
shift, ($VT102 = 0), ($AVO = 0) if $ARGV[0] =~ /^-?-vt100$/; |
30 |
|
|
shift, ($VT102 = 0) if $ARGV[0] =~ /^-?-vt100\+avo$/; |
31 |
|
|
shift if $ARGV[0] =~ /^-?-vt102$/; |
32 |
|
|
shift, ($VT131 = 1) if $ARGV[0] =~ /^-?-vt131$/; |
33 |
root |
1.10 |
|
34 |
root |
1.19 |
# vt100 wps = word processing roms |
35 |
|
|
# vt101 = vt102 - avo, but custom rom? really? |
36 |
|
|
# vt103 = vt100 + tu58 tape drive |
37 |
|
|
# vt125 = vt100 + gpo graphics processor |
38 |
|
|
# vt132 = vt100 + avo, stp |
39 |
|
|
# vt180 = vt100 + z80 cp/m |
40 |
|
|
|
41 |
root |
1.10 |
if ($ARGV[0] =~ /^-/) { |
42 |
|
|
die <<EOF; |
43 |
|
|
|
44 |
root |
1.19 |
VT102, A VT100/102/131 SIMULATOR |
45 |
root |
1.10 |
|
46 |
|
|
Usage: |
47 |
|
|
|
48 |
|
|
$0 [option] [program [args]] |
49 |
|
|
|
50 |
|
|
Examples: |
51 |
|
|
|
52 |
|
|
$0 bash |
53 |
|
|
$0 telnet towel.blinkenlights.nl |
54 |
|
|
$0 curl http://artscene.textfiles.com/vt100/trekvid.vt |
55 |
|
|
$0 curl http://artscene.textfiles.com/vt100/surf.vt # in 3d! |
56 |
|
|
|
57 |
|
|
Option can be one of: |
58 |
|
|
|
59 |
|
|
--vt100 |
60 |
|
|
--vt100+avo |
61 |
|
|
--vt102 |
62 |
|
|
--vt131 |
63 |
|
|
|
64 |
|
|
Non-obvious special keys are: |
65 |
|
|
|
66 |
|
|
SET UP Home |
67 |
|
|
BACKSPACE Rubout |
68 |
|
|
CAPS LOCK Prior/PgUp |
69 |
|
|
NO SCROLL Next/PgDown |
70 |
|
|
BREAK End |
71 |
|
|
|
72 |
|
|
Set-Up Guide: |
73 |
|
|
|
74 |
|
|
http://vt100.net/docs/vt102-ug/chapter3.html#S3.6 |
75 |
|
|
|
76 |
|
|
Author: |
77 |
|
|
|
78 |
|
|
Marc Lehmann <vt102\@schmorp.de> |
79 |
|
|
|
80 |
|
|
EOF |
81 |
|
|
} |
82 |
|
|
|
83 |
root |
1.1 |
############################################################################# |
84 |
root |
1.10 |
# ROM/hardware init |
85 |
root |
1.1 |
|
86 |
root |
1.15 |
my $PTY; # the pty we allocated, if any |
87 |
|
|
my $KBD = 1; |
88 |
|
|
|
89 |
root |
1.10 |
my $ROMS = do { |
90 |
root |
1.1 |
binmode DATA; |
91 |
|
|
local $/; |
92 |
|
|
<DATA> |
93 |
|
|
}; |
94 |
|
|
|
95 |
root |
1.10 |
0x6801 == length $ROMS or die "corrupted rom image"; |
96 |
root |
1.1 |
|
97 |
|
|
my @M = (0xff) x 65536; # main memory, = (0xff) x 65536; |
98 |
|
|
|
99 |
|
|
# populate mem with rom contents |
100 |
|
|
if ($VT102) { |
101 |
root |
1.10 |
@M[0x0000 .. 0x1fff] = unpack "C*", substr $ROMS, 0x2000, 0x2000; |
102 |
|
|
@M[0x8000 .. 0x9fff] = unpack "C*", substr $ROMS, 0x4000, 0x2000; |
103 |
|
|
@M[0xa000 .. 0xa7ff] = unpack "C*", substr $ROMS, 0x6000, 0x0800 if $VT131; |
104 |
root |
1.1 |
} else { |
105 |
root |
1.10 |
@M[0x0000 .. 0x1fff] = unpack "C*", substr $ROMS, 0x0000, 0x2000; |
106 |
root |
1.1 |
} |
107 |
|
|
|
108 |
|
|
############################################################################# |
109 |
root |
1.10 |
# 8085 CPU registers and I/O support |
110 |
root |
1.1 |
|
111 |
|
|
# 8080/8085 registers |
112 |
root |
1.23 |
my ($A, $B, $C, $D, $E, $H, $L); # 8 bit general purpose |
113 |
|
|
my ($PC, $SP, $IFF); # program counter, stack pointer, interrupt flag |
114 |
|
|
my ($FA, $FZ, $FS, $FP, $FC); # condition codes (psw) |
115 |
|
|
|
116 |
root |
1.25 |
my $RST = 0; # pending interrupts (external interrupt logic) |
117 |
root |
1.23 |
my $INTMASK = 7; # 8085 half interrupt mask |
118 |
|
|
my $INTPEND = 0; # 8085 half interrupts pending |
119 |
root |
1.1 |
|
120 |
root |
1.23 |
my $CLK; # rather inexact clock, counts extended basic blocks |
121 |
root |
1.1 |
|
122 |
|
|
############################################################################# |
123 |
root |
1.10 |
# the dreaded NVR1400 chip. not needed to get it going, but provided anyway |
124 |
root |
1.1 |
|
125 |
|
|
# nvram |
126 |
|
|
my @NVR = (0x3fff) x 100; # vt102: 214e accum, 214f only lower 8 bit used, first 44 bytes |
127 |
|
|
my $NVRADDR; |
128 |
|
|
my $NVRDATA; |
129 |
|
|
my $NVRLATCH; |
130 |
|
|
|
131 |
|
|
my @NVRCMD = ( |
132 |
root |
1.5 |
sub { $NVRDATA = ($NVRDATA << 1) + $_[1]; }, # 0 accept data |
133 |
|
|
sub { $NVRADDR = ($NVRADDR << 1) + $_[1]; }, # 1 accept addr |
134 |
|
|
sub { ($NVRDATA <<= 1) & 0x4000 }, # 2 shift out |
135 |
|
|
undef, # 3 not used, will barf |
136 |
|
|
sub { $NVR[$_[0]] = $NVRDATA & 0x3fff; }, # 4 write |
137 |
|
|
sub { $NVR[$_[0]] = 0x3fff; }, # 5 erase |
138 |
|
|
sub { $NVRDATA = $NVR[$_[0]]; }, # 6 read |
139 |
|
|
sub { }, # 7 standby |
140 |
root |
1.1 |
); |
141 |
|
|
|
142 |
root |
1.23 |
my @NVR_BITIDX; $NVR_BITIDX[1 << $_] = 9 - $_ for 0..9; |
143 |
root |
1.1 |
|
144 |
|
|
# the nvr1400 state machine. what a monster |
145 |
|
|
sub nvr() { |
146 |
root |
1.15 |
my $a1 = $NVR_BITIDX[(~$NVRADDR ) & 0x3ff]; |
147 |
|
|
my $a0 = $NVR_BITIDX[(~$NVRADDR >> 10) & 0x3ff]; |
148 |
root |
1.1 |
|
149 |
|
|
$NVRCMD[($NVRLATCH >> 1) & 7]($a1 * 10 + $a0, $NVRLATCH & 1) |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
############################################################################# |
153 |
root |
1.10 |
# I/O ports - output |
154 |
root |
1.1 |
|
155 |
root |
1.23 |
my $DC11_REVERSE = 0; # light background? |
156 |
root |
1.1 |
|
157 |
|
|
my $XON = 1; # false if terminal wants us to pause |
158 |
|
|
my $PUSARTCMD; |
159 |
|
|
|
160 |
root |
1.23 |
my $KSTATUS; # keyboard status (click + scan flag + leds) |
161 |
|
|
my @KXMIT; # current scan queue |
162 |
|
|
my %KXMIT; # currently pressed keys |
163 |
|
|
my @KQUEUE; # key event queue |
164 |
|
|
my $KXCNT; # count for debouncew |
165 |
|
|
|
166 |
|
|
my @PUSARTRECV; # serial input (to terminal) queue |
167 |
root |
1.1 |
|
168 |
|
|
sub out_00 { # pusartdata |
169 |
|
|
# handle xon/xoff, but also pass it through |
170 |
|
|
if ($_[0] == 0x13) { |
171 |
|
|
$XON = 0; |
172 |
root |
1.3 |
return;#d# |
173 |
root |
1.1 |
} elsif ($_[0] == 0x11) { |
174 |
|
|
$XON = 1; |
175 |
root |
1.3 |
return;#d# |
176 |
root |
1.1 |
} |
177 |
|
|
|
178 |
|
|
syswrite $PTY, chr $_[0]; |
179 |
|
|
|
180 |
root |
1.3 |
$INTPEND |= 1; |
181 |
root |
1.1 |
} |
182 |
|
|
|
183 |
root |
1.23 |
sub out_01 { # pusartcmd |
184 |
root |
1.1 |
$PUSARTCMD = shift; |
185 |
|
|
|
186 |
|
|
$INTPEND |= 1 if $PUSARTCMD & 0x01; # VT102, 5.5 txrdy |
187 |
root |
1.3 |
$INTPEND |= 2 if $PUSARTCMD & 0x04 && !@PUSARTRECV; # VT102, 6.5 rxrdy, needed for some reason |
188 |
root |
1.1 |
} |
189 |
|
|
|
190 |
|
|
sub out_02 { } # baudrate generator |
191 |
|
|
|
192 |
root |
1.23 |
sub out_23 { } # vt102 unknown |
193 |
|
|
sub out_27 { } # vt102 unknown |
194 |
|
|
sub out_2f { } # vt102 unknown, connected to in 0f |
195 |
root |
1.1 |
|
196 |
|
|
sub out_42 { } # brightness |
197 |
|
|
|
198 |
root |
1.23 |
sub out_62 { # nvr latch register (4 bits) |
199 |
root |
1.1 |
$NVRLATCH = shift; |
200 |
|
|
} |
201 |
|
|
|
202 |
root |
1.23 |
sub out_a2 { # device control 011 |
203 |
root |
1.6 |
my $dc11 = 0x0f & shift; |
204 |
|
|
|
205 |
|
|
$DC11_REVERSE = 1 if $dc11 == 0b1010; |
206 |
|
|
$DC11_REVERSE = 0 if $dc11 == 0b1011; |
207 |
|
|
} |
208 |
|
|
|
209 |
root |
1.1 |
sub out_c2 { } # unknown |
210 |
root |
1.23 |
sub out_d2 { } # device control 012, 0..3 == 80c/132c/60hz/50hz |
211 |
root |
1.1 |
|
212 |
root |
1.23 |
sub out_82 { # keyboard txmit |
213 |
|
|
# CLICK STARTSCAN ONLINE LOCKED | L1 L2 L3 L4 (vt100) |
214 |
|
|
# CLICK STARTSCAN ONLINE LOCKED | CTS DSR INS L1 (vt102) |
215 |
root |
1.1 |
$KSTATUS = $_[0]; |
216 |
|
|
|
217 |
root |
1.23 |
# start new scan unless scan is in progress |
218 |
root |
1.1 |
if (($_[0] & 0x40) && !@KXMIT) { |
219 |
|
|
# do not reply with keys in locked mode |
220 |
|
|
# or during post (0xff), |
221 |
|
|
# mostly to skip init and not fail POST, |
222 |
|
|
# and to send startup keys only when terminal is ready |
223 |
|
|
unless (($_[0] & 0x10) || ($_[0] == 0xff) || ($VT102 && $INTMASK == 0x07)) { |
224 |
|
|
if ($KXCNT <= 0 && @KQUEUE) { |
225 |
|
|
my $c = shift @KQUEUE; |
226 |
|
|
|
227 |
|
|
if ($c < 0) { # key up |
228 |
|
|
delete $KXMIT{-$c}; |
229 |
|
|
$KXCNT = 10; |
230 |
|
|
} elsif ($c > 0) { # key down |
231 |
|
|
undef $KXMIT{$c}; |
232 |
|
|
$KXCNT = 10; |
233 |
|
|
} else { # delay |
234 |
|
|
$KXCNT = 100; |
235 |
|
|
} |
236 |
|
|
} |
237 |
|
|
|
238 |
|
|
--$KXCNT; |
239 |
|
|
@KXMIT = sort keys %KXMIT; |
240 |
|
|
} |
241 |
|
|
|
242 |
|
|
$RST |= 1; |
243 |
|
|
} |
244 |
|
|
} |
245 |
|
|
|
246 |
|
|
############################################################################# |
247 |
root |
1.10 |
# I/O ports - input |
248 |
root |
1.1 |
|
249 |
root |
1.23 |
my $NVRBIT; # the current nvr data bit |
250 |
|
|
my $LBA6; # twice the frequenxy of LBA7 |
251 |
root |
1.1 |
|
252 |
|
|
sub in_00 { # pusart data |
253 |
root |
1.3 |
# interrupt not generated here, because infinite |
254 |
|
|
# speed does not go well with the vt102. |
255 |
root |
1.1 |
|
256 |
|
|
shift @PUSARTRECV |
257 |
|
|
} |
258 |
|
|
|
259 |
|
|
sub in_01 { # pusart status |
260 |
|
|
# DSR SYNDET FE OE | PE TXEMPTY RXRDY TXRDY |
261 |
|
|
0x85 + (@PUSARTRECV && 0x02) |
262 |
|
|
} |
263 |
|
|
|
264 |
root |
1.23 |
sub in_22 { # modem buffer |
265 |
root |
1.1 |
# wild guess: -CTS -SPDI -RI -CD 0 0 0 0 |
266 |
|
|
0x20 |
267 |
|
|
} |
268 |
|
|
|
269 |
root |
1.10 |
sub in_0f { 0xff } # vt102 unknown, connected to out 2f |
270 |
root |
1.1 |
|
271 |
|
|
sub in_42 { # flag buffer |
272 |
root |
1.10 |
++$LBA6; |
273 |
root |
1.1 |
|
274 |
root |
1.10 |
$NVRBIT = nvr ? 0x20 : 0x00 if ($LBA6 & 0x3) == 0x2; |
275 |
root |
1.1 |
|
276 |
|
|
# KBD_XMITEMPTY LBA7 NVRDATA ODDFIELD - OPTION !GFX !AVO PUSART_TXRDY |
277 |
|
|
|
278 |
|
|
my $f = 0x85 | $NVRBIT; |
279 |
|
|
|
280 |
|
|
$f |= 0x02 unless $AVO; |
281 |
root |
1.10 |
$f |= 0x40 if $LBA6 & 0x2; |
282 |
root |
1.1 |
|
283 |
|
|
$f |
284 |
|
|
} |
285 |
|
|
|
286 |
|
|
sub in_82 { # tbmt keyboard uart |
287 |
|
|
return 0x7f unless @KXMIT; |
288 |
|
|
|
289 |
|
|
$RST |= 1; |
290 |
|
|
shift @KXMIT |
291 |
|
|
} |
292 |
|
|
|
293 |
root |
1.10 |
sub in_03 { 0xff } # vt102 unknown, printer uart input? |
294 |
|
|
sub in_0b { 0xff } # vt102 unknown |
295 |
|
|
sub in_17 { 0xff } # vt102 unknown, printer status clear by reading? |
296 |
|
|
sub in_1b { 0xff } # vt102 unknown |
297 |
root |
1.1 |
|
298 |
|
|
############################################################################# |
299 |
root |
1.10 |
# 8085 cpu opcodes and flag handling |
300 |
root |
1.1 |
|
301 |
root |
1.17 |
my $x; # dummy scratchpad for opcodes |
302 |
|
|
|
303 |
root |
1.23 |
sub sf { # set flags, full version (ZSC - AP not implemented) |
304 |
root |
1.10 |
$FS = $_[0] & 0x080; |
305 |
|
|
$FZ = !($_[0] & 0x0ff); |
306 |
|
|
$FC = $_[0] & 0x100; |
307 |
|
|
|
308 |
|
|
$_[0] &= 0xff; |
309 |
|
|
} |
310 |
root |
1.1 |
|
311 |
root |
1.23 |
sub sf8 { # set flags, for 8-bit results (ZSC - AP not implemented) |
312 |
root |
1.10 |
$FS = $_[0] & 0x080; |
313 |
|
|
$FZ = !($_[0] & 0x0ff); |
314 |
|
|
$FC = 0; |
315 |
root |
1.1 |
} |
316 |
|
|
|
317 |
root |
1.23 |
sub sf_nc { # set flags, except carry |
318 |
root |
1.1 |
$FS = $_[0] & 0x080; |
319 |
|
|
$FZ = ($_[0] & 0x0ff) == 0; |
320 |
|
|
|
321 |
root |
1.10 |
$_[0] &= 0xff; |
322 |
root |
1.1 |
} |
323 |
|
|
|
324 |
root |
1.23 |
# opcode table |
325 |
root |
1.10 |
my @op = map { sprintf "status(); die 'unknown op %02x'", $_ } 0x00 .. 0xff; |
326 |
root |
1.1 |
|
327 |
root |
1.23 |
my @reg = qw($B $C $D $E $H $L $M[$H*256+$L] $A); # r/m encoding |
328 |
|
|
my @cc = ('!$FZ', '$FZ', '!$FC', '$FC', 'die;', 'die;', '!$FS', '$FS'); # cc encoding. die == unimplemented $FP parity |
329 |
root |
1.1 |
|
330 |
root |
1.23 |
$op[0x00] = ''; # nop |
331 |
root |
1.10 |
|
332 |
root |
1.1 |
# mov r,r / r,M / M,r |
333 |
|
|
for my $s (0..7) { |
334 |
|
|
for my $d (0..7) { |
335 |
root |
1.10 |
$op[0x40 + $d * 8 + $s] = "$reg[$d] = $reg[$s]"; # mov |
336 |
root |
1.1 |
} |
337 |
|
|
} |
338 |
|
|
|
339 |
root |
1.10 |
$op[0x76] = 'die "HLT"'; # hlt (mov m,m) |
340 |
|
|
|
341 |
|
|
# mvi r / M |
342 |
|
|
$op[0x06 + $_ * 8] = "$reg[$_] = IMM8" for 0..7; |
343 |
root |
1.1 |
|
344 |
|
|
$op[0x01] = '($B, $C) = (IMM16 >> 8, IMM16 & 0xff)'; # lxi |
345 |
|
|
$op[0x11] = '($D, $E) = (IMM16 >> 8, IMM16 & 0xff)'; # lxi |
346 |
|
|
$op[0x21] = '($H, $L) = (IMM16 >> 8, IMM16 & 0xff)'; # lxi |
347 |
root |
1.10 |
$op[0x31] = '$SP = IMM16' ; # lxi |
348 |
root |
1.1 |
|
349 |
|
|
$op[0x02] = '$M[$B * 256 + $C] = $A'; # stax |
350 |
|
|
$op[0x12] = '$M[$D * 256 + $E] = $A'; # stax |
351 |
|
|
$op[0x32] = '$M[IMM16 ] = $A'; # sta |
352 |
|
|
|
353 |
root |
1.10 |
$op[0x0a] = '$A = $M[$B * 256 + $C]'; # ldax b |
354 |
|
|
$op[0x1a] = '$A = $M[$D * 256 + $E]'; # ldax d |
355 |
|
|
$op[0x3a] = '$A = $M[IMM16]'; # lda |
356 |
|
|
|
357 |
|
|
$op[0x22] = '($M[IMM16], $M[IMM16 + 1]) = ($L, $H)'; # shld |
358 |
|
|
$op[0x2a] = '($L, $H) = ($M[IMM16], $M[IMM16 + 1])'; # lhld |
359 |
|
|
|
360 |
root |
1.1 |
sub inxdcx($$$) { |
361 |
root |
1.10 |
$x = $_[0] * 256 + $_[1] + $_[2]; |
362 |
|
|
($_[0], $_[1]) = (($x >> 8) & 0xff, $x & 0xff); |
363 |
root |
1.1 |
} |
364 |
|
|
|
365 |
|
|
$op[0x03] = 'inxdcx $B, $C, 1'; # inx |
366 |
|
|
$op[0x13] = 'inxdcx $D, $E, 1'; # inx |
367 |
|
|
$op[0x23] = 'inxdcx $H, $L, 1'; # inx |
368 |
|
|
$op[0x33] = '$SP++' ; # inx |
369 |
|
|
$op[0x0b] = 'inxdcx $B, $C, -1'; # dcx |
370 |
|
|
$op[0x1b] = 'inxdcx $D, $E, -1'; # dcx |
371 |
|
|
$op[0x2b] = 'inxdcx $H, $L, -1'; # dcx |
372 |
|
|
$op[0x3b] = '--$SP' ; # dcx |
373 |
|
|
|
374 |
|
|
# "no carry" doesn't seem to be needed for vt100 - optimize? |
375 |
root |
1.10 |
$op[0x04 + $_ * 8] = "sf_nc ++$reg[$_]" for 0..7; # inr |
376 |
|
|
$op[0x05 + $_ * 8] = "sf_nc --$reg[$_]" for 0..7; # dcr |
377 |
|
|
|
378 |
|
|
$op[0x07] = ' $FC = $A & 0x80; $A = (($A << 1) + ($FC && 0x01)) & 0xff '; # rlc |
379 |
|
|
$op[0x17] = ' ($FC, $A) = ($A & 0x80, (($A << 1) + ($FC && 0x01)) & 0xff)'; # ral |
380 |
|
|
$op[0x0f] = ' $FC = $A & 0x01; $A = ($A >> 1) | ($FC && 0x80) '; # rrc |
381 |
|
|
$op[0x1f] = ' ($FC, $A) = ($A & 0x01, ($A >> 1) | ($FC && 0x80))'; # rar |
382 |
root |
1.1 |
|
383 |
|
|
# getting this insn wrong (its the only 16 bit insn to modify flags) |
384 |
|
|
# wasted three of my best days with mindless vt102 rom reverse engineering |
385 |
|
|
sub dad { |
386 |
|
|
$x = $H * 256 + $L + $_[0]; |
387 |
|
|
|
388 |
|
|
($H, $L) = (($x >> 8) & 0xff, $x & 0xff); |
389 |
|
|
$FC = $x > 0xffff; |
390 |
|
|
} |
391 |
|
|
|
392 |
|
|
$op[0x09] = 'dad $B * 256 + $C'; # dad |
393 |
|
|
$op[0x19] = 'dad $D * 256 + $E'; # dad |
394 |
|
|
$op[0x29] = 'dad $H * 256 + $L'; # dad |
395 |
|
|
$op[0x39] = 'dad $SP '; # dad |
396 |
|
|
|
397 |
root |
1.23 |
$op[0x2f] = '$A ^= 0xff'; # cma |
398 |
|
|
|
399 |
root |
1.10 |
$op[0x80 + $_] = 'sf $A += + ' . $reg[$_] for 0..7; # add |
400 |
|
|
$op[0x88 + $_] = 'sf $A += ($FC && 1) + ' . $reg[$_] for 0..7; # adc |
401 |
|
|
$op[0x90 + $_] = 'sf $A -= + ' . $reg[$_] for 0..7; # sub |
402 |
|
|
$op[0x98 + $_] = 'sf $A -= ($FC && 1) + ' . $reg[$_] for 0..7; # sbb |
403 |
|
|
$op[0xa0 + $_] = 'sf8 $A &= ' . $reg[$_] for 0..7; # ana |
404 |
|
|
$op[0xa8 + $_] = 'sf8 $A ^= ' . $reg[$_] for 0..7; # xra |
405 |
|
|
$op[0xb0 + $_] = 'sf8 $A |= ' . $reg[$_] for 0..7; # ora |
406 |
|
|
$op[0xb8 + $_] = 'sf $x = $A - ' . $reg[$_] for 0..7; # cmp |
407 |
root |
1.23 |
# possible todo: optimize ora a, maybe xra a, possibly ana |
408 |
root |
1.1 |
|
409 |
root |
1.10 |
$op[0xc6] = 'sf $A += IMM8'; # adi |
410 |
|
|
$op[0xd6] = 'sf $A -= IMM8'; # sui |
411 |
|
|
$op[0xe6] = 'sf8 $A &= IMM8'; # ani |
412 |
|
|
$op[0xee] = 'sf8 $A ^= IMM8'; # xri |
413 |
|
|
$op[0xf6] = 'sf8 $A |= IMM8'; # ori |
414 |
|
|
$op[0xfe] = 'sf $A - IMM8'; # cpi |
415 |
root |
1.23 |
# ce ACI NYI, apparently unused |
416 |
|
|
# de SBI NYI, apparently unused |
417 |
root |
1.1 |
|
418 |
root |
1.10 |
$op[0xc5] = 'PUSH $B; PUSH $C'; |
419 |
|
|
$op[0xd5] = 'PUSH $D; PUSH $E'; |
420 |
|
|
$op[0xe5] = 'PUSH $H; PUSH $L'; |
421 |
|
|
$op[0xf5] = 'PUSH $A; PUSH +($FS && 0x80) | ($FZ && 0x40) | ($FA && 0x10) | ($FP && 0x04) | ($FC && 0x01)'; # psw |
422 |
root |
1.1 |
|
423 |
|
|
$op[0xc1] = '($C, $B) = (POP, POP)'; # pop |
424 |
|
|
$op[0xd1] = '($E, $D) = (POP, POP)'; # pop |
425 |
|
|
$op[0xe1] = '($L, $H) = (POP, POP)'; # pop |
426 |
root |
1.10 |
$op[0xf1] = '($x, $A) = (POP, POP); ($FS, $FZ, $FA, $FP, $FC) = ($x & 0x80, $x & 0x40, $x & 0x10, $x & 0x04, $x & 0x01)'; # pop psw |
427 |
root |
1.1 |
|
428 |
root |
1.23 |
$op[0xc2 + $_ * 8] = 'BRA IMM16 if ' . $cc[$_] for 0..7; # jcc |
429 |
root |
1.1 |
$op[0xc3] = 'JMP IMM16'; # jmp |
430 |
|
|
|
431 |
root |
1.23 |
$op[0xc4 + $_ * 8] = '(PUSH PC >> 8), (PUSH PC & 0xff), (BRA IMM16) if ' . $cc[$_] for 0..7; # ccc |
432 |
root |
1.1 |
$op[0xcd] = '(PUSH PC >> 8), (PUSH PC & 0xff), (BRA IMM16)'; # call |
433 |
|
|
|
434 |
root |
1.23 |
$op[0xc0 + $_ * 8] = 'BRA POP + POP * 256 if ' . $cc[$_] for 0..7; # rcc |
435 |
root |
1.10 |
$op[0xc9] = 'JMP POP + POP * 256'; # ret |
436 |
|
|
|
437 |
root |
1.1 |
$op[0xc7 + $_ * 8] = "JMP $_ * 8" for 0..7; # rst |
438 |
|
|
|
439 |
root |
1.10 |
$op[0xe9] = 'JMP $H * 256 + $L'; # pchl |
440 |
root |
1.19 |
# f9 SPHL NYI, apparently unused |
441 |
root |
1.1 |
|
442 |
root |
1.10 |
$op[0x37] = '$FC = 1 '; # stc |
443 |
|
|
$op[0x3f] = '$FC = !$FC'; # cmc |
444 |
root |
1.1 |
|
445 |
|
|
$op[0xd3] = 'OUT'; # out |
446 |
root |
1.23 |
$op[0xdb] = 'IN'; # in |
447 |
root |
1.1 |
|
448 |
root |
1.10 |
$op[0xeb] = '($D, $E, $H, $L) = ($H, $L, $D, $E)'; # xchg |
449 |
|
|
|
450 |
root |
1.19 |
# e3 xthl NYI # @ 917b in e69, hl <-> (sp) |
451 |
root |
1.1 |
|
452 |
root |
1.23 |
$op[0x20] = '$A = $INTPEND * 16 + $INTMASK + ($IFF && 8)'; # rim (8085, incomplete) |
453 |
|
|
$op[0x30] = '$INTMASK = $A & 7 if $A & 8'; # sim (8085, incomplete) |
454 |
root |
1.1 |
|
455 |
root |
1.23 |
$op[0xf3] = '$IFF = 0'; # di |
456 |
|
|
$op[0xfb] = '$IFF = 1'; # ei |
457 |
root |
1.1 |
|
458 |
root |
1.23 |
# yeah, the fucking setup screen actually uses daa... |
459 |
root |
1.10 |
$op[0x27] = ' |
460 |
|
|
my ($h, $l); |
461 |
|
|
|
462 |
|
|
($h, $l) = ($A >> 4, $A & 15); |
463 |
|
|
|
464 |
|
|
if ($l > 9 || $FA) { |
465 |
|
|
sf $A += 6; |
466 |
|
|
($h, $l) = ($A >> 4, $A & 15); |
467 |
|
|
} |
468 |
|
|
|
469 |
|
|
if ($h > 9 || $FC) { |
470 |
|
|
$h += 6; |
471 |
|
|
$A = ($h * 16 + $l) & 0xff; |
472 |
|
|
} |
473 |
|
|
'; # daa, almost certainly borked, also, acarry not set by sf |
474 |
root |
1.1 |
|
475 |
|
|
############################################################################# |
476 |
root |
1.23 |
# debug |
477 |
root |
1.1 |
|
478 |
|
|
# print cpu status, for debugging |
479 |
|
|
sub status { |
480 |
|
|
my $PC = shift || $PC; |
481 |
|
|
|
482 |
|
|
printf "%04x/%04x A=%02x BC=%02x:%02x DE=%02x:%02x HL=%02x:%02x ZSCAP=%s: %02x %s\n", |
483 |
|
|
$PC, $SP, |
484 |
|
|
$A, $B, $C, $D, $E, $H, $L, |
485 |
|
|
($FZ ? "1" : "0") |
486 |
|
|
. ($FS ? "1" : "0") |
487 |
|
|
. ($FC ? "1" : "0") |
488 |
|
|
. ($FA ? "1" : "0") |
489 |
|
|
. ($FP ? "1" : "0"), |
490 |
root |
1.10 |
$M[$PC], $op[$M[$PC]]; |
491 |
root |
1.1 |
} |
492 |
|
|
|
493 |
|
|
############################################################################# |
494 |
root |
1.10 |
# video emulation |
495 |
root |
1.1 |
|
496 |
root |
1.14 |
binmode STDOUT; |
497 |
|
|
|
498 |
root |
1.23 |
my @CHARMAP = ( # acschars / chars 0..31 |
499 |
root |
1.5 |
" " , "\x{29eb}", "\x{2592}", "\x{2409}", |
500 |
|
|
"\x{240c}", "\x{240d}", "\x{240a}", "\x{00b0}", |
501 |
|
|
"\x{00b1}", "\x{2424}", "\x{240b}", "\x{2518}", |
502 |
|
|
"\x{2510}", "\x{250c}", "\x{2514}", "\x{253c}", |
503 |
|
|
"\x{23ba}", "\x{23bb}", "\x{2500}", "\x{23bc}", |
504 |
|
|
"\x{23bd}", "\x{251c}", "\x{2524}", "\x{2534}", |
505 |
|
|
"\x{252c}", "\x{2502}", "\x{2264}", "\x{2265}", |
506 |
|
|
"\x{03c0}", "\x{2260}", "\x{00a3}", "\x{00b7}", |
507 |
root |
1.1 |
(map chr, 0x020 .. 0x7e), |
508 |
|
|
); |
509 |
|
|
|
510 |
root |
1.10 |
utf8::encode $_ for @CHARMAP; |
511 |
root |
1.1 |
|
512 |
root |
1.10 |
my @SGR; # sgr sequences for attributes |
513 |
root |
1.6 |
|
514 |
|
|
for (0x00 .. 0xff) { |
515 |
|
|
my $sgr = ""; |
516 |
|
|
|
517 |
root |
1.10 |
# ~1 sgr 5 blink |
518 |
|
|
# ~2 sgr 4 underline |
519 |
|
|
# ~4 sgr 1 bold |
520 |
|
|
# 0x80 in attr, sgr 7, reversed |
521 |
|
|
|
522 |
root |
1.6 |
$sgr .= ";5" unless $_ & 0x01; |
523 |
|
|
$sgr .= ";4" unless $_ & 0x02; |
524 |
|
|
$sgr .= ";1" unless $_ & 0x04; |
525 |
|
|
$sgr .= ";7" if $_ & 0x80; |
526 |
|
|
|
527 |
root |
1.10 |
$SGR[$_] = "\e[${sgr}m"; |
528 |
root |
1.6 |
} |
529 |
|
|
|
530 |
root |
1.10 |
my @LED = $VT102 |
531 |
|
|
? qw(L1 INSERT DSR CTS LOCKED LOCAL SCAN BEEP) |
532 |
|
|
: qw(L4 L3 L2 L1 LOCKED LOCAL SCAN BEEP); |
533 |
|
|
|
534 |
root |
1.26 |
my $CURSOR_IS_ON; |
535 |
|
|
|
536 |
root |
1.10 |
# display screen |
537 |
|
|
sub display { |
538 |
root |
1.26 |
# this is for the powersave mode - check whether the cursor is on here, |
539 |
|
|
# and only allow powersave later when it was on the last display time |
540 |
|
|
$CURSOR_IS_ON = $M[$VT102 ? 0x207b : 0x21ba]; |
541 |
|
|
|
542 |
root |
1.1 |
my $i = 0x2000; |
543 |
|
|
|
544 |
root |
1.10 |
my $leds = join " ", map $KSTATUS & 2**$_ ? "\e[7m$LED[$_]\e[m" : "$LED[$_]", reverse 0 .. $#LED; |
545 |
|
|
|
546 |
|
|
my $scr = sprintf "\e[H--- LED [ %s ] CLK %d\e[K\n", $leds, $CLK; |
547 |
root |
1.6 |
|
548 |
|
|
$scr .= "\e[?5" . ($DC11_REVERSE ? "h" : "l"); |
549 |
root |
1.5 |
|
550 |
root |
1.1 |
line: |
551 |
root |
1.6 |
for my $y (0 .. 25) { # ntsc, two vblank delay lines, up to 24 text lines |
552 |
|
|
my $prev_sgr; |
553 |
|
|
|
554 |
root |
1.9 |
$scr .= sprintf "%2d \xe2\x94\x82", $y; |
555 |
root |
1.1 |
|
556 |
root |
1.6 |
for (0..139) { |
557 |
|
|
my $c = $M[$i]; |
558 |
root |
1.1 |
|
559 |
|
|
if ($c == 0x7f) { # also 0xff, but the firmware avoids that |
560 |
root |
1.9 |
$scr .= "\e[m\xe2\x94\x82\e[K\n"; |
561 |
root |
1.1 |
|
562 |
root |
1.6 |
my $a1 = $M[$i + 1]; |
563 |
|
|
my $a0 = $M[$i + 2]; |
564 |
root |
1.1 |
|
565 |
|
|
$i = 0x2000 + (($a1 * 256 + $a0) & 0xfff); |
566 |
|
|
|
567 |
|
|
next line; |
568 |
|
|
} |
569 |
|
|
|
570 |
root |
1.10 |
my $sgr = $SGR[ ($M[$i++ + 0x1000] & 15) | ($c & 0x80)]; |
571 |
root |
1.6 |
|
572 |
|
|
$scr .= $prev_sgr = $sgr if $sgr ne $prev_sgr; |
573 |
|
|
|
574 |
root |
1.10 |
$scr .= $CHARMAP[$c & 0x7f]; |
575 |
root |
1.1 |
} |
576 |
|
|
|
577 |
root |
1.6 |
$scr .= "\e[K\nvideo overflow\e[K\n"; |
578 |
root |
1.1 |
last; |
579 |
|
|
} |
580 |
|
|
|
581 |
root |
1.10 |
$scr .= "\e[m\e[J"; |
582 |
root |
1.1 |
|
583 |
|
|
syswrite STDOUT, $scr; |
584 |
|
|
} |
585 |
|
|
|
586 |
|
|
############################################################################# |
587 |
root |
1.10 |
# keyboard handling |
588 |
root |
1.1 |
|
589 |
root |
1.7 |
# 0x080 shift, 0x100 ctrl |
590 |
root |
1.1 |
my %KEYMAP = ( |
591 |
root |
1.8 |
"\t" => 0x3a, |
592 |
|
|
"\r" => 0x64, |
593 |
|
|
"\n" => 0x44, |
594 |
|
|
|
595 |
|
|
"\x00" => 0x77 | 0x100, # CTRL-SPACE |
596 |
|
|
"\x1c" => 0x45 | 0x100, # CTRL-\ |
597 |
|
|
"\x1d" => 0x14 | 0x100, # CTRL-] |
598 |
|
|
"\x1e" => 0x24 | 0x100, # CTRL-~ |
599 |
|
|
"\x1f" => 0x75 | 0x100, # CTRL-? |
600 |
|
|
|
601 |
|
|
# hardcoded rxvt keys |
602 |
|
|
"\e" => 0x2a, # ESC |
603 |
|
|
"\e[3~" => 0x03, # DC |
604 |
|
|
"\e[5~" => 0x7e, # CAPS LOCK (prior) |
605 |
|
|
"\e[6~" => 0x6a, # NO SCROLL (next) |
606 |
|
|
"\e[A" => 0x30, # UP |
607 |
|
|
"\e[B" => 0x22, # DOWN |
608 |
|
|
"\e[C" => 0x10, # RIGHT |
609 |
|
|
"\e[D" => 0x20, # LEFT |
610 |
|
|
"\e[a" => 0x30 | 0x080, # UP |
611 |
|
|
"\e[b" => 0x22 | 0x080, # DOWN |
612 |
|
|
"\e[c" => 0x10 | 0x080, # RIGHT |
613 |
|
|
"\e[d" => 0x20 | 0x080, # LEFT |
614 |
|
|
"\e[7~" => 0x7b, # SETUP (home) |
615 |
|
|
"\e[8~" => 0x23, # BREAK (end) |
616 |
|
|
"\e[8\$" => 0x23 | 0x080, # SHIFT BREAK / DISCONNECT (shift-end) |
617 |
|
|
"\x7f" => 0x33, # BACKSPACE |
618 |
|
|
|
619 |
|
|
"\e[11~" => 0x32, # F1 |
620 |
|
|
"\e[11~" => 0x42, # F2 |
621 |
|
|
"\e[11~" => 0x31, # F3 |
622 |
|
|
"\e[11~" => 0x41, # F4 |
623 |
root |
1.1 |
); |
624 |
|
|
|
625 |
root |
1.10 |
@KEYMAP{map chr, 0x20 .. 0x40, 0x5b .. 0x7e} = unpack "C*", pack "H*", |
626 |
|
|
"779ad5a9a8b8a755a6b5b6b466256575" . "351a3929283837273626d656e634e5f5" . "b9" # 20..40 |
627 |
|
|
. "154514b7a5" . "244a6879591949485816574746766706" . "050a185a0817780969077a95c594a4"; # 5b..7e |
628 |
root |
1.1 |
|
629 |
root |
1.7 |
$KEYMAP{"\x1f" & $_} ||= $KEYMAP{$_} | 0x100 for "a" .. "z"; # ctrl |
630 |
root |
1.10 |
$KEYMAP{"\x20" ^ $_} ||= $KEYMAP{$_} | 0x080 for "a" .. "z"; # shift |
631 |
root |
1.1 |
|
632 |
|
|
my $KEYMATCH = join "|", map quotemeta, reverse sort keys %KEYMAP; |
633 |
|
|
$KEYMATCH = qr{^($KEYMATCH)}s; |
634 |
|
|
|
635 |
root |
1.23 |
my %KMOD; # currently pressed modifier keys |
636 |
root |
1.10 |
|
637 |
root |
1.1 |
sub key { |
638 |
|
|
my ($key) = @_; |
639 |
|
|
|
640 |
root |
1.10 |
push @KQUEUE, -0x7c if !($key & 0x100) && delete $KMOD{0x7c}; # ctrl-up |
641 |
|
|
push @KQUEUE, -0x7d if !($key & 0x080) && delete $KMOD{0x7d}; # shift-up |
642 |
root |
1.1 |
|
643 |
root |
1.10 |
push @KQUEUE, 0x7c if $key & 0x100 && !$KMOD{0x7c}++; # ctrl-down |
644 |
|
|
push @KQUEUE, 0x7d if $key & 0x080 && !$KMOD{0x7d}++; # shift-down |
645 |
root |
1.1 |
|
646 |
|
|
$key &= 0x7f; |
647 |
|
|
push @KQUEUE, $key, -$key; |
648 |
|
|
} |
649 |
|
|
|
650 |
|
|
my $STDIN_BUF; |
651 |
|
|
|
652 |
|
|
sub stdin_parse { |
653 |
|
|
key $KEYMAP{$1} |
654 |
|
|
while $STDIN_BUF =~ s/$KEYMATCH//; |
655 |
|
|
|
656 |
|
|
# skip input we can't decipher |
657 |
|
|
substr $STDIN_BUF, 0, 1, ""; |
658 |
|
|
} |
659 |
|
|
|
660 |
|
|
if ($KBD) { |
661 |
|
|
system "stty -icanon -icrnl -inlcr -echo min 1 time 0"; |
662 |
|
|
eval q{ sub END { system "stty sane" } }; |
663 |
|
|
$SIG{INT} = $SIG{TERM} = $SIG{QUIT} = sub { exit 1 }; |
664 |
|
|
} |
665 |
|
|
|
666 |
|
|
############################################################################# |
667 |
root |
1.10 |
# initial key input, to set up online mode etc. |
668 |
|
|
# could be done via nvram defaults |
669 |
|
|
|
670 |
|
|
@KQUEUE = ( |
671 |
|
|
0x7b, -0x7b, # setup |
672 |
|
|
0, # delay |
673 |
|
|
0x28, -0x28, # 4, toggle local/online |
674 |
|
|
0x38, -0x38, # 5, setup b |
675 |
|
|
0, # delay |
676 |
|
|
(0x10, -0x10) x 2, # cursor right |
677 |
|
|
0x37, -0x37, # 6 toggle soft scroll |
678 |
|
|
(0x10, -0x10) x 1, # cursor right |
679 |
|
|
0x37, -0x37, # 6 toggle autorepeat off |
680 |
|
|
(0x10, -0x10) x 8, # cursor right |
681 |
|
|
0x37, -0x37, # 6 toggle keyclick |
682 |
|
|
(0x10, -0x10) x 1, # cursor right |
683 |
|
|
$VT102 ? () : (0x37, -0x37), # 6 toggle ansi/vt52 |
684 |
|
|
(0x10, -0x10) x 7, # cursor right |
685 |
|
|
0x37, -0x37, # 6 toggle wrap around |
686 |
|
|
0x7b, -0x7b, # leave setup |
687 |
|
|
); |
688 |
|
|
|
689 |
|
|
############################################################################# |
690 |
|
|
# process/pty management |
691 |
|
|
|
692 |
root |
1.26 |
if (1) { |
693 |
|
|
require IO::Pty; |
694 |
|
|
$PTY = IO::Pty->new; |
695 |
|
|
|
696 |
|
|
my $slave = $PTY->slave; |
697 |
|
|
|
698 |
|
|
$PTY->set_winsize (24, 80); |
699 |
root |
1.10 |
|
700 |
root |
1.26 |
unless (fork) { |
701 |
|
|
$ENV{LC_ALL} = "C"; |
702 |
|
|
$ENV{TERM} = $VT102 ? "vt102" : "vt100"; |
703 |
root |
1.10 |
|
704 |
root |
1.26 |
close $PTY; |
705 |
root |
1.10 |
|
706 |
root |
1.26 |
open STDIN , "<&", $slave; |
707 |
|
|
open STDOUT, ">&", $slave; |
708 |
|
|
open STDERR, ">&", $slave; |
709 |
root |
1.10 |
|
710 |
root |
1.26 |
system "stty ixoff erase ^H"; |
711 |
root |
1.10 |
|
712 |
root |
1.26 |
$PTY->make_slave_controlling_terminal; |
713 |
|
|
$PTY->close_slave; |
714 |
root |
1.10 |
|
715 |
root |
1.26 |
@ARGV = "sh" unless @ARGV; |
716 |
|
|
exec @ARGV; |
717 |
|
|
} |
718 |
root |
1.10 |
|
719 |
|
|
$PTY->close_slave; |
720 |
root |
1.26 |
} else { |
721 |
|
|
open $PTY, "+</dev/null" |
722 |
|
|
or die "/dev/null: $!"; |
723 |
root |
1.10 |
} |
724 |
|
|
|
725 |
|
|
############################################################################# |
726 |
|
|
# the actual hardware simulator |
727 |
root |
1.1 |
|
728 |
root |
1.23 |
my @ICACHE; # compiled instruction/basic block cache |
729 |
root |
1.1 |
|
730 |
root |
1.21 |
my $POWERSAVE; # powersave counter |
731 |
|
|
|
732 |
|
|
my $RIN; # libev for the less well-off |
733 |
|
|
|
734 |
|
|
(vec $RIN, 0, 1) = 1 if $KBD; |
735 |
|
|
(vec $RIN, fileno $PTY, 1) = 1 if $PTY; |
736 |
|
|
|
737 |
root |
1.23 |
# the cpu. |
738 |
root |
1.1 |
while () { |
739 |
root |
1.26 |
# execute an extended basic block |
740 |
root |
1.1 |
$PC = ($ICACHE[$PC] ||= do { |
741 |
|
|
my $pc = $PC; |
742 |
|
|
|
743 |
|
|
my $insn = ""; |
744 |
|
|
|
745 |
|
|
# the jit compiler |
746 |
root |
1.10 |
for (0..31) { |
747 |
root |
1.1 |
my $imm; |
748 |
|
|
my $op = $op[$M[$pc++]]; |
749 |
|
|
|
750 |
|
|
for ($op) { |
751 |
|
|
s/\bPUSH\b/\$M[--\$SP] =/g; # push byte to stack |
752 |
|
|
s/\bPOP\b/\$M[\$SP++]/g; # pop byte from stack |
753 |
|
|
|
754 |
|
|
s/\bIMM16\b/$imm \/\/= $M[$pc++] + $M[$pc++] * 256/xge; # 16 bit insn immediate |
755 |
|
|
s/\bIMM8\b /$imm \/\/= $M[$pc++] /xge; # 8 bit insn immediate |
756 |
|
|
|
757 |
|
|
s/\bPC\b/$pc/ge; # PC at end of insn |
758 |
|
|
s/\bBRA\b/return/g; # conditional jump |
759 |
|
|
s/\bJMP\b(.*)/$1\x00/sg; # unconditional jump |
760 |
|
|
|
761 |
root |
1.23 |
s/\bIN\b/ sprintf "\$A = in_%02x", $M[$pc++]/xge; # in insns call in_HEX |
762 |
|
|
s/\bOUT\b/sprintf "out_%02x \$A ", $M[$pc++]/xge; # out likewise |
763 |
root |
1.1 |
} |
764 |
|
|
|
765 |
|
|
$insn .= "$op;\n"; |
766 |
|
|
} |
767 |
|
|
|
768 |
|
|
|
769 |
root |
1.12 |
$insn .= $pc; |
770 |
root |
1.1 |
$insn =~ s/\x00.*$//s; |
771 |
|
|
|
772 |
root |
1.26 |
eval "sub { $insn }" or die "$insn: $@" |
773 |
root |
1.1 |
})->(); |
774 |
|
|
|
775 |
|
|
++$CLK; |
776 |
|
|
|
777 |
root |
1.18 |
# things we do from time to time only |
778 |
root |
1.1 |
unless ($CLK & 0xf) { |
779 |
|
|
# do I/O |
780 |
|
|
|
781 |
root |
1.10 |
unless ($CLK & 0xfff) { |
782 |
root |
1.27 |
if (select $x = $RIN, undef, undef, $POWERSAVE < 10 ? 0 : $CURSOR_IS_ON && 10) { |
783 |
root |
1.24 |
|
784 |
root |
1.21 |
# pty/serial I/O |
785 |
|
|
if ($PTY && (vec $x, fileno $PTY, 1) && (@PUSARTRECV < 128) && !@KQUEUE) { |
786 |
root |
1.23 |
sysread $PTY, my $buf, 256; |
787 |
root |
1.21 |
|
788 |
root |
1.26 |
# linux don't do cs7 and/or parity anymore, so we need to filter # out xoff characters to avoid freezes. |
789 |
root |
1.23 |
push @PUSARTRECV, grep { ($_ & 0x7f) != 0x13 } unpack "C*", $buf; |
790 |
root |
1.21 |
} |
791 |
root |
1.1 |
|
792 |
root |
1.21 |
# keyboard input |
793 |
|
|
if ($KBD && (vec $x, 0, 1)) { |
794 |
root |
1.23 |
# to avoid non-blocking mode on stdin (and stty min 0), we |
795 |
|
|
# just read byte-by-byte after a select says there is data. |
796 |
root |
1.21 |
while (select my $rin = "\x01", undef, undef, 0) { |
797 |
|
|
sysread STDIN, $STDIN_BUF, 1, length $STDIN_BUF |
798 |
|
|
or last; |
799 |
|
|
} |
800 |
root |
1.1 |
|
801 |
root |
1.21 |
stdin_parse if length $STDIN_BUF; |
802 |
root |
1.1 |
} |
803 |
|
|
|
804 |
root |
1.23 |
$POWERSAVE = 0; # activity |
805 |
root |
1.24 |
} elsif (@PUSARTRECV || @KQUEUE) { |
806 |
|
|
$POWERSAVE = 0; |
807 |
root |
1.21 |
} else { |
808 |
root |
1.24 |
++$POWERSAVE; |
809 |
root |
1.1 |
} |
810 |
|
|
} |
811 |
|
|
|
812 |
root |
1.23 |
# kick off serial input interrupt quite often |
813 |
root |
1.3 |
$RST |= 2 if @PUSARTRECV && $XON; # VT100, but works on vt102, too (probably not used on real hardware though) |
814 |
|
|
#$INTPEND |= 2 if @PUSARTRECV && $XON; # VT102, 6.5 rxrdy |
815 |
root |
1.1 |
|
816 |
root |
1.23 |
# kick off vertical retrace interrupt from time to time |
817 |
root |
1.5 |
unless ($CLK & 0x1ff) { |
818 |
root |
1.1 |
$RST |= 4; # vertical retrace |
819 |
|
|
} |
820 |
|
|
|
821 |
|
|
# handle video hardware |
822 |
root |
1.10 |
unless ($CLK & 0x3fff) { |
823 |
|
|
display; |
824 |
root |
1.1 |
} |
825 |
|
|
} |
826 |
root |
1.4 |
|
827 |
root |
1.23 |
# the interrupt logic - we only interrupt after basic blocks |
828 |
|
|
# which, as a side effect, ensures that we don't interrupt |
829 |
|
|
# "ei; ret" sequences and thus reduce the risk of stack overflows. |
830 |
root |
1.10 |
if (($RST || ($INTPEND & ~$INTMASK)) && $IFF) { |
831 |
root |
1.4 |
# rst 1 kbd data available |
832 |
|
|
# rst 2 pusart xmit+recv flag |
833 |
|
|
# rst 4 vertical retrace |
834 |
|
|
# 5.5 vt125 mb7 trans ready (serial send?) |
835 |
|
|
# 6.5 vt125 mb7 read ready (something modem?) |
836 |
|
|
# 7.5 vt125 mb7 vblank h(?) |
837 |
|
|
# trap vt125 mbi init h(?) |
838 |
|
|
my $vec; |
839 |
|
|
|
840 |
root |
1.17 |
my $pend = $INTPEND & ~$INTMASK; |
841 |
root |
1.10 |
|
842 |
root |
1.17 |
if ($pend & 1) { $vec = 0x2c; $INTPEND &= ~1; |
843 |
|
|
} elsif ($pend & 2) { $vec = 0x34; $INTPEND &= ~2; |
844 |
|
|
} elsif ($pend & 4) { $vec = 0x3c; $INTPEND &= ~4; |
845 |
root |
1.10 |
# } elsif ($RST ) { $vec = $RST * 8; $RST = 0; # the vt102 firmware doesn't like combined interrupts |
846 |
root |
1.4 |
} elsif ($RST & 1) { $vec = 0x08; $RST &= ~1; # separate is better for vt102 |
847 |
|
|
} elsif ($RST & 2) { $vec = 0x10; $RST &= ~2; |
848 |
|
|
} elsif ($RST & 4) { $vec = 0x20; $RST &= ~4; |
849 |
|
|
} else { |
850 |
|
|
die; |
851 |
|
|
} |
852 |
|
|
|
853 |
root |
1.23 |
# jump to the interrupt vector |
854 |
root |
1.4 |
$M[--$SP] = $PC >> 8; |
855 |
|
|
$M[--$SP] = $PC & 0xff; |
856 |
|
|
$PC = $vec; |
857 |
|
|
|
858 |
|
|
$IFF = 0; |
859 |
|
|
} |
860 |
root |
1.1 |
} |
861 |
|
|
|
862 |
root |
1.10 |
############################################################################# |
863 |
|
|
# roms in the data section + one newline |
864 |
|
|
# |
865 |
|
|
# vt100 @ 0x0000+0x0800 23-032E2 |
866 |
|
|
# vt100 @ 0x0800+0x0800 23-061E2 |
867 |
|
|
# vt100 @ 0x1000+0x0800 23-033E2 |
868 |
|
|
# vt100 @ 0x1800+0x0800 23-034E2 |
869 |
|
|
# |
870 |
root |
1.11 |
# vt102 @ 0x0000+0x2000 23-226E4 |
871 |
|
|
# vt102 @ 0x8000+0x2000 23-225E4 |
872 |
root |
1.10 |
# |
873 |
|
|
# vt131 @ 0xa000+0x0800 23-280E2 |
874 |
|
|
# |
875 |
|
|
|
876 |
root |
1.1 |
__DATA__ |
877 |
|
|
1N ; 0 >b/BWog<Gӂ,O $
O [ xI <ӂ,Bt @`+6 +|v #~ʐ |¡ 0ڡ q~ʨ |¡ 0Ҩ ,ڥ # yOt ͤ[ zW>/2!b>> >ӂx ӂ:h zW͢uۂG|g$>%
!h w-!h >-4!j pO:{ y:! u:x!_yA[>y
>yA[>?y@
:x!yA[P>>O[>>[Î:!ʵyA>>OlyAPÇ!:!S!h ~ ~ >%: O͓: Ô!20!2!!!yAG~"&=w< w:!/!!A:!Ey2!~1N ! ~eBi<2!͢:P =2S!~6ʘ!!6 |
878 |
|
|
2!0* w4ʘ> 2! ~î!N ̓/2!! "R !"" |
879 |
|
|
! ͋! 0 Ãppppp!"-!>52,!>2[ 2v!!"I!>2s >2 B>2y >2!2!&l" >@:X!:!͔>2!b:!K>G:| !p ^!p" :!x:! u> |
880 |
|
|
Ӣ:[!Ӣ:!cww#:!>>{́kB͈͇!w!~6 :!ʮ2D!î :O:!:8>'y7:!y !!>D! NDy<wG: 'qx<o61,@ 7~G>G>w70)1!2@3#4$5%6^7&8*9(-_=+`~[{]};:/?'",<.>\| poytwq ][iure1 `-9743=08652 Ѱ |
881 |
|
|
\lkgfa ';jhds
.,nbx /m vczN> Ӣ:e !Q >>2e 6 >2[ :V!>2[ :U!=/2z [ |
882 |
|
|
!Z 'wWӢzӢz>2e |
883 |
|
|
:V!8:U!=2z !x ~O52F!!,!~=i65>Ӣ!!~jӢw>@2H!! 4:!B:X!:!b:!!{ uG:{ x©:y xک ڲ*@!! |
884 |
|
|
2>2y |
885 |
|
|
G>xbO͈ByFsO! V#zozz2 V: Gzy_ Oz@y$#$: O:B!A! :S!A6 U * q|gpx2 ! q! :S!hy2 :!@m462B!:!
! ~#n& V! ~<w+@0§~z:h _!A{2g W !n ~!j #6
#{>2r !G:r < 2r :!@{:P!!_#!s 56:r y!n ~C#8vyj !n ~[ |
886 |
|
|
f#}rQ |
887 |
|
|
lNG:g x2g 2P!{j,C_:D!A{WW{!v_ Ny1 xpy{aOx0!K~###NxyA[? {AAO:!2T!S:P!!n A#!n ~8#+A:P!w>2r !h Vw#r#w#L:!@>2G!{*j:d:0!W:1!_>= zħ;>>ܧ>b>ܧz >oz2 QW>>Wʞ _{ |
888 |
|
|
>!_ ^#V 8 A
U U U K <2 :!*{!|!r!>w!r!~w!{!F#\!~0 #
$ !x ~w! ~562 6K :! K ! V:V!s Ϳxr6:!ʘ ͎>2!4:! 2 =2 2} 2!! |
889 |
|
|
0ҽ !} O~ʻ q2~ ! |
890 |
|
|
:} :! !P |
891 |
|
|
! |
892 |
|
|
G:! x( 2)1#!{ |
893 |
|
|
!:~ O#
|
894 |
|
|
## |
895 |
|
|
~#fo!"@!A |
896 |
|
|
B |
897 |
|
|
C |
898 |
|
|
D |
899 |
|
|
F |
900 |
|
|
GH |
901 |
|
|
IJ |
902 |
|
|
K |
903 |
|
|
YZ=>1W<]`
c ER M1W[ |
904 |
|
|
H
DU 7h8q=>ZNFOF 345J67`
8
!"@!>H2~ ! "0!! |
905 |
|
|
:} ! |
906 |
|
|
:!!0!:K!_ |
907 |
|
|
~! |
908 |
|
|
G :!# |
909 |
|
|
DBCHSArfSxyd cqn
JAKlmhg
!"@!G ڲ!Q!.! "@!~B6x 2R!!"@!6 x PO2 Ϳ:R!]2 |
910 |
|
|
62!ͭPLPÉ>2!ͭL2U!Ϳx2V!y2P BH>ê! :U!G~ʸ! 56:!͎>2!5:!2 -!x!6!x!6 !!~ w:!&&Hl" " 2 &&l" !E!x#~wG7)w:~ G!J##~ȸ9#~! 44AHB01 2 !y ~ |
911 |
|
|
6! |
912 |
|
|
!! w! !͋6!xʗ 2 ! ~w>õ:!»>õ>! w>2 :0!!r!~w>Ϳ
:! 6+6/6?#>1
BG/Oxy0w#6:!x!r!2
~w>Ϳ
:!x)
0w#6~w>Ϳ
: G:!J
:U!Ox<z
ͻ
: <z
6B͎> |