Skip to content

Commit

Permalink
Updated to Pico SDK 2.0.0. Added binary info, removed TMS PIO clock d…
Browse files Browse the repository at this point in the history
…ivider
  • Loading branch information
tschrapel committed Oct 9, 2024
1 parent feb29d0 commit 1e770c5
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 45 deletions.
54 changes: 45 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
{
"files.associations": {
"*.md": "markdown",
"xtr1common": "c",
"stdlib.h": "c",
"multicore.h": "c",
"stdio.h": "c",
"tms9918.pio.h": "c"
}
}
"cmake.options.statusBarVisibility": "hidden",
"cmake.options.advanced": {
"build": {
"statusBarVisibility": "hidden"
},
"launch": {
"statusBarVisibility": "hidden"
},
"debug": {
"statusBarVisibility": "hidden"
}
},
"cmake.configureOnEdit": false,
"cmake.automaticReconfigure": false,
"cmake.configureOnOpen": false,
"cmake.generator": "Ninja",
"cmake.cmakePath": "C:\\Users\\troy\\.pico-sdk\\cmake\\v3.28.6\\bin\\cmake",
"C_Cpp.debugShortcut": false,
"terminal.integrated.env.windows": {
"PICO_SDK_PATH": "${env:USERPROFILE}/.pico-sdk/sdk/2.0.0",
"PICO_TOOLCHAIN_PATH": "${env:USERPROFILE}/.pico-sdk/toolchain/13_3_Rel1",
"Path": "${env:USERPROFILE}/.pico-sdk/toolchain/13_3_Rel1/bin;${env:USERPROFILE}/.pico-sdk/picotool/2.0.0/picotool;${env:USERPROFILE}/.pico-sdk/cmake/v3.30.5/bin;${env:USERPROFILE}/.pico-sdk/ninja/v1.12.1;${env:PATH}"
},
"terminal.integrated.env.osx": {
"PICO_SDK_PATH": "${env:HOME}/.pico-sdk/sdk/2.0.0",
"PICO_TOOLCHAIN_PATH": "${env:HOME}/.pico-sdk/toolchain/13_3_Rel1",
"PATH": "${env:HOME}/.pico-sdk/toolchain/13_3_Rel1/bin:${env:HOME}/.pico-sdk/picotool/2.0.0/picotool:${env:HOME}/.pico-sdk/cmake/v3.30.5/bin:${env:HOME}/.pico-sdk/ninja/v1.12.1:${env:PATH}"
},
"terminal.integrated.env.linux": {
"PICO_SDK_PATH": "${env:HOME}/.pico-sdk/sdk/2.0.0",
"PICO_TOOLCHAIN_PATH": "${env:HOME}/.pico-sdk/toolchain/13_3_Rel1",
"PATH": "${env:HOME}/.pico-sdk/toolchain/13_3_Rel1/bin:${env:HOME}/.pico-sdk/picotool/2.0.0/picotool:${env:HOME}/.pico-sdk/cmake/v3.30.5/bin:${env:HOME}/.pico-sdk/ninja/v1.12.1:${env:PATH}"
},
"raspberry-pi-pico.cmakeAutoConfigure": true,
"raspberry-pi-pico.useCmakeTools": false,
"raspberry-pi-pico.cmakePath": "${HOME}/.pico-sdk/cmake/v3.30.5/bin/cmake",
"raspberry-pi-pico.ninjaPath": "${HOME}/.pico-sdk/ninja/v1.12.1/ninja",
"raspberry-pi-pico.python3Path": "${HOME}/.pico-sdk/python/3.12.1/python.exe",
"files.associations": {
"vremutms9918priv.h": "c",
"stdlib.h": "c",
"binary_info.h": "c",
"divider.h": "c"
}
}
48 changes: 32 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
cmake_minimum_required(VERSION 3.12)
# Generated Cmake Pico project file

# pull in PICO SDK (must be before project)
include(pico_sdk_import.cmake)
cmake_minimum_required(VERSION 3.13)

# pull in helpers for my custom tools
include(visrealm_tools.cmake)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Initialise pico_sdk from installed location
# (note this can come from environment, CMake cache etc)

# == DO NEVER EDIT THE NEXT LINES for Raspberry Pi Pico VS Code Extension to work ==
if(WIN32)
set(USERHOME $ENV{USERPROFILE})
else()
set(USERHOME $ENV{HOME})
endif()
set(sdkVersion 2.0.0)
set(toolchainVersion 13_3_Rel1)
set(picotoolVersion 2.0.0)
set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake)
if (EXISTS ${picoVscode})
include(${picoVscode})
endif()
# ====================================================================================

set(BUILD_SHARED_LIBS OFF)
set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR}/src/boards )
set(PICO_BOARD "pico9918_v04" CACHE STRING "Board type")

set(PROJECT pico9918)
# Pull in Raspberry Pi Pico SDK (must be before project)
include(pico_sdk_import.cmake)

set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR}/src/boards )
set(PICO_BOARD "pico9918_v04")
# pull in helpers for my custom tools
include(visrealm_tools.cmake)

project(${PROJECT} C CXX)
project(pico9918 C CXX ASM)

add_definitions(-DPICO_BUILD=1)
add_definitions(-DVR_EMU_TMS9918_SINGLE_INSTANCE=1)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

# Initialize the Pico SDK
# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()

add_subdirectory(submodules/vrEmuTms9918)
add_subdirectory(src)
add_subdirectory(test)

add_subdirectory(test)
15 changes: 13 additions & 2 deletions pico_sdk_import.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_P
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
endif ()

if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG))
set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG})
message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')")
endif ()

if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG)
set(PICO_SDK_FETCH_FROM_GIT_TAG "master")
message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG")
endif()

set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK")

if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT)
Expand All @@ -34,14 +45,14 @@ if (NOT PICO_SDK_PATH)
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
GIT_SUBMODULES_RECURSE FALSE
)
else ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
)
endif ()

Expand Down
53 changes: 48 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
set(PROGRAM pico9918)
cmake_minimum_required(VERSION 3.13)

#add_subdirectory(pio-utils)

add_executable(${PROGRAM})
# compile-time options

set(PICO9918_VERSION "0.4.2")
set(PICO9918_PCB_MAJOR_VER 0)
set(PICO9918_PCB_MINOR_VER 4)

set(PICO9918_SCANLINES 1)

# end compile-time options


# set up variables for the build process

