Skip to content

Repository files navigation

Turtle Core 1

This is a homemade 8bits CPU architecture. The goal of this project is to learn how CPU work and have fun. I will base my architecture on the 6502 processor (because I will use 6502 assembly language). This way we can easily compare our results with a real 6502 and see how our performed.

CPU Architecture

As all CPU Turtle core 1 is mostly built around differents registers links with multiple 8 bits bus.

Register Architecture

Registers

AcronymNameGoal
DLData latchThis register store the data on the input bus every clock.
PCLProgram Counter LowThis register is the lowest 8 bits of the 16 bits of the program counter.
PCHProgram Counter HighThis register is the highest 8 bits of the 16 bits of the program counter.
ABLAdress Bus LowHold the low 8 bits of the adress bus.
ABHAdress Bus HighHold the high 8 bits of the adress bus.
SStack pointerThe stack pointer is an 8 bit register and holds the low 8 bits of the next free location on the stack. The location of the stack is fixed and cannot be moved.
XRegister XCan be use to store and send data. It can be used to get a copy of the stack pointer or change its value.
YRegister YCan be use to store and send data.
ACAccumulatorAn 8 bit register use for all arithmetic and logical operations.
PProcessor StatusThe register holds 7 flags that are update when doing operations and they can be set and clear. (Carry Flag, Zero Flag, Interrupt Disable, Decimal Mode, Break Command, Overflow Flag, Negative Flag)

Flags

There is 7 flags that are stored in the processor status.

  • Carry Flag: The carry flag is set if the last operation caused an overflow from bit 7 of the result or an underflow from bit 0. This condition is set during arithmetic, comparison and during logical shifts. It can be manually set or clear.
  • Zero Flag: The zero flag is set when the result of an operation was zero.
  • Interrupt Disable: This flag prevent interrupts to be trigger by external devices. It can be set or clear.
  • Decimal Mode: If decimal flag is set processor will use BCD (Binary Coded Decimal) arithmetic for addition and substraction. It can be set or clear.
  • Break Command: This bit is set when a BRK instruction has been executed.
  • Overflow Flag: The flag is set if the result is an invalid 2's complement result. (64 + 64 = -128).
  • Negative Flag: The negative flag is set if the result of the last operation had bit 7 set to a one. So the number is negative if the bit is signed.

Intructions

For now, this is all the instructions that are available on the CPU.

OpCodeInstructionCycles
$69ADC #5
$65ADC zpg6
$75ADC zpg,X7
$6dADC abs7
$7dADC abs,X7 +(1)
$79ADC abs,Y7 +(1)
$00BRK imp12
$a0LDY #5
$a4LDY zpg6
$b4LDY zpg,X7
$acLDY abs7
$bcLDY abs,X7 +(1)
$a2LDX #5
$a6LDX zpg6
$b6LDX zpg,Y7
$aeLDX abs7
$beLDX abs,Y7 +(1)
$a9LDA #5
$a5LDA zpg6
$b5LDA zpg,X7
$adLDA abs7
$bdLDA abs,X7 +(1)
$b9LDA abs,Y7 +(1)
$38SEC imp4
$f8SED imp4
$78SEI imp4
$85STA zpg5
$95STA zpg,X6
$8dSTA abs6
$9dSTA abs,X6 +(1)
$99STA abs,Y6 +(1)
$86STX zpg5
$96STX zpg,Y6
$8eSTX abs6
$84STY zpg5
$94STY zpg,X6
$8cSTY abs6
$aaTAX imp4
$a8TAY imp4
$baTSX imp4
$8aTXA imp4
$9aTXS imp4
$98TYA imp4

Memory

As the adress bus of the CPU is a 16-bits bus we can access 65537 space of 8-bits (1 byte) for a total memory of 65.537KB. The memory will be handle as follow:

AddressesTypeTotal space
$0000 - $00FFRAM zero page256B
$0100 - $01FFRAM stack256B
$0200 - $7EFFRAM32,000B
$7F00 - $7FFFIO256B
$8000 - $FFFFROM32,769B

Vectors

Vectors are memory adress that the CPU will load into its PC.

  • On a RESET, the CPU loads the vector from $FFFC/$FFFD into the program counter and continues fetching instructions from there.
  • On a BRK instruction, the CPU pushes the low byte and the high byte of the program counter as well as the processor status onto the stack (with bit #4 (B flag) sets), disables interrupts and loads the vector from $FFFE/$FFFF into the program counter and continues fetching instructions from there.

Tools

Simulation

To simulate the behavior of our architecture we use Logisim Evolution.

Save all assembly file under the /asm/ folder and then compile with .\vasm\vasm6502_oldstyle.exe -Fbin -dotdir -o .\bin\out.bin .\asm\file_name.s

About

Custom 8-bit CPU architecture :)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages