comparison clojure/com/aurellem/assembly.clj @ 125:d2e00c923bad

need to add another mode to handle 16 bit start point
author Robert McIntyre <rlm@mit.edu>
date Sat, 17 Mar 2012 02:00:02 -0500
parents f8dadd9478a5
children 86f92deacd2a
comparison
equal deleted inserted replaced
124:f8dadd9478a5 125:d2e00c923bad
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 ; start-point
627 0x00 ;D385 ; unused 627 0x00 ;D385 ; bytes-written
628 0x00 ;D386 ; unused 628 0x00 ;D386 ; unused
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)
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 0x00 ;D39A 662 ;; GOTO Mode 3 (write-memory) if current mode is 3
663 0x00 ;D39B 663 0xFE ;D39A
664 0x03 ;D39B
665
664 0x00 ;D39C 666 0x00 ;D39C
665 0x00 ;D39D 667 0xCA ;D39D
666 0x00 ;D39E 668 0xXX ;D39E
667 0x00 ;D39F 669 0xXX ;D39F
668 0x00 ;D3A0 670 0x00 ;D3A0
669 0x00 ;D3A1 671 0x00 ;D3A1
670 0x00 ;D3A2 672 0x00 ;D3A2
671 0x00 ;D3A3 673 0x00 ;D3A3
672 0x00 ;D3A4 674 0x00 ;D3A4
750 752
751 0xC3 ;D3CA ; go back to beginning 753 0xC3 ;D3CA ; go back to beginning
752 0x1D ;D3CB 754 0x1D ;D3CB
753 0xD3 ;D3CC 755 0xD3 ;D3CC
754 ;;End Mode 2 756 ;;End Mode 2
755 757
756 0x00 ;D3CD 758
757 0x00 ;D3CE 759 ;; Mode 3 -- write bytes mode
758 0x00 ;D3CF 760
759 0x00 ;D3D0 761 ;; This is where RAM manipulation happens. User supplies
760 0x00 ;D3D1 762 ;; bytes every frame, which are written sequentially to
761 0x00 ;D3D2 763 ;; start-point until bytes-to-write have been written. Once
762 0x00 ;D3D3 764 ;; bytes-to-write have been written, the mode is reset to 0.
763 0x00 ;D3D4 765
764 0x00 ;D3D5 766 ;; compare bytes-written with bytes-to-write.
767 ;; if they are the same, then reset mode to 0
768
769 0xFA ;D3CD ; load bytes-to-write into A
770 0x83 ;D3CE
771 0xD3 ;D3CF
772
773 0x47 ;D3D0 ; load A into B
774
775 0xFA ;D3D1 ; load bytes-written into A
776 0x82 ;D3D2
777 0xD3 ;D3D3
778
779 0xB8 ;D3D4 ; compare A with B
780
781 0xCA ;D3D5 ; if they are equal, go to cleanup
782
783 ;; Write Memory Section
784 ;; Write the input-number, interpreted as an 8-bit number,
785 ;; into the current target register, determined by
786 ;; (+ start-point bytes-written).
787 ;; Then, increment bytes-written by 1.
788
765 0x00 ;D3D6 789 0x00 ;D3D6
766 790 0x00 ;D3D6
767 ;; Mode 3 -- write bytes mode 791 0x00 ;D3D7
768 ;; This is where RAM manipulation happens. 792 0x00 ;D3D8
769 ;; User supplies bytes every frame, which are written 793 0x00 ;D3D9
770 ;; sequentially to 794 0x00 ;D3DA
795 0x00 ;D3DB
796 0x00 ;D3DC
797 0x00 ;D3DD
798 0x00 ;D3DE
799 0x00 ;D3DF
800 0x00 ;D3E0
801 0x00 ;D3E1
802 0x00 ;D3E2
803 0x00 ;D3E3
804 0x00 ;D3E4
805 0x00 ;D3E5
806 0x00 ;D3E6
807 0x00 ;D3E7
808 0x00 ;D3E8
809 0x00 ;D3E9
810 0x00 ;D3EA
811 0x00 ;D3EB
812 0x00 ;D3EC
813 0x00 ;D3ED
814 0x00 ;D3EE
815 0x00 ;D3EF
816 0x00 ;D3F0
817 0x00 ;D3F1
818 0x00 ;D3F2
819 0x00 ;D3F3
820 0x00 ;D3F4
821 0x00 ;D3F5
822 0x00 ;D3F6
823 0x00 ;D3F7
824 0x00 ;D3F8
825 0x00 ;D3F9
826 0x00 ;D3FA
827 0x00 ;D3FB
828 0x00 ;D3FC
829 0x00 ;D3FD
830 0x00 ;D3FE
831
771 832
772 833
773 834
774 835
775 0xC3 ; ; Complete Loop 836 0xC3 ; ; Complete Loop
785 (def frame-count 0xD31F) 846 (def frame-count 0xD31F)
786 (def input 0xD352) 847 (def input 0xD352)
787 (def current-mode 0xD382) 848 (def current-mode 0xD382)
788 (def bytes-to-write 0xD383) 849 (def bytes-to-write 0xD383)
789 (def start-point 0xD384) 850 (def start-point 0xD384)
790 851 (def bytes-written 0xD385)
791 852
792 (defn write-memory [] 853 (defn write-memory []
793 (-> (tick (mid-game)) 854 (-> (tick (mid-game))
794 (IE! 0) ; disable interrupts 855 (IE! 0) ; disable interrupts
795 (inject-item-assembly (write-memory-assembly)))) 856 (inject-item-assembly (write-memory-assembly))))
800 (dotimes [_ 5000] 861 (dotimes [_ 5000]
801 (view-memory (step @current-state) current-mode)))) 862 (view-memory (step @current-state) current-mode))))
802 863
803 (def bytes-to-write 0xD383) 864 (def bytes-to-write 0xD383)
804 (def start-point 0xD384) 865 (def start-point 0xD384)
866
867 (defn print-blank-assembly
868 [start end]
869 (dorun
870 (map
871 #(println (format "0x00 ;%04X " %))
872 (range start end))))
805 873
806 (defn test-mode-2 [] 874 (defn test-mode-2 []
807 (-> 875 (->
808 (write-memory) 876 (write-memory)
809 (view-memory frame-count) 877 (view-memory frame-count)
827 (#(do (println "step with [:a]") %)) 895 (#(do (println "step with [:a]") %))
828 (view-memory current-mode) 896 (view-memory current-mode)
829 (view-memory bytes-to-write) 897 (view-memory bytes-to-write)
830 (view-memory start-point) 898 (view-memory start-point)
831 (#(do (println "step with [:u :d :l :r]")%)) 899 (#(do (println "step with [:u :d :l :r]")%))
832 (step [:u :d]) 900 (step [:u :d :l :r])
833 (view-memory current-mode) 901 (view-memory current-mode)
834 (view-memory bytes-to-write) 902 (view-memory bytes-to-write)
835 (view-memory start-point) 903 (view-memory start-point)
836 (#(do (println "step with [:u :d]")%)) 904 (#(do (println "step with [:u :d]")%))
837 (step [:u :d]) 905 (step [:u :d])