Best way to detect CPU program is running on?

Page 1/2
| 2

By WORP3

Paladin (804)

WORP3's picture

02-09-2018, 23:03

As the title is saying, what is the best way to detect which CPU is running the program?
Probably there are lot's of Turbo-R tutorials to switch between CPU's but is there a easy way to detect the current cpu, something that runs on all msx's ?

Login or register to post comments

By gdx

Prophet (3036)

gdx's picture

03-09-2018, 08:33

On turbo R you can use same method as Popolon-fr to determinate if the current mode is Z80 or R800 (see JoySNES manual, the link is in the wiki). This method uses an undocumented instruction.
On other MSXs and also the turbo, you can execute a long loop and count the time to determinate if the current mode is 3.57Mhz or turbo.

By Grauw

Ascended (8454)

Grauw's picture

03-09-2018, 09:14

First check the 002DH BIOS variable whether it is a turboR or higher, and then use the GETCPU BIOS call to determine the CPU mode.

; f <- nc: R800, c: not R800
IsR800Enabled:
    ld a,(002DH)
    cp 3
    ret c
    call GETCPU  ; 0183H
    cp 1
    ret

By WORP3

Paladin (804)

WORP3's picture

03-09-2018, 09:21

gdx wrote:

On turbo R you can use same method as Popolon-fr to determinate if the current mode is Z80 or R800 (see JoySNES manual, the link is in the wiki). This method uses an undocumented instruction.
On other MSXs and also the turbo, you can execute a long loop and count the time to determinate if the current mode is 3.57Mhz or turbo.

Wow so detecting the speed by just counting a specific loop is really the way to go? I was thinking about that but couldn't imagine that there wasn't some bios routine or I/O register that was telling you which cpu is running at a specific time.

Isn't it possible to just access register 0xE4/0xE5 to tell the cpu mode or will the absence on the non turbo-r computers screw this up?

By Grauw

Ascended (8454)

Grauw's picture

03-09-2018, 09:32

No measuring a loop is not the way to go… (unless you want to detect 7 MHz mod circuits)

Is my post invisible? Smile

By WORP3

Paladin (804)

WORP3's picture

03-09-2018, 10:03

Grauw wrote:

No measuring a loop is not the way to go… (unless you want to detect 7 MHz mod circuits)

Is my post invisible? Smile

Nope, but i've entered a quote edit mode before your message was visible Smile
Thanks for your reply !

By gdx

Prophet (3036)

gdx's picture

03-09-2018, 11:07

Method with an undocumented instruction is the faster.

Grauw wrote:

No measuring a loop is not the way to go… (unless you want to detect 7 MHz mod circuits)

Why would a loop with a counter that starts at one interrupt to another not work?

By luppie

Paladin (854)

luppie's picture

03-09-2018, 13:38

Because he want's to the detect the CPU type, not the CPU speed. Since there is 3.57Mhz - 6 Mhz - 7Mhz and in case of Gr8bit the speed can be 4 ~ 20 Mhz. The loop counter doesn't say anything about the CPU type only about it's speed.

By Grauw

Ascended (8454)

Grauw's picture

03-09-2018, 14:07

gdx wrote:

Method with an undocumented instruction is the faster.

Because it matters at all if a check that’s only done once executes in ten or a hundred microseconds?

You’re doing the wrong kind of optimisation.

By Wolverine_nl

Paragon (1037)

Wolverine_nl's picture

03-09-2018, 15:06

#2D is to check which MSX version, and between R800 and Z80 :
https://www.msx.org/wiki/R800_Programming#How_to_change_the_...

Why not combine the two, if TR is detected, then check if R800 is enabled or not.
This should work on all MSX types.
*edit:
In GR8CFG, a BASIC program, I detect MSX type, and if TR is detected I switch to Z80, updating via online option is dodgy when R800 is enabled.
So an idea is: You could force it to R800 when TR is detected and change it back, if a value has not changed, then it was on R800 and else it was on Z80. (never done this, just an idea) ;)

By Wolverine_nl

Paragon (1037)

Wolverine_nl's picture

03-09-2018, 15:14

But whats Grauw said seems the easiest lol, your post is not invisible LOL!

Page 1/2
| 2