mirror of
https://github.com/irmen/prog8.git
synced 2024-09-10 09:54:32 +00:00
added cx16.push_vera_context() and cx16.pop_vera_context() for use in irq handlers
This commit is contained in:
parent
7fff4f249d
commit
064d412ec8
@ -42,6 +42,7 @@ psg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub envelope(ubyte voice_num, ubyte attack, ubyte release) {
|
sub envelope(ubyte voice_num, ubyte attack, ubyte release) {
|
||||||
|
envelope_states[voice_num] = 255
|
||||||
envelope_attacks[voice_num] = attack * $0040
|
envelope_attacks[voice_num] = attack * $0040
|
||||||
envelope_releases[voice_num] = release * $0040
|
envelope_releases[voice_num] = release * $0040
|
||||||
if attack
|
if attack
|
||||||
@ -54,9 +55,9 @@ psg {
|
|||||||
|
|
||||||
sub silent() {
|
sub silent() {
|
||||||
for cx16.r15L in 0 to 15 {
|
for cx16.r15L in 0 to 15 {
|
||||||
volume(cx16.r15L, 0)
|
|
||||||
envelope_volumes[cx16.r15L] = 0
|
|
||||||
envelope_states[cx16.r15L] = 255
|
envelope_states[cx16.r15L] = 255
|
||||||
|
envelope_volumes[cx16.r15L] = 0
|
||||||
|
volume(cx16.r15L, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,11 +66,7 @@ psg {
|
|||||||
; cx16.r15L = the voice number
|
; cx16.r15L = the voice number
|
||||||
; the other virtual registers are used to backup vera registers.
|
; the other virtual registers are used to backup vera registers.
|
||||||
|
|
||||||
cx16.r13L = cx16.VERA_CTRL
|
; calculate new volumes
|
||||||
cx16.r13H = cx16.VERA_ADDR_L
|
|
||||||
cx16.r14L = cx16.VERA_ADDR_M
|
|
||||||
cx16.r14H = cx16.VERA_ADDR_H
|
|
||||||
|
|
||||||
for cx16.r15L in 0 to 15 {
|
for cx16.r15L in 0 to 15 {
|
||||||
when envelope_states[cx16.r15L] {
|
when envelope_states[cx16.r15L] {
|
||||||
0 -> {
|
0 -> {
|
||||||
@ -81,7 +78,6 @@ psg {
|
|||||||
envelope_states[cx16.r15L] = 1 ; start release
|
envelope_states[cx16.r15L] = 1 ; start release
|
||||||
}
|
}
|
||||||
envelope_volumes[cx16.r15L] = cx16.r0
|
envelope_volumes[cx16.r15L] = cx16.r0
|
||||||
volume(cx16.r15L, msb(cx16.r0)) ; TODO optimize to not use vpoke and use vera auto increment
|
|
||||||
}
|
}
|
||||||
1 -> {
|
1 -> {
|
||||||
; release
|
; release
|
||||||
@ -91,14 +87,24 @@ psg {
|
|||||||
envelope_releases[cx16.r15L] = 0
|
envelope_releases[cx16.r15L] = 0
|
||||||
}
|
}
|
||||||
envelope_volumes[cx16.r15L] = cx16.r0
|
envelope_volumes[cx16.r15L] = cx16.r0
|
||||||
volume(cx16.r15L, msb(cx16.r0)) ; TODO optimize to not use vpoke and use vera auto increment
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cx16.VERA_CTRL = cx16.r13L
|
|
||||||
cx16.VERA_ADDR_L = cx16.r13H
|
; set new volumes using vera stride of 4
|
||||||
cx16.VERA_ADDR_M = cx16.r14L
|
cx16.push_vera_context()
|
||||||
cx16.VERA_ADDR_H = cx16.r14H
|
cx16.VERA_CTRL = 0
|
||||||
|
cx16.VERA_ADDR_L = $c2
|
||||||
|
cx16.VERA_ADDR_M = $f9
|
||||||
|
cx16.VERA_ADDR_H = 1 | %00110000
|
||||||
|
cx16.VERA_CTRL = 1
|
||||||
|
cx16.VERA_ADDR_L = $c2
|
||||||
|
cx16.VERA_ADDR_M = $f9
|
||||||
|
cx16.VERA_ADDR_H = 1 | %00110000
|
||||||
|
for cx16.r15L in 0 to 15 {
|
||||||
|
cx16.VERA_DATA0 = cx16.VERA_DATA1 & %11000000 | msb(envelope_volumes[cx16.r15L])
|
||||||
|
}
|
||||||
|
cx16.pop_vera_context()
|
||||||
}
|
}
|
||||||
|
|
||||||
ubyte[16] envelope_states
|
ubyte[16] envelope_states
|
||||||
|
@ -735,6 +735,52 @@ IRQ_SCRATCH_ZPWORD2 .word 0
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline asmsub push_vera_context() clobbers(A) {
|
||||||
|
; -- use this at the start of your IRQ handler if it uses Vera registers, to save the state
|
||||||
|
%asm {{
|
||||||
|
lda cx16.VERA_ADDR_L
|
||||||
|
pha
|
||||||
|
lda cx16.VERA_ADDR_M
|
||||||
|
pha
|
||||||
|
lda cx16.VERA_ADDR_H
|
||||||
|
pha
|
||||||
|
lda cx16.VERA_CTRL
|
||||||
|
pha
|
||||||
|
eor #1
|
||||||
|
sta cx16.VERA_CTRL
|
||||||
|
lda cx16.VERA_ADDR_L
|
||||||
|
pha
|
||||||
|
lda cx16.VERA_ADDR_M
|
||||||
|
pha
|
||||||
|
lda cx16.VERA_ADDR_H
|
||||||
|
pha
|
||||||
|
lda cx16.VERA_CTRL
|
||||||
|
pha
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline asmsub pop_vera_context() clobbers(A) {
|
||||||
|
; -- use this at the end of your IRQ handler if it uses Vera registers, to restore the state
|
||||||
|
%asm {{
|
||||||
|
pla
|
||||||
|
sta cx16.VERA_CTRL
|
||||||
|
pla
|
||||||
|
sta cx16.VERA_ADDR_H
|
||||||
|
pla
|
||||||
|
sta cx16.VERA_ADDR_M
|
||||||
|
pla
|
||||||
|
sta cx16.VERA_ADDR_L
|
||||||
|
pla
|
||||||
|
sta cx16.VERA_CTRL
|
||||||
|
pla
|
||||||
|
sta cx16.VERA_ADDR_H
|
||||||
|
pla
|
||||||
|
sta cx16.VERA_ADDR_M
|
||||||
|
pla
|
||||||
|
sta cx16.VERA_ADDR_L
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
asmsub restore_irq() clobbers(A) {
|
asmsub restore_irq() clobbers(A) {
|
||||||
%asm {{
|
%asm {{
|
||||||
|
@ -156,3 +156,10 @@ And for the Commander X16::
|
|||||||
cx16.set_rasterirq(uword handler_address, uword rasterline) ; note: disables kernal irq handler! sys.wait() won't work anymore
|
cx16.set_rasterirq(uword handler_address, uword rasterline) ; note: disables kernal irq handler! sys.wait() won't work anymore
|
||||||
cx16.restore_irq() ; set everything back to the systems default irq handler
|
cx16.restore_irq() ; set everything back to the systems default irq handler
|
||||||
|
|
||||||
|
|
||||||
|
The Commander X16 provides two additional routines that should be used *in your IRQ handler routine* if it uses the Vera registers::
|
||||||
|
|
||||||
|
cx16.push_vera_context()
|
||||||
|
; ... do your work that uses vera here...
|
||||||
|
cx15.pop_vera_context()
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ TODO
|
|||||||
|
|
||||||
For next release
|
For next release
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
- psg: use all 16 voices and see how many rasterlines the envelope interrupt handler takes
|
- fix push() pop() of vera registers
|
||||||
- if passing a subroutine or label name as an uword argument, without &, add the addressof automatically
|
- if passing a subroutine or label name as an uword argument, without &, add the addressof automatically
|
||||||
- convert the sounds in cx16 tehtriz to use the psg module instead
|
- convert the sounds in cx16 tehtriz to use the psg module instead
|
||||||
- notify petaxian that it could use the psg module too?
|
- notify petaxian that it could use the psg module too?
|
||||||
|
Loading…
Reference in New Issue
Block a user