.export _copyxdata .import __XDATA_LOAD__, __XDATA_RUN__, __XDATA_SIZE__ .importzp ptr1, ptr2, tmp1 .code _copyxdata: lda #<__XDATA_LOAD__ ; Source pointer sta ptr1 lda #>__XDATA_LOAD__ sta ptr1+1 lda #<__XDATA_RUN__ ; Target pointer sta ptr2 lda #>__XDATA_RUN__ ora #$04 ; write port sta ptr2+1 ldx #<~__XDATA_SIZE__ lda #>~__XDATA_SIZE__ ; Use -(__DATASIZE__+1) sta tmp1 ldy #$00 ; Copy loop @L1: inx beq @L3 @L2: lda #0 sta $3F ; select ROM0 lda (ptr1),y pha lda #0 sta $3E ; select RAM0 pla sta (ptr2),y iny bne @L1 inc ptr1+1 inc ptr2+1 ; Bump pointers bne @L1 ; Branch always (hopefully) ; Bump the high counter byte @L3: inc tmp1 bne @L2 ; Done lda #0 sta $3F ; select ROM0 rts