/*
 * @(#)SEQStructs.txt  1.1  2010-12-25
 *
 * Copyright (c) 2010 Werner Randelshofer, Immensee, Switzerland.
 * All rights reserved.
 *
 * You may not use, copy or modify this file, except in compliance with the
 * license agreement you entered into with Werner Randelshofer.
 * For details see accompanying license terms.
 */


/** Cyberpaint Sequence *.SEQ structs
 * http://www.atari-forum.com/wiki/index.php/ST_Picture_Formats
 */

/* ============================================
 *
 * Primitive Data Types
 *
 * ============================================
 */
/* Numbers */
typedef uint4   uint4_t;
typedef byte   int8_t;
typedef uint8   uint8_t;
typedef int   int16_t;
typedef uint16   uint16_t;
typedef charbyte   char_t;  //  8 bits unsigned
typedef ubyte   ubyte8_t;

typedef charbyte   CHAR;  //  8 bits unsigned
typedef ubyte  UBYTE;  //  8 bits unsigned
typedef short  WORD;   // 16 bits signed
typedef ushort UWORD;  // 16 bits unsigned
typedef ushort USHORT;  // 16 bits unsigned
typedef int    LONG;   // 32 bits signed
typedef uint   ULONG;  // 32 bits unsigned


/* Seq Header. 128 bytes. */
magic SeqHeader "SeqHeader";
description SeqHeader "Header", "Cyberpaint Sequence header.";

typedef struct {
    ubyte[2] magicNumber;       // [$FEDB or $FEDC]
    WORD version;           // version number
    LONG numberOfFrames;        // number of frames
    WORD speed;             // maybe given in a timebase of 6000 nanoseconds
    ubyte[16] reserved[7];
    ubyte[6] reserved;
} SeqHeader;

/* Frame offsets. (numberOfFrames * 4) bytes. */
magic FrameOffsets "FrameOffsets";
description FrameOffsets "Offsets", "Frame offsets.";

typedef struct {
  ULONG offset;
} frofOffset;

typedef struct {
  frofOffset[] frame;
} FrameOffsets;

/* Frame. 128+data.length bytes. */
magic Frame "Frame";
description Frame "Frame", "Frame";


/* Frame Header. 128 bytes. */
magic FrameHeader "FrameHeader";
description FrameHeader "Header", "Frame header.";

enum {
    copy=0,
    xor=1
} frhdOp;

enum {
    uncompressed=0,
    compressed=1
} frhdMthd;

typedef struct {
  ataricolor color;
} frhdColor;

enum {
  lowRes=0, // 320 x 200, 16 colors
  mediumRes=1, // 640 x 200, 4 colors
  highRes=2 // 640 x 400, 2 colors
} frhdResolution;

enum {
  dataIsValid=0x80,
  dataIsInvalid=0x0
} hdrColorAnimationFlags;

enum {
  animationIsOn=0x80,
  animationIsOff=0x0
} hdrColorAnimationActive;

typedef struct {
 uint8_t enum hdrColorAnimationFlags flags;
 uint4_t rangeStart;
 uint4_t rangeEnd;
 uint8_t enum hdrColorAnimationActive active;
 int8_t speeddir;
 uint16_t steps;
} ColorAnimation;


typedef struct {
    ubyte[2] type;              // (ignored?)
    WORD enum frhdResolution resolution;        // [always 0]
    frhdColor[16] palette;
    CHAR[12] filename;      // [usually "        .   "]
    ColorAnimation colorAnimation;
    WORD xOffset;           // x offset for this frame [0 - 319]
    WORD yOffset;           // y offset for this frame [0 - 199]
    WORD width;             // width of this frame, in pixels (may be 0, see below)
    WORD height;            // height of this frame, in pixels (may be 0, see below)
    UBYTE enum frhdOp operation;       // operation [0 = copy, 1 = exclusive or]
    UBYTE enum frhdMthd storageMethod; // storage method [0 = uncompressed, 1 = compressed]
    ULONG lengthOfData;      // length of data in bytes (if the data is compressed, this
                            // will be the size of the compressed data BEFORE decompression)
    ubyte[16] reserved[3];
    ubyte[12] reserved;
} FrameHeader;


/* Frame Body. */
magic FrameData "FrameData";
description FrameData "Data", "Frame data.";
