;==========================================================================================
;
;   UNOFFICIAL SNES POWERPAK FIRMWARE V2.02 (CODENAME: "SIMBA")
;   (c) 2012/2013 by ManuLöwe (http://www.manuloewe.de/)
;
;	*** FUNCTIONS: READ LASTSNES.TXT ***
;	Code in this file based on v1.0X code written by:
;	- bunnyboy (SNES PowerPak creator), (c) 2009
;
;==========================================================================================



; *************************** Load last game ***************************

LoadLastGame:
	FindFile "LASTSNES.TXT"

	lda #<sectorBuffer1
	sta destLo
	lda #>sectorBuffer1
	sta destHi				; put into sector RAM
	stz destBank

	stz sectorCounter
	stz bankCounter

	jump jClusterToLBA			; sourceCluster -> first sourceSector

	lda #kDestWRAM
	sta destType

	jump jCardReadSector			; sector -> WRAM

	rep #A_8BIT				; A = 16 bit

	ldx #$0000
	ldy #$0000

LoadLastGameLoop:				; game name and cluster
	lda sectorBuffer1, y
	sta gameName, x
	inx
	inx
	iny
	iny
	cpx #$0080				; 128 bytes
	bne LoadLastGameLoop

	ldx #$0000

LoadLastSaveLoop:				; save name and cluster
	lda sectorBuffer1, y
	sta saveName, x
	inx
	inx
	iny
	iny
	cpx #$0080				; 128 bytes
	bne LoadLastSaveLoop

	ldx #$0000

LoadLastGameGenieLoop:				; GameGenie codes
	lda sectorBuffer1, y
	sta GameGenie.Codes, x
	inx
	inx
	iny
	iny
	cpx #$0028
	bne LoadLastGameGenieLoop

	sep #A_8BIT				; A = 8 bit
rts

; **********************************************************************
