// Overhead crane animation
// ------------------------

// frame     : current frame of animation (0 to 237)
// a_frame   : adjusted frame number for direction change (0 to 118, 118 to 0)
// t_frame   : frame number for tile (0 to 23), crane is hidden in first and last positions

// frame:       0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30...
// t_frame t0: 10 11 12 13 14 15 16 17 18 19 20 21 22 23
//         t1:                    0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
//         t2:                                                                    0  1  2  3  4  5  6  7  8...

// t1 sprite offset:                 0  0  1  1  2  2  3  3  3  3  3  3  3  3  3  3  4  4  5  5  6  6
// t1 visible:                    0  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  0
// t1 x offset:                      9  8  9  8  9  8  9  8  7  6  5  4  3  2  1  0  1  0  1  0  1  0

	// Get animation frame of south tile
	1 * 1	02 04 0A // ID
		81 41 // platform info and relative position
		24 0F // position along platform from south
		\2rst
		7B 66 // animation frame of nearby tile using position from south as parameter
		00 FF
		00 // return frame
		\wx8000

	// Calculate a_frame for reverse movement
	1 * 1	02 04 70 // ID
		81 1A // always -1
		20 \b237 // max_frame
		\2-
		7D 25 // read register for frame of south tile
		00 FF
		00 // return a_frame = max_frame - frame
		\wx8000

	// Return a_frame for forward movement
	1 * 1	02 04 71 // ID
		81
		7D 25 // read register for frame of south tile
		00 FF
		00 // return a_frame = frame
		\wx8000

	// Select movement direction
	1 * 1	02 04 72 // ID
		81 7E 0A // animation frame - south tile
		20 FF
		\2sto 1A
		00 25 // store in register to prevent multiple calls to frame of nearby tile
		01
		\wx0071 \b0 \b118 // frames 0 to 118
		\wx0070 // frames 119 to max

	// Calculate t_frame {t_frame = a_frame + 10 - (p_pos * 16)}
	1 * 1	02 04 73 // ID
		81 7E 72 // get a_frame
		20 FF
		\2+
		1A // all bits on
		20 \b10 // val + 10
		\2-
		41 // platform info, get position along platform (from S)
		20 F0 // shift 0 and mask 4 bits to give p_pos * 16
		\2> // result = max(val1, val2)
		1A // all bits on
		20 \b0 // result is capped at min 0
		\2< // result = min(val1, val2)
		1A // all bits on
		00 \b23 // result is capped at max 23
		00 // return t_frame
		\wx8000


	// Animation start/stop control
	1 * 1	02 04 78 // ID
		81 18 // extra callback info - reason for call
		00 FF
		02
		\wx80FE 03 03 // vehicle enters station - start
		\wx80FF 04 04 // vehicle leaves station - stop
		\wx80FD // do nothing


	// Calc new frame for reverse movement
	1 * 1	02 04 08 // ID
		81 1A // all bits on
		20 \b237 // max_frame
		\2-
		4A // animation frame
		00 FF
		00 // return new_frame = max_frame - frame
		\wx8000

	// Animation frame control - determine point to reverse direction
	// {max_frame = ((plat_length - 2) * 16) + 6}
	1 * 1	02 04 09 // ID
		81 41 // platform info and relative position
		30 0F // platform length
		\2< // result = min(val1, val2)
		1A // all bits on
		20 \b9 // result is capped at max 9
		\2-
		1A  // all bits on
		20 \b2 // val - 2
		\2<<
		1A // all bits on
		20 \b4 // val * 16
		\2+
		1A  // all bits on
		20 \b6 // val + 6 - gives max_frame for this platform length
		\2-
		4A // animation frame
		00 FF // subtract animation frame from max_frame
		01
		\wx0008 00 00 // if animation frame = max_frame, set new frame
		\wx80FE // continue animation

	1 * 1	02 04 79 // ID
		81 41 // platform info and relative position
		04 0F // position along platform from south
		01
		\wx0009 00 00 // if most southerly tile
		\wx80FE // continue animation

// Platform 0 - building door animation
// -------------------------------------
	// Animation control - maybe start animation
	1 * 1	02 04 57 // ID
		81 10 // extra callback info - random bits
		00 01
		01
		\wx80FE 01 01 // 50% chance of start (from current frame)
		\wx80FD // do nothing

	// Animation start/stop control - platform 0
	1 * 1	02 04 59 // ID
		81 18 // extra callback info - reason for call
		00 FF
		01
		\wx0057 03 03 // vehicle enters station - maybe start
		\wx80FD // do nothing

	// Animation frame - maybe stop at closed
	1 * 1	02 04 56 // ID
		81 10 // extra callback info - random bits
		00 01
		01
		\wx80FF 01 01 // 50% chance of stop
		\wx8000

	// Animation frame - maybe stop at open
	1 * 1	02 04 54 // ID
		81 10 // extra callback info - random bits
		00 03
		01
		\wx80FF 01 01 // 25% chance of stop
		\wx80FE // continue

	// Animation frame - platform 0
	1 * 1	02 04 55 // ID
		81 4A // animation frame
		00 FF
		04
		\wx0054 \b3 \b3 // maybe stop
		\wx0054 \b7 \b7 // maybe stop
		\wx0054 \b11 \b11 // maybe stop
		\wx0056 \b15 \b15 // maybe stop
		\wx80FE // continue


