Image noise: Difference between revisions

Content added Content deleted
m (→‎{{header|Z80 Assembly}}: typo fix and clarification)
Line 3,202: Line 3,202:
rrca
rrca
rrca
rrca
xor (hl) ;crude xorshift rng used to select a "random" location to draw to.
xor (hl) ;crude xorshift rng used to select a "random" location to draw to.


ld h,0
ld h,0
ld L,a ;this random value becomes the low byte of HL
ld L,a ;this random value becomes the low byte of HL


rlc L
rlc L
rl h ;reduce the RNG's bias towards the top of the screen by shifting one bit into H.
rl h ;reduce the RNG's bias towards the top of the screen by shifting one bit into H.
ld a,&98 ;high byte of gb vram
ld a,&98 ;high byte of gb vram
add h ;h will equal either 0 or 1.
add h ;h will equal either 0 or 1.
ld H,a ;now H will either equal &98 or &99
ld H,a ;now H will either equal &98 or &99
ld a,(frametimer) ;it's possible that this value is different from before since every vblank it increments.
ld a,(frametimer) ;it's possible that this value is different from before since every vblank it increments.
Line 3,225: Line 3,225:
wait:
wait:
halt ;waits for an interrupt.
halt ;waits for an interrupt.
cp (hl) ;
cp (hl) compare 0 to vblankflag
jr z,wait ;vblank flag is still 1 so keep waiting.
jr z,wait ;vblank flag is still 1 so keep waiting.
ld (hl),a ;clear vblank flag.
ld (hl),a ;clear vblank flag.
Line 3,257: Line 3,257:
And the interrupt handler located at memory address <code>&A000</code>:
And the interrupt handler located at memory address <code>&A000</code>:
<lang z80>TV_Static_FX:
<lang z80>TV_Static_FX:
;this code runs every time the game boy finishes drawing one row of pixels, unless the interrupt is disabled as described above.
push hl
push hl
push af
push af
ld hl,(COSINE_INDEX
ld hl,(COSINE_INDEX)
inc (hl)
inc (hl)
ld a,(hl)
ld a,(hl)
Line 3,268: Line 3,269:
; returns cos(A) into A
; returns cos(A) into A


LDH (&43),A ;output A to horizontal scroll register.
LD (&FF43),A ;output cos(frametimer) to horizontal scroll register
done_TV_Static_FX:
done_TV_Static_FX:
pop af
pop af
pop hl
pop hl
reti ;return to main program
reti ;return to main program
TV_Static_FX_End:</lang>
TV_Static_FX_End:</lang>