Code Monkey home page Code Monkey logo

6502's Introduction

DB6502 - Dawid Buchwald's 6502 Computer

This repository contains all the work in progress during my build of Ben Eater's inspired 6502 8-bit computer similar to typical machines of the early 1980s. If you haven't seen Ben's videos, I would strongly suggest you start there:

Ben Eater's 6502 project

As stated above, this build is not 100% compatible with what Ben had done - and for a reason, described in next section.

If I had to explain shortly "what it is", the answer would be: simple, yet easy to expand, 8-bit CPU based computer designed and built with one goal only: to use it as a learning and tinkering platform to understand how computers really work. You can use it for simple things like understanding buses, clock cycles, instruction execution, but it also demonstrates more complex concepts like interrupts, interfaces to external components and device handling. More on that below. Everything, hopefully, is simple enough to wrap your head around by one person in couple of weeks.

Why build something different

Ben's videos on 6502 computer are absolutely awesome - it's one of the best sources in the whole Internet explaining how any computer works. The build he introduced is probably sufficient for most of the things you might ever want to build, and yet I decided to deviate from his design.

The rationale behind this project is pretty simple - the best way to test your understanding of certain subject is to try to expand on what you have learned. You never know if you understood something until you test it by introducing changes to original design - and I used this approach in this project to learn a lot. It was my first proper electronics project, so I would like to apologize for any mistakes. If you think something is off or could have been done differently - please go ahead and raise issue for the repo! All improvements are welcome!

Why would you bother using DB6502 instead of BE6502

Basically, it gives you almost all the flexibility of Ben's buid without the hassle of breadboard connections for the critical components. You can still run all of Ben's programs (using second VIA port), but the days of looking for loose wire between RAM and CPU are over :) You can, obviously, still experiment with peripherals and breadboard connections using extension port and second VIA.

On top of that you get additional features like extra screen (via onboard connector), keyboard for more versatile input and finally all-in-one serial over USB terminal. You also get easy to use software ready to be installed on the machine to jumpstart your tinkering. When using bootloader you don't even have to flash the EEPROM more than once!

Important note: All of the content here is, and always will be open source and free to use, and I don't intend to make any profit out of it. The only way I get anything at all (and it's only small commission to be used for future PCBWay orders) is when you order my boards from PCBWay using the links posted below, but you are welcome to grab these gerber files and order the boards from another provider, or even from PCBWay, just by uploading gerbers to your account, if you don't want me to get the commission :)

What is different

Compared to Ben's 6502 build I introduced the following changes:

  1. Added automatic power-up reset circuitry,
  2. Changed address decoder logic (very important from compatibility perspective),
  3. Changed LCD interface from 8-bit to 4-bit (very important from compatibility perspective),
  4. Added additional VIA chip to provide easy expansion of the system,
  5. Added ACIA chip for serial communication,
  6. Added (optional - more on that later) USB-UART interface for easy connectivity with PC,
  7. Added PS/2 keyboard port and ATtiny4313-based keyboard controller to provide proper replacement for five pushbuttons in Ben's design,
  8. Added expansion port (not really deviation from Ben's build, save for one detail - unlike Ben's build, my version can support various interrupt sources, including the expansion port),
  9. Modified clock module (external),
  10. Changed compilator from VASM to CC65,
  11. Added simple way to choose clock source.

You might be wondering if this means that you can't run Ben's programs on DB6502 - and the answer is YES YOU CAN. Indeed, some changes to the code are necessary, but thanks to the additional VIA chip and with some changes to the addressing mode you can run any program from Ben's videos. If you want to use LCD in 8-bit mode, you can also use the additional VIA for it, ignoring the built-in LCD connector.

By the way, the opposite is also true - you can compile and run my programs on Ben's computer. There are special compilation flags that enable usage of Ben's address decoder. I will describe this in more detail in software section.

Detailed description and rationale for each change is discussed in Schematics README.

Getting started

Okay, so it should be pretty clear what this project is about, so how to start playing with it? That really depends on what you decide to do:

  • Stick with BE6502 and just use subset of provided software (either to install it in EEPROM, or just use it as reference for your own hacking),
  • Build your own breadboard design based on this one with any modifications you can think of,
  • Order PCBs of DB6502, solder the components and run provided software to see how it works and get started with your own designs.

To start from scratch it's actually easiest to select last option - after some waiting you will end up having pretty solid base to extend your design on.

Using provided software with BE6502

If you decide to go down that route, head straight to the Software folder, where you will find several programs either identical or similar to what Ben has shown in his videos, but built with much more versatile toolchain.

If you want to read more, go ahead and read Software folder section. Make sure to check out the building software subsection, as it explains how to compile programs to run on BE6502 directly.

Build your own breadboard design

Maybe you have already started expanding on Ben's build, or maybe you are just considering it now. If you want to check out how I did certain things, jump right into Schematics folder, where you will find KiCAD projects for all the components used in this project. Obviously the most important one is the 65C02_Computer project, but there are some additional goodies there.

Please note: This part is not very well documented, I have assumed that anybody willing to dig into these schematics already knows how to read them.

Most of the decisions made during the schematic design were explained above. Justification for anything not covered here can be probably found in the invaluable 6502 primer.

Using my PCB design

This will be explained in the most detail, obviously. Start with getting the PCBs. Please note: clock module is entirely optional, but really useful for single stepping or slow clocking required by Ben Eater's design of Arduino Mega based bus analyzer. As explained in number of places here, you can either order PCBs from PCBWay directly or use your manufacturer of choice - it should have no impact on the final result.

What's in the repo

Everything, basically. Schematics of the 6502 board, modified clock module, address decoder and other circuits I built during the project. Arduino sketches I used for debugging and simple programs used to test different features.

And, last but not least, full set of sample programs to follow Ben's videos on DB6502 plus my own bootloader/OS. The last two things are coming soon :)

Arduino folder

There are several sketches there, and their full description is available is separate README.

AVR folder

There are several projects there, used to experiment with pure avr-gcc development for Atmel AVR chips. While it has been interesting adventure that I plan to explore further in the future, it was easier to stick to standard Arduino tools for now and simply restructure code to work there.

Datasheets folder

All the datasheets I used when designing DB6502, attached for reference.

Schematics folder

All the KiCAD schematics for the 6502 computer, modified clock module and several others:

  • 65C02_Computer - main schematic, including PCB design for DB6502 computer,
  • Clock_module - schematic for the modified clock module, including PCB design,
  • 555_troubleshoot - schematic of circuit used in troubleshooting of clock module monostable noise issue,
  • Address_decoder_basic - schematic of Ben Eater's address decoder for 6502 project,
  • Address_decoder_basic_v2 - slightly modified version of the above,
  • Address_decoder_extended - schematic of my own address decoder, used in the DB6502 computer.

There is dedicated README in the folder, containing all the build-related details.

Software folder

This one is the most important folder, as it contains range of different programs to play with the 6502 computer. Large subset of this programs can be built for Ben Eater's version of the 6502 computer without any changes. Some of them, however, use features available only in DB6502, like ACIA or keyboard connector. These can still be ran on Ben Eater's 6502 computer, assuming that compatible hardware is added to it.

The Software folder is currently divided into four main parts:

  • build - temporary folder where all the build artifacts are created, including ROM binaries to be uploaded to EEPROM,
  • common - common sources: include files with common constants, sources with shared function, configuration files for different address decoder logic modes, shared makefile used by all projects and small python script to optimize size of loadable modules,
  • rom - set of projects used to create various ROM images to follow Ben's videos, test different features of the board and some day complete operating system for the computer,
  • load - set of project containing loadable modules. These can be uploaded at runtime, without the need to flash the EEPROM. Basic bootloader is required, obviously, and the usage instructions are provided below.

There is also one "master" makefile located directly in the Software folder - it will build all the projects in rom and load subfolders.

There is dedicated README in the folder, containing all the software-related details.

Credits

This project would not be possible if not inspiration, support and help from many, many people:

6502's People

Contributors

dbuchwald avatar neilenns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

6502's Issues

Document md5sum on MacOS

Currently it's failing on MacOS due to lack of md5sum by default - document brew install md5sha1sum

Test drive 8MHz clock

Currently, due to usage of R6551 chip for ACIA, clock speed is limited to 2MHz, but when WDC65C51 is supported (#11 ), it should be possible to increase up to 14MHz

Keyboard is required to connect serial

I'm unable to connect via serial until I attach a keyboard. Once I plug in a ps/2 keyboard I get "shell connected", and can disconnect the keyboard. However if I disconnect serial, I must reconnect the keyboard in order to connect again.

Replace PS/2 port by USB connector

Assuming that the keyboard used would fall back to PS/2 compatibility mode. Will be tested first with simple PS/2->USB homemade adapter.

help compiling .c files

I am unsure how to compile the .c files in the 6502 projects ROM folder im not sure what to use crygwin? cc65? and what commands do I type into these to compile the .C file into an .out file ive been looking on the internet for days and cannot find anything Im looking for, so some pointers on how to do this would be appreciated :)

Add escaping to strings in list operation in BASIC

Currently BASIC lists strings with special characters in not so nice way:

New program will be stored at location 0x331e
OS/1 Basic>100 print "Hello \"World\" \\!"
OS/1 Basic>run
Hello "World" \!
OS/1 Basic>list
100 PRINT "Hello "World" \!"
OS/1 Basic>

Dead?

Seems everything dropped off 2 years ago. Is this project dead? I would rather not put time into something that is dead.

Fix monitor issue with relative backwards jumps

105f:   jsr  $1109
1062:   tax
1063:   beq  $115f

Should be:

105f:   jsr  $1109
1062:   tax
1063:   beq  $105f
00000050  a2 12 20 03 11 a9 0a 20  00 11 a9 0d 20 00 11 20  |.. .... .... .. |
00000060  09 11 aa f0 fa 20 f7 10  20 0c 11 92 00 20 00 11  |..... .. .... ..|

Unable to get ps/2 keyboard input working

I've flashed my ATTiny4313 with the keyboard_4313 sketch, using an Arduino as ISP:

image

I also flashed the rom withSoftware/rom/19_keyboard_test.

When I boot the computer (with a ps2 keyboard plugged in) the lights briefly flash on the keyboard.

It then shows key 4 as being pressed intermittently, but I am unable to type anything.

I checked my solder joints on the ps/2 connector, and they look ok.

Please provide PDFs for schematic

Currently you cannot take a look at the schematic using build-in GitHub file preview.
Could you add schematics in PDF format, please? (can be done using File -> Plot... in KiCad).

Schematics would also be much easier to read if they where stored into a single directory as a hierarchical sheet. Then you can have one PDF with hierarchy on the first page and all the schematics on the following pages.

Where to go for help?

I'm having some issues but not sure where the best place to get help is.

I have the PCB and have mounted everything but the 6551 (in transit someplace between here and China). No matter what I try I can't get the VIA (#1) to output anything. All of the lines in seem to be set properly but there's nothing on V1PB0-7. This means that neither the blink sketch nor any of the others (LCD etc..) work. I have the mega debugger setup and I can step through the program and see that it's writing to the via (8800) but nada. I have checked/re-checked/checked again to make sure there are no cold solders or bridges. Checked voltages, used a logic probe to make sure that the various input lines are set. I can see Chip Select working etc...etc...

I realize this isn't the right place for help with the board so if someone could either point me in the right direction or give me some pointers it would be extremely helpful.

Add a "how to use this with Ben's stuff" document

I suspect several people will come to this board/project while watching Ben Eater's tutorials on YouTube. The board design has variations from what Ben's doing though so nothing from Ben's tutorials will work directly.

Add documentation that explains the differences between Ben's design and this design, and provide specific steps on how to adapt Ben's code to work on this board:

  1. Document the difference in address ranges, perhaps with a helpful graphic to compare the two side-by-side
  2. Explain briefly why these changes were made
  3. Explain how to update the locations in Ben's sample apps to ones that will work with this board

This documentation is clear enough when I can take Ben's code with updated address locations, assemble it using the assembler he uses, and have it work on this board.

Add a "ok, now what?" doc section

Update the readme.md (or some other doc) with instructions on what to do after all the parts are soldered onto the board to verify things work correctly. Include things like:

  1. How to attach the clock to the main board
  2. How to use a jumper on the main board to get 1MHz clock
  3. Which program to run first (04_blink_s) and second (13_4bit_lcd?)

Makefile - common C sources

I added a C source file common/source/lcd.c and its header common/include/lcd.h to my source tree.
In the project directory makefile I added lcd.o to COMMON_DEPS.
When I run make I get the following output:

cc65 --cpu 65C02 -t none -O -I ../common/include -o ../build/common/lcd.s ../common/source/lcd.c
ca65 --cpu 65C02 -o ../build/common/lcd.o -l ../build/common/lcd.lst ../build/../common/source/lcd.s
Fatal error: Cannot open input file '../build/../common/source/lcd.s': No such file or directory
../common/makefile:74: recipe for target '../build/common/lcd.o' failed

It should be looking for build/common/lcd.s (which has just been created by cc65) for the ca65 step.

Add a pin 1 indicator for the UART

The silk screen on the 6502 board doesn't have an indicator for pin 1/up for the UART SMD. I had to crack open the board design in KiCad to see which one was pin 1 and make sure I put the SMD on the right way.

It'd be nice to have an indicator right on the board for which way the UART goes, just like there are for the larger ICs.

Document "fastclock=0"

Add information somewhere that you need to build with fastclock=0 if you're doing anything involving the LCD with the external clock module connected.

Incorrect value for RV1 in BOM for clock module

The BOM for the clock module lists a value of 10K for RV1 (a Piher PT10-LV10-105 potentiometer).

image

That must be a typo: the Piher part number is actually for a 1M potentiometer.

With a 10K pot, the astable circuit generates a square wave with frequency between 62 and 481 Hz, which may be too fast for troubleshooting. Changing to a 1M pot yields a frequency range of 0.72 to 481 Hz.

question about OS1

tried some other programs and they work but I am unsure on how to make this one work I have the os1 code installed on my eeprom but when I turn it on nothing happens from the comments I read the lcd should say something like shell connected and should have a bootup message I have this hooked up to a terminal using tera term and usb to ttl converter but nothing is displaying, am I missing something here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.