| 1 | #include "app.h"\r |
| 2 | //#include "FileMenu.h"\r |
| 3 | \r |
| 4 | char LoopQuit=0;\r |
| 5 | static FILE *DebugFile=NULL;\r |
| 6 | int LoopMode=0;\r |
| 7 | static void UpdateSound(int len);\r |
| 8 | \r |
| 9 | int LoopInit()\r |
| 10 | {\r |
| 11 | int ret=0;\r |
| 12 | \r |
| 13 | // bits LSb->MSb:\r |
| 14 | // enable_ym2612&dac, enable_sn76496, enable_z80, stereo_sound;\r |
| 15 | // alt_renderer, 6button_gamepad, accurate_timing, accurate_sprites\r |
| 16 | PicoOpt=0xbcc7;\r |
| 17 | PsndRate=44100;\r |
| 18 | \r |
| 19 | // Init Direct3D:\r |
| 20 | ret=DirectInit(); if (ret) { error("DirectX video init failed"); return 1; }\r |
| 21 | InputInit();\r |
| 22 | \r |
| 23 | // Init DirectSound:\r |
| 24 | //DSoundInit();\r |
| 25 | \r |
| 26 | ret=EmuInit(); if (ret) return 1;\r |
| 27 | //FileMenu.init();\r |
| 28 | \r |
| 29 | LoopMode=8;\r |
| 30 | PicoWriteSound = UpdateSound;\r |
| 31 | \r |
| 32 | return 0;\r |
| 33 | }\r |
| 34 | \r |
| 35 | extern "C" char *debugString();\r |
| 36 | \r |
| 37 | void LoopExit()\r |
| 38 | {\r |
| 39 | dprintf(debugString());\r |
| 40 | \r |
| 41 | //FileMenu.exit();\r |
| 42 | EmuExit();\r |
| 43 | DSoundExit(); PsndLen=0;\r |
| 44 | InputExit();\r |
| 45 | DirectExit();\r |
| 46 | \r |
| 47 | if (DebugFile) fclose(DebugFile);\r |
| 48 | DebugFile=NULL;\r |
| 49 | }\r |
| 50 | \r |
| 51 | // ----------------------------------------------------------------\r |
| 52 | \r |
| 53 | static int DoGame()\r |
| 54 | {\r |
| 55 | EmuFrame();\r |
| 56 | \r |
| 57 | if (Inp.held[7]==1) LoopMode=2; // Right thumb = Toggle Menu\r |
| 58 | \r |
| 59 | return 0;\r |
| 60 | }\r |
| 61 | // ----------------------------------------------------------------\r |
| 62 | \r |
| 63 | /*\r |
| 64 | static int MenuUpdate()\r |
| 65 | {\r |
| 66 | int delta=0;\r |
| 67 | \r |
| 68 | if (Inp.repeat[0]) delta-=0x100;\r |
| 69 | if (Inp.repeat[1]) delta+=0x100;\r |
| 70 | \r |
| 71 | if (Inp.button[14]>30) delta-=Inp.button[14]-30;\r |
| 72 | if (Inp.button[15]>30) delta+=Inp.button[15]-30;\r |
| 73 | \r |
| 74 | if (delta) FileMenu.scroll(delta);\r |
| 75 | \r |
| 76 | if (Inp.held[8]==1 || Inp.held[10]==1 || Inp.held[4]==1) // A, X or Start\r |
| 77 | {\r |
| 78 | //RomFree();\r |
| 79 | //FileMenu.getFilePath(RomName);\r |
| 80 | //RomLoad();\r |
| 81 | //LoopMode=8; // Go to game\r |
| 82 | }\r |
| 83 | \r |
| 84 | if (Inp.held[7]==1) LoopMode=8; // Right thumb = Toggle Menu\r |
| 85 | \r |
| 86 | return 0;\r |
| 87 | }\r |
| 88 | \r |
| 89 | static int MenuRender()\r |
| 90 | {\r |
| 91 | WCHAR text[80]={0};\r |
| 92 | wsprintfW(text,L"%.40S v%x.%.3x",AppName,PicoVer>>12,PicoVer&0xfff);\r |
| 93 | FontSetColour(0x60c0ff);\r |
| 94 | FontText(text,64,48);\r |
| 95 | \r |
| 96 | FileMenu.render();\r |
| 97 | \r |
| 98 | return 0;\r |
| 99 | }\r |
| 100 | */\r |
| 101 | \r |
| 102 | // ----------------------------------------------------------------\r |
| 103 | \r |
| 104 | static int ModeUpdate()\r |
| 105 | {\r |
| 106 | if (Inp.held[14] && Inp.held[15] && Inp.held[12]==1) LoopQuit=1; // L+R+black to quit:\r |
| 107 | if (Inp.button[4]>30 && Inp.button[5]>30) LoopQuit=1; // Start and back to quit\r |
| 108 | \r |
| 109 | if (LoopMode==8) { DoGame(); return 0; }\r |
| 110 | \r |
| 111 | // if (DSoundNext) memset(DSoundNext,0,PsndLen<<2);\r |
| 112 | \r |
| 113 | // if (LoopMode==2) { FileMenu.scan(); LoopMode++; return 0; }\r |
| 114 | // if (LoopMode==3) { MenuUpdate(); return 0; }\r |
| 115 | // if (LoopMode==4) { LightCalUpdate(); return 0; }\r |
| 116 | \r |
| 117 | LoopMode=2; // Unknown mode, go to rom menu\r |
| 118 | return 0;\r |
| 119 | }\r |
| 120 | \r |
| 121 | \r |
| 122 | static int ModeRender()\r |
| 123 | {\r |
| 124 | DirectScreen();\r |
| 125 | // if (LoopMode==3) MenuRender();\r |
| 126 | // if (LoopMode==4) LightCalRender();\r |
| 127 | \r |
| 128 | return 0;\r |
| 129 | }\r |
| 130 | \r |
| 131 | static void UpdateSound(int len)\r |
| 132 | {\r |
| 133 | while (DSoundUpdate() > 0) { Sleep(1); }\r |
| 134 | while (DSoundUpdate()== 0) { }\r |
| 135 | }\r |
| 136 | \r |
| 137 | int LoopCode()\r |
| 138 | {\r |
| 139 | \r |
| 140 | // Main loop:\r |
| 141 | while (!LoopQuit)\r |
| 142 | {\r |
| 143 | InputUpdate();\r |
| 144 | \r |
| 145 | DirectClear(0);\r |
| 146 | ModeUpdate();\r |
| 147 | ModeRender();\r |
| 148 | DirectPresent();\r |
| 149 | // UpdateSound();\r |
| 150 | }\r |
| 151 | \r |
| 152 | return 0;\r |
| 153 | }\r |
| 154 | \r |
| 155 | // -------------------------------------------------------------------------------------\r |
| 156 | \r |
| 157 | #if 0\r |
| 158 | extern "C" int dprintf(char *format, ...)\r |
| 159 | {\r |
| 160 | char *name=NULL;\r |
| 161 | va_list val=NULL;\r |
| 162 | \r |
| 163 | #ifdef _XBOX\r |
| 164 | name="d:\\zout.txt";\r |
| 165 | #else\r |
| 166 | name="zout.txt";\r |
| 167 | #endif\r |
| 168 | \r |
| 169 | if (DebugFile==NULL) DebugFile=fopen(name,"wt");\r |
| 170 | if (DebugFile==NULL) return 1;\r |
| 171 | \r |
| 172 | fprintf(DebugFile, "%05i: ", emu_frame);\r |
| 173 | va_start(val,format);\r |
| 174 | vfprintf(DebugFile,format,val);\r |
| 175 | fprintf(DebugFile, "\n");\r |
| 176 | fflush(DebugFile);\r |
| 177 | \r |
| 178 | va_end(val);\r |
| 179 | return 0;\r |
| 180 | }\r |
| 181 | #endif\r |
| 182 | \r |
| 183 | extern "C" int dprintf2(char *format, ...)\r |
| 184 | {\r |
| 185 | char str[512];\r |
| 186 | va_list val=NULL;\r |
| 187 | \r |
| 188 | va_start(val,format);\r |
| 189 | vsprintf(str,format,val);\r |
| 190 | va_end(val);\r |
| 191 | OutputDebugString(str);\r |
| 192 | \r |
| 193 | return 0;\r |
| 194 | }\r |
| 195 | \r |