Author Topic: Emulator detection  (Read 5017 times)

0 Members and 1 Guest are viewing this topic.

Offline HAL 6128

  • 6128 Plus
  • ******
  • Posts: 516
  • Country: de
    • index.php?action=treasury
  • Liked: 256
  • Likes Given: 1349
Re: Emulator detection
« Reply #25 on: 23:42, 30 September 15 »

My question:  What are you doing that doesn't work on emulators?

If you would share the code with me I can make sure my emulator works with your code and that I can tell other people how to make their emulators work better too :)
...it was just a thought to shorten things. I'm coding a small "filemanager" for the CPC which should do things in the same way like the Midnight-Commander (show directory entries, copy, move, etc.) for FAT32 Harddiscs attached on Symbiface or X-Mass (...uses the &FD0x ports). Some ATA-Commands (e.g. the device-identify command) or Registers are not supported by WinApe. If I could detect WinApe I could jump over some subroutines...
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2275
  • Likes Given: 3478
Re: Emulator detection
« Reply #26 on: 11:31, 01 October 15 »
@HAL6128:

Question, does Winape give you an error condition when you try the commands it doesn't support?
Perhaps you can use that to detect it and the code is also valid to check for errors.

I think the ATA specification says that the commands *should* or *must* be supported but they can give errors if they are not.
The ATA specification is linked from the wiki article about Symbiface 2.
« Last Edit: 15:07, 01 October 15 by arnoldemu »
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1982
  • Likes Given: 4650
Re: Emulator detection
« Reply #27 on: 17:32, 01 October 15 »
No, that's not the case. You just wait for that bit to become '1' and it never does. So back to topic:


How to detect WinApe or Caprice? [nb]Once I did know that, but forgot, the programmer do know though. I clearly remember there is a way for winape, I used that in FutureOS system 5. a decade ago, but it's not there any longer, since not needed.[/nb]
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Offline Bryce

  • The Hardware Guy.
  • Supporter
  • 6128 Plus
  • *
  • Posts: 11.833
  • Country: wf
  • It's not broken, it just hasn't been fixed yet.
    • index.php?action=treasury
  • Liked: 4273
  • Likes Given: 450
Re: Emulator detection
« Reply #28 on: 17:46, 01 October 15 »
How about:

10 INPUT "Are you running this on an emulator (Y/N)";A$
20 IF A$="n" or A$="N" THEN GOTO 100
30 PRINT "Sorry this doesn't work on emulators."
40 END

:)

Bryce.

P.S: That's the upper limits of my programming skills!

Offline ||C|-|E||

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 1.852
  • Country: gb
    • index.php?action=treasury
    • Mundo CPC
  • Liked: 1031
  • Likes Given: 1125
Re: Emulator detection
« Reply #29 on: 18:03, 01 October 15 »
 :picard2:

Offline TotO

  • 6128 Plus
  • ******
  • Posts: 3.804
  • Country: fr
    • ?area=showdonations;u=4
  • Liked: 2910
  • Likes Given: 1747
Re: Emulator detection
« Reply #30 on: 18:27, 01 October 15 »
Simple and clever. Will always work!
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Offline HAL 6128

  • 6128 Plus
  • ******
  • Posts: 516
  • Country: de
    • index.php?action=treasury
  • Liked: 256
  • Likes Given: 1349
Re: Emulator detection
« Reply #31 on: 19:18, 01 October 15 »
@HAL6128:

Question, does Winape give you an error condition when you try the commands it doesn't support?
Perhaps you can use that to detect it and the code is also valid to check for errors.

I think the ATA specification says that the commands *should* or *must* be supported but they can give errors if they are not.
The ATA specification is linked from the wiki article about Symbiface 2.

I don't know if there's an error feedback. (I should read the specification!). The command works but the buffer in RAM is only filled with &FF instead of reasonable datas.
And yes, what a good idea... this could be a detection if the whole checksum for the sector is &FF. I had just tested the command with the emulators (WinCPC and WinApe) and they both return &FF. Let me check if the command will provide the same result on real hardware with NO X-MASS attached.
Thanks for the leading thoughts!

@Bryce : yes, I had your solution also in mind, honestly :)
« Last Edit: 19:22, 01 October 15 by HAL 6128 »
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1982
  • Likes Given: 4650
Re: Emulator detection
« Reply #32 on: 17:33, 02 October 15 »
10 INPUT "Are you running this on an emulator (Y/N)";A$
20 IF A$="n" or A$="N" THEN GOTO 100
30 PRINT "Sorry this doesn't work on emulators."
40 END


RUN
Are you running this on an emulator (Y/N) N

Line does not exist


 :doh:
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Offline TotO

  • 6128 Plus
  • ******
  • Posts: 3.804
  • Country: fr
    • ?area=showdonations;u=4
  • Liked: 2910
  • Likes Given: 1747
Re: Emulator detection
« Reply #33 on: 17:35, 02 October 15 »
 :laugh:
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Offline HAL 6128

  • 6128 Plus
  • ******
  • Posts: 516
  • Country: de
    • index.php?action=treasury
  • Liked: 256
  • Likes Given: 1349
Re: Emulator detection
« Reply #34 on: 22:28, 02 October 15 »
Ok, the "device_identify" command could work. On real hardware and no IDE interface attached the buffer is filled &FF and &F7 in random order. So a checksum over the first 16 bytes will be different to an emulators which is always &FF (at least tested with WinCPC, WinApe, Caprice and JavaCPC)...
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2275
  • Likes Given: 3478
Re: Emulator detection
« Reply #35 on: 22:37, 02 October 15 »
Ok, the "device_identify" command could work. On real hardware and no IDE interface attached the buffer is filled &FF and &F7 in random order. So a checksum over the first 16 bytes will be different to an emulators which is always &FF (at least tested with WinCPC, WinApe, Caprice and JavaCPC)...
Are you detecting if symbiface 2 or x-mass is connected?
Or are you detecting if ide drive is connected or not?

I would not assume to read 0x0ff or 0x0f7. This may just be bus noise. It is best if you check if sector/track register can be written and read back and that status register has expected bits (e.g. busy) and that when you write a command (identify is good), that the bits change to show command is being executed, and then check the status to see result looks good.
You should also check if drq is set, this will tell you if bits are ready to read or not. This will then tell you there is a symbiface or x-mass device attached.
If you see a problem, best to tell Richard to fix it ;)

I think better to do this than to expect the buffer to be specific values because it may not always be true like this.

I am guessing that symbiface 2 doesn't buffer the sector, the buffer is on the ide device. Symbiface 2 is like a i/o port decode and pass through the data to the ide device.

The ATA spec is here, all commands are described here (later specs describe SMART and features like this):

http://www.t13.org/documents/UploadedDocuments/project/d1153r18-ATA-ATAPI-4.pdf

Symbiface 2 registers are here:

SYMBiFACE II:IDE registers - CPCWiki


My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline Bryce

  • The Hardware Guy.
  • Supporter
  • 6128 Plus
  • *
  • Posts: 11.833
  • Country: wf
  • It's not broken, it just hasn't been fixed yet.
    • index.php?action=treasury
  • Liked: 4273
  • Likes Given: 450
Re: Emulator detection
« Reply #36 on: 22:41, 02 October 15 »

RUN
Are you running this on an emulator (Y/N) N

Line does not exist


 :doh:

Of course. His main routine needs to start at 100!

Bryce.

Offline HAL 6128

  • 6128 Plus
  • ******
  • Posts: 516
  • Country: de
    • index.php?action=treasury
  • Liked: 256
  • Likes Given: 1349
Re: Emulator detection
« Reply #37 on: 21:26, 03 October 15 »
Are you detecting if symbiface 2 or x-mass is connected?
Or are you detecting if ide drive is connected or not?

I would not assume to read 0x0ff or 0x0f7. This may just be bus noise. It is best if you check if sector/track register can be written and read back and that status register has expected bits (e.g. busy) and that when you write a command (identify is good), that the bits change to show command is being executed, and then check the status to see result looks good.
You should also check if drq is set, this will tell you if bits are ready to read or not. This will then tell you there is a symbiface or x-mass device attached.
If you see a problem, best to tell Richard to fix it ;)

I think better to do this than to expect the buffer to be specific values because it may not always be true like this.

I am guessing that symbiface 2 doesn't buffer the sector, the buffer is on the ide device. Symbiface 2 is like a i/o port decode and pass through the data to the ide device.
I've detected it without any device attached on the CPC. Just the plain CPC.

I think it's what you said and TotO mentioned. The CPC is not perfect (versus the Emulator). I mean the noises around the extension bus or the drive belt speed variation during action.

Although the IDE emulation is not perfect it's not a problem. I'm glad that WinApe has at least one working.

But you are right. The proper way is using the status register and read them. This is normally what the PC does during BIOS boot.

The status register from WinApe deliver "&x11111111" whereas on a real CPC (with a X-Mass attached) it's "&x00000101". At least it says that DRQ = 0 (which should be as the spec describes), but ERR = 1, which worries a little bit because spec says it should also be cleared.
(Just a thought, maybe this register value could be the problem why BonnyDOS hangs in WinApe during initialising the ROM because it does something like a device identify???)

And yes, the sector (either reading, writing or device identify) will buffered by the ide device and you just have to  "INI" or "OUTI" it 512 times to RAM. The principle is the same X-MASS or Symbiface.
« Last Edit: 21:59, 03 October 15 by HAL 6128 »
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.915
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1123
  • Likes Given: 1900
Re: Emulator detection
« Reply #38 on: 02:40, 05 October 15 »
The program @Bryce provided is great, the trouble is punishing any Liars who want to fool it, unfortunately the suggestion I offered earlier crashes on a Real Amstrad. I presume the object here is to punish the Emulator user?
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline Bryce

  • The Hardware Guy.
  • Supporter
  • 6128 Plus
  • *
  • Posts: 11.833
  • Country: wf
  • It's not broken, it just hasn't been fixed yet.
    • index.php?action=treasury
  • Liked: 4273
  • Likes Given: 450
Re: Emulator detection
« Reply #39 on: 10:28, 05 October 15 »
The program @Bryce provided is great, the trouble is punishing any Liars who want to fool it, unfortunately the suggestion I offered earlier crashes on a Real Amstrad. I presume the object here is to punish the Emulator user?

Then how about:

10 INPUT "Are you running this on an emulator (Y/N)";A$
20 IF A$="n" or A$="N" THEN GOTO 100
30 PRINT "Sorry this doesn't work on emulators."
40 Load "Airwolf"

Bryce.

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.915
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1123
  • Likes Given: 1900
Re: Emulator detection
« Reply #40 on: 11:41, 05 October 15 »
Then how about:

10 INPUT "Are you running this on an emulator (Y/N)";A$
20 IF A$="n" or A$="N" THEN GOTO 100
30 PRINT "Sorry this doesn't work on emulators."
40 Load "Airwolf"

Bryce.


Followed by:


SAVE"emtst.bas",p


 :laugh:
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline TotO

  • 6128 Plus
  • ******
  • Posts: 3.804
  • Country: fr
    • ?area=showdonations;u=4
  • Liked: 2910
  • Likes Given: 1747
Re: Emulator detection
« Reply #41 on: 11:51, 05 October 15 »
Line 40 ? Airwolf only for emulator users! :-\
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1016
  • Likes Given: 926
Re: Emulator detection
« Reply #42 on: 13:00, 05 October 15 »
Best:
Make a check:
Press CTRL, SHIFT + ESC to continue ;)
(PC can handle max. 2 keys simulteanously, perhaps 3, but this combination is impossible)
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Bryce

  • The Hardware Guy.
  • Supporter
  • 6128 Plus
  • *
  • Posts: 11.833
  • Country: wf
  • It's not broken, it just hasn't been fixed yet.
    • index.php?action=treasury
  • Liked: 4273
  • Likes Given: 450
Re: Emulator detection
« Reply #43 on: 13:24, 05 October 15 »
Line 40 ? Airwolf only for emulator users! :-\

Well AMSDOS said he wanted them to suffer. You can replace Airwolf with any other CPC disaster you care to choose.

Bryce.

Offline TotO

  • 6128 Plus
  • ******
  • Posts: 3.804
  • Country: fr
    • ?area=showdonations;u=4
  • Liked: 2910
  • Likes Given: 1747
Re: Emulator detection
« Reply #44 on: 14:49, 05 October 15 »
(PC can handle max. 2 keys simulteanously, perhaps 3, but this combination is impossible)
On R-Type, a hidden screen is shown if you press 'S' 'P' 'C' 'Y' simultaneously when loading.
Originally, it was 'S' 'P' 'E' 'C' 'Y', but it reported to not work on emulators...  ;)
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1016
  • Likes Given: 926
Re: Emulator detection
« Reply #45 on: 15:12, 05 October 15 »
On R-Type, a hidden screen is shown if you press 'S' 'P' 'C' 'Y' simultaneously when loading.
Originally, it was 'S' 'P' 'E' 'C' 'Y', but it reported to not work on emulators...  ;)

It's because the keyboard clash in real hardware.
No emulator (except JavaCPC, and I think, Kevin added it to Arnold) emulates this yet...
In JavaCPC you can press combinations with virtual keyboard  :laugh: :P
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2275
  • Likes Given: 3478
