Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making the Lib compatible with C++. #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"dc_timer.h": "c"
}
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ include $(KOS_BASE)/addons/Makefile.prefab

create_kos_link:
rm -f ../include/dreamroq
ln -s ../libdreamroq/include ../include/dreamroq
ln -s ../libdreamroq/include ../include/dreamroq
35 changes: 24 additions & 11 deletions dreamroq-player.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ static int current_frame = 0;
static int graphics_initialized = 0;
static float video_delay;
static int frame=0;
static int vid_width = 640;
static int vid_height = 480;
static const float VIDEO_RATE = 30.0f; /* Video FPS */
static int vid_width = 320;
static int vid_height = 240;
static const float VIDEO_RATE = 25.0f; /* Video FPS */

static void snd_thd(){
do
Expand Down Expand Up @@ -110,8 +110,8 @@ int roq_set_size(int width, int height) {

ul_x = 0;
ul_y = 0;
br_x = 640;
br_y = 480;
br_x = 512;
br_y = 270;



Expand Down Expand Up @@ -206,19 +206,32 @@ int roq_set_size(int width, int height) {
}

int roq_quit_cb(){
maple_device_t *cont;
cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
cont_cond_t cont;

cont_state_t *state;
state = maple_dev_status(cont);
return (state->buttons & CONT_START);
/* check controller state */
if (cont_get_cond(maple_first_controller(), &cont))
{
/* controller read error */
return 1;
}
cont.buttons = ~cont.buttons;
return (cont.buttons & CONT_START);
}

int roq_free_texture(){
int roq_free_texture(){
pvr_mem_free(textures[0]);
pvr_mem_free(textures[1]);
}

int free_variables() {
current_frame = 0;
graphics_initialized = 0;
video_delay;
frame=0;
vid_width = 320;
vid_height = 240;
}

int roq_free_audio() {
if(audio_init)
{
Expand Down
Binary file added dreamroq-player.o
Binary file not shown.
12 changes: 5 additions & 7 deletions dreamroqlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ static int roq_unpack_vq(unsigned char *buf, int size, unsigned int arg,
int roq_play(char *filename, int loop, render_callback render_cb,
audio_callback audio_cb, quit_callback quit_cb)
{
pvr_init_defaults();
FILE *f;
size_t file_ret;
int framerate;
Expand All @@ -385,7 +386,6 @@ int roq_play(char *filename, int loop, render_callback render_cb,
if (file_ret != 1)
{
fclose(f);
printf("\nROQ_FILE_READ_FAILURE\n\n");
return ROQ_FILE_READ_FAILURE;

}
Expand All @@ -397,7 +397,6 @@ int roq_play(char *filename, int loop, render_callback render_cb,
return ROQ_FILE_READ_FAILURE;
}
framerate = LE_16(&read_buffer[6]);
printf("RoQ file plays at %d frames/sec\n", framerate);

/* Initialize Audio SQRT Look-Up Table */
for(i = 0; i < 128; i++)
Expand All @@ -409,7 +408,6 @@ int roq_play(char *filename, int loop, render_callback render_cb,
status = ROQ_SUCCESS;
while (!feof(f) && status == ROQ_SUCCESS)
{
printf("DreamROQ: playing frame %d\n", frameCount);
frameCount++;
/* if client program defined a quit callback, check if it's time
* to quit */
Expand All @@ -418,7 +416,7 @@ int roq_play(char *filename, int loop, render_callback render_cb,

file_ret = fread(read_buffer, CHUNK_HEADER_SIZE, 1, f);
#ifdef FPSGRAPH
printf("r\n");

#endif
if (file_ret != 1)
{
Expand Down Expand Up @@ -496,9 +494,7 @@ int roq_play(char *filename, int loop, render_callback render_cb,
while (state.texture_height < state.height)
state.texture_height <<= 1;
}
printf(" RoQ_INFO: dimensions = %dx%d, %dx%d; %d mbs, texture = %dx%d\n",
state.width, state.height, state.mb_width, state.mb_height,
state.mb_count, state.stride, state.texture_height);

state.frame[0] = (unsigned short*)malloc(state.texture_height * state.stride * sizeof(unsigned short));
state.frame[1] = (unsigned short*)malloc(state.texture_height * state.stride * sizeof(unsigned short));
state.current_frame = 0;
Expand Down Expand Up @@ -573,7 +569,9 @@ int roq_play(char *filename, int loop, render_callback render_cb,
free(state.frame[1]);
roq_free_texture();
roq_free_audio();
free_variables();
fclose(f);
pvr_shutdown();

return status;
}
Binary file added dreamroqlib.o
Binary file not shown.
16 changes: 8 additions & 8 deletions include/dreamroqlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ typedef int (*audio_callback)(unsigned char *buf, int samples, int channels);
* Return non-zero if it's time to quite. */
typedef int (*quit_callback)();

int roq_play(char *filename, int loop, render_callback render_cb,
extern "C" int roq_play(char *filename, int loop, render_callback render_cb,
audio_callback audio_cb, quit_callback quit_cb);

int roq_set_size(int width, int height);

int roq_render_cb(unsigned short *buf, int width, int height, int stride, int texture_height);
int roq_audio_cb(unsigned char *buf, int size, int channels);
int roq_quit_cb();
int roq_free_texture();
int roq_free_audio();
extern "C" int roq_set_size(int width, int height);

extern "C" int roq_render_cb(unsigned short *buf, int width, int height, int stride, int texture_height);
extern "C" int roq_audio_cb(unsigned char *buf, int size, int channels);
extern "C" int roq_quit_cb();
extern "C" int roq_free_texture();
extern "C" int roq_free_audio();
extern "C" int free_variables();

#endif /* NEWROQ_H */
2 changes: 0 additions & 2 deletions libdcmc/snd_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ snd_stream_hnd_t snd_stream_alloc(snd_stream_callback_t cb, int bufsize) {
// And channels
streams[hnd].ch[0] = snd_sfx_chn_alloc();
streams[hnd].ch[1] = snd_sfx_chn_alloc();
printf("snd_stream: alloc'd channels %d/%d\n", streams[hnd].ch[0], streams[hnd].ch[1]);

return hnd;
}
Expand Down Expand Up @@ -458,7 +457,6 @@ int snd_stream_poll(snd_stream_hnd_t hnd) {
needed_samples = (streams[hnd].buffer_size/2) - streams[hnd].last_write_pos;
/* round it a little bit */
needed_samples &= ~0x7ff;
/* printf("last_write_pos %6i, current_play_pos %6i, needed_samples %6i\n",last_write_pos,current_play_pos,needed_samples); */

//if (needed_samples > 0) {
if (needed_samples ==4096) {
Expand Down
Binary file modified libdcmc/snd_stream.o
Binary file not shown.
10 changes: 0 additions & 10 deletions libdcmc/snddrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ int snddrv_exit() {

while( snddrv.drv_status != SNDDRV_STATUS_NULL )
thd_pass();


printf("SNDDRV: Exited\n");
}

memset( snddrv.pcm_buffer, 0, 65536+16384);
Expand Down Expand Up @@ -94,8 +91,6 @@ static void *snddrv_callback(snd_stream_hnd_t hnd, int len, int * actual) {

static int snddrv_thread() {

printf("SNDDRV: Rate - %i, Channels - %i\n", snddrv.rate, snddrv.channels);

shnd = snd_stream_alloc(snddrv_callback, SND_STREAM_BUFFER_MAX/4);

snd_stream_start(shnd, snddrv.rate, snddrv.channels-1);
Expand All @@ -112,8 +107,6 @@ static int snddrv_thread() {
snd_stream_destroy(shnd);
snd_stream_shutdown();

printf("SNDDRV: Finished\n");

return snddrv.drv_status;
}

Expand All @@ -123,12 +116,9 @@ int snddrv_start( int rate, int chans ) {
snddrv.rate = rate;
snddrv.channels = chans;
if( snddrv.channels > 2) {
printf("SNDDRV: ERROR - Exceeds maximum channels\n");
return -1;
}

printf("SNDDRV: Creating Driver Thread\n");

snddrv.drv_status = SNDDRV_STATUS_INITIALIZING;

snd_stream_init();
Expand Down
Binary file modified libdcmc/snddrv.o
Binary file not shown.
2 changes: 1 addition & 1 deletion libdcmc/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void frame_delay( float AVI_video_rate, float AVI_delay, int frameCounter )
{
float AVI_real_time = frameCounter / AVI_video_rate;
float CPU_real_time= ( ( (float)dc_get_time()- AVI_delay ) / 1000.0f );
//printf("AVI_real_time: %f, CPU_real_time %f\n", AVI_real_time, CPU_real_time );

while ( CPU_real_time < AVI_real_time ) {
CPU_real_time= ( ( (float)dc_get_time()- AVI_delay ) / 1000.0f );
thd_pass();
Expand Down
Binary file modified libdcmc/timer.o
Binary file not shown.
Binary file modified libdreamroq.a
Binary file not shown.
2 changes: 1 addition & 1 deletion samples/basic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rm-elf:

$(TARGET): $(OBJS) romdisk.o
$(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $(TARGET) $(KOS_START) \
$(OBJS) romdisk.o $(OBJEXTRA) -lm -lkosutils -ldreamroq $(KOS_LIBS)
$(OBJS) romdisk.o $(OBJEXTRA) -lm -ldreamroq $(KOS_LIBS)

romdisk.img:
$(KOS_GENROMFS) -f romdisk.img -d romdisk -v
Expand Down
4 changes: 0 additions & 4 deletions samples/basic/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ extern uint8 romdisk[];
KOS_INIT_ROMDISK(romdisk);

int main() {
printf("DreamROQ Demo.\n");

vid_set_mode(DM_640x480, PM_RGB565);
pvr_init_defaults();

Expand All @@ -27,6 +25,4 @@ int main() {
roq_audio_cb, // default audio callback
roq_quit_cb // default quit callback
);

printf("DreamROQ video done.\n");
}
Binary file modified samples/basic/dreamroq_basic.elf
Binary file not shown.
Binary file modified samples/basic/romdisk.img
Binary file not shown.
Binary file modified samples/basic/romdisk.o
Binary file not shown.