/*****************************************************************************
 * CheatCode/Camelot
 * Code: Cruzer/CML 2006
 * Compiled with: KickAss
 * Tab: 4 chars
 *****************************************************************************/

//Mem...

.var lineCnt =		$fe
.var cnt =			$ff
.var screen =		$0400
.var base =			$0801
.var charset =		$3000
.var sine =			$6000
.var pixelBuffer =	$7800

.pc = base

.var numLines = 12 //must be divisible by 4

//Basic...
			.by $0b,$08,$39,$05,$9e,$32,$30,$36,$31,$00,$00,$00


//calc sine... (using basic is lame!)
	
			//lda #$00
			pha
			//tax
			ldy #$ff

			lda #$1c
			sta $d018
			sta $d016
			lda #$0d
			sta $d022
	
!loop:	
loa:		lda #$15
			adc #$07
			sta loa+1
			bcc !+
			inc hia+1
			clc
!:
lo:			adc #$00
			sta lo+1
			pla
hia:		adc #$00
			pha
			sta $d021
			sta $d023
			sta sine,x
			sta sine,y
			eor #$7f
			sta sine+$80,x
			sta sine-$80,y
			inx
			dey
			cpx #$40
			bne !loop-
		

//setup charset...

			ldy #$0f
!loop:
			clc
			tya
			ldx #0
ss:			sta screen+$032c,x
			inx
			adc #$10
			bcc ss
			lda ss+1
			sbc #40
			sta ss+1
			bcs !+
			dec ss+2
!:			dey
			bpl !loop-
	
mainLoop:

//draw dots...

			lda #numLines
			sta lineCnt
lineLoop:
			lda lineCnt
			and #2
			tax
			lda lineCnt
			adc cnt
			asl
			asl
			cpx #2
			beq !+
			asl
!:			sta ls+1
	
			lda #>pixelBuffer
			sta eb+2
			sta sb+2
			sta ep+2
			sta ep+5

charLoop:
			ldx #3
pixelLoop:
ls:			lda sine
as:			adc sine
			lsr
			tay
			lda pixels,x
color:		and #%10101010
ep:			eor pixelBuffer,y
			sta pixelBuffer,y
			dec ls+1
			dec ls+1
			inc as+1
			dex
			bpl pixelLoop
			lda ep+1
			eor #$80
			sta ep+1
			sta ep+4
			bne charLoop
			inc ep+2
			inc ep+5
			bpl charLoop
			lda color+1
			eor #%01010101
			sta color+1
			dec lineCnt
			bne lineLoop
		
		
//fill and clear pixelBuffer...


			lda #>charset
			sta sc+2
			
			ldy #$00
			ldx #$00
!loop:
			txa
eb:			eor pixelBuffer,y
sc:			sta charset,y
			tax
			lda #$00
sb:			sta pixelBuffer,y
			iny
			bne !loop-
			inc sc+2
			inc eb+2
			inc sb+2
			bpl !loop-

			inc cnt
			
			jmp mainLoop
	
pixels:		
			.by %00000011
			.by %00001100
			.by %00110000
			.by %11000000
