;00000001-Prawo
;00000010-Lewo
;00000100-D
;00001000-Gra
;00010000-Start
;00100000-Select
;01000000-B
;10000000-A
KEYPAD:
	lda #$00   ; these lines tell $2003
	sta $2003  ; to tell
	lda #$00   ; $2004 to start
	sta $2003  ; at $0000.

	lda #$00
	sta $02

        lda Nacisn_guzik
        bne waitblank
        lda #$00
        sta Trzyma_guzik   ;Zresetuj moliwo nacinicia Select
;----------------------------------------------
waitblank:
	lda #$00   ; these lines tell $2003
	sta $2003  ; to tell
	lda #$00   ; $2004 to start
	sta $2003  ; at $0000.

	lda #$01   ; these
	sta $4016  ; lines
	lda #$00   ; setup/strobe the
	sta $4016  ; keypad.

           ldy #$08      ;read keypad
           ldx #$01
           stx $4016
           dex
           stx $4016

.r_bit:    lda $4016
           ROR A
           txa
           ROL A
           tax
           dey
           bne .r_bit

           cmp Nacisn_guzik
           beq .no_chg
           sta Nacisn_guzik
           

.no_chg:
        lda Nacisn_guzik
        bne kuncz
        lda #$00
        sta Trzyma_guzik

	lda Software
	AND #%11111110
	sta Software		;Czyci ze trzyba B po wziciu itemu
kuncz:        
        lda #$0
	   rts
