comparison vgmplay.c @ 487:c08a4efeee7f opengl

Update opengl branch from default. Fix build breakage unrelated to merge
author Mike Pavone <pavone@retrodev.com>
date Sat, 26 Oct 2013 22:38:47 -0700
parents 140af5509ce7
children b7b7a1cab44a
comparison
equal deleted inserted replaced
449:7696d824489d 487:c08a4efeee7f
1 /*
2 Copyright 2013 Michael Pavone
3 This file is part of BlastEm.
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
5 */
1 #include "render.h" 6 #include "render.h"
2 #include "ym2612.h" 7 #include "ym2612.h"
3 #include "psg.h" 8 #include "psg.h"
9 #include "config.h"
4 #include <stdint.h> 10 #include <stdint.h>
5 #include <stdio.h> 11 #include <stdio.h>
6 12
7 #define MCLKS_NTSC 53693175 13 #define MCLKS_NTSC 53693175
8 #define MCLKS_PAL 53203395 14 #define MCLKS_PAL 53203395
70 76
71 void handle_keyup(int keycode) 77 void handle_keyup(int keycode)
72 { 78 {
73 } 79 }
74 80
81 void handle_joydown(int joystick, int button)
82 {
83 }
84
85 void handle_joyup(int joystick, int button)
86 {
87 }
88
89 void handle_joy_dpad(int joystick, int dpadnum, uint8_t value)
90 {
91 }
92
75 #define CYCLE_LIMIT MCLKS_NTSC/60 93 #define CYCLE_LIMIT MCLKS_NTSC/60
94 tern_node * config;
76 95
77 void wait(ym2612_context * y_context, psg_context * p_context, uint32_t * current_cycle, uint32_t cycles) 96 void wait(ym2612_context * y_context, psg_context * p_context, uint32_t * current_cycle, uint32_t cycles)
78 { 97 {
79 *current_cycle += cycles; 98 *current_cycle += cycles;
80 psg_run(p_context, *current_cycle); 99 psg_run(p_context, *current_cycle);
81 ym_run(y_context, *current_cycle); 100 ym_run(y_context, *current_cycle);
82 101
83 if (*current_cycle > CYCLE_LIMIT) { 102 if (*current_cycle > CYCLE_LIMIT) {
84 *current_cycle -= CYCLE_LIMIT; 103 *current_cycle -= CYCLE_LIMIT;
85 p_context->cycles -= CYCLE_LIMIT; 104 p_context->cycles -= CYCLE_LIMIT;
86 y_context->current_cycle -= CYCLE_LIMIT; 105 y_context->current_cycle -= CYCLE_LIMIT;
87 process_events(); 106 process_events();
89 } 108 }
90 109
91 int main(int argc, char ** argv) 110 int main(int argc, char ** argv)
92 { 111 {
93 uint32_t fps = 60; 112 uint32_t fps = 60;
94 render_init(320, 240, "vgm play", 60); 113 config = load_config(argv[0]);
95 114 render_init(320, 240, "vgm play", 60, 0);
96 115
116
97 ym2612_context y_context; 117 ym2612_context y_context;
98 ym_init(&y_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_YM, render_audio_buffer(), 0); 118 ym_init(&y_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_YM, render_audio_buffer(), 0);
99 119
100 psg_context p_context; 120 psg_context p_context;
101 psg_init(&p_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_PSG, render_audio_buffer()); 121 psg_init(&p_context, render_sample_rate(), MCLKS_NTSC, MCLKS_PER_PSG, render_audio_buffer());
102 122
103 FILE * f = fopen(argv[1], "rb"); 123 FILE * f = fopen(argv[1], "rb");
104 vgm_header header; 124 vgm_header header;
105 fread(&header, sizeof(header), 1, f); 125 fread(&header, sizeof(header), 1, f);
106 if (header.version < 0x150 || !header.data_offset) { 126 if (header.version < 0x150 || !header.data_offset) {
107 header.data_offset = 0xC; 127 header.data_offset = 0xC;
109 fseek(f, header.data_offset + 0x34, SEEK_SET); 129 fseek(f, header.data_offset + 0x34, SEEK_SET);
110 uint32_t data_size = header.eof_offset + 4 - (header.data_offset + 0x34); 130 uint32_t data_size = header.eof_offset + 4 - (header.data_offset + 0x34);
111 uint8_t * data = malloc(data_size); 131 uint8_t * data = malloc(data_size);
112 fread(data, 1, data_size, f); 132 fread(data, 1, data_size, f);
113 fclose(f); 133 fclose(f);
114 134
115 uint32_t mclks_sample = MCLKS_NTSC / 44100; 135 uint32_t mclks_sample = MCLKS_NTSC / 44100;
116 136
117 uint8_t * end = data + data_size; 137 uint8_t * end = data + data_size;
118 uint8_t * cur = data; 138 uint8_t * cur = data;
119 uint32_t current_cycle = 0; 139 uint32_t current_cycle = 0;
120 while (cur < end) { 140 while (cur < end) {
121 uint8_t cmd = *(cur++); 141 uint8_t cmd = *(cur++);