###############################################################################
#
#  File:  dkong3.keg
#
#  Description:
#
#      This file contains the definition for Donkey Kong 3.
#
#  Author:  Kevin Brisley
#
###############################################################################


#
#  The name of the game.
#
DKong3.Name:                           Donkey Kong 3

# 
#  The desired FPS.
#
DKong3.FramesPerSecond:                60

#
#  The history and anecdote files.
#
DKong3.HistoryFile:                    dkong3.his
DKong3.TalesFile:                      dkong3.tal

#
#  Address spaces.
#
DKong3.NumSpaces:                       1

#
#  The first address space is used by the Game CPU.  It includes the following:
#  0x00000-0x0FFFF (64K):      Game RAM/ROM.
#  0x10000-0x10000 (1Byte):    Gfx Bank Select.
#
DKong3.Space1.Size:                     0x10001
DKong3.Space1.NumROMs:                  4
DKong3.Space1.ROM1.Description:         dk3c.7b @ 0x00000
DKong3.Space1.ROM2.Description:         dk3c.7c @ 0x02000
DKong3.Space1.ROM3.Description:         dk3c.7d @ 0x04000
DKong3.Space1.ROM4.Description:         dk3c.7e @ 0x08000

#
#  CPUs.
#
DKong3.NumCPUs:                         1

#
#  CPU 1 (game).
#
DKong3.CPU1.Description:                Game
DKong3.CPU1.Type:                       Z80_OLD
DKong3.CPU1.ClockSpeed:                 4000000
DKong3.CPU1.Space:                      1
DKong3.CPU1.IValue:                     INT_NMI
DKong3.CPU1.IDisable:                   0x07e84


#
#  The number of inputs.
#
DKong3.NumInputs:                       4

DKong3.Input1.Description:              Player 1 Controls
DKong3.Input1.CPU:                      1
DKong3.Input1.Location:                 0x07c00
DKong3.Input1.Default:                  0x00

DKong3.Input2.Description:              Player 2 Controls
DKong3.Input2.CPU:                      1
DKong3.Input2.Location:                 0x07c80
DKong3.Input2.Default:                  0x00

DKong3.Input3.Description:              Dip Switch 1
DKong3.Input3.CPU:                      1
DKong3.Input3.Location:                 0x07d00
DKong3.Input3.Default:                  0x00

DKong3.Input4.Description:              Dip Switch 2
DKong3.Input4.CPU:                      1
DKong3.Input4.Location:                 0x07d80
DKong3.Input4.Default:                  0x00

#
#  The number of outputs.
#
DKong3.NumOutputs:                      1

DKong3.Output1.Description:             Gfx Set Select
DKong3.Output1.CPU:                     1
DKong3.Output1.WLocation:               0x07e81
DKong3.Output1.Location:                0x10000
DKong3.Output1.NumConversions:          1
DKong3.Output1.ConversionList:          0x00, 0x01
DKong3.Output1.ConversionDefault:       0x00

#
#  The keys used in the game.
#
DKong3.NumKeys:                         14

#  Player 2 Start
DKong3.Key1.Key:                        KEY_2
DKong3.Key1.Mask:                       0x40
DKong3.Key1.Input:                      1
DKong3.Key1.Default:                    Off/0

#  Player 1 Start
DKong3.Key2.Key:                        KEY_1
DKong3.Key2.Mask:                       0x20
DKong3.Key2.Input:                      1
DKong3.Key2.Default:                    Off/0

#  Player 1 Jump
DKong3.Key3.Key:                        KEY_SPACE
DKong3.Key3.Joy:                        JOY_B1  
DKong3.Key3.Mask:                       0x10
DKong3.Key3.Input:                      1
DKong3.Key3.Default:                    Off/0

#  Player 1 Down 
DKong3.Key4.Key:                        KEY_DOWN 
DKong3.Key4.Joy:                        JOY_DOWN 
DKong3.Key4.Mask:                       0x08
DKong3.Key4.Input:                      1
DKong3.Key4.Default:                    Off/0

#  Player 1 Up
DKong3.Key5.Key:                        KEY_UP
DKong3.Key5.Joy:                        JOY_UP
DKong3.Key5.Mask:                       0x04
DKong3.Key5.Input:                      1
DKong3.Key5.Default:                    Off/0

#  Player 1 Left
DKong3.Key6.Key:                        KEY_LEFT
DKong3.Key6.Joy:                        JOY_LEFT
DKong3.Key6.Mask:                       0x02
DKong3.Key6.Input:                      1
DKong3.Key6.Default:                    Off/0

#  Player 1 Right
DKong3.Key7.Key:                        KEY_RIGHT
DKong3.Key7.Joy:                        JOY_RIGHT
DKong3.Key7.Mask:                       0x01
DKong3.Key7.Input:                      1
DKong3.Key7.Default:                    Off/0

#  Coin 2      
DKong3.Key8.Key:                        KEY_3
DKong3.Key8.Mask:                       0x40
DKong3.Key8.Input:                      2
DKong3.Key8.Default:                    Off/0

#  Coin 1        
DKong3.Key9.Key:                        KEY_4
DKong3.Key9.Mask:                       0x20
DKong3.Key9.Input:                      2
DKong3.Key9.Default:                    Off/0

#  Player 2 Jump
DKong3.Key10.Key:                       KEY_A
DKong3.Key10.Mask:                      0x10
DKong3.Key10.Input:                     2
DKong3.Key10.Default:                   Off/0

#  Player 2 Down 
DKong3.Key11.Key:                       KEY_K
DKong3.Key11.Mask:                      0x08
DKong3.Key11.Input:                     2
DKong3.Key11.Default:                   Off/0

#  Player 2 Up    
DKong3.Key12.Key:                       KEY_I
DKong3.Key12.Mask:                      0x04
DKong3.Key12.Input:                     2
DKong3.Key12.Default:                   Off/0

#  Player 2 Left
DKong3.Key13.Key:                       KEY_J
DKong3.Key13.Mask:                      0x02
DKong3.Key13.Input:                     2
DKong3.Key13.Default:                   Off/0

#  Player 2 Right
DKong3.Key14.Key:                       KEY_L
DKong3.Key14.Mask:                      0x01
DKong3.Key14.Input:                     2
DKong3.Key14.Default:                   Off/0


#
#  The dip switches used in the game.
#
DKong3.NumDips:                         8 

#  Difficulty (1 of 2)
DKong3.Dip1.Description:                Difficulty (1 of 2)
DKong3.Dip1.Mask:                       0x80
DKong3.Dip1.Input:                      4
DKong3.Dip1.Default:                    Off/0

#  Difficulty (2 of 2)
DKong3.Dip2.Description:                Difficulty (2 of 2)
DKong3.Dip2.Mask:                       0x40
DKong3.Dip2.Input:                      4
DKong3.Dip2.Default:                    On/1

#  Bonus Life (1 of 2)
DKong3.Dip3.Description:                Bonus Life (1 of 2)
DKong3.Dip3.Mask:                       0x20
DKong3.Dip3.Input:                      4
DKong3.Dip3.Default:                    Off/0

#  Bonus Life (2 of 2)
DKong3.Dip4.Description:                Bonus Life (2 of 2)
DKong3.Dip4.Mask:                       0x10
DKong3.Dip4.Input:                      4
DKong3.Dip4.Default:                    Off/0

#  Coins Per Play (1 of 2)
DKong3.Dip5.Description:                Coins Per Play (1 of 2)
DKong3.Dip5.Mask:                       0x08
DKong3.Dip5.Input:                      4
DKong3.Dip5.Default:                    Off/0

#  Coins Per Play (2 of 2)
DKong3.Dip6.Description:                Coins Per Play (2 of 2)
DKong3.Dip6.Mask:                       0x04
DKong3.Dip6.Input:                      4
DKong3.Dip6.Default:                    Off/0

#  Number of Lives (1 of 2)
DKong3.Dip7.Description:                Number of Lives (1 of 2)
DKong3.Dip7.Mask:                       0x02
DKong3.Dip7.Input:                      4
DKong3.Dip7.Default:                    Off/0

#  Number of Lives (2 of 2)
DKong3.Dip8.Description:                Number of Lives (2 of 2)
DKong3.Dip8.Mask:                       0x01
DKong3.Dip8.Input:                      4
DKong3.Dip8.Default:                    Off/0


#
#  Screen Resolution.
#
DKong3.ScreenWidth:                     256
DKong3.ScreenHeight:                    256


#
#  Graphics Sets.
#
DKong3.NumGfxSets:                      2

#
#  The first set contains the characters.
#
DKong3.GfxSet1.Width:                   8
DKong3.GfxSet1.Height:                  8
DKong3.GfxSet1.Number:                  512
DKong3.GfxSet1.BPP:                     2
DKong3.GfxSet1.BPs:                     0 32768
DKong3.GfxSet1.XBits:                    56  48  40  32  24  16   8   0
DKong3.GfxSet1.YBits:                     0   1   2   3   4   5   6   7
DKong3.GfxSet1.Increment:               64
DKong3.GfxSet1.NumROMs:                 2
DKong3.GfxSet1.ROM1.Description:        dk3v.3n
DKong3.GfxSet1.ROM2.Description:        dk3v.3p

