mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-16 11:15:06 +00:00
Added blending modes to color
This commit is contained in:
parent
b01987b175
commit
a1bc5f3593
9 changed files with 99 additions and 70 deletions
|
@ -98,17 +98,15 @@ A device that works like a NES controller, each button is a bit from a single by
|
||||||
|
|
||||||
## TODOs
|
## TODOs
|
||||||
|
|
||||||
- LDR/STR helpers
|
|
||||||
- Line routine
|
- Line routine
|
||||||
- On-screen debugger.
|
|
||||||
- Getting rid of IOR/IOW would be nice..
|
- Getting rid of IOR/IOW would be nice..
|
||||||
- Sending from the wst to the rst, balance counter?
|
|
||||||
|
|
||||||
### Misc TODOs
|
### Misc TODOs
|
||||||
|
|
||||||
- Includes
|
- Includes
|
||||||
- Defines
|
- Defines
|
||||||
- Lint, print unused labels
|
- Print unused labels
|
||||||
|
- Blending mode
|
||||||
|
|
||||||
## Refs
|
## Refs
|
||||||
|
|
||||||
|
|
2
build.sh
2
build.sh
|
@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr
|
||||||
# cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
|
# cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator
|
||||||
|
|
||||||
# run
|
# run
|
||||||
./bin/assembler examples/paint.usm bin/boot.rom
|
./bin/assembler examples/devmouse.usm bin/boot.rom
|
||||||
./bin/emulator bin/boot.rom
|
./bin/emulator bin/boot.rom
|
||||||
|
|
15
emulator.c
15
emulator.c
|
@ -106,14 +106,13 @@ paintchr(Uint8 *dst, Uint16 x, Uint16 y, Uint8 *sprite)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
painticn(Uint8 *dst, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 fg, Uint8 alpha)
|
painticn(Uint8 *dst, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 blend)
|
||||||
{
|
{
|
||||||
Uint16 v, h;
|
Uint16 v, h;
|
||||||
for(v = 0; v < 8; v++)
|
for(v = 0; v < 8; v++)
|
||||||
for(h = 0; h < 8; h++) {
|
for(h = 0; h < 8; h++) {
|
||||||
Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1);
|
Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1);
|
||||||
if(!alpha || (alpha && ch1))
|
paintpixel(dst, x + h, y + v, ch1 ? blend % 4 : blend / 4);
|
||||||
paintpixel(dst, x + h, y + v, ch1 ? fg : 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,12 +356,12 @@ spritew(Device *d, Memory *m, Uint8 b)
|
||||||
Uint16 x = (d->mem[2] << 8) + d->mem[3];
|
Uint16 x = (d->mem[2] << 8) + d->mem[3];
|
||||||
Uint16 y = (d->mem[0] << 8) + d->mem[1];
|
Uint16 y = (d->mem[0] << 8) + d->mem[1];
|
||||||
Uint16 a = (d->mem[4] << 8) + d->mem[5];
|
Uint16 a = (d->mem[4] << 8) + d->mem[5];
|
||||||
Uint8 clr = d->mem[6] & 0xf;
|
Uint8 source = d->mem[6] >> 4 & 0xf;
|
||||||
Uint8 layer = d->mem[6] >> 4 & 0xf;
|
Uint8 *layer = source % 2 ? screen.fg : screen.bg;
|
||||||
if(clr > 7)
|
if(source / 2)
|
||||||
paintchr(layer ? screen.fg : screen.bg, x, y, &m->dat[a]);
|
paintchr(layer, x, y, &m->dat[a]);
|
||||||
else
|
else
|
||||||
painticn(layer ? screen.fg : screen.bg, x, y, &m->dat[a], clr % 4, clr > 3);
|
painticn(layer, x, y, &m->dat[a], d->mem[6] & 0xf);
|
||||||
screen.reqdraw = 1;
|
screen.reqdraw = 1;
|
||||||
d->ptr = 0;
|
d->ptr = 0;
|
||||||
}
|
}
|
||||||
|
|
46
examples/blending.usm
Normal file
46
examples/blending.usm
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
( desktop )
|
||||||
|
|
||||||
|
:dev/w fff9 ( const write port )
|
||||||
|
|
||||||
|
;x1 2 ;y1 2
|
||||||
|
|
||||||
|
;x 2 ;y 2 ;color 1
|
||||||
|
|
||||||
|
|0100 @RESET
|
||||||
|
|
||||||
|
#02 =dev/w
|
||||||
|
|
||||||
|
#01 =color
|
||||||
|
#00 ,icon #0040 #0040 ,draw-sprite JSR
|
||||||
|
#01 ,icon #0048 #0040 ,draw-sprite JSR
|
||||||
|
#02 ,icon #0050 #0040 ,draw-sprite JSR
|
||||||
|
#03 ,icon #0058 #0040 ,draw-sprite JSR
|
||||||
|
#04 ,icon #0040 #0048 ,draw-sprite JSR
|
||||||
|
#05 ,icon #0048 #0048 ,draw-sprite JSR
|
||||||
|
#06 ,icon #0050 #0048 ,draw-sprite JSR
|
||||||
|
#07 ,icon #0058 #0048 ,draw-sprite JSR
|
||||||
|
#08 ,icon #0040 #0050 ,draw-sprite JSR
|
||||||
|
#09 ,icon #0048 #0050 ,draw-sprite JSR
|
||||||
|
#0a ,icon #0050 #0050 ,draw-sprite JSR
|
||||||
|
#0b ,icon #0058 #0050 ,draw-sprite JSR
|
||||||
|
#0c ,icon #0040 #0058 ,draw-sprite JSR
|
||||||
|
#0d ,icon #0048 #0058 ,draw-sprite JSR
|
||||||
|
#0e ,icon #0050 #0058 ,draw-sprite JSR
|
||||||
|
#0f ,icon #0058 #0058 ,draw-sprite JSR
|
||||||
|
|
||||||
|
BRK
|
||||||
|
|
||||||
|
@icon [ 3c7e e7c3 c3e7 7e3c ]
|
||||||
|
|
||||||
|
@draw-sprite
|
||||||
|
IOW2 ( y byte )
|
||||||
|
IOW2 ( x byte )
|
||||||
|
IOW2 ( sprite address )
|
||||||
|
IOW ( layer-color )
|
||||||
|
RTS
|
||||||
|
|
||||||
|
|c000 @FRAME
|
||||||
|
|d000 @ERROR
|
||||||
|
|
||||||
|
|FFF0 [ f3f0 f30b f30a ] ( palette )
|
||||||
|
|FFFA .RESET .FRAME .ERROR
|
|
@ -19,6 +19,7 @@ BRK
|
||||||
DUP2 LDR IOW ( write pointer value to console )
|
DUP2 LDR IOW ( write pointer value to console )
|
||||||
#0001 ADD2 ( increment string pointer )
|
#0001 ADD2 ( increment string pointer )
|
||||||
DUP2 LDR #00 NEQ ,cliloop ROT JMP? POP2 ( while *ptr!=0 goto loop )
|
DUP2 LDR #00 NEQ ,cliloop ROT JMP? POP2 ( while *ptr!=0 goto loop )
|
||||||
|
|
||||||
RTS
|
RTS
|
||||||
|
|
||||||
@text " Hello World " ( add characters to memory )
|
@text " Hello World " ( add characters to memory )
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#02 =dev/w ( set dev/write to sprite )
|
#02 =dev/w ( set dev/write to sprite )
|
||||||
#0080 =x #0040 =y ( origin )
|
#0080 =x #0040 =y ( origin )
|
||||||
|
|
||||||
#02 ,up_icn ~x ~y ,draw-sprite JSR
|
#12 ,up_icn ~x ~y ,draw-sprite JSR
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ BRK
|
||||||
~x #0001 ADD2 =x
|
~x #0001 ADD2 =x
|
||||||
@end
|
@end
|
||||||
( redraw )
|
( redraw )
|
||||||
#03 ~sprite ~x ~y ,draw-sprite JSR
|
#13 ~sprite ~x ~y ,draw-sprite JSR
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ RTS
|
||||||
IOW2 ( y byte )
|
IOW2 ( y byte )
|
||||||
IOW2 ( x byte )
|
IOW2 ( x byte )
|
||||||
IOW2 ( sprite address )
|
IOW2 ( sprite address )
|
||||||
#08 IOW ( layer-color )
|
#20 IOW ( layer-color )
|
||||||
RTS
|
RTS
|
||||||
|
|
||||||
@clear_icn [ 0000 0000 0000 0000 ]
|
@clear_icn [ 0000 0000 0000 0000 ]
|
||||||
|
|
|
@ -1,61 +1,46 @@
|
||||||
( hello world )
|
( desktop )
|
||||||
|
|
||||||
:dev/w fff9 ( const write port )
|
:dev/w fff9 ( const write port )
|
||||||
|
|
||||||
|
;x1 2 ;y1 2
|
||||||
|
|
||||||
;x 2 ;y 2 ;color 1
|
;x 2 ;y 2 ;color 1
|
||||||
|
|
||||||
|0100 @RESET
|
|0100 @RESET
|
||||||
|
|
||||||
( print to console )
|
#02 =dev/w
|
||||||
,string ,displaycli JSR
|
|
||||||
|
|
||||||
( print to screen )
|
|
||||||
#0008 =x #0030 =y #01 =color
|
|
||||||
,string ,displaygui JSR
|
|
||||||
#0010 =x #0038 =y #02 =color
|
|
||||||
,string ,displaygui JSR
|
|
||||||
#0018 =x #0040 =y #03 =color
|
|
||||||
,string ,displaygui JSR
|
|
||||||
|
|
||||||
|
#01 =color
|
||||||
|
,text #0020 #0030 ,draw-label JSR
|
||||||
|
#02 =color
|
||||||
|
,text #0022 #0038 ,draw-label JSR
|
||||||
|
#03 =color
|
||||||
|
,text #0024 #0040 ,draw-label JSR
|
||||||
|
#04 =color
|
||||||
|
,text #0026 #0048 ,draw-label JSR
|
||||||
|
#06 =color
|
||||||
|
,text #0028 #0050 ,draw-label JSR
|
||||||
|
#07 =color
|
||||||
|
,text #002a #0058 ,draw-label JSR
|
||||||
|
#08 =color
|
||||||
|
,text #002c #0060 ,draw-label JSR
|
||||||
|
#09 =color
|
||||||
|
,text #002e #0068 ,draw-label JSR
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
@string " Hello Merveilles " ( add string to memory )
|
@text " Hello World " ( add string to memory )
|
||||||
|
|
||||||
@displaycli
|
@draw-label ( x1 y1 text )
|
||||||
#00 =dev/w ( set dev/write to console )
|
=y1 =x1
|
||||||
@cliloop
|
@draw-label-loop
|
||||||
DUP2 LDR IOW ( write pointer value to console )
|
( draw ) ~x1 ~y1 IOW2 IOW2 DUP2 LDR #00 SWP #0008 MUL2 ,font ADD2 IOW2 ~color IOW
|
||||||
#0001 ADD2 ( increment string pointer )
|
( incr ) #0001 ADD2
|
||||||
DUP2 LDR #00 NEQ ,cliloop ROT JMP? POP2 ( while *ptr!=0 goto loop )
|
( incr ) ~x1 #0008 ADD2 =x1
|
||||||
RTS
|
DUP2 LDR #00 NEQ ,draw-label-loop ROT JMP? POP2
|
||||||
|
RTS
|
||||||
@displaygui
|
|
||||||
#02 =dev/w ( set dev/write to sprite )
|
|
||||||
@guiloop
|
|
||||||
DUP2 LDR ,printchar JSR
|
|
||||||
#0001 ADD2
|
|
||||||
~x #0008 ADD2 =x
|
|
||||||
DUP2 LDR #00 NEQ ,guiloop ROT JMP? POP2
|
|
||||||
RTS
|
|
||||||
|
|
||||||
@printchar
|
|
||||||
~color ,getchar JSR ~x ~y ,draw-sprite JSR
|
|
||||||
RTS
|
|
||||||
|
|
||||||
@getchar
|
|
||||||
#00 SWP #0008 MUL2 ,SPRITESHEET ADD2
|
|
||||||
RTS
|
|
||||||
|
|
||||||
@draw-sprite
|
|
||||||
IOW2 ( y byte )
|
|
||||||
IOW2 ( x byte )
|
|
||||||
IOW2 ( sprite address )
|
|
||||||
IOW ( layer-color )
|
|
||||||
RTS
|
|
||||||
|
|
||||||
|0300 @SPRITESHEET ( first 128 characters of the spectrum-zx font )
|
|
||||||
|
|
||||||
|
@font ( spectrum-zx font )
|
||||||
[
|
[
|
||||||
0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000
|
0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000
|
||||||
0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000
|
0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000
|
|
@ -10,18 +10,18 @@
|
||||||
#01 =dev/w ( set dev/write to screen )
|
#01 =dev/w ( set dev/write to screen )
|
||||||
|
|
||||||
#01 =color
|
#01 =color
|
||||||
#0020 #0020 #0060 #0060 ,fill-rect JSR
|
#0010 #0020 #0040 #0060 ,fill-rect JSR
|
||||||
#02 =color
|
#02 =color
|
||||||
#0030 #0030 #0070 #0070 ,fill-rect JSR
|
#0020 #0030 #0050 #0070 ,fill-rect JSR
|
||||||
#03 =color
|
#03 =color
|
||||||
#0040 #0040 #0080 #0080 ,fill-rect JSR
|
#0030 #0040 #0060 #0080 ,fill-rect JSR
|
||||||
|
|
||||||
#01 =color
|
#01 =color
|
||||||
#0090 #0020 #00d0 #0060 ,line-rect JSR
|
#0070 #0020 #00a0 #0060 ,line-rect JSR
|
||||||
#02 =color
|
#02 =color
|
||||||
#00a0 #0030 #00e0 #0070 ,line-rect JSR
|
#0080 #0030 #00b0 #0070 ,line-rect JSR
|
||||||
#03 =color
|
#03 =color
|
||||||
#00b0 #0040 #00f0 #0080 ,line-rect JSR
|
#0090 #0040 #00c0 #0080 ,line-rect JSR
|
||||||
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
|
@ -71,5 +71,5 @@ RTS
|
||||||
|
|
||||||
|c000 @FRAME BRK
|
|c000 @FRAME BRK
|
||||||
|d000 @ERROR BRK
|
|d000 @ERROR BRK
|
||||||
|FFF0 [ f2ac 35bb 2b5f ] ( palette )
|
|FFF0 [ 0f0f 0fff 0ff0 ] ( palette )
|
||||||
|FFFA .RESET .FRAME .ERROR ( vectors )
|
|FFFA .RESET .FRAME .ERROR ( vectors )
|
Loading…
Reference in a new issue