|
77 | 77 | * |
78 | 78 | * @param[in] source The starting address of the memory block to be copied. |
79 | 79 | * @param[in] destination The starting address of the location where the memory block will be copied to. |
80 | | - * @param[in] count The number of bytes to be copied. |
81 | 80 | * |
82 | | - * @remark Registers .A, .X, and .Y will be modified. |
| 81 | + * @remark Registers .A and .X will be modified. |
83 | 82 | * @remark Flags N and Z will be affected. |
84 | 83 | * @remark Zeropage location $fe will be used. |
| 84 | + * @remark During copy, interrupts are disabled. |
85 | 85 | * |
86 | | - * @note Usage: CopyWithRelocation($C000, $C100, 256) // Copies 256 bytes from memory location $C000 to $C100 with relocation |
| 86 | + * @note Usage: CopyWithRelocation($C000, $C100) // Copies 256 bytes from memory location $C000 to $C100 with relocation |
| 87 | + * @note The number of bytes that can be copied is always 256. |
| 88 | + * @note Source and destination less significant byte should be $00. Any |
| 89 | + * different value will be ignored. |
87 | 90 | * @note Use c128lib_CopyWithRelocation in mem-global.asm |
88 | 91 | * |
89 | 92 | * @since 1.0.0 |
90 | 93 | */ |
91 | | -.macro CopyWithRelocation(source, destination, count) { |
| 94 | +.macro CopyWithRelocation(source, destination) { |
92 | 95 | .label TEMP = $fe |
93 | 96 | sei |
| 97 | + ldx #>source // Preparing self mod code |
94 | 98 | stx !+ + 2 |
95 | | - tsx |
| 99 | + tsx // Save current stack pointer |
96 | 100 | stx TEMP |
97 | | - sty Mmu.PAGE1_PAGE_POINTER |
| 101 | + ldx #>destination |
| 102 | + stx Mmu.PAGE1_PAGE_POINTER |
98 | 103 |
|
99 | 104 | ldx #0 |
100 | 105 | txs |
101 | | -!: lda Mmu.LOAD_CONFIGURATION,x |
| 106 | +!: lda $FF00,x // Placeholder for self mod code |
102 | 107 | pha |
103 | 108 | dex |
104 | 109 | bne !- |
105 | 110 |
|
106 | | - ldx #1 |
| 111 | + // .X contains 0 because bne didn't jump to the start of the loop |
| 112 | + inx // Setting back stack page to 1 |
107 | 113 | stx Mmu.PAGE1_PAGE_POINTER |
108 | 114 | ldx TEMP |
109 | | - txs |
| 115 | + txs // Setting stack pointer to previous value |
110 | 116 | cli |
111 | 117 | rts |
112 | 118 | } |
|
0 commit comments