1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
/* spec_se.c: ZX Spectrum SE specific routines
Copyright (c) 1999-2011 Fredrick Meunier, Philip Kendall, Darren Salt
$Id: spec_se.c 4862 2013-01-27 11:00:36Z fredm $
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Author contact information:
E-mail: philip-fuse@shadowmagic.org.uk
*/
#include <config.h>
#include <stdio.h>
#include <string.h>
#include <libspectrum.h>
#include "fuse.h"
#include "keyboard.h"
#include "machine.h"
#include "machines.h"
#include "machines_periph.h"
#include "memory.h"
#include "peripherals/dck.h"
#include "peripherals/scld.h"
#include "snapshot.h"
#include "sound.h"
#include "spec128.h"
#include "settings.h"
#include "spectrum.h"
#include "tc2068.h"
#include "ui/ui.h"
static void dock_exrom_reset( void );
static int spec_se_reset( void );
static int spec_se_memory_map( void );
int
spec_se_init( fuse_machine_info *machine )
{
machine->machine = LIBSPECTRUM_MACHINE_SE;
machine->id = "se";
machine->reset = spec_se_reset;
machine->timex = 1;
machine->ram.port_from_ula = tc2048_port_from_ula;
machine->ram.contend_delay = spectrum_contend_delay_65432100;
machine->ram.contend_delay_no_mreq = spectrum_contend_delay_65432100;
machine->ram.valid_pages = 9;
machine->unattached_port = spectrum_unattached_port_none;
machine->shutdown = NULL;
machine->memory_map = spec_se_memory_map;
return 0;
}
static void
dock_exrom_reset( void )
{
/* The dock is always active on the SE */
dck_active = 1;
}
int
spec_se_reset( void )
{
int error;
size_t i, j;
dock_exrom_reset();
error = machine_load_rom( 0, settings_current.rom_spec_se_0,
settings_default.rom_spec_se_0, 0x4000 );
if( error ) return error;
error = machine_load_rom( 1, settings_current.rom_spec_se_1,
settings_default.rom_spec_se_1, 0x4000 );
if( error ) return error;
scld_home_map_16k( 0x0000, memory_map_rom, 0 );
scld_home_map_16k( 0x4000, memory_map_ram, 5 );
scld_home_map_16k( 0x8000, memory_map_ram, 8 );
scld_home_map_16k( 0xc000, memory_map_ram, 0 );
/* RAM pages 1, 3, 5 and 7 contended */
for( i = 0; i < 8; i++ )
memory_ram_set_16k_contention( i, i & 1 );
periph_clear();
machines_periph_128();
/* SE style memory paging present */
periph_set_present( PERIPH_TYPE_128_MEMORY, PERIPH_PRESENT_NEVER );
periph_set_present( PERIPH_TYPE_SE_MEMORY, PERIPH_PRESENT_ALWAYS );
/* ULA uses full decoding */
periph_set_present( PERIPH_TYPE_ULA, PERIPH_PRESENT_NEVER );
periph_set_present( PERIPH_TYPE_ULA_FULL_DECODE, PERIPH_PRESENT_ALWAYS );
/* As does the AY chip */
periph_set_present( PERIPH_TYPE_AY, PERIPH_PRESENT_NEVER );
periph_set_present( PERIPH_TYPE_AY_FULL_DECODE, PERIPH_PRESENT_ALWAYS );
/* Timex-style AY also present */
periph_set_present( PERIPH_TYPE_AY_TIMEX, PERIPH_PRESENT_ALWAYS );
/* SCLD always present */
periph_set_present( PERIPH_TYPE_SCLD, PERIPH_PRESENT_ALWAYS );
/* ZX Printer available */
periph_set_present( PERIPH_TYPE_ZXPRINTER_FULL_DECODE,
PERIPH_PRESENT_OPTIONAL );
for( i = 0; i < 8; i++ ) {
libspectrum_byte *dock_ram = memory_pool_allocate( 0x2000 );
libspectrum_byte *exrom_ram = memory_pool_allocate( 0x2000 );
for( j = 0; j < MEMORY_PAGES_IN_8K; j++ ) {
int page_num = i * MEMORY_PAGES_IN_8K + j;
timex_dock[page_num].page = dock_ram + j * MEMORY_PAGE_SIZE;
timex_dock[page_num].offset = j * MEMORY_PAGE_SIZE;
timex_dock[page_num].page_num = i;
timex_dock[page_num].contended = 0;
timex_dock[page_num].writable = 1;
timex_dock[page_num].save_to_snapshot = 1;
timex_dock[page_num].source = memory_source_dock;
timex_exrom[page_num].page = exrom_ram + j * MEMORY_PAGE_SIZE;
timex_exrom[page_num].offset = j * MEMORY_PAGE_SIZE;
timex_exrom[page_num].page_num = i;
timex_exrom[page_num].contended = 0;
timex_exrom[page_num].writable = 1;
timex_exrom[page_num].save_to_snapshot = 1;
timex_exrom[page_num].source = memory_source_exrom;
}
}
/* The dock and exrom aren't cleared by the reset routine, so do
so manually (only really necessary to keep snapshot sizes down) */
for( i = 0; i < MEMORY_PAGES_IN_64K; i++ ) {
memset( timex_dock[i].page, 0, MEMORY_PAGE_SIZE );
memset( timex_exrom[i].page, 0, MEMORY_PAGE_SIZE );
}
machine_current->ram.locked = 0;
machine_current->ram.last_byte = 0;
machine_current->ram.current_page=0;
machine_current->ram.current_rom=0;
memory_current_screen = 5;
memory_screen_mask = 0xdfff;
/* Make sure SCLD and friends are enabled, calls memory_map() as a side
effect so we need memory related variables etc. to be initialised */
periph_update();
scld_dec_write( 0x00ff, 0x80 );
scld_dec_write( 0x00ff, 0x00 );
scld_hsr_write( 0x00f4, 0x00 );
tc2068_tc2048_common_display_setup();
return 0;
}
static int
spec_se_memory_map( void )
{
memory_page *exrom_dock;
scld_memory_map_home();
/* Spectrum SE memory paging is just a combination of the 128K
0x7ffd and Timex DOCK/EXROM paging schemes with one exception */
spec128_memory_map();
scld_memory_map();
/* Exceptions apply if an odd bank is paged in via 0x7ffd */
if( machine_current->ram.current_page & 0x01 ) {
/* If so, bits 2 and 3 of 0xf4 also control whether the DOCK/EXROM
is paged in at 0xc000 and 0xe000 respectively */
exrom_dock =
scld_last_dec.name.altmembank ? timex_exrom : timex_dock;
if( scld_last_hsr & ( 1 << 2 ) )
memory_map_8k( 0xc000, exrom_dock, 6 );
if( scld_last_hsr & ( 1 << 3 ) )
memory_map_8k( 0xe000, exrom_dock, 7 );
}
memory_romcs_map();
return 0;
}
|