Jump to content
IGNORED

Reading a long sequence of data


Cisano

Recommended Posts

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 by Cisano
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 by Cisano
Link to comment
Share on other sites

 

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 by Dave C
Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...