Compare commits

..

2 Commits

Author SHA1 Message Date
Yourtion
b2d31a8e54 MML播放器 2016-05-20 13:38:43 +08:00
Yourtion
72532c8cd7 文本阅览器 2016-05-20 12:03:41 +08:00
19 changed files with 651 additions and 1 deletions

View File

@@ -23,7 +23,7 @@ haribote.img : haribote/ipl20.bin haribote/haribote.sys Makefile \
sosu/sosu.hrb sosu2/sosu2.hrb sosu3/sosu3.hrb \
type/type.hrb iroha/iroha.hrb chklang/chklang.hrb \
notrec/notrec.hrb bball/bball.hrb invader/invader.hrb \
calc/calc.hrb
calc/calc.hrb tview/tview.hrb mmlplay/mmlplay.hrb
$(EDIMG) imgin:../z_tools/fdimg0at.tek \
wbinimg src:haribote/ipl20.bin len:512 from:0 to:0 \
copy from:haribote/haribote.sys to:@: \
@@ -56,6 +56,12 @@ haribote.img : haribote/ipl20.bin haribote/haribote.sys Makefile \
copy from:bball/bball.hrb to:@: \
copy from:invader/invader.hrb to:@: \
copy from:calc/calc.hrb to:@: \
copy from:tview/tview.hrb to:@: \
copy from:mmlplay/mmlplay.hrb to:@: \
copy from:mmldata/kirakira.mml to:@: \
copy from:mmldata/fujisan.mml to:@: \
copy from:mmldata/daigo.mml to:@: \
copy from:mmldata/daiku.mml to:@: \
copy from:nihongo/nihongo.fnt to:@: \
imgout:haribote.img
@@ -100,6 +106,8 @@ full :
$(MAKE) -C bball
$(MAKE) -C invader
$(MAKE) -C calc
$(MAKE) -C tview
$(MAKE) -C mmlplay
$(MAKE) haribote.img
run_full :
@@ -152,6 +160,8 @@ clean_full :
$(MAKE) -C bball clean
$(MAKE) -C invader clean
$(MAKE) -C calc clean
$(MAKE) -C tview clean
$(MAKE) -C mmlplay clean
src_only_full :
$(MAKE) -C haribote src_only
@@ -183,6 +193,8 @@ src_only_full :
$(MAKE) -C bball src_only
$(MAKE) -C invader src_only
$(MAKE) -C calc src_only
$(MAKE) -C tview src_only
$(MAKE) -C mmlplay src_only
-$(DEL) haribote.img
refresh :

BIN
30_day/mmldata/daigo.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>CQ7<B-Q4GE-
Q7<B->B->B-B-E-GGGE-<B-B-B-GE-E-E-
Q8<B-Q7>DDDQ8E-Q7>GGGE-<B-B-B-GE-E-E-
Q8<B-Q7>B-B-B-B-4R4.B-B-B-B-4R4.>DDDE-4
R1R4

BIN
30_day/mmldata/daiku.mml Normal file

Binary file not shown.

17
30_day/mmldata/daiku.org Normal file
View File

@@ -0,0 +1,17 @@
/* 「交響曲第9番 ニ短調 "合唱" op.125」より Ludwig van Beethoven 尾崎喜八作詞 */
$E"SJIS"; T110L4
O4
$K"晴れたる青空 漂う雲よ"; F+F+GA AGF+E DDEF+ F+.E8E2
$K"小鳥は歌えり 林に森に"; F+F+GA AGF+E DDEF+ E.D8D2
$K"心は爽やか 喜び満ちて"; EEF+D EF+8G8F+D EF+8G8F+E DE<A>
$K"見交わす我らの 明るき笑顔"; F+& F+F+GA AGF+E DDEF+ E.D8D2
O5
$K"花咲く丘べに 憩える友よ"; F+F+GA AGF+E DDEF+ F+.E8E2
$K"吹く風爽やか みなぎる陽射し"; F+F+GA AGF+E DDEF+ E.D8D2
$K"心は穏やか 幸せ溢れ"; EEF+D EF+8G8F+D EF+8G8F+E DE<A>
$K"響くは我らの 喜びの歌"; F+& F+F+GA AGF+E DDEF+ E.D8D2
$K""; R1

