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


im learning graphical programming in tasm using dosbox. ive been using bunch of loops draw square blocks of pixels , hard. want know if theres way read image , display it. know how read txt file maybe start. pls help

you need write/use image loader or use own image file format. bmp may simple has in compression pixel formats etc still can focus on specific type of bmp , ignore others...

back in days of ms-dos using 256 color pcx images palette used 256 color video modes. here nasm linez game example:

see pcx: subroutine. decodes loaded pcx file memory ds:0 raw vga image @ es:di. beware support 64 kbyte size limit !!! visualize image have copy es:di content videoram (assuming a000:0000) example rep movsd or can set es:di in first place (but flicker).

this pcx loader not use palette image need encode ... (the routines change vga palette included in source need extract rgb values pcx think @ end of file) here:

if converts pcx 32bit raw image.

for more info ms-dos game programing see pcgpe 1.0

here game example (tasm) uses own image file-format:

it has text menues, binary file access, 320x200 sprite graphics, 3 human players

[edit1] new code

i removed old code example , instead created compilable , working 8bit pcx color palette viewer in tasm. uses vesa 800x600x256 colors mode (103h).

the image must fit screen , file size must less 64 kbyte !!!

i did not add checks or error messages ... loads file image.pcx , displays on vesa wait on key hit end exit. here tasm source:

pcx.asm

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;     .386     ideal     model tiny ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;     dataseg file:   db 'image.pcx',0    ;filename 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 ds:buff, cx bytes     call    fopen     lea dx,[buff]     mov cx,64000    ; max value fit ds segment     call    fread       ; cx pcx real size     call    fclose      lea si,[buff]   ; decode directly 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     mov [cs:scrpag],al     mov     dl,al     sub     dh,dh     sub     bx,bx     mov     ax,4f05h    ; window     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 @ ds:si 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     , 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 take image 800x600 convert 256 color pcx palette , rename image.pcx. place *.com file , run. compiled volcov commander extension script vc.ext this:

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

so each time hit enter on asm file compile. change paths , if not targeting *.com files change /t switch accordingly. here preview dosbox:

preview


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -