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