0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-23 14:25:10 +00:00

Started sprite editor

This commit is contained in:
neauoire 2021-03-02 10:14:55 -08:00
parent 39faf4c2b7
commit d8fdf3840b
5 changed files with 203 additions and 16 deletions

View file

@ -44,8 +44,8 @@ Program p;
/* clang-format off */
char ops[][4] = {
"BRK", "NOP", "LIT", "---", "---", "---", "LDR", "STR",
"JMP", "JSR", "---", "RTS", "AND", "ORA", "ROL", "ROR",
"BRK", "NOP", "LIT", "JMP", "JSR", "RTS", "LDR", "STR",
"---", "---", "---", "---", "AND", "XOR", "ROL", "ROR",
"POP", "DUP", "SWP", "OVR", "ROT", "---", "WSR", "RSW",
"ADD", "SUB", "MUL", "DIV", "EQU", "NEQ", "GTH", "LTH"
};
@ -247,11 +247,13 @@ makevariable(char *id, Uint16 *addr, FILE *f)
Macro *m = NULL;
fscanf(f, "%s", wv);
origin = *addr;
if((m = findmacro(wv))) {
if(sihx(wv))
len = shex(wv);
else if((m = findmacro(wv))) {
len = m->size;
m->refs++;
} else
len = shex(wv);
return error("Invalid macro", wv);
*addr += len;
return makelabel(id, origin, len, m);
}

View file

@ -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
# run
./bin/assembler examples/dev.key.usm bin/boot.rom
./bin/assembler examples/app.pattern.usm bin/boot.rom
./bin/emulator bin/boot.rom

181
examples/app.pattern.usm Normal file
View file

