'* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' '* ____________________ *' '* *' '* File name: ________.BAS *' '* Type: Quick Basic Source Code *' '* Version: 1.00 *' '* Created in: 1995-1997 *' '* Created by: Zsolt Nagy Perge *' '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' DEFINT A-Z DECLARE SUB SCREEN.SAVE (SCREENBUFFER()) DECLARE SUB SCREEN.RESTORE (SCREENBUFFER()) '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' '* Keyboard Function Declarations *' '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' DECLARE SUB GetKey (Key$) DECLARE SUB GetText (Text$, MaxLength, Filter$) DECLARE SUB SetKeyboardSpeed (Delay, Rate) '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' '* Assembly Routine Caller Function Declaration *' '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' DECLARE SUB ASSEMBLY (Code$) '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' '* Text Window Application Function Declarations *' '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' DECLARE SUB PutText (ScreenSide, Col1, Col2, Row, Text$) DECLARE SUB PutLine (Way, Col, Row, CR2, LineSet$) DECLARE SUB PutSqare (Col1, Row1, Col2, Row2, LineSet$) DECLARE SUB PutWindow (Col1, Row1, Col2, Row2, ForeColor, BackColor, LineSet$) DECLARE SUB PutButton (State, Button$, Col, Row, ForeColor, BackColor) DECLARE SUB PutDesktop (Col1, Row1, Col2, Row2, Sample$, ForeColor, BackColor) DECLARE SUB PutMessage (Col, Row, Message$(), Rows, ForeColor, BackColor, LineSet$) DECLARE SUB PutCommentLine (CommentText$, ForeColor, BackColor) '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' '* Mouse Function Declarations *' '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' DECLARE SUB MShow () DECLARE SUB MHide () DECLARE SUB MGetEvent (MCol, MRow, MButton) DECLARE SUB MSetRange (MCol1, MRow1, MCol2, MRow2) DECLARE SUB MSetPosition (MCol, MRow) DECLARE SUB MResetDriver () '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' '* Block Input/Output Function Declarations *' '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' DECLARE SUB PutBlock (Col1, Row1, Col2, Row2, Buffer()) DECLARE SUB GetBlock (Col1, Row1, Col2, Row2, Buffer()) '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' '* Staring Sorting Function Declarations *' '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' DECLARE SUB Sort (Block$(), BlockLength, CaseSensitivity) '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' '* Menu Application Function Declarations *' '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' DECLARE SUB PutMenu (Col, Row, ActiveMenu, Menus, Menu$(), ForeColor, BackColor, MenuColor, SelectedColor, LineSet$) DECLARE SUB PutButtonMenu (Shape, Col, Row, ActiveButton, Buttons, Button$(), ForeColor, BackColor, ActiveForeColor, ActiveBackColor) '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' CONST Left = 1 CONST Right = 2 CONST Center = 3 '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' CONST Pushed = 1 CONST Released = 2 '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' CONST Vertical = 1 CONST Horizontal = 2 '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' COMMON SHARED ErrorCode COMMON SHARED MouseStatus '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' DIM SHARED C(10) C(1) = 15 ' FC: Main window C(2) = 1 ' BC: Main window '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' '* Main Program *' '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' Main: ON ERROR GOTO ErrorHandler ON TIMER(1) GOSUB TimerHandler CLS PutDesktop 1, 1, 80, 24, "°", 12, 5 PutCommentLine " SAMPLE SAMPLE SAMPLE ...", 15, 1 DIM Msg$(10) Msg$(0) = " Main Menu " Msg$(1) = "Draw F4" Msg$(2) = "Erase F3" Msg$(3) = "Copy F5" Msg$(4) = "Save F2" Msg$(4) = "Help F1" Msg$(5) = "Exit... Alt+F4" ActiveMenu = 4 PutMenu 27, 8, ActiveMenu, 5, Msg$(), 11, 3, 14, 5, "ɻȼͺ*" Msg$(0) = "-- Message Window " Msg$(1) = "--" Msg$(2) = "o 512 THEN MaxLength = 512 IF LEN(Text$) > MaxLength THEN Text$ = MID$(Text$, 1, MaxLength) CursorCounter = LEN(Text$) Col = POS(0) + CursorCounter MOD 80 Row = CSRLIN + CursorCounter / 80 PRINT Text$; LOCATE , , 1, 12, 13 DO LOCATE 10, 10: PRINT CursorCounter LOCATE Row, Col: PRINT ; GetKey Key$ SELECT CASE Key$ CASE CHR$(27): ' [Esc] MaxLength = -1 LOCATE , , 0 EXIT SUB CASE CHR$(13): ' [Enter] MaxLength = LEN(Text$) LOCATE , , 0 EXIT SUB CASE CHR$(0) + "G": ' [Home] DO WHILE CursorCounter > 0 GOSUB CursorBackWard LOOP CASE CHR$(0) + "O": ' [End] TextLen = LEN(Text$) IF LEN(Text$) = MaxLength THEN TextLen = TextLen - 1 DO WHILE CursorCounter < TextLen GOSUB CursorForeWard LOOP CASE CHR$(0) + "R": ' [Insert] Insert = NOT Insert IF Insert = 0 THEN LOCATE , , , 12, 13 ELSE LOCATE , , , 1, 13 END IF CASE CHR$(0) + "S": ' [Delete] IF LEN(Text$) > 0 THEN LOCATE Row, Col FOR Counter = CursorCounter + 2 TO LEN(Text$) PRINT MID$(Text$, Counter, 1); NEXT Counter PRINT " "; Text$ = MID$(Text$, 1, CursorCounter) + MID$(Text$, CursorCounter + 2, LEN(Text$)) END IF CASE CHR$(8): ' [BackSpace] IF LEN(Text$) > 0 THEN GOSUB CursorBackWard LOCATE Row, Col FOR Counter = CursorCounter + 2 TO LEN(Text$) PRINT MID$(Text$, Counter, 1); NEXT Counter PRINT " "; Text$ = MID$(Text$, 1, CursorCounter) + MID$(Text$, CursorCounter + 2, LEN(Text$)) END IF CASE CHR$(0) + "M": ' [] GOSUB CursorForeWard CASE CHR$(0) + "K": ' [] GOSUB CursorBackWard CASE ELSE: IF Filter$ = "" THEN IF ASC(Key$) >= 32 AND ASC(Key$) <= 255 THEN GOSUB WriteCharacter ELSE FOR Counter = 1 TO LEN(Filter$) IF UCASE$(Key$) = UCASE$(MID$(Filter$, Counter, 1)) THEN GOSUB WriteCharacter NEXT Counter END IF END SELECT LOOP EXIT SUB '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' WriteCharacter: IF Insert = 0 THEN LOCATE Row, Col: PRINT Key$; Text$ = MID$(Text$, 1, CursorCounter) + Key$ + MID$(Text$, CursorCounter + 2, LEN(Text$)) GOSUB CursorForeWard ELSEIF LEN(Text$) < MaxLength THEN LOCATE Row, Col: PRINT Key$; FOR Counter = CursorCounter + 1 TO LEN(Text$) PRINT MID$(Text$, Counter, 1); NEXT Counter Text$ = MID$(Text$, 1, CursorCounter) + Key$ + MID$(Text$, CursorCounter + 1, LEN(Text$)) GOSUB CursorForeWard END IF RETURN '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' CursorForeWard: IF MaxLength > CursorCounter + 1 AND CursorCounter < LEN(Text$) THEN IF Col = 80 THEN Col = 1 IF Row < 24 THEN Row = Row + 1 ELSE PRINT ELSE Col = Col + 1 END IF CursorCounter = CursorCounter + 1 END IF RETURN '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' CursorBackWard: IF CursorCounter > 0 THEN IF Col = 1 THEN Col = 80 Row = Row - 1 ELSE Col = Col - 1 END IF CursorCounter = CursorCounter - 1 END IF RETURN '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' END SUB SUB MGetEvent (MCol, MRow, MButton) IF MouseStatus = &HFF THEN ASSEMBLY "¸" + CHR$(0) + "Í3ÑéÑéÑéÑêÑêÑê1ÀP&‰P&‰R&‰TË" DEF SEG = 0 MCol = PEEK(&H250) + 1 MRow = PEEK(&H252) + 1 MButton = PEEK(&H254) DEF SEG END IF END SUB SUB MHide IF MouseStatus = &HFF THEN ASSEMBLY "¸" + CHR$(0) + "Í3Ë" END SUB SUB MResetDriver ASSEMBLY "1ÀPÍ3&£PË" DEF SEG = 0 MouseStatus = PEEK(&H250) DEF SEG END SUB SUB MSetPosition (MCol, MRow) IF MouseStatus = &HFF THEN ASSEMBLY "¹" + MID$(MKI$(MCol * 8 - 1), 1, 1) + MID$(MKI$(MCol * 8 - 1), 2, 1) + "º" + MID$(MKI$(MRow * 8 - 1), 1, 1) + MID$(MKI$(MRow * 8 - 1), 2, 1) + "¸" + CHR$(0) + "Í3Ë" END SUB SUB MSetRange (MCol1, MRow1, MCol2, MRow2) IF MouseStatus = &HFF THEN ASSEMBLY "¹" + MID$(MKI$(MCol1 * 8 - 1), 1, 1) + MID$(MKI$(MCol1 * 8 - 1), 2, 1) + "º" + MID$(MKI$(MCol2 * 8 - 1), 1, 1) + MID$(MKI$(MCol2 * 8 - 1), 2, 1) + "¸" + CHR$(0) + "Í3Ë" ASSEMBLY "¹" + MID$(MKI$(MRow1 * 8 - 1), 1, 1) + MID$(MKI$(MRow1 * 8 - 1), 2, 1) + "º" + MID$(MKI$(MRow2 * 8 - 1), 1, 1) + MID$(MKI$(MRow2 * 8 - 1), 2, 1) + "¸" + CHR$(0) + "Í3Ë" END IF END SUB SUB MShow IF MouseStatus = &HFF THEN ASSEMBLY "¸" + CHR$(0) + "Í3Ë" END SUB SUB PutBlock (Col1, Row1, Col2, Row2, Buffer()) DEF SEG = &HB800 FOR VCounter = Row1 - 1 TO Row2 - 1 FOR HCounter = Col1 - 1 TO Col2 - 1 POKE HCounter * 2 + VCounter * 160, Buffer(Counter) Counter = Counter + 1 POKE HCounter * 2 + VCounter * 160 + 1, Buffer(Counter) Counter = Counter + 1 NEXT HCounter NEXT VCounter DEF SEG END SUB SUB PutButton (State, Button$, Col, Row, ForeColor, BackColor) ShadowColor = VAL(MID$(HEX$(SCREEN(Row + 1, Col + 1, 1)), 1, 1)) SELECT CASE State CASE Pushed: COLOR ForeColor, BackColor LOCATE Row, Col + 1: PRINT Button$; CASE Released: COLOR 8, ShadowColor LOCATE Row + 1, Col + 1: PRINT STRING$(LEN(Button$), "ß"); LOCATE Row, Col + LEN(Button$): PRINT "Ü"; COLOR ForeColor, BackColor LOCATE Row, Col: PRINT Button$; END SELECT END SUB SUB PutButtonMenu (Shape, Col, Row, ActiveButton, Buttons, Button$(), ForeColor, BackColor, ActiveForeColor, ActiveBackColor) DIM Buffer(4000) MaxLength = 6 FOR Counter = 1 TO Buttons IF MaxLength < LEN(Button$(Counter)) THEN MaxLength = LEN(Button$(Counter)) NEXT Counter Row1 = Row Col1 = Col IF Shape = Horizontal THEN Row2 = Row + 3 Col2 = Col + Buttons * MaxLength ELSE Row2 = Row + Buttons * 2 + 1 Col2 = Col + MaxLength END IF GetBlock Col1, Row1, Col2, Row2, Buffer() DO Length = 0 FOR Counter = 1 TO Buttons IF ActiveButton = Counter THEN FColor = ActiveForeColor BColor = ActiveBackColor ELSE FColor = ForeColor BColor = BackColor END IF IF Shape = Horizontal THEN PutButton Released, Button$(Counter), Col + Length, Row1, FColor, BColor ELSE PutButton Released, Button$(Counter) + SPACE$(MaxLength - LEN(Button$(Counter))), Col, Row + (Counter - 1) * 2, FColor, BColor END IF Length = Length + LEN(Button$(Counter)) + 2 NEXT Counter GetKey Key$ IF Key$ = CHR$(0) + "K" OR Key$ = CHR$(0) + "H" THEN IF ActiveButton > 1 THEN ActiveButton = ActiveButton - 1 ELSE ActiveButton = Buttons IF Key$ = CHR$(0) + "M" OR Key$ = CHR$(0) + "P" OR Key$ = CHR$(9) THEN IF ActiveButton < Buttons THEN ActiveButton = ActiveButton + 1 ELSE ActiveButton = 1 IF Key$ = CHR$(13) THEN EXIT DO LOOP PutBlock Col1, Row1, Col2, Row2, Buffer() END SUB SUB PutCommentLine (CommentText$, ForeColor, BackColor) COLOR ForeColor, BackColor LOCATE 25, 1: PRINT CommentText$ + SPACE$(80 - LEN(CommentText$)); END SUB SUB PutDesktop (Col1, Row1, Col2, Row2, Sample$, ForeColor, BackColor) COLOR ForeColor, BackColor SquareWidth = Col2 - Col1 + 1 FOR HC = Row1 TO Row2 LOCATE HC, Col1: PRINT STRING$(SquareWidth, Sample$); NEXT HC END SUB SUB PutLine (Way, Col, Row, CR2, LineSet$) SELECT CASE Way CASE Vertical: LOCATE Row, Col: PRINT MID$(LineSet$, 1, 1) FOR Counter = Row + 1 TO CR2 - 1 LOCATE Counter, Col: PRINT MID$(LineSet$, 2, 1) NEXT Counter LOCATE CR2, Col: PRINT MID$(LineSet$, 3, 1) CASE Horizontal: LOCATE Row, Col: PRINT MID$(LineSet$, 1, 1) FOR Counter = Col + 1 TO CR2 - 1 LOCATE Row, Counter: PRINT MID$(LineSet$, 2, 1) NEXT Counter LOCATE Row, CR2: PRINT MID$(LineSet$, 3, 1) END SELECT END SUB SUB PutMenu (Col, Row, ActiveMenu, Menus, Menu$(), ForeColor, BackColor, MenuColor, SelectedColor, LineSet$) DIM Buffer(4000) MaxLength = 20 FOR Counter = 0 TO Menus IF MaxLength < LEN(Menu$(Counter)) THEN MaxLength = LEN(Menu$(Counter)) NEXT Counter Col1 = Col Col2 = Col + MaxLength + 3 Row1 = Row Row2 = Row + Menus + 1 GetBlock Col1, Row1, Col2 + 2, Row2 + 1, Buffer() PutWindow Col1, Row1, Col2, Row2, ForeColor, BackColor, LineSet$ PutText Center, Col1, Col2, Row1, Menu$(0) DO FOR Counter = 1 TO Menus IF ActiveMenu = Counter THEN COLOR MenuColor, SelectedColor ELSE COLOR MenuColor, BackColor PutText Left, Col + 1, 0, Row + Counter, " " + Menu$(Counter) + SPACE$(MaxLength - LEN(Menu$(Counter)) + 1) NEXT Counter GetKey Key$ SELECT CASE Key$ CASE CHR$(0) + "H": ' Up IF ActiveMenu > 1 THEN ActiveMenu = ActiveMenu - 1 ELSE ActiveMenu = Menus CASE CHR$(0) + "P": ' Down IF ActiveMenu < Menus THEN ActiveMenu = ActiveMenu + 1 ELSE ActiveMenu = 1 CASE ELSE: IF Key$ = CHR$(13) THEN EXIT DO END SELECT LOOP PutBlock Col1, Row1, Col2 + 2, Row2 + 1, Buffer() END SUB SUB PutMessage (Col, Row, Message$(), Rows, ForeColor, BackColor, LineSet$) MaxColumn = 20 FOR Counter = 0 TO Rows IF MaxColumn < LEN(Message$(Counter)) THEN MaxColumn = LEN(Message$(Counter)) - 2 NEXT Counter Row1 = Row Row2 = Row + Rows Col1 = Col Col2 = Col + MaxColumn IF MID$(LineSet$, 1, 1) = " " THEN DIM Buffer(4000) GetBlock Col1, Row1, Col2 + 6, Row2 + 2, Buffer() END IF PutWindow Col1, Row1, Col2 + 3, Row2 + 1, ForeColor, BackColor, MID$(LineSet$, 2, 7) FOR Counter = 0 TO Rows Text$ = MID$(Message$(Counter), 3, LEN(Message$(Counter))) TextColor = ASC(UCASE$(MID$(Message$(Counter), 1, 1))) - 65 IF TextColor >= 0 AND TextColor < 32 THEN COLOR TextColor ELSE COLOR ForeColor IF MID$(Message$(Counter), 2, 1) = "|" THEN PutLine Horizontal, Col1, Counter + Row1, Col2 + 3, MID$(Message$(Counter), 3, 3) ELSE SELECT CASE MID$(Message$(Counter), 2, 1) CASE "<": 'Col = Col1 PutText Left, Col1 + 2, 0, Counter + Row1, Text$ CASE ">": 'Col = Col2 - LEN(Text$) + 1 PutText Right, 0, Col2 + 1, Counter + Row1, Text$ CASE ELSE: PutText 0, Col1, Col2 + 4, Counter + Row1, Text$ 'Col = 40 - LEN(Text$) / 2 END SELECT 'LOCATE Counter + Row1, Col + 2 'PRINT Text$; END IF NEXT Counter IF MID$(LineSet$, 1, 1) = " " THEN GetKey Key$ PutBlock Col1, Row1, Col2 + 6, Row2 + 2, Buffer() END IF END SUB SUB PutSqare (Col1, Row1, Col2, Row2, LineSet$) SqareWidth = Col2 - Col1 + 1 LOCATE Row1, Col1 PRINT MID$(LineSet$, 1, 1) + STRING$(SqareWidth - 2, MID$(LineSet$, 5, 1)) + MID$(LineSet$, 2, 1); FOR Counter = Row1 + 1 TO Row2 - 1 LOCATE Counter, Col1 PRINT MID$(LineSet$, 6, 1); IF LEN(LineSet$) > 6 THEN PRINT STRING$(SqareWidth - 2, MID$(LineSet$, 7, 1)); END IF LOCATE Counter, Col2: PRINT MID$(LineSet$, 6, 1); NEXT Counter LOCATE Row2, Col1 PRINT MID$(LineSet$, 3, 1) + STRING$(SqareWidth - 2, MID$(LineSet$, 5, 1)) + MID$(LineSet$, 4, 1); END SUB SUB PutText (ScreenSide, Col1, Col2, Row, Text$) SELECT CASE ScreenSide CASE Left: Col = Col1 + Col2 CASE Right: Col = Col2 - LEN(Text$) - Col1 + 1 CASE ELSE: Col = Col1 + (Col2 - Col1) / 2 - LEN(Text$) / 2 END SELECT LOCATE Row, Col PRINT Text$; END SUB SUB PutWindow (Col1, Row1, Col2, Row2, ForeColor, BackColor, LineSet$) IF LEN(LineSet$) > 6 AND NOT MID$(LineSet$, LEN(LineSet$), 1) = " " THEN COLOR 8, 0 FOR Counter = Col1 TO Col2 LOCATE Row2 + 1, Counter + 2: PRINT CHR$(SCREEN(Row2 + 1, Counter + 2)); NEXT Counter FOR Counter = Row1 TO Row2 LOCATE Counter + 1, Col2 + 1: PRINT CHR$(SCREEN(Counter + 1, Col2 + 1)); LOCATE Counter + 1, Col2 + 2: PRINT CHR$(SCREEN(Counter + 1, Col2 + 2)); NEXT Counter END IF COLOR ForeColor, BackColor PutSqare Col1, Row1, Col2, Row2, MID$(LineSet$, 1, 6) + " " END SUB SUB SetKeyboardSpeed (Delay, Rate) ASSEMBLY "¸»" + CHR$(Rate) + CHR$(Delay) + "Í" + CHR$(&H16) + "Ë" END SUB SUB Sort (Block$(), BlockLength, CaseSensitivity) FOR Counter1 = BlockLength TO 0 STEP -1 FOR Counter2 = BlockLength TO Counter1 STEP -1 GOSUB StringCompare IF Result > 0 THEN SWAP Block$(Counter1), Block$(Counter2) NEXT Counter2 NEXT Counter1 EXIT SUB '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *' StringCompare: Result = 0 String1$ = Block$(Counter1) String2$ = Block$(Counter2) IF CaseSensitivity = 0 THEN String1$ = UCASE$(String1$) String2$ = UCASE$(String2$) END IF IF LEN(String1$) > LEN(String2$) THEN Length = LEN(String2$) ELSE Length = LEN(String1$) END IF FOR Counter = 1 TO Length Result = ASC(MID$(String1$, Counter, 1)) - ASC(MID$(String2$, Counter, 1)) IF NOT Result = 0 THEN EXIT FOR NEXT Counter RETURN END SUB