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 extern unsigned char ram_
[20*1024]; // ROM (16K) and RAM (4K)
31 extern unsigned char charset_rom_
[4*1024]; // Character set ROM (4K)
32 extern unsigned char spriteset_rom_
[4*1024]; // Sprite set ROM (4K)
33 extern unsigned char dirty_
[1024];
34 extern unsigned char video_mem_
[1024]; // Video memory (1K)
35 extern unsigned char color_mem_
[1024]; // Color memory (1K)
36 extern unsigned char charmap_
[256*8*8]; /* Character data for 256 8x8 characters */
37 extern unsigned char spritemap_
[64*16*16]; /* Sprite data for 64 16x16 sprites */
38 extern unsigned char output_devices_
; /* Output flip-flops set by the game program */
39 extern unsigned char interrupt_vector_
;
40 extern unsigned coin_counter_
;
41 extern unsigned char port1_
;
42 extern unsigned char port2_
;
43 extern unsigned char dip_switches_
;
45 /* Output flip-flops */
48 PlayerOneLight
= 0x02,
49 PlayerTwoLight
= 0x04,
50 InterruptEnabled
= 0x08,
54 AuxBoardEnabled
= 0x80
59 int mode
; /** Display mode (normal or flipped) */
60 int x
; /** X coordinate */
61 int y
; /** Y coordinate */
62 int n
; /** Shape (from 0 to 63) */
63 int color
; /** Base color (0=not visible) */
66 /* Internal tables and structures for faster access to data */
67 extern struct PacmanSprite sprites_
[8]; /* Sprites */
68 extern short vchar_to_i_
[1024];
70 void writeByte(unsigned addr
, unsigned char b
);
71 unsigned char readPort( unsigned port
);
72 void writePort( unsigned addr
, unsigned char b
);
73 void setOutputFlipFlop( unsigned char bit
, unsigned char value
);
76 For Z80 Environment: read a byte from high memory addresses (i.e. the
77 memory-mapped registers)
79 static inline unsigned char readByte( unsigned addr
)
83 if (addr
< sizeof(ram_
))
86 // Address is not in RAM, check to see if it's a memory mapped register
87 switch( addr
& 0xFFC0 ) {
94 // bit 4 : switch: advance to next level
97 // bit 7 : credit (same as coin but coin counter is not incremented)
101 // bit 0 : up (2nd player)
102 // bit 1 : left (2nd player)
103 // bit 2 : right (2nd player)
104 // bit 3 : down (2nd player)
105 // bit 4 : switch: rack test -> 0x10=off, 0=on
108 // bit 7 : cabinet -> 0x80=upright, 0x00=table
112 // bits 0,1 : coinage -> 0=free play, 1=1 coin/play, 2=1 coin/2 play, 3=2 coin/1 play
113 // bits 2,3 : lives -> 0x0=1, 0x4=2, 0x8=3, 0xC=5
114 // bits 4,5 : bonus life -> 0=10000, 0x10=15000, 0x20=20000, 0x30=none
115 // bit 6 : jumper pad: difficulty -> 0x40=normal, 0=hard
116 // bit 7 : jumper pad: ghost name -> 0x80=normal, 0=alternate
117 return dip_switches_
;
126 /* Reads a 16 bit word from memory at the specified address. */
127 static inline unsigned readWord( unsigned addr
) {
130 if (addr
< (sizeof(ram_
)-1)) {
131 return ram_
[addr
] | ((ram_
[addr
+1]) << 8);
133 return readByte(addr
) | (((unsigned)readByte(addr
+1)) << 8);
137 /* Writes a 16 bit word to memory at the specified address. */
138 static inline void writeWord( unsigned addr
, unsigned value
) {
139 writeByte( addr
, value
& 0xFF );
140 writeByte( addr
+1, (value
>> 8) & 0xFF );