-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.c
177 lines (160 loc) · 5.71 KB
/
main.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "main.h"
// main entry point
int main(void) {
/* initialise default settings */
settings.stored_password = 0;
settings.kbd_layout = LAYOUT_UK;
settings.brk_code = KEY_BREAK;
settings.page_width = PAGE_WIDTH;
settings.page_height = PAGE_HEIGHT;
settings.tab_width = TAB_WIDTH;
settings.checksum = hash((const char *) (&settings + sizeof(settings.checksum)), (sizeof(settings) - sizeof(settings.checksum)));
initPlatform();
beep();
int ch;
FRESULT fr = FR_OK;
enable_flags |= FLAG_NO_ECHO;
if(enable_flags & FLAG_VIDEO) {
posX = posY = 0;
fontScale = 3;
drawRect(0, 0, (Hres - 1),
fontScale * (font->header.height + font->header.blankT + font->header.blankB) - 2,
COL_GREY25);
fontFcol = COL_SOLID;
fontBcol = COL_TRANSP;
posX = (Hres - (6 + strlen(PLATFORM_NAME) * fontScale *
(font->header.width + font->header.blankL + font->header.blankR))) / 2;
}
else {
printf("\r");
for(ch = 0; ch < 100; ch++) printf("\n");
}
printf("%s\r\n", PLATFORM_NAME);
if(enable_flags & FLAG_VIDEO) {
fontScale = 1; posX += 4;
fontFcol = COL_SOLID;
fontBcol = COL_NONE;
}
mSec(1000);
if(enable_flags & FLAG_VIDEO) mSec(3000); /* allow time for the monitor to adjust to the video mode */
if(enable_flags & FLAG_USB_PRES) {
printf("\r \rAttaching USB... ");
mSec(500);
ch = 50; // 5 seconds
while((enable_flags & FLAG_USB_PRES) && (enable_flags && FLAG_USB) == 0 && ch--) mSec(100);
printf("\r \r");
}
if(enable_flags & FLAG_VIDEO) {
posX = (Hres - (17 + strlen(AUTHOR) + strlen(SW_VERSION)) * fontScale *
(font->header.width + font->header.blankL + font->header.blankR)) / 2;
}
PRINT_VER_INFO(); printf(" \r");
if((enable_flags & FLAG_VIDEO) == 0 || (enable_flags & FLAG_USB)) printf("\n");
if(RAM_DRV_KB > 0) printf("[ram]");
if(IFS_DRV_KB > 0) printf("[ifs]");
if(enable_flags & FLAG_USB) printf("[usb]");
if(enable_flags & FLAG_SERIAL) printf("[ser]");
if(enable_flags & FLAG_PS2) printf("[kbd]");
if(enable_flags & FLAG_VIDEO) printf("[vid]");
if(enable_flags & FLAG_RTC) printf("[rtc]");
printf("\r\n\n");
#if IFS_DRV_KB > 0
fr = FR_OK;
f_chdrive("IFS:");
fr = f_mount(&FatFs, "IFS:", 1);
if(fr == FR_NO_FILESYSTEM) execute_cmd_fos("init IFS:");
#endif
/* read the stored settings */
fr = FR_OK;
f_chdrive(PWD_FILE);
f_mount(&FatFs, PWD_FILE, 0);
f_chdir(PWD_FILE);
UINT rdwr;
fr = f_open(&File, PWD_FILE, (FA_OPEN_EXISTING | FA_READ));
if(fr == FR_OK) {
ride_settings_t st;
f_read(&File, &st, sizeof(ride_settings_t), &rdwr);
if(fr == FR_OK && rdwr == sizeof(settings)) {
memcpy(&settings, &st, sizeof(ride_settings_t));
}
}
f_close(&File);
if(enable_flags & FLAG_VIDEO) printf("Video RAM: %5lu bytes (%d x %d)\r\n", VidMemSize, Hres, Vres);
printf("System RAM: %5lu bytes\r\n", SysMemSize);
if(enable_flags & FLAG_PS2) {
printf("Kbd layout: ");
switch(settings.kbd_layout) {
case LAYOUT_US: printf("US"); break;
case LAYOUT_UK: printf("UK"); break;
case LAYOUT_DE: printf("DE"); break;
case LAYOUT_FR: printf("FR"); break;
default: printf("unknown"); break;
}
printf("\r\n");
}
printf("\n");
char autorun = 1; /* auto-run flag */
mSec(1000);
printf("<Esc> to cancel autorun... ");
ch = 10; // 1000 milliseconds
while(ch--) {
mSec(100);
if(kbhit() && getchx() == KEY_ESC) autorun = 0; /* <Esc> will cancel automated run */
}
printf("\r \r\n\n");
/* auto-execute file */
if(autorun) {
FILINFO *finfo = NULL;
x_malloc((byte **) &finfo, sizeof(FILINFO));
char xt = 2, *xfn;
while(xt-- && finfo) {
if(xt == 1) xfn = AUTORUN_FILE; /* first check the IFS: autorun file */
else xfn = AUTORUN_FILE_SD; /* alternatively check in SD1: */
if(xfn && *xfn) {
f_chdrive(xfn);
f_mount(&FatFs, xfn, 0);
f_chdir(xfn);
fr = f_stat(xfn, finfo);
if(fr == FR_OK) {
x_free((byte **) &finfo);
strcpy(buffer, xfn);
run_file(buffer);
RIDE_release_memory();
printf("\r\n\n");
break;
}
}
}
if(finfo) x_free((byte **) &finfo);
}
/* login with password */
passw_mode = 1;
while(1) {
ch = edit_line(NULL, 0, 0, hl_keys_RIDE);
if(ch == KEY_ENT) {
printf("\r");
#ifdef BOOTLOADER_APP
if(!strcmp(buffer, "./update")) bootloader(); /* run the bootloader */
#endif
if((settings.stored_password == 0 && *buffer == '\0') ||
(*buffer && hash(buffer, strlen(buffer)) == settings.stored_password)) break;
printf("\r"); /* wrong password at this point */
for(ch = 0; ch < (int) strlen("password: "); ch++) {
mSec(150);
printf(" ");
}
}
}
passw_mode = 0;
/* try to switch to SD1: */
fr = f_chdrive("SD1:");
if(fr == FR_OK) fr = f_mount(&FatFs, "SD1:", 1);
if(fr == FR_OK) fr = f_chdir("/");
if(fr != FR_OK) {
f_chdrive(PWD_FILE);
f_mount(&FatFs, PWD_FILE, 1);
f_chdir(PWD_FILE);
}
while(1) RIDE();
return 0;
}