Sunday, November 17, 2019

ACSL AGRAM - PC/370 - Keyboard Input


Previous AGRAM Card Game Posts:
ACLS AGRAM Card Game Exercise - Just for Fun
ACLS AGRAM Card Game - PC/370 Version

In this post I'll add another variation to the PC/370 version of the AGRAM Card Game. As I explained in the previous posts the AGRAM theme was part of my daughter's computer lab assignment. So far I created 3 program versions - SQR, WinBatch & PC/370 Assembler.

The previous PC/370 Assembler version used File I/O - An input file containing the Opponent/Dealer hands & an output file to log the results. Now I'll create a PC/370 version that builds an input screen & accepts direct keyboard entry - this will be similar in function to the WinBatch GUI version.

WinBatch Data Entry:

In WinBatch, the data entry screen was built using a GUI tool (called a Dialog Editor) which generates the code for you - just insert into the program. To utilize the screen just call the Dialog() function. Very simple.

   ButtonPushed         = Dialog("TD")



PC/370 Data Entry Screen:

PC/370 Assembler is much different. The developer is responsible for each character displayed & every key that is pressed. Video mode, X/Y coordinates, colors, boxes, reverse video, blinking, etc... These are all controlled by elaborate bit settings & DOS Interrupts that emulate MVS/370 Supervisor Calls and must be constructed properly in your program.


Above: Quick template I constructed where you can enter the Opponent Card & Dealer Hand (comma delimited string).

The full AGRAM program (TDAGRAM) including the logic of the game was displayed in the last post. This post will focus on the changes to convert it to Screen/Keyboard input. This version will be called TDAGRAM2.

Copybooks:
I'll start with a listing of the custom CopyBooks utilized by the program. These take care of all the critical Screen, Keyboard & Data Entry functions. I developed these in the fall of 1996.

***********************************************************************
*        COPYBOOKS                                                    *
***********************************************************************
         COPY  CPY/TDBOX.CPY                 COPYBOOK - BOX DISPLAY
         COPY  CPY/TDVID.CPY                 COPYBOOK - VIDEO UTILITY
         COPY  CPY/TDACC.CPY                 COPYBOOK - ACCEPT INPUT
         COPY  CPY/TDKBD.CPY                 COPYBOOK - KEYBOARD INPUT
         COPY  CPY/TDEDT.CPY                 COPYBOOK - EDITOR UTILITY
         COPY  CPY/TDKEY.CPY                 COPYBOOK - KEYSTROKES
         COPY  CPY/TDCLR.CPY                 COPYBOOK - COLORS
         COPY  CPY/TDSVC.CPY                 COPYBOOK - SUPERVISOR
***********************************************************************


Main Procedure:
The main logic is very similar to the prior version. Instead of reading from a file the SCREEN routine is called. If the <ESCAPE> key was pressed the process terminates. Otherwise the AGRAM logic kicks in - PARSE, SELECT & RESULT - then it loops back to display the screen again.

***********************************************************************
*        MAINLINE PROCEDURE                                           *
***********************************************************************
         PRINT NOGEN
         SVC   @TRACE                        ISSUE SUPERVISOR CALL
         DC    CL4'IOF '                     KEYBOARD INTERRUPT OFF
*
MAIN     EQU   *
         BAL   6,SCREEN                      BUILD SCREEN
*
         CLI   KEY,@K#ESC                    KEY = ESCAPE ???
         BE    MAINX                         YES - EXIT PLEASE

*
         BAL   6,PARSE                       PARSE RECORD
         BAL   6,SELECT                      SELECT CARD
         BAL   6,RESULT                      PRINT RESULT
*
         B     MAIN                          LOOP AGAIN
MAINX    EQU   *
         B     RETURN                        EXIT PROGRAM PLEASE
***********************************************************************


I designed the SCREEN Build routines to be dynamic - all activity is driven by a series of configuration tables. First, the screen is cleared using VRESET. Then a BOX is displayed around the screen (0,0 thru 23,79) using the VBOX routine. Static text is plotted & displayed using the VXYS routine & @WTO (Write to Operator) Supervisor Call. Finally, the ACCDAT routine is called to Accept Data entry of the two fields (OPPONENT & DEALER HAND). The table AKEY defines all the acceptable EXIT keys for the routine while the ATAB table defines each "edit" field on the page - address, length, coordinates, datatype & video settings. The <ESCAPE> & <F1> keys break out of the routine.

***********************************************************************
*        BUILD SCREEN                                                 *
***********************************************************************
         DC    F'0'                          RETURN ADDRESS SAVE AREA
SCREEN   EQU   *
         ST    6,*-4                         SAVE RETURN ADDRESS
*
         MVI   VBITS,@BKWT                   SET BG(BLACK)/FG(WHITE)
         BAL   6,VRESET                      CHANGE SCREEN ATTRIBUTES
*
*        DISPLAY SINGLE BOX
*
         MVC   VBX,VBOX2                     LOAD BOX FRAME
         MVC   VBXRC,BXTAB                   LOAD BOX COORDINATES
         BAL   6,VBOX                        DISPLAY BOX FRAME
*
*        DISPLAY SCREEN TEXT
*
         LA    5,SCTAB                       LOAD TABLE ADDRESS
SC1LP    EQU   *
         CLI   0(5),X'FF'                    END OF TABLE ???
         BE    SC1LPX                        YES - EXIT LOOP PLEASE
*
         MVC   VXYS,0(5)                     MOVE CURSOR POSITION
         BAL   6,VXYSET                      SET CURSOR POSITION
         L     2,4(5)                        LOAD MESSAGE ADDRESS
         SVC   @WTO                          ISSUE SUPERVISOR CALL
