2013年2月28日木曜日

SHIFT-JIS文字ほぼ全一覧表示(UTF8版)

X68000がサポートしていたSHIFT-JIS文字ほぼ全てを一覧表示します。
算術で作り出したSHIFT-JISコードを表示時にUTF8に変換しています。
強制SHIFT-JISモードをオフに設定して実行してください。
// UTF8版
/* SHIFT-JIS 全文字コード表示プログラム 
// テキスト画面がスクロールできないのでページ切り替え
    font("Migu 1M")
    int fzenhan:// YES=
    width(64,,fzenhan)
    print "fzenhan=";fzenhan
    cls()
    
    if isLocalizeJapan() then {
        setFunctionKey(0,"次へ",&h0d)
        setFunctionKey(1,"中断",&h1b)
        print "半角文字"
    } else {
        setFunctionKey(0,"Next",&h0d)
        setFunctionKey(1,"Break",&h1b)
        print "Half-Width Character"
    }
    print_code0(fzenhan)
    //
    displayFunctionKey(YES,0,1)
    //
    while YES
        if print_code(&h8100,&h9fff) then break
        if print_code(&he000,&hefff) then break
        print_head()
        break
    endwhile
    //
    // ファンクションキー表示は個数を変えても自動的に前の表示は消えないので、
    // ユーザーが消す必要がある(そうしないと表示が重なる)
    displayFunctionKey(NO,0,1)
    if isLocalizeJapan() then {
        setFunctionKey(0,"終了",&h0d)
    } else {
        setFunctionKey(0,"End",&h0d)
    }
    displayFunctionKey(YES,0,0)
    int ky
    repeat
        ky=inkey()
    until ky<>0
end

//--------------------------------

func print_head()
    if fzenhan then {
        print "-code-:-+0-+1-+2-+3-+4-+5-+6-+7-+8-+9-+A-+B-+C-+D-+E-+F-"
    } else {
        print "-code-:-0-1-2-3-4-5-6-7-8-9-A-B-C-D-E-F-"
    }
endfunc

func print_skip()
    print "      :                                                "
endfunc

func str hex4$(h;int)
    return (right$("0000"+hex$(h),4))
endfunc

func str hex2$(h;int)
    return (right$("00"+hex$(h),2))
endfunc

func printChr(h;int,l;int)
    print chr$((h shl 16)or l);
endfunc

func int print_code(st;int,ed;int)
/* 全角文字表示 
int i,li,hi
int j
    for i=st to ed
        hi=i / 256
        li=i mod 256
        if li=0 then {
            print_head()
            int ky
            int ts=time()
            int dt=0,t
            repeat
                ky=inkey()
                t=time()
                if t-ts>dt then { :/* 秒が変った
                    dt=dt+1
                    locate(40,0):print dt
                    beep2(0)
                }
            until ky<>0
            if ky=&h1b then return (YES)
            cls()
            if isLocalizeJapan() then {
                print "全角文字"
            } else {
                print "Double-Width character"
            }
            print_head()
        }
        if li<&h40 then continue:/* 下位8ビットが<$40の文字はない 
        
        /* アドレス表示 
        print " ";hex4$(i);" :";
        for j=0 to 16-1
            print " ";
            int c=(i+j) and &hff
            if c<&h40 or c=&h7f or c>=&hfd then { /* 未定義文字 
                if fzenhan then {
                    print "**";
                } else {
                    print "*";
                }
            } else {
                c=sjisToUtf8(i+j)
                print chr$(c);    /* 途中で桁上がりを起こさないことを前提にした処理 
            }
        next
        print
        i=i+16-1:/* 次のnext +1されるから
    next
    return (NO)
endfunc

func print_code0(fzenhan;int)
/* 半角文字表示 
int li
int j,c
    print_head()
    for li=&h20 to &he0-1
        /* 途中表示しないエリア 
        if li=&h80 then print_skip()
        if li>=&h80 and li<=&h9f then continue
        
        /* アドレス表示 
        print "  ";hex2$(li);"  :";
        /* 文字表示
        for j=0 to 16-1
            print " ";
            c=li+j
            if c=&h7f or c=&ha0 then c='*' else c=sjisToUtf8(c)
            print chr$(c);
            if fzenhan then print " ";:/* 全角=半角*2のフォントの時は後ろにスペースを入れる
        next
        print
        li=li+16-1:/* 次のnext +1されるから
    next
endfunc

Zipファイル :XBetc.zip

2013年2月27日水曜日

ビンゴゲーム

いわゆるビンゴゲーム。コンピューターと対戦します。
多くのタッチエリアを設定しています。
画面表示の関係上、iPadの縦画面専用です。
//--------------------------------------------------------------------------------
/* BINGO
// for X-BASIC for iOS v2.0
//--------------------------------------------------------------------------------

if deviceType()<>DEVICE_IPAD and deviceType()<>DEVICE_IPAD_SIMULATOR then {
    print localizedString("このプログラムはiPad専用です","This program only for iPad.")
    end
}
dim int A(5,11),B(12,2)
dim int keyAreaNo(5,5)
int d,L,T,E,F
int WX,WY
int sx,sy,ex,ey
int OPEND=100:// 定数
/*
srand2()
width(64)
getWidth(WX,WY)
setUpScroll(NO):// テキスト画面の上スクロールを止める (V2.0)
apage(GPAGE0)
vpage(B_TPAGE or B_GPAGE0 or B_GPAGE1,YES)
//display_title()

d=0
dim str menues(1)
str title
int e
repeat
    cls()
    apage(GPAGE1):wipe()
    apage(GPAGE0):wipe()
    gcolor(-TWHITE,0,0,255)
    symbol(128,2,"BINGO GAME","IPAGothic",48)
    gcolor(-THWHITE,0,0,255)
    symbol(129,3,"BINGO GAME","IPAGothic",48)
    gcolor(-THRED,0,0,255)
    box(13,64,748,614)
    tcolor(-THWHITE,0,0,255)
    shuffle():// 数字の設定
    field_print():// 数字表示&タッチエリア設定
    print_number(NO)
    /*
    if isLocalizeJapan() then {
        menues={"先手","後手"}
        title="順番選択"
    } else {
        menues={"First move","Passive move"}
        title="Moving order"
    }
    repeat
        L=selectMenu2(title,menues):// -1,0,1
    until L>=0:// -1=BREAK/outside menu touch
    L=L+1:// 0,1->1,2

    sub_cls()
    /*
    for e=0 to 12
        B(e,0)=0
        B(e,1)=0
        B(e,2)=0
    next
    E=0:F=0:T=0
    repeat
        T=T+1
        tcolor(-THWHITE,0,0,255)
        locate(6,17)
        if isLocalizeJapan() then {
            print"第";T;"手"
        } else {
            print"The";T;" hand"
        }
        repeat
            switch L
                case 1:
                    locate(11,19)
                    print localizedString("あなた:","You : ");
                    d=input_num()
                    L=2
                    break
                case 2:
                    locate(38,19)
                    print localizedString("コンピューター:","Computer : ");
                    d=com_num()
                    //beep()
                    L=1
                    break
            endswitch
            int cx=pos()
            int cy=csrlin()
            int ffind=check_num(d)
            if not ffind then {
                // 見つからなかった
                // 人間側のみありえる
                L=1
                beep()
                // 選択しなおし
            }
        until ffind
        locate(cx,cy):print d
    until (F>=5) or (E>=5)
    resetALlKeys():// タッチエリアの解除
    sub_cls()
    print_number(YES)
    hantei(E,F)
    locate(11,24)
    if isLocalizeJapan() then {
        print "御苦労さまでした"
        menues={"はい","いいえ"}
        title="もう一度しますか?"
    } else {
        print "Cheers for hard work was."
        menues={"YES","NO"}
        title="Try again ?"
    }
    L=selectMenu2(title,menues):// -1=stop,0=YES,1=NO
until L=1 or L=-1
end

//--------------------------------------------------------------------------------
// functions
//--------------------------------------------------------------------------------

func hantei(E;int,F;int)
/* 勝ち負け判定
    tcolor(-THYELLOW,0,0,255)
    locate(10,23)
    if isLocalizeJapan() then {
        print E;" 対";F;"で ";
    }
    if F<E then {
           print localizedString("あなたの勝ち","You win");
    } else {
        if E<F then {
            print localizedString("コンピューターの勝ち","Computer win");
        } else {
            print localizedString("引き分け","Draw");
        }
    }
    if not isLocalizeJapan() then {
        print " in the";E;"-for-";F
    }
endfunc
/*
func int input_num()
/* 人間の数字選択
int num
//    kbclr()
    // キー入力待ち
    while not kbhit()
    endwhile
    // エリアをタッチすると、数字がキーコードとして返ってくる
    num=inkey()
    return(num)
endfunc
/*
func int check_num(d;int)
/* 番号チェック&マスオープン
int h,x,y,ac,bb,i,j
    for h=1 to 2:// 両方を調べる
        // 数字からマス座標を得る
        int ffind=NO
        for i=1 to 5
            for j=1 to 5
                ac=A(i,j+(h-1)*6)
                if ac=d then {
                    x=i:y=j
                    ffind=YES
                    break
                }
            next
            if ffind then break
        next
        if not ffind then {
            // 見つからない
            locate(0,5):print "見つからない"
            return (NO)
        }
        //
        apage(GPAGE1)
        switch h
            case 1:gcolor(-THMAGENTA,0,0,200):break
            case 2:gcolor(-THGREEN  ,0,0,200):break
        endswitch
        calc_grid_gxy(x,y,h-1):// ->sx,sy,ex,ey
        fill(sx,sy,ex,ey)
        apage(GPAGE0)
        //
        A(x,y+(h-1)*6)=ac+OPEND:/* 開いたの印
        bb=0
        if x=y   then bb=B(12,h):B(12,h)=bb+1
        if x=6-y then bb=B(11,h):B(11,h)=bb+1
        bb=B(x,h)  :B(x  ,h)=bb+1
        bb=B(y+5,h):B(y+5,h)=bb+1
        x=0
        for i=1 to 12
            x=x+B(i,h)\5
        next
        if (h=1) and (E<x) then {
            locate(11,15)
            if isLocalizeJapan() then {
                print "あなた:";x;"列"
            } else {
                print "You :";x;" lines"
            }
            E=x
            beep2(7)
        } else {
            if (h=2)*(F<x) then {
                locate(38,15)
                if isLocalizeJapan() then {
                    print "コンピューター:";x;"列"
                } else {
                    print "Computer :";x;" lines"
                }
                F=x
                beep2(8)
            }
        }
    next
    // 見つかって処理した
    return (YES)
endfunc
/*
func int com_num()
/* コンピューターの番号考え
int i,j,m,bb,c
    m=0
    for i=1 to 5
        for j=1 to 5
            bb=0
            if A(i,j+6)<OPEND then {
                if i=j   then bb=   1+B(12,2)
                if i=6-j then bb=bb+1+B(11,2)
                bb=bb+2+B(i,2)+B(j+5,2)
                if bb>m then c=A(i,j+6):m=bb
            }
        next
    next
//    locate(0,26):print "com=";c
    return(c)
endfunc
/*
func sub_cls()
/* 画面一部クリア
    int y
    for y=16 to WY
        locate(0,y):print space$(WX);
    next
endfunc
/*
func shuffle()
/* マス内数字シャッフル
int i,j,l,h
int c,x,y
    for l=0 to 1:/* l=0:あなた , 1=コンピューター
        /* まずはマス内に順番に数字を入れる
        /* A(i,j) : j=1〜5:あなた , 6〜11:コンピューター
        h=0
        for i=1 to 5
            for j=1 to 5
                h=h+1
                A(i,j+l*6)=h
            next
        next
        /* マスを入れ替える
        for i=1 to 5
            for j=1 to 5
                x=rand() mod 5+1
                y=rand() mod 5+1+l*6
                c=A(i,j+l*6)
                A(i,j+l*6)=A(x,y)
                A(x,y)=c
            next
        next
    next
endfunc
/*
func print_number(mode;int)
/* マス内番号表示
// mode : NO=人側のみ開く , YES=コンピューター側を開く
int i,j,c
int x,y
    tcolor(-THWHITE,0,0,255)
    for i=1 to 5
        x=(i-1)*5
        for j=1 to 5
            y=j*2+2
            if not mode then {
                // 人側(Human)のみ開く
                c=A(i,j)
                if c>OPEND then c=c-OPEND:/* すでに開いているマスの時
                locate(x+ 7,y):print using "##";c
                locate(x+36,y):print "??"
            } else {
                // コンピューター側(Computer)を開く
                c=A(i,j+6)
                if c>OPEND then c=c-OPEND:/* すでに開いているマスの時
                locate(x+36,y):print using "##";c
            }
        next
    next
endfunc
/*
func field_print()
/* フィールド描画
// 先にshuffle()で数字を確定しておくこと
int l,i,j
    for l=0 to 1:/* l=0:あなた , 1=コンピューター
        if l=0 then {
            tcolor(-THCYAN,0,0,255)
            locate(11,14)
            print localizedString("あなたのマス目","Your grid")
        } else {
            tcolor(-THYELLOW,0,0,255)
            locate(36,14)
            print localizedString("コンピューターのマス目","  Computer grid  ")
        }
        // ます線描画
        gcolor(-THMAGENTA,0,0,255)
        for i=1 to 5
            for j=1 to 5
                calc_grid_gxy(i,j,l):// ->sx,sy,ex,ey
                box(sx,sy,ex,ey)
                if l=0 then {
                    // タッチエリアの設定
                    // 人間側のみ
                    // キーコードに数字を入れておく
                    keyAreaNo(i,j)=setTouchArea(sx,sy,(ex-sx),(ey-sy),A(i,j),YES)
                    // save touch area No into keyAreaNo()
                }
            next
        next
    next
    tcolor(-THWHITE,0,0,255)
endfunc
/*
func resetALlKeys()
// 全タッチアリアの解除(重要)
    int i,j
    for i=1 to 5
          for j=1 to 5
            removeTouchArea(keyAreaNo(i,j))
        next
    next
endfunc
/*
func calc_grid_gxy(i;int,j;int,l;int)
// マス目座標からグラフィック表示座標を得る
int x,y
    x=textX2Gx((i-1)*5+7)+l*340
    y=textY2Gy(j*2+2)
    // 以下リターン値(グローバル変数)
    ex=textX2Gx((i-1+1)*5+7)+l*340-12
    ey=textY2Gy((j+1)*2+2)-12
    sx=x-12
    sy=y-12
endfunc
/*
func display_title()
/* タイトル描画
int i,x
str s,s1
    wipe()
    lineWidth(2)
    gcolor(-THRED,0,0,255)
    box(61,4,448,128)
    gcolor(-THMAGENTA,0,0,200)
    fill(63,6,446,126)
    s="BINGO"
    for i=0 to 4
        x=i*70+90
        s1=utf8Mid$(s,i+1,1)
        gcolor(-TWHITE,0,0,255)
        symbol(x-11,16,s1,"Times New Roman",64)
        gcolor(-THWHITE,0,0,255)
        symbol(x-9 ,18,s1,"Times New Roman",64)
    next
    /*
    gcolor(-TGREEN,0,0,255)        :fill(112,180,400,320)
    //
    str copyright="Presented by AIG-SOFT"
    str forMachine="for X-BASIC or iOS"
    gcolor(-TWHITE,0,0,255)
    symbol(170,201,copyright,"IPAGothic",16)
    symbol(180,231,forMachine,"IPAGothic",16)
    gcolor(-THWHITE,0,0,255)
    symbol(169,200,copyright,"IPAGothic",16)
    symbol(179,230,forMachine,"IPAGothic",16)
    //
    gcolor(-THRED,0,0,255)
    box(109,178,403,324)
    hitKey()
endfunc
/*
func srand2()
/* 乱数初期化
int t
    t=val(right$(time$,2))+val(mid$(time$,4,2))
    srand(t*16)
endfunc
/*
func hitKey()
    setFunctionKey(0,localizedString("ここを押してください","Hit This Button"),'!')
    displayFunctionKey(YES,0,0)
    while inkey()=0
    endwhile
    cls()
    displayFunctionKey(NO,0,0)
endfunc

func str localizedString(js;str,es;str)
    if isLocalizeJapan() then return(js)
    return (es)
endfunc


//--------------------------------------------------------------------------------

Zipファイル :XBbingo.zip

2013年2月26日火曜日

電子メイル関数テスト

電子メイル関数のサンプルプログラムです。 別途pngファイルを用意しておいてください(添付ファイルを作るため)。
//------------------------------------------------
/* eMailSend() test
//------------------------------------------------

dim str fileList(256):// ()内は扱える最大ファイル数
int cnt
// ここをpng->jpegと変更してテスト
cnt=files(fileList,"","png",YES,FILES_FILE)
if isLocalizeJapan() then {
 print "該当ファイル数=";cnt
} else {
 print "Corresponding file number=";cnt
}
int i
for i=0 to cnt-1
 print i;":";fileList(i)
next

// (1)添付なし
if isLocalizeJapan() then {
 print "(1)添付なし"
 emailSend("件名1","本文1")
} else {
 print "(1)no attachment"
 emailSend("subject1","body1")
}
//hitKey()
// (2)そのまま添付
if isLocalizeJapan() then {
 print "(2)そのまま添付"
 emailSend("件名2","本文2(添付付き)",fileList,3)
} else {
 print "(2)attach each file"
 emailSend("subject2","body2(with attachment)",fileList,3)
}
//hitKey()
// (3)zip圧縮添付
if isLocalizeJapan() then {
 print "(3)zip圧縮添付"
 emailSend("件名3","本文3(zip添付付き)",fileList,10,"testzip.zip")
} else {
 print "(3)attach with zip archive"
 emailSend("subject3","body3(zip archive)",fileList,10,"testzip.zip")
}

if isLocalizeJapan() then {
 print "全送信終了"
} else {
 print "All send finish."
}

//------------------------------------------------
end
//------------------------------------------------
func hitKey()
 str exit$
 if isLocalizeJapan() then {
  exit$="次へ"
 } else {
  exit$="To Next"
 }
 setFunctionKey(0,exit$,'!')
 displayFunctionKey(YES,0,0)
 while inkey()=0
 endwhile
 cls()
 displayFunctionKey(NO,0,0)
endfunc

Zipファイル :XBtests.zip

2013年2月25日月曜日

電子コンパス関数テスト

電子コンパス関数のテストプログラムです。 iPod touchには電子コンパスはないので利用できません。 (これが電話以外のiPhoneとの違い。)
//----------------------------------------------------------------------------------------------
// compass test
//----------------------------------------------------------------------------------------------

print "version Motion=";versionXBiOSMotion$()

font("Cochin",6):// ファンクションキーのフォントを設定
setFunctionKey(0,"end"   ,'!')
setFunctionKey(1,"pause" ,'p')
setFunctionKey(2,"start" ,'s')
setFunctionKey(3,"clear" ,'c')
displayFunctionKey(YES,0,3)
kBackgroundAlpha(0.9)
font("IPAGothic")

if compassStart(10) then {
 print localizedString("方位取得は使えません","Can't use compass.")
 end
}

float degree,magnetic
int ky,cnt,i

while YES
 if not kbhit() then {
  i=0
  cnt=compassCount()
  if cnt>0 then locate(0,1):print "cnt=";cnt
  while cnt>0
   degree=compassGetData(magnetic)
   locate(0,2+i)
   if isLocalizeJapan() then {
    print using "極北からの角度=###.####,磁北からの角度=###.####";degree,magnetic
   } else {
    print using "true=###.####,magnetic=###.####";degree,magnetic
   }
   cnt=cnt-1
   i=i+1
   if kbhit() then break
  endwhile
 } else {
  ky=inkey()
  switch ky
   case 'p'
    compassPause(YES)
    print "Pause"
    break
   case 's'
    compassPause(NO)
    print "Start"
    break
   case 'c'
    cls()
    compassClear()
    break
   default:
    // 念のため
    beep()
    break
  endswitch
  if ky='!' then break
 }
endwhile
compassEnd()
end

//----------------------------------------------------------------------------------------------

func str localizedString(js;str,es;str)
 if isLocalizeJapan() then return(js)
 return (es)
endfunc

//----------------------------------------------------------------------------------------------

Zipファイル :XBtests.zip

2013年2月24日日曜日

音声関数テスト

音声関数のテストプログラムです。
最初にあるa_setPlayData()に、手持ちの音声ファイルを指定してください。
サンプル曲は満開製作所の「Muff&Huff」より拝借しています(自由に利用できる曲)。

// audio test

// ↓手持ちの音声ファイルを指定してください
// サンプルは満開製作所「Muff&Huff」より
int sno=a_setPlayData("EARTH SONG #1.mp3")
if (sno=-2) then {
 print "sound file not found."
 end
}
int wx
//
dim int touchNo(10) :// タッチエリア番号
int touchCnt  :// タッチエリア数

font("IPAGothic")
int fzenhan
int WX=64:if deviceType()<>1 then WX=48
int WY=width(WX,,fzenhan)
int xw=1:/* 全角1文字の桁数
if fzenhan then xw=2

 str exit$
 if isLocalizeJapan() then {
  exit$="中断"
 } else {
  exit$="exit"
 }
 int x=WX/2-18
 int y=WY/2
     //  012345678901234567890123456789
 locate(x,y+0):print "      ┏━┓"
 locate(x,y+1):print "      ┃8┃"
 locate(x,y+2):print "      ┗━┛"
 locate(x,y+3):print "┏━┓┏━┓┏━┓    ┏━━┓"
 locate(x,y+4):print "┃4┃┃?┃┃6┃    ┃";exit$;"┃"
 locate(x,y+5):print "┗━┛┗━┛┗━┛    ┗━━┛"
 locate(x,y+6):print "      ┏━┓"
 locate(x,y+7):print "      ┃2┃"
 locate(x,y+8):print "      ┗━┛"

 int i=0
 touchNo(inc(i))=setTouchArea(textX2Gx(x+ 6),textY2Gy(y  ),textX2Gx(xw*3),textY2Gy(3),'8',YES,  0,50,55,220)
 touchNo(inc(i))=setTouchArea(textX2Gx(x+ 6),textY2Gy(y+6),textX2Gx(xw*3),textY2Gy(3),'2',YES,  0,50,55,220)
 touchNo(inc(i))=setTouchArea(textX2Gx(x   ),textY2Gy(y+3),textX2Gx(xw*3),textY2Gy(3),'4',YES,  0,50,55,220)
 touchNo(inc(i))=setTouchArea(textX2Gx(x+12),textY2Gy(y+3),textX2Gx(xw*3),textY2Gy(3),'6',YES,  0,50,55,220)
 //
 touchNo(inc(i))=setTouchArea(textX2Gx(x+ 6),textY2Gy(y+3),textX2Gx(xw*3),textY2Gy(3),'?',YES,150,50, 5,120)
 touchNo(inc(i))=setTouchArea(textX2Gx(x+22),textY2Gy(y+3),textX2Gx(xw*4),textY2Gy(3),'!',YES,150, 5 ,5,120)
 touchCnt=i
 //

  keyRepeatTime(0,0):// リピート無し
 //
 setFunctionKey(0,exit$,'!')
 setFunctionKey(1,"V-UP",'u')
 setFunctionKey(2,"V-DN",'d')
 setFunctionKey(3,"SPD",'S')
 setFunctionKey(4,"LP=1",'1')
 setFunctionKey(5,"LP∞" ,'0')
 setFunctionKey(6,"LP=2",'2')
 setFunctionKey(7,"PAN",'c')
 setFunctionKey(8,"stop",'s')
 setFunctionKey(9,"cont",'C')

 setFunctionKeyBackgroundImage("funcBack.png")
 displayFunctionKeyAll(YES)

 int speed=0
 int pan=0
 str cs
 int dt=0,t
 int ts=time():/* 開始時間
 locate(20,1)
 a_play(sno)
 while YES
// while a_stat(sno)
  // キー入力待ちしながら時計を回す
  while (not kbhit())
   /* キー入力の無い間
   t=time()
   if t-ts>dt then { :/* 秒が変った
    dt=dt+1
    locate(20,0):print dt;
    beep2(0)
    locate(20,1)
   }
  endwhile
  // キー操作判定
  cs=inkey$()
  switch cs
   case "u":a_volume(sno,1.0):break
   case "d":a_volume(sno,0.05):break
   case "S":
    switch speed
     case 0:a_speed(sno,2.0):break
     case 1:a_speed(sno,0.5):break
     case 2:a_speed(sno,1.0):break
    endswitch
    speed=speed+1
    break
   case "1":
    a_loop(sno,1):print "loop=1"
    break
   case "2":
    a_loop(sno,2):print "loop=2"
    break
   case "0":
    a_loop(sno,0):print "loop=∞"
    break
   case "c":
    switch pan
     case 0:a_pan(sno,-1.0):inc(pan):break
     case 1:a_pan(sno, 0.0):inc(pan):break
     case 2:a_pan(sno, 1.0):pan=0:break
    endswitch
    break
   case "r"
    break
   case "s":a_stop(sno):break
   case "C":a_cont(sno):break
  endswitch
  print cs;
  if cs="!" then break
 endwhile
 a_end(sno)
 print "end"
end

func resetTouchArea()
// タッチエリアの解除
int i
 for i=0 to touchCnt
  removeTouchArea(touchNo(i))
 next
 touchCnt=0
endfunc
サンプル音声ファイル入り圧縮ファイル:XBaudioTest.zip

2013年2月16日土曜日

音声ファイルローダー

サポートしている音声ファイルを順次演奏します。
サンプル音声はZ-MUSIC v3から無断で借りています。
不都合があればご連絡ください。

// Sound player
// for X-BASIC for iOS v1.7 later

width(64)
//
vpriority(TPAGE,GPAGE0,GPAGE1,GPAGE2,GPAGE3)
vpage(B_TPAGE or B_GPAGE0 or B_GPAGE1 or B_GPAGE2 or B_GPAGE3,YES)
apage(GPAGE0)
//
// 全ファイルリストを得る
dim str fileList(256):// ()内は扱える最大ファイル数
int allcnt
int i,ret
str ext
//
// 拡張子(大文字小文字を区別するので注意)
// 正規表現
ext="PCM|pcm|wav|WAV|aiff|AIFF|M44|P16|M30":
allcnt=files(fileList,"",ext,YES,FILES_FILE,YES)
if allcnt<=0 then {
 locate(0,0)
 print localizedString("音声ファイルがありません":"Sound file not found.")
} else {
 int no
 for i=0 to allcnt-1
  locate(0,0):print fileList(i)
  str pext=pathExtension(fileList(i))
  strupr(pext)
  if pext="PCM" then {
   print "(ADPCM)"
   no=a_setPlayData(fileList(i),0)
  } else {
   no=a_setPlayData(fileList(i))
  }
  a_play(no)
  hitKey()
  a_end(no)
 next
}
end
//---------
func hitKey()
 setFunctionKey(0,localizedString("ここを押してください","Hit This Button"),'!')
 displayFunctionKey(YES,0,0)
 while inkey()=0
 endwhile
 cls()
 displayFunctionKey(NO,0,0)
endfunc
//---------
func str localizedString(js;str,es;str)
 if isLocalizeJapan() then return(js)
 return (es)
endfunc
//---------
音声サンプルを含む圧縮ファイルはこちら XBsoundloader.zip

2013年2月15日金曜日

しずくデモ

しずくが上から落ちてきて、いっぱいになったらまた最初から繰り返すデモです。
終了するには「×」を押してください。

/******************************************************************/
/* しずくデモ
/******************************************************************/
/* 内蔵フォントを使うので、全角文字もOK

/* これらは変数であって定数ではないので、グローバル配列の大きさ指定やcase値には使えない
int WX ://=(80/2)
int WY ://=24
int MAX =75  :/* 棚の本数   
int LNG =5  :/* 滴の最大長さ

/* 内部キャラクター
int WALL='#' :/* 外壁
int BALL='o' :/* 滴  
int TANA='=' :/* 棚 
int SPC =' ' :/* 空間

int dx,dy :/* 移動方向
int clng :/* 動作中ポインター
int retY :/* X-BASICレベルでは2つのリターン値を戻せないのでグローバル変数を経由する

dim int drpx(5)   :/* 移動x座標バッファー
dim int drpy(5)   :/* 移動y座標バッファー
dim char tvram(96,96) :/* 仮想VRAM / virtual video RAM
      :/* 機種によってサイズが可変なので、最大値で確保しておく

int wtt  :/* ウエイト

/******************************************************************/
/* メインルーチン
/******************************************************************/

getWidth(WX,WY):// システムの設定したテキスト画面サイズを得る
setUpScroll(NO):// テキスト画面の上スクロールを止める (V2.0)
 WX=WX/2
MAX=(WX*WY/13)
int ts,t
/*int c
 srand2() /* 乱数初期化
 wtt=CalcWait()/100*8:/* ウエイト算出(8ms)
 repeat
  InitScreen() :/* 画面初期化
  if Cascades() then break:/* 滴移動
  beep()
  locate(8,7)
  if isLocalizeJapan() then {
   print "もう一度見ますか? ";
  } else {
   print "Watch again ?";
  }
 /* c='Y';
  ts =time()
  repeat:/* 15秒たったら自動的に再開する
   t=time()
  until t-ts>=15
 until NO :/*(c<>'Y' && c<>CR)
end

/******************************************************************/
/* 以下内部関数
/******************************************************************/

func InitScreen()
/* 初期画面作成
int i,j,x,y
 cls()
 print "  CASCADES"
 init_tvram()

 /* 外枠作成
 for y=1 to WY-2:/* 縦
  storexy(   0,y,WALL)
  storexy(WX-1,y,WALL)
 next
 for x=0 to WX-1:/* 横
  storexy(x,WY-1,WALL)
 next

 /* 棚作成
 for i=0 to MAX-1
  x=1+rand2(WX-2) :/* 両端を除く
  y=2+rand2(WY-3) :/* 一番上とその次と最下行を除く
  for j=0 to 3
   if (x+j>=WX-1) then break /* x-over
   if (scrn(x+j,y)=SPC) then storexy(x+j,y,TANA)
  next
 next
 // 全画面一気表示
 printScreenAll(1,WY-1)
endfunc

/******************************************************************/

