error.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* $Id$
  2. * MegaZeux
  3. *
  4. * Copyright (C) 1996 Greg Janson
  5. * Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. // Error code
  22. #include "helpsys.h"
  23. #include "error.h"
  24. #include "window.h"
  25. #include "graphics.h"
  26. #include "getkey.h"
  27. #include "string.h"
  28. #include <setjmp.h>
  29. #include "error.h"
  30. #include <stdlib.h>
  31. #include "palette.h"
  32. #include <stdio.h>
  33. #include "ems.h"
  34. #include <alloc.h>
  35. #include <conio.h>
  36. //Defined and set in MAIN.CPP
  37. extern jmp_buf exit_jump;//Used in error function and nowhere else
  38. //Call for an error OR a warning. Type=0 for a warning, 1 for a recoverable
  39. //error, 2 for a fatal error. Options are (bits set in options and returned
  40. //as action) FAIL=1, RETRY=2, EXIT TO DOS=4, OK=8, HELP=16 (OK is for usually
  41. //only for warnings) Type = 3 for a critical error
  42. int error(char far *string,char type,char options,int segment,
  43. unsigned int code) {
  44. int t1=9,ret=0,fad=is_faded();;
  45. char temp[5];
  46. char old_help=allow_help;
  47. //Window
  48. set_context(code>>8);
  49. m_hide();
  50. save_screen(segment);
  51. if(fad) {
  52. clear_screen(1824,segment);
  53. insta_fadein();
  54. }
  55. draw_window_box(1,10,78,14,segment,76,64,72);
  56. //Add title and error name
  57. if(type==0) write_string(" WARNING: ",35,10,78,segment);
  58. else if(type==1) write_string(" ERROR: ",36,10,78,segment);
  59. else if(type==2) write_string(" FATAL ERROR: ",33,10,78,segment);
  60. else if(type==3) write_string(" CRITICAL ERROR: ",32,10,78,segment);
  61. write_string(string,40-(str_len(string)>>1),11,79,segment);
  62. //Add options
  63. write_string("Press",4,13,78,segment);
  64. if(options&1) {
  65. write_string(", F for Fail",t1,13,78,segment);
  66. t1+=12;
  67. }
  68. if(options&2) {
  69. write_string(", R to Retry",t1,13,78,segment);
  70. t1+=12;
  71. }
  72. if(options&4) {
  73. write_string(", E to Exit to Dos",t1,13,78,segment);
  74. t1+=18;
  75. }
  76. if(options&8) {
  77. write_string(", O for OK",t1,13,78,segment);
  78. t1+=10;
  79. }
  80. if((options&16)&&(allow_help==1)) {
  81. write_string(", F1 for Help",t1,13,78,segment);
  82. t1+=13;
  83. }
  84. else allow_help=0;
  85. draw_char('.',78,t1,13,segment);
  86. draw_char(':',78,9,13,segment);
  87. //Add code if not 0
  88. if(code!=0) {
  89. write_string(" Debug code:0000h ",30,14,64,segment);
  90. itoa(code,temp,16);
  91. write_string(temp,46-str_len(temp),14,64,segment);
  92. }
  93. //Get key
  94. do {
  95. t1=getkey();
  96. if((t1>='a')&&(t1<='z')) t1-=32;
  97. //Process
  98. switch(t1) {
  99. case 'F':
  100. fail:
  101. if(!(options&1)) break;
  102. ret=1;
  103. break;
  104. case 'R':
  105. retry:
  106. if(!(options&2)) break;
  107. ret=2;
  108. break;
  109. case 'E':
  110. exit:
  111. if(!(options&4)) break;
  112. ret=4;
  113. break;
  114. case 'O':
  115. ok:
  116. if(!(options&8)) break;
  117. ret=8;
  118. break;
  119. case 'H':
  120. if(!(options&16)) break;
  121. //Call help
  122. break;
  123. case 27:
  124. //Escape. Order of options this applies to-
  125. //Fail, Ok, Retry, Exit.
  126. if(options&1) goto fail;
  127. if(options&8) goto ok;
  128. if(options&2) goto retry;
  129. goto exit;
  130. case 13:
  131. //Enter. Order of options this applies to-
  132. //OK, Retry, Fail, Exit.
  133. if(options&8) goto ok;
  134. if(options&2) goto retry;
  135. if(options&1) goto fail;
  136. goto exit;
  137. }
  138. } while(ret==0);
  139. pop_context();
  140. //Restore screen and exit appropriately
  141. if(fad) insta_fadeout();
  142. restore_screen(segment);
  143. m_show();
  144. if(ret==4) //Exit to DOS
  145. longjmp(exit_jump,1);
  146. allow_help=old_help;
  147. return ret;
  148. }
  149. //For SFX data integrity checks
  150. #define NUM_SAM_CACHE 16
  151. extern char far *SamStorage[NUM_SAM_CACHE];
  152. //Filenames
  153. extern char SamNames[NUM_SAM_CACHE][13];
  154. //Number of times played (0=NOT LOADED)
  155. extern int SamPlayed[NUM_SAM_CACHE];
  156. //Channel currently playing on plus one (0=none)
  157. extern char SamChannel[NUM_SAM_CACHE];
  158. extern int SCDoing;
  159. extern char far *SCLoadingName;
  160. //For CEH interface
  161. int error2(char far *string,char type,char options,int segment,
  162. unsigned int code) {
  163. //For data integrity errors in SFX code
  164. if((type==3)&&(string[1]=='a')) {
  165. clrscr();
  166. printf("\nData integrity error in MegaZeux Sound cache system!\n");
  167. printf("Please report the following data to Software Visions:\n");
  168. printf("Action: ");
  169. if(SCDoing&512) printf("load_mod(%s) ",SCLoadingName);
  170. if(SCDoing&1) printf("play_sample ");
  171. if(SCDoing&16) printf("spot_sample ");
  172. if(SCDoing&2) printf("end_sample ");
  173. if(SCDoing&4) printf("jump_mod ");
  174. if(SCDoing&8) printf("volume_mod ");
  175. if(SCDoing&256) printf("_load_sam(%s) ",SCLoadingName);
  176. if(SCDoing&64) printf("_free_sam_cache(0) ");
  177. if(SCDoing&128) printf("_free_sam_cache(1) ");
  178. if(SCDoing&32) printf("_free_sam ");
  179. printf("(%d)\nSFX data:\n",SCDoing);
  180. for(int tmp=0;tmp<NUM_SAM_CACHE;tmp++) {
  181. printf("#%2.2d: %12.12s played %3.3d times. Channel %2.2d. Mem %s\n",
  182. tmp,SamNames[tmp],SamPlayed[tmp],SamChannel[tmp],
  183. SamStorage[tmp]?"ALLOC":"NULL");
  184. }
  185. printf("Memory: %ld\nEMS: %d\n",farcoreleft(),free_mem_EMS());
  186. printf("We will try to work out this problem as soon as possible.\n");
  187. for(;;) ;
  188. }
  189. return error(string,type,options,segment,code);
  190. }