1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MSX キーボードイベント

Posted at
kbevt.c
/*
z80dk kbevt.c キーボードイベント
zcc +msx -lndos -create-app kbevt.c

WebMSXにa.casをドロップ
bload"cas:",r
*/

#include <stdio.h>

int snsmat(int line)
{
#asm
	ld	a, l
	call	$0141		; SNSMAT
	ld	l, a
	ld	h, 0
#endasm
}

char *mat[][] = {
	{ "7", "6", "5", "4", "3", "2", "1", "0" },
	{ "+", "[", "@", "\\", "^", "-", "9", "8" },
	{ "B", "A", "_", "/", ">", "<", "]", "*" },
	{ "J", "I", "H", "G", "F", "E", "D", "C" },
	{ "R", "Q", "P", "O", "N", "M", "L", "K" },
	{ "Z", "Y", "X", "W", "V", "U", "T", "S" },
	{ "F3", "F2", "F1", "KANA", "CPAS", "GRAPH", "CTRL", "SHIFT" },
	{ "RETURN", "SELECT", "BS", "STOP", "TAB", "ESC", "F5", "F4" },
	{ "RIGHT", "DOWN", "UP", "LEFT", "DEL", "INS", "CLS", "SPACE" },
	{ "4", "3", "2", "1", "0", "/", "+", "*" },
	{ ".", ",", "-", "9", "8", "7", "6", "5" }
};

void main()
{
	int bits[2][11];
	int iold = 0;
	int inew = 1;

	for (int i = 0; i <= 10; i++) {
		bits[iold][i] = snsmat(i);
	}

	for (;;) {
		for (int i = 0; i <= 10; i++) {
			bits[inew][i] = snsmat(i);
		}
		for (int i = 0; i <= 10; i++) {
			int bold = bits[iold][i];
			int bnew = bits[inew][i];
			int diff = bold ^ bnew;
			if (diff) {
				int bit = 0x80;
				for (int j = 0; j < 8; j++) {
					if (diff & bit) {
						printf("%s %s\n", mat[i][j],
							(bnew & bit) ? "Up" : "Down");
					}
					bit >>= 1;
				}
			}
		}
		iold = inew;
		inew = 1 - iold;
	}
}

ROMカートリッジ版

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?