#
#  The second set contains the sprites.
#
DKong3.GfxSet2.Width:                   16
DKong3.GfxSet2.Height:                  16
DKong3.GfxSet2.Number:                  256
DKong3.GfxSet2.BPP:                     2
DKong3.GfxSet2.BPs:                     0 65536
DKong3.GfxSet2.XBits:                   120 112 104  96  88  80  72  64 \
                                         56  48  40  32  24  16   8   0
DKong3.GfxSet2.YBits:                     0   1   2   3   4   5   6   7 \
                                          32768   32769   32770   32771 \
                                          32772   32773   32774   32775
DKong3.GfxSet2.Increment:               128
DKong3.GfxSet2.NumROMs:                 4
DKong3.GfxSet2.ROM1.Description:        dk3v.7c
DKong3.GfxSet2.ROM2.Description:        dk3v.7d
DKong3.GfxSet2.ROM3.Description:        dk3v.7e
DKong3.GfxSet2.ROM4.Description:        dk3v.7f


#
#  Graphic Layers
#
DKong3.NumGfxLayers:                    2


###############################################################################
#  The first layer renders the characters.
#
#  The video RAM starts at 0x07400 and is used for the characters and the
#  colour.  The value written to 0x07e81 indicates which graphic bank to
#  use.  This is stored in 0x10000.  The RAM is mapped as follows:
#
#      0x77e0 0x77c0 0x77a0   ...   0x7420 0x7400
#      0x77e1 0x77c1 0x77a1   ...   0x7421 0x7401
#      ...    ...    ...            ...    ...
#      0x77ff 0x77df 0x77bf   ...   0x743f 0x741f
###############################################################################
DKong3.GfxLayer1.Lightweight:                  Yes
DKong3.GfxLayer1.Space:                        1
DKong3.GfxLayer1.GfxSet:                       1
DKong3.GfxLayer1.Palette:                      1
DKong3.GfxLayer1.ColourTable:                  1
DKong3.GfxLayer1.Transparency:                 Off
DKong3.GfxLayer1.NumChars:                     1024   

DKong3.GfxLayer1.NumDirty:                     2
DKong3.GfxLayer1.Dirty1.Start:                 0x07400
DKong3.GfxLayer1.Dirty1.End:                   0x077ff
DKong3.GfxLayer1.Dirty1.CharsPerLoc:           1
DKong3.GfxLayer1.Dirty1.Assign:                #
DKong3.GfxLayer1.Dirty2.Start:                 0x10000
DKong3.GfxLayer1.Dirty2.End:                   0x10000
DKong3.GfxLayer1.Dirty2.CharsPerLoc:           1024
DKong3.GfxLayer1.Dirty2.Assign:                $

DKong3.GfxLayer1.NumCharNums:                  1
DKong3.GfxLayer1.CharNum1.Value:               @0x10000 * 256 + @(0x07400 + #)

DKong3.GfxLayer1.NumColours:                   1
DKong3.GfxLayer1.Colour1.Value:                \
    (@0x10000 * 256 + @(0x07400 + #)) >> 2

DKong3.GfxLayer1.NumXPoss:                     1
DKong3.GfxLayer1.XPos1.Value:                  (31 - # / 32) * 8

DKong3.GfxLayer1.NumYPoss:                     1
DKong3.GfxLayer1.YPos1.Value:                  (# % 32) * 8


###############################################################################
#  The second layer renders the sprites.
#
#  The sprite RAM starts at 0x06900.  There are 4 sequential bytes per
#  sprite and 96 sprites.  The following describes the 4 bytes:
#
#      0 : X Position & Enable.
#      1 : bits 0-6 indicates part 1 of the sprite number
#          bit  7   indicates vertical flip
#      2 : bits 0-5 indicate the colour
#          bit  6   indicates part 2 of the sprite number
#          bit  7   indicates horizontal flip
#      3 : Y Position.
###############################################################################
DKong3.GfxLayer2.Space:                  1
DKong3.GfxLayer2.GfxSet:                 2
DKong3.GfxLayer2.Palette:                1
DKong3.GfxLayer2.ColourTable:            2
DKong3.GfxLayer2.Clipping:               0,255,0,255
DKong3.GfxLayer2.Transparency:           On
DKong3.GfxLayer2.NumChars:               96

DKong3.GfxLayer2.NumDirty:               1
DKong3.GfxLayer2.Dirty1.Start:           0x06900
DKong3.GfxLayer2.Dirty1.End:             0x06a7f
DKong3.GfxLayer2.Dirty1.CharsPerLoc:     1
DKong3.GfxLayer2.Dirty1.Assign:          # / 4

DKong3.GfxLayer2.NumCharNums:            1
DKong3.GfxLayer2.CharNum1.Value:         \
    (@(0x6901 + 4 * #) & 0x7f) + 2 * (@(0x6902 + 4 * #) & 0x40)

DKong3.GfxLayer2.NumColours:             1
DKong3.GfxLayer2.Colour1.Value:          @(0x6902 + 4 * #) & 0x3f

DKong3.GfxLayer2.NumXPoss:               1
DKong3.GfxLayer2.XPos1.Value:            @(0x6900 + 4 * #) - 7

DKong3.GfxLayer2.NumYPoss:               1
DKong3.GfxLayer2.YPos1.Value:            @(0x6903 + 4 * #) - 8

DKong3.GfxLayer2.NumEnables:             1
DKong3.GfxLayer2.Enable1.Value:          @(0x6900 + 4 * #)

DKong3.GfxLayer2.NumHFlips:              1
DKong3.GfxLayer2.HFlip1.Value:           @(0x6901 + 4 * #) & 0x80

DKong3.GfxLayer2.NumVFlips:              1
DKong3.GfxLayer2.VFlip1.Value:           @(0x6902 + 4 * #) & 0x80



#
#  Colour Palettes
#
DKong3.NumPalettes:                     1

DKong3.Palette1.NumColours:             16
DKong3.Palette1.MaxValue:               255
DKong3.Palette1.Colour1.RGB:            0x00/0x00/0x00
DKong3.Palette1.Colour2.RGB:            0xdb/0x00/0x00
DKong3.Palette1.Colour3.RGB:            0xdb/0x92/0x49
DKong3.Palette1.Colour4.RGB:            0xff/0xb6/0xdb
DKong3.Palette1.Colour5.RGB:            0x00/0xdb/0x00
DKong3.Palette1.Colour6.RGB:            0x00/0xdb/0xdb
DKong3.Palette1.Colour7.RGB:            0x49/0xb6/0xdb
DKong3.Palette1.Colour8.RGB:            0xff/0xb6/0x49
DKong3.Palette1.Colour9.RGB:            0x88/0x88/0x88
DKong3.Palette1.Colour10.RGB:           0xdb/0xdb/0x00
DKong3.Palette1.Colour11.RGB:           0xff/0x00/0xdb
DKong3.Palette1.Colour12.RGB:           0x24/0x24/0xdb
DKong3.Palette1.Colour13.RGB:           0x00/0xdb/0x00
DKong3.Palette1.Colour14.RGB:           0x49/0xb6/0x92
DKong3.Palette1.Colour15.RGB:           0xff/0xb6/0x92
DKong3.Palette1.Colour16.RGB:           0xdb/0xdb/0xdb

#
#  The colour lookup table.
#
DKong3.NumColourTables:           2

DKong3.ColourTable1.NumEntries:   256
DKong3.ColourTable1.List:                                                     \
                                  0x00,0x04,0x08,0x0f, 0x00,0x04,0x08,0x0f,   \
                                  0x00,0x04,0x01,0x0f, 0x00,0x0b,0x01,0x0d,   \
                                  0x00,0x01,0x01,0x01, 0x00,0x01,0x01,0x01,   \
                                  0x00,0x01,0x01,0x01, 0x00,0x01,0x01,0x01,   \
                                  0x00,0x01,0x01,0x01, 0x00,0x01,0x01,0x01,   \
                                  0x00,0x0d,0x01,0x01, 0x00,0x0d,0x0d,0x0d,   \
                                  0x00,0x0d,0x0a,0x0d, 0x00,0x01,0x0b,0x0f,   \
                                  0x00,0x0b,0x0b,0x0f, 0x00,0x01,0x0b,0x0f,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0b,0x0d,0x0c, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x06,0x0a,0x0b, 0x00,0x06,0x0a,0x0b
                              
DKong3.ColourTable2.NumEntries:   64
DKong3.ColourTable2.List:                                                     \
                                  0x00,0x01,0x02,0x0f, 0x00,0x04,0x08,0x0a,   \
                                  0x00,0x08,0x04,0x0a, 0x00,0x0b,0x0d,0x0c,   \
                                  0x00,0x0a,0x08,0x04, 0x00,0x0b,0x0d,0x0f,   \
                                  0x00,0x04,0x0a,0x08, 0x00,0x0d,0x01,0x0b,   \
                                  0x00,0x0e,0x02,0x0b, 0x00,0x01,0x0c,0x0b,   \
                                  0x00,0x01,0x02,0x09, 0x00,0x0d,0x0c,0x0b,   \
                                  0x00,0x0d,0x0b,0x0c, 0x00,0x06,0x01,0x09,   \
                                  0x00,0x01,0x0c,0x0f, 0x00,0x01,0x02,0x01