From c287f9bcb9a14f7e1ec883cadaf3ee3185efb815 Mon Sep 17 00:00:00 2001 From: Wei-ju Wu Date: Mon, 19 Sep 2016 20:49:56 -0700 Subject: [PATCH] added sprites file, restructured startup file --- hardware/.gitignore | 1 + hardware/Makefile | 7 ++- hardware/sprites.c | 149 ++++++++++++++++++++++++++++++++++++++++++++ hardware/startup.c | 40 ++++++++---- 4 files changed, 182 insertions(+), 15 deletions(-) create mode 100644 hardware/sprites.c diff --git a/hardware/.gitignore b/hardware/.gitignore index efcfc5a..76eec39 100644 --- a/hardware/.gitignore +++ b/hardware/.gitignore @@ -1 +1,2 @@ startup +sprites diff --git a/hardware/Makefile b/hardware/Makefile index 314c511..ad82673 100644 --- a/hardware/Makefile +++ b/hardware/Makefile @@ -1,10 +1,13 @@ CC=vc +kick13 CFLAGS=-c99 -I$(NDK_INC) -DDEBUG -O2 -all: startup +all: startup sprites clean: - rm -f *.o startup + rm -f *.o startup sprites startup: startup.o $(CC) $(CFLAGS) $^ -lamiga -lauto -o $@ + +sprites: sprites.o + $(CC) $(CFLAGS) $^ -lamiga -lauto -o $@ diff --git a/hardware/sprites.c b/hardware/sprites.c new file mode 100644 index 0000000..18ff4d8 --- /dev/null +++ b/hardware/sprites.c @@ -0,0 +1,149 @@ +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/* + * A simple setup to display a sprite. + */ +extern struct Custom custom; +extern struct CIA ciaa, ciab; +extern struct Library *GfxBase; + +// VBCC Inline assembly +void waitmouse(void) = "waitmouse:\n\tbtst\t#6,$bfe001\n\tbne\twaitmouse"; + +#define EXEC_BASE (4L) +#define TASK_PRIORITY 127 +#define VFREQ_PAL 50 +#define WB_SCREEN_NAME "Workbench" + +#define BPLCON0 0x100 +#define COLOR00 0x180 +#define SPR0PTH 0x120 +#define SPR0PTL 0x122 + +#define BPLCON0_COLOR (1 << 9) + +#define COP_MOVE(addr, data) addr, data +#define COP_WAIT_END 0xffff, 0xfffe + +static UWORD __chip coplist_pal[] = { + COP_MOVE(SPR0PTH, 0x0000), + COP_MOVE(SPR0PTL, 0x0000), + COP_WAIT_END, + COP_WAIT_END +}; +static UWORD __chip coplist_ntsc[] = { + COP_MOVE(SPR0PTL, 0x0000), + COP_MOVE(SPR0PTH, 0x0000), + COP_WAIT_END, + COP_WAIT_END +}; + +// space ship data from the Hardware Reference Manual +static UWORD __chip spdat0[] = { + 0x6d60, 0x7200, // VSTART+HSTART, VSTOP + // data here + 0x0990, 0x07e0, + 0x13c8, 0x0ff0, + 0x23c4, 0x1ff8, + 0x13c8, 0x0ff0, + 0x0990, 0x07e0, + 0x0000, 0x0000 +}; + + +static struct Screen *wbscreen; +static ULONG oldresolution; + +static void ApplySpriteFix(void) +{ + if (wbscreen = LockPubScreen(WB_SCREEN_NAME)) { + struct TagItem video_control_tags[] = { + {VTAG_SPRITERESN_GET, SPRITERESN_ECS}, + {TAG_DONE, 0} + }; + struct TagItem video_control_tags2[] = { + {VTAG_SPRITERESN_SET, SPRITERESN_140NS}, + {TAG_DONE, 0} + }; + VideoControl(wbscreen->ViewPort.ColorMap, video_control_tags); + oldresolution = video_control_tags[0].ti_Data; + VideoControl(wbscreen->ViewPort.ColorMap, video_control_tags2); + MakeScreen(wbscreen); + RethinkDisplay(); + } +} + +static void UnapplySpriteFix(void) +{ + if (wbscreen) { + struct TagItem video_control_tags[] = { + {VTAG_SPRITERESN_SET, oldresolution}, + {TAG_DONE, 0} + }; + VideoControl(wbscreen->ViewPort.ColorMap, video_control_tags); + MakeScreen(wbscreen); + UnlockPubScreen(NULL, wbscreen); + } +} + +static BOOL init_display(UWORD lib_version) +{ + BOOL is_pal; + + LoadView(NULL); // clear display, reset hardware registers + WaitTOF(); // 2 WaitTOFs to wait for 1. long frame and + WaitTOF(); // 2. short frame copper lists to finish (if interlaced) + + // Kickstart > 3.0: fix sprite bug + if (lib_version >= 39) { + ApplySpriteFix(); + is_pal = (((struct GfxBase *) GfxBase)->DisplayFlags & PAL) == PAL; + } else { + // Note: FS-UAE reports 0 this, so essentially, there is no information + // for 1.x + printf("PAL/NTSC: %d\n", (int) ((struct ExecBase *) EXEC_BASE)->VBlankFrequency); + is_pal = ((struct ExecBase *) EXEC_BASE)->VBlankFrequency == VFREQ_PAL; + } + custom.cop1lc = is_pal ? (ULONG) coplist_pal : (ULONG) coplist_ntsc; + return is_pal; +} + +static void reset_display(struct View *current_view, UWORD lib_version) +{ + if (lib_version >= 39) UnapplySpriteFix(); + LoadView(current_view); + WaitTOF(); + WaitTOF(); + custom.cop1lc = (ULONG) ((struct GfxBase *) GfxBase)->copinit; + RethinkDisplay(); +} + +int main(int argc, char **argv) +{ + // translated startup.asm + struct Task *current_task = FindTask(NULL); + BYTE old_prio = SetTaskPri(current_task, TASK_PRIORITY); + struct View *current_view = ((struct GfxBase *) GfxBase)->ActiView; + UWORD lib_version = ((struct Library *) GfxBase)->lib_Version; + + coplist_ntsc[1] = ((ULONG) spdat0) & 0xffff; + coplist_ntsc[3] = (((ULONG) spdat0) >> 16) & 0xffff; + coplist_pal[1] = ((ULONG) spdat0) & 0xffff; + coplist_pal[3] = (((ULONG) spdat0) >> 16) & 0xffff; + + init_display(lib_version); + + waitmouse(); + + reset_display(current_view, lib_version); + return 0; +} diff --git a/hardware/startup.c b/hardware/startup.c index de7956a..0cce711 100644 --- a/hardware/startup.c +++ b/hardware/startup.c @@ -23,7 +23,7 @@ extern struct CIA ciaa, ciab; extern struct Library *GfxBase; // VBCC Inline assembly -void waitmouse() = "waitmouse:\n\tbtst\t#6,$bfe001\n\tbne\twaitmouse"; +void waitmouse(void) = "waitmouse:\n\tbtst\t#6,$bfe001\n\tbne\twaitmouse"; #define EXEC_BASE (4L) #define TASK_PRIORITY 127 @@ -62,7 +62,7 @@ static UWORD __chip coplist_ntsc[] = { static struct Screen *wbscreen; static ULONG oldresolution; -static void ApplySpriteFix() +static void ApplySpriteFix(void) { if (wbscreen = LockPubScreen(WB_SCREEN_NAME)) { struct TagItem video_control_tags[] = { @@ -80,7 +80,8 @@ static void ApplySpriteFix() RethinkDisplay(); } } -static void UnapplySpriteFix() + +static void UnapplySpriteFix(void) { if (wbscreen) { struct TagItem video_control_tags[] = { @@ -93,18 +94,13 @@ static void UnapplySpriteFix() } } -int main(int argc, char **argv) +static BOOL init_display(UWORD lib_version) { - // translated startup.asm - struct Task *current_task = FindTask(NULL); - BYTE old_prio = SetTaskPri(current_task, TASK_PRIORITY); - struct View *current_view = ((struct GfxBase *) GfxBase)->ActiView; - UWORD lib_version = ((struct Library *) GfxBase)->lib_Version; BOOL is_pal; - LoadView(NULL); - WaitTOF(); - WaitTOF(); + LoadView(NULL); // clear display, reset hardware registers + WaitTOF(); // 2 WaitTOFs to wait for 1. long frame and + WaitTOF(); // 2. short frame copper lists to finish (if interlaced) // Kickstart > 3.0: fix sprite bug if (lib_version >= 39) { @@ -117,13 +113,31 @@ int main(int argc, char **argv) is_pal = ((struct ExecBase *) EXEC_BASE)->VBlankFrequency == VFREQ_PAL; } custom.cop1lc = is_pal ? (ULONG) coplist_pal : (ULONG) coplist_ntsc; + return is_pal; +} - waitmouse(); +static void reset_display(struct View *current_view, UWORD lib_version) +{ if (lib_version >= 39) UnapplySpriteFix(); LoadView(current_view); WaitTOF(); WaitTOF(); custom.cop1lc = (ULONG) ((struct GfxBase *) GfxBase)->copinit; RethinkDisplay(); +} + +int main(int argc, char **argv) +{ + // translated startup.asm + struct Task *current_task = FindTask(NULL); + BYTE old_prio = SetTaskPri(current_task, TASK_PRIORITY); + struct View *current_view = ((struct GfxBase *) GfxBase)->ActiView; + UWORD lib_version = ((struct Library *) GfxBase)->lib_Version; + + init_display(lib_version); + + waitmouse(); + + reset_display(current_view, lib_version); return 0; }