6502-OS/programs/memcopy.s65

66 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2023-11-10 00:55:03 +01:00
.ifndef INCLUDE_MEMCOPY
INCLUDE_MEMCOPY = 1
2023-12-08 22:56:35 +01:00
.include "system.h65"
2023-11-10 00:55:03 +01:00
2023-12-27 16:55:40 +01:00
.export memcopy,memcopy16
2023-12-20 12:27:54 +01:00
2023-12-08 22:56:35 +01:00
.code
2023-12-27 16:55:40 +01:00
;;********************************************************************************
;; @function Copy a block of memory to a different address
;; @param ARG0-1: Source address
;; @param ARG2-3: Target address
;; @param Y: Number of bytes to copy
2024-08-08 20:39:25 +02:00
;; @modifies A,Y
2023-12-27 16:55:40 +01:00
;;********************************************************************************
2023-11-10 00:55:03 +01:00
.proc memcopy
2023-12-08 22:56:35 +01:00
cpy #0
2023-12-20 12:27:54 +01:00
beq @rts
@copy_byte:
dey
2023-12-08 00:03:29 +01:00
lda (ARG0),y
sta (ARG2),y
2023-12-20 12:27:54 +01:00
cpy #0
bne @copy_byte
@rts:
2023-11-10 00:55:03 +01:00
rts
2023-12-08 22:56:35 +01:00
.endproc
2023-12-27 16:55:40 +01:00
;;********************************************************************************
;; @function Copy a block of memory to a different address
;; @param ARG0-1: Source address
;; @param ARG2-3: Target address
;; @param ARG5-6: Number of bytes to copy (LE)
2024-08-08 20:39:25 +02:00
;; @modifies A,Y
2023-12-27 16:55:40 +01:00
;;********************************************************************************
.proc memcopy16
lda ARG6
beq @last_page ; no full page
ldy #$ff
bra @copy_byte
@next_page: ; y is 0
lda ARG6
beq @rts ; done
inc ARG1
inc ARG3
dec ARG6
beq @last_page
ldy #$ff
@copy_byte:
lda (ARG0),y
sta (ARG2),y
@dec_y:
dey
beq @next_page
bra @copy_byte
@last_page:
ldy ARG5
dey
bra @copy_byte
@rts:
rts
.endproc
2023-11-10 00:55:03 +01:00
.endif ; guard