changeset 184:d585b91de06c

Added a worlds directory for worldbuilding practice, and added some assembly-reading utilities.
author Dylan Holmes <ocsenave@gmail.com>
date Thu, 22 Mar 2012 06:58:18 -0500
parents 5e34473ac774
children c8ec477beeac
files clojure/com/aurellem/gb/assembly.clj
diffstat 1 files changed, 307 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/assembly.clj	Wed Mar 21 23:19:01 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/assembly.clj	Thu Mar 22 06:58:18 2012 -0500
     1.3 @@ -1438,3 +1438,310 @@
     1.4        (#(do (println "memory from 0xC00F to 0xC01F:"
     1.5                       (subvec (vec (memory %)) 0xC00F 0xC01F)) %)))))
     1.6  
     1.7 +
     1.8 +
     1.9 +
    1.10 +
    1.11 +
    1.12 +;;; ASSEMBLY-READING UTILITIES
    1.13 +
    1.14 +(def opcodes
    1.15 +  [
    1.16 +   "NOP"
    1.17 +   "LD BC,nn"
    1.18 +   "LD (BC),A"
    1.19 +   "INC BC"
    1.20 +   "INC B"
    1.21 +   "DEC B"
    1.22 +   "LD B,n"
    1.23 +   "RLC A"
    1.24 +   "LD (nn),SP"
    1.25 +   "ADD HL,BC"
    1.26 +   "LD A,(BC)"
    1.27 +   "DEC BC"
    1.28 +   "INC C"
    1.29 +   "DEC C"
    1.30 +   "LD C,n"
    1.31 +   "RRC A"
    1.32 +
    1.33 +   "STOP"
    1.34 +   "LD DE,nn"
    1.35 +   "LD (DE),A"
    1.36 +   "INC DE"
    1.37 +   "INC D"
    1.38 +   "DEC D"
    1.39 +   "LD D,n"
    1.40 +   "RL A"
    1.41 +   "JR n"
    1.42 +   "ADD HL,DE"
    1.43 +   "LD A,(DE)"
    1.44 +   "DEC DE"
    1.45 +   "INC E"
    1.46 +   "DEC E"
    1.47 +   "LD E,n"
    1.48 +   "RR A"
    1.49 +
    1.50 +   "JR NZ,n"
    1.51 +   "LD HL,nn"
    1.52 +   "LDI (HL),A"
    1.53 +   "INC HL"
    1.54 +   "INC H"
    1.55 +   "DEC H"
    1.56 +   "LD H,n"
    1.57 +   "DAA"
    1.58 +   "JR Z,n"
    1.59 +   "ADD HL,HL"
    1.60 +   "LDI A,(HL)"
    1.61 +   "DEC HL"
    1.62 +   "INC L"
    1.63 +   "DEC L"
    1.64 +   "LD L,n"
    1.65 +   "CPL"
    1.66 +
    1.67 +   "JR NC,n"
    1.68 +   "LD SP,nn"
    1.69 +   "LDD (HL),A"
    1.70 +   "INC SP"
    1.71 +   "INC (HL)"
    1.72 +   "DEC (HL)"
    1.73 +   "LD (HL),n"
    1.74 +   "SCF"
    1.75 +   "JR C,n"
    1.76 +   "ADD HL,SP"
    1.77 +   "LDD A,(HL)"
    1.78 +   "DEC SP"
    1.79 +   "INC A"
    1.80 +   "DEC A"
    1.81 +   "LD A,n"
    1.82 +   "CCF"
    1.83 +
    1.84 +   "LD B,B"
    1.85 +   "LD B,C"
    1.86 +   "LD B,D"
    1.87 +   "LD B,E"
    1.88 +   "LD B,H"
    1.89 +   "LD B,L"
    1.90 +   "LD B,(HL)"
    1.91 +   "LD B,A"
    1.92 +   "LD C,B"
    1.93 +   "LD C,C"
    1.94 +   "LD C,D"
    1.95 +   "LD C,E"
    1.96 +   "LD C,H"
    1.97 +   "LD C,L"
    1.98 +   "LD C,(HL)"
    1.99 +   "LD C,A"
   1.100 +
   1.101 +   "LD D,B"
   1.102 +   "LD D,C"
   1.103 +   "LD D,D"
   1.104 +   "LD D,E"
   1.105 +   "LD D,H"
   1.106 +   "LD D,L"
   1.107 +   "LD D,(HL)"
   1.108 +   "LD D,A"
   1.109 +   "LD E,B"
   1.110 +   "LD E,C"
   1.111 +   "LD E,D"
   1.112 +   "LD E,E"
   1.113 +   "LD E,H"
   1.114 +   "LD E,L"
   1.115 +   "LD E,(HL)"
   1.116 +   "LD E,A"
   1.117 +
   1.118 +   "LD H,B"
   1.119 +   "LD H,C"
   1.120 +   "LD H,D"
   1.121 +   "LD H,E"
   1.122 +   "LD H,H"
   1.123 +   "LD H,L"
   1.124 +   "LD H,(HL)"
   1.125 +   "LD H,A"
   1.126 +   "LD L,B"
   1.127 +   "LD L,C"
   1.128 +   "LD L,D"
   1.129 +   "LD L,E"
   1.130 +   "LD L,H"
   1.131 +   "LD L,L"
   1.132 +   "LD L,(HL)"
   1.133 +   "LD L,A"
   1.134 +
   1.135 +   "LD (HL),B"
   1.136 +   "LD (HL),C"
   1.137 +   "LD (HL),D"
   1.138 +   "LD (HL),E"
   1.139 +   "LD (HL),H"
   1.140 +   "LD (HL),L"
   1.141 +   "HALT"
   1.142 +   "LD (HL),A"
   1.143 +   "LD A,B"
   1.144 +   "LD A,C"
   1.145 +   "LD A,D"
   1.146 +   "LD A,E"
   1.147 +   "LD A,H"
   1.148 +   "LD A,L"
   1.149 +   "LD A,(HL)"
   1.150 +   "LD A,A"
   1.151 +
   1.152 +   "ADD A,B"
   1.153 +   "ADD A,C"
   1.154 +   "ADD A,D"
   1.155 +   "ADD A,E"
   1.156 +   "ADD A,H"
   1.157 +   "ADD A,L"
   1.158 +   "ADD A,(HL)"
   1.159 +   "ADD A,A"
   1.160 +   "ADC A,B"
   1.161 +   "ADC A,C"
   1.162 +   "ADC A,D"
   1.163 +   "ADC A,E"
   1.164 +   "ADC A,H"
   1.165 +   "ADC A,L"
   1.166 +   "ADC A,(HL)"
   1.167 +   "ADC A,A"
   1.168 +
   1.169 +   "SUB A,B"
   1.170 +   "SUB A,C"
   1.171 +   "SUB A,D"
   1.172 +   "SUB A,E"
   1.173 +   "SUB A,H"
   1.174 +   "SUB A,L"
   1.175 +   "SUB A,(HL)"
   1.176 +   "SUB A,A"
   1.177 +   "SBC A,B"
   1.178 +   "SBC A,C"
   1.179 +   "SBC A,D"
   1.180 +   "SBC A,E"
   1.181 +   "SBC A,H"
   1.182 +   "SBC A,L"
   1.183 +   "SBC A,(HL)"
   1.184 +   "SBC A,A"
   1.185 +
   1.186 +   "AND B"
   1.187 +   "AND C"
   1.188 +   "AND D"
   1.189 +   "AND E"
   1.190 +   "AND H"
   1.191 +   "AND L"
   1.192 +   "AND (HL)"
   1.193 +   "AND A"
   1.194 +   "XOR B"
   1.195 +   "XOR C"
   1.196 +   "XOR D"
   1.197 +   "XOR E"
   1.198 +   "XOR H"
   1.199 +   "XOR L"
   1.200 +   "XOR (HL)"
   1.201 +   "XOR A"
   1.202 +
   1.203 +   "OR B"
   1.204 +   "OR C"
   1.205 +   "OR D"
   1.206 +   "OR E"
   1.207 +   "OR H"
   1.208 +   "OR L"
   1.209 +   "OR (HL)"
   1.210 +   "OR A"
   1.211 +   "CP B"
   1.212 +   "CP C"
   1.213 +   "CP D"
   1.214 +   "CP E"
   1.215 +   "CP H"
   1.216 +   "CP L"
   1.217 +   "CP (HL)"
   1.218 +   "CP A"
   1.219 +
   1.220 +   "RET NZ"
   1.221 +   "POP BC"
   1.222 +   "JP NZ,nn"
   1.223 +   "JP nn"
   1.224 +   "CALL NZ,nn"
   1.225 +   "PUSH BC"
   1.226 +   "ADD A,n"
   1.227 +   "RST 0"
   1.228 +   "RET Z"
   1.229 +   "RET"
   1.230 +   "JP Z,nn"
   1.231 +   "Ext ops"
   1.232 +   "CALL Z,nn"
   1.233 +   "CALL nn"
   1.234 +   "ADC A,n"
   1.235 +   "RST 8"
   1.236 +
   1.237 +   "RET NC"
   1.238 +   "POP DE"
   1.239 +   "JP NC,nn"
   1.240 +   "XX"
   1.241 +   "CALL NC,nn"
   1.242 +   "PUSH DE"
   1.243 +   "SUB A,n"
   1.244 +   "RST 10"
   1.245 +   "RET C"
   1.246 +   "RETI"
   1.247 +   "JP C,nn"
   1.248 +   "XX"
   1.249 +   "CALL C,nn"
   1.250 +   "XX"
   1.251 +   "SBC A,n"
   1.252 +   "RST 18"
   1.253 +
   1.254 +   "LDH (n),A"
   1.255 +   "POP HL"
   1.256 +   "LDH (C),A"
   1.257 +   "XX"
   1.258 +   "XX"
   1.259 +   "PUSH HL"
   1.260 +   "AND n"
   1.261 +   "RST 20"
   1.262 +   "ADD SP,d"
   1.263 +   "JP (HL)"
   1.264 +   "LD (nn),A"
   1.265 +   "XX"
   1.266 +   "XX"
   1.267 +   "XX"
   1.268 +   "XOR n"
   1.269 +   "RST 28"
   1.270 +
   1.271 +   "LDH A,(n)"
   1.272 +   "POP AF"
   1.273 +   "XX"
   1.274 +   "DI"
   1.275 +   "XX"
   1.276 +   "PUSH AF"
   1.277 +   "OR n"
   1.278 +   "RST 30"
   1.279 +   "LDHL SP,d"
   1.280 +   "LD SP,HL"
   1.281 +   "LD A,(nn)"
   1.282 +   "EI"
   1.283 +   "XX"
   1.284 +   "XX"
   1.285 +   "CP n"
   1.286 +   "RST 38"])
   1.287 +
   1.288 +
   1.289 +(defn hex
   1.290 +  "Converts the number into a hexadecimal-formatted symbol."
   1.291 +  [n]
   1.292 +  (symbol (str "0x" (.toUpperCase (Integer/toHexString n)))))
   1.293 +
   1.294 +
   1.295 +
   1.296 +(defn arity
   1.297 +  "Returns the arity of the given opcode (hex numeral)."
   1.298 +  [op]
   1.299 +  (cond
   1.300 +    (#{0x06 0x0E 0x16 0x1E
   1.301 +       0x20 0x26 0x28 0x2E
   1.302 +       0x30 0x36 0x38 0x3E
   1.303 +       0xC6 0xD6 0xCE 0xDE
   1.304 +       0xE0 0xF0 0xE6 0xF6
   1.305 +       0xEE 0xFE} op)
   1.306 +    1
   1.307 +    (#{0x01 0x08 0x11 0x21
   1.308 +       0x31 0xC2 0xC3 0xC4
   1.309 +       0xCA 0xDA 0xCC 0xDC
   1.310 +       0xCD 0xEA 0xFA} op)
   1.311 +    2
   1.312 +    :else
   1.313 +    0))
   1.314 \ No newline at end of file