;
; 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, "../../../filetype/tap/src/tap.c", 1719, 1267200478
	.dbg		file, "C:\Programme\cc65\include/stdio.h", 5964, 1262467470
	.dbg		file, "C:\Programme\cc65\include/stddef.h", 2972, 1262467470
	.dbg		file, "C:\Programme\cc65\include/stdarg.h", 2817, 1262467470
	.dbg		file, "C:\Programme\cc65\include/stdlib.h", 5578, 1262467470
	.dbg		file, "C:\Programme\cc65\include/string.h", 4883, 1262467470
	.dbg		file, "../../../filetype/tap/inc/tap.h", 141, 1267200478
	.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/c2n.h", 1275, 1267200496
	.dbg		file, "../../../system/inc/c64_addr.h", 2168, 1267200486
	.dbg		file, "../../../storage/ram/inc/mapper.h", 2486, 1267200486
	.dbg		file, "../../../io/inc/uart.h", 1541, 1267200496
	.import		_printf
	.import		_strncmp
	.import		_memset
	.import		_f_open_direct
	.import		_f_read
	.import		_f_close
	.export		_tap_open_file
	.export		_tap_stream
	.export		_tap_file
	.export		_tap_header
	.export		_next_block

.segment	"DATA"

_next_block:
	.word	$0000

.segment	"RODATA"

L0001:
	.byte	$43,$36,$34,$2D,$54,$41,$50,$45,$2D,$52,$41,$00,$4E,$6F,$74,$20
	.byte	$61,$20,$63,$6F,$72,$72,$65,$63,$74,$20,$68,$65,$61,$64,$65,$72
	.byte	$2E,$20,$25,$73,$0A,$00,$54,$41,$50,$20,$56,$65,$72,$73,$69,$6F
	.byte	$6E,$20,$3D,$20,$25,$64,$2E,$0A,$00,$43,$61,$6E,$27,$74,$20,$6F
	.byte	$70,$65,$6E,$20,$66,$69,$6C,$65,$2E,$0A,$00

.segment	"BSS"

_tap_file:
	.res	540,$00
_tap_header:
	.res	20,$00

; ---------------------------------------------------------------
; unsigned char __near__ tap_open_file (__near__ struct _DIRENTRY*)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_tap_open_file: near

.segment	"CODE"

;
; f_close(&tap_file);
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 28
	jsr     decsp3
	lda     #<(_tap_file)
	ldx     #>(_tap_file)
	jsr     pushax
	jsr     _f_close
;
; C2N_CONTROL = C2N_ERROR; // clear error
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 29
	lda     #$02
	sta     $2400
;
; fres = f_open_direct(&tap_file, entry);
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 31
	jsr     decsp4
	lda     #<(_tap_file)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_tap_file)
	sta     (sp),y
	ldy     #$08
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _f_open_direct
	ldy     #$02
	sta     (sp),y
;
; if(fres == FR_OK) {
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 32
	lda     (sp),y
	jne     L0013
;
; memset(&tap_header, 0, 20);
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 33
	ldy     #$13
L0019:	sta     _tap_header,y
	dey
	bpl     L0019
;
; fres = f_read(&tap_file, (void *)&tap_header, 20, &br);
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 34
	jsr     decsp8
	lda     #<(_tap_file)
	ldy     #$06
	sta     (sp),y
	iny
	lda     #>(_tap_file)
	sta     (sp),y
	lda     #<(_tap_header)
	ldy     #$04
	sta     (sp),y
	iny
	lda     #>(_tap_header)
	sta     (sp),y
	lda     #$14
	ldy     #$02
	sta     (sp),y
	iny
	lda     #$00
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$08
	bcc     L0020
	inx
L0020:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _f_read
	ldy     #$02
	sta     (sp),y
;
; tap_header.id_string[11]=0;
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 35
	lda     #$00
	sta     _tap_header+11
;
; if(strncmp(tap_header.id_string, "C64-TAPE-RA", 11)) {
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 36
	jsr     decsp4
	lda     #<(_tap_header)
	sta     (sp),y
	iny
	lda     #>(_tap_header)
	sta     (sp),y
	lda     #<(L0001)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(L0001)
	sta     (sp),y
	ldx     #$00
	lda     #$0B
	jsr     _strncmp
	stx     tmp1
	ora     tmp1
	beq     L0024
;
; printf("Not a correct header. %s\n", tap_header.id_string);
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 37
	lda     #<(L0001+12)
	ldx     #>(L0001+12)
	jsr     pushax
	lda     #<(_tap_header)
	ldx     #>(_tap_header)
	jsr     pushax
	ldy     #$04
;
; return FALSE;
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 38
	jmp     L005F
;
; printf("TAP Version = %d.\n", tap_header.version);
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 40
L0024:	lda     #<(L0001+38)
	ldx     #>(L0001+38)
	jsr     pushax
	lda     _tap_header+12
	jsr     pusha0
	ldy     #$04
	jsr     _printf
;
; next_block = 512 - 20;
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 41
	ldx     #$01
	lda     #$EC
	sta     _next_block
	stx     _next_block+1
;
; } else {
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 42
	jmp     incsp5
;
; printf("Can't open file.\n");
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 43
L0013:	lda     #<(L0001+57)
	ldx     #>(L0001+57)
	jsr     pushax
	ldy     #$02
L005F:	jsr     _printf
;
; return FALSE;
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 44
	ldx     #$00
	txa
;
; }
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 47
	jmp     incsp5
	.dbg	line

.endproc

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

.segment	"CODE"

.proc	_tap_stream: near

.segment	"CODE"

;
; if(!next_block)
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 55
	jsr     decsp4
	lda     _next_block
	ora     _next_block+1
	bne     L0037
;
; return FALSE;
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 56
	tax
	jmp     incsp4
;
; st = C2N_STATUS;
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 58
L0037:	lda     $2400
	ldy     #$03
	sta     (sp),y
;
; if(!(st & C2N_FIFO_ALMOSTFULL)) {
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 59
	and     #$08
	bne     L003D
;
; fres = f_read(&tap_file, (void *)C2N_FIFO_ADDR, next_block, &br);
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 60
	jsr     decsp8
	lda     #<(_tap_file)
	ldy     #$06
	sta     (sp),y
	iny
	lda     #>(_tap_file)
	sta     (sp),y
	lda     #$00
	ldy     #$04
	sta     (sp),y
	iny
	lda     #$26
	sta     (sp),y
	lda     _next_block
	ldy     #$02
	sta     (sp),y
	iny
	lda     _next_block+1
	sta     (sp),y
	lda     sp
	ldx     sp+1
	clc
	adc     #$08
	bcc     L0046
	inx
L0046:	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _f_read
	ldy     #$02
	sta     (sp),y
;
; UART_DATA = '>';
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 61
	lda     #$3E
	sta     $2100
;
; if(fres == FR_OK) {
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 62
	lda     (sp),y
	bne     L004A
;
; if(br) {
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 63
	dey
	lda     (sp),y
	dey
	ora     (sp),y
	beq     L004C
;
; next_block = 512;
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 64
	ldx     #$02
	sty     _next_block
	stx     _next_block+1
;
; } else {
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 65
	jmp     L0058
;
; next_block = 0; // stop streaming
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 66
L004C:	tax
	sta     _next_block
	sta     _next_block+1
;
; return FALSE;
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 67
	jmp     incsp4
;
; next_block = 0;
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 70
L004A:	ldx     #$00
	txa
	sta     _next_block
	sta     _next_block+1
;
; return FALSE;
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 71
	jmp     incsp4
;
; C2N_CONTROL = C2N_ENABLE;
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 74
L003D:	lda     #$01
	sta     $2400
;
; return TRUE;
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 76
L0058:	ldx     #$00
	lda     #$01
;
; }
;
	.dbg	line, "../../../filetype/tap/src/tap.c", 77
	jmp     incsp4
	.dbg	line

.endproc

