Author Topic: I'm writing a asm console lib that i hope will one day will be as good as ncurs  (Read 2312 times)

Offline brethren

  • Jr. Member
  • *
  • Posts: 28
could you see if you can improve on the code?
Code: [Select]
extern kernel_syswrite

section .data

GotoStr db 27,"[00;00H" ;<ESC>[<Y>;<X>H

section .text
global goto_xy
;--------------------------------------------------------------------
;goto_xy: position the cursor at x,y coordinates
;input: ax (ah=X value, al=Y value)
;limitations: coordinates must be in the range 0-99
;--------------------------------------------------------------------
goto_xy:
push eax ;store regs altered by proc
push ecx
push edx
;info: if you store a coordinate in ax (say the Y coordinate) and it
; is between 0-99 all you have to do is divide ax by 10 and then
; add 3030h to ax to turn it into 2 ascii chars ready for
; inserting into the control string.
mov dl,10 ;the divisor
mov cl,ah ;save x coordinate for later
mov ah,0 ;isolate y coordinate
div dl ;y coordinate is now 2 single
;digits in ah,al
add ax,3030h ;transform digits to ascii chars
mov [GotoStr+2],ax ;insert chars into control string
movzx ax,cl ;move x coordinate into ax
div dl ;x coordinate is now 2 digits in ah,al
add ax,3030h ;transform into ascii chars
mov [GotoStr+5],ax ;insert chars into control string

mov ecx,GotoStr ;offset of control string
mov edx,8 ;length of control string
call kernel_syswrite ;move the cursor!

pop edx
pop ecx
pop eax ;restore regs altered by proc

ret


Code: [Select]
section .text
global kernel_syswrite
;-----------------------------------------------------------------------
;kernel_syswrite: set up eax,ebx and make the kernel call
;input: ecx contains a string pointer and edx
; contains the string length
;-----------------------------------------------------------------------
kernel_syswrite:
push eax ;save all registers altered by the proc
push ebx

mov eax,4 ;sys_write
mov ebx,1 ;file descriptor 1-standard output
int 80h ;call into kernel

pop ebx
pop eax ;restore all registers altered by the proc

ret


this is only the goto_xy proc but i'm hoping better coders than me can improve on it. Also my main purspose is to write a console based gui lib with optimized code available to anyone under a permissive license

btw are there any more control strings i can use for changing text colour etc that are work with the other shells
« Last Edit: March 03, 2010, 07:39:01 PM by brethren »