Good test games / programs for an emulator

discuss bbc micro and electron emulators (including mame) here!
Post Reply
dominicbeesley
Posts: 1126
Joined: Tue Apr 30, 2013 12:16 pm
Contact:

Good test games / programs for an emulator

Post by dominicbeesley » Tue Jan 21, 2020 11:46 am

Hello,

I've been hacking at BeebEm quite extensively in preparation for getting an emulation of the blitter board running. The first step has been to rip out the old 65x02 cores and replace them with a slightly reworked version of the MAME cores (simplified and sped up slightly). The main loop now works on a 2mhz clock cycle basis rather than the per-instruction basis that it used to work on - needed to sanely work out the contention between cpu, blitter, sound etc.

I've run the 6502A core through all the Dorman tests and it seems good but I've not tested for cycle accuracy

This seems to be running ok if a little slowly in BeebEm but I'd like to have some test case programs to run that check for undocumented/illegal opcodes and any that depend on accurate instruction timing, preferably ones that already run correctly in either B-em or BeebEm as I am still without my real machines!

So any good tests for timing and/or undocumented ops?

TIA

D

https://github.com/dominicbeesley/beebe ... ee/Blitter

dominicbeesley
Posts: 1126
Joined: Tue Apr 30, 2013 12:16 pm
Contact:

Re: Good test games / programs for an emulator

Post by dominicbeesley » Wed Jan 22, 2020 10:37 am

Does nobody know our am i asking in the wrong forum? I found zalaga which appears to use undocumented ops

User avatar
Pernod
Posts: 2193
Joined: Fri Jun 08, 2012 11:01 pm
Location: Croydon, UK
Contact:

Re: Good test games / programs for an emulator

Post by Pernod » Wed Jan 22, 2020 11:01 am

- Nigel

BBC Model B: ATPL Sidewise, Acorn Speech, 2xWatford Floppy Drives, AMX Mouse, Viglen case, BeebZIF, etc.

dominicbeesley
Posts: 1126
Joined: Tue Apr 30, 2013 12:16 pm
Contact:

Re: Good test games / programs for an emulator

Post by dominicbeesley » Wed Jan 22, 2020 11:22 am

Thankyou Pernod, I spent ages searching and didn't come up with either of those threads but I

I was hoping there would be a list of games that used sketchy opcodes somewhere but not joy so far.

Zalaga worked first time so it looks like the MAME cpus were right first time. I also got it running acceptably fast last night so will undo all my hacks and start some proper testing later this week.

D

User avatar
BigEd
Posts: 3356
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: Good test games / programs for an emulator

Post by BigEd » Wed Jan 22, 2020 12:11 pm

Allow me to edit that slightly:
Pernod wrote:
Wed Jan 22, 2020 11:01 am
See the following topics:
There have been many previous threads about low level timing, and I'm not sure I've yet found the one I was looking for, but for reference - and hopefully as a useful contribution - here are some I did find:

User avatar
Pernod
Posts: 2193
Joined: Fri Jun 08, 2012 11:01 pm
Location: Croydon, UK
Contact:

Re: Good test games / programs for an emulator

Post by Pernod » Wed Jan 22, 2020 12:59 pm

dominicbeesley wrote:
Wed Jan 22, 2020 11:22 am
Zalaga worked first time so it looks like the MAME cpus were right first time.
The only 6502 related issues in MAME that I'm aware of are that the BCD test suite fails to distinguish between a 65SC02 and 65C02.
- Nigel

BBC Model B: ATPL Sidewise, Acorn Speech, 2xWatford Floppy Drives, AMX Mouse, Viglen case, BeebZIF, etc.

User avatar
Rich Talbot-Watkins
Posts: 1651
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: Good test games / programs for an emulator

Post by Rich Talbot-Watkins » Wed Jan 22, 2020 1:08 pm

I'm amused that, of all those threads, nearly all of them were started by either me or Matt!

