Memory questions

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Memory questions

Post by Ast A. Moore »

w00tguy wrote: Wed Apr 04, 2018 2:17 am I don't plan to use BASIC outside of the loader, but I have noticed I need to leave some room after 0x5CCB to allow BASIC to load my code. Good to know that it's free to use it after my program starts.
Well, it’s not 0x5CCB per se, but rather whatever’s held in the PROG system variable. The value will change depending on which peripherals are attached to the Spectrum (and initialized), so don’t just assume it’s 23755.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Memory questions

Post by Ralf »

If you don't need ALL existing memory you can safely do for example in standard Spectrum 48kB

Code: Select all

1 CLEAR 24000
2 LOAD "" SCREEN$
3 LOAD "" CODE
4 RANDOMIZE USR 24000
This leaves area above 24000 for machine code. Your tiny Basic loader starts at 23755 and will fit below 24000

And if your machine code program is short just place it above 32768 so it runs in memory not slowed down by ULA.
User avatar
Morkin
Bugaboo
Posts: 3251
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: Memory questions

Post by Morkin »

IIRC, for Balachor's Revenge I started the program at 24500 and pointed the stack pointer just below it. The stack isn't particularly big during the game, <100 bytes.

I figured that'd be pretty safe for most models, peripherals etc. as I didn't need to return to BASIC for anything. Though it was more a rough guess than anything else.
My Speccy site: thirdharmoniser.com
User avatar
Einar Saukas
Bugaboo
Posts: 3070
Joined: Wed Nov 15, 2017 2:48 pm

Re: Memory questions

Post by Einar Saukas »

Ralf wrote: Wed Apr 04, 2018 1:33 pm If you don't need ALL existing memory you can safely do for example in standard Spectrum 48kB

Code: Select all

1 CLEAR 24000
2 LOAD "" SCREEN$
3 LOAD "" CODE
4 RANDOMIZE USR 24000
This leaves area above 24000 for machine code. Your tiny Basic loader starts at 23755 and will fit below 24000

And if your machine code program is short just place it above 32768 so it runs in memory not slowed down by ULA.
It should be CLEAR 23999 :)
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Memory questions

Post by RMartins »

Einar Saukas wrote: Wed Apr 04, 2018 1:52 pm ...
It should be CLEAR 23999 :)
Eagle eyes Einar :D
w00tguy
Drutt
Posts: 4
Joined: Tue Apr 03, 2018 2:57 am

Re: Memory questions

Post by w00tguy »

Alright, I think I've got a handle on the "memory map" now. I do plan to use ALL available memory (and then some) since I'll be trying to write my project in C for the most part.
Ast A. Moore wrote: Wed Apr 04, 2018 9:42 am Well, it’s not 0x5CCB per se, but rather whatever’s held in the PROG system variable.
Perfect, that's just what I need. At the moment this reads 0x5CCB for me, but I should check that var in my loader or program code so I know exactly where to place my code/data or wtv ends up in that area.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Memory questions

Post by Ast A. Moore »

w00tguy wrote: Wed Apr 04, 2018 8:21 pm
Perfect, that's just what I need. At the moment this reads 0x5CCB for me, but I should check that var in my loader or program code so I know exactly where to place my code/data or wtv ends up in that area.
For releases, I personally use a machine-code loader placed inside the BASIC file. To run it, I make use of the PROG variable (but there’s an even better way to do it). As for the value that PROG contains, try this experiment (that is, if your emulator can also emulate the Interface 1):

1. “Attach” the Interface 1 and reset the machine
2. Read the PROG system variable: PRINT PEEK 23635+256*PEEK 23636
3. Do CAT 1 (you’ll get an error, but that’s irrelevant)
4. Now read the PROG sys. variable again. The value will change.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
User avatar
1024MAK
Bugaboo
Posts: 3104
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Memory questions

Post by 1024MAK »

w00tguy wrote: Wed Apr 04, 2018 2:17 am

Code: Select all

--+-------------+-----+-------+------+-----+-------------------+----+-----+--
  |   Channel   | 80h | BASIC | Vars | 80h | Command or prog.  | NL | 80h |
  | information |     | prog  |      |     | line being edited |    |     |
--+-------------+-----+-------+------+-----+-------------------+----+-----+--
      ^                                                                   ^
      |                                                                   |
    5CB6h                                                             WORKSP
   (23734)
    CHANS
In case you have not worked it out, the names in the table in the Spectrum manual that define the location in memory where the boundaries are, are system variables. So to find the current location of said boundary, read the appropriate system variable.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
Post Reply