This commit is contained in:
neauoire 2022-09-10 12:19:31 -07:00
commit a7ae3d0ca5
5 changed files with 261 additions and 0 deletions

BIN
ray/bin/ray.rom Normal file

Binary file not shown.

34
ray/build.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/sh -e
ASM="uxncli $HOME/roms/drifblim.rom"
EMU="uxnemu"
LIN="uxncli $HOME/roms/uxnlin.rom"
SRC="src/ray.tal"
DST="bin/ray.rom"
CPY="$HOME/roms"
ETC="src/manifest.tal"
ARG=""
echo ">> Cleaning"
rm -rf bin
mkdir bin
if [[ "$*" == *"--lint"* ]]
then
echo ">> Linting $SRC"
$LIN $SRC $ETC
fi
echo ">> Assembling $SRC"
$ASM $SRC $DST
if [[ "$*" == *"--save"* ]]
then
echo ">> Saving $DST"
cp $DST $CPY
fi
echo ">> Running $DST"
$EMU $DST $ARG

BIN
ray/etc/map.chr Normal file

Binary file not shown.

BIN
ray/etc/map.chr.nmt Normal file

Binary file not shown.

227
ray/src/ray.tal Normal file
View File

@ -0,0 +1,227 @@
( a blank file )
|00 @System &vector $2 &wst $1 &rst $1 &eaddr $2 &ecode $1 &pad $1 &r $2 &g $2 &b $2 &debug $1 &halt $1
|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|30 @Audio0 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1
|40 @Audio1 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1
|50 @Audio2 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1
|60 @Audio3 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1
|80 @Controller &vector $2 &button $1 &key $1 &func $1
|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &pad $3 &scrollx $2 &scrolly $2
|a0 @File0 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|b0 @File1 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|c0 @DateTime &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1
( variables )
|0000
@player
&x $2 &y $2 &a $2
@line
&x $2 &y $2 &dx $2 &dy $2 &e1 $2
( program )
|0100 ( -> )
( theme )
#0fe5 .System/r DEO2
#0fc5 .System/g DEO2
#0f25 .System/b DEO2
( vectors )
;on-frame .Screen/vector DEO2
#0060 .player/x STZ2
#0070 .player/y STZ2
#0032 .player/a STZ2
;draw-map JSR2
BRK
(
@|vectors )
@on-frame ( -> )
.player/x LDZ2
.player/y LDZ2
[ LIT2 &range 0020 ] STH2k ;raycast JSR2
OVR2 .player/x LDZ2 STH2kr #01 SFT2 SUB2 ADD2
#03 SFT2 ;print JSR2 #2018 DEO
DUP2 .player/y LDZ2 STH2kr #01 SFT2 SUB2 ADD2
#03 SFT2 ;print JSR2 #0a18 DEO
SWP2 .player/x LDZ2 STH2kr #01 SFT2 SUB2 ADD2 SWP2
.player/y LDZ2 STH2r #01 SFT2 SUB2 ADD2
#02 ;draw-line JSR2
,&range LDR2 INC2 ,&range STR2
BRK
@raycast ( range* -- x* y* )
STH2
.player/a LDZ2 #10 SFT2 ;sin60 ADD2 LDA2
#00 SWP STH2kr MUL2 #08 SFT2 ,&y STR2
#00 SWP STH2r MUL2 #08 SFT2 ,&x STR2
[ LIT2 &x $2 ]
[ LIT2 &y $2 ]
JMP2r
@draw-map ( -- )
#01 .Screen/auto DEO
#0000 .Screen/y DEO2
#1000
&ver
STHk
#0000 .Screen/x DEO2
#1000
&hor
( id ) #00 OVR STHkr #40 SFT ADD
( addr* ) #0003 MUL2 ;nametable ADD2
LDA2k ;spritesheet ADD2 .Screen/addr DEO2
( color ) INC2 INC2 LDA .Screen/sprite DEO
INC GTHk ,&hor JCN
POP2
POPr
.Screen/y DEI2k #0008 ADD2 ROT DEO2
INC GTHk ,&ver JCN
POP2
( draw player )
.player/x LDZ2 #0004 SUB2 .Screen/x DEO2
.player/y LDZ2 #0004 SUB2 .Screen/y DEO2
;player-icn .Screen/addr DEO2
#05 .Screen/sprite DEO
JMP2r
#3c00
&a
#00 OVR .player/a STZ2
#ff00
&r
#00 OVR ;raycast JSR2 ;get-tile JSR2 #00 NEQ ,&collide JCN
INC GTHk ,&r JCN
&collide
POP2
INC GTHk ,&a JCN
POP2
JMP2r
@get-tile ( x* y* -- tile )
#03 SFT2 #0010 SFT2
#03 SFT2 ADD2 #0003 MUL2 ;nametable ADD2 LDZ
JMP2r
@draw-line ( x1* y1* x2* y2* color -- )
( load ) STH ,&y STR2 ,&x STR2 .line/y STZ2 .line/x STZ2
,&x LDR2 .line/x LDZ2 SUB2 ;abs2 JSR2 .line/dx STZ2
#0000 ,&y LDR2 .line/y LDZ2 SUB2 ;abs2 JSR2 SUB2 .line/dy STZ2
#ffff #00 .line/x LDZ2 ,&x LDR2 ;lts2 JSR2 DUP2 ADD2 ADD2 ,&sx STR2
#ffff #00 .line/y LDZ2 ,&y LDR2 ;lts2 JSR2 DUP2 ADD2 ADD2 ,&sy STR2
.line/dx LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
&loop
.line/x LDZ2 DUP2 .Screen/x DEO2 [ LIT2 &x $2 ] EQU2
.line/y LDZ2 DUP2 .Screen/y DEO2 [ LIT2 &y $2 ] EQU2
STHkr .Screen/pixel DEO
AND ,&end JCN
.line/e1 LDZ2 DUP2 ADD2 DUP2
.line/dy LDZ2 ;lts2 JSR2 ,&skipy JCN
.line/e1 LDZ2 .line/dy LDZ2 ADD2 .line/e1 STZ2
.line/x LDZ2 [ LIT2 &sx $2 ] ADD2 .line/x STZ2
&skipy
.line/dx LDZ2 ;gts2 JSR2 ,&skipx JCN
.line/e1 LDZ2 .line/dx LDZ2 ADD2 .line/e1 STZ2
.line/y LDZ2 [ LIT2 &sy $2 ] ADD2 .line/y STZ2
&skipx
,&loop JMP
&end
POPr
JMP2r
@abs2 DUP2 #0f SFT2 EQU #05 JCN #0000 SWP2 SUB2 JMP2r
@lts2 #8000 STH2k ADD2 SWP2 STH2r ADD2 GTH2 JMP2r
@gts2 #8000 STH2k ADD2 SWP2 STH2r ADD2 LTH2 JMP2r
@print ( short* -- )
SWP ,&byte JSR
&byte ( byte -- ) DUP #04 SFT ,&char JSR
&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
JMP2r
@print-str ( str* -- )
&while
LDAk #18 DEO
INC2 LDAk ,&while JCN
POP2
JMP2r
@player-icn
0010 387c 3810 0000
@sin60 ( 60 positions on a circle )
8000 8d00 9a02 a706 b40b c011 cb18 d520
df2a e734 ee40 f44b f958 fd65 ff72 ff80
ff8d fd9a f9a7 f4b4 eec0 e7cb dfd5 d5df
cbe7 c0ee b4f4 a7f9 9afd 8dff 80ff 72ff
65fd 58f9 4bf4 40ee 34e7 2adf 20d5 18cb
11c0 0bb4 06a7 029a 008d 0080 0072 0265
0658 0b4b 113f 1834 202a 2a20 3418 3f11
4b0b 5806 6502 7200
@spritesheet
0000 0000 0000 0000 0000 0000 0000 0000
ffff ffff ffff ffff 0000 0000 0000 0000
0000 0000 0000 0000 ffff ffff ffff ffff
ffff ffff ffff ffff ffff ffff ffff ffff
0000 0000 0000 0000 ffff ffff ffff ffff
ffff ffff ffff ffff ffff ffff ffff ffff
0000 0000 0000 0000 ffff ffff ffff ffff
ffff ffff ffff ffff ffff ffff ffff ffff
@nametable
0010 8100 1081 0010 8100 1081 0010 8100 1081 0010 8100 1081 0010 8100 1081 0010
8100 1081 0010 8100 1081 0010 8100 1081 0010 8100 0081 0000 8100 0081 0000 8100
0081 0000 8100 0081 0000 8100 0081 0000 8100 0081 0000 8100 0081 0000 8100 1081
0010 8100 0081 0000 8100 0081 0000 8100 2081 0020 8100 0081 0000 8100 0081 0000
8100 0081 0000 8100 0081 0000 8100 1081 0010 8100 0081 0000 8100 0081 0000 8100
1081 0000 8100 0081 0010 8100 1081 0010 8100 1081 0010 8100 3081 0030 8100 1081
0010 8100 0081 0000 8100 0081 0000 8100 1081 0000 8100 0081 0000 8100 0081 0000
8100 0081 0000 8100 0081 0000 8100 1081 0010 8100 0081 0000 8100 0081 0000 8100
1081 0000 8100 0081 0000 8100 0081 0000 8100 0081 0000 8100 0081 0000 8100 1081
0010 8100 0081 0000 8100 1081 0010 8100 1081 0010 8100 1081 0010 8100 1081 0000
8100 0081 0000 8100 0081 0000 8100 1081 0010 8100 0081 0000 8100 1081 0000 8100
0081 0000 8100 0081 0000 8100 2081 0020 8100 2081 0020 8100 0081 0000 8100 1081
0010 8100 0081 0000 8100 1081 0000 8100 0081 0000 8100 0081 0000 8100 1081 0000
8100 0081 0000 8100 0081 0000 8100 1081 0010 8100 0081 0000 8100 1081 0000 8100
0081 0000 8100 0081 0000 8100 1081 0000 8100 2081 0020 8100 2081 0020 8100 2081
0010 8100 0081 0000 8100 0081 0000 8100 0081 0000 8100 0081 0000 8100 3081 0000
8100 0081 0000 8100 0081 0000 8100 2081 0020 8100 0081 0000 8100 0081 0000 8100
0081 0000 8100 0081 0000 8100 3081 0000 8100 0081 0000 8100 0081 0000 8100 2081
0020 8100 0081 0000 8100 0081 0000 8100 0081 0000 8100 0081 0000 8100 1081 0000
8100 0081 0000 8100 0081 0000 8100 2081 0020 8100 0081 0010 8100 1081 0020 8100
2081 0020 8100 2081 0010 8100 1081 0000 8100 0081 0000 8100 0081 0000 8100 1081
0020 8100 0081 0000 8100 0081 0000 8100 0081 0000 8100 0081 0000 8100 0081 0000
8100 0081 0000 8100 0081 0000 8100 1081 0020 8100 2081 0020 8100 1081 0010 8100
1081 0010 8100 3081 0030 8100 3081 0010 8100 1081 0020 8100 2081 0010 8100 1081