home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / decus / RB140 / grlib03a.arj / MSDOS.ASM < prev    next >
Assembly Source File  |  1988-12-08  |  9KB  |  430 lines

  1. PAGE 60,132
  2. title MSDOS.ASM
  3. ;UPDATE HISTORY
  4. ;==============
  5. ; 29-11-84  Preserve ES register across int 18 in kbd calls
  6.  
  7. ;---------------------------------------------------------------+
  8. ;                                |
  9. ;        Definitions for 'C' Modules            |
  10. ;                                |
  11. ;---------------------------------------------------------------+
  12.  
  13.     include asmc.h
  14.     include asmk.h
  15.     SEGEND    CODE
  16.  
  17.     .xlist
  18.  
  19. ;  Parameter offsets
  20.  
  21. param1    EQU    @ab+[BP]
  22. param2    EQU    @ab+2[BP]
  23. param3    EQU    @ab+4[BP]
  24. param4    EQU    @ab+6[BP]
  25. param5    EQU    @ab+8[BP]
  26. param6    EQU    @ab+10[BP]
  27. param7    EQU    @ab+12[BP]
  28. param8    EQU    @ab+14[BP]
  29. param9    EQU    @ab+16[BP]
  30. param10    EQU    @ab+18[BP]
  31.  
  32. ;  macros
  33.  
  34. ldata    macro
  35. ?dptr    =    -2
  36.     endm
  37.  
  38. lvar    macro    nam
  39. nam    equ    ?dptr
  40. ?dptr    =    ?dptr-2
  41.     endm
  42.  
  43. enter    macro    lvars
  44.     push    bp
  45.     mov    bp,sp
  46.     ifnb    <lvars>
  47.     sub    sp,(lvars+1)/2
  48.     endif
  49.     endm
  50.  
  51. leave    macro
  52.     pop    bp
  53.     ret
  54.     endm
  55.  
  56. ?genp    macro    pnum
  57.     ifnb    <p&pnum>
  58.     push    p&pnum
  59.     endif
  60.     endm
  61.  
  62. ccall    macro    p1,p2,p3,p4,p5,p6,p7,p8,p9,p10
  63. ?p    =    10
  64.     rept    10
  65.     ?genp    %?p
  66. ?p    =    ?p-1
  67.     endm
  68.     endm
  69.  
  70.     .list
  71.  
  72. ;---------------------------------------------------------------
  73. ;
  74. ;    Interface to stranger MSDOS functions:
  75. ;
  76. ;        ax = msdos(ax, bx, cx, dx);
  77. ;        if carry set: _carry = 1 else 0
  78. ;
  79. ;----------------------------------------------------------------
  80.     SEGDEF    DATA
  81.  
  82.     PUBLIC    _carry        ;global carry flag
  83.  
  84. _carry    dw    0
  85.  
  86.     SEGEND    DATA
  87.  
  88.     SEGDEF    CODE
  89.     PUBLIC    msdos    ;entry point
  90.  
  91.     PROCDEF    msdos
  92.     enter
  93.     mov    ax,param1
  94.     mov    bx,param2
  95.     mov    cx,param3
  96.     mov    dx,param4
  97.     mov    _carry,0
  98.     Push    ES        ;save es
  99.     int    21h        ;call msdos
  100.     Pop    ES        ;save es
  101.     jnc    nocarry
  102.     mov    _carry,1
  103. nocarry: leave
  104.     PROCEND    msdos
  105.     SEGEND    CODE
  106.  
  107. ;---------------------------------------------------------------+
  108. ;                                |
  109. ;        Fast Video Put Line and Attributes        |
  110. ;                                |
  111. ;    Vers. 1.0            9/13/83  A.F.        |
  112. ;                                |
  113. ;    History:                        |
  114. ;                                |
  115. ;    9/13/83        Created        AF            |
  116. ;                                |
  117. ;---------------------------------------------------------------+
  118. ;
  119. ;    putline (line, col, string)
  120. ;    putattr (line, col, len, array)
  121. ;
  122. ;    int line,col;        /* place to put string or attribs */
  123. ;    char *string;        /* string to write */
  124. ;    char array[];        /* array of attributes */
  125. ;    int len            /* length of attribute array */
  126. ;
  127.  
  128.     SEGDEF    CODE
  129.  
  130.     public    putline,putattr
  131.  
  132.     PROCDEF    putline
  133.     enter                ;initialize stack
  134.     push    es            ;gets clobbered
  135.     mov    si,param3        ;si=> string
  136.  
  137. ;    get the string length in cx
  138.  
  139.     push    ds            ;es=ds
  140.     pop    es
  141.     mov    di,si            ;set =>
  142.     cld                ;going up!
  143.     mov    cx,-1            ;set count
  144.     xor    al,al            ;look for null
  145.  
  146. repne    scasb
  147.     inc    cx
  148.     not    cx            ;cx now has the length
  149.     mov    ax,2            ;set move characters
  150.  
  151. ;    Putline and Putattr common code
  152.  
  153. put:
  154.     mov    bl,param1        ;get line
  155.     mov    bh,param2        ;and col
  156.  
  157.     cmp    bl,1            ;make sure line is in range 1-24
  158.     jl    exit
  159.     cmp    bl,24
  160.     jg    exit
  161.  
  162.     push    ax            ;save 
  163.     mov    al,bh            ;check to make sure we don't
  164.     add    ax,cx            ;exceed the end of the line
  165.     cmp    ax,81            ;assuming 80 chars single width
  166.     pop    ax
  167.     ja    exit
  168.  
  169.     mov    bp,ds            ;the call requires bp=ds
  170.     mov    di,14h            ;function #
  171.     int     18h            ;do it
  172. exit:
  173.     pop    es
  174.     leave
  175.     PROCEND    putline
  176.  
  177.     PROCDEF    putattr
  178.     enter                ;initialize stack
  179.     push    es
  180.     mov    dx,param4        ;dx=> attributes
  181.            mov    cx,param3        ;length
  182.     mov    ax,1            ;set attributes
  183.     jmp    put            ;go to common part of routines
  184.     PROCEND    putattr
  185.  
  186.     SEGEND    CODE
  187.  
  188.  
  189.     SEGDEF    DATA
  190.  
  191. ; TRANSLATION TabLE TO CONVERT FIRMWARE 16-BIT KEYCODES INTO 'FINAL' KEYCODES
  192. ;
  193. ;    FINAL KEYCODE        KEY ID        FIRMWARE    FINAL
  194.  
  195. keytbl    db    15        ;HELP        00    TO    15.
  196.     db    16        ;DO        01    TO    16.
  197.     db    0        ;COMPOSE    02    TO    0
  198.     db    2        ;PRINT SCREEN    03    TO    2
  199.     db    0FFh        ;        04
  200.     db    4        ;F4        05    TO    4
  201.     db    0FFh        ;        06
  202.     db    6        ;INTERRUPT    07    TO    6
  203.     db    0FFh        ;        08
  204.     db    7        ;RESUME        09    TO    7
  205.     db    0FFh        ;        0A
  206.     db    8        ;CANCEL        0B    TO    8
  207.     db    0FFh        ;        0C
  208.     db    9        ;MAIN SCREEN    0D    TO    9
  209.     db    0FFh        ;        0E
  210.     db    10        ;EXIT        0F    TO    10.
  211.     db    0FFh        ;        10
  212.     db    14        ;ADDTNL OPTIONS    11    TO    14.
  213.     db    0FFh        ;        12
  214.     db    17        ;F17        13    TO    17.
  215.     db    0FFh        ;        14
  216.     db    18        ;F18        15    TO    18.
  217.     db    0FFh        ;        16
  218.     db    19        ;F19        17    TO    19.
  219.     db    0FFh        ;        18
  220.     db    20        ;F20        19    TO    20.
  221.     db    0FFh        ;        1A
  222.     db    21        ;FIND        1B    TO    21.
  223.     db    0FFh        ;        1C
  224.     db    22        ;INSERT HERE    1D    TO    22.
  225.     db    0FFh        ;        1E
  226.     db    23        ;REMOVE        1F    TO    23.
  227.     db    0FFh        ;        20
  228.     db    24        ;SELECT        21    TO    24.
  229.     db    0FFh        ;        22
  230.     db    25        ;PREV SCREEN    23    TO    25.
  231.     db    0FFh        ;        24
  232.     db    26        ;NEXT SCREEN    25    TO    26.
  233.     db    0FFh        ;        26
  234.     db    27        ;UP-ARROW    27    TO    27.
  235.     db    0FFh        ;        28
  236.     db    29        ;DOWN-ARROW    29    TO    29.
  237.     db    0FFh        ;        2A
  238.     db    30        ;RIGHT-ARROW    2B    TO    30.
  239.     db    0FFh        ;        2C
  240.     db    28        ;LEFT-ARROW    2D    TO    28.
  241.     db    0FFh        ;        2E
  242.     db    31        ;KEYPAD 0    2F    TO    31.
  243.     db    0FFh        ;        30
  244.     db    0FFh        ;        31
  245.     db    32        ;KEYPAD 1    32    TO    32.
  246.     db    0FFh        ;        33
  247.     db    0FFh        ;        34
  248.     db    33        ;KEYPAD 2    35    TO    33.
  249.     db    0FFh        ;        36
  250.     db    0FFh        ;        37
  251.     db    34        ;KEYPAD 3    38    TO    34.
  252.     db    0FFh        ;        39
  253.     db    0FFh        ;        3A
  254.     db    35        ;KEYPAD 4    3B    TO    35.
  255.     db    0FFh        ;        3C
  256.     db    0FFh        ;        3D
  257.     db    36        ;KEYPAD 5    3E    TO    36.
  258.     db    0FFh        ;        3F
  259.     db    0FFh        ;        40
  260.     db    37        ;KEYPAD 6    41    TO    37.
  261.     db    0FFh        ;        42
  262.     db    0FFh        ;        43
  263.     db    38        ;KEYPAD 7    44    TO    38.
  264.     db    0FFh        ;        45
  265.     db    0FFh        ;        46
  266.     db    39        ;KEYPAD 8    47    TO    39.
  267.     db    0FFh        ;        48
  268.     db    0FFh        ;        49
  269.     db    40        ;KEYPAD 9    4A    TO    40.
  270.     db    0FFh        ;        4B
  271.     db    0FFh        ;        4C
  272.     db    42        ;KEYPAD DASH    4D    TO    42.
  273.     db    0FFh        ;        4E
  274.     db    0FFh        ;        4F
  275.     db    41        ;KEYPAD COMMA    50    TO    41.
  276.     db    0FFh        ;        51
  277.     db    0FFh        ;        52
  278.     db    43        ;KEYPAD PERIOD    53    TO    43.
  279.     db    0FFh        ;        54
  280.     db    0FFh        ;        55
  281.     db    48        ;KEYPAD ENTER    56    TO    48.
  282.     db    0FFh        ;        57
  283.     db    0FFh        ;        58
  284.     db    44        ;KEYPAD PF1    59    TO    44.
  285.     db    0FFh        ;        5A
  286.     db    0FFh        ;        5B
  287.     db    45        ;KEYPAD PF2    5C    TO    45.
  288.     db    0FFh        ;        5D
  289.     db    0FFh        ;        5E
  290.     db    46        ;KEYPAD PF3    5F    TO    46.
  291.     db    0FFh        ;        60
  292.     db    0FFh        ;        61
  293.     db    47        ;KEYPAD PF4    62    TO    47.
  294.     db    0FFh        ;        63
  295.     db    0FFh        ;        64
  296.     db    5        ;BREAK        65    TO    5.
  297.  
  298.     SEGEND    DATA
  299.  
  300. ;******************************************************************
  301. ;*    character I/O
  302. ;*
  303. ;    int kbd16(&i)        /* level 1 console in */
  304. ;    int *i;
  305. ;
  306. ;    int kbdin(&i);        /* level 2 console in */
  307. ;    int *i;
  308. ;
  309. ;    kbdout(c);            /* level 2 character out */
  310. ;    unsigned char c;
  311. ;
  312.  
  313.     SEGDEF    CODE
  314.  
  315.     public    kbd16,kbdin,kbdout
  316.  
  317.     PROCDEF    kbd16
  318.  
  319.     push    bp    ;Computer Innovations says ax,bc,cx,dx,si & di free
  320.     mov    bp,sp        ; [bp+0] = old bp
  321.                 ; [bp+2] = return address
  322.                 ; [bp+4] = first (only) argument
  323.  
  324.     mov    di,06        ; 16 bit  console function
  325.     Push    ES        ;save es
  326.     int    18h        ; msdos equivalent of int 40
  327.                 ; cl = 0, 1 or FF
  328.                 ; ax = 16 bit character.
  329.  
  330.     pop    es
  331.     xchg    ax,cx        ; al = 0, 1 or FF, cx = char.
  332.     cbw            ; ax = 0, 1 or FFFF
  333.     and    ax,ax        ; if ax != FFFF, don't translate...
  334.     jns    nochar        ; ... just return status (in ax).
  335.  
  336.     test    ch,01        ; ch bit 0 is 1 for function keys.
  337.     jz    nofunc        ; if not a function key, skip translation.
  338.  
  339.     lea    bx, keytbl    ; address of translate table.
  340.     xchg    cx,ax        ; swap character and status (ax = character)
  341.     xlat             ; translate char in al to one in table.
  342.     xchg    ax,cx        ; swap character and status (ax = status)
  343.  
  344. nofunc:    mov    bx,param1    ; get parameter (address of buffer)
  345.     mov    [bx],cx        ; put char in the buffer
  346.  
  347. nochar:    pop    bp        ; status is in ax
  348.     ret
  349.     PROCEND    kbd16
  350.  
  351.     PROCDEF    kbdin
  352.  
  353.     push    bp    ;Computer Innovations says ax,bc,cx,dx,si & di free
  354.     mov    bp,sp        ; [bp+0] = old bp
  355.                 ; [bp+2] = return address
  356.                 ; [bp+4] = first (only) argument
  357.  
  358.     mov    di,02        ; 8 bit  console in function
  359.     Push    ES        ;save es
  360.     int    18h        ; msdos equivalent of int 40
  361.                 ; cl = 0 or FF
  362.                 ; al = 8 bit character.
  363.     pop    es
  364.  
  365.     xchg    ax,cx        ; al = 0 or FF, cx = char.
  366.     cbw            ; ax = 0 or FFFF
  367.     and    ax,ax        ; if ax != FFFF ...
  368.     jns    kin1        ; ... just return status (in ax).
  369.  
  370.     mov    bx,param1    ; get parameter (address of buffer)
  371.     mov    [bx],cx        ; put char in the buffer
  372.  
  373. kin1:    pop    bp        ; status is in ax
  374.     ret
  375.     PROCEND    kbdin
  376.  
  377.     PROCDEF    kbdout
  378.  
  379.     push    bp    ;Computer Innovations says ax,bc,cx,dx,si & di free
  380.     mov    bp,sp        ; [bp+0] = old bp
  381.                 ; [bp+2] = return address
  382.                 ; [bp+4] = first (only) argument
  383.     mov    ax,param1    ; get char for output
  384.     mov    di,02        ; 8 bit  console out function
  385.     Push    ES        ;save es
  386.     int    18h        ; msdos equivalent of int 40
  387.     pop    es
  388.     ret
  389.     PROCEND    kbdout
  390.  
  391.  
  392.     SEGEND    CODE
  393.  
  394. ;---------------------------------------------------------------+
  395. ;                                |
  396. ;            Enable and Disable Cursor            |
  397. ;                                |
  398. ;---------------------------------------------------------------+
  399. ;
  400. ;    enb_cur()
  401. ;    dis_cur()
  402. ;
  403.  
  404.     SEGDEF    CODE
  405.  
  406.     public    enb_cur,dis_cur
  407.  
  408.     PROCDEF    enb_cur
  409.     enter                ;initialize stack
  410.     push    es            ;gets clobbered
  411.     mov    di,0Ah            ;function #
  412.     int     18h            ;do it
  413.     pop    es
  414.     leave
  415.     PROCEND    enb_cur
  416.  
  417.     PROCDEF    dis_cur
  418.     enter                ;initialize stack
  419.     push    es
  420.     mov    di,08h
  421.     int    18h
  422.     pop    es
  423.     leave
  424.     PROCEND    dis_cur
  425.  
  426.     SEGEND    CODE
  427.  
  428.     END
  429. 
  430.