Author Topic: Scrollable DOS Screen  (Read 239 times)

Scrollable DOS Screen
« on: March 15, 2019, 02:22:33 PM »
Is it possible to use/access the method a modern DOS computer uses to display large number of lines in the DOS window?

For example, in a dos window type "help" and a long help list is displayed. You can scroll up and down this list.

This would be very useful in the tools firmware I use to monitor my industrial cell phones.

Offline FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Scrollable DOS Screen
« Reply #1 on: March 15, 2019, 02:29:20 PM »
Start your program with:

Code: QB64 [Select]

Offline Pete

  • Cuz I sez so, varmint!
Re: Scrollable DOS Screen
« Reply #2 on: March 15, 2019, 03:02:05 PM »
Or do you mean just to scroll say 500 lines of text through a 25 line high window? Yes, that can be coded. Something like: FOR i = 1 to 500: PRINT i: NEXT and have a way to scroll back through those numbers would require a routine similar to like this...

Code: QB64 [Select]
  1. WIDTH 80, 25 ' Standard window.
  2. DIM myarray(500) AS STRING * 80 ' Screen width
  3. FOR ii% = 1 TO 500
  4.     myarray(ii%) = LTRIM$(STR$(ii%))
  5.     PRINT myarray(ii%)
  6.  
  7.     _LIMIT 30
  8.     b$ = INKEY$
  9.     IF LEN(b$) THEN
  10.         IF b$ = CHR$(27) THEN SYSTEM ' Quit.
  11.         IF b$ = CHR$(0) + "H" AND ii% > 23 THEN
  12.             ' scroll up
  13.             CLS
  14.             ii% = ii% - 23: IF ii% < 24 THEN ii% = 24
  15.             FOR j% = 23 TO 1 STEP -1
  16.                 PRINT myarray(ii% - j%)
  17.             NEXT
  18.         END IF
  19.         IF b$ = CHR$(0) + "P" AND ii% < 500 THEN
  20.             ' scroll down
  21.             CLS
  22.             FOR j% = 1 TO 23
  23.                 IF ii% > 500 THEN EXIT FOR
  24.                 PRINT myarray(ii%)
  25.                 ii% = ii% + 1
  26.             NEXT
  27.         END IF
  28.  
  29.     END IF

Up and down conditions show two approaches to the math, but there are several others. You can also make routines that scroll one line at a time. In other words you could show a cursor and it would travel up and down, entry by entry, and only scroll the screen when it was going above or below the top or bottom visible line. Anyway, I wouldn't recommend this code, it's too simplistic and if using $CONSOLE:ONLY with _DEST _CONSOLE is all you need, that's even easier!

Pete

Re: Scrollable DOS Screen
« Reply #3 on: April 01, 2019, 04:52:24 PM »
Thanks for the replies.

Well I tried the $console lines and it had no effect. I couldn't scroll up to see what scrolled off the upper part of the string.

How could I screw up two lines?

Any thoughts?

Re: Scrollable DOS Screen
« Reply #4 on: April 01, 2019, 07:25:38 PM »
My only thought is, how are you scrolling? Are you using the scroll bar on the right? Or are you trying to use the arrow keys?

In a DOS window, if you try to scroll using the arrow keys, you will instead see a sequence of the most recent inputs you entered into the app.

Here, try this handy little number conversion program, to see what I mean.

Code: QB64 [Select]
  1. REM  Number Conversion - Binary-Hex-Decimal
  2. REM ---------------------------------------
  3. REM OPEN "c:\temp\NumberConversions.txt" FOR OUTPUT AS #1
  4. DIM SHARED dec AS _FLOAT, decin AS _FLOAT, TotDec AS _FLOAT, MSbitVal AS _FLOAT
  5. DIM SHARED DecVal AS _FLOAT, TotDecVal AS _FLOAT, MaxDecVal AS _FLOAT
  6. DIM SHARED TotIntVal AS _FLOAT, IntVal AS _FLOAT, MSbitIntVal AS _FLOAT
  7. DIM SHARED Bit(1000) AS INTEGER, i AS INTEGER, subtract(1000) AS _FLOAT
  8. DIM SHARED Character(128)
  9. 1 CALL intro(op$)
  10. IF op$ = "x" THEN
  11.     CLOSE
  12.     END
  13. IF op$ = "b" THEN CALL BinTo
  14. IF op$ = "i" THEN CALL IntTo(op$)
  15. IF op$ = "d" THEN CALL DecTo(op$)
  16. IF op$ = "h" THEN CALL IntTo(op$)
  17.  
  18. SUB intro (op$)
  19.     PRINT "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  20.     PRINT "NUMBERICAL DEC-BIN-HEX CONVERSIONS"
  21.     PRINT
  22.     PRINT "Binary to decimal and hex = b"
  23.     PRINT "Non-neg integer decimal to binary and hex = i"
  24.     PRINT "Decimal to binary and hex = d"
  25.     PRINT "Hex to decimal and binary = h"
  26.     PRINT
  27.     INPUT "Enter conversion operation (x exits) -> ", op$
  28.  
  29. SUB BinTo
  30.     i = 0
  31.     imax = 0
  32.    2 CLS
  33.     INPUT "Enter binary number, MSbit entered first -> ", binnum$
  34.     imax = LEN(binnum$)
  35.     warn = 0
  36.     FOR i = 1 TO imax
  37.         Bit(i) = ASC(binnum$, i)
  38.         IF Bit(i) < 48 OR Bit(i) > 49 THEN warn = 1
  39.         IF Bit(i) = 48 THEN Bit(i) = 0
  40.         IF Bit(i) = 49 THEN Bit(i) = 1
  41.         IF warn = 1 THEN
  42.             PRINT
  43.             COLOR 4, 7
  44.             BEEP
  45.             PRINT "Entered one or more non-binary bits."
  46.             PRINT
  47.             COLOR 1, 7
  48.             INPUT "Continue"; cont$
  49.             EXIT SUB
  50.         END IF
  51.     NEXT i
  52.     CLS
  53.     PRINT "Entered"; imax; "-bit binary value (MSbit left) ="
  54.     FOR i = 1 TO imax
  55.         REM LOCATE 2, 2 * i
  56.         PRINT Bit(i)
  57.     NEXT i
  58.     PRINT
  59.     INPUT "Is this value correct (y/n)"; ans$
  60.     IF ans$ = "n" GOTO 2
  61.     dec = 0
  62.     TotDec = 0
  63.     FOR i = 1 TO imax
  64.         dec = Bit(i) * 2 ^ (imax - i)
  65.         TotDec = TotDec + dec
  66.     NEXT i
  67.     HexNum$ = HEX$(TotDec)
  68.     PRINT
  69.     PRINT "Value as if integer ="; TotDec, "Hex value = "; HexNum$
  70.     PRINT
  71.     REM PRINT #1, "Entered"; imax; "-bit binary value (MSbit top) ="
  72.     FOR i = 1 TO imax
  73.         REM  PRINT #1, Bit(i)
  74.     NEXT i
  75.     REM PRINT #1,
  76.     REM PRINT #1, "Value as if integer ="; TotDec, , "Hex value = "; HexNum$
  77.     INPUT "Enter value of MSbit (negative to indicate 2's complement) -> ", MSbitVal
  78.     TotDecVal = 0
  79.     FOR i = 1 TO imax
  80.         DecVal = ABS(MSbitVal) * Bit(i) / 2 ^ (i - 1)
  81.         TotDecVal = TotDecVal + DecVal
  82.     NEXT i
  83.     IF MSbitVal < 0 AND Bit(1) = 1 THEN TotDecVal = TotDecVal - 2 * ABS(MSbitVal)
  84.     PRINT "Value of binary number = "; TotDecVal
  85.     REM PRINT #1,
  86.     REM PRINT #1, "MSbit (- for 2's complement) = "; MSbitVal, "Value of binary number = "; TotDecVal
  87.     REM PRINT #1, "----------------------------------------"
  88.     REM PRINT #1,
  89.     PRINT
  90.     INPUT "Continue"; cont$
  91.  
  92. SUB IntTo (op$)
  93.     CLS
  94.     warn = 0
  95.     IF op$ = "i" THEN
  96.         INPUT "Enter decimal (non-negative integer) -> ", dec
  97.         IF dec < 0 OR dec <> INT(dec) THEN
  98.             PRINT
  99.             COLOR 4, 7
  100.             BEEP
  101.             PRINT "Must enter a non-negative integer."
  102.             PRINT
  103.             COLOR 1, 7
  104.             INPUT "Continue"; cont$
  105.             EXIT SUB
  106.         END IF
  107.         hexnum$ = HEX$(dec)
  108.     ELSE
  109.         INPUT "Enter hex value (0-9, A-F) -> ", hexnum$
  110.         NumChar = LEN(hexnum$)
  111.         FOR i = 1 TO NumChar
  112.             Character(i) = ASC(hexnum$, i)
  113.             IF Character(i) < 48 THEN warn = 1
  114.             IF Character(i) > 57 AND Character(i) < 65 THEN warn = 1
  115.             IF Character(i) > 70 AND Character(i) < 97 THEN warn = 1
  116.             IF Character(i) > 102 THEN warn = 1
  117.         NEXT i
  118.         IF warn = 1 THEN
  119.             PRINT
  120.             COLOR 4, 7
  121.             BEEP
  122.             PRINT "Entered one or more non-hex characters."
  123.             PRINT
  124.             COLOR 1, 7
  125.             INPUT "Continue"; cont$
  126.             EXIT SUB
  127.         END IF
  128.         dec = VAL("&h" + hexnum$)
  129.     END IF
  130.     imax = 0
  131.     n = 0
  132.     DO
  133.         numbits = dec / 2 ^ n
  134.         IF numbits < 1 THEN EXIT DO
  135.         n = n + 1
  136.     LOOP
  137.     IF n - 1 >= 0 THEN
  138.         imax = n - 1
  139.     ELSE imax = 0
  140.     END IF
  141.     PRINT
  142.     PRINT "Decimal value ="; dec, "Hex value = "; UCASE$(hexnum$)
  143.     PRINT
  144.     REM PRINT #1, "Decimal value ="; dec, "Hex value = "; UCASE$(hexnum$)
  145.     REM PRINT #1,
  146.     PRINT "Requires"; imax + 1; "-bit binary value (MSbit left) ="
  147.     REM PRINT #1, "Requires"; imax + 1; "-bit binary value (MSbit top) ="
  148.     FOR i = imax TO 0 STEP -1
  149.         remainder = dec / 2 ^ i
  150.         IF remainder >= 1 THEN
  151.             Bit(i) = 1
  152.             dec = dec - 2 ^ i
  153.         ELSE
  154.             Bit(i) = 0
  155.         END IF
  156.         REM LOCATE 6, 1 + 2 * (imax - i)
  157.         PRINT Bit(i)
  158.         REM  PRINT #1, Bit(i)
  159.     NEXT i
  160.     IF n > 0 THEN
  161.         PRINT
  162.         REM PRINT #1,
  163.         PRINT "MSbit value if non-negative integer ="; 2 ^ imax
  164.         REM PRINT #1, "MSbit value if non-negative integer ="; 2 ^ imax
  165.     END IF
  166.     IF op$ = "h" THEN
  167.         PRINT
  168.         INPUT "Enter value of MSbit (negative to indicate 2's complement) -> ", MSbitVal
  169.         TotDecVal = 0
  170.         FOR i = 0 TO imax
  171.             DecVal = ABS(MSbitVal) * Bit(imax - i) / 2 ^ i
  172.             TotDecVal = TotDecVal + DecVal
  173.         NEXT i
  174.         IF MSbitVal < 0 THEN TotDecVal = TotDecVal - 2 * ABS(MSbitVal)
  175.         PRINT "Value of binary number = "; TotDecVal
  176.         REM PRINT #1,
  177.         REM PRINT #1, "MSbit (- for 2's complement) = "; MSbitVal, "Value of binary number = "; TotDecVal
  178.     END IF
  179.     PRINT
  180.     REM PRINT #1, "----------------------------------------"
  181.     REM PRINT #1,
  182.     INPUT "Continue"; cont$
  183.  
  184. SUB DecTo (op$)
  185.     CLS
  186.    4 INPUT "Enter decimal value (negative for 2's complement) -> ", decin
  187.     INPUT "Enter number of bits in binary value (positive integer) -> ", imax
  188.     IF imax = 0 THEN EXIT SUB
  189.     IF imax < 1 OR imax <> INT(imax) THEN
  190.         PRINT
  191.         GOTO 4
  192.     END IF
  193.     INPUT "Enter value of the MSbit (positive number) -> ", MSbitVal
  194.     IF MSbitVal <= 0 THEN
  195.         PRINT
  196.         GOTO 4
  197.     END IF
  198.     IF decin < 0 THEN
  199.         dec = MSbitVal * 2 + decin
  200.     ELSE dec = decin
  201.     END IF
  202.     n = 0
  203.     PRINT
  204.     PRINT "Decimal value = "; decin, "Decimal as positive number ="; dec
  205.     PRINT "MSbit value ="; MSbitVal; "of the"; imax; "-bit binary number"
  206.     PRINT
  207.     REM PRINT #1, "Decimal value = "; decin, "Decimal as positive number ="; dec
  208.     REM PRINT #1, "MSbit value ="; MSbitVal; "of the"; imax; "-bit binary number"
  209.     REM PRINT #1,
  210.     PRINT "Binary value (MSbit left) ="
  211.     REM PRINT #1, "Binary value (MSbit top) ="
  212.     FOR i = 0 TO imax - 1
  213.         subtract(i) = MSbitVal / 2 ^ i
  214.         IF dec - subtract(i) >= 0 THEN
  215.             Bit(i) = 1
  216.             dec = dec - subtract(i)
  217.         ELSE Bit(i) = 0
  218.         END IF
  219.         REM LOCATE 9, 1 + 2 * i
  220.         PRINT Bit(i)
  221.         REM  PRINT #1, Bit(i)
  222.     NEXT i
  223.     REM -------
  224.     REM  Now calculate the actual value produced by the BINARY number
  225.     REM -------
  226.     TotDecVal = 0
  227.     FOR i = 0 TO imax - 1
  228.         DecVal = MSbitVal * Bit(i) / 2 ^ i
  229.         TotDecVal = TotDecVal + DecVal
  230.     NEXT i
  231.     IF decin < 0 THEN TotDecVal = TotDecVal - 2 * MSbitVal
  232.     REM -------
  233.     REM  Now calculate the positive INTEGER value AND hex equivalent
  234.     REM -------
  235.     MSbitIntVal = 2 ^ (imax - 1)
  236.     TotIntVal = 0
  237.     FOR i = 0 TO imax - 1
  238.         IntVal = MSbitIntVal * Bit(i) / 2 ^ i
  239.         TotIntVal = TotIntVal + IntVal
  240.     NEXT i
  241.     PRINT
  242.     PRINT "Actual decimal equivalent = "; TotDecVal, "Positive Integer ="; TotIntVal, "Hex = "; HEX$(TotIntVal)
  243.     PRINT
  244.     REM PRINT #1,
  245.     REM PRINT #1, "Actual decimal equivalent = "; TotDecVal, "Positive Integer ="; TotIntVal, "Hex = "; HEX$(TotIntVal)
  246.     REM PRINT #1, "----------------------------------------"
  247.     REM PRINT #1,
  248.     INPUT "Continue"; cont$
  249.  

Re: Scrollable DOS Screen
« Reply #5 on: April 01, 2019, 07:51:52 PM »
Thanks for the reply.

I'd like to use the scroll bar on the right.  Your program worked great. That's the way I'd like my program to look.

I guess i need to analyze your program and figure out what I'm doing differently.

Compared to your program, my program looks like I wrote it when I was first using a TRS-80 Model 1 to teach myself Basic!

Re: Scrollable DOS Screen
« Reply #6 on: April 01, 2019, 08:18:50 PM »
Thanks, hotInc, but I didn't do anything subtle, wrt your question. So, here's a much shorter program which seems to work for me. See if it works for you. You can just keep the <enter> key pressed, to enter a bunch of zeroes. The you can try scrolling up and down, with the scrool bar on the right.

Code: QB64 [Select]
  1.     INPUT "Enter any number (if you enter 100 you exit this loop)"; num
  2.     IF num = 100 THEN EXIT DO
  3.     PRINT "Number entered = "; num
  4.     PRINT
  5.  

Re: Scrollable DOS Screen
« Reply #7 on: April 02, 2019, 10:56:49 AM »
That small program worked great.

I moved the three screen format statements below my DIM and shared statements and my screen now is scrollable.

Thanks for all the help guys.