flat assembler
Message board for the users of flat assembler.
Index
> Main > drawstring algorithm problem |
Author |
|
DOS386 05 Mar 2011, 13:36
> im not getting the correct address to the letter 'b'
Are you cutting off or corrupting the data maybe ? I can see the top line of your b Some code quality issues to fix: > add edi,1280*4 better: add edi, [BPSL] ; Do NOT hardcode here set BPSL and VRAM at same place. ---- > mov edi,[video_ptr] This (VRAM) belongs to the beginning of your routine ---- > push ecx > pop ecx this needs a clean-up ---- > shl ebx,3 > shl ebx,2 > ;shl ebx,1 better: SHL EBX, 5 ; WtF ??? ---- add comments: the 5 above, what is in the ECX pushed more above , ... ---- > a dd 0,0,0,0,0,0,0,0 You waste 32 bits to store just 1 bit Reduce 32 to 8, later to 1 |
|||
05 Mar 2011, 13:36 |
|
Teehee 05 Mar 2011, 14:22
Hi, DOS.
DOS386 wrote: Are you cutting off or corrupting the data maybe ? I can see the top line of your b i made a test, printing just a char, and the char a it print, but b it doens't. Maybe yes. How can i ensure that where i put my vars (db,dd,dw) is a safe place? Quote:
whats BPSL? Quote:
Im just following revolution's statement: "make it works, then make it faster" (or something like that) Quote: > a dd 0,0,0,0,0,0,0,0 I still dont know how to work with values in the bit layer. I did dd just to get easy to me. Later i optimize. [rev's statem. =p] _________________ Sorry if bad english. |
|||
05 Mar 2011, 14:22 |
|
edfed 05 Mar 2011, 14:46
i've cleaned your source for mode 13h
now, it works. Code: org 100h mov ax,13h int 10h push 0a000h pop fs mov esi,text call printf ret db 'printf' printf: @@: movzx ecx,byte[esi] test ecx,ecx je @f call putc add [screen.x],8 inc esi jmp @b @@: ret db 'putc' putc: sub cl,'a' mov ecx,[keys+ecx*4] mov eax,[screen.x] mov ebx,[screen.y] mov dx,0707h .loop: cmp byte[ecx],0 je @f call putpixel @@: inc ecx dec dl jl @f inc eax jmp .loop @@: mov dl,7 dec dh jl @f sub eax,7 inc ebx jmp .loop @@: ret db 'putpixel' putpixel: push eax ebx imul eax,[screen.bpp] imul ebx,[screen.bpsl] mov byte[fs:eax+ebx],red pop ebx eax ret db 'screen' screen: .x dd 0 .y dd 0 .bpsl dd 320 ;replace it with vesa byte per scan line .bpp dd 1 ;Byte per pixel, not bit per pixel red=4 text db 'ababba',0 align 4 keys dd a,b a db 0,0,0,0,0,0,0,0 db 0,0,0,0,0,0,0,0 db 0,0,1,1,1,0,0,0 db 0,0,0,0,0,1,0,0 db 0,0,1,1,1,1,0,0 db 0,1,0,0,0,1,0,0 db 0,1,0,0,0,1,0,0 db 0,0,1,1,1,0,1,0 b db 0,1,1,0,0,0,0,0 db 0,0,1,0,0,0,0,0 db 0,0,1,0,0,0,0,0 db 0,0,1,0,1,1,1,0 db 0,0,1,1,0,0,0,1 db 0,0,1,0,0,0,0,1 db 0,0,1,1,0,0,0,1 db 0,1,1,0,1,1,1,0 and you just have to change fs to point to linear frame buffer, make bpsl = vesa bpsl, and bpp equal to byte per pixels from your vesa mode. when you encounter many nested loops, prefer the use of calls. |
|||
05 Mar 2011, 14:46 |
|
Teehee 05 Mar 2011, 15:00
i'm using that in my OS, ed. its a lil bit different, isn't?
|
|||||||||||
05 Mar 2011, 15:00 |
|
edfed 05 Mar 2011, 15:15
in an os, prefer the use of atomic functions.
printf>call putc putc>call putpixel putpixel>invoke screen structure screen>contains screen datas then, you will be able to share the properties of putpixel in every display functions. then, you will be able to put a single char, just using putc. i see in your "os" that you made drawchar, and just below, wrote drawstring. and drawstring contains code to draw the char instead of using drawchar func, it is a misconception to do like this. one more time i tell it to you, prefer the use of atomic functions, that will let you save memory, and develop many things on a simple way. just look the code i gave you, printf (your drawchar) is only 8 instructions, and uses the putc atom putc uses putpixel atom and putpixel can be used to draw a single pixel without modification appart the color parameter that should be passed. Code: mov eax,X mov ebx,Y call putpixel and you can use any calling convention to pass parameters. |
|||
05 Mar 2011, 15:15 |
|
Teehee 05 Mar 2011, 15:20
yea.. that 'drawchar' is just a try to draw a char and then i will put it inside drawstring. But neither drawchar is drawing correctly the letter 'b' (well, neither 'a' for awhile).
[edit:] i just checked my letter buffers ('a', 'b') is really being overrided. But why? |
|||
05 Mar 2011, 15:20 |
|
edfed 05 Mar 2011, 20:59
i can't answer, i just modified your code to test it, and i can display b with your original line.
Code: org 100h ;;;;;;;;;;;;;;;;;;; mov ax,13h ;;;;;;;;;;;;;;;;;;; int 10h ;;;;;;;;;;;;;;;;;;; push word 0a000h ;;;;;;;;;;;;;;;;;;; pop fs ;;;;;;;;;;;;;;;;;;; mov edi,0 ;;;;;;;;;;;;;;;;;;; call drawstring ;;;;;;;;;;;;;;;;;;; ret ;;;;;;;;;;;;;;;;;;; video_ptr dd 0 ;;;;;;;;;;;;;;;;;;; ; assuming edi = videobuffer drawstring: mov esi,text xor ecx,ecx .for0:push ecx ; next char loop movzx ebx,byte[esi] test ebx,ebx je .done ;sub ebx,'a' ;neg ebx mov ebx,[keys+4] ; 0 = a, 4 = b ( theoricaly Sad ) xor ecx,ecx .for1: push ecx ; height loop xor ecx,ecx .for2: ; width loop cmp dword[ebx],0 jz @f ;;;;;;;;;;;;;;;;;;;;;;;;;;; mov byte[fs:edi+ecx],4 ; set color @@:add ebx,4 inc ecx cmp ecx,8 jne .for2 pop ecx ;;;;;;;;;;;;;;;;;;; add edi,320 inc ecx cmp ecx,8 jne .for1 pop ecx inc ecx mov edi,[video_ptr] mov ebx,ecx shl ebx,3 ;;;;;;;;;;;; ; shl ebx,2 ;shl ebx,1 add edi,ebx inc esi jmp .for0 .done: pop ecx ret align 4 text db 'ababba',0 align 4 keys dd a,b,0 align 4 a dd 0,0,0,0,0,0,0,0 dd 0,0,0,0,0,0,0,0 dd 0,0,1,1,1,0,0,0 dd 0,0,0,0,0,1,0,0 dd 0,0,1,1,1,1,0,0 dd 0,1,0,0,0,1,0,0 dd 0,1,0,0,0,1,0,0 dd 0,0,1,1,1,0,1,0 b dd 0,1,1,0,0,0,0,0 dd 0,0,1,0,0,0,0,0 dd 0,0,1,0,0,0,0,0 dd 0,0,1,0,1,1,1,0 dd 0,0,1,1,0,0,0,1 dd 0,0,1,0,0,0,0,1 dd 0,0,1,1,0,0,0,1 dd 0,1,1,0,1,1,1,0 lines i just adapted are marked by ;;;;;;;;;;;;;;;;; it work for me, then, i cannot tell you why it don't work for you. maybe the rest of the code of the os is the source of the problem. ('b' overwritten)
|
||||||||||
05 Mar 2011, 20:59 |
|
JohnFound 06 Mar 2011, 07:35
off topic: It is really weird way to use dword for every pixel in the font. If normally one pixel uses 1bit - then you are using 32 times more memory than is needed. Assembly programs should be small fast and beautiful.
Regards |
|||
06 Mar 2011, 07:35 |
|
DOS386 06 Mar 2011, 09:31
Quote: it work for me Horrible MEVDM and even en francais JohnFound wrote: off topic: It is really weird way to use dword for every pixel in the font. If normally one pixel uses 1bit already pointed, see above |
|||
06 Mar 2011, 09:31 |
|
edfed 06 Mar 2011, 12:16
Quote: Horrible MEVDM and even en francais just made the original code works under DOS. i don't see the horrible problem. |
|||
06 Mar 2011, 12:16 |
|
Teehee 07 Mar 2011, 18:05
Guys it is working!!!
The 'b' were overriden bc i do not loaded the 3º sector Thank you very much!!!! |
|||
07 Mar 2011, 18:05 |
|
DOS386 08 Mar 2011, 03:22
Teehee wrote: whats BPSL? WtF ??? Did you write the code ? You don't know why you did put in the "1280*4" ? Teehee wrote: Guys it is working!!! COOL Quote: The 'b' were overriden bc i do not loaded the 3º sector As suspected |
|||
08 Mar 2011, 03:22 |
|
Teehee 08 Mar 2011, 11:09
DOS386 wrote: WtF ??? Did you write the code ? You don't know why you did put in the "1280*4" ? first time i read i didn't assign the bpsl with bytes per scan line _________________ Sorry if bad english. |
|||
08 Mar 2011, 11:09 |
|
Teehee 09 Mar 2011, 22:20
DOS386 wrote: Reduce 32 to 8, later to 1 Can anyone give an example of how to work with a font bit-to-bit? if i let my font in 'db', i will lost ~16kb ;/ _________________ Sorry if bad english. |
|||
09 Mar 2011, 22:20 |
|
edfed 09 Mar 2011, 22:31
http://board.flatassembler.net/topic.php?p=63088#63088
it is not the last state of this font, but it is the only one that is still loaded here, and not for fool. to use it, just include it in your source, and call txt, with esi pointing to the string and (txt.x, txt.y) set to the coordinates you want. there is a version somewhere for vesa, search for "fbrowser contest" in os construction. |
|||
09 Mar 2011, 22:31 |
|
Teehee 09 Mar 2011, 22:35
thanks, i will check.
|
|||
09 Mar 2011, 22:35 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.