#include <vsrv.h>

/* A routine to read Master Clock Counter. Counter increments every
 * DSP clock cycle. So, don't use this routine for anything else.
 */
	/* u_int32 ReadMasterClockCounter(); */
	.sect code, ReadMasterClockCounter
	.export _ReadMasterClockCounter
_ReadMasterClockCounter:
	/* Disable interrupts */
	ldc INT_GLOB_DIS, i7
	STP i7, (i7)
	nop
	nop
	nop
	ldc MCLKC_COUNTH, i7
	/* Interrupts should be disabled */
	LDP (i7)+(MCLKC_COUNTL-MCLKC_COUNTH), a1 /* <- sampling point */
	LDP (i7), a0 /* point + 1 */
	add a0, ones, a0 /* Now the value is back to sampling point. */
	ldc INT_GLOB_ENA, i7 /* Enable interrupts */
	jr
	STP i7, (i7)

/* A routine to read Master Clock Counter inside an interrupt.
 * Counter increments every DSP clock cycle. So, don't use
 * this routine  for anything else.
 */

	/* u_int32 ReadMasterClockCounterInterrupt(); */
	.sect code, ReadMasterClockCounterInterrupt
	.export _ReadMasterClockCounterInterrupt
_ReadMasterClockCounterInterrupt:
	ldc MCLKC_COUNTH, i7
	/* Interrupts should be disabled */
	LDP (i7)+(MCLKC_COUNTL-MCLKC_COUNTH), a1 /* <- sampling point */
	LDP (i7), a0 /* point + 1 */
	jr
	add a0, ones, a0 /* Now the value is back to sampling point. */



.end
