BT I: GFX format

Any developer realated stuff
Post Reply
tedious
Posts: 2
Joined: Wed Dec 23, 2009 2:44 am

BT I: GFX format

Post by tedious »

Some graphics in the intro sequence are encoded in the following runlength encoding (example: $5200, $5d00, $6800, $6d00, $9000, $9700, $9d00, $a300, $a800, $ae00):

First byte: tag for "Set position" instruction (default row 0, col 0)
Second byte: tag for run length instruction
Then comes image data, in 4 pixel (== 1 byte in multi-color mode) columns, wrapping around at the end of the column to the beginning of the next column. However, this in interlaced mode: The bytes map to every other line of the screen, at the end of the drawing area they wrap around to the second row. This can be changed with the set position tag. If that byte occurs, the next two bytes specify the row/col to continue drawing.

If a run length instruction byte occurs, the next byte says how often the byte after that one should be repeated (plus three more times).

Example program follows.

Code: Select all

#include <stdlib.h>
#include <stdio.h>
char *pixel[] = { "  ", "..", "--", "[]" };
#define ROWS 128
#define COLS 160
unsigned char screen[ROWS][COLS];
static int len;
unsigned char
safe_getchar ()
{
  int chr = getchar();
  if (chr == EOF)
    {
      fprintf (stderr, "premature EOF");
      exit (1);
    }
  len++;
  return (unsigned char) chr;
}


void
decode ()
{
  int row = 0;
  int col = 0;
  int val = 0;
  int run = 0;

  unsigned char tag_next_run;
  unsigned char tag_next_pos;

  tag_next_run = safe_getchar();
  tag_next_pos = safe_getchar();
  row = 0;
  col = 0;
  do
    {
      if (run == 0)
        {
          unsigned char chr = safe_getchar();

          if (chr == tag_next_run)
            {
              run = safe_getchar() + 3;
              val = safe_getchar();
              continue;
            }
          else if (chr == tag_next_pos)
            {
              row = safe_getchar();
              col = safe_getchar();
              if (col == 0xff)
                return;
              continue;
            }
          else
            val = chr;
        }
      else
        run--;

      screen[row][col / 4] = val;
      /* Interlaced */
      row += 2;
      if (row >= ROWS)
        {
          row -= ROWS;
          col += 4;
          if (col >= COLS)
            {
              row++;
              if (row >= 2)
                return;
              col = 0;
            }
        }
    }
  while (1);
}


int
main (int argc, char*argv[])
{
  int r;
  int c;
  int val;

  decode ();

  printf ("Length: 0x%04x\n", len);
  for (r = 0; r < ROWS; r++)
    {
      for (c = 0; c < COLS/4; c++)
        {
          val = screen[r][c];
          printf ("%s%s%s%s", pixel[(val >> 6) & 3], pixel[(val >> 4) & 3], pixel[(val >> 2)&3], pixel[val&3]);
        }
      printf ("\n");
    }
  return 0;
}
User avatar
ZeroZero
Posts: 286
Joined: Tue Mar 10, 2009 9:10 pm
Location: Germany

Post by ZeroZero »

Still trying to reproduce this on the in game gfx files, gfx is in files
NM50 to NM90...

Maybe you can help?

Careful, there must be some animation instrcutions in the gfx,
since some gfx are animated, e.g.
NM50, NM51 not animated
NM52, NM54 are animated
as examples....

NM50 GFX: Inside The Guild
NM51 GFX: Inside Garth's Equipment Shoppe
NM52 A GFX: Inside The Inn
NM54 A GFX: Inside Temple
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

I'll assume this pertains to the C64 version.

The animated images could be a series of still images (my avatar as an example is from the Tavern; it is 4 frames).
User avatar
ZeroZero
Posts: 286
Joined: Tue Mar 10, 2009 9:10 pm
Location: Germany

Post by ZeroZero »

Oh, I am sorry, yes of course I reflect to the CBM64 version.
Since you made up your avatar, you seem having made code to fully extract the C64 gfx/animation file format. Did you also manage to find the timing info for frame change, as well as the frame sequence information?

