merge heads (properly this time)

Wed, 29 Dec 2010 09:04:43 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Wed, 29 Dec 2010 09:04:43 +0000
changeset 78
c149c13aff1c
parent 74
51cbc7a44cd9
parent 76
2ef98ea1e944
child 79
674226015c8a

merge heads (properly this time)

src/main.c file | annotate | diff | revisions
src/memory.c file | annotate | diff | revisions
src/state.c file | annotate | diff | revisions
src/wd279x.c file | annotate | diff | revisions
     1.1 diff -r 51cbc7a44cd9 -r c149c13aff1c src/main.c
     1.2 --- a/src/main.c	Wed Dec 29 01:38:54 2010 +0000
     1.3 +++ b/src/main.c	Wed Dec 29 09:04:43 2010 +0000
     1.4 @@ -204,12 +204,13 @@
     1.5  	 * The 3B1 CPU runs at 10MHz, with DMA running at 1MHz and video refreshing at
     1.6  	 * around 60Hz (???), with a 60Hz periodic interrupt.
     1.7  	 */
     1.8 -	const uint32_t TIMESLOT_FREQUENCY = 240;	// Hz
     1.9 +	const uint32_t TIMESLOT_FREQUENCY = 1000;//240;	// Hz
    1.10  	const uint32_t MILLISECS_PER_TIMESLOT = 1e3 / TIMESLOT_FREQUENCY;
    1.11  	const uint32_t CLOCKS_PER_60HZ = (10e6 / 60);
    1.12  	uint32_t next_timeslot = SDL_GetTicks() + MILLISECS_PER_TIMESLOT;
    1.13  	uint32_t clock_cycles = 0;
    1.14  	bool exitEmu = false;
    1.15 +	bool lastirq_fdc = false;
    1.16  	for (;;) {
    1.17  		// Run the CPU for however many cycles we need to. CPU core clock is
    1.18  		// 10MHz, and we're running at 240Hz/timeslot. Thus: 10e6/240 or
    1.19 @@ -217,8 +218,7 @@
    1.20  		clock_cycles += m68k_execute(10e6/TIMESLOT_FREQUENCY);
    1.21  
    1.22  		// Run the DMA engine
    1.23 -		//
    1.24 -		if (state.dmaen) { //((state.dma_count < 0x3fff) && state.dmaen) {
    1.25 +		if (state.dmaen) {
    1.26  			// DMA ready to go -- so do it.
    1.27  			size_t num = 0;
    1.28  			while (state.dma_count < 0x4000) {
    1.29 @@ -325,8 +325,13 @@
    1.30  		}
    1.31  
    1.32  		// Any interrupts? --> TODO: masking
    1.33 -/*		if (wd2797_get_irq(&state.fdc_ctx)) {
    1.34 -			m68k_set_irq(2);
    1.35 +/*		if (!lastirq_fdc) {
    1.36 +			if (wd2797_get_irq(&state.fdc_ctx)) {
    1.37 +				lastirq_fdc = true;
    1.38 +				m68k_set_irq(2);
    1.39 +			} else {
    1.40 +				lastirq_fdc = false;
    1.41 +			}
    1.42  		} else {
    1.43  			m68k_set_irq(0);
    1.44  		}
     2.1 diff -r 51cbc7a44cd9 -r c149c13aff1c src/memory.c
     2.2 --- a/src/memory.c	Wed Dec 29 01:38:54 2010 +0000
     2.3 +++ b/src/memory.c	Wed Dec 29 09:04:43 2010 +0000
     2.4 @@ -438,7 +438,7 @@
     2.5  				break;
     2.6  			case 0x070000:				// Line Printer Status Register
     2.7  				data = 0x00120012;	// no parity error, no line printer error, no irqs from FDD or HDD
     2.8 -				data |= (state.fdc_ctx.irql) ? 0x00080008 : 0;	// FIXME! HACKHACKHACK! shouldn't peek inside FDC structs like this
     2.9 +				data |= wd2797_get_irq(&state.fdc_ctx) ? 0x00080008 : 0;
    2.10  				return data;
    2.11  				break;
    2.12  			case 0x080000:				// Real Time Clock
     3.1 diff -r 51cbc7a44cd9 -r c149c13aff1c src/state.c
     3.2 --- a/src/state.c	Wed Dec 29 01:38:54 2010 +0000
     3.3 +++ b/src/state.c	Wed Dec 29 09:04:43 2010 +0000
     3.4 @@ -15,6 +15,12 @@
     3.5  
     3.6  	// Initialise hardware registers
     3.7  	state.romlmap = false;
     3.8 +	state.idmarw = state.dmaen = state.dmaenb = false;
     3.9 +	state.dma_count = state.dma_address = 0;
    3.10 +	state.pie = 0;
    3.11 +	state.leds = 0;
    3.12 +	state.genstat = 0;				// FIXME: check this
    3.13 +	state.bsr0 = state.bsr1 = 0;	// FIXME: check this
    3.14  
    3.15  	// Allocate Base RAM, making sure the user has specified a valid RAM amount first
    3.16  	// Basically: 512KiB minimum, 2MiB maximum, in increments of 512KiB.
     4.1 diff -r 51cbc7a44cd9 -r c149c13aff1c src/wd279x.c
     4.2 --- a/src/wd279x.c	Wed Dec 29 01:38:54 2010 +0000
     4.3 +++ b/src/wd279x.c	Wed Dec 29 09:04:43 2010 +0000
     4.4 @@ -37,19 +37,20 @@
     4.5  	ctx->track = ctx->head = ctx->sector = 0;
     4.6  
     4.7  	// no IRQ pending
     4.8 -	ctx->irql = ctx->irqe = false;
     4.9 +	ctx->irq = false;
    4.10  
    4.11  	// no data available
    4.12  	ctx->data_pos = ctx->data_len = 0;
    4.13  	ctx->data = NULL;
    4.14  
    4.15 -	// Status register clear, not busy
    4.16 +	// Status register clear, not busy; type1 command
    4.17  	ctx->status = 0;
    4.18 +	ctx->cmd_has_drq = false;
    4.19  
    4.20  	// Clear data register
    4.21  	ctx->data_reg = 0;
    4.22  
    4.23 -	// Last step direction
    4.24 +	// Last step direction = "towards zero"
    4.25  	ctx->last_step_dir = -1;
    4.26  
    4.27  	// No disc image loaded
    4.28 @@ -64,7 +65,7 @@
    4.29  	ctx->track = ctx->head = ctx->sector = 0;
    4.30  
    4.31  	// no IRQ pending
    4.32 -	ctx->irql = ctx->irqe = false;
    4.33 +	ctx->irq = false;
    4.34  
    4.35  	// no data available
    4.36  	ctx->data_pos = ctx->data_len = 0;
    4.37 @@ -95,13 +96,7 @@
    4.38  
    4.39  bool wd2797_get_irq(WD2797_CTX *ctx)
    4.40  {
    4.41 -	// If an IRQ is pending, clear it and return true, otherwise return false
    4.42 -	if (ctx->irqe) {
    4.43 -		ctx->irqe = false;
    4.44 -		return true;
    4.45 -	} else {
    4.46 -		return false;
    4.47 -	}
    4.48 +	return ctx->irq;
    4.49  }
    4.50  
    4.51  
    4.52 @@ -169,8 +164,7 @@
    4.53  	switch (addr & 0x03) {
    4.54  		case WD2797_REG_STATUS:		// Status register
    4.55  			// Read from status register clears IRQ
    4.56 -			ctx->irql = false;
    4.57 -			ctx->irqe = false;
    4.58 +			ctx->irq = false;
    4.59  
    4.60  			// Get current status flags (set by last command)
    4.61  			// DRQ bit
    4.62 @@ -197,9 +191,8 @@
    4.63  			if (ctx->data_pos < ctx->data_len) {
    4.64  				// set IRQ if this is the last data byte
    4.65  				if (ctx->data_pos == (ctx->data_len-1)) {
    4.66 -					// Set IRQ only if IRQL has been cleared (no pending IRQs)
    4.67 -					ctx->irqe = ctx->irql ? ctx->irqe : true;
    4.68 -					ctx->irql = true;
    4.69 +					// Set IRQ
    4.70 +					ctx->irq = true;
    4.71  				}
    4.72  				// return data byte and increment pointer
    4.73  				return ctx->data[ctx->data_pos++];
    4.74 @@ -228,7 +221,7 @@
    4.75  	switch (addr) {
    4.76  		case WD2797_REG_COMMAND:	// Command register
    4.77  			// write to command register clears interrupt request
    4.78 -			ctx->irql = false;
    4.79 +			ctx->irq = false;
    4.80  
    4.81  			// Is the drive ready?
    4.82  			if (ctx->disc_image == NULL) {
    4.83 @@ -319,9 +312,8 @@
    4.84  				// S0 = Busy. We just exec'd the command, thus we're not busy.
    4.85  				// 		TODO: Set a timer for seeks, and ONLY clear BUSY when that timer expires. Need periodics for that.
    4.86  				
    4.87 -				// Set IRQ only if IRQL has been cleared (no pending IRQs)
    4.88 -				ctx->irqe = ctx->irql ? ctx->irqe : true;
    4.89 -				ctx->irql = true;
    4.90 +				// Set IRQ
    4.91 +				ctx->irq = true;
    4.92  				return;
    4.93  			}
    4.94  
    4.95 @@ -344,9 +336,8 @@
    4.96  					// Set Write Protect bit and bail.
    4.97  					ctx->status = 0x40;
    4.98  
    4.99 -					// Set IRQ only if IRQL has been cleared (no pending IRQs)
   4.100 -					ctx->irqe = ctx->irql ? ctx->irqe : true;
   4.101 -					ctx->irql = true;
   4.102 +					// Set IRQ
   4.103 +					ctx->irq = true;
   4.104  
   4.105  					return;
   4.106  				}
   4.107 @@ -398,9 +389,8 @@
   4.108  						// CHS parameters exceed limits
   4.109  						ctx->status = 0x10;		// Record Not Found
   4.110  						break;
   4.111 -						// Set IRQ only if IRQL has been cleared (no pending IRQs)
   4.112 -						ctx->irqe = ctx->irql ? ctx->irqe : true;
   4.113 -						ctx->irql = true;
   4.114 +						// Set IRQ
   4.115 +						ctx->irq = true;
   4.116  					}
   4.117  
   4.118  					// reset data pointers
   4.119 @@ -485,9 +475,8 @@
   4.120  					// TODO!
   4.121  					ctx->status = 0;
   4.122  					ctx->data_pos = ctx->data_len = 0;
   4.123 -					// Set IRQ only if IRQL has been cleared (no pending IRQs)
   4.124 -					ctx->irqe = ctx->irql ? ctx->irqe : true;
   4.125 -					ctx->irql = true;
   4.126 +					// Set IRQ
   4.127 +					ctx->irq = true;
   4.128  					break;
   4.129  			}
   4.130  			break;
   4.131 @@ -509,9 +498,8 @@
   4.132  			if (ctx->data_pos < ctx->data_len) {
   4.133  				// set IRQ if this is the last data byte
   4.134  				if (ctx->data_pos == (ctx->data_len-1)) {
   4.135 -					// Set IRQ only if IRQL has been cleared (no pending IRQs)
   4.136 -					ctx->irqe = ctx->irql ? ctx->irqe : true;
   4.137 -					ctx->irql = true;
   4.138 +					// Set IRQ
   4.139 +					ctx->irq = true;
   4.140  				}
   4.141  
   4.142  				// store data byte and increment pointer
     5.1 diff -r 51cbc7a44cd9 -r c149c13aff1c src/wd279x.h
     5.2 --- a/src/wd279x.h	Wed Dec 29 01:38:54 2010 +0000
     5.3 +++ b/src/wd279x.h	Wed Dec 29 09:04:43 2010 +0000
     5.4 @@ -27,11 +27,8 @@
     5.5  	int						track, head, sector;
     5.6  	// Geometry of current disc
     5.7  	int						geom_secsz, geom_spt, geom_heads, geom_tracks;
     5.8 -	// IRQ status, level and edge sensitive.
     5.9 -	// Edge sensitive is cleared when host polls the IRQ status.
    5.10 -	// Level sensitive is cleared when emulated CPU polls the status reg or writes a new cmnd.
    5.11 -	// No EDGE sensitive interrupts will be issued unless the LEVEL SENSITIVE IRQ is clear.
    5.12 -	bool					irql, irqe;
    5.13 +	// IRQ status
    5.14 +	bool					irq;
    5.15  	// Status of last command
    5.16  	uint8_t					status;
    5.17  	// Last command uses DRQ bit?