OneLoneCoder / olcPixelGameEngine

The official distribution of olcPixelGameEngine, a tool used in javidx9's YouTube videos and projects
Other
3.83k stars 915 forks source link

Not an issue - Font suggestions. #361

Closed zxMarce closed 7 months ago

zxMarce commented 7 months ago

Hi.

I completed and "expanded" the rough NES emulator, but I wanted a more "familiar" font for PGE itself (DrawString()). By familiar, I mean my first machines' font, the T/S1000 and ZX Spectrum (yes, I'm THAT old).

I reverse-engineered PGE's font encoding algorithm, extracted the ZX font from the ROMs (hope it's not copyrighted!) and added it to PGE. The fonts can be switched at compile time by adding a simple #define in the main app .cpp file:

#define OLC_PGE_APPLICATION
//#define OLC_FONT_JAVIDX9       // Uncomment for original JavidX9 "arcade" font.
//#define OLC_FONT_ZXSPECTRUM    // Uncomment for original ZX Spectrum ROM font.
                                 // No #define means to use the modified ZX Spectrum ROM font.
#include "olcPixelGameEngine.h"

Don't think I can manage GIT intricacies for submitting patches or pull requests (I said I'm old, remember?), so I'll paste here my modded code in case anyone else wants this. The code is in the first lines of void PixelGameEngine::olc_ConstructFontSheet(). Note that, by default, PGE will use the third font definition: The ZX Spectrum ROM font with rounded-corners "$" character.

#if defined(OLC_FONT_JAVIDX9)
        /*
         * Original Javidx9's "arcade style" font.
         */
        data += "?Q`0001oOch0o01o@F40o0<AGD4090LAGD<090@A7ch0?00O7Q`0600>00000000";
        data += "O000000nOT0063Qo4d8>?7a14Gno94AA4gno94AaOT0>o3`oO400o7QN00000400";
        data += "Of80001oOg<7O7moBGT7O7lABET024@aBEd714AiOdl717a_=TH013Q>00000000";
        data += "720D000V?V5oB3Q_HdUoE7a9@DdDE4A9@DmoE4A;Hg]oM4Aj8S4D84@`00000000";
        data += "OaPT1000Oa`^13P1@AI[?g`1@A=[OdAoHgljA4Ao?WlBA7l1710007l100000000";
        data += "ObM6000oOfMV?3QoBDD`O7a0BDDH@5A0BDD<@5A0BGeVO5ao@CQR?5Po00000000";
        data += "Oc``000?Ogij70PO2D]??0Ph2DUM@7i`2DTg@7lh2GUj?0TO0C1870T?00000000";
        data += "70<4001o?P<7?1QoHg43O;`h@GT0@:@LB@d0>:@hN@L0@?aoN@<0O7ao0000?000";
        data += "OcH0001SOglLA7mg24TnK7ln24US>0PL24U140PnOgl0>7QgOcH0K71S0000A000";
        data += "00H00000@Dm1S007@DUSg00?OdTnH7YhOfTL<7Yh@Cl0700?@Ah0300700000000";
        data += "<008001QL00ZA41a@6HnI<1i@FHLM81M@@0LG81?O`0nC?Y7?`0ZA7Y300080000";
        data += "O`082000Oh0827mo6>Hn?Wmo?6HnMb11MP08@C11H`08@FP0@@0004@000000000";
        data += "00P00001Oab00003OcKP0006@6=PMgl<@440MglH@000000`@000001P00000000";
        data += "Ob@8@@00Ob@8@Ga13R@8Mga172@8?PAo3R@827QoOb@820@0O`0007`0000007P0";
        data += "O`000P08Od400g`<3V=P0G`673IP0`@3>1`00P@6O`P00g`<O`000GP800000000";
        data += "?P9PL020O`<`N3R0@E4HC7b0@ET<ATB0@@l6C4B0O`H3N7b0?P01L3R000000020";

