Skip to content

Instantly share code, notes, and snippets.

@shinh
Last active February 26, 2024 09:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinh/10e2285430f07fc3c2e8b0ff397ab862 to your computer and use it in GitHub Desktop.
Save shinh/10e2285430f07fc3c2e8b0ff397ab862 to your computer and use it in GitHub Desktop.
MN-Core2 vsm ゴルフ

https://projects.preferred.jp/mn-core/ で MN-Core2 のエミュレータとアセンブラが公開されたということで、喜び勇んでゴルフ場に足そうと準備してたのですが、ゴルフ場 32bit やんけ!と気付いて悲しくなりました

まぁせっかく標準入出力をつなぐスクリプトを書いたので、 caddy というの経由でゴルフ場の問題を楽しめる手順を説明する gist です。環境は x86-64 の Linux を使ってください

caddy を取ってきます

$ git clone https://github.com/shinh/caddy.git
$ cd caddy

問題一覧をゴルフ場から取ってきます

$ caddy update
Installing config.rb into /home/i/.golf/config.rb
Initializing DB in /home/i/.golf
Enter your user name: <enter your name>  # 名前を適当に入力
Downloading problem.db...
Downloading hello world.db...
...
# かなり時間がかかります
...

同梱の invert_case.vsm をローカルテストします。うまくいけば初回はエミュレータとアセンブラをダウンロードします

$ caddy -l invert_case.vsm
invert_case corresponds to
 0: none of below
 1: invert case (909)
 2: Inverse Quine (5384)
 3: UPPERCASE (5555)
 4: Convert to hex (5714)
 5: inverse matrix (5714)
Input 0-5 [1] ? : 1  # ここで 1 を入力
Loading testcases of 'invert case'
Test #1... 26 instructions
OK 0.669868782
Test #2... 26 instructions
OK 1.610155305
Test #3... 26 instructions
OK 1.009584558
...

標準入出力は $p0 という場所にヌル終端で置かれます

Hello, world! が既に若干苦労しました……

imm ui"0" $n0
imm ui"0x48656c6c" $r2
imm ui"0x6f2c2077" $r3
imm ui"0x6f726c64" $r0
imm ui"0x21000000" $r1
sor $subpeid $n0 $omr1
nop
lpassa $lr2 $lr0/$imr1
nop/2
# d get $lr0n0c0b0m0 1
l1bmrsbor $llr0v $llb0
nop/3
# d get $lb0n0c0b0 1
l2bmrsbor $lb0 $lc0
# d get $lc0n0c0 1
nop/3
mvp/n64i01 $lc0@.0 $p0
nop; wait i01
# http://golf.shinh.org/p.rb?invert+case
imm ui"0x20202020" $n0
imm ui"0x20200000" $n1
mvp/n64i01 $p0 $lc0@.0
nop; wait i01
l2bmb $lc0 $lb0
nop/3
l1bmm $lb0 $lr0v
nop/3
lxor $ln0 $lr0 $lr0
nop/3
l1bmrsbor $llr0v $llb0
nop/3
l2bmrsbor $lb0 $lc0
nop/3
mvp/n64i01 $lc0@.0 $p0
nop; wait i01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment