Jump to content
IGNORED

Stephen's A8 Blog - Fast mem clear + source


RSS Bot

Recommended Posts

Like most projects, I needed a mem clear routine. Standard Atari BASIC rev.C running a simple for-next loop takes a whopping 4.76 seconds to clear 768 bytes of RAM. This is unacceptable. Below is a 25-byte relocatable routine meant to be called via USR. It takes 2 parameters and is called via X=USR(1536,32768,3). 1536 is where I currently have it (page 6). Since I only need it upon initialization I will overwrite it. It would be just as easy to put it in a string, and call via X=USR(ADR(STRING$),32768,3).

 

Parameters:

1st is a 16-it number, used to hold the starting address of RAM to clear. Must be page aligned

2nd parameter is a 16-bit number, used to hold the # of pages to clear. hi-byte discarded so 255 is max. Don't do it, you'll crash the box!

 

This will clear the same 768 bytes in 7749 cycles, which is .004 seconds! Execution time grabbed via an AtariWin800Plus 4 trace file. Not a bad improvement. The only thing it requires is 25-bytes for code and 2 zero-page variables while executing.

 

;Original create date 01/06/10 - This is assembled to "MEMCLEAR.OBJ";This will be called from a USR function;1st parameter is # of parms (1 byte);2nd parameter is STARTing page of mem to clear (2 bytes hi-lo);3rd parameter is # of pages to clear (2 bytes hi-lo);E.G. X=USR($600,2,3);STACK will contain;02 - #paramaters;02 - hi (address to clear - valid is 00 to FF);00 - lo (address to clear, will always want this to be 00);00 - hi (DISCARD);03 - lo (save in X as # pages to clear);BENCHMARK - according to a tracefile (A800Win+) clearing 3 pages of RAM;takes 2326 instructions, 7749 cycles, .004 seconds;Atari BASIC loop takes 4.76 seconds (acording to $13,$14);ASM version is 1,192 times faster!;EquatesMEMTOCLR equ $CE ;$CE and $CF will contain the address of RAM to clear org $0600 ;This code will be overwritten once used ;since calling from BASIC, clear stack and set up variables pla ;clear # parameters from stack pla sta MEMTOCLR+1 ;hi-byte pla sta MEMTOCLR ;lo-byte pla ;discard since we can't clear more than $FF pages pla tax ;# of pages to clear ;stack is clean, variables set, now do the work lda #0 ;so we can clear RAM ;# of pages to clear has been preloaded in XL2 ldy #0 ;will be our countdown timerL1 sta (MEMTOCLR),y ; dey bne L1 ;when we fall through to here we have cleared one page inc MEMTOCLR+1 ;prepare to clear the next page dex ;decrease page counter bne L2 ;if not zero, jump back and clear another page rts ;All done - return control to BASIC

 

Attachment is a ZIP file (so it remained a binary). UnZIP and you have the object version. Read it into BASIC to call from USR or better yet, ream & import to a string.

 

Stephen Anderson

 

http://www.atariage.com/forums/index.php?app=blog&blogid=341&showentry=6729

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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