]> git.sesse.net Git - pistorm/blobdiff - emulator.c
Some PiSCSI file system reloc changes
[pistorm] / emulator.c
index 78ee1a5d18e5e2ad5df3bfbfed94e33bc94a5885..b72c2436168ec30c89a2a77b31139573687bc081 100644 (file)
@@ -126,11 +126,13 @@ void *ipl_task(void *args) {
     value = *(gpio + 13);
 
     if (!(value & (1 << PIN_IPL_ZERO))) {
-      irq = 1;
       old_irq = irq_delay;
       //NOP
-      M68K_END_TIMESLICE;
-      NOP
+      if (!irq) {
+        M68K_END_TIMESLICE;
+        NOP
+        irq = 1;
+      }
       //usleep(0);
     }
     else {
@@ -444,6 +446,9 @@ void sigint_handler(int sig_num) {
 
 int main(int argc, char *argv[]) {
   int g;
+
+  ps_setup_protocol();
+
   //const struct sched_param priority = {99};
 
   // Some command line switch stuffles
@@ -461,8 +466,12 @@ int main(int argc, char *argv[]) {
         printf("%s switch found, but no config filename specified.\n", argv[g]);
       } else {
         g++;
-        cfg = load_config_file(argv[g]);
-        if (cfg) {
+        FILE *chk = fopen(argv[g], "rb");
+        if (chk == NULL) {
+          printf("Config file %s does not exist, please check that you've specified the path correctly.\n", argv[g]);
+        } else {
+          fclose(chk);
+          load_new_config = 1;
           set_pistorm_devcfg_filename(argv[g]);
         }
       }
@@ -480,19 +489,19 @@ int main(int argc, char *argv[]) {
 switch_config:
   srand(clock());
 
+  ps_reset_state_machine();
+  ps_pulse_reset();
+  usleep(1500);
+
   if (load_new_config != 0) {
     uint8_t config_action = load_new_config - 1;
     load_new_config = 0;
-    free_config_file(cfg);
     if (cfg) {
+      free_config_file(cfg);
       free(cfg);
       cfg = NULL;
     }
 
-    /*for(int i = 0; i < 2 * SIZE_MEGA; i++) {
-      write8(i, 0);
-    }*/
-
     switch(config_action) {
       case PICFG_LOAD:
       case PICFG_RELOAD:
@@ -569,43 +578,11 @@ switch_config:
   InitGayle();
 
   signal(SIGINT, sigint_handler);
-  /*setup_io();
-
-  //goto skip_everything;
-
-  // Enable 200MHz CLK output on GPIO4, adjust divider and pll source depending
-  // on pi model
-  printf("Enable 200MHz GPCLK0 on GPIO4\n");
-  gpio_enable_200mhz();
-
-  // reset cpld statemachine first
-
-  write_reg(0x01);
-  usleep(100);
-  usleep(1500);
-  write_reg(0x00);
-  usleep(100);
-
-  // reset amiga and statemachine
-  skip_everything:;
 
-  usleep(1500);
-
-  m68k_init();
-  printf("Setting CPU type to %d.\n", cpu_type);
-  m68k_set_cpu_type(cpu_type);
-  cpu_pulse_reset();
-
-  if (maprom == 1) {
-    m68k_set_reg(M68K_REG_PC, 0xF80002);
-  } else {
-    m68k_set_reg(M68K_REG_PC, 0x0);
-  }*/
-  ps_setup_protocol();
   ps_reset_state_machine();
   ps_pulse_reset();
-
   usleep(1500);
+
   m68k_init();
   printf("Setting CPU type to %d.\n", cpu_type);
   m68k_set_cpu_type(cpu_type);
@@ -936,8 +913,11 @@ void m68k_write_memory_16(unsigned int address, unsigned int value) {
   if (address & 0xFF000000)
     return;
 
-  if (address & 0x01)
-    printf("Unaligned WORD write!\n");
+  if (address & 0x01) {
+    write8(value & 0xFF, address);
+    write8((value >> 8) & 0xFF, address + 1);
+    return;
+  }
 
   write16((uint32_t)address, value);
   return;
@@ -950,8 +930,12 @@ void m68k_write_memory_32(unsigned int address, unsigned int value) {
   if (address & 0xFF000000)
     return;
 
-  if (address & 0x01)
-    printf("Unaligned LONGWORD write!\n");
+  if (address & 0x01) {
+    write8(value & 0xFF, address);
+    write16(htobe16(((value >> 8) & 0xFFFF)), address + 1);
+    write8((value >> 24), address + 3);
+    return;
+  }
 
   write16(address, value >> 16);
   write16(address + 2, value);