-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.mfk
128 lines (94 loc) · 1.69 KB
/
main.mfk
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
import nes_lib
import custom_random
import graphics
import graphics_buffer
import input
import sound/sound
import ui/screen
import ui/aquarium
import ui/commandbar
import ui/planteditor
import tank/tank
import fish/fish
byte in_nmi = 0
byte nmi_fail = 0
byte frame
volatile bool new_frame = false
void main() {
init_graphics()
init_rw_memory()
init_random()
init_tank()
init_fish()
init_plants()
#if(music)
famistudio_init(0, $D000)
famistudio_sfx_init($E000)
#endif
init_title()
draw_screen()
process_buffered_writes()
enable_graphics()
while(true) {
// Wait for NMI to complete rendering frame
while (new_frame && not(buffer_screen_draw)) {}
if (buffer_screen_draw) {
screen_draw_tick()
} else {
sprite_tick()
input_and_screen_tick()
clear_remaining_oam()
}
// wait_for_sprite0_clear()
new_frame = true
frame += 1
}
}
void nmi() {
if in_nmi != 0 {
// Overran NMI
nmi_fail = 1
asm {
kil
}
}
in_nmi = 1
nmi_work()
in_nmi = 0
}
inline void nmi_work() {
if (buffer_screen_blank) {
load_transition_palette()
screen_transfer_tick()
nmi_always_run()
new_frame = false
return
}
if (not(drawing_enabled)) {
nmi_always_run()
return
}
if (new_frame) {
nmi_frame()
new_frame = false
}
nmi_always_run()
}
void nmi_frame() {
// set_color_effect(clear)
sprite_render()
process_buffered_writes()
read_ppu_status()
ppu_ctrl = standard_ppu_ctrl
read_ppu_status()
ppu_set_scroll(0, 0)
// wait_for_sprite0_nmi()
// set_color_effect(blue)
}
void nmi_always_run() {
#if(music)
famistudio_update()
#endif
}
void irq() {
}