Show us yer programming projects!

Coders forum. Discuss techniques, swap code snippets, ask for help etc. relating to all forms of software development.
Post Reply
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Show us yer programming projects!

Post by Dio »

Barney wrote:Accurate contention is a sod though!
If you do intra-instruction cycle counting it's trivial :) . In mine it's just a single table lookup on each memory access if the write hits a contended page, because at the point of the memory read the cycle count is exactly valid.

If you count cycles by table lookup in the fetch it's a total nightmare though. I started out an argument on one of the Atari forums by insisting that wait states were dead easy before I found out that everyone else does cycles by table...

I probably have a distorted view of it all mind because it's a very different thing working inside a modular emulator like Emu. Some things become so much easier, because there's so much utility code already in place and the framework does 90% of the work for you (the Spectrum-specific code is just 50k and that's probably half comments), but then there's always some little thing where it's really hard to express the semantics you need...
User avatar
Barney
Baaaaaa!
Baaaaaa!
Posts: 2131
Joined: Tue Aug 23, 2005 7:59 pm 0
Location: UK, Broughton, Brigg

Re: Show us yer programming projects!

Post by Barney »

Dio wrote:
Barney wrote:Accurate contention is a sod though!
If you do intra-instruction cycle counting it's trivial :) . In mine it's just a single table lookup on each memory access if the write hits a contended page, because at the point of the memory read the cycle count is exactly valid.

If you count cycles by table lookup in the fetch it's a total nightmare though.

I probably have a distorted view of it all mind because it's a very different thing working inside a modular emulator like Emu. Some things become so much easier, because there's so much utility code already in place and the framework does 90% of the work for you (the Spectrum-specific code is just 50k and that's probably half comments), but then there's always some little thing where it's really hard to express the semantics you need...
It's easy when you know what the contention is doing ;-) Mind you, we still don't know 100% what the contention in the +3 is doing, though educated guesses tend to turn out reasonably well.

I can clearly recall many, many nights sat in front of a hot 48k running tests on ULA snow to determine the effects it has on contention (and indeed, the "contention" it applies itself)... And then there's the tests for various z80 CPUs and their timing differences, they were a nightmare. We've got it all documented now, but it took a lot of work.

I've yet to convert the display callback to update after every TState, but might see about it for the next version. Too much work :(
"Oh dear lord, I slightly soiled myself. Oxfam won’t be pleased."
User avatar
Barney
Baaaaaa!
Baaaaaa!
Posts: 2131
Joined: Tue Aug 23, 2005 7:59 pm 0
Location: UK, Broughton, Brigg

Re: Show us yer programming projects!

Post by Barney »

evilpaul wrote:Oooo! Nice looking gigascreen support! Now that could come in handy... ;)
When's the likely release date?
I'm currently passing out test versions for the inhabitants of #spin (irc.coldfront.net) before moving onto major changes. My main goal is to get the damned thing stable on as many machines as I can before I let it out into the Wild. Marko is feverishly updating the assembler module, and getting the debugger fixed up and documented - when that's done, I'll likely release a 0.7, with 0.8 when the new stuff is done.

I have two more things to fix in the graphics system, then I'll be good to go.
"Oh dear lord, I slightly soiled myself. Oxfam won’t be pleased."
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Show us yer programming projects!

Post by Dio »

Ah, right. I still haven't got into the hairyness of a flushable display yet, I still generate on line boundaries. It's on the to-do list (which is currently running at 40K, so it's not far behind the actual whole Spectrum emulator...!)
User avatar
Barney
Baaaaaa!
Baaaaaa!
Posts: 2131
Joined: Tue Aug 23, 2005 7:59 pm 0
Location: UK, Broughton, Brigg

Re: Show us yer programming projects!

Post by Barney »

Dio wrote:Ah, right. I still haven't got into the hairyness of a flushable display yet, I still generate on line boundaries. It's on the to-do list (which is currently running at 40K, so it's not far behind the actual whole Spectrum emulator...!)
Most emulators that do the whole "demo scene" thing update every 4 TStates - this gets most effects going nicely. However, one young man wrote a hardware scroller for the speccy using ULA snow, and that needs 1TState update frequencies in the worst case. ZXSpin does a reasonable job of emulating it, but it could be better. Then there's the whole palette change when INVERSE is used, which I don't emulate and the ghosting from FLASHing attributes to do...

Lots to get done :)
"Oh dear lord, I slightly soiled myself. Oxfam won’t be pleased."
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Show us yer programming projects!

Post by Dio »

I'd issue the flush on any write to a contended memory location, but I really haven't considered the snow issue yet. Flush on each refresh is one option; another might be to store a list of refresh cycles over the frame, and use that during the flush, although if the refresh needs to incur CPU wait states that wouldn't be an option.
User avatar
Barney
Baaaaaa!
Baaaaaa!
Posts: 2131
Joined: Tue Aug 23, 2005 7:59 pm 0
Location: UK, Broughton, Brigg

Re: Show us yer programming projects!

Post by Barney »

Dio wrote:I'd issue the flush on any write to a contended memory location, but I really haven't considered the snow issue yet. Flush on each refresh is one option; another might be to store a list of refresh cycles over the frame, and use that during the flush, although if the refresh needs to incur CPU wait states that wouldn't be an option.
Flushing on contended writes is the usual method, and the one we use currently... The routine really only needs to know about how to draw at 4Ts resolution though; and happily, rendering what the ULA is sending fits nicely into that time-frame. ULA snow does tend to throw that out the window though, and will be a lot slower - I know of only one z80 core that emulates at micro-code level, and that's SpecEMU. Everyone else tends to lump their opcode handlers into one procedure call per opcode.
"Oh dear lord, I slightly soiled myself. Oxfam won’t be pleased."
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Show us yer programming projects!

Post by Dio »

Yeah, that's what I do, although it counts the subcycles internally so when the device gets an op from the pagetable the cycle count is right. (It also means the timing 'falls out' automatically of the CPU - there's relatively few places I have to patch it with extra cycles here and there).

It turns up some fascinating edge cases. The most interesting one I've had so far was on the ST: there was a game that had a huge bug, polling the keyboard serial port status reg in order to see when to exit a busy wait loop BUT simultaneously had interrupts enabled. The serial receive event could only fire on an instruction boundary, which meant that as soon as the CPU started running again it took the interrupt. However, on the real hardware there was a 4-cycle window when the status register would show that a byte was ready. I fixed that by allowing devices to say "This register depends on this event, so can I check if it needs to fire in the middle of an instruction?"

Is there a doc you can point me at on how the refresh interaction works to generate the snow? I assumed initially it was something like: Z80 sends a refresh, ULA sees A14/A15 as 01 and generates WAIT, which the CPU ignores. What I'm not clear on is why that then causes the ULA to go wrong; the decoupled bus should prevent the problem, and WAIT doesn't generate any externally visible signal it could be relying on. Then I noticed that WAIT isn't actually the way that the waitstates are generated on the Spectrum - is it by clock gating the CPU line out of the ULA?

I'm looking forward to the ULA book that that FPGA chap is writing.
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Show us yer programming projects!

Post by Dio »

Ha, right, found it on the Harlequin page. My interpretation: the contention circuitry (which is indeed a clock gate) only enables if the first cycle of an instruction is seen by the ULA, not if it's the third/fourth like a refresh. The MREQ for the refresh then leads to the DRAM controller forcing RAS low - so although the Z80's actual address bits are ignored, the bad RAS means no new row address and so the previous attr/colour bytes are read again.

If that's right, the job should be solvable without needing per-cycle flush by keeping a list of issued refresh cycles, and matching them up in the video flush. Should be tolerably cheap to do in the Z80 core... once I've got a flushable screen of course :) .

