+  RHDN Forum Archive
|-+  Romhacking
| |-+  ROM Hacking Discussion
| | |-+  PSX font & VRAM question
Pages: [1]
Author Topic: PSX font & VRAM question  (Read 1 times)
esperknight
Guest
« on: July 04, 2011, 03:33:02 pm »

I've recently been looking at some PSX games and I'm having trouble with one in particulatr called UFO : A Day in the Life.  I'm not sure how to backtrack from it accessing the font to find what it uses for the letters.  I can see the font is loaded in VRAM at 768,256 using Agemo's VRAM viewer.  I've read the vram doc for the PSX and also the incredibly detailed one as well so I know of how it access VRAM through the two ports but even with that I'm not understanding too much of how it copies it from one locaton to another.  I'm not sure if it reads it out of VRAM to RAM and then goes the other way or ...?  I tried using another game (Gunnm : Kasei No Kioku) where I could also see the font in VRAM and where I know it uses SJIS but no real luck there either as I'm not sure what I'm looking for.  Any help in pointing me in the right direction would be appreciated, thanks!
Gemini
Guest
« Reply #1 on: July 04, 2011, 05:29:28 pm »

Forget all the low level stuff, it's not necessary when it comes to RAM->VRAM transfers. Everything is basically reduced to calling this function in a way or another:
Code:
LoadImage:                               # CODE XREF: TEXT:loc_80011040p
                                         # TEXT:800110BCp ...

var_10          = -0x10
var_C           = -0xC
var_8           = -8

                addiu   $sp, -0x20
                sw      $s0, 0x20+var_10($sp)
                move    $s0, $a0
                sw      $s1, 0x20+var_C($sp)
                move    $s1, $a1
                li      $a0, 0x800565E8
                sw      $ra, 0x20+var_8($sp)
                jal     sub_80012018
                move    $a1, $s0
                move    $a1, $s0
                lw      $v0, off_8006AB2C
                li      $a2, 8
                lw      $a0, 0x20($v0)
                lw      $v0, 8($v0)
                nop
                jalr    $v0
                move    $a3, $s1
                lw      $ra, 0x20+var_8($sp)
                lw      $s1, 0x20+var_C($sp)
                lw      $s0, 0x20+var_10($sp)
                jr      $ra
                addiu   $sp, 0x20
This piece of code takes parameters assigned to a0 and a1, where a0 is the RECT structure pointing to VRAM coordinates and a1 is a pointer with the upload data.

Now, let's go back to your game. There are several cases of font upload, just like it used to be on the good ol' SNES:
  • Cached upload: read a character from the string, do some processing with the font in ram and upload a chunk to VRAM. This way you get to see an entire period loaded in VRAM and the game just maps sprites to each;
  • Bitmap: similar to cached, but it writes text pixels to an image in ram and then sends the whole thing to VRAM every whatever period (could be even once per frame);
  • Mapped: the entire font is always in ram (or just enough of it to render most symbols) and the game only needs to map a sprite to a said range of VRAM.
In the first two cases you've got to track the upload by breaking on string read or just LoadImage execution, in the second one you probably just need the string read break.
esperknight
Guest
« Reply #2 on: July 04, 2011, 06:21:58 pm »

Thanks!  That'll help in finding the font upload.  So when uploading to VRAM it uses X,Y coordinates rather than an exact pointer?  That explains then why in the VRAM viewer it lists everything in x,y coords.  I prob read this in those docs to but it didn't register.  I'm more use to specifying an address then coordinates.

For UFO, I noticed that when looking in VRAM it already has the entire font in there.  To use this, would it then extract it out from VRAM into RAM then use the above function to put it back in?  Or is there a way to do a transfer from one location in VRAM to another that I should be looking for?

I didn't even think about the BIOS calls, is there a document that lists them?  The long PSX doc here just as a TBA.  Would the BIOS call be the jalr to V0 loaded with $8006AB2C?  Thanks!

Edit :
Been playing around with Agemo's version of the PCSX debugger and was reading the debugger notes and saw that you can log the VRAM rights.  From there I found exactly what I think I need :

05E7B8:2C - FT4 (260, 168)*(15, 15) clut(0, 500) TP(768, 256)(bit:0) UV<(772, 272)*(15, 15)>(16, 16)*(15, 15) RGB( 4, 42, 84)

The TP conforms to the font in VRAM and the UV is the coordinates of the letter.  No idea what any of it means but hey Cheesy  (Well, I recognize clut at least Smiley )

Just to double check, would $5E7B8  be the code executing?  I can't find it in a trace but I'd imagine that would be in a bios function right?

Edit 2:

Figure out that's the location in memory it's reading.  Can't find it in a trace though so doesn't help me out so far...

Edit 3:

Last update Smiley  Turns out that I was logging the GPU stuff to early along with the ASM.  Seems that I was logging it after it's first print, and due to how it shifts the color I was capturing that.  So logging it a bit earlier I found the instance where it first captures the letter in to RAM (at least that's what I'm guessing it's doing which seems to be right Smiley  Tracing back from there I figured out the letters (which I was actually somewhat right on... turns out they were two byte anyways and I got the last half correct at least).  Now just need to figure out the print routine as the letters aren't in order so it accesses something else to jump around the table.

Thanks for your help!  And hopefully this helps someone else as well.
« Last Edit: July 05, 2011, 12:19:34 am by esperknight »
Pages: [1]  


Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC