;contiki 1.1-rc0 on cart experiment
;14/08/03 iAN CooG/TWT^HF
;compile with dasm
;$1000 Thanx to Markus Brenner and his dumping programs

                processor 6502
                org $8000
SCREEN = $0400
PROGRAMSTART = $080b

                .byte $09, $80
                .byte $5E, $FE
                .byte $C3,$C2,$CD,$38,$30

                JSR $FDA3 ;init code ripped from Doubledragon -start
                JSR $FD50 ;
                JSR $FD15 ;
                JSR $FF5B ;
                CLI       ;
                ;JSR $E453 ;
                ;JSR $E3BF ;
                ;JSR $E422 ;- end

                LDX #$FF
                TXS
                INX
                STX $D011
                LDA #$C8
                STA $D016
                LDA #$15
                STA $D018
                LDA #$79
                STA $D019
                LDA #$F0
                STA $D01A
                LDA #$00
                STA $D020
                STA $D021
                ldy #0
transf:         lda moveh,y
                sta SCREEN,y
                iny
                bne transf
                jmp docart
moveh:
                rorg SCREEN

docart:
                ldx #<$800
                lda #>$800
                stx $fe
                sta $ff
                ldx #<eocode
                lda #>eocode
                stx $fc
                sta $fd
                ldx #<$c000
                lda #>$c000
                stx $2d
                sta $2e
                jsr reloc

;nextbank:       lda #$01
                ;cmp #$02
                ;beq exit
                ;ora #$80
                ;sta $d020
                ;sta $de00
                ; destination $fe-ff is same from last transfer
                ; eg: last transfer finished at 1fff now $fe,ff=00,20
                ldx #<$8000
                lda #>$8000
                stx $fc
                sta $fd
                ldx #<$a000
                lda #>$a000
                stx $2d
                sta $2e
                jsr reloc

                ;inc nextbank+1
                ;jmp nextbank

exit:
                lda #$00
                sta $de00
                lda #$37
                sta $01
                ldx #$1b
                STX $D011
                STX $D020
                cli
startprg        JMP PROGRAMSTART

reloc:          ldy #0
trb:            lda ($fc),y
                sta ($fe),y
                ;if fc==2d && fd==2e finished
                lda $fc
                eor $2d
                bne next0
                sta $02
                lda $fd
                eor $2e
                bne next0
                clc
                adc $02
                beq finish

next0:          inc $fc
                lda $fc
                bne next1
                inc $fd
next1:          inc $fe
                lda $fe
                bne trb
                inc $ff
next2:          jmp trb

finish:         rts



                rend
eocode:         .byte 0 ; this is the first byte @ $0800
