Giter VIP home page Giter VIP logo

bf-romulator's Introduction

bf-romulator

Romulator - RAM/ROM replacement and debug for 6502 and Z80 CPU systems

romulator - verilog code to implement ROMulator RAM/ROM replacement

programmer - programmer and console application for updating ROMulator, and debug

tools - C++ tools for building firmware images for ROMulator

About

The ROMulator is a RAM/ROM replacement device for 6502 and Z80 systems, with programmable memory maps and debug functionality which allows you to halt a running CPU and read from or write to memory. See https://bitfixer.com/romulator for more information.

This Readme mostly covers the 6502 version for now, more documentation coming soon for Z80.

Installation

To use the ROMulator, first remove the 6502 CPU from its socket on the PET (or other computer)'s motherboard. Note the orientation of the notch on the 6502 chip in the socket. Insert the 6502 chip into the 40-pin socket on the ROMulator board. Make sure the notch on the chip is aligned with the notch on the ROMulator socket. Then, take the ROMulator board, and using the pins on the underside of the board, insert it into the 6502 socket on the motherboard. Make sure the notch on the 6502 chip is pointing in its original direction. If the ROMulator is inserted backwards, this may damage the ROMulator board since 5v will be presented where it shouldn't be. Just make sure to double check:

  • Original orientation of 6502
  • 6502 chip notch should match with notch in ROMulator socket
  • When inserting ROMulator into 6502 socket, 6502 chip should be in its original orientation

Default Switch Settings

The ROMulator supports up to 32 memory maps. The default memory maps shipped with the ROMulator are currently mostly related to the Commodore PET, but you can add any maps you want via the programming interface. Over time more configurations for common 6502 computers will be added. Please note that these settings reflect the head commit of the repository, and may differ from the default settings on your ROMulator depending on when it was programmed. Building the latest version with make program after a git pull will generate the settings as described. The default switch settings are as follows:

Set Index Setting Switch 1 Switch 2 Switch 3 Switch 4
0 BASIC 2, NON-CRTC, Business Kbd (i.e. 2001) Off Off Off Off
1 BASIC 4, NON-CRTC (i.e. 2001) On Off Off Off
2 BASIC 4, CRTC, 80C (i.e. 8032) Off On Off Off
3 BASIC 4, CRTC, 40C (i.e. 4032,4016) On On Off Off
4 BASIC 4, PET 4032 60Hz Off Off On Off
5 BASIC 2, NON-CRTC, Normal Kbd (i.e. 2001) On Off On Off
6 BASIC 4, PET 4032 50Hz Off On On Off
7 BASIC 4, PET 4016 60Hz On On On Off
8 Apple II plus Off Off Off On
9 BASIC 1, PET 2001-8 On Off Off On
10 VIC-20 PAL Off On Off On
11 VIC-20 NTSC On On Off On
12 NOP Generator Off Off On On
13 PETTESTER On Off On On
14 PET Low RAM Test Off On On On
15 PET RAM/ROM/VRAM Test On On On On

The memory maps are defined in config/memory_set_default.csv. This file indicates which ROMs are located at which memory address.

Adding Configurations for New 6502 Machines

This topic is big enough to have its own readme, and it is located here:
config/README.md

Program / Debug

Programming and Debugging with the ROMulator can be done in one of two ways:

  • using a Raspberry Pi connected to the ROMulator's 10-pin header, or
  • using a standalone programmer consisting of a D1 Mini Board (dev board for ESP12 wifi microcontroller module) and an interface board for connecting to the ROMulator. This method allows uploading new firmware over a wifi network as well as a direct connection to a Win/Linux/Mac using usb.

Program / Debug with Standalone Programmer over WiFi or USB

Information on programming and debugging using the standalone programmer can be found here:
ROMULATOR_STANDALONE.md

Program / Debug with Raspberry Pi

Programming or Debug functionality of the ROMulator uses a Raspberry Pi using a soft SPI implementation. You can use the optional RPI ROMulator programming board, or directly connect the following RPI physical pins to the corresponding pins on the 10-pin header on the ROMulator FPGA board:

RPI FPGA Hdr FPGA Hdr RPI
19 1 (MOSI) 2 (3.3v) 17
24 3 (CS) 4 (DBG) 36
22 5 (RST) 6 (CDONE) 11
23 7 (SCK) 8 NC
21 9 (MISO) 10 (GND) 34

If you are only programming and not running the debug client, DBG and CDONE are optional. Take a look at this wiring diagram for a visual aid: programming/debug diagram

ROMulator programming board

The optional RPI ROMulator programming board is just a breakout board for SPI and UART on the Pi which brings SPI0 and SPI1 pins out to separate headers, as well as a UART header. The ROMulator only uses the SPI0 header. If you received a kit for this board, here are a few quick notes on the assembly.

  1. Solder header pins onto the TOP of the board in the section marked 'SPI0'.
  2. Solder a 2-pin header onto the header section directly adjacent to SPI0.
  3. Solder the 2x20 socket onto the BOTTOM of the board.
  4. Connect the jumper onto the 2-pin header for programming. Remove for debug.
  5. When attaching the board to the raspberry pi, the headers face away from the body of the raspberry pi. Depending on how the connectors are attached to the ribbon cable, it may be connected in one of two ways. Just make sure there is no twist in the cable. See these images for reference:
If your cable looks like this: Connect it like this.

Or,

If your cable looks like this: Connect it like this.

Please follow this procedure to enter debug mode on the romulator and read the contents of a running CPU.

  1. run make bin/console from bf-romulator directory
  2. run make debug to set appropriate pin directions on the pi. Specifically, this sets the DBG line to 1 to allow the ROMulator to start and not be stuck in a halt state, and sets the RST line to an input to avoid holding the fpga in reset.
  3. If you are using the optional RPI programming board, remove the programming jumper.
  4. run bin/console -r > output.bin to halt the cpu and read the full memory map into a file called output.bin.

Installation

To install the ROMulator software on a Raspberry PI for programming or debug, download the script setup.sh onto your Pi and execute from your home directory. This will install the prequisites and fetch the latest version of the code in this repo.

The one-liner for this on the command line is:
wget -O - https://raw.githubusercontent.com/bitfixer/bf-romulator/master/setup.sh | sudo bash

Programming

To program a new firmware onto the ROMulator, run
make program
from the ~/bf-romulator directory.

Note that you will need all of the roms present in order to complete the build.
This means that every unique rom specified in config/memory_set_default.csv to be present in the bf-romulator/roms directory.
For convenience if you are downloading ROM images from a single source, there is a script which will do this for you.
If you were downloading every rom with the base url of http://bitfixer.com, you would run the command:
BASEURL=http://bitfixer.com make fetch_roms
This downloads every unique rom specified in config/memory_set_default.csv to the roms directory.

Programming Custom Firmware

If you just want to program a custom .bin file (if I send you one, for example) the procedure is a bit simpler. Before the first time doing this run
make bin/programmer_spi
from the ~/bf-romulator directory.

Then, copy the custom .bin file somewhere on your raspberry pi, and run
bin/programmer_spi < customfirmware.bin
from the ~/bf-romulator directory, replacing customfirmware.bin with the actual path of that file.

Virtual Display

A recent feature added to the ROMulator is the ability to create a virtual external display, using a connected Raspberry Pi as a webserver. By pointing a browser to the pi server, you will be able to 'see' the contents of video ram in realtime rendered into bitmap images.
Currently, only the PET 2001 is supported, but other 6502 machines with memory-mapped graphics will be added soon.
To use the virtual display feature on a PET 2001, connect the ROMulator to the 6502 socket on the pet, and connect the Pi via the interface board with the programming jumper OFF. For now only setting 1 (Sw 1 ON, rest OFF) is supported, which is BASIC 4.
Power up the PET as usual, and the ROMulator LED should blink on for about one second. Then from the console on your Pi, from the bf-romulator directory, run:
make webserver
Then open a browser on another computer on the same network as the Pi, and navigate to the pi's server, like so:
http://raspberrypi.local:10000/canvas.html
Please note that while the pi will usually show up as raspberrypi.local, this is not always the case and you may need to know the actual local IP. At this point you should be able to enjoy a roughly 15-20 FPS PET 2001 display in your browser!

bf-romulator's People

Contributors

