令和からZ80を始める為のメモ

# 趣味の個人メモです

Z80を動かすための方法をまとめていく


## 参考書籍

https://www.amazon.co.jp/%E5%9B%B3%E8%A7%A3-Z80-%E3%83%9E%E3%82%B7%E3%83%B3%E8%AA%9E%E5%88%B6%E5%BE%A1%E3%81%AE%E3%81%99%E3%81%B9%E3%81%A6%E2%80%95%E3%83%8F%E3%83%BC%E3%83%89%E3%81%8B%E3%82%89%E3%82%BD%E3%83%95%E3%83%88%E3%81%BE%E3%81%A7-%E7%99%BD%E5%9C%9F-%E7%BE%A9%E7%94%B7/dp/4501514507

一番わかりやすい


## アセンブラ
https://k1.spdns.de/Develop/Projects/zasm/Distributions/

Windows x64　なら以下のリンクから
https://k1.spdns.de/Develop/Projects/zasm/Distributions/zasm-4.4.9-Windows64.zip

```
>zasm.exe
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
  zasm - 8080/z80/z180 assembler (c) 1994 - 2022 Günter Woigk.
  version 4.4.9, 2022-03-15, for Unix-Linux.
  homepage: https://k1.spdns.de/zasm/
  git repo: https://github.com/Megatokio/zasm

syntax:
  zasm [options] [-i] inputfile [[-l] listfile|dir] [[-o] outfile|dir]
  zasm [--version|--help]

  default output dir = source dir
  default list dir   = output dir

examples:
  zasm speccirom.asm
  zasm -uwy emuf_rom.asm rom_v2.0.1.rom

options:
  -u  --opcodes   include object code in list file
  -w  --labels    append label listing to list file
  -y  --cycles    include cpu clock cycles in list file
  -b  --bin       write output to binary file (default)
  -x  --hex       write output in intel hex format
  -s  --s19       write output in motorola s-record format
  -z  --clean     clear intermediate files, e.g. compiled c files
  -e  --compare   compare own output to existing output file
  -T  --test      run self test (requires test directory with test sources)
  -g  --cgi       prevent access to files outside the source dir
  --maxerrors=NN  set maximum for reported errors (default=30, max=999)
  --date=DATETIME for reproducible __date__ and __time__
  --target=ram    default to target 'ram' => cpu addresses in hex files
  -o0             don't write output file
  -l0             don't write list file
  --8080          target Intel 8080 (default if --asm8080)
  --z80           target Zilog Z80  (default except if --asm8080)
  --z180          target Zilog Z180 / Hitachi HD64180
  --asm8080       use 8080 assembler syntax
  --convert8080   convert 8080 assembler source to Z80
  -v[0,1,2]       verbosity of messages to stderr (0=off, 1=default, 2=more)
  --ixcbr2        enable illegal instructions like 'set b,(ix+d),r'
  --ixcbxh        enable illegal instructions like 'set b,xh'
  --dotnames      allow label names starting with a dot '.'
  --reqcolon      require colon ':' after program label definitions
                  => label definitions and instructions may start in any column
  --casefold      label names are case insensitive (implied if --asm8080)
  --flatops       no operator precedence: evaluate strictly from left to right
  -c [path/to/]cc declare or set path to c compiler (search in $PATH)
  -t path/to/dir  set path to temp dir for c compiler (default: output dir)
  -I path/to/dir  set path to c system header dir (default: compiler default)
  -L path/to/dir  set path to standard library dir (default: none)
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

>zasm.exe init8250.asm
assembled file: init8250.asm
    244 lines, 2 passes, 0.0025 sec.
    no errors
```

## Z80 命令セット

- PDF

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwjSzPmI28T7AhWWHnAKHffgChMQFnoECA4QAQ&url=https%3A%2F%2Fuserweb.alles.or.jp%2Fchunichidenko%2Fnd3setumeisyo%2Fnd3_z80meirei.pdf&usg=AOvVaw0MV6fStCDi3Q0Lp2cxAaku

- WEB

http://www.yamamo10.jp/yamamoto/comp/Z80/instructions/index.php

## 目指すBASIC

- NASCOM_BASIC_4.7

https://github.com/feilipu/NASCOM_BASIC_4.7

- NASCOMについて

http://www.nascomhomepage.com/

- Tiny Basic

http://cpuville.com/Code/Tiny-BASIC.html


## アセンブラの書き方

### JP

0番地から始まりNOPを２回行った後にMAIN(0x0010)番地に飛んでHALTする
```
    .ORG $0000
INIT:           NOP
                NOP
            JP  MAIN
    .ORG $0010
MAIN:
        HALT
```

### LD

LD A,xxx 　　XXXの値をAレジスタに保存
LD (xxxx),A 　　Aレジスタの値をXXXXに保存
LD A,(xxxx) 　　xxxxアドレスの値をAレジスタに保存（確認用）
JP xxxx 　　xxxx番地へジャンプ

```    
.ORG $0000
INIT:           NOP
                NOP
            JP  MAIN
    .ORG $0010
MAIN:
    LD  A,0x76
    LD  (0x8000),A
    LD  A,(0x8000)
    JP  0x8000
```

### IOとLOOP

Z80のIOモードはアドレスが下位8bitのみである（上位8bitにはIOのデータが載ってた）
LOOPの方法は他にもあるっぽい。

```
    .ORG $0000
INIT:           NOP
                NOP
            JP  MAIN

    .ORG $0010
MAIN:
    LD  A,0x12
    OUT (0x00),A
    NOP
    LD  B,0x05

LOOP:
    NOP
    DJNZ    LOOP
    
    LD  A,0x34
    OUT (0x00),A
    NOP
    JP MAIN
```