#include "p16F690.inc"

	__CONFIG _FOSC_INTRCIO & _MCLRE_OFF &_WDTE_OFF & _PWRTE_OFF & _BOREN_OFF & _CPD_OFF & _CP_OFF & _IESO_OFF & _FCMEN_OFF
    
    errorlevel    -302    


;******************************************************************
;****************** P R O M E N N E *******************************
;******************************************************************
    
    cblock 0x20
	EXP_READ1		;ocekavam log.1 - uvodni rising edge
	EXP_BOUNCE1		;ocekavam log.1 - test na debounce
	EXP_RELESE0		;ocekavam log.0 - uvolneni tlacitka
	button1_stat	;aktualni stav (0/1) buttonu1 v preruseni
	button2_stat	;aktualni stav (0/1) buttonu2 v preruseni
	b1_exp_stat		;0/1/2 - v jakem stavu se nachazi port buttonu1
	b2_exp_stat		;0/1/2 - v jakem stavu se nachazi port buttonu2
	check			;true/false - muze se vyhodnotit stav tlacitek
	w_temp
	status_temp
	pclath_temp
	del1			;registry pro cekaci subrutiny
	del2
	del3
	hiByte
	loByte
	tmp
	i2c_tmp			;writeByte
	i2c_i			;writeByte	
	base  			;drawTimer			
	tmpByte
	nonZeroByte
	numSecs
	numMilis
	index
	rnd					
	i
	j				;LCD_draw_*
	X				;X - aktualni pozice cislice skore
	X_copy
	Y				;Y - aktualni pozice cislice skore
	player1_score
	player2_score
	pressed			;Kdo stiskl - 0-nikdo, 1-player2, 2-player1, 3-oba
	diff_score
	X_indicator		;Pozice aktualniho sloupce - indikator
	ind_value		;data sloupce indikatoru
	save			;indikator tmp
	tens			;desitky - bin2ascii
	ones			;jednotky - bin2ascii
	number			;vypisovana cislice
	timer			;hra trva 15secs
	timerON			;odpocet bezi
	gameOver		;mame odpocet na 0, konec hry?
	intr_counter	;interrupt counter - cteni portu kazdych 10ms
	intr_copy		;kopie interrupt counteru
	timer1_counter	;sekundove odpocitavani
	timer1_copy
	portb_save		;nacteni stavu buttonu
	winner			;0-player1, 1-player2
	numSound		;cislo zvuku z WT588D
	textPointer:2	;Ukazatel do textu
	fontPointer:2	;Ukazatel do dat fontu
	toggler			;0<->1 prepinac
    endc

;******************************************************************
;****************** K O N S T A N T Y *****************************
;******************************************************************

FALSE				equ 0x00
TRUE				equ 0x01

;LCD NOKIA 5110
FONT_D_W			equ .18
FONT_D_H			equ .4
FONT_D_CHARSIZE		equ FONT_D_W*FONT_D_H

FONT_S_W			equ .5
FONT_S_H			equ .1
FONT_S_CHARSIZE		equ FONT_S_W*FONT_S_H

SPLASH_W			equ .84 ;px uvodni obrazovka
SPLASH_H			equ .4	;4*8px uvodni obrazovka

INDICATOR_Y_POS		equ .5

LCD_BYTES			equ .504 ;(84 x 6 = 84 x 48px)

GAME_SECS			equ .15	 ;Delka hry v sekundach

NUM_INTRS_TMR0		equ .40  ;40x128us = 5ms delay mezi ctenimi stavu BUTTONU (Timer0)
NUM_INTRS_TMR1		equ .31  ;30 preruseni po 32768us + 1 preruseni 16960us

;WT588D
SOUND_00_321		equ .0
SOUND_01_0			equ .1
SOUND_02_INGAME1	equ .2
SOUND_03_INGAME2	equ .3
SOUND_04_INGAME3	equ .4
SOUND_05_GAME_OVER	equ .5
SOUND_06_WINNER_IS	equ .6
SOUND_07_PLAYER1	equ .7
SOUND_08_PLAYER2	equ .8
SOUND_09_APPLAUSE	equ .9
SOUND_0A_INTRO		equ .10

;******************************************************************
;****************** D E F I N I C E *******************************
;******************************************************************
   
;Buttons
#define	B_BUTTON1	PORTB, RB5;
#define B_BUTTON2	PORTB, RB6;

;Nokia 3410 LCD display SPI
#define LCD_RESET	PORTC, RC3;
#define LCD_SCLK	PORTC, RC4;
#define LCD_SDIN	PORTC, RC5;
#define LCD_DC		PORTC, RC6;

#define BIT_BUTTON1	RB5	;bit pro BUTTON1
#define BIT_BUTTON2	RB6	;bit pro BUTTON2

;WT588D   
#define S_SCK		PORTA, RA0;
#define S_CS		PORTA, RA1;
#define S_SDA		PORTA, RA2;
;******************************************************************
;****************** M A K R A *************************************
;******************************************************************
 
BANK0 macro
    bcf STATUS, RP0 ;Select memory bank 0
    bcf STATUS, RP1 
    endm
    
BANK1 macro
    bsf STATUS, RP0 ;Select memory bank 1
    bcf STATUS, RP1 
    endm   
    
BANK2 macro
    bcf STATUS, RP0 ;Select memory bank 2
    bsf STATUS, RP1 
    endm   
    
BANK3 macro
    bsf STATUS, RP0 ;Select memory bank 3
    bsf STATUS, RP1 
    endm           
    
;******************************************************************    
;*************************** S T A R T ****************************
;******************************************************************
    
	org 0x00
    goto main
	
; ******************************************************************
; *********************** I N T E R R U P T ************************
; ******************************************************************
	org 0x04
interrupt
	movwf w_temp 		;copy W to temp register, could be in either bank
	swapf STATUS,w 		;swap status to be saved into W	
	movwf status_temp 	;save status to bank 0 register
    movf  PCLATH,w      ; move pclath register into w register
    movwf pclath_temp   ; save off contents of PCLATH register
	
	clrf PCLATH

checkTMR0
	btfss INTCON, T0IF	;TMR0 interrupt?
	goto checkTMR1
	bcf INTCON, T0IF    ;vycisti TMR0 Interrupt flag
	decfsz intr_counter, f
	goto checkTMR1	
	movf intr_copy, w
	movwf intr_counter
	movf PORTB, w
	movwf portb_save
	movlw TRUE
	movwf check			;muzeme vyhodnotit stav buttonu
checkTMR1
	btfss PIR1, TMR1IF	;TMR1 interrupt = timer (1secs)
	goto skip
	bcf PIR1, TMR1IF	;vycisti TMR1 Interrupt flag
	decfsz timer1_counter, f
	goto skip

    movf timer, f        ;mame konec odpoctu?
    btfss STATUS, Z        
    goto timerNotZero
    movlw TRUE
    movwf gameOver        ;KONEC HRY
    goto TMR1common    
timerNotZero
    decf timer, f        

TMR1common
	call initTimer1		;Nastav hodnoty pro 1sec
	movf timer1_copy, w
	movwf timer1_counter			
skip
    movf  pclath_temp,w ;retrieve copy of PCLATH register
    movwf PCLATH        ;restore pre-isr PCLATH register contents
	swapf status_temp,w	;swap status_temp register into W, sets bank to original state
	movwf STATUS 		;move W into STATUS register
	swapf w_temp,f 		;swap w_temp
	swapf w_temp,w 		;swap w_temp into W	
	retfie

; ******************************************************************
; ************************** M A I N *******************************
; ******************************************************************

main
	clrwdt
	nop

	BANK1
	movlw b'01110100'
	movwf OSCCON		;8MHZ internal
	movlw b'11001000'
	movwf OPTION_REG

	;*** PORTA NASTAVENI - WT588D ***
	BANK1	
	;RA0,1,2 - WT588D
	clrf TRISA

	BANK2
	clrf ANSEL
	clrf ANSELH
	clrf CM1CON0
	clrf CM2CON0

	BANK0 		
	clrf PORTA

	;*** PORTB NASTAVENI - BUTTONY ***
	
	BANK1
	movlw b'01100000'	;RB5, RB6 tlacitka
	movwf TRISB	
	BANK0
	clrf PORTB   
	clrf CCP1CON 		; Turn CCP module off

	;Inicializace Timer0
	clrf INTCON	

	;*** PORTC NASTAVENI - Nokia LCD 3410 ***
	
	BANK1
	clrf TRISC
	
	BANK0
	clrf PORTC
	clrf SSPCON  		; Vypnout MSSP module

	;Nastav SCK a CS na log. 1
	bsf S_SCK			;Pro WT588D
	bsf S_CS
		
;*******************************************************************
;******************* M A I N   L O O P *****************************
;*******************************************************************

	call LCD_init

_START_GAME

	call LCD_clear

	call disableInterrupts

	call LCD_drawSplashScreen

	;call showInfo

	call playIntroSound

	call waitForKeyIntro

	call LCD_clear
	
	call drawCountdown

	call LCD_clear

	call initScore

	call initGameTimer

	call drawScoreDivider

	call initButtonVars

	call playIngameSound

	call enableInterrupts

_GAME_LOOP	

	btfsc gameOver, 0
	goto _GAME_OVER
	
	call evalButtons

	call drawScore
	
	call drawTimer

	goto _GAME_LOOP
	
_GAME_OVER

	call showGameOver

	call playGameOverSound

	call evaluateWinner

	movf winner, f
	btfss STATUS, Z
	goto weHaveWinner

	call showNoWinner

	call waitForKey

	goto _GAME_NEXT

weHaveWinner
	call showWinner

	call playWinnerSound

	call waitForKeyOutro

_GAME_NEXT
	
	movlw .10
	call waitMilis
	
_GAME_PRESSED

	;Pockej, az neni stisknuty zadny button
	btfsc B_BUTTON1
	goto _GAME_PRESSED
	btfsc B_BUTTON2
	goto _GAME_PRESSED	

	goto _START_GAME

;*******************************************************************
;******************* VYHODNOCENI STAVU TLACITEK ********************
;*******************************************************************

initButtonVars

	clrf check

	;Stisk buttonu = log.1-stisk,log.1 po 10ms-debounce test,log.0-uvolneni
	movlw .1	
	movwf EXP_READ1			;log.1 - stav 0
	movwf EXP_BOUNCE1		;log.1 - stav 1
	clrf  EXP_RELESE0		;log.0 - stav 2
	
	clrf button1_stat
	clrf button2_stat

	clrf b1_exp_stat
	clrf b2_exp_stat
	return

;Zjisti, jestli probehl u nektereho z tlacitek kompletni stisk
evalButtons
	
	clrf pressed			
	btfss check, 0			;pokracuj, pokud preruseni naplnilo porta_save
	return
	
	clrf check				;pro dalsi cyklus

	;BUTTON1
	bsf button1_stat, 0				;button1 - aktualni stav na portu dej na log1
	btfss portb_save, BIT_BUTTON1	;mame log1?
	bcf button1_stat, 0				;ne, mame log0
	;Ted zjisti jakou hodnotu ocekavam
	movlw 0x20						;pocatek promennych EXP_
	addwf b1_exp_stat, w
	movwf FSR
	movf INDF, w					;ziskej ocekavanou hodnotu pro dany stav
	xorwf button1_stat, w
	btfss STATUS, Z			 ;expected == actual?
	goto b1Unexpected		 ;neshoda
	;Mame shodu - zjisti, jestli uz mame cely stisk za sebou 
	btfss b1_exp_stat, 1	;b1_exp_stat == 2?
	goto b1NextExpState		;ne, posun se na dalsi stav
	clrf b1_exp_stat		;reset stavu, zaciname odznovu, cekej na dalsi stisk
	bsf pressed, 1			;mame stisk buttonu hrace1
	goto evalButton2
b1NextExpState	
	incf b1_exp_stat, f		;dalsi stav
	goto evalButton2
b1Unexpected				;aktualni stav je ruzny od ocekavaneho, resim jen stav b1_exp_stat == 1
	btfss b1_exp_stat, 0	;pokud jsme na stavu 1 a mam neshodu, je nutno zacit od znovu
	goto evalButton2
	clrf b1_exp_stat		;cekame na uvodni log.1 stisku	
evalButton2
	;BUTTON2
	bsf button2_stat, 0				;button1 - aktualni stav na portu
	btfss portb_save, BIT_BUTTON2	;mame log1
	bcf button2_stat, 0				;mame log0
	;Ted zjisti jakou hodnotu ocekavam
	movlw 0x20						;pocatek promennych EXP_
	addwf b2_exp_stat, w
	movwf FSR
	movf INDF, w
	xorwf button2_stat, w
	btfss STATUS, Z			 ;expected == actual?
	goto b2Unexpected		 ;neshoda
	;Mame shodu - zjisti, jestli uz mame cely stisk za sebou (b2_exp_stat == 2)
	btfss b2_exp_stat, 1
	goto b2NextExpState
	clrf b2_exp_stat		;reset stavu, cekej na dalsi stisk
	bsf pressed, 0			;mame stisk buttonu 2
	return
b2Unexpected				;aktualni stav je ruzny od ocekavaneho, resim jen stav b1_exp_stat == 1
	btfss b2_exp_stat, 0	;pokud jsme na 1 a mam neshodu, je nutno zacit od znovu
	return
	clrf b2_exp_stat		;cekame na uvodni log.1 stisku 	
	return	
b2NextExpState	
	incf b2_exp_stat, f	
	return
	
;*******************************************************************
;******************* WT588D - prehravani zvuku cislo numSound ******
;*******************************************************************	

playIntroSound
	movlw SOUND_0A_INTRO
	call doSoundFX
	return
	
;Prehrej nahodne jeden ze 3 zvuku _INGAME{1,2,3}
playIngameSound
	movlw SOUND_03_INGAME2
	goto inGamePlay
	

	movlw SOUND_04_INGAME3
	btfsc rnd, 0
	goto inGamePlay
	movlw SOUND_03_INGAME2
	btfsc rnd, 1
	goto inGamePlay
	movlw SOUND_02_INGAME1
inGamePlay
	call doSoundFX
	movlw .10
	call waitMilis
	return
	
setLoopSound
	movlw 0xF2			;loop aktualne prehravaneho zvuku
	call doSoundFX
	return

playGameOverSound
	movlw SOUND_05_GAME_OVER
	call doSoundFX
	movlw .2
	call waitSecs
	return

;Prehrej Winner is .... player{1,2}
playWinnerSound
	movf winner, f			;0-remiza, nic neprehravej, jen pockej 3s
	btfsc STATUS, Z
	return

	movlw SOUND_06_WINNER_IS
	call doSoundFX
	movlw .2
	call waitSecs

	movlw SOUND_07_PLAYER1
	btfss winner, 0
	movlw SOUND_08_PLAYER2
	call doSoundFX
	movlw .2
	call waitSecs

	;aplaus
	movlw SOUND_09_APPLAUSE
	call doSoundFX
	return

