flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Protected Mode - Print letters to screen in Graphics Mode

Author
Thread Post new topic Reply to topic
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 08 Mar 2016, 16:34
How do you print letters (eg: A, B, C) to the screen in graphics mode when utilizing video memory directly (A0000h)? Remember I am in protected mode... Thanks in advance!

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 08 Mar 2016, 16:34
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 08 Mar 2016, 22:04
EDIT: Apologies, the following was misinterpreted, mis-remembered and incorrect Embarassed

Quote:
Simply write the letters to that memory:
Code:
mov edi,$A0000
mov byte [edi],'A'    
I've had cases where the A0000 region doesn't work but the B8000 region does.
/EDIT This is the same except each character is 2 bytes with the letter in the bottom byte and colours in each nybble (background at top, foreground at bottom) of the upper byte:
Code:
mov edi,$B8000
mov word [edi],(($F shl 12) or ($0 shl 8) or 'A')    


Last edited by cod3b453 on 15 Mar 2016, 18:57; edited 1 time in total
Post 08 Mar 2016, 22:04
View user's profile Send private message Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 09 Mar 2016, 01:25
yea, that doesn't work. i've instantiated video mode 13h-10h prior to entering protected mode which requires A0000h. Now if I instantiate 03h-10h prior to protected mode, I can use the Text Mode @ B8000, which i've already built a partial keyboard driver for, but now i'm converting my OS to a graphical layout.. Thanks for the input, but it doesn't work for me that way.
Post 09 Mar 2016, 01:25
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20484
Location: In your JS exploiting you and your system
revolution 09 Mar 2016, 01:42
You have to set each pixel to the foreground/background colours to draw the character.

You will probably need a bitmap giving you the character shapes. And then convert each bit into a pixel colour.
Post 09 Mar 2016, 01:42
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 09 Mar 2016, 01:54
could you provide an example or point to some docs that might cover how to do this revolution? thanks..
Post 09 Mar 2016, 01:54
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20484
Location: In your JS exploiting you and your system
revolution 09 Mar 2016, 02:42
First you ned the character shape definition:
Code:
db 00000000b
db 00111100b
db 01000010b
db 01000010b
db 01111110b
db 01000010b
db 01000010b
db 01000010b
db 00000000b    
Then for each bit in the shape definition you set the pixel colour. Black for 0 and white for 1 (or whatever colours you need).
Post 09 Mar 2016, 02:42
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 09 Mar 2016, 03:12
ok. i got that part. thanks. however, i'm still at a loss. this is what i tried, but all i get is a single pixel in the upper left-hand corner..
Code:

        mov edi, 0A0000h
        mov al,0x02 ; the color of the pixel
        mov dword[edi],letterA  
 
letterA:
        db 00000000b
        db 00111100b
        db 01000010b
        db 01000010b
        db 01111110b
        db 01000010b
        db 01000010b
        db 01000010b
        db 00000000b            


    
Post 09 Mar 2016, 03:12
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20484
Location: In your JS exploiting you and your system
revolution 09 Mar 2016, 03:33
Read each bit from the shape bitmap, one by one, if it is zero set for black, or 1 set for white, then put the colour on the screen. Move to the next pixel and repeat. Ugly pseudo code:
Code:
        screen = top_left_position_of_character
        vertical_pixel_count = 8
loop_v:
        horizontal_pixel_count = 8      ;a line of pixels
loop_h:
        read_next_bit_from_the_shape_bitmap
        if 0
                colour=black
        else
                colour=white
        end if
        mov [screen],colour
        add screen,1    ;move to next pixel
        dec horizontal_pixel_count
        jnz     loop_h
        add screen,160-8 ;or whatever value needed to get to the next line
        dec vertical_pixel_count
        jnz     loop_v    
Post 09 Mar 2016, 03:33
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 09 Mar 2016, 03:59
thanks revolution! i'll work with that and see what i come up with..
Post 09 Mar 2016, 03:59
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 12 Mar 2016, 03:20
I came up with the following that will correctly plot pixels for the byte sequence - 10101010b. However, I cannot figure out how I would move to the next row..

