comparison vgmplay.c @ 466:bc9e0829ffc7

Fix vgmplay
author Mike Pavone <pavone@retrodev.com>
date Tue, 10 Sep 2013 21:20:54 -0700
parents c1bddeadc566
children 140af5509ce7
comparison
equal deleted inserted replaced
465:dc322bc77ea2 466:bc9e0829ffc7
1 #include "render.h" 1 #include "render.h"
2 #include "ym2612.h" 2 #include "ym2612.h"
3 #include "psg.h" 3 #include "psg.h"
4 #include "config.h"
4 #include <stdint.h> 5 #include <stdint.h>
5 #include <stdio.h> 6 #include <stdio.h>
6 7
7 #define MCLKS_NTSC 53693175 8 #define MCLKS_NTSC 53693175
8 #define MCLKS_PAL 53203395 9 #define MCLKS_PAL 53203395
70 71
71 void handle_keyup(int keycode) 72 void handle_keyup(int keycode)
72 { 73 {
73 } 74 }
74 75
76 void handle_joydown(int joystick, int button)
77 {
78 }
79
80 void handle_joyup(int joystick, int button)
81 {
82 }
83
84 void handle_joy_dpad(int joystick, int dpadnum, uint8_t value)
85 {
86 }
87
75 #define CYCLE_LIMIT MCLKS_NTSC/60 88 #define CYCLE_LIMIT MCLKS_NTSC/60
89 tern_node * config;
76 90
77 void wait(ym2612_context * y_context, psg_context * p_context, uint32_t * current_cycle, uint32_t cycles) 91 void wait(ym2612_context * y_context, psg_context * p_context, uint32_t * current_cycle, uint32_t cycles)
78 { 92 {
79 *current_cycle += cycles; 93 *current_cycle += cycles;
80 psg_run(p_context, *current_cycle); 94 psg_run(p_context, *current_cycle);
81 ym_run(y_context, *current_cycle); 95 ym_run(y_context, *current_cycle);
82 96
83 if (*current_cycle > CYCLE_LIMIT) { 97 if (*current_cycle > CYCLE_LIMIT) {
84 *current_cycle -= CYCLE_LIMIT; 98 *current_cycle -= CYCLE_LIMIT;
85 p_context->cycles -= CYCLE_LIMIT; 99 p_context->cycles -= CYCLE_LIMIT;
86 y_context->current_cycle -= CYCLE_LIMIT; 100 y_context->current_cycle -= CYCLE_LIMIT;
87 process_events(); 101 process_events();
89 } 103 }
90 104
91 int main(int argc, char ** argv) 105 int main(int argc, char ** argv)
92 { 106 {
93 uint32_t fps = 60; 107 uint32_t fps = 60;
94 render_init(320, 240, "vgm play", 60); 108 config = load_config(argv[0]);
95 109 render_init(320, 240, "vgm play", 60, 0);
96 110
111
97 ym2612_context y_context; 112 ym2612_context y_context;
98 ym_init(&y_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_YM, render_audio_buffer(), 0); 113 ym_init(&y_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_YM, render_audio_buffer(), 0);
99 114
100 psg_context p_context; 115 psg_context p_context;
101 psg_init(&p_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_PSG, render_audio_buffer()); 116 psg_init(&p_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_PSG, render_audio_buffer());
102 117
103 FILE * f = fopen(argv[1], "rb"); 118 FILE * f = fopen(argv[1], "rb");
104 vgm_header header; 119 vgm_header header;
105 fread(&header, sizeof(header), 1, f); 120 fread(&header, sizeof(header), 1, f);
106 if (header.version < 0x150 || !header.data_offset) { 121 if (header.version < 0x150 || !header.data_offset) {
107 header.data_offset = 0xC; 122 header.data_offset = 0xC;
109 fseek(f, header.data_offset + 0x34, SEEK_SET); 124 fseek(f, header.data_offset + 0x34, SEEK_SET);
110 uint32_t data_size = header.eof_offset + 4 - (header.data_offset + 0x34); 125 uint32_t data_size = header.eof_offset + 4 - (header.data_offset + 0x34);
111 uint8_t * data = malloc(data_size); 126 uint8_t * data = malloc(data_size);
112 fread(data, 1, data_size, f); 127 fread(data, 1, data_size, f);
113 fclose(f); 128 fclose(f);
114 129
115 uint32_t mclks_sample = MCLKS_NTSC / 44100; 130 uint32_t mclks_sample = MCLKS_NTSC / 44100;
116 131
117 uint8_t * end = data + data_size; 132 uint8_t * end = data + data_size;
118 uint8_t * cur = data; 133 uint8_t * cur = data;
119 uint32_t current_cycle = 0; 134 uint32_t current_cycle = 0;
120 while (cur < end) { 135 while (cur < end) {
121 uint8_t cmd = *(cur++); 136 uint8_t cmd = *(cur++);