diff options
| author | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2025-02-28 11:41:56 -0500 |
|---|---|---|
| committer | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2025-02-28 11:41:56 -0500 |
| commit | 58fbe5dfa0b0b3dab5262b36807b91605d9f961a (patch) | |
| tree | c19292df190c6850769fb43ef6114f30dd7c73ee /cmpen472hw6_McDonnell/Sources | |
| parent | 8f172c86f60da45f946a181e1292aceb52b9ac36 (diff) | |
HW6 Bug Fixes
Diffstat (limited to 'cmpen472hw6_McDonnell/Sources')
| -rw-r--r-- | cmpen472hw6_McDonnell/Sources/main.asm | 106 |
1 files changed, 88 insertions, 18 deletions
diff --git a/cmpen472hw6_McDonnell/Sources/main.asm b/cmpen472hw6_McDonnell/Sources/main.asm index 0b40a5a..e5656e9 100644 --- a/cmpen472hw6_McDonnell/Sources/main.asm +++ b/cmpen472hw6_McDonnell/Sources/main.asm @@ -77,23 +77,8 @@ buffer2 ds.b $0010 ; Array of 16 bytes for reading and reve dc.b NULL ; NULL terminated lenBuf2 dc.w $0010 ; length of buffer2 -badAddr dc.b 'invalid input, address',CR,LF,NULL ; Error message for bad address - -badData dc.b 'invalid input, data',CR,LF,NULL ; Error message for bad data - -badCom dc.b 'invalid input, command',CR,LF,NULL ; Error message for bad command - -; twMsg: welcome message when type writer loads -twMsg dc.b 'Welcome to Type Writer, you may type below.',CR,LF - dc.b 'Restart to enter main menu again.',CR,LF,NULL - - -; msg: this is the main option menu string -msg dc.b 'S: Show the contents of memory location in word',CR,LF - dc.b 'W: Write the data word (not byte) to memory location',CR,LF - dc.b 'QUIT: Quit the main program, run Type writer program.',CR,LF,NULL - * +* There is a section Data Section at the end of the file ************************************************************************** * Program Section: address used [ $3100 to $3FFF ] RAM Memory * @@ -108,7 +93,9 @@ pgstart lds #$3100 ; initialize the stack pointer ldd #$0001 ; Set SCI Baud Register = $0001 => 1.5M baud at 24MHz (for simulation) std SCIBDH ; SCI port baud rate change - + + ldx #msg ; Load the address of the welcome message into X + jsr WriteString ; Write the string to the serial console mainLoop ldx #buffer ; Load the address of the buffer into X @@ -420,7 +407,9 @@ revLoop ldaa 1,y- ; Load Character from Y into A, decremen beq revDone ; If Character is 0, exit loop staa 1,x+ ; Save character in address in X, increment X bra revLoop ; Loop back always -revDone pula ; Restore A from the stack + clra ; Set A to Zero +revDone staa 1,x+ ; Copy Null terminator into new string + pula ; Restore A from the stack puly ; Restore Y from the stack pulx ; Restore X from the stack rts ; Return to caller @@ -479,6 +468,20 @@ PrintHexWord pshx ; Save X to the stack pshd ; Save D (A:B) to the stack pshy ; Save Y to the stack + cpd #0 ; Compare D to zero + beq hIsZero ; Branch to hIsZero + psha ; Save A to the stack + pshy ; Save Y to the stack + pshx ; Save x to the stack + ldaa #'0' ; Load the '0' character into A + ldx #buffer2 ; Load the address of buffer2 into X + ldy #5 ; Load 5 into Y + jsr memset ; Write '0' to the first 5 bytes in buffer2 + pulx ; Restore X from the stack + puly ; Restore Y from the stack + clra ; Set A to zero + staa 0,y ; Load Zero into Y for Null Terminator + pula ; Restore A from the stack hPrintLoop ldx #16 ; Load 16 in X for division idiv ; Divide D / 16 to get Hex Digit cpx #0 ; Compare X to 0 @@ -508,6 +511,14 @@ hPrintDone ldaa #'$' ; Load '$' into puld ; Restore D (A:B) from the stack pulx ; Restore X from the stack rts ; Return to caller +hIsZero ldaa #'$' ; Load '$' character into A + jsr putchar ; Print character to the screen + ldaa #'0' ; Load '0' character into A + jsr putchar ; Print character to the screen + puly ; Restore Y from the stack + puld ; Restore D (A:B) from the stack + pulx ; Restore X from the stack + rts ; Return to caller ;************************************************************************* ; PrintDecimalWord subroutine @@ -527,6 +538,20 @@ PrintDecimalWord pshx ; Save X to the stack pshd ; Save D (A:B) to the stack pshy ; Save Y to the stack + cpd #0 ; Compare D to zero + beq dIsZero ; Branch to hIsZero + psha ; Save A to the stack + pshy ; Save Y to the stack + pshx ; Save x to the stack + ldaa #'0' ; Load the '0' character into A + ldx #buffer2 ; Load the address of buffer2 into X + ldy #5 ; Load 5 into Y + jsr memset ; Write '0' to the first 5 bytes in buffer2 + pulx ; Restore X from the stack + puly ; Restore Y from the stack + clra ; Set A to zero + staa 0,y ; Load Zero into Y for Null Terminator + pula ; Restore A from the stack dPrintLoop ldx #10 ; Load 10 in X for division idiv ; Divide D / 10 to get Hex Digit cpx #0 ; Compare X to 0 @@ -547,6 +572,12 @@ dPrintDone ldx #buffer2 ; Load the address of buffer2 in X puld ; Restore D (A:B) from the stack pulx ; Restore X from the stack rts ; Return to caller +dIsZero ldaa #'0' ; Load '0' character into A + jsr putchar ; Print character to the screen + puly ; Restore Y from the stack + puld ; Restore D (A:B) from the stack + pulx ; Restore X from the stack + rts ; Return to caller ;************************************************************************* ; Zeros subroutine @@ -570,6 +601,24 @@ zerosLoop staa 1,x+ ; Load A into byte at X rts ; Return to caller ;************************************************************************* +; memset subroutine +; +; This subroutine will write a given byte to every byte in a given array. +; +; Input: Address of an array in X and its length in Y, the byte in A +; Output: The given byte in every byte of an array. +; Registers in use: X for the address of the array, Y for the length, and A for the given byte +; Memory locations in use: Memory Address of the array +; +; Comments: This subroutine requires serial to be setup and putchar subroutine. +; + +memset + staa 1,x+ ; Load A into byte at X + dbne y,memset ; Decrement Y and loop if Y != 0 + rts ; Return to caller + +;************************************************************************* ; WriteString subroutine ; ; This subroutine will write a given null terminated string to the serial. @@ -657,4 +706,25 @@ getchar brclr SCISR1,#%00100000,getchar7 ; If no input on SCI port, r getchar7 clra ; Set A to 0 rts ; Return to caller +* +************************************************************************** +* Data Section 2: address used [ $3100 to $3FFF ] RAM Memory +* + +badAddr dc.b 'invalid input, address',CR,LF,NULL ; Error message for bad address + +badData dc.b 'invalid input, data',CR,LF,NULL ; Error message for bad data + +badCom dc.b 'invalid input, command',CR,LF,NULL ; Error message for bad command + +; twMsg: welcome message when type writer loads +twMsg dc.b 'Welcome to Type Writer, you may type below.',CR,LF + dc.b 'Restart to enter main menu again.',CR,LF,NULL + + +; msg: this is the main option menu string +msg dc.b 'S: Show the contents of memory location in word',CR,LF + dc.b 'W: Write the data word (not byte) to memory location',CR,LF + dc.b 'QUIT: Quit the main program, run Type writer program.',CR,LF,NULL + end ; last line of the file |
