sm-blueprint-lib 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sm_blueprint_lib/__init__.py +138 -0
- sm_blueprint_lib/bases/controllers/basecontroller.py +20 -0
- sm_blueprint_lib/bases/controllers/baselogiccontroller.py +10 -0
- sm_blueprint_lib/bases/controllers/logicgatecontroller.py +10 -0
- sm_blueprint_lib/bases/controllers/sensorcontroller.py +24 -0
- sm_blueprint_lib/bases/controllers/timercontroller.py +11 -0
- sm_blueprint_lib/blueprint.py +31 -0
- sm_blueprint_lib/body.py +13 -0
- sm_blueprint_lib/bounds.py +10 -0
- sm_blueprint_lib/constants.py +29 -0
- sm_blueprint_lib/id.py +5 -0
- sm_blueprint_lib/pos.py +16 -0
- sm_blueprint_lib/prebuilds/adder.py +44 -0
- sm_blueprint_lib/prebuilds/barrel_shifter.py +86 -0
- sm_blueprint_lib/prebuilds/clock40hz.py +28 -0
- sm_blueprint_lib/prebuilds/comparator.py +70 -0
- sm_blueprint_lib/prebuilds/counter.py +68 -0
- sm_blueprint_lib/prebuilds/decoder.py +56 -0
- sm_blueprint_lib/prebuilds/distance_sensor.py +45 -0
- sm_blueprint_lib/prebuilds/ram.py +90 -0
- sm_blueprint_lib/prebuilds/register.py +72 -0
- sm_blueprint_lib/prebuilds/rom.py +76 -0
- sm_blueprint_lib/prebuilds/timer_ram_cached.py +386 -0
- sm_blueprint_lib/prebuilds/timer_ram_multiclient.py +85 -0
- sm_blueprint_lib-0.0.1.dist-info/METADATA +16 -0
- sm_blueprint_lib-0.0.1.dist-info/RECORD +28 -0
- sm_blueprint_lib-0.0.1.dist-info/WHEEL +4 -0
- sm_blueprint_lib-0.0.1.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,386 @@
|
|
1
|
+
from itertools import cycle
|
2
|
+
from typing import Sequence
|
3
|
+
from numpy import array, clip, ndarray
|
4
|
+
from sm_blueprint_lib import get_bits_required, check_pos, connect, num_to_bit_list
|
5
|
+
from sm_blueprint_lib.bases.parts.baseinteractablepart import BaseInteractablePart
|
6
|
+
from sm_blueprint_lib.bases.parts.baselogicpart import BaseLogicPart
|
7
|
+
from sm_blueprint_lib.blueprint import Blueprint
|
8
|
+
from sm_blueprint_lib.constants import TICKS_PER_SECOND
|
9
|
+
from sm_blueprint_lib.parts.logicgate import LogicGate
|
10
|
+
from sm_blueprint_lib.parts.timer import Timer
|
11
|
+
from sm_blueprint_lib.pos import Pos
|
12
|
+
from sm_blueprint_lib.prebuilds.clock40hz import clock40hz
|
13
|
+
from sm_blueprint_lib.prebuilds.counter import counter
|
14
|
+
from sm_blueprint_lib.prebuilds.decoder import decoder
|
15
|
+
from sm_blueprint_lib.prebuilds.ram import ram
|
16
|
+
from sm_blueprint_lib.prebuilds.register import register
|
17
|
+
|
18
|
+
|
19
|
+
def timer_ram_cached(
|
20
|
+
bp: Blueprint,
|
21
|
+
bit_length: int,
|
22
|
+
num_address_per_cache: int,
|
23
|
+
num_caches: int,
|
24
|
+
num_timer_banks: int,
|
25
|
+
num_caches_per_bank: int,
|
26
|
+
pos: Pos | Sequence = (0, 0, 0)):
|
27
|
+
initial_part_count = len(bp.bodies[0].childs)
|
28
|
+
total_bits = bit_length*num_address_per_cache*num_timer_banks*num_caches_per_bank
|
29
|
+
cached_bits = bit_length*num_address_per_cache*num_caches
|
30
|
+
cached_addresses = num_address_per_cache*num_caches
|
31
|
+
banked_addresses = num_address_per_cache*num_timer_banks
|
32
|
+
total_pages = num_timer_banks*num_caches_per_bank
|
33
|
+
|
34
|
+
pos = check_pos(pos)
|
35
|
+
|
36
|
+
clock = clock40hz(
|
37
|
+
bp, get_bits_required(num_caches_per_bank), pos + (-get_bits_required(total_pages) - 5, 7, num_caches))
|
38
|
+
|
39
|
+
cache = ram(bp,
|
40
|
+
bit_length,
|
41
|
+
cached_addresses,
|
42
|
+
pos + (0, 5, 0))
|
43
|
+
cache_arr = ndarray((bit_length, cached_addresses, 4), dtype=LogicGate)
|
44
|
+
cache_full_page_in = ndarray(
|
45
|
+
(bit_length, num_address_per_cache), dtype=LogicGate)
|
46
|
+
cache_full_page_out = ndarray(
|
47
|
+
(bit_length, num_address_per_cache), dtype=LogicGate)
|
48
|
+
|
49
|
+
timer_bank = ndarray(
|
50
|
+
(bit_length, banked_addresses, 5), dtype=BaseLogicPart)
|
51
|
+
|
52
|
+
timer_bank_decoder_read = [LogicGate(
|
53
|
+
pos + (bit_length*3, 8, z), "000000", xaxis=1, zaxis=3) for z in range(banked_addresses)]
|
54
|
+
timer_bank_decoder_read_in = ndarray(
|
55
|
+
(get_bits_required(num_timer_banks), 2), dtype=LogicGate)
|
56
|
+
timer_bank_decoder_read_enable = LogicGate(
|
57
|
+
pos + (bit_length*3, 8, -1), "FF0000", 1, xaxis=1, zaxis=3)
|
58
|
+
|
59
|
+
timer_bank_decoder_write_keep = ndarray(
|
60
|
+
(banked_addresses, 2), dtype=LogicGate)
|
61
|
+
timer_bank_decoder_write_keep_in = ndarray(
|
62
|
+
(get_bits_required(num_timer_banks), 4), dtype=LogicGate)
|
63
|
+
timer_bank_decoder_write_keep_enable = (LogicGate(pos + (bit_length*3, 6, -1), "FF0000", 1, xaxis=1, zaxis=3),
|
64
|
+
LogicGate(pos + (bit_length*3, 6, -2), "FF0000", 1, xaxis=1, zaxis=3))
|
65
|
+
|
66
|
+
cache_pointer = counter(bp, get_bits_required(num_caches),
|
67
|
+
pos + (-get_bits_required(total_pages) - 5, 5, num_caches))
|
68
|
+
|
69
|
+
# cache_table_offset_x = int(
|
70
|
+
# clip(get_bits_required(total_pages) - bit_length + 2, 0, None))
|
71
|
+
cache_table = ram(bp,
|
72
|
+
bit_length=get_bits_required(total_pages) + 2,
|
73
|
+
num_address=num_caches,
|
74
|
+
# pos=pos + (-cache_table_offset_x, 5, cached_addresses+2))
|
75
|
+
pos=pos + (-get_bits_required(total_pages) - 5, 5, 0))
|
76
|
+
|
77
|
+
cache_table_lookup = ndarray(
|
78
|
+
(get_bits_required(total_pages), num_caches), dtype=LogicGate)
|
79
|
+
cache_table_lookup_in = [LogicGate(pos + (x-get_bits_required(total_pages) - 5, 4, -1),
|
80
|
+
"ff0000", 1, xaxis=1, zaxis=3) for x in range(get_bits_required(total_pages))]
|
81
|
+
cache_table_lookup_out = array([LogicGate(pos + (x-get_bits_required(total_pages) - 5, 4, -2),
|
82
|
+
"0000ff", 1, xaxis=1, zaxis=3) for x in range(get_bits_required(num_caches)+1)], dtype=LogicGate)
|
83
|
+
cache_table_lookup_dec = [LogicGate(pos + (-get_bits_required(
|
84
|
+
total_pages) - 6, 4, z), "000000", xaxis=1, zaxis=3) for z in range(num_caches)]
|
85
|
+
|
86
|
+
for x in range(bit_length):
|
87
|
+
for y in range(cached_addresses):
|
88
|
+
cache_arr[x, y, :] = [
|
89
|
+
LogicGate(pos + (x, 3, y), "000000"),
|
90
|
+
LogicGate(pos + (x, 4, y), "FF0000", 2),
|
91
|
+
LogicGate(pos + (x, 5, y), "000000"),
|
92
|
+
cache[0][x, y, 3]
|
93
|
+
]
|
94
|
+
for y in range(num_address_per_cache):
|
95
|
+
cache_full_page_in[x, y] = LogicGate(
|
96
|
+
pos + (x, 2, y+1), "FF0000", 1, xaxis=1, zaxis=-3)
|
97
|
+
cache_full_page_out[x, y] = LogicGate(
|
98
|
+
pos + (x, 2, y+num_address_per_cache+1), "0000FF", 1, xaxis=1, zaxis=-3)
|
99
|
+
for x in range(bit_length):
|
100
|
+
for y in range(banked_addresses):
|
101
|
+
timer_bank[x, y, :] = [
|
102
|
+
LogicGate(pos + (x*2 + bit_length, 7, y), "FF0000"),
|
103
|
+
LogicGate(pos + (x*2 + bit_length+1, 7, y), "0000FF"),
|
104
|
+
LogicGate(pos + (x*2 + bit_length, 8, y), "000000"),
|
105
|
+
LogicGate(pos + (x*2 + bit_length+1, 8, y), "000000", 1),
|
106
|
+
Timer(pos + (x*2 + bit_length, 9, y+1), "0000FF",
|
107
|
+
divmod(num_caches_per_bank-3, TICKS_PER_SECOND), xaxis=-3, zaxis=-2)
|
108
|
+
]
|
109
|
+
for x in range(get_bits_required(num_timer_banks)):
|
110
|
+
timer_bank_decoder_read_in[x, :] = [
|
111
|
+
LogicGate(pos + (bit_length*3+1, 8, x),
|
112
|
+
"FF0000", 4, xaxis=1, zaxis=3),
|
113
|
+
LogicGate(pos + (bit_length*3+2, 8, x),
|
114
|
+
"FF0000", 1, xaxis=1, zaxis=3),
|
115
|
+
]
|
116
|
+
timer_bank_decoder_write_keep_in[x, :] = [
|
117
|
+
LogicGate(pos + (bit_length*3+2, 6, x),
|
118
|
+
"FF0000", 4, xaxis=1, zaxis=3),
|
119
|
+
LogicGate(pos + (bit_length*3+3, 6, x),
|
120
|
+
"FF0000", 1, xaxis=1, zaxis=3),
|
121
|
+
LogicGate(pos + (bit_length*3+4, 6, x),
|
122
|
+
"FF0000", 4, xaxis=1, zaxis=3),
|
123
|
+
LogicGate(pos + (bit_length*3+5, 6, x),
|
124
|
+
"FF0000", 1, xaxis=1, zaxis=3),
|
125
|
+
]
|
126
|
+
for z in range(banked_addresses):
|
127
|
+
timer_bank_decoder_write_keep[z, :] = [
|
128
|
+
LogicGate(pos + (bit_length*3, 6, z), "000000", xaxis=1, zaxis=3),
|
129
|
+
LogicGate(pos + (bit_length*3+1, 6, z),
|
130
|
+
"000000", 3, xaxis=1, zaxis=3),
|
131
|
+
]
|
132
|
+
for x in range(get_bits_required(total_pages)):
|
133
|
+
for z in range(num_caches):
|
134
|
+
cache_table_lookup[x, z] = LogicGate(
|
135
|
+
pos + (x-get_bits_required(total_pages) - 5, 5, z+1), "000000", 5, xaxis=1, zaxis=-3)
|
136
|
+
|
137
|
+
connect(timer_bank[:, :, 4], timer_bank[:, :, 2])
|
138
|
+
connect(timer_bank[:, :, 2], timer_bank[:, :, 3])
|
139
|
+
connect(timer_bank[:, :, 3], timer_bank[:, :, 4])
|
140
|
+
connect(timer_bank[:, :, 4], timer_bank[:, :, 1])
|
141
|
+
connect(timer_bank[:, :, 0], timer_bank[:, :, 3])
|
142
|
+
|
143
|
+
decoder(bp, banked_addresses,
|
144
|
+
precreated_outputs=timer_bank_decoder_read,
|
145
|
+
precreated_inputs_binary=timer_bank_decoder_read_in,
|
146
|
+
precreated_output_enable=timer_bank_decoder_read_enable,
|
147
|
+
address_divisor=num_address_per_cache)
|
148
|
+
|
149
|
+
decoder(bp, banked_addresses,
|
150
|
+
precreated_outputs=timer_bank_decoder_write_keep[:, 0],
|
151
|
+
precreated_inputs_binary=timer_bank_decoder_write_keep_in[:, :2],
|
152
|
+
precreated_output_enable=timer_bank_decoder_write_keep_enable[0],
|
153
|
+
address_divisor=num_address_per_cache)
|
154
|
+
|
155
|
+
decoder(bp, banked_addresses,
|
156
|
+
precreated_outputs=timer_bank_decoder_write_keep[:, 1],
|
157
|
+
precreated_inputs_binary=timer_bank_decoder_write_keep_in[:, 2:],
|
158
|
+
precreated_output_enable=timer_bank_decoder_write_keep_enable[1],
|
159
|
+
address_divisor=num_address_per_cache)
|
160
|
+
|
161
|
+
connect(timer_bank_decoder_read, timer_bank[:, :, 1].T)
|
162
|
+
connect(timer_bank_decoder_write_keep[:, 0], timer_bank[:, :, 0].T)
|
163
|
+
connect(timer_bank_decoder_write_keep[:, 1], timer_bank[:, :, 2].T)
|
164
|
+
|
165
|
+
for t, c in zip(timer_bank[:, :, 1].T, cycle(cache_full_page_in.T)):
|
166
|
+
connect(t, c)
|
167
|
+
|
168
|
+
for c, t in zip(cycle(cache_full_page_out.T), timer_bank[:, :, 0].T):
|
169
|
+
connect(c, t)
|
170
|
+
|
171
|
+
connect(cache_table[0][:, :, -1], cache_table_lookup)
|
172
|
+
connect(cache_table[0][-2, :, -1], cache_table_lookup_dec)
|
173
|
+
connect(cache_table_lookup_in, cache_table_lookup)
|
174
|
+
connect(cache_table_lookup.T, cache_table_lookup_dec)
|
175
|
+
connect(cache_table_lookup_dec, cache_table_lookup_out[-1])
|
176
|
+
for x in range(num_caches):
|
177
|
+
bit_mask = num_to_bit_list(
|
178
|
+
x, get_bits_required(num_caches)+1)
|
179
|
+
connect(cache_table_lookup_dec[x], cache_table_lookup_out[bit_mask])
|
180
|
+
|
181
|
+
ram(bp,
|
182
|
+
bit_length=bit_length*num_address_per_cache,
|
183
|
+
num_address=cached_addresses,
|
184
|
+
pos=pos + (0, 1, 0),
|
185
|
+
address_divisor=num_address_per_cache,
|
186
|
+
pre_arr=cache_arr,
|
187
|
+
pre_inputs=cache_full_page_in.T.flat,
|
188
|
+
pre_outputs=cache_full_page_out.T.flat)
|
189
|
+
|
190
|
+
control_pos = pos+(0, 15, 0)
|
191
|
+
data_register = register(bp, bit_length=bit_length, pos=control_pos)
|
192
|
+
address_register = register(
|
193
|
+
bp, bit_length=get_bits_required(total_bits//bit_length), pos=control_pos+(bit_length+1, 0, 0))
|
194
|
+
read_write_register = register(
|
195
|
+
bp, bit_length=1, pos=control_pos+(bit_length+get_bits_required(total_bits//bit_length)+2, 0, 0))
|
196
|
+
execute = LogicGate(pos=control_pos+(bit_length+get_bits_required(total_bits//bit_length)+3, 3, 0),
|
197
|
+
color="FF0000",
|
198
|
+
controller=1)
|
199
|
+
execution_done = LogicGate(pos=control_pos+(bit_length+get_bits_required(total_bits//bit_length)+4, 3, 0),
|
200
|
+
color="0000FF",
|
201
|
+
controller=1)
|
202
|
+
|
203
|
+
address_comparator = [
|
204
|
+
# cache_table
|
205
|
+
[LogicGate(pos + (-get_bits_required(total_pages) - 5 + x, 8, num_caches),
|
206
|
+
"000000",
|
207
|
+
5, xaxis=1, zaxis=3) for x in range(get_bits_required(num_caches_per_bank))],
|
208
|
+
LogicGate(pos + (-get_bits_required(total_pages) - 5, 8, num_caches+1),
|
209
|
+
"000000", 0, xaxis=1, zaxis=3),
|
210
|
+
]
|
211
|
+
connect(address_comparator[0], address_comparator[1])
|
212
|
+
connect(clock[:, 0], address_comparator[0])
|
213
|
+
connect(cache_table[2], address_comparator[0])
|
214
|
+
|
215
|
+
row_start = control_pos+(-1, -1, 0)
|
216
|
+
|
217
|
+
selectors = [
|
218
|
+
[LogicGate(row_start+(x,5,0), "000000") for x in range(get_bits_required(total_pages))],
|
219
|
+
[Timer(row_start+(x,6,0), "000000", (0,2)) for x in range(get_bits_required(total_pages))],
|
220
|
+
[LogicGate(row_start+(x,7,0), "000000") for x in range(get_bits_required(total_pages))],
|
221
|
+
[LogicGate(row_start+(x,8,0), "000000") for x in range(get_bits_required(num_caches))],
|
222
|
+
# [Timer(row_start+(x,6,0), "000000", (0,0)) for x in range(get_bits_required(num_caches))],
|
223
|
+
# [LogicGate(row_start+(x,7,0), "000000") for x in range(get_bits_required(num_caches))],
|
224
|
+
]
|
225
|
+
connect(address_register[0][::-1, 1], selectors[0][::-1])
|
226
|
+
connect(selectors[0], cache_table[1])
|
227
|
+
connect(cache_table[2], selectors[1])
|
228
|
+
connect(selectors[1], selectors[2])
|
229
|
+
connect(selectors[2], cache_table[1])
|
230
|
+
connect(cache_table_lookup_out, selectors[3])
|
231
|
+
connect(selectors[3], cache_table[3])
|
232
|
+
|
233
|
+
connect(address_register[0][::-1, 1], cache_table_lookup_in[::-1])
|
234
|
+
connect(cache_table_lookup_out[-2::-1], cache[3][::-1])
|
235
|
+
connect(cache_table_lookup_out[-2::-1], cache[6][::-1])
|
236
|
+
connect(address_register[0][:get_bits_required(
|
237
|
+
num_address_per_cache), 1], cache[3])
|
238
|
+
connect(address_register[0][:get_bits_required(
|
239
|
+
num_address_per_cache), 1], cache[6])
|
240
|
+
connect(cache[2], data_register[0][:, -1])
|
241
|
+
connect(data_register[0][:, 1], cache[1])
|
242
|
+
connect(address_register[0][get_bits_required(
|
243
|
+
num_address_per_cache):, 1], cache_table[1])
|
244
|
+
# connect(cache_table_lookup_out, cache_table[3])
|
245
|
+
connect(cache_pointer[0][:, 0], cache_table[6])
|
246
|
+
|
247
|
+
def NODE(t=0, x=0, y=0, z=0, _from=[], _to=[]):
|
248
|
+
if t == 6:
|
249
|
+
g = LogicGate(row_start+(-x, y, z), "000000", 2, xaxis=-1, zaxis=2)
|
250
|
+
connect(g, g)
|
251
|
+
else:
|
252
|
+
g = LogicGate(row_start+(-x, y, z), "000000", t, xaxis=-1, zaxis=2)
|
253
|
+
connect(_from, g)
|
254
|
+
connect(g, _to)
|
255
|
+
bp.add(g)
|
256
|
+
return g
|
257
|
+
|
258
|
+
g0 = NODE(x=0, _from=execute)
|
259
|
+
g1 = NODE(x=1, _from=g0, )
|
260
|
+
g2 = NODE(x=2, _from=g1, )
|
261
|
+
g3 = NODE(x=3, _from=g2, )
|
262
|
+
g4 = NODE(x=4, _from=g3, )
|
263
|
+
g5 = NODE(x=5, _from=g4, )
|
264
|
+
# If (page loaded)
|
265
|
+
g6 = NODE(x=6, _from=(g5), )
|
266
|
+
g7 = NODE(x=6, y=1, _from=(cache_table_lookup_out[-1]), )
|
267
|
+
g8 = NODE(x=6, y=2, t=3, _from=(cache_table_lookup_out[-1]), )
|
268
|
+
# Then:
|
269
|
+
g9 = NODE(x=7, _from=(g6, g7), )
|
270
|
+
# If (read mode)
|
271
|
+
g10 = NODE(x=8, t=1, _from=(g9), _to=(
|
272
|
+
cache_table[1][-1], cache_table[1][-2], cache_table[5]))
|
273
|
+
g11 = NODE(x=8, y=1, _from=(read_write_register[0][:, 1]), )
|
274
|
+
g12 = NODE(x=8, y=2, t=3, _from=(read_write_register[0][:, 1]), )
|
275
|
+
# Then:
|
276
|
+
g13 = NODE(x=9, _from=(g10, g11), _to=(cache[8]))
|
277
|
+
g14 = NODE(x=10, _from=(g13))
|
278
|
+
g15 = NODE(x=11, _from=(g14))
|
279
|
+
g16 = NODE(x=12, _from=(g15))
|
280
|
+
g17 = NODE(x=13, _from=(g16), _to=(data_register[1], execution_done))
|
281
|
+
# Else:
|
282
|
+
g18 = NODE(x=9, y=2, _from=(g10, g12), _to=(cache[5], execution_done))
|
283
|
+
# Else:
|
284
|
+
g19 = NODE(x=6, y=3, _from=(g6, g8))
|
285
|
+
# g20 = NODE(x=6, y=4, t=1, _from=(g19), _to=(cache_table[8]))
|
286
|
+
# g21 = NODE(x=7, y=4, _from=(g20))
|
287
|
+
# g22 = NODE(x=8, y=4, _from=(g21))
|
288
|
+
# g23 = NODE(x=9, y=4, _from=(g22))
|
289
|
+
# g24 = NODE(x=10, y=4, _from=(g23))
|
290
|
+
# # If (Invalid page)
|
291
|
+
# g25 = NODE(x=11, y=4, _from=(g24))
|
292
|
+
# g26 = NODE(x=11, y=5, _from=(cache_table[2][-2]))
|
293
|
+
# g27 = NODE(x=11, y=6, t=3, _from=(cache_table[2][-2]))
|
294
|
+
# # Then:
|
295
|
+
# g28 = NODE(x=12, y=4, _from=(g25, g27), _to=(selectors[0]))
|
296
|
+
# g29 = NODE(x=13, y=4, _from=(g28), _to=(
|
297
|
+
# cache_table[1][-1], cache_table[1][-2], cache_table[5]))
|
298
|
+
# g30 = NODE(x=14, y=4, _from=(g29))
|
299
|
+
# g30_1 = NODE(x=15, y=4, _from=(g30), _to=(g10))
|
300
|
+
# # Else:
|
301
|
+
# # If (Visited bit set)
|
302
|
+
# g31 = NODE(x=12, y=6, _from=(g25, g26))
|
303
|
+
# g31_1 = NODE(x=11, y=8, _from=(cache_table[2][-1]))
|
304
|
+
# g32 = NODE(x=12, y=7, _from=(g31_1))
|
305
|
+
# g33 = NODE(x=12, y=8, t=3, _from=(g31_1))
|
306
|
+
# # Then:
|
307
|
+
# g34 = NODE(x=13, y=6, _from=(g31, g32), _to=(selectors[2], cache_pointer[1]))
|
308
|
+
# g35 = NODE(x=14, y=6, _from=(g34), _to=(cache_table[1][-2], cache_table[5]))
|
309
|
+
|
310
|
+
|
311
|
+
bp.add(cache_arr[:, :, :3], cache_full_page_in, cache_full_page_out,
|
312
|
+
timer_bank, timer_bank_decoder_read, timer_bank_decoder_read_in, timer_bank_decoder_read_enable,
|
313
|
+
timer_bank_decoder_write_keep, timer_bank_decoder_write_keep_in, timer_bank_decoder_write_keep_enable,
|
314
|
+
cache_table_lookup, cache_table_lookup_in, cache_table_lookup_out, cache_table_lookup_dec,
|
315
|
+
execute, execution_done, address_comparator, selectors)
|
316
|
+
|
317
|
+
print(
|
318
|
+
f"Total memory: {total_bits/8} bytes, "
|
319
|
+
f"Cached memory: {cached_bits/8} bytes, ")
|
320
|
+
|
321
|
+
# timers = ndarray((bit_length, 3), dtype=object)
|
322
|
+
# timer_read_write_enable = LogicGate(pos + (-1, 1, 0), "FF0000", 4)
|
323
|
+
# for x in range(bit_length):
|
324
|
+
# # timers[x] = [
|
325
|
+
# # t0 := Timer(pos + (x % 8, 0, 2*(x//8)), "000000", ((num_address-3) // 40, (num_address-3) % 40)),
|
326
|
+
# # l0 := LogicGate(pos + (x % 8, 1, 2*(x//8)), "000000"),
|
327
|
+
# # l1 := LogicGate(pos + (x % 8, 1, 2*(x//8)+1), "000000", 1),
|
328
|
+
# # ]
|
329
|
+
# timers[x] = [
|
330
|
+
# t0 := Timer(pos + (x, 0, 0), "000000", ((num_address_per_cache-3) // 40, (num_address_per_cache-3) % 40)),
|
331
|
+
# l0 := LogicGate(pos + (x, 1, 0), "000000"),
|
332
|
+
# l1 := LogicGate(pos + (x, 1, 1), "000000", 1),
|
333
|
+
# ]
|
334
|
+
# t0.connect(l0).connect(l1).connect(t0)
|
335
|
+
# connect(timer_read_write_enable, timers[:, 1])
|
336
|
+
|
337
|
+
# for z in range(num_caches):
|
338
|
+
# cpos = pos + (0, 0, z*2)
|
339
|
+
# data = register(bp, bit_length, pos=cpos + (0, 4, 0))
|
340
|
+
# timers_readers = [LogicGate(cpos+(x, 3, 0), "000000")
|
341
|
+
# for x in range(bit_length)]
|
342
|
+
# timers_readers_enable = LogicGate(cpos+(-1, 3, 0), "FF0000", 1)
|
343
|
+
# timers_readers_buffer = LogicGate(cpos+(-1, 5, 0), "000000")
|
344
|
+
# address = register(bp, get_bits_required(
|
345
|
+
# num_address_per_cache), pos=cpos + (bit_length+1, 5, 0), OE=False)
|
346
|
+
# post_rw = register(bp, 2,
|
347
|
+
# pos=cpos + (bit_length+1+get_bits_required(num_address_per_cache)+1, 5, 0), OE=False)
|
348
|
+
# rw_inv = [
|
349
|
+
# LogicGate(
|
350
|
+
# cpos + (bit_length+1+get_bits_required(num_address_per_cache)+1, 4, 0), "000000", 3),
|
351
|
+
# LogicGate(
|
352
|
+
# cpos + (bit_length+1+get_bits_required(num_address_per_cache)+2, 4, 0), "000000")
|
353
|
+
# ]
|
354
|
+
# comparator = [LogicGate(cpos+(x+bit_length+1, 4, 0), "000000", 5)
|
355
|
+
# for x in range(get_bits_required(num_address_per_cache))]
|
356
|
+
# comparator_write = LogicGate(cpos+(bit_length+1, 3, 0), "000000")
|
357
|
+
# comparator_read = LogicGate(cpos+(bit_length+2, 3, 0), "000000")
|
358
|
+
# connect(post_rw[0][0, 0], rw_inv)
|
359
|
+
# connect(address[0][:, 0], comparator)
|
360
|
+
# connect(clock[:, 0], comparator)
|
361
|
+
# connect(comparator, comparator_write)
|
362
|
+
# connect(comparator, comparator_read)
|
363
|
+
# connect(rw_inv[0], comparator_write)
|
364
|
+
# connect(rw_inv[1], comparator_read)
|
365
|
+
# connect(post_rw[0][1, 0], comparator_write)
|
366
|
+
# connect(post_rw[0][1, 0], comparator_read)
|
367
|
+
# connect(comparator_write, timer_read_write_enable)
|
368
|
+
# connect(comparator_write, data[2])
|
369
|
+
# connect(data[0][:, 0], timers[:, 2])
|
370
|
+
# connect(comparator_write, post_rw[1])
|
371
|
+
# connect(comparator_read, post_rw[1])
|
372
|
+
# connect(comparator_read, timers_readers_enable)
|
373
|
+
# connect(timers_readers_enable, timers_readers_buffer)
|
374
|
+
# connect(timers_readers_buffer, data[1])
|
375
|
+
# connect(timers_readers_enable, timers_readers)
|
376
|
+
# connect(timers[:, 0], timers_readers)
|
377
|
+
# connect(timers_readers, data[0][:, 3])
|
378
|
+
# bp.add(comparator, comparator_write, comparator_read, rw_inv,
|
379
|
+
# timers_readers, timers_readers_enable, timers_readers_buffer)
|
380
|
+
|
381
|
+
# bp.add(timers, timer_read_write_enable)
|
382
|
+
|
383
|
+
# print(f"Timer ram: {bit_length*num_address_per_cache} bits ({bit_length*num_address_per_cache/8} bytes), "
|
384
|
+
# f"Max time delay: {
|
385
|
+
# num_address_per_cache} ticks ({num_address_per_cache/40} seconds), "
|
386
|
+
# f"Bits per part: {bit_length*num_address_per_cache / (len(bp.bodies[0].childs)-initial_part_count):.2f} bits/part")
|
@@ -0,0 +1,85 @@
|
|
1
|
+
from typing import Sequence
|
2
|
+
from numpy import ndarray
|
3
|
+
from sm_blueprint_lib import get_bits_required, check_pos, connect
|
4
|
+
from sm_blueprint_lib.blueprint import Blueprint
|
5
|
+
from sm_blueprint_lib.parts.logicgate import LogicGate
|
6
|
+
from sm_blueprint_lib.parts.timer import Timer
|
7
|
+
from sm_blueprint_lib.pos import Pos
|
8
|
+
from sm_blueprint_lib.prebuilds.clock40hz import clock40hz
|
9
|
+
from sm_blueprint_lib.prebuilds.decoder import decoder
|
10
|
+
from sm_blueprint_lib.prebuilds.ram import ram
|
11
|
+
from sm_blueprint_lib.prebuilds.register import register
|
12
|
+
|
13
|
+
|
14
|
+
def timer_ram_multiclient(bp: Blueprint, bit_length: int, num_address: int, num_clients=1, pos: Pos | Sequence = (0, 0, 0)):
|
15
|
+
initial_part_count = len(bp.bodies[0].childs)
|
16
|
+
pos = check_pos(pos)
|
17
|
+
|
18
|
+
clock = clock40hz(
|
19
|
+
bp, get_bits_required(num_address), pos + (bit_length, 0, 0))
|
20
|
+
|
21
|
+
timers = ndarray((bit_length, 3), dtype=object)
|
22
|
+
timer_read_write_enable = LogicGate(pos + (-1, 1, 0), "FF0000", 4)
|
23
|
+
for x in range(bit_length):
|
24
|
+
# timers[x] = [
|
25
|
+
# t0 := Timer(pos + (x % 8, 0, 2*(x//8)), "000000", ((num_address-3) // 40, (num_address-3) % 40)),
|
26
|
+
# l0 := LogicGate(pos + (x % 8, 1, 2*(x//8)), "000000"),
|
27
|
+
# l1 := LogicGate(pos + (x % 8, 1, 2*(x//8)+1), "000000", 1),
|
28
|
+
# ]
|
29
|
+
timers[x] = [
|
30
|
+
t0 := Timer(pos + (x, 0, 0), "000000", ((num_address-3) // 40, (num_address-3) % 40)),
|
31
|
+
l0 := LogicGate(pos + (x, 1, 0), "000000"),
|
32
|
+
l1 := LogicGate(pos + (x, 1, 1), "000000", 1),
|
33
|
+
]
|
34
|
+
t0.connect(l0).connect(l1).connect(t0)
|
35
|
+
connect(timer_read_write_enable, timers[:, 1])
|
36
|
+
|
37
|
+
for z in range(num_clients):
|
38
|
+
cpos = pos + (0, 0, z*2)
|
39
|
+
data = register(bp, bit_length, pos=cpos + (0, 4, 0))
|
40
|
+
timers_readers = [LogicGate(cpos+(x, 3, 0), "000000")
|
41
|
+
for x in range(bit_length)]
|
42
|
+
timers_readers_enable = LogicGate(cpos+(-1, 3, 0), "FF0000", 1)
|
43
|
+
timers_readers_buffer = LogicGate(cpos+(-1, 5, 0), "000000")
|
44
|
+
address = register(bp, get_bits_required(
|
45
|
+
num_address), pos=cpos + (bit_length+1, 5, 0), OE=False)
|
46
|
+
post_rw = register(bp, 2,
|
47
|
+
pos=cpos + (bit_length+1+get_bits_required(num_address)+1, 5, 0), OE=False)
|
48
|
+
rw_inv = [
|
49
|
+
LogicGate(
|
50
|
+
cpos + (bit_length+1+get_bits_required(num_address)+1, 4, 0), "000000", 3),
|
51
|
+
LogicGate(
|
52
|
+
cpos + (bit_length+1+get_bits_required(num_address)+2, 4, 0), "000000")
|
53
|
+
]
|
54
|
+
comparator = [LogicGate(cpos+(x+bit_length+1, 4, 0), "000000", 5)
|
55
|
+
for x in range(get_bits_required(num_address))]
|
56
|
+
comparator_write = LogicGate(cpos+(bit_length+1, 3, 0), "000000")
|
57
|
+
comparator_read = LogicGate(cpos+(bit_length+2, 3, 0), "000000")
|
58
|
+
connect(post_rw[0][0, 0], rw_inv)
|
59
|
+
connect(address[0][:, 0], comparator)
|
60
|
+
connect(clock[:, 0], comparator)
|
61
|
+
connect(comparator, comparator_write)
|
62
|
+
connect(comparator, comparator_read)
|
63
|
+
connect(rw_inv[0], comparator_write)
|
64
|
+
connect(rw_inv[1], comparator_read)
|
65
|
+
connect(post_rw[0][1, 0], comparator_write)
|
66
|
+
connect(post_rw[0][1, 0], comparator_read)
|
67
|
+
connect(comparator_write, timer_read_write_enable)
|
68
|
+
connect(comparator_write, data[2])
|
69
|
+
connect(data[0][:, 0], timers[:, 2])
|
70
|
+
connect(comparator_write, post_rw[1])
|
71
|
+
connect(comparator_read, post_rw[1])
|
72
|
+
connect(comparator_read, timers_readers_enable)
|
73
|
+
connect(timers_readers_enable, timers_readers_buffer)
|
74
|
+
connect(timers_readers_buffer, data[1])
|
75
|
+
connect(timers_readers_enable, timers_readers)
|
76
|
+
connect(timers[:, 0], timers_readers)
|
77
|
+
connect(timers_readers, data[0][:, 3])
|
78
|
+
bp.add(comparator, comparator_write, comparator_read, rw_inv,
|
79
|
+
timers_readers, timers_readers_enable, timers_readers_buffer)
|
80
|
+
|
81
|
+
bp.add(timers, timer_read_write_enable)
|
82
|
+
|
83
|
+
print(f"Timer ram: {bit_length*num_address} bits ({bit_length*num_address/8} bytes), "
|
84
|
+
f"Max time delay: {num_address} ticks ({num_address/40} seconds), "
|
85
|
+
f"Bits per part: {bit_length*num_address / (len(bp.bodies[0].childs)-initial_part_count):.2f} bits/part")
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: sm_blueprint_lib
|
3
|
+
Version: 0.0.1
|
4
|
+
Summary: Scrap Mechanic Library for Blueprint manipulation.
|
5
|
+
Project-URL: Homepage, https://github.com/pypa/sampleproject
|
6
|
+
Project-URL: Issues, https://github.com/pypa/sampleproject/issues
|
7
|
+
Author-email: Maurice <mauriciotorrez00@gmail.com>
|
8
|
+
License-Expression: MIT
|
9
|
+
License-File: LICENSE
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
12
|
+
Requires-Python: >=3.8
|
13
|
+
Description-Content-Type: text/markdown
|
14
|
+
|
15
|
+
# sm_blueprint_lib
|
16
|
+
Scrap Mechanic Library for Blueprint manipulation.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
sm_blueprint_lib/__init__.py,sha256=9ktxwUvthBopqAAg6vPnLAwiOP97nnLpPcH2wY-weG0,4915
|
2
|
+
sm_blueprint_lib/blueprint.py,sha256=foTUnSeMMcpfTKL-NnhkYE9vUX8QqG5qndTDVnaJ8Ps,1128
|
3
|
+
sm_blueprint_lib/body.py,sha256=6Daa4mjUwrBYQjowTbDozEWsESVTtkhqW4441TwZJDM,397
|
4
|
+
sm_blueprint_lib/bounds.py,sha256=fH-i8PdlZVg8qlEd3FmIf5mbx4RKhdBOFRAe5cSWWiI,183
|
5
|
+
sm_blueprint_lib/constants.py,sha256=mll05HrWLGCETzvQlkDPRMBe5HJLAGn5rRkxs5gJ71E,710
|
6
|
+
sm_blueprint_lib/id.py,sha256=5sBHC8qZJnCaizSBs4KGS1dnZHOSdoq5wkuIpuYNRnw,71
|
7
|
+
sm_blueprint_lib/pos.py,sha256=W0yaIg_nYgRqFwSkHlpd7Tfr69XSVwjTY1DfICHXoDo,411
|
8
|
+
sm_blueprint_lib/bases/controllers/basecontroller.py,sha256=wWz2dMvBzBG9Zn1l_sZf5L-L5lwNRMhNTynFSLC4KPs,652
|
9
|
+
sm_blueprint_lib/bases/controllers/baselogiccontroller.py,sha256=PNQhukaP8jceHs7O3b33xbKalS1Bym8x5T4ZN7XNGyQ,324
|
10
|
+
sm_blueprint_lib/bases/controllers/logicgatecontroller.py,sha256=g-Cla8kvFA77KQkAMbRxfyS_tvjFaIf6GJjOfsQ1FsY,257
|
11
|
+
sm_blueprint_lib/bases/controllers/sensorcontroller.py,sha256=K_nE8RmQSCxXAEiwpWeMSpeZtxXePbn_BDbgkkgMtEM,744
|
12
|
+
sm_blueprint_lib/bases/controllers/timercontroller.py,sha256=q0eusjpJ2EQ82mfxMHJP6ok5QH29eqIUpkzNfGLGsAQ,263
|
13
|
+
sm_blueprint_lib/prebuilds/adder.py,sha256=eWABQFvpuB2hHosMzD2LgJkdn_rLh00Wptc75UR8eT4,1804
|
14
|
+
sm_blueprint_lib/prebuilds/barrel_shifter.py,sha256=soDQWvOCfSNo3G3HXjglIfjte-QCil72SpwQDDDS7UE,3610
|
15
|
+
sm_blueprint_lib/prebuilds/clock40hz.py,sha256=XOEe1pthSGnVznU64itpzUMYCNsAJS-nrNxftgY-vJ0,898
|
16
|
+
sm_blueprint_lib/prebuilds/comparator.py,sha256=FuEz72Bh7G5yKHiuApnaF_mjuW-fwikxgjOUXK2H4UE,2259
|
17
|
+
sm_blueprint_lib/prebuilds/counter.py,sha256=zsfC6UKDH9PPrb9dDcM8G80_-QIPk9wAFYlu4US6eao,2602
|
18
|
+
sm_blueprint_lib/prebuilds/decoder.py,sha256=Ofso078Llj5Wu__9k0E_Q9-rREZu294piifdpA4mqGM,2131
|
19
|
+
sm_blueprint_lib/prebuilds/distance_sensor.py,sha256=RWvaoPYJySkjcrD6gfugho26QxQGc1Ub-Wmox8gUtdI,1821
|
20
|
+
sm_blueprint_lib/prebuilds/ram.py,sha256=YGzalt72H5vYKxcVqNkXLm_VbcoyebGlmRRp8oiTfZM,4281
|
21
|
+
sm_blueprint_lib/prebuilds/register.py,sha256=Y66NazPvjhajMQqBA4dwtdoFAxiwpeHBu8WMqbymUAA,2744
|
22
|
+
sm_blueprint_lib/prebuilds/rom.py,sha256=74rNXxVUCqvdsPhsUW7gLI-f2-jQa4-CWT04uyUAQAE,3784
|
23
|
+
sm_blueprint_lib/prebuilds/timer_ram_cached.py,sha256=EFEQP-fOt9M5U_tM3WdwwPFjr70BzbD_U1Ay4jfCTzo,19246
|
24
|
+
sm_blueprint_lib/prebuilds/timer_ram_multiclient.py,sha256=76domx9N9WelMIxIxTX4i-S66B6wTItOPIlXj1KIYdE,4329
|
25
|
+
sm_blueprint_lib-0.0.1.dist-info/METADATA,sha256=6qqYIYND-jRvLkt4ytFJxgHuTcOMcg2ewVAwWEEonjE,574
|
26
|
+
sm_blueprint_lib-0.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
27
|
+
sm_blueprint_lib-0.0.1.dist-info/licenses/LICENSE,sha256=DWhaodryTSEv07KdWbanCMaEujOXYxnj-IEhmgTkOq0,1084
|
28
|
+
sm_blueprint_lib-0.0.1.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Maurice
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|