;
; 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, "../../../application/ultimate/src/main_loop.c", 13448, 1267200480
	.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, "../../../ui/inc/c64_menu.h", 1936, 1267200498
	.dbg		file, "../../../data/inc/types.h", 1544, 1267200498
	.dbg		file, "../../../io/inc/spi.h", 1305, 1267200496
	.dbg		file, "../../../io/inc/sd.h", 1808, 1267200496
	.dbg		file, "../../../filesystem/fat/inc/ff.h", 11459, 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
	.dbg		file, "../../../io/inc/uart.h", 1541, 1267200496
	.dbg		file, "../../../io/inc/iec.h", 1159, 1267200496
	.dbg		file, "../../../io/inc/keyb.h", 1109, 1267200496
	.dbg		file, "../../../ui/inc/freezer.h", 1398, 1267200498
	.dbg		file, "../../../io/inc/screen.h", 1493, 1267200496
	.dbg		file, "../../../system/inc/soft_signal.h", 1293, 1267200486
	.dbg		file, "../../../filesystem/fat/inc/dir.h", 2992, 1267200484
	.dbg		file, "../../../system/inc/c64_irq.h", 1127, 1267200486
	.dbg		file, "../../../system/inc/copper.h", 1146, 1267200486
	.dbg		file, "../../../debug/inc/trace.h", 970, 1267200486
	.dbg		file, "../../../storage/ram/inc/mem_tools.h", 1350, 1267200486
	.dbg		file, "../../../storage/flash/inc/flash.h", 1349, 1267200486
	.dbg		file, "../../../io/inc/1541.h", 1342, 1267200496
	.dbg		file, "../../../filetype/d64/inc/d64.h", 1475, 1267200478
	.dbg		file, "../../../debug/inc/dump_hex.h", 1030, 1267200486
	.dbg		file, "../../../io/inc/diskio.h", 2164, 1267200496
	.dbg		file, "../../../ui/inc/config.h", 2554, 1267200498
	.dbg		file, "../../../io/inc/buttons.h", 1110, 1267200496
	.dbg		file, "../../../filetype/tap/inc/tap.h", 141, 1267200478
	.import		_printf
	.import		_do_scroller
	.import		_menu_init
	.import		_menu_run
	.export		_sal_handle_up
	.export		_sal_handle_select
	.import		_check_sd
	.import		_card_change
	.import		_card_det
	.import		_f_open_direct
	.import		_f_close
	.import		_f_mountdrv
	.import		_f_sync
	.import		_load_d64
	.import		_load_g64
	.import		_uart_write_buffer
	.import		_iec_init
	.import		_iec_poll
	.import		_iec_dir_down
	.import		_iec_dir_up
	.import		_scan_keyboard
	.import		_init_freeze
	.import		_Signals
	.import		_dir_getentry
	.import		_soft_irq
	.import		_ClearFloppyMem
	.import		_d64_write_track
	.import		_cfg_get_value
	.import		_read_buttons
	.import		_clear_button_event
	.import		_button_event
	.import		_button_hold
	.import		_tap_stream
	.export		_current_drv
	.export		_enable_drv
	.import		_mountfile
	.import		_disk_change
	.import		_stand_alone
	.export		_frozen
	.export		_set_drive
	.export		_do_menu
	.export		_irq_handler
	.export		_write
	.export		_writeback_poll
	.export		_main_check_sd_change
	.export		_main_loop
	.import		_iec_dir_cache
	.import		_iec_dir_depth
	.export		_sal_index_trace
	.export		_sal_dir_index
	.export		_sal_handle_left
	.export		_sal_handle_begin
	.export		_sal_handle_right
	.export		_sal_handle_end
	.export		_stand_alone_loop

.segment	"DATA"

_frozen:
	.byte	$00

.segment	"RODATA"

L0001:
	.byte	$53,$65,$74,$20,$64,$72,$69,$76,$65,$20,$63,$61,$6C,$6C,$65,$64
	.byte	$2E,$0A,$00,$45,$6E,$61,$62,$6C,$65,$64,$20,$64,$72,$69,$76,$65
	.byte	$20,$61,$74,$20,$25,$64,$2E,$0A,$00,$45,$72,$72,$6F,$72,$2E,$2E
	.byte	$20,$6D,$6F,$75,$6E,$74,$20,$66,$69,$6C,$65,$20,$73,$65,$65,$6D
	.byte	$73,$20,$74,$6F,$20,$62,$65,$20,$63,$6C,$6F,$73,$65,$64,$2E,$0A
	.byte	$00,$57,$72,$69,$74,$69,$6E,$67,$20,$62,$61,$63,$6B,$20,$74,$72
	.byte	$61,$63,$6B,$20,$25,$64,$2E,$0A,$00,$45,$72,$72,$6F,$72,$20,$73
	.byte	$79,$6E,$63,$69,$6E,$67,$20,$66,$69,$6C,$65,$2E,$0A,$00,$43,$61
	.byte	$72,$64,$20,$72,$65,$6D,$6F,$76,$65,$64,$2C,$20,$63,$6C,$65,$61
	.byte	$72,$69,$6E,$67,$20,$66,$6C,$6F,$70,$70,$79,$20,$6D,$65,$6D,$6F
	.byte	$72,$79,$2E,$0A,$00,$48,$61,$6E,$64,$6C,$65,$20,$6C,$65,$66,$74
	.byte	$2E,$20,$73,$61,$6C,$20,$49,$6E,$64,$65,$78,$20,$3D,$20,$25,$64
	.byte	$2F,$25,$64,$2E,$0A,$00,$73,$61,$6C,$20,$49,$6E,$64,$65,$78,$20
	.byte	$3D,$20,$25,$64,$2E,$20,$28,$25,$73,$29,$0A,$00,$48,$61,$6E,$64
	.byte	$6C,$65,$20,$62,$65,$67,$69,$6E,$2E,$20,$73,$61,$6C,$20,$49,$6E
	.byte	$64,$65,$78,$20,$3D,$20,$25,$64,$2F,$25,$64,$2E,$0A,$00,$73,$61
	.byte	$6C,$20,$49,$6E,$64,$65,$78,$20,$3D,$20,$25,$64,$2E,$20,$28,$25
	.byte	$73,$29,$0A,$00,$48,$61,$6E,$64,$6C,$65,$20,$72,$69,$67,$68,$74
	.byte	$2E,$20,$73,$61,$6C,$20,$49,$6E,$64,$65,$78,$20,$3D,$20,$25,$64
	.byte	$2F,$25,$64,$2E,$0A,$00,$73,$61,$6C,$20,$49,$6E,$64,$65,$78,$20
	.byte	$3D,$20,$25,$64,$2E,$20,$28,$25,$73,$29,$0A,$00,$48,$61,$6E,$64
	.byte	$6C,$65,$20,$65,$6E,$64,$2E,$20,$73,$61,$6C,$20,$49,$6E,$64,$65
	.byte	$78,$20,$3D,$20,$25,$64,$2F,$25,$64,$2E,$0A,$00,$73,$61,$6C,$20
	.byte	$49,$6E,$64,$65,$78,$20,$3D,$20,$25,$64,$2E,$20,$28,$25,$73,$29
	.byte	$0A,$00,$54,$72,$79,$69,$6E,$67,$20,$74,$6F,$20,$65,$6E,$74,$65
	.byte	$72,$20,$25,$73,$2E,$20,$44,$65,$70,$74,$68,$20,$3D,$20,$25,$64
	.byte	$0A,$00,$4E,$75,$6D,$62,$65,$72,$20,$6F,$66,$20,$74,$72,$61,$63
	.byte	$6B,$73,$20,$72,$65,$61,$64,$3A,$20,$25,$64,$0A,$00,$41,$66,$74
	.byte	$65,$72,$20,$65,$6E,$74,$65,$72,$3A,$20,$44,$65,$70,$74,$68,$20
	.byte	$3D,$20,$25,$64,$2E,$20,$53,$61,$6C,$20,$69,$6E,$64,$65,$78,$20
	.byte	$3D,$20,$25,$64,$2E,$0A,$00,$48,$61,$6E,$64,$6C,$65,$20,$64,$69
	.byte	$72,$65,$63,$74,$6F,$72,$79,$20,$75,$70,$2E,$2E,$0A,$00,$41,$66
	.byte	$74,$65,$72,$20,$75,$70,$3A,$20,$44,$65,$70,$74,$68,$20,$3D,$20
	.byte	$25,$64,$2E,$20,$53,$61,$6C,$20,$69,$6E,$64,$65,$78,$20,$3D,$20
	.byte	$25,$64,$2E,$20,$28,$25,$73,$29,$0A,$00,$49,$45,$43,$20,$61,$64
	.byte	$64,$72,$65,$73,$73,$3A,$20,$25,$64,$0A,$00

.segment	"BSS"

_current_drv:
	.res	1,$00
_enable_drv:
	.res	1,$00
_reinit_iec:
	.res	1,$00
_sal_index_trace:
	.res	24,$00
_sal_dir_index:
	.res	2,$00