doSoundFX
		movwf tmp

		bsf S_SCK
		nop
		bsf S_CS
		nop	
		
		movlw .17
		call waitMilis				

		bcf	S_CS		;Slave Select = LOW (Initiating transmission)

		movlw .2
		call waitMilis

		;Ted projdu postupne bit 0, bit 1, bit 2, bit 3 a nastavuju podle toho log 1 nebo log 0

		movlw .8
		movwf i
		
cycle	bcf S_SCK		;Clock na log. 0, zaciname prenos data			

		btfss tmp, 0;  bit 0 nastaven?
		goto btNotSet
		bsf S_SDA		 ; ano, posli log 1
		goto tsted
btNotSet bcf S_SDA		; ne, posli log 0 na vystup
tsted	call wait30us

		bsf S_SCK		;Clock na log. 1, skoncili jsme prenos 1 bitu	
		call wait30us

		rrf tmp, f
		decfsz i, f
		goto cycle
		
		bsf S_CS		;Slave Select = HI

		return


;*******************************************************************
;******************* ZAPINANI/VYPINANI TIMERU1 pro odpocet *********
;*******************************************************************	
	
; *** START TIMER1
startTimer1

	BANK1
	bsf PIE1, TMR1IE
	BANK0
	
	movlw NUM_INTRS_TMR1
	movwf timer1_counter
	movwf timer1_copy
		
	call initTimer1

	bsf INTCON, PEIE		;Peripheral interrupt pro Timer1	

	BANK0
	movlw b'00000101'		;Prescaler 1:1, internal, Timer1 ON
	movwf T1CON

	movlw TRUE
	movwf timerON
	return
	
; *** STOP TIMER1
stopTimer1

	movlw b'00000100'		;Prescaler 1:1, internal, Timer1 OFF
	movwf T1CON
	
	movlw FALSE
	movwf timerON

	bcf INTCON, PEIE		;Peripheral interrupt pro Timer1 - OFF

	BANK1
	bcf PIE1, TMR1IE
	BANK0
	return


; *** INIT TIMER1 - nastav na 48576
initTimer1
	movlw 0x7B
	movwf TMR1H
	movlw 0x80
	movwf TMR1L
	return	
	
;*******************************************************************
;******************* ZAPINANI/VYPINANI PRERUSENI *******************
;*******************************************************************

disableInterrupts

	movf TMR0, w
	movwf rnd

	call stopTimer1			;Zakaz Timer1 preruseni
	bcf INTCON, T0IE    	;Zakaz Timer0 interrupt
	bcf INTCON, GIE	    	;Zakaz vsechna preruseni
	clrf TMR0
	clrf T2CON				;Nepouzivej Timer2
	BANK1
	bcf PIE1, TMR2IE
	BANK0
	return

enableInterrupts

	call startTimer1		;Povol Timer1 preruseni - odpocet
	clrf TMR0
	movlw NUM_INTRS_TMR0
	movwf intr_counter		;40 * 256us = 10240us =~ 10ms
	movwf intr_copy
	bsf INTCON, T0IE    	;Povol Timer0 interrupt
	bsf INTCON, GIE	    	;Povol vsechna preruseni
	return

;*******************************************************************
;******************* H E R N I  R U T I N Y ************************
;*******************************************************************

;Pri prehravani aplauzu (11secs) muzem znovu na start
waitForKeyOutro
		movlw HIGH .1100
		movwf hiByte
		movlw LOW .1100
		movwf loByte

waitKO1	call checkKeys
		iorlw 0x00
		btfsc STATUS, Z		;byl nejaky stisk?
		goto waitKO2
		return
waitKO2	call wait10ms
		call decHL
		btfss STATUS, Z
		goto waitKO1
		return				

;Cekej na tlacitko a pritom blikej "Press any key to START!"
waitForKeyIntro
		clrf toggler
waitFK0	call showPressButton
		movlw .50			;testuj 50x10ms (0.5s) stisk
		movwf i
waitFK1	call checkKeys
		iorlw 0x00		
		btfsc STATUS, Z		;byl stisk?
		goto waitFK2
		return				;byl, koncime		
waitFK2	call wait10ms		
		decfsz i, f
		goto waitFK1
		goto waitFK0		;opakuj, dokud nebude stisk
		
;Podle hodnoty toggler zobraz text nebo jej smaz
showPressButton
		movlw .1			;Prepinej 0<->1 dokola (=blikani textu)
		xorwf toggler, f
		btfss toggler, 0
		goto doNotShow
		call LCD_write_t2	;Zobraz text
		call LCD_write_t3
		return
doNotShow
		call LCD_write_t2c	;Vycisti misto po textu
		call LCD_write_t3c				
		return

checkKeys		
		btfss B_BUTTON1		;mame stisk nektereho tlacitka?
		goto checkK2
		retlw TRUE
checkK2	btfss B_BUTTON2
		retlw FALSE
		retlw TRUE
		
waitForKey
	btfss B_BUTTON1			;mame stisk nektereho tlacitka?
	goto wait_b2
	return					;stisk p1, kasli na debounce
wait_b2
	btfss B_BUTTON2
	goto waitForKey
	return

initScore
	movlw .50
	movwf player1_score
	movwf player2_score

	call drawScore2			;Vypis 50:50, inicialni skore

	;Vykresli prouzek prevahy
	;movlw .48
	;movwf X_indicator
	;movwf X
	;movlw INDICATOR_Y_POS
	;movwf Y
	;call LCD_setXY
	;movlw 0xF0
	;call LCD_sendData		
	return
	
initGameTimer
	movlw GAME_SECS
	movwf timer
	
	movlw FALSE
	movwf gameOver	
	return	

;Nastav promennou winner - 0-remiza,1-player1,2-player2
evaluateWinner
	clrf winner
	movf player1_score, w
	subwf player2_score, w
	btfsc STATUS, Z			;mame remizu, uz nic nevyhodnocuj
	return

	movlw .2				;player2 wins
	btfss STATUS, C
	movlw .1				;player1 wins
	movwf winner
	return

;*******************************************************************
;*************** LCD - INICIALIZACE DISPLEJE ***********************
;*******************************************************************
	
LCD_init
;{
	bcf LCD_RESET	
	movlw .250
	call waitMilis
	movlw .250
	call waitMilis
		
	bsf LCD_RESET

	; Tohle ma Arduino 5510
	movlw 0x21			; Extended instruction set, H=1, V=0, PD=0
	call LCD_sendCmd
	movlw 0xC4			; Set LCD Vop (Contrast)
	call LCD_sendCmd
	movlw 0x06			; Set Temp coefficient
	call LCD_sendCmd
	movlw 0x13			; LCD Bias system (1:48)
	call LCD_sendCmd
	movlw b'00100000'	;0x20, basic instruction set, H=0, V=0, PD=0
	call LCD_sendCmd
	movlw b'00001100'	;0x0C, normal mode, D=1, E=0
	call LCD_sendCmd
	
	return
;}

;*******************************************************************
;******************* LCD - POSILANI COMMANDU ***********************
;*******************************************************************

LCD_sendCmd
;{
	bcf LCD_DC	
	call LCD_writeByte
	return
;}

;*******************************************************************
;******************* LCD - POSILANI OBRAZOVYCH DAT *****************
;*******************************************************************

LCD_sendData
;{
	bsf LCD_DC
	call LCD_writeByte
	return
;}

;*******************************************************************
;******************* LCD - SPI WRITE BYTE **************************
;*******************************************************************

LCD_writeByte
;{
		movwf i2c_tmp	;uschovej posilany byte

		movlw .8
		movwf i2c_i
		
LCD_wc	bcf LCD_SCLK	 ;clock na log. 0, zaciname prenos data			
		btfss i2c_tmp, 7 ;bit 0 nastaven?
		goto bitNotSet
		bsf LCD_SDIN	;ano, posli log 1
		goto bitChecked
bitNotSet 
		bcf LCD_SDIN	;ne, posli log 0 na vystup
bitChecked			
		bsf LCD_SCLK	;clock na log. 1, skoncili jsme prenos 1 bitu

		rlf i2c_tmp, f
		decfsz i2c_i, f
		goto LCD_wc

		bcf LCD_SCLK
		return
;}

;******************************************************************
;********************* LCD - CLEAR SCREEN *************************
;******************************************************************

LCD_clear
;{
		movlw LOW LCD_BYTES
		movwf loByte
		movlw HIGH LCD_BYTES
		movwf hiByte
LCD_c1	clrw
		call LCD_sendData		
		call decHL
		btfss STATUS, Z
		goto LCD_c1
		return
;}

;******************************************************************
;********************* LCD - BLACK SCREEN *************************
;******************************************************************

LCD_black
;{
		movlw LOW LCD_BYTES
		movwf loByte
		movlw HIGH LCD_BYTES
		movwf hiByte
LCD_b1	movlw 0xFF
		call LCD_sendData		
		call decHL
		btfss STATUS, Z
		goto LCD_b1
		return
;}
;******************************************************************
;********************* LCD - SET X,Y ******************************
;******************************************************************

LCD_setXY
;{
		movf X, w			;Nastav souradnice
		iorlw b'10000000'	;X = 1X6X5X4X3X2X1X0
		call LCD_sendCmd
		movf Y, w
		iorlw b'01000000'	;Y = 0100Y3Y2Y1Y0
		call LCD_sendCmd
		return
;}

;******************************************************************
;************ LCD - VYKRESLI ODPOCITAVADLO ************************
;******************************************************************

drawTimer
	movf timer, w
	sublw GAME_SECS - .1
	btfsc STATUS, Z
	call setLoopSound	;po 1. sekunde zajisti loop

	movf timer, w
	call bin2ascii		;naplnim tens a ones
	movlw .36
	movwf X
	movlw .4
	movwf Y
	movf tens, w
	movwf number
	call LCD_drawSmallDigit
	movlw .42
	movwf X
	movlw .4
	movwf Y		
	movf ones, w
	movwf number
	call LCD_drawSmallDigit
	return

;******************************************************************
;************ LCD - ZAHAJ ODPOCITAVANI PRED HROU ******************
;******************************************************************

drawCountdown
	movlw .3
	movwf number
drawC_l	
	movlw .33
	movwf X
	movwf X_copy
	movlw .1
	movwf Y

	movlw .254			;zvuk 01_0 pro number==1
	addwf number, w
	movlw SOUND_00_321	
	btfss STATUS, C
	movlw SOUND_01_0
	call doSoundFX
	call LCD_drawDigit
	call wait1s		
	decfsz number, f
	goto drawC_l
	return

;******************************************************************
;************ LCD - VYPIS AKTUALNI SKORE OBOU HRACU ***************
;******************************************************************

drawScore

	movf pressed, f			;Prekresli score jen pri nejakem stisku
	btfsc STATUS, Z
	return

	movf pressed, w			;Stisk obou hracu = nemen skore
	xorlw 0x03		
	btfsc STATUS, Z
	return

	;call drawIndicator		;Nejprve je potreba nastavit indikator
	
press1
	btfss pressed, 1	;player1++, player2--
	goto press2
	incf player1_score, f
	decf player2_score, f
	goto checkScore
press2	
	btfss pressed, 0	;player2++, player1--
	goto scoreNext
	incf player2_score, f
	decf player1_score, f

checkScore
	;Kontrola, jestli jsme neprekrocili 100 bodu u nektereho z hracu
	;Resp. zjistime, jestli nektery hrac neni na 0
	movf player1_score, f
	btfss STATUS, Z
	goto checkScore2
	goto endGame
checkScore2
	movf player2_score, f
	btfss STATUS, Z
	goto scoreNext
endGame
	movlw TRUE
	movwf gameOver
	return

drawScore2
scoreNext
	movf player1_score, w
	call bin2ascii

	;PLAYER1 - desitky - pozice X=0, Y=0
	clrf X
	clrf X_copy
	clrf Y
	movf tens, w
	movwf number
	call LCD_drawDigit
	
	;PLAYER1 - jednotky - pozice X=18, Y=0
	movlw .18
	movwf X
	movwf X_copy
	clrf Y
	movf ones, w
	movwf number
	call LCD_drawDigit
			
	movf player2_score, w
	call bin2ascii		
	
	;PLAYER2 - desitky - pozice X=48, Y=0
	movlw .48
	movwf X
	movwf X_copy
	clrf Y
	movf tens, w
	movwf number
	call LCD_drawDigit
	
	;PLAYER2 - jednotky - pozice X=66, Y=0
	movlw .66
	movwf X
	movwf X_copy
	clrf Y
	movf ones, w
	movwf number
	call LCD_drawDigit

	clrf pressed
	return

;******************************************************************
;************ LCD - VYKRESLI PROUZEK AKTUALNI PREVAHY *************
;******************************************************************

drawIndicator

		;Nejdriv ohandluj stisk playera2
		btfss pressed, 0
		goto pl1ind
		;player2-player1
		movf player1_score, w
		subwf player2_score, w
		btfss STATUS, C			;p2-p1 >= 0? (jsme na polovine hrace2)
		goto p2dneg				;dej znacku a posun se doprava
		incf X_indicator, f
ip1		movf X_indicator, w
		movwf X
		movlw INDICATOR_Y_POS
		movwf Y
		call LCD_setXY
		movlw 0xF0
		call LCD_sendData
		return
p2dneg	movf X_indicator, w		;p2-p1 < 0? (jsme na polovine hrace1)
		movwf X					;smaz znacku a posun se doprava
		movlw INDICATOR_Y_POS
		movwf Y
		call LCD_setXY
		movlw 0x00
		call LCD_sendData
		incf X_indicator, f
		return		

		;Ohandluj pak stisk playera1
pl1ind	btfss pressed, 1
		return
		;player1-player2
		movf player2_score, w
		subwf player1_score, w
		btfss STATUS, C			;p1-p2 >=0? (jsme na polovine hrace1)
		goto p1dneg
		decf X_indicator, f
		goto ip1				;spolecny kod		
p1dneg	movf X_indicator, w		;p1-2 <0? (jsme na polovine hrace2)
		movwf X
		movlw INDICATOR_Y_POS
		movwf Y
		call LCD_setXY
		movlw 0x00
		call LCD_sendData
		decf X_indicator, f
		return

;******************************************************************
;************ LCD - VYKRESLI ODDELOVAC SKORE HRACU ****************
;******************************************************************

drawScoreDivider
		movlw .6
		movwf j
		movlw .39
		movwf X
		movlw .1
		movwf Y
		call LCD_setXY
LCD_di1	movlw 0x3F
		call LCD_sendData		
		decfsz j, f
		goto LCD_di1

		movlw .6
		movwf j
		movlw .39
		movwf X
		movlw .3
		movwf Y
		call LCD_setXY
LCD_di2	movlw 0x3F
		call LCD_sendData		
		decfsz j, f
		goto LCD_di2
		return


;******************************************************************
;************ LCD - VYKRESLOVANI CISLIC TIMERU ODPOCITAVANI *******
;******************************************************************

