;**************************************************************************
;
; Filename : INIT.ASM
; -------------------
;
; (c) 1990 by Thomas Lehmann
;
;
; Jackophone V5.00
;
;
; Initialisierungs Routinen
;
;
;**************************************************************************


; =========================================================================
;
; Type	: Resetprg.
;
; Eingang	: bei Reset
;
; Ausgang	: Stackpointer initialisiert
;	: dezimal Mode ausgeschaltet
;
; Register	: 
;
; (c) by Thomas Lehmann Feb. 1990
;
; =========================================================================

init_stk	ldx #$ff	; Stackstart laden, Page1+x = $1ff
	txs		; Stackpointer initialisieren
	cld		; Prozessormodus einstellen


; =========================================================================
;
; Type	: Resetprg.
;
; Eingang	: bei Reset
;
; Ausgang	: RAM mit NULL initialisiert
;
; Register	: 
;
; (c) by Thomas Lehmann Feb. 1990
;
; =========================================================================

	lda #<INIT_START	; low Byte des Init RAM`s
	sta ind_adr	; setzen
	lda #>INIT_START	; high Byte des Init RAM`s
	sta ind_adr+1	; setzen
	ldx #<INIT_END	; low Byte RAM Ende
	ldy #>INIT_END	; dito high
	lda #$00	; Füllwert laden
	jsr fill_ram	; RAM füllen

; =========================================================================
;
; Type	: Resetprg.
;
; Eingang	: bei Reset
;
; Ausgang	: LED Matrix initialisiert
;	: akt. MB für Wähltastatur-Abfrage eingestellt
;
; Register	: 
;
; (c) by Thomas Lehmann Feb. 1990
;
; =========================================================================

	lda #$01
	sta blink_bit	; Bitzähler für LED ein/aus
	sta led_yl	; aktueller YL

	lda #<led_ram	; Startadresse des LED-RAM setzen
	sta led_po
	lda #>led_ram
	sta led_po+1
	lda #00		; Füllwert laden
	jsr fill_ledram	; LED-RAM initialisieren

	lda #MB4	; MB4 einstellen, set=0
	sta akt_mb	; aktueller MB für Wähltastaturabfrage

; =========================================================================
;
; Type	: Resetprg.
;
; Eingang	: bei Reset
;
; Ausgang	: VIA 6522 initialisiert
;
; Register	: 
;
; (c) by Thomas Lehmann Feb. 1990
;
; =========================================================================

	lda #$1f	; PB0-4=Ausgang, PB5-7=Eingang
	sta Via+2
	lda #%10001111	; PA0-3=Ausgang, PA4-7=Eingang, MB0-3, MA0-2
	sta Via+3
	stz Via		; Port A clear
	stz Via+1	; Port B clear
	lda #$ee	; %11101110
	sta Via+$0c

	lda #<IRQ_TIM1
	sta Via+4	; Timer1 low
	lda #>IRQ_TIM1
	sta Via+5	; Timer1 high

	lda #<IRQ_TIM2
	sta Via+8	; Timer2 low
	lda #>IRQ_TIM2
	sta Via+9	; Timer2 high
	lda #%11100010
	sta Via+$0e	; Interrupt Enable Register
	cli		; clear Interrupt Flag
			
; =========================================================================
;
; Type	: Resetprg.
;
; Eingang	: bei Reset
;
; Ausgang	: Display Initialisiert
;
; Register	: 
;
; (c) by Thomas Lehmann Feb. 1990
;
; =========================================================================

	jsr dp_busy	; Display für Befehl vorbereiten

	lda #$30	; D5=1
	sta Display	; DL=1 Datenbyte 8Bit
	jsr dp_busy	; N =0 obere Zeile
	sta Display
	jsr dp_busy
	sta Display

		 	; D4=1 verschieben
			; SC=1 Anzeige
		 	; SC=0 Cursor
		 	; RL=1 rechts
		 	; RL=0 links

	jsr dp_busy
	lda #$06	; D2=1 verschieben
	sta Display	; ID=1 Curs rechts 
			; S =1 Anzeige mit
	jsr dp_busy
	lda #12		;D3=1
	sta Display	; D =1 Anzeige ein
		 	; C =0 Cursor ein
			; B=0 Zeich blinkt
			; D1=1 Cursor Home
			; D0=1 CLR Disp




	jsr beantw_off	; Anrufbeantworter LED einschalten
	jmp main	; Start Hauptprg.

