summaryrefslogtreecommitdiff
path: root/apps/plugins/pacbox/hardware.c
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2006-03-11 15:44:35 +0000
committerDave Chapman <dave@dchapman.com>2006-03-11 15:44:35 +0000
commita814584c87fef79038f6b0f311cfc70fb51d1b95 (patch)
tree4df31679017735c7fa64b32ae78ec3ad078271ae /apps/plugins/pacbox/hardware.c
parent1246668a7807f1f5b9253ad7f9a682fb6b2ff7dd (diff)
pacbox - a Pacman arcade machine emulator. Currently working for all colour targets and the iriver H1x0. Requires the Pacman arcade machine ROMs in /.rockbox/pacman/
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9001 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pacbox/hardware.c')
-rw-r--r--apps/plugins/pacbox/hardware.c197
1 files changed, 197 insertions, 0 deletions
diff --git a/apps/plugins/pacbox/hardware.c b/apps/plugins/pacbox/hardware.c
new file mode 100644
index 0000000000..3cc4858e43
--- /dev/null
+++ b/apps/plugins/pacbox/hardware.c
@@ -0,0 +1,197 @@
+/***************************************************************************
+ * __________ __ ___.
+ * 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.
+ *
+ ****************************************************************************/
+
+#include "plugin.h"
+#include "hardware.h"
+
+extern struct plugin_api* rb;
+
+/* The main data for Pacman */
+
+unsigned char ram_[20*1024] IBSS_ATTR; // ROM (16K) and RAM (4K)
+unsigned char charset_rom_[4*1024] IBSS_ATTR; // Character set ROM (4K)
+unsigned char spriteset_rom_[4*1024] IBSS_ATTR; // Sprite set ROM (4K)
+unsigned char dirty_[1024] IBSS_ATTR;
+unsigned char video_mem_[1024] IBSS_ATTR; // Video memory (1K)
+unsigned char color_mem_[1024] IBSS_ATTR; // Color memory (1K)
+unsigned char charmap_[256*8*8]; /* Character data for 256 8x8 characters */
+unsigned char spritemap_[64*16*16]; /* Sprite data for 64 16x16 sprites */
+unsigned char output_devices_ IBSS_ATTR; /* Output flip-flops set by the game program */
+unsigned char interrupt_vector_ IBSS_ATTR;
+unsigned coin_counter_ IBSS_ATTR;
+unsigned char port1_ IBSS_ATTR;
+unsigned char port2_ IBSS_ATTR;
+unsigned char dip_switches_ IBSS_ATTR;
+
+/* Internal tables and structures for faster access to data */
+struct PacmanSprite sprites_[8]; /* Sprites */
+short vchar_to_i_[1024];
+
+
+/*
+ For Z80 Environment: write a byte to memory.
+*/
+void writeByte( unsigned addr, unsigned char b )
+{
+ addr &= 0x7FFF;
+
+ if( addr < 0x4000 ) {
+ // This is a ROM address, do not write into it!
+ }
+ else if( addr < 0x4400 ) {
+ // Video memory
+ if (ram_[addr] != b) {
+ int x = vchar_to_i_[addr-0x4000];
+ ram_[addr] = b;
+ dirty_[x] = 1;
+ video_mem_[x] = b;
+ }
+ }
+ else if( addr < 0x4800 ) {
+ // Color memory
+ if (ram_[addr] != b) {
+ int x = vchar_to_i_[addr-0x4400];
+ ram_[addr] = b;
+ dirty_[x] = 1;
+ color_mem_[x] = b;
+ }
+ }
+ else if( addr < 0x4FF0 ) {
+ // Standard memory
+ ram_[addr] = b;
+ }
+ else if( addr < 0x5000 ) {
+ // Sprites
+ ram_[addr] = b;
+
+ unsigned idx = (addr - 0x4FF0) / 2;
+
+ if( addr & 1 ) {
+ sprites_[ idx ].color = b;
+ }
+ else {
+ sprites_[ idx ].n = b >> 2;
+ sprites_[ idx ].mode = b & 0x03;
+ }
+ }
+ else {
+ // Memory mapped ports
+ switch( addr ) {
+ case 0x5000:
+ // Interrupt enable
+ setOutputFlipFlop( InterruptEnabled, b & 0x01 );
+ break;
+ case 0x5001:
+ // Sound enable
+ setOutputFlipFlop( SoundEnabled, b & 0x01 );
+ break;
+ case 0x5002:
+ // Aux board enable?
+ break;
+ case 0x5003:
+ // Flip screen
+ setOutputFlipFlop( FlipScreen, b & 0x01 );
+ break;
+ case 0x5004:
+ // Player 1 start light
+ setOutputFlipFlop( PlayerOneLight, b & 0x01 );
+ break;
+ case 0x5005:
+ // Player 2 start light
+ setOutputFlipFlop( PlayerTwoLight, b & 0x01 );
+ break;
+ case 0x5006:
+ // Coin lockout: bit 0 is used to enable/disable the coin insert slots
+ // (0=disable).
+ // The coin slot is enabled at startup and (temporarily) disabled when
+ // the maximum number of credits (99) is inserted.
+ setOutputFlipFlop( CoinLockout, b & 0x01 );
+ break;
+ case 0x5007:
+ // Coin meter (coin counter incremented on 0/1 edge)
+ if( (output_devices_ & CoinMeter) == 0 && (b & 0x01) != 0 )
+ coin_counter_++;
+ setOutputFlipFlop( CoinMeter, b & 0x01 );
+ break;
+ case 0x50c0:
+ // Watchdog reset
+ break;
+ default:
+ if( addr >= 0x5040 && addr < 0x5060 ) {
+ // Sound registers
+ //SOUND sound_chip_.setRegister( addr-0x5040, b );
+ }
+ else if( addr >= 0x5060 && addr < 0x5070 ) {
+ // Sprite coordinates, x/y pairs for 8 sprites
+ unsigned idx = (addr-0x5060) / 2;
+
+ if( addr & 1 ) {
+ sprites_[ idx ].y = 272 - b + 1;
+ }
+ else {
+ sprites_[ idx ].x = 240 - b - 1;
+
+ if( idx <= 2 ) {
+ // In Pacman the first few sprites must be further offset
+ // to the left to get a correct display (is this a hack?)
+ sprites_[ idx ].x -= 1;
+ }
+ }
+ }
+ break;
+ }
+ }
+}
+
+/*
+ For Z80 Environment: read from a port.
+
+ Note: all ports in Pacman are memory mapped so they are read with readByte().
+*/
+unsigned char readPort( unsigned port )
+{
+ (void)port;
+ return 0;
+}
+
+/*
+ For Z80 Environment: write to a port.
+*/
+void writePort( unsigned addr, unsigned char b )
+{
+ if( addr == 0 ) {
+ // Sets the interrupt vector for the next CPU interrupt
+ interrupt_vector_ = b;
+ }
+}
+
+void setOutputFlipFlop( unsigned char bit, unsigned char value )
+{
+ if( value ) {
+ output_devices_ |= bit;
+ }
+ else {
+ output_devices_ &= ~bit;
+ }
+}