; ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
; ³ (c) Lord Julus - 2000                Vxtasy #1 - Magazine source code ³
; ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

locate_menubar_name proc near
        push bp                              ;
        mov bp, sp                           ;
        push ax bx cx di                     ;
        mov bx, word ptr ss:[bp+04h]         ; ax = the bar
                                             ;
        lea si, menu_items                   ; si point's to the popups
                                             ;
repeat_locate_menu_name:                     ;
        lodsb                                ; take the first byte (bar nr)
        cmp al, bl                           ; is it the one we are searching
        je found_menu_name                   ;
        mov di, si                           ;
        mov al, 0                            ; otherwise,
        mov cx, 0FFh                         ;
        repnz scasb                          ; scan for the next 2 zeroes
        mov si, di                           ;
        cmp si, offset menu_end - 1          ; if we gone over the end...
        jae not_found_menu_name              ;
        jmp repeat_locate_menu_name          ;
                                             ;
found_menu_name:                             ;
        add si, 2                            ; si points to the menu bar name
        clc                                  ;
        jmp exit_locate_menu_name            ;
                                             ;
not_found_menu_name:                         ;
        stc                                  ;
        jmp exit_locate_menu_name            ;
                                             ;
exit_locate_menu_name:                       ;
        pop di cx bx ax                      ;
        pop bp                               ;
        ret 2                                ;
locate_menubar_name endp                     ;


