mirror of
https://github.com/libretro/RetroArch
synced 2025-03-15 13:21:29 +00:00
(360) Combined console and font code into one file
This commit is contained in:
parent
f9ab3711eb
commit
8e8f56b5e8
@ -17,11 +17,229 @@
|
||||
*/
|
||||
|
||||
#include <xtl.h>
|
||||
#include <xgraphics.h>
|
||||
#include <malloc.h>
|
||||
#include "xdk360_video.h"
|
||||
#include "xdk360_video_debugfonts.h"
|
||||
#include "fonts.h"
|
||||
#include "../general.h"
|
||||
|
||||
static video_console_t video_console;
|
||||
static xdk360_video_font_t m_Font;
|
||||
|
||||
void xdk360_console_draw(void)
|
||||
{
|
||||
xdk360_video_t *vid = (xdk360_video_t*)g_d3d;
|
||||
D3DDevice *m_pd3dDevice = vid->xdk360_render_device;
|
||||
|
||||
// The top line
|
||||
unsigned int nTextLine = ( video_console.m_nCurLine -
|
||||
video_console.m_cScreenHeight + video_console.m_cScreenHeightVirtual -
|
||||
video_console.m_nScrollOffset + 1 )
|
||||
% video_console.m_cScreenHeightVirtual;
|
||||
|
||||
xdk360_video_font_begin(&m_Font);
|
||||
|
||||
for( unsigned int nScreenLine = 0; nScreenLine < video_console.m_cScreenHeight; nScreenLine++ )
|
||||
{
|
||||
xdk360_video_font_draw_text(&m_Font, (float)( video_console.m_cxSafeAreaOffset ),
|
||||
(float)( video_console.m_cySafeAreaOffset +
|
||||
video_console.m_fLineHeight * nScreenLine ),
|
||||
video_console.m_colTextColor,
|
||||
video_console.m_Lines[nTextLine], 0.0f );
|
||||
|
||||
nTextLine = ( nTextLine + 1 ) % video_console.m_cScreenHeightVirtual;
|
||||
}
|
||||
|
||||
xdk360_video_font_end(&m_Font);
|
||||
}
|
||||
|
||||
HRESULT xdk360_console_init( LPCSTR strFontFileName, unsigned long colBackColor,
|
||||
unsigned long colTextColor)
|
||||
{
|
||||
xdk360_video_t *vid = (xdk360_video_t*)g_d3d;
|
||||
D3DDevice *m_pd3dDevice = vid->xdk360_render_device;
|
||||
|
||||
video_console.first_message = true;
|
||||
video_console.m_Buffer = NULL;
|
||||
video_console.m_Lines = NULL;
|
||||
video_console.m_nScrollOffset = 0;
|
||||
|
||||
// Calculate the safe area
|
||||
unsigned int uiSafeAreaPct = vid->video_mode.fIsHiDef ? SAFE_AREA_PCT_HDTV
|
||||
: SAFE_AREA_PCT_4x3;
|
||||
|
||||
video_console.m_cxSafeArea = ( vid->d3dpp.BackBufferWidth * uiSafeAreaPct ) / 100;
|
||||
video_console.m_cySafeArea = ( vid->d3dpp.BackBufferHeight * uiSafeAreaPct ) / 100;
|
||||
|
||||
video_console.m_cxSafeAreaOffset = ( vid->d3dpp.BackBufferWidth - video_console.m_cxSafeArea ) / 2;
|
||||
video_console.m_cySafeAreaOffset = ( vid->d3dpp.BackBufferHeight - video_console.m_cySafeArea ) / 2;
|
||||
|
||||
// Create the font
|
||||
HRESULT hr = xdk360_video_font_init(&m_Font, strFontFileName );
|
||||
if( FAILED( hr ) )
|
||||
{
|
||||
SSNES_ERR( "Could not create font.\n" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Save the colors
|
||||
video_console.m_colBackColor = colBackColor;
|
||||
video_console.m_colTextColor = colTextColor;
|
||||
|
||||
// Calculate the number of lines on the screen
|
||||
float fCharWidth, fCharHeight;
|
||||
xdk360_video_font_get_text_width(&m_Font, L"i", &fCharWidth, &fCharHeight, FALSE);
|
||||
|
||||
video_console.m_cScreenHeight = (unsigned int)( video_console.m_cySafeArea / fCharHeight );
|
||||
video_console.m_cScreenWidth = (unsigned int)( video_console.m_cxSafeArea / fCharWidth );
|
||||
|
||||
video_console.m_cScreenHeightVirtual = video_console.m_cScreenHeight;
|
||||
|
||||
video_console.m_fLineHeight = fCharHeight;
|
||||
|
||||
// Allocate memory to hold the lines
|
||||
video_console.m_Buffer = new wchar_t[ video_console.m_cScreenHeightVirtual * ( video_console.m_cScreenWidth + 1 ) ];
|
||||
video_console.m_Lines = new wchar_t *[ video_console.m_cScreenHeightVirtual ];
|
||||
|
||||
// Set the line pointers as indexes into the buffer
|
||||
for( unsigned int i = 0; i < video_console.m_cScreenHeightVirtual; i++ )
|
||||
video_console.m_Lines[ i ] = video_console.m_Buffer + ( video_console.m_cScreenWidth + 1 ) * i;
|
||||
|
||||
video_console.m_nCurLine = 0;
|
||||
video_console.m_cCurLineLength = 0;
|
||||
memset( video_console.m_Buffer, 0, video_console.m_cScreenHeightVirtual * ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) );
|
||||
xdk360_console_draw();
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
void xdk360_console_deinit()
|
||||
{
|
||||
// Delete the memory we've allocated
|
||||
if(video_console.m_Lines)
|
||||
{
|
||||
delete[] video_console.m_Lines;
|
||||
video_console.m_Lines = NULL;
|
||||
}
|
||||
|
||||
if(video_console.m_Buffer)
|
||||
{
|
||||
delete[] video_console.m_Buffer;
|
||||
video_console.m_Buffer = NULL;
|
||||
}
|
||||
|
||||
// Destroy the font
|
||||
xdk360_video_font_deinit(&m_Font);
|
||||
}
|
||||
|
||||
void xdk360_console_add( wchar_t wch )
|
||||
{
|
||||
// If this is a newline, just increment lines and move on
|
||||
if( wch == L'\n' )
|
||||
{
|
||||
video_console.m_nCurLine = ( video_console.m_nCurLine + 1 )
|
||||
% video_console.m_cScreenHeightVirtual;
|
||||
video_console.m_cCurLineLength = 0;
|
||||
memset(video_console.m_Lines[video_console.m_nCurLine], 0,
|
||||
( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) );
|
||||
return;
|
||||
}
|
||||
|
||||
int bIncrementLine = FALSE; // Whether to wrap to the next line
|
||||
|
||||
if( video_console.m_cCurLineLength == video_console.m_cScreenWidth )
|
||||
bIncrementLine = TRUE;
|
||||
else
|
||||
{
|
||||
// Try to append the character to the line
|
||||
video_console.m_Lines[ video_console.m_nCurLine ]
|
||||
[ video_console.m_cCurLineLength ] = wch;
|
||||
|
||||
float fTextWidth, fTextHeight;
|
||||
xdk360_video_font_get_text_width(&m_Font, video_console.m_Lines[ video_console.m_nCurLine ], &fTextWidth, &fTextHeight, 0);
|
||||
if( fTextHeight > video_console.m_cxSafeArea )
|
||||
{
|
||||
// The line is too long, we need to wrap the character to the next line
|
||||
video_console.m_Lines[video_console.m_nCurLine]
|
||||
[ video_console.m_cCurLineLength ] = L'\0';
|
||||
bIncrementLine = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// If we need to skip to the next line, do so
|
||||
if( bIncrementLine )
|
||||
{
|
||||
video_console.m_nCurLine = ( video_console.m_nCurLine + 1 )
|
||||
% video_console.m_cScreenHeightVirtual;
|
||||
video_console.m_cCurLineLength = 0;
|
||||
memset( video_console.m_Lines[video_console.m_nCurLine],
|
||||
0, ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) );
|
||||
video_console.m_Lines[video_console.m_nCurLine ][0] = wch;
|
||||
}
|
||||
|
||||
video_console.m_cCurLineLength++;
|
||||
}
|
||||
|
||||
void xdk360_console_format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... )
|
||||
{
|
||||
video_console.m_nCurLine = 0;
|
||||
video_console.m_cCurLineLength = 0;
|
||||
memset( video_console.m_Buffer, 0,
|
||||
video_console.m_cScreenHeightVirtual *
|
||||
( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) );
|
||||
|
||||
va_list pArgList;
|
||||
va_start( pArgList, strFormat );
|
||||
|
||||
// Count the required length of the string
|
||||
unsigned long dwStrLen = _vscprintf( strFormat, pArgList ) + 1;
|
||||
// +1 = null terminator
|
||||
char * strMessage = ( char * )_malloca( dwStrLen );
|
||||
vsprintf_s( strMessage, dwStrLen, strFormat, pArgList );
|
||||
|
||||
// Output the string to the console
|
||||
unsigned long uStringLength = strlen( strMessage );
|
||||
for( unsigned long i = 0; i < uStringLength; i++ )
|
||||
{
|
||||
wchar_t wch;
|
||||
int ret = MultiByteToWideChar( CP_ACP, // ANSI code page
|
||||
0, // No flags
|
||||
&strMessage[i], // Character to convert
|
||||
1, // Convert one byte
|
||||
&wch, // Target wide character buffer
|
||||
1 ); // One wide character
|
||||
xdk360_console_add( wch );
|
||||
}
|
||||
|
||||
_freea( strMessage );
|
||||
|
||||
va_end( pArgList );
|
||||
}
|
||||
|
||||
void xdk360_console_format_w(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... )
|
||||
{
|
||||
video_console.m_nCurLine = 0;
|
||||
video_console.m_cCurLineLength = 0;
|
||||
memset( video_console.m_Buffer, 0, video_console.m_cScreenHeightVirtual
|
||||
* ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) );
|
||||
|
||||
va_list pArgList;
|
||||
va_start( pArgList, wstrFormat );
|
||||
|
||||
// Count the required length of the string
|
||||
unsigned long dwStrLen = _vscwprintf( wstrFormat, pArgList ) + 1; // +1 = null terminator
|
||||
wchar_t * strMessage = ( wchar_t * )_malloca( dwStrLen * sizeof( wchar_t ) );
|
||||
vswprintf_s( strMessage, dwStrLen, wstrFormat, pArgList );
|
||||
|
||||
// Output the string to the console
|
||||
unsigned long uStringLength = wcslen( strMessage );
|
||||
for( unsigned long i = 0; i < uStringLength; i++ )
|
||||
xdk360_console_add( strMessage[i] );
|
||||
|
||||
_freea( strMessage );
|
||||
|
||||
va_end( pArgList );
|
||||
}
|
||||
|
||||
#define CALCFONTFILEHEADERSIZE(x) ( sizeof(unsigned long) + (sizeof(float)* 4) + sizeof(unsigned short) + (sizeof(wchar_t)*(x)) )
|
||||
#define FONTFILEVERSION 5
|
||||
|
||||
@ -53,7 +271,6 @@ static const char g_strFontShader[] =
|
||||
"float2 Tex : TEXCOORD0;\n"
|
||||
"float4 ChannelSelector : TEXCOORD1;\n"
|
||||
"};\n"
|
||||
// "\n"
|
||||
"struct VS_OUT\n"
|
||||
"{\n"
|
||||
"float4 Position : POSITION;\n"
|
||||
@ -61,12 +278,9 @@ static const char g_strFontShader[] =
|
||||
"float2 TexCoord0 : TEXCOORD0;\n"
|
||||
"float4 ChannelSelector : TEXCOORD1;\n"
|
||||
"};\n"
|
||||
// "\n"
|
||||
"uniform float4 Color : register(c1);\n"
|
||||
"uniform float2 TexScale : register(c2);\n"
|
||||
// "\n"
|
||||
"sampler FontTexture : register(s0);\n"
|
||||
// "\n"
|
||||
"VS_OUT FontVertexShader( VS_IN In )\n"
|
||||
"{\n"
|
||||
"VS_OUT Out;\n"
|
||||
@ -80,36 +294,15 @@ static const char g_strFontShader[] =
|
||||
"Out.ChannelSelector = In.ChannelSelector;\n"
|
||||
"return Out;\n"
|
||||
"}\n"
|
||||
// "\n"
|
||||
"float4 FontPixelShader( VS_OUT In ) : COLOR0\n"
|
||||
"{\n"
|
||||
// "// Fetch a texel from the font texture\n"
|
||||
"float4 FontTexel = tex2D( FontTexture, In.TexCoord0 );\n"
|
||||
// "\n"
|
||||
"if( dot( In.ChannelSelector, float4(1,1,1,1) ) )\n"
|
||||
"{\n"
|
||||
// "// Select the color from the channel\n"
|
||||
"float value = dot( FontTexel, In.ChannelSelector );\n"
|
||||
// "\n"
|
||||
// "// For white pixels, the high bit is 1 and the low\n"
|
||||
// "// bits are luminance, so r0.a will be > 0.5. For the\n"
|
||||
// "// RGB channel, we want to lop off the msb and shift\n"
|
||||
// "// the lower bits up one bit. This is simple to do\n"
|
||||
// "// with the _bx2 modifier. Since these pixels are\n"
|
||||
// "// opaque, we emit a 1 for the alpha channel (which\n"
|
||||
// "// is 0.5 x2 ).\n"
|
||||
// "\n"
|
||||
// "// For black pixels, the high bit is 0 and the low\n"
|
||||
// "// bits are alpha, so r0.a will be < 0.5. For the RGB\n"
|
||||
// "// channel, we emit zero. For the alpha channel, we\n"
|
||||
// "// just use the x2 modifier to scale up the low bits\n"
|
||||
// "// of the alpha.\n"
|
||||
"float4 Color;\n"
|
||||
"Color.rgb = ( value > 0.5f ? 2*value-1 : 0.0f );\n"
|
||||
"Color.a = 2 * ( value > 0.5f ? 1.0f : value );\n"
|
||||
// "\n"
|
||||
// "// Return the texture color modulated with the vertex\n"
|
||||
// "// color\n"
|
||||
"return Color * In.Diffuse;\n"
|
||||
"}\n"
|
||||
"else\n"
|
@ -16,11 +16,40 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SSNES360_DEBUG_FONTS_H
|
||||
#define _SSNES360_DEBUG_FONTS_H
|
||||
#ifndef SSNES_360_FONTS_H
|
||||
#define SSNES_360_FONTS_H
|
||||
|
||||
#include "xdk360_video_resources.h"
|
||||
|
||||
#define PAGE_UP (255)
|
||||
#define PAGE_DOWN (-255)
|
||||
|
||||
#define SCREEN_SIZE_X_DEFAULT 640
|
||||
#define SCREEN_SIZE_Y_DEFAULT 480
|
||||
|
||||
#define SAFE_AREA_PCT_4x3 85
|
||||
#define SAFE_AREA_PCT_HDTV 90
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float m_fLineHeight; // height of a single line in pixels
|
||||
unsigned int m_nScrollOffset; // offset to display text (in lines)
|
||||
unsigned int first_message;
|
||||
unsigned int m_cxSafeArea;
|
||||
unsigned int m_cySafeArea;
|
||||
unsigned int m_cxSafeAreaOffset;
|
||||
unsigned int m_cySafeAreaOffset;
|
||||
unsigned int m_nCurLine; // index of current line being written to
|
||||
unsigned int m_cCurLineLength; // length of the current line
|
||||
unsigned long m_colBackColor;
|
||||
unsigned long m_colTextColor;
|
||||
unsigned int m_cScreenHeight; // height in lines of screen area
|
||||
unsigned int m_cScreenHeightVirtual; // height in lines of text storage buffer
|
||||
unsigned int m_cScreenWidth; // width in characters
|
||||
wchar_t * m_Buffer; // buffer big enough to hold a full screen
|
||||
wchar_t ** m_Lines; // pointers to individual lines
|
||||
} video_console_t;
|
||||
|
||||
typedef struct GLYPH_ATTR
|
||||
{
|
||||
unsigned short tu1, tv1, tu2, tv2; // Texture coordinates for the image
|
||||
@ -73,6 +102,12 @@ typedef struct
|
||||
const GLYPH_ATTR* m_Glyphs; // Array of glyphs
|
||||
} xdk360_video_font_t;
|
||||
|
||||
HRESULT xdk360_console_init ( LPCSTR strFontFileName, D3DCOLOR colBackColor, D3DCOLOR colTextColor);
|
||||
void xdk360_console_deinit (void);
|
||||
void xdk360_console_format (_In_z_ _Printf_format_string_ LPCSTR strFormat, ... );
|
||||
void xdk360_console_format_w (_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... );
|
||||
void xdk360_console_draw (void);
|
||||
|
||||
HRESULT xdk360_video_font_init(xdk360_video_font_t * font, const char * strFontFileName);
|
||||
void xdk360_video_font_get_text_width(xdk360_video_font_t * font, const wchar_t * strText, float * pWidth, float * pHeight, int bFirstLineOnly);
|
||||
void xdk360_video_font_deinit(xdk360_video_font_t * font);
|
||||
@ -83,4 +118,4 @@ void xdk360_video_font_set_size(float x, float y);
|
||||
void xdk360_video_font_draw_text(xdk360_video_font_t * font, float fOriginX, float fOriginY, unsigned long dwColor,
|
||||
const wchar_t * strText, float fMaxPixelWidth );
|
||||
|
||||
#endif
|
||||
#endif
|
@ -19,7 +19,7 @@
|
||||
#ifndef _XDK360_VIDEO_H
|
||||
#define _XDK360_VIDEO_H
|
||||
|
||||
#include "xdk360_video_console.h"
|
||||
#include "fonts.h"
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
|
@ -1,242 +0,0 @@
|
||||
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2012 - Daniel De Matteis
|
||||
*
|
||||
* Some code herein may be based on code found in BSNES.
|
||||
*
|
||||
* SSNES is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with SSNES.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <xtl.h>
|
||||
#include <malloc.h>
|
||||
#include "xdk360_video.h"
|
||||
#include "xdk360_video_console.h"
|
||||
#include "xdk360_video_debugfonts.h"
|
||||
#include "../general.h"
|
||||
|
||||
static video_console_t video_console;
|
||||
static xdk360_video_font_t m_Font;
|
||||
|
||||
void xdk360_console_draw(void)
|
||||
{
|
||||
xdk360_video_t *vid = (xdk360_video_t*)g_d3d;
|
||||
D3DDevice *m_pd3dDevice = vid->xdk360_render_device;
|
||||
|
||||
// The top line
|
||||
unsigned int nTextLine = ( video_console.m_nCurLine -
|
||||
video_console.m_cScreenHeight + video_console.m_cScreenHeightVirtual -
|
||||
video_console.m_nScrollOffset + 1 )
|
||||
% video_console.m_cScreenHeightVirtual;
|
||||
|
||||
xdk360_video_font_begin(&m_Font);
|
||||
|
||||
for( unsigned int nScreenLine = 0; nScreenLine < video_console.m_cScreenHeight; nScreenLine++ )
|
||||
{
|
||||
xdk360_video_font_draw_text(&m_Font, (float)( video_console.m_cxSafeAreaOffset ),
|
||||
(float)( video_console.m_cySafeAreaOffset +
|
||||
video_console.m_fLineHeight * nScreenLine ),
|
||||
video_console.m_colTextColor,
|
||||
video_console.m_Lines[nTextLine], 0.0f );
|
||||
|
||||
nTextLine = ( nTextLine + 1 ) % video_console.m_cScreenHeightVirtual;
|
||||
}
|
||||
|
||||
xdk360_video_font_end(&m_Font);
|
||||
}
|
||||
|
||||
HRESULT xdk360_console_init( LPCSTR strFontFileName, unsigned long colBackColor,
|
||||
unsigned long colTextColor)
|
||||
{
|
||||
xdk360_video_t *vid = (xdk360_video_t*)g_d3d;
|
||||
D3DDevice *m_pd3dDevice = vid->xdk360_render_device;
|
||||
|
||||
video_console.first_message = true;
|
||||
video_console.m_Buffer = NULL;
|
||||
video_console.m_Lines = NULL;
|
||||
video_console.m_nScrollOffset = 0;
|
||||
|
||||
// Calculate the safe area
|
||||
unsigned int uiSafeAreaPct = vid->video_mode.fIsHiDef ? SAFE_AREA_PCT_HDTV
|
||||
: SAFE_AREA_PCT_4x3;
|
||||
|
||||
video_console.m_cxSafeArea = ( vid->d3dpp.BackBufferWidth * uiSafeAreaPct ) / 100;
|
||||
video_console.m_cySafeArea = ( vid->d3dpp.BackBufferHeight * uiSafeAreaPct ) / 100;
|
||||
|
||||
video_console.m_cxSafeAreaOffset = ( vid->d3dpp.BackBufferWidth - video_console.m_cxSafeArea ) / 2;
|
||||
video_console.m_cySafeAreaOffset = ( vid->d3dpp.BackBufferHeight - video_console.m_cySafeArea ) / 2;
|
||||
|
||||
// Create the font
|
||||
HRESULT hr = xdk360_video_font_init(&m_Font, strFontFileName );
|
||||
if( FAILED( hr ) )
|
||||
{
|
||||
SSNES_ERR( "Could not create font.\n" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Save the colors
|
||||
video_console.m_colBackColor = colBackColor;
|
||||
video_console.m_colTextColor = colTextColor;
|
||||
|
||||
// Calculate the number of lines on the screen
|
||||
float fCharWidth, fCharHeight;
|
||||
xdk360_video_font_get_text_width(&m_Font, L"i", &fCharWidth, &fCharHeight, FALSE);
|
||||
|
||||
video_console.m_cScreenHeight = (unsigned int)( video_console.m_cySafeArea / fCharHeight );
|
||||
video_console.m_cScreenWidth = (unsigned int)( video_console.m_cxSafeArea / fCharWidth );
|
||||
|
||||
video_console.m_cScreenHeightVirtual = video_console.m_cScreenHeight;
|
||||
|
||||
video_console.m_fLineHeight = fCharHeight;
|
||||
|
||||
// Allocate memory to hold the lines
|
||||
video_console.m_Buffer = new wchar_t[ video_console.m_cScreenHeightVirtual * ( video_console.m_cScreenWidth + 1 ) ];
|
||||
video_console.m_Lines = new wchar_t *[ video_console.m_cScreenHeightVirtual ];
|
||||
|
||||
// Set the line pointers as indexes into the buffer
|
||||
for( unsigned int i = 0; i < video_console.m_cScreenHeightVirtual; i++ )
|
||||
video_console.m_Lines[ i ] = video_console.m_Buffer + ( video_console.m_cScreenWidth + 1 ) * i;
|
||||
|
||||
video_console.m_nCurLine = 0;
|
||||
video_console.m_cCurLineLength = 0;
|
||||
memset( video_console.m_Buffer, 0, video_console.m_cScreenHeightVirtual * ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) );
|
||||
xdk360_console_draw();
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
void xdk360_console_deinit()
|
||||
{
|
||||
// Delete the memory we've allocated
|
||||
if(video_console.m_Lines)
|
||||
{
|
||||
delete[] video_console.m_Lines;
|
||||
video_console.m_Lines = NULL;
|
||||
}
|
||||
|
||||
if(video_console.m_Buffer)
|
||||
{
|
||||
delete[] video_console.m_Buffer;
|
||||
video_console.m_Buffer = NULL;
|
||||
}
|
||||
|
||||
// Destroy the font
|
||||
xdk360_video_font_deinit(&m_Font);
|
||||
}
|
||||
|
||||
void xdk360_console_add( wchar_t wch )
|
||||
{
|
||||
// If this is a newline, just increment lines and move on
|
||||
if( wch == L'\n' )
|
||||
{
|
||||
video_console.m_nCurLine = ( video_console.m_nCurLine + 1 )
|
||||
% video_console.m_cScreenHeightVirtual;
|
||||
video_console.m_cCurLineLength = 0;
|
||||
memset(video_console.m_Lines[video_console.m_nCurLine], 0,
|
||||
( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) );
|
||||
return;
|
||||
}
|
||||
|
||||
int bIncrementLine = FALSE; // Whether to wrap to the next line
|
||||
|
||||
if( video_console.m_cCurLineLength == video_console.m_cScreenWidth )
|
||||
bIncrementLine = TRUE;
|
||||
else
|
||||
{
|
||||
// Try to append the character to the line
|
||||
video_console.m_Lines[ video_console.m_nCurLine ]
|
||||
[ video_console.m_cCurLineLength ] = wch;
|
||||
|
||||
float fTextWidth, fTextHeight;
|
||||
xdk360_video_font_get_text_width(&m_Font, video_console.m_Lines[ video_console.m_nCurLine ], &fTextWidth, &fTextHeight, 0);
|
||||
if( fTextHeight > video_console.m_cxSafeArea )
|
||||
{
|
||||
// The line is too long, we need to wrap the character to the next line
|
||||
video_console.m_Lines[video_console.m_nCurLine]
|
||||
[ video_console.m_cCurLineLength ] = L'\0';
|
||||
bIncrementLine = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// If we need to skip to the next line, do so
|
||||
if( bIncrementLine )
|
||||
{
|
||||
video_console.m_nCurLine = ( video_console.m_nCurLine + 1 )
|
||||
% video_console.m_cScreenHeightVirtual;
|
||||
video_console.m_cCurLineLength = 0;
|
||||
memset( video_console.m_Lines[video_console.m_nCurLine],
|
||||
0, ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) );
|
||||
video_console.m_Lines[video_console.m_nCurLine ][0] = wch;
|
||||
}
|
||||
|
||||
video_console.m_cCurLineLength++;
|
||||
}
|
||||
|
||||
void xdk360_console_format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... )
|
||||
{
|
||||
video_console.m_nCurLine = 0;
|
||||
video_console.m_cCurLineLength = 0;
|
||||
memset( video_console.m_Buffer, 0,
|
||||
video_console.m_cScreenHeightVirtual *
|
||||
( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) );
|
||||
|
||||
va_list pArgList;
|
||||
va_start( pArgList, strFormat );
|
||||
|
||||
// Count the required length of the string
|
||||
unsigned long dwStrLen = _vscprintf( strFormat, pArgList ) + 1;
|
||||
// +1 = null terminator
|
||||
char * strMessage = ( char * )_malloca( dwStrLen );
|
||||
vsprintf_s( strMessage, dwStrLen, strFormat, pArgList );
|
||||
|
||||
// Output the string to the console
|
||||
unsigned long uStringLength = strlen( strMessage );
|
||||
for( unsigned long i = 0; i < uStringLength; i++ )
|
||||
{
|
||||
wchar_t wch;
|
||||
int ret = MultiByteToWideChar( CP_ACP, // ANSI code page
|
||||
0, // No flags
|
||||
&strMessage[i], // Character to convert
|
||||
1, // Convert one byte
|
||||
&wch, // Target wide character buffer
|
||||
1 ); // One wide character
|
||||
xdk360_console_add( wch );
|
||||
}
|
||||
|
||||
_freea( strMessage );
|
||||
|
||||
va_end( pArgList );
|
||||
}
|
||||
|
||||
void xdk360_console_format_w(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... )
|
||||
{
|
||||
video_console.m_nCurLine = 0;
|
||||
video_console.m_cCurLineLength = 0;
|
||||
memset( video_console.m_Buffer, 0, video_console.m_cScreenHeightVirtual
|
||||
* ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) );
|
||||
|
||||
va_list pArgList;
|
||||
va_start( pArgList, wstrFormat );
|
||||
|
||||
// Count the required length of the string
|
||||
unsigned long dwStrLen = _vscwprintf( wstrFormat, pArgList ) + 1; // +1 = null terminator
|
||||
wchar_t * strMessage = ( wchar_t * )_malloca( dwStrLen * sizeof( wchar_t ) );
|
||||
vswprintf_s( strMessage, dwStrLen, wstrFormat, pArgList );
|
||||
|
||||
// Output the string to the console
|
||||
unsigned long uStringLength = wcslen( strMessage );
|
||||
for( unsigned long i = 0; i < uStringLength; i++ )
|
||||
xdk360_console_add( strMessage[i] );
|
||||
|
||||
_freea( strMessage );
|
||||
|
||||
va_end( pArgList );
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
|
||||
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2012 - Daniel De Matteis
|
||||
*
|
||||
* Some code herein may be based on code found in BSNES.
|
||||
*
|
||||
* SSNES is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with SSNES.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef SSNES360_CONSOLE_H
|
||||
#define SSNES360_CONSOLE_H
|
||||
|
||||
#include <xtl.h>
|
||||
#include "xdk360_video_debugfonts.h"
|
||||
|
||||
#define PAGE_UP (255)
|
||||
#define PAGE_DOWN (-255)
|
||||
|
||||
#define SCREEN_SIZE_X_DEFAULT 640
|
||||
#define SCREEN_SIZE_Y_DEFAULT 480
|
||||
|
||||
#define SAFE_AREA_PCT_4x3 85
|
||||
#define SAFE_AREA_PCT_HDTV 90
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float m_fLineHeight; // height of a single line in pixels
|
||||
unsigned int m_nScrollOffset; // offset to display text (in lines)
|
||||
unsigned int first_message;
|
||||
unsigned int m_cxSafeArea;
|
||||
unsigned int m_cySafeArea;
|
||||
unsigned int m_cxSafeAreaOffset;
|
||||
unsigned int m_cySafeAreaOffset;
|
||||
unsigned int m_nCurLine; // index of current line being written to
|
||||
unsigned int m_cCurLineLength; // length of the current line
|
||||
unsigned long m_colBackColor;
|
||||
unsigned long m_colTextColor;
|
||||
unsigned int m_cScreenHeight; // height in lines of screen area
|
||||
unsigned int m_cScreenHeightVirtual; // height in lines of text storage buffer
|
||||
unsigned int m_cScreenWidth; // width in characters
|
||||
wchar_t * m_Buffer; // buffer big enough to hold a full screen
|
||||
wchar_t ** m_Lines; // pointers to individual lines
|
||||
} video_console_t;
|
||||
|
||||
HRESULT xdk360_console_init ( LPCSTR strFontFileName, D3DCOLOR colBackColor, D3DCOLOR colTextColor);
|
||||
void xdk360_console_deinit (void);
|
||||
void xdk360_console_format (_In_z_ _Printf_format_string_ LPCSTR strFormat, ... );
|
||||
void xdk360_console_format_w (_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... );
|
||||
void xdk360_console_draw (void);
|
||||
|
||||
#endif
|
@ -33,7 +33,6 @@ struct XPR_HEADER
|
||||
};
|
||||
|
||||
#define XPR2_MAGIC_VALUE (0x58505232)
|
||||
#define eXALLOCAllocatorId_AtgResource eXALLOCAllocatorId_GameMax
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Name: PackedResource
|
||||
@ -120,7 +119,7 @@ HRESULT PackedResource::Create( const char * strFilename )
|
||||
m_dwSysMemDataSize = 0;
|
||||
return E_FAIL;
|
||||
}
|
||||
m_pVidMemData = ( BYTE* )XMemAlloc( m_dwVidMemDataSize, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_AtgResource,
|
||||
m_pVidMemData = ( BYTE* )XMemAlloc( m_dwVidMemDataSize, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_GameMax,
|
||||
XALLOC_PHYSICAL_ALIGNMENT_4K, XALLOC_MEMPROTECT_WRITECOMBINE, 0, XALLOC_MEMTYPE_PHYSICAL ) );
|
||||
|
||||
if( m_pVidMemData == NULL )
|
||||
@ -179,7 +178,7 @@ void PackedResource::Destroy()
|
||||
m_dwSysMemDataSize = 0L;
|
||||
|
||||
if( m_pVidMemData != NULL )
|
||||
XMemFree( m_pVidMemData, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_AtgResource,
|
||||
XMemFree( m_pVidMemData, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_GameMax,
|
||||
0, 0, 0, XALLOC_MEMTYPE_PHYSICAL ) );
|
||||
|
||||
m_pVidMemData = NULL;
|
||||
|
@ -283,13 +283,12 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\360\file_browser.c" />
|
||||
<ClCompile Include="..\..\360\fonts.cpp" />
|
||||
<ClCompile Include="..\..\360\main.c" />
|
||||
<ClCompile Include="..\..\360\xdk360_audio.cpp" />
|
||||
<ClCompile Include="..\..\360\xdk360_input.cpp" />
|
||||
<ClCompile Include="..\..\360\xdk360_video.cpp" />
|
||||
<ClCompile Include="..\..\360\menu.cpp" />
|
||||
<ClCompile Include="..\..\360\xdk360_video_console.cpp" />
|
||||
<ClCompile Include="..\..\360\xdk360_video_debugfonts.cpp" />
|
||||
<ClCompile Include="..\..\360\xdk360_video_resources.cpp" />
|
||||
<ClCompile Include="..\..\audio\hermite.c" />
|
||||
<ClCompile Include="..\..\audio\utils.c" />
|
||||
|
@ -131,13 +131,10 @@
|
||||
<ClCompile Include="..\..\console\main_wrap.c">
|
||||
<Filter>Source Files\console</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\360\xdk360_video_debugfonts.cpp">
|
||||
<Filter>Source Files\360</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\360\xdk360_video_resources.cpp">
|
||||
<Filter>Source Files\360</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\360\xdk360_video_console.cpp">
|
||||
<ClCompile Include="..\..\360\fonts.cpp">
|
||||
<Filter>Source Files\360</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
|
Loading…
x
Reference in New Issue
Block a user