Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cls queston
#1
somebody gave me this piece of code and said its faster than "cls"
is it true?

Code:
line (0,0)-(320,200),0,bf
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#2
oops, almost forgot..i understand how the piece of code worx..but i dont understand why it might be any faster than cls
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#3
Because that piece of code fills the screen memory with 0s

Whereas CLS reinitialize and do other stuff
Reply
#4
If you're really concerned about speed in screen 13, you can use this asm code...

[syntax="asm"]
mov ax, 0xA000
mov es, ax
xor di, di
mov cx, 0xFA00
xor al, al
rep stosb
retf
[/syntax]

Which is specialised to fill the entire screen in mode 13 (thus it is faster than the LINE method... no mode checking, no clipping).

Here is a SUB you can add to your program implementing this:

[syntax="QBASIC"]
SUB ClearScr

asm$ = CHR$(&HB8) + CHR$(&H0) + CHR$(&HA0) + CHR$(&H8E)
asm$ = asm$ + CHR$(&HC0) + CHR$(&H31) + CHR$(&HFF) + CHR$(&HB9)
asm$ = asm$ + CHR$(&H0) + CHR$(&HFA) + CHR$(&H30) + CHR$(&HC0)
asm$ = asm$ + CHR$(&HF3) + CHR$(&HAA) + CHR$(&HCB)

DEF SEG = VARSEG(asm$)
CALL ABSOLUTE(SADD(asm$))
DEF SEG

END SUB
[/syntax]

Remember to start QB with the /L switch to use this. Smile

To make it even faster, make 'asm$' a global constant, so the top part of the code doesn't have to be executed each time. Smile

It won't work in FreeBASIC, by the way.


-shiftLynx
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Reply
#5
Quote:[syntax="QBASIC"]
SUB ClearScr

asm$ = CHR$(&HB8) + CHR$(&H0) + CHR$(&HA0) + CHR$(&H8E)
asm$ = asm$ + CHR$(&HC0) + CHR$(&H31) + CHR$(&HFF) + CHR$(&HB9)
asm$ = asm$ + CHR$(&H0) + CHR$(&HFA) + CHR$(&H30) + CHR$(&HC0)
asm$ = asm$ + CHR$(&HF3) + CHR$(&HAA) + CHR$(&HCB)

DEF SEG = VARSEG(asm$)
CALL ABSOLUTE(SADD(asm$))
DEF SEG

END SUB
[/syntax]

[...]To make it even faster, make 'asm$' a global constant, so the top part of the code doesn't have to be executed each time. Smile

Don't use intermodule globals Tongue You can solve the speed issue with this:

Code:
SUB ClearScr
    STATIC initalised%
    IF NOT initialised% THEN
        initialised% = -1
        asm$ = CHR$(&HB8) + CHR$(&H0) + CHR$(&HA0) + CHR$(&H8E)
        asm$ = asm$ + CHR$(&HC0) + CHR$(&H31) + CHR$(&HFF) + CHR$(&HB9)
        asm$ = asm$ + CHR$(&H0) + CHR$(&HFA) + CHR$(&H30) + CHR$(&HC0)
        asm$ = asm$ + CHR$(&HF3) + CHR$(&HAA) + CHR$(&HCB)
    END IF

    DEF SEG = VARSEG(asm$)
        CALL ABSOLUTE(SADD(asm$))
    DEF SEG

END SUB

Btw, the above is PDS code, not QB45 (note the SADD thingo Wink)
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#6
Shouldnt it be SSEG() too?

Or that doesent matter?


FB has shadowed my QB knowledge Tongue
Reply
#7
How come you guys are clearing the screen a single byte at a time? :lol:

xteraco:
If you do use line:
line (0, 0)-(320 - 1, 200 - 1), 0, bf
X ranges from 0 to 319 and y from 0 to 199 in screen 13.

But their way will probably be much faster (even faster if they'd use dwords...).
Reply
#8
dwords? whats that?
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#9
Double Words
4 bytes

A word is 2 bytes


If I'm not misstaken... some compilers has it so words are 4 bytes and double words are 8 bytes... silly...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)