In this post I show how the virtual cursor is used and a routine to put single characters in a window. The functions introduced here are part of LIBWIN.ACT. The contents of my library, as well as an API reference, will be released in its entirety at the conclusion of the posts. The functions for this post are position (WPos) and put (WPut).
The WPos function is used to position the virtual cursor. It requires three parameters:
- Window handle number (n) – This also accepts WPABS which directs the position function to move the virtual cursor to an absolute screen position rather than a window based position.
- X position / column (x) – the column within the given window
- Y position / row (y) – the row within the given window
WPos returns either 0 (good) or an error code.
The functions works as follows:
- First, a default return code of 0 (good) is set.
- Next the window handle is checked to see if it is WPABS. If it is, the virtual cursor position is set to the x and y coordinates specified, which are absolute screen coordinates, not window coordinates.
- If the window handle is not set as WPABS, the window handles memory location is computed. The window handles status is then checked.
- If the window handle status is free, the routine sets the return code to the error code NOT OPEN and exits.
- If the window handle status is uses, the virtual cursors x and y positions are set relative the the windows frame coordinates. The routine then exits.
; -------------------------------------- ; Func..: BYTE WPos(BYTE n,x,y) ; Desc..: Moves cursor to x,y in window ; or x,y of screen ; Params: n = number of window handle ; or WPABS for screen ; x = column for cursor ; y = row for cursor ; Return: WERNOPN (not open) or ; 0 (good) ; -------------------------------------- BYTE FUNC WPos(BYTE bN,x,y) BYTE bR ; Set valid return bR=0 ; If absolute mode if bN=WPABS then ; Set screen coords vCur.vX=x vCur.vY=y else ; Find window handle record pWn=baW+(WRECSZ*bN) ; Only if handle in use if pWn.bS#WSFREE then ; Set relative to window vCur.vX=pWn.bX+x vCur.vY=pWn.bY+y else ; Set not open return code bR=WERNOPN fi fi RETURN(bR)
The WPut function puts a single character at the windowing systems virtual cursor position. The function requires two parameters:
- Window handle number (n)
- Character value to print (x) – This should be an ATASCII code. It will be converted to internal code.
The routine will return 0 (good) if successful, otherwise an error code.
The function works in the following manner:
- First, a default error return code of NOT OPEN is set.
- Next, the byte value passed is converted to a string.
- Then the window handles memory location is computed. The window handles status is then checked.
- If the window handles status is free, the routine exits returning the previously defined error code of NOT OPEN.
- If the window handles status is not free (in use), the routine converts the string to internal code from ATASCII code. If the windows inverse flag is set, the string is inversed.
- The screen memory location is computed, and the string (byte) is moved to that location. The virtual cursor position is then incremented by one just like a real cursor.
- A return code of 0 (good) is set and the routine exits.
; -------------------------------------- ; Func..: BYTE WPut(BYTE n,x) ; Desc..: Puts byte x in window ; at virtual cursor coord ; Params: n = number of window handle ; x = ATA byte to display ; Return: WERNOPEN (not open) or ; 0 (good) ; -------------------------------------- BYTE FUNC WPut(BYTE bN,x) BYTE bR CHAR ARRAY bC(2) CARD POINTER pS ; Set default return bR=WERNOPN ; Convert passed byte into string bc(0)=1 bC(1)=x ; Find window handle record pWn=baW+(WRECSZ*bN) ; Only if handle in use if pWn.bS#WSFREE then ; Convert byte from ATA to INT StrAI(bC) ; If window is inverse, flip byte if pWn.bI=WINVON then bC(1)==!128 fi ; Find screen loc based on vCur pS=RSCRN+(vCur.vY*40)+vCur.vX ; Move byte to screen ; pS^=bC(1) MoveBlock(pS,bC+1,1) ; Inc virtual cur by 1 vCur.vX==+1 ; Set return code bR=0 fi RETURN(bR)
The previously used demonstration program is expanded here to demonstrate WPos and WPut. Notable differences are the WPos() lines and WPut() lines. After the third window is cleared, WPos and WPut are used to draw a line of asterisks in the window.
; 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,7,WINVOFF) WTitle(bW1,"One") WPrint(bW1,1,1,"Row 1 Column 1") WPrint(bW1,1,5,"Unfinished Bitness") ; Open window 2 bW2=WOpen(5,15,30,6,WINVON) WTitle(bW2,"TWO") WPrint(bW2,2,2,"2,2") WPrint(bW2,WPCENT,4,"Inverse ATASCII Podcast") ; Open window 3 bW3=WOpen(15,8,10,10,WINVOFF) WTitle(bW3,"Three") WPrint(bW3,1,3,"Hello") WPrint(bW3,3,5,"Hello") WPrint(bW3,1,7,"Hello") ; Wait for a keystroke or console key WaitKC() ; Clear window 3 WClr(bW3) ; Draw \ in window 3 WPos(bW3,1,1) WPut(bW3,42) WPos(bW3,2,2) WPut(bW3,42) WPos(bW3,3,3) WPut(bW3,42) WPos(bW3,4,4) WPut(bW3,42) WPos(bW3,5,5) WPut(bW3,42) ; Wait for a keystroke or console key WaitKC() ; Close window 3 WClose(bW3) ; Close window 2 WClose(bW2) ; Close window 1 WClose(bW1) RETURN
These screen shots depict the results when the program is run. The first screenshot shows the windows open and populated, and waiting for a keystroke:
Once a key is pressed, window 3 is cleared, then WPos() and WPut() are used to draw a line using asterisks in window 3. It is again waiting for a keystroke:
After the windows are all closed, control is returned to the Action! cartridge:
The next post will include a function for getting the status of a window handle.