;==========( Procedure to locate the address of a bar's popup )==============

locate_popup proc near
        push bp                              ;
        mov bp, sp                           ;
        push ax bx cx di                     ;
        mov bx, word ptr ss:[bp+04h]         ; ax = the bar
                                             ;
        lea si, pop_up_items                 ; si point's to the popups
                                             ;
repeat_locate_popup:                         ;
        lodsb                                ; take the first byte (bar nr)
        cmp al, bl                           ; is it the one we are searching
        je found_popup                       ;
        mov di, si                           ;
        mov al, 0                            ; otherwise,
        mov cx, 0FFh                         ;
        repnz scasb                          ; scan for the next 2 zeroes
        repnz scasb                          ;
        mov si, di                           ;
        cmp si, offset pop_end  - 1          ; if we gone over the end...
        jae not_found_popup                  ;
        jmp repeat_locate_popup              ;
                                             ;
found_popup:                                 ;
        dec si                               ; si points to the popup
        clc                                  ;
        jmp exit_locate_popup                ;
                                             ;
not_found_popup:                             ;
        stc                                  ;
        jmp exit_locate_popup                ;
                                             ;
exit_locate_popup:                           ;
        pop di cx bx ax                      ;
        pop bp                               ;
        ret 2                                ;
locate_popup endp                            ;

;==========( Procedure to locate a popup item )==============================

locate_popup_item proc near
        push bp
        mov bp, sp
        push ax bx cx dx di
        mov bx, word ptr ss:[bp+04h]         ; popup number
        mov dx, word ptr ss:[bp+06h]         ; bar number
                                             ;
        push dx                              ;
        call locate_popup                    ;
        jc not_found_popup_item              ;
                                             ;
repeat_locate_popup_item:                    ;
        lodsb                                ;
        cmp al, dl                           ; still same popup ?
        jne not_found_popup_item             ;
        lodsb                                ;
        cmp al, bl                           ; found item ?
        je found_popup_item                  ;
        mov di, si                           ;
        mov al, 0                            ; otherwise,
        mov cx, 0FFh                         ;
        repnz scasb                          ; scan for the next 2 zeroes
        repnz scasb                          ;
        mov si, di                           ;
;       cmp si, offset pop_end  - 1          ; if we gone over the end...
;       jae not_found_popup                  ;
                                             ;
        jmp repeat_locate_popup_item         ;
                                             ;
not_found_popup_item:                        ;
        stc                                  ;
        jmp exit_locate_popup_item           ;
                                             ;
found_popup_item:                            ;
        dec si                               ;
        dec si                               ;
        clc                                  ;
        jmp exit_locate_popup_item           ;
                                             ;
                                             ;
exit_locate_popup_item:                      ;
        pop di dx cx bx ax                   ;
        pop bp                               ;
        ret 4                                ;
locate_popup_item endp                       ;

;==========( Procedure to locate the name of a popup item )==================

locate_popup_item_name proc near             ;
        push bp                              ;
        mov bp, sp                           ;
        push ax bx cx dx di                  ;
        mov bx, word ptr ss:[bp+04h]         ; popup number
        mov dx, word ptr ss:[bp+06h]         ; bar number
                                             ;
        push dx                              ;
        push bx                              ;
        call locate_popup_item               ;
        jc not_found_popup_item_name         ;
                                             ;
        lodsb                                ;
        cmp al, dl                           ;
        jne error_while_searching_popup_name ;
        lodsb                                ;
        cmp al, bl                           ;
        jne error_while_searching_popup_name ;
        lodsb                                ;
        clc                                  ;
        jmp exit_locate_popup_item_name      ;
                                             ;
not_found_popup_item_name:                   ;
error_while_searching_popup_name:            ;
        stc                                  ;
        jmp exit_locate_popup_item_name      ;
                                             ;
exit_locate_popup_item_name:                 ;
        pop di dx cx bx ax                   ;
        pop bp                               ;
        ret 4
locate_popup_item_name endp

;==========( Procedure to locate the description of a popup item )===========

locate_popup_item_desc proc near             ;
        push bp                              ;
        mov bp, sp                           ;
        push ax bx cx dx di                  ;
        mov bx, word ptr ss:[bp+04h]         ; popup number
        mov dx, word ptr ss:[bp+06h]         ; bar number
                                             ;
        push dx                              ;
        push bx                              ;
        call locate_popup_item               ;
        jc not_found_popup_item_desc         ;
                                             ;
        lodsb                                ;
        cmp al, dl                           ;
        jne error_while_searching_popup_desc ;
        lodsb                                ;
        cmp al, bl                           ;
        jne error_while_searching_popup_desc ;
        lodsb                                ;
        mov di, si                           ;
        mov cx, 0FFh                         ;
        mov al, 0                            ;
        repnz scasb                          ;
        mov si, di                           ;
        clc                                  ;
        jmp exit_locate_popup_item_desc      ;
                                             ;
not_found_popup_item_desc:                   ;
error_while_searching_popup_desc:            ;
        stc                                  ;
        jmp exit_locate_popup_item_desc      ;
                                             ;
exit_locate_popup_item_desc:                 ;
        pop di dx cx bx ax                   ;
        pop bp                               ;
        ret 4                                ;
locate_popup_item_desc endp                  ;

;==========( Procedure to create a popup buffer )============================

create_popup proc near                       ;
        push bp                              ;
        mov bp, sp                           ;
        push ax bx cx dx                     ;
                                             ;
                                             ;
        mov dx, 1                            ;
        lea di, pop_buffer                   ;
                                             ;
repeat_create_popup:                         ;
        push bx                              ;
        push dx                              ;
        call locate_popup_item_name          ;
        jc no_more_items                     ;
        mov al, byte ptr [si-1]              ;
        mov overallno, al                    ;
        mov ax, 1225h                        ;
        int 2fh                              ;
        rep movsb                            ;
                                             ;
        pusha                                ;
        call check_toggleability             ;
        jc no_toggle                         ;
                                             ;
        mov ax, 1225h                        ;
        int 2fh                              ;
        sub di, cx                           ;
        rep movsb                            ;
                                             ;
no_toggle:                                   ;
        popa                                 ;
        inc dx                               ;
        jmp repeat_create_popup              ;
                                             ;
no_more_items:                               ;
        mov ax, 0                            ;
        stosb                                ;
        pop dx cx bx ax                      ;
        pop bp                               ;
        dec di                               ;
        mov popup_buffer_end, di             ;
        lea di, pop_buffer                   ;
        call create_hot_letters              ;
        ret 2                                ;
create_popup endp                            ;
                                             ;
                                             ;
check_toggleability proc near                ;
        push ax bx cx dx di                  ;
;        xor ax, ax                          ;
;        mov al, overallno                   ;
;        push ax                             ;
;        call locate_toggle                  ;
;        jc no_toggle_found                  ;
;        cmp byte ptr [si], '-'              ;
;        je no_toggle_found                  ;
;                                            ;
;        pop di dx cx bx ax                  ;
;        clc                                 ;
;        ret                                 ;
                                             ;
no_toggle_found:                             ;
        pop di dx cx bx ax                   ;
        stc                                  ;
        ret                                  ;
check_toggleability endp                     ;
                                             ;
;locate_toggle proc near                     ;
;        push bp                             ;
;        mov bp, sp                          ;
;        mov bx, word ptr ss:[bp+04h]        ;
;                                            ;
;        lea si, popup_toggle                ;
;                                            ;
;scan_toggle_again:                          ;
;        xor ax, ax                          ;
;        lodsb                               ;
;        cmp al, 0ffh                        ;
;        je toggle_not_found                 ;
;        cmp ax, bx                          ;
;        je found_toggle_place               ;
;        lodsb                               ;
;        xor ax, ax                          ;
;        mov cx, 0feh                        ;
;        mov di, si                          ;
;        repnz scasb                         ;
;        repnz scasb                         ;
;        mov si, di                          ;
;        jmp scan_toggle_again               ;
;                                            ;
;found_toggle_place:                         ;
;        lodsb                               ;
;        cmp al, 0                           ;
;        je ok_first_toggle                  ;
;        inc si                              ;
;        mov di, si                          ;
;        xor ax, ax                          ;
;        mov cx, 0feh                        ;
;        repnz scasb                         ;
;        mov si, di                          ;
;        jmp jump_out                        ;
;                                            ;
;ok_first_toggle:                            ;
;;        inc si                             ;
;                                            ;
;jump_out:                                   ;
;        clc                                 ;
;        jmp exit_scan_toggle                ;
;                                            ;
;toggle_not_found:                           ;
;        stc                                 ;
;                                            ;
;exit_scan_toggle:                           ;
;        pop bp                              ;
;        ret 2                               ;
;locate_toggle endp                          ;
                                             ;
;toggle_current_popup proc near              ;
;        pusha                               ;
;                                            ;
;        xor bx, bx                          ;
;        mov bl, overallno                   ;
;        lea si, popup_toggle                ;
;                                            ;
;_scan_toggle_again:                         ;
;        xor ax, ax                          ;
;        lodsb                               ;
;        cmp al, 0ffh                        ;
;        je _toggle_not_found                ;
;        cmp ax, bx                          ;
;        je _found_toggle_place              ;
;        lodsb                               ;
;        xor ax, ax                          ;
;        mov cx, 0feh                        ;
;        mov di, si                          ;
 ;       repnz scasb                         ;
 ;       repnz scasb                         ;
  ;      mov si, di                          ;
  ;      jmp _scan_toggle_again              ;
  ;                                          ;
;_found_toggle_place:                        ;
;        mov di, si                          ;
;        lodsb                               ;
;        mov ah, 1                           ;
;        sub ah, al                          ;
;        mov al, ah                          ;
;        stosb                               ;
;        jmp _jump_out                       ;
;                                            ;
;_jump_out:                                  ;
;        clc                                 ;
;        jmp _exit_scan_toggle               ;
;                                            ;
;_toggle_not_found:                          ;
;        stc                                 ;
;                                            ;
;_exit_scan_toggle:                          ;
;        popa                                ;
;        ret                                 ;
;toggle_current_popup endp                   ;
                                             ;
create_hot_letters proc near                 ;
        pusha                                ;
        lea si, hot_letters                  ;
        mov cx, 0FFFEh                       ;
        mov bx, 1                            ;
                                             ;
repeat_scan_hot_letters:                     ;
        mov al, '~'                          ;
        repnz scasb                          ;
        mov al, byte ptr [di]                ;
        mov byte ptr [si], al                ;
        mov al, 0                            ;
        repnz scasb                          ;
        cmp di, popup_buffer_end             ;
        jae done_hot_letters                 ;
        inc bx                               ;
        inc si                               ;
        jmp repeat_scan_hot_letters          ;
                                             ;
done_hot_letters:                            ;
        mov al, 0ffh                         ;
        mov byte ptr [si+1], al              ;
        mov hot_letters_number, bx           ;
        lea si, hot_letters                  ;
        mov di, si                           ;
        mov ax, 1211h                        ;   ; uppercase string
        int 2fh                              ;
        popa                                 ;
        ret                                  ;
create_hot_letters endp                      ;

;=========( Procedure to calculate some data for mouse )=====================

calculate_menus proc near                    ;
        pusha                                ;
        push ds es                           ;
        lea si, menu_items                   ;
        lea di, menu_bar_xcoord              ;
        xor bx, bx                           ;
        mov cx, max_menu_item                ;
                                             ;
repeat_calculate_xcoords:                    ;
        push cx                              ;
        add bx, menu_items_space             ;
        mov ax, bx                           ;
        stosw                                ;
        lodsb                                ;
        lodsb                                ;
        mov ax, 1225h                        ;
        int 2fh                              ;
        add bx, cx                           ;
        mov ax, bx                           ;
        stosw                                ;
        add si, cx                           ;
        pop cx                               ;
        loop repeat_calculate_xcoords        ;
                                             ;
        pop es ds                            ;
        popa                                 ;
        ret                                  ;
calculate_menus endp                         ;
                                             ;
                                             ;
                                             ;
;============================================================================
;============================================================================