Background editor collection for C64 crossdevelopment
-----------------------------------------------------

Utilities written by Lasse rni (loorni@student.oulu.fi)

CovertBitOps C64 page: http://covertbitops.cjb.net

SDL library (http://www.libsdl.org), BME library and gcc required to recompile.


BGEDIT   - MW background editor, color per block, 128 blocks max.
BGEDIT2  - MW2 background editor, color per char, 128 blocks max.
BGEDIT3  - MW3 background editor, color per char, 192 blocks max., 4 color-sets for
           $d021-$d023 (night,evening,morning,day)
TBGEDIT  - Detective Takashi (unfinished game) background editor, color per
           block, 192 blocks max.
BOFHEDIT - BOFH background editor, color per block, 256 blocks max.
AOMEDIT  - MW4 background editor, color per char, 256 blocks max, saves in
           chunk-file format (not useful unless you use the old MW4 engine)
AOMEDIT2 - MW4 background editor, color per block, 192 chars only, 256 blocks
           max., uses various special features corresponding to MW4


Char/block editor: (all editors)
--------------------------------

LBM     Draw
RMB     Erase
, .     Select char
Z X     Select block
C       Clear char
Cursors Slide char
P       Put char to copybuffer
T       Take char from copybuffer
Q       Put block to copybuffer
W       Take block from copybuffer
1-8     Edit char bits (for collision detection)
F1      Load chars
F2      Save chars
F3      Load blocks
F4      Save blocks
F5      Go to map editor
F6      Go to level editor
F7      Load chars with collision-info
F8      Save chars with collision-info
F9      Load all leveldata (chars, blocks, map, actordata)
F10     Save all leveldata

Map editor: (all editors)
-------------------------

LBM     Draw with selected block
Z X     Select block
I J K M Change map size
G       Grab block under cursor
F1      Load map
F2      Save map
F5      Go to char/block editor
F6      Go to level editor
F9      Load all leveldata (chars, blocks, map, actordata)
F10     Save all leveldata

Level editor: (BGEDIT,BGEDIT2,BGEDIT3)
--------------------------------------

LMB     Create actor
RMB     Remove actor
Z X     Change actornumber
1 2 3 4 Change actornumber
5 6 7 8 Change power of actor under mousecursor
5 6 , . Change destination of door under mousecursor
D       Create/delete door
F5      Go to char/block editor
F6      Go to map editor
F9      Load all leveldata (chars, blocks, map, actordata)
F10     Save all leveldata

MW3 editor added keys (BGEDIT3)
-------------------------------

M       Toggle multi/singlecolor for char
V B N   Swap colors of char
R       Reverse char
V,B,N   Swap char colors
TAB     Cycle between the 4 colormodes

BOFH editor special keys: (BOFHEDIT)
------------------------------------

0-6     Select floor to draw (in map editor only)

BOFH level editor: (BOFHEDIT)
-----------------------------

C V     Change actornumber (if mouse not over any actor)
C V     Change actor's (under cursor) power
A       Create new actor
D       Delete actor under cursor
R       Rotate actor under cursor 45 degrees

Editing BOFH levels gets quite messy as the actor-infos fill the screen :)

MW4 editor added keys (AOMEDIT)
-------------------------------

F7      Go to zone editor
F8	Go to actor editor


MW4 actor/door editor (AOMEDIT)
-------------------------------

Z X     Select actornumber (actornumber 1 is always an item)
C V     Select actor's weapon/item's type
, .     Select actor's hitpoints/item's pickup amount (0 = default)
        or door's destination number
N M     Select actor's ID (needed for script operations)
G       Select actor's group association
D       Select actor's initial direction
A       Select actor's initial AI state
E       Create/delete door
F5      Go to char/block editor
F6      Go to map editor
F7      Go to zone editor
F9      Load all leveldata (chars, blocks, map, leveldata)
F10     Save all leveldata

