StevenCombs.com

Logo

Blog posts and video from Steven as he “COMBS” through the minutia to discover tech, retro-computing, physical computing, gadgets and sci-fi.

retroCombs Playlist

Commodore Plus/4 Series

9 November 2021

Install the MEGA65 on a Nexys4 or A7 FPGA | Build your own MEGA65!

by Steven B. Combs, Ph.D.
tags: commodore - mega65 - nexys4

The MEGA65 is AVAILABLE! That was the virtual shout during early October 2021. The first 400, of which I snagged one, will ship late December, while another batch of 1000 will ship during Q2 of next year. As of this writing, there are a few available. At around $850 USD, these pre-orders may be out of reach of some early adopters. If that’s the case, there are two ways you can begin your MEGA65 journey while production increases and costs decrease during the next couple of years.

The first option I’ve covered; Run a MEGA65 on your Mac using Xemu (or Linux/PC). This software solution has the advantage of being a free solution and I recommend it for anyone curious about the MEGA65 project. It is a great way to get started; however, if you want to build a hardware solution that costs less than a Dev Kit or original release models, you can purchase a Nexys A7-100T FPGA Trainer Board for ≈$270; or less if you are a student or educator. Once you have this FPGA training board in hand, what’s next? I’ll cover that in this post and show you how to configure and use the board as a MEGA65.

Before you read the rest of this post, look at my companion video below.


Table of Contents


YouTube Video: Install a MEGA65 Bitstream on a Digilent Nexys4 FPGA | Build your own MEGA65!

In the video below, I show the process to install and use a MEGA65 bitstream on a Digilent Nexys4 FPGA.

Read the blog post below for detailed information.

Video Errata

2021-11-10: Added a Bill of Materials and Total Project Cost table. Thanks, Tayger!

Below are the links I mention in the video. All Amazon links are affiliate links.

  1. Run a MEGA65 on your Mac using Xemu
  2. MEGA65 FileHost
  3. MEGA65 Developer’s Guide
  4. Purchase a MEGA65
  5. The MEGA65 Project
  6. Purchase a Nexys A7-100T FPGA Trainer Board
  7. MEGA65 Command Line Tools
  8. Inexpensive micro SD Card
  9. Blackmagic Design ATEM Mini
  10. FOINNEX Active Male VGA in Female HDMI
  11. 4Keyboard brand Commodore 64 keyboard stickers
  12. Combian pi/400

Bill of Materials

{UPDATE: 2021-11-10} Tayger made a recommendation on the MEGA65 Discord to add a cost table/bill of materials. This was a great idea and it is below.

Item Cost Suggested Link
Nexys4 $215.00 https://digilent.com/shop/nexys-4-artix-7-fpga-trainer-board/
Dell L100 Keyboard <$20.00 https://ebay.us/SIylZz
4Keyboard brand Commodore 64 keyboard stickers $4.00 https://amzn.to/38KRcHN
Micro SD Card $10.00 https://amzn.to/3BosMAe
5V 4A Switching Power Supply or USB Power Supply $20.00 https://digilent.com/shop/5v-4a-switching-power-supply/ or https://amzn.to/3qtN9tM
VGA to HDMI Convertor $11.00 https://amzn.to/2ZFSZwY
Total Project Cost ≈$280.00  

The table includes everything to purchase, but it is important to note that many readers will have these things available as parts of other projects, accessories other devices, or found in a technology recycle bin. For instance, if you have a power adapter for a Raspberry Pi, it will work with a Nexys4 FPGA and if you don’t plan to use the data connection to a PC on the Nexys4, you don’t need the barrel adapter 9V power supply. You save $20!

MEGA65 Developer’s Guide

The MEGA65 Developer Guide is part of a series of MEGA65 user guides. With a focus on the tools and techniques programmers need to develop MEGA65 software, Chapter 16 includes instructions to build a MEGA65 using a Nexys Field Programmable Gate Array (FPGA). Prior to the MEGA65 Dev Kit and the MEGA65, bitstream development occurred on FPGA boards. These boards share a Xilinx™ Artix A7 found in the Dev Kit and the MEGA65.

