|
|
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: */ ! 13: const char Cycles_rcsid[] = "Hatari $Id: cycles.c,v 1.3 2006/02/08 22:49:27 eerot Exp $"; ! 14: ! 15: #include "main.h" ! 16: #include "cycles.h" ! 17: ! 18: ! 19: int nCyclesMainCounter; /* Main cycles counter */ ! 20: ! 21: static int nCyclesCounter[CYCLES_COUNTER_MAX]; /* Array with all counters */ ! 22: ! 23: ! 24: /*-----------------------------------------------------------------------*/ ! 25: /* ! 26: Update all cycles counters with the current value of nCyclesMainCounter. ! 27: */ ! 28: static void Cycles_UpdateCounters(void) ! 29: { ! 30: int i; ! 31: ! 32: for (i = 0; i < CYCLES_COUNTER_MAX; i++) ! 33: { ! 34: nCyclesCounter[i] += nCyclesMainCounter; ! 35: } ! 36: ! 37: nCyclesMainCounter = 0; ! 38: } ! 39: ! 40: ! 41: /*-----------------------------------------------------------------------*/ ! 42: /* ! 43: Set a counter to a new value. ! 44: */ ! 45: void Cycles_SetCounter(int nId, int nValue) ! 46: { ! 47: /* Update counters first (nCyclesMainCounter must be 0 afterwards) */ ! 48: Cycles_UpdateCounters(); ! 49: ! 50: /* Now set the new value: */ ! 51: nCyclesCounter[nId] = nValue; ! 52: } ! 53: ! 54: ! 55: /*-----------------------------------------------------------------------*/ ! 56: /* ! 57: Read a counter. ! 58: */ ! 59: int Cycles_GetCounter(int nId) ! 60: { ! 61: /* Update counters first so we read an up-to-date value */ ! 62: Cycles_UpdateCounters(); ! 63: ! 64: return nCyclesCounter[nId]; ! 65: } ! 66: ! 67: ! 68: /*-----------------------------------------------------------------------*/ ! 69: /* ! 70: Read a counter on CPU memory read access by taking care of the instruction ! 71: type (add the needed amount of additional cycles). ! 72: */ ! 73: int Cycles_GetCounterOnReadAccess(int nId) ! 74: { ! 75: int nAddCycles; ! 76: ! 77: /* Update counters first so we read an up-to-date value */ ! 78: Cycles_UpdateCounters(); ! 79: ! 80: /* TODO: Find proper cycle offset depending on the type of the current instruction */ ! 81: nAddCycles = 0; ! 82: ! 83: return nCyclesCounter[nId] + nAddCycles; ! 84: } ! 85: ! 86: ! 87: /*-----------------------------------------------------------------------*/ ! 88: /* ! 89: Read a counter on CPU memory write access by taking care of the instruction ! 90: type (add the needed amount of additional cycles). ! 91: */ ! 92: int Cycles_GetCounterOnWriteAccess(int nId) ! 93: { ! 94: int nAddCycles; ! 95: ! 96: /* Update counters first so we read an up-to-date value */ ! 97: Cycles_UpdateCounters(); ! 98: ! 99: /* TODO: Find proper cycle offset depending on the type of the current instruction */ ! 100: nAddCycles = 0; ! 101: ! 102: return nCyclesCounter[nId] + nAddCycles; ! 103: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.