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

Fix nasty HuCC compiler bug when __fastcall function calls are split over multiple lines. #79

Merged
merged 2 commits into from
Mar 2, 2025
Merged
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
2 changes: 1 addition & 1 deletion examples/hucc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Makefile for examples
#

SUBDIRS = sgx shmup
SUBDIRS = scroll sgx shmup

all clean:
@$(MAKE) $(SUBDIRS) "COMMAND=$@"
Expand Down
10 changes: 10 additions & 0 deletions examples/hucc/scroll/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
all: scroll.pce

include ../Make_ex.inc

SRC = scroll.c

CFLAGS ?= -v -O2 -fno-recursive -gC

scroll.pce: $(SRC)
$(CC) $(CFLAGS) $(SRC) $(LIBS)
70 changes: 70 additions & 0 deletions examples/hucc/scroll/make.cmd
Original file line number Diff line number Diff line change
@@ -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
)
229 changes: 229 additions & 0 deletions examples/hucc/scroll/scroll.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
/*
* file: scroll.c
* description: a three-screen horizontal scrolling demo
* author: David Michel ([email protected])
* date: 2000.08.16
* files: scroll.pcx
* version: 1.0
*/

#include "huc.h"
#include "hucc-scroll.h"

#define TRUE 1
#define FALSE 0

/* vram allocation */
#define TILE_VRAM 0x1000
#define PANEL_VRAM 0x2000
#define SPRITE_VRAM 0x4000

/* palette allocation */
#define TILE_PAL 0
#define PANEL_PAL 2
#define SPRITE_PAL 16

/* tiles */
#inctile(tile_gfx, "scroll.pcx", 4, 3)
#incpal(tile_pal, "scroll.pcx", 0)

/* sprites */
#incspr(sprite, "scroll.pcx", 64, 0, 2, 1)
#incpal(sprite_pal, "scroll.pcx", 1)

/* control panel */
#incchr(panel_gfx, "scroll.pcx", 0, 48, 32, 4)
#incpal(panel_pal, "scroll.pcx", 2)
#incbat(panel_bat, "scroll.pcx", PANEL_VRAM, 0, 48, 32, 4)

/* define the demo map
*
* (should be #incbin'ed if the map is big
* or uses more than a dozen of tiles)
*/
#define MAP_WIDTH 48
#define MAP_HE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,2,1,1,1,1,1,0,3,3,3,3,3,0, 1,1,1,1,1,1,1,1,1,0,3,3,3,3,3,3, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,1,
1,1,1,1,1,1,1,1,1,0,3,3,3,3,3,0, 1,1,1,1,1,1,1,1,1,0,3,3,3,3,3,3, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,1
};

/* palette index for tiles (one index per tile) */
const char tile_pal_ref[NB_TILE] = {
TILE_PAL<<4, TILE_PAL<<4, TILE_PAL<<4, TILE_PAL<<4,
TILE_PAL<<4, TILE_PAL<<4, TILE_PAL<<4, TILE_PAL<<4,
TILE_PAL<<4, TILE_PAL<<4, TILE_PAL<<4, TILE_PAL<<4
};

/* scroll vars */
int tx;
int sx, sy;
int map_x;
int dir;

pause()
{
/* show 'paused' sprite */
spr_set(0);
spr_pal(SPRITE_PAL);
spr_pattern(SPRITE_VRAM);
spr_ctrl(SIZE_MAS|FLIP_MAS, SZ_32x16|NO_FLIP);
spr_pri(1);
spr_x(112);
spr_y(88);
satb_update();

/* wait that the user press START again */
do {
vsync();
} while (!(joytrg(0) & JOY_STRT));

/* hide sprite */
spr_hide();
satb_update();
}

main()
{
int flag;
int score;

/* disable display */
disp_off();

/* clear display */
cls();

/* init sprite */
load_sprites(SPRITE_VRAM, sprite, 1);
load_palette(SPRITE_PAL, sprite_pal, 1);

/* init map */
set_map_data(demo_map, MAP_WIDTH, MAP_HEIGHT);
set_tile_data(tile_gfx, NB_TILE, tile_pal_ref, 16);
load_tile(TILE_VRAM);
load_palette(TILE_PAL, tile_pal, 1);
load_map(0, 0, 0, 0, 17, 12);

/* init font */
set_font_color(1, 10);
set_font_pal(PANEL_PAL);
load_default_font();

/* init control panel */
load_vram(PANEL_VRAM, panel_gfx, 2048);
load_bat(0x600, panel_bat, 32, 4);
load_palette(PANEL_PAL, panel_pal, 1);
put_string("score: ", 1, 25);

/* split screen */
scroll_split(0, 0, 0, 0, BKG_ON | SPR_ON);
scroll_split(1, 192, 0, 192, BKG_ON);

/* enable display */
disp_on();

/* init scroll */
sx = 0;
tx = 0;
dir = 1;
map_x = 0;
score = 0;

/* demo main loop */
for (;;)
{
/* check if we should pause */
if (joytrg(0) & JOY_STRT) {
pause();
}

/* get move direction */
if (joy(0) & JOY_LEFT) {
dir = -1;
flag = TRUE;
}
else
if (joy(0) & JOY_RGHT) {
dir = 1;
flag = TRUE;
}
else {
flag = FALSE;
}

/* calculate the new scroll position */
if (flag == TRUE)
tx = sx + (dir << 1);
else
tx = sx + (dir);

/* compare the old and new screen position
* (on a tile basis), and update the screen map
* if they are different
*/
if((tx & 0xFFF0) != (sx & 0xFFF0)) {
/* right dir */
if (dir == 1) {
map_x = map_x + 1;

if (map_x > MAP_WIDTH)
map_x -= MAP_WIDTH;

load_map(
(tx + 256) >> 4, /* screen x coordinate (in tile unit) */
0, /* screen y */
map_x + 16, /* map x */
0, /* map y */
1, /* nb of map column to load */
12); /* nb of row */
}

/* left dir */
else {
map_x = map_x - 1;

if (map_x < 0)
map_x += MAP_WIDTH;

load_map(
(tx) >> 4, /* screen x coordinate */
0, /* screen y */
map_x, /* map x */
0, /* map y */
1, /* nb of map column to load */
12); /* nb of row */
}
score += 1;
}

/* earthquake :) */
if (!(joy(0) & (JOY_A | JOY_B)))
sy = 0;
else {
sy = rand() & 0x07;
score += sy;
}

/* display score */
put_number(score, 5, 8, 25);

/* set new scroll position */
sx = tx;
scroll_split(0, 0, sx, sy, BKG_ON | SPR_ON);
vsync();
}
}

Binary file added examples/hucc/scroll/scroll.pcx
Binary file not shown.
Loading