Skip to content

Commit

Permalink
Merge pull request #5 from visrealm/dev
Browse files Browse the repository at this point in the history
v0.4.0
  • Loading branch information
visrealm committed Aug 4, 2024
2 parents 833314b + 990720d commit dc73003
Show file tree
Hide file tree
Showing 14 changed files with 1,127 additions and 750 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ set(BUILD_SHARED_LIBS OFF)

set(PROJECT pico9918)

set(PICO_BOARD_HEADER_DIRS ${CMAKE_CURRENT_LIST_DIR}/src/boards )
set(PICO_BOARD "pico9918_v04")

project(${PROJECT} C CXX)

add_definitions(-DPICO_BUILD=1)
Expand Down
99 changes: 99 additions & 0 deletions src/boards/pico9918_v04.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

// -----------------------------------------------------
// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO
// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
// -----------------------------------------------------

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

#ifndef _BOARDS_PICO_H
#define _BOARDS_PICO_H

// For board detection
#define PICO9918

#ifndef PICO_XOSC_STARTUP_DELAY_MULTIPLIER
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 32
#endif

// --- UART ---
#ifndef PICO_DEFAULT_UART
#define PICO_DEFAULT_UART 0
#endif
#ifndef PICO_DEFAULT_UART_TX_PIN
#define PICO_DEFAULT_UART_TX_PIN 0
#endif
#ifndef PICO_DEFAULT_UART_RX_PIN
#define PICO_DEFAULT_UART_RX_PIN 1
#endif

// --- LED ---
#ifndef PICO_DEFAULT_LED_PIN
#define PICO_DEFAULT_LED_PIN 25
#endif
// no PICO_DEFAULT_WS2812_PIN

// --- I2C ---
#ifndef PICO_DEFAULT_I2C
#define PICO_DEFAULT_I2C 0
#endif
#ifndef PICO_DEFAULT_I2C_SDA_PIN
#define PICO_DEFAULT_I2C_SDA_PIN 4
#endif
#ifndef PICO_DEFAULT_I2C_SCL_PIN
#define PICO_DEFAULT_I2C_SCL_PIN 5
#endif

// --- SPI ---
#ifndef PICO_DEFAULT_SPI
#define PICO_DEFAULT_SPI 0
#endif
#ifndef PICO_DEFAULT_SPI_SCK_PIN
#define PICO_DEFAULT_SPI_SCK_PIN 18
#endif
#ifndef PICO_DEFAULT_SPI_TX_PIN
#define PICO_DEFAULT_SPI_TX_PIN 19
#endif
#ifndef PICO_DEFAULT_SPI_RX_PIN
#define PICO_DEFAULT_SPI_RX_PIN 16
#endif
#ifndef PICO_DEFAULT_SPI_CSN_PIN
#define PICO_DEFAULT_SPI_CSN_PIN 17
#endif

// --- FLASH ---

#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1

#ifndef PICO_FLASH_SPI_CLKDIV
#define PICO_FLASH_SPI_CLKDIV 2
#endif

#ifndef PICO_FLASH_SIZE_BYTES
#define PICO_FLASH_SIZE_BYTES (2 * 1024 * 1024)
#endif

// Drive high to force power supply into PWM mode (lower ripple on 3V3 at light loads)
#define PICO_SMPS_MODE_PIN 23

#ifndef PICO_RP2040_B0_SUPPORTED
#define PICO_RP2040_B0_SUPPORTED 1
#endif

// The GPIO Pin used to read VBUS to determine if the device is battery powered.
#ifndef PICO_VBUS_PIN
#define PICO_VBUS_PIN 24
#endif

// The GPIO Pin used to monitor VSYS. Typically you would use this with ADC.
// There is an example in adc/read_vsys in pico-examples.
#ifndef PICO_VSYS_PIN
#define PICO_VSYS_PIN 29
#endif

#endif
65 changes: 41 additions & 24 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
*/

#define PCB_MAJOR_VERSION 0
#define PCB_MINOR_VERSION 3
#define PCB_MINOR_VERSION 4

#define GPIO_CD0 14
#define GPIO_CSR tmsRead_CSR_PIN // defined in tms9918.pio
Expand Down Expand Up @@ -105,7 +105,9 @@
#define TMS_IRQ PIO1_IRQ_0


/* file globals */


/* file globals */

static uint8_t nextValue = 0; /* TMS9918A read-ahead value */
static bool currentInt = false; /* current interrupt state */
Expand Down Expand Up @@ -191,7 +193,6 @@ static inline void disableTmsPioInterrupts()
__dmb();
}


/*
* generate a single VGA scanline (called by vgaLoop(), runs on proc1)
*/
Expand All @@ -211,6 +212,9 @@ static void __time_critical_func(tmsScanline)(uint16_t y, VgaParams* params, uin
const uint32_t vBorder = (VIRTUAL_PIXELS_Y - TMS9918_PIXELS_Y) / 2;
const uint32_t hBorder = (VIRTUAL_PIXELS_X - TMS9918_PIXELS_X * 2) / 2;

static int frameCount = 0;
static int logoOffset = 100;

uint16_t bg = tms9918PaletteBGR12[vrEmuTms9918RegValue(TMS_REG_FG_BG_COLOR) & 0x0f];

/*** top and bottom borders ***/
Expand All @@ -226,24 +230,37 @@ static void __time_critical_func(tmsScanline)(uint16_t y, VgaParams* params, uin
* : 430 bytes
* format: 16-bit abgr palette, 2bpp indexed image
*/
if (y >= vBorder + TMS9918_PIXELS_Y + 12)
if (frameCount < 600)
{
y -= vBorder + TMS9918_PIXELS_Y + 12;
if (y < splashHeight)
if (y == 0)
{
++frameCount;
if (frameCount & 0x01)
{
if (frameCount < 200 && logoOffset > 12) --logoOffset;
else if (frameCount > 500) ++logoOffset;
}
}

if (y < (VIRTUAL_PIXELS_Y - 1))
{
uint8_t* splashPtr = splash + (y * splashWidth / 4);
for (int x = 4; x < 4 + splashWidth; x += 4)
y -= vBorder + TMS9918_PIXELS_Y + logoOffset;
if (y < splashHeight)
{
uint8_t c = *(splashPtr++);
uint8_t p0 = (c & 0xc0);
uint8_t p1 = (c & 0x30);
uint8_t p2 = (c & 0x0c);
uint8_t p3 = (c & 0x03);

if (p0) { pixels[x] = splash_pal[(p0 >> 6)]; }
if (p1) { pixels[x + 1] = splash_pal[(p1 >> 4)]; }
if (p2) { pixels[x + 2] = splash_pal[(p2 >> 2)]; }
if (p3) { pixels[x + 3] = splash_pal[p3]; }
uint8_t* splashPtr = splash + (y * splashWidth / 4);
for (int x = 4; x < 4 + splashWidth; x += 4)
{
uint8_t c = *(splashPtr++);
uint8_t p0 = (c & 0xc0);
uint8_t p1 = (c & 0x30);
uint8_t p2 = (c & 0x0c);
uint8_t p3 = (c & 0x03);

if (p0) { pixels[x] = splash_pal[(p0 >> 6)]; }
if (p1) { pixels[x + 1] = splash_pal[(p1 >> 4)]; }
if (p2) { pixels[x + 2] = splash_pal[(p2 >> 2)]; }
if (p3) { pixels[x + 3] = splash_pal[p3]; }
}
}
}
}
Expand Down Expand Up @@ -348,6 +365,9 @@ uint initClock(uint gpio, float freqHz)
*/
void tmsPioInit()
{
irq_set_exclusive_handler(TMS_IRQ, pio_irq_handler);
irq_set_enabled(TMS_IRQ, true);

uint tmsWriteProgram = pio_add_program(TMS_PIO, &tmsWrite_program);

pio_sm_config writeConfig = tmsWrite_program_get_default_config(tmsWriteProgram);
Expand All @@ -357,6 +377,7 @@ void tmsPioInit()

pio_sm_init(TMS_PIO, tmsWriteSm, tmsWriteProgram, &writeConfig);
pio_sm_set_enabled(TMS_PIO, tmsWriteSm, true);
pio_set_irq0_source_enabled(TMS_PIO, pis_sm0_rx_fifo_not_empty, true);

uint tmsReadProgram = pio_add_program(TMS_PIO, &tmsRead_program);

Expand All @@ -375,9 +396,6 @@ void tmsPioInit()

pio_sm_init(TMS_PIO, tmsReadSm, tmsReadProgram, &readConfig);
pio_sm_set_enabled(TMS_PIO, tmsReadSm, true);
irq_set_exclusive_handler(TMS_IRQ, pio_irq_handler);
irq_set_enabled(TMS_IRQ, true);
pio_set_irq0_source_enabled(TMS_PIO, pis_sm0_rx_fifo_not_empty, true);
pio_set_irq0_source_enabled(TMS_PIO, pis_sm1_rx_fifo_not_empty, true);

pio_sm_put(TMS_PIO, tmsReadSm, 0x000000ff);
Expand Down Expand Up @@ -406,7 +424,6 @@ void proc1Entry()
}



/*
* main entry point
*/
Expand Down Expand Up @@ -438,10 +455,10 @@ int main(void)
vgaInit(params);

/* signal proc1 that we're ready to start the display */
multicore_fifo_push_timeout_us(0, 0);
multicore_fifo_push_blocking(0);

/* twiddle our thumbs - everything from this point on
is handled by interrupts and PIOs */
is handled by interrupts and PIOs */;
while (1)
{
tight_loop_contents();
Expand Down
Binary file modified src/res/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion submodules/vrEmuTms9918
18 changes: 3 additions & 15 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
set(PROGRAM pico9918test)
cmake_minimum_required(VERSION 3.12)

add_executable(${PROGRAM})

# generate image array source files from png images
visrealm_generate_bindata_source(${PROGRAM} breakout res/BREAKOUT.* )

pico_generate_pio_header(${PROGRAM} ${CMAKE_CURRENT_LIST_DIR}/clocks.pio)

target_sources(${PROGRAM} PRIVATE test.c font.c)

pico_add_extra_outputs(${PROGRAM})

target_link_libraries(${PROGRAM} PUBLIC
pico_stdlib
hardware_pio)
add_subdirectory(host)
#add_subdirectory(qc)

17 changes: 17 additions & 0 deletions test/host/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set(PROGRAM pico9918test)

add_executable(${PROGRAM})

# generate image array source files from png images
visrealm_generate_bindata_source(${PROGRAM} breakout res/BREAKOUT.* )

pico_generate_pio_header(${PROGRAM} ${CMAKE_CURRENT_LIST_DIR}/clocks.pio)

target_sources(${PROGRAM} PRIVATE test.c font.c)

pico_add_extra_outputs(${PROGRAM})

target_link_libraries(${PROGRAM} PUBLIC
pico_stdlib
hardware_pio)

70 changes: 35 additions & 35 deletions test/clocks.pio → test/host/clocks.pio
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
/*
* Project: pico9918
*
* Copyright (c) 2024 Troy Schrapel
*
* This code is licensed under the MIT license
*
* https://github.com/visrealm/pico9918
*
*/
.program clock
pull block
.wrap_target
set pins, 1
mov x, osr
onDelay:
jmp x-- onDelay
set pins, 0
mov x, osr
offDelay:
jmp x-- offDelay
.wrap
% c-sdk {
void clock_program_init(PIO pio, uint sm, uint offset, uint pin) {
pio_gpio_init(pio, pin);
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
pio_sm_config c = clock_program_get_default_config(offset);
sm_config_set_set_pins(&c, pin, 1);
pio_sm_init(pio, sm, offset, &c);
}
%}
/*
* Project: pico9918
*
* Copyright (c) 2024 Troy Schrapel
*
* This code is licensed under the MIT license
*
* https://github.com/visrealm/pico9918
*
*/

.program clock
pull block
.wrap_target
set pins, 1
mov x, osr
onDelay:
jmp x-- onDelay
set pins, 0
mov x, osr
offDelay:
jmp x-- offDelay
.wrap


% c-sdk {

void clock_program_init(PIO pio, uint sm, uint offset, uint pin) {
pio_gpio_init(pio, pin);
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
pio_sm_config c = clock_program_get_default_config(offset);
sm_config_set_set_pins(&c, pin, 1);
pio_sm_init(pio, sm, offset, &c);
}
%}
Loading

0 comments on commit dc73003

Please sign in to comment.