Subversion Repositories Kolibri OS

Rev

Rev 9718 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; 2022, Edited by Coldy
  2. ; Added changes for auto load & linking
  3.  
  4. format binary as "kex"
  5.  
  6. use32
  7.         org     0x0
  8.         db      'MENUET01'      
  9.         dd      0x02          ; 2 - for enable autoload feature            
  10.         dd      START          
  11.         dd      IM_END          
  12.         dd      MEM  
  13.         dd      MEM
  14.         dd      0
  15.         dd      0
  16.        
  17.         ; { Begin of KX header (this need for recognition by dll.obj)
  18.        
  19.         db  'KX',0            ; Signature/Magic
  20.         db  0                 ; Revision
  21.         db  1000000b          ; Flags0  (user app w/import)
  22.         db  0                 ; Flags1
  23.         dw  0                 ; Reserved
  24.    
  25.         dd  @IMPORT           ; Pointer to import table
  26.        
  27.         ; } End of KX header
  28.  
  29. include '../../../../../../macros.inc'
  30. include '../../../../../../proc32.inc'
  31. include '../../../../../../KOSfuncs.inc'
  32.  
  33. ; no needed for autoload
  34. ;include '../../../../../dll.inc'
  35. ;include '../../../../../debug-fdo.inc'
  36.  
  37. ;__DEBUG__               = 1
  38. ;__DEBUG_LEVEL__         = 2
  39.  
  40. START:
  41.         ; Disabled, dll.obj doing this
  42.         ;stdcall dll.Load, @IMPORT
  43.         ;test    eax, eax
  44.         ;jnz     exit
  45.  
  46.         cinvoke libc_strlen, test_str1
  47.         ;DEBUGF 2, "%d", eax
  48.         mcall   SF_SYS_MISC, SSF_MEM_ALLOC, eax
  49.         mov     [test_str2], eax
  50.        
  51.         cinvoke libc_sprintf, [test_str2], format_str, str_var, [dec_var], dword [float_var], dword[float_var+4], [hex_var]
  52.         cinvoke libc_puts, test_str1
  53.         cinvoke libc_puts, [test_str2]
  54.        
  55.         cinvoke libc_strcmp, test_str1, [test_str2]
  56.        
  57.         test    eax, eax
  58.         jz      print_succ
  59.         jmp     print_fail
  60.        
  61. print_succ:
  62.         cinvoke libc_puts, success_msg
  63.         jmp exit
  64.        
  65. print_fail:
  66.         cinvoke libc_puts, failed_msg
  67.        
  68. exit:
  69.         mcall   SF_SYS_MISC, SSF_MEM_FREE, [test_str2]
  70.         //mcall   SF_TERMINATE_PROCESS - disabled, dll.obj also doing this
  71.         ret
  72.        
  73. ; data
  74.  
  75. format_str  db "%s %d %f 0x%x", 0
  76. test_str1   db "Test 463 -26.432100 0x9d81", 0
  77. test_str2   dd 0
  78.  
  79. str_var     db "Test",0
  80. dec_var     dd 463
  81. float_var   dq -26.4321
  82. hex_var     dd 40321
  83.  
  84. success_msg db "Test successful!", 0
  85. failed_msg  db "Test failed!", 0
  86.        
  87. align 4
  88.  
  89. @IMPORT:
  90. library libc,   'libc.obj'
  91. import  libc,   \
  92.         libc_sprintf, 'sprintf', \
  93.         libc_strcmp, 'strcmp', \
  94.         libc_strlen, 'strlen', \
  95.         libc_puts, 'puts'
  96.  
  97. IM_END:
  98. align   4
  99. rb      1024    ; stack
  100. MEM:
  101.