Previous Thread
Next Thread
Print Thread
Page 5 of 6 1 2 3 4 5 6
#112609 - 02/13/18 05:54 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: Apr 2013
Posts: 67
geecab Offline
Member
geecab  Offline
Member

Joined: Apr 2013
Posts: 67
Thanks for the responses!

According to top, when running Firefly my CPU performance jumps from 12% without my hack, to 57% with my hack. Ouch!

Thinking about it, the timer really doesn't need to be triggered every cycle. Just been increasing the timeout (number of cycles) value to see how it effects CPU:-
1 cycle = 57% CPU
8 cycles = 19% CPU
16 cycles = 15% CPU
32 cycles = 13% CPU
224 cycles = 12% CPU

Might as well go with 224, at least it is clear that the screen is being put together line-by-line. Just tried the games out and they all look/play just as good.

I don't think my changes can be applied as-is though as I think I may have broken a few Russian clones. See the diff above, in the mame/video/spectrum.cpp file I commented out calls to spectrum_UpdateScreenBitmap() from the screen_vblank_spectrum() and screen_update_spectrum() functions. I reckon/guess a few of the clones rely on these calls. I will try and get my head around which ones will need attention.

#112681 - 02/18/18 10:42 AM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: Apr 2013
Posts: 67
geecab Offline
Member
geecab  Offline
Member

Joined: Apr 2013
Posts: 67
Originally Posted by Haze
per-scanline drawing isn't difficult (in fact the code might already support finer grained than that, as I said, some stuff was added for the russian clone demos to work where there are no contended memory issues at least)


Hi Haze! Any ideas of the names of these demos that work on the Pentagon? The existing (Partial screen update) fixes to the Pentagon driver basically result in calling spectrum_UpdateScreenBitmap() (In the pentagon_scr_w and pentagon_scr2_w memory write handler functions) more often than the Spectrum driver does. I think doing this somehow 'gets by' making these Russian demos work but doesn't fix the 'Firefly' issue or the flickering in certain games. I don't think the Pentagon driver's extra calls to spectrum_UpdateScreenBitmap() would be necessary if I implement my fix (Repeatedly triggering a call to spectrum_UpdateScreenBitmap() after x amount of CPU cycles). Just want to try these Pentagon demos out for myself in case there is something I haven't understood.

#112682 - 02/18/18 11:56 AM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: May 2004
Posts: 1,498
Haze Offline
Very Senior Member
Haze  Offline
Very Senior Member

Joined: May 2004
Posts: 1,498
_Metallic_ would know better about the Russian demos than I do as he enabled the partial update support for them in the first place.

Maybe if you were lucky some of them were added to a software list, but I don't think they were (they probably should be tho as they provide useful test cases)

Last edited by Haze; 02/18/18 11:57 AM.
#112784 - 03/03/18 11:24 AM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: Apr 2013
Posts: 67
geecab Offline
Member
geecab  Offline
Member

Joined: Apr 2013
Posts: 67
Here is my improved fix. It builds up the screen bitmap (I.e. calls spectrum_UpdateScreenBitmap()) every 224 (48K models) or 228 (128K models) CPU cycles (TStates).

My fix does appear to have a small impact on performance. I am running Ubuntu 17.10 64-bit, on an i3-2120 2.60Ghz CPU with 8Gbytes RAM. Playing Amaurote using the spec128 driver without my fix mame64 CPU usage is 19%, with my fix mame64 CPU usage is 22%.

I implemented my fix for all Spectrum models and clones apart from the pentagon and pent1024. After running various demos that Metallic suggested, I decided to leave the pentagon driver as is. The reason for this is - The pentagon driver calls the spectrum_UpdateScreenBitmap() function a lot (Each time any memory address is written to that could potentially effect the display) and as a result, the pentagon driver is slightly more processor hungry than the spectrum driver. The additional call to spectrum_UpdateScreenBitmap() as a result of my fix significantly hurts the pentagon's performance (Playing Amaurote using the pentagon driver without fix mame64 CPU usage is 25%, with my fix mame64 CPU usage is 66%). I really do not understand why my fix hurts the pentagon's performance so much, but would be very interested if anyone understands why?

Many thanks!

Code
diff --git a/src/mame/drivers/pentagon.cpp b/src/mame/drivers/pentagon.cpp
index 9dde309682..b0c1ee9f93 100644
--- a/src/mame/drivers/pentagon.cpp
+++ b/src/mame/drivers/pentagon.cpp
@@ -38,6 +38,7 @@ public:
 	DECLARE_READ8_MEMBER(beta_enable_r);
 	DECLARE_READ8_MEMBER(beta_disable_r);
 	DECLARE_MACHINE_RESET(pentagon);
+	DECLARE_VIDEO_START(pentagon);
 	INTERRUPT_GEN_MEMBER(pentagon_interrupt);
 	TIMER_CALLBACK_MEMBER(irq_on);
 	TIMER_CALLBACK_MEMBER(irq_off);
@@ -230,6 +231,22 @@ MACHINE_RESET_MEMBER(pentagon_state,pentagon)
 	pentagon_update_memory();
 }
 
+VIDEO_START_MEMBER(pentagon_state,pentagon)
+{
+	m_frame_invert_count = 16;
+	m_frame_number = 0;
+	m_flash_invert = 0;
+
+	m_previous_border_x = 0;
+	m_previous_border_y = 0;
+	machine().first_screen()->register_screen_bitmap(m_border_bitmap);
+	m_previous_screen_x = 0;
+	m_previous_screen_y = 0;
+	machine().first_screen()->register_screen_bitmap(m_screen_bitmap);
+
+	m_screen_location = m_ram->pointer() + (5 << 14);
+}
+
 /* F4 Character Displayer */
 static const gfx_layout spectrum_charlayout =
 {
@@ -262,6 +279,7 @@ MACHINE_CONFIG_DERIVED(pentagon_state::pentagon, spectrum_128)
 	MCFG_SCREEN_MODIFY("screen")
 	//MCFG_SCREEN_RAW_PARAMS(XTAL(14'000'000) / 2, 448, 0, 352,  320, 0, 304)
 	MCFG_SCREEN_RAW_PARAMS(XTAL(14'000'000) / 2, 448, 0, 352,  320, 0, 287)
+	MCFG_VIDEO_START_OVERRIDE(pentagon_state, pentagon )
 
 	MCFG_BETA_DISK_ADD(BETA_DISK_TAG)
 	MCFG_GFXDECODE_MODIFY("gfxdecode", pentagon)
diff --git a/src/mame/drivers/spectrum.cpp b/src/mame/drivers/spectrum.cpp
index 39c7974919..fd70130c11 100644
--- a/src/mame/drivers/spectrum.cpp
+++ b/src/mame/drivers/spectrum.cpp
@@ -643,13 +643,24 @@ GFXDECODE_END
 
 void spectrum_state::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
 {
-	m_maincpu->set_input_line(0, CLEAR_LINE);
+	switch (id)
+	{
+	case TIMER_IRQ_OFF:
+		m_maincpu->set_input_line(0, CLEAR_LINE);
+		break;
+	case TIMER_SCANLINE:
+		timer_set(m_maincpu->cycles_to_attotime(m_CyclesPerLine), TIMER_SCANLINE);
+		spectrum_UpdateScreenBitmap();
+		break;
+	default:
+		assert_always(false, "Unknown id in spectrum_state::device_timer");
+	}
 }
 
 INTERRUPT_GEN_MEMBER(spectrum_state::spec_interrupt)
 {
 	m_maincpu->set_input_line(0, HOLD_LINE);
-	timer_set(attotime::from_ticks(32, m_maincpu->clock()), 0, 0);
+	timer_set(attotime::from_ticks(32, m_maincpu->clock()), TIMER_IRQ_OFF, 0);
 }
 
 MACHINE_CONFIG_START(spectrum_state::spectrum_common)
diff --git a/src/mame/includes/spectrum.h b/src/mame/includes/spectrum.h
index 2b75781ab6..65894731b6 100644
--- a/src/mame/includes/spectrum.h
+++ b/src/mame/includes/spectrum.h
@@ -63,6 +63,12 @@ struct EVENT_LIST_ITEM
 class spectrum_state : public driver_device
 {
 public:
+        enum
+        {
+                TIMER_IRQ_ON,
+                TIMER_IRQ_OFF,
+                TIMER_SCANLINE
+        };
 	spectrum_state(const machine_config &mconfig, device_type type, const char *tag)
 		: driver_device(mconfig, type, tag),
 		m_video_ram(*this, "video_ram"),
@@ -110,13 +116,17 @@ public:
 
 	int m_ROMSelection;
 
+	// Build up the screen bitmap line-by-line as the z80 uses CPU cycles.
+	// Elimiates sprite flicker on various games (E.g. Marauder and
+	// Stormlord) and makes Firefly playable.
+	emu_timer *m_scanline_timer;
 
 	EVENT_LIST_ITEM *m_pCurrentItem;
 	int m_NumEvents;
 	int m_TotalEvents;
 	char *m_pEventListBuffer;
 	int m_LastFrameStartTime;
-	int m_CyclesPerFrame;
+	int m_CyclesPerLine;
 
 	uint8_t *m_ram_0000;
 	uint8_t m_ram_disabled_by_beta;
diff --git a/src/mame/video/spectrum.cpp b/src/mame/video/spectrum.cpp
index 2a26f0f209..46a7b04d59 100644
--- a/src/mame/video/spectrum.cpp
+++ b/src/mame/video/spectrum.cpp
@@ -17,6 +17,7 @@
 
 #include "emu.h"
 #include "includes/spectrum.h"
+#include "includes/spec128.h"
 #include "screen.h"
 
 
@@ -37,6 +38,11 @@ VIDEO_START_MEMBER(spectrum_state,spectrum)
 	machine().first_screen()->register_screen_bitmap(m_screen_bitmap);
 
 	m_screen_location = m_video_ram;
+
+	m_CyclesPerLine = SPEC_CYCLES_PER_LINE;
+	m_scanline_timer = timer_alloc(TIMER_SCANLINE);
+	timer_set(m_maincpu->cycles_to_attotime(m_CyclesPerLine), TIMER_SCANLINE);
+
 }
 
 VIDEO_START_MEMBER(spectrum_state,spectrum_128)
@@ -53,6 +59,10 @@ VIDEO_START_MEMBER(spectrum_state,spectrum_128)
 	machine().first_screen()->register_screen_bitmap(m_screen_bitmap);
 
 	m_screen_location = m_ram->pointer() + (5 << 14);
+
+	m_CyclesPerLine = SPEC128_CYCLES_PER_LINE;
+	m_scanline_timer = timer_alloc(TIMER_SCANLINE);
+	timer_set(m_maincpu->cycles_to_attotime(m_CyclesPerLine), TIMER_SCANLINE);
 }

