1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Pacbox - a Pacman Emulator for Rockbox
12 * Based on PIE - Pacman Instructional Emulator
14 * Copyright (c) 1997-2003,2004 Alessandro Scotti
15 * http://www.ascotti.org/
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
23 * KIND, either express or implied.
25 ****************************************************************************/
30 /* The main data for Pacman */
32 unsigned char ram_
[20*1024] IBSS_ATTR
; // ROM (16K) and RAM (4K)
33 unsigned char charset_rom_
[4*1024] IBSS_ATTR
; // Character set ROM (4K)
34 unsigned char spriteset_rom_
[4*1024] IBSS_ATTR
; // Sprite set ROM (4K)
35 unsigned char dirty_
[1024] IBSS_ATTR
;
36 unsigned char video_mem_
[1024] IBSS_ATTR
; // Video memory (1K)
37 unsigned char color_mem_
[1024] IBSS_ATTR
; // Color memory (1K)
38 unsigned char charmap_
[256*8*8] IBSS_ATTR
; /* Character data for 256 8x8 characters */
39 unsigned char spritemap_
[64*16*16]; /* Sprite data for 64 16x16 sprites */
40 unsigned char output_devices_ IBSS_ATTR
; /* Output flip-flops set by the game program */
41 unsigned char interrupt_vector_ IBSS_ATTR
;
42 unsigned coin_counter_ IBSS_ATTR
;
43 unsigned char port1_ IBSS_ATTR
;
44 unsigned char port2_ IBSS_ATTR
;
45 unsigned char dip_switches_ IBSS_ATTR
;
47 /* Internal tables and structures for faster access to data */
48 struct PacmanSprite sprites_
[8]; /* Sprites */
49 short vchar_to_i_
[1024];
53 For Z80 Environment: write a byte to memory.
55 void writeByte( unsigned addr
, unsigned char b
)
60 // This is a ROM address, do not write into it!
62 else if( addr
< 0x4400 ) {
64 if (ram_
[addr
] != b
) {
65 int x
= vchar_to_i_
[addr
-0x4000];
71 else if( addr
< 0x4800 ) {
73 if (ram_
[addr
] != b
) {
74 int x
= vchar_to_i_
[addr
-0x4400];
80 else if( addr
< 0x4FF0 ) {
84 else if( addr
< 0x5000 ) {
88 unsigned idx
= (addr
- 0x4FF0) / 2;
91 sprites_
[ idx
].color
= b
;
94 sprites_
[ idx
].n
= b
>> 2;
95 sprites_
[ idx
].mode
= b
& 0x03;
99 // Memory mapped ports
103 setOutputFlipFlop( InterruptEnabled
, b
& 0x01 );
107 setOutputFlipFlop( SoundEnabled
, b
& 0x01 );
114 setOutputFlipFlop( FlipScreen
, b
& 0x01 );
117 // Player 1 start light
118 setOutputFlipFlop( PlayerOneLight
, b
& 0x01 );
121 // Player 2 start light
122 setOutputFlipFlop( PlayerTwoLight
, b
& 0x01 );
125 // Coin lockout: bit 0 is used to enable/disable the coin insert slots
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 );
132 // Coin meter (coin counter incremented on 0/1 edge)
133 if( (output_devices_
& CoinMeter
) == 0 && (b
& 0x01) != 0 )
135 setOutputFlipFlop( CoinMeter
, b
& 0x01 );
141 if( addr
>= 0x5040 && addr
< 0x5060 ) {
143 //SOUND sound_chip_.setRegister( addr-0x5040, b );
145 else if( addr
>= 0x5060 && addr
< 0x5070 ) {
146 // Sprite coordinates, x/y pairs for 8 sprites
147 unsigned idx
= (addr
-0x5060) / 2;
150 sprites_
[ idx
].y
= 272 - b
+ 1;
153 sprites_
[ idx
].x
= 240 - b
- 1;
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;
168 For Z80 Environment: read from a port.
170 Note: all ports in Pacman are memory mapped so they are read with readByte().
172 unsigned char readPort( unsigned port
)
179 For Z80 Environment: write to a port.
181 void writePort( unsigned addr
, unsigned char b
)
184 // Sets the interrupt vector for the next CPU interrupt
185 interrupt_vector_
= b
;
189 void setOutputFlipFlop( unsigned char bit
, unsigned char value
)
192 output_devices_
|= bit
;
195 output_devices_
&= ~bit
;