Announcement

Collapse
No announcement yet.

(Artemis) Fonts for PS2-side GUI

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • (Artemis) Fonts for PS2-side GUI

    There are basically three ways I could begin working on the PS2-side GUI.

    First, I could simply use the (hacky) scr_printf function included in the PS2SDK. This would keep the GUI fairly limited, and very primitive looking, but would be the easiest way of doing things. Perhaps I'll start this way, while I build the basic menu structure.

    Second, I could utilize the GS to draw fonts, or use something like BMP2C to convert bitmap fonts to raw C, and throw them around the screen in the right places. This is probably the way we'll eventually end up doing things, and is, as a purist might say, the "right" way to do it. However, this may be considerable work, if we're to have an original font, and a functional menu system that highlights/underlines/etc the selected item(s).

    Third, I could look into FONTM, something documented by [RO]man and adresd. Apparently, there is a built-in PS2 font in OSDSYS, but there are three possible issues with following this route: the font is probably about as primitive as the scr_printf one, there may be legal issues with loading FONTM, as it's likely Sony intellectual property, and it's rumored that it may not exist, or may be different, on a few PS2 models (though it has been tested on several models, and no one's verified a failure as far as I can see). Anyway, here's what I have on it (I forget where I grabbed this from, a year or so ago):

    Description of file format for 'FONTM' from the PS2 BIOS.
    ---------------------------------------------------------
    adresd 2003.

    Intro
    -----
    The FONTM file contains a PS2 Font, in a format which allows access to individual characters without having to upload a big font bitmap. As each character is stored seperately.
    The font contains over 4000 characters, of all types and languages, and non-textual characters as well.
    This allows flexible use and the characters to be used any way in which the programmer wishes.

    The FONTM file is packed, the depack algorithm and example code have been provided by [RO]man on the site: http://ps2dev.pgamers.com/ in the file 'unpack.zip'.
    Rather than duplicate it here, grab from there.
    [Quick greet to [RO]man and the good work he has done ]
    This should be used to depack the file before trying to use the supplied extractor test program, or using it as reference to this document.

    After hearing many people wonder about the format of these files and using them, as they quite like the fonts, I decided to write this short doc and example code.
    I hope this is of some use to someone.

    The fonts in the files I examined were all 4bit CLUT.
    The CLUT does not seem to be included in here, and is probably elsewhere.
    That does not matter too much as it seems an intensity based CLUT, so creating one will not be hard.

    One thing to note, it has been pointed out that this file may not be consistent across ALL ps2 models, and may be a different format or missing on some models.
    I do not have details of this, but until it is verified take this into consideration.

    I've tested it on my SCPH-10000 (japanese) and SCPH-30003R (pal) machines.
    It's also been tested on a SCPH-50000 (japanese) and SCPH-35001 (US).

    Data Format
    -----------
    In this doc, uint32 means: 4 bytes, A,B,C,D
    value = (A) + (B<<8) + (C<<16) + (D<<24)

    The file contains a basic header
    --------------------------------
    4 ascii bytes 'FBJ2'
    4 bytes, uint32, version
    4 bytes, uint32, bitsize of file
    4 bytes, uint32, baseoffset
    4 bytes, uint32, num entries in the file
    4 bytes, uint32, end of file position

    Then follows the offset table
    -----------------------------
    Each entry is 4 bytes (uint32), making up an offset.
    Take this offset add this to the baseoffset from the header, this gives the absolute offset in the file.
    There are 'num entries' offsets in a list.

    The size of each entry can be taken from the difference between offsets, and seems to be the same for all entries in the file. So calculate difference between first and second entries, and that will give the size.

    Then follows the actual data for each character
    -----------------------------------------------
    This is 4bit CLUT data.
    A line of the font graphic is 13 bytes.
    each byte represents two pixels, so for 0x43 pixel 1 is color 4, pixel 2 is color 3.

    This means each pixel can have one of 16 values, 0x0 -> 0xf

    An example of a character is given below (NOTE:this is not from the actual file, but a madeup one).
    This is shown in HEX notation, as it makes it really easy to view.
    ----
    00000000000000000000000000
    01111111111111111111111110
    01200000000000000000000310
    01020000000000000000003010
    01002000000000000000030010
    01000200000000000000300010
    01000020000000000003000010
    01000002000000000030000010
    01000000200000000300000010
    01000000020000003000000010
    01000000002FFFF30000000010
    0100000000F2EE3F0000000010
    01FFFFFFFFFE23EFFFFFFFFF10
    01FFFFFFFFFE32EFFFFFFFFF10
    0100000000F3EE2F0000000010
    01000000003FFFF20000000010
    01000000030000002000000010
    01000000300000000200000010
    01000003000000000020000010
    01000030000000000002000010
    01000300000000000000200010
    01003000000000000000020010
    01030000000000000000002010
    01300000000000000000000210
    01111111111111111111111110
    00000000000000000000000000

    The example exporter/dump program
    ---------------------------------
    I have included a program, which will dump out the characters from the font file to a ascii version. You can set in the code which chars to dump out, or all of them.
    The ascii output is easy to view and I wanted to keep the src clean and easy to understand.

    I leave it as a simple exercise for the reader to write these out as bitmaps.
    Or to use the same format for similar data, and create new fonts.

    Thats all folks,
    adresd
    _____________________________________________

    The following is ANSI C (compile using DevCPP or some other C compiler, not PS2SDK):

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int  offsets[10000];
    
    unsigned int read_uint32(FILE *fp)
    {
      unsigned int address = fgetc(fp);
      address += (fgetc(fp)<<8);
      address += (fgetc(fp)<<16);
      address += (fgetc(fp)<<24);
      return (address);
    }
    
    //  This is for output of the 13 byte wide, 4 bit clut format entries
    //  writes them out as a HEX display, so you can see what the chars are
    void dump_chunk13(FILE *fp,int number)
    {
      int start, size, count;
      FILE *fp2;
      char filename[100];
    
      start = offsets[number];
      //  Go to start of chunk
      fseek(fp,start,SEEK_SET);
      //  work out size, by start of next chunk
      size = offsets[number+1] - offsets[number];
    
      sprintf(filename,"data_%04d.dat",number);
      printf("dumping chunk13 -  %d to '%s' (start %d , size %d)\n",number,filename,start,size);
      fp2 = fopen(filename,"wb");
    
      //  Write out the chunk  
      for(count=0;count<size;count++)
      {
        fprintf(fp2,"%02X",fgetc(fp));
        if (count%13 == 12) fprintf(fp2,"\n");
      }
      //  Cleanup
      fprintf(fp2,"\n");
      fclose(fp2);
    }
    
    int main(int argc,char *argv[])
    {
      FILE *fp; 
      char data[100];
      unsigned int address;
      int count;
      int maxcount;
      int baseoffset;
    
      if (argc == 2)
      {
        if ((fp = fopen(argv[1],"rb")) != 0)
        {
        fread(data,1,4,fp);  // This reads the header bytes
        data[4] = 0;
        printf("Header : '%s'\n",data);
    
        // Mini header first
        address = read_uint32(fp);     printf(" version : 0x%06X\n",address);
        address = read_uint32(fp);     printf(" bitsize : 0x%06X\n",address);
        baseoffset = read_uint32(fp);  printf(" baseoffset : 0x%06X\n",baseoffset);
        maxcount = read_uint32(fp);    printf(" num entries : 0x%06X\n",maxcount);
        address = read_uint32(fp);     printf(" end of file : 0x%06X\n",address);
        printf("max entries = %d\n",maxcount);
    
        // now read the offset entries
        for (count=0;count<maxcount;count++)
        {
          offsets[count] = baseoffset + read_uint32(fp);
        }
    
        // dump a few example chunks to test
        for (count=0;count<100;count++)
          dump_chunk13(fp,count);
        for (count=0;count<100;count++)
          dump_chunk13(fp,4000+count);
    
        fclose(fp);
        }
      } else printf("\nUsage : %s filename\n\n",argv[0]);
      return 1;
    }
    _________________________________________________

    Any thoughts or suggestions?
    I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

  • #2
    I'm pretty clueless when it comes to graphics and fonts, but aren't there any open source fonts we can use?

    Comment


    • #3
      I'm sure there are many. I'm not too worried about the particular font, but how we load it for maximum efficiency/versatility.
      I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

      Comment


      • #4
        I see. The only thing I know about PS2 graphics is how to patch the video mode and set the background color.

        So don't expect much help.

        Comment


        • #5
          No problem; I had mostly intended to take care of the graphical parts of Artemis by myself, unless I find someone else with some experience in that area.

          The reason I'm interested in FONTM is that you can load characters one at a time, and they're already on-board. This means both smaller filesize/less files and a smaller footprint on the system. Still, I don't even know how FONTM looks...it might suck, heh.
          I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

          Comment


          • #6
            Though I never got to working on fonts for Artemis thoroughly over the weekend, I've generated a set of several fonts I like, and I'll do some testing tonight, if I get the chance.
            I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

            Comment


            • #7
              Heh, it appears I've totally overlooked the fact that FONTM use is built-in to gsKit. I'll check that out a little later. In any case, looking at this (I'm behind a proxy at work, hence the cached version rather than the original):

              http://64.233.167.104/search?q=cache...ient=firefox-a

              It would appear FONTM can cause some serious DMA issues, including corrupting data in transit. Perhaps it was just used improperly (in fact, I'm sure that's what it was, but how exactly to use it properly, perhaps only a Sony developer would know), so I'll still take a look.

              I've made a complete set of font bitmaps for all the fonts I think might look decent for Artemis, in both 256x256 and 256x128 configurations, and generated the corresponding C arrays (using a little batch file I wrote really helped speed up use of BMP2C, allowing relative batch conversion). I'll try to put them into action later.
              I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

              Comment


              • #8
                For now, I'm going to draw fonts using C arrays, and we'll probably end up sticking with that method. I've started putting together a demo of various fonts and styles that can be used for the PS2-side GUI, utilizing the g2 graphics library, by DreamTime; I'll post it here when it's decent enough for viewing, so we can get a good idea of what Artemis should look like.
                I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

                Comment


                • #9
                  A quick GUI font demo for Artemis is about 75% done...
                  I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

                  Comment


                  • #10
                    screen picts please
                    Cant stand the 32 bit and above gaming.
                    Gamers for the return of 2d sprite filled games!

                    Comment


                    • #11
                      When it's decent, I'll post the ELF, the source, and some shots. I'm working on it right now.
                      I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

                      Comment


                      • #12
                        OK, here's the first, quick and rough, demo of some various fonts that could be used for Artemis. Yes, I realized after already packing, packaging, and zipping, that the last two fonts need to have their font titles shifted a few dozen X-coords to the right, heh. It'll be fine, for this crappy demo

                        I've only captured two of them for this post, but there are twenty or so in the actual demo.

                        In the next version, I'll implement pads (controllers) for the sample transitions rather than increment-based delay timers, create some sample menu "pages", and perhaps add some graphics:

                        http://GSHI.org/downloads/Artemis_Fonts.zip



                        I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

                        Comment


                        • #13
                          I just got done testing the improvements to FONTM, using cosmito's fontm_scroll demo, and I must say, it's quite impressive. What happened was...

                          cheriff of PS2Dev.org started tinkering around a bit with FONTM after I mentioned issues with DMA, memory leaks, flickering, and incompatibility with PCSX2 (which is nice to use for testing). Though I wasn't necessarily asking for help as much as I was just bitching about it, this led to a back-and-forth between us concerning how to extract that data from your PS2, what tools are around to interpret it, implementation, etc. Meanwhile, cosmito and I were engaged in conversation concerning other aspects of Artemis, and by pure accident, I asked cosmito if he'd made any progress in FONTM research. He asked what I was talking about, I realized I'd sent that to him by mistake, and explained what cheriff and I were toying with, and he pointed me to two threads buried in PS2Dev.org's forums that he had just so happened to have been involved with (I think he started one of them, even), concerning the very issues I was struggling with.

                          It turns out that Mega Man discovered and fixed some issues in gsKit's FONTM implementation some time ago, but that the final part of the improvement was never committed to the PS2Dev.org SVN (I have admin rights on the main site there, but not SVN commit rights...I suppose I could bring the fix up, now that I know about it). After making the necessary modifications, I think that FONTM is now sufficient to be used in Artemis.

                          This means that we'll be able to reduce the file size of the ELF, and reduce the amount of memory taken up by fonts (FONTM allows you to load text one character at a time, rather than loading the entire alpha-numeric/character set at once), thus reducing the footprint of Artemis, for later, in-game, on-screen functionality. It also means we can have a good-looking font (it's the font built into the BIOS, which Sony uses for the memory card manager, etc), with LESS work than other methods.

                          I'll start playing with it as soon as I get a chance.
                          I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

                          Comment


                          • #14
                            Nice to see that you are still working on it and that its coming along. keep up the good work.

                            Comment


                            • #15
                              Ack, this has been fairly dormant for a while. I honestly haven't had enough time to properly figure out how to implement pads (controller input), which would really motivate me to put a proper skeleton GUI together, then progressively make it prettier and prettier.

                              I'll dig around a bit more, and/or ask for some pointers (or feel free to give me some).
                              I may be lazy, but I can...zzzZZZzzzZZZzzzZZZ...

                              Comment

                              Working...
                              X