'///
'/// List 5a: saving screen state in a RAM segment
'///

@macro	R_SEGI	e=usr(3)	'Reading from a segment with autoincrement
@macro	WSEGI	e=usr(7)	'Idem for writing

'Segment and address where we will save state
'As usual, you must define it as you want

@define STA_SEG 6
@define STA_DIR 0

@define VARIABLE v	'For a loop

'System variables we will save

@define LINLEN &HF3B0	'Current WIDTH
@define CRTCNT &HF3B1	'Number of lines on screen
@define CLIKSW &HF3DB	'Key click sound, (0=no, other=yes)
@define CNSDFG &HF3DE	'KEY ON (0) / OFF (other)
@define FORCLR &HF3E9	'Text color
@define BAKCLR &HF3EA	'Back color
@define BDRCLR &HF3EB	'Border color
@define SCRMOD &HFCAF	'Current SCREEN

'We save state with a simple loop
'(Ok, I said before that it is better to not use DATAs in order to save 
'memory... but this is just a sample! Besides you surely will put this code 
'in a short initialization program rather than in the main program)

~	p(0)= STA_SEG:
	p(1)= STA_DIR:
	restore ~VARIABLES

~	read @VARIABLE:
	if @VARIABLE<> 0 then
	p(2)= peek (@VARIABLE):
	@W_SEGI:
	goto ~~

~DONE: 'Here life goes on...

..

'Here you have the used system variables, be careful to not modify
'the variables order in the DATA line, else list 5b will not work!

~VARIABLES:
	data	@SCRMOD, @LINLEN, @CRTCNT, @CLIKSW, @CNSDFG,
		@FORCLR, @BAKCLR, @BORCLR, 0
