|
|
1.1 root 1: /*
2: Hatari - cycles.c
3:
4: This file is distributed under the GNU Public License, version 2 or at
5: your option any later version. Read the file gpl.txt for details.
6:
7: Here we take care of cycle counters. For performance reasons we don't increase
8: all counters after each 68k instruction, but only one main counter.
9: When we need to read one of the normal counters (currently only for video
10: and sound cycles), we simply update these counters with the main counter
11: before returning the current counter value.
12: */
1.1.1.2 root 13:
14:
15: /* 2007/03/xx [NP] Use 'CurrentInstrCycles' to get a good approximation for */
16: /* Cycles_GetCounterOnReadAccess and Cycles_GetCounterOnWriteAccess*/
17: /* (this should work correctly with 'move' instruction). */
1.1.1.3 ! root 18: /* 2008/04/14 [NP] Take nWaitStateCycles into account when computing the value of */
! 19: /* Cycles_GetCounterOnReadAccess and Cycles_GetCounterOnWriteAccess*/
1.1.1.2 root 20:
21:
22:
23:
1.1.1.3 ! root 24: const char Cycles_rcsid[] = "Hatari $Id: cycles.c,v 1.6 2008/04/18 20:31:59 npomarede Exp $";
1.1 root 25:
26: #include "main.h"
1.1.1.3 ! root 27: #include "m68000.h"
1.1 root 28: #include "cycles.h"
29:
30:
31: int nCyclesMainCounter; /* Main cycles counter */
32:
33: static int nCyclesCounter[CYCLES_COUNTER_MAX]; /* Array with all counters */
34:
1.1.1.2 root 35: int CurrentInstrCycles;
36:
1.1 root 37:
38: /*-----------------------------------------------------------------------*/
1.1.1.2 root 39: /**
40: * Update all cycles counters with the current value of nCyclesMainCounter.
41: */
1.1 root 42: static void Cycles_UpdateCounters(void)
43: {
44: int i;
45:
46: for (i = 0; i < CYCLES_COUNTER_MAX; i++)
47: {
48: nCyclesCounter[i] += nCyclesMainCounter;
49: }
50:
51: nCyclesMainCounter = 0;
52: }
53:
54:
55: /*-----------------------------------------------------------------------*/
1.1.1.2 root 56: /**
57: * Set a counter to a new value.
58: */
1.1 root 59: void Cycles_SetCounter(int nId, int nValue)
60: {
61: /* Update counters first (nCyclesMainCounter must be 0 afterwards) */
62: Cycles_UpdateCounters();
63:
64: /* Now set the new value: */
65: nCyclesCounter[nId] = nValue;
66: }
67:
68:
69: /*-----------------------------------------------------------------------*/
1.1.1.2 root 70: /**
71: * Read a counter.
72: */
1.1 root 73: int Cycles_GetCounter(int nId)
74: {
75: /* Update counters first so we read an up-to-date value */
76: Cycles_UpdateCounters();
77:
78: return nCyclesCounter[nId];
79: }
80:
81:
82: /*-----------------------------------------------------------------------*/
1.1.1.2 root 83: /**
84: * Read a counter on CPU memory read access by taking care of the instruction
85: * type (add the needed amount of additional cycles).
86: */
1.1 root 87: int Cycles_GetCounterOnReadAccess(int nId)
88: {
89: int nAddCycles;
90:
91: /* Update counters first so we read an up-to-date value */
92: Cycles_UpdateCounters();
93:
1.1.1.2 root 94: /* TODO: Find proper cycles count depending on the type of the current instruction */
95: /* (e.g. movem is not correctly handled) */
1.1.1.3 ! root 96: nAddCycles = CurrentInstrCycles + nWaitStateCycles; /* read is effective at the end of the instr ? */
1.1 root 97:
98: return nCyclesCounter[nId] + nAddCycles;
99: }
100:
101:
102: /*-----------------------------------------------------------------------*/
1.1.1.2 root 103: /**
104: * Read a counter on CPU memory write access by taking care of the instruction
105: * type (add the needed amount of additional cycles).
106: */
1.1 root 107: int Cycles_GetCounterOnWriteAccess(int nId)
108: {
109: int nAddCycles;
110:
111: /* Update counters first so we read an up-to-date value */
112: Cycles_UpdateCounters();
113:
1.1.1.2 root 114: /* TODO: Find proper cycles count depending on the type of the current instruction */
115: /* (e.g. movem is not correctly handled) */
1.1.1.3 ! root 116: nAddCycles = CurrentInstrCycles + nWaitStateCycles;
1.1.1.2 root 117:
118: /* assume the behaviour of a 'move' (since this is the most */
119: /* common instr used when requiring cycle precise writes) */
120: if ( nAddCycles >= 8 )
121: nAddCycles -= 4; /* last 4 cycles are for prefetch */
1.1 root 122:
123: return nCyclesCounter[nId] + nAddCycles;
124: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.