学研TV BOYエミュレータをつくる その3

Cコンパイラ開発顛末記 小窓次郎 | 組み込み業界独り言からCコンパイラ(C3PO)をダウンロードして、TVボーイでMC6847を表示するプログラムを開発して行きます。

f:id:tanam:20200606161047p:plain

VRAM($1000-$17FF)、ROM($F000-$FFFF)の想定で書いていきます。

hello.c
int memset(p, x, y)
char	*p;
char	x;
int	y;
{
	int i;
	for (i=0; i<y; i++,p++) {
		*p=x;
	}
	return 0;
}

int main()
{
	char *p;
	char *q;
	p="HELLO WORLD";
	q=0x2000;
	*q=0x20;
	memset(0x1000, ' ', 0x800);
	for (q=0x1000; *p != 0; q++, p++) {
		*q = *p;
	}
	return 0;
}

MS-DOSで開発します。

>msdos C3PO.EXE HELLO
>notepad hello.src

hello.srcを編集してhello.txtで保存します。DOS用8ビットCPUクロスアセンブラでSレコード形式を作成します。

>msdos X6801.EXE hello

6801 Cross Assembler Version 3.12
   Copyright(C) Arcpit Co.,LTD.1990. All rights reserved.

Object Filename [HELLO.S] :
Source Listting [NUL.LST] :
Cross Reference [NUL.CRF] :
Symbol Table [NUL.MAP] :
^L                                     2020- 6- 7 6801 Assembler  Page    1
                                                      File:HELLO.TXT

    1                   ;       INCLUDE 630X.LIB
    2                   ;
    3                   ;***** C3PO for 6301/3 version 3.06c MSDOS ***** Nishiy
    4                   ; *** Copyright (c) S.Nishiyama Mar 14 1992
    5                   ;***          1 int memset(p, x, y)
    6                   ;***          2 char    *p;
    7                   ;***          3 char    x;
    8                   ;***          4 int     y;
    9                   ;***          5 {
   10                   ;***          6         int i;
   11                   ;***          7         for (i=0; i<y; i++,p++) {
   12                   ;       CSEG
   13                   ;       GLOBAL  _memset
   14 F000                         ORG      $F000
   15 00FF              STACK      EQU      $FF
   16 F000 8E00FF       START      LDS      #STACK
   17 F003 2035                    BRA      _main
   18 F005              _memset:
   19 F005 3C                      PSHX
   20 F006 30                      TSX
   21 F007 37                      PSHB
   22 F008 36                      PSHA
   23 F009 34                      DES
   24 F00A 34                      DES
   25 F00B 4F                      CLRA
   26 F00C 5F                      CLRB
   27 F00D 30                      TSX
   28 F00E ED00                    STD      0,X
   29 F010              L3:
   30 F010 EC08                    LDD      8,X
   31 F012 A300                    SUBD     0,X
   32 F014 2F19                    BLE      L2
   33                   ;***          8                 *p=x;
   34 F016 4F                      CLRA
   35 F017 E605                    LDAB     5,X
   36 F019 EE02                    LDX      2,X
   37 F01B E700                    STAB     0,X
   38 F01D 30                      TSX
   39                   ;***          9         }
   40                   ;***         10         return 0;
   41 F01E              L4:
   42 F01E EC00                    LDD      0,X
   43 F020 C30001                  ADDD     #1
   44 F023 ED00                    STD      0,X
   45 F025 EC02                    LDD      2,X
   46 F027 C30001                  ADDD     #1
   47 F02A ED02                    STD      2,X
   48 F02C 7EF010                  JMP      L3
   49 F02F              L2:
   50 F02F 4F                      CLRA
   51 F030 5F                      CLRB
   52                   ;***         11 }
   53 F031 7EF034                  JMP      L1
   54 F034              L1:
   55 F034 31                      INS
   56 F035 31                      INS
   57 F036 31                      INS
   58 F037 31                      INS
^L                                     2020- 6- 7 6801 Assembler  Page    2
                                                      File:HELLO.TXT

   59 F038 38                      PULX
   60 F039 39                      RTS
   61                   ;** Local value mapping information
   62                   ;** i   EQU     0
   63                   ;** y   EQU     8
   64                   ;** x   EQU     5
   65                   ;** p   EQU     2
   66                   ;* Function 
   67                   ;* Executive step count 8
   68                   ;* Used stack size ===6 Byte===
^L                                     2020- 6- 7 6801 Assembler  Page    3
                                                      File:HELLO.TXT

   70                   ;***         12
   71                   ;***         13 int main()
   72                   ;***         14 {
   73                   ;***         15         char *p;
   74                   ;***         16         char *q;
   75                   ;***         17         p="HELLO WORLD";
   76                   ;       GLOBAL  _main
   77 F03A              _main:
   78 F03A 3C                      PSHX
   79 F03B 30                      TSX
   80 F03C 34                      DES
   81 F03D 34                      DES
   82 F03E 34                      DES
   83 F03F 34                      DES
   84 F040 3C                      PSHX
   85 F041 30                      TSX
   86 F042 CCF093                  LDD      #S0
   87 F045 ED04                    STD      4,X
   88                   ;***         18         q=0x2000;
   89 F047 CC2000                  LDD      #8192
   90 F04A ED02                    STD      2,X
   91                   ;***         19         *q=0x20;
   92 F04C EE02                    LDX      2,X
   93 F04E C620                    LDAB     #$20
   94 F050 E700                    STAB     0,X
   95 F052 30                      TSX
   96                   ;***         20         memset(0x1000, ' ', 0x800);
   97 F053 CC0800                  LDD      #2048
   98 F056 37                      PSHB
   99 F057 36                      PSHA
  100 F058 CE0020                  LDX      #32
  101 F05B 05                      ASLD
  102 F05C BDF005                  JSR      _memset
  103 F05F 31                      INS
  104 F060 31                      INS
  105 F061 30                      TSX
  106                   ;***         21         for (q=0x1000; *p != 0; q++, p+
  107 F062 CC1000                  LDD      #4096
  108 F065 ED02                    STD      2,X
  109 F067              L7:
  110 F067 EE04                    LDX      4,X
  111 F069 4F                      CLRA
  112 F06A E600                    LDAB     0,X
  113 F06C 30                      TSX
  114 F06D 271B                    BEQ      L6
  115                   ;***         22                 *q = *p;
  116 F06F EE04                    LDX      4,X
  117 F071 E600                    LDAB     0,X
  118 F073 30                      TSX
  119 F074 EE02                    LDX      2,X
  120 F076 E700                    STAB     0,X
  121 F078 30                      TSX
  122                   ;***         23         }
  123                   ;***         24         return 0;
  124 F079              L8:
  125 F079 EC02                    LDD      2,X
  126 F07B C30001                  ADDD     #1
  127 F07E ED02                    STD      2,X
^L                                     2020- 6- 7 6801 Assembler  Page    4
                                                      File:HELLO.TXT

  128 F080 EC04                    LDD      4,X
  129 F082 C30001                  ADDD     #1
  130 F085 ED04                    STD      4,X
  131 F087 7EF067                  JMP      L7
  132 F08A 20FE         L6:        BRA      L6
  133                   ;***         25 }
  134 F08C 7EF08F                  JMP      L5
  135 F08F              L5:
  136 F08F 38                      PULX
  137 F090 35                      TXS
  138 F091 38                      PULX
  139 F092 39                      RTS
  140                   ;** Local value mapping information
  141                   ;** q   EQU     2
  142                   ;** p   EQU     4
  143                   ;* Function 
144 ;* Executive step count 12 145 ;* Used stack size ===14 Byte=== ^L 2020- 6- 7 6801 Assembler Page 5 File:HELLO.TXT 147 ;*** 26 148 F093 S0: 149 F093 48454C4C4F20 FCB 72,69,76,76,79,32,87,79 574F 150 F09B 524C4400 FCB 82,76,68,0 151 ;* Direct page size 0 152 ;* Global segment size 0 153 ;* Character size 12 154 ;* Executive step count 20 155 ;* Error count 0 156 FFFE ORG $FFFE 157 FFFE F000 FDB START 158 0000 END ^L 2020- 6- 7 6801 Assembler Page 6 File:HELLO.TXT SYMBOL TABLE: L1 F034 L2 F02F L3 F010 L4 F01E L5 F08F L6 F08A L7 F067 L8 F079 S0 F093 STACK 00FF START F000 _main F03A _memset F005 ^L 2020- 6- 7 6801 Assembler Page 7 File:HELLO.TXT 0 Error(s) detected. LINES : 158 LABELS : 13 LAST PROGRAM ADDRESS : $FFFD LAST DATA ADDRESS : $0000

SRecord 1.64でhello.sをhello.binに変換します。

>srec_cat hello.S -offset -0xF000 -o hello.bin -binary