#dontinclude
; canceled project

; coco main
	opt	forwardrefmax
#include	coco\main_lib.txt
#include	coco\disk_lib.txt
#include	coco\cg3_display.txt
#include	coco\sidchip.txt
#include	coco\joystick_lib.txt

#memstart	28672	;$7500


	org	$3500	;mem start?
start
	lds	#$900	;move stack into dsk area


;set channels to all pulse width

	lda	#0
	sta	edit_chan1
	sta	edit_chan2
	sta	edit_chan3

;	sta	$ffdf	;ram/rom return ffdf =ramram no basic more memory

	disk_buffer()
	std	diskbuffer
	disk_granuals()
	std	diskgran
	disk_loadm(#0,#filename,#$6000,diskbuffer,diskgran)	;music


;	disk_loadm(#0,#filename3,#0,diskbuffer,diskgran)	;use header for load placement sprites
;	disk_savem(#0,#0,#filename3,#sprite_layer,#sprite_layer_end,diskbuffer,diskgran)	;save sprites
	disk_loadm(#0,#filename3,#9755,diskbuffer,diskgran)	;use header for load placement sprites

	disk_loadm(#0,#filename1,#3579,diskbuffer,diskgran)	;use header for load placement bg staff
	disk_loadm(#0,#filename1,#0,diskbuffer,diskgran)	;use header for load placement bg staff

;	disk_savem(#0,#1,#filename2,#$6000,#$6ad4,diskbuffer,diskgran)	;create a copy

	sid_chip(#0)	;mux off use ext line
	sid_setchannel1(#%01000001)
	sid_setchannel2(#%00110001)
	sid_setchannel3(#%01010001)

	sid_setmodevol(#%00001111)
	sid_setresfilter(#%11110000)

	sid_playmusic(#$6000,#2,#1)


	
	cg3_setdisplay(#1)

	lda	#114
	sta	xsid_tile
	lda	#1
	sta	edit_track
	sta	edit_page
	clr	click


	bytestring(edit_track,#myword)
	cg3_print(#0,#96,#1,#myword,#1,#2)
	cg3_print(#1,#96,#1,#myword,#1,#2)	;both pages

	bytestring(edit_page,#myword)
	cg3_print(#0,#0,#88,#myword,#1,#2)
	cg3_print(#1,#0,#88,#myword,#1,#2)	;both pages

; clear mouse sprite
	ldx	#mouse_bg
	clr	0,x
	clr	1,x
	clr	2,x
	ldx	#mouse_bg2
	clr	0,x
	clr	1,x
	clr	2,x



	lda	#112
	sta	mouse_tile
	clr	mouse_tilec
	cg3_sprite1(#0,xsid_tile,#20,#0,#5,#1)


	jsr	set_mychannel1

doloop

	keystring(#0)
	stb	mybyte


	inc	xsid_tilec
	if	b,xsid_tilec>#10

	inc	mouse_tile

	if	b,mouse_tile>#113
	lda	#112
	sta	mouse_tile
	endif

	clr	xsid_tilec
	lda	xsid_tile
	adda	#5
	sta	xsid_tile
	if	b,xsid_tile=>#144
	lda	#114
	sta	xsid_tile
	endif
	cg3_sprite1(#1,xsid_tile,#20,#0,#5,#1)
	endif


;play sfx try
	if	b,mybyte=#32
	sid_playmusicsfx(#sfxtry1)
	endif

	joystick()
	ldb	$15d
	stb	mouse_click

	ldx	#mousex_table
	ldb	$15b
	abx
	lda	0,x
	sta	mousepos_x
	ldx	#mousey_table
	ldb	$15a
	abx
	lda	0,x
	sta	mousepos_y


	jsr	qmidi_checkpage


	cg3_sprite(#1,#mouse_bg,mouse_tile,mousepos_x,mousepos_y,#1,#1,#0)



	cg3_nosync(#1)



	lbra	doloop


mousey_table	fcb	0,0,1,2,3,4,5,6,7,8,9,10,11,13,14,16,17,19,20,22,23,25,26
		fcb	28,29,31,32,34,35,37,38,44,44,47,48,50,51,53,54,56
		fcb	57,59,60,62,63,65,66,68,69,71,72,74,75,77,77,80
		fcb	82,83,84,85,86,87,88,88

mousex_table	fcb	0,1,2,3,4,5,6,6,7,7,8,8,9,9,10,10,15,18,21,24,27,30,33,36,39,42,45,48
		fcb	51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96
		fcb	99,102,105,108,111,110,110,112,112,113,113,114,114,115,115,116
		fcb	117,118,120,122

filename	fcn	'TEST    MDM'
filename1	fcn	'XSID    BIN'
filename2	fcn	'TEST1   MDM'
filename3	fcn	'XSIDSPR BIN'

filename4	fcn	'ABCDEFGHIJKLMNOP'

def	edit_track	byte
def	edit_page	byte
; what instrument selection?
def	edit_chan1	byte
def	edit_chan2	byte
def	edit_chan3	byte




def	xsid_tile	byte
def	xsid_tilec	byte

def	mouse_tile	byte
def	mouse_tilec	byte
def	mousepos_x	byte
def	mousepos_y	byte

def	temp	byte

def	myword	string	8
def	click	byte

def	diskbuffer	word
def	diskgran	word

def	sinetable	word

def	mybyte	byte
def	ctrbyte	byte

def	mouse_click	byte

def	mouse_bg	string	3	;uses full bg layer
def	mouse_bg2	string	3	;uses full bg layer

; o=octave   0-7
; v=volume 0-f
; m=mode 0-f  is the gate function
; t=type of sound 0-f
; p=pause 0-f
; s=speed 0-f
; r=release rate 0-f
; a b c d e f g notes



sfxtry2	fcc	'm1t2rds9o7vfa veb vdc v9a b c#c p0a b c m5t1s9o5a b c d e f g '


	fcb	0,0



sfxtry1	fcc	'vfm1t3o3s3rdc d e f g a b t4a c d e d e p0'
	fcc	'vfm1t3o4s2rdc d e f g a b t4a c d e d e p0'
	fcc	'vfm1t3o5s1rdc d e f g a b t4a c d e d e p0'
	fcc	'vfm1t3o6s0rdc d e f g a b t4a c d e d e p0'


	fcb	0,0


mtout	fcn	`   `




sprite_layer



sprite_layer_end








qmidi_checkpage


	if	x,#1!mouse_click
	lda	#1
	sta	click
	endif


; channel 1,2,3 edit buttons
;***********************************************************************************************************************************************************************************
	if	b,click=#1	x,#1=mouse_click	b,mousepos_x>#118	b,mousepos_y<#6
	clr	click
	inc	edit_track
	if	b,edit_track>#3
	lda	#3
	sta	edit_track
	endif
	bytestring(edit_track,#myword)
	cg3_print(#0,#96,#1,#myword,#1,#2)
	cg3_print(#1,#96,#1,#myword,#1,#2)	;both pages
	jsr	what_channel
	endif
	if	b,click=#1	x,#1=mouse_click	b,mousepos_x<#118	b,mousepos_x>#111	b,mousepos_y<#6
	clr	click
	dec	edit_track
	if	b,edit_track<#1
	lda	#1
	sta	edit_track
	endif
	bytestring(edit_track,#myword)
	cg3_print(#0,#96,#1,#myword,#1,#2)
	cg3_print(#1,#96,#1,#myword,#1,#2)	;both pages
	jsr	what_channel
	endif
;noise type
;*************************************************************************************************************************************************************************************
	if	b,click=#1	x,#1=mouse_click	b,mousepos_x=>#87	b,mousepos_x=<#93	b,mousepos_y<#6
	clr	click

	if	b,edit_track=#1
	lda	edit_chan1
	adda	#128
	anda	#128
	sta	temp
	lda	edit_chan1
	anda	#112
	adda	temp
	sta	edit_chan1
	jsr	set_mychannel1
	endif

	if	b,edit_track=#2
	lda	edit_chan2
	adda	#128
	anda	#128
	sta	temp
	lda	edit_chan2
	anda	#112
	adda	temp
	sta	edit_chan2
	jsr	set_mychannel2
	endif

	if	b,edit_track=#3
	lda	edit_chan3
	adda	#128
	anda	#128
	sta	temp
	lda	edit_chan3
	anda	#112
	adda	temp
	sta	edit_chan3
	jsr	set_mychannel3
	endif

	endif

;triangle type
;*************************************************************************************************************************************************************************************
	if	b,click=#1	x,#1=mouse_click	b,mousepos_x=>#81	b,mousepos_x=<#84	b,mousepos_y<#6
	clr	click

	if	b,edit_track=#1
	lda	edit_chan1
	adda	#16
	anda	#16
	sta	temp
	lda	edit_chan1
	anda	#224
	adda	temp
	sta	edit_chan1
	jsr	set_mychannel1
	endif

	if	b,edit_track=#2
	lda	edit_chan2
	adda	#16
	anda	#16
	sta	temp
	lda	edit_chan2
	anda	#224
	adda	temp
	sta	edit_chan2
	jsr	set_mychannel2
	endif

	if	b,edit_track=#3
	lda	edit_chan3
	adda	#16
	anda	#16
	sta	temp
	lda	edit_chan3
	anda	#224
	adda	temp
	sta	edit_chan3
	jsr	set_mychannel3
	endif

	endif



;saw type
;*************************************************************************************************************************************************************************************
	if	b,click=#1	x,#1=mouse_click	b,mousepos_x=>#72	b,mousepos_x=<#78	b,mousepos_y<#6
	clr	click

	if	b,edit_track=#1
	lda	edit_chan1
	adda	#32
	anda	#32
	sta	temp
	lda	edit_chan1
	anda	#208
	adda	temp
	sta	edit_chan1
	jsr	set_mychannel1
	endif

	if	b,edit_track=#2
	lda	edit_chan2
	adda	#32
	anda	#32
	sta	temp
	lda	edit_chan2
	anda	#208
	adda	temp
	sta	edit_chan2
	jsr	set_mychannel2
	endif

	if	b,edit_track=#3
	lda	edit_chan3
	adda	#32
	anda	#32
	sta	temp
	lda	edit_chan3
	anda	#208
	adda	temp
	sta	edit_chan3
	jsr	set_mychannel3
	endif

	endif



;pulse type
;*************************************************************************************************************************************************************************************
	if	b,click=#1	x,#1=mouse_click	b,mousepos_x=>#63	b,mousepos_x=<#69	b,mousepos_y<#6
	clr	click

	if	b,edit_track=#1
	lda	edit_chan1
	adda	#64
	anda	#64
	sta	temp
	lda	edit_chan1
	anda	#176
	adda	temp
	sta	edit_chan1
	jsr	set_mychannel1
	endif

	if	b,edit_track=#2
	lda	edit_chan2
	adda	#64
	anda	#64
	sta	temp
	lda	edit_chan2
	anda	#176
	adda	temp
	sta	edit_chan2
	jsr	set_mychannel2
	endif

	if	b,edit_track=#3
	lda	edit_chan3
	adda	#64
	anda	#64
	sta	temp
	lda	edit_chan3
	anda	#176
	adda	temp
	sta	edit_chan3
	jsr	set_mychannel3
	endif

	endif



;no clicks found
	if	b,click=#1	x,#1=mouse_click
	clr	click
	endif


	rts

what_channel
	lda	edit_track
	cmpa	#1
	lbeq	set_mychannel1
	cmpa	#2
	lbeq	set_mychannel2
	lbra	set_mychannel3


;********************************************************************************************************
set_mychannel1
;pulse width
	if	x,#64=edit_chan1
	cg3_sprite1(#0,#86,#64,#0,#1,#1)
	cg3_sprite1(#1,#86,#64,#0,#1,#1)
	else
	cg3_sprite1(#0,#82,#64,#0,#1,#1)
	cg3_sprite1(#1,#82,#64,#0,#1,#1)
	endif
;sawtooth
	if	x,#32=edit_chan1
	cg3_sprite1(#0,#87,#72,#0,#1,#1)
	cg3_sprite1(#1,#87,#72,#0,#1,#1)
	else
	cg3_sprite1(#0,#83,#72,#0,#1,#1)
	cg3_sprite1(#1,#83,#72,#0,#1,#1)
	endif
;triangle
	if	x,#16=edit_chan1
	cg3_sprite1(#0,#88,#80,#0,#1,#1)
	cg3_sprite1(#1,#88,#80,#0,#1,#1)
	else
	cg3_sprite1(#0,#84,#80,#0,#1,#1)
	cg3_sprite1(#1,#84,#80,#0,#1,#1)
	endif
;noise
	if	x,#128=edit_chan1
	cg3_sprite1(#0,#89,#88,#0,#1,#1)
	cg3_sprite1(#1,#89,#88,#0,#1,#1)
	else
	cg3_sprite1(#0,#85,#88,#0,#1,#1)
	cg3_sprite1(#1,#85,#88,#0,#1,#1)
	endif


	rts


;********************************************************************************************************
set_mychannel2
;pulse width
	if	x,#64=edit_chan2
	cg3_sprite1(#0,#86,#64,#0,#1,#1)
	cg3_sprite1(#1,#86,#64,#0,#1,#1)
	else
	cg3_sprite1(#0,#82,#64,#0,#1,#1)
	cg3_sprite1(#1,#82,#64,#0,#1,#1)
	endif
;sawtooth
	if	x,#32=edit_chan2
	cg3_sprite1(#0,#87,#72,#0,#1,#1)
	cg3_sprite1(#1,#87,#72,#0,#1,#1)
	else
	cg3_sprite1(#0,#83,#72,#0,#1,#1)
	cg3_sprite1(#1,#83,#72,#0,#1,#1)
	endif
;triangle
	if	x,#16=edit_chan2
	cg3_sprite1(#0,#88,#80,#0,#1,#1)
	cg3_sprite1(#1,#88,#80,#0,#1,#1)
	else
	cg3_sprite1(#0,#84,#80,#0,#1,#1)
	cg3_sprite1(#1,#84,#80,#0,#1,#1)
	endif
;noise
	if	x,#128=edit_chan2
	cg3_sprite1(#0,#89,#88,#0,#1,#1)
	cg3_sprite1(#1,#89,#88,#0,#1,#1)
	else
	cg3_sprite1(#0,#85,#88,#0,#1,#1)
	cg3_sprite1(#1,#85,#88,#0,#1,#1)
	endif


	rts

;********************************************************************************************************
set_mychannel3
;pulse width
	if	x,#64=edit_chan3
	cg3_sprite1(#0,#86,#64,#0,#1,#1)
	cg3_sprite1(#1,#86,#64,#0,#1,#1)
	else
	cg3_sprite1(#0,#82,#64,#0,#1,#1)
	cg3_sprite1(#1,#82,#64,#0,#1,#1)
	endif
;sawtooth
	if	x,#32=edit_chan3
	cg3_sprite1(#0,#87,#72,#0,#1,#1)
	cg3_sprite1(#1,#87,#72,#0,#1,#1)
	else
	cg3_sprite1(#0,#83,#72,#0,#1,#1)
	cg3_sprite1(#1,#83,#72,#0,#1,#1)
	endif
;triangle
	if	x,#16=edit_chan3
	cg3_sprite1(#0,#88,#80,#0,#1,#1)
	cg3_sprite1(#1,#88,#80,#0,#1,#1)
	else
	cg3_sprite1(#0,#84,#80,#0,#1,#1)
	cg3_sprite1(#1,#84,#80,#0,#1,#1)
	endif
;noise
	if	x,#128=edit_chan3
	cg3_sprite1(#0,#89,#88,#0,#1,#1)
	cg3_sprite1(#1,#89,#88,#0,#1,#1)
	else
	cg3_sprite1(#0,#85,#88,#0,#1,#1)
	cg3_sprite1(#1,#85,#88,#0,#1,#1)
	endif


	rts




; end of program
cocoromend



	end	start