Because of the similarities, bitstream releases are concurrent with the Dev Kit and the MEGA65. You can purchase a Nexys, load a bitstream and files on a SD card, and build your own MEGA65; albeit without a case, floppy drive, and ports. There are other limitations, but if you want a hardware device to play on while you wait for your MEGA65 to arrive, this is an option. Let’s build a MEGA65 by selecting an appropriate FPGA board.

Summary of Build Steps

This blog post has significant detail. Below are the summarized steps to the process:

  1. Purchase Nexys hardware.
  2. Acquire a compatible keyboard (Dell LT100).
  3. Format an 8Gb microSD card to FAT32.
  4. Download the Nexys bitstream from the FileHost.
  5. Copy the bitstream to the root directory of the microSD card.
  6. Insert the microSD card into the Nexys.
  7. Connect the keyboard, video, audio, and power supply (either 9V barrel or microUSB port).
  8. Boot the bitstream to test the system and the MEGA65 onboarding screen will appear if operational.
  9. Turn off the Nexys.
  10. Turn on the computer while holding the (ALT) key on the keyboard until the MEGA65 Utility Menu Displays.
  11. Select the SD CARD FDISK+FORMAT UTILITY option and follow the prompts.
  12. Eject the microSD card.
  13. Download a .ROM file (rename the file MEGA65.ROM), SD Card Essentials (extract the .rar file), and the BASIC.D81 file from the FileHost.
  14. Place the files above and the bitstream on the root directory of the microSD card.
  15. Boot the Nexys with the SD card.

Those steps outline a high-level summary. Below are the details.

Nexys FPGA Versions

There are three Nexys FPGA boards that support the MEGA65 bitstream (more on bitstreams later):

  1. Nexys4 - discontinued and available in limited numbers.
  2. Nexys4DDR - discontinued and available in limited numbers.
  3. Nexys A7 - readily available, updated, and rebranded version of #2.

I’ll demonstrate the install on a Nexys4 that I was able to purchase from Digilent for $210. Setup for all three versions is identical.

Unbox the Nexys4

The Nexys4 comes in a plastic case similar to a thicker DVD case. The case includes the Nexys4 and a micro USB cable. It does not include instructions which are available online as I discuss below.

Nexys4 and Case

Nexys4 A7 Anatomy Primer

Before using the MEGA65 bitstream on the Nexys4, it is important to understand the input/output (I/O) features of the hardware necessary for this project. These components are shown in the image below.

Nexys4 Hardware

I will not cover every hardware feature. See the Nexys A7 Reference Manual, which I used as a reference.

Micro USB

The micro USB port provides two functions; power and a serial connection. This project will use the micro USB port to provide power to the Nexys4 since I don’t have an external power supply. I won’t cover the serial connection; however, this port can connect the Nexys4 to a Mac or PC using M65 Connect or the MEGA65 command-line tools to manage and control the MEGA65.

Power Supply

You can provide power to the board using a micro USB port, a barrel jack, or a battery:

  1. Micro USB port - Use a USB power supply that provides 4.5VDC to 5.5VDC and at least 1A. For this project, use 2 to 3A as reading the SD card may require additional power to operate reliably.
  2. Barrel Jack - Use a power supply with a coax, center-positive 2.1mm internal-diameter plug that delivers 4.5VDC to 5.5VDC and at least 1A.
  3. Battery - Maximum voltage is 5.5VDC. The minimum voltage depends on the application. USB host function (J5) requires at least 4.6V. Other applications may require the minimum voltage of 3.6V.

I used the micro USB port with a Kano Kit wall wart. The specifications are below:

Jumper JP3 selects USB as the power source as shown below:

Power Supply Jumpers

Input/Output (I/O) Devices

The Nexys4 includes slide switches, a USB port for HID keyboard/mouse devices, VGA for video out, and a 3.5mm jack for audio.

Slide Switches

This project does not require the use of the slide switches at the bottom of the board; however, ensure all switches are in the down position, or away from the LED display as shown in the image below:

