;align macro 
 ;  cnop 0,\1
  ; endm


;WaitFrame macro
 ;  stop #$2500
  ; endm
   


timer1      Equ $FF000A
VSync       EQU $FF0008 
VRAM_Flags  EQU $FF0000 ; VRAM Flags for nametable
Palette     EQU $FF0010
Echo68K     EQU $FF0040 ; /
VUMeters    EQU $FF0050 ; 
EchoZ80     EQU $A01FA0 ;
VuTiles     EQU $FF0060
HINTTIMER   EQU $FF0260
ScreenScr   EQU $FF0262
BGScr       EQU $FF0264
LoadOIF:                ; Loads an Optimized Image File
 MOVE.L #"TOIF", D0     ; D2=Start Tile
 SUB.L  (A0)+, D0
 lea VDPDATA, A6
 MOVE.W (A0)+, D3       ; Xlen
 MOVE.W (A0)+, D4       ; Ylen
 MOVE.W D2, D7
 LSL.W  #5, D2          ; Point to correct address...
 MOVE.W D2, D0
 ROL.W  #2, D0          ; A14, A15
 AND.W  #3, D0
 AND.W  #$3FFF, D2
 OR.W   #$4000, D2
 SWAP   D2
 MOVE.W D0, D2          ; Add lower part
 MOVE.L D2, 4(A6)       ; Write command+screen pointer
 MOVE.W (A0)+, D0       ; Load all tiles from the OIF to VRAM
LoadOIFtiles:
 MOVE.L (A0)+, (A6)
 MOVE.L (A0)+, (A6)
 MOVE.L (A0)+, (A6)
 MOVE.L (A0)+, (A6)
 MOVE.L (A0)+, (A6)
 MOVE.L (A0)+, (A6)
 MOVE.L (A0)+, (A6)
 MOVE.L (A0)+, (A6)
 DBRA   D0, LoadOIFtiles
 MOVE.W #%0000000000000000, D2   ; Display these tiles
 MOVE.W #0, D6
OYloop:
 MOVE.W D6, D0
 LSL.W  #6, D0
 ADD.W  #0, D0      ; D0=Y, D1=X
 ADD.W  D0, D0
 ADD.W  #$E000, D0    ; Add Pattern table address
 MOVE.W D0, D1
 ROL.W  #2, D1
 AND.W  #3, D1
 AND.W  #$3FFF, D0
 OR.W   #$4000, D0
 SWAP   D0
 MOVE.W D1, D0          ; Add lower part
 MOVE.L D0, 4(A6)       ; Write command+screen pointer
 MOVE.L D3, D5
OXloop:
 MOVE.W (A0)+, D0
 ADD.W  D7, D0
 OR.W   D2, D0          ; Add additional attributes
 MOVE.W D0, (A6)
 DBRA   D5, OXloop
 ADDQ.W #1, D6
 DBRA   D4, OYloop
 RTS
Axelay:
    move.w  #$8114, (VDPControl) 

    DisableInts
    move.l #Axelay_VINT, (RAM_VINTLOC+2)
    move.w #$8F02, (VDPCONTROL)
    move.w #$8B00, (VDPControl)
    move.w #$855b, (VDPControl)
     move.w #$8a00, (VDPControl)
     move.w #$9011, (VDPControl)
    lea (Hint_Seifert), a0
    lea (RAM_HInt), a1
    move.l #((Hint_Seifert_End-Hint_Seifert)/2)-1,d0   
@CopyHINT:
    move.w (a0)+, (a1)+
    dbf d0, @CopyHINT 
    
  

;    lea (AXELAY_FG_ART), a0
;    lea (RLEData), a1
;    jsr RunLengthDeCoDiNg

    move.w #$8d2e, vdpcontrol
    moveq #0, d2
    lea (OIFTileS), a0
    jsr LoadOIF 
    
    SingleDMACRAM Axelay_BG_PAL, 0, 32, VDPCONTROL

    singledmavram axelay_FG_ART, 861*32, 583*32, VDPCONTROL
    
    
    SingleDMACRAM Axelay_FG_PAL, 32,32, VDPCONTROL
    lea AXELAY_FG_MAP, a0
    setvramaddr $C000, vdpcontrol
    move.w #64*64, d0
@LOADFGMAP
    move.w (a0)+, d1
    add.w #861, d1
    or.w #%0010000000000000, d1
    move.w d1, vdpdata
    dbf d0, @LOADFGMAP
    
    
    lea Axelay_ScrollTable, a6
    move.w  #$8174, (VDPControl)          ; Enable display, interrupts, all the good shit
    EnableInts
   
@LOOPMANIATOR:

    subq.w #1, (BGSCR)
    subq.w #2, (SCREENSCR)
    WaitFrame
        
        Echo_z80request
        move.b ($A01200), d0
        move.b #0, ($A01200)
        echo_z80release
        tst.b d0
        beq.w @LOOPMANIATOR

    lea (Sinetwister2), a0
    lea (Sinetwister2+$180), a1
    
@ROTATELOOP

    move.w (a0, d7.w), d6
    lsl.w #1, d6
    move.w d6, (BGSCR)     ; BG
    lsl.w #1, d6
    move.w d6, (SCREENSCR) ; FG
    
    setvramaddr $B800, vdpcontrol
    move.w (a1, d7.w), d6
    
    lsl.w #1, d6
    lsl.w #1, d6
    move.w d6, vdpdata     ; BG
    lsr.w #1, d6
    move.w d6, vdpdata ; FG
    
    
    
    WaitFrame
        
        addq.w #4, d7
        cmp.w #1536, d7
        bne.w @noreset
        moveq #0, d7
        
