;
; 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, "../../../ui/src/freezer.c", 16946, 1267200498
	.dbg		file, "../inc/manifest.h", 151, 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, "../../../ui/inc/freezer.h", 1398, 1267200498
	.dbg		file, "../../../data/inc/types.h", 1544, 1267200498
	.dbg		file, "../../../filesystem/fat/inc/ff.h", 11459, 1267200484
	.dbg		file, "../../../storage/ram/inc/mapper.h", 2486, 1267200486
	.dbg		file, "../../../io/inc/screen.h", 1493, 1267200496
	.dbg		file, "../../../io/inc/gpio.h", 4272, 1267200496
	.dbg		file, "../../../system/inc/c64_irq.h", 1127, 1267200486
	.dbg		file, "../../../system/inc/c64_addr.h", 2168, 1267200486
	.dbg		file, "../../../io/inc/keyb.h", 1109, 1267200496
	.dbg		file, "../../../system/inc/cartridge.h", 1084, 1267200486
	.import		_printf
	.export		_stop_c64
	.export		_run_c64
	.export		_backup_c64_io
	.export		_init_c64_io
	.export		_restore_c64_io
	.export		_init_freeze
	.export		_exit_freeze
	.export		_dma_load_init
	.export		_dma_load_exit
	.import		_clear_screen
	.import		_start_pos
	.import		_num_lines
	.import		_width
	.import		_do_color
	.importzp	_cursor_x
	.importzp	_cursor_y
	.importzp	_cursor_pos
	.import		_init_cia_handler
	.import		_restore_cia
	.import		_wait_kb_free
	.import		_enable_cartridge
	.import		_disable_cartridge
	.export		_BCK_VIC
	.export		_BCK_CIA
	.export		_vic_irq_en
	.export		_vic_irq
	.export		_raster
	.export		_raster_hi
	.export		_stop_mode
	.export		_vic_d012
	.export		_vic_d011
	.export		_determine_d012
	.import		_dmacode_start
	.import		_dmacode_end
	.import		_current_drv

.segment	"RODATA"

L0001:
	.byte	$46,$72,$6F,$7A,$65,$6E,$20,$6F,$6E,$20,$42,$61,$64,$20,$6C,$69
	.byte	$6E,$65,$2E,$20,$52,$61,$73,$74,$65,$72,$20,$3D,$20,$25,$30,$32
	.byte	$78,$2E,$20,$56,$49,$43,$20,$49,$72,$71,$20,$45,$6E,$61,$62,$6C
	.byte	$65,$3A,$20,$25,$30,$32,$78,$2E,$20,$56,$69,$63,$20,$49,$52,$51
	.byte	$3A,$20,$25,$30,$32,$78,$0A,$00,$4F,$72,$69,$67,$69,$6E,$61,$6C
	.byte	$20,$64,$30,$31,$32,$2F,$31,$31,$20,$63,$6F,$6E,$74,$65,$6E,$74
	.byte	$20,$3D,$20,$25,$30,$32,$78,$20,$25,$30,$32,$58,$2E,$0A,$00,$46
	.byte	$72,$6F,$7A,$65,$6E,$20,$6F,$6E,$20,$52,$2F,$57,$6E,$20,$73,$65
	.byte	$71,$75,$65,$6E,$63,$65,$2E,$0A,$00,$48,$61,$72,$64,$20,$73,$74
	.byte	$6F,$70,$21,$21,$21,$0A,$00,$49,$6E,$74,$65,$72,$6E,$61,$6C,$20
	.byte	$65,$72,$72,$6F,$72,$2E,$20,$53,$68,$6F,$75,$6C,$64,$20,$62,$65
	.byte	$20,$6F,$6E,$65,$20,$6F,$66,$20,$74,$68,$65,$20,$63,$61,$73,$65
	.byte	$73,$2E,$0A,$00,$52,$65,$73,$75,$6D,$65,$64,$20,$6F,$6E,$20,$42
	.byte	$61,$64,$20,$6C,$69,$6E,$65,$2E,$20,$52,$61,$73,$74,$65,$72,$20
	.byte	$3D,$20,$25,$30,$32,$78,$2E,$20,$56,$49,$43,$20,$49,$72,$71,$20
	.byte	$45,$6E,$61,$62,$6C,$65,$3A,$20,$25,$30,$32,$78,$2E,$20,$56,$69
	.byte	$63,$20,$49,$52,$51,$3A,$20,$25,$30,$32,$78,$0A,$00,$43,$49,$41
	.byte	$31,$20,$72,$65,$67,$69,$73,$74,$65,$72,$73,$3A,$20,$00,$25,$30
	.byte	$32,$78,$20,$00,$0A,$00,$53,$65,$74,$20,$43,$49,$41,$31,$20,$25
	.byte	$30,$32,$58,$20,$25,$30,$32,$58,$20,$25,$30,$32,$58,$20,$25,$30
	.byte	$32,$58,$20,$25,$30,$32,$58,$0A,$00,$2F,$00,$56,$65,$63,$74,$6F
	.byte	$72,$20,$72,$65,$61,$64,$20,$3D,$20,$25,$30,$34,$78,$0A,$00,$5F
	.byte	$00

.segment	"BSS"

_BCK_VIC:
	.res	48,$00
_BCK_CIA:
	.res	5,$00
_vic_irq_en:
	.res	1,$00
_vic_irq:
	.res	1,$00
_raster:
	.res	1,$00
_raster_hi:
	.res	1,$00
_stop_mode:
	.res	1,$00
_vic_d012:
	.res	1,$00
_vic_d011:
	.res	1,$00

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

.segment	"DMACODE"

.proc	_stop_c64: near

.segment	"DMACODE"

;
; stop_mode = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 105
	jsr     decsp3
	lda     #$00
	sta     _stop_mode
;
; raster = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 106
	sta     _raster
;
; raster_hi = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 107
	sta     _raster_hi
;
; vic_irq_en = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 108
	sta     _vic_irq_en
;
; vic_irq = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 109
	sta     _vic_irq
;
; GPIO_CLEAR  = STOP_COND; // cond = 0
;
	.dbg	line, "../../../ui/src/freezer.c", 112
	lda     #$18
	sta     $2001
