	.file	"extr_sms_cart.c_mapper_16k_w.c"
	.intel_syntax noprefix
	.text
	.p2align 4
	.type	mapper_16k_w, @function
mapper_16k_w:
.LFB0:
	.cfi_startproc
	endbr64
	mov	ecx, DWORD PTR slot[rip]
	mov	r8, QWORD PTR slot[rip+8]
	mov	eax, esi
	xor	edx, edx
	div	ecx
	mov	eax, DWORD PTR [r8]
	and	eax, 3
	je	.L2
	mov	r11, QWORD PTR MAPPER_SEGA[rip]
	cmp	QWORD PTR slot[rip+16], r11
	je	.L46
.L2:
	movsx	rax, edi
	mov	DWORD PTR [r8+rax*4], esi
	cmp	edi, 2
	je	.L3
	jg	.L4
	test	edi, edi
	je	.L5
	cmp	edi, 1
	jne	.L47
	mov	rax, QWORD PTR slot[rip+16]
	sal	edx, 14
	cmp	rax, QWORD PTR MAPPER_CODIES[rip]
	mov	rdi, QWORD PTR z80_readmap[rip]
	je	.L17
	cmp	rax, QWORD PTR MAPPER_MULTI[rip]
	je	.L17
.L18:
	mov	esi, 1
	.p2align 4,,10
	.p2align 3
.L19:
	mov	ecx, esi
	mov	rax, QWORD PTR slot[rip+24]
	sal	ecx, 10
	or	ecx, edx
	movsx	rcx, ecx
	lea	rax, [rax+rcx*4]
	mov	QWORD PTR [rdi+rsi*8], rax
	add	rsi, 1
	cmp	rsi, 16
	jne	.L19
	ret
	.p2align 4,,10
	.p2align 3
.L4:
	cmp	edi, 3
	jne	.L48
	test	BYTE PTR [r8], 8
	jne	.L1
	mov	rdi, QWORD PTR z80_readmap[rip]
	sal	edx, 14
	mov	eax, 32
	.p2align 4,,10
	.p2align 3
.L24:
	mov	ecx, eax
	mov	rsi, QWORD PTR slot[rip+24]
	sal	ecx, 10
	and	ecx, 15360
	or	ecx, edx
	movsx	rcx, ecx
	lea	rcx, [rsi+rcx*4]
	mov	QWORD PTR [rdi+rax*8], rcx
	add	rax, 1
	cmp	rax, 40
	jne	.L24
	mov	rsi, QWORD PTR MAPPER_CODIES[rip]
	cmp	QWORD PTR slot[rip+16], rsi
	je	.L49
	.p2align 4,,10
	.p2align 3
.L26:
	mov	ecx, eax
	mov	rsi, QWORD PTR slot[rip+24]
	sal	ecx, 10
	and	ecx, 15360
	or	ecx, edx
	movsx	rcx, ecx
	lea	rcx, [rsi+rcx*4]
	mov	QWORD PTR [rdi+rax*8], rcx
	add	rax, 1
	cmp	rax, 48
	jne	.L26
.L1:
	ret
	.p2align 4,,10
	.p2align 3
.L48:
	ret
	.p2align 4,,10
	.p2align 3
.L5:
	mov	rcx, QWORD PTR z80_writemap[rip]
	mov	rdi, QWORD PTR z80_readmap[rip]
	test	sil, 8
	je	.L9
	mov	r9d, esi
	mov	edx, 256
	sal	r9d, 12
	and	r9d, 16384
	.p2align 4,,10
	.p2align 3
.L10:
	mov	eax, edx
	mov	r8, QWORD PTR sram[rip]
	sal	eax, 7
	and	eax, 15360
	or	eax, r9d
	lea	rax, [r8+rax*4]
	mov	QWORD PTR [rcx+rdx], rax
	mov	QWORD PTR [rdi+rdx], rax
	add	rdx, 8
	cmp	rdx, 384
	jne	.L10
.L15:
	and	esi, 16
	mov	edx, 384
	je	.L12
	.p2align 4,,10
	.p2align 3
.L11:
	mov	rax, rdx
	sal	rax, 9
	and	eax, 61440
	add	rax, QWORD PTR sram[rip]
	mov	QWORD PTR [rcx+rdx], rax
	mov	QWORD PTR [rdi+rdx], rax
	add	rdx, 8
	cmp	rdx, 512
	jne	.L11
	ret
	.p2align 4,,10
	.p2align 3
.L3:
	mov	r8, QWORD PTR z80_readmap[rip]
	sal	edx, 14
	mov	edi, 16
	lea	r9, slot[rip]
	.p2align 4,,10
	.p2align 3
.L20:
	mov	ecx, edi
	mov	rax, QWORD PTR slot[rip+24]
	sal	ecx, 10
	and	ecx, 15360
	or	ecx, edx
	movsx	rcx, ecx
	lea	rax, [rax+rcx*4]
	mov	QWORD PTR [r8+rdi*8], rax
	add	rdi, 1
	cmp	rdi, 32
	jne	.L20
	mov	rax, QWORD PTR MAPPER_CODIES[rip]
	cmp	QWORD PTR slot[rip+16], rax
	jne	.L1
	and	esi, 128
	mov	rdi, QWORD PTR z80_writemap[rip]
	je	.L21
	mov	edx, 320
	.p2align 4,,10
	.p2align 3
.L22:
	mov	rax, rdx
	sal	rax, 9
	and	eax, 61440
	add	rax, QWORD PTR sram[rip]
	mov	QWORD PTR [rdi+rdx], rax
	mov	QWORD PTR [r8+rdx], rax
	add	rdx, 8
	cmp	rdx, 384
	jne	.L22
	ret
	.p2align 4,,10
	.p2align 3
.L46:
	mov	r9d, 4
	sub	r9d, eax
	lea	eax, [rdx+r9*8]
	xor	edx, edx
	div	ecx
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L12:
	mov	rax, rdx
	sal	rax, 9
	and	eax, 28672
	add	rax, QWORD PTR work_ram[rip]
	mov	QWORD PTR [rcx+rdx], rax
	mov	QWORD PTR [rdi+rdx], rax
	add	rdx, 8
	cmp	rdx, 512
	jne	.L12
	ret
	.p2align 4,,10
	.p2align 3
.L9:
	mov	r9d, DWORD PTR slot[rip]
	mov	eax, DWORD PTR 12[r8]
	xor	edx, edx
	div	r9d
	mov	eax, esi
	and	eax, 3
	je	.L13
	mov	r11, QWORD PTR MAPPER_SEGA[rip]
	cmp	QWORD PTR slot[rip+16], r11
	je	.L50
.L13:
	mov	eax, DWORD PTR cart[rip]
	sal	edx, 14
	mov	r8d, 256
	lea	r10d, 5308416[rax]
	movsx	r10, r10d
	.p2align 4,,10
	.p2align 3
.L14:
	mov	eax, r8d
	mov	r9, QWORD PTR slot[rip+24]
	sal	eax, 7
	and	eax, 15360
	or	eax, edx
	cdqe
	lea	rax, [r9+rax*4]
	mov	QWORD PTR [rdi+r8], rax
	mov	QWORD PTR [rcx+r8], r10
	add	r8, 8
	cmp	r8, 384
	jne	.L14
	jmp	.L15
	.p2align 4,,10
	.p2align 3
.L17:
	mov	rcx, QWORD PTR slot[rip+24]
	movsx	rax, edx
	lea	rax, [rcx+rax*4]
	mov	QWORD PTR [rdi], rax
	jmp	.L18
.L21:
	mov	rax, QWORD PTR slot[rip+8]
	xor	edx, edx
	mov	ecx, 320
	mov	eax, DWORD PTR 12[rax]
	div	DWORD PTR [r9]
	mov	eax, DWORD PTR cart[rip]
	lea	r9d, 5308416[rax]
	movsx	r9, r9d
	sal	edx, 14
	.p2align 4,,10
	.p2align 3
.L23:
	mov	eax, ecx
	mov	rsi, QWORD PTR slot[rip+24]
	sal	eax, 7
	and	eax, 15360
	or	eax, edx
	cdqe
	lea	rax, [rsi+rax*4]
	mov	QWORD PTR [r8+rcx], rax
	mov	QWORD PTR [rdi+rcx], r9
	add	rcx, 8
	cmp	rcx, 384
	jne	.L23
	ret
.L50:
	mov	r8d, 4
	sub	r8d, eax
	lea	eax, [rdx+r8*8]
	xor	edx, edx
	div	r9d
	jmp	.L13
.L49:
	mov	rcx, QWORD PTR slot[rip+8]
	test	BYTE PTR 8[rcx], -128
	je	.L26
	ret
.L47:
	ret
	.cfi_endproc
.LFE0:
	.size	mapper_16k_w, .-mapper_16k_w
	.comm	z80_writemap,8,8
	.comm	z80_readmap,8,8
	.comm	work_ram,8,8
	.comm	sram,8,8
	.comm	slot,32,32
	.comm	cart,4,4
	.comm	MAPPER_SEGA,8,8
	.comm	MAPPER_MULTI,8,8
	.comm	MAPPER_CODIES,8,8
	.ident	"GCC: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	 1f - 0f
	.long	 4f - 1f
	.long	 5
0:
	.string	 "GNU"
1:
	.align 8
	.long	 0xc0000002
	.long	 3f - 2f
2:
	.long	 0x3
3:
	.align 8
4:

	.arch armv5t
	.eabi_attribute 20, 1
	.eabi_attribute 21, 1
	.eabi_attribute 23, 3
	.eabi_attribute 24, 1
	.eabi_attribute 25, 1
	.eabi_attribute 26, 2
	.eabi_attribute 30, 2
	.eabi_attribute 34, 0
	.eabi_attribute 18, 4
	.file	"extr_sms_cart.c_mapper_16k_w.c"
	.text
	.global	__aeabi_uidivmod
	.align	2
	.syntax unified
	.arm
	.fpu softvfp
	.type	mapper_16k_w, %function
mapper_16k_w:
	@ args = 0, pretend = 0, frame = 0
	@ frame_needed = 0, uses_anonymous_args = 0
	push	{r4, r5, r6, r7, r8, r9, r10, lr}
	ldr	r4, .L57
	mov	r6, r1
	ldr	r7, [r4]
	mov	r5, r0
	mov	r0, r1
	mov	r1, r7
	bl	__aeabi_uidivmod
	ldr	r8, [r4, #4]
	ldr	r3, [r8]
	ands	r3, r3, #3
	beq	.L2
	ldr	r2, .L57+4
	ldr	r0, [r4, #8]
	ldr	r2, [r2]
	cmp	r0, r2
	beq	.L53
.L2:
	str	r6, [r8, r5, lsl #2]
	cmp	r5, #3
	ldrls	pc, [pc, r5, asl #2]
	b	.L1
.L5:
	.word	.L8
	.word	.L7
	.word	.L6
	.word	.L4
.L1:
	pop	{r4, r5, r6, r7, r8, r9, r10, pc}
.L4:
	ldr	r3, [r8]
	tst	r3, #8
	popne	{r4, r5, r6, r7, r8, r9, r10, pc}
	mov	r3, #32768
	ldr	r2, .L57+8
	lsl	ip, r1, #14
	ldr	lr, [r2]
	add	r0, lr, #124
.L26:
	ldr	r2, [r4, #12]
	and	r1, r3, #15360
	orr	r1, r1, ip
	add	r3, r3, #1024
	add	r2, r2, r1, lsl #2
	cmp	r3, #40960
	str	r2, [r0, #4]!
	bne	.L26
	ldr	r2, .L57+12
	ldr	r1, [r4, #8]
	ldr	r2, [r2]
	cmp	r1, r2
	beq	.L54
.L27:
	add	r0, lr, #156
.L28:
	ldr	r2, [r4, #12]
	and	r1, r3, #15360
	orr	r1, r1, ip
	add	r3, r3, #1024
	add	r2, r2, r1, lsl #2
	cmp	r3, #49152
	str	r2, [r0, #4]!
	bne	.L28
	pop	{r4, r5, r6, r7, r8, r9, r10, pc}
.L6:
	mov	r3, #16384
	ldr	r2, .L57+8
	lsl	ip, r1, #14
	ldr	r5, [r2]
	add	r1, r5, #60
.L22:
	ldr	r2, [r4, #12]
	and	r0, r3, #15360
	orr	r0, r0, ip
	add	r3, r3, #1024
	add	r2, r2, r0, lsl #2
	cmp	r3, #32768
	str	r2, [r1, #4]!
	bne	.L22
	ldr	r3, .L57+12
	ldr	r2, [r4, #8]
	ldr	r3, [r3]
	cmp	r2, r3
	popne	{r4, r5, r6, r7, r8, r9, r10, pc}
	ldr	r3, .L57+16
	tst	r6, #128
	ldr	r6, [r3]
	beq	.L23
	mov	r2, #40960
	ldr	r0, .L57+20
	add	r1, r6, #156
	add	r5, r5, #156
.L24:
	ldr	r3, [r0]
	and	ip, r2, #15360
	add	r2, r2, #1024
	add	r3, r3, ip, lsl #2
	cmp	r2, #49152
	str	r3, [r1, #4]!
	str	r3, [r5, #4]!
	bne	.L24
	pop	{r4, r5, r6, r7, r8, r9, r10, pc}
.L7:
	ldr	r2, .L57+12
	ldr	r3, [r4, #8]
	ldr	r0, [r2]
	ldr	r2, .L57+8
	cmp	r3, r0
	lsl	ip, r1, #14
	ldr	r1, [r2]
	beq	.L19
	ldr	r2, .L57+24
	ldr	r2, [r2]
	cmp	r3, r2
	beq	.L19
.L20:
	mov	r3, #1024
.L21:
	ldr	r2, [r4, #12]
	orr	r0, r3, ip
	add	r3, r3, #1024
	add	r2, r2, r0, lsl #2
	cmp	r3, #16384
	str	r2, [r1, #4]!
	bne	.L21
	pop	{r4, r5, r6, r7, r8, r9, r10, pc}
.L8:
	ldr	r2, .L57+16
	ldr	r3, .L57+8
	tst	r6, #8
	ldr	r7, [r2]
	ldr	r5, [r3]
	beq	.L9
	mov	r2, #32768
	lsl	r4, r6, #12
	ldr	r0, .L57+20
	and	r4, r4, #16384
	add	lr, r7, #124
	add	ip, r5, #124
.L10:
	ldr	r3, [r0]
	and	r1, r2, #15360
	orr	r1, r1, r4
	add	r2, r2, #1024
	add	r3, r3, r1, lsl #2
	cmp	r2, #49152
	str	r3, [lr, #4]!
	str	r3, [ip, #4]!
	bne	.L10
.L15:
	tst	r6, #16
	beq	.L55
	mov	r2, #49152
	ldr	r0, .L57+20
	add	r7, r7, #188
	add	r5, r5, #188
.L16:
	ldr	r3, [r0]
	and	r1, r2, #15360
	add	r2, r2, #1024
	add	r3, r3, r1, lsl #2
	cmp	r2, #65536
	str	r3, [r7, #4]!
	str	r3, [r5, #4]!
	bne	.L16
	pop	{r4, r5, r6, r7, r8, r9, r10, pc}
.L53:
	rsb	r3, r3, #4
	add	r0, r1, r3, lsl #3
	mov	r1, r7
	bl	__aeabi_uidivmod
	b	.L2
.L9:
	ldr	r9, [r4]
	ldr	r0, [r8, #12]
	mov	r1, r9
	bl	__aeabi_uidivmod
	ands	r3, r6, #3
	beq	.L13
	ldr	r2, .L57+4
	ldr	r0, [r4, #8]
	ldr	r2, [r2]
	cmp	r0, r2
	beq	.L56
.L13:
	mov	r3, #32768
	ldr	r2, .L57+28
	lsl	lr, r1, #14
	ldr	r8, [r2]
	add	ip, r5, #124
	add	r8, r8, #5308416
	add	r0, r7, #124
.L14:
	ldr	r2, [r4, #12]
	and	r1, r3, #15360
	orr	r1, r1, lr
	add	r3, r3, #1024
	add	r2, r2, r1, lsl #2
	cmp	r3, #49152
	str	r2, [ip, #4]!
	str	r8, [r0, #4]!
	bne	.L14
	b	.L15
.L19:
	ldr	r3, [r4, #12]
	add	r3, r3, ip, lsl #2
	str	r3, [r1]
	b	.L20
.L55:
	mov	r2, #49152
	ldr	r0, .L57+32
	add	r7, r7, #188
	add	r5, r5, #188
.L17:
	ldr	r3, [r0]
	and	r1, r2, #7168
	add	r2, r2, #1024
	add	r3, r3, r1, lsl #2
	cmp	r2, #65536
	str	r3, [r7, #4]!
	str	r3, [r5, #4]!
	bne	.L17
	pop	{r4, r5, r6, r7, r8, r9, r10, pc}
.L23:
	ldm	r4, {r1, r3}
	ldr	r0, [r3, #12]
	bl	__aeabi_uidivmod
	mov	r3, #40960
	ldr	r2, .L57+28
	lsl	lr, r1, #14
	ldr	ip, [r2]
	add	r5, r5, #156
	add	r0, r6, #156
	add	ip, ip, #5308416
.L25:
	ldr	r2, [r4, #12]
	and	r1, r3, #15360
	orr	r1, r1, lr
	add	r3, r3, #1024
	add	r2, r2, r1, lsl #2
	cmp	r3, #49152
	str	r2, [r5, #4]!
	str	ip, [r0, #4]!
	bne	.L25
	pop	{r4, r5, r6, r7, r8, r9, r10, pc}
.L56:
	rsb	r3, r3, #4
	add	r0, r1, r3, lsl #3
	mov	r1, r9
	bl	__aeabi_uidivmod
	b	.L13
.L54:
	ldr	r2, [r4, #4]
	ldr	r2, [r2, #8]
	tst	r2, #128
	popne	{r4, r5, r6, r7, r8, r9, r10, pc}
	b	.L27
.L58:
	.align	2
.L57:
	.word	slot
	.word	MAPPER_SEGA
	.word	z80_readmap
	.word	MAPPER_CODIES
	.word	z80_writemap
	.word	sram
	.word	MAPPER_MULTI
	.word	cart
	.word	work_ram
	.size	mapper_16k_w, .-mapper_16k_w
	.comm	z80_writemap,4,4
	.comm	z80_readmap,4,4
	.comm	work_ram,4,4
	.comm	sram,4,4
	.comm	slot,16,4
	.comm	cart,4,4
	.comm	MAPPER_SEGA,4,4
	.comm	MAPPER_MULTI,4,4
	.comm	MAPPER_CODIES,4,4
	.ident	"GCC: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0"
	.section	.note.GNU-stack,"",%progbits
