aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c87
1 files changed, 44 insertions, 43 deletions
diff --git a/src/main.c b/src/main.c
index 6e7d3e5..a5a0628 100644
--- a/src/main.c
+++ b/src/main.c
@@ -112,37 +112,46 @@ screen_talk(Device *d, u8 b0, u8 w) {
112 } 112 }
113} 113}
114 114
115static u8 buf[KB(1)];
116
117static void 115static void
118audio_talk(Device *d, u8 b0, u8 w) { 116audio_talk(Device *d, u8 b0, u8 w) {
119 AudioChannel *c = &apu.chan_0; 117 AudioChannel *c = &channels[0];
120 if(!w) { 118 if(!w) {
121 if(b0 == 0x2) { 119 if(b0 == 0x2) {
122 mempoke16(d->dat, 0x2, c->position); 120 mempoke16(d->dat, 0x2, c->pos);
121 c->pos <<= 12; // fixed point.
123 } else if(b0 == 0x4) { 122 } else if(b0 == 0x4) {
124 // d->dat[0x4] = apu_get_vu(c); 123 // d->dat[0x4] = apu_get_vu(c);
125 } 124 }
126 } else if(b0 == 0xf) { 125 } else if(b0 == 0xf) {
127 // SDL_LockAudioDevice(audio_id); 126 // Disable the channel before updating.
128 c->n_samples = mempeek16(d->dat, 0xa); 127 c->data = NULL;
129 c->samples = &d->mem[mempeek16(d->dat, 0xc)]; 128
130 // Transform the samples from u8 to s8. 129 // Initialization.
131 for (size_t i = 0; i < c->n_samples; ++i) { 130 c->inc = (44100 << 12) / AUDIO_FREQ;
132 buf[i] = (u8)c->samples[i] + 0x80; 131 c->pos = 0;
133 } 132
134 c->samples = &buf; 133 // Data.
134 c->length = mempeek16(d->dat, 0xa);
135 c->length <<= 12; // fixed point.
136 c->data = &d->mem[mempeek16(d->dat, 0xc)];
137
138 // TODO: Volume.
139 c->vol = 12; // 0-64
135 // c->volume[0] = d->dat[0xe] >> 4; 140 // c->volume[0] = d->dat[0xe] >> 4;
136 // c->volume[1] = d->dat[0xe] & 0xf; 141 // c->volume[1] = d->dat[0xe] & 0xf;
137 c->loop = !(d->dat[0xf] & 0x80); 142
143 // Looping.
144 if (!(d->dat[0xf] & 0x80)) {
145 c->loop_length = c->length;
146 } else {
147 c->loop_length = 0;
148 }
149
150 // Pitch
138 c->pitch = d->dat[0xf] & 0x7f; 151 c->pitch = d->dat[0xf] & 0x7f;
139 // init_sound(c); 152 txt_position(0, 0);
140 reset_sound(c);
141 txt_printf("note: %d \n", c->pitch); 153 txt_printf("note: %d \n", c->pitch);
142 // apu_start(c, mempeek16(d->dat, 0x8), d->dat[0xf] & 0x7f);
143 // SDL_UnlockAudioDevice(audio_id);
144 } 154 }
145 // txt_printf("AUDIO TALK: %d\n", d);
146} 155}
147 156
148void 157void
@@ -401,41 +410,33 @@ int main(void) {
401 txt_position(0,0); 410 txt_position(0,0);
402 411
403 init_sound(); 412 init_sound();
404 // reset_sound(&apu.chan_0);
405 // txt_printf("DING\n");
406 // sound_mix();
407 413
408 // Main loop. 414 // Main loop.
409 int frame_counter = 0; 415 int frame_counter = 0;
410 // evaluxn(&u, 0x0100); 416 evaluxn(&u, 0x0100);
411 // u32 flip_cycles = 0; 417 u32 flip_cycles = 0;
412 while(true) { 418 while(true) {
413 bios_vblank_wait(); 419 bios_vblank_wait();
414 // profile_start(); 420 profile_start();
415 // handle_input(&u); 421 handle_input(&u);
416 // u32 input_cycles = profile_stop(); 422 u32 input_cycles = profile_stop();
417 // profile_start(); 423 profile_start();
418 // evaluxn(&u, mempeek16(devscreen->dat, 0)); 424 evaluxn(&u, mempeek16(devscreen->dat, 0));
419 // u32 eval_cycles = profile_stop(); 425 u32 eval_cycles = profile_stop();
420 // txt_position(0, 8); 426 txt_position(0, 8);
421 // txt_printf("INPUT: %lu \n", input_cycles); 427 profile_start();
422 // txt_printf("EVAL: %lu \n", eval_cycles); 428 flip_cycles = profile_stop();
423 // txt_printf("FLIP: %lu \n", flip_cycles);
424 // profile_start();
425 // flip_cycles = profile_stop();
426 frame_counter++; 429 frame_counter++;
427 // if (frame_counter == 120) {
428 // init_sound(&apu.chan_0);
429 // reset_sound(&apu.chan_0);
430 // frame_counter = 0;
431 // }
432 profile_start(); 430 profile_start();
433 sound_mix(); 431 sound_mix();
434 u32 mix_cycles = profile_stop(); 432 u32 mix_cycles = profile_stop();
435 433
436 txt_position(0, 18); 434 txt_position(0, 15);
437 txt_printf("MIX CYCLES: %lu \n", mix_cycles); 435 txt_printf("INPUT: %lu \n", input_cycles);
438 txt_printf("FRAME: %lu \n", frame_counter); 436 txt_printf("EVAL: %lu \n", eval_cycles);
437 txt_printf("FLIP: %lu \n", flip_cycles);
438 txt_printf("MIX: %lu \n", mix_cycles);
439 txt_printf("FRAME: %lu \n", frame_counter);
439 flipbuf(&ppu); 440 flipbuf(&ppu);
440 } 441 }
441 442