0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

z88dk MSX VDPコマンド HMMC

0
Last updated at Posted at 2026-02-04

テクニカルハンドブックに掲載されているHMMCのコードは、画像が表示されない

以下修正コード
DIX=0, DIY=0で固定

vdp_hmmc.c
#include <stdint.h>

void vdp_hmmc(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t data_addr) {
#asm
RPORT:  EQU     0006H
WPORT:  EQU     0007H

INIT:
        ld ix,2
        add ix,sp
        ld iy,(ix)      ; data_addr
        ld e,(ix+2)     ; h (NY)
        ld d,(ix+4)     ; w (NX)
        ld l,(ix+6)     ; y (DY)
        ld h,(ix+8)     ; x (DX)
START:   
        DI                              ;disable interrupt
        CALL    WAIT_VDP                ;wait end of command

        LD      A,(WPORT)
        LD      C,A
        INC     C                       ;C := PORT#1's address
        LD      A,36
        OUT     (C),A
        LD      A,17+80H
        OUT     (C),A                   ;R#17 := 36

        INC     C
        INC     C                       ;C := PORT#3's address
        XOR     A
        OUT     (C),H                   ; R#36 DX
        OUT     (C),A                   ; R#37 0
        OUT     (C),L                   ; R#38 DY
        OUT     (C),A                   ; R#39 0
        XOR     A                       ; A=0
        OUT     (C),D                   ; R#40 NX
        OUT     (C),A                   ; R#41 0
        OUT     (C),E                   ; R#42 NY
        OUT     (C),A                   ; R#43 0
        LD      H,(IY)
        OUT     (C),H                   ; R#44 first DATA
        OUT     (C),A                   ; R#45 DIX=0 and DIY=0
        LD      A,0F0H
        OUT     (C),A                   ; R#46 HMMC command

        LD      A,(WPORT)
        LD      C,A
        INC     C                       ; C=PORT#1                    
        LD      A,44+80H
        OUT     (C),A
        LD      A,17+80H
        OUT     (C),A
        INC     C
        INC     C

LOOP:   LD      A,2
        CALL    GET_STATUS
        BIT     0,A                     ;check CE bit
        JR      Z,EXIT
        BIT     7,A                     ;check TR bit
        JR      Z,LOOP
        INC     IY
        LD      A,(IY)
        OUT     (C),A
        JR      LOOP

EXIT:   LD      A,0
        CALL    GET_STATUS              ;when exit, you must select S#0
        EI
        RET

GET_STATUS:                             ;read status register specified by A
        PUSH    BC
        LD      BC,(WPORT)
        INC     C
        OUT     (C),A
        LD      A,8FH
        OUT     (C),A
        LD      BC,(RPORT)
        INC     C
        IN      A,(C)
        POP     BC
        RET

WAIT_VDP:                               ;wait VDP ready
        LD      A,2
        CALL    GET_STATUS
        AND     1
        JR      NZ,WAIT_VDP
        XOR     A
        CALL    GET_STATUS
        RET
#endasm
}
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?