Skip to content

Commit 5a3c933

Browse files
committed
Add some comments to the ROT13 example
1 parent fd8739d commit 5a3c933

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

litex/workshop_rot13.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,21 @@
3131
# ROT13 input CSR. Doesn't need to do anything special.
3232
class FomuROT13In(Module, AutoCSR):
3333
def __init__(self):
34+
# 8-Bit CSR (one ASCII character)
3435
self.csr = CSRStorage(8)
3536

3637
# ROT13 output CSR, plus the wiring to automatically create the output from the input CSR.
3738
class FomuROT13Out(Module, AutoCSR):
3839
def __init__(self, rot13_in):
40+
# Set up an 8-bit CSR (one ASCII character)
3941
self.csr = CSRStorage(8)
42+
# There are three cases:
43+
# 1. It's "A" through "M": Add 13, to make the letters "N" through "Z".
44+
# 2. It's "N" through "Z": Remove 13, to make the letters "A" through "M".
45+
# 3. It's something else, so leave it alone.
46+
#
47+
# In all three cases, we want to wire up the "output" signal (self.csr.storage)
48+
# to be equal to something based on the input signal (rot13_in.csr.storage).
4049
self.sync += If( # A-M, a-m
4150
(rot13_in.csr.storage >= ord('A')) & (rot13_in.csr.storage <= ord('M')) | (rot13_in.csr.storage >= ord('a')) & (rot13_in.csr.storage <= ord('m')),
4251
self.csr.storage.eq(rot13_in.csr.storage + 13)

0 commit comments

Comments
 (0)