portrait editor

This commit is contained in:
Jeremy Penner 2020-01-13 16:52:56 -05:00
parent 643645307b
commit 71b45c35ef
8 changed files with 143 additions and 50 deletions

BIN
game.exe

Binary file not shown.

BIN
game.prj

Binary file not shown.

View file

@ -24,7 +24,8 @@ array preview 128 allot
i 3 % 2 * 65 + i 3 / 16 * preview paintbuf i 3 % 2 * 65 + i 3 / 16 * preview paintbuf
next ; next ;
: mousepos>sprpos 3 >> swap 3 >> swap ; : mousecoord>sprcoord 2 edittarget = if 2 else 3 then >> ;
: mousepos>sprpos mousecoord>sprcoord swap mousecoord>sprcoord swap ;
: mousexys mousepos mousepos>sprpos spriteindex @ ; : mousexys mousepos mousepos>sprpos spriteindex @ ;
: mousepixel! ( color -- ) : mousepixel! ( color -- )
@ -35,13 +36,13 @@ array preview 128 allot
: gfxfilename : gfxfilename
0 edittarget = if 0 edittarget = if
s" sprite.gfx" s" sprite.gfx"
else else 1 edittarget = if
NIGHT flag@ if NIGHT flag@ if
s" ntiles.gfx" s" ntiles.gfx"
else else
s" tiles.gfx" s" tiles.gfx"
then then
then ; else s" portrait.gfx" then then ;
var jiles-old-tick var jiles-old-tick
var jiles-old-draw var jiles-old-draw
@ -74,7 +75,7 @@ var copysrc
^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 gfxfilename dup 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 ^T key-pressed if edittarget 1 + 3 % edittarget! 0 +sprite! then
^C key-pressed if spriteindex @ copysrc ! then ^C key-pressed if spriteindex @ copysrc ! then
^V key-pressed if copysrc @ spriteindex @ paste-tile refresh then ^V key-pressed if copysrc @ spriteindex @ paste-tile refresh then
^F key-pressed if spriteindex @ flip-tile refresh then ^F key-pressed if spriteindex @ flip-tile refresh then
@ -86,7 +87,7 @@ var copysrc
^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 reloadtiles load-footer mousehide unfuck invalidate-map reloadtiles reloadportraits load-footer
then then
tick-debounce tick-debounce
; ;

BIN
portrait.gfx Executable file

Binary file not shown.

Binary file not shown.

141
testbed.c
View file

@ -84,31 +84,37 @@ size_t freadfar(FILE *fp, void far *buf, size_t length) {
} }
/*** S C R A T C H ***/ /*** S C R A T C H ***/
#define PORTRAIT_GFX
#define NUM_SPRITES 64 #define NUM_SPRITES 64
#define TILE_STRIDE 64 #define TILE_STRIDE 64
#define SPRITE_STRIDE 80 #define SPRITE_STRIDE 80
#define PORTRAIT_STRIDE 256
unsigned int far *tiles; unsigned int far *tiles;
unsigned int far *sprites; unsigned int far *sprites;
unsigned int far *portraits;
unsigned char map[10000]; unsigned char map[10000];
void deallocate_gfx() { void deallocate_gfx() {
if (tiles) farfree(tiles); if (tiles) farfree(tiles);
if (sprites) farfree(sprites); if (sprites) farfree(sprites);
if (portraits) farfree(portraits);
} }
void allocate_gfx() { void allocate_gfx() {
unsigned long memleft = farcoreleft(); unsigned long memleft = farcoreleft();
tiles = farmalloc(NUM_TILES * TILE_STRIDE * 2); tiles = farmalloc(NUM_TILES * TILE_STRIDE * 2);
sprites = farmalloc(NUM_SPRITES * SPRITE_STRIDE * 2); sprites = farmalloc(NUM_SPRITES * SPRITE_STRIDE * 2);
portraits = farmalloc(NUM_PORTRAITS * PORTRAIT_STRIDE * 2);
atexit(deallocate_gfx); atexit(deallocate_gfx);
if (!tiles || !sprites) { if (!tiles || !sprites || !portraits) {
printf("%lu bytes free - need %lu\n", memleft, printf("%lu bytes free - need %lu\n", memleft,
(unsigned long) (unsigned long)
((NUM_TILES * TILE_STRIDE) + ((NUM_TILES * TILE_STRIDE * 2) +
(NUM_SPRITES * SPRITE_STRIDE))); (NUM_SPRITES * SPRITE_STRIDE * 2) +
(NUM_PORTRAITS * PORTRAIT_STRIDE * 2)));
exit(1); exit(1);
} }
} }
@ -153,8 +159,6 @@ void f_loadtiles() {
DROP(1); DROP(1);
} }
#define TILES_GFX
void f_load_footer() { void f_load_footer() {
FILE *f = fopen("FOOTER.TIF", "rb"); FILE *f = fopen("FOOTER.TIF", "rb");
TifImageMeta_t meta = tifLoadMeta(f); TifImageMeta_t meta = tifLoadMeta(f);
@ -162,6 +166,10 @@ void f_load_footer() {
fclose(f); fclose(f);
} }
void f_reloadportraits() {
blitMemToVid(OFF_PORTRAITS, portraits, PORTRAIT_STRIDE >> 2, NUM_PORTRAITS);
}
void game_init() { void game_init() {
FILE *f; FILE *f;
TifImageMeta_t meta; TifImageMeta_t meta;
@ -186,17 +194,21 @@ void game_init() {
freadfar(f, sprites, NUM_SPRITES * SPRITE_STRIDE * 2); freadfar(f, sprites, NUM_SPRITES * SPRITE_STRIDE * 2);
fclose(f); fclose(f);
#ifdef PORTRAIT_GFX
f = fopen("portrait.gfx", "rb");
freadfar(f, portraits, NUM_PORTRAITS * PORTRAIT_STRIDE * 2);
fclose(f);
f_reloadportraits();
#else
f = fopen("PORTRAIT.TIF", "rb"); f = fopen("PORTRAIT.TIF", "rb");
meta = tifLoadMeta(f); meta = tifLoadMeta(f);
tifLoad(f, meta, portraits, NUM_PORTRAITS * 32, 32, 4);
tifLoadEGA(f, meta, OFF_PORTRAITS, NUM_PORTRAITS * 32, 32); tifLoadEGA(f, meta, OFF_PORTRAITS, NUM_PORTRAITS * 32, 32);
fclose(f); fclose(f);
#ifdef TILES_GFX
readTiles("tiles.gfx");
#else
readTifTiles("TILES.TIF");
#endif #endif
readTiles("tiles.gfx");
loadMap(map, 100, 100); loadMap(map, 100, 100);
scroll(0, 0); scroll(0, 0);
} }
@ -321,25 +333,39 @@ void f_glitch() {
typedef enum { typedef enum {
ET_SPRITE = 0, ET_SPRITE = 0,
ET_TILE = 1 ET_TILE = 1,
ET_PORTRAIT = 2
} EditTarget_t; } EditTarget_t;
EditTarget_t editTarget = ET_SPRITE; EditTarget_t editTarget = ET_SPRITE;
unsigned int far *getTarget(int index) { unsigned int far *getTarget(int index) {
if (editTarget == ET_SPRITE) { if (editTarget == ET_SPRITE) {
return &sprites[index * SPRITE_STRIDE]; return &sprites[index * SPRITE_STRIDE];
} else { } else if (editTarget == ET_TILE) {
return &tiles[index * TILE_STRIDE]; return &tiles[index * TILE_STRIDE];
} else {
return &portraits[index * PORTRAIT_STRIDE];
} }
} }
#define ET_STRIDE (editTarget == ET_SPRITE ? SPRITE_STRIDE : \
(editTarget == ET_TILE ? TILE_STRIDE : PORTRAIT_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 % 16));
int b = (spr[y + 0] & (1 << shift)) >> shift; int plane_stride = 16;
int g = (spr[y + 16] & (1 << shift)) >> shift; int b, g, r, i, v;
int r = (spr[y + 32] & (1 << shift)) >> shift; if (editTarget == ET_PORTRAIT) {
int i = (spr[y + 48] & (1 << shift)) >> shift; y = y << 1;
int v = editTarget != ET_SPRITE || (spr[y + 64] & (1 << shift)) ? 0 : 1; if (x > 15) y ++;
plane_stride = 64;
}
spr += y;
b = (*spr & (1 << shift)) >> shift; spr += plane_stride;
g = (*spr & (1 << shift)) >> shift; spr += plane_stride;
r = (*spr & (1 << shift)) >> shift; spr += plane_stride;
i = (*spr & (1 << shift)) >> shift; spr += plane_stride;
v = editTarget != ET_SPRITE || (*spr & (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;
@ -367,12 +393,30 @@ void drawFatBox(int x, int y, int color) {
} }
} }
void drawDoubleFatBox(int x, int y, int colorl, int colorr) {
int faty, plane;
unsigned int dst = (SCREEN_STRIDE * y) + x;
setResetEnabledCached(0);
for ( plane = 0; plane < 4; plane ++ ) {
int fill = colorr & ( 1 << plane ) ? 0x0f : 0x00;
fill |= colorl & ( 1 << plane ) ? 0xf0 : 0x00;
setPlane( plane );
for ( faty = 0; faty < 4; faty ++ ) {
VID[dst + (SCREEN_STRIDE * faty)] = fill;
}
}
}
void f_drawfatsprite() { void f_drawfatsprite() {
int isprite = TOP().i; int isprite = TOP().i;
unsigned int far *spr = getTarget(isprite); unsigned int far *spr = getTarget(isprite);
int x, y; int x, y;
DROP(1); DROP(1);
if (editTarget != ET_PORTRAIT) {
setAllPlanes(); setAllPlanes();
for ( y = 0; y < 16; y ++ ) { for ( y = 0; y < 16; y ++ ) {
for ( x = 0; x < 16; x ++ ) { for ( x = 0; x < 16; x ++ ) {
@ -380,6 +424,16 @@ void f_drawfatsprite() {
drawFatBox(x, y << 3, color); drawFatBox(x, y << 3, color);
} }
} }
} else {
for ( y = 0; y < 32; y ++ ) {
for ( x = 0; x < 32; x += 2 ) {
int colorl = getsprpixel( x, y, spr);
int colorr = getsprpixel(x + 1, y, spr);
drawDoubleFatBox(x >> 1, y << 2, colorl, colorr);
}
}
setAllPlanes();
}
} }
void f_drawfatbox() { void f_drawfatbox() {
@ -391,8 +445,10 @@ void f_savegfx() {
FILE *fp = fopen(TOP().s, "wb"); FILE *fp = fopen(TOP().s, "wb");
if (editTarget == ET_SPRITE) { if (editTarget == ET_SPRITE) {
fwritefar(fp, sprites, NUM_SPRITES * SPRITE_STRIDE * 2); fwritefar(fp, sprites, NUM_SPRITES * SPRITE_STRIDE * 2);
} else { } else if (editTarget == ET_TILE) {
fwritefar(fp, tiles, NUM_TILES * TILE_STRIDE * 2); fwritefar(fp, tiles, NUM_TILES * TILE_STRIDE * 2);
} else {
fwritefar(fp, portraits, NUM_PORTRAITS * PORTRAIT_STRIDE * 2);
} }
fclose(fp); fclose(fp);
DROP(1); DROP(1);
@ -421,24 +477,32 @@ void f_putpixel() {
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;
int plane_stride = 16;
DROP(3); DROP(3);
color = TOP().i; color = TOP().i;
DROP(1); DROP(1);
shift = (15 - x); shift = (15 - (x % 16));
if (editTarget == ET_PORTRAIT) {
y = y << 1;
if (x > 15) y ++;
plane_stride = 64;
}
b = (color & 0x01); b = (color & 0x01);
g = (color & 0x02) >> 1; g = (color & 0x02) >> 1;
r = (color & 0x04) >> 2; r = (color & 0x04) >> 2;
i = (color & 0x08) >> 3; i = (color & 0x08) >> 3;
v = ((color & 0x10) >> 4) ^ 1; v = ((color & 0x10) >> 4) ^ 1;
spr = &spr[y];
spr[y + 0] = (spr[y + 0] & ~(1 << shift)) | (b << shift); *spr = (*spr & ~(1 << shift)) | (b << shift); spr += plane_stride;
spr[y + 16] = (spr[y + 16] & ~(1 << shift)) | (g << shift); *spr = (*spr & ~(1 << shift)) | (g << shift); spr += plane_stride;
spr[y + 32] = (spr[y + 32] & ~(1 << shift)) | (r << shift); *spr = (*spr & ~(1 << shift)) | (r << shift); spr += plane_stride;
spr[y + 48] = (spr[y + 48] & ~(1 << shift)) | (i << shift); *spr = (*spr & ~(1 << shift)) | (i << shift); spr += plane_stride;
if (editTarget == ET_SPRITE) { if (editTarget == ET_SPRITE) {
spr[y + 64] = (spr[y + 64] & ~(1 << shift)) | (v << shift); *spr = (*spr & ~(1 << shift)) | (v << shift);
} }
} }
@ -455,8 +519,10 @@ void f_getpixel() {
void f_spritecount() { void f_spritecount() {
if (editTarget == ET_SPRITE) { if (editTarget == ET_SPRITE) {
PUSHI(NUM_SPRITES); PUSHI(NUM_SPRITES);
} else { } else if (editTarget == ET_TILE) {
PUSHI(NUM_TILES); PUSHI(NUM_TILES);
} else if (editTarget == ET_PORTRAIT) {
PUSHI(NUM_PORTRAITS);
} }
} }
@ -484,14 +550,11 @@ void f_remap_spr2buf() {
} }
void f_pastetile() { void f_pastetile() {
unsigned int far *src; unsigned int far *src = getTarget(ST1().i);
unsigned int far *dst; unsigned int far *dst = getTarget(TOP().i);
unsigned int far *gfx = editTarget == ET_SPRITE ? sprites : tiles; unsigned int stride = ET_STRIDE;
unsigned int stride = editTarget == ET_SPRITE ? SPRITE_STRIDE : TILE_STRIDE;
unsigned int i; unsigned int i;
src = &gfx[ST1().i * stride];
dst = &gfx[TOP().i * stride];
DROP(2); DROP(2);
for (i = 0; i < stride; i ++) { for (i = 0; i < stride; i ++) {
dst[i] = src[i]; dst[i] = src[i];
@ -499,13 +562,11 @@ void f_pastetile() {
} }
void f_fliptile() { void f_fliptile() {
unsigned int far *dst; unsigned int far *dst = getTarget(TOP().i);
unsigned int far *gfx = editTarget == ET_SPRITE ? sprites : tiles; unsigned int stride = ET_STRIDE;
unsigned int stride = editTarget == ET_SPRITE ? SPRITE_STRIDE : TILE_STRIDE;
unsigned int i; unsigned int i;
unsigned int bit; unsigned int bit;
dst = &gfx[TOP().i * stride];
DROP(1); DROP(1);
for (i = 0; i < stride; i ++) { for (i = 0; i < stride; i ++) {
unsigned int src = dst[i]; unsigned int src = dst[i];
@ -515,9 +576,15 @@ void f_fliptile() {
result |= (1 << (15 - bit)); result |= (1 << (15 - bit));
} }
} }
if (editTarget == ET_PORTRAIT && ((i % 2) == 1)) {
bit = dst[i - 1];
dst[i - 1] = result;
dst[i] = bit;
} else {
dst[i] = result; dst[i] = result;
} }
} }
}
void f_vfliptile() { void f_vfliptile() {
unsigned int far *dst; unsigned int far *dst;
@ -526,6 +593,7 @@ void f_vfliptile() {
unsigned int y; unsigned int y;
unsigned int plane; unsigned int plane;
if (editTarget == ET_PORTRAIT) return; // TODO
dst = &gfx[TOP().i * stride]; dst = &gfx[TOP().i * stride];
DROP(1); DROP(1);
for (plane = 0; plane < (editTarget == ET_SPRITE ? 5 : 4); plane ++) { for (plane = 0; plane < (editTarget == ET_SPRITE ? 5 : 4); plane ++) {
@ -621,6 +689,7 @@ void game_f_init(char *exe, char *bootjor) {
CDEF("edittarget", f_getedittarget); CDEF("edittarget", f_getedittarget);
CDEF("edittarget!", f_setedittarget); CDEF("edittarget!", f_setedittarget);
CDEF("reloadtiles", f_reloadtiles); CDEF("reloadtiles", f_reloadtiles);
CDEF("reloadportraits", f_reloadportraits);
CDEF("paste-tile", f_pastetile); CDEF("paste-tile", f_pastetile);
CDEF("flip-tile", f_fliptile); CDEF("flip-tile", f_fliptile);
CDEF("vflip-tile", f_vfliptile); CDEF("vflip-tile", f_vfliptile);

22
tiles.c
View file

@ -53,6 +53,28 @@ void blit32x32(unsigned int offsetFrom, unsigned int offsetTo) {
} }
} }
void blitMemToVid(unsigned int offset, unsigned int far *mem, unsigned int planeStride, int count) {
int i, j, plane;
offset = offset >> 1; // word aligned
setWriteMode(0);
for (i = 0; i < count; i ++) {
for (plane = 0; plane < 4; plane ++) {
unsigned int drawOffset = offset;
unsigned int bmp;
setPlane(plane);
for (j = 0; j < planeStride; j ++) {
bmp = mem[j];
WVID[drawOffset + j] = (bmp << 8) | (bmp >> 8);
}
mem += planeStride;
}
offset += planeStride;
}
setAllPlanes();
}
#define D_NOTHING 0x80 #define D_NOTHING 0x80
#define D_BGTILE 0x81 #define D_BGTILE 0x81
#define isBufIndex(d) (!((d) & 0x80)) #define isBufIndex(d) (!((d) & 0x80))

View file

@ -11,6 +11,7 @@ void scroll(int newX, int newY);
void drawScreen(); void drawScreen();
void blit32x32(unsigned int offsetFrom, unsigned int offsetTo); void blit32x32(unsigned int offsetFrom, unsigned int offsetTo);
void blitMemToVid(unsigned int offset, unsigned int far *mem, unsigned int planeStride, int count);
void writeTile(unsigned int *buf, unsigned int far *tile); void writeTile(unsigned int *buf, unsigned int far *tile);
void overlaySprite(unsigned int *buf, unsigned int far *sprite, int shift, int yStart, char *remap); void overlaySprite(unsigned int *buf, unsigned int far *sprite, int shift, int yStart, char *remap);