NEW
  AUTO 3,1
				.LIST OFF
				.OP	65C02
				.OR	$2000
				.TF root/tuitest
*--------------------------------------
				.INB inc/macros.i
				.INB inc/a2osx.i
				.INB inc/libtui.i
*--------------------------------------
EV.SAVE			.EQ $C0
EV.QUIT			.EQ $C1
EV.CHECKBOX		.EQ $C2
EV.RADIO		.EQ $C3
EV.LBOX1.CHANGED	.EQ $C4
EV.LBOX1.PRESSED	.EQ $C5
EV.OK			.EQ $CE
EV.CANCEL		.EQ $CF
*--------------------------------------
				.DUMMY
				.OR ZPBIN
ZS.START
ZPPtr1			.BS 2

hCTX			.BS 1
hSCRN			.BS 1

hTBOX1			.BS 1
hRADIO1			.BS 1

hDLGSAVE		.BS 1
ZS.END			.ED
*--------------------------------------
*			File Header (16 Bytes)
*--------------------------------------
CS.START		cld
				jmp (.1,x)
				.DA #$61				6502,Level 1 (65c02)
				.DA #1					BIN Layout Version 1
				.DA #0					S.PS.F.EVENT
				.DA #0
				.DA CS.END-CS.START		Code Size (without Constants)
				.DA DS.END-DS.START		Data Segment Size
				.DA #64					Stack Size
				.DA #ZS.END-ZS.START	Zero Page Size
				.DA 0
*--------------------------------------
.1				.DA CS.INIT
				.DA CS.RUN
				.DA CS.DOEVENT
				.DA	CS.QUIT
L.LIBTUI		.DA LIBTUI
*--------------------------------------
L.SCRN.Title	.DA SCRN.Title

L.TBOX1.Title	.DA TBOX1.Title
L.TBOX1.Status	.DA TBOX1.Status

L.LBOX1.List	.DA LBOX1.List
L.LABEL.Label	.DA LABEL.Label
L.TLINE.Default	.DA TLINE.Default
L.CBOX1.Label	.DA CBOX1.Label
L.RADIO1.List	.DA RADIO1.List
L.BUTQ.Label	.DA BUTQ.Label
L.BUTS.Label	.DA BUTS.Label
L.DLGSAVE.Title	.DA DLGSAVE.Title
L.BUT.OK		.DA BUT.OK
L.BUT.Cancel	.DA BUT.Cancel
				.DA 0
*--------------------------------------
CS.INIT			>LDYA L.LIBTUI
				>SYSCALL LoadLib
				bcs CS.INIT.RTS

				sta hLIBTUI

*				clc

CS.INIT.RTS		rts
*--------------------------------------
CS.RUN			>LIBCALL hLIBTUI,LIBTUI.Init
				bcs CS.INIT.RTS
				
				sta hCTX

				jsr CS.SCRN.Init
				bcs CS.INIT.RTS

				jsr CS.TBOX1.Init
				bcs CS.INIT.RTS

				jsr CS.LBOX1.Init
				bcs CS.INIT.RTS

				jsr CS.TLINE1.Init
				bcs CS.INIT.RTS

				jsr CS.CBOX1.Init
				bcs CS.INIT.RTS

				jsr CS.RADIO1.Init
				bcs CS.INIT.RTS

				jsr CS.BUT.Init
				bcs CS.INIT.RTS

				jsr CS.SCRN.Draw		Will Call SCRN.Draw

				lda hTBOX1
				>LIBCALL hLIBTUI,LIBTUI.Activate
*--------------------------------------
CS.RUN.LOOP		lda hSCRN
				>LIBCALL hLIBTUI,LIBTUI.Exec
				bcs .9

				cmp #EV.RESIZE
				bne .1

				jsr CS.SCRN.Draw
				bcs .9

				bra CS.RUN.LOOP

.1				cmp #EV.SAVE
				bne .2
				
				jsr CS.RUN.DLGSAVE
				bcc CS.RUN.LOOP
				
				rts

.2				cmp #EV.CHECKBOX
				bne .3

				>LDA.G CBOX1.Var
				bne .20
				
				lda hRADIO1
				>LIBCALL hLIBTUI,LIBTUI.Hide
				bcc CS.RUN.LOOP
				
				rts
				
.20				lda hRADIO1
				>LIBCALL hLIBTUI,LIBTUI.Show
				bcc CS.RUN.LOOP
				
				rts

.3				cmp #EV.LBOX1.CHANGED
				bne .8
				
				>PUSHB hSCRN
				>PUSHBI S.OBJ.pSTATUS
				>PUSHW.G LBOX1.Var
				>LIBCALL hLIBTUI,LIBTUI.SetProp
				bra CS.RUN.LOOP

.8				cmp #EV.QUIT
				bne CS.RUN.LOOP

				lda hSCRN
				>LIBCALL hLIBTUI,LIBTUI.Destroy
				
				lda #0
				sec
