summaryrefslogtreecommitdiff
path: root/cmpen472hw5_McDonnell/bin/main.dbg
diff options
context:
space:
mode:
authorJacob McDonnell <jacob@jacobmcdonnell.com>2025-02-21 16:03:18 -0500
committerJacob McDonnell <jacob@jacobmcdonnell.com>2025-02-21 16:03:18 -0500
commit2b6e22d8d4debc81cb8b7a16f731b46c7dd59c2e (patch)
tree23edc2b4ab13e6242bb3018290ab23675a049ee9 /cmpen472hw5_McDonnell/bin/main.dbg
parent7b229a479e8951d6ef4a738ac22ef46ca33808eb (diff)
HW5 ReadString now checks length
Diffstat (limited to 'cmpen472hw5_McDonnell/bin/main.dbg')
-rw-r--r--cmpen472hw5_McDonnell/bin/main.dbg23
1 files changed, 16 insertions, 7 deletions
diff --git a/cmpen472hw5_McDonnell/bin/main.dbg b/cmpen472hw5_McDonnell/bin/main.dbg
index 92a558c..8c52b13 100644
--- a/cmpen472hw5_McDonnell/bin/main.dbg
+++ b/cmpen472hw5_McDonnell/bin/main.dbg
@@ -77,9 +77,9 @@ Counter dc.w $0036 ; X register count number for time Delay
LEVEL dc.b $0005 ; Light Level that the LED should be
-str ds.b $0005 ; Array of 5 bytes to read a string
+str ds.b $000F ; Array of 16 bytes to read a string
dc.b NULL
-lenStr dc.w $0005 ; Length of str array
+lenStr dc.w $000F ; Length of str array
* There is a second Data Section at the end of the file.
*
**************************************************************************
@@ -107,6 +107,7 @@ mainLoop
jsr Zeros ; jump to Zeros to zero out str
ldx #str ; Reload address of str into X
+ ldy lenStr ; Load the length of the string into Y
jsr ReadString ; Jump to ReadString to read user input into str
ldx #str ; Reload Address of str into X
@@ -153,6 +154,7 @@ CheckInput
cmpa #'4' ; Compare Character in A to '4'
beq L4Check ; If A == '4', branch to L4Check
suba #'0' ; Subtract character '0' from A
+ ; This allows the number in A to be the LED number (if correct)
ble none ; If A < '0', branch to none (unknown string)
cmpa #4 ; Compare A to 4
bhs none ; Branch to None if A > 3
@@ -245,7 +247,8 @@ doneWrite pula ; restore A from the stack
;
; Input: Address of an array in X
; Output: Null terminated string in the given array
-; Registers in use: X for the address of the string and A for the current byte
+; Registers in use: X for the address of the string Y for the length of the string,
+; and A for the current byte
; Memory locations in use: Memory Address for serial line, address of the string
;
; Comments: This subroutine requires serial to be setup and getchar subroutine.
@@ -253,6 +256,7 @@ doneWrite pula ; restore A from the stack
ReadString
psha ; Save accumulator A to the stack
+ pshy ; Save Y to the stack
pshx ; Save X to the stack
readLoop jsr getchar ; Jump to putchar to write byte to serial
beq readLoop ; While A == 0, loop
@@ -260,10 +264,13 @@ readLoop jsr getchar ; Jump to putchar to write byte to seria
beq doneRead ; Branch to doneRead if A == CR
staa 1,x+ ; Save the byte to the addr in X, then add 1
jsr putchar ; Write Character back to the terminal
+ dey ; Decrement Y by 1
+ beq doneRead ; If Y == 0, no more room, stop reading
bra readLoop ; branch always to readLoop
doneRead ldaa #LF ; Load Line Feed into A
jsr putchar ; Write LF to terminal
pulx ; Restore X from the stack
+ pulY ; Restore Y from the stack
pula ; restore A from the stack
rts ; return to caller
@@ -345,14 +352,15 @@ doneDec pula ; Restore A from the stack
rts ; Return to caller
;*************************************************************************
-; HighToLow subroutine
+; LowToHigh subroutine
;
-; This subroutine will dim LED4 from 100% to 0% in 400ms
+; This subroutine will dim LED4 from 0% to 100% in 400ms
;
; Input: No Input, all parameters are hard coded
-; Output: LED4 dimmed from 100% to 0% in 400ms, wasted cycles
+; Output: LED4 dimmed from 0% to 100% in 400ms, wasted cycles
; Registers in use: A accumulator to control the light level of the LED
; Memory locations in use: PORTB memory location associated with PORTB on the chip
+; LEVEL memory location for byte of light level.
;
; Comments: This subroutine requires dimmer subroutine
;
@@ -381,7 +389,8 @@ doneInc pula ; Restore A from the stack
; LED4 should be on and off for.
; Output: LED4 dimmed to a given level, wasted cycles
; Registers in use: A accumulator to counter number of times looped
-; Memory locations in use: Two bytes ONN and OFF used to dim the LED4 to a given level
+; Memory locations in use: PORTB memory location associated with PORTB on the chip
+; LEVEL memory location for byte of light level.
;
; Comments: This subroutine requires delay10usec subroutine
;