; PIC16F883 Configuration Bit Settings

; Assembly source line config statements

#include "p16F883.inc"

	__CONFIG _CONFIG1, (_FOSC_INTRC_NOCLKOUT & _LVP_OFF & _WDTE_OFF & _MCLRE_OFF & _PWRTE_OFF & _BOREN_OFF & _CP_OFF & _CPD_OFF & _IESO_OFF & _FCMEN_OFF);
	__CONFIG _CONFIG2, (_WRT_OFF & _BOR4V_BOR40V);
 
    errorlevel    -302    
    
    cblock 0x20
	pressOrder1	;cislo hrace, ktery stiskl 1.
	pressOrder2	;cislo hrace, ktery stiskl 2.
	pressOrder3 ;...
	pressOrder4
	w_temp
	status_temp
	pclath_temp
	d			;ktery LED 7seg displej zobrazujeme 0,1,2,3?
	d_temp		
	d1			;Body pro hrace 1-4
	d2	
	d3
	d4
	c1			;preruseni
	c1_copy
	del1		;registry pro cekaci subrutiny
	del2
	del3
	hiByte
	loByte
	numSound
	numText			;cislo textu, ktery vypisovat
	numTextSaved	;uloz
	textLen
	tmp
	tmpByte
	i2c_byte
	lcd_backlight
	lcd_data
	nonZeroByte
	numMilis	;Kolik cyklu wait1ms zavolat
	numSecs		;Kolik cyklu wait1s zavolat
	i			;i2c_send
	j
	k			;text output
	l			;zobraz vice vitezu
	round		;cislo kola
	rounds2go	;kolik kol do konce
	failMask	;maska pro zjisteni, ktery hrac podvadi (stlacil brzy)
	pressMask	;maska pro zjisteni, ktery z hracu uz stisk provedl
	pressLeft	;max 4. hraci mohou stisknout, counter pro zjisteni, ze uz vsichni stiskli
	index		;table lookup - uloz pozici
	player		;pro texty, body pro..., zvitezil hrac...
	winLed		;maska PORTB pro blikani spravne ledky pro viteze kola
	winMask		;pro vyhodnoceni celkoveho vitez
	numWinners	;pocet vitezu, counter
	cmpMax		;nalezene maximum, evaluateWinner
	waitStart	;cekame na stisk START tlacitka? (bool)
	startLED	;aktualni stav START buttonu (ON/OFF), toggle
    endc

FALSE				equ 0x00
TRUE				equ 0x01


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;7SEG LED DEFINES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;   aaaa    
;   f  b
;   f  b
;   gggg
;   e  c
;   e  c
;   dddd
        
;Ktera cislice/displej se zobrazuje aktualne    
W_FIRST	    		equ b'0001'
W_SECOND    		equ b'0010'
W_THIRD	    		equ b'0100'
W_FOURTH    		equ b'1000'
    
;Anody
#define A_FIRST	    PORTA, RA0
#define A_SECOND    PORTA, RA1
#define A_THIRD	    PORTA, RA2
#define A_FOURTH	PORTA, RA3

;Vystupy pro BCD decoder
#define BCD_A		PORTA, RA5
#define BCD_B		PORTC, RC0
#define BCD_C		PORTC, RC1
#define BCD_D		PORTA, RA4

;WT588D   
#define S_SCK		PORTC, RC6;
#define S_CS		PORTC, RC5;
#define S_SDA		PORTC, RC4;

;LCD1602
#define LCD_SDA		PORTC, RC2;
#define LCD_SCL		PORTC, RC3;

;Vypocet pro obnovovaci frekvenci 50Hz @4MHz krystal
;1 instrukce = 1000 nS = 1uS
;1 preruseni = 256 instrukci = 256 * 1uS = 256uS
;50Hz = 1/50 = 0.02 sec = 20mS = 20000uS / 4 digits = 5000uS na 1 digitu
;5000 / 256 = kolik preruseni = cca 20 preruseni
N_PRERUSENI 		equ .20;

;Pocet preruseni pri blikani START buttonu, potrebujeme blikat
;v 500ms intervalech, coz je 1953*256uS (256=1 interrupt)
N_START_PRERUS		equ .1953;	(7*256+161)
N_START_PRERUS_L	equ .161;	LOW BYTE	
N_START_PRERUS_H	equ .7;		HI BYTE

N_ROUNDS			equ .9		;Pocet kol

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;BUTTONY
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#define B_PLAYER1	PORTB, RB7
#define L_PLAYER1	PORTB, RB6
#define B_PLAYER2	PORTB, RB5
#define L_PLAYER2	PORTB, RB4
#define B_PLAYER3	PORTB, RB3
#define L_PLAYER3	PORTB, RB2
#define B_PLAYER4	PORTB, RB1
#define L_PLAYER4	PORTB, RB0

#define B_START		PORTA, RA6;		;TLACITKO PRO START
#define L_START		PORTA, RA7;		;LED TLACITKA START

;Bity failMask
F_PLAYER1_BIT		equ .0
F_PLAYER2_BIT		equ .1
F_PLAYER3_BIT		equ .2
F_PLAYER4_BIT		equ .3

;Id hracu
PLAYER1				equ .1
PLAYER2				equ .2
PLAYER3				equ .4
PLAYER4				equ .8

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;LCD 1602 DEFINES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

					;D7 D6 D5 D4 BL EN RW RS
;LCD1602 COMMANDS
LCD_ADDR_BYTE		equ b'01001110'	;0x27 Ywrobot LCM1602 IIC v1
LCD_4BIT_INIT		equ b'00110000' 
LCD_EN_MASK			equ b'00000100' ;EN (BF) bit
LCD_EN_MASK_AND		equ b'11111011' ;EN (BF) bit AND
LCD_BL_MASK			equ b'00001000' ;BL - BACKLIGHT bit
LCD_NOBL_MASK		equ b'00000000' ;BL - BACKLIGHT off
LCD_RS_MASK			equ b'00000001' ;RS - 1=DATA
LCD_NORS_MASK		equ b'00000000' ;RS - 0=COMMAND

;Texty
T_PRESS_START			equ .0
T_POINTS_FOR			equ .1
T_NO_POINTS				equ	.2
T_GAME_NAME				equ .3
T_GAME_OVER				equ .4
T_NO_WINNER				equ .5
T_PLAYER_WINS			equ .6
T_ROUND_NR				equ .7
T_GET_READY				equ .8
T_LETS_GO				equ .9
T_DRAW_ALL				equ .10
T_DRAW					equ .11

;Zvuky
Z_INTRO_20TH_CENTURY	equ 0x00
Z_GAMEOVER_APPLAUSE		equ 0x01
Z_GAME_TICK_OLD_CLOCK	equ 0x02
Z_GAME_TICK2			equ 0x03
Z_GAME_TICK3			equ 0x04
Z_GAME_BELL_RING		equ 0x05
Z_GAME_BUZZER			equ 0x06
Z_GAME_DESK_BELL		equ 0x07
Z_GAME_CASH_REGISTER	equ 0x08
Z_NUMBERS_BASE			equ 0x08	;Jedu od 1
Z_ONE					equ 0x09
Z_TWO					equ 0x0a
Z_THREE					equ 0x0b
Z_FOUR					equ 0x0c
Z_FIVE					equ 0x0d
Z_SIX					equ 0x0e
Z_SEVEN					equ 0x0f
Z_EIGHT					equ 0x10
Z_NINE					equ 0x11
Z_TEN					equ 0x12
Z_GAME_ROUND			equ 0x13
Z_SILENCE				equ 0x14
Z_GAME_OVER				equ 0x15
  
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           
    
    
;****** START ****************************************
    
	org 0x00
    goto main
	
	org 0x04
	goto interrupt


; ********************************************************************
; *********************** INTERRUPT **********************************
; ********************************************************************

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

ISR	bcf INTCON, T0IF    ;vycisti Interrupt flag
	decfsz c1, f	    ;prechod na dalsi cislici?
	goto ISR_next		;jeste kontrola LED
	movf c1_copy, w		
	movwf c1	    	;mame zresetovany pocet preruseni
	call zobraz	

ISR_next				;START button LEDka
	btfss waitStart, 0
	goto skip
	call decHL
	btfss STATUS, Z		;Mame 500ms? Vymen stav na portu LEDky	
	goto skip
	movlw N_START_PRERUS_H
	movwf hiByte
	movlw N_START_PRERUS_L
	movwf loByte

	movlw .1			;Prepni stav na LEDce, XORuj s 1
	xorwf startLED, f
	btfss startLED, 0
	goto startOff
	bsf L_START
	goto skip
startOff
	bcf L_START

skip
	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'11001000'
	movwf OPTION_REG

	;*** PORTA NASTAVENI - tlacitka ***
	BANK1	
	movlw 0x06   ; Configure all PORTA pins
	movwf ADCON1 ; as digital inputs			
	movlw b'01000000'; RA6 - BUTTON START
	movwf TRISA 

	BANK0 	
	clrf PORTA
	
	;*** PORTB NASTAVENI - BUTTONY a LEDKY BUTTONU ***
	
	BANK1
	movlw b'10101010'; 1=BUTTON,0=LEDKA
	movwf TRISB
	clrf IOCB		 ;Interrupt onChange disabled
	clrf WPUB
	BANK3
	clrf ANSEL
	clrf ANSELH
	BANK0
	clrf PORTB   

	;*** PORTC NASTAVENI (WT558D, LCD1602, START BUTTON) ***
	
	BANK1
	movlw b'10000000'
	movwf TRISC			;pouze RC3 je vstup (B_START)
	
	BANK0
	
	clrf CCP1CON 		; Turn CCP module off
	clrf SSPCON  		; Vypnout MSSP module
	clrf PORTC
	
						;Nastav SCK a CS na log. 1
	bsf S_SCK			;Pro WT588D
	bsf S_CS
	
;***** INIT ****************************************** 

init	

	movlw .1
	movwf nonZeroByte

	clrf waitStart			;Jeste necekame na START
	clrf startLED			

	call vynulujBody		;Vyresetuj cislice

	clrf lcd_backlight		;Podsviceni default off
	clrf lcd_data			;Defaultne posilame commandy (=0, 1=data)
	
	;1.cislice = b'0001'; 2.cislice=b'0010', 3.cislice=b'0100',... (.1,.2,.4,.8)
	movlw W_FIRST
	movwf d
		
	;Pocet preruseni nez prejdu na dalsi cislici
	movlw N_PRERUSENI
	movwf c1
	movwf c1_copy


	;Inicializace Timer0
	BANK0
	clrf INTCON
	clrf TMR0	

	bsf INTCON, TMR0IE    	;Povol Timer0 interrupt
	bsf INTCON, GIE	    	;Povol vsechna preruseni
	
	call zobraz				;Zobraz LED displej
	call i2c_lcdInit		;Inicializuj LCD display
				

; *********************************************************************
; *********************************************************************
; ********************** S T A R T   G A M E **************************
; *********************************************************************
; *********************************************************************

			
RESET_GAME	
		call lcd_clearDisplay

		call vynulujBody			;Vsichni hraci 0 bodu

		clrf waitStart				;Jeste necekame na START
		clrf startLED			

		movlw T_GAME_NAME
		call lcd_printText			;Zobraz nazev hry

		movlw Z_INTRO_20TH_CENTURY
		call doSoundFX				;Uvodni Fanfara

		call introLightFX			;Uvodni poblikavani buttonu
					
BEGIN	movlw N_ROUNDS				;Kolik kol hry?
		movwf rounds2go

		movlw .1
		movwf round					;Aktualni cislo kola

START_loop	
		movlw T_PRESS_START
		call lcd_printText			;Zobraz cekani na START			
							
		;Blikani START LEDky reseno pres interrupt
		movlw N_START_PRERUS_H
		movwf hiByte
		movlw N_START_PRERUS_L
		movwf loByte

		movlw TRUE
		movwf startLED				;Zapnuto
		bsf L_START					;Rozsvit START LEDku
		movwf waitStart				;Cekame na tlacitko

START_c	btfss B_START				;mame stisk START tlacitka?
		goto START_c
		call wait10ms
		btfss B_START				;debounce test
		goto START_c
				
START_w btfsc B_START				;akce AZ po uvolneni tlacitka
		goto START_w

		movlw FALSE
		movwf waitStart				;Uz necekame, neblikej STARTem		
		bcf L_START					;Vypni START LEDku

		movlw Z_GAME_DESK_BELL		;Zvonek ohlasujici dalsi kolo
		call doSoundFX
		movlw .2
		call waitSecs

		call lcd_clearDisplay

		movlw T_ROUND_NR			;"Kolo c. "
		call lcd_printText

		movf round, w
		xorlw b'00001010'			;kolo 10 handluj zvlast
		btfss STATUS, Z
		goto notRound10
		movlw '1'
		call lcd_printChar
		movlw '0'
		call lcd_printChar
		goto zvukRound
notRound10
		movf round, w
		addlw '0'
		call lcd_printChar
zvukRound
		movlw Z_GAME_ROUND			;Ohlas cislo kola "ROUND X!"
		call doSoundFX		
		call wait1s
		
		movf round, w				;Spocitej ktery zvuk prehrat
		addlw Z_NUMBERS_BASE
		call doSoundFX
		call wait1s

		movlw T_GET_READY			;Pripravit se!
		call lcd_printText
		
		movlw Z_GAME_TICK_OLD_CLOCK	;Tikot
		call doSoundFX

		call waitRandom				;Pockej cca 2 - 5 sekund "nahodne"
	
		call findCheaters			;Napln bity masky podvodniky
		
		movlw Z_GAME_BELL_RING		;TED!
		call doSoundFX

		movlw T_LETS_GO				;HRAJEME!
		call lcd_printText

		call evaluateRound			;Ohandluj stisky a zjisti kdo vyhral

		;Tuto sekci jsem vyndal z evaluateGame kvuli hloubce stacku
		call lcd_printText			;Vypis viteze kola
		btfsc player, 7				;Vyhral nekdo? (0x80)
		goto eval_Done
		
		movf player, w				;Vypis cislo hrace			
		call lcd_printChar			;Goto misto call usetri stack
		;;;;

eval_Done
		movlw Z_GAME_CASH_REGISTER
		call doSoundFX
		;Mame 2secs na vyblikani viteze kola
		call blikWinner
	
		incf round, f				;Zvys cislo kola

		decfsz rounds2go, f
		goto START_loop				;Dalsi kolo po stisku STARTu

GAME_OVER		
		clrf waitStart				;Uz necekame na START
		clrf startLED			
		call lcd_clearDisplay

		movlw T_GAME_OVER
		call lcd_printText

		call evaluateWinner			;Vrati winMask, 4 dolni bity s vitezi
		
		;1) Zjisti, jestli je nejaky vitez, tj. otestuj stav, kdy
		;maji vsichni 0 bodu - vypis "BEZ VITEZE"
		movf numWinners, f
		btfss STATUS, Z
		goto haveWinners
		movlw T_NO_WINNER
		call lcd_printText
		goto FINALE
haveWinners
		;2) Zjisti, jestli nevyhrali vsichni, tj. numWinners == 4
		btfss numWinners, 2	;bit 2 == 0x04
		goto less4Wins
		movlw T_DRAW_ALL
		call lcd_printText
		goto FINALE
less4Wins
		;3) Zjisti, jestli vyhral prave 1 hrac
		decfsz numWinners, w
		goto moreThanOne
		movlw T_PLAYER_WINS	;Vitezi prave 1 hrac
		call lcd_printText
		call getWinnerNumber
		call lcd_printChar
		goto FINALE		
moreThanOne
		movlw T_DRAW		;Vitezi
		call lcd_printText
		
		;Projdi winMask na nastavene bity. Pokud je nastaven, zvys counter.
		;Pokud counter == numWinner, uz nevypisuj "," mezi cisly hracu
		clrf l
		btfss winMask, F_PLAYER1_BIT
		goto nextW2
		incf l, f
		movlw '1'
		call lcd_printChar
		movlw ','
		call lcd_printChar
nextW2	btfss winMask, F_PLAYER2_BIT
		goto nextW3
		incf l, f
		movlw '2'
		call lcd_printChar
		movf l, w			
		xorwf numWinners, w	;l == numWinners?
		btfsc STATUS, Z
		goto FINALE
		movlw ','			;jeste mame dalsi viteze
		call lcd_printChar
nextW3	btfss winMask, F_PLAYER3_BIT
		goto nextW4
		incf l, f
		movlw '3'
		call lcd_printChar
		movf l, w
		xorwf numWinners, w	;l == numWinners?
		btfsc STATUS, Z
		goto FINALE
		movlw ','
		call lcd_printChar
nextW4	btfss winMask, F_PLAYER4_BIT
		goto FINALE
		movlw '4'
		call lcd_printChar

		

FINALE	movlw Z_GAME_OVER	;Zahlas text "Game over"
		call doSoundFX
		movlw .2
		call waitSecs

		;Kdyz neni vitez, neni komu tleskat
		movf numWinners, f		
		btfss STATUS, Z
		goto cheer			;Mame viteze, doprej mu :)
        movlw .3
		call waitSecs
		goto RESET_GAME

cheer	movlw Z_GAMEOVER_APPLAUSE
		call doSoundFX
		
		movlw .12					;Applaus trva 12secs
		call waitSecs

		goto RESET_GAME




; ********************************************************************
; ********************** BODOVANI HRACU ******************************
; ********************************************************************

vynulujBody
		clrf d1
		clrf d2
		clrf d3
		clrf d4
		return	

;Subrutina naplni failMask byte (XXXX4321)
;Pokud nektery z hracu drzi stlacene tlacitko jeste pred gongem,
;nastavi se odpovidajici bit na 1. Hrac s nastavenym bitem pak nedostane
;bod
findCheaters
		clrf failMask				;vynuluj flagy pro podvodniky

		btfss B_PLAYER1
		goto check2
		bsf failMask, F_PLAYER1_BIT
check2	btfss B_PLAYER2
		goto check3	
		bsf failMask, F_PLAYER2_BIT
check3	btfss B_PLAYER3
		goto check4
		bsf failMask, F_PLAYER3_BIT
check4	btfss B_PLAYER4
		return
		bsf failMask, F_PLAYER4_BIT
		return

;Vyhodnot jednotlive stisky hracu a zjisti viteze kola.
;Timeout na stisk jsou 1.5sec (300cyklu x 5ms), pote nikdo neziskava bod.
evaluateRound
			;Counter = 300 cyklu (300 = 0x012C)
			movlw 0x01
			movwf hiByte
			movlw 0x2C
			movwf loByte

			clrf pressOrder1		;Vyresetuj poradi stisku
			clrf pressOrder2
			clrf pressOrder3
			clrf pressOrder4
				
			clrf pressMask			;Vyresetuj stisky

			movlw .4				;4 hraci
			movwf pressLeft

			movlw 0x20				;Zde je pole 4 bajtu s poradim stisku
			movwf FSR				;Bajty odpovidaji ID hracu (1,2,4,8 -> hrac1,hrac2,hrac3,hrac4)

evalG		movf pressLeft, f		;Stiskli uz vsichni?
			btfsc STATUS, Z
			goto evalPoints			;Kdo vyhral kolo?
			
evalB1		;Zpracuj stisk tlacitka Hrace1
			btfss B_PLAYER1			;Hrac1 stiskl?
			goto evalB2
			btfsc pressMask, F_PLAYER1_BIT
			goto evalB2				;Hrac1 uz stiskl, dalsi stisky ignoruju
			bsf pressMask, F_PLAYER1_BIT	;Zaregistruj stisk Hrac1
			movlw PLAYER1
			movwf INDF				;Hrac1 ulozen do poradi stisku
			incf FSR, F				;Presun se na dalsi volne misto
			decf pressLeft, f		;O jednoho hrace mene, ktery muze stisknout

evalB2
			btfss B_PLAYER2			
			goto evalB3
			btfsc pressMask, F_PLAYER2_BIT
			goto evalB3				
			bsf pressMask, F_PLAYER2_BIT
			movlw PLAYER2
			movwf INDF				
			incf FSR, F				
			decf pressLeft, f		
			
evalB3
			btfss B_PLAYER3			
			goto evalB4
			btfsc pressMask, F_PLAYER3_BIT
			goto evalB4				
			bsf pressMask, F_PLAYER3_BIT
			movlw PLAYER3
			movwf INDF				
			incf FSR, F				
			decf pressLeft, f		

evalB4
			btfss B_PLAYER4			
			goto evalC
			btfsc pressMask, F_PLAYER4_BIT
			goto evalC				
			bsf pressMask, F_PLAYER4_BIT
			movlw PLAYER4
			movwf INDF				
			incf FSR, F				
			decf pressLeft, f		

evalC		movlw .5			;Pockej 5ms
			call waitMilis
			call decHL			;Sniz 16bit counter
			btfss STATUS, Z		;Hotovo?
			goto evalG


evalPoints	;Zjistime kdo vyhral kolo, vratime 0-nikdo,1-hrac1,2-hrac2,....
			btfss pressLeft, 2		;Nikdo nezmacknul, porad hodnota 4
			goto havePress
			clrw
			goto evalFinal
havePress	movf pressOrder1, w		;jedna z hodnot 1,2,4,8 -> hrac1,hrac2....
			andwf failMask,w		;nepodvadel tento hrac?
			btfss STATUS, Z
			goto evalW2
			movf pressOrder1, w
			goto evalFinal
evalW2		movf pressOrder2, w
			andwf failMask, w
			btfss STATUS, Z
			goto evalW3
			movf pressOrder2, w
			goto evalFinal
evalW3		movf pressOrder3, w
			andwf failMask, w
			btfss STATUS, Z
			goto evalW4
			movf pressOrder3, w
			goto evalFinal
evalW4		movf pressOrder4, w
			andwf failMask, w
			btfss STATUS, Z
			clrw
			goto evalFinal
			movf pressOrder4, w

evalFinal	movwf tmp					;W obsahuje kdo vyhral kolo
			andlw PLAYER1
			btfsc STATUS, Z
			goto winner2
			incf d1, f					;Zvys body hrace1
			movlw '1'
			movwf player
			movlw b'01000000'			;Budeme blikat hracem 1
			movwf winLed				;Maska pro PORTB
			movlw T_POINTS_FOR
			goto printRoundWinner
winner2		movf tmp, w
			andlw PLAYER2
			btfsc STATUS, Z
			goto winner3
			incf d2, f
			movlw '2'
			movwf player
			movlw b'00010000'			;Budeme blikat hracem 2
			movwf winLed
			movlw T_POINTS_FOR
			goto printRoundWinner
winner3 	movf tmp, w
			andlw PLAYER3
			btfsc STATUS, Z
			goto winner4
			incf d3, f
			movlw '3'
			movwf player
			movlw b'00000100'			;Budeme blikat hracem 3
			movwf winLed
			movlw T_POINTS_FOR
			goto printRoundWinner
winner4 	movf tmp, w
			andlw PLAYER4
			btfsc STATUS, Z
			goto winnerNobody
			incf d4, f
			movlw '4'
			movwf player
			movlw b'00000001'			;Budeme blikat hracem 4
			movwf winLed
			movlw T_POINTS_FOR
			goto printRoundWinner			
winnerNobody
			movlw 0x80				;0x80 - nevyhral nikdo
			movwf player
			clrf winLed
			movlw T_NO_POINTS
printRoundWinner
			return					;ve W mam cislo textu



;Vyhodnot viteze cele hry a vrat ve winMask bity, ktere oznacuji viteze
;Dolni 4 bity:
;Priklad
;0000 - BEZ VITEZE
;0100 - VITEZI HRAC 3
;1111 - REMIZA VSECH
;1010 - REMIZA 2,4
evaluateWinner
			clrf winMask
			clrf numWinners

			;Nejprve zjistime stav BEZ VITEZE = vsichni 0 bodu
			movf d1, w
			iorwf d2, w
			iorwf d3, w
			iorwf d4, w
			btfss STATUS, Z
			goto findWinners
			return				;vracim vynulovany winMask i numWinners