User avatar
BigEd
Posts: 3356
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: Good test games / programs for an emulator

Post by BigEd » Wed Jan 22, 2020 1:17 pm

Rich Talbot-Watkins wrote:
Wed Jan 22, 2020 1:08 pm
I'm amused that, of all those threads, nearly all of them were started by either me or Matt!
Surely down to the care and attention in fine-tuning JSBeeb. Or possibly because I was originally searching for some specific tests or programs I'd run, and thought I would have posted in response to one or other you...

Edit: another discussion here mentions very sensitive branch timing:
Re: NMI/IRQ timing to vector pull

Edit: and this one points at protection systems again, and scrolling in Planetoid:
Re: 6522 VIA emulation: ACR writes

User avatar
tricky
Posts: 4578
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Good test games / programs for an emulator

Post by tricky » Wed Jan 22, 2020 1:48 pm

Scramble is quite tight on timing.
If the timing is off, you get rows shown twice.
Certainly works in b-em, but maybe not all versions of beebem (I think vsync is off).

dominicbeesley
Posts: 1126
Joined: Tue Apr 30, 2013 12:16 pm
Contact:

Re: Good test games / programs for an emulator

Post by dominicbeesley » Wed Jan 22, 2020 4:14 pm

Thanks all,

I'll have to start chewing through these over the weekend.

I'm trying to get 1st light of the 65c02/ master first then I'll start looking at all these.

It looks like the undocumented behaviour is ok but the timing isn't 100% - unsurprising as I've not even got it properly doing 1MHz hardware accesses yet but I'm suspicious that my changes to the cpu cores have upset some cycle timings which will require poring over datasheets.

Thanks again

D

User avatar
BigEd
Posts: 3356
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: Good test games / programs for an emulator

Post by BigEd » Wed Jan 22, 2020 4:24 pm

BTW if you're in any position to take lots of traces it might well be that automatic analysis can find outliers. Maybe hoglet's 6502 decoder would be useful here.

User avatar
scarybeasts
Posts: 535
Joined: Tue Feb 06, 2018 7:44 am
Contact:

Re: Good test games / programs for an emulator

Post by scarybeasts » Wed Jan 22, 2020 5:13 pm

tricky wrote:
Wed Jan 22, 2020 1:48 pm
Scramble is quite tight on timing.
If the timing is off, you get rows shown twice.
Certainly works in b-em, but maybe not all versions of beebem (I think vsync is off).
As someone working on an emulator, I can attest to this! If you mess it up it might look a bit like this:
https://www.youtube.com/watch?v=U169-xj2L_k

Some of this is likely duplicative of other notes in this thread, but timing / opcode stuff I've hit recently includes:
- The Nightshade protected loader is indeed savage, although it also depends on 6522 behavior as well as checking 6502 interrupts in the right place.
- The Exile protected loader (typically not present on the SSDs kicking around; the FSDs have it, maybe the tape has it too?) is awful insofar as it unpacks using a lot of ADC instructions... and has kindly set the decimal flag ahead of time! So BCD results and flags are given a workout in the presence of out-of-range BCD digits.
- I just hit a ton of previously-not-seen-by-me undocumented opcodes in the Hopper protected loader, present on the FSD. A lot of different NOP modes and lengths in an attempt to obfuscate but also SAX abs and LAX zpg. The latter is the fist LAX I've seen at all. I don't recall if it cares about timing or even the result though.
- Revs is very sensitive to the correctness of vsync timing in interlace modes (ugh). But that's more of a 6522 vs. 6845 thing.


Cheers
Chris

dominicbeesley
Posts: 1126
Joined: Tue Apr 30, 2013 12:16 pm
Contact:

Re: Good test games / programs for an emulator

Post by dominicbeesley » Wed Jan 22, 2020 6:15 pm

Good point Ed, I might add a dump to hoglet binary option and check where decodes fail - I'm guessing the Hoglet decoder will barf on mis-timed instructions?

Thanks Chris, excuse my ignorance - what's a "FSD"?

D

User avatar
hoglet
Posts: 9390
Joined: Sat Oct 13, 2012 7:21 pm
Location: Bristol
Contact:

Re: Good test games / programs for an emulator

Post by hoglet » Wed Jan 22, 2020 6:36 pm

dominicbeesley wrote:
Wed Jan 22, 2020 6:15 pm
Good point Ed, I might add a dump to hoglet binary option and check where decodes fail - I'm guessing the Hoglet decoder will barf on mis-timed instructions?
Yes, indeed it will, especially if you force it to ignore the sync input.

I've used the decoders to verify the cycle accuracy of the T65 and T80 FPGA cores used in ICE-6502 and ICE-Z80:
- The current version of the T65 core passed.
- The current verstion of the T80 core has just one failure, the cycle ordering within EX (SP), HL.

You obviously need to exercise every instruction/addressing mode. On the 6502 the Dormann tests do this.

Dave

User avatar
scarybeasts
Posts: 535
Joined: Tue Feb 06, 2018 7:44 am
Contact:

Re: Good test games / programs for an emulator

Post by scarybeasts » Wed Jan 22, 2020 7:20 pm

FSD is a file format whose journey (creation, supporting materials, challenges) is documented in this thread:

viewtopic.php?f=4&t=4353&start=120

Emulator support is patchy. There's a hacked up version of BeebEm that I don't believe was merged into an official release yet. MAME does have FSD support for a subset of simpler FSDs.


Cheers
Chris

User avatar
Pernod
Posts: 2193
Joined: Fri Jun 08, 2012 11:01 pm
Location: Croydon, UK
Contact:

Re: Good test games / programs for an emulator

Post by Pernod » Wed Jan 22, 2020 8:19 pm

scarybeasts wrote:
Wed Jan 22, 2020 7:20 pm
Emulator support is patchy. There's a hacked up version of BeebEm that I don't believe was merged into an official release yet. MAME does have FSD support for a subset of simpler FSDs.
I'd be interested in seeing your implementation :D
- Nigel

BBC Model B: ATPL Sidewise, Acorn Speech, 2xWatford Floppy Drives, AMX Mouse, Viglen case, BeebZIF, etc.

User avatar
scarybeasts
Posts: 535
Joined: Tue Feb 06, 2018 7:44 am
Contact:

Re: Good test games / programs for an emulator

Post by scarybeasts » Wed Jan 22, 2020 9:13 pm

Pernod wrote:
Wed Jan 22, 2020 8:19 pm
I'd be interested in seeing your implementation :D
Sure! I'm trying to get my emulator released but there's always "one more thing". Perhaps I'm falling into some form of perfectionist trap. In the interim, I'd be happy to describe some of the headaches getting all the different FSDs working, and some of the heuristics / tradeoffs deployed.


Cheers
Chris

dominicbeesley
Posts: 1126
Joined: Tue Apr 30, 2013 12:16 pm
Contact:

Re: Good test games / programs for an emulator

Post by dominicbeesley » Thu Jan 23, 2020 11:04 am

Gah, it was all going for too well. I'm now getting random linking errors when linking in Debug mode in Visual C++. I'm pretty sure this isn't a project settings thing. It is usually (but not always) the constructors that it can't find in the static library if I change them to m6502_device(void) to m6502_device() it might work a couple of compiles then it will randomly fail. It always works for release builds!

D

User avatar
scarybeasts
Posts: 535
Joined: Tue Feb 06, 2018 7:44 am
Contact:

Re: Good test games / programs for an emulator

Post by scarybeasts » Fri Jan 24, 2020 9:36 am

This is too good to not mention.

I've just found out that the Zalaga tape loader is chock full of undocumented instructions, starting with:

[ITRP] 2412: LAX $FFEB
[ITRP] 2415: ALR #$C5
[ITRP] 2417: NOP $A9,X
[ITRP] 2419: BCS $23EE