execute_process(
COMMAND git symbolic-ref --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE PICO9918_GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

string(REPLACE "." "-" PICO9918_VERSION_STR "${PICO9918_VERSION}")

set(PICO9918_BINARY_SUFFIX -pcb-v${PICO9918_PCB_MAJOR_VER}-${PICO9918_PCB_MINOR_VER}-${PICO9918_GIT_BRANCH}-build-${PICO9918_VERSION_STR})

if (${PICO9918_SCANLINES})
set(PICO9918_BINARY_SUFFIX ${PICO9918_BINARY_SUFFIX}-sl)
endif()

if (${PICO9918_DIAG})
set(PICO9918_BINARY_SUFFIX ${PICO9918_BINARY_SUFFIX}-diag)
endif()

set(PROGRAM pico9918${PICO9918_BINARY_SUFFIX})

add_executable(${PROGRAM} )

target_sources(${PROGRAM} PRIVATE main.c palette.c clocks.pio.h tms9918.pio.h)

pico_set_program_name(${PROGRAM} "pico9918")
pico_set_program_version(${PROGRAM} ${PICO9918_VERSION})
pico_set_program_description(${PROGRAM} "PICO9918 VDP for PCB v${PICO9918_PCB_MAJOR_VER}.${PICO9918_PCB_MINOR_VER}")
pico_set_program_url(${PROGRAM} "https://github.com/visrealm/pico9918")

# generate image array source files from png images
visrealm_generate_image_source_ram(${PROGRAM} splash res/splash.png )

Expand All @@ -19,11 +57,16 @@ pico_enable_stdio_uart(${PROGRAM} 0)

pico_set_binary_type(${PROGRAM} copy_to_ram) # TOO SLOW TO BOOT

add_definitions(-DPICO9918_VERSION="${PICO9918_VERSION}")
add_definitions(-DPICO9918_PCB_MAJOR_VER=${PICO9918_PCB_MAJOR_VER})
add_definitions(-DPICO9918_PCB_MINOR_VER=${PICO9918_PCB_MINOR_VER})
add_definitions(-DPICO9918_SCANLINES=${PICO9918_SCANLINES})

add_definitions(-DPICO_DISABLE_SHARED_IRQ_HANDLERS=1)
add_definitions(-DPICO_TIME_DEFAULT_ALARM_POOL_DISABLED=1)
#add_definitions(-DPICO_TIME_DEFAULT_ALARM_POOL_DISABLED=1)
add_definitions(-DPICO_PANIC_FUNCTION=)

target_link_libraries(${PROGRAM} PUBLIC
target_link_libraries(${PROGRAM} PUBLIC
pico_stdlib
pico_multicore
hardware_pio
Expand Down
7 changes: 1 addition & 6 deletions src/boards/pico9918_v04.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
// -----------------------------------------------------

// This header may be included by other board headers as "boards/pico.h"

#ifndef _BOARDS_PICO_H
#define _BOARDS_PICO_H

#pragma once
// For board detection
#define PICO9918

Expand Down Expand Up @@ -95,5 +92,3 @@
#ifndef PICO_VSYS_PIN
#define PICO_VSYS_PIN 29
#endif

#endif
13 changes: 10 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "pico/stdlib.h"
#include "pico/multicore.h"
#include "pico/binary_info.h"

#include "hardware/pio.h"
#include "hardware/clocks.h"
Expand Down Expand Up @@ -104,7 +105,13 @@
#define TMS_PIO pio1
#define TMS_IRQ PIO1_IRQ_0


bi_decl(bi_1pin_with_name(GPIO_GROMCL, "GROM Clock"));
bi_decl(bi_1pin_with_name(GPIO_CPUCL, "CPU Clock"));
bi_decl(bi_pin_mask_with_names(GPIO_CD_MASK, "CPU Data (CD7 - CD0)"));
bi_decl(bi_1pin_with_name(GPIO_CSR, "Read"));
bi_decl(bi_1pin_with_name(GPIO_CSW, "Write"));
bi_decl(bi_1pin_with_name(GPIO_MODE, "Mode"));
bi_decl(bi_1pin_with_name(GPIO_INT, "Interrupt"));


/* file globals */
Expand Down Expand Up @@ -368,7 +375,7 @@ void tmsPioInit()
pio_sm_config writeConfig = tmsWrite_program_get_default_config(tmsWriteProgram);
sm_config_set_in_pins(&writeConfig, GPIO_CD7);
sm_config_set_in_shift(&writeConfig, false, true, 16); // L shift, autopush @ 16 bits
sm_config_set_clkdiv(&writeConfig, 4.0f);
sm_config_set_clkdiv(&writeConfig, 1.0f);

pio_sm_init(TMS_PIO, tmsWriteSm, tmsWriteProgram, &writeConfig);
pio_sm_set_enabled(TMS_PIO, tmsWriteSm, true);
Expand All @@ -387,7 +394,7 @@ void tmsPioInit()
sm_config_set_out_pins(&readConfig, GPIO_CD7, 8);
sm_config_set_in_shift(&readConfig, false, false, 32); // L shift
sm_config_set_out_shift(&readConfig, true, false, 32); // R shift
sm_config_set_clkdiv(&readConfig, 4.0f);
sm_config_set_clkdiv(&readConfig, 1.0f);

pio_sm_init(TMS_PIO, tmsReadSm, tmsReadProgram, &readConfig);
pio_sm_set_enabled(TMS_PIO, tmsReadSm, true);
Expand Down
8 changes: 7 additions & 1 deletion src/vga/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
#include "pio_utils.h"

#include "pico/multicore.h"
#include "pico/binary_info.h"

#include "hardware/dma.h"
#include "hardware/pio.h"
#include "hardware/clocks.h"

// compile options
#define VGA_CRT_EFFECT 1
#define VGA_CRT_EFFECT PICO9918_SCANLINES
#define VGA_SCANLINE_TIME_DEBUG 0
#define VGA_HARDCODED_640 1
#define VGA_NO_MALLOC 1
Expand Down Expand Up @@ -62,6 +63,11 @@ int roundflt(float x)
#define END_OF_SCANLINE_MSG 0x40000000
#define END_OF_FRAME_MSG 0x80000000

bi_decl(bi_1pin_with_name(SYNC_PINS_START, "H Sync"));
bi_decl(bi_1pin_with_name(SYNC_PINS_START + 1, "V Sync"));
bi_decl(bi_pin_mask_with_names(0xf << RGB_PINS_START, "Red (LSB - MSB)"));
bi_decl(bi_pin_mask_with_names(0xf << RGB_PINS_START + 4, "Green (LSB - MSB)"));
bi_decl(bi_pin_mask_with_names(0xf << RGB_PINS_START + 8, "Blue (LSB - MSB)"));

/*
* sync pio dma data buffers
Expand Down
2 changes: 1 addition & 1 deletion submodules/vrEmuTms9918
2 changes: 1 addition & 1 deletion tools/bin2carray.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def getFileHeader(fileName, fileList, args, isHeaderFile) -> str:
sanitizedFile = re.sub('[^0-9a-zA-Z]+', '_', baseName.upper())
hdrText += f"#pragma once\n\n"
else:
hdrText += "#include \"pico/platform.h\"\n"
hdrText += "#include \"pico.h\"\n"
hdrText += "#include <inttypes.h>"
return hdrText

Expand Down
2 changes: 1 addition & 1 deletion tools/img2carray.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def getFileHeader(fileName, romFileList, ramFileList, args, isHeaderFile) -> str
sanitizedFile = re.sub('[^0-9a-zA-Z]+', '_', baseName.upper())
hdrText += f"#pragma once\n"
else:
hdrText += "#include \"pico/platform.h\"\n"
hdrText += "#include \"pico.h\"\n"
hdrText += "#include <inttypes.h>"
return hdrText

Expand Down

0 comments on commit 1e770c5

Please sign in to comment.