Asm code to C code

Discussion in 'C Programming' started by LordBlue, Aug 15, 2003.

  1. LordBlue

    LordBlue Guest

    Hi, please forgive me if i'm sending this post in the wrong place, and
    please don't tell me to post it in another group, because if i found a
    better one i'd have already done it. I'm writing a thesis and i'm in
    real hurry. I have an old c code which i cannot compile correctly. I
    am using the Dev-Cpp 4 compiler. Anyway, my question is: i have
    already solved most of the problems deleting some parts of the code
    which used graphics i don't need (and by the way cannot even see using
    winxp) but i have a function i cannot delete which is written in ASM.
    I know what are you thinking: "use an assembler to compile it first
    and then link the two files together.". But I don't want to make it as
    it would take me much more time to find an assembler, learn to use it
    and then learn to compile and link separately.
    So please, if anyone knows how to do it, i need the ASM code to be
    rewritten in C code.
    I am sending the whole ASM source file, because i don't know which are
    the important parts of it. I only need the TTY function.
    Thank You very, very much!!!

    ;
    ;ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
    ;º Miscellaneous auxiliary assembler routines
    º
    ;ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ
    ;º B. Mueller, J. Reinhardt: Neural Networks
    º
    ;º (C) Springer Verlag 1990
    º
    ;ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
    ;

    PUBLIC _TTY, _HERCLEAR, _CGACLEAR, _EGACLEAR, _VIDEO_TEST

    include asmuti.h ; useful assembler macros

    _TEXT SEGMENT PARA PUBLIC 'CODE'
    ASSUME CS:_TEXT ; Segmentname fuer C-Programm

    ;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
    ;³ Write a string into text screen
    ³
    ;³ Usage: TTY(row,col,attrib,string,textscreen)
    ³
    ;³ row,col: screen position
    ³
    ;³ attrib: character attribute (color, highlighted, blinking)
    ³
    ;³ string: outputstring
    ³
    ;³ textscreen: memory address of the text screen (b000 or b800)
    ³
    ;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    pBegin _TTY
    push bp
    mov bp,sp
    push di
    push si
    push ds
    push es

    mov ax,[bp+argbase] ; Zeile
    mov bl,160
    mul bl ; *160
    mov bx,[bp+argbase+2] ; Spalte
    shl bx,1 ; *2
    add ax,bx ; DI:Offset = 160*Zeile + 2*Spalte
    mov di,ax

    xor ax,ax
    mov ax,[bp+argbase+4] ; AH:Attribute
    mov ah,al

    mov si,[bp+argbase+6] ; ds:si is pointer to string
    ifdef FARDATA
    mov ds,[bp+argbase+8] ; ds: String-Segment
    endif

    mov dx,[bp+argbase+10] ; DX: Video-RAM-Segment
    mov es,dx

    hneu: mov al,[si]
    or al,al ; Set zero flag
    jz hende
    stosw ; Copy AX to es:di, increment di
    inc si
    jmp hneu

    hende: pop es
    pop ds
    pop si
    pop di
    mov sp,bp
    pop bp
    ret
    ;
    pEnd _TTY

    ;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
    ;³ Routine to clear the Hercules graphics screen
    ³
    ;³ Usage: HERCLEAR(pattern,page)
    ³
    ;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    pBegin _HERCLEAR
    push bp
    mov bp,sp
    push di
    push si
    push es

    mov bx,[bp+argbase+2]
    cmp bx,0h
    jne pagelbl
    mov ax,0b000h
    jmp weiter
    pagelbl:mov ax,0b800h
    weiter: mov es,ax
    xor di,di
    mov cx,04000h
    mov ax,[bp+argbase] ; Byte pattern to be displayed
    repz stosw

    pop es
    pop si
    pop di
    mov sp,bp
    pop bp
    ret
    ;
    pEnd _HERCLEAR

    ;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
    ;³ Clear the CGA graphics screen
    ³
    ;³ Usage: CGACLEAR(pattern)
    ³
    ;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    pBegin _CGACLEAR
    push bp
    mov bp,sp
    push di
    push si
    push es

    mov ax,0b800h
    mov es,ax
    xor di,di
    mov cx,02000h
    mov ax,[bp+argbase] ; Pattern to be displayed
    repz stosw

    pop es
    pop si
    pop di
    mov sp,bp
    pop bp
    ret

    ;
    pEnd _CGACLEAR

    ;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
    ;³ Clear the EGA graphics screen
    ³
    ;³ Usage: EGACLEAR()
    ³
    ;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
    pBegin _EGACLEAR
    push bp
    mov bp,sp
    push di
    push si
    push ds
    push es

    mov dx,3c4h
    mov al,2
    out dx,al
    inc dx
    mov al,0ffh
    out dx,al ; Enable access to all 4 planes

    mov dx,3ceh
    mov al,8
    out dx,al
    mov al,0ffh
    inc dx
    out dx,al ; Enable access to all 8 bits

    mov ax,0A000h ; Starting address
    mov es,ax
    xor ax,ax
    mov di,ax
    mov cx,28000
    cld
    rep stosb ; Cclear screen


    mov dx,3ceh
    mov al,5 ; Mode Register 5
    out dx,al
    mov dx,3cfh
    mov al,0 ; Write Mode 0
    out dx,al

    mov dx,3ceh
    mov al,1 ; Enable Set/Reset register 1
    out dx,al
    mov dx,3cfh
    mov al,0fh ; Enable all planes
    out dx,al

    pop es
    pop ds
    pop si
    pop di
    mov sp,bp
    pop bp
    ret
    pEnd _EGACLEAR

    ;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
    ;³ Routine to analyze the video screen adapter cards and displays
    ³
    ;³ in an IBM compatible system.
    ³
    ;³ Adapted from a program by Dan Jacobs and Joel Rosenblum (1986)
    ³
    ;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

    ; video mode equates
    UNKNOWN equ 00H ; Unknown board type
    CGA equ 01H ; IBM Color graphics adapter (CGA)
    MONO equ 02H ; IBM Monochrome card
    HERCULES equ 04H ; Hercules monochrome graphics card
    EGA_MONO equ 10H ; IBM Enhanced graphics adapter (EGA)
    monochrome
    EGA_COLOR equ 20H ; EGA w/color display
    EGA_HIGH equ 40H ; EGA w/high resolution color display

    ; global equates
    VIDEO_IO equ 10H ; BIOS video i/o interrupt number
    GET_MODE equ 0FH ; video i/o get mode function

    video_type db ? ; place to accumulate the video type

    pBegin _VIDEO_TEST
    push bp ; save the frame pointer
    mov bp, sp


    check_ega:
    ; This method of checking the EGA requires the use of BIOS
    routines

    mov ax, 1200H ; video alternate select
    mov bl, 10H ; return EGA info
    mov bh, 0FFH ; invalid data for test
    mov cl, 0FH ; reserved switch setting
    int VIDEO_IO ; returns with bh = color or
    mono mode
    ; bl = memory
    value
    ; ch = feature
    bits
    ; cl = switch
    setting

    cmp cl, 0CH ; test switch setting
    jge ega_done ; above max setting
    cmp bh, 01H ; test range 0 - 1
    jg ega_done ; above range
    cmp bl, 03H ; check memory value for 0 - 3
    range
    jg ega_done ; above range

    ; if it gets here, there is a EGA card present
    ; now test for the attached monitor

    and cl, 0EH ; trim the switch to the bits
    we need
    cmp cl, 1010B ; monochrome monitor attached
    ?
    je is_m
    cmp cl, 0100B ; secondary mono setting ?
    jne ecolor ; nope check color display
    is_m: or cs:video_type, EGA_MONO ; set EGA card with monochrome
    display
    jmp short ega_done
    ecolor: cmp cl, 1000B ; primary color display ?
    je is_c
    cmp cl, 1110B ; secondary color ?
    jne enh_d ; check for high resolution
    display
    is_c: or cs:video_type, EGA_COLOR ; EGA card with color
    display
    jmp short ega_done
    enh_d: cmp cl, 1100B ; primary high resolution
    display ?
    je is_enh
    cmp cl, 0110B ; secondary high resolution
    display ?
    jne ega_done
    is_enh: or cs:video_type, EGA_HIGH ; EGA card w. high resolution
    color display

    ega_done:

    ; check for Hercules card is present by checking the status
    port
    ; at 3BAH for the vertical retrace bit.

    mov dx,3BAH ; address of status port
    in al,dx
    and al,80h ; vertical retrace bit
    mov ah,al ; Save bit 7 for test

    mov cx,8000h ; count for delay loop
    examine:
    in al,dx ; Take another reading
    and al,80h ; Isolate bit 7
    cmp al,ah
    jne is_hercules ; If bit 7 changes then it
    loop examine ; is a Hercules Graphics Card

    jmp check_color ; After this long, it must be
    ; something else.
    is_hercules:
    or cs:video_type, HERCULES
    jmp short check_done ; don't check for mono or
    color
    ; board if Hercules present

    check_color:
    test cs:video_type, EGA_COLOR + EGA_HIGH
    jnz check_mono ; can't have a color card with
    ; EGA in color mode

    ; next check for a Color Graphics Adapter by the checking for
    the
    ; presence of the cursor register at 0x3D4
    mov dx, 03D4H
    call CURSOR_REG ; carry flag set if not there
    jc check_mono
    or cs:video_type, CGA ; there is a color graphics
    adapter

    check_mono:
    test cs:video_type, EGA_MONO ; can't have mono card in
    machine
    jnz check_done ; with EGA in mono

    ; first check for a monochrome board by checking for the
    ; presence of the cursor register at 0x3B4
    mov dx, 03B4H
    call CURSOR_REG ; carry flag set if not there
    jc check_done
    or cs:video_type, MONO ; there is a monochrome
    adapter card

    check_done:
    xor ax, ax ; clear ah
    mov al, cs:video_type

    pop bp ; restore frame pointer

    ret

    pEnd _VIDEO_TEST
    comment\**********************************************************************
    NAME
    CURSOR_REG

    SYNOPSIS
    checks to see if there is a cursor register at the
    address passed in dx

    RETURN VALUE
    carry clear - if cursor register present
    carry set - no cursor register here

    *****************************************************************************\
    CURSOR_REG proc near

    mov al, 0FH ; set the index to the cursor register
    out dx, al
    inc dx ; increment to data register
    in al, dx ; get the original value
    xchg al, ah ; save it for later
    mov al, 5AH ; test value
    out dx, al ; set cursor control register
    jmp $+2 ; waste some time
    jmp $+2
    jmp $+2
    in al, dx
    cmp al, 5AH ; same as written ?
    xchg al, ah ; restore saved value
    out dx, al
    je yup ; it was the control register
    stc ; no cursor return code
    ret
    yup: clc ; is there return code
    ret

    CURSOR_REG endp

    _TEXT ENDS
    END
     
    LordBlue, Aug 15, 2003
    #1
    1. Advertising

  2. On 15 Aug 2003 04:17:57 -0700, (LordBlue) wrote:

    >Hi, please forgive me if i'm sending this post in the wrong place, and
    >please don't tell me to post it in another group, because if i found a
    >better one i'd have already done it.


    Better groups are in [comp.os.ms-windows.programmer.*].

    Repost your question there, and also read up on netiquette in general
    and the FAQ for this group.

    Follow-up set to [comp.os.ms-windows.programmer.win32] (that means
    that any answers to this posting will end up there).



    >I'm writing a thesis and i'm in real hurry.


    Your chances of ending up with a satisfactory thesis are very low,
    since (1) you're in a hurry, (2) you show disregard for commonly
    accepted rules, (3) you're unable to solve a trivial problem, and...


    > I have an old c code whichi cannot compile correctly. I
    >am using the Dev-Cpp 4 compiler. Anyway, my question is: i have
    >already solved most of the problems deleting some parts of the code
    >which used graphics i don't need (and by the way cannot even see using
    >winxp)


    (4) you base your work on modification of what others have done, and...


    > but i have a function i cannot delete which is written in ASM.
    >I know what are you thinking: "use an assembler to compile it first
    >and then link the two files together.". But I don't want to make it as
    >it would take me much more time to find an assembler, learn to use it
    >and then learn to compile and link separately.
    >So please, if anyone knows how to do it, i need the ASM code to be
    >rewritten in C code.


    (5) you think you know what you need as an answer, instead of
    figuring out what the problem is.


    > I only need the TTY function.


    See the comment above that function to find out what it does.

    Note that it was written for MS-DOS.

    Find a corresponding API function for the platform you're using,
    the follow-up redirection assumes Windows.


    >Thank You very, very much!!!


    [snipped umpteen lines of asm code]
     
    Alf P. Steinbach, Aug 15, 2003
    #2
    1. Advertising

  3. On 15 Aug 2003 04:17:57 -0700
    (LordBlue) wrote:
    > Hi, please forgive me if i'm sending this post in the wrong place


    You are forgiven.

    > please don't tell me to post it in another group, because if i found a
    > better one i'd have already done it.


    You somehow missed comp.lang.asm.x86? How did you manage to do that?

    > I'm writing a thesis and i'm in real hurry.


    Then you should have started earlier, and if you can't write the thesis by
    yourself, you shouldn't have started with it.

    > I have an old c code which i cannot compile correctly.


    Then you either have a bad compiler or the program isn't using standard C.

    > I am using the Dev-Cpp 4 compiler. Anyway, my question is: i have already
    > solved most of the problems deleting some parts of the code which used
    > graphics i don't need (and by the way cannot even see using winxp) but i have
    > a function i cannot delete which is written in ASM.


    Dev-Cpp is a compiler, off-topic. Next to that, it's a C++ compiler, and
    this is a standard C newsgroup. In this newsgroup we DISCUSS standard C, we
    don't rewrite programs in other languages, or do other people's homework, both
    of which you're asking us to do. Assembler is off-topic.

    > I know what are you thinking: "use an assembler to compile it first and then
    > link the two files together.".


    Actually, I was thinking 'what the hell was this guy thinking when he posted to
    c.l.c?' but yeah, yours is pretty close. Why haven't you done this yet?

    > But I don't want to make it as it would take me much more time to find an
    > assembler, learn to use it and then learn to compile and link separately.


    Ah, so that's why. You're too lazy. See your reason is bogus, you can find out
    how to use an assembler and a linker in two minutes these days, thanks to
    google. Rewriting this assembler program into C is a lot more work, and
    pointless at that, since you're either too lazy to learn how to use things you
    should have known already if you've ever coded in c or assembler (or writing a
    thesis having anything to do with either), or too lazy to do actual work for you
    thesis.

    > So please, if anyone knows how to do it, i need the ASM code to be rewritten
    > in C code.


    Doing that is tedious and boring. And in this case, it's pointless since the
    solution is right in front of you.

    > I am sending the whole ASM source file, because i don't know which are the
    > important parts of it. I only need the TTY function. Thank You very, very
    > much!!!


    You're welcome.

    <snip assembler>

    This newsgroup is for discussing Standard C. It's about that for a reason. And
    other topics are not handled, for a reason. If everyone would post questions
    about all topics in random newsgroups, things would quickly get out of hand,
    would they not? Kind of defeating the purpose of Usenet?

    Oh, and if you want someone to do your homework, threaten to beat up the skinny
    kid with the glasses who always sits in the corner of your classroom. He'll do
    it.

    --
    char*x(c,k,s)char*k,*s;{if(!k)return*s-36?x(0,0,s+1):s;if(s)if(*s)c=10+(c?(x(
    c,k,0),x(c,k+=*s-c,s+1),*k):(x(*s,k,s+1),0));else c=10;printf(&x(~0,0,k)[c-~-
    c+"1"[~c<-c]],c);}main(){x(0,"^[kXc6]dn_eaoh$%c","-34*1'.+(,03#;+,)/'///*");}
     
    Pieter Droogendijk, Aug 15, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Al Ponomarev
    Replies:
    3
    Views:
    478
    Ken Cox [Microsoft MVP]
    May 3, 2004
  2. Edwin Knoppert

    define byte asm substitute?

    Edwin Knoppert, Jan 11, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    517
    Edwin Knoppert
    Jan 11, 2006
  3. Joris

    C++ produced ASM code

    Joris, Aug 9, 2005, in forum: C++
    Replies:
    3
    Views:
    392
    Joris
    Aug 9, 2005
  4. Gernot Frisch

    asm code for ARM (very simple)

    Gernot Frisch, Sep 4, 2008, in forum: C++
    Replies:
    7
    Views:
    566
    Jorgen Grahn
    Sep 16, 2008
  5. MarlonBrando

    ASM method attribute and code order

    MarlonBrando, Oct 15, 2009, in forum: Java
    Replies:
    7
    Views:
    471
    Marcin Rze¼nicki
    Oct 15, 2009
Loading...

Share This Page