Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MMFS support to the Master builds #1

Open
wants to merge 1 commit into
base: pico
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added roms/mmfs/bitbang_fedc/MAMMFS.rom
Binary file not shown.
Binary file added roms/mmfs/bitbang_fedc/MMFS.rom
Binary file not shown.
7 changes: 7 additions & 0 deletions src/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "z80.h"
#include "6502.h"

#ifdef INCLUDE_MMFS
#include "mmc/mmc.h"
#endif

#define CFG_SECT_LEN 20

fdc_type_t fdc_type;
Expand Down Expand Up @@ -265,6 +269,9 @@ void model_init()
m6502_init();
#ifndef NO_USE_TUBE
tube_init();
#endif
#ifdef INCLUDE_MMFS
mmc_init();
#endif
cmos_load(models[curmodel]);
}
Expand Down
21 changes: 21 additions & 0 deletions src/pico/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,20 @@ target_compile_definitions(pico_common INTERFACE
# DEBUG_SCANLINES
)


# ENABLE THIS TO INCLUDE MMFS SUPPORT ON THE RP2040 (currently Master Only)
#
# This adds a version of MMFS as ROM 8, and tweaks the config to use this
# as the default filing system.
#
# Note: On the VGA Demo Board, gpio20/21 are used for the default UART,
# and also for DAT1/2 on the SD Card. However, DAT1/2 are only used
# if the SD Card is run in 4-bit mode. MMFS only uses 1-bit SPI mode.
#
# If you want to be very safe, then there are PCB links that can be cut
# that isolate DAT1/2 on the SD card.
set(INCLUDE_MMFS 1)

# >>> ENABLE THIS TO GET USB SUPPORT ON THE RP2040 - however right now this interferes with video (actually it currently causes a panic)
#set(USE_USB_KEYBOARD 1)

Expand All @@ -233,6 +247,12 @@ if (PICO_ON_DEVICE)
)
endif ()

if (INCLUDE_MMFS)
target_compile_definitions(spock_common INTERFACE
INCLUDE_MMFS
)
endif ()

if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
target_compile_options(spock_common INTERFACE "-Ofast")
endif()
Expand Down Expand Up @@ -341,6 +361,7 @@ target_sources(spock_common INTERFACE
${CMAKE_CURRENT_LIST_DIR}/video/display.c
${CMAKE_CURRENT_LIST_DIR}/video/gui_stub.c
${CMAKE_CURRENT_LIST_DIR}/video/menu.c
${CMAKE_CURRENT_LIST_DIR}/mmc/mmc.c
)

target_include_directories(spock_common INTERFACE
Expand Down
44 changes: 44 additions & 0 deletions src/pico/mmc/mmc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "mmc.h"
#include "pico/stdlib.h"
#include "hardware/gpio.h"

#define PIN_CLK PICO_SD_CLK_PIN
#define PIN_MOSI PICO_SD_CMD_PIN
#define PIN_MISO PICO_SD_DAT0_PIN
#define PIN_CS 22

static volatile uint8_t port = 0;

void mmc_init() {
gpio_init(PIN_CS);
gpio_put(PIN_CS, 0); // Always selected
gpio_set_dir(PIN_CS, GPIO_OUT);

gpio_init(PIN_CLK);
gpio_put(PIN_CLK, 1);
gpio_set_dir(PIN_CLK, GPIO_OUT);
gpio_set_pulls(PIN_CLK, false, true);

gpio_init(PIN_MOSI);
gpio_put(PIN_MOSI, 1);
gpio_set_dir(PIN_MOSI, GPIO_OUT);
gpio_set_pulls(PIN_MOSI, true, false);

gpio_init(PIN_MISO);
gpio_set_dir(PIN_MISO, GPIO_IN);
gpio_set_pulls(PIN_MISO, true, false); // This pullup is crucial!
}

uint8_t mmc_read(uint16_t addr) {
if (gpio_get(PIN_MISO)) {
return port | 0x80;
} else {
return port & 0x7f;
}
}

void mmc_write(uint16_t addr, uint8_t val) {
port = val;
gpio_put(PIN_CLK, port & 2);
gpio_put(PIN_MOSI, port & 1);
}
10 changes: 10 additions & 0 deletions src/pico/mmc/mmc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _MMC_H
#define _MMC_H

#include <inttypes.h>

void mmc_init();
uint8_t mmc_read(uint16_t addr);
void mmc_write(uint16_t addr, uint8_t val);

#endif
10 changes: 9 additions & 1 deletion src/pico/roms/cmos.bin.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
static unsigned char cmos[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc9, 0xff, 0xff, 0x12, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

// If MMFS is included, then use it as the default filesystem
#ifdef INCLUDE_MMFS
0xc8,
#else
0xc9,
#endif
0xff, 0xff, 0x12, 0x00,
0x17, 0xca, 0x1e, 0x05, 0x00, 0x35, 0xa6, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down
1 change: 1 addition & 0 deletions src/pico/roms/master_roms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
!path ../../../roms

mos320 = os/mos320.rom
mmfs = mmfs/bitbang_fedc/MAMMFS.rom
3 changes: 3 additions & 0 deletions src/pico/stub_allegro5/al_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ struct {
{"cmos", "cmos"},
{"tube", "none"},
{"romsetup", "master"},
#ifdef INCLUDE_MMFS
{ "rom08", "mmfs" },
#endif
// { "rom08", "vdfs" },
// {"disc0", GAME_ROOT "/bs-badappl.dsd"},
// {"disc0", GAME_ROOT "/bs-wave-runner-v1-1.ssd"},
Expand Down
11 changes: 11 additions & 0 deletions src/thumb_cpu/src/cpu_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include "hw_event_queue.h"
#include "hardware/gpio.h"

#ifdef INCLUDE_MMFS
#include "mmc/mmc.h"
#endif

CU_REGISTER_DEBUG_PINS(hw_event, hw_reading, hw_writing)
//CU_SELECT_DEBUG_PINS(hw_event)
//CU_SELECT_DEBUG_PINS(hw_reading)
Expand Down Expand Up @@ -547,6 +551,10 @@ uint8_t hw_read(uint16_t addr) {
case 0x90/8:
case 0x98/8:
return non_master_fdc_read(addr);
#ifdef INCLUDE_MMFS
case 0xdc/8:
return mmc_read(addr);
#endif
#endif
#ifndef NO_USE_ADC
[0xc0/4] = master_only_adc_read,
Expand Down Expand Up @@ -797,6 +805,9 @@ static void (*sheila_write_funcs[])(uint16_t addr, uint8_t val) = {
[0xd8/4] = master_only_adc_write,
[0xdc/4] = master_only_adc_write,
#endif
#ifdef INCLUDE_MMFS
[0xdc/4] = mmc_write,
#endif
#ifndef NO_USE_TUBE
[0xe0/4] = tube_host_write,
[0xe4/4] = tube_host_write,
Expand Down