; 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
    ;{
	    
	d1		;registry pro cekaci subrutiny
	d2
	d3
	i
	j
	k
	tmp
	tmp2
	
	hiByte
	loByte	
	
	numMilis			;Kolik cyklu wait1ms zavolat
	numSecs				;Kolik cyklu wait1s zavolat		
	dataPointer:.2		;pozice v grafickych datech
	textPointer:.2  	;pozice v textu
	
	GAME_player1Score	;0-10
	GAME_player2Score	;0-10
	GAME_fobNumber		;Ktery fob (1-10) nalezen?
	GAME_fobPlayer		;Ktereho hrace je fob? 0-Player1, 1-Player2
	GAME_found			;Prepinac na jedno pouziti (emptyCircle, fullCircle)
	GAME_isGameOver		;Nekdo ma nalezeno vse?	
	GAME_winner			;Vitez 0-player1, 1-player2, FF-init
	
	EEPROM_addr			;PIC EEPROM	(nutne mit na adrese >0x70)???
	EEPROM_value	
	
	
	;WT588D player
	
	WT588D_i
	WT588D_tmp	
	
	;ST7735 TFT display variables
	
	TFT_i				;TFT_WriteByte
	TFT_word:.2	
	TFT_tmp
	TFT_byte
	TFT_X				;Pozice pro display window
	TFT_X_MAX
	TFT_Y
	TFT_Y_copy			;TFT_drawText
	TFT_Y_MAX
	TFT_pieceFGColor:.2
	TFT_pieceBGColor:.2
	TFT_dataLen			;Pocet bytes graficky dat pro vykresleni	
	TFT_whichFont		;0-8x16, 1-8x9
	TFT_charWidth		;Vykreslovani fontu
	TFT_charHeight
	TFT_putChar			;Vykreslujeme pouze 1 znak, 0-ne, 1-ano
	

	;MFRC522 variables
	
	UID_size
	UID_byte:.5			;PICC UID 4 bytes + BCC 1 byte (XOR)
	UID_sak
	
	SPI_value		
	
	mfrc522_hiByte
	mfrc522_loByte	
	mfrc522_atqa:.2		;ATQA response, 2 bytes
	mfrc522_bitFraming
	mfrc522_bufferSize	;number of bytes received from PICC	
	mfrc522_command
	mfrc522_errorRegValue
	mfrc522_i
	mfrc522_index		;pointer do mfrc522_IN_byteArray		
	mfrc522_j	
	mfrc522_hi
	mfrc522_lo	
	mfrc522_mask
	mfrc522_register
	mfrc522_result
	mfrc522_status
	mfrc522_tmp
	mfrc522_txLastBits
	mfrc522_validBits
	mfrc522_validBits2
	mfrc522_value
	mfrc522_waitIRq
	mfrc522_OUT_bytesCount		;FIFO output buffer
	mfrc522_OUT_index
	mfrc522_OUT_offset
	mfrc522_IN_bytesCount		;FIFO input buffer
	mfrc522_IN_offset
	mfrc522_rxAlign				;default = 0
	mfrc522_checkCRC			;default = FALSE	
	mfrc522_uidComplete
	mfrc522_cascadeLevel
	mfrc522_useCascadeTag
	mfrc522_uidIndex
	mfrc522_currentLevelKnownBits
	mfrc522_selectDone
	mfrc522_count	
    endc
    
    ;BANK1 - co se nevlezlo
	cblock 0x0A0
    	GAME_foundPlayer1: .10		;Co uz bylo nalezeno Player1
    	GAME_foundPlayer2: .10		;Co uz bylo nalezeno Player2	
    	mfrc522_OUT_byteArray:.10	;FIFO output buffer
    	mfrc522_IN_byteArray:.10	;FIFO input buffer
    endc
    
    ;BANK2 - UIDs
    cblock 0x120
    	UIDs: .80			;10 x 4B - RED, 10 x 4B - BLUE
    endc
    
    ;}
    
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; D E F I N E S ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
       
;{
;TFT 1.8" ST7735
#define TFT_SCK				PORTB, RB7;		(OUTPUT)
#define TFT_MOSI			PORTB, RB6;		(OUTPUT)
#define TFT_DC				PORTB, RB5;		(OUTPUT)
#define TFT_RESET			PORTB, RB4;		(OUTPUT)
#define TFT_CS				PORTB, RB3;		(OUTPUT)

;MFRC522 SPI 
#define MFRC522_MISO		PORTC, RC4;		SPI SDI (INPUT)
#define MFRC522_MOSI		PORTC, RC5;		SPI SDO (OUTPUT)
#define MFRC522_CLK			PORTC, RC3;		SPI SCK (OUTPUT)
#define MFRC522_CS			PORTC, RC6;		SPI CS  (OUTPUT)

#define MFRC522_UID_SIZE			.4		;4 bajty

#define GAME_PLAYER1				.0
#define GAME_PLAYER2				.1
#define GAME_FOBS_COUNT				.10

#define FONT_8x16					.0
#define FONT_8x16_CHAR_HEIGHT		.16		;8x16 = 1 znak
#define FONT_8x16_CHAR_WIDTH		.8

#define FONT_8x9					.1
#define FONT_8x9_CHAR_HEIGHT		.9
#define FONT_8x9_CHAR_WIDTH			.8
#define FONT_8x9_FOB_OFFSET			.4		;4px dolu doprava od leveho horniho rohu kruhu

#define GFX_FOB_SIZE				.16		;kruh 16x16px
#define GFX_FOBS_P1_Y_OFFSET		.50		;Y pro levy horni roh, player1
#define GFX_FOBS_P2_Y_OFFSET		.88		;Y pro levy horni roh, player2

;MFRC522 registers
#define CommandReg			0x01 << 1
#define ModWidthReg 		0x24 << 1	; controls the ModWidth setting?
#define	TxModeReg			0x12 << 1	; defines transmission data rate and framing
#define RxModeReg 			0x13 << 1	; defines reception data rate and framing
#define ComIrqReg			0x04 << 1	; interrupt request bits
#define ErrorReg			0x06 << 1	; error bits showing the error status of the last command executed 
#define	FIFODataReg			0x09 << 1	; input and output of 64 byte FIFO buffer
#define	FIFOLevelReg		0x0A << 1	; number of bytes stored in the FIFO buffer
#define	ControlReg			0x0C << 1	; miscellaneous control registers
#define	BitFramingReg		0x0D << 1	; adjustments for bit-oriented frames	
#define CollReg				0x0E << 1	; bit position of the first bit-collision detected on the RF interface
#define TModeReg			0x2A << 1	; defines settings for the internal timer
#define	TPrescalerReg		0x2B << 1	; the lower 8 bits of the TPrescaler value. The 4 high bits are in TModeReg.		
#define TReloadRegH			0x2C << 1	; defines the 16-bit timer reload value
#define	TReloadRegL			0x2D << 1
#define TxASKReg			0x15 << 1	; controls the setting of the transmission modulation			
#define ModeReg				0x11 << 1	; defines general modes for transmitting and receiving 
#define TxControlReg		0x14 << 1	; controls the logical behavior of the antenna driver pins TX1 and TX2

;MFRC522 commands
#define PCD_SoftReset		0x0F		; resets the MFRC522
#define PCD_Transceive 		0x0C		; transmits data from FIFO buffer to antenna and automatically activates the receiver after transmission
#define PCD_Idle			0x00		; no action, cancels current command execution
#define PICC_CMD_REQA		0x26		; REQuest command, Type A. Invites PICCs in state IDLE to go to READY and prepare for anticollision or selection. 7 bit frame.
#define PICC_CMD_SEL_CL1	0x93		; Anti collision/Select, Cascade Level 1
#define PICC_CMD_CT			0x88		; Cascade Tag. Not really a command, but used during anti collision.

;TFT 1.8" ST7735 defines
#define TFT_WIDTH			.160		;LCD w
#define TFT_HEIGHT			.128		;LCD h

;WT588D   
#define WT588D_SCK			PORTC, RC0;
#define WT588D_CS			PORTC, RC1;
#define WT588D_SDA			PORTC, RC2;

#define BUTTON_START		PORTA, RA0;

#define ST7735_NOP     		0x00
#define ST7735_SWRESET 		0x01
#define ST7735_RDDID   		0x04
#define ST7735_RDDST   		0x09
#define ST7735_SLPIN   		0x10
#define ST7735_SLPOUT  		0x11
#define ST7735_PTLON   		0x12
#define ST7735_NORON   		0x13
#define ST7735_INVOFF  		0x20
#define ST7735_INVON   		0x21
#define ST7735_DISPOFF 		0x28
#define ST7735_DISPON  		0x29
#define ST7735_CASET   		0x2A
#define ST7735_RASET   		0x2B
#define ST7735_RAMWR   		0x2C
#define ST7735_RAMRD   		0x2E
#define ST7735_PTLAR   		0x30
#define ST7735_VSCRDEF 		0x33
#define ST7735_COLMOD  		0x3A
#define ST7735_MADCTL  		0x36
#define ST7735_VSCRSADD 	0x37
#define ST7735_FRMCTR1 		0xB1
#define ST7735_FRMCTR2 		0xB2
#define ST7735_FRMCTR3 		0xB3
#define ST7735_INVCTR  		0xB4
#define ST7735_DISSET5 		0xB6
#define ST7735_PWCTR1  		0xC0
#define ST7735_PWCTR2  		0xC1
#define ST7735_PWCTR3  		0xC2
#define ST7735_PWCTR4  		0xC3
#define ST7735_PWCTR5  		0xC4
#define ST7735_VMCTR1  		0xC5
#define ST7735_RDID1   		0xDA
#define ST7735_RDID2   		0xDB
#define ST7735_RDID3   		0xDC
#define ST7735_RDID4   		0xDD
#define ST7735_PWCTR6  		0xFC
#define ST7735_GMCTRP1 		0xE0
#define ST7735_GMCTRN1 		0xE1
;Color definitions
#define ST7735_BLACK   		0x0000
#define ST7735_DARKBLUE    	0x00CF
#define ST7735_BLUE    		0x001F
#define ST7735_RED     		0xF800
#define ST7735_RED2			0xE041
#define ST7735_GREEN   		0x07A0
#define ST7735_CYAN    		0x07FF
#define ST7735_MAGENTA 		0xF81F
#define ST7735_YELLOW  		0xFFE0
#define ST7735_WHITE   		0xFFFF
;}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;; C O N S T A N T S ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;{
	
FALSE					equ 0x00
TRUE					equ 0x01 
	
STATUS_OK				equ 0x00	; Success
STATUS_ERROR			equ 0x01	; Error in communication
STATUS_COLLISION		equ 0x02	; Collision detected
STATUS_TIMEOUT			equ 0x03	; Timeout in communication.
STATUS_NO_ROOM			equ 0x04	; A buffer is not big enough.
STATUS_INTERNAL_ERROR	equ 0x05	; Internal error in the code. Should not happen ;-)
STATUS_INVALID			equ 0x06	; Invalid argument.
STATUS_CRC_WRONG		equ 0x07	; The CRC_A does not match
STATUS_XOR_WRONG		equ 0x08	; My custom error (BCC wrong)
STATUS_MIFARE_NACK		equ 0xff	; A MIFARE PICC responded with NAK.


;WT588D
SOUND_00_INTRO_INDY			equ 0x00
SOUND_01_INGAME_MAJOR		equ 0x01
SOUND_02_CASH_FOUND			equ 0x02
SOUND_03_GAME_OVER1			equ 0x03
SOUND_04_GAME_OVER2			equ 0x04
SOUND_05_WINNER_IS			equ 0x05
SOUND_06_PLAYER1			equ 0x06
SOUND_07_PLAYER2			equ 0x07
SOUND_08_APPLAUSE			equ 0x08

