Boriel Basic Forum
Weirdness 4 - 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: Weirdness 4 (/showthread.php?tid=148)



Weirdness 4 - britlion - 2010-01-31

Okay, this one is pretty small. It crashes.

Code:
FUNCTION RAND () as uInteger : REM Code by Jon Ritman random: REM add 46 bytes to this location to hit the store "Lion" asm RANDOM: LD HL,(SEED+2) LD D,L ADD HL,HL ADD HL,HL LD C,H LD HL,(SEED) LD B,H RL B LD E,H RL E RL D ADD HL,BC LD (SEED),HL LD HL,(SEED+2) ADC HL,DE RES 7,H LD (SEED+2),HL JP M,RANDOM3 LD HL,SEED RANDOM2: INC (HL) INC HL JR Z,RANDOM2 RANDOM3: LD HL,(SEED) RET SEED: DB "Lion" end asm END FUNCTION CLS DIM a as uInteger let a=@random PRINT a let a=a+46 PRINT a DIM n as uInteger DIM result as uByte FOR n=a to a+4 LET result=peek n print n;"=";result;"=";CHR$ (result) next n

IF I change the last line to:
Code:
print n;"=";result;"=";CHR$ (76)

It doesn't crash. What's the problem with CHR$(uByte) suddenly?

Can anyone else replicate this?

All I was trying to do was put in a nice shiny new random number generator...


Re: Weirdness 4 - boriel - 2010-02-21

britlion Wrote:Okay, this one is pretty small. It crashes.

Code:
FUNCTION RAND () as uInteger : REM Code by Jon Ritman random: REM add 46 bytes to this location to hit the store "Lion" asm RANDOM: LD HL,(SEED+2) LD D,L ADD HL,HL ADD HL,HL LD C,H LD HL,(SEED) LD B,H RL B LD E,H RL E RL D ADD HL,BC LD (SEED),HL LD HL,(SEED+2) ADC HL,DE RES 7,H LD (SEED+2),HL JP M,RANDOM3 LD HL,SEED RANDOM2: INC (HL) INC HL JR Z,RANDOM2 RANDOM3: LD HL,(SEED) RET SEED: DB "Lion" end asm END FUNCTION CLS DIM a as uInteger let a=@random PRINT a let a=a+46 PRINT a DIM n as uInteger DIM result as uByte FOR n=a to a+4 LET result=peek n print n;"=";result;"=";CHR$ (result) next n

IF I change the last line to:
Code:
print n;"=";result;"=";CHR$ (76)

It doesn't crash. What's the problem with CHR$(uByte) suddenly?

Can anyone else replicate this?

All I was trying to do was put in a nice shiny new random number generator...

This program does not crash to me. Try it with the new 1.2.5 Beta 2 version, anyway. It prints Lion# where # means rubbish.
The problem here is you're printing 5 chars (a, a+1, a+2, a+3, a+4) and Lion has 4 letters. You have an overflow in your print, so the glitched character is expected. But the program should not crash (It does not in my emulator).

Can you try with V 1.2.5 Beta 2?