// Callback 141 - Next animation frame
// -----------------------------------
	1 * 1	02 04 5D // ID
		81 41 // platform info and relative position
		08 0F // platform number from north
		01
		\wx0055 00 00 // if platform 0
		\wx0079

	1 * 1	02 04 5A // ID
		81 41 // platform info and relative position
		14 0F // total number of platforms
		01
		\wx0079 01 01 // 1 platform
		\wx005D


// Callback 140 - Animation control
// --------------------------------
	1 * 1	02 04 5C // ID
		81 41 // platform info and relative position
		08 0F // platform number from north
		01
		\wx0059 00 00 // platform 0
		\wx0078

	1 * 1	02 04 5B // ID
		81 41 // platform info and relative position
		14 0F // total number of platforms
		01
		\wx0078 01 01 // 1 platform
		\wx005C


	1 * 1	00 04 0B 01 STEEL_MILL
		08 "ISRA"

		// Sprite layout
		1A 0A
			// 00 (x) - crane rails with animated crane and cargo platforms - platform 1
			45
			\dx000003F4 \wx0002 // ground sprite
			10 // register
			\dx80000435 \wx0000 // back platform
			00 00 00 // x/y/z offset
			10 05 1B // x/y/z extent
			\dx8000042D \wx0040 // back cargo (child)
			05 15 80 // x/y/z offset
			04 // value for variable 10
			\dx8000043B \wx0000 // front platform
			00 0B 00 // x/y/z offset
			10 05 19 // x/y/z extent
			\dx8000042F \wx0042 // front cargo (child)
			05 0F 80 // x/y/z offset
			09 // register - sprite offset for cargo (old or new)
			04 // value for variable 10
			\dx8000043D \wx0013 // crane
			00 02 14 // x/y/z offset
			08 0C 0A // x/y/z extent
			01 06 11 12 // registers - show, sprite offset, x, y

			// 01 (y) - crane rails with animated crane and cargo platforms - platform 1
			45
			\dx000003F3 \wx0002 // ground sprite
			10 // register
			\dx80000436 \wx0000 // back platform
			00 00 00 // x/y/z offset
			05 10 1B // x/y/z extent
			\dx8000042E \wx0040 // back cargo (child)
			04 15 80 // x/y/z offset
			04 // value for variable 10
			\dx8000043C \wx0000 // front platform
			0B 00 00 // x/y/z offset
			05 10 19 // x/y/z extent
			\dx80000430 \wx0042 // front cargo (child)
			04 0F 80 // x/y/z offset
			09 // register - sprite offset for cargo (old or new)
			04 // value for variable 10
			\dx80000444 \wx0013 // crane
			02 00 14 // x/y/z offset
			0C 08 0A // x/y/z extent
			01 06 12 11 // registers - show, sprite offset, x, y

			// 02 (x) - crane rails with animated crane and cargo platforms - platforms > 1
			45
			\dx000003F4 \wx0002 // ground sprite
			10 // register
			\dx80000437 \wx0000 // back platform
			00 00 00 // x/y/z offset
			10 05 1B // x/y/z extent
			\dx8000042D \wx0040 // back cargo (child)
			05 13 80 // x/y/z offset
			04 // value for variable 10
			\dx8000043B \wx0000 // front platform
			00 0B 00 // x/y/z offset
			10 05 19 // x/y/z extent
			\dx8000042F \wx0042 // front cargo (child)
			05 0F 80 // x/y/z offset
			09 // register - sprite offset for cargo (old or new)
			04 // value for variable 10
			\dx8000043D \wx0013 // crane
			00 02 14 // x/y/z offset
			08 0C 0A // x/y/z extent
			01 06 11 12 // registers - show, sprite offset, x, y

			// 03 (y) - crane rails with animated crane and cargo platforms - platforms > 1
			45
			\dx000003F3 \wx0002 // ground sprite
			10 // register
			\dx80000438 \wx0000 // back platform
			00 00 00 // x/y/z offset
			05 10 1B // x/y/z extent
			\dx8000042E \wx0040 // back cargo (child)
			04 13 80 // x/y/z offset
			04 // value for variable 10
			\dx8000043C \wx0000 // front platform
			0B 00 00 // x/y/z offset
			05 10 19 // x/y/z extent
			\dx80000430 \wx0042 // front cargo (child)
			04 0F 80 // x/y/z offset
			09 // register - sprite offset for cargo (old or new)
			04 // value for variable 10
			\dx80000444 \wx0013 // crane
			02 00 14 // x/y/z offset
			0C 08 0A // x/y/z extent
			01 06 12 11 // registers - show, sprite offset, x, y

			// 04 (x) - // crane rails with crane building - north end of platform
			43
			\dx000003F4 \wx0002 // ground sprite
			10 // register
			\dx80000435 \wx0002 // back
			00 00 00 // x/y/z offset
			10 05 1B // x/y/z extent
			05 // register - sprite offset for platform
			\dx80008433 \wx0000 // front
			00 0A 00 // x/y/z offset
			10 06 2C // x/y/z extent
			\dx80000439 \wx0001 // building snow
			00 00 80 // x/y/z offset
			13 // register

			// 05 (y) - // crane rails with crane building - north end of platform
			43
			\dx000003F3 \wx0002 // ground sprite
			10 // register
			\dx80000436 \wx0002 // back
			00 00 00 // x/y/z offset
			05 10 1B // x/y/z extent
			05 // register - sprite offset for platform
			\dx80008434 \wx0000 // front
			0A 00 00 // x/y/z offset
			06 10 2C // x/y/z extent
			\dx8000043A \wx0001 // building snow
			00 00 80 // x/y/z offset
			13 // register

			// 06 (x) - platform 0 building
			45
			\dx000003F4 \wx0002 // ground sprite
			10 // register
			\dx8000042F \wx0000 // back part
			06 00 00 // x/y/z offset
			0A 06 11 // x/y/z extent
			\dx8000042D \wx0000 // building
			00 00 00 // x/y/z offset
			10 10 2A // x/y/z extent
			\dx80000431 \wx0001 // building snow
			00 00 80 // x/y/z offset
			13 // register
			\dx8000042D \wx0043 // door 1
			2A 25 80 // x/y/z offset
			02 07 // registers - show, sprite offset
			05 // value for variable 10
			\dx8000042D \wx0043 // door 2
			36 1F 80 // x/y/z offset
			03 08 // registers - show, sprite offset
			05 // value for variable 10

			// 07 (y) - platform 0 building
			45
			\dx000003F3 \wx0002 // ground sprite
			10 // register
			\dx80000430 \wx0000 // back part
			00 06 00 // x/y/z offset
			06 0A 11 // x/y/z extent
			\dx8000042E \wx0000 // building
			00 00 00 // x/y/z offset
			10 10 2A // x/y/z extent
			\dx80000432 \wx0001 // building snow
			00 00 80 // x/y/z offset
			13 // register
			\dx8000042E \wx0043 // door 1
			07 1F 80 // x/y/z offset
			02 07 // registers - show, sprite offset
			05 // value for variable 10
			\dx8000042E \wx0043 // door 2
			13 25 80 // x/y/z offset
			03 08 // registers - show, sprite offset
			05 // value for variable 10

			// 08 (x) - purchase
			41
			\dx000003F4 \wx0000 // ground sprite
			\dx8000842D \wx0000 // purchase list sprite
			00 00 00 // x/y/z offset
			10 10 20 // x/y/z extent

			// 09 (y) - purchase
			41
			\dx000003F3 \wx0000 // ground sprite
			\dx8000842E \wx0000 // purchase list sprite
			00 00 00 // x/y/z offset
			10 10 20 // x/y/z extent

		12 \dx00000200 // cargo types for randomisation triggers (steel)
		10 \w400 // set little / lots threshold

		11 00 // pylon placement (none)
		14 FF // wires (none)

		0B 06 // use callback to determine layout and animation frame

		// General flags
		13 04 // give callback 141 random bits in variable 10

		16 \wx01ED // animation info 238 frames looping
		17 04 // animation speed 2^4 ticks per frame (~400ms)
		18 \wx0018 // animation triggers - train enters (0x08), train leaves (0x10)



	1 * 1	01 04 02 1E
	// North platform building and crane building
	// Old style
	1 images/newsteelmill3.pcx    2   16  09   65  70  -31  -34 // 042D x, building P0
	1 images/newsteelmill3.pcx   82   16  09   65  70  -37  -34 // 042E y, building P0
	1 images/newsteelmill3.pcx  162   16  09   22  25  -19   -7 // 042F x, building P0 back wall
	1 images/newsteelmill3.pcx  194   16  09   22  25   -4   -7 // 0430 y, building P0 back wall
	1 images/newsteelmill3.pcx    2   88  09   38  70    0    0 // 0431 x, building P0 snow
	1 images/newsteelmill3.pcx   78   88  09   38  70    0    0 // 0432 y, building P0 snow
	1 images/newsteelmill3.pcx  226   16  09   57  43  -29  -36 // 0433 x, crane building
	1 images/newsteelmill3.pcx  274   16  09   57  43  -12  -36 // 0434 y, crane building
	1 images/newsteelmill3.pcx  514   16  01   49  42  -31  -29 // 0435 x, P1 building side with rail back
	1 images/newsteelmill3.pcx  562   16  01   49  42   -9  -29 // 0436 y, P1 building side with rail back
	1 images/newsteelmill3.pcx  323   16  01   44  42  -31  -24 // 0437 x, >=P2 crane rail back
	1 images/newsteelmill3.pcx  370   16  01   44  42   -9  -24 // 0438 y, >=P2 crane rail back
	1 images/newsteelmill3.pcx  154   88  09   20  36    7    0 // 0439 x, crane building snow
	1 images/newsteelmill3.pcx  195   88  09   19  36    0    0 // 043A y, crane building snow
	1 images/newsteelmill3.pcx  418   16  01   42  42  -31  -22 // 043B x, >=P1 crane rail front
	1 images/newsteelmill3.pcx  466   16  01   42  42   -9  -22 // 043C y, >=P1 crane rail front