;
; if(do_raster) {
;
	.dbg	line, "../../../ui/src/freezer.c", 114
	ldy     #$03
	lda     (sp),y
	beq     L004E
;
; TIMER = 200; // 1 ms
;
	.dbg	line, "../../../ui/src/freezer.c", 116
	lda     #$C8
	sta     $2004
;
; GPIO_SET2 = C64_STOP;
;
	.dbg	line, "../../../ui/src/freezer.c", 119
	lda     #$04
	sta     $2006
;
; for(b=0;b<25;) {
;
	.dbg	line, "../../../ui/src/freezer.c", 121
	lda     #$00
	dey
L0346:	sta     (sp),y
L004D:	lda     (sp),y
	cmp     #$19
	bcs     L004E
;
; if(GPIO_IN2 & C64_STOP) {  // has the C64 stopped already?
;
	.dbg	line, "../../../ui/src/freezer.c", 122
	lda     $2007
	and     #$04
	beq     L0054
;
; GPIO_SET2 = C64_GAME;
;
	.dbg	line, "../../../ui/src/freezer.c", 125
	lda     #$10
	sta     $2006
;
; GPIO_CLEAR2 = C64_EXROM;
;
	.dbg	line, "../../../ui/src/freezer.c", 126
	lda     #$08
	sta     $2007
;
; raster     = VIC_REG(18);
;
	.dbg	line, "../../../ui/src/freezer.c", 128
	lda     $3012
	sta     _raster
;
; raster_hi  = VIC_REG(17);
;
	.dbg	line, "../../../ui/src/freezer.c", 129
	lda     $3011
	sta     _raster_hi
;
; vic_irq_en = VIC_REG(26);
;
	.dbg	line, "../../../ui/src/freezer.c", 130
	lda     $301A
	sta     _vic_irq_en
;
; vic_irq    = VIC_REG(25);
;
	.dbg	line, "../../../ui/src/freezer.c", 131
	lda     $3019
	sta     _vic_irq
;
; stop_mode = 1;
;
	.dbg	line, "../../../ui/src/freezer.c", 132
	lda     #$01
	sta     _stop_mode
;
; break;
;
	.dbg	line, "../../../ui/src/freezer.c", 133
	jmp     L004E
;
; if(!TIMER) {
;
	.dbg	line, "../../../ui/src/freezer.c", 135
L0054:	lda     $2004
	bne     L004D
;
; TIMER = 200; // 1 ms
;
	.dbg	line, "../../../ui/src/freezer.c", 136
	lda     #$C8
	sta     $2004
;
; b++;
;
	.dbg	line, "../../../ui/src/freezer.c", 137
	lda     (sp),y
	clc
	adc     #$01
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 139
	jmp     L0346
;
; if(!stop_mode) {
;
	.dbg	line, "../../../ui/src/freezer.c", 143
L004E:	lda     _stop_mode
	bne     L0086
;
; GPIO_CLEAR = STOP_COND;
;
	.dbg	line, "../../../ui/src/freezer.c", 144
	lda     #$18
	sta     $2001
;
; GPIO_SET   = (1 << STOP_COND_BIT); // set to mode 1
;
	.dbg	line, "../../../ui/src/freezer.c", 145
	lda     #$08
	sta     $2000
;
; GPIO_SET2 = C64_STOP;  // we do this again, in case we need to stop without raster
;
	.dbg	line, "../../../ui/src/freezer.c", 148
	lda     #$04
	sta     $2006
;
; TIMER = 200; // 1 ms
;
	.dbg	line, "../../../ui/src/freezer.c", 150
	lda     #$C8
	sta     $2004
;
; for(w=0;w<100;) { // was 1500
;
	.dbg	line, "../../../ui/src/freezer.c", 152
	ldx     #$00
	txa
L0347:	jsr     stax0sp
L0085:	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cpx     #$00
	bne     L008C
	cmp     #$64
L008C:	bcs     L0086
;
; if(GPIO_IN2 & C64_STOP) {
;
	.dbg	line, "../../../ui/src/freezer.c", 153
	lda     $2007
	and     #$04
	beq     L008D
;
; stop_mode = 2;
;
	.dbg	line, "../../../ui/src/freezer.c", 154
	lda     #$02
	sta     _stop_mode
;
; break;
;
	.dbg	line, "../../../ui/src/freezer.c", 155
	jmp     L0086
;
; if(!TIMER) {
;
	.dbg	line, "../../../ui/src/freezer.c", 157
L008D:	lda     $2004
	bne     L0085
;
; TIMER = 200; // 1 ms
;
	.dbg	line, "../../../ui/src/freezer.c", 158
	lda     #$C8
	sta     $2004
;
; w++;
;
	.dbg	line, "../../../ui/src/freezer.c", 159
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$01
	bcc     L0347
	inx
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 161
	jmp     L0347
;
; if(!stop_mode) {
;
	.dbg	line, "../../../ui/src/freezer.c", 166
L0086:	lda     _stop_mode
	bne     L009A
;
; GPIO_SET = (3 << STOP_COND_BIT); // set to mode 3
;
	.dbg	line, "../../../ui/src/freezer.c", 167
	lda     #$18
	sta     $2000
;
; while(!(GPIO_IN2 & C64_STOP))
;
	.dbg	line, "../../../ui/src/freezer.c", 170
L00A0:	lda     $2007
	and     #$04
;
; ;
;
	.dbg	line, "../../../ui/src/freezer.c", 171
	beq     L00A0
;
; stop_mode = 3;
;
	.dbg	line, "../../../ui/src/freezer.c", 173
	lda     #$03
	sta     _stop_mode
;
; if(do_raster) {  // WRONG parameter actually, but this function is only called in two places:
;
	.dbg	line, "../../../ui/src/freezer.c", 176
L009A:	ldy     #$03
	lda     (sp),y
	jeq     incsp4
;
; switch(stop_mode) {
;
	.dbg	line, "../../../ui/src/freezer.c", 179
	lda     _stop_mode
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 197
	cmp     #$01
	beq     L00AD
	cmp     #$02
	beq     L00C2
	cmp     #$03
	beq     L00C6
	jmp     L00C9
;
; printf("Frozen on Bad line. Raster = %02x. VIC Irq Enable: %02x. Vic IRQ: %02x\n", raster, vic_irq_en, vic_irq);
;
	.dbg	line, "../../../ui/src/freezer.c", 181
L00AD:	lda     #<(L0001)
	ldx     #>(L0001)
	jsr     pushax
	lda     _raster
	jsr     pusha0
	lda     _vic_irq_en
	jsr     pusha0
	lda     _vic_irq
	jsr     pusha0
	ldy     #$08
	jsr     _printf
;
; if(vic_irq_en & 0x01) { // Raster interrupt enabled
;
	.dbg	line, "../../../ui/src/freezer.c", 182
	lda     _vic_irq_en
	and     #$01
	beq     L00B3
;
; determine_d012(&vic_d012, &vic_d011);
;
	.dbg	line, "../../../ui/src/freezer.c", 183
	jsr     decsp4
	lda     #<(_vic_d012)
	ldy     #$02
	sta     (sp),y
	iny
	lda     #>(_vic_d012)
	sta     (sp),y
	lda     #<(_vic_d011)
	ldy     #$00
	sta     (sp),y
	iny
	lda     #>(_vic_d011)
	sta     (sp),y
	jsr     _determine_d012
;
; printf("Original d012/11 content = %02x %02X.\n", vic_d012, vic_d011);
;
	.dbg	line, "../../../ui/src/freezer.c", 184
	lda     #<(L0001+72)
	ldx     #>(L0001+72)
	jsr     pushax
	lda     _vic_d012
	jsr     pusha0
	lda     _vic_d011
	jsr     pusha0
	ldy     #$06
;
; } else {
;
	.dbg	line, "../../../ui/src/freezer.c", 185
	jmp     L0345
;
; vic_d011 = VIC_REG(17); // for all other bits
;
	.dbg	line, "../../../ui/src/freezer.c", 186
L00B3:	lda     $3011
	sta     _vic_d011
;
; break;
;
	.dbg	line, "../../../ui/src/freezer.c", 188
	jmp     incsp4
;
; printf("Frozen on R/Wn sequence.\n");
;
	.dbg	line, "../../../ui/src/freezer.c", 190
L00C2:	lda     #<(L0001+111)
	ldx     #>(L0001+111)
;
; break;
;
	.dbg	line, "../../../ui/src/freezer.c", 191
	jmp     L0349
;
; printf("Hard stop!!!\n");
;
	.dbg	line, "../../../ui/src/freezer.c", 193
L00C6:	lda     #<(L0001+137)
	ldx     #>(L0001+137)
;
; break;
;
	.dbg	line, "../../../ui/src/freezer.c", 194
	jmp     L0349
;
; printf("Internal error. Should be one of the cases.\n");
;
	.dbg	line, "../../../ui/src/freezer.c", 196
L00C9:	lda     #<(L0001+151)
	ldx     #>(L0001+151)
L0349:	jsr     pushax
	ldy     #$02
L0345:	jsr     _printf
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 199
	jmp     incsp4
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ run_c64 (void)
; ---------------------------------------------------------------

.segment	"DMACODE"

.proc	_run_c64: near

.segment	"BSS"

L00CD:
	.res	1,$00
L00CE:
	.res	1,$00
L00CF:
	.res	1,$00

.segment	"DMACODE"

;
; rast_lo = raster - 1;
;
	.dbg	line, "../../../ui/src/freezer.c", 207
	lda     _raster
	sec
	sbc     #$01
	sta     L00CE
;
; rast_hi = raster_hi & 0x80;
;
	.dbg	line, "../../../ui/src/freezer.c", 208
	lda     _raster_hi
	and     #$80
	sta     L00CF
;
; if(!raster)
;
	.dbg	line, "../../../ui/src/freezer.c", 209
	lda     _raster
	bne     L00D5
;
; rast_hi ^= 0x80;
;
	.dbg	line, "../../../ui/src/freezer.c", 210
	lda     L00CF
	eor     #$80
	sta     L00CF
;
; if (stop_mode == 1) {
;
	.dbg	line, "../../../ui/src/freezer.c", 213
L00D5:	lda     _stop_mode
	cmp     #$01
	jne     L00D9
;
; if(vic_irq & 0x01) { // was raster flag set when we stopped? then let's set it again
;
	.dbg	line, "../../../ui/src/freezer.c", 216
	lda     _vic_irq
	and     #$01
	beq     L00DB
;
; VIC_REG(26) = 0x81;
;
	.dbg	line, "../../../ui/src/freezer.c", 217
	lda     #$81
	sta     $301A
;
; VIC_REG(18) = rast_lo;
;
	.dbg	line, "../../../ui/src/freezer.c", 218
	lda     L00CE
	sta     $3012
;
; VIC_REG(17) = rast_hi;
;
	.dbg	line, "../../../ui/src/freezer.c", 219
	lda     L00CF
	sta     $3011
;
; while((VIC_REG(18) != rast_lo)&&((VIC_REG(17)&0x80) != rast_hi)) {
;
	.dbg	line, "../../../ui/src/freezer.c", 220
L00E9:	lda     L00CE
	cmp     $3012
	beq     L00EA
	lda     $3011
	and     #$80
	cmp     L00CF
	beq     L00EA
;
; if(!TIMER) {
;
	.dbg	line, "../../../ui/src/freezer.c", 221
	lda     $2004
	bne     L00E9
;
; TIMER = 200;
;
	.dbg	line, "../../../ui/src/freezer.c", 222
	lda     #$C8
	sta     $2004
;
; dummy++;
;
	.dbg	line, "../../../ui/src/freezer.c", 223
	lda     L00CD
	clc
	adc     #$01
	sta     L00CD
;
; if(dummy == 40)
;
	.dbg	line, "../../../ui/src/freezer.c", 224
	cmp     #$28
	bne     L00E9
;
; VIC_REG(18) = vic_d012;
;
	.dbg	line, "../../../ui/src/freezer.c", 228
L00EA:	lda     _vic_d012
	sta     $3012
;
; VIC_REG(17) = vic_d011;
;
	.dbg	line, "../../../ui/src/freezer.c", 229
	lda     _vic_d011
	sta     $3011
;
; } else {
;
	.dbg	line, "../../../ui/src/freezer.c", 230
	jmp     L0106
;
; while((VIC_REG(18) != rast_lo)&&((VIC_REG(17)&0x80) != rast_hi)) {
;
	.dbg	line, "../../../ui/src/freezer.c", 231
L00DB:	lda     L00CE
	cmp     $3012
	beq     L0108
	lda     $3011
	and     #$80
	cmp     L00CF
	beq     L0108
;
; if(!TIMER) {
;
	.dbg	line, "../../../ui/src/freezer.c", 232
	lda     $2004
	bne     L00DB
;
; TIMER = 200;
;
	.dbg	line, "../../../ui/src/freezer.c", 233
	lda     #$C8
	sta     $2004
;
; dummy++;
;
	.dbg	line, "../../../ui/src/freezer.c", 234
	lda     L00CD
	clc
	adc     #$01
	sta     L00CD
;
; if(dummy == 40)
;
	.dbg	line, "../../../ui/src/freezer.c", 235
	cmp     #$28
	bne     L00DB
;
; VIC_REG(18) = vic_d012;
;
	.dbg	line, "../../../ui/src/freezer.c", 239
L0108:	lda     _vic_d012
	sta     $3012
;
; VIC_REG(17) = vic_d011;
;
	.dbg	line, "../../../ui/src/freezer.c", 240
	lda     _vic_d011
	sta     $3011
;
; VIC_REG(25) = 0x81; // clear raster irq
;
	.dbg	line, "../../../ui/src/freezer.c", 241
	lda     #$81
	sta     $3019
;
; VIC_REG(26) = vic_irq_en;
;
	.dbg	line, "../../../ui/src/freezer.c", 243
L0106:	lda     _vic_irq_en
	sta     $301A
;
; raster     = VIC_REG(18);
;
	.dbg	line, "../../../ui/src/freezer.c", 245
	lda     $3012
	sta     _raster
;
; vic_irq_en = VIC_REG(26);
;
	.dbg	line, "../../../ui/src/freezer.c", 246
	lda     $301A
	sta     _vic_irq_en
;
; vic_irq    = VIC_REG(25);
;
	.dbg	line, "../../../ui/src/freezer.c", 247
	lda     $3019
	sta     _vic_irq
;
; GPIO_CLEAR = STOP_COND;
;
	.dbg	line, "../../../ui/src/freezer.c", 249
	lda     #$18
	sta     $2001
;
; GPIO_CLEAR2 = C64_EXROM | C64_GAME;
;
	.dbg	line, "../../../ui/src/freezer.c", 252
	sta     $2007
;
; dummy = VIC_REG(0);
;
	.dbg	line, "../../../ui/src/freezer.c", 255
	lda     $3000
	sta     L00CD
;
; GPIO_CLEAR2 = C64_STOP;
;
	.dbg	line, "../../../ui/src/freezer.c", 258
	lda     #$04
	sta     $2007
;
; printf("Resumed on Bad line. Raster = %02x. VIC Irq Enable: %02x. Vic IRQ: %02x\n", raster, vic_irq_en, vic_irq);
;
	.dbg	line, "../../../ui/src/freezer.c", 260
	lda     #<(L0001+196)
	ldx     #>(L0001+196)
	jsr     pushax
	lda     _raster
	jsr     pusha0
	lda     _vic_irq_en
	jsr     pusha0
	lda     _vic_irq
	jsr     pusha0
	ldy     #$08
	jmp     _printf
;
; GPIO_SET = STOP_COND;
;
	.dbg	line, "../../../ui/src/freezer.c", 262
L00D9:	lda     #$18
	sta     $2000
;
; GPIO_CLEAR2 = C64_EXROM | C64_GAME;
;
	.dbg	line, "../../../ui/src/freezer.c", 265
	sta     $2007
;
; GPIO_CLEAR2 = C64_STOP;
;
	.dbg	line, "../../../ui/src/freezer.c", 267
	lda     #$04
	sta     $2007
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 269
	rts
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ backup_c64_io (void)
; ---------------------------------------------------------------

.segment	"DMACODE"

.proc	_backup_c64_io: near

.segment	"DMACODE"

;
; char *scr = (char *)SCREEN1_ADDR;
;
	.dbg	line, "../../../ui/src/freezer.c", 286
	jsr     decsp3
	ldx     #$44
	lda     #$00
	jsr     pushax
;
; GPIO_SET2 = C64_GAME;
;
	.dbg	line, "../../../ui/src/freezer.c", 290
	lda     #$10
	sta     $2006
;
; GPIO_CLEAR2 = C64_EXROM;
;
	.dbg	line, "../../../ui/src/freezer.c", 291
	lda     #$08
	sta     $2007
;
; for(b=0;b<NUM_VICREGS;b++)
;
	.dbg	line, "../../../ui/src/freezer.c", 294
	lda     #$00
	ldy     #$02
L034E:	sta     (sp),y
	cmp     #$30
	bcs     L015E
;
; BCK_VIC[b] = VIC_REG(b); 
;
	.dbg	line, "../../../ui/src/freezer.c", 295
	lda     #<(_BCK_VIC)
	ldx     #>(_BCK_VIC)
	clc
	adc     (sp),y
	bcc     L0167
	inx
L0167:	sta     sreg
	stx     sreg+1
	lda     (sp),y
	sta     ptr1
	lda     #$00
	clc
	adc     #$30
	sta     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	sta     (sreg),y
;
; for(b=0;b<NUM_VICREGS;b++)
;
	.dbg	line, "../../../ui/src/freezer.c", 294
	ldy     #$02
	lda     (sp),y
	clc
	adc     #$01
	jmp     L034E
;
; VIC_CTRL = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 298
L015E:	lda     #$00
	sta     $3011
;
; BORDER  = 0; // black
;
	.dbg	line, "../../../ui/src/freezer.c", 299
	sta     $3020
;
; BACKGROUND = 0; // black for later
;
	.dbg	line, "../../../ui/src/freezer.c", 300
	sta     $3021
;
; SID_VOLUME  = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 301
	sta     $3418
;
; printf("CIA1 registers: ");
;
	.dbg	line, "../../../ui/src/freezer.c", 305
	lda     #<(L0001+269)
	ldx     #>(L0001+269)
	jsr     pushax
	ldy     #$02
	jsr     _printf
;
; for(b=0;b<13;b++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 306
	lda     #$00
	ldy     #$02
L034F:	sta     (sp),y
	cmp     #$0D
	bcs     L017E
;
; printf("%02x ", CIA1_REG(b));
;
	.dbg	line, "../../../ui/src/freezer.c", 307
	lda     #<(L0001+286)
	ldx     #>(L0001+286)
	jsr     pushax
	ldy     #$04
	lda     (sp),y
	sta     ptr1
	lda     #$00
	clc
	adc     #$3C
	sta     ptr1+1
	ldx     #$00
	lda     (ptr1,x)
	jsr     pusha0
	ldy     #$04
	jsr     _printf
;
; for(b=0;b<13;b++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 306
	ldy     #$02
	lda     (sp),y
	clc
	adc     #$01
	jmp     L034F
;
; } printf("\n");
;
	.dbg	line, "../../../ui/src/freezer.c", 308
L017E:	lda     #<(L0001+292)
	ldx     #>(L0001+292)
	jsr     pushax
	ldy     #$02
	jsr     _printf
;
; MAPPER_MAP1 = MAP_RAMDMA;
;
	.dbg	line, "../../../ui/src/freezer.c", 311
	ldx     #$04
	lda     #$00
	sta     $2300
	stx     $2300+1
;
; MAPPER_MAP2 = MAP_BACKUP;
;
	.dbg	line, "../../../ui/src/freezer.c", 312
	tax
	lda     #$38
	sta     $2302
	stx     $2302+1
;
; for(w=0;w<BACKUP_SIZE;w++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 314
	txa
	ldy     #$03
L0350:	jsr     staxysp
	ldy     #$04
	lda     (sp),y
	tax
	dey
	cpx     #$0C
	bcs     L0193
;
; BCK_LOC(w) = MEM_LOC(w);
;
	.dbg	line, "../../../ui/src/freezer.c", 315
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	txa
	clc
	adc     #$70
	sta     sreg+1
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	txa
	clc
	adc     #$44
	sta     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	sta     (sreg),y
;
; for(w=0;w<BACKUP_SIZE;w++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 314
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$01
	bcc     L0350
	inx
	jmp     L0350
;
; MAPPER_MAP2 = MAP_BACKUP;
;
	.dbg	line, "../../../ui/src/freezer.c", 319
L0193:	ldx     #$00
	lda     #$38
	sta     $2302
	stx     $2302+1
;
; for(w=0;w<1000;w++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 320
	txa
L0351:	jsr     staxysp
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cpx     #$03
	bne     L01AC
	cmp     #$E8
L01AC:	bcs     L01A6
;
; BCK_COLOR(w) = COLOR_MAP3(w);
;
	.dbg	line, "../../../ui/src/freezer.c", 321
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	txa
	clc
	adc     #$7C
	sta     sreg+1
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	txa
	clc
	adc     #$38
	sta     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	sta     (sreg),y
;
; for(w=0;w<1000;w++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 320
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$01
	bcc     L0351
	inx
	jmp     L0351
;
; MAPPER_MAP1 = MAP_RAMDMA;
;
	.dbg	line, "../../../ui/src/freezer.c", 325
L01A6:	ldx     #$04
	lda     #$00
	sta     $2300
	stx     $2300+1
;
; for(w=0;w<2048;w++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 326
	tax
L0352:	jsr     staxysp
	ldy     #$04
	lda     (sp),y
	tax
	cpx     #$08
	bcs     L01B9
;
; CHAR_DEST(w) = CHAR_SRC(w);
;
	.dbg	line, "../../../ui/src/freezer.c", 327
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	txa
	clc
	adc     #$48
	sta     sreg+1
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	txa
	clc
	adc     #$60
	sta     ptr1+1
	ldy     #$00
	lda     (ptr1),y
	sta     (sreg),y
;
; for(w=0;w<2048;w++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 326
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$01
	bcc     L0352
	inx
	jmp     L0352
;
; BCK_CIA[0] = CIA2_DDRA;
;
	.dbg	line, "../../../ui/src/freezer.c", 331
L01B9:	lda     $3D02
	sta     _BCK_CIA
;
; BCK_CIA[1] = CIA2_DPA;
;
	.dbg	line, "../../../ui/src/freezer.c", 332
	lda     $3D00
	sta     _BCK_CIA+1
;
; BCK_CIA[2] = CIA1_DDRA;
;
	.dbg	line, "../../../ui/src/freezer.c", 333
	lda     $3C02
	sta     _BCK_CIA+2
;
; BCK_CIA[3] = CIA1_DDRB;
;
	.dbg	line, "../../../ui/src/freezer.c", 334
	lda     $3C03
	sta     _BCK_CIA+3
;
; BCK_CIA[4] = CIA1_DPA;
;
	.dbg	line, "../../../ui/src/freezer.c", 335
	lda     $3C00
	sta     _BCK_CIA+4
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 336
	jmp     incsp5
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ init_c64_io (void)
; ---------------------------------------------------------------

.segment	"DMACODE"

.proc	_init_c64_io: near

.segment	"DMACODE"

;
; CIA2_DDRA |= 0x03;
;
	.dbg	line, "../../../ui/src/freezer.c", 343
	lda     $3D02
	ora     #$03
	sta     $3D02
;
; CIA2_DPA  |= 0x03;
;
	.dbg	line, "../../../ui/src/freezer.c", 344
	lda     $3D00
	ora     #$03
	sta     $3D00
;
; CIA1_DDRA  = 0xFF; // all out
;
	.dbg	line, "../../../ui/src/freezer.c", 347
	lda     #$FF
	sta     $3C02
;
; CIA1_DDRB  = 0x00; // all in
;
	.dbg	line, "../../../ui/src/freezer.c", 348
	lda     #$00
	sta     $3C03
;
; VIC_MMAP = 0x12; // screen $0400 / charset at 0800
;
	.dbg	line, "../../../ui/src/freezer.c", 352
	lda     #$12
	sta     $3018
;
; start_pos  = 0x0000;
;
	.dbg	line, "../../../ui/src/freezer.c", 354
	lda     #$00
	sta     _start_pos
	sta     _start_pos+1
;
; width    = 40;
;
	.dbg	line, "../../../ui/src/freezer.c", 355
	lda     #$28
	sta     _width
;
; num_lines  = 25;
;
	.dbg	line, "../../../ui/src/freezer.c", 356
	lda     #$19
	sta     _num_lines
;
; cursor_pos = MAP1_ADDR + 0x0400;
;
	.dbg	line, "../../../ui/src/freezer.c", 357
	ldx     #$44
	lda     #$00
	sta     _cursor_pos
	stx     _cursor_pos+1
;
; cursor_x   = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 358
	sta     _cursor_x
;
; cursor_y   = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 359
	sta     _cursor_y
;
; do_color   = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 360
	sta     _do_color
;
; clear_screen(0x0f);
;
	.dbg	line, "../../../ui/src/freezer.c", 361
	lda     #$0F
	jsr     pusha
	jsr     _clear_screen
;
; init_cia_handler();
;
	.dbg	line, "../../../ui/src/freezer.c", 368
	jsr     _init_cia_handler
;
; VIC_REG(17) = 0x1B; // vic_ctrl // Enable screen in text mode, 25 rows
;
	.dbg	line, "../../../ui/src/freezer.c", 410
	lda     #$1B
	sta     $3011
;
; VIC_REG(18) = 0xF8; // raster line to trigger on
;
	.dbg	line, "../../../ui/src/freezer.c", 411
	lda     #$F8
	sta     $3012
;
; VIC_REG(21) = 0x00; // turn off sprites
;
	.dbg	line, "../../../ui/src/freezer.c", 412
	lda     #$00
	sta     $3015
;
; VIC_REG(22) = 0xC8; // Screen = 40 cols with correct scroll
;
	.dbg	line, "../../../ui/src/freezer.c", 413
	lda     #$C8
	sta     $3016
;
; VIC_REG(26) = 0x01; // Enable Raster interrupt
;
	.dbg	line, "../../../ui/src/freezer.c", 414
	lda     #$01
	sta     $301A
;
; }    
;
	.dbg	line, "../../../ui/src/freezer.c", 415
	rts
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ restore_c64_io (void)
; ---------------------------------------------------------------

.segment	"DMACODE"

.proc	_restore_c64_io: near

.segment	"DMACODE"

;
; VIC_CTRL = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 446
	jsr     decsp3
	lda     #$00
	sta     $3011
;
; MAPPER_MAP1 = MAP_RAMDMA;
;
	.dbg	line, "../../../ui/src/freezer.c", 448
	ldx     #$04
	sta     $2300
	stx     $2300+1
;
; MAPPER_MAP2 = MAP_BACKUP;
;
	.dbg	line, "../../../ui/src/freezer.c", 449
	tax
	lda     #$38
	sta     $2302
	stx     $2302+1
;
; for(w=0;w<BACKUP_SIZE;w++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 452
	txa
L0353:	jsr     stax0sp
	ldy     #$01
	lda     (sp),y
	tax
	cpx     #$0C
	bcs     L022E
;
; MEM_LOC(w) = BCK_LOC(w);
;
	.dbg	line, "../../../ui/src/freezer.c", 453
	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	txa
	clc
	adc     #$44
	sta     sreg+1
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	txa
	clc
	adc     #$70
	sta     ptr1+1
	lda     (ptr1),y
	sta     (sreg),y
;
; for(w=0;w<BACKUP_SIZE;w++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 452
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$01
	bcc     L0353
	inx
	jmp     L0353
;
; for(w=0;w<1000;w++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 457
L022E:	ldx     #$00
	txa
L0354:	jsr     stax0sp
	ldy     #$01
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	cpx     #$03
	bne     L0244
	cmp     #$E8
L0244:	bcs     L023E
;
; COLOR_MAP3(w) = BCK_COLOR(w);
;
	.dbg	line, "../../../ui/src/freezer.c", 458
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     sreg
	txa
	clc
	adc     #$38
	sta     sreg+1
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	txa
	clc
	adc     #$7C
	sta     ptr1+1
	lda     (ptr1),y
	sta     (sreg),y
;
; for(w=0;w<1000;w++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 457
	iny
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	clc
	adc     #$01
	bcc     L0354
	inx
	jmp     L0354
;
; CIA2_DDRA = BCK_CIA[0];
;
	.dbg	line, "../../../ui/src/freezer.c", 462
L023E:	lda     _BCK_CIA
	sta     $3D02
;
; CIA2_DPA  = BCK_CIA[1];
;
	.dbg	line, "../../../ui/src/freezer.c", 463
	lda     _BCK_CIA+1
	sta     $3D00
;
; CIA1_DDRA = BCK_CIA[2];
;
	.dbg	line, "../../../ui/src/freezer.c", 464
	lda     _BCK_CIA+2
	sta     $3C02
;
; CIA1_DDRB = BCK_CIA[3];
;
	.dbg	line, "../../../ui/src/freezer.c", 465
	lda     _BCK_CIA+3
	sta     $3C03
;
; CIA1_DPA  = BCK_CIA[4];
;
	.dbg	line, "../../../ui/src/freezer.c", 466
	lda     _BCK_CIA+4
	sta     $3C00
;
; printf("Set CIA1 %02X %02X %02X %02X %02X\n", BCK_CIA[0], BCK_CIA[1], BCK_CIA[2], BCK_CIA[3], BCK_CIA[4]);
;
	.dbg	line, "../../../ui/src/freezer.c", 468
	lda     #<(L0001+294)
	ldx     #>(L0001+294)
	jsr     pushax
	lda     _BCK_CIA
	jsr     pusha0
	lda     _BCK_CIA+1
	jsr     pusha0
	lda     _BCK_CIA+2
	jsr     pusha0
	lda     _BCK_CIA+3
	jsr     pusha0
	lda     _BCK_CIA+4
	jsr     pusha0
	ldy     #$0C
	jsr     _printf
;
; for(b=0;b<NUM_VICREGS;b++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 471
	lda     #$00
	ldy     #$02
L0355:	sta     (sp),y
	cmp     #$30
	bcs     L0273
;
; VIC_REG(b) = BCK_VIC[b]; 
;
	.dbg	line, "../../../ui/src/freezer.c", 472
	lda     (sp),y
	sta     ptr1
	lda     #$00
	clc
	adc     #$30
	sta     ptr1+1
	lda     (sp),y
	tay
	lda     _BCK_VIC,y
	ldy     #$00
	sta     (ptr1),y
;
; for(b=0;b<NUM_VICREGS;b++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 471
	ldy     #$02
	lda     (sp),y
	clc
	adc     #$01
	jmp     L0355
;
; restore_cia();  // Restores the interrupt generation
;
	.dbg	line, "../../../ui/src/freezer.c", 475
L0273:	jsr     _restore_cia
;
; SID_VOLUME = 15;  // turn on volume. Unfortunately we could not know what it was set to.
;
	.dbg	line, "../../../ui/src/freezer.c", 477
	lda     #$0F
	sta     $3418
;
; SID_DUMMY  = 0;   // clear internal charge on databus!
;
	.dbg	line, "../../../ui/src/freezer.c", 478
	lda     #$00
	sta     $341F
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 479
	jmp     incsp3
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ init_freeze (void)
; ---------------------------------------------------------------

.segment	"DMACODE"

.proc	_init_freeze: near

.segment	"DMACODE"

;
; stop_c64(TRUE);
;
	.dbg	line, "../../../ui/src/freezer.c", 420
	lda     #$01
	jsr     pusha
	jsr     _stop_c64
;
; GPIO_IMASK  &= ~BUTTONS;
;
	.dbg	line, "../../../ui/src/freezer.c", 423
	lda     $2002
	and     #$F8
	sta     $2002
;
; backup_c64_io();
;
	.dbg	line, "../../../ui/src/freezer.c", 425
	jsr     _backup_c64_io
;
; init_c64_io();
;
	.dbg	line, "../../../ui/src/freezer.c", 426
	jmp     _init_c64_io
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ exit_freeze (void)
; ---------------------------------------------------------------

.segment	"DMACODE"

.proc	_exit_freeze: near

.segment	"DMACODE"

;
; wait_kb_free();
;
	.dbg	line, "../../../ui/src/freezer.c", 483
	jsr     _wait_kb_free
;
; GPIO_IMASK &= ~C64_IRQ;
;
	.dbg	line, "../../../ui/src/freezer.c", 486
	lda     $2002
	and     #$EF
	sta     $2002
;
; restore_c64_io();
;
	.dbg	line, "../../../ui/src/freezer.c", 488
	jsr     _restore_c64_io
;
; run_c64();
;
	.dbg	line, "../../../ui/src/freezer.c", 491
	jsr     _run_c64
;
; GPIO_IMASK |= BUTTON1;
;
	.dbg	line, "../../../ui/src/freezer.c", 494
	lda     $2002
	ora     #$02
	sta     $2002
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 495
	rts
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ dma_load_init (void)
; ---------------------------------------------------------------

.segment	"DMACODE"

.proc	_dma_load_init: near

.segment	"BSS"

L0294:
	.res	2,$00
L0295:
	.res	2,$00
L0296:
	.res	2,$00
L0297:
	.res	2,$00
L0298:
	.res	1,$00

.segment	"DMACODE"

;
; MAPPER_MAP1 = MAP_RAMDMA;
;
	.dbg	line, "../../../ui/src/freezer.c", 508
	ldx     #$04
	lda     #$00
	sta     $2300
	stx     $2300+1
;
; GPIO_IMASK  = 0;    // turn off all interrupts
;
	.dbg	line, "../../../ui/src/freezer.c", 510
	sta     $2002
;
; disable_cartridge();
;
	.dbg	line, "../../../ui/src/freezer.c", 511
	jsr     _disable_cartridge
;
; GPIO_SET2   = C64_RESET;
;
	.dbg	line, "../../../ui/src/freezer.c", 514
	lda     #$80
	sta     $2006
;
; GPIO_SET2   = C64_EXROM; // TODO: Conditional? In 128 mode??
;
	.dbg	line, "../../../ui/src/freezer.c", 515
	lda     #$08
	sta     $2006
;
; GPIO_CLEAR2 = C64_GAME;
;
	.dbg	line, "../../../ui/src/freezer.c", 516
	lda     #$10
	sta     $2007
;
; TIMER     = 200;
;
	.dbg	line, "../../../ui/src/freezer.c", 518
	lda     #$C8
	sta     $2004
;
; while(TIMER)
;
	.dbg	line, "../../../ui/src/freezer.c", 519
L02AC:	lda     $2004
;
; ;
;
	.dbg	line, "../../../ui/src/freezer.c", 520
	bne     L02AC
;
; GPIO_CLEAR2 = C64_RESET;
;
	.dbg	line, "../../../ui/src/freezer.c", 522
	lda     #$80
	sta     $2007
;
; TIMER     = 255;
;
	.dbg	line, "../../../ui/src/freezer.c", 526
	lda     #$FF
	sta     $2004
;
; while(TIMER)
;
	.dbg	line, "../../../ui/src/freezer.c", 527
L02B6:	lda     $2004
;
; ;
;
	.dbg	line, "../../../ui/src/freezer.c", 528
	bne     L02B6
;
; GPIO_CLEAR2 = C64_EXROM; // 128 should have tested already (TODO)
;
	.dbg	line, "../../../ui/src/freezer.c", 530
	lda     #$08
	sta     $2007
;
; stop_c64(FALSE);
;
	.dbg	line, "../../../ui/src/freezer.c", 532
	lda     #$00
	jsr     pusha
	jsr     _stop_c64
;
; *(BYTE *)(MAP1_ADDR + 0x0315) = 0x00;
;
	.dbg	line, "../../../ui/src/freezer.c", 535
	lda     #$00
	sta     $4315
;
; while((*(BYTE *)(MAP1_ADDR + 0x0315)) == 0x00) {
;
	.dbg	line, "../../../ui/src/freezer.c", 537
L02C2:	lda     $4315
	bne     L02C3
;
; run_c64();
;
	.dbg	line, "../../../ui/src/freezer.c", 538
	jsr     _run_c64
;
; for(b=0;b<20;b++)  {
;
	.dbg	line, "../../../ui/src/freezer.c", 539
	lda     #$00
L0356:	sta     L0298
	cmp     #$14
	bcs     L02C9
;
; TIMER = 255;
;
	.dbg	line, "../../../ui/src/freezer.c", 540
	lda     #$FF
	sta     $2004
;
; while(TIMER)
;
	.dbg	line, "../../../ui/src/freezer.c", 541
L02D3:	lda     $2004
;
; ;
;
	.dbg	line, "../../../ui/src/freezer.c", 542
	bne     L02D3
;
; for(b=0;b<20;b++)  {
;
	.dbg	line, "../../../ui/src/freezer.c", 539
	lda     L0298
	clc
	adc     #$01
	jmp     L0356
;
; printf("/");
;
	.dbg	line, "../../../ui/src/freezer.c", 544
L02C9:	lda     #<(L0001+329)
	ldx     #>(L0001+329)
	jsr     pushax
	ldy     #$02
	jsr     _printf
;
; stop_c64(FALSE);
;
	.dbg	line, "../../../ui/src/freezer.c", 545
	lda     #$00
	jsr     pusha
	jsr     _stop_c64
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 546
	jmp     L02C2
;
; i = (WORD)&dmacode_end - (WORD)&dmacode_start;
;
	.dbg	line, "../../../ui/src/freezer.c", 550
L02C3:	lda     #<(_dmacode_end)
	sec
	sbc     #<(_dmacode_start)
	sta     L0294
	lda     #>(_dmacode_end)
	sbc     #>(_dmacode_start)
	sta     L0294+1
;
; s = (BYTE *)&dmacode_start;
;
	.dbg	line, "../../../ui/src/freezer.c", 551
	lda     #<(_dmacode_start)
	sta     L0295
	lda     #>(_dmacode_start)
	sta     L0295+1
;
; d = (BYTE *)(MAP1_ADDR + 0x0140);
;
	.dbg	line, "../../../ui/src/freezer.c", 552
	ldx     #$41
	lda     #$40
	sta     L0296
	stx     L0296+1
;
; while(i) {
;
	.dbg	line, "../../../ui/src/freezer.c", 554
L02E2:	lda     L0294
	ora     L0294+1
	beq     L02E3
;
; *(d++) = *(s++);
;
	.dbg	line, "../../../ui/src/freezer.c", 555
	lda     L0296
	ldx     L0296+1
	sta     regsave
	stx     regsave+1
	clc
	adc     #$01
	bcc     L02E7
	inx
L02E7:	sta     L0296
	stx     L0296+1
	lda     regsave
	ldx     regsave+1
	jsr     pushax
	lda     L0295
	ldx     L0295+1
	sta     regsave
	stx     regsave+1
	clc
	adc     #$01
	bcc     L02EA
	inx
L02EA:	sta     L0295
	stx     L0295+1
	ldy     #$00
	lda     (regsave),y
	jsr     staspidx
;
; i--;
;
	.dbg	line, "../../../ui/src/freezer.c", 556
	lda     L0294
	ldx     L0294+1
	sec
	sbc     #$01
	bcs     L02EC
	dex
L02EC:	sta     L0294
	stx     L0294+1
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 557
	jmp     L02E2
;
; run_c64();
;
	.dbg	line, "../../../ui/src/freezer.c", 559
L02E3:	jsr     _run_c64
;
; for(i=0;i<200;i++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 561
	lda     #$00
	sta     L0294
	sta     L0294+1
L02EE:	lda     L0294+1
	bne     L02F5
	lda     L0294
	cmp     #$C8
L02F5:	bcs     L02EF
;
; TIMER = 200;
;
	.dbg	line, "../../../ui/src/freezer.c", 562
	lda     #$C8
	sta     $2004
;
; while(TIMER)
;
	.dbg	line, "../../../ui/src/freezer.c", 563
L02FB:	lda     $2004
;
; ;
;
	.dbg	line, "../../../ui/src/freezer.c", 564
	bne     L02FB
;
; for(i=0;i<200;i++) {
;
	.dbg	line, "../../../ui/src/freezer.c", 561
	lda     L0294
	ldx     L0294+1
	clc
	adc     #$01
	bcc     L02F7
	inx
L02F7:	sta     L0294
	stx     L0294+1
	jmp     L02EE
;
; stop_c64(FALSE);
;
	.dbg	line, "../../../ui/src/freezer.c", 567
L02EF:	lda     #$00
	jsr     pusha
	jsr     _stop_c64
;
; vec = *(WORD *)(MAP1_ADDR + 0x0314);
;
	.dbg	line, "../../../ui/src/freezer.c", 570
	lda     $4314
	ldx     $4314+1
	sta     L0297
	stx     L0297+1
;
; *(WORD *)(MAP1_ADDR + 0x0140) = vec;
;
	.dbg	line, "../../../ui/src/freezer.c", 571
	sta     $4140
	stx     $4140+1
;
; printf("Vector read = %04x\n", vec);
;
	.dbg	line, "../../../ui/src/freezer.c", 573
	lda     #<(L0001+331)
	ldx     #>(L0001+331)
	jsr     pushax
	lda     L0297
	ldx     L0297+1
	jsr     pushax
	ldy     #$04
	jsr     _printf
;
; *(WORD *)(MAP1_ADDR + 0x0314) = 0x0146;
;
	.dbg	line, "../../../ui/src/freezer.c", 576
	ldx     #$01
	lda     #$46
	sta     $4314
	stx     $4314+1
;
; while((*(BYTE *)(MAP1_ADDR + 0x0143)) == 0x00) {
;
	.dbg	line, "../../../ui/src/freezer.c", 579
L030D:	lda     $4143
	bne     L030E
;
; run_c64();
;
	.dbg	line, "../../../ui/src/freezer.c", 580
	jsr     _run_c64
;
; TIMER = 255;
;
	.dbg	line, "../../../ui/src/freezer.c", 581
	lda     #$FF
	sta     $2004
;
; while(TIMER)
;
	.dbg	line, "../../../ui/src/freezer.c", 582
L0316:	lda     $2004
;
; ;
;
	.dbg	line, "../../../ui/src/freezer.c", 583
	bne     L0316
;
; printf("_");
;
	.dbg	line, "../../../ui/src/freezer.c", 584
	lda     #<(L0001+351)
	ldx     #>(L0001+351)
	jsr     pushax
	ldy     #$02
	jsr     _printf
;
; stop_c64(FALSE);
;
	.dbg	line, "../../../ui/src/freezer.c", 585
	lda     #$00
	jsr     pusha
	jsr     _stop_c64
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 586
	jmp     L030D
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 587
L030E:	rts
	.dbg	line

.endproc

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

.segment	"DMACODE"

.proc	_dma_load_exit: near

.segment	"DMACODE"

;
; MAPPER_MAP1 = MAP_RAMDMA;
;
	.dbg	line, "../../../ui/src/freezer.c", 595
	ldx     #$04
	lda     #$00
	sta     $2300
	stx     $2300+1
;
; *(BYTE *)(MAP1_ADDR + 0x0142) = run_code;
;
	.dbg	line, "../../../ui/src/freezer.c", 596
	tay
	lda     (sp),y
	sta     $4142
;
; *(BYTE *)(MAP1_ADDR + 0x00BA) = current_drv;
;
	.dbg	line, "../../../ui/src/freezer.c", 599
	lda     _current_drv
	sta     $40BA
;
; *(BYTE *)(MAP1_ADDR + 0x0090) = 0x40;
;
	.dbg	line, "../../../ui/src/freezer.c", 601
	lda     #$40
	sta     $4090
;
; *(WORD *)(MAP1_ADDR + 0x0035) = 0xA000;
;
	.dbg	line, "../../../ui/src/freezer.c", 603
	ldx     #$A0
	sty     $4035
	stx     $4035+1
;
; *(WORD *)(MAP1_ADDR + 0x00AE) = *(WORD *)(MAP1_ADDR + 0x002D);
;
	.dbg	line, "../../../ui/src/freezer.c", 605
	lda     $402D
	sta     $40AE
	lda     $402D+1
	sta     $40AE+1
;
; enable_cartridge();
;
	.dbg	line, "../../../ui/src/freezer.c", 607
	jsr     _enable_cartridge
;
; TIMER     = 255;
;
	.dbg	line, "../../../ui/src/freezer.c", 608
	lda     #$FF
	sta     $2004
;
; while(TIMER)
;
	.dbg	line, "../../../ui/src/freezer.c", 609
L0336:	lda     $2004
;
; ;
;
	.dbg	line, "../../../ui/src/freezer.c", 610
	bne     L0336
;
; CART_KILL = 0xFF; // kill it immediately, so it would only work after reset
;
	.dbg	line, "../../../ui/src/freezer.c", 611
	lda     #$FF
	sta     $2005
;
; TIMER     = 255;
;
	.dbg	line, "../../../ui/src/freezer.c", 612
	sta     $2004
;
; while(TIMER)
;
	.dbg	line, "../../../ui/src/freezer.c", 613
L0340:	lda     $2004
;
; ;
;
	.dbg	line, "../../../ui/src/freezer.c", 614
	bne     L0340
;
; run_c64();
;
	.dbg	line, "../../../ui/src/freezer.c", 616
	jsr     _run_c64
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 617
	jmp     incsp1
	.dbg	line

.endproc

; ---------------------------------------------------------------
; void __near__ determine_d012 (__near__ unsigned char*, __near__ unsigned char*)
; ---------------------------------------------------------------

.segment	"DMACODE"

.proc	_determine_d012: near

.segment	"DMACODE"

;
; VIC_REG(26) = 0x01; // interrupt enable = raster only
;
	.dbg	line, "../../../ui/src/freezer.c", 74
	jsr     decsp1
	lda     #$01
	sta     $301A
;
; VIC_REG(25) = 0x81; // clear raster interrupts
;
	.dbg	line, "../../../ui/src/freezer.c", 75
	lda     #$81
	sta     $3019
;
; *b12 = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 79
	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	tay
	sta     (ptr1),y
;
; *b11 = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 80
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     #$00
	dey
	sta     (ptr1),y
;
; b = 0;
;
	.dbg	line, "../../../ui/src/freezer.c", 82
	sta     (sp),y
;
; while(!(VIC_REG(25) & 0x81)) {
;
	.dbg	line, "../../../ui/src/freezer.c", 83
L0018:	lda     $3019
	and     #$81
	bne     L0019
;
; if(!TIMER) {
;
	.dbg	line, "../../../ui/src/freezer.c", 84
	lda     $2004
	bne     L0018
;
; TIMER = 200;
;
	.dbg	line, "../../../ui/src/freezer.c", 85
	lda     #$C8
	sta     $2004
;
; b++;
;
	.dbg	line, "../../../ui/src/freezer.c", 86
	ldy     #$00
	lda     (sp),y
	clc
	adc     #$01
	sta     (sp),y
;
; if(b == 40)
;
	.dbg	line, "../../../ui/src/freezer.c", 87
	cmp     #$28
	bne     L0018
;
; *b12 = VIC_REG(18); // d012
;
	.dbg	line, "../../../ui/src/freezer.c", 92
L0019:	ldy     #$04
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     $3012
	ldy     #$00
	sta     (ptr1),y
;
; *b11 = VIC_REG(17); // d011
;
	.dbg	line, "../../../ui/src/freezer.c", 93
	ldy     #$02
	lda     (sp),y
	tax
	dey
	lda     (sp),y
	sta     ptr1
	stx     ptr1+1
	lda     $3011
	dey
	sta     (ptr1),y
;
; VIC_REG(26) = 0x00; // disable interrutps
;
	.dbg	line, "../../../ui/src/freezer.c", 95
	sty     $301A
;
; VIC_REG(25) = 0x81; // clear raster interrupt
;
	.dbg	line, "../../../ui/src/freezer.c", 96
	lda     #$81
	sta     $3019
;
; }
;
	.dbg	line, "../../../ui/src/freezer.c", 97
	jmp     incsp5
	.dbg	line

.endproc