func int Cascades()
/* 滴処理
int x,y
//int ts=time():/* 開始時間
//int t,dt=0
 while CheckDropPoint()=0
  /* 開いているとき
  /* 初期位置設定
  x=SetFirstPoint()
  y=1
  repeat
   //t=time()
   //if t-ts>dt then { :/* 秒が変った
   // dt=dt+1
   // locate(30,0):print dt;
   //}
   //if inkey()=ESC then return(1)

   /* 移動&表示
   Drop(x,y)
   if clng=0 then break
   clng=clng-1
   x=drpx(clng)
   y=drpy(clng)
  until x=0 and y=0
 endwhile
 /* 最上行が開いていなかったら終わり
 return(0)
endfunc

/******************************************************************/

func int CheckDropPoint()
/* 最上行が開いているかどうかを調べる
int x
 for x=1 to WX-2
  if scrn(x,1)=SPC then return(0) :/* 開いている
 next
 return(1) :/* 開いていない
endfunc

/******************************************************************/

func int SetFirstPoint()
/* スタートポイント設定(最上行)
int i,x
 x=1+rand2(WX-2):/* 始点決定
 while scrn(x,1)<>SPC
  x=x+1
  if (x=WX-1) then x=1
 endwhile
 clng=LNG-1
 for i=0 to clng-1
  drpx(i)=0
  drpy(i)=0:/* 0=未記録の印
 next
 drpx(clng)=x
 drpy(clng)=1
 dx=0
 dy=1: /* 下へ
 return(x)
endfunc

/******************************************************************/

