;*****************************************************************
;* This stationery serves as the framework for a                 *
;* user application (single file, absolute assembly application) *
;* For a more comprehensive program that                         *
;* demonstrates the more advanced functionality of this          *
;* processor, please see the demonstration applications          *
;* located in the examples subdirectory of the                   *
;* Metrowerks CodeWarrior for the HC12 Program directory         *
;*****************************************************************

; export symbols
            XDEF Entry        ; export 'Entry' symbol
            ABSENTRY Entry    ; for absolute assembly: mark this as application entry point

; include derivative specific macros
            INCLUDE 'mc9s12c32.inc'

ROMStart    EQU  $4000  ; absolute address to place code/constant data

PILE      	EQU	$0900	; User Stack

VECTEURS    equ	$ffd6





; variable/data section
            ORG RAMStart
      

; code section
            ORG ROMStart
Entry:      LDS	#PILE	; initialise la pile SP
                  
            SEI     ; interruption OFF
						
* initialise le diviseur de fréquence
            LDAA	#%00000111  ;  65.536ms pour E=8MHz
            STAA	RTICTL		
           

* initialise le flag RTIF 
            
            LDAA  #%10000000		; efface le flag
            STAA	CRGFLG        ; CRGFLG_RTIF

*  active RTIE 
                                 
            LDAA CRGINT
            ORAA #%10000000				; RTIE=1 active l'IT du timer RTI
            STAA CRGINT				                    
           
;            LDX    #60          ; temporisation
;boucle01    DEX   
;            CPX    #0   
;            BNE    boucle01
            
            CLI		 ; interruption ON
            ;WAI	 ; attente d'une multi-interruption 
            SWI    ; provoque une interruption logicielle 
                       
attend      BRA   attend


RTI_IRQ     LDAA	#%10000000 ; interruption materielle
            STAA	CRGFLG	
      			RTI


SWI_IRQ 		LDAA	#%10000000 ; interruption logicielle
      	  	STAA	CRGFLG	
					  RTI

; CRGFLG $37  RTIF=bit7    
; CRGINT $38  RTIE=bit7    
; RTICTL $3B  RTR[6:0]   

;**************************************************************
;*                 Interrupt Vectors                          *
;**************************************************************
  ORG $FFFE

  fdb     Entry      ; Reset
  
  ORG $FFF0
  
  fdb     RTI_IRQ;   
  
  ORG $FFF6
  
  fdb     SWI_IRQ;
  
  
 ; table des vecteurs d'interruption

   ORG	VECTEURS 


  fdb Entry ;SCIINT     ;  $FFD6     ; SCI serial system
  fdb Entry ;SPIINT     ; $FFD8     ; SPI serial system
  fdb Entry ;PAIINT     ;  $FFDA     ; Pulse Accumulator Input Edge
  fdb Entry ;PAOVINT    ; $FFDC     ; Pulse Accumulator Overflow
  fdb Entry ;TOINT      ;  $FFDE     ; Timer Overflow
  fdb Entry ;TOC5INT    ;  $FFE0     ; Timer Output Compare 5
  fdb Entry ;TOC4INT    ;  $FFE2      ; Timer Output Compare 4
  fdb Entry ;TOC3INT    ;  $FFE4     ; Timer Output Compare 3
  fdb Entry ;TOC2INT    ;  $FFE6     ; Timer Output Compare 2
  fdb Entry ;TOC1INT    ;  $FFE8     ; Timer Output Compare 1
  fdb Entry ;TIC3INT    ;  $FFEA     ; Timer Input Capture 3
  fdb Entry ;TIC2INT    ;  $FFEC     ; Timer Input Capture 2
  fdb Entry ;TIC1INT     ; $FFEE     ; Timer Input Capture 1
  fdb Entry ;RTIINT     ;  $FFF0     ; Real Time Interrupt
  fdb Entry ;IRQINT      ; $FFF2     ; IRQ External Interrupt
  fdb Entry ;XIRQINT     ; $FFF4     ; XIRQ External Interrupt
  fdb Entry ;SWIINT      ; $FFF6     ; Software Interrupt
  fdb Entry ;BADOPINT    ;$FFF8     ; Illegal Opcode Trap Interrupt
  fdb Entry ;NOCOPINT    ;$FFFA     ; COP Failure (Reset)
  fdb Entry ;CMEINT      ; $FFFC     ; COP Clock Monitor Fail (Reset)
  fdb Entry ;RESETINT    ; $FFFE     ; RESET Interrupt
  

  END

;  a) Mise à 1 du bit 4 (valeur sur 8 bits)
;LDAA valeur
;ORA #$10 (ou #%00010000)
;STAA valeur
;b) Mise à 0 du bit 4
;LDAA valeur
;ANDA #%EF (ou #%11101111)
;STAA valeur
;c) Changement d'état du bit 4
;LDAA valeur
;EORA #$10 ou exclusif
;STAA valeur

