Jump to content
IGNORED

WUDSN and cpx counter 16bit?


eflake

Recommended Posts

I'm trying to load in a charset using an example, how would I change this to a 16-bit counter to read the entire 1024 bytes of a redefined character set? Can only seem to go to 255 - thought X was a 16 bit register.  Thanks.

 

space_loop
    lda charset.space,x
    sta chr,x
    inx
    cpx $400
    bne space_loop

 

Edited by eflake
Link to comment
Share on other sites

On the 6502 and non 16 bit derivatives the only 16-bit register is the PC.

 

Zero-page can be sort of like a bunch of psuedo 16-bit registers since the indirect addressing modes use them as such.

 

To copy more than 256 bytes there's generally 3 usual options:

. Use extra indexed instructions e.g. lda charset.space+$100,x / sta chr+$100,x

. Use a pair of z-page pointers.  The usual case there is when the size to be copied is variable or unknown.  More coding needed and you usually keep a counter for the # of pages or do a compare when incrementing the high byte of source or destination.

. Self-modifying code.  It can be done in a compact fashion and can often be the fastest method but hard to debug if things go wrong.

  • Like 1
Link to comment
Share on other sites

you need an outer loop and an inner loop and as @Rybags said page zero pointers

something like this

 

   lda #source&255

   sta $E0

   lda #source/256

   sta $E1

   lda #dest&255

   sta $E2

   lda #dest/256

   sta $E3

   ldx #4 ; will move 1K

loop ldy #0

   lda ($E0),y

   sta ($E2),y

   iny

   bne loop

   dex

   bne loop

 

 

 

  • Like 1
Link to comment
Share on other sites

47 minutes ago, TGB1718 said:

   ldx #4 ; will move 1K

loop ldy #0

   lda ($E0),y

   sta ($E2),y

   iny

   bne loop

   dex

   bne loop

Almost....

You still need to inc $E1 & $E3 in the outer loop.  As written, it will just copy the same $100 bytes four times.

 

Link to comment
Share on other sites

4 hours ago, eflake said:

space_loop
    lda charset.space,x
    sta chr,x
    inx
    cpx $400
    bne space_loop

If X was 16-bit, you'd need #$400 ;) 

 

I would copy a kilobyte without using page zero. Like Rybags said:

 

; mads syntax
	ldx #0
loop
	mva src+$0000,x dst+$0000,x
	mva src+$0100,x dst+$0100,x
	mva src+$0200,x dst+$0200,x
	mva src+$0300,x dst+$0300,x
	inx:bne loop

 

  • Like 4
Link to comment
Share on other sites

45 minutes ago, ivop said:

I would copy a kilobyte without using page zero. Like Rybags said:

Agreed, that's much better for small chunks of code, I just looked at some code I used in a Centronics

Printer handler I wrote many moons ago that moved the OS ROM into RAM, then overwrote the internal

printer handler with my own code (saved using any memory), so was moving lots more code

Link to comment
Share on other sites

This did it, thanks. to get it to where i can understand it - and it seems smart doing 4 at once

 

 

ldx #0        ;set counter to 0

space_loop

    mva charset.space,x chr,x                            ;move charset(x) to High byte of character set pointer
    mva charset.space+$100,x chr+$100,x        ;move charset(x+256) to High byte of character set pointer
    mva charset.space+$200,x chr+$200,x        ;move charset(x+512) to High byte of character set pointer
    mva charset.space+$300,x chr+$300,x        ;move charset(x+768) to High byte of character set pointer
    mva charset.space+$400,x chr+$400,x        ;move charset(x+1024) to High byte of character set pointer
    inx                                                             ;add 1 to pointer (counter)
    bne space_loop                                           ;if not rolled over keep looping

 

Edited by eflake
  • Like 1
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...