PC-88 z80asmでセミグラフィック (3)

```semgra.asm
; z88dk / PC-88 mon
; z80asm -b -l semgra.asm

tvram   equ     $f3c8
vtvram  equ     $c3c8

        org     $b000
start:
        call    crtset
        call    vtinit
.mloop
        xor     a
        call    vtcls

        call    inkey           ; hl = (datidx)

        ld      b, 160          ; 列数
        ld      c, 0            ; x
.vloop
        push    bc
        ld      a, h
        and     $03             ; hl %= 1024
        ld      h, a
        push    hl
        add     hl, hl
        ld      de, data
        add     hl, de          ; hl = data + hl*2
        ld      d, (hl)
        ld      a, 50
        sub     d
        ld      b, a            ; y = 50 - d
        rlc     d               ; 高さ
        inc     hl
        ld      e, (hl)         ; 色
        call    vline
        pop     hl
        inc     hl
        pop     bc
        inc     c
        djnz    vloop

        call    vblank
        call    vtblt
        jr      mloop
.exit
        di
        halt

crtset:
        ld      hl, $e6b4
        ld      (hl), $98       ; アトリビュート
        inc     hl
        inc     hl
        inc     hl
        inc     hl
        ld      (hl), $00       ; ファンクション・キー表示スイッチ
        inc     hl
        ld      (hl), $ff       ; カラー／白黒スイッチ
        ld      b, 80
        ld      c, 25
        call    $6f6b           ; CRTSET
        ret

vblank:
        in      a, ($40)
        and     $20
        jr      nz, vblank
.wait
        in      a, ($40)
        and     $20
        jr      z, wait
        ret

vtinit:
        ld      hl, tvram
        ld      de, vtvram
        ld      bc, 120*25
        ldir
        ret

vtblt:
        ld      hl, vtvram
        ld      de, tvram
        ld      bc, 120*25
        ldir
        ret

vtcls:
        ld      hl, vtvram
        ld      b, 25
.vtcls1
        push    bc
        ld      (hl), a
        ld      d, h
        ld      e, l
        inc     de
        ld      bc, 80-1
        ldir
        ld      de, 40+1
        add     hl, de
        pop     bc
        djnz    vtcls1
        ret

inkey:
        ld      hl, (datidx)
        in      a, ($0a)        ; 左キー
        and     $04
        jr      nz, skip1
        dec     hl
        dec     hl
.skip1
        in      a, ($08)        ; 右キー
        and     $04
        jr      nz, skip2
        inc     hl
        inc     hl
.skip2
        ld      (datidx), hl
        ret

; vertical line
; b=y c=x d=高さ e=色
vline:
        ld      a, d
        or      a
        ret     z

        push    de
        ld      hl, pmasks
        ld      d, 0
        add     hl, de
        ld      a, (hl)
        ld      (pmask), a
        call    pset
.vline1
        pop     de
        dec     d
        ret     z
        push    de
        call    psetd
        jr      vline1

; point set
; b=y c=x
; use: a, de, hl
pset:
        ld      a, b            ; de = y & $fc
        and     $fc
        ld      e, a
        ld      d, 0

        ld      hl, 0           ; hl = de * 30
        add     hl, de
        add     hl, hl
        add     hl, de
        add     hl, hl
        add     hl, de
        add     hl, hl
        add     hl, de
        add     hl, hl          ; %11110=30倍

        ld      e, c            ; hl += x / 2
        srl     e
        add     hl, de
        ld      de, vtvram
        add     hl, de

        ld      a, b
        and     $03
        ld      e, a            ; e = y & 3
        ld      a, c            ; a = (x & 1 == 0) ? $01 : $10
        and     $01
        ld      a, $01
        jr      z, pset1
        ld      a, $10
.pset1
        dec     e
        jp      m, pset2
        add     a, a
        jr      pset1
.pset2
        call    psetdo
        ret

; pset down
; use: a, de, hl
psetd:
        ld      hl, (paddr)
        ld      a, (pbits)
        ld      e, a
        and     $88
        ld      a, e
        jr      z, psetd1

        ld      de, 120
        add     hl, de
        rlca
        rlca
        rlca
        rlca
.psetd1
        rlca
        call    psetdo
        ret

; pset do
; hl=addr a=bits
; use: a, e
psetdo:
        ld      (paddr), hl
        ld      (pbits), a
        ld      e, a
        ld      a, (pmask)
        and     e
        ld      a, e
        jr      z, psetdo0
.psetdo1
        or      (hl)
        ld      (hl), a
        ret
.psetdo0
        cpl
        and     (hl)
        ld      (hl), a
        ret

paddr:  defw    0
pbits:  defb    0
pmask:  defb    0
pmasks: defb    $ff, $5a

datidx: defw    0

data:
        defb    16,0,16,0,16,0,16,0,16,0,16,0,04,0,04,0,04,0,04,0,04,0,04,0,04,0,04,0,04,0,04,0
        defb    04,0,04,0,04,0,00,0,00,0,00,0,00,0,03,1,03,1,03,0,03,0,03,1,03,1,04,1,04,1,04,1
        defb    04,0,04,0,04,0,04,0,04,0,04,0,04,0,04,0,04,0,04,0,04,0,04,0,04,0,04,0,00,0,00,0
        defb    03,1,03,1,03,1,03,0,03,0,03,0,03,0,03,0,03,0,03,0,03,0,03,0,03,0,03,0,03,0,00,0
        defb    00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,03,0,03,1
        defb    03,1,05,1,05,1,07,1,07,1,07,1,07,1,07,1,07,1,07,1,07,1,07,1,07,1,08,1,08,1,08,1
        defb    08,1,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,07,0,07,0,07,0,07,0,07,0,07,0,07,0
        defb    07,0,07,0,07,0,07,0,07,0,07,0,06,1,06,1,06,0,06,0,06,0,06,0,06,0,06,0,05,0,05,0
        defb    05,0,05,0,05,0,05,0,05,0,05,0,00,0,00,0,00,0,00,0,00,0,00,0,03,1,03,1,03,1,03,1
        defb    03,1,04,1,04,1,05,1,05,1,05,1,05,1,16,1,16,1,16,1,16,1,16,1,16,1,16,1,16,1,16,1
        defb    16,1,16,1,16,1,16,1,16,1,16,1,16,1,16,1,16,1,17,1,17,1,17,1,17,1,17,1,17,1,28,1
        defb    28,1,28,1,28,1,28,1,28,1,28,1,28,1,28,1,28,1,28,1,28,1,28,1,28,1,28,1,28,1,28,1
        defb    28,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1
        defb    29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,30,1,30,1
        defb    30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1
        defb    30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1
        defb    30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1
        defb    30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1,30,1
        defb    30,1,30,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1
        defb    29,1,29,1,29,1,29,1,29,1,29,1,29,1,29,1,18,1,18,1,18,1,30,0,30,0,30,0,30,0,32,0
        defb    32,0,32,0,32,0,33,0,33,0,33,0,33,0,33,0,34,0,34,0,34,0,34,0,34,0,36,0,36,0,36,0
        defb    36,0,36,0,36,0,36,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,38,0,40,0,40,0,40,0,40,0
        defb    40,0,40,0,40,0,40,0,40,0,42,0,42,0,42,0,42,0,42,0,42,0,42,0,42,0,42,0,42,0,42,0
        defb    42,0,44,0,44,0,44,0,44,0,44,0,44,0,44,0,44,0,44,0,44,0,44,0,44,0,44,0,44,0,44,0
        defb    44,0,47,0,47,0,47,0,47,0,47,0,47,0,47,0,47,0,47,0,47,0,47,0,47,0,47,0,47,0,47,0
        defb    47,0,47,0,47,0,47,0,47,0,47,0,47,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0
        defb    50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0
        defb    50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0
        defb    50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0
        defb    50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,0,50,1,50,1,50,1,50,1,50,1,50,1,50,1,47,1
        defb    47,1,47,1,47,1,44,1,44,1,44,1,42,1,42,1,40,1,40,1,38,1,38,1,36,1,34,1,34,1,33,1
        defb    32,1,29,1,28,1,27,1,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0
        defb    00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0
        defb    05,1,05,0,05,0,05,0,05,0,05,0,05,0,05,0,05,0,05,0,05,0,05,0,05,0,05,0,05,0,05,0
        defb    05,0,05,0,05,0,05,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0
        defb    00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0
        defb    00,0,00,0,03,1,03,1,03,1,04,1,04,1,04,1,04,0,04,0,04,0,04,0,04,0,04,0,04,0,04,0
        defb    07,1,07,1,07,1,07,1,07,1,07,1,08,1,08,1,08,1,08,1,08,1,08,1,08,1,08,1,08,1,08,0
        defb    08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0
        defb    08,0,08,0,07,0,07,0,07,0,07,0,04,1,04,1,04,1,04,1,04,0,04,0,04,0,04,0,04,0,04,0
        defb    04,0,04,0,04,0,04,0,04,0,00,0,00,0,00,0,00,0,07,1,07,1,07,1,08,1,08,1,08,1,08,1
        defb    08,1,08,1,09,1,09,1,09,1,09,1,09,1,09,1,09,1,09,1,09,1,09,1,09,1,09,1,09,1,09,1
        defb    09,1,09,1,09,1,09,1,09,1,09,1,09,0,09,0,09,0,09,0,09,0,09,0,09,0,09,0,08,0,08,0
        defb    08,0,08,0,08,0,08,0,08,0,08,1,08,0,08,0,08,0,08,0,07,0,07,0,07,0,07,0,07,0,07,0
        defb    07,0,05,1,05,1,05,1,05,1,05,1,05,1,05,1,05,1,05,1,05,1,05,1,05,1,05,1,05,1,05,1
        defb    05,0,05,0,05,0,08,1,08,1,08,1,08,1,08,1,08,1,08,1,08,1,08,1,08,1,08,1,08,1,20,1
        defb    20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1
        defb    20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1
        defb    20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1
        defb    20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1
        defb    20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1,20,1
        defb    20,1,20,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,10,1,00,0
        defb    10,0,10,0,10,0,11,0,11,0,11,0,11,0,11,0,11,0,11,0,11,0,12,0,12,0,12,0,12,0,12,0
        defb    12,0,12,0,13,0,13,0,13,0,13,0,13,0,13,0,13,0,13,0,14,0,14,0,14,0,14,0,14,0,14,0
        defb    14,0,14,0,14,0,15,0,15,0,15,0,15,0,15,0,15,0,15,0,15,0,16,0,16,0,16,0,16,0,16,0
        defb    16,0,16,0,16,1,16,1,16,1,16,1,16,1,16,1,16,1,16,1,16,1,16,1,15,1,15,1,15,1,15,1
        defb    15,1,15,1,15,1,15,1,15,1,15,1,15,1,14,1,14,1,14,1,14,1,14,1,14,1,14,1,14,1,14,1
        defb    14,1,14,1,14,1,13,1,13,1,13,1,13,1,13,1,00,0,00,0,00,0,00,0,00,0,00,0,00,0,00,0
        defb    00,0,00,0,00,0,00,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0
        defb    08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,08,0,09,0,09,0
        defb    08,1,08,1,08,1,08,1,08,1,08,1,08,1,08,1,08,1,07,1,15,0,15,0,15,0,15,0,15,0,15,0
        defb    15,0,15,0,15,0,15,0,15,0,15,0,15,0,15,0,15,0,15,0,15,0,15,0,15,0,15,0,15,0,15,0
        defb    15,0,15,0,15,0,15,0,15,0,15,0,15,0,15,0,15,0,16,0,16,0,16,0,16,0,16,0,16,0,16,0
        defb    16,0,16,0,16,0,16,0,16,0,16,0,16,0,16,0,16,0,16,0,16,0,16,0,16,0,16,0,16,0,16,0
```

![semgra.png](https://qiita-image-store.s3.amazonaws.com/0/257554/1394c69c-6fee-9f6a-0eef-88844e0708f3.png)