~rabbits/cccc

8af56207568a0bb932d942c8a2670a765b80157c — neauoire 5 months ago 8e40357 + ee20b2b
Merge branch 'main' of git.sr.ht:~rabbits/cccc
6 files changed, 1798 insertions(+), 356 deletions(-)

D .theme
A etc/.theme
A etc/cccc-old.tal
R etc/{spritesheet.chr => ss10x10.chr}
A etc/ss10x10.chr.nmt
M src/cccc.tal
D .theme => .theme +0 -1
@@ 1,1 0,0 @@
���
\ No newline at end of file

A etc/.theme => etc/.theme +1 -0
@@ 0,0 1,1 @@
P����
\ No newline at end of file

A etc/cccc-old.tal => etc/cccc-old.tal +1364 -0
@@ 0,0 1,1364 @@
( app/cccc : graphical calculator 52428 )

|00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2
|10 @Console &vector $2 &read $1 &pad $5 &write $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
|80 @Controller &vector $2 &button $1 &key $1
|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &chord $1
|a0 @File &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2

|0000

	@mode
		&dec $1
		&dot $1
	@cursor
		&x $2 &y $2
	@input $8
	@length $2

|0100

	( theme )
	#d70f .System/r DEO2
	#c80f .System/g DEO2
	#a80f .System/b DEO2
	;load-theme JSR2

	( size )
	#0080 .Screen/width DEO2
	#0128 .Screen/height DEO2

	( setup synth )
	#0048 .Audio0/adsr DEO2
	;tone .Audio0/addr DEO2
	#0100 .Audio0/length DEO2
	#ff .Audio0/volume DEO ( TODO: turn ON )

	( initial draw )
	;redraw JSR2

	( draw mem )
	#01 .Screen/auto DEO
	#0018 .Screen/x DEO2
	#0018 .Screen/y DEO2
	#0000 ;memory SUB2 ;draw-dec JSR2
	;&mem-txt ;draw-str JSR2

	( vectors )
	;on-console .Console/vector DEO2
	;on-button .Controller/vector DEO2
	;on-mouse .Mouse/vector DEO2
	;on-frame .Screen/vector DEO2

BRK
	&mem-txt 20 "free $1

(
@|vectors )

@on-console ( -> )

	.Console/read DEI ;listen JSR2

BRK

@on-button ( -> )

	.Controller/button DEI2 #01 LIT "v NEQ2 ,&no-paste JCN
		;snarf-paste JSR2
		&no-paste

	.Controller/key DEI ;listen JSR2

BRK

@on-frame ( -> )

	( delay )
	[ LIT &f 00 ] INCk ,&f STR #03 AND #00 EQU [ JMP BRK ]

	( find buttons )
	;buttons/end ;buttons
	&loop
		#0008 ADD2 LDAk #00 EQU ,&continue JCN
			( decr time )
			DUP2 LDAk #01 SUB ROT ROT STA
			( release button )
			LDAk #00 NEQ ,&continue JCN
				DUP2 #0008 SUB2 #00 ;press-button/release JSR2
			&continue
		INC2 GTH2k ,&loop JCN
	POP2 POP2

BRK

@on-mouse ( -> )

	( clear last cursor )
	#40 ;draw-cursor JSR2

	( draw new cursor )
	.Mouse/x DEI2 .cursor/x STZ2
	.Mouse/y DEI2 .cursor/y STZ2
	;cursor-icn .Screen/addr DEO2
	.Mouse/state DEI #00 NEQ DUP ADD #41 ADD ;draw-cursor JSR2

	.Mouse/state DEI ,&on-mouse-touch JCN

BRK
	&on-mouse-touch ( -> )

	.Mouse/x DEI2 #0010 SUB2 #03 SFT2 NIP #03 DIV
	.Mouse/y DEI2 #0068 SUB2 #03 SFT2 NIP
	#00 .Mouse/state DEO

	OVR #03 GTH ,&skip JCN
	DUP #02 LTH ,on-touch-ctlpad JCN
	DUP #08 LTH ,on-touch-modpad JCN
	DUP #0a LTH ,on-touch-wstpad JCN
	DUP #16 LTH ,on-touch-numpad JCN
	&skip
	POP2

BRK

@on-touch-ctlpad ( x/3 y -> )

	( id ) POP
	#00 SWP #03 MUL INC ;keys/ctl ADD2 LDA2 JSR2

BRK

@on-touch-modpad ( x/3 y -> )

	( id ) #02 SUB
	#03 DIV #20 SFT ADD
	#00 SWP #03 MUL INC ;keys/mod ADD2 LDA2 JSR2

BRK

@on-touch-wstpad ( x/3 y -> )

	( id ) POP
	#00 SWP #03 MUL INC ;keys/wst ADD2 LDA2 JSR2

BRK

@on-touch-numpad ( x/3 y -> )

	( id ) #0a SUB
	#03 DIV #20 SFT ADD
	#00 SWP #03 MUL INC ;keys/num ADD2 LDA2 JSR2

BRK

@listen ( c -- )

	STHk
	#00 EQU ,&skip JCN

	;keys/end ;keys
	&loop
		LDAk STHkr NEQ ,&continue JCN
			INC2k LDA2 JSR2 ,&end JMP
			&continue
		INC2 INC2 INC2 GTH2k ,&loop JCN
	&end
	POP2 POP2
	&skip
	POPr

JMP2r

@eval ( -- )

	.input LDZ #00 EQU ,&skip JCN
		;buttons/push ;press-button JSR2
		;input ;sval JSR2 #0001 ;push JSR2
		;draw-display JSR2
		;clear-input JSR2
		;input #0008 ;mclr JSR2
		&skip

JMP2r

@append ( char -- )

	;input ;slen JSR2 #0003 .mode/dec LDZ ADD GTH2 ,&skip JCN
		DUP ;input ;sput JSR2
		;draw-input JSR2
		&skip
	POP

JMP2r

@erase ( -- )

	( clamp )
	.input LDZ ,&has-input JCN
		;buttons/pop ;press-button JSR2
		.length LDZ2 ORA #01 JCN JMP2r
		;pop JSR2 POP2 POP2
		;draw-display JMP2
		&has-input

	;input ;spop JSR2
	;clear-input JSR2
	;draw-input ( .. )

JMP2

@clear ( -- )

	;buttons/clr ;press-button JSR2
	#0000 .length STZ2
	;input #0008 ;mclr JSR2
	;draw-display JSR2
	;clear-input ( .. )

JMP2

@tog-mode ( -- )

	;buttons/mode ;press-button JSR2
	.mode/dec LDZk INC #01 AND SWP STZ
	.mode/dot LDZk .mode/dec LDZ #00 EQU ADD #01 AND SWP STZ
	;draw-display JSR2
	;draw-mode ( .. )

JMP2

@set-dec ( -- )

	#01 .mode/dec STZ
	;draw-display JSR2
	;draw-mode ( .. )

JMP2

@set-hex ( -- )

	#00 .mode/dec STZ
	;draw-display JSR2
	;draw-mode ( .. )

JMP2

@gcd ( num* den* -- d* ) ORAk ,&ok JCN POP2 JMP2r &ok SWP2 OVR2 ( MOD2 ) [ DIV2k MUL2 SUB2 ] ,gcd JMP

@push ( num* den* -- )

	OVR2 #0000 EQU2 ,&invalid JCN
	ORAk #00 EQU ,&invalid JCN
	( reduce )
	OVR2 OVR2 ,gcd JSR STH2k DIV2 SWP2 STH2r DIV2
	( store )
	.length LDZ2 #20 SFT2 ;memory ADD2 STH2k STA2
	STH2r INC2 INC2 STA2
	.length LDZ2k INC2 ROT STZ2

JMP2r
	&invalid POP2 POP2 JMP2r

@pop ( -- num* den* )

	.length LDZ2 #01 SUB #20 SFT2 ;memory ADD2
	LDA2k SWP2 INC2 INC2 LDA2
	.length LDZ2k #0001 SUB2 ROT STZ2

JMP2r

@dup ( -- )

	;buttons/dup ;press-button JSR2
	;eval JSR2
	.length LDZ2 ORA #01 JCN JMP2r

	;pop JSR2 OVR2 OVR2 ;push JSR2 ;push JSR2
	;draw-display ( .. )

JMP2

@swp ( -- )

	;buttons/swp ;press-button JSR2
	;eval JSR2
	.length LDZ2 #0002 LTH2 ,&skip JCN

	;pop JSR2 ;pop JSR2 ROT2 STH2 ROT2 STH2r ;push JSR2 ;push JSR2
	;draw-display JSR2
	&skip

JMP2r

@vid ( -- )

	;buttons/vid ;press-button JSR2
	;eval JSR2
	.length LDZ2 ORA #01 JCN JMP2r
	.length LDZ2 #20 SFT2 #0002 SUB2 ;memory ADD2 LDA2 #0001 EQU2 ,&skip JCN

	;pop JSR2 SWP2 #0001 ;push JSR2
	#0001 ;push JSR2
	;draw-display JSR2
	&skip

JMP2r

@inv ( -- )

	;buttons/inv ;press-button JSR2
	;eval JSR2
	.length LDZ2 ORA #01 JCN JMP2r

	;pop JSR2 SWP2 ;push JSR2
	;draw-display ( .. )

JMP2

@add ( -- )

	;buttons/add ;press-button JSR2
	;eval JSR2
	.length LDZ2 #0002 LTH2 ,&skip JCN

	;pop JSR2 ,&bd STR2 ,&bn STR2
	;pop JSR2 ,&ad STR2 ,&an STR2
	[ LIT2 &an $2 ] [ LIT2 &bd $2 ] MUL2
	[ LIT2 &ad $2 ] [ LIT2 &bn $2 ] MUL2 ADD2
	,&ad LDR2 ,&bd LDR2 MUL2 ;push JSR2
	;draw-display JSR2
	&skip

JMP2r

@sub ( -- )

	;buttons/sub ;press-button JSR2
	;eval JSR2
	.length LDZ2 #0002 LTH2 ,&skip JCN

	;pop JSR2 ,&bd STR2 ,&bn STR2
	;pop JSR2 ,&ad STR2 ,&an STR2
	[ LIT2 &an $2 ] [ LIT2 &bd $2 ] MUL2
	[ LIT2 &ad $2 ] [ LIT2 &bn $2 ] MUL2 SUB2
	,&ad LDR2 ,&bd LDR2 MUL2 ;push JSR2
	;draw-display JSR2
	&skip

JMP2r

@mul ( -- )

	;buttons/mul ;press-button JSR2
	;eval JSR2
	.length LDZ2 #0002 LTH2 ,&skip JCN

	;pop JSR2 ,&bd STR2 ,&bn STR2
	;pop JSR2 ,&ad STR2 ,&an STR2
	[ LIT2 &an $2 ] [ LIT2 &bn $2 ] MUL2
	[ LIT2 &ad $2 ] [ LIT2 &bd $2 ] MUL2
		;push JSR2
	;draw-display JSR2
	&skip

JMP2r

@div ( -- )

	;buttons/div ;press-button JSR2
	;eval JSR2
	.length LDZ2 #0002 LTH2 ,&skip JCN

	;pop JSR2 ,&bd STR2 ,&bn STR2
	;pop JSR2 ,&ad STR2 ,&an STR2
	[ LIT2 &an $2 ] [ LIT2 &bd $2 ] MUL2
	[ LIT2 &ad $2 ] [ LIT2 &bn $2 ] MUL2
		;push JSR2
	;draw-display JSR2
	&skip

JMP2r

@and ( -- )

	;buttons/and ;press-button JSR2
	;eval JSR2
	.length LDZ2 #0002 LTH2 ,&skip JCN

	;pop JSR2 ,&bd STR2 ,&bn STR2
	;pop JSR2 ,&ad STR2 ,&an STR2
	[ LIT2 &an $2 ] [ LIT2 &bd $2 ] MUL2
	[ LIT2 &ad $2 ] [ LIT2 &bn $2 ] MUL2 AND2
	,&ad LDR2 ,&bd LDR2 MUL2 ;push JSR2
	;draw-display JSR2
	&skip

JMP2r

@ora ( -- )

	;buttons/ora ;press-button JSR2
	;eval JSR2
	.length LDZ2 #0002 LTH2 ,&skip JCN

	;pop JSR2 ,&bd STR2 ,&bn STR2
	;pop JSR2 ,&ad STR2 ,&an STR2
	[ LIT2 &an $2 ] [ LIT2 &bd $2 ] MUL2
	[ LIT2 &ad $2 ] [ LIT2 &bn $2 ] MUL2 ORA2
	,&ad LDR2 ,&bd LDR2 MUL2 ;push JSR2
	;draw-display JSR2
	&skip

JMP2r

@sfl ( -- )

	;buttons/sfl ;press-button JSR2
	;eval JSR2
	.length LDZ2 ORA #01 JCN JMP2r

	;pop JSR2 SWP2 DUP2 ADD2 SWP2 ;push JSR2
	;draw-display ( .. )

JMP2

@sfr ( -- )

	;buttons/sfr ;press-button JSR2
	;eval JSR2
	.length LDZ2 ORA #01 JCN JMP2r

	;pop JSR2 SWP2 #01 SFT2 SWP2 ;push JSR2
	;draw-display ( .. )

JMP2

@put0 ( -- )
	;buttons/0 ;press-button JSR2
	#0b ;play-note JSR2
	LIT "0 ;append JMP2
@put1 ( -- ) 
	;buttons/1 ;press-button JSR2
	#0c ;play-note JSR2
	LIT "1 ;append JMP2
@put2 ( -- ) 
	;buttons/2 ;press-button JSR2
	#0e ;play-note JSR2
	LIT "2 ;append JMP2
@put3 ( -- ) 
	;buttons/3 ;press-button JSR2
	#10 ;play-note JSR2
	LIT "3 ;append JMP2
@put4 ( -- ) 
	;buttons/4 ;press-button JSR2
	#11 ;play-note JSR2
	LIT "4 ;append JMP2
@put5 ( -- ) 
	;buttons/5 ;press-button JSR2
	#13 ;play-note JSR2
	LIT "5 ;append JMP2
@put6 ( -- ) 
	;buttons/6 ;press-button JSR2
	#15 ;play-note JSR2
	LIT "6 ;append JMP2
@put7 ( -- ) 
	;buttons/7 ;press-button JSR2
	#17 ;play-note JSR2
	LIT "7 ;append JMP2
@put8 ( -- ) 
	;buttons/8 ;press-button JSR2
	#18 ;play-note JSR2
	LIT "8 ;append JMP2
@put9 ( -- ) 
	;buttons/9 ;press-button JSR2
	#1a ;play-note JSR2
	LIT "9 ;append JMP2
@puta ( -- ) 
	;buttons/a ;press-button JSR2
	#09 ;play-note JSR2
	LIT "a ;append JMP2
@putb ( -- ) 
	;buttons/b ;press-button JSR2
	#07 ;play-note JSR2
	LIT "b ;append JMP2
@putc ( -- ) 
	;buttons/c ;press-button JSR2
	#21 ;play-note JSR2
	LIT "c ;append JMP2
@putd ( -- ) 
	;buttons/d ;press-button JSR2
	#1f ;play-note JSR2
	LIT "d ;append JMP2
@pute ( -- ) 
	;buttons/e ;press-button JSR2
	#1d ;play-note JSR2
	LIT "e ;append JMP2
@putf ( -- ) 
	;buttons/f ;press-button JSR2
	#1c ;play-note JSR2
	LIT "f ;append JMP2

@press-button ( button* -- )

	( set timer )
	DUP2 #0008 ADD2 #04 ROT ROT STA
	#01
	&release ( button* state -- )
	STH
	LDA2k .Screen/x DEO2
	INC2 INC2 LDA2k .Screen/y DEO2
	INC2 INC2 LDA2k ( icon )
	SWP2 INC2 INC2 LDA2 STHr ROT ROT ( .. )

JMP2

@play-note ( pitch -- )

	#24 ADD .Audio0/pitch DEO

JMP2r

( drawing )

@redraw ( -- )

	#04 ;buttons/ctl ;draw-pad JSR2
	#08 ;buttons/mod ;draw-pad JSR2
	#04 ;buttons/wst ;draw-pad JSR2
	#10 ;buttons/num ;draw-pad JSR2
	;draw-display JSR2
	;clear-input JSR2

	( frame )
	#0000 DUP2
	.Screen/width DEI2 #03 SFT2 NIP #02 SUB
	.Screen/height DEI2 #03 SFT2 NIP #02 SUB
	;outline-frame
		;draw-frame JSR2

	( decal )
	#16 .Screen/auto DEO
	#0010 .Screen/x DEO2
	#0003 .Screen/y DEO2
	;decal-icn .Screen/addr DEO2
	#01 .Screen/sprite DEO

	( logo )
	#01 .Screen/auto DEO
	#0050 .Screen/x DEO2
	.Screen/height DEI2 #000a SUB2 .Screen/y DEO2
	;logo-icn .Screen/addr DEO2
	#01 .Screen/sprite DEOk DEOk DEOk DEO

JMP2r

@clear-input ( -- )

	#62 .Screen/auto DEO
	#0018 .Screen/x DEO2
	#0050 .Screen/y DEO2
	;fill-icn .Screen/addr DEO2
	#02 .Screen/sprite DEO

@draw-mode ( -- )

	#0050 .Screen/x DEO2
	#0050 .Screen/y DEO2
	#08 ;draw-char/color STA
	#01 .Screen/auto DEO
	LIT ". LIT "/ .mode/dot LDZ [ JMP SWP POP ] ;draw-char JSR2
	;&modes #00 .mode/dec LDZ #03 MUL ADD2 ;draw-str ( .. )

JMP2
	&modes "hx $1 "dc $1

@draw-input ( -- )

	#0018 .Screen/x DEO2
	#0050 .Screen/y DEO2
	#0b ;draw-char/color STA
	;input ;draw-str ( .. )

JMP2

@draw-display ( -- )

	#0010 DUP2 #0a08 [ LIT2 &style :display-frame/def ] ;draw-frame JSR2
	#0018 .Screen/x DEO2
	#0018 .Screen/y DEO2
	#0a06 ;fill-icn #02 ;draw-patt JSR2

	#0018 .Screen/x DEO2
	#0a ;draw-dotted JSR2

	#05 ;draw-char/color STA
	( memory )
	#0600
	&loop
		#00 OVR INC .length LDZ2 GTH2 ,&end JCN
		#0018 .Screen/x DEO2
		#00 OVR #30 SFT2 #0040 SWP2 SUB2 .Screen/y DEO2
		#00 OVR INC .length LDZ2 SWP2 SUB2 #20 SFT2 ;memory ADD2 ;draw-fraction JSR2
		INC GTHk ,&loop JCN
		&end
	POP2

JMP2r

@draw-patt ( w h patt* color -- )

	,&color STR
	.Screen/addr DEO2
	.Screen/x DEI2 ,&x STR2
	#01 .Screen/auto DEO
	SWP STH
	#00
	&hloop
		[ LIT2 &x $2 ] .Screen/x DEO2
		STHkr #00
		&wloop
			[ LIT &color 0f ] .Screen/sprite DEO
			INC GTHk ,&wloop JCN
		POP2
		.Screen/y DEI2k #0008 ADD2 ROT DEO2
		INC GTHk ,&hloop JCN
	POP2
	POPr
	,&x LDR2 .Screen/x DEO2
	#00 .Screen/auto DEO

JMP2r

@draw-pad ( length sprites* -- )

	STH2
	#00
	&loop
		#00 OVR #0009 MUL2 STH2kr ADD2 #00 ;press-button/release JSR2
		INC GTHk ,&loop JCN
	POP2
	POP2r

JMP2r

@draw-button-special ( icon* state -- )

	#05 ,draw-button-small/color STR
	,draw-button-small JSR
	#0a ,draw-button-small/color STR

JMP2r

@draw-button-small ( icon* state -- )

	#00 NEQ STH
	#26 .Screen/auto DEO
	[ LIT2 &alt :button/alt ] [ LIT2 &def :button/def ]
		STHkr [ JMP SWP2 POP2 ] STH2k .Screen/addr DEO2
	#81 .Screen/sprite DEO
	STH2r #0060 ADD2 .Screen/addr DEO2
	#81 .Screen/sprite DEO
	( icon )
	.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
	.Screen/y DEI2 #000c SUB2 #00 STHr ADD2 .Screen/y DEO2
	#00 .Screen/auto DEO
	.Screen/addr DEO2
	[ LIT &color 0a ] .Screen/sprite DEOk DEO

JMP2r

@draw-button-hex ( icon* state -- )

	#05 ,draw-button/color STR
	,draw-button JSR
	#0a ,draw-button/color STR

JMP2r

@draw-button ( icon* state -- )

	#00 NEQ STH
	#26 .Screen/auto DEO
	[ LIT2 &alt :button/alt ] [ LIT2 &def :button/def ]
		STHkr [ JMP SWP2 POP2 ] .Screen/addr DEO2
	#81 .Screen/sprite DEOk DEOk DEO
	( icon )
	.Screen/x DEI2 #0004 ADD2 .Screen/x DEO2
	.Screen/y DEI2 #0014 SUB2 #00 STHr ADD2 .Screen/y DEO2
	#16 .Screen/auto DEO
	.Screen/addr DEO2
	[ LIT &color 0a ] .Screen/sprite DEOk DEO

JMP2r

@os8 ( -- )

	( theme )
	#f80f .System/r DEO2
	#f80f .System/g DEO2
	#fb0f .System/b DEO2

	#0000 DUP2 .Screen/x DEO2 .Screen/y DEO2
	.Screen/width DEI2 #03 SFT2 NIP
	.Screen/height DEI2 #03 SFT2 NIP
	;patt-icn #01
		;draw-patt JSR2

	;button/os8-def ;draw-button-small/def STA2
	;button/os8-alt ;draw-button-small/alt STA2
	;button/os8-def ;draw-button/def STA2
	;button/os8-alt ;draw-button/alt STA2
	;display-frame/os8 ;draw-display/style STA2
	;redraw ( .. )

JMP2

@draw-fraction ( addr* -- )

	#01 .Screen/auto DEO
	LDA2k SWP2 INC2 INC2 LDA2
	DUP2 #0001 EQU2 ,&whole JCN
	GTH2k ,&mixed JCN

&proper ( num* den* -- )

	.mode/dot LDZ ,&proper-dot JCN
	SWP2 ,draw-value JSR
	LIT "/ ;draw-char JSR2
	,draw-value ( .. )

JMP

&proper-dot ( num* den* -- )

	LIT "0 ;draw-char JSR2
	LIT ". ;draw-char JSR2
	SWP2 #03e8 #1000 .mode/dec LDZ [ JMP SWP2 POP2 ] MUL2 SWP2 DIV2
	,draw-value ( .. )

JMP

&mixed ( num* den* -- )

	.mode/dot LDZ ,&mixed-dot JCN
	DIV2k ,draw-value JSR
	LIT "' ;draw-char JSR2
	STH2k ( MOD2 ) [ DIV2k MUL2 SUB2 ] STH2r
	,&proper ( .. )

JMP

&mixed-dot ( num* den* -- )

	DIV2k ,draw-value JSR
	LIT ". ;draw-char JSR2
	STH2k ( MOD2 ) [ DIV2k MUL2 SUB2 ] STH2r
	SWP2 #03e8 #1000 .mode/dec LDZ [ JMP SWP2 POP2 ] MUL2 SWP2 DIV2
	,draw-value ( .. )

JMP

&whole ( num* den* -- )

	POP2

