all repos — mgba @ ee344f0dcab22151b49a1f2eff693bb904741366

mGBA Game Boy Advance Emulator

Optimize and fix IntrWait, make sure that SVC doesn't trample its input register r0
Jeffrey Pfau jeffrey@endrift.com
Tue, 15 Oct 2013 00:50:07 -0700
commit

ee344f0dcab22151b49a1f2eff693bb904741366

parent

f90b01b95d6f8ed936ffbc0fa456a8ea0016cc18

2 files changed, 44 insertions(+), 45 deletions(-)

jump to
M src/gba/hle-bios.csrc/gba/hle-bios.c

@@ -1,24 +1,22 @@

#include "hle-bios.h" -const unsigned int hleBiosLength = 220; +const unsigned int hleBiosLength = 196; const unsigned char hleBios[] = { 0x06, 0x00, 0x00, 0xea, 0xfe, 0xff, 0xff, 0xea, 0x05, 0x00, 0x00, 0xea, 0xfe, 0xff, 0xff, 0xea, 0xfe, 0xff, 0xff, 0xea, 0x00, 0x00, 0xa0, 0xe1, - 0x0c, 0x00, 0x00, 0xea, 0xfe, 0xff, 0xff, 0xea, 0x02, 0xf3, 0xa0, 0xe3, + 0x0e, 0x00, 0x00, 0xea, 0xfe, 0xff, 0xff, 0xea, 0x02, 0xf3, 0xa0, 0xe3, 0x00, 0x00, 0x5d, 0xe3, 0x01, 0xd3, 0xa0, 0x03, 0x20, 0xd0, 0x4d, 0x02, - 0x00, 0x40, 0x2d, 0xe9, 0x02, 0x00, 0x5e, 0xe5, 0x04, 0x00, 0x50, 0xe3, - 0x09, 0x00, 0x00, 0x0b, 0x05, 0x00, 0x50, 0xe3, 0x07, 0x00, 0x00, 0x0b, - 0x00, 0x40, 0xbd, 0xe8, 0x0e, 0xf0, 0xb0, 0xe1, 0x0f, 0x50, 0x2d, 0xe9, - 0x01, 0x03, 0xa0, 0xe3, 0x00, 0xe0, 0x8f, 0xe2, 0x04, 0xf0, 0x10, 0xe5, - 0x0f, 0x50, 0xbd, 0xe8, 0x04, 0xf0, 0x5e, 0xe2, 0x10, 0x40, 0x2d, 0xe9, - 0x04, 0xd0, 0x4d, 0xe2, 0xb0, 0x10, 0xcd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0x43, 0xa0, 0xe3, + 0x00, 0x00, 0x50, 0xe3, 0x00, 0x00, 0xa0, 0xe3, 0x01, 0x20, 0xa0, 0xe3, + 0x00, 0x00, 0x00, 0x0a, 0x01, 0x03, 0xc4, 0xe5, 0x04, 0x22, 0xc4, 0xe5, + 0xb8, 0x30, 0x54, 0xe1, 0x01, 0x30, 0x13, 0xe0, 0x01, 0x30, 0x23, 0x10, + 0xb8, 0x30, 0x44, 0x11, 0x04, 0x02, 0xc4, 0xe5, 0xf7, 0xff, 0xff, 0x0a, + 0x00, 0x00, 0x0f, 0xe1, 0x80, 0x00, 0x80, 0xe3, 0x00, 0xf0, 0x29, 0xe1, 0x10, 0x80, 0xbd, 0xe8 };
M src/gba/hle-bios.ssrc/gba/hle-bios.s

@@ -18,13 +18,15 @@ swiBase:

cmp sp, #0 moveq sp, #0x04000000 subeq sp, #0x20 -stmfd sp!, {lr} -ldrb r0, [lr, #-2] -cmp r0, #4 +stmfd sp!, {r2, lr} +ldrb r2, [lr, #-2] +cmp r2, #4 bleq IntrWait -cmp r0, #5 +cmp r2, #5 +moveq r0, #1 +moveq r1, #1 bleq IntrWait -ldmfd sp!, {lr} +ldmfd sp!, {r2, lr} movs pc, lr irqBase:

@@ -37,32 +39,31 @@ subs pc, lr, #4

IntrWait: stmfd sp!, {r4, lr} -add sp, #-4 -strh r1, [sp, #0] -mov r4, #0x04000000 -add r4, #0x200 -ldrh r0, [r4, #0] -strh r0, [sp, #2] -ldrh r1, [sp, #0] -orr r0, r1 -strh r0, [r4, #0x0] +# Save inputs +mrs r3, cpsr +bic r3, #0x80 +msr cpsr, r3 +# Pull current interrupts enabled and add the ones we need mov r4, #0x04000000 -IntrWaitLoop: -mov r0, #0x1F -msr cpsr, r0 +# See if we want to return immediately +cmp r0, #0 mov r0, #0 +mov r2, #1 +beq .L1 +# Halt +.L0: strb r0, [r4, #0x301] -mov r0, #0xD3 +.L1: +# Check which interrupts were acknowledged +strb r2, [r4, #0x204] +ldrh r3, [r4, #-8] +ands r3, r1 +eorne r3, r1 +strneh r3, [r4, #-8] +strb r0, [r4, #0x204] +beq .L0 +#Restore state +mrs r0, cpsr +orr r0, #0x80 msr cpsr, r0 -ldrh r0, [r4, #-8] -ldrh r1, [sp, #0] -ands r1, r0 -eorne r1, r0 -strneh r1, [r4, #-8] -beq IntrWaitLoop -mov r4, #0x04000000 -add r4, #0x200 -ldrh r0, [sp, #2] -strh r0, [r4, #0] -add sp, #4 ldmfd sp!, {r4, pc}