<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Thu, 24 Jun 1993 09:54:47 BST
From   : matthew@... (Matthew Sweet)
Subject: Re: Unrolling loops & fast routines

Mik,

You wrote:
>  Great, now I'm no expert in this area, so could someone please send me
>the above code set up to work anywhere in memory. (Dave mentioned something
>about page boundaries earlier?). The destination will always be the screen
>display RAM (yes, I'm shifting MODE 7 screens) so &7C00 to &7FFF. The source
>address could potentially be anywhere as it is just DIMed in BASIC.

Mik,

The only way to get the routine as fast as the above is to use it to
copy from and to page aligned buffers. The easiest way to guarantee
that you can do this is to DIM more memory than you need, and use
another variable as your base:

DIM BufferSpace% &4ff
BufferStart%=(BufferSpace%+&ff) AND &100

If you _always_ want to copy from the same buffer to screen memory,
then the preamble at the start of the routine can be reduced, making
the code:

copy_buffer_to_screen:
       ldx #0
.loop  lda BufferStart%,X
       sta &7c00,X
       lda (BufferStart%+&100),X
       sta &7d00,X
       lda (BufferStart%+&200),X
       sta &7e00,X
       lda (BufferStart%+&300),X
       sta &7f00,X
       inx
       bne loop
       rts

This code fragment is 30 bytes long, and contains no absolute jumps,
therefore you should be able to assemble it starting at BufferSpace%,
and relocate it to BufferStart%+&400 if BufferStart%-BufferSpace% < 30.

Note:
1      Your code will not work if you are using a second processor.
2      Your code will give strange results if the screen has H/W
       scrolled since the last time the screen was cleared.

Hope that this has been helpful!

Matthew
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>