@draw-value ( short* -- )

	ORAk ,&no-null JCN
		LIT "0 ,draw-char JMP
		&no-null

	.mode/dec LDZ ,draw-dec JCN

@draw-hex ( short* -- )

	#00 ,&z STR
	,&parse JSR
	,&parse JSR
	,&parse JSR
	,&parse JSR POP2

JMP2r
	&parse
		OVR #04 SFT DUP [ LIT &z $1 ] EQU ,&skip JCN
			#ff ,&z STR DUP ,hex-char JSR ,draw-char JSR
			&skip
		POP #40 SFT2
	JMP2r

@draw-dec ( short* -- )

	#00 ,&z STR
	#2710 ,&parse JSR
	#03e8 ,&parse JSR
	#0064 ,&parse JSR
	#000a ,&parse JSR
	NIP
	&emit
		DUP [ LIT &z $1 ] EQU ,&skip JCN
		#ff ,&z STR DUP #30 ADD ,draw-char JSR
		&skip
	POP

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

@draw-char ( char -- )

	#00 SWP #20 SUB #30 SFT2 ;font ADD2 .Screen/addr DEO2
	[ LIT &color 05 ] .Screen/sprite DEO

JMP2r

@draw-str ( str* -- )

	#01 .Screen/auto DEO
	&w
		LDAk ,draw-char JSR
		INC2 LDAk ,&w JCN
	POP2

JMP2r

@hex-char ( hex -- char )

	#0f AND DUP #09 GTH #27 MUL ADD #30 ADD

JMP2r

@draw-dotted ( w -- )

	#01 .Screen/auto DEO
	;&icn .Screen/addr DEO2
	#00
	&loop
		#08 .Screen/sprite DEO
		INC GTHk ,&loop JCN
	POP2

JMP2r
	&icn 0000 0055 0000 0000

@draw-frame ( x* y* w h sprite* -- )

	.Screen/addr DEO2
	,&h STR ,&w STR
	DUP2 .Screen/y DEO2 ,&y STR2
	DUP2 .Screen/x DEO2 ,&x STR2
	#01 .Screen/auto DEO
	#81 .Screen/sprite DEO
	,&next JSR [ LIT &w $1 ] ,&repeat JSR
	#02 .Screen/auto DEO
	,&next JSR #81 .Screen/sprite DEO
	,&next JSR [ LIT &h $1 ] ,&repeat JSR
	( left )
	[ LIT2 &y $2 ] #0008 ADD2 .Screen/y DEO2
	[ LIT2 &x $2 ] .Screen/x DEO2
	,&next JSR ,&h LDR ,&repeat JSR
	#01 .Screen/auto DEO
	,&next JSR #81 .Screen/sprite DEO
	,&next JSR ,&w LDR ,&repeat JSR
	,&next JSR #81 .Screen/sprite DEO
	( fill )
	,&next JSR
	,&x LDR2 #0008 ADD2 .Screen/x DEO2
	,&y LDR2 #0008 ADD2 .Screen/y DEO2

JMP2r
	&next
		.Screen/addr DEI2k #0010 ADD2 ROT DEO2
	JMP2r
	&repeat
		#00
		&repeat-loop
			#81 .Screen/sprite DEO
			INC GTHk ,&repeat-loop JCN
		POP2
	JMP2r

@sval ( str* -- short* )

	.mode/dec LDZ ,sdec JCN

@shex ( str* -- short* )

	LIT2r 0000
	&while
		LITr 40 SFT2r
		LITr 00
		LDAk ,chex JSR STH ADD2r
		INC2 LDAk ,&while JCN
	POP2 STH2r

JMP2r

@chex ( char -- value/ff )

	DUP #2f GTH OVR #3a LTH AND ,&number JCN
	DUP #60 GTH OVR #67 LTH AND ,&lc JCN
		POP #ff

JMP2r
	&number #30 SUB JMP2r
	&lc #57 SUB JMP2r

@sdec ( str* -- short* )

	LIT2r 0000
	&while
		LDAk #30 SUB #00 SWP
		STH2r #000a MUL2 ADD2 STH2
		INC2 LDAk ,&while JCN
	POP2
	STH2r

JMP2r

@draw-cursor ( color -- )

	#00 .Screen/auto DEO
	.cursor/x LDZ2 .Screen/x DEO2
	.cursor/y LDZ2 .Screen/y DEO2
	.Screen/sprite DEO

JMP2r

( print )

@print ( -- )

	.length LDZ2 ORA ,&no-empty JCN
		;empty-txt ;print-str JSR2 #0a18 DEO
		JMP2r
		&no-empty

	.length LDZ2 #0001 SUB2 #20 SFT2 ;memory ADD2

@print-fraction ( addr* -- )

	LDA2k SWP2 INC2 INC2 LDA2
	DUP2 #0001 EQU2 ,&whole JCN
	GTH2k ,&mixed JCN

&proper ( num* den* -- )

	SWP2 ,print-value JSR
	LIT "/ #18 DEO
	,print-value JSR #0a18 DEO

JMP2r

&mixed ( num* den* -- )

	DIV2k ,print-value JSR STH2k ( MOD2 ) [ DIV2k MUL2 SUB2 ] STH2r
	LIT "' #18 DEO ,&proper ( .. )

JMP

&whole ( num* den* -- )

	POP2 ,print-value JSR #0a18 DEO

JMP2r

@print-value ( short* -- )

	ORAk ,&no-null JCN
		LIT "0 #18 DEO JMP2r
		&no-null

	.mode/dec LDZ ,print-dec JCN

@print-hex ( short* -- )

	#00 ,&z STR
	,&parse JSR
	,&parse JSR
	,&parse JSR
	,&parse JSR POP2

JMP2r
	&parse
		OVR #04 SFT DUP [ LIT &z $1 ] EQU ,&skip JCN
			#ff ,&z STR DUP ;hex-char JSR2 #18 DEO
			&skip
		POP #40 SFT2
	JMP2r

@print-dec ( short* -- )

	#00 ,&z STR
	#2710 ,&parse JSR
	#03e8 ,&parse JSR
	#0064 ,&parse JSR
	#000a ,&parse JSR
	NIP
	&emit
		DUP [ LIT &z $1 ] EQU ,&skip JCN
		#ff ,&z STR DUP #30 ADD #18 DEO
		&skip
	POP

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

@print-str ( str* -- )

	&while
		LDAk #18 DEO
		INC2 LDAk ,&while JCN
	POP2

JMP2r

@snarf-paste ( -- )

	;&snarf-txt .File/name DEO2
	#0001 .File/length DEO2
	&stream
		;&buf .File/read DEO2
		.File/success DEI2 #0000 EQU2 ,&end JCN
		[ LIT &buf 20 ] ;listen JSR2
		,&stream JMP
	&end

JMP2r
	&snarf-txt ".snarf $1

( theme )

@load-theme ( -- )

	;&path .File/name DEO2
	#0002 .File/length DEO2
	;&r .File/read DEO2
	;&g .File/read DEO2
	;&b .File/read DEO2
	.File/success DEI2 ORA #01 JCN JMP2r
	LIT2 &r $2 .System/r DEO2
	LIT2 &g $2 .System/g DEO2
	LIT2 &b $2 .System/b DEO2

JMP2r
	&path ".theme $1

@scap ( str* -- end* ) LDAk #00 NEQ JMP JMP2r &w INC2 LDAk ,&w JCN JMP2r
@spop ( str* -- ) LDAk ,&n JCN POP2 JMP2r &n ,scap JSR #0001 SUB2 #00 ROT ROT STA JMP2r
@sput ( chr str* -- ) ,scap JSR STA JMP2r
@slen ( str* -- len* ) DUP2 ,scap JSR SWP2 SUB2 JMP2r
@mclr ( src* len* -- ) OVR2 ADD2 SWP2 &l STH2k #00 STH2r STA INC2 GTH2k ,&l JCN POP2 POP2 JMP2r

@empty-txt "Empty 20 "Stack $1

@keys
	&ctl
	"~ :clear 09 :tog-mode "? :inv "@ :vid
	&mod
	"+ :add "- :sub "* :mul "/ :div
	"& :and "| :ora "< :sfl "> :sfr
	&wst
	20 :eval 08 :erase "% :swp "" :dup
	&num
	"7 :put7 "8 :put8 "9 :put9 "f :putf
	"4 :put4 "5 :put5 "6 :put6 "e :pute
	"1 :put1 "2 :put2 "3 :put3 "d :putd
	"0 :put0 "a :puta "b :putb "c :putc
	0d :eval
	"! :erase
	". :print
	1b :clear
	"# :set-hex
	"$ :set-dec
	"` :os8 ( huh? )
	&end

@buttons ( x* y* icon* size* state )
	&ctl
	&clr  0010 0068 :ctl-icns/clr :draw-button-special 00
	&mode 0028 0068 :ctl-icns/mode :draw-button-small 00
	&inv  0040 0068 :ctl-icns/inv :draw-button-small 00
	&vid  0058 0068 :ctl-icns/vid :draw-button-small 00
	&num
	&7   0010 00b8 :num-icns/7 :draw-button 00
	&8   0028 00b8 :num-icns/8 :draw-button 00
	&9   0040 00b8 :num-icns/9 :draw-button 00
	&f   0058 00b8 :num-icns/f :draw-button-hex 00
	&4   0010 00d0 :num-icns/4 :draw-button 00
	&5   0028 00d0 :num-icns/5 :draw-button 00
	&6   0040 00d0 :num-icns/6 :draw-button 00
	&e   0058 00d0 :num-icns/e :draw-button-hex 00
	&1   0010 00e8 :num-icns/1 :draw-button 00
	&2   0028 00e8 :num-icns/2 :draw-button 00
	&3   0040 00e8 :num-icns/3 :draw-button 00
	&d   0058 00e8 :num-icns/d :draw-button-hex 00
	&0   0010 0100 :num-icns/0 :draw-button 00
	&a   0028 0100 :num-icns/a :draw-button-hex 00
	&b   0040 0100 :num-icns/b :draw-button-hex 00
	&c   0058 0100 :num-icns/c :draw-button-hex 00
	&wst
	&push 0010 00a8 :wst-icns/push :draw-button-small 00
	&pop  0028 00a8 :wst-icns/pop :draw-button-small 00
	&swp  0040 00a8 :wst-icns/swp :draw-button-small 00
	&dup  0058 00a8 :wst-icns/dup :draw-button-small 00
	&mod
	&add 0010 0078 :mod-icns/add :draw-button 00
	&sub 0028 0078 :mod-icns/sub :draw-button 00
	&mul 0040 0078 :mod-icns/mul :draw-button 00
	&div 0058 0078 :mod-icns/div :draw-button 00
	&and 0010 0090 :mod-icns/and :draw-button 00
	&ora 0028 0090 :mod-icns/ora :draw-button 00
	&sfl 0040 0090 :mod-icns/sfl :draw-button 00
	&sfr 0058 0090 :mod-icns/sfr :draw-button 00

	&end

@cursor-icn
	80c0 e0f0 f8e0 1000
@fill-icn
	ffff ffff ffff ffff
@logo-icn
	1824 40df 4024 1800
@patt-icn
	8800 2200 8800 2200
	aa55 aa55 aa55 aa55
@decal-icn
	001c 22c1 0000 0000
	0000 0007 8870 0000

