summaryrefslogtreecommitdiff
path: root/apps/plugins/pacbox/hardware.c
diff options
context:
space:
mode:
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 @@
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#include "plugin.h"
26#include "hardware.h"
27
28extern struct plugin_api* rb;
29
30/* The main data for Pacman */
31
32unsigned char ram_[20*1024] IBSS_ATTR; // ROM (16K) and RAM (4K)
33unsigned char charset_rom_[4*1024] IBSS_ATTR; // Character set ROM (4K)
34unsigned char spriteset_rom_[4*1024] IBSS_ATTR; // Sprite set ROM (4K)
35unsigned char dirty_[1024] IBSS_ATTR;
36unsigned char video_mem_[1024] IBSS_ATTR; // Video memory (1K)
37unsigned char color_mem_[1024] IBSS_ATTR; // Color memory (1K)
38unsigned char charmap_[256*8*8]; /* Character data for 256 8x8 characters */
39unsigned char spritemap_[64*16*16]; /* Sprite data for 64 16x16 sprites */
40unsigned char output_devices_ IBSS_ATTR; /* Output flip-flops set by the game program */
41unsigned char interrupt_vector_ IBSS_ATTR;
42unsigned coin_counter_ IBSS_ATTR;
43unsigned char port1_ IBSS_ATTR;
44unsigned char port2_ IBSS_ATTR;
45unsigned char dip_switches_ IBSS_ATTR;
46
47/* Internal tables and structures for faster access to data */
48struct PacmanSprite sprites_[8]; /* Sprites */
49short vchar_to_i_[1024];
50
51
52/*
53 For Z80 Environment: write a byte to memory.
54*/
55void writeByte( unsigned addr, unsigned char b )
56{
57 addr &= 0x7FFF;
58
59 if( addr < 0x4000 ) {
60 // This is a ROM address, do not write into it!
61 }
62 else if( addr < 0x4400 ) {
63 // Video memory
64 if (ram_[addr] != b) {
65 int x = vchar_to_i_[addr-0x4000];
66 ram_[addr] = b;
67 dirty_[x] = 1;
68 video_mem_[x] = b;
69 }
70 }
71 else if( addr < 0x4800 ) {
72 // Color memory
73 if (ram_[addr] != b) {
74 int x = vchar_to_i_[addr-0x4400];
75 ram_[addr] = b;
76 dirty_[x] = 1;
77 color_mem_[x] = b;
78 }
79 }
80 else if( addr < 0x4FF0 ) {
81 // Standard memory
82 ram_[addr] = b;
83 }
84 else if( addr < 0x5000 ) {
85 // Sprites
86 ram_[addr] = b;
87
88 unsigned idx = (addr - 0x4FF0) / 2;
89
90 if( addr & 1 ) {
91 sprites_[ idx ].color = b;
92 }
93 else {
94 sprites_[ idx ].n = b >> 2;
95 sprites_[ idx ].mode = b & 0x03;
96 }
97 }
98 else {
99 // Memory mapped ports
100 switch( addr ) {
101 case 0x5000:
102 // Interrupt enable
103 setOutputFlipFlop( InterruptEnabled, b & 0x01 );
104 break;
105 case 0x5001:
106 // Sound enable
107 setOutputFlipFlop( SoundEnabled, b & 0x01 );
108 break;
109 case 0x5002:
110 // Aux board enable?
111 break;
112 case 0x5003:
113 // Flip screen
114 setOutputFlipFlop( FlipScreen, b & 0x01 );
115 break;
116 case 0x5004:
117 // Player 1 start light
118 setOutputFlipFlop( PlayerOneLight, b & 0x01 );
119 break;
120 case 0x5005:
121 // Player 2 start light
122 setOutputFlipFlop( PlayerTwoLight, b & 0x01 );
123 break;
124 case 0x5006:
125 // Coin lockout: bit 0 is used to enable/disable the coin insert slots
126 // (0=disable).
127 // The coin slot is enabled at startup and (temporarily) disabled when
128 // the maximum number of credits (99) is inserted.
129 setOutputFlipFlop( CoinLockout, b & 0x01 );
130 break;
131 case 0x5007:
132 // Coin meter (coin counter incremented on 0/1 edge)
133 if( (output_devices_ & CoinMeter) == 0 && (b & 0x01) != 0 )
134 coin_counter_++;
135 setOutputFlipFlop( CoinMeter, b & 0x01 );
136 break;
137 case 0x50c0:
138 // Watchdog reset
139 break;
140 default:
141 if( addr >= 0x5040 && addr < 0x5060 ) {
142 // Sound registers
143 //SOUND sound_chip_.setRegister( addr-0x5040, b );
144 }
145 else if( addr >= 0x5060 && addr < 0x5070 ) {
146 // Sprite coordinates, x/y pairs for 8 sprites
147 unsigned idx = (addr-0x5060) / 2;
148
149 if( addr & 1 ) {
150 sprites_[ idx ].y = 272 - b + 1;
151 }
152 else {
153 sprites_[ idx ].x = 240 - b - 1;
154
155 if( idx <= 2 ) {
156 // In Pacman the first few sprites must be further offset
157 // to the left to get a correct display (is this a hack?)
158 sprites_[ idx ].x -= 1;
159 }
160 }
161 }
162 break;
163 }
164 }
165}
166
167/*
168 For Z80 Environment: read from a port.
169
170 Note: all ports in Pacman are memory mapped so they are read with readByte().
171*/
172unsigned char readPort( unsigned port )
173{
174 (void)port;
175 return 0;
176}
177
178/*
179 For Z80 Environment: write to a port.
180*/
181void writePort( unsigned addr, unsigned char b )
182{
183 if( addr == 0 ) {
184 // Sets the interrupt vector for the next CPU interrupt
185 interrupt_vector_ = b;
186 }
187}
188
189void setOutputFlipFlop( unsigned char bit, unsigned char value )
190{
191 if( value ) {
192 output_devices_ |= bit;
193 }
194 else {
195 output_devices_ &= ~bit;
196 }
197}