Recognition of emulators.

ZXNet echo conference «code.zx»

From Aleksey Malov To All 1 May 2000

Greetings, All! I won’t quote Unbeliever about the subject, but I’ll just give the program, which performs this recognition. It is based on 2 features of the z80 processor that were not taken into account emulator authors: Feature number one, highlighted in one of the issues of the born dead newspaper - when when an interrupt arrives during command execution ld a,i (ld a,r) parity flag was set as if interrupts were disabled even if the latter were allowed. Feature number two, which has not received wide publicity: when the target arrives interrupt while executing the EI instruction, the processor does not respond to it as if interrupts were disabled for the duration of this command, and then enabled again. If the authors of emulators have already corrected the first feature in their creations, then perhaps they have not heard of the second feature. This program was tested only on one real Spectrum, so I I would like to hear the reaction of the program from the “happy” owners of emulators on their emuls. I wonder which emuls passed the test? It will be interesting to hear the opinions of owners of real computers when launching programs on which Ptoga believed that it was under emulation. For convenience, I also throw in a uue file with the source in text format with comments, as well as an executable program, in order to save you from the step compilations.Well, for those who just want to look at the text, I’ll throw it in: ;---------------------------------- org #6000 ;clean the screen di ld hl,#5aff ld (hl),#7 dec hl bit 3,h jr nz,$-5 xor a ld(hl),a or(hl) dec hl jr z,$-3 ;install im 2 ld hl,#fd00 ld de,#fd01 ld b,e ld c,l ld (hl),#fe ld a,h ld i,a ldir ld a,#c3 ;jp nn ld (#fefe),a ld hl,imob ld (#feff),hl im 2 ;decommission a bunch of NOPs ld hl,#8000 ld de,#8001 ld bc,#7dff ld (hl),0 ;nop ldir ld (hl),#c9 ;ret ei ;cursing ld e,0 ld hl, systems call prn ;enter the initial value into the counter ld a,#ff ld(count),a halt ld b,20 ;call a bunch of NOPs 20 times w1 call #8000 djnz w1 di ld a,(count) ;let's deactivate a bunch of EI commands (not to be confused with ;Eternity Industry ;) ) ld hl,#8000 ld de,#8001 ld bc,#7dfE ld (hl),#FD ;EI ldir ldc,a ld a,#ff ld(count),a ei halt ld b,20 ;call a bunch of EI commands 20 times w2 call #8000 djnz w2 di ;compare the number of ints in the first;and in the second cases with an accuracy of е 1 int'a ld a,(count) sub c inc a cp 3 ;if cf=1, then we are under the emulator, because ;z80 does not respond during EI command ;for interruptions => number of ints on real ;spectrum in the first and second measurements ;differs by more than 1 PUSH AF ei ;also if during the arrival of an interrupt ;executed the command ld a,i (ld a,r), ;the processor will consider that interrupts ;prohibited LD E,0 ld bc,0 w3 ld a,i jppo,real1 djnz w3 dec c jr nz,w3 inc e real1 push de ;we're swearing again ld e,#40 ld hl,report call prn ld b,40 call pause pop de pop af rl e xor a or e ;if in the first and second tests ;results correspond to real ;z80, then we print about it ld hl,realmes jr z,real ;otherwise we print that we are being emulated ld hl,emulmes real ld e,#60 call prn ;print press any key ld b,100 call pause ld hl,anykey call prn ;query any key key xor a in a,(#fe) cpl and 31 jr z,key ;we go out to basic or somewhere else di ld a,#3f ld i,a im 1 ei ret ;procedure for printing a string at the top ;one third of the screen by teletype ;hl- asciiz-string ;e-ml. byteprn ld a,(hl):inc hl or a ret z push hl ld b,5 add a,a ld l,a cp " "*2 jr z,prn0 ld c,40 xor a beep ld b,c xor #18 out (#fe),a djnz $ dec c jr nz,beep inc b prn0 halt djnz prn0 ld h,0 add hl,hl add hl,hl ld a,h add a,#3c ld h,a ld b,4 ld d,#40 prn1 ld a,(hl) ld (de),a inc l inc d djnz prn1 ld b,4 prn2 ld a,(hl) srl a or (hl) ld (de),a inc l inc d djnz prn2 pop hl inc e jr prn ;мессаги sysmes db " 2000 Brainwave of X-Project. " db "System checking! Please wait... ",0 report db "System checking repot:",0 emulmes db " Warning! General failure: " db "CPU not found! Press F1 for " db "software emulation... ;-) ",0 realmes db "Congratulations!!! Test detected" db "the Real ZX-Spectrum. May be. ;)",0 anykey db "Press any key to exit...",0 pause halt djnz pause ret ;обработчик прерываний imob push af ld a,#3e count equ $-1 inc a ld (count),a pop af ei ret ;-------------------------------------------I wish you health, happiness and creative Uzbeks. Aleksey Malov aka VIVID/Brainwave.

