summaryrefslogtreecommitdiff
path: root/6502.lisp
diff options
context:
space:
mode:
Diffstat (limited to '6502.lisp')
-rw-r--r--6502.lisp45
1 files changed, 28 insertions, 17 deletions
diff --git a/6502.lisp b/6502.lisp
index a7982d8..1e9c7d4 100644
--- a/6502.lisp
+++ b/6502.lisp
@@ -18,8 +18,25 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|#
-;; Every instruction, its decimal opcode, and the
-;; usable addressing modes.
+;;; List of addressing modes.
+(setf
+ *addressing-modes*
+ '(immediate
+ absolute
+ zero-page
+ implied
+ indirect-absolute
+ absolute-indexed-x
+ absolute-indexed-y
+ zero-page-indexed-x
+ zero-page-indexed-y
+ indexed-indirect
+ indirect-indexed
+ relative
+ accumulator))
+
+;;; Instructions, with decimal opcode and
+;;; addressing modes.
(setf
*instructions*
;; Load & Store
@@ -185,18 +202,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
(NOP 234 (implied))
(BRK 0 (implied))))
-;; Predicate: is a combination of instruction
-;; and addressing mode correct?
(defun valid-instruction? (instruction addressing-mode)
- (dolist (x *instructions* nil)
- (when
- (and
- (equal (car x) instruction)
- (member addressing-mode (caddr x)))
- (return T))))
+ "Is instruction and addressing mode combination correct?"
+ (cond
+ ((member addressing-mode
+ (caddr (assoc instruction *instructions*))) t)
+ (t nil)))
-;; Is string hexadecimal?
(defun hexd? (string)
+ "Is a string a hexd number?"
(let ((stack ()))
(dotimes (i (length string))
(push
@@ -212,9 +226,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
(push 'and stack)
(eval stack)))
-;; Convert an arbitrarily sized hexadecimal number as
-;; string, to a positive decimal integer.
(defun hex2dec (string)
+ "Convert an arbitrarily sized hexd number (as string) to a positive decimal."
(flet ((hex (c)
(cond
((and (char-not-lessp c #\0)
@@ -236,10 +249,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
(hex (char string i))))))
ret)))
-;;(define-compiler-macro (list)
;; A list with with the respective rules of some
;; addressing mode syntax.
-;; ... ... ... could definitely macro most of them.
(setf
*addressing-modes-syntax*
'((immediate ; #?? ... more complex syntax rules for later
@@ -321,8 +332,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
(equal (length s) 1)
(equal "A" (subseq s 0 1)))))))
-;; EXAMPLE
;; Evaluate the second syntax rule on a string
+;; temporary
(funcall
- (eval (cadar (cdr *addressing-modes-syntax*)))
+ (eval (cadr (assoc 'absolute *addressing-modes-syntax*)))
"$A6AF")