@button
	&def
	0000 1f3f 3f3f 3f3f 001f 3f7f 7f7f 7f7f
	0000 ffff ffff ffff 00ff ffff ffff ffff
	0000 f8fc fcfc fcfc 00f8 fcfe fefe fefe
	3f3f 3f3f 3f3f 3f3f 7f7f 7f7f 7f7f 7f7f
	ffff ffff ffff ffff ffff ffff ffff ffff
	fcfc fcfc fcfc fcfc fefe fefe fefe fefe
	3f3f 3f3f 3f1f 0000 7f7f 7f7f 5f20 1f00
	ffff ffff ffff 0000 ffff ffff ff00 ff00
	fcfc fcfc fcf8 0000 fefe fefe fa04 f800
	&alt
	0000 001f 3f3f 3f3f 0000 1f20 4040 4040
	0000 00ff ffff ffff 0000 ff00 0000 0000
	0000 00f8 fcfc fcfc 0000 f804 0202 0202
	3f3f 3f3f 3f3f 3f3f 4040 4040 4040 4040
	ffff ffff ffff ffff 0000 0000 0000 0000
	fcfc fcfc fcfc fcfc 0202 0202 0202 0202
	3f3f 3f3f 3f1f 0000 4040 4040 4020 1f00
	ffff ffff ffff 0000 0000 0000 0000 ff00
	fcfc fcfc fcf8 0000 0202 0202 0204 f800
	&os8-def
	0000 001f 1f1f 1f1f 0000 3f3f 3f3f 3f3f
	0000 00ff ffff ffff 0000 ffff ffff ffff
	0000 00f8 f8f8 f8f8 0000 fcfc fcff ffff
	1f1f 1f1f 1f1f 1f1f 3f3f 3f3f 3f3f 3f3f
	ffff ffff ffff ffff ffff ffff ffff ffff
	f8f8 f8f8 f8f8 f8f8 ffff ffff ffff ffff
	1f1f 1f1f 1f00 0000 3f3f 3f3f 3f3f 0f0f
	ffff ffff ff00 0000 ffff ffff ffff ffff
	f8f8 f8f8 f800 0000 ffff ffff ffff ffff
	&os8-alt
	0000 0000 1f1f 1f1f 0000 003f 2020 2020
	0000 0000 ffff ffff 0000 00ff 0000 0000
	0000 0000 f8f8 f8f8 0000 00fc 0404 0707
	1f1f 1f1f 1f1f 1f1f 2020 2020 2020 2020
	ffff ffff ffff ffff 0000 0000 0000 0000
	f8f8 f8f8 f8f8 f8f8 0707 0707 0707 0707
	1f1f 1f1f 1f1f 1f00 2020 2020 2020 203f
	ffff ffff ffff ff00 0000 0000 0000 00ff
	f8f8 f8f8 f8f8 f800 0707 0707 0707 07ff

@display-frame
	&def
	0000 0000 0000 0000 003f 7f7f 7f7f 7f7f
	0000 0000 0000 0000 00ff ffff ffff ffff
	0000 0000 0000 0000 00fc fefe fefe fefe
	0000 0000 0000 0000 fefe fefe fefe fefe
	0000 0000 0000 0000 7f7f 7f7f 7f7f 7f7f
	0000 0000 0040 3f00 7f7f 7f7f 7f3f 0000
	0000 0000 0000 ff00 ffff ffff ffff 0000
	0000 0000 0002 fc00 fefe fefe fefc 0000
	&os8
	0000 0000 0000 0000 0000 3f20 2f2f 2f2f
	0000 0000 0000 0000 0000 ff00 ffff ffff
	0000 0000 0000 0000 0000 fc04 f4f4 f4f4
	0000 0000 0000 0000 f4f4 f4f4 f4f4 f4f4
	0000 0000 0000 0000 2f2f 2f2f 2f2f 2f2f
	0000 0000 0000 0000 2f2f 2f2f 203f 0000
	0000 0000 0000 0000 ffff ffff 00ff 0000
	0000 0000 0000 0000 f4f4 f4f4 04fc 0000

@outline-frame
	0000 0000 0000 0102 8000 0000 0000 0000
	0000 0000 0000 ff00 0000 0000 0000 0000
	0000 0000 0000 8040 f160 0000 0000 0000
	4040 4040 4040 4040 0000 0000 0000 0000
	0202 0202 0202 0202 0000 0000 0000 0000
	0201 0000 0000 0000 0000 0000 0000 0080
	00ff 0000 0000 0000 0000 0000 0000 0000
	4080 0000 0000 0000 0000 0000 0000 0001

@ctl-icns
	&clr 0000 183c 3c18 0000
	&mode 0000 007f fe00 0000
	&inv 007c 7e02 407e 3e00
	&vid 0033 6666 6666 cc00

@mod-icns
	&and
	0000 000f 1f18 180f 0000 00e0 e000 00f8
	0f18 181f 0f00 0000 f860 60e0 e000 0000
	&ora
	0000 0001 0101 0101 0000 0080 8080 8080
	0101 0101 0100 0000 8080 8080 8000 0000
	&sfl
	0000 0006 060c 0c19 0000 0060 60c0 c080
	190c 0c06 0600 0000 80c0 c060 6000 0000
	&sfr
	0000 0006 0603 0301 0000 0060 6030 3098
	0103 0306 0600 0000 9830 3060 6000 0000
	&add
	0000 0001 0101 011f 0000 0080 8080 80f8
	1f01 0101 0100 0000 f880 8080 8000 0000
	&sub
	0000 0000 0000 001f 0000 0000 0000 00f8
	1f00 0000 0000 0000 f800 0000 0000 0000
	&mul
	0000 0018 1806 0601 0000 0018 1860 6080
	0106 0618 1800 0000 8060 6018 1800 0000
	&div
	0000 0001 0100 001f 0000 0080 8000 00f8
	1f00 0001 0100 0000 f800 0080 8000 0000

@wst-icns
	&push 0018 3c7e 1818 1800
	&pop 0018 1818 7e3c 1800
	&swp 006c 6666 6666 3600
	&dup 003c 6666 6666 6c00

@num-icns
	&0
	0000 000f 1f18 1818 0000 00f0 f818 1818
	1818 181f 0f00 0000 1818 18f8 f000 0000
	&1
	0000 0003 0307 0701 0000 0080 8080 8080
	0101 0101 0100 0000 8080 8080 8000 0000
	&2
	0000 001f 1f00 000f 0000 00f0 f818 18f8
	1f18 181f 1f00 0000 f000 00f8 f800 0000
	&3
	0000 001f 1f00 001f 0000 00f0 f818 18f0
	1f00 001f 1f00 0000 f018 18f8 f000 0000
	&4
	0000 0018 1818 181f 0000 0018 1818 18f8
	0f00 0000 0000 0000 f818 1818 1800 0000
	&5
	0000 001f 1f18 181f 0000 00f8 f800 00f0
	0f00 001f 1f00 0000 f818 18f8 f000 0000
	&6
	0000 0018 1818 181f 0000 0000 0000 00f0
	1f18 181f 0f00 0000 f818 18f8 f000 0000
	&7
	0000 001f 1f00 0000 0000 00f8 f818 1830
	0000 0000 0000 0000 3060 60c0 c000 0000
	&8
	0000 000f 1f18 180f 0000 00f0 f818 18f0
	0f18 181f 0f00 0000 f018 18f8 f000 0000
	&9
	0000 000f 1f18 181f 0000 00f0 f818 18f8
	0f00 0000 0000 0000 f818 1818 1800 0000
	&a
	0000 000f 1f18 181f 0000 00f0 f818 18f8
	1f18 1818 1800 0000 f818 1818 1800 0000
	&b
	0000 001f 1f18 181f 0000 00f0 f818 18f0
	1f18 181f 1f00 0000 f018 18f8 f000 0000
	&c
	0000 000f 1f18 1818 0000 00f8 f800 0000
	1818 181f 0f00 0000 0000 00f8 f800 0000
	&d
	0000 001f 1f18 1818 0000 00f0 f818 1818
	1818 181f 1f00 0000 1818 18f8 f000 0000
	&e
	0000 001f 1f18 181f 0000 00f8 f800 00f8
	1f18 181f 1f00 0000 f800 00f8 f800 0000
	&f
	0000 000f 1f18 181f 0000 00f8 f800 0080
	1f18 1818 1800 0000 8000 0000 0000 0000

@tone 
8eae b5b9 c0ce dbdc cdb6 a295 8b80 7364 
5953 5256 585a 5d62 686f 7579 7d7e 8183 
8585 8483 8587 8b96 9d9e 9282 7876 7674 
706b 696c 7479 7d81 8385 898d 8d8d 8c8a 
8a88 8684 8180 7f7e 7d7c 7c7c 7c7c 7a74 
6445 221d 4179 a2b4 b7bc c7d6 ddd5 c0aa 
9b8f 867a 6b5e 5553 5456 585c 6065 6c73 
787c 7e80 8284 8484 8484 8589 919a a098 
897c 7676 7572 6e6a 6b6f 777d 7f81 8587 
8c8e 8e8d 8c8a 8988 8584 817f 7e7d 7e7d 
7c7d 7c7c 786d 5530 1a2d 5e91 aeb7 b9c1 
cfdc dacb b4a0 948b 8072 6458 5354 5558 
5a5e 636a 7076 7a7d 7f82 8484 8584 8485 
878d 969e 9d91 8177 7575 7470 6b69 6c74 
7a7e 8182 8589 8d8e 8e8d 8a8a 8887 8582 
807e 7e7d 7c7c 7c7c 7d7b 7463 4121 1e46 

@font ( atari8 )
0000 0000 0000 0000 6060 6060 6000 6000
6666 6600 0000 0000 006c fe6c 6cfe 6c00
183e 603c 067c 1800 0066 6c18 3066 4600
386c 3870 decc 7600 6060 6000 0000 0000
1c30 3030 3030 1c00 380c 0c0c 0c0c 3800
0066 3cff 3c66 0000 0018 187e 1818 0000
0000 0000 0030 3060 0000 007e 0000 0000
0000 0000 0018 1800 0306 0c18 3060 c000
3c66 6e76 6666 3c00 1838 1818 1818 7e00
3c66 060c 1830 7e00 7e0c 180c 0666 3c00
0c1c 3c6c 7e0c 0c00 7e60 7c06 0666 3c00
3c60 607c 6666 3c00 7e06 0c18 3030 3000
3c66 663c 6666 3c00 3c66 663e 060c 3800
0018 1800 0018 1800 0018 1800 1818 3000
0c18 3060 3018 0c00 0000 7e00 007e 0000
3018 0c06 0c18 3000 3c66 060c 1800 1800
3c66 6e6a 6e60 3e00 183c 6666 7e66 6600
7c66 667c 6666 7c00 3c66 6060 6066 3c00
786c 6666 666c 7800 7e60 607c 6060 7e00
7e60 607c 6060 6000 3e60 606e 6666 3e00
6666 667e 6666 6600 7830 3030 3030 7800
3e06 0606 0666 3c00 666c 7870 786c 6600
6060 6060 6060 7e00 c6ee fed6 c6c6 c600
6676 7e7e 6e66 6600 3c66 6666 6666 3c00
7c66 667c 6060 6000 3c66 6666 766c 3600
7c66 667c 6c66 6600 3c66 603c 0666 3c00
7e18 1818 1818 1800 6666 6666 6666 3e00
6666 6666 663c 1800 c6c6 c6d6 feee c600
6666 3c18 3c66 6600 6666 663c 1818 1800
7e06 0c18 3060 7e00 3c30 3030 3030 3c00
c060 3018 0c06 0300 3c0c 0c0c 0c0c 3c00
1038 6cc6 0000 0000 0000 0000 0000 fe00
0060 3018 0000 0000 0000 3c06 3e66 3e00
6060 7c66 6666 7c00 0000 3c60 6060 3c00
0606 3e66 6666 3e00 0000 3c66 7e60 3c00
1c30 7c30 3030 3000 0000 3e66 663e 067c
6060 7c66 6666 6600 1800 3818 1818 3c00
1800 1818 1818 1870 6060 666c 786c 6600
3818 1818 1818 3c00 0000 ecfe d6c6 c600
0000 7c66 6666 6600 0000 3c66 6666 3c00
0000 7c66 6666 7c60 0000 3e66 6666 3e06
0000 7c66 6060 6000 0000 3e60 3c06 7c00
0018 7e18 1818 0e00 0000 6666 6666 3e00
0000 6666 663c 1800 0000 c6c6 d67c 6c00
0000 663c 183c 6600 0000 6666 663e 067c
0000 7e0c 1830 7e00 1c30 3060 3030 1c00
1818 1818 1818 1818 380c 0c06 0c0c 3800
0000 60f2 9e0c 0000 0018 1834 3462 7e00