#112785 - 03/03/18 02:03 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: May 2004
Posts: 1,498
Haze Offline
Very Senior Member
Haze  Offline
Very Senior Member

Joined: May 2004
Posts: 1,498
just fwiw, you should resolve the screen and use m_screen instead of first_screen()

#112786 - 03/03/18 03:03 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: Apr 2013
Posts: 67
geecab Offline
Member
geecab  Offline
Member

Joined: Apr 2013
Posts: 67
Sorry Haze, I'm not really following you. The first_screen() stuff is left just as I found it?

#112788 - 03/03/18 04:47 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: May 2004
Posts: 1,498
Haze Offline
Very Senior Member
Haze  Offline
Very Senior Member

Joined: May 2004
Posts: 1,498
well the diff makes it look like you added it, but maybe that's just pasted from elsewhere

either way, it's not the recommended way of doing things because it means the driver will always try to use the first indexed screen, which, in the future will be a problem because the idea is that eventually MAME will be able to run multiple machines at the same time :-) basically it's a bit of a leftover from the old days of MAME when CPUs, screens, regions etc. were indexed by value, not name.

#112789 - 03/03/18 05:02 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: Mar 2001
Posts: 15,933
R. Belmont Offline
R. Belmont  Offline

Very Senior Member

Joined: Mar 2001
Posts: 15,933
USA
That's a very new change though, I'll apply it locally and submit.

#112790 - 03/03/18 05:26 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: Haze]  
Joined: Apr 2013
Posts: 67
geecab Offline
Member
geecab  Offline
Member

Joined: Apr 2013
Posts: 67
Originally Posted by Haze
well the diff makes it look like you added it, but maybe that's just pasted from elsewhere

Ah yes, VIDEO_START_MEMBER(pentagon_state,pentagon) is a copy and paste of the original VIDEO_START_MEMBER(spectrum_state,spectrum_128) function, which does make it look like I added it :p The only difference between the two functions is that the spectrum version starts my scanline timer, the pentagon version doesn't.

#112791 - 03/03/18 05:32 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: May 2004
Posts: 1,498
Haze Offline
Very Senior Member
Haze  Offline
Very Senior Member

Joined: May 2004
Posts: 1,498
well first_screen use has slowly been reduced for a number of years now, bit surprised it wasn't actually marked as deprecated until vas just did it earlier today tho.

Page 5 of 6 1 2 3 4 5 6

Who's Online Now
2 registered members (dxl, 1 invisible), 16 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Shout Box
Forum Statistics
Forums9
Topics8,534
Posts111,541
Members4,793
Most Online225
May 26th, 2014
Powered by UBB.threads™ PHP Forum Software 7.6.0
Page Time: 0.028s Queries: 14 (0.008s) Memory: 5.0287 MB (Peak: 5.2520 MB) Zlib enabled. Server Time: 2018-05-23 09:12:01 UTC