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
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 @ ;
: mousepixel! ( color -- )
@ -35,13 +36,13 @@ array preview 128 allot
: gfxfilename
0 edittarget = if
s" sprite.gfx"
else
else 1 edittarget = if
NIGHT flag@ if
s" ntiles.gfx"
else
s" tiles.gfx"
then
then ;
else s" portrait.gfx" then then ;
var jiles-old-tick
var jiles-old-draw
@ -74,7 +75,7 @@ var copysrc
^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 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
^V key-pressed if copysrc @ spriteindex @ paste-tile refresh then
^F key-pressed if spriteindex @ flip-tile refresh then
@ -86,7 +87,7 @@ var copysrc
^TAB key-pressed if
jiles-old-draw @ ' draw redefine
jiles-old-tick @ ' tick redefine
mousehide unfuck invalidate-map reloadtiles load-footer
mousehide unfuck invalidate-map reloadtiles reloadportraits load-footer
then
tick-debounce
;

BIN
portrait.gfx Executable file

Binary file not shown.

Binary file not shown.

157
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 ***/
#define PORTRAIT_GFX
#define NUM_SPRITES 64
#define TILE_STRIDE 64
#define SPRITE_STRIDE 80
#define PORTRAIT_STRIDE 256
unsigned int far *tiles;
unsigned int far *sprites;
unsigned int far *portraits;
unsigned char map[10000];
void deallocate_gfx() {
if (tiles) farfree(tiles);
if (sprites) farfree(sprites);
if (tiles) farfree(tiles);
if (sprites) farfree(sprites);
if (portraits) farfree(portraits);
}
void allocate_gfx() {
unsigned long memleft = farcoreleft();
tiles = farmalloc(NUM_TILES * TILE_STRIDE * 2);
sprites = farmalloc(NUM_SPRITES * SPRITE_STRIDE * 2);
portraits = farmalloc(NUM_PORTRAITS * PORTRAIT_STRIDE * 2);
atexit(deallocate_gfx);
if (!tiles || !sprites) {
if (!tiles || !sprites || !portraits) {
printf("%lu bytes free - need %lu\n", memleft,
(unsigned long)
((NUM_TILES * TILE_STRIDE) +
(NUM_SPRITES * SPRITE_STRIDE)));
((NUM_TILES * TILE_STRIDE * 2) +
(NUM_SPRITES * SPRITE_STRIDE * 2) +
(NUM_PORTRAITS * PORTRAIT_STRIDE * 2)));
exit(1);
}
}
@ -153,8 +159,6 @@ void f_loadtiles() {
DROP(1);
}
#define TILES_GFX
void f_load_footer() {
FILE *f = fopen("FOOTER.TIF", "rb");
TifImageMeta_t meta = tifLoadMeta(f);
@ -162,6 +166,10 @@ void f_load_footer() {
fclose(f);
}
void f_reloadportraits() {
blitMemToVid(OFF_PORTRAITS, portraits, PORTRAIT_STRIDE >> 2, NUM_PORTRAITS);
}
void game_init() {
FILE *f;
TifImageMeta_t meta;
@ -186,17 +194,21 @@ void game_init() {
freadfar(f, sprites, NUM_SPRITES * SPRITE_STRIDE * 2);
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");
meta = tifLoadMeta(f);
tifLoad(f, meta, portraits, NUM_PORTRAITS * 32, 32, 4);
tifLoadEGA(f, meta, OFF_PORTRAITS, NUM_PORTRAITS * 32, 32);
fclose(f);
#ifdef TILES_GFX
readTiles("tiles.gfx");
#else
readTifTiles("TILES.TIF");
#endif
readTiles("tiles.gfx");
loadMap(map, 100, 100);
scroll(0, 0);
}
@ -321,25 +333,39 @@ void f_glitch() {
typedef enum {
ET_SPRITE = 0,
ET_TILE = 1
ET_TILE = 1,
ET_PORTRAIT = 2
} EditTarget_t;
EditTarget_t editTarget = ET_SPRITE;
unsigned int far *getTarget(int index) {
if (editTarget == ET_SPRITE) {
return &sprites[index * SPRITE_STRIDE];
} else {
} else if (editTarget == ET_TILE) {
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 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 = editTarget != ET_SPRITE || (spr[y + 64] & (1 << shift)) ? 0 : 1;
int shift = (15 - (x % 16));
int plane_stride = 16;
int b, g, r, i, v;
if (editTarget == ET_PORTRAIT) {
y = y << 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);
}
int resetEnabledCache = 0;
@ -367,18 +393,46 @@ 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() {
int isprite = TOP().i;
unsigned int far *spr = getTarget(isprite);
int x, y;
DROP(1);
setAllPlanes();
for ( y = 0; y < 16; y ++ ) {
for ( x = 0; x < 16; x ++ ) {
int color = getsprpixel(x, y, spr);
drawFatBox(x, y << 3, color);
if (editTarget != ET_PORTRAIT) {
setAllPlanes();
for ( y = 0; y < 16; y ++ ) {
for ( x = 0; x < 16; x ++ ) {
int color = getsprpixel(x, y, spr);
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();
}
}
@ -391,8 +445,10 @@ void f_savegfx() {
FILE *fp = fopen(TOP().s, "wb");
if (editTarget == ET_SPRITE) {
fwritefar(fp, sprites, NUM_SPRITES * SPRITE_STRIDE * 2);
} else {
} else if (editTarget == ET_TILE) {
fwritefar(fp, tiles, NUM_TILES * TILE_STRIDE * 2);
} else {
fwritefar(fp, portraits, NUM_PORTRAITS * PORTRAIT_STRIDE * 2);
}
fclose(fp);
DROP(1);
@ -421,24 +477,32 @@ void f_putpixel() {
int x = ST2().i;
int y = ST1().i;
int color, shift, b, g, r, i, v;
int plane_stride = 16;
DROP(3);
color = TOP().i;
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);
g = (color & 0x02) >> 1;
r = (color & 0x04) >> 2;
i = (color & 0x08) >> 3;
v = ((color & 0x10) >> 4) ^ 1;
spr = &spr[y];
spr[y + 0] = (spr[y + 0] & ~(1 << shift)) | (b << shift);
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);
*spr = (*spr & ~(1 << shift)) | (b << shift); spr += plane_stride;
*spr = (*spr & ~(1 << shift)) | (g << shift); spr += plane_stride;
*spr = (*spr & ~(1 << shift)) | (r << shift); spr += plane_stride;
*spr = (*spr & ~(1 << shift)) | (i << shift); spr += plane_stride;
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() {
if (editTarget == ET_SPRITE) {
PUSHI(NUM_SPRITES);
} else {
} else if (editTarget == ET_TILE) {
PUSHI(NUM_TILES);
} else if (editTarget == ET_PORTRAIT) {
PUSHI(NUM_PORTRAITS);
}
}
@ -484,14 +550,11 @@ void f_remap_spr2buf() {
}
void f_pastetile() {
unsigned int far *src;
unsigned int far *dst;
unsigned int far *gfx = editTarget == ET_SPRITE ? sprites : tiles;
unsigned int stride = editTarget == ET_SPRITE ? SPRITE_STRIDE : TILE_STRIDE;
unsigned int far *src = getTarget(ST1().i);
unsigned int far *dst = getTarget(TOP().i);
unsigned int stride = ET_STRIDE;
unsigned int i;
src = &gfx[ST1().i * stride];
dst = &gfx[TOP().i * stride];
DROP(2);
for (i = 0; i < stride; i ++) {
dst[i] = src[i];
@ -499,13 +562,11 @@ void f_pastetile() {
}
void f_fliptile() {
unsigned int far *dst;
unsigned int far *gfx = editTarget == ET_SPRITE ? sprites : tiles;
unsigned int stride = editTarget == ET_SPRITE ? SPRITE_STRIDE : TILE_STRIDE;
unsigned int far *dst = getTarget(TOP().i);
unsigned int stride = ET_STRIDE;
unsigned int i;
unsigned int bit;
dst = &gfx[TOP().i * stride];
DROP(1);
for (i = 0; i < stride; i ++) {
unsigned int src = dst[i];
@ -515,7 +576,13 @@ void f_fliptile() {
result |= (1 << (15 - bit));
}
}
dst[i] = result;
if (editTarget == ET_PORTRAIT && ((i % 2) == 1)) {
bit = dst[i - 1];
dst[i - 1] = result;
dst[i] = bit;
} else {
dst[i] = result;
}
}
}
@ -526,6 +593,7 @@ void f_vfliptile() {
unsigned int y;
unsigned int plane;
if (editTarget == ET_PORTRAIT) return; // TODO
dst = &gfx[TOP().i * stride];
DROP(1);
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_setedittarget);
CDEF("reloadtiles", f_reloadtiles);
CDEF("reloadportraits", f_reloadportraits);
CDEF("paste-tile", f_pastetile);
CDEF("flip-tile", f_fliptile);
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_BGTILE 0x81
#define isBufIndex(d) (!((d) & 0x80))

View file

@ -11,6 +11,7 @@ void scroll(int newX, int newY);
void drawScreen();
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 overlaySprite(unsigned int *buf, unsigned int far *sprite, int shift, int yStart, char *remap);