~rabbits/drifblim

1fde191c9c8be0e7b8a970f47331900d98c321dc — Devine Lu Linvega a month ago e876028
Stream output
3 files changed, 62 insertions(+), 47 deletions(-)

M build.sh
M examples/hello.tal
M src/drifblim.tal
M build.sh => build.sh +1 -0
@@ 28,3 28,4 @@ uxncli bin/hello.rom

# uxncli bin/drifblim.rom etc/bh.tal bin/bh.rom
# uxncli bin/bh.rom bin/drifblim.rom > bin/bh.log


M examples/hello.tal => examples/hello.tal +1 -0
@@ 17,3 17,4 @@ BRK
JMP2r

~examples/include.tal


M src/drifblim.tal => src/drifblim.tal +60 -47
@@ 2,6 2,7 @@

|10 @Console &vector $2 &read $1 &pad $5 &write $1 &err $1
|a0 @File1 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
|b0 @File2 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2

|0000



@@ 42,8 43,8 @@ BRK
		;&c .File1/read DEO2
		.File1/success DEI2 ORA ?&continue
			,&c LDR #00 EQU ?&err JMP2r
		&continue [ LIT &c $1 ] handle-char !&s
( .. )
		&continue [ LIT &c $1 ] handle-char
!&s
	&err .File1/name DEI2 ;err/source !crash

@handle-char ( c -- )


@@ 66,25 67,22 @@ JMP2r
	&on-sleep ( t* -- ) POP2 JMP2r

(
@|library )
@|core )

@assemble ( src* dst* -- )

	( output )
	.File2/name DEO2
	#0001 .File2/length DEO2
	( pass1 )
	#0100 set-head
	;dict/reset ;scope scpy
	OVR2 handle-file
	( write rom origin )
	;create-label/ptr LDA2 INC2 INC2 ;write/rom STA2
	DUP2 handle-file
	( pass2 )
	#0100 set-head
	;dict/reset ;scope scpy
	#00 ;write/skip STA
	SWP2 handle-file
	( export )
	.File1/name DEO2
	[ LIT2 &length $2 ] #00ff SUB2 .File1/length DEO2
	;write/rom LDA2 #0100 ADD2 .File1/write DEO2
	handle-file

JMP2r



@@ 107,29 105,38 @@ JMP2r
JMP2r

@lib
&padabs INC2 get-hex !set-head
&padrel INC2 get-hex !write-fill
&toplab INC2 ;scope OVR2 SWP2 scpy !create-label
&sublab INC2 make-sublabel !create-label
&litrel #80 write
&rawrel INC2 get-ref get-rel INC !write
&litzep #80 write
&rawzep INC2 get-ref LDA2 NIP !write
&litabs #a0 write
&rawabs INC2 get-ref LDA2 !write-short
&litjci #20 write INC2 !write-call
&litjmi #40 write INC2 !write-call
&litjsi #60 write !write-call
&lithex INC2 DUP2 slen NIP #02 SFT #a080 ROT [ JMP SWP POP ] write
&rawhex !write-hex
&rawstr INC2 !write-str
&opcode find-opcode !write
&inc INC2k ;include STH2k scpy sclr STH2r !handle-file
&ignore POP2 JMP2r
	&padabs INC2 get-hex write-pad !set-head
	&padrel INC2 get-hex !write-fill
	&toplab INC2 ;scope OVR2 SWP2 scpy !create-label
	&sublab INC2 make-sublabel !create-label
	&litrel #80 write
	&rawrel INC2 get-ref get-rel INC !write
	&litzep #80 write
	&rawzep INC2 get-ref LDA2 NIP !write
	&litabs #a0 write
	&rawabs INC2 get-ref LDA2 !write-short
	&litjci #20 write INC2 !write-call
	&litjmi #40 write INC2 !write-call
	&litjsi #60 write !write-call
	&lithex INC2 DUP2 slen NIP #02 SFT #a080 ROT [ JMP SWP POP ] write
	&rawhex !write-hex
	&rawstr INC2 !write-str
	&opcode find-opcode !write
	&inc INC2k ;include STH2k scpy sclr STH2r !handle-file
	&ignore POP2 JMP2r

(
@|primitives )