@memory ( den*, num*, den*, num*, .. )


R etc/spritesheet.chr => etc/ss10x10.chr +0 -0
A etc/ss10x10.chr.nmt => etc/ss10x10.chr.nmt +0 -0
M src/cccc.tal => src/cccc.tal +433 -355
@@ 15,37 15,34 @@
		&dot $1
	@cursor
		&x $2 &y $2
	@input $8
		&d &dx $1 &dy $1
	@input 
		&num $2 &den $2
	@length $2

|0100

	( theme )
	#d70f .System/r DEO2
	#c80f .System/g DEO2
	#a80f .System/b DEO2
	#50f2 .System/r DEO2
	#b0f9 .System/g DEO2
	#a0f8 .System/b DEO2
	;load-theme JSR2

	( size )
	#0080 .Screen/width DEO2
	#0128 .Screen/height DEO2
	( playdate size 0190 x 00f0  )
	#00e0 .Screen/width DEO2
	#00f0 .Screen/height DEO2

	( setup synth )
	#0048 .Audio0/adsr DEO2
	#0003 .Audio0/adsr DEO2
	;tone .Audio0/addr DEO2
	#0100 .Audio0/length DEO2
	#ff .Audio0/volume DEO ( TODO: turn ON )

	#0001 .input/den STZ2

	( initial draw )
	;redraw JSR2

	( draw mem )
	#01 .Screen/auto DEO
	#0018 .Screen/x DEO2
	#0018 .Screen/y DEO2
	#0000 ;memory SUB2 ;draw-dec JSR2
	;&mem-txt ;draw-str JSR2

	( vectors )
	;on-console .Console/vector DEO2
	;on-button .Controller/vector DEO2


@@ 53,7 50,6 @@
	;on-frame .Screen/vector DEO2

BRK
	&mem-txt 20 "free $1

(
@|vectors )


@@ 70,6 66,27 @@ BRK
		;snarf-paste JSR2
		&no-paste

	.Controller/button DEI
	DUP #10 NEQ ,&no-u JCN
		.cursor/dx LDZ .cursor/dy LDZ #01 SUB ;set-sel JSR2
		&no-u
	DUP #20 NEQ ,&no-d JCN
		.cursor/dx LDZ .cursor/dy LDZ INC ;set-sel JSR2
		&no-d
	DUP #40 NEQ ,&no-l JCN
		.cursor/dx LDZ #01 SUB .cursor/dy LDZ ;set-sel JSR2
		&no-l
	DUP #80 NEQ ,&no-r JCN
		.cursor/dx LDZ INC .cursor/dy LDZ ;set-sel JSR2
		&no-r
	DUP #01 NEQ ,&no-a JCN
		;press-sel JSR2
		&no-a
	DUP #02 NEQ ,&no-b JCN
		;erase JSR2
		&no-b
	POP

	.Controller/key DEI ;listen JSR2

BRK


@@ 86,7 103,7 @@ BRK
			( decr time )
			DUP2 LDAk #01 SUB ROT ROT STA
			( release button )
			LDAk #00 NEQ ,&continue JCN
			LDAk ,&continue JCN
				DUP2 #0008 SUB2 #00 ;press-button/release JSR2
			&continue
		INC2 GTH2k ,&loop JCN


@@ 103,7 120,7 @@ BRK
	.Mouse/x DEI2 .cursor/x STZ2
	.Mouse/y DEI2 .cursor/y STZ2
	;cursor-icn .Screen/addr DEO2
	.Mouse/state DEI #00 NEQ DUP ADD #41 ADD ;draw-cursor JSR2
	#43 .Mouse/state DEI #00 NEQ DUP ADD SUB ;draw-cursor JSR2

	.Mouse/state DEI ,&on-mouse-touch JCN



@@ 111,49 128,70 @@ BRK
	&on-mouse-touch ( -> )

	.Mouse/x DEI2 #0010 SUB2 #03 SFT2 NIP #03 DIV
	.Mouse/y DEI2 #0068 SUB2 #03 SFT2 NIP
	.Mouse/y DEI2 #0078 SUB2 #03 SFT2 NIP

	#00 .Mouse/state DEO

	OVR #03 GTH ,&skip JCN
	DUP #02 LTH ,on-touch-ctlpad JCN
	DUP #08 LTH ,on-touch-modpad JCN
	DUP #0a LTH ,on-touch-wstpad JCN
	DUP #16 LTH ,on-touch-numpad JCN
	OVR #07 GTH ,&skip JCN
	DUP #fd GTH ,on-touch-bitpad JCN
	DUP #0b GTH ,&skip JCN
	OVR #02 LTH ,on-touch-fncpad JCN
	OVR #06 LTH ,on-touch-numpad JCN
	OVR #08 LTH ,on-touch-modpad JCN
	&skip
	POP2

BRK

@on-touch-ctlpad ( x/3 y -> )
@on-touch-bitpad ( x y -- )

	POP2

	( id ) POP
	#00 SWP #03 MUL INC ;keys/ctl ADD2 LDA2 JSR2
	.Mouse/x DEI2 #0033 GTH2 ,&continue JCN
		BRK
		&continue

	#0001
	( shift )
	#000f
	.Mouse/x DEI2 #0038 SUB2 #03 SFT2
		DUP2 #0005 DIV2 SUB2 SUB2
	#40 SFT NIP
	( mask )
	SFT2 .input LDZ2 EOR2
		 .input STZ2
	;update-input JSR2

BRK

@on-touch-modpad ( x/3 y -> )
@on-touch-fncpad ( x/3 y -> )

	( id ) #02 SUB
	#03 DIV #20 SFT ADD
	#00 SWP #03 MUL INC ;keys/mod ADD2 LDA2 JSR2
	#01 SFT SWP #06 MUL ADD
	#00 SWP DUP ADD ;fncpad ADD2
		LDA2 JSR2

BRK

@on-touch-wstpad ( x/3 y -> )
@on-touch-numpad ( x/3 y -> )

	( id ) POP
	#00 SWP #03 MUL INC ;keys/wst ADD2 LDA2 JSR2
	SWP #02 SUB SWP
	#03 DIV #20 SFT ADD 
	#00 SWP DUP ADD ;numpad ADD2
		LDA2 JSR2

BRK

@on-touch-numpad ( x/3 y -> )
@on-touch-modpad ( x/3 y -> )

	( id ) #0a SUB
	#03 DIV #20 SFT ADD
	#00 SWP #03 MUL INC ;keys/num ADD2 LDA2 JSR2
	#03 DIV SWP #06 SUB #20 SFT ADD
	#00 SWP DUP ADD ;modpad ADD2
		LDA2 JSR2

BRK

(
@|main )

@listen ( c -- )

	STHk


@@ 174,39 212,38 @@ JMP2r

@eval ( -- )

	.input LDZ #00 EQU ,&skip JCN
		;buttons/push ;press-button JSR2
		;input ;sval JSR2 #0001 ;push JSR2
		;draw-display JSR2
		;clear-input JSR2
		;input #0008 ;mclr JSR2
		&skip
	;buttons/push ;press-button JSR2
	.input LDZ2 #0001 ;push JSR2
	#0000 .input STZ2
	;update-input JSR2
	;draw-display ( .. )

JMP2r
JMP2

@append ( char -- )
@append ( val -- )

	;input ;slen JSR2 #0003 .mode/dec LDZ ADD GTH2 ,&skip JCN
		DUP ;input ;sput JSR2
		;draw-input JSR2
		&skip
	POP
	#00 SWP 
	.input LDZ2 
		#00 #0a10 .mode/dec LDZ [ JMP SWP POP ] MUL2 ADD2 
		.input STZ2
	;draw-input ( .. )

JMP2r
JMP2

@erase ( -- )

	( clamp )
	.input LDZ ,&has-input JCN
	.input LDZ2 ORA ,&has-input JCN
		;buttons/pop ;press-button JSR2
		.length LDZ2 ORA #01 JCN JMP2r
		;pop JSR2 POP2 POP2
		;draw-display JMP2
		&has-input

	;input ;spop JSR2
	;clear-input JSR2
	;draw-input ( .. )
	.input LDZ2 
		#00 #0a10 .mode/dec LDZ [ JMP SWP POP ] DIV2
		.input STZ2
	;update-input ( .. )

JMP2



@@ 214,9 251,9 @@ JMP2

	;buttons/clr ;press-button JSR2
	#0000 .length STZ2
	;input #0008 ;mclr JSR2
	#0000 .input STZ2
	;draw-display JSR2
	;clear-input ( .. )
	;update-input ( .. )

JMP2



@@ 246,6 283,28 @@ JMP2

JMP2

@set-sel ( x y -- )

	( erase last sel )
	#00 ;draw-sel JSR2
	#40 ;draw-cursor JSR2

	( store new sel )
	#03 AND .cursor/dy STZ
	#07 AND .cursor/dx STZ

	( draw new sel )
	#81 ;draw-sel ( .. )

JMP2

@press-sel ( -- )

	#00 .cursor/d LDZ2 #30 SFT ADD #20 SFT2
		;layout ADD2 INC2 INC2 LDA2 ( .. )

JMP2

@gcd ( num* den* -- d* ) ORAk ,&ok JCN POP2 JMP2r &ok SWP2 OVR2 ( MOD2 ) [ DIV2k MUL2 SUB2 ] ,gcd JMP

@push ( num* den* -- )


@@ 270,6 329,9 @@ JMP2r

JMP2r

(
@|operations )

@dup ( -- )

	;buttons/dup ;press-button JSR2


@@ 439,67 501,67 @@ JMP2
@put0 ( -- )
	;buttons/0 ;press-button JSR2
	#0b ;play-note JSR2
	LIT "0 ;append JMP2
	#00 ;append JMP2
@put1 ( -- ) 
	;buttons/1 ;press-button JSR2
	#0c ;play-note JSR2
	LIT "1 ;append JMP2
	#01 ;append JMP2
@put2 ( -- ) 
	;buttons/2 ;press-button JSR2
	#0e ;play-note JSR2
	LIT "2 ;append JMP2
	#02 ;append JMP2
@put3 ( -- ) 
	;buttons/3 ;press-button JSR2
	#10 ;play-note JSR2
	LIT "3 ;append JMP2
	#03 ;append JMP2
@put4 ( -- ) 
	;buttons/4 ;press-button JSR2
	#11 ;play-note JSR2
	LIT "4 ;append JMP2
	#04 ;append JMP2
@put5 ( -- ) 
	;buttons/5 ;press-button JSR2
	#13 ;play-note JSR2
	LIT "5 ;append JMP2
	#05 ;append JMP2
@put6 ( -- ) 
	;buttons/6 ;press-button JSR2
	#15 ;play-note JSR2
	LIT "6 ;append JMP2
	#06 ;append JMP2
@put7 ( -- ) 
	;buttons/7 ;press-button JSR2
	#17 ;play-note JSR2
	LIT "7 ;append JMP2
	#07 ;append JMP2
@put8 ( -- ) 
	;buttons/8 ;press-button JSR2
	#18 ;play-note JSR2
	LIT "8 ;append JMP2
	#08 ;append JMP2
@put9 ( -- ) 
	;buttons/9 ;press-button JSR2
	#1a ;play-note JSR2
	LIT "9 ;append JMP2
	#09 ;append JMP2
@puta ( -- ) 
	;buttons/a ;press-button JSR2
	#09 ;play-note JSR2
	LIT "a ;append JMP2
	#0a ;append JMP2
@putb ( -- ) 
	;buttons/b ;press-button JSR2
	#07 ;play-note JSR2
	LIT "b ;append JMP2
	#0b ;append JMP2
