libmsx
C library for MSX
Loading...
Searching...
No Matches
vdp.h
Go to the documentation of this file.
1// -*- coding: utf-8-unix -*-
2/*
3 * Copyright (c) 2021-2025 Daishi Mori (mori0091)
4 *
5 * This software is released under the MIT License.\n
6 * See https://github.com/mori0091/libmsx/blob/main/LICENSE
7 *
8 * GitHub libmsx project\n
9 * https://github.com/mori0091/libmsx
10 */
22#pragma once
23
24#ifndef VDP_H
25#define VDP_H
26
27#include <assert.h>
28#include <stdbool.h>
29#include <stdint.h>
30
31#include "io.h"
32#include "vmem.h"
33#include "vdp_unsafe.h"
34
35#include "bios.h"
36#include "workarea.h"
37
38// ---- VDP status register
66uint8_t vdp_get_status(uint8_t reg);
67
70// ---- VDP control registers
84void vdp_set_control(uint8_t reg, uint8_t x);
85
93void vdp_write_control(uint8_t reg, void* src, uint8_t len);
94
97// ---- VDP color register
150void vdp_set_color(uint8_t c); // set color register R#7
151
154// ---- VDP palette registers
167typedef uint16_t palette_t;
168
177#define RGB(r, g, b) \
178 ((palette_t)((((g) & 7) << 8) | (((r) & 7) << 4) | ((b) & 7)))
179
188void vdp_set_palette(uint8_t idx, const palette_t palette);
189
197void vdp_write_palette(const palette_t palettes[16]);
198
201// ---- VDP display setting
217 VDP_SCREEN_MODE_TEXT_1 = 1, // SCREEN 0: WIDTH 40
225 VDP_SCREEN_MODE_TEXT_2 = 5, // SCREEN 0: WIDTH 80
234};
235
246
261
316
324
330void vdp_set_visible(bool visible);
331
364
371
377void vdp_set_sprite_visible(bool visible);
378
406
416
432
442
458
479void vdp_set_adjust(int8_t x, int8_t y);
480
486void vdp_set_vscroll(uint8_t y);
487
493void vdp_set_hscroll(uint16_t x);
494
500void vdp_set_hscroll_mask(bool enable);
501
508
534 VDP_RGB = 0x00,
548 VDP_YJK = 0x08,
564};
565
581
584// ---- VDP COMMANDs
599inline bool vdp_cmd_is_running(void) {
600 return (vdp_get_status(2) & 1);
601}
602
608inline void vdp_cmd_await(void) {
609 while (vdp_cmd_is_running())
610 ;
611}
612
622void vdp_cmd_set_unrestricted(bool enable);
623
663 VDP_CMD_LRTB = (0 << 2),
664 VDP_CMD_RLTB = (1 << 2),
665 VDP_CMD_LRBT = (2 << 2),
666 VDP_CMD_RLBT = (3 << 2),
667};
668
672inline void vdp_cmd_stop(void) {
673 vdp_set_control(46, 0);
674}
675
683uint8_t vdp_cmd_execute_POINT(uint16_t sx, uint16_t sy);
684
693void vdp_cmd_execute_PSET(uint16_t dx, uint16_t dy,
694 uint8_t color,
695 enum vdp_cmd_logop logop);
696
710bool vdp_cmd_execute_SRCH(uint16_t * ret,
711 uint16_t sx, uint16_t sy,
712 uint8_t color,
713 uint8_t arg);
714
725void vdp_cmd_execute_LINE(uint16_t x1, uint16_t y1,
726 uint16_t x2, uint16_t y2,
727 uint8_t color,
728 enum vdp_cmd_logop logop);
729
730
740bool vdp_cmd_read(uint8_t * ret);
741
784void vdp_cmd_execute_LMCM(uint16_t x, uint16_t y,
785 uint16_t w, uint16_t h,
786 enum vdp_cmd_dir dir);
787
798bool vdp_cmd_write(const uint8_t val);
799
843void vdp_cmd_execute_LMMC(uint16_t x, uint16_t y,
844 uint16_t w, uint16_t h,
845 enum vdp_cmd_dir dir,
846 enum vdp_cmd_logop logop);
847
902void vdp_cmd_execute_HMMC(uint16_t x, uint16_t y,
903 uint16_t w, uint16_t h,
904 enum vdp_cmd_dir dir);
905
931void vdp_cmd_execute_LMMV(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
932 uint8_t color, enum vdp_cmd_logop logop);
933
962void vdp_cmd_execute_LMMM(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
963 uint16_t x2, uint16_t y2, enum vdp_cmd_logop logop);
964
996void vdp_cmd_execute_HMMV(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
997 uint8_t color);
998
1033void vdp_cmd_execute_HMMM(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
1034 uint16_t x2, uint16_t y2);
1035
1067void vdp_cmd_execute_YMMM(uint16_t x, uint16_t y, uint16_t h, uint16_t y2, uint8_t dir);
1068
1150
1156struct vdp_cmd {
1157 uint8_t r32;
1158 uint8_t r33;
1159 uint8_t r34;
1160 uint8_t r35;
1161 uint8_t r36;
1162 uint8_t r37;
1163 uint8_t r38;
1164 uint8_t r39;
1165 uint8_t r40;
1166 uint8_t r41;
1167 uint8_t r42;
1168 uint8_t r43;
1169 uint8_t r44;
1170 uint8_t r45;
1171 uint8_t r46;
1172};
1173
1182inline void vdp_cmd_set_SX(struct vdp_cmd * c, uint16_t sx) {
1183 c->r32 = (sx & 0xff);
1184 c->r33 = (sx >> 8) & 0x01;
1185}
1186
1195inline void vdp_cmd_set_SY(struct vdp_cmd * c, uint16_t sy) {
1196 c->r34 = (sy & 0xff);
1197 c->r35 = (sy >> 8) & 0x03;
1198}
1199
1208inline void vdp_cmd_set_DX(struct vdp_cmd * c, uint16_t dx) {
1209 c->r36 = (dx & 0xff);
1210 c->r37 = (dx >> 8) & 0x01;
1211}
1212
1221inline void vdp_cmd_set_DY(struct vdp_cmd * c, uint16_t dy) {
1222 c->r38 = (dy & 0xff);
1223 c->r39 = (dy >> 8) & 0x03;
1224}
1225
1234inline void vdp_cmd_set_NX(struct vdp_cmd * c, uint16_t nx) {
1235 c->r40 = (nx & 0xff);
1236 c->r41 = (nx >> 8) & 0x01;
1237}
1238
1247inline void vdp_cmd_set_NY(struct vdp_cmd * c, uint16_t ny) {
1248 c->r42 = (ny & 0xff);
1249 c->r43 = (ny >> 8) & 0x03;
1250}
1251
1260inline void vdp_cmd_set_CLR(struct vdp_cmd * c, uint8_t clr) {
1261 c->r44 = clr;
1262}
1263
1272inline void vdp_cmd_set_ARG(struct vdp_cmd * c, uint8_t arg) {
1273 c->r45 = arg;
1274}
1275
1284inline void vdp_cmd_set_logop(struct vdp_cmd * c, enum vdp_cmd_logop logop) {
1285 c->r46 = logop;
1286}
1287
1327void vdp_cmd_execute(const struct vdp_cmd * c, enum vdp_cmd_op opcode);
1328
1331#endif
C language I/F for MSX BIOS routines.
#define color(fg, bg, border)
MSX Set foreground, background, and border color.
Definition text.h:157
void vdp_set_color(uint8_t c)
MSX Set VDP color register.
void vdp_cmd_execute_LMMC(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enum vdp_cmd_dir dir, enum vdp_cmd_logop logop)
MSX2 Executes VDP command "LMMC" (CPU to VRAM logical transfer).
void vdp_cmd_execute_HMMV(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t color)
MSX2 Executes VDP command "HMMV" (fills rectangular area).
void vdp_cmd_execute_LINE(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t color, enum vdp_cmd_logop logop)
MSX2 Executes VDP command "LINE" (Draw line w/ logical operation).
void vdp_cmd_execute_HMMM(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t x2, uint16_t y2)
MSX2 Executes VDP command "HMMM" (copy rectangular area).
void vdp_cmd_execute_LMMV(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t color, enum vdp_cmd_logop logop)
MSX2 Executes VDP command "LMMV" (fills rectangular area w/ logical operation).
void vdp_cmd_execute_YMMM(uint16_t x, uint16_t y, uint16_t h, uint16_t y2, uint8_t dir)
MSX2 Executes VDP command "YMMM" (copy rectangular area from VRAM to VRAM vertically).
uint8_t vdp_cmd_execute_POINT(uint16_t sx, uint16_t sy)
MSX2 Executes VDP command "POINT" (Read color code at the given point).
bool vdp_cmd_read(uint8_t *ret)
MSX2 Reads a value from VDP.
vdp_cmd_dir
Enumeration of directions of rectangular operation for VDP commands.
Definition vdp.h:662
bool vdp_cmd_is_running(void)
MSX2 Tests if a VDP command is running.
Definition vdp.h:599
void vdp_cmd_execute_PSET(uint16_t dx, uint16_t dy, uint8_t color, enum vdp_cmd_logop logop)
MSX2 Executes VDP command "PSET" (Write color code at the given point).
bool vdp_cmd_execute_SRCH(uint16_t *ret, uint16_t sx, uint16_t sy, uint8_t color, uint8_t arg)
MSX2 Executes VDP command "SRCH" (Search color code from the given point towards left/right).
void vdp_cmd_execute_HMMC(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enum vdp_cmd_dir dir)
MSX2 Executes VDP command "HMMC" (CPU to VRAM high speed transfer).
void vdp_cmd_await(void)
MSX2 Wait for the VDP command to finish.
Definition vdp.h:608
bool vdp_cmd_write(const uint8_t val)
MSX2 Writes a value to VDP.
void vdp_cmd_execute_LMCM(uint16_t x, uint16_t y, uint16_t w, uint16_t h, enum vdp_cmd_dir dir)
MSX2 Executes VDP command "LMCM" (VRAM to CPU logical transfer).
vdp_cmd_logop
Enumeration of logical operation codes for VDP commands.
Definition vdp.h:629
void vdp_cmd_stop(void)
MSX2 Executes VDP command "STOP" (stop the running VDP command).
Definition vdp.h:672
void vdp_cmd_execute_LMMM(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t x2, uint16_t y2, enum vdp_cmd_logop logop)
MSX2 Executes VDP command "LMMM" (copy rectangular area w/ logical operation).
void vdp_cmd_set_unrestricted(bool enable)
MSX2+ Unristricts/Restricts availability of the VDP command for some screen modes.
@ VDP_CMD_LRTB
Left to Right, Top to Bottom.
Definition vdp.h:663
@ VDP_CMD_RLBT
Right to Left, Bottom to Top.
Definition vdp.h:666
@ VDP_CMD_LRBT
Left to Right, Bottom to Top.
Definition vdp.h:665
@ VDP_CMD_RLTB
Right to Left, Top to Bottom.
Definition vdp.h:664
@ VDP_CMD_OR
Logical operation code "OR" : destination ← destination | source.
Definition vdp.h:635
@ VDP_CMD_TNOT
Logical operation code "TNOT" : destination ← ~source , if source ≠ 0.
Definition vdp.h:653
@ VDP_CMD_EOR
Logical operation code "EOR" : destination ← destination ^ source.
Definition vdp.h:637
@ VDP_CMD_AND
Logical operation code "AND" : destination ← destination & source.
Definition vdp.h:633
@ VDP_CMD_XOR
(synonim for VDP_CMD_EOR)
Definition vdp.h:639
@ VDP_CMD_TEOR
Logical operation code "TEOR" : destination ← destination ^ source , if source ≠ 0.
Definition vdp.h:649
@ VDP_CMD_TXOR
(synonim for VDP_CMD_TEOR)
Definition vdp.h:651
@ VDP_CMD_IMP
Logical operation code "IMP" : destination ← source.
Definition vdp.h:631
@ VDP_CMD_TAND
Logical operation code "TAND" : destination ← destination & source , if source ≠ 0.
Definition vdp.h:645
@ VDP_CMD_NOT
Logical operation code "NOT" : destination ← ~source.
Definition vdp.h:641
@ VDP_CMD_TOR
Logical operation code "TOR" : destination ← destination | source , if source ≠ 0.
Definition vdp.h:647
@ VDP_CMD_TIMP
Logical operation code "TIMP" : destination ← source , if source ≠ 0.
Definition vdp.h:643
uint8_t r33
SX (hi)
Definition vdp.h:1158
uint8_t r44
CLR (2bpp * 4 pix, 4bpp * 2 pix, or 8bpp * 1 pix)
Definition vdp.h:1169
uint8_t r45
ARG (0000b | DIY | DIX | 00b)
Definition vdp.h:1170
uint8_t r35
SY (hi)
Definition vdp.h:1160
uint8_t r39
DY (hi)
Definition vdp.h:1164
uint8_t r40
NX (lo)
Definition vdp.h:1165
uint8_t r43
NY (hi)
Definition vdp.h:1168
uint8_t r38
DY (lo)
Definition vdp.h:1163
uint8_t r42
NY (lo)
Definition vdp.h:1167
uint8_t r37
DX (hi)
Definition vdp.h:1162
uint8_t r32
SX (lo)
Definition vdp.h:1157
uint8_t r36
DX (lo)
Definition vdp.h:1161
uint8_t r34
SY (lo)
Definition vdp.h:1159
uint8_t r46
CMR (op | logop)
Definition vdp.h:1171
uint8_t r41
NX (hi)
Definition vdp.h:1166
void vdp_cmd_set_SY(struct vdp_cmd *c, uint16_t sy)
MSX2 Set SY value (y-coordinate of the source point) for VDP commands.
Definition vdp.h:1195
void vdp_cmd_set_SX(struct vdp_cmd *c, uint16_t sx)
MSX2 Set SX value (x-coordinate of the source point) for VDP commands.
Definition vdp.h:1182
void vdp_cmd_set_DY(struct vdp_cmd *c, uint16_t dy)
MSX2 Set DY value (y-coordinate of the destination point) for VDP commands.
Definition vdp.h:1221
void vdp_cmd_set_DX(struct vdp_cmd *c, uint16_t dx)
MSX2 Set DX value (x-coordinate of the destination point) for VDP commands.
Definition vdp.h:1208
void vdp_cmd_set_ARG(struct vdp_cmd *c, uint8_t arg)
MSX2 Set ARG value (DIX, DIY, etc.) for VDP commands.
Definition vdp.h:1272
void vdp_cmd_execute(const struct vdp_cmd *c, enum vdp_cmd_op opcode)
MSX2 Executes a VDP command.
vdp_cmd_op
Enumeration of operation codes for VDP commands.
Definition vdp.h:1083
void vdp_cmd_set_NY(struct vdp_cmd *c, uint16_t ny)
MSX2 Set NY value (height) for VDP commands.
Definition vdp.h:1247
void vdp_cmd_set_logop(struct vdp_cmd *c, enum vdp_cmd_logop logop)
MSX2 Set a logical operation code for VDP commands.
Definition vdp.h:1284
void vdp_cmd_set_CLR(struct vdp_cmd *c, uint8_t clr)
MSX2 Set CLR value (color) for VDP commands.
Definition vdp.h:1260
void vdp_cmd_set_NX(struct vdp_cmd *c, uint16_t nx)
MSX2 Set NX value (width) for VDP commands.
Definition vdp.h:1234
@ VDP_CMD_LMCM
Operation code "LMCM" : VRAM to CPU logical transfer.
Definition vdp.h:1123
@ VDP_CMD_SRCH
Operation code "SRCH" : Search color code from the given point towards left/right.
Definition vdp.h:1103
@ VDP_CMD_LMMM
Operation code "LMMM" : Copy rectangular area from VRAM to VRAM w/ logical operation.
Definition vdp.h:1118
@ VDP_CMD_STOP
Operation code "STOP" : Stop the running VDP command.
Definition vdp.h:1088
@ VDP_CMD_HMMV
Operation code "HMMV" : Fill rectangular area.
Definition vdp.h:1133
@ VDP_CMD_YMMM
Operation code "YMMM" : Copy rectangular area from VRAM to VRAM vertically.
Definition vdp.h:1143
@ VDP_CMD_LINE
Operation code "LINE" : Draw line w/ logical operation.
Definition vdp.h:1108
@ VDP_CMD_LMMC
Operation code "LMMC" : CPU to VRAM logical transfer.
Definition vdp.h:1128
@ VDP_CMD_PSET
Operation code "PSET" : Write color code at the given point.
Definition vdp.h:1098
@ VDP_CMD_LMMV
Operation code "LMMV" : Fill rectangular area w/ logical operation.
Definition vdp.h:1113
@ VDP_CMD_POINT
Operation code "POINT" : Read color code at the given point.
Definition vdp.h:1093
@ VDP_CMD_HMMM
Operation code "HMMM" : Copy rectangular area from VRAM to VRAM.
Definition vdp.h:1138
@ VDP_CMD_HMMC
Operation code "HMMC" : CPU to VRAM high speed transfer.
Definition vdp.h:1148
Parameters for VDP commands.
Definition vdp.h:1156
void vdp_write_control(uint8_t reg, void *src, uint8_t len)
MSX2 Write to a series of VDP control registers.
void vdp_set_control(uint8_t reg, uint8_t x)
MSX Write to a VDP control register.
void vdp_set_hscroll(uint16_t x)
MSX2+ Set VDP horizontal display offset register.
void vdp_set_hscroll_mask(bool enable)
MSX2+ Enables/Disables the screen mask for the leftmost 8 pixels.
void vdp_set_vscroll(uint8_t y)
MSX2 Set VDP vertical display offset register.
void vdp_set_yjk_mode(enum vdp_yjk_mode yjk)
MSX2+ Set V9958 VDP's color space to RGB, YJK, or YJK/RGB.
void vdp_set_adjust(int8_t x, int8_t y)
MSX2 Set VDP display adjust register.
vdp_yjk_mode
MSX2+ Enumeration of V9958 VDP's color space.
Definition vdp.h:519
void vdp_set_hscroll_dual_page(bool enable)
MSX2+ Enable/disable horizontal scrolling for two pages.
@ VDP_YJK
YJK mode.
Definition vdp.h:548
@ VDP_RGB
Default color space of the V9958 (same as the V9938).
Definition vdp.h:534
@ VDP_YJK_RGB
YJK / RGB mixed mode.
Definition vdp.h:563
vdp_screen_lines
Enumeration of VDP screen lines.
Definition vdp.h:240
void vdp_set_visible(bool visible)
MSX Show / hide screen.
void vdp_set_screen_mode(enum vdp_screen_mode mode)
MSX Set VDP screen mode.
vdp_screen_mode
Enumeration of VDP screen modes.
Definition vdp.h:213
void vdp_set_sprite_visible(bool visible)
MSX2 Show / hide sprites.
uint8_t vdp_get_sprite_mode(void)
MSX Get current sprite mode.
void vdp_set_sprite_size(enum vdp_sprite_size size)
MSX Set sprite size.
vdp_sprite_size
Enumeration of VDP sprite size.
Definition vdp.h:251
void vdp_set_screen_lines(enum vdp_screen_lines lines)
MSX2 Set number of visible lines.
@ VDP_SCREEN_LINES_192
192 lines
Definition vdp.h:242
@ VDP_SCREEN_LINES_212
212 lines
Definition vdp.h:244
@ VDP_SCREEN_MODE_GRAPHIC_2
MSX GRAPHIC 2 (SCREEN 2)
Definition vdp.h:221
@ VDP_SCREEN_MODE_MULTI_COLOR
MSX MULTI COLOR (SCREEN 3)
Definition vdp.h:219
@ VDP_SCREEN_MODE_GRAPHIC_3
MSX2 GRAPHIC 3 (SCREEN 4)
Definition vdp.h:223
@ VDP_SCREEN_MODE_GRAPHIC_7
MSX2 GRAPHIC 7 (SCREEN 8)
Definition vdp.h:233
@ VDP_SCREEN_MODE_GRAPHIC_5
MSX2 GRAPHIC 5 (SCREEN 6)
Definition vdp.h:229
@ VDP_SCREEN_MODE_GRAPHIC_1
MSX GRAPHIC 1 (SCREEN 1)
Definition vdp.h:215
@ VDP_SCREEN_MODE_GRAPHIC_6
MSX2 GRAPHIC 6 (SCREEN 7)
Definition vdp.h:231
@ VDP_SCREEN_MODE_GRAPHIC_4
MSX2 GRAPHIC 4 (SCREEN 5)
Definition vdp.h:227
@ VDP_SCREEN_MODE_TEXT_1
MSX TEXT 1 (SCREEN 0, WIDTH 40)
Definition vdp.h:217
@ VDP_SCREEN_MODE_TEXT_2
MSX2 TEXT 2 (SCREEN 0, WIDTH 80)
Definition vdp.h:225
@ VDP_SPRITE_SIZE_16x16
16x16 pixels
Definition vdp.h:257
@ VDP_SPRITE_SIZE_16x16_MAGNIFIED
16x16 pixels, 2x magnification
Definition vdp.h:259
@ VDP_SPRITE_SIZE_8x8_MAGNIFIED
8x8 pixels, 2x magnification
Definition vdp.h:255
@ VDP_SPRITE_SIZE_8x8
8x8 pixels
Definition vdp.h:253
uint16_t palette_t
Type for RGB color palette value.
Definition vdp.h:167
void vdp_set_palette(uint8_t idx, const palette_t palette)
MSX2 Write to a VDP palette register.
void vdp_write_palette(const palette_t palettes[16])
MSX2 Write to a series of VDP palette registers.
uint8_t vdp_get_status(uint8_t reg)
MSX Read from a VDP status register.
void vdp_set_image_table(vmemptr_t table)
MSX Set VRAM address of the pattern name table.
void vdp_set_sprite_pattern_table(vmemptr_t table)
MSX Set VRAM address of the sprite pattern generator table.
void vdp_set_sprite_attribute_table(vmemptr_t table)
MSX Set VRAM address of the sprite attribute table.
void vdp_set_color_table(vmemptr_t table)
MSX Set VRAM address of the color table.
void vdp_set_pattern_table(vmemptr_t table)
MSX Set VRAM address of the pattern generator table.
uint32_t vmemptr_t
Type for VRAM address.
Definition vmem.h:43
Definition of I/O ports.
Unsafe primitive functions for VDP (Video Display Proccessor) access.
Data types and functions for VRAM access.
Definitions of MSX SYSTEM Workarea.