-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvsync.asm
155 lines (124 loc) · 2.28 KB
/
vsync.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
\ ******************************************************************
\ * Event Vector Routines
\ ******************************************************************
.vsync_palette_override EQUB &FF
.vsync_swap_buffers EQUB 0
.vsync_enable_timer EQUB 0
.vsync_timer_ticks EQUW 0
.old_eventv SKIP 2
.start_eventv ; new event handler in X,Y
{
\\ Remove interrupt instructions
; lda #NOP_OP
; sta PSG_STROBE_SEI_INSN
; sta PSG_STROBE_CLI_INSN
\\ Set new Event handler
sei
lda EVENTV
sta old_eventv
lda EVENTV+1
sta old_eventv+1
stx EVENTV
sty EVENTV+1
cli
\\ Enable VSYNC event.
lda #14
ldx #4
jmp osbyte
}
IF 0 ; not currently used
.stop_eventv
{
\\ Disable VSYNC event.
lda #13
ldx #4
jsr osbyte
\\ Reset old Event handler
sei
lda old_eventv
sta EVENTV
lda old_eventv+1
sta EVENTV+1
cli
\\ Insert interrupt instructions back
lda #SEI_OP
sta PSG_STROBE_SEI_INSN
lda #CLI_OP
sta PSG_STROBE_CLI_INSN
rts
}
ENDIF
.vsync_start_timer
{
LDA #&FF
STA vsync_enable_timer
STZ vsync_timer_ticks+0
STZ vsync_timer_ticks+1
RTS
}
.vsync_stop_timer
{
STZ vsync_enable_timer
RTS
}
.event_handler
{
php
cmp #4
bne not_vsync
\\ Preserve registers
pha:txa:pha:tya:pha
; prevent re-entry - KC do we need this?
lda re_entrant
bne skip_update
inc re_entrant
;-------------------------------------------------
; Add vsync IRQ service routines here
;-------------------------------------------------
\\ Increment vsync counter
INC beeb_vsync_count
\\ Swap frame buffers if requested
LDA vsync_swap_buffers
BEQ no_swap
JSR shadow_swap_buffers
DEC vsync_swap_buffers
.no_swap
IF _AUDIO
; call our audio interrupt handler
jsr audio_update
ENDIF
; is real time counter enabled?
{
LDA vsync_enable_timer
BEQ done
INC vsync_timer_ticks+0
BNE done
INC vsync_timer_ticks+1
.done
}
; hack in screen flash
{
LDA vsync_palette_override
BMI default
JSR beeb_set_palette_all
JMP skip_palette
.default
CMP #&FF
BEQ skip_palette
JSR beeb_set_default_palette
LDA #&FF
STA vsync_palette_override
.skip_palette
}
;-------------------------------------------------
dec re_entrant
.skip_update
\\ Restore registers
pla:tay:pla:tax:pla
\\ Return
.not_vsync
plp
jmp (old_eventv)
rts
.re_entrant EQUB 0
}