assembly - 6502 assembler random number problems -


i playing around 6502 assembler here: http://skilldrick.github.io/easy6502

i have made puts random color pixel in random place on screen:

ldy #$00    ; clear y  loop:  jsr genpos ; put new position in memory  lda $fe    ; random number color  sta ($10), y   ; put pixel on screen  jmp loop  genpos:  sta $10    ; store accumulator in low  lda $fe    ; new random number (why, oh why?)  , #$03   ; mask out low 2 bits (=numbers 0-3)  clc        ; clear carry flag  adc #2     ; add 2 (= numbers 2-5)  sta $11    ; store number in high  rts 

i trying use few instructions possible. problem if don't put lda $fe in genpos sub routine pixels drawn in strange pattern if have lda code works perfectly. can't comprehend why - can give me hint?

regards, jacob

it making fine low byte! line:

lda $fe    ; new random number (why, oh why?) 

goes on decide high byte, , if don't generate new random number, y value dependent on lowest 2 bits of x value, causing diagonals you're seeing: value of x & 3 equals segment of screen value being drawn on, meaning pattern like

█   █   █   █   █   █   █   █    \ █   █   █   █   █   █   █   █     | █   █   █   █   █   █   █   █     |  x & 3 == 0  in $200-$2ff █   █   █   █   █   █   █   █     | █   █   █   █   █   █   █   █    /  █   █   █   █   █   █   █   █   \  █   █   █   █   █   █   █   █    |  █   █   █   █   █   █   █   █    |  x & 3 == 1  in $300-$3ff  █   █   █   █   █   █   █   █    |  █   █   █   █   █   █   █   █   /   █   █   █   █   █   █   █   █  \   █   █   █   █   █   █   █   █   |   █   █   █   █   █   █   █   █   |  x & 3 == 2  in $400-$4ff   █   █   █   █   █   █   █   █   |   █   █   █   █   █   █   █   █  /    █   █   █   █   █   █   █   █ \    █   █   █   █   █   █   █   █  |    █   █   █   █   █   █   █   █  |  x & 3 == 3  in $500-$5ff    █   █   █   █   █   █   █   █  |    █   █   █   █   █   █   █   █ / 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -