previous:
The MSX World Expo ‘99 report
MCCW issue 91, January/February 2000
Back to contents
next:
[nl] Wammes’ kolom
the new from Japan is now usable in Europe
MSX-Kanji revealed

As many people may have found out, after the ‘import’ of the MSX2+ system and/or MSX-DOS 2.20 in Europe we are aware of the Kanji-screens. After my not so small MSX-collection was enriched with a MSX turbo R, the Kanji-screens and the PUT KANJI statement — which can be found in really every MSX2 computer or higher, even the European versions — are more clear to me. Using these Kanji statements many nice things can be done. The first things Kanji enables is printing text onto a graphical screen using simple LOCATE and PRINT statements. However, this rom hides many more nice features, including a conversion system from and to Katakana, Hiragana and Kanji characters.

 
Albert Beevendorp
 
Directory
Kanji screens
Kanji string manipulation
Kanji add-ons
Kanji in machine language
The PUT KANJI statement
PUT KANJI in machine language



The Kanji characters are the more complex characters of Hiragana characters which are printed above these Kanji characters on many packages of Japanese games. The Katakana characters are used by Japanese to phonetically write English words. Usually names are written in Katakana characters as well. Hiragana characters are mostly used to create sentences, but the actual translation procedure is unknown to me, so let’s keep that to the experts okay? This article just explains the use of both the Kanji screens and PUT KANJI. The Kanji rom is accessible using machine language, so some example sources are implemented.

Kanji screens
The MSX Kanji rom exists out of four Kanji screens and some functions which are very much usable outside of the Kanji screens. There are six statements which enable selection of the Kanji screens. The table “Kanji screens” describes the possible screen modes which can be selected. The CALL statement itself can be abbriviated using an underscore (_), so CALL ANK and _ANK do the exact same thing:

    

Kanji screens
StatementResolutionDescription
_KANJI(64,13)Character size 8×16 (WIDTH 64 max.)
_KANJI0(64,13)Character size 8×16 (WIDTH 64 max.)
_KANJI1(80,13)Character size 6×16 (WIDTH 80 max.)
_KANJI2(64,24)Interlaced 8×8 (WIDTH 64 max.)
_KANJI3(80,24)Interlaced 6×8 (WIDTH 80 max.)
_ANK(80,24)SCREEN 0 or SCREEN 1

    After selecting a Kanji screen the keyboard will take the Japanese layout, which is the reason for the confusing non-japanese keyboards. With MSX-DOS 2.20 this was made very clear and there are converted MSX2+ computer which have a reprogrammed version in eprom which let you keep the original keyboard layout. Officially the Kanji rom was designed for the Japanse market which explains the Japanese keyboard layout. MSX-DOS 2.20-Kanji enabled clearing the screen with just a simple CLS. However, the official version of Kanji rom only _CLS enables clearing the screen. A normal CLS would simply give an error. Using _PALETTE(C,R,G,B) even colours can be changed in the Kanji screen. The result is 100% equal to COLOR=(C,R,G,B), but this would mess up part of the screen.

Kanji string manipulation
Next to the eight Kanji screen manipulation statements, ten Kanji string manipulation statements are included. The table “Kanji string manipulations” lists these statements which are explained right thereafter:

    