#elif defined (OLC_FONT_ZXSPECTRUM)
        /*
         * New ZX Spectrum ROM font "as is".
         */
        data += "00000000?3`0o4Qn@V8097`BFU8094XBETX094XBFTH0648B73`004@<00000000";
        data += "00000000O000620l4T@095A24T9N95AB4Wh095AR4T00o7Q2O400P00l00000000";
        data += "00000000OV@0001nBU86N7hBBU8014PBBU8014PBBU8614Pb=4`0031<00000000";
        data += "00000000?2@TB00T@T9nE3Q:@T8TE4A:@TXTE4A:@TYn84A:93@T000`00000000";
        data += "00000002OS000302@RQL14P2@RAD?TQn@WknA4P2921D@7h2621d000200000000";
        data += "00000000ORi6?3PnBTXV@5A0BTX@@5A0BTX8@5A0BTYT?4Q0@S9R000n00000000";
        data += "00000000OS`P300N2TYD<00P2TY:@7a02TYD<0Y02TXP308P0S1@000N00000000";
        data += "00000000?080?1Pn@P80@:A0@V84>:@PDQ82@:@PDPX0?7a0=0H0000n00000000";
        data += "00000000OS@0A7i224X0:0PT24X040PH24Xl:0PH24Y2A70TOS@0001200000000";
        data += "0000000200`07004@U92X4P8@U8lX7Y`OU80X408@U80O004@S`0000200000000";
        data += "00000000<000A012@00@I41R@4QDE81B@00hC81:@01DA7Y6?P0@001200000000";
        data += "00000000OP000000280@27h026@@21P0501lMRAn8P0@@T12@00@@P1200000000";
        data += "00000000OP000004@0000008@12003h@@2QPOT0P@4@00410@000000000000000";
        data += "00000000OP00@Wa212P@@PA222P@MWQn22P@20@012P@27P0ORP@000000000000";
        data += "00000000OP0007`8100010@424AP0PAn42QP10@481000WP8OP00000000000000";
        data += "0000?020?0@0@SR0@P90VDB0@P8PYDB0@U8@YDB0@PX8PCR0?0@4@P200000?020";

#else
        /*
         * New ZX Spectrum ROM font with rounded "$" char.
         */
        data += "00000000?3`0o4Qn@V8097`BFU8094XBETX094XBFTH0648B73`004@<00000000";
        data += "00000000O000620l4T@095A24T9N95AB4Wh095AR4T00o7Q2O400P00l00000000";
        data += "00000000OV@0001nBU86N7hBBU8014PBBU8014PBBU8614Pb=4`0031<00000000";
        data += "00000000?2@TB00T@T9nE3Q:@T8TE4A:@TXTE4A:@TYn84A:93@T000`00000000";
        data += "00000002OS000302@RQ814P2@RAD?TQn@WknA4P2921D@7h2620T000200000000";
        data += "00000000ORi6?3PnBTXV@5A0BTX@@5A0BTX8@5A0BTYT?4Q0@S9R000n00000000";
        data += "00000000OS`P300N2TYD<00P2TY:@7a02TYD<0Y02TXP308P0S1@000N00000000";
        data += "00000000?080?1Pn@P80@:A0@V84>:@PDQ82@:@PDPX0?7a0=0H0000n00000000";
        data += "00000000OS@0A7i224X0:0PT24X040PH24Xl:0PH24Y2A70TOS@0001200000000";
        data += "0000000200`07004@U92X4P8@U8lX7Y`OU80X408@U80O004@S`0000200000000";
        data += "00000000<000A012@00@I41R@4QDE81B@00hC81:@01DA7Y6?P0@001200000000";
        data += "00000000OP000000280@27h026@@21P0501lMRAn8P0@@T12@00@@P1200000000";
        data += "00000000OP000004@0000008@12003h@@2QPOT0P@4@00410@000000000000000";
        data += "00000000OP00@Wa212P@@PA222P@MWQn22P@20@012P@27P0ORP@000000000000";
        data += "00000000OP0007`8100010@424AP0PAn42QP10@481000WP8OP00000000000000";
        data += "0000?020?0@0@SR0@P90VDB0@P8PYDB0@U8@YDB0@PX8PCR0?0@4@P200000?020";
#endif

By using this, pretty much any other 80's machine font may be adapted, as long as it uses an 8x8 pixel matrix.

Hope somebody finds this useful.

Thanks for the videos, Javidx9!

zxMarce commented 7 months ago

Closing issue marking it completed.

Moros1138 commented 7 months ago

I don't think it's particularly appropriate to embed potentially copyrighted fonts ripped from the roms of legacy systems. This practice could invite legal liability to the project and to Javid himself. Personally, I don't think it is worth the risk.

That said, I'm not sure if there's a mechanism currently in place for swapping out the default font in PGE. If not, it might be worth implementing one so people who want to use their own custom 8x8 fonts would be capable of doing so.

zxMarce commented 7 months ago

Moros1138,

You're absolutely right, and I thank you for your time.

While I do not really know whether the font is useable outside of the ROM, I do know that Amstrad's own Sir Alan Sugar (AFAIK Sinclair's current copyright owner) does allow free distribution of the ROM (his note is in www.WorldOfSpectrum.org). Nonetheless, this permission does not cover the point of extracting things (fonts, routines, constants, whatever) from the ROM.

I just wanted to contribute something to the project. If there is a way to remove this "non-issue", and the admins concur with your point, please be my guests and kill my notes.

Next time, I'll know better and ask first before posting.

Thanks again, zxMarce.