home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / caway349.zip / BIN / SCREEN32.ASM < prev    next >
Assembly Source File  |  1996-06-17  |  3KB  |  147 lines

  1. ; Example of using NEAR model
  2. ; This example will also work using FLAT model (WL32 /f option)
  3. ;
  4.     .386p
  5.  
  6.     include cw.inc
  7.  
  8. ;
  9. ;The segment name _NEAR isn't important here, it's the class 'near' that is.
  10. ;
  11. _NEAR    segment para public 'near' use32
  12.     assume cs:_NEAR, ds:_NEAR
  13.  
  14. ;-----------------------------------------------------------------------------
  15. ;
  16. ;On entry DS=ES=PSP as normal, SS=_NEAR
  17. ;
  18. start    proc    far
  19.     mov    ax,_NEAR        ;should yield a data selector
  20.     mov    ds,ax        ;with a limit of 4G. SS already
  21.     mov    es,ax        ;has this value so that could be
  22.     mov    fs,ax        ;used but this method shows that
  23.     mov    gs,ax        ;segments can still be used.
  24. ;
  25. ;CS=DS=ES=FS=GS=_NEAR from this point on unless we're in interrupt code in which
  26. ;case we need to reload DS,ES,FS,GS. SS will be using a system stack for
  27. ;hardware interrupts or CallBack's but will otherwise already = _NEAR.
  28. ;
  29.     mov    edx,offset message1    ;need to do something to show
  30.     mov    ah,9        ;there is life after WL32.
  31.     int    21h
  32. ;
  33. ;Patch an interrupt vector for the sake of it.
  34. ;
  35.     mov    bl,60h
  36.     sys    GetVect        ;Get current vector contents.
  37.     push    edx
  38.     push    ecx
  39.     mov    cx,cs
  40.     mov    edx,offset IntHandler
  41.     sys    SetVect        ;Set new handler address.
  42. ;
  43. ;Allocate some memory for a text screen buffer.
  44. ;
  45.     mov    ebx,80*2*25
  46.     sys    GetMemNear
  47.     jc    @@Error
  48.     mov    edi,esi
  49.     mov    edx,esi
  50. ;
  51. ;Get a near address for color text screen memory.
  52. ;
  53.     mov    esi,0b8000h        ;normal linear address.
  54.     sys    Linear2Near
  55.     mov    ebx,esi        ;near address.
  56. ;
  57. ;Copy current screen contents.
  58. ;
  59.     mov    ecx,(80*2*25)/4
  60.     rep    movsd
  61. ;
  62. ;Fill the screen with rubbish.
  63. ;
  64.     mov    edi,ebx
  65.     mov    eax,03400340h
  66.     mov    ecx,(80*2*25)/4
  67.     rep    stosd
  68. ;
  69. ;Pass control to the interrupt handler.
  70. ;
  71.     int    60h
  72. ;
  73. ;Restore the screen.
  74. ;
  75.     mov    edi,ebx
  76.     mov    esi,edx
  77.     mov    ecx,(80*2*25)/4
  78.     rep    movsd
  79. ;
  80. ;Release screen buffer memory.
  81. ;
  82.     mov    esi,edx
  83.     sys    RelMemNear
  84. ;
  85. ;Restore original interrupt vector.
  86. ;
  87.     pop    ecx
  88.     pop    edx
  89.     mov    bl,60h
  90.     sys    SetVect
  91. ;
  92. ;Demonstration over.
  93. ;
  94. @@Error:    mov    ax,4c00h
  95.     int    21h
  96. start    endp
  97.  
  98.  
  99. ;-----------------------------------------------------------------------------
  100. IntHandler    proc    far
  101. ;
  102. ;Save all the registers first.
  103. ;
  104.     push    ds
  105.     push    es
  106.     push    fs
  107.     push    gs
  108.     pushad
  109. ;
  110. ;Now make all our data addressable.
  111. ;
  112.     mov    ax,_NEAR
  113.     mov    ds,ax
  114.     mov    es,ax
  115.     mov    fs,ax
  116.     mov    gs,ax
  117. ;
  118. ;Print a message again.
  119. ;
  120.     mov    edx,offset message2
  121.     mov    ah,9
  122.     int    21h
  123. ;
  124. ;Wait for the key press.
  125. ;
  126.     mov    ah,0
  127.     int    16h
  128. ;
  129. ;Restore the registers.
  130. ;
  131.     popad
  132.     pop    gs
  133.     pop    fs
  134.     pop    es
  135.     pop    ds
  136.     iretd
  137. IntHandler    endp
  138.  
  139.  
  140. ;-----------------------------------------------------------------------------
  141. message1    db 'hello world',13,10,'$'
  142. message2    db 13,10,'press any key to continue',13,10,13,10,'$'
  143.  
  144. _NEAR    ends
  145.  
  146.     end    start
  147.