;Willams cart Bank Copy / Run routine
;written by Nir Dary
;
;i.e SpeedKing game from Mastertronics
;Loads to memory $5480 -> $9840, Run address $9800
DOSINI = $0C ;**
DOSVEC = $0A
TMPFROM = $CA ;Tmp Source addrss
TMPTO = $CC ;Tmp Destination address
TMPEND = $CE ;Tmp Last source address to copy
TMPTABLE = $D0 ;Table address
TMPRUN = $C2 ;Game Run address
Org $0600 ; (This Data will be located at $A000)
TABLE .BYTE $00,$B4 ; Game Start Addrss $5000
.BYTE $00,$00,$B4,$00,$B4,$00,$B5 ; Bank 01, A000 -> 5000 move 8K bytes
.BYTE $01,$00,$A0,$00,$20,$00,$C0 ; Bank 02, A000 -> 7000 move 8K bytes
.BYTE $02,$00,$A0,$00,$40,$00,$C0 ; $FF ends the copy routine
.BYTE $03,$00,$A0,$00,$60,$00,$B0
.BYTE $FF
START STX $03E9
STX $03EA
DEX
STX $D301
LDA #$01
STA $09
STA $42
STA $03F8
LDA #
TABLE
STA TMPTABLE+1
LDA (TMPTABLE),Y ; Load GameRun Address from table
STA TMPRUN
INC TMPTABLE
LDA (TMPTABLE),Y
STA TMPRUN+1
INC TMPTABLE
LDA #$00 ; Move 0100 bytes to 0600 region, jump there to finish load
STA TMPTO
STA TMPFROM
TAY
LDA #$06
STA TMPTO+1
LDA #$A0
STA TMPFROM+1
L11 LDA (TMPFROM),Y
STA (TMPTO),Y
INY
BNE L11
JMP COPY ;ie. jmp 0600 region to move code out of cartridge
COPY LDA #$00
STA $D40E
SEI
LDA #$FE
STA $D301
L22 LDY #$00 ;Load Bank# from table into X register
LDA (TMPTABLE),Y ;and deted if End of Table then exit to run game
CMP #$FF
BEQ EXITCOPY
TAX
INC TMPTABLE
LDA (TMPTABLE),Y ; Load Source Address from table
STA TMPFROM
INC TMPTABLE
LDA (TMPTABLE),Y
STA TMPFROM+1
INC TMPTABLE
LDA (TMPTABLE),Y ;Load Destination Address from table
STA TMPTO
INC TMPTABLE
LDA (TMPTABLE),Y
STA TMPTO+1
INC TMPTABLE
LDA (TMPTABLE),Y ;Load End address of copy sequace
STA TMPEND
INC TMPTABLE
LDA (TMPTABLE),Y
STA TMPEND+1
INC TMPTABLE
;Start of Copy Routine
MAINLOOP STA $D500,X ;enter Williams cart desired bank
LDA (TMPFROM),Y
STA $D508 ;Turn cartrige off
STA (TMPTO),Y
INC TMPFROM
BNE L1
INC TMPFROM+1
L1 INC TMPTO
BNE L2
INC TMPTO+1
L2 LDA TMPFROM+1 ; Copy unitl address end addres in table
CMP TMPEND+1
BNE MAINLOOP
LDA TMPFROM
CMP TMPEND
BNE MAINLOOP
BEQ L22 ; Do next Bank?
EXITCOPY LDA #$22
STA $D400 ;DMA control
LDA #$FF
STA $D301 ;RAM under ROM off, ROM on
LDA #$C0 ;Some games need 40???**
STA $D40E ;NMI interrupts allowed, see Mapping Atari
CLI
LDA #WAIT3+1 ;**
STA DOSINI+1
STA DOSVEC+1
LDA #$C0 ;C000 high byte
STA $2E4 ;system size, sometimes not important, sometimes is!
STA $2E6 ;**
STA $6A ;dl list ends here and goes down in memory apprx0300h bytes.
LDA #$00 ;cart interlock, could be LDA d013
STA $03FA ;off
STA $42 ;critic OK for long interrupts
LDA #$00
STA $244 ; COLDST
LDA #$01
STA $08 ; WARMST
RTS
;
WAIT3 LDA $14 ;*****
CLC
ADC #$03 ;3 SCREENS
L3 CMP $14
BNE L3
JMP $B400
;
Org $BFFA
.WORD $0000
.BYTE $00
.BYTE $00
.WORD START