The branch is taken, and it lands upon and executes this exact text string!! :

Orlando M.Pilchard

Oh, Orlando :)

That corresponds to a pretty unusual first instruction, an SRE:
[ITRP] 23EE: SRE $6C72
[ITRP] 23F1: ADC ($6E,X)
[ITRP] 23F3: NOP $6F
[ITRP] 23F5: JSR $2E4D


Cheers
Chris

User avatar
tricky
Posts: 4578
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Good test games / programs for an emulator

Post by tricky » Fri Jan 24, 2020 4:22 pm

Are your libs depe dependencies of you exe and each other if build order is important?
Does it always work with a rebuild all?

dominicbeesley
Posts: 1126
Joined: Tue Apr 30, 2013 12:16 pm
Contact:

Re: Good test games / programs for an emulator

Post by dominicbeesley » Fri Jan 24, 2020 5:28 pm

Thanks tricky

The .exe depends on the Static library but no other dependencies.

The debug build sometimes works sometimes not. Fixing one function often makes the other fail!

Rebuild all gives the same result as normal build.

I tried running dumpbin /symbols on the static library and the missing functions (actually a no parameter constructor and sometimes another no parameter function) are not being listed so it looks like it's the library that is at fault. It might be a coincidence but the constructor is the first thing declared in the class header and the other method the last!

I suspect it works in release because "whole program optimisation" is on for release which means that rather than linking in real code it links in intermediate code and that is not missing the constructors/functions.

Aside: I'm going to rework the whole thing anyway over the weekend. I have been using class member pointers to implement a state machine - this was much faster than the original mame implementation which used a couple of huge case statements and state variables but I suspect that normal function pointers (rather than class member pointers) will be even faster and solve a load of horrendous kludges I've had to do to get it to work due to the fact that member pointers don't inherit in the same way as object pointers.

D

dominicbeesley
Posts: 1126
Joined: Tue Apr 30, 2013 12:16 pm
Contact:

Re: Good test games / programs for an emulator

Post by dominicbeesley » Sun Jan 26, 2020 11:59 pm

hoglet wrote:
Wed Jan 22, 2020 6:36 pm
dominicbeesley wrote:
Wed Jan 22, 2020 6:15 pm
Good point Ed, I might add a dump to hoglet binary option and check where decodes fail - I'm guessing the Hoglet decoder will barf on mis-timed instructions?
Yes, indeed it will, especially if you force it to ignore the sync input.
Thanks I've just got the Master/65c02 working and one anomaly seems to be thrown in up for JMP (abs) decode6502 is picking up a repeated high byte and then complaining about predictions. I suspect that the code in MAME is wrong - it looks funky to me:

What the NMOS 6502 mame does - this seems to work ok in decode6502.
The following code blocks are all in the pseudo microcode that gets turned into a set of C functions that are called by the state machine for each cycle. Each read/write/fetch will cause a cycle

Code: Select all

	TMP = read(PC++);
	TMP = set_h(TMP, read(PC++));
	PC = read(TMP);
	PC = set_h(PC, read(set_l(TMP, TMP+1)));
	fetch();
The MAME 65c02 core has this

Code: Select all

	TMP = read_pc();
	TMP = set_h(TMP, read_pc());
	PC = read(TMP);			<-- looks odd
	read(set_l(TMP, TMP+1));		<-- looks even odder
	PC = set_h(PC, read(TMP+1));
	prefetch();
What I think it probably should be - this matches the 65c02 datasheet at http://datasheets.chipdb.org/Western%20 ... 65C02S.pdf

Code: Select all

	TMP = read(PC++);
	TMP = set_h(TMP, read(PC++));
	read(PC);					<-- dummy read ignored
	PC = read(TMP);
	PC = set_h(PC, read(TMP+1));
	fetch();
Does anyone know? If the WD 65c02 datasheet is the most correct.

I also note that the BeebEm original has a fudge for indirect addresses on a page boundary for the NMOS 6502 i.e. at &xxFF I will apply that too as I seem to recall it is right - not sure if the Dorman test check for that one!

Finally I seem to be getting somewhere - no idea what fixed the linking problems but they seem to have gone away...for now.

@scarybeasts, that looks horrendous! I'll have to give it a go - though I've never done anything with tape images before! Will the tape images on STH contain this or will they have been sanitised?

Ta

D

julie_m
Posts: 227
Joined: Wed Jul 24, 2019 9:53 pm
Location: Derby, UK
Contact:

Re: Good test games / programs for an emulator

Post by julie_m » Mon Jan 27, 2020 12:18 am

On an original NMOS 6502, indirect addresses across a page boundary are broken: the high byte of the address bus is not increased after reading the low byte of an address from the last byte within a page. For instance, JMP(&4BFF) gets the low byte of the address from &4BFF, but the high byte from &4B00 rather than the expected 4C00. This is of course only a problem at most 50% of the time ;) If you are careful how you align the low byte of an address to be always in an even address, then you will never encounter this behaviour.

I wonder if anyone ever actually made use of it in a program?

User avatar
scarybeasts
Posts: 535
Joined: Tue Feb 06, 2018 7:44 am
Contact:

Re: Good test games / programs for an emulator

Post by scarybeasts » Mon Jan 27, 2020 6:20 am

dominicbeesley wrote:
Sun Jan 26, 2020 11:59 pm
@scarybeasts, that looks horrendous! I'll have to give it a go - though I've never done anything with tape images before! Will the tape images on STH contain this or will they have been sanitised?
The STH tape images do contain all the protected loaders. Lots of undocumented opcode goodness :) I suppose this is because a tape UEF is created based on an original tape WAV audio file, so no need to futz around with it. (On the other side of things, protected disc image formats are less standardized, not well supported, etc., so STH disc images are hacked up deprotected SSDs.)


Cheers
Chris

User avatar
scarybeasts
Posts: 535
Joined: Tue Feb 06, 2018 7:44 am
Contact:

Re: Good test games / programs for an emulator

Post by scarybeasts » Mon Jan 27, 2020 6:27 am

julie_m wrote:
Mon Jan 27, 2020 12:18 am
On an original NMOS 6502, indirect addresses across a page boundary are broken: the high byte of the address bus is not increased after reading the low byte of an address from the last byte within a page. For instance, JMP(&4BFF) gets the low byte of the address from &4BFF, but the high byte from &4B00 rather than the expected 4C00. This is of course only a problem at most 50% of the time ;) If you are careful how you align the low byte of an address to be always in an even address, then you will never encounter this behaviour.

I wonder if anyone ever actually made use of it in a program?
Yes! I'm current writing an emulator and instead of implementing the crazy corner cases, I usually put an assert(WTF). This way, I get to see and note which software is doing crazy things and also I can prioritize implementation based on which craziness occurs first / more often.

I first saw a JMP (&xxFF) in a PI digit calculation test case from another stardot thread. Attached here for posterity.


Cheers
Chris
Attachments
pi.ssd
(200 KiB) Downloaded 16 times

User avatar
scarybeasts
Posts: 535
Joined: Tue Feb 06, 2018 7:44 am
Contact:

Re: Good test games / programs for an emulator

Post by scarybeasts » Mon Jan 27, 2020 6:51 am

dominicbeesley wrote:
Sun Jan 26, 2020 11:59 pm

What I think it probably should be - this matches the 65c02 datasheet at http://datasheets.chipdb.org/Western%20 ... 65C02S.pdf

Code: Select all

	TMP = read(PC++);
	TMP = set_h(TMP, read(PC++));
	read(PC);					<-- dummy read ignored
	PC = read(TMP);
	PC = set_h(PC, read(TMP+1));
	fetch();