@write-pad ( addr* -- )

	;write/head LDA2 LTH2k ?&no-pad
		SUB2k write-fill
		&no-pad
	POP2

JMP2r

@write-fill ( len* -- )

	#0000 EQU2k ?&skip


@@ 172,15 179,26 @@ JMP2r

@write ( byte -- )

	[ LIT &skip 01 ] ?&no-write
	,&head LDR2 #0100 LTH2 ?&no-write
		DUP [ LIT2 &rom $2 ] ,&head LDR2 ADD2 STA
		DUP #00 EQU ?&no-write
			[ LIT2 &head 0100 ] ;assemble/length STA2
		&no-write
	[ LIT2 &head 0100 ] #0100 LTH2 ?&ignore
	[ LIT &skip 01 ] ?&pass1
	[ LIT2 &length $2 ] ,&head LDR2 LTH2 ?&ignore
	( pass2 )
	DUP ;&b STAk .File2/write DEO2 POP
	&ignore
	POP
	#0001 move-head

JMP2r

#0001 !move-head
&b $1

&pass1
	DUP #00 EQU ?&no-record
		,&head LDR2 ;write/length STA2
		&no-record
	POP
	#0001 move-head
JMP2r

(
@|helpers )


@@ 201,7 219,7 @@ JMP2r

JMP2r
	&fail POP2 #0003 ADD2 ;err/distance !crash
	&fill POP2 #00 JMP2r
	&fill POP2 #ff JMP2r

@get-ref ( token* -- <label*> )



@@ 219,7 237,7 @@ JMP2r
	INC2k INC2 LDAk INC ROT ROT STA

JMP2r
	&fill 0000 "[empty] $1
	&fill ffff "[empty] $1

@create-label ( name* -- )



@@ 227,7 245,6 @@ JMP2r
	( check name ) DUP2 is-hex ?&invalid
	( check name ) DUP2 is-opcode ?&invalid
	( check duplicate ) DUP2 find-label INC2 ORA ?&not-unique
	( check limit ) ,&ptr LDR2 ;symbols/end GTH2 ?&limit
	( save addr ) ;write/head LDA2 [ LIT2 &ptr =symbols ] STH2k STA2
	( move ) INC2r INC2r INC2r
	( save name ) DUP2 STH2kr scpy


@@ 237,7 254,6 @@ JMP2r
JMP2r
	&invalid ;err/invalid !crash
	&not-unique ;err/duplicate !crash
	&limit ;err/limit !crash
	&skip POP2 JMP2r

@make-sublabel ( name* -- sublabel* )


@@ 347,8 363,7 @@ BRK
	;dict/spacer pstr
	;dst pstr
	( length )
	;dict/in pstr ;assemble/length LDA2 #00ff SUB2 pdec ;dict/bytes pstr
	LIT "( #18 DEO #0000 ;write/rom LDA2 SUB2 ;assemble/length LDA2 SUB2 pdec ;dict/left pstr LIT ") #18 DEO
	;dict/in pstr ;write/length LDA2 #00ff SUB2 pdec ;dict/bytes pstr
	LIT ", #18 DEO #2018 DEO ;create-label/count LDA2 pdec ;dict/labels pstr LIT ". #18 DEO #0a18 DEO

JMP2r


@@ 410,11 425,10 @@ JMP2r
	&input "Input(.tal): 20 $1
	&output "Output(.rom): 20 $1
	&assembled "Assembled 20 $1
	&reset "[reset] $1
	&reset "INIT $1
	&spacer 20 "-> 20 $1
	&in ", 20 "in 20 $1
	&bytes 20 "bytes $1
	&left 20 "left $1
	&labels 20 "labels $1
	&unused "-- 20 "Unused 20 "label: 20 $1



@@ 424,7 438,6 @@ JMP2r
	&number "Number $1
	&reference "Reference $1
	&distance "Distance $1
	&limit "Labels-limit $1
	&invalid "Invalid $1
	&mode "Mode $1



@@ 454,5 467,5 @@ JMP2r
@scope $20
@sublabel $20
@include $30
@symbols $4000 ( addr*, refs, name[], 00 ) &end
@symbols ( addr*, refs, name[], 00 )