News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Memory full when using .bas file to run a .bin

Started by emilb, 18:08, 05 August 21

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

emilb

Hello,


This is my first post so apologies in advance if I make a fool out of myself ;)


I've recently bought a CPC 6128 and started playing with assembler. I created a small program that calculates the number of primes up to 1000. Its beginning looks following:


WRITE "primes.bin"


        org     &1200     
        call    Main      ; call the main part of the program
        ld      e,0       
        ld      (res),de  ; load result to memory for later use
        ret



res     equ     &3000     ; address to store the result in
...
some more code to do the actual calculation



After assembling that code in Maxam I can run following basic commands:
MEMORY &11FF
LOAD "primes.bin", &1200
CALL &1200
RES=PEEK(&3001)
PRINT RES

with the result being 168, as expected.


I would like to have a little basic program though which would execute the above commands, as well as measure time required to calculate the prime numbers. In order to achieve that I wrote the following:

10 MEMORY &11FF
20 LOAD "primes.bin", &1200
30 t1=TIME
40 CALL &1200
50 t2=TIME
60 result=PEEK(&3001)
70 td=INT((t2-t1)/3)
80 PRINT result;"primes found in";td;"* 1/100 s."


SAVE "primes.bas



However now whenever I try running that basic program, it throws a "Memory full in 20" error every time.


I checked the BASIC programming tips manual for creating the simple loader and looked for an answer to this problem on this forum and the web, but nowhere could find anything that would help. Is there (there must be) something that I'm missing?


Thanks in advance!


[EDIT] Solved
In case anyone has the same problem in the future, after some experimentation in WinApe it turned out that there needs to be exactly 4100 bytes of free space in memory after the end of the loaded basic program in order to avoid the Memory full problem. The basic program always starts at &170.


In other words, code of the basic loader should look like this:
10 MEMORY <368(&170) + size of the basic program in memory + 4100>
20 LOAD <filename>, <number above + 1>
...



Or just use any reasonably high number (like &8000) instead of what I did in the beginning...

eto

Move the program from 1200 to 8000 and you should not have any issues any more.


&1200 is just about 4KB and I guess this leaves not enough room for BASIC to store code and variables.



emilb


reidrac

#3
I'm not aware of a "memory map" on the wiki, but this is what I usually use: https://www.cpcwiki.eu/imgs/0/02/CPC_firmware.pdf

EDIT: actually, is not that one; but close enough :D
Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse, Brick Rick, Hyperdrive and The Heart of Salamanderland for the CPC.

If you like my games and want to show some appreciation, you can always buy me a coffee.

emilb

Thanks for the link. It's slightly confusing for me though.


Does BASIC load the program (meaning the .bas file) at &0170? If so, I guess there should be plenty of space for it to load the binary, as the basic code in the file is only around 200 bytes long. What am I missing here?

reidrac

Quote from: emilb on 16:48, 06 August 21
Thanks for the link. It's slightly confusing for me though.


Does BASIC load the program (meaning the .bas file) at &0170? If so, I guess there should be plenty of space for it to load the binary, as the basic code in the file is only around 200 bytes long. What am I missing here?

You can't use memory reserved for the BASIC code I suspect. Use "MEMORY ‹memory address›" to limit the memory allocated to BASIC, and then you can load your program after HIMEM (try "print HIMEM").

I'm not an expert, the first thing I do in my games is disable all ROMs and take over the CPC completely ;D But some folk around here can confirm/correct/expand on this.

Also, look at this: https://www.cpcwiki.eu/index.php?title=Locomotive_BASIC

Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse, Brick Rick, Hyperdrive and The Heart of Salamanderland for the CPC.

If you like my games and want to show some appreciation, you can always buy me a coffee.

Powered by SMFPacks Menu Editor Mod