戻る
APIインターフェース

アセンブラインターフェース

0x600cfc番地からの4バイトが、APIテーブルの先頭番地を示します。 APIテーブルには、以下のAPIルーチンのアドレスが4バイト毎に格納されています。 なお、APIテーブルの先頭番地やAPIルーチン自体のアドレスは OSのバージョンで異なります。0x600cfcはおそらく変更されません。

各関数の動作説明はSDK付属の API.TXT 、あるいは、 エミュレータディレクトリのNOT-PROD内の USERAPI2.H を参照してください。 なお、FileSeek及びFlashSeekでは、フラグを指定することはできません。 必ずファイル先頭からのシークになります。 (C言語からでも同様です)

インターフェース cdeclは、C言語の関数呼びだし規約であり、 パラメータをスタックに積み、戻り値はhlレジスタになります。

0: PowerSaveLock
1: PowerSaveUnlock
  余分な呼び出しはかまいません
2: Screen
  in: a=newMode
  out: a=prevMode
3: PutChar
  in: wa=tcode l=x h=y c=attr
4: PutChar2
  in: wa=tcode c=attr
5: PutStr
  in: xix=str l=x h=y c=attr
6: PutStr2
  in: xix=str c=attr
7: PutNum
  in: ix=val a=width b=mode l=x h=y
8: PutNum2
  in: ix=val a=width b=mode
9: Indicator
  in: a=num b=state
10:PutChar24
  in: wa=tcode ix=xドット iy=yドット c=attr
11:PutStr24
  in: xhl=str ix=x iy=y c=attr
12:PutNum24
  in: wa=val b=width c=mode ix=x iy=y
13:PutChar32
  in: wa=tcode ix=x iy=y c=attr 数字等のみ
14:PutStr32
  in: xhl=str ix=x iy=y c=attr
15:PutNum32
  in: wa=val b=width c=mode ix=x iy=y
16:アイコン表示
  in: a:0〜22でパターン b=0=クリア/else=表示
17:InKey
  out: a
18:InKeyWait
  out: a
19:SenseKey
  out: a
20:ReadKey
  out: b=scan3 c=scan2 d=scan1 e=scan0 a=keycode
21:InChar
  out: wa
22:InCharWait
  out: wa
23:Input
  in: xix=buf a=len b=curpos l=x h=y
  out: a=key b=curpos
24:Input2
  in: xix=buf a=len b=curpos
  out: a=key b=curpos
25:GetChar
  in: l=x h=y
  out: a=code b=type
26:GetChar2
  out: a=code b=type
27:ClearScreen
28:CursorOn
29:CursorOff
30:Locate
  in: l=x h=y
31:GetPos
  out: l=x h=y
32:SetKeyMode
  in: a=mode
33:Beep
34:Click
35:Sound
  in: w=tone a=len
36:DispImage
  in: xhl=addr ix=x iy=y b=yBytes c=xLines
37:GetDate
  out: w=year-1996 b=month c=day l=week
38:SetDate
  in: w=year-1996 b=month c=day
  out: a=0=success
39:GetTime
  out: d=hour e=min h=sec
40:DayOfWeek
  in: w=year-1996 b=month c=day
  out: l=week a=0=success
41:SetAlarm
  in: w=year b=month c=day d=hour e=min h=type
  out: l=handle a=0=success
42:GetAlarm
  in: l=handle
  out: w=year b=month c=day d=hour e=min h=type
43:DeleteAlarm
  in: l=handle
  out: a=0=success
44:OpenComm
  in: xiy=device bc=inqueue hl=outqueue
  out: hl=handle/-X=error
45:WriteComm
  in: bc=handle xiz=buf hl=size
  out: hl=size/-X=error
46:ReadComm
  in: bc=handle xiz=buf hl=size
  out: hl=size/-X=error
47:SetCommState
  in: wa=speed bc=parity hl=stop e=bitlen d=flow
  out: hl=0/-X=error