@noreset
        
        
        Echo_z80request
        move.b ($A01200), d0
        move.b #0, ($A01200)
        echo_z80release
        tst.b d0
        beq.w @ROTATELOOP  
    
@ArrTeeEss:
    rts
        
    
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
; Routines of miscellaneous usefulness levels

; ---------------------------------------------------------------------------
; Subroutine to transfer a mapping to the VDP
;
; Address to the map goes in a5
; Number of columns to d0
; Number of rows to d1
; VDP VRAM (ie $40000003) address to d2.
; ---------------------------------------------------------------------------

Screen_Map:    
      lea      ($C00000).l,a6             ; Load VDP data port address to a6
      lea      $04(a6),a4                 ; Load VDP address port address to a4
      move.l   #$00800000,d4              ; Prepare line add value

SM_Row:
      move.l   d2,(a4)                    ; Set VDP to VRam write mode
      move.w   d0,d3                   ; Reload number of columns

SM_Column:
      move.w   (a5)+,(a6)                 ; Dump map to VDP map slot
      dbf      d3,SM_Column               ; Repeat til columns have dumped
      add.l d4,d2                   ; Increase to next row on VRam
      dbf      d1,SM_Row                  ; Repeat til all rows have dumped
      rts                              ; Return To Sub
 

; ---------------------------------------------------------------------------
; Subroutine to transfer a mapping to the VDP while adding a value to each
; tile automagically.
;
; Address to the map goes in a5
; Number of columns to d0
; Number of rows to d1
; VDP address to d2.
; Value to add to each entry in the mapping to d6.
; ---------------------------------------------------------------------------

Screen_Map_WithAdd:     
      lea      ($C00000).l, a6               ; Load VDP data port address to a6
      lea      4(a6), a4                  ; Load VDP address port address to a4
      move.l   #$00800000, d4             ; Prepare line add value

@SM_Row:
      move.l   d2, (a4)                ; Set VDP to VRam write mode
      move.w   d0, d3                     ; Reload number of columns

@SM_Column:
      move.w   (a5)+, d5                  ; Dump map to d5
      add.w d6, d5                     ; Add addition offset to the tile.
      move.w   d5, (a6)                ; Write to VDP
      dbf      d3, @SM_Column             ; Repeat til columns have dumped
      add.l d4, d2                     ; Increase to next row on VRam
      dbf      d1, @SM_Row                ; Repeat til all rows have dumped
      rts
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;; Interrrupts 'n schits (Secret code for what does the effect)

HInt_Seifert: 
   DisableInts                             ; Disable interrupts

   movem.l  d0-d1/a0, -(sp)                             ; Back up registers

   cmp.b    #225, (HINTTIMER)                        ; Have we reached the bottom?
   bne.s    @NoReset                                 ; If not, branch.
   move.b   #0, (HINTTIMER)                          ; Reset scanline counter
@NoReset:
 
   moveq    #0, d0                                   ; Clear d0
   move.b   (HINTTIMER), d0                          ; Copy current scanline to d0
   add.w    d0, d0                                   ; Multiply by two for offset into table   
   move.w   (a6, d0.w), d0                ; Get entry for current scanline from table
   add.w    (ScreenScr), d0                          ; Add overall scroll to the value
   move.l   #$40000010, (VDPControl)                 ; First VSCRAM entry
   move.w   d0, (VDPDATA)                            ; Set to computed value
   
   moveq    #0, d0                                   ; Clear d0
   move.b   (HINTTIMER), d0                          ; Copy current scanline to d0
   add.w    d0, d0                                   ; Multiply by two for offset into table   
   move.w   (a6, d0.w), d0                ; Get entry for current scanline from table
   add.w    (BGScr), d0                              ; Add overall scroll to the value
   move.l   #$40020010, (VDPControl)                 ; First VSCRAM entry
   move.w   d0, (VDPDATA)                            ; Set to computed value
   
   addq.b   #1, (HINTTIMER)                          ; Increase scanline counter.

   movem.l  (sp)+, d0-d1/a0     
   EnableInts                     ; Enable interrupts again
   rte
Hint_Seifert_End:
    
Axelay_ScrollTable:
   include "./axelay/scrolltable.asm"
   even
   
Axelay_VInt:
   move.w   #0, (HINTTIMER)                          ; Reset HScroll timer
   
   rte
   
   even
    
;####################################################################################################
; Data 'n schits
    
    
OIFTiles:
   incbin   "./axelay/gfx.oif"
   even

Axelay_BG_Map:
   incbin   "./axelay/bg.map"
   even

Axelay_BG_Pal
 DC.L   $00000080, $0C200042, $08880666, $00460220
 DC.L   $00EE0A60, $00A00A40, $00600AAA, $02680024
   even

Axelay_FG_art:
   incbin   "./axelay/foreground.bin"
   even
      
Axelay_FG_pal:
   incbin   "./axelay/foreground.pal"
   even


Axelay_FG_map:
   incbin   "./axelay/foreground.MAP"
   even

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;; Interrrupts 'n schits (Secret code for what does the effect)


ScrollTable_2:
   incbin "./axelay/scrolltable.asm"
   
   even
