burgertime hardware
-------------------
note: all of this info is from looking at the confusing mame sources, since i didnt have an
internet connection when i wrote this + my emulator to look up some websites with info.
compile mame with the debugger, its really cool!  if any of this info confuses you, read
it more.  btw, i am not good at explaining shit and most of this stuff will only be
understood by me :P  somethings are probably left out of this, so just look through the
sources of my emulator and you will find it.  sound chip stuff is left out.

another note: have fun and disassemble the roms, a lot of the opcodes are wrong when you
look at it from the encrypted ones.  the disassemblys i made really fucked up my brain
until i remembered some opcodes were encrypted :P

info:
	the screen is 256x256, but viewable area is 240x240, think of like an 8 pixel border
around the screen.  there is the 2 memory maps for each cpu, and 3 vrom banks, the screen
and sprite tiles are $6000 bytes big and are bank 0, background tiles are $1800 bytes big
and are bank 1, and background information is $800 bytes and is bank 2.  there are 1024
screen and sprite tiles, and 64 background tiles.

memory map - main cpu:
	+---------+-------+---------------------------------------------+
	| address | size  | description                                 |
	+---------+-------+---------------------------------------------+
	| $0000   | $0800 | ram                                         |
	| $0c00   | $0010 | palette ram                                 |
	| $1000   | $0400 | video ram                                   |
	| $1400   | $0400 | color ram                                   |
	| $1800   | $0400 | video ram mirror                            |
	| $1c00   | $0400 | color ram mirror                            |
	| $4000   | $0001 | player 1 input (read)                       |
	| $4001   | $0001 | player 2 input (read)                       |
	| $4002   | $0001 | video control (write)                       |
	| $4003   | $0001 | dip switch 1 (read) / sound command (write) |
	| $4004   | $0001 | dip switch 2 (read)                         |
	| $c000   | $4000 | rom                                         |
	+---------+-------+---------------------------------------------+

memory map - sound cpu:
	+---------+-------+---------------------------------------------+
	| address | size  | description                                 |
	+---------+-------+---------------------------------------------+
	| $0000   | $0400 | ram                                         |
	| $a000   | $0001 | sound command (read only)                   |
	| $a001   | $0fff | mirror of $a000                             |
	| $f000   | $1000 | rom                                         |
	+---------+-------+---------------------------------------------+

ports - main cpu:
	+-[ $4000 - player 1 input (read only) ]---------------+
	|                                                      |
	| xx?bdulr                                             |
	|    |||||                                             |
	|    ||||+--- right                                    |
	|    |||+---- left                                     |
	|    ||+----- up                                       |
	|    |+------ down                                     |
	|    +------- button                                   |
	|                                                      |
	| when a bit is set to 0, the button is pressed        |
	|                                                      |
	+-[ $4001 - player 2 input (read only) ]---------------+
	|                                                      |
	| xx?bdulr                                             |
	|    |||||                                             |
	|    ||||+--- right                                    |
	|    |||+---- left                                     |
	|    ||+----- up                                       |
	|    |+------ down                                     |
	|    +------- button                                   |
	|                                                      |
	| when a bit is set to 0, the button is pressed        |
	|                                                      |
	+-[ $4002 - coins/start buttons (read only) ]----------+
	|                                                      |
	| ba????21                                             |
	| ||    ||                                             |
	| ||    |+--- player 1 start button                    |
	| ||    |      0: pressed                              |
	| ||    |      1: not pressed                          |
	| ||    +---- player 2 start button                    |
	| ||           0: pressed                              |
	| ||           1: not pressed                          |
	| |+--------- coin slot a                              |
	| |            0: no coin inserted                     |
	| |            1: coin inserted                        |
	| +---------- coin slot b                              |
	|              0: no coin inserted                     |
	|              1: coin inserted                        |
	|                                                      |
	| nmi is generated on main cpu when a coin is inserted |
	|                                                      |
	+-[ $4002 - video control (write only) ]---------------+
	|                                                      |
	| ???????f                                             |
	|        |                                             |
	|        +--- flip screen (x and y are flipped)        |
	|                                                      |
	+-[ $4003 - dip switch 1 (read only) ]-----------------+
	|                                                      |
	| vchsbbaa                                             |
	| ||||\|\|                                             |
	| |||| | +--- coin a                                   |
	| |||| |       00: 2 coins = 1 credit                  |
	| |||| |       01: 1 coin = 3 credits                  |
	| |||| |       10: 1 coin = 2 credits                  |
	| |||| |       11: 1 coin = 1 credit                   |
	| |||| +----- coin b                                   |
	| ||||         00: 2 coins = 1 credit                  |
	| ||||         01: 1 coin = 3 credits                  |
	| ||||         10: 1 coin = 2 credits                  |
	| ||||         11: 1 coin = 1 credit                   |
	| |||+------- service mode                             |
	| |||          0: on                                   |
	| |||          1: off                                  |
	| ||+-------- show cross hatch                         |
	| ||           0: on                                   |
	| ||           1: off                                  |
	| |+--------- cabinet type                             |
	| |            0: upright                              |
	| |            1: cocktail                             |
	| +---------- vblank status                            |
	|              0: not in vblank                        |
	|              1: in vblank                            |
	|                                                      |
	+-[ $4003 - sound command (write only) ]---------------+
	|                                                      |
	| vvvvvvvv -- command                                  |
	|                                                      |
	| this value gets put into a latch, which is read by   |
	| the sound cpu when it reads $a000 or its mirrors.    |
	| after a write here, the sound cpu gets an irq        |
	|                                                      |
	+-[ $4004 - dip switch 2 (read only) ]-----------------+
	|                                                      |
	| ???pebbl                                             |
	|    ||\||                                             |
	|    || |+--- lives                                    |
	|    || |      0: 5 lives                              |
	|    || |      1: 3 lives                              |
	|    || +---- bonus life                               |
	|    ||        00: 30000 points                        |
	|    ||        01: 20000 points                        |
	|    ||        10: 15000 points                        |
	|    ||        11: 10000 points                        |
	|    |+------ enemies                                  |
	|    |         0: 6 enemies                            |
	|    |         1: 4 enemies                            |
	|    +------- end of level pepper                      |
	|              0: on                                   |
	|              1: off                                  |
	|                                                      |
	+------------------------------------------------------+

ports - main cpu:
	+-[ $a000 - sound command (read only) ]----------------+
	|                                                      |
	| vvvvvvvv -- command                                  |
	|                                                      |
	| this is the value written to $4003 on the main cpu   |
	|                                                      |
	+------------------------------------------------------+

tile format:
	each tile is 3 bits each, the bits are seperated into 3 areas, to get bit x from an area,
use the formula (n * s * b).  n is the total number of tiles in the bank (see info section,
it says how many tiles are in the banks), s is the size of one tile in bytes for one bit plane,
like and 8x8 tile is 8 bytes, and 16x16 tile is 32 bytes.  b is the bit you need to get, 0, 1,
or 2.

palette:
	there is 16 palette entries for burger time.  the upper 8 colors are used for only the
background, the lower 8 are used for screen and sprites.  to get r g and b values from each
write, use this c code (i dunno how to explain this, its based on mame's anyway :P)
	value = ~value;
	r = (0x21 * ((value >> 0) & 1)) + (0x47 * ((value >> 1) & 1)) + (0x97 * ((value >> 2) & 1));
	g = (0x21 * ((value >> 3) & 1)) + (0x47 * ((value >> 4) & 1)) + (0x97 * ((value >> 5) & 1));
	b = (0x47 * ((value >> 6) & 1)) + (0x97 * ((value >> 7) & 1));

encrpytion:
	during a write, if the next opcode address has bits 2 and 8 set (0x0104), then the opcode
needs decrypting.  watch out for jsr, since it writes to the stack during execution you will
need to check the address of the opcode that jsr jumps to and see if it has the bits set.  to
decrypt the opcode, change around the bits from 76543210 to 65342710.  here is code i used:
	addr = getnextopcodepc();
	tmp = getcurrentopcodepc();
	if(cpumem[2][tmp] == 0x20)
		addr = mem[tmp+1] + (mem[tmp+2] << 8);
	if((addr & 0x0104) == 0x0104)
		cpumem[2][addr] = (u8)((mem[addr] & 0x13) | ((mem[addr] & 0x80) >> 5) | ((mem[addr] & 0x64) << 1) | ((mem[addr] & 0x08) << 2));
cpumem[2] is the decrypted opcode space, and mem is the main cpus memory

sprites:
	there are 8 sprites, each sprite uses up 4 bytes, each byte is 32 bytes after the last one
in video ram.  starting at 0, then 32, 64, 96 for sprite 0, then 128, 160, 192, and 224 for
sprite 1, etc etc.  use this chart for each byte:

	+-[ first byte ]---------------------------------------+
	|                                                      |
	| ?????xy?                                             |
	|      ||                                              |
	|      |+---- flip x                                   |
	|      +----- flip y                                   |
	|                                                      |
	+-[ second byte ]--------------------------------------+
	|                                                      |
	| tttttttt -- tile to use from vrom bank 0             |
	|                                                      |
	+-[ third byte ]---------------------------------------+
	|                                                      |
	| yyyyyyyy -- y coordinate                             |
	|                                                      |
	+-[ fourth byte ]--------------------------------------+
	|                                                      |
	| xxxxxxxx -- x coordinate                             |
	|                                                      |
	+------------------------------------------------------+

thanks:
	mame - www.mame.net

written by Dead_Body - www.parodius.com/~deadbody/ - deadbody@parodius.com
