Compare commits

...

3 Commits

Author SHA1 Message Date
Nico d03e373f28 add more test files 2021-11-07 19:54:47 +00:00
Nico 4f5319db11 use as a viewer 2021-11-07 19:54:35 +00:00
Nico 2ca7b61c84 things 2021-11-07 19:14:52 +00:00
6 changed files with 238 additions and 24 deletions

View File

@ -189,4 +189,4 @@ wormlet,games
xobox,games
xworld,games
zxbox,viewers
varvara,apps
varvara,viewers

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,177 @@
( dev/screen )
%RTN { JMP2r }
%2/ { #01 SFT }
%4/ { #02 SFT }
( devices )
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
( variables )
|0000
@count $2
@center
&x $2 &y $2
( init )
|0100 ( -> )
( vector )
;on-frame .Screen/vector DEO2
( theme )
#f07f .System/r DEO2
#f0e0 .System/g DEO2
#f0c0 .System/b DEO2
( find screen center )
.Screen/width DEI2 #01 SFT2 #0020 SUB2 .center/x STZ2
.Screen/height DEI2 #01 SFT2 .center/y STZ2
( draw )
;draw-table JSR2
;draw-sprites JSR2
;draw-1bpp JSR2
;draw-2bpp JSR2
;draw-pixels JSR2
BRK
@on-frame ( -> )
.count LDZ2 INC2 [ DUP2 ] .count STZ2
.center/x LDZ2 #0048 ADD2 .Screen/x DEO2
.center/y LDZ2 #0050 SUB2 .Screen/y DEO2
( color ) #01 STH
SWP
DUP #04 SFT [ #00 SWP ] #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
( draw ) STHkr .Screen/sprite DEO
#0f AND [ #00 SWP ] #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
( draw ) STHkr .Screen/sprite DEO
DUP #04 SFT [ #00 SWP ] #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
( draw ) STHkr .Screen/sprite DEO
#0f AND [ #00 SWP ] #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
( draw ) STHr .Screen/sprite DEO
BRK
@draw-table ( -- )
#10 #00
&loop
DUP #30 SFT #00 SWP ;font-hex ADD2 .Screen/addr DEO2
( x-axis )
DUP #30 SFT #00 SWP
.center/x LDZ2 #0040 SUB2 ADD2 .Screen/x DEO2
.center/y LDZ2 #0050 SUB2 .Screen/y DEO2
( draw ) #01 .Screen/sprite DEO
( y-axis )
DUP #30 SFT #00 SWP
.center/y LDZ2 #0040 SUB2 ADD2 .Screen/y DEO2
.center/x LDZ2 #0050 SUB2 .Screen/x DEO2
( draw ) #01 .Screen/sprite DEO
INC GTHk ,&loop JCN
POP2
RTN
@draw-sprites ( -- )
;preview_icn .Screen/addr DEO2
#00 #00
&loop
( move ) DUP #0f AND #40 SFT 2/ #00 SWP
.center/x LDZ2 #0040 SUB2 ADD2 .Screen/x DEO2
( move ) DUP #f0 AND 2/ #00 SWP
.center/y LDZ2 #0040 SUB2 ADD2 .Screen/y DEO2
( draw ) DUP .Screen/sprite DEO
INC NEQk ,&loop JCN
POP2
RTN
@draw-1bpp ( -- )
#10 #00
&loop
( color ) STHk
( y ) DUP 4/ [ #00 SWP ] #40 SFT2
[ .center/y LDZ2 #0040 SUB2 ADD2 ] STH2
( x ) DUP #03 AND [ #00 SWP ] #40 SFT2 #0040 ADD2
[ .center/x LDZ2 #0008 ADD2 ADD2 ]
STH2r STHr #00 ;draw-circle JSR2
INC GTHk ,&loop JCN
POP2
RTN
@draw-2bpp ( -- )
#10 #00
&loop
( color ) STHk
( y ) DUP 4/ [ #00 SWP ] #40 SFT2
[ .center/y LDZ2 ADD2 ] STH2
( x ) DUP #03 AND [ #00 SWP ] #40 SFT2 #0040 ADD2
[ .center/x LDZ2 #0008 ADD2 ADD2 ]
STH2r STHr #80 ;draw-circle JSR2
INC GTHk ,&loop JCN
POP2
RTN
@draw-circle ( x* y* color depth -- )
ADD STH
;preview_icn .Screen/addr DEO2
.Screen/y DEO2
.Screen/x DEO2
#00 STHkr ADD .Screen/sprite DEO
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
#10 STHkr ADD .Screen/sprite DEO
.Screen/x DEI2 #0008 SUB2 .Screen/x DEO2
.Screen/y DEI2 #0008 ADD2 .Screen/y DEO2
#20 STHkr ADD .Screen/sprite DEO
.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
#30 STHr ADD .Screen/sprite DEO
RTN
@draw-pixels ( -- )
.center/y LDZ2 #0040 SUB2 .Screen/y DEO2
.center/x LDZ2 #0048 ADD2 .Screen/x DEO2
#00 .Screen/pixel DEO
.center/x LDZ2 #0049 ADD2 .Screen/x DEO2
#01 .Screen/pixel DEO
.center/x LDZ2 #004a ADD2 .Screen/x DEO2
#02 .Screen/pixel DEO
.center/x LDZ2 #004b ADD2 .Screen/x DEO2
#03 .Screen/pixel DEO
RTN
@preview_icn [
0f38 675f dfbf bfbf 0007 1820 2344 4848
@font-hex
007c 8282 8282 827c 0030 1010 1010 1010
007c 8202 7c80 80fe 007c 8202 1c02 827c
000c 1424 4484 fe04 00fe 8080 7c02 827c
007c 8280 fc82 827c 007c 8202 1e02 0202
007c 8282 7c82 827c 007c 8282 7e02 827c
007c 8202 7e82 827e 00fc 8282 fc82 82fc
007c 8280 8080 827c 00fc 8282 8282 82fc
007c 8280 f080 827c 007c 8280 f080 8080

View File

@ -10,7 +10,7 @@ copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
TODO proper support for greyscale displays
TODO optimise support for greyscale/1-bit displays
TODO rom loading
TODO other varvara devices
TODO clean up
@ -306,6 +306,9 @@ unsigned int palette[3];
static Uint8 framebuffer[LCD_HEIGHT * LCD_WIDTH * 4];
static fb_data *lcd_fb = NULL;
static unsigned long starttick;
static void
memzero8(void *src, uint64_t n)
{
@ -443,18 +446,35 @@ nil_talk(Device *d, Uint8 b0, Uint8 w)
return 1;
}
// TODO mono, greyscale
// TODO mono and greyscale that don't suck
static void redraw(void)
{
if (!lcd_fb)
{
struct viewport *vp_main = rb->lcd_set_viewport(NULL);
lcd_fb = vp_main->buffer->fb_ptr;
}
for(int y = 0 ; y < LCD_WIDTH*LCD_HEIGHT; y++ ) {
lcd_fb[y] = palette[ppu_read(&ppu, y%LCD_WIDTH, y/LCD_HEIGHT)];
}
rb->lcd_update();
#if LCD_DEPTH > 4
if (!lcd_fb)
{
struct viewport *vp_main = rb->lcd_set_viewport(NULL);
lcd_fb = vp_main->buffer->fb_ptr;
}
for(int i = 0 ; i < LCD_WIDTH*LCD_HEIGHT; i++ ) {
Uint32 row = i / 2;
Uint8 shift = !(i & 0x1) << 2;
Uint8 pix = framebuffer[row] >> shift;
if(pix & 0x0c)
pix = pix >> 2;
lcd_fb[i] = palette[pix & 0x3];
}
rb->lcd_update();
#else
rb->lcd_clear_display();
for(Uint16 x = 0; x < LCD_WIDTH; x++ ) {
for(Uint16 y = 0; y < LCD_HEIGHT; y++ ) {
if(palette[ppu_read(&ppu, x, y)]) {
rb->lcd_drawpixel(x, y);
}
}
}
rb->lcd_update();
#endif
ppu.reqdraw = 0;
}
@ -468,6 +488,7 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id)
// TODO fix timing
static void run() {
starttick = *rb->current_tick;
while(!devsystem->dat[0xf]) {
uxn_eval(&u, devscreen->vector);
if(ppu.reqdraw || devsystem->dat[0xe])
@ -513,6 +534,9 @@ static void run() {
uxn_eval(&u, peek16(devctrl->dat, 0));
}
if((*rb->current_tick - starttick)<HZ/60) {
rb->sleep(*rb->current_tick - starttick);
}
}
}
@ -520,18 +544,31 @@ static void run() {
enum plugin_status plugin_start(const void* parameter)
{
(void)parameter;
DEBUGF("Setting PPU size\n");
ppu_init(&ppu, LCD_WIDTH, LCD_HEIGHT, framebuffer);
DEBUGF("UXN init\n");
// Clear RAM and copy rom to VM.
DEBUGF("zeroing\n");
if(!parameter) {
rb->splash(HZ, "Please open a .rom file using this plugin!");
return PLUGIN_ERROR;
}
DEBUGF("zeroing\n");
memzero8(&u, sizeof(Uxn));
DEBUGF("copying ROM\n");
memcpy(u.ram.dat + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom));
DEBUGF("registering ports\n");
DEBUGF("loading ROM\n");
char* filename = (char*) parameter;
int fd = rb->open(filename, O_RDONLY);
if (fd < 0) {
rb->splash(HZ, "File Error");
return PLUGIN_ERROR;
}
int numread = rb->read(fd, u.ram.dat + PAGE_PROGRAM, 65536-PAGE_PROGRAM);
if (numread==-1) {
rb->splash(HZ, "I/O Error");
return PLUGIN_ERROR;
}
rb->close(fd);
ppu_init(&ppu, LCD_WIDTH, LCD_HEIGHT, framebuffer);
// Register ports
/* system */ devsystem = uxn_port(&u, 0x0, system_talk);
/* console */ devconsole = uxn_port(&u, 0x1, console_talk);
@ -549,7 +586,6 @@ enum plugin_status plugin_start(const void* parameter)
/* empty */ uxn_port(&u, 0xd, nil_talk);
/* empty */ uxn_port(&u, 0xe, nil_talk);
/* empty */ uxn_port(&u, 0xf, nil_talk);
DEBUGF("eval\n");
uxn_eval(&u, 0x0100);
run();
return PLUGIN_OK;

View File

@ -103,3 +103,4 @@ z7,viewers/frotz,-
z8,viewers/frotz,-
shopper,viewers/shopper,1
lnk,viewers/windows_lnk,-
rom,viewers/varvara,-