Pi Pico Microcomputer using MicroPython

I had this vision of a system you can load onto a raspberry pi pico with micropython, which turns it into an 80’s style microcomputer with PS/2 keyboard, VGA output, and sound (SD card support may also be good).

Since it runs on top of micropython, it shouldn’t need a separate development environment to make modifications.

It does need extra hardware or connectors to connect the screen etc, the aim is that the required adaptors are simple, and already available without requiring further soldering.

I’ll be selective about using any advanced features of micropython - I don’t want to depend too much on any version or language-specific features of micropython. It should be possible to imagine how it could work in assembly language or C instead, and shouldn’t require frequent updates to the version of micropython.

It may be desirable to include some assembly language code - this can be done with the micropython assembler.

One goal is to make it easy to understand - I’ve made the VGA output routine as simple as I could given that it needs to use DMA to fetch the display from memory, and output it via the PIO system. To improve the display it will probably be necessary to make a more advanced version as well.

So far I’ve got low resolution VGA output, some basic sound, and use of the USB serial connection instead of a keyboard. This is with some wires connecting to the Pimoroni VGA demo board for VGA and audio output.

Code here: https://gitlab.com/caspianmaclean/pico-smm
Demo here: https://youtu.be/BbCuAeUnRkI?si=-evtZrhXMxhee7O7

I’m not sure what programs I want it to run, but I’d thought there could be an interpreter or emulator written in a mix of micropython and assembly, e.g. to run chip-8 or BASIC or 6502 programs. I see it both as potentially becoming something like a microcomputer, but also as parts people could use in a whole range of different microcomputers or emulators.

2 Likes

Nice little project/idea.

I’ve sort of been doing something similar myself - but starting with real old systems (6502, 65816) and imagining what they might be like with modern tools, OS, etc. I migrated it all to RISC-V, but lack of suitable hardware (and some other ideas) made me move it to bare metal ARM (Pi v1) where it’s mostly working well.

Not python though, that’s really not my thing, but BCPL and assembler.

Video has always been the crux (for me). I did start with a composite video generator (PAL) and that worked well, but lack of suitable monitors, and other factors made me change track there and I resorted to serial output to a fancy terminal program running on a Linux desktop… The Pi solution gives me video for free (well, for the effort of writing the code to make it work)

And there’s the catch - it’s all great as a personal project but trying to get others interested is hard… So you end up doing all the software yourself which is somewhat time consuming, even in high level languages…

And for a while I was of the opinion that if you wanted to code in e.g. 6502 then get a real 6502! There are plenty of real 6502 systems still out there, and you can still buy the chips new, but in recent times (months) I’ve been thinking of writing an emulator for the 6502/65816 in my new super fast ARM based system - trouble then is I’ll just re-implement my current 65816 system on the emulated 65816 on the ARM system and that’s where it all gets somewhat complicated, given the path I’ve been down.

Still fun though.

-Gordon

1 Like

Video is the got ya, the old machines wanted TV out not VGA. You can pick just one
I suspect. Games pulled alot of tricks to get the best off of TV that may not work
with VGA.

More details on your arm system? I have a new 9/18 bit cpu that I am emulating
and porting to a working sbc saves me building real hardware. IO is rs232 serial
and compact flash emulating the washing machine sized drives of the early 1970’s. Tool chain is small C, and byte addressing.
Doing the hardware design is no problem, getting a working pcb and mother board
is.
More I look at BCPL, less I under stand the syntax. The machine design could be
changed to use the carry flag for byte addessing, making it a word machine.
Are there any other language options other than BCPL for word machines?

It’s a Raspberry Pi - not sure I can provide more details than that. Pi’s have been about for over a decade now… I looked at many “bare metal” frameworks and “tutorials” for it, took them, bludgeoned them together to make something work then re-wrote most of it from scratch as the code quality was shockingly bad… Learned (learning) ARM assembly along the way.

On top of this framework I can run my own BASIC (written in C) or my BCPL system (written in ARM assembler) It can boot to Basic or BCPL in under 2 seconds.

