Giter Club home page Giter Club logo

nxdk-pdclib's Introduction

XboxDev

XboxDev is the place for all original Xbox projects to come together.

XboxDev is an effort to provide tools and documentation for the original Microsoft Xbox and Xbox-based SEGA Chihiro. We not only care about technical details about those platforms, but also how to develop homebrew and emulate them.

We are not interested in documenting the Xbox 360, Xbox One or any other console at this point.

You can create an issue to contact XboxDev maintainers.

Ecosystem

We currently provide the following services:

Want to help? Contact us!

Please come chat with us:

and for closely related projects:

You'll also get the details for XboxDevWiki account creation on any of these channels.

Coding style

The usual rule is: follow the existing code / commit style of whatever you are working on. If the previous commits use prefix style: use prefix style. If the surrounding code respects 80 column limit: respect it. If the surrounding code uses an unusual C style: mimic it.

Disclaimer

XboxDev is not affiliated with, endorsed by, or sponsored by Microsoft Corporation, Nvidia Corporation, licensed Xbox developers, publishers, manufacturers or any of their affiliates or subsidiaries. All product and company names are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.

Reverse engineering of the original software and hardware is done to achieve interoperability with other computing platforms. In the process, excerpts of the reverse engineered source code will be shown for educational purposes.

No copyright infringement is intended at any stage during creation of XboxDev software, hardware or documentation.

nxdk-pdclib's People

Contributors

devsolar avatar dracc avatar glebm avatar jayfoxrox avatar sam-itt avatar thrimbor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nxdk-pdclib's Issues

CMakeLists.txt points at missing file

18e3b16 introduced a bug which breaks CMake (which was added later in 4246158); this prevents running tests on non-Xbox platforms.

$ mkdir build
$ cd build
$ cmake ..
++ CMAKE_BUILD_TYPE not set. Defaulting to 'Debug'.
-- Configuring done
CMake Error at CMakeLists.txt:309 (add_library):
  Cannot find source file:

    functions/_PDCLIB/assert.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx

[...]

I'm not sure how to resolve this most gracefully.

Generally it feels like 18e3b16 shouldn't require changes to existing pdclib code. We have extension hooks now and there has always been the optimization overlay (which works as long as we don't use wildcards in our Makefiles).

sscanf() is broken (hangs / stores unexpected values)

This code (taken from Neverball) leads to faulty behaviour:

#ifdef NXDK
#include <hal/video.h>
#include <hal/debug.h>
#else
#define debugPrint(...) printf(__VA_ARGS__)
#endif
#include <stdio.h>

int main() {

#ifdef NXDK
  XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);
#endif

  const char* line = "fullscreen                0";

  int ks, ke, vs;

  ks = -1;
  ke = -1;
  vs = -1;

  debugPrint("Starting scan\n");

  int ret = sscanf(line, " %n%*s%n %n", &ks, &ke, &vs);

  debugPrint("Result %d = %d %d %d\n", ret, ks, ke, vs);

#ifdef NXDK
  while(1);
#else
  return 0;
#endif
}

On my desktop with clang I get:

Starting scan
Result 0 = 0 10 26

On nxdk (in XQEMU) I only get:

Starting scan

(it seems to hang before the second debugPrint is reached)

On nxdk (in XQEMU) I got this with an older revision of the code which didn't retrieve / print int ret:

Starting scan
Result 1701995379 1819047270 10

Probably a bug in pdclib? CC @DevSolar

tan() and tanf() seem broken

Both tan() and tanf() seem to return 0 or garbage on any inputs I've tested them with.

Sample code:

#define DEG2RAD(x) ((x) * M_PI / 180.0)
#define DEG2RADF(x) ((x) * (float)M_PI / 180.f)
#define FAKETAN(x) (sin((x)) / cos((x)))

const double testd1 = tan(DEG2RAD(45.0));
const double testd2 = tan(DEG2RAD(90.0));
const double testd3 = tan(DEG2RAD(0.0));
const double testd4 = tan(DEG2RAD(22.5));

const float testf1 = tanf(DEG2RADF(45.0f));
const float testf2 = tanf(DEG2RADF(90.0f));
const float testf3 = tanf(DEG2RADF(0.0f));
const float testf4 = tanf(DEG2RADF(22.5f));

const double testc1 = FAKETAN(DEG2RAD(45.0));
const double testc2 = FAKETAN(DEG2RAD(90.0));
const double testc3 = FAKETAN(DEG2RAD(0.0));
const double testc4 = FAKETAN(DEG2RAD(22.5));

gdb output when running in xqemu, code compiled with DEBUG=y and inserted into the hello sample:

(gdb) p testd1
$2 = 0
(gdb) p testd2
$3 = 0
(gdb) p testd3
$4 = 0
(gdb) p testd4
$5 = 0
(gdb) p testf1
$6 = 0
(gdb) p testf2
$7 = 0
(gdb) p testf3
$8 = 0
(gdb) p testf4
$9 = 1.55740774
(gdb) p testc1
$10 = 0.99999999999999989
(gdb) p testc2
$11 = 16331778728383844
(gdb) p testc3
$12 = 0
(gdb) p testc4
$13 = 0.41421356237309509

Output from real hardware, built with my nxdk fork and added debugPrints (not sure if my float formatter is very correct):

testd1 = nan
testd2 = nan
testd3 = nan
testd4 = nan
testf1 = nan
testf2 = nan
testf3 = nan
testf4 = nan
testc1 = 1.000000
testc2 = 1.633178e+16
testc3 = 0.000000
testc4 = 0.414214

Use DbgPrint in place of internal `_PDCLIB_print`

Attempting to minimize executable size, PDClib' print function uses a fair amount of space and is frankly unneeded, also as far as I can tell these aren't actually printed anywhere to the user(?), either the screen or via serial port. So it should be replaced with a call to DbgPrint.

int main(void)
{
    for(;;) {
        DbgPrint("Hello\n");
    }
    return 0;
}
LTO = y
CFLAGS += -Oz -DNDEBUG
CXXFLAGS += -Oz -DNDEBUG
NXDK_CFLAGS += -Oz -DNDEBUG
NXDK_CXXFLAGS += -Oz -DNDEBUG

As is, this results in a 32KB binary. Nuking the while loops in vfprintf and vsnprintf we end up with 28KB.

math.h is not optimized for Xbox

I was surprised to find that trunc is done using x87 by modifying the control word.

Xbox should have SSE, so we can use faster methods like these http://wurstcaptures.untergrund.net/assembler_tricks.html

This isn't necessarily much faster, but hopefully shorter code which is easier to read (and step through).

We should also review other math.h funtions like round. Also possibly affects #7 (future floor implementation).

I think we can safely ignore any precision issues beyond 32 / 64 bit IEEE float.

`pow()` leads to issues in SDL2 audio conversion

See XboxDev/nxdk-sdl#20 (comment)

Additionally, I noticed that the math functions don't have any copyright header or note where they stem from / wether they were tested; this makes it hard to analyze / report such issues.

It is worth noting that the code for different precisions is exactly the same (except for type suffix on float constants). I'm not sure if this is enough / correct.

I also believe we never set up or check the control words for precision (I expected this in crt0). So it might be possible to get different results on different runs, depending on how the XBE was started?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.