<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Z80 &#8211; EXPERTGIG</title>
	<atom:link href="https://expertgig.jp/tag/z80/feed/" rel="self" type="application/rss+xml" />
	<link>https://expertgig.jp</link>
	<description>工場IoT に特化したシステム開発</description>
	<lastBuildDate>Mon, 06 Apr 2026 04:38:20 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>今年は細々とMZ80Kのマシン語を組む</title>
		<link>https://expertgig.jp/2026/01/30/%e4%bb%8a%e5%b9%b4%e3%81%af%e7%b4%b0%e3%80%85%e3%81%a8mz80k%e3%81%ae%e3%83%9e%e3%82%b7%e3%83%b3%e8%aa%9e%e3%82%92%e7%b5%84%e3%82%80/</link>
					<comments>https://expertgig.jp/2026/01/30/%e4%bb%8a%e5%b9%b4%e3%81%af%e7%b4%b0%e3%80%85%e3%81%a8mz80k%e3%81%ae%e3%83%9e%e3%82%b7%e3%83%b3%e8%aa%9e%e3%82%92%e7%b5%84%e3%82%80/#respond</comments>
		
		<dc:creator><![CDATA[Ariyuki Tano]]></dc:creator>
		<pubDate>Fri, 30 Jan 2026 12:45:46 +0000</pubDate>
				<category><![CDATA[マイコン]]></category>
		<category><![CDATA[情報発信基地]]></category>
		<category><![CDATA[MZ-80]]></category>
		<category><![CDATA[Z80]]></category>
		<category><![CDATA[エミュレータ]]></category>
		<category><![CDATA[マシン語]]></category>
		<guid isPermaLink="false">https://expertgig.jp/?p=6118</guid>

					<description><![CDATA[去年(2025) はPC-8001向けに、マシン語のゲームを2つ作成したので、今年(2026) は来年の干支 「羊」をテーマにしたゲームをMZ-80Kのマシン語で開発することにする。同じZ80なのでPC-8001向けにプ [&#8230;]]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="6118" class="elementor elementor-6118" data-elementor-post-type="post">
						<section class="elementor-section elementor-top-section elementor-element elementor-element-b7754f7 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="b7754f7" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-2734d9b" data-id="2734d9b" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-3ffaf46 elementor-widget elementor-widget-text-editor" data-id="3ffaf46" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>去年(2025) はPC-8001向けに、マシン語のゲームを2つ作成したので、今年(2026) は来年の干支 「羊」をテーマにしたゲームをMZ-80Kのマシン語で開発することにする。同じZ80なのでPC-8001向けにプログラミングするのとそんなに違いはありませんが、私の一番思い入れの強いMZ-80K2向けにオールマシン語でゲームを開発するというのは大変意味のある事なんです(笑)。</p>
<p>とはいえ、実機を使って当時のアセンブラで開発するというは、現代ではなかなかの苦行ですので、例によってクロス開発環境を整える。</p>
<p>Z80のアセンブリコードは秀丸を利用。<br />アセンブラは AILZ80ASM を利用。<br />.mztファイルの生成には DumpListEditor Ver 0.80を利用。</p>
<p>こんな構成で行きます。<br />PC8001のときから少し時間がたってしまったので、手順をおさらいします。</p>
<p>テストコードとして、「VRAMをクリアして、VRAMの先頭からディスプレイコードすべてを書き込む」というプログラムを作成します。</p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-8aa20da elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="8aa20da" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-9def595" data-id="9def595" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-7b0831b elementor-widget elementor-widget-heading" data-id="7b0831b" data-element_type="widget" data-e-type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">1. 秀丸でアセンブリコードを記述して保存</h2>				</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-9b183a7 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="9b183a7" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-e742c15" data-id="e742c15" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap">
							</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-d8863a6 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="d8863a6" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-ab333d3" data-id="ab333d3" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-0221cb6 elementor-widget elementor-widget-code-highlight" data-id="0221cb6" data-element_type="widget" data-e-type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-less line-numbers">
				<code readonly="true" class="language-less">
					<xmp>;============================================================
; MZ-80K Display Code Table Viewer
;============================================================

            ORG     1200h

;----------------------------
; MZ-80K 定義
;----------------------------
VRAM        EQU     0D000h	; テキストVRAM先頭
COLS        EQU     40		; 画面の横文字数
ROWS        EQU     25		; 画面の縦文字数
VRAM_SIZE   EQU     COLS*ROWS	; 1000 bytes
SPC         EQU     00h		; スペース

;============================================================
START:
;----------------------------
; 1) VRAMクリア（SPC=$00）
;----------------------------
	LD	HL, VRAM
	LD	(HL), SPC
	LD	DE, VRAM+1
	LD	BC, VRAM_SIZE-1
	LDIR

;----------------------------
; 2) 表示コードを 00h→FFh 順に書く
;----------------------------
	LD	HL, VRAM
	LD	A, 00h

DISP_LOOP:
	LD	(HL), A		; VRAMに文字を書きこむ
	INC	HL		;
	INC	A		; 00→01→…→FF→00…

	CP	FFh
	JR	NZ, DISP_LOOP

;----------------------------
; 3) CPU停止
;----------------------------
STOP_CPU:
	HALT

END
</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-51db709 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="51db709" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-754ae2c" data-id="754ae2c" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-8a5ff8e elementor-widget elementor-widget-text-editor" data-id="8a5ff8e" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>保存するファイル名を VRAMTEST.z80 として保存します。</p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-b969496 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="b969496" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b041249" data-id="b041249" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-9de71e2 elementor-widget elementor-widget-heading" data-id="9de71e2" data-element_type="widget" data-e-type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">2. アセンブラでバイナリファイルを生成</h2>				</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-514a902 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="514a902" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-3edb7f9" data-id="3edb7f9" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-78561bd elementor-widget elementor-widget-text-editor" data-id="78561bd" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>AILZ80ASMはコマンドラインで利用するアセンブラですので、次のような batファイルを作成すると便利だろう。</p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-36dc421 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="36dc421" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-5006cc2" data-id="5006cc2" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-da1badc elementor-widget elementor-widget-code-highlight" data-id="da1badc" data-element_type="widget" data-e-type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-bash line-numbers">
				<code readonly="true" class="language-bash">
					<xmp>cd C:\work\2025\05_PERSONAL\Emulator\MZ80マシン語テスト
ailz80asm VRAMTEST.z80 -bin -lst -sym -f
pause
</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-1372c60 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="1372c60" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-7b98f83" data-id="7b98f83" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-7101b05 elementor-widget elementor-widget-text-editor" data-id="7101b05" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>バッチファイルを実行すると次のようなファイルが生成される。</p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-4a140fa elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="4a140fa" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-d79166a" data-id="d79166a" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-221e551 elementor-widget elementor-widget-image" data-id="221e551" data-element_type="widget" data-e-type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img decoding="async" width="211" height="148" src="https://expertgig.jp/wp/wp-content/uploads/2026/01/d432fa515bd7e8287f17d9ec63d019b9.jpg" class="attachment-large size-large wp-image-6123" alt="" />															</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-94ef25a elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="94ef25a" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-f72296f" data-id="f72296f" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-bf9f0d2 elementor-widget elementor-widget-text-editor" data-id="bf9f0d2" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>*.sym はシンボリックファイルで、アセンブリソース記述した「EQU」で設定した値と「ラベル」の位置のアドレスが一覧になっている。EQUは、他の言語で言えば const である。これを頼りにしてソースコードとにらめっこしてデバッグしていくのである。</p>
<p>*.lst は、アドレス、クロック数、アセンブルした16進数のコード、アセンブリソースを一体化したもので、プログラムの解析に利用する。</p>
<p>*.bin はアセンブリソースをマシン語に変換したバイナリプログラムでこれが実行プログラムになる。</p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-9564ebe elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="9564ebe" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-04fef43" data-id="04fef43" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-39bbd5f elementor-widget elementor-widget-heading" data-id="39bbd5f" data-element_type="widget" data-e-type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">3. DumpListEditor で mztファイルを生成する</h2>				</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-2a68c05 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="2a68c05" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-769dd4f" data-id="769dd4f" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-ade9856 elementor-widget elementor-widget-text-editor" data-id="ade9856" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>binファイルができたので、これをエミュレータで読み込める形式にするため、このツールを使う。</p>
<p>最初に「MZ-80K」モードにする。</p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-8109d20 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="8109d20" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b4640b0" data-id="b4640b0" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-93b5e0b elementor-widget elementor-widget-image" data-id="93b5e0b" data-element_type="widget" data-e-type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img fetchpriority="high" decoding="async" width="424" height="223" src="https://expertgig.jp/wp/wp-content/uploads/2026/01/2b5c935017301a56d7ea9d97d8579833.jpg" class="attachment-large size-large wp-image-6124" alt="" srcset="https://expertgig.jp/wp/wp-content/uploads/2026/01/2b5c935017301a56d7ea9d97d8579833.jpg 424w, https://expertgig.jp/wp/wp-content/uploads/2026/01/2b5c935017301a56d7ea9d97d8579833-300x158.jpg 300w" sizes="(max-width: 424px) 100vw, 424px" />															</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-1f58dde elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="1f58dde" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-d4db180" data-id="d4db180" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-9881185 elementor-widget elementor-widget-text-editor" data-id="9881185" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>次に 「ファイル読み込み」メニューから「BINファイル読み込み&amp;ダンプリスト表示」で作ほど作成した「VRAMTEST.bin」を読み込む。</p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-f4fecfb elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="f4fecfb" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-7af4204" data-id="7af4204" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-476408b elementor-widget elementor-widget-image" data-id="476408b" data-element_type="widget" data-e-type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img decoding="async" width="870" height="343" src="https://expertgig.jp/wp/wp-content/uploads/2026/01/418c80b53d7d74248d924ba2c1823cee.jpg" class="attachment-large size-large wp-image-6125" alt="" srcset="https://expertgig.jp/wp/wp-content/uploads/2026/01/418c80b53d7d74248d924ba2c1823cee.jpg 870w, https://expertgig.jp/wp/wp-content/uploads/2026/01/418c80b53d7d74248d924ba2c1823cee-300x118.jpg 300w, https://expertgig.jp/wp/wp-content/uploads/2026/01/418c80b53d7d74248d924ba2c1823cee-768x303.jpg 768w" sizes="(max-width: 870px) 100vw, 870px" />															</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-ed6bf47 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="ed6bf47" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-360432e" data-id="360432e" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-31a2c54 elementor-widget elementor-widget-text-editor" data-id="31a2c54" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>先頭の行に「$1200」と入力して、「アドレス補正」ボタンを押すと次のように水色にハイライトされる。</p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-3038de8 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="3038de8" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-f2a0c54" data-id="f2a0c54" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-e51d061 elementor-widget elementor-widget-image" data-id="e51d061" data-element_type="widget" data-e-type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img loading="lazy" decoding="async" width="834" height="413" src="https://expertgig.jp/wp/wp-content/uploads/2026/01/804784694ad54d387a75d33f157c5d76.jpg" class="attachment-large size-large wp-image-6126" alt="" srcset="https://expertgig.jp/wp/wp-content/uploads/2026/01/804784694ad54d387a75d33f157c5d76.jpg 834w, https://expertgig.jp/wp/wp-content/uploads/2026/01/804784694ad54d387a75d33f157c5d76-300x149.jpg 300w, https://expertgig.jp/wp/wp-content/uploads/2026/01/804784694ad54d387a75d33f157c5d76-768x380.jpg 768w" sizes="(max-width: 834px) 100vw, 834px" />															</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-5930c2a elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="5930c2a" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-63e6f89" data-id="63e6f89" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-ff6925f elementor-widget elementor-widget-text-editor" data-id="ff6925f" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>そして「形式変換」ボタンを押せばバイナリファイルの先頭アドレスが「1200」からとなる。</p>
<p>右側のファイル名を確認して、必要であれば変更する。実行アドレスは先頭アドレスと同じであれば 1200とする。</p>
<p>「ファイル整理画面にPaste」ボタンを押すと「ファイル整理」タグに移動し、binファイルが生成される。</p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-609df14 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="609df14" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-07c0a55" data-id="07c0a55" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-98e8094 elementor-widget elementor-widget-image" data-id="98e8094" data-element_type="widget" data-e-type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img loading="lazy" decoding="async" width="566" height="307" src="https://expertgig.jp/wp/wp-content/uploads/2026/01/becc0f2f7610b9f2ce6171bd5ded2453.jpg" class="attachment-large size-large wp-image-6127" alt="" srcset="https://expertgig.jp/wp/wp-content/uploads/2026/01/becc0f2f7610b9f2ce6171bd5ded2453.jpg 566w, https://expertgig.jp/wp/wp-content/uploads/2026/01/becc0f2f7610b9f2ce6171bd5ded2453-300x163.jpg 300w" sizes="(max-width: 566px) 100vw, 566px" />															</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-8bcb05b elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="8bcb05b" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-179ddd2" data-id="179ddd2" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-396a505 elementor-widget elementor-widget-text-editor" data-id="396a505" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>これで、「mzt書出し」ボタンを押して、保存すれば mztファイルの出来上がり。</p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-4b5d406 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="4b5d406" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-3946583" data-id="3946583" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-037c950 elementor-widget elementor-widget-image" data-id="037c950" data-element_type="widget" data-e-type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img loading="lazy" decoding="async" width="646" height="163" src="https://expertgig.jp/wp/wp-content/uploads/2026/01/987e362b24a78f2af719a296c3f96c94.jpg" class="attachment-large size-large wp-image-6128" alt="" srcset="https://expertgig.jp/wp/wp-content/uploads/2026/01/987e362b24a78f2af719a296c3f96c94.jpg 646w, https://expertgig.jp/wp/wp-content/uploads/2026/01/987e362b24a78f2af719a296c3f96c94-300x76.jpg 300w" sizes="(max-width: 646px) 100vw, 646px" />															</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-6170b3f elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="6170b3f" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-cca4ce4" data-id="cca4ce4" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-2add1d4 elementor-widget elementor-widget-heading" data-id="2add1d4" data-element_type="widget" data-e-type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-default">4. MZ-80Kのエミュレータで実行させる</h2>				</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-f5df6b5 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="f5df6b5" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-2f0677b" data-id="2f0677b" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-37803c3 elementor-widget elementor-widget-text-editor" data-id="37803c3" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Emulator を起動して、生成した VRAMTEST.mzt を選択して、「LOAD」+ CR (Enter) でプログラムがロードされます。mzt ファイルにはプログラムの読み込みアドレス、実行アドレスが書き込まれているので、読み込むが完了すると自動的に実行されます。</p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-0ec9bb9 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="0ec9bb9" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-44f9ae6" data-id="44f9ae6" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-dc900c2 elementor-widget elementor-widget-image" data-id="dc900c2" data-element_type="widget" data-e-type="widget" data-widget_type="image.default">
				<div class="elementor-widget-container">
															<img loading="lazy" decoding="async" width="1024" height="717" src="https://expertgig.jp/wp/wp-content/uploads/2026/01/57cb2d8bad3c0566ad951fbbad01f1bc-1024x717.jpg" class="attachment-large size-large wp-image-6129" alt="" srcset="https://expertgig.jp/wp/wp-content/uploads/2026/01/57cb2d8bad3c0566ad951fbbad01f1bc-1024x717.jpg 1024w, https://expertgig.jp/wp/wp-content/uploads/2026/01/57cb2d8bad3c0566ad951fbbad01f1bc-300x210.jpg 300w, https://expertgig.jp/wp/wp-content/uploads/2026/01/57cb2d8bad3c0566ad951fbbad01f1bc-768x538.jpg 768w, https://expertgig.jp/wp/wp-content/uploads/2026/01/57cb2d8bad3c0566ad951fbbad01f1bc.jpg 1440w" sizes="(max-width: 1024px) 100vw, 1024px" />															</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-15e3ec1 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="15e3ec1" data-element_type="section" data-e-type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-657cb63" data-id="657cb63" data-element_type="column" data-e-type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-6a95f89 elementor-widget elementor-widget-text-editor" data-id="6a95f89" data-element_type="widget" data-e-type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>おー、パチパチパチ。<br />めでたく実行されました。MZ-80Kに設定されているキャラクタはちょっと楽しい感じですね。グラフィクスを描画できないので、ゲームをつくるときは、この文字を組み合わせて、それっぽい感じにすることになります。センスが問われるのがおもしろいところ。</p>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				</div>
		]]></content:encoded>
					
					<wfw:commentRss>https://expertgig.jp/2026/01/30/%e4%bb%8a%e5%b9%b4%e3%81%af%e7%b4%b0%e3%80%85%e3%81%a8mz80k%e3%81%ae%e3%83%9e%e3%82%b7%e3%83%b3%e8%aa%9e%e3%82%92%e7%b5%84%e3%82%80/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Raspi Zero 2W ベアメタル開発 9 (キー入力の基礎知識 編)</title>
		<link>https://expertgig.jp/2025/06/21/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab-10-%e3%82%ad%e3%83%bc%e5%85%a5%e5%8a%9b%e3%81%ae%e5%9f%ba%e7%a4%8e%e7%9f%a5%e8%ad%98-%e7%b7%a8/</link>
					<comments>https://expertgig.jp/2025/06/21/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab-10-%e3%82%ad%e3%83%bc%e5%85%a5%e5%8a%9b%e3%81%ae%e5%9f%ba%e7%a4%8e%e7%9f%a5%e8%ad%98-%e7%b7%a8/#respond</comments>
		
		<dc:creator><![CDATA[Ariyuki Tano]]></dc:creator>
		<pubDate>Fri, 20 Jun 2025 17:22:06 +0000</pubDate>
				<category><![CDATA[マイコン]]></category>
		<category><![CDATA[情報発信基地]]></category>
		<category><![CDATA[KEYSTROBE]]></category>
		<category><![CDATA[MZ-80]]></category>
		<category><![CDATA[Raspi Zero 2W]]></category>
		<category><![CDATA[Ultibo]]></category>
		<category><![CDATA[Z80]]></category>
		<category><![CDATA[キーストローブ]]></category>
		<category><![CDATA[キーマトリクス]]></category>
		<guid isPermaLink="false">https://expertgig.jp/?p=6098</guid>

					<description><![CDATA[MZ80K のキーボードの実装を進めていきたいと思う。 キーボードの実装に当たっては、MZ80K がマップドI/O方式について理解する必要がある。 今、この瞬間に押されてるキーボードは何か? あのキーボードは押されている [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>MZ80K のキーボードの実装を進めていきたいと思う。</p>



<p>キーボードの実装に当たっては、MZ80K がマップドI/O方式について理解する必要がある。</p>



<p>今、この瞬間に押されてるキーボードは何か? あのキーボードは押されているのか押されていないのか? リアルタイムなゲームを作るうえでは欠かせない情報である。MZ80KのBASICでは、キーの状態をリアルタイムに検知する機能はない。</p>



<p>MZ80KのBASIC ( SP-5030等) の場合、INKEY$ でキー入力が発生するまで、ループして押された瞬間を検知することはできるが、今どんな状態かを知ることができない。しかしマシン語を使えば、簡単である。<br>メモリの $E000 と $E001 に接続された Intel 8255 ( Programmable Peripheral Interface ) PPI の対して、操作を行えばいいのである。</p>



<p>具体的には、メモリの$E000 の 上位4ビットは常に1111B として、下位4ビットには下図の知りたいキーがある場所のKEYSTROBE番号をセットして、$E0001 のDATAビットの状態をしらべれば良い。 MZ700やMZ1500のキーマトリクスはネットでもちらほら散見するが、今となっては MZ80Kのキーマトリクスの情報が無いと思われるので、ここに情報を公開しておこう。だれかの役に立つかもしれないので。</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="669" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-16-1024x669.png" alt="" class="wp-image-6099" style="width:715px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-16-1024x669.png 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-16-300x196.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-16-768x501.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-16.png 1438w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>例えば、【V】キーが押されているかどうか知りたかったら、$E000 に F7h (11110111B) をセットして、$E000 の値が FDh (1111 1101B) ならば、Vキーがおされているということになる。</p>



<p>Z80のマシン語だとこんな感じ。BITの状態を調べて条件分岐。</p>



<pre class="wp-block-code"><code class="">LD ($E000),$F7<br>LD A,($E001) <br>BIT 2,A<br>JP Z,V_KEY_PRESSED</code></pre>



<p>もしくは、AND (論理積) を使って明示的に下記のようにするのも良い。</p>



<pre class="wp-block-code"><code class="">LD ($E000),$F7<br>LD A,($E001) <br>AND %00000100     ; Bit2だけマスク（0b00000100）<br>JP Z,V_KEY_PRESSED</code></pre>



<p>鋭い人であれば、これが複数キーの状態も検知できそうだと気づくだろう。つまり同時押しも検知できるのである。</p>



<p>ただし、キーマトリクスの回路の弱点として、ある特定のパターンで3つ以上のキーを押すと回路のショートルートができ、違うキーが押された誤検知するという現象があり、ゴーストキーと呼ばれています。 </p>



<h2 class="wp-block-heading">エミュレータでどのように組み込むか</h2>



<p>エミュレータでは、マップされたI/O $E000～$E008 のメモリに対して読み書きがあったら、上記処理をすれば良い。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://expertgig.jp/2025/06/21/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab-10-%e3%82%ad%e3%83%bc%e5%85%a5%e5%8a%9b%e3%81%ae%e5%9f%ba%e7%a4%8e%e7%9f%a5%e8%ad%98-%e7%b7%a8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Raspi Zero 2W ベアメタル開発 07 (Z80 スピードアップ編)</title>
		<link>https://expertgig.jp/2025/06/17/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba-07-z80-%e3%82%b9%e3%83%94%e3%83%bc%e3%83%89%e3%82%a2%e3%83%83%e3%83%97%e7%b7%a8/</link>
					<comments>https://expertgig.jp/2025/06/17/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba-07-z80-%e3%82%b9%e3%83%94%e3%83%bc%e3%83%89%e3%82%a2%e3%83%83%e3%83%97%e7%b7%a8/#respond</comments>
		
		<dc:creator><![CDATA[Ariyuki Tano]]></dc:creator>
		<pubDate>Tue, 17 Jun 2025 12:06:11 +0000</pubDate>
				<category><![CDATA[マイコン]]></category>
		<category><![CDATA[情報発信基地]]></category>
		<category><![CDATA[MZ-80]]></category>
		<category><![CDATA[Raspi Zero 2W]]></category>
		<category><![CDATA[Ultibo]]></category>
		<category><![CDATA[Z80]]></category>
		<category><![CDATA[エミュレータ]]></category>
		<guid isPermaLink="false">https://expertgig.jp/?p=6089</guid>

					<description><![CDATA[先週は週末も含め、画面まわりの改善に時間を費やしましたが、HDMIのV-SYNC IRQをトリガとしたDMA転送の実装は、同期や動作確認が取れずにことごとく失敗。代わりにDMAをポーリングで監視する方法も試しましたが、ポ [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>先週は週末も含め、画面まわりの改善に時間を費やしましたが、HDMIのV-SYNC IRQをトリガとしたDMA転送の実装は、同期や動作確認が取れずにことごとく失敗。代わりにDMAをポーリングで監視する方法も試しましたが、ポーリングしてもDMAの状態が一切変化せず、値も返らないという状態で機能せず。コードを大幅に改造しすぎて元の状態に戻すのも困難になり、挫折感の大きい週末となりました。</p>



<p>気晴らしに、Z80エミュ部分のスピード改善に集中することにした。</p>



<h1 class="wp-block-heading">Z80エミュを 10MHz まで上げたい!</h1>



<p>最初、とりあえず動作するようになった Z80エミュですが、当初は実機を下回る。1.727MHz</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="576" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-1024x576.jpg" alt="" class="wp-image-6078" style="width:418px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-1024x576.jpg 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-300x169.jpg 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-768x432.jpg 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-1536x864.jpg 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-2048x1153.jpg 2048w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-800x450.jpg 800w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>エミュなのでいうなれば、内部的な構造はZ80インタプリタという感じではあるが、Cortex-A53（64-bit）@ 1GHz のマシンで 1.7MHz では、なんとも悲しいではないか。ここに画面描画 Thread が動いたら、どんだけ遅いんだってことになってしまいます。</p>



<p>それで、いろいろとムダ改善 ( 工場らしい単語だね ) を行いまして、スピードは徐々に改善し、3.367MHz と約2倍に。</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="576" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-1024x576.jpg" alt="" class="wp-image-6082" style="width:460px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-1024x576.jpg 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-300x169.jpg 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-768x432.jpg 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-1536x864.jpg 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-2048x1153.jpg 2048w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-800x450.jpg 800w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>それでも、まだまだということで、絞りまくって、なんと 6.098MHz まで到達。</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="576" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250617_193423-1024x576.jpg" alt="" class="wp-image-6088" style="width:457px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250617_193423-1024x576.jpg 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250617_193423-300x169.jpg 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250617_193423-768x432.jpg 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250617_193423-1536x864.jpg 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250617_193423-2048x1153.jpg 2048w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250617_193423-800x450.jpg 800w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>とりあえずここまでくれば、一段落。</p>



<p>今回、どんなことをしてスピードを上げたのか。箇条書きで記します。</p>



<h2 class="wp-block-heading">Z80エミュレーション スピードアップ施策（時系列）</h2>



<h3 class="wp-block-heading" style="font-size:27px">【初期】〜 1.73MHz 程度</h3>



<ol class="wp-block-list">
<li class="has-vivid-cyan-blue-color has-text-color has-link-color has-medium-font-size wp-elements-bbedcccff48773359065e3a80f5e4be6"><strong>Z80の命令実行部を関数ポインタ配列で管理（Opc_mainなど）</strong></li>
</ol>



<p>　初期は Delphi 的なスタイルで、オペコードごとにメソッド参照で分岐。</p>



<ol start="2" class="wp-block-list">
<li class="has-vivid-cyan-blue-color has-text-color has-link-color has-medium-font-size wp-elements-daef81c1b59f23000004cd8a05719c20"><strong>Z80_RDMEM/Z80_WRMEMの抽象化</strong></li>
</ol>



<p>　メモリアクセスを関数化したが、処理分岐が多く遅延の原因に。可能な限りダイレクトにメモリの読み書きをするように書き換え。</p>



<ol start="3" class="wp-block-list">
<li class="has-vivid-cyan-blue-color has-text-color has-link-color has-medium-font-size wp-elements-69f9b3c8fefd3e5b79144c7dc102f56d"><strong>Z80のClass化を廃止、Cライクにべた書き</strong></li>
</ol>



<p>　意外にこれはすごく大きく改善した。Class は便利だが、やはり動作は遅くなることがわかった。</p>



<h3 class="wp-block-heading" style="font-size:27px">【中期】〜 約3〜5MHz台</h3>



<p class="has-vivid-cyan-blue-color has-text-color has-link-color has-medium-font-size wp-elements-7b2b19ec8abdd12594192972b5689349">　<strong>4. 関数ポインタ呼び出しの高速化検討</strong></p>



<p>　　<code>Opc_main[opcode]()</code> での呼び出しが遅いか検証。</p>



<p class="has-vivid-cyan-blue-color has-text-color has-link-color has-medium-font-size wp-elements-1c1af6999f38bd90e9d47d21f841686e"><strong>　5. 命令デコードの分岐を単純</strong></p>



<p>　　<code>case</code>や<code>if-else</code>の多重分岐を避け、直接ジャンプに近い構造に。</p>



<p class="has-vivid-cyan-blue-color has-text-color has-link-color has-medium-font-size wp-elements-9eb8cc75cc26cae36f89f543468f3d9d"><strong>　6. 読み出し回数が多いところでのムダな関数呼び出し排除</strong></p>



<p>　　関数呼び出しがネストしていっている部分がかなりムダが多かった。</p>



<h2 class="wp-block-heading" style="font-size:27px">【最適化フェーズ】〜 約6.06MHz 到達</h2>



<p class="has-vivid-cyan-blue-color has-text-color has-link-color has-medium-font-size wp-elements-30de01dcf268fda272bdd954d8d7fa3e"><strong>　7. 変数の型のオバースペックを解消</strong></p>



<p>　　なんとなく Int32 となっていたところを、厳格に Word (UInt16) にしたり、byte (Uint8) にしたら、内部的なムダなキャスト処理が減ったということで、これも大きくスピードアップに貢献</p>



<p class="has-vivid-cyan-blue-color has-text-color has-link-color has-medium-font-size wp-elements-8021809c6618c653e43429916bf4e51a">　<strong>8. メモリマップドI/Oを早期に除外</strong></p>



<p>　　MZ80がメモリマップドI/Oの構造をとっているため、 $E000～$E008 のアドレスに読み書きがあったら、pio8255、pit8253 の処理と連動させなくてはいけないので、メモリに読み書きがあるたびに判定を繰り替えしていたが、初期の段階で $E000以前のアドレスだったらすぐに手続き離脱 (exit ) することで、かなり速くなった。</p>



<p>ということで、これからはVRAM描画の最適化に挑戦。 (今のバージョンをバックアップしておこう。。)</p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://expertgig.jp/2025/06/17/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba-07-z80-%e3%82%b9%e3%83%94%e3%83%bc%e3%83%89%e3%82%a2%e3%83%83%e3%83%97%e7%b7%a8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Raspi Zero 2W ベアメタル開発 06 (エミュ速度改善編)</title>
		<link>https://expertgig.jp/2025/06/11/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba-06-%e3%82%a8%e3%83%9f%e3%83%a5%e9%80%9f%e5%ba%a6%e6%94%b9%e5%96%84%e7%b7%a8/</link>
					<comments>https://expertgig.jp/2025/06/11/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba-06-%e3%82%a8%e3%83%9f%e3%83%a5%e9%80%9f%e5%ba%a6%e6%94%b9%e5%96%84%e7%b7%a8/#respond</comments>
		
		<dc:creator><![CDATA[Ariyuki Tano]]></dc:creator>
		<pubDate>Wed, 11 Jun 2025 14:36:25 +0000</pubDate>
				<category><![CDATA[マイコン]]></category>
		<category><![CDATA[情報発信基地]]></category>
		<category><![CDATA[MZ-80]]></category>
		<category><![CDATA[Raspi Zero 2W]]></category>
		<category><![CDATA[Ultibo]]></category>
		<category><![CDATA[Z80]]></category>
		<category><![CDATA[エミュレータ]]></category>
		<guid isPermaLink="false">https://expertgig.jp/?p=6079</guid>

					<description><![CDATA[さて、前回 MZ-80K2 のエミュはほぼ動いたのですが、めちゃめちゃ遅いという問題がは発生。 画面描画にメスを入れる ★ カラーを 32bitから16bit にして描画コストを半分にする。 エミュレートする対象がMZ- [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>さて、前回 MZ-80K2 のエミュはほぼ動いたのですが、めちゃめちゃ遅いという問題がは発生。</p>



<h2 class="wp-block-heading">画面描画にメスを入れる</h2>



<p>★ カラーを 32bitから16bit にして描画コストを半分にする。</p>



<p>エミュレートする対象がMZ-80Kなので、カラーが 32bit というのはかなりオーバースペックであることに気づいたので、16bitモードに変更。これに伴って、 ARGB (LongWord) で記述していたコードを RGB565 (Word) にすべて書き換え。</p>



<pre class="wp-block-code"><code class="">//==============================================================================<br>// 指定した X,Y (40x25) にキャラを表示  (RGB565形式バージョン)<br>//==============================================================================<br>procedure DrawCharToSurface(X, Y: Integer; CharCode: Byte);<br>var<br>  Line, Bit: Integer;<br>  Data: Byte;<br>  PixelAddr: PWord;<br>  BaseAddr: PtrUInt;<br>begin<br>  // 1文字目の先頭アドレス（1ピクセル=2バイト）<br>  BaseAddr := FBInfo.PixelAddr + Y * FBInfo.Pitch + X * 2;<br><br>  for Line := 0 to 7 do<br>  begin<br>    Data := FontRom[CharCode * 8 + Line];<br>    for Bit := 0 to 7 do<br>    begin<br>      PixelAddr := PWord(BaseAddr + Line * FBInfo.Pitch + Bit * 2);<br>      if (Data and (128 shr Bit)) &lt;&gt; 0 then<br>        PixelAddr^ := FG   // FG は Word 型（RGB565値）<br>      else<br>        PixelAddr^ := BG;  // BG も Word 型<br>    end;<br>  end;<br>end; </code></pre>



<p> こんな感じで、すべて Word型に。 RGB565変換は、下記のようなfunctionを作成。</p>



<pre class="wp-block-code"><code class="">//==============================================================================<br>// RGB565 形式に変換する関数<br>//==============================================================================<br>function RGB565(R, G, B: Byte): Word;<br>begin<br>  Result := ((R shr 3) shl 11) or ((G shr 2) shl 5) or (B shr 3);<br>end; </code></pre>



<p>これは、ARDUINO や ESP32 などのSBCで、外部LEDに出力するときに RGB565仕様のLEDモニタが多いので役立ちそう。あまり考えずに RGB を 255,255,255 で指定して、自動変換。</p>



<p>★ フレーム描画を間引き</p>



<p>禁断かどうかわかりませんが、フレーム描画を4回に1回だけ描画して、フレーム描画をすっとばす。</p>



<pre class="wp-block-code"><code class="">//==============================================================================<br>// Draw Screen Thread Execeute<br>//==============================================================================<br>procedure TDrawScreenThread.Execute;<br>var<br>  FStartVSync, FEndVSync, FVSyncTime: QWord;<br>  FrameCount: Integer;<br>begin<br>  FrameCount := 0;<br><br>  while not Terminated do<br>  begin<br>    FStartVSync := GetTickCount64;<br><br>    Inc(FrameCount);<br><br>    if hw80.v_gate then<br>    begin<br>      if (FrameCount mod 4 = 0) then<br>        update_scrn;<br>    end<br>    else<br>    begin<br>      // 描画間引きに関係なく、背景は毎回クリア<br>      ClearGameAreaFast16(BG);<br>    end;<br><br>    FEndVSync := GetTickCount64;<br>    FVSyncTime := FEndVSync - FStartVSync;<br><br>    if SYNCTIME &gt; FVSyncTime then<br>      Sleep(SYNCTIME - FVSyncTime)<br>    else<br>      Sleep(1);<br>  end;<br>end;</code></pre>



<p> update_scrn の呼び出し頻度を変えている。</p>



<p>★ Thread の優先順位を設定</p>



<p>画面描画をLOWEST にして、 Z80のThreadをHIGHEST に設定</p>



<h2 class="wp-block-heading">結果は?</h2>



<p>少し早くなったが、まだまだぜんぜん。なかなかなやましい。</p>



<h2 class="wp-block-heading">画面描画処理をストップしてZ80だけ動かして計測してみた</h2>



<p>そもそも Z80 部分は十分なスピードで動いているのか? という疑問があったので、計測用のソースに書き換えてテスト</p>



<pre class="wp-block-code"><code class="">//==============================================================================<br>// Z80Thread Execute<br>//==============================================================================<br>procedure TZ80Thread.Execute;<br>var<br>  i: Integer;<br>  T1, T2: QWord;<br>  Hz: Double;<br>begin<br>  // 描画がない状態で、Z80処理速度を測定<br>  T1 := GetTickCount64;<br><br>  for i := 1 to 1000000 do<br>    z80.Z80_Execute;<br><br>  T2 := GetTickCount64;<br><br>  // ミリ秒 → 秒へ変換して Hz 計算<br>  if (T2 &gt; T1) then<br>  begin<br>    Hz := 1000000 / ((T2 - T1) / 1000);<br>    ConsoleWindowWriteLn(Console1, 'Z80: ' + FloatToStrF(Hz / 1000000, ffFixed, 5, 3) + ' MHz');<br>  end<br>  else<br>    ConsoleWindowWriteLn(Console1, '計測エラー');<br><br>  // スレッド終了<br>  Terminate;<br>end;  </code></pre>



<p>1,000,000個の命令を処理して、何ヘルツで動いているか計測してみた。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="576" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-1024x576.jpg" alt="" class="wp-image-6078" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-1024x576.jpg 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-300x169.jpg 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-768x432.jpg 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-1536x864.jpg 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-2048x1153.jpg 2048w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_225115-800x450.jpg 800w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>ガーン! ショック。テスト結果は 1.727MHz。実機の 2MHz に達していないではないか!</p>



<p>そりゃ、描画処理も入れたら遅いわけだ。。</p>



<h2 class="wp-block-heading">ボトルネックは何んなのか考える</h2>



<p>ChatGPT に相談してみた。</p>



<p>そしたら、以下のような指摘が帰ってきました。(致命的!!) と言ってます。</p>



<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/26a0.png" alt="⚠" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 問題点①：ExecMethod2 の文字列分岐（致命的）<br><br>ExecMethod2(op, &#8216;main&#8217;, opcode); // ← これが非常に遅い<br>文字列で分岐しています：<br>if kind = &#8216;main&#8217; then<br>op.opc_main[opcode]()<br>else if kind = &#8216;cb&#8217; then …<br><br><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 改善策：直接呼び出しに置き換える<br>op.opc_main[opcode](); // ← これで高速化（関数ポインタ直呼び）<br><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f4a1.png" alt="💡" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 25%以上の速度向上が見込めます。</p>



<p>先生了解しました。直接呼出しにしてみます。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="576" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-1024x576.jpg" alt="" class="wp-image-6082" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-1024x576.jpg 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-300x169.jpg 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-768x432.jpg 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-1536x864.jpg 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-2048x1153.jpg 2048w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250612_071623-800x450.jpg 800w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>す、すごい 倍速になりました。</p>



<p>やはり、Z80などのエミュレーションは、とにかく繰り返し処理なので、繰り返しの中のオーバーヘッドをなくすってことですね。</p>



<p>昔のマイコンプログラムを思い出す。</p>



<p>現代のゆるーい感じのコーディングのぬるま湯に浸かりすぎてました。反省。</p>



<p>まだまだ、改善できそうなので、次回に続く。</p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://expertgig.jp/2025/06/11/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba-06-%e3%82%a8%e3%83%9f%e3%83%a5%e9%80%9f%e5%ba%a6%e6%94%b9%e5%96%84%e7%b7%a8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Raspi Zero 2W ベアメタル開発 05【MZ-80K2 Emu 編】</title>
		<link>https://expertgig.jp/2025/06/11/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba%e3%80%90mz-80k2-emu-%e7%b7%a8%e3%80%91/</link>
					<comments>https://expertgig.jp/2025/06/11/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba%e3%80%90mz-80k2-emu-%e7%b7%a8%e3%80%91/#respond</comments>
		
		<dc:creator><![CDATA[Ariyuki Tano]]></dc:creator>
		<pubDate>Wed, 11 Jun 2025 03:54:22 +0000</pubDate>
				<category><![CDATA[マイコン]]></category>
		<category><![CDATA[情報発信基地]]></category>
		<category><![CDATA[未分類]]></category>
		<category><![CDATA[MZ-80]]></category>
		<category><![CDATA[Raspi Zero 2W]]></category>
		<category><![CDATA[Ultibo]]></category>
		<category><![CDATA[Z80]]></category>
		<category><![CDATA[エミュレータ]]></category>
		<guid isPermaLink="false">https://expertgig.jp/?p=6074</guid>

					<description><![CDATA[さて、前回から数日経ってしまいましたが、Z80のエミュレーションで、問題が発生。 Delphi で開発したソースは、メモリからオペコード（1byte）を読み込んで、事前に用意したオペコードに対応するプロシージャ名の配列か [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>さて、前回から数日経ってしまいましたが、Z80のエミュレーションで、問題が発生。</p>



<p>Delphi で開発したソースは、メモリからオペコード（1byte）を読み込んで、事前に用意したオペコードに対応するプロシージャ名の配列から、対象となるprocedure 名を取得して、そのprocedure名からプロシージャを呼び出すためのポインタを取得してマシン語の実行というプログラムだったのですが（ややこしいですけど効率的）、なんとベアメタルでの Free Pascal では構文でエラーは出ないものの、ポインタの値が null しか戻ってこないという大ピンチに陥っていまして、ちょいとなやんでいました。</p>



<p>色々と調べて、トライしてやっと求めている動きになりました。</p>



<p>具体的には、procedure（ ）of object 型の配列を準備して、オペコードに対応するprocedure のポインタを設定するという方法です。</p>



<p>TOp という class にマシン語命令を処理するprocedure がすべて入っていて、そのインスタンスをop とした時、クラス外で準備した配列に次のようにポインタを代入します。</p>



<p>opcode_main[$C3] := @op.jp;</p>



<p>Z80 ではメインとなる命令群が256個、2バイト命令が、CB, DD,ED,FD ということで、4*256個、3バイト命令で、256*2の512個、合わせて 1792 個の命令（その中には未定義の部分もありますが）なので、ポインタを利用した呼び出しをしないと、大量のif then else if をずらーっと記述しなければいけないはめになり、かつ遅いプログラムとなってしまいます。</p>



<p>まぁとりあえず、解決策があって良かった。</p>



<p>ということで、Z80の動作もレジスタの値の変化を表示して、うまくいってるようなので、VRAMの内容を画面に書き込むモードに切り替えて実行!</p>



<figure class="wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex">
<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="576" data-id="6075" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_040155-1024x576.jpg" alt="" class="wp-image-6075" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_040155-1024x576.jpg 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_040155-300x169.jpg 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_040155-768x432.jpg 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_040155-1536x864.jpg 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_040155-2048x1152.jpg 2048w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250611_040155-800x450.jpg 800w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</figure>



<p>とりあえず、モニタプログラムが動いて、画面にSP-1002 の表示が出ました。</p>



<p>しかし、めちゃくちゃ遅い! これはなんとかせねば。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://expertgig.jp/2025/06/11/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba%e3%80%90mz-80k2-emu-%e7%b7%a8%e3%80%91/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Raspi Zero 2W ベアメタル開発 04 ( MZ80KのVRAM表示編)</title>
		<link>https://expertgig.jp/2025/06/08/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba-mz80k%e3%81%aevram%e8%a1%a8%e7%a4%ba%e7%b7%a8/</link>
					<comments>https://expertgig.jp/2025/06/08/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba-mz80k%e3%81%aevram%e8%a1%a8%e7%a4%ba%e7%b7%a8/#respond</comments>
		
		<dc:creator><![CDATA[Ariyuki Tano]]></dc:creator>
		<pubDate>Sat, 07 Jun 2025 15:33:22 +0000</pubDate>
				<category><![CDATA[マイコン]]></category>
		<category><![CDATA[情報発信基地]]></category>
		<category><![CDATA[Lazarus]]></category>
		<category><![CDATA[MZ-80]]></category>
		<category><![CDATA[Raspi Zero 2W]]></category>
		<category><![CDATA[Ultibo]]></category>
		<category><![CDATA[VRAM]]></category>
		<category><![CDATA[Z80]]></category>
		<category><![CDATA[エミュレータ]]></category>
		<guid isPermaLink="false">https://expertgig.jp/?p=6069</guid>

					<description><![CDATA[前回、画面へのキャラクタ描画はうまく行ったので、もっとエミュレータ開発に使づくように、今日はもう一歩前進してみましょう。 MZ80Kのメモリ領域全体は、8bitマシンということで、64KBとなります。 メモリ内容を保持す [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>前回、画面へのキャラクタ描画はうまく行ったので、もっとエミュレータ開発に使づくように、今日はもう一歩前進してみましょう。</p>



<p>MZ80Kのメモリ領域全体は、8bitマシンということで、64KBとなります。</p>



<pre class="wp-block-code"><code class="">unit mem;<br>interface<br>var<br>  memory: array[0..65535] of Byte;<br>implementation<br>end. </code></pre>



<p>メモリ内容を保持する unit として、上記のように準備しました。</p>



<p>ここに、MZ-80KのモニタROM (SP-1002) を読み込んでみましょう。</p>



<pre class="wp-block-code"><code class="">//==============================================================================<br>// Load MONITOR ROM<br>//==============================================================================<br>procedure LoadMonitorRom;<br>var<br>  FS: TFileStream;<br>  MonitorPath: string;<br>  I: Integer;<br>begin<br>  ConsoleWindowWriteLn(Console1, 'Waiting for drive...');<br><br>  // C:\ または fat:\ が使えるのを待つ<br>  while not DirectoryExists('C:\') and not DirectoryExists('fat:\') do<br>    Sleep(100);<br><br>  if DirectoryExists('C:\') then<br>    MonitorPath := 'C:\mon_rom'<br>  else<br>    MonitorPath := 'fat:\mon_rom';<br><br>  ConsoleWindowWriteLn(Console1, 'Drive is ready.');<br><br>  if FileExists(MonitorPath) then<br>  begin<br>    ConsoleWindowWriteLn(Console1, 'Loading monitor ROM file...');<br>    FS := TFileStream.Create(MonitorPath, fmOpenRead);<br>    FS.Read(MonitorRom, SizeOf(MonitorRom));<br>    FS.Free;<br>    ConsoleWindowWriteLn(Console1, 'Monitor ROM loaded successfully!');<br>  end<br>  else<br>  begin<br>    ConsoleWindowWriteLn(Console1, 'Monitor ROM file not found at ' + MonitorPath);<br>  end;<br><br>  // 読み込んだ内容を memory[] にコピー<br>  for I := 0 to SizeOf(MonitorRom) - 1 do<br>    memory[I] := MonitorRom[I];<br>end;                  </code></pre>



<p>メモリの先頭 $0000番地から4KBのモニタROMを読み込んでセットします。</p>



<p>今後、Z80のエミュレータがうまく動けば、このモニタ部分を実行して、VRAMへの初期表示もされることになります。</p>



<p>まだそこまでは行けないので、今回はVRAMとして割り当てられた $D000 からの1000byte の内容を画面に表示するところまでやってみましょう。</p>



<p>つまり画面表示部分だけ先にテストしておこうというわけです。</p>



<h2 class="wp-block-heading">VRAMの内容を画面に表示する</h2>



<p>とりあえずざっとソースプログラムを見てみましょう。</p>



<pre class="wp-block-code"><code class="">//==============================================================================<br>// スクリーン描画スレッド<br>//==============================================================================<br>procedure DrawScreenThread;<br>var<br>  FTimeValue : QWord;<br>  FTimeDis   : QWord;<br>  FStartVSync: QWord;<br>  FEndVSync  : QWord;<br>  FVSyncTime : QWord;<br>  Amin       : Integer;<br>  Asec       : Integer;<br>  DrawFreq   : Integer;<br>  i, j       : Integer;<br>begin<br>  // すでにスレッドが開始されていたら停止<br>  if Assigned(ScreenThread) then<br>  begin<br>    flgStop := True;<br>    ScreenThread.Terminate;<br>    FreeAndNil(ScreenThread);<br>  end;<br><br>  // スレッド開始<br>  flgStop := False;<br>  ScreenThread := TDrawScreenThread.Create(False); // False = 自動起動<br>  ScreenThread.FreeOnTerminate := False;<br>end;<br><br>//==============================================================================<br>// Draw Screen Thread Execeute<br>//==============================================================================<br>procedure TDrawScreenThread.Execute;<br>var<br>  FStartVSync, FEndVSync, FVSyncTime: QWord;<br>begin<br>  while not Terminated do<br>  begin<br>    FStartVSync := GetTickCount64;<br><br>    //if hw80.v_gate then<br>    if true then  // z80動かすまでの仮設定<br>    begin<br>      update_scrn;<br>    end<br>    else<br>    begin<br>      ClearScreenFast(BG);  // 事前定義された背景色<br>    end;<br><br>    FEndVSync := GetTickCount64;<br>    FVSyncTime := FEndVSync - FStartVSync;<br><br>    if SYNCTIME > FVSyncTime then<br>      Sleep(SYNCTIME - FVSyncTime);<br><br>    Sleep(1);<br>  end;<br>end;<br><br>//==============================================================================<br>// 画面アップデート処理  (v-blank) [書き換えが必要部分だけ画面を書き換える]<br>//==============================================================================<br>procedure update_scrn;<br>var<br>  i: Integer;<br>  CharCode: Byte;<br>  Row, Col: Integer;<br>begin<br>  for i := 0 to 999 do<br>  begin<br>    CharCode := Memory[$D000 + i];<br>    if ScrChar[i] &lt;> CharCode then<br>    begin<br>      Row := i div 40;<br>      Col := i mod 40;<br>      DrawCharToSurface(Col * 8, Row * 8, CharCode);<br>      ScrChar[i] := CharCode;<br>    end;<br>  end;<br>end;<br><br>//==============================================================================<br>// 指定した X,Y (40x25) にキャラを表示<br>//==============================================================================<br>procedure DrawCharToSurface(X, Y: Integer; CharCode: Byte);<br>var<br>  Line, Bit: Integer;<br>  Px, Py: Integer;<br>  Data: Byte;<br>  Color: LongWord;<br>begin<br>  for Line := 0 to 7 do<br>  begin<br>    Data := FontRom[CharCode * 8 + Line];<br>    for Bit := 0 to 7 do<br>    begin<br>      Px := X + Bit;<br>      Py := Y + Line;<br><br>      if (Data and (1 shl (7 - Bit))) &lt;> 0 then<br>        Color := FG<br>      else<br>        Color := BG;<br><br>      PutPixel(Px, Py, Color);<br>    end;<br>  end;<br>end;<br><br>//==============================================================================<br>// 点を描画<br>//==============================================================================<br>procedure PutPixel(X, Y: Integer; Color: LongWord);<br>var<br>  Offset: PtrUInt;<br>begin<br>  Offset := FBInfo.PixelAddr + Y * FBInfo.Pitch + X * 4;<br>  PLongWord(Pointer(Offset))^ := Color;<br>end;<br><br>//==============================================================================<br>// 画面を高速クリア<br>//==============================================================================<br>procedure ClearScreenFast(Color: LongWord);<br>var<br>  PixelPtr: PLongWord;<br>  Count: Integer;<br>begin<br>  PixelPtr := PLongWord(Pointer(FBInfo.PixelAddr));<br>  Count := (FBInfo.Pitch div 4) * FBInfo.Height;<br><br>  while Count > 0 do<br>  begin<br>    PixelPtr^ := Color;<br>    Inc(PixelPtr);<br>    Dec(Count);<br>  end;<br>end;                 </code></pre>



<p>画面を一定周期で更新するThread を定義して実行します。</p>



<p>Thead内から、update_scrn (画面の更新処理) を呼び出します。</p>



<p>update_scrn では、高速化のためVRAM 上の値が前回と違う部分だけ更新するようにしています。</p>



<p>この中で、指定のX,Y 座標に文字を書き込む処理 DrawCharToSurface(X,Y,CharCode) を呼びだしています。</p>



<p>DrawCharToSurfaceでは、フォントデータに基づいてドットで画像を生成 ( PutPixel) しています。</p>



<p>PutPixel では、文字単位ではなくドット単位で書き込む処理が記述されています。</p>



<p>このように階層的に処理をしています。</p>



<h2 class="wp-block-heading">ランダムな情報をVRAMに書き込む</h2>



<p>まだ Z80が動いていないので、VRAMエリアに情報が書き込まれない状態ですので、とりあえずVRAMエリアにランダムに値を書き込みます。</p>



<pre class="wp-block-code"><code class="">procedure FillVRAMWithRandomChars;<br>var<br>  i: Integer;<br>begin<br>  Randomize;<br>  for i := 0 to 999 do<br>  begin<br>    Memory[$D000 + i] := Random(256);  // ランダムなキャラクターコード（0〜255）<br>  end;<br>end;   </code></pre>



<p>これで、元データはできあ゛かりますので、テストしてみましょう。</p>



<p>それと、プログラムがちゃんと動作していることを確かめるため、MZ700風に背景を青にして描画するようにしてみましょう。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="576" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250608_002026-1024x576.jpg" alt="" class="wp-image-6070" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250608_002026-1024x576.jpg 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250608_002026-300x169.jpg 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250608_002026-768x432.jpg 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250608_002026-1536x864.jpg 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250608_002026-2048x1152.jpg 2048w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250608_002026-800x450.jpg 800w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>うまく行きました。</p>



<p>Z80部分もコンパイルできるところまでは修正したのですが、まだうまく動いていないので、とりあえず今日はVRAMの表示をスレッドでできたというところまで。</p>



<div class="wp-block-file"><a id="wp-block-file--media-11e68203-2e33-4c76-a816-bdaf13c6df1f" href="https://expertgig.jp/wp/wp-content/uploads/2025/06/VRAM_DRAW.zip">VRAM_DRAW</a><a href="https://expertgig.jp/wp/wp-content/uploads/2025/06/VRAM_DRAW.zip" class="wp-block-file__button wp-element-button" download aria-describedby="wp-block-file--media-11e68203-2e33-4c76-a816-bdaf13c6df1f">ダウンロード</a></div>



<p>今回は、Z80の実装とMZ80のハードウェア定義もすべてソースに含まれていますが、まだZ80の実装部分のテストができていないので、動作からは外しています。</p>



<p>しかし、Z80部分のDEBUGをどうやってやろうかな。今の開発のやり方だと、まともにデバッグできないので、Raspi の エミュレータを開発環境に絡めてやるしかないんだろうな。。また開発環境の設定を触るしかないね。</p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://expertgig.jp/2025/06/08/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba-mz80k%e3%81%aevram%e8%a1%a8%e7%a4%ba%e7%b7%a8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Raspi Zero 2W ベアメタル開発 02 (環境構築～Hello表示編)</title>
		<link>https://expertgig.jp/2025/06/07/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba-02-%e7%92%b0%e5%a2%83%e6%a7%8b%e7%af%89%ef%bd%9ehello%e8%a1%a8%e7%a4%ba%e7%b7%a8/</link>
					<comments>https://expertgig.jp/2025/06/07/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba-02-%e7%92%b0%e5%a2%83%e6%a7%8b%e7%af%89%ef%bd%9ehello%e8%a1%a8%e7%a4%ba%e7%b7%a8/#respond</comments>
		
		<dc:creator><![CDATA[Ariyuki Tano]]></dc:creator>
		<pubDate>Fri, 06 Jun 2025 15:08:10 +0000</pubDate>
				<category><![CDATA[IoT関連]]></category>
		<category><![CDATA[マイコン]]></category>
		<category><![CDATA[情報発信基地]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Lazarus]]></category>
		<category><![CDATA[MZ-80]]></category>
		<category><![CDATA[Pascal]]></category>
		<category><![CDATA[Raspi Zero 2W]]></category>
		<category><![CDATA[Ultibo]]></category>
		<category><![CDATA[Z80]]></category>
		<category><![CDATA[エミュレータ]]></category>
		<guid isPermaLink="false">https://expertgig.jp/?p=6035</guid>

					<description><![CDATA[さて、意を決してから、右往左往して、ようやくHDMI 接続したモニタに文字を表示できましたので、そこまでの手順を手短に解説します。 Ultibo Core のダウンロード Lazarus IDE と統合された Ultib [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>さて、意を決してから、右往左往して、ようやくHDMI 接続したモニタに文字を表示できましたので、そこまでの手順を手短に解説します。</p>



<h2 class="wp-block-heading">Ultibo Core のダウンロード</h2>



<p>Lazarus IDE と統合された Ultibo は下記よりダウンロードします。</p>



<p>/<a href="https://ultibo.org/download/">https://ultibo.org/download/</a></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="788" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-1024x788.png" alt="" class="wp-image-6036" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-1024x788.png 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-300x231.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-768x591.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-1536x1182.png 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image.png 2008w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>2025/6/6 時点では、Ultibo-Core-2.6.049-Beetroot.exe が最新ですので、これをダウンロード。<br><br>もしくは、GitHub からもダウンロードできます。必要に応じて古いバージョンのダウンロードもできます。<br></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="787" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-1-1024x787.png" alt="" class="wp-image-6037" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-1-1024x787.png 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-1-300x231.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-1-768x590.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-1-1536x1181.png 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-1.png 2014w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>こちらだと、少しサイズの大きい Ultibo-Core-2.6.049-Beetroot-Main.exe というのもあります。</p>



<p>私は、何か不足してもいやなので、こちらからダウンロードしました。</p>



<h2 class="wp-block-heading">インストール</h2>



<p>ダウンロードしたファイルを実行するとインストールが始まります。インストールディレクトリの指定などもできますが、とりあえずデフォルトのまま次へ次へと進みインストール。数分でインストールが完了します。</p>



<p>インストールが完了すると、C:\Ultibo\Core というフォルダができています。</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="842" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-2-1024x842.png" alt="" class="wp-image-6038" style="width:455px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-2-1024x842.png 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-2-300x247.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-2-768x632.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-2.png 1075w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>C:\Ultibo\Core の下にこんなフォルダとファイルができていればとりあえずインストール成功かと思います。</p>



<h2 class="wp-block-heading">Lazarus (Ultibo Edition) を起動</h2>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" width="339" height="353" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-3.png" alt="" class="wp-image-6039" style="width:204px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-3.png 339w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-3-288x300.png 288w" sizes="(max-width: 339px) 100vw, 339px" /></figure>



<p>Lazarus IDE (Ultibo Edition) を起動します。</p>



<p>初回の起動はFPC (free pascal ) のパスなどを設定する画面が表示されますが、デフォルトで設定されているので、開発環境のWindow のモードを選択するだけで良いでしょう。Windowモードは、Classic だと 昔風にそれぞれのウィンドが独立している形になっていて、今風だと、最近のDelphi風に1つのWindowにメニュー、プロジェクトインスペクタ、ソースエディタ、コードエクスプローラなどがドッキングされた感じになります。特に深い思い入れがなければ、今風のほうが良いでしょう。</p>



<p></p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="690" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-4-1024x690.png" alt="" class="wp-image-6040" style="width:567px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-4-1024x690.png 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-4-300x202.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-4-768x518.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-4-1536x1035.png 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-4-2048x1380.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>これは今風の場合。</p>



<h2 class="wp-block-heading">プロジェクトの作成</h2>



<p>メニューの[ファイル]→[新規] で下の画面が開きます。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="605" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-5-1024x605.png" alt="" class="wp-image-6041" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-5-1024x605.png 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-5-300x177.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-5-768x453.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-5.png 1128w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>今回は、Raspi Zero 2W をターゲットにしますので、これを選んで[OK] ボタンでプロジェクトが作成されます。</p>



<h2 class="wp-block-heading">プロジェクトオプションの設定</h2>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" width="524" height="634" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-6.png" alt="" class="wp-image-6042" style="width:237px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-6.png 524w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-6-248x300.png 248w" sizes="(max-width: 524px) 100vw, 524px" /></figure>



<p>[プロジェクト] → [プロジェクトオプション] で下の画面が開きます。</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="679" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-7-1024x679.png" alt="" class="wp-image-6043" style="width:683px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-7-1024x679.png 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-7-300x199.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-7-768x509.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-7.png 1208w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>[コンパイラオプション] → [設定と対象] で、対称プラットフォームは、上記画面のように設定してください。</p>



<p>ARMV7A 、RPIZERO2W がポイントです。設定したら[OK]ボタンで画面を閉じます。</p>



<h2 class="wp-block-heading">Hello world サンプルプログラムの作成</h2>



<pre class="wp-block-code"><code class="">program HelloPi;<br><br>uses<br>  RaspberryPi3, // ← ここが機種名<br>  GlobalConst, GlobalTypes,<br>  Platform, Console, SysUtils;<br><br>var<br>  Console1: TWindowHandle;<br><br>begin<br>  Console1 := ConsoleWindowCreate(ConsoleDeviceGetDefault, 0, True);<br><br>  if Console1 &lt;&gt; -1 then<br>  begin<br>    ConsoleWindowWriteLn(Console1, 'Hello from Ultibo on Pi Zero 2 W!');<br>  end;<br><br>  while True do Sleep(1000);<br>end.<br></code></pre>



<p>最初は何も考えずに、初期表示されているソースを消して、上記コードをペタッと貼り付けましょう!</p>



<h2 class="wp-block-heading">プロジェクトの保存</h2>



<p>まず最初にソースを保存してみましょうか。</p>



<p>Pascal は、ソースの先頭に書いた名前とファイル名が一致しないといけないので、 program hellopi; としたので、ファイルに名前を付けて保存で、 hellopi.lpr として保存してください。</p>



<p>とりあえず今は、このファイルしかないので、メニューの [プロジェクト] → [名前を付けてプロジェクト保存] で保存しても同じ結果かなと思います。 </p>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" width="513" height="624" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-8.png" alt="" class="wp-image-6044" style="width:216px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-8.png 513w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-8-247x300.png 247w" sizes="(max-width: 513px) 100vw, 513px" /></figure>



<p>Pascal はこの他 unit というファイルもありまして、この後開発していく中で unit に分けて、uses で宣言して使うことになると思います。</p>



<h2 class="wp-block-heading">構築 (コンパイル + img出力)</h2>



<p>さていよいよ、コンパイルです。</p>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" width="387" height="229" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-10.png" alt="" class="wp-image-6046" style="width:194px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-10.png 387w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-10-300x178.png 300w" sizes="(max-width: 387px) 100vw, 387px" /></figure>



<p>[構築] でコンパイルと Raspi 用の img ファイルができあがります。</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="104" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-11-1024x104.png" alt="" class="wp-image-6047" style="width:601px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-11-1024x104.png 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-11-300x31.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-11-768x78.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-11.png 1061w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>こんな風に表示されたら、コンパイルは成功です。</p>



<p>出力先のフォルダ内をみてみましょう。</p>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" width="164" height="254" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-12.png" alt="" class="wp-image-6048" style="width:112px;height:auto"/></figure>



<p>このように出力されていれば成功かと思います。</p>



<h2 class="wp-block-heading">SDカードに書き込む</h2>



<p>先ほど生成された kernel7.img がこのプログラムの本体です。まずはこれをSDカードにコピーしましょう。</p>



<p>次に、 C:\Ultibo\Core\firmware\RPi3 のフォルダにある下の3つのファイルをSDカードにコピーします。</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="389" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-13-1024x389.png" alt="" class="wp-image-6049" style="width:474px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-13-1024x389.png 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-13-300x114.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-13-768x291.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/image-13.png 1041w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>結果、SDカードの中身は、下のようになります。</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="200" height="191" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/image-14.png" alt="" class="wp-image-6050"/></figure>



<h2 class="wp-block-heading">Raspi Zero に差して実行!</h2>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="576" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235558-1024x576.jpg" alt="" class="wp-image-6051" style="width:355px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235558-1024x576.jpg 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235558-300x169.jpg 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235558-768x432.jpg 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235558-1536x864.jpg 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235558-2048x1153.jpg 2048w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235558-800x450.jpg 800w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>micro SD-CARD を Raspi に差して、HDMIケーブルとモニタを繋いで、電源コードを差し込めば、すぐに起動します。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="576" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235603-1024x576.jpg" alt="" class="wp-image-6052" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235603-1024x576.jpg 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235603-300x169.jpg 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235603-768x432.jpg 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235603-1536x864.jpg 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235603-2048x1152.jpg 2048w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235603-800x450.jpg 800w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="576" src="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235607-1024x576.jpg" alt="" class="wp-image-6053" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235607-1024x576.jpg 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235607-300x169.jpg 300w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235607-768x432.jpg 768w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235607-1536x864.jpg 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235607-2048x1153.jpg 2048w, https://expertgig.jp/wp/wp-content/uploads/2025/06/IMG_20250606_235607-800x450.jpg 800w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>さすがに、OS無しは起動が速い!</p>



<p>とりあえず、起動までできたので、次からはさっそくDelphi で書いた MZ-80K2 のエミュを移植したいと思います。</p>



<p>うん? まてよ。まだUSBキーボードのテストをしていなかった。こちらが先かな。</p>



<p>ということで、今回はここまで。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://expertgig.jp/2025/06/07/raspi-zero-2w-%e3%83%99%e3%82%a2%e3%83%a1%e3%82%bf%e3%83%ab%e9%96%8b%e7%99%ba-02-%e7%92%b0%e5%a2%83%e6%a7%8b%e7%af%89%ef%bd%9ehello%e8%a1%a8%e7%a4%ba%e7%b7%a8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Delphi で MZ-80K エミュ開発 を再開 (数年ぶり)</title>
		<link>https://expertgig.jp/2025/05/31/delphi-%e3%81%a7-mz-80k-%e3%82%a8%e3%83%9f%e3%83%a5%e9%96%8b%e7%99%ba-%e3%82%92%e5%86%8d%e9%96%8b-%e6%95%b0%e5%b9%b4%e3%81%b6%e3%82%8a/</link>
					<comments>https://expertgig.jp/2025/05/31/delphi-%e3%81%a7-mz-80k-%e3%82%a8%e3%83%9f%e3%83%a5%e9%96%8b%e7%99%ba-%e3%82%92%e5%86%8d%e9%96%8b-%e6%95%b0%e5%b9%b4%e3%81%b6%e3%82%8a/#respond</comments>
		
		<dc:creator><![CDATA[Ariyuki Tano]]></dc:creator>
		<pubDate>Sat, 31 May 2025 09:46:37 +0000</pubDate>
				<category><![CDATA[マイコン]]></category>
		<category><![CDATA[情報発信基地]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[MZ-80]]></category>
		<category><![CDATA[Z80]]></category>
		<category><![CDATA[エミュレータ]]></category>
		<guid isPermaLink="false">https://expertgig.jp/?p=6010</guid>

					<description><![CDATA[以前、2021年頃に Delphi で MZ-80K のエミュを開発してみましたが、少し中途半端なところがあったので、数年ぶりにプロジェクトファイルを開いて、ソースを久しぶりに眺めてみました。 当時は、Delphi 10 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>以前、2021年頃に Delphi で MZ-80K のエミュを開発してみましたが、少し中途半端なところがあったので、数年ぶりにプロジェクトファイルを開いて、ソースを久しぶりに眺めてみました。</p>



<p>当時は、Delphi 10.4.1 で開発したのですが、今は Delphi 12.3 ( 2025/5/31現在 ) になっているので、少し手直し。</p>



<p>そういえば Delphi 12.3 は Skia4Delphi が標準で組み込まれたという話だったねということで、少し調べて画面描画部分を全体的に Skia に対応させて、描画速度の向上を図りました。</p>



<p>少し躓いたのは、少し前のバージョンでは Skia4Delphi のプラグインをインストールしたのですが、Delphi 12.3 では標準で組み込まれているというところ。uses に追加するライブラリ名が違うので、ややこしい。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="60" src="https://expertgig.jp/wp/wp-content/uploads/2025/05/image-21-1024x60.png" alt="" class="wp-image-6011" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/05/image-21-1024x60.png 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-21-300x18.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-21-768x45.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-21-1200x72.png 1200w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-21.png 1223w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p> 上記が正しい宣言ですが、前のバージョンでは、 SKia.FMX だったりしますし、ライブラリの構成も結構違うということで、少し迷子になりつつ、なんとか Skia 対応しました。</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="517" src="https://expertgig.jp/wp/wp-content/uploads/2025/05/image-22-1024x517.png" alt="" class="wp-image-6012" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/05/image-22-1024x517.png 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-22-300x151.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-22-768x388.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-22-1536x775.png 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-22-2048x1034.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>画面右の レジスタ内容の LED表示も Skia で高速描画する方法にしました。以前は大量に TImage を配置して visible を true / false して切り替えていました。visible の切り替えで簡単だろうと安易に考えていたのですが、内部的には画面の重ね合わせ処理などの書き換えが大量に発生していたんですね。メモリの処理もお任せで大丈夫だろうと思っていたのですが、何時間も放っておくとメモリリークが大量に発生した結果エラーになるという感じでした。昔のマイコンが熱暴走しているみたいでリアルだねとか、呑気に考えていたのですが、それじゃダメだねと思い直して、Skia で直接描画に切り替えた次第です。</p>



<p> ついでに、VRAM のメモリに変化があった部分だけ描画を書き換えるというプログラムに書き直しまして、少し高速化を図りました。実際どのくらい高速化したかは不明ですが、性能が悪いPCでテストすればかなり違うでしょう。</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<p class="responsive-video-wrap clr"><iframe title="Delphi で MZ-80K エミュ を久しぶり更新。( Skia 対応 )" width="1200" height="675" src="https://www.youtube.com/embed/XJc5x7VfWWY?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></p>
</div></figure>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://expertgig.jp/2025/05/31/delphi-%e3%81%a7-mz-80k-%e3%82%a8%e3%83%9f%e3%83%a5%e9%96%8b%e7%99%ba-%e3%82%92%e5%86%8d%e9%96%8b-%e6%95%b0%e5%b9%b4%e3%81%b6%e3%82%8a/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>PC-8001 のマシン語開発 (環境構築編)</title>
		<link>https://expertgig.jp/2025/05/17/pc-8001-%e3%81%ae%e3%83%9e%e3%82%b7%e3%83%b3%e8%aa%9e%e9%96%8b%e7%99%ba-%e7%92%b0%e5%a2%83%e6%a7%8b%e7%af%89%e7%b7%a8/</link>
					<comments>https://expertgig.jp/2025/05/17/pc-8001-%e3%81%ae%e3%83%9e%e3%82%b7%e3%83%b3%e8%aa%9e%e9%96%8b%e7%99%ba-%e7%92%b0%e5%a2%83%e6%a7%8b%e7%af%89%e7%b7%a8/#respond</comments>
		
		<dc:creator><![CDATA[Ariyuki Tano]]></dc:creator>
		<pubDate>Sat, 17 May 2025 05:20:06 +0000</pubDate>
				<category><![CDATA[マイコン]]></category>
		<category><![CDATA[情報発信基地]]></category>
		<category><![CDATA[PC-8001]]></category>
		<category><![CDATA[Z80]]></category>
		<category><![CDATA[アセンブラ]]></category>
		<category><![CDATA[エミュレータ]]></category>
		<category><![CDATA[マシン語]]></category>
		<guid isPermaLink="false">https://expertgig.jp/?p=5968</guid>

					<description><![CDATA[PC-8001 でオールマシン語のプログラムを実機でやろうと思うと気持ちが折れてしまいますので、2025年現在の方法で考えてみましょう。ちなみにこれは私の備忘録としての意味合いが強いです。最近忘れやすくて、細かく手順とか [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>PC-8001 でオールマシン語のプログラムを実機でやろうと思うと気持ちが折れてしまいますので、2025年現在の方法で考えてみましょう。ちなみにこれは私の備忘録としての意味合いが強いです。最近忘れやすくて、細かく手順とかをまとめておかないと本当にきれいさっぱり忘れてしまいます。</p>



<h2 class="wp-block-heading">まずはPC8001のエミュレータを準備</h2>



<p>PC-8001 は人気機種だけあって、エミュレータは多数存在します。それぞれ好みはあると思いますが、私は XM8 というエミュレータを利用しています。これはPC-8801MAのエミュレータなのですが、Nモードもありますので大丈夫です。</p>



<p>下記よりダウンロードできます。</p>



<p><a href="http://retropc.net/pi/xm8/index.html">http://retropc.net/pi/xm8/index.html</a></p>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" width="951" height="666" src="https://expertgig.jp/wp/wp-content/uploads/2025/05/image-4.png" alt="" class="wp-image-5974" style="aspect-ratio:1.427927927927928;width:463px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/05/image-4.png 951w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-4-300x210.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-4-768x538.png 768w" sizes="(max-width: 951px) 100vw, 951px" /></figure>



<h2 class="wp-block-heading">専用エディタの準備 (BASIC打ちこみ用)</h2>



<p>いわゆるテキストエディタなのですが、当時のマイコンのASCIIコードは各社独自で、キャラ文字も独自に設定されていますので、これに対応しないといけません。</p>



<p>下記より N-FONT をダウンロード (OUT of STANDARD さんのページ )させていただいて、</p>



<p><a href="http://upd780c1.g1.xrea.com/pc-8001/index.html">http://upd780c1.g1.xrea.com/pc-8001/index.html</a></p>



<p>エディタは、DumpListEditor 一択でしょう。エディタだけでなく、エミュ用のファイル出力なども統合されています。<br>正直これがないと、どうにもなりません。2025年現在もアップデートされ続けています。<br><a href="https://bugfire2009.ojaru.jp/download.html#dleditor">https://bugfire2009.ojaru.jp/download.html#dleditor</a></p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="654" src="https://expertgig.jp/wp/wp-content/uploads/2025/05/image-5-1024x654.png" alt="" class="wp-image-5975" style="aspect-ratio:1.5657492354740061;width:463px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/05/image-5-1024x654.png 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-5-300x192.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-5-768x491.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-5-1536x982.png 1536w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-5.png 1549w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>使い方はこっちのページで。</p>



<p>/<a href="https://expertgig.jp/2025/05/17/dumplisteditor-%e3%81%ae%e4%bd%bf%e3%81%84%e6%96%b9-pc-8001%e7%b7%a8/" data-type="post" data-id="5984">DumpListEditor の使い方  (PC-8001編)</a></p>



<p></p>



<p></p>



<h2 class="wp-block-heading">アセンブラ用エディタ</h2>



<p>これは何でもよいのですが、私は秀丸でやってます。色の設定などは 内藤氏の設定をまねてます。</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1021" height="1024" src="https://expertgig.jp/wp/wp-content/uploads/2025/05/image-2-1021x1024.png" alt="" class="wp-image-5972" style="aspect-ratio:0.9970703125;width:499px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/05/image-2-1021x1024.png 1021w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-2-300x300.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-2-150x150.png 150w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-2-768x770.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-2-1532x1536.png 1532w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-2.png 1585w" sizes="(max-width: 1021px) 100vw, 1021px" /></figure>



<p>この設定については、内藤氏が下記ページで説明されています。<br><a href="https://codeknowledge.livedoor.blog/archives/14714379.html">https://codeknowledge.livedoor.blog/archives/14714379.html</a></p>



<p>それで、最後に、『えーい面倒だ、これを食らえ!』となっていまして、私はこれをくらって設定しました。(笑)</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="292" src="https://expertgig.jp/wp/wp-content/uploads/2025/05/image-3-1024x292.png" alt="" class="wp-image-5973" style="aspect-ratio:3.506849315068493;width:459px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/05/image-3-1024x292.png 1024w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-3-300x85.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-3-768x219.png 768w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-3.png 1208w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<h2 class="wp-block-heading">Z80コンパイラ</h2>



<p>選択肢は数個ありますが、伝説のプログラマ 内藤氏 (ハイドライドなど開発された方) のおすすめが、AILZ80ASM ということで、それに倣って私も利用しています。</p>



<p><a href="https://github.com/AILight/AILZ80ASM">https://github.com/AILight/AILZ80ASM</a></p>



<h2 class="wp-block-heading">画面デザインツール</h2>



<p>上述の内藤氏作の 『IORI for PC-8001』をぜひ使っていただきたい。昔風に紙に書いてもいいのですが、PC-8001だとカラー画面を想定すると、カラー表示における制限事項がありますので、その辺のチェックもしてくれるこのツールはとても良いです。<br>これもダウンロードは、上記の DumpListEditor のダウンロードと同じ場所からお願いします。</p>



<p>下のスクリーンショットは、私が今回開発した OBSIDIAN のプレイ画面のデザインをしながら、1行の色数制限に引っ掛からないようにチェックした様子です。</p>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" width="890" height="523" src="https://expertgig.jp/wp/wp-content/uploads/2025/05/image.png" alt="" class="wp-image-5969" style="aspect-ratio:1.7017208413001912;width:429px;height:auto" srcset="https://expertgig.jp/wp/wp-content/uploads/2025/05/image.png 890w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-300x176.png 300w, https://expertgig.jp/wp/wp-content/uploads/2025/05/image-768x451.png 768w" sizes="(max-width: 890px) 100vw, 890px" /></figure>



<p>ちなみにですが私が独自にEXCELで作成して、開発時に使っているファイルもアップしておきます。</p>



<div class="wp-block-file"><a id="wp-block-file--media-62162822-8f58-483d-8823-7cbf50afbe56" href="blob:https://expertgig.jp/6e255286-bcb9-4f66-842a-86d91cbc4d3d">画面デザインシート_OBSIDIAN.xlsx</a><a href="blob:https://expertgig.jp/6e255286-bcb9-4f66-842a-86d91cbc4d3d" class="wp-block-file__button wp-element-button" download aria-describedby="wp-block-file--media-62162822-8f58-483d-8823-7cbf50afbe56">ダウンロード</a></div>



<p>マシン語でプログラムする際にVRAMのアドレスを直接指定したいケースが多々あります。またカラーモードにするとBASICですと画面左の1列が書き込みできなくなり、WIDTH 40,25 としても実際は 39×25 になってしまいます。理由は不明。仕様です (笑)。ですがマシン語ではVRAMに直接書き込めます。ますます理由が不明。</p>



<h2 class="wp-block-heading">環境設定の次は実際のアセンブルから実行まで</h2>



<p>環境がなんとか整いましたら、次はコードを書いて、アセンブラでアセンブルして読込可能なファイルを書き出して、エミュで実行となります。ここはかなりキモになります。これがスムーズにできないとデバッグで気持ちが折れちゃいますので。。</p>



<p>今回は、環境整備編 ということでここまで。あまり親切に書いていないので、もしご要望があれば連絡ください。追記します。</p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://expertgig.jp/2025/05/17/pc-8001-%e3%81%ae%e3%83%9e%e3%82%b7%e3%83%b3%e8%aa%9e%e9%96%8b%e7%99%ba-%e7%92%b0%e5%a2%83%e6%a7%8b%e7%af%89%e7%b7%a8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>2020年にPC-8001 の新作ゲームを発表してしまうのも面白いかも。</title>
		<link>https://expertgig.jp/2020/04/08/2020%e5%b9%b4%e3%81%abpc-8001-%e3%81%ae%e6%96%b0%e4%bd%9c%e3%82%b2%e3%83%bc%e3%83%a0%e3%82%92%e7%99%ba%e8%a1%a8%e3%81%97%e3%81%a6%e3%81%97%e3%81%be%e3%81%86%e3%81%ae%e3%82%82%e9%9d%a2%e7%99%bd/</link>
					<comments>https://expertgig.jp/2020/04/08/2020%e5%b9%b4%e3%81%abpc-8001-%e3%81%ae%e6%96%b0%e4%bd%9c%e3%82%b2%e3%83%bc%e3%83%a0%e3%82%92%e7%99%ba%e8%a1%a8%e3%81%97%e3%81%a6%e3%81%97%e3%81%be%e3%81%86%e3%81%ae%e3%82%82%e9%9d%a2%e7%99%bd/#respond</comments>
		
		<dc:creator><![CDATA[Ariyuki Tano]]></dc:creator>
		<pubDate>Tue, 07 Apr 2020 15:47:15 +0000</pubDate>
				<category><![CDATA[マイコン]]></category>
		<category><![CDATA[情報発信基地]]></category>
		<category><![CDATA[技術全般]]></category>
		<category><![CDATA[N-BASIC]]></category>
		<category><![CDATA[PC-8001]]></category>
		<category><![CDATA[Z80]]></category>
		<guid isPermaLink="false">http://expertgig.jp/?p=4091</guid>

					<description><![CDATA[40年前のマイコン PC-8001 でゲームを作る 1979年に発表されたNECのPC-8001。当時はまだパソコンという言葉がなく、マイコンと呼んでいました。 最近では、マイコンと言えば、RaspberryPi や A [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>40年前のマイコン PC-8001 でゲームを作る</h1>
<p>1979年に発表されたNECのPC-8001。当時はまだパソコンという言葉がなく、マイコンと呼んでいました。</p>
<p>最近では、マイコンと言えば、RaspberryPi や Arduino、ESP32 などの SBC (Single Board Computer)を意味しますね。</p>
<h2>懐古主義? と思われがちですが。。</h2>
<p>私の場合は、個人的な思い入れが非常に強いということもありますが、IoTシステムを構築する上で、コンピュータの根本を知るといことが重要になってきます。組み込み開発の分野では当たり前のことですが、一般的な業務システム開発、Webシステム開発の技術者が工場IoTとリンクするときにコンピュータとは何かというところを理解していないと問題が生じてしまいます。</p>
<h2>ということで今更ながらPC-8001用のゲームを作ってウォーミングアップ</h2>
<p>まだ発表するには時期尚早ですが、途中のものの一部をアップします。</p>
<p><img decoding="async" src="http://expertgig.jp/wp/wp-content/uploads/2020/04/image-1586267768581.png" alt="file"><br />
タイトル画面。PC-8001 では、2&#215;4ドット毎に1色しか指定することができません。160&#215;100ドットという低解像度ですが、うまく作成すれば、なんとなく味のあるデザインになます!</p>
<p><img decoding="async" src="http://expertgig.jp/wp/wp-content/uploads/2020/04/image-1586267812260.png" alt="file"><br />
当時、よくあったストーリーを表示する画面。Ultima II をイメージして作成してみました。</p>
<p><img decoding="async" src="http://expertgig.jp/wp/wp-content/uploads/2020/04/image-1586269270260.png" alt="file"><br />
キャラクターの初期パラメータを乱数で設定。キーを押してストップさせてそれぞれの値を決めていきます。昔の光栄の初期の「信長の野望」「三国志」がこんな感じのキャラ設定でした。多分。当時プログラムがBASICで書かれていたので、ここを最大値になるように改造してチートしてました。。</p>
<p><img decoding="async" src="http://expertgig.jp/wp/wp-content/uploads/2020/04/image-1586267900143.png" alt="file"><br />
フルグラフィックにしようかと思いましたが、ちょっとマシン語で書く時間もないので、BASICでもある程度スピードがでるようにキャラ文字オンリーでマップ表示。</p>
<h2>N-BASIC 小ネタ</h2>
<p>N-BASIC でゲームプログラムをする際のちょっとしたテクニックについて、おさらいします。(いまさらだれが必要としているのか不明ですが。。)</p>
<h3>ファンクションキーを設定する</h3>
<p>よく利用するコマンドをファンクションキーに割り当てることで、プログラム作成時の時間の節約になります。</p>
<pre><code class="language-VB">KEY1,"WIDTH 80,25"+CHR$(13)
KEY2,CHR$(12)
KEY3,"CONSOLE 0,25,1,1"+CHR$(13)</code></pre>
<h3>リアルタイムなキー入力は INP(n) を利用する</h3>
<p>キー入力には INKEY$ という命令もありますが、これはキークリックされたかどうか評価するものです。上記画面のパラメータを設定するような場合や、質問にY/N でこたえるような UI の場合は良いですが、ゲームのキャラクタを動かすときなどは、キーを押しっぱなしたときは連続してキャラクタが動いてほしい場面が多いかと思います。<br />
その際は、INP(n) で対象のキーの状態 (押下しているかどうか)を取得することができます。</p>
<table>
<thead>
<tr>
<th>ポート</th>
<th>0</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
<th>7</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>(0)</td>
<td>(1)</td>
<td>(2)</td>
<td>(3)</td>
<td>(4)</td>
<td>(5)</td>
<td>(6)</td>
<td>(7)</td>
</tr>
<tr>
<td>1</td>
<td>(8)</td>
<td>(9)</td>
<td>(*)</td>
<td>(+)</td>
<td>(=)</td>
<td>(,)</td>
<td>(.)</td>
<td>RET</td>
</tr>
<tr>
<td>2</td>
<td>@</td>
<td>A</td>
<td>B</td>
<td>C</td>
<td>D</td>
<td>E</td>
<td>F</td>
<td>G</td>
</tr>
<tr>
<td>3</td>
<td>H</td>
<td>I</td>
<td>J</td>
<td>K</td>
<td>L</td>
<td>M</td>
<td>N</td>
<td>O</td>
</tr>
<tr>
<td>4</td>
<td>P</td>
<td>Q</td>
<td>R</td>
<td>S</td>
<td>T</td>
<td>U</td>
<td>V</td>
<td>W</td>
</tr>
<tr>
<td>5</td>
<td>X</td>
<td>Y</td>
<td>Z</td>
<td>[</td>
<td>\</td>
<td>]</td>
<td>^</td>
<td>&#8211;</td>
</tr>
<tr>
<td>6</td>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
<td>*</td>
<td>+</td>
<td>&lt;</td>
<td>&gt;</td>
<td>?</td>
<td>_</td>
</tr>
<tr>
<td>8</td>
<td>HOME</td>
<td>↑</td>
<td>→</td>
<td>INS</td>
<td>GRPH</td>
<td>カナ</td>
<td>SHIFT</td>
<td>CTRL</td>
</tr>
<tr>
<td>9</td>
<td>STOP</td>
<td>F1</td>
<td>F2</td>
<td>F3</td>
<td>F4</td>
<td>F5</td>
<td>SPACE</td>
<td>ESC</td>
</tr>
<tr>
<td>Val</td>
<td>254</td>
<td>253</td>
<td>251</td>
<td>247</td>
<td>239</td>
<td>223</td>
<td>191</td>
<td>127</td>
</tr>
</tbody>
</table>
<p>()はテンキー側のキーボードを示しています。<br />
何も押されていないときは255となります。<br />
一般的な利用方法 (Zキーが押されていることを確認するとき)</p>
<pre><code>IF INP(5)=251 THEN ....</code></pre>
<p>ゲームの時はコード量を減らす技として、論理演算を利用することが多いです。<br />
例えば [4]で左、[6]で右にキャラクタを移動させるときに、移動量を論理式を使ってシンプルに記述することができます。</p>
<pre><code>I=INP(0):X=X+(I=191)-(I=239)</code></pre>
<p>それと、実は同じボードで同時に押されているキーも検出できます。上記の例では、 251や191などと書いていますがポートの1byte の8つのビットが0か1になっているだけです。<br />
何も押されていなければ、11111111B で255となっているだけです。例えば ポート0 で、テンキーの1が押されていたら11111110B、2が押されていたら 11111101B、同時に押されていたら、 11111100B となるだけのことです。これを10進数表記して条件に入れているだけです。</p>
<h3>INSTR で何種類かの入力を受け付けるようにする</h3>
<p>例えば、ゲームなどで Y,y,ﾝ,SPACE,RETURN で入力を待つようなときに、キーのモード (大文字、小文字、カナ)を気にしないで対応させる小ネタです。<br />
すなおに記述すると</p>
<pre><code>K$=INPUT$(1):PRINT K$;
IF K$="Y" OR K$="y" OR K$="ﾝ" OR K$=" " OR K$=CHR$(13) THEN.....</code></pre>
<p>となりますが、INSTR$ をうまく使うとすっきり書けます。</p>
<pre><code>K$=INPUT$(1):PRINT K$;
IF INSTR("Yyﾝ "+CHR$(13),K$) &lt;&gt; 0 THEN ....</code></pre>
<h2>タイトル画像の作成について</h2>
<p>160&#215;100 の低解像度画像とは言っても、手作業だとかなりだるいので、これは現代の力を借りました。</p>
<p>最初に 160 x 100 の画像を PhotoShop で作成。これをコントラストを上げて、さらに減色。これである程度の画像ができあがります。<br />
2&#215;4 ドット毎に1色しか色付けができないこと、1行では20回までしか色を変化されることができないという点を考慮してデザインすることも重要です。PNGで保存。<br />
このあとは、Delphi で作成したツールで画像を読み込んで、16進数に変換して、CSVで書き出しました。<br />
さすが文明の利器! らくちんでした。</p>
<h2>まだまだ制作途中です</h2>
<p>まだコーディング半ばなので、発表するまでに至りませんが、夜や週末にぼちぼち進めていきます。</p>
<p>MZ-80のエミュレーターも同時に作っているので、中々進まないです。。</p>
<h2>何がしたいのか?</h2>
<p>何がしたくて、過去のテクノロジーのおさらいをしているのかと申しますと、RaspberyPi などで、LinuxなどのOSなしで直接動かす、いわゆる Bare Metal で超高速なIoT機器を作りたいのです。 Arm系のマシン語をやったことがないので、Z80, 6809, 6502, 8086 でウォーミングアップして助走をつけているのです。。(笑)</p>
]]></content:encoded>
					
					<wfw:commentRss>https://expertgig.jp/2020/04/08/2020%e5%b9%b4%e3%81%abpc-8001-%e3%81%ae%e6%96%b0%e4%bd%9c%e3%82%b2%e3%83%bc%e3%83%a0%e3%82%92%e7%99%ba%e8%a1%a8%e3%81%97%e3%81%a6%e3%81%97%e3%81%be%e3%81%86%e3%81%ae%e3%82%82%e9%9d%a2%e7%99%bd/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
