Loosing a counter after calling a PROC

Started by omdown, June 02, 2005, 06:20:16 AM

Previous topic - Next topic

omdown

Okay, this program has a bit sloppy code I know, and for that I apologize.  All I really need help with is one little area which I've surrounded with three rows of stars.  I have a small red window, which the user can input text into, and there's a counter that keeps track of how many letters have been typed and when it reaches 63 it wraps to the next line.  This works fine unless the user presses Ctrl-F or Ctrl-E, both of which call functions that drop down pull down lists, then return after the user presses enter (this will be changed once I figure out whats wrong with my first problem).  Anyone, once it returns from the function, the counter stops working.  Can someone help me figure out why?

Here's the code, with the part I need help on with three rows of stars surrounding it (I wanted to make it red but that wouldnt work) :

TITLE project {project.asm)

include Irvine16.inc

ENTER_KEY = 0Dh
ESC_KEY = 1Bh
CTRL_F = 06h
CTRL_E = 05h
CTRL_H = 08h


.data
file BYTE "File",0
edit BYTE "Edit",0
help BYTE "Help",0
top_border BYTE "+--------+",0
side_border BYTE "¦        ¦",0
bottom_border BYTE "+--------+",0
file_open BYTE "Open",0
file_save BYTE "Save",0
file_saveas BYTE "Save As",0
edit_cut BYTE "Cut",0
edit_copy BYTE "Copy",0
edit_paste BYTE "Paste",0
lc_file WORD 0201h
lc_edit WORD 0209h
number_of_chars WORD 0
counter WORD 0
cursor WORD 0
position word 0



.code
main PROC
mov ax,@data
mov ds,ax

; create the window
mov ax,0600h ;scroll a window
mov bh,00001110b ;black bg, yellow txt
mov cx,0000h ;upper left hand corner
mov dx,001Fh ;lower right hand corner
int 10h ; i assume this means do it

; reposition the cursor
mov ah,2 ;set cursor position function
mov dx,0001h ; row 0 col 1
mov bh,0 ; video page 0
int 10h ; i assume this means do it again

; write the word file to the bar
mov dx, OFFSET file
call writestring

; move to the position of the next menu item
mov ah,2 ; set cursor funciton
mov dx,0009h ; row 0 col 9
mov bh,0 ; video page 0
int 10h ; make it so...

; write the edit option
mov dx, OFFSET edit
call writestring


; move to the position of the next menu item
mov ah,2
mov dx,0012h ; row 0 col 18
mov bh,0 ; video page 0
int 10h ; make it so...

; write the help option
mov dx, OFFSET help
call writestring

; okay, we now have the freakin bar.
; set the editable area to be white on red.

; create the window
mov ax,0600h ; scroll a window
mov bh,11000000b ; red bg, white txt
mov cx,0101h ; row 1 col 1
mov dx,153Fh ; row 15 col 16
int 10h


;***        Get characters       ***


mov ah,2
mov bh,0
mov dh,1
mov dl,1
int 10h

;******************************************************
;******************************************************
;******************************************************
L5:
mov ah,1
int 21h
.IF (al == CTRL_F)
    call file_menu
.ELSEIF (al == CTRL_E)
   call edit_menu
.ENDIF


inc number_of_chars

.IF (number_of_chars == 63)
     call crlf

     mov ah,3
     mov bh,0
     int 10h

     inc dl

     call gotoxy

     mov number_of_chars, 0
.ENDIF

jmp L5
;******************************************************
;******************************************************
;******************************************************




exit

main ENDP







file_menu PROC
; ************************       <  FILE  >       ****************************

mov ah,3
mov bh,0
int 10h

push dx

dec dl

mov ah,2
mov bh,0
int 10h

mov ah,020h
call writechar




mov ax,0B800h
mov ds,ax
mov ax,0B900h
mov es,ax

xor si,si
xor di,di

mov cx, 4000d

rep movsb


mov ah,020h
call writechar


; ***THE FIRST THING WE MUST DO IS GO TO THE WORD "FILE" AND COLOR IT TO SIGNIFY SELECTION***

mov ax,@data
mov ds,ax
mov es,ax



; move to the file location
mov ah,2 ; go to...
mov dx,0001h ; row 0 col 1
mov bh,0 ; video page 1
mov bl,0
int 10h ; make it so...


; now that we're in the right place, color the word File
mov ax,0600h ; draw a window
mov bh,11100000b ; invert the colors
mov cx, 0001h ; left hand side
mov dx, 0004h ; right hand side
int 10h ; make it so...






; move to the word file location
mov ah,2
mov dx,0001h
mov bh,0
int 10h

; write the word file in the right place
mov dx, OFFSET file
call writestring



; ***THE WORD "FILE" IS NOW HIGHLIGHTED.  NOW WE MUST CREATE A GRAY WINDOW WITH BLACK TEXT***

; make the window for submenu thing
mov ax,0600h ; scroll a window
mov bh,01110000b ; light gray bg, black text
mov cx,0101h ; row 1 col 1
mov dx,070Ah ; row 7 col 10 (add9)
int 10h

; ***GIVE THE "FILE" WINDOW IT'S BORDER***

; get ready to draw the border
mov ah,2 ; set cursor position
mov dx,0101h ; row 1, col 1
mov bh,0 ; video page 1
int 10h ; do it

; draw it
mov dx, OFFSET top_border
call writestring

; create a loop that will extend the window downward.

push cx
mov cx,5

L1:
     mov ah,2
     mov dx,lc_file
     mov bh,0
     int 10h

     push dx

     mov dx, OFFSET side_border
     call writestring

     pop dx

     add dx,0100h
     mov lc_file,dx

     loop L1

