How to read image file and display on the screen in windows tasm dosbox

I am currently studying graphical programming in tasm using dosbox. I used a bunch of loops to draw square blocks of pixels, and it's really complicated. I want to know if there is a way to read the image and display it. I know how to read a txt file, maybe this is the beginning. Pls Help

-2
assembly tasm dosbox graphics
source share
1 answer

You need to write / use an image downloader or use your own image file format. BMP may look simple, but too much in it, like pixel compression formats, etc., but you can still focus on a specific type of BMP and ignore everyone else ...

In the days of MS-DOS, I used 256 color PCX images with a palette because I used 256 color video modes. Here's an example of a NASM LINEZ game:

  • Colored lines - a simple game in C ++ / verification algorithm

see pcx: routine pcx: It decodes the downloaded PCX file from ds:0 into the original VGA image in es:di . Be wary that it only supports 64 KByte size 64 KByte !!! Now, to render the image, you would need to copy the contents of es:di to VideoRAM (suppose A000:0000 ), for example, using rep movsd or you can set es:di for it (first of all) which may flicker).

This PCX loader, however, does not use the palette from the image, so you need to encode it ... (routines for changing the VGA palette are included in the source, which you just need to extract the RGB values ​​from PCX I think it was at the end of the file). Look at here:

  • my C ++ PCX loader with palette

if converts PCX to 32-bit source image.

For more information on MS-DOS software, see PCGPE 1.0

Here is another example game ( TASM ) that uses its own image file format:

  • What is the best way to move an object on the screen?

It has text menus, access to binary files, 320x200 sprite graphics, 3 people.

[Edit1] New code

I deleted the old code sample, and instead I created a compiled and working 8-bit PCX with a color palette viewer in TASM . It uses VESA mode 800x600x256 colors ( 103h ).

The image should fit on the screen, and its file size should be less than 64 KB.

I did not add any error messages or error messages ... It just uploads the image.pcx file and displays it on VESA , and then waits for the output with the final hit. Here is the source of TASM :

PCX.ASM

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .386 IDEAL MODEL TINY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DATASEG file: db 'image.pcx',0 ;filename to load buff: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CODESEG STARTUPCODE scrxs equ 800 scrys equ 600 mov ax,103h ; VESA 800x600x256 call vesamod mov al,0 call vesapag ; scrxs equ 320 ; scrys equ 200 ; mov ax,19 ; VGA 320x200x256 ; int 10h lea dx,[file] ; load PCX into DS:buff, CX bytes call fopen lea dx,[buff] mov cx,64000 ; some max value to fit into DS segment call fread ; CX is PCX real size call fclose lea si,[buff] ; decode directly to VRAM mov ax,0A000h mov es,ax mov di,0 call pcx mainl0: mov ax,256 ; test keyboard int 16h jz mainl0 sub ax,ax ; clear key buffer int 16h mov ax,3 ;|VGA 80x25 text int 16 ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; vesamod:pusha ;set VESA videomode ax mov bx,ax mov ax,4f02h int 16 popa ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; vesapag:pusha ;al=page switch vesa video page window A mov [cs:scrpag],al mov dl,al sub dh,dh sub bx,bx mov ax,4f05h ; window A int 16 popa ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .386P scrpag db 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .386P hand dw 0 ;### handler... ferr db 0 ;### DOS error code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; fopen: pusha ;DS:DX = file name, [hand] <= file handle mov ax,3D02h int 21h mov bl,0 jnc fopen0 mov bl,al sub ax,ax fopen0: mov [cs:hand],ax mov [cs:ferr],bl popa ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; fclose: pusha ;[hand] = file handle mov bx,[cs:hand] mov ah,3eh int 21h mov bl,0 jnc fclose0 mov bl,al sub ax,ax fclose0:mov [cs:ferr],bl mov [cs:hand],ax popa ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; fread: pusha ;DS:DX = adr, CX = lenght, [hand] = hand, CX => read mov bx,[cs:hand] mov ah,3Fh int 21h mov bl,0 jnc fread0 mov bl,al sub ax,ax fread0: mov [cs:ferr],bl mov [cs:freadsz],ax popa mov cx,[cs:freadsz] ret freadsz dw 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; pcx: pusha ;decode pcx at ds:si to es:di cx = PCX size push ds push es push ecx push edx push si ;set palette add si,cx sub si,768 sub ax,ax pall0: mov dx,3C8h mov al,ah out dx,al inc dx lodsb shr al,2 out dx,al lodsb shr al,2 out dx,al lodsb shr al,2 out dx,al inc ah jnz pall0 pop si mov ax,[ds:si+8] ;get xs sub ax,[ds:si+4] inc ax mov [cs:pcxxs],ax mov [cs:pcxx],ax mov ax,[ds:si+10] ;get ys sub ax,[ds:si+6] inc ax mov [cs:pcxys],ax mul [cs:pcxxs] push dx push ax pop edx add si,128 ;src start after pcx header sub ecx,ecx ;RLE decoder of PCX pcxl0: lodsb mov cx,1 cmp al,192 jb pcxr0 mov cl,al and cl,63 lodsb pcxr0: mov bx,cx pcxl1: call point dec [cs:pcxx] ;correct next screen line position if end of PCX line jnz pcxr1 mov ax,[cs:pcxxs] mov [cs:pcxx],ax neg ax add ax,scrxs add di,ax jnc pcxr1 ; page swith mov al,[cs:scrpag] inc al call vesapag pcxr1: loop pcxl1 mov cx,bx sub edx,ecx jz pcxesc jnc pcxl0 pcxesc: pop edx pop ecx pop es pop ds popa ret pcxxs dw 0 ;PCX resolution pcxys dw 0 pcxx dw 0 ;actual X coordinate ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; point: mov [es:di],al ;point ;estosb inc di jnz pntesc ; page swith mov al,[cs:scrpag] inc al call vesapag pntesc: ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

So, make any image up to 800x600 convert it to 256 color PCX with a palette and rename it to image.pcx . Then put it in the *.com file and run it. I compiled it with the Commander Volcov script vc.ext as follows:

 asm:@c:\language\compil\tasm\tasm !.! /ic:\language\source\tasm\inc @c:\language\compil\tasm\tlink !.obj /t /x @del !.obj 

so every time I press enter in any asm file, it compiles. Just change the paths, and if you do not target *.com files, change the /t switch accordingly. Here's a preview from my DOSBox :

preview

0
source share

All Articles