Tech with Dave
Technical projects created by Dave Van Wagner
Tuesday, December 24, 2024
Avoid conflicts between C64 keyboard and joystick #1
Sunday, September 15, 2024
No name IPS 240*240 ST7789 TFT display with Arduino GFX Library and ESP32-C3 (RISC-V) development board
This is an alternative take on the previous article Adafruit ST7789 TFT display with Arduino GFX Library and M5StampS3. This time with a generic display, and a different MCU (ESP32-C3). This one has a single RISC-V core (instead of dual core Xtensa).
So excuse the repeated text, the content has been changed only slightly for the different hardware...
Attaching a display to a circuit can provide a lot of detailed info and graphical value. While "a picture is worth a thousand words," an animated display can be entertainment value, textual information can be informative, and add an input device, and the system can be interactive with billions of possibilities.
The tricks in embedded development is choosing the right display, having the right library that supports the display, and figuring out to use it all together with your target embedded system.
Shown above is a minimal footprint ESP32-C3 development board (I purchased one from AliExpress for around two US dollars, very cheap!), with a generic IPS 240x240 TFT display (ST7789 based) I had purchased years ago on eBay. An SPI interface is utilized for communications using the GFX Library for Arduino. I am using a solderless breadboard to prototype the circuit. Later I will implement as a more permanent circuit.
Besides power and ground, there are only 4 connections from the ESP32: SCLK, MOSI, DC, and Reset. In this sample, the TFT select line is permanently selected by connecting to ground.
2/*sclk*/, 3/*mosi*/, 10/*miso*/, &SPI,
true/*is_shared_interface*/);
true/*ips*/, 240, 240);
- Arduino IDE 2.3.2
- esp32 boards 3.0.4
- GFX Library for Arduino 1.4.7
Sunday, September 8, 2024
Adafruit ST7789 TFT display with Arduino GFX Library and M5StampS3
Attaching a display to a circuit can provide a lot of detailed info and graphical value. While "a picture is worth a thousand words," an animated display can be entertainment value, textual information can be informative, and add an input device, and the system can be interactive with billions of possibilities.
The tricks in embedded development is choosing the right display, having the right library that supports the display, and figuring out to use it all together with your target embedded system.
Shown above is a minimal footprint ESP32S3 in the form of an M5StampS3 from M5Stack connected to 2.54mm pins, with a rounded corner ST7789 based 280x240 display from Adafruit. An SPI interface is utilized for communications using the GFX Library for Arduino. I am using a solderless breadboard to prototype the circuit. Later I will implement as a more permanent circuit.
Besides power and ground, there are only 4 connections from the ESP32: SCLK, MOSI, DC, and Reset. In this sample, the TFT select line is permanently selected by connecting to ground.
(The Adafruit display used in this example also includes a MicroSD connector and SPI connections for that as well. Support for SD is beyond the scope of this article, and would require additional changes to the circuit and code.)
- Arduino IDE 2.3.2
- esp32 boards 3.0.4
- GFX Library for Arduino 1.4.7
Sunday, August 25, 2024
Wireless controller adapter for Commodore
It's August 2024. I've just bought a new (to me) Vic-20 for US$50 to replace my childhood one. I already have the PenUltimate Vic-20 Cartridge with a ton of games. I also bought a Hyperkin Trooper joystick. But I want to game wirelessly!
I've already had great success with a BlueRetro Nintendo GameCube controllers wireless adapter with my original Wii game console. I purchased it on ebay for a good price and it worked great.
But I wanted to go back further to replacing an Atari joystick on my Commodore Vic-20 that has a DB-9 connector. Searching the Internet, it looks like BlueRetro internally supports Atari 7800 with a 2-player mode, and there is a single player version available for sale on Amazon for about $25. Also the ESP 32 firmware source code is available as open source.
Having experience developing with ESP32, and a plethora of electronic parts already at my disposal, I did what any enterprising consumer would do -- I purchased additional parts from AliExpress. I mean, you can't have enough electronic parts, can you? Okay, I could've done it completely from scratch but my time is valuable, I have only so much energy at the end of the day, and cheating my way to success is legal here. So we're doing it halfway.
First I bought the BlueRetro Core. It provides the base functionality with a DB-25 connector for all its pins. It is designed to allow connector adapters to be wired to various console systems. It is a very creative and functional design. And there are adapters available for many of the common systems. But I didn't have any luck finding Atari connectors.
But no problem! I can build my own! So I found a DIY screw terminal DB25 male connector with the correct optional mating screws, and the counterpart DB9 female connector with screw terminals. The only trick left is to wire it up.
Steps
- Connect BlueRetro Core to USB power adapter (don't require direct connection to computer)
- Download latest firmware ZIP via link provided on BlueRetro support site
- Unzip, and look for the parallel 2P firmware (1P should work fine too, skip the 3V3 versions.
- Follow flashing firmware instructions from BlueRetro support site
- Pair a supported wireless controller (I'm using an Xbox One Bluetooth compatible controller)
- Plug BlueRetro Core into the DB25 breakout
- Connect a voltage meter to ground on the breakout, and then test the voltage at each remaining pin with and without pressing a button (e.g. DPAD up/down/left/right, and A)
- Write down the DB25 pin numbers and the names of the controller functions
- Unplug the core, and power off for now
- Search the internet for the DB9 pin numbers for Atari joystick connector pinout so you have their functions handy
- Cut and strip ends of 8 wires of different colors long enough to connect the DB9 and DB25 breakouts
- Be sure to first feed the wires through the included rings, and confirm their orientation.
- Then connect the appropriate functions: up, down, left, right, fire, framing ground, signal ground, and voltage in (VIN) to +5V supply from Commodore/Atari
- Minimally connect, and test the functionality first with meter, then with Commodore/Atari console
- Once verified working, finish connecting wiring stress-relief, bolt the enclosures closed, and otherwise button-up and tidy up the solution.
- Play games!
Sunday, August 11, 2024
Vic-20 memory configurations supported by emulator
The C128 team invented the GO64 command for compatibility. Years ago I claimed to invent the GO128 command, and GO20 and some others.
My Commodore emulator (unified branch) that supports Windows and LCD targets including compact watch form factor, now supports an argument to the GO statement to specify the total memory to configure.
The Vic-20's memory map looks roughly like this.
// (from emuvic20.cpp)
// $0000-$03FF Low 1K RAM
// $0400-$0FFF (3K RAM expansion)
// $1000-$1DFF 3.5K RAM (for BASIC) [or alternate screen address]
// $1E00-$1FFF 0.5K RAM (Screen characters)
// $2000-$7FFF (24K RAM expansion)
// $8000-$8FFF (Character ROM)
// $9000-$9FFF (I/O)
// $A000-$BFFF (8K Cartridge ROM, or RAM expansion)
// $C000-$DFFF BASIC ROM
// $E000-$FFFF KERNAL ROM
The Vic-20 was manufactured with 5K RAM, with only 3.5K available for BASIC, not counting the color RAM nybbles (half-bytes).
There is a missing hole of 3K RAM in lower memory, cartridge sold separately. And you could also purchase 8K or 16K RAM cartridges. And later on 24K and 32K solutions. Up to a total of 35K RAM can be added into the memory map.
So specify the amount of RAM you want to add, and rounding down, the emulator will populate the appropriate memory.
But only 27.5K is available to BASIC programs. 1.5K is reserved for system use, the lower 3K RAM is only available to BASIC in some instances, and an upper 8K is reserved for cartridges and otherwise not contiguous, so also not available directly for BASIC use.
The VIC video chip (named VIC) can only address screen memory on the main board, so when both 3K and 8K memory expansions are populated, screen memory is directly in the middle, causing Commodore BASIC to ignore the lower 3K memory to prioritize for the larger contiguous memory configured after screen memory. The 3K lower memory is only used directly when it is the only contiguous RAM expansion, such as with the separate 3K memory expansion cartridge and with the Super Expander that included 3K RAM expansion, but stole more memory for the programmable function keys, and for the graphics screen.
GO 20 (default, 3583 bytes free)
GO 20, 5 (minimum, 3583 bytes free)
GO 20, 8 (5K, +3K, 6655 bytes free)
GO 20, 13 (5K, +8K, 11775 bytes free)
GO 20, 16 (5K, +3K, +8K, 11775 bytes free)
GO 20, 21 (5K, +8K, +8K, 19967 bytes free)
GO 20, 24 (5K, +3K, +8K, +8K, 19967 bytes free)
GO 20, 29 (5K, +8K, +8K, +8K, 28159 bytes free)
GO 20, 32 (5K, +3K, +8K, +8K, +8K, 28159 bytes free)
GO 20, 37 (5K, +8K, +8K, +8K, +8K, 28159 bytes free)
GO 20, 40 (5K, +3K, +8K, +8K, +8K, +8K, 28159 bytes free)
Note that many of these show the same number of bytes free even though extra memory has been added. This again is because only contiguous RAM can be configured as available to BASIC. The extra RAM is available for PEEKs, POKEs, and other machine language programs.
If a number out of range is entered, it is effectively rounded down to a valid configuration. For example GO 20, 64 will configure with 40K RAM. But 5 is the minimum, so GO 20,0 will configure 5K RAM.
Technically the Vic-20 tests for and can handle memory added in smaller configurations, but that's not commonly present in reality, and not how I implemented it. Also I only implemented adding 8K memory forward in the map (with the exception of the 3K coming and going based on math), and not configuring each section separately. Going with a total RAM value is a simpler concept to implement and understand.
Please enjoy the Vic-20 with extra RAM!
Save capability added to C64 version of VWAS6502 monitor
Tuesday, July 30, 2024
Snapshot feature implemented for MINIMUM 6502 mode
This snapshot feature is for the minimum 6502 emulation target included in c-simple-emu6502-cbm (unified branch). (This is a bare bones 6502 target with CPU/RAM/ROM/UART. The UART is MC6850. See SWEET-16 and vwas6502 previous discussions.)
Ooo. The screen is so fancy. F2 or F3 to bring up this screen. Up/Down make a selection. Return performs load or save for that slot, or return on the slot number allows up/down to change the slot number. When loading, the current state is replaced by the state loaded from disk. When saving, the current state is backed up to disk. (The reason for the Up/Down/Enter UI choices is that it can be performed by three buttons or touch equivalents with the supported M5Stack devices.)
F2 defaults to SAVE
F3 defaults to LOAD
This is about the simplest way to provide a general load/save functionality without implementing a higher level monitor. The state includes 6502 CPU, RAM, ROM, minimum settings (where MC6850 is mapped in memory), terminal state, and UART state. The data is serialized to a binary blob and stored as a single file with the name state01 or such. Pretty imaginative huh?
So, now you can use the machine language monitor, or Apple 1 BASIC, or whatever you have ported or implemented to this system, and save a current snapshot of the system to restore later.
Example:
6502 hello world |
In the example screenshot, I have restored a snapshot from a previous session where I created a program to display the visible ASCII characters 32 through 127.
So in the future, I can expand on the program, save the current state, and resume where I left off another time. Also the snapshots can be transferred between systems running the emulator. In my case, I can run on Windows, or M5Stack CoreS3, or Sunton 7". Switching is a breeze of copying files to/from microSD.
I hope this feature is useful to others as well!