Skip to content

Commit fd05947

Browse files
authored
Merge pull request #10 from c128lib/intoinside/issue1
Intoinside/issue1
2 parents 88c5ac8 + 7074868 commit fd05947

2 files changed

Lines changed: 167 additions & 2 deletions

File tree

lib/mmu-global.asm

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,53 @@
130130
* @since 1.1.0
131131
*/
132132
.macro @c128lib_SetMMULoadConfiguration(config) { SetMMULoadConfiguration(config) }
133+
134+
/**
135+
* @brief Set banking. Only main banking are available.
136+
*
137+
* @param[in] config Values for Mmu confiuration
138+
*
139+
* @remark Register .A will be modified.
140+
* @remark Flags N and Z will be affected.
141+
*
142+
* @note Use Basic banking, see reference https://c128lib.github.io/Reference/MemoryMap
143+
* Only banking 0, 1, 4, 5, 12, 13, 14 and 15 are supported.
144+
*
145+
* @since 1.2.0
146+
*/
147+
.macro @c128lib_SetBankConfiguration(id) { SetBankConfiguration(id) }
148+
149+
/**
150+
* @brief Set mode configuration register.
151+
*
152+
* @param[in] config Values for configuration register
153+
*
154+
* @note Config parameter can be filled with Mmu.CPU_*, Mmu.FASTSERIAL*, Mmu.GAME_*, Mmu.EXROM_*, Mmu.KERNAL_*, Mmu.COLS_*
155+
*
156+
* @remark Register .A will be modified.
157+
* @remark Flags N and Z will be affected.
158+
*
159+
* @since 1.2.0
160+
*/
161+
.macro c128lib_SetModeConfig(config) { SetModeConfig(config) }
162+
163+
/**
164+
* @brief Configure common RAM amount.
165+
*
166+
* RAM Bank 0 is always the visible RAM bank.
167+
* Valid values are 1,4,8 and 16.
168+
* For ex. if you choose 4K common ram at top and bottom
169+
* you'll have 4K up and 4K bottom.
170+
*
171+
* @param[in] config Values for common ram configuration
172+
*
173+
* @remark Register .A will be modified.
174+
* @remark Flags N and Z will be affected.
175+
*
176+
* @note Config parameter can be filled with Mmu.COMMON_RAM_*
177+
*
178+
* @note Use c128lib_SetCommonRAM in mmu-global.asm
179+
*
180+
* @since 1.2.0
181+
*/
182+
.macro c128lib_SetCommonRAM(config) { SetCommonRAM(config) }