func Drop(x;int,y;int)
/* 移動&表示
int r,l
 while (YES)
  /* 表示
  printxy(x,y,BALL)
  TWait(wtt):/* ウエイト
  
  /* 下が開いている?
  if scrn(x,y+1)=SPC then {
   /* 無条件に下に落ちる
   dx=0
   dy=1
   x=Move(x,y)
   y=retY
   continue
  }
  
  /* 移動先チェック
  if scrn(x+dx,y+dy)=SPC then {
   /* 移動可能
   x=Move(x,y)
   y=retY
   continue
  }
  
  /* 移動先に移動できない時
  if (dy=1) then { :/* 下に落ちるはずだった時
   /* 左右チェック
   r=(scrn(x+1,y)=SPC):/* 右
   l=(scrn(x-1,y)=SPC):/* 左
   
   /* 動けるなら左右移動に変更
   dx=0
   if (r) then { :/* 右が開いている
    dx=1
   }
   if (l) then { :/* 左が開いている
    dx=-1
    if (r) then { :/* 右も開いている
     /* 左右どちらかを選ぶ
     if rand2(2)=1 then dx=1
    }
   }
   if dx<>0 then {:/* 動ける時
    dy=0
    x=Move(x,y)
    y=retY
    continue
   }
  }
  /* 動けないときはループ終了
  break
 endwhile
endfunc

/******************************************************************/

