uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 38a9be86c2ab093abdcc600ff992448ab8e440cf
parent 19157a9ae1994def43f41fa89a274bd8425b196d
Author: neauoire <aliceffekt@gmail.com>
Date:   Sat, 24 Apr 2021 21:18:15 -0700

Fixed color swatch in nasu

Diffstat:
Mprojects/software/nasu.usm | 102++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/assembler.c | 16+++++++++-------
Msrc/emulator.c | 6+++---
Msrc/ppu.c | 26++++++++++++++------------
4 files changed, 78 insertions(+), 72 deletions(-)

diff --git a/projects/software/nasu.usm b/projects/software/nasu.usm @@ -8,6 +8,8 @@ 1 2 3 - select brush TODO: + Copy in 2 bits mode, copies 2 tiles + Modify up to 4 pages Save/load/rename Select paint color for 2-bit mode ) @@ -49,11 +51,11 @@ |0000 -@settings [ &blending $1 &depth $1 &brush $1 &page $2 ] +@settings [ &blending $1 &depth $1 &brush $1 &page $2 &tile $2 ] @frame [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 &width $2 &height $2 ] @bankview [ &x $2 &y $2 &mode $1 &selection $1 ] -@tileview [ &x $2 &y $2 &addr $2 ] +@tileview [ &x $2 &y $2 ] @colorview [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] @blendview [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] @dataview [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ] @@ -90,7 +92,7 @@ .frame/x2 PEK2 #0098 SUB2 .tileview/x POK2 .frame/y1 PEK2 .tileview/y POK2 - BANK #0448 ADD2 .tileview/addr POK2 + BANK #0448 ADD2 .settings/tile POK2 .frame/x1 PEK2 #0010 ADD2 .frame/y2 PEK2 #0020 SUB2 #0020 #0020 SIZE-TO-RECT ;blendview SET-RECT .frame/x1 PEK2 #0038 ADD2 .frame/y2 PEK2 #0020 SUB2 #0020 #0020 SIZE-TO-RECT ;colorview SET-RECT @@ -204,7 +206,7 @@ BRK .bankview/mode PEK #01 NEQ ,&not-copy-mode JNZ #00 .i POK &copy-loop - ( load ) .tileview/addr PEK2 .i PEK ADD GET + ( load ) .settings/tile PEK2 .i PEK ADD GET ( get touch addr ) .Mouse/x DEI2 .bankview/x PEK2 SUB2 STEP8 .Mouse/y DEI2 .bankview/y PEK2 SUB2 STEP8 #0010 MUL2 ADD2 @@ -243,7 +245,7 @@ BRK .Mouse/x DEI2 .tileview/x PEK2 SUB2 STEP8 #0040 DIV2 .Mouse/y DEI2 .tileview/y PEK2 SUB2 STEP8 #0040 DIV2 2* ADD2 8* - .tileview/addr PEK2 ADD2 .addr POK2 ( addr offset ) + .settings/tile PEK2 ADD2 .addr POK2 ( addr offset ) .Mouse/x DEI2 .tileview/x PEK2 SUB2 .Mouse/x DEI2 .tileview/x PEK2 SUB2 #0040 DIV2 #0040 MUL2 SUB2 .pos/x POK2 .Mouse/y DEI2 .tileview/y PEK2 SUB2 .Mouse/y DEI2 .tileview/y PEK2 SUB2 #0040 DIV2 #0040 MUL2 SUB2 .pos/y POK2 .Mouse/state DEI #10 NEQ ,&no-erase-mode JNZ @@ -288,17 +290,17 @@ BRK BRK @on-touch-colorview ( -> ) - + ( channel ) .Mouse/y DEI2 .colorview/y1 PEK2 SUB2 8/ SWP POP STH ( rgb ) .Mouse/x DEI2 .colorview/x1 PEK2 SUB2 8/ SWP POP DUP #00 NEQ ,&no-brush JNZ DUPr STHr .settings/brush POK &no-brush DUP #01 NEQ ,&no-red JNZ - DUPr STHr ;System/r ;set-color JSR2 &no-red + DUPr STHr .System/r ;set-color JSR2 &no-red DUP #02 NEQ ,&no-green JNZ - DUPr STHr ;System/g ;set-color JSR2 &no-green + DUPr STHr .System/g ;set-color JSR2 &no-green DUP #03 NEQ ,&no-blue JNZ - DUPr STHr ;System/b ;set-color JSR2 &no-blue + DUPr STHr .System/b ;set-color JSR2 &no-blue POP POPr ( release ) #00 .Mouse/state DEO ;redraw JSR2 @@ -307,29 +309,29 @@ BRK @set-color ( color rgb -- ) - STH2 + STH DUP #00 NEQ ,&no-red0 JNZ - DUP2r STH2r GET DUP #04 SFT #01 ADD + DUPr STHr DEI DUP #04 SFT #01 ADD ( add/sub ) .Mouse/state DEI #10 EQU #fe MUL ADD - ( resume ) #40 SFT SWP #0f AND ADD DUP2r STH2r PUT + ( resume ) #40 SFT SWP #0f AND ADD DUPr STHr DEO &no-red0 DUP #01 NEQ ,&no-red1 JNZ - DUP2r STH2r GET DUP #0f AND #01 ADD + DUPr STHr DEI DUP #0f AND #01 ADD ( add/sub ) .Mouse/state DEI #10 EQU #fe MUL ADD - ( resume ) #0f AND SWP #f0 AND ADD DUP2r STH2r PUT + ( resume ) #0f AND SWP #f0 AND ADD DUPr STHr DEO &no-red1 DUP #02 NEQ ,&no-red2 JNZ - DUP2r STH2r #0001 ADD2 GET DUP #04 SFT #01 ADD + DUPr STHr #01 ADD DEI DUP #04 SFT #01 ADD ( add/sub ) .Mouse/state DEI #10 EQU #fe MUL ADD - ( resume ) #40 SFT SWP #0f AND ADD DUP2r STH2r #0001 ADD2 PUT + ( resume ) #40 SFT SWP #0f AND ADD DUPr STHr #01 ADD DEO &no-red2 DUP #03 NEQ ,&no-red3 JNZ - DUP2r STH2r #0001 ADD2 GET DUP #0f AND #01 ADD + DUPr STHr #01 ADD DEI DUP #0f AND #01 ADD ( add/sub ) .Mouse/state DEI #10 EQU #fe MUL ADD - ( resume ) #0f AND SWP #f0 AND ADD DUP2r STH2r #0001 ADD2 PUT + ( resume ) #0f AND SWP #f0 AND ADD DUPr STHr #01 ADD DEO &no-red3 POP - POP2r + POPr RTN @@ -339,7 +341,7 @@ RTN ( y ) #10 MOD #10 MUL #00 SWP 8* ( x ) ROT #10 MOD #00 SWP 8* ADD2 ( 2-bit mode ) #00 .settings/depth PEK #01 ADD MUL2 - ( offset ) .settings/page PEK2 ADD2 .tileview/addr POK2 + ( offset ) .settings/page PEK2 ADD2 .settings/tile POK2 ;redraw JSR2 RTN @@ -354,29 +356,29 @@ RTN @op_shiftup - .tileview/addr PEK2 GET - .tileview/addr PEK2 #0001 ADD2 GET .tileview/addr PEK2 PUT - .tileview/addr PEK2 #0002 ADD2 GET .tileview/addr PEK2 #0001 ADD2 PUT - .tileview/addr PEK2 #0003 ADD2 GET .tileview/addr PEK2 #0002 ADD2 PUT - .tileview/addr PEK2 #0004 ADD2 GET .tileview/addr PEK2 #0003 ADD2 PUT - .tileview/addr PEK2 #0005 ADD2 GET .tileview/addr PEK2 #0004 ADD2 PUT - .tileview/addr PEK2 #0006 ADD2 GET .tileview/addr PEK2 #0005 ADD2 PUT - .tileview/addr PEK2 #0007 ADD2 GET .tileview/addr PEK2 #0006 ADD2 PUT - .tileview/addr PEK2 #0007 ADD2 PUT + .settings/tile PEK2 GET + .settings/tile PEK2 #0001 ADD2 GET .settings/tile PEK2 PUT + .settings/tile PEK2 #0002 ADD2 GET .settings/tile PEK2 #0001 ADD2 PUT + .settings/tile PEK2 #0003 ADD2 GET .settings/tile PEK2 #0002 ADD2 PUT + .settings/tile PEK2 #0004 ADD2 GET .settings/tile PEK2 #0003 ADD2 PUT + .settings/tile PEK2 #0005 ADD2 GET .settings/tile PEK2 #0004 ADD2 PUT + .settings/tile PEK2 #0006 ADD2 GET .settings/tile PEK2 #0005 ADD2 PUT + .settings/tile PEK2 #0007 ADD2 GET .settings/tile PEK2 #0006 ADD2 PUT + .settings/tile PEK2 #0007 ADD2 PUT RTN @op_shiftdown - .tileview/addr PEK2 #0007 ADD2 GET - .tileview/addr PEK2 #0006 ADD2 GET .tileview/addr PEK2 #0007 ADD2 PUT - .tileview/addr PEK2 #0005 ADD2 GET .tileview/addr PEK2 #0006 ADD2 PUT - .tileview/addr PEK2 #0004 ADD2 GET .tileview/addr PEK2 #0005 ADD2 PUT - .tileview/addr PEK2 #0003 ADD2 GET .tileview/addr PEK2 #0004 ADD2 PUT - .tileview/addr PEK2 #0002 ADD2 GET .tileview/addr PEK2 #0003 ADD2 PUT - .tileview/addr PEK2 #0001 ADD2 GET .tileview/addr PEK2 #0002 ADD2 PUT - .tileview/addr PEK2 GET .tileview/addr PEK2 #0001 ADD2 PUT - .tileview/addr PEK2 PUT + .settings/tile PEK2 #0007 ADD2 GET + .settings/tile PEK2 #0006 ADD2 GET .settings/tile PEK2 #0007 ADD2 PUT + .settings/tile PEK2 #0005 ADD2 GET .settings/tile PEK2 #0006 ADD2 PUT + .settings/tile PEK2 #0004 ADD2 GET .settings/tile PEK2 #0005 ADD2 PUT + .settings/tile PEK2 #0003 ADD2 GET .settings/tile PEK2 #0004 ADD2 PUT + .settings/tile PEK2 #0002 ADD2 GET .settings/tile PEK2 #0003 ADD2 PUT + .settings/tile PEK2 #0001 ADD2 GET .settings/tile PEK2 #0002 ADD2 PUT + .settings/tile PEK2 GET .settings/tile PEK2 #0001 ADD2 PUT + .settings/tile PEK2 PUT RTN @@ -443,7 +445,7 @@ RTN .bankview/x PEK2 DUP2 #0080 ADD2 &hor ( save ) OVR2 .Screen/x DEO2 - ( get selected ) .Screen/addr DEI2 .tileview/addr PEK2 EQU2 + ( get selected ) .Screen/addr DEI2 .settings/tile PEK2 EQU2 ( get blending ) .settings/blending PEK ( get depth ) .settings/depth PEK #20 MUL ( draw ) #20 ADD ADD ADD .Screen/color DEO @@ -463,7 +465,7 @@ RTN .tileview/x PEK2 #0028 ADD2 .Screen/x DEO2 .tileview/y PEK2 #0010 SUB2 .Screen/y DEO2 - .tileview/addr PEK2 .Screen/addr DEO2 + .settings/tile PEK2 .Screen/addr DEO2 ( get blending ) .settings/blending PEK ( get depth ) .settings/depth PEK #20 MUL @@ -473,28 +475,28 @@ RTN .tileview/x PEK2 .Screen/x DEO2 .tileview/y PEK2 #0010 SUB2 .Screen/y DEO2 - .tileview/addr PEK2 ;draw-short JSR2 + .settings/tile PEK2 ;draw-short JSR2 ( body ) .tileview/x PEK2 .Screen/x DEO2 .tileview/y PEK2 .Screen/y DEO2 - .tileview/addr PEK2 .tileview/addr POK2 + .settings/tile PEK2 .settings/tile POK2 ;draw-tileview-icn JSR2 .tileview/x PEK2 #0040 ADD2 .Screen/x DEO2 .tileview/y PEK2 .Screen/y DEO2 - .tileview/addr PEK2 8+ .tileview/addr POK2 + .settings/tile PEK2 8+ .settings/tile POK2 ;draw-tileview-icn JSR2 .tileview/x PEK2 .Screen/x DEO2 .tileview/y PEK2 #0040 ADD2 .Screen/y DEO2 - .tileview/addr PEK2 8+ .tileview/addr POK2 + .settings/tile PEK2 8+ .settings/tile POK2 ;draw-tileview-icn JSR2 .tileview/x PEK2 #0040 ADD2 .Screen/x DEO2 .tileview/y PEK2 #0040 ADD2 .Screen/y DEO2 - .tileview/addr PEK2 8+ .tileview/addr POK2 + .settings/tile PEK2 8+ .settings/tile POK2 ;draw-tileview-icn JSR2 ( line hor ) @@ -513,7 +515,7 @@ RTN ( incr ) .Screen/y DEI2 #0002 ADD2 .Screen/y DEO2 .Screen/y DEI2 .tileview/y PEK2 #0081 ADD2 LTH2 ,&line-ver JNZ - ( rewind ) .tileview/addr PEK2 #0018 SUB2 .tileview/addr POK2 + ( rewind ) .settings/tile PEK2 #0018 SUB2 .settings/tile POK2 RTN @@ -525,7 +527,7 @@ RTN &hor ( get bit ) ;blank_icn #00 - .tileview/addr PEK2 #00 .pt/y PEK ADD2 GET #07 .pt/x PEK SUB SFT #01 AND ( get bit ) + .settings/tile PEK2 #00 .pt/y PEK ADD2 GET #07 .pt/x PEK SUB SFT #01 AND ( get bit ) 8* ADD2 .Screen/addr DEO2 ( add *8 ) ( draw ) #21 .Screen/color DEO ( incr ) .Screen/x DEI2 8+ .Screen/x DEO2 @@ -542,7 +544,7 @@ RTN .blendview/x1 PEK2 #0002 SUB2 .blendview/y1 PEK2 #0002 SUB2 .blendview/x2 PEK2 #0001 ADD2 .blendview/y2 PEK2 #0001 ADD2 #03 ;line-rect JSR2 - .tileview/addr PEK2 .Screen/addr DEO2 + .settings/tile PEK2 .Screen/addr DEO2 #00 #10 &loop OVR #04 MOD #00 SWP #0008 MUL2 .blendview/x1 PEK2 ADD2 .Screen/x DEO2 @@ -571,7 +573,7 @@ RTN #00 .i POK &bytes .tileview/x PEK2 #0088 ADD2 .Screen/x DEO2 - .tileview/addr PEK2 #00 .i PEK ADD2 GET #22 ;draw-byte JSR2 + .settings/tile PEK2 #00 .i PEK ADD2 GET #22 ;draw-byte JSR2 ( incr ) .i PEK #01 ADD .i POK ( incr ) .Screen/y DEI2 8+ .Screen/y DEO2 .i PEK #08 LTH ;&bytes JNZ2 @@ -587,7 +589,7 @@ RTN ( draw tiles 2x2 ) .tileview/y PEK2 .Screen/y DEO2 - #00 .pt/x POK #00 .pt/y POK .tileview/addr PEK2 .Screen/addr DEO2 + #00 .pt/x POK #00 .pt/y POK .settings/tile PEK2 .Screen/addr DEO2 &tiles-ver #00 .pt/x POK diff --git a/src/assembler.c b/src/assembler.c @@ -236,28 +236,28 @@ parsetoken(char *w) return error("Address is not in zero page", w); pushbyte(l->addr, 1); return ++l->refs; - } else if(w[0] == ',' && (l = findlabel(w + 1))) { + } else if(w[0] == ',' && (l = findlabel(w + 1))) { /* relative */ int off = l->addr - p.ptr - 3; if(off < -126 || off > 126) return error("Address is too far", w); pushbyte((Sint8)off, 1); return ++l->refs; - } else if(w[0] == ':' && (l = findlabel(w + 1))) { /* absolute */ + } else if(w[0] == ':' && (l = findlabel(w + 1))) { /* raw */ pushshort(l->addr, 0); return ++l->refs; } else if(w[0] == ';' && (l = findlabel(w + 1))) { /* absolute */ pushshort(l->addr, 1); return ++l->refs; - } else if(findopcode(w) || scmp(w, "BRK", 4)) { + } else if(findopcode(w) || scmp(w, "BRK", 4)) { /* opcode */ pushbyte(findopcode(w), 0); return 1; - } else if(w[0] == '"') { + } else if(w[0] == '"') { /* string */ pushword(w + 1); return 1; - } else if(w[0] == '\'') { + } else if(w[0] == '\'') { /* char */ pushbyte((Uint8)w[1], 0); return 1; - } else if(w[0] == '#') { + } else if(w[0] == '#') { /* immediate */ if(slen(w + 1) == 1) pushbyte((Uint8)w[1], 1); if(sihx(w + 1) && slen(w + 1) == 2) @@ -267,11 +267,13 @@ parsetoken(char *w) else return 0; return 1; - } else if(sihx(w)) { + } else if(sihx(w)) { /* raw */ if(slen(w) == 2) pushbyte(shex(w), 0); else if(slen(w) == 4) pushshort(shex(w), 0); + else + return error("Hex value length is invalid", w); return 1; } else if((m = findmacro(w))) { int i; diff --git a/src/emulator.c b/src/emulator.c @@ -23,7 +23,7 @@ static SDL_Renderer *gRenderer; static SDL_Texture *gTexture; static Ppu ppu; static Apu apu; -static Device *devsystem, *devscreen, *devmouse, *devctrl, *devapu, *devfile; +static Device *devscreen, *devmouse, *devctrl, *devapu; Uint8 zoom = 0, debug = 0, reqdraw = 0; @@ -350,14 +350,14 @@ main(int argc, char **argv) if(!init(&u)) return error("Init", "Failed"); - devsystem = portuxn(&u, 0x0, "system", system_talk); + portuxn(&u, 0x0, "system", system_talk); portuxn(&u, 0x1, "console", console_talk); devscreen = portuxn(&u, 0x2, "screen", screen_talk); devapu = portuxn(&u, 0x3, "audio", audio_talk); devctrl = portuxn(&u, 0x4, "controller", nil_talk); portuxn(&u, 0x5, "---", nil_talk); devmouse = portuxn(&u, 0x6, "mouse", nil_talk); - devfile = portuxn(&u, 0x7, "file", file_talk); + portuxn(&u, 0x7, "file", file_talk); portuxn(&u, 0x8, "---", nil_talk); portuxn(&u, 0x9, "midi", nil_talk); portuxn(&u, 0xa, "datetime", datetime_talk); diff --git a/src/ppu.c b/src/ppu.c @@ -30,6 +30,14 @@ static Uint8 font[][8] = { {0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c}, {0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}}; +Uint8 +readpixel(Uint8 *sprite, Uint8 h, Uint8 v) +{ + Uint8 ch1 = ((sprite[v] >> h) & 0x1); + Uint8 ch2 = (((sprite[v + 8] >> h) & 0x1) << 1); + return ch1 + ch2; +} + void clear(Ppu *p) { @@ -79,9 +87,8 @@ puticn(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color) for(v = 0; v < 8; v++) for(h = 0; h < 8; h++) { Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1); - if(ch1 == 0 && (color == 0x05 || color == 0x0a || color == 0x0f)) - continue; - putpixel(p, layer, x + h, y + v, ch1 ? color % 4 : color / 4); + if(ch1 == 1 || (color != 0x05 && color != 0x0a && color != 0x0f)) + putpixel(p, layer, x + h, y + v, ch1 ? color % 4 : color / 4); } } @@ -135,15 +142,10 @@ drawppu(Ppu *p) Uint16 key = (y * p->hor + x) * 16; for(v = 0; v < 8; v++) for(h = 0; h < 8; h++) { - Uint8 *sprite = &p->fg[key]; - Uint8 ch1 = ((sprite[v] >> h) & 0x1); - Uint8 ch2 = (((sprite[v + 8] >> h) & 0x1) << 1); - if(ch1 + ch2 == 0) { - sprite = &p->bg[key]; - ch1 = ((sprite[v] >> h) & 0x1); - ch2 = (((sprite[v + 8] >> h) & 0x1) << 1); - } - drawpixel(p, x * 8 + p->pad + 7 - h, y * 8 + p->pad + v, ch1 + ch2); + Uint8 color = readpixel(&p->fg[key], h, v); + if(color == 0) + color = readpixel(&p->bg[key], h, v); + drawpixel(p, x * 8 + p->pad + 7 - h, y * 8 + p->pad + v, color); } } }