A few links to timing testers there as well, I'll be having those :) .
User avatar
Barney
Baaaaaa!
Baaaaaa!
Posts: 2131
Joined: Tue Aug 23, 2005 7:59 pm 0
Location: UK, Broughton, Brigg

Re: Show us yer programming projects!

Post by Barney »

Dio wrote:Ha, right, found it on the Harlequin page. My interpretation: the contention circuitry (which is indeed a clock gate) only enables if the first cycle of an instruction is seen by the ULA, not if it's the third/fourth like a refresh. The MREQ for the refresh then leads to the DRAM controller forcing RAS low - so although the Z80's actual address bits are ignored, the bad RAS means no new row address and so the previous attr/colour bytes are read again.

If that's right, the job should be solvable without needing per-cycle flush by keeping a list of issued refresh cycles, and matching them up in the video flush. Should be tolerably cheap to do in the Z80 core... once I've got a flushable screen of course :) .

A few links to timing testers there as well, I'll be having those :) .
Yep, as I said - you need a flushable display routine. We have one, but it's based on 4Ts granularity rather than just the 1. Our ULA-Snow emulation generates a passable rendition but isn't accurate because of this.

Basically, in the opcode fetch, we:

Check if snow is enabled (I register in the range 64..127), if so then fetch the opcode, then increment TState counter by 3, then flush the display without snow. Then increment TState counter by 1, and flush again, with snow. The graphics flush routine knows about snow and where to get the display bytes from when it's enabled. Then turn snow off again for the remainder of the instruction.

