;------------------------------------------------------------------------------
; "REU-COLORS", an approach (compiles with acme)
;------------------------------------------------------------------------------
; Inspired by Blue-REU from Crest at BP2010, so what can we really do with
; a REU as we could read/manipulate 1 Memoryadresse per Cycle (!) Lets try
; a rastersplit with 48 columns... no interlace or Bankswitching this time
;
; Code: Cryer, done in 2 hours on the 10th of april 2010, just 4 fun
;
; Note:   This was not as ugly as it was before sqeezing to 256 Bytes... ;)
;         It just uses the normaly visible columns on the Screen (x from 0-384)
;
; Please Fill the memory with (standard)-zeros before running the intro, at least
; from $0800-$0a00... it will erase the lightgrey space in between the bars...sry
;------------------------------------------------------------------------------
;other possible things to do:
;
;    - native chars with ghostbyte, no sprites needed 
;      (respect to: http://psw.ca/robin/?page_id=185)
;    - realtime logging of any registers of the c64 into the REU (and 
;      of course backwards), f.e. random pattern of the sid        
;    - massive filled vectors (1 cycle = 1 byte memoryfill)
;    - ...
;
;of course we dont want to use it too much, at least we are not using a 
;Atari XL... 64kB should be enough for everyone. But we could, hehe!
;------------------------------------------------------------------------------
!to"reucolors_release.prg",cbm
*= $0801
;------------------------------------------------------------------
;BasicHeader (10 SYS 2061)
;------------------------------------------------------------------
		!byte $0b,$08,$0a,$00,$9e,$32,$30,$36
		!byte $31,$00,$00,$00

;	-->  	*= $080d
reubase    = $df00
reustat    = reubase
reucmd     = reubase+1
c64mem     = reubase+2
reumem     = reubase+4   ;(lo/hi/bank)
translen   = reubase+7
reuirqmask = reubase+9
reucntrl   = reubase+10
	
start    
         sei
;        lda #$00              we assume accu is zero, saves two bytes
;        sta d011         
;----------------------------------------------------------
; just write some Colors to Bank0 of REU
;----------------------------------------------------------         
         lda #<colors
         sta c64mem
         lda #>colors
         sta c64mem+1
         lda #<131+68				;68 additional cycles, see below for explaination ;(
         sta translen
         lda #>131+68       ;=0
         sta translen+1     
;        lda #0							;saves 2 bytes again
         sta reumem
         sta reumem+1
         sta reumem+2
         sta $d011          ;another 2 bytes for africa! ;)
         ldx #%10010000			;direction:    to REU
         stx reucmd
;----------------------------------------------------------
; prepare the REU to write it back, but dont start, wait for
; a stable raster to come
;----------------------------------------------------------         
         inx							;saves another byte
;        ldx #%10010001		;at least load x with the command for the reu for later
                          ;(saves 2 cycles later, so the color exactly starts at x=0)
;----------------------------------------------------------
; our attempt for a fucking stable raster
;----------------------------------------------------------         
        ;sei                   ;we already assured not to get disturbed by IRQ calls
main:
        lda #$11
sync 
        cmp $d012             ;scan for begin rasterline (no explicit rasterline needed, just any...)
        bne sync              
        ldy #8                
        sty $dc04             ;cia timer a
ciawait                   
        dey                   
        bne ciawait           
        sty $dc05             
        sta $dc0e,y           
        lda #$11             
        cmp $d012             ;still same line?
        sty $d015             
        bne sync              
;---------------------------------------------------------------------------------
; stable point starts now... and we stand on x=0, 3 Chars before left border ends
;---------------------------------------------------------------------------------
main2        	
;---------------------------------------------------------------------------------
; Start Cycleexact copy from REU to C64 ($d020). Until "reucmd" the screen remains
; still black, so the colortable below is adjusted to fit the timing (note the nop)
;---------------------------------------------------------------------------------
         lda #%10000000   ;2 cycles    
         sta reucntrl     ;4 cycles
         lda #<$d020      ;2 cycles
         sta c64mem       ;4 cycles
         lda #>$d020      ;2 cycles
         sta c64mem+1     ;4 cycles
         lda #0           ;2 cycles    
         sta reumem       ;4 cycles
         sta reumem+1     ;4 cycles
         nop
;        lda #0           ;2 cycles     could be spared, but banks were manipulated due testing ;)
         sta reumem+2     ;4 cycles
         lda #<131+68     ;2 cycles
         sta translen     ;4 cycles
         lda #>131+68     ;2 cycles
         sta translen+1   ;4 cycles       
;        ldx #%10010001		;direction is to the C64... already loaded to x before
         stx reucmd       ;4 cycles    = 50 cycles + 131 cycles reu-copy = 181 cycles

;-----------------------------------------------------------------------------------------
;timing	(68 Cycles left to waste without the "jmp"), could be used for further effect etc.
;-----------------------------------------------------------------------------------------
;         ldy #13
;wait
;				 dey
;				 bne wait
;				 nop     
;--------------> we dont use those commands to save 6 Bytes in the waitloop, this is
;--------------> just because of the 256 Byte-Intro-Limit. Remove the comments and 
;--------------> the "68" on the 4 lines (Line 56/58/114/116) to see it more crispy
colors
         jmp main2        ;3 cycles    =184        Ziel: 252 (=3*84) (=4*63) cycles --> 4 Lines at all
;----------------------------------------------------------------------------------------
;the "colors" label was meant to be behind the jmp but I needed 2 more bytes, and a 
;jump $0853 is $4c $53 $08... which is a nice color-tab, too ~8). Got 1 Byte left 
;still to fill. Lets use it at the end...

;!byte $0b,$0b,$0b
!byte $0b,$0b,$0b,$0b,$0b
!byte $0b,$0b,$0b,$0b,$0b,$0b,$0b,$0b
!byte $0b,$0b,$0b,$01,$01,$0d,$01,$0d
!byte $0d,$0f,$0d,$0f,$0f,$03,$0f,$03
!byte $03,$0c,$03,$0c,$0c,$0e,$0c,$0e
!byte $0e,$04,$0e,$04,$04,$06,$04,$06
!byte $06,$0b,$06,$0b,$0b,$09,$0b,$09
!byte $09,$02,$09,$02,$02,$0c,$02,$0c
!byte $08,$0f,$0a,$00,$00,$00,$00,$00
!byte $00,$00,$00,$00,$00,$00,$00,$00
!byte $00,$00,$01,$0d,$01,$0d,$0d,$0f
!byte $0d,$0f,$0f,$03,$0f,$03,$03,$0c
!byte $03,$0c,$0c,$0e,$0c,$0e,$0e,$04
!byte $0e,$04,$04,$06,$04,$06,$06,$0b
!byte $06,$0b,$0b,$09,$0b,$09,$09,$02
!byte $09,$02,$02,$08,$02,$08,$08,$0a
!byte $08,$0a,$0b													;last byte defines color between rasters

;-------------------> This Byte is totally wasted, because we CAN DO! Have a nice Day ~8] Why not "64"?
!byte $64