
RAM_PaletteATM EQU $FF1400
RAM_PaletteTO EQU $FF1500
Ram_PaletteBuilt EQU $FF1600
;RAM_HSCROLL EQU $FF0400
;RAM_VSCROLL EQU $FF1400


z80request macro
    move.w #$100, ($A11100)
@waitz80:
    btst.b #0, ($A11100)
    bne.s @waitz80
    endm

z80release macro
    move.w #$000, ($A11100)
    endm

z80reset macro
    move.w #$000, ($A11200)
    rept $10
    nop
    endr
    move.w #$100, ($A11200)
    endm

FMsetParam macro port, chan, data
    WaitYM
    move.b #port, ($A04000+(chan>>2)*2)
    move.b #data, ($A04001+(chan>>2)*2)
    endm

FMwriteParam2 macro port, chan, data
    WaitYM
    move.b #port, ($A04000+(chan>>2)*2)
    move.b \data, ($A04001+(chan>>2)*2)
    endm

WaitYM macro

    btst.b #7, ($a04000)
    bne.s *-8
    endm


LogoMania:
    DISABLEINTS
   
    lea titanpal, a0
    
    move.w #$9001, (VDPControl)
    
    SingleDMAVRAM Titan, 32, 32*1000, VDPCONTROL
    SETVRAMADDR $E000, VDPControl
    move.l #28, d7
    moveq #0, d5
@Mappomania

    moveq #40-1, d6
@Filled
    addq.w #1, d5
    move.w d5, (VDPDATA)
    dbf d6, @Filled
    
    moveq #24-1, d6
@Notfilled
    move.w #0, (VDPDATA)
    dbf d6, @NotFilled
    
    dbf d7, @Mappomania
    
    lea RAM_PaletteATM, a0
    
    rept 16
    move.b #0, (a0)+
    move.b #0, (a0)+
    move.b #0, (a0)+
    endr
    
    lea TitanPal, a0
    
    jsr FadeIN
    
    move.w #200, d7
    jsr WAITD7
    
    lea (random256), a0
    
    move.w #$8B03, VDPCONTROL
  


    
    move.w #50, d7    
    move.w #8, d3
    jsr EndHorizDistort  
    
    move.w #150, d7    
    move.w #0, d3
    jsr EndHorizDistort 
    
    lea (RANDOM256), a0
    moveq #0, d0
    move.w #$2E, d7
    
    lea (Random256), a5
    lea (Random256), a4
@DoPals
    moveq #0, d6
    setvramaddr $F800, vdpcontrol
    move.w #224*2, d5
@distort1:					
    move.b (a5)+, d0
    and.w #$00FF, d0
    ;add.w #384, d0
    sub.w #$80, d0
    lsr.w d3, d0
    move.w d0, (VDPDATA)
    dbf d5, @distort1
    move.b (a4)+, d6
    lea (random256), a5
    lea (a5, d6.w), a5
    waitframe
    singledmacram TitanPal, 0, 32, VDPCONTROL
    moveq #0, d6
    setvramaddr $F800, vdpcontrol
    move.w #224*2, d5
@distort2 
    move.b (a5)+, d0
    and.w #$00FF, d0
    ;add.w #384, d0
    sub.w #$80, d0
    lsr.w d3, d0
    move.w d0, (VDPDATA)
    dbf d5, @distort2
    move.b (a4)+, d6
    lea (random256), a5
    lea (a5, d6.w), a5
    waitframe
    singledmacram Random256, 0, 32, VDPCONTROL
    
	    Echo_z80request
        move.b ($A01200), d0
        move.b #0, ($A01200)
        echo_z80release
    dbf d7, @DoPals

    singledmacram White, 0, 32,  VDPCONTROL
    lea RAM_PaletteATM, a2
    moveq #16-1, d0
@FillWhite
    move.b #$0E, (a2)+
    move.b #$0E, (a2)+
    move.b #$0E, (a2)+
    dbf d0, @FillWhite   
    
    lea RAM_PaletteTO, a2
    moveq #16-1, d0
@FillWhite2
    move.b #$00, (a2)+
    move.b #$00, (a2)+
    move.b #$00, (a2)+
    dbf d0, @FillWhite2

    jsr fadeout
        
    rts

White:
    hex 0EEE0EEE0EEE0EEE0EEE0EEE0EEE0EEE0EEE0EEE0EEE0EEE0EEE0EEE0EEE0EEE
    even
FadeOUT:

    moveq #15, d7
    
@FADELOOP:
    lea RAM_PaletteATM, a0

    moveq #(3*16)-1, d6
@ColorParse
    move.b (a0)+, d0
    tst.b d0
    beq.s @dontcare
    subq.b #1, d0
    move.b d0, -1(a0)
@dontcare
    dbf d6, @ColorParse

    lea RAM_PaletteATM, a0
    lea RAM_PaletteBuilt, a1
    
    moveq #16-1, d6
@BuildPal:
    move.b (a0)+, (a1)+
    move.b (a0)+, d0
    lsl.b #4, d0
    or.b (a0)+, d0
    move.b d0, (a1)+
    dbf d6, @BuildPal

    SingleDMACram RAM_PaletteBuilt, 0, 32, VDPControl
    
    WaitFrame
    WaitFrame
    WaitFrame
    WaitFrame
    dbf d7, @FADELOOP

    rts

FadeIN:
    moveq #16-1, d7
    lea RAM_PaletteTo, a1
@Loadmajig
    move.b (a0)+, (a1)+
    move.b (a0), d0
    lsr.b #4, d0
    move.b d0, (a1)+
    move.b (a0)+, d0
    and.b #$0F, d0
    move.b d0, (a1)+    
    dbf d7, @Loadmajig


    moveq #15, d7
    
@FADELOOP:
    lea RAM_PaletteATM, a0
    lea RAM_PaletteTO, a1

    moveq #(3*16)-1, d6
@ColorParse
    move.b (a0)+, d0
    move.b (a1)+, d1
    cmp.b d0, d1
    beq.s @dontcare
    addq.b #1, d0
    move.b d0, -1(a0)
@dontcare
    dbf d6, @ColorParse

    lea RAM_PaletteATM, a0
    lea RAM_PaletteBuilt, a1
    
    moveq #16-1, d6
    
@BuildPal:
    move.b (a0)+, (a1)+
    move.b (a0)+, d0
    lsl.b #4, d0
    or.b (a0)+, d0
    move.b d0, (a1)+
    dbf d6, @BuildPal    

    SingleDMACram RAM_PaletteBuilt, 0, 32, VDPControl
    
    WaitFrame
    WaitFrame
    dbf d7, @FADELOOP

    rts
  
     align $8000
Titan:
    incbin ./taiten/titan.bin
    even
Titanpal:
    incbin ./taiten/titanpal.bin
Titansound:
    incbin ./taiten/titan.snd
    even
titansound_End:

