Page 1 of 1

Setting cursor loaction - Review my asm code

Posted: Sun Apr 25, 2010 10:55 pm
by TylerH
I want to post my cursor managing code to the wiki, because it annoys me when there isn't an asm example. Tell me what you think.
The cursor is updated from the col and row variables, I did it that way instead of passing args because the need for variables to keep up with columns and rows already exists for many other reasons.

Code: Select all

update_cursor_pos:
   push      ebp
   mov       ebp,esp
   pushad
   xor       eax,eax
   mov       al,[row]             ; Get new row
   mov       dl,80
   mul       dl                   ; row*80
   add       al,[col]             ; row*80+col
   mov       [pos],ax             ; pos=row*80+col
   mov       al,0fh
   mov       dx,[vid_ctrl_reg]
   out       dx,al                ; Set video reg to f
   mov       ax,[pos]
   and       al,0ffh
   mov       dx,[vid_out_reg]
   out       dx,al                ; Access video reg f
   mov       al,0eh
   mov       dx,[vid_ctrl_reg]
   out       dx,al                ; Set video reg to e
   mov       ax,[pos]
   mov       al,ah
   and       al,0ffh
   mov       dx,[vid_out_reg]
   out       dx,al                ; Access video reg e
   popad
   mov       esp,ebp
   pop       ebp
   ret

vid_ctrl_reg       dw 3d4h
vid_out_reg        dw 3d5h
col                db 0
row                db 0
pos                dw 0                   

Re: Setting cursor loaction - Review my asm code

Posted: Mon Apr 26, 2010 1:18 am
by earlz
TylerAnon wrote:I want to...
Not to say that adding more code is bad, but I think it's trivial to convert the C code already there to assembly. I think adding assembly code to it just complicates the page for no real gain.

Re: Setting cursor loaction - Review my asm code

Posted: Mon Apr 26, 2010 1:37 am
by TylerH
Okay, I'll leave the page as it is...