Skip to content

Commit c43487c

Browse files
committed
Updated Cia and started Mmu (wip)
1 parent 2d5abf2 commit c43487c

5 files changed

Lines changed: 316 additions & 1 deletion

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ retroProject {
1515

1616
viceExecutable = 'x128'
1717

18-
libFromGitHub "c128lib/labels", "0.1.0"
18+
libFromGitHub "c128lib/labels", "0.2.0"
1919
libFromGitHub "c128lib/128spec", "0.7.2"
2020
}

lib/cia-global.asm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,17 @@
6262
* @since 1.0.0
6363
*/
6464
.macro c128lib_GetFirePressedPort2() { GetFirePressedPort2() }
65+
66+
/**
67+
* @brief Disables the interrupts from both CIA chips.
68+
*
69+
* This macro disables the interrupts from both CIA chips on a Commodore 64. It loads the accumulator with the value $7F, which disables all interrupt sources,
70+
* and then stores this value in the IRQ control registers of both CIA chips. It then reads the IRQ control registers to confirm the changes.
71+
*
72+
* @remark Register .A will be modified.
73+
* @remark Flags N and Z will be affected.
74+
*
75+
* @since 1.1.0
76+
*/
77+
.macro c128lib_DisableCIAInterrupts() { DisableCIAInterrupts() }
78+

lib/cia.asm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,24 @@
7272
lda Cia.CIA1_DATA_PORT_A
7373
and #Cia.JOY_FIRE
7474
}
75+
76+
/**
77+
* @brief Disables the interrupts from both CIA chips.
78+
*
79+
* This macro disables the interrupts from both CIA chips on a Commodore 64. It loads the accumulator with the value $7F, which disables all interrupt sources,
80+
* and then stores this value in the IRQ control registers of both CIA chips. It then reads the IRQ control registers to confirm the changes.
81+
*
82+
* @remark Register .A will be modified.
83+
* @remark Flags N and Z will be affected.
84+
*
85+
* @note Use c128lib_GetFirePressedPort2 in cia-global.asm
86+
*
87+
* @since 1.1.0
88+
*/
89+
.macro DisableCIAInterrupts() {
90+
lda #$7f
91+
sta Cia.CIA1_IRQ_CONTROL
92+
sta Cia.CIA2_IRQ_CONTROL
93+
lda Cia.CIA1_IRQ_CONTROL
94+
lda Cia.CIA2_IRQ_CONTROL
95+
}

lib/mmu-global.asm

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/**
2+
* @file mmu-global.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 "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+
* @since 1.1.0
83+
*/
84+
.macro c128lib_SetMMUConfiguration(config) { SetMMUConfiguration(config) }
85+
86+
/**
87+
* @brief Macro for Mmu configuration. Uses $FF00 instead of $D500.
88+
*
89+
* I/O block selection
90+
*
91+
* - Mmu.IO_ROM set I/O block visible on $D000-$DFFF
92+
* - Mmu.IO_RAM set area on $D000-$DFFF dependant from Mmu.ROM_HI selection
93+
*
94+
* If omitted, Mmu.IO_ROM will be used.
95+
*
96+
* Low-ram selection
97+
*
98+
* - Mmu.ROM_LOW_ROM set rom active for low BASIC ($4000-$7FFF)
99+
* - Mmu.ROM_LOW_RAM set ram active on $4000-$7FFF
100+
*
101+
* If omitted, Mmu.ROM_LOW_ROM will be used.
102+
*
103+
* Mid-ram selection
104+
*
105+
* - Mmu.ROM_MID_RAM set ram active on $8000-$AFFF and $B000-$BFFF
106+
* - Mmu.ROM_MID_EXT set external function ROM
107+
* - Mmu.ROM_MID_INT set internal function ROM
108+
* - Mmu.ROM_MID_ROM set rom active for BASIC ($8000-$AFFF) and monitor ($B000-$BFFF)
109+
*
110+
* If omitted, Mmu.ROM_MID_ROM will be used.
111+
*
112+
* Hi-ram selection
113+
*
114+
* - Mmu.ROM_HI_RAM set ram active on $C000-$CFFF, $D000-$DFFF and $E000-$FFFF
115+
* - Mmu.ROM_HI_EXT set external function ROM
116+
* - Mmu.ROM_HI_INT set internal function ROM
117+
* - Mmu.ROM_HI set rom active for Screen editor ($C000-$CFFF), character ($D000-$DFFF), Kernal ($E000-$FFFF)
118+
*
119+
* If omitted, Mmu.ROM_HI will be used.
120+
*
121+
* Bank selection
122+
*
123+
* - Mmu.RAM0 or Mmu.RAM1 can be used to set ram bank 0 or 1. If omitted, bank 0 will be selected.
124+
*
125+
* @remark Register .A will be modified.
126+
* @remark Flags N and Z will be affected.
127+
*
128+
* @note Use SetMMULoadConfiguration in mmu-global.asm
129+
*
130+
* @since 1.1.0
131+
*/
132+
.macro c128lib_SetMMULoadConfiguration(config) { SetMMULoadConfiguration(config) }

lib/mmu.asm

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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

Comments
 (0)