LCD_drawSmallDigit
		movlw FONT_S_CHARSIZE
		movwf j
		clrf index
		call LCD_setXY

		;base=5*number
		movf number, w
		movwf tmp
		movwf base
		rlf base, f
		rlf base, f
		movf tmp, w
		addwf base, f

LCD_s1	call LCD_getSmallDigitFontData ;Ziskej bitmapova data
		call LCD_sendData
		
		incf index, f
LCD_s2	decfsz j, f
		goto LCD_s1
		return

LCD_getSmallDigitFontData
		movlw HIGH LCD_smallFont
		movwf PCLATH
			
		movf index, w
		addwf base, w		
		movwf PCL
										
;******************************************************************
;************ LCD - VYKRESLOVANI JEDNOTLIVYCH CISLIC **************
;******************************************************************

LCD_drawDigit
		movlw FONT_D_CHARSIZE
		movwf j
		clrf index
		call LCD_setXY

LCD_d1	call LCD_getDigitFontData ;Ziskej bitmapova data
		clrf PCLATH
;		movwf tmp				  ;Vrat PCLATH zpet sem		
;		movlw HIGH LCD_drawDigit
;		movwf PCLATH
;		movf tmp, w
		call LCD_sendData

		incf index, f
		incf X, f
		movf X_copy, w
		addlw FONT_D_W
		subwf X, w			;Mame sirku cislice? 		
		btfss STATUS, Z		
		goto LCD_d2
		movf X_copy, w		;Vrat se zpet na zacatecni Xovou
		movwf X
		incf Y, f
		call LCD_setXY	
LCD_d2	decfsz j, f
		goto LCD_d1
		return

LCD_getDigitFontData		
		movlw HIGH digiT
		movwf PCLATH
		movlw LOW digiT		
		addwf number, w
		movwf PCL
			
		;FONT_D_CHARSIZE
		
digiT	goto font_0
		goto font_1
		goto font_2
		goto font_3
		goto font_4
		goto font_5
		goto font_6
		goto font_7
		goto font_8
		goto font_9	

font_0
		movlw HIGH font_0_tbl
		movwf PCLATH
		movlw LOW font_0_tbl		
		addwf index, w
		movwf PCL
font_1
		movlw HIGH font_1_tbl
		movwf PCLATH
		movlw LOW font_1_tbl
		addwf index, w
		movwf PCL
font_2
		movlw HIGH font_2_tbl
		movwf PCLATH
		movlw LOW font_2_tbl
		addwf index, w
		movwf PCL
font_3
		movlw HIGH font_3_tbl
		movwf PCLATH
		movlw LOW font_3_tbl
		addwf index, w
		movwf PCL
font_4
		movlw HIGH font_4_tbl
		movwf PCLATH
		movlw LOW font_4_tbl
		addwf index, w
		movwf PCL
font_5
		movlw HIGH font_5_tbl
		movwf PCLATH
		movlw LOW font_5_tbl
		addwf index, w
		movwf PCL
font_6
		movlw HIGH font_6_tbl
		movwf PCLATH
		movlw LOW font_6_tbl
		addwf index, w
		movwf PCL		
font_7
		movlw HIGH font_7_tbl
		movwf PCLATH
		movlw LOW font_7_tbl
		addwf index, w
		movwf PCL		
font_8
		movlw HIGH font_8_tbl
		movwf PCLATH
		movlw LOW font_8_tbl
		addwf index, w
		movwf PCL								
font_9
		movlw HIGH font_9_tbl
		movwf PCLATH
		movlw LOW font_9_tbl
		addwf index, w
		movwf PCL		
		
;******************************************************************
;************ LCD - VYKRESLOVANI TEXTOVYCH RETEZCU ****************
;******************************************************************		

showInfo	
	;Uvodni info
	call LCD_write_t1
	return
	
showGameOver
	goto LCD_write_t7
	
showNoWinner
	goto LCD_write_t6
	
showWinner
	btfss winner, 0
	goto LCD_write_t5	 ;p2
	goto LCD_write_t4	 ;p1
	
;Pic powered game
LCD_write_t1		
		clrf X
		movlw .4
		movwf Y
		call LCD_setXY
		movlw HIGH t1
		movwf textPointer+1
		movlw LOW t1
		movwf textPointer+0
		goto LCD_drawText
		
;Press any button
LCD_write_t2
		clrf X
		movlw .4
		movwf Y
		call LCD_setXY
		movlw HIGH t2
		movwf textPointer+1
		movlw LOW t2
		movwf textPointer+0
		goto LCD_drawText
		
;Blank line
LCD_write_t2c
		clrf X
		movlw .4
		movwf Y
		call LCD_setXY
		movlw HIGH tc
		movwf textPointer+1
		movlw LOW tc
		movwf textPointer+0
		goto LCD_drawText		
		
;to START!
LCD_write_t3
		clrf X
		movlw .5
		movwf Y
		call LCD_setXY
		movlw HIGH t3
		movwf textPointer+1
		movlw LOW t3
		movwf textPointer+0
		goto LCD_drawText
		
;Blank line
LCD_write_t3c
		clrf X
		movlw .5
		movwf Y
		call LCD_setXY
		movlw HIGH tc
		movwf textPointer+1
		movlw LOW tc
		movwf textPointer+0
		goto LCD_drawText		
		
;PLAYER1 WINS!
LCD_write_t4
		clrf X
		movlw .5
		movwf Y
		call LCD_setXY
		movlw HIGH t4
		movwf textPointer+1
		movlw LOW t4
		movwf textPointer+0
		goto LCD_drawText
		
;PLAYER2 WINS!
LCD_write_t5
		clrf X
		movlw .5
		movwf Y
		call LCD_setXY
		movlw HIGH t5
		movwf textPointer+1
		movlw LOW t5
		movwf textPointer+0
		goto LCD_drawText		

;IT IS A DRAW!
LCD_write_t6
		clrf X
		movlw .5
		movwf Y
		call LCD_setXY
		movlw HIGH t6
		movwf textPointer+1
		movlw LOW t6
		movwf textPointer+0
		goto LCD_drawText
		
;GAME OVER
LCD_write_t7
		clrf X
		movlw .4
		movwf Y
		call LCD_setXY
		movlw HIGH t7
		movwf textPointer+1
		movlw LOW t7
		movwf textPointer+0
		goto LCD_drawText		


; **************************************************************************************
; **************  LCD_drawText *********************************************************
; **************************************************************************************
LCD_drawText

LCD_dt1	call getNextChar
		iorlw 0x00 
		btfsc STATUS, Z
		return
		movwf tmp
		movlw .32
		subwf tmp, f			;x 1		
		movlw HIGH font_5x8_data
		movwf fontPointer+1
		movlw LOW font_5x8_data
		movwf fontPointer+0		;k fontPointer musime pricit 5x base
		bcf STATUS, C			;vynuluj Carry
		rlf tmp, w				;x 2
		movwf fontPointer+0		;uloz primo, nemuze pretect (max znak = 90 * 2 = 180)
		addwf fontPointer+0, f	;x 4
		btfsc STATUS, C
		incf fontPointer+1, f
		incf tmp, w				;x 5 + 1 (1=posun tabulky o 1B)
		addwf fontPointer+0, f	
		btfsc STATUS, C
		incf fontPointer+1, f		
		call getNextFontByte
		call LCD_sendData
		call getNextFontByte
		call LCD_sendData
		call getNextFontByte
		call LCD_sendData
		call getNextFontByte
		call LCD_sendData
		call getNextFontByte
		call LCD_sendData
		clrw					;Mezera mezi pismeny
		call LCD_sendData
		goto LCD_dt1

