-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLearnings_December_27th_final.txt
More file actions
688 lines (533 loc) · 32.9 KB
/
Copy pathLearnings_December_27th_final.txt
File metadata and controls
688 lines (533 loc) · 32.9 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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
* ▐▛███▜▌ * Claude Code v2.0.76
* ▝▜█████▛▘ * Opus 4.5 · Claude Max
* ▘▘ ▝▝ * ~/proj-chess
A gift for you
Your rate limits are 2x higher through 12/31. Enjoy the extra room to think!
══════════════════ Conversation compacted · ctrl+o for history ═════════════════
⎿ Referenced file negamax.asm
⎿ Referenced file board-0x88.asm
⎿ Read engine-vh.out (3 lines)
⎿ Read engine-vg.out (3 lines)
⎿ Todo list read (3 items)
● I'll continue with building and testing the fixed version. Let me first check the current version marker and update it to VI, then build.
● Search(pattern: "VERSION_MARKER", path: "negamax.asm", output_mode: "content")
⎿ Found 0 lines
● Search(pattern: "\.DB "V", path: "negamax.asm", output_mode: "content")
⎿ Found 0 lines
● Search(pattern: "V[A-Z]", path: "~/proj-chess", output_mode: "content")
⎿ Found 8867 lines (ctrl+o to expand)
● Let me look for the version in the main file:
● Read(negamax.asm)
⎿ Read 50 lines
● Search(pattern: "VERSION", path: "~/proj-chess", glob: "*.asm", output_mode:
"content")
⎿ Found 45 lines (ctrl+o to expand)
● Read(negamax.asm)
⎿ Read 20 lines
● Update(negamax.asm)
⎿ Added 1 line, removed 1 line
1297 ; Debug: VERSION MARKER - change this to verify new
build is loaded
1298 LDI 'V'
1299 CALL SERIAL_WRITE_CHAR
1300 - LDI 'H'
1300 + LDI 'I'
1301 CALL SERIAL_WRITE_CHAR
1302
1303 ; Debug: entered SEARCH_POSITION
> Not sure why you're setting the stack to your storage register (e.g. "SEX
10"). The STR instruction already stores D directly to the register you're
pointing to, not X.
● You're right - STR 10 stores D to M(R10) regardless of what X is. Let me re-check my code. The reason I used SEX 10 was for the subsequent instructions that DO use X, like XOR, SM, ADD - those read from M(R(X)).
Let me verify my fixes are correct:
● Read(negamax.asm)
⎿ Read 50 lines
● Looking at line 628, XOR reads from M(R(X)), so SEX 10 is needed before it. Same for SM/SMB on lines 638 and 642. The STR 10 doesn't need it, but the subsequent XOR/SM/SMB operations do.
Let me build version VI:
● Bash(./build.sh 2>&1)
⎿ RCA 1802/1806 Chess Engine - Build Script
==========================================
… +73 lines (ctrl+o to expand)
● Build succeeded. Version VI is ready for testing at chess-engine.hex (15974 bytes).
The key fix: All STR 2 scratch usages have been replaced with SEX 10 / STR 10 pattern using COMPARE_TEMP at $6449, preventing stack corruption of the move count.
> Still infinitely looping. I grabbed a good chunk of output into
engine-vi.out
● Read(engine-vi.out)
⎿ Read 28 lines
● Let me analyze the pattern. The move counts are still jumping around: #21, #1F, #21, #1E, #21, #22 (33, 31, 33, 30, 33, 34).
Let me check where the move count is actually stored and popped from the stack:
● Search(pattern: "move.*count|#", path: "negamax.asm", output_mode: "content")
⎿ Found 27 lines (ctrl+o to expand)
● Read(negamax.asm)
⎿ Read 50 lines
● I found it! Look at lines 816-819:
816: IRX ; R2 now points AT move_count
817: LDN 2 ; D = move_count
818: CALL SERIAL_PRINT_HEX ; CALL pushes R6 to stack, overwriting move_count!
819: LDN 2 ; D = garbage (R6.1, not move_count!)
When we do CALL with R2 pointing at move_count, the SCRT CALL sequence pushes R6 linkage onto the stack, overwriting move_count! After RET, R2 is back but the data is corrupted.
The fix: save move_count to R15.0 before the CALL, use that for the decrement:
● Read(negamax.asm)
⎿ Read 20 lines
● Update(negamax.asm)
⎿ Added 7 lines, removed 4 lines
813 ; Debug: show move count before decrement
814 LDI '#'
815 CALL SERIAL_WRITE_CHAR
816 - IRX
816 + IRX ; Point to move_count
817 LDN 2 ; Get move count
818 - CALL SERIAL_PRINT_HEX ; Show count as hex
819 - LDN 2 ; Reload count
818 + PLO 15 ; Save to R15.0 - survives CALL (PLO
+doesn't change D)
819 + CALL SERIAL_PRINT_HEX ; Show count as hex (D still has
+count)
820 + ; CRITICAL: M(R2) was corrupted by CALL pushing R6
+linkage!
821 + ; Use saved value from R15.0 instead of reloading from
+stack
822 + GLO 15 ; Get saved move count
823 SMI 1 ; Decrement
824 BZ NEGAMAX_LOOP_DONE ; If count == 0, exit loop
825 - STR 2 ; Store decremented count back
825 + STR 2 ; Store decremented count back
+ (restores correct value)
826 DEC 2 ; Re-decrement stack pointer
827 LBR NEGAMAX_MOVE_LOOP
828
● Now let me check for other similar issues - any place where we do IRX/INC 2 followed by CALL while R2 points at data:
● Search(pattern: "IRX|INC 2", path: "negamax.asm", output_mode: "content")
⎿ Found 12 lines (ctrl+o to expand)
● Let me check each IRX location for the same pattern:
● Read(negamax.asm)
⎿ Read 30 lines
● Read(negamax.asm)
⎿ Read 40 lines
● Read(negamax.asm)
⎿ Read 60 lines
● Read(negamax.asm)
⎿ Read 25 lines
● Read(negamax.asm)
⎿ Read 25 lines
● Read(negamax.asm)
⎿ Read 20 lines
● Read(negamax.asm)
⎿ Read 20 lines
● Good - line 839's IRX is just popping the move_count (we're done with it before CALL). The fix at line 816 was the critical one.
Let me check quiescence search for similar issues:
● Read(negamax.asm)
⎿ Read 30 lines
● Quiescence uses R15 for move count, not stack - no issue there. Let me update the version marker to VJ and build:
● Update(negamax.asm)
⎿ Added 1 line, removed 1 line
1300 ; Debug: VERSION MARKER - change this to verify new
build is loaded
1301 LDI 'V'
1302 CALL SERIAL_WRITE_CHAR
1303 - LDI 'I'
1303 + LDI 'J'
1304 CALL SERIAL_WRITE_CHAR
1305
1306 ; Debug: entered SEARCH_POSITION
● Bash(./build.sh 2>&1)
⎿ RCA 1802/1806 Chess Engine - Build Script
==========================================
… +73 lines (ctrl+o to expand)
● Version VJ built successfully (15988 bytes).
Key fix: Before the debug CALL, save move_count to R15.0 (via PLO 15). After CALL returns, the stack location is corrupted by R6 linkage, so we use GLO 15 to get the saved value instead of LDN 2.
The move counts should now decrement properly: 33, 32, 31, 30... instead of jumping around.
> Before I test this, I have a suggestion... I think our code base is
getting sufficiently complex that we should use git for revision control.
This would more easily reveal where an unintended, subtle change, may have
introduced a negative impact.
● Excellent idea. Let me initialize a git repository and make an initial commit with the current codebase.
● Bash(git init)
⎿ Initialized empty Git repository in /home/phiber/proj-chess/.git/
hint: Using 'master' as the name for the initial branch. This default b
ranch name
… +11 lines (ctrl+o to expand)
● Bash(ls -la /home/phiber/proj-chess/ | head -50)
⎿ total 10568
drwxr-xr-x 5 phiber staff 24576 Dec 27 19:36 .
drwxr-xr-x 191 phiber staff 12288 Dec 27 19:32 ..
… +49 lines (ctrl+o to expand)
● Write(.gitignore)
⎿ Wrote 24 lines to .gitignore
# Generated files
*.hex
*.lst
*.out
*.bin
# Preprocessed/concatenated files
*-pp.asm
*-preprocessed.asm
chess-engine.asm
… +14 lines (ctrl+o to expand)
● Bash(git add .gitignore *.asm *.sh *.md 2>&1 | head -20)
⎿ The following paths are ignored by one of your .gitignore files:
chess-engine-test.asm
chess-engine.asm
… +17 lines (ctrl+o to expand)
● Bash(git status)
⎿ On branch master
No commits yet
… +255 lines (ctrl+o to expand)
● Bash(git add .gitignore && git add '*.asm' '*.sh' '*.md' '*.txt' 2>&1)
⎿ (No content)
● Bash(git add . && git status --short | head -40)
⎿ A .gitignore
A "9600 baud.asm"
A CHESS-ENGINE-DESIGN.md
… +37 lines (ctrl+o to expand)
● Bash(git commit -m "Initial commit: RCA 1802/1806 Chess Engine…)
⎿ [master (root-commit) cdb2e3d] Initial commit: RCA 1802/1806 Chess Engi
ne
251 files changed, 88200 insertions(+)
… +251 lines (ctrl+o to expand)
● Bash(git log --oneline)
⎿ cdb2e3d Initial commit: RCA 1802/1806 Chess Engine
● Done. Git repository initialized with initial commit cdb2e3d.
- .gitignore excludes generated files (*.hex, *.lst, *-pp.asm, etc.)
- 251 source files committed
- Future changes will be easy to track with git diff
Version VJ is ready for testing. After testing, we can commit fixes incrementally to track what changed.
> Still infinite loop. Initial chunk of output in engine-vj.out
● Read(engine-vj.out)
⎿ Read 28 lines
● Good news - the move counts are now decrementing properly: #21, #20, #1F, #1E, #1D, #1C, #1B, #1A, #19, #18, #17, #16, #15...
That fix worked. But the search still doesn't terminate. Let me add a marker to see if we ever exit the move loop (when count reaches 0):
● Read(negamax.asm)
⎿ Read 15 lines
● Update(negamax.asm)
⎿ Added 4 lines
827 LBR NEGAMAX_MOVE_LOOP
828
829 NEGAMAX_LOOP_DONE:
830 + ; Debug: loop done - count reached 0
831 + LDI '@'
832 + CALL SERIAL_WRITE_CHAR
833 +
834 ; Count reached 0 - R2 is AT move_count, need to put it
BELOW
835 DEC 2 ; Now R2 is below move_count, matching
Path A
836 ; Fall through to NEGAMAX_RETURN
● Update(negamax.asm)
⎿ Added 1 line, removed 1 line
1304 ; Debug: VERSION MARKER - change this to verify new
build is loaded
1305 LDI 'V'
1306 CALL SERIAL_WRITE_CHAR
1307 - LDI 'J'
1307 + LDI 'K'
1308 CALL SERIAL_WRITE_CHAR
1309
1310 ; Debug: entered SEARCH_POSITION
● Bash(./build.sh 2>&1 | tail -20)
⎿ fixes for LCC/Windows by HRJ update Jan 2022
A18 source_file | -l list_file | -o/-m/-b object_file
… +17 lines (ctrl+o to expand)
● Bash(git add negamax.asm && git commit -m "VK: Add '@' marker for loop exit,
fix move count corruption…)
⎿ [master d73e1f1] VK: Add '@' marker for loop exit, fix move count corru
ption
1 file changed, 5 insertions(+), 1 deletion(-)
● Version VK built (15998 bytes). Added @ marker at loop exit.
If you see @ in the output, the loop is terminating correctly (just slow due to no alpha-beta pruning). If you never see @, there's still a loop bug.
> Output chunk in engine-vk.out. There is no @
● Read(engine-vk.out)
⎿ Read 28 lines
● No @ means count never reaches 0. The counts are decrementing (#21→#20→#1F...→#15) but never hitting zero. Let me check if something is resetting the count or preventing it from reaching 0.
Let me trace what happens in the move loop - maybe something is pushing/popping incorrectly:
● Read(negamax.asm)
⎿ Read 100 lines
● Read(negamax.asm)
⎿ Read 80 lines
● Read(negamax.asm)
⎿ Read 100 lines
● Let me check what happens at the end of each loop iteration - specifically where O is printed and what path we take:
● Search(pattern: "LDI 'O'", path: "negamax.asm", output_mode: "content")
⎿ Found 6 lines (ctrl+o to expand)
● Read(negamax.asm)
⎿ Read 40 lines
● Search(pattern: "LDI 'N'", path: "negamax.asm", output_mode: "content")
⎿ Found 4 lines (ctrl+o to expand)
● Read(negamax.asm)
⎿ Read 50 lines
● I see the pattern - after #21, we see JKLMNabcO.ABCD00XYZ which is: make next move, recurse to depth 0, evaluate. This is correct behavior.
The counts #21→#20→#1F...→#15 show proper decrement. Let me verify the BZ (branch if zero) is working correctly. The issue might be that SMI sets different flags than expected:
● Read(negamax.asm)
⎿ Read 20 lines
● Let me add debug to show the count AFTER decrement to verify SMI is working:
● Update(negamax.asm)
⎿ Added 7 lines
821 ; Use saved value from R15.0 instead of reloading from
stack
822 GLO 15 ; Get saved move count
823 SMI 1 ; Decrement
824 + PLO 15 ; Save decremented value
825 + ; Debug: show count AFTER decrement
826 + LDI '-'
827 + CALL SERIAL_WRITE_CHAR
828 + GLO 15
829 + CALL SERIAL_PRINT_HEX
830 + GLO 15 ; Reload decremented count
831 BZ NEGAMAX_LOOP_DONE ; If count == 0, exit loop
832 STR 2 ; Store decremented count back
(restores correct value)
833 DEC 2 ; Re-decrement stack pointer
● Update(negamax.asm)
⎿ Added 1 line, removed 1 line
1311 ; Debug: VERSION MARKER - change this to verify new
build is loaded
1312 LDI 'V'
1313 CALL SERIAL_WRITE_CHAR
1314 - LDI 'K'
1314 + LDI 'L'
1315 CALL SERIAL_WRITE_CHAR
1316
1317 ; Debug: entered SEARCH_POSITION
● Bash(./build.sh 2>&1 | tail -10)
⎿ Configuration used:
#define CFG_USE_BIOS
#define CFG_USE_EF3
… +7 lines (ctrl+o to expand)
● Bash(git add negamax.asm && git commit -m "VL: Add count-after-decrement debug
output…)
⎿ [master 0c947bb] VL: Add count-after-decrement debug output
1 file changed, 8 insertions(+), 1 deletion(-)
● Version VL built. Now the output will show #XX-YY where:
- XX = count before decrement
- YY = count after decrement
We should see patterns like #21-20, #20-1F, ... #02-01, #01-00, then @.
If YY doesn't equal XX-1, or if we never see #01-00@, we'll know exactly what's going wrong.
> Actually, I didn't wait long enough on the VK run. It does reach #01, and
then shows an "@".
● Excellent! So the loop IS terminating correctly - the fix worked! The search is just slow because alpha-beta pruning isn't cutting off branches (no 'X' beta cutoff markers in the output).
What happens after the @? Does the search eventually complete and return a best move, or does something else go wrong at that point?
If you want, I can revert version VL back to VK (remove the extra -YY debug output) since we've confirmed the decrement is working.
> VL isn't right. The #'s are jumping around again, not decrementing.
● The additional CALLs in VL might be corrupting R15. Let me check if SERIAL_PRINT_HEX uses R15:
● Search(pattern: "SERIAL_PRINT_HEX|R15|PLO 15|PHI 15|GLO 15|GHI 15", path:
"serial-io.asm", output_mode: "content")
⎿ Found 13 lines (ctrl+o to expand)
● Found it! Lines 191-193 show SERIAL_PRINT_HEX uses R15 for string pointer. My VL code saves to R15, then calls functions that overwrite R15, then tries to read R15 - garbage!
Let me revert to VK which was working:
● Update(negamax.asm)
⎿ Added 5 lines, removed 11 lines
815 CALL SERIAL_WRITE_CHAR
816 IRX ; Point to move_count
817 LDN 2 ; Get move count
818 - PLO 15 ; Save to R15.0 - survives
-CALL (PLO doesn't change D)
818 + PLO 15 ; Save to R15.0 - survives single
+CALL (PLO doesn't change D)
819 CALL SERIAL_PRINT_HEX ; Show count as hex (D still has
count)
820 ; CRITICAL: M(R2) was corrupted by CALL pushing R6
linkage!
821 - ; Use saved value from R15.0 instead of reloading from
-stack
822 - GLO 15 ; Get saved move count
821 + ; NOTE: R15 was also corrupted by SERIAL_PRINT_HEX -
+reload from where we saved it
822 + ; Actually R15 is corrupted, so we need to peek stack
+again BEFORE any more CALLs
823 + LDN 2 ; Re-peek move count from stack (CALL
+restored it via balanced push/pop)
824 SMI 1 ; Decrement
825 - PLO 15 ; Save decremented value
826 - ; Debug: show count AFTER decrement
827 - LDI '-'
828 - CALL SERIAL_WRITE_CHAR
829 - GLO 15
830 - CALL SERIAL_PRINT_HEX
831 - GLO 15 ; Reload decremented count
825 BZ NEGAMAX_LOOP_DONE ; If count == 0, exit loop
826 - STR 2 ; Store decremented count back
- (restores correct value)
826 + STR 2 ; Store decremented count back
827 DEC 2 ; Re-decrement stack pointer
828 LBR NEGAMAX_MOVE_LOOP
829
● Wait, let me re-check. In VK, we used GLO 15 after CALL SERIAL_PRINT_HEX, and you said it worked. Let me look at what SERIAL_PRINT_HEX actually does with R15:
● Read(serial-io.asm)
⎿ Read 60 lines
● I see - SERIAL_PRINT_HEX itself doesn't corrupt R15 (only uses R9.0). But my new code is wrong - I'm doing LDN 2 after the CALL, but M(R2) is corrupted. Let me properly revert to VK:
● Update(negamax.asm)
⎿ Added 4 lines, removed 6 lines
815 CALL SERIAL_WRITE_CHAR
816 IRX ; Point to move_count
817 LDN 2 ; Get move count
818 - PLO 15 ; Save to R15.0 - survives single CALL
- (PLO doesn't change D)
818 + PLO 15 ; Save to R15.0 - SERIAL_PRINT_HEX
+preserves R15
819 CALL SERIAL_PRINT_HEX ; Show count as hex (D still has
count)
820 - ; CRITICAL: M(R2) was corrupted by CALL pushing R6
-linkage!
821 - ; NOTE: R15 was also corrupted by SERIAL_PRINT_HEX -
-reload from where we saved it
822 - ; Actually R15 is corrupted, so we need to peek stack
-again BEFORE any more CALLs
823 - LDN 2 ; Re-peek move count from stack (CALL
-restored it via balanced push/pop)
820 + ; M(R2) was corrupted by CALL, but R15 is preserved
821 + GLO 15 ; Get saved move count from R15
822 SMI 1 ; Decrement
823 BZ NEGAMAX_LOOP_DONE ; If count == 0, exit loop
824 - STR 2 ; Store decremented count back
824 + STR 2 ; Store decremented count back
+ (fixes corrupted M(R2))
825 DEC 2 ; Re-decrement stack pointer
826 LBR NEGAMAX_MOVE_LOOP
827
● Update(negamax.asm)
⎿ Added 1 line, removed 1 line
1303 ; Debug: VERSION MARKER - change this to verify new
build is loaded
1304 LDI 'V'
1305 CALL SERIAL_WRITE_CHAR
1306 - LDI 'L'
1306 + LDI 'M'
1307 CALL SERIAL_WRITE_CHAR
1308
1309 ; Debug: entered SEARCH_POSITION
● Bash(./build.sh 2>&1 | tail -5)
⎿ Next steps:
1. If assembly succeeded, flash chess-engine.hex to your RCA 1806 sys
tem
… +2 lines (ctrl+o to expand)
● Bash(git add negamax.asm && git commit -m "VM: Revert to VK logic (working
move count decrement)…)
⎿ [master 975e642] VM: Revert to VK logic (working move count decrement)
1 file changed, 5 insertions(+), 13 deletions(-)
● VM built - should behave same as VK which was working.
Since VK was reaching @ (loop termination), the search is working but just slow due to no alpha-beta pruning. For a depth-2 search with ~34 × ~30 = 1000+ positions to evaluate, it will take a while.
Would you like to:
1. Let it run to completion and see if it returns a valid move?
2. Or investigate why alpha-beta pruning isn't working to speed up the search?
> The # count is still jumping all over the place, not decrementing.
● That's strange - VM should be identical to VK. Let me check git to see what VK actually was:
● Bash(git log --oneline)
⎿ 975e642 VM: Revert to VK logic (working move count decrement)
0c947bb VL: Add count-after-decrement debug output
d73e1f1 VK: Add '@' marker for loop exit, fix move count corruption
cdb2e3d Initial commit: RCA 1802/1806 Chess Engine
● Bash(git show d73e1f1:negamax.asm | grep -A 20 "NEGAMAX_NEXT_MOVE:")
⎿ NEGAMAX_NEXT_MOVE:
; -----------------------------------------------
; Decrement move counter and continue loop
… +20 lines (ctrl+o to expand)
● Bash(git diff d73e1f1:negamax.asm negamax.asm | head -50)
⎿ diff --git a/negamax.asm b/negamax.asm
index a3aec17..5fe9771 100644
--- a/negamax.asm
… +34 lines (ctrl+o to expand)
● The code is identical except comments. Something else must be wrong. Let me try saving to memory instead of R15, in case SCRT or something else is corrupting R15:
● Read(board-0x88.asm)
⎿ Read 50 lines
● Search(pattern: "COMPARE_TEMP", path: "board-0x88.asm", output_mode:
"content")
⎿ Found 1 line (ctrl+o to expand)
● Read(board-0x88.asm)
⎿ Read 10 lines
● Update(board-0x88.asm)
⎿ Added 1 line
104 SCORE_HI EQU $6447 ; 1 byte - score return high byte
105 CURRENT_PLY EQU $6448 ; 1 byte - current search ply
(0=root)
106 COMPARE_TEMP EQU $6449 ; 1 byte - scratch for
comparisons (NEVER use STR 2!)
107 +MOVECOUNT_TEMP EQU $644A ; 1 byte - saved move count for
+loop decrement
108
109 ; -----------------------------------------------------------
-------------------
110 ; UCI state: $6500-$6600
● Now update the code to use memory instead of R15:
● Update(negamax.asm)
⎿ Added 15 lines, removed 5 lines
815 CALL SERIAL_WRITE_CHAR
816 IRX ; Point to move_count
817 LDN 2 ; Get move count
818 - PLO 15 ; Save to R15.0 - SERIAL_PRINT_HEX
-preserves R15
819 - CALL SERIAL_PRINT_HEX ; Show count as hex (D still has
-count)
820 - ; M(R2) was corrupted by CALL, but R15 is preserved
821 - GLO 15 ; Get saved move count from R15
818 + ; Save to MOVECOUNT_TEMP memory (R15 might be corrupted
+by CALLs)
819 + LDI HIGH(MOVECOUNT_TEMP)
820 + PHI 10
821 + LDI LOW(MOVECOUNT_TEMP)
822 + PLO 10
823 + LDN 2 ; Re-load move count (D was clobbered
+by LDI)
824 + STR 10 ; Save to memory
825 + CALL SERIAL_PRINT_HEX ; Show count as hex
826 + ; Reload from memory (M(R2) was corrupted by CALL, R15
+might be too)
827 + LDI HIGH(MOVECOUNT_TEMP)
828 + PHI 10
829 + LDI LOW(MOVECOUNT_TEMP)
830 + PLO 10
831 + LDN 10 ; Get saved move count from memory
832 SMI 1 ; Decrement
833 BZ NEGAMAX_LOOP_DONE ; If count == 0, exit loop
834 - STR 2 ; Store decremented count back (fixes
-corrupted M(R2))
834 + STR 2 ; Store decremented count back to stack
835 DEC 2 ; Re-decrement stack pointer
836 LBR NEGAMAX_MOVE_LOOP
837
● Update(negamax.asm)
⎿ Added 1 line, removed 1 line
1313 ; Debug: VERSION MARKER - change this to verify new
build is loaded
1314 LDI 'V'
1315 CALL SERIAL_WRITE_CHAR
1316 - LDI 'M'
1316 + LDI 'N'
1317 CALL SERIAL_WRITE_CHAR
1318
1319 ; Debug: entered SEARCH_POSITION
● Bash(./build.sh 2>&1 | tail -5)
⎿ Next steps:
1. If assembly succeeded, flash chess-engine.hex to your RCA 1806 sys
tem
… +2 lines (ctrl+o to expand)
● Bash(git add board-0x88.asm negamax.asm && git commit -m "VN: Use memory
instead of R15 for move count save…)
⎿ [master b294b60] VN: Use memory instead of R15 for move count save
2 files changed, 17 insertions(+), 6 deletions(-)
● Version VN built. Now using memory at MOVECOUNT_TEMP ($644A) instead of R15. This eliminates any possibility of register corruption across CALLs.
> I still see the # values jumping around sporadically. Unfortunately I'll
have to stop for today. We can pick this up tomorrow.
● No problem. Let me save the current state to PROGRESS.md so we can pick up where we left off.
● Read(PROGRESS.md)
⎿ Read 50 lines
● Bash(tail -100 /home/phiber/proj-chess/PROGRESS.md)
⎿ When PUSH_HISTORY_ENTRY read HISTORY_PTR, it got garbage ($FFFE), and w
rote history entries to random memory - corrupting CURRENT_PLY, SCORE,
ALPHA, BETA, and other variables in the $64xx region.
… +112 lines (ctrl+o to expand)
● Bash(cat >> /home/phiber/proj-chess/PROGRESS.md << 'EOF'…)
⎿ PROGRESS.md updated
● Bash(git add PROGRESS.md && git commit -m "Update PROGRESS.md with Dec 27
session notes…)
⎿ [master 7124f68] Update PROGRESS.md with Dec 27 session notes
1 file changed, 81 insertions(+)
● State saved. Here's where we are:
What we know:
- VK was confirmed working (count decremented to 0, showed @)
- VM (same logic) and VN (memory-based) show counts jumping around
- The issue is NOT just the CALL corrupting M(R2) - we fixed that
To investigate tomorrow:
1. Something in the move loop body may be corrupting R2 or the stack
2. Maybe a different code path is being taken than we expect
3. Consider removing all debug CALLs to isolate the issue
Git commits are saved, PROGRESS.md updated. See you tomorrow!