Nexys4 Slide Switches

USB Keyboard

Finding a USB keyboard that works with the Nexys4 is the hardest part of this project. While researching this project on the MEGA65 Discord, the recommendation was to use the “cheapest,” “dirtiest,” “nastiest” Dell keyboard I could find. Mechanical keyboards do not work, nor do keyboards with track pads or USB ports. The following keyboards did NOT work:

My penchant for mechanical keyboards was a detriment to this project. Searching through a recycle bin, I found two Dell keyboards:

  1. L100
  2. KB216t

The Dell L100, shown below, worked while the KB216t provided the same non-working result of the previous six make and models.

Dell L100 Keyboard

NOTE: Discord user Lydon is asking everyone to share the keyboards that work, or don’t, to compile a list. The process is simple, but you will need a *NIX OS and use the lsusb command. Lydon describes the process in his post.

You can view a list of working/non-work keyboards on the MEGA65 Wiki page.

VGA Device

A VGA port provides video out. You can connect this port to a VGA monitor or a capture device. I used a Black Magic Design ATEM Mini with VGA to HDMI adapter to capture video for the companion blog post as shown in the image below:

VGA to HDMI Adapter

Audio

A 3.5 mm audio jack provides audio out. This can be a headphone, powered speaker, or capture device. I can use either the ATEM mini or my VGA to HDMI adapter to capture the audio.

Use the Nexys4 Self-Test

Before installation of the MEGA65 bitstream, test the board to make sure it is operational. To use the on-board Nexys4 self-test, and with the Nexys4 off, move the pin on the external configuration jumper (SD/USB) to USB as shown in the image below:

Nexys4 Self Test Jumper Settings

Turn on the Nexys4 and the self-test will display as shown in the image below:

Nexys4 Self-Test

The reference manual lists the self-test functions below:

  1. The VGA port displays feedback from the onboard microphone, temperature sensors, accelerometer, RGB LEDs, and USB Mouse.
  2. The user LEDs illuminate when the corresponding user switch is on.
  3. Micro-switches control the tricolor LEDs. Pressing BTNL, BTNC, or BTNR causes them to illuminate either red, green, or blue, respectively. Pressing BTND cycle through the colors. Repeatedly pressing BTND will turn the two LEDs on or off.
  4. Pressing BTNU will trigger a 5 second recording from the onboard PDM microphone. A mono audio out port replays the audio. User LEDs display the status of the recording and playback. DDR2 memory is used to store the recordings.
  5. Connecting a mouse to the USB-HID Mouse port allows the pointer on the VGA display to be controlled. The board only supports mice compatible with the boot mouse HID interface.
  6. The seven-segment LEDs display a moving snake pattern.

Prepare a microSD Card

With operational hardware, the next step is to prepare a microSD that will boot the Nexys4 with the MEGA65 bitstream. The first step is to format the microSD.

Format a microSD Card

Consult your OS for specific instructions, but below an outline of the process on a Mac computer.

  1. Insert a microSD card into your Mac.
  2. Open the Disk Utility application.
  3. Format the microSD card as a single FAT32 partition.
  4. The name of the microSD card is unimportant, but consider “NEXYS4-C65”.
  5. Do not remove the microSD card from the computer.

The microSD is now ready for a bitstream file.

Download the MEGA65 bitstream

A bitstream is the data to load into a field-programmable gate array (FPGA) to configure the Nexys4 hardware as a MEGA65. Download the latest version of the bitstream from the MEGA65 FileHost.

Copy the bitstream to microUSB

Copy the bitstream to the root directory of the microSD card. Ensure there are no other files on the microSD card. Later, we will format this same microSD card and add files to create a boot disk. Keep a copy of the bitstream on the computer. You will need it later.

Boot the bitstream

Use the bitstream to boot the Nexys4 with the instructions below:

  1. Place the microSD card into the Nexys4 microSD card reader.
  2. Plug in a USB keyboard.
  3. Connect a VGA display device.
  4. Connect a micro USB cable connected to a power supply to the micro USB port.
  5. Turn on the Nexys4 and the MEGA65 on-boarding screen below will display. This screen verifies the MEGA65 is operational.

    MEGA65 Boots on Nexys4

  6. Turn off the Nexys4.

