Monday, February 22, 2021
Sunday, January 17, 2021
|Raspberry Pi 400|
The Raspberry Pi 400 invokes a sense of nostalgia back to the all-in-one systems of the past, such as those commonly available in the 80's (about 40 years ago!) of having the keyboard and computer all in one, with connections at the back of the enclosure, and expansion at the back of the enclosure.
My favorite system released January 1982 was the Commodore 64.
So why not have both? With emulation, let the Raspberry Pi 400 become a Commodore 64 as well.
|Vice 3.5 built, running on Raspian|
One way to do this, is using Vice (the Versatile Commodore emulator). Of course you can use a prepackaged solution like Retropie and Emulation Station. But since it is open source, you can also just download and build the source yourself.
As vice 3.5 was just released Christmas Eve, 2020, it makes a lot of sense to build yourself, so you can have the latest build relatively easily. Just think of all those new features!!!
I've attempted this myself on my Raspberry Pi 400 (and expect should work on others fine too) with Raspian. I've tested with both the latest 32-bit ARM, and beta 64-bit ARM builds.
Following are the steps I took to accomplish building the default configuration. I followed the basic instructions, and when configuration or build failed due to a dependency, researched the dependencies necessary (thanks Google and all those who have built before me and posted their solutions).
Grab yourself your favorite beverage, power up your Pi, and get building! And once you're done, feel free to test my hires.d64 image. Maybe even pick up some keyboard stickers. And also can run Pet, Vic-20, Commodore 128, etc.
- Install dependency packages
- Download three archives from web: vice 3.5, SDL2, SDL2_image
- extract the archives to their respective directories
- configure, build, and install each iteratively in the order: SDL2, SDL2_image, vice 3.5
- sudo apt-get install flex bison xa65 libgtk2.0-dev texinfo libxxf86vm-dev dos2unix libpulse-dev libasound2-dev
- sudo apt-get install texlive-latex-base texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra
- http://libsdl.org/download-2.0.php Download SDL2-2.0.14.tar.gz - GPG signed
- cd ~
- tar xvfz ~/Downloads/SDL2-2.0.14.tar.gz
- cd SDL2-2.0.14
- sudo make install
- https://www.libsdl.org/projects/SDL_image/ Download SDL2_image-2.0.5.tar.gz
- cd ~
- tar xvfz ~/Downloads/SDL2_image-2.0.5.tar.gz
- cd SDL2_image-2.0.5
- sudo make install
- https://vice-emu.sourceforge.io/ Download tarball: vice-3.5.tar.gz
- cd ~
- tar xvfz ~/Downloads/vice-3.5.tar.gz
- cd vice-3.5
- sudo make install
Thursday, August 6, 2020
Monday, July 13, 2020
- Portable (got a web browser right?)
- Keyboard driver works best with Firefox
- Works on Mobile and TV too (click on screen for configuration, help)
- F9 to toggle Help
- Recommend use wired or bluetooth keyboard instead of onscreen keyboard
- This is based on my earlier efforts (see previous posts)
Sunday, April 12, 2020
- 320x200 text screen on graphics LCD, with top/bottom border.
- USB Keyboard (e.g. PC-103) support (symbolic, not positional)
- Tab maps to C64 Ctrl key
- Ctlr maps to C64 Commodore key
- Esc key maps to C64 RUN/STOP key
- PrtScr/SysRq maps to C64 RESTORE key (supports STOP+RESTORE)
- PgUp also maps to C64 RESTORE key
- Full 6502 emulation. Go ahead, run some machine language on it.
- Commodore character set
- Text video at $0400 (address 1024)
- Text color at $D800 (address 55296)
- Keyboard scan by writing to $DC00, reading from $DC01
- Full 64K RAM. Update 2020-04-14: RAM/ROM/IO/Charset banking is implemented! And 1K color nybbles
- 1/60 second IRQ. So we've got the software clock: TI, TI$
- Upper/lower case switch ($D018), and reverse characters.
- Border color ($D020) and background color ($D021).
- Approximately 85% cpu speed of a real C64
No NMI. No Restore key.Update 2020-04-15: implemented, see keyboard above.
- No other device support. No tape, no disk, no serial, no cartridges, no joysticks, no printer.
- VIC-II support is limited to getting system booted.
- No full register support.
- Text address can't be moved.
- No graphics support.
- No programmable characters.
- No raster interrupts.
- No sprites.
- No left/right side border displayed. Ran out of pixels.
- No CIA1/CIA2 (except for keyboard data ports, but no data direction registers)
- No SID.
- In progress. There are bugs lurking (for example, the IRQ and USB keyboard stops working exactly at 35 minutes, 38 seconds from start, maybe a resource leak in third party libraries, so we'll call that time limited I guess)
- Keyboard support may need tweaks for more complete PETSCII key support
- No CAPS LOCK or SHIFT LOCK supported
- Doesn't utilize full capabilities of the STM32F429 MCU and discovery board components including 2.0MB of Flash (uses 110KB), 256KB of RAM (uses 83KB), 8MB SDRAM, motion sensor, user leds, user button, or other expansion capabilities. Opportunity awaits!
- Source on mbed.com (utilizes MBED OS, MBED USBHOST, ST429 BSP)
- Terminal Console related C64/6502 emulator source on github.com
- Binary firmware (yes you can flash and try right now if you have the hardware)
- ST-Link Utility (flash utility for STM32, programmer built into discovery board)
- STM32F429x Datasheet
- STM32F429IDISCOVERY resources at st.com
Monday, March 30, 2020
- Only keyboard/console I/O. No text pokes, no graphics. Just stdio. No asynchronous input (GET K$), but INPUT S$ works. No special Commodore keys, e.g. function keys, cursor keys, color keys, STOP/RESTORE, etc. (Could improve this.)
- No keyboard color switching. No border or border color. Text and background colors are implemented, but disabled by default because mapping to the standard console colors results in some fairly horrible color combinations.
- No screen editing (gasp!) Just short and sweet for running C64 BASIC in terminal/console window via 6502 chip emulation in software
- No PETSCII graphic characters, only supports printables CHR$(32) to CHR$(126). But does support CHR$(147) for clear screen. Now also supports Home/Left/Right/Up/Down output characters (not input).
- No memory management or banking. Not full 64K RAM despite what the startup screen says. C64 has just 44K RAM, 16K ROM, 1K VIC-II color RAM nybbles. VIC-20 has just 5K RAM including screen memory (you can add more memory at the command line).
- No timers. No interrupts except BRK. No NMI/RESTORE key. No STOP key.
- No loading or saving of files implemented (but Windows clipboard works!)
- No cartridges.
- No joysticks.
- No sprites.
- No graphics (you know this is a terminal/console window right?)
- Yikes, that's a lot of no. Seriously, it is a simple emulator. Emphasis on simple.
- Lightly tested. Bugs are lurking!
Trace Execution:It is possible to trace some or all of execution by setting the Emu6502.trace to true, and it will produce debug output (see in your IDE, or capture with DebugView). Note that this slows down the emulation significantly, but provides very good insight. Registers and flags are shown to the left of the statement's disassembly, in their states prior to executing the statement. Currently, referenced memory is not shown, that would be a good enhancement for the future.
Walk a ROM:
- Use C64 BASIC in existing VICE emulator to test tokenizing, and execution - validate entry points, memory usage, define API subset
- Emulate 6502 code on Windows
- Graphing techniques - capture code paths, variables used
- Convert 6502 machine code to C or other using graphing information
- Add optimization techniques
Did it actually work first time? Definitely not. I had to fix my implementation of the BIT statement, somehow some opcodes got deleted, had to fix some instruction modes, and continuously fixing the flag assignments. The challenge was fun.
Monday night March 30 I created this blog entry. Okay, time to get more sleep.
Sleep, maybe some, but TED was bothering me. Turns out it needed memory banking (damn you TED!) so there you go, revised the memory scheme from an array, to a C# class that each machine type can handle those accesses including banking support. Watch out 128, I'm going to get you next.
Saturday April 4 I was able to fix some I/O issues, and check in TED (C16, Plus/4) and PET 2001 support.
What's next? I'm toying with replicating the static recompilation, to C would work best for me. Then I could test on various or select embedded hardware platforms I have in my possession (or did I say obsession?).
And maybe even use one with an LCD, and modify the emulation to support the screen editor and hi-res graphics support, either hooked or emulated, and support file loading from SD.
External Links:Open Source! https://github.com/davervw/simple-emu-c64 (C#, follow links for C version)
Friday, March 13, 2020
[Author's Note: There is text to this blog post. Be sure to also scroll down]
So what shall we draw first on our Commodore 64? I vote for a circle. Since I'm running the show here, I get to pick my favorite one sided two dimensional object. Just a little trigonometry in play here. Ah, takes me back to high school in 1982. Good times!
20 COLOR 1, 15, 0, 14: REM GRAPHICS COLORS: LT GRAY ON BLACK, LT BLUE BORDER
30 HIRES 1 CLR: REM SWITCH TO GRAPHICS AND CLEAR
40 PI=3.1416: REM OR USE PI CHARACTER
50 R=90: REM RADIUS
55 C=1: REM COLOR
60 FOR A=0 TO 2*PI+PI/30 STEP PI/15: REM LOOP THROUGH ALL THE ANGLES AND MORE
85 PLOT COLOR C
86 C=C+1:IF C=16 THEN C=1
90 IF A=0 THEN:PLOT 1,X,Y: REM PLOT POINT FIRST
100 IF A<>0 THEN:PLOT 1 TO X,Y: REM ALL OTHERS ARE LINES
Pretty cool. The code fakes a circle with 30 lines (see the different colors!) using SIN/COS to get the coordinates. (Hint: to get out blind type HIRES 0 and RETURN, or just make a syntax error and that will return to text as well. Or use STOP+RESTORE, or power cycle as a last resort).
But what? You don't have the COLOR, HIRES, PLOT keywords in your Commodore 64 BASIC? Shucks, time to install HI-RES FOR C64. Better yet, let's just dive in to learning the new keywords by launching LOADHIRES.
Insert your HI-RES FOR C64 disk. I wish I had a time machine. We could dial back to 1982 and look for it in your favorite computer retailer shop, or mail order house. If it only existed then. I probably could have sold this for something.
Except we are in the 21st century now. We have Internet and everything. You're not reading this on a BBS are you? Just download the HI-RES FOR C64 disk image (open source!) and run in your favorite C64 emulator (VICE 3.3 r35872 or later recommended as that's what I'm running). Or just copy to a floppy or such (SD for use with SD2IEC, pi1541, etc.) and run in your real C64 or C128. (I personally use ZoomFloppy to transfer to my 1581 on 3 1/2" floppy to run on my C128[DCR].)
Hi-res is a software extension to Commodore I wrote over the course of about a year (June 2019 - March 2020) to continue my retro vibe, and close the loop on a project I had embarked on in the early 1980s. I realized my dream! Achievement completed. Okay that is pretty priceless.
The keyword commands that you can learn about in the interactive documentation shown above, include:
I'm not going to explain how to use them here. Run the interactive documentation and learn there. Move the cursor up and down, and press return for a demo or more information. The demos show the capabilities of this hi-res system and utilize its keywords.
Now I'm going to use this remaining blog space to continue to rant about my Commodore programming memories...
Now I started on a PET at high school school. And soon afterwards bought a VIC-20 for home with my own money. I didn't get a Commodore 64 until about 1986, and a Commodore 128(DCR) in 1987. With limited funds available prior to the C128, my only graphics capabilities was from purchasing a Super Expander with 3K RAM for my VIC-20. While I was underwhelmed by some specifics of the Super Expander product (after shelling out about $60), having access to graphics was way cool and I did use it along with my math studies. But then I outgrew BASIC programming in 1982 and branched into 6502 assembly. I used HESMON to code 6502 machine language to develop a graphics package I could call into from BASIC using SYS commands. I remember adding ability to parse commas and numbers to get arguments to my hi-res routines.
And since this was a VIC-20 and not a C64, there were no sprites to speak of. So I wrote my own
shape routines to copy portions of screen to and from memory. And wrote my own character editor, and wrote my own routines for 40 columns text. Unfortunately I haven't recovered any of those programs for tape and disk yet. Here's hoping! Finishing this project has been in the back of my mind for more than 35 years.
But I did one better. I rewrote the high resolution package from scratch. Well, actually I had some help starting out, so can't take all the credit (more on that later). And this time targeted the C64 instead of the VIC-20. Modern equipment and upgrades, you know! Well, the C64 is a better more popular target for now, and has pretty good resources available (64K vs. 5K), except my VIC-20 Golden RAM 24K expansion board is laying around here somewhere. But the VIC-20 isn't running. So yeah, back to the C128 in 64 mode or more technically, the VICE emulator.
Okay, so Paul Soper posted on Reddit a link to his blog post of plotting a math function. And I was in the retro mood so I ported the BASIC code he posted directly to machine code. So I could pretty much replace the BASIC GOSUB routines with SYS commands. The result was a little messy for passing values in A,X,Y registers, but it worked, and the graphics init and clear were much faster. I posted the response to a comment in Reddit and on his blog. Thanks again Paul! And Paul credits the book The Graphics Book for the Commodore 64 as a source for his program, so thanks also to Abacus Software!
So to make a long story longer, I patched BASIC vectors to add the keywords. This is not something I had accomplished in the 80s. But with PDFs of Commodore manuals accessible at my fingertips to search and reference at whim, and more determination, and more senior engineering experience and confidence, I was able to accomplish the complete task in a professional and ideal manner.
Here are the successes of hi-res summarized:
- supports graphics screens across the memory map (except zero page, and not where character rom gets in the way)
- can switch between multiple graphics screens. Supporting both hardware screens, and software swapped color tables, depending on addresses used.
- default graphics screen is under KERNAL ROM
- alternate graphics screen and color table is under BASIC ROM and I/O
- So two screens without taking away any BASIC RAM!!!
- machine code is from $C000-D423 (or thereabouts). Utilizes more than 1K of RAM under I/O using banking, so not taking away any BASIC RAM.
- Shape routines can copy any size portion of hi-res screen to/from RAM, and combine using GET/PUT/AND/OR/NOT/XOR. This is leveraged to also support filling rectangular area with 8x8 pixel pattern, and plotting character strings to hi-res screen.
- Hi-res patches SCRLEDIT in RAM so it will list the new tokens correctly. Scroll up and down through your BASIC programs with F1/F7 using software I published in Compute!'s Gazzette.
- assembly compiled using ACME. Developing 6502 Assembly using Microsoft Visual Code editor, and builds into a running VICE instance. And vice has built in machine language monitor with symbol table loaded built by ACME. Very nice edit+build+test+debug cycle for development!!! So glad not developing in the 80s anymore.
- Machine language interface is also there. Load up A/X/Y with correct values and JSR to $C000 as entry point for all the routines. See source for details.
- There are actual comments in the source code! Gasp! Don't worry, the BASIC interactive demo source is almost indecipherable in comparison.
- Writing the assembly code was fun!
- Writing the BASIC code to drive the demo was so much of a chore it wore on and dragged on for months. Finally it is done. I'm done with it too. I'm sure it's done with me too.