;}

 
;{
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
	
; *********************************************************************
; ************************** M A I N **********************************
; *********************************************************************

MAIN
;{
	clrwdt	
	
	;8MHz
	BANK1
	movlw b'01110100'
	movwf OSCCON
	
	movlw b'11001000'
	movwf OPTION_REG

	;*** PORTA NASTAVENI - NIC ***
	BANK3
	clrf ANSEL
	clrf ANSELH
	clrf CM1CON0
	clrf CM2CON0
	
	BANK1	
	movlw b'00000001'
	movwf TRISA

	BANK0 	
	clrf PORTA
	
	;*** PORTB NASTAVENI - LCD1602 ***
	
	BANK1	
	clrf TRISB		 	;Vse output
	clrf IOCB		 	;Interrupt onChange disabled
	clrf WPUB
	BANK0
	clrf PORTB   

	;*** PORTC NASTAVENI - MFRC522 ***
	
	BANK1
	movlw b'00010000'	; RC4-MISO MFRC522
	movwf TRISC	
	BANK0
	
	clrf CCP1CON 		; Turn CCP module off	
	clrf PORTC	
		
	;MFRC522 SPI setup
	bsf MFRC522_CS
	clrf SSPCON  		; Inicializace MSSP modulu
	movlw b'00100000'	; 00, SSPEN=1,CKP=0, 0000 SPI Master Mode = FOSC/4	
	movwf SSPCON
	
	BANK1
	clrf SSPSTAT
  	movlw b'11000000'	; set up spi port, SPI master,
	movwf SSPSTAT		; CKE = 1 (mode 0,0, SPI Mode 0)
	
	BANK0
	
	;WT588D				;Nastav SCK a CS na log. 1
	bsf WT588D_SCK		;Pro WT588D
	bsf WT588D_CS	
	
;}
	
; *********************************************************************
; ************************** M A I N   I N I T ************************
; *********************************************************************

MAIN_Init
;{

	call EEPROM_ReadUIDs	
		
	call MFRC522_PCD_Init
	
	call TFT_Init		

	call TFT_ClearScreen	
	
	call TFT_DrawLogo
	
	call WT588D_playIntroSound

MAIN_Loop

	call TFT_DrawLogo

	call GAME_Init
	
	call TFT_DrawFobs

	;Zobraz texty
	call TFT_SetFont8x16

	call TFT_ShowPlayer1
	
	call TFT_ShowPlayer2		
	
	call TFT_ShowPressStart	
	
	call GAME_Wait4ButtonPress		
	
	call TFT_ShowFindAllFobs
	
	call WT588D_playIngameSound

;}	
	
; *********************************************************************
; ************************* M A I N   L O O P *************************
; *********************************************************************	

	
MAIN_CardLoop
	
	call MFRC522_PICC_IsNewCardPresent

	;mfrc522_status
	;0-SUCCESS (card present)
	;1-NO CARD READ	
	
	;call TFT_PrintStatus
	
	;movlw .100
	;call waitMilis
	
	movf mfrc522_status, f
	btfss STATUS, Z				
	goto MAIN_CardLoop
	
	call MFRC522_PICC_Select

	;call TFT_PrintStatus    ;DEBUG
	
	movf mfrc522_status, f		;0-OK, jinak error
	btfsc STATUS, Z
	goto MAIN_CardFound	
	goto MAIN_CardLoop
	
	;call TFT_PrintUID
	;call wait1s
	
MAIN_CardFound	
	
	;call TFT_PrintUID			; DEBUG
	;call TFT_PrintStatus    	; DEBUG
	
	call GAME_CheckUID
	movf GAME_fobNumber, f		; mame nalez? 0-ne, != 0 ano
	btfsc STATUS, Z
	goto MAIN_CardLoop			;Zadny nalez, nacti dalsi fob
		
	call TFT_DrawFobFound		;Jinak zobraz nalez a zpracuj ho
	
	call GAME_UpdateScoreAndFound	; updatuj score a zjisti, je-li konec hry
	btfss GAME_isGameOver, 0
	goto MAIN_CardLoop
	
	call TFT_SetFont8x16		;nutne, vypisovali jsme cisla fobu
	
	;Nech jeste dohrat posledni cinknuti pokladny
	movlw .250
	call waitMilis
	
	call wait1s
	
	call WT588D_playGameOverMusic
	
	call TFT_ShowGameOver
	
	call WT588D_playGameOverSpeech
	
	call WT588D_playWinnerIs
	
	call TFT_ShowWinner
	
	call WT588d_playWinner	
	
	goto MAIN_Loop
					
	;call MFRC522_ClearUID
	;call TFT_PrintUID	


; *********************************************************************
; ************************ W T 5 8 8 D ********************************
; *********************************************************************

WT588D_playIntroSound
;{
	movlw SOUND_00_INTRO_INDY
	goto WT588D_doSoundFX
;}

WT588D_playIngameSound
;{
	movlw SOUND_01_INGAME_MAJOR
	call WT588D_doSoundFX	
	movlw .30
	call waitMilis
	movlw 0xF2			;loop aktualne prehravaneho zvuku
	goto WT588D_doSoundFX
;}

WT588D_playFoundSound
;{
	movlw SOUND_02_CASH_FOUND
	goto WT588D_doSoundFX
;}

WT588D_playGameOverMusic
;{
	movlw SOUND_03_GAME_OVER1
	call WT588D_doSoundFX
	movlw .2
	goto waitSecs
;}

WT588D_playGameOverSpeech
;{
	movlw SOUND_04_GAME_OVER2
	call WT588D_doSoundFX
	movlw .2
	goto waitSecs
;}

WT588D_playWinnerIs
;{
	movlw SOUND_05_WINNER_IS
	call WT588D_doSoundFX
	movlw .2
	goto waitSecs
;}

WT588d_playWinner
;{
	movlw SOUND_07_PLAYER2
	btfss GAME_winner, 0
	movlw SOUND_06_PLAYER1
	call WT588D_doSoundFX
	movlw .2
	call waitSecs

	;aplaus
	movlw SOUND_08_APPLAUSE
	call WT588D_doSoundFX
	
	movlw .11
	goto waitSecs
;}

WT588D_doSoundFX
;{
		movwf WT588D_tmp
	
		;Nastav SCK a CS na log. 1
		movlw b'00000011'		;SCK log. 1, CS log. 1
		movwf PORTC
		
		movlw .17
		call waitMilis
		
		movlw b'00000001'		;SCK log. 1, CS log. 0
		movwf PORTC				;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 WT588D_i
		
cycle	bcf WT588D_SCK		;Clock na log. 0, zaciname prenos dat			

		btfss WT588D_tmp, 0;  bit 0 nastaven?
		goto btNotSet
		bsf WT588D_SDA		 ; ano, posli log 1
		goto tsted
btNotSet bcf WT588D_SDA		; ne, posli log 0 na vystup
tsted	call WT588D_wait30us

		bsf WT588D_SCK		;Clock na log. 1, skoncili jsme prenos 1 bitu	
		call WT588D_wait30us

		rrf WT588D_tmp, f
		decfsz WT588D_i, f
		goto cycle

		movlw b'00000011'	;SDA log. 0, CS log. 1, SCK log. 1
		movwf PORTC			;Slave Select = HI

		return
;}


WT588D_wait30us
;{
			;55 cycles
	movlw	0x12
	movwf	d1
wait30us_0
	decfsz	d1, f
	goto	wait30us_0

			;1 cycle
	nop

			;4 cycles (including call)
	return
;}

; *********************************************************************
; *********************** H E R N I   R U T I N Y *********************
; *********************************************************************

;Cekej, dokud se nestiskne tlacitko
GAME_Wait4ButtonPress
;{
	btfsc BUTTON_START
	return
	goto GAME_Wait4ButtonPress
;}


;Inicializu herni promenne
GAME_Init
;{
	movlw FALSE
	movwf GAME_isGameOver
	
	clrf GAME_player1Score		;Pocet nalezenych
	clrf GAME_player2Score
	
	movlw 0xFF
	movwf GAME_winner
	
	movlw GAME_foundPlayer1
	movwf FSR
	
	movlw GAME_FOBS_COUNT * .2 ; 2 hraci
	movwf i
GAME_InitLoop
	clrf INDF
	incf FSR, f
	decfsz i, f
	goto GAME_InitLoop
	return
;}

;Pri nalezu uprav score a pole nalezencu
;Vstup: GAME_fobNumber (1-10)
;Vstup: GAME_fobPlayer
;Vystup: GAME_isGameOver pokud ma nektery z hracu score 10
;Vystup: GAME_winner = 0 (player1) nebo = 1 (player2), pokud GAME_isGameOver = TRUE
GAME_UpdateScoreAndFound
;{
	; Nastav se do spravneho pole, na zacatek
	movlw GAME_foundPlayer1
	btfsc GAME_fobPlayer, 0
	movlw GAME_foundPlayer2
	movwf FSR
	
	; Zkontroluj cislo fobu 1-10 (0-9)
	decf GAME_fobNumber, w
	addwf FSR, f
	movf INDF, f		; uz byl nalezen?
	btfsc STATUS, Z
	goto GAME_UpdateFound
	return				; byl, koncime
	
GAME_UpdateFound
	incf INDF, f		; nebyl, zvys (+1)
	
	call WT588D_playFoundSound	;byl nalez
	
	btfss GAME_fobPlayer, 0
	goto GAME_IncScoreP1
	goto GAME_IncScoreP2	
	
GAME_IncScoreP1	
	incf GAME_player1Score, f
	goto GAME_checkGameOver

GAME_IncScoreP2
	incf GAME_player2Score, f
		
GAME_checkGameOver

	;Ma player1 nebo player2 10 nalezu?
	movlw GAME_FOBS_COUNT
	subwf GAME_player1Score, w
	btfss STATUS, Z
	goto GAME_checkPlayer2
	goto GAME_IsOver

GAME_checkPlayer2
	movlw GAME_FOBS_COUNT
	subwf GAME_player2Score, w
	btfss STATUS, Z
	return	
	
GAME_IsOver
	movlw TRUE
	movwf GAME_isGameOver

	movf GAME_fobPlayer, w		;Tento hrac je vitez (ten co nasel tento fob)
	movwf GAME_winner
	return
;}

;Vstup: UID_byte: .4
;Vstup: UIDs
;Vystup: GAME_fobNumber nastaveny na 1-10 pri nalezu, 0 - pri nenalezeni
;Vystup: GAME_fobPlayer nastaveny na PLAYER1 nebo PLAYER2 pri nalezu, 0xFF nic
GAME_CheckUID
;{
	
	bsf STATUS, IRP			;BANK2 FSR
	
	clrf GAME_fobNumber		; nic nenalezeno

	movlw .255
	movwf GAME_fobPlayer
	
	movlw .1
	movwf j
	
	movlw GAME_FOBS_COUNT * .2				;20 FOBu v databazi
	movwf i
GAME_CheckUIDLoop

	movlw LOW UIDs
	movwf FSR

	decf j, w			; k = (j-1) * 4
	movwf k		
	bcf STATUS, C
	rlf k, f
	rlf k, w
				
	addwf FSR, f		; FSR = FSR + k
	
	;Kontrola 1. byte UID
	movf UID_byte+0, w		
	xorwf INDF, w
	btfss STATUS, Z
	goto GAME_CheckUIDNext	;Neshoda
	
	;Kontrola 2. byte UID
	incf FSR, f
	movf UID_byte+1, w
	xorwf INDF, w
	btfss STATUS, Z
	goto GAME_CheckUIDNext
	
	;Kontrola 3. byte UID
	incf FSR, f
	movf UID_byte+2, w
	xorwf INDF, w
	btfss STATUS, Z
	goto GAME_CheckUIDNext
	
	;Kontrola 4. byte UID
	incf FSR, f
	movf UID_byte+3, w
	xorwf INDF, w
	btfss STATUS, Z
	goto GAME_CheckUIDNext
	
	;Mame shodu, nastav hrace shody
	movf j, w
	movwf GAME_fobNumber
	
	;Je nalezena pozice > 10? Pak jde o hrace2
	movlw GAME_FOBS_COUNT + .1
	subwf j, w
	movlw GAME_PLAYER1
	btfsc STATUS, C			;je-li C, jsme <= 10
	goto GAME_CheckAdjustP2
	movwf GAME_fobPlayer
	
	goto GAME_CheckFinish	; hotovo

GAME_CheckAdjustP2

	movlw GAME_PLAYER2
	movwf GAME_fobPlayer
	movlw GAME_FOBS_COUNT		;pozice 20 = cislo fobu 10 u druheho hrace
	subwf GAME_fobNumber, f

	goto GAME_CheckFinish	; hotovo
	
GAME_CheckUIDNext

	incf j, f
		
	decfsz i, f
	goto GAME_CheckUIDLoop
	
GAME_CheckFinish

	bcf STATUS, IRP		;FSR v BANK0 a BANK1
	return
;}

; *********************************************************************
; *************************** E E P R O M *****************************
; *********************************************************************

;Nacte seznam UIDs
;
EEPROM_ReadUIDs
;{
		clrf EEPROM_addr	; Cteme od addresy 0

		movlw EEPROM_Table_UIDs_len	;Nacteme UIDs delku
		movwf i

		bsf STATUS, IRP		;BANK2 FSR
		movlw LOW UIDs
		movwf FSR

EEPROM_rLoop	
		movf EEPROM_addr, w	
		BANK2
		movwf EEADR 		; Address to read
		BANK3		
		bcf EECON1, EEPGD 	; Point to Data memory
		bsf EECON1, RD 		; EE Read
		BANK2		
		movf EEDATA, w 		; W = EEDATA
		BANK0
		movwf INDF
		incf FSR, f

		incf EEPROM_addr, f
		decfsz i, f
		goto EEPROM_rLoop

		bcf STATUS, IRP		;FSR v BANK0 a BANK1
		return
;}


; *********************************************************************
; ************************ 1.8" TFT ST7735 DRIVER *********************
; *********************************************************************

TFT_ColorSetBlackBG
;{
	movlw HIGH ST7735_BLACK
    movwf TFT_pieceBGColor+0
    movlw LOW ST7735_BLACK
    movwf TFT_pieceBGColor+1    
    return
;}

TFT_ColorSetWhiteFG
;{
    movlw HIGH ST7735_WHITE
    movwf TFT_pieceFGColor+0
    movlw LOW ST7735_WHITE
    movwf TFT_pieceFGColor+1
    return
;}

TFT_ColorSetBlueFG
;{
    movlw HIGH ST7735_BLUE
    movwf TFT_pieceFGColor+0
    movlw LOW ST7735_BLUE
    movwf TFT_pieceFGColor+1
    return
;}

TFT_ColorSetRedFG
;{
    movlw HIGH ST7735_RED
    movwf TFT_pieceFGColor+0
    movlw LOW ST7735_RED
    movwf TFT_pieceFGColor+1
    return
;}




;Vykresli kruh pro nalezeny fob + cislici
TFT_DrawFobFound
;{
	call TFT_DrawFob
		
	call TFT_SetFont8x9
	
	movlw TRUE				;Pouze 1 cislici
	movwf TFT_putChar
	
	call TFT_ColorSetWhiteFG
	
    btfss GAME_fobPlayer, 0	;Nastav spravne pozadi pro hrace
    goto TFT_DrawFobFound_Player1
    movlw HIGH ST7735_RED
    movwf TFT_pieceBGColor+0
    movlw LOW ST7735_RED
    movwf TFT_pieceBGColor+1
    goto TFT_DrawFobFoundCommon
TFT_DrawFobFound_Player1    
    movlw HIGH ST7735_BLUE
    movwf TFT_pieceBGColor+0
    movlw LOW ST7735_BLUE
    movwf TFT_pieceBGColor+1
TFT_DrawFobFoundCommon
	
	goto TFT_DrawFobNumber
;}

;Vykresli cislice 1 - 10 na jednotlive foby
;Vstup GAME_fobPlayer
;Vstup GAME_fobPlayer
TFT_DrawFobNumbers
;{	
	call TFT_ColorSetWhiteFG
    
    movlw .1
    movwf GAME_fobNumber
        	
	movlw GAME_FOBS_COUNT
	movwf k
TFT_DrawFobsNumbersCommonL

	movf GAME_fobNumber, w
	call TFT_DrawFobNumber
	
	incf GAME_fobNumber, f
	
	decfsz k, f
	goto TFT_DrawFobsNumbersCommonL
	return    
    
;}

TFT_DrawFobNumber
;{	
	decf GAME_fobNumber, f		;1-10 -> 0-9
	call TFT_DrawFobCompute		;Spocitej okno X,Y,X_MAX,Y_MAX pro kresleni fobu
	incf GAME_fobNumber, f
	;TODO My se posunem o 5px doprava a 4px dolu (doprostred fobu)
	movlw .4
	addwf TFT_X, f
	incf TFT_X, f		
	addwf TFT_Y, f
	movlw ' '						;Pozor, mame 0-9, drawChar bere -32
	addwf GAME_fobNumber, w 		;0-9 -> '0' -> '9'
	goto TFT_DrawChar
	return	
;}

TFT_DrawFobs
;{
	
	movlw FALSE
	movwf GAME_found		;Kreslime prazdne kruznice
	
	movlw FONT_8x9
	movwf TFT_whichFont		;8x9 na ocislovani fobu
	
	call TFT_SetFont8x9
	
	movlw TRUE				;Pouze 1 cislici
	movwf TFT_putChar
	
	call TFT_ColorSetBlackBG
    
    ;Nejprve foby hrace 1
    movlw GAME_PLAYER1
    movwf GAME_fobPlayer
    call TFT_DrawFobsCommon
    
    call TFT_DrawFobNumbers
    
    ;Nejprve foby hrace 2
    movlw GAME_PLAYER2
    movwf GAME_fobPlayer
    call TFT_DrawFobsCommon
    
    call TFT_DrawFobNumbers
    
    movlw TRUE
	movwf GAME_found		;Ted uz budeme kreslit jen nalezy
    return
;}  
    
TFT_DrawFobsCommon
;{
    movlw .1
    movwf GAME_fobNumber
        	
	movlw GAME_FOBS_COUNT
	movwf k
TFT_DrawFobsCommonL

	movf GAME_fobNumber, w
	call TFT_DrawFob
		
	incf GAME_fobNumber, f
	
	decfsz k, f
	goto TFT_DrawFobsCommonL
	return
;}


;Input W-Reg - Cislo fobu 1-10
;Input GAME_fobPlayer 0-player1, 1-player2
TFT_DrawFob
;{  
	call TFT_ColorSetBlackBG
	
    btfss GAME_fobPlayer, 0
    goto TFT_DrawFob_Player1
    
    call TFT_ColorSetRedFG  

    goto TFT_DrawFobCommon
TFT_DrawFob_Player1    

    call TFT_ColorSetBlueFG
    
TFT_DrawFobCommon

	decf GAME_fobNumber, f
	call TFT_DrawFobCompute		;Spocitej okno X,Y,X_MAX,Y_MAX pro kresleni fobu
	incf GAME_fobNumber, f
	
	btfsc GAME_found, 0			; Co kreslime?
	goto TFT_drawFull
	movlw HIGH Table_emptyCircle
	movwf dataPointer+0
	movlw LOW Table_emptyCircle
	movwf dataPointer+1
	goto TFT_drawFinish
	
TFT_drawFull
	movlw HIGH Table_fullCircle
	movwf dataPointer+0
	movlw LOW Table_fullCircle
	movwf dataPointer+1	

TFT_drawFinish
	movlw Table_emptyCircle_len ;Delka pro obe je stejna
	movwf TFT_dataLen
	
	call TFT_Draw
	
    return
;}

;Spocitej pozici okna, kam budu vykreslovat
;Input: GAME_fobPlayer
;Input: GAME_fobNumber
;Y pro Player1 - 50
;Y pro Player2 - 92
;Okno [X,Y,X_MAX,Y_MAX] bude [16*(GAME_fobNumber-1),50 nebo 92,16*(GAME_fobNumber-1)+15,65 nebo 107]
TFT_DrawFobCompute
;{
	;16*GAME_fobNumber-1    
    ;decf GAME_fobNumber, w
    movf GAME_fobNumber, w
    movwf tmp2
    bcf STATUS, C
    rlf tmp2, f
    rlf tmp2, f ;x4
    rlf tmp2, f ;x8
    rlf tmp2, f ;x16
    
    ;X, X_MAX
    movf tmp2, w
    movwf TFT_X
    movlw GFX_FOB_SIZE
    addwf tmp2, f
    decf tmp2, w	;-1
    movwf TFT_X_MAX
        
    ;Y, Y_MAX
	movlw GFX_FOBS_P2_Y_OFFSET
	btfss GAME_fobPlayer, 0
	movlw GFX_FOBS_P1_Y_OFFSET
	movwf TFT_Y
	movlw GFX_FOB_SIZE - .1
	addwf TFT_Y, w
	movwf TFT_Y_MAX
    return
    
;}

TFT_DrawLogo
;{
	;104 x 32px
	movlw .28
	movwf TFT_X
	movlw .0
	movwf TFT_Y
	
	movlw .28 + .104 - .1
	movwf TFT_X_MAX
	movlw .32 - .1
	movwf TFT_Y_MAX

	movlw HIGH ST7735_GREEN
    movwf TFT_pieceBGColor+0
    movlw LOW ST7735_GREEN
    movwf TFT_pieceBGColor+1
    movlw HIGH ST7735_BLACK
    movwf TFT_pieceFGColor+0
    movlw LOW ST7735_BLACK
    movwf TFT_pieceFGColor+1	
    
    movlw HIGH Table_Splash1
    movwf dataPointer+0
    movlw LOW Table_Splash1
    movwf dataPointer+1
    
	movlw Table_Splash1_len
	movwf TFT_dataLen	
	
	call TFT_Draw
	
    movlw HIGH Table_Splash2
    movwf dataPointer+0
    movlw LOW Table_Splash2
    movwf dataPointer+1
    
	movlw Table_Splash2_len
	movwf TFT_dataLen		
	
	call TFT_Draw2	
	
	return	
;}

TFT_Init
;{

  		bsf TFT_CS
  		bcf TFT_DC
  
  		bcf TFT_SCK
    	bcf TFT_MOSI
    
		movlw ST7735_SWRESET
		call TFT_SendCmd
		movlw .150
		call waitMilis
		movlw ST7735_SLPOUT
		call TFT_SendCmd
		movlw .250
		call waitMilis
		movlw .250
		call waitMilis
		movlw ST7735_FRMCTR1
		call TFT_SendCmd
		movlw 0x01
		call TFT_SendData
		movlw 0x2C
		call TFT_SendData
		movlw 0x2D
		call TFT_SendData
		movlw ST7735_FRMCTR2
		call TFT_SendCmd
		movlw 0x01
		call TFT_SendData
		movlw 0x2C
		call TFT_SendData
		movlw 0x2D
		call TFT_SendData
		movlw ST7735_FRMCTR3
		call TFT_SendCmd
		movlw 0x01
		call TFT_SendData 
		movlw 0x2C
		call TFT_SendData 
		movlw 0x2D
		call TFT_SendData
		movlw 0x01
		call TFT_SendData 
		movlw 0x2C
		call TFT_SendData 
		movlw 0x2D
		call TFT_SendData
		movlw ST7735_INVCTR
		call TFT_SendCmd
		movlw 0x07
		call TFT_SendData
		movlw ST7735_PWCTR1
		call TFT_SendCmd
		movlw 0xA2
		call TFT_SendData
		movlw 0x02
		call TFT_SendData
		movlw 0x84
		call TFT_SendData
		movlw ST7735_PWCTR2
		call TFT_SendCmd
		movlw 0xC5
		call TFT_SendData
		movlw ST7735_PWCTR3
		call TFT_SendCmd
		movlw 0x0A
		call TFT_SendData
		movlw 0x00
		call TFT_SendData
		movlw ST7735_PWCTR4
		call TFT_SendCmd
		movlw 0x8A
		call TFT_SendData
		movlw 0x2A
		call TFT_SendData
		movlw ST7735_PWCTR5
		call TFT_SendCmd
		movlw 0x8A
		call TFT_SendData
		movlw 0xEE
		call TFT_SendData
		movlw ST7735_VMCTR1
		call TFT_SendCmd
		movlw 0x0E
		call TFT_SendData
		movlw ST7735_INVOFF
		call TFT_SendCmd
		movlw ST7735_MADCTL
		call TFT_SendCmd
		;movlw 0xC8
		;movlw 0xA8 ;landscape BRG
		movlw 0xA0  ;landscape RGB OK
		call TFT_SendData
		movlw ST7735_COLMOD
		call TFT_SendCmd
		movlw 0x05
		call TFT_SendData 
		movlw ST7735_CASET
		call TFT_SendCmd
		movlw 0x00
		call TFT_SendData 
		movlw 0x00
		call TFT_SendData
		movlw 0x00
		call TFT_SendData 
		movlw 0x7F
		call TFT_SendData
		movlw ST7735_RASET
		call TFT_SendCmd
		movlw 0x00
		call TFT_SendData 
		movlw 0x00
		call TFT_SendData
		movlw 0x00
		call TFT_SendData 
		movlw 0x9F
		call TFT_SendData
		movlw ST7735_GMCTRP1
		call TFT_SendCmd
		movlw 0x02
		call TFT_SendData
		movlw 0x1C
		call TFT_SendData 
		movlw 0x07
		call TFT_SendData 
		movlw 0x12
		call TFT_SendData
		movlw 0x37
		call TFT_SendData 
		movlw 0x32
		call TFT_SendData 
		movlw 0x29
		call TFT_SendData 
		movlw 0x2D
		call TFT_SendData
		movlw 0x29
		call TFT_SendData 
		movlw 0x25
		call TFT_SendData 
		movlw 0x2B
		call TFT_SendData 
		movlw 0x39
		call TFT_SendData
		movlw 0x00
		call TFT_SendData 
		movlw 0x01
		call TFT_SendData 
		movlw 0x03
		call TFT_SendData 
		movlw 0x10
		call TFT_SendData
		movlw ST7735_GMCTRN1
		call TFT_SendCmd
		movlw 0x03
		call TFT_SendData 
		movlw 0x1D
		call TFT_SendData 
		movlw 0x07
		call TFT_SendData 
		movlw 0x06
		call TFT_SendData
		movlw 0x2E
		call TFT_SendData 
		movlw 0x2C
		call TFT_SendData 
		movlw 0x29
		call TFT_SendData 
		movlw 0x2D
		call TFT_SendData
		movlw 0x2E
		call TFT_SendData 
		movlw 0x2E
		call TFT_SendData 
		movlw 0x37
		call TFT_SendData 
		movlw 0x3F
		call TFT_SendData
		movlw 0x00
		call TFT_SendData 
		movlw 0x00
		call TFT_SendData 
		movlw 0x02
		call TFT_SendData 
		movlw 0x10
		call TFT_SendData
		movlw ST7735_NORON
		call TFT_SendCmd
		movlw .10
		call waitMilis
		movlw ST7735_DISPON
		call TFT_SendCmd
		movlw .100
		call waitMilis   
    		
		return
;}		
		

; Left-Top, [X,Y] -> [X_MAX, Y_MAX]
TFT_SetWindow
;{
		movlw ST7735_CASET
		call TFT_SendCmd
		movlw 0
		call TFT_SendData
		movf TFT_X, w
		call TFT_SendData
		movlw 0
		call TFT_SendData
		movf TFT_X_MAX, w
		call TFT_SendData
		movlw ST7735_RASET
		call TFT_SendCmd
		movlw 0
		call TFT_SendData
		movf TFT_Y, w
		call TFT_SendData
		movlw 0
		call TFT_SendData
		movf TFT_Y_MAX, w
		call TFT_SendData
		movlw ST7735_RAMWR
		call TFT_SendCmd
		return
;}		


;Vykresli data do obdelniku [X,Y] -> [X_MAX, Y_MAX]
;TFT_dataLen - pocet bytes
TFT_Draw
;{
    call TFT_SetWindow			;Spocitej a nastav pozici

TFT_Draw2   
	

    bcf TFT_CS		;Zacatek write operace
	nop
	nop
	bsf TFT_DC		;Pouze data
	nop
	nop
    		
    movf TFT_dataLen, w		
TFT_DrawBox					;Vykreslovani obecnych obdelniku
    movwf i

TFT_draw_loop

	call TFT_getNextByte
    movwf tmp

    movlw .8				
    movwf j

TFT_draw_loopB    
    btfss tmp, 7        ;nejvyssi bit set?
    goto TFT_drawBitNotSet
    movf TFT_pieceFGColor+0, w
    call TFT_WriteByte
    movf TFT_pieceFGColor+1, w
    call TFT_WriteByte
    goto TFT_bitCommon

TFT_drawBitNotSet
    movf TFT_pieceBGColor+0, w
    call TFT_WriteByte
    movf TFT_pieceBGColor+1, w
    call TFT_WriteByte

TFT_bitCommon            
    rlf tmp, f
	
    decfsz j, f
    goto TFT_draw_loopB
        
    decfsz i, f
    goto TFT_draw_loop
    
    bsf TFT_CS				; Konec write operace
    
    return
;}


TFT_getNextByte
;{
	call TFT_getNextByte2 	;To je patch kvuli strankovani
	clrf PCLATH
	incfsz dataPointer+1, f ;Inkrementuj pointer
	goto $+2
	incf dataPointer+0, f
	return 					;Vrat hodnotu (je stale ve W)
TFT_getNextByte2
	;Zde se pouze skoci na dvoubajtovou adresu v dataPointer	
	movf dataPointer+0, w 	;Zkopiruj HI byte do PCLATHu
	movwf PCLATH
	movf dataPointer+1, w 	;Dej LO byte do PCL
	movwf PCL 				;Skoci na adresu, kam ukazuje textPointer		
;}


TFT_GetNextChar
;{
		call TFT_GetNextChar2 		;To je patch kvuli strankovani
		clrf PCLATH
		incfsz textPointer+1, f ;Inkrementuj pointer
		goto $+2
		incf textPointer+0, f
		return 					;Vrat hodnotu (je stale ve W)
TFT_GetNextChar2
		;Zde se pouze skoci na dvoubajtovou adresu v textPointer
		movf textPointer+0,w 	;Zkopiruj HI byte do PCLATHu
		movwf PCLATH
		movf textPointer+1,w 	;Dej LO byte do PCL
		movwf PCL 				;Skoci na adresu, kam ukazuje textPointer
;}

		
TFT_ClearScreen
;{	
	movlw .0
	movwf TFT_X
	
	movlw .0
	movwf TFT_Y

	movlw TFT_WIDTH - .1
	movwf TFT_X_MAX

	movlw TFT_HEIGHT - .1
	movwf TFT_Y_MAX
	
	call TFT_SetWindow
			
	bcf TFT_CS		;Zacatek write operace
	nop
	nop
	bsf TFT_DC		;Data
	nop
	nop
		
	movlw TFT_HEIGHT	
	movwf j

TFT_fillR					; Rows
	movlw TFT_WIDTH
	movwf i	
TFT_fillC					; Columns

	movlw HIGH ST7735_BLACK	;Use selected color
	call TFT_WriteByte
	movlw LOW ST7735_BLACK
	call TFT_WriteByte
    
    decfsz i, f
    goto TFT_fillC			
    
	decfsz j, f
    goto TFT_fillR
	
	bsf TFT_CS				; Konec write operace			
	return
;}
				

TFT_SendCmd
;{
		bcf TFT_CS
		;nop
		;nop
		bcf TFT_DC		;Command
		;nop
		;nop
		
		call TFT_WriteByte
		
		;nop
		;nop
		bsf TFT_CS
		return
;}
		
TFT_SendData
;{
		bcf TFT_CS
		;nop
		;nop
		bsf TFT_DC		;Data
		;nop
		;nop
		
		call TFT_WriteByte
		
		;nop
		;nop
		bsf TFT_CS
		return
;}

TFT_WriteByte				;SW SPI
;{
		movwf TFT_tmp

		movlw .8			;8 bits transfer
		movwf TFT_i

TFT_cycle	
		btfss TFT_tmp, 7		
		goto TFT_bitNotSet
		bcf TFT_SCK	
		bsf TFT_MOSI
		goto TFT_tested
TFT_bitNotSet 		
		bcf TFT_SCK
		bcf TFT_MOSI
TFT_tested
		bsf TFT_SCK

		rlf TFT_tmp, f
		decfsz TFT_i, f
		goto TFT_cycle
	
		bcf TFT_SCK
		return			
;}
		
TFT_WriteWord
;{
		movlw TFT_word
		call TFT_WriteByte
		movlw TFT_word+1
		call TFT_WriteByte
		return
;}


;Vykresli text
;Vstup:
; textPointer:2 - zacatek textu
; TFT_X, TFT_Y - pozice kam
; TFT_char_width - sirka pismene fontu v pixelech
; TFT_char_height - vyska pismene fontu v pixelech

TFT_DrawText
;{
		movlw FALSE				;Vypisuj cele retezce
		movwf TFT_putChar
		
TFT_DrawTextLoop
		call TFT_GetNextChar
		iorlw 0x00 
		btfsc STATUS, Z
		return
TFT_DrawChar
		movwf tmp
		movlw .32
		subwf tmp, w			;x 1

		movwf loByte
		movwf tmp				;x1 uschovej
		clrf hiByte
											
		btfss TFT_whichFont, 0
		goto TFT_Mult8x16

		;8x9 font 				;x8 + x1
		bcf STATUS, C
		rlf loByte, f
		rlf hiByte, f
		rlf loByte, f
		rlf hiByte, f
		rlf	loByte, f
		rlf hiByte, f
		movf tmp, w			    ;+ x1
		addwf loByte, f
		btfsc STATUS, C
		incf hiByte, f		
		goto TFT_MultFinished
		
TFT_Mult8x16
		;Najdi graficka data pro pismeno (x16 pro 8x16 font)
		bcf STATUS, C
		rlf loByte, f
		rlf hiByte, f
		rlf loByte, f
		rlf hiByte, f
		rlf	loByte, f
		rlf hiByte, f				
		rlf loByte, f
		rlf hiByte, f

TFT_MultFinished		

		btfsc TFT_whichFont, 0
		goto TFT_DrawFont8x9
		movlw HIGH Table_font8x16	;8x16
		movwf dataPointer+0
		movlw LOW Table_font8x16
		movwf dataPointer+1		;k dataPointer musime pricit 16x base
		goto TFT_DrawFontOK
		
TFT_DrawFont8x9			
		movlw HIGH Table_font8x9
		movwf dataPointer+0
		movlw LOW Table_font8x9
		movwf dataPointer+1		;k dataPointer musime pricit 16x base		
		
TFT_DrawFontOK		
		movf loByte, w
		addwf dataPointer+1, f
		btfsc STATUS, C			;soucet >256?
		incf dataPointer+0, f		
		movf hiByte, w
		addwf dataPointer+0, f			
		
		movf TFT_X, w
		movwf TFT_X_MAX	
		
		movlw .1
		subwf TFT_charWidth, w		;W = CHAR_WIDTH - 1
	
		addwf TFT_X_MAX, f
		
		movf TFT_Y, w
		movwf TFT_Y_MAX
		
		movlw .1
		subwf TFT_charHeight, w		;W = CHAR_HEIGHT - 1		
		
		addwf TFT_Y_MAX, f

		;Vykresli graficka data znaku na pozici
		movf TFT_charHeight, w
		
		movwf TFT_dataLen
					
		call TFT_Draw
			
		movf TFT_Y_copy, w
		movwf TFT_Y
		
		;Posun se o znak doprava na obrazovce
		movf TFT_charWidth, w
		addwf TFT_X, f
		
		btfss TFT_putChar, 0		;0-ne, 1-ano		
		goto TFT_DrawTextLoop
		return

;}				


TFT_PrintStatus
;{
		call TFT_ColorSetBlackBG
		call TFT_ColorSetWhiteFG
		call TFT_SetFont8x16
		
		movlw TRUE				;Pouze 1 znak
		movwf TFT_putChar
		
		movlw .100
		movwf TFT_X
		movlw .0
		movwf TFT_Y
		movwf TFT_Y_copy	
		
		movf mfrc522_status, w
		call UTIL_bin2char
		goto TFT_DrawChar		
;}

;Vypis 4 bajty z UID, preved kazdy bajt na 2 znaky (0x34 na '3', '4')
;Vypisuj na pozici 0,0
TFT_PrintUID
;{
		call TFT_ColorSetBlackBG
		call TFT_ColorSetWhiteFG
		call TFT_SetFont8x16
		
		movlw TRUE				;Pouze 1 znak
		movwf TFT_putChar
		
		movlw .0
		movwf TFT_X
		movlw .0
		movwf TFT_Y
		movwf TFT_Y_copy
			
		movlw UID_byte
		movwf FSR
		
		movlw MFRC522_UID_SIZE + .1 ; + 1 == BCC 		
		movwf k
TFT_PrintUIDLoop
		swapf INDF, w		;1. byte UID, horni -> dolni
		andlw 0x0F
		call UTIL_bin2char
		call TFT_DrawChar
		movf INDF, w
		andlw 0x0F
		call UTIL_bin2char
		call TFT_DrawChar
		
		incf FSR, f
		decfsz k, f
		goto TFT_PrintUIDLoop
		return
;}	


TFT_SetFont8x16
;{
	movlw FONT_8x16
	movwf TFT_whichFont		;8x16 herni texty
	
	movlw FONT_8x16_CHAR_HEIGHT
	movwf TFT_charHeight
	movlw FONT_8x16_CHAR_WIDTH
	movwf TFT_charWidth	
	return
;}

TFT_SetFont8x9
;{	
	movlw FONT_8x9
	movwf TFT_whichFont		;8x9 cisla na fobech
		
	movlw FONT_8x9_CHAR_HEIGHT
	movwf TFT_charHeight
	movlw FONT_8x9_CHAR_WIDTH
	movwf TFT_charWidth	
	return

;}



TFT_ShowPlayer1
;{
	call TFT_ColorSetWhiteFG
	call TFT_ColorSetBlackBG      
	
	movlw HIGH T_PLAYER1
	movwf textPointer+0
	movlw LOW T_PLAYER1
	movwf textPointer+1
	
	movlw .32
	movwf TFT_X
	movlw .34
	movwf TFT_Y
	movwf TFT_Y_copy
	
	goto TFT_DrawText		
;}

TFT_ShowPlayer2
;{
	movlw HIGH T_PLAYER2
	movwf textPointer+0
	movlw LOW T_PLAYER2
	movwf textPointer+1
	
	movlw .32
	movwf TFT_X
	movlw .70
	movwf TFT_Y
	movwf TFT_Y_copy
	
	goto TFT_DrawText
	
;}

;Zluta na cernem pozadi
TFT_SetInfoTextColour
;{
    movlw HIGH ST7735_YELLOW
    movwf TFT_pieceFGColor+0
    movlw LOW ST7735_YELLOW
    movwf TFT_pieceFGColor+1	
    
    goto TFT_ColorSetBlackBG

;}
    

TFT_ShowPressStart
;{
	movlw HIGH T_PRESS_START
	movwf textPointer+0
	movlw LOW T_PRESS_START
	movwf textPointer+1
	
	call TFT_SetInfoTextColour	
	
	movlw .24
	movwf TFT_X
	movlw .110
	movwf TFT_Y
	movwf TFT_Y_copy
	
	goto TFT_DrawText
	
;}

TFT_ShowFindAllFobs
;{
	movlw HIGH T_FIND_ALL_FOBS
	movwf textPointer+0
	movlw LOW T_FIND_ALL_FOBS
	movwf textPointer+1
	
	call TFT_SetInfoTextColour	
	
	movlw .28
	movwf TFT_X
	movlw .110
	movwf TFT_Y
	movwf TFT_Y_copy
	
	goto TFT_DrawText	
	
;}

TFT_ShowGameOver
;{
	movlw HIGH T_GAME_OVER
	movwf textPointer+0
	movlw LOW T_GAME_OVER
	movwf textPointer+1
	
	call TFT_SetInfoTextColour
	
	movlw .28
	movwf TFT_X
	movlw .110
	movwf TFT_Y
	movwf TFT_Y_copy
	
	goto TFT_DrawText	
	
;}

TFT_ShowWinner
;{
	btfss GAME_winner, 0
	goto GAME_P1Wins
	goto GAME_P2Wins
	
GAME_P1Wins
	movlw HIGH T_PLAYER1_WINS
	movwf textPointer+0
	movlw LOW T_PLAYER1_WINS
	movwf textPointer+1
	goto GAME_ShowWinnerNext

GAME_P2Wins	
	movlw HIGH T_PLAYER2_WINS
	movwf textPointer+0
	movlw LOW T_PLAYER2_WINS
	movwf textPointer+1	

GAME_ShowWinnerNext

	call TFT_SetInfoTextColour
	
	movlw .24
	movwf TFT_X
	movlw .110
	movwf TFT_Y
	movwf TFT_Y_copy
	
	goto TFT_DrawText		
	
;}

;

; ********************************************************************		
; ********************** MFRC522  D R I V E R ************************
; ********************************************************************

SPI_send
;{
	movwf SSPBUF			; Place data in send buffer
	BANK1
SPI_sendLoop
    btfss SSPSTAT, BF		; Has data been received?
	;nop
	goto SPI_sendLoop		; Loop if not received yet
	BANK0
    movf SSPBUF, w			; Empty the receive buffer
  	movwf SPI_value			; Put received byte into SPI_value
  	return
;}

MFRC522_PCD_Reset
;{
	movlw CommandReg				;0x02
	movwf mfrc522_register	
	movlw PCD_SoftReset				;0x0F
	movwf mfrc522_value	
	call MFRC522_PCD_WriteRegister
	
	;Section 8.8.2 in the datasheet says the oscillator start-up time is the start up time of the crystal + 37,74us. Let us be generous: 50ms.
	movlw .50
	call waitMilis
	
	;TODO dodelat test dokonceni resetu
	; Wait for the PowerDown bit in CommandReg to be cleared
	;while (PCD_ReadRegister(CommandReg) & (1<<4)) {
	; PCD still restarting - unlikely after waiting 50ms, but better safe than sorry.
		
	return	
;}	

MFRC522_ResetBaudRates
;{
	; Reset baud rates
	movlw TxModeReg					;0x24
	movwf mfrc522_register
	movlw 0x00
	movwf mfrc522_value			
	call MFRC522_PCD_WriteRegister
	
	movlw RxModeReg					;0x26
	movwf mfrc522_register
	movlw 0x00
	movwf mfrc522_value			
	call MFRC522_PCD_WriteRegister
	
	; Reset ModWidthReg 
	movlw ModWidthReg				;0x48
	movwf mfrc522_register
	movlw 0x26
	movwf mfrc522_value			
	call MFRC522_PCD_WriteRegister	  	
	
	return
;}

MFRC522_PCD_Init
;{

	bsf MFRC522_CS

	call MFRC522_PCD_Reset
	
	call MFRC522_ResetBaudRates
	
	; When communicating with a PICC we need a timeout if something goes wrong.
	; f_timer = 13.56 MHz / (2*TPreScaler+1) where TPreScaler = [TPrescaler_Hi:TPrescaler_Lo].
	; TPrescaler_Hi are the four low bits in TModeReg. TPrescaler_Lo is TPrescalerReg.
	movlw TModeReg				; 0x54	- 	TAuto=1; timer starts automatically at the end of the transmission in all communication modes at all speeds
	movwf mfrc522_register
	movlw 0x80
	movwf mfrc522_value			
	call MFRC522_PCD_WriteRegister
	
	movlw TPrescalerReg			; 0x56 -	 TPreScaler = TModeReg[3..0]:TPrescalerReg, ie 0x0A9 = 169 => f_timer=40kHz, ie a timer period of 25?s.
	movwf mfrc522_register
	movlw 0xA9
	movwf mfrc522_value			
	call MFRC522_PCD_WriteRegister
	
	movlw TReloadRegH			; 0x58 -	 Reload timer with 0x3E8 = 1000, ie 25ms before timeout.
	movwf mfrc522_register
	movlw 0x03
	movwf mfrc522_value			
	call MFRC522_PCD_WriteRegister

	movlw TReloadRegL			; 0x5A
	movwf mfrc522_register
	movlw 0xE8
	movwf mfrc522_value			
	call MFRC522_PCD_WriteRegister	
	
	movlw TxASKReg				; 0x2A -	Default 0x00. Force a 100 % ASK modulation independent of the ModGsPReg register setting
	movwf mfrc522_register
	movlw 0x40
	movwf mfrc522_value			
	call MFRC522_PCD_WriteRegister	
	
	movlw ModeReg				; 0x22 -	Default 0x3F. Set the preset value for the CRC coprocessor for the CalcCRC command to 0x6363 (ISO 14443-3 part 6.2.4)	
	movwf mfrc522_register
	movlw 0x3D
	movwf mfrc522_value			
	call MFRC522_PCD_WriteRegister		
	
	call MFRC522_PCD_AntennaOn
	
	return
;}

; Turns the antenna on by enabling pins TX1 and TX2.
; After a reset these pins are disabled.
MFRC522_PCD_AntennaOn
;{
	movlw TxControlReg		; 0x28 (0x28 | 0x80 = 0xA8)
	movwf mfrc522_register
	call MFRC522_PCD_ReadRegister
			
	movf SPI_value, w
	andlw 0x03
	sublw 0x03
	btfss STATUS, Z
	goto MFRC522_PCD_AntennaOn2
	return
	
MFRC522_PCD_AntennaOn2	
	movlw TxControlReg		; 0x28
	movwf mfrc522_register
	movf SPI_value, w
	iorlw 0x03
	movwf mfrc522_value
	call MFRC522_PCD_WriteRegister
	return		
;}

;Vycisti buffery
MFRC522_BufferInit
;{
	BANK1
	movlw mfrc522_OUT_byteArray
	movwf FSR
	BANK0
	
	movlw GAME_FOBS_COUNT * .2 ; 2 hraci
	movwf i
MFRC522_BufferInitLoop
	clrf INDF
	incf FSR, f
	decfsz i, f
	goto MFRC522_BufferInitLoop
	return	
;}


MFRC522_ClearUID
;{
	
	clrf UID_byte+0
	clrf UID_byte+1
	clrf UID_byte+2
	clrf UID_byte+3
	movlw .1
	movwf UID_byte+4	;Hack, aby nesedel XOR
	return
;}

;Vystup: UID_size, UID_byte[4,7,10], UID_sak
;The SAK (Select acknowledge) byte returned from the PICC after successful selection
;Vstup: mfrc522_validBits = 0;
;{

   ; Description of buffer structure:
   ;        Byte 0: SEL             Indicates the Cascade Level: PICC_CMD_SEL_CL1, PICC_CMD_SEL_CL2 or PICC_CMD_SEL_CL3
   ;        Byte 1: NVB            Number of Valid Bits (in complete command, not just the UID): High nibble: complete bytes, Low nibble: Extra bits.
   ;        Byte 2: UID-data or CT  See explanation below. CT means Cascade Tag.
   ;        Byte 3: UID-data
   ;        Byte 4: UID-data
   ;        Byte 5: UID-data
   ;        Byte 6: BCC             Block Check Character - XOR of bytes 2-5
   ;        Byte 7: CRC_A
   ;        Byte 8: CRC_A
   ; The BCC and CRC_A are only transmitted if we know all the UID bits of the current Cascade Level.
   ;
   ; Description of bytes 2-5: (Section 6.5.4 of the ISO/IEC 14443-3 draft: UID contents and cascade levels)
   ;        UID size    Cascade level    Byte2    Byte3    Byte4    Byte5
   ;        ========    =============    =====    =====    =====    =====
   ;         4 bytes        1            uid0    uid1    uid2    uid3
   ;         7 bytes        1            CT      uid0    uid1    uid2
   ;                        2            uid3    uid4    uid5    uid6
   ;        10 bytes        1            CT      uid0    uid1    uid2
   ;                        2            CT      uid3    uid4    uid5
   ;                        3            uid6    uid7    uid8    uid9
 ;}
MFRC522_PICC_Select
;{
	;default	
	movlw STATUS_ERROR
	movwf mfrc522_status
	
	;Clear UID
	call MFRC522_ClearUID
	
	;Clear buffers
	call MFRC522_BufferInit
			
	clrf mfrc522_validBits
	
	movlw 0x01
	movwf mfrc522_cascadeLevel
	
	; Prepare MFRC522
    ; PCD_ClearRegisterBitMask(CollReg, 0x80);        // ValuesAfterColl=1 => Bits received after collision are cleared.	
    movlw CollReg				;0x1C | 0x80 = 0x9C
    movwf mfrc522_register
    movlw 0x80
    movwf mfrc522_mask
    call MFRC522_PCD_ClearRegisterBitMask
    
    movlw FALSE
    movwf mfrc522_uidComplete

	;While (!uidComplete) {
PICC_SelectLoop
	movf mfrc522_uidComplete, f
	btfss STATUS, Z
	goto PICC_SelectFinish
	
	;Set the Cascade Level in the SEL byte, find out if we need to use the Cascade Tag in byte 2.
	;Cascade Level 1 mi staci
	movlw PICC_CMD_SEL_CL1			;0x93
	BANK1
	movwf mfrc522_OUT_byteArray+0
	BANK0
	clrf mfrc522_uidIndex
		
	;useCascadeTag = validBits && uid->size > 4;    // When we know that the UID has more than 4 bytes		
	clrf mfrc522_useCascadeTag	;validBits==0  => useCascadeTag bude vzdy false pro UID delky 4
	
	; How many UID bits are known in this Cascade Level?
	;currentLevelKnownBits = validBits - (8 * uidIndex);
	clrf mfrc522_currentLevelKnownBits	; opet, pouze pro UID delky 4
	
    ;Copy the known bits from uid->uidByte[] to buffer[]
    ;index = 2; // destination index in buffer[]
    movlw .2
    movwf mfrc522_index			;// destination index in buffer[] (MFRC522_OUT_byteArray)
    
    	movlw FALSE
    	movwf mfrc522_selectDone
    	
    	;while (!selectDone) {
PICC_SelectDoneLoop

		;Find out how many bits and bytes to send and receive.
		
		;This is an ANTICOLLISION.
		;txLastBits        = currentLevelKnownBits % 8;		
		movf mfrc522_currentLevelKnownBits, w
		call UTIL_mod8
		movwf mfrc522_txLastBits
		
		movf mfrc522_currentLevelKnownBits, w
		call UTIL_div8
		movwf mfrc522_count				; Number of whole bytes in the UID part.
	
		;index = 2 + count;            ; Number of whole bytes: SEL + NVB + UIDs
		movf mfrc522_count, w
		addlw .2
		movwf mfrc522_index
		
		;buffer[1]        = (index << 4) + txLastBits;    // NVB - Number of Valid Bits
		movf mfrc522_index, w
		movwf mfrc522_tmp		;(index << 4)
		bcf STATUS, C
		rlf mfrc522_tmp, f
		bcf STATUS, C
		rlf mfrc522_tmp, f
		bcf STATUS, C
		rlf mfrc522_tmp, f
		bcf STATUS, C
		rlf mfrc522_tmp, f
		movf mfrc522_txLastBits, w
		addwf mfrc522_tmp, w	; (index << 4) + txLastBits
		movwf mfrc522_value
		
		movlw 0x01
		movwf mfrc522_OUT_offset
		call MFRC522_setOutputBufValueAtIndex		
		
		;bufferUsed        = index + (txLastBits ? 1 : 0);  (mfrc522_OUT_index)
		movf mfrc522_index, w
		movwf mfrc522_OUT_bytesCount
		;TODO REMOVE? movwf mfrc522_OUT_index
		
		; + (txLastBits ? 1 : 0)
		movf mfrc522_txLastBits, f
		btfss STATUS, Z
		;TODO REMOVE? incf mfrc522_OUT_index, f
		incf mfrc522_OUT_bytesCount, f
		
		; Store response in the unused part of buffer
        ; responseBuffer    = &buffer[index];
        ; responseLength    = sizeof(buffer) - index;
        
        ;mfrc522_IN_byteArray == responseBuffer
        movlw .10
        movwf mfrc522_IN_bytesCount ;responseLength, muzu max. 10
        
        ;PCD_WriteRegister(BitFramingReg, (rxAlign << 4) + txLastBits);
        movf mfrc522_txLastBits, w
        movwf mfrc522_rxAlign		;RxAlign = BitFramingReg[6..4]. TxLastBits = BitFramingReg[2..0]
		movlw BitFramingReg			;0x1A
		movwf mfrc522_register
		movf mfrc522_rxAlign, w		;value = (rxAlign << 4) + txLastBits
		movwf mfrc522_tmp			
		bcf STATUS, C
		rlf mfrc522_tmp, f
		bcf STATUS, C
		rlf mfrc522_tmp, f
		bcf STATUS, C
		rlf mfrc522_tmp, f
		bcf STATUS, C
		rlf mfrc522_tmp, f
		movf mfrc522_txLastBits, w
		addwf mfrc522_tmp, w
		movwf mfrc522_value
		call MFRC522_PCD_WriteRegister
		
		;Transmit the buffer and receive the response.
		;TODO REMOVE movf mfrc522_OUT_index, w
		;TODO REMOVE movwf mfrc522_OUT_bytesCount
		;Vstupem jsou:
		;mfrc522_OUT_byteArray
		;mfrc522_OUT_bytesCount
		;mfrc522_IN_byteArray
		;mfrc522_IN_bytesCount
		;mfrc522_rxAlign
		;mfrc522_txLastBits
		call MFRC522_PCD_TransceiveData
		
		;if (result == STATUS_COLLISION) { // More than one PICC in the field => collision.
		movlw STATUS_COLLISION
		subwf mfrc522_status, w
		btfss STATUS, Z					;result == STATUS_COLLISION
		goto PICC_SelectNotColl
		
		;byte valueOfCollReg = PCD_ReadRegister(CollReg); // CollReg[7..0] bits are: ValuesAfterColl reserved CollPosNotValid CollPos[4:0]
		movlw CollReg				;0x1C
		movwf mfrc522_register
		call MFRC522_PCD_ReadRegister  ;SPI_value = valueOfCollReg
		
		;if (valueOfCollReg & 0x20) { // CollPosNotValid
		movlw 0x20
		andwf SPI_value, f			;pouzijeme dale jako collisionPos
		btfss STATUS, Z
		goto PICC_Select_COLLISION	;// Without a valid collision position we cannot continue
		
		;byte collisionPos = valueOfCollReg & 0x1F; // Values 0-31, 0 means bit 32.
		movlw 0x1F
		andwf SPI_value, f			;collisionPos = SPI_value
		
		movlw .32
		movf SPI_value, f			;collisionPos == 0?
		btfsc STATUS, Z
		movwf SPI_value				;yes, then collisionPos = 32;
		
        ;if (collisionPos <= currentLevelKnownBits) { 
        ;return STATUS_INTERNAL_ERROR;                
        movf SPI_value, w
		subwf mfrc522_currentLevelKnownBits, w
		btfss STATUS, C
		goto collisionPosGreater
		
		; No progress - should not happen
		goto PICC_Select_INTERNAL_ERROR
				
collisionPosGreater
		
		;Choose the PICC with the bit set.
		movf SPI_value, w
		movwf mfrc522_currentLevelKnownBits
		
		;count            = currentLevelKnownBits % 8; // The bit to modify
		call UTIL_div8
		movwf mfrc522_count
		
		;checkBit        = (currentLevelKnownBits - 1) % 8;
		movf mfrc522_currentLevelKnownBits, w
		sublw .1
		call UTIL_mod8
		movwf mfrc522_tmp		;checkBit
		
		;index            = 1 + (currentLevelKnownBits / 8) + (count ? 1 : 0); // First byte is index 0.
		movlw .1
		movwf mfrc522_index	;1 + 
		
		movf mfrc522_currentLevelKnownBits, w	
		call UTIL_div8
		addwf mfrc522_index, f ;1 + (currentLevelKnownBits / 8)
		
		movf mfrc522_count, w
		btfss STATUS, Z
		incf mfrc522_index, f	; + (count ? 1 : 0)
		
		;buffer[index]    |= (1 << checkBit);
		movf mfrc522_index, w
		movwf mfrc522_OUT_offset
		call MFRC522_getOutputBufValueAtIndex  ;buffer[index] -> mfrc522_value
				
		movf mfrc522_tmp, w		;checkBit
		call UTIL_shiftLeftX	; 1<<checkBit
		iorwf mfrc522_value, f	; buffer[index] | (1<<checkBit)
		call MFRC522_setOutputBufValueAtIndex	;uloz 
		goto PICC_SelectDoneLoop
		;end if (result == STATUS_COLLISION)
		               		
PICC_SelectNotColl

		; else if (result != STATUS_OK) {
        ; return result;
        movf mfrc522_status, f
        btfss STATUS, Z
        return
        
        ;else { // STATUS_OK
	     
		;if (currentLevelKnownBits >= 32) nedelame SELECT!!
		movlw .32
		movwf mfrc522_currentLevelKnownBits
		
		; We now have all 32 bits of the UID in this Cascade Level
		movlw TRUE					
		movwf mfrc522_selectDone
		movwf mfrc522_uidComplete
		
		;Zkontrolujeme, ze UID[0] ^ UID[1] ^ UID[2] ^ UID[3] == UID[4] (BCC) a
		;vratim STATUS_XOR_WRONG, pokud nesedi
		
		;Copy UID + BCC
		BANK1
		movf mfrc522_IN_byteArray+0, w
		BANK0
		movwf mfrc522_tmp
		movwf UID_byte+0
		BANK1
		movf mfrc522_IN_byteArray+1, w
		BANK0
		xorwf mfrc522_tmp, f
		movwf UID_byte+1
		BANK1
		movf mfrc522_IN_byteArray+2, w
		BANK0
		xorwf mfrc522_tmp, f
		movwf UID_byte+2
		BANK1
		movf mfrc522_IN_byteArray+3, w
		BANK0
		xorwf mfrc522_tmp, f
		movwf UID_byte+3
		BANK1
		movf mfrc522_IN_byteArray+4, w
		BANK0
		movwf UID_byte+4
		
		;XOR ok?
		subwf mfrc522_tmp, w
		btfss STATUS, Z
		goto PICC_Select_XOR_WRONG
										
		goto PICC_SelectFinish
		
        ;end else // STATUS_OK
		
		;End of while (!selectDone)
							
	goto PICC_SelectLoop
 	; End of while (!uidComplete)
	
PICC_SelectFinish
	movlw STATUS_OK
	goto PICC_SelectSetStatus

PICC_Select_XOR_WRONG
	movlw STATUS_XOR_WRONG
	goto PICC_SelectSetStatus
	
PICC_Select_ERROR
	movlw STATUS_ERROR
	goto PICC_SelectSetStatus
	
PICC_Select_INTERNAL_ERROR	
	movlw STATUS_INTERNAL_ERROR
	goto PICC_SelectSetStatus
	
PICC_Select_COLLISION
	movlw STATUS_COLLISION
	
PICC_SelectSetStatus
	movwf mfrc522_status
	return		
;}

MFRC522_PICC_IsNewCardPresent
;{
	call MFRC522_ResetBaudRates
	
	;1) Send PICC_RequestA
	movlw CollReg			; 0x1C (0x9C = 0x1C | 0x80)
	movwf mfrc522_register
	movlw 0x80
	movwf mfrc522_mask
	call MFRC522_PCD_ClearRegisterBitMask		; ValuesAfterColl=1 => Bits received after collision are cleared.	
	
	movlw .7	; For REQA and WUPA we need the short frame format - transmit only 7 bits of the last (and only) byte. TxLastBits = BitFramingReg[2..0]
	movwf mfrc522_validBits
		
	;Call PCD_TransceiveData()
	movlw PICC_CMD_REQA				;0x26
	BANK1
	movwf mfrc522_OUT_byteArray+0
	BANK0

	movlw .1
	movwf mfrc522_OUT_bytesCount
	
	movlw .2					;ATQA, 2 bytes returned
	movwf mfrc522_IN_bytesCount		
	
	clrf mfrc522_rxAlign
		
	call MFRC522_PCD_TransceiveData
		
	movf mfrc522_status, f			;STATUS_OK (=0)?
	btfsc STATUS, Z
	return		
	
	movlw .2						;bufferSize != 2 -> return STATUS_ERROR
	subwf mfrc522_IN_bytesCount, w  ;bufferSize = mfrc522_IN_bytesCount
	btfss STATUS, Z
	goto PICC_IsNewCardPresent_vb
	goto PICC_IsNewCardPresent_ERROR
	
PICC_IsNewCardPresent_vb	
	movf mfrc522_validBits, f		;validBits != 0 -> return STATUS_ERROR
	btfsc STATUS, Z
	goto PICC_IsNewCardPresent_OK
	
PICC_IsNewCardPresent_ERROR
	movlw STATUS_ERROR
	movwf mfrc522_status
	return
	
PICC_IsNewCardPresent_OK	
	movlw STATUS_OK
	movwf mfrc522_status
	return	
;}




;Vstup: 
;	mfrc522_OUT_byteArray+0	;sendData
;	mfrc522_OUT_bytesCount	;sendLen
;Vystup: STATUS_???
MFRC522_PCD_TransceiveData	
;{
	movlw 0x30				; RxIRq and IdleIRq
	movwf mfrc522_waitIRq
	
	movlw PCD_Transceive	; 0x0C
	movwf mfrc522_command
	
	clrf mfrc522_checkCRC	; false
	
	;PCD_CommunicateWithPICC()
	; Prepare values for BitFramingReg
	movf mfrc522_validBits, w
	movwf mfrc522_txLastBits
	
	;save rxAlign
	movf mfrc522_rxAlign, w
	movwf mfrc522_tmp
	
	bcf STATUS, C				;rxAlign << 4
	rlf mfrc522_rxAlign, f
	bcf STATUS, C
	rlf mfrc522_rxAlign, f
	bcf STATUS, C
	rlf mfrc522_rxAlign, f
	bcf STATUS, C
	rlf mfrc522_rxAlign, w
	
	addwf mfrc522_txLastBits, w ; RxAlign = BitFramingReg[6..4]. TxLastBits = BitFramingReg[2..0]
	movwf mfrc522_bitFraming	;(rxAlign << 4) + txLastBits
	
	;restore rxAlign
	movf mfrc522_tmp, w
	movwf mfrc522_rxAlign
	
	;PCD_WriteRegister(CommandReg, PCD_Idle);			// Stop any active command.
	movlw CommandReg		; 0x02
	movwf mfrc522_register
	movlw PCD_Idle			; 0x00
	movwf mfrc522_value
	call MFRC522_PCD_WriteRegister
	
	;PCD_WriteRegister(ComIrqReg, 0x7F);				// Clear all seven interrupt request bits
	movlw ComIrqReg			; 0x08
	movwf mfrc522_register
	movlw 0x7F
	movwf mfrc522_value
	call MFRC522_PCD_WriteRegister
	
	;PCD_WriteRegister(FIFOLevelReg, 0x80);				// FlushBuffer = 1, FIFO initialization
	movlw FIFOLevelReg		; 0x14
	movwf mfrc522_register
	movlw 0x80
	movwf mfrc522_value
	call MFRC522_PCD_WriteRegister
	
	;PCD_WriteRegister(FIFODataReg, sendLen, sendData);	// Write sendData to the FIFO
	;	mfrc522_OUT_byteArray+0	already set
	;	mfrc522_OUT_bytesCount	already set
	movlw FIFODataReg		; 0x12
	movwf mfrc522_register
	call MFRC522_PCD_WriteBufToRegister
		
	;PCD_WriteRegister(BitFramingReg, bitFraming);		// Bit adjustments
	movlw BitFramingReg		; 0x1A
	movwf mfrc522_register
	movf mfrc522_bitFraming, w
	movwf mfrc522_value
	call MFRC522_PCD_WriteRegister
	
	;PCD_WriteRegister(CommandReg, command);			// Execute the command
	movlw CommandReg		; 0x02
	movwf mfrc522_register
	movf mfrc522_command, w	; 0x0C - PCD_Transceive
	movwf mfrc522_value
	call MFRC522_PCD_WriteRegister
	
	;PCD_SetRegisterBitMask(BitFramingReg, 0x80);		// StartSend=1, transmission of data starts
	movlw BitFramingReg		; 0x1A
	movwf mfrc522_register
	movlw 0x80
	movwf mfrc522_mask
	call MFRC522_PCD_SetRegisterBitMask		

	; Wait for the command to complete.
	; In PCD_Init() we set the TAuto flag in TModeReg. This means the timer automatically starts when the PCD stops transmitting.
	; Each iteration of the do-while-loop takes 17.86us (on Arduino Uno)
	movlw HIGH .1000		;Was 2000, Arduino @16MHz, we are @8MHz
	movwf mfrc522_hiByte
	movlw LOW .1000
	movwf mfrc522_loByte
	
	movlw ComIrqReg			; 0x08
	movwf mfrc522_register
	
Transceive_waitIRQ
	call MFRC522_PCD_ReadRegister	;// ComIrqReg[7..0] bits are: Set1 TxIRq RxIRq IdleIRq HiAlertIRq LoAlertIRq ErrIRq TimerIRq
	movf mfrc522_waitIRq, w			;if (SPI_value & waitIRq) then break
	andwf SPI_value, w				; One of the interrupts that signal success has been set.
	btfss STATUS, Z
	goto Transceive_break
	
	movlw 0x01						;if (SPI_value & 0x01) then break
	andwf SPI_value, w				;Timer interrupt - nothing received in 25ms
	btfss STATUS, Z
	goto Transceive_TIMEOUT
	
	call MFRC522_decHL
	btfsc STATUS, Z					; The emergency break. If all other conditions fail we will eventually terminate on this one after 35.7ms. Communication with the MFRC522 might be down.
	
	; 35.7ms and nothing happened. Communication with the MFRC522 might be down.
	goto Transceive_TIMEOUT			; if (i == 0) return STATUS_TIMEOUT
	goto Transceive_waitIRQ			
	
Transceive_break
	
	;Stop now if any errors except collisions were detected.
	movlw ErrorReg				; 0x0C - ErrorReg[7..0] bits are: WrErr TempErr reserved BufferOvfl CollErr CRCErr ParityErr ProtocolErr
	movwf mfrc522_register
	call MFRC522_PCD_ReadRegister
	movf SPI_value, w				
	movwf mfrc522_errorRegValue
	movlw 0x13						; BufferOvfl ParityErr ProtocolErr
	andwf mfrc522_errorRegValue, w
	btfss STATUS, Z
	goto Transceive_ERROR
	
	; If the caller wants data back, get it from the MFRC522.
	
	movlw FIFOLevelReg			; 0x14
	movwf mfrc522_register
	call MFRC522_PCD_ReadRegister

	;TODO check that mfrc522_IN_bytesCount > SPI_value, abychom nepretekli
	
	movf SPI_value, w
	movwf mfrc522_IN_bytesCount		; Number of bytes returned
	
	;PCD_ReadRegister(FIFODataReg, n, backData, rxAlign);
	;Get received data from FIFO
	movlw FIFODataReg			; 0x12
	movwf mfrc522_register
	call MFRC522_PCD_ReadRegisterToBuffer
	
	movlw ControlReg			; 0x18
	movwf mfrc522_register
	call MFRC522_PCD_ReadRegister	; RxLastBits[2:0] indicates the number of valid bits in the last received byte. If this value is 000b, the whole byte is valid.
	movlw 0x07
	andwf SPI_value, f				; chci & 0x07 mit ulozene (jako _validBits)
	btfsc STATUS, Z
	goto Transceive_validBits
	movf SPI_value, w
	movwf mfrc522_validBits

Transceive_validBits
	movwf mfrc522_validBits2		;_validBits	
	
	; Tell about collisions
	movlw 0x08						;CollErr
	andwf mfrc522_errorRegValue, w
	btfss STATUS, Z
	goto Transceive_COLLISION
	
	;TODO check if CRC_A validation Arduino code is needed here
	
	movlw STATUS_OK
	goto Transceive_setStatus	
	
Transceive_COLLISION
	movlw STATUS_COLLISION
	goto Transceive_setStatus		
	
Transceive_ERROR
	movlw STATUS_ERROR
	goto Transceive_setStatus	
	
Transceive_TIMEOUT
	movlw STATUS_TIMEOUT

Transceive_setStatus	
	movwf mfrc522_status
	return
;}


MFRC522_PCD_WriteRegister
;{
	bcf MFRC522_CS			; Zacatek operace
	
	movf mfrc522_register, w
	; MSB == 0 is for writing. LSB is not used in address. Datasheet section 8.1.2.3.
	call SPI_send
	
	movf mfrc522_value, w
	call SPI_send
	
	bsf MFRC522_CS			; Konec operace
	
	return
;}  

;Vstup
;	mfrc522_register
;	mfrc522_OUT_bytesCount		;pocet bytes k odeslani
;	mfrc522_OUT_byteArray		;zacatek bufferu
MFRC522_PCD_WriteBufToRegister
;{
	bcf MFRC522_CS			; Zacatek operace
	
	movf mfrc522_register, w
	call SPI_send
	
	BANK1
	movlw mfrc522_OUT_byteArray+0
	BANK0
	movwf FSR
	
	movf mfrc522_OUT_bytesCount, w
	movwf mfrc522_j	
	
WriteBufferLoop

	movf INDF, w
	call SPI_send
	
	incf FSR, f
	
	decfsz mfrc522_j, f
	goto WriteBufferLoop
	
	bsf MFRC522_CS			; Konec operace	
	
	return
;}

MFRC522_PCD_ReadRegister
;{
	bcf MFRC522_CS			; Zacatek operace
	
	movf mfrc522_register, w	
	iorlw 0x80				; MSB == 1 is for reading. LSB is not used in address. Datasheet section 8.1.2.3.
	call SPI_send
	
	movlw .0				; Read the value back. Send 0 to stop reading.
	call SPI_send
	
	bsf MFRC522_CS			; Konec operace
	
	return
;}  
	
;Vstup: mfrc522_rxAlign - only bit positions rxAlign..7 in values[0] are updated.
;Vstup: mfrc522_IN_bytesCount	
;Vystup: uklada data z FIFO MFRC522 do mfrc522_IN_byteArray
;  Reads a number of bytes from the specified register in the MFRC522 chip.
;  The interface is described in the datasheet section 8.1.2.
MFRC522_PCD_ReadRegisterToBuffer
;{
	
	;if (count == 0) return
	movf mfrc522_IN_bytesCount, f
	btfsc STATUS, Z
	return
	
	bcf MFRC522_CS			; Zacatek operace
	
	
	clrf mfrc522_index
	decf mfrc522_IN_bytesCount, f	;Posledni read se bude delat zvlast
	
	movf mfrc522_register, w			
	iorlw 0x80				; MSB == 1 is for reading. LSB is not used in address. Datasheet section 8.1.2.3.	
	movwf mfrc522_register	; Uloz 
	call SPI_send			; Tell MFRC522 which address we want to read

	;if (rxAlign) {}
	movf mfrc522_rxAlign, f		; Only update bit positions rxAlign..7 in values[0]
	btfsc STATUS, Z
	goto ReadRegisterToBufferNext
	
	;Create bit mask for bit positions rxAlign..7
	movlw 0xFF
	movwf mfrc522_tmp
	movf mfrc522_rxAlign, w
	movwf mfrc522_i			;(0xFF << rxAlign)
createMask
	bcf STATUS, C
	rlf mfrc522_tmp, f
	decfsz mfrc522_i, f
	goto createMask
	
	movlw 0xFF
	andwf mfrc522_tmp, w
	movwf mfrc522_mask		;byte mask = (0xFF << rxAlign) & 0xFF;
	
	;Read value and tell that we want to read the same address again.
	movf mfrc522_register, w
	call SPI_send
	;Apply mask to both current value of values[0] and the new data in value.
	
	;values[0] = (values[0] & ~mask) | (value & mask);
	;mfrc522_IN_byteArray[0] = (mfrc522_IN_byteArray[0] & ~mask) | (SPI_value & mask);
	clrf mfrc522_IN_offset
	call MFRC522_getInputBufValueAtIndex	;mfrc522_value = mfrc522_IN_byteArray[0]
	comf mfrc522_mask, w			;~mask
	andwf mfrc522_value, f			;mfrc522_value = mfrc522_value & ~mask
	
	movf mfrc522_mask, w			;SPI_value & mask -> WREG
	andwf SPI_value, w
	
	iorwf mfrc522_value, f			;(mfrc522_value & ~mask) | (SPI_value & mask)
	clrf mfrc522_IN_offset			;[0]
	call MFRC522_setInputBufValueAtIndex ; result to mfrc522_IN_byteArray[0]	
	
	incf mfrc522_index, f

	;end (rxAlign)
	
ReadRegisterToBufferNext

	;while (index < count) {}
	movf mfrc522_index, w			; index < count
	subwf mfrc522_IN_bytesCount, w
	btfsc STATUS, Z					;equals == loop break	
	goto ReadRegisterToBuffer_Next2
	
	movf mfrc522_register, w
	call SPI_send
	
	movf mfrc522_index, w
	movwf mfrc522_IN_offset
	
	movf SPI_value, w
	movwf mfrc522_value
	call MFRC522_setInputBufValueAtIndex ;mfrc522_IN_byteArray[index]
	
	incf mfrc522_index, f
	goto ReadRegisterToBufferNext		
	;end while(index < count)
	
ReadRegisterToBuffer_Next2
	;values[index] = SPI.transfer(0);			// Read the final byte. Send 0 to stop reading.
	clrw
	call SPI_send
	movf SPI_value, w
	movwf mfrc522_value
	
	movf mfrc522_index, w
	movwf mfrc522_IN_offset
	call MFRC522_setInputBufValueAtIndex
	
	bsf MFRC522_CS			; Konec operace
	
	return	
;}

;Vstup: mfrc522_IN_offset
;Vystup: mfrc522_IN_byteArray[offset] -> mfrc522_value
MFRC522_getInputBufValueAtIndex
;{
	BANK1
	movlw mfrc522_IN_byteArray+0
	BANK0
	movwf FSR
	movf mfrc522_IN_offset, w
	addwf FSR, f	
	movf INDF, w
	movwf mfrc522_value
	return
;}

;Vstup: mfrc522_OUT_offset
;Vystup: mfrc522_OUT_byteArray[offset] = mfrc522_value
MFRC522_getOutputBufValueAtIndex
;{
	BANK1
	movlw mfrc522_OUT_byteArray+0
	BANK0
	movwf FSR
	movf mfrc522_OUT_offset, w
	addwf FSR, f	
	movf INDF, w
	movwf mfrc522_value
	return
;}

;Vstup: mfrc522_IN_offset
;Vstup: mfrc522_value
;Nastavi mfrc522_IN_byteArray[offset] = value
MFRC522_setInputBufValueAtIndex
;{
	BANK1
	movlw mfrc522_IN_byteArray+0
	BANK0
	movwf FSR
	movf mfrc522_IN_offset, w
	addwf FSR, f
	movf mfrc522_value, w
	movwf INDF
	return
;}

;Vstup: mfrc522_OUT_offset
;Vstup: mfrc522_value
;Nastavi mfrc522_OUT_byteArray[offset] = value
MFRC522_setOutputBufValueAtIndex
;{
	BANK1
	movlw mfrc522_OUT_byteArray+0
	BANK0
	movwf FSR
	movf mfrc522_OUT_offset, w
	addwf FSR, f
	movf mfrc522_value, w
	movwf INDF
	return
;}


;Vstup - mfrc522_register
;Vstup - mfrc522_mask
MFRC522_PCD_ClearRegisterBitMask
;{
	call MFRC522_PCD_ReadRegister	; Nacti do SPI_value
	comf mfrc522_mask, f			; komplement
	movf SPI_value, w
	andwf mfrc522_mask, w			; clear bit mask
	movwf mfrc522_value
	call MFRC522_PCD_WriteRegister
	return
	
;}

;Vstup - mfrc522_register
;Vstup - mfrc522_mask
MFRC522_PCD_SetRegisterBitMask
;{
	call MFRC522_PCD_ReadRegister	; Nacti do SPI_value	
	movf SPI_value, w
	iorwf mfrc522_mask, w			; set bit mask
	movwf mfrc522_value
	call MFRC522_PCD_WriteRegister
	return	
;}
		

;Vstup: W-reg binarni hodnota 0-15
;Vystup W-reg znak '0'-'9', 'A'-'F'
UTIL_bin2char
;{
		movwf tmp
			
		movlw HIGH UTIL_bin2charTable
		movwf PCLATH
		movf tmp, w
		addwf PCL, f
;}
		
UTIL_bin2charTable
;{
			dt '0'
			dt '1'
			dt '2'
			dt '3'
			dt '4'
			dt '5'
			dt '6'
			dt '7'
			dt '8'
			dt '9'
			dt 'A'
			dt 'B'
			dt 'C'
			dt 'D'
			dt 'E'
			dt 'F'
;}

;Spocita X % 8
;Vstup X = WReg 
UTIL_mod8
;{
	movwf d1		;uloz X -> d1
	call UTIL_div8	;spocitej X / 8  -> WREG
	
	movwf tmp		; 8 * (X/8)
	bcf STATUS, C
	rlf tmp, f
	bcf STATUS, C
	rlf tmp, f
	bcf STATUS, C
	rlf tmp, w	
		
	subwf d1, w		;X - (X/8)
	return
;}
	
;Spocita X / 8	
;Vstup X = WREG
UTIL_div8
;{
	movwf tmp
	bcf STATUS, C
	rrf tmp, f
	bcf STATUS, C
	rrf tmp, f
	bcf STATUS, C
	rrf tmp, w		
	return
;}
	
;Spocita 1<<X
;Vstup X = WREG
UTIL_shiftLeftX
;{
	movwf d1		;X -> d1
	movlw .1
	movf d1, f		;1<<0?
	btfsc STATUS, Z
	return			;return 1 - WREG
	movwf tmp		;tmp = 1
	
UTIL_shiftLeftXLoop
	bcf STATUS, C
	rlf tmp, f
	decfsz d1, f
	goto UTIL_shiftLeftXLoop	
	
	movf tmp, w
	return
;}

		
; ********************************************************************************
; ************************ C E K A C I   S M Y C K Y *****************************
; ********************************************************************************
waitSecs
;{
		movwf numSecs
waitS	call wait1s
		decfsz numSecs, f
		goto waitS
		return
;}

waitMilis
;{
		movwf numMilis
waitM	call wait1ms
		decfsz numMilis, f
		goto waitM
		return
;}


; Clock frequency = 8 MHz
wait1ms
;{
			;1993 cycles
	movlw	0x8E
	movwf	d1
	movlw	0x02
	movwf	d2
wait1ms_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	wait1ms_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return
;}



; Clock frequency = 8 MHz
wait1s
;{
			;1999996 cycles
	movlw	0x11
	movwf	d1
	movlw	0x5D
	movwf	d2
	movlw	0x05
	movwf	d3
wait1s_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	wait1s_0

			;4 cycles (including call)
	return
;}


; ********************************************************************************
; **************** SUBRUTINY pro 16bitovy counter ********************************	
; ********************************************************************************

; Nastavi Zero, pokud jsme na nule
MFRC522_decHL
;{	
		movf mfrc522_loByte, f
		btfsc STATUS, Z ;je loByte na nule?
		goto MFRC522_decHL2
		decf mfrc522_loByte, w	;kopie pro nasledny OR (test na 0)
		decf mfrc522_loByte, f
		iorwf mfrc522_hiByte, w ;Z flag nastaven pri 0 (loByte OR hiByte)
		return
MFRC522_decHL2	
		decf mfrc522_loByte, f
		decf mfrc522_hiByte, f
		bcf STATUS, Z ;Potrebuju vynulovat Zero (aby mi pri lo/hi 0/1 predchozi decf Z nenastavil)
		return
;}



				org 0x0800
Table_Texty
;{
T_PLAYER1		dt "* PLAYER 1 *", 0x00
T_PLAYER2		dt "* PLAYER 2 *", 0x00
T_PRESS_START	dt "  PRESS START ", 0x00
T_FIND_ALL_FOBS	dt "FIND ALL FOBS", 0x00
T_GAME_OVER		dt "  GAME OVER  ", 0x00
T_PLAYER1_WINS	dt "PLAYER 1 WINS!", 0x00
T_PLAYER2_WINS	dt "PLAYER 2 WINS!", 0x00
Table_Texty_end
Table_Texty_len	equ Table_Texty_end - Table_Texty
;}
;LEN: 99B

	
; ******************************************************************************
; ************************* FONTY A GRAFICKA DATA ******************************
; ******************************************************************************
			
				org 0x0900
Table_emptyCircle		
;{		
				dt 0x07, 0xE0	;      ######     
				dt 0x18, 0x18	;    ##      ##   
				dt 0x20, 0x04	;   #          #  
				dt 0x40, 0x02	;  #            # 
				dt 0x40, 0x02	;  #            # 
				dt 0x80, 0x01	; #              #
				dt 0x80, 0x01	; #              #
				dt 0x80, 0x01	; #              #
				dt 0x80, 0x01	; #              #
				dt 0x80, 0x01	; #              #
				dt 0x80, 0x01	; #              #
				dt 0x40, 0x02	;  #            # 
				dt 0x40, 0x02	;  #            # 
				dt 0x20, 0x04	;   #          #  
				dt 0x18, 0x18	;    ##      ##   
				dt 0x07, 0xE0	;      ######     
Table_emptyCircle_end
Table_emptyCircle_len	equ Table_emptyCircle_end - Table_emptyCircle
;LEN: 32B
;}
				
Table_fullCircle
;{
				dt 0x07, 0xE0 ;       ######     
				dt 0x1F, 0xF8 ;     ##########   
				dt 0x3F, 0xFC ;    ############  
				dt 0x7F, 0xFE ;   ############## 
				dt 0x7F, 0xFE ;   ############## 
				dt 0xFF, 0xFF ;  ################
				dt 0xFF, 0xFF ;  ################
				dt 0xFF, 0xFF ;  ################
				dt 0xFF, 0xFF ;  ################
				dt 0xFF, 0xFF ;  ################
				dt 0xFF, 0xFF ;  ################
				dt 0x7F, 0xFE ;   ############## 
				dt 0x7F, 0xFE ;   ############## 
				dt 0x3F, 0xFC ;    ############  
				dt 0x1F, 0xF8 ;     ##########   
				dt 0x07, 0xE0 ;       ######    
Table_fullCircle_end
Table_fullCircle_len	equ Table_fullCircle_end - Table_fullCircle
;LEN: 32B

Table_font_5x8
					; code=48, hex=0x30  ; ascii="0"
					dt 0x00  ;  /* 00000 */
					dt 0x00  ;  /* 00000 */
					dt 0x60  ;  /* 01100 */
					dt 0x90  ;  /* 10010 */
					dt 0x90  ;  /* 10010 */
					dt 0x90  ;  /* 10010 */
					dt 0x60  ;  /* 01100 */
					dt 0x00  ;  /* 00000 */
					; code=49, hex=0x31, ascii="1"
					dt 0x00  ;  /* 00000 */
					dt 0x00  ;  /* 00000 */
					dt 0x20  ;  /* 00100 */
					dt 0x60  ;  /* 01100 */
					dt 0x20  ;  /* 00100 */
					dt 0x20  ;  /* 00100 */
					dt 0x20  ;  /* 00100 */
					dt 0x00  ;  /* 00000 */
					; code=50  ; hex=0x32, ascii="2"
					dt 0x00  ;  /* 00000 */
					dt 0x00  ;  /* 00000 */
					dt 0x60  ;  /* 01100 */
					dt 0x90  ;  /* 10010 */
					dt 0x20  ;  /* 00100 */
					dt 0x40  ;  /* 01000 */
					dt 0xF0  ;  /* 11110 */
					dt 0x00  ;  /* 00000 */
					; code=51, hex=0x33, ascii="3"
					dt 0x00  ;  /* 00000 */
					dt 0x00  ;  /* 00000 */
					dt 0xE0  ;  /* 11100 */
					dt 0x10  ;  /* 00010 */
					dt 0x60  ;  /* 01100 */
					dt 0x10  ;  /* 00010 */
					dt 0xE0  ;  /* 11100 */
					dt 0x00  ;  /* 00000 */
					; code=52, hex=0x34, ascii="4"
					dt 0x00  ;  /* 00000 */
					dt 0x00  ;  /* 00000 */
					dt 0x10  ;  /* 00010 */
					dt 0x30  ;  /* 00110 */
					dt 0x50  ;  /* 01010 */
					dt 0xF0  ;  /* 11110 */
					dt 0x10  ;  /* 00010 */
					dt 0x00  ;  /* 00000 */
					; code=53, hex=0x35, ascii="5"
					dt 0x00  ;  /* 00000 */
					dt 0x00  ;  /* 00000 */
					dt 0xF0  ;  /* 11110 */
					dt 0x80  ;  /* 10000 */
					dt 0xE0  ;  /* 11100 */
					dt 0x10  ;  /* 00010 */
					dt 0xE0  ;  /* 11100 */
					dt 0x00  ;  /* 00000 */
					; code=54, hex=0x36, ascii="6"
					dt 0x00  ;  /* 00000 */
					dt 0x00  ;  /* 00000 */
					dt 0x60  ;  /* 01100 */
					dt 0x80  ;  /* 10000 */
					dt 0xE0  ;  /* 11100 */
					dt 0x90  ;  /* 10010 */
					dt 0x60  ;  /* 01100 */
					dt 0x00  ;  /* 00000 */
					; code=55, hex=0x37, ascii="7"
					dt 0x00  ;  /* 00000 */
					dt 0x00  ;  /* 00000 */
					dt 0xF0  ;  /* 11110 */
					dt 0x10  ;  /* 00010 */
					dt 0x20  ;  /* 00100 */
					dt 0x40  ;  /* 01000 */
					dt 0x40  ;  /* 01000 */
					dt 0x00  ;  /* 00000 */
					; code=56, hex=0x38, ascii="8"
					dt 0x00  ;  /* 00000 */
					dt 0x00  ;  /* 00000 */
					dt 0x60  ;  /* 01100 */
					dt 0x90  ;  /* 10010 */
					dt 0x60  ;  /* 01100 */
					dt 0x90  ;  /* 10010 */
					dt 0x60  ;  /* 01100 */
					dt 0x00  ;  /* 00000 */
					; code=57, hex=0x39, ascii="9"
					dt 0x00  ;  /* 00000 */
					dt 0x00  ;  /* 00000 */
					dt 0x60  ;  /* 01100 */
					dt 0x90  ;  /* 10010 */
					dt 0x70  ;  /* 01110 */
					dt 0x10  ;  /* 00010 */
					dt 0x60  ;  /* 01100 */
					dt 0x00  ;  /* 00000 */
;}
;LEN: 80B

Table_font8x9				
;{
			   dt 0xC4,0xCE,0xDB,0xDB,0xDB,0xDB,0xDB,0xCE,0xC4 ; 0 - 10
			   dt 0x18,0xF8,0x18,0x18,0x18,0x18,0x18,0x18,0xFF ; 1 
			   dt 0x7C,0xC6,0xC6,0x06,0x0C,0x18,0x30,0x60,0xFE ; 2
			   dt 0x7C,0x86,0x06,0x06,0x3C,0x06,0x06,0x86,0x7C ; 3
			   dt 0x1C,0x1C,0x3C,0x2C,0x6C,0x4C,0xFE,0x0C,0x3E ; 4
			   dt 0x7C,0x60,0x60,0x78,0x4C,0x0C,0x0C,0x8C,0x78 ; 5
			   dt 0x1E,0x70,0x60,0xDC,0xE6,0xC6,0xC6,0x66,0x3C ; 6
			   dt 0xFC,0x8C,0x0C,0x18,0x18,0x18,0x38,0x30,0x30 ; 7
			   dt 0x7C,0xC6,0xC6,0xC6,0x7C,0xC6,0xC6,0xC6,0x7C ; 8
			   dt 0x78,0xCC,0xC6,0xC6,0xCE,0x76,0x0C,0x1C,0xF0 ; 9
			   dt 0xC4,0xCE,0xDB,0xDB,0xDB,0xDB,0xDB,0xCE,0xC4 ; 10
;}
;LEN: 99B

;TOTAL LEN: 32 + 32 + 80 + 99 = 243B

;--------------------------------------------------------------------------------

				org 0x0A00
;FOBIACS logo
Table_SplashScree
;{

Table_Splash1	;256B
		
				dt 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF  ; ########################################################################################################
				dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01  ; #                                                                                                      #
				dt 0x8A, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xA1  ; #   # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #    #
				dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01  ; #                                                                                                      #
				dt 0x8F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF1  ; #   ################################################################################################   #
				dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01  ; #                                                                                                      #
				dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01  ; #                                                                                                      #
				dt 0x87, 0xFF, 0x01, 0xF0, 0x1F, 0xF8, 0x1F, 0x83, 0xF8, 0x01, 0xFC, 0x1F, 0xC1  ; #    ###########       #####       ##########      ######     #######          #######     #######     #
				dt 0x87, 0xFF, 0x07, 0xFC, 0x1F, 0xFF, 0x1F, 0x83, 0xF8, 0x07, 0xFC, 0x7F, 0xC1  ; #    ###########     #########     #############   ######     #######        #########   #########     #
				dt 0x87, 0xFF, 0x0F, 0xFE, 0x1F, 0xFF, 0x9F, 0x83, 0xF8, 0x0F, 0xFC, 0xFF, 0xC1  ; #    ###########    ###########    ##############  ######     #######       ##########  ##########     #
				dt 0x87, 0xFF, 0x1F, 0xFF, 0x1F, 0xFF, 0xDF, 0x87, 0xFC, 0x1F, 0xFD, 0xFF, 0xC1  ; #    ###########   #############   ############### ######    #########     ########### ###########     #
				dt 0x87, 0xFF, 0x1F, 0xFF, 0x1F, 0xFF, 0xDF, 0x87, 0xFC, 0x3F, 0xFD, 0xFF, 0xC1  ; #    ###########   #############   ############### ######    #########    ############ ###########     #
				dt 0x87, 0xFF, 0x3F, 0xFF, 0x9F, 0xFF, 0xDF, 0x87, 0xFC, 0x3F, 0xFD, 0xFF, 0xC1  ; #    ###########  ###############  ############### ######    #########    ############ ###########     #
				dt 0x87, 0xFF, 0x3F, 0xFF, 0x9F, 0xFF, 0xDF, 0x87, 0xFC, 0x7F, 0xFD, 0xFF, 0xC1  ; #    ###########  ###############  ############### ######    #########   ############# ###########     #
				dt 0x87, 0xE0, 0x3F, 0xFF, 0x9F, 0x87, 0xDF, 0x87, 0xFE, 0x7F, 0xFC, 0xFF, 0xC1  ; #    ######       ###############  ######    ##### ######    ##########  #############  ##########     #
				dt 0x87, 0xE0, 0x3F, 0x3F, 0x9F, 0x87, 0xDF, 0x8F, 0xFE, 0x7F, 0x80, 0x7E, 0x01  ; #    ######       ######  #######  ######    ##### ######   ###########  ########        ######        #
				dt 0x87, 0xE0, 0x3F, 0x1F, 0x9F, 0xFF, 0x9F, 0x8E, 0xFE, 0x7F, 0x00, 0x3E, 0x01  ; #    ######       ######   ######  ##############  ######   ### #######  #######          #####        #
				dt 0x87, 0xE0, 0x3F, 0x1F, 0x9F, 0xFF, 0x1F, 0x8E, 0xFE, 0x7E, 0x00, 0x1E, 0x01  ; #    ######       ######   ######  #############   ######   ### #######  ######            ####        #
				dt 0x87, 0xFE, 0x3F, 0x1F, 0x9F, 0xFF, 0x1F, 0x8C, 0x7F, 0x7E, 0x00, 0x0F, 0x01  ; #    ##########   ######   ######  #############   ######   ##   ####### ######             ####       #
				dt 0x87, 0xFC, 0x1F, 0x1F, 0x1F, 0x87, 0x9F, 0x9C
Table_Splash1_end
Table_Splash1_len	equ Table_Splash1_end - Table_Splash1
				
				org 0x0B00
Table_Splash2	;Zbytek			
				dt 0x7F, 0x3E, 0x00, 0x0F, 0x81  ; #    #########     #####   #####   ######    ####  ######  ###   #######  #####             #####      #
				dt 0x87, 0xFC, 0x1F, 0xBF, 0x1F, 0x87, 0x9F, 0x9C, 0x3F, 0x3F, 0x80, 0x0F, 0x81  ; #    #########     ###### ######   ######    ####  ######  ###    ######  #######           #####      #
				dt 0x87, 0xE0, 0x0F, 0xFE, 0x1F, 0xFF, 0x9F, 0x9C, 0x7F, 0x1F, 0xFC, 0x7F, 0x81  ; #    ######         ###########    ##############  ######  ###   #######   ###########   ########      #
				dt 0x87, 0xE0, 0x0F, 0xFE, 0x1F, 0xFF, 0x9F, 0x9B, 0xFF, 0x0F, 0xF8, 0x7F, 0x81  ; #    ######         ###########    ##############  ######  ## ##########    #########    ########      #
				dt 0x87, 0xE0, 0x07, 0xFC, 0x1F, 0xFF, 0x1F, 0xBB, 0xBF, 0x87, 0xF8, 0x3F, 0x01  ; #    ######          #########     #############   ###### ### ### #######    ########     ######       #
				dt 0x87, 0xE0, 0x01, 0xF0, 0x1F, 0xF8, 0x1F, 0xB9, 0x1F, 0x81, 0xF8, 0x3E, 0x01  ; #    ######            #####       ##########      ###### ###  #   ######      ######     #####        #
				dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01  ; #                                                                                                      #
				dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01  ; #                                                                                                      #
				dt 0x8F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF1  ; #   ################################################################################################   #
				dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01  ; #                                                                                                      #
				dt 0x8A, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xA1  ; #   # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #    #
				dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01  ; #                                                                                                      #
				dt 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF  ; ########################################################################################################
Table_Splash2_end
Table_Splash2_len	equ Table_Splash2_end - Table_Splash2
;}

; ******************************************************************************
; ****************************** T E X T Y *************************************
; ******************************************************************************


				org 0x0C00
;16 radku x 16bytes = 256Bytes = 1 page
Table_font8x16
;{
Table_Font1	
				dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ; " " (dec 32)
				dt 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00 
				dt 0x6c, 0x6c, 0x6c, 0x6c, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
				dt 0x6c, 0x6c, 0x6c, 0x6c, 0xfe, 0xfe, 0x6c, 0x6c, 0xfe, 0xfe, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00 
				dt 0x10, 0x10, 0x7c, 0x7c, 0xd0, 0xd0, 0x7c, 0x7c, 0x16, 0x16, 0x16, 0x16, 0x7c, 0x7c, 0x10, 0x10 
				dt 0x60, 0x60, 0x96, 0x96, 0x6c, 0x6c, 0x18, 0x18, 0x30, 0x30, 0x6c, 0x6c, 0xd2, 0xd2, 0x0c, 0x0c 
				dt 0x70, 0x70, 0xd8, 0xd8, 0x70, 0x70, 0xf6, 0xf6, 0xdc, 0xdc, 0xd8, 0xd8, 0x7c, 0x7c, 0x06, 0x06 
				dt 0x18, 0x18, 0x18, 0x18, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
				dt 0x03, 0x07, 0x0e, 0x0c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0c, 0x0e, 0x07, 0x03, 0x00, 0x00 
				dt 0xc0, 0xe0, 0x70, 0x30, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x30, 0x70, 0xe0, 0xc0, 0x00, 0x00 
				dt 0x00, 0x00, 0x6c, 0x6c, 0x38, 0x38, 0xfe, 0xfe, 0x38, 0x38, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00 
				dt 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00 
				dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x30, 0x30 
				dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
				dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00 
				dt 0x03, 0x03, 0x06, 0x06, 0x0c, 0x0c, 0x18, 0x18, 0x30, 0x30, 0x60, 0x60, 0xc0, 0xc0, 0x80, 0x80 
Table_Font2				
				dt 0x00, 0x00, 0x78, 0x78, 0xcc, 0xcc, 0xde, 0xde, 0xf6, 0xf6, 0xe6, 0xe6, 0x7c, 0x7c, 0x00, 0x00 
				dt 0x18, 0x18, 0x18, 0x18, 0x38, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x7e, 0x00, 0x00 
				dt 0x7c, 0x7c, 0x06, 0x06, 0x3c, 0x3c, 0x60, 0x60, 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0xfe, 0x00, 0x00 
				dt 0x3c, 0x3c, 0x06, 0x06, 0x1c, 0x1c, 0x06, 0x06, 0x46, 0x46, 0xc6, 0xc6, 0x7c, 0x7c, 0x00, 0x00 
				dt 0x18, 0x18, 0x18, 0x18, 0x30, 0x30, 0x6c, 0x6c, 0xcc, 0xcc, 0xfe, 0xfe, 0x0c, 0x0c, 0x00, 0x00 
				dt 0xf8, 0xf8, 0xc0, 0xc0, 0xfc, 0xfc, 0x06, 0x06, 0x46, 0x46, 0xcc, 0xcc, 0x78, 0x78, 0x00, 0x00 
				dt 0x70, 0x70, 0xc0, 0xc0, 0xfc, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0xcc, 0xcc, 0x78, 0x78, 0x00, 0x00 
				dt 0xfe, 0xfe, 0x06, 0x06, 0x0c, 0x0c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00 
				dt 0x78, 0x78, 0xcc, 0xcc, 0x7c, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xcc, 0xcc, 0x78, 0x78, 0x00, 0x00 
				dt 0x78, 0x78, 0xcc, 0xcc, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x7e, 0x06, 0x06, 0x1c, 0x1c, 0x00, 0x00 
				dt 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00 
				dt 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x30, 0x30 
				dt 0x03, 0x03, 0x06, 0x06, 0x0c, 0x0c, 0x18, 0x18, 0x0c, 0x0c, 0x06, 0x06, 0x03, 0x03, 0x00, 0x00 
				dt 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00 
				dt 0xc0, 0xc0, 0x60, 0x60, 0x30, 0x30, 0x18, 0x18, 0x30, 0x30, 0x60, 0x60, 0xc0, 0xc0, 0x00, 0x00 
				dt 0x7c, 0x7c, 0xc6, 0xc6, 0x06, 0x06, 0x3c, 0x3c, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00 
Table_Font3		
				dt 0x7c, 0x7c, 0xc6, 0xc6, 0xde, 0xde, 0xd6, 0xd6, 0xde, 0xde, 0xc0, 0xc0, 0x7e, 0x7e, 0x00, 0x00 
				dt 0x78, 0x78, 0xcc, 0xcc, 0xc6, 0xc6, 0xfe, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00 
				dt 0xf8, 0xf8, 0xcc, 0xcc, 0xfc, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0xcc, 0xcc, 0xf8, 0xf8, 0x00, 0x00 
				dt 0x78, 0x78, 0xcc, 0xcc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc6, 0xc6, 0x7c, 0x7c, 0x00, 0x00 
				dt 0xf8, 0xf8, 0xcc, 0xcc, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xfc, 0xfc, 0x00, 0x00 
				dt 0xfe, 0xfe, 0xc0, 0xc0, 0xfc, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0xfe, 0x00, 0x00 
				dt 0xfe, 0xfe, 0xc0, 0xc0, 0xfc, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00 
				dt 0x38, 0x38, 0x60, 0x60, 0xc0, 0xc0, 0xce, 0xce, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x7e, 0x06, 0x06 
				dt 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00 
				dt 0x7e, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x7e, 0x00, 0x00 
				dt 0x0e, 0x0e, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x7c, 0x00, 0x00 
				dt 0xc6, 0xc6, 0xcc, 0xcc, 0xd8, 0xd8, 0xf0, 0xf0, 0xd8, 0xd8, 0xcc, 0xcc, 0xc6, 0xc6, 0x00, 0x00 
				dt 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfe, 0xfe, 0x00, 0x00 
				dt 0xc6, 0xc6, 0xee, 0xee, 0xfe, 0xfe, 0xd6, 0xd6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00 
				dt 0xc6, 0xc6, 0xe6, 0xe6, 0xf6, 0xf6, 0xde, 0xde, 0xce, 0xce, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00 
				dt 0x78, 0x78, 0xcc, 0xcc, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x7c, 0x00, 0x00 
				
Table_Font4				
				dt 0xf8, 0xf8, 0xcc, 0xcc, 0xc6, 0xc6, 0xc6, 0xc6, 0xfc, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00 
				dt 0x78, 0x78, 0xcc, 0xcc, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xd6, 0x7c, 0x7c, 0x0c, 0x0c 
				dt 0xf8, 0xf8, 0xcc, 0xcc, 0xc6, 0xc6, 0xc6, 0xc6, 0xfc, 0xfc, 0xd8, 0xd8, 0xcc, 0xcc, 0x06, 0x06 
				dt 0x78, 0x78, 0xc0, 0xc0, 0x7c, 0x7c, 0x06, 0x06, 0x46, 0x46, 0xc6, 0xc6, 0x7c, 0x7c, 0x00, 0x00 
				dt 0x7e, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00 
				dt 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x7c, 0x00, 0x00 
				dt 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x6c, 0x6c, 0x6c, 0x38, 0x38, 0x38, 0x38, 0x00, 0x00 
				dt 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xd6, 0xfe, 0xfe, 0xee, 0xee, 0xc6, 0xc6, 0x00, 0x00 
				dt 0xc6, 0xc6, 0x6c, 0x6c, 0x38, 0x38, 0x38, 0x38, 0x6c, 0x6c, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00 
				dt 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x7c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x00, 0x00 
				dt 0xfe, 0xfe, 0x0c, 0x0c, 0x18, 0x18, 0x30, 0x30, 0x60, 0x60, 0xc0, 0xc0, 0xfe, 0xfe, 0x00, 0x00 ; "Z" (dec 90)				
;}

;---------------------------------------------------------------------------------

				org 0x2100
EEPROM_Table_UIDs
;{
	
				;Blue - Player1
				dt 0xEE, 0xC2, 0xB9, 0x12
				dt 0xD2, 0x42, 0x30, 0xD0
				dt 0xEE, 0x2C, 0xBA, 0x12
				dt 0xD2, 0x9E, 0xF4, 0xD0
				dt 0x72, 0xC4, 0xB4, 0xD0
				dt 0x32, 0xB7, 0x33, 0xD0
				dt 0xF2, 0xCD, 0x30, 0xD0
				dt 0xEE, 0x4D, 0xBD, 0x12
				dt 0x52, 0x4B, 0x32, 0xD0
				dt 0x52, 0x3B, 0x32, 0xD0
					
				;Red - Player2
				dt 0xA2, 0x05, 0x17, 0xD0
				dt 0xC2, 0x1E, 0x14, 0xD0
				dt 0xF2, 0x9F, 0x16, 0xD0
				dt 0xA2, 0x66, 0xD0, 0xD0
				dt 0xB2, 0x14, 0x14, 0xD0
				dt 0xF2, 0xC7, 0xFF, 0xD0
				dt 0xB2, 0xE1, 0x14, 0xD0
				dt 0x72, 0x94, 0x39, 0xD1
				dt 0x62, 0xF9, 0x3A, 0xD1
				dt 0x02, 0x8E, 0x16, 0xD0

EEPROM_Table_UIDs_end
EEPROM_Table_UIDs_len	equ EEPROM_Table_UIDs_end - EEPROM_Table_UIDs
;}

; *****************************************************************************
; *** KONEC SOUBORU ***********************************************************
; *****************************************************************************
	end