comparison clojure/com/aurellem/assembly.clj @ 138:2b69cbe8a5b9

saving progress on state machine; 240 ops -> 90 ops (provided it withstands debugging)
author Dylan Holmes <ocsenave@gmail.com>
date Mon, 19 Mar 2012 03:05:42 -0500
parents 1c58fa3cfc68
children 74ec1ac044bb
comparison
equal deleted inserted replaced
137:1c58fa3cfc68 138:2b69cbe8a5b9
495 (defn write-memory-assembly* 495 (defn write-memory-assembly*
496 "Currently, grabs input from the user each frame." 496 "Currently, grabs input from the user each frame."
497 [] 497 []
498 [ 498 [
499 ;; --------- FRAME METRONOME 499 ;; --------- FRAME METRONOME
500 0x00 ;; v-blank-prev D31D 500 0x18 ;; jump ahead to cleanup. first time only.
501 501 0x40 ;; v-blank-prev [D31E]
502 0xFA ;; load modes into A 502
503 0xFA ;; load modes into A [D31F]
503 0x41 504 0x41
504 0xFF 505 0xFF
505 506
506 0x47 ;; A -> B 507 0x47 ;; A -> B
507 0xCB ;; rotate A 508 0xCB ;; rotate A
510 511
511 0xA0 512 0xA0
512 0x47 ;; now B_0 contains (VB==1) 513 0x47 ;; now B_0 contains (VB==1)
513 514
514 0xFA ;; load v-blank-prev 515 0xFA ;; load v-blank-prev
515 0x1D 516 0x1E
516 0xD3 517 0xD3
517 518
518 0x2F ;; complement v-blank-prev 519 0x2F ;; complement v-blank-prev
519 520
520 0xA0 ;; A & B --> A 521 0xA0 ;; A & B --> A
521 0x4F ;; now C_0 contains increment? 522 0x4F ;; now C_0 contains increment?
522 523
523 524
524 0x78 ;; B->A 525 0x78 ;; B->A
525
526 0xEA ;; spit A --> vbprev 526 0xEA ;; spit A --> vbprev
527 0x1D 527 0x1E
528 0xD3 528 0xD3
529 529
530 0xCB ;test C_0 530 0xCB ;test C_0
531 0x41 531 0x41
532 0x20 ; JUMP ahead to button input if nonzero 532 0x20 ; JUMP ahead to button input if nonzero
533 0x03 533 0x02
534 0x18 ; JUMP back to frame metronome (D31E) 534 0x18 ; JUMP back to frame metronome (D31F)
535 0xE7 535 0xE6 ; todo: verify this jump length
536 536
537 ;; -------- GET BUTTON INPUT 537 ;; -------- GET BUTTON INPUT
538 538
539 ;; btw, C_0 is now 1 539 ;; btw, C_0 is now 1
540 0x00 ;; var: which-input D337
541 ;; prepare to select bits 540 ;; prepare to select bits
542 541
543 0x06 ;; load 0x00 into B 542 0x06 ;; load 0x00 into B
544 0x00 543 0x00 ;; to initialize for "OR" loop
545 544
546 0x3E ;; load 0x20 into A, to measure dpad 545 0x3E ;; load 0x20 into A, to measure dpad
547 0x20 546 0x20
548 547
549 548
550 0xE0 ;; load A into [FF00] ;; D33C 549 0xE0 ;; load A into [FF00] ;; start of OR loop [D33C]
551 0x00 550 0x00
552 551
553 0xF0 ;; load A from [FF00] 552 0xF0 ;; load A from [FF00]
554 0x00 553 0x00
555 554
569 0x3E ;; load 0x10 into A, to measure btns 568 0x3E ;; load 0x10 into A, to measure btns
570 0x10 569 0x10
571 0x18 ;; JUMP back to "load A into [FF00]" [20 steps?] 570 0x18 ;; JUMP back to "load A into [FF00]" [20 steps?]
572 0xED 571 0xED
573 572
573
574 ;; ------ TAKE ACTION BASED ON USER INPUT
575
576 ;; mode 0x00 : select mode
577 ;; mode 0x08 : select bytes-to-write
578 ;; mode 0x10 : select hi-bit
579 ;; mode 0x18 : select lo-bit
580
581 ;; mode 0xF0 : write bytes
582 ;; mode 0xFF : jump PC
583
584
585 ;; registers
586 ;; D : mode select
587 ;; E : count of bytes to write
588 ;; H : address-high
589 ;; L : address-low
590
574 ;; now A contains the pressed keys 591 ;; now A contains the pressed keys
575 592 0x2F ; complement A, by request. [D34F]
576 593
577 594 0x47 ; A->B ;; now B contains the pressed keys
578 595 0x7B ; E->A ;; now A contains the count.
579 596
580 597 0xCB ; test bit 4 of D (are we in o/p mode?)
581 598 0x26
582 599 0x28 ; if test == 0, skip this o/p section
583 0xC3 ;; todo replace with relative jump 600 0x13 ; JUMP
584 0x1E 601
602 0xCB ; else, test bit 0 of D (fragile; are we in pc mode?)
603 0x42
604 0x28 ; if test == 0, skip the following command
605 0x01
606
607 ;; output mode I: moving the program counter
608 0xE9 ; ** move PC to (HL)
609
610 ;; output mode II: writing bytes
611 0xFE ; A compare 0. finished writing?
612 0x00
613 0x28 ; if we are not finished, skip cleanup
614 0x04 ; JUMP
615
616 ;; CLEANUP
617 ;; btw, A is already zero.
618 0xAF ; zero A [D35F]
619 0x57 ; A->D; makes D=0.
620 0x18 ; end of frame
621 0xBC
622
623 ;; ---- end of cleanup
624
625
626 ;; continue writing bytes
627 0x1D ;; decrement E, the number of bytes to write
628 0x78 ;; B->A; now A contains the pressed keys
629 0x77 ;; copy A to (HL)
630 0x23 ;; increment HL
631 0x18 ;; end frame.
632 0xC2 ;; TODO: set skip length backwards
633
634
635 ;; ---- end of o/p section
636
637 ;; get data
638 0x3E ;; load the constant 57 into A. [D369]
639 0x57
640 0x82 ;; add the mode to A
641 0xEA ;; store A into "thing to execute"
642 0x74
585 0xD3 643 0xD3
586 ;;0x18 ;;JUMP back to "metronome" in one hop [D31E] 644
587 ;;0xCA ;; E1 645 0x3E ;; load the constant 8 into A
588 646 0x08
647 0x82 ;; add the mode to A
648 0x57 ;; store the incremented mode into D
649 0x78 ;; B->A; now A contains the pressed keys
650
651 0x00 ;; var: thing to execute [D374]
652
653 0x18 ;; end frame
654 0xA8 ;; JUMP
589 ] 655 ]
590 ) 656 )
591 657
592 (defn write-mem-dyl [] 658 (defn write-mem-dyl []
593 (-> (tick (mid-game)) 659 (-> (tick (mid-game))
594 (IE! 0) 660 (IE! 0)
595 (inject-item-assembly (write-memory-assembly*)))) 661 (inject-item-assembly (write-memory-assembly*))))
662
663
664 (defn dylan* []
665 (->
666 (write-mem-dyl)
667
668 (tick)
669 (tick)
670 (tick)
671 (tick)
672 (tick)
673 (tick)
674 (tick)
675 (tick)
676 (tick)
677 (tick)
678 (tick)
679 (tick)
680 (tick)
681 (tick)
682 (tick)
683 (tick)
684 (tick)
685 (tick)
686 (tick)
687 (tick)
688 (tick)
689 (tick)
690 (tick)
691 (tick)
692 (tick)
693 (tick)
694 (tick)
695 (tick)
696 (tick)
697 (tick)
698 (tick)
699 (tick)
700 (tick)
701 (tick)
702 (tick)
703 (tick)
704
705 ;;(view-memory 0xD374)
706 (tick)
707 (tick)
708 (tick)
709 (tick)
710 (tick)
711 (tick)
712 (tick)
713 (tick)
714 (tick)
715 (tick)
716 (tick)
717 (tick)
718 (tick)
719 (tick)
720 (tick)
721 ;;(view-memory 0xD374)
722 (d-tick)
723
724 (view-register "A" A)
725 (view-register "B" B)
726 (view-register "C" C))
727
728 )
596 729
597 730
598 (defn dylan [] 731 (defn dylan []
599 (-> 732 (->
600 (write-mem-dyl) 733 (write-mem-dyl)