Mercurial > vba-clojure
comparison clojure/com/aurellem/run/bootstrap_0.clj @ 338:92f0011925d2
created 40-byte program to bootstrap main bootstrap program
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 07 Apr 2012 12:31:12 -0500 |
parents | 2dd40f6b6a1f |
children | 93e74ed34305 |
comparison
equal
deleted
inserted
replaced
337:2dd40f6b6a1f | 338:92f0011925d2 |
---|---|
748 0x01 | 748 0x01 |
749 | 749 |
750 0x04 ;; target ID (pokeball) | 750 0x04 ;; target ID (pokeball) |
751 0x3E ;; target Quantity (lemonade) | 751 0x3E ;; target Quantity (lemonade) |
752 ]])))) | 752 ]])))) |
753 | |
754 | |
755 | |
756 | |
757 | |
758 (defn basic-writer [target-address limit return-address] | |
759 (let [[target-high target-low] (disect-bytes-2 target-address) | |
760 [return-high return-low] (disect-bytes-2 return-address)] | |
761 (flatten | |
762 [0xF3 ;; disable interrupts | |
763 ;;0xC5 ;; push junk onto stack | |
764 ;;0xD5 | |
765 ;;0xE5 | |
766 ;;0xF5 | |
767 | |
768 0x1E ;; load limit into E | |
769 limit | |
770 | |
771 0x21 ;; load target into HL | |
772 target-low | |
773 target-high | |
774 | |
775 ;; load 1 into C. | |
776 0x0E ;; C == 1 means input-first nybble | |
777 0x01 ;; C == 0 means input-second nybble | |
778 | |
779 | |
780 ;; Input Section | |
781 | |
782 0x3E ;; load 0x20 into A, to measure dpad | |
783 0x20 | |
784 | |
785 0xE0 ;; load A into [FF00] | |
786 0x00 | |
787 | |
788 0xF0 ;; load 0xFF00 into A to get | |
789 0x00 ;; d-pad presses | |
790 | |
791 0xE6 | |
792 0x0F ;; select bottom four bits of A | |
793 | |
794 0xB8 ;; see if input is different (CP A B) | |
795 | |
796 0x28 ;; repeat above steps if input is not different | |
797 ;; (jump relative backwards if B != A) | |
798 0xF5 ;; (literal -11) | |
799 | |
800 0x47 ;; load A into B | |
801 | |
802 0x0D ;; dec C | |
803 ;; branch based on C: | |
804 0x20 ;; JR NZ | |
805 0x07 ;; skip "input first nybble" below | |
806 | |
807 | |
808 ;; input first nybble | |
809 | |
810 0xCB | |
811 0x37 ;; swap nybbles on A | |
812 | |
813 0x57 ;; A -> D | |
814 | |
815 0x18 | |
816 0xEC ;; literal -20 -- go back to input section | |
817 | |
818 ;; input second nybble | |
819 | |
820 0x0C ;; inc C | |
821 | |
822 0xE6 ;; select bottom bits | |
823 0x0F | |
824 | |
825 0xB2 ;; (OR A D) -> A | |
826 | |
827 0x22 ;; (do (A -> (HL)) (INC HL)) | |
828 | |
829 0x1D ;; (DEC E) | |
830 | |
831 0x20 ;; jump back to input section if not done | |
832 0xE4 ;; literal -28 | |
833 | |
834 ;; cleanup | |
835 ;;0xF1 | |
836 ;;0xE1 | |
837 ;;0xD1 | |
838 ;;0xC1 | |
839 | |
840 0xFB ;; re-enable interrupts | |
841 | |
842 0xC3 | |
843 return-low | |
844 return-high ]))) | |
845 | |
846 | |
847 (defn test-basic-writer [] | |
848 (-> (read-state "bootstrap-init") | |
849 (set-memory pc-item-list-start 50) | |
850 (set-memory-range | |
851 map-function-address-start | |
852 (reverse (disect-bytes-2 (inc pc-item-list-start)))) | |
853 (set-memory-range | |
854 (inc pc-item-list-start) | |
855 (basic-writer 0xD162 10 0x5F0C)))) | |
856 | |
857 (defn debug-basic-writer [] | |
858 (PC! (test-basic-writer) (inc pc-item-list-start))) | |
859 | |
860 (defn d-ticks [state n] | |
861 (reduce (fn [state _] (d-tick state)) | |
862 state (range n))) | |
863 | |
864 (defn d-print [state message] | |
865 (println message) state) | |
866 | |
867 (defn dddd | |
868 [] | |
869 (-> (debug-basic-writer) | |
870 (d-ticks 20) | |
871 (set-memory 0xFF00 0xFF) | |
872 (d-print "============== second cycle") | |
873 (d-ticks 14) | |
874 (d-print "============== end") | |
875 (d-ticks 20))) | |
876 | |
877 |