save edited sprites to disk and use them in-game
This commit is contained in:
parent
09750d0472
commit
e630e20d46
BIN
sprite.gfx
Executable file
BIN
sprite.gfx
Executable file
Binary file not shown.
48
testbed.c
48
testbed.c
|
@ -50,6 +50,38 @@ void text_draw(unsigned int vidOffset, unsigned char *s) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*** I / O ***/
|
||||||
|
size_t fwritefar(FILE *fp, void far *buf, size_t length) {
|
||||||
|
char nearbuf[32];
|
||||||
|
size_t written = 0;
|
||||||
|
size_t towrite;
|
||||||
|
|
||||||
|
for (; towrite = min(32, length), length > 0; length -= towrite) {
|
||||||
|
movedata(FP_SEG(buf), FP_OFF(buf) + written, _SS, nearbuf, towrite);
|
||||||
|
if (!fwrite(nearbuf, towrite, 1, fp)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
written += towrite;
|
||||||
|
}
|
||||||
|
return written;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t freadfar(FILE *fp, void far *buf, size_t length) {
|
||||||
|
char nearbuf[32];
|
||||||
|
size_t totalread = 0;
|
||||||
|
size_t toread;
|
||||||
|
|
||||||
|
for (; toread = min(32, length), length > 0; length -= toread) {
|
||||||
|
size_t bytesread = fread(nearbuf, 1, toread, fp);
|
||||||
|
movedata(_SS, nearbuf, FP_SEG(buf), FP_OFF(buf) + totalread, bytesread);
|
||||||
|
totalread += bytesread;
|
||||||
|
if (bytesread != toread) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return totalread;
|
||||||
|
}
|
||||||
|
|
||||||
/*** S C R A T C H ***/
|
/*** S C R A T C H ***/
|
||||||
|
|
||||||
#define NUM_SPRITES 64
|
#define NUM_SPRITES 64
|
||||||
|
@ -109,6 +141,8 @@ void f_loadtiles() {
|
||||||
DROP(1);
|
DROP(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SPRITE_GFX
|
||||||
|
|
||||||
void game_init() {
|
void game_init() {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
TifImageMeta_t meta;
|
TifImageMeta_t meta;
|
||||||
|
@ -132,10 +166,16 @@ 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");
|
||||||
|
freadfar(f, sprites, NUM_SPRITES * SPRITE_STRIDE * 2);
|
||||||
|
fclose(f);
|
||||||
|
#else
|
||||||
f = fopen("SPRITE.TIF", "rb");
|
f = fopen("SPRITE.TIF", "rb");
|
||||||
meta = tifLoadMeta(f);
|
meta = tifLoadMeta(f);
|
||||||
tifLoad(f, meta, sprites, NUM_SPRITES * 16, 16, 5);
|
tifLoad(f, meta, sprites, NUM_SPRITES * 16, 16, 5);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
#endif
|
||||||
|
|
||||||
f = fopen("PORTRAIT.TIF", "rb");
|
f = fopen("PORTRAIT.TIF", "rb");
|
||||||
meta = tifLoadMeta(f);
|
meta = tifLoadMeta(f);
|
||||||
|
@ -319,6 +359,13 @@ void f_drawfatbox() {
|
||||||
DROP(3);
|
DROP(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void f_savegfx() {
|
||||||
|
FILE *fp;
|
||||||
|
fp = fopen("sprite.gfx", "wb");
|
||||||
|
fwritefar(fp, sprites, NUM_SPRITES * SPRITE_STRIDE * 2);
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
void f_mousehide() {
|
void f_mousehide() {
|
||||||
mouse_hide();
|
mouse_hide();
|
||||||
}
|
}
|
||||||
|
@ -402,6 +449,7 @@ void game_f_init(char *exe, char *bootjor) {
|
||||||
CDEF("putpixel", f_putpixel);
|
CDEF("putpixel", f_putpixel);
|
||||||
CDEF("getpixel", f_getpixel);
|
CDEF("getpixel", f_getpixel);
|
||||||
CDEF("spritecount", f_spritecount);
|
CDEF("spritecount", f_spritecount);
|
||||||
|
CDEF("savegfx", f_savegfx);
|
||||||
|
|
||||||
f_loadjor(bootjor);
|
f_loadjor(bootjor);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue