Skip to content
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
Binary file added SSFN/consolas.sfn
Binary file not shown.
Binary file added SSFN/consolas.ttf
Binary file not shown.
Binary file added SSFN/sfnconv.exe
Binary file not shown.
Binary file added SSFN/sfnedit.exe
Binary file not shown.
127 changes: 99 additions & 28 deletions src/XDON-OG/XDON/XDON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@

#include "stdafx.h"
#include "XDON.h"
#include "font.h"

#define SSFN_IMPLEMENTATION
#define SFFN_MAXLINES 8192
#define SSFN_memcmp memcmp
#define SSFN_memset memset
#define SSFN_realloc realloc
#define SSFN_free free
#include "ssfn.h"

#pragma region

XNADDR localAddr;
LPDIRECT3DDEVICE8 pd3dDevice;
LPDIRECT3DVERTEXBUFFER8 pVB;
LPDIRECT3DTEXTURE8 pTexture;
LPDIRECT3DTEXTURE8 pBackgroundTexture;
LPDIRECT3DTEXTURE8 pFontOverlayTexture;
//Order must match DEVICE_INDEX_INTERNAL.
DEVICE_INFO devices[] =
{
Expand Down Expand Up @@ -70,6 +80,61 @@ BOOLEAN writeTookPlaceOnHDD = FALSE;

#pragma region

void CreateFontOverlay(int width, int height)
{
ssfn_t fontContext;
memset(&fontContext, 0, sizeof(ssfn_t));
int result = ssfn_load(&fontContext, font_sfn);
assert(result == 0);

result = ssfn_select(&fontContext, SSFN_FAMILY_SERIF, "FreeSans", SSFN_STYLE_REGULAR, 64);
assert(result == 0);

HRESULT hr = D3DXCreateTexture(pd3dDevice, width, height, 1, 0, D3DFMT_LIN_A8R8G8B8, D3DPOOL_DEFAULT, &pFontOverlayTexture);
assert(!FAILED(hr));

D3DSURFACE_DESC surfaceDesc;
pFontOverlayTexture->GetLevelDesc(0, &surfaceDesc);

D3DLOCKED_RECT lockedRect;
hr = pFontOverlayTexture->LockRect(0, &lockedRect, NULL, 0);
assert(!FAILED(hr));

memset(lockedRect.pBits, 0x00, surfaceDesc.Size);

ssfn_buf_t buffer;
memset(&buffer, 0, sizeof(buffer));
buffer.ptr = (uint8_t*)lockedRect.pBits;
buffer.x = 10;
buffer.y = 100;
buffer.w = surfaceDesc.Width;
buffer.h = surfaceDesc.Height;
buffer.p = surfaceDesc.Width * 4;
buffer.bg = 0xff000000;
buffer.fg = 0xffffffff;

char ipStr[255];
sprintf(ipStr,
"IP Address: %u.%u.%u.%u",
(localAddr.ina.S_un.S_un_b.s_b1),
(localAddr.ina.S_un.S_un_b.s_b2),
(localAddr.ina.S_un.S_un_b.s_b3),
(localAddr.ina.S_un.S_un_b.s_b4)
);

char* message = ipStr;
int ret = 0;
while((ret = ssfn_render(&fontContext, &buffer, message)) > 0)
{
message += ret;
}

hr = pFontOverlayTexture->UnlockRect(0);
assert(!FAILED(hr));

ssfn_free(&fontContext);
}

VOID Print(PRINT_VERBOSITY_FLAG Verbosity, const PCHAR Format, ...)
{
if ((Verbosity & verbositySetting) != Verbosity) return;
Expand Down Expand Up @@ -484,9 +549,11 @@ VOID InitDisplay()
HRESULT hr = Direct3DCreate8(D3D_SDK_VERSION)->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice);
assert(!FAILED(hr));

hr = D3DXCreateTextureFromFileInMemory(pd3dDevice, img, imgSize, &pTexture);
hr = D3DXCreateTextureFromFileInMemory(pd3dDevice, img, imgSize, &pBackgroundTexture);
assert(!FAILED(hr));

CreateFontOverlay(width, height);

D3DXMATRIX matProj;
D3DXMatrixIdentity(&matProj);
hr = pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);
Expand All @@ -501,29 +568,9 @@ VOID InitDisplay()
D3DXMatrixIdentity(&matWorld);
hr = pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);
assert(!FAILED(hr));

VERTEX vertices[] =
{
{ -1.0f, 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f, 1.0f, 0.0f, 1.0f, 0.0f },
{ -1.0f, -1.0f, 0.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, 0.0f, 1.0f, 0.0f },
{ 1.0f, -1.0f, 0.0f, 1.0f, 1.0f },
{ -1.0f, -1.0f, 0.0f, 0.0f, 1.0f }
};
hr = pd3dDevice->CreateVertexBuffer(sizeof(vertices), 0, 0, 0, &pVB);
assert(!FAILED(hr));

