flat assembler
Message board for the users of flat assembler.

Index > DOS > [Example] Print "2023" with embedded font bitmap

Author
Thread Post new topic Reply to topic
FlierMate11



Joined: 13 Oct 2022
Posts: 19
FlierMate11 20 Nov 2022, 19:50
I make use of the routine I wrote in "textmode colors" (direct video memory access) with three embedded font bitmap to print "2023" on screen.

Not quite a good example but at least it is working.

If you are interested, you can expand it to include A...Z, a..z font bitmap too each in 64-bit unsigned integer (or 8 bytes).

Code:
org 100h
use16
        lea     bx, [two]
        mov     [fixed_x], 0
        mov     [fixed_y], 5
        call    print_font

        lea     bx, [zero]
        mov     [fixed_x], 20
        mov     [fixed_y], 5
        call    print_font

        lea     bx, [two]
        mov     [fixed_x], 40
        mov     [fixed_y], 5
        call    print_font

        lea     bx, [three]
        mov     [fixed_x], 60
        mov     [fixed_y], 5
        call    print_font

        mov     ax, 4c00h
        int     21h

print_font:
; bx = pointer to 8x8 font bitmap
        mov     word [pos_y], 0
.repeat_y:
        mov     cx, 8

.repeat_x:
        mov     word [pos_x], 8
        sub     word [pos_x], cx
        xor     ah, ah
        push    bx
        add     bx, word [pos_y]
        mov     al, byte [bx]
        bt      ax, cx
        jc      .on
        lea     si, [digit]
        add     si, [pos_x]
        mov     byte [si], ' '
        pop     bx
        dec     cx
        jnz     .repeat_x
        jmp     .finish
.on:
        lea     si, [digit]
        add     si, word [pos_x]
        mov     byte [si], '*'
        pop     bx
        dec     cx
        jnz     .repeat_x
.finish:

        push    ax
        push    bx
        push    cx
        lea     bx, [digit]
        mov     dx, [fixed_x]
        mov     [x], dx
        mov     dx, [fixed_y]
        mov     [y], dx
        mov     dx, [pos_y]
        add     [y], dx
        mov     [color], 15
        call    print
        pop     cx
        pop     bx
        pop     ax
        inc     [pos_y]
        cmp     [pos_y], 8
        jb      .repeat_y
        ret

print:
; bx = pointer to text string
        push    0b800h
        pop     es
        mov     ax, word [y]
        mov     dx, 80
        mul     dx
        add     ax, word [x]
        mov     dx, 2
        mul     dx
        mov     di, ax
        mov     ah, byte [color]
.redo:
        mov     al, byte [bx]
        or      al, al
        jz      .quit
        stosw
        inc     bx
        jmp     .redo
.quit:
        ret

fixed_x dw      ?
fixed_y dw      ?
x       dw      ?
y       dw      ?
color   db      ?
pos_x   dw      ?
pos_y   dw      ?
digit   db      8 dup (?)
        db      0
two     db      7Eh,02h,02h,7Eh,40h,40h,7Eh,00h   ;8x8 font bitmap (digit '2')
zero    db      7Eh,42h,42h,42h,42h,42h,7Eh,00h   ;8x8 font bitmap (digit '0')
three   db      7Eh,02h,02h,7Eh,02h,02h,7Eh,00h   ;8x8 font bitmap (digit '3')    
[/url]


Description: Example output
Filesize: 6.73 KB
Viewed: 312 Time(s)

Screenshot 2022-11-21 034413.png


Post 20 Nov 2022, 19:50
View user's profile Send private message Reply with quote
FlierMate11



Joined: 13 Oct 2022
Posts: 19
FlierMate11 20 Nov 2022, 19:57
The font bitmap is composed as below:

Code:
01111110 =7E
00000010 =02
00000010 =02
01111110 =7E
01000000 =40
01000000 =40
01111110 =7E
00000000 =00

7E02027E40407E00
9079822539999444480

01111110 =7E
01000010 =42
01000010 =42
01000010 =42
01000010 =42
01000010 =42
01111110 =7E
00000000 =00

