; GRAB.ASM    - Grab Screen                     http://nxdos.sourceforge.net/
; ------------- Copyright 2007 Christopher Evans  Email:   teknopup@lycos.com
;
; -[version]-+-[date             ]-+-[notes                                ]-
;      1.0      8th 2007 October      Created grab screen grabber
; 

grab:
     _fopen grabfile, 1, 0, WO
     mov  ghandle, ax
     mov  ax, 0b800h
     push ax
     pop  es
     mov  si, 0
     mov  cx, 4000
     xor  ax, ax
     mov  di, ax
grabscrn:
     inc  di
     xor  ax, ax
     mov  al, byte ptr es:[si]  ; char
     inc  si
;     mov  ah, byte ptr es:[si] ; color
     mov  gbuf, ax
     pushregs
     _fwrite ghandle, gbuf, 1
     popregs
     mov  ax, di
     cmp  ax, 80
     jne  nograbcrlf    
     xor  ax, ax
     mov  di, ax
     mov  al, lf
     mov  gbuf, ax
     pushregs
     _fwrite ghandle, gbuf, 1
     mov  al, cr
     mov  gbuf, ax
     _fwrite ghandle, gbuf, 1
     popregs
nograbcrlf:
     inc  si
     loop grabscrn
     _fclose ghandle
     ret

grabfile db 'scrntext.txt',0
ghandle  dw ?
gbuf     dw ?