Kanji string manipulations
FunctionDescription
_AKCNV(A$,B$)Converts an Ank string to a Kanji string.
_JIS(A$,B$)Put Jis code of the character in B$ (obtained using _KNJ) in hexadecimal notation in A$.
_KACNV(A$,B$)Converts a Kanji string to an Ank string.
_KEXT(A$,B$,A)Filters characters of the given type A from string B$ to string A$.
_KINSTR(A,B,A$,B$)Equivalent to A=INSTR(B,A$,B$), but designed for the Kanji strings.
_KLEN(A,A$)Equivalent to A=LEN(A$), but designed for the Kanji strings.
_KMID(A$,B$,A,B)Equivalent to A$=MID(B$,A,B), but designed for the Kanji strings.
_KNJ(A$,B$)Put the character with Jis code B$ in A$.
_KTYPE(A,A$,B)Returns type of the character on position B of A$ in A.
_SJIS(A$,B$)Put the ascii values of character B$ (obtained using _KNJ) in hexadecimale notation in A$.

    Some commands need more explanation and examples in order to show the exact result. It’s necessary that you should try some things yourself in order to understand it all. Japanese characters kan be viewed if the appropriate support for this is installed or else you would see some meaningless characters.

    _KNJ(A$,B$) converts the Jis code to a string which can be used to put the character actually on the Kanji screen. In the Japanese manuals all characters are put in Jis code, which is the standard code for every Japanese computer system to display the correct character without its own translation method because of incompatibility. The Jis code is the standard for the Japanese Kanji and all conversions should go through the Jis code. The Jis code itself is put in B$ and the result will come in A$. As an example let’s take Jis code “4B62”. If we want to put this character on the screen, we should do _KNJ(A$, "4B62") and the characters to put the Kanji character onto the screen is put in A$. The character itself on MSX looks like this:

    This Kanji character can be converted back to a Jis code using _JIS(B$,A$) and B$ will have the string “4B62”. Using _SJIS(C$,A$) will result in the hexadecimal values of the character codes you should print to the screen to display that character: “9682”. In this case the character codes are &H96 and &H82. Printing these codes to a Kanji screen would result in the display of the Kanji character. Also a nice feature (and used a lot) is converting a string from Ank string to Kanji string, which results in double width characters on the screen. Less used is the conversion from Kanji string to Ank string (in somehow a less perfect way, as there are many more characters in the Kanji rom and conversion to Ank string is done with just 256 characters).

    If we want for us readble text (converted from an Ank string to a Kanji string) printed in double width on a Kanji screen, then use the statement _AKCNV(A$,"Hello") and when printing A$ to the Kanji screen. the text will be printed in double width as the Kanji characters are 16 pixels wide in stead of 8 pixels and on the Kanji screen two positions are used for one character for this purpose. If we want to convert this Kanji string back to an Ank string the statement _KACNV(B$,A$) and the result is that B$ contains the normal “Hello” (in both Ank and Kanji screens). The Katakana and Hiragana characters are smoother after converting from an Ank string to Kanji string, because the Ank characters are 8×8 pixels and Kanji characters are 16×16 pixels which are located in a seperate rom: the Jis rom.

    Using _KEXT(A$,B$,A) it’s possible to filter all characters of a given type A from B$ to A$. It’s possible to combine Ank-type and Kanji-type characters in a single string. If A=0 then all Ank-type characters would be filtered out from B$ into A$ and if A=1 then all Kanji-type characters would be filtered out from B$ into A$. After this, the length of the string can be determined using _KLEN(A,A$) for a particular purpose. You can get the type of a character within a string with _KTYPE or you can select a particular part out of it using _KMID. Before using one of those statements, you should get the length of the string first as A=LEN(A$) will give a different value than _KLEN(A,A$) when it contains Kanji-type characters.

    _KTYPE(A,A$,B) can determine the type of a selected character. The result A will contain the type of character in A$ on position B. Use _KLEN before using _KTYPE to stay within the actual length of the string, without getting an error. When A=0, the pointed character is Ank-type or A=1 when it points to a Kanji-type character. _KMID(A$,B$,A,B) gets the selected part of the string. _KMID detects character-types and reacts accordingly. Use _KLEN to determine the length of the string.

Kanji add-ons
In the Kanji mode (using Kanji screens) it’s possible to print onto a graphics screen using simple LOCATE and PRINT statements without opening a file "GRP:". Unfortunately the pixel-type positioning doesn’t work with LOCATE, so you need to open a "GRP:" file for this and so PRINT #1 is necessary. At the “introduction” of Kanji in Europe the simple LOCATE and PRINT statements were used in the MSX2+ demo’s which were all equipped with Kanji rom. Even MSX2 computers converted (or expanded) to MSX2+ have a Kanji rom without Jis rom — and with international keyboard layout and character set — so the built-in character set is used in stead, because the Jis rom couldn’t be found. The art of removing we would say here.

    The key combinations GRAPH-SELECT and CTRL-SPACE reveal some nice functions. If there is a difference between these two key combinations, I don’t know what it exactly is. Both key combinations disable this function. On the last line a cursor is positioned where japanese characters are entered using phonetic speech (which is called Romaji) and results in hiragana characters. Ouside of this function (and the Kanji screens) entering Romaji can be entered using SHIFT-KANA and CAPS-LOCK acts as a toggle between Hiragana characters (CAPS-LOCK off) and Katakana characters (CAPS-LOCK on).

    While entering text there are some keys with special functions. The cursor keys left and right enable browsing within the typed text. Cursor keys up and down or the space bar enable brwosing through a selection of Hiragana to Kanji converted possibilities. The RETURN-key tranfers the text to the actual screen from the cursor position. The KANA-key toggles phonetic speech entry (Romaji) and direct Hiragana entry. F1 toggles entry using our alphabet, F2 converts input to Kanji typed Katakana, F3 converts input to Ank-typed Katakana.

Kanji in machine language
Undoubtly there are more things to do with KANJI using machine language, but only switching Kanji screens, reading the current Kanji screen mode and Kanji driver installation detection are explained now. The Kanji routines are called using the H.EXTB just like the DOS2 memory routines and MST’s MemMan. The ID-code is put in register D and has value 17 (&H11) and the ‘command’ is put in register E. Below the three routines in a WB-ASS2 source.

    

ML-listing: KANJI.ASM

;
; KANJI-driver check - BiFi'96/'99
;
; Out: Z-flag set when no driver
;
KNJCHK: LD    A,255
        LD    DE,&H1100       ; D = ID-code, E = Command
        CALL  &HFFCA
        INC   A
        RET
;
; Read KANJI-mode - BiFi'96/'99
;
; Out: A=Current KANJI-mode
;         =0   ANK
;         =1   KANJI0
;         =2   KANJI1
;         =3   KANJI2
;         =4   KANJI3
;
RD_KNJ: LD    DE,&H1100
        JP    &HFFCA
;
; Set KANJI-mode - BiFi'96/'99
;
; In:  A = KANJI-mode
;
WRTKNJ: LD    DE,&H1101
        JP    &HFFCA

The PUT KANJI statement
Until now this Basic command was very unknown to many European MSX-users, but the fact is, the command is included in every MSX2 rom: PUT KANJI. It was not documented because it gets the character data from the Jis rom and the non-japanese computers don’t have a Jis rom. PUT KANJI is a graphical command, which means it’s only accessible from within a graphical screen. Even a bios entry is included in the MSX2 subrom to do a PUT KANJI from machine language and it’s included in this article. The complete syntax of the statement is:

     PUT KANJI [STEP] [(X-coordinate,Y-coordinate)], <Jis code> [,<Color>] [,<Logical operation>] [,<Printmode>]

    Like most graphical commands the optional "STEP" is used to do a relative positioning. Between the brackets the (with STEP relative) coordinates for the character are located. <Jis code> is expected and describes the character to print. Like all Jis codes in this article are in hexadecimal notation the same notation is kept here as well. So if you want to print Jis code “4B62” the Jis code is to be entered like &H4B62 (just for our easy reading and quick reference) in PUT KANJI. <Color> depends on the number of colors for that graphical screen. Like most graphical commands the <Logical operation> is printed in alphanumeric format. At default the <Logical operation> is PSET.

    <Printmode> needs some more explanation. There are 3 printmodes (0 to 2) and the table explains most of them:

PUT KANJI print modes
PrintmodeExplanation
0Complete KANJI character
1Print even lines only
2Print odd lines only

Printmode 0 displays the complete Kanji character on the active screen page. This is the defaultmode and is mostly used when there is no interlace necessary. Printmode 1 displays the even lines on the active page. To combine both even and odd lines to the full character the even lines are to be printed on the even numbered page and the odd lines on the odd numbered page using interlace. Remember: screen pages 0 and 1 are connected and screen pages 2 and 3 are connected too. These two examples show the usage of PUT KANJI in Basic. The first example shows the use of printmode 0, the second example print the same text using printmodes 1 and 2:

    

Basic-listing: KANJI1.BAS

10 SCREEN 5: X=60: Y=80: RESTORE
20 READ A$: IF A$<>"*" THEN Z=VAL("&H"+A$): GOSUB 40: X=X+16: GOTO 20
30 I$=INPUT$(1): SCREEN 0: END
40 PUT KANJI (X,Y),Z,14,PSET,0: RETURN
50 DATA 234D,2353,2358,2342,2341,2353,2349,2343,*

    

Basic-listing: KANJI2.BAS

10 SCREEN 7,,,,,3: X=180: Y=100: RESTORE
20 SET PAGE ,1: CLS: SET PAGE 1
30 READ A$: IF A$<>"*" THEN Z=VAL("&H"+A$): GOSUB 50: X=X+16: GOTO 30
40 I$=INPUT$(1): SCREEN 0,,,,,0: END
50 SET PAGE ,0: PUT KANJI (X,Y),Z,14,PSET,1
60 SET PAGE ,1: PUT KANJI (X,Y),Z,14,PSET,2: RETURN
70 DATA 234D,2353,2358,2342,2341,2353,2349,2343,*

    The examples above read the Jis code from the DATA statement. It’s easier to use the Kanji rom. As described earlier it’s possible to convert from Ank-type to Kanji-type and to get the Jis code per character to print using PUT KANJI. The statements used are: _AKCNV, _JIS, _KLEN and _KMID. The examples would be like this after changing some of the code:

    

Basic-listing: KANJI3.BAS

10 SCREEN 5: X=60: Y=80: _AKCNV (A$,"MSXBASIC")
20 _KLEN (M,A$): FOR L=1 TO M: GOSUB 50: GOSUB 40: X=X+16: NEXT L
30 I$=INPUT$(1): SCREEN 0: END
40 PUT KANJI (X,Y),Z,14,PSET,0: RETURN
50 _KMID (B$,A$,L,1): _JIS (C$,B$): Z=VAL("&H"+C$): RETURN

    

Basic-listing: KANJI4.BAS

10 SCREEN 7,,,,,3: X=180: Y=100: _AKCNV (A$,"MSXBASIC")
20 SET PAGE ,1: CLS: SET PAGE 1
30 _KLEN (M,A$): FOR L=1 TO M: GOSUB 70: GOSUB 50: X=X+16: NEXT L
40 I$=INPUT$(1): SCREEN 0,,,,,0: END
50 SET PAGE ,0: PUT KANJI (X,Y),Z,14,PSET,1
60 SET PAGE ,1: PUT KANJI (X,Y),Z,14,PSET,2: RETURN
70 _KMID (B$,A$,L,1): _JIS (C$,B$): Z=VAL("&H"+C$): RETURN

PUT KANJI in machine language
The subrom of every MSX2 a bios entry is included to do a PUT KANJI in machine language. The coordinates are to be put in GRPACX and GRPACY and are updated automatically, the logic operation is stored in LOGOPR and the color is stored in ATRBYT . For interlace display ACPAGE is to be filled with the active page before doing the actual PUT KANJI. Interlace mode is activcated by setting both bits 2 and 3 of R#9 and R#2 should be filled with 63 for page 1 and with 127 for page 3 to see both pages interlaced. The source below describes the interlaced PUT KANJI and includes some more variables:

    

ML-listing: PUTKANJI.ASM

        ORG   &HC000
;
; EQU's (BIOS)
;
CHGMOD: EQU   &H5F
CHGET:  EQU   &H9F
CLS:    EQU   &HC3
SUBROM: EQU   &H015F
KNJPRT: EQU   &H01BD
;
; EQU's (Systeem variabelen)
;
VDP2RG: EQU   &HF3E1
ATRBYT: EQU   &HF3F2
ACPAGE: EQU   &HFAF6
LOGOPR: EQU   &HFB02
GRPACX: EQU   &HFCB7
GRPACY: EQU   &HFCB9
VDP9RG: EQU   &HFFE8
;
; PUT KANJI demo - BiFi'99 - Interlaced version
; Non-interlace is very easy to extract from
; this source.
;
START:  LD    A,7             ; SCREEN 7
        CALL  &H5F

        LD    A,(VDP9RG)      ; Interlace on
        OR    12
        LD    (VDP9RG),A
        OUT   (&H99),A
        LD    A,128+9
        OUT   (&H99),A

        LD    A,63            ; SET PAGE 1,1
        LD    (VDP2RG),A
        OUT   (&H99),A
        LD    A,128+2
        OUT   (&H99),A
        LD    A,1
        LD    (ACPAGE),A

        XOR   A
        CALL  CLS

        LD    HL,180          ; X = 180
        LD    (GRPACX),HL
        LD    HL,100          ; Y = 100
        LD    (GRPACY),HL
        LD    HL,TJIS

PRT_LP: LD    C,(HL)          ; Read Jis-code
        INC   HL
        LD    B,(HL)
        INC   HL
        LD    A,B             ; Check for table ending
        OR    C
        JR    Z,PRTDNE

        CALL  PRINT           ; PUT KANJI twice
        JR    PRT_LP

PRTDNE: CALL  CHGET           ; Wait for keypress
        LD    A,(VDP9RG)      ; Interlace off
        AND   243
        LD    (VDP9RG),A
        OUT   (&H99),A
        LD    A,128+9
        OUT   (&H99),A
        XOR   A               ; SCREEN 0
        JP    CHGMOD
;
PRINT:  LD    DE,(GRPACX)
        PUSH  DE
        LD    E,0
        CALL  KANJI
        POP   DE
        LD    (GRPACX),DE
        LD    E,1

KANJI:  LD    A,14            ; Color
        LD    (ATRBYT),A
        LD    A,0             ; Logic operation
        LD    (LOGOPR),A
        LD    A,E             ; SET PAGE (active part)
        LD    (ACPAGE),A
        INC   A               ; Printmode

        LD    IX,KNJPRT
        JP    SUBROM
;
TJIS:   DW    &H234D,&H2353,&H2358,&H2342
        DW    &H2341,&H2353,&H2349,&H2343,0

    The routine KANJI actually does the PUT KANJI thing. The settings are done (color, logic operation and printmode). SET PAGE and interlace control can be removed with printmode 0. Adjusting the source for printmode 0 is not that hard. Choosing the source with interlace above the non-interlace is done because the non-interlace version can be easily extracted from this one.

previous:
The MSX World Expo ‘99 report
MSX Computer & Club Webmagazine
issue 91, January/February 2000
next:
[nl] Wammes’ kolom