|
32 | 32 | #importonce |
33 | 33 |
|
34 | 34 | #import "labels/lib/mmu.asm" |
| 35 | +#import "labels/lib/zeropage.asm" |
35 | 36 |
|
36 | 37 | .filenamespace c128lib |
37 | 38 |
|
|
80 | 81 | * |
81 | 82 | * @remark Registers .A and .X will be modified. |
82 | 83 | * @remark Flags N and Z will be affected. |
83 | | - * @remark Zeropage location $fe will be used. |
| 84 | + * @remark Zeropage location $FE will be used. |
84 | 85 | * @remark During copy, interrupts are disabled. |
85 | 86 | * |
86 | 87 | * @note Usage: CopyWithRelocation($C000, $C100) // Copies 256 bytes from memory location $C000 to $C100 with relocation |
|
92 | 93 | * @since 1.0.0 |
93 | 94 | */ |
94 | 95 | .macro CopyWithRelocation(source, destination) { |
95 | | - .label TEMP = $fe |
96 | 96 | sei |
97 | 97 | ldx #>source // Preparing self mod code |
98 | 98 | stx !+ + 2 |
99 | 99 | tsx // Save current stack pointer |
100 | | - stx TEMP |
| 100 | + stx Zeropage.FE |
101 | 101 | ldx #>destination |
102 | 102 | stx Mmu.PAGE1_PAGE_POINTER |
103 | 103 |
|
|
111 | 111 | // .X contains 0 because bne didn't jump to the start of the loop |
112 | 112 | inx // Setting back stack page to 1 |
113 | 113 | stx Mmu.PAGE1_PAGE_POINTER |
114 | | - ldx TEMP |
| 114 | + ldx Zeropage.FE |
115 | 115 | txs // Setting stack pointer to previous value |
116 | 116 | cli |
117 | | - rts |
| 117 | +} |
| 118 | + |
| 119 | +/** |
| 120 | + * @brief This macro copies a block of memory from one location to another using page relocation |
| 121 | + * with bank selection. |
| 122 | + * |
| 123 | + * @details This macro also handles the page relocation of the memory block during the copy operation. |
| 124 | + * It's slower than @sa CopyFast but it uses much less memory, especially for large memory blocks copy. |
| 125 | + * This version allows to specify the bank for source and destination memory locations. |
| 126 | + * |
| 127 | + * @param[in] source The starting address of the memory block to be copied. |
| 128 | + * @param[in] sourceBank Bank of the starting address. |
| 129 | + * @param[in] destination The starting address of the location where the memory block will be copied to. |
| 130 | + * @param[in] destinationBank Bank of the destination address. |
| 131 | + * |
| 132 | + * @remark Registers .A and .X will be modified. |
| 133 | + * @remark Flags N and Z will be affected. |
| 134 | + * @remark Zeropage location $FE will be used. |
| 135 | + * @remark During copy, interrupts are disabled. |
| 136 | + * |
| 137 | + * @note The number of bytes that can be copied is always 256. |
| 138 | + * @note Source and destination less significant byte should be $00. Any |
| 139 | + * different value will be ignored. |
| 140 | + * @note Use c128lib_CopyWithRelocationWithBank in mem-global.asm |
| 141 | + * |
| 142 | + * @since 1.2.0 |
| 143 | + */ |
| 144 | +.macro CopyWithRelocationWithBank(source, sourceBank, destination, destinationBank) { |
| 145 | + sei |
| 146 | + ldx #>source // Preparing self mod code |
| 147 | + stx !+ + 2 |
| 148 | + tsx // Save current stack pointer |
| 149 | + |
| 150 | + lda Mmu.PAGE0_BLOCK_POINTER |
| 151 | + pha |
| 152 | + lda sourceBank |
| 153 | + sta Mmu.PAGE0_BLOCK_POINTER |
| 154 | + |
| 155 | + lda Mmu.PAGE1_BLOCK_POINTER |
| 156 | + pha |
| 157 | + lda destinationBank |
| 158 | + sta Mmu.PAGE1_BLOCK_POINTER |
| 159 | + |
| 160 | + stx Zeropage.FE |
| 161 | + ldx #>destination |
| 162 | + stx Mmu.PAGE1_PAGE_POINTER |
| 163 | + |
| 164 | + ldx #0 |
| 165 | + txs |
| 166 | +!: lda $FF00,x // Placeholder for self mod code |
| 167 | + pha |
| 168 | + dex |
| 169 | + bne !- |
| 170 | + |
| 171 | + // .X contains 0 because bne didn't jump to the start of the loop |
| 172 | + inx // Setting back stack page to 1 |
| 173 | + stx Mmu.PAGE1_PAGE_POINTER |
| 174 | + ldx Zeropage.FE |
| 175 | + txs // Setting stack pointer to previous value |
| 176 | + |
| 177 | + pla |
| 178 | + sta Mmu.PAGE1_BLOCK_POINTER |
| 179 | + |
| 180 | + pla |
| 181 | + sta Mmu.PAGE0_BLOCK_POINTER |
| 182 | + |
| 183 | + cli |
118 | 184 | } |
119 | 185 |
|
120 | 186 | /** |
|
0 commit comments