aboutsummaryrefslogtreecommitdiff
path: root/MOS6502.lisp
blob: e04c562fcbc998daa61c43e202ace7d535f98ac9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
;;;; Processor

;;; Processor function
;;;
;;; Each time the *CPU* is called, it executes one operation, meaning it reads the
;;;   next value in *M*, when an opcode, it either executes it, or if the opcode
;;;   needs a value, gets ready to read it from the next address and do something
;;;
;;; The implementation uses closures for the internal registers.
(defparameter *CPU* (let ((PC 0) (AC 0) (X 0) (Y 0) (SR 0) (SP 0)) #'(lambda ()
  (let ((mval (nth PC *M*)))
    (if (eql mval +OP_BRK+)
      ()
    (if (eql mval +OP_ORAxi+)
      ()))))))

;;; External memory, where the zero page, stack and general purpose memory resides
;;; Another file has to implement it.
(defvar *M*)

;;; Processor opcodes
;;; Ends with a small letter, depending on address mode:
;;;   ac  | accumulator
;;;   a   | absolute
;;;   ax  | absolute, X-indexed
;;;   ay  | absolute, Y-indexed
;;;   d   | immediate
;;;       | implied
;;;   i   | indirect
;;;   xi  | X-indexed, indirect
;;;   iy  | indirect, Y-indexed
;;;   r   | relative
;;;   z   | zeropage
;;;   zx  | zeropage, X-indexed
;;;   zy  | zeropage, Y-indexed
(defconstant +OP_BRK+   #x00)
(defconstant +OP_ORAxi+ #x01)
(defconstant +OP_ORAz+  #x05)
(defconstant +OP_ASLz+  #x06)
(defconstant +OP_PHP+   #x08)
(defconstant +OP_ORAd+  #x09)
(defconstant +OP_ASLac+ #x0A)
(defconstant +OP_ORAa+  #x0D)
(defconstant +OP_ASLa+  #x0E)


(defconstant +OP_BPLr+  #x10)
(defconstant +OP_ORAiy+ #x11)
(defconstant +OP_ORAzx+ #x15)
(defconstant +OP_ASLzx+ #x16)
(defconstant +OP_CLC+   #x18)
(defconstant +OP_ORAay+ #x19)
(defconstant +OP_ORAax+ #x1D)
(defconstant +OP_ASLax+ #x1E)

(defconstant +OP_JSRa+  #x20)
(defconstant +OP_ANDxi+ #x21)
(defconstant +OP_BITz+  #x24)
(defconstant +OP_ANDz+  #x25)
(defconstant +OP_ROLz+  #x26)
(defconstant +OP_PLP+   #x28)
(defconstant +OP_ANDd+  #x29)
(defconstant +OP_ROLac+ #x2A)
(defconstant +OP_BITa+  #x2C)
(defconstant +OP_ANDa+  #x2D)
(defconstant +OP_ROLa+  #x2E)