bitfixer avatar lagomorph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bf-romulator's Issues

Issue with Romulator

I just received and assembled the romulator but it doesn’t work in my Pet 8032. The FPGA flashes once and then nothing, not even the chirp. This is in a working PET with a working 6502.

Can only access 1023 bytes of vram of size 1024 bytes

Tested with - Standalone Programmer-Debugger D1-mini

When the D1-mini tries to read the last 8 bytes of vram, the first 7 bytes read from this section of the FPGA are correct but the last byte is wrong.

This is due to an incorrect vram size parameter calculation in verilog code "enable_logic.v". The size should be 1024 bytes, but 1023 is set.

Change :
wire [10:0]vram_size = vram_end[config_byte] - vram_start[config_byte];
to
wire [10:0]vram_size = vram_end[config_byte] + 1 - vram_start[config_byte];

With this change, once the FPGA has sent the last byte the address rolls over from 1023 to 0 when the code adds 1 to 1023 (11 bit wide address bus). This additional change is therefore required.

Change line from
else if (vram_address == vram_size)
to
else if ( (vram_address == vram_size) || (vram_address == 0) )

Cannot get fetch_roms.py working. Ubuntu server and Windows wsl ubuntu

Issuing the command 'BASEURL=http://bitfixer.com make fetch_roms' I get the following error.
I also get this trying to use the zimmers pet rom directory as the base.

user@ubuntu-compiler:~/bf-romulator$ BASEURL=http://bitfixer.com make fetch_roms
mkdir -p roms
#cd bin; python ../tools/fetch_roms.py /home/user/bf-romulator/config/memory_set_default.csv http://bitfixer.com
cd roms; python ../tools/fetch_roms.py /home/user/bf-romulator/config/memory_set_default.csv http://bitfixer.com
Traceback (most recent call last):
File "../tools/fetch_roms.py", line 26, in
for row in romreader:
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
make: *** [Makefile:85: fetch_roms] Error 1

Any suggestions?

ERROR: IO 'dataout[7]' is unconstrained in PCF

Hello Michael,

many thanks for the romulator 6502. it really is a great tool.

I have a problem with creating my own custom firmware. The "make program" process is always aborted with an error message. I just can't find the problem and hope you could give me a hint.

I am using a Raspberry Pi 3+ with the latest RaspianOS (64Bit).

When I generate the files via your website, the firmware works on the romulator.

Best regards Frank

Logfile:

