home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / dmkit / flat / doscalls.asm < prev    next >
Encoding:
Assembly Source File  |  1993-12-31  |  4.1 KB  |  177 lines

  1. ;; This is the C prototype header file for DOSCALLS.  This provides
  2. ;; the minimal DOS dependent interface for flatmodel programs into
  3. ;; DOS.        The primary support needed is the ability to allocate and
  4. ;; de-allocate memory in the low 1mb of address space.
  5. ;; extern char * cdecl AllocLowMem(long int size,short *selector); // Allocate low memory.
  6. ;; extern void cdecl FreeLowMem(short selector); // Free allocated memory.
  7. ;; extern char * cdecl RealPtr(char *real); // Convert flat model address to segment:offset
  8. ;; extern void cdecl memorymove(char *dest,char *source,long int length);
  9. ;;                                                                                                                                                     */
  10. ;;        Written by John W. Ratcliff (c) 1994
  11. ;;             Compuserve: 70253,3237
  12. ;;             Genie: J.RATCLIFF3
  13. ;;             BBS: 1-314-939-0200
  14. ;;             Addresss:
  15. ;;                747 Napa Lane
  16. ;;                St. Charles, MO 63304
  17. ;;                                                                                                                                                     */
  18.     IDEAL
  19.     P386
  20.     JUMPS
  21.     MODEL FLAT,C
  22.     CODESEG
  23.  
  24.     public    AllocLowMem
  25.     public    FreeLowMem
  26.     public    RealPtr
  27.     public    memorymove
  28.     public    tprint
  29.     public    TextCursor
  30.  
  31.  
  32. Proc    C AllocLowMem    near
  33.     ARG    AMOUNT:DWORD,SELECTOR:DWORD
  34.     uses    ebx,edx
  35.  
  36.     mov    ebx,[AMOUNT]    ; Get number of bytes requested.
  37.     add    ebx,15        ; Round up to closest number of paragraphs.
  38.     shr    ebx,4        ; /16.
  39.     mov    eax,0100h    ; Allocate.
  40.     int    31h        ; Allocate memory.
  41.     jc    @@ERR
  42.     shl    eax,4        ; Into flat model address space.
  43.     mov    ebx,[SELECTOR]    ; Get address of selector.
  44.     mov    [ebx],dx    ; Save selector.
  45.     jmp short @@RET
  46. @@ERR:    xor    eax,eax     ; Zero return address.
  47. @@RET:
  48.     ret
  49.     endp
  50.  
  51. Proc    C FreeLowMem    near
  52.     ARG    SELECTOR:DWORD
  53.  
  54.     mov    eax,0101h
  55.     mov    edx,[SELECTOR]
  56.     int    31h
  57.  
  58.     ret
  59.     endp
  60.  
  61. Proc    C RealPtr    near
  62.     ARG    DATA:DWORD
  63.     uses    edx
  64.  
  65.     mov    eax,[DATA]
  66.     mov    edx,eax
  67.     and    eax,0Fh     ; Offset portion.
  68.     and    edx,0FFFF0h
  69.     shl    edx,(16-4)
  70.     add    eax,edx
  71.  
  72.     ret
  73.     endp
  74.  
  75. Proc    C memorymove near
  76.     ARG    DEST:DWORD,SOURCE:DWORD,MLEN:DWORD
  77.     uses    ecx,esi,edi
  78.  
  79.     mov    esi,[SOURCE]
  80.     mov    edi,[DEST]
  81.     mov    ecx,[MLEN]
  82.     rep    movsb
  83.  
  84.     ret
  85.     endp
  86.  
  87. PROC    C tprint near
  88.     ARG    XLOC:DWORD,YLOC:DWORD,LN:DWORD,STRING:DWORD,COLOR:DWORD
  89.     uses    ebx,ecx,edx,esi,edi
  90.  
  91.     mov    esi,[STRING]        ;; Get base address of text to print.
  92.     cmp    [LN],0        ;; If length passed is zero, then use string length.
  93.     jne    @@LNPASS    ;; use length passed.
  94.     or    esi,esi       ;; Null string?
  95.     jz    @@EXIT        ;; yes, exit.
  96.     mov    edi,esi
  97.     xor    eax,eax
  98.     mov    ecx,-1
  99.     repnz    scasb
  100.     neg    ecx
  101.     dec    ecx         ; Less one.
  102.     mov    [LN],ecx     ; Length of string.
  103. @@LNPASS:
  104. ;; If ylocation above are below clip window, exit.
  105.     mov    eax,[YLOC]         ;; Get destination ylocation.
  106.     or    eax,eax           ;; < top margin?
  107.     js    @@EXIT             ;; yes, doesn't fit.
  108.     cmp    eax,25             ;; > bottom margin?
  109.     jg    @@EXIT             ;; yes, doesn't fit.
  110.  
  111. ;; If xlocation > right margin? yes->exit.
  112.     mov    eax,[XLOC]         ;; Get xlocation passed?
  113.     cmp    eax,79             ;; > right margin?
  114.     jg    @@EXIT            ;; doesn't fit, exit.
  115.     or    eax,eax
  116.     jns    @@SKP1            ;; no, start postion is ok.
  117.     neg    eax             ;; Make it positive.
  118.     or    esi,esi           ;; Null string?
  119.     jz    @@REN
  120.     add    esi,eax           ;; Number of pixels to skip.
  121. @@REN:    sub    [LN],eax         ;; Differnece, from total length.
  122.     js    @@EXIT
  123.     jz    @@EXIT             ;; If length zerod out, get out.
  124.     mov    [XLOC],0        ;; Set it.
  125. @@SKP1:
  126.     add    eax,[LN]         ;; Add total length.
  127.     dec    eax             ;; Less one to ending pixel position.
  128.     cmp    eax,79             ;; Past right margin?
  129.     jle    @@SKIP            ;; no->it fits fine.
  130.     sub    eax,79             ;; Amount past right margin.
  131.     sub    [LN],eax         ;; Lower total length.
  132.     js    @@EXIT            ;; if negitze, no go.
  133. @@SKIP: mov    edi,0B8000h
  134.     mov    eax,160
  135.     mul    [YLOC]
  136.     add    edi,eax
  137.     mov    eax,[XLOC]
  138.     shl    eax,1
  139.     add    edi,eax
  140.  
  141.     mov    eax,[COLOR]
  142.     mov    ah,al            ;; Into AH.
  143.     mov    ecx,[LN]         ;; Length.
  144.     or    esi,esi
  145.     jz    @@SPACE         ;; Fill rest with spaces
  146. @@SND:    lodsb                ;; Get character to send.
  147.     or    al,al            ;; Is it eos?
  148.     jz    @@SPACE         ;; fill rest with spaces.
  149.     stosw
  150.     loop    @@SND
  151.     jmp    @@EXIT
  152. @@SPACE:mov    al,20h            ;; Space character.
  153. @@FILL: rep    stosw            ;; Fill rest with spaces.
  154.  
  155.  
  156. @@EXIT:
  157.     ret
  158.     endp
  159.  
  160. PROC    C TextCursor near
  161.     ARG    XLOC:DWORD,YLOC:DWORD
  162.     uses    ebx,edx
  163.  
  164.     mov    eax,[YLOC]
  165.     mov    edx,[XLOC]
  166.     mov    dh,al
  167.     mov    ah,2
  168.     mov    bh,0
  169.     int    10h
  170.  
  171.     ret
  172.     endp
  173.  
  174.  
  175.  
  176.     end
  177.