From 72f934d1417f8ff29f2a538e151761f4d9fc5cf6 Mon Sep 17 00:00:00 2001 From: TomW Date: Tue, 13 Aug 2013 19:20:28 +0100 Subject: [PATCH] Direct3D video output. Fixed redraw when DirectDraw/Direct3D device is lost. --- src/Makefile.mingw | 4 +- src/device.c | 16 ++ src/device.h | 2 + src/ibm.h | 1 + src/pc.c | 10 +- src/pc.rc | 3 + src/resources.h | 4 + src/sis496.c | 1 + src/sound_adlib.c | 1 + src/sound_adlibgold.c | 1 + src/sound_cms.c | 1 + src/sound_gus.c | 1 + src/sound_pas16.c | 1 + src/sound_sb.c | 7 + src/sound_sn76489.c | 1 + src/sound_wss.c | 1 + src/vid_ati18800.c | 8 + src/vid_ati28800.c | 8 + src/vid_ati_mach64.c | 8 + src/vid_cga.c | 1 + src/vid_cl5429.c | 8 + src/vid_ega.c | 1 + src/vid_et4000.c | 8 + src/vid_et4000w32.c | 8 + src/vid_hercules.c | 1 + src/vid_mda.c | 1 + src/vid_olivetti_m24.c | 1 + src/vid_oti067.c | 8 + src/vid_paradise.c | 9 + src/vid_pc1512.c | 1 + src/vid_pc1640.c | 1 + src/vid_pc200.c | 1 + src/vid_s3.c | 9 + src/vid_s3_virge.c | 8 + src/vid_svga.c | 10 +- src/vid_tandy.c | 1 + src/vid_tvga.c | 9 + src/vid_vga.c | 8 + src/video.h | 2 + src/win-d3d.cc | 414 ++++++++++++++++++++++++++++------------- src/win-d3d.h | 1 + src/win-ddraw.cc | 10 +- src/win.c | 142 ++++++++------ 43 files changed, 539 insertions(+), 203 deletions(-) diff --git a/src/Makefile.mingw b/src/Makefile.mingw index 4774748..10772de 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -18,12 +18,12 @@ OBJ = 386.o 808x.o acer386sx.o ali1429.o amstrad.o cdrom-ioctl.o \ vid_oti067.o vid_paradise.o vid_pc1512.o vid_pc1640.o vid_pc200.o vid_s3.o \ vid_s3_virge.o vid_sdac_ramdac.o vid_stg_ramdac.o vid_svga.o vid_svga_render.o \ vid_tandy.o vid_tkd8001_ramdac.o vid_tvga.o vid_unk_ramdac.o vid_vga.o \ - vid_voodoo.o video.o wd76c10.o win.o win-ddraw.o win-keyboard.o win-midi.o \ + vid_voodoo.o video.o wd76c10.o win.o win-d3d.o win-ddraw.o win-keyboard.o win-midi.o \ win-mouse.o win-timer.o win-video.o x86seg.o x87.o xtide.o pc.res FMOBJ = fmopl.o ymf262.o -LIBS = -mwindows -lwinmm -lalut -lopenal32 -lddraw -ldinput -ldxguid +LIBS = -mwindows -lwinmm -lalut -lopenal32 -lddraw -ldinput -ldxguid -ld3d9 PCem.exe: $(OBJ) $(FMOBJ) $(CC) $(OBJ) $(FMOBJ) -o "PCem.exe" $(LIBS) diff --git a/src/device.c b/src/device.c index 92a7b7e..0e1b6fb 100644 --- a/src/device.c +++ b/src/device.c @@ -58,6 +58,22 @@ void device_speed_changed() } } +void device_force_redraw() +{ + int c; + + for (c = 0; c < 256; c++) + { + if (devices[c] != NULL) + { + if (devices[c]->force_redraw != NULL) + { + devices[c]->force_redraw(device_priv[c]); + } + } + } +} + char *device_add_status_info(char *s, int max_len) { int c; diff --git a/src/device.h b/src/device.h index 237960d..f6e9cad 100644 --- a/src/device.h +++ b/src/device.h @@ -4,6 +4,7 @@ typedef struct device_t void *(*init)(); void (*close)(void *p); void (*speed_changed)(void *p); + void (*force_redraw)(void *p); int (*add_status_info)(char *s, int max_len, void *p); } device_t; @@ -11,4 +12,5 @@ void device_init(); void device_add(device_t *d); void device_close_all(); void device_speed_changed(); +void device_force_redraw(); char *device_add_status_info(char *s, int max_len); diff --git a/src/ibm.h b/src/ibm.h index 66602f8..2d6fb6a 100644 --- a/src/ibm.h +++ b/src/ibm.h @@ -367,6 +367,7 @@ extern uint8_t gdcreg[16]; extern int egareads,egawrites; extern int cga_comp; extern int vid_resize; +extern int vid_api; extern int winsizex,winsizey; extern int chain4; diff --git a/src/pc.c b/src/pc.c index 8a1f4f3..4868e4f 100644 --- a/src/pc.c +++ b/src/pc.c @@ -35,7 +35,7 @@ int frame = 0; int cdrom_enabled; int CPUID; int kb_win; -int vid_resize; +int vid_resize, vid_api; int cycles_lost = 0; @@ -203,7 +203,6 @@ void initpc() atfullspeed=0; device_init(); - pclog("Initvideo\n"); initvideo(); mem_init(); @@ -264,7 +263,6 @@ void resetpchard() mem_resize(); fdc_init(); model_init(); - pclog("Video_init\n"); video_init(); speaker_init(); sound_card_init(sound_card_current); @@ -312,6 +310,8 @@ void runpc() { char s[200]; int done=0; + + startblit(); clockrate = models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed; if (is386) exec386(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed / 100); else if (AT) exec386(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed / 100); @@ -320,6 +320,8 @@ void runpc() keyboard_process(); // checkkeys(); pollmouse(); + endblit(); + framecountx++; framecount++; if (framecountx>=100) @@ -461,6 +463,7 @@ void loadconfig() kb_win = get_config_int(NULL, "kb_win", 0); vid_resize = get_config_int(NULL, "vid_resize", 0); + vid_api = get_config_int(NULL, "vid_api", 0); hdc[0].spt = get_config_int(NULL, "hdc_sectors", 0); hdc[0].hpc = get_config_int(NULL, "hdc_heads", 0); @@ -501,6 +504,7 @@ void saveconfig() set_config_int(NULL, "cdrom_enabled", cdrom_enabled); set_config_int(NULL, "kb_win", kb_win); set_config_int(NULL, "vid_resize", vid_resize); + set_config_int(NULL, "vid_api", vid_api); set_config_int(NULL, "hdc_sectors", hdc[0].spt); set_config_int(NULL, "hdc_heads", hdc[0].hpc); diff --git a/src/pc.rc b/src/pc.rc index a750147..e4d3ff4 100644 --- a/src/pc.rc +++ b/src/pc.rc @@ -27,6 +27,9 @@ BEGIN POPUP "&Video" BEGIN MENUITEM "&Resizeable window",IDM_VID_RESIZE + MENUITEM SEPARATOR + MENUITEM "&DirectDraw", IDM_VID_DDRAW + MENUITEM "Direct&3D", IDM_VID_D3D END END POPUP "&Misc" diff --git a/src/resources.h b/src/resources.h index 4e0ca43..6b58f1e 100644 --- a/src/resources.h +++ b/src/resources.h @@ -11,6 +11,8 @@ #define IDM_KEY_ALLEGRO 40040 #define IDM_KEY_WINDOWS 40041 #define IDM_VID_RESIZE 40050 +#define IDM_VID_DDRAW 40060 +#define IDM_VID_D3D 40061 #define IDM_CDROM_EMPTY 40100 #define IDM_CDROM_REAL 40100 #define IDM_CDROM_DISABLED 40200 @@ -57,3 +59,5 @@ #define IDC_STEXT7 1106 #define IDC_STEXT8 1107 #define IDC_STEXT_DEVICE 1108 + +#define WM_RESETD3D WM_USER diff --git a/src/sis496.c b/src/sis496.c index 09829fb..83fa832 100644 --- a/src/sis496.c +++ b/src/sis496.c @@ -133,5 +133,6 @@ device_t sis496_device = sis496_init, sis496_close, NULL, + NULL, NULL }; diff --git a/src/sound_adlib.c b/src/sound_adlib.c index f55f7b0..31561d3 100644 --- a/src/sound_adlib.c +++ b/src/sound_adlib.c @@ -59,5 +59,6 @@ device_t adlib_device = adlib_init, adlib_close, NULL, + NULL, NULL }; diff --git a/src/sound_adlibgold.c b/src/sound_adlibgold.c index 880def8..7b2ca81 100644 --- a/src/sound_adlibgold.c +++ b/src/sound_adlibgold.c @@ -594,5 +594,6 @@ device_t adgold_device = adgold_init, adgold_close, NULL, + NULL, NULL }; diff --git a/src/sound_cms.c b/src/sound_cms.c index 1019eb6..794e3eb 100644 --- a/src/sound_cms.c +++ b/src/sound_cms.c @@ -176,5 +176,6 @@ device_t cms_device = cms_init, cms_close, NULL, + NULL, NULL }; diff --git a/src/sound_gus.c b/src/sound_gus.c index cd784af..ebca432 100644 --- a/src/sound_gus.c +++ b/src/sound_gus.c @@ -1104,5 +1104,6 @@ device_t gus_device = gus_init, gus_close, gus_speed_changed, + NULL, NULL }; diff --git a/src/sound_pas16.c b/src/sound_pas16.c index ccf350d..59d15c6 100644 --- a/src/sound_pas16.c +++ b/src/sound_pas16.c @@ -750,5 +750,6 @@ device_t pas16_device = pas16_init, pas16_close, NULL, + NULL, NULL }; diff --git a/src/sound_sb.c b/src/sound_sb.c index 506dc60..2d47cc1 100644 --- a/src/sound_sb.c +++ b/src/sound_sb.c @@ -430,6 +430,7 @@ device_t sb_1_device = sb_1_init, sb_close, sb_speed_changed, + NULL, NULL }; device_t sb_15_device = @@ -438,6 +439,7 @@ device_t sb_15_device = sb_15_init, sb_close, sb_speed_changed, + NULL, NULL }; device_t sb_2_device = @@ -446,6 +448,7 @@ device_t sb_2_device = sb_2_init, sb_close, sb_speed_changed, + NULL, NULL }; device_t sb_pro_v1_device = @@ -454,6 +457,7 @@ device_t sb_pro_v1_device = sb_pro_v1_init, sb_close, sb_speed_changed, + NULL, NULL }; device_t sb_pro_v2_device = @@ -462,6 +466,7 @@ device_t sb_pro_v2_device = sb_pro_v2_init, sb_close, sb_speed_changed, + NULL, NULL }; device_t sb_16_device = @@ -470,6 +475,7 @@ device_t sb_16_device = sb_16_init, sb_close, sb_speed_changed, + NULL, NULL }; device_t sb_awe32_device = @@ -478,5 +484,6 @@ device_t sb_awe32_device = sb_awe32_init, sb_close, sb_speed_changed, + NULL, NULL }; diff --git a/src/sound_sn76489.c b/src/sound_sn76489.c index 75f40ff..5ab0dbb 100644 --- a/src/sound_sn76489.c +++ b/src/sound_sn76489.c @@ -195,5 +195,6 @@ device_t sn76489_device = sn76489_init, sn76489_close, NULL, + NULL, NULL }; diff --git a/src/sound_wss.c b/src/sound_wss.c index 7aec4ac..24e2685 100644 --- a/src/sound_wss.c +++ b/src/sound_wss.c @@ -304,5 +304,6 @@ device_t wss_device = wss_init, wss_close, NULL, + NULL, NULL }; diff --git a/src/vid_ati18800.c b/src/vid_ati18800.c index 2ffed2b..a41d0e7 100644 --- a/src/vid_ati18800.c +++ b/src/vid_ati18800.c @@ -152,12 +152,20 @@ void ati18800_speed_changed(void *p) svga_recalctimings(&ati18800->svga); } +void ati18800_force_redraw(void *p) +{ + ati18800_t *ati18800 = (ati18800_t *)p; + + ati18800->svga.fullchange = changeframecount; +} + device_t ati18800_device = { "ATI-18800", ati18800_init, ati18800_close, ati18800_speed_changed, + ati18800_force_redraw, svga_add_status_info }; diff --git a/src/vid_ati28800.c b/src/vid_ati28800.c index 1d547f7..db8f4ae 100644 --- a/src/vid_ati28800.c +++ b/src/vid_ati28800.c @@ -173,11 +173,19 @@ void ati28800_speed_changed(void *p) svga_recalctimings(&ati28800->svga); } +void ati28800_force_redraw(void *p) +{ + ati28800_t *ati28800 = (ati28800_t *)p; + + ati28800->svga.fullchange = changeframecount; +} + device_t ati28800_device = { "ATI-28800", ati28800_init, ati28800_close, ati28800_speed_changed, + ati28800_force_redraw, svga_add_status_info }; diff --git a/src/vid_ati_mach64.c b/src/vid_ati_mach64.c index b5a128e..0f11bf7 100644 --- a/src/vid_ati_mach64.c +++ b/src/vid_ati_mach64.c @@ -1848,11 +1848,19 @@ void mach64_speed_changed(void *p) svga_recalctimings(&mach64->svga); } +void mach64_force_redraw(void *p) +{ + mach64_t *mach64 = (mach64_t *)p; + + mach64->svga.fullchange = changeframecount; +} + device_t mach64gx_device = { "ATI Mach64GX", mach64gx_init, mach64_close, mach64_speed_changed, + mach64_force_redraw, svga_add_status_info }; diff --git a/src/vid_cga.c b/src/vid_cga.c index ceab7fc..c033bb5 100644 --- a/src/vid_cga.c +++ b/src/vid_cga.c @@ -523,5 +523,6 @@ device_t cga_device = cga_standalone_init, cga_close, cga_speed_changed, + NULL, NULL }; diff --git a/src/vid_cl5429.c b/src/vid_cl5429.c index 7e7e60e..e164827 100644 --- a/src/vid_cl5429.c +++ b/src/vid_cl5429.c @@ -834,11 +834,19 @@ void gd5429_speed_changed(void *p) svga_recalctimings(&gd5429->svga); } +void gd5429_force_redraw(void *p) +{ + gd5429_t *gd5429 = (gd5429_t *)p; + + gd5429->svga.fullchange = changeframecount; +} + device_t gd5429_device = { "Cirrus Logic GD5429", gd5429_init, gd5429_close, gd5429_speed_changed, + gd5429_force_redraw, svga_add_status_info }; diff --git a/src/vid_ega.c b/src/vid_ega.c index fab74e2..06a67e4 100644 --- a/src/vid_ega.c +++ b/src/vid_ega.c @@ -840,5 +840,6 @@ device_t ega_device = ega_standalone_init, ega_close, ega_speed_changed, + NULL, NULL }; diff --git a/src/vid_et4000.c b/src/vid_et4000.c index 0a8e903..f449747 100644 --- a/src/vid_et4000.c +++ b/src/vid_et4000.c @@ -146,11 +146,19 @@ void et4000_speed_changed(void *p) svga_recalctimings(&et4000->svga); } +void et4000_force_redraw(void *p) +{ + et4000_t *et4000 = (et4000_t *)p; + + et4000->svga.fullchange = changeframecount; +} + device_t et4000_device = { "Tseng Labs ET4000AX", et4000_init, et4000_close, et4000_speed_changed, + et4000_force_redraw, svga_add_status_info }; diff --git a/src/vid_et4000w32.c b/src/vid_et4000w32.c index fc5aeff..2ae15d5 100644 --- a/src/vid_et4000w32.c +++ b/src/vid_et4000w32.c @@ -965,11 +965,19 @@ void et4000w32p_speed_changed(void *p) svga_recalctimings(&et4000->svga); } +void et4000w32p_force_redraw(void *p) +{ + et4000w32p_t *et4000w32p = (et4000w32p_t *)p; + + et4000w32p->svga.fullchange = changeframecount; +} + device_t et4000w32p_device = { "Tseng Labs ET4000/w32p", et4000w32p_init, et4000w32p_close, et4000w32p_speed_changed, + et4000w32p_force_redraw, svga_add_status_info }; diff --git a/src/vid_hercules.c b/src/vid_hercules.c index f3bc7cf..534feee 100644 --- a/src/vid_hercules.c +++ b/src/vid_hercules.c @@ -354,5 +354,6 @@ device_t hercules_device = hercules_init, hercules_close, hercules_speed_changed, + NULL, NULL }; diff --git a/src/vid_mda.c b/src/vid_mda.c index e8c191a..944c891 100644 --- a/src/vid_mda.c +++ b/src/vid_mda.c @@ -312,5 +312,6 @@ device_t mda_device = mda_init, mda_close, mda_speed_changed, + NULL, NULL }; diff --git a/src/vid_olivetti_m24.c b/src/vid_olivetti_m24.c index 701d5f9..ee9a5ce 100644 --- a/src/vid_olivetti_m24.c +++ b/src/vid_olivetti_m24.c @@ -483,5 +483,6 @@ device_t m24_device = m24_init, m24_close, m24_speed_changed, + NULL, NULL }; diff --git a/src/vid_oti067.c b/src/vid_oti067.c index 53b1202..74dc7e0 100644 --- a/src/vid_oti067.c +++ b/src/vid_oti067.c @@ -141,11 +141,19 @@ void oti067_speed_changed(void *p) svga_recalctimings(&oti067->svga); } +void oti067_force_redraw(void *p) +{ + oti067_t *oti067 = (oti067_t *)p; + + oti067->svga.fullchange = changeframecount; +} + device_t oti067_device = { "Oak OTI-067", oti067_init, oti067_close, oti067_speed_changed, + oti067_force_redraw, svga_add_status_info }; diff --git a/src/vid_paradise.c b/src/vid_paradise.c index 6b942b6..b2f7902 100644 --- a/src/vid_paradise.c +++ b/src/vid_paradise.c @@ -319,12 +319,20 @@ void paradise_speed_changed(void *p) svga_recalctimings(¶dise->svga); } +void paradise_force_redraw(void *p) +{ + paradise_t *paradise = (paradise_t *)p; + + paradise->svga.fullchange = changeframecount; +} + device_t paradise_pvga1a_device = { "Paradise PVGA1A", paradise_pvga1a_init, paradise_close, paradise_speed_changed, + paradise_force_redraw, svga_add_status_info }; device_t paradise_wd90c11_device = @@ -333,5 +341,6 @@ device_t paradise_wd90c11_device = paradise_wd90c11_init, paradise_close, paradise_speed_changed, + paradise_force_redraw, svga_add_status_info }; diff --git a/src/vid_pc1512.c b/src/vid_pc1512.c index 918cd11..6085ca1 100644 --- a/src/vid_pc1512.c +++ b/src/vid_pc1512.c @@ -482,5 +482,6 @@ device_t pc1512_device = pc1512_init, pc1512_close, pc1512_speed_changed, + NULL, NULL }; diff --git a/src/vid_pc1640.c b/src/vid_pc1640.c index b49bda4..3f84f31 100644 --- a/src/vid_pc1640.c +++ b/src/vid_pc1640.c @@ -141,5 +141,6 @@ device_t pc1640_device = pc1640_init, pc1640_close, pc1640_speed_changed, + NULL, NULL }; diff --git a/src/vid_pc200.c b/src/vid_pc200.c index ce478b5..62f5128 100644 --- a/src/vid_pc200.c +++ b/src/vid_pc200.c @@ -135,5 +135,6 @@ device_t pc200_device = pc200_init, pc200_close, pc200_speed_changed, + NULL, NULL }; diff --git a/src/vid_s3.c b/src/vid_s3.c index eae74f9..40ca424 100644 --- a/src/vid_s3.c +++ b/src/vid_s3.c @@ -1605,12 +1605,20 @@ void s3_speed_changed(void *p) svga_recalctimings(&s3->svga); } +void s3_force_redraw(void *p) +{ + s3_t *s3 = (s3_t *)p; + + s3->svga.fullchange = changeframecount; +} + device_t s3_bahamas64_device = { "Paradise Bahamas 64 (S3 Vision864)", s3_bahamas64_init, s3_close, s3_speed_changed, + s3_force_redraw, svga_add_status_info }; @@ -1620,5 +1628,6 @@ device_t s3_9fx_device = s3_9fx_init, s3_close, s3_speed_changed, + s3_force_redraw, svga_add_status_info }; diff --git a/src/vid_s3_virge.c b/src/vid_s3_virge.c index 3ef73b6..adc4998 100644 --- a/src/vid_s3_virge.c +++ b/src/vid_s3_virge.c @@ -490,11 +490,19 @@ void s3_virge_speed_changed(void *p) svga_recalctimings(&virge->svga); } +void s3_virge_force_redraw(void *p) +{ + virge_t *virge = (virge_t *)p; + + virge->svga.fullchange = changeframecount; +} + device_t s3_virge_device = { "Diamond Stealth 3D 2000 (S3 VIRGE)", s3_virge_init, s3_virge_close, s3_virge_speed_changed, + s3_virge_force_redraw, svga_add_status_info }; diff --git a/src/vid_svga.c b/src/vid_svga.c index 3222e74..6b9480a 100644 --- a/src/vid_svga.c +++ b/src/vid_svga.c @@ -1116,16 +1116,15 @@ uint8_t svga_read_linear(uint32_t addr, void *p) void svga_doblit(int y1, int y2, int wx, int wy, svga_t *svga) { + pclog("svga_doblit start\n"); svga->frames++; // pclog("doblit %i %i\n", y1, y2); if (y1 > y2) { - startblit(); video_blit_memtoscreen(32, 0, 0, 0, xsize, ysize); - endblit(); return; } - startblit(); + if ((wx!=xsize || wy!=ysize) && !vid_resize) { xsize=wx; @@ -1141,9 +1140,8 @@ void svga_doblit(int y1, int y2, int wx, int wy, svga_t *svga) ysize = wy + 1; } video_blit_memtoscreen(32, 0, y1, y2, xsize, ysize); - if (readflash) rectfill(screen,winsizex-40,8,winsizex-8,14,0xFFFFFFFF); - endblit(); - + if (readflash) rectfill(screen,winsizex-40,8,winsizex-8,14,0xFFFFFFFF); + pclog("svga_doblit end\n"); } void svga_writew(uint32_t addr, uint16_t val, void *p) diff --git a/src/vid_tandy.c b/src/vid_tandy.c index 84d00c3..264edbf 100644 --- a/src/vid_tandy.c +++ b/src/vid_tandy.c @@ -692,5 +692,6 @@ device_t tandy_device = tandy_init, tandy_close, tandy_speed_changed, + NULL, NULL }; diff --git a/src/vid_tvga.c b/src/vid_tvga.c index b915165..b29d431 100644 --- a/src/vid_tvga.c +++ b/src/vid_tvga.c @@ -420,12 +420,20 @@ void tvga_speed_changed(void *p) svga_recalctimings(&tvga->svga); } +void tvga_force_redraw(void *p) +{ + tvga_t *tvga = (tvga_t *)p; + + tvga->svga.fullchange = changeframecount; +} + device_t tvga8900d_device = { "Trident TVGA 8900D", tvga8900d_init, tvga_close, tvga_speed_changed, + tvga_force_redraw, svga_add_status_info }; device_t tgui9440_device = @@ -434,6 +442,7 @@ device_t tgui9440_device = tgui9440_init, tvga_close, tvga_speed_changed, + tvga_force_redraw, svga_add_status_info }; diff --git a/src/vid_vga.c b/src/vid_vga.c index 3dc0be2..625139d 100644 --- a/src/vid_vga.c +++ b/src/vid_vga.c @@ -106,11 +106,19 @@ void vga_speed_changed(void *p) svga_recalctimings(&vga->svga); } +void vga_force_redraw(void *p) +{ + vga_t *vga = (vga_t *)p; + + vga->svga.fullchange = changeframecount; +} + device_t vga_device = { "VGA", vga_init, vga_close, vga_speed_changed, + vga_force_redraw, svga_add_status_info }; diff --git a/src/video.h b/src/video.h index 4201c54..ae72dd0 100644 --- a/src/video.h +++ b/src/video.h @@ -48,3 +48,5 @@ extern int video_timing_b, video_timing_w, video_timing_l; extern int video_speed; extern int video_res_x, video_res_y, video_bpp; + +extern int vid_resize; diff --git a/src/win-d3d.cc b/src/win-d3d.cc index 77be9fa..a1e92ea 100644 --- a/src/win-d3d.cc +++ b/src/win-d3d.cc @@ -2,127 +2,205 @@ #define BITMAP WINDOWS_BITMAP #include #undef BITMAP +#include "resources.h" #include "win-d3d.h" #include "video.h" extern "C" void fatal(const char *format, ...); extern "C" void pclog(const char *format, ...); +extern "C" void device_force_redraw(); + +void d3d_init_objects(); +void d3d_close_objects(); void d3d_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h); void d3d_blit_memtoscreen_8(int x, int y, int w, int h); -LPDIRECT3D9 d3d = NULL; -LPDIRECT3DDEVICE9 d3ddev = NULL; -LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL; -LPDIRECT3DTEXTURE9 d3dTexture = NULL; -D3DPRESENT_PARAMETERS d3dpp; +static LPDIRECT3D9 d3d = NULL; +static LPDIRECT3DDEVICE9 d3ddev = NULL; +static LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL; +static LPDIRECT3DTEXTURE9 d3dTexture = NULL; +static D3DPRESENT_PARAMETERS d3dpp; -HWND d3d_hwnd; +static HWND d3d_hwnd; struct CUSTOMVERTEX { FLOAT x, y, z, rhw; // from the D3DFVF_XYZRHW flag - DWORD color; // from the D3DFVF_DIFFUSE flag FLOAT tu, tv; }; -CUSTOMVERTEX OurVertices[] = +static PALETTE cgapal= { - { 0.0f, 0.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), 0.0f, 0.0f}, - {2048.0f, 2048.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 1.0f}, - { 0.0f, 2048.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), 0.0f, 1.0f}, + {0,0,0},{0,42,0},{42,0,0},{42,21,0}, + {0,0,0},{0,42,42},{42,0,42},{42,42,42}, + {0,0,0},{21,63,21},{63,21,21},{63,63,21}, + {0,0,0},{21,63,63},{63,21,63},{63,63,63}, - { 0.0f, 0.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), 0.0f, 0.0f}, - {2048.0f, 0.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0.0f}, - {2048.0f, 2048.0f, 1.0f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), 1.0f, 1.0f}, + {0,0,0},{0,0,42},{0,42,0},{0,42,42}, + {42,0,0},{42,0,42},{42,21,00},{42,42,42}, + {21,21,21},{21,21,63},{21,63,21},{21,63,63}, + {63,21,21},{63,21,63},{63,63,21},{63,63,63}, + + {0,0,0},{0,21,0},{0,0,42},{0,42,42}, + {42,0,21},{21,10,21},{42,0,42},{42,0,63}, + {21,21,21},{21,63,21},{42,21,42},{21,63,63}, + {63,0,0},{42,42,0},{63,21,42},{41,41,41}, + + {0,0,0},{0,42,42},{42,0,0},{42,42,42}, + {0,0,0},{0,42,42},{42,0,0},{42,42,42}, + {0,0,0},{0,63,63},{63,0,0},{63,63,63}, + {0,0,0},{0,63,63},{63,0,0},{63,63,63}, +}; + +static uint32_t pal_lookup[256]; + +static CUSTOMVERTEX d3d_verts[] = +{ + { 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f}, + {2048.0f, 2048.0f, 1.0f, 1.0f, 1.0f, 1.0f}, + { 0.0f, 2048.0f, 1.0f, 1.0f, 0.0f, 1.0f}, + + { 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f}, + {2048.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f}, + {2048.0f, 2048.0f, 1.0f, 1.0f, 1.0f, 1.0f}, }; void d3d_init(HWND h) { - VOID* pVoid; // the void pointer - D3DLOCKED_RECT dr; - RECT r; - int x, y; - uint32_t *p; + int c; + HRESULT hr; + for (c = 0; c < 256; c++) + pal_lookup[c] = makecol(cgapal[c].r << 2, cgapal[c].g << 2, cgapal[c].b << 2); + d3d_hwnd = h; d3d = Direct3DCreate9(D3D_SDK_VERSION); memset(&d3dpp, 0, sizeof(d3dpp)); - d3dpp.Flags = D3DPRESENTFLAG_VIDEO; - d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP; - d3dpp.hDeviceWindow = h; - d3dpp.BackBufferCount = 1; - d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; - d3dpp.MultiSampleQuality = 0; - d3dpp.EnableAutoDepthStencil = false; - d3dpp.AutoDepthStencilFormat = D3DFMT_UNKNOWN; - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - d3dpp.Windowed = true; - d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; - d3dpp.BackBufferWidth = 0; - d3dpp.BackBufferHeight = 0; + d3dpp.Flags = 0; + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + d3dpp.hDeviceWindow = h; + d3dpp.BackBufferCount = 1; + d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; + d3dpp.MultiSampleQuality = 0; + d3dpp.EnableAutoDepthStencil = false; + d3dpp.AutoDepthStencilFormat = D3DFMT_UNKNOWN; + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + d3dpp.Windowed = true; + d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; + d3dpp.BackBufferWidth = 0; + d3dpp.BackBufferHeight = 0; - d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, h, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); + hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, h, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); - d3ddev->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); - d3ddev->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); - d3ddev->SetTextureStageState(0,D3DTSS_ALPHAOP, D3DTOP_DISABLE); - - d3ddev->SetSamplerState(0,D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); - d3ddev->SetSamplerState(0,D3DSAMP_MINFILTER, D3DTEXF_LINEAR); - - // create the vertex and store the pointer into v_buffer, which is created globally - d3ddev->CreateVertexBuffer(6*sizeof(CUSTOMVERTEX), - 0, - D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, - D3DPOOL_MANAGED, - &v_buffer, - NULL); - - - v_buffer->Lock(0, 0, (void**)&pVoid, 0); // lock the vertex buffer - memcpy(pVoid, OurVertices, sizeof(OurVertices)); // copy the vertices to the locked buffer - v_buffer->Unlock(); // unlock the vertex buffer - - d3ddev->CreateTexture(2048, 2048, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &d3dTexture, NULL); - - r.top = r.left = 0; - r.bottom = r.right = 2047; - - if (FAILED(d3dTexture->LockRect(0, &dr, &r, 0))) - fatal("LockRect failed\n"); - - for (y = 0; y < 2048; y++) - { - p = (uint32_t *)(dr.pBits + (y * dr.Pitch)); - for (x = 0; x < 2048; x++) - { - p[x] = x + (y << 11); - } - } - - d3dTexture->UnlockRect(0); - -// atexit(d3d_close); + d3d_init_objects(); video_blit_memtoscreen = d3d_blit_memtoscreen; video_blit_memtoscreen_8 = d3d_blit_memtoscreen_8; } +void d3d_close_objects() +{ + if (d3dTexture) + { + d3dTexture->Release(); + d3dTexture = NULL; + } + if (v_buffer) + { + v_buffer->Release(); + v_buffer = NULL; + } +} + +void d3d_init_objects() +{ + HRESULT hr; + D3DLOCKED_RECT dr; + int y; + RECT r; + + hr = d3ddev->CreateVertexBuffer(6*sizeof(CUSTOMVERTEX), + 0, + D3DFVF_XYZRHW | D3DFVF_TEX1, + D3DPOOL_MANAGED, + &v_buffer, + NULL); + + d3ddev->CreateTexture(2048, 2048, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &d3dTexture, NULL); + + r.top = r.left = 0; + r.bottom = r.right = 2047; + + if (FAILED(d3dTexture->LockRect(0, &dr, &r, 0))) + fatal("LockRect failed\n"); + + for (y = 0; y < 2048; y++) + { + uint32_t *p = (uint32_t *)(dr.pBits + (y * dr.Pitch)); + memset(p, 0, 2048 * 4); + } + + d3dTexture->UnlockRect(0); + + d3ddev->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); + d3ddev->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); + d3ddev->SetTextureStageState(0,D3DTSS_ALPHAOP, D3DTOP_DISABLE); + + d3ddev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + d3ddev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); +} + void d3d_resize(int x, int y) { -// d3d_close(); -// d3d_init(d3d_hwnd); - d3dpp.BackBufferWidth = 0; - d3dpp.BackBufferHeight = 0; - d3ddev->Reset(&d3dpp); + HRESULT hr; + + d3dpp.BackBufferWidth = x; + d3dpp.BackBufferHeight = y; + + d3d_reset(); } -void d3d_close() +void d3d_reset() { + HRESULT hr; + + memset(&d3dpp, 0, sizeof(d3dpp)); + + d3dpp.Flags = 0; + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + d3dpp.hDeviceWindow = d3d_hwnd; + d3dpp.BackBufferCount = 1; + d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; + d3dpp.MultiSampleQuality = 0; + d3dpp.EnableAutoDepthStencil = false; + d3dpp.AutoDepthStencilFormat = D3DFMT_UNKNOWN; + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + d3dpp.Windowed = true; + d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; + d3dpp.BackBufferWidth = 0; + d3dpp.BackBufferHeight = 0; + + hr = d3ddev->Reset(&d3dpp); + + if (hr == D3DERR_DEVICELOST) + return; + + d3ddev->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_SELECTARG1); + d3ddev->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE); + d3ddev->SetTextureStageState(0,D3DTSS_ALPHAOP, D3DTOP_DISABLE); + + d3ddev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + d3ddev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + + device_force_redraw(); +} + +void d3d_close() +{ if (d3dTexture) { d3dTexture->Release(); @@ -147,79 +225,155 @@ void d3d_close() void d3d_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) { + HRESULT hr = D3D_OK; VOID* pVoid; - float xmax, ymax; D3DLOCKED_RECT dr; RECT r; uint32_t *p, *src; int yy; - xmax = (float)w / 2048.0; - ymax = (float)h / 2048.0; - - OurVertices[1].tu = OurVertices[4].tu = OurVertices[5].tu = xmax; - OurVertices[1].tv = OurVertices[2].tv = OurVertices[5].tv = ymax; + d3d_verts[0].tu = d3d_verts[2].tu = d3d_verts[3].tu = 0;//0.5 / 2048.0; + d3d_verts[0].tv = d3d_verts[3].tv = d3d_verts[4].tv = 0;//0.5 / 2048.0; + d3d_verts[1].tu = d3d_verts[4].tu = d3d_verts[5].tu = (float)w / 2048.0; + d3d_verts[1].tv = d3d_verts[2].tv = d3d_verts[5].tv = (float)h / 2048.0; GetClientRect(d3d_hwnd, &r); - OurVertices[1].x = OurVertices[4].x = OurVertices[5].x = r.right - r.left; - OurVertices[1].y = OurVertices[2].y = OurVertices[5].y = r.bottom - r.top; - - //pclog("Window %i, %i\n", + d3d_verts[0].x = d3d_verts[2].x = d3d_verts[3].x = -0.5; + d3d_verts[0].y = d3d_verts[3].y = d3d_verts[4].y = -0.5; + d3d_verts[1].x = d3d_verts[4].x = d3d_verts[5].x = (r.right - r.left) - 0.5; + d3d_verts[1].y = d3d_verts[2].y = d3d_verts[5].y = (r.bottom - r.top) - 0.5; - v_buffer->Lock(0, 0, (void**)&pVoid, 0); // lock the vertex buffer - memcpy(pVoid, OurVertices, sizeof(OurVertices)); // copy the vertices to the locked buffer - v_buffer->Unlock(); // unlock the vertex buffer - // clear the window to a deep blue - //d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0); + if (hr == D3D_OK) + hr = v_buffer->Lock(0, 0, (void**)&pVoid, 0); // lock the vertex buffer + if (hr == D3D_OK) + memcpy(pVoid, d3d_verts, sizeof(d3d_verts)); // copy the vertices to the locked buffer + if (hr == D3D_OK) + hr = v_buffer->Unlock(); // unlock the vertex buffer r.top = y1; r.left = 0; r.bottom = y2; r.right = 2047; + + if (hr == D3D_OK) + { + if (FAILED(d3dTexture->LockRect(0, &dr, &r, 0))) + fatal("LockRect failed\n"); - if (FAILED(d3dTexture->LockRect(0, &dr, &r, 0))) - fatal("LockRect failed\n"); + for (yy = y1; yy < y2; yy++) + memcpy(dr.pBits + ((yy - y1) * dr.Pitch), &(((uint32_t *)buffer32->line[yy + y])[x]), w * 4); + + d3dTexture->UnlockRect(0); + } + + if (hr == D3D_OK) + hr = d3ddev->BeginScene(); + + if (hr == D3D_OK) + { + if (hr == D3D_OK) + hr = d3ddev->SetTexture(0, d3dTexture); + + if (hr == D3D_OK) + hr = d3ddev->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1); + + if (hr == D3D_OK) + hr = d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX)); + + if (hr == D3D_OK) + hr = d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); + + if (hr == D3D_OK) + hr = d3ddev->SetTexture(0, NULL); + + if (hr == D3D_OK) + hr = d3ddev->EndScene(); + } + + if (hr == D3D_OK) + hr = d3ddev->Present(NULL, NULL, d3d_hwnd, NULL); - for (yy = y1; yy < y2; yy++) - memcpy(dr.pBits + (yy * dr.Pitch), &(((uint32_t *)buffer32->line[y + yy])[x]), w * 4); - - d3dTexture->UnlockRect(0); - - -// d3dpp.BackBufferWidth = r.right - r.left; -// d3dpp.BackBufferHeight = r.bottom - r.top; - -// d3ddev->Reset(&d3dpp); - - d3ddev->BeginScene(); // begins the 3D scene - - d3ddev->SetTexture( 0, d3dTexture ); - // select which vertex format we are using - d3ddev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1); - - // select the vertex buffer to display - d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX)); - - // copy the vertex buffer to the back buffer - d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); - - d3ddev->SetTexture( 0, NULL ); - - d3ddev->EndScene(); // ends the 3D scene - - d3ddev->Present(NULL, NULL, d3d_hwnd, NULL); // displays the created frame + if (hr == D3DERR_DEVICELOST || hr == D3DERR_INVALIDCALL) + PostMessage(d3d_hwnd, WM_RESETD3D, 0, 0); } void d3d_blit_memtoscreen_8(int x, int y, int w, int h) { - // clear the window to a deep blue - d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0); + VOID* pVoid; + D3DLOCKED_RECT dr; + RECT r; + uint32_t *p, *src; + int yy, xx; + HRESULT hr = D3D_OK; - d3ddev->BeginScene(); // begins the 3D scene + d3d_verts[0].tu = d3d_verts[2].tu = d3d_verts[3].tu = 0;//0.5 / 2048.0; + d3d_verts[0].tv = d3d_verts[3].tv = d3d_verts[4].tv = 0;//0.5 / 2048.0; + d3d_verts[1].tu = d3d_verts[4].tu = d3d_verts[5].tu = (float)w / 2048.0; + d3d_verts[1].tv = d3d_verts[2].tv = d3d_verts[5].tv = (float)h / 2048.0; - // do 3D rendering on the back buffer here + GetClientRect(d3d_hwnd, &r); + d3d_verts[0].x = d3d_verts[2].x = d3d_verts[3].x = -0.5; + d3d_verts[0].y = d3d_verts[3].y = d3d_verts[4].y = -0.5; + d3d_verts[1].x = d3d_verts[4].x = d3d_verts[5].x = (r.right - r.left) - 0.5; + d3d_verts[1].y = d3d_verts[2].y = d3d_verts[5].y = (r.bottom - r.top) - 0.5; - d3ddev->EndScene(); // ends the 3D scene + if (hr == D3D_OK) + hr = v_buffer->Lock(0, 0, (void**)&pVoid, 0); // lock the vertex buffer + if (hr == D3D_OK) + memcpy(pVoid, d3d_verts, sizeof(d3d_verts)); // copy the vertices to the locked buffer + if (hr == D3D_OK) + hr = v_buffer->Unlock(); // unlock the vertex buffer - d3ddev->Present(NULL, NULL, NULL, NULL); // displays the created frame + r.top = 0; + r.left = 0; + r.bottom = h; + r.right = 2047; + + if (hr == D3D_OK) + { + if (FAILED(d3dTexture->LockRect(0, &dr, &r, 0))) + fatal("LockRect failed\n"); + + for (yy = 0; yy < h; yy++) + { + uint32_t *p = (uint32_t *)(dr.pBits + (yy * dr.Pitch)); + if ((y + yy) >= 0 && (y + yy) < buffer->h) + { + for (xx = 0; xx < w; xx++) + p[xx] = pal_lookup[buffer->line[y + yy][x + xx]]; + } + } + + d3dTexture->UnlockRect(0); + } + + if (hr == D3D_OK) + hr = d3ddev->BeginScene(); + + if (hr == D3D_OK) + { + if (hr == D3D_OK) + hr = d3ddev->SetTexture(0, d3dTexture); + + if (hr == D3D_OK) + hr = d3ddev->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1); + + if (hr == D3D_OK) + hr = d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX)); + + if (hr == D3D_OK) + hr = d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); + + if (hr == D3D_OK) + hr = d3ddev->SetTexture(0, NULL); + + if (hr == D3D_OK) + hr = d3ddev->EndScene(); + } + + if (hr == D3D_OK) + hr = d3ddev->Present(NULL, NULL, d3d_hwnd, NULL); + + if (hr == D3DERR_DEVICELOST || hr == D3DERR_INVALIDCALL) + PostMessage(d3d_hwnd, WM_RESETD3D, 0, 0); } diff --git a/src/win-d3d.h b/src/win-d3d.h index a7c1787..bd90795 100644 --- a/src/win-d3d.h +++ b/src/win-d3d.h @@ -3,6 +3,7 @@ extern "C" { #endif void d3d_init(HWND h); void d3d_close(); + void d3d_reset(); void d3d_resize(int x, int y); #ifdef __cplusplus } diff --git a/src/win-ddraw.cc b/src/win-ddraw.cc index 3790c3f..7719100 100644 --- a/src/win-ddraw.cc +++ b/src/win-ddraw.cc @@ -8,6 +8,8 @@ extern "C" void fatal(const char *format, ...); extern "C" void pclog(const char *format, ...); +extern "C" void device_force_redraw(); + extern "C" void ddraw_init(HWND h); extern "C" void ddraw_close(); extern "C" void ddraw_draw(); @@ -157,7 +159,7 @@ void ddraw_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) { lpdds_back->Restore(); lpdds_back->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - fullchange = changeframecount; + device_force_redraw(); } if (!ddsd.lpSurface) return; for (yy = y1; yy < y2; yy++) @@ -190,7 +192,7 @@ void ddraw_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) { lpdds_back2->Restore(); lpdds_back2->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - fullchange = changeframecount; + device_force_redraw(); } if (!ddsd.lpSurface) return; for (yy = 8; yy < 14; yy++) @@ -229,7 +231,7 @@ void ddraw_blit_memtoscreen_8(int x, int y, int w, int h) { lpdds_back->Restore(); lpdds_back->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - fullchange = changeframecount; + device_force_redraw(); } if (!ddsd.lpSurface) return; for (yy = 0; yy < h; yy++) @@ -270,7 +272,7 @@ void ddraw_blit_memtoscreen_8(int x, int y, int w, int h) { lpdds_back2->Restore(); lpdds_back2->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); - fullchange = changeframecount; + device_force_redraw(); } if (!ddsd.lpSurface) return; for (yy = 8; yy < 14; yy++) diff --git a/src/win.c b/src/win.c index 6a0203b..a3d0080 100644 --- a/src/win.c +++ b/src/win.c @@ -22,9 +22,20 @@ #include "plat-keyboard.h" #include "win-ddraw.h" -//#include "win-d3d.h" +#include "win-d3d.h" //#include "win-opengl.h" +static struct +{ + void (*init)(HWND h); + void (*close)(); + void (*resize)(int x, int y); +} vid_apis[] = +{ + ddraw_init, ddraw_close, NULL, + d3d_init, d3d_close, d3d_resize +}; + #define TIMER_1SEC 1 int winsizex=640,winsizey=480; @@ -75,19 +86,15 @@ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); char szClassName[ ] = "WindowsApp"; HWND ghwnd; +static int win_doresize = 0; + void updatewindowsize(int x, int y) { RECT r; if (vid_resize) return; + winsizex=x; winsizey=y; - GetWindowRect(ghwnd,&r); - MoveWindow(ghwnd,r.left,r.top, - x+(GetSystemMetrics(SM_CXFIXEDFRAME)*2), - y+(GetSystemMetrics(SM_CYFIXEDFRAME)*2)+GetSystemMetrics(SM_CYMENUSIZE)+GetSystemMetrics(SM_CYCAPTION)+1, - TRUE); -// startblit(); -// d3d_resize(x, y); -// endblit(); + win_doresize = 1; } void releasemouse() @@ -153,55 +160,49 @@ void mainthread(LPVOID param) int t = 0; int frames = 0; DWORD old_time, new_time; + mainthreadon=1; // Sleep(500); drawits=0; old_time = GetTickCount(); while (!quited) { -// if (infocus) -// { -/* if (!drawits) + if (updatestatus) + { + updatestatus=0; + if (statusopen) SendMessage(statushwnd,WM_USER,0,0); + } + new_time = GetTickCount(); + drawits += new_time - old_time; + old_time = new_time; + if (drawits > 0 && !pause) + { + drawits-=10; if (drawits>50) drawits=0; + wokeups++; + runpc(); + frames++; + if (frames >= 200 && nvr_dosave) { - while (!drawits) - { - ResetEvent(frameobject); - WaitForSingleObject(frameobject,10); - } - }*/ - if (updatestatus) - { - updatestatus=0; - if (statusopen) SendMessage(statushwnd,WM_USER,0,0); + frames = 0; + nvr_dosave = 0; + savenvr(); } - new_time = GetTickCount(); - drawits += new_time - old_time; - old_time = new_time; - if (drawits > 0 && !pause) - { -// printf("Drawits %i\n",drawits); - drawits-=10; - if (drawits>50) drawits=0; - wokeups++; - startblit(); - runpc(); -// ddraw_draw(); - endblit(); - frames++; - if (frames >= 200 && nvr_dosave) - { - frames = 0; - nvr_dosave = 0; - savenvr(); - } -//#if 0 -//#endif - } - else - { - Sleep(1); - } -// } + } + else + { + Sleep(1); + } + + if (win_doresize) + { + RECT r; + GetWindowRect(ghwnd, &r); + MoveWindow(ghwnd, r.left, r.top, + winsizex + (GetSystemMetrics(SM_CXFIXEDFRAME) * 2), + winsizey + (GetSystemMetrics(SM_CYFIXEDFRAME) * 2) + GetSystemMetrics(SM_CYMENUSIZE) + GetSystemMetrics(SM_CYCAPTION) + 1, + TRUE); + win_doresize = 0; + } } mainthreadon=0; } @@ -300,13 +301,12 @@ int WINAPI WinMain (HINSTANCE hThisInstance, ghwnd=hwnd; - ddraw_init(hwnd); midi_init(); atexit(midi_close); -// d3d_init(hwnd); -// opengl_init(hwnd); initpc(); + + vid_apis[vid_api].init(ghwnd); if (vid_resize) SetWindowLong(hwnd, GWL_STYLE, WS_OVERLAPPEDWINDOW|WS_VISIBLE); else SetWindowLong(hwnd, GWL_STYLE, (WS_OVERLAPPEDWINDOW&~WS_SIZEBOX&~WS_THICKFRAME&~WS_MAXIMIZEBOX)|WS_VISIBLE); @@ -317,7 +317,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, CheckMenuItem(menu, IDM_CDROM_REAL + cdrom_drive, MF_CHECKED); CheckMenuItem(menu, IDM_KEY_ALLEGRO + kb_win, MF_CHECKED); if (vid_resize) CheckMenuItem(menu, IDM_VID_RESIZE, MF_CHECKED); - + CheckMenuItem(menu, IDM_VID_DDRAW + vid_api, MF_CHECKED); // set_display_switch_mode(SWITCH_BACKGROUND); d=romset; @@ -462,6 +462,9 @@ InitializeCriticalSection(&cs); // pclog("Closepc\n"); closepc(); // pclog("dumpregs\n"); + + vid_apis[vid_api].close(); + timeEndPeriod(1); // endsoundthread(); // dumpregs(); @@ -1470,6 +1473,19 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM SetWindowPos(hwnd, 0, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_FRAMECHANGED); saveconfig(); break; + + case IDM_VID_DDRAW: case IDM_VID_D3D: + startblit(); + CheckMenuItem(hmenu, IDM_VID_DDRAW + vid_api, MF_UNCHECKED); + vid_apis[vid_api].close(); + vid_api = LOWORD(wParam) - IDM_VID_DDRAW; + CheckMenuItem(hmenu, IDM_VID_DDRAW + vid_api, MF_CHECKED); + vid_apis[vid_api].init(ghwnd); + endblit(); + saveconfig(); + device_force_redraw(); + break; + case IDM_KEY_ALLEGRO: case IDM_KEY_WINDOWS: CheckMenuItem(hmenu,LOWORD(wParam),MF_CHECKED); CheckMenuItem(hmenu,LOWORD(wParam)^1,MF_UNCHECKED); @@ -1583,14 +1599,24 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM case WM_SIZE: winsizex=lParam&0xFFFF; winsizey=lParam>>16; -// startblit(); -// d3d_resize(winsizex, winsizey); -// endblit(); + + if (vid_apis[vid_api].resize) + { + startblit(); + vid_apis[vid_api].resize(winsizex, winsizey); + endblit(); + } break; case WM_TIMER: if (wParam == TIMER_1SEC) - onesec(); + onesec(); + break; + + case WM_RESETD3D: + startblit(); + d3d_reset(); + endblit(); break; case WM_KEYDOWN: