init repo
This commit is contained in:
commit
90e6151613
3260 files changed
+3745062
No files matched your search
@@ -0,0 +1,25 @@
|
||||
# compile c programs with GLCC
|
||||
CC=../../build/glcc
|
||||
|
||||
# use 32k map modified by overlay horizon.ovl
|
||||
CFLAGS=-map=32k,./horizon.ovl
|
||||
|
||||
# avoid runtime bss initialization to save code.
|
||||
LDFLAGS=--no-runtime-bss-init
|
||||
|
||||
|
||||
PGMS=horizon-v4.gt1 horizon-v5a.gt1 horizon-dev7.gt1
|
||||
|
||||
all: $(PGMS)
|
||||
|
||||
clean:
|
||||
-rm $(PGMS)
|
||||
|
||||
horizon-v4.gt1: horizon.c horizon.ovl
|
||||
${CC} ${CFLAGS} ${LDFLAGS} -rom=v4 horizon.c -o $@
|
||||
|
||||
horizon-v5a.gt1: horizon.c horizon.ovl
|
||||
${CC} ${CFLAGS} ${LDFLAGS} -rom=v5a horizon.c -o $@
|
||||
|
||||
horizon-dev7.gt1: horizon.c horizon.ovl
|
||||
${CC} ${CFLAGS} ${LDFLAGS} -rom=dev7 horizon.c -o $@
|
||||
@@ -0,0 +1,72 @@
|
||||
|
||||
/*----------------------------------------------------------------------+
|
||||
| |
|
||||
| Horizon.c -- Interactive 3D demo in C |
|
||||
| |
|
||||
+----------------------------------------------------------------------*/
|
||||
|
||||
// Standard includes
|
||||
#include <stdio.h>
|
||||
#include <gigatron/sys.h>
|
||||
|
||||
#define screenWidth 160
|
||||
#define screenHeight 120
|
||||
#define horizonY 32
|
||||
#define maxPitch (256 - screenWidth) // Aim for max possible pitch at bottom
|
||||
#define color1 0x3f
|
||||
#define color2 0x03
|
||||
#define maxV 32
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int y, x, i, j, v = 8;
|
||||
byte *p, *q = &videoTable[240];
|
||||
|
||||
#define makeEven(v) (((v) + 1) & ~1) // Odd pitches give jagged edges?
|
||||
#define calcPitch(y) makeEven((y) + (maxPitch - screenHeight + 1))
|
||||
|
||||
// Draw tiles in perspective in screen memory
|
||||
for (y=screenHeight-1; y>=horizonY; y--) {
|
||||
int pitch = calcPitch(y);
|
||||
int width = screenWidth + pitch;
|
||||
i = (screenWidth/2) % pitch;
|
||||
j = (400 / (y-horizonY+40)) & 1 ? 0 : color1^color2; // Swap colors
|
||||
for (x=0; x<width; x++) {
|
||||
if (i-- == 0)
|
||||
i = pitch - 1;
|
||||
screenMemory[y][x] = (i+i >= pitch) ? color1^j : color2^j;
|
||||
}
|
||||
videoTop_v5 = y+y; // Safe no-op on ROMs without videoTop
|
||||
}
|
||||
videoTop_v5 = 0; // Show all
|
||||
|
||||
// Interactive animation
|
||||
for (x=0; ; x+=v) {
|
||||
i = x & 255; // Phase i
|
||||
|
||||
// Calculate horizontal shift j at horizon
|
||||
for (y=0,j=0; y<calcPitch(horizonY); y++)
|
||||
j += i;
|
||||
|
||||
// Quickly update videoTable, in steps of 2 pixel lines for more speed
|
||||
p = &videoTable[horizonY*2+1];
|
||||
i += i;
|
||||
|
||||
// Synchronize with vertical blank
|
||||
{ byte nextFrame = frameCount + 1;
|
||||
while (frameCount != nextFrame) /**/ ; }
|
||||
|
||||
for (; p<q; p+=4) {
|
||||
*p = j >> 8; // LCC nicely emits LD vAC+1 for the shift
|
||||
j = i + (j & 255); // Faster operand order for LCC...
|
||||
}
|
||||
|
||||
// Change speed by game controller or keys
|
||||
switch (buttonState) {
|
||||
case buttonRight: if (++v > maxV) v = maxV; break;
|
||||
case buttonLeft: if (--v < -maxV) v = -maxV; break;
|
||||
case buttonA: case buttonB: v = 0; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# horizon.ovl
|
||||
# ------------size----addr----step----end---- flags (1=nocode, 2=nodata)
|
||||
segments = [ (0x00fa, 0x0200, 0x0100, 0x0500, 0),
|
||||
(0x0100, 0x0500, None, None, 0),
|
||||
(0x0060, 0x08a0, 0x0100, 0x80a0, 0) ]
|
||||
Reference in new issue
Block a user