Commodore 64 (C64) Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Any clever way to speed up this copy loop?

 
Post new topic   Reply to topic    Commodore 64 (C64) Forum Index -> Help & Support
View previous topic :: View next topic  
Author Message
e5frog
Immortal Grandmaster of C64
Immortal Grandmaster of C64


Joined: 30 Apr 2009
Age: 38
Posts: 3465
Location: Sweden

PostPosted: Sat Mar 17, 2012 2:05 pm    Post subject: Any clever way to speed up this copy loop? Reply with quote

Code:
.C:034f   A0 40      LDY #$40
.C:0351   A2 00      LDX #$00
.C:0353   BD 00 80   LDA $8000,X
.C:0356   9D 00 08   STA $0800,X
.C:0359   E8         INX
.C:035a   D0 F7      BNE $0353
.C:035c   EE 55 03   INC $0355
.C:035f   EE 58 03   INC $0358
.C:0362   88         DEY
.C:0363   D0 EC      BNE $0351
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
mrsid
C64 Enthusiast
C64 Enthusiast


Joined: 27 Jan 2003
Age: 38
Posts: 802
Location: Netherlands

PostPosted: Sat Mar 17, 2012 2:22 pm    Post subject: Reply with quote

How much memory are you willing to sacrifice?
Back to top
View user's profile Send private message
e5frog
Immortal Grandmaster of C64
Immortal Grandmaster of C64


Joined: 30 Apr 2009
Age: 38
Posts: 3465
Location: Sweden

PostPosted: Sat Mar 17, 2012 3:06 pm    Post subject: Reply with quote

Speed is nice, as long as it copies 16k from 8000 to 0800 I don't really care how it looks if it's faster. Wink

I need to repeat the copy process three more times (change banks and continue copy), preferably also fit it in the tape buffer. Last time is only leftover 1500 bytes.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
iAN CooG
Master of C64
Master of C64


Joined: 31 Jan 2003
Age: 42
Posts: 1152
Location: Italy

PostPosted: Sat Mar 17, 2012 5:20 pm    Post subject: Reply with quote

this is a non issue, copying 62k (not 64k, because you have to copy to $800) takes 1 second anyway.
You also don't consider that you have to reserve about $100 bytes in bank 0 to actually store the crt init routine + the relocation code, and that you're not actually copying 64k but 62 max ($800-ffff), so every bank need to copy a variable amount of bytes. Not counting that you have to switch roms off when you write, else you will make a mess when copying to $d000. =)
A cart that support 4x16kb banks is Supergames, this is a quick example how to use it. Refer to CRT.txt or your cart documentation on how to switch banks and turn off the cart completely after you're done relocating.
http://iancoog.altervista.org/...es_crt.rar
Code:

; copy from 64kcart rom, 4x16kb banks to $0800-$ffff (62kb usable)
; using Supergames type cart
trbuff=$0334
bank=$02
gameinit=$080d
    *=$8000
    word start
    word start
    hex c3 c2 cd 38 30
start
    jsr $fda3
    jsr $fd50
    jsr $fd15
    jsr $ff5b
    cli
    ldx #$ff
    txs
    inx
    stx $d011
    stx $d020
    stx $d021
    lda #$c8
    sta $d016
    lda #$15
    sta $d018
    lda #$79
    sta $d019
    lda #$f0
    sta $d01a
    ldy #$00
lp1
    lda reloc,y
    sta trbuff,y
    iny
    cpy #[endreloc-reloc+1]
    bne lp1
    jmp trbuff
    ; this is relocated to $0334
reloc
    rorg trbuff
    sei
    ldx #$0
    stx bank
    ; 1st bank is NOT copied from $8000 but, let's say from $8100, because
    ; you have to put init code and this copy routine at $8000 in bank 0
    ; hence from $8000-80ff it's reserved
mainloop
    stx $df00   ; set cart bank
    ldy blocklen,x
    ldx #$00
inloop
ptr1=*+2
    lda $8100,x
    inc $01
ptr2=*+2
    sta $0800,x
    dec $01
    inx
    bne inloop
    inc ptr1
    inc ptr2
    dey
    bne inloop

    lda #$80    ; reset ptr1 to $8000, ptr2 is already pointing correctly
    sta ptr1
    inc bank
    ldx bank
    cpx #4
    bne mainloop
exitloop
    lda #$0c    ; disable cart (supergames), your cart may vary, check crt.txt
    sta $df00
    cli
    jmp gameinit

blocklen byte $3f,$40,$40,$39
    rend
endreloc
    *=$8100
    byte 0 ; this is byte $0800, usually game prgs are at $0801
    incprg yourgame.prg
endofgame
    ds [endofcart-endofgame],$ff ; fill rest of the ROM with $ff
    *=$18000
endofcart

_________________
-=[]=--- iAN CooG/HVSC & C64Intros ---=[]=-
Back to top
View user's profile Send private message Send e-mail Visit poster's website
e5frog
Immortal Grandmaster of C64
Immortal Grandmaster of C64


Joined: 30 Apr 2009
Age: 38
Posts: 3465
Location: Sweden

PostPosted: Sat Mar 17, 2012 10:25 pm    Post subject: Reply with quote

I'm using an EasyFlash cart and the method I used works fine, just curious if it can be done faster. I'll take a look at that and see if I ever understand it fully...
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Commodore 64 (C64) Forum Index -> Help & Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Tip: Get C64 Forever for super-comfy C64 emulation with pre-installed games, demos and other goodies!


Powered by phpBB © 2001, 2005 phpBB Group