//@@LET xpos = 265
//@@LET ypos = 88
//@@LET xsize = 42
//@@LET ysize = 25
//@@LET xrel = -16
//@@LET yrel = -9
//@@LET xsizeh = 22
//@@LET xsizeh1 = (xsize xsizeh -)
//@@LET xposh = (xpos xsizeh1 +)
//@@LET xrelhX = (xrel xposh + xpos - 8 -)

	1 images/newsteelmill3.pcx (xposh 4 +) (ypos) 01 (ysize) (xsizeh 4 -)  (xrelhX)    (yrel 6 +) // 043D x, crane 1
	1 images/newsteelmill3.pcx (xposh)     (ypos) 01 (ysize) (xsizeh)      (xrelhX)    (yrel 4 +) // 043E x, crane 2
	1 images/newsteelmill3.pcx (xposh 4 -) (ypos) 01 (ysize) (xsizeh 4 +)  (xrelhX)    (yrel 2 +) // 043F x, crane 3
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsize)       (xrel)      (yrel)     // 0440 x, crane 4 - 8 (6 - centre)
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsizeh1 4 +) (xrel  4 +) (yrel 2 -) // 0441 x, crane 9
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsizeh1)     (xrel  8 +) (yrel 4 -) // 0442 x, crane 10
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsizeh1 4 -) (xrel 12 +) (yrel 6 -) // 0443 x, crane 11

