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

Re: 6502 assembler and emulator in JavaScript



<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.

You also seem to have a rather peculiar range of addresses you are
writing to. Were you trying to write to the text or lo-res graphics
screen? If so, your base addresses should be $0400 throgh $0700.

You should also avoid writing to the screen holes ($78 through $7F and
$F8 through $FF on each page of the text/lores graphics screen), since
they belong to the firmware (internal or slots). The safest way to do
this would be to test whether your index is in either of these ranges,
and if so, loop around again, or modify the address so that it is not
out of range (e.g. subtract 8 from the offset, which will tend to hit
the last eight columns twice as often as elsewhere on the screen).

-- 
David Empson
dempson@actrix.gen.nz