=== Basics

Sprites and fonts are located in dat files: charset.dat, goal1.dat, team1.dat,
team2.dat etc. Sprite.dat contains offsets for sprites, and after fix up all
that's needed to access any sprite is to index into this file. First 227
sprites are the sprites needed while the menu system is active (fonts, little
player images, faces, etc.).

Sprites are stored in bit-coded form, and they must be "uncrunched" first in
order to be used, which is job of UnchainSprite procedure. Sprites use only 16
colors, and therefore each pixel is represented with 4 bits (2 pixels = 1
byte). This is what the format of the SpriteGraphics structure looks like:

        offset  length   description
        ------  ------   -----------
           0      4      pointer to sprite pixels
           4      6      unknown, always zero in files
          10      2      exact width in pixels (nibbles)
          12      2      number of lines (nlines)
          14      2      width in paragraphs - number of pixels / 16, or
                         number of bytes / 8 (since 1 pixel = 1 nibble)
                         Some formulas:
                         ofs14 << 4 - number of pixels
                         ofs14 << 3 - number of bytes (width when copied to screen)
          16      2      x center, used range: [-8..34]
          18      2      y center, used range: [0..27], these are used only in
                         game sprites, menu sprites have it at zero always
          20      1      so far unknown, perhaps some sort of flags?
          21      1      nlines / 4, haven't seen it used anywhere so far
          22      2      sprite ordinal in sprite.dat file

For example fields 16 and 18 are used as a point in sprite from which ball
bounces off.

sprite.dat:
227 pointers are data from charset.dat (sprites used during the menu)
114 pointers to score.dat
303 pointers to team(1|2|3).dat (usually 1)
303       -||-                  (usually 2)
116 pointers to goal1.dat
116       -||-
155 pointers to bench.dat (or benc2.dat if 16 color mode is on)
1   dword - 0 - marks the end of the file

team1.dat contains pictures of players with shirts with vertical stripes
team2.dat contains pictures of players with colored sleeves
team3.dat contains pictures of players with shirts with horizontal stripes

Players with solid color shirts are created from team1.dat, by using same color
for stripes and shirt base.


   sprite.dat:                   team1.dat - array of sprite structures
(pointers to sprite
    structures)              ptr 0    +------+--------+
   +-----+-----+            +-------->|   x  |        |
   |  x  |  x  |            |         +---|--+--------+
   +--|--+--|--+            |      +--+---+           |
   |  +-----|--+------------+      |  +---------------+
   |        |  |                   +->| sprite 0 data |
   |        +--+------------+         |               |
   |     .     |            | ptr 1   +------+--------+
   |     .     |            +-------->|   x  |        |
         .                            +---|--+--------+
   |           |                   +--+---+           |
   +-----------+                   |  +---------------+
                                   +->| sprite 1 data |
                                      |               |
                                      +---------------|
                                      |       .       |
                                              .
                                              .
                                      |               |
                                      +---------------+

Despite pointers being used here, sprites are actually stored sequentially. In
each .dat file that contains sprites the order is following: sprite structure
first, immediately followed by sprite pixels. Some files differ slightly in
handling the offset fields, but they are here only to improve loading and
drawing performance.
First 227 offsets are relative to charset.dat. After that offsets start from 0
again, but now they are relative to memory block comprised of score.dat,
team1.dat (or team2.dat), team3.dat, goal1.dat (two times) and bench or
benc.dat. End of sprite.dat is marked with zero offset, which also marks the
end of last file (benc[h2].dat).
Offset to data is always relative to beginning of the file, except for
benc[h2].dat file, where offsets are relative to beginning of the joint memory
block.


=== Sprite map

Sprite 1286 has an error: width is mistakingly set to 5 pixels. It should be 16
pixels.

0-112 character set

0-56 small set:
0 - x in a box
1 - '
2 - (
3 - )
4 - ,
5 - -
6 - .
7 - /
8-17  - numbers
18-43 - letters
44 - block (cursor)
45 - *
46 - pound sign
47 - em dash
48 - ?
49 - :
50 - +
51 - %
52 - ;
53 - A with umlaut
54 - U   - // -
55 - O   - // -

56 - vertical bar
57 - invalid character symbol (x in a box)

Big character set follows, to get big character index add 57 to small character
index (except for number 56, that one's unique).

113-122 stars (for visualising player skills)

123 - ball sprite, but I haven't noticed it being used anywhere

small player sprites with team colors and shirt stripes; used in edit tactics
menu (corresponding sprites are copied into them)
124 white
125 ginger
126 black

small goalkeeper sprites, used in tactics editing
(corresponding sprites are copied into them)
127 white
128 ginger
129 black

small player sprites with single-color shirts
130 white
131 ginger
132 black

small player sprites with colored sleeves
133 white
134 ginger
135 black

small player sprites with vertical stripe shirts
136 white
137 ginger
138 black

small player sprites with horizontal stripe shirts
139 white
140 ginger
141 black

small goalkeeper sprites
142 white
143 ginger
144 black

149 - cursor during tactics editing, frame 1
150 -                -||-                  2
151 -                -||-                  3

181 - two empty sprites - they're located in edit teams menu, in invisible
182 - entries near the end

183 - up arrow (for scrolling)
184 - down arrow    -||-

player faces, used during tactics editing (perhaps elsewhere too)
186 - white
187 - ginger
188 - black

189 - empty sprite, also located in edit teams menu, as last, invisible entry

trophies
215 - Premier division champion
216 - Invitation tournament winner
217 - Cup winner
218 - ??? (unknown trophy)
219 - European Champions Cup
220 - Cup Winners Cup
221 - UEFA Cup
222 - World Championship
223 - European Championship

227-234 first scrolling ad
235-242 second   -||-
243-250 third    -||-

255-270 numbers + player names, written in top left corner of the screen, that
        mark the player with the ball
271-286 numbers + player names for team 2
These sprites are filled before the game, initally they're empty.

307 - first team name
308 - second team name

310-317 - space to use for goal scorers, for team 1
318-325 -         - || -                     team 2

330 - sprite for current game time ("118 mins." when uninitialized)

During the game, sprites [341..1178] will be adapted to colors of playing
teams. Hair and skin color are handled by having three sets of images, and
using the correct ones for each individual player. Goalkeepers have their own
images, for main and reserve goalkeeper.

team 1
341-441  set 1 (all player images - white)
442-542  set 2 (       -||-       - ginger)
543-643  set 3 (       -||-       - black)

team 2
745-845  set 1 (all player images - white)
846-946  set 2 (       -||-       - ginger)
947-1004 set 3 (       -||-       - black)

940-1004  team1 main goalkeeper
1005-1062 team1 reserve goalkeeper

1063-1120 team2 main goalkeeper
1121-1178 team2 reserve goalkeeper

team1 bench players
1310-1315 sitting
1316-1321 standing

team2 bench players
1322-1327 sitting
1328-1333 standing


=== Sprite decoding algorithm

- line is split in four "planes", 0, 1, 2 i 3 (wquads * 8 / 4)
- each pixel consists of four bits
- each pixel is composed out of one bit from each plane
- first pixel is composed of highest bits from plane 3, 2, 1, 0 in that order
- second pixel is composed of next bits
- we move bit by bit to the right, until the end of the line
- this process is repeated nlines times, until all lines are processed


=== In-game sprite structure

This structure is mostly tied to players but other entities are represented as
well, such as the ball and corner flags.

offset  length  description
------  ------  -----------
   0        2   team number; for the ball, referee, corner flag = 3
                0 = sprites that are not shown in the highlights
   2        2   player ordinal (shirt number)
   4        2   ??? (zero during the game)
                perhaps some sortf of picture offset for some specific sprite
   6        4   pointer to an animation table, it changes depending if the
                player is running, tackling or heading; can change without
                ball (say rolling on the pitch injured, or getting booked)
                table structure:
                - first word is the number of cycles between image transitions
                - after that the array of 32 pointers to image indices tables
                  follows; they are actually grouped into 4 categories of 8
                  pointers each:
                    0 - player, team 1
                    1 - player, team 2
                    2 - goalkeeper, team 1
                    3 - goalkeeper, team 2
                - inside the category pointer is indexed based on sprite
                  direction 0..7
                - in index table special indices exist:
                    = 999   - reset index to zero
                    = 100   - subtract one of the indices
                    <= 101  - add 100 + this to index
                    -99..-1 - seems to be delay value
                    otherwise - negate, add to frame delay and write to timer
  10        2   initial direction for the animation
  12        1   player state
                - if it's non-zero, player is not marked
                - ball has it 255 constantly (but check this again)
                - known values are:
                    0  - running
                    1  - tackling
                    3  - on the ground (tackled)
                    4  - for the goalkeeper, jumping in place, boxing or catching the ball
                    5  - performing a throw-in
                    6  - for the goalkeeper, diving, low ball
                    7  - for the goalkeeper, diving, high ball
                    9  - heading
                    12 - being booked
                    13 - injured
                    14 - sad, lost the game
                    15 - happy, won the game
                other possible values are: 8, 10, 11 - anything else results in
                program crashing
  13        1   count-down of how long the player will stay on the ground after
                being tackled; actually how long the player will be
                "inoperable"; this field is also used when player takes
                throw-in, heads the ball, etc...
  14        2   ??? (ball has it 0 always)
  16        2   something for x
  18        2   something for y
                for referee, player and ball shadow this is a dword, pointer to
                something; dword from sprite table is written here; seems to be
                a pointer to an array of picture indices
  20        2   might be continuation of previous field
                seems like field 18 is a pointer to array of indices of
                pictures of sprites that are shown (array of words), array
                seems to end with a negative member
                could be a union, since there are places where ofs18 is used as
                a word
  22        2   index of currently shown picture
  24        2   ??? write first word from sprite tables
                could be number of pictures, or highest index
  26        2   cyclic timer for images, ticks whenever the sprite is visible
                once it goes down to zero, next frame is drawn
  28        2   unlimited image timer, with delay
  30        4   x coordinate in fixed point signed word.signed word (+2 offset contains the whole part)
  34        4   y coordinate in fixed point
  38        4   z coordinate in fixed point (makes sense only for the ball)
                -1 when player is controlling the ball
  42        2   pravac u kome je igrac okrenut, 0..7 (0 = gore, 4 = dole...)
                       0
                   7   |   1
                     \ | /
                  6 ---+--- 2
                     / | \
                   5   |   3
                       4
                za loptu -1 ako je van igre
  44        2   brzina igraca
                mnozi se sa some_pitch_related_value2
                ofs6 iz pitch_cvt tabele
  46        4   delta x, u fiksnom zarezu word.word (pomeraj po x)
  50        4   delta y, u fiksnom zarezu word.word (pomeraj po y)
  54        4   delta z, u fiksnom zarezu word.word (pomeraj po z)
  58        2   destination x, whole part
  60        2   destination y, whole part
  62        6   ??? (kod lopte 62, 64 = 0, 66 = -1 const.)
  68        2   is_visible, da li je sprajt vidljiv? !0 - da, 0 - ne
  70        2   indeks slicice sprajta, ako je negativno nema slicicu
  72        2   flag za snimanje sprajta: 1 - nemoj da snimas, !1 - snimaj
  74        4   sqr(x igraca - x lopte) + sqr(y igraca - y lopte)
  78        4
  82        2   rezultat iz tmp01 (pravac i smer 0..255)
  84        2   da li je sprajt crtan u prethodnom ciklusu? 0 = ne, 1 = da
                is ball out of play, or with goalkeeper
  86        2   ??? mozda true za igraca, false za golmana
                kod lopte uvek nula
                is goalkeeper playing like an ordinary player
  88        4   ??? kod lopte uvek nula
  92        2   pravac u kome je igrac okrenut 0..7 (0 = gore, 4 = dole...)
  94        2   ako se igrac krece, vrednost je 255, ako stoji 0
                (tretira se kao bajt)
  96        2   nesto u vezi faulova (setuje se na 1 pri prvom faulu i ostaje
                tako dugo vreme, resetuje se gotovo random)
                ako je 2, nakon krljanja ce se samo pustiti komentar za faul
                recimo tackle state, 1 ako igrac uklizava, 2 za uspesno uklizavanje
                (uspeva da pokupi loptu)
  98        2   ??? nesto u vezi udaranja glavudzom
                set to 1 after strong header
 100        2   ??? vrednosti 0,1,2,3
                izgleda se inicijalizuje na 1, ako je ofs 142 tima != 0 (za igrace)
                za golmane = 3
                u MovePlayers, ako je lopta van igre ako je 1 stavi na 2
 102        2   ako je < 0, igrac ima crveni karton, ako je > 0 igrac ima zuti
                karton, ako je nula, nema kartona
 104        2   izgleda nesto u vezi povreda, izgleda ako je -2 => povreda
                moze biti i -1 i -2
                stepen povrede, pocetna vrednost za tajmer povrede (koliko ce
                se dugo igrac valjati po terenu) (bajt)
                video sam vrednosti 60, 70 i 80
 106        2   brojac, umanjuje se za jedan dok je igrac u klizecem startu
                moze se i povecavati za jedan, nepoznato zasto
                menja se samo dok je igrac blizu lopte
 108        2   da li je igrac izbacen, tj. da li je dobio crveni karton?
                (1 = true)

Length 110 bytes.


=== Sprite color conversion

Boje:

 0 - \
 1 - +- bez izmene
 2 - |
 3 - /
 4 - boja koze (tamna nijansa)
 5 - boja koze (srednja nijansa)
 6 - boja koze (svetla nijansa)
 7 - ide u nulu
 8 - ne menja se
 9 - boja kose (srednja nijansa)
10 - osnovna boja majice
11 - boja pruga majice (menja se sa 10 u slucaju vertikalnih pruga)
12 - boja kose (tamna nijansa)
13 - boja kose (svetla nijansa)
14 - boja sortsa
15 - boja carapa


=== Koordinate objekata po terenu

Koordinate su u pikselima u odnosu na gornji levi piksel terena. SWOS koristi
y koordinate uvecane za 16, jer ima jos jedan red patterna pre pocetka koji se
ne vidi. Dimenzije terena su 672 x 848 piksela.

[koordinate date za 16 manje nego u SWOS-u]

y koordinata lopte se poredi sa 216, 682, 449 pri odredjivanju da li ce se
partija produziti

Sesnaesterac po x: [193..478]
Donja granica gornjeg sesnaesterca: 200
Gornja granica donjeg sesnaesterca: 666
Granice terena po y: [113..753] (SWOS: 129..769)
Granice od kojih se lopta odbija po x: [53..618]
              -||-               po y: [84..783]
Gornja gol-linija: 113
Donja gol-linija: 753
Krajnja donja linija donjeg gola: 762
Precka gornjeg dela: 96
Leva stativa: 302
Desna stativa: 372
Leva aut linija: 81
Desna aut linija: 590

y kamere kada gornji tim krece sa centra: 336
      -||-    donji          -||-       : 309

Teren: (0, 16) - (671, 863)
Koordinate gola po x: 302..366
Precka gornjeg gola: 112
Pokusaj suta na gol po x: 240..430

Donja bela tacka: 336, 711

Lopta na centru: (336, 449)

Korneri:
gornji levi:  ( 86, 134)
gornji desni: (585, 134)
donji levi:   ( 86, 764)
donji desni:  (585, 764)

Gol auti (kada golman izvodi):
gornji levi:  (276, 154)
gornji desni: (396, 154)
donji levi:   (276, 744)
donji desni:  (396, 744)

Granice za "near miss":
po x: 290..281
po z:   0..25
Takodje, brzina lopte mora biti barem 768

Granice donjeg podrucja za slobodni udarac:
po y: 551..666
Granice gornjeg podrucja za slobodni udarac:
po y: 200..31


=== Razno

- igrac koji je postigao gol se raduje u 78.90625% frejmova, dok se njegovi saigraci raduju u 50%
