Can a basic function call (FN) cause out of memory?

Basic and Machine Language

Moderator: Moderators

User avatar
Witzo
Vic 20 Afficionado
Posts: 381
Joined: Thu Dec 01, 2011 9:14 am
Location: The Hague

Can a basic function call (FN) cause out of memory?

Post by Witzo »

I get an out of memory error on a line with a function call, but I still have 701 bytes left.
(t+3*i+1) is 673+3*5+1=689 at the time of the error.
It's some data I stored in USRVCTRS, a trick I read about in a previous thread.

Are there other reasons to get 'out of memory' besides actually being out of memory?

Image


(And here a more interesting picture of the goings-on; still deeply uncertain if this is going to work out especially in the light of this error.)
Image
User avatar
tokra
Vic 20 Scientist
Posts: 1123
Joined: Tue Apr 27, 2010 5:32 pm
Location: Scheessel, Germany

Re: Can a basic function call (FN) cause out of memory?

Post by tokra »

Witzo wrote:I get an out of memory error on a line with a function call, but I still have 701 bytes left.
(t+3*i+1) is 673+3*5+1=689 at the time of the error.
It's some data I stored in USRVCTRS, a trick I read about in a previous thread.

Are there other reasons to get 'out of memory' besides actually being out of memory?
Yes, if you have a stack overflow. Try this for example:

Code: Select all

0 GOSUB 0
This will get you out of memory as well. Not sure what your DO-function does? Or if you're maybe deep into the stack already.
User avatar
Mike
Herr VC
Posts: 4832
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Can a basic function call (FN) cause out of memory?

Post by Mike »

Witzo wrote:Are there other reasons to get 'out of memory' besides actually being out of memory?
Yes, there are.

FOR loops and GOSUBs are stored on the stack; when there are too many open FOR loops and/or nested sub-routines, even a simple expression evaluation might not have enough spare memory on the stack to complete properly.

It's quite 'difficult' to nest a lot of FOR loops, most probably you have some sub-routine in your program, which at one point doesn't return to the main program via RETURN but with GOTO. Such programming errors fill up the stack within short time.
User avatar
Witzo
Vic 20 Afficionado
Posts: 381
Joined: Thu Dec 01, 2011 9:14 am
Location: The Hague

Post by Witzo »

Thanks, Tokra and Mike.
I'll check out my gosubs and for nestings; there are indeed quite a lot.

The DO function rolls a six-sided die to determine how well a unit hits, and doesn't use any fors or gosubs. It must be in the other parts and been coincidence that the error popped at that line.
User avatar
orion70
VICtalian
Posts: 4341
Joined: Thu Feb 02, 2006 4:45 am
Location: Piacenza, Italy
Occupation: Biologist

Post by orion70 »

Hope these suggestions will help you complete the game :) . Are you planning to redefine characters? Any info about what the game will be about :mrgreen: ?
User avatar
Ghislain
Realms of Quest
Posts: 1279
Joined: Sun Aug 08, 2004 12:54 am

Post by Ghislain »

orion70 wrote:Hope these suggestions will help you complete the game :) . Are you planning to redefine characters? Any info about what the game will be about :mrgreen: ?
I suspect that it's a hex-based wargame, but I am biased and tend to see all hex-based games as wargames.
"A slave is one who waits for someone to come and free him." -- Ezra Pound
User avatar
orion70
VICtalian
Posts: 4341
Joined: Thu Feb 02, 2006 4:45 am
Location: Piacenza, Italy
Occupation: Biologist

Post by orion70 »

:) It could be a fantasy turn-based strategy game in the fashion of the wonderful HOMM2...
User avatar
Witzo
Vic 20 Afficionado
Posts: 381
Joined: Thu Dec 01, 2011 9:14 am
Location: The Hague

Post by Witzo »

You guessed right, it's a war game / turn based strategy game :D
I was inspired after reading this book from 1980:
http://www.librarything.com/work/1613529

It's not going to have redefined characters, since I'm not experienced in making them and I'm trying to squeeze it into the unexpanded VIC. Because I still haven't ordered a Megacart to get more memory :)