During the LD I,A instruction, add IR contention (contention based on the I register as the high-order byte of the address) and then set the I register, followed by a non-snow enabled graphics flush. Then flag the next opcode as being a contender for snow if the I register is set appropriately.

It matches the vast majority of our tests on the 48k hardware, but could be better - effects tend to appear 8 or 16 pixels offset for pixel effects, but attribute effects work perfectly. The problem is that we still don't know how the effect works - investigation is still ongoing, but nobody has come up with an algorithm that matches the real thing yet.
"Oh dear lord, I slightly soiled myself. Oxfam won’t be pleased."
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Show us yer programming projects!

Post by Dio »

By the way, what's the name of that hicolour demo you showed?
User avatar
Barney
Baaaaaa!
Baaaaaa!
Posts: 2131
Joined: Tue Aug 23, 2005 7:59 pm 0
Location: UK, Broughton, Brigg

Re: Show us yer programming projects!

Post by Barney »

You can get that here: http://speccy-live.untergrund.net/wp-co ... eeshon.zip

There's also this one: http://pc.sux.org/tomcat/Animals.zip
Which is very nice also:

Image

These demos also come very highly recommended, but require Pentagon emulation:

Brain Surgery
Stellar Contour

and will really give your emulator a workout.
"Oh dear lord, I slightly soiled myself. Oxfam won’t be pleased."
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Show us yer programming projects!

Post by Dio »

Ta vez much :) .
User avatar
The Caffeine Kid
Baaaaaaa!
Baaaaaaa!
Posts: 5691
Joined: Mon Mar 01, 2004 9:24 pm 0
XBL Gamertag: TheCaffeineKid
PSN: caffeinekid
Yahoo Messenger: caffeinekid
Location: Wakefield
Contact:

Re: Show us yer programming projects!

Post by The Caffeine Kid »

Well I've just released my game - remake of Cruising on Broadway from the ZX Spectrum.

http://www.tcksoft.co.uk/downloads/rema ... way-extra/

Blessing and input from the original author was very helpful, he's a top bloke. :)
Life... Don't talk to me about life...

http://www.tcksoft.co.uk
http://www.retroremakes.com
User avatar
BleuLlama
Baa!
Baa!
Posts: 38
Joined: Mon Sep 12, 2005 6:55 pm 0
Location: Rochester, NY, USA
Contact:

Re: Show us yer programming projects!

Post by BleuLlama »

Hi all.

Here's a little something I've been poking at for the past few days...
Image

It doesn't look like much yet, it's more of a proof of concept, and the basic foundation thus far.

It's an iPhone library/app which consists of a Z80 emulator (I'm using the BSD licensed "Z80Pack"), and some customized "hardware" which maps into the Z80 space. The idea is that I can write games in Z80 asm that talk to hardware in this virtual machine, and it becomes an iPhone game. I'm going to be adding the sprite engine tonight probably, using the cocos2d library, and the tiled background soon afterwards. I don't think i'm going to be emulating the pac/pengo color support for sprites/tiles, and instead use PNG files for the engine. I've specced out some 'hardware' where you can change which sprite/character png is used in each sprite slot.

I'm making it such that the "hardware" can easily be moved about in the memory space, so that I can make it compatible with pac-man or Pengo hardware, even though my goal is not to make an arcade emulator. In fact, I general practice, I will not be throttling the Z80 emulation to any specific speed, so it will likely not function properly as an arcade game emulator.

Here's more information about the project...
http://umlautllama.com/w2/?action=view& ... 0%20Engine

Here's a link to a couple of videos and such..
http://umlautllama.com/rand/?q=iphone-llamacore&b=18

Currently, I have the Z80 cpu running, with a 60Hz interrupt (like pac/pengo hardware), defined/loadable ROM banks, accelerometer, touch X/Y, and tap count from the device mapped into Z80 memory space.
Post Reply