|
| 1 | +/** |
| 2 | + * @file mmu.asm |
| 3 | + * @brief Mmu module |
| 4 | + * @details Simple macros for the Commodore 128. |
| 5 | + * |
| 6 | + * @author Raffaele Intorcia raffaele.intorcia@gmail.com |
| 7 | + * |
| 8 | + * @copyright MIT License |
| 9 | + * Copyright (c) 2024 c128lib - https://github.com/c128lib |
| 10 | + * |
| 11 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | + * of this software and associated documentation files (the "Software"), to deal |
| 13 | + * in the Software without restriction, including without limitation the rights |
| 14 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | + * copies of the Software, and to permit persons to whom the Software is |
| 16 | + * furnished to do so, subject to the following conditions: |
| 17 | + * |
| 18 | + * The above copyright notice and this permission notice shall be included in all |
| 19 | + * copies or substantial portions of the Software. |
| 20 | + * |
| 21 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 27 | + * SOFTWARE. |
| 28 | + * |
| 29 | + * @date 2024 |
| 30 | + */ |
| 31 | + |
| 32 | +#importonce |
| 33 | + |
| 34 | +#import "labels/lib/mmu.asm" |
| 35 | + |
| 36 | +.filenamespace c128lib |
| 37 | + |
| 38 | +/** |
| 39 | + * @brief Macro for Mmu configuration. |
| 40 | + * |
| 41 | + * I/O block selection |
| 42 | + * |
| 43 | + * - Mmu.IO_ROM set I/O block visible on $D000-$DFFF |
| 44 | + * - Mmu.IO_RAM set area on $D000-$DFFF dependant from Mmu.ROM_HI selection |
| 45 | + * |
| 46 | + * If omitted, Mmu.IO_ROM will be used. |
| 47 | + * |
| 48 | + * Low-ram selection |
| 49 | + * |
| 50 | + * - Mmu.ROM_LOW_ROM set rom active for low BASIC ($4000-$7FFF) |
| 51 | + * - Mmu.ROM_LOW_RAM set ram active on $4000-$7FFF |
| 52 | + * |
| 53 | + * If omitted, Mmu.ROM_LOW_ROM will be used. |
| 54 | + * |
| 55 | + * Mid-ram selection |
| 56 | + * |
| 57 | + * - Mmu.ROM_MID_RAM set ram active on $8000-$AFFF and $B000-$BFFF |
| 58 | + * - Mmu.ROM_MID_EXT set external function ROM |
| 59 | + * - Mmu.ROM_MID_INT set internal function ROM |
| 60 | + * - Mmu.ROM_MID_ROM set rom active for BASIC ($8000-$AFFF) and monitor ($B000-$BFFF) |
| 61 | + * |
| 62 | + * If omitted, Mmu.ROM_MID_ROM will be used. |
| 63 | + * |
| 64 | + * Hi-ram selection |
| 65 | + * |
| 66 | + * - Mmu.ROM_HI_RAM set ram active on $C000-$CFFF, $D000-$DFFF and $E000-$FFFF |
| 67 | + * - Mmu.ROM_HI_EXT set external function ROM |
| 68 | + * - Mmu.ROM_HI_INT set internal function ROM |
| 69 | + * - Mmu.ROM_HI set rom active for Screen editor ($C000-$CFFF), character ($D000-$DFFF), Kernal ($E000-$FFFF) |
| 70 | + * |
| 71 | + * If omitted, Mmu.ROM_HI will be used. |
| 72 | + * |
| 73 | + * Bank selection |
| 74 | + * |
| 75 | + * - Mmu.RAM0 or Mmu.RAM1 can be used to set ram bank 0 or 1. If omitted, bank 0 will be selected. |
| 76 | + * |
| 77 | + * @param[in] config Values for Mmu confiuration |
| 78 | + * |
| 79 | + * @remark Register .A will be modified. |
| 80 | + * @remark Flags N and Z will be affected. |
| 81 | + * |
| 82 | + * @note Use c128lib_SetMMUConfiguration in mmu-global.asm |
| 83 | + * |
| 84 | + * @since 1.1.0 |
| 85 | + */ |
| 86 | +.macro SetMMUConfiguration(config) { |
| 87 | + lda #config |
| 88 | + sta Mmu.CONFIGURATION |
| 89 | +} |
| 90 | +.assert "SetMMUConfiguration(RAM1 | ROM_HI_RAM | ROM_MID_RAM | ROM_LOW_RAM | IO_RAM) sets accumulator to 7f", { SetMMUConfiguration(Mmu.RAM1 | Mmu.ROM_HI_RAM | Mmu.ROM_MID_RAM | Mmu.ROM_LOW_RAM | Mmu.IO_RAM) }, { |
| 91 | + lda #%01111111; sta $d500 |
| 92 | +} |
| 93 | + |
| 94 | +/** |
| 95 | + * @brief Macro for Mmu configuration. Uses $FF00 instead of $D500. |
| 96 | + * |
| 97 | + * I/O block selection |
| 98 | + * |
| 99 | + * - Mmu.IO_ROM set I/O block visible on $D000-$DFFF |
| 100 | + * - Mmu.IO_RAM set area on $D000-$DFFF dependant from Mmu.ROM_HI selection |
| 101 | + * |
| 102 | + * If omitted, Mmu.IO_ROM will be used. |
| 103 | + * |
| 104 | + * Low-ram selection |
| 105 | + * |
| 106 | + * - Mmu.ROM_LOW_ROM set rom active for low BASIC ($4000-$7FFF) |
| 107 | + * - Mmu.ROM_LOW_RAM set ram active on $4000-$7FFF |
| 108 | + * |
| 109 | + * If omitted, Mmu.ROM_LOW_ROM will be used. |
| 110 | + * |
| 111 | + * Mid-ram selection |
| 112 | + * |
| 113 | + * - Mmu.ROM_MID_RAM set ram active on $8000-$AFFF and $B000-$BFFF |
| 114 | + * - Mmu.ROM_MID_EXT set external function ROM |
| 115 | + * - Mmu.ROM_MID_INT set internal function ROM |
| 116 | + * - Mmu.ROM_MID_ROM set rom active for BASIC ($8000-$AFFF) and monitor ($B000-$BFFF) |
| 117 | + * |
| 118 | + * If omitted, Mmu.ROM_MID_ROM will be used. |
| 119 | + * |
| 120 | + * Hi-ram selection |
| 121 | + * |
| 122 | + * - Mmu.ROM_HI_RAM set ram active on $C000-$CFFF, $D000-$DFFF and $E000-$FFFF |
| 123 | + * - Mmu.ROM_HI_EXT set external function ROM |
| 124 | + * - Mmu.ROM_HI_INT set internal function ROM |
| 125 | + * - Mmu.ROM_HI set rom active for Screen editor ($C000-$CFFF), character ($D000-$DFFF), Kernal ($E000-$FFFF) |
| 126 | + * |
| 127 | + * If omitted, Mmu.ROM_HI will be used. |
| 128 | + * |
| 129 | + * Bank selection |
| 130 | + * |
| 131 | + * - Mmu.RAM0 or Mmu.RAM1 can be used to set ram bank 0 or 1. If omitted, bank 0 will be selected. |
| 132 | + * |
| 133 | + * @param[in] config Values for Mmu confiuration |
| 134 | + * |
| 135 | + * @remark Register .A will be modified. |
| 136 | + * @remark Flags N and Z will be affected. |
| 137 | + * |
| 138 | + * @note Use SetMMULoadConfiguration in mmu-global.asm |
| 139 | + * |
| 140 | + * @since 1.1.0 |
| 141 | + */ |
| 142 | +.macro SetMMULoadConfiguration(config) { |
| 143 | + lda #config |
| 144 | + sta Mmu.LOAD_CONFIGURATION |
| 145 | +} |
| 146 | +.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) }, { |
| 147 | + lda #%01111111; sta $ff00 |
| 148 | +} |
0 commit comments