.equ PINA = 0x00 ; définition des adresses des ports
.equ DDRA = 0x01
.equ PORTA = 0x02
.equ PINC = 0x06
.equ DDRC = 0x07
.equ PORTC = 0x08
.equ PIND = 0x09
.equ DDRD = 0x0A
.equ PORTD = 0x0B

.equ SREG = 0x3F

.equ EIMSK = 0x3D
.equ EICRA = 0x69
.equ EICRB = 0x6A

.equ TCNT0 = 0x46
.equ OCR0A = 0x47
.equ OCR0B = 0x48
.equ TTCR0A = 0x24
.equ TTCR0B = 0x25
.equ TMSK0 = 0x6e

.equ RAMEND = 0x21FF
.equ SPH = 0x3E ; initialisation de la pile
.equ SPL = 0x3D

.org  0x000
    ; Vecteur RESET
    jmp debut

.org 0x0002 ; INT0
    jmp bouton

.org 0x0004 ; INT1
    jmp bouton

.org 0x0006 ; INT2
    jmp bouton

.org 0x0008 ; INT3
    jmp bouton

.org 0x002E ; Timer Overflow
    jmp timer

.org 0x0080

afficheur:
    .DB 0x3F, 0x30, 0x6D, 0x79, 0x72, 0x5B, 0x5F, 0x31, 0x7F, 0x7B
    ;      0,    1,    2,    3,    4,    5,    6,    7,    8,    9

debut:
    DDRA@IO <- 0xFF
    DDRC@IO <- 0xFF
    ;DDRD@IO <- 0x00
    EIMSK <- 0b00001111
    EICRA <- 0b10101010 ; TODO Oscillations annulables ?
    EICRB <- 0b00000000
    ; Timer
    ;TTCR0A@IO <- 0b00000001
    ;TTCR0B@IO <- 0b00000011
    ;TMSK0  <- 0b00000011
    ;OCR0A <- 100
    SEI

    PORTC@IO <- 0x00
    PORTA@IO <- 0x3F
    r20 <- 0

boucle:
    sleep
    saut boucle

valider:
    inc r20
    si r20 > 9 alors r20 <- 0
    PORTA@IO <- afficheur@ROM[r20]
    reti

bouton:
    ;TCNT0 <- 0
    jmp valider

reti:
    reti


timer:
    ;si (PORTD@IO & 0x01) = 0 saut valider
    ;r20 <- PORTC@IO
    ;inc r20
    ;PORTC@IO <- r20
    ;PORTA@IO <- PIND@IO
    reti

tca:
    reti

tempo:
    ldi r24,8
tempoA:
    subi r22,1
    sbci r23,0
    sbci r24,0
    brcc tempoA
    ret
