[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 6502 assembler and emulator in JavaScript



David Empson wrote:
<bieling@terra.es> wrote:


biel...@terra.es wrote:

<http://6502asm.com/>

I've written this to try it out:

start: lda $ff   ; read keypress
      ldx $fe   ; get a random number
      sta $200,x
      sta $300,x
      sta $400,x
      sta $500,x
      jmp start

When it's run, there are 4 dots whose color never change (you've got
to press a key to change the color).
Is it that the random number at $fe never gets the value $ff ?
What do you think ?


In a loop like this (on a real Apple II), $FE and $FF will always
contain the same values. They are only a random number if you wait for a
keypress using the KEYIN routine, which does a cyclic 16-bit increment
of these two locations.

It gets its randomness from the human reaction time of pressing keys.
The low order byte ($FE) will increment 256 times faster than the high
order byte, so if the person presses keys quickly, the pattern of the
$FF byte won't be very random but the $FE byte should be.

You would have to wait for a keypress on each loop if you wanted to get
a random pattern on the screen.

As Marcus pointed out, the machine being simulated is not an
Apple II at all.

But on an Apple II, the "RAND" counter is $4E and $4F.

And, FWIW, the low byte is incremented over 68,000 times per
second, and the high byte is incremented about 266 times per
second.

Typing at 100 wpm translates to 600 keystrokes per minute
(five-letter standard words plus a space), or 10 keystrokes per
second.  If we allow for quite unrhythmic typing, the minimum
period between keystrokes might be just 50 milliseconds.

In that time, the low byte will typically "turn over" 3400 times,
making it essentially uncorrelated, and the high byte will turn
over more than ten times, so unless one's rhythm is quite good,
even it will have successive values that are nearly independent.

-michael

NadaNet file server for Apple II computers!
Home page:  http://members.aol.com/MJMahon/

"The wastebasket is our most important design
tool--and it's seriously underused."