summaryrefslogtreecommitdiff
path: root/apps/plugins/pacbox/arcade.h
blob: 5de2517e80f55127bad3d4bcec15eb2c5276b919 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Pacbox - a Pacman Emulator for Rockbox
 *
 * Based on PIE - Pacman Instructional Emulator
 *
 * Copyright (c) 1997-2003,2004 Alessandro Scotti
 * http://www.ascotti.org/
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#ifndef ARCADE_H_
#define ARCADE_H_

#include "plugin.h"
#include "z80.h"
#include "hardware.h"

extern fb_data  palette[256];  /* Color palette in native Rockbox format */

/**
    Pacman sprite properties.

    This information is only needed by applications that want to do their own
    sprite rendering, as the renderVideo() function already draws the sprites.

    @see PacmanMachine::renderVideo
*/

/** Machine hardware data */
enum {
    ScreenWidth         = 224,
    ScreenHeight        = 288,
    ScreenWidthChars    = 28,
    ScreenHeightChars   = 36,
    CharWidth           = 8,
    CharHeight          = 8,
    VideoFrequency      = 60,
    CpuClock            = 3072000,
    SoundClock          = 96000,    // CPU clock divided by 32
    CpuCyclesPerFrame   = CpuClock / VideoFrequency
};

/** Input devices and switches */
enum InputDevice {
    Joy1_Up = 0,
    Joy1_Left,
    Joy1_Right,
    Joy1_Down,
    Switch_RackAdvance,
    CoinSlot_1,
    CoinSlot_2,
    Switch_AddCredit,
    Joy2_Up,
    Joy2_Left,
    Joy2_Right,
    Joy2_Down,
    Switch_Test,
    Key_OnePlayer,
    Key_TwoPlayers,
    Switch_CocktailMode
};

/** Input device mode */
enum InputDeviceMode {
    DeviceOn,
    DevicePushed = DeviceOn,
    DeviceOff,
    DeviceReleased = DeviceOff,
    DeviceToggle
};

/** DIP switches */
enum {
    DipPlay_Free            =   0x00, // Coins per play
    DipPlay_OneCoinOneGame  =   0x01,
    DipPlay_OneCoinTwoGames =   0x02,
    DipPlay_TwoCoinsOneGame =   0x03,
    DipPlay_Mask            =   0x03,
    DipLives_1              =   0x00, // Lives per game
    DipLives_2              =   0x04,
    DipLives_3              =   0x08,
    DipLives_5              =   0x0C,
    DipLives_Mask           =   0x0C,
    DipBonus_10000          =   0x00, // Bonus life
    DipBonus_15000          =   0x10,
    DipBonus_20000          =   0x20,
    DipBonus_None           =   0x30,
    DipBonus_Mask           =   0x30,
    DipDifficulty_Normal    =   0x40, // Difficulty
    DipDifficulty_Hard      =   0x00,
    DipDifficulty_Mask      =   0x40,
    DipGhostNames_Normal    =   0x80, // Ghost names
    DipGhostNames_Alternate =   0x00,
    DipGhostNames_Mask      =   0x80,
    DipMode_Play            = 0x0000, // Play/test mode
    DipMode_Test            = 0x0100,
    DipMode_Mask            = 0x0100,
    DipCabinet_Upright      = 0x0000, // Cabinet upright/cocktail
    DipCabinet_Cocktail     = 0x0200,
    DipCabinet_Mask         = 0x0200,
    DipRackAdvance_Off      = 0x0000, // Automatic level advance
    DipRackAdvance_Auto     = 0x0400,
    DipRackAdvance_Mask     = 0x0400
};

void init_PacmanMachine(int dip);
int run(void);
void reset_PacmanMachine(void);
void decodeROMs(void);

/**
    Tells the emulator that the status of an input device has changed.
*/
void setDeviceMode( enum InputDevice device, enum InputDeviceMode mode );

/**
    Returns the value of the DIP switches.
*/
unsigned getDipSwitches(void);

/**
    Sets the value of the DIP switches that control several game settings
    (see the Dip... constants above). 
    
    Most of the DIP switches are read at program startup and take effect 
    only after a machine reset.
*/
void setDipSwitches( unsigned value );

/**
    Draws the current video into the specified buffer.

    The buffer must be at least 224*288 bytes long. Pixels are stored in
    left-to-right/top-to-bottom order starting from the upper left corner.
    There is one byte per pixel, containing an index into the color palette 
    returned by getPalette().

    It's up to the application to display the buffer to the user. The 
    code might look like this:
    <BLOCKQUOTE>
    <PRE>
    @@    unsigned char video_buffer[ PacmanMachine::ScreenWidth * PacmanMachine::ScreenHeight ];
    @@    unsigned char * vbuf = video_buffer;
    @@    const unsigned * palette = arcade.getPalette();
    @@
    @@    arcade.renderVideo( vbuf );
    @@
    @@    for( int y=0; y<PacmanMachine::ScreenHeight; y++ ) {
    @@        for( int x=0; x<PacmanMachine::ScreenWidth; x++ ) {
    @@            unsigned color = palette[ *vbuf++ ];
    @@            unsigned char red = color & 0xFF;
    @@            unsigned char green = (color >> 8) & 0xFF;
    @@            unsigned char blue = (color >> 16) & 0xFF;
    @@
    @@            setPixel( x, y, red, green, blue );
    @@        }
    @@    }
    </PRE>
    </BLOCKQUOTE>

*/
bool renderBackground( unsigned char * buffer );
void renderSprites( unsigned char * buffer );

/**
    Enables/disables a common speed hack that allows Pacman to
    move four times faster than the ghosts.

    @param enabled true to enabled the hack, false to disable

    @return 0 if successful, otherwise the patch could not be applied
            (probably because the loaded ROM set does not support it)
*/
int setSpeedHack( int enabled );

/* Implementation of the Z80 Environment interface */
unsigned char readByteHigh( unsigned addr );

void writeByte( unsigned, unsigned char );

unsigned char readPort( unsigned port );

void writePort( unsigned, unsigned char );

#endif // ARCADE_H_