Possible project - portable 6502 Forth computer

Building your first 6502-based project? We'll help you get started here.
molleraj
Posts: 10
Joined: 07 Jan 2015

Possible project - portable 6502 Forth computer

Post by molleraj »

Hi everyone! This is my first post in the 6502.org forum.

I got my start in homebuilt computers through the famous 1802-based COSMAC ELF. I've added RS-232, a hex keypad, and a 16x16 LED display to my ELF so far. Eventually, I plan to add a 128x64 LCD so I can play CHIP-8 games :-)
Pictures of my ELF can be seen here: https://www.flickr.com/photos/80187190@N05/

I am posting here because I'm interested in taking up an idea I have had for a long time - building a portable 6502 machine running FORTH (perhaps FIG-Forth or Q-Forth). It would be great to use an LCD/keyboard for primary interaction with the computer and a UART for uploading/downloading of data or programs. Such a machine could be used to control or measure lots of different things (e.g., wireless interfaces, musical keyboards via MIDI, various I2C sensors or EEPROMs). The Rockwell R6502P and R6522P sitting in my parts box will thus hopefully find some use :-)

I plan to base most of my design on Daryl Rictor's SBC-2 (http://sbc.rictor.org/sch2.html). I will construct the circuit using my favorite construction technique - wire wrapping. It would have the following specs:

Power:
1A DC passed through LM7805 with 1A rating

Processor and clock:
Use NMOS R6502P
Use 1.8432 MHz TTL full can oscillator for clock
Divide frequency in 2 with 74LS74 (or 74HCT74?) for R6502P (thus 921.6 kHz clock)

Memory:
X28C256 - 32 KB EEPROM mapped from 8000-FFFFh
62256 - 32 KB SRAM mapped from 0000-7EFFh (minus 256 bytes for I/O)
Long term storage in 32 MB CF card (access via 8-bit CF interface)
Map CF to 7F00-7F0F.

Parallel and Serial I/O:
R6522P VIA mapped to 7F50-7F5F (VIA1 in Daryl's design)
6551 ACIA running at 1.8432 MHz mapped to 7F70-7F7F; MAX233 for level shifting

Input: PS/2 interface using two pins of R6522P VIA
Output: 40x4 HD44780-based LCD mapped to 7F00

Address decoding ICs (Daryl's design): 74LS00 + 74LS30 NAND gates for /MRD and /MWR + ROM, RAM, and I/O chip select
74LS138 for further I/O decoding

Does this seem like a reasonable project for a relative novice? The hardware doesn't seem too difficult, and I'm very comfortable with wire wrapping. The hard part seems to be the software.

I need to set up the Forth implementation to use the LCD as its output interface and a PS/2 keyboard as its input using associated 6502 subroutines, but I unfortunately have little experience with 6502 assembly (I know I love 1802 assembly, though). I did see some routines for using a HD44780-based LCD display here: http://6502.org/mini-projects/optrexlcd/lcd.htm. I also saw that Daryl Rictor developed some subroutines for interfacing a PS/2 keyboard to two pins of a VIA: http://sbc.rictor.org/pckb6522.html
Could these be integrated into FIG Forth for the 6502, for example?

I would greatly appreciate it if anyone could provide some tips about construction or Forth implementation in my planned project.

Thanks,
Jon
Last edited by molleraj on Mon Apr 13, 2015 1:13 am, edited 1 time in total.
scotws
Posts: 576
Joined: 07 Jan 2013
Location: Just outside Berlin, Germany
Contact:

Re: Possible project - portable 6502 Forth computer

Post by scotws »

Welcome to the forum. And what a cute little elf!

Learning 6502 assembly will not be a problem, the chip is still around for a reason while pretty much all the others from that age have bitten the dust: It fits your brain, to quote a Python saying. Enormous amount of literature out there, and pretty much any assembler or emulator you could want.

About Forth, sorry if I missed this in the post -- do you know the language yet?

There are a bunch of Forths out there for the 6502, Fig Forth being the most famous; however, it is also one of the oldest. Things like DO-LOOPs don't work that way anymore, and PARSE-NAME is a lot easier to use than WORD. All depends on what you want and how much you want to adapt things.

The short answer is that I'd be pretty amazed if you couldn't get it to work.
molleraj
Posts: 10
Joined: 07 Jan 2015

Re: Possible project - portable 6502 Forth computer

Post by molleraj »

Hi Scot,

Thank you very much for your response! Good to hear that my idea is quite plausible :)

Also great to hear that 6502 assembly is easy to understand! I see the big difference between the 1802 and the 6502 is the "lack" of registers in the 6502 (use of the zero page instead as well as X/Y). The 1802 relies heavily on internal registers (R0-RF).

Should I have any concerns regarding power consumption? If I recall correctly, NMOS components should take about 100 mA each (maximum), correct?

I've done a little bit with FORTH in the past - mostly some little math programs I wrote on my Palm Z22.

Are there any NMOS 6502-compatible Forth implementations you would recommend? The challenge I think will be integrating the basic I/O subroutines (my "custom" BIOS, hehe) with which ever Forth implementation I choose.

Do you have any recommendations for permanent storage? Are IDE/CF interfaces reasonable, or a real pain? :-)

Thanks again,
Jon
molleraj
Posts: 10
Joined: 07 Jan 2015

Re: Possible project - portable 6502 Forth computer

Post by molleraj »

Thank you for the primer! Indeed, I have bookmarked that page :)
User avatar
PaulF
Posts: 143
Joined: 08 Dec 2008
Location: Brighton, England

Re: Possible project - portable 6502 Forth computer

Post by PaulF »

molleraj wrote:
Should I have any concerns regarding power consumption? If I recall correctly, NMOS components should take about 100 mA each (maximum), correct?
With the hardware you plan to use, you should have no problems with your power supply. You are planing to use a 1A regulator, the devices you intend to power from it should not require this much. I estimate your power consumption will be in the 750mA region, leaving you with some spare capacity.

Don't forget to add a small heat sink to the regulator chip. Otherwise it may overheat and shut down, which can cause much head-scratching until you work out what is going on! (The voice of experience talks here!)
Shift to the left,
Shift to the right,
Mask in, Mask Out,
BYTE! BYTE! BYTE!
molleraj
Posts: 10
Joined: 07 Jan 2015

Re: Possible project - portable 6502 Forth computer

Post by molleraj »

OK, that sounds good! I'll definitely add a heatsink to my 7805. I'm also going to invest in a ZIF socket for the EEPROM ;)

A few other questions: Is it possible to use some sort of permanent storage with FORTH (e.g., a CF drive)? I'd just be interested in storing new words (the updated dictionary) and possibly data.

Is it possible to use a CF card with an IDE adapter for permanent storage? I want to use a simple 8-bit CF or IDE connection, much like this: viewtopic.php?f=4&t=2877
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: Possible project - portable 6502 Forth computer

Post by GARTHWILSON »

Everything you want to do is possible. Note that the high-density flash ICs are 3.3V, not 5V, so you'll need voltage translators, and serial ones (SPI, SD card, etc.) have very few lines to deal with, and to make it even better, each one is unidirectional, making the job easier. CF OTOH has a ton of connections, including bidirectional ones. I've used the 25VF032 SPI flash memory which has 4Mx8 in a tiny SO-8 package for a couple of bux. I²C is a really nice serial interface too, but because of its limited speed (topping out at a megabit per second), you won't find really dense memories in I²C. They'll top out at 128Kx8 or 256Kx8 in an 8-pin DIP. The 6502 primer chapter on expansion buses and interfaces includes the I2C-6 connector method I recommend. You could have a bunch of these home-made half-postage-stamp-size modules with different already-compiled images to run. You'll probably be doing more compiling from source code though, and for that (because of the length of source-code files), the denser SPI flash memory, combined with a file system of some sort, is a more likely candidate.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
scotws
Posts: 576
Joined: 07 Jan 2013
Location: Just outside Berlin, Germany
Contact:

Re: Possible project - portable 6502 Forth computer

Post by scotws »

Hi Jon,

I'm really not the person you want to be asking about hardware -- don't tell anybody, but occasionally I have to remind myself what the red and what the black wire do ...
molleraj wrote:
Are there any NMOS 6502-compatible Forth implementations you would recommend? The challenge I think will be integrating the basic I/O subroutines (my "custom" BIOS, hehe) with which ever Forth implementation I choose.