NOTE: If the screen below appears in a continual loop, try a different microSD. Non-working microSD card

With an operational MEGA65 Nexys4 bitstream, we can now format the micro SD Card for MEGA65 use.

Format a microSD on the MEGA65

Use the steps below to boot the MEGA65 Utility Menu and format the micro SD card:

  1. Turn off the Nexys4.
  2. Hold the ALT key on the keyboard.
  3. Turn on the Nexys4.
  4. Release the ALT key when the Utility menu loads as shown below:

    Utility Menu

  5. Select the SD CARD FDISK+FORMAT UTILITY menus option by hitting 2 on the keyboard.
  6. Type 0 to select the micro SD card.
  7. Type DELETE EVERYTHING + to verify the format option
  8. Once the format process is complete, turn off the Nexys4. Ignore the restart options on the menu. The micro SD care can no longer boot the Nexys4 because it is empty and without a bitstream.
  9. Remove the microSD card from the Nexys4.

The microSD card has two partitions; One hidden and used by the MEGA65 to store configuration files, and another that is user accessible to store SD Card Essentials, a .ROM file, and .D81 disk images.

Copy files to micro SD card

Move to a computer and copy the required files using the steps below:

  1. Insert the microSD card in a Mac or PC.
  2. Download the following files:

  3. Copy the bitstream downloaded earlier to the root directory of the microSD card.
  4. Decompress the SD Essentials .rar file.
  5. Copy all the files to the root directory of the microSD card.
  6. Rename the file ROM file to MEGA65.ROM.
  7. Copy the MEGA65.ROM file to the root directory of the microSD card.
  8. Copy the BASIC.D81 file to the root directory of the microSD card.
  9. Eject the microSD card from the computer.

The microSD card is now ready to use in the Nexys4.

Boot the Nexys with the microSD card

The SD card is ready to boot the Nexys4 as a MEGA65 using the steps below:

  1. Insert the microSD card into the Nexys4 microSD card reader.
  2. Use the power switch to turn on the Nexys4 FPGA. The Nexys4 will boot and after a few seconds will display the screen below:

MEGA65 Start-Up Screen

Operating the MEGA65 on the Nexys4

Using the MEGA65 isn’t an intuitive experience. There are several hardware controls the new user needs to know to use the MEGA65. I’ll cover these next.

USB-Keyboard Key Mapping

Using a PC keyboard to emulate a Commodore keyboard is a frustrating experience. This is one reason that the Dev Kit and MEGA65 provide an exceptional user experience that recreates that official 1980s computing feel. There is something you can do to make the experience better.

If you use this setup long term, I recommend you purchase these 4Keyboard brand Commodore 64 keyboard stickers. I use them on my Combian pi/400 and they serve as a reminder of the keys needed to use colors/PETSCII or other Commodore functions not found on modern keyboards.

Combian pi/400

Below are important U.S. keyboard mappings you need to get started using the MEGA65 on the Nexys4 since the original Commodore key mappings are not the same as modern keyboard mappings:

