0
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?

z88dk C言語で MSX ゲームプログラミング初級 Part03

0
Last updated at Posted at 2026-01-30

main.h
#include <stdint.h>

void put(uint8_t x, uint8_t y, char* str);
main.c
#include "main.h"

#include "bios.h"

void main() {
  BIOS_CHGMOD(1);  // スクリーン・モード1に変更
  BIOS_CLS();

  // カタカナは半角カタカナで入力し、ファイルをShift-JISで保存する
  put(1, 1, "マウガ セメコンデ キマシタ");
  put(1, 3, "1.タタカウ");
  put(1, 5, "2.ニゲル");

  while (1) {
    uint8_t key = *(uint8_t*)(NEWKEY + 0);  // 0行目のキーコードを取得

    if (key == 253) {
      // 1キーが押された場合(テンキーの1ではない)
      put(1, 7, "マオウニショウリシ ヘイワガ オトズレマシタ");
      put(1, 9, "GAME CLER!");
      break;
    }

    if (key == 251) {
      // 2キーが押された場合(テンキーの2ではない)
      put(1, 7, "マオウガ セカイヲ ホロボシマシタ");
      put(1, 9, "GAME OVER");
      break;
    }
  }
}

void put(uint8_t x, uint8_t y, char* str) {
  // 0x1800は、スクリーン・モード1の、VRAMのパターンネームテーブルの開始アドレス
  // 32は、スクリーン・モード1の1行あたりのバイト数
  BIOS_LDIRVM(str, 0x1800 + 32 * y + x, strlen(str));
}
bios.h
#include <stdint.h>

/*
現在押下されているキーマトリクスの値が格納されているワークエリアのアドレス
0行:0xFBE5~10行:0xFBF5
参考URL: キースキャン
https://ngs.no.coocan.jp/doc/wiki.cgi/TechHan?page=3%BE%CF+%A5%AD%A1%BC%A5%DC%A1%BC%A5%C9%A1%A6%A5%A4%A5%F3%A5%BF%A1%BC%A5%D5%A5%A7%A5%A4%A5%B9
*/
#define NEWKEY 0xFBE5

void BIOS_CLS();
void BIOS_CHGMOD(uint8_t mode);
void BIOS_LDIRVM(char* src, uint16_t* dst, uint16_t len);
bios.c
#include <bios.h>

//	機能	スクリーン・モードを変える。パレットは初期化しない。
//	入力	A にスクリーンモード (0~8)
void BIOS_CHGMOD(uint8_t mode) {
#asm
	LD		IX, 2
	ADD		IX, SP
	LD		A, (IX)		;//	A = mode
	CALL	005FH
#endasm
}

//	機能	画面クリア
void BIOS_CLS() {
#asm
	XOR		A		;//ゼロフラグをセット
	CALL	00C3H
#endasm
}

//	機能	メモリから VRAM へブロック転送
//	入力	HL にソース・アドレス (メモリ)、DE にデスティネーション・アドレス (VRAM)、BC に長さ。指定する VRAM のアドレスは全ビット有効
void BIOS_LDIRVM(char* src, uint16_t* dst, uint16_t len) {
#asm
	LD		IX, 2
	ADD		IX, SP
	LD		BC,(IX)		;//	len
	LD		DE,(IX+2)	;//	dst	
	LD		HL,(IX+4)	;//	src
	CALL	005CH
#endasm
}


0
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
0
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?