~rabbits/nasu

4efbe19669ee3a91e84835fc06f0ed4109c88951 — neauoire 1 year, 9 months ago c4a8876
Added colors to nasuxn
2 files changed, 115 insertions(+), 249 deletions(-)

M nasu.c
M nasu.usm
M nasu.c => nasu.c +3 -3
@@ 41,9 41,9 @@ Brush brush;

Uint32 theme[] = {
	0x000000,
	0xFFFFFF,
	0x72DEC2,
	0x666666,
	0xee3333,
	0xffccaa,
	0xcccccc,
	0x222222};

Uint8 icons[][8] = {

M nasu.usm => nasu.usm +112 -246
@@ 9,11 9,14 @@

	TODO:
		Copy in 2 bits mode, copies 2 tiles
		Modify up to 4 pages
		Save/load/rename
		Select paint color for 2-bit mode
		Inject a new tile at location
		Delete tile at location
		Tile Modifiers
		Zoom
		Brushes
		Resize buttons
)

%+  { ADD } %-   { SUB }  %*  { MUL } %/   { DIV }


@@ 74,6 77,7 @@
|0000

@settings [ 
	&color $1
	&blending $1 
	&depth $1 
	&brush $1 


@@ 86,8 90,6 @@
@frame [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 &width $2 &height $2 ]

( interface )
@bankview  [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
@editview  [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
@toolview  [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
@colorview [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]
@blendview [ &x1 $2 &y1 $2 &x2 $2 &y2 $2 ]


@@ 117,66 119,47 @@

	( set defaults )
	HOR TOS #0008 ** .frame/width STZ2
	VER TOS #0008 ** #0040 ++ .frame/height STZ2
	VER TOS #0008 ** #0048 ++ .frame/height STZ2
	#01 .settings/brush STZ
	#32 .settings/ratio STZ
	BANK .settings/page STZ2
	BANK #0448 ++ .settings/tile STZ2
	#01 .settings/depth STZ
	#01 .settings/blending STZ
	#01 .settings/color STZ

	.Screen/width DEI2 #0001 SFT2 .frame/width LDZ2 #0001 SFT2 --
	.Screen/height DEI2 #0001 SFT2 .frame/height LDZ2 #0001 SFT2 --
	.frame/width LDZ2 .frame/height LDZ2
	SIZE-TO-RECT ;frame SET-RECT

	.frame/x1 LDZ2 #0010 ++ .frame/y2 LDZ2 #0080 -- #0080 #0080 SIZE-TO-RECT ;bankview SET-RECT
	.frame/x2 LDZ2 #0090 -- .frame/y2 LDZ2 #0080 -- #0080 #0080 SIZE-TO-RECT ;editview SET-RECT
	.frame/x1 LDZ2 .frame/y2 LDZ2 #0008 -- HOR TOS #0008 ** #0008 SIZE-TO-RECT ;toolview SET-RECT

	.frame/x1 LDZ2 .frame/y1 LDZ2 #0030 ++ #0100 #0080 SIZE-TO-RECT ;tileview SET-RECT
	.frame/x1 LDZ2 .frame/y1 LDZ2 #0038 ++ HOR TOS #0008 ** VER TOS #0008 ** SIZE-TO-RECT ;tileview SET-RECT
	.tileview/x1 LDZ2 .tileview/y2 LDZ2 #0008 ++ HOR TOS #0008 ** #0008 SIZE-TO-RECT ;toolview SET-RECT

	.frame/x1 LDZ2 .frame/y1 LDZ2 #0020 #0020 SIZE-TO-RECT ;blendview SET-RECT
	.frame/x1 LDZ2 #0030 ++ .frame/y1 LDZ2 #0020 #0020 SIZE-TO-RECT ;preview SET-RECT
	.frame/x1 LDZ2 #0060 ++ .frame/y1 LDZ2 #0020 #0020 SIZE-TO-RECT ;colorview SET-RECT
	.frame/x1 LDZ2 #0090 ++ .frame/y1 LDZ2 #0048 #0020 SIZE-TO-RECT ;dataview SET-RECT


	.tileview/x1 LDZ2 #0002 -- 
	.tileview/y1 LDZ2 #0002 -- 
	.tileview/x2 LDZ2 #0001 ++ 
	.tileview/y2 LDZ2 #0001 ++ #03 ;line-rect JSR2
(


	.frame/x1 LDZ2 #0002 -- 
	.frame/y1 LDZ2 #0002 -- 
	.frame/x2 LDZ2 #0001 ++ 
	.frame/y2 LDZ2 #0001 ++ #02 ;line-rect JSR2

	.editview/x1 LDZ2 DUP2 #0080 ++ .editview/y1 LDZ2 #0020 ++ #03 ;line-hor JSR2
	.editview/x1 LDZ2 DUP2 #0080 ++ .editview/y1 LDZ2 #0040 ++ #03 ;line-hor JSR2
	.editview/x1 LDZ2 DUP2 #0080 ++ .editview/y1 LDZ2 #0060 ++ #03 ;line-hor JSR2
	.editview/x1 LDZ2 #0020 ++ .editview/y1 LDZ2 DUP2 #0080 ++ #03 ;line-ver JSR2
	.editview/x1 LDZ2 #0040 ++ .editview/y1 LDZ2 DUP2 #0080 ++ #03 ;line-ver JSR2
	.editview/x1 LDZ2 #0060 ++ .editview/y1 LDZ2 DUP2 #0080 ++ #03 ;line-ver JSR2

	.bankview/x1 LDZ2 #0002 -- 
	.bankview/y1 LDZ2 #0002 -- 
	.bankview/x2 LDZ2 #0001 ++ 
	.bankview/y2 LDZ2 #0001 ++ #03 ;line-rect JSR2

	.editview/x1 LDZ2 #0002 -- 
	.editview/y1 LDZ2 #0002 -- 
	.editview/x2 LDZ2 #0001 ++ 
	.editview/y2 LDZ2 #0001 ++ #03 ;line-rect JSR2

	.frame/x1 LDZ2 .frame/x2 LDZ2 .frame/y1 LDZ2 #0032 ++ #03 ;line-hor JSR2

	
	.tileview/x1 LDZ2 #0002 -- 
	.tileview/y1 LDZ2 #0002 -- 
	.tileview/x2 LDZ2 #0001 ++ 
	.tileview/y2 LDZ2 #0001 ++ #03 ;line-rect JSR2
	.toolview/x1 LDZ2 #0002 -- 
	.toolview/y1 LDZ2 #0002 -- 
	.toolview/x2 LDZ2 #0001 ++ 
	.toolview/y2 LDZ2 #0001 ++ #03 ;line-rect JSR2


	.frame/x1 LDZ2 .frame/x2 LDZ2 .frame/y1 LDZ2 #0032 ++ #03 ;line-hor JSR2

	
	.blendview/x1 LDZ2 #0002 -- 
	.blendview/y1 LDZ2 #0002 -- 


@@ 204,9 187,8 @@
	.frame/y2 LDZ2 #0001 ++ #02 ;line-rect JSR2
	
)
	#01 .settings/blending STZ

	;filepath1 .File/name DEO2 #1000 .File/length DEO2 BANK .File/load DEO2
	;filepath1 .File/name DEO2 #2000 .File/length DEO2 BANK .File/load DEO2

	;redraw JSR2



@@ 257,21 239,12 @@ BRK
	.Mouse/y DEI2 DUP2 .tileview/y1 LDZ2 >> ROT ROT .tileview/y2 LDZ2 << #0101 ==
	#0101 == ;on-touch-tileview JCN2

	( bankview )
	.Mouse/x DEI2 DUP2 .bankview/x1 LDZ2 >> ROT ROT .bankview/x2 LDZ2 << #0101 ==
	.Mouse/y DEI2 DUP2 .bankview/y1 LDZ2 >> ROT ROT .bankview/y2 LDZ2 << #0101 ==
	#0101 == ;on-touch-bankview JCN2

	( editview )
	.Mouse/x DEI2 DUP2 .editview/x1 LDZ2 >> ROT ROT .editview/x2 LDZ2 << #0101 ==
	.Mouse/y DEI2 DUP2 .editview/y1 LDZ2 >> ROT ROT .editview/y2 LDZ2 << #0101 ==
	#0101 == ;on-touch-editview JCN2

	( toolview )
	.Mouse/x DEI2 DUP2 .toolview/x1 LDZ2 >> ROT ROT .toolview/x2 LDZ2 << #0101 ==
	.Mouse/y DEI2 DUP2 .toolview/y1 LDZ2 >> ROT ROT .toolview/y2 LDZ2 << #0101 ==
	#0101 == ;on-touch-toolview JCN2


	( dataview )
	.Mouse/x DEI2 DUP2 .dataview/x1 LDZ2 >> ROT ROT .dataview/x2 LDZ2 << #0101 ==
	.Mouse/y DEI2 DUP2 .dataview/y1 LDZ2 >> ROT ROT .dataview/y2 LDZ2 << #0101 ==


@@ 298,61 271,21 @@ BRK
	
	.Mouse/x DEI2 .tileview/x1 LDZ2 -- 
	.Mouse/y DEI2 .tileview/y1 LDZ2 -- 
	;get-addr JSR2 LDA
	DEBUG

BRK

@on-touch-bankview ( -> )
	
	.settings/tool LDZ #01 ! ,&not-copy-mode JCN
		#00 #10
		&copy-loop
			( from )
			OVR TOS GET-ADDR ++ LDA STH
			( to )
			OVR STHr SWP TOS 
			.Mouse/x DEI2 .bankview/x1 LDZ2 -- #0008 //
			.Mouse/y DEI2 .bankview/y1 LDZ2 -- #0008 // #0010 ** ++
			#0010 ** BANK ++ ++ STA
			INCR
			LTHk ,&copy-loop JCN
		POP2
		( release ) #00 .Mouse/state DEO
		;redraw JSR2 BRK
	&not-copy-mode

	.settings/tool LDZ #02 ! ,&not-erase-mode JCN
		#00 #10
		&erase-loop
			OVR #00 SWP TOS 
			.Mouse/x DEI2 .bankview/x1 LDZ2 -- #0008 //
			.Mouse/y DEI2 .bankview/y1 LDZ2 -- #0008 // #0010 ** ++
			#0010 ** BANK ++ ++ STA
			INCR
			LTHk ,&erase-loop JCN
		POP2
		( release ) #00 .Mouse/state DEO
		;redraw JSR2 BRK
	&not-erase-mode

	( select )
	.Mouse/x DEI2 .bankview/x1 LDZ2 -- #0008 // TOB
	.Mouse/y DEI2 .bankview/y1 LDZ2 -- #0008 // TOB #40 SFT +
	.settings/selection STZ
	;redraw JSR2

BRK

@on-touch-editview ( -> )
	
	#aa DEBUG
	.settings/color LDZ
	;put-pixel JSR2
	;draw-tileview JSR2

BRK

@on-touch-toolview ( -> )
	
	#aa DEBUG
	.Mouse/x DEI2 .toolview/x1 LDZ2 -- #0008 // TOB
	DUP #02 > ,&no-color JCN
		DUP #01 + .settings/color STZ
		;draw-toolview JSR2
		&no-color
	POP
	( release ) #00 .Mouse/state DEO

BRK



@@ 414,17 347,6 @@ BRK

	( release ) #00 .Mouse/state DEO

	( clear editview )
	.editview/x1 LDZ2 .editview/y1 LDZ2 .editview/x2 LDZ2 .editview/y2 LDZ2 #00 ;fill-rect JSR2

	( editview grid )
	.editview/x1 LDZ2 DUP2 #0080 ++ .editview/y1 LDZ2 #0020 ++ #03 ;line-hor JSR2
	.editview/x1 LDZ2 DUP2 #0080 ++ .editview/y1 LDZ2 #0040 ++ #03 ;line-hor JSR2
	.editview/x1 LDZ2 DUP2 #0080 ++ .editview/y1 LDZ2 #0060 ++ #03 ;line-hor JSR2
	.editview/x1 LDZ2 #0020 ++ .editview/y1 LDZ2 DUP2 #0080 ++ #03 ;line-ver JSR2
	.editview/x1 LDZ2 #0040 ++ .editview/y1 LDZ2 DUP2 #0080 ++ #03 ;line-ver JSR2
	.editview/x1 LDZ2 #0060 ++ .editview/y1 LDZ2 DUP2 #0080 ++ #03 ;line-ver JSR2

	;redraw JSR2

BRK


@@ 496,63 418,51 @@ RTN

@redraw ( -- )
	
	(
	;draw-bankview JSR2
	;draw-editview JSR2 
	)

	;draw-toolview JSR2 
	;draw-blendview JSR2
	;draw-colorview JSR2
	;draw-dataview JSR2
	;draw-preview JSR2


	;draw-tileview JSR2

RTN

@draw-tileview ( -- )
	
	#0000 HEIGHT
	#00 VER
	&ver
		OVR2 STH2
		#0000 WIDTH
		OVR DUP #08 * TOS .tileview/y1 LDZ2 ++ .Screen/y DEO2 STH
		#00 HOR
		&hor
			( have iterators )
			OVR2 STH2kr
			( get pixel )
			OVR2 OVR2 ,get-pixel JSR
			( put pixel )
			;put-pixel JSR2
			INCR2
			LTH2k ,&hor JCN
		POP2 POP2
		POP2r
		INCR2
		LTH2k ,&ver JCN
	POP2 POP2
			OVR DUP #08 * TOS .tileview/x1 LDZ2 ++ .Screen/x DEO2 STHkr
			TOS ROT TOS SWP2
			HOR TOS ** ++ #0010 **
			BANK ++ .Screen/addr DEO2
			.settings/blending LDZ 
			.settings/depth LDZ #20 * +
			#20 + .Screen/color DEO
			INCR
			LTHk ,&hor JCN
		POP2
		POPr
		INCR
		LTHk ,&ver JCN
	POP2

RTN

@get-pixel ( x* y* -- color )
	
	( get address )
	OVR2 SWP2 ,get-addr JSR LDA
	( get mod of x* )
	ROT ROT TOB #08 MOD
	( get color )
	( channel 1 )
	OVR2 SWP2 ,get-addr JSR [ STH2k ] LDA
	ROT ROT TOB #08 MOD [ STHk ]
	#07 SWP - SFT #01 AND

RTN

@put-pixel ( x* y* color -- )

	STH
	.tileview/y1 LDZ2 ++ .Screen/y DEO2
	.tileview/x1 LDZ2 ++ .Screen/x DEO2
	STHr
	.Screen/color DEO
	( channel 2 )
	[ STHr ] [ STH2r ] #0008 ++ LDA SWP 
	#07 SWP - SFT #01 AND
	#02 * 
	+

RTN



@@ 560,127 470,79 @@ RTN
	
	( get row )
	DUP2 #0008 MOD2 

	( get tile )
	SWP2 #0008 // WIDTH #0002 ** ** ++

	SWP2 STEP8 
	#0002 ** 
	++ 
	SWP2 STEP8 #0002 ** ++ 
	BANK ++

RTN

@draw-bankview ( -- )

	( guides )
	.bankview/x1 LDZ2 #0010 -- .Screen/x DEO2
	.bankview/y1 LDZ2 .Screen/y DEO2
	;font-hex .Screen/addr DEO2
	#00 #10
	&guides
		( draw ) OVR .settings/selection LDZ #04 SFT = #21 + .Screen/color DEO
		.Screen/addr DEI2 #0008 ++ .Screen/addr DEO2
		.Screen/y DEI2 #0008 ++ .Screen/y DEO2
		INCR
		LTHk ,&guides JCN
	POP2

	( draw page )
	#00 #10
	&ver
		OVR #08 * TOS .bankview/y1 LDZ2 ++ .Screen/y DEO2
		#00 #10
		&hor
			OVR #08 * TOS .bankview/x1 LDZ2 ++ .Screen/x DEO2
			GET-ITERATORS
			( addr ) DUP2 TOS #0100 ** ROT TOS #0010 ** ++ BANK ++ .Screen/addr DEO2
			( draw ) #40 SFT + .settings/selection LDZ = #40 .settings/blending LDZ + + .Screen/color DEO
			INCR
			LTHk ,&hor JCN
		POP2
		INCR
		LTHk ,&ver JCN
	POP2
	
RTN

@draw-editview ( -- )
@put-pixel ( x* y* color -- )

	( tiles )
	GET-ADDR STH2k .Screen/addr DEO2
	#00 #04
	&ver
		OVR #20 * TOS .editview/y1 LDZ2 ++ .Screen/y DEO2
		#00 #04
		&hor
			OVR #20 * TOS .editview/x1 LDZ2 ++ .Screen/x DEO2
			GET-ITERATORS
			.settings/ratio LDZ #0f AND < STH
			.settings/ratio LDZ #04 SFT < STHr
			#0101 !! ,&outside JCN 
				STH2kr .Screen/addr DEO2
				,draw-tile JSR
				( incr ) STH2r #0010 ++ STH2
			&outside
			( incr ) INCR
			LTHk ,&hor JCN
		POP2
		( incr ) INCR
		LTHk ;&ver JCN2
	POP2
	POP2r
	STH
	OVR2 SWP2 ,get-addr JSR 
	( ch1 )
	OVR2 OVR2
		STHkr #00 ,toggle-pixel JSR
	( ch2 )
	#0008 ++ 
		STHr #01 ,toggle-pixel JSR

RTN

@draw-tile ( -- )

	#00 #08
	&ver
		#00 #08
		&hor
			( get x,y )
			GET-ITERATORS
			( get address )
			.Screen/addr DEI2 
			( after this, +R XY )
			SWP2 SWP STH
			( got sprite line )
			TOS ++ LDA
			( get pixel )
			STHr 
			#07 SWP - SFT #01 AND
			.Screen/color DEO

			( move ) #0004 .Screen/x DEI2 ++ .Screen/x DEO2
			( incr ) INCR
			LTHk ,&hor JCN
		POP2
		( move ) #0004 .Screen/y DEI2 ++ .Screen/y DEO2
		( rewind ) .Screen/x DEI2 #0020 -- .Screen/x DEO2
		( incr ) INCR
		LTHk ,&ver JCN
	POP2
	( rewind ) .Screen/y DEI2 #0020 -- .Screen/y DEO2
@toggle-pixel ( x* addr* color* -- )
	
	STH2
	DUP2 LDA
	STH SWP2 TOB
	STHr SWP 
	STH2r SFT #01 AND ,&do-set JCN
		( mask ) #01 #07 ROT #08 MOD - SFL #ff EOR AND
		( save ) ROT ROT STA
		RTN
	&do-set
		( mask ) #01 #07 ROT #08 MOD - SFL ORA
		( save ) ROT ROT STA

RTN

@draw-toolview ( -- )
	
		
	.toolview/y1 LDZ2 .Screen/y DEO2

	.toolview/x1 LDZ2 .Screen/x DEO2

	( colors )

	;circle-icns [ .settings/color LDZ #01 = TOS #0008 ** ] ++ .Screen/addr DEO2
	#21 .Screen/color DEO
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	;circle-icns [ .settings/color LDZ #02 = TOS #0008 ** ] ++ .Screen/addr DEO2
	#22 .Screen/color DEO
	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	;circle-icns [ .settings/color LDZ #03 = TOS #0008 ** ] ++ .Screen/addr DEO2
	#23 .Screen/color DEO

	.Screen/x DEI2 #0010 ++ .Screen/x DEO2
	;tool_selector .Screen/addr DEO2
	#21 .settings/tool LDZ #00 = + .Screen/color DEO

	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	;tool_hand .Screen/addr DEO2
	#21 .settings/tool LDZ #01 = + .Screen/color DEO

	.Screen/x DEI2 #0008 ++ .Screen/x DEO2
	;tool_eraser .Screen/addr DEO2
	#21 .settings/tool LDZ #02 = + .Screen/color DEO

	( file i/o )
	.toolview/x2 LDZ2 #0008 -- .Screen/x DEO2
	;name-icn .Screen/addr DEO2
	#21 .Screen/color DEO
	.Screen/x DEI2 #0008 -- .Screen/x DEO2
	;save-icn .Screen/addr DEO2
	#21 .Screen/color DEO
	.Screen/x DEI2 #0008 -- .Screen/x DEO2
	;load-icn .Screen/addr DEO2
	#21 .Screen/color DEO

RTN

@draw-blendview ( -- )


@@ 754,11 616,11 @@ RTN
	.settings/brush LDZ #23 ;draw-byte JSR2

	.colorview/x1 LDZ2 .Screen/x DEO2
	;circle_icns .Screen/addr DEO2
	;circle-icns .Screen/addr DEO2

	#00 #04
	&loop
		OVR .settings/brush LDZ = #00 SWP #0008 ** ;circle_icns ++ .Screen/addr DEO2
		OVR .settings/brush LDZ = #00 SWP #0008 ** ;circle-icns ++ .Screen/addr DEO2
		OVR .colorview/y1 LDZ2 ROT #00 SWP #0008 ** ++ .Screen/y DEO2
		OVR #20 + .Screen/color DEO
		INCR


@@ 935,9 797,13 @@ RTN
@movedown_icn  0010 1010 fe7c 3810
@halftone_icn  aa55 aa55 aa55 aa55

@circle_icns
	0038 7cfe fefe 7c38 ( full )
	0038 4482 8282 4438 ( line )
@name-icn  1054 28c6 2854 1000 
@save-icn  fe82 8282 848a f400 
@load-icn  feaa d6aa d4aa f400 

@circle-icns
	3844 8282 8244 3800 ( full )
	387c fefe fe7c 3800 ( line )
@eye_icns
	0038 4492 2810 0000 ( open )
	0000 0082 4438 0000 ( closed )