Skip to content

Commit

Permalink
Version 0.9.7 (the latest lament)
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperIlu committed Oct 20, 2019
1 parent 12ce9eb commit 50c7475
Show file tree
Hide file tree
Showing 81 changed files with 1,273 additions and 358,085 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ miktest.c
upx/
cylindrix/
build/
capture/
p5.js-master/
tests/p5.js/
.vscode/ipch
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
**Version 0.9.7 (the late lament)**
* fixed rect().
* added Bitmap.DrawTrans() for 32bit TGA images w/ alpha.
* Added Cut, Copy & Paste to the editor.
* Added auto indent and backtab handling.
* Started working on allegro 3D fuctions (unfinished, untested)!

**Version 0.9.6 (the crashing creation)**
* Fixed massive crash when using the builtin font in p5 compatibility layer
* Some API improvements
Expand Down
9 changes: 9 additions & 0 deletions DOjS.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SOFTWARE.
#include <unistd.h>

#include "DOjS.h"
#include "a3d.h"
#include "bitmap.h"
#include "color.h"
#include "edit.h"
Expand Down Expand Up @@ -71,6 +72,12 @@ BITMAP *cur;

volatile unsigned long sys_ticks;

/************************
** function prototypes **
************************/
static void tick_handler(void);
static void tick_handler_end(void);

/*********************
** static functions **
*********************/
Expand Down Expand Up @@ -279,6 +286,7 @@ static void run_script(char *script, int width, int bpp, bool no_sound, bool no_
init_bitmap(J);
init_font(J);
init_file(J);
init_a3d(J);

// create canvas
set_color_depth(bpp);
Expand All @@ -303,6 +311,7 @@ static void run_script(char *script, int width, int bpp, bool no_sound, bool no_
js_dofile(J, JSINC_COLOR);
js_dofile(J, JSINC_FILE);
js_dofile(J, JSINC_IPX);
js_dofile(J, JSINC_A3D);

// load main file
lastError = NULL;
Expand Down
6 changes: 3 additions & 3 deletions DOjS.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ SOFTWARE.

#define SYSINFO ">>> " //!< logfile line prefix for system messages

#define DOSJS_VERSION 0.96 //!< version number
#define DOSJS_VERSION_STR "V0.96" //!< version number as string
#define DOSJS_VERSION 0.97 //!< version number
#define DOSJS_VERSION_STR "V0.97" //!< version number as string

#define BOOT_DIR "JSBOOT/" //!< directory with boot files.

Expand Down Expand Up @@ -148,6 +148,6 @@ extern volatile unsigned long sys_ticks; //!< tick counter
/***********************
** exported functions **
***********************/
extern void update_transparency();
extern void update_transparency(void);

#endif // __DOJS_H__
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ALLEGRO=allegro-4.2.2-xc-master
INCLUDES=-I$(MUJS) -I$(ALLEGRO)/include
LIBS=-lalleg -lmujs -lm -lemu

CFLAGS=-MMD -Wall -O2 -march=i386 -mtune=i586 -ffast-math $(INCLUDES) -DPLATFORM_MSDOS -fgnu89-inline #-DDEBUG_ENABLED
CFLAGS=-MMD -Wall -Wmissing-prototypes -O2 -march=i386 -mtune=i586 -ffast-math $(INCLUDES) -DPLATFORM_MSDOS -fgnu89-inline #-DDEBUG_ENABLED
LDFLAGS=-L$(MUJS)/build/release -L$(ALLEGRO)/lib/djgpp

EXE=DOJS.EXE
Expand Down Expand Up @@ -47,7 +47,8 @@ PARTS= \
$(BUILDDIR)/funcs.o \
$(BUILDDIR)/gfx.o \
$(BUILDDIR)/sound.o \
$(BUILDDIR)/util.o
$(BUILDDIR)/util.o \
$(BUILDDIR)/a3d.o

all: init libmujs liballegro $(EXE)

Expand Down
251 changes: 251 additions & 0 deletions a3d.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/*
MIT License
Copyright (c) 2019 Andre Seidelt <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include <allegro.h>
#include <dirent.h>
#include <dpmi.h>
#include <errno.h>
#include <mujs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>

#include "DOjS.h"
#include "a3d.h"
#include "bitmap.h"

/*********************
** static functions **
*********************/
/**
* expects an array w/ 5 elements on the stack and returns a V3D.
*/
static V3D_f *array_to_v3d(js_State *J, int idx) {
V3D_f *v = malloc(sizeof(V3D_f));
if (!v) {
return NULL;
}

js_getindex(J, idx, 0);
v->x = js_tonumber(J, -1);
js_pop(J, 1);
js_getindex(J, idx, 1);
v->y = js_tonumber(J, -1);
js_pop(J, 1);
js_getindex(J, idx, 2);
v->z = js_tonumber(J, -1);
js_pop(J, 1);
js_getindex(J, idx, 3);
v->u = js_tonumber(J, -1);
js_pop(J, 1);
js_getindex(J, idx, 4);
v->v = js_tonumber(J, -1);
js_pop(J, 1);

js_getindex(J, idx, 5);
v->c = js_toint32(J, -1);
js_pop(J, 1);

return v;
}

static V3D_f **v3d_array(js_State *J, int idx, int *vc) {
if (!js_isarray(J, idx)) {
*vc = 0;
js_error(J, "Array expected");
return NULL;
} else {
int len = js_getlength(J, idx);
V3D_f **array = malloc(len * sizeof(V3D_f *));
if (!array) {
return NULL;
}
for (int i = 0; i < len; i++) {
js_getindex(J, idx, i);
{
int vlen = js_getlength(J, -1);
if (vlen < 6) {
js_error(J, "V3D must have 6 values");
free(array);
*vc = 0;
return NULL;
}

array[i] = array_to_v3d(J, -1);
}
js_pop(J, 1);
}
*vc = len;
return array;
}
}

static void free_v3d(V3D_f **v, int vc) {
if (v) {
for (int i = 0; i < vc; i++) {
free(v[i]);
}

free(v);
}
}

static BITMAP *bitmap_or_null(js_State *J, int idx) {
BITMAP *texture = NULL;
if (js_isuserdata(J, idx, TAG_BITMAP)) {
texture = js_touserdata(J, idx, TAG_BITMAP);
}
return texture;
}

static void f_Triangle3D(js_State *J) {
int type = js_toint16(J, 1);
BITMAP *texture = bitmap_or_null(J, 2);

V3D_f *v1 = array_to_v3d(J, 3);
V3D_f *v2 = array_to_v3d(J, 4);
V3D_f *v3 = array_to_v3d(J, 5);

if (v1 && v2 && v3) {
triangle3d_f(cur, type, texture, v1, v2, v3);
} else {
js_error(J, "Cannot convert vertex");
}

if (v1) {
free(v1);
}
if (v2) {
free(v2);
}
if (v3) {
free(v3);
}
}

static void f_Quad3D(js_State *J) {
int type = js_toint16(J, 1);
BITMAP *texture = bitmap_or_null(J, 2);

V3D_f *v1 = array_to_v3d(J, 3);
V3D_f *v2 = array_to_v3d(J, 4);
V3D_f *v3 = array_to_v3d(J, 5);
V3D_f *v4 = array_to_v3d(J, 6);

if (v1 && v2 && v3 && v4) {
quad3d_f(cur, type, texture, v1, v2, v3, v4);
} else {
js_error(J, "Cannot convert vertex");
}

if (v1) {
free(v1);
}
if (v2) {
free(v2);
}
if (v3) {
free(v3);
}
if (v4) {
free(v4);
}
}

static void f_RenderScene(js_State *J) { render_scene(); }

static void f_DestroyScene(js_State *J) { destroy_scene(); }

static void f_ClearScene(js_State *J) { clear_scene(cur); }

static void f_CreateScene(js_State *J) {
int nedge = js_toint16(J, 1);
int npoly = js_toint16(J, 2);

if (create_scene(nedge, npoly) < 0) {
js_error(J, "Cannot allocate scene");
return;
}
}

static void f_Polygon3D(js_State *J) {
int type = js_toint16(J, 1);
BITMAP *texture = bitmap_or_null(J, 2);

int vc = 0;
V3D_f **vtx = v3d_array(J, 3, &vc);
if (vtx) {
polygon3d_f(cur, type, texture, vc, vtx);
} else {
js_error(J, "Cannot convert vertices");
}

free_v3d(vtx, vc);
}

static void f_VDebug(js_State *J) {
int vc = 0;
V3D_f **vtx = v3d_array(J, 1, &vc);
if (vtx) {
fprintf(LOGSTREAM, "Number of entries=%d\n", vc);
for (int i = 0; i < vc; i++) {
fprintf(LOGSTREAM, " v[%d] = {x=%f, y=%f, z=%f, u=%f, v=%f, c=0x%X}\n", i, vtx[i]->x, vtx[i]->y, vtx[i]->z, vtx[i]->u, vtx[i]->v, vtx[i]->c);
}
} else {
js_error(J, "Cannot convert vertices");
}
fflush(LOGSTREAM);

free_v3d(vtx, vc);
}

// static void f_(js_State *J) {}

/***********************
** exported functions **
***********************/
/**
* @brief initialize a3d subsystem.
*
* @param J VM state.
*/
void init_a3d(js_State *J) {
// define global functions
FUNCDEF(J, f_RenderScene, "RenderScene", 0);
FUNCDEF(J, f_DestroyScene, "DestroyScene", 0);
FUNCDEF(J, f_ClearScene, "ClearScene", 0);
FUNCDEF(J, f_CreateScene, "CreateScene", 2);

FUNCDEF(J, f_Polygon3D, "Polygon3D", 3);
FUNCDEF(J, f_Triangle3D, "Triangle3D", 5);
FUNCDEF(J, f_Quad3D, "Quad3D", 6);

FUNCDEF(J, f_VDebug, "VDebug", 1);
}

/**
int clip3d_f(int type, float min_z, float max_z, int vc, const V3D_f *vtx[], V3D_f *vout[], V3D_f *vtmp[], int out[]);
zbuffer?
*/
39 changes: 39 additions & 0 deletions a3d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
MIT License
Copyright (c) 2019 Andre Seidelt <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef __A3D_H__
#define __A3D_H__

#include <mujs.h>
#include "DOjS.h"

/************
** defines **
************/
#define JSINC_A3D BOOT_DIR "a3d.js" //!< boot script for a3d subsystem

/***********************
** exported functions **
***********************/
extern void init_a3d(js_State *J);

#endif // __A3D_H__
Loading

0 comments on commit 50c7475

Please sign in to comment.