//@@LET xpos = 315
//@@LET ypos = 88
//@@LET xsize = 42
//@@LET ysize = 23
//@@LET xrel = -24
//@@LET yrel = -9
//@@LET xsizeh = 20
//@@LET xsizeh1 = (xsize xsizeh -)
//@@LET xposh = (xpos xsizeh1 +)
//@@LET xrelh = (xrel xposh + xpos - 8 -)

	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsizeh1 4 -) (xrel 12 +) (yrel 6 +) // 0444 y, crane 1
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsizeh1)     (xrel  8 +) (yrel 4 +) // 0445 y, crane 2
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsizeh1 4 +) (xrel  4 +) (yrel 2 +) // 0446 y, crane 3
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsize)       (xrel)      (yrel)     // 0447 y, crane 4 - 8 (6 - centre)
	1 images/newsteelmill3.pcx (xposh 4 -) (ypos) 01 (ysize) (xsizeh 4 +)  (xrelh)     (yrel 2 -) // 0448 y, crane 9
	1 images/newsteelmill3.pcx (xposh)     (ypos) 01 (ysize) (xsizeh)      (xrelh)     (yrel 4 -) // 0449 y, crane 10
	1 images/newsteelmill3.pcx (xposh 4 +) (ypos) 01 (ysize) (xsizeh 4 -)  (xrelh)     (yrel 6 -) // 044A y, crane 11

	// New style
	1 images/newsteelmill3.pcx    2  160  09   57  67  -31  -26 // 042D x, building P0
	1 images/newsteelmill3.pcx   79  160  09   57  67  -34  -26 // 042E y, building P0
	1 images/newsteelmill3.pcx  155  160  09   22  25  -19   -7 // 042F x, building P0 back wall
	1 images/newsteelmill3.pcx  187  160  09   22  25   -4   -7 // 0430 y, building P0 back wall
	1 images/newsteelmill3.pcx    2  306  09   30  67    0    0 // 0431 x, building P0 snow
	1 images/newsteelmill3.pcx   78  306  09   30  67    0    0 // 0432 y, building P0 snow
	1 images/newsteelmill3.pcx    2  240  09   57  43  -29  -36 // 0433 x, crane building
	1 images/newsteelmill3.pcx   50  240  09   57  43  -12  -36 // 0434 y, crane building
	1 images/newsteelmill3.pcx  288  240  41   49  42  -31  -29 // 0435 x, P1 crane rail back
	1 images/newsteelmill3.pcx  336  240  41   49  42   -9  -29 // 0436 y, P1 crane rail back
	1 images/newsteelmill3.pcx   99  240  01   44  42  -31  -24 // 0437 x, >=P2 crane rail back
	1 images/newsteelmill3.pcx  146  240  01   44  42   -9  -24 // 0438 y, >=P2 crane rail back
	1 images/newsteelmill3.pcx  154  306  09   20  36    7    0 // 0439 x, crane building snow
	1 images/newsteelmill3.pcx  195  306  09   20  36    0    0 // 043A y, crane building snow
	1 images/newsteelmill3.pcx  192  240  41   44  42  -31  -24 // 043B x, >=P1 crane rail front
	1 images/newsteelmill3.pcx  240  240  41   44  42   -9  -24 // 043C y, >=P1 crane rail front

