Skip to content

Commit

Permalink
Original source of SunVox 1.3b
Browse files Browse the repository at this point in the history
  • Loading branch information
bohwaz committed Dec 21, 2015
1 parent 86ed371 commit 43999c0
Show file tree
Hide file tree
Showing 101 changed files with 42,267 additions and 0 deletions.
252 changes: 252 additions & 0 deletions sundog_engine/core/code/debug.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
/*
debug.cpp. Debug functions
This file is part of the SunDog engine.
Copyright (C) 2002 - 2009 Alex Zolotov <[email protected]>
*/

#include "../core.h"
#include "../../memory/memory.h"
#include "../../utils/utils.h"
#include "../../filesystem/v3nus_fs.h"
#include "../debug.h"
#include <stdarg.h>

#ifndef PALMOS
#include <stdio.h>
#else
#include "palm_functions.h"
#endif

#define Y_LIMIT 50

int hide_debug_counter = 0;

void hide_debug( void )
{
hide_debug_counter++;
}

void show_debug( void )
{
if( hide_debug_counter > 0 )
hide_debug_counter--;
}

long debug_count = 0;
UTF8_CHAR temp_debug_buf[ 256 ];
UTF8_CHAR *debug_buf = 0;
int debug_buf_size = 0;
int y = 10;

const UTF8_CHAR *debug_output_file = "log.txt";

void debug_set_output_file( const UTF8_CHAR *filename )
{
debug_output_file = filename;
}

void debug_reset( void )
{
#ifdef NODEBUG
return;
#endif

if( debug_output_file == 0 ) return;

#ifndef PALMOS
v3_remove( debug_output_file );
#endif
}

void sprint( UTF8_CHAR *dest_str, const UTF8_CHAR *str, ... )
{
va_list p;
va_start( p, str );

int ptr = 0;
int ptr2 = 0;
UTF8_CHAR num_str[ 32 ];
int len;

//Make a string:
for(;;)
{
if( str[ ptr ] == 0 ) break;
if( str[ ptr ] == '%' )
{
if( str[ ptr + 1 ] == 'd' || str[ ptr + 1 ] == 'x' )
{
//Integer value:
int arg = va_arg( p, int );
if( str[ ptr + 1 ] == 'd' )
int_to_string( arg, num_str );
else
hex_int_to_string( arg, num_str );
len = mem_strlen( num_str );
mem_copy( dest_str + ptr2, num_str, len );
ptr2 += len;
ptr++;
}
else
if( str[ ptr + 1 ] == 's' )
{
//ASCII string:
UTF8_CHAR *arg2 = va_arg( p, UTF8_CHAR* );
if( arg2 )
{
len = mem_strlen( arg2 );
if( len )
{
mem_copy( dest_str + ptr2, arg2, len );
ptr2 += len;
}
}
ptr++;
}
}
else
{
dest_str[ ptr2 ] = str[ ptr ];
ptr2++;
}
ptr++;
}
dest_str[ ptr2 ] = 0;
va_end( p );
}

void dprint( const UTF8_CHAR *str, ... )
{
#ifdef NODEBUG
return;
#endif

if( hide_debug_counter ) return;

if( debug_output_file == 0 ) return;

va_list p;
va_start( p, str );
if( debug_buf_size == 0 )
{
debug_buf = temp_debug_buf;
debug_buf_size = 256;
debug_buf = (UTF8_CHAR*)MEM_NEW( HEAP_DYNAMIC, 256 );
}
int ptr = 0;
int ptr2 = 0;
UTF8_CHAR num_str[ 32 ];
int len;

//Make a number:
#ifdef PALMOS
int_to_string( debug_count, num_str );
len = mem_strlen( num_str );
mem_copy( debug_buf, num_str, len );
debug_buf[ len ] = ':';
debug_buf[ len + 1 ] = ' ';
ptr2 += len + 2;
#endif
debug_count++;

//Make a string:
for(;;)
{
if( str[ ptr ] == 0 ) break;
if( str[ ptr ] == '%' )
{
if( str[ ptr + 1 ] == 'd' || str[ ptr + 1 ] == 'x' )
{
int arg = va_arg( p, int );
if( str[ ptr + 1 ] == 'd' )
int_to_string( arg, num_str );
else
hex_int_to_string( arg, num_str );
len = mem_strlen( num_str );
if( ptr2 + len >= debug_buf_size )
{
//Resize debug buffer:
debug_buf_size += 256;
debug_buf = (UTF8_CHAR*)mem_resize( debug_buf, debug_buf_size );
}
mem_copy( debug_buf + ptr2, num_str, len );
ptr2 += len;
ptr++;
}
else
if( str[ ptr + 1 ] == 's' )
{
//ASCII string:
UTF8_CHAR *arg2 = va_arg( p, UTF8_CHAR* );
if( arg2 )
{
len = mem_strlen( arg2 );
if( len )
{
if( ptr2 + len >= debug_buf_size )
{
//Resize debug buffer:
debug_buf_size += 256;
debug_buf = (UTF8_CHAR*)mem_resize( debug_buf, debug_buf_size );
}
mem_copy( debug_buf + ptr2, arg2, len );
ptr2 += len;
}
}
ptr++;
}
}
else
{
debug_buf[ ptr2 ] = str[ ptr ];
ptr2++;
if( ptr2 >= debug_buf_size )
{
//Resize debug buffer:
debug_buf_size += 256;
debug_buf = (UTF8_CHAR*)mem_resize( debug_buf, debug_buf_size );
}
}
ptr++;
}
debug_buf[ ptr2 ] = 0;
va_end( p );

//Save result:
#ifdef NONPALM
V3_FILE f = v3_open( debug_output_file, "ab" );
if( f )
{
v3_write( debug_buf, 1, mem_strlen( debug_buf ), f );
v3_close( f );
}
printf( "%s", debug_buf );
#else
//PalmOS:
int a;
for( a = 0; a < 128; a++ )
{
if( debug_buf[ a ] == 0 ) break;
if( debug_buf[ a ] == 0xA ) break;
if( debug_buf[ a ] == 0xD ) break;
}
WinDrawChars( " ", 80, 0, y );
WinDrawChars( debug_buf, a, 0, y );
y += 10;
if( y >= Y_LIMIT ) y = 0;
#endif
}

