ASSEMBLY X86 - how to prevent Clear Flag errors? (the jc command) -


using dosbox tasm

first of all, want sorry incomprehensible title, didn't know how call because can't define problem myself, that's why need help.

i'm trying show blinking picture on screen, 2 pictures pretty same 1 object disappears in second picture, causing blink 'wait' procedure.

the problem occurs after 16 'wait' procedures causing problem (which can't manage define) related carry flag searched on internet bit , found out happens when bit reaches limit (0fh + 1 = 10h = 16) whats happens in procedure 'openfile' jc met , error msg shown. i'm posting because can't understand solution here or has fixed

ideal model small stack 100h dataseg ; -------------------------- ; variables: imgwelcome1 db 'welcome1.bmp',0 imgwelcome2 db 'welcome2.bmp',0 filename db 'test.bmp',0  filehandle dw 1  header db 54 dup (0)  palette db 256*4 dup (0)  scrline db 320 dup (0)  errormsg db 'error', 13, 10,'$'  counter db 0 ; -------------------------- codeseg ; -------------------------- ; procedures: proc openfile1     mov ah, 3dh     xor al, al     mov dx, offset imgwelcome1 int 21h jc openerror1 mov [filehandle], ax ret openerror1: mov dx, offset errormsg mov ah, 9h int 21h ret endp  proc openfile2 mov ah, 3dh xor al, al mov dx, offset imgwelcome2 int 21h jc openerror2 mov [filehandle], ax ret openerror2: mov dx, offset errormsg mov ah, 9h int 21h ret endp  proc readheader mov ah,3fh mov bx, [filehandle] mov cx,54 mov dx, offset header int 21h ret endp readheader  proc readpalette mov ah,3fh mov cx,400h mov dx,offset palette int 21h ret endp  proc copypal mov si, offset palette mov cx,256 mov dx,3c8h mov al,0 out dx,al inc dx palloop: mov al,[si+2] ; red value. shr al,2 ; max. 255, video palette maximal out dx,al ; send it. mov al,[si+1] ; green value. shr al,2 out dx,al ; send it. mov al,[si] ; blue value. shr al,2 out dx,al ; send it. add si,4 ; point next color. loop palloop ret endp  proc copybitmap mov ax, 0a000h mov es, ax mov cx,200 printbmploop: push cx mov di,cx shl cx,6 shl di,8 add di,cx mov ah,3fh mov cx,320 mov dx,offset scrline int 21h cld  mov cx,320 mov si,offset scrline rep movsb  pop cx loop printbmploop ret endp  proc time push ax push cx push dx mov cx, 0001h mov dx, 9999h mov ah, 86h int 15h  pop dx pop cx pop ax ret endp ; -------------------------- start: mov ax, @data mov ds, ax ; -------------------------- ; code: mov ax, 13h int 10h again: mov ah, 01h     int 16h     jnz skip call openfile1 call readheader call readpalette call copypal call copybitmap call time call openfile2 call readheader call readpalette call copypal call copybitmap call time inc counter jmp again skip: mov ax, 03h int 10h ; -------------------------- exit: mov ax, 4c00h int 21h end start 

(turning comment answer, q "answered" properly)

just guess. see "open" in code, no "close", if repeatedly opening new , new files, new , new file handles, until cause shortage of file handles inside dos, , next open fails.

you can either open 2 files once, , keep handles stored (and reset file pointer 0 offset before next image re-read), or can try close file after each read verify cause of problem (writing close shorter fixing code open files once).

you should still close open files before exit way, if change whole code keep 2 files open time, , re-read them (although modern dos , dosbox recover if exit through 4ch service, , clean after you, iirc).

as use int 21h, 3d open files, should use int 21h, 3e close them.

so first quick fix create "closefile" procedure , call after 1 image loaded.

more advanced fix involve opening both files @ start, storing both handles, , re-reading them every time resetting file pointer 0 int 21h, 42, without opening them again. closing them once ahead of exit.

and more advanced fix allocate more memory (if free memory available), load both images first free memory, close files, , animate decoded images in memory, without file reading (just suggestion if bored , wanted try push original code in new direction. looks "welcome" message, it's sort of ok reread files every time, insanely noisy , slow on original pc, if run floppy disc. if testing under dosbox, maybe can try mount <your dir executable> -t floppy, think may emulate floppy speed, i'm not sure, never used dosbox way ... still without actual *agonizing sounds* drive it's difficult explain you, how bad re-read files every time in dos :) ;) ).


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? -