license stuff
[ppcskel.git] / main.c
1 /*
2         BootMii - a Free Software replacement for the Nintendo/BroadOn bootloader.
3         Requires mini.
4
5 Copyright (C) 2008, 2009        Haxx Enterprises <bushing@gmail.com>
6 Copyright (C) 2009              Andre Heider "dhewg" <dhewg@wiibrew.org>
7 Copyright (C) 2008, 2009        Hector Martin "marcan" <marcan@marcansoft.com>
8 Copyright (C) 2008, 2009        Sven Peter <svenpeter@gmail.com>
9 Copyright (C) 2009              John Kelley <wiidev@kelley.ca>
10
11 # This code is licensed to you under the terms of the GNU GPL, version 2;
12 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
13 */
14
15 #include "bootmii_ppc.h"
16 #include "string.h"
17 #include "ipc.h"
18 #include "mini_ipc.h"
19 #include "nandfs.h"
20 #include "fat.h"
21 #include "malloc.h"
22 #include "diskio.h"
23 #include "printf.h"
24 #include "video_low.h"
25 #include "input.h"
26 #include "console.h"
27 #include "irq.h"
28 #include "usb/core/core.h"
29 #include "usb/drivers/class/hid.h"
30 #include "hollywood.h"
31
32 #define MINIMUM_MINI_VERSION 0x00010001
33
34 otp_t otp;
35 seeprom_t seeprom;
36
37 static void dsp_reset(void)
38 {
39         write16(0x0c00500a, read16(0x0c00500a) & ~0x01f8);
40         write16(0x0c00500a, read16(0x0c00500a) | 0x0010);
41         write16(0x0c005036, 0);
42 }
43
44 static char ascii(char s) {
45   if(s < 0x20) return '.';
46   if(s > 0x7E) return '.';
47   return s;
48 }
49
50 void hexdump(void *d, int len) {
51   u8 *data;
52   int i, off;
53   data = (u8*)d;
54   for (off=0; off<len; off += 16) {
55     printf("%08x  ",off);
56     for(i=0; i<16; i++)
57       if((i+off)>=len) printf("   ");
58       else printf("%02x ",data[off+i]);
59
60     printf(" ");
61     for(i=0; i<16; i++)
62       if((i+off)>=len) printf(" ");
63       else printf("%c",ascii(data[off+i]));
64     printf("\n");
65   }
66 }
67         
68 void testOTP(void)
69 {
70         printf("reading OTP...\n");
71         getotp(&otp);
72         printf("read OTP!\n");
73         printf("OTP:\n");
74         hexdump(&otp, sizeof(otp));
75
76         printf("reading SEEPROM...\n");
77         getseeprom(&seeprom);
78         printf("read SEEPROM!\n");
79         printf("SEEPROM:\n");
80         hexdump(&seeprom, sizeof(seeprom));
81 }
82
83 int main(void)
84 {
85         int vmode = -1;
86         exception_init();
87         dsp_reset();
88
89         irq_initialize();
90         irq_bw_enable(BW_PI_IRQ_RESET);
91         irq_bw_enable(BW_PI_IRQ_HW); //hollywood pic
92         /* external ohci */
93         irq_hw_enable(IRQ_OHCI0);
94         /* internal ohci */
95         //irq_hw_enable(IRQ_OHCI1);
96
97         ipc_initialize();
98         ipc_slowping();
99
100         gecko_init();
101     input_init();
102         init_fb(vmode);
103
104         VIDEO_Init(vmode);
105         VIDEO_SetFrameBuffer(get_xfb());
106         VISetupEncoder();
107
108         u32 version = ipc_getvers();
109         u16 mini_version_major = version >> 16 & 0xFFFF;
110         u16 mini_version_minor = version & 0xFFFF;
111         printf("Mini version: %d.%0d\n", mini_version_major, mini_version_minor);
112
113         if (version < MINIMUM_MINI_VERSION) {
114                 printf("Sorry, this version of MINI (armboot.bin)\n"
115                         "is too old, please update to at least %d.%0d.\n", 
116                         (MINIMUM_MINI_VERSION >> 16), (MINIMUM_MINI_VERSION & 0xFFFF));
117                 for (;;) 
118                         ; // better ideas welcome!
119         }
120
121         /* external ohci */
122         usb_init(OHCI0_REG_BASE);
123
124         /* internal ohci */
125         //usb_init(OHCI1_REG_BASE);
126
127         /* load HID keyboard driver */
128         usb_hidkb_init();
129
130         /* you are welcome to make this nice :) */
131         char str[7];
132         u16 i, j, y=20, x=20;
133         struct kbrep *k;
134
135         while(1) {
136                 memset(str, '\0', 8);
137                 j=0;
138                 k = usb_hidkb_getChars();
139                 for(i=0; k->keys[i]>0; i++) {
140                         if(x>650) {
141                                 x = 20;
142                                 y += 15;
143                         }
144                         if(y>440) {
145                                 y=20;
146                         }
147                         if((k->keys[i] >= 4) && k->keys[i] <= 4+'z'-'a') {
148                                 str[j] = k->keys[i] - 4 + 'a';
149                         } 
150                         else if (k->keys[i] == 0x28) {
151                                 y += 15;
152                                 x = 20;
153                         }
154                         j++;
155                 }
156                 if(j > 0) {
157                         print_str_noscroll(x, y, str);
158                         printf("y: %d\n", y);
159                 }
160                 while(j--) {
161                         x += 13;
162                 }
163         }
164
165         return 0;
166 }
167