Re: A86: call _RANDOM
[Prev][Next][Index][Thread]
Re: A86: call _RANDOM
In a message dated 5/5/99 5:28:49 PM Eastern Daylight Time,
warhorse@bellatlantic.net writes:
> From ASM Studio:
> _RANDOM Routine
> Generates a pseudo-random number between 0 and 1 and stores it in OP1.
>
> Output OP1 = random number between 0 and 1
>
> How do I work this thing? Is OP1 a register or a "whatever you define it
> as?" What would be an example of loading the result into a register "a"?
>
> I have:
> ld a, 0
> call _RANDOM
> call _INTGR
> ld hl, a
> call _puts
> but it doesn't work
uh...there are about a million and a half reasons why that doesn't work :)
first, OP1 is _not_ a. the OP registers are floating point registers which
in reality are just ten bytes each in ram. the a register holds only
integers, so it would be impossible (or at least really dumb) to copy a
random floating point number between 0 and 1 into a register which can't
define floating points. there are various ways of outputting OPs, the most
simple of which is _dispOP1, which displays OP1 right-aligned like an answer
on the home screen.
my guess is that you're looking for a random integer routine, in which case
_randint is what you're looking for. it gives you a random integer between
OP1 and OP2 and stores t in OP1. after you call _randint, you can call
_convOP1 which will store the results into register a.
here is example code (not really efficient but illustrative) which displays a
random number between 0 and 9:
ld a,0 ;lower value
call _SetXXOP1 ;OP1=0
ld a,9 ;upper value
call _SetXXOP2 ;OP2=9
call _randint ;OP1=random number between 0 and 9
call _convOP1 ;a=OP1 (random number)
add a,'0' ;convert to ascii format
call _putc ;display character stored in a
ret ;return from routine
Follow-Ups: