From b31f5a40aa173fb1fabe55247ae767c155761bb8 Mon Sep 17 00:00:00 2001 From: Wei-ju Wu Date: Wed, 21 Sep 2016 21:19:59 -0700 Subject: [PATCH] hardware: clean out main modules made the init_display() and reset_display() functions more indepenent from their callers --- hardware/common.c | 7 +++++-- hardware/common.h | 4 ++-- hardware/playfield1.c | 18 ++---------------- hardware/sprites.c | 12 ++---------- hardware/startup.c | 16 ++-------------- 5 files changed, 13 insertions(+), 44 deletions(-) diff --git a/hardware/common.c b/hardware/common.c index dd93709..111915f 100644 --- a/hardware/common.c +++ b/hardware/common.c @@ -46,8 +46,9 @@ static void UnapplySpriteFix(void) } } -BOOL init_display(UWORD lib_version) +BOOL init_display(void) { + UWORD lib_version = ((struct Library *) GfxBase)->lib_Version; BOOL is_pal; LoadView(NULL); // clear display, reset hardware registers @@ -67,8 +68,10 @@ BOOL init_display(UWORD lib_version) return is_pal; } -void reset_display(struct View *current_view, UWORD lib_version) +void reset_display(void) { + struct View *current_view = ((struct GfxBase *) GfxBase)->ActiView; + UWORD lib_version = ((struct Library *) GfxBase)->lib_Version; if (lib_version >= 39) UnapplySpriteFix(); LoadView(current_view); WaitTOF(); diff --git a/hardware/common.h b/hardware/common.h index 3a67fa6..9b17c8c 100644 --- a/hardware/common.h +++ b/hardware/common.h @@ -50,8 +50,8 @@ #define COP_MOVE(addr, data) addr, data #define COP_WAIT_END 0xffff, 0xfffe -extern BOOL init_display(UWORD lib_version); -extern void reset_display(struct View *current_view, UWORD lib_version); +extern BOOL init_display(void); +extern void reset_display(void); // VBCC Inline assembly void waitmouse(void) = "waitmouse:\n\tbtst\t#6,$bfe001\n\tbne\twaitmouse"; diff --git a/hardware/playfield1.c b/hardware/playfield1.c index 19e178e..da72f3d 100644 --- a/hardware/playfield1.c +++ b/hardware/playfield1.c @@ -1,12 +1,5 @@ #include -#include - #include -#include -#include -#include -#include -#include #include #include "common.h" @@ -34,7 +27,6 @@ * A simple setup to display a playfield with a depth of 1 bit. */ extern struct Custom custom; -extern struct Library *GfxBase; static UWORD __chip coplist[] = { COP_MOVE(BPL1PTH, 0), @@ -56,13 +48,7 @@ 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; - - BOOL is_pal = init_display(lib_version); - - ULONG pl1data = (ULONG) image_data; - ULONG pl2data = ((ULONG) &image_data[20 * NUM_RASTER_LINES]); + BOOL is_pal = init_display(); // hardcoded for UAE, since it seems that the mode returned is always NTSC is_pal = USE_PAL; @@ -97,6 +83,6 @@ int main(int argc, char **argv) waitmouse(); - reset_display(current_view, lib_version); + reset_display(); return 0; } diff --git a/hardware/sprites.c b/hardware/sprites.c index 124c279..56dce45 100644 --- a/hardware/sprites.c +++ b/hardware/sprites.c @@ -1,16 +1,12 @@ #include -#include #include - #include - #include "common.h" /* * A simple setup to display a sprite. */ extern struct Custom custom; -extern struct Library *GfxBase; static UWORD __chip coplist_pal[] = { COP_MOVE(SPR0PTH, 0x0000), @@ -39,13 +35,9 @@ static UWORD __chip spdat0[] = { 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; - - BOOL is_pal = init_display(lib_version); + BOOL is_pal = init_display(); coplist_ntsc[1] = ((ULONG) spdat0) & 0xffff; coplist_ntsc[3] = (((ULONG) spdat0) >> 16) & 0xffff; coplist_pal[1] = ((ULONG) spdat0) & 0xffff; @@ -55,6 +47,6 @@ int main(int argc, char **argv) waitmouse(); - reset_display(current_view, lib_version); + reset_display(); return 0; } diff --git a/hardware/startup.c b/hardware/startup.c index 88ccce1..ef4ec60 100644 --- a/hardware/startup.c +++ b/hardware/startup.c @@ -1,12 +1,5 @@ #include -#include - #include -#include -#include -#include -#include -#include #include #include "common.h" @@ -21,7 +14,6 @@ * A great starting point to use as a template for demos and games. */ extern struct Custom custom; -extern struct Library *GfxBase; static UWORD __chip coplist_pal[] = { COP_MOVE(BPLCON0, BPLCON0_COMPOSITE_COLOR), @@ -46,17 +38,13 @@ static UWORD __chip coplist_ntsc[] = { 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; - - BOOL is_pal = init_display(lib_version); + BOOL is_pal = init_display(); custom.cop1lc = is_pal ? (ULONG) coplist_pal : (ULONG) coplist_ntsc; waitmouse(); - reset_display(current_view, lib_version); + reset_display(); return 0; }