pitchx.dat
pitchx.blk, 1<=x<=6

Pitchx.dat files contain pointers into corresponding pitchx.blk files. Pointers
point to 16 x 16 patterns that the entire pitch is comprised of.

55 chunks 176 bytes long are transferred from pitchx.dat files to
g_pitchDatBuffer (55 x 168 = 9240, entire file), but only first 168 bytes are
read from the file (those unread 8 bytes are zeros, since g_pitchDatBuffer is
initialized to zero). After reading pitchx.dat the pointer fixup is performed,
pointers get incremented by the address of corresponding pitch.blk file's
contents.

For pitchx.blk file SWOS sets aside 75776 bytes, which is enough for 296 unique
patterns. Anything above that will cause overwrite of the patterns near the end
by saved sprites, which will make a big mess on the field.

At the start of the pitchx.dat file there are 2 x 21 pointers. Those are
pointers to patterns that need to be converted - ie. colored to colors of teams
that are playing (fans). First 21 pointers are for the left team, and second 21
are for the right one. At the end of the file there are 42 more pointers to
patterns that need color conversion.

Patterns with indices 1..24 are used to animate the crowd.
0 - empty tile (mostly, not always)
1..12  - upper spectator area \
                              |- animated crowd
13..24 - lower spectator area /
Odd indices are static images, even are moving (jumping, waving with scarf,
etc.)

Colors are converted using a lookup table. Each color byte from the pattern is
used as an index into the table (multiplied by two - word index). Resulting
byte replaces original pixel. Size of the table seems to be 96 byte, but only
even bytes are used. Before the actual conversion takes place, conversion table
is edited, a word is written to offset 20: shirt background color, if shirts
aren't plain, and if they are shorts color, and to offset 22: shirt stripes
color (primary color). Colors that are converted are 10 and 11 (20 / 2 and
22 / 2). Those are bright red and bright blue.

Real patterns that comprise the field start from 42. One screen fits 20
patterns horizontally (20x16=320). Dimensions of the virtual field are 42 x 53
patterns, that is 672 x 848 pixels. After 42 + 42 x 53 patterns, another 42
patterns used for fan coloring follow. Since initial patterns start at 42, 16
needs to be subtracted from y coordinates used in SWOS in order to get the
first pixel of the field.


    single row:

    20 visible patterns   |    22 invisible patterns
    +--+--+--+   +--+--+--+--+--+--+--+--+   +--+--+
    |  |  |  |...|  |  |  |  |  |  |  |  |...|  |  |
    +--+--+--+   +--+--+--+--+--+--+--+--+   +--+--+
                          |


    Entire virtual field:

              1               42              1
            +---+-----------     -----------+---+
          1 |   |            ...            |   | 1
            +---+-----------     -----------+---+
          1 |   |                           |   | 1
            +---+-----------     -----------+---+
            |   |                           |   |
            |   |                           |   |
            |   |                           |   |
            |   |                           |   |
                              .
         53                   .
                              .
            |   |                           |   |
            |   |                           |   |
            |   |                           |   |
            +---+-----------     -----------+---+
          1 |   |                           |   | 1
            +---+-----------     -----------+---+
          1 |   |                           |   | 1
            +---+-----------     -----------+---+
              1               42              1

Additional rows and columns around the field are used for scrolling: when
camera moves, for each pixel of movement 1 pattern is drawn into this slack
area.

Tables for the movement:
patternTableVert db 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
    db -1, 17, -1, 18, -1, 19, -1, 20, -1, 21, -1, 22, -1, 23, -1
patternTableHorz db 0, 1, 2, 3, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9, -1, 10,
    db -1, 11, -1, 12, -1, 13, -1, 14, -1, 15, -1, 16, -1, 17, -1

For each of 16 pixels that are scrolled (a whole pattern), one or two patterns
are copied in the spots around the virtual screen. So when the 16-pixel pattern
limit is crossed, next row or column of patterns is already in its spot and
scrolling can continue (18 or 24 patterns). It is probably done like this in
order to divide the job more equally for each frame and avoid delaying update
if scroll routine has too much to do.
Copy patterns function is called twice per pixel scrolled, odd indices are used
for first call, even for second. -1 means don't copy anything.
24 x 16 = 384 (24 patterns for virtual screen length)
18 x 16 = 288 (18 patterns for virtual screen length)

Each pitch file contains corresponding type of stripes on the field:
pitch1 - vertical stripes
pitch2 - horizontal stripes
pitch3 - rhombus
pitch4 - squares
pitch5 - diagonal stripes
pitch6 - training pitch

Pitch types:
0 - frozen
1 - muddy
2 - wet
3 - soft
4 - normal
5 - dry
6 - hard

are achieved by palette editing. For each type of pitch there is a 27 bytes
(colors) table, and it's used to copy the colors are to the specific place in
working palette: (0, 1, 2, 21, 22, 23, 27, 28, 29, 234, 235, 236, 237, 238,
239, 240, 241, 242, 243, 244, 245, 318, 319, 320, 321, 322, 323). Those are the
colors: 0, 7, 9, 78, 79, 80, 81, 106, 107.


=== Various pitch coordinates

Coordinates are given in pixels relative to upper left pixel of the pitch. SWOS
uses y coordinates increased by 16, since there is an additional invisible row
of patterns on top. Pitch dimensions are 672 x 848 pixels.

[coordinates given below are by 16 less compared to what SWOS uses in the code]

Ball y coordinate gets compared with 216, 682, 449 when determining if the
match will end.

Penalty area by x: [193..478]
Top penalty area lower bound: 200
Lower penalty area top bound: 666
Pitch boundaries by y: [113..753] (SWOS: 129..769)
Ball bouncing boundaries by x: [53..618]
              -||-       by y: [84..783]
Top goal line: 113
Bottom goal line: 753
Bottom goal bottom net line: 762
Top goal bar: 96
Left post: 302
Right post: 372
Left touchline: 81
Right touchline: 590

Camera y when top team starts off from the center: 336
      -||-    bottom             -||-            : 309

Pitch: (0, 16) - (671, 863)
Goal coordinates by x: 302..366
Top goal bar: 112
Goal attempt by x: 240..430

Bottom penalty spot: 336, 711

Ball center location: (336, 449)

Corner kick locations:
top left:     ( 86, 134)
top right:    (585, 134)
bottom left:  ( 86, 764)
bottom right: (585, 764)

Goal kicks:
top left:     (276, 154)
top right:    (396, 154)
bottom left:  (276, 744)
bottom right: (396, 744)

"Near miss" limits:
x: 290..281
z:   0..25
Also the ball speed has to be at least 768

Free kick bottom area limits:
y: 551..666
Free kick top area limits:
y: 200..31

AI x values for turning the players:
0..299, 300..371, 372+