//@@LET xpos = 239
//@@LET ypos = 306
//@@LET xsize = 31
//@@LET ysize = 21
//@@LET xrel = -10
//@@LET yrel = -6
//@@LET xsizeh = 17
//@@LET xsizeh1 = (xsize xsizeh -)
//@@LET xposh = (xpos xsizeh1 +)
//@@LET xrelhX = (xrel xposh + xpos - 8 -)

	1 images/newsteelmill3.pcx (xposh 4 +) (ypos) 01 (ysize) (xsizeh 4 -)  (xrelhX)    (yrel 6 +) // 043D x, crane 1
	1 images/newsteelmill3.pcx (xposh)     (ypos) 01 (ysize) (xsizeh)      (xrelhX)    (yrel 4 +) // 043E x, crane 2
	1 images/newsteelmill3.pcx (xposh 4 -) (ypos) 01 (ysize) (xsizeh 4 +)  (xrelhX)    (yrel 2 +) // 043F x, crane 3
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsize)       (xrel)      (yrel)     // 0440 x, crane 4 - 8 (6 - centre)
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsizeh1 4 +) (xrel  4 +) (yrel 2 -) // 0441 x, crane 9
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsizeh1)     (xrel  8 +) (yrel 4 -) // 0442 x, crane 10
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsizeh1 4 -) (xrel 12 +) (yrel 6 -) // 0443 x, crane 11

//@@LET xpos = 277
//@@LET ypos = 306
//@@LET xsize = 31
//@@LET ysize = 21
//@@LET xrel = -19
//@@LET yrel = -6
//@@LET xsizeh = 14
//@@LET xsizeh1 = (xsize xsizeh -)
//@@LET xposh = (xpos xsizeh1 +)
//@@LET xrelh = (xrel xposh + xpos - 8 -)

	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsizeh1 4 -) (xrel 12 +) (yrel 6 +) // 0444 y, crane 1
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsizeh1)     (xrel  8 +) (yrel 4 +) // 0445 y, crane 2
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsizeh1 4 +) (xrel  4 +) (yrel 2 +) // 0446 y, crane 3
	1 images/newsteelmill3.pcx (xpos)      (ypos) 01 (ysize) (xsize)       (xrel)      (yrel)     // 0447 y, crane 4 - 8 (6 - centre)
	1 images/newsteelmill3.pcx (xposh 4 -) (ypos) 01 (ysize) (xsizeh 4 +)  (xrelh)     (yrel 2 -) // 0448 y, crane 9
	1 images/newsteelmill3.pcx (xposh)     (ypos) 01 (ysize) (xsizeh)      (xrelh)     (yrel 4 -) // 0449 y, crane 10
	1 images/newsteelmill3.pcx (xposh 4 +) (ypos) 01 (ysize) (xsizeh 4 -)  (xrelh)     (yrel 6 -) // 044A y, crane 11

	1 * 1	02 04 00 // ID
		00 01
		\w0

	1 * 1	02 04 01 // ID
		00 01
		\w1


	1 * 1	01 04 04 06
	// Empty
	1 images/newsteelmill3.pcx    2  343  01  01  01   0   0 // 042D x, steel back platform
	1 images/newsteelmill3.pcx    2  343  01  01  01   0   0 // 042E y, steel back platform
	1 images/newsteelmill3.pcx    2  343  01  01  01   0   0 // 042F x, steel front platform old
	1 images/newsteelmill3.pcx    2  343  01  01  01   0   0 // 0430 y, steel front platform old
	1 images/newsteelmill3.pcx    2  343  01  01  01   0   0 // 0431 x, steel front platform new
	1 images/newsteelmill3.pcx    2  343  01  01  01   0   0 // 0432 y, steel front platform new
	// Cargo level 1
	1 images/newsteelmill3.pcx    2  343  41  24  33   0   0 // 042D x, steel back platform
	1 images/newsteelmill3.pcx   40  343  41  24  33   0   0 // 042E y, steel back platform
	1 images/newsteelmill3.pcx    2  372  41  24  33   0   0 // 042F x, steel front platform old
	1 images/newsteelmill3.pcx   40  372  41  24  33   0   0 // 0430 y, steel front platform old
	1 images/newsteelmill3.pcx    2  401  41  24  33   0   0 // 0431 x, steel front platform new
	1 images/newsteelmill3.pcx   40  401  41  24  33   0   0 // 0432 y, steel front platform new
	// Cargo level 2
	1 images/newsteelmill3.pcx   78  343  41  24  33   0   0 // 042D x, steel back platform
	1 images/newsteelmill3.pcx  116  343  41  24  33   0   0 // 042E y, steel back platform
	1 images/newsteelmill3.pcx   78  372  41  24  33   0   0 // 042F x, steel front platform old
	1 images/newsteelmill3.pcx  116  372  41  24  33   0   0 // 0430 y, steel front platform old
	1 images/newsteelmill3.pcx   78  401  41  24  33   0   0 // 0431 x, steel front platform new
	1 images/newsteelmill3.pcx  116  401  41  24  33   0   0 // 0432 y, steel front platform new
	// Cargo level 3
	1 images/newsteelmill3.pcx  154  343  41  24  33   0   0 // 042D x, steel back platform
	1 images/newsteelmill3.pcx  192  343  41  24  33   0   0 // 042E y, steel back platform
	1 images/newsteelmill3.pcx  154  372  41  24  33   0   0 // 042F x, steel front platform old
	1 images/newsteelmill3.pcx  192  372  41  24  33   0   0 // 0430 y, steel front platform old
	1 images/newsteelmill3.pcx  154  401  41  24  33   0   0 // 0431 x, steel front platform new
	1 images/newsteelmill3.pcx  192  401  41  24  33   0   0 // 0432 y, steel front platform new

	1 * 1	02 04 10 // ID
		0E 01
		\w0 \w1 \w1 \w1 \w1 \w1 \w2 \w2 \w2 \w2 \w2 \w3 \w3 \w3
		\w3

	1 * 1	02 04 11 // ID
		0E 01
		\w0 \w0 \w1 \w1 \w1 \w1 \w1 \w2 \w2 \w2 \w2 \w2 \w3 \w3
		\w3

	1 * 1	02 04 12 // ID
		0E 01
		\w0 \w0 \w0 \w1 \w1 \w1 \w1 \w1 \w2 \w2 \w2 \w2 \w2 \w3
		\w3

	1 * 1	02 04 13 // ID
		0E 01
		\w0 \w0 \w0 \w0 \w1 \w1 \w1 \w1 \w1 \w2 \w2 \w2 \w2 \w2
		\w3

	1 * 1	02 04 02 // ID
		80
		00 // no more cargo (triggered by random in graphics chain)
		12 // use bits 18 and 19
		04
		\wx0010
		\wx0011
		\wx0012
		\wx0013

	// Empty
	1 * 1	02 04 03 // ID
		00 01
		\w0


	1 * 1	01 04 01 06
	// New style side doors
	1 images/newsteelmill3.pcx  223  160  09   15   6    0    0 // 042D x, building door 1
	1 images/newsteelmill3.pcx  267  160  09   15   6    0    0 // 042E y, building door 1
	1 images/newsteelmill3.pcx  237  160  09   15   6    0    0 // 042F x, building door 2
	1 images/newsteelmill3.pcx  281  160  09   15   6    0    0 // 0430 y, building door 2
	1 images/newsteelmill3.pcx  251  160  09   15   6    0    0 // 0431 x, building door 3
	1 images/newsteelmill3.pcx  295  160  09   15   6    0    0 // 0432 y, building door 3

	1 * 1	02 04 04 // ID
		00 01
		\w0


	1 * 1	01 04 02 02
	// Purchase list
	1 images/purchaseicons.pcx   19  361  09   62  64  -31  -31 // 042D x
	1 images/purchaseicons.pcx   91  361  09   62  64  -31  -31 // 042E y
	1 images/purchaseicons.pcx  163  361  09   62  64  -31  -31 // 042F x
	1 images/purchaseicons.pcx  235  361  09   62  64  -31  -31 // 0430 y

	1 * 1	02 04 0A // ID
		00 01
		\w0

	1 * 1	02 04 0B // ID
		00 01
		\w1

