         ]
     (-> state
         ;; clear VF before we start
-        (assoc-in [:cpu :v] (assoc v 0xF 0))
+        (write-v 0xf 0)
+
         ;; detect collision
-        (assoc-in [:cpu :draw-flag] 1)
-        (assoc-in [:cpu :pc] 2))))
+        (write-draw-flag 1)
+        (write-pc 2))))
 
 ;; TODO: Ex09E
 

(defn- VxVy [V x y]
  [(nth V x) (nth V y)])

(defn- update-memory
  ([{{:keys [memory]} :cpu :as state} arr start]
   (update-memory state (assoc-in-range memory arr start)))
  ([state memory]
   (assoc-in state [:cpu :memory] memory)))

(defn- update-pc
  [state pc]
  (assoc-in state [:cpu :pc] pc))

(defn- update-sp
  [state sp]
  (assoc-in state [:cpu :sp] sp))

(defn- update-i
  [state i]
  (assoc-in state [:cpu :i] i))

(defn- update-dt
  [state dt]
  (assoc-in state [:cpu :dt] dt))

(defn- update-st
  [state st]
  (assoc-in state [:cpu :st] st))

(defn- update-draw-flag
  [state draw-flag]
  (assoc-in state [:cpu :draw-flag] draw-flag))

(defn- update-stack
  ([{{:keys [stack]} :cpu :as state} idx val]
   (update-stack state (assoc stack idx val)))
  ([state stack]
   (assoc-in state [:cpu :stack] stack)))

(defn- update-v
  ([{{:keys [v]} :cpu :as state} x val]
   (update-v state (assoc v x val)))
  ([{{:keys [v]} :cpu :as state} val]
   (assoc-in state [:cpu :v]
             (if (sequential? val)
               (assoc-in-range v val) val))))


(def ^{:private true}
  default-state

  (let [[Vx Vy] (VxVy v x y)
        sum (+ Vx Vy)]
    (-> state
        (write-v  x (if (> sum 0xff) (- sum 256) sum))
        (write-v 15 (if (> sum 0xff) 1 0))
        (write-pc 2))))

(defn opcode-8XY5
  "Set Vx = Vx - Vy, set VF = NOT borrow."
