Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: andy on October 27, 2003, 01:03:19 PM



Title: Black box around text
Post by: andy on October 27, 2003, 01:03:19 PM
When using the code:

Code:
screen 13
cls
line(20,0)-(180,320),26,bf
locate 10,10
? "Hello"


There is a small black box around the text.

I could only figuer out one method to avoid this.

Code:
for y = 20 to 180
for x = 1 to 360
if point(x,y) = 15 then pset(x,y),26
next:next


This works, but it is slow and anoying. Does anyone know any better methods.


Title: Black box around text
Post by: Agamemnus on October 27, 2003, 01:52:17 PM
Without using libraries, your best bet is to have a sub that use LINEs to draw sequences of letters (words). Otherwise, use the QBASIC graphics stuff. I'd advise against it though. It's extremely messy stuff.


Title: Black box around text
Post by: Plasma on October 27, 2003, 02:45:56 PM
It's not that hard. :P

Code:
' Print text without the black box in screen 13
' by Plasma

DEFINT A-Z
DECLARE SUB ColorPrint (Row, Column, Text$, TextColor)

' Example:
SCREEN 13
CLS
LINE (20, 0)-(180, 320), 26, BF
ColorPrint 10, 10, "Hello", 15

SUB ColorPrint (Row, Column, Text$, TextColor)

  StartX = (Column - 1) * 8
  StartY = (Row - 1) * 8

  FOR x = 1 TO LEN(Text$)
    Char = ASC(MID$(Text$, x, 1))
    FOR y = &HFA6E + Char * 8 TO &HFA6E + 7 + Char * 8
      DEF SEG = &HF000
      Bits = PEEK(y)
      DEF SEG = &HA000
      Offset& = StartY * 320& + StartX
      IF Bits AND 128 THEN POKE Offset&, TextColor
      Offset& = Offset& + 1
      IF Bits AND 64 THEN POKE Offset&, TextColor
      Offset& = Offset& + 1
      IF Bits AND 32 THEN POKE Offset&, TextColor
      Offset& = Offset& + 1
      IF Bits AND 16 THEN POKE Offset&, TextColor
      Offset& = Offset& + 1
      IF Bits AND 8 THEN POKE Offset&, TextColor
      Offset& = Offset& + 1
      IF Bits AND 4 THEN POKE Offset&, TextColor
      Offset& = Offset& + 1
      IF Bits AND 2 THEN POKE Offset&, TextColor
      Offset& = Offset& + 1
      IF Bits AND 1 THEN POKE Offset&, TextColor
      Offset& = Offset& + 1
      StartY = StartY + 1
    NEXT
    StartX = StartX + 8
    StartY = (Row - 1) * 8
  NEXT
  DEF SEG

END SUB


Title: Re: Black box around text
Post by: Mango on October 27, 2003, 02:50:48 PM
Quote from: "andy"
This works, but it is slow and anoying. Does anyone know any better methods.


I don't usually do things like this, so don't have example code.  However, it should be pretty straightforward to write your text to screen, use the graphics 'get'  function to put the text in memory (as graphics, not text), then use the graphics 'put' function to put the text to screen *using the OR action mode*.

Here...I just tested it...works fine
Code:
SCREEN 13

s$ = "Hello"   ' Here's our string

'Lets find out how much graphics memory will be needed to hold it
bytesperpixel% = 1
charwidth% = 8    ' 320 pixels across / 40 characters across
charheight% = 10 ' 240 pixles vertical/ 24 characters vertical
numcharacters% = LEN(s$)
pixles% = charwidth% * charheight% * numcharacters%
bytesneeded% = pixles% * bytesperpixel%
intsneeded% = bytesneeded%

DIM myword(1 TO intsneeded%) AS INTEGER   'used to hold text
  ' OK...we are ready to put text in memory

cls
PRINT s$
GET (0, 0)-(numcharacters% * charwidth%, charheight%), myword
CLS

  'ok...text is in memory.  Now...we draw stuff on screen
LINE (0, 0)-(319, 239), 25, BF
   ' and now we can print our text on top of what's drawn on screen with no black box
PUT (50, 50), myword, OR


Title: Black box around text
Post by: Agamemnus on October 27, 2003, 02:56:30 PM
Plasma, you are the peek and poke MASTER!!


Title: Black box around text
Post by: KiZ on October 27, 2003, 03:11:10 PM
Or you could of course use a custom font. They look nicer than the original QB fonts....


Title: Black box around text
Post by: Mango on October 27, 2003, 03:41:55 PM
Quote from: "dark_prevail"
Or you could of course use a custom font. They look nicer than the original QB fonts....


Could someone post or point me to a simple (stripped) example that creates a custom font and uses it to print text to screen, with no other code distractions?  TIA


Title: Black box around text
Post by: Plasma on October 27, 2003, 03:49:30 PM
Just change the segment and offset of my example to get the font data from somewhere else...the characters are stored as bit images, with one byte per line, 8 bytes per character.


Title: Black box around text
Post by: TheBigBasicQ on October 27, 2003, 04:25:08 PM
Just use a lib like Future.Library =P.


Title: Black box around text
Post by: pr0gger on October 27, 2003, 06:41:59 PM
:king:  <--- Plasma


Title: Black box around text
Post by: Neo on October 28, 2003, 06:42:48 AM
Plasma the king... ;) lol
That's what you get when you have a lot of experience with it :)
Memory location &HF000 and &HA000 ....


Title: Black box around text
Post by: Neo on October 28, 2003, 06:44:50 AM
EDIT: sorry for double clicking the submit-button :)


Title: Black box around text
Post by: TheBigBasicQ on October 28, 2003, 03:26:14 PM
Quote from: "Neo"
Plasma the king... ;) lol
That's what you get when you have a lot of experience with it :)
Memory location &HF000 and &HA000 .... which are the location of the ROM Bios and the 13h VGA Screen Buffer.


I have one word for you - EDIT! and delete your previous post  :) .


Title: Black box around text
Post by: oracle on October 29, 2003, 12:30:50 AM
BAD TBBQ: by posting that message you made it impossible for Neo to delete his message!! :P


Title: Black box around text
Post by: barok on October 29, 2003, 02:18:32 AM
isn't it something like &hf800?  i think there's an 8 in there....


Title: Black box around text
Post by: Plasma on October 29, 2003, 02:23:04 AM
B800h is where the display buffer starts for color text modes.


Title: Black box around text
Post by: Neo on October 29, 2003, 06:28:06 AM
2 bytes for each char, a char and a colour. Wasn't it? Ah yes, it was. I learned very much by analysing the Digital Reality code... ;)


Title: Black box around text
Post by: TheBigBasicQ on October 29, 2003, 09:49:26 AM
Quote from: "oracle"
BAD TBBQ: by posting that message you made it impossible for Neo to delete his message!! :P


Like you posted this message which made it impossible for me to delete my message so in turn you made it impossible for Neo to delete his message  :wink:.


Title: Black box around text
Post by: ak00ma on October 29, 2003, 11:58:38 AM
Try this:
Code:

SUB QQB.Font (xpos, ypos, text$, col, Bcol, Style)
xx = xpos - 1
yy = ypos
IF Style AND 4 THEN
    QQB.Font xpos - 1, ypos - 1, text$, Bcol, 0, Style - 4