findWinners	
			;Mame <=4 viteze, zjistime kdo
			;Postup: Nejprve zjistim maximum bodu a zjistim,
			;kteri hraci jej maji. 
			;A) Musim pak odlisit stav == 4 vitezove
			;B) Musim odlisit stav [1,3] vitezove

			;Krok 1) urci maximum hodnot d1,d2,d3,d4
			call findMaximum ;vrati cmpMax s nejvyssi bodovou hodnotou
			;Krok 2) oznac hrace, kteri maji cmpMax bodu
			movf d1, w
			subwf cmpMax, w
			btfss STATUS, Z
			goto chck_d2			
			incf numWinners, f
			bsf winMask, F_PLAYER1_BIT
chck_d2		movf d2, w
			subwf cmpMax, w
			btfss STATUS, Z
			goto chck_d3
			incf numWinners, f
			bsf winMask, F_PLAYER2_BIT
chck_d3		movf d3, w
			subwf cmpMax, w
			btfss STATUS, Z
			goto chck_d4
			incf numWinners, f
			bsf winMask, F_PLAYER3_BIT
chck_d4		movf d4, w
			subwf cmpMax, w
			btfss STATUS, Z
			return
			incf numWinners, f
			bsf winMask, F_PLAYER4_BIT
			return

			
;Najdi maximum z d1, d2, d3, d4 a vrat ho v cmpMax
findMaximum	clrf cmpMax		;max na nule
			movf d1, w		;Prvni hodnota, nastav za MAX
			movwf cmpMax			
		    movf d2, w      
          	subwf cmpMax,w                                                          
	      	btfsc  STATUS,Z		
          	goto equal_d1_d2	
	      	btfss STATUS,C		
          	goto d1_less_d2	
equal_d1_d2	goto test_d3
d1_less_d2	movf d2, w			;d2 je nove maximum
			movwf cmpMax
test_d3		movf d3, w
			subwf cmpMax, w
			btfsc STATUS, Z
			goto equal_d2_d3
			btfss STATUS, C
			goto d2_less_d3
equal_d2_d3 goto test_d4
d2_less_d3	movf d3, w
			movwf cmpMax
test_d4		movf d4, w
			subwf cmpMax, w
			btfsc STATUS, Z
			return				;d4 uz nebude maximum, hotovo
			btfss STATUS, C
			goto d3_less_d4
			return
d3_less_d4	movf d4, w
			movwf cmpMax
			return


;Zjistime, ktery hrac vyhral (podle winMask bitu) a vrat znak '1', '2', '3' nebo '4'
;Urcite alespon 1 vyhral 
getWinnerNumber		
		btfsc winMask, F_PLAYER1_BIT
		retlw '1'
		btfsc winMask, F_PLAYER2_BIT
		retlw '2'
		btfsc winMask, F_PLAYER3_BIT
		retlw '3'
		retlw '4'

			
; ********************************************************************
; *********************** LCD DISPLAY DRIVER *************************
; ********************************************************************

; ***** LCD: I2C: EXPANDER RESET
; posli same nuly

i2c_expanderReset
					call i2c_startCond
					call i2c_sendAddr
					movlw b'00000000'
					call i2c_sendA
					call i2c_stopCond
					return
					
; ***** LCD: I2C: INIT LCD

i2c_lcdInit			
					call wait1s

					call i2c_expanderReset

					movlw .100		;Wait 100ms after reset
					call waitMilis

					movlw LCD_4BIT_INIT ;0x03
					call i2c_sendByte

					;now wait 4.5ms
					movlw .4
					call waitMilis
					call wait150us
					call wait150us	
					call wait150us
					
					movlw LCD_4BIT_INIT
					call i2c_sendByte

					;now wait 150us
					call wait150us

					movlw LCD_4BIT_INIT
					call i2c_sendByte

					;now wait 150us
					call wait150us
					
					movlw b'00100000'	;0x02 - 4bit mode
					call i2c_sendByte

					;now wait 150us
					call wait150us

					;function set (DL=0,N=1,F=0)
					movlw b'00100000'
					call i2c_sendByte
					movlw b'10000000'
					call i2c_sendByte

					;display control
					call lcd_blinkOff

					call lcd_clearDisplay

					;entry mode set (increment, no display shift)
					movlw b'00000000'
					call i2c_sendByte
					movlw b'01100000'
					call i2c_sendByte

					return



; ***** LCD: I2C: CLEAR DISPLAY
lcd_clearDisplay	
					movlw b'00000000'
					call i2c_sendByte
					movlw b'00010000'
					call i2c_sendByte
				    movlw .2
					call waitMilis
					return

; ***** LCD: I2C: HOME
lcd_home		
					movlw b'00000000'
					call i2c_sendByte
					movlw b'00100000'
					call i2c_sendByte
				    movlw .2
					call waitMilis
					return

; ***** LCD: I2C: BLINK OFF
lcd_blinkOff
					;display control(disp ON, cursor OFF, blink OFF)
					movlw b'00000000'
					call i2c_sendByte
					movlw b'11000000'
					call i2c_sendByte
					return

; ***** LCD: I2C: BLINK ON
lcd_blinkOn
					;display control(disp ON, cursor OFF, blink ON)
					movlw b'00000000'
					call i2c_sendByte
					movlw b'11010000'
					call i2c_sendByte
					return

; ***** LCD: I2C: TURN ON BACKLIGHT
lcd_backlightOn
					call i2c_startCond
					call i2c_sendAddr
					movlw b'00001000'
					call i2c_sendA
					call i2c_stopCond
					return

; ***** LCD: I2C: TURN OFF BACKLIGHT
lcd_backlightOff
					movlw b'00000000'
					call i2c_sendByte
					return
					

; ***** LCD: I2C: SEND START CONDITION

i2c_startCond		bsf LCD_SDA
					call wait5us
					bsf LCD_SCL
					call wait5us
					call wait5us
					bcf LCD_SDA
					call wait5us
					call wait5us
					bcf LCD_SCL
					call wait5us
					call wait5us
					return
				
; ***** LCD: I2C: SEND STOP CONDITION

i2c_stopCond		bcf LCD_SDA
					call wait5us
					bsf LCD_SCL
					call wait5us
					call wait5us
					bsf LCD_SDA
					call wait5us
					call wait5us
					return

; ***** LCD: I2C: SEND ADDRESS
i2c_sendAddr		movlw LCD_ADDR_BYTE
					call i2c_sendA
					return

