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-2024 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 */
21#pragma once
22
23#ifndef VDP_H
24#define VDP_H
25
26#include <assert.h>
27#include <stdbool.h>
28#include <stdint.h>
29
30#include "io.h"
31#include "vmem.h"
32#include "vdp_unsafe.h"
33
34#include "bios.h"
35#include "workarea.h"
36
37// ---- VDP status register
65uint8_t vdp_get_status(uint8_t reg);
66
69// ---- VDP control registers
83void vdp_set_control(uint8_t reg, uint8_t x);
84
92void vdp_write_control(uint8_t reg, void* src, uint8_t len);
93
96// ---- VDP color register
149void vdp_set_color(uint8_t c); // set color register R#7
150
153// ---- VDP palette registers
166typedef uint16_t palette_t;
167
176#define RGB(r, g, b) \
177 ((palette_t)((((g) & 7) << 8) | (((r) & 7) << 4) | ((b) & 7)))
178
187void vdp_set_palette(uint8_t idx, const palette_t palette);
188
196void vdp_write_palette(const palette_t palettes[16]);
197
200// ---- VDP display setting
216 VDP_SCREEN_MODE_TEXT_1 = 1, // SCREEN 0: WIDTH 40
224 VDP_SCREEN_MODE_TEXT_2 = 5, // SCREEN 0: WIDTH 80
233};
234
245
260
315
323
329void vdp_set_visible(bool visible);
330
363
370
376void vdp_set_sprite_visible(bool visible);
377
405
415
431
441
457
478void vdp_set_adjust(int8_t x, int8_t y);
479
485void vdp_set_vscroll(uint8_t y);
486
492void vdp_set_hscroll(uint16_t x);
493
499void vdp_set_hscroll_mask(bool enable);
500
507
533 VDP_RGB = 0x00,
547 VDP_YJK = 0x08,
563};
564
580
583// ---- VDP COMMANDs
598inline bool vdp_cmd_is_running(void) {
599 return (vdp_get_status(2) & 1);
600}
601
607inline void vdp_cmd_await(void) {
608 while (vdp_cmd_is_running())
609 ;
610}
611
621void vdp_cmd_set_unrestricted(bool enable);
622
662 VDP_CMD_LRTB = (0 << 2),
663 VDP_CMD_RLTB = (1 << 2),
664 VDP_CMD_LRBT = (2 << 2),
665 VDP_CMD_RLBT = (3 << 2),
666};
667
671inline void vdp_cmd_stop(void) {
672 vdp_set_control(46, 0);
673}
674
682uint8_t vdp_cmd_execute_POINT(uint16_t sx, uint16_t sy);
683
692void vdp_cmd_execute_PSET(uint16_t dx, uint16_t dy,
693 uint8_t color,
694 enum vdp_cmd_logop logop);
695
709bool vdp_cmd_execute_SRCH(uint16_t * ret,
710 uint16_t sx, uint16_t sy,
711 uint8_t color,
712 uint8_t arg);
713
724void vdp_cmd_execute_LINE(uint16_t x1, uint16_t y1,
725 uint16_t x2, uint16_t y2,
726 uint8_t color,
727 enum vdp_cmd_logop logop);
728
729
739bool vdp_cmd_read(uint8_t * ret);
740
783void vdp_cmd_execute_LMCM(uint16_t x, uint16_t y,
784 uint16_t w, uint16_t h,
785 enum vdp_cmd_dir dir);
786
797bool vdp_cmd_write(const uint8_t val);
798
842void vdp_cmd_execute_LMMC(uint16_t x, uint16_t y,
843 uint16_t w, uint16_t h,
844 enum vdp_cmd_dir dir,
845 enum vdp_cmd_logop logop);
846
901void vdp_cmd_execute_HMMC(uint16_t x, uint16_t y,
902 uint16_t w, uint16_t h,
903 enum vdp_cmd_dir dir);
904
930void vdp_cmd_execute_LMMV(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
931 uint8_t color, enum vdp_cmd_logop logop);
932
961void vdp_cmd_execute_LMMM(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
962 uint16_t x2, uint16_t y2, enum vdp_cmd_logop logop);
963
995void vdp_cmd_execute_HMMV(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
996 uint8_t color);
997
1032void vdp_cmd_execute_HMMM(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
1033 uint16_t x2, uint16_t y2);
1034
1066void vdp_cmd_execute_YMMM(uint16_t x, uint16_t y, uint16_t h, uint16_t y2, uint8_t dir);
1067
1149
1155struct vdp_cmd {
1156 uint8_t r32;
1157 uint8_t r33;
1158 uint8_t r34;
1159 uint8_t r35;
1160 uint8_t r36;
1161 uint8_t r37;
1162 uint8_t r38;
1163 uint8_t r39;
1164 uint8_t r40;
1165 uint8_t r41;
1166 uint8_t r42;
1167 uint8_t r43;
1168 uint8_t r44;
1169 uint8_t r45;
1170 uint8_t r46;
1171};
1172
1181inline void vdp_cmd_set_SX(struct vdp_cmd * c, uint16_t sx) {
1182 c->r32 = (sx & 0xff);
1183 c->r33 = (sx >> 8) & 0x01;
1184}
1185
1194inline void vdp_cmd_set_SY(struct vdp_cmd * c, uint16_t sy) {
1195 c->r34 = (sy & 0xff);
1196 c->r35 = (sy >> 8) & 0x03;
1197}
1198
1207inline void vdp_cmd_set_DX(struct vdp_cmd * c, uint16_t dx) {
1208 c->r36 = (dx & 0xff);
1209 c->r37 = (dx >> 8) & 0x01;
1210}
1211
1220inline void vdp_cmd_set_DY(struct vdp_cmd * c, uint16_t dy) {
1221 c->r38 = (dy & 0xff);
1222 c->r39 = (dy >> 8) & 0x03;
1223}
1224
1233inline void vdp_cmd_set_NX(struct vdp_cmd * c, uint16_t nx) {
1234 c->r40 = (nx & 0xff);
1235 c->r41 = (nx >> 8) & 0x01;
1236}
1237
1246inline void vdp_cmd_set_NY(struct vdp_cmd * c, uint16_t ny) {
1247 c->r42 = (ny & 0xff);
1248 c->r43 = (ny >> 8) & 0x03;
1249}
1250
1259inline void vdp_cmd_set_CLR(struct vdp_cmd * c, uint8_t clr) {
1260 c->r44 = clr;
1261}
1262
1271inline void vdp_cmd_set_ARG(struct vdp_cmd * c, uint8_t arg) {
1272 c->r45 = arg;
1273}
1274
1283inline void vdp_cmd_set_logop(struct vdp_cmd * c, enum vdp_cmd_logop logop) {
1284 c->r46 = logop;
1285}
1286
1326void vdp_cmd_execute(const struct vdp_cmd * c, enum vdp_cmd_op opcode);
1327
1330#endif
C language I/F for MSX BIOS routines.
#define color(fg, bg, border)
MSX Set foreground, background, and border color.
Definition text.h:156
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:661
bool vdp_cmd_is_running(void)
MSX2 Tests if a VDP command is running.
Definition vdp.h:598
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:607
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:628
void vdp_cmd_stop(void)
MSX2 Executes VDP command "STOP" (stop the running VDP command).
Definition vdp.h:671
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:662
@ VDP_CMD_RLBT
Right to Left, Bottom to Top.
Definition vdp.h:665
@ VDP_CMD_LRBT
Left to Right, Bottom to Top.
Definition vdp.h:664
@ VDP_CMD_RLTB
Right to Left, Top to Bottom.
Definition vdp.h:663
@ VDP_CMD_OR
Logical operation code "OR" : destination ← destination | source.
Definition vdp.h:634
@ VDP_CMD_TNOT
Logical operation code "TNOT" : destination ← ~source , if source ≠ 0.
Definition vdp.h:652
@ VDP_CMD_EOR
Logical operation code "EOR" : destination ← destination ^ source.
Definition vdp.h:636
@ VDP_CMD_AND
Logical operation code "AND" : destination ← destination & source.
Definition vdp.h:632
@ VDP_CMD_XOR
(synonim for VDP_CMD_EOR)
Definition vdp.h:638
@ VDP_CMD_TEOR
Logical operation code "TEOR" : destination ← destination ^ source , if source ≠ 0.
Definition vdp.h:648
@ VDP_CMD_TXOR
(synonim for VDP_CMD_TEOR)
Definition vdp.h:650
@ VDP_CMD_IMP
Logical operation code "IMP" : destination ← source.
Definition vdp.h:630
@ VDP_CMD_TAND
Logical operation code "TAND" : destination ← destination & source , if source ≠ 0.
Definition vdp.h:644
@ VDP_CMD_NOT
Logical operation code "NOT" : destination ← ~source.
Definition vdp.h:640
@ VDP_CMD_TOR
Logical operation code "TOR" : destination ← destination | source , if source ≠ 0.
Definition vdp.h:646
@ VDP_CMD_TIMP
Logical operation code "TIMP" : destination ← source , if source ≠ 0.
Definition vdp.h:642
uint8_t r33
SX (hi)
Definition vdp.h:1157
uint8_t r44
CLR (2bpp * 4 pix, 4bpp * 2 pix, or 8bpp * 1 pix)
Definition vdp.h:1168
uint8_t r45
ARG (0000b | DIY | DIX | 00b)
Definition vdp.h:1169
uint8_t r35
SY (hi)
Definition vdp.h:1159
uint8_t r39
DY (hi)
Definition vdp.h:1163
uint8_t r40
NX (lo)
Definition vdp.h:1164
uint8_t r43
NY (hi)
Definition vdp.h:1167
uint8_t r38
DY (lo)
Definition vdp.h:1162
uint8_t r42
NY (lo)
Definition vdp.h:1166
uint8_t r37
DX (hi)
Definition vdp.h:1161
uint8_t r32
SX (lo)
Definition vdp.h:1156
uint8_t r36
DX (lo)
Definition vdp.h:1160
uint8_t r34
SY (lo)
Definition vdp.h:1158
uint8_t r46
CMR (op | logop)
Definition vdp.h:1170
uint8_t r41
NX (hi)
Definition vdp.h:1165
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:1194
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:1181
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:1220
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:1207
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:1271
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:1082
void vdp_cmd_set_NY(struct vdp_cmd *c, uint16_t ny)
MSX2 Set NY value (height) for VDP commands.
Definition vdp.h:1246
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:1283
void vdp_cmd_set_CLR(struct vdp_cmd *c, uint8_t clr)
MSX2 Set CLR value (color) for VDP commands.
Definition vdp.h:1259
void vdp_cmd_set_NX(struct vdp_cmd *c, uint16_t nx)
MSX2 Set NX value (width) for VDP commands.
Definition vdp.h:1233
@ VDP_CMD_LMCM
Operation code "LMCM" : VRAM to CPU logical transfer.
Definition vdp.h:1122
@ VDP_CMD_SRCH
Operation code "SRCH" : Search color code from the given point towards left/right.
Definition vdp.h:1102
@ VDP_CMD_LMMM
Operation code "LMMM" : Copy rectangular area from VRAM to VRAM w/ logical operation.
Definition vdp.h:1117
@ VDP_CMD_STOP
Operation code "STOP" : Stop the running VDP command.
Definition vdp.h:1087
@ VDP_CMD_HMMV
Operation code "HMMV" : Fill rectangular area.
Definition vdp.h:1132
@ VDP_CMD_YMMM
Operation code "YMMM" : Copy rectangular area from VRAM to VRAM vertically.
Definition vdp.h:1142
@ VDP_CMD_LINE
Operation code "LINE" : Draw line w/ logical operation.
Definition vdp.h:1107
@ VDP_CMD_LMMC
Operation code "LMMC" : CPU to VRAM logical transfer.
Definition vdp.h:1127
@ VDP_CMD_PSET
Operation code "PSET" : Write color code at the given point.
Definition vdp.h:1097
@ VDP_CMD_LMMV
Operation code "LMMV" : Fill rectangular area w/ logical operation.
Definition vdp.h:1112
@ VDP_CMD_POINT
Operation code "POINT" : Read color code at the given point.
Definition vdp.h:1092
@ VDP_CMD_HMMM
Operation code "HMMM" : Copy rectangular area from VRAM to VRAM.
Definition vdp.h:1137
@ VDP_CMD_HMMC
Operation code "HMMC" : CPU to VRAM high speed transfer.
Definition vdp.h:1147
Parameters for VDP commands.
Definition vdp.h:1155
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:518
void vdp_set_hscroll_dual_page(bool enable)
MSX2+ Enable/disable horizontal scrolling for two pages.
@ VDP_YJK
YJK mode.
Definition vdp.h:547
@ VDP_RGB
Default color space of the V9958 (same as the V9938).
Definition vdp.h:533
@ VDP_YJK_RGB
YJK / RGB mixed mode.
Definition vdp.h:562
vdp_screen_lines
Enumeration of VDP screen lines.
Definition vdp.h:239
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:212
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:250
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:241
@ VDP_SCREEN_LINES_212
212 lines
Definition vdp.h:243
@ VDP_SCREEN_MODE_GRAPHIC_2
MSX GRAPHIC 2 (SCREEN 2)
Definition vdp.h:220
@ VDP_SCREEN_MODE_MULTI_COLOR
MSX MULTI COLOR (SCREEN 3)
Definition vdp.h:218
@ VDP_SCREEN_MODE_GRAPHIC_3
MSX2 GRAPHIC 3 (SCREEN 4)
Definition vdp.h:222
@ VDP_SCREEN_MODE_GRAPHIC_7
MSX2 GRAPHIC 7 (SCREEN 8)
Definition vdp.h:232
@ VDP_SCREEN_MODE_GRAPHIC_5
MSX2 GRAPHIC 5 (SCREEN 6)
Definition vdp.h:228
@ VDP_SCREEN_MODE_GRAPHIC_1
MSX GRAPHIC 1 (SCREEN 1)
Definition vdp.h:214
@ VDP_SCREEN_MODE_GRAPHIC_6
MSX2 GRAPHIC 6 (SCREEN 7)
Definition vdp.h:230
@ VDP_SCREEN_MODE_GRAPHIC_4
MSX2 GRAPHIC 4 (SCREEN 5)
Definition vdp.h:226
@ VDP_SCREEN_MODE_TEXT_1
MSX TEXT 1 (SCREEN 0, WIDTH 40)
Definition vdp.h:216
@ VDP_SCREEN_MODE_TEXT_2
MSX2 TEXT 2 (SCREEN 0, WIDTH 80)
Definition vdp.h:224
@ VDP_SPRITE_SIZE_16x16
16x16 pixels
Definition vdp.h:256
@ VDP_SPRITE_SIZE_16x16_MAGNIFIED
16x16 pixels, 2x magnification
Definition vdp.h:258
@ VDP_SPRITE_SIZE_8x8_MAGNIFIED
8x8 pixels, 2x magnification
Definition vdp.h:254
@ VDP_SPRITE_SIZE_8x8
8x8 pixels
Definition vdp.h:252
uint16_t palette_t
Type for RGB color palette value.
Definition vdp.h:166
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:42
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.