mirror of
https://github.com/andwati/mos-6502.git
synced 2026-10-18 03:02:51 +00:00
add CPU and memory modules with associated header files; update README and .gitignore
This commit is contained in:
@@ -76,6 +76,5 @@ dkms.conf
|
||||
|
||||
bin/
|
||||
build/
|
||||
docs/
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/c,visualstudiocode
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
# A mos-6502 emulator in c
|
||||
[Design Doc ](./docs/design.md)
|
||||
|
||||
The source code in this repository has been developed exploratively, in order to validate and refine the ideas laid out in above document. As such, it is incomplete, may occasionally malfunction, and does not yet provide the fine bone porcelain rendering it usable in anger. It's a prototype, if you wish.
|
||||
|
||||
## Links
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
# design doc
|
||||
The MOS 6502 is an 8-bit microprocessor with a 16-bit address bus, providing a linear addressable memory space of 64KiB
|
||||
|
||||
Unlike its contemporaries, the 6502 was designed with a minimal internal register set to reduce transistor count and manufacturing costs, featuring only one primary 8-bit accumulator (A), two 8-bit index registers (X and Y), a 16-bit program counter (PC), and an 8-bit stack pointer (S).
|
||||
This lack of general-purpose registers is compensated for by the implementation of "Zero Page" addressing, which allows the first 256 bytes of memory ($0000–$00FF) to be treated as a large, fast-access register file
|
||||
|
||||
The architectural philosophy of the 6502 is rooted in the Von Neumann model, where instructions and data share the same memory bus. A critical aspect of 6502 emulation is the adherence to little-endian byte ordering, meaning the least significant byte of a 16-bit address is stored at the lower memory address
|
||||
|
||||
# primary register specification
|
||||
|
||||
The internal state of the 6502 is defined by a specific set of registers that dictates the processor's operational capabilities.
|
||||
|
||||
| Register Name | Mnemonic | Width(Bits) | Functional Description |
|
||||
| ---------------- | -------- | ----------- | --------------------------------------------------------------- |
|
||||
| Accumulator | A | 8 | The primary register for all arithmetic and logical operations. |
|
||||
| Index Register X | X | 8 | Used primarily for indexed addressing and as a loop counter. |
|
||||
| Index Register Y | Y | 8 | Used primarily for indexed addressing and pointer offsets. |
|
||||
| Program Counter | PC | 16 | Stores the address of the next instruction to be fetched. |
|
||||
| Stack Pointer | S | 8 | Points to the next free location in the $0100-$01FF page. |
|
||||
| Status Register | P | 8 | Holds the processor flags (N, V, D, I, Z, C). |
|
||||
|
||||
|
||||
# processor status register(P) detail
|
||||
The status register is a collection of binary flags that represent the outcome of recent operations or control the processor's mode of operation.
|
||||
|
||||
| Bit | Flag | Name | Description |
|
||||
| --- | ---- | --------- | ------------------------------------------------------- |
|
||||
| 7 | N | Negative | Set if the result of an operation has bit 7 set. |
|
||||
| 6 | V | Overflow | Set if signed arithmetic results in an invalid sign. |
|
||||
| 5 | \- | Unused | Always read as 1 on some NMOS implementations. |
|
||||
| 4 | B | Break | Set only when a BRK instruction pushes status to stack. |
|
||||
| 3 | D | Decimal | Toggles Binary Coded Decimal (BCD) mode for ADC/SBC. |
|
||||
| 2 | I | Interrupt | Masks IRQ requests when set. |
|
||||
| 1 | Z | Zero | Set if the result of an operation is zero. |
|
||||
| 0 | C | Carry | Set if an operation results in a carry or borrow. |
|
||||
@@ -8,7 +8,7 @@ typedef struct
|
||||
uint8_t A; // accumulator
|
||||
uint8_t X; // index X
|
||||
uint8_t Y; // index y
|
||||
uint8_t SP; // stack pointer
|
||||
uint8_t S; // stack pointer
|
||||
uint8_t PC; // program counter
|
||||
uint8_t P; // status flags
|
||||
} CPU6502;
|
||||
Reference in New Issue
Block a user