;; -*- mode: common-lisp -*- ;; 6502.lisp ;; Contains data structures specific to the 6502 system. #| clasm-6502: An assembler for the 6502 written in Common Lisp. Copyright (C) 2024 Aleksei Eaves This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |# ;;; List of addressing modes and their length. (defparameter *addressing-mode-lengths* '((immediate 2) (absolute 3) (zero-page 2) (implied 1) (indirect-absolute 3) (absolute-indexed-x 3) (absolute-indexed-y 3) (zero-page-indexed-x 2) (zero-page-indexed-y 2) (indexed-indirect 2) (indirect-indexed 2) (relative 2) (accumulator 1))) ;; Generated list of addressing modes. (defparameter *addressing-modes* (extract-keys *addressing-mode-lengths*)) ;;; Instructions, with decimal opcode and ;;; addressing modes. (defparameter *instructions* ;; Load & Store '((LDA 169 (immediate absolute zero-page absolute-indexed-x absolute-indexed-y zero-page-indexed-x indexed-indirect indirect-indexed)) (LDX 162 (immediate zero-page zero-page-indexed-y absolute absolute-indexed-y)) (LDY 160 (immediate zero-page zero-page-indexed-x absolute absolute-indexed-x)) (STA 137 (absolute zero-page absolute-indexed-x absolute-indexed-y zero-page-indexed-x indexed-indirect indirect-indexed)) (STX 130 (zero-page zero-page-indexed-y absolute)) (STY 128 (zero-page zero-page-indexed-x absolute)) ;;Arithmetic (ADC 105 (immediate absolute zero-page absolute-indexed-x absolute-indexed-y zero-page-indexed-x indexed-indirect indirect-indexed)) (SBC 233 (immediate absolute zero-page absolute-indexed-x absolute-indexed-y zero-page-indexed-x indexed-indirect indirect-indexed)) ;;Increment & Decrement (INC 226 (zero-page zero-page-indexed-x absolute absolute-indexed-x)) (INX 232 (implied)) (INY 200 (implied)) (DEC 194 (zero-page zero-page-indexed-x absolute absolute-indexed-x)) (DEX 202 (implied)) (DEY 136 (implied)) ;; Logical (AND 41 (immediate absolute zero-page absolute-indexed-x absolute-indexed-y zero-page-indexed-x indexed-indirect indirect-indexed)) (ORA 9 (immediate absolute zero-page absolute-indexed-x absolute-indexed-y zero-page-indexed-x indexed-indirect indirect-indexed)) (EOR 73 (immediate absolute zero-page absolute-indexed-x absolute-indexed-y zero-page-indexed-x indexed-indirect indirect-indexed)) ;; Jump, Branch, Compare (JMP 72 (absolute indirect-absolute)) (BCC 144 (relative)) (BCS 176 (relative)) (BEQ 240 (relative)) (BNE 208 (relative)) (BMI 48 (relative)) (BPL 16 (relative)) (BVS 112 (relative)) (BVC 80 (relative)) (CMP 201 (immediate absolute zero-page absolute-indexed-x absolute-indexed-y zero-page-indexed-x indexed-indirect indirect-indexed)) (CPX 224 (immediate zero-page absolute)) (CPY 192 (immediate zero-page absolute)) (BIT 32 (zero-page absolute)) ;; Shift & Rotate (ASL 10 (accumulator zero-page zero-page-indexed-x absolute absolute-indexed-x)) (LSR 74 (accumulator zero-page zero-page-indexed-x absolute absolute-indexed-x)) (ROL 42 (accumulator zero-page zero-page-indexed-x absolute absolute-indexed-x)) (ROR 106 (accumulator zero-page zero-page-indexed-x absolute absolute-indexed-x)) ;; Transfer (TAX 170 (implied)) (TAY 168 (implied)) (TXA 138 (implied)) (TYA 152 (implied)) ;; Stack (TSX 186 (implied)) (TXS 154 (implied)) (PHA 72 (implied)) (PHP 8 (implied)) (PLA 104 (implied)) (PLP 40 (implied)) ;; Subroutine (JSR 32 (implied)) (RTI 64 (implied)) (RTS 96 (implied)) ;; Set & Reset (CLC 24 (implied)) (CLD 216 (implied)) (CLI 88 (implied)) (CLV 184 (implied)) (SEC 56 (implied)) (SED 248 (implied)) (SEI 120 (implied)) ;; Other (NOP 234 (implied)) (BRK 0 (implied)))) ;; Generated list of opcodes. (defparameter *opcodes* (extract-keys *instructions*))