How can I find where in memory to locate the current Basic program in an Amstrad CPC/PCW family Zilog Z80-based microcomputer?

  • Is it always the same address?
  • A different well-known address depending on the model, ROM version, or Basic version?
  • A changeable address that can be determined by looking at a certain system variable?

(On the Spectrum there's a system variable and cracks and demos also hardcoded some well-known addresses for the most common machine variants. I can't seem to find the equivalent for Amstrads by Googling.)

  • 1
    The PCW's Mallard BASIC - though also written by Locomotive - ran under CP/M, so would be quite different – scruss May 28 '20 at 13:51
  • @scruss: Do you know if they both locate the basic code at the same address $0170? – hippietrail May 28 '20 at 14:47
  • very unlikely, as CP/M's TPA starts (IIRC) at 100h – scruss May 29 '20 at 23:13
  • @scruss: Ah so Mallard BASIC runs on CP/M on the Amstrad and not natively? – hippietrail May 30 '20 at 0:24

With a bit of googling: http://www.cpcwiki.eu/forum/amstrad-cpc-hardware/memory-map/ (information is not very widespread, I could not find any confirmation somewhere else)

Basic starts at &170 and grows up to HIMEM. HIMEM is set around &b0ff for 464, but lower for other systems with extra roms attached because roms can reserve some ram if they need it.

So according to this link, the answer is (in hexadecimal): $170. The higher limit depends on the memory reserved by extra roms and can also be set by the HIMEM command.

  • 1
    Verified by writing a Basic program in an emulator that printed the CHR$ of each memory address by PEEKin there. Thanks. – hippietrail May 28 '20 at 8:28
  • I also remember reading in an Amstrad Magazine article that BASIC programs on CPC started at &170. – Medinoc May 31 '20 at 12:44

The Locomotive BASIC is a bit of an oddity as the start of the BASIC area is hardcoded to 0170h (for the CPCs) and no indirection via a pointer is given. Then again, location AE26h (*1) is checked when a program is LOADed, and usually contained $0170.

In general using RAM addresses is model-dependent as they got reshuffled every time. A good primary source for information about ram variables and structure is given by the The Amstrad CPC Firmware Guide. Some Magazines like the German CPC-Magazin did give enhanced version like in Issue 86/8-9 p.70ff.

A major site for more information about the CPC series would be cpctech.

*1 - For the 6128. The 464 uses AE3Fh

  • Thanks for mentioning ae26h and ae3fh which indeed appear in the Firmware Guide, but contain zero even if a program is created (I just tested). – Stéphane Gourichon Oct 14 '20 at 18:18

Under CP/M, the program start address in Mallard BASIC differs by version. I'm not aware of any fixed location that can be interrogated to find it; however, it may be possible to determine it by searching for a known piece of code that references the stored program.

In at least versions 1.29-1.48, SAVE writes out a magic number FC 04 at the start of the file, and the code that does this is followed by code that calculates the length of data to save:

LD A,0FCh       ;Magic number
CALL write_char
LD A,04h        ;File format version
CALL write_char
POP AF          ;Protected flag
CALL write_char
LD HL,(program_start) ; Start address of tokenised program (minus 1)

So, if you search memory for the byte pattern 3E FC CD xx xx 3E 04 CD xx xx F1 CD xx xx 2A the next two bytes will be the address of a word. That word is the address of the byte before the start of the program.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.