home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / v9t9 / linux / sources / V9t9 / source / dsr.c < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-19  |  2.6 KB  |  133 lines

  1.  
  2. /*
  3.     DSR rom
  4.  
  5. */
  6.  
  7. #include "v9t9_common.h"
  8. #include "dsr.h"
  9. #include "9900.h"
  10. #include "memory.h"
  11. #include "moduleconfig.h"
  12. #include "config.h"
  13. #include "opcode_callbacks.h"
  14.  
  15. static vmModule *active = NULL;
  16.  
  17. void
  18. dsr_set_active(vmModule * module)
  19. {
  20.     if (!module)
  21.         active = NULL;
  22.     else {
  23.         if (module->type != vmTypeDSR)
  24.             logger(LOG_FATAL | LOG_INTERNAL,
  25.                    "dsr_set_active:  trying to install bogus module");
  26.         active = module;
  27.     }
  28. }
  29.  
  30. void
  31. emulate_dsr(void)
  32. {
  33.     u16         callpc = pc - 2;
  34.     u16            opcode = memory_read_word(callpc);
  35.     u16            crubase = memory_read_word(0x83D0);
  36.  
  37.     if (callpc >= 0x4000 && callpc < 0x6000) {
  38.         u32         base;
  39.  
  40.         /*  Only respond if we have an active module whose
  41.            base matches that which DSRLNK is currently scanning. */
  42.         if (active && active->m.dsr->getcrubase(&base) == vmOk
  43.             && crubase == base) {
  44.             logger(LOG_CPU | LOG_INFO | L_1, "emulate_dsr:  pc = %d [%4X]\n",
  45.                    callpc, opcode);
  46.  
  47.             // on success, return to DSR handler, to return an
  48.             // error or otherwise terminate instead of continuing
  49.             // to scan CRU bases
  50.             if (active->m.dsr->filehandler(opcode - OP_DSR) == vmOk) {
  51.                 pc = register (11);
  52.             }
  53.         }
  54.     }
  55. }
  56.  
  57. int dsr_get_disk_count(void)
  58. {
  59. #ifdef EMU_DISK_DSR
  60.     if (emuDiskDSR.runtimeflags & vmRTInUse)
  61.         return 5;
  62. #endif
  63. #ifdef REAL_DISK_DSR
  64.     if (realDiskDSR.runtimeflags & vmRTInUse)
  65.         return 3;
  66. #endif
  67.     return 0;
  68. }
  69.  
  70. #ifdef REAL_DISK_DSR
  71. int dsr_is_real_disk(int disk)
  72. {
  73.     if (realDiskDSR.runtimeflags & vmRTInUse)
  74. #ifdef EMU_DISK_DSR
  75.         if (emuDiskDSR.runtimeflags & vmRTInUse)
  76.             return disk == 1 || disk == 2;
  77.         else    
  78. #endif
  79.             return disk >= 1 && disk <= 3;
  80.     else
  81.         return 0;
  82. }
  83. #endif
  84.  
  85. #ifdef EMU_DISK_DSR
  86. int dsr_is_emu_disk(int disk)
  87. {
  88.     if (emuDiskDSR.runtimeflags & vmRTInUse)
  89. #ifdef REAL_DISK_DSR
  90.         if (realDiskDSR.runtimeflags & vmRTInUse)
  91.             return disk >= 3 && disk <= 5;
  92.         else
  93. #endif
  94.             return disk >= 1 && disk <= 5;
  95.     else
  96.         return 0;
  97. }
  98. #endif
  99.  
  100. const char *dsr_get_disk_info(int disk)
  101. {
  102. #ifdef REAL_DISK_DSR
  103.     if (dsr_is_real_disk(disk))
  104.         //return OS_NameSpecToString1(&diskname[disk-1]);
  105.         return diskname[disk-1];
  106.     else 
  107. #endif
  108. #ifdef EMU_DISK_DSR
  109.     if (dsr_is_emu_disk(disk))
  110.         return OS_PathSpecToString1(&emudiskpath[disk-1]);
  111.     else
  112. #endif
  113.         return 0L;
  114. }
  115.  
  116. int    dsr_set_disk_info(int disk, const char *path)
  117. {
  118.     char command[1024];
  119. #ifdef REAL_DISK_DSR
  120.     if (dsr_is_real_disk(disk)) {
  121.         snprintf(command, sizeof(command), "DiskImage%d = \"%s\"\n", disk, escape(path,0));
  122.         return command_parse_text(command);
  123.     }
  124. #endif
  125. #ifdef EMU_DISK_DSR
  126.     if (dsr_is_emu_disk(disk)) {
  127.         snprintf(command, sizeof(command), "DSK%dPath = \"%s\"\n", disk, escape(path,0));
  128.         return command_parse_text(command);
  129.     }
  130. #endif
  131.     return 0;
  132. }
  133.