void debug_close( void )
{
#ifdef NODEBUG
return;
#endif

if( debug_buf && debug_buf != temp_debug_buf )
{
mem_free( debug_buf );
debug_buf = temp_debug_buf;
debug_buf_size = 256;
}
}
85 changes: 85 additions & 0 deletions sundog_engine/core/core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#ifndef __CORE__
#define __CORE__

#define SUNDOG_VERSION "SunDog Engine v1.5"
#define SUNDOG_DATE __DATE__

//#define COLOR8BITS //8 bit color
//#define COLOR16BITS //16 bit color
//#define COLOR32BITS //32 bit color
//#define RGB565 //Default for 16bit color
//#define RGB555 //16bit color in Windows GDI
//#define GRAYSCALE //Used with COLOR8BITS for grayscale palette
//#define UNIX //OS = some UNIX veriation (Linux, FreeBSD...)
//#define FREEBSD //OS = FreeBSD
//#define LINUX //OS = Linux
//#define WIN //OS = Windows
//#define WINCE //OS = WindowsCE
//#define PALMOS //OS = PalmOS
//#define OSX //OS = OSX
//#define X11 //X11 support
//#define OPENGL //OpenGL support
//#define GDI //GDI support
//#define DIRECTDRAW //Win32: DirectDraw; PalmOS: direct write to screen; WinCE: GAPI
//#define FRAMEBUFFER //Use framebuffer
//#define SLOWMODE //For some slow devices
//#define NOSTORAGE //PalmOS: do not use the Storage Heap and MemSemaphores
//#define PALMLOWRES //PalmOS: low-density screen
//#define ONLY44100 //Sampling frequencies other then 44100 not allowed
//#define NODEBUG //No debug messages
//#define SMALLCACHE
//#define SMALLMEMORY
//#define ARCH_ARM
//#define ARCH_X86

//Variations:
//WIN32: COLOR32BITS + WIN [ + OPENGL / DIRECTDRAW / GDI + RGB555 / FRAMEBUFFER ]
//LINUX: COLOR32BITS + LINUX [ + OPENGL / DIRECTDRAW / X11 / FRAMEBUFFER ]
//PALMOS: COLOR8BITS + PALMOS [ + NOSTORAGE / PALMLOWRES / SLOWMODE / DIRECTDRAW ]
//WINCE: COLOR16BITS + WINCE [ + GDI + RGB555 / FRAMEBUFFER / DIRECTDRAW ]

//Examples:
//WIN32: ARCH_X86, WIN, COLOR32BITS, GDI
//LINUX: ARCH_X86, LINUX, COLOR32BITS, X11
//PALMOS: ARCH_ARM, PALMOS, COLOR8BITS, PALMLOWRES
//PALMOS: ARCH_ARM, PALMOS, COLOR8BITS, PALMLOWRES, FRAMEBUFFER
//PALMOS: ARCH_ARM, PALMOS, COLOR8BITS, DIRECTDRAW
//WINCE: ARCH_ARM, WINCE, COLOR16BITS, GDI, RGB555
//WINCE: ARCH_ARM, WINCE, COLOR16BITS, DIRECTDRAW

typedef unsigned char uchar;
typedef unsigned short uint16;
typedef signed short int16;
typedef unsigned long ulong;
typedef signed long slong;

typedef char UTF8_CHAR;
typedef unsigned short UTF16_CHAR;
typedef unsigned long UTF32_CHAR;

#ifdef DIRECTDRAW
#define FRAMEBUFFER
#endif

#if defined(OSX) || defined(LINUX) || defined(FREEBSD)
#define UNIX
#endif

#ifdef PALMOS
#ifdef DIRECTDRAW
#undef PALMLOWRES
#endif
#define ONLY44100
#define SMALLMEMORY
#define SMALLCACHE
#else
#define NONPALM
#endif

#ifdef WINCE
#define ONLY44100
#define SMALLCACHE
#endif

#endif

15 changes: 15 additions & 0 deletions sundog_engine/core/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef __DEBUG__
#define __DEBUG__

#include "core.h"

void hide_debug( void );
void show_debug( void );

void debug_set_output_file( const UTF8_CHAR *filename );
void debug_reset( void );
void sprint( UTF8_CHAR *dest_str, const UTF8_CHAR *str, ... );
void dprint( const UTF8_CHAR *str, ... );
void debug_close( void );

#endif
30 changes: 30 additions & 0 deletions sundog_engine/docs/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
==============================================================================
SunDog engine Release License:
==============================================================================
The BSD License

Copyright (c) 2002 - 2009, Alex Zolotov <[email protected]>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* The name of the author may not be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit 43999c0

Please sign in to comment.