Skip to content

Commit

Permalink
Move comments to defmethod docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
devn committed Apr 11, 2012
1 parent 1e3936c commit e7e7df4
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/clj_dcpu16/core.clj
Expand Up @@ -139,87 +139,87 @@

(defmulti execute get-o)

;;Special OP Codes *currently only JMP*
(defmethod execute 0x0 [word]
"Special OP codes *currently only JMP*"
(if (= 1 (get-a word))
(let [[a b out] (process word)]
(change-memory :push (bit-and 0xFFFF (inc (get-memory :pc))))
(change-memory :pc b))))

;; SET a to b
(defmethod execute 0x1 [word]
"SET a to b"
(let [[a b out] (process word)]
(change-memory out b)
(if-not (= out :pc) (inc-memory :pc))))

;; ADD a to b
(defmethod execute 0x2 [word]
"ADD a to b"
(let [[a b out] (process word)]
(if (> 0xFFFF (+ a b))
(change-memory :o 1)
(change-memory :o 0))
(change-memory out (bit-and 0xFFFF (+ a b)))
(inc-memory :pc)))

;; SUB a from b
(defmethod execute 0x3 [word]
"SUB a from b"
(let [[a b out] (process word)]
(if (pos? (- a b))
(change-memory :o 0xFFFF)
(change-memory :o 0))
(change-memory out (bit-and 0xFFFF (- a b)))
(inc-memory :pc)))

;; MUL a = a * b
(defmethod execute 0x4 [word]
"MUL a = a * b"
(let [[a b out] (process word)]
(change-memory :o (bit-and 0xFFFF (bit-shift-right (* a b) 16)))
(change-memory out (bit-and 0xFFFF (* a b)))
(inc-memory :pc)))

;; DIV a = a / b
(defmethod execute 0x5 [word]
"DIV a = a / b"
(let [[a b out] (process word)]
(change-memory :o (bit-and 0xFFFF (/ (bit-shift-right a 16) b)))
(change-memory out (bit-and 0xFFFF (/ a b)))
(inc-memory :pc)))

;; MOD a = a % b
(defmethod execute 0x6 [word]
"MOD a = a % b"
(let [[a b out] (process word)]
(if (zero? b)
(change-memory out 0)
(change-memory out (bit-and 0xFFFF (mod a b))))
(inc-memory :pc)))

;; SHL a = a << b
(defmethod execute 0x7 [word]
"SHL a = a << b"
(let [[a b out] (process word)]
(change-memory :o (bit-and 0xFFFF (bit-shift-right (bit-shift-left a b) 16)))
(change-memory out (bit-and 0xFFFF (bit-shift-left a b)))
(inc-memory :pc)))

;; SHR a = a >> b
(defmethod execute 0x8 [word]
"SHR a = a >> b"
(let [[a b out] (process word)]
(change-memory :o (bit-and 0xFFFF (bit-shift-right (bit-shift-left a 16) b)))
(change-memory out (bit-and 0xFFFF (bit-shift-right a b)))
(inc-memory :pc)))

;; AND a = a & b
(defmethod execute 0x9 [word]
"AND a = a & b"
(let [[a b out] (process word)]
(change-memory out (bit-and a b))
(inc-memory :pc)))

;; BOR a = a | b
(defmethod execute 0xa [word]
"BOR a = a | b"
(let [[a b out] (process word)]
(change-memory out (bit-or a b))
(inc-memory :pc)))

;; XOR a = a ^ b
(defmethod execute 0xb [word]
"XOR a = a ^ b"
(let [[a b out] (process word)]
(change-memory out (bit-xor a b))
(inc-memory :pc)))
Expand All @@ -232,23 +232,23 @@
(change-memory :pc (let [pc (get-memory :pc)]
(+ pc 1 (op-size (get-memory (inc pc))))))))

;; IFE execute next instruction iff a==b
(defmethod execute 0xc [word]
"IFE execute next instruction iff a==b"
(let [[a b out] (process word)]
(perform-branch (= a b))))

;; IFN execute next instruction iff a!=b
(defmethod execute 0xd [word]
"IFN execute next instruct iff a!=b"
(let [[a b out] (process word)]
(perform-branch (not= a b))))

;; IFG execute next instruction iff a>b
(defmethod execute 0xe [word]
"IFG execute next instruction iff a>b"
(let [[a b out] (process word)]
(perform-branch (> a b))))

;; IFB execute next instruction iff (a&b)!= 0
(defmethod execute 0xf [word]
"IFB execute next instruction iff (a&b)!=0"
(let [[a b out] (process word)]
(perform-branch (not= 0 (bit-and a b)))))

Expand Down

0 comments on commit e7e7df4

Please sign in to comment.