diff --git a/examples/hucc/sgx_vdc_example/Makefile b/examples/hucc/sgx_vdc_example/Makefile new file mode 100644 index 00000000..01b80daa --- /dev/null +++ b/examples/hucc/sgx_vdc_example/Makefile @@ -0,0 +1,15 @@ +all: sgx_vdc_scroll.sgx sgx_vdc_scroll.iso + +include ../Make_ex.inc + +SRC = sgx_vdc_scroll.c + +CFLAGS ?= -O2 --sgx -fno-recursive -gA +CDFLAGS = --scd +LIBS = + +sgx_vdc_scroll.iso: $(SRC) + $(CC) $(CFLAGS) $(CDFLAGS) $< $(LIBS) + +sgx_vdc_scroll.sgx: $(SRC) sgx_vdc_scroll.iso + $(CC) $(CFLAGS) $< $(LIBS) diff --git a/examples/hucc/sgx_vdc_example/b.bmp b/examples/hucc/sgx_vdc_example/b.bmp new file mode 100644 index 00000000..62e4e0c8 Binary files /dev/null and b/examples/hucc/sgx_vdc_example/b.bmp differ diff --git a/examples/hucc/sgx_vdc_example/f.bmp b/examples/hucc/sgx_vdc_example/f.bmp new file mode 100644 index 00000000..694c87d5 Binary files /dev/null and b/examples/hucc/sgx_vdc_example/f.bmp differ diff --git a/examples/hucc/sgx_vdc_example/make.cmd b/examples/hucc/sgx_vdc_example/make.cmd new file mode 100644 index 00000000..aaaa2510 --- /dev/null +++ b/examples/hucc/sgx_vdc_example/make.cmd @@ -0,0 +1,70 @@ +@rem ************************************************************************ +@rem ************************************************************************ +@rem +@rem make.cmd +@rem +@rem Build a project with a native Windows version of Linux and macOS "make". +@rem +@rem Copyright John Brandwood 2025. +@rem +@rem Distributed under the Boost Software License, Version 1.0. +@rem (See accompanying file LICENSE_1_0.txt or copy at +@rem http://www.boost.org/LICENSE_1_0.txt) +@rem +@rem ************************************************************************ +@rem ************************************************************************ +@rem +@rem Put this in your project's directory on Windows to automatically set the +@rem PATH and PCE_INCLUDE environment variables if your project is located in +@rem a directory within the main HuC folder tree. +@rem +@rem Then mingw32-make.exe is run to build the project using its Makefile. +@rem +@rem You can run this from a Windows "Command Prompt", or by navigating to it +@rem in Windows Explorer and then double-clicking on the file. +@rem +@rem ************************************************************************ +@rem ************************************************************************ + +@echo off + +setlocal + +call :findexe hucc.exe +if not [%EXEFILE%] == [""] goto :gotpath + +cd /d "%~dp0" +set rootdir="%~d0\" +:search +if not exist "%CD%\bin" goto :next +if not exist "%CD%\bin\hucc.exe" goto :next +set PATH=%CD%\bin;%PATH% +set PCE_INCLUDE=%CD%\include\hucc +goto :gotpath +:next +if not ["%CD%"] == [%rootdir%] ( + cd .. + goto :search +) +echo. +echo Unable to locate hucc.exe, please set up your PATH and PCE_INCLUDE +echo environment variables! +if /i "%comspec% /c %~0 " equ "%cmdcmdline:"=%" ( + echo. + pause +) +exit /b 1 + +:findexe +set EXEFILE="%~$PATH:1" +goto :eof + +:gotpath +cd /d "%~dp0" +mingw32-make.exe %* + +rem Pause if this was run by doubleclicking on the file in Explorer. +if /i "%comspec% /c %~0 " equ "%cmdcmdline:"=%" ( + echo. + pause +) diff --git a/examples/hucc/sgx_vdc_example/sgx_vdc_scroll.c b/examples/hucc/sgx_vdc_example/sgx_vdc_scroll.c new file mode 100644 index 00000000..94095716 --- /dev/null +++ b/examples/hucc/sgx_vdc_example/sgx_vdc_scroll.c @@ -0,0 +1,163 @@ +#include +#include + +/* + * DISPLAY CONTROL MACROS + * ------------------------ + * These macros directly control the PC Engine (PCE) and SuperGrafx (SGX) displays + * by setting or clearing bits in their respective VDC control registers. + * They are implemented using inline assembly. + */ +void __fastcall __macro pce_disp_on(void); +void __fastcall __macro pce_disp_off(void); +void __fastcall __macro sgx_disp_on(void); +void __fastcall __macro sgx_disp_off(void); + +#asm + .macro _pce_disp_on + lda #$C0 + tsb > 3; /* Divide by 8 to remove the fractional part */ + temp_y = scroll_y >> 3; + j_x = (unsigned char)temp_x; + j_y = (unsigned char)temp_y; + + /* + * APPLY SCROLLING: + * - sgx_scroll_split() scrolls the SuperGrafx background layer. + * - scroll_split() scrolls the PC Engine layer, with a negative X offset for a parallax effect. + */ + /* Background layer */ + sgx_scroll_split(0, 0, j_x, j_y, sgx_on ? 0xC0 : 0x00); + /* Foreground layer */ + scroll_split(0, 0, -j_x, -j_y, pce_on ? 0xC0 : 0x00); + + /* HANDLE INPUT: Toggle display outputs when joystick buttons are pressed */ + joyt = joytrg(0); + if (joyt & JOY_I) + { + pce_on = !pce_on; /* Toggle PCE display flag */ + if (pce_on) + pce_disp_on(); + else + pce_disp_off(); + } + if (joyt & JOY_II) + { + sgx_on = !sgx_on; /* Toggle SGX display flag */ + if (sgx_on) + sgx_disp_on(); + else + sgx_disp_off(); + } + } + } +} diff --git a/examples/hucc/sgx_vdc_example/sgx_vdc_scroll.cue b/examples/hucc/sgx_vdc_example/sgx_vdc_scroll.cue new file mode 100644 index 00000000..9e4c18ef --- /dev/null +++ b/examples/hucc/sgx_vdc_example/sgx_vdc_scroll.cue @@ -0,0 +1,3 @@ +FILE sgx_vdc_scroll.iso BINARY + TRACK 01 MODE1/2048 + INDEX 01 00:00:00