It's the small things that matter.
-
So, yeah, spent a few days (at night, as this is not for my day job) looking for a bug in this code...yep, the bug? Needed to place the return command "ret" after white space, ie. not at the start of a line. Side-effect? It doesn't return, just keeps running the next instruction in memory after ret. :wtf:
DisplaySelectList:
cls() ;======================================== ; ; Input: ; AppSelectListControl.TopPosition ; AppSelectListControl.ListItemsIndirect ; AppSelectListControl.LineStartAddys ; ; ; Start reading the LineStartAddys ; at the TopPosition position ; ; Set the TextInverse if the value in ; ListItemsIndirect at position is equal to ; SelectedItem value. ; ; Determine if TopPosition ptr is the first ; line of a list item, if so, then print ; that number. ; ; Print starting at the LineStartAddys\[x\] ; until NULL reached. ld a, (AppSelectListControl.TopPosition) ld (AppSelectListControl.PositionCount), a ; save to variable ;.breakpoint check\_a\_for\_top\_position nop
LoopPositions:
;======================================= ; Check that PositionCount - TopPosition ; is not equal to 9, else stop printing ;======================================= ld a, (AppSelectListControl.TopPosition) ld b, a ld a, (AppSelectListControl.PositionCount) sub b cp 9 .breakpoint check\_z\_for\_reached\_9\_a\_vs\_b ;==============Base case displayed == 9 ? then stop jp z, donePrintingSelectList ;============================================= ; Get the addy of the string and save to stack ; ; ;============================================= ld de, AppSelectListControl.LineStartAddys ;calculate offset of array start .breakpoint de\_has\_LineStartAddy ;calculate offset using TopPosition xor a ld h, a ld a, (AppSelectListControl.PositionCount) ld l, a add hl, hl ;double because array is of 2byte items add hl, de ; offset calculated ;.breakpoint check\_hl\_for\_addy\_of\_LineStartAddys\_of\_index ;============== ;-->ld (hl), hl ;============== ld c, (hl) inc hl ld b, (hl) push bc ; Save the addy to list item's string ; to be used by print string. ;========================== ; Get next position's addy, ; could be 0000 ; ;========================== inc hl ld a, (hl) ld (AppSelectListControl.NextAddy), a inc hl ld a, (hl) ld (AppSelectListControl.NextAddy+1), a ;reset hl back to ptr to addy
-
So, yeah, spent a few days (at night, as this is not for my day job) looking for a bug in this code...yep, the bug? Needed to place the return command "ret" after white space, ie. not at the start of a line. Side-effect? It doesn't return, just keeps running the next instruction in memory after ret. :wtf:
DisplaySelectList:
cls() ;======================================== ; ; Input: ; AppSelectListControl.TopPosition ; AppSelectListControl.ListItemsIndirect ; AppSelectListControl.LineStartAddys ; ; ; Start reading the LineStartAddys ; at the TopPosition position ; ; Set the TextInverse if the value in ; ListItemsIndirect at position is equal to ; SelectedItem value. ; ; Determine if TopPosition ptr is the first ; line of a list item, if so, then print ; that number. ; ; Print starting at the LineStartAddys\[x\] ; until NULL reached. ld a, (AppSelectListControl.TopPosition) ld (AppSelectListControl.PositionCount), a ; save to variable ;.breakpoint check\_a\_for\_top\_position nop
LoopPositions:
;======================================= ; Check that PositionCount - TopPosition ; is not equal to 9, else stop printing ;======================================= ld a, (AppSelectListControl.TopPosition) ld b, a ld a, (AppSelectListControl.PositionCount) sub b cp 9 .breakpoint check\_z\_for\_reached\_9\_a\_vs\_b ;==============Base case displayed == 9 ? then stop jp z, donePrintingSelectList ;============================================= ; Get the addy of the string and save to stack ; ; ;============================================= ld de, AppSelectListControl.LineStartAddys ;calculate offset of array start .breakpoint de\_has\_LineStartAddy ;calculate offset using TopPosition xor a ld h, a ld a, (AppSelectListControl.PositionCount) ld l, a add hl, hl ;double because array is of 2byte items add hl, de ; offset calculated ;.breakpoint check\_hl\_for\_addy\_of\_LineStartAddys\_of\_index ;============== ;-->ld (hl), hl ;============== ld c, (hl) inc hl ld b, (hl) push bc ; Save the addy to list item's string ; to be used by print string. ;========================== ; Get next position's addy, ; could be 0000 ; ;========================== inc hl ld a, (hl) ld (AppSelectListControl.NextAddy), a inc hl ld a, (hl) ld (AppSelectListControl.NextAddy+1), a ;reset hl back to ptr to addy
I've seen a similar bug caused by a compiler not behaving correctly when the last line in a file doesn't end in a newline character.
Steve
-
I've seen a similar bug caused by a compiler not behaving correctly when the last line in a file doesn't end in a newline character.
Steve
Had that with early Visual C++ and .h files: no newline == massive fail by compiler.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
So, yeah, spent a few days (at night, as this is not for my day job) looking for a bug in this code...yep, the bug? Needed to place the return command "ret" after white space, ie. not at the start of a line. Side-effect? It doesn't return, just keeps running the next instruction in memory after ret. :wtf:
DisplaySelectList:
cls() ;======================================== ; ; Input: ; AppSelectListControl.TopPosition ; AppSelectListControl.ListItemsIndirect ; AppSelectListControl.LineStartAddys ; ; ; Start reading the LineStartAddys ; at the TopPosition position ; ; Set the TextInverse if the value in ; ListItemsIndirect at position is equal to ; SelectedItem value. ; ; Determine if TopPosition ptr is the first ; line of a list item, if so, then print ; that number. ; ; Print starting at the LineStartAddys\[x\] ; until NULL reached. ld a, (AppSelectListControl.TopPosition) ld (AppSelectListControl.PositionCount), a ; save to variable ;.breakpoint check\_a\_for\_top\_position nop
LoopPositions:
;======================================= ; Check that PositionCount - TopPosition ; is not equal to 9, else stop printing ;======================================= ld a, (AppSelectListControl.TopPosition) ld b, a ld a, (AppSelectListControl.PositionCount) sub b cp 9 .breakpoint check\_z\_for\_reached\_9\_a\_vs\_b ;==============Base case displayed == 9 ? then stop jp z, donePrintingSelectList ;============================================= ; Get the addy of the string and save to stack ; ; ;============================================= ld de, AppSelectListControl.LineStartAddys ;calculate offset of array start .breakpoint de\_has\_LineStartAddy ;calculate offset using TopPosition xor a ld h, a ld a, (AppSelectListControl.PositionCount) ld l, a add hl, hl ;double because array is of 2byte items add hl, de ; offset calculated ;.breakpoint check\_hl\_for\_addy\_of\_LineStartAddys\_of\_index ;============== ;-->ld (hl), hl ;============== ld c, (hl) inc hl ld b, (hl) push bc ; Save the addy to list item's string ; to be used by print string. ;========================== ; Get next position's addy, ; could be 0000 ; ;========================== inc hl ld a, (hl) ld (AppSelectListControl.NextAddy), a inc hl ld a, (hl) ld (AppSelectListControl.NextAddy+1), a ;reset hl back to ptr to addy
Ah! You have brightened up a dull grey Thursday - it has been a few years since I looked at any Z80 code. :thumbsup: It's a bugger when you miss that an instruction is being treated as a label.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Ah! You have brightened up a dull grey Thursday - it has been a few years since I looked at any Z80 code. :thumbsup: It's a bugger when you miss that an instruction is being treated as a label.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
So, yeah, spent a few days (at night, as this is not for my day job) looking for a bug in this code...yep, the bug? Needed to place the return command "ret" after white space, ie. not at the start of a line. Side-effect? It doesn't return, just keeps running the next instruction in memory after ret. :wtf:
DisplaySelectList:
cls() ;======================================== ; ; Input: ; AppSelectListControl.TopPosition ; AppSelectListControl.ListItemsIndirect ; AppSelectListControl.LineStartAddys ; ; ; Start reading the LineStartAddys ; at the TopPosition position ; ; Set the TextInverse if the value in ; ListItemsIndirect at position is equal to ; SelectedItem value. ; ; Determine if TopPosition ptr is the first ; line of a list item, if so, then print ; that number. ; ; Print starting at the LineStartAddys\[x\] ; until NULL reached. ld a, (AppSelectListControl.TopPosition) ld (AppSelectListControl.PositionCount), a ; save to variable ;.breakpoint check\_a\_for\_top\_position nop
LoopPositions:
;======================================= ; Check that PositionCount - TopPosition ; is not equal to 9, else stop printing ;======================================= ld a, (AppSelectListControl.TopPosition) ld b, a ld a, (AppSelectListControl.PositionCount) sub b cp 9 .breakpoint check\_z\_for\_reached\_9\_a\_vs\_b ;==============Base case displayed == 9 ? then stop jp z, donePrintingSelectList ;============================================= ; Get the addy of the string and save to stack ; ; ;============================================= ld de, AppSelectListControl.LineStartAddys ;calculate offset of array start .breakpoint de\_has\_LineStartAddy ;calculate offset using TopPosition xor a ld h, a ld a, (AppSelectListControl.PositionCount) ld l, a add hl, hl ;double because array is of 2byte items add hl, de ; offset calculated ;.breakpoint check\_hl\_for\_addy\_of\_LineStartAddys\_of\_index ;============== ;-->ld (hl), hl ;============== ld c, (hl) inc hl ld b, (hl) push bc ; Save the addy to list item's string ; to be used by print string. ;========================== ; Get next position's addy, ; could be 0000 ; ;========================== inc hl ld a, (hl) ld (AppSelectListControl.NextAddy), a inc hl ld a, (hl) ld (AppSelectListControl.NextAddy+1), a ;reset hl back to ptr to addy
-
So, yeah, spent a few days (at night, as this is not for my day job) looking for a bug in this code...yep, the bug? Needed to place the return command "ret" after white space, ie. not at the start of a line. Side-effect? It doesn't return, just keeps running the next instruction in memory after ret. :wtf:
DisplaySelectList:
cls() ;======================================== ; ; Input: ; AppSelectListControl.TopPosition ; AppSelectListControl.ListItemsIndirect ; AppSelectListControl.LineStartAddys ; ; ; Start reading the LineStartAddys ; at the TopPosition position ; ; Set the TextInverse if the value in ; ListItemsIndirect at position is equal to ; SelectedItem value. ; ; Determine if TopPosition ptr is the first ; line of a list item, if so, then print ; that number. ; ; Print starting at the LineStartAddys\[x\] ; until NULL reached. ld a, (AppSelectListControl.TopPosition) ld (AppSelectListControl.PositionCount), a ; save to variable ;.breakpoint check\_a\_for\_top\_position nop
LoopPositions:
;======================================= ; Check that PositionCount - TopPosition ; is not equal to 9, else stop printing ;======================================= ld a, (AppSelectListControl.TopPosition) ld b, a ld a, (AppSelectListControl.PositionCount) sub b cp 9 .breakpoint check\_z\_for\_reached\_9\_a\_vs\_b ;==============Base case displayed == 9 ? then stop jp z, donePrintingSelectList ;============================================= ; Get the addy of the string and save to stack ; ; ;============================================= ld de, AppSelectListControl.LineStartAddys ;calculate offset of array start .breakpoint de\_has\_LineStartAddy ;calculate offset using TopPosition xor a ld h, a ld a, (AppSelectListControl.PositionCount) ld l, a add hl, hl ;double because array is of 2byte items add hl, de ; offset calculated ;.breakpoint check\_hl\_for\_addy\_of\_LineStartAddys\_of\_index ;============== ;-->ld (hl), hl ;============== ld c, (hl) inc hl ld b, (hl) push bc ; Save the addy to list item's string ; to be used by print string. ;========================== ; Get next position's addy, ; could be 0000 ; ;========================== inc hl ld a, (hl) ld (AppSelectListControl.NextAddy), a inc hl ld a, (hl) ld (AppSelectListControl.NextAddy+1), a ;reset hl back to ptr to addy
-
So, yeah, spent a few days (at night, as this is not for my day job) looking for a bug in this code...yep, the bug? Needed to place the return command "ret" after white space, ie. not at the start of a line. Side-effect? It doesn't return, just keeps running the next instruction in memory after ret. :wtf:
DisplaySelectList:
cls() ;======================================== ; ; Input: ; AppSelectListControl.TopPosition ; AppSelectListControl.ListItemsIndirect ; AppSelectListControl.LineStartAddys ; ; ; Start reading the LineStartAddys ; at the TopPosition position ; ; Set the TextInverse if the value in ; ListItemsIndirect at position is equal to ; SelectedItem value. ; ; Determine if TopPosition ptr is the first ; line of a list item, if so, then print ; that number. ; ; Print starting at the LineStartAddys\[x\] ; until NULL reached. ld a, (AppSelectListControl.TopPosition) ld (AppSelectListControl.PositionCount), a ; save to variable ;.breakpoint check\_a\_for\_top\_position nop
LoopPositions:
;======================================= ; Check that PositionCount - TopPosition ; is not equal to 9, else stop printing ;======================================= ld a, (AppSelectListControl.TopPosition) ld b, a ld a, (AppSelectListControl.PositionCount) sub b cp 9 .breakpoint check\_z\_for\_reached\_9\_a\_vs\_b ;==============Base case displayed == 9 ? then stop jp z, donePrintingSelectList ;============================================= ; Get the addy of the string and save to stack ; ; ;============================================= ld de, AppSelectListControl.LineStartAddys ;calculate offset of array start .breakpoint de\_has\_LineStartAddy ;calculate offset using TopPosition xor a ld h, a ld a, (AppSelectListControl.PositionCount) ld l, a add hl, hl ;double because array is of 2byte items add hl, de ; offset calculated ;.breakpoint check\_hl\_for\_addy\_of\_LineStartAddys\_of\_index ;============== ;-->ld (hl), hl ;============== ld c, (hl) inc hl ld b, (hl) push bc ; Save the addy to list item's string ; to be used by print string. ;========================== ; Get next position's addy, ; could be 0000 ; ;========================== inc hl ld a, (hl) ld (AppSelectListControl.NextAddy), a inc hl ld a, (hl) ld (AppSelectListControl.NextAddy+1), a ;reset hl back to ptr to addy
That's NOT what she said!!!
I wasn't, now I am, then I won't be anymore.