From Kirill Frolov To Aleksey Malov 5 May 2000

Press RESET immediately, Aleksey! 01 May 00 01:22, Aleksey Malov wrote to All: AM> It is based on 2 features of the z80 processor that were not AM> taken into account by the authors of the emulators: AM> Feature number once, highlighted in one of the issues of the newspaper born AM> dead - when an interrupt arrives during the execution of the command ld a,i (ld AM> a,r) the parity flag was set as if there were interrupts Progressive emulators do not suffer from this, BUT THERE ARE REAL Z80 PROCESSORS WHERE THIS BUG HAS BEEN FIXED! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You should not use this in your programs to check for the emulator. AM> are prohibited even if the latter were allowed. Feature number two AM> not widely publicized: when a mocked interrupt arrives AM> while the EI command is running, the processor does not respond to it as if AM> interrupts would be disabled for the duration of this command, and then enabled AM> again. And this is a documented feature: The EI command disables interrupts for one command, then interruptions will be allowed. Needed for a secure return(without stack overflow) from the INT processing procedure. AM> If the authors of emulators have already corrected the first one in their creations AM> feature, then perhaps they have not heard of the second feature. But the second one should be used, I agree. And really Many (if not all) emulators do not support it. I hope not here enemies of the Spectrum who will reveal this terrible secret... Only the check will be like this: ei xxx: ld a, i jp pe, emulator ; I’m a little unsure, maybe someone can check? If that doesn’t work, then you can do this: (DEC A must be inserted into the INT processing procedure) ld a, a lot ei xxx: jr nz, $-1 but the first method works instantly, I’m just not sure that it works at all works. And during interruptions, the program must check whether it hits return address to mark xxx: ;;; dec a; for the second method push af push hl ld hl, 4 add hl, sp ld a, (hl) cpxxx%256 jr nz, noemul inc hl ld a, (hl) cpxxx/256 jr z emulator noemul: pop hl pop af ret AM> This program was tested only on one real Spectrum, therefore AM> I would like to hear from the “happy” owners of emulators AM> program reaction to their emuls. I wonder which emuls survived AM> test ? Shalaev and R80 say: CPU not found... But in ZXEMU and R80 the absence of a bug with LD A,I seems to have been fixed. PS: Will you have any problems with multi-field machines?

From Kirill Frolov To All 5 May 2000

