vbeinfo

changeset 3:5b0ef094b8fd

backported changes from more recent VBE projects
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 07 Jan 2019 12:07:53 +0200
parents 193757920de9
children d2c44edd8b77
files Makefile src/dpmi.c src/dpmi.h src/vbe.c src/vbe.h
diffstat 5 files changed, 135 insertions(+), 34 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Wed Jul 26 21:08:55 2017 +0300
     1.2 +++ b/Makefile	Mon Jan 07 12:07:53 2019 +0200
     1.3 @@ -4,19 +4,24 @@
     1.4  #opt = -5 -fp5 -otexan
     1.5  dbg = -d1
     1.6  
     1.7 +!ifdef __UNIX__
     1.8 +RM = rm -f
     1.9 +!else
    1.10 +RM = del
    1.11 +!endif
    1.12 +
    1.13  CC = wcc386
    1.14 -CFLAGS = $(dbg) $(opt) -zq -bt=dos -Isrc\stl
    1.15 +CFLAGS = $(dbg) $(opt) -zq -bt=dos
    1.16  LD = wlink
    1.17  
    1.18  $(bin): $(obj)
    1.19 -	%write objects.lnk file { $(obj) }
    1.20 -	$(LD) debug all name $@ @objects $(LDFLAGS)
    1.21 +	$(LD) debug all name $@ system dos4g file { $(obj) } $(LDFLAGS)
    1.22  
    1.23  .c: src
    1.24  
    1.25  .c.obj: .autodepend
    1.26 -	$(CC) $(CFLAGS) $[*
    1.27 +	$(CC) -fo=$@ $(CFLAGS) $[*
    1.28  
    1.29  clean: .symbolic
    1.30 -	del *.obj
    1.31 -	del $(bin)
    1.32 +	$(RM) *.obj
    1.33 +	$(RM) $(bin)
     2.1 --- a/src/dpmi.c	Wed Jul 26 21:08:55 2017 +0300
     2.2 +++ b/src/dpmi.c	Mon Jan 07 12:07:53 2019 +0200
     2.3 @@ -1,3 +1,4 @@
     2.4 +#ifdef __WATCOMC__
     2.5  #include "dpmi.h"
     2.6  
     2.7  void dpmi_real_int(int inum, struct dpmi_real_regs *regs)
     2.8 @@ -53,3 +54,6 @@
     2.9  		int 0x31
    2.10  	}
    2.11  }
    2.12 +#else
    2.13 +int stop_gcc_crying_about_empty_translation_units = 0;
    2.14 +#endif	/* __WATCOM__ */
     3.1 --- a/src/dpmi.h	Wed Jul 26 21:08:55 2017 +0300
     3.2 +++ b/src/dpmi.h	Mon Jan 07 12:07:53 2019 +0200
     3.3 @@ -1,6 +1,10 @@
     3.4  #ifndef DPMI_H_
     3.5  #define DPMI_H_
     3.6  
     3.7 +#ifdef __DJGPP__
     3.8 +#include <dpmi.h>
     3.9 +#endif
    3.10 +
    3.11  #include "inttypes.h"
    3.12  
    3.13  struct dpmi_real_regs {
    3.14 @@ -12,13 +16,27 @@
    3.15  	uint16_t ip, cs, sp, ss;
    3.16  };
    3.17  
    3.18 -unsigned short dpmi_alloc(unsigned int par);
    3.19 +uint16_t dpmi_alloc(unsigned int par, uint16_t *sel);
    3.20 +void dpmi_free(uint16_t sel);
    3.21 +
    3.22 +#ifdef __WATCOMC__
    3.23  #pragma aux dpmi_alloc = \
    3.24  		"mov eax, 0x100" \
    3.25  		"int 0x31" \
    3.26 -		value[ax] parm[ebx];
    3.27 +		"mov [edi], dx" \
    3.28 +		value[ax] parm[ebx][edi];
    3.29 +
    3.30 +#pragma aux dpmi_free = \
    3.31 +		"mov eax, 0x101" \
    3.32 +		"int 0x31" \
    3.33 +		parm[dx];
    3.34  
    3.35  void dpmi_real_int(int inum, struct dpmi_real_regs *regs);
    3.36 +#endif	/* __WATCOMC__ */
    3.37 +
    3.38 +#ifdef __DJGPP__
    3.39 +#define dpmi_real_int(inum, regs) __dpmi_int((inum), (__dpmi_regs*)(regs))
    3.40 +#endif
    3.41  
    3.42  void *dpmi_mmap(uint32_t phys_addr, unsigned int size);
    3.43  void dpmi_munmap(void *addr);
     4.1 --- a/src/vbe.c	Wed Jul 26 21:08:55 2017 +0300
     4.2 +++ b/src/vbe.c	Mon Jan 07 12:07:53 2019 +0200
     4.3 @@ -1,7 +1,20 @@
     4.4  #include <stdio.h>
     4.5  #include <string.h>
     4.6 +#include <conio.h>
     4.7  #include "vbe.h"
     4.8  #include "dpmi.h"
     4.9 +#include "inttypes.h"
    4.10 +
    4.11 +#ifdef __DJGPP__
    4.12 +#include <pc.h>
    4.13 +#include <sys/nearptr.h>
    4.14 +
    4.15 +#define SEG_ADDR(s)	(((uint32_t)(s) << 4) - __djgpp_base_address)
    4.16 +
    4.17 +#define outp(p, v)	outportb(p, v)
    4.18 +#else
    4.19 +#define SEG_ADDR(s)	((uint32_t)(s) << 4)
    4.20 +#endif
    4.21  
    4.22  /* VGA DAC registers used for palette setting in 8bpp modes */
    4.23  #define VGA_DAC_STATE		0x3c7
    4.24 @@ -14,14 +27,14 @@
    4.25  
    4.26  struct vbe_info *vbe_get_info(void)
    4.27  {
    4.28 -	static unsigned short info_block_seg;
    4.29 +	static uint16_t info_block_seg, info_block_selector;
    4.30  	static struct vbe_info *info;
    4.31  	struct dpmi_real_regs regs;
    4.32  
    4.33  	if(!info) {
    4.34  		/* allocate 32 paragraphs (512 bytes) */
    4.35 -		info_block_seg = dpmi_alloc(32);
    4.36 -		info = (struct vbe_info*)(info_block_seg << 4);
    4.37 +		info_block_seg = dpmi_alloc(32, &info_block_selector);
    4.38 +		info = (struct vbe_info*)SEG_ADDR(info_block_seg);
    4.39  	}
    4.40  
    4.41  	memcpy(info->sig, "VBE2", 4);
    4.42 @@ -37,14 +50,14 @@
    4.43  
    4.44  struct vbe_mode_info *vbe_get_mode_info(int mode)
    4.45  {
    4.46 -	static unsigned short mode_info_seg;
    4.47 +	static uint16_t mode_info_seg, mode_info_selector;
    4.48  	static struct vbe_mode_info *mi;
    4.49  	struct dpmi_real_regs regs;
    4.50  
    4.51  	if(!mi) {
    4.52  		/* allocate 16 paragraphs (256 bytes) */
    4.53 -		mode_info_seg = dpmi_alloc(16);
    4.54 -		mi = (struct vbe_mode_info*)(mode_info_seg << 4);
    4.55 +		mode_info_seg = dpmi_alloc(16, &mode_info_selector);
    4.56 +		mi = (struct vbe_mode_info*)SEG_ADDR(mode_info_seg);
    4.57  	}
    4.58  
    4.59  	memset(&regs, 0, sizeof regs);
    4.60 @@ -85,7 +98,7 @@
    4.61  	regs.ebx = bits << 8;	/* bits in bh */
    4.62  	dpmi_real_int(0x10, &regs);
    4.63  
    4.64 -	if((regs.eax >> 8) & 0xff == 3) {
    4.65 +	if(((regs.eax >> 8) & 0xff) == 3) {
    4.66  		return -1;
    4.67  	}
    4.68  	return regs.ebx >> 8 & 0xff;	/* new color bits in bh */
    4.69 @@ -98,11 +111,7 @@
    4.70  {
    4.71  	int i, shift = 8 - bits;
    4.72  
    4.73 -	__asm {
    4.74 -		mov dx, VGA_DAC_ADDR_WR
    4.75 -		mov eax, idx
    4.76 -		out dx, al
    4.77 -	}
    4.78 +	outp(VGA_DAC_ADDR_WR, idx);
    4.79  
    4.80  	for(i=0; i<count; i++) {
    4.81  		unsigned char r = *col++;
    4.82 @@ -115,18 +124,68 @@
    4.83  			b >>= shift;
    4.84  		}
    4.85  
    4.86 -		__asm {
    4.87 -			mov dx, VGA_DAC_DATA
    4.88 -			mov al, r
    4.89 -			out dx, al
    4.90 -			mov al, g
    4.91 -			out dx, al
    4.92 -			mov al, b
    4.93 -			out dx, al
    4.94 -		}
    4.95 +		outp(VGA_DAC_DATA, r);
    4.96 +		outp(VGA_DAC_DATA, g);
    4.97 +		outp(VGA_DAC_DATA, b);
    4.98  	}
    4.99  }
   4.100  
   4.101 +int vbe_set_disp_start(int x, int y, int when)
   4.102 +{
   4.103 +	struct dpmi_real_regs regs;
   4.104 +
   4.105 +	memset(&regs, 0, sizeof regs);
   4.106 +	regs.eax = 0x4f07;
   4.107 +	regs.ebx = when & 0xffff;
   4.108 +	regs.ecx = x & 0xffff;
   4.109 +	regs.edx = y & 0xffff;
   4.110 +	dpmi_real_int(0x10, &regs);
   4.111 +
   4.112 +	if(regs.eax == 0x100) {
   4.113 +		return -1;
   4.114 +	}
   4.115 +	return 0;
   4.116 +}
   4.117 +
   4.118 +int vbe_set_scanlen(int len, int mode)
   4.119 +{
   4.120 +	struct dpmi_real_regs regs;
   4.121 +
   4.122 +	memset(&regs, 0, sizeof regs);
   4.123 +	regs.eax = 0x4f06;
   4.124 +	regs.ebx = mode;
   4.125 +	regs.ecx = len & 0xffff;
   4.126 +	dpmi_real_int(0x10, &regs);
   4.127 +
   4.128 +	if(regs.eax == 0x100) {
   4.129 +		return -1;
   4.130 +	}
   4.131 +	return regs.ecx & 0xffff;
   4.132 +}
   4.133 +
   4.134 +int vbe_get_scanlen(int mode)
   4.135 +{
   4.136 +	int res;
   4.137 +	struct dpmi_real_regs regs;
   4.138 +
   4.139 +	memset(&regs, 0, sizeof regs);
   4.140 +	regs.eax = 0x4f06;
   4.141 +	regs.ebx = 1;
   4.142 +	dpmi_real_int(0x10, &regs);
   4.143 +
   4.144 +	if(regs.eax == 0x100) {
   4.145 +		return -1;
   4.146 +	}
   4.147 +
   4.148 +	if(mode == VBE_SCANLEN_PIXELS) {
   4.149 +		res = regs.ecx & 0xffff;
   4.150 +	} else {
   4.151 +		res = regs.ebx & 0xffff;
   4.152 +	}
   4.153 +	return res;
   4.154 +}
   4.155 +
   4.156 +
   4.157  static unsigned int get_mask(int sz, int pos)
   4.158  {
   4.159  	unsigned int i, mask = 0;
   4.160 @@ -149,5 +208,5 @@
   4.161  	fprintf(fp, "red bits: %d (mask: %x)\n", (int)mi->rmask_size, get_mask(mi->rmask_size, mi->rpos));
   4.162  	fprintf(fp, "green bits: %d (mask: %x)\n", (int)mi->gmask_size, get_mask(mi->gmask_size, mi->gpos));
   4.163  	fprintf(fp, "blue bits: %d (mask: %x)\n", (int)mi->bmask_size, get_mask(mi->bmask_size, mi->bpos));
   4.164 -	fprintf(fp, "framebuffer address: %x\n", mi->fb_addr);
   4.165 +	fprintf(fp, "framebuffer address: %x\n", (unsigned int)mi->fb_addr);
   4.166  }
     5.1 --- a/src/vbe.h	Wed Jul 26 21:08:55 2017 +0300
     5.2 +++ b/src/vbe.h	Mon Jan 07 12:07:53 2019 +0200
     5.3 @@ -3,6 +3,12 @@
     5.4  
     5.5  #include "inttypes.h"
     5.6  
     5.7 +#ifdef __GNUC__
     5.8 +#define PACKED	__attribute__((packed))
     5.9 +#else
    5.10 +#define PACKED
    5.11 +#endif
    5.12 +
    5.13  #define VBE_ATTR_LFB	(1 << 7)
    5.14  #define VBE_MODE_LFB	(1 << 14)
    5.15  
    5.16 @@ -20,7 +26,7 @@
    5.17  	uint32_t oem_product_rev_ptr;
    5.18  	uint8_t reserved[222];
    5.19  	uint8_t oem_data[256];
    5.20 -};
    5.21 +} PACKED;
    5.22  
    5.23  struct vbe_mode_info {
    5.24  	uint16_t mode_attr;
    5.25 @@ -54,17 +60,26 @@
    5.26  	uint16_t reserved3;
    5.27  
    5.28  	uint8_t reserved4[206];
    5.29 -};
    5.30 +} PACKED;
    5.31  #pragma pack (pop)
    5.32  
    5.33  struct vbe_info *vbe_get_info(void);
    5.34 -struct vbe_mode_info *vbe_get_mode_info(unsigned int mode);
    5.35 +struct vbe_mode_info *vbe_get_mode_info(int mode);
    5.36  
    5.37 -int vbe_set_mode(unsigned int mode);
    5.38 +int vbe_set_mode(int mode);
    5.39  
    5.40  int vbe_set_palette_bits(int bits);
    5.41  void vbe_set_palette(int idx, int *col, int count, int bits);
    5.42  
    5.43 +#define VBE_SET_DISP_START_NOW		0
    5.44 +#define VBE_SET_DISP_START_VBLANK	0x80
    5.45 +int vbe_set_disp_start(int x, int y, int when);
    5.46 +
    5.47 +#define VBE_SCANLEN_PIXELS	0
    5.48 +#define VBE_SCANLEN_BYTES	2
    5.49 +int vbe_set_scanlen(int len, int mode);
    5.50 +int vbe_get_scanlen(int mode);
    5.51 +
    5.52  void print_mode_info(FILE *fp, struct vbe_mode_info *modei);
    5.53  
    5.54  #endif	/* VBE_H_ */