@putc ( -- ) 
	;buttons/c ;press-button JSR2
	#21 ;play-note JSR2
	LIT "c ;append JMP2
	#0c ;append JMP2
@putd ( -- ) 
	;buttons/d ;press-button JSR2
	#1f ;play-note JSR2
	LIT "d ;append JMP2
	#0d ;append JMP2
@pute ( -- ) 
	;buttons/e ;press-button JSR2
	#1d ;play-note JSR2
	LIT "e ;append JMP2
	#0e ;append JMP2
@putf ( -- ) 
	;buttons/f ;press-button JSR2
	#1c ;play-note JSR2
	LIT "f ;append JMP2
	#0f ;append JMP2

@press-button ( button* -- )



@@ 521,7 583,8 @@ JMP2

JMP2r

( drawing )
(
@|drawing )

@redraw ( -- )



@@ 529,78 592,90 @@ JMP2r
	#08 ;buttons/mod ;draw-pad JSR2
	#04 ;buttons/wst ;draw-pad JSR2
	#10 ;buttons/num ;draw-pad JSR2
	;draw-mode JSR2
	;draw-display JSR2
	;clear-input JSR2
	;update-input JSR2

	( frame )
	#0000 DUP2
	.Screen/width DEI2 #03 SFT2 NIP #02 SUB
	#1a
	.Screen/height DEI2 #03 SFT2 NIP #02 SUB
	;outline-frame
		;draw-frame JSR2

	( decal )
	#16 .Screen/auto DEO
	#0010 .Screen/x DEO2
	#0018 .Screen/x DEO2
	#0003 .Screen/y DEO2
	;decal-icn .Screen/addr DEO2
	#01 .Screen/sprite DEO

	( logo )
	#01 .Screen/auto DEO
	#0050 .Screen/x DEO2
	#00b0 .Screen/x DEO2
	.Screen/height DEI2 #000a SUB2 .Screen/y DEO2
	;logo-icn .Screen/addr DEO2
	#01 .Screen/sprite DEOk DEOk DEOk DEO

JMP2r

@clear-input ( -- )
@update-input ( -- )

	#62 .Screen/auto DEO
	#11 .Screen/auto DEO
	#0018 .Screen/x DEO2
	#0050 .Screen/y DEO2
	;fill-icn .Screen/addr DEO2
	#02 .Screen/sprite DEO

@draw-mode ( -- )

	#0050 .Screen/x DEO2
	#0050 .Screen/y DEO2
	#08 ;draw-char/color STA
	#01 .Screen/auto DEO
	LIT ". LIT "/ .mode/dot LDZ [ JMP SWP POP ] ;draw-char JSR2
	;&modes #00 .mode/dec LDZ #03 MUL ADD2 ;draw-str ( .. )

JMP2
	&modes "hx $1 "dc $1
	#1600
	&loop
		#01 .Screen/sprite DEO
		INC GTHk ,&loop JCN
	POP2

@draw-input ( -- )

	&res
	#0018 .Screen/x DEO2
	#0050 .Screen/y DEO2
	#0b ;draw-char/color STA
	;input ;draw-str ( .. )
	#04 ;draw-num/color STA
	;input ;draw-fraction JSR2

JMP2
	( draw binary )

	#05 .Screen/auto DEO
	#0038 .Screen/x DEO2
	#006c .Screen/y DEO2

	#1000
	&loop
		#0f OVR SUB .input LDZ2 ROT SFT2
			#0001 AND2 #30 SFT2 ;binary-icns ADD2 .Screen/addr DEO2
		#01 .Screen/sprite DEO
		INCk #03 AND ,&no-space JCN
			.Screen/x DEI2k #0008 ADD2 ROT DEO2
			&no-space
		INC GTHk ,&loop JCN
	POP2

JMP2r

@draw-display ( -- )

	#0010 DUP2 #0a08 [ LIT2 &style :display-frame/def ] ;draw-frame JSR2
	#0010 DUP2 #1609 ;display-frame ;draw-frame JSR2
	#0018 .Screen/x DEO2
	#0018 .Screen/y DEO2
	#0a06 ;fill-icn #02 ;draw-patt JSR2
	#1606 ;fill-icn #01 ;draw-patt JSR2

	#0018 .Screen/x DEO2
	#0a ;draw-dotted JSR2
	#16 ;draw-dotted JSR2

	#05 ;draw-char/color STA
	#06 ;draw-num/color STA
	( memory )
	#0600
	#0300
	&loop
		#00 OVR INC .length LDZ2 GTH2 ,&end JCN
		#0018 .Screen/x DEO2
		#00 OVR #30 SFT2 #0040 SWP2 SUB2 .Screen/y DEO2
		#00 OVR #40 SFT2 #0038 SWP2 SUB2 .Screen/y DEO2
		#00 OVR INC .length LDZ2 SWP2 SUB2 #20 SFT2 ;memory ADD2 ;draw-fraction JSR2
		INC GTHk ,&loop JCN
		&end


@@ 608,6 683,18 @@ JMP2

JMP2r

@draw-mode ( -- )

	#05 .Screen/auto DEO
	#0010 .Screen/x DEO2
	#006c .Screen/y DEO2
	#00 .mode/dec LDZ #40 SFT2 ;mode-icns ADD2 .Screen/addr DEO2
	#01 .Screen/sprite DEOk DEO
	#00 .mode/dot LDZ #30 SFT2 ;mode-icns/dot ADD2 .Screen/addr DEO2
	#01 .Screen/sprite DEO

JMP2r

@draw-patt ( w h patt* color -- )

	,&color STR


@@ 644,11 731,11 @@ JMP2r

JMP2r

@draw-button-special ( icon* state -- )
@draw-button-clr ( icon* state -- )

	#05 ,draw-button-small/color STR
	#09 ,draw-button-small/color STR
	,draw-button-small JSR
	#0a ,draw-button-small/color STR
	#0b ,draw-button-small/color STR

JMP2r



@@ 656,25 743,50 @@ JMP2r

	#00 NEQ STH
	#26 .Screen/auto DEO
	[ LIT2 &alt :button/alt ] [ LIT2 &def :button/def ]
	;button-icns/alt ;button-icns/def
		STHkr [ JMP SWP2 POP2 ] STH2k .Screen/addr DEO2
	#81 .Screen/sprite DEO
	STH2r #0060 ADD2 .Screen/addr DEO2
	#81 .Screen/sprite DEO
	( icon )
	.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
	.Screen/y DEI2 #000c SUB2 #00 STHkr ADD2 .Screen/y DEO2
	#00 .Screen/auto DEO
	.Screen/addr DEO2
	#09 [ LIT &color 0b ] STHr [ JMP SWP POP ] .Screen/sprite DEOk DEO

JMP2r

@draw-button-tall ( icon* state -- )

	#00 NEQ STH
	#26 .Screen/auto DEO
	;button-icns/alt ;button-icns/def
		STHkr [ JMP SWP2 POP2 ] STH2k .Screen/addr DEO2
	#81 .Screen/sprite DEO
	( body )
	#0400
	&loop
		STH2kr #0030 ADD2 .Screen/addr DEO2
		#81 .Screen/sprite DEO
		INC GTHk ,&loop JCN
	POP2
	STH2r #0060 ADD2 .Screen/addr DEO2
	#81 .Screen/sprite DEO
	( icon )
	.Screen/x DEI2 #0008 ADD2 .Screen/x DEO2
	.Screen/y DEI2 #000c SUB2 #00 STHr ADD2 .Screen/y DEO2
	.Screen/y DEI2 #0010 SUB2 #00 STHkr ADD2 .Screen/y DEO2
	#00 .Screen/auto DEO
	.Screen/addr DEO2
	[ LIT &color 0a ] .Screen/sprite DEOk DEO
	#090b STHr [ JMP SWP POP ] .Screen/sprite DEOk DEO

JMP2r

@draw-button-hex ( icon* state -- )

	#05 ,draw-button/color STR
	#09 ,draw-button/color STR
	,draw-button JSR
	#0a ,draw-button/color STR
	#0b ,draw-button/color STR

JMP2r



@@ 682,40 794,18 @@ JMP2r

	#00 NEQ STH
	#26 .Screen/auto DEO
	[ LIT2 &alt :button/alt ] [ LIT2 &def :button/def ]
	;button-icns/alt ;button-icns/def
		STHkr [ JMP SWP2 POP2 ] .Screen/addr DEO2
	#81 .Screen/sprite DEOk DEOk DEO
	( icon )
	.Screen/x DEI2 #0004 ADD2 .Screen/x DEO2
	.Screen/y DEI2 #0014 SUB2 #00 STHr ADD2 .Screen/y DEO2
	.Screen/y DEI2 #0014 SUB2 #00 STHkr ADD2 .Screen/y DEO2
	#16 .Screen/auto DEO
	.Screen/addr DEO2
	[ LIT &color 0a ] .Screen/sprite DEOk DEO
	#09 [ LIT &color 0b ] STHr [ JMP SWP POP ] .Screen/sprite DEOk DEO

JMP2r

@os8 ( -- )

	( theme )
	#f80f .System/r DEO2
	#f80f .System/g DEO2
	#fb0f .System/b DEO2

	#0000 DUP2 .Screen/x DEO2 .Screen/y DEO2
	.Screen/width DEI2 #03 SFT2 NIP
	.Screen/height DEI2 #03 SFT2 NIP
	;patt-icn #01
		;draw-patt JSR2

	;button/os8-def ;draw-button-small/def STA2
	;button/os8-alt ;draw-button-small/alt STA2
	;button/os8-def ;draw-button/def STA2
	;button/os8-alt ;draw-button/alt STA2
	;display-frame/os8 ;draw-display/style STA2
	;redraw ( .. )

JMP2

@draw-fraction ( addr* -- )

	#01 .Screen/auto DEO


@@ 727,15 817,15 @@ JMP2

	.mode/dot LDZ ,&proper-dot JCN
	SWP2 ,draw-value JSR
	LIT "/ ;draw-char JSR2
	;draw-slash JSR2
	,draw-value ( .. )

JMP

&proper-dot ( num* den* -- )

	LIT "0 ;draw-char JSR2
	LIT ". ;draw-char JSR2
	#00 ;draw-num JSR2
	;draw-dot JSR2
	SWP2 #03e8 #1000 .mode/dec LDZ [ JMP SWP2 POP2 ] MUL2 SWP2 DIV2
	,draw-value ( .. )



@@ 745,7 835,7 @@ JMP

	.mode/dot LDZ ,&mixed-dot JCN
	DIV2k ,draw-value JSR
	LIT "' ;draw-char JSR2
	;draw-quote JSR2
	STH2k ( MOD2 ) [ DIV2k MUL2 SUB2 ] STH2r
	,&proper ( .. )



@@ 754,7 844,7 @@ JMP
&mixed-dot ( num* den* -- )

	DIV2k ,draw-value JSR
	LIT ". ;draw-char JSR2
	;draw-dot JSR2
	STH2k ( MOD2 ) [ DIV2k MUL2 SUB2 ] STH2r
	SWP2 #03e8 #1000 .mode/dec LDZ [ JMP SWP2 POP2 ] MUL2 SWP2 DIV2
	,draw-value ( .. )


@@ 768,7 858,7 @@ JMP
@draw-value ( short* -- )

	ORAk ,&no-null JCN
		LIT "0 ,draw-char JMP
		POP2 #00 ;draw-num JMP2
		&no-null

	.mode/dec LDZ ,draw-dec JCN


@@ 784,7 874,7 @@ JMP
JMP2r
	&parse
		OVR #04 SFT DUP [ LIT &z $1 ] EQU ,&skip JCN
			#ff ,&z STR DUP ,hex-char JSR ,draw-char JSR
			#ff ,&z STR DUP ;draw-num JSR2
			&skip
		POP #40 SFT2
	JMP2r