BIN
30_day/mmldata/fujisan.mml Normal file

Binary file not shown.

View File

@@ -0,0 +1,15 @@
/* 「富士山」 文部省唱歌 巌谷小波作詞 */
$E"SJIS"; T120L4O4
$K"あたまを雲の上に出し"; G.G8AGEC8D8E2 D.G8GF8E8D2.R
$K"四方の山を見おろして"; G.G8ECA.B8>C<A G.A8G8F8E8D8C2.R
$K"かみなりさまを下に聞く"; D.D8DDC8D8E8F8G2 A.B8>C<AG2.R
$K"富士は日本一の山"; >C2<AGE.E8AG FED.C8C2.R
$K"青空高くそびえ立ち"; G.G8AGEC8D8E2 D.G8GF8E8D2.R
$K"からだに雪の着物着て"; G.G8ECA.B8>C<A G.A8G8F8E8D8C2.R
$K"霞のすそを遠く曳く"; D.D8DDC8D8E8F8G2 A.B8>C<AG2.R
$K"富士は日本一の山"; >C2<AGE.E8AG FED.C8C2.R
$K""; R1R1

BIN
30_day/mmldata/kirakira.mml Normal file

Binary file not shown.

View File

@@ -0,0 +1,13 @@
/* 「きらきら星」 フランス民謡 武鹿悦子作詞 */
$E"SJIS"; T120L4O4
$K"きらきらひかる お空の星よ"; CCGGAAG2 FFEEDDC2
$K"まばたきしては みんなを見てる"; GGFFEED2 GGFFEED2
$K"きらきらひかる お空の星よ"; CCGGAAG2 FFEEDDC2
$K""; R1
$K"きらきらひかる お空の星よ"; CCGGAAG2 FFEEDDC2
$K"みんなの歌が 届くといいな"; GGFFEED2 GGFFEED2
$K"きらきらひかる お空の星よ"; CCGGAAG2 FFEEDDC2
$K""; R1 R1

View File

@@ -0,0 +1 @@
command

View File

@@ -0,0 +1 @@
cmd.exe

5
30_day/mmlplay/Makefile Normal file
View File

@@ -0,0 +1,5 @@
APP = mmlplay
STACK = 132k
MALLOC = 0k
include ../app_make.txt

1
30_day/mmlplay/make.bat Normal file
View File

@@ -0,0 +1 @@
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

271
30_day/mmlplay/mmlplay.c Normal file
View File

@@ -0,0 +1,271 @@
#include "apilib.h"
#include <string.h> /* strlen */
int strtol(char *s, char **endp, int base); /*标准函数<stdlib.h> */
void waittimer(int timer, int time);
void end(char *s);
void HariMain(void)
{
char winbuf[256 * 112], txtbuf[100 * 1024];
char s[32], *p, *r;
int win, timer, i, j, t = 120, l = 192 / 4, o = 4, q = 7, note_old = 0;
/*音号与频率mHz的对照表*/
/*例如04A为440Hz即440000 */
/*第16八度的A为1802240Hz即1802240000 */
/*以下为第16八度的列表CB */
static int tonetable[12] = {
1071618315, 1135340056, 1202850889, 1274376125, 1350154473, 1430438836,
1515497155, 1605613306, 1701088041, 1802240000, 1909406767, 2022946002
};
static int notetable[7] = { +9, +11, +0 /* C */, +2, +4, +5, +7 };
/*命令行解析*/
api_cmdline(s, 30);
for (p = s; *p > ' '; p++) { } /*一直读到空格为止*/
for (; *p == ' '; p++) { } /*跳过空格*/
i = strlen(p);
if (i > 12) {
file_error:
end("file open error.\n");
}
if (i == 0) {
end(0);
}
/*准备窗口*/
win = api_openwin(winbuf, 256, 112, -1, "mmlplay");
api_putstrwin(win, 128, 32, 0, i, p);
api_boxfilwin(win, 8, 60, 247, 76, 7);
api_boxfilwin(win, 6, 86, 249, 105, 7);
/*载入文件*/
i = api_fopen(p);
if (i == 0) {
goto file_error;
}
j = api_fsize(i, 0);
if (j >= 100 * 1024) {
j = 100 * 1024 - 1;
}
api_fread(txtbuf, j, i);
api_fclose(i);
txtbuf[j] = 0;
r = txtbuf;
i = 0; /*通常模式*/
for (p = txtbuf; *p != 0; p++) { /*为了方便处理,将注释和空白删去*/
if (i == 0 && *p > ' ') { /*不是空格或换行符*/
if (*p == '/') {
if (p[1] == '*') {
i = 1;
} else if (p[1] == '/') {
i = 2;
} else {
*r = *p;
if ('a' <= *p && *p <= 'z') {
*r += 'A' - 'a'; /*将小写字母转换为大写字母*/
}
r++;
}
} else if (*p == 0x22) {
*r = *p;
r++;
i = 3;
} else {
*r = *p;
r++;
}
} else if (i == 1 && *p == '*' && p[1] == '/') { /*段注释*/
p++;
i = 0;
} else if (i == 2 && *p == 0x0a) { /*行注释*/
i = 0;
} else if (i == 3) { /*字符串*/
*r = *p;
r++;
if (*p == 0x22) {
i = 0;
} else if (*p == '%') {
p++;
*r = *p;
r++;
}
}
}
*r = 0;
/*定时器准备*/
timer = api_alloctimer();
api_inittimer(timer, 128);
/*主体*/
p = txtbuf;
for (;;) {
if (('A' <= *p && *p <= 'G') || *p == 'R') { /*音符、休止符*/
/*计算频率*/
if (*p == 'R') {
i = 0;
s[0] = 0;
} else {
i = o * 12 + notetable[*p - 'A'] + 12;
s[0] = 'O';
s[1] = '0' + o;
s[2] = *p;
s[3] = ' ';
s[4] = 0;
}
p++;
if (*p == '+' || *p == '-' || *p == '#') {
s[3] = *p;
if (*p == '-') {
i--;
} else {
i++;
}
p++;
}
if (i != note_old) {
api_boxfilwin(win + 1, 32, 36, 63, 51, 8);
if (s[0] != 0) {
api_putstrwin(win + 1, 32, 36, 10, 4, s);
}
api_refreshwin(win, 32, 36, 64, 52);
if (28 <= note_old && note_old <= 107) {
api_boxfilwin(win, (note_old - 28) * 3 + 8, 60, (note_old - 28) * 3 + 10, 76, 7);
}
if (28 <= i && i <= 107) {
api_boxfilwin(win, (i - 28) * 3 + 8, 60, (i - 28) * 3 + 10, 76, 4);
}
if (s[0] != 0) {
api_beep(tonetable[i % 12] >> (17 - i / 12));
} else {
api_beep(0);
}
note_old = i;
}
/*音长计算*/
if ('0' <= *p && *p <= '9') {
i = 192 / strtol(p, &p, 10);
} else {
i = l;
}
for (; *p == '.'; ) {
p++;
i += i / 2;
}
i *= (60 * 100 / 48);
i /= t;
if (s[0] != 0 && q < 8 && *p != '&') {
j = i * q / 8;
waittimer(timer, j);
api_boxfilwin(win, 32, 36, 63, 51, 8);
if (28 <= note_old && note_old <= 107) {
api_boxfilwin(win, (note_old - 28) * 3 + 8, 60, (note_old - 28) * 3 + 10, 76, 7);
}
note_old = 0;
api_beep(0);
} else {
j = 0;
if (*p == '&') {
p++;
}
}
waittimer(timer, i - j);
} else if (*p == '<') { /*八度-- */
p++;
o--;
} else if (*p == '>') { /*八度++ */
p++;
o++;
} else if (*p == 'O') { /*八度指定*/
o = strtol(p + 1, &p, 10);
} else if (*p == 'Q') { /* Q参数指定*/
q = strtol(p + 1, &p, 10);
} else if (*p == 'L') { /*默认音长指定*/
l = strtol(p + 1, &p, 10);
if (l == 0) {
goto syntax_error;
}
l = 192 / l;
for (; *p == '.'; ) {
p++;
l += l / 2;
}
} else if (*p == 'T') { /*速度指定*/
t = strtol(p + 1, &p, 10);
} else if (*p == '$') { /*扩展命令*/
if (p[1] == 'K') { /*卡拉OK命令*/
p += 2;
for (; *p != 0x22; p++) {
if (*p == 0) {
goto syntax_error;
}
}
p++;
for (i = 0; i < 32; i++) {
if (*p == 0) {
goto syntax_error;
}
if (*p == 0x22) {
break;
}
if (*p == '%') {
s[i] = p[1];
p += 2;
} else {
s[i] = *p;
p++;
}
}
if (i > 30) {
end("karaoke too long.\n");
}
api_boxfilwin(win + 1, 8, 88, 247, 103, 7);
s[i] = 0;
if (i != 0) {
api_putstrwin(win + 1, 128 - i * 4, 88, 0, i, s);
}
api_refreshwin(win, 8, 88, 248, 104);
}
for (; *p != ';'; p++) {
if (*p == 0) {
goto syntax_error;
}
}
p++;
} else if (*p == 0) {
p = txtbuf;
} else {
syntax_error:
end("mml syntax error.\n");
}
}
}
void waittimer(int timer, int time)
{
int i;
api_settimer(timer, time);
for (;;) {
i = api_getkey(1);
if (i == 'Q' || i == 'q') {
api_beep(0);
api_end();
}
if (i == 128) {
return;
}
}
}
void end(char *s)
{
if (s != 0) {
api_putstr0(s);
}
api_beep(0);
api_end();
}

