diff --git a/pc98.h b/pc98.h index e654a6df..1d6736c2 100644 --- a/pc98.h +++ b/pc98.h @@ -114,6 +114,11 @@ typedef int8_t uint4_t; #define SEG_PLANE_R 0xB000 #define SEG_PLANE_G 0xB800 #define SEG_PLANE_E 0xE000 + +// Segment distance between B↔R↔G +#define SEG_PLANE_DIST_BRG 0x800 +// Segment distance between G↔E +#define SEG_PLANE_DIST_E 0x2800 /// --------------- /// Keyboard diff --git a/pc98.inc b/pc98.inc index 9197d303..5fe69928 100644 --- a/pc98.inc +++ b/pc98.inc @@ -19,3 +19,10 @@ ROW_SIZE = (RES_X / 8) PLANE_SIZE = (ROW_SIZE * RES_Y) COLOR_COUNT = 16 ; ======== + +SEG_PLANE_B = 0A800h +SEG_PLANE_R = 0B000h +SEG_PLANE_G = 0B800h +SEG_PLANE_E = 0E000h +SEG_PLANE_DIST_BRG = 800h +SEG_PLANE_DIST_E = 2800h diff --git a/th03/formats/cdg.inc b/th03/formats/cdg.inc index 759fe397..9ddfcb7f 100644 --- a/th03/formats/cdg.inc +++ b/th03/formats/cdg.inc @@ -21,3 +21,25 @@ cdg_t struc seg_alpha dw ? seg_colors dw ? cdg_t ends + +vram_plane_next macro seg:req, label_loop:req + ; Next segment... + mov ax, seg + add ax, SEG_PLANE_DIST_BRG + mov seg, ax + + ; Still in the R or G segment? + cmp ax, (SEG_PLANE_G + SEG_PLANE_DIST_BRG) + jb short label_loop + + ; Already in the E segment? + cmp ax, (SEG_PLANE_G + (SEG_PLANE_DIST_BRG * 2)) + jnb short @@vram_plane_next_done + + ; Make the large jump between G and E + add ax, (SEG_PLANE_DIST_E - SEG_PLANE_DIST_BRG) + mov seg, ax + jmp short label_loop + +@@vram_plane_next_done: +endm diff --git a/th03/formats/cdg_put.asm b/th03/formats/cdg_put.asm index 116e6c8a..acf25af0 100644 --- a/th03/formats/cdg_put.asm +++ b/th03/formats/cdg_put.asm @@ -63,6 +63,7 @@ cdg_put proc far mov ds, ax assume ds:nothing +@@row_loop: @@width_2: mov cx, 1234h @@ -73,20 +74,9 @@ cdg_put proc far add di, 4 loop @@blit_dword sub di, dx - jns short @@width_2 + jns short @@row_loop mov di, bx - mov ax, es - add ax, 800h - mov es, ax - assume es:nothing - cmp ax, 0C000h - jb short @@width_2 - cmp ax, 0C800h - jnb short @@ret - add ax, 2000h - mov es, ax - assume es:nothing - jmp short @@width_2 + vram_plane_next es, @@row_loop @@ret: pop ds diff --git a/th03/formats/cdg_put_hflip.asm b/th03/formats/cdg_put_hflip.asm index 81bbe684..9e505aaa 100644 --- a/th03/formats/cdg_put_hflip.asm +++ b/th03/formats/cdg_put_hflip.asm @@ -75,6 +75,7 @@ proc_defconv cdg_put_hflip mov dx, 1234h nop +@@row_loop: @@width_bytes_colors: mov cx, 1234 @@ -86,22 +87,11 @@ proc_defconv cdg_put_hflip dec di loop @@blit_hflip_colors sub di, dx - jns short @@width_bytes_colors + jns short @@row_loop @@last_x_colors: mov di, 1234h - mov ax, es - add ax, 800h - mov es, ax - assume es:nothing - cmp ax, 0C000h - jb short @@width_bytes_colors - cmp ax, 0C800h - jnb short @@ret - add ax, 2000h - mov es, ax - assume es:nothing - jmp short @@width_bytes_colors + vram_plane_next es, @@row_loop @@ret: pop di diff --git a/th03/formats/cdg_put_noalpha.asm b/th03/formats/cdg_put_noalpha.asm index cda938b1..8ca5f7ea 100644 --- a/th03/formats/cdg_put_noalpha.asm +++ b/th03/formats/cdg_put_noalpha.asm @@ -40,24 +40,14 @@ cdg_put_noalpha proc far cld nop +@@row_loop: @@width: mov cx, 1234h rep movsd sub di, dx - jns short @@width + jns short @@row_loop mov di, bx - mov ax, es - add ax, 800h - mov es, ax - assume es:nothing - cmp ax, 0C000h - jb short @@width - cmp ax, 0C800h - jnb short @@ret - add ax, 2000h - mov es, ax - assume es:nothing - jmp short @@width + vram_plane_next es, @@row_loop @@ret: pop ds