Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Moving Memory
2010-06-16 17:06
MisterMSK
Account closed

Registered: Jul 2009
Posts: 37
Moving Memory

Hi All,

Just working on another project. I am trying to take something that loads in $6000, move it to a lower memory address, then JMP to it. I assume it has to do with the SIZE.


!to "testprog.prg",cbm
*=$0801
; BASIC stub: "1 SYS 2061"
!by $0b,$08,$01,$00,$9e,$32,$30,$36,$31,$00,$00,$00

FROM = $6000
TO = $801
SIZE = 2913

MOVEDOWN LDY #0
LDX SIZEH
BEQ MD2
MD1 LDA (FROM),Y ; move a page at a time
STA (TO),Y
INY
BNE MD1
INC FROM+1
INC TO+1
DEX
BNE MD1
MD2 LDX SIZEL
BEQ MD4
MD3 LDA (FROM),Y ; move the remaining bytes
STA (TO),Y
INY
DEX
BNE MD3
MD4 RTS

JMP $80D

* = $6000
!binary "import.prg",,0
2010-06-16 17:18
Peiselulli

Registered: Oct 2006
Posts: 81
Some points are wrong:
1) You overwrite your own code (TO = $0801)
2) lda (FROM),y is similar to LDA FROM,y, I think you want use zeropage pointers instead. Another option is selfmodifying code.
2010-06-16 17:23
Moloch

Registered: Jan 2002
Posts: 2928
Something simple like a "transfer routine" used with intros or demo pages would probably work here. Here is a copy of one of my ancient sources ... something to tinker with if you want. Some of setup code probably isn't needed for your application.

TRANSFER SEI
LDA #$31
STA $0314
LDA #$EA
STA $0315
LDA #$00
STA $D01A
STA $D418
LDA #$81
STA $DC0D
CLI
JSR $FF81
LDX #$00
LOOPA LDA ROUT1,X
STA $0400,X
INX
BNE LOOPA
LDA #$00
STA $0800
JMP $0400
ROUT1 SEI
LDA #$34
STA $01
ROUT3 LDX #$00
ROUT2 LDA $6000,X
STA $0801,X
INX
BNE ROUT2
INC $0409
INC $040C
LDA $0409
BNE ROUT3
LDA #$37
STA $01
CLI
JSR $A659
JMP $A7AE

---
Crimson Twilight Dev Updates [C64 CRPG]
2010-06-17 08:21
Pantaloon

Registered: Aug 2003
Posts: 124
memcpy kickasm macro (can probably be optimized if speed is what you want).


.macro memcpy(dest,source,bytesToCopy)
{
lda #<source
sta load1+1
lda #>source
sta load1+2

lda #<dest
sta store1+1
lda #>dest
sta store1+2

// copy pages
ldx #>bytesToCopy
beq copyBytes
copyPage:
ldy #$00
!:
load1:
lda $0000,y
store1:
sta $0000,y
dey
bne !-
inc load1+2
inc store1+2
dex
bne copyPage
copyBytes:
ldy #<bytesToCopy
beq copyDone

lda load1+1
sta load2+1
lda load1+2
sta load2+2

lda store1+1
sta store2+1
lda store1+2
sta store2+2

ldy #$00
!:
load2:
lda $0000,y
store2:
sta $0000,y
iny
cpy #<bytesToCopy
bne !-
copyDone:
}
2010-06-17 08:32
Frantic

Registered: Mar 2003
Posts: 1648
Then again, in 99% of the cases there is no reason to duplicate the mem-transfer routine itself in memory by using a macro like this, so one would probably want to make a separate macro for the setup part of the code (invoked once for every different call to the mem transfer routine), and one for the transfer routine itself (invoked only once).
2010-06-17 08:48
Pantaloon

Registered: Aug 2003
Posts: 124
it all depends on what you are doing.
2010-06-17 09:19
daison

Registered: May 2005
Posts: 90
I use the pseudo-pc option in KickAsm, it's kind of an elegant way to be sure all jumps/branches are referring to the correct address after copying the routine itsself.



.pc = $0c00 "Copy routine"
//------------------------------------------------------------------------------ ---------------
//COPY ROUTINE
// - The following code will be moved to $0400 to safely copy everything up from $8000 to $ffff
//------------------------------------------------------------------------------ ---------------
copy_ram:
//pseudo to be prepared to be moved to $0400
.pseudopc $0400 {
//copy mem
ldy #0
!loop:
ldx #0
!read:
lda $8000,x
!store:
sta $0800,x
inx
bne !read-
inc !read-+2
inc !store-+2
inc $d020
iny
cpy #80 //nr of blocks to copy
bne !loop-

jmp $0800
}
//------------------------------------------------------------------------------ ------------
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Jazzcat/Onslaught
E$G/HF ⭐ 7
ΛΛdZ
iAN CooG/HVSC
LightSide
Acidchild/Padua
Guests online: 135
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Diskmag Editors
1 Magic  (9.8)
2 hedning  (9.6)
3 Jazzcat  (9.5)
4 Elwix  (9.1)
5 Remix  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.041 sec.