Add Golan5 map compiler
parent
aeb21bb438
commit
7126c6dab0
|
@ -4,6 +4,7 @@ ir
|
||||||
src_crap
|
src_crap
|
||||||
data/codedefs
|
data/codedefs
|
||||||
data/fonts
|
data/fonts
|
||||||
|
data/maps
|
||||||
data/sounds
|
data/sounds
|
||||||
data/sprites
|
data/sprites
|
||||||
data/textures
|
data/textures
|
||||||
|
|
53
Makefile
53
Makefile
|
@ -8,53 +8,64 @@ INC=inc
|
||||||
CODEDEFS=data/codedefs
|
CODEDEFS=data/codedefs
|
||||||
BIN=bin
|
BIN=bin
|
||||||
IR=ir
|
IR=ir
|
||||||
|
MAPSRC=maps
|
||||||
|
MAPBIN=data/maps
|
||||||
|
FOLDERS=$(CODEDEFS) $(BIN) $(IR) $(MAPBIN)
|
||||||
|
|
||||||
CFLAGS += -O2 -g
|
CFLAGS += -O2 -g -lm
|
||||||
|
|
||||||
GDCC_TARGET=--bc-target=Doominati
|
GDCC_TARGET=--bc-target=Doominati
|
||||||
GDCC_LFLAGS += $(GDCC_TARGET)
|
GDCC_LFLAGS += $(GDCC_TARGET)
|
||||||
GDCC_CFLAGS += $(GDCC_TARGET) --alloc-Aut=4194304 -c
|
GDCC_CFLAGS += $(GDCC_TARGET) --alloc-Aut=4194304 -c
|
||||||
|
|
||||||
|
MAPS_SOURCES=$(wildcard $(MAPSRC)/*.gmf9)
|
||||||
|
MAPS_OUTPUTS=$(MAPS_SOURCES:$(MAPSRC)/%.gmf9=$(MAPBIN)/%.gmf0)
|
||||||
|
|
||||||
GAME_SOURCES=$(wildcard $(SRC)/g_*.c)
|
GAME_SOURCES=$(wildcard $(SRC)/g_*.c)
|
||||||
GAME_HEADERS=$(wildcard $(SRC)/g_*.h)
|
GAME_HEADERS=$(wildcard $(SRC)/g_*.h)
|
||||||
GAME_OUTPUT=$(GAME_SOURCES:$(SRC)/g_%.c=$(IR)/g_%.ir)
|
GAME_OUTPUTS=$(GAME_SOURCES:$(SRC)/g_%.c=$(IR)/g_%.ir)
|
||||||
GAME_BINARY=$(CODEDEFS)/eikyo-game.bin
|
GAME_BINARYS=$(CODEDEFS)/eikyo-game.bin
|
||||||
|
|
||||||
MAIN_SOURCES=$(SRC)/main.c
|
MAIN_SOURCES=$(SRC)/main.c
|
||||||
MAIN_OUTPUT=$(MAIN_SOURCES:$(SRC)/%.c=$(IR)/%.ir)
|
MAIN_OUTPUTS=$(MAIN_SOURCES:$(SRC)/%.c=$(IR)/%.ir)
|
||||||
MAIN_BINARY=$(CODEDEFS)/eikyo-main.bin
|
MAIN_BINARYS=$(CODEDEFS)/eikyo-main.bin
|
||||||
|
|
||||||
MISC_SOURCES=$(wildcard $(SRC)/m_*.c)
|
MISC_SOURCES=$(wildcard $(SRC)/m_*.c)
|
||||||
MISC_HEADERS=$(wildcard $(SRC)/m_*.h)
|
MISC_HEADERS=$(wildcard $(SRC)/m_*.h)
|
||||||
MISC_OUTPUT=$(MISC_SOURCES:$(SRC)/m_%.c=$(IR)/m_%.ir)
|
MISC_OUTPUTS=$(MISC_SOURCES:$(SRC)/m_%.c=$(IR)/m_%.ir)
|
||||||
MISC_BINARY=$(CODEDEFS)/eikyo-misc.bin
|
MISC_BINARYS=$(CODEDEFS)/eikyo-misc.bin
|
||||||
|
|
||||||
RENDER_SOURCES=$(wildcard $(SRC)/r_*.c)
|
RNDR_SOURCES=$(wildcard $(SRC)/r_*.c)
|
||||||
RENDER_HEADERS=$(wildcard $(SRC)/r_*.h)
|
RNDR_HEADERS=$(wildcard $(SRC)/r_*.h)
|
||||||
RENDER_OUTPUT=$(RENDER_SOURCES:$(SRC)/r_%.c=$(IR)/r_%.ir)
|
RNDR_OUTPUTS=$(RNDR_SOURCES:$(SRC)/r_%.c=$(IR)/r_%.ir)
|
||||||
RENDER_BINARY=$(CODEDEFS)/eikyo-render.bin
|
RNDR_BINARYS=$(CODEDEFS)/eikyo-render.bin
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
|
||||||
all: $(CODEDEFS) $(BIN) $(IR) $(CODEDEFS)/stdlib.bin $(GAME_BINARY) $(MAIN_BINARY) $(MISC_BINARY) $(RENDER_BINARY)
|
all: $(FOLDERS) $(CODEDEFS)/stdlib.bin $(GAME_BINARYS) $(MAIN_BINARYS) $(MISC_BINARYS) $(RNDR_BINARYS) $(MAPS_OUTPUTS)
|
||||||
|
|
||||||
$(CODEDEFS) $(BIN) $(IR):
|
$(FOLDERS):
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(BIN)/*
|
rm -f $(addsuffix /*,$(FOLDERS))
|
||||||
rm -f $(CODEDEFS)/*
|
|
||||||
rm -f $(IR)/*
|
$(MAPBIN)/%.gmf0: $(MAPSRC)/%.gmf9 $(BIN)/golan5
|
||||||
|
$(BIN)/golan5 $< $@
|
||||||
|
|
||||||
|
$(BIN)/golan5: $(SRC)/golan5.c $(SRC)/m_binio.c $(SRC)/m_token.c $(SRC)/m_tokbuf.c
|
||||||
|
$(BIN)/%:
|
||||||
|
$(CC) $(CFLAGS) $(LFLAGS) -o $@ $^
|
||||||
|
|
||||||
$(CODEDEFS)/stdlib.bin: $(IR)/libc.ir $(IR)/libGDCC.ir
|
$(CODEDEFS)/stdlib.bin: $(IR)/libc.ir $(IR)/libGDCC.ir
|
||||||
$(GAME_BINARY): $(GAME_OUTPUT)
|
$(GAME_BINARYS): $(GAME_OUTPUTS)
|
||||||
$(MAIN_BINARY): $(MAIN_OUTPUT)
|
$(MAIN_BINARYS): $(MAIN_OUTPUTS)
|
||||||
$(MISC_BINARY): $(MISC_OUTPUT)
|
$(MISC_BINARYS): $(MISC_OUTPUTS)
|
||||||
$(RENDER_BINARY): $(RENDER_OUTPUT)
|
$(RNDR_BINARYS): $(RNDR_OUTPUTS)
|
||||||
$(CODEDEFS)/%.bin:
|
$(CODEDEFS)/%.bin:
|
||||||
$(GDCC_LD) $(GDCC_LFLAGS) -o $@ $^
|
$(GDCC_LD) $(GDCC_LFLAGS) -o $@ $^
|
||||||
|
|
||||||
$(IR)/%.ir: $(SRC)/%.c $(GAME_HEADERS) $(MISC_HEADERS) $(RENDER_HEADERS)
|
$(IR)/%.ir: $(SRC)/%.c $(GAME_HEADERS) $(MISC_HEADERS) $(RNDR_HEADERS)
|
||||||
$(GDCC_CC) $(GDCC_CFLAGS) -o $@ $<
|
$(GDCC_CC) $(GDCC_CFLAGS) -o $@ $<
|
||||||
|
|
||||||
$(IR)/libc.ir $(IR)/libGDCC.ir:
|
$(IR)/libc.ir $(IR)/libGDCC.ir:
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
// Copyright © 2017 Project Golan, all rights reserved.
|
||||||
|
{0 Sector -250 -200 200 200}
|
||||||
|
{0 Sector -260 -210 10 220}
|
||||||
|
{0 Sector -50 -210 10 220}
|
||||||
|
{0 Sector -250 -210 200 10}
|
||||||
|
{0 Sector -250 -10 200 10}
|
||||||
|
|
||||||
|
// EOF
|
|
@ -0,0 +1,85 @@
|
||||||
|
// Copyright © 2017 Project Golan, all rights reserved.
|
||||||
|
#include "m_tokbuf.h"
|
||||||
|
#include "m_binio.h"
|
||||||
|
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
// Static Objects ------------------------------------------------------------|
|
||||||
|
|
||||||
|
static jmp_buf ejmp;
|
||||||
|
|
||||||
|
// Static Functions ----------------------------------------------------------|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Expect
|
||||||
|
//
|
||||||
|
static M_token *Expect(M_tkbuf *tb, M_tokty t)
|
||||||
|
{
|
||||||
|
M_token *tok = M_TokBuf_Get(tb);
|
||||||
|
if(tok->type != t) {
|
||||||
|
fprintf(stderr, "unexpected token\n");
|
||||||
|
longjmp(ejmp, 1);
|
||||||
|
}
|
||||||
|
return tok;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extern Functions ----------------------------------------------------------|
|
||||||
|
|
||||||
|
//
|
||||||
|
// main
|
||||||
|
//
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
if(argc < 2) {
|
||||||
|
fprintf(stderr, "not enough arguments\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
M_tkbuf tb = {.fp = fopen(argv[1], "r"), .bbeg = 1, .bend = 8};
|
||||||
|
|
||||||
|
if(!tb.fp) {
|
||||||
|
fprintf(stderr, "couldn't open input file\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *out = fopen(argv[2], "wb");
|
||||||
|
|
||||||
|
if(!out) {
|
||||||
|
fclose(tb.fp);
|
||||||
|
fprintf(stderr, "couldn't open output file\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
M_TokBuf_Ctor(&tb);
|
||||||
|
|
||||||
|
if(setjmp(ejmp) == 1)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
fwrite("Gmf0\r\n\xF7\0", 1, 8, out);
|
||||||
|
|
||||||
|
do {
|
||||||
|
if(M_TokBuf_Drop(&tb, tok_braceo))
|
||||||
|
{
|
||||||
|
M_IO_WriteLE4u(out, strtoul(Expect(&tb, tok_number)->textV, NULL, 0));
|
||||||
|
M_token *tok = Expect(&tb, tok_identi);
|
||||||
|
fwrite(tok->textV, 1, tok->textC, out);
|
||||||
|
if(strcmp(tok->textV, "Sector") == 0)
|
||||||
|
for(int i = 0; i < 4; i++)
|
||||||
|
M_IO_WriteLE4k(out, strtof(Expect(&tb, tok_number)->textV, NULL));
|
||||||
|
Expect(&tb, tok_bracec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(!M_TokBuf_Drop(&tb, tok_eof));
|
||||||
|
|
||||||
|
done:
|
||||||
|
fclose(out);
|
||||||
|
M_TokBuf_Dtor(&tb);
|
||||||
|
fclose(tb.fp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// EOF
|
|
@ -0,0 +1,32 @@
|
||||||
|
// Copyright © 2017 Project Golan, all rights reserved.
|
||||||
|
#include "m_binio.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
// Extern Functions ----------------------------------------------------------|
|
||||||
|
|
||||||
|
//
|
||||||
|
// M_IO_WriteLE4u
|
||||||
|
//
|
||||||
|
void M_IO_WriteLE4u(FILE *fp, mword v)
|
||||||
|
{
|
||||||
|
fputc((v >> 24) & 0xFF, fp);
|
||||||
|
fputc((v >> 16) & 0xFF, fp);
|
||||||
|
fputc((v >> 8) & 0xFF, fp);
|
||||||
|
fputc((v >> 0) & 0xFF, fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// M_IO_WriteLE4k
|
||||||
|
//
|
||||||
|
void M_IO_WriteLE4k(FILE *fp, float v)
|
||||||
|
{
|
||||||
|
float a = fabsf(v);
|
||||||
|
mword k = ((mword)a << 7) & 0x7FFFFF80;
|
||||||
|
k |= (mword)(fmod(a, 1) * 0x7F) & 0x7F;
|
||||||
|
if(v < 0) k |= 0x80000000;
|
||||||
|
M_IO_WriteLE4u(fp, k);
|
||||||
|
}
|
||||||
|
|
||||||
|
// EOF
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright © 2017 Project Golan, all rights reserved.
|
||||||
|
#ifndef m_binio_h
|
||||||
|
#define m_binio_h
|
||||||
|
|
||||||
|
#include "m_types.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// Extern Functions ----------------------------------------------------------|
|
||||||
|
|
||||||
|
void M_IO_WriteLE4u(FILE *fp, mword v);
|
||||||
|
void M_IO_WriteLE4k(FILE *fp, float v);
|
||||||
|
|
||||||
|
#endif
|
|
@ -18,7 +18,7 @@
|
||||||
#if __GDCC__
|
#if __GDCC__
|
||||||
typedef unsigned long fract ulfra;
|
typedef unsigned long fract ulfra;
|
||||||
typedef short accum fixed; // Fixed
|
typedef short accum fixed; // Fixed
|
||||||
typedef long fract lfrac; // Long Fractional
|
typedef long fract lfrac; // Long Fractional
|
||||||
#endif
|
#endif
|
||||||
typedef size_t msize; // Machine Size
|
typedef size_t msize; // Machine Size
|
||||||
typedef ptrdiff_t mpdif; // Machine Pointer Difference
|
typedef ptrdiff_t mpdif; // Machine Pointer Difference
|
||||||
|
|
Loading…
Reference in New Issue