I haven't thought of a theme yet. So far it has three unit types with different movement points and to-hit.
I didn't want to reveal it yet as I'm not sure I'll manage to finish it, but I can't do without this forum to ask about problems I run into. And I still have a fair number of puzzles that I'm not sure I'll be able to solve... (how to make the computer player move in a sensible way, in the 650 or so bytes I have left).
But I appreciate your interest!
User avatar
Mike
Herr VC
Posts: 4832
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

Witzo wrote:It's not going to have redefined characters, since I'm not experienced in making them [...]
Actually, that's no reason not to use them. It's only slightly more complicated when a +8K or bigger RAM expansion is used. You need to set the BASIC start to an higher address, so the RAM 'below' your BASIC program can hold the screen memory and the character data and you still have all the room available up to the top address of the used RAM expansion. As you see, that's a method different from unexpanded or +3K, where the 'roof' is lowered, but it can be done.
[...] and I'm trying to squeeze it into the unexpanded VIC. Because I still haven't ordered a Megacart to get more memory :)
Sigh. Do you see any realistic chance to implement the remaining game logic into the ~600 remaining bytes? Not really? It's still possible to programm for a bigger RAM expansion, taking the shifted screen and colour memory address into account. You can design the redefined graphics 'off-line' if you wish, and combine these into your game at a later stage. And why would you need a Mega-Cart to be able to write a program for expanded memory? You can always try out your program in an emulator, that should go without saying.

Good luck with your project, and please don't let false suppositions and unjustified fears limit your creativity.
User avatar
Witzo
Vic 20 Afficionado
Posts: 381
Joined: Thu Dec 01, 2011 9:14 am
Location: The Hague

Post by Witzo »

No worries. I was already happy that I managed to make hexes and move stuff hex-wise around with a few keys to point where to go. I'm making stuff up as I go along. If I run out of memory when I'm nearly there, I already made up my mind to use the expansion in an emulator, since someday I'll order the Megacart eventually anyway. But if I can run it on the real metal as I have it available now, that would be a big bonus.
ravenxau
Vic 20 Devotee
Posts: 296
Joined: Fri May 28, 2004 10:03 pm

Post by ravenxau »

if you want to stay 'unexpanded' - perhaps get the game working with just one type of unit, eg:- Tank - then proceed to add more until you reach the memory limitation - just my thoughts on an alternate approach.
Android Tablet running Frodo 64 emulator running VIC 20 emulator....
User avatar
Witzo
Vic 20 Afficionado
Posts: 381
Joined: Thu Dec 01, 2011 9:14 am
Location: The Hague

Post by Witzo »

I've put this project on ice for a while.
I think I'm stuck in overflowing the stack with whatever gosubs and for-nexts I'm using.
But I've got a basic layout of what I want in this program, and hope to return to it later, possibly in assembly.
First I want to do an Android project where I'm not stuck, which, this being a hobby, is for now more rewarding :-)
pallas
Vic 20 Devotee
Posts: 212
Joined: Mon Dec 24, 2012 2:38 am

Post by pallas »

What's your android project, if I can ask? I have some experience of that.
User avatar
Witzo
Vic 20 Afficionado
Posts: 381
Joined: Thu Dec 01, 2011 9:14 am
Location: The Hague

Post by Witzo »

pallas wrote:What's your android project, if I can ask? I have some experience of that.
My newest is a calendar conversion routine, it translates today from AD to the Rastafari Tabot calendar:
https://play.google.com/store/apps/deta ... ware.tabot

The interesting thing here was not the Android specifics, because it's just text, but figuring out how to get the right date in the Tabot calendar, that has differing lengths of months and a different phase for leap years.
User avatar
freshlamb
Vic 20 Dabbler
Posts: 76
Joined: Sun Apr 04, 2004 5:38 pm
Website: http://www.rufnoiz.com
Location: Prince Albert SK Can

Post by freshlamb »

A bit of time away from a project sometimes will help. I know when I was working on Martain Raid (forever ago) I got stuck and had no one to ask for help, so I left it for a year or so. When I got back to it, I immediately found I was jumping out (GOTO) of a FOR-NEXT loop. I'm sure I finished quickly after that.

Fresh eyes definitely help, if you can't or don't want to get someone else involved. Hopefully you don't have to leave it for 2 years though ...
Post Reply