;
; File generated by cc65 v 2.13.1
;
	.fopt		compiler,"cc65 v 2.13.1"
	.setcpu		"6502"
	.smart		on
	.autoimport	on
	.case		on
	.debuginfo	on
	.importzp	sp, sreg, regsave, regbank, tmp1, ptr1, ptr2
	.macpack	longbranch
	.dbg		file, "../../../filesystem/fat/src/ff.c", 66917, 1267200484
	.dbg		file, "../inc/manifest.h", 151, 1267200480
	.dbg		file, "C:\Programme\cc65\include/string.h", 4883, 1262467470
	.dbg		file, "C:\Programme\cc65\include/stddef.h", 2972, 1262467470
	.dbg		file, "C:\Programme\cc65\include/stdio.h", 5964, 1262467470
	.dbg		file, "C:\Programme\cc65\include/stdarg.h", 2817, 1262467470
	.dbg		file, "../../../filesystem/fat/inc/dir_banked.h", 439, 1267200484
	.dbg		file, "../../../filesystem/fat/inc/ff_banked.h", 1017, 1267200484
	.dbg		file, "../../../filesystem/fat/inc/ff.h", 11459, 1267200484
	.dbg		file, "../../../data/inc/types.h", 1544, 1267200498
	.dbg		file, "../../../filesystem/fat/inc/dir.h", 2992, 1267200484
	.dbg		file, "../../../io/inc/diskio.h", 2164, 1267200496
	.dbg		file, "../../../io/inc/gpio.h", 4272, 1267200496
	.dbg		file, "../../../data/inc/data_tools.h", 1380, 1267200498
	.dbg		file, "../../../debug/inc/dump_hex.h", 1030, 1267200486
	.import		_strlen
	.import		_strncmp
	.import		_strncpy
	.import		_memcmp
	.import		_memcpy
	.import		_memset
	.import		_printf
	.import		_sprintf
	.export		_clust2sect
	.export		_banked_f_open
	.export		_banked_f_open_direct
	.export		_banked_f_read
	.export		_banked_f_close
	.export		_banked_f_lseek
	.export		_banked_f_opendir
	.export		_banked_f_opendir_direct
	.export		_banked_f_readdir
	.export		_f_readdir_lfn
	.export		_banked_f_stat
	.export		_banked_f_getfree
	.export		_banked_f_mountdrv
	.export		_banked_f_write
	.export		_banked_f_sync
	.export		_banked_f_unlink
	.export		_banked_f_mkdir
	.export		_banked_f_chmod
	.export		_banked_f_rename
	.export		_banked_f_create_file_entry
	.export		_banked_f_create_dir_entry
	.export		_banked_f_unlink_entry
	.export		_banked_f_unlink_direct
	.export		_banked_f_rename_direct
	.importzp	_FatFs_fs_type
	.importzp	_FatFs_files
	.importzp	_FatFs_sects_clust
	.importzp	_FatFs_n_fats
	.importzp	_FatFs_n_rootdir
	.importzp	_FatFs_winflag
	.importzp	_FatFs_winsect
	.importzp	_FatFs_sects_fat
	.importzp	_FatFs_max_clust
	.importzp	_FatFs_fatbase
	.importzp	_FatFs_dirbase
	.importzp	_FatFs_database
	.importzp	_FatFs_last_clust
	.import		_FatFs_win
	.import		_disk_initialize
	.import		_disk_status
	.import		_disk_read
	.import		_disk_write
	.import		_get_fattime
	.import		_data_strnlen
	.export		_move_window
	.export		_get_cluster
	.export		_put_cluster
	.export		_remove_chain
	.export		_create_chain
	.export		_check_fs
	.export		_next_dir_entry
	.export		_get_fileinfo
	.export		_calc_lfn_checksum
	.export		_make_dirfile
	.export		_trace_path
	.export		_reserve_direntry
	.export		_reserve_direntries
	.export		_valid_char
	.export		_create_lfn
	.export		_find_lfn
	.export		_check_mounted
	.export		_init_dir

.segment	"RODATA"

L0001:
	.byte	$7E,$25,$64,$00,$64,$69,$72,$20,$6E,$6F,$74,$20,$65,$6D,$70,$74
	.byte	$79,$0A,$00,$72,$65,$70,$6C,$61,$63,$65,$21,$0A,$00,$61,$70,$70
	.byte	$65,$6E,$64,$21,$20,$28,$66,$69,$6C,$65,$73,$69,$7A,$65,$20,$3D
	.byte	$20,$25,$6C,$64,$29,$0A,$00,$4E,$75,$6D,$62,$65,$72,$20,$6F,$66
	.byte	$20,$63,$6C,$75,$73,$74,$65,$72,$73,$20,$74,$6F,$20,$63,$72,$65
	.byte	$61,$74,$65,$3A,$20,$25,$64,$2E,$0A,$00,$72,$65,$70,$6C,$61,$63
	.byte	$65,$21,$0A,$00

.segment	"BSS"

_temp_name:
	.res	23,$00
_firstscan:
	.res	14,$00
_lastscan:
	.res	14,$00
_tempscan:
	.res	14,$00

; ---------------------------------------------------------------
; unsigned long __near__ clust2sect (unsigned long)
; ---------------------------------------------------------------

.segment	"LIBCODE"

.proc	_clust2sect: near

.segment	"LIBCODE"

;
; clust -= 2;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 284
	ldx     #$00
	stx     sreg
	stx     sreg+1
	lda     #$02
	jsr     lsubeq0sp
;
; if (clust >= FatFs_max_clust) return 0;  /* Invalid cluster# */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 285
	jsr     ldeax0sp
	jsr     pusheax
	lda     _FatFs_max_clust+3
	sta     sreg+1
	lda     _FatFs_max_clust+2
	sta     sreg
	ldx     _FatFs_max_clust+1
	lda     _FatFs_max_clust
	jsr     tosugeeax
	beq     L0113
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	jmp     incsp4
;
; return clust * FatFs_sects_clust + FatFs_database;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 286
L0113:	jsr     ldeax0sp
	jsr     pusheax
	ldx     #$00
	lda     _FatFs_sects_clust
	jsr     tosumul0ax
	jsr     pusheax
	lda     _FatFs_database+3
	sta     sreg+1
	lda     _FatFs_database+2
	sta     sreg
	ldx     _FatFs_database+1
	lda     _FatFs_database
	jsr     tosaddeax
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 287
	jmp     incsp4
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_open (__near__ struct _FIL*, __near__ const signed char*, unsigned char)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_open: near

.segment	"FILESYS"

;
; if ((res = check_mounted()) != FR_OK) return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1059
	ldy     #$1D
	jsr     subysp
	jsr     _check_mounted
	ldy     #$1C
	sta     (sp),y
	cmp     #$00
	beq     L069C
	ldx     #$00
	lda     (sp),y
	jmp     L069A
;
; if ((mode & (FA_WRITE|FA_CREATE_ALWAYS|FA_OPEN_ALWAYS)) && (disk_status() & STA_PROTECT))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1061
L069C:	iny
	lda     (sp),y
	and     #$1A
	beq     L06A1
	ldy     #$00
	jsr     _disk_status
	and     #$04
	beq     L06A1
;
; return FR_WRITE_PROTECTED;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1062
	ldx     #$00
	lda     #$09
	jmp     L069A
;
; res = trace_path(&dirscan, fn, path, &dir); /* Trace the file path */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1065
L06A1:	jsr     decsp8
	lda     sp
	ldx     sp+1
	clc
	adc     #$14
	bcc     L06AC
	inx
L06AC:	ldy     #$06
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$08
	bcc     L06AE
	inx
L06AE:	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$27
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$22
	bcc     L06B1
	inx
L06B1:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _trace_path
	ldy     #$1C
	sta     (sp),y
;
; if (mode & (FA_CREATE_ALWAYS|FA_OPEN_ALWAYS)) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1069
	iny
	lda     (sp),y
	and     #$18
	jeq     L06B2