@@ 799,7 889,7 @@ JMP2r
	NIP
	&emit
		DUP [ LIT &z $1 ] EQU ,&skip JCN
		#ff ,&z STR DUP #30 ADD ,draw-char JSR
		#ff ,&z STR DUP ;draw-num JSR2
		&skip
	POP



@@ 808,26 898,40 @@ JMP2r
		DIV2k DUP ,&emit JSR MUL2 SUB2
	JMP2r

@draw-char ( char -- )
@hex-char ( hex -- char )

	#00 SWP #20 SUB #30 SFT2 ;font ADD2 .Screen/addr DEO2
	[ LIT &color 05 ] .Screen/sprite DEO
	#0f AND DUP #09 GTH #27 MUL ADD #30 ADD

JMP2r

@draw-str ( str* -- )
@draw-num ( num -- )

	#01 .Screen/auto DEO
	&w
		LDAk ,draw-char JSR
		INC2 LDAk ,&w JCN
	POP2
	#00 SWP #50 SFT2 ;num-icns ADD2 .Screen/addr DEO2
	#16 .Screen/auto DEOk DEO
	[ LIT &color 01 ] .Screen/sprite DEOk DEO
	.Screen/y DEI2k #0010 SUB2 ROT DEO2
	.Screen/x DEI2k #000d ADD2 ROT DEO2

JMP2r

@hex-char ( hex -- char )
@draw-dot ( -- )

	#0f AND DUP #09 GTH #27 MUL ADD #30 ADD
	;dot-icns ,draw-type JMP

@draw-quote ( -- )

	;quote-icns ,draw-type JMP

@draw-slash ( -- )

	;slash-icns

@draw-type ( addr* -- )

	.Screen/addr DEO2
	.Screen/x DEI2k INC2 INC2 INC2 ROT DEO2
	#15 .Screen/auto DEOk DEO
	#04 .Screen/sprite DEO

JMP2r



@@ 837,7 941,7 @@ JMP2r
	;&icn .Screen/addr DEO2
	#00
	&loop
		#08 .Screen/sprite DEO
		#04 .Screen/sprite DEO
		INC GTHk ,&loop JCN
	POP2



@@ 881,41 985,14 @@ JMP2r
		POP2
	JMP2r

@sval ( str* -- short* )

	.mode/dec LDZ ,sdec JCN

@shex ( str* -- short* )

	LIT2r 0000
	&while
		LITr 40 SFT2r
		LITr 00
		LDAk ,chex JSR STH ADD2r
		INC2 LDAk ,&while JCN
	POP2 STH2r

JMP2r

@chex ( char -- value/ff )

	DUP #2f GTH OVR #3a LTH AND ,&number JCN
	DUP #60 GTH OVR #67 LTH AND ,&lc JCN
		POP #ff

JMP2r
	&number #30 SUB JMP2r
	&lc #57 SUB JMP2r

@sdec ( str* -- short* )
@draw-sel ( color -- )

	LIT2r 0000
	&while
		LDAk #30 SUB #00 SWP
		STH2r #000a MUL2 ADD2 STH2
		INC2 LDAk ,&while JCN
	POP2
	STH2r
	#00 .Screen/auto DEO
	;dpad-chr .Screen/addr DEO2
	#00 .cursor/d LDZ2 #30 SFT ADD #20 SFT2
		;layout ADD2 LDA2 LDA2k #0008 ADD2 .Screen/x DEO2
		INC2 INC2 LDA2 #0002 SUB2 .Screen/y DEO2
	#40 ADD .Screen/sprite DEO

JMP2r



@@ 1018,6 1095,9 @@ JMP2r

JMP2r

(
@|ecosystem )

@snarf-paste ( -- )

	;&snarf-txt .File/name DEO2


@@ 1049,23 1129,33 @@ JMP2r
JMP2r
	&path ".theme $1

@scap ( str* -- end* ) LDAk #00 NEQ JMP JMP2r &w INC2 LDAk ,&w JCN JMP2r
@spop ( str* -- ) LDAk ,&n JCN POP2 JMP2r &n ,scap JSR #0001 SUB2 #00 ROT ROT STA JMP2r
@sput ( chr str* -- ) ,scap JSR STA JMP2r
@slen ( str* -- len* ) DUP2 ,scap JSR SWP2 SUB2 JMP2r
@mclr ( src* len* -- ) OVR2 ADD2 SWP2 &l STH2k #00 STH2r STA INC2 GTH2k ,&l JCN POP2 POP2 JMP2r
(
@|stdlib )

@empty-txt "Empty 20 "Stack $1

(
@|tables )

@fncpad
	:clear :swp :dup :erase :erase :erase
	:tog-mode :inv :vid :eval :eval :eval

@numpad
	:put7 :put8 :put9 :putf
	:put4 :put5 :put6 :pute
	:put1 :put2 :put3 :putd
	:put0 :puta :putb :putc

@modpad
	:div :mul :sub :add
	:and :ora :sfl :sfr

@keys
	&ctl
	"~ :clear 09 :tog-mode "? :inv "@ :vid
	&mod
	"+ :add "- :sub "* :mul "/ :div
	"& :and "| :ora "< :sfl "> :sfr
	&wst
	20 :eval 08 :erase "% :swp "" :dup
	&num
	"7 :put7 "8 :put8 "9 :put9 "f :putf
	"4 :put4 "5 :put5 "6 :put6 "e :pute
	"1 :put1 "2 :put2 "3 :put3 "d :putd


@@ 1076,51 1166,88 @@ JMP2r
	1b :clear
	"# :set-hex
	"$ :set-dec
	"` :os8 ( huh? )
	&end

@layout
	:buttons/clr :clear
	:buttons/mode :tog-mode
	:buttons/7 :put7
	:buttons/8 :put8
	:buttons/9 :put9
	:buttons/f :putf
	:buttons/div :div
	:buttons/and :and
	:buttons/swp :swp
	:buttons/inv :inv
	:buttons/4 :put4
	:buttons/5 :put5
	:buttons/6 :put6
	:buttons/e :pute
	:buttons/mul :mul
	:buttons/ora :ora
	:buttons/dup :dup
	:buttons/vid :vid
	:buttons/1 :put1
	:buttons/2 :put2
	:buttons/3 :put3
	:buttons/d :putd
	:buttons/sub :sub
	:buttons/sfl :sfl
	:buttons/pop :erase
	:buttons/push :eval
	:buttons/0 :put0
	:buttons/a :puta
	:buttons/b :putb
	:buttons/c :putb
	:buttons/add :add
	:buttons/sfr :sfr

@buttons ( x* y* icon* size* state )
	&ctl
	&clr  0010 0068 :ctl-icns/clr :draw-button-special 00
	&mode 0028 0068 :ctl-icns/mode :draw-button-small 00
	&inv  0040 0068 :ctl-icns/inv :draw-button-small 00
	&vid  0058 0068 :ctl-icns/vid :draw-button-small 00
	&num
	&7   0010 00b8 :num-icns/7 :draw-button 00
	&8   0028 00b8 :num-icns/8 :draw-button 00
	&9   0040 00b8 :num-icns/9 :draw-button 00
	&f   0058 00b8 :num-icns/f :draw-button-hex 00
	&4   0010 00d0 :num-icns/4 :draw-button 00
	&5   0028 00d0 :num-icns/5 :draw-button 00
	&6   0040 00d0 :num-icns/6 :draw-button 00
	&e   0058 00d0 :num-icns/e :draw-button-hex 00
	&1   0010 00e8 :num-icns/1 :draw-button 00
	&2   0028 00e8 :num-icns/2 :draw-button 00
	&3   0040 00e8 :num-icns/3 :draw-button 00
	&d   0058 00e8 :num-icns/d :draw-button-hex 00
	&0   0010 0100 :num-icns/0 :draw-button 00
	&a   0028 0100 :num-icns/a :draw-button-hex 00
	&b   0040 0100 :num-icns/b :draw-button-hex 00
	&c   0058 0100 :num-icns/c :draw-button-hex 00
	&clr  0010 0078 :ctl-icns/clr :draw-button-clr 00
	&swp  0010 0088 :wst-icns/swp :draw-button-small 00
	&dup  0010 0098 :wst-icns/dup :draw-button-small 00
	&pop  0010 00a8 :wst-icns/pop :draw-button-tall 00
	&wst
	&push 0010 00a8 :wst-icns/push :draw-button-small 00
	&pop  0028 00a8 :wst-icns/pop :draw-button-small 00
	&swp  0040 00a8 :wst-icns/swp :draw-button-small 00
	&dup  0058 00a8 :wst-icns/dup :draw-button-small 00
	&mode 0028 0078 :ctl-icns/mode :draw-button-small 00
	&inv  0028 0088 :ctl-icns/inv :draw-button-small 00
	&vid  0028 0098 :ctl-icns/vid :draw-button-small 00
	&push 0028 00a8 :wst-icns/push :draw-button-tall 00
	&num
	&7   0040 0078 :num-icns/7 :draw-button 00
	&8   0058 0078 :num-icns/8 :draw-button 00
	&9   0070 0078 :num-icns/9 :draw-button 00
	&f   0088 0078 :num-icns/f :draw-button-hex 00
	&4   0040 0090 :num-icns/4 :draw-button 00
	&5   0058 0090 :num-icns/5 :draw-button 00
	&6   0070 0090 :num-icns/6 :draw-button 00
	&e   0088 0090 :num-icns/e :draw-button-hex 00
	&1   0040 00a8 :num-icns/1 :draw-button 00
	&2   0058 00a8 :num-icns/2 :draw-button 00
	&3   0070 00a8 :num-icns/3 :draw-button 00
	&d   0088 00a8 :num-icns/d :draw-button-hex 00
	&0   0040 00c0 :num-icns/0 :draw-button 00
	&a   0058 00c0 :num-icns/a :draw-button-hex 00
	&b   0070 00c0 :num-icns/b :draw-button-hex 00
	&c   0088 00c0 :num-icns/c :draw-button-hex 00
	&mod
	&add 0010 0078 :mod-icns/add :draw-button 00
	&sub 0028 0078 :mod-icns/sub :draw-button 00
	&mul 0040 0078 :mod-icns/mul :draw-button 00
	&div 0058 0078 :mod-icns/div :draw-button 00
	&and 0010 0090 :mod-icns/and :draw-button 00
	&ora 0028 0090 :mod-icns/ora :draw-button 00
	&sfl 0040 0090 :mod-icns/sfl :draw-button 00
	&sfr 0058 0090 :mod-icns/sfr :draw-button 00

	&div 00a0 0078 :mod-icns/div :draw-button 00
	&mul 00a0 0090 :mod-icns/mul :draw-button 00
	&sub 00a0 00a8 :mod-icns/sub :draw-button 00
	&add 00a0 00c0 :mod-icns/add :draw-button 00
	&and 00b8 0078 :mod-icns/and :draw-button 00
	&ora 00b8 0090 :mod-icns/ora :draw-button 00
	&sfl 00b8 00a8 :mod-icns/sfl :draw-button 00
	&sfr 00b8 00c0 :mod-icns/sfr :draw-button 00
	&end

(
@|assets )

@cursor-icn
	80c0 e0f0 f8e0 1000
@dpad-chr
	0000 ff81 8142 2418 0000 007e 7e3c 1800
@fill-icn
	ffff ffff ffff ffff
@logo-icn


@@ 1132,83 1259,65 @@ JMP2r
	001c 22c1 0000 0000
	0000 0007 8870 0000

@button
@mode-icns
	( hex/dec )
	0018 7818 1818 7e00
	003c 607c 6666 3c00
	0018 7818 1818 7e00
	003c 6666 6666 3c00
	&dot
	( f )
	007e 6060 7c60 6000
	( d )
	007c 6666 6666 7c00

@binary-icns
	003c 6666 6666 3c00
	0018 7818 1818 7e00

