Author Topic: how do I detect a CPC plus in assembly?  (Read 3770 times)

0 Members and 1 Guest are viewing this topic.

Offline keith56

  • ちび悪魔!
  • Supporter
  • 6128 Plus
  • *
  • Posts: 572
  • Country: jp
  • Part Ma, Part Aku... All Chibi!
    • Chibi Akumas Assembly tutorials
  • Liked: 928
  • Likes Given: 211
how do I detect a CPC plus in assembly?
« on: 11: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
Chibi Akumas: Comedy-Horror 8-bit Bullet Hell shooter!
Learn ARM, 8086, Z80, 6502 or 68000 with my tutorials: www.assemblytutorial.com
My Livestreaming Channel: ChibiAkimas Live

Offline Duke

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.186
  • Country: dk
    • spinpoint.org
  • Liked: 1313
  • Likes Given: 1041
Re: how do I detect a CPC plus in assembly?
« Reply #1 on: 12:08, 13 December 16 »
You could check the basic ROM version to identify plus (v4 I think).

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2275
  • Likes Given: 3478
Re: how do I detect a CPC plus in assembly?
« Reply #2 on: 12: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.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline Ast

  • 6128 Plus
  • ******
  • Posts: 1.101
  • Country: fr
    • Amstrad cpc Website of Ast/iMPACT
  • Liked: 1001
  • Likes Given: 741
Re: how do I detect a CPC plus in assembly?
« Reply #3 on: 14: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, as always.

_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"


Amstrad Plus French Forum

All friends are welcomed !

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 913
  • Liked: 445
  • Likes Given: 73
Re: how do I detect a CPC plus in assembly?
« Reply #4 on: 15: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.

Offline keith56

  • ちび悪魔!
  • Supporter
  • 6128 Plus
  • *
  • Posts: 572
  • Country: jp
  • Part Ma, Part Aku... All Chibi!
    • Chibi Akumas Assembly tutorials
  • Liked: 928
  • Likes Given: 211
Re: how do I detect a CPC plus in assembly?
« Reply #5 on: 23:27, 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!
Chibi Akumas: Comedy-Horror 8-bit Bullet Hell shooter!
Learn ARM, 8086, Z80, 6502 or 68000 with my tutorials: www.assemblytutorial.com
My Livestreaming Channel: ChibiAkimas Live

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 913
  • Liked: 445
  • Likes Given: 73
Re: how do I detect a CPC plus in assembly?
« Reply #6 on: 00:09, 14 December 16 »
Disable interrupts during testing and make sure your code+stack are in a "safe" space.

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2275
  • Likes Given: 3478
Re: how do I detect a CPC plus in assembly?
« Reply #7 on: 11:16, 14 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).
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline keith56

  • ちび悪魔!
  • Supporter
  • 6128 Plus
  • *
  • Posts: 572
  • Country: jp
  • Part Ma, Part Aku... All Chibi!
    • Chibi Akumas Assembly tutorials
  • Liked: 928
  • Likes Given: 211
Re: how do I detect a CPC plus in assembly?
« Reply #8 on: 12: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!
Chibi Akumas: Comedy-Horror 8-bit Bullet Hell shooter!
Learn ARM, 8086, Z80, 6502 or 68000 with my tutorials: www.assemblytutorial.com
My Livestreaming Channel: ChibiAkimas Live

Offline Ast

  • 6128 Plus
  • ******
  • Posts: 1.101
  • Country: fr
    • Amstrad cpc Website of Ast/iMPACT
  • Liked: 1001
  • Likes Given: 741
Re: how do I detect a CPC plus in assembly?
« Reply #9 on: 12: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.


Code: [Select]
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


Code: [Select]
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 :


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


I really hope it would help you.
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"


Amstrad Plus French Forum

All friends are welcomed !

Offline Ast

  • 6128 Plus
  • ******
  • Posts: 1.101
  • Country: fr
    • Amstrad cpc Website of Ast/iMPACT
  • Liked: 1001
  • Likes Given: 741
Re: how do I detect a CPC plus in assembly?
« Reply #10 on: 19:27, 14 December 16 »
As I don't know what to do this afternoon, i wrote an article on Amstrad Plus Forum
Of course, this is only written in french language but remember one thing : "Google translate is your friend"


Thanks.
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"


Amstrad Plus French Forum

All friends are welcomed !

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 913
  • Liked: 445
  • Likes Given: 73
Re: how do I detect a CPC plus in assembly?
« Reply #11 on: 21: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!)

Offline Ast

  • 6128 Plus
  • ******
  • Posts: 1.101
  • Country: fr
    • Amstrad cpc Website of Ast/iMPACT
  • Liked: 1001
  • Likes Given: 741
Re: how do I detect a CPC plus in assembly?
« Reply #12 on: 21:56, 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".


