/**
	\file chacha20Asm.s
	
*/
#include <vstypes.h>


#ifdef ASM
	.sect code,ToHex
	.export _ToHex
_ToHex:
	ldx (I6)+1,NULL
	
	ldc '0',a0
	sub c0,a0,a0;	stx b0,(i6)
	ldc '9',b0
	jlt $2		// c < '0', isdigit(c) = FALSE
	sub c0,b0,b0
	
	nop
	jle $9		// '0' <= 'c' <= '9', isdigit(c) = TRUE
$2:
	// NOTE!
	// Next instruction intentionally put into delay slot of jle $9!
	ldc 0x20,b0
	or c0,b0,c0	// c = toupper(c)

	ldc 'a',a0	// c < 'a', isxdigit(c) = FALSE
	sub c0,a0,a0
	ldc 'f',b0
	jlt $3		// <
	sub c0,b0,b0
	
	ldc 'a'-10,b0
	jle $9		// 'a' <= 'c' <= 'z', isxdigit(c) = TRUE
	sub c0,b0,a0

$3:
	ldc -1,a0	// return 0xFFFF = fail
$9:
	jr
	ldx (i6)-1,b0

#endif /* ASM */




	.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