;
; if (res != FR_OK) {  /* No file, create new */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1071
	jsr     decsp4
	ldy     #$20
	lda     (sp),y
	jeq     L06B5
;
; mode |= FA_CREATE_ALWAYS;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1072
	iny
	lda     (sp),y
	ora     #$08
	sta     (sp),y
;
; if (res != FR_NO_FILE) return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1073
	dey
	lda     (sp),y
	cmp     #$02
	beq     L06B9
	ldx     #$00
	lda     (sp),y
	jsr     incsp4
	jmp     L069A
;
; dir = reserve_direntry(&dirscan, 0); /* Reserve a directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1074
L06B9:	jsr     decsp4
	lda     sp
	ldx     sp+1
	clc
	adc     #$14
	bcc     L06BF
	inx
L06BF:	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #$00
	tay
	sta     (sp),y
	iny
	sta     (sp),y
	jsr     _reserve_direntry
	ldy     #$1E
	jsr     staxysp
;
; if (dir == NULL) return FR_DENIED;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1075
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cpx     #$00
	bne     L06C1
	cmp     #$00
	bne     L06C1
	lda     #$05
	jsr     incsp4
	jmp     L069A
;
; memcpy(dir, fn, 8+3);  /* Initialize the new entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1076
L06C1:	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	lda     sp
	ldx     sp+1
	clc
	adc     #$06
	bcc     L06C8
	inx
L06C8:	jsr     pushax
	ldx     #$00
	lda     #$0B
	jsr     _memcpy
;
; *(dir+12) = fn[11];
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1077
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0C
	bcc     L06CC
	inx
L06CC:	sta     ptr1
	stx     ptr1+1
	ldy     #$0F
	lda     (sp),y
	ldy     #$00
	sta     (ptr1),y
;
; memset(dir+13, 0, 32-13);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1078
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0D
	bcc     L06D2
	inx
L06D2:	sta     ptr1
	stx     ptr1+1
	lda     #$00
	ldy     #$12
L0D85:	sta     (ptr1),y
	dey
	bpl     L0D85
;
; } else {    /* Any object is already existing */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1079
	jmp     L06E0
;
; if ((dir == NULL) || (*(dir+11) & (AM_RDO|AM_DIR))) /* Could not overwrite (R/O or DIR) */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1080
L06B5:	dey
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cpx     #$00
	bne     L0D87
	cmp     #$00
	beq     L06D7
L0D87:	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$11
	beq     L06D6
;
; return FR_DENIED;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1081
L06D7:	ldx     #$00
	lda     #$05
	jsr     incsp4
	jmp     L069A
;
; if (mode & FA_CREATE_ALWAYS) { /* Resize it to zero */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1082
L06D6:	ldy     #$21
	lda     (sp),y
	and     #$08
	jeq     L06E0
;
; dw = FatFs_winsect;   /* Remove the cluster chain */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1083
	lda     _FatFs_winsect+3
	sta     sreg+1
	lda     _FatFs_winsect+2
	sta     sreg
	ldx     _FatFs_winsect+1
	lda     _FatFs_winsect
	jsr     steax0sp
;
; if (!remove_chain(((DWORD)LD_WORD(dir+20) << 16) | LD_WORD(dir+26))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1084
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L06EA
	inx
L06EA:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	sta     sreg+1
	dey
	lda     (ptr1),y
	sta     sreg
	tya
	tax
	jsr     pusheax
	ldy     #$23
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L06ED
	inx
L06ED:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     tosor0ax
	jsr     pusheax
;
; || !move_window(dw) )
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1085
	jsr     _remove_chain
	tax
	beq     L06E5
	jsr     ldeax0sp
	jsr     pusheax
	jsr     _move_window
	tax
	bne     L06E4
;
; return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1086
L06E5:	lda     #$07
	jsr     incsp4
	jmp     L069A
;
; ST_WORD(dir+20, 0); ST_WORD(dir+26, 0); /* cluster = 0 */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1087
L06E4:	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L06F3
	inx
L06F3:	sta     ptr1
	stx     ptr1+1
	lda     #$00
	tay
	sta     (ptr1),y
	iny
	sta     (ptr1),y
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L06F8
	inx
L06F8:	sta     sreg
	stx     sreg+1
	lda     #$00
	tay
	sta     (sreg),y
	iny
	sta     (sreg),y
;
; ST_DWORD(dir+28, 0);     /* size = 0 */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1088
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L06FD
	inx
L06FD:	jsr     pushax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	tay
	jsr     steaxspidx
;
; if (mode & FA_CREATE_ALWAYS) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1091
L06E0:	ldy     #$21
	lda     (sp),y
	and     #$08
	beq     L0700
;
; if(mode & FA_CREATE_HIDDEN) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1092
	lda     (sp),y
	and     #$20
	beq     L0702
;
; *(dir+11) = AM_SYS | AM_HID;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1093
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0B
	bcc     L0706
	inx
L0706:	sta     ptr1
	stx     ptr1+1
	lda     #$06
;
; } else {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1094
	jmp     L0D89
;
; *(dir+11) = AM_ARC;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1095
L0702:	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0B
	bcc     L070B
	inx
L070B:	sta     ptr1
	stx     ptr1+1
	lda     #$20
L0D89:	ldy     #$00
	sta     (ptr1),y
;
; dw = get_fattime();
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1097
	jsr     _get_fattime
	jsr     steax0sp
;
; ST_DWORD(dir+14, dw); /* Created time */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1098
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0E
	bcc     L0711
	inx
L0711:	jsr     pushax
	ldy     #$05
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
;
; ST_DWORD(dir+22, dw); /* Updated time */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1099
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$16
	bcc     L0716
	inx
L0716:	jsr     pushax
	ldy     #$05
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1100
	lda     #$01
	sta     _FatFs_winflag
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1102
L0700:	jsr     incsp4
;
; else {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1104
	jmp     L0728
;
; if (res != FR_OK) return res;  /* Trace failed */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1106
L06B2:	dey
	lda     (sp),y
	beq     L071C
	ldx     #$00
	lda     (sp),y
	jmp     L069A
;
; if ((dir == NULL) || (*(dir+11) & AM_DIR)) /* It is a directory */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1107
L071C:	dey
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cpx     #$00
	bne     L0D88
	cmp     #$00
	beq     L0720
L0D88:	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$10
	beq     L071F
;
; return FR_NO_FILE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1108
L0720:	ldx     #$00
	lda     #$02
	jmp     L069A
;
; if ((mode & FA_WRITE) && (*(dir+11) & AM_RDO)) /* R/O violation */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1110
L071F:	ldy     #$1D
	lda     (sp),y
	and     #$02
	beq     L0728
	ldy     #$1B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$01
	beq     L0728
;
; return FR_DENIED;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1111
	ldx     #$00
	lda     #$05
	jmp     L069A
;
; fp->flag = mode & (FA_WRITE|FA_READ);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1118
L0728:	ldy     #$21
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	stx     sreg+1
	ldy     #$1D
	lda     (sp),y
	and     #$03
	ldy     #$1A
	sta     (sreg),y
;
; fp->dir_sect = FatFs_winsect;   /* Pointer to the directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1119
	ldy     #$21
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	lda     _FatFs_winsect+3
	sta     sreg+1
	lda     _FatFs_winsect+2
	sta     sreg
	ldx     _FatFs_winsect+1
	lda     _FatFs_winsect
	ldy     #$14
	jsr     steaxspidx
;
; fp->dir_ptr  = dir;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1120
	ldy     #$21
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$18
	sta     (ptr1),y
	iny
	txa
	sta     (ptr1),y
;
; fp->org_clust = ((DWORD)LD_WORD(dir+20) << 16) | LD_WORD(dir+26); /* File start cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1122
	ldy     #$21
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$1D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L073D
	inx
L073D:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	sta     sreg+1
	dey
	lda     (ptr1),y
	sta     sreg
	tya
	tax
	jsr     pusheax
	ldy     #$21
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L0740
	inx
L0740:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     tosor0ax
	ldy     #$08
	jsr     steaxspidx
;
; fp->fsize = LD_DWORD(dir+28);  /* File size */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1123
	ldy     #$21
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$1D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L0745
	inx
L0745:	jsr     ldeaxi
	ldy     #$04
	jsr     steaxspidx
;
; fp->fptr = 0;      /* File ptr */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1124
	ldy     #$21
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	tay
	jsr     steaxspidx
;
; fp->sect_clust = 1;     /* Sector counter */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1125
	ldy     #$21
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$01
	ldy     #$1B
	sta     (ptr1),y
;
; FatFs_files++;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1126
	lda     _FatFs_files
	clc
	adc     #$01
	sta     _FatFs_files
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1127
	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1128
L069A:	ldy     #$22
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_open_direct (__near__ struct _FIL*, __near__ struct _DIRENTRY*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_open_direct: near

.segment	"FILESYS"

;
; if ((res = check_mounted()) != FR_OK) return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1137
	jsr     decsp1
	jsr     _check_mounted
	ldy     #$00
	sta     (sp),y
	cmp     #$00
	beq     L074D
	ldx     #$00
	lda     (sp),y
	jmp     incsp5
;
; fp->flag     = FA_READ | ((entry->fattrib & AM_RDO) ? 0 : FA_WRITE); 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1144
L074D:	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	stx     sreg+1
	dey
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$08
	lda     (ptr1),y
	and     #$01
	beq     L0756
	lda     #$00
	jmp     L0758
L0756:	lda     #$02
L0758:	ora     #$01
	ldy     #$1A
	sta     (sreg),y
;
; fp->dir_sect = 0L;   /* Pointer to the directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1145
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	ldy     #$14
	jsr     steaxspidx
;
; fp->dir_ptr  = NULL;         /* set to NULL, to indicate that we never want to change it */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1146
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	ldy     #$18
	sta     (ptr1),y
	iny
	sta     (ptr1),y
;
; fp->org_clust = entry->fcluster;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1150
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	ldy     #$08
	jsr     steaxspidx
;
; fp->fsize = entry->fsize;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1151
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	ldy     #$04
	jsr     steaxspidx
;
; fp->fptr = 0;    /* File ptr */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1152
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	tay
	jsr     steaxspidx
;
; fp->sect_clust = 1;   /* Sector counter */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1153
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$01
	ldy     #$1B
	sta     (ptr1),y
;
; FatFs_files++;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1155
	lda     _FatFs_files
	clc
	adc     #$01
	sta     _FatFs_files
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1156
	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1157
	jmp     incsp5
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_read (__near__ struct _FIL*, __near__ void*, unsigned short, __near__ unsigned short*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_read: near

.segment	"FILESYS"

;
; BYTE cc, *rbuff = buff;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1171
	ldy     #$0F
	jsr     subysp
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
;
; *br = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1175
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	tay
	sta     (ptr1),y
	iny
	sta     (ptr1),y
;
; if ((disk_status() & STA_NOINIT) || !FatFs_fs_type) return FR_NOT_READY; /* Check disk ready */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1176
	dey
	jsr     _disk_status
	and     #$01
	bne     L076D
	lda     _FatFs_fs_type
	bne     L076C
L076D:	ldx     #$00
	lda     #$01
	jmp     L0768
;
; if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1177
L076C:	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$80
	jne     L0D8B
;
; if (!(fp->flag & FA_READ)) return FR_DENIED; /* Check access mode */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1178
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$01
	bne     L0774
	tax
	lda     #$05
	jmp     L0768
;
; ln = fp->fsize - fp->fptr;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1179
L0774:	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	jsr     pusheax
	ldy     #$1C
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	jsr     tossubeax
	ldy     #$05
	jsr     steaxysp
;
; if (btr > ln) btr = (WORD)ln;     /* Truncate read count by number of bytes left */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1180
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0A
	jsr     ldeaxysp
	jsr     tosulong
	jsr     tosugteax
	beq     L077A
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$13
	jsr     staxysp
;
; for ( ;  btr;         /* Repeat until all data transferred */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1182
L077A:	ldy     #$14
	lda     (sp),y
	dey
	ora     (sp),y
	jeq     L077F
;
; if ((fp->fptr % 512) == 0) {    /* On the sector boundary */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1184
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	jsr     pusheax
	ldx     #$01
	lda     #$FF
	jsr     tosand0ax
	jsr     pusheax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	jsr     toseqeax
	jeq     L07CA
;
; if (--(fp->sect_clust)) {    /* Decrement left sector counter */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1185
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1B
	lda     (ptr1),y
	sec
	sbc     #$01
	sta     (ptr1),y
	tax
	beq     L078E
;
; sect = fp->curr_sect + 1;   /* Get current sector */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1186
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$13
	jsr     ldeaxidx
	ldy     #$01
	jsr     inceaxy
	ldy     #$09
	jsr     steaxysp
;
; } else {        /* On the cluster boundary, get next cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1187
	jmp     L0793
;
; clust = (fp->fptr == 0) ? fp->org_clust : get_cluster(fp->curr_clust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1188
L078E:	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	jsr     pusheax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	jsr     toseqeax
	beq     L0797
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	jsr     ldeaxidx
	jmp     L0799
L0797:	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0F
	jsr     ldeaxidx
	jsr     pusheax
	jsr     _get_cluster
L0799:	ldy     #$0D
	jsr     steaxysp
;
; if ((clust < 2) || (clust >= FatFs_max_clust)) goto fr_error;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1190
	ldy     #$10
	jsr     ldeaxysp
	cmp     #$02
	txa
	sbc     #$00
	lda     sreg
	sbc     #$00
	lda     sreg+1
	sbc     #$00
	jcc     L07A1
	ldy     #$10
	jsr     ldeaxysp
	jsr     pusheax
	lda     _FatFs_max_clust+3
	sta     sreg+1
	lda     _FatFs_max_clust+2
	sta     sreg
	ldx     _FatFs_max_clust+1
	lda     _FatFs_max_clust
	jsr     tosugeeax
	jne     L07A1
;
; fp->curr_clust = clust;    /* Current cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1191
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$12
	jsr     ldeaxysp
	ldy     #$0C
	jsr     steaxspidx
;
; sect = clust2sect(clust);   /* Get current sector */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1192
	ldy     #$10
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _clust2sect
	ldy     #$09
	jsr     steaxysp
;
; fp->sect_clust = FatFs_sects_clust; /* Re-initialize the left sector counter */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1193
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     _FatFs_sects_clust
	ldy     #$1B
	sta     (ptr1),y
;
; if (fp->flag & FA__DIRTY) {    /* Flush file I/O buffer if needed */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1196
L0793:	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$40
	beq     L07A9
;
; if (disk_write(fp->buffer, fp->curr_sect, 1) != RES_OK) goto fr_error;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1197
	jsr     decsp7
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L07AE
	inx
L07AE:	ldy     #$05
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$13
	jsr     ldeaxidx
	ldy     #$01
	jsr     steaxysp
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _disk_write
	cmp     #$00
	jne     L07A1
;
; fp->flag &= ~FA__DIRTY;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1198
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$BF
	sta     (ptr1),y
;
; fp->curr_sect = sect;     /* Update current sector */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1201
L07A9:	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0E
	jsr     ldeaxysp
	ldy     #$10
	jsr     steaxspidx
;
; cc = btr / 512;       /* When left bytes >= 512, */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1202
	ldy     #$14
	lda     (sp),y
	lsr     a
	ldy     #$02
	sta     (sp),y
;
; if (cc) {        /* Read maximum contiguous sectors directly */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1203
	lda     (sp),y
	jeq     L07B7
;
; if (cc > fp->sect_clust) cc = fp->sect_clust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1204
	lda     (sp),y
	jsr     pusha0
	ldy     #$1A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1B
	lda     (ptr1),y
	jsr     tosicmp0
	bcc     L07B9
	beq     L07B9
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1B
	lda     (ptr1),y
	ldy     #$02
	sta     (sp),y
;
; if (disk_read(rbuff, sect, cc) != RES_OK) goto fr_error;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1205
L07B9:	jsr     decsp7
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$05
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$13
	jsr     ldeaxysp
	ldy     #$01
	jsr     steaxysp
	ldy     #$09
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	jsr     _disk_read
	cmp     #$00
	jne     L07A1
;
; fp->sect_clust -= cc - 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1206
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	sta     ptr1
	stx     ptr1+1
	ldy     #$1B
	lda     (ptr1),y
	jsr     pusha0
	ldy     #$06
	lda     (sp),y
	sec
	sbc     #$01
	bcs     L07C4
	ldx     #$FF
L07C4:	jsr     tossubax
	ldy     #$1B
	jsr     staspidx
;
; fp->curr_sect += cc - 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1207
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$13
	jsr     ldeaxidx
	jsr     pusheax
	ldy     #$08
	ldx     #$00
	lda     (sp),y
	sec
	sbc     #$01
	bcs     L07C7
	dex
L07C7:	jsr     tosadd0ax
	ldy     #$10
	jsr     steaxspidx
;
; rcnt = cc * 512; continue;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1208
	ldy     #$02
	lda     (sp),y
	sta     tmp1
	lda     #$00
	asl     a
	rol     tmp1
	ldx     tmp1
	iny
	jsr     staxysp
	jmp     L0780
;
; if (disk_read(fp->buffer, sect, 1) != RES_OK) /* Load the sector into file I/O buffer */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1210
L07B7:	jsr     decsp7
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L07CD
	inx
L07CD:	ldy     #$05
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$13
	jsr     ldeaxysp
	ldy     #$01
	jsr     steaxysp
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _disk_read
	cmp     #$00
;
; goto fr_error;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1211
	jne     L07A1
;
; rcnt = 512 - ((WORD)fp->fptr % 512);    /* Copy fractional bytes from file I/O buffer */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1213
L07CA:	ldx     #$02
	lda     #$00
	jsr     pushax
	ldy     #$1A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	tay
	txa
	and     #$01
	tax
	tya
	jsr     tossubax
	ldy     #$03
	jsr     staxysp
;
; if (rcnt > btr) rcnt = btr;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1214
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sec
	ldy     #$13
	sbc     (sp),y
	sta     tmp1
	txa
	iny
	sbc     (sp),y
	ora     tmp1
	bcc     L07D3
	beq     L07D3
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$03
	jsr     staxysp
;
; memcpy(rbuff, &fp->buffer[fp->fptr % 512], rcnt);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1215
L07D3:	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$1A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L07DA
	inx
L07DA:	jsr     pushax
	ldy     #$1C
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	jsr     pusheax
	ldx     #$01
	lda     #$FF
	jsr     tosand0ax
	jsr     tosaddax
	jsr     pushax
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     _memcpy
;
; rbuff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1183
L0780:	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     addeq0sp
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	jsr     ldeaxi
	jsr     pusheax
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     tosadd0ax
	ldy     #$00
	jsr     steaxspidx
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	stx     sreg+1
	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     ptr1
	pha
	txa
	adc     ptr1+1
	tax
	pla
	ldy     #$00
	sta     (sreg),y
	iny
	txa
	sta     (sreg),y
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$13
	jsr     subeqysp
	jmp     L077A
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1218
L077F:	tax
	jmp     L0768
;
; fp->flag |= FA__ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1221
L07A1:	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	ora     #$80
	sta     (ptr1),y
;
; return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1222
L0D8B:	ldx     #$00
	lda     #$07
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1223
L0768:	ldy     #$19
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_close (__near__ struct _FIL*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_close: near

.segment	"FILESYS"

;
; res = f_sync(fp);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1406
	jsr     decsp1
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	jsr     _banked_f_sync
	ldy     #$00
	sta     (sp),y
;
; if (res == FR_OK) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1410
	lda     (sp),y
	bne     L08F0
;
; fp->flag = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1411
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	stx     sreg+1
	lda     #$00
	ldy     #$1A
	sta     (sreg),y
;
; fp->org_clust = 0L; // clear, so if we want to know if the file is open, we can check this field.
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1412
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	ldy     #$08
	jsr     steaxspidx
;
; FatFs_files--;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1413
	lda     _FatFs_files
	sec
	sbc     #$01
	sta     _FatFs_files
;
; return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1415
L08F0:	ldx     #$00
	lda     (sp,x)
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1416
	jmp     incsp3
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_lseek (__near__ struct _FIL*, unsigned long)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_lseek: near

.segment	"FILESYS"

;
; if ((disk_status() & STA_NOINIT) || !FatFs_fs_type) return FR_NOT_READY;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1315
	jsr     decsp5
	ldy     #$00
	jsr     _disk_status
	and     #$01
	bne     L086C
	lda     _FatFs_fs_type
	bne     L086B
L086C:	ldx     #$00
	lda     #$01
	jmp     L086A
;
; if (fp->flag & FA__ERROR) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1316
L086B:	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$80
	jne     L0D8E
;
; if (fp->flag & FA__DIRTY) {   /* Write-back dirty buffer if needed */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1318
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$40
	beq     L0873
;
; if (disk_write(fp->buffer, fp->curr_sect, 1) != RES_OK) goto fk_error;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1319
	jsr     decsp7
	ldy     #$11
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L0878
	inx
L0878:	ldy     #$05
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$11
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$13
	jsr     ldeaxidx
	ldy     #$01
	jsr     steaxysp
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _disk_write
	cmp     #$00
	jne     L087B
;
; fp->flag &= ~FA__DIRTY;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1320
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$BF
	sta     (ptr1),y
;
; if (ofs > fp->fsize) ofs = fp->fsize; /* Clip offset by file size */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1323
L0873:	ldy     #$08
	jsr     ldeaxysp
	jsr     pusheax
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	jsr     tosugteax
	beq     L087E
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	ldy     #$05
	jsr     steaxysp
;
; fp->fptr = ofs; fp->sect_clust = 1;  /* Re-initialize file pointer */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1324
L087E:	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0A
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$01
	ldy     #$1B
	sta     (ptr1),y
;
; if (ofs) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1327
	ldy     #$08
	jsr     ldeaxysp
	jsr     utsteax
	jeq     L08A6
;
; ofs = (ofs - 1) / 512;    /* Calcurate current sector */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1328
	ldy     #$08
	jsr     ldeaxysp
	ldy     #$01
	jsr     deceaxy
	txa
	ldx     sreg
	ldy     sreg+1
	sty     sreg
	ldy     #$00
	sty     sreg+1
	jsr     shreax1
	ldy     #$05
	jsr     steaxysp
;
; sc = FatFs_sects_clust;    /* Number of sectors in a cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1329
	lda     _FatFs_sects_clust
	ldy     #$00
	sta     (sp),y
;
; fp->sect_clust = sc - ((BYTE)ofs % sc); /* Calcurate sector counter */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1330
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$02
	lda     (sp),y
	jsr     pusha0
	ldy     #$09
	lda     (sp),y
	jsr     pusha0
	ldy     #$06
	lda     (sp),y
	jsr     tosumoda0
	jsr     tossubax
	ldy     #$1B
	jsr     staspidx
;
; ofs /= sc;       /* Number of clusters to skip */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1331
	ldy     #$08
	jsr     ldeaxysp
	jsr     pusheax
	ldy     #$04
	ldx     #$00
	lda     (sp),y
	jsr     tosudiv0ax
	ldy     #$05
	jsr     steaxysp
;
; clust = fp->org_clust;    /* Seek to current cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1332
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	jsr     ldeaxidx
L0D8F:	ldy     #$01
	jsr     steaxysp
;
; while (ofs--)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1333
	ldy     #$08
	jsr     ldeaxysp
	jsr     saveeax
	ldy     #$01
	jsr     deceaxy
	ldy     #$05
	jsr     steaxysp
	jsr     resteax
	jsr     utsteax
	beq     L0895
;
; clust = get_cluster(clust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1334
	ldy     #$04
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _get_cluster
	jmp     L0D8F
;
; if ((clust < 2) || (clust >= FatFs_max_clust)) goto fk_error;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1335
L0895:	ldy     #$04
	jsr     ldeaxysp
	cmp     #$02
	txa
	sbc     #$00
	lda     sreg
	sbc     #$00
	lda     sreg+1
	sbc     #$00
	jcc     L087B
	ldy     #$04
	jsr     ldeaxysp
	jsr     pusheax
	lda     _FatFs_max_clust+3
	sta     sreg+1
	lda     _FatFs_max_clust+2
	sta     sreg
	ldx     _FatFs_max_clust+1
	lda     _FatFs_max_clust
	jsr     tosugeeax
	jne     L087B
;
; fp->curr_clust = clust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1336
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$06
	jsr     ldeaxysp
	ldy     #$0C
	jsr     steaxspidx
;
; fp->curr_sect = clust2sect(clust) + sc - fp->sect_clust; /* Current sector */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1337
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$06
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _clust2sect
	jsr     pusheax
	ldy     #$06
	ldx     #$00
	lda     (sp),y
	jsr     tosadd0ax
	jsr     pusheax
	ldy     #$10
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1B
	ldx     #$00
	lda     (ptr1),y
	jsr     tossub0ax
	ldy     #$10
	jsr     steaxspidx
;
; if (fp->fptr % 512) {          /* Load currnet sector if needed */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1338
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	jsr     pusheax
	ldx     #$01
	lda     #$FF
	jsr     tosand0ax
	jsr     utsteax
	beq     L08A6
;
; if (disk_read(fp->buffer, fp->curr_sect, 1) != RES_OK)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1339
	jsr     decsp7
	ldy     #$11
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L08A9
	inx
L08A9:	ldy     #$05
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$11
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$13
	jsr     ldeaxidx
	ldy     #$01
	jsr     steaxysp
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _disk_read
	cmp     #$00
;
; goto fk_error;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1340
	bne     L087B
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1344
L08A6:	ldx     #$00
	txa
	jmp     L086A
;
; fp->flag |= FA__ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1347
L087B:	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	ora     #$80
	sta     (ptr1),y
;
; return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1348
L0D8E:	ldx     #$00
	lda     #$07
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1349
L086A:	ldy     #$0B
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_opendir (__near__ struct _DIR*, __near__ const signed char*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_opendir: near

.segment	"FILESYS"

;
; if ((res = check_mounted()) != FR_OK) return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1434
	ldy     #$0F
	jsr     subysp
	jsr     _check_mounted
	ldy     #$0E
	sta     (sp),y
	cmp     #$00
	jne     L0D92
;
; res = trace_path(scan, fn, path, &dir); /* Trace the directory path */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1436
	jsr     decsp8
	ldy     #$1A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$06
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$08
	bcc     L0903
	inx
L0903:	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$14
	bcc     L0906
	inx
L0906:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _trace_path
	ldy     #$0E
	sta     (sp),y
;
; if (res == FR_OK) {      /* Trace completed */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1438
	lda     (sp),y
	jne     L091E
;
; if (dir != NULL) {     /* It is not a root dir */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1439
	dey
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cpx     #$00
	bne     L0D91
	cmp     #$00
	jeq     L091E
;
; if (*(dir+11) & AM_DIR) {  /* The entry is a directory */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1440
L0D91:	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	dey
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$10
	jeq     L090C
;
; scan->clust = ((DWORD)LD_WORD(dir+20) << 16) | LD_WORD(dir+26);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1441
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L0915
	inx
L0915:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	sta     sreg+1
	dey
	lda     (ptr1),y
	sta     sreg
	tya
	tax
	jsr     pusheax
	ldy     #$13
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L0918
	inx
L0918:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     tosor0ax
	ldy     #$04
	jsr     steaxspidx
;
; scan->sect = clust2sect(scan->clust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1442
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	jsr     pusheax
	jsr     _clust2sect
	ldy     #$08
	jsr     steaxspidx
;
; scan->index = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1443
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	ldy     #$0C
	sta     (ptr1),y
	iny
	sta     (ptr1),y
;
; } else {      /* The entry is not directory */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1444
	jmp     L091E
;
; res = FR_NO_FILE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1445
L090C:	lda     #$02
	ldy     #$0E
	sta     (sp),y
;
; return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1449
L091E:	ldy     #$0E
L0D92:	ldx     #$00
	lda     (sp),y
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1450
	ldy     #$13
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_opendir_direct (__near__ struct _DIR*, const unsigned long)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_opendir_direct: near

.segment	"FILESYS"

;
; if ((res = check_mounted()) != FR_OK) return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1459
	jsr     decsp1
	jsr     _check_mounted
	ldy     #$00
	sta     (sp),y
	cmp     #$00
	beq     L0923
	ldx     #$00
	lda     (sp),y
	jmp     incsp7
;
; if(!cluster) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1461
L0923:	ldy     #$04
	jsr     ldeaxysp
	jsr     bnegeax
	jeq     L0928
;
; if (FatFs_fs_type == FS_FAT32) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1462
	lda     _FatFs_fs_type
	cmp     #$03
	bne     L092A
;
; scan->clust = scan->sclust = FatFs_dirbase;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1463
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	lda     _FatFs_dirbase+3
	sta     sreg+1
	lda     _FatFs_dirbase+2
	sta     sreg
	ldx     _FatFs_dirbase+1
	lda     _FatFs_dirbase
	ldy     #$00
	jsr     steaxspidx
	ldy     #$04
	jsr     steaxspidx
;
; scan->sect = clust2sect(FatFs_dirbase);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1464
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	lda     _FatFs_dirbase+3
	sta     sreg+1
	lda     _FatFs_dirbase+2
	sta     sreg
	ldx     _FatFs_dirbase+1
	lda     _FatFs_dirbase
;
; } else {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1465
	jmp     L0D96
;
; scan->clust = scan->sclust = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1466
L092A:	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	tay
	jsr     steaxspidx
	ldy     #$04
	jsr     steaxspidx
;
; scan->sect = FatFs_dirbase;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1467
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	lda     _FatFs_dirbase+3
	sta     sreg+1
	lda     _FatFs_dirbase+2
	sta     sreg
	ldx     _FatFs_dirbase+1
	lda     _FatFs_dirbase
;
; } else {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1469
	jmp     L0D94
;
; scan->clust = cluster;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1470
L0928:	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$06
	jsr     ldeaxysp
	ldy     #$04
	jsr     steaxspidx
;
; scan->sect = clust2sect(scan->clust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1471
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxidx
L0D96:	jsr     pusheax
	jsr     _clust2sect
L0D94:	ldy     #$08
	jsr     steaxspidx
;
; scan->index = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1473
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	ldy     #$0C
	sta     (ptr1),y
	iny
	sta     (ptr1),y
;
; scan->sclust = scan->clust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1474
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxidx
	ldy     #$00
	jsr     steaxspidx
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1476
	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1477
	jmp     incsp7
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_readdir (__near__ struct _DIR*, __near__ struct _FILINFO*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_readdir: near

.segment	"FILESYS"

;
; finfo->fname[0] = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1489
	jsr     decsp3
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	ldy     #$0D
	sta     (ptr1),y
;
; if ((disk_status() & STA_NOINIT) || !FatFs_fs_type) return FR_NOT_READY;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1490
	tay
	jsr     _disk_status
	and     #$01
	bne     L0949
	lda     _FatFs_fs_type
	bne     L0948
L0949:	ldx     #$00
	lda     #$01
	jmp     incsp7
;
; while (scan->sect) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1492
L0948:	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	jsr     ldeaxidx
	jsr     utsteax
	jeq     L094E
;
; if (!move_window(scan->sect)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1493
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	jsr     ldeaxidx
	jsr     pusheax
	jsr     _move_window
	tax
	bne     L0950
	lda     #$07
	jmp     incsp7
;
; dir = &(FatFs_win[(scan->index & 15) * 32]);  /* pointer to the directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1494
L0950:	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0C
	lda     (ptr1),y
	ldx     #$00
	and     #$0F
	jsr     shlax4
	stx     tmp1
	asl     a
	rol     tmp1
	clc
	adc     #<(_FatFs_win)
	tay
	lda     tmp1
	adc     #>(_FatFs_win)
	tax
	tya
	ldy     #$01
	jsr     staxysp
;
; c = *dir;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1495
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	dey
	lda     (ptr1),y
	sta     (sp),y
;
; if (c == 0) return FR_NO_FILE;        /* Has it reached to end of dir? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1496
	lda     (sp),y
	jeq     L094E
;
; if ((c != 0xE5) && (c != '.') && !(*(dir+11) & AM_VOL)) /* Is it a valid entry? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1497
	lda     (sp),y
	cmp     #$E5
	beq     L095E
	lda     (sp),y
	cmp     #$2E
	beq     L095E
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$08
	bne     L095E
;
; get_fileinfo(finfo, dir);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1498
	jsr     decsp4
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _get_fileinfo
;
; if (!next_dir_entry(scan)) scan->sect = 0;  /* Next entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1499
L095E:	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	jsr     _next_dir_entry
	tax
	bne     L096A
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	ldy     #$08
	jsr     steaxspidx
;
; if (finfo->fname[0]) return FR_OK;      /* Found valid entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1500
L096A:	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0D
	jsr     ldaidx
	jeq     L0948
	ldx     #$00
	txa
	jmp     incsp7
;
; return FR_NO_FILE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1503
L094E:	ldx     #$00
	lda     #$02
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1504
	jmp     incsp7
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ f_readdir_lfn (__near__ struct _DIR*, __near__ struct _FILINFO*, __near__ signed char*, unsigned char, __near__ signed char*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_f_readdir_lfn: near

.segment	"FILESYS"

;
; finfo->fname[0] = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 796
	jsr     decsp5
	ldy     #$0B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	ldy     #$0D
	sta     (ptr1),y
;
; if ((disk_status() & STA_NOINIT) || !FatFs_fs_type) return FR_NOT_READY;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 797
	tay
	jsr     _disk_status
	and     #$01
	bne     L04BE
	lda     _FatFs_fs_type
	bne     L04BD
L04BE:	ldx     #$00
	lda     #$01
	jmp     L04B8
;
; while (scan->sect) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 799
L04BD:	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	dey
	jsr     ldeaxidx
	jsr     utsteax
	jeq     L04C3
;
; if (!move_window(scan->sect)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 800
	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	dey
	jsr     ldeaxidx
	jsr     pusheax
	jsr     _move_window
	tax
	bne     L04C5
	lda     #$07
	jmp     L04B8
;
; entry = &(FatFs_win[(scan->index & 15) * 32]);  /* pointer to the directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 801
L04C5:	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	ldx     #$00
	and     #$0F
	jsr     shlax4
	stx     tmp1
	asl     a
	rol     tmp1
	clc
	adc     #<(_FatFs_win)
	tay
	lda     tmp1
	adc     #>(_FatFs_win)
	tax
	tya
	ldy     #$03
	jsr     staxysp
;
; c = *entry;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 802
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	ldy     #$02
	sta     (sp),y
;
; if (c == 0) return FR_NO_FILE;      /* Has it reached to end of dir? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 803
	lda     (sp),y
	jeq     L04C3
;
; if((*(entry+11) & AM_LFN)==AM_LFN) {            /* Long file name entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 804
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$0F
	cmp     #$0F
	jne     L04D3
;
; chk = *(entry+13);                          /* store checksum for comparison later */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 805
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0D
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	ldy     #$00
	sta     (sp),y
;
; c = (c & 0x1F) - 1;                         /* take lower 5 bits of entry index, and subtract one */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 806
	ldy     #$02
	lda     (sp),y
	and     #$1F
	sec
	sbc     #$01
	sta     (sp),y
;
; c += (c << 3) + (c << 2);                   /* multiply by 13, c = start offset in buffer */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 807
	ldx     #$00
	lda     (sp),y
	jsr     aslax3
	sta     ptr1
	stx     ptr1+1
	ldx     #$00
	lda     (sp),y
	jsr     aslax2
	clc
	adc     ptr1
	pha
	txa
	adc     ptr1+1
	pla
	clc
	adc     (sp),y
	sta     (sp),y
;
; for(i=1;(i<=30)&&(c<maxlen);i+=2,c++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 808
	lda     #$01
	dey
L0D9D:	sta     (sp),y
	ldy     #$01
	lda     (sp),y
	cmp     #$1F
	jcs     L051E
	iny
	ldx     #$00
	lda     (sp),y
	ldy     #$07
	cmp     (sp),y
	jcs     L051E
;
; longname[c] = entry[i];
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 809
	ldy     #$02
	lda     (sp),y
	clc
	ldy     #$08
	adc     (sp),y
	sta     sreg
	txa
	iny
	adc     (sp),y
	sta     sreg+1
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (sp),y
	tay
	lda     (ptr1),y
	ldy     #$00
	sta     (sreg),y
;
; if(i==9) i+=3; /* jump to 14 */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 810
	iny
	lda     (sp),y
	cmp     #$09
	bne     L04F7
	clc
	lda     #$03
	adc     (sp),y
	sta     (sp),y
;
; if(i==24) i+=2; /* jump to 28 */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 811
L04F7:	lda     (sp),y
	cmp     #$18
	bne     L04E7
	clc
	lda     #$02
	adc     (sp),y
	sta     (sp),y
;
; for(i=1;(i<=30)&&(c<maxlen);i+=2,c++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 808
L04E7:	clc
	lda     #$02
	adc     (sp),y
	sta     (sp),y
	iny
	lda     (sp),y
	clc
	adc     #$01
	jmp     L0D9D
;
; else if ((c != 0xE5) && (c != '.') && !(*(entry+11) & AM_VOL)) { /* Is it a valid entry? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 814
L04D3:	ldy     #$02
	lda     (sp),y
	cmp     #$E5
	jeq     L051E
	lda     (sp),y
	cmp     #$2E
	jeq     L051E
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$08
	jne     L051E
;
; get_fileinfo(finfo, entry);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 815
	jsr     decsp4
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _get_fileinfo
;
; ext[0] = *(entry+8);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 816
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$08
	bcc     L0510
	inx
L0510:	ldy     #$00
	jsr     ldaidx
	jsr     staspidx
;
; ext[1] = *(entry+9);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 817
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$09
	bcc     L0515
	inx
L0515:	ldy     #$00
	jsr     ldaidx
	iny
	jsr     staspidx
;
; ext[2] = *(entry+10);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 818
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0A
	bcc     L051A
	inx
L051A:	ldy     #$00
	jsr     ldaidx
	ldy     #$02
	jsr     staspidx
;
; c = calc_lfn_checksum(entry); 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 819
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	jsr     _calc_lfn_checksum
	ldy     #$02
	sta     (sp),y
;
; if(c != chk) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 820
	ldx     #$00
	lda     (sp),y
	ldy     #$00
	cmp     (sp),y
	bne     L0D9C
	txa
	beq     L051E
;
; longname[0] = '\0'; // kill long file name
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 821
L0D9C:	ldy     #$09
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	tay
	sta     (ptr1),y
;
; if (!next_dir_entry(scan)) scan->sect = 0;  /* Next entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 825
L051E:	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	jsr     _next_dir_entry
	tax
	bne     L0523
	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	ldy     #$08
	jsr     steaxspidx
;
; if (finfo->fname[0]) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 827
L0523:	ldy     #$0B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0D
	jsr     ldaidx
	jeq     L04BD
;
; return FR_OK;    /* Found valid entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 828
	ldx     #$00
	txa
	jmp     L04B8
;
; return FR_NO_FILE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 832
L04C3:	ldx     #$00
	lda     #$02
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 834
L04B8:	ldy     #$0E
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_stat (__near__ const signed char*, __near__ struct _FILINFO*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_stat: near

.segment	"FILESYS"

;
; if ((res = check_mounted()) != FR_OK) return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1522
	ldy     #$1D
	jsr     subysp
	jsr     _check_mounted
	ldy     #$1C
	sta     (sp),y
	cmp     #$00
	bne     L0D9F
;
; res = trace_path(&dirscan, fn, path, &dir); /* Trace the file path */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1524
	jsr     decsp8
	lda     sp
	ldx     sp+1
	clc
	adc     #$14
	bcc     L097F
	inx
L097F:	ldy     #$06
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$08
	bcc     L0981
	inx
L0981:	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$28
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$22
	bcc     L0984
	inx
L0984:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _trace_path
	ldy     #$1C
	sta     (sp),y
;
; if (res == FR_OK)       /* Trace completed */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1526
	lda     (sp),y
	bne     L0985
;
; get_fileinfo(finfo, dir);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1527
	jsr     decsp4
	ldy     #$22
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _get_fileinfo
;
; return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1529
L0985:	ldy     #$1C
L0D9F:	ldx     #$00
	lda     (sp),y
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1530
	ldy     #$21
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_getfree (__near__ unsigned long*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_getfree: near

.segment	"FILESYS"

;
; if ((res = check_mounted()) != FR_OK) return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1545
	ldy     #$11
	jsr     subysp
	jsr     _check_mounted
	ldy     #$00
	sta     (sp),y
	cmp     #$00
	beq     L098C
	ldx     #$00
	lda     (sp),y
	jmp     L098B
;
; fat = FatFs_fs_type;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1548
L098C:	lda     _FatFs_fs_type
	ldy     #$04
	sta     (sp),y
;
; n = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1549
	ldy     #$0D
	lda     #$00
	sta     (sp),y
	iny
	sta     (sp),y
	iny
	sta     (sp),y
	iny
	sta     (sp),y
;
; if (fat == FS_FAT12) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1551
	ldy     #$04
	lda     (sp),y
	cmp     #$01
	bne     L0995
;
; clust = 2;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1552
	ldy     #$09
	lda     #$02
	sta     (sp),y
	lda     #$00
	iny
	sta     (sp),y
	iny
	sta     (sp),y
	iny
	sta     (sp),y
;
; if ((WORD)get_cluster(clust) == 0) n++;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1554
L0999:	ldy     #$0C
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _get_cluster
	cpx     #$00
	bne     L099C
	cmp     #$00
	bne     L099C
	ldy     #$10
	jsr     ldeaxysp
	jsr     saveeax
	ldy     #$01
	jsr     inceaxy
	ldy     #$0D
	jsr     steaxysp
	jsr     resteax
;
; } while (++clust < FatFs_max_clust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1555
L099C:	ldx     #$00
	stx     sreg
	stx     sreg+1
	lda     #$01
	ldy     #$09
	jsr     laddeqysp
	jsr     pusheax
	lda     _FatFs_max_clust+3
	sta     sreg+1
	lda     _FatFs_max_clust+2
	sta     sreg
	ldx     _FatFs_max_clust+1
	lda     _FatFs_max_clust
	jsr     tosulteax
	bne     L0999
;
; } else {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1556
	jmp     L09AC
;
; clust = FatFs_max_clust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1558
L0995:	lda     _FatFs_max_clust+3
	sta     sreg+1
	lda     _FatFs_max_clust+2
	sta     sreg
	ldx     _FatFs_max_clust+1
	lda     _FatFs_max_clust
	ldy     #$09
	jsr     steaxysp
;
; sect = FatFs_fatbase;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1559
	lda     _FatFs_fatbase+3
	sta     sreg+1
	lda     _FatFs_fatbase+2
	sta     sreg
	ldx     _FatFs_fatbase+1
	lda     _FatFs_fatbase
	ldy     #$05
	jsr     steaxysp
;
; f = 0; p = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1560
	lda     #$00
	ldy     #$03
	sta     (sp),y
	tax
	ldy     #$01
	jsr     staxysp
;
; if (!f) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1562
L09AB:	ldy     #$03
	lda     (sp),y
	bne     L09AE
;
; if (!move_window(sect++)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1563
	ldy     #$08
	jsr     ldeaxysp
	jsr     saveeax
	ldy     #$01
	jsr     inceaxy
	ldy     #$05
	jsr     steaxysp
	jsr     resteax
	jsr     pusheax
	jsr     _move_window
	tax
	bne     L09B0
	lda     #$07
	jmp     L098B
;
; p = FatFs_win;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1564
L09B0:	lda     #<(_FatFs_win)
	ldx     #>(_FatFs_win)
	ldy     #$01
	jsr     staxysp
;
; if (fat == FS_FAT16) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1566
L09AE:	ldy     #$04
	lda     (sp),y
	cmp     #$02
	bne     L09B6
;
; if (LD_WORD(p) == 0) n++;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1567
	tay
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	cpx     #$00
	bne     L09B8
	cmp     #$00
	bne     L09B8
	ldy     #$10
	jsr     ldeaxysp
	jsr     saveeax
	ldy     #$01
	jsr     inceaxy
	ldy     #$0D
	jsr     steaxysp
	jsr     resteax
;
; p += 2; f += 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1568
L09B8:	ldy     #$01
	ldx     #$00
	lda     #$02
	jsr     addeqysp
	ldy     #$03
	clc
	lda     #$01
;
; } else {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1569
	jmp     L0DA1
;
; if (LD_DWORD(p) == 0) n++;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1570
L09B6:	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	jsr     pusheax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	jsr     toseqeax
	beq     L09C3
	ldy     #$10
	jsr     ldeaxysp
	jsr     saveeax
	ldy     #$01
	jsr     inceaxy
	ldy     #$0D
	jsr     steaxysp
	jsr     resteax
;
; p += 4; f += 2;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1571
L09C3:	ldy     #$01
	ldx     #$00
	lda     #$04
	jsr     addeqysp
	ldy     #$03
	clc
	lda     #$02
L0DA1:	adc     (sp),y
	sta     (sp),y
;
; } while (--clust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1573
	ldx     #$00
	stx     sreg
	stx     sreg+1
	lda     #$01
	ldy     #$09
	jsr     lsubeqysp
	jsr     utsteax
	jne     L09AB
;
; *nclust = n;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1577
L09AC:	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$12
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1578
	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1579
L098B:	ldy     #$13
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_mountdrv (void)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_mountdrv: near

.segment	"FILESYS"

;
; memset(&FatFs_fs_type, 0, 35);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1002
	ldy     #$0D
	jsr     subysp
	ldy     #$22
	lda     #$00
L0637:	sta     _FatFs_fs_type,y
	dey
	bpl     L0637
;
; memset(&FatFs_win, 0, 512);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1003
	lda     #<(_FatFs_win)
	ldx     #>(_FatFs_win)
	jsr     pushax
	ldx     #$02
	lda     #$00
	jsr     __bzero
;
; if (disk_initialize() & STA_NOINIT) return FR_NOT_READY;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1006
	ldy     #$00
	jsr     _disk_initialize
	and     #$01
	beq     L063C
	ldx     #$00
	lda     #$01
	jmp     L0632
;
; fat = check_fs(sect = 0);  /* Check sector 0 as an SFD format */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1009
L063C:	tax
	sta     sreg
	sta     sreg+1
	ldy     #$08
	jsr     steaxysp
	jsr     push0ax
	jsr     _check_fs
	ldy     #$0C
	sta     (sp),y
;
; if (!fat) {      /* Not a FAT boot record, it will be an FDISK format */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1010
	lda     (sp),y
	bne     L0645
;
; if (FatFs_win[0x1C2]) {     /* Is the partition existing? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1012
	lda     _FatFs_win+450
	beq     L0645
;
; sect = LD_DWORD(&(FatFs_win[0x1C6])); /* Partition offset in LBA */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1013
	lda     _FatFs_win+454+3
	sta     sreg+1
	lda     _FatFs_win+454+2
	sta     sreg
	ldx     _FatFs_win+454+1
	lda     _FatFs_win+454
	ldy     #$08
	jsr     steaxysp
;
; fat = check_fs(sect);    /* Check the partition */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1014
	ldy     #$0B
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _check_fs
	ldy     #$0C
	sta     (sp),y
;
; if (!fat) return FR_NO_FILESYSTEM; /* No FAT patition */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1017
L0645:	lda     (sp),y
	bne     L0651
	tax
	lda     #$0B
	jmp     L0632
;
; FatFs_fs_type = fat;        /* FAT type */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1020
L0651:	lda     (sp),y
	sta     _FatFs_fs_type
;
; (fat == FS_FAT32) ? LD_DWORD(&(FatFs_win[0x24])) : LD_WORD(&(FatFs_win[0x16]));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1022
	lda     (sp),y
	cmp     #$03
	bne     L0659
	lda     _FatFs_win+36+3
	sta     sreg+1
	lda     _FatFs_win+36+2
	sta     sreg
	ldx     _FatFs_win+36+1
	lda     _FatFs_win+36
	jmp     L065F
L0659:	lda     _FatFs_win+22
	ldx     _FatFs_win+22+1
	ldy     #$00
	sty     sreg
	sty     sreg+1
L065F:	sta     _FatFs_sects_fat
	stx     _FatFs_sects_fat+1
	ldy     sreg
	sty     _FatFs_sects_fat+2
	ldy     sreg+1
	sty     _FatFs_sects_fat+3
;
; FatFs_sects_clust = FatFs_win[0x0D];    /* Sectors per cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1023
	lda     _FatFs_win+13
	sta     _FatFs_sects_clust
;
; FatFs_n_fats = FatFs_win[0x10];      /* Number of FAT copies */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1024
	lda     _FatFs_win+16
	sta     _FatFs_n_fats
;
; FatFs_fatbase = sect + LD_WORD(&(FatFs_win[0x0E])); /* FAT start sector (physical) */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1025
	ldy     #$0B
	jsr     ldeaxysp
	jsr     pusheax
	lda     _FatFs_win+14
	ldx     _FatFs_win+14+1
	jsr     tosadd0ax
	sta     _FatFs_fatbase
	stx     _FatFs_fatbase+1
	ldy     sreg
	sty     _FatFs_fatbase+2
	ldy     sreg+1
	sty     _FatFs_fatbase+3
;
; FatFs_n_rootdir = LD_WORD(&(FatFs_win[0x11]));  /* Nmuber of root directory entries */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1026
	lda     _FatFs_win+17
	sta     _FatFs_n_rootdir
	lda     _FatFs_win+17+1
	sta     _FatFs_n_rootdir+1
;
; fatend = FatFs_sects_fat * FatFs_n_fats + FatFs_fatbase;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1028
	lda     _FatFs_sects_fat+3
	sta     sreg+1
	lda     _FatFs_sects_fat+2
	sta     sreg
	ldx     _FatFs_sects_fat+1
	lda     _FatFs_sects_fat
	jsr     pusheax
	ldx     #$00
	lda     _FatFs_n_fats
	jsr     tosumul0ax
	jsr     pusheax
	lda     _FatFs_fatbase+3
	sta     sreg+1
	lda     _FatFs_fatbase+2
	sta     sreg
	ldx     _FatFs_fatbase+1
	lda     _FatFs_fatbase
	jsr     tosaddeax
	ldy     #$04
	jsr     steaxysp
;
; if (fat == FS_FAT32) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1029
	ldy     #$0C
	lda     (sp),y
	cmp     #$03
	bne     L0679
;
; FatFs_dirbase = LD_DWORD(&(FatFs_win[0x2C])); /* FAT32: Directory start cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1030
	lda     _FatFs_win+44+3
	sta     sreg+1
	lda     _FatFs_win+44+2
	sta     sreg
	ldx     _FatFs_win+44+1
	lda     _FatFs_win+44
	sta     _FatFs_dirbase
	stx     _FatFs_dirbase+1
	ldy     sreg
	sty     _FatFs_dirbase+2
	ldy     sreg+1
	sty     _FatFs_dirbase+3
;
; FatFs_database = fatend;       /* FAT32: Data start sector (physical) */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1031
	ldy     #$07
	jsr     ldeaxysp
;
; } else {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1032
	jmp     L0DA7
;
; FatFs_dirbase = fatend;      /* Directory start sector (physical) */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1033
L0679:	ldy     #$07
	jsr     ldeaxysp
	sta     _FatFs_dirbase
	stx     _FatFs_dirbase+1
	ldy     sreg
	sty     _FatFs_dirbase+2
	ldy     sreg+1
	sty     _FatFs_dirbase+3
;
; FatFs_database = FatFs_n_rootdir / 16 + fatend; /* Data start sector (physical) */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1034
	lda     _FatFs_n_rootdir
	ldx     _FatFs_n_rootdir+1
	jsr     shrax4
	jsr     pushax
	ldy     #$09
	jsr     ldeaxysp
	jsr     tosulong
	jsr     tosaddeax
L0DA7:	sta     _FatFs_database
	stx     _FatFs_database+1
	ldy     sreg
	sty     _FatFs_database+2
	ldy     sreg+1
	sty     _FatFs_database+3
;
; maxsect = LD_DWORD(&(FatFs_win[0x20]));   /* Calculate maximum cluster number */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1036
	lda     _FatFs_win+32+3
	sta     sreg+1
	lda     _FatFs_win+32+2
	sta     sreg
	ldx     _FatFs_win+32+1
	lda     _FatFs_win+32
	jsr     steax0sp
;
; if (!maxsect) maxsect = LD_WORD(&(FatFs_win[0x13]));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1037
	jsr     ldeax0sp
	jsr     bnegeax
	beq     L068E
	lda     _FatFs_win+19
	ldx     _FatFs_win+19+1
	ldy     #$00
	sty     sreg
	sty     sreg+1
	jsr     steax0sp
;
; FatFs_max_clust = (maxsect - FatFs_database + sect) / FatFs_sects_clust + 2;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1038
L068E:	jsr     ldeax0sp
	jsr     pusheax
	lda     _FatFs_database+3
	sta     sreg+1
	lda     _FatFs_database+2
	sta     sreg
	ldx     _FatFs_database+1
	lda     _FatFs_database
	jsr     tossubeax
	jsr     pusheax
	ldy     #$0F
	jsr     ldeaxysp
	jsr     tosaddeax
	jsr     pusheax
	ldx     #$00
	lda     _FatFs_sects_clust
	jsr     tosudiv0ax
	ldy     #$02
	jsr     inceaxy
	sta     _FatFs_max_clust
	stx     _FatFs_max_clust+1
	ldy     sreg
	sty     _FatFs_max_clust+2
	ldy     sreg+1
	sty     _FatFs_max_clust+3
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1040
	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1041
L0632:	ldy     #$0D
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_write (__near__ struct _FIL*, __near__ const void*, unsigned short, __near__ unsigned short*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_write: near

.segment	"FILESYS"

;
; const BYTE *wbuff = buff;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1241
	ldy     #$0B
	jsr     subysp
	ldy     #$10
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
;
; *bw = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1243
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	tay
	sta     (ptr1),y
	iny
	sta     (ptr1),y
;
; if ((disk_status() & STA_NOINIT) || !FatFs_fs_type) return FR_NOT_READY;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1244
	dey
	jsr     _disk_status
	and     #$01
	bne     L07E6
	lda     _FatFs_fs_type
	bne     L07E5
L07E6:	ldx     #$00
	lda     #$01
	jmp     L07E1
;
; if (fp->flag & FA__ERROR) return FR_RW_ERROR; /* Check error flag */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1245
L07E5:	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$80
	jne     L0DA9
;
; if (!(fp->flag & FA_WRITE)) return FR_DENIED; /* Check access mode */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1246
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$02
	bne     L07ED
	tax
	lda     #$05
	jmp     L07E1
;
; if (fp->fsize + btw < fp->fsize) btw = 0;  /* File size cannot reach 4GB */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1247
L07ED:	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	jsr     pusheax
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     tosadd0ax
	jsr     pusheax
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	jsr     tosulteax
	beq     L07F1
	ldx     #$00
	txa
	ldy     #$0F
	jsr     staxysp
;
; for ( ;  btw;         /* Repeat until all data transferred */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1249
L07F1:	ldy     #$10
	lda     (sp),y
	dey
	ora     (sp),y
	jeq     L07F6
;
; if ((fp->fptr % 512) == 0) {    /* On the sector boundary */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1251
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	jsr     pusheax
	ldx     #$01
	lda     #$FF
	jsr     tosand0ax
	jsr     pusheax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	jsr     toseqeax
	jeq     L0847
;
; if (--(fp->sect_clust)) {    /* Decrement left sector counter */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1252
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1B
	lda     (ptr1),y
	sec
	sbc     #$01
	sta     (ptr1),y
	tax
	beq     L0805
;
; sect = fp->curr_sect + 1;   /* Get current sector */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1253
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxidx
	ldy     #$01
	jsr     inceaxy
	ldy     #$05
	jsr     steaxysp
;
; } else {        /* On the cluster boundary, get next cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1254
	jmp     L080A
;
; if (fp->fptr == 0) {    /* Is top of the file */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1255
L0805:	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	jsr     pusheax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	jsr     toseqeax
	beq     L080B
;
; clust = fp->org_clust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1256
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	jsr     ldeaxidx
	ldy     #$09
	jsr     steaxysp
;
; if (clust == 0)     /* No cluster is created yet */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1257
	ldy     #$0C
	jsr     ldeaxysp
	jsr     pusheax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	jsr     toseqeax
	beq     L0815
;
; fp->org_clust = clust = create_chain(0); /* Create a new cluster chain */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1258
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	txa
	jsr     push0ax
	jsr     _create_chain
	ldy     #$0B
	jsr     steaxysp
	ldy     #$08
	jsr     steaxspidx
;
; } else {       /* Middle or end of file */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1259
	jmp     L0815
;
; clust = create_chain(fp->curr_clust);   /* Trace or streach cluster chain */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1260
L080B:	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0F
	jsr     ldeaxidx
	jsr     pusheax
	jsr     _create_chain
	ldy     #$09
	jsr     steaxysp
;
; if ((clust < 2) || (clust >= FatFs_max_clust)) break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1262
L0815:	ldy     #$0C
	jsr     ldeaxysp
	cmp     #$02
	txa
	sbc     #$00
	lda     sreg
	sbc     #$00
	lda     sreg+1
	sbc     #$00
	jcc     L07F6
	ldy     #$0C
	jsr     ldeaxysp
	jsr     pusheax
	lda     _FatFs_max_clust+3
	sta     sreg+1
	lda     _FatFs_max_clust+2
	sta     sreg
	ldx     _FatFs_max_clust+1
	lda     _FatFs_max_clust
	jsr     tosugeeax
	jne     L07F6
;
; fp->curr_clust = clust;    /* Current cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1263
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0E
	jsr     ldeaxysp
	ldy     #$0C
	jsr     steaxspidx
;
; sect = clust2sect(clust);   /* Get current sector */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1264
	ldy     #$0C
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _clust2sect
	ldy     #$05
	jsr     steaxysp
;
; fp->sect_clust = FatFs_sects_clust; /* Re-initialize the left sector counter */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1265
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     _FatFs_sects_clust
	ldy     #$1B
	sta     (ptr1),y
;
; if (fp->flag & FA__DIRTY) {    /* Flush file I/O buffer if needed */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1267
L080A:	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$40
	beq     L0825
;
; if (disk_write(fp->buffer, fp->curr_sect, 1) != RES_OK) goto fw_error;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1268
	jsr     decsp7
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L082A
	inx
L082A:	ldy     #$05
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$1B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$13
	jsr     ldeaxidx
	ldy     #$01
	jsr     steaxysp
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _disk_write
	cmp     #$00
	jne     L082D
;
; fp->flag &= ~FA__DIRTY;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1269
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$BF
	sta     (ptr1),y
;
; fp->curr_sect = sect;     /* Update current sector */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1271
L0825:	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0A
	jsr     ldeaxysp
	ldy     #$10
	jsr     steaxspidx
;
; cc = btw / 512;       /* When left bytes >= 512, */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1272
	ldy     #$10
	lda     (sp),y
	lsr     a
	ldy     #$02
	sta     (sp),y
;
; if (cc) {        /* Write maximum contiguous sectors directly */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1273
	lda     (sp),y
	jeq     L0834
;
; if (cc > fp->sect_clust) cc = fp->sect_clust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1274
	lda     (sp),y
	jsr     pusha0
	ldy     #$16
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1B
	lda     (ptr1),y
	jsr     tosicmp0
	bcc     L0836
	beq     L0836
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1B
	lda     (ptr1),y
	ldy     #$02
	sta     (sp),y
;
; if (disk_write(wbuff, sect, cc) != RES_OK) goto fw_error;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1275
L0836:	jsr     decsp7
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$05
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$0F
	jsr     ldeaxysp
	ldy     #$01
	jsr     steaxysp
	ldy     #$09
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	jsr     _disk_write
	cmp     #$00
	jne     L082D
;
; fp->sect_clust -= cc - 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1276
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	sta     ptr1
	stx     ptr1+1
	ldy     #$1B
	lda     (ptr1),y
	jsr     pusha0
	ldy     #$06
	lda     (sp),y
	sec
	sbc     #$01
	bcs     L0841
	ldx     #$FF
L0841:	jsr     tossubax
	ldy     #$1B
	jsr     staspidx
;
; fp->curr_sect += cc - 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1277
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$13
	jsr     ldeaxidx
	jsr     pusheax
	ldy     #$08
	ldx     #$00
	lda     (sp),y
	sec
	sbc     #$01
	bcs     L0844
	dex
L0844:	jsr     tosadd0ax
	ldy     #$10
	jsr     steaxspidx
;
; wcnt = cc * 512; continue;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1278
	ldy     #$02
	lda     (sp),y
	sta     tmp1
	lda     #$00
	asl     a
	rol     tmp1
	ldx     tmp1
	iny
	jsr     staxysp
	jmp     L07F7
;
; if ((fp->fptr < fp->fsize) &&     /* Fill sector buffer with file data if needed */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1280
L0834:	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	jsr     pusheax
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	jsr     tosulteax
	beq     L0847
;
; (disk_read(fp->buffer, sect, 1) != RES_OK))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1281
	jsr     decsp7
	ldy     #$1B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L084D
	inx
L084D:	ldy     #$05
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$0F
	jsr     ldeaxysp
	ldy     #$01
	jsr     steaxysp
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _disk_read
	cmp     #$00
	jne     L082D
;
; wcnt = 512 - ((WORD)fp->fptr % 512);  /* Copy fractional bytes to file I/O buffer */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1284
L0847:	ldx     #$02
	lda     #$00
	jsr     pushax
	ldy     #$16
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	tay
	txa
	and     #$01
	tax
	tya
	jsr     tossubax
	ldy     #$03
	jsr     staxysp
;
; if (wcnt > btw) wcnt = btw;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1285
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sec
	ldy     #$0F
	sbc     (sp),y
	sta     tmp1
	txa
	iny
	sbc     (sp),y
	ora     tmp1
	bcc     L0854
	beq     L0854
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$03
	jsr     staxysp
;
; memcpy(&fp->buffer[fp->fptr % 512], wbuff, wcnt);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1286
L0854:	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L085A
	inx
L085A:	jsr     pushax
	ldy     #$16
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	jsr     pusheax
	ldx     #$01
	lda     #$FF
	jsr     tosand0ax
	jsr     tosaddax
	jsr     pushax
	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     _memcpy
;
; fp->flag |= FA__DIRTY;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1287
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	ora     #$40
	sta     (ptr1),y
;
; wbuff += wcnt, fp->fptr += wcnt, *bw += wcnt, btw -= wcnt) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1250
L07F7:	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     addeq0sp
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	jsr     ldeaxi
	jsr     pusheax
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     tosadd0ax
	ldy     #$00
	jsr     steaxspidx
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	stx     sreg+1
	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     ptr1
	pha
	txa
	adc     ptr1+1
	tax
	pla
	ldy     #$00
	sta     (sreg),y
	iny
	txa
	sta     (sreg),y
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0F
	jsr     subeqysp
	jmp     L07F1
;
; if (fp->fptr > fp->fsize) fp->fsize = fp->fptr; /* Update file size if needed */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1290
L07F6:	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	jsr     pusheax
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	jsr     tosugteax
	beq     L0860
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$16
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	ldy     #$04
	jsr     steaxspidx
;
; fp->flag |= FA__WRITTEN;      /* Set file changed flag */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1291
L0860:	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	ora     #$20
	sta     (ptr1),y
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1292
	ldx     #$00
	txa
	jmp     L07E1
;
; fp->flag |= FA__ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1295
L082D:	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	ora     #$80
	sta     (ptr1),y
;
; return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1296
L0DA9:	ldx     #$00
	lda     #$07
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1297
L07E1:	ldy     #$15
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_sync (__near__ struct _FIL*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_sync: near

.segment	"FILESYS"

;
; if ((disk_status() & STA_NOINIT) || !FatFs_fs_type)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1363
	jsr     decsp2
	ldy     #$00
	jsr     _disk_status
	and     #$01
	bne     L08B2
	lda     _FatFs_fs_type
	bne     L08B1
;
; return FR_INCORRECT_DISK_CHANGE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1364
L08B2:	ldx     #$00
	lda     #$08
	jmp     incsp4
;
; if (fp->flag & FA__WRITTEN) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1367
L08B1:	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$20
	jeq     L08E7
;
; if (fp->flag & FA__DIRTY) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1369
	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$40
	beq     L08B8
;
; if (disk_write(fp->buffer, fp->curr_sect, 1) != RES_OK) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1370
	jsr     decsp7
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L08BD
	inx
L08BD:	ldy     #$05
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$13
	jsr     ldeaxidx
	ldy     #$01
	jsr     steaxysp
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _disk_write
	cmp     #$00
	beq     L08BA
	ldx     #$00
	lda     #$07
	jmp     incsp4
;
; fp->flag &= ~FA__DIRTY;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1371
L08BA:	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$BF
	sta     (ptr1),y
;
; if(fp->dir_ptr) { /* should we update the directory? not for some files */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1373
L08B8:	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$18
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	iny
	ora     (ptr1),y
	jeq     L08E7
;
; if (!move_window(fp->dir_sect)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1376
	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$17
	jsr     ldeaxidx
	jsr     pusheax
	jsr     _move_window
	tax
	bne     L08C5
	lda     #$07
	jmp     incsp4
;
; ptr = fp->dir_ptr;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1377
L08C5:	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$19
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     stax0sp
;
; *(ptr+11) |= AM_ARC;     /* Set archive bit */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1378
	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0B
	bcc     L08CD
	inx
L08CD:	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	ora     #$20
	sta     (ptr1),y
;
; ST_DWORD(ptr+28, fp->fsize);   /* Update file size */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1379
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L08D1
	inx
L08D1:	jsr     pushax
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	ldy     #$00
	jsr     steaxspidx
;
; ST_WORD(ptr+26, fp->org_clust);   /* Update start cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1380
	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L08D6
	inx
L08D6:	sta     sreg
	stx     sreg+1
	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$09
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	ldy     #$00
	sta     (sreg),y
	iny
	txa
	sta     (sreg),y
;
; ST_WORD(ptr+20, fp->org_clust >> 16);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1381
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L08DB
	inx
L08DB:	jsr     pushax
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	jsr     ldeaxidx
	ldy     #$00
	ldx     sreg+1
	lda     sreg
	jsr     staxspidx
;
; ST_DWORD(ptr+22, get_fattime());  /* Updated time */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1382
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$16
	bcc     L08E0
	inx
L08E0:	jsr     pushax
	jsr     _get_fattime
	ldy     #$00
	jsr     steaxspidx
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1383
	lda     #$01
	sta     _FatFs_winflag
;
; fp->flag &= ~FA__WRITTEN;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1384
	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1A
	lda     (ptr1),y
	and     #$DF
	sta     (ptr1),y
;
; if (!move_window(0)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1385
	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	bne     L08E7
	lda     #$07
	jmp     incsp4
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1389
L08E7:	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1390
	jmp     incsp4
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_unlink (__near__ const signed char*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_unlink: near

.segment	"FILESYS"

;
; if ((res = check_mounted()) != FR_OK) return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1598
	ldy     #$27
	jsr     subysp
	jsr     _check_mounted
	ldy     #$26
	sta     (sp),y
	cmp     #$00
	beq     L09D2
	ldx     #$00
	lda     (sp),y
	jmp     L09D0
;
; if (disk_status() & STA_PROTECT) return FR_WRITE_PROTECTED;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1599
L09D2:	tay
	jsr     _disk_status
	and     #$04
	beq     L09D7
	ldx     #$00
	lda     #$09
	jmp     L09D0
;
; res = trace_path(&dirscan, fn, path, &dir); /* Trace the file path */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1601
L09D7:	jsr     decsp8
	lda     sp
	ldx     sp+1
	clc
	adc     #$14
	bcc     L09DD
	inx
L09DD:	ldy     #$06
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$08
	bcc     L09DF
	inx
L09DF:	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$30
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$2C
	bcc     L09E2
	inx
L09E2:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _trace_path
	ldy     #$26
	sta     (sp),y
;
; if (res != FR_OK) return res;    /* Trace failed */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1603
	lda     (sp),y
	beq     L09E3
	ldx     #$00
	lda     (sp),y
	jmp     L09D0
;
; if (dir == NULL) return FR_NO_FILE;   /* It is a root directory */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1604
L09E3:	dey
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cpx     #$00
	bne     L09E6
	cmp     #$00
	bne     L09E6
	lda     #$02
	jmp     L09D0
;
; if (*(dir+11) & AM_RDO) return FR_DENIED; /* It is a R/O item */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1605
L09E6:	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$01
	beq     L09EA
	ldx     #$00
	lda     #$05
	jmp     L09D0
;
; dsect = FatFs_winsect;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1606
L09EA:	lda     _FatFs_winsect+3
	sta     sreg+1
	lda     _FatFs_winsect+2
	sta     sreg
	ldx     _FatFs_winsect+1
	lda     _FatFs_winsect
	ldy     #$1A
	jsr     steaxysp
;
; dclust = ((DWORD)LD_WORD(dir+20) << 16) | LD_WORD(dir+26);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1607
	ldy     #$25
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L09F6
	inx
L09F6:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	sta     sreg+1
	dey
	lda     (ptr1),y
	sta     sreg
	tya
	tax
	jsr     pusheax
	ldy     #$29
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L09F9
	inx
L09F9:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     tosor0ax
	ldy     #$1E
	jsr     steaxysp
;
; if (*(dir+11) & AM_DIR) {     /* It is a sub-directory */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1609
	ldy     #$25
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$10
	jeq     L0A06
;
; dirscan.clust = dclust;     /* Check if the sub-dir is empty or not */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1610
	ldy     #$21
	jsr     ldeaxysp
	ldy     #$10
	jsr     steaxysp
;
; dirscan.sect = clust2sect(dclust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1611
	ldy     #$21
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _clust2sect
	ldy     #$14
	jsr     steaxysp
;
; dirscan.index = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1612
	ldx     #$00
	txa
	ldy     #$18
	jsr     staxysp
;
; if (!move_window(dirscan.sect)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1614
L0A05:	ldy     #$17
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _move_window
	tax
	bne     L0A08
	lda     #$07
	jmp     L09D0
;
; sdir = &(FatFs_win[(dirscan.index & 15) * 32]);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1615
L0A08:	ldy     #$18
	lda     (sp),y
	ldx     #$00
	and     #$0F
	jsr     shlax4
	stx     tmp1
	asl     a
	rol     tmp1
	clc
	adc     #<(_FatFs_win)
	tay
	lda     tmp1
	adc     #>(_FatFs_win)
	tax
	tya
	ldy     #$22
	jsr     staxysp
;
; if (*sdir == 0) break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1616
	ldy     #$23
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	beq     L0A06
;
; if (!((*sdir == 0xE5) || (*sdir == '.')) && !(*(sdir+11) & AM_VOL))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1617
	ldy     #$23
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	cmp     #$E5
	beq     L0A15
	ldy     #$23
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	cmp     #$2E
	beq     L0A15
	tya
	jmp     L0A18
L0A15:	lda     #$01
L0A18:	jsr     bnega
	beq     L0A13
	ldy     #$23
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$08
	bne     L0A13
;
; return FR_DENIED; /* The directory is not empty */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1618
	tax
	lda     #$05
	jmp     L09D0
;
; } while (next_dir_entry(&dirscan));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1619
L0A13:	lda     sp
	ldx     sp+1
	clc
	adc     #$0C
	bcc     L0A21
	inx
L0A21:	jsr     pushax
	jsr     _next_dir_entry
	tax
	jne     L0A05
;
; if (!move_window(dsect)) return FR_RW_ERROR; /* Mark the directory entry 'deleted' */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1622
L0A06:	ldy     #$1D
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _move_window
	tax
	bne     L0A22
	lda     #$07
	jmp     L09D0
;
; *dir = 0xE5; 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1623
L0A22:	ldy     #$25
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$E5
	ldy     #$00
	sta     (ptr1),y
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1624
	lda     #$01
	sta     _FatFs_winflag
;
; if (!remove_chain(dclust)) return FR_RW_ERROR; /* Remove the cluster chain */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1625
	ldy     #$21
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _remove_chain
	tax
	bne     L0A2A
	lda     #$07
	jmp     L09D0
;
; if (!move_window(0)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1626
L0A2A:	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	bne     L0A2E
	lda     #$07
	jmp     L09D0
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1628
L0A2E:	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1629
L09D0:	ldy     #$29
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_mkdir (__near__ const signed char*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_mkdir: near

.segment	"FILESYS"

;
; if ((res = check_mounted()) != FR_OK) return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1687
	ldy     #$25
	jsr     subysp
	jsr     _check_mounted
	ldy     #$24
	sta     (sp),y
	cmp     #$00
	beq     L0A9A
	ldx     #$00
	lda     (sp),y
	jmp     L0A98
;
; if (disk_status() & STA_PROTECT) return FR_WRITE_PROTECTED;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1688
L0A9A:	tay
	jsr     _disk_status
	and     #$04
	beq     L0A9F
	ldx     #$00
	lda     #$09
	jmp     L0A98
;
; res = trace_path(&dirscan, fn, path, &dir); /* Trace the file path */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1690
L0A9F:	jsr     decsp8
	lda     sp
	ldx     sp+1
	clc
	adc     #$1C
	bcc     L0AA5
	inx
L0AA5:	ldy     #$06
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$08
	bcc     L0AA7
	inx
L0AA7:	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$2E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$2A
	bcc     L0AAA
	inx
L0AAA:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _trace_path
	ldy     #$24
	sta     (sp),y
;
; if (res == FR_OK) return FR_DENIED;  /* Any file or directory is already existing */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1692
	lda     (sp),y
	bne     L0AAB
	tax
	lda     #$05
	jmp     L0A98
;
; if (res != FR_NO_FILE) return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1693
L0AAB:	lda     (sp),y
	cmp     #$02
	beq     L0AAE
	ldx     #$00
	lda     (sp),y
	jmp     L0A98
;
; dir = reserve_direntry(&dirscan, 0);  /* Reserve a directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1695
L0AAE:	jsr     decsp4
	lda     sp
	ldx     sp+1
	clc
	adc     #$18
	bcc     L0AB4
	inx
L0AB4:	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #$00
	tay
	sta     (sp),y
	iny
	sta     (sp),y
	jsr     _reserve_direntry
	ldy     #$22
	jsr     staxysp
;
; if (dir == NULL) return FR_DENIED;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1696
	ldy     #$23
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cpx     #$00
	bne     L0AB6
	cmp     #$00
	bne     L0AB6
	lda     #$05
	jmp     L0A98
;
; res = init_dir(dirscan.sclust, &dclust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1698
L0AB6:	jsr     decsp6
	ldy     #$1D
	jsr     ldeaxysp
	ldy     #$02
	jsr     steaxysp
	lda     sp
	ldx     sp+1
	clc
	adc     #$16
	bcc     L0ABE
	inx
L0ABE:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _init_dir
	ldy     #$24
	sta     (sp),y
;
; if (res != FR_OK)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1699
	lda     (sp),y
	beq     L0ABF
;
; return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1700
	ldx     #$00
	lda     (sp),y
	jmp     L0A98
;
; tim = get_fattime();
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1702
L0ABF:	jsr     _get_fattime
	ldy     #$0C
	jsr     steaxysp
;
; memcpy(dir, fn, 8+3);   /* Initialize the new entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1703
	ldy     #$23
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	lda     sp
	ldx     sp+1
	clc
	adc     #$02
	bcc     L0AC7
	inx
L0AC7:	jsr     pushax
	ldx     #$00
	lda     #$0B
	jsr     _memcpy
;
; *(dir+11) = AM_DIR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1704
	ldy     #$23
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0B
	bcc     L0ACB
	inx
L0ACB:	sta     ptr1
	stx     ptr1+1
	lda     #$10
	ldy     #$00
	sta     (ptr1),y
;
; *(dir+12) = fn[11];
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1705
	ldy     #$23
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0C
	bcc     L0ACF
	inx
L0ACF:	sta     ptr1
	stx     ptr1+1
	ldy     #$0B
	lda     (sp),y
	ldy     #$00
	sta     (ptr1),y
;
; memset(dir+13, 0, 32-13);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1706
	ldy     #$23
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0D
	bcc     L0AD5
	inx
L0AD5:	sta     sreg
	stx     sreg+1
	lda     #$00
	ldy     #$12
L0DAA:	sta     (sreg),y
	dey
	bpl     L0DAA
;
; ST_DWORD(dir+22, tim);   /* Crated time */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1707
	ldy     #$23
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$16
	bcc     L0ADA
	inx
L0ADA:	jsr     pushax
	ldy     #$11
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
;
; ST_WORD(dir+26, dclust);  /* Table start cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1708
	ldy     #$23
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L0ADF
	inx
L0ADF:	sta     ptr1
	stx     ptr1+1
	ldy     #$11
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (ptr1),y
	iny
	txa
	sta     (ptr1),y
;
; ST_WORD(dir+20, dclust >> 16);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1709
	ldy     #$23
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L0AE4
	inx
L0AE4:	jsr     pushax
	ldy     #$15
	jsr     ldeaxysp
	ldy     #$00
	ldx     sreg+1
	lda     sreg
	jsr     staxspidx
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1710
	lda     #$01
	sta     _FatFs_winflag
;
; if (!move_window(0)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1712
	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	bne     L0AE9
	lda     #$07
	jmp     L0A98
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1714
L0AE9:	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1715
L0A98:	ldy     #$27
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_chmod (__near__ const signed char*, unsigned char, unsigned char)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_chmod: near

.segment	"FILESYS"

;
; if ((res = check_mounted()) != FR_OK) return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1731
	ldy     #$1D
	jsr     subysp
	jsr     _check_mounted
	ldy     #$1C
	sta     (sp),y
	cmp     #$00
	jne     L0DAD
;
; if (disk_status() & STA_PROTECT) return FR_WRITE_PROTECTED;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1732
	tay
	jsr     _disk_status
	and     #$04
	beq     L0AF5
	ldx     #$00
	lda     #$09
	jmp     L0AEE
;
; res = trace_path(&dirscan, fn, path, &dir); /* Trace the file path */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1734
L0AF5:	jsr     decsp8
	lda     sp
	ldx     sp+1
	clc
	adc     #$14
	bcc     L0AFB
	inx
L0AFB:	ldy     #$06
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$08
	bcc     L0AFD
	inx
L0AFD:	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$28
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$22
	bcc     L0B00
	inx
L0B00:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _trace_path
	ldy     #$1C
	sta     (sp),y
;
; if (res == FR_OK) {   /* Trace completed */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1736
	lda     (sp),y
	bne     L0B15
;
; if (dir == NULL) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1737
	dey
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cpx     #$00
	bne     L0B03
	cmp     #$00
	bne     L0B03
;
; res = FR_NO_FILE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1738
	lda     #$02
;
; } else {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1739
	jmp     L0DAE
;
; mask &= AM_RDO|AM_HID|AM_SYS|AM_ARC; /* Valid attribute mask */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1740
L0B03:	ldy     #$1D
	lda     (sp),y
	and     #$27
	sta     (sp),y
;
; *(dir+11) = (value & mask) | (*(dir+11) & ~mask); /* Apply attribute change */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1741
	ldy     #$1B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0B
	bcc     L0B0D
	inx
L0B0D:	jsr     pushax
	ldy     #$1F
	lda     (sp),y
	iny
	and     (sp),y
	jsr     pusha0
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	jsr     pusha0
	ldy     #$23
	lda     (sp),y
	jsr     complax
	jsr     tosandax
	jsr     tosorax
	ldy     #$00
	jsr     staspidx
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1742
	lda     #$01
	sta     _FatFs_winflag
;
; if (!move_window(0)) res = FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1743
	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	bne     L0B15
	lda     #$07
L0DAE:	ldy     #$1C
	sta     (sp),y
;
; return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1746
L0B15:	ldy     #$1C
L0DAD:	ldx     #$00
	lda     (sp),y
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1747
L0AEE:	ldy     #$21
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_rename (__near__ const signed char*, __near__ const signed char*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_rename: near

.segment	"FILESYS"

;
; if ((res = check_mounted()) != FR_OK) return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1765
	ldy     #$38
	jsr     subysp
	jsr     _check_mounted
	ldy     #$37
	sta     (sp),y
	cmp     #$00
	beq     L0B1E
	ldx     #$00
	lda     (sp),y
	jmp     L0B1B
;
; if (disk_status() & STA_PROTECT) return FR_WRITE_PROTECTED;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1766
L0B1E:	tay
	jsr     _disk_status
	and     #$04
	beq     L0B23
	ldx     #$00
	lda     #$09
	jmp     L0B1B
;
; res = trace_path(&dirscan, fn, path_old, &dir_old); /* Check old object */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1768
L0B23:	jsr     decsp8
	lda     sp
	ldx     sp+1
	clc
	adc     #$14
	bcc     L0B29
	inx
L0B29:	ldy     #$06
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$08
	bcc     L0B2B
	inx
L0B2B:	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$43
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$39
	bcc     L0B2E
	inx
L0B2E:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _trace_path
	ldy     #$37
	sta     (sp),y
;
; if (res != FR_OK) return res;   /* The old object is not found */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1769
	lda     (sp),y
	beq     L0B2F
	ldx     #$00
	lda     (sp),y
	jmp     L0B1B
;
; if (!dir_old) return FR_NO_FILE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1770
L0B2F:	ldy     #$32
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     bnegax
	beq     L0B32
	ldx     #$00
	lda     #$02
	jmp     L0B1B
;
; sect_old = FatFs_winsect;     /* Save the object information */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1771
L0B32:	lda     _FatFs_winsect+3
	sta     sreg+1
	lda     _FatFs_winsect+2
	sta     sreg
	ldx     _FatFs_winsect+1
	lda     _FatFs_winsect
	ldy     #$33
	jsr     steaxysp
;
; memcpy(direntry, dir_old+11, 32-11);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1772
	lda     sp
	ldx     sp+1
	clc
	adc     #$1A
	bcc     L0B39
	inx
L0B39:	jsr     pushax
	ldy     #$34
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0B
	bcc     L0B3B
	inx
L0B3B:	jsr     pushax
	ldx     #$00
	lda     #$15
	jsr     _memcpy
;
; res = trace_path(&dirscan, fn, path_new, &dir_new); /* Check new object */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1774
	jsr     decsp8
	lda     sp
	ldx     sp+1
	clc
	adc     #$14
	bcc     L0B40
	inx
L0B40:	ldy     #$06
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$08
	bcc     L0B42
	inx
L0B42:	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$41
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$37
	bcc     L0B45
	inx
L0B45:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _trace_path
	ldy     #$37
	sta     (sp),y
;
; if (res == FR_OK) return FR_DENIED;  /* The new object name is already existing */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1775
	lda     (sp),y
	bne     L0B46
	tax
	lda     #$05
	jmp     L0B1B
;
; if (res != FR_NO_FILE) return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1776
L0B46:	lda     (sp),y
	cmp     #$02
	beq     L0B49
	ldx     #$00
	lda     (sp),y
	jmp     L0B1B
;
; dir_new = reserve_direntry(&dirscan, 0); /* Reserve a directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1778
L0B49:	jsr     decsp4
	lda     sp
	ldx     sp+1
	clc
	adc     #$10
	bcc     L0B4F
	inx
L0B4F:	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #$00
	tay
	sta     (sp),y
	iny
	sta     (sp),y
	jsr     _reserve_direntry
	ldy     #$2F
	jsr     staxysp
;
; if (dir_new == NULL) return FR_DENIED;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1779
	ldy     #$30
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cpx     #$00
	bne     L0B51
	cmp     #$00
	bne     L0B51
	lda     #$05
	jmp     L0B1B
;
; memcpy(dir_new+11, direntry, 32-11); /* Create new entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1780
L0B51:	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0B
	bcc     L0B57
	inx
L0B57:	jsr     pushax
	lda     sp
	ldx     sp+1
	clc
	adc     #$1C
	bcc     L0B59
	inx
L0B59:	jsr     pushax
	ldx     #$00
	lda     #$15
	jsr     _memcpy
;
; memcpy(dir_new, fn, 8+3);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1781
	ldy     #$30
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	lda     sp
	ldx     sp+1
	clc
	adc     #$02
	bcc     L0B5E
	inx
L0B5E:	jsr     pushax
	ldx     #$00
	lda     #$0B
	jsr     _memcpy
;
; *(dir_new+12) = fn[11];
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1782
	ldy     #$30
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0C
	bcc     L0B62
	inx
L0B62:	sta     ptr1
	stx     ptr1+1
	ldy     #$0B
	lda     (sp),y
	ldy     #$00
	sta     (ptr1),y
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1783
	lda     #$01
	sta     _FatFs_winflag
;
; if (!move_window(sect_old)) return FR_RW_ERROR; /* Remove old entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1785
	ldy     #$36
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _move_window
	tax
	bne     L0B68
	lda     #$07
	jmp     L0B1B
;
; *dir_old = 0xE5;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1786
L0B68:	ldy     #$32
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$E5
	ldy     #$00
	sta     (ptr1),y
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1787
	lda     #$01
	sta     _FatFs_winflag
;
; if (!move_window(0)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1788
	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	bne     L0B70
	lda     #$07
	jmp     L0B1B
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1790
L0B70:	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1791
L0B1B:	ldy     #$3C
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_create_file_entry (__near__ struct _FIL*, __near__ struct _DIR*, __near__ signed char*, unsigned long, unsigned char, unsigned char)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_create_file_entry: near

.segment	"BSS"

L0C7D:
	.res	14,$00
L0C7E:
	.res	4,$00
L0C7F:
	.res	4,$00
L0C80:
	.res	4,$00
L0C81:
	.res	2,$00

.segment	"FILESYS"

;
; memcpy(&dummy_scan, scan, sizeof(dummy_scan));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2060
	jsr     decsp7
	lda     #<(L0C7D)
	ldx     #>(L0C7D)
	jsr     pushax
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	lda     #$0E
	jsr     _memcpy
;
; res = find_lfn(&dummy_scan, name_str, &firstscan, &lastscan);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2061
	jsr     decsp8
	lda     #<(L0C7D)
	ldy     #$06
	sta     (sp),y
	iny
	lda     #>(L0C7D)
	sta     (sp),y
	ldy     #$16
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #<(_firstscan)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_firstscan)
	sta     (sp),y
	lda     #<(_lastscan)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(_lastscan)
	sta     (sp),y
	jsr     _find_lfn
	ldy     #$04
	sta     (sp),y
;
; if(res == FR_OK) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2070
	lda     (sp),y
	jne     L0CAA
;
; if((!replace)&&(!append)) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2071
	ldy     #$08
	lda     (sp),y
	bne     L0C8F
	dey
	lda     (sp),y
	bne     L0C8F
;
; return FR_EXISTS;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2072
	tax
	lda     #$0C
	jmp     L0C7C
;
; else if(replace) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2074
L0C8F:	ldy     #$08
	lda     (sp),y
	beq     L0C97
;
; printf("replace!\n");
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2075
	lda     #<(L0001+19)
	ldx     #>(L0001+19)
	jsr     pushax
	ldy     #$02
	jsr     _printf
;
; res = f_remove_lfn(&firstscan, &lastscan, &dclust, TRUE); 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2077
	jsr     decsp7
	lda     #<(_firstscan)
	ldy     #$05
	sta     (sp),y
	iny
	lda     #>(_firstscan)
	sta     (sp),y
	lda     #<(_lastscan)
	ldy     #$03
	sta     (sp),y
	iny
	lda     #>(_lastscan)
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$07
	bcc     L0CA0
	inx
L0CA0:	ldy     #$01
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _f_remove_lfn
	ldy     #$04
	sta     (sp),y
;
; if(res != FR_OK)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2078
	lda     (sp),y
	beq     L0CA2
;
; return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2079
	ldx     #$00
	lda     (sp),y
	jmp     L0C7C
;
; if (!remove_chain(dclust))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2082
L0CA2:	jsr     ldeax0sp
	jsr     pusheax
	jsr     _remove_chain
	tax
	jne     L0CAA
;
; return FR_RW_ERROR; // Remove the cluster chain
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2083
	lda     #$07
	jmp     L0C7C
;
; } else if(append) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2084
L0C97:	dey
	lda     (sp),y
	jeq     L0CAA
;
; dir_new = &(FatFs_win[(lastscan.index & 15) * 32]); /* Pointer to the directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2086
	lda     _lastscan+12
	ldx     #$00
	and     #$0F
	jsr     shlax4
	stx     tmp1
	asl     a
	rol     tmp1
	clc
	adc     #<(_FatFs_win)
	tay
	lda     tmp1
	adc     #>(_FatFs_win)
	tax
	tya
	ldy     #$05
	jsr     staxysp
;
; fp->flag       = FA_READ | ((dir_new[11] & AM_RDO) ? 0 : FA_WRITE); 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2087
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	stx     sreg+1
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0B
	lda     (ptr1),y
	and     #$01
	beq     L0CB6
	lda     #$00
	jmp     L0CB8
L0CB6:	lda     #$02
L0CB8:	ora     #$01
	ldy     #$1A
	sta     (sreg),y
;
; fp->dir_sect   = lastscan.sect; /* Pointer to the directory entry. */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2088
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	lda     _lastscan+8+3
	sta     sreg+1
	lda     _lastscan+8+2
	sta     sreg
	ldx     _lastscan+8+1
	lda     _lastscan+8
	ldy     #$14
	jsr     steaxspidx
;
; fp->dir_ptr    = dir_new;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2089
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$18
	sta     (ptr1),y
	iny
	txa
	sta     (ptr1),y
;
; fp->org_clust  = ((DWORD)LD_WORD(dir_new+20) << 16) | LD_WORD(dir_new+26); /* File start cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2090
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L0CC3
	inx
L0CC3:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	sta     sreg+1
	dey
	lda     (ptr1),y
	sta     sreg
	tya
	tax
	jsr     pusheax
	ldy     #$0C
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L0CC6
	inx
L0CC6:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     tosor0ax
	ldy     #$08
	jsr     steaxspidx
;
; fp->fsize      = LD_DWORD(dir_new+28);  /* File size */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2091
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L0CCB
	inx
L0CCB:	jsr     ldeaxi
	ldy     #$04
	jsr     steaxspidx
;
; fp->fptr       = 0; /* File ptr */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2092
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	tay
	jsr     steaxspidx
;
; fp->sect_clust = 1; /* Sector counter */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2093
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$01
	ldy     #$1B
	sta     (ptr1),y
;
; FatFs_files++;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2097
	lda     _FatFs_files
	clc
	adc     #$01
	sta     _FatFs_files
;
; printf("append! (filesize = %ld)\n", fp->fsize);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2098
	lda     #<(L0001+29)
	ldx     #>(L0001+29)
	jsr     pushax
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	jsr     pusheax
	ldy     #$06
	jsr     _printf
;
; return f_lseek(fp, fp->fsize); // go to end of file           
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2100
	jsr     decsp6
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$18
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	jsr     steax0sp
	jsr     _banked_f_lseek
	jmp     L0C7C
;
; res = create_lfn(scan, name_str, &dir_new);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2104
L0CAA:	jsr     decsp6
	ldy     #$16
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$14
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$0B
	bcc     L0CDC
	inx
L0CDC:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _create_lfn
	ldy     #$04
	sta     (sp),y
;
; if(res != FR_OK)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2106
	lda     (sp),y
	beq     L0CDD
;
; return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2107
	ldx     #$00
	lda     (sp),y
	jmp     L0C7C
;
; start_cluster = 0L;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2109
L0CDD:	sta     L0C7E
	sta     L0C7E+1
	sta     L0C7E+2
	sta     L0C7E+3
;
; if(size) { // reserve space in advance
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2111
	ldy     #$0C
	jsr     ldeaxysp
	jsr     utsteax
	jeq     L0CE2
;
; dir_sect = FatFs_winsect;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2112
	lda     _FatFs_winsect+3
	sta     sreg+1
	lda     _FatFs_winsect+2
	sta     sreg
	ldx     _FatFs_winsect+1
	lda     _FatFs_winsect
	sta     L0C80
	stx     L0C80+1
	ldy     sreg
	sty     L0C80+2
	ldy     sreg+1
	sty     L0C80+3
;
; num_clusters = ((size + 511) >> 9);  // number of sectors
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2114
	ldy     #$0C
	jsr     ldeaxysp
	jsr     pusheax
	ldx     #$01
	lda     #$FF
	jsr     tosadd0ax
	txa
	ldx     sreg
	ldy     sreg+1
	sty     sreg
	ldy     #$00
	sty     sreg+1
	jsr     shreax1
	sta     L0C81
	stx     L0C81+1
;
; num_clusters += FatFs_sects_clust - 1; // for rounding
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2115
	ldx     #$00
	lda     _FatFs_sects_clust
	sec
	sbc     #$01
	bcs     L0CEC
	dex
L0CEC:	clc
	adc     L0C81
	sta     L0C81
	txa
	adc     L0C81+1
	sta     L0C81+1
;
; num_clusters /= FatFs_sects_clust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2116
	lda     L0C81
	ldx     L0C81+1
	jsr     pushax
	lda     _FatFs_sects_clust
	jsr     tosudiva0
	sta     L0C81
	stx     L0C81+1
;
; printf("Number of clusters to create: %d.\n", num_clusters);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2117
	lda     #<(L0001+55)
	ldx     #>(L0001+55)
	jsr     pushax
	lda     L0C81
	ldx     L0C81+1
	jsr     pushax
	ldy     #$04
	jsr     _printf
;
; start_cluster = create_chain(0L);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2118
	ldx     #$00
	txa
	jsr     push0ax
	jsr     _create_chain
	sta     L0C7E
	stx     L0C7E+1
	ldy     sreg
	sty     L0C7E+2
	ldy     sreg+1
	sty     L0C7E+3
;
; if(!start_cluster)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2119
	lda     L0C7E+3
	sta     sreg+1
	lda     L0C7E+2
	sta     sreg
	ldx     L0C7E+1
	lda     L0C7E
	jsr     bnegeax
	beq     L0CF5
;
; return FR_DISK_FULL;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2120
	ldx     #$00
	lda     #$06
	jmp     L0C7C
;
; num_clusters--;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2121
L0CF5:	lda     L0C81
	ldx     L0C81+1
	sec
	sbc     #$01
	bcs     L0CF9
	dex
L0CF9:	sta     L0C81
	stx     L0C81+1
;
; next_cluster = start_cluster;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2122
	lda     L0C7E+3
	sta     sreg+1
	lda     L0C7E+2
	sta     sreg
	ldx     L0C7E+1
	lda     L0C7E
	sta     L0C7F
	stx     L0C7F+1
	ldy     sreg
	sty     L0C7F+2
	ldy     sreg+1
	sty     L0C7F+3
;
; while(num_clusters) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2123
L0CFC:	lda     L0C81
	ora     L0C81+1
	beq     L0CFD
;
; next_cluster = create_chain(next_cluster);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2124
	lda     L0C7F+3
	sta     sreg+1
	lda     L0C7F+2
	sta     sreg
	ldx     L0C7F+1
	lda     L0C7F
	jsr     pusheax
	jsr     _create_chain
	sta     L0C7F
	stx     L0C7F+1
	ldy     sreg
	sty     L0C7F+2
	ldy     sreg+1
	sty     L0C7F+3
;
; num_clusters--;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2125
	lda     L0C81
	ldx     L0C81+1
	sec
	sbc     #$01
	bcs     L0D03
	dex
L0D03:	sta     L0C81
	stx     L0C81+1
;
; if(!start_cluster)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2126
	lda     L0C7E+3
	sta     sreg+1
	lda     L0C7E+2
	sta     sreg
	ldx     L0C7E+1
	lda     L0C7E
	jsr     bnegeax
	beq     L0CFC
;
; return FR_DISK_FULL;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2127
	ldx     #$00
	lda     #$06
	jmp     L0C7C
;
; move_window(dir_sect);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2129
L0CFD:	lda     L0C80+3
	sta     sreg+1
	lda     L0C80+2
	sta     sreg
	ldx     L0C80+1
	lda     L0C80
	jsr     pusheax
	jsr     _move_window
;
; ST_WORD(dir_new+26, start_cluster);  /* Table start cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2132
L0CE2:	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L0D0B
	inx
L0D0B:	sta     ptr1
	stx     ptr1+1
	lda     L0C7E
	ldy     #$00
	sta     (ptr1),y
	iny
	lda     L0C7E+1
	sta     (ptr1),y
;
; ST_WORD(dir_new+20, start_cluster >> 16);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2133
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L0D10
	inx
L0D10:	sta     ptr1
	stx     ptr1+1
	lda     L0C7E+3
	sta     sreg+1
	lda     L0C7E+2
	sta     sreg
	ldy     #$00
	ldx     sreg+1
	lda     sreg
	sta     (ptr1),y
	iny
	txa
	sta     (ptr1),y
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2135
	sty     _FatFs_winflag
;
; if (!move_window(0)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2136
	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	bne     L0D15
	lda     #$07
	jmp     L0C7C
;
; fp->flag       = FA_WRITE|FA_READ;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2138
L0D15:	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	stx     sreg+1
	lda     #$03
	ldy     #$1A
	sta     (sreg),y
;
; fp->dir_sect   = FatFs_winsect;  /* Pointer to the directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2139
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	lda     _FatFs_winsect+3
	sta     sreg+1
	lda     _FatFs_winsect+2
	sta     sreg
	ldx     _FatFs_winsect+1
	lda     _FatFs_winsect
	ldy     #$14
	jsr     steaxspidx
;
; fp->dir_ptr    = dir_new;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2140
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	stx     sreg+1
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$18
	sta     (sreg),y
	iny
	txa
	sta     (sreg),y
;
; fp->org_clust  = start_cluster;     /* File start cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2141
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	lda     L0C7E+3
	sta     sreg+1
	lda     L0C7E+2
	sta     sreg
	ldx     L0C7E+1
	lda     L0C7E
	ldy     #$08
	jsr     steaxspidx
;
; fp->fsize      = size;              /* File size */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2142
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0E
	jsr     ldeaxysp
	ldy     #$04
	jsr     steaxspidx
;
; fp->fptr       = 0;        /* File ptr */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2143
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	tay
	jsr     steaxspidx
;
; fp->sect_clust = 1;     /* Sector counter */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2144
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$01
	ldy     #$1B
	sta     (ptr1),y
;
; FatFs_files++;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2146
	lda     _FatFs_files
	clc
	adc     #$01
	sta     _FatFs_files
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2148
	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2149
L0C7C:	ldy     #$13
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_create_dir_entry (__near__ struct _DIR*, __near__ signed char*, unsigned char)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_create_dir_entry: near

.segment	"BSS"

L0D2A:
	.res	14,$00

.segment	"FILESYS"

;
; memcpy(&dummy_scan, scan, sizeof(dummy_scan));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2161
	ldy     #$0B
	jsr     subysp
	lda     #<(L0D2A)
	ldx     #>(L0D2A)
	jsr     pushax
	ldy     #$11
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	lda     #$0E
	jsr     _memcpy
;
; res = find_lfn(&dummy_scan, name_str, &firstscan, &lastscan);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2163
	jsr     decsp8
	lda     #<(L0D2A)
	ldy     #$06
	sta     (sp),y
	iny
	lda     #>(L0D2A)
	sta     (sp),y
	ldy     #$15
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #<(_firstscan)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_firstscan)
	sta     (sp),y
	lda     #<(_lastscan)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(_lastscan)
	sta     (sp),y
	jsr     _find_lfn
	ldy     #$00
	sta     (sp),y
;
; if(res == FR_OK) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2164
	lda     (sp),y
	bne     L0D48
;
; if(!replace) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2165
	ldy     #$0B
	lda     (sp),y
	bne     L0D38
;
; return FR_EXISTS;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2166
	tax
	lda     #$0C
	jmp     L0D29
;
; printf("replace!\n");
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2169
L0D38:	lda     #<(L0001+90)
	ldx     #>(L0001+90)
	jsr     pushax
	ldy     #$02
	jsr     _printf
;
; res = f_remove_lfn(&firstscan, &lastscan, &dclust, TRUE);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2171
	jsr     decsp7
	lda     #<(_firstscan)
	ldy     #$05
	sta     (sp),y
	iny
	lda     #>(_firstscan)
	sta     (sp),y
	lda     #<(_lastscan)
	ldy     #$03
	sta     (sp),y
	iny
	lda     #>(_lastscan)
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$0C
	bcc     L0D43
	inx
L0D43:	ldy     #$01
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _f_remove_lfn
	ldy     #$00
	sta     (sp),y
;
; if(res != FR_OK)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2172
	lda     (sp),y
	beq     L0D45
;
; return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2173
	ldx     #$00
	lda     (sp),y
	jmp     L0D29
;
; if (!remove_chain(dclust))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2176
L0D45:	ldy     #$08
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _remove_chain
	tax
	bne     L0D48
;
; return FR_RW_ERROR; // Remove the cluster chain
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2177
	lda     #$07
	jmp     L0D29
;
; res = create_lfn(scan, name_str, &p);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2182
L0D48:	jsr     decsp6
	ldy     #$15
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$13
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$0F
	bcc     L0D51
	inx
L0D51:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _create_lfn
	ldy     #$00
	sta     (sp),y
;
; if(res != FR_OK)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2183
	lda     (sp),y
	beq     L0D52
;
; return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2184
	ldx     #$00
	lda     (sp),y
	jmp     L0D29
;
; res = init_dir(scan->sclust, &dclust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2186
L0D52:	jsr     decsp6
	ldy     #$15
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	ldy     #$02
	jsr     steaxysp
	lda     sp
	ldx     sp+1
	clc
	adc     #$0B
	bcc     L0D59
	inx
L0D59:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _init_dir
	ldy     #$00
	sta     (sp),y
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2188
	lda     #$01
	sta     _FatFs_winflag
;
; if (!move_window(0)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2189
	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	bne     L0D5C
	lda     #$07
	jmp     L0D29
;
; tim = get_fattime();
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2191
L0D5C:	jsr     _get_fattime
	ldy     #$01
	jsr     steaxysp
;
; *(p+11) = AM_DIR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2192
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0B
	bcc     L0D64
	inx
L0D64:	sta     ptr1
	stx     ptr1+1
	lda     #$10
	ldy     #$00
	sta     (ptr1),y
;
; *(p+12) = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2193
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0C
	bcc     L0D68
	inx
L0D68:	sta     ptr1
	stx     ptr1+1
	lda     #$00
	tay
	sta     (ptr1),y
;
; memset(p+13, 0, 32-13);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2194
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0D
	bcc     L0D6C
	inx
L0D6C:	sta     sreg
	stx     sreg+1
	lda     #$00
	ldy     #$12
L0DAF:	sta     (sreg),y
	dey
	bpl     L0DAF
;
; ST_DWORD(p+22, tim);  /* Crated time */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2195
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$16
	bcc     L0D71
	inx
L0D71:	jsr     pushax
	ldy     #$06
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
;
; ST_WORD(p+26, dclust);  /* Table start cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2196
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L0D76
	inx
L0D76:	sta     ptr1
	stx     ptr1+1
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (ptr1),y
	iny
	txa
	sta     (ptr1),y
;
; ST_WORD(p+20, dclust >> 16);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2197
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L0D7B
	inx
L0D7B:	jsr     pushax
	ldy     #$0A
	jsr     ldeaxysp
	ldy     #$00
	ldx     sreg+1
	lda     sreg
	jsr     staxspidx
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2198
	lda     #$01
	sta     _FatFs_winflag
;
; if (!move_window(0)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2200
	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	bne     L0D80
	lda     #$07
	jmp     L0D29
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2201
L0D80:	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2202
L0D29:	ldy     #$10
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_unlink_entry (__near__ struct _DIR*, __near__ signed char*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_unlink_entry: near

.segment	"FILESYS"

;
; if ((fres = check_mounted()) != FR_OK) return fres;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1882
	jsr     decsp5
	jsr     _check_mounted
	ldy     #$04
	sta     (sp),y
	cmp     #$00
	jne     L0DB1
;
; if (disk_status() & STA_PROTECT) return FR_WRITE_PROTECTED;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1883
	tay
	jsr     _disk_status
	and     #$04
	beq     L0BF2
	ldx     #$00
	lda     #$09
	jmp     L0BEC
;
; fres = find_lfn(scan, name, &firstscan, &lastscan); // the first parameter will be modified and thus be the last scan.
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1885
L0BF2:	jsr     decsp8
	ldy     #$10
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$06
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #<(_firstscan)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_firstscan)
	sta     (sp),y
	lda     #<(_lastscan)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(_lastscan)
	sta     (sp),y
	jsr     _find_lfn
	ldy     #$04
	sta     (sp),y
;
; if(fres == FR_OK) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1887
	lda     (sp),y
	bne     L0C06
;
; fres = f_remove_lfn(&firstscan, &lastscan, &dclust, TRUE);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1888
	jsr     decsp7
	lda     #<(_firstscan)
	iny
	sta     (sp),y
	iny
	lda     #>(_firstscan)
	sta     (sp),y
	lda     #<(_lastscan)
	ldy     #$03
	sta     (sp),y
	iny
	lda     #>(_lastscan)
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$07
	bcc     L0C02
	inx
L0C02:	ldy     #$01
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _f_remove_lfn
	ldy     #$04
	sta     (sp),y
;
; if(fres == FR_OK) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1889
	lda     (sp),y
	bne     L0C06
;
; if (!remove_chain(dclust))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1890
	jsr     ldeax0sp
	jsr     pusheax
	jsr     _remove_chain
	tax
	bne     L0C06
;
; return FR_RW_ERROR; // Remove the cluster chain
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1891
	lda     #$07
	jmp     L0BEC
;
; if (!move_window(0))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1896
L0C06:	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	bne     L0C0A
;
; return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1897
	lda     #$07
	jmp     L0BEC
;
; return fres;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1899
L0C0A:	ldy     #$04
L0DB1:	ldx     #$00
	lda     (sp),y
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1900
L0BEC:	ldy     #$09
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_unlink_direct (__near__ struct _DIR*, __near__ struct _DIRENTRY*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_unlink_direct: near

.segment	"FILESYS"

;
; if(entry->fattrib  & AM_RDO) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1910
	jsr     decsp5
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$08
	lda     (ptr1),y
	ldx     #$00
	and     #$01
	beq     L0C10
;
; return FR_DENIED; /* It is a R/O item */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1911
	lda     #$05
	jmp     L0C0F
;
; fres = find_scans_fcluster(scan, entry->fcluster, &firstscan, &lastscan);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1913
L0C10:	ldy     #$0A
	jsr     subysp
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$08
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$10
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	ldy     #$04
	jsr     steaxysp
	lda     #<(_firstscan)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_firstscan)
	sta     (sp),y
	lda     #<(_lastscan)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(_lastscan)
	sta     (sp),y
	jsr     _find_scans_fcluster
	ldy     #$04
	sta     (sp),y
;
; if(fres == FR_OK) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1914
	lda     (sp),y
	bne     L0C24
;
; fres = f_remove_lfn(&firstscan, &lastscan, &dclust, TRUE);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1915
	jsr     decsp7
	lda     #<(_firstscan)
	iny
	sta     (sp),y
	iny
	lda     #>(_firstscan)
	sta     (sp),y
	lda     #<(_lastscan)
	ldy     #$03
	sta     (sp),y
	iny
	lda     #>(_lastscan)
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$07
	bcc     L0C20
	inx
L0C20:	ldy     #$01
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _f_remove_lfn
	ldy     #$04
	sta     (sp),y
;
; if(fres == FR_OK) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1916
	lda     (sp),y
	bne     L0C24
;
; if (!remove_chain(dclust))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1917
	jsr     ldeax0sp
	jsr     pusheax
	jsr     _remove_chain
	tax
	bne     L0C24
;
; return FR_RW_ERROR; // Remove the cluster chain
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1918
	lda     #$07
	jmp     L0C0F
;
; if (!move_window(0))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1923
L0C24:	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	bne     L0C28
;
; return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1924
	lda     #$07
	jmp     L0C0F
;
; return fres;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1926
L0C28:	ldy     #$04
	ldx     #$00
	lda     (sp),y
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1927
L0C0F:	ldy     #$09
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ banked_f_rename_direct (__near__ struct _DIRENTRY*, __near__ struct _DIR*, __near__ signed char*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_banked_f_rename_direct: near

.segment	"FILESYS"

;
; res = find_lfn(scan, name, &firstscan, &lastscan);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1993
	ldy     #$12
	jsr     subysp
	jsr     decsp8
	ldy     #$1D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$06
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$1B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #<(_firstscan)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_firstscan)
	sta     (sp),y
	lda     #<(_lastscan)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(_lastscan)
	sta     (sp),y
	jsr     _find_lfn
	ldy     #$0D
	sta     (sp),y
;
; if(res == FR_OK) {     // cannot create two files with the same name in one dir
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1994
	ldx     #$00
	lda     (sp),y
	bne     L0C34
;
; return FR_EXISTS;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1995
	lda     #$0C
	jmp     L0C2D
;
; res = find_scans_fcluster(scan, entry->fcluster, &firstscan, &lastscan);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1999
L0C34:	ldy     #$0A
	jsr     subysp
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$08
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$21
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	ldy     #$04
	jsr     steaxysp
	lda     #<(_firstscan)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_firstscan)
	sta     (sp),y
	lda     #<(_lastscan)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(_lastscan)
	sta     (sp),y
	jsr     _find_scans_fcluster
	ldy     #$0D
	sta     (sp),y
;
; if(res != FR_OK) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2000
	lda     (sp),y
;
; return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2001
	jne     L0DB3
;
; dir_old = (BYTE *)&(FatFs_win[(lastscan.index & 15) * 32]);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2005
	lda     _lastscan+12
	ldx     #$00
	and     #$0F
	jsr     shlax4
	stx     tmp1
	asl     a
	rol     tmp1
	clc
	adc     #<(_FatFs_win)
	tay
	lda     tmp1
	adc     #>(_FatFs_win)
	tax
	tya
	ldy     #$10
	jsr     staxysp
;
; flags = dir_old[11];
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2008
	ldy     #$11
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0B
	lda     (ptr1),y
	iny
	sta     (sp),y
;
; clust_hi = *(WORD*)(dir_old+20);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2009
	ldy     #$11
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L0C4B
	inx
L0C4B:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	ldy     #$0A
	jsr     staxysp
;
; clust_lo = *(WORD*)(dir_old+26);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2010
	ldy     #$11
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L0C4F
	inx
L0C4F:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	ldy     #$08
	jsr     staxysp
;
; filelen  = *(DWORD*)(dir_old+28);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2011
	ldy     #$11
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L0C53
	inx
L0C53:	jsr     ldeaxi
	ldy     #$04
	jsr     steaxysp
;
; res = f_remove_lfn(&firstscan, &lastscan, &dummy, FALSE);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2014
	jsr     decsp7
	lda     #<(_firstscan)
	ldy     #$05
	sta     (sp),y
	iny
	lda     #>(_firstscan)
	sta     (sp),y
	lda     #<(_lastscan)
	ldy     #$03
	sta     (sp),y
	iny
	lda     #>(_lastscan)
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$07
	bcc     L0C59
	inx
L0C59:	ldy     #$01
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #$00
	tay
	sta     (sp),y
	jsr     _f_remove_lfn
	ldy     #$0D
	sta     (sp),y
;
; if(res == FR_OK) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2015
	lda     (sp),y
	jne     L0C77
;
; res = create_lfn(scan, name, &dir_new);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2018
	jsr     decsp6
	ldy     #$1B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$19
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$14
	bcc     L0C62
	inx
L0C62:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _create_lfn
	ldy     #$0D
	sta     (sp),y
;
; if(res == FR_OK) 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2019
	lda     (sp),y
	jne     L0C77
;
; *(dir_new+11) = flags;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2021
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0B
	bcc     L0C67
	inx
L0C67:	sta     ptr1
	stx     ptr1+1
	ldy     #$0C
	lda     (sp),y
	ldy     #$00
	sta     (ptr1),y
;
; *(WORD*)(dir_new+20) = clust_hi;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2022
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L0C6B
	inx
L0C6B:	sta     ptr1
	stx     ptr1+1
	ldy     #$0B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (ptr1),y
	iny
	txa
	sta     (ptr1),y
;
; *(WORD*)(dir_new+26) = clust_lo;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2023
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L0C6F
	inx
L0C6F:	sta     sreg
	stx     sreg+1
	ldy     #$09
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (sreg),y
	iny
	txa
	sta     (sreg),y
;
; *(DWORD*)(dir_new+28) = filelen;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2024
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L0C73
	inx
L0C73:	jsr     pushax
	ldy     #$09
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
;
; FatFs_winflag = 1;   
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2026
	lda     #$01
	sta     _FatFs_winflag
;
; if (!move_window(0))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2027
	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	bne     L0C77
;
; return FR_RW_ERROR; // Writeback
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2028
	lda     #$07
	jmp     L0C2D
;
; return res;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2031
L0C77:	ldy     #$0D
L0DB3:	ldx     #$00
	lda     (sp),y
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 2032
L0C2D:	ldy     #$18
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ move_window (unsigned long)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_move_window: near

.segment	"FILESYS"

;
; wsect = FatFs_winsect;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 95
	jsr     decsp4
	lda     _FatFs_winsect+3
	sta     sreg+1
	lda     _FatFs_winsect+2
	sta     sreg
	ldx     _FatFs_winsect+1
	lda     _FatFs_winsect
	jsr     steax0sp
;
; if (wsect != sector) { /* Changed current window */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 99
	jsr     ldeax0sp
	jsr     pusheax
	ldy     #$0B
	jsr     ldeaxysp
	jsr     tosneeax
	jeq     L000A
;
; if (FatFs_winflag) { /* Write back dirty window if needed */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 102
	jsr     decsp1
	lda     _FatFs_winflag
	jeq     L001A
;
; if (disk_write(FatFs_win, wsect, 1) != RES_OK) return FALSE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 103
	jsr     decsp7
	lda     #<(_FatFs_win)
	ldy     #$05
	sta     (sp),y
	iny
	lda     #>(_FatFs_win)
	sta     (sp),y
	ldy     #$0B
	jsr     ldeaxysp
	ldy     #$01
	jsr     steaxysp
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _disk_write
	cmp     #$00
	beq     L000E
	ldx     #$00
	txa
	jsr     incsp1
	jmp     incsp8
;
; FatFs_winflag = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 104
L000E:	sta     _FatFs_winflag
;
; if (wsect < (FatFs_fatbase + FatFs_sects_fat)) { /* In FAT area */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 105
	ldy     #$04
	jsr     ldeaxysp
	jsr     pusheax
	lda     _FatFs_fatbase+3
	sta     sreg+1
	lda     _FatFs_fatbase+2
	sta     sreg
	ldx     _FatFs_fatbase+1
	lda     _FatFs_fatbase
	jsr     pusheax
	lda     _FatFs_sects_fat+3
	sta     sreg+1
	lda     _FatFs_sects_fat+2
	sta     sreg
	ldx     _FatFs_sects_fat+1
	lda     _FatFs_sects_fat
	jsr     tosaddeax
	jsr     tosulteax
	beq     L001A
;
; for (n = FatFs_n_fats; n >= 2; n--) { /* Refrect the change to all FAT copies */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 106
	lda     _FatFs_n_fats
	ldy     #$00
L0DB4:	sta     (sp),y
	cmp     #$02
	bcc     L001A
;
; wsect += FatFs_sects_fat;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 107
	lda     _FatFs_sects_fat+3
	sta     sreg+1
	lda     _FatFs_sects_fat+2
	sta     sreg
	ldx     _FatFs_sects_fat+1
	lda     _FatFs_sects_fat
	iny
	jsr     laddeqysp
;
; if (disk_write(FatFs_win, wsect, 1) != RES_OK) break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 108
	jsr     decsp7
	lda     #<(_FatFs_win)
	ldy     #$05
	sta     (sp),y
	iny
	lda     #>(_FatFs_win)
	sta     (sp),y
	ldy     #$0B
	jsr     ldeaxysp
	ldy     #$01
	jsr     steaxysp
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _disk_write
	cmp     #$00
	bne     L001A
;
; for (n = FatFs_n_fats; n >= 2; n--) { /* Refrect the change to all FAT copies */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 106
	tay
	lda     (sp),y
	sec
	sbc     #$01
	jmp     L0DB4
;
; if (sector) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 113
L001A:	ldy     #$08
	jsr     ldeaxysp
	jsr     utsteax
	beq     L0028
;
; if (disk_read(FatFs_win, sector, 1) != RES_OK) return FALSE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 114
	jsr     decsp7
	lda     #<(_FatFs_win)
	ldy     #$05
	sta     (sp),y
	iny
	lda     #>(_FatFs_win)
	sta     (sp),y
	ldy     #$0F
	jsr     ldeaxysp
	ldy     #$01
	jsr     steaxysp
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _disk_read
	cmp     #$00
	beq     L002A
	ldx     #$00
	txa
	jsr     incsp1
	jmp     incsp8
;
; FatFs_winsect = sector;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 115
L002A:	ldy     #$08
	jsr     ldeaxysp
	sta     _FatFs_winsect
	stx     _FatFs_winsect+1
	ldy     sreg
	sty     _FatFs_winsect+2
	ldy     sreg+1
	sty     _FatFs_winsect+3
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 117
L0028:	jsr     incsp1
;
; return TRUE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 118
L000A:	ldx     #$00
	lda     #$01
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 119
	jmp     incsp8
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned long __near__ get_cluster (unsigned long)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_get_cluster: near

.segment	"FILESYS"

;
; if ((clust >= 2) && (clust < FatFs_max_clust)) {  // Valid cluster#
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 135
	jsr     decsp8
	ldy     #$0B
	jsr     ldeaxysp
	cmp     #$02
	txa
	sbc     #$00
	lda     sreg
	sbc     #$00
	lda     sreg+1
	sbc     #$00
	jcc     L003E
	ldy     #$0B
	jsr     ldeaxysp
	jsr     pusheax
	lda     _FatFs_max_clust+3
	sta     sreg+1
	lda     _FatFs_max_clust+2
	sta     sreg
	ldx     _FatFs_max_clust+1
	lda     _FatFs_max_clust
	jsr     tosulteax
	jeq     L003E
;
; fatsect = FatFs_fatbase;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 136
	lda     _FatFs_fatbase+3
	sta     sreg+1
	lda     _FatFs_fatbase+2
	sta     sreg
	ldx     _FatFs_fatbase+1
	lda     _FatFs_fatbase
	jsr     steax0sp
;
; switch (FatFs_fs_type) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 137
	lda     _FatFs_fs_type
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 154
	cmp     #$01
	beq     L0040
	cmp     #$02
	jeq     L005A
	cmp     #$03
	jeq     L0065
	jmp     L003E
;
; bc = (WORD)clust * 3 / 2;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 140
L0040:	ldy     #$09
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     mulax3
	jsr     shrax1
	ldy     #$04
	jsr     staxysp
;
; if (!move_window(fatsect + bc / 512)) break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 141
	jsr     ldeax0sp
	jsr     pusheax
	ldy     #$09
	lda     (sp),y
	ldx     #$00
	lsr     a
	jsr     tosadd0ax
	jsr     pusheax
	jsr     _move_window
	tax
	jeq     L003E
;
; wc = FatFs_win[bc % 512]; bc++;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 142
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	txa
	and     #$01
	clc
	adc     #>(_FatFs_win)
	sta     ptr1+1
	ldy     #<(_FatFs_win)
	lda     (ptr1),y
	ldx     #$00
	ldy     #$06
	jsr     staxysp
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$01
	bcc     L004A
	inx
L004A:	jsr     staxysp
;
; if (!move_window(fatsect + bc / 512)) break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 143
	jsr     ldeax0sp
	jsr     pusheax
	ldy     #$09
	lda     (sp),y
	ldx     #$00
	lsr     a
	jsr     tosadd0ax
	jsr     pusheax
	jsr     _move_window
	tax
	jeq     L003E
;
; wc |= (WORD)FatFs_win[bc % 512] << 8;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 144
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	txa
	and     #$01
	clc
	adc     #>(_FatFs_win)
	sta     ptr1+1
	ldy     #<(_FatFs_win)
	lda     (ptr1),y
	tax
	ldy     #$06
	lda     (sp),y
	pha
	txa
	iny
	ora     (sp),y
	tax
	pla
	dey
	jsr     staxysp
;
; return (clust & 1) ? (wc >> 4) : (wc & 0xFFF);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 145
	ldy     #$0B
	jsr     ldeaxysp
	ldx     #$00
	stx     sreg+1
	stx     sreg
	and     #$01
	jsr     utsteax
	beq     L0053
	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     shrax4
	jmp     L0033
L0053:	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	tay
	txa
	and     #$0F
	tax
	tya
	jmp     L0033
;
; if (!move_window(fatsect + clust / 256)) break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 148
L005A:	jsr     ldeax0sp
	jsr     pusheax
	ldy     #$0F
	jsr     ldeaxysp
	txa
	ldx     sreg
	ldy     sreg+1
	sty     sreg
	ldy     #$00
	sty     sreg+1
	jsr     tosaddeax
	jsr     pusheax
	jsr     _move_window
	tax
	beq     L003E
;
; return LD_WORD(&(FatFs_win[((WORD)clust * 2) % 512]));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 149
	ldy     #$09
	lda     (sp),y
	sta     tmp1
	dey
	lda     (sp),y
	asl     a
	rol     tmp1
	tay
	lda     tmp1
	and     #$01
	tax
	tya
	clc
	adc     #<(_FatFs_win)
	sta     ptr1
	txa
	adc     #>(_FatFs_win)
	sta     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	sty     sreg
	sty     sreg+1
	jmp     L0033
;
; if (!move_window(fatsect + clust / 128)) break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 152
L0065:	jsr     ldeax0sp
	jsr     pusheax
	ldy     #$0F
	jsr     ldeaxysp
	jsr     shreax4
	jsr     shreax3
	jsr     tosaddeax
	jsr     pusheax
	jsr     _move_window
	tax
	beq     L003E
;
; return LD_DWORD(&(FatFs_win[((WORD)clust * 4) % 512])) & 0x0FFFFFFF;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 153
	ldy     #$09
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     shlax2
	tay
	txa
	and     #$01
	tax
	tya
	clc
	adc     #<(_FatFs_win)
	tay
	txa
	adc     #>(_FatFs_win)
	tax
	tya
	jsr     ldeaxi
	jsr     pusheax
	ldx     #$FF
	stx     sreg
	lda     #$0F
	sta     sreg+1
	txa
	jsr     tosandeax
	jmp     L0033
;
; return 1; // There is no cluster information, or an error occured 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 156
L003E:	ldx     #$00
	stx     sreg
	stx     sreg+1
	lda     #$01
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 157
L0033:	ldy     #$0C
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ put_cluster (unsigned long, unsigned long)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_put_cluster: near

.segment	"FILESYS"

;
; fatsect = FatFs_fatbase;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 174
	jsr     decsp8
	lda     _FatFs_fatbase+3
	sta     sreg+1
	lda     _FatFs_fatbase+2
	sta     sreg
	ldx     _FatFs_fatbase+1
	lda     _FatFs_fatbase
	jsr     steax0sp
;
; switch (FatFs_fs_type) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 175
	lda     _FatFs_fs_type
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 201
	cmp     #$01
	beq     L0077
	cmp     #$02
	jeq     L00A3
	cmp     #$03
	jeq     L00B0
	jmp     L00BC
;
; bc = (WORD)clust * 3 / 2;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 178
L0077:	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     mulax3
	jsr     shrax1
	ldy     #$06
	jsr     staxysp
;
; if (!move_window(fatsect + bc / 512)) return FALSE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 179
	jsr     ldeax0sp
	jsr     pusheax
	ldy     #$0B
	lda     (sp),y
	ldx     #$00
	lsr     a
	jsr     tosadd0ax
	jsr     pusheax
	jsr     _move_window
	tax
	jeq     L0070
;
; p = &FatFs_win[bc % 512];
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 180
	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	tay
	txa
	and     #$01
	tax
	tya
	clc
	adc     #<(_FatFs_win)
	tay
	txa
	adc     #>(_FatFs_win)
	tax
	tya
	ldy     #$04
	jsr     staxysp
;
; *p = (clust & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 181
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$11
	jsr     ldeaxysp
	ldx     #$00
	stx     sreg+1
	stx     sreg
	and     #$01
	jsr     utsteax
	beq     L0084
	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	and     #$0F
	sta     ptr1
	ldx     #$00
	ldy     #$0A
	lda     (sp),y
	jsr     aslax4
	ora     ptr1
	jmp     L0089
L0084:	ldy     #$0A
	lda     (sp),y
L0089:	ldy     #$00
	jsr     staspidx
;
; bc++;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 182
	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$01
	bcc     L008C
	inx
L008C:	jsr     staxysp
;
; FatFs_winflag = 1; 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 183
	lda     #$01
	sta     _FatFs_winflag
;
; if (!move_window(fatsect + bc / 512)) return FALSE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 184
	jsr     ldeax0sp
	jsr     pusheax
	ldy     #$0B
	lda     (sp),y
	ldx     #$00
	lsr     a
	jsr     tosadd0ax
	jsr     pusheax
	jsr     _move_window
	tax
	jeq     L0070
;
; p = &FatFs_win[bc % 512];
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 185
	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	tay
	txa
	and     #$01
	tax
	tya
	clc
	adc     #<(_FatFs_win)
	tay
	txa
	adc     #>(_FatFs_win)
	tax
	tya
	ldy     #$04
	jsr     staxysp
;
; *p = (clust & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 186
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$11
	jsr     ldeaxysp
	ldx     #$00
	stx     sreg+1
	stx     sreg
	and     #$01
	jsr     utsteax
	beq     L0099
	ldy     #$0D
	jsr     ldeaxysp
	jsr     shreax4
	jmp     L009C
L0099:	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	and     #$F0
	jsr     pusha0
	ldy     #$0F
	jsr     ldeaxysp
	txa
	and     #$0F
	jsr     tosora0
L009C:	ldy     #$00
	jsr     staspidx
;
; break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 187
	jmp     L0075
;
; if (!move_window(fatsect + clust / 256)) return FALSE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 190
L00A3:	jsr     ldeax0sp
	jsr     pusheax
	ldy     #$13
	jsr     ldeaxysp
	txa
	ldx     sreg
	ldy     sreg+1
	sty     sreg
	ldy     #$00
	sty     sreg+1
	jsr     tosaddeax
	jsr     pusheax
	jsr     _move_window
	tax
	jeq     L0070
;
; ST_WORD(&(FatFs_win[((WORD)clust * 2) % 512]), (WORD)val);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 191
	ldy     #$0D
	lda     (sp),y
	sta     tmp1
	dey
	lda     (sp),y
	asl     a
	rol     tmp1
	tay
	lda     tmp1
	and     #$01
	tax
	tya
	clc
	adc     #<(_FatFs_win)
	sta     ptr1
	txa
	adc     #>(_FatFs_win)
	sta     ptr1+1
	ldy     #$09
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (ptr1),y
	iny
	txa
	sta     (ptr1),y
;
; break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 192
	jmp     L0075
;
; if (!move_window(fatsect + clust / 128)) return FALSE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 195
L00B0:	jsr     ldeax0sp
	jsr     pusheax
	ldy     #$13
	jsr     ldeaxysp
	jsr     shreax4
	jsr     shreax3
	jsr     tosaddeax
	jsr     pusheax
	jsr     _move_window
	tax
	beq     L0070
;
; ST_DWORD(&(FatFs_win[((WORD)clust * 4) % 512]), val);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 196
	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     shlax2
	tay
	txa
	and     #$01
	tax
	tya
	clc
	adc     #<(_FatFs_win)
	tay
	txa
	adc     #>(_FatFs_win)
	tax
	tya
	jsr     pushax
	ldy     #$0D
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
;
; break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 197
	jmp     L0075
;
; return FALSE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 200
L00BC:	ldx     #$00
	txa
	jmp     L0070
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 202
L0075:	lda     #$01
	sta     _FatFs_winflag
;
; return TRUE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 203
	ldx     #$00
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 204
L0070:	ldy     #$10
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ remove_chain (unsigned long)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_remove_chain: near

.segment	"FILESYS"

;
; if (clust) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 220
	jsr     decsp4
	ldy     #$07
	jsr     ldeaxysp
	jsr     utsteax
	beq     L00C5
;
; while ((nxt = get_cluster(clust)) >= 2) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 221
L00C4:	ldy     #$07
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _get_cluster
	jsr     steax0sp
	cmp     #$02
	txa
	sbc     #$00
	lda     sreg
	sbc     #$00
	lda     sreg+1
	sbc     #$00
	bcc     L00C5
;
; if (!put_cluster(clust, 0)) return FALSE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 222
	jsr     decsp8
	ldy     #$0F
	jsr     ldeaxysp
	ldy     #$04
	jsr     steaxysp
	ldy     #$00
	tya
	sta     (sp),y
	iny
	sta     (sp),y
	iny
	sta     (sp),y
	iny
	sta     (sp),y
	jsr     _put_cluster
	tax
	jeq     incsp8
;
; clust = nxt;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 223
	jsr     ldeax0sp
	ldy     #$04
	jsr     steaxysp
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 224
	jmp     L00C4
;
; return TRUE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 226
L00C5:	ldx     #$00
	lda     #$01
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 227
	jmp     incsp8
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned long __near__ create_chain (unsigned long)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_create_chain: near

.segment	"FILESYS"

;
; mcl = FatFs_max_clust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 242
	ldy     #$10
	jsr     subysp
	lda     _FatFs_max_clust+3
	sta     sreg+1
	lda     _FatFs_max_clust+2
	sta     sreg
	ldx     _FatFs_max_clust+1
	lda     _FatFs_max_clust
	jsr     steax0sp
;
; if (clust == 0) {  /* Create new chain */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 243
	ldy     #$13
	jsr     ldeaxysp
	jsr     pusheax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	jsr     toseqeax
	beq     L00D5
;
; scl = FatFs_last_clust;   /* Get last allocated cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 244
	lda     _FatFs_last_clust+3
	sta     sreg+1
	lda     _FatFs_last_clust+2
	sta     sreg
	ldx     _FatFs_last_clust+1
	lda     _FatFs_last_clust
	ldy     #$04
	jsr     steaxysp
;
; if (scl < 2 || scl >= mcl) scl = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 245
	ldy     #$07
	jsr     ldeaxysp
	cmp     #$02
	txa
	sbc     #$00
	lda     sreg
	sbc     #$00
	lda     sreg+1
	sbc     #$00
	bcc     L00DA
	ldy     #$07
	jsr     ldeaxysp
	jsr     pusheax
	ldy     #$07
	jsr     ldeaxysp
	jsr     tosugeeax
	beq     L00DE
L00DA:	ldy     #$04
	lda     #$01
	sta     (sp),y
	lda     #$00
	iny
	sta     (sp),y
	iny
	sta     (sp),y
	iny
	sta     (sp),y
;
; else {     /* Stretch existing chain */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 247
	jmp     L00DE
;
; cstat = get_cluster(clust);  /* Check the cluster status */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 248
L00D5:	ldy     #$13
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _get_cluster
	ldy     #$0C
	jsr     steaxysp
;
; if (cstat < 2) return 0;  /* It is an invalid cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 249
	ldy     #$0F
	jsr     ldeaxysp
	cmp     #$02
	txa
	sbc     #$00
	lda     sreg
	sbc     #$00
	lda     sreg+1
	sbc     #$00
	bcs     L00E2
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	jmp     L00D2
;
; if (cstat < mcl) return cstat; /* It is already followed by next cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 250
L00E2:	ldy     #$0F
	jsr     ldeaxysp
	jsr     pusheax
	ldy     #$07
	jsr     ldeaxysp
	jsr     tosulteax
	beq     L00E5
	ldy     #$0F
	jmp     L0DB5
;
; scl = clust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 251
L00E5:	ldy     #$13
	jsr     ldeaxysp
	ldy     #$04
	jsr     steaxysp
;
; ncl = scl;    /* Scan start cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 253
L00DE:	ldy     #$07
	jsr     ldeaxysp
	ldy     #$08
	jsr     steaxysp
;
; ncl++;      /* Next cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 255
L00EC:	ldy     #$0B
	jsr     ldeaxysp
	jsr     saveeax
	ldy     #$01
	jsr     inceaxy
	ldy     #$08
	jsr     steaxysp
	jsr     resteax
;
; if (ncl >= mcl) {   /* Wrap around */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 256
	ldy     #$0B
	jsr     ldeaxysp
	jsr     pusheax
	ldy     #$07
	jsr     ldeaxysp
	jsr     tosugeeax
	beq     L00F4
;
; ncl = 2;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 257
	ldy     #$08
	lda     #$02
	sta     (sp),y
	lda     #$00
	iny
	sta     (sp),y
	iny
	sta     (sp),y
	iny
	sta     (sp),y
;
; if (scl == 1) return 0; /* No free cluster was found */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 258
	ldy     #$07
	jsr     ldeaxysp
	jsr     pusheax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	lda     #$01
	jsr     toseqeax
	beq     L00F4
	ldx     #$00
	txa
	jmp     L00D2
;
; if (ncl == scl) return 0; /* No free cluster was found */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 260
L00F4:	ldy     #$0B
	jsr     ldeaxysp
	jsr     pusheax
	ldy     #$0B
	jsr     ldeaxysp
	jsr     toseqeax
	beq     L00F7
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	jmp     L00D2
;
; cstat = get_cluster(ncl); /* Get the cluster status */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 261
L00F7:	ldy     #$0B
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _get_cluster
	ldy     #$0C
	jsr     steaxysp
;
; if (cstat == 1) return 0; /* Any error occured */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 262
	ldy     #$0F
	jsr     ldeaxysp
	jsr     pusheax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	lda     #$01
	jsr     toseqeax
	beq     L00FD
	ldx     #$00
	txa
	jmp     L00D2
;
; } while (cstat);    /* Repeat until find a free cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 263
L00FD:	ldy     #$0F
	jsr     ldeaxysp
	jsr     utsteax
	jne     L00EC
;
; if (!put_cluster(ncl, 0x0FFFFFFF)) return 0;  /* Mark the new cluster "in use" */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 265
	jsr     decsp8
	ldy     #$13
	jsr     ldeaxysp
	ldy     #$04
	jsr     steaxysp
	ldy     #$00
	lda     #$FF
	sta     (sp),y
	iny
	sta     (sp),y
	iny
	sta     (sp),y
	lda     #$0F
	iny
	sta     (sp),y
	jsr     _put_cluster
	tax
	bne     L0101
	sta     sreg
	sta     sreg+1
	jmp     L00D2
;
; if (clust && !put_cluster(clust, ncl)) return 0; /* Link it to previous one if needed */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 266
L0101:	ldy     #$13
	jsr     ldeaxysp
	jsr     utsteax
	beq     L0106
	jsr     decsp8
	ldy     #$1B
	jsr     ldeaxysp
	ldy     #$04
	jsr     steaxysp
	ldy     #$13
	jsr     ldeaxysp
	jsr     steax0sp
	jsr     _put_cluster
	tax
	bne     L0106
	sta     sreg
	sta     sreg+1
	jmp     L00D2
;
; FatFs_last_clust = ncl;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 267
L0106:	ldy     #$0B
	jsr     ldeaxysp
	sta     _FatFs_last_clust
	stx     _FatFs_last_clust+1
	ldy     sreg
	sty     _FatFs_last_clust+2
	ldy     sreg+1
	sty     _FatFs_last_clust+3
;
; return ncl;  /* Return new cluster number */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 269
	ldy     #$0B
L0DB5:	jsr     ldeaxysp
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 270
L00D2:	ldy     #$14
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ check_fs (unsigned long)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_check_fs: near

.segment	"DATA"

L0118:
	.byte	$46
	.byte	$41
	.byte	$54
	.byte	$31
	.byte	$32
	.byte	$46
	.byte	$41
	.byte	$54
	.byte	$31
	.byte	$36
	.byte	$46
	.byte	$41
	.byte	$54
	.byte	$33
	.byte	$32

.segment	"FILESYS"

;
; memset(FatFs_win, 0, 512);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 305
	lda     #<(_FatFs_win)
	ldx     #>(_FatFs_win)
	jsr     pushax
	ldx     #$02
	lda     #$00
	jsr     __bzero
;
; if (disk_read(FatFs_win, sect, 1) == RES_OK) { /* Load boot record */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 306
	jsr     decsp7
	lda     #<(_FatFs_win)
	ldy     #$05
	sta     (sp),y
	iny
	lda     #>(_FatFs_win)
	sta     (sp),y
	ldy     #$0A
	jsr     ldeaxysp
	ldy     #$01
	jsr     steaxysp
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _disk_read
	cmp     #$00
	jne     L014A
;
; if (LD_WORD(&(FatFs_win[510])) == 0xAA55) {  /* Is it valid? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 307
	lda     _FatFs_win+510+1
	cmp     #$AA
	jne     L014A
	lda     _FatFs_win+510
	cmp     #$55
	jne     L014A
;
; if (!memcmp(&(FatFs_win[0x36]), &fatsign[0], 5))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 310
	jsr     decsp4
	lda     #<(_FatFs_win+54)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_FatFs_win+54)
	sta     (sp),y
	lda     #<(L0118)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(L0118)
	sta     (sp),y
	ldx     #$00
	lda     #$05
	jsr     _memcmp
	stx     tmp1
	ora     tmp1
	bne     L0138
;
; return FS_FAT12;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 311
	tax
	lda     #$01
	jmp     incsp4
;
; if (!memcmp(&(FatFs_win[0x36]), &fatsign[5], 5))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 313
L0138:	jsr     decsp4
	lda     #<(_FatFs_win+54)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_FatFs_win+54)
	sta     (sp),y
	lda     #<(L0118+5)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(L0118+5)
	sta     (sp),y
	ldx     #$00
	lda     #$05
	jsr     _memcmp
	stx     tmp1
	ora     tmp1
	bne     L0141
;
; return FS_FAT16;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 314
	tax
	lda     #$02
	jmp     incsp4
;
; if (!memcmp(&(FatFs_win[0x52]), &fatsign[10], 5) && (FatFs_win[0x28] == 0))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 315
L0141:	jsr     decsp4
	lda     #<(_FatFs_win+82)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_FatFs_win+82)
	sta     (sp),y
	lda     #<(L0118+10)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(L0118+10)
	sta     (sp),y
	ldx     #$00
	lda     #$05
	jsr     _memcmp
	stx     tmp1
	ora     tmp1
	bne     L014A
	lda     _FatFs_win+40
	bne     L014A
;
; return FS_FAT32;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 316
	tax
	lda     #$03
	jmp     incsp4
;
; return 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 320
L014A:	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 321
	jmp     incsp4
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ next_dir_entry (__near__ struct _DIR*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_next_dir_entry: near

.segment	"FILESYS"

;
; idx = scan->index + 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 334
	jsr     decsp6
	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0D
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	clc
	adc     #$01
	bcc     L015B
	inx
L015B:	jsr     stax0sp
;
; if ((idx & 15) == 0) {  /* Table sector changed? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 335
	ldy     #$00
	lda     (sp),y
	and     #$0F
	jne     L0167
;
; scan->sect++;   /* Next sector */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 336
	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0B
	jsr     ldeaxidx
	jsr     saveeax
	ldy     #$01
	jsr     inceaxy
	ldy     #$08
	jsr     steaxspidx
	jsr     resteax
;
; if (!scan->clust) {  /* In static table */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 337
	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	iny
	jsr     ldeaxidx
	jsr     bnegeax
	beq     L0161
;
; if (idx >= FatFs_n_rootdir) return FALSE; /* Reached to end of table */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 338
	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cmp     _FatFs_n_rootdir
	txa
	sbc     _FatFs_n_rootdir+1
	jcc     L0167
	ldx     #$00
	txa
	jmp     incsp8
;
; if (((idx / 16) & (FatFs_sects_clust - 1)) == 0) { /* Cluster changed? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 340
L0161:	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     shrax4
	sta     ptr1
	stx     ptr1+1
	ldx     #$00
	lda     _FatFs_sects_clust
	sec
	sbc     #$01
	bcs     L016C
	dex
L016C:	and     ptr1
	pha
	txa
	and     ptr1+1
	tax
	pla
	cpx     #$00
	jne     L0167
	cmp     #$00
	jne     L0167
;
; clust = get_cluster(scan->clust);  /* Get next cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 341
	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	iny
	jsr     ldeaxidx
	jsr     pusheax
	jsr     _get_cluster
	ldy     #$02
	jsr     steaxysp
;
; if ((clust >= FatFs_max_clust) || (clust < 2)) /* Reached to end of table */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 342
	ldy     #$05
	jsr     ldeaxysp
	jsr     pusheax
	lda     _FatFs_max_clust+3
	sta     sreg+1
	lda     _FatFs_max_clust+2
	sta     sreg
	ldx     _FatFs_max_clust+1
	lda     _FatFs_max_clust
	jsr     tosugeeax
	bne     L0172
	ldy     #$05
	jsr     ldeaxysp
	cmp     #$02
	txa
	sbc     #$00
	lda     sreg
	sbc     #$00
	lda     sreg+1
	sbc     #$00
	bcs     L0171
;
; return FALSE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 343
L0172:	ldx     #$00
	txa
	jmp     incsp8
;
; scan->clust = clust;    /* Initialize for new cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 344
L0171:	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$07
	jsr     ldeaxysp
	ldy     #$04
	jsr     steaxspidx
;
; scan->sect = clust2sect(clust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 345
	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$07
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _clust2sect
	ldy     #$08
	jsr     steaxspidx
;
; scan->index = idx; /* Lower 4 bit of scan->index indicates offset in scan->sect */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 349
L0167:	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0C
	sta     (ptr1),y
	iny
	txa
	sta     (ptr1),y
;
; return TRUE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 350
	ldx     #$00
	lda     #$01
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 351
	jmp     incsp8
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ get_fileinfo (__near__ struct _FILINFO*, __near__ const unsigned char*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_get_fileinfo: near

.segment	"FILESYS"

;
; p = &(finfo->fname[0]);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 367
	jsr     decsp5
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0D
	bcc     L0185
	inx
L0185:	jsr     stax0sp
;
; a = *(dir+12); /* NT flag */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 368
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0C
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	ldy     #$02
	sta     (sp),y
;
; for (n = 0; n < 8; n++) { /* Convert file name (body) */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 369
	lda     #$00
	ldy     #$04
L0DB6:	sta     (sp),y
	cmp     #$08
	bcs     L018B
;
; c = *(dir+n);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 370
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	dey
	lda     (sp),y
	tay
	lda     (ptr1),y
	ldy     #$03
	sta     (sp),y
;
; if (c == ' ') break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 371
	cmp     #$20
	beq     L018B
;
; if (c == 0x05) c = 0xE5;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 372
	lda     (sp),y
	cmp     #$05
	bne     L0197
	lda     #$E5
	sta     (sp),y
;
; if ((a & 0x08) && (c >= 'A') && (c <= 'Z')) c += 0x20;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 373
L0197:	dey
	lda     (sp),y
	and     #$08
	beq     L019B
	iny
	lda     (sp),y
	cmp     #$41
	bcc     L019B
	lda     (sp),y
	cmp     #$5B
	bcs     L019B
	lda     #$20
	adc     (sp),y
	sta     (sp),y
;
; *p++ = c;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 374
L019B:	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     regsave
	stx     regsave+1
	clc
	adc     #$01
	bcc     L01A5
	inx
L01A5:	jsr     stax0sp
	ldy     #$03
	lda     (sp),y
	ldy     #$00
	sta     (regsave),y
;
; for (n = 0; n < 8; n++) { /* Convert file name (body) */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 369
	ldy     #$04
	lda     (sp),y
	clc
	adc     #$01
	jmp     L0DB6
;
; if (*(dir+8) != ' ') {  /* Convert file name (extension) */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 376
L018B:	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$08
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	cmp     #$20
	jeq     L01B0
;
; *p++ = '.';
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 377
	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     regsave
	stx     regsave+1
	clc
	adc     #$01
	bcc     L01AD
	inx
L01AD:	jsr     stax0sp
	lda     #$2E
	ldy     #$00
	sta     (regsave),y
;
; for (n = 8; n < 11; n++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 378
	lda     #$08
	ldy     #$04
L0DB7:	sta     (sp),y
	cmp     #$0B
	bcs     L01B0
;
; c = *(dir+n);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 379
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	dey
	lda     (sp),y
	tay
	lda     (ptr1),y
	ldy     #$03
	sta     (sp),y
;
; if (c == ' ') break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 380
	cmp     #$20
	beq     L01B0
;
; if ((a & 0x10) && (c >= 'A') && (c <= 'Z')) c += 0x20;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 381
	dey
	lda     (sp),y
	and     #$10
	beq     L01BC
	iny
	lda     (sp),y
	cmp     #$41
	bcc     L01BC
	lda     (sp),y
	cmp     #$5B
	bcs     L01BC
	lda     #$20
	adc     (sp),y
	sta     (sp),y
;
; *p++ = c;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 382
L01BC:	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     regsave
	stx     regsave+1
	clc
	adc     #$01
	bcc     L01C6
	inx
L01C6:	jsr     stax0sp
	ldy     #$03
	lda     (sp),y
	ldy     #$00
	sta     (regsave),y
;
; for (n = 8; n < 11; n++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 378
	ldy     #$04
	lda     (sp),y
	clc
	adc     #$01
	jmp     L0DB7
;
; *p = '\0';
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 385
L01B0:	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	tya
	sta     (ptr1),y
;
; finfo->fattrib  = *(dir+11);       /* Attribute */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 387
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	stx     sreg+1
	dey
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	iny
	sta     (sreg),y
;
; finfo->fcluster = ((DWORD)LD_WORD(dir+20) << 16) | LD_WORD(dir+26); /* Cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 388
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L01D4
	inx
L01D4:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	sta     sreg+1
	dey
	lda     (ptr1),y
	sta     sreg
	tya
	tax
	jsr     pusheax
	ldy     #$0C
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L01D7
	inx
L01D7:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     tosor0ax
	ldy     #$04
	jsr     steaxspidx
;
; finfo->fsize    = LD_DWORD(dir+28);         /* Size */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 389
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1C
	bcc     L01DC
	inx
L01DC:	jsr     ldeaxi
	ldy     #$00
	jsr     steaxspidx
;
; finfo->fdate    = LD_WORD(dir+24);      /* Date */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 390
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	stx     sreg+1
	dey
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$18
	bcc     L01E1
	inx
L01E1:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	ldy     #$08
	sta     (sreg),y
	iny
	txa
	sta     (sreg),y
;
; finfo->ftime    = LD_WORD(dir+22);      /* Time */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 391
	dey
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	stx     sreg+1
	dey
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$16
	bcc     L01E6
	inx
L01E6:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	ldy     #$0A
	sta     (sreg),y
	iny
	txa
	sta     (sreg),y
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 392
	ldy     #$09
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ calc_lfn_checksum (__near__ const unsigned char*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_calc_lfn_checksum: near

.segment	"BSS"

L01E8:
	.res	1,$00
L01E9:
	.res	1,$00

.segment	"FILESYS"

;
; for (i=0, sum=0; i!=11; i++)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 403
	lda     #$00
	sta     L01E9
	sta     L01E8
L01EA:	lda     L01E9
	cmp     #$0B
	beq     L01EB
;
; sum = ((sum & 1) ? 0x80 : 0) + (sum >> 1) + dir[i];
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 404
	lda     L01E8
	and     #$01
	beq     L01F8
	ldx     #$00
	lda     #$80
	jmp     L01FA
L01F8:	tax
L01FA:	sta     ptr1
	lda     L01E8
	jsr     asrax1
	clc
	adc     ptr1
	sta     sreg
	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     L01E9
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	clc
	adc     sreg
	sta     L01E8
;
; for (i=0, sum=0; i!=11; i++)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 403
	lda     L01E9
	clc
	adc     #$01
	sta     L01E9
	jmp     L01EA
;
; return sum;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 406
L01EB:	ldx     #$00
	lda     L01E8
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 407
	jmp     incsp2
	.dbg	line

.endproc

; ---------------------------------------------------------------
; signed char __near__ make_dirfile (__near__ __near__ const signed char**, __near__ signed char*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_make_dirfile: near

.segment	"FILESYS"

;
; memset(dirname, ' ', 8+3); /* Fill buffer with spaces */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 421
	jsr     decsp5
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0A
	lda     #$20
L0204:	sta     (ptr1),y
	dey
	bpl     L0204
;
; a = 0; b = 0x18; /* NT flag */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 422
	lda     #$00
	ldy     #$01
	sta     (sp),y
	lda     #$18
	dey
	sta     (sp),y
;
; n = 0; t = 8;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 423
	tya
	ldy     #$04
	sta     (sp),y
	lda     #$08
L0DC2:	dey
	sta     (sp),y
;
; c = *(*path)++;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 425
L0210:	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	stx     sreg+1
	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	sta     regsave
	stx     regsave+1
	clc
	adc     #$01
	bcc     L0214
	inx
L0214:	sta     (sreg),y
	iny
	txa
	sta     (sreg),y
	dey
	lda     (regsave),y
	ldy     #$02
	sta     (sp),y
;
; if (c <= ' ') c = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 426
	cmp     #$21
	bcs     L0215
	lda     #$00
	sta     (sp),y
;
; if ((c == 0) || (c == '/')) {   /* Reached to end of str or directory separator */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 427
L0215:	lda     (sp),y
	beq     L021A
	lda     (sp),y
	cmp     #$2F
	bne     L0219
;
; if (n == 0) break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 428
L021A:	ldy     #$04
	lda     (sp),y
	jeq     L020E
;
; dirname[11] = a & b; return c;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 429
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldx     #$00
	lda     (sp,x)
	ldy     #$01
	and     (sp),y
	ldy     #$0B
	sta     (ptr1),y
	ldy     #$02
	lda     (sp),y
	jpl     L01FF
	dex
	jmp     L01FF
;
; if (c == '.') {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 431
L0219:	lda     (sp),y
	cmp     #$2E
	bne     L0225
;
; if(!(a & 1) && (n >= 1) && (n <= 8)) { /* Enter extension part */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 432
	dey
	lda     (sp),y
	and     #$01
	jne     L020E
	ldy     #$04
	lda     (sp),y
	cmp     #$01
	jcc     L020E
	lda     (sp),y
	cmp     #$09
	jcs     L020E
;
; n = 8; t = 11; continue;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 433
	lda     #$08
	sta     (sp),y
	lda     #$0B
	jmp     L0DC2
;
; if (c >= 0x7F) goto md_l1;    /* Accept \x7F-0xFF */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 446
L0225:	lda     (sp),y
	cmp     #$7F
	jcs     L0268
;
; if (c == '"') break;     /* Reject " */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 448
	lda     (sp),y
	cmp     #$22
	jeq     L020E
;
; if (c <= ')') goto md_l1;    /* Accept ! # $ % & ' ( ) */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 449
	lda     (sp),y
	cmp     #$2A
	jcc     L0268
;
; if (c <= ',') break;     /* Reject * + , */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 450
	lda     (sp),y
	cmp     #$2D
	jcc     L020E
;
; if (c <= '9') goto md_l1;    /* Accept - 0-9 */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 451
	lda     (sp),y
	cmp     #$3A
	bcc     L0268
;
; if (c <= '?') break;     /* Reject : ; < = > ? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 452
	lda     (sp),y
	cmp     #$40
	jcc     L020E
;
; if (!(a & 1)) { /* These checks are not applied to S-JIS 2nd byte */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 453
	dey
	lda     (sp),y
	and     #$01
	bne     L0268
;
; if (c == '|') break;    /* Reject | */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 454
	iny
	lda     (sp),y
	cmp     #$7C
	jeq     L020E
;
; if ((c >= '[') && (c <= ']')) break;/* Reject [ \ ] */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 455
	lda     (sp),y
	cmp     #$5B
	bcc     L0244
	lda     (sp),y
	cmp     #$5E
	jcc     L020E
;
; if ((c >= 'A') && (c <= 'Z'))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 456
L0244:	lda     (sp),y
	cmp     #$41
	bcc     L0256
	lda     (sp),y
	cmp     #$5B
	bcs     L0256
;
; (t == 8) ? (b &= ~0x08) : (b &= ~0x10);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 457
	iny
	lda     (sp),y
	cmp     #$08
	bne     L0252
	ldy     #$00
	lda     (sp),y
	and     #$F7
	jmp     L0DC0
L0252:	ldy     #$00
	lda     (sp),y
	and     #$EF
L0DC0:	sta     (sp),y
;
; if ((c >= 'a') && (c <= 'z')) {  /* Convert to upper case */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 458
L0256:	ldy     #$02
	lda     (sp),y
	cmp     #$61
	bcc     L0268
	lda     (sp),y
	cmp     #$7B
	bcs     L0268
;
; c -= 0x20;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 459
	lda     (sp),y
	sec
	sbc     #$20
	sta     (sp),y
;
; (t == 8) ? (a |= 0x08) : (a |= 0x10);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 460
	iny
	lda     (sp),y
	cmp     #$08
	bne     L0264
	ldy     #$01
	lda     (sp),y
	ora     #$08
	jmp     L0DC1
L0264:	ldy     #$01
	lda     (sp),y
	ora     #$10
L0DC1:	sta     (sp),y
;
; a &= ~1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 464
L0268:	ldy     #$01
	lda     (sp),y
	and     #$FE
	sta     (sp),y
;
; if (n >= t) break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 468
	ldy     #$04
	lda     (sp),y
	dey
	cmp     (sp),y
	bcs     L020E
;
; dirname[n++] = c;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 469
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$06
	lda     (sp),y
	pha
	clc
	adc     #$01
	sta     (sp),y
	pla
	jsr     tosadda0
	sta     ptr1
	stx     ptr1+1
	ldy     #$02
	lda     (sp),y
	ldy     #$00
	sta     (ptr1),y
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 470
	jmp     L0210
;
; return 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 471
L020E:	ldx     #$00
	lda     #$01
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 472
L01FF:	ldy     #$09
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ trace_path (__near__ struct _DIR*, __near__ signed char*, __near__ const signed char*, __near__ __near__ unsigned char**)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_trace_path: near

.segment	"FILESYS"

;
; BYTE *dptr = NULL;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 486
	jsr     decsp5
	jsr     push0
;
; clust = FatFs_dirbase;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 489
	lda     _FatFs_dirbase+3
	sta     sreg+1
	lda     _FatFs_dirbase+2
	sta     sreg
	ldx     _FatFs_dirbase+1
	lda     _FatFs_dirbase
	ldy     #$03
	jsr     steaxysp
;
; if (FatFs_fs_type == FS_FAT32) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 490
	lda     _FatFs_fs_type
	cmp     #$03
	bne     L0279
;
; scan->clust = scan->sclust = clust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 491
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$10
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0A
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
	ldy     #$04
	jsr     steaxspidx
;
; scan->sect = clust2sect(clust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 492
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$08
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _clust2sect
;
; } else {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 493
	jmp     L0DC4
;
; scan->clust = scan->sclust = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 494
L0279:	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$10
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	tay
	jsr     steaxspidx
	ldy     #$04
	jsr     steaxspidx
;
; scan->sect = clust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 495
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$08
	jsr     ldeaxysp
L0DC4:	ldy     #$08
	jsr     steaxspidx
;
; scan->index = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 497
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	dey
	sta     (ptr1),y
	iny
	sta     (ptr1),y
;
; while ((*path == ' ') || (*path == '/')) path++; /* Skip leading spaces */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 499
L0289:	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	jsr     ldaidx
	cmp     #$20
	beq     L028B
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	jsr     ldaidx
	cmp     #$2F
	bne     L028A
L028B:	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$01
	bcc     L0290
	inx
L0290:	jsr     staxysp
	jmp     L0289
;
; if ((BYTE)*path < ' ') {       /* Null path means the root directory */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 500
L028A:	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	cmp     #$20
	bcs     L0299
;
; *dir = NULL; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 501
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	tay
	sta     (ptr1),y
	iny
	sta     (ptr1),y
	tax
	jmp     L0297
;
; ds = make_dirfile(&path, fn);   /* Get a paragraph into fn[] */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 505
L0299:	jsr     decsp4
	lda     sp
	ldx     sp+1
	clc
	adc     #$0D
	bcc     L029D
	inx
L029D:	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$10
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _make_dirfile
	ldy     #$02
	sta     (sp),y
;
; if (ds == 1) return FR_INVALID_NAME;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 506
	cmp     #$01
	bne     L02A6
	ldx     #$00
	lda     #$04
	jmp     L0297
;
; if (!move_window(scan->sect)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 508
L02A6:	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	jsr     ldeaxidx
	jsr     pusheax
	jsr     _move_window
	tax
	bne     L02A7
	lda     #$07
	jmp     L0297
;
; dptr = &(FatFs_win[(scan->index & 15) * 32]); /* Pointer to the directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 509
L02A7:	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	dey
	lda     (ptr1),y
	ldx     #$00
	and     #$0F
	jsr     shlax4
	stx     tmp1
	asl     a
	rol     tmp1
	clc
	adc     #<(_FatFs_win)
	tay
	lda     tmp1
	adc     #>(_FatFs_win)
	tax
	tya
	jsr     stax0sp
;
; if (*dptr == 0)        /* Has it reached to end of dir? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 510
	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	bne     L02B0
;
; return !ds ? FR_NO_FILE : FR_NO_PATH;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 511
	ldy     #$02
	lda     (sp),y
	bne     L02B4
	tax
	tya
	jmp     L0297
L02B4:	ldx     #$00
	lda     #$03
	jmp     L0297
;
; if (    (*dptr != 0xE5)      /* Matched? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 512
L02B0:	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	cmp     #$E5
;
; && !(*(dptr+11) & AM_VOL)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 513
	beq     L02B8
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$08
;
; && !memcmp(dptr, fn, 8+3) ) break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 514
	bne     L02B8
	jsr     decsp4
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$10
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldx     #$00
	lda     #$0B
	jsr     _memcmp
	stx     tmp1
	ora     tmp1
	beq     L02A4
;
; if (!next_dir_entry(scan))     /* Next directory pointer */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 515
L02B8:	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	jsr     _next_dir_entry
	tax
	jne     L02A6
;
; return !ds ? FR_NO_FILE : FR_NO_PATH;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 516
	ldy     #$02
	lda     (sp),y
	bne     L02C8
	tya
	jmp     L0297
L02C8:	lda     #$03
	jmp     L0297
;
; if (!ds) { *dir = dptr; return FR_OK; }   /* Matched with end of path */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 518
L02A4:	ldy     #$02
	lda     (sp),y
	bne     L02CC
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     (ptr1),y
	iny
	txa
	sta     (ptr1),y
	ldx     #$00
	txa
	jmp     L0297
;
; if (!(*(dptr+11) & AM_DIR)) return FR_NO_PATH; /* Cannot trace because it is a file */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 519
L02CC:	dey
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$10
	bne     L02D2
	tax
	lda     #$03
	jmp     L0297
;
; clust = ((DWORD)LD_WORD(dptr+20) << 16) | LD_WORD(dptr+26); /* Get cluster# of the directory */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 520
L02D2:	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L02DD
	inx
L02DD:	sta     ptr1
	stx     ptr1+1
	iny
	lda     (ptr1),y
	sta     sreg+1
	dey
	lda     (ptr1),y
	sta     sreg
	tya
	tax
	jsr     pusheax
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L02E0
	inx
L02E0:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     tosor0ax
	ldy     #$03
	jsr     steaxysp
;
; scan->clust = scan->sclust = clust;    /* Restart scan with the new directory */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 521
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$10
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0A
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
	ldy     #$04
	jsr     steaxspidx
;
; scan->sect = clust2sect(clust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 522
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$08
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _clust2sect
	ldy     #$08
	jsr     steaxspidx
;
; scan->index = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 523
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	dey
	sta     (ptr1),y
	iny
	sta     (ptr1),y
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 524
	jmp     L0299
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 525
L0297:	ldy     #$0F
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; __near__ unsigned char* __near__ reserve_direntry (__near__ struct _DIR*, unsigned short)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_reserve_direntry: near

.segment	"FILESYS"

;
; if((offset == 0)||(offset < scan->index)) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 545
	ldy     #$0C
	jsr     subysp
	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cpx     #$00
	bne     L0DC7
	cmp     #$00
	beq     L02EB
L0DC7:	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$11
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0D
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     tosicmp
	jcs     L02EA
;
; clust = scan->sclust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 547
L02EB:	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	ldy     #$08
	jsr     steaxysp
;
; if (clust) { /* Dyanmic directory table */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 548
	ldy     #$0B
	jsr     ldeaxysp
	jsr     utsteax
	beq     L02F2
;
; scan->clust = clust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 549
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0D
	jsr     ldeaxysp
	ldy     #$04
	jsr     steaxspidx
;
; scan->sect = clust2sect(clust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 550
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0D
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _clust2sect
;
; } else {  /* Static directory table */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 551
	jmp     L0DC9
;
; scan->sect = FatFs_dirbase;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 552
L02F2:	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	lda     _FatFs_dirbase+3
	sta     sreg+1
	lda     _FatFs_dirbase+2
	sta     sreg
	ldx     _FatFs_dirbase+1
	lda     _FatFs_dirbase
L0DC9:	ldy     #$08
	jsr     steaxspidx
;
; scan->index = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 554
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	ldy     #$0C
	sta     (ptr1),y
	iny
	sta     (ptr1),y
;
; } else { // retrieve
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 555
	jmp     L02FE
;
; clust  = scan->clust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 556
L02EA:	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	ldy     #$08
	jsr     steaxysp
;
; if(offset != 0) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 559
L02FE:	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cpx     #$00
	bne     L0304
	cmp     #$00
	beq     L0305
;
; while(scan->index != offset) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 560
L0304:	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	dey
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	cmp     (sp),y
	bne     L0DC8
	txa
	iny
	cmp     (sp),y
	beq     L0305
;
; if (!move_window(scan->sect))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 561
L0DC8:	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	jsr     ldeaxidx
	jsr     pusheax
	jsr     _move_window
	tax
;
; return NULL;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 562
	jeq     L02E9
;
; if (!next_dir_entry(scan))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 563
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	jsr     _next_dir_entry
	tax
	bne     L0304
;
; return NULL;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 564
	jmp     L02E9
;
; if (!move_window(scan->sect)) return NULL;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 569
L0305:	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	jsr     ldeaxidx
	jsr     pusheax
	jsr     _move_window
	tax
	jeq     L02E9
;
; dptr = &(FatFs_win[(scan->index & 15) * 32]);  /* Pointer to the directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 570
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0C
	lda     (ptr1),y
	ldx     #$00
	and     #$0F
	jsr     shlax4
	stx     tmp1
	asl     a
	rol     tmp1
	clc
	adc     #<(_FatFs_win)
	tay
	lda     tmp1
	adc     #>(_FatFs_win)
	tax
	tya
	jsr     stax0sp
;
; c = *dptr;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 571
	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	ldy     #$03
	sta     (sp),y
;
; if ((c == 0) || (c == 0xE5)) return dptr;  /* Found an empty entry! */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 572
	lda     (sp),y
	beq     L031E
	lda     (sp),y
	cmp     #$E5
	bne     L031D
L031E:	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jmp     L02E9
;
; } while (next_dir_entry(scan));      /* Next directory pointer */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 573
L031D:	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	jsr     _next_dir_entry
	tax
	bne     L0305
;
; if ((!clust) || !(clust = create_chain(scan->clust))) return NULL;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 577
	ldy     #$0B
	jsr     ldeaxysp
	jsr     bnegeax
	bne     L0326
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$07
	jsr     ldeaxidx
	jsr     pusheax
	jsr     _create_chain
	ldy     #$08
	jsr     steaxysp
	jsr     bnegeax
	beq     L0325
L0326:	ldx     #$00
	txa
	jmp     L02E9
;
; if (!move_window(0)) return 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 578
L0325:	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	jeq     L02E9
;
; FatFs_winsect = sector = clust2sect(clust);   /* Cleanup the expanded table */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 580
	ldy     #$0B
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _clust2sect
	ldy     #$04
	jsr     steaxysp
	sta     _FatFs_winsect
	stx     _FatFs_winsect+1
	ldy     sreg
	sty     _FatFs_winsect+2
	ldy     sreg+1
	sty     _FatFs_winsect+3
;
; memset(FatFs_win, 0, 512);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 581
	lda     #<(_FatFs_win)
	ldx     #>(_FatFs_win)
	jsr     pushax
	ldx     #$02
	lda     #$00
	jsr     __bzero
;
; for (n = FatFs_sects_clust; n; n--) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 582
	lda     _FatFs_sects_clust
	ldy     #$02
L0DCA:	sta     (sp),y
	lda     (sp),y
	beq     L033A
;
; if (disk_write(FatFs_win, sector, 1) != RES_OK) return NULL;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 583
	jsr     decsp7
	lda     #<(_FatFs_win)
	ldy     #$05
	sta     (sp),y
	iny
	lda     #>(_FatFs_win)
	sta     (sp),y
	ldy     #$0E
	jsr     ldeaxysp
	ldy     #$01
	jsr     steaxysp
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _disk_write
	cmp     #$00
	beq     L0341
	ldx     #$00
	txa
	jmp     L02E9
;
; sector++;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 584
L0341:	ldy     #$07
	jsr     ldeaxysp
	jsr     saveeax
	ldy     #$01
	jsr     inceaxy
	ldy     #$04
	jsr     steaxysp
	jsr     resteax
;
; for (n = FatFs_sects_clust; n; n--) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 582
	ldy     #$02
	lda     (sp),y
	sec
	sbc     #$01
	jmp     L0DCA
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 586
L033A:	lda     #$01
	sta     _FatFs_winflag
;
; return FatFs_win;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 587
	lda     #<(_FatFs_win)
	ldx     #>(_FatFs_win)
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 588
L02E9:	ldy     #$10
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; __near__ unsigned char* __near__ reserve_direntries (__near__ struct _DIR*, unsigned char)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_reserve_direntries: near

.segment	"FILESYS"

;
; WORD offset = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 600
	jsr     decsp4
	jsr     push0
;
; BYTE cnt = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 601
	jsr     pusha
;
; while(cnt < size) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 603
L034E:	ldy     #$00
	lda     (sp),y
	ldy     #$07
	cmp     (sp),y
	jcs     L034F
;
; p = reserve_direntry(scan, offset);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 604
	jsr     decsp4
	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _reserve_direntry
	ldy     #$05
	jsr     staxysp
;
; offset = scan->index + 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 605
	ldy     #$09
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0D
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	clc
	adc     #$01
	bcc     L0357
	inx
L0357:	ldy     #$01
	jsr     staxysp
;
; if(!p)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 607
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     bnegax
	beq     L0358
;
; return NULL;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 608
	ldx     #$00
	txa
	jmp     L034B
;
; if(cnt == 0) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 610
L0358:	ldy     #$00
	lda     (sp),y
;
; } else if(scan->index != (idx+cnt)) { // the next found free entry is not consecutive
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 612
	beq     L0DD8
	ldy     #$09
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0D
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     pushax
	ldy     #$02
	lda     (sp),y
	clc
	ldy     #$05
	adc     (sp),y
	pha
	lda     #$00
	iny
	adc     (sp),y
	tax
	pla
	jsr     tosicmp
	beq     L0360
;
; cnt  = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 614
	lda     #$00
	tay
	sta     (sp),y
;
; idx  = scan->index;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 615
L0DD8:	ldy     #$09
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0D
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	ldy     #$03
	jsr     staxysp
;
; cnt++; // number of free cells found
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 617
L0360:	ldy     #$00
	lda     (sp),y
	clc
	adc     #$01
	sta     (sp),y
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 618
	jmp     L034E
;
; return reserve_direntry(scan, idx);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 620
L034F:	jsr     decsp4
	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _reserve_direntry
;
; }    
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 621
L034B:	ldy     #$0A
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ valid_char (signed char)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_valid_char: near

.segment	"FILESYS"

;
; if((c >= 'A')&&(c <= 'Z'))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 625
	ldy     #$00
	lda     (sp),y
	sec
	sbc     #$41
	bvs     L0370
	eor     #$80
L0370:	bpl     L036C
	lda     (sp),y
	sec
	sbc     #$5B
	bvc     L0374
	eor     #$80
L0374:	bpl     L036C
;
; return 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 626
	ldx     #$00
	lda     #$01
	jmp     incsp1
;
; if((c >= 'a')&&(c <= 'z'))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 627
L036C:	lda     (sp),y
	sec
	sbc     #$61
	bvs     L037B
	eor     #$80
L037B:	bpl     L0377
	lda     (sp),y
	sec
	sbc     #$7B
	bvc     L037F
	eor     #$80
L037F:	bpl     L0377
;
; return 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 628
	ldx     #$00
	lda     #$01
	jmp     incsp1
;
; if((c >= '0')&&(c <= '9'))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 629
L0377:	lda     (sp),y
	sec
	sbc     #$30
	bvs     L0386
	eor     #$80
L0386:	bpl     L0382
	lda     (sp),y
	sec
	sbc     #$3A
	bvc     L038A
	eor     #$80
L038A:	bpl     L0382
;
; return 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 630
	ldx     #$00
	lda     #$01
	jmp     incsp1
;
; if((c == '-')||(c == '_'))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 631
L0382:	lda     (sp),y
	cmp     #$2D
	beq     L038E
	lda     (sp),y
	cmp     #$5F
	bne     L038D
;
; return 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 632
L038E:	ldx     #$00
	lda     #$01
	jmp     incsp1
;
; return 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 633
L038D:	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 634
	jmp     incsp1
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ create_lfn (__near__ struct _DIR*, __near__ signed char*, __near__ __near__ unsigned char**)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_create_lfn: near

.segment	"BSS"

L0398:
	.res	32,$00

.segment	"FILESYS"

;
; BOOL trunc = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 652
	ldy     #$0A
	jsr     subysp
	lda     #$00
	jsr     pusha
;
; memset(shortname, 32, 11); // put spaces
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 659
	ldy     #$1A
	jsr     subysp
	ldy     #$0C
	lda     #$20
L03A1:	sta     (sp),y
	iny
	cpy     #$17
	bne     L03A1
;
; shortname[11] = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 660
	lda     #$00
	sta     (sp),y
;
; len = strlen(name);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 662
	ldy     #$28
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     _strlen
	ldy     #$24
	sta     (sp),y
;
; ext = len;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 667
	ldy     #$1B
	sta     (sp),y
;
; b = len-1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 668
	ldy     #$24
	lda     (sp),y
	sec
	sbc     #$01
	ldy     #$1D
	sta     (sp),y
;
; if (name[b]=='.') {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 670
L03AE:	ldy     #$28
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1D
	lda     (sp),y
	tay
	lda     (ptr1),y
	cmp     #$2E
	jne     L03B1
;
; ext = b;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 671
	ldy     #$1D
	lda     (sp),y
	ldy     #$1B
	sta     (sp),y
;
; for(c=0,b++;c<3;b++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 672
	lda     #$00
	iny
L0DF7:	sta     (sp),y
	ldy     #$1D
	lda     (sp),y
	clc
	adc     #$01
	sta     (sp),y
	dey
	lda     (sp),y
	cmp     #$03
	jcs     L03AF
;
; if (!name[b])
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 673
	ldy     #$28
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1D
	lda     (sp),y
	tay
	lda     (ptr1),y
	tax
;
; break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 674
	jeq     L03AF
;
; if(valid_char(name[b])) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 675
	ldy     #$28
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1D
	lda     (sp),y
	tay
	lda     (ptr1),y
	jsr     pusha
	jsr     _valid_char
	tax
	beq     L03C2
;
; shortname[8+c] = name[b];
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 676
	ldy     #$1C
	ldx     #$00
	lda     (sp),y
	clc
	adc     #$08
	bcc     L0DE7
	inx
	clc
L0DE7:	adc     #$0C
	bcc     L03C9
	inx
	clc
L03C9:	adc     sp
	sta     sreg
	txa
	adc     sp+1
	sta     sreg+1
	ldy     #$28
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1D
	lda     (sp),y
	tay
	lda     (ptr1),y
	ldy     #$00
	sta     (sreg),y
;
; c++;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 677
	ldy     #$1C
	lda     (sp),y
	clc
	adc     #$01
;
; } else {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 678
	jmp     L0DF7
;
; shortname[8+c] = '_';
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 679
L03C2:	ldy     #$1C
	lda     (sp),y
	clc
	adc     #$08
	bcc     L0DE8
	inx
	clc
L0DE8:	adc     #$0C
	bcc     L03D1
	inx
	clc
L03D1:	adc     sp
	sta     ptr1
	txa
	adc     sp+1
	sta     ptr1+1
	lda     #$5F
	ldy     #$00
	sta     (ptr1),y
;
; c++;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 680
	ldy     #$1C
	lda     (sp),y
	clc
	adc     #$01
	sta     (sp),y
;
; trunc = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 681
	lda     #$01
	ldy     #$1A
;
; for(c=0,b++;c<3;b++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 672
	jmp     L0DF7
;
; b--;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 686
L03B1:	ldy     #$1D
	lda     (sp),y
	sec
	sbc     #$01
	sta     (sp),y
;
; } while(b != 0);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 687
	lda     (sp),y
	jne     L03AE
;
; if(ext != len) { // there was an extension
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 691
L03AF:	ldy     #$1B
	ldx     #$00
	lda     (sp),y
	ldy     #$24
	cmp     (sp),y
	bne     L0DEA
	txa
	beq     L03D8
;
; trunc = trunc || ((c==3)&&(b<len));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 692
L0DEA:	ldy     #$1A
	lda     (sp),y
	bne     L03DB
	ldy     #$1C
	lda     (sp),y
	cmp     #$03
	bne     L0DE1
	iny
	lda     (sp),y
	ldy     #$24
	cmp     (sp),y
	bcc     L03DB
L0DE1:	txa
	jmp     L03E1
L03DB:	lda     #$01
L03E1:	ldy     #$1A
	sta     (sp),y
;
; for(b=0,c=0;((b<len)&&(b<ext)&&(c<8));b++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 696
L03D8:	txa
	ldy     #$1D
	sta     (sp),y
	dey
L0DED:	sta     (sp),y
	ldy     #$1D
	lda     (sp),y
	ldy     #$24
	cmp     (sp),y
	bcs     L03E3
	ldy     #$1D
	lda     (sp),y
	ldy     #$1B
	cmp     (sp),y
	bcs     L03E3
	iny
	lda     (sp),y
	cmp     #$08
	bcs     L03E3
;
; if(valid_char(name[b]))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 697
	ldy     #$28
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1D
	lda     (sp),y
	tay
	lda     (ptr1),y
	jsr     pusha
	jsr     _valid_char
	tax
	beq     L03F2
;
; shortname[c++] = name[b];
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 698
	ldy     #$1C
	ldx     #$00
	lda     (sp),y
	pha
	clc
	adc     #$01
	sta     (sp),y
	pla
	clc
	adc     #$0C
	bcc     L03F8
	inx
	clc
L03F8:	adc     sp
	sta     sreg
	txa
	adc     sp+1
	sta     sreg+1
	ldy     #$28
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1D
	lda     (sp),y
	tay
	lda     (ptr1),y
	ldy     #$00
	sta     (sreg),y
;
; else {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 699
	jmp     L03E4
;
; trunc = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 701
L03F2:	lda     #$01
	ldy     #$1A
	sta     (sp),y
;
; for(b=0,c=0;((b<len)&&(b<ext)&&(c<8));b++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 696
L03E4:	ldy     #$1D
	lda     (sp),y
	clc
	adc     #$01
	jmp     L0DED
;
; trunc = ((b<len)&&(b<ext)) || (c<b) || trunc;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 707
L03E3:	ldy     #$1D
	lda     (sp),y
	ldy     #$24
	cmp     (sp),y
	bcs     L0DE3
	ldy     #$1D
	lda     (sp),y
	ldy     #$1B
	cmp     (sp),y
	bcc     L03FF
L0DE3:	ldy     #$1C
	lda     (sp),y
	iny
	cmp     (sp),y
	bcc     L03FF
	ldy     #$1A
	lda     (sp),y
	beq     L0406
L03FF:	lda     #$01
L0406:	ldy     #$1A
	sta     (sp),y
;
; for(b=0;b<11;b++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 712
	lda     #$00
	ldy     #$1D
L0DEE:	sta     (sp),y
	cmp     #$0B
	bcs     L0408
;
; if((shortname[b] >= 'a')&&(shortname[b] <= 'z'))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 713
	lda     sp
	ldx     sp+1
	clc
	adc     #$0C
	bcc     L0DF0
	inx
	clc
L0DF0:	adc     (sp),y
	bcc     L0414
	inx
L0414:	ldy     #$00
	jsr     ldaidx
	sec
	sbc     #$61
	bvs     L0415
	eor     #$80
L0415:	bpl     L0409
	lda     sp
	ldx     sp+1
	clc
	adc     #$0C
	bcc     L0419
	inx
L0419:	ldy     #$1D
	clc
	adc     (sp),y
	bcc     L041A
	inx
L041A:	ldy     #$00
	jsr     ldaidx
	sec
	sbc     #$7B
	bvc     L041B
	eor     #$80
L041B:	bpl     L0409
;
; shortname[b] -= 0x20;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 714
	lda     sp
	ldx     sp+1
	clc
	adc     #$0C
	bcc     L041F
	inx
L041F:	ldy     #$1D
	clc
	adc     (sp),y
	bcc     L0420
	inx
L0420:	jsr     pushax
	ldy     #$00
	jsr     ldaidx
	sec
	sbc     #$20
	jsr     staspidx
;
; for(b=0;b<11;b++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 712
L0409:	ldy     #$1D
	lda     (sp),y
	clc
	adc     #$01
	jmp     L0DEE
;
; num = len / 13;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 718
L0408:	ldy     #$24
	lda     (sp),y
	jsr     pusha0
	lda     #$0D
	jsr     tosudiva0
	ldy     #$23
	sta     (sp),y
;
; num += 2;      // 0 => 2, 12 => 2, 13 => 3 (including the terminating zero, and the short name entry)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 719
	clc
	lda     #$02
	adc     (sp),y
	sta     (sp),y
;
; p = reserve_direntries(scan, num);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 721
	jsr     decsp3
	ldy     #$2D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$01
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$26
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	jsr     _reserve_direntries
	ldy     #$1E
	jsr     staxysp
;
; if(!p)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 723
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     bnegax
	beq     L042A
;
; return FR_DISK_FULL;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 724
	ldx     #$00
	lda     #$06
	jmp     L0396
;
; if(trunc) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 727
L042A:	ldy     #$1A
	lda     (sp),y
	jeq     L042D
;
; idx = scan->index >> 1;  // since an LFN fileentry is at least 2 entries, we can safely divide by 2.
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 728
	ldy     #$2A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0D
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     shrax1
	ldy     #$18
	jsr     staxysp
;
; sprintf(tilde, "~%d", idx);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 729
	jsr     decsp4
	lda     sp
	ldx     sp+1
	clc
	adc     #$08
	bcc     L0433
	inx
L0433:	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #<(L0001)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(L0001)
	sta     (sp),y
	ldy     #$1D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$06
	jsr     _sprintf
;
; b = strlen(tilde);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 730
	ldx     #$FF
	ldy     #$03
L0439:	inx
	iny
	lda     (sp),y
	bne     L0439
	txa
	ldy     #$1D
	sta     (sp),y
;
; if((8-b) <= c)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 731
	lda     #$08
	sec
	sbc     (sp),y
	sec
	dey
	sbc     (sp),y
	sta     tmp1
	lda     tmp1
	beq     L0DE5
	bcs     L043A
;
; c=8-b;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 732
L0DE5:	lda     #$08
	sec
	iny
	sbc     (sp),y
	dey
	sta     (sp),y
;
; memcpy(&shortname[c], tilde, b);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 733
L043A:	lda     sp
	ldx     sp+1
	clc
	adc     #$0C
	bcc     L0DF1
	inx
	clc
L0DF1:	adc     (sp),y
	bcc     L0443
	inx
L0443:	jsr     pushax
	lda     sp
	ldx     sp+1
	clc
	adc     #$06
	bcc     L0445
	inx
L0445:	jsr     pushax
	ldy     #$21
	lda     (sp),y
	ldx     #$00
	jsr     _memcpy
;
; chk = calc_lfn_checksum((BYTE *)shortname);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 736
L042D:	lda     sp
	ldx     sp+1
	clc
	adc     #$0C
	bcc     L044A
	inx
L044A:	jsr     pushax
	jsr     _calc_lfn_checksum
	ldy     #$22
	sta     (sp),y
;
; memset(lfn, 0xff, 32);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 738
	ldy     #$1F
	lda     #$FF
L044F:	sta     L0398,y
	dey
	bpl     L044F
;
; end = 0x40;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 741
	lda     #$40
	ldy     #$20
	sta     (sp),y
;
; while(--num) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 742
L0452:	ldy     #$23
	lda     (sp),y
	sec
	sbc     #$01
	sta     (sp),y
	tax
	jeq     L0453
;
; ofs = 13*(num-1);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 743
	lda     #$0D
	jsr     pusha0
	ldy     #$25
	lda     (sp),y
	sec
	sbc     #$01
	bcs     L0458
	ldx     #$FF
L0458:	jsr     tosumulax
	ldy     #$21
	sta     (sp),y
;
; lfn[0] = num | end;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 744
	dey
	lda     (sp),y
	ldy     #$23
	ora     (sp),y
	sta     L0398
;
; end = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 745
	lda     #$00
	ldy     #$20
	sta     (sp),y
;
; for(b=1;(b<=30)&&(ofs<=len);b+=2,ofs++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 746
	lda     #$01
	ldy     #$1D
L0DEF:	sta     (sp),y
	ldy     #$1D
	lda     (sp),y
	cmp     #$1F
	bcs     L045F
	ldy     #$21
	lda     (sp),y
	sec
	ldy     #$24
	sbc     (sp),y
	bcc     L0461
	bne     L045F
;
; lfn[b] = name[ofs];
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 747
L0461:	lda     #<(L0398)
	ldx     #>(L0398)
	ldy     #$1D
	clc
	adc     (sp),y
	bcc     L046E
	inx
L046E:	sta     sreg
	stx     sreg+1
	ldy     #$28
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$21
	lda     (sp),y
	tay
	lda     (ptr1),y
	ldy     #$00
	sta     (sreg),y
;
; lfn[b+1] = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 748
	ldy     #$1D
	ldx     #$00
	lda     (sp),y
	clc
	adc     #$01
	bcc     L0DE9
	inx
	clc
L0DE9:	adc     #<(L0398)
	sta     ptr1
	txa
	adc     #>(L0398)
	sta     ptr1+1
	lda     #$00
	tay
	sta     (ptr1),y
;
; if(b==9) b+=3; /* jump to 14 */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 749
	ldy     #$1D
	lda     (sp),y
	cmp     #$09
	bne     L0475
	clc
	lda     #$03
	adc     (sp),y
	sta     (sp),y
;
; if(b==24) b+=2; /* jump to 28 */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 750
L0475:	lda     (sp),y
	cmp     #$18
	bne     L0460
	clc
	lda     #$02
	adc     (sp),y
	sta     (sp),y
;
; for(b=1;(b<=30)&&(ofs<=len);b+=2,ofs++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 746
L0460:	clc
	lda     #$02
	adc     (sp),y
	sta     (sp),y
	ldy     #$21
	lda     (sp),y
	clc
	adc     #$01
	jmp     L0DEF
;
; lfn[11] = AM_LFN;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 752
L045F:	lda     #$0F
	sta     L0398+11
;
; lfn[12] = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 753
	lda     #$00
	sta     L0398+12
;
; lfn[13] = chk;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 754
	ldy     #$22
	lda     (sp),y
	sta     L0398+13
;
; lfn[26] = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 755
	lda     #$00
	sta     L0398+26
;
; lfn[27] = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 756
	sta     L0398+27
;
; memcpy(p, lfn, 32);  // write back in directory!
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 758
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	lda     #<(L0398)
	ldx     #>(L0398)
	jsr     pushax
	ldx     #$00
	lda     #$20
	jsr     _memcpy
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 761
	lda     #$01
	sta     _FatFs_winflag
;
; p = reserve_direntry(scan, scan->index + 1);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 764
	jsr     decsp4
	ldy     #$2E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$2E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0D
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	clc
	adc     #$01
	bcc     L0496
	inx
L0496:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _reserve_direntry
	ldy     #$1E
	jsr     staxysp
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 765
	jmp     L0452
;
; memcpy(p, shortname, 11);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 768
L0453:	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	lda     sp
	ldx     sp+1
	clc
	adc     #$0E
	bcc     L049A
	inx
L049A:	jsr     pushax
	ldx     #$00
	lda     #$0B
	jsr     _memcpy
;
; p[11] = AM_ARC;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 769
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$20
	ldy     #$0B
	sta     (ptr1),y
;
; p[12] = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 770
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	ldy     #$0C
	sta     (ptr1),y
;
; memset(p+13, 0, 32-13);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 771
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0D
	bcc     L04A4
	inx
L04A4:	sta     ptr1
	stx     ptr1+1
	lda     #$00
	ldy     #$12
L0DE0:	sta     (ptr1),y
	dey
	bpl     L0DE0
;
; dw = get_fattime();
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 772
	jsr     _get_fattime
	jsr     steax0sp
;
; ST_DWORD(p+14, dw); /* Created time */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 773
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0E
	bcc     L04AB
	inx
L04AB:	jsr     pushax
	ldy     #$05
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
;
; ST_DWORD(p+22, dw); /* Updated time */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 774
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$16
	bcc     L04B0
	inx
L04B0:	jsr     pushax
	ldy     #$05
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
;
; *ptr = p;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 776
	ldy     #$26
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$1F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (ptr1),y
	iny
	txa
	sta     (ptr1),y
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 777
	sty     _FatFs_winflag
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 779
	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 780
L0396:	ldy     #$2B
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ f_readdir_scans (__near__ struct _DIR*, __near__ struct _DIR*, __near__ struct _DIR*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_f_readdir_scans: near

.segment	"FILESYS"

;
; if ((disk_status() & STA_NOINIT) || !FatFs_fs_type) return FR_NOT_READY;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 847
	jsr     decsp7
	ldy     #$00
	jsr     _disk_status
	and     #$01
	bne     L0530
	lda     _FatFs_fs_type
	bne     L052F
L0530:	ldx     #$00
	lda     #$01
	jmp     L052E
;
; first = done = FALSE; // assume we will not read anything
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 849
L052F:	lda     #$00
	ldy     #$04
	sta     (sp),y
	ldy     #$06
	sta     (sp),y
;
; while (scan->sect) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 850
L0537:	ldy     #$0C
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxidx
	jsr     utsteax
	jeq     L0538
;
; if (!move_window(scan->sect)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 851
	ldy     #$0C
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxidx
	jsr     pusheax
	jsr     _move_window
	tax
	bne     L053A
	lda     #$07
	jmp     L052E
;
; entry = &(FatFs_win[(scan->index & 15) * 32]);  /* pointer to the directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 852
L053A:	ldy     #$0C
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	iny
	lda     (ptr1),y
	ldx     #$00
	and     #$0F
	jsr     shlax4
	stx     tmp1
	asl     a
	rol     tmp1
	clc
	adc     #<(_FatFs_win)
	tay
	lda     tmp1
	adc     #>(_FatFs_win)
	tax
	tya
	ldy     #$02
	jsr     staxysp
;
; c = *entry;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 853
	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	iny
	sta     (sp),y
;
; if (c == 0) return FR_NO_FILE;     /* Has it reached to end of dir? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 854
	lda     (sp),y
	jeq     L0538
;
; if((*(entry+11) & AM_LFN)==AM_LFN) {            /* Long file name entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 855
	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$0F
	cmp     #$0F
	bne     L0548
;
; chk = *(entry+13);                          /* store checksum for comparison later */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 856
	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0D
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	ldy     #$00
	sta     (sp),y
;
; copy = TRUE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 857
	lda     #$01
	ldy     #$05
;
; else if ((c != 0xE5) && (c != '.') && !(*(entry+11) & AM_VOL)) { /* Is it a valid entry? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 859
	jmp     L0DFA
L0548:	ldy     #$01
	lda     (sp),y
	cmp     #$E5
	beq     L0555
	lda     (sp),y
	cmp     #$2E
	beq     L0555
	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$08
	bne     L0555
;
; c = calc_lfn_checksum(entry); 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 860
	ldy     #$03
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	jsr     _calc_lfn_checksum
	ldy     #$01
	sta     (sp),y
;
; if(c != chk) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 861
	ldx     #$00
	lda     (sp),y
	dey
	cmp     (sp),y
	bne     L0DFB
	txa
	beq     L0561
;
; first = FALSE; 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 863
L0DFB:	txa
	ldy     #$06
	sta     (sp),y
;
; copy = TRUE;    
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 864
	lda     #$01
	dey
	sta     (sp),y
;
; memcpy(lastscan, scan, sizeof(DIR)); // the caller would like to know 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 866
L0561:	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	lda     #$0E
	jsr     _memcpy
;
; done = TRUE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 867
	lda     #$01
	ldy     #$04
;
; else {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 869
	jmp     L0DFA
;
; copy = FALSE; // Its nothing forget it
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 870
L0555:	lda     #$00
	ldy     #$05
	sta     (sp),y
;
; first = FALSE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 871
	iny
L0DFA:	sta     (sp),y
;
; if(!first && copy) { // Did we get it?
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 874
	ldy     #$06
	lda     (sp),y
	bne     L0572
	dey
	lda     (sp),y
	beq     L0572
;
; memcpy(firstscan, scan, sizeof(DIR)); // the caller would like to know
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 875
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	lda     #$0E
	jsr     _memcpy
;
; first = TRUE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 876
	lda     #$01
	ldy     #$06
	sta     (sp),y
;
; if (!next_dir_entry(scan)) scan->sect = 0;  /* Next entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 879
L0572:	ldy     #$0C
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	jsr     _next_dir_entry
	tax
	bne     L057C
	ldy     #$0C
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	stx     sreg
	stx     sreg+1
	txa
	ldy     #$08
	jsr     steaxspidx
;
; if(done) { 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 881
L057C:	ldy     #$04
	lda     (sp),y
	jeq     L0537
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 882
	ldx     #$00
	txa
	jmp     L052E
;
; return FR_NO_FILE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 886
L0538:	ldx     #$00
	lda     #$02
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 887
L052E:	ldy     #$0D
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ find_scans_fcluster (__near__ struct _DIR*, unsigned long, __near__ struct _DIR*, __near__ struct _DIR*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_find_scans_fcluster: near

.segment	"FILESYS"

;
; do {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 900
	jsr     decsp7
;
; fres = f_readdir_scans(scan, firstscan, lastscan);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 901
L0586:	jsr     decsp6
	ldy     #$16
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$04
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$10
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$0E
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _f_readdir_scans
	ldy     #$06
	sta     (sp),y
;
; entry = &(FatFs_win[(lastscan->index & 15) * 32]);  /* pointer to the directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 902
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0C
	lda     (ptr1),y
	ldx     #$00
	and     #$0F
	jsr     shlax4
	stx     tmp1
	asl     a
	rol     tmp1
	clc
	adc     #<(_FatFs_win)
	tay
	lda     tmp1
	adc     #>(_FatFs_win)
	tax
	tya
	jsr     stax0sp
;
; foundcluster = ((DWORD)LD_WORD(entry+20) << 16) | LD_WORD(entry+26); /* Cluster */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 903
	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L0598
	inx
L0598:	sta     ptr1
	stx     ptr1+1
	iny
	lda     (ptr1),y
	sta     sreg+1
	dey
	lda     (ptr1),y
	sta     sreg
	tya
	tax
	jsr     pusheax
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L059B
	inx
L059B:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     tosor0ax
	ldy     #$02
	jsr     steaxysp
;
; } while((fres == FR_OK) && (fcluster != foundcluster));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 904
	ldy     #$06
	lda     (sp),y
	bne     L0DFC
	ldy     #$0E
	jsr     ldeaxysp
	jsr     pusheax
	ldy     #$09
	jsr     ldeaxysp
	jsr     tosneeax
	jne     L0586
;
; return fres;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 905
L0DFC:	ldy     #$06
	ldx     #$00
	lda     (sp),y
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 906
	ldy     #$11
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ find_lfn (__near__ struct _DIR*, __near__ signed char*, __near__ struct _DIR*, __near__ struct _DIR*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_find_lfn: near

.segment	"BSS"

L05A3:
	.res	26,$00
L05A4:
	.res	1,$00
L05A6:
	.res	23,$00
L05A8:
	.res	4,$00

.segment	"FILESYS"

;
; WORD entries = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 918
	jsr     push0
;
; memcpy(&tempscan, scan, sizeof(tempscan)); // Keep this as we first want to find the bloody file
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 921
	jsr     decsp2
	lda     #<(_tempscan)
	ldx     #>(_tempscan)
	jsr     pushax
	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	lda     #$0E
	jsr     _memcpy
;
; len = data_strnlen(name, MAX_ENTRY_NAME);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 924
	jsr     decsp3
	ldy     #$0C
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$01
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #$16
	ldy     #$00
	sta     (sp),y
	jsr     _data_strnlen
	ldy     #$01
	sta     (sp),y
;
; for(i = 0; i < len; i++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 925
	lda     #$00
	dey
L0E00:	sta     (sp),y
	iny
	cmp     (sp),y
	bcs     L05B4
;
; casedname[i] = name[i] | 0x20;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 926
	lda     #<(L05A6)
	ldx     #>(L05A6)
	dey
	clc
	adc     (sp),y
	bcc     L05BD
	inx
L05BD:	jsr     pushax
	ldy     #$0B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$02
	lda     (sp),y
	tay
	lda     (ptr1),y
	ora     #$20
	ldy     #$00
	jsr     staspidx
;
; for(i = 0; i < len; i++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 925
	ldy     #$00
	lda     (sp),y
	clc
	adc     #$01
	jmp     L0E00
;
; casedname[i] = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 928
L05B4:	lda     #<(L05A6)
	ldx     #>(L05A6)
	dey
	clc
	adc     (sp),y
	bcc     L05C2
	inx
L05C2:	jsr     pushax
	lda     #$00
	tay
	jsr     staspidx
;
; ext[3] = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 932
	tax
	sta     L05A8+3
;
; memset(&temp_name, 0, NR_OF_EL(temp_name));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 934
L05C7:	ldy     #$16
L05D2:	sta     _temp_name,y
	dey
	bpl     L05D2
;
; fres = f_readdir_lfn(&tempscan, &finfo, temp_name, NR_OF_EL(temp_name), ext);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 936
	ldy     #$09
	jsr     subysp
	lda     #<(_tempscan)
	ldy     #$07
	sta     (sp),y
	iny
	lda     #>(_tempscan)
	sta     (sp),y
	lda     #<(L05A3)
	ldy     #$05
	sta     (sp),y
	iny
	lda     #>(L05A3)
	sta     (sp),y
	lda     #<(_temp_name)
	ldy     #$03
	sta     (sp),y
	iny
	lda     #>(_temp_name)
	sta     (sp),y
	lda     #$17
	ldy     #$02
	sta     (sp),y
	lda     #<(L05A8)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(L05A8)
	sta     (sp),y
	jsr     _f_readdir_lfn
	sta     L05A4
;
; if(fres == FR_OK) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 938
	lda     L05A4
	jne     L0605
;
; if(!(temp_name[0]) && finfo.fname[0]) { // if the file has no long file name
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 939
	lda     _temp_name
	bne     L05E0
	lda     L05A3+13
	beq     L05E0
;
; strncpy(temp_name, &finfo.fname[0], NR_OF_EL(temp_name)); // use shorty for it. who cares?
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 940
	jsr     decsp4
	lda     #<(_temp_name)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_temp_name)
	sta     (sp),y
	lda     #<(L05A3+13)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(L05A3+13)
	sta     (sp),y
	ldx     #$00
	lda     #$17
	jsr     _strncpy
;
; len = data_strnlen(temp_name, NR_OF_EL(temp_name));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 944
L05E0:	jsr     decsp3
	lda     #<(_temp_name)
	ldy     #$01
	sta     (sp),y
	iny
	lda     #>(_temp_name)
	sta     (sp),y
	lda     #$17
	ldy     #$00
	sta     (sp),y
	jsr     _data_strnlen
	ldy     #$01
	sta     (sp),y
;
; for(i = 0; i < len; i++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 945
	lda     #$00
	dey
L0E01:	sta     (sp),y
	iny
	cmp     (sp),y
	bcs     L05FA
;
; temp_name[i] |= 0x20;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 946
	lda     #<(_temp_name)
	ldx     #>(_temp_name)
	dey
	clc
	adc     (sp),y
	bcc     L0603
	inx
L0603:	jsr     pushax
	ldy     #$00
	jsr     ldaidx
	ora     #$20
	jsr     staspidx
;
; for(i = 0; i < len; i++) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 945
	ldy     #$00
	lda     (sp),y
	clc
	adc     #$01
	jmp     L0E01
;
; if(strncmp(temp_name, casedname, NR_OF_EL(temp_name)) == 0) { // compare the file name to what we want.
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 951
L05FA:	jsr     decsp4
	lda     #<(_temp_name)
	iny
	sta     (sp),y
	iny
	lda     #>(_temp_name)
	sta     (sp),y
	lda     #<(L05A6)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(L05A6)
	sta     (sp),y
	ldx     #$00
	lda     #$17
	jsr     _strncmp
	cpx     #$00
	bne     L0605
	cmp     #$00
	bne     L0605
;
; memcpy(&tempscan, scan, sizeof(tempscan)); // Keep this as we dont want to change the callers scan
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 953
	lda     #<(_tempscan)
	ldx     #>(_tempscan)
	jsr     pushax
	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	lda     #$0E
	jsr     _memcpy
;
; fres = find_scans_fcluster(&tempscan, finfo.fcluster, firstscan, lastscan);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 954
	ldy     #$0A
	jsr     subysp
	lda     #<(_tempscan)
	ldy     #$08
	sta     (sp),y
	iny
	lda     #>(_tempscan)
	sta     (sp),y
	lda     L05A3+4+3
	sta     sreg+1
	lda     L05A3+4+2
	sta     sreg
	ldx     L05A3+4+1
	lda     L05A3+4
	ldy     #$04
	jsr     steaxysp
	ldy     #$11
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _find_scans_fcluster
	sta     L05A4
;
; return fres;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 955
	ldx     #$00
	lda     L05A4
	jmp     L05A2
;
; } while(fres == FR_OK); 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 958
L0605:	ldx     #$00
	lda     L05A4
	jeq     L05C7
;
; memset(firstscan, 0, sizeof(DIR));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 961
	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	ldy     #$0D
L0DFE:	sta     (ptr1),y
	dey
	bpl     L0DFE
;
; memset(lastscan, 0, sizeof(DIR));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 962
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	ldy     #$0D
L0DFF:	sta     (ptr1),y
	dey
	bpl     L0DFF
;
; return FR_NO_FILE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 964
	ldx     #$00
	lda     #$02
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 965
L05A2:	ldy     #$0C
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ check_mounted (void)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_check_mounted: near

.segment	"FILESYS"

;
; if (disk_status() & STA_NOINIT) { /* The drive has not been initialized */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 974
	ldy     #$00
	jsr     _disk_status
	and     #$01
	beq     L0626
;
; if (FatFs_files)     /* Drive was uninitialized with any file left opend */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 975
	lda     _FatFs_files
	jeq     _banked_f_mountdrv
;
; return FR_INCORRECT_DISK_CHANGE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 976
	ldx     #$00
	lda     #$08
	rts
;
; if (!FatFs_fs_type)    /* But the file system has not been initialized */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 980
L0626:	lda     _FatFs_fs_type
;
; return f_mountdrv();  /* Initialize file system and return resulut */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 981
	jeq     _banked_f_mountdrv
;
; return FR_OK;      /* File system is valid */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 983
	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 984
	rts
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ init_dir (unsigned long, __near__ unsigned long*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_init_dir: near

.segment	"FILESYS"

;
; sect = FatFs_winsect;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1643
	ldy     #$0F
	jsr     subysp
	lda     _FatFs_winsect+3
	sta     sreg+1
	lda     _FatFs_winsect+2
	sta     sreg
	ldx     _FatFs_winsect+1
	lda     _FatFs_winsect
	ldy     #$0B
	jsr     steaxysp
;
; dsect = clust2sect(*dclust = create_chain(0)); /* Get a new cluster for new directory */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1644
	ldy     #$10
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	txa
	jsr     push0ax
	jsr     _create_chain
	ldy     #$00
	jsr     steaxspidx
	jsr     pusheax
	jsr     _clust2sect
	ldy     #$07
	jsr     steaxysp
;
; if (!dsect) return FR_DENIED;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1645
	ldy     #$0A
	jsr     ldeaxysp
	jsr     bnegeax
	beq     L0A3B
	ldx     #$00
	lda     #$05
	jmp     L0A33
;
; if (!move_window(0)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1646
L0A3B:	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	bne     L0A3E
	lda     #$07
	jmp     L0A33
;
; w = FatFs_win;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1648
L0A3E:	lda     #<(_FatFs_win)
	ldx     #>(_FatFs_win)
	ldy     #$01
	jsr     staxysp
;
; memset(w, 0, 512);      /* Initialize the directory table */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1649
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$02
	lda     #$00
	jsr     __bzero
;
; for (n = FatFs_sects_clust - 1; n; n--) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1650
	lda     _FatFs_sects_clust
	sec
	sbc     #$01
	ldy     #$00
L0E04:	sta     (sp),y
	lda     (sp),y
	beq     L0A49
;
; if (disk_write(w, dsect+n, 1) != RES_OK) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1651
	jsr     decsp7
	ldy     #$09
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$05
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$11
	jsr     ldeaxysp
	jsr     pusheax
	ldy     #$0B
	ldx     #$00
	lda     (sp),y
	jsr     tosadd0ax
	ldy     #$01
	jsr     steaxysp
	lda     #$01
	ldy     #$00
	sta     (sp),y
	jsr     _disk_write
	cmp     #$00
	beq     L0A4A
	ldx     #$00
	lda     #$07
	jmp     L0A33
;
; for (n = FatFs_sects_clust - 1; n; n--) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1650
L0A4A:	tay
	lda     (sp),y
	sec
	sbc     #$01
	jmp     L0E04
;
; FatFs_winsect = dsect;     /* Create dot directories */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1654
L0A49:	ldy     #$0A
	jsr     ldeaxysp
	sta     _FatFs_winsect
	stx     _FatFs_winsect+1
	ldy     sreg
	sty     _FatFs_winsect+2
	ldy     sreg+1
	sty     _FatFs_winsect+3
;
; memset(w, ' ', 8+3);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1655
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0A
	lda     #$20
L0A5D:	sta     (ptr1),y
	dey
	bpl     L0A5D
;
; *w = '.';
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1656
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$2E
	dey
	sta     (ptr1),y
;
; *(w+11) = AM_DIR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1657
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$0B
	bcc     L0A62
	inx
L0A62:	sta     ptr1
	stx     ptr1+1
	lda     #$10
	dey
	sta     (ptr1),y
;
; tim = get_fattime();
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1658
	jsr     _get_fattime
	ldy     #$03
	jsr     steaxysp
;
; ST_DWORD(w+22, tim);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1659
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$16
	bcc     L0A68
	inx
L0A68:	jsr     pushax
	ldy     #$08
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
;
; ST_WORD(w+26, *dclust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1660
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L0A6D
	inx
L0A6D:	sta     sreg
	stx     sreg+1
	ldy     #$10
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	sta     (sreg),y
	iny
	txa
	sta     (sreg),y
;
; ST_WORD(w+20, (*dclust) >> 16);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1661
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L0A72
	inx
L0A72:	jsr     pushax
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     ldeaxi
	ldy     #$00
	ldx     sreg+1
	lda     sreg
	jsr     staxspidx
;
; memcpy(w+32, w, 32); *(w+33) = '.';
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1662
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$20
	bcc     L0A78
	inx
L0A78:	jsr     pushax
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldx     #$00
	lda     #$20
	jsr     _memcpy
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$21
	bcc     L0A7D
	inx
L0A7D:	sta     ptr1
	stx     ptr1+1
	lda     #$2E
	dey
	sta     (ptr1),y
;
; if (FatFs_fs_type == FS_FAT32 && pclust == FatFs_dirbase)
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1664
	lda     _FatFs_fs_type
	cmp     #$03
	bne     L0A7F
	ldy     #$14
	jsr     ldeaxysp
	jsr     pusheax
	lda     _FatFs_dirbase+3
	sta     sreg+1
	lda     _FatFs_dirbase+2
	sta     sreg
	ldx     _FatFs_dirbase+1
	lda     _FatFs_dirbase
	jsr     toseqeax
	beq     L0A7F
;
; pclust = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1665
	ldy     #$11
	lda     #$00
	sta     (sp),y
	iny
	sta     (sp),y
	iny
	sta     (sp),y
	iny
	sta     (sp),y
;
; ST_WORD(w+32+26, pclust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1666
L0A7F:	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$20
	bcc     L0E02
	inx
	clc
L0E02:	adc     #$1A
	bcc     L0A88
	inx
L0A88:	sta     ptr1
	stx     ptr1+1
	ldy     #$12
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (ptr1),y
	iny
	txa
	sta     (ptr1),y
;
; ST_WORD(w+32+20, pclust >> 16);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1667
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$20
	bcc     L0E03
	inx
	clc
L0E03:	adc     #$14
	bcc     L0A8E
	inx
L0A8E:	jsr     pushax
	ldy     #$16
	jsr     ldeaxysp
	ldy     #$00
	ldx     sreg+1
	lda     sreg
	jsr     staxspidx
;
; FatFs_winflag = 1;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1668
	lda     #$01
	sta     _FatFs_winflag
;
; if (!move_window(sect)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1670
	ldy     #$0E
	jsr     ldeaxysp
	jsr     pusheax
	jsr     _move_window
	tax
	bne     L0A93
	lda     #$07
	jmp     L0A33
;
; return FR_OK;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1672
L0A93:	ldx     #$00
	txa
;
; }    
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1673
L0A33:	ldy     #$15
	jmp     addysp
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ f_check_dir_empty (__near__ struct _DIR*)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_f_check_dir_empty: near

.segment	"FILESYS"

;
; dir_entry = &(FatFs_win[(lastscan->index & 15) * 32]); /* pointer to the last directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1800
	jsr     decsp6
	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0C
	lda     (ptr1),y
	ldx     #$00
	and     #$0F
	jsr     shlax4
	stx     tmp1
	asl     a
	rol     tmp1
	clc
	adc     #<(_FatFs_win)
	tay
	lda     tmp1
	adc     #>(_FatFs_win)
	tax
	tya
	ldy     #$04
	jsr     staxysp
;
; dclust = ((DWORD)LD_WORD(dir_entry+20) << 16) | LD_WORD(dir_entry+26); // start cluster of the file/dir we're looking at
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1801
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L0B80
	inx
L0B80:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	sta     sreg+1
	dey
	lda     (ptr1),y
	sta     sreg
	tya
	tax
	jsr     pusheax
	ldy     #$09
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L0B83
	inx
L0B83:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     tosor0ax
	jsr     steax0sp
;
; if (*(dir_entry+11) & AM_DIR) {     /* It is a sub-directory */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1803
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$10
	jeq     L0B90
;
; tempscan.clust = dclust;     /* Check if the sub-dir is empty or not */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1804
	jsr     ldeax0sp
	sta     _tempscan+4
	stx     _tempscan+4+1
	ldy     sreg
	sty     _tempscan+4+2
	ldy     sreg+1
	sty     _tempscan+4+3
;
; tempscan.sect = clust2sect(dclust);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1805
	jsr     ldeax0sp
	jsr     pusheax
	jsr     _clust2sect
	sta     _tempscan+8
	stx     _tempscan+8+1
	ldy     sreg
	sty     _tempscan+8+2
	ldy     sreg+1
	sty     _tempscan+8+3
;
; tempscan.index = 0;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1806
	lda     #$00
	sta     _tempscan+12
	sta     _tempscan+12+1
;
; if (!move_window(tempscan.sect)) return FR_RW_ERROR;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1808
L0B8F:	lda     _tempscan+8+3
	sta     sreg+1
	lda     _tempscan+8+2
	sta     sreg
	ldx     _tempscan+8+1
	lda     _tempscan+8
	jsr     pusheax
	jsr     _move_window
	tax
	bne     L0B92
	lda     #$07
	jmp     incsp8
;
; dir_entry = &(FatFs_win[(tempscan.index & 15) * 32]);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1809
L0B92:	lda     _tempscan+12
	ldx     #$00
	and     #$0F
	jsr     shlax4
	stx     tmp1
	asl     a
	rol     tmp1
	clc
	adc     #<(_FatFs_win)
	tay
	lda     tmp1
	adc     #>(_FatFs_win)
	tax
	tya
	ldy     #$04
	jsr     staxysp
;
; if (*dir_entry == 0) break;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1810
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	beq     L0B90
;
; if (!((*dir_entry == 0xE5) || (*dir_entry == '.')) && !(*(dir_entry+11) & AM_VOL)) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1811
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	cmp     #$E5
	beq     L0B9F
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	cmp     #$2E
	beq     L0B9F
	tya
	jmp     L0BA2
L0B9F:	lda     #$01
L0BA2:	jsr     bnega
	beq     L0B9D
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$08
	bne     L0B9D
;
; printf("dir not empty\n");
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1812
	lda     #<(L0001+4)
	ldx     #>(L0001+4)
	jsr     pushax
	ldy     #$02
	jsr     _printf
;
; return FALSE; /* The directory is not empty */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1813
	ldx     #$00
	txa
	jmp     incsp8
;
; } while (next_dir_entry(&tempscan));
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1815
L0B9D:	lda     #<(_tempscan)
	ldx     #>(_tempscan)
	jsr     pushax
	jsr     _next_dir_entry
	tax
	jne     L0B8F
;
; return TRUE;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1817
L0B90:	tax
	lda     #$01
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1818
	jmp     incsp8
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ f_remove_lfn (__near__ struct _DIR*, __near__ struct _DIR*, __near__ unsigned long*, unsigned char)
; ---------------------------------------------------------------

.segment	"FILESYS"

.proc	_f_remove_lfn: near

.segment	"FILESYS"

;
; dir_entry = &(FatFs_win[(lastscan->index & 15) * 32]); /* pointer to the last directory entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1832
	jsr     decsp7
	ldy     #$0B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$0C
	lda     (ptr1),y
	ldx     #$00
	and     #$0F
	jsr     shlax4
	stx     tmp1
	asl     a
	rol     tmp1
	clc
	adc     #<(_FatFs_win)
	tay
	lda     tmp1
	adc     #>(_FatFs_win)
	tax
	tya
	ldy     #$05
	jsr     staxysp
;
; dclust = ((DWORD)LD_WORD(dir_entry+20) << 16) | LD_WORD(dir_entry+26); // start cluster of the file/dir we're looking at
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1833
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$14
	bcc     L0BB9
	inx
L0BB9:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	sta     sreg+1
	dey
	lda     (ptr1),y
	sta     sreg
	tya
	tax
	jsr     pusheax
	ldy     #$0A
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$1A
	bcc     L0BBC
	inx
L0BBC:	sta     ptr1
	stx     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	tax
	dey
	lda     (ptr1),y
	jsr     tosor0ax
	jsr     steax0sp
;
; if (*(dir_entry+11) & AM_RDO) { //  This entry tell us the attributes
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1835
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$0B
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	and     #$01
	beq     L0BBD
;
; return FR_DENIED; /* It is a R/O item */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1836
	ldx     #$00
	lda     #$05
	jmp     L0BAE
;
; if(check_dir_empty) 
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1839
L0BBD:	ldy     #$07
	lda     (sp),y
	beq     L0BC4
;
; if(!f_check_dir_empty(lastscan))
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1840
	ldy     #$0B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	jsr     _f_check_dir_empty
	tax
	bne     L0BC4
;
; return FR_DENIED;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1841
	lda     #$05
	jmp     L0BAE
;
; while (firstscan->sect) {
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1844
L0BC4:	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	dey
	jsr     ldeaxidx
	jsr     utsteax
	jeq     L0BC9
;
; if (!move_window(firstscan->sect)) return FR_RW_ERROR;   
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1845
	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	dey
	jsr     ldeaxidx
	jsr     pusheax
	jsr     _move_window
	tax
	bne     L0BCB
	lda     #$07
	jmp     L0BAE
;
; dir_entry = &(FatFs_win[(firstscan->index & 15) * 32]);
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1846
L0BCB:	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     (ptr1),y
	ldx     #$00
	and     #$0F
	jsr     shlax4
	stx     tmp1
	asl     a
	rol     tmp1
	clc
	adc     #<(_FatFs_win)
	tay
	lda     tmp1
	adc     #>(_FatFs_win)
	tax
	tya
	ldy     #$05
	jsr     staxysp
;
; c = *dir_entry;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1847
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	ldy     #$04
	sta     (sp),y
;
; if (c == 0) break; /* Has it reached to end of dir? */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1848
	lda     (sp),y
	beq     L0BC9
;
; FatFs_winflag = 1;   
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1849
	lda     #$01
	sta     _FatFs_winflag
;
; *dir_entry = 0xE5; /* clear entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1850
	ldy     #$06
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$E5
	ldy     #$00
	sta     (ptr1),y
;
; if (memcmp(firstscan, lastscan, sizeof(DIR)) == 0) break; /* Found finished the last entry */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1852
	jsr     decsp4
	ldy     #$11
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$0F
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldx     #$00
	lda     #$0E
	jsr     _memcmp
	cpx     #$00
	bne     L0E05
	cmp     #$00
	beq     L0BC9
;
; if (!next_dir_entry(firstscan)) break; // false means end of root!!! (GZW) firstscan->sect = 0; /* Next entry */  
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1853
L0E05:	ldy     #$0D
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	jsr     _next_dir_entry
	tax
	jne     L0BC4
;
; if (!move_window(0)) return FR_RW_ERROR; /* Writeback: Mark the directory entry 'deleted' */
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1856
L0BC9:	ldx     #$00
	txa
	jsr     push0ax
	jsr     _move_window
	tax
	bne     L0BE5
	lda     #$07
	jmp     L0BAE
;
; *clust = dclust;
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1858
L0BE5:	ldy     #$09
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     pushax
	ldy     #$05
	jsr     ldeaxysp
	ldy     #$00
	jsr     steaxspidx
;
; return FR_OK;    
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1859
	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filesystem/fat/src/ff.c", 1860
L0BAE:	ldy     #$0E
	jmp     addysp
	.dbg	line

.endproc