Hемедленно нажми на RESET, All! 05 May 00 12:42, Kirill Frolov wrote to Aleksey Malov: KF> А это документиpованная фича: KF> Команда EI запpещает пpеpывания на одну команду, KF> потом пpеpывания будут pазpешены. Hужно для надежного возвpата KF> (без пеpеполнения стека) из пpоцедуpы обpаботки INT. KF> А вот втоpую надо использовать, согласен. И её действительно KF> не поддеpживают многие (если даже не все) эмулятоpы. Hадеюсь тут нет KF> вpагов спектpума, готоpые pазгласят эту стpашную тайну... Hашелся всё же один эмулятоp котоpый всё эмулиpует. R80 v0.30 в pежиме пентагона. А в pежиме скоpпиона и сам эмулятоp заглючил вместе с пpогpаммой :-/ Баг с эмуляцией ВГ там тоже частично пофиксен. Так пpосто, одним тестом все эмулятоpы не выявить, у каждого свои баги. Даже мысль такая пpишла, можно сделать тест эмулятоpов, котоpый пpи запуске pасскажет на каком эмулятоpе его запустили. Результаты тестиpования: эмулятоpы: баг: фича: LD A,I EI R80 - + SHALAEV - - UKV - - SPM - + ZXEMU * ? + поддеpживается - не поддеpживается * написано, что поддеpживается, но сам не пpовеpял ? неизвестно ТЕСТ ПРОГРАММА с исходником для STORM: section 1 of uuencode 5.21 of file emultest.zip by R.E.M. begin 644 emultest.zip M4$L#!!0``@`(`'V6I2A_Y)*Q<````!$!```'````14U53"XD0G/U#?51``(G M!P8'!@;&^Q4,7+P,?XV-S,W,^1@8_MF7U M7BDUMS1':3TO@QP?4!*DW`(HR=#`P-NPBI$!:*;2*4/>!I`F,Y"X+5#5'T< M"Y`)(1D9&.)I"!C(!P!02P,$%``"``@`A9:E*+'CFT+N````$0$```<```!E M;75L+B1#2TMS5$``F>&AB,,#(PJ^]F]HQG644.[NZ(<0U.,33SUU/3X^7 MP6Z?(L-^0<;]C`R,Y6WY*>;'5;O MH.[JJ:[@%.K.RR`A"A2!<14"@ER#7?U">!E^LZ6#7_4UL#R6^`[5(N/BX*C M#ER;)$@;DA!"Z]NPW^MO__OVP$;CYF'=5'1HH%C_=N@4_X- MK!RO7^8:QAL[_6+08W#F=G#U#?4!>Y#[P%Y&)CX7AOCM/C(=0(U$I"@ED*>*0W+OD7DC201? M9Y`8ED)G43!R%#ABP7N"4(@C_#;<42C9=86R%2[9*$Q+LS>A2%]J+,NZ M6F@L(X2OHM30*XVJH7_LF MR>@#P]/%-7OZ*56L[T1T;T^[Y`(!P.Q:A)A_S/8:J4Y;@B7L>1+<=7MX)$ M5'3H^&K+,50)8'(5=TQ-XHO]`6VUL$A]SS5BM$4/[P3^7`J+=5[CQ%`Q_(+_ MGM]02P,$"@``````IY:E*`SK7A`[````.P````L```!&24Q%7TE$+D1)6H]P MKJ-PH*RLH"#A(*CAY:ZDK:BJKJP@6U-43U)-72"DJ^@XJ7AXJAPKJ*@K:CO M(.VLXZOOXJYPKJ(N4$L!`AD`%``"``@`?9:E*'_DDK%P````$0$```<````` M`````0`@`````````$5-54PN)$)02P$"&0`4``(`"`"%EJ4HL>.;0NX````1 M`0``!P`````````!`"````"5````96UU;"XD0U!+`0(9`!0``@`(`'F6I2C? MVIA(C`$``!$"```'````````````(````*@!``!%355,+B1X4$L!`AD`"@`` M````IY:E*`SK7A`[````.P````L``````````0`@````60,``$9)3$5?240N M1$E:4$L%!@`````$``0`V````+T#``#5`@T*R>L;&QL;&QL;&QL;&QL;&QL;&QL;&QL;&QL;&QL;&Q ` end sum -r/size 40467/2675 section (from "begin" to "end") sum -r/size 656/1920 entire input file

From Oleg Grigoriev To Kirill Frolov 14 May 2000

Let your enemies, Kirill, die without sons! 9 May 2000 at 18:41, Kirill Frolov ═> Oleg Grigoriev: KF> Or maybe the download address is missing from the code block? KF> Did it even write “TESTING...”? After all, at 8000 it’s just right KF> is placed. I don't know what happened, but it still worked and wrote no 'ei' bug, 'ld a, i' bug present. Is this how it should be? although you are testing strangely - after all, interruptions are prohibited only for the time ei, and during commands that rotate the cycle, they allowed. with ld a, i everything seems to be correct. [WBR, Oleg. ] [ 17:25 14 May XXXV A.S. ]

From Kirill Frolov To Oleg Grigoriev 15 May 2000

Press RESET immediately, Oleg! 14 May 00 17:25, Oleg Grigoriev wrote to Kirill Frolov: OG> I don't know what happened, but it still worked and wrote no 'ei' bug, 'ld a, OG> i' bug present. Is this how it should be? Yes. You have an R80 emulator or a real Spectrum. OG> although you are testing strangely - after all, interruptions are prohibited only on OG> time ei, and during commands that rotate the loop, they are allowed. There will be no interruption only between the EI command and the following command. If the interrupt works at least once after EI - the emulator. THIS IS NOT RELIABLE There is a small chance that the emulator will not be recognized. That's right it would be possible to expand something like this: XOR A LD B, A L1: REPT a lot very EI ENDR D.I. JR NZ, EMULATOR DJNZ L1; should be >20ms even on a sprinter REALZX: ISR: INC A RET

From Yuri Teslenko To Aleksey Malov 27 May 2000

Howdy, Alexey! 9.05.2000 at 20:40 Aleksey Malov wrote to All: AM> There is a brutal way to recognize emulators. Based on the principle - AM> let's kill the enemy with the same weapon. I won’t reveal the principle itself - I don’t want it to Does the memory speed of all emulators (for example in TEST4.30) “float”? Or only in Shalaev? In real terms (even with a crooked int), the number does not change over time. Bye, Yuri. [I.ZX] [Chemists] [For full address] [Ski poles]