Does anyone know? If the WD 65c02 datasheet is the most correct.

I also note that the BeebEm original has a fudge for indirect addresses on a page boundary for the NMOS 6502 i.e. at &xxFF I will apply that too as I seem to recall it is right - not sure if the Dorman test check for that one!
This is a good resource for NMOS vs CMOS differences: http://6502.org/tutorials/65c02opcodes.html

The CMOS part fixes the page wrap failure in JMP (ind), but takes 1 extra cycle (unconditionally).

I don't know what the CMOS part is doing in the extra cycle. A 6502 is always reading or writing _some_ address every cycle. jsbeeb, which has good accuracy, doesn't seem to do what I might expect. The NMOS part, when doing carry fixup, typically reads the uncarried address in the extra cycle. So one possibility for the CMOS part would be:

For: JMP (&01FF)

read: JMP (ind) opcode
read: JMP operand 0xFF
read: JMP operand 0x01
read: addr 0x01FF
read: addr 0x0100 (uncarried address)
read: addr 0x0200 (carried address)

Unfortunately we don't have visual65c02 but a timing test can ascertain whether the uncarried address is being read, because some reads on a BBC have side effects (cycle stretching of 1MHz peripheral accesses). Something like timing JMP (&FE62) after setting &FE62 and &FE63 appropriately.


Cheers
Chris

dominicbeesley
Posts: 1126
Joined: Tue Apr 30, 2013 12:16 pm
Contact:

Re: Good test games / programs for an emulator

Post by dominicbeesley » Mon Jan 27, 2020 9:31 am

Thanks,

I'll bodge the 6502 to fail on xxFF jmps and add a //TODO to the 65c02 to check what it really does on the Master when I get it set up again.

On the Zalaga tape loader - it does look to be a warts and all one on STH - which doesn't work in the original BeebEm (it does in B-em) - any ideas why it wouldn't have worked in the original BeebEm? I'm trying to save myself from falling down too many rabbit holes but now my interest is piqued. This was supposed to be a quick'n'dirty hack of the blitter into BeebEm but is fast turning into a rewrite!

D

User avatar
scarybeasts
Posts: 535
Joined: Tue Feb 06, 2018 7:44 am
Contact:

Re: Good test games / programs for an emulator

Post by scarybeasts » Mon Jan 27, 2020 9:57 am

dominicbeesley wrote:
Mon Jan 27, 2020 9:31 am
On the Zalaga tape loader - it does look to be a warts and all one on STH - which doesn't work in the original BeebEm (it does in B-em) - any ideas why it wouldn't have worked in the original BeebEm? I'm trying to save myself from falling down too many rabbit holes but now my interest is piqued. This was supposed to be a quick'n'dirty hack of the blitter into BeebEm but is fast turning into a rewrite!
Couple of ideas:

1) I did notice that BeebEm has an option for how many of the undocumented opcodes it runs. The default for me was something like "common subset". However, the Zalaga opcodes are not common so check that setting?

2) General accuracy. BeebEm is not as accurate as b-em, which is not as accurate as jsbeeb. The more modern code bases were typically started with a better understanding of how the BBC actually ticks. I wouldn't personally recommend BeebEm as the best basis for any project requiring the utmost accuracy.


Cheers
Chris

dominicbeesley
Posts: 1126
Joined: Tue Apr 30, 2013 12:16 pm
Contact:

Re: Good test games / programs for an emulator

Post by dominicbeesley » Mon Jan 27, 2020 12:48 pm

Thanks,

I would have started with B-em but I couldn't get mingw to work, I didn't think of jsbeeb! I will have a look.

I misspoke earlier - original BeebEm didn't work (even with "full set" checked) however I must have tested with something set wrong on my version it works fine!

[Turns out I am still crap at Zalaga though 30 odd years of ageing and drinking have not improved my reflexes]

Post Reply

Return to “8-bit acorn emulators”