// Real sprites
//-------------
	// North platform building and crane building
	1 * 1	02 04 06 // ID
		85 FA // date station was built
		00 \wxFFFF
		01
		\wx0000 \w0 \w01/01/1980 // old style steel mill sprites
		\wx0001 // modern style steel mill sprites

	// For purchase list
	1 * 1	02 04 07 // ID
		85 00 // current date
		00 \wxFFFF
		01
		\wx000A \w0 \w01/01/1980 // old style purchase list sprites
		\wx000B // modern style purchase list sprites

	// Test variable 10 for real sprites
	1 * 1	02 04 1A // ID
		81 10 // additional information for sprite selection
		00 0F
		02
		\wx0002 04 04 // cargo sprites
		\wx0004 05 05 // door sprites
		\wx0006 // building sprites

	// Test variable 10 for real sprites - empty
	1 * 1	02 04 1B // ID
		81 10 // additional information for sprite selection
		00 0F
		02
		\wx0003 04 04 // cargo sprites
		\wx0004 05 05 // door sprites
		\wx0006 // building sprites


	// Select back platform type
	1 * 1	02 04 6A // ID
		81 41 // platform info and relative position
		08 0F // platform number from north
		01
		\wx8000 00 01 // if platform 0 or 1
		\wx8002

	1 * 1	02 04 24 // ID
		81 41 // platform info and relative position
		14 0F // total number of platforms
		01
		\wx8002 01 01 // if 1 platform
		\wx006A

	// Select move offset
	1 * 1	02 04 65 // ID
		81
		7D 21 // read register 21 for t_frame
		00 FF
		\b18
		\wx8009 \b1 \b1
		\wx8008 \b2 \b2
		\wx8009 \b3 \b3
		\wx8008 \b4 \b4
		\wx8009 \b5 \b5
		\wx8008 \b6 \b6
		\wx8009 \b7 \b7
		\wx8008 \b8 \b8
		\wx8007 \b9 \b9
		\wx8006 \b10 \b10
		\wx8005 \b11 \b11
		\wx8004 \b12 \b12
		\wx8003 \b13 \b13
		\wx8002 \b14 \b14
		\wx8001 \b15 \b15
		\wx8001 \b17 \b17
		\wx8001 \b19 \b19
		\wx8001 \b21 \b21
		\wx8000

	// Check for position along platform from south
	1 * 1	02 04 64 // ID
		81 41 // platform info and relative position
		04 0F // position along platform from south
		01
		\wx0065 00 07 // if valid animation tile
		\wx8000 // else

	// Hide animation sprites
	1 * 1	02 04 63 // ID
		81
		7D 21 // read register 21 for t_frame
		00 FF
		01
		\wx8001 \b1 \b22 // t_frame 1 to 22 - show
		\wx8000 // hide

	// Check for position along platform from south
	1 * 1	02 04 62 // ID
		81 41 // platform info and relative position
		04 0F // position along platform from south
		01
		\wx0063 00 07 // if valid animation tile
		\wx8000 // hide

	// Select sprite
	1 * 1	02 04 61 // ID
		81 7E 73 // get tile frame (0 to 12)
		20 FF
		\2sto 1A
		00 21 // store in register to prevent calculating t_frame multiple times
		06
		\wx8000 \b1 \b2
		\wx8001 \b3 \b4
		\wx8002 \b5 \b6
		\wx8004 \b17 \b18
		\wx8005 \b19 \b20
		\wx8006 \b21 \b22
		\wx8003

	// Check for end of platform - south
	1 * 1	02 04 60 // ID
		81 41 // platform info and relative position
		04 0F // position along platform from south
		01
		\wx0061 00 07 // if valid animation tile
		\wx8000 // else

	// Door A animation offset
	1 * 1	02 04 66 // ID
		81
		4A // animation frame
		00 FF
		04
		\wx8004 \b0 \b0
		\wx8002 \b1 \b1
		\wx8002 \b10 \b10
		\wx8004 \b11 \b16
		\wx8000

	// Door A show/hide
	1 * 1	02 04 6A // ID
		81
		4A // animation frame
		00 FF
		01
		\wx8000 \b3 \b8
		\wx8001

	// Door A show/hide
	1 * 1	02 04 67 // ID
		85 FA // date station was built
		00 \wxFFFF
		01
		\wx8000 \w0 \w01/01/1980
		\wx006A

	// Door B animation offset
	1 * 1	02 04 68 // ID
		81
		4A // animation frame
		00 FF
		04
		\wx8004 \b0 \b4
		\wx8002 \b5 \b5
		\wx8002 \b14 \b14
		\wx8004 \b15 \b15
		\wx8000

	// Door B show/hide
	1 * 1	02 04 6B // ID
		81
		4A // animation frame
		00 FF
		01
		\wx8000 \b7 \b12
		\wx8001

	// Door B show/hide
	1 * 1	02 04 69 // ID
		85 FA // date station was built
		00 \wxFFFF
		01
		\wx8000 \w0 \w01/01/1980
		\wx006B

	// Cargo front sprite offset
	1 * 1	02 04 6C // ID
		85 FA // date station was built
		00 \wxFFFF
		01
		\wx8000 \w0 \w01/01/1980
		\wx8002

