Author Topic: Memory full when using .bas file to run a .bin  (Read 629 times)

0 Members and 1 Guest are viewing this topic.

Offline emilb

  • CPC464
  • **
  • Posts: 5
  • Country: de
    • Awards
Memory full when using .bas file to run a .bin
« on: 20:08, 05 August 21 »
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:


Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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...
« Last Edit: 03:21, 07 August 21 by emilb »
like
0
No reactions

Offline eto

  • Supporter
  • 6128 Plus
  • *
  • Posts: 578
  • Country: de
    • Awards
Re: Memory full when using .bas file to run a .bin
« Reply #1 on: 23:31, 05 August 21 »
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.


like
0
No reactions

Offline emilb

  • CPC464
  • **
  • Posts: 5
  • Country: de
    • Awards
Re: Memory full when using .bas file to run a .bin
« Reply #2 on: 23:38, 05 August 21 »
Thank you, that solved the problem.
like
0
No reactions

Offline reidrac

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.068
  • Country: gb
  • Trying to gamedev!
    • index.php?action=treasury
    • usebox.net
    • Awards
Re: Memory full when using .bas file to run a .bin
« Reply #3 on: 10:03, 06 August 21 »
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
« Last Edit: 10:05, 06 August 21 by reidrac »
like
0
No reactions
Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse and Brick Rick for the CPC.

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

Offline emilb

  • CPC464
  • **
  • Posts: 5
  • Country: de
    • Awards
Re: Memory full when using .bas file to run a .bin
« Reply #4 on: 18: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?
like
0
No reactions

Offline reidrac

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.068
  • Country: gb
  • Trying to gamedev!
    • index.php?action=treasury
    • usebox.net
    • Awards
Re: Memory full when using .bas file to run a .bin
« Reply #5 on: 19:05, 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

like
0
No reactions
Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse and Brick Rick for the CPC.

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