View File

@@ -0,0 +1 @@
command

View File

@@ -0,0 +1 @@
cmd.exe

5
30_day/tview/Makefile Normal file
View File

@@ -0,0 +1,5 @@
APP = tview
STACK = 1024k
MALLOC = 0k
include ../app_make.txt

1
30_day/tview/make.bat Normal file
View File

@@ -0,0 +1 @@
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

276
30_day/tview/tview.c Normal file
View File

@@ -0,0 +1,276 @@
#include "apilib.h"
#include <stdio.h>
int strtol(char *s, char **endp, int base); /* 标准函数 <stdlib.h> */
char *skipspace(char *p);
void textview(int win, int w, int h, int xskip, char *p, int tab, int lang);
char *lineview(int win, int w, int y, int xskip, unsigned char *p, int tab, int lang);
int puttab(int x, int w, int xskip, char *s, int tab);
void HariMain(void)
{
char winbuf[1024 * 757], txtbuf[240 * 1024];
int w = 30, h = 10, t = 4, spd_x = 1, spd_y = 1;
int win, i, j, lang = api_getlang(), xskip = 0;
char s[30], *p, *q = 0, *r = 0;
/*命令行解析*/
api_cmdline(s, 30);
for (p = s; *p > ' '; p++) { } /*一直读到空格为止*/
for (; *p != 0; ) {
p = skipspace(p);
if (*p == '-') {
if (p[1] == 'w') {
w = strtol(p + 2, &p, 0);
if (w < 20) {
w = 20;
}
if (w > 126) {
w = 126;
}
} else if (p[1] == 'h') {
h = strtol(p + 2, &p, 0);
if (h < 1) {
h = 1;
}
if (h > 45) {
h = 45;
}
} else if (p[1] == 't') {
t = strtol(p + 2, &p, 0);
if (t < 1) {
t = 4;
}
} else {
err:
api_putstr0(" >tview file [-w30 -h10 -t4]\n");
api_end();
}
} else { /*找到文件名*/
if (q != 0) {
goto err;
}
q = p;
for (; *p > ' '; p++) { } /*一直读到空格为止*/
r = p;
}
}
if (q == 0) {
goto err;
}
/*准备窗口*/
win = api_openwin(winbuf, w * 8 + 16, h * 16 + 37, -1, "tview");
api_boxfilwin(win, 6, 27, w * 8 + 9, h * 16 + 30, 7);
/*载入文件*/
*r = 0;
i = api_fopen(q);
if (i == 0) {
api_putstr0("file open error.\n");
api_end();
}
j = api_fsize(i, 0);
if (j >= 240 * 1024 - 1) {
j = 240 * 1024 - 2;
}
txtbuf[0] = 0x0a; /*卫兵用的换行代码*/
api_fread(txtbuf + 1, j, i);
api_fclose(i);
txtbuf[j + 1] = 0;
q = txtbuf + 1;
for (p = txtbuf + 1; *p != 0; p++) { /*为了让处理变得简单删掉0x0d的代码*/
if (*p != 0x0d) {
*q = *p;
q++;
}
}
*q = 0;
/*主体*/
p = txtbuf + 1;
for (;;) {
textview(win, w, h, xskip, p, t, lang);
i = api_getkey(1);
if (i == 'Q' || i == 'q') {
api_end();
}
if ('A' <= i && i <= 'F') {
spd_x = 1 << (i - 'A'); /* 1, 2, 4, 8, 16, 32 */
}
if ('a' <= i && i <= 'f') {
spd_y = 1 << (i - 'a'); /* 1, 2, 4, 8, 16, 32 */
}
if (i == '<' && t > 1) {
t /= 2;
}
if (i == '>' && t < 256) {
t *= 2;
}
if (i == '4') {
for (;;) {
xskip -= spd_x;
if (xskip < 0) {
xskip = 0;
}
if (api_getkey(0) != '4') { /*如果没有按下“4”则处理结束*/
break;
}
}
}
if (i == '6') {
for (;;) {
xskip += spd_x;
if (api_getkey(0) != '6') {
break;
}
}
}
if (i == '8') {
for (;;) {
for (j = 0; j < spd_y; j++) {
if (p == txtbuf + 1) {
break;
}
for (p--; p[-1] != 0x0a; p--) { } /*回溯到上一个字符为0x0a为止*/
}
if (api_getkey(0) != '8') {
break;
}
}
}
if (i == '2') {
for (;;) {
for (j = 0; j < spd_y; j++) {
for (q = p; *q != 0 && *q != 0x0a; q++) { }
if (*q == 0) {
break;
}
p = q + 1;
}
if (api_getkey(0) != '2') {
break;
}
}
}
}
}
char *skipspace(char *p)
{
for (; *p == ' '; p++) { } /*跳过空格*/
return p;
}
void textview(int win, int w, int h, int xskip, char *p, int tab, int lang)
{
int i;
api_boxfilwin(win + 1, 8, 29, w * 8 + 7, h * 16 + 28, 7);
for (i = 0; i < h; i++) {
p = lineview(win, w, i * 16 + 29, xskip, p, tab, lang);
}
api_refreshwin(win, 8, 29, w * 8 + 8, h * 16 + 29);
return;
}
char *lineview(int win, int w, int y, int xskip, unsigned char *p, int tab, int lang)
{
int x = - xskip;
char s[130];
for (;;) {
if (*p == 0) {
break;
}
if (*p == 0x0a) {
p++;
break;
}
if (lang == 0) { /* ASCII */
if (*p == 0x09) {
x = puttab(x, w, xskip, s, tab);
} else {
if (0 <= x && x < w) {
s[x] = *p;
}
x++;
}
p++;
}
if (lang == 1) { /* SJIS */
if (*p == 0x09) {
x = puttab(x, w, xskip, s, tab);
p++;
} else if ((0x81 <= *p && *p <= 0x9f) || (0xe0 <= *p && *p <= 0xfc)) {
/*全角字符*/
if (x == -1) {
s[0] = ' ';
}
if (0 <= x && x < w - 1) {
s[x] = *p;
s[x + 1] = p[1];
}
if (x == w - 1) {
s[x] = ' ';
}
x += 2;
p += 2;
} else {
if (0 <= x && x < w) {
s[x] = *p;
}
x++;
p++;
}
}
if (lang == 2) { /* EUC */
if (*p == 0x09) {
x = puttab(x, w, xskip, s, tab);
p++;
} else if (0xa1 <= *p && *p <= 0xfe) {
/*全角字符*/
if (x == -1) {
s[0] = ' ';
}
if (0 <= x && x < w - 1) {
s[x] = *p;
s[x + 1] = p[1];
}
if (x == w - 1) {
s[x] = ' ';
}
x += 2;
p += 2;
} else {
if (0 <= x && x < w) {
s[x] = *p;
}
x++;
p++;
}
}
}
if (x > w) {
x = w;
}
if (x > 0) {
s[x] = 0;
api_putstrwin(win + 1, 8, y, 0, x, s);
}
return p;
}
int puttab(int x, int w, int xskip, char *s, int tab)
{
for (;;) {
if (0 <= x && x < w) {
s[x] = ' ';
}
x++;
if ((x + xskip) % tab == 0) {
break;
}
}
return x;
}