Skip to content

Commit 14e6241

Browse files
authored
Merge pull request #12 from c128lib/5+
Added SetVicBank
2 parents 0451428 + 2726827 commit 14e6241

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

lib/cia-global.asm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,17 @@
7676
*/
7777
.macro @c128lib_DisableCIAInterrupts() { DisableCIAInterrupts() }
7878

79+
/**
80+
* @brief Configures Vic bank (16K) which is directly addressable by VIC2 chip.
81+
*
82+
* @param[in] bank Bank to set
83+
*
84+
* @remark Register .A will be modified.
85+
* @remark Flags N, Z and C will be affected.
86+
*
87+
* @note Bank parameter can be filled with Cia.BANK_0, Cia.BANK_1, Cia.BANK_2, Cia.BANK_3
88+
* @note BANK_0 $0000-$3FFF, BANK_1 $4000-$7FFF, BANK_2 $8000-$BFFF, BANK_3 $C000-$FFFF
89+
*
90+
* @since 1.2.0
91+
*/
92+
.macro c128lib_SetVicBank(bank) { SetVicBank(bank) }

lib/cia.asm

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
/**
7777
* @brief Disables the interrupts from both CIA chips.
7878
*
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,
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,
8080
* 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.
8181
*
8282
* @remark Register .A will be modified.
@@ -92,4 +92,38 @@
9292
sta Cia.CIA2_IRQ_CONTROL
9393
lda Cia.CIA1_IRQ_CONTROL
9494
lda Cia.CIA2_IRQ_CONTROL
95-
}
95+
}
96+
97+
/**
98+
* @brief Configures Vic bank (16K) which is directly addressable by VIC2 chip.
99+
*
100+
* @param[in] bank Bank to set
101+
*
102+
* @remark Register .A will be modified.
103+
* @remark Flags N, Z and C will be affected.
104+
*
105+
* @note Bank parameter can be filled with Cia.BANK_0, Cia.BANK_1, Cia.BANK_2, Cia.BANK_3
106+
* @note BANK_0 $0000-$3FFF, BANK_1 $4000-$7FFF, BANK_2 $8000-$BFFF, BANK_3 $C000-$FFFF
107+
*
108+
* @note Use c128lib_SetVicBank in cia-global.asm
109+
*
110+
* @since 1.2.0
111+
*/
112+
.macro SetVicBank(bank) {
113+
lda Cia.CIA2_DATA_PORT_A
114+
and #%11111100
115+
ora #[bank & %00000011]
116+
sta Cia.CIA2_DATA_PORT_A
117+
}
118+
.assert "SetVicBank(BANK_0) sets 11", { SetVicBank(Cia.BANK_0) }, {
119+
lda $DD00
120+
and #%11111100
121+
ora #%00000011
122+
sta $DD00
123+
}
124+
.assert "SetVicBank(BANK_3) sets 00", { SetVicBank(Cia.BANK_3) }, {
125+
lda $DD00
126+
and #%11111100
127+
ora #%00000000
128+
sta $DD00
129+
}

0 commit comments

Comments
 (0)