#include <vstypes.h>
#include <vs1005h.h>

#define TICKS_PER_SEC 1000

#if 0
	.sect code,GetMR0
	.export _GetMR0
_GetMR0:
	jr
	mv mr0,a0
#endif

/*
u_int32 TestSpeedLoopAsm(void);
*/
	.sect code,TestSpeedLoopAsm
	.export _TestSpeedLoopAsm
_TestSpeedLoopAsm:
	.import _timeCount
	.import _quitCpuTask
	.import _delayMS
	and a,null,a;	ldx (i6)+1,null
	stx b0,(I6)+1 ; sty d0,(I6)
	stx c0,(i6)

	ldc _timeCount,i5
	ldy (i5),d0
	ldc _quitCpuTask,i7

	// Exactly 10 cycles / loop
$1:
	ldx (i7),b0
	and b0,b0,b0
	ldc _delayMS,i7
	jzc $99
	ldy (i5),b0; ldx (i7),c0
	sub b0,d0,b0
	sub b0,c0,b0
	ldc _quitCpuTask,i7
	jcc $1
	sub a,ones,a

$99:
	ldx (i6)-1,c0
	jr
	ldx (I6)-1,b0 ; ldy (I6),d0



	.end

#if 0
	/********* EVERYTHING FROM NOW ON IS PURELY DECORATIONAL!!! **********/

/*
	void Generic(void) - 2018 edition
*/
 	.sect code,Generic
	.export _Generic
_Generic:
	ldx (i6)+1,null
	stx i0,(I6)+1;	sty i1,(I6)
	stx i2,(I6)+1;	sty i3,(I6)
	stx le,(I6)+1;	sty ls,(I6)
	stx lr0,(I6)+1;	sty lc,(I6)
	stx a0,(I6)+1;	sty a1,(I6)
	stx b0,(I6)+1;	sty b1,(I6)
	stx c0,(I6)+1;	sty c1,(I6)
	stx d0,(I6)+1;	sty d1,(I6)
	stx i4,(I6)

	ldx (I6)-1,i4
	ldx (I6)-1,d0;	ldy (I6),d1
	ldx (I6)-1,c0;	ldy (I6),c1
	ldx (I6)-1,b0;	ldy (I6),b1
	ldx (I6)-1,a0;	ldy (I6),a1
	ldx (I6)-1,lr0;	ldy (I6),lc
	ldx (I6)-1,le;	ldy (I6),ls
	ldx (I6)-1,i2;	ldy (I6),i3
	jr
	ldx (I6)-1,i0;	ldy (I6),i1
#endif
