diff options
Diffstat (limited to 'cmpen472hw10_McDonnell/bin/main.dbg')
| -rw-r--r-- | cmpen472hw10_McDonnell/bin/main.dbg | 380 |
1 files changed, 127 insertions, 253 deletions
diff --git a/cmpen472hw10_McDonnell/bin/main.dbg b/cmpen472hw10_McDonnell/bin/main.dbg index 58564c7..3934132 100644 --- a/cmpen472hw10_McDonnell/bin/main.dbg +++ b/cmpen472hw10_McDonnell/bin/main.dbg @@ -113,7 +113,7 @@ numPoints dc.w 2048 ; Max Number of points for waves timeTrigger dc.b $00 ; Tracks when timer is triggered -waveType dc.b 'q' ; Used to track wave type 'T' for increasing triangle, +waveType dc.b 'S' ; Used to track wave type 'T' for increasing triangle, ; 't' for decreasing triangle, ; 'Q' for square high ; 'q' for square low @@ -161,26 +161,20 @@ pgstart lds #$3100 ; initialize the stack pointer cli ; Enable interrupts mainLoop + ldaa #'>' ; Load '>' character + jsr putchar ; Print to serial console + ldaa #' ' ; Load ' ' character + jsr putchar ; Print to serial console ldx #inputBuffer ; Load the address of inputBuffer into X ldy lenInput ; Load the length of inputBuffer into Y jsr ReadString ; Jump to ReadString to read input - ldd #0 ; Clear D - std outputCnt ; Clear outputCnt - staa outputVal ; Clear outputVal - - jsr StartTimer5oc ; Start Timer on CH5 - -looooop ldaa timeTrigger - beq looooop - clra - staa timeTrigger - jsr PrintWave ; Jump to PrintWave - ldd outputCnt - cpd numPoints - blo looooop + ldx #inputBuffer ; Load the address of inputBuffer into X + jsr ExecuteCommand ; Jump to ExecuteCommand - jsr StopTimerCH5 + ldx #inputBuffer ; Load the address of inputBuffer into X + ldy lenInput ; Load the length of inputBuffer into Y + jsr Zeros ; Zero out input buffer bra mainLoop ; Loop back to mainLoop always @@ -395,6 +389,27 @@ StopTimerCH5 pula ; Restore A from the stack rts ; Return +GenWave + pshd ; Save D to the stack + ldd #0 ; Clear D + std outputCnt ; Clear outputCnt + staa outputVal ; Clear outputVal + + jsr StartTimer5oc ; Start Timer on CH5 + + +genLoop ldaa timeTrigger ; Load timeTrigger into A + beq genLoop ; If A == 0, loop + clra ; Clear A + staa timeTrigger ; Clear timeTrigger + jsr PrintWave ; Jump to PrintWave + ldd outputCnt ; Load outputCnt into D + cpd numPoints ; Compare D to numPoints + blo genLoop ; If D < numPoints, Loop + + jsr StopTimerCH5 ; Turn off timer + puld ; Restore D from the stack + rts ; Return ;************************************************************************* ; PrintTime subroutine @@ -431,28 +446,6 @@ skipRest jsr TimeOnPortB ; Call TimeOnPortB to output time rts ; Return to caller ;************************************************************************* -; PrintPrompt subroutine -; -; This subroutine will output the CMD prompt and any current input to the serial console -; -; Input: No Input -; Output: The CMD prompt and any input onto the serial console -; Registers in use: X for addresses of strings -; Memory locations in use: PORTB memory location, CMD prompt memory locaiton, inputBuffer location -; -; Comments: This subroutine requires WriteString subroutine. -; - -PrintPrompt - pshx ; Save X to the stack - ldx #CMD ; Load the address of CMD into X - jsr WriteString ; Write the string to the serial - ldx #inputBuffer ; Load the address of the inputBuffer into X - jsr WriteString ; Write the string to the serial - pulx ; Restore X from the stack - rts ; Return - -;************************************************************************* ; TimeOnPortB subroutine ; ; This subroutine will output the time given on on PORTB for two seven segment displays. @@ -527,64 +520,121 @@ skipSpaces ldaa 1,+x ; Load the next character into X jsr ReadDecimal ; Read minute number exg y,d ; Exchange Y and D cpd #60 ; Compare D to 60 - bhs badMinutes ; If D >= 60, badMinutes + lbhs badMinutes ; If D >= 60, badMinutes cpd #0 ; Compare D to 0 - blt badMinutes ; If D < 0, badMinutes + lblt 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 badMinutes ; If A != ':', badMinutes + lbne 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 badSeconds ; If D >= 60, badSeconds + lbhs badSeconds ; If D >= 60, badSeconds cpd #0 ; Compare D to 0 - blt badSeconds ; If D < 0, badSeconds + lblt 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 badSeconds ; If A != ':', badSeconds + lbne 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 + lbra ecDone ; Branch to ecDone isH cmpa #'h' ; Compare A to 'h' bne isM ; If A != 'h', branch to isM ldab 1,x+ ; Load next character into B cmpb #NULL ; Compare B to NULL - bne badCommand ; If B != CR, bad command + lbne badCommand ; If B != CR, bad command staa outputBuf ; Store A into outputBuf - bra ecDone ; Branch to ecDone + lbra ecDone ; Branch to ecDone isM cmpa #'m' ; Compare A to 'm' bne isS ; If A != 'm', branch to isS ldab 1,x+ ; Load next character into B cmpb #NULL ; Compare B to NULL - bne badCommand ; If B != CR, bad command + lbne badCommand ; If B != CR, bad command staa outputBuf ; Store A into outputBuf - bra ecDone ; Branch to ecDone + lbra ecDone ; Branch to ecDone isS cmpa #'s' ; Compare A to 's' bne isQ ; If A != 's', branch to isQ ldab 1,x+ ; Load next character into B cmpb #NULL ; Compare B to NULL - bne badCommand ; If B != CR, bad command + lbne badCommand ; If B != CR, bad command staa outputBuf ; Store A into outputBuf - bra ecDone ; Branch to ecDone + lbra ecDone ; Branch to ecDone isQ cmpa #'q' ; Compare A to 'q' - bne isEquation ; If A != 'q', branch to isEquation + bne isGw ; If A != 'q', branch to isGw ldab 1,x+ ; Load next character into B cmpb #NULL ; Compare B to NULL - bne badCommand ; If B != NULL, branch to ecDone + lbne badCommand ; If B != NULL, branch to ecDone jmp TypeWrite ; Jump to TypeWrite -isEquation dex ; Decrement X by 1 - jsr VerifyInput ; Verify input is valid equation - beq badCommand ; If Z == 1, badCommand - jsr Solve ; Jump to Solve to solve equation - bra ecDone ; Branch always to ecDone +isGw cmpa #'g' ; Compare A to 'g' + lbne badCommand ; If A != 'g', branch to badCommand + ldaa 1,x+ ; Load next character into B + cmpa #'w' ; Compare A to 'w' + bne isGt ; If A != 'w', branch to isGt + ldab 1,x+ ; Load next charater into B + cmpb #NULL ; Compare B to NULL + bne isGw2 ; If B != NULL, branch to isGw2 + ldx #swMsg ; Load address of sawtooth message + jsr WriteString ; Write string + ldaa #'S' ; Load 'S' for sawtooth + staa waveType ; Save A to waveType + jsr GenWave ; Jump to GenWave + ldx #doneWave ; Load the address of doneWave + jsr WriteString ; Write string + lbra ecDone ; Branch always to ecDone +isGw2 cmpb #'2' ; Compare B to '2' + lbne badCommand ; If B != '2', bad + ldab 1,x+ ; Load next character into B + cmpb #NULL ; Compare to NULL + lbne badCommand ; Not NULL? bad + ldx #sw2Msg ; Load address of sawtooth 125Hz message + jsr WriteString ; Write string + ldx #doneWave ; Load the address of doneWave + jsr WriteString ; Write string + lbra ecDone ; Branch always to ecDone +isGt cmpa #'t' ; Compare A to 't' + bne isGq ; If A != 't', branch to isGq + ldab 1,x+ ; Load next character into B + cmpb #NULL ; Compare to NULL + lbne badCommand ; A != NULL? bad + ldx #tMsg ; Load address of triangle message + jsr WriteString ; Write string + ldaa #'T' ; Load 'T' for triangle + staa waveType ; Save A to waveType + jsr GenWave ; Jump to GenWave + ldx #doneWave ; Load the address of doneWave + jsr WriteString ; Write string + lbra ecDone ; Branch always to ecDone +isGq cmpa #'q' ; Compare A to 'q' + lbne badCommand ; A != 'q'? bad + ldab 1,x+ ; Load next character into B + cmpb #NULL ; Compare B to NULL + bne isGq2 ; B != NULL? isGq2 + ldx #sqMsg ; Load address of square message + jsr WriteString ; Write string + ldaa #'q' ; Load 'q' for square + staa waveType ; Save A to waveType + jsr GenWave ; Jump to GenWave + ldx #doneWave ; Load the address of doneWave + jsr WriteString ; Write string + lbra ecDone ; Branch always to ecDone +isGq2 cmpb #'2' ; Compare B to '2' + lbne badCommand ; B != '2'? bad + ldab 1,x+ ; Load next character into B + cmpb #NULL ; Compare B to NULL + bne badCommand ; B != NULL? bad + ldx #sq2Msg ; Load address of square 125Hz message + jsr WriteString ; Write string + ldx #doneWave ; Load the address of doneWave + jsr WriteString ; Write string + lbra ecDone ; Branch always to ecDone badSeconds puld ; Restore Seconds from the stack std seconds ; Restore seconds before change badMinutes puld ; Restore minutes from the stack @@ -593,13 +643,6 @@ 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 - jsr putchar ; Jump to putchar to write space character - jsr putchar ; Jump to putchar to write space character - ldx #error ; Load the address of the error prompt into X - jsr WriteString ; Jump to WriteString ldx #badInput ; Load the address of badInput into X jsr WriteString ; Jump to WriteString pulx ; Restore X from the stack @@ -608,182 +651,6 @@ ecDone puly ; Restore Y from the stack rts ; Return to caller ;************************************************************************* -; Solve subroutine -; -; This subroutine will solve the math equation in the given string. -; -; Input: Address of null terminated string in X. -; Output: No Output, Control flow changed to proper subroutine. -; Registers in use: X for the address of the string, A & B to read characters from -; from the string. -; Memory locations in use: Memory Address for serial line, address of the string, numBuf word -; -; Comments: This subroutine EXPECTS the input to be valid. RUN VerifyInput BEFORE -; TO MAKE SURE THE STRING IS VALID, OTHERWISE THERE WILL BE ERRORS. -; - -Solve - pshy ; Save Y to the stack - pshd ; Save D to the stack - pshx ; Save X to the stack - jsr ReadDecimal ; Read First number - pshy ; Save Y to the stack - ldaa -1,x ; Read operator from X and save to A - jsr ReadDecimal ; Read First number - cmpa #'+' ; Compare A to '+' - beq sAdd ; Jump to sAdd to add the numbers - cmpa #'-' ; Compare A to '-' - beq sSub ; Jump to sSub to add the numbers - cmpa #'*' ; Compare A to '*' - beq sMul ; Jump to sMul to add the numbers - exg y,x ; Exchange X and Y - puly ; Restore Y from the stack - exg y,d ; Exchange Y and D - idiv ; Divide D/X => X - exg x,d ; Exchange X & D - bra sDone ; Jump to sDone -sAdd sty numBuf ; Save Y to numBuf - puly ; Restore Y from the stack - exg y,d ; Exchange Y and D - addd numBuf ; Add D and numBuf - bra sDone ; Jump to sDone -sSub sty numBuf ; Save Y to numBuf - puly ; Restore Y from the stack - exg y,d ; Exchange Y and D - subd numBuf ; Subtract D and numBuf - bra sDone ; Jump to sDone -sMul exg y,d ; Exchange Y and D - puly ; Restore Y from the stack - emul ; Multiply Y*D => Y:D - cpy #0 ; Compare Y to 0 - bne sOverflow ; If Y != 0, Overflow -sDone cpd #9999 ; Compare D to 9999 (Max output) - bgt sOverflow ; Branch to sOverflow if D > 9999 - cpd #-9999 ; Compare D to -9999 (Min output) - blt sOverflow ; Branch to sOverflow if D < -9999 - sei ; Disable Interrupts - jsr PrintTime ; Print Time to serial - psha ; Save A to the stack - ldaa #' ' ; Load the space character into A - jsr putchar ; Print the space character to the serial console - jsr putchar ; Print the space character to the serial console - jsr putchar ; Print the space character to the serial console - jsr putchar ; Print the space character to the serial console - pula ; Restore A from the stack - pulx ; Restore X from the stack - pshx ; Save X to the stack - jsr WriteString ; Write original equation to serial console - pulx ; Restore X from the stack - ldy lenInput ; Load the length of the input buffer into Y - jsr Zeros ; Clear input buffer - psha ; Save A to the stack - ldaa #'=' ; Load '=' into A - jsr putchar ; Print '=' to serial console - pula ; Restore A from the stack - ldy #buffer ; Load address of buffer into Y - jsr PrintDecimalWord; Print the answer to the Serial console - clra ; Clear A - staa operator ; Clear operator - jsr PrintTime ; Print the time to the serial console - ldx #spacer ; Load the address of spacer into X - jsr WriteString ; Write the spacer string to the output - jsr PrintPrompt ; Write CMD prompt to serial - cli ; Enable Interrupts - puld ; Restore D from the stack - puly ; Restore Y from the stack - rts ; Return to caller -sOverflow ldaa #' ' ; Load a space character into A - jsr putchar ; Jump to putchar to write space character - jsr putchar ; Jump to putchar to write space character - jsr putchar ; Jump to putchar to write space character - jsr putchar ; Jump to putchar to write space character - ldx #error ; Load the address of the error prompt into X - jsr WriteString ; Write original string to serial console - ldaa #' ' ; Load a space character into A - jsr putchar ; Jump to putchar to write space character - ldx #overflow ; Load address of overflow string into X - jsr WriteString ; Write overflow string to serial - pulx ; Restore X from the stack - puld ; Restore D from the stack - puly ; Restore Y from the stack - rts ; Return to caller - -;************************************************************************* -; VerifyInput subroutine -; -; This subroutine will verify the user input is valid. -; -; Input: An address of a Null terminated string in register X. -; Output: If valid Zero bit = 0 in CCR, if invalid, Zero bit = 1 -; and the string is outputed up to the error on the serial -; console with an error message. -; Registers in use: X for the address of the string, A for reading characters. -; Y to count the number of digits in a number, & B to count the number of numbers -; Memory locations in use: Memory Address for serial line, address of the string, 1 byte for operator -; -; Comments: This subroutine will modify the user string if invalid. -; - -VerifyInput - pshy ; Save Y to the stack - pshd ; Save D to the stack - pshx ; Save X to the stack - clrb ; Set B to Zero - stab operator ; Clear operator - ldy #0 ; Load Zero into Y -vNumLoop ldaa 1,x+ ; Load character from X into A - cmpa #'9' ; Compare A to '9' - bhi vInvalid ; If A > '9', not valid string - cmpa #'0' ; Compare A to '0' - blt vIsOp ; If A < '0', check if operator - iny ; Increment Y by 1 to count numbers - cpy #4 ; Compare Y to 4 - bhi vInvalid ; If greater than 4, invalid - bra vNumLoop ; Loop back to check for more digits -vIsOp cmpa #'+' ; Compare A to '+' - beq vOp ; This is an operator - cmpa #'-' ; Compare A to '-' - beq vOp ; This is an operator - cmpa #'*' ; Compare A to '*' - beq vOp ; This is an operator - cmpa #'/' ; Compare A to '/' - beq vOp ; This is an operator - cmpa #NULL ; Compare A to NULL character - beq vEndOfLine ; Check if end of line -vInvalid clra ; Set A to zero - staa 0,X ; Write Null terminator to X - ldaa #4 ; Load 4 into A to set zero bit - tap ; Transfer A to CCR - pulx ; Restore X from the stack - puld ; Restore D from the stack - puly ; Restore Y from the stack - rts ; Return to caller -vOp staa operator ; Store operator in operator buffer - ldaa -2,x ; Load previous character into A - cmpa #'0' ; Compare A to '0' - blt vInvalid ; Invalid string since previous is not number - cmpa #'9' ; Compare A to '9' - bhi vInvalid ; Invalid string since previous is not number - addb #1 ; Increment B by 1 - cmpb #1 ; Compare B to 1 - bhi vInvalid ; Invalid string since B > 1 and we have another operator - ldy #0 ; Set Y to 0 - bra vNumLoop ; Check for next number -vEndOfLine ldaa -2,x ; Load previous character into A - cmpa #'0' ; Compare A to '0' - blt vInvalid ; Invalid string since previous is not number - cmpa #'9' ; Compare A to '9' - bhi vInvalid ; Invalid string since previous is not number - ldaa operator ; Load operator character from buffer - beq vInvalid ; If operator buffer is zero, invalid - clra ; Set A to zero - tap ; Transfer A to CCR - pulx ; Restore X from the stack - puld ; Restore D from the stack - puly ; Restore Y from the stack - rts ; Return to caller - -;************************************************************************* ; ReadDecimal subroutine ; ; This subroutine will read an ASCII string of a number in decimal and convert it to @@ -1031,7 +898,11 @@ readLoop jsr getchar ; Jump to putchar to write byte to seria dey ; Decrement Y by 1 beq doneRead ; If Y == 0, no more room, stop reading bra readLoop ; branch always to readLoop -doneRead pulx ; Restore X from the stack +doneRead ldaa #CR ; Load CR into A + jsr putchar ; Print to serial + ldaa #LF ; Load LF into A + jsr putchar ; Print to serial + pulx ; Restore X from the stack pulY ; Restore Y from the stack pula ; restore A from the stack rts ; return to caller @@ -1073,25 +944,28 @@ getchar7 clra ; Set A to 0 * Data Section 2: address used [ $3100 to $3FFF ] RAM Memory * -clock dc.b 'Tcalc> ',NULL ; Prompt string for clock - -CMD dc.b 'CMD> ',NULL ; Prompt string for CMD - -error dc.b 'Error> ',NULL ; Prompt string for errors - -badInput dc.b 'Invalid Input',NULL ; Invalid Input Prompt - -overflow dc.b 'Overflow Error',NULL ; Overflow error message +badInput dc.b 'Invalid Input',CR,LF,NULL ; Invalid Input Prompt ; twMsg: welcome message for typewrite twMsg dc.b CR,LF,'Clock stopped and Typewrite program started.',CR,LF dc.b 'You may type below.',CR,LF,NULL -; spacer: the white space between time and cmd prompt -spacer dc.b ' ',NULL +; Messages for different waveforms +swMsg dc.b 'sawtooth wave generation...',CR,LF,NULL +sw2Msg dc.b 'sawtooth wave 125Hz generation...',CR,LF,NULL +tMsg dc.b 'triangle wave generation...',CR,LF,NULL +sqMsg dc.b 'square wave generation...',CR,LF,NULL +sq2Msg dc.b 'square wave 125Hz generation...',CR,LF,NULL + +doneWave dc.b 'Done generating wave.',CR,LF,NULL ; msg: this is the main option menu string msg dc.b 'Commands:',CR,LF + dc.b 'gw: generate sawtooth wave, printing 0 through 255, repeated for total 2048 points',CR,LF + dc.b 'gw2: generate sawtooth wave of 125Hz, wave repeated for total 2048 points',CR,LF + dc.b 'gt: generate triangle wave, printing 0 through 255, then 255 down to 0, repeated for total 2048 points',CR,LF + dc.b 'gq: generate square wave, printing 0 for 255 times, then print 255 for 255 times, then repeated for total 2048 points',CR,LF + dc.b 'gq2: generate square wave of 125Hz, wave repeated for total 2048 points',CR,LF dc.b 't: Set the time in format HH:MM:SS',CR,LF dc.b 'h: Display the hours on the 7 segment displays',CR,LF dc.b 'm: Display the minutes on the 7 segment displays',CR,LF |