.9
CS.RUN.RTS		rts
*--------------------------------------
CS.SCRN.Init	>PUSHB hCTX				hParent
				>PUSHBI S.OBJ.F.bTitle+S.OBJ.F.bStatus
				>LIBCALL hLIBTUI,LIBTUI.NewScrn
				bcs .9

				sta hSCRN

				>PUSHA
				>PUSHBI S.OBJ.pTITLE
				>PUSHEA.G SCRN.TitleBuf
				>LIBCALL hLIBTUI,LIBTUI.SetProp

				>PUSHB hSCRN
				>PUSHBI S.OBJ.pSTATUS
				>PUSHW L.LBOX1.List
				>LIBCALL hLIBTUI,LIBTUI.SetProp

.9				rts
*--------------------------------------
CS.TBOX1.Init	>LDYAI 1024
				>SYSCALL GetMem
				bcs CS.RUN.RTS
				
				>STYA ZPPtr1
				
				txa
				>STA.G TBOX1.hBuf

				lda #0
				sta (ZPPtr1)

				>PUSHB hSCRN			hParent
				>PUSHBI 1				X1
				>PUSHBI 1				Y1
				>PUSHBI	44				W
				>PUSHBI 20				H
				>LDA.G TBOX1.hBuf
				>SYSCALL GetMemPtr
				>PUSHYA
				>PUSHWI 1024
				>PUSHBI S.OBJ.F.bHBorder+S.OBJ.F.bVBorder+S.OBJ.F.bTitle+S.OBJ.F.bStatus+S.OBJ.F.bEdit
				>LIBCALL hLIBTUI,LIBTUI.NewTBox
				bcs .9

				sta hTBOX1

				>PUSHA
				>PUSHBI S.OBJ.pTITLE
				>PUSHW L.TBOX1.Title
				>LIBCALL hLIBTUI,LIBTUI.SetProp

				>PUSHB hTBOX1
				>PUSHBI S.OBJ.pSTATUS
				>PUSHW L.TBOX1.Status
				>LIBCALL hLIBTUI,LIBTUI.SetProp

.9				rts
*--------------------------------------
CS.LBOX1.Init	>PUSHB hSCRN			hParent
				>PUSHBI 50				X1
				>PUSHBI 1				Y1
				>PUSHBI	20				W
				>PUSHBI 9				H
				>PUSHBI EV.LBOX1.CHANGED
				>PUSHBI EV.LBOX1.PRESSED	
				>PUSHW L.LBOX1.List
				>PUSHEA.G LBOX1.Var
				>PUSHBI S.OBJ.F.bHBorder+S.OBJ.F.bVBorder
				>LIBCALL hLIBTUI,LIBTUI.NewLBox
				rts
*--------------------------------------
CS.TLINE1.Init	>PUSHB hSCRN			hParent
				>PUSHBI 50				X1
				>PUSHBI 11				Y1
				>PUSHW L.LABEL.Label
				>PUSHBI 0
				>LIBCALL hLIBTUI,LIBTUI.NewLabel
				bcs .9
				
				>PUSHB hSCRN			hParent
				>PUSHBI 50				X1
				>PUSHBI 12				Y1
				>PUSHBI 25				W
				>PUSHEA.G TLINE.Buf
				>PUSHWI 65				Len
				>PUSHBI 0
				>LIBCALL hLIBTUI,LIBTUI.NewTLine
				
				>PUSHEA.G TLINE.Buf
				>PUSHW L.TLINE.Default
				>SYSCALL StrCpy
				
.9				rts				
*--------------------------------------
CS.CBOX1.Init	>PUSHB hSCRN			hParent
				>PUSHBI 50				X1
				>PUSHBI 14				Y1
				>PUSHBI	0
				>PUSHBI EV.CHECKBOX
				>PUSHW L.CBOX1.Label
				>PUSHEA.G CBOX1.Var
				>PUSHBI 0
				>LIBCALL hLIBTUI,LIBTUI.NewCBox
				rts
*--------------------------------------
CS.RADIO1.Init	>PUSHB hSCRN			hParent
				>PUSHBI 50				X1
				>PUSHBI 16				Y1
				>PUSHBI	0
				>PUSHBI EV.RADIO
				>PUSHW L.RADIO1.List
				>PUSHEA.G RADIO1.Var
				>PUSHBI 0
				>LIBCALL hLIBTUI,LIBTUI.NewRadio
				bcs .9
				
				sta hRADIO1
				
				>LIBCALL hLIBTUI,LIBTUI.Hide
				
.9				rts
*--------------------------------------
CS.BUT.Init		>PUSHB hSCRN			hParent
				>PUSHBI 50				X1
				>PUSHBI 20				Y1
				>PUSHBI	19				Ctrl-S
				>PUSHBI EV.SAVE
				>PUSHW L.BUTS.Label
				>PUSHBI 0
				>LIBCALL hLIBTUI,LIBTUI.NewBut
				bcs .9

				>PUSHB hSCRN			hParent
				>PUSHBI 65				X1
				>PUSHBI 20				Y1
				>PUSHBI	17				Ctrl-Q
				>PUSHBI EV.QUIT
				>PUSHW L.BUTQ.Label
				>PUSHBI 0
				>LIBCALL hLIBTUI,LIBTUI.NewBut