pi@romulator:~/bf-romulator $ make program
gpio mode 27 out
gpio write 27 1
gpio mode 6 out
gpio mode 10 out
bin/programmer -b
mkdir -p bin
bin/build_enable_table /home/pi/bf-romulator/config/enable_table_default.csv bin/enable_table.bin > bin/enable_table.txt
mkdir -p bin
cd /home/pi/bf-romulator/romulator; rm -f input*.v; rm -f *.pcf
cp /home/pi/bf-romulator/romulator/6502/* /home/pi/bf-romulator/romulator
cd /home/pi/bf-romulator/romulator; rm -f hardware.*; apio build
(DEBUG) Profile path: /home/pi/.apio/profile.json
(DEBUG) Home_dir: /home/pi/.apio

PATH: /home/pi/.apio/packages/tools-oss-cad-suite/bin:/home/pi/.apio/packages/tools-oss-cad-suite/lib:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

[Fri Jan 12 20:36:50 2024] Processing upduino
------------------------------------------------------------------------------------------------------------------------
yosys -p "synth_ice40 -json hardware.json" -q SPI_Master.v diagnostics.v enable_logic.v input6502.v ramenable.v simple_ram_dual_clock.v spi_flash_reader.v spi_slave.v sram.v sram64k.v
Warning: Yosys has only limited support for tri-state logic at the moment. (spi_slave.v:197)
Warning: Resizing cell port sram.ramfn_inst1.POWEROFF from 32 bits to 1 bits.
Warning: Resizing cell port sram.ramfn_inst1.SLEEP from 32 bits to 1 bits.
Warning: Resizing cell port sram.ramfn_inst1.STANDBY from 32 bits to 1 bits.
nextpnr-ice40 --up5k --package sg48 --json hardware.json --asc hardware.asc --pcf up5k.pcf -q
Warning: unmatched constraint 'spi_clk' (on line 1)
Warning: unmatched constraint 'spi_miso' (on line 2)
Warning: unmatched constraint 'spi_out' (on line 3)
Warning: unmatched constraint 'spi_cs' (on line 4)
Warning: unmatched constraint 'data[0]' (on line 6)
Warning: unmatched constraint 'data[1]' (on line 7)
Warning: unmatched constraint 'data[2]' (on line 8)
Warning: unmatched constraint 'data[3]' (on line 9)
Warning: unmatched constraint 'data[4]' (on line 10)
Warning: unmatched constraint 'data[5]' (on line 11)
Warning: unmatched constraint 'data[6]' (on line 12)
Warning: unmatched constraint 'data[7]' (on line 13)
Warning: unmatched constraint 'phi2' (on line 33)
Warning: unmatched constraint 'rwbar' (on line 34)
Warning: unmatched constraint 'dataoutenable' (on line 36)
Warning: unmatched constraint 'busenable' (on line 37)
Warning: unmatched constraint 'diag_spi_cs' (on line 39)
Warning: unmatched constraint 'rdy' (on line 40)
Warning: unmatched constraint 'rst' (on line 41)
Warning: unmatched constraint 'led_blue' (on line 43)
ERROR: IO 'dataout[7]' is unconstrained in PCF (override this error with --pcf-allow-unconstrained)
ERROR: Loading PCF failed.
20 warnings, 2 errors
scons: *** [hardware.asc] Error 255
============================================= [ ERROR ] Took 9.53 seconds =============================================
make: *** [Makefile:130: bin/hardware_6502.bin] Fehler 2
pi@romulator:~/bf-romulator $

Support for BBC computers?

Do you have any available memory map files (or rather the stanzas) for the BBC Micro ( or B), or BBC Master to put in config/memory_set_default.csv?

bin/console 'c to change config' not working for custom config files

Custom configurations that use their own non-default files such as: memory_set_apple1.csv, enable_table_apple1.csv
will fail to load when using the new 'c to change configuration' feature of bin/console

This is because the profile value of 'default' is hard-coded in line 39 of console.cpp:
const char* profile = "default";

If possible one solution might be to integrate console into the Makefile and pass profile definition as argument on the g++ line ($(CONFIG))

Parity Error Check Bug - When D1-mini sends 0x22 for a reread after a parity error the FPGA does not decrement the address by 8.

I tested using the incrementing byte pattern that vram is initialized too by file vram_test.txt, and then loading the canvas.html page on the standalone D1-mini programmer with the relevant "verbose = true" in function romulatorReadVramBlock() in module libRomulatorDebug.cpp to print out the returned data values.

To produce a parity error to test the FPGA I forced a send of 0x22 to the FPGA when a specific vram address was accessed and looked at the data returned by the FPGA.

The error in the FPGA verilog code is in the VERIFY_PARITY_BYTE section of the state machine in "diagnostics.v". Change line 219 from "if (rx_dv <= 1'b1)" to "if (rx_dv == 1'b1)"

VERIFY_PARITY_BYTE:
begin
  tx_dv <= 0;
  // if (rx_dv <= 1'b1)
  if (rx_dv == 1'b1)
  begin
    if (rx_byte == PARITY_ERROR)
    begin
      vram_address <= vram_address - 8;
    end
    state <= NEXT_VRAM_BYTE;
  end
end

Now that "if (rx_dv == 1'b1)" is functioning properly, the D1-mini code needs to be modified in file "libRomulatorDebug.cpp".

Between lines 356 and 357 add
// Advance FPGA so it can prepare the next vram byte for sending over SPI.
xfer(0x0);

A similar change should also be made on the Raspberry Pi code for that version of debugger.

D1-mini : Buffer Overflow on Reading Long Configuration File Lines

In function handleCharacterRom() in file "rServer.cpp" buffer overflow can occur when reading the config file if a line is longer than 128 characters such as a comment line. This happened to me resulting in a segmentation fault and crash.

Fix is to limit reads to 128 bytes maximum. Add the start of the file add the following

#define MAX_LINE_CHARS 128

Line 158 change
char line[128];
to
char line[MAX_LINE_CHARS];

Between line 215 and 216 add
if (numchars > MAX_LINE_CHARS) numchars = MAX_LINE_CHARS

such that the code now looks like this
while (!found)
{
while (*end != '\n' && *end != 0 && end - tableBegin < enableTableLen) {
end++;
}

    int numchars = end-start;  
    if (numchars > MAX_LINE_CHARS) numchars = MAX_LINE_CHARS;
    strncpy(line, start, numchars);
    line[numchars] = 0;

Adressdecoding for Commodore 1541 Floppy Drive

Hello Michael,

I used your great Romulator 6502 in my Commodore 1541 floppy drive. I can now use many floppy speeders like DolphinDos etc. with it. However, there is a small improvement for your Romulator in a 1541 floppy drive. The IO ICs VIA are at address $1800 and $1C00 and are mirrored by the simple address decoding every 2K in the address space. This has the disadvantage that with the romulator from $2000 - $7FFF I cannot provide any additional memory through the romulator, as the VIAs then interfere with write accesses /WE. But I have found a solution. If you set the A15 on the mainboard address bus to high, then the VIAs no longer interfere and I can insert additional RAM from $2000-$BFFF. Then DOS and KERNAL appear. Maybe that would be a feature for the Romulator. I have an intermediate board running at the moment. But I think that something like this can also be built into the Romulator as a feature.

Logic:
Stop VIAs Mirroring on 1541 Floppydrive
------
CPU A15----+ |
CPU A14----+ OR + ----A15 Mainboard 1541 Floppydrive
CPU A13----+ |
-------

Greetings from Berlin
Frank

65c02 Apple IIe Enhanced

Not sure if this is the right place but I just got my romulator put together and tested as working. I was hoping to use this to dig into my Apple IIe (enhanced). I noticed there are through holes for a jumper with the board silk screen showing to connect for a 65c02 which I have done. However there seems to only be a rom entry for the Apple II+ in the default enable and memory mapping.

I was hoping to get some help figuring out how to add an Apple IIe Enhanced entry since I have the system with upgraded rom that's been tested and working 100%,.

My understanding is that the dip switches on the romulator are for selecting the rom / memory map to load. So I would imagine I need to dump the rom from the machine, then somehow figure out a mapping. After that I would need to get those added into the firmware for the fpga?

To be honest I'm new to all this and part of why I want to get this working is to just learn more about the 6502 era of computing. This started with ben eater's fantastic 6502 breadboard computer kit which I also intend to program into the romulator eventually.

Anyways, some advice, steps, or general information would be helpful as I'm still getting oriented.

The romulator FPGA image doesn't always meet timing when minor modifications are made to the verilog code.

I found that when modifying FPGA verilog code that even though the code builds correctly without errors using the provided tools and scripts it doesn't always run correctly. Sometimes even removing a few lines of non-called verilog code will result in the FPGA going from working to not functioning at all, or partially functioning. Such as random spi errors causing partially missing data and a distorted image on canvas.html web page.

After going around in circles for many days I found that the recompiled verilog images likely did not meet timing despite no warning.

The installation instructions and script provided forces apio version 0.5.4 and uses the FPGA tools and versions assigned to this apio version. In windows subsystem for linux later versions of apio and tools will build the romulator image but with timing errors. (Note, only Raspberry Pi 64bit OS is supported in the newer tools for those using that for synthesizing/placing/routing). I upgraded to apio version 0.8.1 in WSL debain and timing errors are reported with this latest version. For example :

"ERROR: Max frequency for clock 'romulator.clk': 34.93 MHz (FAIL at 48.00 MHz).

Changing the clk clock frequency from 48MHz to 24MHz resolved the timing error reported by the packages in apio 0.8.1 and converted non-working code built by apio tools installed on version 0.5.4 to working.

I made the following clock change to the verilog code in enable_logic.v :

Change line from :
SB_HFOSC #(.CLKHF_DIV ("0b01")) inthosc(.CLKHFPU(1'b1), .CLKHFEN(1'b1), .CLKHF(clk));
to
SB_HFOSC inthosc(.CLKHFPU(1'b1), .CLKHFEN(1'b1), .CLKHF(clk));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.