#include "p16F76.inc"

	__CONFIG _WDTE_OFF & _PWRTE_OFF & _BOREN_OFF & _CP_OFF & _FOSC_HS
	    
    errorlevel    -302    

;TODO GAME_over, nelze hrat -> reset hry

;******************************************************************
;****************** P R O M E N N E *******************************
;******************************************************************
    ;BANK 0
    cblock 0x20
;{		
	del1			;registry pro cekaci subrutiny
	del2
	del3
	hiByte
	loByte	
	numSecs
	numMilis
	i
	j
	k
	tmp
	tmp_m			;multiply30
	x2
	x4
	x8
	x16
	eeprom_addr:.3	;24bit adresa pro read
	eeprom_tx
	eeprom_rx
	eeprom_i		;read more bytes
	eeprom_j		;
	tmp24bit:.3		;pocitani 24bit
	tmp16bit:.2		;pocitani 16bit
	dataPointer:.2	;Ukazatel do grafickych dat
	wt588d_i
	wt588d_tmp	

	UTIL_ones
	UTIL_tens
	
	TFT_i				
	TFT_byte		;8bit cislo
	TFT_word:.2		;16bit cislo
	TFT_increment	;board vykreslovani	
	TFT_X:.2		;Pozice pro display window
	TFT_X_MAX:.2
	TFT_Y:.2
	TFT_Y_MAX:.2
	TFT_skip		;Pro vykresleni kamenu do skore boardu
	TFT_pieceFGColor:.2		;foreground
	TFT_pieceBGColor:.2		;background

	JOY_ADresult	
	JOY_increment	;255=-1
	JOY_tmp			;8 -> 0, -1 -> 7
	JOY_whichAdjust ;0-BOARD_x, 1-BOARD_y

	GAME_unableCounter ; ===2 - konec hry, ani jeden z hracu nemohl zahrat
	GAME_wasMove	;Pohnuli jsme kurzorem?
	GAME_playerTurn ;1-white, 2-black
	GAME_piecesLeft ;Pocet zbyvajicich kamenu	
	GAME_pieceType	;0-empty (zelene pozadi)
					;1-white (normal, po polozeni kamene)
					;2-black (normal, po polozeni kamene), 
					;4-white (hratelna prazdna pozice pred polozenim)
					;8-black (hratelna prazdna pozice pred polozenim)
					;16-white (obsazena pozice, cervene pozadi)
					;32-black (obsazena pozice, cervene pozadi)
					;64-cross (nehratelna prazdna pozice, kriz)
					
	GAME_scorePlayer1
	GAME_scorePlayer2
	
	BOARD_x			;pozice [x,y] na boardu [0,0]-[7,7]
	BOARD_y
	BOARD_x_old		;Predchozi pozice
	BOARD_y_old		
	BOARD_x_tmp
	BOARD_y_tmp
	BOARD_i
	BOARD_j
	BOARD_piece			 ;1-white, 2-black, kamen na pozici
	BOARD_direction		 ;Pohyb do smeru 0-7
	BOARD_neighboursByte ;Sousedi v okoli
	BOARD_expectedPiece	 ;Ocekavana barva kamene, 1-white, 2-black
	BOARD_expectedActPiece ;Prave hrana barva kamene, 1-white, 2-black	
	BOARD_tmp
	
    endc
     
    cblock 0x120
    board:.64		;0-empty, 1-white, 2-black
    endc
    
;}

	
;******************************************************************
;****************** K O N S T A N T Y *****************************
;******************************************************************
; Konstanty
;{

FALSE						equ 0x00
TRUE						equ 0x01
DUMMY_BYTE					equ 0x00	

;Hraci
PLAYER_WHITE				equ 0x01
PLAYER_BLACK				equ 0x02

;Deska
BOARD_EMPTY					equ 0x00
BOARD_WHITE					equ 0x01
BOARD_BLACK					equ 0x02
BOARD_WHITE_READY			equ 0x04
BOARD_BLACK_READY			equ 0x08
BOARD_WHITE_OCCUPIED		equ 0x10
BOARD_BLACK_OCCUPIED		equ 0x20
BOARD_CROSS					equ 0x40

;Joystick
JOY1_X_ADC					equ b'11000001' ;ADC Frc clock, AN0, ADC ON
JOY1_Y_ADC					equ b'11001001' ;ADC Frc clock, AN1, ADC ON
JOY2_X_ADC					equ b'11010001' ;ADC Frc clock, AN2, ADC ON
JOY2_Y_ADC					equ b'11011001' ;ADC Frc clock, AN3, ADC ON


;WT588D
SOUND_00_REVERSI			equ 0x00
SOUND_01_MOVE				equ 0x01
SOUND_02_CHANGE1			equ 0x02
SOUND_03_CHANGE2			equ 0x03
SOUND_04_GAMEOVER			equ 0x04
SOUND_05_GUNSHOT			equ 0x05
SOUND_06_ERROR				equ 0x06
SOUND_07_WHITE_UNABLE		equ 0x07
SOUND_08_BLACK_UNABLE		equ 0x08
SOUND_09_WHITE_TURN			equ 0x09
SOUND_0A_BLACK_TURN			equ 0x0A
SOUND_0B_GAME_OVER_VOICE	equ 0x0B
SOUND_0C_TIE				equ 0x0C
SOUND_0D_WHITE_WINS			equ 0x0D
SOUND_0E_BLACK_WINS			equ 0x0E



TFT_HEIGHT 					equ .240 
TFT_WIDTH 					equ .320

SCORE_DIGIT_WIDTH			equ .24
SCORE_DIGIT_HEIGHT			equ .48

;Souradnice levych hornich rohu cislic skore pro oba hrace
P1_TENS_X					equ .256
P1_TENS_Y					equ .16
P1_ONES_X					equ .280
P1_ONES_Y					equ .16

P2_TENS_X					equ .256
P2_TENS_Y					equ .176
P2_ONES_X					equ .280
P2_ONES_Y					equ .176

;HRACI PLOCHA
BOARD_SIZE					equ .8			;8x8 plocha
TILE_SIZE					equ .30 		;px
PIECE_SIZE					equ .24			;px
TILE_PADDING				equ .3

TFT_BLACK       			equ 0x0000
TFT_WHITE       			equ 0xFFFF
TFT_RED         			equ 0xF800
TFT_GREEN       			equ 0x04C0
TFT_LIGHTGREY   			equ 0xC618      
TFT_DARKGREY    			equ 0x5ACB

;}
;******************************************************************
;****************** D E F I N I C E *******************************
;******************************************************************
; Definice
;{   
	
;Joystick vstupy
#define JOY1_VRX		PORTA, RA0
#define JOY1_VRY		PORTA, RA1
#define JOY2_VRX		PORTA, RA2
#define JOY2_VRY		PORTA, RA3
#define JOY1_SW			PORTB, RB0
#define JOY2_SW			PORTB, RB1
	
;SPI EEPROM
#define EEPROM_SDI		PORTC, RC4;		SPI SDI (INPUT)
#define EEPROM_SDO		PORTC, RC5;		SPI SDO (OUTPUT)
#define EEPROM_SCK		PORTC, RC3;		SPI SCK (OUTPUT)
#define EEPROM_CS		PORTC, RC6;		SPI CS  (OUTPUT)

;LEDky
#define TFT_SCK			PORTA, RA7;		(OUTPUT)
#define TFT_MOSI		PORTA, RA6;		(OUTPUT)
#define TFT_DC			PORTC, RC0;		(OUTPUT)
#define TFT_RESET		PORTC, RC1;		(OUTPUT)
#define TFT_CS			PORTC, RC2;		(OUTPUT)

;WT588D   
#define WT588D_SCK		PORTB, RB5;
#define WT588D_CS		PORTB, RB6;
#define WT588D_SDA		PORTB, RB7;

;}

;******************************************************************
;****************** M A K R A *************************************
;******************************************************************
; Makra
;{
BANK0 macro
    bcf STATUS, RP0 ;Select memory bank 0
    bcf STATUS, RP1 
    endm
    
BANK1 macro
    bsf STATUS, RP0 ;Select memory bank 1
    bcf STATUS, RP1 
    endm   
    
BANK2 macro
    bcf STATUS, RP0 ;Select memory bank 2
    bsf STATUS, RP1 
    endm   
    
BANK3 macro
    bsf STATUS, RP0 ;Select memory bank 3
    bsf STATUS, RP1 
    endm   
;}
    
;******************************************************************    
;*************************** S T A R T ****************************
;******************************************************************
    
				org 0x00
				goto MAIN
	
; ******************************************************************
; ************************** M A I N *******************************
; ******************************************************************

MAIN
;{		
	BANK1
	movlw b'11001000'
	movwf OPTION_REG

	;***********************
	;*** PORTA NASTAVENI ***
	;***********************

	banksel ADCON1
	movlw b'00000010' 	;RA0-RA3 Analog
	movwf ADCON1
	
	;Set RA0 - joy1 X to analog
	;Set RA1 - joy1 Y
	;    RA4 Spinac1
	;Set RA2 - joy2 X to analog
	;Set RA3 - joy2 Y	
	;    RA5 Spinac2
	
	banksel ADCON0 ;
	movlw b'11000000' ;ADC Frc clock ;AN0, ADC OFF

	BANK1	
	movlw b'00001111'	;RA0-RA5 = JOY1, JOY2
	movwf TRISA

	BANK0 		
	clrf PORTA

	;***********************
	;*** PORTB NASTAVENI ***
	;***********************
	
	BANK1
	movlw b'00000011'	;RB0, RB1 - spinace JOY1, JOY2, RB5-7 WT588D output
	movwf TRISB	
	
	BANK0
	clrf CCP1CON 		;Turn CCP module off
	clrf PORTB   
	
	;***********************
	;*** PORTC NASTAVENI ***
	;***********************
	
	BANK1
	movlw b'00010000';	RC4-SDI FLASH, jinak ostatni output
	movwf TRISC
	
	BANK0
	clrf PORTC

	;EEPROM INIT
	bsf  EEPROM_CS		
	clrf SSPCON  		; Inicializace MSSP modulu
	movlw b'00110000'	; 00, SSPEN=1,CKP=1, 0001 SPI Master Mode = FOSC/4
	movwf SSPCON
	BANK1
	clrf SSPSTAT
  	movlw 0x80			; set up spi port, SPI master,
	movwf SSPSTAT		; CKE = 0 (mode 1,1)

	BANK0
	clrf INTCON			;Vypni interrupty
	
	;WT588D				;Nastav SCK a CS na log. 1
	bsf WT588D_SCK		;Pro WT588D
	bsf WT588D_CS	
;}				

;*******************************************************************
;******************* M A I N   L O O P *****************************
;*******************************************************************
	
	call TFT_Init

GAME_START
							
	call BOARD_init
	
	call GAME_init
	
	call TFT_clearScreen
	
	call TFT_showLogo
	
	call WT588D_playIntroSound
		
	call TFT_clearScreen

	call TFT_drawBoard
	
	call TFT_drawScore
	
	call TFT_showTurnText
	
	call TFT_showActualPlayer

GAME_LOOP

	call BOARD_findPlayablePlace
	btfsc STATUS, Z
	goto GAME_PLACEFOUND
	
	incf GAME_unableCounter, f
	btfsc GAME_unableCounter, 1			;==2?
	goto GAME_OVER						;KONEC HRY, nikdo nezahral
	
	call WT588D_playCannotMove
	call GAME_setNextPlayer				;Nelze hrat
	call TFT_showActualPlayer			;Prepni kamen
	goto GAME_LOOP
	
GAME_PLACEFOUND
	;call WT588D_playPlayerTurn			;Rekni kdo hraje
	clrf GAME_unableCounter
	call GAME_setPieceTypeBeforeMove
	
GAME_MOVE
	
	call GAME_savePosition	;uschovej x,y -> x_old, y_old a piece type
	
	call TFT_drawPiece		;na pozici BOARD_x, BOARD_y
	
	call JOY_getReadings	;uprav BOARD_x, BOARD_y podle pohybu
	
	call GAME_checkMove		;Zjisti, jestli byl pohyb, nastav GAME_wasMove
	btfss GAME_wasMove, 0	;[x,y] vs [x_old,y_old]
	goto GAME_checkSwitch
			
	;Zajisti uklid na predchozi pozici				
	call GAME_setPieceOldPosition ;nastav, co se bude kreslit	
	call BOARD_saveXY		
	call GAME_restorePosition ;x_old,y_old -> x,y
	call TFT_drawPiece		  ;na pozici BOARD_x_old, BOARD_y_old

	call BOARD_restoreXY	
			
	;A vykreslime situaci na nove pozici
	call GAME_setPieceTypeAfterMove	;Zjisti obsazenost/hratelnost noveho mista
	call WT588D_playMoveClick
	call TFT_drawPiece		;a vykresli novou pozici BOARD_x, BOARD_y
	
GAME_checkSwitch

	call JOY_getSwitchReading
	btfss STATUS, Z			;ZERO set - byl stisk u aktualniho hrace
	goto GAME_noPush
	
	;GAME_pieceType obsahuje aktualni stav pozice (lze hrat, nelze)
	call GAME_setPieceTypeAfterSwitch	;uloz kamen na desku, pokud je OK
	btfss STATUS, Z			;Da se kamen na pozici odehrat?
	goto GAME_badPlace			;Ne hrac musi najit jine misto
	goto GAME_okPlace			;Hratelne misto

GAME_badPlace
	call WT588D_playError
	goto GAME_MOVE
GAME_okPlace		
	call BOARD_setPlaceValue ;Uloz kamen na desku
	
	call GAME_incrementScore ;+1 za prave ulozeny kamen
	
	call TFT_drawPiece
	
	call TFT_updateBoard	;Prekresli obklopene kameny, updatuj skore
	
	call TFT_drawScore		;Zobraz aktualni skore hracu

	decf GAME_piecesLeft, f
	btfsc STATUS, Z
	goto GAME_OVER
	
	call GAME_setNextPlayer
	
	call TFT_showActualPlayer		
		
	goto GAME_LOOP			;Budeme znovu hledat hratelne misto

GAME_noPush

	movlw .100
	call waitMilis		

	goto GAME_MOVE

GAME_OVER
	
	call TFT_showGameOverText
	
	call WT588D_playGameOver
	
	call WT588D_playWinnerOrDraw
	
	call JOY_waitButton

	goto GAME_START
;*******************************************************************
;************************** B O A R D  *****************************
;*******************************************************************

;Vycisti board a nastavi prvni 4 kameny
BOARD_init
;{
	
	;1) Vycisteni boardu
	movlw BOARD_SIZE * BOARD_SIZE
	movwf BOARD_i
	
	bsf STATUS, IRP
	movlw LOW board
	movwf FSR
	
	clrw
B_clear
	movwf INDF
	incf FSR, f
	decfsz BOARD_i, f
	goto B_clear

	;2) Uvodni rozestaveni 4 kamenu
	
	;WHITE |  BLACK
	movlw LOW (board+.27)
	movwf FSR
	movlw BOARD_WHITE
	movwf INDF
	incf FSR, f
	movlw BOARD_BLACK
	movwf INDF
	
	;BLACK  | WHITE
	movlw LOW (board+.35)
	movwf FSR
	movlw BOARD_BLACK
	movwf INDF
	incf FSR, f
	movlw BOARD_WHITE
	movwf INDF	
	
	bcf STATUS, IRP
	
	return
;}	


;Zjisti, jestli je misto hratelne
;Vstup: BOARD_x, BOARD_y
;Vystup: ZERO set - neni, ZERO unset - je
BOARD_isPlacePlayable
;{
	call BOARD_setExpected
	call BOARD_checkPlacePlayable	;vraci ZERO-nelze
	return
;}

;Nastav ocekavane barvy pro sousedy a aktualniho hrace
BOARD_setExpected
;{
	;Nastav ocekavanou souperovu barvu pro testy na sousedy	
	movlw BOARD_BLACK				;2
	btfss GAME_playerTurn, 0		;1-white, 2-black
	movlw BOARD_WHITE				;1
	movwf BOARD_expectedPiece
	
	;Nastav ocekavanou barvu aktualniho hrace pro testy na obklopeni
	movlw BOARD_WHITE				;1
	btfss GAME_playerTurn, 0		;1-white, 2-black
	movlw BOARD_BLACK				;2
	movwf BOARD_expectedActPiece	
	return
;}

;Najdi na desce hratelne misto pro danou barvu kamene GAME_playerTurn
;Vystup: ZERO set - mame hratelne
BOARD_findPlayablePlace
;{
	call BOARD_setExpected
	
	clrf  BOARD_x	
	clrf  BOARD_y	
	movlw BOARD_SIZE
	movwf BOARD_j
	
BOARD_findRow
	movlw BOARD_SIZE
	movwf BOARD_i
	clrf BOARD_x
BOARD_findColumn
	
	call BOARD_checkPlacePlayable		;vraci ZERO set-nelze
	btfss STATUS, Z
	goto BOARD_placeFound				;Mame hratelne misto
	incf BOARD_x, f
	
	decfsz BOARD_i, f
	goto BOARD_findColumn
	
	incf BOARD_y, f
	
	decfsz BOARD_j, f
	goto BOARD_findRow

BOARD_placeNotFound
	bcf STATUS, Z
	return
	
BOARD_placeFound
	bsf STATUS, Z
	return
;}