//@@WARNING DISABLE 100
//@@WARNING DISABLE 170

	// Crane rails with animated crane and cargo platforms
	1 * 1	02 04 15 // ID
		85
		7E 60 // get crane sprite offset
		20 \wx7FFF
		\2sto 1A
		20 \wx0006 // store in register - sprite offset
		\2rst
		7E 62 // get crane show/hide
		20 \wx7FFF
		\2sto 1A
		20 \wx0001 // store in register - show crane flag
		\2rst
		7E 64 // get crane position offset
		20 \wx7FFF
		\2sto 1A
		20 \wx0011 // store in register - move x offset
		\2rst
		1A // all bits on
		20 \w0 // val = 0
		\2sto 1A
		20 \wx0012 // store in register - move y offset
		\2rst
		7E 6C // get cargo sprite offset
		20 \wx7FFF
		\2sto 1A
		20 \wx0009 // store in register - cargo offset
		\2rst
		7E BE // get normal/snow/desert offset
		20 \wx7FFF
		\2+
		7E BD // add monorail/maglev offset
		20 \wx00FF
		\2sto 1A
		00 \wx0010 // store in register - ground sprite offset
		01
		\wx001A \w0 \w0
		\wx001A

	// Crane rails with animated crane and cargo platforms -empty
	1 * 1	02 04 18 // ID
		85
		7E 60 // get crane sprite offset
		20 \wx7FFF
		\2sto 1A
		20 \wx0006 // store in register - sprite offset
		\2rst
		7E 62 // get crane show/hide
		20 \wx7FFF
		\2sto 1A
		20 \wx0001 // store in register - show crane flag
		\2rst
		7E 64 // get crane position offset
		20 \wx7FFF
		\2sto 1A
		20 \wx0011 // store in register - move x offset
		\2rst
		1A // all bits on
		20 \w0 // val = 0
		\2sto 1A
		20 \wx0012 // store in register - move y offset
		\2rst
		7E 6C // get cargo sprite offset
		20 \wx7FFF
		\2sto 1A
		20 \wx0009 // store in register - cargo offset
		\2rst
		7E BE // get normal/snow/desert offset
		20 \wx7FFF
		\2+
		7E BD // add monorail/maglev offset
		20 \wx00FF
		\2sto 1A
		00 \wx0010 // store in register - ground sprite offset
		01
		\wx001B \w0 \w0
		\wx001B

	// Crane rails with crane building - north end of platform
	1 * 1	02 04 16 // ID
		85
		7E 24 // get layout type
		20 \wx7FFF
		\2sto 1A
		20 \wx0005 // store in register - platform sprite offset
		\2rst
		7E BB // get snow overlay flag
		20 \wx00FF
		\2sto 1A
		20 \wx0013 // store in register
		\2rst
		7E BE // get normal/snow/desert offset
		20 \wx7FFF
		\2+
		7E BD // add monorail/maglev offset
		20 \wx00FF
		\2sto 1A
		00 \wx0010 // store in register - ground sprite offset
		01
		\wx001A \w0 \w0
		\wx001A

	// Platform 0 building
	1 * 1	02 04 17 // ID
		85
		7E 67 // get door A show/hide
		20 \wx7FFF
		\2sto 1A
		20 \wx0002 // store in register - show door A
		\2rst
		7E 66 // get door A sprite offset
		20 \wx7FFF
		\2sto 1A
		20 \wx0007 // store in register - door A sprite offset
		\2rst
		7E 69 // get door B show/hide
		20 \wx7FFF
		\2sto 1A
		20 \wx0003 // store in register - show door B
		\2rst
		7E 68 // get door B sprite offset
		20 \wx7FFF
		\2sto 1A
		20 \wx0008 // store in register - door B sprite offset
		\2rst
		7E BB // get snow overlay flag
		20 \wx00FF
		\2sto 1A
		20 \wx0013 // store in register
		\2rst
		7E BE // get normal/snow/desert offset
		20 \wx7FFF
		\2+
		7E BD // add monorail/maglev offset
		20 \wx00FF
		\2sto 1A
		00 \wx0010 // store in register - ground sprite offset
		01
		\wx001A \w0 \w0
		\wx001A

