| Welcome, Guest |
You have to register before you can post on our site.
|
| Online Users |
There are currently 150 online users. » 0 Member(s) | 149 Guest(s) Bing
|
| Latest Threads |
New video Couse / Nuevo c...
Forum: News
Last Post: Duefectu
2026-04-29, 11:02 PM
» Replies: 0
» Views: 212
|
location of heap manageme...
Forum: Help & Support
Last Post: boriel
2026-03-07, 12:13 AM
» Replies: 1
» Views: 485
|
non-paged supervisor code...
Forum: Help & Support
Last Post: sdo303
2026-02-20, 06:38 PM
» Replies: 8
» Views: 1,299
|
How to open fuse as an ex...
Forum: How-To & Tutorials
Last Post: Duefectu
2026-02-09, 01:52 PM
» Replies: 3
» Views: 1,389
|
Old zxbasic game errors
Forum: Help & Support
Last Post: boriel
2025-11-09, 11:52 AM
» Replies: 7
» Views: 2,078
|
Error: Undefined GLOBAL l...
Forum: Help & Support
Last Post: ardentcrest
2025-11-04, 05:46 PM
» Replies: 3
» Views: 1,080
|
A Fast(er) Plot Routine f...
Forum: How-To & Tutorials
Last Post: tubz74
2025-10-30, 03:16 PM
» Replies: 2
» Views: 1,179
|
Hall of Fame - Include fo...
Forum: How-To & Tutorials
Last Post: tubz74
2025-10-28, 03:48 PM
» Replies: 0
» Views: 630
|
[SOLVED] Array layout bug...
Forum: Bug Reports
Last Post: Zoran
2025-10-25, 05:48 PM
» Replies: 2
» Views: 1,217
|
3DOS Commands?
Forum: Help & Support
Last Post: boriel
2025-10-06, 02:54 PM
» Replies: 3
» Views: 1,380
|
|
|
| Odd error |
|
Posted by: britlion - 2012-02-27, 07:57 PM - Forum: Bug Reports
- Replies (5)
|
 |
This might be another float bug. I wrote up the distance algorithm na_th_an showed us. It seems to work - but in this test program, it's the floating point values that go wrong...
If you set your emulator to full speed, you see it looking for the biggest error it can find, showing larger errors as it finds them. Eventually it hits distance (250,56) which my function says is > 255 (so returns 255). The value calculated from square rooting in floats is...er 0. So that's an error of 255, apparently. Except the correct answer would be 256.1952 Is the int (256) returning 0 for some reason? On a float?
When I'm happy with this funtion, it will go in the function library as a code snippet.
Code: FUNCTION fastcall distance (a as ubyte, b as ubyte) as uByte
' returns a fast approximation of SQRT (a^2 + b^2) - the distance formula, generated from taylor series expansion.
asm
POP DE ; return address
; First parameter in A
POP BC ; second parameter -> B
LD C,A ; Put second parameter in C for safekeeping.
LD HL,0
ADD A,B
LD L,A ; Put result in HL
RL H ; Pull in carry bit if necessary.
LD A,B ; get original
CP C ; compare with C
JP NC, distance_Cbigger
LD C,A ; B was smaller, so we replace the value in C with the smaller value in A
distance_Cbigger:
; C was smaller, so we leave it alone.
SRL C ; C=C/2
XOR A
LD B,A
SBC HL,BC ; take half our smallest from HL
SRL C
AND A ; Clear carry flag.
SBC HL,BC
SRL C
SRL C
AND A ; Clear carry flag.
ADD HL,BC
LD A,H
AND A
JP NZ, distance_toobig
LD A,L ; Get result.
EX DE,HL ; return address is in DE.
JP (HL)
distance_toobig:
; If the answer turns out to be > 255, we'll return 255.
LD A,255
EX DE,HL ; return address is in DE.
JP (HL)
END ASM
END FUNCTION
CLS
DIM i,imax as uByte
dim j,jmax as uByte
dim answer,realanswer as uByte
dim errorval,errorvalmax as float
imax=0
jmax=0
errorvalmax=0
for j=1 to 250
for i=1 to 250
answer=distance(i,j)
realanswer=SQR(CAST(float,i)*i+CAST(float,j)*j)
errorval=ABS(CAST(float,realanswer)-answer)
if errorval>errorvalmax then
PRINT i;" ";j;" ";answer;" ";INT realanswer; " ";int errorval
imax=i
jmax=j
errorvalmax=errorval
end if
border j
next i
next j
|
|
|
| mod with type float |
|
Posted by: britlion - 2012-02-27, 07:49 PM - Forum: Bug Reports
- Replies (1)
|
 |
This seems to work backwards, giving division instead of remainder.
Code: dim i as float
For i = 1 to 255
print int i
if i mod 22=0 then
pause 1
pause 0
cls
end if
next i
If you change the dim i as float to dim i as uinteger, it works perfectly, pausing each screen.
|
|
|
| USR function (*solved*) |
|
Posted by: britlion - 2012-02-26, 04:18 PM - Forum: Bug Reports
- Replies (7)
|
 |
We seem to have a regression with the latest version:
print USR "A" falls over:
Traceback (most recent call last):
File "zxb.py", line 312, in <module>
File "zxb.py", line 246, in main
File "zxbtrad.pyc", line 316, in traverse
File "zxbtrad.pyc", line 1286, in traverse
File "zxbtrad.pyc", line 593, in traverse
UnboundLocalError: local variable 'suffix' referenced before assignment
Build Failed!
|
|
|
| New release 1.2.9-s785 |
|
Posted by: boriel - 2012-02-21, 07:02 PM - Forum: Bug Reports
- No Replies
|
 |
Okay, a new beta release with *important* fixes :!:
- ! Fixed some array copying operations bugs detected by britlion
- ! Fixed line error reporting, which was wrong under some circunstances.
- ! Fixed $+offset expression in ASM (was not allowed with the newer preprocessor)
You can download (as always) from <!-- m --><a class="postlink" href="http://www.boriel.com/files/zxb">http://www.boriel.com/files/zxb</a><!-- m -->
|
|
|
| Re-Dim (*solved*) |
|
Posted by: britlion - 2012-02-20, 05:42 PM - Forum: Bug Reports
- Replies (9)
|
 |
Boriel, can I use Dim in a SUB to reinitialise a global array?
DIM grid (3,3) as uByte
SUB reinitialiseGrid ()
DIM grid (3,3) as uByte => { {0,1,2,3}, {4,5,6,7}, {8,9,10,11}, {12,13,14,15} }
END SUB
Is that legal, or is it trying to make a local variable?
|
|
|
| Fractal |
|
Posted by: britlion - 2012-02-18, 08:32 PM - Forum: Gallery
- Replies (14)
|
 |
Just for fun.
Incidentally, if I change the float types to fixed, it crashes. Has something gone wrong with fixed type maths?
EDIT: Updated with fixed and exit for, so if people use it here, they get the best version.
Code: #define width 256
#define height 192
DIM x,y as FIXED
DIM xstart,xstep,ystart,ystep as FIXED
DIM xend,yend as FIXED
DIM z,zi,newz,newzi as FIXED
DIM colour as byte
DIM iter as uInteger
DIM col as uInteger
DIM i,k as uByte
DIM j as uInteger
dim inset as uByte
xstart=-1.6
xend=0.65
ystart=-1.15
yend=-ystart
iter=24
xstep=(xend-xstart)/width
ystep=(yend-ystart)/height
'Main loop
x=xstart
y=ystart
border 0
paper 0
ink 7
CLS
for i=0 to ( height -1 )/2 +1
for j=0 to width -1
z=0
zi=0
inset=1
for k=0 to iter
';z^2=(a+bi)*(a+bi) = a^2+2abi-b^2
newz=(z*z)-(zi*zi)+x
newzi=2*z*zi+y
z=newz
zi=newzi
if (z*z)+(zi*zi) > 4 then
inset=0
colour=k
exit for
END IF
next k
if NOT inset then
if colour BAND 1 THEN
plot j,i
plot j,192-i
END IF
end if
x=x+xstep
next j
y=y+ystep
x=xstart
print at 23,0;CAST(uinteger,i)*200/height;"%"
next i
BEEP 1,1
PAUSE 0
(This will take a long time. Even if you push an emulator to top speed)
|
|
|
| A new site for ZX Basic? |
|
Posted by: boriel - 2012-02-18, 12:59 PM - Forum: ZX Basic Compiler
- Replies (8)
|
 |
Well, I've been thinking about it for a Long time, but don't know whether it will be worth the hassle or not...
This site is a mix of many things (ZX BASIC, XSPF Player, Captcha plugin, spam...). The wiki is separated, etc...
I was thinking on moving all ZX Stuff to a different exclusive site (zxbasic.net). This site will continue working, but if the other works, this will eventually be closed as read-only.
|
|
|
|