; ---------------------------------------------------------------
; void __near__ sal_handle_up (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_sal_handle_up: near

.segment	"BSS"

L01F5:
	.res	2,$00

.segment	"CODE"

;
; printf("Handle directory up..\n");
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 399
	lda     #<(L0001+487)
	ldx     #>(L0001+487)
	jsr     pushax
	ldy     #$02
	jsr     _printf
;
; iec_dir_up();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 400
	jsr     _iec_dir_up
;
; sal_dir_index = sal_index_trace[iec_dir_depth];
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 402
	ldx     #$00
	lda     _iec_dir_depth
	asl     a
	bcc     L0269
	inx
	clc
L0269:	adc     #<(_sal_index_trace)
	sta     ptr1
	txa
	adc     #>(_sal_index_trace)
	sta     ptr1+1
	ldy     #$01
	lda     (ptr1),y
	sta     _sal_dir_index+1
	dey
	lda     (ptr1),y
	sta     _sal_dir_index
;
; entry = dir_getentry(sal_dir_index, &iec_dir_cache);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 404
	jsr     decsp4
	lda     _sal_dir_index
	ldy     #$02
	sta     (sp),y
	iny
	lda     _sal_dir_index+1
	sta     (sp),y
	lda     #<(_iec_dir_cache)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(_iec_dir_cache)
	sta     (sp),y
	jsr     _dir_getentry
	sta     L01F5
	stx     L01F5+1
;
; printf("After up: Depth = %d. Sal index = %d. (%s)\n", iec_dir_depth, sal_dir_index, entry->fname);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 405
	lda     #<(L0001+510)
	ldx     #>(L0001+510)
	jsr     pushax
	lda     _iec_dir_depth
	jsr     pusha0
	lda     _sal_dir_index
	ldx     _sal_dir_index+1
	jsr     pushax
	lda     L01F5
	ldx     L01F5+1
	clc
	adc     #$0A
	bcc     L0205
	inx
L0205:	jsr     pushax
	ldy     #$08
	jmp     _printf
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ sal_handle_select (unsigned char)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_sal_handle_select: near

.segment	"BSS"

L01B9:
	.res	2,$00

.segment	"CODE"

;
; entry = dir_getentry(sal_dir_index, &iec_dir_cache);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 366
	jsr     decsp3
	jsr     decsp4
	lda     _sal_dir_index
	ldy     #$02
	sta     (sp),y
	iny
	lda     _sal_dir_index+1
	sta     (sp),y
	lda     #<(_iec_dir_cache)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(_iec_dir_cache)
	sta     (sp),y
	jsr     _dir_getentry
	sta     L01B9
	stx     L01B9+1
;
; printf("Trying to enter %s. Depth = %d\n", entry->fname, iec_dir_depth);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 367
	lda     #<(L0001+386)
	ldx     #>(L0001+386)
	jsr     pushax
	lda     L01B9
	ldx     L01B9+1
	clc
	adc     #$0A
	bcc     L01C1
	inx
L01C1:	jsr     pushax
	lda     _iec_dir_depth
	jsr     pusha0
	ldy     #$06
	jsr     _printf
;
; sal_index_trace[iec_dir_depth] = sal_dir_index;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 369
	ldx     #$00
	lda     _iec_dir_depth
	asl     a
	bcc     L026B
	inx
	clc
L026B:	adc     #<(_sal_index_trace)
	sta     ptr1
	txa
	adc     #>(_sal_index_trace)
	sta     ptr1+1
	lda     _sal_dir_index
	ldy     #$00
	sta     (ptr1),y
	iny
	lda     _sal_dir_index+1
	sta     (ptr1),y
;
; delay = (BYTE)cfg_get_value(CFG_SWAP_DELAY);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 371
	lda     #$16
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$00
	sta     (sp),y
;
; switch(entry->ftype) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 372
	lda     L01B9
	sta     ptr1
	lda     L01B9+1
	sta     ptr1+1
	ldy     #$09
	lda     (ptr1),y
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 388
	cmp     #$02
	beq     L01CD
	cmp     #$0C
	beq     L01DF
	jmp     L01EC
;
; f_close(&mountfile);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 374
L01CD:	lda     #<(_mountfile)
	ldx     #>(_mountfile)
	jsr     pushax
	jsr     _f_close
;
; f_open_direct(&mountfile, entry);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 375
	jsr     decsp4
	lda     #<(_mountfile)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_mountfile)
	sta     (sp),y
	lda     L01B9
	ldy     #$00
	sta     (sp),y
	iny
	lda     L01B9+1
	sta     (sp),y
	jsr     _f_open_direct
;
; wp = (BYTE)(entry->fattrib & AM_RDO);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 376
	lda     L01B9
	sta     ptr1
	lda     L01B9+1
	sta     ptr1+1
	ldy     #$08
	lda     (ptr1),y
	and     #$01
	ldy     #$02
	sta     (sp),y
;
; tr = load_d64(&mountfile, wp, delay);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 377
	jsr     decsp4
	lda     #<(_mountfile)
	sta     (sp),y
	iny
	lda     #>(_mountfile)
	sta     (sp),y
	ldy     #$06
	lda     (sp),y
	ldy     #$01
	sta     (sp),y
	ldy     #$04
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	jsr     _load_d64
	ldy     #$01
	sta     (sp),y
;
; printf("Number of tracks read: %d\n", tr);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 378
	lda     #<(L0001+418)
	ldx     #>(L0001+418)
	jsr     pushax
	ldy     #$03
	lda     (sp),y
	jsr     pusha0
	ldy     #$04
	jsr     _printf
;
; break;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 379
	jmp     L01CB
;
; f_close(&mountfile);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 381
L01DF:	lda     #<(_mountfile)
	ldx     #>(_mountfile)
	jsr     pushax
	jsr     _f_close
;
; f_open_direct(&mountfile, entry);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 382
	jsr     decsp4
	lda     #<(_mountfile)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_mountfile)
	sta     (sp),y
	lda     L01B9
	ldy     #$00
	sta     (sp),y
	iny
	lda     L01B9+1
	sta     (sp),y
	jsr     _f_open_direct
;
; wp = (BYTE)(entry->fattrib & AM_RDO);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 383
	lda     L01B9
	sta     ptr1
	lda     L01B9+1
	sta     ptr1+1
	ldy     #$08
	lda     (ptr1),y
	and     #$01
	ldy     #$02
	sta     (sp),y
;
; load_g64(&mountfile, wp, delay);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 384
	jsr     decsp4
	lda     #<(_mountfile)
	sta     (sp),y
	iny
	lda     #>(_mountfile)
	sta     (sp),y
	ldy     #$06
	lda     (sp),y
	ldy     #$01
	sta     (sp),y
	ldy     #$04
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	jsr     _load_g64
;
; break;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 385
	jmp     L01CB
;
; iec_dir_down(entry);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 387
L01EC:	lda     L01B9
	ldx     L01B9+1
	jsr     pushax
	jsr     _iec_dir_down
;
; printf("After enter: Depth = %d. Sal index = %d.\n", iec_dir_depth, sal_dir_index);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 390
L01CB:	lda     #<(L0001+445)
	ldx     #>(L0001+445)
	jsr     pushax
	lda     _iec_dir_depth
	jsr     pusha0
	lda     _sal_dir_index
	ldx     _sal_dir_index+1
	jsr     pushax
	ldy     #$06
	jsr     _printf
;
; return TRUE;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 392
	ldx     #$00
	lda     #$01
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 393
	jmp     incsp4
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ set_drive (unsigned char, unsigned char)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_set_drive: near

.segment	"CODE"

;
; current_drv = addr;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 69
	ldy     #$01
	lda     (sp),y
	sta     _current_drv
;
; enable_drv = en;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 70
	dey
	lda     (sp),y
	sta     _enable_drv
;
; printf("Set drive called.\n");
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 71
	lda     #<(L0001)
	ldx     #>(L0001)
	jsr     pushax
	ldy     #$02
	jsr     _printf
;
; GPIO_CLEAR  = DRIVE_ADDR_MASK;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 73
	lda     #$03
	sta     $2001
;
; GPIO_SET    = ((addr&0x3) << DRIVE_ADDR_BIT);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 74
	ldy     #$01
	lda     (sp),y
	and     #$03
	sta     $2000
;
; GPIO_SET2   = DRIVE_RESET;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 75
	lda     #$40
	sta     $2006
;
; if(en) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 76
	dey
	lda     (sp),y
	jeq     incsp2
;
; DELAY5US(2);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 77
	lda     #$02
	sta     $2004
L0024:	lda     $2004
	bne     L0024
;
; GPIO_CLEAR2 = DRIVE_RESET;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 78
	lda     #$40
	sta     $2007
;
; printf("Enabled drive at %d.\n", addr);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 79
	lda     #<(L0001+19)
	ldx     #>(L0001+19)
	jsr     pushax
	ldy     #$03
	lda     (sp),y
	jsr     pusha0
	ldy     #$04
	jsr     _printf
;
; } 
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 81
	jmp     incsp2
	.dbg	line

.endproc

; ---------------------------------------------------------------
; unsigned char __near__ do_menu (unsigned char)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_do_menu: near

.segment	"BSS"

L002F:
	.res	1,$00

