add colour & sprite selection

This commit is contained in:
Jeremy Penner 2019-07-26 21:37:47 -04:00
parent 0c1a4c0539
commit 09750d0472
5 changed files with 92 additions and 48 deletions

View file

@ -65,7 +65,17 @@
: max ( x y -- x|y ) 2dup < if swap then drop ; : max ( x y -- x|y ) 2dup < if swap then drop ;
: +!pos ( n var -- ) dup @ <rot + 0 max swap ! ; : +!pos ( n var -- ) dup @ <rot + 0 max swap ! ;
: cycle! ( lim var -- )
>r dup r@ @ <= if
drop 0 r@ !
else r@ @ 0 < if
r@ !
else drop then then rdrop ;
: +!cycle ( n var lim -- )
>r >r r@ +! <r <r swap cycle! ;
over > if drop 0 else dup 0 <
: checkpoint ( cp -- ) : checkpoint ( cp -- )
create here 4 cells + , latest , tasks , , create here 4 cells + , latest , tasks , ,
does> dup @ here! does> dup @ here!

BIN
game.exe

Binary file not shown.

BIN
game.prj

Binary file not shown.

View file

@ -17,29 +17,46 @@ input.jor loadfile
var color var color
var spriteindex var spriteindex
8 spriteindex ! var refresh-needed
2 color ! : refresh 1 refresh-needed ! ;
: color! dup color @ = if drop else color ! refresh then ;
: +sprite! spriteindex spritecount +!cycle refresh ;
: refresh : draw-palette 0 0x11 for i 79 i 3 << drawfatbox next ;
mousehide spriteindex @ drawfatsprite mouseshow ;
: mousepos>sprpos 3 >> swap 3 >> swap ; : mousepos>sprpos 3 >> swap 3 >> swap ;
: mousexys mousepos mousepos>sprpos spriteindex @ ; : mousexys mousepos mousepos>sprpos spriteindex @ ;
: tick : tick
MOUSEL mousedown if mousepos 128 < swap 128 < and if
mousexys getpixel color @ != if MOUSEL mousedown if
color @ mousexys putpixel mousexys getpixel color @ != if
refresh color @ mousexys putpixel
refresh
then
then
MOUSER clicked if
mousexys getpixel color!
then then
then then
MOUSER clicked if mousepos 136 < swap 312 >= and if
mousexys getpixel color ! mousepos swap drop 3 >>
MOUSEL mousedown if color! else drop then
then then
^LEFT key-pressed if -1 +sprite! then
^RIGHT key-pressed if 1 +sprite! then
tick-debounce tick-debounce
; ;
: draw ; : draw
refresh-needed @ if
mousehide
spriteindex @ drawfatsprite
color @ 78 0 drawfatbox
draw-palette
mouseshow
0 refresh-needed !
then ;
mouseshow mouseshow
refresh refresh

View file

@ -265,60 +265,71 @@ void f_glitch() {
/* JILES */ /* JILES */
#define SCREEN_STRIDE 40 #define SCREEN_STRIDE 40
void f_mousehide() {
mouse_hide();
}
void f_mouseshow() {
setLogicalWidth(SCREEN_STRIDE >> 1);
mouse_show();
}
int getpixel(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);
int b = (spr[y + 0] & (1 << shift)) >> shift; int b = (spr[y + 0] & (1 << shift)) >> shift;
int g = (spr[y + 16] & (1 << shift)) >> shift; int g = (spr[y + 16] & (1 << shift)) >> shift;
int r = (spr[y + 32] & (1 << shift)) >> shift; int r = (spr[y + 32] & (1 << shift)) >> shift;
int i = (spr[y + 48] & (1 << shift)) >> shift; int i = (spr[y + 48] & (1 << shift)) >> shift;
return b | (g << 1) | (r << 2) | (i << 3); int v = (spr[y + 64] & (1 << shift)) ? 0 : 1;
return b | (g << 1) | (r << 2) | (i << 3) | (v << 4);
}
int resetEnabledCache = 0;
#define setResetEnabledCached(m) \
if (resetEnabledCache != m) { \
resetEnabledCache = m; \
setResetEnabled(m); \
}
void drawFatBox(int x, int y, int color) {
int faty;
int fill1 = color <= 0x0f ? 0xff : 0x55;
int fill2 = fill1 == 0xff ? 0xff : 0xaa;
unsigned int dst = SCREEN_STRIDE * y;
if (color > 0x0f) {
setResetEnabledCached(0);
} else {
setResetEnabledCached(0x0f);
setResetMask(color);
}
for ( faty = 0; faty < 8; faty ++) {
VID[dst + x + (SCREEN_STRIDE * faty)] = (faty % 2) ? fill1 : fill2;
}
} }
void f_drawfatsprite() { void f_drawfatsprite() {
int isprite = TOP().i; int isprite = TOP().i;
unsigned int dst = 0;
unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE]; unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE];
int x, y, faty, resetEnabled; int x, y;
DROP(1); DROP(1);
setWriteMode(0);
setAllPlanes();
setResetEnabled(0x0f);
resetEnabled = 1;
for ( y = 0; y < 16; y ++ ) { for ( y = 0; y < 16; y ++ ) {
for ( x = 0; x < 16; x ++ ) { for ( x = 0; x < 16; x ++ ) {
int color = getpixel(x, y, spr); int color = getsprpixel(x, y, spr);
int fill1 = color & 0x10 ? 0xff : 0x55; drawFatBox(x, y << 3, color);
int fill2 = fill1 == 0xff ? 0xff : 0xaa;
if (color >= 0x0f) {
if (resetEnabled) {
setResetEnabled(0);
resetEnabled = 0;
}
} else {
if (!resetEnabled) {
setResetEnabled(0x0f);
resetEnabled = 1;
}
setResetMask(color);
}
for ( faty = 0; faty < 8; faty ++) {
VID[dst + x + (SCREEN_STRIDE * faty)] = (faty % 2) ? fill1 : fill2;
}
} }
dst += (SCREEN_STRIDE * 8);
} }
} }
void f_drawfatbox() {
drawFatBox(ST1().i, TOP().i, ST2().i);
DROP(3);
}
void f_mousehide() {
mouse_hide();
}
void f_mouseshow() {
setLogicalWidth(SCREEN_STRIDE >> 1);
setResetEnabledCached(0);
setWriteMode(0);
setAllPlanes();
mouse_show();
}
void f_putpixel() { void f_putpixel() {
int isprite = TOP().i; int isprite = TOP().i;
unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE]; unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE];
@ -351,7 +362,11 @@ void f_getpixel() {
int y = ST1().i; int y = ST1().i;
DROP(2); DROP(2);
TOP().i = getpixel(x, y, spr); TOP().i = getsprpixel(x, y, spr);
}
void f_spritecount() {
PUSHI(NUM_SPRITES);
} }
/* INIT */ /* INIT */
@ -383,8 +398,10 @@ void game_f_init(char *exe, char *bootjor) {
CDEF("mouseshow", f_mouseshow); CDEF("mouseshow", f_mouseshow);
CDEF("mousehide", f_mousehide); CDEF("mousehide", f_mousehide);
CDEF("drawfatsprite", f_drawfatsprite); CDEF("drawfatsprite", f_drawfatsprite);
CDEF("drawfatbox", f_drawfatbox);
CDEF("putpixel", f_putpixel); CDEF("putpixel", f_putpixel);
CDEF("getpixel", f_getpixel); CDEF("getpixel", f_getpixel);
CDEF("spritecount", f_spritecount);
f_loadjor(bootjor); f_loadjor(bootjor);