; ---- File Routines for Ultrabasic
; ---- Gabriel Fernandez
; ---- You are not allowed to use this code without permission

; ---- CLS
CLS:
  CMP dword [screenmode], 0
  JNE Othermodecls
  MOV [push1], EDI
  mov edi, [textscreenoffset]
  mov ecx, 2000
  xor al, al
  mov ah, [screencolor]
  rep stosw
  mov word [textx], 0
  mov word [texty], 0
  MOV EDI, [push1]
  RET
Othermodecls:
  RET
RET     ; END CLS

; ---- PRINT
; EAX = String Offset

Print:
  CMP word [texty], 25
  JNE dontscrollscreen
    mov esi, [textscreenoffset]
    add esi, 160
    mov edi, [textscreenoffset]
    PUSH EAX

    MOV ecx, 960  ; Scroll screen
    CLD
    REP MOVSD     ;

    mov al, [screencolor]
    mov ah, 0

    MOV ecx, 80
    REP STOSW

    MOV word [texty], 24
    POP EAX
dontscrollscreen:
  xor edi, edi
  mov ecx, [eax]
  Cmp ecx, 0
  Je skipprint
  mov di, [texty]
  mov bx, [texty]
  shl di, 4
  shl bx, 6
  mov dx, [textx]
  add di, bx
  shl di, 1
  shl dx, 1
  add di, dx
  add edi, [textscreenoffset]
  add eax, 4
  mov bh, [screencolor]
PrintNextChar:
  dec ecx
  mov bl, [eax]
  mov [edi], bl
  mov [edi+1], bh
  add edi, 2
  inc eax
CMP ecx, 0
jne PrintNextChar
  MOV EDI, [varedi]
  inc word [texty]
  mov word [textx], 0
skipprint:
RET  ; END Print
