|
|
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). */
! 18:
! 19:
! 20:
! 21:
! 22: const char Cycles_rcsid[] = "Hatari $Id: cycles.c,v 1.5 2008/01/24 21:41:54 thothy Exp $";
1.1 root 23:
24: #include "main.h"
25: #include "cycles.h"
26:
27:
28: int nCyclesMainCounter; /* Main cycles counter */
29:
30: static int nCyclesCounter[CYCLES_COUNTER_MAX]; /* Array with all counters */
31:
1.1.1.2 ! root 32: int CurrentInstrCycles;
! 33:
1.1 root 34:
35: /*-----------------------------------------------------------------------*/
1.1.1.2 ! root 36: /**
! 37: * Update all cycles counters with the current value of nCyclesMainCounter.
! 38: */
1.1 root 39: static void Cycles_UpdateCounters(void)
40: {
41: int i;
42:
43: for (i = 0; i < CYCLES_COUNTER_MAX; i++)
44: {
45: nCyclesCounter[i] += nCyclesMainCounter;
46: }
47:
48: nCyclesMainCounter = 0;
49: }
50:
51:
52: /*-----------------------------------------------------------------------*/
1.1.1.2 ! root 53: /**
! 54: * Set a counter to a new value.
! 55: */
1.1 root 56: void Cycles_SetCounter(int nId, int nValue)
57: {
58: /* Update counters first (nCyclesMainCounter must be 0 afterwards) */
59: Cycles_UpdateCounters();
60:
61: /* Now set the new value: */
62: nCyclesCounter[nId] = nValue;
63: }
64:
65:
66: /*-----------------------------------------------------------------------*/
1.1.1.2 ! root 67: /**
! 68: * Read a counter.
! 69: */
1.1 root 70: int Cycles_GetCounter(int nId)
71: {
72: /* Update counters first so we read an up-to-date value */
73: Cycles_UpdateCounters();
74:
75: return nCyclesCounter[nId];
76: }
77:
78:
79: /*-----------------------------------------------------------------------*/
1.1.1.2 ! root 80: /**
! 81: * Read a counter on CPU memory read access by taking care of the instruction
! 82: * type (add the needed amount of additional cycles).
! 83: */
1.1 root 84: int Cycles_GetCounterOnReadAccess(int nId)
85: {
86: int nAddCycles;
87:
88: /* Update counters first so we read an up-to-date value */
89: Cycles_UpdateCounters();
90:
1.1.1.2 ! root 91: /* TODO: Find proper cycles count depending on the type of the current instruction */
! 92: /* (e.g. movem is not correctly handled) */
! 93: nAddCycles = CurrentInstrCycles; /* read is effective at the end of the instr */
1.1 root 94:
95: return nCyclesCounter[nId] + nAddCycles;
96: }
97:
98:
99: /*-----------------------------------------------------------------------*/
1.1.1.2 ! root 100: /**
! 101: * Read a counter on CPU memory write access by taking care of the instruction
! 102: * type (add the needed amount of additional cycles).
! 103: */
1.1 root 104: int Cycles_GetCounterOnWriteAccess(int nId)
105: {
106: int nAddCycles;
107:
108: /* Update counters first so we read an up-to-date value */
109: Cycles_UpdateCounters();
110:
1.1.1.2 ! root 111: /* TODO: Find proper cycles count depending on the type of the current instruction */
! 112: /* (e.g. movem is not correctly handled) */
! 113: nAddCycles = CurrentInstrCycles;
! 114:
! 115: /* assume the behaviour of a 'move' (since this is the most */
! 116: /* common instr used when requiring cycle precise writes) */
! 117: if ( nAddCycles >= 8 )
! 118: nAddCycles -= 4; /* last 4 cycles are for prefetch */
1.1 root 119:
120: return nCyclesCounter[nId] + nAddCycles;
121: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.