Search code examples
imageassemblygraphicsmasm

Display an image file saved in buffer MASM 5.1


I want to display an image in graphics mode. I have read the image to a buffer. I have made this code but how can I display the pixels on the screen? This code works to display a text file but how can I display the pixels?

readFIL PROC NEAR ; proc que escreve uma ficha
     mov ah, 3dh ;Open the file
    mov al, 0 ;Open for reading
    lea dx, FILENAM;Presume DS points at FILENAM
    int 21h ; segment.
    mov  FHAND, ax ;Save file handle
LP: mov ah,3fh ;Read data from the file
    lea dx, NAMEFLD ;Address of data NAMEFLD
    mov cx, 12 ;Read one byte
    mov bx,  FHAND ;Get file handle value
    int 21h

    cmp ax, cx ;EOF reached?
    jne EOF
    mov al, NAMEFLD ;Get character read   
    ;--------
    mov cx,0
    siga:


    ;----------------------

    mov al,NAMEFLD
    lea si , NAMEFLD
    MOV AH,09h 
    int 21h

    ;---------------------
    inc dx   ;->> move next caracter in buffer
    add cx, 1
    cmp cx,12
    jne siga

EOF: mov bx,  FHAND
     mov ah, 3eh ;Close file
     int 21h

 RET
readFIL ENDP

Need help for school but teacher don't help us anyway :(


Solution

  • Set a graphics mode using BIOS interrupt 10h function 0.

    I recommend setting mode 13h (320x200x8bpp) because it's the easiest to program and it should work on any VGA card or better.

    Then draw the image in the video buffer, pixel by pixel. The buffer starts at the physical address 0xA0000 and is 320*200=64000 bytes long.

    If you don't need to support more than the "16 standard" colors (the ones you get by default in text modes) or you're OK with black-and-white, you can avoid reprogramming the VGA palette in the VGA DAC and you can avoid finding the best color. Just convert the RGB triplets into brightness (add together 30% of the red value, 59% of the green value, and 11% of the blue value), scale the value to the range from 0 to 15 inclusive, add 16 to that and that's the byte value you should write into the video buffer.