home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / anivga12 / unchain.asm < prev    next >
Assembly Source File  |  1993-07-11  |  12KB  |  320 lines

  1. ;Here's the TSR I mentioned a few days ago.  Only it's not a TSR, and
  2. ;I took the easy way out of supporting only the mode I use.  Just change my
  3. ;mode set to yours and save any register you change!
  4. ;
  5. ;Do what the hell you like with it...
  6. ;.----------------------------------------------------.
  7. ;| Colin Buckley                                      |
  8. ;| Toronto, Ontario, Canada                           |
  9. ;| InterNet: colin.buckley@rose.com                   |
  10. ;|                                                    |
  11. ;| So Eager to Play, So Relunctant to Admit it...     |
  12. ;`----------------------------------------------------'
  13. ;
  14. ;UNCHAIN.ASM starts here...
  15. ;
  16. ; ---------------------------------------------------------------------
  17. ; UNCHAIN.EXE -- 320x200x256x4 Enforcer -- Colin Buckley
  18. ; Released to the PUBLIC DOMAIN January 14, 1993.
  19. ; If you modify this, add your name and changes and please
  20. ; send the source my way.  (Internet: colin.buckley@rose.com)
  21. ;
  22. ; January 14, 1993
  23. ; o Started
  24. ; o Released
  25. ;
  26. ; NOTES:
  27. ;
  28. ; Use TASM to compile.
  29. ;
  30. ; Requires 1K of memory
  31. ;
  32. ; Most of display memory on Plane 1 from Page 1 (0..16000) will be corrupt
  33. ; because of entering text mode.  So don't use the first page during debugging,
  34. ; although it's not all that bad of a mess.  Perhaps I'll add an option to
  35. ; watch for text mode and save that plane, of course it'll need ~10,000 bytes.
  36. ; I don't know what text mode places in A000, fonts ring a bell.  Anyways,
  37. ; maybe using mono text mode will help.  I haven't tried.
  38. ;
  39. ; You can turn off EGA/VGA graphic save if your debugger uses it, as it won't
  40. ; work.  At least you'll get ~10,000 bytes back.
  41. ;
  42. ; UNCHAIN has been tested with Turbo Pascal 6, and Turbo Debugger.
  43. ;
  44. ; TP doesn't save the palette correctly either, I'll probably add that
  45. ; next.
  46. ;
  47. ; I wrote UNCHAIN for myself, I don't plan to support it, remove the
  48. ; 320x200x256x4 set mode, add yours, save and restore all modified registers,
  49. ; compile, and it should work fine.
  50. ;
  51. ;
  52. ; PURPOSE:
  53. ;
  54. ; Most debuggers will only remember which Video Mode you're in, if you're
  55. ; using an unchained (aka planar, mode x) mode, then the debugger will drop
  56. ; you in Mode 13h, and not restore your VGA register modifications.
  57. ;
  58. ; UNCHAIN will modify the registers everytime Mode 13h is called.  If
  59. ; you're not using 320x200x256x4, then use your Mode Set instead of
  60. ; the 320x200x256x4 routine curently used.
  61. ;
  62. ;
  63. ; USAGE:
  64. ;
  65. ; If you use
  66. ;
  67. ; >TD YourGame.EXE <YourGame commandline options>
  68. ;
  69. ; then use
  70. ;
  71. ; >UNCHAIN TD YourGame.EXE <YourGame commandline options>
  72. ;
  73. ; UNCHAIN will spawn TD and Turbo Debugger will load your game and
  74. ; operate as usual.
  75. ;
  76. ;
  77. ; ENHANCEMENTS:
  78. ;
  79. ; You could use some marker like FF13h and upon encountering that you
  80. ; save all VGA registers, and every 0013h encountered restore all VGA
  81. ; registers.
  82. ;
  83. ;
  84. ; WARNING, IF YOU CHANGE THE SOURCE:
  85. ;
  86. ; Watch out for the small stack!
  87. ;
  88. ; Save and restore all modified registers in your mode set routine.
  89. ; I change AX and DX, so I save them and restore them at both possible
  90. ; exits.
  91. ;
  92. ; Add all the segment sizes in your MAP and place that value in the
  93. ; MemoryReq equate.
  94. ; ---------------------------------------------------------------------
  95.  
  96.     IDEAL
  97.     DOSSEG
  98.     MODEL  Small
  99.     STACK  24
  100.     LOCALS
  101.  
  102. ; Program Size in bytes
  103. MemoryReq      EQU  1024             ;Only need 720 bytes, but what the hell.
  104.  
  105. ; VGA Registers
  106. AC_Addr        EQU  3C0h             ;Attribute Controller Port Address
  107. GC_Addr        EQU  3CEh             ;Graphic Controller Port Address
  108. SC_Addr        EQU  3C4h             ;Sequence Controller Port Address
  109. CRTC_Addr      EQU  3D4h             ;CRT Controller Port Address
  110.  
  111.     DATASEG
  112.  
  113. ; Variables
  114. Copyright   DB 13,10,'UNCHAIN -- 320x200x256x4 Enforcer! -- Colin Buckley (colin.buckley@rose.com)'
  115.             DB 13,10,'Released to the PUBLIC DOMAIN January 14, 1993.'
  116.             DB 13,10,'$'
  117. Usage       DB 13,10,'Usage: UNCHAIN <Filename> <Parameters>'
  118.             DB 13,10,'$'
  119. FileError   DB 13,10,'Error: Can not execute file!'
  120.             DB 13,10,'$'
  121.  
  122. FileOkay    DB 0                     ;File Okay to execute
  123. File        DB 80 DUP(0)             ;File to execute
  124. ParamLen    DB 0                     ;Length of Parameter
  125. Param       DB 80 DUP(13)            ;Parameter
  126. FCB         DB 16 DUP(0)             ;File control block
  127. ParamBlock  DW 0                     ;Parameter block
  128.             DW ParamLen
  129.             DW @DATA
  130.             DW FCB,@DATA
  131.             DW FCB,@DATA
  132.  
  133.     CODESEG
  134.  
  135. ; Variables
  136. VideoISR        DD 0                 ;To save original INT 10h vector
  137. OldSS           DW ?                 ;To save SS
  138. OldSP           DW ?                 ;To save SP
  139. ; New VideoISR
  140. PROC Int10hISR FAR
  141.     PUSH  AX DX
  142.     ; Check for Video BIOS Function 00h -- Set Video Mode
  143.     CMP   AX,0013h                    ;If VGA then
  144.     JZ    @@DoIt                      ;  DoIt;
  145.     CMP   AX,0013h+128                ;If Not VGA then
  146.     JNZ   @@OriginalISR               ;  OriginalISR;
  147. @@DoIt:
  148.     ; Call original Int 10h and let it set Mode 13h
  149.     PUSHF
  150.     CALL  [CS:VideoISR]
  151.     ;
  152.     ; Unchain Mode 13 (320x200x256x4)
  153.     ;
  154.     ; Alter CPU addressing of Video Memory
  155.     MOV   DX,SC_Addr                  ; |Disable Chain 4
  156.     MOV   AL,4                        ; |Disable Odd/Even
  157.     OUT   DX,AL                       ; |
  158.     INC   DX                          ; |
  159.     IN    AL,DX                       ; |
  160.     AND   AL,NOT 08h                  ; |
  161.     OR    AL,04h                      ; |
  162.     OUT   DX,AL                       ;/
  163.     MOV   DX,GC_Addr                  ; |Disable Odd/Even
  164.     MOV   AL,5                        ; |
  165.     OUT   DX,AL                       ; |
  166.     INC   DX                          ; |
  167.     IN    AL,DX                       ; |
  168.     AND   AL,NOT 10h                  ; |
  169.     OUT   DX,AL                       ;/
  170.     DEC   DX                          ; |Disable Chain
  171.     MOV   AL,6                        ; |
  172.     OUT   DX,AL                       ; |
  173.     INC   DX                          ; |
  174.     IN    AL,DX                       ; |
  175.     AND   AL,NOT 02h                  ; |
  176.     OUT   DX,AL                       ;/
  177.     ; Change linear 320x200 to planar 320x200
  178.     MOV   DX,CRTC_Addr                ; |Disable DoubleWord Mode
  179.     MOV   AL,14h                      ; |
  180.     OUT   DX,AL                       ; |
  181.     INC   DX                          ; |
  182.     IN    AL,DX                       ; |
  183.     AND   AL,NOT 40h                  ; |
  184.     OUT   DX,AX                       ;/
  185.     DEC   DX                          ; |Enable Byte Mode
  186.     MOV   AL,17h                      ; |
  187.     OUT   DX,AL                       ; |
  188.     INC   DX                          ; |
  189.     IN    AL,DX                       ; |
  190.     OR    AL,40h                      ; |
  191.     OUT   DX,AL                       ;/
  192.     ;
  193.     ;
  194.     ;
  195.     POP   DX AX
  196.     IRET
  197. @@OriginalISR:
  198.     POP   DX AX
  199.     JMP   [CS:VideoISR]              ;Continue Original ISR chain
  200. ENDP Int10hISR
  201.  
  202. PROC DoParams
  203.     ;ES = PSP, DS = DataSeg
  204.     CMP   [BYTE ES:80h],0             ;Compare PSP:80h to 0
  205.     JE    @@Exit                      ;Yes, Exit
  206.     XOR   CX,CX                       ;CX <- 0
  207.     MOV   AL,' '                      ;Look for Space
  208.     MOV   DI,82h                      ;Search starting at PSP:82h
  209.     MOV   CL,[ES:80h]                 ;Search for length of PSP:81h
  210.     CLD                               ;Auto increment
  211.     REPNZ SCASB                       ;Search until Space is found
  212.     DEC   DI                          ;Go back to found position
  213.     PUSH  DI ES DS                    ;Save Position, ES, & DS
  214.     POP   ES DS                       ;Restore DS in ES
  215.     ;ES = DataSeg, DS = PSP
  216.     MOV   SI,82h                      ;SI <- PSP:82h
  217.     MOV   DI,OFFSET File              ;DI <- File String
  218.     POP   CX                          ;AX <- Length
  219.     SUB   CL,82h                      ;Get Length of file string
  220.     MOV   AX,CX                       ;Store AX <- CX
  221.     REP   MOVSB                       ;Copy File <- SI
  222.     INC   AL                          ;Include one more character for spaces
  223.     CMP   [BYTE 80h],AL               ;Are there anymore Params?
  224.     JE    @@Equal                     ;No, jump to Equal
  225.     MOV   DI,OFFSET Param             ;DI <- Param String
  226.     MOV   CL,[80h]                    ; | CX <- Calculate length of Param
  227.     SUB   CL,AL                       ;/
  228.     MOV   [ES:ParamLen],CL            ;Store length of Param in ParamLen
  229.     REP   MOVSB                       ;Copy Param <- SI
  230. @@Equal:
  231.     INC   [ES:FileOkay]               ;Okay to execute file
  232.     PUSH  ES                          ; |Make ES and DS equal
  233.     POP   DS                          ;/
  234. @@Exit:
  235.     RET
  236. ENDP DoParams
  237.  
  238. ; Install Procedure
  239. PROC Install
  240.     PUSH  ES                          ;Save ES
  241.     ; Save Original Int 10h ISR
  242.     MOV   AX,3510h                    ;Get Interrupt function
  243.     INT   21h                         ;DOS Interrupt
  244.     MOV   [WORD PTR CS:VideoISR],BX   ;Save Int 10h Offset
  245.     MOV   [WORD PTR CS:VideoISR+2],ES ;Save Int 10h Segment
  246.     POP   ES                          ;Restore ES
  247.     PUSH  DS CS                       ; |Save DS then Make DS and CS Equal
  248.     POP   DS                          ;/
  249.     ; Install Int 10h ISR
  250.     MOV   AX,2510h                    ;Set Interrupt function
  251.     LEA   DX,[Int10hISR]              ;Use new Interrupt handler
  252.     INT   21h                         ;DOS Interrupt
  253.     POP   DS                          ;Restore DS
  254.     RET
  255. ENDP Install
  256.  
  257. ; Un-Install Procedure
  258. PROC UnInstall
  259.     PUSH  DS
  260.     ; Resets Original Int 10h handler
  261.     LDS   DX,[CS:VideoISR]            ;Use old Interrupt
  262.     MOV   AX,2510h                    ;Set Interrupt Vector function
  263.     INT   21h                         ;DOS Interrupt
  264.     POP   DS
  265.     RET
  266. ENDP UnInstall
  267.  
  268. ; Start of Program
  269. Start:
  270.     ; Shrink Memory
  271.     MOV   AH,4Ah                      ;Modify Memory Allocation
  272.     MOV   BX,MemoryReq/16             ;Request enough memory
  273.     INT   21h                         ;Ask nicely.
  274.  
  275.     ; Initilize Segments
  276.     MOV   AX,@DATA                    ; |Initilize Extra Segment
  277.     MOV   DS,AX                       ;/
  278.  
  279.     ; Split Commandline
  280.     CALL  DoParams                    ;Splits Commandline
  281.  
  282.     ; Do Intro
  283.     MOV   AH,9h
  284.     MOV   DX,OFFSET Copyright
  285.     INT   21h
  286.     ; Check Parameters
  287.     CMP   [FileOkay],1                ;Is file okay to execute
  288.     JE    @@ParamOkay                 ;Yes, Jump
  289.     ; Parameter Error
  290.     MOV   AH,9h
  291.     MOV   DX,OFFSET Usage
  292.     INT   21h
  293.     JMP   SHORT @@ExitProgram         ;Jump to exit
  294.  
  295. @@ParamOkay:
  296.     CALL  Install                     ;Install
  297.  
  298.     MOV   BX,Offset ParamBlock        ;ParamBlock -> BX
  299.     MOV   DX,Offset File              ;Filename -> DX
  300.     MOV   [CS:OldSS],SS               ;Save Stack Segment
  301.     MOV   [CS:OldSP],SP               ;Save Stack Pointer
  302.     MOV   AX,4B00h                    ;Execute program
  303.     INT   21h                         ;DOS Interrupt
  304.     STI                               ;Disable Interrupts
  305.     MOV   SS,[CS:OldSS]               ;ReStore Stack Segment
  306.     MOV   SP,[CS:OldSP]               ;ReStore Stack Pointer
  307.     CLI                               ;Enable Interrupt
  308.     JNC   @@Okay                      ; |If Carry set then
  309.     MOV   AH,9h                       ; |  Error;
  310.     MOV   DX,OFFSET FileError         ; |
  311.     INT   21h                         ;/
  312. @@Okay:
  313.     CALL  UnInstall                   ;UnInstall
  314.  
  315. @@ExitProgram:
  316.     MOV   AX,4C00h
  317.     INT   21h
  318.  
  319.     END   START
  320.