;Vstup BOARD_x a BOARD_y
;Vystup: ZERO - nelze hrat, NONZERO-lze
BOARD_checkPlacePlayable
;{
	call BOARD_isPlaceEmpty				;Misto musi byt prazdne = ZERO
	btfss STATUS, Z
	goto BOARD_checkPlaceUnable
	
BOARD_checkPlaceNeighbours
	call BOARD_hasPlaceNeighbours		;Musi mit sousedy, ZERO set = nema
	btfsc STATUS, Z	
	goto BOARD_checkPlaceUnable
	
BOARD_checkSurroundingPosition			;Obklopime souperovy kameny?
	call BOARD_checkPlaceFlanks
	btfss STATUS, Z
	return
	
BOARD_checkPlaceUnable
	bsf STATUS, Z
	return
;}


;Zjisti, jestli pro vybrane smery v BOARD_neighboursByte obklopime
;kameny soupere, tzn. mame XOO...X sekvenci v danych smerech, kde X je
;muj kamen.
;Vstup: BOARD_neighboursByte, BOARD_x, BOARD_y
;Vystup: BOARD_neighboursByte - naplnim vsechny smery, kde obklopim soupere
;Vystup: ZERO set: BOARD_neighboursByte==0 (v zadnem smeru nic neobklopim)
;Vystup: ZERO unset - BOARD_neighboursByte != 0
BOARD_checkPlaceFlanks
;{

	;1) Nejprve se presunu na sousedni kamen, ten je souperuv
	;2) Od nej dale ve vybranem smeru hledam svuj kamen
	;3) Otestuju, jestli nejsem na okraji
	;4) Posunu se dale ve vybranem smeru
	;5) Jsem na souperove kamenu, svem nebo prazdnem miste?
	;6) GOTO 3)
		
BOARD_fPos0
	btfss BOARD_neighboursByte, 0	
	goto BOARD_fPos1
	movlw b'00000001'
	call BOARD_checkDirection
BOARD_fPos1	
	btfss BOARD_neighboursByte, 1	
	goto BOARD_fPos2
	movlw b'00000010'
	call BOARD_checkDirection
BOARD_fPos2
	btfss BOARD_neighboursByte, 2	
	goto BOARD_fPos3
	movlw b'00000100'
	call BOARD_checkDirection
BOARD_fPos3	
	btfss BOARD_neighboursByte, 3	
	goto BOARD_fPos4
	movlw b'00001000'
	call BOARD_checkDirection
BOARD_fPos4	
	btfss BOARD_neighboursByte, 4	
	goto BOARD_fPos5
	movlw b'00010000'
	call BOARD_checkDirection	
BOARD_fPos5	
	btfss BOARD_neighboursByte, 5	
	goto BOARD_fPos6
	movlw b'00100000'
	call BOARD_checkDirection	
BOARD_fPos6	
	btfss BOARD_neighboursByte, 6	
	goto BOARD_fPos7	
	movlw b'01000000'
	call BOARD_checkDirection
BOARD_fPos7	
	btfss BOARD_neighboursByte, 7
	goto BOARD_checkFlanksFinish
	movlw b'10000000'
	call BOARD_checkDirection		
BOARD_checkFlanksFinish
	movf BOARD_neighboursByte, f		;Zadny smer neni dobry?
	btfss STATUS, Z
	bcf STATUS, Z						;Nasli jsme hratelny smer!
	return								;Nechej ZERO flag == nenasli jsme
;}

;Zjisti, jestli kdyz se vydanym danym smerem najdu svuj kamen,
;ktery obklopuje souperovic
;Vstup W_REG - smer 0-7
;Vystup - BOARD_neighboursByte, WREG = 1, pokud smer vyhovuje
;Vystup - BOARD_neighboursByte, WREG = 0, pokud ve smeru nelze obklopit
BOARD_checkDirection
;{	
	movwf BOARD_direction
	
	;Nejprve vycisti bit, ze dany smer vyhovuje. Ten nastavime, az najdeme
	;obklopujici kamen
	xorwf BOARD_neighboursByte, f
	
	call BOARD_saveXY

	;Presun se na souperuv kamen v danem smeru
	;Od nej zacneme dale hledat svuj kamen, ktery
	;obklopi soupere. Urcite nejsme za krajem desky.
	call BOARD_nextPositionInDirection
		
BOARD_checkDirectionLoop

	;Testuj okraj desky, skoncime, pokud ano
	call BOARD_checkMarginsForDirection
	btfsc STATUS, Z
	goto BOARD_checkDirectionFinish		;Koncime, v tomto smeru uz nic neni

	call BOARD_nextPositionInDirection	;Nekoncime, posun dale ve smeru
		
	;Otestuj, jestli neni prazdno		
	call BOARD_isPlaceEmpty
	btfsc STATUS, Z						;ZERO set == EMPTY
	goto BOARD_checkDirectionFinish		;Prazdne misto, nebude obklopeni
		
	;Otestuj, je-li na mistech muj kamen (=obklopili jsme).
	;Nastav odpovidajici bit v BOARD_neighboursByte a koncime
	movf BOARD_expectedActPiece, w		;Prave hrana barva kamene
	xorwf BOARD_piece, w				;Je na aktualnim miste na desce?
	btfss STATUS, Z	
	goto BOARD_checkDirectionLoop
	
	;Nasli jsme obklopujici kamen, hotovo
	movf BOARD_direction, w
	xorwf BOARD_neighboursByte, f		;Tento smer je schudny
		
BOARD_checkDirectionFinish
	
	call BOARD_restoreXY
	
	return
;}


;Zkontroluj jestli nejsme na okraji desky pro dany smer
;Vstup: BOARD_direction, BOARD_x, BOARD_y
;Vystup: ZERO set - jsme na kraji v ramci daneho smeru
;        ZERO not set - nejsme
BOARD_checkMarginsForDirection
;{
	
BOARD_checkMargins0	
	btfss BOARD_direction, 0
	goto BOARD_checkMargins1
	movf BOARD_x, f
	return
BOARD_checkMargins1
	btfss BOARD_direction, 1
	goto BOARD_checkMargins2
	movf BOARD_x, f			
	btfsc STATUS, Z			
	return
	movf BOARD_y, f			
	return
BOARD_checkMargins2
	btfss BOARD_direction, 2
	goto BOARD_checkMargins3
	movf BOARD_y, f
	return
BOARD_checkMargins3
	btfss BOARD_direction, 3
	goto BOARD_checkMargins4
	movf BOARD_y, f
	btfsc STATUS, Z
	return
	movlw (BOARD_SIZE - .1)
	xorwf BOARD_x, w
	return		
BOARD_checkMargins4
	btfss BOARD_direction, 4
	goto BOARD_checkMargins5
	movlw (BOARD_SIZE - .1)
	xorwf BOARD_x, w
	return		
BOARD_checkMargins5
	btfss BOARD_direction, 5
	goto BOARD_checkMargins6
	movlw (BOARD_SIZE - .1)
	xorwf BOARD_x, w
	btfsc STATUS, Z
	return
	movlw (BOARD_SIZE - .1)
	xorwf BOARD_y, w
	return
BOARD_checkMargins6
	btfss BOARD_direction, 6
	goto BOARD_checkMargins7
	movlw (BOARD_SIZE - .1)
	xorwf BOARD_y, w
	return		
BOARD_checkMargins7
	movlw (BOARD_SIZE - .1)
	xorwf BOARD_y, w
	btfsc STATUS, Z
	return
	movf BOARD_x, f
	return
;}
		

;Posunu se na dalsi pozici v danem smeru
;Vstup: BOARD_direction
;Vystup: Zmeny v BOARD_x a BOARD_y podle smeru
BOARD_nextPositionInDirection
;{
	
BOARD_nextPosition0	
	btfss BOARD_direction, 0
	goto BOARD_nextPosition1
	decf BOARD_x, f
	return
BOARD_nextPosition1
	btfss BOARD_direction, 1
	goto BOARD_nextPosition2
	decf BOARD_x, f
	decf BOARD_y, f
	return
BOARD_nextPosition2
	btfss BOARD_direction, 2
	goto BOARD_nextPosition3
	decf BOARD_y, f
	return	
BOARD_nextPosition3
	btfss BOARD_direction, 3
	goto BOARD_nextPosition4
	incf BOARD_x, f
	decf BOARD_y, f
	return		
BOARD_nextPosition4
	btfss BOARD_direction, 4
	goto BOARD_nextPosition5
	incf BOARD_x, f
	return	
BOARD_nextPosition5
	btfss BOARD_direction, 5
	goto BOARD_nextPosition6
	incf BOARD_x, f
	incf BOARD_y, f
	return
BOARD_nextPosition6
	btfss BOARD_direction, 6
	goto BOARD_nextPosition7
	incf BOARD_y, f
	return	
BOARD_nextPosition7	
	btfss BOARD_direction, 7
	return	
	decf BOARD_x, f
	incf BOARD_y, f	
	return
;}

;Ulozi BOARD_x a BOARD_y do BOARD_x_tmp a BOARD_y_tmp
BOARD_saveXY
;{
	movf  BOARD_x, w
	movwf BOARD_x_tmp
	movf  BOARD_y, w
	movwf BOARD_y_tmp
	return
;}


;Obnovi BOARD_x a BOARD_y
BOARD_restoreXY
;{
	movf  BOARD_x_tmp, w
	movwf BOARD_x
	movf  BOARD_y_tmp, w
	movwf BOARD_y
	return
;}

;Zjisti, jestli ma pozice v okoli nejake sousedy souperovy barvy
;Vstup: BOARD_x, BOARD_y, BOARD_expectedPiece
;Vystup: ZERO - nema sousedy, NONZERO - ma
;		 nastavi BOARD_neighboursByte bity 0-7 podle pozic nize 1-OK, 0-KO
; Prochazim tyto pozice na desce od bodu P
; a ukladam 1, pokud je soused barvy souperova kamene
; Hlidam kraje desky

; Pozice
;  1 2 3
;  0 P 4
;  7 6 5

BOARD_hasPlaceNeighbours
;{
	clrf BOARD_neighboursByte
	
BOARD_pos0	
	movf BOARD_x, f			;Test okraje
	btfsc STATUS, Z			;Jsme na levem okraji?
	goto BOARD_pos1			;Urcite nemame leveho souseda
	decf BOARD_x, f			;Pozice 0
	call BOARD_hasPlaceOpponentPiece
	btfss STATUS, Z
	bsf BOARD_neighboursByte, 0		;Ma, nastav 1 na danou pozici
	nop
	incf BOARD_x, f			;Vrat zpet pozici	
BOARD_pos1
	movf BOARD_x, f			;Test okraje
	btfsc STATUS, Z			;Levy okraj?
	goto BOARD_pos2			;Levy soused na levem kraji desky neni
	movf BOARD_y, f			;Horni okraj?
	btfsc STATUS, Z
	goto BOARD_pos2			;Taky nic
	decf BOARD_x, f
	decf BOARD_y, f
	call BOARD_hasPlaceOpponentPiece
	btfss STATUS, Z
	bsf BOARD_neighboursByte, 1
	nop		
	incf BOARD_x, f			;Vratime zpet X i Y
	incf BOARD_y, f	
BOARD_pos2
	movf BOARD_y, f			;Test horniho okraje
	btfsc STATUS, Z			;Horni okraj?
	goto BOARD_pos3			;Nahore soused nebude urcite	
	decf BOARD_y, f
	call BOARD_hasPlaceOpponentPiece
	btfss STATUS, Z
	bsf BOARD_neighboursByte, 2
	nop		
	incf BOARD_y, f
BOARD_pos3
	movf BOARD_y, f			;Test horniho okraje
	btfsc STATUS, Z			;Horni okraj?
	goto BOARD_pos4			;Horni soused neni
	movlw (BOARD_SIZE - .1)	;7
	xorwf BOARD_x, w		;Pravy okraj?
	btfsc STATUS, Z			;Ano
	goto BOARD_pos4			;Soused nebude		
	decf BOARD_y, f
	incf BOARD_x, f
	call BOARD_hasPlaceOpponentPiece
	btfss STATUS, Z
	bsf BOARD_neighboursByte, 3
	nop		
	decf BOARD_x, f			;Vratime zpet X i Y
	incf BOARD_y, f	
BOARD_pos4
	movlw (BOARD_SIZE - .1)	;7 test okraje
	xorwf BOARD_x, w		;Pravy okraj?
	btfsc STATUS, Z			;Jsme na levem okraji?	
	goto BOARD_pos5			;Urcite nemame praveho souseda
	incf BOARD_x, f			;Pozice 0
	call BOARD_hasPlaceOpponentPiece
	btfss STATUS, Z
	bsf BOARD_neighboursByte, 4		;Ma, nastav 1 na danou pozici
	nop
	decf BOARD_x, f			;Vrat zpet pozici	
BOARD_pos5
	movlw (BOARD_SIZE - .1)	;7
	xorwf BOARD_x, w		;Pravy okraj?
	btfsc STATUS, Z			;
	goto BOARD_pos6			;Pravy soused neni
	movlw (BOARD_SIZE - .1)	;7
	xorwf BOARD_y, w		;Dolni okraj?
	btfsc STATUS, Z			;Ano
	goto BOARD_pos6			;Soused nebude			
	incf BOARD_x, f
	incf BOARD_y, f
	call BOARD_hasPlaceOpponentPiece
	btfss STATUS, Z
	bsf BOARD_neighboursByte, 5
	nop		
	decf BOARD_x, f			;Vratime zpet X i Y
	decf BOARD_y, f	
BOARD_pos6
	movlw (BOARD_SIZE - .1)	;7
	xorwf BOARD_y, w		;Dolni okraj?
	btfsc STATUS, Z			;Ano
	goto BOARD_pos7
	incf BOARD_y, f
	call BOARD_hasPlaceOpponentPiece
	btfss STATUS, Z
	bsf BOARD_neighboursByte, 6
	nop		
	decf BOARD_y, f
BOARD_pos7
	movlw (BOARD_SIZE - .1)	;7
	xorwf BOARD_y, w		;Dolni okraj?
	btfsc STATUS, Z			;Ano
	goto BOARD_posFinish	;Koncime
	movf BOARD_x, f			;Test okraje
	btfsc STATUS, Z			;Levy okraj?
	goto BOARD_posFinish	;Neni soused
	decf BOARD_x, f
	incf BOARD_y, f
	call BOARD_hasPlaceOpponentPiece
	btfss STATUS, Z
	bsf BOARD_neighboursByte, 7
	nop
	incf BOARD_x, f
	decf BOARD_y, f	
BOARD_posFinish
	movf BOARD_neighboursByte, f
	return
;}
	
;Je pozice [BOARD_x,BOARD_y] prazdna?
;Vystup Z-flag: SET - prazdne, UNSET - obsazeno
BOARD_isPlaceEmpty
;{
	call BOARD_getPlaceValue
	movwf BOARD_tmp	
	movf BOARD_tmp, f	
	return
;}
	

;Zjisti, jestli je misto obsazene souperovym kamenem	
;Vstup: BOARD_x, BOARD_y, BOARD_expectedPiece
;Vystup: ZERO-neni, NONZERO-je
BOARD_hasPlaceOpponentPiece
;{
	
	;1) Je misto prazdne? ANO, vrat ZERO
	call BOARD_isPlaceEmpty
	btfsc STATUS, Z
	return
	
	;2) Je obsazeno souperovym kamenem?
	movf BOARD_piece, w			   ;nastavilo uz isPlaceEmpty
	xorwf BOARD_expectedPiece, w   ;porovnej s ocekavanym kamenem		
	btfss STATUS, Z				   ;je stejne, musime ale obratit Zero flag
	goto BOARD_hasPlaceFinish	
	bcf STATUS, Z
	return
BOARD_hasPlaceFinish
	bsf STATUS, Z
	return
;}

;Vraci hodnotu  board[BOARD_tmp]
;Vstup: BOARD_x, BOARD_y
;Vystup: WREG hodnota v poli
BOARD_getPlaceValue
;{
	call BOARD_setAndGetAddress
	movf INDF, w
	movwf BOARD_piece			;kopii sem
	bcf STATUS, IRP
	return
;}

;Uloz kamen na pozici x,y
;Vstup: BOARD_x, BOARD_y
BOARD_setPlaceValue
;{
	call BOARD_setAndGetAddress
	
	movlw BOARD_WHITE
	btfss GAME_playerTurn, 0	;1-WHITE, 2-BLACK
	movlw BOARD_BLACK	
	movwf INDF
	
	bcf STATUS, IRP
	return
;}

BOARD_setAndGetAddress
;{
	movf BOARD_y, w
	movwf BOARD_tmp
	bcf STATUS, C		;Vynasob 8
	rlf BOARD_tmp, f
	rlf BOARD_tmp, f
	rlf BOARD_tmp, f
	movf BOARD_x, w
	addwf BOARD_tmp, f	;Jsme v poli board na spravne adrese
	bsf STATUS, IRP
	movlw LOW board
	movwf FSR
	movf BOARD_tmp, w
	addwf FSR, f
	return
;}

;*******************************************************************
;********************** J O Y S T I C K Y **************************
;*******************************************************************

;Cekej na stisk nektereho buttonu
;Vrat se, az nejaky byl
JOY_waitButton
;{
	btfss JOY1_SW
	return
	btfss JOY2_SW
	return
	goto JOY_waitButton
;}

;Byl stisk aktualniho hrace?
;Vystup: ZERO set: byl, ZERO unset nebyl
JOY_getSwitchReading
;{
	btfss GAME_playerTurn, 0	;Hrac1 nebo Hrac2?
	goto JOY2_SwRead
JOY1_SwRead
	btfsc JOY1_SW
	goto JOY_SwReadWasNotPushed	;Neni stisk
	goto JOY_SwReadNext
JOY2_SwRead	
	btfsc JOY2_SW
	goto JOY_SwReadWasNotPushed

;-----------
JOY_SwReadNext
	movlw .10					;Debounce test
	call waitMilis	

	btfss GAME_playerTurn, 0
	goto JOY2_SwReadTest2
JOY1_SwReadTest2	
	btfsc JOY1_SW
	goto JOY_SwReadWasNotPushed
	goto JOY_SwReadFinal	
JOY2_SwReadTest2
	btfsc JOY2_SW
	goto JOY_SwReadWasNotPushed

;-----------	
JOY_SwReadFinal

	btfss GAME_playerTurn, 0	
	goto JOY2_SwReadTest3	
JOY1_SwReadTest3
	btfss JOY1_SW
	goto JOY_SwReadFinal
	goto JOY_SwReadWasPushed
JOY2_SwReadTest3
	btfss JOY2_SW
	goto JOY_SwReadFinal	
	
JOY_SwReadWasPushed
	bsf STATUS, Z
	return
	
JOY_SwReadWasNotPushed
	bcf STATUS, Z
	return
;}

JOY_getReadings
;{
	clrf JOY_whichAdjust	;BOARD_x
	call JOY_getAnalogX		
	
	movlw HIGH JOY_handleMoveX
	movwf PCLATH
	call JOY_handleMoveX
	clrf PCLATH
	
	incf JOY_whichAdjust, f	;BOARD_y
	call JOY_getAnalogY
	
	movlw HIGH JOY_handleMoveY
	movwf PCLATH
	call JOY_handleMoveY
	clrf PCLATH
	
	call JOY_stopADC
	return
;}


	
JOY_stopADC
;{
	banksel ADCON0 
	movlw b'11000000' 			;ADC Frc clock, movwf ADCON0 ;AN0, ADC OFF	
	return
;}

JOY_getAnalogX
;{
	movlw JOY1_X_ADC				;1
	btfss GAME_playerTurn, 0		;1-white, 2-black
	movlw JOY2_X_ADC				;2
	goto JOY_readAnalog
;}
JOY_getAnalogY
;{
	movlw JOY1_Y_ADC				;1
	btfss GAME_playerTurn, 0		;1-white, 2-black
	movlw JOY2_Y_ADC				;2
	goto JOY_readAnalog
;}		
JOY_readAnalog
;{		
	banksel ADCON0
	movwf ADCON0 ;ADC On		
	call wait30us ;Acquisiton delay
	bsf ADCON0, GO ;Start conversion
	btfsc ADCON0, GO ;Is conversion done?
	goto $-1 ;No, test again
	banksel ADRES
	movf ADRES, w ;Read upper 2 bits
	BANK0
	movwf JOY_ADresult ;store in GPR space
	return
;}

;*******************************************************************
;*****************T F T  2.8 ILI9341 DISPLAY ***********************
;*******************************************************************

;Black on Green
TFT_setBlackOnGreen
;{
	movlw HIGH TFT_GREEN
    movwf TFT_pieceBGColor+0
    movlw LOW TFT_GREEN
    movwf TFT_pieceBGColor+1
    movlw HIGH TFT_BLACK
    movwf TFT_pieceFGColor+0
    movlw LOW TFT_BLACK
    movwf TFT_pieceFGColor+1
    return
;}

TFT_drawBoard
;{
	;1) Vycisti plochu zelene
	;2) Horizontalni linie
	;3) Vertikalni linie
	;4) Vykresli kameny
	
	call TFT_drawHorizontalLines
	call TFT_drawVerticalLines

	;movlw TRUE
	;movwf TFT_skip					;nepocitej XY podle boardu
	;call TFT_drawPlayersPiece		;Bily a cerny kamen vedle skore

	movlw FALSE
	movwf TFT_skip
	
	call TFT_drawPieces				;Az pri vypnutem skipu!
	
	return
;}


;Zobraz barvu kamene, ktery prave hraje
TFT_showActualPlayer
;{
	movlw TRUE
	movwf TFT_skip
	
	call TFT_setBlackOnGreen
	
	movlw BOARD_WHITE
	btfss GAME_playerTurn, 0	;1-white, 2-black
	movlw BOARD_BLACK
	movwf GAME_pieceType
	
	;X
	movlw HIGH .268
    movwf TFT_X+0
    movlw LOW .268
    movwf TFT_X+1
    movlw HIGH (.268 + PIECE_SIZE - .1)
    movwf TFT_X_MAX+0
    movlw LOW (.268 + PIECE_SIZE - .1)
    movwf TFT_X_MAX+1

    ;Y
    clrf TFT_Y+0
    movlw .117
    movwf TFT_Y+1
    movlw HIGH (.117 + PIECE_SIZE - .1)
    movwf TFT_Y_MAX+0
    movlw LOW (.117 + PIECE_SIZE - .1)
    movwf TFT_Y_MAX+1	
	
	call TFT_setXY2
	call TFT_drawPiece	
	
	movlw FALSE
	movwf TFT_skip
		
	return	
;}


;Zobraz text "HRAJE"
TFT_showTurnText
;{
	call TFT_setBlackOnGreen
	
	;X
	movlw HIGH .243
    movwf TFT_X+0
    movlw LOW .243
    movwf TFT_X+1
    movlw HIGH (.243 + .72 - .1)
    movwf TFT_X_MAX+0
    movlw LOW (.243 + .72 - .1)
    movwf TFT_X_MAX+1

    ;Y
    clrf TFT_Y+0
    movlw .96
    movwf TFT_Y+1
    movlw HIGH (.96 + .15 - .1)
    movwf TFT_Y_MAX+0
    movlw LOW (.96 + .15 - .1)
    movwf TFT_Y_MAX+1	
	
    call TFT_setXY2
    
    movlw HIGH Table_hraje
    movwf dataPointer+0
    movlw LOW Table_hraje
    movwf dataPointer+1
    
    movlw hraje_len
    call TFT_drawBox
    return
 ;}  

TFT_showLogo
;{
	call TFT_setBlackOnGreen
	
	;X
	movlw HIGH .60
    movwf TFT_X+0
    movlw LOW .60
    movwf TFT_X+1
    movlw HIGH (.60 + .200 - .1)
    movwf TFT_X_MAX+0
    movlw LOW (.60 + .200 - .1)
    movwf TFT_X_MAX+1

    ;Y
    movlw HIGH .70
    movwf TFT_Y+0
    movlw LOW .70
    movwf TFT_Y+1
    movlw HIGH (.70 + .100 - .1)
    movwf TFT_Y_MAX+0
    movlw LOW (.70 + .100 - .1)
    movwf TFT_Y_MAX+1	
	
    call TFT_setXY2
    
    movlw HIGH Table_logo0
    movwf dataPointer+0
    movlw LOW Table_logo0
    movwf dataPointer+1
    movlw logo_len
    call TFT_drawBox
    
    movlw HIGH Table_logo1
    movwf dataPointer+0
    movlw LOW Table_logo1
    movwf dataPointer+1
    movlw logo_len
    call TFT_drawBox
    
    movlw HIGH Table_logo2
    movwf dataPointer+0
    movlw LOW Table_logo2
    movwf dataPointer+1
    movlw logo_len
    call TFT_drawBox    
    
    movlw HIGH Table_logo3
    movwf dataPointer+0
    movlw LOW Table_logo3
    movwf dataPointer+1
    movlw logo_len
    call TFT_drawBox
    
    movlw HIGH Table_logo4
    movwf dataPointer+0
    movlw LOW Table_logo4
    movwf dataPointer+1
    movlw logo_len
    call TFT_drawBox
    
    movlw HIGH Table_logo5
    movwf dataPointer+0
    movlw LOW Table_logo5
    movwf dataPointer+1
    movlw logo_len
    call TFT_drawBox
    
    movlw HIGH Table_logo6
    movwf dataPointer+0
    movlw LOW Table_logo6
    movwf dataPointer+1
    movlw logo_len
    call TFT_drawBox
    
    movlw HIGH Table_logo7
    movwf dataPointer+0
    movlw LOW Table_logo7
    movwf dataPointer+1
    movlw logo_len
    call TFT_drawBox
    
    movlw HIGH Table_logo8
    movwf dataPointer+0
    movlw LOW Table_logo8
    movwf dataPointer+1
    movlw logo_len
    call TFT_drawBox
    
    movlw HIGH Table_logo9
    movwf dataPointer+0
    movlw LOW Table_logo9
    movwf dataPointer+1
    movlw logo_len
    call TFT_drawBox        
    return
 ;}  

TFT_showBullet1
;{
	call TFT_setBlackOnGreen
	
	;X
	movlw HIGH .20
    movwf TFT_X+0
    movlw LOW .20
    movwf TFT_X+1
    movlw HIGH (.20 + .32 - .1)
    movwf TFT_X_MAX+0
    movlw LOW (.20 + .32 - .1)
    movwf TFT_X_MAX+1    
    ;Y
    movlw HIGH .70
    movwf TFT_Y+0
    movlw LOW .70
    movwf TFT_Y+1
    movlw HIGH (.70 + .30 - .1)
    movwf TFT_Y_MAX+0
    movlw LOW (.70 + .30 - .1)
    movwf TFT_Y_MAX+1	
	
    call TFT_setXY2
    
    movlw HIGH Table_gunshot_data
    movwf dataPointer+0
    movlw LOW Table_gunshot_data
    movwf dataPointer+1
    movlw Table_gunshot_data_len
    call TFT_drawBox    
    return

TFT_showBullet2    
	;X
	movlw HIGH .260
    movwf TFT_X+0
    movlw LOW .260
    movwf TFT_X+1
    movlw HIGH (.260 + .32 - .1)
    movwf TFT_X_MAX+0
    movlw LOW (.260 + .32 - .1)
    movwf TFT_X_MAX+1
    
    ;Y
    movlw HIGH .100
    movwf TFT_Y+0
    movlw LOW .100
    movwf TFT_Y+1
    movlw HIGH (.100 + .30 - .1)
    movwf TFT_Y_MAX+0
    movlw LOW (.100 + .30 - .1)
    movwf TFT_Y_MAX+1	
	
    call TFT_setXY2
    
    movlw HIGH Table_gunshot_data
    movwf dataPointer+0
    movlw LOW Table_gunshot_data
    movwf dataPointer+1
    movlw Table_gunshot_data_len
    call TFT_drawBox
    return
    
TFT_showBullet3    
	;X
	movlw HIGH .160
    movwf TFT_X+0
    movlw LOW .160
    movwf TFT_X+1
    movlw HIGH (.160 + .32 - .1)
    movwf TFT_X_MAX+0
    movlw LOW (.160 + .32 - .1)
    movwf TFT_X_MAX+1
    
    ;Y
    movlw HIGH .170
    movwf TFT_Y+0
    movlw LOW .170
    movwf TFT_Y+1
    movlw HIGH (.170 + .30 - .1)
    movwf TFT_Y_MAX+0
    movlw LOW (.170 + .30 - .1)
    movwf TFT_Y_MAX+1	
	
    call TFT_setXY2
    
    movlw HIGH Table_gunshot_data
    movwf dataPointer+0
    movlw LOW Table_gunshot_data
    movwf dataPointer+1
    movlw Table_gunshot_data_len
    call TFT_drawBox        
	return
 ;} 

;Zobraz text "KONEC HRY"
TFT_showGameOverText
;{
	call TFT_setBlackOnGreen
	
	;X
	movlw HIGH .243
    movwf TFT_X+0
    movlw LOW .243
    movwf TFT_X+1
    movlw HIGH (.243 + .72 - .1)
    movwf TFT_X_MAX+0
    movlw LOW (.243 + .72 - .1)
    movwf TFT_X_MAX+1

    ;Y
    clrf TFT_Y+0
    movlw .96
    movwf TFT_Y+1
    movlw HIGH (.96 + .45 - .1)
    movwf TFT_Y_MAX+0
    movlw LOW (.96 + .45 - .1)
    movwf TFT_Y_MAX+1	
	
    call TFT_setXY2
    
    movlw HIGH Table_konec
    movwf dataPointer+0
    movlw LOW Table_konec
    movwf dataPointer+1
    
    movlw konec_len
    call TFT_drawBox
    
    movlw HIGH Table_hry
    movwf dataPointer+0
    movlw LOW Table_hry
    movwf dataPointer+1
    
    movlw hry_len
    call TFT_drawBox    
    return
 ;}  



;Zobraz aktualni skore obou hracu
TFT_drawScore
;{
	;Score White	
	movlw HIGH TFT_setWhiteOnGreen
	movwf PCLATH
	call TFT_setWhiteOnGreen
	clrf PCLATH


    ;Player 1, tens, ones    
    movlw HIGH UTIL_bin2ascii
    movwf PCLATH
    movf GAME_scorePlayer1, w
    call UTIL_bin2ascii
    clrf PCLATH
    
    movlw HIGH P1_TENS_X
    movwf TFT_X+0
    movlw LOW P1_TENS_X
    movwf TFT_X+1
    movlw HIGH (P1_TENS_X + SCORE_DIGIT_WIDTH - .1)
    movwf TFT_X_MAX+0
    movlw LOW (P1_TENS_X + SCORE_DIGIT_WIDTH - .1)
    movwf TFT_X_MAX+1

    movlw HIGH P1_TENS_Y
    movwf TFT_Y+0
    movlw LOW P1_TENS_Y
    movwf TFT_Y+1
    movlw HIGH (P1_TENS_Y + SCORE_DIGIT_HEIGHT - .1)
    movwf TFT_Y_MAX+0
    movlw LOW (P1_TENS_Y + SCORE_DIGIT_HEIGHT - .1)
    movwf TFT_Y_MAX+1
    
    call TFT_setXY2
    
    movf UTIL_tens, w
    call TFT_setDataPointer
    
    ;TODO Nastav dataPointer podle cislice tens    

    movlw digit_len
    call TFT_drawBox

    movlw HIGH P1_ONES_X
    movwf TFT_X+0
    movlw LOW P1_ONES_X
    movwf TFT_X+1
    movlw HIGH (P1_ONES_X + SCORE_DIGIT_WIDTH - .1)
    movwf TFT_X_MAX+0
    movlw LOW (P1_ONES_X + SCORE_DIGIT_WIDTH - .1)
    movwf TFT_X_MAX+1

    movlw HIGH P1_ONES_Y
    movwf TFT_Y+0
    movlw LOW P1_ONES_Y
    movwf TFT_Y+1
    movlw HIGH (P1_ONES_Y + SCORE_DIGIT_HEIGHT - .1)
    movwf TFT_Y_MAX+0
    movlw LOW (P1_ONES_Y + SCORE_DIGIT_HEIGHT - .1)
    movwf TFT_Y_MAX+1
    
    call TFT_setXY2
    
    movf UTIL_ones, w
    call TFT_setDataPointer
    
    movlw digit_len
    call TFT_drawBox
          
    ;Player 2, tens, ones
    
	call TFT_setBlackOnGreen

    movlw HIGH UTIL_bin2ascii
    movwf PCLATH
    movf GAME_scorePlayer2, w
    call UTIL_bin2ascii
    clrf PCLATH        
        
    movlw HIGH P2_TENS_X
    movwf TFT_X+0
    movlw LOW P2_TENS_X
    movwf TFT_X+1
    movlw HIGH (P2_TENS_X + SCORE_DIGIT_WIDTH - .1)
    movwf TFT_X_MAX+0
    movlw LOW (P2_TENS_X + SCORE_DIGIT_WIDTH - .1)
    movwf TFT_X_MAX+1

    movlw HIGH P2_TENS_Y
    movwf TFT_Y+0
    movlw LOW P2_TENS_Y
    movwf TFT_Y+1
    movlw HIGH (P2_TENS_Y + SCORE_DIGIT_HEIGHT - .1)
    movwf TFT_Y_MAX+0
    movlw LOW (P2_TENS_Y + SCORE_DIGIT_HEIGHT - .1)
    movwf TFT_Y_MAX+1
        
    call TFT_setXY2
    
    movf UTIL_tens, w
    call TFT_setDataPointer
    
    movlw digit_len
    call TFT_drawBox
    
    movlw HIGH P2_ONES_X
    movwf TFT_X+0
    movlw LOW P2_ONES_X
    movwf TFT_X+1
    movlw HIGH (P2_ONES_X + SCORE_DIGIT_WIDTH - .1)
    movwf TFT_X_MAX+0
    movlw LOW (P2_ONES_X + SCORE_DIGIT_WIDTH - .1)
    movwf TFT_X_MAX+1

    movlw HIGH P2_ONES_Y
    movwf TFT_Y+0
    movlw LOW P2_ONES_Y
    movwf TFT_Y+1
    movlw HIGH (P2_ONES_Y + SCORE_DIGIT_HEIGHT - .1)
    movwf TFT_Y_MAX+0
    movlw LOW (P2_ONES_Y + SCORE_DIGIT_HEIGHT - .1)
    movwf TFT_Y_MAX+1    
    
    call TFT_setXY2
    
    movf UTIL_ones, w
    call TFT_setDataPointer
    
    movlw digit_len
    call TFT_drawBox    
     	
	return
	
;}

