LoginSignup
1
0

More than 5 years have passed since last update.

PC-88 z80asmでランダムドット

Posted at
pset.asm
; z88dk / PC-88 mon
; z80asm -b -l pset.asm

TVRAM   equ     $f3c8

        org     $b000
start:
        call    crtset
        ld      iy, paint1
.mloop
        ld      hl, pset
        ld      (paint2+1), hl
        ld      (iy+1), 0
        call    paint
        ld      (iy+1), 1
        call    paint
        call    randot

        ld      hl, preset
        ld      (paint2+1), hl
        ld      (iy+1), 0
        call    paint
        ld      (iy+1), 1
        call    paint
        call    randot

        jr      mloop

paint:
        ld      b, 0
.paint1
        ld      c, 0
.paint2
        call    0
        inc     c
        inc     c
        ld      a, c
        cp      160
        jr      c, paint2
        inc     b
        ld      a, b
        cp      100
        jr      c, paint1
        ret

randot:
        ld      hl, 10000
.randot0
        push    hl
.randot1
        call    rnd
        ld      a, l
        cp      160
        jr      nc, randot1
        ld      c, a
        ld      a, h
        and     $7f
        cp      100
        jr      nc, randot1
        ld      b, a
        call    pset
.randot2
        call    rnd
        ld      a, l
        cp      160
        jr      nc, randot2
        ld      c, a
        ld      a, h
        and     $7f
        cp      100
        jr      nc, randot2
        ld      b, a
        call    preset

        pop     hl
        dec     hl
        ld      a, l
        or      h
        jr      nz, randot0
        ret

rnd:
        ld      hl, $cafe
        add     hl, hl
        ld      a, h
        jr      nc, noxor
        xor     2
.noxor
        bit     1, a
        jr      nz, noinc
        inc     l
.noinc
        ld      (rnd+1), hl
        ret

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

; point set
; b=y c=x
pset:
        call    pcalc
        or      (hl)
        ld      (hl), a
        ret

; point reset
; b=y c=x
preset:
        call    pcalc
        cpl
        and     (hl)
        ld      (hl), a
        ret

; point calc
; in : b=y c=x
; out: hl=addr a=bits
pcalc:
        ld      a, b            ; de = y & $fc
        and     $fc
        ld      e, a
        ld      d, 0

        ld      h, d            ; hl = de * 30
        ld      l, e
        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, TVRAM
        add     hl, de
        push    hl

        ld      a, c
        and     $01
        add     a, a
        add     a, a
        ld      e, a
        ld      a, b
        and     $03
        or      e
        ld      e, a
        ld      d, 0
        ld      hl, PCALC
        add     hl, de
        ld      a, (hl)
        pop     hl
        ret

PCALC:  defb    $01,$02,$04,$08,$10,$20,$40,$80

pset.png

1
0
2

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