PC Key MEGA65 Function
PAGE UP RESTORE
ESC RUN/STOP
WINDOWS MEGA
`
@
^ &
&
* (
( )
= -
[ @
] *
\ =
; :
;
DEL
INS £
F1 40/80 Column Mode
F3 Directory
Shift-F3 DIR “*=PRG”
F5 Forward a Word
F7 Back a Word
Shift-F7 Monitor
F12 Delete
NUM Lock Activate WASD Joystick Mode

On-screen Keyboard

Useful for the MEGAPhone development, the MEGA65 bitstream includes an on-screen keyboard.

MEGAPhone On-Screen Keyboard Image Courtesy: MEGA65 Blog Post

The virtual keyboard will display keyboard mappings when you use a U.S. keyboard layout. There are two ways to activate the on-screen keyboard:

Configuration Mode

  1. Hold the ALT key and turn on the power or press the PROG micro-switch on the Nexys4 board.
  2. Choose option 3 when the Configuration Menu displays.

The virtual keyboard shown in the image below will display.

MEGA65 Utility Application Virtual Keyboard

Immediate Mode Keyboard

  1. Boot the MEGA65 bitstream on the Nexys4.
  2. Hold the [MEGA] key (or Windows key on a Dell keyboard) and press [TAB]. The Matrix Mode Debugger will appear.
  3. Use one of the two commands below to display a semi-transparent virtual keyboard:

    • s ffd3615 ff + – display the keyboard at the top of the screen
    • s ffd3615 ff ff + – display the keyboard at the center of the screen
  4. Press [MEGA] + [TAB] to exit the Matrix Mode Debugger and you will have an overlay of the keyboard as you type, as shown in the image below:

    Virtual Keyboard

  5. To hide the virtual keyboard, press [MEGA] + [TAB] and type the command s ffd3615 7f + followed by another [MEGA] + [TAB]. Huge thanks to Paul for this one!

The virtual keyboard, and the Matrix Mode Debugger have display issues. The screen overlaps the right and left side, as shown in the image above. Checking in with Paul again, he shared:

“Yes, this is a known problem. It was designed for 800 wide on the handheld, not 720 of the desktop.”

FPGA Micro-Switch Controls

There are seven onboard micro-switches and we use the three shown below for the MEGA65 implementation:

Micro-switches

  1. CPU RESET - Resets the FPGA with the current bitstream and does not clear FPGA memory contents.
  2. PROG - Resets the FPGA, clears FPGA memory contents, and reloads the current bitstream.
  3. BTND - [RESTORE] key alternative

We won’t use the other buttons, but will use these three to operate the MEGA65.

Joystick Emulation

There is no joystick port on the Nexys4, but the bitstream provides joystick emulation via the keyboard using the steps below:

  1. Press the [NUM LOCK] key on the keyboard
  2. Joystick #1 controls use the WASD format; W = ↑, A = ←, S= ↓, and D = →. The left shift key or 0 on the num pad = fire button.
  3. Joystick #2 uses the cursor keys and the cursor keys on the num pad. Space = fire button.

Basic Nexys4 Use

With a bitstream on the Nexys4 and an understanding of how to operate the device, watch the companion video for a demonstration of ways to use the MEGA65 to run your favorite Commodore 64 software or new MEGA65 software from the FileHost.

Final Thoughts

  1. If you build your own Nexys4 based MEGA65 and you have questions, please join me over on the MEGA65 Discord on the #nexys channel. I will do my best to answer questions, as will the rest of the community.
  2. Getting the MEGA65 bitstream working on the Nexys4 was a journey. It started with a YouTube livestream, where I had lots of help troubleshooting the keyboard, to this complete set of instructions and companion video. It’s been a blast.
  3. What’s next you ask? You didn’t? I have an answer. I have another project planned with this Nexys4. It’s ambitious, but hope to finish it in the coming months.
  4. The Nexys4, and the MEGA65, have PMOD ports. These ports provide hardware additions and I’d love to see a joystick port addition.
  5. Why would I install a MEGA65 bitstream on a Nexys4 when I have a MEGA65 Dev Kit and a MEGA65 on the way? You sure are full of questions today! The answer is, to understand the entire hardware experience. The Nexys4 was the original development board. Working through this exercise gives me the full gamut of hardware experiences. A perk for the reader is that users who don’t have a Dev Kit or feel the MEGA65 is not within their financial resources, now have a less expensive hardware option to learn and experiment with while they save or wait for a MEGA65 price drop.

Join the Fun

Don’t miss the retro-computing fun. SUBSCRIBE to my YouTube channel and check out my other posts.

Help make this content better! Leave your comments, corrections, additions, and thoughts in the comments below. You can email me at retrocombs@icloud.com. Thanks for reading and, please let others know about the blog using the hashtag #retroCombs.

🕹️ retroCombs, OUT!

comments powered by Disqus