summaryrefslogtreecommitdiff
path: root/apps/plugins/pacbox/hardware.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pacbox/hardware.h')
-rw-r--r--apps/plugins/pacbox/hardware.h141
1 files changed, 141 insertions, 0 deletions
diff --git a/apps/plugins/pacbox/hardware.h b/apps/plugins/pacbox/hardware.h
new file mode 100644
index 0000000000..9b225ad1a5
--- /dev/null
+++ b/apps/plugins/pacbox/hardware.h
@@ -0,0 +1,141 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Pacbox - a Pacman Emulator for Rockbox
11 *
12 * Based on PIE - Pacman Instructional Emulator
13 *
14 * Copyright (c) 1997-2003,2004 Alessandro Scotti
15 * http://www.ascotti.org/
16 *
17 * All files in this archive are subject to the GNU General Public License.
18 * See the file COPYING in the source tree root for full license agreement.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24
25#ifndef _HARDWARE_H
26#define _HARDWARE_H
27
28extern unsigned char ram_[20*1024]; // ROM (16K) and RAM (4K)
29extern unsigned char charset_rom_[4*1024]; // Character set ROM (4K)
30extern unsigned char spriteset_rom_[4*1024]; // Sprite set ROM (4K)
31extern unsigned char dirty_[1024];
32extern unsigned char video_mem_[1024]; // Video memory (1K)
33extern unsigned char color_mem_[1024]; // Color memory (1K)
34extern unsigned char charmap_[256*8*8]; /* Character data for 256 8x8 characters */
35extern unsigned char spritemap_[64*16*16]; /* Sprite data for 64 16x16 sprites */
36extern unsigned char output_devices_; /* Output flip-flops set by the game program */
37extern unsigned char interrupt_vector_;
38extern unsigned coin_counter_;
39extern unsigned char port1_;
40extern unsigned char port2_;
41extern unsigned char dip_switches_;
42
43/* Output flip-flops */
44enum {
45 FlipScreen = 0x01,
46 PlayerOneLight = 0x02,
47 PlayerTwoLight = 0x04,
48 InterruptEnabled = 0x08,
49 SoundEnabled = 0x10,
50 CoinLockout = 0x20,
51 CoinMeter = 0x40,
52 AuxBoardEnabled = 0x80
53};
54
55struct PacmanSprite
56{
57 int mode; /** Display mode (normal or flipped) */
58 int x; /** X coordinate */
59 int y; /** Y coordinate */
60 int n; /** Shape (from 0 to 63) */
61 int color; /** Base color (0=not visible) */
62};
63
64/* Internal tables and structures for faster access to data */
65extern struct PacmanSprite sprites_[8]; /* Sprites */
66extern short vchar_to_i_[1024];
67
68void writeByte(unsigned addr, unsigned char b);
69unsigned char readPort( unsigned port );
70void writePort( unsigned addr, unsigned char b );
71void setOutputFlipFlop( unsigned char bit, unsigned char value );
72
73/*
74 For Z80 Environment: read a byte from high memory addresses (i.e. the
75 memory-mapped registers)
76*/
77static inline unsigned char readByte( unsigned addr )
78{
79 addr &= 0xFFFF;
80
81 if (addr < sizeof(ram_))
82 return ram_[addr];
83
84 // Address is not in RAM, check to see if it's a memory mapped register
85 switch( addr & 0xFFC0 ) {
86 // IN0
87 case 0x5000:
88 // bit 0 : up
89 // bit 1 : left
90 // bit 2 : right
91 // bit 3 : down
92 // bit 4 : switch: advance to next level
93 // bit 5 : coin 1
94 // bit 6 : coin 2
95 // bit 7 : credit (same as coin but coin counter is not incremented)
96 return port1_;
97 // IN1
98 case 0x5040:
99 // bit 0 : up (2nd player)
100 // bit 1 : left (2nd player)
101 // bit 2 : right (2nd player)
102 // bit 3 : down (2nd player)
103 // bit 4 : switch: rack test -> 0x10=off, 0=on
104 // bit 5 : start 1
105 // bit 6 : start 2
106 // bit 7 : cabinet -> 0x80=upright, 0x00=table
107 return port2_;
108 // DSW1
109 case 0x5080:
110 // bits 0,1 : coinage -> 0=free play, 1=1 coin/play, 2=1 coin/2 play, 3=2 coin/1 play
111 // bits 2,3 : lives -> 0x0=1, 0x4=2, 0x8=3, 0xC=5
112 // bits 4,5 : bonus life -> 0=10000, 0x10=15000, 0x20=20000, 0x30=none
113 // bit 6 : jumper pad: difficulty -> 0x40=normal, 0=hard
114 // bit 7 : jumper pad: ghost name -> 0x80=normal, 0=alternate
115 return dip_switches_;
116 // Watchdog reset
117 case 0x50C0:
118 break;
119 }
120
121 return 0xFF;
122}
123
124/* Reads a 16 bit word from memory at the specified address. */
125static inline unsigned readWord( unsigned addr ) {
126 addr &= 0xFFFF;
127
128 if (addr < (sizeof(ram_)-1)) {
129 return ram_[addr] | ((ram_[addr+1]) << 8);
130 } else {
131 return readByte(addr) | (((unsigned)readByte(addr+1)) << 8);
132 }
133}
134
135/* Writes a 16 bit word to memory at the specified address. */
136static inline void writeWord( unsigned addr, unsigned value ) {
137 writeByte( addr, value & 0xFF );
138 writeByte( addr+1, (value >> 8) & 0xFF );
139}
140
141#endif