If so, would you mind to share this info? Preferably in this thread:
http://brotherhood.de/Bardstale/talefil ... .php?t=910

Do you know a person, who did the same with BT1 music format?

Excellent job anyway, tedious!
User avatar
ZeroZero
Posts: 286
Joined: Tue Mar 10, 2009 9:10 pm
Location: Germany

Post by ZeroZero »

Thanks to this thread of tedious, I was able to fully decode the gfx and animation format of BT1, C64 version (likely also apple version and likely also BT2 on C64 and apple).

I made a viewer for the BT1 C64 version and am about to extend it to become a full editor for new gfx/animations. It is written in VB6, so you probably need to run the installer in admin mode on Vista and higher, as well as on XP Pro and server systems. This is because at least the common dialogs ocx must be available to the program, further ocxs may follow...

The editor will automatically calculate the differences and create the appropriate sequences and also pack the new gfx back into BT1 format.

It works directly on D64 disk images of BT1, and it also brings a set of disks from the, imho best images, from the Arnold's collection, which can be created out of the program as many times as you wish. For that, and only for that, disk set I will also support to edit custom colors for the images NM50 to NM81. If anyone wants to try to modify the boot disk to store the custom colors in a different free place in memory and support custom colors for more images, I should be happy to replace the boot disk in the editor by that version.

On both disks, city and dungeon, is sufficient space, as well in directory entries, as also in free blocks, to support 80+ images, and the images do not need to be alike on the two disks, i.e. NM50 can be the guild on city disk, but can be a monster on dungeon disk. However, the unmodified original BT1 game relies on certain files for certain monster and building gfx, and I haven't yet found out where these tables are located. Anyway modified BT1 games can be a lot richer in gfx.

I am open now for suggestions on what gfx functions are needed in such an editor, but with respect of the resolution of 38 x 86 pixels of the gfx, please do not suggest silly features like "Blur" or such. Dots, lines, circles, fill and alike seem to be sufficient.
I am also open for other suggestions for general functions.
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

I actually took screenshots of the game running in VICE and made them into GIF images, then used Microsoft GIF animator to put the frames together. I guessed the framerates.

:?

Yeah.
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

I wish it didn't need Visual Basic, as it doesn't work for me.
ZeroZero wrote:Thanks to this thread of tedious, I was able to fully decode the gfx and animation format of BT1, C64 version (likely also apple version and likely also BT2 on C64 and apple).

I made a viewer for the BT1 C64 version and am about to extend it to become a full editor for new gfx/animations. It is written in VB6, so you probably need to run the installer in admin mode on Vista and higher, as well as on XP Pro and server systems. This is because at least the common dialogs ocx must be available to the program, further ocxs may follow...

The editor will automatically calculate the differences and create the appropriate sequences and also pack the new gfx back into BT1 format.

It works directly on D64 disk images of BT1, and it also brings a set of disks from the, imho best images, from the Arnold's collection, which can be created out of the program as many times as you wish. For that, and only for that, disk set I will also support to edit custom colors for the images NM50 to NM81. If anyone wants to try to modify the boot disk to store the custom colors in a different free place in memory and support custom colors for more images, I should be happy to replace the boot disk in the editor by that version.

On both disks, city and dungeon, is sufficient space, as well in directory entries, as also in free blocks, to support 80+ images, and the images do not need to be alike on the two disks, i.e. NM50 can be the guild on city disk, but can be a monster on dungeon disk. However, the unmodified original BT1 game relies on certain files for certain monster and building gfx, and I haven't yet found out where these tables are located. Anyway modified BT1 games can be a lot richer in gfx.

I am open now for suggestions on what gfx functions are needed in such an editor, but with respect of the resolution of 38 x 86 pixels of the gfx, please do not suggest silly features like "Blur" or such. Dots, lines, circles, fill and alike seem to be sufficient.
I am also open for other suggestions for general functions.
:x
User avatar
Darendor
Posts: 1502
Joined: Wed Jan 14, 2009 1:53 am
Location: Red Deer, Alberta, Canada

Post by Darendor »

So how does the animation for the intro screen work? Is it much the same way?
Post Reply