![]() |
|
Out of memory when using uinteger array (*solved*) - Printable Version +- Boriel Basic Forum (https://forum.boriel.com) +-- Forum: Compilers and Computer Languages (https://forum.boriel.com/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://forum.boriel.com/forumdisplay.php?fid=11) +---- Forum: Bug Reports (https://forum.boriel.com/forumdisplay.php?fid=15) +---- Thread: Out of memory when using uinteger array (*solved*) (/showthread.php?tid=354) Pages:
1
2
|
Out of memory when using uinteger array (*solved*) - Darkstar - 2011-06-08 Code: ' tn = TriangleNumber, mt = MaximumTriangles (# of), rn = RandomNumber, GraphicWidth, GraphicHeight, zn = ZeroNumber (Modifier) 'DIM udg(7) AS UBYTE => {0,1,3,7,15,31,63,127}
INK 6: PAPER 1: FLASH 0: BRIGHT 1: OVER 0: INVERSE 0: DIM tn, mt, rn, gw, gh, znw, znh AS UBYTE: DIM x(4,4) AS UINTEGER: DIM y(4,4) AS UINTEGER
'DIM x(4,4) AS FLOAT: DIM y(4,4) AS FLOAT
tn=0: mt=0: rn=0: znw=0: znh=16
gw=255: gh=175+znh: BORDER 1: CLS: PRINT AT 10,5;"The Sierpinski Triangle";: tn=1: mt=4 '256-1 '176-1
x(tn,1)=znw: y(tn,1)=znh: x(tn,2)=gw/2: y(tn,2)=gh: x(tn,3)=gw: y(tn,3)=znh: GOSUB FirstPoint: tn=tn+1
x(tn,1)=znw: y(tn,1)=gh: x(tn,2)=gw/2: y(tn,2)=znh: x(tn,3)=gw: y(tn,3)=gh: GOSUB FirstPoint: tn=tn+1
x(tn,1)=znw: y(tn,1)=gh: x(tn,2)=gw: y(tn,2)=gh/2: x(tn,3)=znw: y(tn,3)=znh: GOSUB FirstPoint: tn=tn+1
x(tn,1)=gw: y(tn,1)=gh: x(tn,2)=znw: y(tn,2)=gh/2: x(tn,3)=gw: y(tn,3)=znh: GOSUB FirstPoint
tn=1: PRINT AT 12,4;"Press any key to continue";
ScanAnyKey:
IF INKEY$="" THEN GO TO ScanAnyKey: END IF
RANDOMIZE : CLS
DrawTriangles:
rn=INT (RND*3)+1
x(tn,4)=(x(tn,4)+x(tn,rn))/2
y(tn,4)=(y(tn,4)+y(tn,rn))/2
PLOT x(tn,4),y(tn,4)
tn=tn+1: IF tn>mt THEN tn=1: END IF
GO TO DrawTriangles
FirstPoint:
x(tn,4)=x(tn,2): y(tn,4)=y(tn,2): RETURNThis crashes after a few pixels drawn with an out of memory error while if you use float it works fine under the latest version of the compiler. In version 1.2.6 uinteger works without a hitch. The compilation options are: zxb Triangles.bas --optimize=2 --output=TRIANGLES.ASM --asm --org=24576 --array-base=1 --string-base=1 --heap-size=1024 zxbasm TRIANGLES.ASM --output=TRIANGLES --tap --BASIC --autorun On to another subject, what is the correct syntax for "DIM udg(7) AS UBYTE => {0,1,3,7,15,31,63,127}" as a multidimensional array? I tried "DIM ma(2,2) AS UBYTE => {1,4,6,2,0,55}" but it did not work. Re: Out of memory when using uinteger array - Darkstar - 2011-06-09 "rn=CAST(UINTEGER,RND)*3+1" Crashes the machine, UBYTE as well. Re: Out of memory when using uinteger array - boriel - 2011-07-13 Darkstar Wrote:Sorry for this mega-delay (I'm alive), but I've been *REALLY* busy (okay, I went to NY for two weeks, but had lot of stuff piled up upon return). I will check this ASAP. Quote:On to another subject, what is the correct syntax for "DIM udg(7) AS UBYTE => {0,1,3,7,15,31,63,127}"Use "vector inside vectors": Code: DIM ma(1 TO 2, 2) AS UBYTE => {{1, 4, 6}, {2, 0, 55}}You can read more about it here: <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:DIM">http://www.boriel.com/wiki/en/index.php/ZX_BASIC:DIM</a><!-- m --> Re: Out of memory when using uinteger array - boriel - 2011-07-13 Darkstar Wrote:"rn=CAST(UINTEGER,RND)*3+1"Sorry, I can't make the machine to crash with the above sentence. Is this part of a greater program? Please download the lastest compiler version (1.2.8s703) and check if it work now. Otherwise, send me the --asm generated file of the above sentence to debug it. Re: Out of memory when using uinteger array - boriel - 2011-07-16 Okay, both bugs seems to be related, and fixed. Even more, the compiler produces a little better code now. Download latest version 1.2.8-s705 and tell me if it works, please. Re: Out of memory when using uinteger array - Darkstar - 2011-07-18 Code: ' tn = TriangleNumber, mt = MaximumTriangles (# of), rn = RandomNumber, GraphicWidth, GraphicHeight, zn = ZeroNumber (Modifier)
INK 6: PAPER 1: FLASH 0: BRIGHT 1: OVER 0: INVERSE 0: DIM tn, mt, rn, gw, gh, znw, znh AS UBYTE: DIM x(4,4) AS UINTEGER: DIM y(4,4) AS UINTEGER
tn=0: mt=0: rn=0: znw=0: znh=16
gw=255: gh=175+znh: BORDER 1: CLS: PRINT AT 10,5;"The Sierpinski Triangle";: tn=1: mt=4 '256-1 '176-1
x(tn,1)=znw: y(tn,1)=znh: x(tn,2)=gw/2: y(tn,2)=gh: x(tn,3)=gw: y(tn,3)=znh: GOSUB FirstPoint: tn=tn+1
x(tn,1)=znw: y(tn,1)=gh: x(tn,2)=gw/2: y(tn,2)=znh: x(tn,3)=gw: y(tn,3)=gh: GOSUB FirstPoint: tn=tn+1
x(tn,1)=znw: y(tn,1)=gh: x(tn,2)=gw: y(tn,2)=gh/2: x(tn,3)=znw: y(tn,3)=znh: GOSUB FirstPoint: tn=tn+1
x(tn,1)=gw: y(tn,1)=gh: x(tn,2)=znw: y(tn,2)=gh/2: x(tn,3)=gw: y(tn,3)=znh: GOSUB FirstPoint
tn=1: PRINT AT 12,4;"Press any key to continue";
ScanAnyKey:
IF INKEY$="" THEN GO TO ScanAnyKey: END IF
RANDOMIZE : CLS
DrawTriangles:
'rn=RND*3+1
rn=CAST(UINTEGER,RND)*3+1
'rn=CAST(UINTEGER,RND*3)+1
'rn=INT (RND*3)+1
x(tn,4)=(x(tn,4)+x(tn,rn))/2
y(tn,4)=(y(tn,4)+y(tn,rn))/2
PLOT x(tn,4),y(tn,4)
tn=tn+1: IF tn>mt THEN tn=1: END IF
GO TO DrawTriangles
FirstPoint:
x(tn,4)=x(tn,2): y(tn,4)=y(tn,2): RETURNCode: __LABEL__DrawTriangles:
call RND
call __FTOU32REG
ld de, 3
call __MUL16_FAST
inc hl
ld a, l
ld (_rn), aI am trying to get rid of the floating point multiplication in the RND section to gain speed. The arrays work fine now thanks, and thanks for the DIM answer; reminds me of context within a context. I had a feeling that those two bugs might be related. Otherwise, I just checked into the forum as I have been really busy so sorry for the late reply to this thread. Re: Out of memory when using uinteger array - Darkstar - 2011-07-18 Code: @echo off
if exist TRIANGLES.TAP del TRIANGLES.TAP
if exist TRIANGLES.ASM del TRIANGLES.ASM
zxb Triangles.bas --optimize=2 --output=TRIANGLES.ASM --asm --org=24576 --array-base=1 --string-base=1 --heap-size=1024
rem --enable-break
zxbasm TRIANGLES.ASM --output=TRIANGLES --tap --BASIC --autorun
ren TRIANGLES TRIANGLES.TAPThis is the compiling BAT file. Re: Out of memory when using uinteger array - boriel - 2011-07-19 Did you download the latest version 1.2.8-s705 (linked above)? I've run your test for about 10 minutes (at x400 speed) and it does not crash on my emulator... :?: Re: Out of memory when using uinteger array - Darkstar - 2011-07-19 Yes of course I did download 1.2.8-s705, even double checked it using the --version switch before proceeding. However I did not delete the old files but just copied over them thus replacing the old files with the new ones. Could that be it? I am using Spectaculator 7.51. Re: Out of memory when using uinteger array - boriel - 2011-07-19 Check the attached TRIANGLES.asm file and compare it with your one. They should be the same (try using something like gvimdiff or the like). I think it could be a good idea to place a comment in the beginning of the ASM file which read something like: ";; Generated by ZX Basic version XXXX". What do you think? Also assemble this file and run it and tell me if it works ok. :roll: Re: Out of memory when using uinteger array - Darkstar - 2011-07-19 Quote:I think it could be a good idea to place a comment in the beginning of the ASM file which read something like: ";; Generated by ZX Basic version XXXX". What do you think? I would think that would be a very good idea to keep track and to avoid confusion. I have a program made for the 16K that takes up all of the lower memory and it's made with 1.2.6 and I have not recompiled it for the new version might run out of memory, so I keep 1.2.6 around. My asm file is 65.286 bytes. Yours is 64.091 bytes. The code for rnd in the zip file: Code: __LABEL__DrawTriangles:
call RND
push bc
push de
push af
ld a, 082h
ld de, 00040h
ld bc, 00000h
call __MULF
call __FTOU32REG
inc hl
ld a, l
ld (_rn), aAre you sure you compiled it with this statement? "rn=CAST(UINTEGER,RND)*3+1" Re: Out of memory when using uinteger array - boriel - 2011-07-19 Note: CAST(Uinteger, RND) is *always* 0, because RND returns a float number form 0 to 0.99999999... So CAST(Uinteger, RND * 3) will return an Uinteger number between 0 and 2 (which is most likely what you want). I used this 2nd form, and your program works ok. The first ASM chunk you posted corresponds to CAST(Uinteger, RND) * 3 + 1, and won't work. If you use the 1st one your program will looks like crashed but it is not; it's only generating the same "random" (truncated) numbers once and over again (this should happen both in 1.2.6 and 1.2.8). Check this and tell me. Re: Out of memory when using uinteger array - Darkstar - 2011-07-19 "Note: CAST(Uinteger, RND) is *always* 0, because RND returns a float number form 0 to 0.99999999..." I was waiting for that argument somehow. However can you not do a RND that works on integers. I know it can be done
Re: Out of memory when using uinteger array - Darkstar - 2011-07-19 "Check this and tell me." I have checked this back and forth and the current release is stable. Re: Out of memory when using uinteger array - boriel - 2011-07-19 Darkstar Wrote:"Note: CAST(Uinteger, RND) is *always* 0, because RND returns a float number form 0 to 0.99999999..."It is, and very easy indeed, since the main RAND routine generates a 32bits (DE, HL) integer. I can add a library <rand.bas> which contains a randint() routine, for example (it's just a simple call to RAND routine). Try this: Code: function fastcall randint as ULong
asm
jp RAND
end asm
end function
#require "random.asm" |