Mercurial > vba-clojure
comparison clojure/com/aurellem/run/bootstrap_0.clj @ 343:652c5abee892
constructing exact item-pc layout for item-writer.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sun, 08 Apr 2012 08:27:55 -0500 |
parents | 4e0b64ea7b66 |
children | 9366539d29b6 |
comparison
equal
deleted
inserted
replaced
342:4e0b64ea7b66 | 343:652c5abee892 |
---|---|
1028 (reverse (disect-bytes-2 (inc pc-item-list-start)))) | 1028 (reverse (disect-bytes-2 (inc pc-item-list-start)))) |
1029 (set-memory-range | 1029 (set-memory-range |
1030 (inc pc-item-list-start) | 1030 (inc pc-item-list-start) |
1031 (item-writer 0xD162 201 0xD162)))) | 1031 (item-writer 0xD162 201 0xD162)))) |
1032 | 1032 |
1033 | |
1034 (defn item-writer-state [] | 1033 (defn item-writer-state [] |
1035 (read-state "item-writer")) | 1034 (read-state "item-writer")) |
1036 | 1035 |
1037 (defn test-item-writer-2 [] | 1036 (defn test-item-writer-2 [] |
1038 (let [orig (item-writer-state)] | 1037 (let [orig (item-writer-state)] |
1039 (-> orig | 1038 (-> orig |
1040 (print-listing 0xD162 (+ 0xD162 20)) | 1039 (print-listing 0xD162 (+ 0xD162 20)) |
1041 (run-moves (reduce | 1040 (run-moves (reduce concat |
1042 concat [[:a] [:b]] | 1041 (repeat 10 [[:a :b :start :select] []]))) |
1043 (repeat 5 [[:a :b :start :select] []]))) | |
1044 ((fn [_] (println "===========") _)) | 1042 ((fn [_] (println "===========") _)) |
1045 (print-listing 0xD162 (+ 0xD162 20))))) | 1043 (print-listing 0xD162 (+ 0xD162 20))))) |
1046 | 1044 |
1045 (defn pc-item-writer-program | |
1046 [] | |
1047 (let [limit 201 | |
1048 [target-high target-low] (disect-bytes-2 0xD162)] | |
1049 (flatten | |
1050 [[0x00 ;; (item-hack) set increment stack pointer no-op | |
1051 0x1E ;; load limit into E | |
1052 limit | |
1053 0x3F ;; (item-hack) set carry flag no-op | |
1054 | |
1055 ;; load 2 into C. | |
1056 0x0E ;; C == 1 means input-first nybble | |
1057 0x04 ;; C == 0 means input-second nybble | |
1058 | |
1059 0x21 ;; load target into HL | |
1060 target-low | |
1061 target-high | |
1062 0x37 ;; (item-hack) set carry flag no-op | |
1063 | |
1064 0x2F ;; (item-hack) cpl A | |
1065 0x2F ;; (item-hack) cpl A --together a spacer no-op | |
1066 | |
1067 0x00 ;; (item-hack) no-op | |
1068 0xF3 ;; disable interrupts | |
1069 ;; Input Section | |
1070 | |
1071 0x3E ;; load 0x20 into A, to measure buttons | |
1072 0x10 | |
1073 | |
1074 0x00 ;; (item-hack) no-op | |
1075 0xE0 ;; load A into [FF00] | |
1076 0x00 | |
1077 | |
1078 0xF0 ;; load 0xFF00 into A to get | |
1079 0x00 ;; button presses | |
1080 | |
1081 0xE6 | |
1082 0x0F ;; select bottom four bits of A | |
1083 0x37 ;; (item-hack) set carry flag no-op | |
1084 | |
1085 0x00 ;; (item-hack) no-op | |
1086 0xB8 ;; see if input is different (CP A B) | |
1087 | |
1088 0x00 ;; (item-hack) (INC SP) | |
1089 0x28 ;; repeat above steps if input is not different | |
1090 ;; (jump relative backwards if B != A) | |
1091 0xED ;; (literal -19) (item-hack) -19 == egg bomb (TM37) | |
1092 | |
1093 0x47 ;; load A into B | |
1094 | |
1095 0x0D ;; dec C | |
1096 0x37 ;; (item-hack) set-carry flag | |
1097 ;; branch based on C: | |
1098 0x20 ;; JR NZ | |
1099 23 ;; skip "input second nybble" and "jump to target" below | |
1100 | |
1101 ;; input second nybble | |
1102 | |
1103 0x0C ;; inc C | |
1104 0x0C ;; inc C | |
1105 | |
1106 0x00 ;; (item-hack) no-op | |
1107 0xE6 ;; select bottom bits | |
1108 0x0F | |
1109 0x37 ;; (item-hack) set-carry flag no-op | |
1110 | |
1111 0x00 ;; (item-hack) no-op | |
1112 0xB2 ;; (OR A D) -> A | |
1113 | |
1114 0x22 ;; (do (A -> (HL)) (INC HL)) | |
1115 | |
1116 0x1D ;; (DEC E) | |
1117 | |
1118 0x00 ;; (item-hack) | |
1119 0x20 ;; jump back to input section if not done | |
1120 0xDA ;; literal -36 == TM 18 (counter) | |
1121 0x01 ;; (item-hack) set BC to literal (no-op) | |
1122 | |
1123 ;; jump to target | |
1124 0x00 ;; (item-hack) these two bytes can be anything. | |
1125 0x01 | |
1126 | |
1127 0x00 ;; (item-hack) no-op | |
1128 0xBF ;; (CP A A) ensures Z | |
1129 | |
1130 0xCA ;; (item-hack) jump if Z | |
1131 target-low | |
1132 target-high | |
1133 0x01 ;; (item-hack) will never be reached. | |
1134 | |
1135 ;; input first nybble | |
1136 0x00 | |
1137 0xCB | |
1138 0x37 ;; swap nybbles on A | |
1139 | |
1140 0x57 ;; A -> D | |
1141 | |
1142 0x37 ;; (item-hack) set carry flag no-op | |
1143 0x18 ;; relative jump backwards | |
1144 0xCD ;; literal -51 == TM05; go back to input section | |
1145 0x01 ;; (item-hack) will never reach this instruction | |
1146 | |
1147 ] | |
1148 (repeat 8 [0xFF 0x01]) | |
1149 | |
1150 [;; jump to actual program | |
1151 0x00 | |
1152 0x37 ;; (item-hack) set carry flag no-op | |
1153 | |
1154 0x00 | |
1155 0x21 | |
1156 | |
1157 0x3A | |
1158 0xD5 | |
1159 | |
1160 ;; 0x00 | |
1161 ;; 0x44 ;; H -> B | |
1162 | |
1163 ;; 0x00 | |
1164 ;; 0x7D ;; L -> A | |
1165 | |
1166 ;; 0x00 | |
1167 ;; 0x7C ;; A -> H | |
1168 | |
1169 ;; 0x00 | |
1170 ;; 0x68 ;; B -> L | |
1171 | |
1172 0x00 | |
1173 0xE9 ;; jump to (HL) | |
1174 ]]))) | |
1175 | |
1176 | |
1177 (defn test-pc-item-writer [] | |
1178 (-> (read-state "bootstrap-init") | |
1179 (set-memory pc-item-list-start 50) | |
1180 (set-memory-range | |
1181 map-function-address-start | |
1182 [0x8B 0xD5]) | |
1183 (set-memory-range | |
1184 (inc pc-item-list-start) | |
1185 (pc-item-writer-program)))) | |
1186 | |
1187 (defn test-pc-item-writer-2 [] | |
1188 (let [orig (read-state "pc-item-writer")] | |
1189 (-> orig | |
1190 (print-listing 0xD162 (+ 0xD162 20)) | |
1191 (run-moves (reduce concat | |
1192 (repeat 10 [[:a :b :start :select] []]))) | |
1193 ((fn [_] (println "===========") _)) | |
1194 (print-listing 0xD162 (+ 0xD162 20))))) |