brown@nicmad.UUCP (10/30/86)
Quite awhile ago I received from Hercules, three programs to use with their graphics cards. Maybe some of you do programming with the graphics card and would like a little hint. The files are in shar format and also remove the .signature at the end. Mike Brown ***** CUT HERE ***** #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # check.asm # herc.asm # herc.doc # modetest.asm # This archive created: Thu Oct 30 13:38:58 1986 # By: Mr. Video () export PATH; PATH=/bin:$PATH echo shar: extracting "'check.asm'" '(1132 characters)' if test -f 'check.asm' then echo shar: will not over-write existing file "'check.asm'" else sed 's/^ X//' << \SHAR_EOF > 'check.asm' X;- - - - - - - - - - - - - - - - - X; CHECK.ASM X; X; Will perform a test to see if X; a Hercules Graphics Card is X; present. X; X;- - - - - - - - - - - - - - - - - X Xstatus_port equ 03BAh ; Display Status Port - Bit 7 X ; changes on vertical retrace. Xdseg segment X msg1 db 0dh,0ah,'Yes, this is a Hercules Graphics Card.$' X msg2 db 0dh,0ah,'Hey, this is not a Hercules Graphics Card!$' Xdseg ends X Xstack segment STACK X dw 40 dup (?) Xstack ends X Xcheck segment X assume cs:check,ds:dseg,ss:stack X Xstart proc far X X push ds X xor ax,ax X push ax X X mov ax,dseg X mov ds,ax X X mov dx,status_port ; Take a reading X in al,dx X and al,80h X mov ah,al ; Save bit 7 for test X X mov cx,8000h Xexamine: X in al,dx ; Take another reading X and al,80h ; Isolate bit 7 X cmp al,ah X jne hercules ; If bit 7 changes then it X loop examine ; is a Hercules Graphics Card X X jmp other ; After this long, it must be X ; something else. X Xhercules: X mov dx,offset msg1 ; Print appropriate message X mov ah,9 X int 21h X X jmp exit X Xother: X mov dx,offset msg2 ; Print appropriate message X mov ah,9 X int 21h X Xexit: X ret X Xstart endp Xcheck ends X end start X X SHAR_EOF if test 1132 -ne "`wc -c < 'check.asm'`" then echo shar: error transmitting "'check.asm'" '(should have been 1132 characters)' fi fi # end of overwriting check echo shar: extracting "'herc.asm'" '(11843 characters)' if test -f 'herc.asm' then echo shar: will not over-write existing file "'herc.asm'" else sed 's/^ X//' << \SHAR_EOF > 'herc.asm' X; HERC.ASM version 1.11B by Bela Lubkin 3/4/85 X; Copyright (C) 1985, Borland International X; X; This program may be freely distributed as long as Borland copyright X; notices are retained both in source and object files. X; X; Enhancements from version 1.00A: X; (1) HERC will no longer allow itself to be run twice, and it will not load X; if SideKick is present (therefore it must be loaded before SK). X; (2) Alt + left SHIFT + 'H' turns on Hercules graphics mode, page 1. (G X; turns on page 0). AutoCAD is known to use page 1. If turning on page 0 X; gives junk on the screen, try page 1. X; X; When this program is run, it checks the system for the presence of a X; Hercules graphics card. If there is one present, it installs a resident X; routine that will turn Hercules graphics mode on (page 0) whenever you type X; ALT + left SHIFT + 'G'. Typing Alt + left SHIFT + 'H' will turn on Hercules X; graphics mode page 1 (AutoCAD uses this). Finally, Alt + left SHIFT + 'T' X; will turn graphics mode off (turn text mode on). X; X; The main use for this is to turn graphics mode back on after bringing X; SideKick up inside a graphics program. For instance, if you are using MS X; WORD on the HGC, and you bring SK up, the screen is left in text mode when X; you exit. You then type ALT-left SHIFT-G and WORD is back! X; X; There are three error messages that can be printed when HERC is run: X; X; "Hercules graphics card not detected in system" means that HERC cannot find X; a Hercules Graphics card in your computer. If you have an HGC and it is not X; detected, please report to me through the Borland SIG on CompuServe (GO X; BOR), or through Borland International technical support at (408) 438-8400. X; X; "HERC must be loaded before SideKick" will be printed if HERC detects that X; SideKick has already been loaded into your system. HERC must be run before X; SideKick for proper operation. (Almost all other resident programs must X; also be run before SideKick). Note that if SideKick has been loaded, HERC X; will no longer be able to detect its own presence in the system, so you will X; get this message if both programs are already in the system. X; X; "HERC has already been loaded - type Alt + Left shift + G, H or T" will be X; printed if you try to run HERC after it has already been loaded into your X; system. This is to prevent the instant crash that would happen if you X; loaded HERC twice. X; X; X; To assemble this: X; MASM HERC; (or ASM) X; LINK HERC; X; EXE2BIN HERC HERC.COM X; X XTerminate = 20H ; Terminate interrupt XMsDos = 21H ; MS-DOS interrupt XTermResident = 27H ; Terminate but stay resident interrupt X XDOSPrint = 9 ; INT 21 code 9, print string X XCR = 13 XLF = 10 X XBIOSStuff = 0040H ; Segment value for BIOS parameters XShiftFlags = 0017H ; Offset value for BIOS shift flags state X XHercConfig = 03BFH ; Hercules configuration port XHercStatus = 03BAH ; Hercules status port XHercControl = 03B8H ; Hercules control port XHercIndex = 03B4H ; Hercules 6845 index port XHercValue = 03B5H ; Hercules 6845 value port (label not used) XHercScreenEnable = 8 ; Bit to send to control port to enable video X XAlt = 08H ; Shift key flag bit for ALT key XCtrl = 04H ; Shift key flag bit for CTRL key XLShift = 02H ; Shift key flag bit for left SHIFT key XRShift = 01H ; Shift key flag bit for right SHIFT key X XInvoke = Alt+LShift ; Invoking sequence is ALT-left SHIFT X XKbdIn = 60H ; Keyboard scan code input port XKbdCtrl = 61H ; Keyboard control port XScanCodeG = 22H ; Scan code for 'g' key XScanCodeH = 23H ; Scan code for 'h' key XScanCodeT = 14H ; Scan code for 't' key X XEndOfINT = 20H ; Interrupt controller end-of-interrupt signal XINTCtrl = 20H ; Interrupt controller port X XF = 0FFH ; Just to save typing... X XHerculesSideKickFix Segment XAssume CS:HerculesSideKickFix, DS:Nothing, ES:Nothing X X ORG 0100H X XHercFix:JMP Initialize XHercModes: DB 32,61H,50H,52H,0FH,19H,06H,19H,19H,02H,0DH,0BH,0CH X DB 2, 35H,2DH,2EH,07H,5BH,02H,57H,57H,02H,03H,00H,00H X XNoOfVals = 0CH ; Number of 6845 parameters X XHMode: ; SI=0 for text, 0DH for graphics. X ADD SI,Offset HercModes ; SI=Offset of ModeDescriptor[Mode] X MOV DX,HercConfig ; [DX]=Configuration port X MOV AL,1 ; Allow graphics, page 0 only X OUT DX,AL X MOV AL,CS:[SI] ; AL=ModeDescriptor.CRTMode X MOV DL,HercControl And F ; [DX]=Control port X OUT DX,AL X MOV CX,0 ; For CX:=0 To 11 Do Begin X MOV DL,HercIndex And F ; [DX]=Index port XOutLoop:MOV AL,CL X OUT DX,AL ; Select CX'th register X INC SI X MOV AL,CS:[SI] ; AL:=ModeDescriptor.R6845[CX] X INC DX ; [DX]=Data port X OUT DX,AL X DEC DX X INC CX X CMP CL,NoOfVals X JNZ OutLoop ; End X SUB SI,NoOfVals X MOV AL,CS:[SI] ; AL:=ModeDecriptor.CRTMode X OR AL,HercScreenEnable ; Or ScreenEnable X MOV DL,HercControl And F ; Control port X OUT DX,AL X RET ; Routine modified from Hercules version X ; of Turbo Graphix Toolbox X XOldINT9:DD ? ; Will save old keyboard INT vector for X ; proper keyboard interrupt processing X XID: DB 'HCBL' X XNewINT9:PUSH ES X PUSH AX X PUSH SI X PUSHF X MOV AX,BIOSStuff X MOV ES,AX X MOV AL,ES:[ShiftFlags] ; Get BIOS shift key state flags X AND AL,Invoke X CMP AL,Invoke ; Both ALT and left SHIFT depressed? X JNE DoOldINT9 X IN AL,KbdIn ; Get scan code X CMP AL,ScanCodeG ; 'G'? X JE GrafMode ; Yes: turn graphics on X CMP AL,ScanCodeH ; 'H'? X JE GrafMode ; Yes: turn graphics on, page 1 X CMP AL,ScanCodeT ; 'T'? X JNE DoOldINT9 ; No: pass on to former keyboard int X MOV SI,0 ; Yes: set text mode XDoMode: PUSH DX X PUSH CX X PUSH AX X CALL HMode X POP AX X CMP AL,ScanCodeH ; Need to set page 1? X JNE Exit X MOV AL,3 X MOV DX,HercConfig X OUT DX,AL ; Allow graphics, both pages X MOV DL,HercControl and F X MOV AL,8AH X OUT DX,AL ; Set graphics mode, page 1 X XExit: IN AL,KbdCtrl ; Reset key ready bit... nobody sees X MOV AH,AL ; key but us X OR AL,80H X OUT KbdCtrl,AL X MOV AL,AH X OUT KbdCtrl,AL X MOV AL,EndOfINT ; Tell interrupt processor we're X OUT INTCtrl,AL ; (almost) done. X POP CX X POP DX X POPF X POP SI X POP AX X POP ES X IRET X XGrafMode: ; Set graphics mode X MOV SI,0DH X JMP DoMode X XDoOldINT9: X POPF X POP SI X POP AX X POP ES X JMP DWord Ptr [OldINT9] ; Key is not 't', 'g' or 'h' with Invoke X ; flags set, so pass on to old X ; keyboard handler X ; Took me 45 minutes to figure out the X ; MASM syntax for what DEBUG took as X ; simply JMP FAR [address] !! X XInitialize: X MOV AH,9 X MOV DX,Offset CopyRightMsg X INT MsDos X XOR AX,AX X MOV DS,AX X LDS DI,Dword ptr DS:[0020H] ; INT 8 vector X CMP Word ptr DS:[DI-4],'KS' X JNE CheckHERCLoaded X MOV DX,Offset SKAlreadyLoadedMSG X CMP Word ptr DS:[DI-2],'IB' X JE AbortMSG X XCheckHERCLoaded: X MOV DS,AX X LDS DI,Dword ptr DS:[0024H] ; INT 9 vector X CMP Word ptr DS:[DI-4],'CH' X JNE CheckHGC X MOV DX,Offset HERCAlreadyLoadedMSG X CMP Word ptr DS:[DI-2],'LB' X JNE CheckHGC X XAbortMSG: X PUSH CS X POP DS X MOV AH,DOSPrint X INT MsDos X INT Terminate X XNotThere: X MOV DX,Offset NotThereMsg X JMP Short AbortMSG X XCheckHGC: X MOV BX,0100H X MOV DX,HercStatus ; Loop looking for status port bit 7 to X IN AL,DX ; be on. Herc uses it as a retrace X MOV AH,AL ; indicator while IBM doesn't ever X AND AH,80H ; turn it on. XII1: MOV CX,0040H XII2: IN AL,DX X AND AL,80H X CMP AL,AH X LOOPZ II2 X JNZ EndLoop X DEC BX X JNZ II1 XEndLoop:JZ NotThere ; Not a herc if status doesn't change X MOV AX,0B000H X MOV DS,AX ; Need DS prefixes because of DS:Nothing X MOV BL,DS:[7FFFH] ; Check for at least a full 32K of X MOV CL,DS:[3FFFH] ; memory. (Some cards other than herc X INC Byte ptr DS:[3FFFH] ; do set bit 7) X CMP BL,DS:[7FFFH] X MOV DS:[3FFFH],CL ; Restore former value X JE There X MOV DX,HercConfig ; [DX]=Configuration port X MOV AL,1 ; Allow graphics, page 0 only X OUT DX,AL ; -- in case memory test failed because X MOV BL,DS:[7FFFH] ; the card was in 'diagnostic' mode X MOV CL,DS:[3FFFH] X INC Byte ptr DS:[3FFFH] X CMP BL,DS:[7FFFH] X MOV DS:[3FFFH],CL X JNE NotThere ; Not >=32K RAM: not a herc X XThere: MOV AX,0 X MOV ES,AX X MOV BX,ES:[0024H] ; Get current INT 9 vector X MOV CX,ES:[0026H] X MOV Word ptr [OldINT9],BX X MOV Word ptr [OldINT9+2],CX ; Save it X MOV DX,Offset NewINT9 X MOV AX,2509H X PUSH CS X POP DS X INT MsDos ; Set INT 9 to our handler X MOV DX,Offset InstalledMSG X MOV AH,DOSPrint X INT MsDos ; Say we're installed X MOV DX,Offset Initialize ; Terminate and stay resident (keep only X INT TermResident ; the necessary code, not this init X ; stuff. Still saves a copy of the X ; environment + a PSP, about 1/2K) X XCopyRightMsg: X DB 'HERC.COM Copyright (C) 1985, Borland International',CR,LF X DB 'This program may be freely copied as long as this copyright notice is retained',CR,LF,'$' XNotThereMsg: X DB 'Hercules graphics card not detected in system$' XSKAlreadyLoadedMSG: X DB 'HERC must be loaded before SideKick$' XHERCAlreadyLoadedMSG: X DB 'HERC has already been loaded - type Alt + Left shift + G, H or T$' XInstalledMSG: X DB 'HERC version 1.11B installed. Type Alt + Left shift + G for graphics page 0,' X DB CR,LF,'Alt + LS + H for graphics page 1, or Alt + LS + T for text.$' X XHerculesSideKickFix ENDS X END HercFix SHAR_EOF if test 11843 -ne "`wc -c < 'herc.asm'`" then echo shar: error transmitting "'herc.asm'" '(should have been 11843 characters)' fi fi # end of overwriting check echo shar: extracting "'herc.doc'" '(782 characters)' if test -f 'herc.doc' then echo shar: will not over-write existing file "'herc.doc'" else sed 's/^ X//' << \SHAR_EOF > 'herc.doc' X Because there is no system record of the Hercules Graphics Card's graphics Xmode, SideKick cannot determine the current mode of the Hercules card. As a Xconsequence of this, after bringing SideKick up the screen is always left in Xthe text mode. X X After running HERC.COM, typing ALT-left shift-G will turn Hercules Graphics Xmode on. ALT-left shift-T will turn it off (turn text mode on). After Xleaving SK, if the screen is left all garbled, type ALT-left shift-G to fix Xit! X X If G doesn't do the job, try ALT-ls-H, which turns on the Hercules card's Xsecond graphics page. AutoCAD uses this, as do many other programs. X X HERC should be run before SideKick, so that SideKick can be killed by typing XCTRL-Home CTRL-End from its main menu. X X - Bela Lubkin, Borland International SHAR_EOF if test 782 -ne "`wc -c < 'herc.doc'`" then echo shar: error transmitting "'herc.doc'" '(should have been 782 characters)' fi fi # end of overwriting check echo shar: extracting "'modetest.asm'" '(4313 characters)' if test -f 'modetest.asm' then echo shar: will not over-write existing file "'modetest.asm'" else sed 's/^ X//' << \SHAR_EOF > 'modetest.asm' X X;HERCULES COMPUTER TECHNOLOGY X X; This code is designed to illustrate the technique used to X; dynamically sense the mode (text or graphics) of the Hercules X; Graphics Card. The way that the program does this is to set the X; light pen flip-flop and then read the light-pen trip address X; in the 6845. A comparison of the value obtained here and a X; "threshold" value reveals the current mode. X X;MODETEST.ASM - In Response to Alt-Left Shift will beep once if the HGC X; is in text mode, twice if the HGC is in graphics mode. X;5-23-85 X XKbInt equ 9*4 ;Vector location for keyboard routine XBIOSseg equ 0040h ;Segment value for BIOS parameters XShftFl equ 0017h ;Offset for BIOS keyboard flag XALT equ 8 ;Bit flag for ALT key XLShift equ 2 ;Bit flag for Left Shift key XInvoke equ ALT+LShift ;Invoking Sequence XLpSet equ 03B9h ;Set light pen address XLpReset equ 03BBh ;Reset light pen address XLpff equ 2 ;Flip-flop suitable for s/w query XOur6845 equ 03B4h ;6845 index register XOurStat equ 03BAh ;Display Status Port XNotVSync equ 80h ;This bit 0 during vertical X ; retrace XThreshold equ (80*25 + 45*87)/2 ;This value is the average of the X ;possible byte offset numbers in text X ;(80*25) and graphics (45*87) modes. X Xmode segment X assume cs:mode,ds:mode,es:nothing X org 100h X Xok: jmp loader X XErrMsg db 0dh,0ah,'Light-Pen not operative - aborting.$' XKb dd 0 X Xmodetest: X push ax X push dx X X push es X push ds X X push cs X pop ds X X mov ax,BIOSseg X mov es,ax X mov al,es:[ShftFl] ;Get Keyboard state X and al,Invoke X cmp al,Invoke ;Is it ALT-Left Shift X jne Done ;If not, do normal INT 9 X X;****************** This is the code you are interested in ****************** X;****************** Mode Detection ****************** X X xor al,al X mov dx,OurStat Xwait1: ;test for v-sync transtition X in al,dx X test al,NotVSync X jz wait1 Xwait2: X in al,dx X test al,NotVSync X jnz wait2 X X xor al,al ;Reset and Set Light Pen. X mov dx,LpReset X out dx,al X mov dx,LpSet X out dx,al X X xor bx,bx X X mov al,16 ;Look in the 6845 for the offset into X mov dx,Our6845 ; buffer when the light pen is X out dx,al ; tripped - high byte. X inc dx X in al,dx X mov bh,al X X mov al,17 ;Get low byte of light pen X mov dx,Our6845 ; trip address X out dx,al X inc dx X in al,dx X mov bl,al ;BX now contains Light Pen trip X ; address. X X xor dx,dx ;Set up dx as flag for sound routine X ; you don't need this. X X cmp bx,threshold ;If BX < threshold value - text mode. X jb sound ;Jump to what should happen for text. X X;************************* End of interesting code.************************* X X mov dl,01 ;Flag to indicate graphics mode X Xsound: ;This code just sounds speaker X mov al,10110110b X out 43h,al X mov ax,800h X out 42h,al X mov al,ah X out 42h,al X X in al,61h X mov ah,al X or al,3 X out 61h,al X X mov cx,0ffffh Xpause: loop pause X mov al,ah X out 61h,al X X cmp dl,1 ;If graphics mode, beep again X jne done X X dec dl X X mov cx,7fffh Xpause1: loop pause1 X jmp sound X Xdone: X pop ds X pop es X pop dx X pop ax X X jmp cs:Kb ;Original Interrupt 9 code. X Xloader: X push ds ;Set up a Far return to DS:0000 X xor ax,ax X push ax X X push es X push si X push di X X push cs X pop ds ;Makes DS = CS X X;**************************** Also of interest ****************************** X;******* Makes sure light pen is present and working before loading ********* X X mov dx,LpSet X out dx,al X mov dx,OurStat X in al,dx X test al,Lpff X jz exit ;If light pen stuck low, can't do X ;mode test - abort. X mov dx,LpReset X out dx,al X mov dx,OurStat X in al,dx X test al,Lpff X jnz exit ;If light pen stuck high, can't do X ;mode test - abort. X X;********************* End of minor interest section ************************ X X; Save original keyboard routine X X xor ax,ax X mov es,ax X mov si,KbInt X lea di,Kb X X cli X mov ax,es:[si] X mov cs:[di],ax X mov ax,es:[si+2] X mov cs:[di+2],ax X sti X X; Load keyboard vector with our routine X X mov di,KbInt X mov ax,cs X lea si,modetest X X cli X mov es:[di],si X mov es:[di+2],ax X sti X X pop di X pop si X pop es X X pop ax X pop ds X X lea dx,loader ;DOS terminate but remain resident. X int 27h X Xexit: ;Have failed to load, quit. X mov ah,9 X mov dx,offset ErrMsg X int 21h X X pop di X pop si X pop es X X ret X Xmode ends X end ok X SHAR_EOF echo shar: a missing newline was added to "'modetest.asm'" if test 4313 -ne "`wc -c < 'modetest.asm'`" then echo shar: error transmitting "'modetest.asm'" '(should have been 4313 characters)' fi fi # end of overwriting check # End of shell archive exit 0 -- ihnp4------\ harvard-\ \ Mr. Video seismo!uwvax!nicmad!brown topaz-/ / decvax------/