;Vstup: W-REG (znak '0' - '9')
;Vystup: dataPointer nastaveny na Table_font_<cislice 0-9> 
TFT_setDataPointer
;{	
	addlw .256 - '0'	;0-9
	movwf tmp_m
	
TFT_setDP0	
	movf tmp_m, f		;0
	btfss STATUS, Z
	goto TFT_setDP1
	movlw HIGH Table_font_0
	movwf dataPointer+0
	movlw LOW Table_font_0
	movwf dataPointer+1
	return
TFT_setDP1
	decfsz tmp_m, f
	goto TFT_setDP2
	movlw HIGH Table_font_1
	movwf dataPointer+0
	movlw LOW Table_font_1
	movwf dataPointer+1
	return	
TFT_setDP2
	decfsz tmp_m, f
	goto TFT_setDP3
	movlw HIGH Table_font_2
	movwf dataPointer+0
	movlw LOW Table_font_2
	movwf dataPointer+1
	return
TFT_setDP3
	decfsz tmp_m, f
	goto TFT_setDP4
	movlw HIGH Table_font_3
	movwf dataPointer+0
	movlw LOW Table_font_3
	movwf dataPointer+1
	return
TFT_setDP4
	decfsz tmp_m, f
	goto TFT_setDP5
	movlw HIGH Table_font_4
	movwf dataPointer+0
	movlw LOW Table_font_4
	movwf dataPointer+1
	return
TFT_setDP5
	decfsz tmp_m, f
	goto TFT_setDP6
	movlw HIGH Table_font_5
	movwf dataPointer+0
	movlw LOW Table_font_5
	movwf dataPointer+1
	return
TFT_setDP6
	decfsz tmp_m, f
	goto TFT_setDP7
	movlw HIGH Table_font_6
	movwf dataPointer+0
	movlw LOW Table_font_6
	movwf dataPointer+1
	return
TFT_setDP7
	decfsz tmp_m, f
	goto TFT_setDP8
	movlw HIGH Table_font_7
	movwf dataPointer+0
	movlw LOW Table_font_7
	movwf dataPointer+1
	return
TFT_setDP8
	decfsz tmp_m, f
	goto TFT_setDP9
	movlw HIGH Table_font_8
	movwf dataPointer+0
	movlw LOW Table_font_8
	movwf dataPointer+1
	return
TFT_setDP9
	movlw HIGH Table_font_9
	movwf dataPointer+0
	movlw LOW Table_font_9
	movwf dataPointer+1
	return
		
;}


;Po odehrani kamene prekresli vsechny obklopene kameny
;Vstup: BOARD_neighboursByte ma nastavene smery, kde obklopuji
;Vystup: Prekresleny board, updatnute score obou hracu
TFT_updateBoard
;{
	;Barva kamene, kterym prekreslujeme
	movlw BOARD_WHITE
	btfss GAME_playerTurn, 0		;1-white, 2-black
	movlw BOARD_BLACK
	movwf GAME_pieceType
	
TFT_updateBoardPos0
	btfss BOARD_neighboursByte, 0	
	goto TFT_updateBoardPos1
	movlw b'00000001'
	call TFT_updateDirection
TFT_updateBoardPos1	
	btfss BOARD_neighboursByte, 1	
	goto TFT_updateBoardPos2
	movlw b'00000010'
	call TFT_updateDirection
TFT_updateBoardPos2
	btfss BOARD_neighboursByte, 2	
	goto TFT_updateBoardPos3
	movlw b'00000100'
	call TFT_updateDirection
TFT_updateBoardPos3	
	btfss BOARD_neighboursByte, 3	
	goto TFT_updateBoardPos4
	movlw b'00001000'
	call TFT_updateDirection
TFT_updateBoardPos4	
	btfss BOARD_neighboursByte, 4	
	goto TFT_updateBoardPos5
	movlw b'00010000'
	call TFT_updateDirection	
TFT_updateBoardPos5	
	btfss BOARD_neighboursByte, 5	
	goto TFT_updateBoardPos6
	movlw b'00100000'
	call TFT_updateDirection	
TFT_updateBoardPos6	
	btfss BOARD_neighboursByte, 6	
	goto TFT_updateBoardPos7	
	movlw b'01000000'
	call TFT_updateDirection
TFT_updateBoardPos7	
	btfss BOARD_neighboursByte, 7
	goto BOARD_checkFlanksFinish
	movlw b'10000000'
	call TFT_updateDirection		
	return
;}


;Prekresli vsechny souperovy kameny v danem smeru
;Updatuj skore pri kazdem prekresleni
TFT_updateDirection
;{
	movwf BOARD_direction
	
	call BOARD_saveXY
	
TFT_updateDirectionLoop

	call BOARD_nextPositionInDirection	;Nekoncime, posun dale ve smeru
	
	call BOARD_getPlaceValue
		
	;Otestuj, je-li na mistech muj kamen (=obklopili jsme). To skonci.
	movf  BOARD_expectedActPiece, w		;Prave hrana barva kamene
	xorwf BOARD_piece, w				;Je na aktualnim miste na desce?
	btfsc STATUS, Z	
	goto TFT_updateDirectionFinish
	
	call TFT_drawPiece					;Prekresli
	
	call WT588D_playChange
	
	call BOARD_setPlaceValue			;Vymen barvu i na desce
	
	call GAME_incrementScore			;Pricti aktualnimu hraci
	
	call GAME_decrementOpponentScore	;Odecti protihraci
	
	goto TFT_updateDirectionLoop
		
TFT_updateDirectionFinish
	
	call BOARD_restoreXY
	
	return
;}

TFT_clearScreen
;{
	
	;Column Set
	movlw 0x2A
	call TFT_sendCmd
	movlw .0
	call TFT_sendData
	movlw .0
	call TFT_sendData
	movlw HIGH TFT_WIDTH
	call TFT_sendData
	movlw LOW TFT_WIDTH
	call TFT_sendData

	;Page Set
	movlw 0x2B
	call TFT_sendCmd
	movlw .0
	call TFT_sendData
	movlw .0
	call TFT_sendData
	movlw .0
	call TFT_sendData
	movlw TFT_HEIGHT
	call TFT_sendData
	
	;memory write
	movlw 0x2C
	call TFT_sendCmd
	
	bcf TFT_CS		;Zacatek write operace
	nop
	nop
	bsf TFT_DC		;Data
	nop
	nop
		
	movlw HIGH TFT_WIDTH	
	movwf hiByte
	movlw LOW TFT_WIDTH	
	movwf loByte
TFT_fillR					; Rows
	movlw TFT_HEIGHT
	movwf i	
TFT_fillC					; Columns
	movlw HIGH TFT_GREEN
	movwf SSPBUF
	BANK1
TFT_fillScreenH
    btfss SSPSTAT, BF		; Has data been transmitted?
	goto TFT_fillScreenH	; Loop if not transmitted yet
	BANK0
    movf SSPBUF, w			; Empty the receive buffer

	movlw LOW TFT_GREEN
	movwf SSPBUF
	BANK1
TFT_fillScreenL
    btfss SSPSTAT, BF		; Has data been transmitted?
	goto TFT_fillScreenL	; Loop if not transmitted yet
	BANK0
    movf SSPBUF, w			; Empty the receive buffer
    
    decfsz i, f
    goto TFT_fillC			
    
    call decHL
    btfss STATUS, Z
    goto TFT_fillR
	
	bsf TFT_CS				; Konec write operace			
	return
;}


TFT_drawHorizontalLines
;{
	movlw TILE_SIZE
	movwf TFT_increment
	
	movlw BOARD_SIZE+1
	movwf i					;9 linek
	
	clrf j					;Y-osa

TFT_drawHorizontalLinesR

	;Column Set
	movlw 0x2A
	call TFT_sendCmd
	movlw .0
	call TFT_sendData
	movlw .0
	call TFT_sendData
	movlw HIGH TFT_HEIGHT	;Jen ctverec
	call TFT_sendData
	movlw LOW TFT_HEIGHT
	call TFT_sendData

	;Page Set
	movlw 0x2B
	call TFT_sendCmd
	movlw .0
	call TFT_sendData
	movf j, w
	call TFT_sendData
	movlw .0
	call TFT_sendData
	movf j, w
	addlw .1
	call TFT_sendData
	
	;memory write
	movlw 0x2C
	call TFT_sendCmd
	
	movlw TFT_HEIGHT
	movwf k

TFT_drawHorizontalLinesC	

	movlw HIGH TFT_BLACK
	call TFT_sendData
	movlw LOW TFT_BLACK
	call TFT_sendData
	
	decfsz k, f
	goto TFT_drawHorizontalLinesC

	movf TFT_increment, w			;Dalsi linka
	addwf j, f
	
	decfsz i, f
	goto TFT_drawHorizontalLinesR
	
	return
;}



TFT_drawVerticalLines
;{
	movlw TILE_SIZE
	movwf TFT_increment
	
	movlw BOARD_SIZE+1
	movwf i					;9 linek
	
	clrf j					;X-osa

TFT_drawVerticalLinesR

	;Column Set
	movlw 0x2A
	call TFT_sendCmd
	movlw .0
	call TFT_sendData
	movf j, w
	call TFT_sendData
	movlw .0
	call TFT_sendData
	movf j, w
	call TFT_sendData

	;Page Set
	movlw 0x2B
	call TFT_sendCmd
	movlw .0
	call TFT_sendData
	movlw .0
	call TFT_sendData
	movlw HIGH TFT_HEIGHT
	call TFT_sendData
	movlw LOW TFT_HEIGHT
	call TFT_sendData
	
	;memory write
	movlw 0x2C
	call TFT_sendCmd
	
	movlw TFT_HEIGHT
	movwf k

TFT_drawVerticalLinesC	

	movlw HIGH TFT_BLACK
	call TFT_sendData
	movlw LOW TFT_BLACK
	call TFT_sendData
	
	decfsz k, f
	goto TFT_drawVerticalLinesC

	movf TFT_increment, w			;Dalsi linka
	addwf j, f
	
	decfsz i, f
	goto TFT_drawVerticalLinesR
	
	return
;}




;Vykresli kameny na boardu
TFT_drawPieces
;{
	clrf BOARD_y
	movlw BOARD_SIZE
	movwf BOARD_j

TFT_pieceTestY	
	clrf BOARD_x
	movlw BOARD_SIZE
	movwf BOARD_i
	
TFT_pieceTestX
	call BOARD_getPlaceValue
	movwf GAME_pieceType
	iorlw 0x00
	btfss STATUS, Z
	call TFT_drawPiece
	incf BOARD_x, f
	decfsz BOARD_i, f
	goto TFT_pieceTestX
		
	incf BOARD_y, f
	decfsz BOARD_j, f
	goto TFT_pieceTestY
	return
;}
	
;Nastavi v displeji okno pro vykresleni kamene, podle BOARD_x a BOARD_y
TFT_setXY
;{

	clrf TFT_X+0
	clrf TFT_X+1
	clrf TFT_X_MAX+0
	clrf TFT_X_MAX+1
	clrf TFT_Y+0
	clrf TFT_Y+1
	clrf TFT_Y_MAX+0
	clrf TFT_Y_MAX+1	
	clrf TFT_byte
	
	movf BOARD_x, w
	movwf tmp_m
	
	movlw HIGH UTIL_multiply30
	movwf PCLATH
	call UTIL_multiply30
	clrf PCLATH
	
	addwf TFT_X+1, f
	addwf TFT_X_MAX+1, f
	movlw PIECE_SIZE - .1
	addwf TFT_X_MAX+1, f		;+velikost kamene
	
	movf BOARD_y, w
	movwf tmp_m
	
	movlw HIGH UTIL_multiply30
	movwf PCLATH
	call UTIL_multiply30
	clrf PCLATH	

	addwf TFT_Y+1, f
	addwf TFT_Y_MAX+1, f
	movlw PIECE_SIZE - .1
	addwf TFT_Y_MAX+1, f
	
TFT_setXY2						;Pro skore
	;Column Set
	movlw 0x2A
	call TFT_sendCmd
	movf TFT_X+0, w
	call TFT_sendData
	movf TFT_X+1, w
	call TFT_sendData
	movf TFT_X_MAX+0, w
	call TFT_sendData
	movf TFT_X_MAX+1, w
	call TFT_sendData

	;Page Set
	movlw 0x2B
	call TFT_sendCmd
	movf TFT_Y+0, w
	call TFT_sendData
	movf TFT_Y+1, w
	call TFT_sendData
	movf TFT_Y_MAX+0, w
	call TFT_sendData
	movf TFT_Y_MAX+1, w
	call TFT_sendData
	
	;memory write
	movlw 0x2C
	call TFT_sendCmd
		
	return
;}





;Vykresli kamen na pozici [BOARD_x, BOARD_y] v barve GAME_pieceType
TFT_drawPiece
;{
	movlw HIGH TFT_drawPiecePrep
	movwf PCLATH
	call TFT_drawPiecePrep
	clrf PCLATH
	
	btfss TFT_skip, 0	
    call TFT_setXY				;Spocitej a nastav pozici
    
TFT_drawPiece2					;Vykresli kameny do score boardu
    movlw Table_kamen_data_len	;Kamen i krizek stejna delka
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_bitNotSet
    movf TFT_pieceFGColor+0, w
    call TFT_sendData
    movf TFT_pieceFGColor+1, w
    call TFT_sendData
    goto TFT_bitCommon

TFT_bitNotSet
    movf TFT_pieceBGColor+0, w
    call TFT_sendData
    movf TFT_pieceBGColor+1, w
    call TFT_sendData

TFT_bitCommon            
    rlf tmp, f

    decfsz j, f
    goto TFT_draw_loopB
    
    incf FSR, f
    
    decfsz i, f
    goto TFT_draw_loop
    
    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		
;}
			
; *******************************************************************
; ************ H E R N I    R U T I N Y *****************************
; *******************************************************************
GAME_init
;{	
	movlw BOARD_WHITE
	movwf GAME_pieceType	
	
	movlw BOARD_SIZE * BOARD_SIZE - 4 ;4 jiz nasazene
	movwf GAME_piecesLeft

	movlw .2
	movwf GAME_scorePlayer1
	movwf GAME_scorePlayer2
		
	movlw PLAYER_WHITE					;zacina white
	movwf GAME_playerTurn
	
	clrf GAME_unableCounter
	
	return
;}

;Prepni mezi hraci
GAME_setNextPlayer
;{
	movlw PLAYER_BLACK				;2
	btfss GAME_playerTurn, 0		;1-white, 2-black
	movlw PLAYER_WHITE				;1
	movwf GAME_playerTurn		
	return
;}

;Inkrementuj skore pro aktualniho hrace
GAME_incrementScore
;{	
	btfss GAME_playerTurn, 0	;1-white, 2-black
	goto GAME_incPlayerBlack
	incf GAME_scorePlayer1, f
	return	
GAME_incPlayerBlack
	incf GAME_scorePlayer2, f	
	return
;}

;Dekrementuj souperovou skore (pri prekreslovani obklopenych kamenu)
GAME_decrementOpponentScore
;{
	btfss GAME_playerTurn, 0	;1-white, 2-black
	goto GAME_decPlayerWhite
	decf GAME_scorePlayer2, f
	return	
GAME_decPlayerWhite
	decf GAME_scorePlayer1, f	
	return
;}

;Vstup: GAME_pieceType
;Vystup: ZERO set - byla hratelna pozice (_READY), ZERO unset - nebyla
GAME_setPieceTypeAfterSwitch
;{
	btfss GAME_playerTurn, 0
	goto GAME_checkPieceP2
	
GAME_checkPieceP1		
	btfss GAME_pieceType, 2
	goto GAME_afterSwitchNotOK
	movlw BOARD_WHITE				;Ukladame WHITE
	movwf GAME_pieceType
	goto GAME_afterSwitchOK
	
GAME_checkPieceP2	
	btfss GAME_pieceType, 3
	goto GAME_afterSwitchNotOK
	movlw BOARD_BLACK				;Ukladame BLACK
	movwf GAME_pieceType
	goto GAME_afterSwitchOK
	
GAME_afterSwitchNotOK
	bcf STATUS, Z
	return
GAME_afterSwitchOK
	bsf STATUS, Z
	return
;}

