TITLE "VIDO - Vlib 4.1" NAME ('VIDO') ;================================================================= ; Copyright (C) 1989 by Harold F. Bower. Permission granted to ; Alpha Systems Corp. to distribute with The Libraries, Version 4 ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Date : 4 Mar 89 ; Version : 1.0 ; Module : VIDO ; Abstract: This module contains the routine SETPDM which initial- ; izes a Pull-Down Menu item, and PDMINI which initializes ; the entire Pull-Down Menu system. It also contains the ; globak variables used by the Menuing system. ; Revision: ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC SETPDM, SETPDR, PDMINI PUBLIC @PDMCH, @PDMBF, @MBUFF ; ..from Z3LIB Get.. EXT GETCRT ; Constants ESC EQU 1BH ; Default Menu Escape character LINLEN EQU 132 ; Maximum allowable line length .Z80 CSEG ;=============================================================== ; PDMINI - Initialize the Pull-Down Menu variable system ; Entry: - None. ; Exit : - None. The variables are initialized ; Uses : - None. ; Special Requirements: None ;=============================================================== PDMINI: PUSH HL ; Save regs PUSH BC PUSH AF LD HL,@PDMCH ; Set default PDM Escape char LD (HL),ESC INC HL ; Point to Menu line string (@PDMBF) PUSH HL ; ..save for a while CALL GETCRT ; Address the current CRT LD A,(HL) ; Load # of chars/line POP HL CP LINLEN+1 ; Is it longer than our space? JR C,PDMIN0 ; ..jump if not LD A,LINLEN ; Else set to our maximum length PDMIN0: LD (HL),A ; Set the maximum length INC HL ; Advance to current EOL LD B,WBLEN ; Clear line + Count + EOL + Ptr Array PDML: LD (HL),0 ; Null a char INC HL ; ..and advance to next DJNZ PDML ; ...loop til done POP AF ; Restore regs POP BC POP HL RET ;=============================================================== ; SETPDM - Initialize Pull Down Menu ; Entry: - None. Stack points to data area ; Exit : A = 0 and Zero Flag Set (Z) if Error ; A = FFH and Zero flag Reset (NZ) if Operation OK ; Uses : AF ; Special Requirements: None ;=============================================================== SETPDM: EX (SP),HL ; Get ptr to data CALL SETPDR ; ..and set from HL EX (SP),HL ; Swap Ret addr w/HL value RET ;=============================================================== ; SETPDR - Initialize Pull Down Menu from Register HL ; Entry: HL = Address of start of PDM definition structure ; Exit : HL = Address of byte after terminating Null in PDM def ; A = 0FFH, Zero flag Reset (NZ) if Menu Loaded OK ; A = 0 and Zero Flag Set (Z) if Error ; Uses : AF,HL ; Special Requirements: None ;=============================================================== SETPDR: PUSH DE ; Save regs PUSH BC EX DE,HL LD HL,@MBUFF ; Point to Menu buffer LD A,(DE) ; Get Menu number LD (MENUNM),A ; ..and save INC DE ; Else bypass Number to Menu Line start PUSH DE ; Save ptr while we search LD D,1 ; Set initial pointer CALL FIND1 ; ..and find an empty slot POP DE ; Restore input line ptr JR NC,BAD ; ..and quit here if bad PUSH DE ; Save Input pointer EX DE,HL ; Put index ptr in DE LD HL,@PDMBF ; Calculate header address LD C,(HL) ; Get current index LD B,0 ; ..for 16-bit math INC HL ADD HL,BC ; ..and point to next available position EX DE,HL ; Ptr to array in HL, Menu line start in DE LD (HL),E ; Store Menu address in Array INC HL LD (HL),D EX (SP),HL ; Swap Array ptr with Input ptr LOOP: LD A,(HL) ; Get first char of menu INC HL ; ..bump ptr INC C ; ...advance end pointer CP 1 ; End of Menu char? JR Z,SETPD1 ; ..exit if so LD (DE),A ; Else store char INC DE ; ..bump INC B ; Bump accumulated bytes LD A,(@PDLEN) ; Get maximum line length DEC A ; ..back down one for check CP C ; Are we at end? JR NC,LOOP ; Else continue EX (SP),HL ; ERROR, swap block addr back LD D,(HL) ; ..and get Menu Line ptr back LD (HL),0 ; ...nulling storage locns DEC HL LD E,(HL) LD (HL),0 EX DE,HL ; Put Line addr in HL XOR A NLOOP: LD (HL),A ; ..and fill with Nulls INC HL DJNZ NLOOP POP DE ; Retrieve Menu definition pointer BAD: XOR A ; Set Error Status JR VBAD ; ..then take error exit SETPD1: EX (SP),HL ; Swap ptrs to array INC HL LD (HL),B ; Save Menu item length INC HL LD A,(MENUNM) ; Store Menu Number LD (HL),A INC HL EX (SP),HL ; ..swap ptrs back again LD B,4 ; Send four spaces to separate SETPDX: LD A,' ' LD (DE),A INC DE INC C LD A,(@PDLEN) ; Get maximum line length DEC A ; ..compensating CP C ; At the End? JR C,SETPD2 ; ..quit here if end DJNZ SETPDX ; Loop if not finished SETPD2: LD A,C ; Retrieve current end pointer DEC A ; .back up to end LD (@PDMBF),A ; ..and store EX DE,HL ; Submenu string addr to DE POP HL ; Restore pointer to array LD (HL),E ; ..and save index INC HL LD (HL),D OR 0FFH ; ..and set Ok Flag VBAD: PUSH AF ; Save status EX DE,HL XOR A LOOP2: CP (HL) ; Scan for end of data string INC HL JR NZ,LOOP2 POP AF POP BC POP DE RET ;..... ; Locate an unused PDM ID Block ; Return Addr in HL, Menu # in A, Carry Clear if None available FIND1: LD A,(HL) ; Is this one vacant? INC HL OR (HL) DEC HL ; Keep address constant JR Z,FIND10 ; ..return if available LD BC,6 ; In use, advance to next ADD HL,BC INC D ; Bump to next count CALL FIND10 ; Check status JR C,FIND1 ; ..loop if Ok, else fall thru & return FIND10: LD A,D ; Check for legal Block # CP 10+1 RET ; ..return with status set ;..... ; Data used by Pull-Down Menu routines DSEG MENUNM: DEFS 1 ; Temp storage for Menu # @PDMCH: DEFS 1 ; Pull-Down Escape Char @PDLEN: DEFS 1 ; Maximum Length of PDM line @PDMBF: DEFS LINLEN+1 ; PDM Buffer (132), EOL (1) @MBUFF: DEFS 10*6 ; Pointers to 10 Menu Items as: ; ..Menu header addr - 2 ; ..Menu header len - 1 ; ..Menu Number - 1 ; ..Menu String addr - 2 WBLEN EQU $-@PDMBF END