Re: Emulator detection
« Reply #46 on: 15:26, 05 October 15 »
It's because the keyboard clash in real hardware.
No emulator (except JavaCPC, and I think, Kevin added it to Arnold) emulates this yet...
In JavaCPC you can press combinations with virtual keyboard  :laugh: :P
Yes I added it to the "mythical" Arnold wip ;)
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2275
  • Likes Given: 3478
Re: Emulator detection
« Reply #47 on: 15:44, 05 October 15 »
I've detected it without any device attached on the CPC. Just the plain CPC.

I think it's what you said and TotO mentioned. The CPC is not perfect (versus the Emulator). I mean the noises around the extension bus or the drive belt speed variation during action.

Although the IDE emulation is not perfect it's not a problem. I'm glad that WinApe has at least one working.

But you are right. The proper way is using the status register and read them. This is normally what the PC does during BIOS boot.

The status register from WinApe deliver "&x11111111" whereas on a real CPC (with a X-Mass attached) it's "&x00000101". At least it says that DRQ = 0 (which should be as the spec describes), but ERR = 1, which worries a little bit because spec says it should also be cleared.
(Just a thought, maybe this register value could be the problem why BonnyDOS hangs in WinApe during initialising the ROM because it does something like a device identify???)

And yes, the sector (either reading, writing or device identify) will buffered by the ide device and you just have to  "INI" or "OUTI" it 512 times to RAM. The principle is the same X-MASS or Symbiface.
My advice is to make it work with the real device. Emulators should be fixed :)

With Arnold WIP, when I implemented Symbiface 2 IDE I didn't test it against a real HD yet. That is my next plan - but I needed to finish testing the Kempston Mouse first.
I followed the ATA spec and I tested it against SymbOS and BonnyDOS.

BonnyDOS works on Arnold WIP, I can partition, format and use it. :)

SymbOS partially works but because I didn't have an appropiate MBR setup on my emulated hard disc it didn't recognise the disc. I haven't yet implemented reading/writing of hard disc images which I need to do. When I've done that I'll support Winape's IDE file structure (which Richard has described to me :) ).

So I'll be testing on real HD and making it closer to that. I believe it's the ONLY way to get an accurate working emulation.

(I have also implemented Dobbertin HD and Vortex HD in Arnold WIP, both are experimental because I don't have access to the hardware to test them as much as I would like to).

I am also suprised that the status register is reporting an error. ATA Spec also says it's reporting something in an unused bit. Looking at an earlier specification (ATA-1):

http://www.t13.org/documents/UploadedDocuments/project/d0791r4c-ATA-1.pdf

The status register is reporting:

1. ERR
2. CORR - Corrected Data. A correctable data error was encountered and the data has been corrected.

When the drive (or in this case the plugin Drive module in the X-MASS) is reset it performs a startup sequence. In this startup sequence perhaps it encountered this recoverable error and signalled it?
I don't really know enough about the startup sequence for HD drives.

What value does the Error register return? This should tell you more.


My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline HAL 6128

  • 6128 Plus
  • ******
  • Posts: 516
  • Country: de
    • index.php?action=treasury
  • Liked: 256
  • Likes Given: 1349
Re: Emulator detection
« Reply #48 on: 23:40, 05 October 15 »
Your emulator WIP sounds very promising. Maybe TFM can help with the Dobbertin HD testing?

Interesting ATA spec!

For a future vision I also want to support partitioned drives connected to the Symbiface. The X-MASS DOM supposed not to be partitioned (and won't make sense) and it's more efficient to handle it with a FAT16 file system (as TotO and SyX intend) with their ACMEDOS.

At the moment I try to copy parts of a real HD-Image into WinApe IDE File with the help of a Hex-Editor. The first sector starts at &a00. For testing purposes I fill this sector with a MBR datas.

I didn't check the Error Status register so far. This will be my next step. Maybe I also did a programing failure. I only asked the Status Register once. I found an article on ATA PIO Mode - OSDev Wiki which explained some booting details. I should poll the Status Register until reaching the right status!?

Let me see.
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1982
  • Likes Given: 4650
Re: Emulator detection
« Reply #49 on: 00:06, 06 October 15 »
I will have access to my HD20 at X-MASS, but I know that other people in the forum own one. If a hard-disc-image or something like this is needed then let me know, so I can write a backup tool / disc image creator or something.
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus