flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > 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
Protected Mode - Print letters to screen in Graphics Mode
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: 616
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 12or ($0 shl 8or '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
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: 15241
Location: 1I/ʻOumuamua
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
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: 15241
Location: 1I/ʻOumuamua
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
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 edi0A0000h
        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: 15241
Location: 1I/ʻOumuamua
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
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
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 eaxeax
        xor ebxebx
        xor ecxecx
        xor edxedx

        mov edi0xA0000 ;start memory address(vga)
        mov al0x0A ;pixel color

        mov bl10101010b ; this is plotted correctly

        pixelstart:
          shl bl1
          jnc noprintpixel
        printPixel:
          mov [edi], al
        noprintpixel:
          add cx1
          inc edi
          cmp cx8
          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: 15241
Location: 1I/ʻOumuamua
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
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
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 eaxeax
        xor ebxebx
        xor ecxecx
        xor edxedx

        mov edi0xA0000
        mov al0x0A
        mov esiletterA
        mov bl, [esi]
        mov dx0
        mov cx0
        jmp drawLetter

        drawLetter:
                cld
                call drawByte
                inc esi
                add edi312
                mov bl, [esi]
                mov al0x0a
                add cx1
                cmp cx8
                je finished
                jmp drawLetter

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

letterAdb 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
Nevermind, lol... found the problem

this....

Code:

        endpixel:



should actually be this...

Code:

        endpixel:
        mov dx0



_________________
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: 616
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
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
Assembly Artist


Joined: 16 Jun 2003
Posts: 6633
Location: Kraków, Poland

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
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.