;Vstup - board_x, board_y
;Vystup - nastavi game_setPieceType pred pokladanim pro daneho hrace
GAME_setPieceTypeBeforeMove
;{	
	movlw BOARD_BLACK_READY	;4
	btfss GAME_playerTurn, 1;1-white, 2-black
	movlw BOARD_WHITE_READY ;8
	movwf GAME_pieceType	;a uloz kam potrebujeme			
	return
;}

;Vstup: BOARD_x, BOARD_y
;Vystup: GAME_pieceType v zavislosti na obsazenosti a hratelnosti mista
GAME_setPieceTypeAfterMove
;{
	;1) Nejprve zjistim obsazenost, at nehledam hratelne misto zbytecne
	call BOARD_isPlaceEmpty
	btfsc STATUS, Z
	goto GAME_setPieceVacant

	;Obsazeno - nastav barvy pozadi a popredi
	movlw BOARD_WHITE_OCCUPIED		;16
	btfss BOARD_piece, 0			;1-white, 2-black
	movlw BOARD_BLACK_OCCUPIED		;32
	movwf GAME_pieceType
	return

GAME_setPieceVacant	

	;2) Misto volne, zkus hratelnost mista
	call BOARD_isPlacePlayable
	btfsc STATUS, Z
	goto GAME_notPlayable
	
GAME_playable
	;3) Hratelne misto - nastav barvy pozadi a popredi podle akt. hrace
	movlw BOARD_WHITE_READY			;4
	btfss GAME_playerTurn, 0		;1-white, 2-black
	movlw BOARD_BLACK_READY			;8
	movwf GAME_pieceType
	return
	
GAME_notPlayable
	;4) Nehratelne
	movlw BOARD_CROSS
	movwf GAME_pieceType
	return
;}

;Nastavi GAME_pieceType na stare pozici
;Vstup - board_x_old, board_y_old
GAME_setPieceOldPosition
;{
	call BOARD_saveXY
	
	call GAME_restorePosition ;x_old,y_old -> x,y
	call BOARD_getPlaceValue
	movwf GAME_pieceType
	
	call BOARD_restoreXY
	return
;}

;Uloz aktualni pozici X,Y kurzoru a aktualni typ zobrazovani
GAME_savePosition
;{
	movf BOARD_x, w
	movwf BOARD_x_old
	movf BOARD_y, w
	movwf BOARD_y_old
	return
;}

;Obnov aktualni pozici X,Y kurzoru a aktualni typ zobrazovani
GAME_restorePosition
;{
	movf BOARD_x_old, w
	movwf BOARD_x
	movf BOARD_y_old, w
	movwf BOARD_y
	return
;}

		
;Vraci 0-kurzorem se nepohlo, 1-byl pohyb
GAME_checkMove
;{
		movlw TRUE				; Predpokladame, ze byl
		movwf GAME_wasMove
		
		movf BOARD_x_old, w
		xorwf BOARD_x, w
		btfss STATUS, Z
		return
		movf BOARD_y_old, w
		xorwf BOARD_y, w
		btfss STATUS, Z
		return
		movlw FALSE
		movwf GAME_wasMove
		return
;}

; *******************************************************************
; ************ 2.8" TFT ILI9341   R U T I N Y ***********************
; *******************************************************************