7E42424242427E00

9097907049588751872

01111110 =7E
00000010 =02
00000010 =02
01111110 =7E
00000010 =02
00000010 =02
01111110 =7E
00000000 =00

7E02027E02027E00

9079822538955193856
    
Post 20 Nov 2022, 19:57
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8041
Location: Kraków, Poland
Tomasz Grysztar 20 Nov 2022, 21:34
Let me show a similar example but with a 8x14 font (read from video ROM) and two pixels per text mode character (like the old LIFE.COM example from fasm packages does it):
Code:
org 100h

        mov     ax,1130h
        mov     bh,2
        int     10h
        ; ES:BP is now pointer to ROM 8x14 character font
        push    es ds
        pop     es ds
        mov     si,bp
        mov     di,font
        mov     cx,256*14
        rep     movsb
        push    cs
        pop     ds

        push    0B800h
        pop     es
        xor     di,di
        mov     si,message
draw_message:
        lodsb
        test    al,al
        jz      done
        push    si
        mov     ah,14
        mul     ah
        mov     si,font
        add     si,ax
        mov     bx,14/2
  draw_character:
        mov     cx,8
        lodsw
        mov     dx,ax
    draw_points:
        mov     ax,0DCh
        shl     dh,1
        jnc     upper_ok
        or      ah,7
      upper_ok:
        shl     dl,1
        jnc     lower_ok
        or      ah,70h
      lower_ok:
        stosw
        loop    draw_points
        dec     bx
        jz      next_character
        add     di,(80-8)*2
        jmp     draw_character
  next_character:
        sub     di,80*(14/2-1)*2
        pop     si
        jmp     draw_message

done:
        int     20h

message db '2023',0

font rb 256*14    
Post 20 Nov 2022, 21:34
View user's profile Send private message Visit poster's website Reply with quote
macgub



Joined: 11 Jan 2006
Posts: 301
Location: Poland
macgub 21 Nov 2022, 17:32
Tomasz
Your ROM font example remind me some home/period work I have at school... (over 20 years ago).

During exam teacher ask me question - Could I change CS register when program is executed? I said "yes" (but I dont added - "you will probably got crash"). Teacher qualified my answer as not correct...
Post 21 Nov 2022, 17:32
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: 18963
Location: In your JS exploiting you and your system
revolution 21 Nov 2022, 21:12
Changing CS is easy. And it won't always crash
Code:
jmp 0x1234:0x5678 ; changes CS register while program is running.    
Post 21 Nov 2022, 21:12
View user's profile Send private message Visit poster's website Reply with quote
macgub



Joined: 11 Jan 2006
Posts: 301
Location: Poland
macgub 22 Nov 2022, 08:02
revolution
Thanks. So I'm gonna call the teacher, tell him he was wrong. I will suggest him to increase the rating he gave. . .

Wink
Post 22 Nov 2022, 08:02
View user's profile Send private message Visit poster's website Reply with quote
FlierMate11



Joined: 13 Oct 2022
Posts: 19
FlierMate11 22 Nov 2022, 10:33
Tomasz

Thanks for making the example complete with your ROM font program!
I also know there are 8x14 and 8x16 besides 8x8 ROM font.
Since the characters are big size, it is nice if can scroll the magnified text across the screen. Very Happy

---

Meanwhile, I also make a HLL variant of this font bitmap example:
https://dotnetfiddle.net/15ih29 (C# program)
It also prints "2023" on console screen in Windows.

Instead of embedding 8 bytes of "db" in DOS Assembly program, I straightly use 64-bit unsigned integer in HLL. And, this is the font variable declaration: Cool
Code:
                UInt64[] font=new UInt64[4];
                font[0]=9079822539999444480;
                font[1]=9097907049588751872;
                font[2]=font[0];
                font[3]=9079822538955193856;    


Description: Output from Tomasz's 8x14 ROM font program
Filesize: 5.81 KB
Viewed: 207 Time(s)

Screenshot 2022-11-22 182941.png


Post 22 Nov 2022, 10:33
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.