pop cx


; go to the next spot
mov ah,2
mov dx,0701h
mov bh,0
int 10h

; draw it
mov dx, OFFSET bottom_border
call writestring

int 10h

; ***THE ENTIRE BORDER FOR THE "FILE" WINDOW HAS NOW BEEN DRAWN***
; ***NOW WE NEED TO START WRITING THE OPTIONS YOU HAVE IN THE BOX***

; move back and start writing in the options
mov ah,2 ; cursor positioning function
mov dx,0202h ; row 2 col 2
mov bh,0 ; video page 1
int 10h ; do it

; write the stuff
mov edx, OFFSET file_open
call writestring

; move again to the next part
mov ah,2 ; cursor positioning
mov dx,0302h ; row 2 col 2
mov bh,0 ; video page 1
int 10h ; do it

; write it
mov edx, OFFSET file_save
call writestring

; mov again
mov ah,2 ; cursor positioning
mov dx,0402h ; row 3 col 2
mov bh,0 ; video page 1
int 10h ; do it

; write it
mov edx, OFFSET file_saveas
call writestring

L6:
mov ah,1
int 21h
.IF (al == 0Dh)
jmp quit
.ENDIF
jne L6


quit:

mov ax,0B900h
mov ds,ax
mov ax,0B800h
mov es,ax

xor si,si
xor di,di

mov cx, 4000d

rep movsb

pop dx

mov ah,2
mov bh,0
int 10h
ret



file_menu ENDP





;****************************************************************
edit_menu PROC
;****************************************************************

                  ; *******************        <  EDIT  >       **********************
mov ah,3
mov bh,0
int 10h

push dx

dec dl

mov ah,2
mov bh,0
int 10h

mov ah,0FFh
call writechar




mov ax,0B800h
mov ds,ax
mov ax,0B900h
mov es,ax

xor si,si
xor di,di

mov cx, 4000d

rep movsb


mov ah,0FFh
call writechar





; ***THE FIRST THING WE MUST DO IS GO TO THE WORD "FILE" AND COLOR IT TO SIGNIFY SELECTION***

mov ax,@data
mov ds,ax
mov es,ax



; ***THE FIRST THING WE MUST DO IS GO TO THE WORD "OPTIONS" AND COLOR IT TO SIGNIFY SELECTION***

; move to the "EDIT" location
mov ah,2 ; go to...
mov dx,0009h ; row 0 col 9
mov bh,0 ; video page 1
int 10h ; make it so...

; now that we're in the right place, color the word "EDIT"
mov ax,0600h ; draw a window
mov bh,11100000b ; invert the colors
mov cx, 0009h ; left hand side
mov dx, 000Dh ; right hand side
int 10h ; make it so...

; write the word "EDIT" in the right place
mov dx, OFFSET edit
call writestring


; ***THE WORD "EDIT" IS NOW HIGHLIGHTED.  NOW WE MUST CREATE A GRAY WINDOW WITH BLACK TEXT***

; make the window for submenu thing
mov ax,0600h ; scroll a window
mov bh,01110000b ; light gray bg, black text
mov cx,0109h ; row 1 col 9
mov dx,0712h ; row 7 col 16
int 10h


; ***GIVE THE "EDIT" WINDOW IT'S BORDER***

; get ready to draw the border
mov ah,2 ; set cursor position
mov dx,0109h ; row 1, col 9
mov bh,0 ; video page 1
int 10h ; do it

; draw it
mov dx, OFFSET top_border
call writestring

; create a loop that will extend the window downward.

push cx
mov cx,5

L2:
     mov ah,2
     mov dx,lc_edit
     mov bh,0
     int 10h

     push dx

     mov dx, OFFSET side_border
     call writestring

     pop dx

     add dx,100h
     mov lc_edit,dx

     loop L2

pop cx

; go to the next spot
mov ah,2
mov dx,0709h
mov bh,0
int 10h

; draw it
mov dx, OFFSET bottom_border
call writestring

; ***THE ENTIRE BORDER FOR THE "EDIT" WINDOW HAS NOW BEEN DRAWN***
; ***NOW WE NEED TO START WRITING THE OPTIONS YOU HAVE IN THE BOX***

; move back and start writing in the options
mov ah,2 ; cursor positioning function
mov dx,020Ah ; row 1 col 10
mov bh,0 ; video page 1
int 10h ; do it

; write the stuff
mov edx, OFFSET edit_cut
call writestring

; move again to the next part
mov ah,2 ; cursor positioning
mov dx,030Ah ; row 2 col 10
mov bh,0 ; video page 1
int 10h ; do it

; write it
mov edx, OFFSET edit_copy
call writestring

; mov again
mov ah,2 ; cursor positioning
mov dx,040Ah ; row 3 col 10
mov bh,0 ; video page 1
int 10h ; do it

; write it
mov edx, OFFSET edit_paste
call writestring

L11:
mov ah,1
int 21h
.IF (al == 0Dh)
jmp quit
.ENDIF
jne L11


quit:

mov ax,0B900h
mov ds,ax
mov ax,0B800h
mov es,ax

xor si,si
xor di,di

mov cx, 4000d

rep movsb

pop dx

mov ah,2
mov bh,0
int 10h
ret


edit_menu ENDP




END main


By the way, the reason I try to back up one space and write a space is because when someone pushes Ctrl-F it leaves a clubs sign on the screen.  I'm eventually going to change that to just check to see if the ctrl key is being held.

MichaelW

I think DS is being changed in the calls.
eschew obfuscation