.9
CS.BUT.Init.RTS	rts
*--------------------------------------
CS.RUN.DLGSAVE	>PUSHB hCTX				hParent
				>PUSHBI 70				W
				>PUSHBI 11				H
				>PUSHW L.DLGSAVE.Title
				>PUSHBI 0
				>LIBCALL hLIBTUI,LIBTUI.NewDlg
				bcs CS.BUT.Init.RTS
				
				sta hDLGSAVE
				
				>PUSHA
*				>PUSHB hDLGSAVE			hParent
				>PUSHBI 50				X1
				>PUSHBI 7				Y1
				>PUSHBI	C.CR
				>PUSHBI EV.OK
				>PUSHW L.BUT.OK
				>PUSHBI 0
				>LIBCALL hLIBTUI,LIBTUI.NewBut
				bcs .9

				sta ZPPtr1

				>PUSHB hDLGSAVE			hParent
				>PUSHBI 57				X1
				>PUSHBI 7				Y1
				>PUSHBI	3				Ctrl-C
				>PUSHBI EV.CANCEL
				>PUSHW L.BUT.Cancel
				>PUSHBI 0
				>LIBCALL hLIBTUI,LIBTUI.NewBut
				bcs .9

				lda hDLGSAVE
				>LIBCALL hLIBTUI,LIBTUI.Draw
				bcs .9
				
				lda ZPPtr1
				>LIBCALL hLIBTUI,LIBTUI.Activate

.1				lda hDLGSAVE
				>LIBCALL hLIBTUI,LIBTUI.Exec
				
.9				php
				pha
				lda hDLGSAVE
				>LIBCALL hLIBTUI,LIBTUI.Destroy
				
				lda hSCRN
				>LIBCALL hLIBTUI,LIBTUI.Draw
				pla
				plp
				rts				
*--------------------------------------
CS.DOEVENT		sec						do not discard TIMER event
				rts
*--------------------------------------
CS.QUIT			>LDA.G TBOX1.hBuf
				beq .1

				>SYSCALL FreeMem

.1				lda hCTX
				beq .2
				
				>LIBCALL hLIBTUI,LIBTUI.Close
				
.2				lda hLIBTUI
				beq .8

				>SYSCALL UnloadLib

.8				clc
				rts
*--------------------------------------
CS.SCRN.Draw	lda hSCRN
				>SYSCALL GetMemPtr
				>STYA ZPPtr1

				>PUSHEA.G SCRN.TitleBuf
				>PUSHW L.SCRN.Title

				ldy #S.OBJ.X1

.1				lda (ZPPtr1),y
				>PUSHA
				iny
				cpy #S.OBJ.InnerH+1
				bne .1

				>PUSHBI 10
				>SYSCALL sprintf

				lda hSCRN
				>LIBCALL hLIBTUI,LIBTUI.Draw
				rts
*--------------------------------------
CS.END
*--------------------------------------
LIBTUI			.AZ "libtui"
hLIBTUI			.BS 1
*--------------------------------------
SCRN.Title		.AZ "Window: X1=%d,Y1=%d, W=%d,H=%d, X2=%d,Y2=%d, iX=%d,iY=%d, iW=%d,iH=%d"
*--------------------------------------
TBOX1.Title		.AZ "Text Box Title"
TBOX1.Status	.AZ "Text Box Status"
*--------------------------------------
LBOX1.List		.CZ "Item 1"
				.CZ "Item 2"
				.CZ "Item 3"
				.CZ "Item 4"
				.CZ "Item 5"
				.CZ "Item 6 very long line"
				.CZ "Item 7"
				.CZ "Item 8"
				.CZ "Item 9"
				.CZ "Item 10"
				.CZ "Item 11"
				.CZ "Item 12"
				.CZ "Item 13"
				.CZ "Item 14 last one"
				.HS 00
*--------------------------------------
LABEL.Label		.AZ "This is a label."
*--------------------------------------
TLINE.Default	.AZ "This is a Line."
*--------------------------------------
RADIO1.List		.CZ "\e[91mRed"
				.CZ "\e[92mGreen"
				.CZ "\e[96mBlue"
				.HS 00
*--------------------------------------
CBOX1.Label		.AZ "Check Me"
*--------------------------------------
BUTS.Label		.AZ "(^S)ave..."
BUTQ.Label		.AZ "(^Q)uit"
DLGSAVE.Title	.AZ "Save As..."
BUT.OK			.AZ " OK "
BUT.Cancel		.AZ "Cancel"
*--------------------------------------
				.DUMMY
				.OR 0
DS.START
SCRN.TitleBuf	.BS 80
TLINE.Buf		.BS 65
CBOX1.Var		.BS 1
RADIO1.Var		.BS 1
LBOX1.Var		.BS 2
TBOX1.hBuf		.BS 1
DS.END			.ED
*--------------------------------------
MAN
SAVE root/tuitest.s
ASM
