Skip to content

Commit aae034f

Browse files
committed
Conditional compile for scart RGBs NTSC/PAL vs VGA
1 parent c55f045 commit aae034f

File tree

3 files changed

+49
-52
lines changed

3 files changed

+49
-52
lines changed

src/CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,19 @@ execute_process(
2525
OUTPUT_STRIP_TRAILING_WHITESPACE
2626
)
2727

28+
if (${PICO9918_SCART_RGBS})
29+
if (${PICO9918_SCART_PAL})
30+
set(PICO9918_OUTPUT_STR "rgbs-pal576i")
31+
else()
32+
set(PICO9918_OUTPUT_STR "rgbs-ntsc480i")
33+
endif()
34+
else()
35+
set(PICO9918_OUTPUT_STR "vga")
36+
endif()
37+
2838
string(REPLACE "." "-" PICO9918_VERSION_STR "${PICO9918_VERSION}")
2939

30-
set(PICO9918_BINARY_SUFFIX -pcb-v${PICO9918_PCB_MAJOR_VER}-${PICO9918_PCB_MINOR_VER}-${PICO9918_GIT_BRANCH}-build-${PICO9918_VERSION_STR})
40+
set(PICO9918_BINARY_SUFFIX -pcb-v${PICO9918_PCB_MAJOR_VER}-${PICO9918_PCB_MINOR_VER}-${PICO9918_OUTPUT_STR}-build-${PICO9918_VERSION_STR})
3141

3242
if (${PICO9918_SCANLINES})
3343
set(PICO9918_BINARY_SUFFIX ${PICO9918_BINARY_SUFFIX}-sl)
@@ -59,12 +69,14 @@ pico_add_extra_outputs(${PROGRAM})
5969
pico_enable_stdio_usb(${PROGRAM} 0)
6070
pico_enable_stdio_uart(${PROGRAM} 0)
6171

62-
pico_set_binary_type(${PROGRAM} copy_to_ram) # TOO SLOW TO BOOT
72+
pico_set_binary_type(${PROGRAM} copy_to_ram)
6373

6474
add_definitions(-DPICO9918_VERSION="${PICO9918_VERSION}")
6575
add_definitions(-DPICO9918_PCB_MAJOR_VER=${PICO9918_PCB_MAJOR_VER})
6676
add_definitions(-DPICO9918_PCB_MINOR_VER=${PICO9918_PCB_MINOR_VER})
6777
add_definitions(-DPICO9918_SCANLINES=${PICO9918_SCANLINES})
78+
add_definitions(-DPICO9918_SCART_RGBS=${PICO9918_SCART_RGBS})
79+
add_definitions(-DPICO9918_SCART_PAL=${PICO9918_SCART_PAL})
6880

6981
add_definitions(-DPICO_DISABLE_SHARED_IRQ_HANDLERS=1)
7082
#add_definitions(-DPICO_TIME_DEFAULT_ALARM_POOL_DISABLED=1)

src/main.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
* https://www.aliexpress.com/item/1005007066733934.html
6464
*/
6565

66-
#define PCB_MAJOR_VERSION 0
67-
#define PCB_MINOR_VERSION 3
66+
#define PCB_MAJOR_VERSION PICO9918_PCB_MAJOR_VER
67+
#define PCB_MINOR_VERSION PICO9918_PCB_MINOR_VER
6868

6969
#define GPIO_CD7 14
7070
#define GPIO_CSR tmsRead_CSR_PIN // defined in tms9918.pio
@@ -97,13 +97,15 @@
9797

9898
#define TMS_CRYSTAL_FREQ_HZ 10738635.0f
9999

100-
//#define PICO_CLOCK_PLL 1260000000
101-
//#define PICO_CLOCK_PLL_DIV1 5
102-
//#define PICO_CLOCK_PLL_DIV2 1
103-
104-
#define PICO_CLOCK_PLL 1536000000
105-
#define PICO_CLOCK_PLL_DIV1 3
106-
#define PICO_CLOCK_PLL_DIV2 2
100+
#if PICO9918_SCART_RGBS // for 15kHz
101+
#define PICO_CLOCK_PLL 1536000000
102+
#define PICO_CLOCK_PLL_DIV1 3
103+
#define PICO_CLOCK_PLL_DIV2 2
104+
#else // for 31.46875 kHz
105+
#define PICO_CLOCK_PLL 1260000000
106+
#define PICO_CLOCK_PLL_DIV1 5
107+
#define PICO_CLOCK_PLL_DIV2 1
108+
#endif
107109

108110
#define PICO_CLOCK_HZ (PICO_CLOCK_PLL / PICO_CLOCK_PLL_DIV1 / PICO_CLOCK_PLL_DIV2)
109111

@@ -451,11 +453,19 @@ int main(void)
451453

452454
/* then set up VGA output */
453455
VgaInitParams params = { 0 };
454-
params.params = vgaGetParams(RGBS_NTSC_720_480i_60HZ);
455-
//params.params = vgaGetParams(VGA_640_480_60HZ);
456456

457-
/* virtual size will be 640 x 320 to accomodate 80-column mode */
458-
//setVgaParamsScaleY(&params.params, 2);
457+
#if PICO9918_SCART_RGBS
458+
#if PICO9918_SCART_PAL
459+
params.params = vgaGetParams(RGBS_PAL_720_576i_50HZ);
460+
#else
461+
params.params = vgaGetParams(RGBS_NTSC_720_480i_60HZ);
462+
#endif
463+
#else // VGA
464+
params.params = vgaGetParams(VGA_640_480_60HZ);
465+
466+
/* virtual size will be 640 x 240 to accomodate 80-column mode */
467+
setVgaParamsScaleY(&params.params, 2);
468+
#endif
459469

460470
/* set vga scanline callback to generate tms9918 scanlines */
461471
params.scanlineFn = tmsScanline;

src/vga/vga.c

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222

2323
// compile options
2424
#define VGA_CRT_EFFECT PICO9918_SCANLINES
25-
#define VGA_SCANLINE_TIME_DEBUG 0
26-
#define VGA_HARDCODED_640 0
27-
#define VGA_NO_MALLOC 1
28-
#define VGA_COMBINE_SYNC 1
25+
#define VGA_HARDCODED_640 !PICO9918_SCART_RGBS
26+
#define VGA_COMBINE_SYNC PICO9918_SCART_RGBS
2927

28+
#define VGA_NO_MALLOC 1
3029

3130
// a number of compiile-time optimisations can occur
3231
// if it knows some of the VGA parameters
@@ -61,10 +60,16 @@ int roundflt(float x)
6160
#define RGB_SM 1 // vga rgb state machine index
6261

6362
#define END_OF_SCANLINE_MSG 0x40000000
64-
#define END_OF_FRAME_MSG 0x80000000
63+
#define END_OF_FRAME_MSG 0x80000000
6564

65+
#if VGA_COMBINE_SYNC
66+
bi_decl(bi_1pin_with_name(SYNC_PINS_START, "C Sync"));
67+
bi_decl(bi_1pin_with_name(SYNC_PINS_START + 1, "C Sync"));
68+
#else
6669
bi_decl(bi_1pin_with_name(SYNC_PINS_START, "H Sync"));
6770
bi_decl(bi_1pin_with_name(SYNC_PINS_START + 1, "V Sync"));
71+
#endif
72+
6873
bi_decl(bi_pin_mask_with_names(0xf << RGB_PINS_START, "Red (LSB - MSB)"));
6974
bi_decl(bi_pin_mask_with_names(0xf << RGB_PINS_START + 4, "Green (LSB - MSB)"));
7075
bi_decl(bi_pin_mask_with_names(0xf << RGB_PINS_START + 8, "Blue (LSB - MSB)"));
@@ -77,10 +82,10 @@ uint32_t __aligned(4) syncDataPorch[4]; // vertical porch
7782
uint32_t __aligned(4) syncDataSync[4]; // vertical sync
7883

