From 58fbe5dfa0b0b3dab5262b36807b91605d9f961a Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Fri, 28 Feb 2025 11:41:56 -0500 Subject: HW6 Bug Fixes --- cmpen472hw6_McDonnell/ASM_layout.hwl | 8 +- cmpen472hw6_McDonnell/Sources/main.asm | 106 +++++++-- cmpen472hw6_McDonnell/bin/Project.abs | Bin 7674 -> 7350 bytes cmpen472hw6_McDonnell/bin/Project.abs.s19 | 74 +++---- cmpen472hw6_McDonnell/bin/main.dbg | 242 ++++++++++++--------- cmpen472hw6_McDonnell/cmpen472hw6_McDonnell.mcp | Bin 57065 -> 57065 bytes .../Standard/ObjectCode/main.asm.o | Bin 7674 -> 7350 bytes .../Standard/ObjectCode/main.asm.sx | 74 +++---- .../Standard/TargetDataWindows.tdt | Bin 64813 -> 64868 bytes 9 files changed, 311 insertions(+), 193 deletions(-) diff --git a/cmpen472hw6_McDonnell/ASM_layout.hwl b/cmpen472hw6_McDonnell/ASM_layout.hwl index 89689db..fced6df 100644 --- a/cmpen472hw6_McDonnell/ASM_layout.hwl +++ b/cmpen472hw6_McDonnell/ASM_layout.hwl @@ -15,7 +15,13 @@ Command < attributes CACHESIZE 1000 OPEN Terminal 61 47 33 48 Terminal < attributes CACHESIZE 1000 Terminal < attributes SCI_DEFAULT_TEXT "Virtual SCI",SCI_CONNECTION 0,1,SCI_CONNECTION 1,0,SCI_CONNECTION 1,3,SCI_CONNECTION 3,1,SCI_PORT COM1,SCI_BAUD 9600,SCI_SHOW_PROTOCOL OFF,SCI_VIRTUAL_IN "Sci:2.SerialOutput",SCI_VIRTUAL_OUT "Sci:2.SerialInput",SCI_FILENAME_IN "",SCI_FILENAME_OUT "" +OPEN Visualizationtool 80 14 10 30 +VisualizationTool< Attributes [stEditM="0",swRefresh="3",refCycles="1"] +VisualizationTool< LoadInstrument Seg7[BoundX="54",BoundY="24",Port="0x1",Port_PortEndian="1",swDM="2"] +VisualizationTool< LoadInstrument Seg7[BoundX="95",BoundY="25",Port="0x1",swDM="1"] +VisualizationTool< LoadInstrument DILSwitch[BoundX="55",BoundY="117",Port="0x1"] +VisualizationTool< ResetVT Undo bckcolor 50331647 font 'Courier New' 9 BLACK AUTOSIZE on -ACTIVATE "Assembly" "Memory" "Register" "Command" "Data" "Source" "Procedure" "Terminal" +ACTIVATE "Assembly" "Memory" "Register" "Command" "Data" "Source" "Procedure" "Terminal" "VisualizationTool" 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 @@ -569,6 +600,24 @@ zerosLoop staa 1,x+ ; Load A into byte at X pula ; Restore A from the stack 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 ; @@ -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 diff --git a/cmpen472hw6_McDonnell/bin/Project.abs b/cmpen472hw6_McDonnell/bin/Project.abs index 7b911f3..83bccdd 100644 Binary files a/cmpen472hw6_McDonnell/bin/Project.abs and b/cmpen472hw6_McDonnell/bin/Project.abs differ diff --git a/cmpen472hw6_McDonnell/bin/Project.abs.s19 b/cmpen472hw6_McDonnell/bin/Project.abs.s19 index 01ad9e1..ea16b3d 100644 --- a/cmpen472hw6_McDonnell/bin/Project.abs.s19 +++ b/cmpen472hw6_McDonnell/bin/Project.abs.s19 @@ -1,40 +1,38 @@ S0580000433A5C55736572735C4A61636F62204D63446F6E6E656C6C5C446F63756D656E74735C434D50454E2D3437322D48575C636D70656E3437326877365F4D63446F6E6E656C6C5C62696E5C50726F6A6563742E6162734A -S1233000003605000000000000000000000000000000000000100000000000000000000061 -S1233020000000000000000010696E76616C696420696E7075742C20616464726573730D06 -S12330400A00696E76616C696420696E7075742C20646174610D0A00696E76616C69642027 -S1143060696E7075742C20636F6D6D616E640D0A00E9 -S1233100CF310086F15A03860C5ACBCC00015CC8CE3003FD3014163352863E163386862019 -S1233120163386CE3003FD3014163367CE300316314620DCCE33AF16335B16338D27FB16DE -S123314033865A0120F4343BA630815727258151276F81532662A6008124265C1631DA2701 -S123316044B7E534CE3003FD301416335230163252202FA6008124263F1631DA2727B7E487 -S12331803BA6302729812027F88124270809163225271B2006091631DA27133AB7C56D00D1 -S12331A020003A303DCE302916335B3A303DCE304216335B3A3A303DCE305816335B3A30A9 -S12331C03DA630815526F1A630814926EBA630815426E5A63026E10631343BCD0000E6301E -S12331E0C124263BE6302732C120272EC1302D2FC139220EC03037CC001013B7C63319ED9D -S123320020E2C1412D19C1462215C041CB0A37CC001013B7C63319ED20CA87B7023A3D8649 -S123322004B7023A3D3BCD0000E630271AC1202716C1302D17C1392213C03037CC000A1365 -S1233240B7C63319ED20E287B7023A3D8604B7023A3D353BB7D4CD30031632E0B7C5863DDF -S1233260163386863E163386EC00CE3003FD30141633521632BB3686201633861633863270 -S1233280CD30031632E036862016338616338632CE3003FD3014163352CD30031633228688 -S12332A00D163386860A1633863A313D343536A67F27046A3020F83231303D343B37180EEA -S12332C08625163386CE001055B72084018B301633860405088E000826EE3320EB3A303DB7 -S12332E0343B35CE001018108E00002716C10A2D0ACB41C00A6B60B7D420E8CB306B60B7A2 -S1233300D420E08C000026E586246A60CE30161632AC16335BFD3027CE3016163352313AB0 -S1233320303D343B35CE000A18108E00002708CB306B60B7D420EE8C000026F3CE3016168D -S123334032AC16335BFD3027CE3016163352313A303D36876A300436FB323D36A6302705D9 -S123336016338620F7323D36353416338D27FB810D270A6A3016338603270220ED860A1656 -S123338033863031323D4FCC80FC5ACF3D4FCC200396CF3D873D4572726F723A20556E6B6D -S12333A06E6F776E20436F6D6D616E640D0A0057656C636F6D6520746F2054797065205749 -S12333C072697465722C20796F75206D617920747970652062656C6F772E0D0A52657374B5 -S12333E061727420746F20656E746572206D61696E206D656E7520616761696E2E0D0A0042 -S12334004C313A205475726E206F6E204C4544310D0A46313A205475726E206F6666204CAD -S12334204544310D0A4C323A205475726E206F6E204C4544320D0A46323A205475726E2060 -S12334406F6666204C4544320D0A4C333A205475726E206F6E204C4544330D0A46333A205E -S12334605475726E206F6666204C4544330D0A4C343A204C45443420676F65732066726FED -S12334806D203025206C69676874206C6576656C20746F2031303025206C69676874206C39 -S12334A06576656C20696E20302E34207365636F6E64730D0A46343A204C45443420676FBA -S12334C065732066726F6D2031303025206C69676874206C6576656C20746F203025206CF2 -S12334E069676874206C6576656C20696E20302E34207365636F6E64730D0A515549543A98 -S12335002051756974206D656E752070726F6772616D2C2072756E20547970652077726922 -S11235207465722070726F6772616D2E0D0A00F0 +S1233000000500000000000000000000000000000000000010000000000000000000000097 +S10B3020000000000000001094 +S1233100CF310086F15A03860C5ACBCC00015CC8CE34851633B1CE3002FD30131633A286FD +S12331203E1633DC86201633DCCE3002FD30131633BDCE300216314C20DCCE34341633B158 +S12331401633E327FB1633DC5A0120F4343BA630815727228151276D81532660A600812418 +S1233160265A1631DE2742B7E534CE3002FD30131633A230202DA600812426401631DE27C8 +S123318028B7E43BA630272A812027F88124270809163229271C2006091631DE27143AB735 +S12331A0C56D001632563A303DCE33EC1633B13A303DCE34051633B13A3A303DCE341B16F1 +S12331C033B13A303DA630815526F1A630814926EBA630815426E5A63026E106313A3BCDE0 +S12331E00000E630C124263BE6302732C120272EC1302D2FC139220EC03037CC001013B786 +S1233200C63319ED20E2C1412D19C1462215C041CB0A37CC001013B7C63319ED20CA87B749 +S1233220023A3D8604B7023A3D3BCD0000E630271AC1202716C1302D17C1392213C030374F +S1233240CC000A13B7C63319ED20E287B7023A3D8604B7023A3D353BB7D4CD30021632E72F +S1233260B7C5863D1633DC863E1633DCEC00CE3002FD30131633A21632C23686201633DCDB +S12332801633DC32CD30021632E73686201633DC1633DC32CE3002FD30131633A2CD300223 +S12332A0163350860D1633DC860A1633DC3A313D343536A67F27056A3020F8876A30323136 +S12332C0303D343B37180E86251633DCCE001055B72084018B301633DC0405088E000826A5 +S12332E0EE3320EB3A303D343B358C000027533635348630CE3015CD00051633AB30318737 +S12333006A4032CE001018108E00002716C10A2D0ACB41C00A6B60B7D420E8CB306B60B749 +S1233320D420E08C000026E586246A60CE30151632B01633B1FD3026CE30151633A2313AE9 +S1233340303D86241633DC86301633DC313A303D343B358C000027413635348630CE30157A +S1233360CD00051633AB3031876A4032CE000A18108E00002708CB306B60B7D420EE8C0017 +S12333800026F3CE30151632B01633B1FD3026CE30151633A2313A303D86301633DC313A9C +S12333A0303D36876A300436FB323D6A300436FB3D36A63027051633DC20F7323D36353413 +S12333C01633E327FB810D270A6A301633DC03270220ED860A1633DC3031323D4FCC80FCC8 +S12333E05ACF3D4FCC200396CF3D873D696E76616C696420696E7075742C2061646472653C +S123340073730D0A00696E76616C696420696E7075742C20646174610D0A00696E76616C5D +S1233420696420696E7075742C20636F6D6D616E640D0A0057656C636F6D6520746F2054E6 +S1233440797065205772697465722C20796F75206D617920747970652062656C6F772E0D17 +S12334600A5265737461727420746F20656E746572206D61696E206D656E752061676169CC +S12334806E2E0D0A00533A20202020202053686F772074686520636F6E74656E7473206F09 +S12334A066206D656D6F7279206C6F636174696F6E20696E20776F72640D0A573A20202095 +S12334C0202020577269746520746865206461746120776F726420286E6F74206279746519 +S12334E02920746F206D656D6F7279206C6F636174696F6E0D0A515549543A2020205175B0 +S1233500697420746865206D61696E2070726F6772616D2C2072756E205479706520777220 +S1133520697465722070726F6772616D2E0D0A0086 S9030000FC diff --git a/cmpen472hw6_McDonnell/bin/main.dbg b/cmpen472hw6_McDonnell/bin/main.dbg index 34c58c5..066f6eb 100644 --- a/cmpen472hw6_McDonnell/bin/main.dbg +++ b/cmpen472hw6_McDonnell/bin/main.dbg @@ -1,42 +1,38 @@ ************************************************************************** * -* Title: Hardware Controller +* Title: Memory Monitor * -* Objective: CMPEN 472 Homework 5 +* Objective: CMPEN 472 Homework 6 * * Revision: V1.0 * -* Date: Feb. 21, 2025 +* Date: Mar. 1, 2025 * * Programmer: Jacob McDonnell * * Company: The Pennsylvania State University * Department of Computer Science and Engineering * -* Algorithm: Simple Serial I/O, Parallel I/O use, time delay-loop, and PWM control +* Algorithm: Simple Serial I/O, address poking and modifying * -* Register Use: A & B to control LEDS initially, Light Level, current byte, etc -* X & Y to hold the counter in the loop and address of strings and length of string. +* Register Use: A & B to current byte, etc, +* X & Y holds address of strings and length of string, +* D to hold data and address of the memory location to work on. * * Memory Use: RAM Locations from $3000 for data, * RAM Locations from $3100 for program * -* Input: Parameters hard-coded in the program - PORTB -* Serial Port for User Input +* Input: Serial Port for User Input * -* Output: LED 1 at PORTB bit 4 -* LED 2 at PORTB bit 5 -* LED 3 at PORTB bit 6 -* LED 4 at PORTB bit 7 -* Serial Port for String Output +* Output: Serial Port for String Output +* Memory locations changed if modified by user * -* Observation: This program will respond to user input to turn on and off LEDs 1, 2, & 3, -* Dim LED 4 from 100% to 0%, Dim LED 4 from 0% to 100%, and echo user input -* back to the terminal in Type Writer Mode. +* Observation: This program will prompt the user to print the contents of a +* memory location and to modify the location with hexadecimal or +* decimal data. If the user wishes, they can type 'QUIT' to exit +* the memory monitor and enter the type writer program. * * Note: ON CSM-12C128 board, -* Switch 1 is at PORTB bit 0, and -* LED 4 is at PORTB bit 7. * * Comments: This program is developed and simulated using CodeWarrior * development software and targeted for Axion @@ -70,12 +66,8 @@ NULL equ $00 ; NULL Terminator character * org $3000 ; Reserved RAM memory starting address ; for Data for CMPEN 472 class -Counter dc.w $0036 ; X register count number for time Delay - ; loop for 10 useconds - ; The work to calculate this number is in - ; the comments for the delay10usec subroutine. - -LEVEL dc.b $0005 ; Light Level that the LED should be +TESTER dc.w $0005 ; Memory location to test showing data + ; and writing data. buffer ds.b $0010 ; Array of 16 bytes to read a string dc.b NULL ; NULL terminated @@ -85,14 +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 - -* There is a second Data Section at the end of the file. * +* There is a section Data Section at the end of the file ************************************************************************** * Program Section: address used [ $3100 to $3FFF ] RAM Memory * @@ -107,24 +93,26 @@ 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 - ldy lenBuf - jsr Zeros + ldx #buffer ; Load the address of the buffer into X + ldy lenBuf ; Load the length of the buffer into Y + jsr Zeros ; Fill the buffer with zeros ldaa #'>' ; Load '>' into A jsr putchar ; Jump to putchar to write to console ldaa #' ' ; Load space character into A jsr putchar ; Jump to putchar to write to console - - ldx #buffer - ldy lenBuf - jsr ReadString - - ldx #buffer - jsr CheckInput + + ldx #buffer ; Load the address of the buffer into X + ldy lenBuf ; Load the length of the buffer into Y + jsr ReadString ; Read a line from the serial console + + ldx #buffer ; Load the address of the buffer into X + jsr CheckInput ; Jump to CheckInput to parse the user input bra mainLoop ; Loop back to mainLoop always TypeWriter ldx #twMsg ; Load Type Writer welcome message address jsr WriteString ; Jump to WriteString to write message to serial @@ -168,20 +156,19 @@ CheckInput cmpa #'$' ; Compare A to '$' bne cUnknownCMD ; If A != '$', branch to unknown command jsr ReadHex ; ReadHex to Read the memory Address - beq cBadAddr ; If Z == 1, branch to cBadAddr + beq cBadAddr ; If Z == 1, branch to cBadAddr exg Y,X ; Exchange Y for X pshx ; Save X to the stack ldx #buffer ; Load address of buffer into X ldy lenBuf ; Loadd length of the buffer into Y jsr Zeros ; Fill buffer with Zeros pulx ; Restore X from the stack - jsr PrintMem ; Print the data at the memory address bra cDone ; branch always to cDone cWrite ldaa 0,x ; Load next character but don't increment cmpa #'$' ; Compare A to '$' bne cUnknownCMD ; If A != '$', branch to unknown command jsr ReadHex ; ReadHex to Read the memory Address - beq cBadAddr ; If Z == 1, branch to cBadAddr + beq cBadAddr ; If Z == 1, branch to cBadAddr exg Y,D ; Exchange Y and D pshd ; Save D to the stack skipSpaces ldaa 1,x+ ; Load next character into A @@ -192,25 +179,25 @@ skipSpaces ldaa 1,x+ ; Load next character into A beq cHexData ; If A == '$', branch to cHexData dex ; Decrement X by 1 jsr ReadDecimal ; Jump to ReadDecimal - beq cBadData ; If Z == 1, branch to cBadData + beq cBadData ; If Z == 1, branch to cBadData bra cWriteData ; Branch always to cWriteData cHexData dex ; Decrement X by 1 jsr ReadHex ; Jump to ReadHex to read hex data - beq cBadData ; If Z == 1, branch to cBadData + beq cBadData ; If Z == 1, branch to cBadData cWriteData puld ; Restore D from the stack exg D,X ; Exchange D and X sty x ; Write data in Y to memory in X - bra cDone ; Branch always to cDone -cDone puld ; Restore D from the stack +cDone jsr PrintMem ; Jump to PrintMem to print the contents of the location + puld ; Restore D from the stack pulx ; Restore X from the stack rts ; Return to caller cBadAddr ldx #badAddr ; Load the address of badAddr into X - jsr WriteString ; Write badAddr to seriel console + jsr WriteString ; Write badAddr to serial console puld ; Restore D from the stack pulx ; Restore X from the stack rts ; Return to caller cBadData ldx #badData ; Load the address of badData into X - jsr WriteString ; Write badData to seriel console + jsr WriteString ; Write badData to serial console puld ; Restore D from the stack puld ; Restore D from the stack pulx ; Restore X from the stack @@ -232,7 +219,7 @@ cTypeWrite ldaa 1,x+ ; Load next character from X ldaa 1,x+ ; Load next character from X bne cUnknownCMD ; If A != 0, branch to unknown command jmp TypeWriter ; Jump to TypeWriter - + ;************************************************************************* ; ReadHex subroutine ; @@ -241,7 +228,7 @@ cTypeWrite ldaa 1,x+ ; Load next character from X ; ; Input: A memory address in register X. ; Output: The value of the hex number in the Y register, and any errors printed -; to the seriel line. Zero bit is set if error occurs. +; to the serial line. Zero bit is set if error occurs. ; Registers in use: X for the address of the contents and for a buffer while printing, ; D for multiplication, B for the character, Y for output value. ; Memory locations in use: Memory Address for serial line, address of the string @@ -249,7 +236,7 @@ cTypeWrite ldaa 1,x+ ; Load next character from X ; Comments: This subroutine will return the value in the Y register, and if an error occurs, ; the Zero bit in the CCR will be set. ; - + ReadHex pshd ; Save D to the stack ldy #0 ; Clear Y register @@ -293,7 +280,7 @@ rHError ldaa #4 ; Load 4 into A to set zero bit in CCR tap ; Transfer A into CCR to set zero bit and warn error puld ; Restore D from the stack rts ; Return to caller - + ;************************************************************************* ; ReadDecimal subroutine ; @@ -302,7 +289,7 @@ rHError ldaa #4 ; Load 4 into A to set zero bit in CCR ; ; Input: A memory address in register X. ; Output: The value of the number in the Y register, and any errors printed -; to the seriel line. Zero bit is set if error occurs. +; to the serial line. Zero bit is set if error occurs. ; Registers in use: X for the address of the contents and for a buffer while printing, ; D for multiplication, B for the character, Y for output value. ; Memory locations in use: Memory Address for serial line, address of the string @@ -310,7 +297,7 @@ rHError ldaa #4 ; Load 4 into A to set zero bit in CCR ; Comments: This subroutine will return the value in the Y register, and if an error occurs, ; the Zero bit in the CCR will be set. ; - + ReadDecimal pshd ; Save D to the stack ldy #0 ; Clear Y register @@ -338,7 +325,7 @@ dHError ldaa #4 ; Load 4 into A to set zero bit in CCR tap ; Transfer A into CCR to set zero bit and warn error puld ; Restore D from the stack rts ; Return to caller - + ;************************************************************************* ; PrintMem subroutine ; @@ -346,15 +333,15 @@ dHError ldaa #4 ; Load 4 into A to set zero bit in CCR ; ; Input: A memory address in register X. ; Output: The memory address in Hex and the contents in binary, hex, & decimal -; on the seriel output. +; on the serial output. ; Registers in use: X for the address of the contents and for a buffer while printing, ; D for the contents of the location, Y for another buffer address while ; reversing strings and printing. ; Memory locations in use: Memory Address for serial line, address of the string ; -; Comments: This subroutine requires the seriel console to be setup before calling. +; Comments: This subroutine requires the serial console to be setup before calling. ; - + PrintMem pshy ; Save Y to the Stack pshd ; Save D to the Stack @@ -363,39 +350,39 @@ PrintMem jsr PrintHexWord ; Print the Address in Hex exg d,x ; Copy Address from D to X ldaa #'=' ; Load the '=' character into A - jsr putchar ; Print the character to the seriel + jsr putchar ; Print the character to the serial ldaa #'>' ; Load the '>' character into A - jsr putchar ; Print the character to the seriel + jsr putchar ; Print the character to the serial ldd x ; Load data from address in X into D ldx #buffer ; Load the address of the buffer into X ldy lenBuf ; Load the length of the buffer into Y jsr Zeros ; Fill the buffer with Zeros - jsr PrintBinaryWord ; Print the binary word to the seriel + jsr PrintBinaryWord ; Print the binary word to the serial psha ; Save A to the stack ldaa #' ' ; Load Space character into A - jsr putchar ; Print Space character to the seriel - jsr putchar ; Print Space character to the seriel + jsr putchar ; Print Space character to the serial + jsr putchar ; Print Space character to the serial pula ; Restore A from the stack ldy #buffer ; Load the address of the buffer into Y - jsr PrintHexWord ; Prin the hex representation of the word to seriel + jsr PrintHexWord ; Prin the hex representation of the word to serial psha ; Save A to the stack ldaa #' ' ; Load Space character into A - jsr putchar ; Print Space character to the seriel - jsr putchar ; Print Space character to the seriel + jsr putchar ; Print Space character to the serial + jsr putchar ; Print Space character to the serial pula ; Restore A from the stack ldx #buffer ; Load the address of the buffer into X ldy lenBuf ; Load the length of the buffer into Y jsr Zeros ; Fill the buffer with Zeros ldy #buffer ; Load the address of the buffer into Y - jsr PrintDecimalWord; Prin the decimal representation of the word to seriel + jsr PrintDecimalWord; Prin the decimal representation of the word to serial ldaa #CR ; Load the carriage return character into A - jsr putchar ; Print the character to seriel + jsr putchar ; Print the character to serial ldaa #LF ; Load the line feed character into A - jsr putchar ; Print the character to seriel + jsr putchar ; Print the character to serial puld ; Restore D from the stack puly ; Restore Y from the stack rts ; Return to caller - + ;************************************************************************* ; strrev subroutine ; @@ -411,7 +398,7 @@ PrintMem ; Comments: This subroutine will not check that the output buffer is large enough, that ; is the job of the caller. ; - + strrev pshx ; Save X to the stack pshy ; Save Y to the stack @@ -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 @@ -439,7 +428,7 @@ revDone pula ; Restore A from the stack ; Comments: This subroutine requires serial to be setup and putchar subroutine. ; -PrintBinaryWord +PrintBinaryWord pshx ; Save X to the stack pshd ; Save D (A:B) to the stack pshb ; Save B to the stack (we want these bits again later) @@ -460,7 +449,7 @@ bPrintLoop rolb ; Rotate MSB of B into C of CCR bPrintDone puld ; Restore D (A:B) from the stack pulx ; Restore X from the stack rts ; Return to caller - + ;************************************************************************* ; PrintHexWord subroutine ; @@ -468,17 +457,31 @@ bPrintDone puld ; Restore D (A:B) from the stack ; ; Input: 1 word of data in register D, Buffer Address in Y ; Output: Hexadecimal representation of the data on the serial console -; Registers in use: Y for the address of the buffer, X to count the number of bits +; Registers in use: Y for the address of the buffer, X to count the number of bits ; written and for division, D for the input, A for characters. ; Memory locations in use: Memory addresses for serial. ; ; Comments: This subroutine requires serial to be setup and putchar subroutine. ; - + 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 @@ -496,7 +499,7 @@ hex10 addb #'0' ; Add '0' to B to get ASCII Character bra hPrintLoop ; Loop to hPrintLoop hCheck cpd #0 ; Compare D to 0 bne hDNotZero ; If D != 0, branch back to hDNotZero -hPrintDone ldaa #'$' ; Load '$' into +hPrintDone ldaa #'$' ; Load '$' into staa 1,+y ; Save '$' into buffer in Y to denote Hex ldx #buffer2 ; Load the address of buffer2 in X jsr strrev ; Reverse string in Y in buffer in X @@ -508,7 +511,15 @@ 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 ; @@ -516,17 +527,31 @@ hPrintDone ldaa #'$' ; Load '$' into ; ; Input: 1 word of data in register D, Buffer Address in Y ; Output: Decimal representation of the data on the serial console -; Registers in use: Y for the address of the buffer, X to count the number of bits +; Registers in use: Y for the address of the buffer, X to count the number of bits ; written and for division, D for the input, A for characters. ; Memory locations in use: Memory addresses for serial. ; ; Comments: This subroutine requires serial to be setup and putchar subroutine. ; - + 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,7 +572,13 @@ 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 ; @@ -569,6 +600,24 @@ zerosLoop staa 1,x+ ; Load A into byte at X pula ; Restore A from the stack 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 ; @@ -625,7 +674,6 @@ doneRead ldaa #LF ; Load Line Feed into A pula ; restore A from the stack rts ; return to caller - ;************************************************************************* ; putchar subroutine ; @@ -658,26 +706,24 @@ getchar brclr SCISR1,#%00100000,getchar7 ; If no input on SCI port, r getchar7 clra ; Set A to 0 rts ; Return to caller +* ************************************************************************** -* Data Section: address used [ $3100 to $3FFF ] RAM Memory +* Data Section 2: address used [ $3100 to $3FFF ] RAM Memory * -; unknown: string to warn the user of unknown output -unknown dc.b 'Error: Unknown Command',CR,LF,NULL +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 'L1: Turn on LED1',CR,LF - dc.b 'F1: Turn off LED1',CR,LF - dc.b 'L2: Turn on LED2',CR,LF - dc.b 'F2: Turn off LED2',CR,LF - dc.b 'L3: Turn on LED3',CR,LF - dc.b 'F3: Turn off LED3',CR,LF - dc.b 'L4: LED4 goes from 0% light level to 100% light level in 0.4 seconds',CR,LF - dc.b 'F4: LED4 goes from 100% light level to 0% light level in 0.4 seconds',CR,LF - dc.b 'QUIT: Quit menu program, run Type writer program.',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 diff --git a/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell.mcp b/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell.mcp index 1466bdc..b8bca08 100644 Binary files a/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell.mcp and b/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell.mcp differ diff --git a/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell_Data/Standard/ObjectCode/main.asm.o b/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell_Data/Standard/ObjectCode/main.asm.o index 7b911f3..83bccdd 100644 Binary files a/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell_Data/Standard/ObjectCode/main.asm.o and b/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell_Data/Standard/ObjectCode/main.asm.o differ diff --git a/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell_Data/Standard/ObjectCode/main.asm.sx b/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell_Data/Standard/ObjectCode/main.asm.sx index 8880999..05d7a45 100644 --- a/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell_Data/Standard/ObjectCode/main.asm.sx +++ b/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell_Data/Standard/ObjectCode/main.asm.sx @@ -1,40 +1,38 @@ S0840000433A5C55736572735C4A61636F62204D63446F6E6E656C6C5C446F63756D656E74735C434D50454E2D3437322D48575C636D70656E3437326877365F4D63446F6E6E656C6C5C636D70656E3437326877365F4D63446F6E6E656C6C5F446174615C5374616E646172645C4F626A656374436F64655C6D61696E2E61736D2E70726DCD -S1233000003605000000000000000000000000000000000000100000000000000000000061 -S1233020000000000000000010696E76616C696420696E7075742C20616464726573730D06 -S12330400A00696E76616C696420696E7075742C20646174610D0A00696E76616C69642027 -S1143060696E7075742C20636F6D6D616E640D0A00E9 -S1233100CF310086F15A03860C5ACBCC00015CC8CE3003FD3014163352863E163386862019 -S1233120163386CE3003FD3014163367CE300316314620DCCE33AF16335B16338D27FB16DE -S123314033865A0120F4343BA630815727258151276F81532662A6008124265C1631DA2701 -S123316044B7E534CE3003FD301416335230163252202FA6008124263F1631DA2727B7E487 -S12331803BA6302729812027F88124270809163225271B2006091631DA27133AB7C56D00D1 -S12331A020003A303DCE302916335B3A303DCE304216335B3A3A303DCE305816335B3A30A9 -S12331C03DA630815526F1A630814926EBA630815426E5A63026E10631343BCD0000E6301E -S12331E0C124263BE6302732C120272EC1302D2FC139220EC03037CC001013B7C63319ED9D -S123320020E2C1412D19C1462215C041CB0A37CC001013B7C63319ED20CA87B7023A3D8649 -S123322004B7023A3D3BCD0000E630271AC1202716C1302D17C1392213C03037CC000A1365 -S1233240B7C63319ED20E287B7023A3D8604B7023A3D353BB7D4CD30031632E0B7C5863DDF -S1233260163386863E163386EC00CE3003FD30141633521632BB3686201633861633863270 -S1233280CD30031632E036862016338616338632CE3003FD3014163352CD30031633228688 -S12332A00D163386860A1633863A313D343536A67F27046A3020F83231303D343B37180EEA -S12332C08625163386CE001055B72084018B301633860405088E000826EE3320EB3A303DB7 -S12332E0343B35CE001018108E00002716C10A2D0ACB41C00A6B60B7D420E8CB306B60B7A2 -S1233300D420E08C000026E586246A60CE30161632AC16335BFD3027CE3016163352313AB0 -S1233320303D343B35CE000A18108E00002708CB306B60B7D420EE8C000026F3CE3016168D -S123334032AC16335BFD3027CE3016163352313A303D36876A300436FB323D36A6302705D9 -S123336016338620F7323D36353416338D27FB810D270A6A3016338603270220ED860A1656 -S123338033863031323D4FCC80FC5ACF3D4FCC200396CF3D873D4572726F723A20556E6B6D -S12333A06E6F776E20436F6D6D616E640D0A0057656C636F6D6520746F2054797065205749 -S12333C072697465722C20796F75206D617920747970652062656C6F772E0D0A52657374B5 -S12333E061727420746F20656E746572206D61696E206D656E7520616761696E2E0D0A0042 -S12334004C313A205475726E206F6E204C4544310D0A46313A205475726E206F6666204CAD -S12334204544310D0A4C323A205475726E206F6E204C4544320D0A46323A205475726E2060 -S12334406F6666204C4544320D0A4C333A205475726E206F6E204C4544330D0A46333A205E -S12334605475726E206F6666204C4544330D0A4C343A204C45443420676F65732066726FED -S12334806D203025206C69676874206C6576656C20746F2031303025206C69676874206C39 -S12334A06576656C20696E20302E34207365636F6E64730D0A46343A204C45443420676FBA -S12334C065732066726F6D2031303025206C69676874206C6576656C20746F203025206CF2 -S12334E069676874206C6576656C20696E20302E34207365636F6E64730D0A515549543A98 -S12335002051756974206D656E752070726F6772616D2C2072756E20547970652077726922 -S11235207465722070726F6772616D2E0D0A00F0 +S1233000000500000000000000000000000000000000000010000000000000000000000097 +S10B3020000000000000001094 +S1233100CF310086F15A03860C5ACBCC00015CC8CE34851633B1CE3002FD30131633A286FD +S12331203E1633DC86201633DCCE3002FD30131633BDCE300216314C20DCCE34341633B158 +S12331401633E327FB1633DC5A0120F4343BA630815727228151276D81532660A600812418 +S1233160265A1631DE2742B7E534CE3002FD30131633A230202DA600812426401631DE27C8 +S123318028B7E43BA630272A812027F88124270809163229271C2006091631DE27143AB735 +S12331A0C56D001632563A303DCE33EC1633B13A303DCE34051633B13A3A303DCE341B16F1 +S12331C033B13A303DA630815526F1A630814926EBA630815426E5A63026E106313A3BCDE0 +S12331E00000E630C124263BE6302732C120272EC1302D2FC139220EC03037CC001013B786 +S1233200C63319ED20E2C1412D19C1462215C041CB0A37CC001013B7C63319ED20CA87B749 +S1233220023A3D8604B7023A3D3BCD0000E630271AC1202716C1302D17C1392213C030374F +S1233240CC000A13B7C63319ED20E287B7023A3D8604B7023A3D353BB7D4CD30021632E72F +S1233260B7C5863D1633DC863E1633DCEC00CE3002FD30131633A21632C23686201633DCDB +S12332801633DC32CD30021632E73686201633DC1633DC32CE3002FD30131633A2CD300223 +S12332A0163350860D1633DC860A1633DC3A313D343536A67F27056A3020F8876A30323136 +S12332C0303D343B37180E86251633DCCE001055B72084018B301633DC0405088E000826A5 +S12332E0EE3320EB3A303D343B358C000027533635348630CE3015CD00051633AB30318737 +S12333006A4032CE001018108E00002716C10A2D0ACB41C00A6B60B7D420E8CB306B60B749 +S1233320D420E08C000026E586246A60CE30151632B01633B1FD3026CE30151633A2313AE9 +S1233340303D86241633DC86301633DC313A303D343B358C000027413635348630CE30157A +S1233360CD00051633AB3031876A4032CE000A18108E00002708CB306B60B7D420EE8C0017 +S12333800026F3CE30151632B01633B1FD3026CE30151633A2313A303D86301633DC313A9C +S12333A0303D36876A300436FB323D6A300436FB3D36A63027051633DC20F7323D36353413 +S12333C01633E327FB810D270A6A301633DC03270220ED860A1633DC3031323D4FCC80FCC8 +S12333E05ACF3D4FCC200396CF3D873D696E76616C696420696E7075742C2061646472653C +S123340073730D0A00696E76616C696420696E7075742C20646174610D0A00696E76616C5D +S1233420696420696E7075742C20636F6D6D616E640D0A0057656C636F6D6520746F2054E6 +S1233440797065205772697465722C20796F75206D617920747970652062656C6F772E0D17 +S12334600A5265737461727420746F20656E746572206D61696E206D656E752061676169CC +S12334806E2E0D0A00533A20202020202053686F772074686520636F6E74656E7473206F09 +S12334A066206D656D6F7279206C6F636174696F6E20696E20776F72640D0A573A20202095 +S12334C0202020577269746520746865206461746120776F726420286E6F74206279746519 +S12334E02920746F206D656D6F7279206C6F636174696F6E0D0A515549543A2020205175B0 +S1233500697420746865206D61696E2070726F6772616D2C2072756E205479706520777220 +S1133520697465722070726F6772616D2E0D0A0086 S9033100CB diff --git a/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell_Data/Standard/TargetDataWindows.tdt b/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell_Data/Standard/TargetDataWindows.tdt index 701d82f..94bdf6c 100644 Binary files a/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell_Data/Standard/TargetDataWindows.tdt and b/cmpen472hw6_McDonnell/cmpen472hw6_McDonnell_Data/Standard/TargetDataWindows.tdt differ -- cgit v1.2.3