ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/main_unix.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/main_unix.cpp (file contents):
Revision 1.3 by cebix, 1999-10-19T17:41:35Z vs.
Revision 1.10 by cebix, 2000-01-21T13:47:05Z

# Line 48 | Line 48
48   #include <gtk/gtk.h>
49   #endif
50  
51 < #if ENABLE_DGA
51 > #if ENABLE_XF86_DGA
52   #include <X11/Xlib.h>
53   #include <X11/Xutil.h>
54   #include <X11/extensions/xf86dga.h>
55   #endif
56  
57 + #if ENABLE_MON
58 + #include "mon.h"
59 + #endif
60 +
61 + #ifdef USE_MAPPED_MEMORY
62 + #include <sys/mman.h>
63 + extern char *address_space, *good_address_map;
64 + #endif
65 +
66  
67   // Constants
68   const char ROM_FILE_NAME[] = "ROM";
# Line 87 | Line 96 | static struct sigaction timer_sa;                                      //
96   static timer_t timer;                                                           // 60Hz timer
97   #endif
98  
99 + #if ENABLE_MON
100 + static struct sigaction sigint_sa;                                      // sigaction for SIGINT handler
101 + static void sigint_handler(...);
102 + #endif
103 +
104  
105   // Prototypes
106   static void *xpram_func(void *arg);
# Line 132 | Line 146 | int main(int argc, char **argv)
146          for (int i=1; i<argc; i++) {
147                  if (strcmp(argv[i], "-display") == 0 && ++i < argc)
148                          x_display_name = argv[i];
149 +                else if (strcmp(argv[i], "-break") == 0 && ++i < argc)
150 +                        ROMBreakpoint = strtol(argv[i], NULL, 0);
151 +                else if (strcmp(argv[i], "-rominfo") == 0)
152 +                        PrintROMInfo = true;
153          }
154  
155          // Open display
# Line 143 | Line 161 | int main(int argc, char **argv)
161                  QuitEmulator();
162          }
163  
164 < #if ENABLE_DGA
164 > #if ENABLE_XF86_DGA && !ENABLE_MON
165          // Fork out, so we can return from fullscreen mode when things get ugly
166          XF86DGAForkApp(DefaultScreen(x_display));
167   #endif
# Line 165 | Line 183 | int main(int argc, char **argv)
183                  if (!PrefsEditor())
184                          QuitEmulator();
185  
186 <        // Create area for Mac RAM
186 >        // Read RAM size
187          RAMSize = PrefsFindInt32("ramsize") & 0xfff00000;       // Round down to 1MB boundary
188          if (RAMSize < 1024*1024) {
189                  WarningAlert(GetString(STR_SMALL_RAM_WARN));
190                  RAMSize = 1024*1024;
191          }
174        RAMBaseHost = new uint8[RAMSize];
192  
193 <        // Create area for Mac ROM
193 >        // Create areas for Mac RAM and ROM
194 > #ifdef USE_MAPPED_MEMORY
195 >    int fd = open("/dev/zero", O_RDWR);
196 >    good_address_map = (char *)mmap(NULL, 1<<24, PROT_READ, MAP_PRIVATE, fd, 0);
197 >    address_space = (char *)mmap(NULL, 1<<24, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
198 >    if ((int)address_space < 0 || (int)good_address_map < 0) {
199 >                ErrorAlert(GetString(STR_NOT_ENOUGH_MEMORY_ERR));
200 >                QuitEmulator();
201 >    }
202 >    RAMBaseHost = (uint8 *)mmap(address_space, RAMSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, fd, 0);
203 >    ROMBaseHost = (uint8 *)mmap(address_space + 0x00400000, 0x80000, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED, fd, 0);
204 >    close(fd);
205 >        char *nam = tmpnam(NULL);
206 >    int good_address_fd = open(nam, O_CREAT | O_RDWR, 0600);
207 >        char buffer[4096];
208 >    memset(buffer, 1, sizeof(buffer));
209 >    write(good_address_fd, buffer, sizeof(buffer));
210 >    unlink(nam);
211 >    for (int i=0; i<RAMSize; i+=4096)
212 >        mmap(good_address_map + i, 4096, PROT_READ, MAP_FIXED | MAP_PRIVATE, good_address_fd, 0);
213 >    for (int i=0; i<0x80000; i+=4096)
214 >        mmap(good_address_map + i + 0x00400000, 4096, PROT_READ, MAP_FIXED | MAP_PRIVATE, good_address_fd, 0);
215 > #else
216 >        RAMBaseHost = new uint8[RAMSize];
217          ROMBaseHost = new uint8[0x100000];
218 + #endif
219  
220          // Get rom file path from preferences
221          const char *rom_path = PrefsFindString("rom");
# Line 227 | Line 268 | int main(int argc, char **argv)
268          req.it_value.tv_nsec = 16625000;
269          req.it_interval.tv_sec = 0;
270          req.it_interval.tv_nsec = 16625000;
271 <        if (timer_settime(timer, TIMER_RELTIME, &req, NULL) < 0) {
271 >        if (timer_settime(timer, 0, &req, NULL) < 0) {
272                  printf("FATAL: cannot start timer\n");
273                  QuitEmulator();
274          }
# Line 252 | Line 293 | int main(int argc, char **argv)
293          }
294   #endif
295  
296 + #if ENABLE_MON
297 +        // Setup SIGINT handler to enter mon
298 +        sigemptyset(&sigint_sa.sa_mask);
299 +        sigint_sa.sa_flags = 0;
300 +        sigint_sa.sa_handler = sigint_handler;
301 +        sigaction(SIGINT, &sigint_sa, NULL);
302 + #endif
303 +
304          // Start 68k and jump to ROM boot routine
305          Start680x0();
306  
# Line 326 | Line 375 | void FlushCodeCache(void *start, uint32
375   }
376   #endif
377  
378 +
379 + /*
380 + *  SIGINT handler, enters mon
381 + */
382 +
383 + #if ENABLE_MON
384 + extern void m68k_dumpstate(uaecptr *nextpc);
385 + static void sigint_handler(...)
386 + {
387 +        uaecptr nextpc;
388 +        m68k_dumpstate(&nextpc);
389 +        char *arg[2] = {"rmon", NULL};
390 +        mon(1, arg);
391 +        QuitEmulator();
392 + }
393 + #endif
394 +
395  
396   /*
397   *  Interrupt flags (must be handled atomically!)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines