uxn

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

commit 56a3a993f45a603e45578cafcab2a4ba7dc7332e
parent ff81d21b08821c7bef3a594cf9e9010afbe6885c
Author: neauoire <aliceffekt@gmail.com>
Date:   Tue, 13 Apr 2021 11:38:22 -0700

Added graphical example to file device

Diffstat:
MREADME.md | 6++++--
Mbuild.sh | 2+-
Amkfile | 46++++++++++++++++++++++++++++++++++++++++++++++
Mprojects/examples/dev.file.usm | 210++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
Mprojects/examples/dev.mouse.usm | 2++
Mprojects/software/left.usm | 2+-
Mprojects/software/nasu.usm | 2+-
Mprojects/software/noodle.usm | 2+-
Mprojects/software/orca.usm | 3++-
Msrc/emulator.c | 8+++++---
Msrc/ppu.c | 2+-
11 files changed, 230 insertions(+), 55 deletions(-)

diff --git a/README.md b/README.md @@ -58,11 +58,13 @@ RTN - Shortcut to export/import disk state - Implement Uxambly REPL - Load disks at a different place than 0x0000. +- Curl device? 8-bit web browser? ## Palettes -- `[ 6a03 4a0d aa0c ]`, purple/cyan -- `[ a1f3 a14d a16c ]`, grey-pink/teal +- `#6a03` `#4a0d` `#aa0c`, purple/cyan +- `#a1f3` `#a14d` `#a16c`, grey-pink/teal +- `#8c4b` `#884b` `#e8bb`, commodore64 ## Refs diff --git a/build.sh b/build.sh @@ -32,7 +32,7 @@ else fi echo "Assembling.." -./bin/assembler projects/software/noodle.usm bin/boot.rom +./bin/assembler projects/examples/dev.file.usm bin/boot.rom echo "Running.." if [ "${2}" = '--cli' ]; diff --git a/mkfile b/mkfile @@ -0,0 +1,46 @@ +</$objtype/mkfile + +TARG=assembler debugger emulator +ROM=assembler left nasu neralie noodle orca +CFLAGS=$CFLAGS -I/sys/include/npe +BIN=/$objtype/bin/uxn +HFILES=\ + /sys/include/npe/stdio.h\ + src/apu.h\ + src/ppu.h\ + src/uxn.h\ + +CLEANFILES=${TARG:%=bin/%} ${ROM:%=bin/%.rom} + +default:V: all + +all:V: ${TARG:%=bin/%} ${ROM:%=bin/%.rom} + +</sys/src/cmd/mkmany + +/sys/include/npe/stdio.h: + hget https://git.sr.ht/~ft/npe/archive/master.tar.gz | tar xz && + cd npe-master && + mk install && + rm -r npe-master + +bin/%.rom: projects/software/%.usm bin/assembler + bin/assembler projects/software/$stem.usm $target + +bin/assembler:Q: $O.assembler + mkdir -p bin && cp $prereq $target + +bin/debugger:Q: $O.debugger + mkdir -p bin && cp $prereq $target + +bin/emulator:Q: $O.emulator + mkdir -p bin && cp $prereq $target + +$O.assembler: assembler.$O + +$O.debugger: debugger.$O uxn.$O + +$O.emulator: emulator.$O apu.$O ppu.$O uxn.$O + +%.$O: src/%.c + $CC $CFLAGS -Isrc -o $target src/$stem.c diff --git a/projects/examples/dev.file.usm b/projects/examples/dev.file.usm @@ -1,67 +1,188 @@ ( Dev/File ) %RTN { JMP2r } +%STEP8 { #0033 SFT2 } +%++ { #01 ADD } + +%MEMORY { #1000 } + +;loadbtn { x 2 y 2 } +;output { x 2 y 2 } +;pointer { x 2 y 2 } +;label { x 2 y 2 color 1 addr 2 } ( devices ) -|0100 ;Console { pad 8 char 1 byte 1 short 2 } -|0160 ;File { offset 2 append 1 pad 5 name 2 length 2 load 2 save 2 } -|01F0 .RESET .FRAME .ERROR ( vectors ) -|01F8 [ 13fd 1ef3 1bf2 ] ( palette ) +|0100 ;System { vector 2 pad 6 r 2 g 2 b 2 } +|0110 ;Console { vector 2 pad 6 char 1 byte 1 short 2 } +|0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 } +|0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 } +|0170 ;File { vector 2 pad 6 name 2 length 2 load 2 save 2 } ( program ) -|0200 @RESET - - #11 - $loop - ,text1 ,print-label JSR2 - ,scramble JSR2 - #01 SUB DUP ,$loop ROT JNZ2 +|0200 + + ( theme ) #804b =System.r #804b =System.g #e0bb =System.b + ( vectors ) ,on-mouse =Mouse.vector + ( vectors ) ,on-transfer =File.vector + + #0020 =loadbtn.x + #0020 =loadbtn.y + #0020 =output.x + #0030 =output.y + + ~loadbtn.x ~loadbtn.y #26 ,load_txt ,draw-label JSR2 + + ,draw-file JSR2 BRK -@print-label ( text ) - - $loop NOP - ( send ) DUP2 PEK2 =Console.char - ( incr ) #0001 ADD2 - ( loop ) DUP2 PEK2 #00 NEQ ^$loop MUL JMP +@on-transfer ( -> ) + + ,draw-file JSR2 + ~output.x ~output.y #0088 ADD2 #23 ,done_txt ,draw-label JSR2 + ( release ) #00 =Mouse.state + +BRK + +@on-mouse ( -> ) + + ~loadbtn.x ~loadbtn.y #26 ,load_txt ,draw-label JSR2 + ~loadbtn.x #0028 ADD2 ~loadbtn.y #23 ,srcpath ,draw-label JSR2 + + ~Mouse.state #00 EQU ^$touch-end JNZ + + ~Mouse.y STEP8 ~loadbtn.y NEQ2 ^$no-touch-load JNZ + ~loadbtn.x ~loadbtn.y #27 ,load_txt ,draw-label JSR2 + ,srcpath #0100 ,load-file JSR2 + ( release ) #00 =Mouse.state + $no-touch-load + + $touch-end + + ,draw-cursor JSR2 + +BRK + +@draw-file ( -- ) + + #00 #10 + $ver + ( pos-y ) OVR #00 SWP #0008 MUL2 ~output.y ADD2 =Screen.y + #00 #10 + $hor + ( pos-x ) OVR #00 SWP #0008 MUL2 ~output.x ADD2 =Screen.x + ( get x,y ) SWP2 OVR STH SWP2 OVR STHr + ( get id ) #10 MUL ADD + ( get data ) #00 SWP MEMORY ADD2 PEK2 + ( get sprite ) #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr + ( draw ) #2d =Screen.color + ( incr ) SWP ++ SWP + DUP2 NEQ ^$hor JNZ + POP2 + ( incr ) SWP ++ SWP + DUP2 NEQ ^$ver JNZ POP2 RTN -@scramble - - ,filename =File.name - - #00 =File.append - #0000 =File.offset - #0003 =File.length - ,text1 #000d ADD2 =File.save - - #01 =File.append - #0003 =File.offset - #000d =File.length - ,text1 =File.save +@load-file ( path length -- ) - #0000 =File.offset - #0004 =File.length - ,text1 =File.load - - #0004 =File.offset - #0008 =File.length - ,text1 #0008 ADD2 =File.load + =File.length =File.name MEMORY =File.load + +RTN + +@draw-cursor ( -- ) + + ( clear last cursor ) + ,clear_icn =Screen.addr + ~pointer.x =Screen.x + ~pointer.y =Screen.y + #30 =Screen.color + + ( record pointer positions ) + ~Mouse.x =pointer.x ~Mouse.y =pointer.y + + ( draw new cursor ) + ,cursor_icn =Screen.addr + ~pointer.x =Screen.x + ~pointer.y =Screen.y + #32 ~Mouse.state #00 NEQ ADD =Screen.color + +RTN + +@draw-label ( x y color addr -- ) - #000c =File.offset - #0004 =File.length - ,text1 #0004 ADD2 =File.load + ( load ) =label.addr =label.color =Screen.y =Screen.x + ~label.addr + $loop + ( draw ) DUP2 PEK2 #20 SUB #00 SWP #0008 MUL2 ,font ADD2 =Screen.addr ~label.color =Screen.color + ( incr ) #0001 ADD2 + ( incr ) ~Screen.x #0008 ADD2 =Screen.x + DUP2 PEK2 #00 NEQ ^$loop JNZ + POP2 RTN +@clear_icn [ 0000 0000 0000 0000 ] +@cursor_icn [ 80c0 e0f0 f8e0 1000 ] + +@done_txt [ LOAD 20 SUCCESS! 00 ] +@load_txt [ LOAD 00 ] +@save_txt [ SAVE 00 ] -@text1 [ Welcome 20 to 20 UxnVM 0a00 ] -@filename [ textio.bit ] +@srcpath [ README.md 00 ] +@dstpath [ bin/export.md 00 ] -@FRAME BRK -@ERROR BRK +@font ( specter8-frag font ) +[ + 0000 0000 0000 0000 0008 0808 0800 0800 + 0014 1400 0000 0000 0024 7e24 247e 2400 + 0008 1e28 1c0a 3c08 0000 2204 0810 2200 + 0030 4832 4c44 3a00 0008 1000 0000 0000 + 0004 0808 0808 0400 0020 1010 1010 2000 + 0000 2214 0814 2200 0000 0808 3e08 0800 + 0000 0000 0000 0810 0000 0000 3e00 0000 + 0000 0000 0000 0800 0000 0204 0810 2000 + 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 + 0000 0010 0000 1000 0000 1000 0010 1020 + 0000 0810 2010 0800 0000 003e 003e 0000 + 0000 1008 0408 1000 003c 420c 1000 1000 + 003c 4232 4a42 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 003c 4240 4642 3c00 + 0042 427e 4242 4200 001c 0808 0808 1c00 + 007e 0202 0242 3c00 0042 4478 4442 4200 + 0040 4040 4040 7e00 0042 665a 4242 4200 + 0042 6252 4a46 4200 003c 4242 4242 3c00 + 007c 4242 7c40 4000 003c 4242 4244 3a00 + 007c 4242 7c44 4200 003e 403c 0242 3c00 + 007e 0808 0808 1000 0042 4242 4244 3a00 + 0042 4242 4224 1800 0042 4242 5a66 4200 + 0042 423c 4242 4200 0042 423e 0242 3c00 + 007e 020c 3040 7e00 000c 0808 0808 0c00 + 0040 2010 0804 0200 0030 1010 1010 3000 + 0008 1400 0000 0000 0000 0000 0000 7e00 + 0008 0400 0000 0000 0000 3c02 3e42 3a00 + 0040 407c 4242 7c00 0000 3c42 4042 3c00 + 0002 023e 4242 3e00 0000 3c42 7e40 3e00 + 0000 3e40 7840 4000 0000 3c42 3e02 3c00 + 0040 405c 6242 4200 0008 0018 0808 0400 + 0008 0018 0808 4830 0040 4244 7844 4200 + 0010 1010 1010 0c00 0000 6c52 5252 5200 + 0000 5c62 4242 4200 0000 3c42 4242 3c00 + 0000 7c42 427c 4040 0000 3e42 423e 0202 + 0000 5c62 4040 4000 0000 3e40 3c02 7c00 + 0008 7e08 0808 1000 0000 4242 4244 3a00 + 0000 4242 4224 1800 0000 5252 5252 2e00 + 0000 4224 1824 4200 0000 4242 3e02 7c00 + 0000 7e02 3c40 7e00 000c 0810 1008 0c00 + 0008 0808 0808 0800 0030 1008 0810 3000 + 0000 0032 4c00 0000 3c42 99a1 a199 423c +] +\ No newline at end of file diff --git a/projects/examples/dev.mouse.usm b/projects/examples/dev.mouse.usm @@ -13,6 +13,8 @@ ;pointer { x 2 y 2 } ;circle { xc 2 yc 2 x 2 y 2 r 2 d 2 } +( devices ) + |0100 ;System { vector 2 pad 6 r 2 g 2 b 2 } |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 } |0160 ;Mouse { vector 2 x 2 y 2 state 1 chord 1 } diff --git a/projects/software/left.usm b/projects/software/left.usm @@ -47,7 +47,7 @@ |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 } |0140 ;Controller { vector 2 button 1 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 } +|0170 ;File { vector 2 pad 6 name 2 length 2 load 2 save 2 } ( program ) diff --git a/projects/software/nasu.usm b/projects/software/nasu.usm @@ -36,7 +36,7 @@ |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 } |0140 ;Controller { vector 2 button 1 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 } +|0170 ;File { vector 2 pad 6 name 2 length 2 load 2 save 2 } ( program ) diff --git a/projects/software/noodle.usm b/projects/software/noodle.usm @@ -56,7 +56,7 @@ |0120 ;Screen { vector 2 width 2 height 2 pad 2 x 2 y 2 addr 2 color 1 } |0140 ;Controller { vector 2 button 1 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 } +|0170 ;File { vector 2 pad 6 name 2 length 2 load 2 save 2 } ( program ) diff --git a/projects/software/orca.usm b/projects/software/orca.usm @@ -225,10 +225,11 @@ RTN ( get right ) DUP2 SWP ++ SWP GET-CELL-VALUE STH ( incr y ) ++ ( get result ) SUBr STHr - DUP =Console.byte GET-CHAR SET-CELL + ( NOTE: Issue is not with modulo, but with converting ff to 36 ) + RTN @op-c ( x y char -- ) 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; +static Device *devsystem, *devscreen, *devmouse, *devctrl, *devapu, *devfile; Uint8 zoom = 0, debug = 0, reqdraw = 0; @@ -219,13 +219,14 @@ file_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) Uint8 *m = u->ram.dat; char *name = (char *)&m[(m[ptr + 8] << 8) + m[ptr + 8 + 1]]; Uint16 length = (m[ptr + 8 + 2] << 8) + m[ptr + 8 + 3]; - Uint16 offset = (m[ptr + 0] << 8) + m[ptr + 1]; + Uint16 offset = (m[ptr + 2] << 8) + m[ptr + 3]; if(b0 == 0x0d) { Uint16 addr = (m[ptr + 8 + 4] << 8) + b1; FILE *f = fopen(name, "r"); if(f && fseek(f, offset, SEEK_SET) != -1 && fread(&m[addr], length, 1, f)) { fclose(f); printf("Loaded %d bytes, at %04x from %s\n", length, addr, name); + evaluxn(u, devfile->vector); } } else if(b0 == 0x0f) { Uint16 addr = (m[ptr + 8 + 6] << 8) + b1; @@ -233,6 +234,7 @@ file_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) if(f && fseek(f, offset, SEEK_SET) != -1 && fwrite(&m[addr], length, 1, f)) { fclose(f); printf("Saved %d bytes, at %04x from %s\n", length, addr, name); + evaluxn(u, devfile->vector); } } return b1; @@ -378,7 +380,7 @@ main(int argc, char **argv) devctrl = portuxn(&u, 0x04, "controller", ppnil); portuxn(&u, 0x05, "---", ppnil); devmouse = portuxn(&u, 0x06, "mouse", ppnil); - portuxn(&u, 0x07, "file", file_poke); + devfile = portuxn(&u, 0x07, "file", file_poke); portuxn(&u, 0x08, "---", ppnil); portuxn(&u, 0x09, "midi", ppnil); portuxn(&u, 0x0a, "datetime", datetime_poke); diff --git a/src/ppu.c b/src/ppu.c @@ -12,7 +12,7 @@ WITH REGARD TO THIS SOFTWARE. #include "ppu.h" -Uint8 font[][8] = { +static Uint8 font[][8] = { {0x00, 0x3c, 0x46, 0x4a, 0x52, 0x62, 0x3c, 0x00}, {0x00, 0x18, 0x28, 0x08, 0x08, 0x08, 0x3e, 0x00}, {0x00, 0x3c, 0x42, 0x02, 0x3c, 0x40, 0x7e, 0x00},