FORTRAN. The Prime P500 series minicomputers were word machines and the OS was written in (partly in) FORTRAN. It supported FORTRAN (naturally), COBOL, Basic and Pascal (although I’ve no idea how). It wasn’t until the P9950 series (If I recall rightly) that they could support byte addressing sensibly enough to run C.

Modern BCPL (as in the past 45 years) supports byte addressing and even when it didn’t there were packstring and unpackstring routines. ARM CPUs since v6 (in the Pi v1 and Zero) also support unaligned data accesses, so the 2 go together quite well. BCPL doesn’t require byte addressing, but the underlying CINTCODE VM does. Cintcode instructions are 1, 2, 3 or 5 bytes long. The ability to read bytes is handy for a bytecode interpreter…

But I’m not really sure how you can’t understand it - if you know C, then BCPL is very similar - just remove structs and use ! instead of […] (or % for bytes)… Strings are length byte then data rather than being zero terminated, but that then lets you do stuff like:

name := "Hello, World!*n"
FOR i = 1 TO name%0 DO
  wrch (name%i)

and so on. (How do I turn off this useless syntax colouring?) the Cintcode virtual machine doesn’t have flags and in the ARM case doesn’t rely on the carry flag. (In the '816 version it needs the CPUs carry flag to implement 32-bit arithmetic on a 16-bit machine)

But your 9/18 bit CPU…

-Gordon

Ooh, neat. I’m very much about MicroPython in my day to day work.

While the project I’m about to link to isn’t Python-based, I think it shares many goals with yours: PicoMite — a Raspberry Pi Pico running MMBasic. It has VGA graphics, PS/2 keyboard, sound and SD card support. The BASIC dialect is quite modern, and is designed for developing real embedded applications, rather than nostalgic fun.

What with cheap PCBs being able to be built and populated direct from the factory, the PicoMite went from being a slightly challenging build to something you can order directly, 100% built.

The PicoMite VGA setup is slightly different from Pimoroni’s approach. It (apparently) demands more memory for the display than PicoMite does.

There was a VGA-for-MicroPython project released a couple of years ago: Simple VGA driver using Pico and micropython - MicroPython Forum (Archive). Ever since the old MicroPython forum went quiet, I don’t know what happened to the project.

1 Like

I’ve done some development work with MicroPython for a project later shifted to C. That included a substantial chunk of work with PIO engines. I use Python a lot, so that was tempting. I found it workable but a bit clunky, I don’t remember precisely why.
For my most recent Pico project I looked for alternatives to C but didn’t consider Python because I need fast response. I thought of FORTH and some searching turned up ZeptoForth, which is very nice and quite efficient. FORTH is much more of a low level language; for example, you can trivially manipulate any part of the hardware directly without needing to drop into assembler. So it doesn’t provide the protection from programming errors that Python does (or even, to a lesser extent, C). But it works well for me.

1 Like

Some other boards to make the Pico into a retro computer are the Pimoroni Pico and the Olimex RP2040-PICO-PC.

2 Likes

You can do some of the low level stuff in micropython, it allows directly accessing memory addresses, which is how I programmed the DMA hardware for VGA output. It feels a bit weird since the language is garbage collected. I’m not trying for high speed in micropython though, for this project.

Looks like the repo with that VGA micropython code has added fonts now.
I think my approach is simpler but more wasteful of memory.

I got one of the early picomite systems as a kit from a magazine. I had to solder it and it didn’t come with sound hardware.

When you mentioned that I wondered if any of the designs were already uploaded to the pcb assemblers/manufacturers so you could buy them more easily. I didn’t find the picomite but I did find this:
PICO-56 - A 6502 + TMS9918 Retro Computer on a Raspberry Pi Pico - Share Project - PCBWay which I’m guessing would come with all the electronics assembled, but need programming.

That might fit as hardware to go with the software I’m working on. Unlike the pimoroni board I’m using at the moment it does include a PS/2 keyboard adaptor, whereas I’ll need to add something separately.

Should still be able to wire up connections individually between the board and the pico, like I’m doing with the pimoroni one.

One of the things I did liked in some of the picomites is the full sized SD card, they’re easier to label and harder to lose than microSD.

1 Like