
;	MIC	GFX_MODE=1
;	INP	GFX_MODE=2
;	CIN	GFX_MODE=3
;	HIP	GFX_MODE=4
;	TIP	GFX_MODE=5

GFX_MODE	= 5

* Main definitions
undo_buffer	equ $2800
undo_length	equ $0800

prog		equ $3000

prog_max	equ $5000

PM_base		equ $5000 ; memory for player data
KB_KEYTABLE	equ PM_BASE+$000 ; $100, for 63 keys
MENU_MENUTABLE	equ PM_BASE+$100	;$100, for ca 35 entries
zoom_lineadr	equ PM_BASE+$200 	;hi addr of zoom per line
MISS_base	equ PM_BASE+$300
PLR0_base	equ PM_BASE+$400

fontset		equ $5800
gr0_mem		equ $5c00	;ca 1000

module		equ $6000 ; module has memory $6000-$bfff and ROM if it wants

TESTMODE	equ 0 ; !0

* zero page
zer		equ $e0
zer0	equ $e2
zer1	equ $e4
zer2	equ $e6
zer3	equ $e8
zer4	equ $ea
zerHlp	equ $f0

	org prog
start
	jsr init
		ift TESTMODE
START_LINE	equ $20
		els
START_LINE	equ $70
		eif
loop
	jsr MOUSE.update
	lda #START_LINE
	cmp $d40b
	bcc *-3
	lda #START_LINE
	cmp $d40b
	bcs *-3

;	mva #$22 $d01a
	jsr zoom.zul_reset
	jsr cursor_clear
;	mva #$44 $d01a

	jsr KB.update
	jsr JOY.update
;	mva #$66 $d01a

	jsr cursor_update

;	mva #$aa $d01a

	jsr ZOOM.update

	jsr put_pixel_if_needed

	lda KB.pressed
	beq no_menu
	lda KB.key
	cmp #KEYCODE_ESC
	beq go_menu
	cmp #KEYCODE_TAB
	bne no_menu
go_menu
	jsr VBL.disable
	jsr MENU.enter
	jsr VBL.enable
no_menu

;	mva #$4c $d01a

	jsr zoom.zul_apply

;	mva #$00 $d01a

;	mva #$cc $d01a
	jmp loop

***********************************************************
* Puts pixel, but only if button has just been pressed or if
* it's still pressed and the cursor moved
put_pixel_if_needed .LOCAL
	ldx last_pressed
	lda cursor_pressed
	sta last_pressed
	beq dont_draw
	txa
	ldx cursor_X
	ldy cursor_Y
	cmp #0
	beq draw
	cpx last_X
	bne draw
	cpy last_Y
	beq dont_draw
draw
	stx last_X
	sty last_Y
	jsr MOD_put_pixel
	lda ZOOM.state
	beq dont_draw
	lda cursor_Y
	jsr zoom.zul_add ; max 1 line updated in zoom
dont_draw
	rts
	
last_pressed	dta 0
last_X			dta 0
last_Y			dta 0
	.ENDL  ; put_pixel_if_new

*******************************************************************************
* Initializes everything
init	equ *
;	sei
;	inc $d40e
	lda $d40b
	bne *-3
	sta $d400
;	sta $d40e

	jsr FONT.init
	jsr ZOOM.init
	jsr MENU.init
	jsr dl.init
	jsr cursor_init
	jsr KB.init
	jsr MOUSE.init
	jsr UNDO.init

	jsr mod_init

	lda $d40b
	bne *-3

	jsr DLI.init
	jsr VBL.init
;	mva #$c0 $d40e	; switch on all interrupts
;	mva $22f $d400
	lda $d40b
	bne *-3
	mva $22f $d400
		ift TESTMODE
	mva #$40 $d40e
		els
	mva #$c0 $d40e
		eif


	rts

*******************************************************************************
	icl 'atari.asx'
* Included libraries
	icl 'font.asx'
	icl 'dl.asx'
	icl 'dli.asx'
	icl 'vbl.asx'
	icl 'cursor.asx'
	icl 'utils.asx'
	icl 'joy.asx'
	icl 'mouse.asx'
	icl 'keyboard.asx'
	icl 'zoom.asx'
	icl 'io.asx'
	icl 'menu.asx'
	icl 'undo.asx'
	
INCLUDE_PICTURE	equ 0

		ift !GFX_MODE
;GFX_MODE	equ 1	; MIC
;GFX_MODE	equ 2	; INP
;GFX_MODE	equ 3	; CIN
;GFX_MODE	equ 4	; HIP
GFX_MODE	equ 5	; TIP
		eif
		
		ift GFX_MODE=1
	icl 'mod_mic.asx'
		eli GFX_MODE=2
	icl 'mod_inp.asx'
		eli GFX_MODE=3
	icl 'mod_cin.asx'
		eli GFX_MODE=4
	icl 'mod_hip.asx'
		eli GFX_MODE=5
	icl 'mod_tip.asx'
		els
	.PRINT 'Unspecified mode'
	ert 1;
		eif

*******************************************************************************
main_vbl
	rts
*******************************************************************************
	.PRINT 'End: '
	.PRINT *
	ert [*>prog_max]

	run start
;	INI start
