Skip to content

Instantly share code, notes, and snippets.

@axsann
Last active February 21, 2023 14:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axsann/142619439b15fcbe446a9ea7a2e76f71 to your computer and use it in GitHub Desktop.
Save axsann/142619439b15fcbe446a9ea7a2e76f71 to your computer and use it in GitHub Desktop.
typing_pro.py カナ対応版
import x68k
import machine
import uctypes
import time
from struct import pack
w_data =[
["47","ホエホエ","コンニチハ","ンター","ウルウル","オヒサデス","ポ","ヒョヒョ","プププ","ナンタラカタラ","パモパモ"],
["46","クマ","サル","クジラ","アルマジロ","ナマケモノ","ラッコ","オランウータン","シマリス","エリマキトカゲ","ライチョウ"],
["59","フルイケヤ","カワズトビコム","ミズノオト","ナツクサヤ","ツワモノドモガ","ユメノアト","メニアオバ","ヤマ","ホトトギス","ハツガツオ"],
["52","apple","mxdrv","mankai","gradius","python","basic","screen","files","list","run"]
]
htime =[0,20,30,30,30]
ptime =[0,0,0,0,0]
# main
def main():
# initialize screen
x68k.crtmod(12,True)
x68k.curoff()
x68k.iocs(x68k.i.TXFILL,a1=pack('6h',0,0,0,1024,1024,0))
x68k.iocs(x68k.i.TXFILL,a1=pack('6h',1,0,0,1024,1024,0))
x68k.iocs(x68k.i.BOX,a1=pack('6h',0,0,511,511,0xffff,0xffff))
while True:
print("          記録")
print("1.チャッターコース " + str(htime[1]) + "秒")
print("2.動物さん コース " + str(htime[2]) + "秒")
print("3.俳句さん コース " + str(htime[3]) + "秒")
print("4.英語さん コース " + str(htime[4]) + "秒")
course = input("どのコースでいきますか?(4)")
i = int(course)
if i < 1 or i > 4:
continue
ptime[i] = time.time()
for j in range(10):
w = w_data[i-1][j+1]
print()
print(w)
t = 1
codes = list(bytes(w, 'ascii'))
wlen = len(codes)
#for t in range(len(w_data[i-1][j+1])):
while (t < wlen+1):
#print("t" + str(t) ,end="")
#q = inkey$(0)
q = x68k.getc()
if q < ord(" "):
continue
x68k.putchar(q)
#if q != mid$(w_data[i-1][j],t,1)
if q != codes[t-1]:
#beep
print("\a",end="")
#print("\033[1D" ,end="")
print(chr(0x08), end="")
continue
t = t + 1
print()
ptime[i]= time.time() - ptime[i]
print("所要時間" + str(ptime[i]) + "秒")
print("一文字平均時間" + str(ptime[i]/int(w_data[i-1][0])) + "秒")
if ptime[i] < htime [i]:
print("新記録でっせ!")
htime[i]=ptime[i]
# cursor on
x68k.curon()
if __name__ == "__main__":
main()
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2023 Yuichi Nakamura
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/* 追記 */
#include <x68k/dos.h>
/************************************追記分****************************************/
STATIC mp_obj_t x68k_getc(void) {
int d = _dos_getc();
return MP_OBJ_NEW_SMALL_INT(d);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(x68k_getc_obj, x68k_getc);
STATIC mp_obj_t x68k_putchar(mp_obj_t o_in) {
mp_int_t c = MP_OBJ_SMALL_INT_VALUE(o_in);
_dos_putchar(c);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(x68k_putchar_obj, x68k_putchar);
/****************************************************************************/
STATIC const mp_rom_map_elem_t mp_module_x68k_globals_table[] = {
/* 追記分 */
{ MP_ROM_QSTR(MP_QSTR_getc), MP_ROM_PTR(&x68k_getc_obj) },
{ MP_ROM_QSTR(MP_QSTR_putchar), MP_ROM_PTR(&x68k_putchar_obj) },
};
@axsann
Copy link
Author

axsann commented Feb 16, 2023

micropython.xのgetc(), putchar()対応版のバイナリはこちら↓

https://drive.google.com/file/d/1GHxa7lWmpIWcINrSMVoKR16TSX7PSerQ/view?usp=share_link

  • x68k.getc()とx68k.putchar()を追加
  • (さりげなくimport jsonにも対応)

====
オリジナル版(yunkさん):https://github.com/yunkya2/micropython-x68k

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment