Author |
Message |
Kat Suit Mod #1 / 9
|
 odd behavior in Qbasic
Using Qbasic 7.1 PDS under DOS in Win98, I ran the following code, intending to display each printable charachter. The results were a bit bizarre. ---------------- code block ---------------------- count = 3 bigloop: PRINT CHR$(count); SLEEP 30 count = count + 1 GOTO bigloop ON ERROR GOTO stinky stinky: count = count + 1: GOTO bigloop ---------------- end code block ------------------ After the first dozen or so charachters, the program would only progress when I hit a key. It would then beep the PC Speaker, and print the next character. When I hold down Ctrl, however, it progresses without beeping, or requiring repeated keypresses. Incidentally, ON ERROR is called, because a few of the lower values for CHR$() produced an Illegal Function Call.
|
Mon, 20 Sep 2004 08:17:07 GMT |
|
 |
Arargh #2 / 9
|
 odd behavior in Qbasic
Quote:
>Using Qbasic 7.1 PDS under DOS in Win98, I ran the following code, >intending to display each printable charachter. The results were a bit >bizarre.
First off, PDS 7.1 is 'QuickBASIC' not 'QBasic' Quote: >---------------- code block ---------------------- >count = 3 >bigloop: >PRINT CHR$(count);
Values of <0 and >255 are illegal for CHR$ Quote: >SLEEP 30
Try reading the help details for 'SLEEP' Quote: >count = count + 1 > GOTO bigloop >ON ERROR GOTO stinky >stinky: >count = count + 1: GOTO bigloop >---------------- end code block ------------------ >After the first dozen or so charachters, the program would only >progress when I hit a key. It would then beep the PC Speaker, and >print the next character. When I hold down Ctrl, however, it >progresses without beeping, or requiring repeated keypresses. >Incidentally, ON ERROR is called, because a few of the lower values >for CHR$() produced an Illegal Function Call.
The easier way would be: FOR n=0 to 255 print chr$(n); Next N -- Arargh (at arargh dot com) http://www.arargh.com To reply by email, correct the mangled reply address.
|
Mon, 20 Sep 2004 10:07:18 GMT |
|
 |
Hensley Bas #3 / 9
|
 odd behavior in Qbasic
The ON ERROR GOTO code should be at the beginning. Your program is waiting for 30 seconds to progress. By hitting the Enter key you are cancelling out the 30 seconds waiting time. The SLEEP command does the generate beep statements if interrupted many times. I guess that it does not clear the keyboard buffer. You could replace the SLEEP with a: DO LOOP UNTIL INKEY$ <> "" 'Program code ON ERROR GOTO stinky CLS count = 3 bigloop: PRINT CHR$(count); 'SLEEP 30 count = count + 1 GOTO bigloop stinky: count = count + 1: IF count > 255 THEN END END IF RESUME NEXT -- --------------------- Hensley Bass
Home Page: http://pages.intnet.mu/jhbpage
Quote: > Using Qbasic 7.1 PDS under DOS in Win98, I ran the following code, > intending to display each printable charachter. The results were a bit > bizarre. > ---------------- code block ---------------------- > count = 3 > bigloop: > PRINT CHR$(count); > SLEEP 30 > count = count + 1 > GOTO bigloop > ON ERROR GOTO stinky > stinky: > count = count + 1: GOTO bigloop > ---------------- end code block ------------------ > After the first dozen or so charachters, the program would only > progress when I hit a key. It would then beep the PC Speaker, and > print the next character. When I hold down Ctrl, however, it > progresses without beeping, or requiring repeated keypresses. > Incidentally, ON ERROR is called, because a few of the lower values > for CHR$() produced an Illegal Function Call.
|
Mon, 20 Sep 2004 11:15:58 GMT |
|
 |
Paul Daxt #4 / 9
|
 odd behavior in Qbasic
