outofmbufs / python-pdp11-emulator Goto Github PK
View Code? Open in Web Editor NEWYet another PDP-11 emulator, written in Python. Can boot/run V7 Unix!
License: MIT License
Yet another PDP-11 emulator, written in Python. Can boot/run V7 Unix!
License: MIT License
In RORB (and others):
cpu.psw_n = val & signmask
cpu.psw_z = (val == 0)
cpu.psw_v = cpu.psw_n ^ cpu.psw_c
Now val is 0...255. Signmask is 128. So psw_n can be 128 and 0.
This makes psw_v into 0, 1, 128 or 129.
_brconds (in branches.py) for v-flag is:
0o102000: lambda n, z, v, c: not v, # BVC
0o102400: lambda n, z, v, c: v, # BVS
I think you shold either make the lambda in: "not (v & 1)" and "(v & 1)" or the asignment of the n-flag into e.g.:
cpu.psw_n = 1 if val & signmask else 0
Hi,
Trying to load XXDP modules into the emulator to do extra testing of its emulation.
For that I implemented a tape image loader which should be able to read e.g. a .BIC file from the XXDP set.
The loading at itself works fine but as soon as the emulated code wants to write a character to the console, an PDPTraps.AddressError is triggered. I dug a bit into it and klregs from KL11 in kl11.py is called with address 017566 and a value of None, yet the following is logged:
pdp11.DEBUG[004933]: Byte write to 0o17566 value=13
pdp11.DEBUG[004933]: TRAP: AddressError(vector=0o4):
BKTCB0.BIC.zip
tapeloader.py.zip
Stack trace:
* Stack trace, innermost first
*
** byteme at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/mmio.py:215
*** ioaddr: 8054
*** value: None
*** opsize: 2
*** iofunc: <bound method KL11.klregs of <kl11.KL11 object at 0x75ad6c350d90>>
*** self: <mmio.MMIO object at 0x75ad6c346450>
** wordRW at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/mmio.py:280
*** self: <mmio.MMIO object at 0x75ad6c346450>
*** ioaddr: 8054
*** value: None <=------- here value is suddenly None
** byteme at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/mmio.py:220
*** ioaddr: 8054
*** value: 13
*** opsize: 1
*** iofunc: <bound method KL11.klregs of <kl11.KL11 object at 0x75ad6c350d90>>
*** self: <mmio.MMIO object at 0x75ad6c346450>
** byteRW at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/mmio.py:290
*** self: <mmio.MMIO object at 0x75ad6c346450>
*** ioaddr: 8054
*** value: 13
** byteRW at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/mmu.py:559
*** self: <mmu.MemoryMgmt object at 0x75ad6cf24d50>
*** vaddr: 65398
*** value: 13
*** mode: None
*** space: 1
*** pa: 65398
*** odd: 0
** operandx at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/machine.py:528
*** self: <machine.PDP1170 object at 0x75ad6c5b6010>
*** b6: 55
*** value: 13
*** opsize: 1
*** altmode: None
*** altspace: None
*** rmw: False
*** justEA: False
*** Rn: 7
*** autocrement: 0
*** space: 1
*** extendedb6: None
*** addr: 65398
*** addrmode: 48
*** x: 64786
** op11_movb at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/op4.py:110
*** cpu: <machine.PDP1170 object at 0x75ad6c5b6010>
*** inst: 37943
*** val: 13
*** dst: 55
** run at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/machine.py:585
*** self: <machine.PDP1170 object at 0x75ad6c5b6010>
*** pc: 128
*** breakpoint: None
*** interrupt_mgr: <interrupts.InterruptManager object at 0x75ad6c346410>
*** mmu: <mmu.MemoryMgmt object at 0x75ad6cf24d50>
*** abort_trap: None
*** thisPC: 608
*** inst: 37943
** <module> at /home/folkert/Projects/PDP-11/json/python-pdp11-emulator/./tapeloader.py:63
*** __name__: '__main__'
[...]
In mmio.py line 220 a word is read from the i/o to convert the byte-write into a word-write.
For that to work I think you need to do something like this:
diff --git a/kl11.py b/kl11.py
index b8ad643..9db36fc 100644
--- a/kl11.py
+++ b/kl11.py
@@ -125,7 +125,8 @@ class KL11:
self.ub.intmgr.simple_irq(pri=4, vector=0o64)
# transmit buffer
- case 6 if value is not None: # tbuf
+ case 6:
+ if value is not None: # tbuf
# *** WRITING ***
value &= 0o177
if (value != 0o177):
@@ -133,6 +134,8 @@ class KL11:
self.tq.put(s)
if self.t_ienable:
self.ub.intmgr.simple_irq(pri=4, vector=0o64)
+ else:
+ value = 0
case _:
raise PDPTraps.AddressError
Hi,
Shouldn't BIC(B) clear the V-flag?
Hi,
Are you sure about the current SOB implementation?
It is subtle different from other implementations I saw (p11, simh) and behaves a tiny bit different because of that.
I think it should be:
def op077_sob(cpu, inst):
srcreg = (inst & 0o000700) >> 6
r = (cpu.r[srcreg] - 1) & 0xffff
if r != 0:
# technically if this instruction occurs low enough in memory
# this PC subtraction could wrap, so be technically correct & mask
cpu.r[cpu.PC] = (cpu.r[cpu.PC] - 2 * (inst & 0o077)) & cpu.MASK16
cpu.r[srcreg] = r
See https://github.com/open-simh/simh/blob/master/PDP11/pdp11_cpu.c#L1895
Hi,
I'm not 100% sure but regarding https://github.com/outofmbufs/python-pdp11-emulator/blob/main/machine.py#L454
At line 463 for registers that are not SP/PC, the autoincrement is set to word_size. But I think that should always be 2 unless I mis-interpret https://bitsavers.org/pdf/dec/pdp11/1170/PDP-11_70_Handbook_1977-78.pdf page 33, 3-9.
"Register is first used as a pointer to a word containing the address of the operand, then incremented (always by 2; even for byte instructions)". Same for mode 5 (which currently only for SP decrements by 2).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.