The MASM Forum

General => The Campus => Topic started by: jj2007 on November 01, 2020, 10:44:15 AM

Title: __UNICODE__ equ 1
Post by: jj2007 on November 01, 2020, 10:44:15 AM
If unicode is not defined, the output is   Hello world, 100 is the sum
If unicode is defined, the output is        Hello world, 〱0 is the sum

What am I doing wrong?

__UNICODE__     equ     1
include \masm32\include\masm32rt.inc

.data
MyArray dd 25, 18, 23, 17, 9, 2, 6

.code
start:
  print "Hello world, "
  xor ebx, ebx ; set two non-volatile
  xor esi, esi ; registers to zero
  .Repeat
add esi, MyArray[4*ebx]
inc ebx
  .Until ebx>=lengthof MyArray
  inkey str$(esi), " is the sum"
  exit
end start
Title: Re: __UNICODE__ equ 1
Post by: kiptron on November 01, 2020, 01:36:27 PM
 Should be ebx+4  not ebx*4  ??   Kiptron
Title: Re: __UNICODE__ equ 1
Post by: Vortex on November 01, 2020, 07:27:28 PM
Hello,

On Windows 10, the output displays a question mark symbol inside a square.
Title: Re: __UNICODE__ equ 1
Post by: Biterider on November 01, 2020, 08:07:08 PM
Hi
QuoteOn Windows 10, the output displays a question mark symbol inside a square.
This usually happens when an Unicode code point cannot be properly resolved or displayed.
This can happen when you mix Unicode text with Ansi functions or vice versa.

Biterider
Title: Re: __UNICODE__ equ 1
Post by: jj2007 on November 01, 2020, 08:29:41 PM
Quote from: Biterider on November 01, 2020, 08:07:08 PMwhen you mix Unicode text with Ansi functions or vice versa

So, despite the Unicode def on top, str$() remains Ansi??
Title: Re: __UNICODE__ equ 1
Post by: Vortex on November 01, 2020, 08:31:17 PM
Hello,

QuoteThis can happen when you mix Unicode text with Ansi functions or vice versa.

I didn't mix anything. I guess there is a problem with the print macro used by inkey :


__UNICODE__     equ     0

include \masm32\include\masm32rt.inc

.code

start:

    inkey    str$(100), " test1"
    invoke  ExitProcess,0

END start


I get the same question mark symbol here.
Title: Re: __UNICODE__ equ 1
Post by: TouEnMasm on November 01, 2020, 08:32:23 PM
There is numerous macros who can change with UNNICODE.
Made a listing of your code or use dumpbin /DISASM to made appear the problem.
Title: Re: __UNICODE__ equ 1
Post by: Biterider on November 01, 2020, 09:16:11 PM
Hi
On my distribution, the macros.asm contains the str$ macro, that looks like:
str$ MACRO DDvalue
  LOCAL rvstring
  .data
    rvstring db 20 dup (0)
    align 4
  .code
  invoke dwtoa,DDvalue,ADDR rvstring
  EXITM <ADDR rvstring>
ENDM


Finally looking for dwtoa, I found it in MASM32\m32lib. This proc is intended for Ansi chars.

Biterider

Title: Re: __UNICODE__ equ 1
Post by: Vortex on November 01, 2020, 09:21:46 PM
Hi Jochen,

Replacing str$ with ustr$ solves the problem :

inkey ustr$(esi), " is the sum"

Reading macros.asm :

; -----------------------------------------
    ; MSVCRT ASCII & UNICODE integer conversion
    ; -----------------------------------------
      ustr$ MACRO number
        LOCAL buffer
        .data?
          buffer TCHAR 40 dup (?)
          align 4
        .code
        IFNDEF __UNICODE__
          invoke crt__itoa,number,ADDR buffer,10
        ELSE
          invoke crt__itow,number,ADDR buffer,10
        ENDIF
        EXITM <eax>
      ENDM

      sstr$ MACRO number
        LOCAL buffer
        .data?
          buffer TCHAR 40 dup (?)
          align 4
        .code
        IFNDEF __UNICODE__
          invoke crt__ltoa,number,ADDR buffer,10
        ELSE
          invoke crt__ltow,number,ADDR buffer,10
        ENDIF
        EXITM <eax>
      ENDM
Title: Re: __UNICODE__ equ 1
Post by: jj2007 on November 01, 2020, 10:44:40 PM
Quote from: Vortex on November 01, 2020, 09:21:46 PMReplacing str$ with ustr$ solves the problem

Right. For MasmBasic, I've chosen to implement separately Str$() and wStr$() (http://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1186). The idea to declare once on top "this is Unicode, folks" is cute but it's a can of worms. Does anybody here on the forum have a source that has __UNICODE__ equ 1 on top and more than a hundred lines? I doubt it.
Title: Re: __UNICODE__ equ 1
Post by: hutch-- on November 01, 2020, 11:21:26 PM
Out of luck here, I have a full unicode editor but it was done before the equate. It uses the unicode functions in the masm32 library.