.segment	"CODE"

;
; GPIO_IMASK = 0;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 88
	lda     #$00
	sta     $2002
;
; IRQ_TMR_CTRL = TMR_DISABLE;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 89
	sta     $200A+1
	lda     #$02
	sta     $200A
;
; init_freeze();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 90
	jsr     _init_freeze
;
; reinit = menu_run(boot); // reinit iec when the menu actions affected it
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 91
	ldy     #$00
	lda     (sp),y
	jsr     pusha
	jsr     _menu_run
	sta     L002F
;
; frozen = FALSE;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 92
	lda     #$00
	sta     _frozen
;
; GPIO_IMASK = BUTTON1; // turn on interrupt on middle button
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 93
	lda     #$02
	sta     $2002
;
; IRQ_TMR_CTRL = TMR_ENABLE;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 94
	ldx     #$00
	lda     #$01
	sta     $200A
	stx     $200A+1
;
; return reinit;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 96
	lda     L002F
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 97
	jmp     incsp1
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ irq_handler (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_irq_handler: near

.segment	"CODE"

;
; if(soft_irq) {   // copper irq
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 101
	lda     _soft_irq
	beq     L0044
;
; do_scroller();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 102
	jsr     _do_scroller
;
; scan_keyboard();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 103
	jsr     _scan_keyboard
;
; check_sd();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 104
	jsr     _check_sd
;
; soft_irq = 0;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 105
	lda     #$00
	sta     _soft_irq
;
; else if(((GPIO_IN & BUTTON1)==0)&&(GPIO_IMASK & BUTTON1)) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 113
	rts
L0044:	lda     $2001
	and     #$02
	bne     L004C
	lda     $2002
	and     #$02
	beq     L004C
;
; UART_DATA = '1';
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 114
	lda     #$31
	sta     $2100
;
; if(!frozen) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 115
	lda     _frozen
	bne     L0059
;
; frozen = TRUE;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 116
	lda     #$01
	sta     _frozen
;
; set_signal(SGNL_UART_BREAK);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 117
	sta     _Signals+1
;
; GPIO_IMASK = 0; // turn off all interrupts
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 118
	lda     #$00
	sta     $2002
;
; } else {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 119
	rts
;
; UART_DATA = '#';
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 120
L0059:	lda     #$23
;
; } else if(((GPIO_IN & BUTTON2)==0)&&(GPIO_IMASK & BUTTON2)) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 122
	jmp     L026C
L004C:	lda     $2001
	and     #$04
	bne     L0068
	lda     $2002
	and     #$04
	beq     L0068
;
; UART_DATA = '2';
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 123
	lda     #$32
;
; } else if(IRQ_TMR_CTRL & TMR_IRQ) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 125
	jmp     L026C
L0068:	lda     $200A
	and     #$04
	beq     L0076
;
; check_sd();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 127
	jsr     _check_sd
;
; if(stand_alone)
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 128
	lda     _stand_alone
	beq     L007A
;
; read_buttons();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 129
	jsr     _read_buttons
;
; IRQ_TMR_CTRL = TMR_IRQ;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 130
L007A:	ldx     #$00
	lda     #$04
	sta     $200A
	stx     $200A+1
;
; } else {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 131
	rts
;
; UART_DATA = '?';
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 132
L0076:	lda     #$3F
L026C:	sta     $2100
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 134
	rts
	.dbg	line

.endproc

; ---------------------------------------------------------------
; int __near__ __fastcall__ write (int, __near__ const void*, unsigned int)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_write: near

.segment	"CODE"

;
; {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 137
	jsr     pushax
;
; hnd = hnd;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 138
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	jsr     staxysp
;
; return uart_write_buffer(buf, count);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 139
	jsr     decsp4
	ldy     #$07
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$02
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	ldy     #$05
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	iny
	txa
	sta     (sp),y
	jsr     _uart_write_buffer
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 140
	jmp     incsp6
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ writeback_poll (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_writeback_poll: near

.segment	"DATA"

L008D:
	.byte	$00

.segment	"BSS"

L008B:
	.res	1,$00
L008C:
	.res	1,$00

.segment	"CODE"

;
; if((((ANY_DIRTY)||(skipped))) && (card_det)) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 147
	lda     $2540
	bne     L0092
	lda     L008D
	beq     L0097
L0092:	lda     _card_det
	bne     L0090
L0097:	rts
;
; if(!mountfile.org_clust) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 148
L0090:	lda     _mountfile+8+3
	sta     sreg+1
	lda     _mountfile+8+2
	sta     sreg
	ldx     _mountfile+8+1
	lda     _mountfile+8
	jsr     bnegeax
	beq     L009A
;
; printf("Error.. mount file seems to be closed.\n");
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 149
	lda     #<(L0001+41)
	ldx     #>(L0001+41)
	jsr     pushax
	ldy     #$02
	jsr     _printf
;
; ANY_DIRTY = 0;  // clear flag so we won't come back here endlessly
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 150
	lda     #$00
	sta     $2540
;
; return;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 151
	rts
;
; if(!skipped) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 154
L009A:	lda     L008D
	bne     L00A1
;
; ANY_DIRTY = 0;  // clear flag once we didn't skip anything anymore
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 155
	sta     $2540
;
; skipped = 0;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 157
L00A1:	lda     #$00
	sta     L008D
;
; for(b=0,c=0;b<41;b++) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 158
	sta     L008B
	sta     L008C
L00A8:	lda     L008B
	cmp     #$29
	jcs     L00A9
;
; if(TRACK_DIRTY(b)) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 159
	lda     L008B
	sta     ptr1
	lda     #$00
	clc
	adc     #$25
	sta     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	beq     L00AA
;
; if((!(DRV_STATUS & DRV_MOTOR)) || ((DRV_TRACK >> 1) != b)) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 160
	lda     $2542
	and     #$02
	beq     L00B7
	ldx     #$00
	lda     $2543
	jsr     asrax1
	cpx     #$00
	bne     L00B7
	cmp     L008B
	beq     L00B6
;
; TRACK_DIRTY(b) = 0;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 161
L00B7:	lda     L008B
	sta     ptr1
	tya
	clc
	adc     #$25
	sta     ptr1+1
	tya
	sta     (ptr1),y
;
; printf("Writing back track %d.\n", b+1);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 162
	lda     #<(L0001+81)
	ldx     #>(L0001+81)
	jsr     pushax
	ldx     #$00
	lda     L008B
	clc
	adc     #$01
	bcc     L00C6
	inx
L00C6:	jsr     pushax
	ldy     #$04
	jsr     _printf
;
; d64_write_track(&mountfile, b);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 163
	jsr     decsp3
	lda     #<(_mountfile)
	ldy     #$01
	sta     (sp),y
	iny
	lda     #>(_mountfile)
	sta     (sp),y
	lda     L008B
	ldy     #$00
	sta     (sp),y
	jsr     _d64_write_track
;
; c++;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 164
	lda     L008C
	pha
	clc
	adc     #$01
	sta     L008C
;
; } else {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 165
	jmp     L026E
;
; skipped ++;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 166
L00B6:	lda     L008D
	pha
	clc
	adc     #$01
	sta     L008D
L026E:	pla
;
; for(b=0,c=0;b<41;b++) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 158
L00AA:	lda     L008B
	clc
	adc     #$01
	sta     L008B
	jmp     L00A8
;
; if(c)
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 170
L00A9:	lda     L008C
	beq     L00CF
;
; if(f_sync(&mountfile) != FR_OK)
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 171
	lda     #<(_mountfile)
	ldx     #>(_mountfile)
	jsr     pushax
	jsr     _f_sync
	cmp     #$00
	beq     L00CF
;
; printf("Error syncing file.\n");
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 172
	lda     #<(L0001+105)
	ldx     #>(L0001+105)
	jsr     pushax
	ldy     #$02
	jmp     _printf
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 174
L00CF:	rts
	.dbg	line

.endproc

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

.segment	"CODE"

.proc	_main_check_sd_change: near

.segment	"CODE"

;
; if(card_change) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 178
	lda     _card_change
	jeq     incsp1
;
; card_change = 0; // I saw it! clear flag
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 179
	lda     #$00
	sta     _card_change
;
; disk_change = TRUE; // notify that we've already done a disk change
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 180
	lda     #$01
	sta     _disk_change
;
; reinit_iec = TRUE;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 181
	sta     _reinit_iec
;
; if(card_det) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 183
	lda     _card_det
	beq     L00DD
;
; f_mountdrv();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 184
	jsr     _f_mountdrv
;
; else {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 194
	jmp     L00E5
;
; printf("Card removed, clearing floppy memory.\n");
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 195
L00DD:	lda     #<(L0001+126)
	ldx     #>(L0001+126)
	jsr     pushax
	ldy     #$02
	jsr     _printf
;
; f_close(&mountfile);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 196
	lda     #<(_mountfile)
	ldx     #>(_mountfile)
	jsr     pushax
	jsr     _f_close
;
; if(cfg_get_value(CFG_CLR_ON_RMV)) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 197
	lda     #$08
	jsr     pusha
	jsr     _cfg_get_value
	stx     tmp1
	ora     tmp1
	beq     L00E5
;
; ClearFloppyMem();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 198
	jsr     _ClearFloppyMem
;
; ANY_DIRTY   = 0;  // clear flag
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 201
L00E5:	lda     #$00
	sta     $2540
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 203
	jmp     incsp1
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ main_loop (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_main_loop: near

.segment	"CODE"

;
; MAPPER_MAP3 = MAP3_IO;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 213
	jsr     decsp4
	ldx     #$08
	lda     #$0D
	sta     $2304
	stx     $2304+1
;
; GPIO_IPOL   = BUTTONS | C64_IRQ; // buttons and stuff are active low
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 214
	lda     #$17
	sta     $2003
;
; GPIO_IMASK  = BUTTON1;           // turn on interrupt on middle button
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 215
	lda     #$02
	sta     $2002
;
; IRQ_TIMER    = 18749; // 10 Hz
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 217
	ldx     #$49
	lda     #$3D
	sta     $2008
	stx     $2008+1
;
; IRQ_TMR_CTRL = TMR_ENABLE; // for testing card insertion
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 218
	ldx     #$00
	lda     #$01
	sta     $200A
	stx     $200A+1
;
; ANY_DIRTY   = 0;  // clear flag
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 219
	stx     $2540
;
; menu_init();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 226
	jsr     _menu_init
;
; main_check_sd_change(0);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 227
	lda     #$00
	jsr     pusha
	jsr     _main_check_sd_change
;
; cfg_drv_enable = (BYTE)cfg_get_value(CFG_1541_ENABLE);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 230
	lda     #$06
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$00
	sta     (sp),y
;
; cfg_drv_addr = (BYTE)cfg_get_value(CFG_1541_ADDR);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 231
	lda     #$01
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$01
	sta     (sp),y
;
; set_drive(cfg_drv_addr, cfg_drv_enable);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 232
	jsr     decsp2
	ldy     #$03
	lda     (sp),y
	ldy     #$01
	sta     (sp),y
	iny
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	jsr     _set_drive
;
; if(cfg_get_value(CFG_MENU_START)) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 234
	lda     #$0E
	jsr     pusha
	jsr     _cfg_get_value
	stx     tmp1
	ora     tmp1
	beq     L010B
;
; do_menu(1);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 235
	lda     #$01
	jsr     pusha
	jsr     _do_menu
;
; iec_enable = (BYTE)cfg_get_value(CFG_IEC_ENABLE);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 238
L010B:	lda     #$02
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$02
	sta     (sp),y
;
; iec_addr   = (BYTE)cfg_get_value(CFG_IEC_ADDR);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 239
	lda     #$03
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$03
	sta     (sp),y
;
; main_check_sd_change(0);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 243
L0116:	lda     #$00
	jsr     pusha
	jsr     _main_check_sd_change
;
; if(reinit_iec) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 245
	lda     _reinit_iec
	beq     L011B
;
; iec_enable = (BYTE)cfg_get_value(CFG_IEC_ENABLE);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 246
	lda     #$02
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$02
	sta     (sp),y
;
; iec_addr   = (BYTE)cfg_get_value(CFG_IEC_ADDR);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 247
	lda     #$03
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$03
	sta     (sp),y
;
; iec_init(iec_addr, iec_enable);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 248
	jsr     decsp2
	ldy     #$05
	lda     (sp),y
	ldy     #$01
	sta     (sp),y
	ldy     #$04
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	jsr     _iec_init
;
; reinit_iec = FALSE;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 249
	lda     #$00
	sta     _reinit_iec
;
; if(iec_enable) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 251
L011B:	ldy     #$02
	lda     (sp),y
	beq     L0128
;
; iec_poll();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 252
	ldy     #$00
	jsr     _iec_poll
;
; if(frozen) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 258
L0128:	lda     _frozen
	jeq     L0145
;
; reinit_iec = do_menu(0);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 259
	lda     #$00
	jsr     pusha
	jsr     _do_menu
	sta     _reinit_iec
;
; if(((BYTE)cfg_get_value(CFG_IEC_ENABLE) != iec_enable) ||
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 261
	lda     #$02
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$02
	cmp     (sp),y
	bne     L0131
	txa
	bne     L0131
;
; ((BYTE)cfg_get_value(CFG_IEC_ADDR) != iec_addr)) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 262
	lda     #$03
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$03
	cmp     (sp),y
	bne     L0131
	txa
	beq     L0130
;
; iec_enable = (BYTE)cfg_get_value(CFG_IEC_ENABLE);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 264
L0131:	lda     #$02
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$02
	sta     (sp),y
;
; iec_addr   = (BYTE)cfg_get_value(CFG_IEC_ADDR);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 265
	lda     #$03
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$03
	sta     (sp),y
;
; reinit_iec = TRUE;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 266
	lda     #$01
	sta     _reinit_iec
;
; cfg_drv_enable = (BYTE)cfg_get_value(CFG_1541_ENABLE);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 268
L0130:	lda     #$06
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$00
	sta     (sp),y
;
; cfg_drv_addr = (BYTE)cfg_get_value(CFG_1541_ADDR);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 269
	lda     #$01
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$01
	sta     (sp),y
;
; if((current_drv != cfg_drv_addr) || (enable_drv != cfg_drv_enable)) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 271
	cmp     _current_drv
	bne     L0146
	dey
	lda     (sp),y
	cmp     _enable_drv
	beq     L0145
;
; set_drive(cfg_drv_addr, cfg_drv_enable);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 272
L0146:	jsr     decsp2
	ldy     #$03
	lda     (sp),y
	ldy     #$01
	sta     (sp),y
	iny
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	jsr     _set_drive
;
; writeback_poll();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 275
L0145:	jsr     _writeback_poll
;
; tap_stream();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 276
	jsr     _tap_stream
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 277
	jmp     L0116
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ sal_handle_left (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_sal_handle_left: near

.segment	"BSS"

L0151:
	.res	2,$00

.segment	"CODE"

;
; printf("Handle left. sal Index = %d/%d.\n", sal_dir_index, iec_dir_cache.num_entries);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 292
	lda     #<(L0001+165)
	ldx     #>(L0001+165)
	jsr     pushax
	lda     _sal_dir_index
	ldx     _sal_dir_index+1
	jsr     pushax
	lda     _iec_dir_cache+2
	ldx     _iec_dir_cache+2+1
	jsr     pushax
	ldy     #$06
	jsr     _printf
;
; if(!iec_dir_cache.num_entries)
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 294
	lda     _iec_dir_cache+2
	ora     _iec_dir_cache+2+1
;
; return;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 295
	beq     L0150
;
; if(sal_dir_index)
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 297
	lda     _sal_dir_index
	ora     _sal_dir_index+1
	beq     L0158
;
; sal_dir_index--;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 298
	lda     _sal_dir_index
	ldx     _sal_dir_index+1
	sec
	sbc     #$01
	bcs     L015B
	dex
L015B:	sta     _sal_dir_index
	stx     _sal_dir_index+1
;
; if((sal_dir_index == 0)&&(iec_dir_cache.cbm_medium)) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 300
L0158:	lda     _sal_dir_index
	ora     _sal_dir_index+1
	bne     L015C
	lda     _iec_dir_cache+4
	beq     L015C
;
; sal_dir_index = 1; // ?
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 301
	ldx     #$00
	lda     #$01
	sta     _sal_dir_index
	stx     _sal_dir_index+1
;
; entry = dir_getentry(sal_dir_index, &iec_dir_cache);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 304
L015C:	jsr     decsp4
	lda     _sal_dir_index
	ldy     #$02
	sta     (sp),y
	iny
	lda     _sal_dir_index+1
	sta     (sp),y
	lda     #<(_iec_dir_cache)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(_iec_dir_cache)
	sta     (sp),y
	jsr     _dir_getentry
	sta     L0151
	stx     L0151+1
;
; printf("sal Index = %d. (%s)\n", sal_dir_index, entry->fname);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 305
	lda     #<(L0001+198)
	ldx     #>(L0001+198)
	jsr     pushax
	lda     _sal_dir_index
	ldx     _sal_dir_index+1
	jsr     pushax
	lda     L0151
	ldx     L0151+1
	clc
	adc     #$0A
	bcc     L016D
	inx
L016D:	jsr     pushax
	ldy     #$06
	jmp     _printf
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 306
L0150:	rts
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ sal_handle_begin (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_sal_handle_begin: near

.segment	"BSS"

L016F:
	.res	2,$00

.segment	"CODE"

;
; printf("Handle begin. sal Index = %d/%d.\n", sal_dir_index, iec_dir_cache.num_entries);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 312
	lda     #<(L0001+220)
	ldx     #>(L0001+220)
	jsr     pushax
	lda     _sal_dir_index
	ldx     _sal_dir_index+1
	jsr     pushax
	lda     _iec_dir_cache+2
	ldx     _iec_dir_cache+2+1
	jsr     pushax
	ldy     #$06
	jsr     _printf
;
; if(!iec_dir_cache.num_entries)
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 314
	lda     _iec_dir_cache+2
	ora     _iec_dir_cache+2+1
;
; return;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 315
	beq     L016E
;
; sal_dir_index = 0;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 317
	ldx     #$00
	txa
	sta     _sal_dir_index
	sta     _sal_dir_index+1
;
; if((sal_dir_index == 0)&&(iec_dir_cache.cbm_medium)) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 319
	lda     _iec_dir_cache+4
	beq     L0178
;
; sal_dir_index = 1; // ?
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 320
	lda     #$01
	sta     _sal_dir_index
	stx     _sal_dir_index+1
;
; entry = dir_getentry(sal_dir_index, &iec_dir_cache);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 323
L0178:	jsr     decsp4
	lda     _sal_dir_index
	ldy     #$02
	sta     (sp),y
	iny
	lda     _sal_dir_index+1
	sta     (sp),y
	lda     #<(_iec_dir_cache)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(_iec_dir_cache)
	sta     (sp),y
	jsr     _dir_getentry
	sta     L016F
	stx     L016F+1
;
; printf("sal Index = %d. (%s)\n", sal_dir_index, entry->fname);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 324
	lda     #<(L0001+254)
	ldx     #>(L0001+254)
	jsr     pushax
	lda     _sal_dir_index
	ldx     _sal_dir_index+1
	jsr     pushax
	lda     L016F
	ldx     L016F+1
	clc
	adc     #$0A
	bcc     L0189
	inx
L0189:	jsr     pushax
	ldy     #$06
	jmp     _printf
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 325
L016E:	rts
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ sal_handle_right (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_sal_handle_right: near

.segment	"BSS"

L018B:
	.res	2,$00

.segment	"CODE"

;
; printf("Handle right. sal Index = %d/%d.\n", sal_dir_index, iec_dir_cache.num_entries);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 331
	lda     #<(L0001+276)
	ldx     #>(L0001+276)
	jsr     pushax
	lda     _sal_dir_index
	ldx     _sal_dir_index+1
	jsr     pushax
	lda     _iec_dir_cache+2
	ldx     _iec_dir_cache+2+1
	jsr     pushax
	ldy     #$06
	jsr     _printf
;
; if(!iec_dir_cache.num_entries)
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 333
	lda     _iec_dir_cache+2
	ora     _iec_dir_cache+2+1
;
; return;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 334
	bne     L0274
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 343
	rts
;
; if(sal_dir_index+1 < iec_dir_cache.num_entries)
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 336
L0274:	lda     _sal_dir_index
	ldx     _sal_dir_index+1
	clc
	adc     #$01
	bcc     L0194
	inx
L0194:	cmp     _iec_dir_cache+2
	txa
	sbc     _iec_dir_cache+2+1
	bcs     L0192
;
; sal_dir_index++;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 337
	lda     _sal_dir_index
	ldx     _sal_dir_index+1
	clc
	adc     #$01
	bcc     L019A
	inx
;
; else
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 338
	jmp     L019A
;
; sal_dir_index = iec_dir_cache.num_entries-1;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 339
L0192:	lda     _iec_dir_cache+2
	ldx     _iec_dir_cache+2+1
	sec
	sbc     #$01
	bcs     L019A
	dex
L019A:	sta     _sal_dir_index
	stx     _sal_dir_index+1
;
; entry = dir_getentry(sal_dir_index, &iec_dir_cache);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 341
	jsr     decsp4
	lda     _sal_dir_index
	ldy     #$02
	sta     (sp),y
	iny
	lda     _sal_dir_index+1
	sta     (sp),y
	lda     #<(_iec_dir_cache)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(_iec_dir_cache)
	sta     (sp),y
	jsr     _dir_getentry
	sta     L018B
	stx     L018B+1
;
; printf("sal Index = %d. (%s)\n", sal_dir_index, entry->fname);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 342
	lda     #<(L0001+310)
	ldx     #>(L0001+310)
	jsr     pushax
	lda     _sal_dir_index
	ldx     _sal_dir_index+1
	jsr     pushax
	lda     L018B
	ldx     L018B+1
	clc
	adc     #$0A
	bcc     L01A3
	inx
L01A3:	jsr     pushax
	ldy     #$06
	jmp     _printf
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ sal_handle_end (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_sal_handle_end: near

.segment	"BSS"

L01A5:
	.res	2,$00

.segment	"CODE"

;
; printf("Handle end. sal Index = %d/%d.\n", sal_dir_index, iec_dir_cache.num_entries);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 349
	lda     #<(L0001+332)
	ldx     #>(L0001+332)
	jsr     pushax
	lda     _sal_dir_index
	ldx     _sal_dir_index+1
	jsr     pushax
	lda     _iec_dir_cache+2
	ldx     _iec_dir_cache+2+1
	jsr     pushax
	ldy     #$06
	jsr     _printf
;
; if(!iec_dir_cache.num_entries)
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 351
	lda     _iec_dir_cache+2
	ora     _iec_dir_cache+2+1
;
; return;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 352
	beq     L01A4
;
; sal_dir_index = iec_dir_cache.num_entries-1;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 354
	lda     _iec_dir_cache+2
	ldx     _iec_dir_cache+2+1
	sec
	sbc     #$01
	bcs     L01AE
	dex
L01AE:	sta     _sal_dir_index
	stx     _sal_dir_index+1
;
; entry = dir_getentry(sal_dir_index, &iec_dir_cache);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 356
	jsr     decsp4
	lda     _sal_dir_index
	ldy     #$02
	sta     (sp),y
	iny
	lda     _sal_dir_index+1
	sta     (sp),y
	lda     #<(_iec_dir_cache)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(_iec_dir_cache)
	sta     (sp),y
	jsr     _dir_getentry
	sta     L01A5
	stx     L01A5+1
;
; printf("sal Index = %d. (%s)\n", sal_dir_index, entry->fname);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 357
	lda     #<(L0001+364)
	ldx     #>(L0001+364)
	jsr     pushax
	lda     _sal_dir_index
	ldx     _sal_dir_index+1
	jsr     pushax
	lda     L01A5
	ldx     L01A5+1
	clc
	adc     #$0A
	bcc     L01B7
	inx
L01B7:	jsr     pushax
	ldy     #$06
	jmp     _printf
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 358
L01A4:	rts
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ check_buttons (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_check_buttons: near

.segment	"CODE"

;
; if(button_event & BUTTON0) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 427
	lda     _button_event
	and     #$01
	beq     L0207
;
; sal_handle_left();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 429
	jsr     _sal_handle_left
;
; clear_button_event(BUTTON0, 0);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 430
	jsr     decsp2
	lda     #$01
	tay
	sta     (sp),y
	lda     #$00
	dey
	sta     (sp),y
	jmp     _clear_button_event
;
; } else if(button_event & BUTTON2) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 431
L0207:	lda     _button_event
	and     #$04
	beq     L020E
;
; sal_handle_right();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 433
	jsr     _sal_handle_right
;
; clear_button_event(BUTTON2, 0);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 434
	jsr     decsp2
	lda     #$04
	ldy     #$01
	sta     (sp),y
	lda     #$00
	dey
	sta     (sp),y
	jmp     _clear_button_event
;
; } else if(button_event & BUTTON1) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 435
L020E:	lda     _button_event
	and     #$02
	beq     L0215
;
; sal_handle_select(FALSE);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 437
	lda     #$00
	jsr     pusha
	jsr     _sal_handle_select
;
; clear_button_event(BUTTON1, 0);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 438
	jsr     decsp2
	lda     #$02
	ldy     #$01
	sta     (sp),y
	lda     #$00
	dey
	sta     (sp),y
	jmp     _clear_button_event
;
; } else if(button_hold & BUTTON1) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 439
L0215:	lda     _button_hold
	and     #$02
	beq     L021D
;
; sal_handle_up();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 440
	jsr     _sal_handle_up
;
; clear_button_event(0, BUTTON1);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 441
	jsr     decsp2
	lda     #$00
	ldy     #$01
	sta     (sp),y
	lda     #$02
	dey
	sta     (sp),y
	jmp     _clear_button_event
;
; } else if(button_hold & BUTTON0) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 442
L021D:	lda     _button_hold
	and     #$01
	beq     L0224
;
; sal_handle_begin();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 443
	jsr     _sal_handle_begin
;
; clear_button_event(0, BUTTON0);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 444
	jsr     decsp2
	lda     #$00
	ldy     #$01
	sta     (sp),y
	tya
	dey
	sta     (sp),y
	jmp     _clear_button_event
;
; } else if(button_hold & BUTTON2) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 445
L0224:	lda     _button_hold
	and     #$04
	beq     L022B
;
; sal_handle_end();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 446
	jsr     _sal_handle_end
;
; clear_button_event(0, BUTTON2);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 447
	jsr     decsp2
	lda     #$00
	ldy     #$01
	sta     (sp),y
	lda     #$04
	dey
	sta     (sp),y
	jmp     _clear_button_event
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 456
L022B:	rts
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ stand_alone_loop (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_stand_alone_loop: near

.segment	"CODE"

;
; GPIO_SET    = MASK_BUTTONS;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 465
	jsr     decsp4
	lda     #$80
	sta     $2000
;
; GPIO_IMASK  = 0;   // no external interrupts
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 466
	lda     #$00
	sta     $2002
;
; IRQ_TIMER    = 9765; // 20 Hz
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 468
	ldx     #$26
	lda     #$25
	sta     $2008
	stx     $2008+1
;
; IRQ_TMR_CTRL = TMR_ENABLE; // for testing card insertion and 
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 469
	ldx     #$00
	lda     #$01
	sta     $200A
	stx     $200A+1
;
; ANY_DIRTY   = 0;  // clear flag
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 470
	stx     $2540
;
; cfg_drv_enable = (BYTE)cfg_get_value(CFG_1541_ENABLE);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 473
	lda     #$06
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$00
	sta     (sp),y
;
; cfg_drv_addr = (BYTE)cfg_get_value(CFG_1541_ADDR);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 474
	lda     #$01
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$01
	sta     (sp),y
;
; set_drive(cfg_drv_addr, cfg_drv_enable);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 475
	jsr     decsp2
	ldy     #$03
	lda     (sp),y
	ldy     #$01
	sta     (sp),y
	iny
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	jsr     _set_drive
;
; iec_enable = 1;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 478
	lda     #$01
	ldy     #$02
	sta     (sp),y
;
; iec_addr   = (BYTE)cfg_get_value(CFG_IEC_ADDR);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 479
	lda     #$03
	jsr     pusha
	jsr     _cfg_get_value
	ldy     #$03
	sta     (sp),y
;
; if(iec_addr == current_drv)
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 480
	cmp     _current_drv
	bne     L024F
;
; iec_addr++;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 481
	lda     (sp),y
	clc
	adc     #$01
	sta     (sp),y
;
; reinit_iec = TRUE;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 483
L024F:	lda     #$01
	sta     _reinit_iec
;
; printf("IEC address: %d\n", iec_addr);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 484
	lda     #<(L0001+554)
	ldx     #>(L0001+554)
	jsr     pushax
	ldy     #$05
	lda     (sp),y
	jsr     pusha0
	ldy     #$04
	jsr     _printf
;
; main_check_sd_change(1);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 487
L0257:	lda     #$01
	jsr     pusha
	jsr     _main_check_sd_change
;
; if(reinit_iec) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 489
	lda     _reinit_iec
	beq     L025C
;
; iec_init(iec_addr, iec_enable);
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 490
	jsr     decsp2
	ldy     #$05
	lda     (sp),y
	ldy     #$01
	sta     (sp),y
	ldy     #$04
	lda     (sp),y
	ldy     #$00
	sta     (sp),y
	jsr     _iec_init
;
; reinit_iec = FALSE;
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 491
	lda     #$00
	sta     _reinit_iec
;
; if(iec_enable) {
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 493
L025C:	ldy     #$02
	lda     (sp),y
	beq     L0263
;
; iec_poll();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 494
	ldy     #$00
	jsr     _iec_poll
;
; check_buttons();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 497
L0263:	jsr     _check_buttons
;
; writeback_poll();
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 501
	jsr     _writeback_poll
;
; }
;
	.dbg	line, "../../../application/ultimate/src/main_loop.c", 502
	jmp     L0257
	.dbg	line

.endproc

