![]() |
Memory Management - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: Wishlist (https://www.boriel.com/forum/forumdisplay.php?fid=14) +---- Thread: Memory Management (/showthread.php?tid=341) Pages:
1
2
|
Memory Management - britlion - 03-31-2011 Why not just put your org lower, have your low non speed critical functions, use align to hop to 32768 and stick a defs 6912, 0 to skip your screen buffer zone? Re: A string bug in 1.2.8-s682 - Darkstar - 03-31-2011 britlion Wrote:Why not just put your org lower, have your low non speed critical functions, use align to hop to 32768 and stick a defs 6912, 0 to skip your screen buffer zone? That's an idea except that would make the compiler runtime low as well so that is not an option. Or place the screen buffer at top and experiment with the ORG so the program compiles right up to the screen buffer and that would work with some programs but you would have no control over what goes where and the runtime again would be at the low end of the memory. I rewrote the ATTR routine and it is as follows: Code: Declare sub SetAttr (ByVal Line as ubyte, ByVal Column as ubyte, ByVal NumberOfCells as uinteger) NumberOfCells is treated as a ubyte in the ASM code instead of uinteger, it saves me one indexing instruction, the BC register pair. The declareation of AttrAddress is moved into global scobe instead of local as that saves in indexing instuctions as well and they are slow. If i rem out the global declaration of AttrAddress and the ASM section and "AttrAddress = AttrAddress" and unrem the other parts then the resulting code is 90 bytes larger with 22 indexing instructions instead of three and of those 10 are in the Do-Loop section if I counted correctly. I use AttrAddress = AttrAddress to make sure that it is the HL register pair before the code moves on. The resulting code with O2 is: ld hl, (_AttrAddress) ld (_AttrAddress), hl If the O3 level get's smarter isn't there a danger that is will be optimized out? Does it matter for I did compile this without "AttrAddress = AttrAddress" and it did work fine but that could have been luck for this is the first uinteger variable declared in the global scobe and as such it could have been in HL I don't know but I would never depend on such luck so the question does matter. Maybe someone can use this code. Darkstar. Re: A string bug in 1.2.8-s682 - boriel - 03-31-2011 Note: there is already both SetAttr and GetAttrAddr routines in <attr.bas>. Did you had a look to them? Maybe what you want was already there... I'm now checking this bug. Re: A string bug in 1.2.8-s682 - Darkstar - 03-31-2011 boriel Wrote:Note: there is already both SetAttr and GetAttrAddr routines in <attr.bas>. Did you had a look to them? Maybe what you want was already there... I'm now checking this bug. Thank you. Yes, there was something there and here is the reworked version of the sub. Code: Declare sub SetAttr (ByVal Line as ubyte, ByVal Column as ubyte, ByVal NumberOfCells as uinteger) Nothing in the global scope, some of this is inline addition from attr.asm. Re: A string bug in 1.2.8-s682 - Darkstar - 03-31-2011 Darkstar Wrote:...and the runtime again would be at the low end of the Correction, the runtime is placed after the program so it would be in high but with limited control over the routines, that is nothing but hope as in what goes low and what goes high. Re: A string bug in 1.2.8-s682 - britlion - 03-31-2011 It's my belief that they are compiled in order, so you should get that effect from GOTO start REM Routines that can go below 32768 FUNCTION a () END FUNCTION SUB b END SUB align 32768 REM BUFFER asm defs 0,6912 end asm REM High memory routines FUNCTION c() end function SUB d end sub start: Here's where we jump to immediately, so start of program. [Note that the above code is example, rather than strictly correct!] Not sure where the heap is put, though? I think it's after the code. Re: A string bug in 1.2.8-s682 - boriel - 03-31-2011 This thread has derived to a completely new topic. Splitted and moved to WishList: memory management :wink: Re: A string bug in 1.2.8-s682 - Darkstar - 04-01-2011 britlion Wrote:Not sure where the heap is put, though? I think it's after the code....It's my belief that they are compiled in order, so you should get that effect from.......... The heap is after the code and runtime. With O1 and ORG 28000 this produces a TAP file of 6078 bytes and that I find quite odd. Code: GOTO start They are compiled in order but not in the way you think. In the generated ASM file there is a small section to init the machine code and that includes the goto statement, then the align and def and then it is all (code and data) lumped together in one section as the compiler finds it, code first and then the data. So it did not solve the problem. Also if you do: Asm ld e, (NN) End asm Then the assembler acctepts it and it is there in the generated ASM file and when you compile it with zbasm it goes through without a hitch but as there is no such instruction in the Z80A instruction set then the result is garbage. That one can see in a debugger after the TAP file is loaded. So i guess this is a item for the whishlist, two sections of code and data under user control. Re: Memory Management - britlion - 04-01-2011 That should be defs 6912,0 I think. My error. You might want to do something like defs 6912, 128 just so you can see the code block for the buffer differently to empty ram. I compiled this and I saw initialize gap of zeroes buffer starting at 32768 E markers A markers B markers C markers Hmm. Not what I expected at all. I have to concur with your analysis. Darn. I had hopes for that method. I have no idea why the compiler would do that. It must be following a non linear logic. I even tried adding declare statements for the functions. For: Asm ld e, (16384) End asm Yes, that looks like a bug in the assembler in accepting that. Looks like it does a LD E,0 instruction there. Re: Memory Management - Darkstar - 04-01-2011 britlion Wrote:That should be defs 6912,0 I think. My error.I did defs 6912,65 and the Byte header was 28000, 12990 so it did fix the length problem. I saw the same thing through the debugger. I had a larger program once with a lot of text in it and the compiled text was all out of order even if it was within the same section of code, but it did not use subs. I have no idea.... britlion Wrote:For:Then after that it does LD E, (HL) or was it LD (HL), E? I don't remember. I think it was the latter. This passed through the assembler in the compiler and through zbasm, double bug or the same bug that needs to be corrected in two places. Low strictly speaking would be below the ORG address or if I were to use a new term, Start.Prog address. But that could be changed with a compiler directive if a buffer has to go in between. The compiler would use Start.Prog and the ASM part would use ORG. The directive would let the beginning (or end for it goes bakwards towards the 24 KiB limit) be a fixed number for a program. Re: A string bug in 1.2.8-s682 - boriel - 04-01-2011 Darkstar Wrote:Also if you do:This is a matter of ambiguity: For the assembler (16384) is also an arithmetical expression. So the above is compiled to: Code: asm Pasmo already allows brackets [ ] for memory indirection. Zxbasm will also do (in the near future). Re: A string bug in 1.2.8-s682 - Darkstar - 04-01-2011 boriel Wrote:Darkstar Wrote:Also if you do:This is a matter of ambiguity: For the assembler (16384) is also an arithmetical expression. So the above is compiled to: This is all fine and well but the instruction itself does not exist. In the thread <!-- l --><a class="postlink-local" href="http://www.boriel.com/forum/how-to-tutorials/topic468-30.html#p1444">how-to-tutorials/topic468-30.html#p1444</a><!-- l --> Britlion posted on the string bug thread there was a mention of doing variables FreeBasic style and then ld [e], (NN) could work but as it stands... For the record I was trying to do: "ld e, (23693)" and it produced ld e, 143 and some byte that I can't quite remember. Well, garbage in, garbage out in the debugging window. It's a work in progress ![]() Re: Memory Management - Darkstar - 04-13-2011 The heap should be user locateble in either high or low memory. For background go to: <!-- l --><a class="postlink-local" href="http://www.boriel.com/forum/bug-reports/paper-border-rerun-bug-t626.html#p2244">bug-reports/paper-border-rerun-bug-t626.html#p2244</a><!-- l --> If I had a game in two parts like a multiloader game and the game parts of it go into high memory then it is quite possible that it would wipe out the heap and the shared data there. Also you could specify heap location manually. This is easier than POKEing and PEEKing but not as easy as sharing the variables themselves and I think it is a good comprimize both in terms of user ease and compiler writing and runtime size. What does waste memory is having two runtimes in memory and the same time for a two part program, multilevel or not. This also ensures what part of the program really got control for example if you got to return to BASIC to load a multilevel disk based game then the BASIC part has got the real control. My two cents. Re: Memory Management - Darkstar - 04-13-2011 By the same token the runtime should be user relocateable or at least make it the first item loaded or we would have overwrite issues when different parts are loaded if there is to be one runtime at a time. Even an option where you can compile parts without the runtime as that would save loading time. Re: Memory Management - Darkstar - 04-13-2011 Darkstar Wrote:By the same token the runtime should be user relocateable or at least make If that option is going to be implemented then there would have to be a way to specify what to include in the runtime and what not and that would override certain optimisations that are now in place so that has to be taken into consideration. By overriding then I mean if a list what to include is specified. |