7984
#if VGA_NO_MALLOC
80-
uint16_t __aligned(4) rgbDataBuffer[2 + VGA_SCANLINE_TIME_DEBUG][640 * sizeof(uint16_t)] = { 0 }; // two scanline buffers (odd and even)
85+
uint16_t __aligned(4) rgbDataBuffer[2][640 * sizeof(uint16_t)] = { 0 }; // two scanline buffers (odd and even)
8186
#else
8287
#include <stdlib.h>
83-
uint16_t* __aligned(4) rgbDataBuffer[2 + VGA_SCANLINE_TIME_DEBUG] = { 0 }; // two scanline buffers (odd and even)
88+
uint16_t* __aligned(4) rgbDataBuffer[2] = { 0 }; // two scanline buffers (odd and even)
8489
#endif
8590

8691

@@ -93,11 +98,6 @@ static uint syncDmaChanMask = 0;
9398
static uint rgbDmaChanMask = 0;
9499
static VgaInitParams vgaParams = { 0 };
95100

96-
#if VGA_SCANLINE_TIME_DEBUG
97-
bool hasRenderedNext = false;
98-
#endif
99-
100-
101101
uint32_t vgaMinimumPioClockKHz(VgaParams* params)
102102
{
103103
if (params)
@@ -130,15 +130,6 @@ static bool buildSyncData()
130130
rgbDataBuffer[1] = malloc(VIRTUAL_PIXELS_X * sizeof(uint16_t));
131131
#endif
132132

133-
#if VGA_SCANLINE_TIME_DEBUG
134-
#if !VGA_NO_MALLOC
135-
rgbDataBuffer[2] = malloc(VIRTUAL_PIXELS_X * sizeof(uint16_t));
136-
#endif
137-
138-
for (int i = 0; i < VIRTUAL_PIXELS_X; ++i)
139-
rgbDataBuffer[2][i] = 0x0f00;
140-
#endif
141-
142133
vgaParams.params.pioDivider = roundflt(sysClockKHz / (float)minClockKHz);
143134
vgaParams.params.pioFreqKHz = sysClockKHz / vgaParams.params.pioDivider;
144135

@@ -361,15 +352,6 @@ static void __isr __time_critical_func(dmaIrqHandler)(void)
361352
}
362353
#endif
363354

364-
#if VGA_SCANLINE_TIME_DEBUG
365-
// apply a few darkened values before passing to dma
366-
if (pxLineRpt != 0 && hasRenderedNext)
367-
{
368-
currentBuffer = (uint32_t*)rgbDataBuffer[2];
369-
}
370-
#endif
371-
372-
373355
dma_channel_set_read_addr(rgbDmaChan, currentBuffer, true);
374356

375357
// need a new line every X display lines
@@ -380,9 +362,6 @@ static void __isr __time_critical_func(dmaIrqHandler)(void)
380362

381363
multicore_fifo_push_timeout_us(requestLine, 0);
382364

383-
#if VGA_SCANLINE_TIME_DEBUG
384-
hasRenderedNext = false;
385-
#endif
386365
if (requestLine == VIRTUAL_PIXELS_Y - 1)
387366
{
388367
multicore_fifo_push_timeout_us(END_OF_FRAME_MSG, 0);
@@ -449,10 +428,6 @@ void __time_critical_func(vgaLoop)()
449428
{
450429
// get the next scanline pixels
451430
vgaParams.scanlineFn(message & 0xfff, &vgaParams.params, rgbDataBuffer[message & 0x01]);
452-
#if VGA_SCANLINE_TIME_DEBUG
453-
dma_channel_set_read_addr(rgbDmaChan, rgbDataBuffer[2], true);
454-
hasRenderedNext = true;
455-
#endif
456431
}
457432
}
458433
}

0 commit comments

Comments
 (0)