;******************* TestDP512.RTF ***************
; Test program for the MC9S12DP512 for Real Mode
;  Jonathan W. Valvano 8/29/2008 9:17:36 AM

; This example accompanies either of the following two books
;   "Embedded Microcomputer Systems: Real Time Interfacing", Thomson, 
;         copyright (c) 2000, 2006,
;   "Introduction to Embedded Microcomputer Systems:
;    Motorola 6811 and 6812 Simulation", Thomson, copyright (c) 2002
; TExaS Copyright 2006 by Jonathan W. Valvano, valvano@mail.utexas.edu 
; You may use, edit, run or distribute this file 
;    as long as the above copyright notices remain
;*******************************************************   
DDRH     equ $0262  ; Port H Data Direction Register
DDRP     equ $025A  ; Port P Data Direction Register
DDRT     equ $0242  ; Port T Data Direction Register
PTH      equ $0260  ; Port H I/O Register
PTP      equ $0258  ; Port P I/O Register
PTT      equ $0240  ; Port T I/O Register
TCNT     equ $0044  ; Timer Count Register
TSCR1    equ $0046  ; Timer System Control Register1,  make bit7=1 to enable TCNT
      org  $0800    ; Globals go in 14K Ram
Avar  ds   1        ; Copy of output to Port P
Count ds   4
      org  $4000    ; Object code goes in 512K EEPROM (48K simulated)
Main  lds  #$4000   ; stack grows down from $3FFF
      ldaa #$FF
      staa DDRP     ; make all pins of Port P output
      cli
      ldaa #$80
      staa TSCR1    ; enable TCNT
      ldx  #0
      stx  Count
      stx  Count+2
loop  psha
      bsr  subroutine
      pula
      ldy  TCNT     ; TCNT increments every cycle
      ldx  Count+2
      inx
      stx  Count+2
      cpx  #0
      bne  loop
      ldab PTP
      stab Avar
      eorb #$80
      stab PTP
      ldx  Count
      inx
      stx  Count
      bra  loop     ; Repeat
subroutine
      ldaa #20
ll    deca
      bne  ll
      rts
      
      org  $FFFE
      fdb  Main     ; Starting address after a RESET