//@@WARNING ENABLE 170
//@@WARNING ENABLE 100


	// For crane platform 2 or greater or single platform station
	1 * 1	02 04 21 // ID
		81 41 // platform info and relative position
		00 0F // position along platform from north
		01
		\wx0016 00 00 // crane rails with crane building
		\wx0015 // crane rails

	// For crane platform 2 or greater or single platform station - empty
	1 * 1	02 04 29 // ID
		81 41 // platform info and relative position
		00 0F // position along platform from north
		01
		\wx0016 00 00 // crane rails with crane building
		\wx0018 // crane rails - empty

	// For >1 platform
	1 * 1	02 04 25 // ID
		81 41 // platform info and relative position
		08 0F // platform number from north
		01
		\wx0017 00 00 // if platform 0
		\wx0021

	// For >1 platform - empty
	1 * 1	02 04 28 // ID
		81 41 // platform info and relative position
		08 0F // platform number from north
		01
		\wx0017 00 00 // if platform 0
		\wx0029

	1 * 1	02 04 26 // ID
		81 41 // platform info and relative position
		14 0F // total number of platforms
		01
		\wx0021 01 01 // if 1 platform
		\wx0025

	// Empty
	1 * 1	02 04 27 // ID
		81 41 // platform info and relative position
		14 0F // total number of platforms
		01
		\wx0029 01 01 // if 1 platform
		\wx0028


// Callback 14 - Sprite layout
// ---------------------------
	// Select back platform type
	1 * 1	02 04 23 // ID
		81 41 // platform info and relative position
		08 0F // platform number from north
		01
		\wx8000 00 01 // if platform 0 or 1
		\wx8002

	1 * 1	02 04 22 // ID
		81 41 // platform info and relative position
		14 0F // total number of platforms
		01
		\wx8002 01 01 // if 1 platform
		\wx0023

	// For crane platform 2 or greater or single platform station
	1 * 1	02 04 32 // ID
		81 41 // platform info and relative position
		00 0F // position along platform from north
		01
		\wx8004 00 00 // crane rails with crane building
		\wx0022 // crane rails

	// For >1 platform
	1 * 1	02 04 31 // ID
		81 41 // platform info and relative position
		08 0F // platform number from north
		01
		\wx8006 00 00 // if platform 0
		\wx0032

	1 * 1	02 04 30 // ID
		81 41 // platform info and relative position
		14 0F // total number of platforms
		01
		\wx0032 01 01 // if 1 platform
		\wx0031

//-------------------------------------------------------------

	1 * 1	02 04 12 // ID
		85 0C // callback
		00 \wxFFFF
		03
		\wx0030 \wx0014 \wx0014 // sprite layout
		\wx005B \wx0140 \wx0140 // animation control
		\wx005A \wx0141 \wx0141 // animation frame
		\wx0026 // real sprites

	// For purchase list
	1 * 1	02 04 13 // ID
		81 0C // callback
		00 FF
		01
		\wx8008 14 14 // sprite layout
		\wx0007

//@@WARNING DISABLE 113

	// Random action 2 outside callback triggers re-randomisation
	1 * 1	02 04 09 // ID
		80
		02 // no more cargo
		12 // trigger bits 18 and 19
		04
		\wx0027
		\wx0027
		\wx0027
		\wx0027

//@@WARNING ENABLE 113

	// No suitable cargo
	1 * 1	02 04 1F // ID
		85 0C // callback
		00 \wxFFFF
		03
		\wx0030 \wx0014 \wx0014 // sprite layout
		\wx005B \wx0140 \wx0140 // animation control
		\wx005A \wx0141 \wx0141 // animation frame
		\wx0009 // real sprites

	1 * 1	03 04
		01 STEEL_MILL
		02
		09 \wx0012 // steel
		FF \wx0013 // purchase
		\wx001F // no suitable cargo
