Metropoli BBS
VIEWER: print.asm MODE: TEXT (ASCII)
include qlib.inc  ;setup
include dos.inc
include string.inc
include conio.inc
include stdio.inc

.code
print proc,off:dword
  callp fprint,stdout,off
  ret
print endp

fprint proc,dev:byte,off:dword
  callp strlen,off
  or eax,eax
  jnz @f
  ret  ;eax=0
@@:
  pushad
  mov ecx,eax
  mov esi,off
@@:
  lodsb
  .if al==13 ;in case there is a 13,10 (we don't want the 10 to for count 2)
    lodsb
    .if !al
      jmp cont
    .endif
    jmp @b
  .elseif al==10
    inc ecx  ;CR + LF
    jmp @b
  .elseif al
    jmp @b
  .endif
cont:
  sub esp,ecx
  mov esi,off
  mov edi,esp
@@:
  lodsb
  .if al==13
    stosb
    lodsb    ;it may be 10
    .if !al
      jmp done
    .endif
    stosb
    jmp @b
  .elseif al==10
    mov al,13
    stosb
    mov al,10
    stosb
    jmp @b
  .elseif al
    stosb
    jmp @b
  .endif
done:
  mov eax,esp
  callp write,dev,eax,ecx  ;handle , offset , size
  add esp,ecx
  popad
  xor eax,eax
  ret
fprint endp

printxy proc,x:word,y:word,off:dword
  pushad
  callp gotoxy,x,y
  callp print,off
  popad
  xor eax,eax
  ret
printxy endp

end

[ RETURN TO DIRECTORY ]