comparison clojure/com/aurellem/assembly.clj @ 126:86f92deacd2a

completed mode 3
author Robert McIntyre <rlm@mit.edu>
date Sat, 17 Mar 2012 02:25:48 -0500
parents d2e00c923bad
children 901ee6b648da
comparison
equal deleted inserted replaced
125:d2e00c923bad 126:86f92deacd2a
621 ;; beginning of main state machine 621 ;; beginning of main state machine
622 0x18 ;D380 ; Declaration of variables 622 0x18 ;D380 ; Declaration of variables
623 0x05 ;D381 ; 5 variables: 623 0x05 ;D381 ; 5 variables:
624 0x00 ;D382 ; current-mode 624 0x00 ;D382 ; current-mode
625 0x00 ;D383 ; bytes-to-write 625 0x00 ;D383 ; bytes-to-write
626 0x00 ;D384 ; start-point 626 0x00 ;D384 ; bytes-written
627 0x00 ;D385 ; bytes-written 627 0x00 ;D385 ; start-point-high
628 0x00 ;D386 ; unused 628 0x00 ;D386 ; start-point-low
629 629
630 630
631 ;; banch on current mode 631 ;; banch on current mode
632 0xFA ;D387 ; load current-mode (0xD382) 632 0xFA ;D387 ; load current-mode (0xD382)
633 0x82 ;D388 ; into A 633 0x82 ;D388 ; into A
649 649
650 0xCA ;D392 650 0xCA ;D392
651 0xB1 ;D393 651 0xB1 ;D393
652 0xD3 ;D394 ; goto Mode 1 if A == 1 652 0xD3 ;D394 ; goto Mode 1 if A == 1
653 653
654 ;; GOTO Mode 2 (set-start-point) if current mode is 2 654 ;; GOTO Mode 2 (set-start-point-high) if current mode is 2
655 0xFE ;D395 655 0xFE ;D395
656 0x02 ;D396 ; compare A with 0x02 656 0x02 ;D396 ; compare A with 0x02
657 657
658 0xCA ;D397 658 0xCA ;D397
659 0xBF ;D398 659 0xBF ;D398
660 0xD3 ;D399 ; goto Mode 2 if A == 2 660 0xD3 ;D399 ; goto Mode 2 if A == 2
661 661
662 ;; GOTO Mode 3 (write-memory) if current mode is 3 662 ;; GOTO Mode 3 (set-start-point-low) if current mode is 3
663 0xFE ;D39A 663 0xFE ;D39A
664 0x03 ;D39B 664 0x03 ;D39B
665 665
666 0x00 ;D39C 666 0xCA ;D39C
667 0xCA ;D39D 667 0xCD ;D39D
668 0xXX ;D39E 668 0xD3 ;D39E ; goto Mode 3 if A == 3
669 0xXX ;D39F 669
670 0x00 ;D39F
670 0x00 ;D3A0 671 0x00 ;D3A0
671 0x00 ;D3A1 672 0x00 ;D3A1
672 0x00 ;D3A2 673 0x00 ;D3A2
673 0x00 ;D3A3 674 0x00 ;D3A3
674 0x00 ;D3A4 675 0x00 ;D3A4
725 0x1D ;D3BD 726 0x1D ;D3BD
726 0xD3 ;D3BE 727 0xD3 ;D3BE
727 ;; End Mode 1 728 ;; End Mode 1
728 729
729 730
730 ;; Mode 2 -- set start-point mode 731 ;; Mode 2 -- set start-point-high mode
731 ;; Final part of the header for writing things to memory. 732 ;; Middle part of the header for writing things to memory.
732 ;; User specifies the start location in RAM to which 733 ;; User specifies the start location in RAM to which
733 ;; data will be written. 734 ;; data will be written.
734 ;; Mode is auto advanced to Mode 3 after this mode completes. 735 ;; Mode is auto advanced to Mode 3 after this mode completes.
735 736
736 ;; Set start-point to input-number; 737 ;; Set start-point-high to input-number;
737 ;; set current mode to 0x03. 738 ;; set current mode to 0x03.
738 0xFA ;D3BF ; load input-number (0xD352) 739 0xFA ;D3BF ; load input-number (0xD352)
739 0x52 ;D3C0 ; into A 740 0x52 ;D3C0 ; into A
740 0xD3 ;D3C1 741 0xD3 ;D3C1
741 742
742 0xEA ;D3C2 ; load A into start-point 743 0xEA ;D3C2 ; load A into start-point-high
743 0x84 ;D3C3 ; (0xD384) 744 0x85 ;D3C3 ; (0xD385)
744 0xD3 ;D3C4 745 0xD3 ;D3C4
745 746
746 0x3E ;D3C5 ; load 0x03 into A. 747 0x3E ;D3C5 ; load 0x03 into A.
747 0x03 ;D3C6 748 0x03 ;D3C6
748 749
754 0x1D ;D3CB 755 0x1D ;D3CB
755 0xD3 ;D3CC 756 0xD3 ;D3CC
756 ;;End Mode 2 757 ;;End Mode 2
757 758
758 759
759 ;; Mode 3 -- write bytes mode 760 ;; Mode 3 -- set-start-point-low mode
761 ;; Final part of header for writing things to memory.
762 ;; User specifies the low bytes of 16 bit start-point.
763
764 ;; Set start-point-low to input-number;
765 ;; set current mode to 0x04
766 0xFA ;D3CD ; load input-number into A
767 0x52 ;D3CE
768 0xD3 ;D3CF
769
770 0xEA ;D3D0 ; load A into start-point-low
771 0x86 ;D3D1
772 0xD3 ;D3D2
773
774 0x3E ;D3D3 ; load 0x04 into A.
775 0x04 ;D3D4
776
777 0xEA ;D3D5 ; load A to current-mode,
778 0x82 ;D3D6 ; advancing from Mode 3 to
779 0xD3 ;D3D7 ; Mode 4.
780
781 0xC3 ;D3D8 ; go back to beginning
782 0x1D ;D3D9
783 0xD3 ;D3DA
784
785 ;; Mode 4 -- write bytes mode
760 786
761 ;; This is where RAM manipulation happens. User supplies 787 ;; This is where RAM manipulation happens. User supplies
762 ;; bytes every frame, which are written sequentially to 788 ;; bytes every frame, which are written sequentially to
763 ;; start-point until bytes-to-write have been written. Once 789 ;; start-point until bytes-to-write have been written. Once
764 ;; bytes-to-write have been written, the mode is reset to 0. 790 ;; bytes-to-write have been written, the mode is reset to 0.
765 791
766 ;; compare bytes-written with bytes-to-write. 792 ;; compare bytes-written with bytes-to-write.
767 ;; if they are the same, then reset mode to 0 793 ;; if they are the same, then reset mode to 0
768 794
769 0xFA ;D3CD ; load bytes-to-write into A 795 0xFA ;D3DB ; load bytes-to-write into A
770 0x83 ;D3CE 796 0x83 ;D3DC
771 0xD3 ;D3CF 797 0xD3 ;D3DD
772 798 0x47 ;D3DE ; load A into B
773 0x47 ;D3D0 ; load A into B 799 0xFA ;D3DF ; load bytes-written into A
774 800 0x84 ;D3E0
775 0xFA ;D3D1 ; load bytes-written into A 801 0xD3 ;D3E1
776 0x82 ;D3D2 802 0xB8 ;D3E2 ; compare A with B
777 0xD3 ;D3D3 803 0xCA ;D3E3 ; if they are equal, go to cleanup
778
779 0xB8 ;D3D4 ; compare A with B
780
781 0xCA ;D3D5 ; if they are equal, go to cleanup
782 804
783 ;; Write Memory Section 805 ;; Write Memory Section
784 ;; Write the input-number, interpreted as an 8-bit number, 806 ;; Write the input-number, interpreted as an 8-bit number,
785 ;; into the current target register, determined by 807 ;; into the current target register, determined by
786 ;; (+ start-point bytes-written). 808 ;; (+ start-point bytes-written).
845 867
846 (def frame-count 0xD31F) 868 (def frame-count 0xD31F)
847 (def input 0xD352) 869 (def input 0xD352)
848 (def current-mode 0xD382) 870 (def current-mode 0xD382)
849 (def bytes-to-write 0xD383) 871 (def bytes-to-write 0xD383)
850 (def start-point 0xD384) 872 (def start-point-high 0xD385)
873 (def start-point-low 0xD386)
874
851 (def bytes-written 0xD385) 875 (def bytes-written 0xD385)
852 876
853 (defn write-memory [] 877 (defn write-memory []
854 (-> (tick (mid-game)) 878 (-> (tick (mid-game))
855 (IE! 0) ; disable interrupts 879 (IE! 0) ; disable interrupts
893 (view-memory current-mode) 917 (view-memory current-mode)
894 (step [:a]) 918 (step [:a])
895 (#(do (println "step with [:a]") %)) 919 (#(do (println "step with [:a]") %))
896 (view-memory current-mode) 920 (view-memory current-mode)
897 (view-memory bytes-to-write) 921 (view-memory bytes-to-write)
898 (view-memory start-point) 922 (view-memory start-point-high)
923 (view-memory start-point-low)
924 (#(do (println "step with [:a :b :start]")%))
925 (step [:a :b :start])
926 (view-memory current-mode)
927 (view-memory bytes-to-write)
928 (view-memory start-point-high)
929 (view-memory start-point-low)
930 (#(do (println "step with [:u :d]")%))
931 (step [:u :d])
932 (view-memory current-mode)
933 (view-memory bytes-to-write)
934 (view-memory start-point-high)
935 (view-memory start-point-low)
899 (#(do (println "step with [:u :d :l :r]")%)) 936 (#(do (println "step with [:u :d :l :r]")%))
900 (step [:u :d :l :r]) 937 (step [:u :d :l :r])
901 (view-memory current-mode) 938 (view-memory current-mode)
902 (view-memory bytes-to-write) 939 (view-memory bytes-to-write)
903 (view-memory start-point) 940 (view-memory start-point-high)
904 (#(do (println "step with [:u :d]")%)) 941 (view-memory start-point-low)
905 (step [:u :d]) 942
906 (view-memory current-mode)
907 (view-memory bytes-to-write)
908 (view-memory start-point)
909
910 )) 943 ))
911 944
912 945