Search
lxdream.org :: lxdream/src/sh4/sh4core.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/sh4/sh4core.c
changeset 23:1ec3acd0594d
prev19:9da7a8e38f9d
next27:1ef09a52cd1e
author nkeynes
date Fri Dec 23 11:44:55 2005 +0000 (14 years ago)
permissions -rw-r--r--
last change Start of "real" time slices, general structure in place now
file annotate diff log raw
1.1 --- a/src/sh4/sh4core.c Thu Dec 22 07:38:12 2005 +0000
1.2 +++ b/src/sh4/sh4core.c Fri Dec 23 11:44:55 2005 +0000
1.3 @@ -1,17 +1,48 @@
1.4 +/**
1.5 + * $Id: sh4core.c,v 1.9 2005-12-23 11:44:55 nkeynes Exp $
1.6 + *
1.7 + * SH4 emulation core, and parent module for all the SH4 peripheral
1.8 + * modules.
1.9 + *
1.10 + * Copyright (c) 2005 Nathan Keynes.
1.11 + *
1.12 + * This program is free software; you can redistribute it and/or modify
1.13 + * it under the terms of the GNU General Public License as published by
1.14 + * the Free Software Foundation; either version 2 of the License, or
1.15 + * (at your option) any later version.
1.16 + *
1.17 + * This program is distributed in the hope that it will be useful,
1.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.20 + * GNU General Public License for more details.
1.21 + */
1.22 +
1.23 #include <math.h>
1.24 #include "dream.h"
1.25 #include "modules.h"
1.26 #include "sh4core.h"
1.27 #include "sh4mmio.h"
1.28 #include "mem.h"
1.29 +#include "clock.h"
1.30 #include "intc.h"
1.31
1.32 -void sh4_save( FILE *f );
1.33 -int sh4_load( FILE *f );
1.34 +uint32_t sh4_freq = SH4_BASE_RATE;
1.35 +uint32_t sh4_bus_freq = SH4_BASE_RATE;
1.36 +uint32_t sh4_peripheral_freq = SH4_BASE_RATE / 2;
1.37 +
1.38 +/********************** SH4 Module Definition ****************************/
1.39 +
1.40 +void sh4_init( void );
1.41 +void sh4_reset( void );
1.42 +void sh4_run_slice( int );
1.43 +void sh4_start( void );
1.44 +void sh4_stop( void );
1.45 +void sh4_save_state( FILE *f );
1.46 +int sh4_load_state( FILE *f );
1.47
1.48 struct dreamcast_module sh4_module = { "SH4", sh4_init, sh4_reset,
1.49 - NULL, sh4_stop,
1.50 - sh4_save, sh4_load };
1.51 + NULL, sh4_run_slice, sh4_stop,
1.52 + sh4_save_state, sh4_load_state };
1.53
1.54 struct sh4_registers sh4r;
1.55 static int running = 0;
1.56 @@ -34,10 +65,16 @@
1.57 intc_reset();
1.58 }
1.59
1.60 -void sh4_set_pc( int pc )
1.61 +void sh4_run_slice( int microsecs )
1.62 {
1.63 - sh4r.pc = pc;
1.64 - sh4r.new_pc = pc+2;
1.65 + int count = sh4_freq * microsecs;
1.66 + int i;
1.67 +
1.68 + for( i=0; i<count; i++ ) {
1.69 + sh4_execute_instruction();
1.70 + }
1.71 + TMU_run_slice( microsecs );
1.72 + SCIF_run_slice( microsecs );
1.73 }
1.74
1.75 void sh4_stop(void)
1.76 @@ -45,16 +82,16 @@
1.77 running = 0;
1.78 }
1.79
1.80 -void sh4_save( FILE *f )
1.81 +void sh4_save_state( FILE *f )
1.82 {
1.83 fwrite( &sh4r, sizeof(sh4r), 1, f );
1.84 - /* Save all additional on-board MMIO state */
1.85 + SCIF_save_state( f );
1.86 }
1.87
1.88 -int sh4_load( FILE * f )
1.89 +int sh4_load_state( FILE * f )
1.90 {
1.91 fread( &sh4r, sizeof(sh4r), 1, f );
1.92 - return 0;
1.93 + return SCIF_load_state( f );
1.94 }
1.95
1.96 void sh4_run(void)
1.97 @@ -65,6 +102,19 @@
1.98 }
1.99 }
1.100
1.101 +/********************** SH4 emulation core ****************************/
1.102 +
1.103 +void sh4_set_pc( int pc )
1.104 +{
1.105 + sh4r.pc = pc;
1.106 + sh4r.new_pc = pc+2;
1.107 +}
1.108 +
1.109 +void sh4_set_breakpoint( uint32_t pc, int type )
1.110 +{
1.111 +
1.112 +}
1.113 +
1.114 void sh4_runfor(uint32_t count)
1.115 {
1.116 running = 1;
.