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

#define TICKS_PER_SEC 1000

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

/*
void RunTenClockCounter(void);
*/
	.sect code,RunTenClockCounter
	.export _RunTenClockCounter
_RunTenClockCounter:
	.import _tenClockLoops, _quitCpuTask
	ldx (i6)+1,null
	stx a0,(I6)+1 ; sty a1,(I6)
	ldc _tenClockLoops,i5
	ldx (i5)+1,a0;	sty b0,(I6)
	ldx (i5)-1,a1

	ldc _quitCpuTask,i7

	// Exactly 6 clock cycles / loop
$1:
	ldx (i7),b0
	stx a0,(i5)+1
	and b0,b0,b0;	stx a1,(i5)+1
	stx a0,(i5)+1
	jzs $1
	sub a,ones,a;	stx a1,(i5)-3

$99:
	ldy (I6)-1,b0
	jr
	ldx (I6)-1,a0 ; ldy (I6),a1



	.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
