From 7fad06a6fb304532a585326242c18e159f3014e4 Mon Sep 17 00:00:00 2001 From: Wei-ju Wu Date: Wed, 27 Jan 2016 12:55:48 -0800 Subject: [PATCH] added hardware subproject --- hardware/Makefile | 10 ++++++ hardware/README.md | 7 ++++ hardware/startup.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 hardware/Makefile create mode 100644 hardware/README.md create mode 100644 hardware/startup.c diff --git a/hardware/Makefile b/hardware/Makefile new file mode 100644 index 0000000..314c511 --- /dev/null +++ b/hardware/Makefile @@ -0,0 +1,10 @@ +CC=vc +kick13 +CFLAGS=-c99 -I$(NDK_INC) -DDEBUG -O2 + +all: startup + +clean: + rm -f *.o startup + +startup: startup.o + $(CC) $(CFLAGS) $^ -lamiga -lauto -o $@ diff --git a/hardware/README.md b/hardware/README.md new file mode 100644 index 0000000..d07dd6f --- /dev/null +++ b/hardware/README.md @@ -0,0 +1,7 @@ +# Hardware programming + +## Description + +This is a place for playing with programs that directly talk to the hardware +such as demos and games. + diff --git a/hardware/startup.c b/hardware/startup.c new file mode 100644 index 0000000..b1e74d8 --- /dev/null +++ b/hardware/startup.c @@ -0,0 +1,84 @@ +#include +#include + +#include +#include +#include +#include +#include +#include + +/* + * This is essentially the code for startup.asm from + * "Amiga Demo Coders Reference Manual" translated to C. + * + * This allows a program which operates directly on the hardware + * to play nice with the operating system and ensure a clean exit + * to Workbench. + * A great starting point to use as a template for demos and games. + */ +extern struct Custom custom; +extern struct CIA ciaa, ciab; +extern struct Library *GfxBase; + +// VBCC Inline assembly +void waitmouse() = "waitmouse:\n\tbtst\t#6,$bfe001\n\tbne\twaitmouse"; + +#define EXEC_BASE (4L) +#define TASK_PRIORITY 127 +#define VFREQ_PAL 50 + +static UWORD __chip coplist_pal[] = { + 0x100, 0x200, // otherwise no display! + 0x180, 0x00, + 0x8107, 0xfffe, // wait for $8107,$fffe + 0x180, + 0xf0f, // background red + 0xd607, 0xfffe, // wait for $d607,$fffe + 0x180, 0xff0, // background yellow + 0xffff, 0xfffe, + 0xffff, 0xfffe +}; +static UWORD __chip coplist_ntsc[] = { + 0x100, 0x0200, // otherwise no display! + 0x180, 0x00, + 0x6e07, 0xfffe, // wait for $6e07,$fffe + 0x180, 0xf00, // background red + 0xb007, 0xfffe, // wait for $b007,$fffe + 0x180, 0xff0, // background yellow + 0xffff, 0xfffe, + 0xffff, 0xfffe +}; + + +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; + LoadView(NULL); + WaitTOF(); + WaitTOF(); + + // Assuming 1.x, TODO: add handling for >= 2.x + // Note: FS-UAE reports 0 this, so essentially, there is no information + // for 1.x + if (((struct ExecBase *) EXEC_BASE)->VBlankFrequency == VFREQ_PAL) { + // Handle PAL + printf("PAL: %d\n", (int) ((struct ExecBase *) EXEC_BASE)->VBlankFrequency); + custom.cop1lc = (ULONG) coplist_pal; + } else { + // Handle NTSC + printf("NTSC: %d\n", (int) ((struct ExecBase *) EXEC_BASE)->VBlankFrequency); + custom.cop1lc = (ULONG) coplist_ntsc; + } + + waitmouse(); + LoadView(current_view); + WaitTOF(); + WaitTOF(); + custom.cop1lc = (ULONG) ((struct GfxBase *) GfxBase)->copinit; + RethinkDisplay(); + return 0; +}