48:FileCreate
  in: xhl=filename a=attr
  out: w=handle a=0=success
49:FileOpen
  in: xhl=filename
  out: w=handle a=0=success
50:FileClose
  in: w=handle
  out: a=0=success
51:FileRead
  in: w=handle xhl=buf xbc=size
  out: xbc=size a=0=success
52:FileWrite
  in: w=handle xhl=buf xbc=size
  out: xbc=size a=0=success
53:FileDelete
  in: xhl=filename
  out: a=0=success
54:FileSeek
  in: w=handle xhl=offset
  out: a=success=0
55:FilePosition
  in: w=handle
  out: xhl=offset a=0=success
56:FileFirst
  cdecl
57:FileNext
  cdecl
58:OpenDataBase
  cdecl
59:CloseDataBase2
  cdecl
60:ReadRecord2
  cdecl
61:WriteRecord2
  cdecl
62:AddRecord2
  cdecl
63:DelRecord2
  cdecl
64:ReadField2
  cdecl
65:WriteField2
  cdecl
66:SetTime
  in: d=hout e=min h=sec
67:CloseComm
  in: hl=handle
  out: hl=0/-X=error
68:FlashCreate
  in: xhl=filename a=attr
  out: w=handle a=0=success
69:FlashOpen
  in: xhl=filename
  out: w=handle a=0=success
  ※フラッシュメモリの書き換え寿命は10万回ぐらい
70:FlashClose
  in: w=handle
  out: a=0=success
71:FlashRead
  in: w=handle xhl=buf xbc=size
  out: xbc=size a=0=success
72:FlashWrite
  in: w=handle xhl=buf xbc=size
  out: xbc=size a=0=success
73:FlashDelete
  in: xhl=filename
  out: a=0=success
74:FlashSeek
  in: w=handle xhl=offset
  out: a=0=success
75:FlashPosition
  in: w=handle
  out: xhl=offset a=0=success
76:FlashFirst
  cdecl
77:FlashNext
  cdecl
78:LcdSleepLock
79:LcdSleepUnlock
80:
81:
82:
83:
84:DialPHS
  in: xix=DIAL_p
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:曲の演奏 (詳細)
  in:xix=music_score
101:
102:

非公開APIのC言語からの呼びだし

USERAPI2.Hに説明のある非公開APIは APILIB.LIB中にラップ関数がないため、直接呼び出せません。 インラインアセンブラ経由で呼び出します。
※インラインアセンブラを使用する場合は、 一度コンパイラにアセンブラコードを吐き出させて、 XIZレジスタが関数を通して保護されるかどうか検証してください。
example() {
  ...
  // 24ドット文字列描画
  __XHL= (long)"24ドット文字列";
  __IX= 10; __IY= 148; __C= 0;
  __asm("push xiz");
  __asm("ld xiz,(0x600cfc)");
  __asm("ld xiz,(xiz+11*4)");
  __asm("call xiz");
  __asm("pop xiz");
  ...
}

cdecl呼び出しタイプは、 APILIB.LIB中でAPI_TABLE_ADR_pが0x600cfcとして定義されてますので、 以下のコードで直接呼び出せます。

extern short (***API_TABLE_ADR_p)();
example() {
  ...
  // AddRecord2
  result= (*(*API_TABLE_ADR_p)[62])(&hdb, buff, &recno);
  // コンパイラのバグで以下だと動作しない
  result= (*(*(short(***)())0x600cfc)[62])(&hdb, buff, &recno);
  ...
}

アプリケーション起動理由
アプリケーション終了時と同じく、起動時にも、起動理由が渡ります。 但し、レジスタBCを経由します。

これをmain()の頭でつかまえればいいのですが、 初期値つき配列などの初期化コードが bc レジスタを破壊することがあるので、 最低限のmain関数で受けます。
main()
{
  short cause;
  cause= __BC;
  UserStart(cause);
}

UserStart(short cause)
{
  ... cause に応じた処理 ...
}