So i started programming in basic again yesterday and i wrote a code to display text randomly all over the screen. But randInt( threw me an overflow error! After trying to run it 3 more times, it just gave me an obscenely large number like 1e99 and it was not afriad of decimals. So i tried the rand function and that did the same, and it gave me negative numbers also. So i was sitting there all depressed, thinking i could never fill the screen with blatantly offensive text again… So i just entered the rand command over and over again, trying to detect a pattern. Sure enough, there was: the numbers were getting smaller, until finally, randint( was listening to me and rand only gave me a number from 0 to 1.
This was all very weird and i think it had something to do with the refresh register. You see, i could never get the random routines in assembly to work, so i had to muck around with the code (without avail). I think my most recent code involved loading into the refresh register and i suspect that was the problem.
Here it is if you want to look at it.
RANDOM: LD B, A LD A, R ADD A, B AND %11 ;3 LD R, A INC A ;4 is now possible, 0 is not LD (HL), A INC HL LD A, L AND A ;if L is not 0 JR NZ, RANDOM LD A, H CP $81 ;if H is not $81 JR NZ, RANDOM
OR it could have been the other one that i use now (more random, but still doesn't work)
Rand8: ld a,0 ; Seed is usually 0 ld b,a add a,a add a,a add a,b inc a ; another possibility is ADD A,7 ld (Rand8+1),a AND %11000000 ;takes the 2 most upper bits because lower bits aren't random RRA ;%01100000 RRA ;%00110000 RRA ;%00011000 RRA ;%00001100 RRA ;%00000110 RRA ;all this makes the number 0-3 INC A ;4 is now possible, 0 is not LD (HL), A INC HL LD A, L AND A ;if L is not 0 JR NZ, Rand8 LD A, H CP $81 ;if H is not $81 JR NZ, Rand8