; L6NEW.asm - new Reslt Subr, better

;             management of data locations

; Code for Lab 6 on the EVB

; Must be modified to test on THRSim11

; Program prints a message to screen,

; accepts a keypress, and calculates

; reaction time in  SWI ISR.

;

       PutC  = bfd3  ;assign labels to the custom

       GetC  = bfd0  ; instruction address locations

;;;;;;;;;;;;;;;;;;;;;;;;

       IRQ = ef

       SWI = f5                         ; You may use these

       RTI = ec                          ; or make your own

       TCNT = 100e

;;;;;;;;;;;;;;;;;;;;;;;;

       org c00a

      

       db 0a,0d

       db 72,65,61,64                ; Message data

       db 79,28,79,20

       db 6f,72,20,6e

       db 29,3f,00

 

 

       org c200

 

Main:  lds #dfff  ; initialize the stack at bottom of

                                  ; memory

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Set jump table for

; Interrupt Svc. Routines

;  here

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

       clr c000                            ; initialize test data locations

       clr c001

       clr c002

       clr c003

 

First: ldy #c000     ; initialize data pointer

Load:  sty c006

       cli                     ; enable interrupts

       ldx #c00a

Send:  ldaa 0,x   ; load A with ASCII for Message

       beq Wait

       psha       ; push the contents of A onto the stack

       inx

       jsr PutC             ; Send message to screen

       bra Send

 

 

Wait:  jsr GetC   ; use GetC to detect a key press

       bcc Wait

       pula   ; when a key is pressed load the ASCII vale into A

       psha       ; put it back on the stack

       jsr PutC   ; dump the ASCII character for the key to the Monitor

       cmpa #79   ; check to see if the key press was "yes"

       beq Next

       cmpa #6e

       beq End

       bra Load

Next:  clr 0,y

       clr 1004

       com 1004                         ; blank the LEDs

       jsr DelVar        ; Wait for a variable time

       ldx #1000

       bset 24,x,40     ; Enable RTI interrupt

Port:  com 1004                     ; Shine LEDs

Spc:   jsr GetC                       ; Wait for spacebar press

       bcc Spc

       pula

       cmpa #20

       bne Spc

       psha

       ldx #0a0d

       pshx

       jsr PutC

       jsr PutC

       swi                   ; If Spacebar press, Interrupt

       ldy c006

       iny

       cpy #c004

       bne Load

       jmp First

End:   ldaa #65

       psha

       ldx #6279

       pshx

       ldx #0a0d

       pshx

       jsr PutC

       jsr PutC

       jsr PutC

       jsr PutC

       jsr PutC

       jsr DelVar

       swi

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DelVar:

 

; make your delay subroutine here

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

IRQSvc:

 

; make your IRQ ISR here

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

RTISvc:

 

; make your RTI ISR here

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SWISvc:

 

;make your SWI ISR here

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HtoA:

                                ; Convert 8-bit ASCII to 4-bit Hex

                                ; input registers: none - 8-bit

                                ;                  local variable

                                ;                                  passed to stack

                                ; output registers: none - 8-bit

                                ;                   local variable

                                ;                   passed to stack

                                ;                   4-bits of leading

                                ;                   zeros, 4-bits data

                                ;

       pshx ; store old values of X and A

       psha

       tsx      ; transfer SP contents to X

       ldaa 5,x ; load ASCII char from stack

       adda #30 ; stubtract 30 from ASCII

       cmpa #3a  ; check if number was less than A (10)

       blt Done ; if so, done, restore registers

       adda #27 ; if not, convert to "a" thru "f" value

Done:  staa 5,x ; put HEX number on stack

       pula     ; restore contents of A and X

       pulx

       rts

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Reslt:

;                               Input: 16 bit variable passed to stack

;                               Output: Puts 2 ASCII Char to Montr

;                               !!Data NOT removed from stack!!

;                               Does not corrupt registers

;                               Calls Subroutine Parse

       pshy

       pshx

       psha

       tsx

       ldaa 7,x

       psha

       psha

       jsr Parse

       jsr HtoA

       jsr PutC

       jsr HtoA

       jsr PutC

       ldaa 8,x

       psha

       psha

       jsr Parse

       jsr HtoA

       jsr PutC

       jsr HtoA

       jsr PutC

       ldx #6d53

       pshx

       jsr PutC

       jsr PutC

       pula

       pulx

       puly

       rts

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Parse:

;                               Subr to turn 8-bit Hex into

;                               2 4-bit Hex

;                               INPUT:  2 pushes of one 8-bit Hex

;                                               passed to the stack

;                               OUTPUT: 2 nibbles of 4-bit Hex

;                                               passed to the stack,

;                                               4-bits of leading zeros

       pshx

       psha

       pshb

       tsx

       ldaa 6,x

       tab

       anda #0f

       lsrb

       lsrb

       lsrb

       lsrb

       staa 7,x

       stab 6,x

       pulb

       pula

       pulx

       rts

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;