; Screen Scrambler
; Illustrates the technique of using pixel data to manipulate the screen
; and leaving the color information stationary for a wierd effect.
; It does also illustrate the usage of the random number generator and
; the speed impact that self-modifying code gives.
; By Todd S. Elliott

;equates
vicontrol = 53272; vic control register
scrmem = 1024; location of screen memory
vic = 53248; vic ii chip register
multiclr = 53270; multi-color register
charbase = 14336; char base address
backgnd = 53281; background color register
multi1 = 53282; multi-color register one
multi2 = 53283; multi-color register two
frehi3 = 54287; frequency register three
vcreg3 = 54290; voice control register three
sigvol = 54296; oscillator three
random = 54299; random generator

;initializes the screen
  lda #151; char code for color dark gray
  jsr $ffd2; changes video color matrix color to dark gray
  lda #147:jsr $ffd2; clears the screen
  lda #$ff; set voice three to max.
  sta frehi3
  lda #128
  sta vcreg3
  sta sigvol; turn on random generator for random numbers
  ldy #$00; load offset
- tya; transfer to accumulator
  sta scrmem,y; store char code
  sta scrmem+256,y
  sta scrmem+512,y
  sta scrmem+768,y
  dey; decrement offset
  bne -; if not equal, branch back
  lda vicontrol; get the values of the vic control register
  and #240; protect bits
  ora #14; store offset
  sta vicontrol; change the modified value to point to 14336
  lda multiclr; get the bit values of the multi color register
  ora #16; turn on bit 4
  sta multiclr; switch on multi color
  lda #$00; color black
  sta 53280; border register

;starts the whole shebang!
; This uses self-modifying code for the sake of speed and efficiency.
  lda #$01
  sta multi1
  lda #$00
  sta backgnd
  lda #$0f
  sta multi2
- lda #<charbase; low byte
  ldy #>charbase; high byte
  sta base+1
  sty base+2
  ldx #$07; x-offset
- ldy #$00; y-offset
- lda random; get a random number
base sta $ffff,y; and store it into mem.
  dey
  bne -; decrement 256 counter and loop back
  inc base+2; decrement high byte of character base
  dex
  bpl --; decrements the page counter and branches back
  jmp ---; ad infinitum...

; end Screenies



