    (assoc-in state [:memory] memory)))
 
 (defn- write-v
-  ([{:keys [v] :as state} x val]
-   (write-v state (assoc v x val)))
+  ([{:keys [v] :as state} X val]
+   (write-v state (assoc v X val)))
   ([{:keys [v] :as state} val]
    (assoc-in state [:v] (assoc-in-range v val))))
 


(defn opcode-FX07
  "Set Vx = delay timer value."
  [{:keys [v dt] :as state} x]
  (-> state
      (write-v x dt)
      (write-pc 2)))

;; TODO: Fx0A

(defn opcode-FX15
  "Set delay timer = Vx."
  [{:keys [v] :as state} x]
  (let [Vx (nth v x)]
    (-> state
        (write-dt Vx)
        (write-pc 2))))


(defn opcode-1NNN
  "Jump to address NNN."
  [state NNN]
  (-> state
      (write-pc NNN)))

(defn opcode-2NNN
  "Call subroutine at nnn."
  [{:keys [pc sp stack] :as state} NNN]
  (-> state
      (write-stack sp pc)
      (write-sp (inc pc))
      (write-pc NNN)))

(defn opcode-3XNN
  "Skip next instruction if VX = NN."
  [{:keys [v] :as state} X NN]
  (let [Vx (nth v X)]
    (-> state
        (write-pc (if (= Vx NN) 4 2)))))

(defn opcode-4XNN
  "Skip next instruction if VX != NN."
  [{:keys [v] :as state} X NN]
  (let [Vx (nth v X)]
    (-> state
        (write-pc (if-not (= Vx NN) 4 2)))))

(defn opcode-5XY0
  "Skip next instruction if Vx = Vy."
