I worked out something for my "multiple windows" routine. Let's see if I can track it down...
(An aside, if the program itself is defining all the windows, it's easier for the program itself to keep track of the VDU state, which is what *TALK does with its three windows.)
Ah ha, found it. PROC_DWIND() defines a window, FN_WIND() selects a window within a PRINT sequence, saving the current state and selecting the selected state.
Code: Select all
1000 DEFPROC_DWIND(wind%,a%,b%,c%,d%)
1010 LOCAL BA%
1020 IF wind%>7 OR wind%<0 THEN ENDPROC
1030 BA%=wind%*9+&411
1040 ?BA%=0:?(BA%+1)=0
1050 ?(BA%+2)=a%:?(BA%+3)=b%:?(BA%+4)=c%:?(BA%+5)=d%
1060 ?(BA%+6)=?&D2:?(BA%+7)=?&D3:?(BA%+8)=?&358
1070 ENDPROC
1080 DEFFN_WIND(w%)
1090 IF w%<0 OR w%>7 THEN =""
1100 LOCAL BA%
1110 BA%=(7 AND (?&410))*9+&411
1120 ?BA%=POS:BA%?1=VPOS:?(BA%+6)=?&D2:?(BA%+7)=?&D3:?(BA%+8)=?&358
1130 BA%=w%*9+&411
1140 VDU 28,?(BA%+2),?(BA%+3),?(BA%+4),?(BA%+5)
1150 VDU31,?BA%,?(BA%+1)
1160 ?&410=w%:?&D2=?(BA%+6):?&D3=?(BA%+7):?&358=?(BA%+8)
1170 =""
POS and VPOS are found and restored the usual way. The rest is very messy.
It looks like it saves each window's data in BASIC's workspace in page 4.
The text window size isn't saved from the VDU state, it's saved from what was set with PROC_DWIND()
The colours are saved and written with the VDU workspace colour masks.
If I was writing that now, I'd:
* Read window state with OSBYTE 160 from
VDU variables 0-7
* Read POS,VPOS with POS,VPOS
* Read current colours with
OSBYTE 160
* Read the graphics positions with
OSWORD 13
* Read the palette with
OSWORD 11 (though the palette is a global state)
and
* Write the window state with VDU
* Write the POS,VPOS with VDU
* Write the current colours with VDU
* Write the graphics positions with VDU
Ideally, get the saved state to be such that you can just plough through a block of VDUs to restore it. So, starting from the target, I'd want to build up:
VDU 28,a,b,c,d, 24,a,b,c,d,e,f,g,h, 29,a,b,c,d, 25,k,a,b,c,d, 25,k,a,b,c,d, 31,a,b, 17,a, 17,128+b, 18,a,b, 18,a,128+b
textwindow ..... graphicwindow ....... origin .... previous ..... current ... pos/vpos txfgd .. txbgd .. gfgd .... gbgd
That would be 44 bytes.
A quick'n'dirty solution could be to save/restore:
* VDU zero page &D0-&D5
* VDU workspace &00-&19 window state
* VDU workspace &57-&5C colour state
* VDU workspace &66-&6E graphics state
That would be 47 bytes.
Something like:
REM Save VDU state
store%=saved state
addr%=&D0:off%=0
REPEAT
store%?off%=FNmem_rd(addr%)
addr%=addr%+1
IF addr%=&0D6:addr%=&300
IF addr%=&31A:addr%=&357
IF addr%=&35D:addr%=&366
off%=off%+1
UNTIL off%=48
REM Restore VDU state
store%=saved state
addr%=&D0:off%=0
REPEAT
PROCmem_wr(addr%,store%?off%)
addr%=addr%+1
IF addr%=&0D6:addr%=&300
IF addr%=&31A:addr%=&357
IF addr%=&35D:addr%=&366
off%=off%+1
UNTIL off%=48
I've a suspision that you need to do VDU 31,x,y to program the hardware cursor, just writing the variables won't be enough.