Quote:
>Using Qbasic 7.1 PDS under DOS in Win98, I ran the following code, >intending to display each printable charachter. The results were a bit >bizarre. <SNIP>
The characters below 32 act as control codes when QB tries to print them. For example, 7 is BEL (bell) which sounds the BEEP you hear. Code 8 is a backspace so any printing on screen will go back one character. Other codes might well produce the strange effects you are getting as there are device controls of different sorts such as printer controls, comms codes, and so on.
|
Tue, 21 Sep 2004 03:46:27 GMT |
|
 |
]-[orro #5 / 9
|
 odd behavior in Qbasic
The best way to print all 255 characters to screen is this: Cls Def Seg=&HB800 For n=0 to 255 Poke n*2,n Next n Ok, it's a bit strange but here is how it works. Poke writes directly to memory at position xxxx:yyyy. Assuming that you have a color monitor and video card, B800:0000 is the memory location for the first character, so you have to tell the program to write there. To set xxxx you must use Def Seg=&Hxxxx (&H means that you enter a hexademical number). Then by using Poke yyyy,c you write at B800:yyyy the character c (c is the ascii number of the char). The reason that we have to multiply n with 2 is that the screen uses 2 bytes for each character to display. 1 for the char and 1 for the color.So if we want to write 2 characters the top left side of our screen we must write at B800:0000 and B800:0002. (when n=0 n*2=0 so B800:0000 and when n=1 n*2=2 so B800:0002). ]-[orror '02
|
Tue, 21 Sep 2004 18:19:00 GMT |
|
 |
Andreas Meil #6 / 9
|
 odd behavior in Qbasic
Quote: > The characters below 32 act as control codes when QB tries to > print them. For example, 7 is BEL (bell) which sounds the BEEP > you hear. Code 8 is a backspace so any printing on screen will > go back one character. Other codes might well produce the > strange effects you are getting as there are device controls of > different sorts such as printer controls, comms codes, and so
All ASCII codes which are not printable (but of course have also a character definition in the character generator ROM on the video card): 7, 9..13 and 28..31 To get these charachters, use a SUB procedure like this one: SUB PrintVerbatim(t$) DEF SEG=&HB800 adr% = 160 * (CSRLIN - 1) + 2 * (POS(0) - 1) PRINT SPACE$(LEN(t$)); ' this fills the colour map with the current ' colour setting and moves the cursor accordingly like a PRINT t$; FOR j% = 1 TO LEN(t$) POKE adr%, ASC(MID$(t$, j%, 1)) adr% = adr% + 2 NEXT j% END SUB Example: PrintVerbatim "Test" + CHR$(13) + CHR$(10) + CHR$(7) will show these special characters. Andreas
|
Tue, 21 Sep 2004 17:24:59 GMT |
|
 |
Derek Ro #7 / 9
|
 odd behavior in Qbasic
Nice explanation! Here's a slightly modified version of the program which produces a more readable end result and includes some character codes to make it easier to work out the code that corresponds to each character. DEFINT A-Z CLS DEF SEG = &HB800 FOR n = 0 TO 255 IF n MOD 16 = 0 THEN LOCATE (n \ 16) * 2 + 1, 1 PRINT n; TAB(6); ":" END IF POKE (n \ 16) * 256 + n * 4 + 20, n NEXT END Cheers Derek Quote:
> The best way to print all 255 characters to screen is this: > Cls > Def Seg=&HB800 > For n=0 to 255 > Poke n*2,n > Next n > Ok, it's a bit strange but here is how it works. > Poke writes directly to memory at position xxxx:yyyy. > Assuming that you have a color monitor and video card, > B800:0000 is the memory location for the first character, > so you have to tell the program to write there. To set xxxx > you must use Def Seg=&Hxxxx (&H means that you enter a > hexademical number). Then by using Poke yyyy,c you write > at B800:yyyy the character c (c is the ascii number of the char). > The reason that we have to multiply n with 2 is that the screen > uses 2 bytes for each character to display. 1 for the char and 1 > for the color.So if we want to write 2 characters the top left > side of our screen we must write at B800:0000 and B800:0002. > (when n=0 n*2=0 so B800:0000 and when n=1 n*2=2 so > B800:0002). > ]-[orror '02
|
Tue, 21 Sep 2004 18:51:07 GMT |
|
 |
Derek Ros #8 / 9
|
 odd behavior in Qbasic
<sigh>, Well it looked great on the NT 80 * 50 text screen that I was using at the time. Here's a version that's visible on an 80 * 25 screen. DEFINT A-Z CLS DEF SEG = &HB800 FOR n = 0 TO 255 IF n MOD 32 = 0 THEN LOCATE (n \ 32) * 2 + 1, 1 PRINT n; TAB(6); ":"; TAB(41); n + 16; TAB(46); ":" END IF POKE (n \ 32) * 160 + (n \ 16) * 16 + n * 4 + 14, n NEXT DEF SEG END Note that it's also good practice to use DEF SEG on its own to set things back to normal after POKEing things.
Quote: > Nice explanation! Here's a slightly modified version of the program > which produces a more readable end result and includes some character > codes to make it easier to work out the code that corresponds to each > character. > DEFINT A-Z > CLS > DEF SEG = &HB800 > FOR n = 0 TO 255 > IF n MOD 16 = 0 THEN > LOCATE (n \ 16) * 2 + 1, 1 > PRINT n; TAB(6); ":" > END IF > POKE (n \ 16) * 256 + n * 4 + 20, n > NEXT > END > Cheers > Derek
Quote: > > The best way to print all 255 characters to screen is this: > > Cls > > Def Seg=&HB800 > > For n=0 to 255 > > Poke n*2,n > > Next n > > Ok, it's a bit strange but here is how it works. > > Poke writes directly to memory at position xxxx:yyyy. > > Assuming that you have a color monitor and video card, > > B800:0000 is the memory location for the first character, > > so you have to tell the program to write there. To set xxxx > > you must use Def Seg=&Hxxxx (&H means that you enter a > > hexademical number). Then by using Poke yyyy,c you write > > at B800:yyyy the character c (c is the ascii number of the char). > > The reason that we have to multiply n with 2 is that the screen > > uses 2 bytes for each character to display. 1 for the char and 1 > > for the color.So if we want to write 2 characters the top left > > side of our screen we must write at B800:0000 and B800:0002. > > (when n=0 n*2=0 so B800:0000 and when n=1 n*2=2 so > > B800:0002). > > ]-[orror '02
|
Wed, 22 Sep 2004 05:52:40 GMT |
|
 |
Don Schullia #9 / 9
|
 odd behavior in Qbasic
Guys.... it can all be done in one smooth operation.... The following routine prints to the designated area in the designated attributes without changing the cursor or color settings. For those of you using powerbasic or FirstBASIC there is an ASM version of this routine on my web site under the name "Tprint" that does SO MUCH MORE. SUB Tprint ( Row%, Col%, Text$, Attr% ) Offset% = ((Row% - 1) * 160 ) + ((Col% - 1) * 2) DEF SEG=&HB800 FOR X% = 1 TO LEN(Text$) Char% = ASC(MID$(Text$,X%)) POKE Offset%, Char% : Offset% = Offset% + 1 POKE Offset%, Attr% : Offset% = Offset% + 1 NEXT DEF SEG END SUB CLS Tprint 10, 10, " Hello World ", &h71 -- C'ya, Don Schullian www.DASoftVSS.com
|
Wed, 22 Sep 2004 12:35:07 GMT |
|
|
|