-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
80 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (c) Fredrik Andersson, 2023 | ||
# All rights reserved | ||
|
||
from digsim.circuit.components.atoms import Component, PortIn, PortOut, PortWire | ||
|
||
|
||
class Mem64kByte(Component): | ||
def __init__(self, circuit, rom_filename=None, rom_address=0): | ||
super().__init__(circuit, "Memory") | ||
self.add_port(PortIn(self, "clk")) | ||
self.add_port(PortWire(self, "Address", width=16)) | ||
self.add_port(PortWire(self, "DataIn", width=8)) | ||
self.add_port(PortWire(self, "WE")) | ||
self.add_port(PortOut(self, "DataOut", width=8)) | ||
self._mem_array = [0] * 65536 | ||
if rom_filename is not None: | ||
with open(rom_filename, mode="rb") as rom: | ||
romdata = rom.read() | ||
for idx, byte in enumerate(romdata): | ||
self._mem_array[rom_address + idx] = byte | ||
|
||
def update(self): | ||
if not self.clk.is_rising_edge() or self.Address.value == "X": | ||
return | ||
addr = self.Address.value | ||
we = self.WE.value | ||
if we == 1: | ||
datain = self.DataIn.value | ||
self._mem_array[addr] = datain | ||
else: | ||
dataout = self._mem_array[addr] | ||
self.DataOut.value = dataout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (c) Fredrik Andersson, 2023 | ||
# All rights reserved | ||
|
||
from digsim.circuit.components.atoms import Component, PortIn, PortWire | ||
|
||
|
||
class MemStdOut(Component): | ||
def __init__(self, circuit, address=0x8000): | ||
super().__init__(circuit, "MemStdOut") | ||
self._address = address | ||
self.add_port(PortIn(self, "clk")) | ||
self.add_port(PortWire(self, "Address", width=16)) | ||
self.add_port(PortWire(self, "DataIn", width=8)) | ||
self.add_port(PortWire(self, "WE")) | ||
self._str = "" | ||
|
||
def update(self): | ||
if self.WE.value == 0 or self.Address.value != self._address: | ||
return | ||
if self.clk.is_rising_edge(): | ||
datain = self.DataIn.value | ||
if datain == 0x0A: | ||
print(f"StringOutput [line]: '{self._str}'") | ||
self._str = "" | ||
else: | ||
inchar = chr(datain) | ||
print(f"StringOutput [char]: '{inchar}'") | ||
self._str += inchar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters