Title screen

This commit is contained in:
Jeremy Penner 2020-04-07 23:20:46 -04:00
parent 89aee929eb
commit 9c91ed8230
25 changed files with 157 additions and 26 deletions

BIN
boot.jim

Binary file not shown.

BIN
debug.jim

Binary file not shown.

BIN
defs.jim

Binary file not shown.

BIN
end.jim

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
game.jim

Binary file not shown.

View file

@ -22,25 +22,12 @@ defer loadlevel
task :noname activate blah begin tick suspend again ; execute
:noname
s" debug.jor" loadfile
s" input.jor" loadfile
s" timer.jor" loadfile
s" entity.jor" loadfile
s" footer.jor" loadfile
s" map.jor" loadfile
s" state.jor" loadfile
s" jiles.jor" loadfile
s" job.jor" loadfile
s" level.jor" loadfile
s" game.jor" loadfile
s" debug.jor" loadfile
s" title.jor" loadfile
; execute
task :noname activate blah begin draw suspend again ; execute
' load-new-level checkpoint _loadlevel
' _loadlevel ' loadlevel redefine
reset-level
6 loadlevel
draw unfuck load-footer
title

BIN
input.jim

Binary file not shown.

BIN
jiles.jim

Binary file not shown.

BIN
job.jim

Binary file not shown.

BIN
lev00001.jim Executable file

Binary file not shown.

Binary file not shown.

BIN
level.jim

Binary file not shown.

BIN
map.jim

Binary file not shown.

Binary file not shown.

Binary file not shown.

20
start.jor Executable file
View file

@ -0,0 +1,20 @@
( ilevel -- )
:noname
s" map.jor" loadfile
s" state.jor" loadfile
s" jiles.jor" loadfile
s" job.jor" loadfile
s" level.jor" loadfile
s" game.jor" loadfile
; execute
task :noname activate blah begin draw suspend again ; execute
' load-new-level checkpoint _loadlevel
' _loadlevel ' loadlevel redefine
reset-level
loadlevel
draw unfuck load-footer

BIN
state.jim

Binary file not shown.

View file

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <sys/stat.h>
#include <alloc.h>
#include <ctype.h>
#include <stdlib.h>
@ -39,18 +40,18 @@ void text_init() {
font = MK_FP(fontSeg, fontOff);
}
void text_draw_char(unsigned int vidOffset, unsigned char c) {
void text_draw_char(unsigned int vidOffset, unsigned char c, int stride) {
unsigned int fontOffset = c << 3;
int i;
for (i = 0; i < 8; i ++) {
VID[vidOffset] = font[fontOffset++];
vidOffset += PAGE_STRIDE;
vidOffset += stride;
}
}
void text_draw(unsigned int vidOffset, unsigned char *s) {
while (*s) {
text_draw_char(vidOffset++, *s++);
text_draw_char(vidOffset++, *s++, PAGE_STRIDE);
}
}
@ -86,6 +87,55 @@ size_t freadfar(FILE *fp, void far *buf, size_t length) {
return totalread;
}
void freadvram(FILE *fp, unsigned int offset, size_t length) {
char nearbuf[32];
int plane;
setWriteMode(0);
for (plane = 0; plane < 4; plane ++) {
volatile char far *vmem = &VID[offset];
size_t planelen = length;
size_t toread;
setPlane(plane);
for (; toread = min(32, planelen), planelen > 0; planelen -= toread) {
size_t bytesread = fread(nearbuf, 1, toread, fp);
size_t i;
for (i = 0; i < bytesread; i +=2) {
// don't ask me why they're byteswapped :P
*vmem++ = nearbuf[i+1];
*vmem++ = nearbuf[i];
}
}
}
}
void loadscr(char *basefn) {
char fn[16];
struct stat exists;
FILE *f;
sprintf(fn, "%s.gfx", basefn);
if (stat(fn, &exists) != 0) {
TifImageMeta_t meta;
unsigned int far *buf = farmalloc(32000);
sprintf(fn, "%s.tif", basefn);
f = fopen(fn, "rb");
meta = tifLoadMeta(f);
tifLoad(f, meta, buf, 200, 200, 4);
fclose(f);
sprintf(fn, "%s.gfx", basefn);
f = fopen(fn, "wb");
fwritefar(f, buf, 32000);
fclose(f);
farfree(buf);
}
f = fopen(fn, "rb");
freadvram(f, 0, 8000);
fclose(f);
}
/*** S C R A T C H ***/
#define PORTRAIT_GFX
@ -220,10 +270,12 @@ void game_init() {
timer_init(TIMER_30HZ);
text_init();
f = fopen("TITLE.TIF", "rb");
loadscr("title");
/* f = fopen("TITLE.TIF", "rb");
meta = tifLoadMeta(f);
tifLoadEGA(f, meta, 0, 200, 320);
fclose(f);
*/
f = fopen("sprite.gfx", "rb");
freadfar(f, sprites, NUM_SPRITES * SPRITE_STRIDE * 2);
@ -300,10 +352,18 @@ void f_textc() { // ( col line c color -- )
setWriteMode(0);
setPlaneColor(TOP().u);
DROP(1);
text_draw_char(ST2().u + (ST1().u * PAGE_STRIDE), TOP().i);
text_draw_char(ST2().u + (ST1().u * PAGE_STRIDE), TOP().i, PAGE_STRIDE);
DROP(3);
}
void f_rawtextc() { // ( offset c color -- )
setWriteMode(0);
setPlaneColor(TOP().u);
DROP(1);
text_draw_char(ST1().u, TOP().i, 40);
DROP(2);
}
void f_text() { // ( col line s color -- )
setWriteMode(0);
setPlaneColor(TOP().u);
@ -369,6 +429,11 @@ void f_glitch() {
}
}
void f_loadscr() {
loadscr(TOP().s);
DROP(1);
}
/* JILES */
#define SCREEN_STRIDE 40
@ -710,9 +775,15 @@ void f_reloadtiles() {
loadTiles(OFF_TILES, tiles);
}
int DONE = 0;
static void f_quit() {
DONE = 1;
}
/* INIT */
void game_f_init(char *exe, char *bootjor) {
f_init(exe);
CDEF("quit", f_quit);
CDEF("seremit", f_seremit);
CDEF("key-pressed", f_keyWasPressed);
CDEF("key-down", f_keyIsDown);
@ -728,6 +799,7 @@ void game_f_init(char *exe, char *bootjor) {
CDEF("ticks!", f_setticks);
CDEF("text", f_text);
CDEF("textc", f_textc);
CDEF("rawtextc", f_rawtextc);
CDEF("map", f_map);
CDEF("mapsize", f_mapsize);
CDEF("mapsize!", f_mapsize_set);
@ -737,6 +809,7 @@ void game_f_init(char *exe, char *bootjor) {
CDEF("glitch", f_glitch);
CDEF("unfuck", tile_init);
CDEF("load-footer", f_load_footer);
CDEF("loadscr", f_loadscr);
CDEF("fuck", f_resetvideo);
CDEF("boss", f_showboss);
@ -780,10 +853,6 @@ void f_poll() {
}
}
int DONE = 0;
static void f_quit() {
DONE = 1;
}
void do_repl(char *exe) {
char buf[128];
@ -812,7 +881,7 @@ int main(int argc, char *argv[]) {
game_init();
game_f_init(argv[0], bootjor);
while (!keyIsDown(K_ESC)) {
while (!keyIsDown(K_F12) && !DONE) {
kbd_debounce();
f_poll();
f_taskloop();

BIN
timer.jim

Binary file not shown.

BIN
title.gfx Executable file

Binary file not shown.

BIN
title.jim Executable file

Binary file not shown.

55
title.jor Executable file
View file

@ -0,0 +1,55 @@
: titlec ( c -- )
textx @ texty @ 40 * + swap text-color @ rawtextc
1 textx +! ;
: textline ( w r m l )
textleft @ textx !
titlec <rot 1 for dup titlec next drop titlec
8 texty +! ;
: boxtop ( w -- ) 184 205 213 textline ;
: boxmid ( w -- ) 179 32 179 textline ;
: boxbot ( w -- ) 190 205 212 textline ;
: box ( w h x y -- )
texty ! textleft !
over boxtop
1 for dup boxmid next
boxbot ;
: strlen ( s -- n ) 0 swap begin dup b@ while 1 + swap 1 + swap repeat drop ;
: titles ( s -- ) begin dup b@ dup while titlec 1 + repeat drop drop ;
: optionbg ( y -- ) texty ! 20 boxmid -8 texty +! ;
: option ( s -- ) dup strlen 1 >> 19 swap - textx ! titles ;
: startgame ( n -- ) s" title" loadscr s" start.jor" loadjor ;
: menu-opts
s" New Game" :| 1 startgame |; yield
s" Continue" ' noop yield
s" Register Today!" ' noop yield
s" Quit" ' quit yield
done ;
var menu-selected
: menu-y ( i -- y ) 10 * 90 + ;
: draw-menu
0 menu-opts each drop
over menu-y optionbg
over menu-selected @ = if LCYAN else WHITE then text-color !
option
1 +
more drop ;
: exec-selected 0 menu-opts each swap drop
over menu-selected @ = if execute break else drop then
1 +
more drop ;
: menu-count 0 menu-opts each drop drop 1 + more ;
: menu-select ( di -- ) menu-selected menu-count +!cycle draw-menu ;
:noname
fuck s" title" loadscr
20 9 9 72 box
draw-menu
:| ^ENTER key-pressed if exec-selected then
^UP key-pressed if -1 menu-select then
^DOWN key-pressed if 1 menu-select then
^ESC key-pressed if quit then
|; ' tick redefine ; checkpoint title

BIN
title.tif

Binary file not shown.