Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ; --------------------------------------------------------------------------
  2. ; FILE: TLog.Asm
  3. ; DATE: February 21, 2009
  4. ; --------------------------------------------------------------------------
  5.  
  6. ; --------------------------------------------------------------------------
  7. align PROC_ALIGN
  8. TLog_Create:
  9.     invoke  HeapAlloc, [glb_Allocator], HEAP_NO_SERIALIZE, TLog.size
  10.     mov     [glb_pLog], eax
  11.  
  12.     mov     edi, eax
  13.     mcZeroBits eax
  14.  
  15.     mov     [edi + TLog.nRemainChars], eax
  16.     mov     [edi + TLog.nStoredChars], eax
  17.     mov     [edi + TLog.pCurrentBufPos], eax
  18.  
  19.     invoke  VirtualAlloc, 0, MAX_LOG_ROOM, MEM_COMMIT or MEM_RESERVE, PAGE_READWRITE
  20.     mov     [edi + TLog.pBuffer], eax
  21.     ret
  22.  
  23. ; --------------------------------------------------------------------------
  24. align PROC_ALIGN
  25. TLog_Enable:
  26.     invoke  CreateFile, str_LogFileName, GENERIC_WRITE, \
  27.             0, 0, CREATE_ALWAYS, FILE_FLAG_SEQ_SCAN, 0
  28.  
  29.     invoke  CloseHandle, eax
  30.  
  31.     mov     edi, [glb_pLog]
  32.     mcZeroBits eax
  33.     mov     edx, MAX_LOG_ROOM
  34.     mov     ebx, [edi + TLog.pBuffer]
  35.  
  36.     mov     [edi + TLog.nRemainChars], edx
  37.     mov     [edi + TLog.nStoredChars], eax
  38.     mov     [edi + TLog.pCurrentBufPos], ebx
  39.     ret
  40.  
  41. ; --------------------------------------------------------------------------
  42. align PROC_ALIGN
  43. TLog_Backspace:
  44.     cmp     [glb_LogEnabled], 1
  45.     je      .do_it
  46.     ret
  47.  
  48. .do_it:
  49.     mov     esi, [glb_pLog]
  50.     cmp     [esi + TLog.nStoredChars], 0
  51.     je      .print_backspace
  52.  
  53.     dec     [esi + TLog.nStoredChars]
  54.     dec     [esi + TLog.pCurrentBufPos]
  55.     inc     [esi + TLog.nRemainChars]
  56.     ret
  57.  
  58. .print_backspace:
  59.     mov     al, '\'
  60.     call    TLog_DumpChar
  61.     mov     al, 'B'
  62.     call    TLog_DumpChar
  63.     mov     al, 'S'
  64.     call    TLog_DumpChar
  65.     mov     al, 'P'
  66.     call    TLog_DumpChar
  67.     mov     al, '\'
  68.     call    TLog_DumpChar
  69.     ret
  70.  
  71. ; --------------------------------------------------------------------------
  72. align PROC_ALIGN
  73. TLog_Disable:
  74.     cmp     [glb_LogEnabled], 1
  75.     je      .do_it
  76.     ret
  77.  
  78. .do_it:
  79.     call    TLog_Flush
  80.     ret
  81.  
  82. ; --------------------------------------------------------------------------
  83. align PROC_ALIGN
  84. TLog_Flush:
  85.     mov     esi, [glb_pLog]
  86.     mov     ecx, [esi + TLog.nStoredChars]
  87.     jecxz   .done
  88.  
  89.     invoke  CreateFile, str_LogFileName, GENERIC_WRITE, \
  90.             0, 0, OPEN_EXISTING, FILE_FLAG_SEQ_SCAN, 0
  91.  
  92.     mov     ebx, eax
  93.     invoke  SetFilePointer, eax, 0, 0, 2
  94.  
  95.     invoke  WriteFile, ebx, [esi + TLog.pBuffer], [esi + TLog.nStoredChars], glb_FPU_Int32, 0
  96.     invoke  CloseHandle, ebx
  97.  
  98.     mcZeroBits eax
  99.     mov     edx, MAX_LOG_ROOM
  100.     mov     ebx, [esi + TLog.pBuffer]
  101.  
  102.     mov     [esi + TLog.nRemainChars], edx
  103.     mov     [esi + TLog.nStoredChars], eax
  104.     mov     [esi + TLog.pCurrentBufPos], ebx
  105.  
  106. .done:
  107.     ret
  108.  
  109. ; --------------------------------------------------------------------------
  110. ; Input:
  111. ;   AL = character to append into log buffer.
  112. ; --------------------------------------------------------------------------
  113. align PROC_ALIGN
  114. TLog_DumpChar:
  115.     cmp     [glb_LogEnabled], 1
  116.     je      .do_it
  117.     ret
  118.  
  119. .do_it:
  120.     mcOnRegZero al, .do_backspace
  121.  
  122.     mov     esi, [glb_pLog]
  123.     cmp     [esi + TLog.nRemainChars], 0
  124.     jne     .dump
  125.  
  126.     push    eax
  127.     call    TLog_Flush
  128.     pop     eax
  129.     mov     esi, [glb_pLog]
  130.  
  131. .dump:
  132.     mov     edi, [esi + TLog.pCurrentBufPos]
  133.     stosb
  134.     mov     [esi + TLog.pCurrentBufPos], edi
  135.     inc     [esi + TLog.nStoredChars]
  136.     dec     [esi + TLog.nRemainChars]
  137.     ret
  138.  
  139. .do_backspace:
  140.     call    TLog_Backspace
  141.     ret
  142.  
  143. ; --- EOF ---
  144.