add background tile editing & saving

This commit is contained in:
Jeremy Penner 2019-08-07 22:25:27 -04:00
parent ca1abba60b
commit b1a71e3e35
9 changed files with 123 additions and 42 deletions

BIN
game.exe

Binary file not shown.

BIN
game.prj

Binary file not shown.

View file

@ -21,8 +21,8 @@ s" timer.jor" loadfile
s" entity.jor" loadfile s" entity.jor" loadfile
s" footer.jor" loadfile s" footer.jor" loadfile
s" map.jor" loadfile s" map.jor" loadfile
s" jiles.jor" loadfile
s" state.jor" loadfile s" state.jor" loadfile
s" jiles.jor" loadfile
s" game.jor" loadfile s" game.jor" loadfile
; execute ; execute

View file

@ -15,8 +15,12 @@ array preview 128 allot
: draw-preview : draw-preview
0 18 for 0 18 for
i preview tile>buf 0 edittarget = if
spriteindex @ preview spr>buf i preview tile>buf
spriteindex @ preview spr>buf
else
spriteindex @ preview tile>buf
then
i 3 % 2 * 65 + i 3 / 16 * preview paintbuf i 3 % 2 * 65 + i 3 / 16 * preview paintbuf
next ; next ;
@ -28,12 +32,24 @@ array preview 128 allot
r@ mousexys putpixel refresh r@ mousexys putpixel refresh
then rdrop ; then rdrop ;
: gfxfilename
0 edittarget = if
s" sprite.gfx"
else
NIGHT flag@ if
s" ntiles.gfx"
else
s" tiles.gfx"
then
then ;
var jiles-old-tick var jiles-old-tick
var jiles-old-draw var jiles-old-draw
44 const ^Z 44 const ^Z
45 const ^X 45 const ^X
31 const ^S 31 const ^S
20 const ^T
: jiles-tick : jiles-tick
mousepos 128 < swap 128 < and if mousepos 128 < swap 128 < and if
@ -49,11 +65,12 @@ var jiles-old-draw
^RIGHT key-pressed if 1 +sprite! then ^RIGHT key-pressed if 1 +sprite! then
^Z key-pressed if mousexys getpixel lcolor color! then ^Z key-pressed if mousexys getpixel lcolor color! then
^X key-pressed if mousexys getpixel rcolor color! then ^X key-pressed if mousexys getpixel rcolor color! then
^S key-pressed if s" SAVING" type cr savegfx then ^S key-pressed if s" SAVING " type gfxfilename dup type cr savegfx then
^T key-pressed if edittarget if 0 else 1 then edittarget! 0 +sprite! then
^TAB key-pressed if ^TAB key-pressed if
jiles-old-draw @ ' draw redefine jiles-old-draw @ ' draw redefine
jiles-old-tick @ ' tick redefine jiles-old-tick @ ' tick redefine
mousehide unfuck invalidate-map mousehide unfuck invalidate-map reloadtiles
then then
tick-debounce tick-debounce
; ;

BIN
ntiles.gfx Executable file

Binary file not shown.

View file

@ -16,8 +16,8 @@ array flags FLAG-COUNT 8 / 1 + allot
: setflag 1 swap flagsf! ; : setflag 1 swap flagsf! ;
: clearflag 0 swap flagsf! ; : clearflag 0 swap flagsf! ;
: day s" TILES.TIF" loadtiles invalidate-map NIGHT clearflag ; : day s" tiles.gfx" loadtiles invalidate-map NIGHT clearflag ;
: night s" NTILES.TIF" loadtiles invalidate-map NIGHT setflag ; : night s" ntiles.gfx" loadtiles invalidate-map NIGHT setflag ;
: {car-drive} NIGHT flag@ if {car-lit} else {car} then ; : {car-drive} NIGHT flag@ if {car-lit} else {car} then ;

View file

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <dos.h> #include <dos.h>
#include <alloc.h> #include <alloc.h>
#include <ctype.h>
#include "video.h" #include "video.h"
#include "kbd.h" #include "kbd.h"
@ -123,25 +124,36 @@ void fillMap() {
} }
} }
void readTiles(char *filename) { void readTifTiles(char *filename) {
FILE *f; FILE *f;
TifImageMeta_t meta; TifImageMeta_t meta;
f = fopen(filename, "rb"); f = fopen(filename, "rb");
meta = tifLoadMeta(f); meta = tifLoadMeta(f);
tifLoad(f, meta, tiles, NUM_TILES * 16, 16, 4); tifLoad(f, meta, tiles, NUM_TILES * 16, 16, 4);
tifLoadEGA(f, meta, OFF_TILES, NUM_TILES * 16, 16); fclose(f);
loadTiles(OFF_TILES, tiles);
}
void readTiles(char *filename) {
FILE *f = fopen(filename, "rb");
freadfar(f, tiles, NUM_TILES * TILE_STRIDE * 2);
fclose(f); fclose(f);
loadTiles(OFF_TILES, tiles); loadTiles(OFF_TILES, tiles);
} }
void f_loadtiles() { void f_loadtiles() {
readTiles(TOP().s); if (tolower(TOP().s[strlen(TOP().s) - 1]) == 'f') {
readTifTiles(TOP().s);
} else {
readTiles(TOP().s);
}
DROP(1); DROP(1);
} }
#define SPRITE_GFX #define TILES_GFX
void game_init() { void game_init() {
FILE *f; FILE *f;
@ -166,23 +178,20 @@ void game_init() {
tifLoadEGA(f, meta, 0, 48, 336); tifLoadEGA(f, meta, 0, 48, 336);
fclose(f); fclose(f);
#ifdef SPRITE_GFX
f = fopen("sprite.gfx", "rb"); f = fopen("sprite.gfx", "rb");
freadfar(f, sprites, NUM_SPRITES * SPRITE_STRIDE * 2); freadfar(f, sprites, NUM_SPRITES * SPRITE_STRIDE * 2);
fclose(f); fclose(f);
#else
f = fopen("SPRITE.TIF", "rb");
meta = tifLoadMeta(f);
tifLoad(f, meta, sprites, NUM_SPRITES * 16, 16, 5);
fclose(f);
#endif
f = fopen("PORTRAIT.TIF", "rb"); f = fopen("PORTRAIT.TIF", "rb");
meta = tifLoadMeta(f); meta = tifLoadMeta(f);
tifLoadEGA(f, meta, OFF_PORTRAITS, NUM_PORTRAITS * 32, 32); tifLoadEGA(f, meta, OFF_PORTRAITS, NUM_PORTRAITS * 32, 32);
fclose(f); fclose(f);
readTiles("TILES.TIF"); #ifdef TILES_GFX
readTiles("tiles.gfx");
#else
readTifTiles("TILES.TIF");
#endif
loadMap(map, 100, 100); loadMap(map, 100, 100);
scroll(0, 0); scroll(0, 0);
@ -306,13 +315,27 @@ void f_glitch() {
/* JILES */ /* JILES */
#define SCREEN_STRIDE 40 #define SCREEN_STRIDE 40
typedef enum {
ET_SPRITE = 0,
ET_TILE = 1
} EditTarget_t;
EditTarget_t editTarget = ET_SPRITE;
unsigned int far *getTarget(int index) {
if (editTarget == ET_SPRITE) {
return &sprites[index * SPRITE_STRIDE];
} else {
return &tiles[index * TILE_STRIDE];
}
}
int getsprpixel(int x, int y, unsigned int far *spr) { int getsprpixel(int x, int y, unsigned int far *spr) {
int shift = (15 - x); int shift = (15 - x);
int b = (spr[y + 0] & (1 << shift)) >> shift; int b = (spr[y + 0] & (1 << shift)) >> shift;
int g = (spr[y + 16] & (1 << shift)) >> shift; int g = (spr[y + 16] & (1 << shift)) >> shift;
int r = (spr[y + 32] & (1 << shift)) >> shift; int r = (spr[y + 32] & (1 << shift)) >> shift;
int i = (spr[y + 48] & (1 << shift)) >> shift; int i = (spr[y + 48] & (1 << shift)) >> shift;
int v = (spr[y + 64] & (1 << shift)) ? 0 : 1; int v = editTarget != ET_SPRITE || (spr[y + 64] & (1 << shift)) ? 0 : 1;
return b | (g << 1) | (r << 2) | (i << 3) | (v << 4); return b | (g << 1) | (r << 2) | (i << 3) | (v << 4);
} }
int resetEnabledCache = 0; int resetEnabledCache = 0;
@ -342,7 +365,7 @@ void drawFatBox(int x, int y, int color) {
void f_drawfatsprite() { void f_drawfatsprite() {
int isprite = TOP().i; int isprite = TOP().i;
unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE]; unsigned int far *spr = getTarget(isprite);
int x, y; int x, y;
DROP(1); DROP(1);
@ -361,10 +384,14 @@ void f_drawfatbox() {
} }
void f_savegfx() { void f_savegfx() {
FILE *fp; FILE *fp = fopen(TOP().s, "wb");
fp = fopen("sprite.gfx", "wb"); if (editTarget == ET_SPRITE) {
fwritefar(fp, sprites, NUM_SPRITES * SPRITE_STRIDE * 2); fwritefar(fp, sprites, NUM_SPRITES * SPRITE_STRIDE * 2);
} else {
fwritefar(fp, tiles, NUM_TILES * TILE_STRIDE * 2);
}
fclose(fp); fclose(fp);
DROP(1);
} }
void f_mousehide() { void f_mousehide() {
@ -386,7 +413,7 @@ void f_resetvideo() {
void f_putpixel() { void f_putpixel() {
int isprite = TOP().i; int isprite = TOP().i;
unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE]; unsigned int far *spr = getTarget(isprite);
int x = ST2().i; int x = ST2().i;
int y = ST1().i; int y = ST1().i;
int color, shift, b, g, r, i, v; int color, shift, b, g, r, i, v;
@ -406,12 +433,14 @@ void f_putpixel() {
spr[y + 16] = (spr[y + 16] & ~(1 << shift)) | (g << shift); spr[y + 16] = (spr[y + 16] & ~(1 << shift)) | (g << shift);
spr[y + 32] = (spr[y + 32] & ~(1 << shift)) | (r << shift); spr[y + 32] = (spr[y + 32] & ~(1 << shift)) | (r << shift);
spr[y + 48] = (spr[y + 48] & ~(1 << shift)) | (i << shift); spr[y + 48] = (spr[y + 48] & ~(1 << shift)) | (i << shift);
spr[y + 64] = (spr[y + 64] & ~(1 << shift)) | (v << shift); if (editTarget == ET_SPRITE) {
spr[y + 64] = (spr[y + 64] & ~(1 << shift)) | (v << shift);
}
} }
void f_getpixel() { void f_getpixel() {
int isprite = TOP().i; int isprite = TOP().i;
unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE]; unsigned int far *spr = getTarget(isprite);
int x = ST2().i; int x = ST2().i;
int y = ST1().i; int y = ST1().i;
DROP(2); DROP(2);
@ -420,29 +449,45 @@ void f_getpixel() {
} }
void f_spritecount() { void f_spritecount() {
PUSHI(NUM_SPRITES); if (editTarget == ET_SPRITE) {
PUSHI(NUM_SPRITES);
} else {
PUSHI(NUM_TILES);
}
} }
void f_tile2buf() { void f_tile2buf() {
unsigned int *buf = TOP().p; unsigned int *buf = (unsigned int *)TOP().p;
unsigned int itile = ST1().u; unsigned int itile = ST1().u;
DROP(2); DROP(2);
writeTile(buf, &tiles[itile * TILE_STRIDE]); writeTile(buf, &tiles[itile * TILE_STRIDE]);
} }
void f_spr2buf() { void f_spr2buf() {
unsigned int *buf = TOP().p; unsigned int *buf = (unsigned int *)TOP().p;
unsigned int isprite = ST1().u; unsigned int isprite = ST1().u;
DROP(2); DROP(2);
overlaySprite(buf, &sprites[isprite * SPRITE_STRIDE], 0, 0); overlaySprite(buf, &sprites[isprite * SPRITE_STRIDE], 0, 0);
} }
void f_paintbuf() { void f_paintbuf() {
unsigned int *buf = TOP().p; unsigned int *buf = (unsigned int *)TOP().p;
int y = ST1().i; int y = ST1().i;
int x = ST2().i; int x = ST2().i;
DROP(3); DROP(3);
paintBuffer(buf, x + (y * 40)); paintBuffer(buf, x + (y * SCREEN_STRIDE));
}
void f_setedittarget() {
editTarget = TOP().i;
}
void f_getedittarget() {
PUSHI(editTarget);
}
void f_reloadtiles() {
loadTiles(OFF_TILES, tiles);
} }
/* INIT */ /* INIT */
@ -483,6 +528,9 @@ void game_f_init(char *exe, char *bootjor) {
CDEF("tile>buf", f_tile2buf); CDEF("tile>buf", f_tile2buf);
CDEF("spr>buf", f_spr2buf); CDEF("spr>buf", f_spr2buf);
CDEF("paintbuf", f_paintbuf); CDEF("paintbuf", f_paintbuf);
CDEF("edittarget", f_getedittarget);
CDEF("edittarget!", f_setedittarget);
CDEF("reloadtiles", f_reloadtiles);
f_loadjor(bootjor); f_loadjor(bootjor);

36
tiles.c
View file

@ -62,9 +62,35 @@ void blit32x32(unsigned int offsetFrom, unsigned int offsetTo) {
TiledScreen_t screen = { 0, 0, 0, 0, { OFF_PAGE1, OFF_PAGE2 }, 0, 0, NULL, NULL, TiledScreen_t screen = { 0, 0, 0, 0, { OFF_PAGE1, OFF_PAGE2 }, 0, 0, NULL, NULL,
0, 0, 0, 0, 0 }; 0, 0, 0, 0, 0 };
void paintBufferPlane(unsigned int *buf, unsigned int vidOffset, int stride, int plane) {
unsigned int drawOffset = vidOffset >> 1;
unsigned int y, bmp;
for (y = 0; y < 16; y ++) {
bmp = buf[y + (BUF_WSTRIDE * plane)];
WVID[drawOffset] = (bmp << 8) | (bmp >> 8);
drawOffset += stride >> 1;
}
}
void loadTiles(unsigned int tilesOffset, unsigned int far *memTiles) { void loadTiles(unsigned int tilesOffset, unsigned int far *memTiles) {
int i, plane;
screen.tilesOffset = tilesOffset; screen.tilesOffset = tilesOffset;
screen.memTiles = memTiles; screen.memTiles = memTiles;
setWriteMode(0);
for (plane = 0; plane < 4; plane ++) {
unsigned int drawOffset = tilesOffset >> 1;
setPlane(plane);
for (i = 0; i < NUM_TILES; i ++) {
unsigned int y, bmp;
unsigned int far *buf = &memTiles[(i * BUF_WSIZE) + (BUF_WSTRIDE * plane)];
for (y = 0; y < 16; y ++) {
bmp = buf[y];
WVID[drawOffset ++] = (bmp << 8) | (bmp >> 8);
}
}
}
setAllPlanes();
} }
void loadMap(unsigned char *map, unsigned int w, unsigned int h) { void loadMap(unsigned char *map, unsigned int w, unsigned int h) {
@ -187,16 +213,6 @@ void scroll(int newX, int newY) {
screen.scrollY = newY; screen.scrollY = newY;
} }
void paintBufferPlane(unsigned int *buf, unsigned int vidOffset, int stride, int plane) {
unsigned int drawOffset = vidOffset >> 1;
unsigned int y, bmp;
for (y = 0; y < 16; y ++) {
bmp = buf[y + (BUF_WSTRIDE * plane)];
WVID[drawOffset] = (bmp << 8) | (bmp >> 8);
drawOffset += stride >> 1;
}
}
void paintBuffer(unsigned int *buf, unsigned int vidOffset) { void paintBuffer(unsigned int *buf, unsigned int vidOffset) {
int plane; int plane;
setWriteMode(0); setWriteMode(0);

BIN
tiles.gfx Executable file

Binary file not shown.