3

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.)

5
  • 1
    The PCW's Mallard BASIC - though also written by Locomotive - ran under CP/M, so would be quite different
    – scruss
    May 28, 2020 at 13:51
  • @scruss: Do you know if they both locate the basic code at the same address $0170? May 28, 2020 at 14:47
  • very unlikely, as CP/M's TPA starts (IIRC) at 100h
    – scruss
    May 29, 2020 at 23:13
  • 1
    @scruss: Ah so Mallard BASIC runs on CP/M on the Amstrad and not natively? May 30, 2020 at 0:24
  • 1
    Yup. Mallard was originally written for CP/M on the BBC Micro Z80 Second Processor box. Although it was written by Locomotive Software, it's a CP/M program. It also came with the ZX Spectrum +3.
    – scruss
    Jun 22, 2021 at 13:43

5 Answers 5

4

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.

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

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

1
  • 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). Oct 14, 2020 at 18:18
3

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.

3

In Locomotive Basic the program is stored after the end of the ROM lower reserved area. There is a pointer to that, AE64hex on the 6128, AE81hex in the 464, according to the firmware guide. It's value is usually 016Fhex, so the Basic starts in the next position, at 170hex.

Usually other ROMs initialization don't reserve a lower area, and so the start is always found at 170hex, but it can be changed, by ROM or by user programs.

The other locations pointing to 170hex are initialized during LOAD or SAVE, and changing them have no permanent effect.

1
  • I've made a test ROM image that reserves space in the lower area and tested in in an emulator, and yes, the pointer at AE64 changes to 130hex bytes (the size the ROM Basic itself reserves for the token buffer) after the reserved space, and the Basic program is stored at that position.
    – NotFound
    Jul 7, 2021 at 14:05
0

In Geoffrey Childs' book PCW: Streamlined BASIC, he states in section 8.1 that:

… you will have to remember that the program start is normally 31382 in [Mallard BASIC] 1.29, and 31523 in 1.39

I don't have an Amstrad PCW8256 to try this on, but I do have a Spectrum +3, and this advice seems to be incorrect. Running a crude search program that looked for four known consecutive bytes in the first line, I found that BASIC starts a few bytes south of 31590: Spectrum +3 CP/M screenshot showing Mallard BASIC program

10 REM K@X% - DO NOT CHANGE
20 FOR A=256 TO 65530!
30 IF PEEK(A)=75 AND PEEK(A+1)=64 AND PEEK(A+2)=88 AND PEEK(A+3)=37 THEN PRINT "*** FOUND AT ";A:END
40 NEXT A
50 PRINT "NOT FOUND"
60 END

Nowhere is the Mallard BASIC start address mentioned in the Mallard BASIC: Introduction and Reference manual for the Amstrad PCW range. It may not be something you can rely on.

1
  • 2
    The Mallard BASIC supplied with Spectrum +3 CP/M is version 1.44, so the addresses Mr Childs gives for 1.29 and 1.39 won't apply. Using the technique in my answer I got a result of 31584 for Mallard 1.44, which seems a reasonable match for your result.
    – john_e
    Jun 29, 2021 at 1:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .