#include "memmap.i65"

; sysinfo.a65: display sysinfo text block
.byt "===SHOW_SYSINFO==="
show_sysinfo:
	php
	sep #$20 : .as
	rep #$10 : .xl
	stz bar_wl
	dec bar_wl
	stz bar_xl
	dec bar_xl
	stz bar_yl
	dec bar_yl
	jsr backup_screen
	lda #^text_mm_sysinfo
	sta window_tbank
	ldx #!text_mm_sysinfo
	stx window_taddr
	lda @sysinfo_win_x
	sta window_x
	inc
	inc
	pha
	stz print_x+1
	lda @sysinfo_win_y
	sta window_y
	inc
	inc
	pha
	stz print_y+1
	lda @sysinfo_win_w
	sta window_w
	lda @sysinfo_win_h
	sta window_h
	jsr draw_window
	stz print_pal
	
	ldx #38
copy_snes_system_text:
	lda @text_system,x
	sta @snes_system_config,x
	dex
	bpl copy_snes_system_text
	
sysinfo_printloop:
	sep #$20 : .as
	rep #$10 : .xl
	lda #CMD_SYSINFO
	sta @MCU_CMD
	lda #^SYSINFO_BLK
	ldx #!SYSINFO_BLK
	sta print_bank
	stx print_src
	stz print_pal
	pla
	sta print_y
	pla
	sta print_x
	lda #40
	sta print_count
	lda #12
-	pha
	jsr hiprint
	inc print_y
	rep #$20 : .al
	lda print_src
	clc
	adc #40
	sta print_src
	sep #$20 : .as
	pla
	dec
	bne -
	
	ldx #24
	lda $213e
	and #$0f
	clc
	adc #$30
	sta @snes_system_config,x
	
	ldx #38
	lda $213f
	and #$0f
	clc
	adc #$30
	sta @snes_system_config,x
	
	ldx #10
	lda $4210
	and #$0f
	clc
	adc #$30
	sta @snes_system_config,x		
	
	lda #^snes_system_config		; System text
	ldx #!snes_system_config
	sta print_bank
	stx print_src
	stz print_pal
	lda #39
	sta print_count
	lda #23
	sta print_y
	lda #12
	sta print_x
	jsr hiprint		
	
-	lda isr_done
	lsr
	bcc -
	jsr printtime
	jsr read_pad
	lda #$80
	and pad1trig
	bne +
	lda #$80
	and pad1trig+1
	bne +
	lda @sysinfo_win_x
	inc
	inc
	pha
	lda @sysinfo_win_y
	inc
	inc
	pha
	jmp sysinfo_printloop
+	plp
	jsr restore_screen
	lda #$00
	sta @MCU_CMD
	rtl
