//--------------------------------------------------------- // LED Game for AVR用 dotshow by takuya matsubara // ・このプログラムはHSP 3で動きます // ・パソコンとLEDゲームをAVRライタで接続する必要があります。 // // このプログラムはフリーソフトです。 //--------------------------------------------------------- #include "hspext.as" #define COL_MAX 16 //カラーテーブルの数 #define BINPACK 8 //1バイトパックするbit数 #define BITPIX 4 //1ピクセルあたりのビット数 #define INFOHSIZE 40 #define FILEHSIZE 14 #define TABLESIZE 4 #define FRAMEMAX 8 #define LEDWIDTH 16 #define FRAMESIZE 64 #define BARHEIGHT 40 #define DOTSZ 25 #define BTNWIDTH 70 #define COMNUM 1 //COM回線番号 sdim buf,512 sdim fbuf,246 screen 0,640,480,0,0,0 flag_comm =0 objsize BTNWIDTH,20 x=0 pos x,0:x+=BTNWIDTH button gosub "Bin Load",*led_load pos x,0:x+=BTNWIDTH button gosub "Send",*dotsend pos x,0:x+=BTNWIDTH button gosub "Recv",*dotrecv pos x,0:x+=BTNWIDTH button gosub "Page+",*pageup pos x,0:x+=BTNWIDTH button gosub "Page-",*pagedown pos x,0:x+=BTNWIDTH button gosub "BMP save",*frame_save pos x,0:x+=BTNWIDTH button gosub "Bin save",*led_save pos x,0:x+=BTNWIDTH button gosub "Cソース save",*cfile_save pos x,0:x+=BTNWIDTH color 0,0,0 boxf 0,0+BARHEIGHT,DOTSZ*16,DOTSZ*16+BARHEIGHT title "LED Game DotView" framenum=0 for i,0,512 poke buf,i,0 next gosub *drawbuf while 1 stick ky if(ky = 256){ ofs=0 gosub *dotset } if(ky = 512){ ofs=32 gosub *dotset } wait 5 wend end //-------------------------------------------------------------------------- *dotset mx = mousex my = mousey - BARHEIGHT if(my<0):return if(mx<0):return mx = mx / DOTSZ my = my / DOTSZ if(mx>15):return if(my>15):return adr = ofs+(FRAMESIZE * framenum)+1-(mx / 8)+(my * 2) poke buf, adr, (peek(buf,adr) ^ (0x80>>(mx \ 8))) gosub *drawbuf return //-------------------------------------------------------------------------- *pagedown framenum -- if(framenum < 0){ framenum=(FRAMEMAX-1) } goto *pagexx *pageup framenum ++ if(framenum > (FRAMEMAX-1)){ framenum=0 } *pagexx gosub *drawbuf return //-------------------------------------------------------------------- *drawbuf title "作業フレーム"+strf("%d",framenum+1)+"/"+strf("%d",FRAMEMAX) redraw 0 for fnum,0,FRAMEMAX adr = (FRAMESIZE * fnum) for y,0,16 for x,0,16,8 for ii,0,8 red=70 green=70 blue=70 if ((0x80>>ii) & peek(buf,adr+0)): red=255 if ((0x80>>ii) & peek(buf,adr+32)): green=255 color red,green,blue x1 = (8-x+ii)*2+(fnum*36) y1 = (y*2) +(16*DOTSZ)+ 44 boxf x1,y1,x1+1,y1+1 next adr++ next next next adr = (FRAMESIZE * framenum) for y,0,16 for x,0,16,8 for ii,0,8 red=70 green=70 blue=70 if ((0x80>>ii) & peek(buf,adr+0)): red=255 if ((0x80>>ii) & peek(buf,adr+32)): green=255 color red,green,blue x1 = (8-x+ii)*DOTSZ y1 = y*DOTSZ + BARHEIGHT boxf x1,y1,x1+DOTSZ-3,y1+DOTSZ-3 next adr++ next next redraw 1 return //-------------------------------------------------------------------- *connect_open if(flag_comm = 0){ comopen COMNUM,"baud=9600 parity=N data=8 stop=1" if stat : dialog "COM"+COMNUM+"は使えません" : end comput "0" //送信(マイコンのリセット解除) wait 50 flag_comm=1 } //-------------------------------------------------------------ゴミデータ消去 *gomiclear wait 50 repeat comgetc a //シリアルポートから1バイト受信 if(stat == 0):break loop return //-------------------------------------------------------------------------- *connect_close if(flag_comm = 1){ comclose //シリアルポートとの通信を終了します flag_comm=0 title "disconnect" } return //-------------------------------------------------------------------------- *dotsend gosub *connect_open dialog "LED Gameに全作業ページを書き込みます。AVRライタでLED Gameに接続してください",2 if(stat = 7):return for fnum,0,FRAMEMAX title "送信フレーム"+strf("%d",fnum+1)+"/"+strf("%d",FRAMEMAX) comput "W" //送信 書き込みコマンド wait 2 computc fnum //ページ番号 wait 2 adr = FRAMESIZE * fnum for i,0,FRAMESIZE computc peek(buf ,adr) wait 2 adr++ next wait 100 next dialog "書き込み完了しました",2 return //-------------------------------------------------------------------------- *dotrecv gosub *connect_open dialog "LED Gameから全ページを読み込みます。AVRライタでLED Gameに接続してください",2 if(stat = 7):return for fnum,0,FRAMEMAX title "受信フレーム"+strf("%d",fnum+1)+"/"+strf("%d",FRAMEMAX) comput "R" //受信コマンド wait 2 computc fnum //ページ番号 wait 2 adr = FRAMESIZE * fnum capcnt=0 while(capcnt < FRAMESIZE) comgetc a ;シリアルポートから1バイト受信 if(stat != 0){ poke buf,adr,a capcnt++ adr++ } wend wait 100 next dialog "読み込み完了しました",2 gosub *drawbuf return //-------------------------------------------------------------------------- *led_load dialog "BIN(バイナリ)形式でファイルを読み込みます" gosub *connect_close dialog "dot",16,"バイナリ" if(refstr=""):return bload refstr,buf framenum=0 dialog "読み込み完了" gosub *drawbuf return //-------------------------------------------------------------------------- *led_save dialog "BIN(バイナリ)ファイル形式で保存します" gosub *connect_close dialog "dot",17,"バイナリ" if(refstr=""):return bsave refstr,buf,FRAMESIZE*FRAMEMAX dialog "保存完了" return //-------------------------------------------------------------------------- *frame_save dialog "全作業ページをBMP(ビットマップ)ファイル形式で保存します" gosub *connect_close dialog "save to DOTS**.BMP",2 if (stat = 7):return for fnum,0,FRAMEMAX fname = "DOTS"+strf("%02d",fnum+1)+".bmp" title "saving "+fname gosub *bmp_save next dialog "complate" return //-------------------------------------------------------------------------- *bmp_save lHeadSize = (INFOHSIZE + FILEHSIZE + (TABLESIZE * COL_MAX)) //ヘッダサイズ lDataSize = (LEDWIDTH * (BINPACK / BITPIX) * LEDWIDTH) //データサイズ lTotalSize = lDataSize + lHeadSize //ファイル全体サイズ fp=0 //--------------file header a= 0x42:gosub *savebyte a= 0x4D:gosub *savebyte a= lTotalSize:gosub *savelong //ファイル全体サイズ a= 0:gosub *savelong a= lHeadSize:gosub *savelong //ヘッダ全体サイズ //---info header a= INFOHSIZE:gosub *savelong //header size a= LEDWIDTH:gosub *savelong //width a= LEDWIDTH:gosub *savelong //height a= 1:gosub *saveword //plane a= BITPIX:gosub *saveword //bitcount a= 0:gosub *savelong a= lDataSize:gosub *savelong //画像データサイズ a= 0:gosub *savelong a= 0:gosub *savelong a= 0:gosub *savelong a= 0:gosub *savelong //---table a= 0x000000:gosub *savelong //black a= 0xff0000:gosub *savelong //red a= 0x00ff00:gosub *savelong //green a= 0xffff00:gosub *savelong //yellow for i,0,12 a= 0:gosub *savelong next //---画像データ a=0 packcnt=0 for y,15,-1,-1 for x,8,-1,-8 p = (fnum*FRAMESIZE)+(y*2)+(x/8) for i,0,8 ccode=0 if ((0x80>>i) & peek(buf,p+0 )){ccode=ccode | 1} if ((0x80>>i) & peek(buf,p+32)){ccode=ccode | 2} a = a<<4 a = a | ccode packcnt++ if(packcnt>=2){ packcnt=0 gosub *savebyte a=0 } next p++ next next bsave fname,fbuf,fp return *savebyte poke fbuf,fp,(a & 0xff) fp++ return *saveword poke fbuf,fp,(a & 0xff) fp++ poke fbuf,fp,((a>>8) & 0xff) fp++ return *savelong poke fbuf,fp,(a & 0xff) fp++ poke fbuf,fp,((a>>8) & 0xff) fp++ poke fbuf,fp,((a>>16) & 0xff) fp++ poke fbuf,fp,((a>>24) & 0xff) fp++ return //-------------------------------------------------------------------------- *cfile_save dialog "全作業ページをCソースファイル形式で保存します" dialog "c",17,"cファイル" if stat=0 : return cbuf = "" cbuf = cbuf+"unsigned int bindat[]={\n" i=0 for fnum,0,FRAMEMAX for a,0,16 cbuf = cbuf+"0x"+ strf("%02x",peek(buf,i+1))+ strf("%02x",peek(buf,i+0)) cbuf = cbuf+", /* RED "+strf("%02d",a)+" */" cbuf = cbuf+"\n" i+=2 next for a,0,16 cbuf = cbuf+"0x"+ strf("%02x",peek(buf,i+1))+ strf("%02x",peek(buf,i+0)) cbuf = cbuf+", /* GREEN "+strf("%02d",a)+" */" cbuf = cbuf+"\n" i+=2 next next cbuf = cbuf+"};\n" bsave refstr,cbuf,strlen(cbuf) ; Cファイルをセーブ return