END IF
FOR chr = 1 TO LEN(text$)
    xx = xx + 8
    Ptr = 8 * ASC(MID$(text$, chr, 1)) + &HE
    FOR l = 0 TO 7
        DEF SEG = &HFFA6
            BitPattern = PEEK(Ptr + l)
        DEF SEG
        IF Style AND 2 THEN
             IF BitPattern AND 1 THEN PSET (xx + (7 - (l \ 2)), yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 2 THEN PSET (xx + (7 - (l \ 2)) - 1, yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 4 THEN PSET (xx + (7 - (l \ 2)) - 2, yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 8 THEN PSET (xx + (7 - (l \ 2)) - 3, yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 16 THEN PSET (xx + (7 - (l \ 2)) - 4, yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 32 THEN PSET (xx + (7 - (l \ 2)) - 5, yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 64 THEN PSET (xx + (7 - (l \ 2)) - 6, yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 128 THEN PSET (xx + (7 - (l \ 2)) - 7, yy + l), col - (7 - l) * (Style AND 1)
             IF Style AND 8 AND l = 7 THEN PSET (xx + (7 - (l \ 2)) - 7, yy + l), col - (7 - l) * (Style AND 1)
         ELSE
             IF BitPattern AND 1 THEN PSET (xx, yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 2 THEN PSET (xx - 1, yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 4 THEN PSET (xx - 2, yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 8 THEN PSET (xx - 3, yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 16 THEN PSET (xx - 4, yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 32 THEN PSET (xx - 5, yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 64 THEN PSET (xx - 6, yy + l), col - (7 - l) * (Style AND 1)
             IF BitPattern AND 128 THEN PSET (xx - 7, yy + l), col - (7 - l) * (Style AND 1)
             IF Style AND 8 AND l = 7 THEN PSET (xx - 7, yy + l), col - (7 - l) * (Style AND 1)
         END IF
    NEXT l
NEXT chr

END SUB


Title: Black box around text
Post by: andy on October 29, 2003, 12:18:58 PM
Thanks, its amazing that something so simple takes so much code.


Title: Black box around text
Post by: ak00ma on October 29, 2003, 12:57:20 PM
With my code you can even print text italic and bold


Title: Black box around text
Post by: KiZ on October 29, 2003, 01:31:55 PM
Quote from: "TheBigBasicQ"
Quote from: "oracle"
BAD TBBQ: by posting that message you made it impossible for Neo to delete his message!! :P


Like you posted this message which made it impossible for me to delete my message so in turn you made it impossible for Neo to delete his message  :wink:.


 :rotfl:


Title: Black box around text
Post by: andy on October 31, 2003, 04:54:06 PM
Thanks again plasma, but how does it work. I see that your drawing, each character ata a time and each line at atime, but it just doesn't make snse to me. And what does DEF SEG do?


Title: Black box around text
Post by: Plasma on October 31, 2003, 06:04:53 PM
Character data for the default fonts (8x8, 8x16, and sometimes 8x14) is stored in ROM. For 8x8 it's accessable at F000:FA6E.

The font is stored one bit for each pixel. Since there's 8 pixels in a row, each row takes a byte. There's 8 rows in a character (in 8x8, for 8x16 there's 16 rows), so one character is 8 bytes. The characters are in order from 0 to 255.

My function just checks to see what bits are set in a row and translates them to pixels, then moves on to the next row.

DEF SEG sets the segment used by PEEK and POKE. You have to use DEF SEG to switch the segment back and forth between ROM (F000) and the video buffer (A000).


Title: Black box around text
Post by: SCM on November 01, 2003, 12:34:12 AM
Where does the 8x16 data start?


Title: Black box around text
Post by: Plasma on November 01, 2003, 04:30:21 AM
I don't think there is a fixed position for the other fonts. You can get the location by calling interrupt 10 AX=1130h (http://www.ctyme.com/intr/rb-0158.htm) though.


Title: talking about text stuff...
Post by: webberboy on November 13, 2003, 02:07:47 AM
check out my text program:
http://www.network54.com/Hide/Forum/message?forumid=178387&messageid=1064853048

use textmake.bas to create the color stencils for text.bas.  use text.bas to write with the different colors.  Make sure that both files and the files you create are all in the same directory, or it won't work.