lab 4 part 2

This is the second post about lab for i am still on the data collection but it is completely working except for the backspace key.

define        SCINIT        $ff81 ; initialize/clear screen
define        CHRIN        $ffcf ; input character from keyboard
define        CHROUT        $ffd2 ; output character to screen
define        SCREEN        $ffed ; get screen size
define        PLOT        $fff0 ; get/set cursor coordinates
define    POINTER        $10    ; ptr: start of row
define    POINTER_H    $11
define    SPOINTER    $12    ; ptr: start of screen
define    SPOINTER_H    $13
define MAX_INPUT    $14

;brk
;ldy #$00
;clc
;cpy #0
;dey
    lda #$f0
    sta SPOINTER_H
    lda #40
    sta MAX_INPUT
   
          jsr SCINIT

          ldx #<label1    ; load XY with a pointer to the string to be printed
          ldy #>label1
      jsr prtstr    ; go print string

          ldx #<name    ; load XY with a pointer to the string to be read and store
          ldy #>name
          lda #len1 ; length of string

          jsr getstr    ; go get user input

          jsr SCINIT

          ldx #<label2
          ldy #>label2
          jsr prtstr

          ldx #<address    ; load XY with a pointer to the string to be read and stored
          ldy #>address
          lda #len2 ; length of string

          jsr getstr    ; go get user input

          jsr SCINIT

          ldx #<label3
          ldy #>label3
          jsr prtstr

          ldx #<city    ; load XY with a pointer to the string to be read and stored
          ldy #>city
          lda #len3 ; length of string

          jsr getstr    ; go get user input

          jsr SCINIT

          ldx #<label4    ; load XY with a pointer to the string to be printed
          ldy #>label4
      jsr prtstr    ; go print string

          ldx #<name    ; load XY with a pointer to the string to be printed
          ldy #>name
      jsr prtstr    ; go print string

      jsr prtcrlf

          ldx #<address    ; load XY with a pointer to the string to be printed
          ldy #>address
      jsr prtstr    ; go print string

      jsr prtcrlf

          ldx #<city    ; load XY with a pointer to the string to be printed
          ldy #>city
      jsr prtstr    ; go print string

      jsr prtcrlf
         
          brk
;this subroutine moves the code to a newline
; there is only one parameter
;prints a newline carriage return charater
prtcrlf:
      ldx #<crlf
      ldy #>crlf
      jsr prtstr

; this subroutine prints a NULL terminated string
; there is only one parameter
;    registers XY point to the string to be printed

prtstr:
          stx POINTER
          sty POINTER_H

          ldy #$00         

prtchar:    
          lda (POINTER),y
          beq prtstrdone

          jsr CHROUT

          iny
          bne prtchar

prtstrdone:
          rts

;this subroutine takes care of the typing and checking of keys
; there is 2 parameters the pointer and length of string

getstr:
     stx POINTER
         sty POINTER_H
    sta SPOINTER
    ldy    #$00
   
check2:
idle:     inx
          cpx #$10
          bne check
          lda (SPOINTER),y
          eor #$80
          sta (SPOINTER),y
check:    lda $ff
          beq idle

          ldx #$00
          stx $ff

          cmp #$08
          bne print

          lda (SPOINTER),y
          and #$7f
          sta (SPOINTER),y

          dey
          jmp next

print: 
    cpy MAX_INPUT
    beq maxed

     cmp #$0D    ; check key == enter
     beq done

     cmp #$83    ; check key == left   
     beq go_left

     cmp #$81    ; check key == go right
     beq go_right

    sta (SPOINTER),y
    sta (POINTER),y
 
          iny

maxed: 
          jmp check2

go_left:
;brk
    dey
    cpy #$ff
    bne not_at_left

    iny

not_at_left:
    jmp idle

go_right:
;brk
    lda (POINTER),y
    cmp #$00
;brk
    beq not_at_right

    iny

not_at_right:
    jmp idle

done: 
 
 rts

label1:
dcb "p","l","e","a","s","e",32,"e","n","t","e","r",32,"y","o","u","r",32,"n","a","m","e",":",00
define len1 24

label2:
dcb "p","l","e","a","s","e",32,"e","n","t","e","r",32,"y","o","u","r",32,"a","d","d","r","e","s","s",":",00
define len2 27

label3:
dcb "p","l","e","a","s","e",32,"e","n","t","e","r",32,"y","o","u","r",32,"c","i","t","y",32,"a","n","d",32,"p","o","s","t","a","l",32,"c","o","d","e",":",00
define len3 40

label4:
dcb "Y","o","u","r",32,"o","r","d","e","r",32,"w","i","l","l",32,"b","e",32,"d","e","l","i","v","e","r","e","d",32,"t","o",":",$0d,$0d,00

name:
dcb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,$0d

address:
dcb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,$0d

city:
dcb 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,$0d

crlf:
dcb $0d,0

Comments

Popular Posts