Blitz3D+ Command Reference

CopyBank src_bank,src_offset,dest_bank,dest_offset,count

Parameters

src_bank - bank to copy from

src_offset - offset in the source bank of the first byte to copy

dest_bank - bank to copy to

dest_offset - offset in the destination bank where the bytes land

count - number of bytes to copy

Description

Copies a block of bytes from one bank to another.

One fast call moves the whole block - use it to assemble packets from pieces, duplicate a structure, or shuffle records around inside a save image. Source and destination can be the same bank, and overlapping ranges are handled safely, so sliding data up or down a bank works fine.

Both ranges must fit inside their banks or a runtime error is raised.

See also: CreateBank, BankSize, PeekByte, PokeByte.

Example

; CopyBank Example
; ----------------

; A player save record packed into an 11 byte bank:
; flags (byte=1) + hp (short=2) + score (int=4) + x_pos (float=4)
save=CreateBank(11)
PokeByte save,0,5
PokeShort save,1,250
PokeInt save,3,1234567
PokeFloat save,7,17.25

Print "Checkpoint reached: hp = "+PeekShort(save,1)+"   score = "+PeekInt(save,3)

; Take a checkpoint - CopyBank copies all 11 bytes into a backup bank
backup=CreateBank(11)
CopyBank save,0,backup,0,11
Print "Record backed up with CopyBank"

; Disaster strikes - the live record gets trashed
PokeShort save,1,10
PokeInt save,3,0
Print ""
Print "After taking damage: hp = "+PeekShort(save,1)+"   score = "+PeekInt(save,3)

; Restore the checkpoint - copy the backup over the live record
CopyBank backup,0,save,0,11
Print ""
Print "Restored from backup: hp = "+PeekShort(save,1)+"   score = "+PeekInt(save,3)

FreeBank backup
FreeBank save

Print ""
Print "Press any key to close the example"
WaitKey

End

Index