; ***** LCD: I2C: SEND BYTE
; 4bit mode, posilam vsechno 2x, poprve s EN=1 a podruhe s EN=0

i2c_sendByte		movwf i2c_byte

					movlw LCD_EN_MASK			;EN=1 (BF)
					iorwf i2c_byte, f

					movf lcd_backlight, f
					btfsc STATUS, Z
					goto noBL
					movlw LCD_BL_MASK
					iorwf i2c_byte, f			;primaskuj 0000 1000 (BL ON)

noBL				movf lcd_data, f			;0=command, 1=data
					btfsc STATUS, Z
					goto noDATA
					movlw LCD_RS_MASK			;primaskuj 0000 0001 pro data
					iorwf i2c_byte, f
noDATA				;
					call i2c_startCond
					call i2c_sendAddr
					call i2c_send
					call i2c_stopCond

					movlw LCD_EN_MASK_AND		;EN=0 (BF)
					andwf i2c_byte, f

					call i2c_startCond
					call i2c_sendAddr
					call i2c_send
					call i2c_stopCond
					return					

; ***** LCD: I2C: SEND

i2c_send			movf i2c_byte, w
i2c_sendA			movwf tmp

					movlw .8
					movwf i
		
i2c_cycle			btfss tmp, 7		
					goto i2c_bitNotSet
					bcf LCD_SCL			;Abych mel hrany co nejbliz u sebe
					bsf LCD_SDA		
					nop
					goto i2c_tested
i2c_bitNotSet 		bcf LCD_SCL
					bcf LCD_SDA	
					nop
					nop	
					nop
i2c_tested			call wait5us
		
					bsf LCD_SCL		
					nop
					nop                    

					rlf tmp, f
					decfsz i, f
					goto i2c_cycle

					nop
					nop
					nop
					nop

					;ACK BIT
					bcf LCD_SCL
					bcf LCD_SDA					
					call wait5us
					nop
					nop
					nop
					bsf LCD_SCL
					call wait5us
					nop
					nop
					nop
					nop
					bcf LCD_SCL
					call wait5us
					return	


; ***** LCD: PRINT CHAR
;Vypis 1 znak na aktualni pozici na displeji
lcd_printChar
			movwf tmpByte

			movlw TRUE
			movwf lcd_data			;ted posilam znaky = DATA

			;ted mam cely bajt s kodem znaku, musim to posilat po nibblech,
			;nejprve horni a pak dolni, vzdy v hornich 4 bitech
			movlw b'11110000'		; Vynuluju dolni 4 bity
			andwf tmpByte, w
			call i2c_sendByte
			swapf tmpByte, f		; Dolni 4 bity <-> horni 4 bity
			movlw b'11110000'
			andwf tmpByte, w
			call i2c_sendByte
			clrf lcd_data			;kdybych mezitim posilal command
			return


; ***** LCD: ZOBRAZ VYBRANY (numText) TEXT
lcd_printText
				movwf numText

				movlw FALSE
				movwf lcd_data			;nejprve posli commandy

;				call lcd_clearDisplay
;				call lcd_home
;				call lcd_backlightOn
				call lcd_processText
				call lcd_blinkOn
				return	

; **** LCD: I2C: WRITE TEXT
; 1. byte - column
; 2. byte - row
; 3. byte - znak1
; 4. byte - znak2
; ...
; 0x00	  - konec stringu

lcd_processText	movlw TRUE
				movwf lcd_backlight
						
				clrf k

				movf k, w				
				call textSelect			;ziskej column, kam pujde cursor
				call i2c_sendByte
				incf k, f				;ziskej row a incrementuj index
				movf k, w
				call textSelect
				call i2c_sendByte

				movlw TRUE
				movwf lcd_data			;ted posilam znaky = DATA

processCycle	incf k, f
				movf k, w
				call textSelect
				movwf tmpByte				;ulozim cely kod znaku
				movf tmpByte, f				;mame konec stringu? (0x00)
				btfsc STATUS, Z
				goto processFin
				;ted mam cely bajt s kodem znaku, musim to posilat po nibblech,
				;nejprve horni a pak dolni, vzdy v hornich 4 bitech
				movlw b'11110000'		; Vynuluju dolni 4 bity
				andwf tmpByte, w
				call i2c_sendByte
				swapf tmpByte, f		; Dolni 4 bity <-> horni 4 bity
				movlw b'11110000'
				andwf tmpByte, w
				call i2c_sendByte

				goto processCycle
							
processFin		clrf lcd_data				;kdybych mezitim posilal command
				return

; ***** INTRO LED POBLIKAVANI
; Musime trvat 7secs nez dohraje fanfara

introLightFX	
		call blik1				;(1.5 secs)
		call wait1s				;(1 sec)
		call blik2				;(1.5 secs)
		call wait1s				;(1 sec)
		call blik3				;(2secs)
		return


blik1
		;3x Zablikej vsemi 4 hraci (1.5secs)
		movlw .3
		movwf j

blik1L	movlw b'01010101'
		movwf PORTB
		call wait250ms
		movlw b'00000000'
		movwf PORTB
		call wait250ms
		decfsz j, f
		goto blik1L
		return


blik2
		;Zablikej dokola 1,3,4,2 3x po sobe (1.5secs)

		movlw .3
		movwf j
blik2L	bsf L_PLAYER1
		call wait125ms
		bcf L_PLAYER1
		bsf L_PLAYER3
		call wait125ms
		bcf L_PLAYER3
		bsf L_PLAYER4
		call wait125ms
		bcf L_PLAYER4
		bsf L_PLAYER2
		call wait125ms
		bcf L_PLAYER2
		decfsz j, f
		goto blik2L
		return


blik3	;Zablikej do krize 1,4 a 2,3
		
		movlw .4
		movwf j

blik3L	movlw b'01000001'
		movwf PORTB
		call wait250ms
		movlw b'00010100'
		movwf PORTB
		call wait250ms
		decfsz j, f
		goto blik3L
		clrf PORTB
		return		
	

blikWinner
;Ve winLed mam masku pro PORTB, zablikam viteze kola
		movlw .4
		movwf j
blikW	movf winLed, w
		movwf PORTB
		call wait250ms
		clrf PORTB
		call wait250ms
		decfsz j, f
		goto blikW
		return

; ***** WT588D: SUBRUTINA NA POSLANI PRIKAZU, cislo zvuku je v numSound

doSoundFX
		movwf numSound
		movf numSound, w
		movwf tmp

		movlw .5
		call waitMilis

		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 bitNotSet
		bsf S_SDA		 ; ano, posli log 1
		goto tested
bitNotSet bcf S_SDA		; ne, posli log 0 na vystup
tested	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



; *** SUBRUTINA, CEKEJ 150us 
wait150us 	call wait30us
			call wait30us
			call wait30us
			call wait30us
			call wait30us
			return

; *** SUBRUTINA, CEKEJ 30us (=30 jednotaktovych instrukci)

wait30us	nop		;26, 2 na zacatku sezere volani call
			nop
			nop
			nop
			nop
		 	nop
			nop
			nop
			nop
			nop
wait20us	nop
			nop
			nop
			nop
			nop
		 	nop
			nop
			nop
			nop
			nop
wait10us	nop
			nop
			nop
			nop
			nop
wait5us	 	nop
			return;		ta je za 2 cykly


; *** 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

wait150ms
		movlw .150
		goto waitMilis
		
; *** SUBRUTINA, CEKEJ 10ms ******************************************

; Delay = 0.01 seconds
; Clock frequency = 4 MHz

; Actual delay = 0.01 seconds = 10000 cycles
; Error = 0 %

wait10ms
			;9993 cycles
	movlw	0xCE
	movwf	del1
	movlw	0x08
	movwf	del2
wait10ms_0
	decfsz	del1, f
	goto	$+2
	decfsz	del2, f
	goto	wait10ms_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return
	

; Delay = 0.001 seconds
; Clock frequency = 4 MHz

; Actual delay = 0.001 seconds = 1000 cycles
; Error = 0 %

wait1ms
			;993 cycles
	movlw	0xC6
	movwf	del1
	movlw	0x01
	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 = 4 MHz

; Actual delay = 1 seconds = 1000000 cycles
; Error = 0 %

wait1s
			;999990 cycles
	movlw	0x07
	movwf	del1
	movlw	0x2F
	movwf	del2
	movlw	0x03
	movwf	del3
wait1s_0
	decfsz	del1, f
	goto	$+2
	decfsz	del2, f
	goto	$+2
	decfsz	del3, f
	goto	wait1s_0

			;6 cycles
	goto	$+1
	goto	$+1
	goto	$+1

			;4 cycles (including call)
	return


; Delay = 0.5 seconds
; Clock frequency = 4 MHz

; Actual delay = 0.5 seconds = 500000 cycles
; Error = 0 %

wait500ms
			;499994 cycles
	movlw	0x03
	movwf	del1
	movlw	0x18
	movwf	del2
	movlw	0x02
	movwf	del3
wait500ms_0
	decfsz	del1, f
	goto	$+2
	decfsz	del2, f
	goto	$+2
	decfsz	del3, f
	goto	wait500ms_0

			;2 cycles
	goto	$+1

			;4 cycles (including call)
	return


; Delay = 0.25 seconds
; Clock frequency = 4 MHz

; Actual delay = 0.25 seconds = 250000 cycles
; Error = 0 %

wait250ms
			;249993 cycles
	movlw	0x4E
	movwf	del1
	movlw	0xC4
	movwf	del2
wait250ms_0
	decfsz	del1, f
	goto	$+2
	decfsz	del2, f
	goto	wait250ms_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return


; Delay = 0.125 seconds
; Clock frequency = 4 MHz

; Actual delay = 0.125 seconds = 125000 cycles
; Error = 0 %


wait125ms
			;124993 cycles
	movlw	0xA6
	movwf	del1
	movlw	0x62
	movwf	del2
wait125ms_0
	decfsz	del1, f
	goto	$+2
	decfsz	del2, f
	goto	wait125ms_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return
	
; Wait random (2.5secs - 5.5secs)
;Podle hodnoty TMR0 pockej
;1) vezmi bity 0 a 1 - z nich poskladam 0, 1, 2, 3 dec
;2) prictu 2ku a pockam $vysledek sekund
;3) zjisti bit 2 TMR0
;4) If set, wait dalsich 450ms
;5) else    wait dalsich 150ms
waitRandom
		movf TMR0, w
		andlw b'00000011'
		addlw .3 ;2 + 1 pro cyklus
		movwf i
waitR	decfsz i, f
		goto wNonZero
		goto nextWaitR
wNonZero call wait1s
		 goto waitR
nextWaitR
		btfss TMR0, 2
		goto wNotSet
		call wait150ms
		call wait150ms
wNotSet call wait150ms
		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
	movf nonZeroByte, f ;Potrebuju vynulovat Zero (aby mi pri lo/hi 0/1 predchozi decf Z nenastavil)
	return


; *** ROUTINA NA ZOBRAZOVANI CISLIC NA LED DISPLEJI ****************	
zobraz
;1)Zjisti, kterou z cislic mam rozsvitit
;2)Zjisti, ktere segmenty na dane pozici vysvitit
;3)Posun se na dalsi pozici
	
;Krok 1 a 3)
	
	;vse vypni
	bcf A_FIRST
	bcf A_SECOND
	bcf A_THIRD
	bcf A_FOURTH
	bcf BCD_A
	bcf BCD_B
	bcf BCD_C
	bcf BCD_D

	btfss d, 0    ;Mame prvni cislici?
	goto sec
;DRIVE1
	bsf A_FIRST
    movf d1, w
    movwf d_temp    ;Hodnota (0-9), kterou budeme na segmentech dane cislice zobrazovat
    movlw W_SECOND;	
	goto step3
sec	btfss d, 1    ;Mame druhou cislici?
	goto third
;DRIVE2	
	bsf A_SECOND
    movf d2, w
    movwf d_temp;    
    movlw W_THIRD;
	goto step3
third	
	btfss d, 2
	goto fourth
;DRIVE3
	bsf A_THIRD
    movf d3, w
    movwf d_temp;    
    movlw W_FOURTH;
	goto step3
fourth
;DRIVE4
	bsf A_FOURTH
    movf d4, w
    movwf d_temp;    
    movlw W_FIRST;