getNextChar:
		call getNextChar2 		;To je patch kvuli strankovani
		clrf PCLATH
		;movwf tmp
		;movlw HIGH getNextChar	;Nastav PCLATH do stranky, kde momentalne jsme
		;movwf PCLATH
		;movf tmp, w
		incfsz textPointer+0,f 	;Inkrementuj pointer
		goto $+2
		incf textPointer+1,f
		return 					;Vrat hodnotu (je stale ve W)
getNextChar2:
		;Zde se pouze skoci na dvoubajtovou adresu v textPointer
		movf textPointer+1,w 	;Zkopiruj HI byte do PCLATHu
		movwf PCLATH
		movf textPointer+0,w 	;Dej LO byte do PCL
		movwf PCL 				;Skoci na adresu, kam ukazuje textPointer
		
getNextFontByte:
		call getNextFontByte2 	;To je patch kvuli strankovani
		movwf tmp				;Posunu byte doleva, posune pismeno smerem dolu o 1px
		clrf PCLATH
		;movlw HIGH getNextFontByte
		;movwf PCLATH			;Nastav PCLATH do stranky, kde momentalne jsme
		bcf STATUS, C			;Nuluj carry, at nam neco neprirotuje zprava
		rlf tmp, w
		incfsz fontPointer+0,f 	;Inkrementuj pointer
		goto $+2
		incf fontPointer+1,f
		return 					;Vrat hodnotu (je stale ve W)
getNextFontByte2:
		;Zde se pouze skoci na dvoubajtovou adresu v fontPointer
		movf fontPointer+1,w 	;Zkopiruj HI byte do PCLATHu
		movwf PCLATH
		movf fontPointer+0,w 	;Dej LO byte do PCL
		movwf PCL 				;Skoci na adresu, kam ukazuje fontPointer		


;******************************************************************
;************ LCD - VYKRESLOVANI UVODNI OBRAZOVKY *****************
;******************************************************************

LCD_drawSplashScreen
		movlw .0			;Splash screen od 0,0
		movwf X
		movwf X_copy
		clrf Y

		;prvni cast obrazku
		movlw splash_1_size
		movwf j
		clrf index
		call LCD_setXY
		clrf number
		call LCD_sp1

		;druha cast obrazku, X a Y zustava nezmeneno
		movlw splash_2_size
		movwf j
		clrf index
		movlw .1
		movwf number
		call LCD_sp1
		return

LCD_sp1	call LCD_getSplashData		 ;Ziskej bitmapova data
		movwf tmp					 ;Vrat se zpet sem
		movlw HIGH LCD_sp1
		movwf PCLATH
		movf tmp, w
		call LCD_sendData		
		incf index, f
		incf X, f
		movf X_copy, w
		addlw SPLASH_W
		subwf X, w				;Mame sirku bitmapy? (84px)		
		btfss STATUS, Z		
		goto LCD_sp2
		movf X_copy, w			;Vrat se zpet na zacatecni Xovou
		movwf X
		incf Y, f
		call LCD_setXY	
LCD_sp2	decfsz j, f
		goto LCD_sp1
		return

LCD_getSplashData
		movlw HIGH splashT
		movwf PCLATH
		movf number, w
		addwf PCL, F
splashT	goto splash_1
		goto splash_2

; *** SUBRUTINA, CEKEJ nuMilis milisekund ***************************

waitSecs
		movwf numSecs
waitS	call wait1s
		decfsz numSecs, f
		goto waitS
		return

waitMilis
		movwf numMilis
waitM	call wait1ms
		decfsz numMilis, f
		goto waitM
		return
		
wait10ms
		movlw .10
		goto waitMilis

wait100ms
		movlw .100
		goto waitMilis

wait150ms
		movlw .150
		goto waitMilis


; *** SUBRUTINA, CEKEJ 30us (=30 jednotaktovych instrukci)

; Delay = 3e-05 seconds
; Clock frequency = 8 MHz

; Actual delay = 3e-05 seconds = 60 cycles
; Error = 0 %

wait30us
			;55 cycles
	movlw	0x12
	movwf	del1
wait30us_0
	decfsz	del1, f
	goto	wait30us_0

			;1 cycle
	nop

			;4 cycles (including call)
	return


; Delay = 0.001 seconds
; Clock frequency = 8 MHz

; Actual delay = 0.001 seconds = 2000 cycles
; Error = 0 %

wait1ms
			;1993 cycles
	movlw	0x8E
	movwf	del1
	movlw	0x02
	movwf	del2
wait1ms_0
	decfsz	del1, f
	goto	$+2
	decfsz	del2, f
	goto	wait1ms_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return

; Delay = 1 seconds
; Clock frequency = 8 MHz

; Actual delay = 1 seconds = 2000000 cycles
; Error = 0 %

wait1s
			;1999996 cycles
	movlw	0x11
	movwf	del1
	movlw	0x5D
	movwf	del2
	movlw	0x05
	movwf	del3
wait1s_0
	decfsz	del1, f
	goto	$+2
	decfsz	del2, f
	goto	$+2
	decfsz	del3, f
	goto	wait1s_0

			;4 cycles (including call)
	return

; *** SUBRUTINY pro 16bitovy counter ********************************	
; *** Nastavi Zero, pokud jsme na nule

incHL	incfsz loByte, f
		return	
		incf hiByte, f
		return

decHL	movf loByte, f
		btfsc STATUS, Z ;je loByte na nule?
		goto decHL2
		decf loByte, w	;kopie pro nasledny OR (test na 0)
		decf loByte, f
		iorwf hiByte, w ;Z flag nastaven pri 0 (loByte OR hiByte)
		return
decHL2	decf loByte, f
		decf hiByte, f
		bcf STATUS, Z	;Potrebuju vynulovat Zero (aby mi pri lo/hi 0/1 predchozi decf Z nenastavil)
		return
	
; *** SUBRUTINA pro prevod 6bit binary to BCD ********************************	
	
bin2ascii
	clrf tens
	addlw .256 - .100
digit100
	addlw .20
	btfss STATUS,C
	goto  digit40
	bsf   tens,3
	addlw .256 - .20
	goto digit10
digit40
	addlw .40
	btfss STATUS,C
	goto  $+3
	bsf   tens,2
	addlw .256 - .40
	addlw .20
	btfss STATUS,C
	goto  $+3
	bsf   tens,1
	addlw .256 - .20
digit10
	addlw .10
	btfss STATUS,C
	goto  $+3
	bsf   tens,0
	addlw .256 - .10
	
	addlw .10
	movwf ones
	return	

; *****************************************************************	
; ********************** F O N T  D A T A *************************
; *****************************************************************

		org 0x400
LCD_smallFont		
        dt 0x7E, 0x81, 0x81, 0x81, 0x7E;0
        dt 0x00, 0x82, 0xFF, 0x80, 0x00;1    
        dt 0xC2, 0xA1, 0x91, 0x89, 0x86;2
        dt 0x41, 0x81, 0x85, 0x8B, 0x71;3
        dt 0x38, 0x24, 0x22, 0xFF, 0x20;4
        dt 0x4F, 0x89, 0x89, 0x89, 0x71;5
        dt 0x7C, 0x8A, 0x89, 0x89, 0x70;6
        dt 0x03, 0xF1, 0x09, 0x05, 0x03;7
        dt 0x76, 0x89, 0x89, 0x89, 0x76;8
        dt 0x06, 0x89, 0x89, 0x49, 0x3E;9

text_table
t1		dt "PIC powered game", 0x00
t2		dt "Press a button"  , 0x00
t3		dt "   to START!  "  , 0x00
t4		dt "PLAYER 1 WINS!"  , 0x00
t5		dt "PLAYER 2 WINS!"  , 0x00
t6		dt " IT'S A DRAW "   , 0x00
t7		dt "  GAME OVER  "   , 0x00
tc		dt "              "  , 0x00
				


;*** SPLASH SCREEN DATA
			org 0x0500
splash_1	movlw HIGH splash_1_data
			movwf PCLATH
			movf index, w
			addwf PCL, f
splash_1_data
		dt 0xFE, 0x03, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xC1, 0xC1, 0x01, 0x01, 0x01, 0x01
		dt 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
		dt 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1, 0xE1
		dt 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
		dt 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
		dt 0x01, 0x01, 0x03, 0xFE, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xE1, 0xE1, 0xFF, 0xFF, 0xBF, 0xBF
		dt 0x1F, 0x00, 0xF0, 0xF8, 0xFE, 0xFF, 0xFF, 0x07, 0x07, 0xFF, 0xFD, 0xFA, 0xFC, 0xF8, 0x00, 0xF8
		dt 0xFC, 0xFE, 0xFF, 0x07, 0x07, 0xFF, 0xFD, 0xFA, 0xF4, 0xF8, 0x01, 0x01, 0x01, 0xFF, 0xFF, 0xFF
		dt 0xFF, 0xFF, 0x01, 0x01, 0x00, 0x00, 0xF8, 0xFE, 0xFF, 0xFF, 0x07, 0x07, 0xFF, 0xFD, 0xFA, 0xFC
		dt 0xF0, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x06, 0xFF, 0xFD, 0xFB, 0xF6, 0xFC, 0x00, 0x07, 0x07
		dt 0x87, 0xF7, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xC1, 0xC1
		dt 0xFF, 0xFF, 0xFD, 0xFF, 0x7E, 0x00, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0xFF, 0xFF, 0xFD
		dt 0xFF, 0x7F, 0x00, 0x7F, 0xFF, 0xFD, 0xFF, 0x80, 0x80, 0xFF, 0xFF, 0xFD, 0xFF, 0x7F, 0x00, 0x00
		dt 0x00, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xFF, 0xFF, 0x80, 0x80
		dt 0xFF, 0xFF, 0xFD, 0xFF, 0x3F, 0x00, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFD, 0xFF
		dt 0xFF, 0x00, 0xE0, 0xFC, 0xFF, 0xFF, 0xFD, 0xBF
splash_1_size equ $-splash_1_data
		
			org 0x0600
splash_2	movlw HIGH splash_2_data
			movwf PCLATH
			movf index, w
			addwf PCL, f
splash_2_data
		dt 0x87, 0x80, 0x00, 0xFF, 0x7F, 0xC0, 0x83, 0x83
		dt 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x81, 0x80, 0x80, 0x80, 0x80, 0x81, 0x83, 0x83, 0x83
		dt 0x83, 0x83, 0x83, 0x81, 0x80, 0x80, 0x80, 0x80, 0x81, 0x81, 0x83, 0x83, 0x83, 0x83, 0x83, 0x81
		dt 0x80, 0x80, 0x80, 0x80, 0x80, 0x83, 0x83, 0x83, 0x83, 0x83, 0x80, 0x80, 0x80, 0x80, 0x80, 0x81
		dt 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x81, 0x80, 0x80, 0x80, 0x83, 0x83, 0x83, 0x83, 0x83, 0x80
		dt 0x83, 0x83, 0x83, 0x83, 0x83, 0x80, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0xC0, 0x7F
splash_2_size equ $-splash_2_data

			org 0x0700
			nop		;musi byt kvuli zarovnani na 255 bytes
font_5x8_data
		dt 0x00, 0x00, 0x00, 0x00, 0x00; space (32dec)
		dt 0x00, 0x00, 0x2f, 0x00, 0x00; !
		dt 0x00, 0x07, 0x00, 0x07, 0x00; "
		dt 0x14, 0x7f, 0x14, 0x7f, 0x14; #
		dt 0x24, 0x2a, 0x7f, 0x2a, 0x12; $
		dt 0xc4, 0xc8, 0x10, 0x26, 0x46; %
		dt 0x36, 0x49, 0x55, 0x22, 0x50; &
		dt 0x00, 0x05, 0x03, 0x00, 0x00; '
		dt 0x00, 0x1c, 0x22, 0x41, 0x00; (
		dt 0x00, 0x41, 0x22, 0x1c, 0x00; )
		dt 0x14, 0x08, 0x3E, 0x08, 0x14; *
		dt 0x08, 0x08, 0x3E, 0x08, 0x08; +
		dt 0x00, 0x00, 0x50, 0x30, 0x00; ,
		dt 0x10, 0x10, 0x10, 0x10, 0x10; -
		dt 0x00, 0x60, 0x60, 0x00, 0x00; .
		dt 0x20, 0x10, 0x08, 0x04, 0x02; /
		dt 0x3E, 0x51, 0x49, 0x45, 0x3E; 0
		dt 0x00, 0x42, 0x7F, 0x40, 0x00; 1
		dt 0x42, 0x61, 0x51, 0x49, 0x46; 2
		dt 0x21, 0x41, 0x45, 0x4B, 0x31; 3
		dt 0x18, 0x14, 0x12, 0x7F, 0x10; 4
		dt 0x27, 0x45, 0x45, 0x45, 0x39; 5
		dt 0x3C, 0x4A, 0x49, 0x49, 0x30; 6
		dt 0x01, 0x71, 0x09, 0x05, 0x03; 7
		dt 0x36, 0x49, 0x49, 0x49, 0x36; 8
		dt 0x06, 0x49, 0x49, 0x29, 0x1E; 9
		dt 0x00, 0x36, 0x36, 0x00, 0x00; :
		dt 0x00, 0x56, 0x36, 0x00, 0x00; ;
		dt 0x08, 0x14, 0x22, 0x41, 0x00; <
		dt 0x14, 0x14, 0x14, 0x14, 0x14; =
		dt 0x00, 0x41, 0x22, 0x14, 0x08; >
		dt 0x02, 0x01, 0x51, 0x09, 0x06; ?
		dt 0x32, 0x49, 0x59, 0x51, 0x3E; @
		dt 0x7E, 0x11, 0x11, 0x11, 0x7E; A
		dt 0x7F, 0x49, 0x49, 0x49, 0x36; B
		dt 0x3E, 0x41, 0x41, 0x41, 0x22; C
		dt 0x7F, 0x41, 0x41, 0x22, 0x1C; D
		dt 0x7F, 0x49, 0x49, 0x49, 0x41; E
		dt 0x7F, 0x09, 0x09, 0x09, 0x01; F
		dt 0x3E, 0x41, 0x49, 0x49, 0x7A; G
		dt 0x7F, 0x08, 0x08, 0x08, 0x7F; H
		dt 0x00, 0x41, 0x7F, 0x41, 0x00; I
		dt 0x20, 0x40, 0x41, 0x3F, 0x01; J
		dt 0x7F, 0x08, 0x14, 0x22, 0x41; K
		dt 0x7F, 0x40, 0x40, 0x40, 0x40; L
		dt 0x7F, 0x02, 0x0C, 0x02, 0x7F; M
		dt 0x7F, 0x04, 0x08, 0x10, 0x7F; N
		dt 0x3E, 0x41, 0x41, 0x41, 0x3E; O
		dt 0x7F, 0x09, 0x09, 0x09, 0x06; P
		dt 0x3E, 0x41, 0x51, 0x21, 0x5E; Q
		dt 0x7F, 0x09, 0x19, 0x29, 0x46; R
		dt 0x46, 0x49, 0x49, 0x49, 0x31; S
		dt 0x01, 0x01, 0x7F, 0x01, 0x01; T
		dt 0x3F, 0x40, 0x40, 0x40, 0x3F; U
		dt 0x1F, 0x20, 0x40, 0x20, 0x1F; V
		dt 0x3F, 0x40, 0x38, 0x40, 0x3F; W
		dt 0x63, 0x14, 0x08, 0x14, 0x63; X
		dt 0x07, 0x08, 0x70, 0x08, 0x07; Y
		dt 0x61, 0x51, 0x49, 0x45, 0x43; Z
		dt 0x00, 0x7F, 0x41, 0x41, 0x00; [
		dt 0x55, 0x2A, 0x55, 0x2A, 0x55; "Yen"
		dt 0x00, 0x41, 0x41, 0x7F, 0x00; ]
		dt 0x04, 0x02, 0x01, 0x02, 0x04; ^
		dt 0x40, 0x40, 0x40, 0x40, 0x40; _
		dt 0x00, 0x01, 0x02, 0x04, 0x00; '
		dt 0x20, 0x54, 0x54, 0x54, 0x78; a
		dt 0x7F, 0x48, 0x44, 0x44, 0x38; b
		dt 0x38, 0x44, 0x44, 0x44, 0x20; c
		dt 0x38, 0x44, 0x44, 0x48, 0x7F; d
		dt 0x38, 0x54, 0x54, 0x54, 0x18; e
		dt 0x08, 0x7E, 0x09, 0x01, 0x02; f
		dt 0x0C, 0x52, 0x52, 0x52, 0x3E; g
		dt 0x7F, 0x08, 0x04, 0x04, 0x78; h
		dt 0x00, 0x44, 0x7D, 0x40, 0x00; i
		dt 0x20, 0x40, 0x44, 0x3D, 0x00; j
		dt 0x7F, 0x10, 0x28, 0x44, 0x00; k
		dt 0x00, 0x41, 0x7F, 0x40, 0x00; l
		dt 0x7C, 0x04, 0x18, 0x04, 0x78; m
		dt 0x7C, 0x08, 0x04, 0x04, 0x78; n
		dt 0x38, 0x44, 0x44, 0x44, 0x38; o
		dt 0x7C, 0x14, 0x14, 0x14, 0x08; p
		dt 0x08, 0x14, 0x14, 0x18, 0x7C; q
		dt 0x7C, 0x08, 0x04, 0x04, 0x08; r
		dt 0x48, 0x54, 0x54, 0x54, 0x20; s
		dt 0x04, 0x3F, 0x44, 0x40, 0x20; t
		dt 0x3C, 0x40, 0x40, 0x20, 0x7C; u
		dt 0x1C, 0x20, 0x40, 0x20, 0x1C; v
		dt 0x3C, 0x40, 0x30, 0x40, 0x3C; w
		dt 0x44, 0x28, 0x10, 0x28, 0x44; x
		dt 0x0C, 0x50, 0x50, 0x50, 0x3C; y
		dt 0x44, 0x64, 0x54, 0x4C, 0x44; z

		org 0x0900
font_data

font_0_tbl	
		dt 0xE0, 0xF0, 0xF8, 0xF4, 0xEE, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xEE, 0xF4, 0xF8, 0xF0, 0xE0 
		dt 0x1F, 0x3F, 0x7F, 0x3F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x3F, 0x1F   
		dt 0xFC, 0xFE, 0xFF, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFE, 0xFF, 0xFE, 0xFC  
		dt 0x03, 0x07, 0x0F, 0x17, 0x3B, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x3B, 0x17, 0x0F, 0x07, 0x03 
  
font_1_tbl  
		dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF0, 0xF8, 0xF0, 0xE0 
		dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x3F, 0x1F   
		dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFE, 0xFF, 0xFE, 0xFC  
		dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x07, 0x03 
  
		org 0x0A00
font_2_tbl  
		dt 0x00, 0x00, 0x00, 0x04, 0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xEE, 0xF4, 0xF8, 0xF0, 0xE0 
		dt 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x3F, 0x1F   
		dt 0xFC, 0xFE, 0xFF, 0xFE, 0xFD, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00  
		dt 0x03, 0x07, 0x0F, 0x17, 0x3B, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x38, 0x10, 0x00, 0x00, 0x00 
  
font_3_tbl  
		dt 0x00, 0x00, 0x00, 0x04, 0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xEE, 0xF4, 0xF8, 0xF0, 0xE0 
		dt 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x3F, 0x1F   
		dt 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFD, 0xFE, 0xFF, 0xFE, 0xFC  
		dt 0x00, 0x00, 0x00, 0x10, 0x38, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x3B, 0x17, 0x0F, 0x07, 0x03 
  
		org 0x0B00
font_4_tbl  
		dt 0xE0, 0xF0, 0xF8, 0xF0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xF0, 0xF8, 0xF0, 0xE0 
		dt 0x1F, 0x3F, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x3F, 0x1F   
		dt 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFD, 0xFE, 0xFF, 0xFE, 0xFC  
		dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x07, 0x03 
  
font_5_tbl  
		dt 0xE0, 0xF0, 0xF8, 0xF4, 0xEE, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x04, 0x00, 0x00, 0x00 
		dt 0x1F, 0x3F, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00   
		dt 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFD, 0xFE, 0xFF, 0xFE, 0xFC  
		dt 0x00, 0x00, 0x00, 0x10, 0x38, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x3B, 0x17, 0x0F, 0x07, 0x03 
		
		org 0x0C00
font_6_tbl  
		dt 0xE0, 0xF0, 0xF8, 0xF4, 0xEE, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x04, 0x00, 0x00, 0x00 
		dt 0x1F, 0x3F, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00   
		dt 0xFC, 0xFE, 0xFF, 0xFE, 0xFD, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFD, 0xFE, 0xFF, 0xFE, 0xFC  
		dt 0x03, 0x07, 0x0F, 0x17, 0x3B, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x3B, 0x17, 0x0F, 0x07, 0x03 
  
font_7_tbl  
		dt 0x00, 0x00, 0x00, 0x04, 0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xEE, 0xF4, 0xF8, 0xF0, 0xE0 
		dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x3F, 0x1F   
		dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFE, 0xFF, 0xFE, 0xFC  
		dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x07, 0x03 
  
		org 0x0D00
font_8_tbl  
		dt 0xE0, 0xF0, 0xF8, 0xF4, 0xEE, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xEE, 0xF4, 0xF8, 0xF0, 0xE0 
		dt 0x1F, 0x3F, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x3F, 0x1F   
		dt 0xFC, 0xFE, 0xFF, 0xFE, 0xFD, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFD, 0xFE, 0xFF, 0xFE, 0xFC  
		dt 0x03, 0x07, 0x0F, 0x17, 0x3B, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x3B, 0x17, 0x0F, 0x07, 0x03 
  
font_9_tbl 
		dt 0xE0, 0xF0, 0xF8, 0xF4, 0xEE, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xEE, 0xF4, 0xF8, 0xF0, 0xE0 
		dt 0x1F, 0x3F, 0x7F, 0xBF, 0xDF, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xDF, 0xBF, 0x7F, 0x3F, 0x1F   
		dt 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0xFD, 0xFE, 0xFF, 0xFE, 0xFC  
		dt 0x00, 0x00, 0x00, 0x10, 0x38, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x7C, 0x3B, 0x17, 0x0F, 0x07, 0x03 
  

; *** KONEC SOUBORU *************************************************	
	end