Previous Thread
Next Thread
Print Thread
Page 1 of 5 1 2 3 4 5
#112363 - 01/26/18 10:11 AM FireFly on the ZX Spectrum - Missing graphics  
Joined: Apr 2013
Posts: 41
geecab Offline
Member
geecab  Offline
Member

Joined: Apr 2013
Posts: 41
Hi There!

I can't seem to get FireFly on the ZX spectrum to work correctly. The section where you select a square on the map, there is no fly to move. In fact, the fly is 'there' (You can move it and select a square from the map) but you just can't see it. Then once the game begins, you can fire, and you can hear your bullets, but you can't see your bullets.

Its very strange. I decided to try and work out what is going on. I thought the game might be doing something similar to Sidewize (Reading a strange/ula input port, waiting for the raster to be in a certain position before drawing the fly/bullets) so I traced all the opcodes during the "select a square on the map" section but the only input ports read are that are used for keyboard input.

Just wondered if anyone knows why this could be happening? What I might be able to do to investigate this further?

Many thanks!

#112368 - 01/26/18 01:10 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: May 2004
Posts: 1,484
Haze Offline
Very Senior Member
Haze  Offline
Very Senior Member

Joined: May 2004
Posts: 1,484
problems are expected in the spectrum drivers because MAME in it's current form is incapable of emulating the waitstates correctly, at least not without extensive ugly hacks to the z80 core.

I'm sure once MAME is capable of that then the driver will get a massive overhaul as it's actually a relatively simple system otherwise

As a result tho, you're unlikely to find anybody wanting to dedicate too much time to this, because a lot of things will come down to the same source, bad timings, incorrect open bus behavior (that won't really be correct without proper timings) etc.

#112369 - 01/26/18 01:49 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: Apr 2013
Posts: 41
geecab Offline
Member
geecab  Offline
Member

Joined: Apr 2013
Posts: 41
Hi Haze and thanks for the response! I totally appreciate what you are saying about MAME's speccy timing flaws.

Bit of a long shot I know, but if it were timing/waitstate related, wouldn't it be more likely that you'd see the fly/bullets flicker, rather than not see them at all? My reasoning for saying this is that I've run lots of speecy games on mame, even the ones that seem to be effected by timing (A few that come to mind are 'Zynaps', 'Marauder' and 'Stormlord') are all still very playable, you just have to put up with that player's ship/hero flickering a bit.

#112370 - 01/26/18 01:52 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: Dec 2015
Posts: 70
AJR Online content
Member
AJR  Online Content
Member

Joined: Dec 2015
Posts: 70
If the schematics are not totally incorrect, the ZX Spectrum hardware actually has no built-in wait states, and leaves /WAIT (along with /BUSREQ and /NMI) to be driven only through the external connector. I don't know exactly what's going on here, but this probably means that the ZX Spectrum ULA, like that of its Acorn Electron counterpart, conditionally stretches the CPU clock which it does output.

#112371 - 01/26/18 01:59 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: May 2004
Posts: 1,484
Haze Offline
Very Senior Member
Haze  Offline
Very Senior Member

Joined: May 2004
Posts: 1,484
the way the waits work on the spectrum is extensively documented, but yeah, it's the ULA grabbing the bus, it can happen mid-opcode fetch or whenever else, stalling the z80 mid operation until it's done if the Z80 attempts to access any kind of contended memory be it for opcode fetch cycle or reading / writing.

the exact patterns of access are well documented for both the original spectrum and a number of clones and there's software that depends on them being near perfect (there's even software that only runs on certain machines due to the tiniest drifts in timing which can differ from machine to machine)

the Russian clone machines don't have any waits at all, so their compatibility is basically the same as MAME.

there is some (probably outdated at this point) information about it here
https://www.worldofspectrum.org/faq/reference/48kreference.htm

I've seen better references tho, although I can't find them right now. you can also find test software people have written that at least a few years ago could even detect an emulator / real machine most of the time. (with a few false positives due to some machines being more out of spec than others)


#112380 - 01/28/18 06:47 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: Apr 2013
Posts: 41
geecab Offline
Member
geecab  Offline
Member

Joined: Apr 2013
Posts: 41
Hi there and thanks again for the responses! As there is a small chance this isn't a timing issue (and for my own interest), I decided to to try and work out some of Firefly's machine code. I discovered that during the game's 'move your fly to a square on the map' section, the machine code repeatedly calls a number of big subroutines. Using Emuzwin and its poke feature, I put a return (C9H) opcode at the beginning of each subroutine to see what effect it had on the game.

For example, I found that one of the big subroutines being called in the main execution loop was located at address B23AH, which when I run the game with C9H at that address, I discovered everything looked fine, but I just wasn't able to move my fly (So I assume this subroutine is checking for key presses).

Here are my complete results:-

B029 CALL AE94H Fly flashes on and off. Fly image slightly distorted
B02C CALL B484H All looks fine but background does not refresh when fly is moved (I.e. fly leaves a trail of itself).
B02F CALL B41DH All looks fine but no fly shown
B032 CALL B1C8H All looks fine but no fly shown
B035 CALL B4B4H All looks fine but background does not refresh when fly is moved (similar to B484H)
B038 CALL B3C2H All looks fine but no moving stars are drawn
B03B CALL B23AH All looks fine but not able to move fly (no response to keyboard).
B03E CALL AD26H Game freezes in between menu and planet screen

