# HG changeset patch # User Steve Losh # Date 1481948966 18000 # Node ID 89e97f4b9950c6c3be71e5c70d5dac615f3a2128 # Parent 8155568555ec110cac2be902ba7860682fc6c4ad Actually add the damn file diff -r 8155568555ec -r 89e97f4b9950 src/declarations.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/declarations.lisp Fri Dec 16 23:29:26 2016 -0500 @@ -0,0 +1,46 @@ +(in-package :chip8) + + +(declaim + (ftype (function (chip)) load-font) + (ftype (function (chip fixnum fixnum)) wrap) + (ftype (function (chip int8 int8 int4) null) draw-sprite) + (ftype (function (chip (integer (16)))) keyup keydown) + (ftype (function (single-float) single-float) square saw) + (ftype (function (chip) null) run-sound) + (ftype (function (chip) null) decrement-timers run-timers) + (ftype (function (chip) null) run-cpu emulate-cycle) + (ftype (function (chip int16) null) dispatch-instruction) + (ftype (function (chip)) reset) + ; (ftype (function ())) + ) + +(defun draw-sprite (chip start-x start-y size) + (declare (type chip chip) + (type int8 start-x start-y) + (type int4 size)) + (with-chip (chip) + (setf flag 0) + (iterate + (declare (iterate:declare-variables)) + (repeat size) + (for (the fixnum i) :from index) + (for (the fixnum y) :from start-y) + (for sprite = (aref memory i)) + (iterate + (declare (iterate:declare-variables)) + (for (the fixnum x) :from start-x) + (for (the fixnum col) :from 7 :downto 0) + (multiple-value-bind (x y draw) (wrap chip x y) + (when draw + (for old-pixel = (plusp (vref chip x y))) + (for new-pixel = (plusp (get-bit col sprite))) + (when (and old-pixel new-pixel) + (setf flag 1)) + (setf (vref chip x y) + (if (xor old-pixel new-pixel) 255 0)))))) + (setf video-dirty t)) + nil) + +; (start-profiling) +; (stop-profiling)