*****  Parallel I/O Port Registers    **********
PORTA:     equ $00     ;Port A Data Register
PORTB:     equ $01     ;Port B Data Register
DDRA:      equ $02     ;Port A Data Direction Register
DDRB:      equ $03     ;Port B Data Direction Register
PORTC:     equ $04     ;Port C Data Register
DDRC:      equ $06     ;Port C Data Direction Register
PORTE:     equ $08     ;Port E Data Register
DDRE:      equ $09     ;Port E Data Direction Register
PEAR:      equ $0A     ;Port E Assigment Register
MODE:      equ $0B     ;Mode Register
PUCR:      equ $0C     ;Pull Up Control Register
RDRIV:     equ $0D     ;Reduced Drive of I/O Lines Register
INITRM:    equ $10     ;Initialization of Internal RAM Position Register
INITRG:    equ $11     ;Initialization of Internal Register Position Register
INITEE:    equ $12     ;Inittaps
****************************************************************************

          ORG     $0800
COUNTER   RMB     1          ;DELAY COUNTER VALUE
*
* main program
*
         ORG     $0840
         LDAA    #$07        ;SET LOWER 3 BITS OF PORT A
         STAA    DDRA        ;TO OUTPUT MODE
         LDAA    #$FF        ;SET ALL PORT B BITS TO
         STAA    DDRB        ;OUTPUT MODE

DISINIT                      ;INITIALISE DISPLAY
         LDAA    #$30        ;SET UP THE FUNCTION
         JSR     WRITE_INST  ;
         LDAA    #!15
         JSR     LONGPAUSE
         LDAA    #$38
         JSR     WRITE_INST
         LDAA    #$08
         JSR     WRITE_INST
         LDAA    #$01
         JSR     WRITE_INST
         LDAA    #!4
         JSR     LONGPAUSE
         LDAA    #$06
         JSR     WRITE_INST
         LDAA    #$0C
         JSR     WRITE_INST

LINE_1
         LDAA   #$80               ;WRITE MESSAGE TO TOP LINE
         JSR    WRITE_INST         
         LDX    #STRING1
         JSR    WRITE_MESS
LINE_2
         LDAA   #$C0               ;WRITE MESSAGE TO SECOND LINE
         JSR    WRITE_INST
         LDX    #STRING2
         JSR    WRITE_MESS

;-------------------------------------------------------------------------
;This section of code writes a single character to the screen.

         LDAA   #$88		  ;Specify the address, i.e. the LCD               
         JSR    WRITE_INST	  ;location to write the character to.
         LDAA   #$25		  ;Specify the address of the character
         STAA   PORTB		  ;to send. See the spec for the character
         			  ;set.
	 
	 JSR    PAUSE		  ;This next section is identical to the				  		
         			  ;WRITE_DATA subroutine. This toggles the
			          ;LCD control lines for proper operation.
	 LDAA   #$01		  ;Toggle the RS line high.
         STAA   PORTA		 
         JSR    PAUSE		  
         LDAA   #$05		  ;Toggle the LCD ENB high, and keep RS hi
         STAA   PORTA	          
         JSR    PAUSE
         LDAA   #$01		  ;Toggle LCD ENB low, keepign RS high.
         STAA   PORTA
         JSR    PAUSE
;-------------------------------------------------------------------------
;This part of the code continously scrolls the screen to the left, without
;modifying the display.

Scroll   LDAA   #$1C               ;Send the scroll instruction to the LCD
         JSR    WRITE_INST	
         JSR    SUPER_WAIT         ;Wait a while before sending it again.
         BRA    Scroll		   ;Loop infinitely, scrolling the screen
				   ;forever.
;------------------------------------------------------------------------
SUPER_WAIT			   ;This is a delay function that uses			
        LDY     #$0300		   ;both of the 16 bit index registers		
Noch    LDX     #$0300		   ;to generate a delay. One is embedded
Loop2   DEX			   ;in the other. X counts all the way
        CPX    #$0000		   ;down, then Y is decremented once,
        BEQ     DownY	           ;then x decrements all the way again,
        BRA     Loop2		   ;and so on until Y is at zero.
DownY   DEY
        CPY     #$0000
        BNE     Noch
        RTS
;-------------------------------------------------------------------------

WRITE_MESS
NEXT_CHAR
         LDAA    0,X               ;LOAD STRING IN ACC
         CMPA    #$00              ;CHECK FOR END OF MESSAGE
         BEQ     END_MESS
         JSR     WRITE_DATA
         INX                       ;INCREMENT STRING POINTER
         BRA     NEXT_CHAR
END_MESS
         RTS

WRITE_MESS2
         LDX    #STRING2


WRITE_DATA                         ;ASSUME DATA IN ACCA
         STAA   PORTB              ;WRITE DATA TO PORTB
         LDAA   #$01               ;SET THE INTERFACE LINES FOR DATA WRITE
         STAA   PORTA
         JSR    PAUSE
         LDAA   #$05
         STAA   PORTA
         JSR    PAUSE
         LDAA   #$01
         STAA   PORTA
         JSR    PAUSE
         RTS

WRITE_INST			;Sets the proper control lines for an
         STAA   PORTB		;instruction write to the LCD.
         LDAA   #$00
         STAA   PORTA
         JSR    PAUSE
         LDAA   #$04
         STAA   PORTA
         JSR    PAUSE
         LDAA   #$00
         STAA   PORTA
         JSR    PAUSE
         RTS

LONGPAUSE
         STAA   COUNTER
LOOK     TST    COUNTER
         BEQ    FINISH
         DEC    COUNTER
         JSR    PAUSE
         BRA    LOOK
FINISH   RTS

PAUSE    LDY    #$00FF         ;DELAY FOR APPRO 1MS
AGAIN    DEY
         CPY    #$0000
         BNE    AGAIN
         RTS                    ;

STRING1  DB     '  Hi               Hi'
         FCB    $00
STRING2  DB     '  Bill               Bill'
         FCB    $00
