* Filename      : MEMTEST.ASM
* Programmer    : Michael Hattermann
* Date          : February 23, 2002
* Version       : 1.0
* Description   : This file contains a program to test
*                  RAM to see if it is working properly.
*                  It displays working address ranges of
*                  RAM between 8000 and FFFF in the
*                  memory map.
*
*
*

#include "hc12.asm"
*
************************************************************
* Memtest Equates
************************************************************
*
STARTADDR       EQU         $8000

*
************************************************************
* Memtest Constants/Variables
************************************************************
*
            ORG     USERPROG_PVECT
            JMP     TEST

            ORG     $0900
#include "sci.asm"
DONESTR     DC.B    CR,LF
            DC.B    'WE ARE DONE!!!!'
            DC.B    CR,LF,EOS

*
*******************************************************************************
*                       SUBROUTINE -  MEMTEST
* Description: Tests memory of working RAM address ranges
* Input         : None.
* Output        : None.
* Destroys      : None.
* Calls         : None.
*******************************************************************************
*
TEST
*            MOVB    #$00,COPCTL     ; turn off COP watchdog timer
*            MOVB    #$A0,MODE       ; turn off E-clk stretching
*            MOVB    #$00,INITEE     ; turn off internal EEPROM

             MOVB    #$00,SLOW       ; slow bus clock to 2Mhz

*            LDS     #$0bff          ; init the stack pointer

            JSR     INITSCI         ; init SCI system

            LDX     #STARTADDR      ; load the start address to start testing

TEST1       LDAA    #$FF            ; load first test byte
TEST2       STAA    0,X             ; write test byte to memory
            LDAB    0,X             ; read test byte from memory
            CBA                     ; did we read what we wrote?
            BNE     MOVEON          ; no, go handle
            TBEQ    A,BADMEM        ; are we done, then get out
            DECA                    ; decrement loop counter
            BRA     TEST2           ; continue checking

MOVEON      IBNE    X,TEST1         ; move to next mem byte if not done
            BRA     DONE            ; if we are done get out

BADMEM      JSR     OUTADDR         ; print bad memory address
            LDAA    #$2D            ; print "-"
            JSR     OUTCHAR         ;

BADLOOP     IBEQ    X,BADOUT        ; move to next addr; if we are done, get out

BADTEST1    LDAA    #$FF            ; load first test byte
BADTEST2    STAA    0,X             ; write test byte to memory
            LDAB    0,X             ; read test byte from memory
            CBA                     ; did we read what we wrote?
            BNE     BADOUT          ; no, move to next byte
            TBEQ    A,BADLOOP       ; are we done, then get out
            DECA                    ; decrement loop counter
            BRA     BADTEST2        ; continue checking

BADOUT      DEX                     ; decrement address to last valid
            JSR     OUTADDR         ; print address
            LDAA    #CR             ; print carrage return
            JSR     OUTCHAR         ;
            LDAA    #LF             ; print line feed
            JSR     OUTCHAR         ;
            BRA     MOVEON          ;

DONE        LDX     #DONESTR        ; print done message
            JSR     OUTSTR          ;
            SWI
HERE        BRA     HERE            ; end of program
*
*******************************************************************************
