|
Post by nathan999 on Mar 11, 2013 6:35:32 GMT -5
Hi! I just learned about this compiler a couple of weeks ago and began porting one of my 8 bits games to the Genesis. It's a flick-screen platformer where you have to step over all enemies in the map to clear a stage. There are several kinds of enemies, moving platforms, pushable blocks, keys and bolts, etcetera. This were going pretty good until today. I was adding a new feature to the engine (to have timed "crushers" over a conveyor belt which would squish the player if not avoided). I hit F5 to compile and got this assembly error: basic.s:8351: *** Error: Word branch out of range *** 009DCA 6100 7FCC bsr allign_heap2 Looking at the assembly listing Basiegaxorz generates, allign_heap2 must be an internal subroutine. It's called all over the code. What's the problem? Well, the subroutine is being called with bsr, which is a relative jump. Relative means that it can only be a +-32K long jump. So if your code grows, as has happened to mine, the subroutine call cannot get to the actual subroutine. Which is a HUGE problem. That means that your code can't grow much bigger than 32K (that is, just the code, not including graphics, data or variables). It could be easily fixed modifying Basiegaxorz's code generator... but as this compiler is closed source and I've read the author is not further developing it I think I'm hopeless Please take this in consideration before starting a big project. I have wasted so much time and effort into mine and it feels really bad when these things happen.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Mar 11, 2013 9:14:12 GMT -5
Looks like allign_heap is called when passing a string as argument to a subroutine. Perhaps you could swap those out with a address / pointer to wherever the data is located .. or move the blocks of code that call these subroutines to the top of your source.
Pretty bad that the compiler doesn't check whether the generated BSR instruction is valid or not though.
|
|
|
Post by nathan999 on Mar 12, 2013 2:56:43 GMT -5
Yeah, I had the very same idea... I stripped my code first, making all variables globals and thus elliminating tons of parameter passing. Then I moved the subs which call subroutines with parameters to the top and got it working. Phew! Hopefully I won't need to add much more code, because I have the engine almost finished. Next time I'll take this important limitation in account When the game is ready I will release it complete with full source code in case anybody is interested in taking a glance Right away it looks like this: Thanks for the reply!
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Mar 12, 2013 7:38:21 GMT -5
Next time I'll take this important limitation in account Subroutines that don't use any strings should be fine though .. so it's not a major limitation either. Right away it looks like this Looking good!
|
|
|
Post by nathan999 on Mar 12, 2013 10:48:41 GMT -5
It's not just the strings. The affected code is that which make calls to other Subs passing parameters Now I'm struggling to code a decent sound driver.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Mar 12, 2013 14:04:24 GMT -5
This is strange. I'm certain I've passed string variables to subroutines without any issues. It seems like it might be an issue with nested subroutines. One alternative would be to use a line label outside of a subroutine and use the shlink command, though I've never tried it so I don't know if it's bugged. I've not called other subroutines while in a sub or function though.
|
|
|
Post by sega16 on Mar 12, 2013 15:17:57 GMT -5
Wow that game looks amazing. I am very excited to play it.
|
|
|
Post by nathan999 on Mar 13, 2013 1:58:15 GMT -5
Glad to hear it I will keep you all posted when it's done. This is strange. I'm certain I've passed string variables to subroutines without any issues. It seems like it might be an issue with nested subroutines. One alternative would be to use a line label outside of a subroutine and use the shlink command, though I've never tried it so I don't know if it's bugged. I've not called other subroutines while in a sub or function though. This certainly happens when I call SUBs/FUNCTIONs from inside SUBs/FUNCTIONs. I am very used to structured programming and I made my engine that way. At first, not all my vars were global and the occurence of the offending bsr in the generated code was very high. When I activated the "all globals" directive in the compiler, bsr only appeared before calling SUBs or FUNCTIONS which take parameters. I guess that the way to go is using just FUNCTIONs with parameters when needed, and don't nest calls, use GOSUB instead of SUBs and try that your code doesn't become a mess
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Mar 13, 2013 9:38:40 GMT -5
It's not just the strings. The affected code is that which make calls to other Subs passing parameters You're not accidentally calling subroutines using the function syntax or something? The following snippet for example doesn't generate any allign_heap calls. global time as Long time& = 1000 addTime 60 print time& declare sub extraTime(numToAdd as long) time& = time& + numToAdd& exit sub end sub
declare sub addTime(numToAdd as long) time& = time& + numToAdd& extraTime 1 exit sub end sub
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Mar 13, 2013 9:49:57 GMT -5
^was also thinking that. On another note, if you have a dimensionalized array, you need the suffix or bex screams: global time&(10) as long At least it did for me
|
|
|
Post by nathan999 on Mar 14, 2013 5:27:21 GMT -5
Just double-checked. It's when calling FUNCTIONs, not SUBs. I use a couple of functions to check collisions with the background in the SUBs which move stuff around. Thankfully, moving such SUBs up solved the problem. The "main" section isn't too big and BSR is more than enough to reach the allign_heap routine. And yes, it does scream It shouldn't, but it does
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Mar 14, 2013 7:21:15 GMT -5
Functions are broken in BEX, I believe.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Mar 14, 2013 8:08:22 GMT -5
Just double-checked. It's when calling FUNCTIONs, not SUBs. I knew something was up Calling a function always aligns the heap, calling a subroutine doesn't always. By the way, i recommend not using the "Make all variables in Subs / Functions GLOBAL" option. It's more flexible to leave that off and define the variables you want to be global using the global keyword yourself. Functions are broken in BEX, I believe. Nothing wrong with functions. print add(1,2) declare function add(a as integer, b as integer) as integer return a+b end function
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Mar 14, 2013 8:45:50 GMT -5
Hmm, I thought they were, whoops I thought I read it somewhere on here, but maybe I'm confusing it with something else, or I'm just imagining things haha
|
|
|
Post by riper on Jul 10, 2015 14:04:14 GMT -5
Hello forum, I'm totally desperate. I spent hours and hours developing an engine that helps me to move the player accross rooms, printing a map and something else. I have a piece of paper of a full map and I started to "make" rooms but... at the 8th room the same error as nathan999 appears on the screen. I can not continue with my game due this error. I've readed this thread many times, but I'm not able to understand what is the problem (and the solution). Is the lenght of the code the problem? I have moved a lot of FUNCTIONS or/and SUBS from the bottom of my code to the top... but the problem is still there. Its related to the global vars? My code works with 1, 2... until 7 rooms... but I can not add any more. Here my "game". Game(button C: from the game to the map... and from the map to the game) I'm totally defeated... i'm near to give up. What makes me ungry is that I don't understand the problem. I don't know if someone wants to read my source code... I know that's a lot of job. Well... thank you in any case.
|
|