-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinit.c
85 lines (62 loc) · 2.1 KB
/
init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Copyright (c) 2015 James Laird-Wah
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
#include <iapetus.h>
#include "satiator.h"
#include <string.h>
#include "fade.h"
void set_satiator_rtc(void);
// Reset everything we can before loading the menu.
void sysinit(void) {
int i;
interrupt_set_level_mask(0xF);
for (i = 0; i < 0x80; i++)
bios_set_sh2_interrupt(i, 0);
for (i = 0x40; i < 0x60; i++)
bios_set_scu_interrupt(i, 0);
// Make sure all interrupts have been called
bios_change_scu_interrupt_mask(0, 0);
bios_change_scu_interrupt_mask(0xFFFFFFFF, 0xFFFFFFFF);
vdp_init(RES_320x224);
VDP2_REG_CYCA0L = 0x15ee;
VDP2_REG_CYCA0U = 0x44ee;
vdp_disp_on();
per_init();
// stop the FRT
SH2_REG_TIER = 0;
if (interrupt_get_level_mask() > 0x7)
interrupt_set_level_mask(0x7);
}
uint16_t vdp1_stash[0x40000];
void restore_vdp_mem(void) {
memcpy((void*)VDP1_RAM, vdp1_stash, sizeof(vdp1_stash));
}
extern char _load_start, _load_end, _bss_end, _free_ram_end;
void main_menu(void);
uint32_t boot_arg;
const char *region_string;
void start(uint32_t) __attribute__((section(".start")));
void start(uint32_t arg) {
// the BIOS only reads 0x1000 bytes when we begin. read the
// lot and zero BSS
int nsec = ((&_load_end-&_load_start-1) / 0x800) + 1;
bios_get_mpeg_rom(2, nsec, (u32)&_load_start);
memset(&_load_end, 0, &_free_ram_end - &_load_end);
// move stack pointer to LoRAM because HiRAM will get clobbered if a load fails
asm volatile (
"mov %0, r15"
: : "r" (&_free_ram_end)
);
boot_arg = arg;
// copy VDP1 RAM first; some games depend on memory they don't initialise
memcpy(vdp1_stash, (void*)VDP1_RAM, sizeof(vdp1_stash));
fadeout(0x10);
// enable Satiator API
s_mode(s_api);
set_satiator_rtc(); // calls SMPC
region_string = get_region_string(); // calls SMPC
sysinit();
main_menu(); // does not return
}