$INCLUDE (..\..\macro.inc)
$INCLUDE (..\..\library.inc)

Patch	 equ 0FC3500h
callAdr  equ 163A078h


org Patch

Entry:	mov		r1, #0
		STRB    R6, [R0,R4]
		ADD     R2, R0, R4
		STRB    R1, [R2,#1]
		MOV     R2, #5

		push	{r0-r2,r4-r7,lr}
		mov	r5, r0
		LoadReg 0, config+4
		bl      GetBuffer
		beq		exit
		
		mov	r4, #44
		add	r0, r6, r4
		bl	StrLen
		mov	r4, r0

		add	r3, r4, #1
		ldrb	r0, [r5, r3]
		cmp	r0, #"#"
		bne	exit

		mov	r7, #52
		add	r0, r6, r7

		mov	r3, #0		;clear ram
		str	r3, [r0]
		str	r3, [r0, #4]

		mov	r1, r5
		bl	strcopy

		add	r1, r0, r4
		mov	r3, #0
		strb	r3, [r1]

		sub	r0, r1 ,r4
		mov	r7, #44
		add	r1, r6, r7
		bl	strcmp
		
		cmp	r0, #0
		bne	exit

		ldrb	r3, [r5, r4]
		sub	r3, #0x30

		cmp	r3, #9
		bhi	exit
		cmp	r3, #0
		bmi	exit

		lsl	r3, #2
		add	r3, r6

		ldrb	r0, [r3, #7]
		cmp	r0, #0x00
		beq	exit

		ldr	r7, [r3, #4]
		//bl	handleRegs	;not implemented yet
		blx	r7


exit:	pop		{r0-r2,r4-r7}
		pop	{r3}
		add	r3, #4
		bx	r3


Align16
config:     dd Magic, 0xEA03, 0,0
db "{patch=HashCodes id=EA03 mem=68}"
db "{4 a F0}"
db "{8 a F1}"
db "{12 a F2}"
db "{16 a F3}"
db "{20 a F4}"
db "{24 a F5}"
db "{28 a F6}"
db "{32 a F7}"
db "{36 a F8}"
db "{40 a F9}"
db "{44 s CallStr maxlen=7}"
db 0
Align16

org callAdr
		CallReg 3, aPatch
aPatch:	dd		Patch + q1

END
