CPCWiki forum

General Category => Programming => Topic started by: keith56 on 10:30, 13 December 16

Title: how do I detect a CPC plus in assembly?
Post by: keith56 on 10:30, 13 December 16
I'm working on the hardware detect code for my game, and I need to identify the following 3 classes of machine :  Cpc 464 / Cpc 6128 / CPC 6128+

For 128k detection I am doing a bankswitch command and checking if the memory contents actually changed. (Note: I don't care about the firmware differences - I only need the extra ram)
For Plus detection I was going to do the same, using some code to turn on the ASIC, and copy a few bytes of ram at 4000 to 2000, and comparing them to the normal memory

The trouble is, when run on a non plus machine, the plus commands are switching on the firmware, which also resides around 2000, and my code thinks the machine is a plus when it is not - and then crashes!

Is there a better 'official' way to check if a machine is a CPC plus? it feels I am doing this wrong!

Thanks,

Keith
Title: Re: how do I detect a CPC plus in assembly?
Post by: Duke on 11:08, 13 December 16
You could check the basic ROM version to identify plus (v4 I think).
Title: Re: how do I detect a CPC plus in assembly?
Post by: arnoldemu on 11:26, 13 December 16
Enable asic ram, write a byte to the sprite ram and see it's masked (high byte read is set to 0).
Do similar for some other bytes.
Title: Re: how do I detect a CPC plus in assembly?
Post by: Ast on 13:08, 13 December 16
The Best Way to detect cpc plus without enabling cpc plus features will be using the ppi bug or the im2 mode.
More informations on QuasarNet (http://quasar.cpcscene.net/doku.php?id=coding:test_crtc), as always.

Title: Re: how do I detect a CPC plus in assembly?
Post by: andycadley on 14:40, 13 December 16
If your code to switch on the ASIC is paging in the Firmware, I suspect you have a bug in it somewhere. That's definitely the best way to do things.
Title: Re: how do I detect a CPC plus in assembly?
Post by: keith56 on 22:27, 13 December 16
Quote from: andycadley on 14:40, 13 December 16
If your code to switch on the ASIC is paging in the Firmware, I suspect you have a bug in it somewhere. That's definitely the best way to do things.

It only happens on the Non plus, the firmware stays off on a plus machine,

This is the command which causes it:
      ld bc,&7fb8
      out (c),c
It turns on the Asic memory on the plus, but on the non plus it turns on the firmware

I copied it, and the Plus-enable code from the sprite example on CPCWIKI!
Title: Re: how do I detect a CPC plus in assembly?
Post by: andycadley on 23:09, 13 December 16
Disable interrupts during testing and make sure your code+stack are in a "safe" space.
Title: Re: how do I detect a CPC plus in assembly?
Post by: arnoldemu on 10:16, 14 December 16
Quote from: keith56 on 22:27, 13 December 16
It only happens on the Non plus, the firmware stays off on a plus machine,

This is the command which causes it:
      ld bc,&7fb8
      out (c),c
It turns on the Asic memory on the plus, but on the non plus it turns on the firmware

I copied it, and the Plus-enable code from the sprite example on CPCWIKI!
that is correct, cpc ignores bit 5 of the data (b8 in this case).
Title: Re: how do I detect a CPC plus in assembly?
Post by: keith56 on 11:08, 14 December 16
I got everything sorted, I copied my plus code from the examples without decoding what it did (as it worked on a plus)

I read through this article, and it made it all clear!:
http://cpctech.cpc-live.com/docs/arnold5a.html

I'm now using these commands to turn the asic on:
      ld bc,&7fb8
      out (c),c
      ld bc,&7f8C
      out (c),c
And these to turn it off:
      ld bc,&7fA8
      out (c),c
      ld bc,&7f8C
      out (c),c

They get the asic on/off , and end with everything in a good state for my code - the code doing this is around &FF00 - so turning on the lower rom doesn't hurt it.

I notice the Gate array page (Which I have printed and laminated as my idiots guide) says bit 5 is unused - maybe it should mention the new Asic function?
http://www.cpcwiki.eu/index.php/Gate_Array

Thanks for the help! I got there in the end!
Title: Re: how do I detect a CPC plus in assembly?
Post by: Ast on 11:40, 14 December 16

For the second and last time, There is no need to unlock asic to detect plus machine...
Here is the piece of code using in iMPdraw to detect if i'm on Amstrad Plus or Amstrad Cpc.


Just Try it and forget bad things !
This test is based on PPi reset.



ld bc,#F782
ld e,c
out (c),c
dec b
ld c,#0f
out (c),c
inc b
ld a,e
out (c),a
dec b
in a,(c)
cp c
jr z,CpcPlus
or a
jr z,CpcOld



Last words, when you said using this command to turn off the asic



ld bc,#7fa8
out (c),c



Don't you really know what you're doing ?
Page  Asic is deconnected but rom #87 is connected to the plage #0000-#3FFF


So, the correct way to turn off the asic will be :



ld bc,#7fa0 ; turn asic off and connect rom #80 into plage #0000-#3FFF
out (c),c



I really hope it would help you.
Title: Re: how do I detect a CPC plus in assembly?
Post by: Ast on 18:27, 14 December 16
As I don't know what to do this afternoon, i wrote an article on Amstrad Plus Forum (http://amstradplus.forumforever.com/t275-Detecter-un-Cpc-Plus-ou-un-Cpc-Old.htm#p3216)
Of course, this is only written in french language but remember one thing : "Google translate is your friend"


Thanks.
Title: Re: how do I detect a CPC plus in assembly?
Post by: andycadley on 20:32, 14 December 16

I think that highlights why I don't particularly like it as a technique, you're detecting one thing and assuming something else based upon it which is inherently fragile (emulators may not behave correctly, revisions of CPCs or clones might be mis-detected etc.) Whereas with the "turn on the ASIC and check it exists" method you are literally testing the thing you want to use, a much more reliable mechanism.


What's more, you're presumably testing with the intention of using Plus features, so you're going to have the ASIC unlocking code available anyway, you may as well use it rather than keeping some other code around (especially given that following your test the very next step is liable to be Call UnlockASIC!)
Title: Re: how do I detect a CPC plus in assembly?
Post by: Ast on 20:56, 14 December 16
Quote from: andycadley on 20:32, 14 December 16
What's more, you're presumably testing with the intention of using Plus features, so you're going to have the ASIC unlocking code available anyway, you may as well use it rather than keeping some other code around (especially given that following your test the very next step is liable to be Call UnlockASIC!)
You'll be right if the final way would be to use Cpc Plus featuring.
-Delock Asic-Connect i/o Page-Poke any value in Asic Page (where we could read this value)-Deconnect i/o Page.


But just imagine, you wanna do a proggy who will have to work on all Cpc incluing the plus range. You have no obligation to delock Asic to know you're on an Amstrad Plus.


Delocking Asic must only be done when you want to use the "plus" mode. My goal was to propose you "a proper solution".


Title: Re: how do I detect a CPC plus in assembly?
Post by: roudoudou on 22:03, 14 December 16
Quote from: Ast on 20:56, 14 December 16
Delocking Asic must only be done when you want to use the "plus" mode. My goal was to propose you "a proper solution".


The proper solution is to ask the user  :P


Because maybe he will want to see the CPC version without plus feature, like prehistorik 2 for example. End user has the choice!
Title: Re: how do I detect a CPC plus in assembly?
Post by: Skunkfish on 12:33, 15 December 16
I'm actually all in favour of a start-up option for this rather than detection, mainly because I'd be interested in trying both options on my 6128+ to see how they compare...
Title: Re: how do I detect a CPC plus in assembly?
Post by: andycadley on 19:25, 15 December 16

Quote from: Ast on 20:56, 14 December 16
But just imagine, you wanna do a proggy who will have to work on all Cpc incluing the plus range. You have no obligation to delock Asic to know you're on an Amstrad Plus.
If it has to work on all CPC's, why would you need to detect a Plus machine? And none of the methods that don't involve unlocking the ASIC guarantee that you aren't using something else, they're all things that could be fooled by external hardware or that might fail on clones, emulators etc.
Title: Re: how do I detect a CPC plus in assembly?
Post by: Ast on 20:30, 15 December 16
Quote from: andycadley on 19:25, 15 December 16
If it has to work on all CPC's, why would you need to detect a Plus machine? And none of the methods that don't involve unlocking the ASIC guarantee that you aren't using something else, they're all things that could be fooled by external hardware or that might fail on clones, emulators etc.
if you need to do a crtc adaptation, for example...
I'm thinking about iMPdraw, for the story... I need to do a crtc adaptation, so I need to know where i'm working...
Title: Re: how do I detect a CPC plus in assembly?
Post by: dragon on 22:13, 15 December 16
Taking apart the gx4000(i assume is a dsk aplication).

Is not possible detect if is a normal cpc or a plus detecting if it have 7 bit printer port or 8 bit?.

Only plus have 8 bit printer, even if you add 8 bit to the normal cpc they not are controlled by the Bit 3 of crtc Register 0Ch.

Just a Theory reading the arnold v especification.

"When installed (default), enables the 8th printer bit, controlled via CRTC (http://www.cpcwiki.eu/index.php/CRTC) Register 0Ch, Bit 3. When removed, outputs LOW as 8th bit (as on classic CPCs with 7bit printer port). See also: 8bit Printer Ports (http://www.cpcwiki.eu/index.php/8bit_Printer_Ports)."
Title: Re: how do I detect a CPC plus in assembly?
Post by: Ast on 22:29, 15 December 16
Quote from: dragon on 22:13, 15 December 16
Taking apart the gx4000(i assume is a dsk aplication).

Is not possible detect if is a normal cpc or a plus detecting if it have 7 bit printer port or 8 bit?.

Only plus have 8 bit printer, even if you add 8 bit to the normal cpc they not are controlled by the Bit 3 of crtc Register 0Ch.

Just a Theory reading the arnold v especification.

"When installed (default), enables the 8th printer bit, controlled via CRTC (http://www.cpcwiki.eu/index.php/CRTC) Register 0Ch, Bit 3. When removed, outputs LOW as 8th bit (as on classic CPCs with 7bit printer port). See also: 8bit Printer Ports (http://www.cpcwiki.eu/index.php/8bit_Printer_Ports)."
iT would be a good idea but it won't work if you displayed a fullscreen picture.
Have you already forgotten the overscan bits ?
Title: Re: how do I detect a CPC plus in assembly?
Post by: keith56 on 05:03, 16 December 16
I think anything we do to detect a Plus / Non plus needs to work reliably on Emulators that do not support Plus features.

I would say most people playing CPC games are using emulators, and a great number of them do not have any CPC+ support - so any detection routine needs to detect as a Non plus and not crash on those emulators!

Title: Re: how do I detect a CPC plus in assembly?
Post by: dragon on 09:42, 23 January 17
@ast mostly i don't know It.


Another question about detect  the Plus range. Is possible diference
where is the program running in the gx4000, the 6128+ or the 464+?.


You can detect a 6128+  or 464+ /gx4000 detecting the fdc controller, But is possible detect the cassette?. To diference between 464+/gx4000?. I speak about only plus range, executing  the Code from cartridge.


Maybe is possible detect gx4000 made some type of internal benchmark.(because the gx4000 is 0.25℅ slow.).


Or this can work:


1: select logical Page 07 in upper rom.
2: Load one byte of the ROM in a register.
3. Load pysicall Page 1 in upper rom.
4.Move a to b
5.load the same direction in upper ROM in register A.
6 a cp b.
7. If a and b registers are equal, then you are in the gx4000 jump to 8 else jump to 9. Restore ROM page to original.
8. Finish.gx4000 detected
9. 464+ or 6128+ detected. Detect fdd  controller
10 fdc detected 6128+ finished
11. No fdc 464+ detected finished.





About detect plus/not Plus funny  Mode. Write in screen calibrating joysticks please press XxX. Simultaneously.Then keyboard Clash=old range no Clash=plus.
Title: Re: how do I detect a CPC plus in assembly?
Post by: Ast on 14:06, 23 January 17

Hi Dragon,

Detecting fastly 6128+ or 464+ and just read what you have in #0039.


If result is #41 you've a 6128 plus
If result is #39 your Cpc is a 464 plus
...
Detecting a gx4000 is more difficult ! The only thing i'm thinking is There is no basic rom on gx4000!
But, but, but... if you run anything on gx4000, it will probabily be a cpr rom. So this cpr rom will not countain the basic rom too... arg... good question...
If someone else Has any idea...



Title: Re: how do I detect a CPC plus in assembly?
Post by: Ast on 14:12, 23 January 17
Quote from: dragon on 09:42, 23 January 17
About detect plus/not Plus funny  Mode. Write in screen calibrating joysticks please press XxX. Simultaneously.Then keyboard Clash=old range no Clash=plus.
Please give me more informations about what you're writing because i don't really understand...


Detecting The rom7 or basic to know if you have a gx4000 or not will not Work...
Because all cpr rom are empty in The beginning.
If you're making some game, demo, tool, working on The range plus (in cartridge format), these roms won't be present !
Title: Re: how do I detect a CPC plus in assembly?
Post by: Ast on 14:39, 23 January 17
Gx4000 has no keyboard... Maybe we could use this to isolate Gx4000.
Title: Re: how do I detect a CPC plus in assembly?
Post by: arnoldemu on 14:40, 23 January 17
GX4000 will not respond to:

ld bc,&df07
out (c),c

On GX4000 you do not get cart page 3.

So try df07, and then df83 and compare some bytes. You will know if you have gx4000 or not.

Why do you need to specific check for gx4000?
Title: Re: how do I detect a CPC plus in assembly?
Post by: dragon on 14:41, 23 January 17
Quote from: Ast on 14:12, 23 January 17
Please give me more informations about what you're writing because i don't really understand...


Detecting The rom7 or basic to know if you have a gx4000 or not will not Work...
Because all cpr rom are empty in The beginning.
If you're making some game, demo, tool, working on The range plus (in cartridge format), these roms won't be present !


O.k explain  the theory of all better.

Taking this from arnold v specification revised.: Executing from cartridge (only 6128+ 464+ and gx4000 posibility).

"On an unmodified GX4000, selecting logical page 7 using DFxx doesn't select physical page 3, instead it selects physical page 1. The appropiate hardware is not activated as it is on 464 and 6128."

So my theory is,If you made a game or program in cartridge, you know what data is in the rom. So if you mount logical id 07 and the content is equal to pysicall id 1 in cartridge, you have a gx4000. If not you have a 464+ or 6128+

And 464+ or 6128+ can be filtered  cheking if fdc is present.

The utilitiy of this is my laser squad cartridge(for example).gx4000 detected->not save,464+ detected load save in tape,6128+ detect load save from disc.

The part of normal range is mostly a joke,  The old cpc have keyboard atribute clash. I mean if you press up right in pad 1 and up only in pad 2, cpc detects player 2 has been pressed right to, as the plus have diodes it detect only up :) .


But in seriusly mode. I think now, that pysicall id only exist in the plus range, old cpc have only logical ids to select roms, so maybe this can  be a way to diference between plus and normal?.

@arnoldemu (http://www.cpcwiki.eu/forum/index.php?action=profile;u=122) yeah, is was i telll +-
Title: Re: how do I detect a CPC plus in assembly?
Post by: arnoldemu on 14:43, 23 January 17
For 464plus or 6128plus why need to check special? Why not check extra ram or detect fdc?

detect extra ram (same as on cpc). You poke to 4000, try 7fc4, poke to 4000, 7fc0, then check 4000. If extra ram byte doesn't change.

detect fdc: amsdos rom for plus has this code.
Title: Re: how do I detect a CPC plus in assembly?
Post by: arnoldemu on 14:47, 23 January 17
Yes the physical cart page number and logical page numbers exist on plus.

On CPC you don't see this.

To detect CPC or Plus, you can use PPI test OR page in registers and write data and read it back.

Title: Re: how do I detect a CPC plus in assembly?
Post by: arnoldemu on 14:50, 23 January 17
Quote from: dragon on 09:42, 23 January 17
You can detect a 6128+  or 464+ /gx4000 detecting the fdc controller, But is possible detect the cassette?. To diference between 464+/gx4000?. I speak about only plus range, executing  the Code from cartridge.
Detecting cassette: I can't think of a method that would work.

Title: Re: how do I detect a CPC plus in assembly?
Post by: Ast on 14:54, 23 January 17
Detecting gx4000 using basic rom or amsdos won't work !
There is no basic rom or amsdos in cartridge you made. You don't need it.
Title: Re: how do I detect a CPC plus in assembly?
Post by: arnoldemu on 15:03, 23 January 17
Quote from: Ast on 14:54, 23 January 17
Detecting gx4000 using basic rom or amsdos won't work !
There is no basic rom or amsdos in cartridge you made. You don't need it.
correct.

I think @dragon (http://www.cpcwiki.eu/forum/index.php?action=profile;u=251) means the basic page or amsdos page (page 1 and 3).

You can detect gx4000 by setting the rom using logical page number, then use physical number. On GX4000 logical page 7 doesn't activate physical page 3. On 6128Plus and 464Plus logical page 7 *DOES* activate physical page 3.

Title: Re: how do I detect a CPC plus in assembly?
Post by: dragon on 16:02, 23 January 17
Quote from: arnoldemu on 14:43, 23 January 17
For 464plus or 6128plus why need to check special? Why not check extra ram or detect fdc?

detect extra ram (same as on cpc). You poke to 4000, try 7fc4, poke to 4000, 7fc0, then check 4000. If extra ram byte doesn't change.

detect fdc: amsdos rom for plus has this code.

Yeah it do it now!. My last version detect if you have fdc with amsdos code  :) I only left make the support for 464+ tape, now that cdt has been dumped i can do it extracting the original subrutine from the cdt.


Quote from: arnoldemu on 15:03, 23 January 17
correct.

I think @dragon (http://www.cpcwiki.eu/forum/index.php?action=profile;u=251) means the basic page or amsdos page (page 1 and 3).

You can detect gx4000 by setting the rom using logical page number, then use physical number. On GX4000 logical page 7 doesn't activate physical page 3. On 6128Plus and 464Plus logical page 7 *DOES* activate physical page 3.



Thats it, is question about diference beetwenn pysicall pages and logicall pages.

The old cpc range have only logical pages to select the upper rom, basic and amsdos are in the 0 and 7. Plus have that, but apart from that it have pysicall id.

The logical pages in the plus  0,7 are redirected to the pysical 1,3 by the hardware for basic and amsdos compatibility.

The pysicall pages are the cartridge pages from 0-31

In the gx4000 the hardware part that redirects the 7 logical to the 3 pysicall is not installed, so it redirect to 1.

If write  df00 you calll logical id page 0
If write  df80 you call pisicall id page 0.

when bit 7 is 0,L logical id are called, when is 1,x,x,p pysicall id are called.

If i understand it o.k
Powered by SMFPacks Menu Editor Mod