Mercurial > repos > blastem
comparison menu.c @ 866:69a6ec208111
Menu ROM now pulls real file names from the OS rather than using a fake list
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 06 Nov 2015 12:19:39 -0800 |
parents | |
children | 1bab7e01ae98 |
comparison
equal
deleted
inserted
replaced
865:305c85c0b954 | 866:69a6ec208111 |
---|---|
1 #include <stdint.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <stdio.h> | |
5 #include "blastem.h" | |
6 #include "menu.h" | |
7 #include "backend.h" | |
8 #include "util.h" | |
9 | |
10 | |
11 uint16_t menu_read_w(uint32_t address, void * context) | |
12 { | |
13 //This should return the status of the last request with 0 | |
14 //meaning either the request is complete or no request is pending | |
15 //in the current implementation, the operations happen instantly | |
16 //in emulated time so we can always return 0 | |
17 return 0; | |
18 } | |
19 | |
20 void * menu_write_w(uint32_t address, void * context, uint16_t value) | |
21 { | |
22 m68k_context *m68k = context; | |
23 genesis_context *gen = m68k->system; | |
24 menu_context *menu = gen->extra; | |
25 if (!menu) { | |
26 gen->extra = menu = calloc(1, sizeof(menu_context)); | |
27 menu->curpath = strdup(get_home_dir()); | |
28 } | |
29 if (menu->state) { | |
30 uint32_t dst = menu->latch << 16 | value; | |
31 switch (address >> 2) | |
32 { | |
33 case 0: { | |
34 size_t num_entries; | |
35 dir_entry *entries = get_dir_list(menu->curpath, &num_entries); | |
36 for (size_t i = 0; i < num_entries; i++) | |
37 { | |
38 uint8_t *dest = get_native_pointer(dst, (void **)m68k->mem_pointers, &m68k->options->gen); | |
39 if (!dest) { | |
40 break; | |
41 } | |
42 *(dest++) = entries[i].is_dir; | |
43 *(dest++) = 1; | |
44 dst += 2; | |
45 uint8_t term = 0; | |
46 for (char *cpos = entries[i].name; *cpos; cpos++) | |
47 { | |
48 dest[1] = *cpos; | |
49 dest[0] = cpos[1]; | |
50 if (cpos[1]) { | |
51 cpos++; | |
52 } else { | |
53 term = 1; | |
54 } | |
55 dst += 2; | |
56 if (!(dst & 0xFFFF)) { | |
57 //we may have walked off the end of a memory block, get a fresh native pointer | |
58 dest = get_native_pointer(dst, (void **)m68k->mem_pointers, &m68k->options->gen); | |
59 if (!dest) { | |
60 break; | |
61 } | |
62 } else { | |
63 dest += 2; | |
64 } | |
65 } | |
66 if (!term) { | |
67 *(dest++) = 0; | |
68 *dest = 0; | |
69 dst += 2; | |
70 } | |
71 } | |
72 free_dir_list(entries, num_entries); | |
73 break; | |
74 } | |
75 default: | |
76 fprintf(stderr, "WARNING: write to undefined menu port %X\n", address); | |
77 } | |
78 menu->state = 0; | |
79 } else { | |
80 menu->latch = value; | |
81 menu->state = 1; | |
82 } | |
83 | |
84 return context; | |
85 } |