TFT_Init
;{
		bsf TFT_RESET
		movlw .200
		call waitMilis
		bcf TFT_RESET
		movlw .200
		call waitMilis		
		bsf TFT_RESET
		movlw .200
		call waitMilis		
		
		;Soft RESET command
		movlw 0x01		
		call TFT_sendCmd
		movlw .1
		call waitSecs
			
		;power control A
		movlw 0xCB
		call TFT_sendCmd
		movlw 0x39
		call TFT_sendData
		movlw 0x2C
		call TFT_sendData
		movlw 0x00
		call TFT_sendData
		movlw 0x34
		call TFT_sendData
		movlw 0x02
		call TFT_sendData
	
	
		;power control B
		movlw 0xCF
		call TFT_sendCmd
		movlw 0x00
		call TFT_sendData
		movlw 0xC1
		call TFT_sendData
		movlw 0x30
		call TFT_sendData
	
		;driver timing control A
		movlw 0xE8
		call TFT_sendCmd
		movlw 0x85
		call TFT_sendData
		movlw 0x00
		call TFT_sendData
		movlw 0x78
		call TFT_sendData
	
		;driver timing control B
		movlw 0xEA
		call TFT_sendCmd
		movlw 0x00
		call TFT_sendData
		movlw 0x00
		call TFT_sendData
	
		;power on sequence control
		movlw 0xED
		call TFT_sendCmd
		movlw 0x64
		call TFT_sendData
		movlw 0x03
		call TFT_sendData
		movlw 0x12
		call TFT_sendData
		movlw 0x81
		call TFT_sendData
	
		;pump ratio control
		movlw 0xF7
		call TFT_sendCmd
		movlw 0x20
		call TFT_sendData
	
		;power control,VRH[5:0]
		movlw 0xC0
		call TFT_sendCmd
		movlw 0x23
		call TFT_sendData
	
		;Power control,SAP[2:0];BT[3:0]
		movlw 0xC1
		call TFT_sendCmd
		movlw 0x10
		call TFT_sendData
	
		;vcm control
		movlw 0xC5
		call TFT_sendCmd
		movlw 0x3E
		call TFT_sendData
		movlw 0x28
		call TFT_sendData
	
		;vcm control 2
		movlw 0xC7
		call TFT_sendCmd
		movlw 0x86
		call TFT_sendData
	
		;memory access control
		movlw 0x36
		call TFT_sendCmd
		;movlw 0x48  ORIG
		movlw 0x28 			;W=320, H=240
		call TFT_sendData
	
		;pixel format
		movlw 0x3A
		call TFT_sendCmd
		movlw 0x55
		call TFT_sendData
	
		;frameration control,normal mode full colours
		movlw 0xB1
		call TFT_sendCmd
		movlw 0x00
		call TFT_sendData
		movlw 0x18
		call TFT_sendData
	
		;display function control
		movlw 0xB6
		call TFT_sendCmd
		movlw 0x08
		call TFT_sendData
		movlw 0x82
		call TFT_sendData
		movlw 0x27
		call TFT_sendData
	
		;3gamma function disable
		movlw 0xF2
		call TFT_sendCmd
		movlw 0x00
		call TFT_sendData
	
		;gamma curve selected
		movlw 0x26
		call TFT_sendCmd
		movlw 0x01
		call TFT_sendData
	
		;set positive gamma correction
		movlw 0xE0
		call TFT_sendCmd
		movlw 0x0F
		call TFT_sendData
		movlw 0x31
		call TFT_sendData
		movlw 0x2B
		call TFT_sendData
		movlw 0x0C
		call TFT_sendData
		movlw 0x0E
		call TFT_sendData
		movlw 0x08
		call TFT_sendData
		movlw 0x4E
		call TFT_sendData
		movlw 0xF1
		call TFT_sendData
		movlw 0x37
		call TFT_sendData
		movlw 0x07
		call TFT_sendData
		movlw 0x10
		call TFT_sendData
		movlw 0x03
		call TFT_sendData
		movlw 0x0E
		call TFT_sendData
		movlw 0x09
		call TFT_sendData
		movlw 0x00
		call TFT_sendData
	
		;set negative gamma correction
		movlw 0xE1
		call TFT_sendCmd
		movlw 0x00
		call TFT_sendData
		movlw 0x0E
		call TFT_sendData
		movlw 0x14
		call TFT_sendData
		movlw 0x03
		call TFT_sendData
		movlw 0x11
		call TFT_sendData
		movlw 0x07
		call TFT_sendData
		movlw 0x31
		call TFT_sendData
		movlw 0xC1
		call TFT_sendData
		movlw 0x48
		call TFT_sendData
		movlw 0x08
		call TFT_sendData
		movlw 0x0F
		call TFT_sendData
		movlw 0x0C
		call TFT_sendData
		movlw 0x31
		call TFT_sendData
		movlw 0x36
		call TFT_sendData
		movlw 0x0F
		call TFT_sendData
	
		;exit sleep
		movlw 0x11
		call TFT_sendCmd
		movlw .120
		call waitMilis
	
		;display on
		movlw 0x29
		call TFT_sendCmd
		
		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				;HW SPI
;{
	movwf SSPBUF			
	BANK1
TFT_wait
    btfss SSPSTAT, BF		; Has data been transmitted?        
	goto TFT_wait			; Loop if not transmitted yet
	BANK0
    movf SSPBUF, w			; Empty the receive buffer
	return
;}
		
TFT_writeWord
;{
		movlw TFT_word
		call TFT_writeByte
		movlw TFT_word+1
		call TFT_writeByte
		return
;}


		
;*******************************************************************
;******************* WT588D - prehravani zvuku cislo numSound ******
;*******************************************************************	

WT588D_playIntroSound
;{
	movlw SOUND_05_GUNSHOT
	call WT588D_doSoundFX
	call TFT_showBullet1
	movlw .250
	call waitMilis
	movlw SOUND_05_GUNSHOT
	call WT588D_doSoundFX
	call TFT_showBullet2
	movlw .250
	call waitMilis
	movlw SOUND_05_GUNSHOT
	call WT588D_doSoundFX
	call TFT_showBullet3
	movlw .250
	call waitMilis
	movlw .250
	call waitMilis	
	movlw SOUND_00_REVERSI
	call WT588D_doSoundFX	
	call wait1s
	call wait1s
	return
;}

WT588D_playMoveClick
;{
	movlw SOUND_01_MOVE
	goto WT588D_doSoundFX
;}

WT588D_playChange
;{
	movlw SOUND_02_CHANGE1
	btfss GAME_playerTurn, 0		;1-white, 2-black
	movlw SOUND_03_CHANGE2
	call WT588D_doSoundFX
	movlw .100
	call waitMilis
	return
;}

WT588D_playGameOver
;{
	movlw SOUND_04_GAMEOVER
	call WT588D_doSoundFX
	call wait1s
	call wait1s
		
	movlw SOUND_0B_GAME_OVER_VOICE
	call WT588D_doSoundFX		
	call wait1s
	return
;}

;Oznam viteze hry, je-li
WT588D_playWinnerOrDraw
;{
	movf GAME_scorePlayer1, w
	xorwf GAME_scorePlayer2, w
	btfss STATUS, Z
	goto notDraw
	movlw SOUND_0C_TIE
	call WT588D_doSoundFX
	call wait1s
	return
notDraw

	movf GAME_scorePlayer1, w     ;CompTo
    subwf  GAME_scorePlayer2, w  ;SomeVar
    
    movlw SOUND_0E_BLACK_WINS
    btfss  STATUS, C    		; Test for Carry Flag Clear    
    movlw SOUND_0D_WHITE_WINS	; SomeVar < CompTo
    call WT588D_doSoundFX
    call wait1s
	call wait1s
	return
;}

WT588D_playError
;{
	movlw SOUND_06_ERROR
	call WT588D_doSoundFX
	movlw .250
	call waitMilis
	return
;}

;Aktualni hrac nemuze udelat tah
WT588D_playCannotMove
;{
	movlw SOUND_07_WHITE_UNABLE
	btfss GAME_playerTurn, 0	;1-white, 2-black
	movlw SOUND_08_BLACK_UNABLE
	call WT588D_doSoundFX
	movlw .250
	call waitMilis
	movlw .250
	call waitMilis
	call wait1s
	return
;}

;Aktualni hrac
WT588D_playPlayerTurn
;{
	movlw SOUND_09_WHITE_TURN
	btfss GAME_playerTurn, 0	;1-white, 2-black
	movlw SOUND_0A_BLACK_TURN
	call WT588D_doSoundFX
	movlw .200
	call waitMilis
	call wait1s
	return
;}

WT588D_doSoundFX
;{
		movwf wt588d_tmp
	
		;Nastav SCK a CS na log. 1
		movlw b'01100000'		;SCK log. 1, CS log. 1
		movwf PORTB
		
		movlw .17
		call waitMilis
		
		movlw b'00100000'		;SCK log. 1, CS log. 0
		movwf PORTB				;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 wait30us

		bsf WT588D_SCK		;Clock na log. 1, skoncili jsme prenos 1 bitu	
		call wait30us

		rrf wt588d_tmp, f
		decfsz wt588d_i, f
		goto cycle

		movlw b'01100000'	;SDA log. 0, CS log. 1, SCK log. 1
		movwf PORTB			;Slave Select = HI

		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
;}

wait30us	
;{			
			nop
			movlw .18
			movwf j
wait30l		decfsz j, f
			goto wait30l																			

			return;			ta je za 2 cykly
;}


; Delay = 0.001 seconds
; Clock frequency = 8 MHz
wait1ms
;{
			;1993 cycles
	movlw	0x8E
	movwf	del1
	movlw	0x02
	movwf	del2
wait1ms_0
	decfsz	del1, f
	goto	$+2
	decfsz	del2, f
	goto	wait1ms_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return
;}


; Delay = 1 seconds
; Clock frequency = 8 MHz
wait1s
;{
			;1999996 cycles
	movlw	0x11
	movwf	del1
	movlw	0x5D
	movwf	del2
	movlw	0x05
	movwf	del3
wait1s_0
	decfsz	del1, f
	goto	$+2
	decfsz	del2, f
	goto	$+2
	decfsz	del3, f
	goto	wait1s_0

			;4 cycles (including call)
	return
;}

; *** SUBRUTINY pro 16bitovy counter ********************************	
; *** Nastavi Zero, pokud jsme na nule
;{
decHL	movf loByte, f
		btfsc STATUS, Z ;je loByte na nule?
		goto decHL2
		decf loByte, w	;kopie pro nasledny OR (test na 0)
		decf loByte, f
		iorwf hiByte, w ;Z flag nastaven pri 0 (loByte OR hiByte)
		return
decHL2	decf loByte, f
		decf hiByte, f
		bcf STATUS, Z	;Potrebuju vynulovat Zero (aby mi pri lo/hi 0/1 predchozi decf Z nenastavil)
		return
;}




; *************************************************************************
; *************************************************************************
; *************************************************************************
						org 0x0700
Table_kamen_data
;{
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x7E, 0x00 ;          ######         
	dt 0x03, 0xFF, 0xC0 ;       ############      
	dt 0x07, 0xFF, 0xE0 ;      ##############     
	dt 0x0F, 0xFF, 0xF0 ;     ################    
	dt 0x1F, 0xFF, 0xF8 ;    ##################   
	dt 0x3F, 0xFF, 0xFC ;   ####################  
	dt 0x3F, 0xFF, 0xFC ;   ####################  
	dt 0x3F, 0xFF, 0xFC ;   ####################  
	dt 0x7F, 0xFF, 0xFE ;  ###################### 
	dt 0x7F, 0xFF, 0xFE ;  ###################### 
	dt 0x7F, 0xFF, 0xFE ;  ###################### 
	dt 0x7F, 0xFF, 0xFE ;  ###################### 
	dt 0x7F, 0xFF, 0xFE ;  ###################### 
	dt 0x7F, 0xFF, 0xFE ;  ###################### 
	dt 0x3F, 0xFF, 0xFC ;   ####################  
	dt 0x3F, 0xFF, 0xFC ;   ####################  
	dt 0x3F, 0xFF, 0xFC ;   ####################  
	dt 0x1F, 0xFF, 0xF8 ;    ##################   
	dt 0x0F, 0xFF, 0xF0 ;     ################    
	dt 0x07, 0xFF, 0xE0 ;      ##############     
	dt 0x03, 0xFF, 0xC0 ;       ############      
	dt 0x00, 0x7E, 0x00 ;          ######         
	dt 0x00, 0x00, 0x00 ;                    					
Table_kamen_data_end
Table_kamen_data_len	equ Table_kamen_data_end - Table_kamen_data
;}

Table_krizek_data
;{
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x80, 0x80 ;         #       #       
	dt 0x00, 0x41, 0x00 ;          #     #        
	dt 0x00, 0x22, 0x00 ;           #   #         
	dt 0x00, 0x14, 0x00 ;            # #          
	dt 0x00, 0x08, 0x00 ;             #           
	dt 0x00, 0x14, 0x00 ;            # #          
	dt 0x00, 0x22, 0x00 ;           #   #         
	dt 0x00, 0x41, 0x00 ;          #     #        
	dt 0x00, 0x80, 0x80 ;         #       #       
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x00, 0x00 ;                         
	dt 0x00, 0x00, 0x00 ;                         
Table_krizek_data_end
Table_krizek_data_len	equ Table_krizek_data_end - Table_krizek_data	
;}

Table_gunshot_data
;{
	 dt 0x00, 0x03, 0x0C, 0x00 ;               ##    ##          
	 dt 0x00, 0x03, 0x0C, 0x00 ;               ##    ##          
	 dt 0x00, 0x03, 0x9E, 0x00 ;               ###  ####         
	 dt 0x0C, 0x0E, 0xFE, 0x00 ;     ##      ### #######         
	 dt 0x07, 0xF8, 0x22, 0x00 ;      ########     #   #         
	 dt 0x03, 0x63, 0xC7, 0x00 ;       ## ##   ####   ###        
	 dt 0x01, 0x87, 0xF3, 0x80 ;        ##    #######  ###       
	 dt 0x01, 0x9F, 0xF8, 0x80 ;        ##  ##########   #       
	 dt 0x01, 0xBF, 0xFC, 0xC0 ;        ## ############  ##      
	 dt 0x07, 0x3F, 0xFE, 0x40 ;      ###  #############  #      
	 dt 0x02, 0x7F, 0xFE, 0x40 ;       #  ##############  #      
	 dt 0x02, 0x7F, 0xFE, 0x40 ;       #  ##############  #      
	 dt 0x02, 0x7F, 0xFE, 0x40 ;       #  ##############  #      
	 dt 0x0C, 0x7F, 0xFE, 0x78 ;     ##   ##############  ####   
	 dt 0x38, 0x3F, 0xFC, 0x7E ;   ###     ############   ###### 
	 dt 0x3E, 0x3F, 0xFC, 0x40 ;   #####   ############   #      
	 dt 0x03, 0x1F, 0xFC, 0xE0 ;       ##   ###########  ###     
	 dt 0x01, 0x9F, 0xF9, 0x80 ;        ##  ##########  ##       
	 dt 0x01, 0x8F, 0xF3, 0x00 ;        ##   ########  ##        
	 dt 0x01, 0x23, 0xE3, 0x00 ;        #  #   #####   ##        
	 dt 0x03, 0xF8, 0x1F, 0x00 ;       #######      #####        
	 dt 0x07, 0x8C, 0x17, 0x80 ;      ####   ##     # ####       
	 dt 0x00, 0x07, 0xD3, 0x80 ;              ##### #  ###       
	 dt 0x00, 0x07, 0xF1, 0x80 ;              #######   ##       
	 dt 0x00, 0x06, 0x70, 0x00 ;              ##  ###            
	 dt 0x00, 0x00, 0x30, 0x00 ;                   ##            
	 dt 0x00, 0x00, 0x20, 0x00 ;                   #             
Table_gunshot_data_end
Table_gunshot_data_len	equ Table_gunshot_data_end - Table_gunshot_data
;}

						org 0x0800
Table_digits
;{
	;0
Table_font_0
		
	dt 0x00,0x00,0x00
	dt 0x0F,0xFF,0xF0
	dt 0x17,0xFF,0xE8
	dt 0x1B,0xFF,0xD8
	dt 0x1D,0xFF,0xB8
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x0E,0x00,0x70
	dt 0x06,0x00,0x60
	dt 0x06,0x00,0x60
	dt 0x0E,0x00,0x70
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1D,0xFF,0xB8
	dt 0x1B,0xFF,0xD8
	dt 0x17,0xFF,0xE8
	dt 0x0F,0xFF,0xF0
	dt 0x00,0x00,0x00
Table_font_0_end
digit_len			equ Table_font_0_end - Table_font_0

;Pro prevod 6bit binary to ASCII
;Vstup: W-REG
;Vystup: UTIL_tens, UTIL_ones ascii cislice vyjadrujici hodnotu ve W-REG
UTIL_bin2ascii
;{
	clrf UTIL_tens
	addlw .256 - .100
digit100
	addlw .20
	btfss STATUS,C
	goto  digit40
	bsf   UTIL_tens,3
	addlw .256 - .20
	goto digit10
digit40
	addlw .40
	btfss STATUS,C
	goto  $+3
	bsf   UTIL_tens,2
	addlw .256 - .40
	addlw .20
	btfss STATUS,C
	goto  $+3
	bsf   UTIL_tens,1
	addlw .256 - .20
digit10
	addlw .10
	btfss STATUS,C
	goto  $+3
	bsf   UTIL_tens,0
	addlw .256 - .10
	
	addlw .10
	movwf UTIL_ones

	;convert to ascii digits
	movlw '0'
	addwf UTIL_tens, f
	addwf UTIL_ones, f
	return
;}	
	
	
					org 0x0900
	
Table_font_1	
	;1
	dt 0x00,0x00,0x00
	dt 0x00,0x00,0x30
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x70
	dt 0x00,0x00,0x60
	dt 0x00,0x00,0x60
	dt 0x00,0x00,0x70
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x30
	dt 0x00,0x00,0x00
	
;vstup W-REG, vystup W-REG * 30
UTIL_multiply30
;{
;	movwf tmp_m
	clrf TFT_byte
	bcf STATUS, C
	rlf tmp_m, w	
	movwf x2
	addwf TFT_byte, f
	rlf TFT_byte, w
	movwf x4
	addwf TFT_byte, f
	rlf x4, w
	movwf x8
	addwf TFT_byte, f
	rlf x8, w
	movwf x16
	addwf TFT_byte, w
	addlw TILE_PADDING	 ;kamen je jen 24x24, + 3px z obou stran = 30px
	return			
;}	
	
						org 0x0A00
Table_font_2						
	;2
	dt 0x00,0x00,0x00
	dt 0x0F,0xFF,0xF0
	dt 0x1F,0xFF,0xE8
	dt 0x1F,0xFF,0xD8
	dt 0x0F,0xFF,0xB8
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x0F,0xFF,0xF8
	dt 0x1F,0xFF,0xF8
	dt 0x1F,0xFF,0xF8
	dt 0x1F,0xFF,0xF0
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1D,0xFF,0xF0
	dt 0x1B,0xFF,0xF8
	dt 0x17,0xFF,0xF8
	dt 0x0F,0xFF,0xF0
	dt 0x00,0x00,0x00
	
TFT_drawPiecePrep
	;Defaultne kreslime kamen
	movlw HIGH Table_kamen_data
	movwf dataPointer+0
	movlw LOW Table_kamen_data
	movwf dataPointer+1	
	
	;Defaultni zelene pozadi
	movlw HIGH TFT_GREEN
    movwf TFT_pieceBGColor+0
    movlw LOW TFT_GREEN
    movwf TFT_pieceBGColor+1
	
TFT_empty	

	movf GAME_pieceType, f		   ;empty?
	btfss STATUS, Z
	goto TFT_drawNotEmpty
	
	movlw HIGH TFT_GREEN		   ;prazdny - zeleny kamen na zelenem pozadi
    movwf TFT_pieceFGColor+0
    movlw LOW TFT_GREEN
    movwf TFT_pieceFGColor+1
    goto TFT_drawPieceNext
	
TFT_drawNotEmpty
	
    btfss GAME_pieceType, 0        ;white (ready) - bily na zelenem
    goto TFT_drawPieceNotWhiteReady
    movlw HIGH TFT_WHITE
    movwf TFT_pieceFGColor+0
    movlw LOW TFT_WHITE
    movwf TFT_pieceFGColor+1
    goto TFT_drawPieceNext

TFT_drawPieceNotWhiteReady

    btfss GAME_pieceType, 1        ;black (ready)
    goto TFT_drawPieceWhiteBefore
    movlw HIGH TFT_BLACK
    movwf TFT_pieceFGColor+0
    movlw LOW TFT_BLACK
    movwf TFT_pieceFGColor+1
    goto TFT_drawPieceNext
    
TFT_drawPieceWhiteBefore

    btfss GAME_pieceType, 2        ;white (pred) - svetly na zelenem
    goto TFT_drawBlackBefore
    movlw HIGH TFT_LIGHTGREY
    movwf TFT_pieceFGColor+0
    movlw LOW TFT_LIGHTGREY
    movwf TFT_pieceFGColor+1
    goto TFT_drawPieceNext
    
TFT_drawBlackBefore            	   ;black (pred) - tmavy na zelenem
	btfss GAME_pieceType, 3
	goto TFT_drawWhiteOccupied
    movlw HIGH TFT_DARKGREY
    movwf TFT_pieceFGColor+0
    movlw LOW TFT_DARKGREY
    movwf TFT_pieceFGColor+1
    goto TFT_drawPieceNext
    
TFT_drawWhiteOccupied			;white (obsazen) - cervena
	btfss GAME_pieceType, 4
	goto TFT_drawBlackOccupied
    movlw HIGH TFT_WHITE
    movwf TFT_pieceFGColor+0
    movlw LOW TFT_WHITE
    movwf TFT_pieceFGColor+1
   	movlw HIGH TFT_RED
    movwf TFT_pieceBGColor+0
    movlw LOW TFT_RED
    movwf TFT_pieceBGColor+1
    goto TFT_drawPieceNext
	
TFT_drawBlackOccupied			;black (obsazen) - cervena
	btfss GAME_pieceType, 5
	goto TFT_drawCross
    movlw HIGH TFT_BLACK
    movwf TFT_pieceFGColor+0
    movlw LOW TFT_BLACK
    movwf TFT_pieceFGColor+1
   	movlw HIGH TFT_RED
    movwf TFT_pieceBGColor+0
    movlw LOW TFT_RED
    movwf TFT_pieceBGColor+1
    goto TFT_drawPieceNext
    
TFT_drawCross					;krizek - cerny na zelenem
	movlw HIGH Table_krizek_data
	movwf dataPointer+0
	movlw LOW Table_krizek_data
	movwf dataPointer+1	
    movlw HIGH TFT_BLACK
    movwf TFT_pieceFGColor+0
    movlw LOW TFT_BLACK
    movwf TFT_pieceFGColor+1
    movlw HIGH TFT_RED
    movwf TFT_pieceBGColor+0
    movlw LOW TFT_RED
    movwf TFT_pieceBGColor+1	
	    
TFT_drawPieceNext
	return	
	
						org 0x0B00
Table_font_3	
	;3
	dt 0x00,0x00,0x00
	dt 0x0F,0xFF,0xF0
	dt 0x1F,0xFF,0xE8
	dt 0x1F,0xFF,0xD8
	dt 0x0F,0xFF,0xB8
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0xFF,0xF0
	dt 0x01,0xFF,0xE0
	dt 0x01,0xFF,0xE0
	dt 0x00,0xFF,0xF0
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x0F,0xFF,0xB8
	dt 0x1F,0xFF,0xD8
	dt 0x1F,0xFF,0xE8
	dt 0x0F,0xFF,0xF0
	dt 0x00,0x00,0x00

						org 0x0C00
Table_font_4
	;4
	dt 0x00,0x00,0x00
	dt 0x0C,0x00,0x30
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1F,0xFF,0xF0
	dt 0x1F,0xFF,0xE0
	dt 0x1F,0xFF,0xE0
	dt 0x0F,0xFF,0xF0
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x30
	dt 0x00,0x00,0x00
	
					org 0x0D00
Table_font_5	
	;5
	dt 0x00,0x00,0x00
	dt 0x0F,0xFF,0xF0
	dt 0x17,0xFF,0xF8
	dt 0x1B,0xFF,0xF8
	dt 0x1D,0xFF,0xF0
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1F,0xFF,0xF0
	dt 0x1F,0xFF,0xF8
	dt 0x1F,0xFF,0xF8
	dt 0x0F,0xFF,0xF8
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x0F,0xFF,0xB8
	dt 0x1F,0xFF,0xD8
	dt 0x1F,0xFF,0xE8
	dt 0x0F,0xFF,0xF0
	dt 0x00,0x00,0x00

						org 0x0E00
Table_font_6
	;6
	dt 0x00,0x00,0x00
	dt 0x0F,0xFF,0xF0
	dt 0x17,0xFF,0xF8
	dt 0x1B,0xFF,0xF8
	dt 0x1D,0xFF,0xF0
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1E,0x00,0x00
	dt 0x1F,0xFF,0xF0
	dt 0x1F,0xFF,0xF8
	dt 0x1F,0xFF,0xF8
	dt 0x1F,0xFF,0xF8
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1F,0xFF,0xB8
	dt 0x1F,0xFF,0xD8
	dt 0x1F,0xFF,0xE8
	dt 0x0F,0xFF,0xF0
	dt 0x00,0x00,0x00
						org 0x0F00
Table_font_7	
	;7
	dt 0x00,0x00,0x00
	dt 0x0F,0xFF,0xF0
	dt 0x1F,0xFF,0xE8
	dt 0x1F,0xFF,0xD8
	dt 0x0F,0xFF,0xB8
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x70
	dt 0x00,0x00,0x60
	dt 0x00,0x00,0x60
	dt 0x00,0x00,0x70
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x30
	dt 0x00,0x00,0x00

						org 0x1000	
Table_font_8
	;8
	dt 0x00,0x00,0x00
	dt 0x0F,0xFF,0xF0
	dt 0x1F,0xFF,0xE8
	dt 0x1F,0xFF,0xD8
	dt 0x1F,0xFF,0xB8
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x0F,0xFF,0xF0
	dt 0x07,0xFF,0xE0
	dt 0x07,0xFF,0xE0
	dt 0x0F,0xFF,0xF0
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1D,0xFF,0xF8
	dt 0x1B,0xFF,0xF8
	dt 0x17,0xFF,0xF8
	dt 0x0F,0xFF,0xF0
	dt 0x00,0x00,0x00
						org 0x1100
Table_font_9	
	;9
	dt 0x00,0x00,0x00
	dt 0x0F,0xFF,0xF0
	dt 0x17,0xFF,0xF8
	dt 0x1B,0xFF,0xF8
	dt 0x1D,0xFF,0xF8
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1E,0x00,0x78
	dt 0x1F,0xFF,0xF8
	dt 0x1F,0xFF,0xF8
	dt 0x1F,0xFF,0xF8
	dt 0x0F,0xFF,0xF8
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x00,0x00,0x78
	dt 0x0F,0xFF,0xB8
	dt 0x1F,0xFF,0xD8
	dt 0x1F,0xFF,0xE8
	dt 0x0F,0xFF,0xF0
	dt 0x00,0x00,0x00
;}
						org 0x1200
Table_hraje
;{
	dt 0xF8, 0xFC, 0xFF, 0xF0, 0x7F, 0xE0, 0x07, 0xCF, 0xFF ; #####   ######  ############     ##########          #####  ############
	dt 0xF8, 0xFC, 0xFF, 0xF8, 0xFF, 0xF0, 0x07, 0xCF, 0xFF ; #####   ######  #############   ############         #####  ############
	dt 0xF8, 0xFC, 0xFF, 0xFD, 0xFF, 0xF8, 0x07, 0xCF, 0xFF ; #####   ######  ############## ##############        #####  ############
	dt 0xF8, 0xFC, 0xFF, 0xFD, 0xFF, 0xF8, 0x07, 0xCF, 0xFF ; #####   ######  ############## ##############        #####  ############
	dt 0xF8, 0xFC, 0xF8, 0x7D, 0xF0, 0xF8, 0x07, 0xCF, 0x80 ; #####   ######  #####    ##### #####    #####        #####  #####       
	dt 0xF8, 0xFC, 0xF8, 0x7D, 0xF0, 0xF8, 0x07, 0xCF, 0x80 ; #####   ######  #####    ##### #####    #####        #####  #####       
	dt 0xFF, 0xFC, 0xFF, 0xF9, 0xFF, 0xF8, 0x07, 0xCF, 0xFF ; ##############  #############  ##############        #####  ############
	dt 0xFF, 0xFC, 0xFF, 0xF9, 0xFF, 0xF8, 0x07, 0xCF, 0xFF ; ##############  #############  ##############        #####  ############
	dt 0xFF, 0xFC, 0xFF, 0xFD, 0xFF, 0xFB, 0xE7, 0xCF, 0xFF ; ##############  ############## ############## #####  #####  ############
	dt 0xF8, 0xFC, 0xF8, 0x7D, 0xF0, 0xFB, 0xE7, 0xCF, 0x80 ; #####   ######  #####    ##### #####    ##### #####  #####  #####       
	dt 0xF8, 0xFC, 0xF8, 0x7D, 0xF0, 0xFB, 0xE7, 0xCF, 0x80 ; #####   ######  #####    ##### #####    ##### #####  #####  #####       
	dt 0xF8, 0xFC, 0xF8, 0x7D, 0xF0, 0xFB, 0xFF, 0xCF, 0xFF ; #####   ######  #####    ##### #####    ##### ############  ############
	dt 0xF8, 0xFC, 0xF8, 0x7D, 0xF0, 0xFB, 0xFF, 0xCF, 0xFF ; #####   ######  #####    ##### #####    ##### ############  ############
	dt 0xF8, 0xFC, 0xF8, 0x7D, 0xF0, 0xF9, 0xFF, 0x8F, 0xFF ; #####   ######  #####    ##### #####    #####  ##########   ############
	dt 0xF8, 0xFC, 0xF8, 0x7D, 0xF0, 0xF8, 0xFF, 0x0F, 0xFF ; #####   ######  #####    ##### #####    #####   ########    ############
Table_hraje_end
hraje_len		equ Table_hraje_end - Table_hraje	
;}
						org 0x1300
Table_konec
;{
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x7C, 0x7E, 0x7F, 0xF3, 0xF3, 0xE7, 0xFF, 0x9F, 0xFE ;  #####   ######  ###########  ######  #####  ############  ############ 
		 dt 0x7C, 0xFC, 0xFF, 0xFB, 0xF3, 0xE7, 0xFF, 0xBF, 0xFE ;  #####  ######  ############# ######  #####  ############ ############# 
		 dt 0x7C, 0xF8, 0xFF, 0xFB, 0xFB, 0xE7, 0xFF, 0xBF, 0xFE ;  #####  #####   ############# ####### #####  ############ ############# 
		 dt 0x7D, 0xF0, 0xF8, 0xFB, 0xFF, 0xE7, 0xC0, 0x3E, 0x00 ;  ##### #####    #####   ##### #############  #####        #####         
		 dt 0x7F, 0xF0, 0xF8, 0xFB, 0xFF, 0xE7, 0xC0, 0x3E, 0x00 ;  ###########    #####   ##### #############  #####        #####         
		 dt 0x7F, 0xE0, 0xF8, 0xFB, 0xFF, 0xE7, 0xFF, 0xBE, 0x00 ;  ##########     #####   ##### #############  ############ #####         
		 dt 0x7F, 0xC0, 0xF8, 0xFB, 0xFF, 0xE7, 0xFF, 0xBE, 0x00 ;  #########      #####   ##### #############  ############ #####         
		 dt 0x7F, 0xE0, 0xF8, 0xFB, 0xFF, 0xE7, 0xFF, 0xBE, 0x00 ;  ##########     #####   ##### #############  ############ #####         
		 dt 0x7F, 0xF0, 0xF8, 0xFB, 0xEF, 0xE7, 0xC0, 0x3E, 0x00 ;  ###########    #####   ##### ##### #######  #####        #####         
		 dt 0x7D, 0xF8, 0xF8, 0xFB, 0xEF, 0xE7, 0xC0, 0x3E, 0x00 ;  ##### ######   #####   ##### ##### #######  #####        #####         
		 dt 0x7C, 0xF8, 0xFF, 0xFB, 0xE7, 0xE7, 0xFF, 0xBF, 0xFE ;  #####  #####   ############# #####  ######  ############ ############# 
		 dt 0x7C, 0xFC, 0xFF, 0xFB, 0xE7, 0xE7, 0xFF, 0xBF, 0xFE ;  #####  ######  ############# #####  ######  ############ ############# 
		 dt 0x7C, 0x7E, 0x7F, 0xF3, 0xE3, 0xE7, 0xFF, 0x9F, 0xFE ;  #####   ######  ###########  #####   #####  ############  ############ 
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0xF8, 0xF9, 0xFF, 0xEF, 0xC7, 0xE0, 0x00 ;                 #####   #####  ############ ######   ######             
		 dt 0x00, 0x00, 0xF8, 0xF9, 0xFF, 0xF7, 0xC7, 0xC0, 0x00 ;                 #####   #####  ############# #####   #####              
		 dt 0x00, 0x00, 0xF8, 0xF9, 0xFF, 0xF3, 0xEF, 0x80, 0x00 ;                 #####   #####  #############  ##### #####               	
Table_konec_end
konec_len		equ Table_konec_end - Table_konec		
;}	
						org 0x1400
Table_hry
;{
		 dt 0x00, 0x00, 0xF8, 0xF9, 0xF1, 0xF3, 0xEF, 0x80, 0x00 ;                 #####   #####  #####   #####  ##### #####               
		 dt 0x00, 0x00, 0xF8, 0xF9, 0xF1, 0xF1, 0xFF, 0x00, 0x00 ;                 #####   #####  #####   #####   #########                
		 dt 0x00, 0x00, 0xFF, 0xF9, 0xFF, 0xE1, 0xFF, 0x00, 0x00 ;                 #############  ############    #########                
		 dt 0x00, 0x00, 0xFF, 0xF9, 0xFF, 0xE0, 0xFE, 0x00, 0x00 ;                 #############  ############     #######                 
		 dt 0x00, 0x00, 0xFF, 0xF9, 0xFF, 0xF0, 0x7C, 0x00, 0x00 ;                 #############  #############     #####                  
		 dt 0x00, 0x00, 0xF8, 0xF9, 0xF1, 0xF0, 0x7C, 0x00, 0x00 ;                 #####   #####  #####   #####     #####                  
		 dt 0x00, 0x00, 0xF8, 0xF9, 0xF1, 0xF0, 0x7C, 0x00, 0x00 ;                 #####   #####  #####   #####     #####                  
		 dt 0x00, 0x00, 0xF8, 0xF9, 0xF1, 0xF0, 0x7C, 0x00, 0x00 ;                 #####   #####  #####   #####     #####                  
		 dt 0x00, 0x00, 0xF8, 0xF9, 0xF1, 0xF0, 0x7C, 0x00, 0x00 ;                 #####   #####  #####   #####     #####                  
		 dt 0x00, 0x00, 0xF8, 0xF9, 0xF1, 0xF0, 0x7C, 0x00, 0x00 ;                 #####   #####  #####   #####     #####                  
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         
		 dt 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;                                                                         	
;}		 
Table_hry_end
hry_len		equ Table_hry_end - Table_hry	


;White on Green
TFT_setWhiteOnGreen
;{
	movlw HIGH TFT_GREEN
    movwf TFT_pieceBGColor+0
    movlw LOW TFT_GREEN
    movwf TFT_pieceBGColor+1
    movlw HIGH TFT_WHITE
    movwf TFT_pieceFGColor+0
    movlw LOW TFT_WHITE
    movwf TFT_pieceFGColor+1
    return
;}

	
						org 0x1500
Table_logo
;{					
Table_logo0
	 dt 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 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, 0x00, 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, 0x00, 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, 0x00, 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, 0x00, 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, 0x00, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                                                                                                                                                                                      #
	 dt 0x81, 0xFF, 0xFF, 0xFE, 0x07, 0xFF, 0xFF, 0xFB, 0xFF, 0x00, 0x1F, 0xF9, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xC0, 0x1F, 0xFF, 0xFF, 0x03, 0xFF, 0x01 ; #      ########################      ######################## ##########           ##########  ########################   ########################         #####################      ##########       #
	 dt 0x81, 0xFF, 0xFF, 0xFF, 0x87, 0xFF, 0xFF, 0xF9, 0xFF, 0x00, 0x1F, 0xF1, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xF0, 0x7F, 0xFF, 0xFF, 0x03, 0xFF, 0x01 ; #      ##########################    ########################  #########           #########   ########################   ##########################     #######################      ##########       #
	 dt 0x81, 0xFF, 0xFF, 0xFF, 0x87, 0xFF, 0xFF, 0xF9, 0xFF, 0x80, 0x3F, 0xF1, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xF0, 0xFF, 0xFF, 0xFF, 0x03, 0xFF, 0x01 ; #      ##########################    ########################  ##########         ##########   ########################   ##########################    ########################      ##########       #
Table_logo0_end
logo_len			equ Table_logo0_end - Table_logo0
	 
					org 0x1600
Table_logo1
	 dt 0x81, 0xFF, 0xFF, 0xFF, 0x87, 0xFF, 0xFF, 0xF9, 0xFF, 0x80, 0x3F, 0xE1, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xF1, 0xFF, 0xFF, 0xFF, 0x03, 0xFF, 0x01 ; #      ##########################    ########################  ##########         #########    ########################   ##########################   #########################      ##########       #
	 dt 0x81, 0xFF, 0xFF, 0xFF, 0xC7, 0xFF, 0xFF, 0xF8, 0xFF, 0x80, 0x3F, 0xE1, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xF9, 0xFF, 0xFF, 0xFF, 0x03, 0xFF, 0x01 ; #      ###########################   ########################   #########         #########    ########################   ###########################  #########################      ##########       #
	 dt 0x81, 0xFF, 0xFF, 0xFF, 0xC7, 0xFF, 0xFF, 0xF8, 0xFF, 0xC0, 0x7F, 0xE1, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xF9, 0xFF, 0xFF, 0xFF, 0x03, 0xFF, 0x01 ; #      ###########################   ########################   ##########       ##########    ########################   ###########################  #########################      ##########       #
	 dt 0x81, 0xFF, 0xFF, 0xFF, 0xC7, 0xFF, 0xFF, 0xF8, 0xFF, 0xC0, 0x7F, 0xE1, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xF9, 0xFF, 0xFF, 0xFF, 0x03, 0xFF, 0x01 ; #      ###########################   ########################   ##########       ##########    ########################   ###########################  #########################      ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFE, 0x00, 0x00, 0x7F, 0xC0, 0x7F, 0xC1, 0xFF, 0x80, 0x00, 0x3F, 0xF0, 0x1F, 0xF9, 0xFF, 0x80, 0x00, 0x03, 0xFF, 0x01 ; #      ##########       ##########   ##########                  #########       #########     ##########                 ##########       ##########  ##########                     ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFE, 0x00, 0x00, 0x7F, 0xE0, 0xFF, 0xC1, 0xFF, 0x80, 0x00, 0x3F, 0xF0, 0x1F, 0xF9, 0xFF, 0x80, 0x00, 0x03, 0xFF, 0x01 ; #      ##########       ##########   ##########                  ##########     ##########     ##########                 ##########       ##########  ##########                     ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFE, 0x00, 0x00, 0x7F, 0xE0, 0xFF, 0xC1, 0xFF, 0x80, 0x00, 0x3F, 0xF0, 0x1F, 0xF9, 0xFF, 0x80, 0x00, 0x03, 0xFF, 0x01 ; #      ##########       ##########   ##########                  ##########     ##########     ##########                 ##########       ##########  ##########                     ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFE, 0x00, 0x00, 0x3F, 0xE0, 0xFF, 0x81, 0xFF, 0x80, 0x00, 0x3F, 0xF0, 0x1F, 0xF9, 0xFF, 0x80, 0x00, 0x03, 0xFF, 0x01 ; #      ##########       ##########   ##########                   #########     #########      ##########                 ##########       ##########  ##########                     ##########       #
	 dt 0x81, 0xFF, 0xFF, 0xFF, 0xC7, 0xFF, 0xFF, 0xF8, 0x3F, 0xF1, 0xFF, 0x81, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xF9, 0xFF, 0xFF, 0xFE, 0x03, 0xFF, 0x01 ; #      ###########################   ########################     ##########   ##########      ########################   ###########################  ########################       ##########       #
	 dt 0x81, 0xFF, 0xFF, 0xFF, 0x87, 0xFF, 0xFF, 0xF8, 0x3F, 0xF1, 0xFF, 0x81, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xF1, 0xFF, 0xFF, 0xFF, 0x83, 0xFF, 0x01 ; #      ##########################    ########################     ##########   ##########      ########################   ##########################   ##########################     ##########       #

					org 0x1700
Table_logo2
	 dt 0x81, 0xFF, 0xFF, 0xFE, 0x07, 0xFF, 0xFF, 0xF8, 0x1F, 0xF1, 0xFF, 0x01, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xC1, 0xFF, 0xFF, 0xFF, 0x83, 0xFF, 0x01 ; #      ########################      ########################      #########   #########       ########################   ########################     ##########################     ##########       #
	 dt 0x81, 0xFF, 0xFF, 0xFF, 0x87, 0xFF, 0xFF, 0xF8, 0x1F, 0xFB, 0xFF, 0x01, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xF1, 0xFF, 0xFF, 0xFF, 0xC3, 0xFF, 0x01 ; #      ##########################    ########################      ########## ##########       ########################   ##########################   ###########################    ##########       #
	 dt 0x81, 0xFF, 0xFF, 0xFF, 0xC7, 0xFF, 0xFF, 0xF8, 0x0F, 0xFB, 0xFE, 0x01, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xF8, 0xFF, 0xFF, 0xFF, 0xC3, 0xFF, 0x01 ; #      ###########################   ########################       ######### #########        ########################   ###########################   ##########################    ##########       #
	 dt 0x81, 0xFF, 0xFF, 0xFF, 0xC7, 0xFF, 0xFF, 0xF8, 0x0F, 0xFB, 0xFE, 0x01, 0xFF, 0xFF, 0xFE, 0x3F, 0xFF, 0xFF, 0xF8, 0x3F, 0xFF, 0xFF, 0xC3, 0xFF, 0x01 ; #      ###########################   ########################       ######### #########        ########################   ###########################     ########################    ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFE, 0x00, 0x00, 0x0F, 0xFF, 0xFE, 0x01, 0xFF, 0x80, 0x00, 0x3F, 0xF0, 0x1F, 0xF8, 0x00, 0x00, 0xFF, 0xC3, 0xFF, 0x01 ; #      ##########       ##########   ##########                     ###################        ##########                 ##########       ##########                   ##########    ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFE, 0x00, 0x00, 0x07, 0xFF, 0xFC, 0x01, 0xFF, 0x80, 0x00, 0x3F, 0xF0, 0x1F, 0xF8, 0x00, 0x00, 0xFF, 0xC3, 0xFF, 0x01 ; #      ##########       ##########   ##########                      #################         ##########                 ##########       ##########                   ##########    ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFE, 0x00, 0x00, 0x07, 0xFF, 0xFC, 0x01, 0xFF, 0x80, 0x00, 0x3F, 0xF0, 0x1F, 0xF8, 0x00, 0x00, 0xFF, 0xC3, 0xFF, 0x01 ; #      ##########       ##########   ##########                      #################         ##########                 ##########       ##########                   ##########    ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFE, 0x00, 0x00, 0x07, 0xFF, 0xFC, 0x01, 0xFF, 0x80, 0x00, 0x3F, 0xF0, 0x1F, 0xF8, 0x00, 0x00, 0xFF, 0xC3, 0xFF, 0x01 ; #      ##########       ##########   ##########                      #################         ##########                 ##########       ##########                   ##########    ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFF, 0xFF, 0xF8, 0x03, 0xFF, 0xF8, 0x01, 0xFF, 0xFF, 0xFE, 0x3F, 0xF0, 0x1F, 0xF9, 0xFF, 0xFF, 0xFF, 0xC3, 0xFF, 0x01 ; #      ##########       ##########   ########################         ###############          ########################   ##########       ##########  ###########################    ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFF, 0xFF, 0xF8, 0x03, 0xFF, 0xF8, 0x01, 0xFF, 0xFF, 0xFE, 0x3F, 0xF0, 0x1F, 0xF9, 0xFF, 0xFF, 0xFF, 0xC3, 0xFF, 0x01 ; #      ##########       ##########   ########################         ###############          ########################   ##########       ##########  ###########################    ##########       #

	 				org 0x1800
Table_logo3
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFF, 0xFF, 0xF8, 0x03, 0xFF, 0xF8, 0x01, 0xFF, 0xFF, 0xFE, 0x3F, 0xF0, 0x1F, 0xF9, 0xFF, 0xFF, 0xFF, 0xC3, 0xFF, 0x01 ; #      ##########       ##########   ########################         ###############          ########################   ##########       ##########  ###########################    ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFF, 0xFF, 0xF8, 0x01, 0xFF, 0xF0, 0x01, 0xFF, 0xFF, 0xFE, 0x3F, 0xF0, 0x1F, 0xF9, 0xFF, 0xFF, 0xFF, 0xC3, 0xFF, 0x01 ; #      ##########       ##########   ########################          #############           ########################   ##########       ##########  ###########################    ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFF, 0xFF, 0xF8, 0x01, 0xFF, 0xF0, 0x01, 0xFF, 0xFF, 0xFE, 0x3F, 0xF0, 0x1F, 0xF9, 0xFF, 0xFF, 0xFF, 0x83, 0xFF, 0x01 ; #      ##########       ##########   ########################          #############           ########################   ##########       ##########  ##########################     ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFF, 0xFF, 0xF8, 0x01, 0xFF, 0xF0, 0x01, 0xFF, 0xFF, 0xFE, 0x3F, 0xF0, 0x1F, 0xF9, 0xFF, 0xFF, 0xFF, 0x83, 0xFF, 0x01 ; #      ##########       ##########   ########################          #############           ########################   ##########       ##########  ##########################     ##########       #
	 dt 0x81, 0xFF, 0x80, 0xFF, 0xC7, 0xFF, 0xFF, 0xF8, 0x00, 0xFF, 0xE0, 0x01, 0xFF, 0xFF, 0xFE, 0x3F, 0xF0, 0x1F, 0xF9, 0xFF, 0xFF, 0xFE, 0x03, 0xFF, 0x01 ; #      ##########       ##########   ########################           ###########            ########################   ##########       ##########  ########################       ##########       #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x00, 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, 0x00, 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, 0x00, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                                                                                                                                                                                      #

					org 0x1900		
Table_logo4
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x00, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                                                                                                                                                                                      #
	 dt 0x83, 0xFF, 0xCF, 0x80, 0x00, 0xF8, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x00, 0xF8, 0x00, 0x3C, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x01 ; #     ############  #####               #####        #####                                            #####             #####             ####             #####                                       #
	 dt 0x83, 0xFF, 0xCF, 0x80, 0x00, 0xF8, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE0, 0x00, 0xF8, 0x00, 0x70, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x01 ; #     ############  #####               #####        #####                                            #####             #####            ###               #####                                       #
	 dt 0x83, 0xFF, 0xCF, 0x80, 0x00, 0xF8, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x01 ; #     ############  #####               #####        #####                                                              #####                              #####                                       #
	 dt 0x83, 0xE0, 0x0F, 0x8F, 0xFC, 0xF9, 0xF7, 0xC1, 0xFF, 0xCF, 0xFC, 0xFF, 0xE3, 0xE3, 0xFE, 0xF9, 0xF3, 0xFF, 0x80, 0x1F, 0xFC, 0x7F, 0xF3, 0xFF, 0x81 ; #     #####         #####   ##########  #####  ##### #####     ###########  ##########  ###########   #####   ######### #####  #####  ###########          ###########   ###########  ###########      #
	 dt 0x83, 0xE0, 0x0F, 0x9F, 0xFE, 0xFB, 0xEF, 0xFD, 0xFF, 0xDF, 0xFE, 0xFF, 0xF3, 0xE7, 0xFE, 0xFB, 0xE7, 0xFF, 0x80, 0x1F, 0xFE, 0x7F, 0xF7, 0xFF, 0x81 ; #     #####         #####  ############ ##### ##### ########## ########### ############ ############  #####  ########## ##### #####  ############          ############  ########### ############      #
	 dt 0x83, 0xFF, 0xCF, 0x9F, 0xFE, 0xFB, 0xEF, 0xFD, 0xFF, 0xDF, 0xFE, 0xFF, 0xF3, 0xE7, 0xFE, 0xFB, 0xE7, 0xFF, 0x80, 0x1F, 0xFE, 0x7F, 0xF7, 0xFF, 0x81 ; #     ############  #####  ############ ##### ##### ########## ########### ############ ############  #####  ########## ##### #####  ############          ############  ########### ############      #
	 dt 0x83, 0xFF, 0xCF, 0x9F, 0x3E, 0xFF, 0xC7, 0xC1, 0xF7, 0xDF, 0x3E, 0xF9, 0xF3, 0xE7, 0xC0, 0xFF, 0xC7, 0xCF, 0x80, 0x1F, 0x3E, 0x7D, 0xF7, 0xCF, 0x81 ; #     ############  #####  #####  ##### ##########   #####     ##### ##### #####  ##### #####  #####  #####  #####      ##########   #####  #####          #####  #####  ##### ##### #####  #####      #	 
					org 0x1A00				
Table_logo5
	 dt 0x83, 0xFF, 0xCF, 0x9F, 0xFE, 0xFF, 0xC7, 0xC1, 0xF7, 0xDF, 0x3E, 0xF9, 0xF3, 0xE7, 0xC0, 0xFF, 0xC7, 0xCF, 0x80, 0x1F, 0x3E, 0x7D, 0xF7, 0xCF, 0x81 ; #     ############  #####  ############ ##########   #####     ##### ##### #####  ##### #####  #####  #####  #####      ##########   #####  #####          #####  #####  ##### ##### #####  #####      #
	 dt 0x83, 0xE0, 0x0F, 0x9F, 0x00, 0xFF, 0xC7, 0xC1, 0xF0, 0x1F, 0x3E, 0xF9, 0xF3, 0xE7, 0xC0, 0xFF, 0xC7, 0xCF, 0x80, 0x1F, 0x3E, 0x7C, 0x07, 0xCF, 0x81 ; #     #####         #####  #####        ##########   #####     #####       #####  ##### #####  #####  #####  #####      ##########   #####  #####          #####  #####  #####       #####  #####      #
	 dt 0x83, 0xE0, 0x0F, 0x9F, 0x00, 0xFF, 0xC7, 0xC1, 0xF0, 0x1F, 0x3E, 0xF9, 0xFB, 0xE7, 0xC0, 0xFF, 0xC7, 0xCF, 0x80, 0x1F, 0x3E, 0x7C, 0x07, 0xCF, 0x81 ; #     #####         #####  #####        ##########   #####     #####       #####  ##### #####  ###### #####  #####      ##########   #####  #####          #####  #####  #####       #####  #####      #
	 dt 0x83, 0xFF, 0xCF, 0x9F, 0xF8, 0xFB, 0xE7, 0xFD, 0xF0, 0x1F, 0xFE, 0xF9, 0xFB, 0xE7, 0xFE, 0xFB, 0xE7, 0xFF, 0xC0, 0x1F, 0x3F, 0x7C, 0x07, 0xFF, 0xC1 ; #     ############  #####  ##########   ##### #####  ######### #####       ############ #####  ###### #####  ########## ##### #####  #############         #####  ###### #####       #############     #
	 dt 0x83, 0xFF, 0xCF, 0x9F, 0xF8, 0xFB, 0xE7, 0xFD, 0xF0, 0x1F, 0xFE, 0xF9, 0xFB, 0xE7, 0xFE, 0xFB, 0xE7, 0xFF, 0xC0, 0x1F, 0x3F, 0x7C, 0x07, 0xFF, 0xC1 ; #     ############  #####  ##########   ##### #####  ######### #####       ############ #####  ###### #####  ########## ##### #####  #############         #####  ###### #####       #############     #
	 dt 0x83, 0xFF, 0xCF, 0x8F, 0xF8, 0xF9, 0xF3, 0xFD, 0xF0, 0x0F, 0xFC, 0xF8, 0xFB, 0xE3, 0xFE, 0xF9, 0xF3, 0xFF, 0xC0, 0x1F, 0x1F, 0x7C, 0x03, 0xFF, 0xC1 ; #     ############  #####   #########   #####  #####  ######## #####        ##########  #####   ##### #####   ######### #####  #####  ############         #####   ##### #####        ############     #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x00, 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, 0x00, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                                                                                                                                                                                      #

					org 0x1B00
Table_logo6
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x00, 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, 0x00, 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, 0x00, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                                                                                                                                                                                      #
	 dt 0x81, 0xE0, 0x07, 0x80, 0x1E, 0x00, 0x78, 0x01, 0xE0, 0x07, 0x80, 0x1E, 0x00, 0x78, 0x01, 0xE0, 0x07, 0x80, 0x1E, 0x00, 0x78, 0x01, 0xE0, 0x07, 0x81 ; #      ####          ####          ####          ####          ####          ####          ####          ####          ####          ####          ####          ####          ####          ####      #
	 dt 0x87, 0xF8, 0x18, 0x60, 0x7F, 0x81, 0x86, 0x07, 0xF8, 0x18, 0x60, 0x7F, 0x81, 0x86, 0x07, 0xF8, 0x18, 0x60, 0x7F, 0x81, 0x86, 0x07, 0xF8, 0x18, 0x61 ; #    ########      ##    ##      ########      ##    ##      ########      ##    ##      ########      ##    ##      ########      ##    ##      ########      ##    ##      ########      ##    ##    #
	 dt 0x8F, 0xFC, 0x20, 0x10, 0xFF, 0xC2, 0x01, 0x0F, 0xFC, 0x20, 0x10, 0xFF, 0xC2, 0x01, 0x0F, 0xFC, 0x20, 0x10, 0xFF, 0xC2, 0x01, 0x0F, 0xFC, 0x20, 0x11 ; #   ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #   #
	 dt 0x8F, 0xFC, 0x20, 0x10, 0xFF, 0xC2, 0x01, 0x0F, 0xFC, 0x20, 0x10, 0xFF, 0xC2, 0x01, 0x0F, 0xFC, 0x20, 0x10, 0xFF, 0xC2, 0x01, 0x0F, 0xFC, 0x20, 0x11 ; #   ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #   #
	 dt 0x9F, 0xFE, 0x40, 0x09, 0xFF, 0xE4, 0x00, 0x9F, 0xFE, 0x40, 0x09, 0xFF, 0xE4, 0x00, 0x9F, 0xFE, 0x40, 0x09, 0xFF, 0xE4, 0x00, 0x9F, 0xFE, 0x40, 0x09 ; #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  #

	 				org 0x1C00
Table_logo7
	 dt 0x9F, 0xFE, 0x40, 0x09, 0xFF, 0xE4, 0x00, 0x9F, 0xFE, 0x40, 0x09, 0xFF, 0xE4, 0x00, 0x9F, 0xFE, 0x40, 0x09, 0xFF, 0xE4, 0x00, 0x9F, 0xFE, 0x40, 0x09 ; #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  #
	 dt 0x9F, 0xFE, 0x40, 0x09, 0xFF, 0xE4, 0x00, 0x9F, 0xFE, 0x40, 0x09, 0xFF, 0xE4, 0x00, 0x9F, 0xFE, 0x40, 0x09, 0xFF, 0xE4, 0x00, 0x9F, 0xFE, 0x40, 0x09 ; #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  #
	 dt 0x9F, 0xFE, 0x40, 0x09, 0xFF, 0xE4, 0x00, 0x9F, 0xFE, 0x40, 0x09, 0xFF, 0xE4, 0x00, 0x9F, 0xFE, 0x40, 0x09, 0xFF, 0xE4, 0x00, 0x9F, 0xFE, 0x40, 0x09 ; #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  ############  #          #  #
	 dt 0x8F, 0xFC, 0x20, 0x10, 0xFF, 0xC2, 0x01, 0x0F, 0xFC, 0x20, 0x10, 0xFF, 0xC2, 0x01, 0x0F, 0xFC, 0x20, 0x10, 0xFF, 0xC2, 0x01, 0x0F, 0xFC, 0x20, 0x11 ; #   ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #   #
	 dt 0x8F, 0xFC, 0x20, 0x10, 0xFF, 0xC2, 0x01, 0x0F, 0xFC, 0x20, 0x10, 0xFF, 0xC2, 0x01, 0x0F, 0xFC, 0x20, 0x10, 0xFF, 0xC2, 0x01, 0x0F, 0xFC, 0x20, 0x11 ; #   ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #    ##########    #        #   #
	 dt 0x87, 0xF8, 0x18, 0x60, 0x7F, 0x81, 0x86, 0x07, 0xF8, 0x18, 0x60, 0x7F, 0x81, 0x86, 0x07, 0xF8, 0x18, 0x60, 0x7F, 0x81, 0x86, 0x07, 0xF8, 0x18, 0x61 ; #    ########      ##    ##      ########      ##    ##      ########      ##    ##      ########      ##    ##      ########      ##    ##      ########      ##    ##      ########      ##    ##    #
	 dt 0x81, 0xE0, 0x07, 0x80, 0x1E, 0x00, 0x78, 0x01, 0xE0, 0x07, 0x80, 0x1E, 0x00, 0x78, 0x01, 0xE0, 0x07, 0x80, 0x1E, 0x00, 0x78, 0x01, 0xE0, 0x07, 0x81 ; #      ####          ####          ####          ####          ####          ####          ####          ####          ####          ####          ####          ####          ####          ####      #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x00, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                                                                                                                                                                                      #





					org 0x1D00
Table_logo8
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x00, 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, 0x00, 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, 0x00, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                                                                                                                                                                                      #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x81, 0xC0, 0x00, 0x03, 0xFE, 0xE7, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                        #########                                                    ###      ###                    ######### ###  ########                                          #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x81, 0xC0, 0x00, 0x03, 0xFE, 0xEF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                        #########                                                    ###      ###                    ######### ### #########                                          #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x71, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x81, 0xC0, 0x00, 0x03, 0x8E, 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                        ###   ###                                                    ###      ###                    ###   ### ### ###                                                #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x71, 0xCF, 0xDD, 0xB8, 0xFE, 0xFE, 0x7F, 0x7F, 0x81, 0xFF, 0xC7, 0x03, 0x8E, 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                        ###   ###  ###### ### ## ###   ####### #######  ####### ########      ###########   ###      ###   ### ### ###                                                #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x71, 0xDF, 0xFD, 0xB9, 0xFE, 0xFE, 0xFF, 0x7F, 0x81, 0xFE, 0xC6, 0x03, 0x8E, 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                        ###   ### ########### ## ###  ######## ####### ######## ########      ######## ##   ##       ###   ### ### ###                                                #
					org 0x1E00
Table_logo9
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xDC, 0xED, 0xB1, 0xCE, 0xEE, 0xE7, 0x73, 0x81, 0xCE, 0xEE, 0x03, 0xFE, 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                        ######### ###  ### ## ## ##   ###  ### ### ### ###  ### ###  ###      ###  ### ### ###       ######### ### ###                                                #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xDC, 0xEF, 0xF1, 0xFE, 0xEE, 0xFF, 0x73, 0x81, 0xCE, 0xEE, 0x03, 0xFE, 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                        ######### ###  ### ########   ######## ### ### ######## ###  ###      ###  ### ### ###       ######### ### ###                                                #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x70, 0x1C, 0xEF, 0xF1, 0xC0, 0xE0, 0xE0, 0x73, 0x81, 0xCE, 0x6C, 0x03, 0x80, 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                        ###       ###  ### ########   ###      ###     ###      ###  ###      ###  ###  ## ##        ###       ### ###                                                #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x70, 0x1F, 0xE7, 0xE1, 0xFC, 0xE0, 0xFE, 0x7F, 0x81, 0xFE, 0x7C, 0x03, 0x80, 0xEF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                        ###       ########  ######    #######  ###     #######  ########      ########  #####        ###       ### #########                                          #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x70, 0x0F, 0xC7, 0xE1, 0xFC, 0xE0, 0xFE, 0x7F, 0x81, 0xFE, 0x78, 0x03, 0x80, 0xE7, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                        ###        ######   ######    #######  ###     #######  ########      ########  ####         ###       ###  ########                                          #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                                                                                                         ###                                                                          #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                                                                                                       ####                                                                           #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ; #                                                                                                                       ####                                                                           #
	 dt 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ; ########################################################################################################################################################################################################
;}					

;Nastavi JOY_increment podle JOY_ADresult 
;JOY_increment = 0		  AD result <64, 191>
;JOY_increment = 255 (-1) AD result <0, 63>
;JOY_increment = 1		  AD result <192, 255>
;Vystup: uprav BOARD_x, BOARD_y podle pohybu joysticku

JOY_handleMoveX
;{
	clrf JOY_increment		;Default - zadna zmena
	movlw .256 - .64		;192
	addwf JOY_ADresult, w	;1) <0,63>
	btfsc STATUS, C
	goto JOY_notZeroX
	incf JOY_increment, f	;Bylo doleva, 255 (-1)
	goto JOY_adjust_X
JOY_notZeroX	
	movlw .256 - .192		;64
	addwf JOY_ADresult, w	;2) <64,191>		
	btfss STATUS, C
	return					;3) else > 64 && < 191 tj. zadna zmena X
	decf JOY_increment, f	
