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 ;
|
: 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!
|
||||||
|
|
31
jiles.jor
31
jiles.jor
|
@ -17,16 +17,18 @@ 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
|
||||||
|
mousepos 128 < swap 128 < and if
|
||||||
MOUSEL mousedown if
|
MOUSEL mousedown if
|
||||||
mousexys getpixel color @ != if
|
mousexys getpixel color @ != if
|
||||||
color @ mousexys putpixel
|
color @ mousexys putpixel
|
||||||
|
@ -34,12 +36,27 @@ var spriteindex
|
||||||
then
|
then
|
||||||
then
|
then
|
||||||
MOUSER clicked if
|
MOUSER clicked if
|
||||||
mousexys getpixel color !
|
mousexys getpixel color!
|
||||||
then
|
then
|
||||||
|
then
|
||||||
|
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
|
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
|
||||||
|
|
85
testbed.c
85
testbed.c
|
@ -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;
|
||||||
|
|
||||||
void f_drawfatsprite() {
|
#define setResetEnabledCached(m) \
|
||||||
int isprite = TOP().i;
|
if (resetEnabledCache != m) { \
|
||||||
unsigned int dst = 0;
|
resetEnabledCache = m; \
|
||||||
unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE];
|
setResetEnabled(m); \
|
||||||
int x, y, faty, resetEnabled;
|
}
|
||||||
|
|
||||||
DROP(1);
|
void drawFatBox(int x, int y, int color) {
|
||||||
setWriteMode(0);
|
int faty;
|
||||||
setAllPlanes();
|
int fill1 = color <= 0x0f ? 0xff : 0x55;
|
||||||
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;
|
int fill2 = fill1 == 0xff ? 0xff : 0xaa;
|
||||||
|
unsigned int dst = SCREEN_STRIDE * y;
|
||||||
|
|
||||||
if (color >= 0x0f) {
|
if (color > 0x0f) {
|
||||||
if (resetEnabled) {
|
setResetEnabledCached(0);
|
||||||
setResetEnabled(0);
|
|
||||||
resetEnabled = 0;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!resetEnabled) {
|
setResetEnabledCached(0x0f);
|
||||||
setResetEnabled(0x0f);
|
|
||||||
resetEnabled = 1;
|
|
||||||
}
|
|
||||||
setResetMask(color);
|
setResetMask(color);
|
||||||
}
|
}
|
||||||
for ( faty = 0; faty < 8; faty ++) {
|
for ( faty = 0; faty < 8; faty ++) {
|
||||||
VID[dst + x + (SCREEN_STRIDE * faty)] = (faty % 2) ? fill1 : fill2;
|
VID[dst + x + (SCREEN_STRIDE * faty)] = (faty % 2) ? fill1 : fill2;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void f_drawfatsprite() {
|
||||||
|
int isprite = TOP().i;
|
||||||
|
unsigned int far *spr = &sprites[isprite * SPRITE_STRIDE];
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
DROP(1);
|
||||||
|
for ( y = 0; y < 16; y ++ ) {
|
||||||
|
for ( x = 0; x < 16; x ++ ) {
|
||||||
|
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() {
|
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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue