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 ゲームプログラミング初級 Part04

0
Posted at

main.h
#include <stdint.h>
#include <stdio.h>

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

#include "bios.c"

uint8_t lv = 1;
uint8_t is_wait = 0;

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

  while (1) {
    BIOS_CLS();

    // カタカナは半角カタカナで入力し、ファイルをShift-JISで保存する
    uint8_t buf[10];
    sprintf(buf, "ユウシャ Lv %d", lv);
    put(1, 1, buf);
    put(1, 3, "マウガ セメコンデ キマシタ");
    put(1, 5, "1.タタカウ");
    put(1, 7, "2.ニゲル");
    put(1, 9, "3.キタエル");

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

      if (is_wait) {
        if (key != 255) {
          // キーの押下が解除されるまでスキップ
          continue;
        }

        if (BIOS_GTTRIG(0) == 0xff || BIOS_GTTRIG(1) == 0xff) {
          // スペースキーかジョイスティック1のボタンが押された場合
          is_wait = 0;
          break;
        }
        continue;
      }

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

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

      if (key == 247) {
        // 3キーが押された場合(テンキーの3ではない)
        put(1, 11, "ユウシャハ レベルガ アガッタ");
        put(1, 13, "hit [space] key");
        lv++;
        is_wait = 1;
      }
    }
  }
}

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.c
#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

//	機能	スクリーン・モードを変える。パレットは初期化しない。
//	入力	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
}

// 機能	トリガボタンの状態を返す
// 入力	A に調べるトリガボタンの番号
//      0: キーボードのスペースキー
//      1: ジョイスティック1のボタン
// 出力 A が 0 ならばトリガボタンは押されていない
//      A が 0FFH ならトリガボタンは押されている
uint8_t BIOS_GTTRIG(uint8_t* triger) {
#asm
	LD		IX, 2
	ADD		IX, SP
	LD		A, (IX)		; A = triger
	CALL	00D8H
	LD		L, A		; 戻り値を L レジスタにセット
	LD		H, 0
#endasm
}
ビルドコマンド.
zcc +msx -create-app -subtype=rom -o main.rom main.c
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?