lib/mmu.asm

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@
135135
* @remark Register .A will be modified.
136136
* @remark Flags N and Z will be affected.
137137
*
138-
* @note Use SetMMULoadConfiguration in mmu-global.asm
139-
*
140138
* @since 1.1.0
141139
*/
142140
.macro SetMMULoadConfiguration(config) {
@@ -146,3 +144,120 @@
146144
.assert "SetMMULoadConfiguration(RAM1 | ROM_HI_RAM | ROM_MID_RAM | ROM_LOW_RAM | IO_RAM) sets accumulator to 7f", { SetMMULoadConfiguration(Mmu.RAM1 | Mmu.ROM_HI_RAM | Mmu.ROM_MID_RAM | Mmu.ROM_LOW_RAM | Mmu.IO_RAM) }, {
147145
lda #%01111111; sta $ff00
148146
}
147+
148+
/**
149+
* @brief Set banking. Only main banking are available.
150+
*
151+
* @param[in] config Values for Mmu confiuration
152+
*
153+
* @remark Register .A will be modified.
154+
* @remark Flags N and Z will be affected.
155+
*
156+
* @note Use Basic banking, see reference https://c128lib.github.io/Reference/MemoryMap
157+
* Only banking 0, 1, 4, 5, 12, 13, 14 and 15 are supported.
158+
*
159+
* @note Use c128lib_SetBankConfiguration in mmu-global.asm
160+
*
161+
* @since 1.2.0
162+
*/
163+
.macro SetBankConfiguration(id) {
164+
.if (id==0) {
165+
SetMMULoadConfiguration(Mmu.RAM0 | Mmu.ROM_HI_RAM | Mmu.ROM_MID_RAM | Mmu.ROM_LOW_RAM | Mmu.IO_RAM)
166+
}
167+
.if (id==1) {
168+
SetMMULoadConfiguration(Mmu.RAM1 | Mmu.ROM_HI_RAM | Mmu.ROM_MID_RAM | Mmu.ROM_LOW_RAM | Mmu.IO_RAM)
169+
}
170+
.if (id==4) {
171+
SetMMULoadConfiguration(Mmu.RAM0 | Mmu.ROM_HI_INT | Mmu.ROM_MID_INT | Mmu.ROM_LOW_RAM | Mmu.IO_ROM)
172+
}
173+
.if (id==5) {
174+
SetMMULoadConfiguration(Mmu.RAM1 | Mmu.ROM_HI_INT | Mmu.ROM_MID_INT | Mmu.ROM_LOW_RAM | Mmu.IO_ROM)
175+
}
176+
.if (id==12) {
177+
SetMMULoadConfiguration(Mmu.RAM0 | Mmu.ROM_HI | Mmu.ROM_MID_INT | Mmu.ROM_LOW_RAM | Mmu.IO_ROM)
178+
}
179+
.if (id==13) {
180+
SetMMULoadConfiguration(Mmu.RAM0 | Mmu.ROM_HI | Mmu.ROM_MID_EXT | Mmu.ROM_LOW_RAM | Mmu.IO_ROM)
181+
}
182+
.if (id==14) {
183+
SetMMULoadConfiguration(Mmu.RAM0 | Mmu.ROM_HI | Mmu.ROM_MID_ROM | Mmu.ROM_LOW_ROM | Mmu.IO_RAM)
184+
}
185+
.if (id==15) {
186+
SetMMULoadConfiguration(Mmu.RAM0 | Mmu.ROM_HI | Mmu.ROM_MID_ROM | Mmu.ROM_LOW_ROM | Mmu.IO_ROM)
187+
}
188+
}
189+
.assert "SetBankConfiguration(0)", { SetBankConfiguration(0) }, {
190+
lda #%00111111; sta $ff00
191+
}
192+
.assert "SetBankConfiguration(1)", { SetBankConfiguration(1) }, {
193+
lda #%01111111; sta $ff00
194+
}
195+
.assert "SetBankConfiguration(4)", { SetBankConfiguration(4) }, {
196+
lda #%00010110; sta $ff00
197+
}
198+
.assert "SetBankConfiguration(5)", { SetBankConfiguration(5) }, {
199+
lda #%01010110; sta $ff00
200+
}
201+
.assert "SetBankConfiguration(12)", { SetBankConfiguration(12) }, {
202+
lda #%00000110; sta $ff00
203+
}
204+
.assert "SetBankConfiguration(13)", { SetBankConfiguration(13) }, {
205+
lda #%00001010; sta $ff00
206+
}
207+
.assert "SetBankConfiguration(14)", { SetBankConfiguration(14) }, {
208+
lda #%00000001; sta $ff00
209+
}
210+
.assert "SetBankConfiguration(15)", { SetBankConfiguration(15) }, {
211+
lda #%00000000; sta $ff00
212+
}
213+
214+
/**
215+
* @brief Set mode configuration register.
216+
*
217+
* @param[in] config Values for configuration register
218+
*
219+
* @note Config parameter can be filled with Mmu.CPU_*, Mmu.FASTSERIAL*, Mmu.GAME_*, Mmu.EXROM_*, Mmu.KERNAL_*, Mmu.COLS_*
220+
*
221+
* @remark Register .A will be modified.
222+
* @remark Flags N and Z will be affected.
223+
*
224+
* @note Use c128lib_SetModeConfig in mmu-global.asm
225+
*
226+
* @since 1.2.0
227+
*/
228+
.macro SetModeConfig(config) {
229+
lda #config
230+
sta Mmu.MODE_CONFIG
231+
}
232+
.assert "SetModeConfig(CPU_8502 | FASTSERIALOUTPUT | GAME_HI | EXROM_HI | KERNAL_64 | COLS_40) sets accumulator to 0f", {
233+
SetModeConfig(Mmu.CPU_8502 | Mmu.FASTSERIALOUTPUT | Mmu.GAME_HI | Mmu.EXROM_HI | Mmu.KERNAL_64 | Mmu.COLS_40)
234+
}, {
235+
lda #%11111001; sta $d505
236+
}
237+
238+
/**
239+
* @brief Configure common RAM amount.
240+
*
241+
* RAM Bank 0 is always the visible RAM bank.
242+
* Valid values are 1,4,8 and 16.
243+
* For ex. if you choose 4K common ram at top and bottom
244+
* you'll have 4K up and 4K bottom.
245+
*
246+
* @param[in] config Values for common ram configuration
247+
*
248+
* @remark Register .A will be modified.
249+
* @remark Flags N and Z will be affected.
250+
*
251+
* @note Config parameter can be filled with Mmu.COMMON_RAM_*
252+
*
253+
* @note Use c128lib_SetCommonRAM in mmu-global.asm
254+
*
255+
* @since 1.2.0
256+
*/
257+
.macro SetCommonRAM(config) {
258+
lda #config
259+
sta Mmu.RAM_CONFIG
260+
}
261+
.assert "SetCommonRAM(COMMON_RAM_16K | COMMON_RAM_BOTH) sets accumulator to 0f", { SetCommonRAM(Mmu.COMMON_RAM_16K | Mmu.COMMON_RAM_BOTH) }, {
262+
lda #%00001111; sta $d506
263+
}

0 commit comments

Comments
 (0)