# HG changeset patch # User Steve Losh # Date 1479329653 0 # Node ID fd215349e7bb91b01d6cc05ea1fcc0c189baab48 # Parent 5cfbf08cb54df4a821584041e72ba999cad5f934 More opcodes diff -r 5cfbf08cb54d -r fd215349e7bb src/emulator.lisp --- a/src/emulator.lisp Wed Nov 16 20:41:42 2016 +0000 +++ b/src/emulator.lisp Wed Nov 16 20:54:13 2016 +0000 @@ -34,6 +34,9 @@ (defun chop (size integer) (ldb (byte size 0) integer)) +(defun cat-bytes (high-order low-order) + (dpb high-order (byte 8 8) low-order)) + (defun +_8 (x y) (let ((result (+ x y))) (values (chop 8 result) @@ -44,7 +47,6 @@ (values (chop 8 result) (if (> x y) 1 0)))) - (defmacro macro-map ((lambda-list items) &rest body) (with-gensyms (macro) `(macrolet ((,macro ,(ensure-list lambda-list) ,@body)) @@ -52,10 +54,6 @@ (collect `(,macro ,@(ensure-list item))))))) -(defun cat-bytes (high-order low-order) - (dpb high-order (byte 8 8) low-order)) - - ;;;; Data --------------------------------------------------------------------- (defstruct (chip (:constructor make-chip%)) (memory (make-simple-array 'int8 4096) @@ -96,7 +94,6 @@ :element-type 'fixnum))) (make-chip% :video-raw video-raw :video video))) - (define-with-macro chip memory registers index program-counter @@ -169,9 +166,12 @@ (fill video-raw 0) (setf video-dirty t)) -(define-opcode op-jp (_ (target 3)) ;; JP addr +(define-opcode op-jp-imm (_ (target 3)) ;; JP addr (setf program-counter target)) +(define-opcode op-jp-imm+reg (_ (target 3)) ;; JP V_0 + addr + (setf program-counter (+ target (register 0)))) + (define-opcode op-call (_ (target 3)) ;; CALL addr (vector-push program-counter stack) (setf program-counter target)) @@ -263,7 +263,7 @@ (#x0 (ecase instruction (#x00E0 (call op-cls)) (#x00EE (call op-ret)))) - (#x1 (call op-jp)) + (#x1 (call op-jp-imm)) (#x2 (call op-call)) (#x3 (call op-se-reg-imm)) (#x4 (call op-sne-reg-imm)) @@ -272,19 +272,19 @@ (#x6 (call op-ld-reg