;
; 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/g64/g64.c", 2976, 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, "../../../data/inc/types.h", 1544, 1267200498
	.dbg		file, "../../../filesystem/fat/inc/ff.h", 11459, 1267200484
	.dbg		file, "../../../filesystem/fat/inc/dir.h", 2992, 1267200484
	.dbg		file, "../../../storage/ram/inc/mapper.h", 2486, 1267200486
	.dbg		file, "../../../data/inc/gcr.h", 1429, 1267200498
	.dbg		file, "../../../io/inc/gpio.h", 4272, 1267200496
	.import		_printf
	.import		_f_read
	.export		_load_g64
	.import		_disk_swap
	.export		_track_offsets
	.export		_read_mem

.segment	"RODATA"

L0001:
	.byte	$54,$6F,$74,$61,$6C,$20,$62,$79,$74,$65,$73,$20,$72,$65,$61,$64
	.byte	$3A,$20,$25,$6C,$64,$2E,$0A,$00,$57,$72,$6F,$6E,$67,$20,$68,$65
	.byte	$61,$64,$65,$72,$2E,$0A,$00,$53,$65,$74,$20,$74,$72,$61,$63,$6B
	.byte	$20,$25,$64,$2E,$25,$64,$20,$74,$6F,$20,$30,$78,$25,$30,$36,$6C
	.byte	$58,$20,$2F,$20,$30,$78,$25,$30,$34,$58,$2E,$0A,$00,$53,$6B,$69
	.byte	$70,$70,$69,$6E,$67,$20,$74,$72,$61,$63,$6B,$20,$25,$64,$2E,$25
	.byte	$64,$2E,$0A,$00,$44,$6F,$6E,$65,$2E,$0A,$00

.segment	"BSS"

_track_offsets:
	.res	336,$00

; ---------------------------------------------------------------
; unsigned char __near__ load_g64 (__near__ struct _FIL*, unsigned char, unsigned char)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_load_g64: near

.segment	"BSS"

L0013:
	.res	2,$00
L0014:
	.res	4,$00
L0015:
	.res	2,$00
L0016:
	.res	2,$00
L0017:
	.res	2,$00
L0018:
	.res	1,$00
L0019:
	.res	1,$00

.segment	"CODE"

;
; GPIO_SET = WRITE_PROT;
;
	.dbg	line, "../../../filetype/g64/g64.c", 56
	lda     #$04
	sta     $2000
;
; total = 0;
;
	.dbg	line, "../../../filetype/g64/g64.c", 57
	lda     #$00
	sta     L0014
	sta     L0014+1
	sta     L0014+2
	sta     L0014+3
