comparison clojure/com/aurellem/run/bootstrap_0.clj @ 339:93e74ed34305

rewriting basic-writer assemly so that it is valid items
author Robert McIntyre <rlm@mit.edu>
date Sun, 08 Apr 2012 03:00:51 -0500
parents 92f0011925d2
children dea7e476eba7
comparison
equal deleted inserted replaced
338:92f0011925d2 339:93e74ed34305
872 (d-print "============== second cycle") 872 (d-print "============== second cycle")
873 (d-ticks 14) 873 (d-ticks 14)
874 (d-print "============== end") 874 (d-print "============== end")
875 (d-ticks 20))) 875 (d-ticks 20)))
876 876
877 877 ;;TMs at celadon store ---
878 ;;01 (any-number) mega punch
879 ;;02 (any-number) razor wind
880 ;;05 (any-number) mega kick
881 ;;07 (any-number) hyper beam
882 ;;09 (any-number) take down
883 ;;13 (only 1) ice beam
884 ;;17 (any-number) submission
885 ;;18 (only 1) counter
886 ;;32 (any-number) double team
887 ;;33 (any-number) reflect
888 ;;37 (any-number) egg bomb
889 ;;48 (only 1) rock slide
890 ;;49 (only 1) tri attack
891
892
893 ;; no-ops
894 ;; 0x00
895 ;; 0xB8 - 0xBF (compares) :garbage
896 ;; 0x3F clear carry flag :s.s.ticket
897 ;; 0x37 set carry flag :guard-spec [!]
898 ;; 0x33 increment SP :poke-doll [!]
899 ;; 0x3B decrement SP :coin
900
901 ;;0x7F A->A :garbage
902 ;;0x40 B->B :gold-teeth
903 ;;0x49 C->C :poke-flute
904 ;;0x52 D->D :elixer
905 ;;0x5B E->E :garbage
906 ;;0x6D L->L :garbage
907 ;;0x64 H->H :garbage
908
909
910 ;;0xC5 push BC :HM02
911 ;;0xD5 push DE :TM13 (ice-beam)
912 ;;0xE5 push HL :TM29 (psychic)
913 ;;0xF5 push AF :TM45 (thunder-wave)
914
915 ;; 0xA7 (AND A A) :garbage
916 ;; 0xB7 (OR A A) :garbage
917
918 ;; 0x2F (CPL A) :leaf-stone
919
920
921 (defn item-writer
922 "This is the basic writer, optimized to be made of valid
923 item-quantity pairs."
924 [target-address limit return-address]
925 (let [[target-high target-low] (disect-bytes-2 target-address)
926 [return-high return-low] (disect-bytes-2 return-address)]
927 (flatten
928 [
929 ;;0xC5 ;; push junk onto stack
930 ;;0xD5
931 ;;0xE5
932 ;;0xF5
933 0x37 ;; (item-hack) set cary flag no-op
934 0x1E ;; load limit into E
935 limit
936 0x3F ;; (item-hack) set carry flag no-op
937
938 ;; load 1 into C.
939 0x0E ;; C == 1 means input-first nybble
940 0x01 ;; C == 0 means input-second nybble
941
942 0x21 ;; load target into HL
943 target-low
944 target-high
945 0x37 ;; (item-hack) set carry flag no-op
946
947 0x2F ;; (item-hack) cpl A
948 0x2F ;; (item-hack) cpl A --together a spacer no-op
949
950 0x00 ;; (item-hack) no-op
951 0xF3 ;; disable interrupts
952 ;; Input Section
953
954 0x3E ;; load 0x20 into A, to measure buttons
955 0x10
956
957 0x00 ;; (item-hack) no-op
958 0xE0 ;; load A into [FF00]
959 0x00
960
961 0xF0 ;; load 0xFF00 into A to get
962 0x00 ;; button presses
963
964 0xE6
965 0x0F ;; select bottom four bits of A
966 0x37 ;; (item-hack) set carry flag no-op
967
968 0x00 ;; (item-hack) no-op
969 0xB8 ;; see if input is different (CP A B)
970
971 0x33 ;; (item-hack) (INC SP)
972 0x28 ;; repeat above steps if input is not different
973 ;; (jump relative backwards if B != A)
974 0xED ;; (literal -19) (item-hack) -19 == egg bomb (TM37)
975
976 0x47 ;; load A into B
977
978 0x0D ;; dec C
979 ;; branch based on C:
980 0x20 ;; JR NZ
981 0x07 ;; skip "input first nybble" below
982
983
984 ;; input first nybble
985
986 0xCB
987 0x37 ;; swap nybbles on A
988
989 0x57 ;; A -> D
990
991 0x18
992 0xEC ;; literal -20 -- go back to input section
993
994 ;; input second nybble
995
996 0x0C ;; inc C
997
998 0xE6 ;; select bottom bits
999 0x0F
1000
1001 0xB2 ;; (OR A D) -> A
1002
1003 0x22 ;; (do (A -> (HL)) (INC HL))
1004
1005 0x1D ;; (DEC E)
1006
1007 0x20 ;; jump back to input section if not done
1008 0xE4 ;; literal -28
1009
1010 ;; cleanup
1011 ;;0xF1
1012 ;;0xE1
1013 ;;0xD1
1014 ;;0xC1
1015
1016 0xFB ;; re-enable interrupts
1017
1018 0xC3
1019 return-low
1020 return-high ])))