
; Debugging Module (c) [yAtEs]
; v4

;v1: basic
;v2: datablocks
;v3: listbox support


DBG_MSGS EQU 1
.data

fbox  db  'My First Prog',0
ftitle db 'www.yates2k.co.uk',0
formath db '%08X',0
formatd db '%lu',0

dbgdata db 200 dup(0)
charout db 0Fh dup(0)

bcharout db 0Fh dup(0)

debug_file  db 'debug.txt',0

charspace db ' ',0
newline db 13,10,0

dbgfhandle  dd ?

LBHANDLE dd ?
LBHANDLE2 dd ?

.code


;--------------------------------------------------------------
dbg_string   PROC NEAR STRING:DWORD
pushad
 
IF DBG_MSGS

  
 call    lstrlen, [STRING]
 mov ebx,eax
 
 mov edi,o [STRING]
 
 call lstrcat,o dbgdata,edi

ENDIF
popad
 ret
dbg_string   ENDP
;--------------------------------------------------------------





;--------------------------------------------------------------
dbg_dword   PROC NEAR HEX:DWORD, DBGFORMAT:BYTE
pushad
 
IF DBG_MSGS


 mov ebx,[HEX]
 cmp [DBGFORMAT],0
 je hex_dump
 
 Call _wsprintfA,offset charout,offset formatd,ebx
 add esp,0Ch
 
 jmp o_hex_dump
 
;---------------------- 
 hex_dump:
 
 Call _wsprintfA,offset charout,offset formath,ebx
 add esp,0Ch
;----------------------


 o_hex_dump:
 
mov eax,o charout
call lstrcat,o dbgdata,eax


ENDIF
popad
 ret
dbg_dword   ENDP
;--------------------------------------------------------------



move_screen	PROC
pushad

  call SendMessageA,LBHANDLE2,018Bh,0,0  ;LB_GETCOUNT
  sub eax,2
  call SendMessageA,LBHANDLE2,0186h,eax,0  ;LB_SETCURSEL
 
popad
ret
move_screen ENDP
  


;--------------------------------------------------------------
dbg_fileout   PROC   LINEFEED:DWORD
pushad
 
IF DBG_MSGS

  cmp [linefeed],1
  jne nlf
  mov edi,o newline
  call lstrcat,o dbgdata,edi
  nlf:

 

 call    CreateFileA, o debug_file, 40000000h,0, 0, 4, 80h, 0 ; 4 == open always
 mov [dbgfhandle],eax


 call    SetFilePointer, eax, 0, 0, 2, eax ; 2 == file end
 add esp,4

 call    lstrlen,o [dbgdata]
 mov ebx,eax
 

  mov eax, [dbgfhandle]
  
  call    WriteFile, eax,o [dbgdata], ebx,o bytesrw, 0, 0
  add esp,4
  mov eax,[STRING]


 mov eax, [dbgfhandle]
 call    CloseHandle,eax
 
 call RtlZeroMemory,o dbgdata,100

ENDIF
popad
 ret
dbg_fileout   ENDP
;--------------------------------------------------------------




;--------------------------------------------------------------
dbg_allout   PROC   LINEFEED:DWORD
pushad
 
IF DBG_MSGS


CALL SendDlgItemMessageA,LBHANDLE,500,180h,0,o dbgdata

  cmp [linefeed],1
  jne nlf1
  mov edi,o newline
  call lstrcat,o dbgdata,edi
  nlf1:

 

 call    CreateFileA, o debug_file, 40000000h,0, 0, 4, 80h, 0 ; 4 == open always
 mov [dbgfhandle],eax


 call    SetFilePointer, eax, 0, 0, 2, eax ; 2 == file end
 add esp,4

 call    lstrlen,o [dbgdata]
 mov ebx,eax
 

  mov eax, [dbgfhandle]
  
  call    WriteFile, eax,o [dbgdata], ebx,o bytesrw, 0, 0
  add esp,4
  mov eax,[STRING]


 mov eax, [dbgfhandle]
 call    CloseHandle,eax
 
 call RtlZeroMemory,o dbgdata,100

ENDIF
popad
 ret
dbg_allout   ENDP
;--------------------------------------------------------------



;--------------------------------------------------------------
dbg_screenout   PROC
pushad
 
IF DBG_MSGS


  CALL SendDlgItemMessageA,LBHANDLE,500,180h,0,o dbgdata

call RtlZeroMemory,o dbgdata,100
 
ENDIF
popad
 ret
dbg_screenout   ENDP
;--------------------------------------------------------------

;--------------------------------------------------------------
dbg_screenlf   PROC
pushad
 
IF DBG_MSGS


CALL SendDlgItemMessageA,LBHANDLE,500,180h,0,o charspace



 call    CreateFileA, o debug_file, 40000000h,0, 0, 4, 80h, 0 ; 4 == open always
 mov [dbgfhandle],eax


 call    SetFilePointer, eax, 0, 0, 2, eax ; 2 == file end
 add esp,4

 call    lstrlen,o [newline]
 mov ebx,eax
 

  mov eax, [dbgfhandle]
  
  call    WriteFile, eax,o [newline], ebx,o bytesrw, 0, 0
  add esp,4
  mov eax,[STRING]


 mov eax, [dbgfhandle]
 call    CloseHandle,eax
 
 call RtlZeroMemory,o dbgdata,100

ENDIF
popad
 ret
dbg_screenlf   ENDP
;-------------------------------------------------------------- 
 




dbg_vstring   PROC NEAR STRING:DWORD,VALUE:DWORD

ret
dbg_vstring   ENDP


dbg_space   PROC NEAR 
ret
dbg_space   ENDP




