News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_lachlank

Detect 6128

Started by lachlank, 10:07, 25 August 09

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

lachlank

Hi all, what is the best way (from Basic or machine code) to detect a 128k machine (i.e. one that supports the kl_bank_switch call) vs a 64k machine?

Thanks,

Lachlan

Ygdrazil

Hi Lachlan

I don't know if it's the best way but the below is a fast way to test if a machine has more than the first 64kb ram available.

Code below #4000 or above #8000, address #4000 in 64Kb and first byte in 16kb bank corrupted.



org &1000

di

ld bc,#7f00
out (c),c
xor a
ld (&4000),a

ld c,#c4
out (c),c

ld a,#ff
ld (&4000),a
ld c,#c0
out (c),c

ld a,(&4000)
cp 0
jr z,found_expansion
ld hl,KB64
jr pr

.found_expansion
ld hl,KB128
.pr ld a,(hl)
cp 0
ret z
call &bb5a
inc hl
jr pr

.KB64 text "No expansion ram found",0
.KB128 text "Expansion ram found",0



Quote from: lachlank on 10:07, 25 August 09
Hi all, what is the best way (from Basic or machine code) to detect a 128k machine (i.e. one that supports the kl_bank_switch call) vs a 64k machine?

Thanks,

Lachlan

Ygdrazil

Sorry a typo crept in!

Corrected!

/Ygdrazil

Quote from: Ygdrazil on 13:09, 25 August 09
Hi Lachlan

I don't know if it's the best way but the below is a fast way to test if a machine has more than the first 64kb ram available.

Code below #4000 or above #8000, address #4000 in 64Kb and first byte in 16kb bank corrupted.



org &1000

di

ld bc,#7fc0
out (c),c
xor a
ld (&4000),a

ld c,#c4
out (c),c

ld a,#ff
ld (&4000),a
ld c,#c0
out (c),c

ld a,(&4000)
cp 0
jr z,found_expansion
ld hl,KB64
jr pr

.found_expansion
ld hl,KB128
.pr ld a,(hl)
cp 0
ret z
call &bb5a
inc hl
jr pr

.KB64 text "No expansion ram found",0
.KB128 text "Expansion ram found",0



lachlank

Ah yeah I wondered about that. Thanks.

Got another game in the pipeline so am experimenting with an "enhanced" 128k version :)

arnoldemu

Quote from: lachlank on 10:07, 25 August 09
Hi all, what is the best way (from Basic or machine code) to detect a 128k machine (i.e. one that supports the kl_bank_switch call) vs a 64k machine?

Thanks,

Lachlan
Hmmm.. you probably need to check the rom version numbers.. or possibly peek the location of that function in the firmware jumpblock to ensure it's valid.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Grim

A tad late for a reply, nevertheless both RAM banks and Jumpblock checks are necessary if your program uses _KL_BANK_SWITCH.

The _KL_BANK_SWITCH function is available in Firmware v2 (CPC 664) and up. So, if you only check that the RAM banks are available (eg. using the snippet posted by Ygdrazil), your program will crash on a CPC 464 (Firmware v1, no _KL_BANK_SWITCH available) with a RAM expansion. If you only check the jumpblock, your program will crash on a bare CPC 664 (Firmware v2 but 64K RAM only) and 464Plus too (Firmware v4 and 64K RAM only).

So you should first check the jumpblock to make sure the _KL_BANK_SWITCH is there, then check if there's any extra RAM available to enable the 128K features of your program.

A jumpblock check could be done like this:

_KL_BANK_SWITCH equ &BD5B

; check jumpblock
; firmware v1 has &EF,&37,&33 located at &BD5B
; (&33 XOR &37) XOR &EF = &EB
ld hl,(_KL_BANK_SWITCH)
ld a,(_KL_BANK_SWITCH+2)
xor h
xor l
cp &EB
jr z,no_kl_bank_switch
; KL_BANK_SWITCH is available
; proceed...


Another option would be to simply drop _KL_BANK_SWITCH and access directly to the MMR register with a single OUT instruction. It's safe (to some extent) and you won't have to bother anymore about the firmware version (assuming your program doesn't call specific Firmware v2+ functions).

Powered by SMFPacks Menu Editor Mod