Skip to content

Commit

Permalink
examples clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Maya Karabula-Stysiak committed Apr 21, 2023
1 parent 224f2f2 commit 412e67f
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 2 deletions.
3 changes: 3 additions & 0 deletions devices/screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ function screen_resize(p: UxnScreen, width: number, height: number)
p.height = height;
screen_fill(p, p.bg, 0, 0, p.width, p.height, 0);
screen_fill(p, p.fg, 0, 0, p.width, p.height, 0);

console.log('resize', p)
}

function screen_redraw(p: UxnScreen)
Expand Down Expand Up @@ -156,6 +158,7 @@ export function screen_dei(u: Uxn, addr: number)

export function screen_deo(ram: number[], d: number[], port: number)
{
console.log('SCREN DEO', port)
switch(port) {
case 0x3:
if(!FIXED_SIZE)
Expand Down
Binary file added examples/cube.rom
Binary file not shown.
Binary file added examples/cube.rom.sym
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file added examples/pixels.rom
Binary file not shown.
27 changes: 27 additions & 0 deletions examples/pixels.tal
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
( hello-pixels.tal )

( devices )
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]

( macros )
%DRAW-PIXEL { #41 .Screen/pixel DEO } ( -- )
%INC-X { .Screen/x DEI2 INC2 .Screen/x DEO2 } ( -- )

( main program )
|0100
#2ce9 .System/r DEO2
#01c0 .System/g DEO2
#2ce5 .System/b DEO2

( set initial x,y coordinates )
#0008 .Screen/x DEO2
#0008 .Screen/y DEO2

( draw 6 pixels in an horizontal line )
DRAW-PIXEL INC-X
DRAW-PIXEL INC-X
DRAW-PIXEL INC-X
DRAW-PIXEL INC-X
DRAW-PIXEL INC-X
DRAW-PIXEL
Binary file added examples/screen.rom
Binary file not shown.
Binary file added examples/screen.rom.sym
Binary file not shown.
216 changes: 216 additions & 0 deletions examples/screen.tal
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
( Screen:
Draws a table of all possible sprite arrangements. )

|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &chord $1

|0000

@center &x $2 &y $2

|0100 ( -> )

( vector )
;on-frame .Screen/vector DEO2
( theme )
#f07f .System/r DEO2
#f0e0 .System/g DEO2
#f0c0 .System/b DEO2
( gba screen size 00f0 x 00a0 )
( nds screen size 0100 x 00c0 )
#0100 .Screen/width DEO2
#00b0 .Screen/height DEO2
( find screen center )
.Screen/width DEI2 #01 SFT2 .center/x STZ2
.Screen/height DEI2 #01 SFT2 .center/y STZ2
( draw )
draw-size
draw-sprites
draw-1bpp
draw-2bpp

BRK

(
@|vectors )

@on-frame ( -> )

( scroll background )
[ LIT2 &f $2 ] INC2k ,&f STR2
#01 SFT2
#001f AND2
#0040 SUB2
DUP2 .Screen/x DEO2
.Screen/y DEO2
;patt-icn draw-fill

.center/x LDZ2 #0070 SUB2 .Screen/x DEO2
.center/y LDZ2 #0048 SUB2 .Screen/y DEO2
;anim-chr ,&f LDR2 #00ff AND2 #02 SFT #07 AND #40 SFT ADD2 .Screen/addr DEO2
#8f .Screen/sprite DEO

draw-size
draw-sprites
draw-1bpp
draw-2bpp

BRK

(
@|drawing )

@draw-sprites ( -- )

( horizontal )
.center/x LDZ2 #0060 SUB2 .Screen/x DEO2
.center/y LDZ2 #0048 SUB2 .Screen/y DEO2
;font-icn .Screen/addr DEO2
#f6 .Screen/auto DEO
#05 .Screen/sprite DEO
( vertical )
.center/x LDZ2 #0070 SUB2 .Screen/x DEO2
.center/y LDZ2 #0038 SUB2 .Screen/y DEO2
;font-icn .Screen/addr DEO2
#f5 .Screen/auto DEO
#05 .Screen/sprite DEO
( table )
#00 .Screen/auto DEO
;preview-chr .Screen/addr DEO2
#00
&loop
( move ) #00 OVR #0f AND #30 SFT
.center/x LDZ2 #0060 SUB2 ADD2 .Screen/x DEO2
( move ) #00 OVR #f0 AND #01 SFT
.center/y LDZ2 #0038 SUB2 ADD2 .Screen/y DEO2
( draw ) DUP .Screen/sprite DEO
INC DUP ?&loop
POP

JMP2r

@draw-1bpp ( -- )

#1000
&loop
( color ) STHk
( y ) #00 OVR #42 SFT2
.center/y LDZ2 #0038 SUB2 ADD2 STH2
( x ) #00 OVR #03 AND #40 SFT2 #0040 ADD2
.center/x LDZ2 #0010 SUB2 ADD2
STH2r STHr #00 draw-circle
INC GTHk ?&loop
POP2

JMP2r

@draw-2bpp ( -- )

#1000
&loop
( color ) STHk
( y ) #00 OVR #42 SFT2
.center/y LDZ2 #0008 ADD2 ADD2 STH2
( x ) #00 OVR #03 AND #40 SFT2 #0040 ADD2
.center/x LDZ2 #0010 SUB2 ADD2
STH2r STHr #80 draw-circle
INC GTHk ?&loop
POP2

JMP2r

@draw-circle ( x* y* color depth -- )

ADD STH
;preview-chr .Screen/addr DEO2
.Screen/y DEO2
.Screen/x DEO2
#01 .Screen/auto DEO
STHr .Screen/sprite DEOk
#02 .Screen/auto DEO
SWP #10 ADD SWP DEOk
.Screen/x DEI2k #0008 SUB2 ROT DEO2
#01 .Screen/auto DEO
SWP #10 ADD SWP DEOk
SWP #10 ADD SWP DEO

JMP2r

@draw-fill ( patt* color -- )

.Screen/addr DEO2
[ LIT2 01 -Screen/auto ] DEO
.Screen/x DEI2 ,&anchor STR2
.Screen/width DEI2 #03 SFT2 NIP #08 ADD ,&x STR
.Screen/height DEI2 #03 SFT2 NIP #08 ADD #00
&h
DUP #02 SFT STH
[ LIT &x $1 ] #00
&w
DUP #02 SFT STHkr ADD #01 AND .Screen/sprite DEO
INC GTHk ?&w
.Screen/y DEI2k #0008 ADD2 ROT DEO2
[ LIT2 &anchor $2 ] .Screen/x DEO2
POP2 POPr
INC GTHk ?&h
POP2

JMP2r

@draw-size ( -- )

#01 .Screen/auto DEO
.center/x LDZ2 #0030 ADD2 .Screen/x DEO2
.center/y LDZ2 #0048 SUB2 .Screen/y DEO2
.Screen/width DEI2 draw-dec
;x-icn .Screen/addr DEO2
#01 .Screen/sprite DEO
.Screen/height DEI2

@draw-dec ( short* -- )

#00 ,&z STR
#2710 draw-dec/parse
#03e8 draw-dec/parse
#0064 draw-dec/parse
#000a draw-dec/parse
NIP
&emit
DUP [ LIT &z $1 ] EQU ?&skip
#ff ,&z STR #00 OVR #30 SFT ;font-icn ADD2 .Screen/addr DEO2
#01 .Screen/sprite DEO
&skip
POP

JMP2r
&parse DIV2k DUP ,&emit JSR MUL2 SUB2 JMP2r

(
@|assets )

@patt-icn [
aa55 aa55 aa55 aa55 ]
@x-icn [
0000 0018 1800 0000 ]
@preview-chr [
0f38 675f dfbf bfbf 0007 1820 2344 4848 ]
@font-icn ( 0-f ) [
007c 8282 8282 827c 0030 1010 1010 1010
007c 8202 7c80 80fe 007c 8202 1c02 827c
000c 1424 4484 fe04 00fe 8080 7c02 827c
007c 8280 fc82 827c 007c 8202 1e02 0202
007c 8282 7c82 827c 007c 8282 7e02 827c
007c 8202 7e82 827e 00fc 8282 fc82 82fc
007c 8280 8080 827c 00fc 8282 8282 82fc
007c 8280 f080 827c 007c 8280 f080 8080 [
@anim-chr [
0000 0018 1800 0000 c381 0000 0000 81c3
0000 183c 3c18 0000 0000 0000 0000 0000
0018 3c7e 7e3c 1800 0000 0000 0000 0000
3c7e ffe7 e7ff 7e3c 0000 0018 1800 0000
ffff e7c3 c3e7 ffff 0000 183c 3c18 0000
ffe7 c381 81c3 e7ff 0018 3c7e 7e3c 1800
c381 0000 0000 81c3 3c7e ffe7 e7ff 7e3c
0000 0000 0000 0000 ffff e7c3 c3e7 ffff
0000 0000 0000 0000 ffe7 c381 81c3 e7ff ]
File renamed without changes.
Binary file added examples/sprites.rom.sym
Binary file not shown.
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "",
"scripts": {
"start": "ts-node uxncli.ts ./hello.rom"
"build": "tsc"
},
"keywords": [],
"author": "",
Expand Down
2 changes: 2 additions & 0 deletions uxn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export function uxn_eval(u: Uxn, pc: number): number {
s = ins & 0x40 ? u.rst : u.wst;
opc = (!(ins & 0x1f) ? 0 - (ins >> 5) : ins & 0x3f);

console.log(opc, opc.toString(16))

switch(opc) {
/* IMM */
case -0x00: /* BRK */ return 1;
Expand Down
7 changes: 6 additions & 1 deletion uxnemu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export function uxn_deo(u: Uxn, addr: number): void {
function draw () {
const canvas = document.getElementById('canvas') as HTMLCanvasElement

canvas.width = uxn_screen.width
canvas.height = uxn_screen.height

if (canvas) {
const ctx = canvas.getContext('2d')

Expand Down Expand Up @@ -101,10 +104,12 @@ function main(): number {
return emu_error("Load", "Failed");
}

if (!uxn_eval(u, (PAGE_PROGRAM))) {
if (!uxn_eval(u, (PAGE_PROGRAM))) {
return u.dev[0x0f] & 0x7f;
}

console.log({ u, uxn_screen })

draw()

return 0
Expand Down

0 comments on commit 412e67f

Please sign in to comment.