Lousy 128K program crashing on 64K machine sucks.
The following routine, aimed to be short and fast, should detect a regular 128K RAM machine. For more informations about extended RAM management in the CPC/Plus, read the MMR register description.
; Usage exemple ; call quick_128k_detection ; jr z,CPC_64K ; Quick 128K Detection routine ; ; The test will corrupt two bytes in the extended RAM bank 0/page 0 ; when available. This should not be a problem since this routine ; should be called before actually using any of this extended RAM. ; ; Output ; - Zero flag is set on a 64K RAM machine ; - All extended RAM banks (if available) will be paged out. quick_128k_detection: ; Initialize some CPU registers ld bc,&7F00 ld hl,&C4C0 ; Make sure the possible extended RAM banks are paged out out (c),l ; Preserve the two bytes in the base64K RAM we are going to modify ld de,(&4000) ; Write a two bytes marker (&7F00) in the base 64K RAM at &4000 ld (&4000),bc ; Try to page in extended RAM bank 0/page 0 from &4000 to &7FFF out (c),h ; Write another two bytes marker (&7EFF) in the extended RAM at &4000 dec bc ld (&4000),bc ; Page out extended RAM (if available) out (c),l ; Read two bytes at &4000 from the base64K RAM ld hl,(&4000) ; Compare them with the two bytes marker of the extended RAM or a sbc hl,bc ; Restore the two modified bytes and exit ld (&4000),de ret