-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
374 lines (296 loc) · 17.2 KB
/
demo.py
File metadata and controls
374 lines (296 loc) · 17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#!/usr/bin/env python3
"""
FLYNNCONCEIVABLE! - The Neural Network That Became a CPU
A FLYNNCOMM, LLC Production
Live Demo - Watch neural networks compute a real CPU!
"""
import sys
import time
sys.path.insert(0, '.')
from flynnconceivable.cpu import CPU
def banner():
print("""
╔═══════════════════════════════════════════════════════════════════════════════╗
║ ║
║ ███████╗██╗ ██╗ ██╗███╗ ██╗███╗ ██╗ ██████╗ ██████╗ ███╗ ██╗ ║
║ ██╔════╝██║ ╚██╗ ██╔╝████╗ ██║████╗ ██║██╔════╝██╔═══██╗████╗ ██║ ║
║ █████╗ ██║ ╚████╔╝ ██╔██╗ ██║██╔██╗ ██║██║ ██║ ██║██╔██╗ ██║ ║
║ ██╔══╝ ██║ ╚██╔╝ ██║╚██╗██║██║╚██╗██║██║ ██║ ██║██║╚██╗██║ ║
║ ██║ ███████╗██║ ██║ ╚████║██║ ╚████║╚██████╗╚██████╔╝██║ ╚████║ ║
║ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ║
║ ║
║ ██████╗███████╗██╗██╗ ██╗ █████╗ ██████╗ ██╗ ███████╗██╗ ║
║ ██╔════╝██╔════╝██║██║ ██║██╔══██╗██╔══██╗██║ ██╔════╝██║ ║
║ ██║ █████╗ ██║██║ ██║███████║██████╔╝██║ █████╗ ██║ ║
║ ██║ ██╔══╝ ██║╚██╗ ██╔╝██╔══██║██╔══██╗██║ ██╔══╝ ╚═╝ ║
║ ╚██████╗███████╗██║ ╚████╔╝ ██║ ██║██████╔╝███████╗███████╗██╗ ║
║ ╚═════╝╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═════╝ ╚══════╝╚══════╝╚═╝ ║
║ ║
║ The Neural Network That Became a CPU ║
║ A FLYNNCOMM, LLC Production ║
║ ║
║ ───────────────────────────────────────────────────────────────────────── ║
║ "You keep using that transformer. ║
║ I do not think it computes what you think it computes." ║
║ ║
║ Yeah, it computes EXACTLY what we think it computes. ║
║ ───────────────────────────────────────────────────────────────────────── ║
║ ║
║ Every computation performed by NEURAL NETWORKS trained to 100% accuracy ║
║ 460,928 input combinations verified - ZERO errors ║
║ ║
╚═══════════════════════════════════════════════════════════════════════════════╝
""")
def demo_addition():
"""Demo 1: Simple addition using Neural ALU"""
print("\n" + "="*70)
print("DEMO 1: NEURAL ADDITION")
print("="*70)
print("\nProgram: LDA #$25, CLC, ADC #$1A (37 + 26)")
print("-"*70)
cpu = CPU(weights_dir='flynnconceivable/weights')
program = [0xA9, 0x25, 0x18, 0x69, 0x1A, 0x00]
cpu.load(program)
print(f"\n Loading 37 into accumulator...")
time.sleep(0.3)
cpu.step()
print(f" A = {cpu.A} (0x{cpu.A:02X})")
print(f"\n Clearing carry flag...")
time.sleep(0.3)
cpu.step()
print(f" C = {cpu.get_flag('C')}")
print(f"\n [NEURAL ALU] Computing 37 + 26...")
time.sleep(0.5)
cpu.step()
print(f" ╔════════════════════════════════════╗")
print(f" ║ 37 + 26 = {cpu.A:3d} ║")
print(f" ║ Neural network computed: 0x{cpu.A:02X} ║")
print(f" ╚════════════════════════════════════╝")
return cpu.A == 63
def demo_logic():
"""Demo 2: Logic operations"""
print("\n" + "="*70)
print("DEMO 2: NEURAL LOGIC OPERATIONS")
print("="*70)
tests = [
("AND", [0xA9, 0xFF, 0x29, 0x0F, 0x00], "0xFF AND 0x0F", 0x0F),
("ORA", [0xA9, 0xF0, 0x09, 0x0F, 0x00], "0xF0 ORA 0x0F", 0xFF),
("EOR", [0xA9, 0xAA, 0x49, 0x55, 0x00], "0xAA EOR 0x55", 0xFF),
]
all_pass = True
for name, prog, desc, expected in tests:
cpu = CPU(weights_dir='flynnconceivable/weights')
cpu.load(prog)
cpu.run()
status = "✓" if cpu.A == expected else "✗"
all_pass &= (cpu.A == expected)
print(f"\n [NEURAL {name}] {desc}")
print(f" Result: 0x{cpu.A:02X} = {bin(cpu.A)} {status}")
time.sleep(0.3)
return all_pass
def demo_shift():
"""Demo 3: Shift operations"""
print("\n" + "="*70)
print("DEMO 3: NEURAL SHIFT OPERATIONS")
print("="*70)
cpu = CPU(weights_dir='flynnconceivable/weights')
print("\n Starting with A = 0x01 (1)")
print(" Shifting left 7 times to create 0x80 (128)...")
print()
program = [0xA9, 0x01]
for _ in range(7):
program.append(0x0A)
program.append(0x00)
cpu.load(program)
cpu.step()
for i in range(7):
old_a = cpu.A
cpu.step()
print(f" ASL: 0x{old_a:02X} << 1 = 0x{cpu.A:02X} ({old_a:3d} -> {cpu.A:3d})")
time.sleep(0.2)
print(f"\n Final: {cpu.A} (expected 128)")
return cpu.A == 128
def demo_fibonacci():
"""Demo 4: Fibonacci sequence"""
print("\n" + "="*70)
print("DEMO 4: FIBONACCI SEQUENCE")
print("="*70)
print("\nComputing Fibonacci using ALL neural organs:")
print(" - ALU for addition")
print(" - INCDEC for loop counter")
print(" - COMPARE for loop termination")
print(" - BRANCH for conditional jumps")
print("-"*70)
cpu = CPU(weights_dir='flynnconceivable/weights')
program = [
0xA9, 0x01, 0x85, 0x00, 0x85, 0x01, 0xA2, 0x0D,
0x18, 0xA5, 0x00, 0x65, 0x01, 0xA8, 0xA5, 0x01,
0x85, 0x00, 0x84, 0x01, 0xCA, 0xD0, 0xF2, 0x00,
]
cpu.load(program)
print("\n Sequence: ", end="", flush=True)
for _ in range(4):
cpu.step()
print("1, 1", end="", flush=True)
iteration = 0
while not cpu.halted and iteration < 13:
for _ in range(9):
cpu.step()
if cpu.halted:
break
if not cpu.halted:
new_val = cpu.memory.read(0x01)
print(f", {new_val}", end="", flush=True)
time.sleep(0.15)
iteration += 1
print("\n")
final = cpu.memory.read(0x01)
print(f" ╔════════════════════════════════════════════════════╗")
print(f" ║ Final Fibonacci value: {final:3d} ║")
print(f" ║ (233 + 144 = 377, wrapped to 121 in 8-bit) ║")
print(f" ║ ║")
print(f" ║ All computed by NEURAL NETWORKS! ║")
print(f" ╚════════════════════════════════════════════════════╝")
return True
def demo_multiply():
"""Demo 5: Multiplication via shifts and adds"""
print("\n" + "="*70)
print("DEMO 5: NEURAL MULTIPLICATION (7 × 13 = 91)")
print("="*70)
print("\nUsing shift-and-add algorithm:")
print(" 13 = 1101 binary = 8 + 4 + 1")
print(" 7 × 13 = 7×8 + 7×4 + 7×1 = 56 + 28 + 7 = 91")
print("-"*70)
cpu = CPU(weights_dir='flynnconceivable/weights')
program = [
0xA9, 0x07, 0x85, 0x00, 0x0A, 0x0A, 0x85, 0x01,
0x0A, 0x18, 0x65, 0x00, 0x65, 0x01, 0x00,
]
cpu.load(program)
print("\n Step 1: Load 7")
cpu.step(); cpu.step()
print(f" A = {cpu.A}, $00 = {cpu.memory.read(0x00)}")
time.sleep(0.3)
print("\n Step 2: Shift left twice (×4)")
cpu.step(); cpu.step()
print(f" 7 × 4 = {cpu.A}")
cpu.step()
time.sleep(0.3)
print("\n Step 3: Shift left once more (×8)")
cpu.step()
print(f" 7 × 8 = {cpu.A}")
time.sleep(0.3)
print("\n Step 4: Add components")
cpu.step()
cpu.step()
print(f" 56 + 7 = {cpu.A}")
cpu.step()
print(f" 63 + 28 = {cpu.A}")
time.sleep(0.3)
print(f"\n ╔════════════════════════════════════╗")
print(f" ║ 7 × 13 = {cpu.A:3d} ║")
print(f" ║ Computed via neural shifts+adds! ║")
print(f" ╚════════════════════════════════════╝")
return cpu.A == 91
def demo_counter():
"""Demo 6: Visual counter"""
print("\n" + "="*70)
print("DEMO 6: COUNTING FROM 0 TO 255")
print("="*70)
print("\nUsing neural INC instruction to count up...")
print("-"*70)
cpu = CPU(weights_dir='flynnconceivable/weights')
program = [
0xA9, 0x00, 0x85, 0x00,
0xE6, 0x00, 0xA5, 0x00, 0xC9, 0x00, 0xD0, 0xF8,
0x00,
]
cpu.load(program)
cpu.step(); cpu.step()
print("\n ", end="")
count = 0
while not cpu.halted and count <= 256:
for _ in range(5):
cpu.step()
if cpu.halted:
break
val = cpu.memory.read(0x00)
if val % 16 == 0 or val == 255:
print(f"[{val:3d}]", end=" ", flush=True)
if val % 64 == 0 and val > 0:
print("\n ", end="")
count += 1
if val == 0 and count > 1:
break
print("\n")
print(f" ╔════════════════════════════════════════════════╗")
print(f" ║ Counted 0→255→0 using NEURAL increment! ║")
print(f" ╚════════════════════════════════════════════════╝")
return True
def summary():
"""Final summary"""
print("""
╔═══════════════════════════════════════════════════════════════════════════════╗
║ ║
║ F L Y N N C O N C E I V A B L E ! C O M P L E T E ║
║ ║
║ ───────────────────────────────────────────────────────────────────────── ║
║ ║
║ A complete 6502 CPU where EVERY computation is performed ║
║ by neural networks trained to 100% accuracy. ║
║ ║
║ NEURAL ORGANS: ║
║ ├── ALU : 131,072 combinations (ADC, SBC) 100% ║
║ ├── SHIFT : 1,536 combinations (ASL/LSR/ROL/ROR) 100% ║
║ ├── LOGIC : 262,144 combinations (AND/ORA/EOR/BIT) 100% ║
║ ├── INCDEC : 512 combinations (INC/DEC) 100% ║
║ ├── COMPARE : 65,536 combinations (CMP/CPX/CPY) 100% ║
║ └── BRANCH : 128 combinations (all branches) 100% ║
║ ║
║ TOTAL: 460,928 verified combinations - ZERO errors ║
║ ║
║ ───────────────────────────────────────────────────────────────────────── ║
║ ║
║ The neural network IS the CPU. ║
║ Not simulating. COMPUTING. ║
║ ║
║ "You keep using that transformer. ║
║ I do not think it computes what you think it computes." ║
║ ║
║ Yeah, it computes EXACTLY what we think it computes. ║
║ ║
║ ───────────────────────────────────────────────────────────────────────── ║
║ TRON (1982) + Princess Bride (1987) + Transformers (2017+) + 6502 (1975) ║
║ ═══════════════════════════════════════════════════════════════════════ ║
║ FLYNNCONCEIVABLE! (2024) ║
║ ───────────────────────────────────────────────────────────────────────── ║
║ ║
║ A FLYNNCOMM, LLC Production ║
║ ║
╚═══════════════════════════════════════════════════════════════════════════════╝
""")
def main():
banner()
time.sleep(1)
results = []
results.append(("Addition", demo_addition()))
results.append(("Logic", demo_logic()))
results.append(("Shift", demo_shift()))
results.append(("Fibonacci", demo_fibonacci()))
results.append(("Multiply", demo_multiply()))
results.append(("Counter", demo_counter()))
summary()
print("\n DEMO RESULTS:")
print(" " + "-"*40)
for name, passed in results:
status = "✓ PASS" if passed else "✗ FAIL"
print(f" {name:20s} {status}")
print(" " + "-"*40)
all_pass = all(r[1] for r in results)
if all_pass:
print("\n ALL DEMOS PASSED!")
print("\n FLYNNCONCEIVABLE! The Grid awaits.")
return all_pass
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)