@button-icns
	&def
	0000 1f3f 3f3f 3f3f 001f 3f7f 7f7f 7f7f
	0000 ffff ffff ffff 00ff ffff ffff ffff
	0000 f8fc fcfc fcfc 00f8 fcfe fefe fefe
	3f3f 3f3f 3f3f 3f3f 7f7f 7f7f 7f7f 7f7f
	ffff ffff ffff ffff ffff ffff ffff ffff
	fcfc fcfc fcfc fcfc fefe fefe fefe fefe
	3f3f 3f3f 3f1f 0000 7f7f 7f7f 5f20 1f00
	ffff ffff ffff 0000 ffff ffff ff00 ff00
	fcfc fcfc fcf8 0000 fefe fefe fa04 f800
	001f 2040 4040 4040 0000 1f3f 3f3f 3f3f 
00ff 0000 0000 0000 0000 ffff ffff ffff 
00f8 0402 0202 0202 0000 f8fc fcfc fcfc 
4040 4040 4040 4040 3f3f 3f3f 3f3f 3f3f 
0000 0000 0000 0000 ffff ffff ffff ffff 
0202 0202 0202 0202 fcfc fcfc fcfc fcfc 
4040 4040 4020 1f00 3f3f 3f3f 1f00 0000 
0000 0000 0000 ff00 ffff ffff ff00 0000 
0202 0202 0204 f800 fcfc fcfc f800 0000 

	&alt
	0000 001f 3f3f 3f3f 0000 1f20 4040 4040
	0000 00ff ffff ffff 0000 ff00 0000 0000
	0000 00f8 fcfc fcfc 0000 f804 0202 0202
	3f3f 3f3f 3f3f 3f3f 4040 4040 4040 4040
	ffff ffff ffff ffff 0000 0000 0000 0000
	fcfc fcfc fcfc fcfc 0202 0202 0202 0202
	3f3f 3f3f 3f1f 0000 4040 4040 4020 1f00
	ffff ffff ffff 0000 0000 0000 0000 ff00
	fcfc fcfc fcf8 0000 0202 0202 0204 f800
	&os8-def
	0000 001f 1f1f 1f1f 0000 3f3f 3f3f 3f3f
	0000 00ff ffff ffff 0000 ffff ffff ffff
	0000 00f8 f8f8 f8f8 0000 fcfc fcff ffff
	1f1f 1f1f 1f1f 1f1f 3f3f 3f3f 3f3f 3f3f
	ffff ffff ffff ffff ffff ffff ffff ffff
	f8f8 f8f8 f8f8 f8f8 ffff ffff ffff ffff
	1f1f 1f1f 1f00 0000 3f3f 3f3f 3f3f 0f0f
	ffff ffff ff00 0000 ffff ffff ffff ffff
	f8f8 f8f8 f800 0000 ffff ffff ffff ffff
	&os8-alt
	0000 0000 1f1f 1f1f 0000 003f 2020 2020
	0000 0000 ffff ffff 0000 00ff 0000 0000
	0000 0000 f8f8 f8f8 0000 00fc 0404 0707
	1f1f 1f1f 1f1f 1f1f 2020 2020 2020 2020
	ffff ffff ffff ffff 0000 0000 0000 0000
	f8f8 f8f8 f8f8 f8f8 0707 0707 0707 0707
	1f1f 1f1f 1f1f 1f00 2020 2020 2020 203f
	ffff ffff ffff ff00 0000 0000 0000 00ff
	f8f8 f8f8 f8f8 f800 0707 0707 0707 07ff
	001f 2040 4040 4040 0000 001f 3f3f 3f3f 
00ff 0000 0000 0000 0000 00ff ffff ffff 
00f8 0402 0202 0202 0000 00f8 fcfc fcfc 
4040 4040 4040 4040 3f3f 3f3f 3f3f 3f3f 
0000 0000 0000 0000 ffff ffff ffff ffff 
0202 0202 0202 0202 fcfc fcfc fcfc fcfc 
4040 4040 4020 1f00 3f3f 3f3f 3f1f 0000 
0000 0000 0000 ff00 ffff ffff ffff 0000 
0202 0202 0204 f800 fcfc fcfc fcf8 0000 

@display-frame
	&def
	0000 0000 0000 0000 003f 7f7f 7f7f 7f7f
	0000 0000 0000 0000 00ff ffff ffff ffff
	0000 0000 0000 0000 00fc fefe fefe fefe
	0000 0000 0000 0000 fefe fefe fefe fefe
	0000 0000 0000 0000 7f7f 7f7f 7f7f 7f7f
	0000 0000 0040 3f00 7f7f 7f7f 7f3f 0000
	0000 0000 0000 ff00 ffff ffff ffff 0000
	0000 0000 0002 fc00 fefe fefe fefc 0000
	&os8
	0000 0000 0000 0000 0000 3f20 2f2f 2f2f
	0000 0000 0000 0000 0000 ff00 ffff ffff
	0000 0000 0000 0000 0000 fc04 f4f4 f4f4
	0000 0000 0000 0000 f4f4 f4f4 f4f4 f4f4
	0000 0000 0000 0000 2f2f 2f2f 2f2f 2f2f
	0000 0000 0000 0000 2f2f 2f2f 203f 0000
	0000 0000 0000 0000 ffff ffff 00ff 0000
	0000 0000 0000 0000 f4f4 f4f4 04fc 0000
001f 205f 5f5f 5f5f 0000 1f20 2020 2020 
00ff 00ff ffff ffff 0000 ff00 0000 0000 
00f8 04fa fafa fafa 0000 f804 0404 0404 
fafa fafa fafa fafa 0404 0404 0404 0404 
5f5f 5f5f 5f5f 5f5f 2020 2020 2020 2020 
5f5f 5f5f 5f20 1f00 2020 2020 201f 0000 
ffff ffff ff00 ff00 0000 0000 00ff 0000 
fafa fafa fa04 f800 0404 0404 04f8 0000

@outline-frame
	0000 0000 0000 0102 8000 0000 0000 0000
	0000 0000 0000 ff00 0000 0000 0000 0000
	0000 0000 0000 8040 f160 0000 0000 0000
	4040 4040 4040 4040 0000 0000 0000 0000
	0202 0202 0202 0202 0000 0000 0000 0000
	0201 0000 0000 0000 0000 0000 0000 0080
	00ff 0000 0000 0000 0000 0000 0000 0000
	4080 0000 0000 0000 0000 0000 0000 0001

@ctl-icns
	&clr 0000 183c 3c18 0000
	&mode 0000 007f fe00 0000
	&inv 007c 7e02 407e 3e00
	&vid 0033 6666 6666 cc00
@outline-frame
0000 0000 0000 0001 0000 0000 0000 0000 
0000 0000 0000 ff00 0000 0000 0000 0000 
0000 0000 0000 0080 0000 0000 0000 0000 
4040 4040 4040 4040 0000 0000 0000 0000 
0202 0202 0202 0202 0000 0000 0000 0000 
0100 0000 0000 0000 0000 0000 0000 0000 
00ff 0000 0000 0000 0000 0000 0000 0000 
8000 0000 0000 0000 0000 0000 0000 0000 

@mod-icns
	&and


@@ 1236,10 1345,16 @@ JMP2r
	0000 0001 0100 001f 0000 0080 8000 00f8
	1f00 0001 0100 0000 f800 0080 8000 0000

@ctl-icns
	&clr 0000 183c 3c18 0000
	&mode 0000 007f fe00 0000
	&inv 006c 6666 6666 3600
	&vid 0033 6666 6666 cc00

@wst-icns
	&push 0018 3c7e 1818 1800
	&pop 0018 1818 7e3c 1800
	&swp 006c 6666 6666 3600
	&swp 007c 7e02 407e 3e00
	&dup 003c 6666 6666 6c00

@num-icns


@@ 1292,6 1407,16 @@ JMP2r
	0000 000f 1f18 181f 0000 00f8 f800 0080
	1f18 1818 1800 0000 8000 0000 0000 0000

@slash-icns
0000 0006 060c 0c18
1830 3060 6000 0000
@dot-icns
0000 0000 0000 0000
0000 0018 1800 0000
@quote-icns
0000 0018 1818 0800
0000 0000 0000 0000

@tone 
8eae b5b9 c0ce dbdc cdb6 a295 8b80 7364 
5953 5256 585a 5d62 686f 7579 7d7e 8183 


@@ 1310,55 1435,8 @@ cfdc dacb b4a0 948b 8072 6458 5354 5558
7a7e 8182 8589 8d8e 8e8d 8a8a 8887 8582 
807e 7e7d 7c7c 7c7c 7d7b 7463 4121 1e46 

@font ( atari8 )
0000 0000 0000 0000 6060 6060 6000 6000
6666 6600 0000 0000 006c fe6c 6cfe 6c00
183e 603c 067c 1800 0066 6c18 3066 4600
386c 3870 decc 7600 6060 6000 0000 0000
1c30 3030 3030 1c00 380c 0c0c 0c0c 3800
0066 3cff 3c66 0000 0018 187e 1818 0000
0000 0000 0030 3060 0000 007e 0000 0000
0000 0000 0018 1800 0306 0c18 3060 c000
3c66 6e76 6666 3c00 1838 1818 1818 7e00
3c66 060c 1830 7e00 7e0c 180c 0666 3c00
0c1c 3c6c 7e0c 0c00 7e60 7c06 0666 3c00
3c60 607c 6666 3c00 7e06 0c18 3030 3000
3c66 663c 6666 3c00 3c66 663e 060c 3800
0018 1800 0018 1800 0018 1800 1818 3000
0c18 3060 3018 0c00 0000 7e00 007e 0000
3018 0c06 0c18 3000 3c66 060c 1800 1800
3c66 6e6a 6e60 3e00 183c 6666 7e66 6600
7c66 667c 6666 7c00 3c66 6060 6066 3c00
786c 6666 666c 7800 7e60 607c 6060 7e00
7e60 607c 6060 6000 3e60 606e 6666 3e00
6666 667e 6666 6600 7830 3030 3030 7800
3e06 0606 0666 3c00 666c 7870 786c 6600
6060 6060 6060 7e00 c6ee fed6 c6c6 c600
6676 7e7e 6e66 6600 3c66 6666 6666 3c00
7c66 667c 6060 6000 3c66 6666 766c 3600
7c66 667c 6c66 6600 3c66 603c 0666 3c00
7e18 1818 1818 1800 6666 6666 6666 3e00
6666 6666 663c 1800 c6c6 c6d6 feee c600
6666 3c18 3c66 6600 6666 663c 1818 1800
7e06 0c18 3060 7e00 3c30 3030 3030 3c00
c060 3018 0c06 0300 3c0c 0c0c 0c0c 3c00
1038 6cc6 0000 0000 0000 0000 0000 fe00
0060 3018 0000 0000 0000 3c06 3e66 3e00
6060 7c66 6666 7c00 0000 3c60 6060 3c00
0606 3e66 6666 3e00 0000 3c66 7e60 3c00
1c30 7c30 3030 3000 0000 3e66 663e 067c
6060 7c66 6666 6600 1800 3818 1818 3c00
1800 1818 1818 1870 6060 666c 786c 6600
3818 1818 1818 3c00 0000 ecfe d6c6 c600
0000 7c66 6666 6600 0000 3c66 6666 3c00
0000 7c66 6666 7c60 0000 3e66 6666 3e06
0000 7c66 6060 6000 0000 3e60 3c06 7c00
0018 7e18 1818 0e00 0000 6666 6666 3e00
0000 6666 663c 1800 0000 c6c6 d67c 6c00
0000 663c 183c 6600 0000 6666 663e 067c
0000 7e0c 1830 7e00 1c30 3060 3030 1c00
1818 1818 1818 1818 380c 0c06 0c0c 3800
0000 60f2 9e0c 0000 0018 1834 3462 7e00
(
@|memory )

@memory ( den*, num*, den*, num*, .. )