I would now like to do the same with mame (See what effect, if any, putting C9H at locations AE94H, then at B4B4H etc..) has. Is there any way I can do this without building a hacked version of mame? Using its debugger perhaps (I've looked though the help but had no joy. Thought that the 'cheatinit' command sounded promising but I don't think that is quite what I'm looking for)??

Thanks for your help!

#112381 - 01/28/18 06:53 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: Jun 2001
Posts: 382
Olivier Galibert Offline
Senior Member
Olivier Galibert  Offline
Senior Member

Joined: Jun 2001
Posts: 382
somewhere else entirely
Start with the debugger, press F12 and load the game, press ` when you want to get back control, open a memory view (menu or ctrl-m), go to the address you want to change, change it, F12 to make the game continue (F5 if you want to debugger windows to stay open).

OG.

#112391 - 01/29/18 09:34 AM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: Apr 2013
Posts: 41
geecab Offline
Member
geecab  Offline
Member

Joined: Apr 2013
Posts: 41
That's just what I'm looking for, thanks OG!

#112409 - 01/31/18 01:17 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: Apr 2013
Posts: 41
geecab Offline
Member
geecab  Offline
Member

Joined: Apr 2013
Posts: 41
Hi there! I think I’ve found what the problem is and maybe a way to fix it….


Here is my over simplistic summary of what I think is happening during the game:-

Step 1. AE94H is called – This is a simple loop that exits only when the Vertical Blank Interrupt occurs (I.e. When the raster returns to the top of the display).
Step 2. B41DH is called – Draws a fly on to the existing background.
Step 3. B1C8H is called – This is a simple loop that exits after a certain amount of iterations (Its purpose is to wait for raster to pass over the fly that we have just drawn)
Step 4. Remove the fly off the background
Step 5. Check keyboard input and draw stars.
Step 6. Go back to ‘1’.

So the problem is that the game draws stuff before the raster, and clears it after the raster has gone. On a real spectrum, it appears that the fly is always floating nicely on the background image. As Mame does not have a raster, it updates the display ‘in one go’ with whatever z80 display memory (6144 bytes starting at address &4000) exists at the time of the interrupt (At Step 1).. Unfortunately, at the time of the interrupt, the display memory has always had its fly removed thus the player never gets to see it.


I think it might be possible to fix it (And make other games that do a similar ‘trick’ look a lot better) like this….

Currently in mame, there is an ‘m_icount’ variable that keeps track of how many cycles (TStates) have passed since the Interrupt occurred (Note. The spectrum runs 69888 TStates per frame). Once the interrupt occurs m_icount is set to 69888, it is then decremented by a certain amount based on each Z80 opcode processed. When m_icount reaches zero, it triggers the interrupt, the screen is redrawn and m_icount is set back to 69888 and off we go again.

Based on the m_icount, we can predict where raster position would be on a real spectrum. There are 312 lines per frame, thus each time m_icount is decremented by 224 (Which is 69888/312), we’ll know the raster will have finished displaying a line. Mame could keep a history of the display memory at these intervals (Stored in, say, an "display_history[312]" array). Then when the interrupt is triggered, update_screen_spectrum() rather that displaying what is currently in the z80 display memory, would instead go though the display_history[312] array and line by line piece together a more accurate render of the display.

This fix might even get the timing based colour effects working (Like the ones seen during the 128k ‘Amaurote’ intro for example).

Very interested to hear what the opinions are on this? I haven’t tested/hacked this yet, wanted to hear if it sounds like a good idea or not.

Many thanks!

#112410 - 01/31/18 01:29 PM Re: FireFly on the ZX Spectrum - Missing graphics [Re: geecab]  
Joined: May 2004
Posts: 1,484
Haze Offline
Very Senior Member
Haze  Offline
Very Senior Member

Joined: May 2004
Posts: 1,484
I actually thought somebody had already added partial update support to the MAME Spectrum driver family as some of the Russian demos, which don't care about timing, use it.

I could be wrong tho, maybe those use a different piece of code entirely. I think it was MetalliC who did it for the Russian ones at least.

It won't fix the colour effects in lots of spectrum demos even if it was added tho, because they're all based on cycle counting which depends on exact timing. They'll end up different, but not correct.

Page 1 of 5 1 2 3 4 5

Who's Online Now
6 registered members (EoceneMiacid, Dorando, Edstrom, robcfg, MarkBielman, 1 invisible), 27 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Shout Box
Forum Statistics
Forums9
Topics8,496
Posts110,806
Members4,781
Most Online225
May 26th, 2014
Powered by UBB.threads™ PHP Forum Software 7.6.0
Page Time: 0.090s Queries: 15 (0.041s) Memory: 5.0234 MB (Peak: 5.2677 MB) Zlib enabled. Server Time: 2018-02-22 16:21:52 UTC