step3	movwf d;	  ;Nastav dalsi cislici v poradi
	
step2
;Krok 2) - v d_temp mam hodnotu aktualne zobrazovaneho cisla
	incf d_temp,f			;0-9 -> 1-10 to d_temp	
	decfsz d_temp, f		;mame 0
	goto next1
	return					;vse je defaultne clearnute, takze staci jen bsf
next1						;mame 1
	decfsz d_temp, f
	goto next2
	bsf BCD_A
	return
next2						;mame 2
	decfsz d_temp, f
	goto next3
	bsf BCD_B
 	return
next3						;mame 3
	decfsz d_temp, f
	goto next4
	bsf BCD_A
	bsf BCD_B
	return
next4						;mame 4
	decfsz d_temp, f
	goto next5
	bsf BCD_C
	return
next5						;mame 5
	decfsz d_temp, f
	goto next6
	bsf BCD_A
	bsf BCD_C
	return
next6						;mame 6
	decfsz d_temp, f
	goto next7
	bsf BCD_B
	bsf BCD_C
	return
next7						;mame 7
	decfsz d_temp, f
	goto next8
	bsf BCD_A
	bsf BCD_B
	bsf BCD_C
	return
next8						;mame 8
	decfsz d_temp, f
	goto next9
	bsf BCD_D
	return
next9						;mame 9
	bsf BCD_A
	bsf BCD_D
	return

; **********************************************************************
; ***** TABULKY S TEXTY PRO LCD DISPLEJ
; **********************************************************************	

				org 0x0400

; ***** podle numText nasmeruj na spravna data pro string
textSelect		movwf index			;uloz pozici do textu
				movf numText, w
				movwf numTextSaved	;Bude se potrebovat znovu na dalsi volani				
				addlw .246			;>9? Ano, jdi do dalsi tabulky
				btfsc STATUS, C
				goto texty2
				movlw HIGH Table_texty
				movwf PCLATH
				goto textNext
texty2			movlw HIGH Table_texty2
				movwf PCLATH
textNext		movf numTextSaved, f	;0?
				btfss STATUS, Z
				goto nextT1
				movf index, w
				goto text0
nextT1			decfsz numTextSaved, f	;1?
				goto nextT2
				movf index,w
				goto text1
nextT2			decfsz numTextSaved, f	;2?
				goto nextT3
				movf index, w
				goto text2
nextT3			decfsz numTextSaved, f	;3?
				goto nextT4
				movf index, w
				goto text3
nextT4			decfsz numTextSaved, f	;4?
				goto nextT5
				movf index, w
				goto text4
nextT5			decfsz numTextSaved, f	;5?
				goto nextT6
				movf index, w
				goto text5
nextT6			decfsz numTextSaved, f	;6?
				goto nextT7
				movf index, w
				goto text6
nextT7			decfsz numTextSaved, f	;7?
				goto nextT8
				movf index, w
				goto text7
nextT8			decfsz numTextSaved, f	;8?
				goto nextT9
				movf index, w
				goto text8
nextT9			decfsz numTextSaved, f	;9?
				goto nextT10
				movf index, w
				goto text9
nextT10			decfsz numTextSaved, f	;10?
				goto nextT11
				movf index, w
				goto text10
nextT11			movf index, w			;11				
				goto text11

Table_texty
				;" Stiskni START!"
text0			addwf PCL,F ;add offset to pc to
				dt 0x80, 0x00		;Pozice na displeji 0,0 (0x80 = command na cursor set)
				dt " Stiskni START!"
				dt 0x00

				;"Bod pro hrace "
text1			addwf PCL,F ;add offset to pc to
				dt 0xC0, 0x00		;Pozice 2,0 (pocitano od 0)
				dt "Bod pro hrace "
				dt 0x00

				;"Nikdo neboduje!"
text2			addwf PCL,F ;add offset to pc to
				dt 0xC0, 0x00		;Pozice 2,0 (pocitano od 0)
				dt "Nikdo neboduje! "
				dt 0x00

				;"Rychlovka 1.0"
text3			addwf PCL,F ;add offset to pc to
				dt 0x80, 0x00		;Pozice 0,0 (pocitano od 0)
				dt "  ReAxion v1.0  "
				dt 0x00

				;"** KONEC HRY! **"
text4			addwf PCL,F ;add offset to pc to
				dt 0x80, 0x00		;Pozice 0,0 (pocitano od 0)
				dt "** KONEC HRY! **"
				dt 0x00

				;"** BEZ VITEZE **"
text5			addwf PCL,F ;add offset to pc to
				dt 0xC0, 0x00		;Pozice 2,0 (pocitano od 0)
				dt "** BEZ VITEZE **"
				dt 0x00

				;"ZVITEZIL HRAC "
text6			addwf PCL,F ;add offset to pc to
				dt 0xC0, 0x00		;Pozice 2,0 (pocitano od 0)
				dt " VYHRAVA HRAC "
				dt 0x00

				;"   KOLO c. "
text7			addwf PCL,F ;add offset to pc to
				dt 0x80, 0x00		;Pozice 0,0 (pocitano od 0)
				dt "   KOLO c. "
				dt 0x00

text8			;" Pripravit se..."
				addwf PCL, F
				dt 0xC0, 0x00		;Pozice 2,0 (pocitano od 0)
				dt " Pripravte se..."
				dt 0x00

text9			;" H R A J E M E!"
				addwf PCL, F
				dt 0xC0, 0x00		;Pozice 2,0 (pocitano od 0)
				dt " H R A J E M E! "
				dt 0x00


				;NUTNO POSUNOUT NA 0x0500
				org 0x0500
Table_texty2

text10			;"REMIZA VSECH :-)" - nezvitezil nikdo, vsichni >0 bodu
				addwf PCL, F
				dt 0xC0, 0x00		;Pozice 2,0 (pocitano od 0)
				dt "REMIZA VSECH :-)"
				dt 0x00

text11			;"REMIZA " - zvitezilo vice hracu
				addwf PCL, F
				dt 0xC0, 0x00		;Pozice 2,0 (pocitano od 0)
				dt "  REMIZA "
				dt 0x00
			
	
; *** KONEC SOUBORU *************************************************	
	end