*
         LA    5,8(,5)                       BUMP TABLE POINTER
         B     SC1LP                         TEST NEXT TABLE ENTRY
SC1LPX   EQU   *
*
*        ACCEPT INPUT DATA
*
         MVC   ACCKEYX,=A(AKEY)              LOAD EXIT KEY TABLE
         LA    5,ATAB                        LOAD TABLE ADDRESS
SC2LP    EQU   *
         CLI   0(5),X'FF'                    END OF TABLE ???
         BNE   *+8                           NO  - CONTINUE PLEASE
         LA    5,ATAB                        LOAD TABLE ADDRESS
*
         MVC   ACCPARM,0(5)                  MOVE ACCEPT PARMS
         BAL   6,ACCDAT                      ACCEPT INPUT DATA
*
         CLI   KEY,@K#ESC                    KEY = ESCAPE ???
         BE    SC2LPX                        YES - EXIT LOOP PLEASE
         CLI   KEY,@K#F1                     KEY = F1 ???
         BE    SC2LPX                        YES - EXIT LOOP PLEASE
*
         CLI   KEY,@K#ARWU                   KEY = ARROW UP ???
         BE    SC2LPU                        YES - BUMP BACKWARDS
         CLI   KEY,@K#ARWL                   KEY = ARROW LEFT ???
         BE    SC2LPU                        YES - BUMP BACKWARDS
         CLI   KEY,@K#TABL                   KEY = TAB LEFT ???
         BE    SC2LPU                        YES - BUMP BACKWARDS
*
         LA    5,12(,5)                      BUMP TABLE POINTER
         B     SC2LP                         TEST NEXT TABLE ENTRY
SC2LPU   EQU   *
         SH    5,=Y(12)                      BUMP TABLE POINTER
         C     5,=A(ATAB)                    TABLE AT TOP ???
         BNL   SC2LP                         NO  - TEST NEXT ENTRY
         LA    5,ATABX-12                    LOAD LAST ENTRY ADDRESS
         B     SC2LP                         TEST NEXT TABLE ENTRY
SC2LPX   EQU   *
         MVI   VBITS,@BKWT                   SET BG(BLACK)/FG(WHITE)
         BAL   6,VRESET                      CHANGE SCREEN ATTRIBUTES
SCREENX  EQU   *
         L     6,SCREEN-4                    RESTORE LINK REGISTER
         BR    6                             BRANCH ON LINK REGISTER
***********************************************************************


Screen/Key Configuration Tables:
BXTAB defines the box coordinates used by the VBOX routine - here a simple 24x80 enclosure for the page. SCTAB writes static text to the screen using x/y coordinates & the address of static text field(s). Each static text definition ends in a "$" sign (required by WTO supervisor call). Finally, the AKEY & ATAB tables are passed to control data entry. This controls how the user enters data, tabs from one field to another & exits the routine. The screen may appear simple, even primitive, but there's a lot behind the scenes to consider.

***********************************************************************
*        BOX COMPONENTS (COORDINATES/FRAME)                           *
***********************************************************************
BXTAB    DS    0F
         DC    AL1(0,0,23,79)                BOX COORDINATES/FRAME
***********************************************************************
*        SCREEN DISPLAY COMPONENTS                                    *
***********************************************************************
SCTAB    DS    0F
         DC    AL1(0,0,4,8),A(SCR01)         SCREEN COORDINATES/MSG
         DC    AL1(0,0,6,8),A(SCR02)         SCREEN COORDINATES/MSG
         DC    AL1(0,0,8,8),A(SCR03)         SCREEN COORDINATES/MSG
         DC    AL1(0,0,10,8),A(SCR04)        SCREEN COORDINATES/MSG
*        DC    AL1(0,0,12,8),A(SCR05)        SCREEN COORDINATES/MSG
SCTABF1  DC    AL1(0,0,15,8),A(SCR99F1)      SCREEN COORDINATES/MSG
         DC    AL1(0,0,17,8),A(SCR99X)       SCREEN COORDINATES/MSG
         DC    XL1'FF'                       END OF TABLE
***********************************************************************
SCR01    DC    C'T D A G R A M 2   -   KEYBOARD INPUT$'
SCR02    DC    C' OPPONENT:',C'$'
SCR03    DC    C'   DEALER:',C'$'
SCR04    DC    C'   RESULT:   ',C'$'
SCR05    DC    CL60' ',C'$'
SCR99F1  DC    C'PRESS <F1> TO SELECT',C'$'
SCR99X   DC    C'PRESS <ESC> TO EXIT SCREEN',C'$'
***********************************************************************
*        ACCEPT DATA COMPONENTS - TABLE A                             *
***********************************************************************
AKEY     DC    AL1(@K#ESC,@K#RET,@K#ARWU,@K#ARWD,@K#TAB,@K#TABL,@K#F1)
AKEYX    DC    X'FF'
***********************************************************************
ATAB     DS    0F
         DC    A(AC1),AL2(L'AC1),AL1(6,19,@E#CHR,0,@BKWT,@WTBK)
         DC    A(AC2),AL2(L'AC2),AL1(8,19,@E#CHR,0,@BKWT,@WTBK)
ATABX    DC    XL1'FF'
***********************************************************************
AC1      DC    CL2' ',C'$'                   ACCEPT - OPPONENT
AC2      DC    CL50' ',C'$'                  ACCEPT - DEALER HAND
***********************************************************************


There's too much information to explain in a single post - especially when it comes to the internals of the routines contained in the Copybooks. I'll save these for another time...