« Last Edit: 22:00, 14 December 16 by Ast »
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"


Amstrad Plus French Forum

All friends are welcomed !

Offline roudoudou

  • 6128 Plus
  • ******
  • Posts: 890
  • Country: fr
    • urban exploration
  • Liked: 1188
  • Likes Given: 736
Re: how do I detect a CPC plus in assembly?
« Reply #13 on: 23:03, 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!
use RASM, the best assembler ever made :p

I will survive

Offline Skunkfish

  • Supporter
  • 6128 Plus
  • *
  • Posts: 596
  • Country: gb
  • Editor of Colour Personal Computing
    • CPCSTORE.CO.UK - Dedicated to the Amstrad CPC
  • Liked: 436
  • Likes Given: 1123
Re: how do I detect a CPC plus in assembly?
« Reply #14 on: 13: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...
An expanding array of hardware available at www.cpcstore.co.uk (and issue 3 of CPC Fanzine!)

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 913
  • Liked: 445
  • Likes Given: 73
Re: how do I detect a CPC plus in assembly?
« Reply #15 on: 20:25, 15 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.

Offline Ast

  • 6128 Plus
  • ******
  • Posts: 1.101
  • Country: fr
    • Amstrad cpc Website of Ast/iMPACT
  • Liked: 1001
  • Likes Given: 741
Re: how do I detect a CPC plus in assembly?
« Reply #16 on: 21:30, 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...
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"


Amstrad Plus French Forum

All friends are welcomed !

Offline dragon

  • 6128 Plus
  • ******
  • Posts: 1.491
  • Country: es
  • Liked: 634
  • Likes Given: 492
Re: how do I detect a CPC plus in assembly?
« Reply #17 on: 23: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 Register 0Ch, Bit 3. When removed, outputs LOW as 8th bit (as on classic CPCs with 7bit printer port). See also: 8bit Printer Ports."
« Last Edit: 23:17, 15 December 16 by dragon »

Offline Ast

  • 6128 Plus
  • ******
  • Posts: 1.101
  • Country: fr
    • Amstrad cpc Website of Ast/iMPACT
  • Liked: 1001
  • Likes Given: 741
Re: how do I detect a CPC plus in assembly?
« Reply #18 on: 23:29, 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 Register 0Ch, Bit 3. When removed, outputs LOW as 8th bit (as on classic CPCs with 7bit printer port). See also: 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 ?
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"


Amstrad Plus French Forum

All friends are welcomed !

Offline keith56

  • ちび悪魔!
  • Supporter
  • 6128 Plus
  • *
  • Posts: 572
  • Country: jp
  • Part Ma, Part Aku... All Chibi!
    • Chibi Akumas Assembly tutorials
  • Liked: 928
  • Likes Given: 211
Re: how do I detect a CPC plus in assembly?
« Reply #19 on: 06: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!

Chibi Akumas: Comedy-Horror 8-bit Bullet Hell shooter!
Learn ARM, 8086, Z80, 6502 or 68000 with my tutorials: www.assemblytutorial.com
My Livestreaming Channel: ChibiAkimas Live

Offline dragon

  • 6128 Plus
  • ******
  • Posts: 1.491
  • Country: es
  • Liked: 634
  • Likes Given: 492
Re: how do I detect a CPC plus in assembly?
« Reply #20 on: 10: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.
« Last Edit: 14:59, 23 January 17 by dragon »

Offline Ast

  • 6128 Plus
  • ******
  • Posts: 1.101
  • Country: fr
    • Amstrad cpc Website of Ast/iMPACT
  • Liked: 1001
  • Likes Given: 741
Re: how do I detect a CPC plus in assembly?
« Reply #21 on: 15: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...



_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"


Amstrad Plus French Forum

All friends are welcomed !

Offline Ast

  • 6128 Plus
  • ******
  • Posts: 1.101
  • Country: fr
    • Amstrad cpc Website of Ast/iMPACT
  • Liked: 1001
  • Likes Given: 741
Re: how do I detect a CPC plus in assembly?
« Reply #22 on: 15:12, 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 !
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"


Amstrad Plus French Forum

All friends are welcomed !

Offline Ast

  • 6128 Plus
  • ******
  • Posts: 1.101
  • Country: fr
    • Amstrad cpc Website of Ast/iMPACT
  • Liked: 1001
  • Likes Given: 741
Re: how do I detect a CPC plus in assembly?
« Reply #23 on: 15:39, 23 January 17 »
Gx4000 has no keyboard... Maybe we could use this to isolate Gx4000.
_____________________

Ast/iMP4CT. "By the power of Grayskull, i've the power"


Amstrad Plus French Forum

All friends are welcomed !

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2275
  • Likes Given: 3478
Re: how do I detect a CPC plus in assembly?
« Reply #24 on: 15: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?
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource