Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/gz/zu.c b/src/gz/zu.c
- index 5bd6bed..b6d88d2 100644
- --- a/src/gz/zu.c
- +++ b/src/gz/zu.c
- @@ -319,23 +319,100 @@ void zu_sram_write(void *dram_addr, uint32_t sram_addr, size_t size)
- void zu_reset(void)
- {
- - volatile uint32_t *mi_intr = (void*)0xA4300008;
- volatile uint32_t *sp_status = (void*)0xA4040010;
- - /* disable interrupts */
- - __asm__ volatile ("mfc0 $t0, $12 \n"
- - "and $t0, %0 \n"
- - "mtc0 $t0, $12 \n" :: "r"(~MIPS_STATUS_IE));
- - /* wait for rsp to halt */
- - while (!(*sp_status & 3))
- - ;
- - /* wait for dma busy */
- - while (pi_regs.status & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY))
- - ;
- - /* reset pi */
- - pi_regs.status = PI_STATUS_RESET | PI_STATUS_CLR_INTR;
- - /* wait for vblank */
- - while (!(*mi_intr & 8))
- - ;
- + volatile uint32_t *mi_mode = (void*)0xA4300000;
- + volatile uint32_t *mi_intr_mask = (void*)0xA430000C;
- + //volatile uint32_t *vi_status = (void*)0xA4400000;
- + volatile uint32_t *pi_status = (void*)0xA4600010;
- + volatile uint32_t *si_status = (void*)0xA4800018;
- +
- + __asm__ volatile (/* reset cp0 status (disable interrupts) */
- + "la $t0, 0b00110100000000000000000000000000;"
- + "mtc0 $t0, $12;"
- + /* reset cp1 fpcsr */
- + "la $t0, 0b00000001100000000000100000000000;"
- + "ctc1 $t0, $31;");
- +
- + /* reset everything */
- + *sp_status = 0b0101010101010101010101110;
- + //*vi_status = 0;
- + *pi_status = 0b11;
- + *si_status = 0;
- + *mi_mode = 0b01101010000000;
- + *mi_intr_mask = 0b010101010101;
- +
- + /* flush data cache */
- + for (uint32_t p = 0x80000000; p < 0x80800000; p += 0x10)
- + __asm__ volatile ("cache 0x19, 0x0000(%0);" :: "r"(p));
- +
- +#ifdef WIIVC
- + __asm__ volatile (".set push;"
- + ".set noat;"
- + ".set noreorder;"
- + /* 80000004 */
- + /* dma rom to ram */
- + "lui $t3, 0xB000;"
- + "lw $t1, 0x0008($t3);"
- + "lui $t2, 0x1FFF;"
- + "ori $t2, $t2, 0xFFFF;"
- + "lui $at, 0xA460;"
- + "and $t1, $t1, $t2;"
- + "sw $t1, 0x0000($at);"
- + "lui $t0, 0xA460;"
- + "lw $t0, 0x0010($t0);"
- + "andi $t0, $t0, 0x0002;"
- + "bnel $t0, $zero, . - 0x0008;"
- + "lui $t0, 0xA460;"
- + "addiu $t0, $zero, 0x1000;"
- + "add $t0, $t0, $t3;"
- + "and $t0, $t0, $t2;"
- + "lui $at, 0xA460;"
- + "sw $t0, 0x0004($at);"
- + "lui $t2, 0x0010;"
- + "addiu $t2, $t2, 0xFFFF;"
- + "lui $at, 0xA460;"
- + "sw $t2, 0x000C($at);"
- + /* wait for dma to complete */
- + ".rept 0x10;"
- + "nop;"
- + ".endr;"
- + "lui $t3, 0xA460;"
- + "lw $t3, 0x0010($t3);"
- + "andi $t3, $t3, 0x0001;"
- + "bnez $t3, . - 0x4C;"
- + "nop;"
- +
- + /* set mi intr mask (clear all) */
- + "lui $at, 0xA430;"
- + "addiu $t0, $zero, 0x0555;"
- + "sw $t0, 0x000C($at);"
- + /* clear si interrupt */
- + "lui $at, 0xA480;"
- + "sw $zero, 0x0018($at);"
- + /* clear ai interrupt */
- + "lui $at, 0xA450;"
- + "sw $zero, 0x000C($at);"
- + /* clear dp interrupt */
- + "lui $at, 0xA430;"
- + "addiu $t1, $zero, 0x0800;"
- + "sw $t1, 0x0000($at);"
- + /* clear pi interrupt */
- + "addiu $t1, $zero, 0x0002;"
- + "lui $at, 0xA460;"
- + "sw $t1, 0x0010($at);"
- +
- + /* jump to game code */
- + "lui $t3, 0xB000;"
- +#if 0
- + "lw $t1, 0x0008($t3);"
- +#else
- + "lui $t1, 0x8040;"
- + "addiu $t1, $t1, 0x0000;"
- +#endif
- + "jr $t1;"
- + "nop;"
- + ".set pop;");
- +#else
- /* copy pif code to rsp imem */
- uint32_t imem[] =
- {
- @@ -352,22 +429,578 @@ void zu_reset(void)
- /* copy cic boot code to rsp dmem */
- memcpy((void*)0xA4000040, (void*)0xB0000040, 0x0FC0);
- /* simulate boot from cic boot code */
- - __asm__ volatile ("lui $t0, 0x8000 \n"
- + __asm__ volatile ("lui $t0, 0x8000;"
- /* osRomType (0: N64, 1: 64DD) */
- - "li $s3, 0x0000 \n"
- + "li $s3, 0x0000;"
- /* osTvType (0: PAL, 1: NTSC, 2: MPAL) */
- - "lw $s4, 0x0300($t0) \n"
- + "lw $s4, 0x0300($t0);"
- /* osResetType (0: Cold, 1: NMI) */
- - "li $s5, 0x0001 \n"
- + "li $s5, 0x0001;"
- /* osCicId (3F: 6101/6102, 78: 6103, 91: 6105, 85: 6106) */
- - "li $s6, 0x0091 \n"
- + "li $s6, 0x0091;"
- /* osVersion */
- - "lw $s7, 0x0314($t0) \n"
- + "lw $s7, 0x0314($t0);"
- /* go */
- - "la $t3, 0xA4000040 \n"
- - "la $sp, 0xA4001FF0 \n"
- - "la $ra, 0xA4001550 \n"
- - "jr $t3 \n");
- + "la $t3, 0xA4000040;"
- + "la $sp, 0xA4001FF0;"
- + "la $ra, 0xA4001550;"
- +#if 0
- + /* jump to boot code */
- + "jr $t3;"
- +#elif 1
- + /* jump to k1 */
- + "la $t0, . + 0x0024;"
- + "lui $t1, 0x8000;"
- + "addiu $t1, $t1, 0xFFFF;"
- + "lui $t2, 0xA000;"
- + "addiu $t2, $t2, 0x0000;"
- + "and $t0, $t0, $t1;"
- + "or $t0, $t0, $t2;"
- + "jr $t0;"
- + "nop;"
- +#endif
- +
- + ".set push;"
- + ".set noat;"
- + ".set noreorder;"
- + /* A4000040 */
- + /* decode rsp boot code */
- + "add $t1, $sp, $zero;"
- + "lw $t0, -0x0FF0($t1);"
- + "lw $t2, 0x0044($t3);"
- + "xor $t2, $t2, $t0;"
- + "sw $t2, -0x0FF0($t1);"
- + "addi $t3, $t3, 0x0004;"
- + "andi $t0, $t0, 0x0FFF;"
- + "bnez $t0, . - 0x0018;"
- + "addi $t1, $t1, 0x0004;"
- + "lw $t0, 0x0044($t3);"
- + "lw $t2, 0x0048($t3);"
- + "sw $t0, -0x0FF0($t1);"
- + "sw $t2, -0x0FEC($t1);"
- + /* this branch is always taken */
- + //"bltz $ra, ..."
- + "sw $zero, -0x0FE8($t1);"
- + "mtc0 $zero, $13;"
- + "mtc0 $zero, $9;"
- + "mtc0 $zero, $11;"
- +
- +#if 1
- + /* A40000C4 */
- + /* rdram configuration */
- + "lui $t0, 0xA470;"
- + "addiu $t0, $t0, 0x0000;"
- + "lw $t1, 0x000C($t0);" /* RI_SELECT_REG */
- + "bnez $t1, . + 0x03B8;"
- + "nop;"
- + "addiu $sp, $sp, 0xFFE8;"
- + "sw $s3, 0x0000($sp);"
- + "sw $s4, 0x0004($sp);"
- + "sw $s5, 0x0008($sp);"
- + "sw $s6, 0x000C($sp);"
- + "sw $s7, 0x0010($sp);"
- + "lui $t0, 0xA470;"
- + "addiu $t0, 0x0000;"
- + "lui $t2, 0xA3F8;"
- + "lui $t3, 0xA3F0;"
- + "lui $t4, 0xA430;"
- + "addiu $t4, $t4, 0x0000;"
- + "ori $t1, $zero, 0x0040;"
- + "sw $t1, 0x0004($t0);" /* RI_CONFIG_REG */
- + "addiu $s1, $zero, 0x1F40;"
- + /* spin */
- + "nop;"
- + "addi $s1, $s1, 0xFFFF;"
- + "bnez $s1, . - 0x0008;"
- + "nop;"
- + "sw $zero, 0x0008($t0);" /* RI_CURRENT_LOAD_REG */
- + "ori $t1, $zero, 0x0014;"
- + "sw $t1, 0x000C($t0);" /* RI_SELECT_REG */
- + "sw $zero, 0x0000($t0);" /* RI_MODE_REG */
- + "addiu $s1, $zero, 0x0004;"
- + /* spin */
- + "nop;"
- + "addi $s1, $s1, 0xFFFF;"
- + "bnez $s1, . - 0x0008;"
- + "nop;"
- +
- + "ori $t1, $zero, 0x000E;"
- + "sw $t1, 0x0000($t0);" /* RI_MODE_REG */
- + "addiu $s1, $zero, 0x0020;"
- + "addi $s1, $s1, 0xFFFF;"
- + "bnez $s1, . - 0x0004;"
- + "ori $t1, $zero, 0x010F;"
- + "sw $t1, 0x0000($t4);" /* MI_MODE_REG (set init mode 15) */
- + "lui $t1, 0x1808;"
- + "ori $t1, $t1, 0x2838;"
- + "sw $t1, 0x0008($t2);" /* RDRAM_GLOBAL_CONFIG, RDRAM_DELAY_REG */
- + "sw $zero, 0x0014($t2);" /* RDRAM_GLOBAL_CONFIG, RDRAM_REF_ROW_REG */
- + "lui $t1, 0x8000;"
- + "sw $t1, 0x0004($t2);" /* RDRAM_GLOBAL_CONFIG, RDRAM_DEVICE_ID_REG */
- + "or $t5, $zero, $zero;"
- + "or $t6, $zero, $zero;"
- + "lui $t7, 0xA3F0;"
- + "or $t8, $zero, $zero;"
- + "lui $t9, 0xA3F0;"
- + "lui $s6, 0xA000;"
- + "or $s7, $zero, $zero;"
- + "lui $a2, 0xA3F0;"
- + "lui $a3, 0xA000;"
- + "or $s2, $zero, $zero;"
- + "lui $s4, 0xA000;"
- + "addiu $sp, $sp, 0xFFB8;"
- + "or $s8, $sp, $zero;"
- + "lui $s0, 0xA430;"
- + "lw $s0, 0x0004($s0);" /* MI_VERSION_REG */
- + "lui $s1, 0x0101;"
- + "addiu $s1, $s1, 0x0101;"
- + "bne $s0, $s1, . + 0x0018;"
- + "nop;"
- + "addiu $s0, $zero, 0x0200;"
- + "ori $s1, $t3, 0x4000;"
- + "beq $zero, $zero, . + 0x0010;"
- + "nop;"
- + "addiu $s0, $zero, 0x0400;"
- + "ori $s1, $t3, 0x8000;"
- + "sw $t6, 0x0004($s1);" /* RDRAM_DEVICE_ID_REG */
- + "addiu $s5, $t7, 0x000C;" /* RDRAM_MODE_REG */
- + "jal 0xA400087C;"
- + "nop;"
- + "beq $v0, $zero, . + 0x00E4;"
- + "nop;"
- + "sw $v0, 0x0000($sp);"
- + "addiu $t1, $zero, 0x2000;"
- + "sw $t1, 0x0000($t4);" /* MI_MODE_REG (MI_SET_RDRAM) */
- + "lw $t3, 0x0000($t7);" /* RDRAM_DEVICE_TYPE_REG */
- + "lui $t0, 0xF0FF;"
- + "and $t3, $t3, $t0;"
- + "sw $t3, 0x0004($sp);"
- + "addi $sp, $sp, 0x0008;"
- + "addiu $t1, $zero, 0x1000;"
- + "sw $t1, 0x0000($t4);" /* MI_MODE_REG (MI_CLR_RDRAM) */
- + "lui $t0, 0xB019;"
- + "bne $t3, $t0, . + 0x0034;"
- + "nop;"
- + "lui $t0, 0x0800;"
- + "add $t8, $t8, $t0;"
- + "add $t9, $t9, $s0;"
- + "add $t9, $t9, $s0;"
- + "lui $t0, 0x0020;"
- + "add $s6, $s6, $t0;"
- + "add $s4, $s4, $t0;"
- + "sll $s2, $s2, 0x01;"
- + "addi $s2, $s2, 0x0001;"
- + "beq $zero, $zero, . + 0x0010;"
- + "nop;"
- + "lui $t0, 0x0010;"
- + "add $s4, $s4, $t0;"
- + "addiu $t0, $zero, 0x2000;"
- + "sw $t0, 0x0000($t4);" /* MI_MODE_REG (MI_SET_RDRAM) */
- + "lw $t1, 0x0024($t7);" /* RDRAM_DEVICE_MANUF_REG */
- + "lw $k0, 0x0000($t7);" /* RDRAM_DEVICE_TYPE_REG */
- + "addiu $t0, $zero, 0x1000;"
- + "sw $t0, 0x0000($t4);" /* MI_MODE_REG (MI_CLR_RDRAM) */
- + "andi $t1, $t1, 0xFFFF;"
- + "addiu $t0, $zero, 0x0500;"
- + "bne $t1, $t0, . + 0x0028;"
- + "nop;"
- + "lui $k1, 0x0100;"
- + "and $k0, $k0, $k1;"
- + "bnez $k0, . + 0x0018;"
- + "nop;"
- + "lui $t0, 0x101C;"
- + "ori $t0, $t0, 0x0A04;"
- + "sw $t0, 0x0018($t7);" /* RDRAM_RAS_INTERVAL_REG */
- + "beq $zero, $zero, . + 0x0010;"
- + "lui $t0, 0x080C;"
- + "ori $t0, $t0, 0x1204;"
- + "sw $t0, 0x0018($t7);" /* RDRAM_RAS_INTERVAL_REG */
- + "lui $t0, 0x0800;"
- + "add $t6, $t6, $t0;"
- + "add $t7, $t7, $s0;"
- + "add $t7, $t7, $s0;"
- + "addiu $t5, $t5, 0x0001;"
- + "sltiu $t0, $t5, 0x0008;"
- + "bnez $t0, . - 0x00EC;"
- + "nop;"
- + "lui $t0, 0xC400;"
- + "sw $t0, 0x000C($t2);" /* RDRAM_GLOBAL_CONFIG, RDRAM_MODE_REG */
- + "lui $t0, 0x8000;"
- + "sw $t0, 0x0004($t2);" /* RDRAM_GLOBAL_CONFIG, RDRAM_DEVICE_ID_REG */
- + "or $sp, $s8, $zero;"
- + "or $v1, $zero, $zero;"
- + "lw $t1, 0x0004($sp);"
- + "lui $t0, 0xB009;"
- + "bne $t1, $t0, . + 0x005C;"
- + "nop;"
- + "sw $t8, 0x0004($s1);" /* RDRAM_DEVICE_ID_REG */
- + "addiu $s5, $t9, 0x000C;"
- + "lw $a0, 0x0000($sp);"
- + "addi $sp, $sp, 0x0008;"
- + "addiu $a1, $zero, 0x0001;"
- + "jal 0xA4000B44;"
- + "nop;"
- + "lw $t0, 0x0000($s6);"
- + "lui $t0, 0x0008;"
- + "add $t0, $t0, $s6;"
- + "lw $t1, 0x0000($t0);"
- + "lw $t0, 0x0000($s6);"
- + "lui $t0, 0x0008;"
- + "add $t0, $t0, $s6;"
- + "lw $t1, 0x0000($t0);"
- + "lui $t0, 0x0400;"
- + "add $t6, $t6, $t0;"
- + "add $t9, $t9, $s0;"
- + "lui $t0, 0x0010;"
- + "add $s6, $s6, $t0;"
- + "beq $zero, $zero, . + 0x0088;"
- + "sw $s7, 0x0004($s1);" /* RDRAM_DEVICE_ID_REG */
- + "addiu $s5, $a2, 0x000C;"
- + "lw $a0, 0x0000($sp);"
- + "addi $sp, $sp, 0x0008;"
- + "addiu $a1, $zero, 0x0001;"
- + "jal 0xA4000B44;"
- + "nop;"
- + "lw $t0, 0x0000($a3);"
- + "lui $t0, 0x0008;"
- + "add $t0, $t0, $a3;"
- + "lw $t1, 0x0000($t0);"
- + "lui $t0, 0x0010;"
- + "add $t0, $t0, $a3;"
- + "lw $t1, 0x0000($t0);"
- + "lui $t0, 0x0018;"
- + "add $t0, $t0, $a3;"
- + "lw $t1, 0x0000($t0);"
- + "lw $t0, 0x0000($a3);"
- + "lui $t0, 0x0008;"
- + "add $t0, $t0, $a3;"
- + "lw $t1, 0x0000($t0);"
- + "lui $t0, 0x0010;"
- + "add $t0, $t0, $a3;"
- + "lw $t1, 0x0000($t0);"
- + "lui $t0, 0x0018;"
- + "add $t0, $t0, $a3;"
- + "lw $t1, 0x0000($t0);"
- + "lui $t0, 0x0800;"
- + "add $s7, $s7, $t0;"
- + "add $a2, $a2, $s0;"
- + "add $a2, $a2, $s0;"
- + "lui $t0, 0x0020;"
- + "add $a3, $a3, $t0;"
- + "addiu $v1, $v1, 0x0001;"
- + "slt $t0, $v1, $t5;"
- + "bnez $t0, . - 0x00F0;"
- + "nop;"
- + "lui $t2, 0xA470;"
- + "sll $s2, $s2, 0x13;"
- + "lui $t1, 0x0006;"
- + "ori $t1, $t1, 0x3634;"
- + "or $t1, $t1, $s2;"
- + "sw $t1, 0x0010($t2);" /* RI_REFRESH_REG */
- + "lw $t1, 0x0010($t2);" /* RI_REFRESH_REG */
- + "lui $t0, 0xA000;"
- + "ori $t0, $t0, 0x03F0;"
- + "lui $t1, 0x0FFF;"
- + "ori $t1, $t1, 0xFFFF;"
- + "and $s6, $s6, $t1;"
- + "sw $s6, 0x0000($t0);"
- + "or $sp, $s8, $zero;"
- + "addiu $sp, $sp, 0x0048;"
- + "lw $s3, 0x0000($sp);"
- + "lw $s4, 0x0004($sp);"
- + "lw $s5, 0x0008($sp);"
- + "lw $s6, 0x000C($sp);"
- + "lw $s7, 0x0010($sp);"
- + "addiu $sp, $sp, 0x0018;"
- +#endif
- +
- +#if 1
- + /* A4000438 */
- + /* invalidate cache */
- + "lui $t0, 0x8000;"
- + "addiu $t0, $t0, 0x0000;"
- + "addiu $t1, $t0, 0x4000;"
- + "addiu $t1, $t1, 0xFFE0;"
- + "mtc0 $zero, $28;"
- + "mtc0 $zero, $29;"
- + "cache 0x08, 0x0000($t0);"
- + "sltu $at, $t0, $t1;"
- + "bnez $at, . - 0x0008;"
- + "addiu $t0, $t0, 0x0020;"
- + "lui $t0, 0x8000;"
- + "addiu $t0, 0x0000;"
- + "addiu $t1, $t0, 0x2000;"
- + "addiu $t1, $t1, 0xFFF0;"
- + "cache 0x09, 0x0000($t0);"
- + "sltu $at, $t0, $t1;"
- + "bnez $at, . - 0x0008;"
- + "addiu $t0, $t0, 0x0010;"
- + "beq $zero, $zero, . + 0x0050;"
- + "nop;"
- + /* A4000488 */
- + "lui $t0, 0x8000;"
- + "addiu $t0, $t0, 0x0000;"
- + "addiu $t1, $t0, 0x4000;"
- + "addiu $t1, $t1, 0xFFE0;"
- + "mtc0 $zero, $28;"
- + "mtc0 $zero, $29;"
- + "cache 0x08, 0x0000($t0);"
- + "sltu $at, $t0, $t1;"
- + "bnez $at, . - 0x0008;"
- + "addiu $t0, $t0, 0x0020;"
- + "lui $t0, 0x8000;"
- + "addiu $t0, 0x0000;"
- + "addiu $t1, $t0, 0x2000;"
- + "addiu $t1, $t1, 0xFFF0;"
- + "cache 0x01, 0x0000($t0);"
- + "sltu $at, $t0, $t1;"
- + "bnez $at, . - 0x0008;"
- + "addiu $t0, $t0, 0x0010;"
- +#endif
- +
- +#if 1
- + /* A40004D0 */
- + /* start rsp */
- + "addiu $t2, $zero, 0x00CE;"
- + "lui $at, 0xA404;"
- + "sw $t2, 0x0010($at);"
- + "lui $t2, 0xB000;"
- + "addiu $t2, $t2, 0x0000;"
- + "lui $t3, 0xFFF0;"
- + "lui $t1, 0x0010;"
- + "and $t2, $t2, $t3;"
- + "lui $t0, 0xB000;"
- + "addiu $t1, $t1, 0xFFFF;"
- + "lui $t3, 0xB000;"
- + "addiu $t0, $t0, 0x0554;"
- + "addiu $t3, $t3, 0x0888;"
- + "and $t0, $t0, $t1;"
- + "and $t3, $t3, $t1;"
- + "lui $at, 0xA408;"
- + "lui $t1, 0xA000;"
- + "sw $zero, 0x0000($at);"
- + "or $t0, $t0, $t2;"
- + "or $t3, $t3, $t2;"
- + "addiu $t1, $t1, 0x0004;"
- + "lw $t5, 0x0000($t0);"
- + "addiu $t0, $t0, 0x0004;"
- + "sltu $at, $t0, $t3;"
- + "addiu $t1, $t1, 0x0004;"
- + "bnez $at, . - 0x0010;"
- + "sw $t5, -0x0004($t1);"
- +#endif
- +
- +#if 0
- + /* jump to final stage of ipl */
- + "lui $t4, 0x8000;"
- + "addiu $t2, $zero, 0x00AD;"
- + "lui $at, 0xA404;"
- + "addiu $t4, $t4, 0x0004;"
- + "jr $t4;"
- + "sw $t2, 0x0010($at);"
- +#elif 1
- + /* jump to k0 */
- + "addiu $t2, $zero, 0x00AD;"
- + "lui $at, 0xA404;"
- + "sw $t2, 0x0010($at);"
- + "la $t0, . + 0x0024;"
- + "lui $t1, 0x8000;"
- + "addiu $t1, $t1, 0xFFFF;"
- + "lui $t2, 0x8000;"
- + "addiu $t2, $t2, 0x0000;"
- + "and $t0, $t0, $t1;"
- + "or $t0, $t0, $t2;"
- + "jr $t0;"
- + "nop;"
- +#endif
- +
- + /* 80000004 */
- + /* dma rom to ram */
- + "lui $t3, 0xB000;"
- + "lw $t1, 0x0008($t3);"
- + "lui $t2, 0x1FFF;"
- + "ori $t2, $t2, 0xFFFF;"
- + "lui $at, 0xA460;"
- + "and $t1, $t1, $t2;"
- + "sw $t1, 0x0000($at);"
- + "lui $t0, 0xA460;"
- + "lw $t0, 0x0010($t0);"
- + "andi $t0, $t0, 0x0002;"
- + "bnel $t0, $zero, . - 0x0008;"
- + "lui $t0, 0xA460;"
- + "addiu $t0, $zero, 0x1000;"
- + "add $t0, $t0, $t3;"
- + "and $t0, $t0, $t2;"
- + "lui $at, 0xA460;"
- + "sw $t0, 0x0004($at);"
- + "lui $t2, 0x0010;"
- + "addiu $t2, $t2, 0xFFFF;"
- + "lui $at, 0xA460;"
- + "sw $t2, 0x000C($at);"
- + /* wait for dma to complete */
- + ".rept 0x10;"
- + "nop;"
- + ".endr;"
- + "lui $t3, 0xA460;"
- + "lw $t3, 0x0010($t3);"
- + "andi $t3, $t3, 0x0001;"
- + "bnez $t3, . - 0x4C;"
- + "nop;"
- +
- + /* clear sp semaphore */
- + "lui $at, 0xA404;"
- + "sw $zero, 0x001C($at);"
- +
- +#if 1
- + /* 800000B4 */
- + /* compute checksum */
- + "lui $t3, 0xB000;"
- + "lw $a0, 0x0008($t3);"
- + "or $a1, $s6, $zero;"
- + "lui $at, 0x5D58;"
- + "ori $at, 0x8B65;"
- + "multu $a1, $at;"
- + "addiu $sp, $sp, 0xFFE0;"
- + "sw $ra, 0x001C($sp);"
- + "sw $s0, 0x0014($sp);"
- + "lui $s6, 0xA000;"
- + "addiu $s6, $s6, 0x0200;"
- + "lui $ra, 0x0010;"
- + "or $v1, $zero, $zero;"
- + "or $t0, $zero, $zero;"
- + "or $t1, $a0, $zero;"
- + "mflo $v0;"
- + "addiu $v0, $v0, 0x0001;"
- + "or $a3, $v0, $zero;"
- + "or $t2, $v0, $zero;"
- + "or $t3, $v0, $zero;"
- + "or $s0, $v0, $zero;"
- + "or $a2, $v0, $zero;"
- + "or $t4, $v0, $zero;"
- + "addiu $t5, $zero, 0x0020;"
- + "lw $v0, 0x0000($t1);"
- + "addu $v1, $a3, $v0;"
- + "sltu $at, $v1, $a3;"
- + "beq $at, $zero, . + 0x000C;"
- + "or $a1, $v1, $zero;"
- + "addiu $t2, $t2, 0x0001;"
- + "andi $v1, $v0, 0x001F;"
- + "subu $t7, $t5, $v1;"
- + "srlv $t8, $v0, $t7;"
- + "sllv $t6, $v0, $v1;"
- + "or $a0, $t6, $t8;"
- + "sltu $at, $a2, $v0;"
- + "or $a3, $a1, $zero;"
- + "xor $t3, $t3, $v0;"
- + "beq $at, $zero, . + 0x0014;"
- + "addu $s0, $s0, $a0;"
- + "xor $t9, $a3, $v0;"
- + "beq $zero, $zero, . + 0x000C;"
- + "xor $a2, $t9, $a2;"
- + "xor $a2, $a2, $a0;"
- + "lw $t7, 0x0000($s6);"
- + "addiu $t0, $t0, 0x0004;"
- + "addiu $s6, $s6, 0x0004;"
- + "xor $t7, $v0, $t7;"
- + "addu $t4, $t7, $t4;"
- + "lui $t7, 0xA000;"
- + "ori $t7, $t7, 0x02FF;"
- + "addiu $t1, $t1, 0x0004;"
- + "bne $t0, $ra, . - 0x0070;"
- + "and $s6, $s6, $t7;"
- + "xor $t6, $a3, $t2;"
- + "xor $a3, $t6, $t3;"
- +#else
- + /* spin instead */
- + "lui $t0, 0x0001;"
- + "bne $t0, $zero, .;"
- + "addiu $t0, $t0, 0xFFFF;"
- +#endif
- +
- + /* 80000194 */
- + /* halt rsp */
- + "lui $t3, 0x00AA;"
- + "ori $t3, 0xAAAE;"
- + "lui $at, 0xA404;"
- + "sw $t3, 0x0010($at);"
- +
- + /* set mi intr mask (clear all) */
- + "lui $at, 0xA430;"
- + "addiu $t0, $zero, 0x0555;"
- + "sw $t0, 0x000C($at);"
- + /* clear si interrupt */
- + "lui $at, 0xA480;"
- + "sw $zero, 0x0018($at);"
- + /* clear ai interrupt */
- + "lui $at, 0xA450;"
- + "sw $zero, 0x000C($at);"
- + /* clear dp interrupt */
- + "lui $at, 0xA430;"
- + "addiu $t1, $zero, 0x0800;"
- + "sw $t1, 0x0000($at);"
- + /* clear pi interrupt */
- + "addiu $t1, $zero, 0x0002;"
- + "lui $at, 0xA460;"
- + "sw $t1, 0x0010($at);"
- +
- + /* save startup info */
- + "lui $t0, 0xA000;"
- + "ori $t0, $t0, 0x0300;"
- + "xor $t8, $s0, $a2;" /* checksum code */
- + "addiu $t1, $zero, 0x17D9;"
- + "xor $s0, $t8, $t4;" /* checksum code */
- + "sw $t1, 0x0010($t0);"
- + "sw $s4, 0x0000($t0);"
- + "sw $s3, 0x0004($t0);"
- + "sw $s5, 0x000C($t0);"
- + "beq $s3, $zero, . + 0x0014;" /* check reset type */
- + "sw $s7, 0x0014($t0);"
- + "lui $t1, 0xA600;"
- + "beq $zero, $zero, . + 0x0010;"
- + "addiu $t1, 0x0000;"
- + "lui $t1, 0xB000;"
- + "addiu $t1, $t1, 0x0000;"
- + "sw $t1, 0x0008($t0);"
- + "lw $t1, 0x00F0($t0);"
- + "lui $t3, 0xB000;"
- + "sw $t1, 0x0018($t0);"
- +
- +#if 1
- + /* check checksum */
- + "lw $t0, 0x0010($t3);"
- + "bne $a3, $t0, . + 0x001C;"
- + "nop;"
- + "lw $t0, 0x0014($t3);"
- + "bne $s0, $t0, . + 0x0010;"
- + "nop;"
- + "bgezal $zero, . + 0x0010;"
- + "nop;"
- + "bgezal $zero, .;"
- + "nop;"
- +#endif
- +
- + /* clear sp mem */
- + "lui $t0, 0xA400;"
- + "addiu $t0, $t0, 0x0000;"
- + "lw $s0, 0x0014($sp);" /* checksum code */
- + "lw $ra, 0x001C($sp);" /* checksum code */
- + "addiu $sp, $sp, 0x0020;" /* checksum code */
- + "addi $t1, $t0, 0x2000;"
- + "addiu $t0, $t0, 0x0004;"
- + "bne $t0, $t1, . - 0x0004;"
- + "sw $t1, -0x0004($t0);"
- + /* jump to game code */
- + "lui $t3, 0xB000;"
- +#if 0
- + "lw $t1, 0x0008($t3);"
- +#else
- + "lui $t1, 0x8040;"
- + "addiu $t1, $t1, 0x0000;"
- +#endif
- + "jr $t1;"
- + "nop;"
- + ".set pop;");
- +#endif
- }
- void zu_void(void)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement