Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. It's the small things that matter.

It's the small things that matter.

Scheduled Pinned Locked Moved The Weird and The Wonderful
data-structuresdebuggingperformancehelpquestion
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    puromtec1
    wrote on last edited by
    #1

    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
    
    S OriginalGriffO B A F 5 Replies Last reply
    0
    • P puromtec1

      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
      
      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      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

      OriginalGriffO 1 Reply Last reply
      0
      • S Stephen Hewitt

        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

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        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.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • P puromtec1

          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
          
          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          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.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          P 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            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.

            P Offline
            P Offline
            puromtec1
            wrote on last edited by
            #5

            Its interesting to see how my suffering helps others.

            1 Reply Last reply
            0
            • P puromtec1

              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
              
              B Offline
              B Offline
              BillW33
              wrote on last edited by
              #6

              Yes, things like that are really a pain to find. You didn't have to post that much code to get the point across though. ;) :)

              Just because the code works, it doesn't mean that it is good code.

              1 Reply Last reply
              0
              • P puromtec1

                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
                
                A Offline
                A Offline
                Al_Brown
                wrote on last edited by
                #7

                jp nz, {++}
                jp {+}
                ++:

                I might be missing something, but why isn't that just

                jr z, {+}

                P 1 Reply Last reply
                0
                • P puromtec1

                  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
                  
                  F Offline
                  F Offline
                  fjdiewornncalwe
                  wrote on last edited by
                  #8

                  That's NOT what she said!!!

                  I wasn't, now I am, then I won't be anymore.

                  1 Reply Last reply
                  0
                  • A Al_Brown

                    jp nz, {++}
                    jp {+}
                    ++:

                    I might be missing something, but why isn't that just

                    jr z, {+}

                    P Offline
                    P Offline
                    puromtec1
                    wrote on last edited by
                    #9

                    I think I'll take CIDiv's advice next time....you're probably not missing something...

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups