add colour & sprite selection
This commit is contained in:
parent
0c1a4c0539
commit
09750d0472
10
defs.jor
10
defs.jor
|
@ -65,7 +65,17 @@
|
|||
: max ( x y -- x|y ) 2dup < if swap then drop ;
|
||||
|
||||
: +!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 -- )
|
||||
create here 4 cells + , latest , tasks , ,
|
||||
does> dup @ here!
|
||||
|
|
41
jiles.jor
41
jiles.jor
|
@ -17,29 +17,46 @@ input.jor loadfile
|
|||
var color
|
||||
var spriteindex
|
||||
|
||||
8 spriteindex !
|
||||
2 color !
|
||||
var refresh-needed
|
||||
: refresh 1 refresh-needed ! ;
|
||||
|
||||
: color! dup color @ = if drop else color ! refresh then ;
|
||||
: +sprite! spriteindex spritecount +!cycle refresh ;
|
||||
|
||||
: refresh
|
||||
mousehide spriteindex @ drawfatsprite mouseshow ;
|
||||
: draw-palette 0 0x11 for i 79 i 3 << drawfatbox next ;
|
||||
|
||||
: mousepos>sprpos 3 >> swap 3 >> swap ;
|
||||
: mousexys mousepos mousepos>sprpos spriteindex @ ;
|
||||
: tick
|
||||
MOUSEL mousedown if
|
||||
mousexys getpixel color @ != if
|
||||
color @ mousexys putpixel
|
||||
refresh
|
||||
mousepos 128 < swap 128 < and if
|
||||
MOUSEL mousedown if
|
||||
mousexys getpixel color @ != if
|
||||
color @ mousexys putpixel
|
||||
refresh
|
||||
then
|
||||
then
|
||||
MOUSER clicked if
|
||||
mousexys getpixel color!
|
||||
then
|
||||
then
|
||||
MOUSER clicked if
|
||||
mousexys getpixel color !
|
||||
mousepos 136 < swap 312 >= and if
|
||||
mousepos swap drop 3 >>
|
||||
MOUSEL mousedown if color! else drop then
|
||||
then
|
||||
^LEFT key-pressed if -1 +sprite! then
|
||||
^RIGHT key-pressed if 1 +sprite! then
|
||||
tick-debounce
|
||||
;
|
||||
;
|
||||
|
||||
: draw ;
|
||||
: draw
|
||||
refresh-needed @ if
|
||||
mousehide
|
||||
spriteindex @ drawfatsprite
|
||||
color @ 78 0 drawfatbox
|
||||
draw-palette
|
||||
mouseshow
|
||||
0 refresh-needed !
|
||||
then ;
|
||||
|
||||
mouseshow
|
||||
refresh
|
||||
|
|
89
testbed.c
89
testbed.c
|
@ -265,60 +265,71 @@ void f_glitch() {
|
|||
|
||||
/* JILES */
|
||||
#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 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;
|
||||
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() {
|
||||
int isprite = TOP().i;
|
||||
unsigned int dst = 0;
|
||||
unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE];
|
||||
int x, y, faty, resetEnabled;
|
||||
int x, y;
|
||||
|
||||
DROP(1);
|
||||
setWriteMode(0);
|
||||
setAllPlanes();
|
||||
setResetEnabled(0x0f);
|
||||
resetEnabled = 1;
|
||||
for ( y = 0; y < 16; y ++ ) {
|
||||
for ( x = 0; x < 16; x ++ ) {
|
||||
int color = getpixel(x, y, spr);
|
||||
int fill1 = color & 0x10 ? 0xff : 0x55;
|
||||
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;
|
||||
}
|
||||
int color = getsprpixel(x, y, spr);
|
||||
drawFatBox(x, y << 3, color);
|
||||
}
|
||||
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() {
|
||||
int isprite = TOP().i;
|
||||
unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE];
|
||||
|
@ -351,7 +362,11 @@ void f_getpixel() {
|
|||
int y = ST1().i;
|
||||
DROP(2);
|
||||
|
||||
TOP().i = getpixel(x, y, spr);
|
||||
TOP().i = getsprpixel(x, y, spr);
|
||||
}
|
||||
|
||||
void f_spritecount() {
|
||||
PUSHI(NUM_SPRITES);
|
||||
}
|
||||
|
||||
/* INIT */
|
||||
|
@ -383,8 +398,10 @@ void game_f_init(char *exe, char *bootjor) {
|
|||
CDEF("mouseshow", f_mouseshow);
|
||||
CDEF("mousehide", f_mousehide);
|
||||
CDEF("drawfatsprite", f_drawfatsprite);
|
||||
CDEF("drawfatbox", f_drawfatbox);
|
||||
CDEF("putpixel", f_putpixel);
|
||||
CDEF("getpixel", f_getpixel);
|
||||
CDEF("spritecount", f_spritecount);
|
||||
|
||||
f_loadjor(bootjor);
|
||||
|
||||
|
|
Loading…
Reference in a new issue