Assembly Language - Copy Full Pages of Data

From NerdConsole
Jump to navigationJump to search
; Purpose: This routine copies some number of full 256-byte 
;          pages from somewhere to somewhere else.
; For: NerdConsole (65C02 Assembly, ca65 format)
; By: David Stephens (NerdOfEpic)
; License: Public Domain - Can be used or modified by anyone 
;                          for any purpose.


; Parameters 
CopySource     = $F0 ; Set $F1 (not $F0!) to the source page
CopyDest       = $F2 ; Set $F3 (not $F2!) to the dest page
CopyPages      = $F4 ; Set to the number of pages to copy
                     ; Cannot copy 0 pages, set to 1+

CopyFullPages:
	; Save state so we can put it back at the end
	php
	pha
	txa
	pha
	tya
	pha
	
	; Clear the low bytes of source and dest
	stz CopySource
	stz CopyDest
	ldy #$00

CopyCurrentPage:
	lda (CopySource),y
	sta (CopyDest),y
	iny
	bne CopyCurrentPage	
	
	; Done with a page, do we need to do another one?
	dec CopyPages
	beq CopyFullPagesDone
	inc CopySource+1
	inc CopyDest+1
	bra CopyCurrentPage	
		
CopyFullPagesDone:
	; Restore the state
	pla
	tay
	pla
	tax
	pla
	plp
	
	; All done
	rts

Back to the list of Assembly Language files.