@ -0,0 +1,181 @@
( app/hex )
&Screen { width 2 height 2 pad 4 y 2 x 2 color 1 }
&Sprite { pad 8 x 2 y 2 addr 2 color 1 }
&Mouse { x 2 y 2 state 1 chord 1 }
&Point2d { x 2 y 2 }
&Rect2d { x1 2 y1 2 x2 2 y2 2 }
&Point { x 1 y 1 }
&Editor { x1 2 y1 2 }
;pixel Point
;window Rect2d
;mouse Point2d
;editor Editor
;rect Rect2d
;color 1
|0100 @RESET
#0030 =window.x1 #0030 =window.y1 #0090 =window.x2 #00a0 =window.y2
#0040 =editor.x1 #0040 =editor.y
#0040 #0040 #01 ,draw-editor JSR
BRK
|0200 @FRAME
,no-click ~dev/mouse.state #00 EQU JMP? POP2
( load ) ,pattern ~dev/mouse.y ~editor.y1 SUB2 #0008 DIV2 ADD2 LDR
( mask ) #01 #07 ~dev/mouse.x ~editor.x1 SUB2 #0008 DIV2 SWP POP SUB ROL
XOR
( save ) ,pattern ~dev/mouse.y ~editor.y1 SUB2 #0008 DIV2 ADD2 STR
,redraw JSR
@no-click
,draw-cursor JSR
BRK
@redraw
#0000 #0000 ~dev/screen.width ~dev/screen.height #03 ,pattern ,tile-rect JSR
~window.x1 #0001 ADD2 ~window.y1 ~window.x2 #0004 ADD2 ~window.y2 #0004 ADD2 #00 ,fill-rect JSR
~window.x1 ~window.y1 #0001 ADD2 ~window.x2 #0001 ADD2 ~window.y2 #0004 ADD2 #00 ,fill-rect JSR
~window.x1 #0001 SUB2 ~window.y1 #0001 SUB2 ~window.x2 ~window.y2 #00 ,line-rect JSR
~window.x1 #0002 SUB2 ~window.y1 #0002 SUB2 ~window.x2 #0001 ADD2 ~window.y2 #0001 ADD2 #02 ,line-rect JSR
~window.x1 ~window.y1 ~window.x2 ~window.y2 #00 ,fill-rect JSR
~editor.x1 =dev/sprite.x
~editor.y1 =dev/sprite.y
,pattern =dev/sprite.addr
#02 =color
#00 =pixel.y
@redraw-ver
#00 =pixel.x
~editor.x1 =dev/sprite.x
@redraw-hor
( get bit )
,cell0_icn #00
,pattern #00 ~pixel.y ADD2 LDR #07 ~pixel.x SUB ROR #01 AND ( get bit )
#0008 MUL2 ADD2 =dev/sprite.addr ( add *8 )
( draw ) ~color =dev/sprite.color
( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
( incr ) ~pixel.x #01 ADD =pixel.x
,redraw-hor ~dev/sprite.x ~editor.x1 #0040 ADD2 LTH2 JMP? POP2
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
( incr ) ~pixel.y #01 ADD =pixel.y
,redraw-ver ~dev/sprite.y ~editor.y1 #0040 ADD2 LTH2 JMP? POP2
,pattern =dev/sprite.addr
~dev/sprite.y #0040 SUB2 =dev/sprite.y
~dev/sprite.x #0008 ADD2 =dev/sprite.x
( draw ) #01 =dev/sprite.color
RTS
@fill-rect ( x1 y1 x2 y2 color )
( load ) =color =rect.y2 =rect.x2 DUP2 =dev/screen.y =rect.y1 DUP2 =dev/screen.x =rect.x1
@fill-rect-ver
~rect.x1 =dev/screen.x
@fill-rect-hor
( draw ) ~color =dev/screen.color
( incr ) ~dev/screen.x #0001 ADD2 =dev/screen.x
,fill-rect-hor ~dev/screen.x ~rect.x2 LTH2 JMP? POP2
( incr ) ~dev/screen.y #0001 ADD2 =dev/screen.y
,fill-rect-ver ~dev/screen.y ~rect.y2 LTH2 JMP? POP2
RTS
@line-rect ( x1 y1 x2 y2 color )
( load ) =color =rect.y2 =rect.x2 DUP2 =dev/screen.y =rect.y1 DUP2 =dev/screen.x =rect.x1
@line-rect-hor
( incr ) ~dev/screen.x #0001 ADD2 =dev/screen.x
( draw ) ~rect.y1 =dev/screen.y ~color =dev/screen.color
( draw ) ~rect.y2 =dev/screen.y ~color =dev/screen.color
,line-rect-hor ~dev/screen.x ~rect.x2 LTH2 JMP? POP2
~rect.y1 =dev/screen.y
@line-rect-ver
( draw ) ~rect.x1 =dev/screen.x ~color =dev/screen.color
( draw ) ~rect.x2 =dev/screen.x ~color =dev/screen.color
( incr ) ~dev/screen.y #0001 ADD2 =dev/screen.y
,line-rect-ver ~dev/screen.y ~rect.y2 #0001 ADD2 LTH2 JMP? POP2
RTS
@tile-rect ( x1 y1 x2 y2 color addr )
=dev/sprite.addr =color =rect.y2 =rect.x2 DUP2 =dev/sprite.y =rect.y1 DUP2 =dev/sprite.x =rect.x1
@tile-rect-ver
~rect.x1 =dev/sprite.x
@tile-rect-hor
( draw ) ~color =dev/sprite.color
( incr ) ~dev/sprite.x #0008 ADD2 =dev/sprite.x
,tile-rect-hor ~dev/sprite.x ~rect.x2 LTH2 JMP? POP2
( incr ) ~dev/sprite.y #0008 ADD2 =dev/sprite.y
,tile-rect-ver ~dev/sprite.y ~rect.y2 LTH2 JMP? POP2
RTS
@draw-editor
=color DUP2 =dev/sprite.y =editor.y1 DUP2 =dev/sprite.x =editor.x1
,redraw JSR
RTS
@draw-cursor
~mouse.x ~dev/mouse.x NEQU2
~mouse.y ~dev/mouse.y NEQU2
#0000 EQU2 RTS? ( Return if unchanged )
( clear last cursor )
#10 ,clear_icn ~mouse.x ~mouse.y ,draw-sprite JSR
( record mouse positions )
~dev/mouse.x =mouse.x ~dev/mouse.y =mouse.y
#13 ,cursor_icn ~mouse.x ~mouse.y ,draw-sprite JSR
RTS
@draw-sprite
=dev/sprite.y
=dev/sprite.x
=dev/sprite.addr
=dev/sprite.color
RTS
@pattern [ 0000 0000 0000 0000 ]
@clear_icn [ 0000 0000 0000 0000 ]
@cursor_icn [ 80c0 e0f0 f8e0 1000 ]
@cell0_icn [ 7c82 8282 8282 7c00 ]
@cell1_icn [ 7cfe fefe fefe 7c00 ]
|d000 @ERROR BRK
|FF10 ;dev/screen Screen
|FF20 ;dev/sprite Sprite
|FF50 ;dev/mouse Mouse
|FFF0 .RESET .FRAME .ERROR ( vectors )
|FFF8 [ 13fd 1ef3 1bf2 ] ( palette )

View file

@ -139,18 +139,22 @@ RTS
RTS
@draw-sprite
=dev/sprite.y
=dev/sprite.x
=dev/sprite.addr
=dev/sprite.color
RTS
RTS
@draw-sprite-chr
=dev/sprite.y
=dev/sprite.x
=dev/sprite.addr
#20 =dev/sprite.color
RTS
RTS
@clear_icn [ 0000 0000 0000 0000 ]
@cursor_icn [ 80c0 e0f0 f8e0 1000 ]

18
uxn.c
View file

@ -34,14 +34,14 @@ Uint16 peek16(Stack *s, Uint8 a) { return peek8(s, a * 2) + (peek8(s, a * 2 + 1)
void op_brk(Uxn *u) { setflag(&u->status, FLAG_HALT, 1); }
void op_lit(Uxn *u) { u->literal += 1; }
void op_nop(Uxn *u) { printf("0x%02x \n", pop8(&u->wst)); fflush(stdout); }
void op_ldr(Uxn *u) { Uint16 a = pop16(&u->wst); push8(&u->wst, mempeek8(u, a)); }
void op_str(Uxn *u) { Uint16 a = pop16(&u->wst); Uint8 b = pop8(&u->wst); mempoke8(u, a, b); }
/* Logic */
void op_jmp(Uxn *u) { u->ram.ptr = pop16(&u->wst); }
void op_jsr(Uxn *u) { push16(&u->rst, u->ram.ptr); u->ram.ptr = pop16(&u->wst); }
void op_rts(Uxn *u) { u->ram.ptr = pop16(&u->rst); }
void op_ldr(Uxn *u) { Uint16 a = pop16(&u->wst); push8(&u->wst, mempeek8(u, a)); }
void op_str(Uxn *u) { Uint16 a = pop16(&u->wst); Uint8 b = pop8(&u->wst); mempoke8(u, a, b); }
/* Logic */
void op_and(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst, b & a); }
void op_ora(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst, b | a); }
void op_xor(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst, b | a); }
void op_rol(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst, b << a); }
void op_ror(Uxn *u) { Uint8 a = pop8(&u->wst), b = pop8(&u->wst); push8(&u->wst, b >> a); }
/* Stack */
@ -67,7 +67,7 @@ void op_nop16(Uxn *u) { printf("%04x\n", pop16(&u->wst)); }
void op_ldr16(Uxn *u) { Uint16 a = pop16(&u->wst); push16(&u->wst, mempeek16(u, a)); }
void op_str16(Uxn *u) { Uint16 a = pop16(&u->wst); Uint16 b = pop16(&u->wst); mempoke16(u, a, b); }
void op_and16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b & a); }
void op_ora16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b | a); }
void op_xor16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b ^ a); }
void op_rol16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b << a); }
void op_ror16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push16(&u->wst, b >> a); }
/* Stack(16-bits) */
@ -89,13 +89,13 @@ void op_gth16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push8(&u-
void op_lth16(Uxn *u) { Uint16 a = pop16(&u->wst), b = pop16(&u->wst); push8(&u->wst, getflag(&u->status, FLAG_SIGN) ? (Sint16)b < (Sint16)a : b < a); }
void (*ops[])(Uxn *u) = {
op_brk, op_nop, op_lit, op_nop, op_nop, op_nop, op_ldr, op_str,
op_jmp, op_jsr, op_nop, op_rts, op_and, op_ora, op_rol, op_ror,
op_brk, op_nop, op_lit, op_jmp, op_jsr, op_rts, op_ldr, op_str,
op_jmp, op_jsr, op_nop, op_rts, op_and, op_xor, op_rol, op_ror,
op_pop, op_dup, op_swp, op_ovr, op_rot, op_nop, op_wsr, op_rsw,
op_add, op_sub, op_mul, op_div, op_equ, op_neq, op_gth, op_lth,
/* 16-bit */
op_brk, op_nop16, op_lit16, op_nop, op_nop, op_nop, op_ldr16, op_str16,
op_jmp, op_jsr, op_nop, op_rts, op_and16, op_ora16, op_rol16, op_ror16,
op_brk, op_nop16, op_lit16, op_jmp, op_jsr, op_rts, op_ldr16, op_str16,
op_jmp, op_jsr, op_nop, op_rts, op_and16, op_xor16, op_rol16, op_ror16,
op_pop16, op_dup16, op_swp16, op_ovr16, op_rot16, op_wsr16, op_rsw16, op_nop,
op_add16, op_sub16, op_mul16, op_div16, op_equ16, op_neq16, op_gth16, op_lth16
};