LoginSignup
1
0

More than 1 year has passed since last update.

BDS Cでfloatのようなものを使ってみた

Last updated at Posted at 2022-09-05

はじめに

環境:Windows 11

準備

CP/Mエミュレータ

から cpm32_04.zip をダウンロード。
解凍し、適当なディレクトリに配置する(例:C:\etc\cpm32_04)

BDS C

から bdsc-all.zip をダウンロード。
解凍し、適当なディレクトリに配置する(例:C:\etc\bdsc-all)

bdsc160\work にある STDIO.H を bdsc160 にコピーする。

hello, world

適当な作業ディレクトリを用意する(例:C:\Projects\etc\BDS_C)

dev.bat
@echo off
path %path%;C:\etc\cpm32_04
set CPMPATH=C:\etc\bdsc-all\bdsc160
cmd
hello.c
/*
cpm -a cc b:hello
cpm -a clink b:hello
*/
#include <stdio.h>

main()
{
	printf("hello, BDS C\n");
}

コンパイル・実行例

C:\Projects\etc\BDS_C>cpm -a cc b:hello
BD Software C Compiler v1.60  (part I)
  43K elbowroom
BD Software C Compiler v1.60 (part II)
  40K to spare
C:\Projects\etc\BDS_C>cpm -a clink b:hello
BD Software C Linker   v1.60

Last code address: 0E48
Externals start at 0E49, occupy 0006 bytes, last byte at 0E4E
Top of memory: FDFF
Stack space: EFB1
Writing output...
  51K link space remaining
C:\Projects\etc\BDS_C>cpm hello
hello, BDS C

C:\Projects\etc\BDS_C>

BCD Function Package

資料

詳しくは bdsc-all\bdsc-guide.pdf の
P.161 9.2 A BCD Function Package For BDS C
を参照。

ヘッダとライブラリ

extra ディレクトリにある
BCD.LBR
MCONFIG.H
を bdsc160 ディレクトリにコピーする。

以下のコマンドで参照、展開する。
lbrext コマンドは U オプションを付けないと圧縮されたまま展開されてしまう。

cpm -a ldir bcd
cpm -a lbrext bcd *.* U

実行例

C:\Projects\etc\BDS_C>cpm -a ldir bcd

Library File = bcd     .LBR

   Name           Length     Method   Cre Date   Mod Date       Comments
============   ============ ========  ====================  =================
BCD     .CZL    78r   9.75k Crunched  FF ore] FF  16 Oct 89  (--> BCD.CRL)
BCD1    .CZM    17r   2.12k Crunched  01 Jan 89  01 Jan 89  (--> BCD1.CSM)
BCD2    .CZM    89r  11.12k Crunched  01 Jan 89  01 Jan 89  (--> BCD2.CSM)
BMATH   .CZ     68r   8.50k Crunched  01 Jan 89  01 Jan 89  (--> BMATH.C  )
DEMO1   .CZ      9r   1.12k Crunched  01 Jan 89  01 Jan 89  (--> DEMO1.C  )
LMATH   .CZ      4r   0.50k Crunched  01 Jan 89  01 Jan 89  (--> LMATH.C  )
TSTINV  .CZ      4r   0.50k Crunched  01 Jan 89  01 Jan 89  (--> TSTINV.C  )

C:\Projects\etc\BDS_C>cpm -a lbrext
LbrExtract, Version 2.6
 Syntax: LBRE dir:library dir:afn1,dir:afn2,... o
Options:
   U - Unsqueeze/Uncrunch  squeezed/crunched files
   O - Overwrite existing files

C:\Projects\etc\BDS_C>cpm -a lbrext bcd *.* U
 File: BCD.CZL      ---> A0:BCD.CRL
 File: BCD1.CZM     (01/01/89) ---> A0:BCD1.CSM
 File: BCD2.CZM     (01/01/89) ---> A0:BCD2.CSM
 File: BMATH.CZ     (01/01/89) ---> A0:BMATH.C
 File: DEMO1.CZ     (01/01/89) ---> A0:DEMO1.C
 File: LMATH.CZ     (01/01/89) ---> A0:LMATH.C
 File: TSTINV.CZ    (01/01/89) ---> A0:TSTINV.C

C:\Projects\etc\BDS_C>

サンプル1

fig1.c
/*
cpm -a cc b:fig1
cpm -a clink b:fig1 a:bcd
*/
#include <stdio.h>
#include <mconfig.h>

main()
{
	FLOAT(f);

	atof(f, "3.14");
	printf("f = %f\n", f);
}

コンパイル・実行例

C:\Projects\etc\BDS_C>cpm -a cc b:fig1
BD Software C Compiler v1.60  (part I)
  43K elbowroom
BD Software C Compiler v1.60 (part II)
  40K to spare
C:\Projects\etc\BDS_C>cpm -a clink b:fig1 a:bcd
BD Software C Linker   v1.60

Last code address: 3D0A
Externals start at 3D0B, occupy 0006 bytes, last byte at 3D10
Top of memory: FDFF
Stack space: C0EF
Writing output...
  40K link space remaining
C:\Projects\etc\BDS_C>cpm fig1
f = 3.140000

C:\Projects\etc\BDS_C>

サンプル2

fig2.c
/*
cpm -a cc b:fig2
cpm -a clink b:fig2 a:bcd
*/
#include <stdio.h>
#include <mconfig.h>

main()
{
	FILE *pf;
	char buf[128];
	FLOAT(fHeight);
	FLOAT(res);
	FLOAT(tmp);

	pf = fopen("fig2.txt", "rt");
	if (pf == NULL) {
		printf("fopen error\n");
		return;
	}

	fgets(buf, 128, pf);
	printf(buf);
	scanf("%f", fHeight);

	fpmult(
		atof(tmp,"0.9"),
		fpsub(fHeight, atof(tmp,"100"), res),
		res);

	fgets(buf, 128, pf);
	printf(buf, res);
	fclose(pf);
}

文字列はコンパイル時に7bit目が0にされてしまうらしいので、sjisなどを使いたいときは別の方法で用意する。

fig2.txt
身長を入力してください(単位はcm)。
あなたの標準体重は %.2f Kg です。

実行例

C:\Projects\etc\BDS_C>cpm fig2
身長を入力してください(単位はcm)。
170.5
あなたの標準体重は 63.45 Kg です。

C:\Projects\etc\BDS_C>
1
0
0

Register as a new user and use Qiita more conveniently

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