Revamped the screen example

This commit is contained in:
neauoire 2021-04-09 12:15:38 -07:00
parent ffded2f642
commit d6036dec6b
7 changed files with 129 additions and 39 deletions

View File

@ -32,7 +32,7 @@ else
fi
echo "Assembling.."
./bin/assembler projects/examples/gui.shapes.usm bin/boot.rom
./bin/assembler projects/examples/dev.screen.usm bin/boot.rom
echo "Running.."
if [ "${2}" = '--cli' ];

View File

@ -11,7 +11,7 @@
|0140 ;Keys { key 1 }
|0150 ;Mouse { x 2 y 2 state 1 chord 1 }
|0160 ;File { pad 8 name 2 length 2 load 2 save 2 }
|0180 ;Audio { wave 2 envelope 2 pad 4 volume 1 pitch 1 play 1 value 2 delay 2 finish 1 }
|0130 ;Audio { wave 2 envelope 2 pad 4 volume 1 pitch 1 play 1 value 2 delay 2 finish 1 }
|01a0 ;DateTime { year 2 month 1 day 1 hour 1 minute 1 second 1 dotw 1 doty 2 isdst 1 refresh 1 }
|01F0 ;System { pad 8 r 2 g 2 b 2 }

View File

@ -33,7 +33,7 @@
|0150 ;Keys { vector 2 key 1 }
|0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 }
|0170 ;File { pad 8 name 2 length 2 load 2 save 2 }
|0180 ;Audio { wave 2 envelope 2 pad 4 volume 1 pitch 1 play 1 value 2 delay 2 finish 1 }
|0130 ;Audio { wave 2 envelope 2 pad 4 volume 1 pitch 1 play 1 value 2 delay 2 finish 1 }
( vectors )

View File

@ -15,6 +15,7 @@
;label { x 2 y 2 addr 2 }
;slider { x1 2 y 2 x2 2 pos 2 }
;selection { byte 1 }
;addr { short 2 }
;theme {
r1 1 r2 1 r3 1 r4 1
g1 1 g2 1 g3 1 g4 1
@ -32,7 +33,7 @@
( theme ) #127f =System.r #34e7 =System.g #56c4 =System.b
( vectors ) ,on-mouse =Mouse.vector
#00a0 =window.w
#00b0 =window.w
#0050 =window.h
( center window )
@ -64,19 +65,19 @@ BRK
~Mouse.y ~window.y1 SUB2 STEP8
DUP2 #0010 NEQ2 ^$no-touch-red JNZ
~Mouse.x ~window.x1 #0050 ADD2 LTH2 ^$no-touch-red JNZ
~Mouse.x ~window.x1 #008c ADD2 GTH2 ^$no-touch-red JNZ
( get new value ) ~Mouse.x ~window.x1 SUB2 #0050 SUB2 #0004 DIV2 S2B ,theme.r1 #00 ~selection ADD2 POK2
~Mouse.x ~window.x1 #0060 ADD2 LTH2 ^$no-touch-red JNZ
~Mouse.x ~window.x1 #009c ADD2 GTH2 ^$no-touch-red JNZ
( get new value ) ~Mouse.x ~window.x1 SUB2 #0060 SUB2 #0004 DIV2 S2B ,theme.r1 #00 ~selection ADD2 POK2
$no-touch-red
DUP2 #0020 NEQ2 ^$no-touch-green JNZ
~Mouse.x ~window.x1 #0050 ADD2 LTH2 ^$no-touch-green JNZ
~Mouse.x ~window.x1 #008c ADD2 GTH2 ^$no-touch-green JNZ
( get new value ) ~Mouse.x ~window.x1 SUB2 #0050 SUB2 #0004 DIV2 S2B ,theme.g1 #00 ~selection ADD2 POK2
~Mouse.x ~window.x1 #0060 ADD2 LTH2 ^$no-touch-green JNZ
~Mouse.x ~window.x1 #009c ADD2 GTH2 ^$no-touch-green JNZ
( get new value ) ~Mouse.x ~window.x1 SUB2 #0060 SUB2 #0004 DIV2 S2B ,theme.g1 #00 ~selection ADD2 POK2
$no-touch-green
DUP2 #0030 NEQ2 ^$no-touch-blue JNZ
~Mouse.x ~window.x1 #0050 ADD2 LTH2 ^$no-touch-blue JNZ
~Mouse.x ~window.x1 #008c ADD2 GTH2 ^$no-touch-blue JNZ
( get new value ) ~Mouse.x ~window.x1 SUB2 #0050 SUB2 #0004 DIV2 S2B ,theme.b1 #00 ~selection ADD2 POK2
~Mouse.x ~window.x1 #0060 ADD2 LTH2 ^$no-touch-blue JNZ
~Mouse.x ~window.x1 #009c ADD2 GTH2 ^$no-touch-blue JNZ
( get new value ) ~Mouse.x ~window.x1 SUB2 #0060 SUB2 #0004 DIV2 S2B ,theme.b1 #00 ~selection ADD2 POK2
$no-touch-blue
DUP2 #0040 NEQ2 ^$no-touch-radio JNZ
~Mouse.x ~window.x1 #0050 ADD2 LTH2 ^$no-touch-radio JNZ
@ -129,13 +130,54 @@ RTN
POP2 POP2
( draw blending modes )
#0000 =Screen.x #0020 =Screen.y ,icon_icn =Screen.addr
#20 #30
$draw-blends
( move ) OVR #00 SWP #0008 MUL2 =Screen.x
,preview_icn =Screen.addr
#0010 =Screen.y
#00 #08
$draw-pixel1
( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
( draw ) OVR =Screen.color
( incr ) SWP #01 ADD SWP
DUP2 LTH ^$draw-blends JNZ
DUP2 LTH ^$draw-pixel1 JNZ
POP POP
#0018 =Screen.y
#00 #08
$draw-pixel2
( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
( draw ) OVR #08 ADD =Screen.color
( incr ) SWP #01 ADD SWP
DUP2 LTH ^$draw-pixel2 JNZ
POP POP
#0020 =Screen.y
#00 #08
$draw-icn1
( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
( draw ) OVR #20 ADD =Screen.color
( incr ) SWP #01 ADD SWP
DUP2 LTH ^$draw-icn1 JNZ
POP POP
#0028 =Screen.y
#00 #08
$draw-icn2
( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
( draw ) OVR #28 ADD =Screen.color
( incr ) SWP #01 ADD SWP
DUP2 LTH ^$draw-icn2 JNZ
POP POP
#0030 =Screen.y
#00 #08
$draw-chr1
( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
( draw ) OVR #40 ADD =Screen.color
( incr ) SWP #01 ADD SWP
DUP2 LTH ^$draw-chr1 JNZ
POP POP
#0038 =Screen.y
#00 #08
$draw-chr2
( move ) OVR #00 SWP #0008 MUL2 #0010 ADD2 =Screen.x
( draw ) OVR #48 ADD =Screen.color
( incr ) SWP #01 ADD SWP
DUP2 LTH ^$draw-chr2 JNZ
POP POP
RTN
@ -149,12 +191,20 @@ RTN
~window.x1 #0002 SUB2 ~window.y1 #0002 SUB2 ~window.x2 #0002 ADD2 ~window.y2 #0002 ADD2 #01 ,line-rect JSR2
~window.x1 #0008 ADD2 ~window.y1 #0010 ADD2 #25 ,red_txt ,draw-label JSR2
~window.x1 #0008 ADD2 ~window.y1 #0020 ADD2 #25 ,green_txt ,draw-label JSR2
~window.x1 #0008 ADD2 ~window.y1 #0030 ADD2 #25 ,blue_txt ,draw-label JSR2
~window.x1 #0038 ADD2 ~window.y1 #0010 ADD2 #28 ,System.r ,draw-byte JSR2
~window.x1 #0048 ADD2 ~window.y1 #0010 ADD2 #28 ,System.r #0001 ADD2 ,draw-byte JSR2
~window.x1 #0050 ADD2 ~window.y1 #0010 ADD2 ~window.x1 #0080 ADD2 #00 ,theme.r1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
~window.x1 #0050 ADD2 ~window.y1 #0020 ADD2 ~window.x1 #0080 ADD2 #00 ,theme.g1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
~window.x1 #0050 ADD2 ~window.y1 #0030 ADD2 ~window.x1 #0080 ADD2 #00 ,theme.b1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
~window.x1 #0008 ADD2 ~window.y1 #0020 ADD2 #25 ,green_txt ,draw-label JSR2
~window.x1 #0038 ADD2 ~window.y1 #0020 ADD2 #28 ,System.g ,draw-byte JSR2
~window.x1 #0048 ADD2 ~window.y1 #0020 ADD2 #28 ,System.g #0001 ADD2 ,draw-byte JSR2
~window.x1 #0008 ADD2 ~window.y1 #0030 ADD2 #25 ,blue_txt ,draw-label JSR2
~window.x1 #0038 ADD2 ~window.y1 #0030 ADD2 #28 ,System.b ,draw-byte JSR2
~window.x1 #0048 ADD2 ~window.y1 #0030 ADD2 #28 ,System.b #0001 ADD2 ,draw-byte JSR2
~window.x1 #0060 ADD2 ~window.y1 #0010 ADD2 ~window.x1 #0090 ADD2 #00 ,theme.r1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
~window.x1 #0060 ADD2 ~window.y1 #0020 ADD2 ~window.x1 #0090 ADD2 #00 ,theme.g1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
~window.x1 #0060 ADD2 ~window.y1 #0030 ADD2 ~window.x1 #0090 ADD2 #00 ,theme.b1 ~selection ADD PEK2 #0004 MUL2 #01 ,draw-slider JSR2
~window.x1 #0050 ADD2 =Screen.x
~window.y1 #0040 ADD2 =Screen.y
@ -178,7 +228,7 @@ RTN
RTN
@draw-cursor
@draw-cursor ( -- )
( clear last cursor )
,clear_icn =Screen.addr
@ -193,11 +243,11 @@ RTN
,pointer_icn =Screen.addr
~pointer.x =Screen.x
~pointer.y =Screen.y
#33 =Screen.color
#33 ~Mouse.state #00 NEQ #02 MUL SUB =Screen.color
RTN
@draw-slider ( x1 y x2 pos color )
@draw-slider ( x1 y x2 pos color -- )
( load ) =color =slider.pos =slider.x2 =slider.y =slider.x1
@ -224,7 +274,7 @@ RTN
RTN
@fill-rect ( x1 y1 x2 y2 color )
@fill-rect ( x1 y1 x2 y2 color -- )
( load ) =color =rect.y2 =rect.x2 DUP2 =Screen.y =rect.y1 DUP2 =Screen.x =rect.x1
$ver
@ -238,7 +288,7 @@ RTN
RTN
@line-rect ( x1 y1 x2 y2 color )
@line-rect ( x1 y1 x2 y2 color -- )
( load ) =color =rect.y2 =rect.x2 DUP2 =Screen.y =rect.y1 DUP2 =Screen.x =rect.x1
$hor
@ -255,7 +305,7 @@ RTN
RTN
@draw-label ( x y color addr )
@draw-label ( x y color addr -- )
( load ) =label.addr =color =Screen.y =Screen.x ~label.addr
$loop
@ -267,6 +317,19 @@ RTN
RTN
@draw-byte ( x y color addr -- )
=addr STH
=Screen.y
=Screen.x
,font_hex #00 ~addr PEK2 #04 SFT #0008 MUL2 ADD2 =Screen.addr
STHr DUP STH =Screen.color
,font_hex #00 ~addr PEK2 #0f AND #0008 MUL2 ADD2 =Screen.addr
~Screen.x 8+ =Screen.x
STHr =Screen.color
RTN
@clear_icn [ 0000 0000 0000 0000 ]
@pointer_icn [ 80c0 e0f0 f8e0 1000 ]
@halftone_icn [ aa55 aa55 aa55 aa55 ]
@ -274,7 +337,7 @@ RTN
@sliderb_icn [ ffff ffff ffff ffff ]
@sliderc_icn [ fcfe ffff ffff fefc ]
@sliderd_icn [ 003c 7e7e 7e7e 3c00 ]
@icon_icn [ 3c7e e7c3 c3e7 7e3c ]
@preview_icn [ 183c 66db db66 3c18 0000 183c 3c18 0000 ]
@radio_icns
[ 3c42 8181 8181 423c ]
[ 3c42 99bd bd99 423c ]
@ -283,6 +346,18 @@ RTN
@green_txt [ Green 00 ]
@blue_txt [ Blue 00 ]
@font_hex ( 0-F TODO: should pull from @font instead.. )
[
003c 464a 5262 3c00 0018 0808 0808 1c00
003c 4202 3c40 7e00 003c 421c 0242 3c00
000c 1424 447e 0400 007e 407c 0242 3c00
003c 407c 4242 3c00 007e 0204 0810 1000
003c 423c 4242 3c00 003c 4242 3e02 3c00
003c 4242 7e42 4200 007c 427c 4242 7c00
003c 4240 4042 3c00 007c 4242 4242 7c00
007e 4078 4040 7e00 007e 4078 4040 4000
]
@font ( spectrum-zx font )
[
0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000

View File

@ -215,10 +215,11 @@ screen_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)
Uint16 y = mempeek16(u, ptr + 10);
Uint8 *addr = &u->ram.dat[mempeek16(u, ptr + 12)];
Uint8 *layer = (b1 >> 4 & 0xf) % 2 ? ppu.fg : ppu.bg;
if((b1 >> 4 & 0xf) / 2)
putsprite(&ppu, layer, x, y, addr, b1 & 0xf);
else
putpixel(&ppu, layer, x, y, b1 & 0xf);
switch((b1 >> 4) / 2) {
case 0: putpixel(&ppu, layer, x, y, b1 & 0x3); break;
case 1: puticn(&ppu, layer, x, y, addr, b1 & 0xf); break;
case 2: putchr(&ppu, layer, x, y, addr, b1 & 0xf); break;
}
reqdraw = 1;
}
return b1;
@ -384,13 +385,12 @@ main(int argc, char **argv)
devsystem = portuxn(&u, 0x00, "system", system_poke);
portuxn(&u, 0x01, "console", console_poke);
devscreen = portuxn(&u, 0x02, "screen", screen_poke);
portuxn(&u, 0x03, "---", ppnil);
devapu = portuxn(&u, 0x03, "audio", audio_poke);
devctrl = portuxn(&u, 0x04, "controller", ppnil);
devkey = portuxn(&u, 0x05, "key", ppnil);
devmouse = portuxn(&u, 0x06, "mouse", ppnil);
portuxn(&u, 0x07, "file", file_poke);
devapu = portuxn(&u, 0x08, "audio", audio_poke);
apu.channel_addr = devapu->addr + 0xa;
portuxn(&u, 0x03, "---", ppnil);
portuxn(&u, 0x09, "midi", ppnil);
portuxn(&u, 0x0a, "datetime", datetime_poke);
portuxn(&u, 0x0b, "---", ppnil);
@ -399,6 +399,8 @@ main(int argc, char **argv)
portuxn(&u, 0x0e, "---", ppnil);
portuxn(&u, 0x0f, "---", ppnil);
apu.channel_addr = devapu->addr + 0xa;
/* Write screen size to dev/screen */
mempoke16(&u, devscreen->addr + 2, ppu.hor * 8);
mempoke16(&u, devscreen->addr + 4, ppu.ver * 8);

View File

@ -110,7 +110,7 @@ putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color)
}
void
putsprite(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
puticn(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
{
Uint16 v, h;
for(v = 0; v < 8; v++)
@ -122,6 +122,18 @@ putsprite(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
}
}
void
putchr(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color)
{
Uint16 v, h;
for(v = 0; v < 8; v++)
for(h = 0; h < 8; h++) {
Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1) * color;
Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1) * color;
putpixel(p, layer, x + h, y + v, (ch1 - ch2 + color / 4) & 0x3);
}
}
void
getcolors(Ppu *p, Uint8 *addr)
{

View File

@ -27,4 +27,5 @@ void drawppu(Ppu *p);
void drawdebugger(Ppu *p, Uint8 *stack, Uint8 ptr);
void getcolors(Ppu *p, Uint8 *addr);
void putpixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color);
void putsprite(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color);
void puticn(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color);
void putchr(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color);