home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / caway349.zip / MISC / LINEAR.ZIP / EXCEPTS.ASM < prev    next >
Assembly Source File  |  1995-10-27  |  7KB  |  278 lines

  1. ;****************************************************************
  2. ; A 'GNU DJGPP GO32' like linear video buffer for CauseWay.
  3. ; J.P. 1995   Stack calling convention.
  4.  
  5. .386
  6.  
  7. DGROUP  group   _DATA
  8. _DATA   segment 'DATA'
  9.  
  10. ALIGN   4
  11.  
  12. OldHandlerOFF        dd  0  ; Old 0E handler
  13. OldHandlerSEL        dd  0  ; Old 0E handler
  14.  
  15. CR2AddrOFF           dd  0  ; Address of CR2 image
  16. CR2AddrSEL           dd  0  ; Address of CR2 image
  17.  
  18. FAULT_ADDR           dd  ?  ; CR2
  19.  
  20. LinearVideoAddr      dd  0  ; Linear video address (start)
  21. LinearVideoEnd       dd  0  ; Linear video address (end)
  22.  
  23. CurrentPage          dd  0  ;This a page descriptor addr
  24. CurrentBank          dd  0  ;This is current active bank (64 k or 16 pages)  (0..n)
  25.  
  26.  
  27. Message              db  '┌────────────────────────────────────────────────┐',13d,10d
  28.                      db  '│ Interrupt 0E occurs out of linear video frame. │',13d,10d
  29.                      db  '│ Pass control to default exception handler...   │',13d,10d
  30.                      db  '└────────────────────────────────────────────────┘',13d,10d,'$'
  31.  
  32. _DATA   ends
  33.  
  34. _TEXT SEGMENT BYTE PUBLIC USE32 'CODE'
  35.   ASSUME  CS:_TEXT
  36.   ASSUME  DS:DGROUP
  37.  
  38. PUBLIC  EnableLinearVideo
  39. PUBLIC  CloseLinearVideo
  40.  
  41. PUBLIC  LinearVideoAddr
  42. PUBLIC  LinearVideoEnd
  43. PUBLIC  CR2AddrOFF
  44. PUBLIC  CR2AddrSEL
  45.  
  46.  
  47. ;*************************************************************
  48. ;    Here are three functions for user.
  49. ;    VideoPrologue   : init video card.Called once at start
  50. ;    VideoEpilogue   : reset video card. Called once at end
  51. ;    VideoBankSwitch : select bank in eax or at [CurrentBank]
  52. ;
  53. ;    Here is a sample for VESA, 64 kB granularity banks.
  54. ;    For instance,if granularity is 4Kb, multiply bank number by 16
  55. ;
  56. ;*************************************************************
  57.  
  58. VideoPrologue PROC
  59.   ret
  60. VideoPrologue ENDP
  61.  
  62.  
  63. VideoEpilogue PROC
  64.   ret
  65. VideoEpilogue ENDP
  66.  
  67.  
  68. VideoBankSwitch PROC
  69.   mov edx,eax
  70.   mov eax,4f05h
  71.   xor ebx,ebx
  72.   int 10h
  73.   ret
  74. VideoBankSwitch ENDP
  75.  
  76.  
  77. ;**************************************************
  78. ;  Here is the trap 0E handler
  79. ;**************************************************
  80.  
  81. Trap0EHandler  PROC FAR
  82.   pushad
  83.  
  84. ; Get fault address
  85.  
  86.   push  es
  87.   mov   eax,[CR2AddrSEL]
  88.   mov   es,ax
  89.   mov   ebx,[CR2AddrOFF]
  90.   mov   eax,es:[ebx]
  91.   pop   es
  92.  
  93.   mov   [FAULT_ADDR],eax
  94.  
  95. ; Call the paging function with eax=the 4k page to set (starts as 0).
  96. ; verify if eax is into the video window
  97.  
  98.   cmp   eax,dword ptr LinearVideoAddr
  99.   jb    RealFault
  100.   dec   ecx                            ; dummy instruction for jump
  101.   cmp   eax,dword ptr LinearVideoEnd
  102.   ja    RealFault
  103.   dec   ecx                            ; dummy instruction for jump
  104.  
  105. ; set prev pages disable and new pages OK.
  106. ; Get fault address in eax and convert to page address at 64kB boundary
  107.  
  108.   shr   eax,12
  109.   shl   eax,2
  110.   add   eax,0FFC00000h
  111.   and   eax,0FFFFFFC0h
  112.  
  113. ; Set the 16 pages as valid and the previous as disabled
  114.  
  115.   or    dword ptr [eax][00h],0000000001h        ; enable actual 64k bank (16 pages)
  116.   or    dword ptr [eax][04h],0000000001h
  117.   or    dword ptr [eax][08h],0000000001h
  118.   or    dword ptr [eax][0Ch],0000000001h
  119.   or    dword ptr [eax][10h],0000000001h
  120.   or    dword ptr [eax][14h],0000000001h
  121.   or    dword ptr [eax][18h],0000000001h
  122.   or    dword ptr [eax][1Ch],0000000001h
  123.   or    dword ptr [eax][20h],0000000001h
  124.   or    dword ptr [eax][24h],0000000001h
  125.   or    dword ptr [eax][28h],0000000001h
  126.   or    dword ptr [eax][2Ch],0000000001h
  127.   or    dword ptr [eax][30h],0000000001h
  128.   or    dword ptr [eax][34h],0000000001h
  129.   or    dword ptr [eax][38h],0000000001h
  130.   or    dword ptr [eax][3Ch],0000000001h
  131.  
  132.   mov   ebx,[CurrentPage]
  133.   and   ebx,0ffffffffh
  134.   jz    SkipOnce
  135.  
  136.   and   dword ptr [ebx][00h],0fffffffeh        ; disable old 64k bank (16 pages)
  137.   and   dword ptr [ebx][04h],0fffffffeh
  138.   and   dword ptr [ebx][08h],0fffffffeh
  139.   and   dword ptr [ebx][0Ch],0fffffffeh
  140.   and   dword ptr [ebx][10h],0fffffffeh
  141.   and   dword ptr [ebx][14h],0fffffffeh
  142.   and   dword ptr [ebx][18h],0fffffffeh
  143.   and   dword ptr [ebx][1Ch],0fffffffeh
  144.   and   dword ptr [ebx][20h],0fffffffeh
  145.   and   dword ptr [ebx][24h],0fffffffeh
  146.   and   dword ptr [ebx][28h],0fffffffeh
  147.   and   dword ptr [ebx][2Ch],0fffffffeh
  148.   and   dword ptr [ebx][30h],0fffffffeh
  149.   and   dword ptr [ebx][34h],0fffffffeh
  150.   and   dword ptr [ebx][38h],0fffffffeh
  151.   and   dword ptr [ebx][3Ch],0fffffffeh
  152.  
  153. ; compute the page descriptor addr according eax -> ebx
  154.  
  155. SkipOnce :
  156.   mov   [CurrentPage],eax
  157.  
  158. ; Compute bank
  159.  
  160.   mov   eax,[FAULT_ADDR]
  161.   sub   eax,[LinearVideoAddr]
  162.   shr   eax,16
  163.  
  164.   mov   [CurrentBank],eax
  165.   Call  VideoBankSwitch
  166.  
  167.   popad
  168.   retf
  169.  
  170. ; Go here in case of unexpected exception 0E
  171. ; Jump to default handler
  172.  
  173. RealFault:
  174.  
  175. ; output message and quit
  176.  
  177.   mov   ax,3
  178.   int   10h
  179.   mov   edx,offset Message
  180.   mov   ax,_DATA
  181.   mov   es,ax
  182.   mov   ah,9
  183.   int   21h
  184.  
  185.   popad
  186.  
  187.   push  dword [OldHandlerSEL]  ; simulate a far jump to old handler...
  188.   push  dword [OldHandlerOFF]
  189.   retf
  190.  
  191. Trap0EHandler  ENDP
  192.  
  193.  
  194.  
  195. ;*****************************************************
  196. ; Function for initialisation
  197.  
  198. EnableLinearVideo  PROC
  199.   push  ebx
  200.   push  ecx
  201.   push  edx
  202.  
  203.   mov   eax,202h       ; get old 0E handler address
  204.   mov   bl,0eh
  205.   int   31h
  206.  
  207.   or    eax,1
  208.   jc    EnableExceptErr
  209.   mov   [OldHandlerOFF],edx
  210.   and   ecx,0ffffh
  211.   mov   [OldHandlerSEL],ecx
  212.  
  213.   mov   eax,203h       ; set new 0E handler address
  214.   mov   bl,0eh
  215.   mov   cx,_TEXT                   ; seg
  216.   mov   edx,offset Trap0EHandler   ; offs
  217.   int   31h
  218.   or    eax,1
  219.   jc    EnableExceptErr
  220.  
  221.   call  VideoPrologue
  222.  
  223.   xor   eax,eax
  224.  
  225. EnableExceptErr :
  226.  
  227.   pop   edx
  228.   pop   ecx
  229.   pop   ebx
  230.   ret
  231. EnableLinearVideo  ENDP
  232.  
  233. ;*****************************************************
  234. ; Function for restore
  235.  
  236. CloseLinearVideo  PROC
  237.   push  ebx
  238.   push  ecx
  239.   push  edx
  240.  
  241.   xor   eax,eax
  242.   or    eax,[OldHandlerOFF]
  243.   or    eax,[OldHandlerSEL]
  244.   jz    Quit
  245.  
  246.   call  VideoEpilogue
  247.  
  248.   mov   edx,[OldHandlerOFF]
  249.   mov   ecx,[OldHandlerSEL]
  250.   mov   eax,203h             ; restore handler address
  251.   mov   bl,0eh
  252.   int   31h
  253.  
  254.   xor   eax,eax
  255.   mov   [OldHandlerOFF],eax
  256.   mov   [OldHandlerSEL],eax
  257.  
  258.   mov   eax,801h             ; free physical zone allocated by int31/ax=800h
  259.   mov   ebx,[LinearVideoAddr]
  260.   or    ebx,ebx
  261.   jz    Quit
  262.   mov   ecx,ebx
  263.   shr   ebx,16
  264.   and   ecx,0ffffh
  265.   int   31h
  266.   xor   eax,eax
  267.  
  268. Quit:
  269.   pop  edx
  270.   pop  ecx
  271.   pop  ebx
  272.   ret
  273. CloseLinearVideo  ENDP
  274.  
  275.  
  276. _TEXT           ENDS
  277. END
  278.