2

I'm reverse-engineering some code I wrote in the middle-90s for which the source is long-lost and I'm a bit baffled by some VGA code I've encountered. I think it's probably from library or 3rd party code as I was just learning computers then and, while I did include some assembly to interact with VGA, it wasn't this informed.

If it's helpful, the app is a 16-bit DOS real-mode exe and the original source was compiled by the Turbo Pascal compiler (either version 6 or 7).

    ; function boilerplate
    push bp
    mov  bp,sp
    call 0EE2:0530  ; stack bounds check function

    ; probe vga port 03CCh
    sub  sp,0002    ; why?
    mov  dx,03CC
    in   al,dx
    and  al,0C      ; mask bits 3 & 2
    cmp  al,04      ; al == 00000100b
    mov  al,00      ; pre return value
    jne  jump_label ; return 0
    inc  ax         ; return 1
jump_label:
    ; store return value in [bp-01] as well, for.. reasons.
    mov  [bp-01],al
    mov  al,[bp-01]

    ; function boilerplate    
    mov  sp,bp
    pop  bp
    retf 0004 ; instance pointer?

So the question is, what is the intent here? Two parts are confusing to me:

First, bits 2 and 3 denote clock select according to the VGA docs I've read, but those docs are light on information about what that means when bit 3 is involved. For example, http://www.osdever.net/FreeVGA/vga/extreg.htm#3CCR3C2W declares the two values with the bit 3 set as undefined.

This function seems to return 0 when bit 3 is set and bit 2 isn't. But, why? What is it trying to determine about the hardware?

Second, and this is an aside, but what is the intent of mov [bp-01],al followed by mov al,[bp-01]? This seems redundant!

3

First: the code is only checking bit 2 (bit 0,1,2) if 25 or 28Mhz clock is set

Second: maybe its redundant but can't say without original code - could be still a problem with your disassembler

retf 0004 ; instance pointer?

is a far return with pop of 4 bytes from stack

| improve this answer | |
  • Ah yes, you're right. This function returns 1 only when the clock select bits are 01 (thus 28MHz or 360/720 width). It makes sense, if the bits were 11 then that would not be true so bit 3 must be preserved. I bet it's testing for the 9-pixel-wide-char VGA mode. Thank you! – Mike E Jun 2 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.