This is the cl-6502 Reference Manual, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Sep 15 03:39:59 2024 GMT+0.
The main system appears first, followed by any subsystem dependency.
cl-6502
An emulator for the MOS 6502 CPU
Brit Butler <redline6561@gmail.com>
BSD
alexandria
(system).
cl-ppcre
(system).
packages.lisp
(file).
conditions.lisp
(file).
addressing.lisp
(file).
cpu.lisp
(file).
disassemble.lisp
(file).
parser.lisp
(file).
assemble.lisp
(file).
opcodes.lisp
(file).
jit.lisp
(file).
utils.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
cl-6502/cl-6502.asd
cl-6502/packages.lisp
cl-6502/conditions.lisp
cl-6502/addressing.lisp
cl-6502/cpu.lisp
cl-6502/disassemble.lisp
cl-6502/parser.lisp
cl-6502/assemble.lisp
cl-6502/opcodes.lisp
cl-6502/jit.lisp
cl-6502/utils.lisp
cl-6502/cl-6502.asd
cl-6502
(system).
app-path
(function).
*basedir*
(special variable).
cl-6502/conditions.lisp
packages.lisp
(file).
cl-6502
(system).
illegal-opcode
(condition).
invalid-mode
(condition).
invalid-syntax
(condition).
line
(reader method).
mode
(reader method).
opcode
(reader method).
cl-6502/addressing.lisp
conditions.lisp
(file).
cl-6502
(system).
absolute
(function).
(setf absolute)
(function).
absolute-x
(function).
(setf absolute-x)
(function).
absolute-y
(function).
(setf absolute-y)
(function).
accumulator
(function).
(setf accumulator)
(function).
immediate
(function).
(setf immediate)
(function).
implied
(function).
(setf implied)
(function).
indirect
(function).
(setf indirect)
(function).
indirect-x
(function).
(setf indirect-x)
(function).
indirect-y
(function).
(setf indirect-y)
(function).
reader
(generic function).
relative
(function).
(setf relative)
(function).
writer
(generic function).
zero-page
(function).
(setf zero-page)
(function).
zero-page-x
(function).
(setf zero-page-x)
(function).
zero-page-y
(function).
(setf zero-page-y)
(function).
*address-modes*
(special variable).
defaddress
(macro).
make-getter
(function).
cl-6502/cpu.lisp
addressing.lisp
(file).
cl-6502
(system).
*cpu*
(special variable).
*opcode-meta*
(special variable).
bytevector
(function).
cpu
(structure).
cpu-ar
(reader).
(setf cpu-ar)
(writer).
cpu-cc
(reader).
(setf cpu-cc)
(writer).
cpu-pc
(reader).
(setf cpu-pc)
(writer).
cpu-sp
(reader).
(setf cpu-sp)
(writer).
cpu-sr
(reader).
(setf cpu-sr)
(writer).
cpu-xr
(reader).
(setf cpu-xr)
(writer).
cpu-yr
(reader).
(setf cpu-yr)
(writer).
defenum
(macro).
get-byte
(function).
(setf get-byte)
(function).
get-range
(function).
(setf get-range)
(function).
get-word
(function).
(setf get-word)
(function).
initialize-instance
(method).
make-cpu
(function).
nmi
(generic function).
reset
(generic function).
status-bit
(macro).
u16
(type).
u8
(type).
wrap-byte
(function).
wrap-word
(function).
%status-bit
(function).
*opcode-funs*
(special variable).
*ram*
(special variable).
branch-if
(macro).
copy-cpu
(function).
cpu-p
(function).
defasm
(macro).
maybe-update-cycle-count
(function).
overflow-p
(function).
rotate-byte
(function).
set-flags-if
(macro).
set-status-bit
(macro).
stack-pop
(function).
stack-pop-word
(function).
stack-push
(function).
stack-push-word
(function).
wrap-page
(function).
cl-6502/disassemble.lisp
cpu.lisp
(file).
cl-6502
(system).
current-instruction
(function).
disasm
(function).
disasm-to-list
(function).
disasm-to-str
(function).
arg-formatter
(function).
bytes-to-keyword-syntax
(function).
disasm-ins
(function).
print-instruction
(function).
sexpify-instruction
(function).
with-disasm
(macro).
cl-6502/parser.lisp
disassemble.lisp
(file).
cl-6502
(system).
fetch-expression
(function).
fetch-label
(function).
fetch-literal
(function).
fetch-name
(function).
fetch-opcode
(function).
fetch-operand
(function).
fetch-term
(function).
make-stream
(function).
match-operand-address-modes
(function).
operand-possible-modes-and-value
(function).
parse-code
(function).
parse-line
(function).
skip-white-space
(function).
strip-comment
(function).
substream-advance
(function).
try-fetch
(function).
cl-6502/assemble.lisp
parser.lisp
(file).
cl-6502
(system).
asm
(generic function).
+absolute-modes+
(special variable).
+max-byte+
(constant).
+relative-branch-size-byte+
(constant).
+zero-page-modes+
(special variable).
assemble-code-block
(function).
assemble-instruction
(function).
copy-instruction
(function).
decide-address-mode
(function).
find-opcode
(function).
get-opcode-address-modes
(function).
instruction
(structure).
instruction-address-mode
(reader).
(setf instruction-address-mode)
(writer).
instruction-label
(reader).
(setf instruction-label)
(writer).
instruction-opcode
(reader).
(setf instruction-opcode)
(writer).
instruction-p
(function).
instruction-value
(reader).
(setf instruction-value)
(writer).
list-to-instructions
(function).
make-and-resolve-byte
(function).
make-byte
(function).
make-instruction
(function).
match-opcode-data
(function).
process-args
(function).
resolve-byte
(macro).
transform-sexp-syntax
(function).
tuple-to-instruction
(function).
zero-page-address
(function).
cl-6502/opcodes.lisp
assemble.lisp
(file).
cl-6502
(system).
cl-6502/jit.lisp
opcodes.lisp
(file).
cl-6502
(system).
jit-step
(function).
*jit-cache*
(special variable).
get-basic-block
(function).
jit-block
(function).
Packages are listed by definition order.
6502
common-lisp
.
*cpu*
(special variable).
*opcode-meta*
(special variable).
absolute
(function).
(setf absolute)
(function).
absolute-x
(function).
(setf absolute-x)
(function).
absolute-y
(function).
(setf absolute-y)
(function).
accumulator
(function).
(setf accumulator)
(function).
asm
(generic function).
bytevector
(function).
cpu
(structure).
cpu-ar
(reader).
(setf cpu-ar)
(writer).
cpu-cc
(reader).
(setf cpu-cc)
(writer).
cpu-pc
(reader).
(setf cpu-pc)
(writer).
cpu-sp
(reader).
(setf cpu-sp)
(writer).
cpu-sr
(reader).
(setf cpu-sr)
(writer).
cpu-xr
(reader).
(setf cpu-xr)
(writer).
cpu-yr
(reader).
(setf cpu-yr)
(writer).
current-instruction
(function).
defenum
(macro).
disasm
(function).
disasm-to-list
(function).
disasm-to-str
(function).
execute
(function).
get-byte
(function).
(setf get-byte)
(function).
get-range
(function).
(setf get-range)
(function).
get-word
(function).
(setf get-word)
(function).
immediate
(function).
(setf immediate)
(function).
implied
(function).
(setf implied)
(function).
indirect
(function).
(setf indirect)
(function).
indirect-x
(function).
(setf indirect-x)
(function).
indirect-y
(function).
(setf indirect-y)
(function).
jit-step
(function).
make-cpu
(function).
nmi
(generic function).
reader
(generic function).
relative
(function).
(setf relative)
(function).
reset
(generic function).
status-bit
(macro).
step-cpu
(function).
u16
(type).
u8
(type).
wrap-byte
(function).
wrap-word
(function).
writer
(generic function).
zero-page
(function).
(setf zero-page)
(function).
zero-page-x
(function).
(setf zero-page-x)
(function).
zero-page-y
(function).
(setf zero-page-y)
(function).
%status-bit
(function).
*address-modes*
(special variable).
*jit-cache*
(special variable).
*opcode-funs*
(special variable).
*ram*
(special variable).
+absolute-modes+
(special variable).
+max-byte+
(constant).
+relative-branch-size-byte+
(constant).
+zero-page-modes+
(special variable).
arg-formatter
(function).
assemble-code-block
(function).
assemble-instruction
(function).
branch-if
(macro).
bytes-to-keyword-syntax
(function).
copy-cpu
(function).
copy-instruction
(function).
cpu-p
(function).
decide-address-mode
(function).
defaddress
(macro).
defasm
(macro).
disasm-ins
(function).
fetch-expression
(function).
fetch-label
(function).
fetch-literal
(function).
fetch-name
(function).
fetch-opcode
(function).
fetch-operand
(function).
fetch-term
(function).
find-opcode
(function).
get-basic-block
(function).
get-opcode-address-modes
(function).
illegal-opcode
(condition).
instruction
(structure).
instruction-address-mode
(reader).
(setf instruction-address-mode)
(writer).
instruction-label
(reader).
(setf instruction-label)
(writer).
instruction-opcode
(reader).
(setf instruction-opcode)
(writer).
instruction-p
(function).
instruction-value
(reader).
(setf instruction-value)
(writer).
invalid-mode
(condition).
invalid-syntax
(condition).
jit-block
(function).
line
(generic reader).
list-to-instructions
(function).
make-and-resolve-byte
(function).
make-byte
(function).
make-getter
(function).
make-instruction
(function).
make-stream
(function).
match-opcode-data
(function).
match-operand-address-modes
(function).
maybe-update-cycle-count
(function).
mode
(generic reader).
opcode
(generic reader).
operand-possible-modes-and-value
(function).
overflow-p
(function).
parse-code
(function).
parse-line
(function).
print-instruction
(function).
process-args
(function).
resolve-byte
(macro).
rotate-byte
(function).
set-flags-if
(macro).
set-status-bit
(macro).
sexpify-instruction
(function).
skip-white-space
(function).
stack-pop
(function).
stack-pop-word
(function).
stack-push
(function).
stack-push-word
(function).
strip-comment
(function).
substream-advance
(function).
transform-sexp-syntax
(function).
try-fetch
(function).
tuple-to-instruction
(function).
with-disasm
(macro).
wrap-page
(function).
zero-page-address
(function).
cl-6502
Homepage: <a href="http://github.com/redline6561/cl-6502">Github</a>
common-lisp
.
Definitions are sorted by export status, category, package, and then by lexicographic order.
The 6502 instance used by default during execution.
A mapping of opcodes to metadata lists.
Define a function named %NAME, that takes KEY as an arg and returns the index of KEY. KEYS should be scalar values.
Test if KEY is set in the status register. KEY should be a keyword.
Return an array of the given SIZE with element-type u8.
Return a list representing the current instruction. If PRINT-P is non-nil, print the current address and instruction and return NIL.
6502
.
Disassemble a given region of memory into a sexp-based format.
6502
.
Call DISASM with the provided args and return its output as a string.
6502
.
Get a byte from RAM at the given ADDRESS.
Set ADDRESS in *ram* to NEW-VAL.
Get a range of bytes from RAM, starting from START and stopping at END if provided.
Replace the contents of RAM, starting from START with BYTEVECTOR.
Get a word from RAM starting at the given ADDRESS.
Set ADDRESS and (1+ ADDRESS) in *ram* to NEW-VAL, little endian ordering.
If the current block has been JIT compiled, run it, otherwise JIT compile it.
Wrap VALUE so it conforms to (typep value ’u8), i.e. a single byte.
Wrap VALUE so it conforms to (typep value ’u16), i.e. a machine word.
Assemble SOURCE into a bytevector and return it.
Generate a non-maskable interrupt. Used for vblanking in NES.
Return a Perl-compatible regex suitable for parsing MODE.
6502
.
(eql |6502|:relative)
)) ¶(eql |6502|:indirect-y)
)) ¶(eql |6502|:indirect-x)
)) ¶(eql |6502|:indirect)
)) ¶(eql |6502|:absolute-y)
)) ¶(eql |6502|:absolute-x)
)) ¶(eql |6502|:absolute)
)) ¶(eql |6502|:zero-page-y)
)) ¶(eql |6502|:zero-page-x)
)) ¶(eql |6502|:zero-page)
)) ¶(eql |6502|:immediate)
)) ¶(eql |6502|:accumulator)
)) ¶(eql |6502|:implied)
)) ¶Reset the OBJ to an initial state.
Return a format string suitable for printing MODE.
6502
.
(eql |6502|:relative)
)) ¶(eql |6502|:indirect-y)
)) ¶(eql |6502|:indirect-x)
)) ¶(eql |6502|:indirect)
)) ¶(eql |6502|:absolute-y)
)) ¶(eql |6502|:absolute-x)
)) ¶(eql |6502|:absolute)
)) ¶(eql |6502|:zero-page-y)
)) ¶(eql |6502|:zero-page-x)
)) ¶(eql |6502|:zero-page)
)) ¶(eql |6502|:immediate)
)) ¶(eql |6502|:accumulator)
)) ¶(eql |6502|:implied)
)) ¶A 6502 CPU with an extra slot for tracking the cycle count/clock ticks.
6502
.
structure-object
.
|6502|:u16
65532
|6502|:u8
253
|6502|:u8
36
|6502|:u8
0
|6502|:u8
0
|6502|:u8
0
fixnum
0
The JIT’s hot code cache. Currently never invalidated.
The opcode lambdas used during emulation.
Take a Relative branch if PREDICATE is true, otherwise increment the PC.
Define an Addressing Mode, NAME, with READER and WRITER methods that take NAME as a symbol and return a regex or format expression, respectively, and a function and setf function to get and set the data pointed to by the given mode.
6502
.
Define a 6502 instruction NAME, storing its DOCS and metadata in *opcode-meta*, and a lambda that executes BODY in *opcode-funs*. Within BODY, the functions GETTER and SETTER can be used to get and set values for the current addressing mode, respectively. TRACK-PC can be passed nil to disable program counter updates for branching/jump operations. If RAW-P is true, GETTER will return the mode’s address directly, otherwise it will return the byte at that address. MODES is a list of opcode metadata lists: (opcode cycles bytes mode).
Given a place and an environment, if that place is a function, call that function with the environment and assign the result to the place.
6502
.
Takes any even number of arguments where the first is a keyword denoting a status bit and the second is a funcallable predicate that takes no arguments. It will set each flag to 1 if its predicate is true, otherwise 0.
Set bit KEY in the status reg to NEW-VAL. KEY should be a keyword.
Loop from START to END, passing each instruction to OP and execute BODY. OP is PRINT-INSTRUCTION by default. Within BODY, the return value of OP is bound to RESULT and the length of the instruction in bytes is bound to STEP.
6502
.
Given an instruction’s ARG, format it for display using the MODE’s WRITER.
6502
.
Given a list of instructions, assemble each to a byte vector.
6502
.
Given an instruction, and the current program counter, fill the environment with any labels and assemble instruction to a list of bytes.
6502
.
Take BYTES and a MODE and return our assembly representation of the arguments.
6502
.
Finds the desired address mode, matching what the opcode allows to what was parsed from the operand’s syntax.
6502
.
Lookup the metadata for the instruction at INDEX and pass it to DISASM-OP for formatting and display, returning the instruction length.
6502
.
Fetches an expression from the stream, either a term or a term plus another.
6502
.
Fetches a label from the stream, or returns nil.
6502
.
Fetches a literal value from the stream and returns it as an alist containing the integer value and address mode, or returns nil.
6502
.
Fetches a name from the stream, or returns nil.
6502
.
Fetches an opcode from the stream as a keyword, or returns nil.
6502
.
Fetches the operand, returning its numerical value and possible address-modes.
6502
.
Fetches a literal or name from the stream, or returns nil.
6502
.
Finds an opcode matching OPCODE and MODE, raising ILLEGAL-OPCODE otherwise.
6502
.
Get the opcodes from the current PC to the next branch.
Given an opcode, return the possible address modes for that operation.
6502
.
6502
.
6502
.
6502
.
6502
.
Given a list of opcodes, JIT compile an equivalent function.
Given a list of assembly tuples, convert them to instructions.
6502
.
Given an operand, convert it to a byte, resolving any delayed functions.
6502
.
Given an integer, return a single byte for the required type. Given a label, return a delayed function to calculate the same, once labels are defined.
6502
.
Generate an appropriate GETTER for NAME based on RAW-P and whether or not it is a register shift operation.
6502
.
Returns whether the asm metadata matches the given opcode, and address-mode if it is provided.
6502
.
Matches the stream against all address-mode readers, returning those that match, as well as the positions where the match occurs.
6502
.
If ADDRESS crosses a page boundary, add an extra cycle to CPU’s count. If START is provided, test that against ADDRESS. Otherwise, use the absolute address.
Returns all matching address-modes for the operand, along with positions where the match occurs.
6502
.
Checks whether the sign of RESULT is found in the signs of REG or MEM.
Parses the assembly source text and returns the assembled code as a list of alists.
6502
.
Converts a line of text into an instruction representing the assembly code.
6502
.
Format the instruction at INDEX and its operands for display.
6502
.
Given the operand value, address-mode, and program counter, return a list of assembled bytes, using delayed functions for labels or expressions.
6502
.
Rotate the bits of INTEGER by COUNT. If COUNT is negative, rotate right.
Given BYTES and metadata, return a sexp-format representation of it.
6502
.
Fetches white space from the stream, ignores it and returns the stream.
6502
.
Pop the value pointed to by the SP and increment the SP.
Push the byte VALUE on the stack and decrement the SP.
Push the 16-bit word VALUE onto the stack.
Removes comment and white space from end of string.
6502
.
Set the stream to a substream at START positions ahead and finishing at END position.
6502
.
Given a SEXP-token using an indirect, *.x or *.y addressing mode, transform it to use the classic string assembly syntax.
6502
.
If the stream begins with a regex match, returns the matched text and move the stream past it. Otherwise, returns nil.
6502
.
Given an opcode and value, as symbols, convert them to an instruction.
6502
.
Wrap the given ADDRESS, ensuring that we don’t cross a page boundary. e.g. If we (get-word address).
Returns whether the address is a zero page access.
6502
.
6502
.
invalid-syntax
)) ¶line
.
6502
.
invalid-mode
)) ¶mode
.
6502
.
illegal-opcode
)) ¶Illegal opcodes are not currently implemented.
6502
.
condition
.
Only the 6502 addressing modes have readers and printers.
Assembly must conform to the syntax in the README.
Represents a single line of code.
6502
.
structure-object
.
(or null string)
(or null symbol)
(or null symbol list)
(or null |6502|:u16 list string)
Jump to: | %
(
A B C D E F G I J L M N O P R S T W Z |
---|
Jump to: | %
(
A B C D E F G I J L M N O P R S T W Z |
---|
Jump to: | *
+
A C L M O P S V X Y |
---|
Jump to: | *
+
A C L M O P S V X Y |
---|
Jump to: | 6
A C D F I J O P S T U |
---|
Jump to: | 6
A C D F I J O P S T U |
---|