comparison clojure/com/aurellem/assembly.clj @ 127:901ee6b648da

preliminary memory bootstrapping program complete.
author Robert McIntyre <rlm@mit.edu>
date Sat, 17 Mar 2012 03:43:42 -0500
parents 86f92deacd2a
children 203d64e16156
comparison
equal deleted inserted replaced
126:86f92deacd2a 127:901ee6b648da
665 665
666 0xCA ;D39C 666 0xCA ;D39C
667 0xCD ;D39D 667 0xCD ;D39D
668 0xD3 ;D39E ; goto Mode 3 if A == 3 668 0xD3 ;D39E ; goto Mode 3 if A == 3
669 669
670 0x00 ;D39F 670 ;; GOTO Mode 4 (write-memory) if current mode is 4
671 0x00 ;D3A0 671 0xFE ;D39F
672 0x00 ;D3A1 672 0x04 ;D3A0
673 0x00 ;D3A2 673
674 0x00 ;D3A3 674 0xCA ;D3A1
675 0xDB ;D3A2
676 0xD3 ;D3A3
677
675 0x00 ;D3A4 678 0x00 ;D3A4
676 ;; End of Mode checking, goto beginning 679 ;; End of Mode checking, goto beginning
677 0xC3 ;D3A5 680 0xC3 ;D3A5
678 0x1D ;D3A6 681 0x1D ;D3A6
679 0xD3 ;D3A7 682 0xD3 ;D3A7
793 ;; if they are the same, then reset mode to 0 796 ;; if they are the same, then reset mode to 0
794 797
795 0xFA ;D3DB ; load bytes-to-write into A 798 0xFA ;D3DB ; load bytes-to-write into A
796 0x83 ;D3DC 799 0x83 ;D3DC
797 0xD3 ;D3DD 800 0xD3 ;D3DD
801
798 0x47 ;D3DE ; load A into B 802 0x47 ;D3DE ; load A into B
803
799 0xFA ;D3DF ; load bytes-written into A 804 0xFA ;D3DF ; load bytes-written into A
800 0x84 ;D3E0 805 0x84 ;D3E0
801 0xD3 ;D3E1 806 0xD3 ;D3E1
807
802 0xB8 ;D3E2 ; compare A with B 808 0xB8 ;D3E2 ; compare A with B
809
803 0xCA ;D3E3 ; if they are equal, go to cleanup 810 0xCA ;D3E3 ; if they are equal, go to cleanup
811 0x07 ;D3E4
812 0xD4 ;D3E5
804 813
805 ;; Write Memory Section 814 ;; Write Memory Section
806 ;; Write the input-number, interpreted as an 8-bit number, 815 ;; Write the input-number, interpreted as an 8-bit number,
807 ;; into the current target register, determined by 816 ;; into the current target register, determined by
808 ;; (+ start-point bytes-written). 817 ;; (+ start-point bytes-written).
809 ;; Then, increment bytes-written by 1. 818 ;; Then, increment bytes-written by 1.
810 819
811 0x00 ;D3D6 820 0xFA ;D3E6 ; load start-point-high into A
812 0x00 ;D3D6 821 0x85 ;D3E7
813 0x00 ;D3D7 822 0xD3 ;D3E8
814 0x00 ;D3D8 823
815 0x00 ;D3D9 824 0x67 ;D3E9 ; load A into H
816 0x00 ;D3DA 825
817 0x00 ;D3DB 826 0xFA ;D3EA ; load start-point-low into A
818 0x00 ;D3DC 827 0x86 ;D3EB
819 0x00 ;D3DD 828 0xD3 ;D3EC
820 0x00 ;D3DE 829
821 0x00 ;D3DF 830 0x6F ;D3ED ; load A into L
822 0x00 ;D3E0 831
823 0x00 ;D3E1 832 0xFA ;D3EE ; load bytes-written into A
824 0x00 ;D3E2 833 0x84 ;D3EF
825 0x00 ;D3E3 834 0xD3 ;D3F0
826 0x00 ;D3E4 835
827 0x00 ;D3E5 836 0x00 ;D3F1 ; These are here because
828 0x00 ;D3E6 837 0x00 ;D3F2 ; I screwed up again.
829 0x00 ;D3E7
830 0x00 ;D3E8
831 0x00 ;D3E9
832 0x00 ;D3EA
833 0x00 ;D3EB
834 0x00 ;D3EC
835 0x00 ;D3ED
836 0x00 ;D3EE
837 0x00 ;D3EF
838 0x00 ;D3F0
839 0x00 ;D3F1
840 0x00 ;D3F2
841 0x00 ;D3F3 838 0x00 ;D3F3
842 0x00 ;D3F4 839
843 0x00 ;D3F5 840 0x85 ;D3F4 ; add L to A; store A in L.
844 0x00 ;D3F6 841 0x6F ;D3F5
845 0x00 ;D3F7 842
846 0x00 ;D3F8 843 0x30 ;D3F6 ; If the addition overflowed,
847 0x00 ;D3F9 844 0x01 ;D3F7
848 0x00 ;D3FA 845 0x24 ;D3F8 ; increment H.
849 0x00 ;D3FB 846
850 0x00 ;D3FC 847 ;; Now, HL points to the correct place in memory
851 0x00 ;D3FD 848
852 0x00 ;D3FE 849 0xFA ;D3F9 ; load input-number into A
853 850 0x52 ;D3FA
854 851 0xD3 ;D3FB
855 852
856 853 0x77 ;D3FC ; load A into (HL)
857 854
858 0xC3 ; ; Complete Loop 855 0xFA ;D3FD ; load bytes-written into A
859 0x1D ; 856 0x84 ;D3FE
860 0xD3 ; 857 0xD3 ;D3FF
861 858
862 859 0x3C ;D400 ; increment A
860
861 0xEA ;D401 ; load A into bytes-written
862 0x84 ;D402
863 0xD3 ;D403
864
865 0xC3 ;D404 ; go back to beginning.
866 0x1D ;D405
867 0xD3 ;D406
868 ;; End Write Memory Section
869
870 ;; Mode 4 Cleanup Section
871 ;; reset bytes-written to 0
872 ;; set mode to 0
873 0x3E ;D407 ; load 0 into A
874 0x00 ;D408
875
876 0xEA ;D409 ; load A into bytes-written
877 0x84 ;D40A
878 0xD3 ;D40B
879
880 0xEA ;D40C ; load A into current-mode
881 0x82 ;D40D
882 0xD3 ;D40E
883
884 0xC3 ;D40F ; go back to beginning
885 0x1D ;D410
886 0xD3 ;D411
887
888 ;; End Mode 4
863 889
864 ]) 890 ])
865 891
866 892
867 893
868 (def frame-count 0xD31F) 894 (def frame-count 0xD31F)
869 (def input 0xD352) 895 (def input 0xD352)
870 (def current-mode 0xD382) 896 (def current-mode 0xD382)
871 (def bytes-to-write 0xD383) 897 (def bytes-to-write 0xD383)
872 (def start-point-high 0xD385) 898 (def bytes-written 0xD384)
873 (def start-point-low 0xD386) 899 (def start-point-high 0xD385)
874 900 (def start-point-low 0xD386)
875 (def bytes-written 0xD385) 901
902
876 903
877 (defn write-memory [] 904 (defn write-memory []
878 (-> (tick (mid-game)) 905 (-> (tick (mid-game))
879 (IE! 0) ; disable interrupts 906 (IE! 0) ; disable interrupts
880 (inject-item-assembly (write-memory-assembly)))) 907 (inject-item-assembly (write-memory-assembly))))
904 (step [:b]) 931 (step [:b])
905 (step [:start]) 932 (step [:start])
906 (step []) 933 (step [])
907 (view-memory frame-count))) 934 (view-memory frame-count)))
908 935
909 (defn test-mode-2 [] 936 (defn test-mode-4 []
910 (-> 937 (->
911 (write-memory) 938 (write-memory)
939 (#(do (println "memory from 0xC00F to 0xC01F:"
940 (subvec (vec (memory %)) 0xC00F 0xC01F)) %))
912 (view-memory current-mode) 941 (view-memory current-mode)
913 (step []) 942 (step [])
914 (step []) 943 (step [])
915 (step []) 944 (step [])
916 (#(do (println "after three steps") %)) 945 (#(do (println "after three steps") %))
917 (view-memory current-mode) 946 (view-memory current-mode)
947
948 ;; Activate memory writing mode
949
950 (#(do (println "step with [:a]") %))
918 (step [:a]) 951 (step [:a])
919 (#(do (println "step with [:a]") %))
920 (view-memory current-mode) 952 (view-memory current-mode)
921 (view-memory bytes-to-write) 953 (view-memory bytes-to-write)
922 (view-memory start-point-high) 954 (view-memory start-point-high)
923 (view-memory start-point-low) 955 (view-memory start-point-low)
924 (#(do (println "step with [:a :b :start]")%)) 956
925 (step [:a :b :start]) 957 ;; Specify four bytes to be written
958
959 (#(do (println "step with [:select]")%))
960 (step [:select])
926 (view-memory current-mode) 961 (view-memory current-mode)
927 (view-memory bytes-to-write) 962 (view-memory bytes-to-write)
928 (view-memory start-point-high) 963 (view-memory start-point-high)
929 (view-memory start-point-low) 964 (view-memory start-point-low)
965
966 ;; Specify target memory address as 0xC00F
967
930 (#(do (println "step with [:u :d]")%)) 968 (#(do (println "step with [:u :d]")%))
931 (step [:u :d]) 969 (step [:u :d])
932 (view-memory current-mode) 970 (view-memory current-mode)
933 (view-memory bytes-to-write) 971 (view-memory bytes-to-write)
934 (view-memory start-point-high) 972 (view-memory start-point-high)
935 (view-memory start-point-low) 973 (view-memory start-point-low)
936 (#(do (println "step with [:u :d :l :r]")%)) 974
937 (step [:u :d :l :r]) 975 (#(do (println "step with [:a :b :start :select]")%))
976 (step [:a :b :start :select])
938 (view-memory current-mode) 977 (view-memory current-mode)
939 (view-memory bytes-to-write) 978 (view-memory bytes-to-write)
940 (view-memory start-point-high) 979 (view-memory start-point-high)
941 (view-memory start-point-low) 980 (view-memory start-point-low)
942 981
943 )) 982 ;; Start reprogramming memory
944 983
945 984 (#(do (println "step with [:a]")%))
985 (step [:a])
986 (view-memory current-mode)
987 (view-memory bytes-written)
988
989 (#(do (println "step with [:b]")%))
990 (step [:b])
991 (view-memory current-mode)
992 (view-memory bytes-written)
993
994 (#(do (println "step with [:a :b]")%))
995 (step [:a :b])
996 (view-memory current-mode)
997 (view-memory bytes-written)
998
999 (#(do (println "step with [:select]")%))
1000 (step [:select])
1001 (view-memory current-mode)
1002 (view-memory bytes-written)
1003
1004 ;; Reprogramming done, program ready for more commands.
1005
1006 (#(do (println "step with []")%))
1007 (step [])
1008 (view-memory current-mode)
1009 (view-memory bytes-written)
1010
1011 (#(do (println "memory from 0xC00F to 0xC01F:"
1012 (subvec (vec (memory %)) 0xC00F 0xC01F)) %))))
1013
1014