Qbasicnews.com

Full Version: is it possible in qb?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was wandering.
It is possible to plot pixels using def seg and poke in for example screen 13. But my question is, is it possible to print ascii tokens to screen other then print / write? somewhow directly?
Not by poking anywhere, no, but there are DOS and BIOS interrupts you can use.
In text mode or in graphics mode? In text mode you can set the character and attribute directly by poking at seg B800h (or B000h if you're real oldskool and have an MDA...) In graphics mode, you either have to draw your own characters by plotting the pixels yourself, or use an interrupt.
Here:

In ASM(One of the ASM stuff I made for Computer Eng. Students)

Code:
;****************************************************************************
;           THE MATRIX
;
;            Http://Rel.Betterwebber.com
;
;
;****************************************************************************

;****************************************************************************
.model small   ; data segment < 64k, code segment < 64k
.stack 200h    ; set up 512 bytes of stack space
.386
; ===========================================================================
.data

seed      dw 3749h          ;random seed value, globe phone number ;*)
icount    dw  0             ;outer loop counter
jcount    dw  0             ;inner loop counter
.code


;*****************************************************************

waitretrace proc

        mov dx,03dah                       ;0x3da9 vertical retrace port

wret:
        in al,dx
        and al,08h                        ;is vga in retrace?
jnz wret
wref:
        in al,dx
        and al,08h                        ;is retrace finished?
jz wref


ret
waitretrace endp

;*****************************************************************

textmode         proc
   mov   ah, 00h                        ;set video mode
   mov   al, 03h                        ;mode 03h
   int   10h                            ;enter 80x25x16 mode
   ret
textmode         endp

;*****************************************************************
ClearScreen Proc
    pusha                                ;preserve general regs
    mov ax, 0600h                        ;int 10, 6(scroll screen)
    mov bh, 02h                            ;color green on Black
    mov cx, 0000                        ;row0,col0
    mov dx, 184fh                        ;25,80
    int 10h                             ;scroll(clear it)
    popa                                ;restore regs
    ret
ClearScreen Endp

;*****************************************************************
;*****************************************************************
;*****************************************************************
;*****************************************************************
;*****************************************************************
;Main proggie

start:
   mov   ax, @data                        ;use the @ operator
   mov   ds, ax                         ;ds now points to the data segment.
   mov   ax, 0b800h                     ;text seg
   mov   es, ax
   call  textmode                        ;set to textmode
   mov ah, 01                           ;disable cursor
   mov cx, 2000h
   int 10h                              ;disable it baby
   call  ClearScreen                    ;clear the screen

mainloop:

   call  waitretrace
   mov icount, 0
iloop:
   ;generate random number
   mov   ax, seed                      ;move the seed value into ax
   mov   dx, 8405h                     ;move 8405h into dx
   mul   dx                            ;put 8405h x seed into dx:ax
   inc   ax                            ;increment ax
   mov   seed, ax                      ;we have a new seed
   cmp dl, 55
   ja negcx
        mov jcount, 3840
        jmp jloop
   negcx:
        mov jcount, -1
   jloop:
        mov cx, jcount
        mov di, cx
        sub di, 160
        mov ax, icount
        add di, ax
        mov dl, es:[di]
        mov di, jcount
        add di, icount
        mov es:[di], dl
        sub jcount, 160
        cmp jcount, 0
   jg jloop
      cmp jcount,0
      jne jnotzero
         ;generate random number
           mov   ax, seed                      ;move the seed value into ax
           mov   dx, 8405h                     ;move 8405h into dx
           mul   dx                            ;put 8405h x seed into dx:ax
           inc   ax                            ;increment ax
           mov   seed, ax                      ;we have a new seed
           cmp dl, 35
           jle printspace
                mov di, icount
                mov es:[di], dl
                jmp jnotzero
        printspace:
                mov di, icount
                mov dl, 32
                mov es:[di], dl
   jnotzero:

        mov cx, 1                   ;erase ugly multicolored
        eraseloop:                  ;top line
            mov di, cx
            mov al, 0
            mov es:[di], al
            add cx, 2
            cmp cx, 160
            jle eraseloop           ;second row?

        add icount, 4
        cmp icount, 159
        jle iloop
   mov   ah, 01h                       ;check for keypress
   int   16h                           ;is a key waiting in the buffer?
   jz    mainloop                      ;no, keep on going

exit:

   mov   ah, 4ch
   mov   al, 00h
   int   21h                            ;return to dos
end start
Yeah. POKEing to B800 is where you poke one byte for the ASCII character and one byte for the attribute. The bits of the attribute are set up as:

Bits 0-3 - RGBI foreground color
Bit 0 - Blue Value
Bit 1 - Green Value
Bit 2 - Red Value
Bit 3 - Intensity Value. If this bit is set, the color is bright (8-15). Otherwise, the color is dark (0-7).

Bits 4-6 - RGB Background color
Bit 4 - Blue Value
Bit 5 - Green Value
Bit 6 - Red Value

Bit 7 - Blinking Bit. If this bit is set, The character/background blink by switching or something. I've seen it but I haven't experimented with it. There is a way to make this bit stand for Background Intensity, so that the background color can be between 0-15 instead of 0-7 like it normally is. The only thing you lose is the ability to make it blink, but most people don't like blinking text anyways, so it isn't used a lot. I don't remember how to do this. I think you have to set something using port I/O with IN and OUT. Someone here will probably know, or you can look it up online (I'm too lazy). Or you can wait a little while and I'll find it in my notes... I know I have it somewhere... In this case, you would use this bit the same way you use the intensity bit for foreground colors.

For more information, check out this site:

http://www2.ics.hawaii.edu/~pagerg/312/n...Index.html

That's all. Just DEF SEG to B800h and POKE to wherever you want. Smile

Here's an explanation with sourcecode for PASCAL... you can probably find one for QBasic somewhere, too...

http://www.geocities.com/SiliconValley/P...l2013.html[/url]
Here is one thing i did for Rel's screensaver contest, as an example of peeking and poking to screen 0. The effect is very bad as the contest had 9 lines limit .
Code:
'The Matrix by Antoni Gual    agual@eic.ictnet.es
'for Rel's 9 LINER contest at QBASICNEWS.COM  1/2003
'------------------------------------------------------------------------
1 DEF SEG = &HB800
2 FOR i% = 0 TO 159 STEP 4
'  adjust this speed constant for optimal effect
'             |    0 no speed ;) .05 should be too fast even for a 386
'             |
3  IF RND < .0005 THEN j% = 3840 ELSE j% = -1
4  IF j% > 0 THEN POKE j% + i%, PEEK(j% - 160 + i%)
5  IF j% > 0 THEN j% = j% - 160
6  IF j% > 0 THEN GOTO 4
7  IF j% = 0 THEN IF RND > .3 THEN POKE i%, 96 * RND + 32 ELSE POKE i%, 32
8 NEXT
9 IF LEN(INKEY$) = 0 THEN GOTO 2
Antoni: That ASM code above uses almost the same algo as your QBcode. In fact, 70% of it is your algo. :*)
Copycat! Big Grin
Quote:Copycat! Big Grin
Hey, they wanted the "matrix". That's the simplest I could find. Perhaps I should send you 4 USD for your part in it. :*)