summaryrefslogtreecommitdiff
path: root/cmpen472hw12_McDonnell/bin/main.dbg
diff options
context:
space:
mode:
Diffstat (limited to 'cmpen472hw12_McDonnell/bin/main.dbg')
-rw-r--r--cmpen472hw12_McDonnell/bin/main.dbg135
1 files changed, 127 insertions, 8 deletions
diff --git a/cmpen472hw12_McDonnell/bin/main.dbg b/cmpen472hw12_McDonnell/bin/main.dbg
index dead2ce..0e16fc5 100644
--- a/cmpen472hw12_McDonnell/bin/main.dbg
+++ b/cmpen472hw12_McDonnell/bin/main.dbg
@@ -151,9 +151,11 @@ CheckInput
cmpa #'Q' ; Compare A to 'Q'
lbeq cTypeWrite ; If A == 'Q', branch to cTypeWrite
cmpa #'M' ; Compare A to 'M'
- beq cMDCommand ; If A != 'M', Check if MD command
+ beq cMDCommand ; If A != 'M', Check if LD command
+ cmpa #'L' ; Compare A to 'L'
+ lbeq cLDCommand ; If A != 'L', Check if GO command
cmpa #'G' ; Compare A to 'G'
- beq cGoTo ; If A != 'G', Check if GO command
+ beq cGoTo ; If A != 'G', Check if L command
cmpa #'S' ; Compare A to 'S'
lbne cUnknownCMD ; If A != 'S', Command unknown
ldaa 0,x ; Load next character but don't increment
@@ -167,7 +169,7 @@ CheckInput
ldy lenBuf ; Loadd length of the buffer into Y
jsr Zeros ; Fill buffer with Zeros
pulx ; Restore X from the stack
- bra cDone ; branch always to cDone
+ lbra cDone ; branch always to cDone
cGoTo ldaa 1,x+ ; Load next character
cmpa #'O' ; Compare to 'O'
lbne cUnknownCMD ; If A != 'S', Command unknown
@@ -177,9 +179,36 @@ cGoTo ldaa 1,x+ ; Load next character
jsr ReadHex ; ReadHex to Read the memory Address
lbeq cBadAddr ; If Z == 1, branch to cBadAddr
jsr 0,y ; Launch address in Y
- bra cNoPrint ; Done with command
+ lbra cNoPrint ; Done with command
cMDCommand ldaa 1,x+ ; Load next character into A
cmpa #'D' ; Compare do 'D' character
+ lbne cUnknownCMD ; If A != 'D', unknown command
+ ldaa 0,x ; Load next character but don't increment
+ cmpa #'$' ; Compare A to '$'
+ lbne cUnknownCMD ; If A != '$', branch to unknown command
+ jsr ReadHex ; ReadHex to Read the memory Address
+ lbeq cBadAddr ; If Z == 1, branch to cBadAddr
+ exg Y,D ; Exchange Y and D
+ pshd ; Save D to the stack
+mSkipSpaces ldaa 1,x+ ; Load next character into A
+ lbeq cBadData ; If A == 0, branch to bad Data (no data given)
+ cmpa #' ' ; Compare A to space character
+ lbeq mSkipSpaces ; While A == ' ', loop to skip spaces
+ cmpa #'$' ; Compare A to '$'
+ lbne cBadData ; If A != '$', branch to cBadData
+ dex ; Decrement X by 1
+ jsr ReadHex ; Jump to ReadHex to read hex data
+ lbeq cBadData ; If Z == 1, branch to cBadData
+ puld ; Restore D from the stack
+ exg D,X ; Exchange D and X
+ pshd ; Save D to the stack, cBadData usually has 2 D's on the stack
+ cpy #2 ; Compare Y to 2
+ blo cBadData ; No distances below 2 bytes
+ puld ; Restore D from the stack
+ jsr MDCommand ; Jump to MDCommand
+ lbra cNoPrint ; Done with command
+cLDCommand ldaa 1,x+ ; Load next character into A
+ cmpa #'D' ; Compare do 'D' character
bne cUnknownCMD ; If A != 'D', unknown command
ldaa 0,x ; Load next character but don't increment
cmpa #'$' ; Compare A to '$'
@@ -188,10 +217,10 @@ cMDCommand ldaa 1,x+ ; Load next character into A
beq cBadAddr ; If Z == 1, branch to cBadAddr
exg Y,D ; Exchange Y and D
pshd ; Save D to the stack
-mSkipSpaces ldaa 1,x+ ; Load next character into A
+lSkipSpaces ldaa 1,x+ ; Load next character into A
beq cBadData ; If A == 0, branch to bad Data (no data given)
cmpa #' ' ; Compare A to space character
- beq mSkipSpaces ; While A == ' ', loop to skip spaces
+ beq lSkipSpaces ; While A == ' ', loop to skip spaces
cmpa #'$' ; Compare A to '$'
bne cBadData ; If A != '$', branch to cBadData
dex ; Decrement X by 1
@@ -200,10 +229,10 @@ mSkipSpaces ldaa 1,x+ ; Load next character into A
puld ; Restore D from the stack
exg D,X ; Exchange D and X
pshd ; Save D to the stack, cBadData usually has 2 D's on the stack
- cpy #2 ; Compare Y to 2
+ cpy #1 ; Compare Y to 1
blo cBadData ; No distances below 2 bytes
puld ; Restore D from the stack
- jsr MDCommand ; Jump to MDCommand
+ jsr LDCommand ; Jump to MDCommand
bra cNoPrint ; Done with command
cWrite ldaa 0,x ; Load next character but don't increment
cmpa #'$' ; Compare A to '$'
@@ -378,6 +407,79 @@ MDDone ldaa #CR ; Load CR into A
pulx ; Restore X from the stack
rts ; Return
+LDCommand
+ pshx ; Save X to the stack
+ pshy ; Save Y to the stack
+ pshd ; Save D to the stack
+ iny ; Add 1 to y for loop
+LDLoop dbeq y,LDDone ; Decrement y, y == 0, done
+ jsr GetCharLoop ; Read Character from serial
+ cmpa #CR ; Compare to CR
+ bne NotNewline ; If A != CR, not newline
+ jsr putchar ; Echo to serial
+ jsr GetCharLoop ; Read Character from serial
+ cmpa #LF ; Compare to LF
+ bne NotNewline ; If not LF, skip next read
+ jsr putchar ; Echo to serial
+ jsr GetCharLoop ; Read Character from serial
+NotNewline jsr putchar ; Echo to serial
+ jsr IsValidHex ; Check if valid hex
+ beq LDInvalid ; If Z == 1, invalid
+ tab ; Transfer A to B
+ jsr GetCharLoop ; Read Character from serial
+ cmpa #CR ; Compare to CR
+ bne NotNewline2 ; If A != CR, not newline
+ jsr putchar ; Echo to serial
+ jsr GetCharLoop ; Read Character from serial
+ cmpa #LF ; Compare to LF
+ bne NotNewline2 ; If not LF, skip next read
+ jsr putchar ; Echo to serial
+ jsr GetCharLoop ; Read Character from serial
+NotNewline2 jsr putchar ; Echo to serial
+ jsr IsValidHex ; Check if valid hex
+ beq LDInvalid ; If Z == 1, invalid
+ exg a,b ; Swap A and B
+ jsr ReadHexByte ; Read ASCII Hex into data
+ staa 1,x+ ; Store byte into memory
+ bra LDLoop ; Loop
+LDDone ldaa #CR ; Load CR into A
+ jsr putchar ; Print to serial
+ ldaa #LF ; Load LF into A
+ jsr putchar ; Print to serial
+ puld ; Restore D from the stack
+ puly ; Restore Y from the stack
+ pulx ; Restore X from the stack
+ rts ; Return
+LDInvalid ldaa #CR ; Load CR into A
+ jsr putchar ; Print to serial
+ ldaa #LF ; Load LF into A
+ jsr putchar ; Print to serial
+ ldx #badData ; Load the address of bad data string
+ jsr WriteString ; Write string to serial
+ puld ; Restore D from the stack
+ puly ; Restore Y from the stack
+ pulx ; Restore X from the stack
+ rts ; Return
+
+GetCharLoop
+ jsr getchar ; Read character from serial
+ beq GetCharLoop ; If 0, loop
+ rts ; Return
+
+IsValidHex
+ cmpa #'0' ; Compare A to '0'
+ blo InvalidHex ; A < '0', invalid
+ cmpa #'9' ; Compare A to '9'
+ bls ValidHex ; A <= '9', valid hex
+ cmpa #'A' ; Compare A to 'A'
+ blo InvalidHex ; A < 'A', invalid
+ cmpa #'F' ; Compare A to 'F'
+ bhi InvalidHex ; A > 'F', invalid
+ValidHex andcc #%11111011 ; Clear Zero Bit
+ rts ; Return
+InvalidHex orcc #%00000100 ; Set the Zero Bit
+ rts ; Return
+
;*************************************************************************
; ReadDecimal subroutine
;
@@ -577,6 +679,23 @@ PrintDone jsr putchar ; Print character to serial
puld ; Restore D from the stack
rts ; Return
+ReadHexByte
+ cmpa #'A' ; Compare A to 'A'
+ blo RHBNotHex ; If A < 'A', decimal number
+ suba #7 ; 'A' - '0' = 17, 'A' - '0' - 7 = 10 = $A
+RHBNotHex suba #'0' ; Remove offset
+ pshb ; Save B to the stack
+ ldab #16 ; 16 to shift digit to left
+ mul ; A * 16, left shift digit
+ tba ; Store result in A
+ pulb ; Restore B from stack
+ cmpb #'A' ; Compare B to 'A'
+ blo RHBNotHexB ; If B < 'A', decimal number
+ subb #7 ; 'A' - '0' = 17, 'A' - '0' - 7 = 10 = $A
+RHBNotHexB subb #'0' ; Remove offset
+ aba ; Add A to B
+ rts ; Return
+
;*************************************************************************
; PrintHexWord subroutine
;