func int Move(x;int,y;int)
/* 移動&消し
int i
 if (drpy(0)<>0) then printxy(drpx(0),drpy(0),SPC):/* 前の場所を消す
 x=x+dx
 y=y+dy
 if (clng>=1) then {
  for i=1 to clng
   drpx(i-1)=drpx(i)
   drpy(i-1)=drpy(i)
  next
 }
 drpx(clng)=x
 drpy(clng)=y
 retY=y:/* 2つ目のリターン値はグローバル変数経由で返す
 return(x)
endfunc

/******************************************************************/
/* 仮想VRAMシステム
/******************************************************************/

func str printChar$(c;char)
/* 表示文字取得
str c$
 switch (c)
  case ' ': c$= " ":break :/* 消す  
  case 'o': c$= "●":break :/* しずく
  case '#': c$= "■":break :/* 外壁
  case '=': c$= "□":break :/* 棚
 endswitch
 return (c$)
endfunc

func printxy(x;int,y;int,c;char)
/* 文字表示
 /* 仮想VRAMに出力
 tvram(x,y)=c

 /* 座標変換
 locate(x*2,y)
 
 /* キャラクター変換して表示
 print printChar$(c);
endfunc

func storexy(x;int,y;int,c;char)
/* 仮想VRAMに出力
 tvram(x,y)=c
endfunc

func char scrn(x;int,y;int)
/* 仮想テキストVRAMを読み出す
 return(tvram(x,y))
endfunc

func printScreenAll(stY;int,edY;int)
/* 全画面一気表示
/* X-BASIC for iOSはテキスト画面表示が遅いので対策(V1.0時代の名残)
int x,y
str linestr
 for y=stY to edY
  linestr=""
  for x=0 to WX-1
   linestr=linestr+printChar$(tvram(x,y))
  next
  locate(0,y):print linestr;
 next
endfunc

func init_tvram()
/* 仮想テキストVRAM初期化
int x,y
 for y=0 to WY-1
  for x=0 to WX-1
   tvram(x,y)=SPC
  next
 next
endfunc

/******************************************************************/
/* 汎用関数
/******************************************************************/

func srand2()
/* rand()乱数を初期化する
int tm
 t=time()
 tm=tm and &h0fff
 tm=tm*16
 srand(tm)
endfunc

func int rand2(seed;int)
/* 0~seed-1の乱数発生
 return (rand() mod seed)
endfunc

/******************************************************************/

func int CalcWait()
/* ウエイト量算出
int tim,tm
int count
 /* 0クロックチェック
 tm=time()
 repeat
  tim=time()
 until tim-tm<>0
 count=0
 repeat
  tm=time()
  count=count+1
 until tm-tim<>0
 return(count):/* 1秒に必要なカウント数
endfunc

/******************************************************************/

func TWait(wt;int)
int i,tm
 for i=0 to wt-1
  tm=time()
 next
endfunc

/******************************************************************/

Zipファイル :XBetc.zip