home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Low Level Languages / Rm Cobol V2.2 / DECFKEY.ASM < prev    next >
Encoding:
Assembly Source File  |  1985-09-20  |  6.5 KB  |  195 lines

  1.     page    63, 132
  2.     title    DECFKEY, example function key handler for RM/COBOL 2.1
  3. ; SCCS information:
  4. ;@(#) decfkey.asm  ver. 1.3 last update 85/09/20 10:30:43
  5. ;@(#) This source obtained from the s file on 85/09/20 at 10:31:06
  6. ;
  7. ;      SUBROUTINE TO HANDLE RAINBOW-100 KEYBOARD FUNCTION KEYS.
  8. ;
  9. ;      The following keys on the keyboard will be recognized:
  10. ;
  11. ;
  12. ;    Key     Sequence    Returned       Key     Sequence    Returned
  13. ;                        Value                              Value
  14. ;                        (decimal)                          (decimal)
  15. ;
  16. ;    Find    ESC [ 1 ~          1       Insert   
  17. ;    Remove  ESC [ 3 ~          3         Here  ESC [ 2 ~           2
  18. ;    Select  ESC [ 4 ~          4       Prev
  19. ;    Next                                Screen ESC [ 5 ~           5
  20. ;     Screen ESC [ 6 ~          6       Up
  21. ;    Down                                 Arrow ESC [ A            65
  22. ;      Arrow ESC [ B           66       Right
  23. ;    Left                                 Arrow ESC [ C            67
  24. ;      Arrow ESC [ D           68
  25. ;    Compose ESC [ 1 0 ~       10       F4      ESC [ 1 4 ~        14
  26. ;    Interrupt                          Resume  ESC [ 1 8 ~        18
  27. ;            ESC [ 1 7 ~       17       Cancel  ESC [ 1 9 ~        19
  28. ;    Main                               Exit    ESC [ 2 1 ~        21
  29. ;     Screen ESC [ 2 0 ~       20       Addtnl 
  30. ;    Help    ESC [ 2 8 ~       28       Options ESC [ 2 6 ~        26
  31. ;    Do      ESC [ 2 9 ~       29       F17     ESC [ 3 1 ~        31
  32. ;    F18     ESC [ 3 2 ~       32       F19     ESC [ 3 3 ~        33
  33. ;    F20     ESC [ 3 4 ~       34       PF1     ESC O P            80
  34. ;    PF2     ESC O Q           81       PF3     ESC O R            82
  35. ;    PF4     ESC O S           83
  36. ;    others  ESC O 'anychar'   Value of 'anychar' is returned
  37. ;
  38. ;          EQUATES
  39. ;
  40. ASCIIZERO      EQU     030H
  41. ASCIIONE       EQU     031H
  42. ASCIISIX       EQU     036H
  43. ASCIININE      EQU     039H
  44. LETTEROH       EQU     04FH
  45. LEFTBRAKET     EQU     05BH
  46. ESC            EQU     01BH
  47. code segment byte public 'code'
  48.     assume cs:code, ds:code
  49. main    proc    far
  50. ;
  51. ;    This program must be a .COM type in order for it to link
  52. ;    successfully with the RUNCOBOL.COM file using the RM/COBOL
  53. ;    utility RMCLNK.  .COM files must have the ORG 100 statement.
  54.     ORG      100H             ;USING 8080 MEMORY MODEL
  55. ;
  56. ;           LINKED ASSEMBLY TABLE
  57. ;
  58.      DW       ENDCODE              ;POINTS TO LAST LOCATION
  59.      DB       6                    ;LENGTH OF 'FUNKEY'
  60.      DB       'FUNKEY'             ;PROGRAM NAME
  61.      DW       FUNKEY               ;ENTRY POINT
  62.      DB       0                    ;END OF TABLE
  63. ;  Sccs information :
  64.         db    '@ #( ) (@)#@(#)'    ;SCCS id.
  65.         db    'decfkey.asm'        ;Program name % M %.
  66.         db    ' ver. '
  67.         db    '1.3'        ;version % I %.
  68.         db    ' 85/09/20 '        ;date % E %.
  69.         db    '10:30:43'        ;time % U %.
  70.         db    '>'        ;Ending indicator.
  71. ;
  72. ;    To link this subroutine into the runtime,
  73. ;    use the RM/COBOL utility RMCLNK to combine the RUNCOBOL.COM
  74. ;    file and this .COM file.
  75. ;    To enable this subroutine, the location FCHANDLE, at 014C of
  76. ;    the configuration tables must be changed to be the offset of
  77. ;    the location FUNKEY.  The RM/COBOL configuration utility
  78. ;    RMCNFG can be used to configure the linked runtime such that
  79. ;    the runtime will call FUNKEY when exception characters are
  80. ;    recognized.  On the RMCNFG configuration menu, FCHANDLE is
  81. ;    the label 'Fkey Addr', and must be set to 0142, which is the
  82. ;    offset of FUNKEY when assembled with MASM and linked with LINK.
  83. ;
  84. ;    Instead of linking this subroutine into the RUNCOBOL.COM file,
  85. ;    the automatic loading of this subroutine can be configured by
  86. ;    setting the location LINKTBL (Link Addr label on the RMCNFG
  87. ;    menu) at 12A of the configuration tables to be FFFF (-1).
  88. ;    Also the file name of this .COM file ('DECFKEY.COM') must be
  89. ;    configured as the name of LNKFCB (Hex Filename on the RMCNFG
  90. ;    menu) at location 12D of the configuration tables.  The presence
  91. ;    of the -1 at LINKTBL directs the runtime to automatically load
  92. ;    the file whose name is found at LNKFCB before the RM/COBOL
  93. ;    programs begin execution. And to enable this subroutine the
  94. ;    location FCHANDLE must be set to be the offset of FUNKEY as
  95. ;    described above for the linked example.
  96. ;
  97. ;
  98. FUNKEY:
  99.             ;It is safe to assume that RUNCOBOL will
  100.             ;save it's own registers
  101.     MOV    DL,AL    ;Enters with first character
  102.             ;in AL, save in DL, which is our
  103.             ;answer register
  104.     CMP    AL,ESC        ;Must be escape
  105.     JNZ    FIRSTOK        ;No, return that first char
  106.     CALL    INCHAR        ;GET NEXT CHARACTER
  107.     CMP    AL,LEFTBRAKET    ;Next is '['
  108.     JZ    YESBRAKET
  109.     CMP    AL,LETTEROH    ;Well, maybe the letter 'O'
  110.     JNZ    ERROR        ;Must be something else
  111.     CALL    INCHAR        ;The next char is the result
  112.     MOV    DL,AL        ;In the answer register
  113.     JMP    FIRSTOK        ;Exit
  114. YESBRAKET:
  115.     CALL    INCHAR        ;GET NEXT CHARACTER
  116.     MOV    CL,AL        ;Remember it in CL
  117.     SUB    AL,ASCIIONE
  118.     JC    ERROR        ;Less than one
  119.     MOV    AL,ASCIISIX    ; 6
  120.     SUB    AL,CL
  121.     JNC    FIRSTINRANGE    ;LESS THAN 7, that is OK
  122.     MOV    AL,CL        ;Check for A,B,C,D
  123.     SUB    AL,'A'
  124.     JC    ERROR        ;Less than 'A'
  125.     MOV    AL,'D'
  126.     SUB    AL,CL
  127.     JC    ERROR        ;Greater than 'D'
  128.     MOV    DL,CL        ;DL has the answer
  129.     JMP    FIRSTOK
  130. FIRSTINRANGE:
  131.     MOV    AL,CL        ;Back to the first digit
  132.     SUB    AL,ASCIIZERO    ;MAKE IT BINARY
  133.     MOV    DL,AL        ;NOW IN RANGE, SAVE IN DL
  134.     CALL    INCHAR        ;NEXT CHARACTER
  135.     MOV    CL,AL        ;Remember in CL
  136.     CMP    AL,'~'        ;MAYBE THIS
  137.     JZ    FIRSTOK        ;THEN DONE
  138.     SUB    AL,ASCIIZERO    ;Range check
  139.     JC    ERROR        ;LESS THAN 0
  140.     MOV    AL,ASCIININE    ; 9
  141.     SUB    AL,CL
  142.     JC    ERROR        ;GREATER THAN 9
  143.     MOV    AL,CL
  144.     SUB    AL,ASCIIZERO    ;MAKE IT BINARY
  145.     MOV    CH,AL        ;SAVE IN CH
  146.     MOV    AL,DL        ;PREVIOUS DIGIT
  147.     SAL    AL,1
  148.     MOV    CL,AL        ;DIGIT1 * 2 IN CL
  149.     SAL    AL,1        ;     * 4
  150.     SAL    AL,1        ;     * 8
  151.     ADD    AL,CL        ;SUM IS * 10
  152.     ADD    AL,CH        ;PLUS SECOND DIGIT
  153.     MOV    DL,AL        ;RETURN VALUE, SAVE IN DL
  154.     CALL    INCHAR        ;LAST CHARACTER MUST BE '~'
  155.     CMP    AL,'~'
  156.     JNZ    ERROR
  157. FIRSTOK:
  158.     XOR    AL,AL        ;Set ZERO flag for all OK
  159.     MOV    AL,DL        ;Returned value is in DL,
  160.     RET            ;RETURN ZERO -> SUCCESS
  161. ERROR:
  162.     OR    AL,1        ;NON-ZERO -> FAILURE
  163.     RET
  164. main    endp
  165. ;
  166. ;
  167. INCHAR    proc    near
  168.     PUSH    DX        ;Save answer register
  169.     MOV    DL,0FFH        ;0FFH -> INPUT FUNCTION
  170. INCHAR1:
  171.     MOV    AH,06H        ;#6 = RAW CONSOLE I/O
  172.     PUSH    BX
  173.     PUSH    CX
  174.     PUSH    DX
  175.     PUSH    DS
  176.     PUSH    ES
  177.     INT    021H    ;Call MSDOS
  178.     POP    ES
  179.     POP    DS
  180.     POP    DX
  181.     POP    CX
  182.     POP    BX
  183.     OR    AL,AL
  184.     JZ    INCHAR1        ;Wait for a character to be typed
  185.     POP    DX        ;Restore answer register
  186.     RET
  187. inchar    endp
  188. ENDCODE:
  189. code    ends
  190. stack    segment    byte    stack    'stack'
  191.     assume    ss:stack
  192. stack    ends
  193.     END    FUNKEY        ;Theoretical entry point
  194.                 ;if this was a normal program
  195.