source: thomson/code/C/HxCHost/main.c@ 53c4be3

main
Last change on this file since 53c4be3 was 645c148, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago

Add WIP HxC host software for Thomson computers.
Not working yet because of timing problems...

git-svn-id: svn://localhost/thomson@3 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/* HcX floppy Emulator Host Software for TO8 and MO5
2 * Copyright 2011, Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
3 * Distributed under the terms of the MIT Licence
4 */
5
6#include "pff/pff.h"
7#include "macros.h"
8
9void asm_write();
10
11#if PLATFORM == 5
12 #define DIRECTORY_BUFFER (FILINFO*)0x3000
13#else
14 // Thomson TO8 code
15 #define DIRECTORY_BUFFER (FILINFO*)0xA000
16#endif
17
18unsigned char mark[512 + 16] = "HxCFEDA";
19unsigned char* secbuf = mark+16;
20
21void printhex(unsigned char n)
22{
23 unsigned char a = n >> 4;
24 a += '0';
25 if (a > '9')
26 a += 'A'-10-'0';
27 mon_putc(a)
28 a = (n&0xF) + '0';
29 if (a > '9')
30 a += 'A'-10-'0';
31 mon_putc(a)
32}
33
34// Program exit point (required by compiler...)
35void __attribute__((noreturn)) exit(int a)
36{
37 for(;;);
38}
39
40// Error exit (required by compiler ...)
41void __attribute__((noreturn)) abort()
42{
43 for(;;);
44}
45
46void my_puts(char* s)
47{
48 int j = 0;
49 while(s[j]) mon_putc(s[j++]);
50}
51
52DIR d;
53char path[256] = "";
54char* pathend = path;
55
56void chdir(char* dirname)
57{
58 *(pathend++) = '/';
59
60 do {
61 *(pathend++) = *(dirname++);
62 } while(*(dirname) != 0);
63
64 *(pathend) = 0;
65
66 FRESULT r = pf_opendir(&d, path);
67
68 if (r != 0) my_puts("directory error");
69}
70
71void parent(void)
72{
73 while(*(pathend) != '/' && pathend > path) pathend--;
74
75 *(pathend) = 0;
76 FRESULT r = pf_opendir(&d, path);
77 if (r != 0) my_puts("directory error");
78}
79
80void ls(FILINFO* fp)
81{
82 for(int i = 23; i > 0; --i) {
83 FRESULT r = pf_readdir(&d, fp);
84 if (r != 0) my_puts("File error");
85 if (*fp->fname == 0) break;
86
87 fp ++;
88 }
89}
90
91int main(void)
92{
93 // Detect HxC and print version code
94 seek();
95 read(255, 0, secbuf);
96 my_puts("Firmware ");
97 my_puts(secbuf + 8);
98
99 // Read FAT / Init card
100 FATFS fs;
101 FRESULT r = pf_mount(&fs);
102 if (r != 0) {
103 my_puts("mount error ");
104 printhex(r);
105 exit(0);
106 }
107
108 mon_putc('z');
109
110 // Open root directory
111 pf_opendir(&d, "");
112 mon_putc('y');
113
114 // List files
115 ls(DIRECTORY_BUFFER);
116 mon_putc('x');
117
118 int selected = 0;
119 // Main input loop
120 for(;;) {
121 // TODO : refresh only the changed items ?
122 mon_putc(0x1B) // Select back color
123 mon_putc(0x50) // Black
124 mon_putc(0x0C) // clear screen
125
126 FILINFO* fp = DIRECTORY_BUFFER;
127 int i = 0;
128 while(*fp->fname != 0) {
129 mon_putc(0x1B); // Select back color
130 if (i++ == selected)
131 mon_putc(0x54) // Blue
132 else
133 mon_putc(0x50) // Black
134
135 mon_putc(0x1B); // Select front color
136 if (fp->fattrib & AM_DIR)
137 mon_putc(0x41) // Red
138 else
139 mon_putc(0x47) // white
140
141 my_puts(fp->fname);
142 mon_putc('\n');
143 mon_putc('\r');
144
145 fp++;
146 }
147 if (selected > i) selected = i;
148
149 // Allow the user to select a file
150 do {
151 asm("SWI \t \t;\n"
152 ".fcb \t0x0A\t;GETC\n");
153 } while(KEY == 0);
154
155 switch(KEY)
156 {
157 case 0x08: // UP
158 // select next file
159 if (selected != 0) --selected;
160 // TODO next page ?
161 break;
162
163 case 0x10: // LEFT
164 parent();
165 ls(DIRECTORY_BUFFER);
166 break;
167
168 case 0x18: // DOWN
169 // select previous file
170 if (selected++ >= i) selected = i-1;
171 // TODO previous page ?
172 break;
173
174 case 0x19: // SPACE
175 fp = DIRECTORY_BUFFER;
176 fp += selected; // Point on the current direntry
177
178 if(fp->fattrib & AM_DIR)
179 {
180 // If it's a dir, enter it
181 chdir(fp->fname);
182 selected = 0;
183 ls(DIRECTORY_BUFFER);
184 } else {
185 // TODO file open
186 // If it's HXCSDFE.CFG, enter config mode
187 // If it's a file, load it in HxCSDFE.CFG, then reboot
188 }
189 break;
190
191 default:
192 printhex(KEY);
193 break;
194 }
195 }
196
197 // Leave LBA mode
198 /*
199
200*/
201
202 // Reboot
203 exit(0);
204}
Note: See TracBrowser for help on using the repository browser.