2013/03/05

Bomb Sweeper Game

This is "Minesweeper" so-called.
This is required "bomb11.aiff" file.
/*****************************************************************
// bomb sweeper
//    Copyright (C) 1993,2012 by AIG-SOFT
/*****************************************************************
/* variable(like constant)

font("IPAGothic")
int fzenhan
int WX=64
int WY=width(WX,,fzenhan)
int xw=1
if fzenhan then xw=2

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

int MX =(WX/2)-2    :/* map max x width (-2 for frame)
int MY =19          :/* map max y heigh
int MXX=5           :/* map min x width
int MYY=4           :/* map min y height

int BOMB='*'                  :/* bomb code:'*'=&h2a =< &h3f
int ERR=9                     :/* Judgment mistake
int BMBIT=bit(7)              :/* bit for should bomb
int CHBIT=bit(6)              :/* unknown bit
int OPBIT=(BMBIT or CHBIT)    :/* bits for open status
int NOPBIT=(not OPBIT)        :/* bits for get character only

/* screen home position
int SX=2    :/* sx>=2 & sx+(MX+1)*2< screen x width
int SY=4    :/* sy>=4 & sy+MY+1    < screen y height

int ESC=&h1B
int CR =&h0d

/*****************************************************************
/* global variable

dim char map( (64/2),19)    :/* current map
dim char map0((64/2),19)    :/* virtual screen

dim int    touchNo(10)      :// Touch area No.
int touchCnt     :// The number of touch area

int wx,wy        :/* map width
int seed,bomb    :/* the number of bomb and should bomb
int all          :/* the number of point on all should open
int ts,dt        :/* start time, elapsed time

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

int ret
int minbomb,maxbomb
/* set field width and the number of bombs
str widthStr,heightStr,bombStr,defaultStr,messageStr
if isLocalizeJapan() then {
    widthStr ="横幅"
    heightStr="縦幅"
    minbomb=MXX*MYY/8 :/* min 1/8
    maxbomb=wx*wy/2     :/* max 1/2
    bombStr="爆弾数"
    defaultStr="標準"
    messageStr="メッセージ"
} else {
    widthStr ="width "
    heightStr="height"
    minbomb=MXX*MYY/8 :/* min=1/8
    maxbomb=wx*wy/2     :/* max=1/2
    bombStr="bombs"
    defaultStr="default"
    messageStr="message"
}
    print widthStr ;"(";MXX;"~";MX;")";
    dim str menues(3)={"10","20","30"}
    menues(3)=defaultStr
    wx=selectMenu(widthStr,menues):// last item of selectMenu() is special
    if wx=3 then wx=2
    wx=(wx+1)*10
    print wx
//    input wx
    print heightStr;"(";MYY;"~";MY;")";
    menues={"5","10","15","19"}
    repeat
        wy=selectMenu2(heightStr,menues)
    until wy<>-1
    wy=5*(wy+1)
    print wy
//    input wy
    
    if wx<MXX then wx=MXX
    if wx>MX  then wx=MX
    if wy<MYY then wy=MYY
    if wy>MY  then wy=MY
    minbomb=MXX*MYY/8 :/* min=1/8
    maxbomb=wx*wy/2     :/* max=1/2
    print bombStr;"(";minbomb;"~";maxbomb")";
    menues={"50","100","150","200"}
    seed=selectMenuWithMessage(bombStr,messageStr,menues)
    seed=50*(seed+1)
    print seed
//    input seed
    if seed<minbomb then seed=minbomb
    if seed>maxbomb then seed=maxbomb

int sno=a_setPlayData("bomb11.aiff")
a_play(sno)

/* main routine
repeat
    /* initialize random number
    srand2()
    
    /* place bombs
    all=BombSeed(seed)
    bomb=0
    BombCount()
    dt=0:/* elapsed time
    
    /* display initial screen
    InitScreen()

    /* key operation
    ret=CursorMove()
    
    /* end check
    if ret=-2 then break:/* force end
    switch ret
        case -1:/* try again
            MapPrintAll(YES):/* display all
            break
        case 0: /* Game clear
            GameClear()
            break
        case 1: /* Game over
            MapPrintAll(YES):/* display all
            GameOver()
            break
    endswitch

    /* Try again
    locate(20,2)
    if isLocalizeJapan() then {
        print "《もう一度しますか?》";
        setFunctionKey(0,"はい"  ,CR)
        setFunctionKey(1,"いいえ",ESC)
    } else {
        print "<< Try Again ? >>";
        setFunctionKey(0,"YES",CR)
        setFunctionKey(1,"NO" ,ESC)
    }
    displayFunctionKey(YES,0,1)
    repeat
        ret=inkey()
    until ret<>0
    displayFunctionKey(NO,0,1)
    // remove touch area
    // Once release and re-set up. Otherwise, it will continue to overlap area.
    resetTouchArea()
until (ret=ESC)
a_end(sno):// release sound buffer
if isLocalizeJapan() then {
    print "終了"
} else {
    print "end"
}
end

/*****************************************************************
/* Functions
/*****************************************************************

func int CursorMove()
/* cursor move and operation
int x,y,c
int t
    /* initial position
    /* move cursor to no bomb place
    for x=0 to wx-1
        for y=0 to wy-1
            if ((map(x,y) and NOPBIT)<>BOMB) then goto "CM1"
        next
    next
label "CM1"
    ts=time():/* start time
    while YES
        /* reverse display at cursor point
        c=map(x,y)
        tatrb(ATRB_REVERSE)
        locate2(x,y)
        print printChr$(c);
        tatrb(ATRB_NORMAL)
        
        // timer count until key input
//        int cnt=0
        while (not kbhit())
            /* until key input none
            t=time()
            if t-ts>dt then { :/* change second
                dt=dt+1
                PrintTime(dt)
//                beep2(0)
//                print "cnt=";cnt
            }
//            inc(cnt)
        endwhile
        
        /* normal display at cursor point
        locate2(x,y)
        print printChr$(c);
        //
        // key operation
        c=inkey()
        beep2(0)    :// click sound
        switch c
            case &h1b: /* retry
                return(-1)
            
            /* cursor roll at screen edge
            case '2': /* ↓
                if y<wy-1 then y=y+1 else y=0
                break
            case '4': /* ←
                if x>0 then x=x-1 else x=wx-1
                break
            case '6': /* →
                if x<wx-1 then x=x+1 else x=0
                break
            case '8': /* ↑
                if y>0 then y=y-1 else y=wy-1
                break
            
            case '5': /* Check
                CheckMapPoint(x,y)
                MapPrint()
                /* The check should not be open to all
                break
            
            case ' ': /* Open
                if OpenMapPoint(x,y) then return(YES):/* game over
                /* display
                if MapPrint() then return(NO)
                break
        endswitch
    endwhile
    return (YES)
endfunc

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

func int MapPrint()
/* diaplay map and update virtual screen
/* return:0=It is not already open all , 1=open all
int x,y,c
int all0=0
    for y=0 to wy-1
        for x=0 to wx-1
            c=map(x,y)
            if map0(x,y)<>c then {
                /* update screen
                locate2(x,y)
                print printChr$(c)
                map0(x,y)=c:/* update virtual screen
            }
            /* count open point
            if ((c and OPBIT)=OPBIT) then all0=all0+1
        next
    next
    return(all0=all)
endfunc

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

func MapPrintAll(mode;int)
/* display map all
/* mode : 0=is still , 1=all open (With a judgment mistake)
int x,y,c
str ls
    for y=0 to wy-1
        ls=""
        for x=0 to wx-1
            c=map(x,y)
            if mode then {
                if (c and OPBIT)=BMBIT then {
                    /* checked with 'bomb is here'
                    /* if there is no bomb then it is doubt
                    if (c and NOPBIT)<>BOMB then c=ERR
                }
                c=(c or OPBIT):/* open
            }
            ls=ls+printChr$(c)
        next
        locate2(0,y)
        print ls
    next
    // color(7)
endfunc

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

func str printChr$(c;int)
/* display character
/* c : bit6,7 = opened(11)/check mark(10)/bomb mark(01)/close(00)
/*     bit0-5 = map status &h00 - &h3f
str cs
    int cc=(c and OPBIT)
    if cc=0 then {
        /* close
        return ("□")
    }
    if cc=CHBIT then {
        /* CHBIT check marking
        return ("?")
    }
    if cc=BMBIT then {
        /* bomb is here marking
        return ("☆")
    }
    if cc=OPBIT then {
        /* opend
        switch (c and NOPBIT)
            case  0:cs= "・":break
            case  1:cs= "1":break
            case  2:cs= "2":break
            case  3:cs= "3":break
            case  4:cs= "4":break
            case  5:cs= "5":break
            case  6:cs= "6":break
            case  7:cs= "7":break
            case  8:cs= "8":break
            case  9:/* mistake
                cs= "×"
                break
            case '*':/* bomb
                cs= "★"
                break
        endswitch
    }
    return (cs)
endfunc

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

func locate2(x;int,y;int)
    locate(SX+(x)*xw,SY+y)    :/* *xw for double-width character
endfunc

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

func WakuPrint(yoko;str,tate;str,kado;str,fall;int)
/* display map frame
int i
    /* horizontal line
    str yokos=""
    for i=0 to wx-1:yokos=yokos+yoko:next
    locate2(0,-1):print yokos
    locate2(0,wy):print yokos

    /* vertical line
    if fall then {
        // erase internal = fast
        str tates=tate+space$(wx*xw)+tate
        for i=0 to wy-1
            locate2(-1,i):print tates;
        next
    } else {
        // redraw border only = slow
        for i=0 to wy-1
            locate2(-1,i):print tate;
            locate2(wx,i):print tate;
        next
    }
    
    /* corner
    locate2(-1,-1):print kado;
    locate2(-1,wy):print kado;
    locate2(wx,-1):print kado;
    locate2(wx,wy):print kado;
endfunc

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

func InitScreen()
/* display initial screen
    cls()
    WakuPrint("-","|","+",YES)
    MapPrintAll(NO)
    locate(5,0)
    if isLocalizeJapan() then {
        print using "マップ幅:##×##  爆弾数:###/###  時間:#####";wx,wy,bomb,seed,dt
            /*         0         1           2         3          4    
            /*        +0123456789012345678901234567890123456789012    
            /*        +locate
    } else {
        print using "map size:##×##  bombs :###/###  time:#####";wx,wy,bomb,seed,dt
    }
    str open$,exit$
    if isLocalizeJapan() then {
        open$="開く"
        exit$="中断"
    } else {
        open$="open"
        exit$="exit"
    }
    int x=WX/2-18
    int y=SY+wy+2
                    //     012345678901234567890123456789
    locate(x,y+0):print "      ┏━┓"
    locate(x,y+1):print "      ┃↑┃"
    locate(x,y+2):print "      ┗━┛"
    locate(x,y+3):print "┏━┓┏━┓┏━┓    ┏━━┓"
    locate(x,y+4):print "┃←┃┃?┃┃→┃    ┃";open$;"┃"
    locate(x,y+5):print "┗━┛┗━┛┗━┛    ┗━━┛"
    locate(x,y+6):print "      ┏━┓"
    locate(x,y+7):print "      ┃↓┃"
    locate(x,y+8):print "      ┗━┛"
    
    int i=0
    touchNo(inc(i))=setTouchAreaWithText(x+ 6,y  ,xw*3,3,'8',YES,125,0,5,100)
    touchNo(inc(i))=setTouchAreaWithText(x+ 6,y+6,xw*3,3,'2',YES,125,0,5,100)
    touchNo(inc(i))=setTouchAreaWithText(x   ,y+3,xw*3,3,'4',YES,125,0,5,100)
    touchNo(inc(i))=setTouchAreaWithText(x+12,y+3,xw*3,3,'6',YES,125,0,5,100)
    //
    touchNo(inc(i))=setTouchAreaWithText(x+ 6,y+3,xw*3,3,'5',YES,150,50, 5,120):/* check
    touchNo(inc(i))=setTouchAreaWithText(x+22,y+3,xw*4,3,' ',YES,150, 5 ,5,120):/* open
    touchCnt=i
    //
    setFunctionKey(0,exit$,ESC)
    displayFunctionKey(YES,0,0)
endfunc

func resetTouchArea()
int i
    for i=0 to touchCnt
        removeTouchArea(touchNo(i))
    next
    touchCnt=0
endfunc

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

func PrintBombCount()
/* display left bombs
    locate(5+26,0)
    print using "###";bomb
endfunc

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

func PrintTime(dt;int)
/* display time
    locate(5+42,0)
    print using "#####";dt
endfunc

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

func GameClear()
/* display game clear screen
    /* change frame design
    beep()
    WakuPrint("◇","◇","◇",NO)
    beep()
    locate(6,1)
    if isLocalizeJapan() then {
        print "§§ おめでとう! あなたは総ての爆弾を捜し当てました §§";
    } else {
        print "<< Congratulations! You've turned up the bomb of all >>";
    }
endfunc

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

func GameOver()
/* display game over screen
    /* change frame design
    a_play(sno)
    WakuPrint("☆","☆","☆",NO)
    a_play(sno)
    locate(10,1)
    if isLocalizeJapan() then {
        print "@@ あなたは爆弾にぶち当たってしまいました @@";
    } else {
        print "@@ You've hit a bomb @@";
    }
endfunc

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

func CheckMapPoint(x;int,y;int)
/* check point on the map
int c
    c=map(x,y)
    c=(c and OPBIT)
    if c=OPBIT then {
        /* already open
        /* Reopen the place is open waste
        beep()
        return()
    }
    if c=0 then {
        /* closed -> probable bomb
        map(x,y)=(BMBIT or map(x,y))
        bomb=bomb+1
        PrintBombCount()
        return()
    }
    if c=BMBIT then {
        /* probable bomb -> check please
        map(x,y)=(c and NOPBIT)or CHBIT
        return()
    }
    if c=CHBIT then {
        /* please check -> close
        map(x,y)=(NOPBIT and map(x,y))
        bomb=bomb-1
        PrintBombCount()
    }
endfunc

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

func int OpenMapPoint(x;int,y;int)
/* open point on the map
int c
    c=map(x,y)
    if ((c and OPBIT)=OPBIT) then {
        /* already open
        /* Reopen the place is open waste
        beep()
        return(NO):/* nothing to do without warning
    }
    if ((c and NOPBIT)=BOMB) then {
        /* open bomb
        a_play(sno)
        return(YES):/* game over
    }
    /* There is open so it is not already open
    if (c=0) then {
        /* If there is no bomb around open in the paint type
        PaintMap(x,y)
    } else {
        /* When there is at least one bomb around, the only one open point
        map(x,y)=(OPBIT or map(x,y)):/* opened symbol
    }
    return(NO)
endfunc

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

func PaintMap(x;int,y;int)
/* open 0 point from map (x,y)
/* Basically it is same as the paint routine, but it is different to open border
int c,xs,xe
    if map(x,y)<>0 then {
        /* if the first point is not zero then end
        return()
    }
    /* 0 <- x : left search
    xe=x+1 :/* point that is search start right
    while x>=0
        c=map(x,y)
        if ((c and OPBIT)=0) then {
            map(x,y)=(OPBIT or map(x,y))
        }
        if (c<>0) then break:/* border
        /* open border too
        // Border is not bomb.
        // Bacause there are from 1 to 8 around the bomb always.
        x=x-1:/* to left
    endwhile
    if x<0 then xs=0 else xs=x
    /* xs=Leftmost segment(include with border)

    /* x -> wx-1 : right search
    while xe<=wx-1
        c=map(xe,y)
        if (c and OPBIT)=0 then map(xe,y)=(OPBIT or map(xe,y))
        if c<>0 then break:/* order
        xe=xe+1 :/* to right
    endwhile
    if xe=wx then xe=xe-1
    /* xe=rightmost segment(include with border)
    if y>0    then PaintMapSub(xs,xe,y-1):/* upper check
    if y<wy-1 then PaintMapSub(xs,xe,y+1):/* lower check
endfunc

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

func PaintMapSub(xs;int,xe;int,yy;int)
/* PaintMap() subroutine : for upper/lower check
int x,c
    for x=xs to xe
        c=map(x,yy)
        if c=0 then {
            PaintMap(x,yy)
        } else {
            if (c and OPBIT)=0 then map(x,yy)=(OPBIT or map(x,yy)):/* open with border
        }
    next
endfunc

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

func int BombSeed(seeds;int)
/* bomb placement in the map
/* seeds : the number of bomb < wx*wy
/* random initialize outside
int x,y
int all
    /* map clear
    for y=0 to wy-1
        for x=0 to wx-1
            map(x,y)=0
        next
    next
    
    /* Number must be open to all non-bomb
    all=wx*wy-seeds
    
    /* bomb placement
    while seeds>0
        x=rand2(wx)
        y=rand2(wy)
        if map(x,y)=0 then {
            /* Set bombs
             map(x,y)=BOMB:/* map
            map0(x,y)=BOMB:/* virtual screen
            seeds=seeds-1 :/* decrement left bomb
        }:/* When there is a bomb there already will look for another location
    endwhile
    
    return(all)
endfunc

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

func BombCount()
/* Write bomb status in the map
/* Writing in advance the number of bomb around each point
int x,y,xx,yy,xs,ys,xe,ye,c
    for y=0 to wy-1
        ys=y-1:if ys<0    then ys=0
        ye=y+1:if ye>wy-1 then ye=wy-1
        for x=0 to wx-1
            if map(x,y)=BOMB then continue:/* skip bomb
            xs=x-1:if xs<0    then xs=0
            xe=x+1:if xe>wx-1 then xe=wx-1
            /* count around
            c=0
            for yy=ys to ye
                for xx=xs to xe
                    if map(xx,yy)=BOMB then c=c+1
                next
            next
            /* c=0~8
             map(x,y)=c:/* map
            map0(x,y)=c:/* virtual screen
        next
    next
endfunc

/*****************************************************************
/* General functions
/*****************************************************************

func srand2()
/* initialize rand()
int tm=time()
    tm=tm and &h0fff
    tm=tm * 16
    srand(tm)
endfunc

func rand2(seed;int)
    return (rand() mod seed):/* generate random number 0 to seed-1
endfunc

/*****************************************************************
Zip file including sound file is here : XBbs.zip

2013/03/04

List all SHIFT-JIS code (SHIFT-JIS version)

List almost all in SHIFT-JIS which X68000 was supporting.
This internal processing is SHIFT-JIS, all work fine.
Please run under SHIFT-JIS forced mode is ON.
// SHIFT-JIS Version(Forced SHIFT-JIS mode)
// X-BASIC for iOS can not text screen scroll, so it is displayed page by page.
    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
    // The previous function key display will not erase automatically when changing the number.
    // The user must erase(View overlaps with otherwise).
    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)
/* Double-Width character display 
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
            repeat
                ky=inkey()
            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:/* The chatacter which low 8bit code<$40 is none
        
        /* print adrs 
        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 { :/* undefined character
                if fzenhan then {
                    print "**";
                } else {
                    print "*";
                }
            } else {
                c=(i+j)
                print chr$(c);    :/* This was treated on the assumption that it does not cause a carry on the way
            }
        next
        print
        i=i+16-1::/* +1 in below 'next'
    next
    return (NO)
endfunc

func print_code0(fzenhan;int)
/* half width character display 
int li
int j,c
    print_head()
    for li=&h20 to &he0-1
        /* skip area 
        if li=&h80 then print_skip()
        if li>=&h80 and li<=&h9f then continue
        
        /* print adrs 
        print "  ";hex2$(li);"  :";
        /* print character
        for j=0 to 16-1
            print " ";
            c=li+j
            if c=&h7f or c=&ha0 then c='*'
            print chr$(c);
            if fzenhan then print " ";:/* if Double-width equal half-width*2 then print space
        next
        print
        li=li+16-1:/* +1 in below 'next'
    next
endfunc

Zip file : XBetc.zip

2013/03/01

Motion function test

This is motion function's test.
Displays the information that you tilt the device.
//----------------------------------------------------------------------------------------------
// motion test
//----------------------------------------------------------------------------------------------

print "versionXBiOSMotion$=";versionXBiOSMotion$()

setFunctionKey(0,"end"   ,'!')
setFunctionKey(1,"pause" ,'p')
setFunctionKey(2,"start" ,'s')
setFunctionKey(3,"clear" ,'c')
setFunctionKey(4,"degree",'d')
setFunctionKey(5,"veloc" ,'v')
setFunctionKey(6,"rotate",'r')
displayFunctionKey(YES,0,6)
kBackgroundAlpha(0.9)

int mode=MOTION_DEGREE
if motionStart(10,mode) then {
    print localizedString("モーションは使えません","Can't use motion.")
    end
}
printMode(mode)

float x,y,z
int ky,cnt,i

while YES
    if not kbhit() then {
        i=0
        cnt=motionCount()
        if cnt>0 then locate(0,1):print "cnt=";cnt
        while cnt>0
            x=motionGetRotation(y,z)
            locate(0,2+i)
            if mode=MOTION_ROTATION then {
                if isLocalizeJapan() then {
                    print using "左右=+#.####,上下=+#.####,方位=+#.####";x,y,z
                } else {
                    print using "pitch=+#.####,roll=+#.####,yaw=+#.####";x,y,z
                }
            } else {
                if mode=MOTION_DEGREE then {
                    if isLocalizeJapan() then {
                        print using "角度:x=+##.####,y=+##.####,z=+##.####";x,y,z
                    } else {
                        print using "degree:x=+##.####,y=+##.####,z=+##.####";x,y,z
                    }
                } else {
                    if isLocalizeJapan() then {
                        print using "角速度:x=+##.####,y=+##.####,z=+##.####";x,y,z
                    } else {
                        print using "velocity:x=+##.####,y=+##.####,z=+##.####";x,y,z
                    }
                }
            }
            cnt=cnt-1
            i=i+1
            if kbhit() then break
        endwhile
    } else {
        ky=inkey()
        switch ky
            case 'p'
                motionPause(YES)
                print "Pause"
                break
            case 's'
                motionPause(NO)
                print "Start"
                break
            case 'c'
                cls()
                motionClear()
                break
            case 'd'
                mode=MOTION_DEGREE
                motionSelectData(mode)
                cls()
                motionClear()
                printMode(mode)
                break
            case 'v'
                mode=MOTION_VELOCITY
                motionSelectData(mode)
                cls()
                motionClear()
                printMode(mode)
                break
            case 'r'
                mode=MOTION_ROTATION
                motionSelectData(mode)
                cls()
                motionClear()
                printMode(mode)
                break
            default:
                // 念のため / just in case
                beep()
                break
        endswitch
        if ky='!' then break
    }
endwhile
motionEnd()
end

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

func printMode(mode;int)
    locate(0,2)
    if mode=MOTION_DEGREE   then print localizedString("角度     ","DEGREE  ")
    if mode=MOTION_VELOCITY then print localizedString("角速度   ","VEROCITY")
    if mode=MOTION_ROTATION then print localizedString("オイラー角","EULER   ")
endfunc

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

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

Zip file : XBtests.zip

2013/02/28

List all SHIFT-JIS code (UTF8 version)

List almost all SHIFT-JIS code which was supported in X68000.
It produced SHIFT-JIS code in arithmetic, and it convert to UTF8 when displaying.
Please run under SHIFT-JIS forced mode is OFF.
/* List all SHIFT-JIS code by UTF8
// X-BASIC for iOS can not text screen scroll, so it is displayed page by page.
    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
    // The previous function key display will not erase automatically when changing the number.
    // The user must erase(View overlaps with otherwise).
    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)
/* Double-Width character display 
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 { :/* change second
                    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:/* The chatacter which low 8bit code<$40 is none
        
        /* print adrs 
        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 { /* undefined character
                if fzenhan then {
                    print "**";
                } else {
                    print "*";
                }
            } else {
                c=sjisToUtf8(i+j)
                print chr$(c); :/* This was treated on the assumption that it does not cause a carry on the way
            }
        next
        print
        i=i+16-1:/* +1 in below 'next'
    next
    return (NO)
endfunc

func print_code0(fzenhan;int)
/* half width character display 
int li
int j,c
    print_head()
    for li=&h20 to &he0-1
        /* skip area 
        if li=&h80 then print_skip()
        if li>=&h80 and li<=&h9f then continue
        
        /* print adrs 
        print "  ";hex2$(li);"  :";
        /* print character
        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 " ";:/* if Double-width equal half-width*2 then print space
        next
        print
        li=li+16-1:/* +1 in below 'next'
    next
endfunc

Zip file is here : XBetc.zip

2013/02/27

Bingo game

Bingo game. You play against the computer.
This has set up a lot of the touch area.
This is only for iPad within portlait because of screen size.
//--------------------------------------------------------------------------------
/* 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:// constant
/*
srand2()
width(64)
getWidth(WX,WY)
setUpScroll(NO):// disable to up scroll (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():// set numbers
    field_print():// display numbers and set touch area
    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 {
                // not found 
                // Human side only
                L=1
                beep()
                // input retry
            }
        until ffind
        locate(cx,cy):print d
    until (F>=5) or (E>=5)
    resetALlKeys():// remove touch area
    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)
/* game decision
    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()
/* human's number select
int num
//    kbclr()
    // wait key input
    while not kbhit()
    endwhile
    // if you touch the grid then return keycode as number
    num=inkey()
    return(num)
endfunc
/*
func int check_num(d;int)
/* check number and grid open
int h,x,y,ac,bb,i,j
    for h=1 to 2:// check both
        // get grid coordinate from number
        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 {
            // not found
            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:/* opened symbol
        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
    // found and processed
    return (YES)
endfunc
/*
func int com_num()
/* computer thinking
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()
/* clear part of screen
    int y
    for y=16 to WY
        locate(0,y):print space$(WX);
    next
endfunc
/*
func shuffle()
/* shuffle the number in grid
int i,j,l,h
int c,x,y
    for l=0 to 1:/* l=0:you , 1=computer
        /* enter number to grid in order
        /* A(i,j) : j=1〜5:yours , 6〜11:computer
        h=0
        for i=1 to 5
            for j=1 to 5
                h=h+1
                A(i,j+l*6)=h
            next
        next
        /* exchange number
        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)
/* display the number in grid
// mode : NO=Human , YES=Computer
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:/* opened grid
                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:/* opened grid
                locate(x+36,y):print using "##";c
            }
        next
    next
endfunc
/*
func field_print()
/* draw field
// In advance that you'll accept the number with shuffle()
int l,i,j
    for l=0 to 1:/* l=0:You , 1=Computer
        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  ")
        }
        // draw 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 {
                    // set toucha area
                    // only human area
                    // keyCode is the number
                    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()
// reset all key touch area (important)
    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)
// calc graphic coordinate from grid coordinate
int x,y
    x=textX2Gx((i-1)*5+7)+l*340
    y=textY2Gy(j*2+2)
    // below return value (grobal variable)
    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()
/* title screen
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()
/* random number initialize
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 file is here : XBbingo.zip

2013/02/26

e-Mail function's test

This is a sample program of e-mail function. Please be prepared to png file separately to make the attachment.
//------------------------------------------------
/* eMailSend() test
//------------------------------------------------

dim str fileList(256):// Inside () is the maximum number of files that can be handled
int cnt
// Test with changing here png->jpeg
cnt=files(fileList,"","bas",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)no attachment
if isLocalizeJapan() then {
 print "(1)添付なし"
 emailSend("件名1","本文1")
} else {
 print "(1)no attachment"
 emailSend("subject1","body1")
}
//hitKey()
// (2)attach each file
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)attach with zip archive
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 archive file : XBtests.zip

2013/02/25

Compass Functions Test

This is a test program of electronic compass function.

This can not use in iPod touch because iPod touch does not have electric compass.
This is the difference between iPhone and iPod touch except phone function.
//----------------------------------------------------------------------------------------------
// compass test
//----------------------------------------------------------------------------------------------

print "version Motion=";versionXBiOSMotion$()

font("Cochin",6):// Function Key's Font
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:
    // just in case
    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 archive file : XBtests.zip