comparison clojure/com/aurellem/assembly.clj @ 139:74ec1ac044bb

write-memory-assembly* confirmed...stage one.
author Dylan Holmes <ocsenave@gmail.com>
date Mon, 19 Mar 2012 05:12:05 -0500
parents 2b69cbe8a5b9
children aa5b5927e5fe
comparison
equal deleted inserted replaced
138:2b69cbe8a5b9 139:74ec1ac044bb
67 (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8)) 67 (bit-shift-right (bit-and 0x0000FF00 (AF state)) 8))
68 68
69 (defn B [state] 69 (defn B [state]
70 (bit-shift-right (bit-and 0x0000FF00 (BC state)) 8)) 70 (bit-shift-right (bit-and 0x0000FF00 (BC state)) 8))
71 71
72 (defn D [state]
73 (bit-shift-right (bit-and 0x0000FF00 (DE state)) 8))
74
75 (defn H [state]
76 (bit-shift-right (bit-and 0x0000FF00 (HL state)) 8))
77
72 (defn C [state] 78 (defn C [state]
73 (bit-and 0xFF (BC state))) 79 (bit-and 0xFF (BC state)))
80 (defn F [state]
81 (bit-and 0xFF (AF state)))
82 (defn E [state]
83 (bit-and 0xFF (DE state)))
84 (defn L [state]
85 (bit-and 0xFF (HL state)))
86
87
88
89
74 90
75 (defn binary-str [num] 91 (defn binary-str [num]
76 (format "%08d" 92 (format "%08d"
77 (Integer/parseInt 93 (Integer/parseInt
78 (Integer/toBinaryString num) 10))) 94 (Integer/toBinaryString num) 10)))
530 0xCB ;test C_0 546 0xCB ;test C_0
531 0x41 547 0x41
532 0x20 ; JUMP ahead to button input if nonzero 548 0x20 ; JUMP ahead to button input if nonzero
533 0x02 549 0x02
534 0x18 ; JUMP back to frame metronome (D31F) 550 0x18 ; JUMP back to frame metronome (D31F)
535 0xE6 ; todo: verify this jump length 551 0xE7
536 552
537 ;; -------- GET BUTTON INPUT 553 ;; -------- GET BUTTON INPUT
538 554
539 ;; btw, C_0 is now 1 555 ;; btw, C_0 is now 1
540 ;; prepare to select bits 556 ;; prepare to select bits
571 0xED 587 0xED
572 588
573 589
574 ;; ------ TAKE ACTION BASED ON USER INPUT 590 ;; ------ TAKE ACTION BASED ON USER INPUT
575 591
592 ;; "input mode"
576 ;; mode 0x00 : select mode 593 ;; mode 0x00 : select mode
577 ;; mode 0x08 : select bytes-to-write 594 ;; mode 0x08 : select bytes-to-write
578 ;; mode 0x10 : select hi-bit 595 ;; mode 0x10 : select hi-bit
579 ;; mode 0x18 : select lo-bit 596 ;; mode 0x18 : select lo-bit
580 597
581 ;; mode 0xF0 : write bytes 598 ;; "output mode"
599 ;; mode 0x20 : write bytes
582 ;; mode 0xFF : jump PC 600 ;; mode 0xFF : jump PC
583 601
584 602
585 ;; registers 603 ;; registers
586 ;; D : mode select 604 ;; D : mode select
592 0x2F ; complement A, by request. [D34F] 610 0x2F ; complement A, by request. [D34F]
593 611
594 0x47 ; A->B ;; now B contains the pressed keys 612 0x47 ; A->B ;; now B contains the pressed keys
595 0x7B ; E->A ;; now A contains the count. 613 0x7B ; E->A ;; now A contains the count.
596 614
597 0xCB ; test bit 4 of D (are we in o/p mode?) 615 0xCB ; test bit 5 of D (are we in o/p mode?)
598 0x26 616 0x6A
599 0x28 ; if test == 0, skip this o/p section 617 0x28 ; if test == 0, skip this o/p section
600 0x13 ; JUMP 618 0x13 ; JUMP
601 619
602 0xCB ; else, test bit 0 of D (fragile; are we in pc mode?) 620 0xCB ; else, test bit 0 of D (fragile; are we in pc mode?)
603 0x42 621 0x42
608 0xE9 ; ** move PC to (HL) 626 0xE9 ; ** move PC to (HL)
609 627
610 ;; output mode II: writing bytes 628 ;; output mode II: writing bytes
611 0xFE ; A compare 0. finished writing? 629 0xFE ; A compare 0. finished writing?
612 0x00 630 0x00
613 0x28 ; if we are not finished, skip cleanup 631 0x20 ; if we are not finished, skip cleanup
614 0x04 ; JUMP 632 0x04 ; JUMP
615 633
616 ;; CLEANUP 634 ;; CLEANUP
617 ;; btw, A is already zero. 635 ;; btw, A is already zero.
618 0xAF ; zero A [D35F] 636 0xAF ; zero A [D35F]
622 640
623 ;; ---- end of cleanup 641 ;; ---- end of cleanup
624 642
625 643
626 ;; continue writing bytes 644 ;; continue writing bytes
627 0x1D ;; decrement E, the number of bytes to write 645 0x1D ;; decrement E, the number of bytes to write [D363]
628 0x78 ;; B->A; now A contains the pressed keys 646 0x78 ;; B->A; now A contains the pressed keys
629 0x77 ;; copy A to (HL) 647 0x77 ;; copy A to (HL)
630 0x23 ;; increment HL 648 0x23 ;; increment HL
631 0x18 ;; end frame. 649 0x18 ;; end frame. [goto D31F]
632 0xC2 ;; TODO: set skip length backwards 650 0xB6 ;; TODO: set skip length backwards
633 651
634 652
635 ;; ---- end of o/p section 653 ;; ---- end of o/p section
636 654
637 ;; get data 655 ;; i/p mode
656 ;; adhere to the mode discipline:
657 ;; D must be one of 0x00 0x08 0x10 0x18.
658
638 0x3E ;; load the constant 57 into A. [D369] 659 0x3E ;; load the constant 57 into A. [D369]
639 0x57 660 0x57
640 0x82 ;; add the mode to A 661 0x82 ;; add the mode to A
641 0xEA ;; store A into "thing to execute" 662 0xEA ;; store A into "thing to execute"
642 0x74 663 0x74
643 0xD3 664 0xD3
644 665
645 0x3E ;; load the constant 8 into A 666 0x3E ;; load the constant 8 into A
646 0x08 667 0x08
647 0x82 ;; add the mode to A 668 0x82 ;; add the mode to A
669
648 0x57 ;; store the incremented mode into D 670 0x57 ;; store the incremented mode into D
649 0x78 ;; B->A; now A contains the pressed keys 671 0x78 ;; B->A; now A contains the pressed keys
650 672
651 0x00 ;; var: thing to execute [D374] 673 0x00 ;; var: thing to execute [D374]
652 674
653 0x18 ;; end frame 675 0x18 ;; end frame
654 0xA8 ;; JUMP 676 0xA8 ;; TODO: set jump correctly
655 ] 677 ]
656 ) 678 )
657 679
658 (defn write-mem-dyl [] 680 (defn write-mem-dyl []
659 (-> (tick (mid-game)) 681 (-> (tick (mid-game))
1287 (step [:b]) 1309 (step [:b])
1288 (step [:start]) 1310 (step [:start])
1289 (step []) 1311 (step [])
1290 (view-memory frame-count))) 1312 (view-memory frame-count)))
1291 1313
1314
1315
1316 (defn dylan-test-mode
1317 ([] (dylan-test-mode (write-mem-dyl)))
1318 ([target-state]
1319 (let [
1320 v-blank-prev 54046
1321 btn-register 65280
1322 eggs 0xD374
1323 ]
1324
1325 (->
1326 target-state
1327
1328 (tick)
1329 (tick)
1330 (tick)
1331 (tick);; jumps back to beginning
1332
1333 (tick)
1334 (tick)
1335 (tick)
1336 (tick)
1337 (tick)
1338 (tick)
1339 (tick)
1340 (tick)
1341 (tick)
1342 (tick)
1343 (tick)
1344 (tick)
1345
1346
1347 (tick)
1348 (tick)
1349 (tick)
1350 (tick)
1351 (tick)
1352 (tick)
1353 (tick)
1354 (tick)
1355 (tick)
1356 (tick)
1357 (tick)
1358 (tick)
1359 (tick)
1360 (tick)
1361 (tick)
1362 (tick)
1363 (tick)
1364 (tick)
1365 (tick)
1366 (tick)
1367 (tick) ;; just complemented A
1368
1369 (tick)
1370 (DE! 0x0800)
1371 (AF! 0xCF00) ;; change inputs @ A
1372 (tick)
1373 (tick)
1374 (tick)
1375 (tick)
1376 (tick)
1377
1378 ;;(view-memory eggs)
1379 (tick)
1380 (tick)
1381 ;;(view-memory eggs)
1382 (tick)
1383 (tick)
1384 (tick)
1385 (tick)
1386
1387 (d-tick)
1388
1389
1390 ;;(view-memory btn-register)
1391 (view-register "A" A)
1392 (view-register "B" B)
1393
1394 ;;(view-register "C" C)
1395 (view-register "D" D)
1396 (view-register "E" E)
1397 (view-register "H" H)
1398 (view-register "L" L)
1399 ))))
1400
1401
1402
1403
1404
1405
1292 (defn test-mode-4 1406 (defn test-mode-4
1293 ([] (test-mode-4 (write-memory))) 1407 ([] (test-mode-4 (write-memory)))
1294 ([target-state] 1408 ([target-state]
1295 (-> 1409 (->
1296 target-state 1410 target-state