In this post I show how the windowing system close routine works, as well as introduce a window titling routine. All of the routines presented here are part of the window library LIBWIN.ACT.
Close (WClose)
The close routine takes one parameter when called – the window handle to close. Windows can be closed out of sequence, but new windows should not be opened until all the topmost windows have been closed. If you do want to close and open a new window in the middle of the stack, the window size of the new window MUST be identical to prevent overwriting another windows screen buffer memory.
The close routine works in the following manner:
- First it sets the default return code to an error code of NOT OPEN. This assumes the window handle specified is not currently open.
- It then computes the location of the windows handle within the window handle memory.
- Then, if the windows handle status is free, the routine exits passing back the default error code NOT OPEN.
- If the windows handle status is not free, it computes the location of the top left corner of the window in screen memory, then restores the screen contents the window was covering one line at a time from top to bottom by copying the saved screen contents from the windows screen buffer memory. Then the windows screen buffer memory is cleared and the pointer to the next free space is moved to the start of this windows screen buffer memory. Last, the window handles attributes are reset, the return code of 0 (good) is set and the routine exits.
; -------------------------------------- ; Func..: BYTE WClose(BYTE n) ; Desc..: Closes a window ; Params: n = number of window handle ; Return: 0 if success ; >100 on error ; -------------------------------------- BYTE FUNC WClose(BYTE bN) BYTE bR,bL CARD POINTER cS,pM ; Set default return code bR=WERNOPN ; Find window handle record pWn=baW+(WRECSZ*bN) ; Only if handle in use if pWn.bS#WSFREE then ; Find top left corner of window ; in screen memory cS=RSCRN+(pWn.bY*40)+pWn.bX ; Set temp ptr to start of win mem pM=pWn.cM ; Restore screen line by line for bL=0 to pWn.bH-1 DO ; Restore underlying scrn from win mem MoveBlock(cS,pM,pWn.bW) ; Inc mem ptr index by width pM==+pWn.bW ; Inc scr by 40 to next line start cS==+40 OD ; Clear window memory Zero(pWn.cM,pWn.cZ) ; Set win mem ptr to prev location cpWM==-pWn.cZ ; Clear handle pWn.bS=WSFREE pWn.bX=0 pWn.bY=0 pWn.bW=0 pWn.bH=0 pWn.bI=WINVOFF pWn.cM=baWM ; point at base storage pWn.cZ=0 ; Set return bR=0 fi RETURN(bR)
Title (WTitle)
The title routine sets the windows title. It requires two parameters; the window handle, and a pointer to the string containing the title. Titles should be at least 4 characters smaller than the window width. If successful, it returns 0 (good). If something went wrong, it returns an error code.
The routine works in the following manner:
- First a default error return code of NOT OPEN is assigned. This assumes the window handle specified is not currently open.
- It then computes the location of the windows handle within the window handle memory.
- Then, if the windows handle status is free, the routine exits passing back the default error code NOT OPEN.
- If the windows handle status is used, it builds a string to present in memory which is a copy of the passed title, but includes bookends. This string is then converted from ATASCII to internal character code because the string will be copied directly into screen memory rather than through CIO. If the window was specified as inverse, the entire built title string is inversed including the bookends, otherwise just the title is inversed. Finally, the titles location in screen memory is computed, and the built title string is copied directly to screen memory to that location.
- Then the return code is set to 0 (good) and the routine exits.
; -------------------------------------- ; Func..: BYTE WTitle(BYTE n ; CARD POINTER s) ; Desc..: Add title decor to window ; Params: n = number of window handle ; s = Title string pointer ; Notes.: Max 36 for frame and bookends ; Return: 0 if success ; >100 on error ; -------------------------------------- BYTE FUNC WTitle(BYTE bN CARD POINTER pS) BYTE bR CHAR ARRAY cL(36) CARD POINTER cS ; Set default return code bR=WERNOPN ; Find window handle record pWn=baW+(WRECSZ*bN) ; Only if handle in use if pWn.bS=WSUSED then ; Create title string ; Copy string SCopy(cL+1,pS) ; Set open bookend cL(1)=4 ; Set close bookend cL(pS(0)+2)=1 ; Set string len to include bookends cL(0)=pS(0)+2 ; Convert from ATA to INT StrAI(cL) ; If inverse on, inverse all if pWn.bI=WINVON then ; Skip first 1b (str len) StrInv(cL+1,cL(0)) ; Else inverse off, inverse only text else ; Skip first 2b (str len,bookend) ; Skip last 1b (bookend) StrInv(cL+2,cL(0)-2) fi ; Find top left corner +1 of window ; in screen memory cS=RSCRN+(pWn.bY*40)+pWn.bX+1 ; Move title to screen MoveBlock(cS,cL+1,cL(0)) ; Set valid return bR=0 fi RETURN(bR)
Usage
To demonstrate the newly introduced functions, this small program is employed. It adds in two more files from my Action! library. They are required to use the function WaitKC(). WaitKC waits for a keystroke or console key press. These files are:
- DEFINES.ACT – Definitions used by my Action! library routines.
- LIBMISC.ACT – Miscellaneous functions. Pulled in for WaitKC().
Notable changes in the demonstration program are the addition of the WTitle() lines, WClose() lines, and the WaitKC() line.
; Program: WINDOW.ACT ; Author.: Wade Ripkowski ; Date...: 2016.04 ; Desc...: Test Windowing Library ; License: Creative Commons ; Attribution-NonCommercial- ; NoDerivatives ; 4.0 International ; Include library INCLUDE "D3:DEFINES.ACT" INCLUDE "D3:DEFWIN.ACT" INCLUDE "D3:LIBSTR.ACT" INCLUDE "D3:LIBWIN.ACT" INCLUDE "D3:LIBMISC.ACT" ; Start MODULE PROC Main() ; Window handles BYTE bW1,bW2,bW3 ; Init Window System WInit() ; Open window 1 bW1=WOpen(10,5,20,6,WINVOFF) WTitle(bW1,"One") ; Open window 2 bW2=WOpen(5,15,30,6,WINVON) WTitle(bW2,"TWO") ; Open window 3 bW3=WOpen(15,8,10,8,WINVOFF) WTitle(bW3,"Three") ; Wait for a keystroke or console key WaitKC() ; Close window 3 WClose(bW3) ; Close window 2 WClose(bW2) ; Close window 1 WClose(bW1) RETURN
Results
Running the demonstration program produces the following. The first screen shot is after the windows have been opened with titles applied, and is waiting for a keystroke. The wait was required due to the window system speed. Without the wait, it would just blink. Yes, its that fast.
This screen shot shows the windows have been closed and control has returned to the Action! cartridge (top line):
The next post will include a routine to print a string to a window, and a routine to clear a windows contents.