.gba
.open "zm.gba","EventUnlock.gba",0x8000000

.org 0x805F0C4
	ldr r0,[r4,4h]

.org 0x805F0D2
	bl FreeSpace
	
.org 0x8043DF0	;Crocomire AI unused
FreeSpace:
	mov r1,1h
	strb r1,[r4]
	ldr r3,=300545Ch
	mov r2,0h
WhileLoop:
	cmp r2,0Fh
	bhi Return
	ldrh r0,[r4,2h]
	and r0,r1
	cmp r0,0h
	bne TryOpenDoor
	ldrh r0,[r4,4h]
	and r0,r1
	cmp r0,0h
	beq Continue
TryOpenDoor:
	ldrb r0,[r3,3h]
	cmp r0,7h
	bne Continue
	sub r0,1h
	strb r0,[r3,3h]
Continue:
	lsl r1,r1,1h
	add r2,1h
	add r3,8h
	b WhileLoop
Return:
	bx r14
	
.pool
.close