PVERTEX pVertices;
hr = pVB->Lock(0, 0, (PBYTE*)&pVertices, 0);
assert(!FAILED(hr));
memcpy(pVertices, vertices, sizeof(vertices));

hr = pVB->Unlock();
assert(!FAILED(hr));

//On OG Xbox, we can get away with doing all this just once (no render loop).
if (pTexture == NULL)
if (pBackgroundTexture == NULL)
{
//Display a red screen if the image failed to load (usually a memory issue) to encourage people to report it so it can be investigated.
hr = pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DCOLOR_XRGB(255, 0, 0), 1.0f, 0);
Expand Down Expand Up @@ -561,14 +608,39 @@ VOID InitDisplay()
assert(!FAILED(hr));
hr = pd3dDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
assert(!FAILED(hr));
hr = pd3dDevice->SetStreamSource(0, pVB, sizeof(VERTEX));
hr = pd3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
assert(!FAILED(hr));
hr = pd3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
assert(!FAILED(hr));
hr = pd3dDevice->SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1);
assert(!FAILED(hr));
hr = pd3dDevice->SetTexture(0, pTexture);

VERTEX textureVertices[] =
{
{ -1.0f, 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f, 1.0f, 0.0f, 1.0f, 0.0f },
{ -1.0f, -1.0f, 0.0f, 0.0f, 1.0f },
{ 1.0f, 1.0f, 0.0f, 1.0f, 0.0f },
{ 1.0f, -1.0f, 0.0f, 1.0f, 1.0f },
{ -1.0f, -1.0f, 0.0f, 0.0f, 1.0f }
};
hr = pd3dDevice->SetTexture(0, pBackgroundTexture);
assert(!FAILED(hr));
hr = pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
hr = pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, textureVertices, sizeof(VERTEX));
assert(!FAILED(hr));

VERTEX fontOverlayVertices[] =
{
{ -1.0f, 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f, 1.0f, 0.0f, (float)width, 0.0f },
{ -1.0f, -1.0f, 0.0f, 0.0f, (float)height },
{ 1.0f, 1.0f, 0.0f, (float)width, 0.0f },
{ 1.0f, -1.0f, 0.0f, (float)width, (float)height },
{ -1.0f, -1.0f, 0.0f, 0.0f, (float)height }
};
hr = pd3dDevice->SetTexture(0, pFontOverlayTexture);
assert(!FAILED(hr));
hr = pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, fontOverlayVertices, sizeof(VERTEX));
}
hr = pd3dDevice->Present(NULL, NULL, NULL, NULL);
assert(!FAILED(hr));
Expand Down Expand Up @@ -1299,7 +1371,6 @@ VOID __cdecl main()
}
else if ((linkStatus & XNET_ETHERNET_LINK_10MBPS) == XNET_ETHERNET_LINK_10MBPS) Print(PRINT_VERBOSITY_FLAG_ESSENTIAL_AND_ERRORS, "Slow ethernet link detected.");

XNADDR localAddr;
DWORD status = XNetGetTitleXnAddr(&localAddr);
while (status == XNET_GET_XNADDR_PENDING)
{
Expand Down
12 changes: 9 additions & 3 deletions src/XDON-OG/XDON/XDON.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
Name="XboxDeploymentTool"/>
<Tool
Name="XboxImageTool"
StackSize="65536"
StackSize="0x40000"
IncludeDebugInfo="TRUE"
DontModifyHD="TRUE"
DontMountUD="TRUE"
Expand Down Expand Up @@ -112,7 +112,7 @@
Name="XboxDeploymentTool"/>
<Tool
Name="XboxImageTool"
StackSize="65536"
StackSize="0x40000"
DontModifyHD="TRUE"
DontMountUD="TRUE"
InsertFile="$(ProjectDir)BKND.png,BKND.png,R"
Expand Down Expand Up @@ -171,7 +171,7 @@
Name="XboxDeploymentTool"/>
<Tool
Name="XboxImageTool"
StackSize="65536"
StackSize="0x40000"
DontModifyHD="TRUE"
DontMountUD="TRUE"
InsertFile="$(ProjectDir)BKND.png,BKND.png,R"
Expand Down Expand Up @@ -200,6 +200,12 @@
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\font.h">
</File>
<File
RelativePath=".\ssfn.h">
</File>
<File
RelativePath=".\stdafx.h">
</File>
Expand Down
9 changes: 9 additions & 0 deletions src/XDON-OG/XDON/XboxExports.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@

#pragma once

typedef signed char int8_t;
typedef short int16_t;
typedef long int32_t;
typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef unsigned long long uint64_t;

#pragma region

#define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0]))
Expand Down
Loading