| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- /* run command: load raw binary from FAT floppy to 0x21000 and execute. */
- #include "fat.h"
- #include "fbtext.h"
- #include "io.h"
- #include "run_api.h"
- #include "timer.h"
- #include "vga.h"
- #define PROGRAM_LOAD_ADDR 0x21000
- #define PROGRAM_LOAD_MAX 0x10000
- #define NAME_BUF_SIZE 12
- static void to_8_3(const char *in, unsigned int in_len, char *out)
- {
- unsigned int i, j, dot;
- for (i = 0; i < in_len && in[i] == ' '; i++)
- ;
- dot = i;
- while (dot < in_len && in[dot] != '.' && in[dot] != ' ')
- dot++;
- j = 0;
- while (i < dot && j < 8) {
- out[j++] = (char)(in[i] >= 'a' && in[i] <= 'z' ? in[i] - 32 : in[i]);
- i++;
- }
- while (j < 8)
- out[j++] = ' ';
- if (i < in_len && in[i] == '.')
- i++;
- while (i < in_len && in[i] != ' ' && j < 11) {
- out[j++] = (char)(in[i] >= 'a' && in[i] <= 'z' ? in[i] - 32 : in[i]);
- i++;
- }
- while (j < 11)
- out[j++] = ' ';
- out[11] = '\0';
- }
- void program_run_main(const char *filename)
- {
- char name_8_3[NAME_BUF_SIZE];
- int n;
- if (!filename || !filename[0]) {
- io_putstr("run: usage run <filename>\n");
- return;
- }
- to_8_3(filename, 64, name_8_3);
- n = fat_init();
- if (n == -2) {
- io_putstr("run: disk read error (see above)\n");
- return;
- }
- if (n != 0) {
- io_putstr("run: no FAT filesystem found\n");
- return;
- }
- n = fat_read_file(name_8_3, (void *)PROGRAM_LOAD_ADDR, PROGRAM_LOAD_MAX);
- if (n == -2) {
- io_putstr("run: disk read error (see above)\n");
- return;
- }
- if (n <= 0) {
- io_putstr("run: file not found\n");
- return;
- }
- io_drain_keyboard();
- {
- struct prog_api api = {
- .draw_string_xy = fbtext_draw_string_xy,
- .get_cols = fbtext_get_cols,
- .get_rows = fbtext_get_rows,
- .poll_key = io_poll_key,
- .poll_key_with_hw = io_poll_key_with_hw,
- .get_fb_width = vga_fb_width,
- .get_fb_height = vga_fb_height,
- .clear_rgb = vga_clear_rgb,
- .put_pixel_rgb = vga_put_pixel_rgb,
- .get_ticks_ms = get_ticks_ms,
- };
- *(struct prog_api *)PROGRAM_API_ADDR = api;
- }
- ((void (*)(void))PROGRAM_LOAD_ADDR)();
- }
|