eg:
Code:
db 10101010b ;how do i move from this row to the next???
db 00111100b
    


any ideas?

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;         Plots a single 8-bit sequence to screen             ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        xor eax, eax
        xor ebx, ebx
        xor ecx, ecx
        xor edx, edx

        mov edi, 0xA0000 ;start memory address(vga)
        mov al, 0x0A ;pixel color

        mov bl, 10101010b ; this is plotted correctly

        pixelstart:
          shl bl, 1
          jnc noprintpixel
        printPixel:
          mov [edi], al
        noprintpixel:
          add cx, 1
          inc edi
          cmp cx, 8
          jne pixelstart
        endpixel:                       
    

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com


Last edited by newport on 12 Mar 2016, 03:39; edited 1 time in total
Post 12 Mar 2016, 03:20
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20484
Location: In your JS exploiting you and your system
revolution 12 Mar 2016, 03:39
The value in BL should ideally come from a predefined array of character shapes. It shouldn't be hard coded into the source like that.

If you have ESI point to the current character shape memory the you can get the next value of BL by "mov bl,[esi]" and "inc esi" to get to the next value.
Post 12 Mar 2016, 03:39
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 12 Mar 2016, 03:41
ok..i think I see now.. thanks for the help...

back to the drawing board.. (pun intended)
Post 12 Mar 2016, 03:41
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 13 Mar 2016, 22:26
Ok.. I been working for days on this and can't seem to get anywhere. This is what I have now, however it will only print the first two bytes from esi. What am I doing wrong???

Code:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;         Plots a character to upper-left corner of screen              ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        xor eax, eax
        xor ebx, ebx
        xor ecx, ecx
        xor edx, edx

        mov edi, 0xA0000
        mov al, 0x0A
        mov esi, letterA
        mov bl, [esi]
        mov dx, 0
        mov cx, 0
        jmp drawLetter

        drawLetter:
                cld
                call drawByte
                inc esi
                add edi, 312
                mov bl, [esi]
                mov al, 0x0a
                add cx, 1
                cmp cx, 8
                je finished
                jmp drawLetter

        finished:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;         Plots a 8-bit sequence to screen                              ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
drawByte:
        pixelstart:
          shl bl, 1
          jnc noprintpixel
        printPixel:
          mov [edi], al
        noprintpixel:
          add dx, 1
          inc edi
          cmp dx, 8
          jne pixelstart
        endpixel:
ret 

letterA: db 00011000b
         db 00100100b
         db 00100100b
         db 00111100b
         db 00100100b
         db 00100100b
         db 00100100b
         db 00000000b                   

    

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 13 Mar 2016, 22:26
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 13 Mar 2016, 22:34
Nevermind, lol... found the problem

this....
Code:
        endpixel:
    

should actually be this...
Code:
        endpixel:
        mov dx, 0
    

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 13 Mar 2016, 22:34
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 15 Mar 2016, 19:01
Sorry my previous was a mess! Just to let you know - there is also VESA LFB which can be written to as blocks of RGB pixels, if you wanted higher resolutions/more colours.
Post 15 Mar 2016, 19:01
View user's profile Send private message Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 17 Mar 2016, 01:44
thanks.. i'm actually reading up on vesa now Smile
Post 17 Mar 2016, 01:44
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8363
Location: Kraków, Poland
Tomasz Grysztar 17 Mar 2016, 09:17
newport wrote:
thanks.. i'm actually reading up on vesa now Smile
If you wouldn't mind a more complex sample, my old kelvar example contains some routines that load a variable-width font from a graphic file and then draw texts in VESA graphic mode using this font. The example uses the 32-bit unreal mode instead of protected mode, but the routines should mostly work the same in either one. The font loading and text drawing is in ENGINE/TEXT.INC (it uses the clip+blit routine from SYSTEM/VIDEO.INC to plot in the off-screen image buffer that later is copied to VESA video memory with video_blit). I'm sorry there are so few sparse comments in this code, this example is almost as old as fasm itself.
Post 17 Mar 2016, 09:17
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 23 Mar 2016, 13:55
thanks! i'll definitely read up on that!
Post 23 Mar 2016, 13:55
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.