summaryrefslogtreecommitdiff
path: root/cmpen472_hw8McDonnell/Sources/main.asm
diff options
context:
space:
mode:
Diffstat (limited to 'cmpen472_hw8McDonnell/Sources/main.asm')
-rw-r--r--cmpen472_hw8McDonnell/Sources/main.asm54
1 files changed, 43 insertions, 11 deletions
diff --git a/cmpen472_hw8McDonnell/Sources/main.asm b/cmpen472_hw8McDonnell/Sources/main.asm
index 1782ad1..cbfe22a 100644
--- a/cmpen472_hw8McDonnell/Sources/main.asm
+++ b/cmpen472_hw8McDonnell/Sources/main.asm
@@ -333,6 +333,21 @@ TimeOnPortB
puld ; Restore D from the stack
rts ; Return from caller
+;*************************************************************************
+; ExecuteCommand subroutine
+;
+; This subroutine will parse user input and execute the proper command or error out.
+;
+; Input: An address of a NULL terminated string in X.
+; Output: The output of the proper command or an error message.
+; Registers in use: X for the address of the user input, A for individual characters,
+; D & Y for numbers read from user input.
+; Memory locations in use: Serial console memory locations.
+;
+; Comments: This subroutine will disable interrupts while setting the time and will
+; reenable them after setting the time.
+;
+
ExecuteCommand
pshd ; Save D to the stack
pshy ; Save Y to the stack
@@ -344,37 +359,48 @@ skipSpaces ldaa 1,+x ; Load the next character into X
cmpa #' ' ; Compare A to ' ' character
beq skipSpaces ; If A == ' ', loop to skipSpaces
sei ; Disable interrupts
+ ldd hours ; Load hours into D
+ pshd ; Save hours to the stack
jsr ReadDecimal ; Read Hour number
exg y,d ; Exchange Y and D
cpd #24 ; Compare D to 24
- bhs badCommand ; If D >= 24, badCommand
+ lbhs badHours ; If D >= 24, badHours
cpd #0 ; Compare D to 0
- blt badCommand ; If D < 0, badCommand
+ lblt badHours ; If D < 0, badHours
std hours ; Save D to hours
ldaa -1,x ; Load the next character into A
cmpa #':' ; Compare A to ':'
- bne badCommand ; If A != ':', bad command
+ lbne badHours ; If A != ':', badHours
+ ldd minutes ; Load minutes into D
+ pshd ; Save minutes to the stack
jsr ReadDecimal ; Read minute number
exg y,d ; Exchange Y and D
cpd #60 ; Compare D to 60
- bhs badCommand ; If D >= 60, badCommand
+ bhs badMinutes ; If D >= 60, badMinutes
cpd #0 ; Compare D to 0
- blt badCommand ; If D < 0, badCommand
+ blt badMinutes ; If D < 0, badMinutes
std minutes ; Save D to minutes
ldaa -1,x ; Load the next character into A
cmpa #':' ; Compare A to ':'
- bne badCommand ; If A != ':', bad command
+ bne badMinutes ; If A != ':', badMinutes
+ ldd seconds ; Load seconds into D
+ pshd ; Save seconds to the stack
jsr ReadDecimal ; Read second number
exg y,d ; Exchange Y and D
cpd #60 ; Compare D to 60
- bhs badCommand ; If D >= 60, badCommand
+ bhs badSeconds ; If D >= 60, badSeconds
cpd #0 ; Compare D to 0
- blt badCommand ; If D < 0, badCommand
+ blt badSeconds ; If D < 0, badSeconds
std seconds ; Save D to seconds
ldaa -1,x ; Load the next character into A
cmpa #NULL ; Compare A to NULL
- bne badCommand ; If A != ':', bad command
+ bne badSeconds ; If A != ':', badSeconds
+ clra ; Set A to 0
+ staa counter ; Clear Counter
cli ; Enable interrupts
+ puld ; Restore D from the stack
+ puld ; Restore D from the stack
+ puld ; Restore D from the stack
bra ecDone ; Branch to ecDone
isH cmpa #'h' ; Compare A to 'h'
bne isM ; If A != 'h', branch to isM
@@ -403,8 +429,14 @@ isQ cmpa #'q' ; Compare A to 'q'
cmpb #NULL ; Compare B to NULL
bne badCommand ; If B != NULL, branch to ecDone
jmp TypeWrite ; Jump to TypeWrite
-badCommand cli ; Reenable interrupts
- pshx ; Save X to the stack
+badSeconds puld ; Restore Seconds from the stack
+ std seconds ; Restore seconds before change
+badMinutes puld ; Restore minutes from the stack
+ std minutes ; Restore minutes before change
+badHours puld ; Restore hours from the stack
+ std hours ; Restore hours before change
+ cli ; Reenable interrupts
+badCommand pshx ; Save X to the stack
ldaa #' ' ; Load Space character into A
jsr putchar ; Jump to putchar to write space character
jsr putchar ; Jump to putchar to write space character