Cisano Posted August 7, 2022 Share Posted August 7, 2022 (edited) Hi, I have this problem. I need to read an array DATA long 250 elements. Is there a way to do it? Thanks. ldy #250 loop lda DATA,y ;do something dey bne loop ;rest of the program ... DATA .byte #$02 .byte #$0a ... .byte #$1d ; 250th element Edited August 7, 2022 by Cisano Quote Link to comment Share on other sites More sharing options...
+Bruce-Robert Pocock Posted August 7, 2022 Share Posted August 7, 2022 Assuming you mean, 300, as a constant value, you can: first, run the loop 256 times with lda DATA, y, and then run the loop 44 times more with lda DATA + $100, y Quote Link to comment Share on other sites More sharing options...
Cisano Posted August 7, 2022 Author Share Posted August 7, 2022 Thanks for reply. I changed the value, my mistake, in 250. The problem is in runtime the data are not readen in the right sequence. It depends in which part of the program are the data after the compilation. Quote Link to comment Share on other sites More sharing options...
+Bruce-Robert Pocock Posted August 7, 2022 Share Posted August 7, 2022 2 hours ago, Cisano said: Thanks for reply. I changed the value, my mistake, in 250. The problem is in runtime the data are not readen in the right sequence. It depends in which part of the program are the data after the compilation. Note that the loop example you gave, above, reads in reverse order, from tail to head. For many things, it may be simply easier to reverse the data table itself so that it's in the reversed order: DATA: .byte LastValue, NextToLast, ..., Third, Second, First If that's not possible or not practical, you'll have to count up in your loop: ldy # 0 Loop: lda DATA, y ;; do something iny cpy # 250 ; end of loop value blt Loop Also, and it may be you're using an assembler I don't know, but it's quite unusual to have the # (hash, octothorpe, pound, number) sign in .byte lines. Normally, they'll be more like .byte $02 .byte $0a ;; ... .byte $1d Quote Link to comment Share on other sites More sharing options...
Cisano Posted August 7, 2022 Author Share Posted August 7, 2022 (edited) Yes, my mistake about the # in the .byte sequence. Anyway I made a mess about this question. I try to ask in another way. ldy # 0 Loop: lda DATA, y ;; do something iny cpy # 250 ; end of loop value blt Loop DATA ;Memory address only for make the question understandable f0fe .byte $02 f0ff .byte $0a f100 .byte $1d ... ... When memory address become f100, the loop doesn't read in the right memory location. I ask this because, moving the data in different part of the program, the output changes and sometimes is correct. How can I fix it? Thanks. Edited August 7, 2022 by Cisano Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted August 7, 2022 Share Posted August 7, 2022 The code you posted looks fine, reading from $f100 should work. 1 Quote Link to comment Share on other sites More sharing options...
+Dave C Posted August 7, 2022 Share Posted August 7, 2022 (edited) agree lda DATA,y should not wrap around. I checked myself (dasm + Stella) by forcing the data to be on a page boundary: ldy #1 lda DATA_PAGE_END,y ; should be $02 from $f300, not $03 from $f200 ORG $f200 ; (or wherever) byte $03 ORG $f2ff ; (or wherever) DATA_PAGE_END byte $01 byte $02 Edited August 7, 2022 by Dave C Quote Link to comment Share on other sites More sharing options...
glurk Posted August 7, 2022 Share Posted August 7, 2022 You could also have the data all on one page, so there is no page-crossing, by using: ALIGN 256 DATA .byte etc,etc,etc.... It's very common to do this in 2600 games for the number fonts and for sprite data to make calculating the LSB's easier (for pointers). But as others have said, LDA DATA,Y should work. But I think it takes 1 extra cycle on a page crossing, which may mess up precise timing. Quote Link to comment Share on other sites More sharing options...
Cisano Posted August 8, 2022 Author Share Posted August 8, 2022 Thanks for the answers. I'll try. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.