MW4 zone editor (AOMEDIT)
-------------------------

LMB     Mark zone top-left corner
RMB     Mark zone bottom-right corner
Z X     Select zone
N M     Change zone music


AOMEDIT2
--------

AOMEDIT2 is somewhat similar to AOMEDIT in operation. Note that zone must always be marked or otherwise saved map data will be lost!!! AOMEDIT2 also doesn't have ability
to store actor's ID, health or group association at all.

AOMEDIT2 char editor added keys
-------------------------------

O 	Optimize charset
U	Remove unused chars
Y	Remove unused blocks (dangerous!)

AOMEDIT2 actor/object editor
----------------------------

LMB	Create level object
RMB	Create actor
DEL	Delete object/actor on cursor

Z,X	Select actor to create
I	Switch between actors/items
L	Go to/leave random actor editor screen
	(use cursor keys + 1,2,Q,W to manipulate)

Object manipulation (when cursor on object)
-------------------------------------------

A	Toggle object animation
S	Toggle object size (height)
D	Toggle object auto-deactivation
R	Toggle object requirement (another object, item carried etc. or none)
Z,X	Select object requirement
E	Toggle requirement item being eaten (one use only)
T,Y	Cycle through object operation types
M,N	Cycle through object activation modes (manual, trigger etc.)
ENTER	Edit object destination/script entrypoint/other data (hex)
	(use LMB in this mode to point for example into an object, actor as
	appropriate, depending on object operation type)
G	Go to object destination, if appropriate (on same level)

Actor/item manipulation (when cursor on actor)
----------------------------------------------

Q,W	Select actor's weapon or item's amount to be added
M,N	Select actor's AI mode
D	Toggle direction
H	Make hidden

Note: for random actor spawnpoint objects the 16bit hex data indicates how the
random generator value is manipulated to select the actor from the list (accessed
by L key). First byte is an add-value and second is and-value. For example the 
default 000F will add 0 and and by 15, so the full range 0-15 is used.


File formats:
-------------

None of these files contain the 2-byte start address, they're raw binary data!

.CHR    Raw C64 character data. In BGEDIT, TBGEDIT and BOFHEDIT this file
        contains also 256 bytes that define the char collision info and only
        then comes the chardata.

        Note that in the editors there's also the option to load/save charsets
        without the collision info but when loading/saving whole leveldata, the
        collision info is always saved.

.INF    Used by BGEDIT2 & BGEDIT3, this contains first the collision info (256
        bytes) for all chars and then char colors (another 256 bytes)

.BLK    Block data. In BGEDIT,TBGEDIT and BOFHEDIT this file contains first the
        block colors (128 blocks -> 128 bytes for BGEDIT, 192 blocks -> 192
        bytes for TBGEDIT, 256 blocks -> 256 bytes for BOFHEDIT) and then the
        character number data of each block in the following order:
        0 1 2 3
        4 5 6 7
        8 9 a b
        c d e f
        So, each block takes 16 bytes and they are stored sequentially starting
        from block 0. Btw. I've verified that for example Sly Spy Secret Agent
        uses 4x4 blocks saved just in the same format and I'm quite sure
        Turricans do so too. BGEDIT2 and BGEDIT3 don't save the block colors (as
        they're char color-based.)

.MAP    Map data. The mapdata itself is rows of block numbers stored
        sequentially in top-down order but the map header (in the beginning of
        the file) changes for each editor:

        For BGEDIT and BGEDIT2:
        <byte> Map X-size in blocks
        <byte> Map Y-size in blocks

        For BGEDIT3:
        <byte> Map X-size in blocks
        <byte> Map Y-size in blocks
        <4 bytes> $d021 values for night,evening,morning,day colors
        <4 bytes> $d022 values for              -||-
        <4 bytes> $d023 values for              -||-

        For TBGEDIT & BOFHEDIT:
        <byte> Map X-size in blocks
        <byte> Map Y-size in blocks
        <byte> $d021 value
        <byte> $d022 value
        <byte> $d023 value

.M0-M6  In BOFHEDIT the .MAP file contains just the header and these contain
        the actual map data.

.A0-A6 (BOFH), .LVL, DOOR.DAT, MW3DOOR.DAT files: game specific. Look at the
game source to see how leveldata is interpreted.


MW4 old engine file formats (AOMEDIT)
-------------------------------------

.CHR    2040 bytes of character set data. The 256th char isn't saved because
        it overlaps the interrupt vectors ($fffa-$ffff)

.BLK    A chunk-datafile, containing blocks. The chunk header is 3 bytes:
        <byte> Number of objects (0)
        <word> Datapart size (high-endian, for optimization)
        The datapart is raw block data, 16 bytes per block, and can be
        variable in size.

.MAP    Begins with the map header:
        <byte> Map X-size in blocks
        <byte> Map Y-size in blocks
        After this comes the chunk header (as above) and raw map data.

.CHC    Char colors (256 bytes)

.CHI    Char collision infos (256 bytes)

.LVA    Level actordata
        <128 bytes> Block X-coordinates
        <128 bytes> Block Y-coordinates
        <128 bytes> Char X,Y-coordinates
        <128 bytes) Type
        <128 bytes) Hitpoints
        <128 bytes) Bits, including direction & group
        <128 bytes) Weapon
        <128 bytes) Actor ID

.LVD    Level doordata
        <42 bytes> Door X-coordinates
        <42 bytes> Door Y-coordinates
        <42 bytes> Destination door number

.LVZ    Level zonedata
        <16 bytes> Left edge block X-coord
        <16 bytes> Right edge block X-coord
        <16 bytes> Top edge block Y-coord
        <16 bytes> Bottom edge block Y-coord
        <16 bytes> $d021 value
        <16 bytes> $d022 value
        <16 bytes> $d023 value
        <16 bytes> Song number

MW4 new engine file formats (AOMEDIT2)
--------------------------------------

.CHR	Character data for 191 chars (64-255)

.CHI	Character collision info. 256 bytes, though only chars 64-255 are often
	used in game background graphics.

.BLK	Level blocks, 16 bytes each block. Variable size

.BLC	Colors for blocks. Variable size (1 byte per block)

.MAP	Raw map data with no header info. Zone information necessary to interpret,
	as data for all zones follows sequentially.

.LVO	Level object data
	<128 bytes> Level object X-coordinates
	<128 bytes> Level object Y-coordinates
	<128 bytes> Level object bits/object operation type
 	<128 bytes> Level object requirements byte
	<128 bytes> Level object destination/info byte 1
	<128 bytes> Level object destination/info byte 2

.LVZ	Level zone data
	<32 bytes> Level zone left limit
	<32 bytes> Level zone right limit
	<32 bytes> Level zone top limit
	<32 bytes> Level zone bottom limit
	<32 bytes> Level zone $d021 value
	<32 bytes> Level zone $d022 value
	<32 bytes> Level zone $d023 value
	<32 bytes> Level zone song number

.LVR	Level random actor spawn data
	<16 bytes> Actor type
	<16 bytes> Actor weapon

LVLACT.DAT Actor data for whole gameworld
	A 6-byte data structure repeats for each actor:
	<byte> Actor levelnumber, high bit indicates purgeability
	       (actors set in editor are not purgeable)
	<byte> Actor X-position in blocks
	<byte> Actor Y-position in block
	<byte> Actor fine position and AI mode
	       (bits 0-1): Fine X-position within block, char accuracy
	       (bits 2-3): Fine Y-position within block, char accuracy
	       (bits 4-7): AI mode
	<byte> Actor type 
	       $00-$7f Enemies / NPCs, lifts etc.
	       $80-$ff items
	<byte> Actor databyte
	       For NPCs this is the weapon type
	       For items this is the amount to add in inventory
			