JOY_adjust_X
	goto JOY_checkRollOver	

JOY_handleMoveY
;{
	clrf JOY_increment		;Default - zadna zmena
	movlw .256 - .64		;192
	addwf JOY_ADresult, w	;1) <0,63>
	btfsc STATUS, C
	goto JOY_notZeroY
	decf JOY_increment, f	;Bylo doleva, 255 (-1)
	goto JOY_adjust_Y
JOY_notZeroY	
	movlw .256 - .192		;64
	addwf JOY_ADresult, w	;2) <64,191>		
	btfss STATUS, C
	return					;3) else > 64 && < 191 tj. zadna zmena X
	incf JOY_increment, f	
JOY_adjust_Y
	goto JOY_checkRollOver	

;Zkontroluj meze boardu po zmene pozice X, Y
;Vstup JOY_increment - 255(-1) nebo 1
;Nastavi BOARD_x nebo BOARD_y (podle JOY_whichAdjust)
JOY_checkRollOver
	movf JOY_increment, w
	btfss JOY_whichAdjust, 0		;BOARD_x nebo BOARD_y?
	goto JOY_adjustX	
	addwf BOARD_y, f
	goto JOY_checkBoundaries
JOY_adjustX							;BOARD_x
	addwf BOARD_x, f
	
JOY_checkBoundaries					;Zkontroluj jestli jsme <0,7>
	movlw .8						;Horni mez 8
	btfss JOY_whichAdjust, 0		;BOARD_y
	goto JOY_checkBoundaryX
	xorwf BOARD_y, w
	goto JOY_8done	
JOY_checkBoundaryX
	xorwf BOARD_x, w		
JOY_8done	
	btfss STATUS, Z
	goto check_255
	btfss JOY_whichAdjust, 0		;snizime BOARD_x nebo BOARD_y?		
	goto JOY_checkDecX
	decf BOARD_y, f
	return
JOY_checkDecX
	decf BOARD_x, f	
	return
	
check_255
	movlw .255
	btfss JOY_whichAdjust, 0		;BOARD_y
	goto JOY_checkBoundaryX2
	xorwf BOARD_y, w
	goto JOY_255done
JOY_checkBoundaryX2
	xorwf BOARD_x, w
JOY_255done
	btfss STATUS, Z
	return							;Nic nemenime
	btfss JOY_whichAdjust, 0		;zvysime BOARD_x nebo BOARD_y?		
	goto JOY_checkIncX
	incf BOARD_y, f
	return
JOY_checkIncX
	incf BOARD_x, f	
	return
;}
		 
; *** KONEC SOUBORU *************************************************	
	end