New font engine in progress

git-svn-id: svn://kolibrios.org@2461 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Artem Jerdev (art_zh) 2012-03-15 01:02:08 +00:00
parent 91f85b6476
commit 30883bfc24
3 changed files with 260 additions and 229 deletions

View File

@ -47,7 +47,7 @@ syscall_entry:
; sti ; sti
push ecx push ecx
xor ecx, ecx xor ecx, ecx
mov cl, al mov cl, al ; keep subfn# in ah
and cl, 7 and cl, 7
call dword [servetable3 + ecx * 4] call dword [servetable3 + ecx * 4]
pop ecx pop ecx

View File

@ -141,341 +141,363 @@ diff10 "old font code size",dtext,$
align 8 align 8
sdsh_data: sdsh_data:
diff16 "sdsh_data : ",0,$
include 'fonts/sd_data.asm' include 'fonts/sd_data.asm'
sdsh_code: sdsh_code:
; eax = if (bit[31]) ; eax = if (bit[31])
; then lower 31 bits points to the user-selected font ; then lower 31 bits points to the user-selected font
; else ax = number of preloaded system font ; else ax = number of preloaded system font
; ebx = x<<16 + y ; ebx = x<<16 + y
; ecx = 0x00RRGGBB ; ecx = 0x00RRGGBB
; edx = if (bits[31:8] == 0) ; edx = if (bits[31:8] == 0)
; then dl = single char to write ; then dl = single char to write
; else edx= pointer to asciiz-string ; else edx= pointer to asciiz-string
diff16 "draw_char : ",0,$
draw_char: draw_char:
; font test ; font test
; bl=y; bh=x ; bl=y; bh=x
; dl=ascii ; dl=ascii
movzx eax, bh movzx eax, bh
movzx ebx, bl movzx ebx, bl
movzx ecx, dl movzx ecx, dl
xor edi, edi xor edi, edi
mov ebp, edi mov ebp, edi
sdsh_draw_char: sdsh_draw_char:
; eax = left side X ; eax = left side X
; ebx = bottom Y ; ebx = bottom Y
; edi = color 0x0RRGGBB ; edi = color 0x0RRGGBB
; ebp = font@ ; ebp = font@
; ecx = ascii, zero-extended to 32bits ; ecx = ascii, zero-extended to 32bits
push ecx push ecx
push edx push edx
push ebp push ebp
shl ebp, 4 shl ebp, 4
add ebp, sdsh_data.info add ebp, sdsh_data.info
call ch_checkscreen ; call ch_checkscreen
jb .exit ; jb .exit
call ch_checkwin ; call ch_checkwin
jc .exit ; jc .exit
xor ch, ch mov edx, [ebp + 4] ; chartable addr
mov edx, [ebp + 4] ; chartable addr mov cx, word[edx + ecx*2] ; tick info
mov cx, word[edx + ecx*2] ; tick info mov edx, ecx
mov edx, ecx and ecx, 7 ; cl = number of ticks
and ecx, 7 ; cl = number of ticks jz .blank
jz .blank shr edx, 4 ; offset in the chartable
shr edx, 4 ; offset in the chartable add edx, sdsh_data.chars ; edx -> the char's ticklist
add edx, [sdsh_data.chars] ; edx -> the char's ticklist
.next_tick: .next_tick:
call parse_tick call parse_tick
add edx, 4 add edx, 2
dec cl dec cl
jnz .next_tick jnz .next_tick
.blank: .blank:
.exit: .exit:
pop ebp pop ebp
pop edx pop edx
pop ecx pop ecx
ret ret
parse_tick: parse_tick:
diff16 "parse_tick : ",0,$
; eax = left side X ; eax = left side X
; ebx = bottom Y ; ebx = bottom Y
; edx ->tickinfo ; edx ->tickinfo
; edi = color 0x0RRGGBB ; edi = color 0x0RRGGBB
; ebp = font's header ; ebp = font's header
pushad pushad
xor ecx, ecx xor ecx, ecx
mov dx, word[edx] mov dx, word[edx]
mov cl, dl mov cl, dl
test dl, 0xE0 ; ticks #32..255 test dl, 0xE0 ; ticks #32..255
jz .lntick.short jz .lntick.short
cmp dl, 0xE0 cmp dl, 0xE0
jae .lntick.long jae .lntick.long
cmp dl, 0xC0 cmp dl, 0xC0
jae .cstick jae .cstick
.gptick: .gptick:
push edx push edx
mov cl, dh mov cl, dh
shr cl, 3 ; orig.# shr cl, 3 ; orig.#
mov edx, [ebp+8] ; orig. table mov edx, [ebp+8] ; orig. table
mov ch, byte[edx+ecx] ; orig. coords mov ch, byte[edx+ecx] ; orig. coords
pop edx pop edx
mov cl, dh mov cl, dh
and cl, 7 ; three rotation bits and cl, 7 ; three rotation bits
and edx, 0xFF ; dl = gptick# and edx, 0xFF ; dl = gptick#
sub dl, 32 sub dl, 32
cmp dl, (sdsh_data.v5-sdsh_data.v1) cmp dl, (sdsh_data.v5-sdsh_data.v1)
jae .gptick.2 jae .gptick.2
.gptick.1: .gptick.1:
mov esi, sdsh_data.tick_table mov esi, sdsh_data.tick_table
add esi, edx ; 1-byte tickgroups .v1-v4: add esi, edx ; 1-byte tickgroups .v1-v4:
inc dh inc dh
sub dl, 2 ; .v1 : 2 ticks only (#32, 33) sub dl, 2 ; .v1 : 2 ticks only (#32, 33)
jae @f jae @f
mov dl, dh mov dl, dh
jmp .gptick.done jmp .gptick.done
@@: inc dh @@: inc dh
shr dl, 3 ; tickgroups .v2-v4 : 8 ticks each shr dl, 3 ; tickgroups .v2-v4 : 8 ticks each
add dl, dh add dl, dh
jmp .gptick.done jmp .gptick.done
.gptick.2: .gptick.2:
sub dl, (sdsh_data.v5-sdsh_data.v1) sub dl, (sdsh_data.v5-sdsh_data.v1)
cmp dl, (sdsh_data.v9-sdsh_data.v5) cmp dl, (sdsh_data.v9-sdsh_data.v5)
jae .gptick.3 jae .gptick.3
mov esi, sdsh_data.v5 mov esi, sdsh_data.v5
lea esi, [esi+edx*2] ; 2-byte tickgroups .v5-v8: 8 ticks each lea esi, [esi+edx*2] ; 2-byte tickgroups .v5-v8: 8 ticks each
mov dh, 5 mov dh, 5
shr dl, 3 shr dl, 3
add dl, dh add dl, dh
jmp .gptick.done jmp .gptick.done
.gptick.3: .gptick.3:
sub dl, (sdsh_data.v9-sdsh_data.v5) sub dl, (sdsh_data.v9-sdsh_data.v5)
cmp dl, (sdsh_data.v13-sdsh_data.v9) cmp dl, (sdsh_data.v13-sdsh_data.v9)
jae .gptick.4 jae .gptick.4
mov esi, sdsh_data.v9 mov esi, sdsh_data.v9
lea esi,[esi+edx*2] lea esi,[esi+edx*2]
add esi, edx ; 3-byte tickgroups .v9-12: 4 ticks each add esi, edx ; 3-byte tickgroups .v9-12: 4 ticks each
mov dh, 9 mov dh, 9
shr dl, 2 shr dl, 2
add dl, dh add dl, dh
jmp .gptick.done jmp .gptick.done
.gptick.4: .gptick.4:
sub dl, (sdsh_data.v13-sdsh_data.v9) sub dl, (sdsh_data.v13-sdsh_data.v9)
cmp dl, 16 cmp dl, 16
jae .exit jae .exit
mov esi, sdsh_data.v13 mov esi, sdsh_data.v13
lea esi,[esi+edx*4] ; 4-byte tickgroups .v13-16: 4 ticks each lea esi,[esi+edx*4] ; 4-byte tickgroups .v13-16: 4 ticks each
mov dh, 13 mov dh, 13
shr dl, 2 shr dl, 2
add dl, dh add dl, dh
.gptick.done: .gptick.done:
mov dh, ch ; dh = orig.XY; dl = numvert mov dh, ch ; dh = orig.XY; dl = numvert
jmp .draw ; cl = rotation jmp .draw ; cl = rotation
.cstick: .cstick:
and cl, 4 and cl, 4
shr cl, 2 ; only one rotational bit shr cl, 2 ; only one rotational bit
and dl, 3 and dl, 3
inc dl inc dl
dec dl dec dl
jz .cstick.0 jz .cstick.0
dec dl dec dl
jnz @f jnz @f
mov dl, 6 mov dl, 6
jz .cstick.1 jz .cstick.1
@@: dec dl @@: dec dl
jz .cstick.2 jz .cstick.2
.cstick.3: .cstick.3:
mov esi, sdsh_data.cs3 ; 12pix-ring mov esi, sdsh_data.cs3 ; 12pix-ring
mov dl, 10 mov dl, 10
jmp .draw jmp .draw
.cstick.2: .cstick.2:
mov dl, 7 mov dl, 7
.cstick.1: .cstick.1:
mov esi, sdsh_data.cs2 ; the square mov esi, sdsh_data.cs2 ; the square
jmp .draw jmp .draw
.cstick.0: .cstick.0:
mov esi, sdsh_data.cs0 ; 4pix-square mov esi, sdsh_data.cs0 ; 4pix-square
mov dl, 3 mov dl, 3
jmp .draw jmp .draw
.ritick: .ritick:
test dl, 1 test dl, 1
jnz .ritick.1 jnz .ritick.1
.ritick.0: .ritick.0:
mov cl, dh ; y mov cl, dh ; y
and cl, 0x0F and cl, 0x0F
sub ebx, ecx sub ebx, ecx
mov cl, dh mov cl, dh
shr cl, 4 ; x shr cl, 4 ; x
add eax, ecx add eax, ecx
call ch_putpixel call ch_putpixel
jmp .exit jmp .exit
.ritick.1: .ritick.1:
mov esi, sdsh_data.ri1 ; 8pix-ring mov esi, sdsh_data.ri1 ; 8pix-ring
mov dl, 4 mov dl, 4
xor cl, cl xor cl, cl
jmp .draw jmp .draw
.lntick.short: .lntick.short:
test dl, 0x06 ; ticks #0, 1 are reserved for test dl, 0x06 ; ticks #0, 1 are reserved for
jz .ritick ; rotational invariants jz .ritick ; rotational invariants
and dl, 0x07 ; dl = line length and dl, 0x07 ; dl = line length
jmp .lntick.both jmp .lntick.both
.lntick.long: .lntick.long:
and dl, 0x07 and dl, 0x07
add dl, 8 add dl, 8
.lntick.both: .lntick.both:
sub dl, 2 ; num_vertice = num_points - 2 sub dl, 2 ; num_vertice = num_points - 2
and cl, 0x18 ; two rotation bits and cl, 0x18 ; two (lower) rotation bits
shr cl, 3 shr cl, 3
mov esi, sdsh_data.blank mov esi, sdsh_data.blank
.draw: .draw:
; cl = rot; dl = numvert; dh = orig.xy ; cl = rot; dl = numvert; dh = orig.xy
push ecx push ecx
mov cl, dh ; y mov cl, dh ; y
and cl, 0x0F and cl, 0x0F
sub ebx, ecx sub ebx, ecx
mov cl, dh mov cl, dh
shr cl, 4 ; x shr cl, 4 ; x
add eax, ecx add eax, ecx
pop ecx pop ecx
call draw_tick call draw_tick
.gptick.5: .gptick.5:
.exit: .exit:
popad popad
ret ret
diff16 "draw_tick : ",0,$
draw_tick: draw_tick:
; eax = x-origin ; eax = x-origin
; ebx = y-origin ; ebx = y-origin
; edi = 0x0RRGGBB ; edi = 0x0RRGGBB
; cl = direction (0..7) ; cl = direction (0..7)
; dl = number of vertices (dl) ; dl = number of vertice (dl)
; esi -> tick bitfield ; esi -> tick bitfield
pushad pushad
inc dl ; -- that's to count down to 0 call ch_putpixel ; the point of origin
call ch_putpixel ; the point of origin and ecx, 7
and ecx, 7 lea ebp, [.move000+ ecx*4]
call [.moves + ecx*4] ; basic vector call ebp ; basic vector
call ch_putpixel call ch_putpixel
dec dl and edx, 15
jz .done ; 2pix lines only jz .done ; no vertex (2pix line)
mov esi, dword [esi] ; max 16 vertice bitfield limit mov esi, dword [esi] ; 15 vertice will easily fit to 1dw
xchg esi, edx xchg esi, edx
.move_and_draw: .move_and_draw:
mov ch, dl mov ch, dl
and ch, 3 and ch, 3
jz .moved jz .moved
btc ecx, 8 dec ch
jz .2 jz .1
dec ch
jz .2
.3:
dec cl
.1: .1:
dec cl ; right turns (1 and 3) dec cl
and cl, 7 jmp .wipe_it
@@: btc ecx, 9 ; straight angle (3) ?
jc .1
jmp .moved
.2: .2:
inc cl ; left turn (2) inc cl
and cl, 7 .wipe_it:
btc ecx, 9 ; just to zero ah and ecx, 7
.moved: .moved:
call [.moves + ecx*4] ; go new way diff16 "moved : ",0,$
call ch_putpixel lea ebp, [.move000+ ecx*4]
shr edx, 2 call ebp ; go new way
dec esi call ch_putpixel
jnz .move_and_draw shr edx, 2
dec esi
jnz .move_and_draw
diff16 "done : ",0,$
.done: .done:
popad popad
ret ret
; WARNING! The order matters! ------
align 4
diff16 "move000 : ",0,$
.move000: .move000:
inc eax inc eax
ret ret
align 4
.move001: .move001:
inc eax inc eax
dec ebx dec ebx
ret ret
align 4
.move010: .move010:
dec ebx dec ebx
ret ret
align 4
.move011: .move011:
dec eax dec eax
dec ebx dec ebx
ret ret
align 4
.move100: .move100:
dec eax dec eax
ret ret
align 4
.move101: .move101:
dec eax dec eax
inc ebx inc ebx
ret ret
align 4
.move110: .move110:
inc ebx inc ebx
ret ret
align 4
diff10 "move111-move000 (must be 28!) : ",.move000,$
.move111: .move111:
inc eax inc eax
inc ebx inc ebx
ret ret
align 4 ;) ---------------
.moves dd .move000, .move001, .move010, .move011, .move100, .move101, .move110, .move111
;)
align 4 align 4
diff16 "checkscreen : ",0,$
ch_checkscreen: ch_checkscreen:
cmp [Screen_Max_X], eax cmp [Screen_Max_X], eax
jb .getout jb .getout
cmp [Screen_Max_Y], ebx cmp [Screen_Max_Y], ebx
.getout: .getout:
ret ret
align 4 align 4
diff16 "checkwin : ",0,$
ch_checkwin: ch_checkwin:
; eax = x coordinate ; eax = x coordinate
; ebx = y coordinate ; ebx = y coordinate
; ebp -> font info ; ebp -> font info
;!destroys ch, edx! ;!destroys ch, edx!
push eax push eax
push ebx push ebx
mov ch, byte[CURRENT_TASK] mov ch, byte[CURRENT_TASK]
mov al, byte [ebp] ; char X-width mov al, byte [ebp] ; char X-width
mov edx, [_display.width] ; screen X-size mov edx, [_display.width] ; screen X-size
imul edx, ebx imul edx, ebx
add edx, [_WinMapAddress] add edx, [_WinMapAddress]
add edx, eax add edx, eax
cmp ch, byte [edx] cmp ch, byte [edx]
jne .fail jne .fail
movzx eax, byte [ebp] movzx eax, byte [ebp]
cmp ch, byte [edx+eax] cmp ch, byte [edx+eax]
jne .fail jne .fail
movzx ebx, byte [ebp+1] movzx ebx, byte [ebp+1]
imul ebx, [_display.width] imul ebx, [_display.width]
cmp ch, byte [edx+ebx] cmp ch, byte [edx+ebx]
jne .fail jne .fail
add edx, eax add edx, eax
cmp ch, byte [edx+ebx] cmp ch, byte [edx+ebx]
clc clc
je .done je .done
.fail: .fail:
stc ; CF means the charbox is invisible stc ; CF means the charbox is invisible
.done: .done:
pop ebx pop ebx
pop eax pop eax
ret ret
align 4 align 4
diff16 "ch_putpix : ",0,$
ch_putpixel: ch_putpixel:
; eax = x coordinate ; eax = x coordinate
; ebx = y coordinate ; ebx = y coordinate
; edi = 0x0RRGGBB ; edi = 0x0RRGGBB
push edx push edx
mov edx, ebx mov edx, ebx
imul edx, [BytesPerScanLine] imul edx, [BytesPerScanLine]

View File

@ -99,6 +99,9 @@ align 4
db 0x30 ; 30 db 0x30 ; 30
align 4 align 4
diff16 "sdsh_data.tick_table: ",0,$
.tick_table: .tick_table:
.v1: .v1:
; 32 33 ; 32 33
@ -210,6 +213,9 @@ align 4
align 4 align 4
.table0: .table0:
diff16 "sdsh_data.table0: ",0,$
times 33 dw 0 times 33 dw 0
dw (.ch0_33 -.chars)*16 + 2 ; #33 ! dw (.ch0_33 -.chars)*16 + 2 ; #33 !
dw (.ch0_34 -.chars)*16 + 2 ; #34 " dw (.ch0_34 -.chars)*16 + 2 ; #34 "
@ -422,6 +428,9 @@ diff10 "check font0 table size: ", .table0, $
; ---------------------------------------------------- ; ----------------------------------------------------
align 4 align 4
diff16 "sdsh_data.chars: ",0,$
.chars: .chars:
dw 0 dw 0
.ch0_33: ; ! .ch0_33: ; !