;
; for(w=GCR_ADDR;w<GCR_END_ADDR;w++) {
;
	.dbg	line, "../../../filetype/g64/g64.c", 59
	ldx     #$10
	lda     #$20
L009F:	sta     L0013
	stx     L0013+1
	lda     L0013+1
	cmp     #$10
	bne     L0026
	lda     L0013
	cmp     #$78
L0026:	bcs     L0020
;
; MAPPER_MAP1 = w;
;
	.dbg	line, "../../../filetype/g64/g64.c", 60
	lda     L0013
	sta     $2300
	lda     L0013+1
	sta     $2300+1
;
; fres = f_read(fp, (void *)0x4000, 8192, &bytes_read);
;
	.dbg	line, "../../../filetype/g64/g64.c", 61
	jsr     decsp8
	ldy     #$0B
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$06
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	lda     #$00
	ldy     #$04
	sta     (sp),y
	iny
	lda     #$40
	sta     (sp),y
	lda     #$00
	ldy     #$02
	sta     (sp),y
	iny
	lda     #$20
	sta     (sp),y
	lda     #<(L0015)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(L0015)
	sta     (sp),y
	jsr     _f_read
	sta     L0019
;
; total += bytes_read;
;
	.dbg	line, "../../../filetype/g64/g64.c", 62
	lda     L0015
	ldx     L0015+1
	ldy     #$00
	sty     sreg
	sty     sreg+1
	ldy     #<(L0014)
	sty     ptr1
	ldy     #>(L0014)
	jsr     laddeq
;
; if(bytes_read != 8192)
;
	.dbg	line, "../../../filetype/g64/g64.c", 63
	lda     L0015+1
	cmp     #$20
	bne     L0020
	lda     L0015
;
; break;
;
	.dbg	line, "../../../filetype/g64/g64.c", 64
	bne     L0020
;
; for(w=GCR_ADDR;w<GCR_END_ADDR;w++) {
;
	.dbg	line, "../../../filetype/g64/g64.c", 59
	lda     L0013
	ldx     L0013+1
	clc
	adc     #$01
	jcc     L009F
	inx
	jmp     L009F
;
; printf("Total bytes read: %ld.\n", total);
;
	.dbg	line, "../../../filetype/g64/g64.c", 66
L0020:	lda     #<(L0001)
	ldx     #>(L0001)
	jsr     pushax
	lda     L0014+3
	sta     sreg+1
	lda     L0014+2
	sta     sreg
	ldx     L0014+1
	lda     L0014
	jsr     pusheax
	ldy     #$06
	jsr     _printf
;
; MAPPER_MAP1 = GCR_ADDR;
;
	.dbg	line, "../../../filetype/g64/g64.c", 69
	ldx     #$10
	lda     #$20
	sta     $2300
	stx     $2300+1
;
; pul = (ULONG *)0x4000;
;
	.dbg	line, "../../../filetype/g64/g64.c", 70
	ldx     #$40
	lda     #$00
	sta     L0016
	stx     L0016+1
;
; if((pul[0] != 0x2D524347)||(pul[1] != 0x31343531)) { // little endianness assumed
;
	.dbg	line, "../../../filetype/g64/g64.c", 71
	jsr     ldeaxi
	jsr     pusheax
	ldx     #$43
	lda     #$52
	sta     sreg
	lda     #$2D
	sta     sreg+1
	lda     #$47
	jsr     tosneeax
	bne     L0040
	lda     L0016
	ldx     L0016+1
	ldy     #$07
	jsr     ldeaxidx
	jsr     pusheax
	ldx     #$35
	lda     #$34
	sta     sreg
	lda     #$31
	sta     sreg+1
	jsr     tosneeax
	beq     L003F
;
; printf("Wrong header.\n");
;
	.dbg	line, "../../../filetype/g64/g64.c", 72
L0040:	lda     #<(L0001+24)
	ldx     #>(L0001+24)
	jsr     pushax
	ldy     #$02
	jsr     _printf
;
; return 0;
;
	.dbg	line, "../../../filetype/g64/g64.c", 73
	ldx     #$00
	txa
	jmp     incsp4
;
; param = (ULONG *)PARAM_BASE;
;
	.dbg	line, "../../../filetype/g64/g64.c", 76
L003F:	ldx     #$2C
	lda     #$00
	sta     L0017
	stx     L0017+1
;
; for(b=0;b<84;b++) {
;
	.dbg	line, "../../../filetype/g64/g64.c", 80
L009D:	sta     L0018
	cmp     #$54
	jcs     L004C
;
; track_offsets[b] = pul[b+3] + (GCR_ADDR << 13);
;
	.dbg	line, "../../../filetype/g64/g64.c", 81
	ldx     #$00
	lda     L0018
	jsr     aslax2
	clc
	adc     #<(_track_offsets)
	tay
	txa
	adc     #>(_track_offsets)
	tax
	tya
	jsr     pushax
	ldx     #$00
	lda     L0018
	clc
	adc     #$03
	bcc     L0057
	inx
L0057:	jsr     aslax2
	clc
	adc     L0016
	pha
	txa
	adc     L0016+1
	tax
	pla
	jsr     ldeaxi
	jsr     pusheax
	ldx     #$00
	lda     #$04
	sta     sreg
	lda     #$02
	sta     sreg+1
	txa
	jsr     tosaddeax
	ldy     #$00
	jsr     steaxspidx
;
; param[b<<1] = track_offsets[b] + 2;
;
	.dbg	line, "../../../filetype/g64/g64.c", 82
	ldx     #$00
	lda     L0018
	asl     a
	bcc     L0098
	inx
L0098:	jsr     aslax2
	clc
	adc     L0017
	pha
	txa
	adc     L0017+1
	tax
	pla
	jsr     pushax
	ldx     #$00
	lda     L0018
	jsr     aslax2
	clc
	adc     #<(_track_offsets)
	tay
	txa
	adc     #>(_track_offsets)
	tax
	tya
	jsr     ldeaxi
	ldy     #$02
	jsr     inceaxy
	ldy     #$00
	jsr     steaxspidx
;
; for(b=0;b<84;b++) {
;
	.dbg	line, "../../../filetype/g64/g64.c", 80
	lda     L0018
	clc
	adc     #$01
	jmp     L009D
;
; for(b=0;b<84;b++) {
;
	.dbg	line, "../../../filetype/g64/g64.c", 84
L004C:	lda     #$00
L009E:	sta     L0018
	cmp     #$54
	jcs     L005E
;
; if(track_offsets[b] != (GCR_ADDR << 13)) {
;
	.dbg	line, "../../../filetype/g64/g64.c", 86
	ldx     #$00
	lda     L0018
	jsr     aslax2
	clc
	adc     #<(_track_offsets)
	tay
	txa
	adc     #>(_track_offsets)
	tax
	tya
	jsr     ldeaxi
	jsr     pusheax
	ldx     #$00
	lda     #$04
	sta     sreg
	lda     #$02
	sta     sreg+1
	txa
	jsr     tosneeax
	jeq     L0065
;
; w = read_mem(track_offsets[b]);
;
	.dbg	line, "../../../filetype/g64/g64.c", 87
	ldx     #$00
	lda     L0018
	jsr     aslax2
	clc
	adc     #<(_track_offsets)
	tay
	txa
	adc     #>(_track_offsets)
	tax
	tya
	jsr     ldeaxi
	jsr     pusheax
	jsr     _read_mem
	ldx     #$00
	sta     L0013
	stx     L0013+1
;
; w |= ((WORD)read_mem(track_offsets[b]+1)) << 8;
;
	.dbg	line, "../../../filetype/g64/g64.c", 88
	jsr     pusha0
	lda     L0018
	jsr     aslax2
	clc
	adc     #<(_track_offsets)
	tay
	txa
	adc     #>(_track_offsets)
	tax
	tya
	jsr     ldeaxi
	ldy     #$01
	jsr     inceaxy
	jsr     pusheax
	jsr     _read_mem
	tax
	lda     #$00
	jsr     tosorax
	sta     L0013
	stx     L0013+1
;
; printf("Set track %d.%d to 0x%06lX / 0x%04X.\n", (b>>1)+1, (b&1)?5:0, track_offsets[b] + 2, w);
;
	.dbg	line, "../../../filetype/g64/g64.c", 89
	lda     #<(L0001+39)
	ldx     #>(L0001+39)
	jsr     pushax
	ldx     #$00
	lda     L0018
	jsr     asrax1
	clc
	adc     #$01
	bcc     L0076
	inx
L0076:	jsr     pushax
	lda     L0018
	and     #$01
	beq     L007B
	lda     #$05
	jmp     L007B
L007B:	jsr     pusha0
	lda     L0018
	jsr     aslax2
	clc
	adc     #<(_track_offsets)
	tay
	txa
	adc     #>(_track_offsets)
	tax
	tya
	jsr     ldeaxi
	ldy     #$02
	jsr     inceaxy
	jsr     pusheax
	lda     L0013
	ldx     L0013+1
	jsr     pushax
	ldy     #$0C
;
; } else {
;
	.dbg	line, "../../../filetype/g64/g64.c", 90
	jmp     L009A
;
; printf("Skipping track %d.%d.\n", (b>>1)+1, (b&1)?5:0);
;
	.dbg	line, "../../../filetype/g64/g64.c", 91
L0065:	lda     #<(L0001+77)
	ldx     #>(L0001+77)
	jsr     pushax
	ldx     #$00
	lda     L0018
	jsr     asrax1
	clc
	adc     #$01
	bcc     L0085
	inx
L0085:	jsr     pushax
	lda     L0018
	and     #$01
	beq     L008A
	lda     #$05
	jmp     L008A
L008A:	jsr     pusha0
	ldy     #$06
L009A:	jsr     _printf
;
; param[(b<<1) + 1] = w - 1;
;
	.dbg	line, "../../../filetype/g64/g64.c", 93
	ldx     #$00
	lda     L0018
	asl     a
	bcc     L009B
	inx
	clc
L009B:	adc     #$01
	bcc     L008F
	inx
L008F:	jsr     aslax2
	clc
	adc     L0017
	pha
	txa
	adc     L0017+1
	tax
	pla
	jsr     pushax
	lda     L0013
	ldx     L0013+1
	sec
	sbc     #$01
	bcs     L0091
	dex
L0091:	ldy     #$00
	sty     sreg
	sty     sreg+1
	jsr     steaxspidx
;
; for(b=0;b<84;b++) {
;
	.dbg	line, "../../../filetype/g64/g64.c", 84
	lda     L0018
	clc
	adc     #$01
	jmp     L009E
;
; printf("Done.\n");
;
	.dbg	line, "../../../filetype/g64/g64.c", 95
L005E:	lda     #<(L0001+100)
	ldx     #>(L0001+100)
	jsr     pushax
	ldy     #$02
	jsr     _printf
;
; disk_swap(wp, delay);
;
	.dbg	line, "../../../filetype/g64/g64.c", 97
	jsr     decsp2
	ldy     #$03
	lda     (sp),y
	ldy     #$01
	sta     (sp),y
	iny
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	jsr     _disk_swap
;
; return 1;
;
	.dbg	line, "../../../filetype/g64/g64.c", 98
	ldx     #$00
	lda     #$01
;
; }
;
	.dbg	line, "../../../filetype/g64/g64.c", 99
	jmp     incsp4
	.dbg	line

.endproc

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

.segment	"CODE"

.proc	_read_mem: near

.segment	"CODE"

;
; MAPPER_MAP1 = (WORD)(address >> 13);
;
	.dbg	line, "../../../filetype/g64/g64.c", 40
	jsr     ldeax0sp
	txa
	ldx     sreg
	ldy     sreg+1
	sty     sreg
	ldy     #$00
	sty     sreg+1
	jsr     shreax4
	jsr     shreax1
	sta     $2300
	stx     $2300+1
;
; return *((BYTE *)(MAP1_ADDR + (address & 0x1FFF)));
;
	.dbg	line, "../../../filetype/g64/g64.c", 41
	jsr     ldeax0sp
	jsr     pusheax
	ldx     #$1F
	lda     #$00
	lda     #$FF
	jsr     tosand0ax
	jsr     pusheax
	ldx     #$40
	lda     #$00
	jsr     tosadd0ax
	sta     ptr1
	stx     ptr1+1
	ldx     #$00
	lda     (ptr1,x)
;
; }
;
	.dbg	line, "../../../filetype/g64/g64.c", 42
	jmp     incsp4
	.dbg	line

.endproc

