Author Topic: Cls  (Read 408 times)

jj2007

  • Member
  • *****
  • Posts: 9794
  • Assembler is fun ;-)
    • MasmBasic
Cls
« on: May 24, 2019, 12:50:43 PM »
Subsystem console, please:
Code: [Select]
include \masm32\include\masm32rt.inc ; plain Masm32 for the fans of pure assembler

Cls MACRO
Local csbiMB, coordScreenMB, dwConSizeMB
  push ebx
  push esi
  sub esp, COORD+CONSOLE_SCREEN_BUFFER_INFO+8
  mov ebx, esp
  csbiMB equ [ebx.CONSOLE_SCREEN_BUFFER_INFO]
  coordScreenMB equ [CONSOLE_SCREEN_BUFFER_INFO+ebx.COORD]
  dwConSizeMB equ [CONSOLE_SCREEN_BUFFER_INFO+COORD+ebx]
  xchg rv(GetStdHandle, STD_OUTPUT_HANDLE), esi
  .if esi
.if rv(GetConsoleScreenBufferInfo, esi, ebx)
movzx eax, csbiMB.dwSize.x ; dwConSizeMB = csbiMB.dwSize.X * csbiMB.dwSize.Y
mul csbiMB.dwSize.y
push eax ; create the charswritten slot
and coordScreenMB, 0
invoke FillConsoleOutputCharacter, esi, 32, eax, coordScreenMB, esp
pop edx ; charswritten
.if rv(GetConsoleScreenBufferInfo, esi, ebx)
push eax ; slot
invoke FillConsoleOutputAttribute, esi, csbiMB.wAttributes, dwConSizeMB, coordScreenMB, esp
pop edx
invoke SetConsoleCursorPosition, esi, coordScreenMB
.endif
.endif
  .endif
  add esp, COORD+CONSOLE_SCREEN_BUFFER_INFO+8
  pop esi
  pop ebx
ENDM

.code
start: inkey "Hello World - hit any key to clear the screen"
Cls
MsgBox 0, "did it work?", "Cls", MB_OK or MB_SETFOREGROUND
exit

end start