Browse Source

Add Golan5 map compiler

master
Marrub 5 years ago
parent
commit
7126c6dab0
  1. 1
      .gitignore
  2. 53
      Makefile
  3. 8
      maps/base.gmf9
  4. 85
      src/golan5.c
  5. 32
      src/m_binio.c
  6. 14
      src/m_binio.h
  7. 2
      src/m_types.h

1
.gitignore vendored

@ -4,6 +4,7 @@ ir
src_crap
data/codedefs
data/fonts
data/maps
data/sounds
data/sprites
data/textures

53
Makefile

@ -8,53 +8,64 @@ INC=inc
CODEDEFS=data/codedefs
BIN=bin
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_LFLAGS += $(GDCC_TARGET)
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_HEADERS=$(wildcard $(SRC)/g_*.h)
GAME_OUTPUT=$(GAME_SOURCES:$(SRC)/g_%.c=$(IR)/g_%.ir)
GAME_BINARY=$(CODEDEFS)/eikyo-game.bin
GAME_OUTPUTS=$(GAME_SOURCES:$(SRC)/g_%.c=$(IR)/g_%.ir)
GAME_BINARYS=$(CODEDEFS)/eikyo-game.bin
MAIN_SOURCES=$(SRC)/main.c
MAIN_OUTPUT=$(MAIN_SOURCES:$(SRC)/%.c=$(IR)/%.ir)
MAIN_BINARY=$(CODEDEFS)/eikyo-main.bin
MAIN_OUTPUTS=$(MAIN_SOURCES:$(SRC)/%.c=$(IR)/%.ir)
MAIN_BINARYS=$(CODEDEFS)/eikyo-main.bin
MISC_SOURCES=$(wildcard $(SRC)/m_*.c)
MISC_HEADERS=$(wildcard $(SRC)/m_*.h)
MISC_OUTPUT=$(MISC_SOURCES:$(SRC)/m_%.c=$(IR)/m_%.ir)
MISC_BINARY=$(CODEDEFS)/eikyo-misc.bin
MISC_OUTPUTS=$(MISC_SOURCES:$(SRC)/m_%.c=$(IR)/m_%.ir)
MISC_BINARYS=$(CODEDEFS)/eikyo-misc.bin
RENDER_SOURCES=$(wildcard $(SRC)/r_*.c)
RENDER_HEADERS=$(wildcard $(SRC)/r_*.h)
RENDER_OUTPUT=$(RENDER_SOURCES:$(SRC)/r_%.c=$(IR)/r_%.ir)
RENDER_BINARY=$(CODEDEFS)/eikyo-render.bin
RNDR_SOURCES=$(wildcard $(SRC)/r_*.c)
RNDR_HEADERS=$(wildcard $(SRC)/r_*.h)
RNDR_OUTPUTS=$(RNDR_SOURCES:$(SRC)/r_%.c=$(IR)/r_%.ir)
RNDR_BINARYS=$(CODEDEFS)/eikyo-render.bin
.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 $@
clean:
rm -f $(BIN)/*
rm -f $(CODEDEFS)/*
rm -f $(IR)/*
rm -f $(addsuffix /*,$(FOLDERS))
$(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
$(GAME_BINARY): $(GAME_OUTPUT)
$(MAIN_BINARY): $(MAIN_OUTPUT)
$(MISC_BINARY): $(MISC_OUTPUT)
$(RENDER_BINARY): $(RENDER_OUTPUT)
$(GAME_BINARYS): $(GAME_OUTPUTS)
$(MAIN_BINARYS): $(MAIN_OUTPUTS)
$(MISC_BINARYS): $(MISC_OUTPUTS)
$(RNDR_BINARYS): $(RNDR_OUTPUTS)
$(CODEDEFS)/%.bin:
$(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 $@ $<
$(IR)/libc.ir $(IR)/libGDCC.ir:

8
maps/base.gmf9

@ -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

85
src/golan5.c

@ -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

32
src/m_binio.c

@ -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

14
src/m_binio.h

@ -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

2
src/m_types.h

@ -18,7 +18,7 @@
#if __GDCC__
typedef unsigned long fract ulfra;
typedef short accum fixed; // Fixed
typedef long fract lfrac; // Long Fractional
typedef long fract lfrac; // Long Fractional
#endif
typedef size_t msize; // Machine Size
typedef ptrdiff_t mpdif; // Machine Pointer Difference

Loading…
Cancel
Save