add background tile editing & saving
This commit is contained in:
parent
ca1abba60b
commit
b1a71e3e35
|
@ -21,8 +21,8 @@ s" timer.jor" loadfile
|
|||
s" entity.jor" loadfile
|
||||
s" footer.jor" loadfile
|
||||
s" map.jor" loadfile
|
||||
s" jiles.jor" loadfile
|
||||
s" state.jor" loadfile
|
||||
s" jiles.jor" loadfile
|
||||
s" game.jor" loadfile
|
||||
; execute
|
||||
|
||||
|
|
21
jiles.jor
21
jiles.jor
|
@ -15,8 +15,12 @@ array preview 128 allot
|
|||
|
||||
: draw-preview
|
||||
0 18 for
|
||||
0 edittarget = if
|
||||
i preview tile>buf
|
||||
spriteindex @ preview spr>buf
|
||||
else
|
||||
spriteindex @ preview tile>buf
|
||||
then
|
||||
i 3 % 2 * 65 + i 3 / 16 * preview paintbuf
|
||||
next ;
|
||||
|
||||
|
@ -28,12 +32,24 @@ array preview 128 allot
|
|||
r@ mousexys putpixel refresh
|
||||
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-draw
|
||||
|
||||
44 const ^Z
|
||||
45 const ^X
|
||||
31 const ^S
|
||||
20 const ^T
|
||||
|
||||
: jiles-tick
|
||||
mousepos 128 < swap 128 < and if
|
||||
|
@ -49,11 +65,12 @@ var jiles-old-draw
|
|||
^RIGHT key-pressed if 1 +sprite! then
|
||||
^Z key-pressed if mousexys getpixel lcolor 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
|
||||
jiles-old-draw @ ' draw redefine
|
||||
jiles-old-tick @ ' tick redefine
|
||||
mousehide unfuck invalidate-map
|
||||
mousehide unfuck invalidate-map reloadtiles
|
||||
then
|
||||
tick-debounce
|
||||
;
|
||||
|
|
BIN
ntiles.gfx
Executable file
BIN
ntiles.gfx
Executable file
Binary file not shown.
|
@ -16,8 +16,8 @@ array flags FLAG-COUNT 8 / 1 + allot
|
|||
: setflag 1 swap flagsf! ;
|
||||
: clearflag 0 swap flagsf! ;
|
||||
|
||||
: day s" TILES.TIF" loadtiles invalidate-map NIGHT clearflag ;
|
||||
: night s" NTILES.TIF" loadtiles invalidate-map NIGHT setflag ;
|
||||
: day s" tiles.gfx" loadtiles invalidate-map NIGHT clearflag ;
|
||||
: night s" ntiles.gfx" loadtiles invalidate-map NIGHT setflag ;
|
||||
|
||||
: {car-drive} NIGHT flag@ if {car-lit} else {car} then ;
|
||||
|
||||
|
|
90
testbed.c
90
testbed.c
|
@ -2,6 +2,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <dos.h>
|
||||
#include <alloc.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "video.h"
|
||||
#include "kbd.h"
|
||||
|
@ -123,25 +124,36 @@ void fillMap() {
|
|||
}
|
||||
}
|
||||
|
||||
void readTiles(char *filename) {
|
||||
void readTifTiles(char *filename) {
|
||||
FILE *f;
|
||||
TifImageMeta_t meta;
|
||||
|
||||
f = fopen(filename, "rb");
|
||||
meta = tifLoadMeta(f);
|
||||
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);
|
||||
|
||||
loadTiles(OFF_TILES, tiles);
|
||||
}
|
||||
|
||||
void f_loadtiles() {
|
||||
if (tolower(TOP().s[strlen(TOP().s) - 1]) == 'f') {
|
||||
readTifTiles(TOP().s);
|
||||
} else {
|
||||
readTiles(TOP().s);
|
||||
}
|
||||
DROP(1);
|
||||
}
|
||||
|
||||
#define SPRITE_GFX
|
||||
#define TILES_GFX
|
||||
|
||||
void game_init() {
|
||||
FILE *f;
|
||||
|
@ -166,23 +178,20 @@ void game_init() {
|
|||
tifLoadEGA(f, meta, 0, 48, 336);
|
||||
fclose(f);
|
||||
|
||||
#ifdef SPRITE_GFX
|
||||
f = fopen("sprite.gfx", "rb");
|
||||
freadfar(f, sprites, NUM_SPRITES * SPRITE_STRIDE * 2);
|
||||
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");
|
||||
meta = tifLoadMeta(f);
|
||||
tifLoadEGA(f, meta, OFF_PORTRAITS, NUM_PORTRAITS * 32, 32);
|
||||
fclose(f);
|
||||
|
||||
readTiles("TILES.TIF");
|
||||
#ifdef TILES_GFX
|
||||
readTiles("tiles.gfx");
|
||||
#else
|
||||
readTifTiles("TILES.TIF");
|
||||
#endif
|
||||
|
||||
loadMap(map, 100, 100);
|
||||
scroll(0, 0);
|
||||
|
@ -306,13 +315,27 @@ void f_glitch() {
|
|||
/* JILES */
|
||||
#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 shift = (15 - x);
|
||||
int b = (spr[y + 0] & (1 << shift)) >> shift;
|
||||
int g = (spr[y + 16] & (1 << shift)) >> shift;
|
||||
int r = (spr[y + 32] & (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);
|
||||
}
|
||||
int resetEnabledCache = 0;
|
||||
|
@ -342,7 +365,7 @@ void drawFatBox(int x, int y, int color) {
|
|||
|
||||
void f_drawfatsprite() {
|
||||
int isprite = TOP().i;
|
||||
unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE];
|
||||
unsigned int far *spr = getTarget(isprite);
|
||||
int x, y;
|
||||
|
||||
DROP(1);
|
||||
|
@ -361,10 +384,14 @@ void f_drawfatbox() {
|
|||
}
|
||||
|
||||
void f_savegfx() {
|
||||
FILE *fp;
|
||||
fp = fopen("sprite.gfx", "wb");
|
||||
FILE *fp = fopen(TOP().s, "wb");
|
||||
if (editTarget == ET_SPRITE) {
|
||||
fwritefar(fp, sprites, NUM_SPRITES * SPRITE_STRIDE * 2);
|
||||
} else {
|
||||
fwritefar(fp, tiles, NUM_TILES * TILE_STRIDE * 2);
|
||||
}
|
||||
fclose(fp);
|
||||
DROP(1);
|
||||
}
|
||||
|
||||
void f_mousehide() {
|
||||
|
@ -386,7 +413,7 @@ void f_resetvideo() {
|
|||
|
||||
void f_putpixel() {
|
||||
int isprite = TOP().i;
|
||||
unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE];
|
||||
unsigned int far *spr = getTarget(isprite);
|
||||
int x = ST2().i;
|
||||
int y = ST1().i;
|
||||
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 + 32] = (spr[y + 32] & ~(1 << shift)) | (r << shift);
|
||||
spr[y + 48] = (spr[y + 48] & ~(1 << shift)) | (i << shift);
|
||||
if (editTarget == ET_SPRITE) {
|
||||
spr[y + 64] = (spr[y + 64] & ~(1 << shift)) | (v << shift);
|
||||
}
|
||||
}
|
||||
|
||||
void f_getpixel() {
|
||||
int isprite = TOP().i;
|
||||
unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE];
|
||||
unsigned int far *spr = getTarget(isprite);
|
||||
int x = ST2().i;
|
||||
int y = ST1().i;
|
||||
DROP(2);
|
||||
|
@ -420,29 +449,45 @@ void f_getpixel() {
|
|||
}
|
||||
|
||||
void f_spritecount() {
|
||||
if (editTarget == ET_SPRITE) {
|
||||
PUSHI(NUM_SPRITES);
|
||||
} else {
|
||||
PUSHI(NUM_TILES);
|
||||
}
|
||||
}
|
||||
|
||||
void f_tile2buf() {
|
||||
unsigned int *buf = TOP().p;
|
||||
unsigned int *buf = (unsigned int *)TOP().p;
|
||||
unsigned int itile = ST1().u;
|
||||
DROP(2);
|
||||
writeTile(buf, &tiles[itile * TILE_STRIDE]);
|
||||
}
|
||||
|
||||
void f_spr2buf() {
|
||||
unsigned int *buf = TOP().p;
|
||||
unsigned int *buf = (unsigned int *)TOP().p;
|
||||
unsigned int isprite = ST1().u;
|
||||
DROP(2);
|
||||
overlaySprite(buf, &sprites[isprite * SPRITE_STRIDE], 0, 0);
|
||||
}
|
||||
|
||||
void f_paintbuf() {
|
||||
unsigned int *buf = TOP().p;
|
||||
unsigned int *buf = (unsigned int *)TOP().p;
|
||||
int y = ST1().i;
|
||||
int x = ST2().i;
|
||||
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 */
|
||||
|
@ -483,6 +528,9 @@ void game_f_init(char *exe, char *bootjor) {
|
|||
CDEF("tile>buf", f_tile2buf);
|
||||
CDEF("spr>buf", f_spr2buf);
|
||||
CDEF("paintbuf", f_paintbuf);
|
||||
CDEF("edittarget", f_getedittarget);
|
||||
CDEF("edittarget!", f_setedittarget);
|
||||
CDEF("reloadtiles", f_reloadtiles);
|
||||
|
||||
f_loadjor(bootjor);
|
||||
|
||||
|
|
36
tiles.c
36
tiles.c
|
@ -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,
|
||||
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) {
|
||||
int i, plane;
|
||||
screen.tilesOffset = tilesOffset;
|
||||
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) {
|
||||
|
@ -187,16 +213,6 @@ void scroll(int newX, int 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) {
|
||||
int plane;
|
||||
setWriteMode(0);
|
||||
|
|
Loading…
Reference in a new issue