ROM load progress bar
[picodrive.git] / platform / win32 / GenaDrive / Emu.cpp
CommitLineData
cc68a136 1\r
2#include "app.h"\r
3\r
4extern "C" {\r
5struct Pico\r
6{\r
7 unsigned char ram[0x10000]; // 0x00000 scratch ram\r
8 unsigned short vram[0x8000]; // 0x10000\r
9 unsigned char zram[0x2000]; // 0x20000 Z80 ram\r
10 unsigned char ioports[0x10];\r
11 unsigned int pad[0x3c]; // unused\r
12 unsigned short cram[0x40]; // 0x22100\r
13 unsigned short vsram[0x40]; // 0x22180\r
14\r
15 unsigned char *rom; // 0x22200\r
16 unsigned int romsize; // 0x22204\r
17\r
18// struct PicoMisc m;\r
19// struct PicoVideo video;\r
20};\r
21 extern struct Pico Pico;\r
22}\r
23\r
24unsigned short *EmuScreen=NULL;\r
25extern "C" unsigned short *framebuff=NULL;\r
26int EmuWidth=0,EmuHeight=0;\r
27static int frame=0;\r
28static int EmuScan(unsigned int num, void *sdata);\r
29\r
30int EmuInit()\r
31{\r
32 int len=0;\r
33\r
34// PicoOpt=-1;\r
35// PsndRate=44100; PsndLen=DSoundSeg;\r
36\r
37 PicoInit();\r
38\r
39 // Allocate screen:\r
40 EmuWidth=320; EmuHeight=224;\r
41 len=EmuWidth*EmuHeight; len<<=1;\r
42 EmuScreen=(unsigned short *)malloc(len); if (EmuScreen==NULL) return 1;\r
43 framebuff=(unsigned short *)malloc((8+320)*(8+224+8)*2);\r
44 memset(EmuScreen,0,len);\r
45\r
46 PicoScan=EmuScan;\r
47\r
48 return 0;\r
49}\r
50\r
51void EmuExit()\r
52{\r
53 //RomFree();\r
54 free(EmuScreen); EmuScreen=NULL; // Deallocate screen\r
55 free(framebuff);\r
56 EmuWidth=EmuHeight=0;\r
57\r
58 PicoExit();\r
59}\r
60\r
61// Megadrive scanline callback:\r
62static int EmuScan(unsigned int num, void *sdata)\r
63{\r
64 unsigned short *pd=NULL,*end=NULL;\r
65 unsigned short *ps=NULL;\r
66\r
67 if (num>=(unsigned int)EmuHeight) return 0;\r
68\r
69 // Copy scanline to screen buffer:\r
70 pd=EmuScreen+(num<<8)+(num<<6); end=pd+320;\r
71 ps=(unsigned short *)sdata;\r
72\r
73 do { *pd++=(unsigned short)PicoCram(*ps++); } while (pd<end);\r
74 \r
75 return 0;\r
76}\r
77\r
78int EmuFrame()\r
79{\r
80 char map[12]={0,1,2,3,8,9,10,4,11,12,13,14}; // Joypads, format is UDLR BCAS ZYXM\r
81 int a=0,input=0;\r
82 \r
83 // Set Megadrive buttons:\r
84 for (a=0;a<12;a++)\r
85 {\r
86 int m=map[a];\r
87 if (m>=0) if (Inp.button[m]>30) input|=1<<a;\r
88 }\r
89\r
90 PicoPad[0]=input;\r
91\r
92 frame++;\r
93 PsndOut=(short *)DSoundNext; PicoFrame(); PsndOut=NULL;\r
94\r
95 // rendermode2\r
96 if(PicoOpt&0x10) {\r
97 unsigned short *pd=EmuScreen;\r
98 unsigned char *ps=(unsigned char*)framebuff+328*8;\r
99\r
100 unsigned short palHigh[0x40];\r
101 for(int i = 0; i < 0x40; i++)\r
102 palHigh[i]=(unsigned short)PicoCram(Pico.cram[i]);\r
103\r
104 for(int y=0; y < 224; y++) {\r
105 ps+=8;\r
106 for(int x=0; x < 320; x++)\r
107 *pd++=palHigh[*ps++];\r
108 }\r
109 }\r
110\r
111 return 0;\r
112}\r