FIG Forth probably the best understood version around, the major bugs seem to have been found, various people have adapted it to their systems -- so you'd have lots of help -- and it's 6502 and not 65c02. If you don't mind the fact that is the Forth equivalent of Ancient Greek, that would probably be your best bet. It's in the public domain.

CamelForth (http://www.camelforth.com/), written by Brad Rodriguez, is a more modern version, very well documented, and has been ported to just about anything ... except the 6502. That would one way to learn assembler.

Then there are various other variants from various members here (mine is Tali Forth, not complete, but close to it: https://github.com/scotws/TaliForth), depending on how much time you want to spend on the tools or if you just want to get things going.

As for Forth, I would recommend reading Thinking Forth by Leo Brodie (http://thinking-forth.sourceforge.net/) which gives you the philosophy and some deeper insights.

Hope this helps!
Y, Scot
6502inside
Posts: 101
Joined: 03 Jan 2007
Location: Sunny So Cal
Contact:

Re: Possible project - portable 6502 Forth computer

Post by 6502inside »

Welcome!
molleraj
Posts: 10
Joined: 07 Jan 2015

Re: Possible project - portable 6502 Forth computer

Post by molleraj »

GARTHWILSON wrote:
Everything you want to do is possible. Note that the high-density flash ICs are 3.3V, not 5V, so you'll need voltage translators, and serial ones (SPI, SD card, etc.) have very few lines to deal with, and to make it even better, each one is unidirectional, making the job easier. CF OTOH has a ton of connections, including bidirectional ones. I've used the 25VF032 SPI flash memory which has 4Mx8 in a tiny SO-8 package for a couple of bux. I²C is a really nice serial interface too, but because of its limited speed (topping out at a megabit per second), you won't find really dense memories in I²C. They'll top out at 128Kx8 or 256Kx8 in an 8-pin DIP. The 6502 primer chapter on expansion buses and interfaces includes the I2C-6 connector method I recommend. You could have a bunch of these home-made half-postage-stamp-size modules with different already-compiled images to run. You'll probably be doing more compiling from source code though, and for that (because of the length of source-code files), the denser SPI flash memory, combined with a file system of some sort, is a more likely candidate.
Cool! I'm reading your 6502 primer sections about expansion buses/interfaces. I'll also check out that forum post.

In the primer, I see you list bit-banging SPI as a possible SPI interface (I'd rather avoid FPGAs/CPLDs due to power consumption, cost, programming, and low likelihood of wire-wrap connectors). Could this be accomplished with a 6522? The only connection I've ever bit-banged is a RS-232 connection (9600 baud) from my COSMAC ELF, heh.

Would bit-banging be a reasonable SPI option for interfacing serial flash (e.g., SD, SPI flash chips)? Are there some small, inexpensive SPI flash chips in through-hole packages? (I'm going to check Digikey). 16Mx8...well, even 4Mx8...would be more than enough room :D

(Update: I see a possible 4Mx8 candidate here: http://www.digikey.com/product-detail/e ... ND/2744777. I also see it requires a ~3.3V power source.)

If so, that sounds like an AWESOME option :)
molleraj
Posts: 10
Joined: 07 Jan 2015

Re: Possible project - portable 6502 Forth computer

Post by molleraj »

6502inside wrote:
Welcome!
Thank you! :)
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: Possible project - portable 6502 Forth computer

Post by GARTHWILSON »

molleraj wrote:
In the primer, I see you list bit-banging SPI as a possible SPI interface (I'd rather avoid FPGAs/CPLDs due to power consumption, cost, programming, and low likelihood of wire-wrap connectors). Could this be accomplished with a 6522?
Absolutely. There's a circuit diagram in the "circuit potpourri" section for doing it, along with sample 6502 code linked. If you're thinking of power consumption though, ditch the NMOS 6502 and 6522 and use CMOS only. CMOS gives a lot of advantages besides just lower power; like more instructions and addressing modes, higher speeds, stronger drivers, all the bugs are out (except the 6522's serial-port mode-011 bug), and WDC's 65c22's inputs are truly high-impedance (not imitating a 74LS input), and that solves certain problems.

Quote:
The only connection I've ever bit-banged is a RS-232 connection (9600 baud) from my COSMAC ELF, heh.

SPI and I²C hardly have any timing requirements since they're synchronous. That makes them much easier than RS-232 to bit-bang, and interrupts can interrupt the transmission or reception of a byte with no ill effects.

Quote:
Would bit-banging be a reasonable SPI option for interfacing serial flash (e.g., SD, SPI flash chips)? Are there some small, inexpensive SPI flash chips in through-hole packages? (I'm going to check Digikey). 16Mx8...well, even 4Mx8...would be more than enough room :D

(Update: I see a possible 4Mx8 candidate here: http://www.digikey.com/product-detail/e ... ND/2744777. I also see it requires a ~3.3V power source.)

The one you link to is 4Mb, not 4MB. It's 512Kx8. Adapters are available to be able to plug the tiny SO-8 package into a DIP socket. They cost at least double what the IC does, but sometimes it's worth it.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
molleraj
Posts: 10
Joined: 07 Jan 2015

Re: Possible project - portable 6502 Forth computer

Post by molleraj »

Hi Scot,
scotws wrote:
I'm really not the person you want to be asking about hardware -- don't tell anybody, but occasionally I have to remind myself what the red and what the black wire do ...
No worries! Long, long ago I thought I'd need a 35V power supply to drive seven 5V chips :?

But that's in the distant past now :wink:
scotws wrote:
CamelForth (http://www.camelforth.com/), written by Brad Rodriguez, is a more modern version, very well documented, and has been ported to just about anything ... except the 6502. That would one way to learn assembler.

Then there are various other variants from various members here (mine is Tali Forth, not complete, but close to it: https://github.com/scotws/TaliForth), depending on how much time you want to spend on the tools or if you just want to get things going.

As for Forth, I would recommend reading Thinking Forth by Leo Brodie (http://thinking-forth.sourceforge.net/) which gives you the philosophy and some deeper insights.

Hope this helps!
Y, Scot
Thank you for describing all the different options! I've done some more reading as well and I think I'll stick with FIG-Forth. There's a nice Forth-based 6502 SBC developed by Douglas Beattie described here: http://www.hytherion.com/beattidp/compu ... iy6502.htm

He also includes the updated source (well, FIG-Forth + custom BIOS for RS-232 communication via a 6551) on his website as well. I'm going to carefully study the FIG Forth listing plus the various I/O routines I've been finding.

I have seen Starting Froth, IIRC. Quite funny as I recall :) . I'll check out Thinking Forth as well.

Thanks,
Jon
molleraj
Posts: 10
Joined: 07 Jan 2015

Re: Possible project - portable 6502 Forth computer

Post by molleraj »

GARTHWILSON wrote:
Absolutely. There's a circuit diagram in the "circuit potpourri" section for doing it, along with sample 6502 code linked. If you're thinking of power consumption though, ditch the NMOS 6502 and 6522 and use CMOS only. CMOS gives a lot of advantages besides just lower power; like more instructions and addressing modes, higher speeds, stronger drivers, all the bugs are out (except the 6522's serial-port mode-011 bug), and WDC's 65c22's inputs are truly high-impedance (not imitating a 74LS input), and that solves certain problems.
Thanks! I had forgotten where I had seen your SPI and I2C interface schematics.

As long as power consumption is under 5V/1A, things should be fine.
GARTHWILSON wrote:
SPI and I²C hardly have any timing requirements since they're synchronous. That makes them much easier than RS-232 to bit-bang, and interrupts can interrupt the transmission or reception of a byte with no ill effects.
Cool!
GARTHWILSON wrote:
The one you link to is 4Mb, not 4MB. It's 512Kx8. Adapters are available to be able to plug the tiny SO-8 package into a DIP socket. They cost at least double what the IC does, but sometimes it's worth it.
Whoops! Indeed, that was a 4Mbit chip. I'll look for SOIC/DIP adapters.
SPI flash sounds quite easy to work with. I guess I'll interface my PS/2 keyboard, SPI flash, and I2C peripherals to my 6522.
Post Reply