flat assembler
Message board for the users of flat assembler.
Index
> DOS > [Example] Print "2023" with embedded font bitmap |
Author |
|
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')
|
||||||||||
20 Nov 2022, 19:50 |
|
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 |
|||
20 Nov 2022, 21:34 |
|
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... |
|||
21 Nov 2022, 17:32 |
|
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. |
|||
21 Nov 2022, 21:12 |
|
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. . . |
|||
22 Nov 2022, 08:02 |
|
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. --- 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: Code: UInt64[] font=new UInt64[4]; font[0]=9079822539999444480; font[1]=9097907049588751872; font[2]=font[0]; font[3]=9079822538955193856;
|
||||||||||
22 Nov 2022, 10:33 |
|
FlierMate2 27 Mar 2023, 15:03
Done a C version, almost similar, but for IOCCC 2023:
https://www.ioccc.org/ https://jdoodle.com/ia/FPU (to be obfuscated further Or, https://jdoodle.com/ia/FPK (Sorry for posting here,as to make my font bitmap collection complete, also in HLL) |
|||
27 Mar 2023, 15:03 |
|
macomics 27 Mar 2023, 15:18
Alternatively, you can pull the standard fonts from the BIOS
Code: use16 org 256 cli mov ax, cs mov ds, ax mov es, ax add ax, ( end_of_image + 15 ) shr 4 postpone { label end_of_image } mov ss, ax mov sp, 1024 mov al, 32 sti next: cmp al, 32 jc @f push ax mov ax, 0500h int 10h mov ax, 0732h mov bh, 07h mov cx, 0000h mov dx, 317Fh int 10h push ds mov ax, 0040h mov ds, ax mov ax, [4Ah] sub ax, 20 shr ax, 1 mov cl, al add ax, 19 mov dl, al mov al, [84h] sub al, 14 shr al, 1 mov ch, al add al, 13 mov dh, al pop ds mov bh, 70h mov ax, 0610h int 10h mov ah, 2 mov bh, 0 mov dx, cx add dx, 0102h int 10h pop ax call draw @@: mov ah, 11h int 16h jz @f mov ah, 10h int 16h jmp @b @@: mov ah, 10h int 16h cmp ax, 7000h jnz next push ds mov ax, 0040h mov ds, ax mov ax, [18h] test ax, 02h pop ds jnz next int 20h draw: push ds mov dx, 0FF00h mov bx, 00A6Eh mov ah, 0 mov ds, dx shl ax, 3 add bx, ax mov ax, [bx + 0] mov dx, [bx + 2] mov cx, [bx + 4] mov bx, [bx + 6] pop ds push bx push cx push dx push ax call @f pop ax mov al, ah call @f pop ax push ax call @f pop ax mov al, ah call @f pop ax push ax call @f pop ax mov al, ah call @f pop ax push ax call @f pop ax mov al, ah call @f retn @@: push ax mov ah, 3 mov bh, 0 int 10h pop ax push dx mov cx, 8 mov bh, 0F0h @@: rol al, 1 push ax sbb al, al and al, 0DBh mov ah, 14 int 10h int 10h pop ax loop @b pop dx inc dh mov ah, 2 mov bh, 0 int 10h retn |
|||
27 Mar 2023, 15:18 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.