home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / MEMORY8.ASM < prev    next >
Assembly Source File  |  1994-12-01  |  4KB  |  119 lines

  1.     PAGE    66,132
  2. ;****************************** MEMORY8.ASM *********************************
  3. ;
  4. ;----------------------------------------------------------------------------
  5. LIBSEG           segment byte public "LIB"
  6.         assume cs:LIBSEG , ds:nothing
  7.  
  8. ;----------------------------------------------------------------------------
  9. .xlist
  10.     include  mac.inc
  11.     include  common.inc
  12. .list
  13.  
  14. ;-----------------------------------------------------------------------;
  15. ;    Segment Descriptor (part of Global Descriptor    Table)         ;
  16. ;-----------------------------------------------------------------------;
  17. DESC    STRUC              ;data segment descriptor
  18.  DESC_LMT   DW    0         ;segment limit (length)
  19.  DESC_BASEL DW    0         ;bits 15-0 of physical address
  20.  DESC_BASEH DB    0         ;bits 23-16 of physical address
  21.  DB    0             ;access rights    byte
  22.  DW    0             ;reserved
  23. DESC    ENDS
  24.  
  25. align 4
  26. ;-----------------------------------------------------------------------
  27. ; bios extended    memory database
  28. ;-----------------------------------------------------------------------;
  29. ;    Global Descriptor Table (GDT), used for extended memory moves    ;
  30. ;-----------------------------------------------------------------------;
  31. ;Access    Rights Byte (93H) is
  32. ;    P=1    (segment is mapped into physical memory)
  33. ;    E=0    (data segment descriptor)
  34. ;    D=0    (grow up segment,    offsets    must be    <= limit)
  35. ;    W=1    (data segment may    be written into)
  36. ;    DPL=0    (privilege level 0)
  37.  
  38. GDT    LABEL    BYTE         ;begin    global descriptor table
  39.     DESC    <>        ;dummy descriptor
  40.      DESC    <>         ;descriptor    for GDT    itself
  41. SRC    DESC    <512,,,93H,>    ;source descriptor
  42. TGT    DESC    <512,,,93H,>    ;target descriptor
  43.      DESC    <>         ;BIOS CS descriptor
  44.      DESC    <>         ;stack segment descriptor
  45.  
  46. c16    dw    16        ;constant 16
  47.  
  48. comment 
  49. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  50. EXT_READ - read block of ext memory
  51. ;  inputs: dx,ax = from    address    (extended memory) 1meg base assumed
  52. ;       es:di = to address (conventional memory)
  53. ;          cx = bytes to move
  54. ;   output - ah    = error    code, or zero if no error
  55. ;          
  56. ;* * * * * * * * * * * * * *
  57. 
  58.  
  59.     public    EXT_READ
  60. EXT_READ    proc    far
  61.     mov    bx,di            ;move -to- offset to bx
  62.     add    dl,10h            ;  to extended byte address
  63.     mov    SRC.DESC_BASEL,ax    ;store target
  64.     mov    SRC.DESC_BASEH,dl    ;  address
  65.  
  66.     mov    ax,es            ;get users buffer segment
  67.     mul    C16            ;convert to byte address
  68.     add    ax,bx            ;add offset
  69.     adc    dl,0            ;add any carry to high address byte
  70.     mov    TGT.DESC_BASEL,AX    ;store source
  71.     mov    TGT.DESC_BASEH,dl    ;  address
  72.     jmp    short do_transfer
  73. EXT_READ    endp
  74.  
  75. comment 
  76. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  MEMORY )
  77. EXT_WRITE - write to EXT memory
  78. ;   inputs:  es:si = from address (conventional    memory)
  79. ;         dx,ax = extended memory address, 1k offset assumed
  80. ;        cx = bytes to move
  81. ;  outputs - ah    = error    code, or zero if no errors
  82. ;
  83. ;          
  84. ;* * * * * * * * * * * * * *
  85. 
  86.  
  87.     public    EXT_WRITE
  88. EXT_WRITE    proc    far
  89.     mov    bx,si
  90.     add    dl,10h            ;convert to extended byte address
  91.     mov    TGT.DESC_BASEL,ax    ;store target
  92.     mov    TGT.DESC_BASEH,dl    ;  address
  93.  
  94.     mov    ax,es            ;get users    buffer segment
  95.     mul    C16            ;convert to byte address
  96.     add    ax,bx            ;add offset
  97.     adc    dl,0            ;add any carry to high address byte
  98.     mov    SRC.DESC_BASEL,AX    ;store source
  99.     mov    SRC.DESC_BASEH,dl    ;  address
  100.     jmp    short do_transfer
  101. EXT_WRITE    endp
  102. ;
  103. ;----------------------------------------------------------------------------
  104. do_transfer:
  105.     push    bp
  106.     mov    SRC.DESC_LMT,cx
  107.     mov    TGT.DESC_LMT,cx
  108.     mov    ax,cs            ;point
  109.     mov    es,ax            ;    -es:si-
  110.     mov    si,offset GDT        ;      at GDT
  111.     shr    cx,1            ;number of words    to transfer
  112.     mov    ah,87h            ;block move code
  113.     int    15h            ;call bios
  114.     pop    bp
  115.     retf                ;if -ah- is non    zero an    error occured
  116.  
  117. LIBSEG    ENDS
  118. ;;    end
  119.