Skip to content
This repository was archived by the owner on May 1, 2022. It is now read-only.

Repository Cleanup #2

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{hpp,cpp,ini,md}]
indent_style = tab
indent_size = 4
charset = utf-8
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.pio
.vscode
526 changes: 526 additions & 0 deletions Include/EROM.hpp

Large diffs are not rendered by default.

526 changes: 526 additions & 0 deletions Include/FROM.hpp

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions Include/ROM.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef Header_ROM
#define Header_ROM

#include <Arduino.h>


const uint8_t rom [] PROGMEM = {

0xd8 , 0x58 , 0xa0 , 0x7f , 0x8c , 0x12 , 0xd0 ,
0xa9 , 0xa7 , 0x8d , 0x11 , 0xd0 , 0x8d , 0x13 ,
0xd0 , 0xc9 , 0xdf , 0xf0 , 0x13 , 0xc9 , 0x9b ,
0xf0 , 0x3 , 0xc8 , 0x10 , 0xf , 0xa9 , 0xdc ,
0x20 , 0xef , 0xff , 0xa9 , 0x8d , 0x20 , 0xef ,
0xff , 0xa0 , 0x1 , 0x88 , 0x30 , 0xf6 , 0xad ,
0x11 , 0xd0 , 0x10 , 0xfb , 0xad , 0x10 , 0xd0 ,
0x99 , 0x0 , 0x2 , 0x20 , 0xef , 0xff , 0xc9 ,
0x8d , 0xd0 , 0xd4 , 0xa0 , 0xff , 0xa9 , 0x0 ,
0xaa , 0xa , 0x85 , 0x2b , 0xc8 , 0xb9 , 0x0 ,
0x2 , 0xc9 , 0x8d , 0xf0 ,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 0x2 , 0x69 ,
0x6 , 0x2c , 0x12 , 0xd0 , 0x30 , 0xfb , 0x8d ,
0x12 , 0xd0 , 0x60 , 0x0 , 0x0 , 0x0 , 0xf ,
0x0 , 0xff , 0x0 , 0x0

};


#endif
13 changes: 13 additions & 0 deletions Include/Settings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef Header_Settings
#define Header_Settings


// 2400 for the authentic experience, 9600 for something more enjoyable

#define BAUD 2400
#define CLOCK 53
#define RESET 52
#define RW 51


#endif
66 changes: 33 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
# Mega6502

Mega6502 is an experiment implementing a minimal 8 bit platform using an Arduino and a 6502.

# Hardware

Mega6502 requires an Ardunio Mega 2560 development board and CMOS 65c02. The 65c02 should be connected to the Arduino as follows


5v GND 5v Arduino
| | +------\/------+ |
| +---- 1| Vss /RES |40 -- 3k3 -+--- 52
+--- 3k3 ----- 2| RDY ϕ2 |39
| 3| ϕ1 /SO |38
+--- 3k3 ----- 4| IRQ ϕ0 |37 -------- 53
| 5| NC NC |36
+--- 3k3 ----- 6| /NMI NC |35
| 7| SYNC R/W |34 -------- 51
+------------- 8| Vcc D0 |33 -------- 49
22 --------- 9| A0 D1 |32 -------- 48
23 --------- 10| A1 D2 |31 -------- 47
24 --------- 11| A2 D3 |30 -------- 46
25 --------- 12| A3 D4 |29 -------- 45
26 --------- 13| A4 D5 |28 -------- 44
27 --------- 14| A5 D6 |27 -------- 43
28 --------- 15| A6 D7 |26 -------- 42
29 --------- 16| A7 A15 |25 -------- 30
37 --------- 17| A8 A14 |24 -------- 31
36 --------- 18| A9 A13 |23 -------- 32
35 --------- 19| A10 A12 |22 -------- 33
34 --------- 20| A11 Vss |21 ---+
+--------------+ |
GND
# Mega6502 [![Badge License]][License]

*An experimental implementation of a minimal* <br>
*8 - bit platform using an **Arduino** + **6502** chip.*

<br>

## Hardware

The **Mega6502** requires:

 **1 x** `Ardunio Mega 2560` development board

 **1 x** `CMOS 65c02`

<br>

### Connections

The **65c02** should be connected to the **Arduino** as follows:

<br>

<div align = center>

<img src = 'Resources/Connections.svg' width = 420>

</div>


<!----------------------------------------------------------------------------->

[Badge License]: https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge

[License]: LICENSE
1 change: 1 addition & 0 deletions Resources/Connections.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
219 changes: 219 additions & 0 deletions Source/Mega6502.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@

#include "Settings.hpp"
#include "EROM.hpp"
#include "FROM.hpp"
#include "ROM.hpp"

#include <util/setbaud.h>
#include <avr/pgmspace.h>
#include <Arduino.h>


#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif

#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

#define ADDR ((addrh << 8) | addrl)

byte ram[0x1000];
byte pia[0x14];


static uint8_t memRead(){

const uint8_t
addrh = PINC,
addrl = PINA;

const uint16_t addr = ADDR;

uint8_t val;

switch(addr >> 12){
default:
// nothing in the address space, just return zero.
return 0x00;
case 0x0:
val = ram[addr];
return val;
case 0xd:

// fake 6821

switch(addrl){
case 0x10:
val = 0x80 | UDR0;
break;
case 0x11:
val = UCSR0A & _BV(RXC0);
break;
case 0x12:
val = UCSR0A & _BV(UDRE0) ? 0x00 : 0xFF;
break;
default:
printf("pia: invalid read at %04x\n",addr);
val = 0;
break;
}

return val;
case 0xe:
val = pgm_read_byte(erom + (addr & 0x0fff));
return val;
case 0xf:
val = pgm_read_byte(from + (addr & 0x0fff));
return val;
}
}


static void memWrite(){

const uint8_t
addrh = PINC,
addrl = PINA,
val = PINL;

const uint16_t addr = ADDR;

switch(addr >> 12){
default:
// nothing in the address space ignore the write;
break;
case 0x0:
ram[addr] = val;
break;
case 0xd:

switch(addrl){
default:
printf("pia: invalid write at %04x: %02x\n",addr,val);
break;
case 0x12:
putchar(val & 0x7f);
break;
case 0x11:
// ignore write to $D011, PIA is not configurable.
break;
case 0x13:
// ignore write to $D013, PIA is not configurable.
break;
}

break;
}
}

int uart_putchar(char c,FILE * stream){

if(c == '\r')
uart_putchar('\n',stream);

loop_until_bit_is_set(UCSR0A,UDRE0);
UDR0 = c;

return 1;
}

static FILE uartout = {0} ;

void uart_init(){

UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;

#if USE_2X
UCSR0A |= _BV(U2X0);
#else
UCSR0A &= ~(_BV(U2X0));
#endif

// 8-bit data

UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);

// Enable RX and TX

UCSR0B = _BV(RXEN0) | _BV(TXEN0);

fdev_setup_stream(& uartout,uart_putchar,NULL,_FDEV_SETUP_WRITE);

stdout = & uartout;
}


void setup(){

uart_init();

printf("RESET\n");

pinMode(CLOCK, OUTPUT);
pinMode(RESET, OUTPUT);
pinMode(RW, INPUT);

digitalWrite(RESET, HIGH);

// setup PORTC to read the low byte of the address

DDRC = 0x00;
PORTC = 0x00;

// setup PORTA to do the same for the high byte

DDRA = 0x00;
PORTA = 0x00;

// send reset pulse

digitalWrite(RESET,LOW);
digitalWrite(CLOCK,HIGH);
digitalWrite(CLOCK,LOW);
digitalWrite(CLOCK,HIGH);
digitalWrite(CLOCK,LOW);
digitalWrite(CLOCK,HIGH);
digitalWrite(CLOCK,LOW);
digitalWrite(CLOCK,HIGH);
digitalWrite(CLOCK,LOW);
digitalWrite(CLOCK,HIGH);
digitalWrite(CLOCK,LOW);
digitalWrite(CLOCK,HIGH);
digitalWrite(RESET,HIGH);
}

void loop(){

while(true){

cli();
cbi(PORTB,0);

// 4 * 62.5ns delay @ 16mhz

__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");

sbi(PORTB, 0);
sei();

if(PINB & _BV(PB2)){

// read cycle

DDRL = 0xff;
PORTL = memRead();

} else {

// write cycle

DDRL = 0x00;
PORTL = 0;
memWrite();

}
}
}
Loading