#include <stdio.h>
#include <i86.h>
#include "cdpmi.h"
+#include "logger.h"
#define LOWBUF_SIZE 8192
#define RMSTACK_SIZE 4096
int dpmi_init(void)
{
if(!(lowbuf_seg = dpmi_alloc(LOWBUF_SIZE >> 4, &lowbuf_sel))) {
- fprintf(stderr, "DPMI init failed to allocate low memory buffer\n");
+ errormsg("DPMI init failed to allocate low memory buffer\n");
return -1;
}
lowbuf = (char*)((intptr_t)lowbuf_seg << 4);
-
#include <conio.h>
#include <i86.h>
#include "drv.h"
+#include "logger.h"
void vid_register_s3(void)
{
#include "vbe.h"
#include "vga.h"
#include "cdpmi.h"
+#include "logger.h"
#define farptr_to_linear(rmaddr) \
((((intptr_t)(rmaddr) >> 12) & 0xffff0) + ((intptr_t)(rmaddr) & 0xffff))
regs.es = bufseg;
dpmi_rmint(0x10, ®s);
if((regs.eax & 0xffff) != 0x4f || memcmp(vbe->sig, "VESA", 4) != 0) {
- fprintf(stderr, "failed to get VBE controller information\n");
+ errormsg("failed to get VBE controller information\n");
return -1;
}
vbe_ver = vbe->ver;
- printf("Found VBE %d.%d\n", VBE_VER_MAJOR(vbe_ver), VBE_VER_MINOR(vbe_ver));
- printf("OEM: %s\n", (char*)farptr_to_linear(vbe->oem_name));
+ infomsg("Found VBE %d.%d\n", VBE_VER_MAJOR(vbe_ver), VBE_VER_MINOR(vbe_ver));
+ infomsg("OEM: %s\n", (char*)farptr_to_linear(vbe->oem_name));
if(vbe_ver >= 0x0200) {
- printf("%s - %s (%s)\n", (char*)farptr_to_linear(vbe->vendor),
+ infomsg("%s - %s (%s)\n", (char*)farptr_to_linear(vbe->vendor),
(char*)farptr_to_linear(vbe->product),
(char*)farptr_to_linear(vbe->revstr));
}
- printf("Video RAM: %s\n", memsize_str((long)vbe->vmem_blk * 65536));
+ infomsg("Video RAM: %s\n", memsize_str((long)vbe->vmem_blk * 65536));
vbe_modelist = (uint16_t*)farptr_to_linear(vbe->modelist_addr);
count = 0;
}
if(!(modelist = malloc(count * sizeof *modelist))) {
- fprintf(stderr, "failed to allocate mode list\n");
+ errormsg("failed to allocate mode list\n");
return -1;
}
for(i=0; i<count; i++) {
}
if(!(drv.modes = malloc(count * sizeof *drv.modes))) {
- fprintf(stderr, "failed to allocate mode list\n");
+ errormsg("failed to allocate mode list\n");
free(modelist);
return -1;
}
static void blitfb_banked(void *fb, int pitch)
{
- int sz, offs, pending;
+ int sz, offs, pending, winsz;
unsigned char *pptr = fb;
+ winsz = cur_mi->win_size << 10;
+
/* assume initial window offset at 0 */
offs = 0;
pending = cur_pgsize;
while(pending > 0) {
- sz = pending > 65536 ? 65536 : pending;
+ sz = pending > winsz ? winsz : pending;
memcpy((void*)0xa0000, pptr, sz);
pptr += sz;
pending -= sz;
#include "vidsys.h"
#include "drv.h"
#include "vga.h"
+#include "logger.h"
static int init(void);
static void cleanup(void);
void kb_init(void)
{
if(DONE_INIT) {
- fprintf(stderr, "keyboard driver already initialized!\n");
+ errormsg("keyboard driver already initialized!\n");
return;
}
return 1;
}
- add_log_file("retroray.log");
+ /*add_log_file("retroray.log");*/
if(vid_init() == -1) {
return 1;
void app_swap_buffers(void)
{
- vid_blitfb(framebuf, opt.vsync);
+ if(opt.vsync) {
+ vid_vsync();
+ }
+ vid_blitfb32(framebuf, 0);
}
void app_quit(void)
#include <stdio.h>
#include <stdlib.h>
+#include <limits.h>
#include <assert.h>
#include "vidsys.h"
#include "vga.h"
#include "drv.h"
#include "cdpmi.h"
+#include "logger.h"
struct vid_driver *vid_drvlist[MAX_DRV];
int vid_numdrv;
int newsz = max_modes ? max_modes * 2 : 128;
void *tmp = realloc(modes, newsz * sizeof *modes);
if(!tmp) {
- fprintf(stderr, "failed to allocate modes list\n");
+ errormsg("failed to allocate modes list\n");
return -1;
}
modes = tmp;
}
}
- printf("found %d modes:\n", num_modes);
+ infomsg("found %d modes:\n", num_modes);
for(i=0; i<num_modes; i+=2) {
vm = modes[i];
- len = printf("[%4s] %04x: %dx%d %dbpp", vm->drv->name, vm->modeno,
+ len = infomsg("[%4s] %04x: %dx%d %dbpp", vm->drv->name, vm->modeno,
vm->width, vm->height, vm->bpp);
if(i + 1 >= num_modes) {
- putchar('\n');
+ infomsg("\n");
break;
}
- for(j=len; j<40; j++) putchar(' ');
+ for(j=len; j<40; j++) infomsg(" ");
vm = modes[i + 1];
- printf("[%4s] %04x: %dx%d %dbpp\n", vm->drv->name, vm->modeno,
+ infomsg("[%4s] %04x: %dx%d %dbpp\n", vm->drv->name, vm->modeno,
vm->width, vm->height, vm->bpp);
}
cur_mode->ops.getpal(idx, count, col);
}
-void vid_blitfb(void *fb, int vsync)
+void vid_blitfb(void *fb, int pitch)
{
- cur_mode->ops.blitfb(fb, vsync);
+ if(pitch <= 0) {
+ pitch = cur_mode->pitch;
+ }
+ cur_mode->ops.blitfb(fb, pitch);
+}
+
+void vid_blitfb32(uint32_t *src, int pitch)
+{
+ int i, j, winpos, winleft;
+ unsigned char *dest;
+ uint16_t *dest16;
+
+ if(cur_mode->bpp == 32) {
+ vid_blitfb(src, pitch);
+ return;
+ }
+
+ if(pitch <= 0) {
+ pitch = cur_mode->width << 2;
+ }
+
+ if(vid_islinear()) {
+ winleft = INT_MAX;
+ } else {
+ winleft = 65536;/*cur_mode->win_size << 10;*/
+ winpos = 0;
+ vid_setwin(0, 0);
+ }
+
+ switch(cur_mode->bpp) {
+ case 8:
+ /* TODO */
+ break;
+
+ case 15:
+ /* TODO */
+ break;
+ case 16:
+ /* TODO */
+ break;
+
+ case 24:
+ dest = vid_vmem;
+ for(i=0; i<cur_mode->height; i++) {
+ for(j=0; j<cur_mode->width; j++) {
+ uint32_t pixel = src[j];
+ if(winleft <= 0) {
+ winpos += cur_mode->win_step;
+ vid_setwin(0, winpos);
+ winleft = 65536;/*cur_mode->win_size << 10;*/
+ dest = vid_vmem;
+ }
+ dest[0] = (pixel >> 16) & 0xff;
+ dest[1] = (pixel >> 8) & 0xff;
+ dest[2] = pixel & 0xff;
+ dest += 3;
+ winleft -= 3;
+ }
+ src = (uint32_t*)((char*)src + pitch);
+ }
+ break;
+
+ default:
+ break;
+ }
}
void vid_setpal(int idx, int count, const struct vid_color *col);
void vid_getpal(int idx, int count, struct vid_color *col);
-void vid_blitfb(void *fb, int vsync);
+void vid_blitfb(void *fb, int pitch);
+void vid_blitfb32(uint32_t *fb, int pitch);
#endif /* VIDSYS_VIDEO_H_ */
#endif
#endif
-static void logmsg(int type, const char *fmt, va_list ap)
+static int logmsg(int type, const char *fmt, va_list ap)
{
static char buf[2048];
- int i;
+ int i, len;
- vsnprintf(buf, sizeof buf, fmt, ap);
+ len = vsnprintf(buf, sizeof buf, fmt, ap);
for(i=0; i<num_outputs; i++) {
switch(outputs[i].type) {
break;
}
}
+
+ return len;
}
-void errormsg(const char *fmt, ...)
+int errormsg(const char *fmt, ...)
{
+ int len;
va_list ap;
va_start(ap, fmt);
- logmsg(LOG_ERR, fmt, ap);
+ len = logmsg(LOG_ERR, fmt, ap);
va_end(ap);
+ return len;
}
-void warnmsg(const char *fmt, ...)
+int warnmsg(const char *fmt, ...)
{
+ int len;
va_list ap;
va_start(ap, fmt);
- logmsg(LOG_WARN, fmt, ap);
+ len = logmsg(LOG_WARN, fmt, ap);
va_end(ap);
+ return len;
}
-void infomsg(const char *fmt, ...)
+int infomsg(const char *fmt, ...)
{
+ int len;
va_list ap;
va_start(ap, fmt);
- logmsg(LOG_INFO, fmt, ap);
+ len = logmsg(LOG_INFO, fmt, ap);
va_end(ap);
+ return len;
}
-void dbgmsg(const char *fmt, ...)
+int dbgmsg(const char *fmt, ...)
{
+ int len;
va_list ap;
va_start(ap, fmt);
- logmsg(LOG_DBG, fmt, ap);
+ len = logmsg(LOG_DBG, fmt, ap);
va_end(ap);
+ return len;
}
-void verrormsg(const char *fmt, va_list ap)
+int verrormsg(const char *fmt, va_list ap)
{
- logmsg(LOG_ERR, fmt, ap);
+ return logmsg(LOG_ERR, fmt, ap);
}
-void vwarnmsg(const char *fmt, va_list ap)
+int vwarnmsg(const char *fmt, va_list ap)
{
- logmsg(LOG_ERR, fmt, ap);
+ return logmsg(LOG_ERR, fmt, ap);
}
-void vinfomsg(const char *fmt, va_list ap)
+int vinfomsg(const char *fmt, va_list ap)
{
- logmsg(LOG_ERR, fmt, ap);
+ return logmsg(LOG_ERR, fmt, ap);
}
-void vdbgmsg(const char *fmt, va_list ap)
+int vdbgmsg(const char *fmt, va_list ap)
{
- logmsg(LOG_ERR, fmt, ap);
+ return logmsg(LOG_ERR, fmt, ap);
}
int add_log_console(const char *devname);
int add_log_callback(void (*cbfunc)(const char*, void*), void *cls);
-void errormsg(const char *fmt, ...);
-void warnmsg(const char *fmt, ...);
-void infomsg(const char *fmt, ...);
-void dbgmsg(const char *fmt, ...);
-
-void verrormsg(const char *fmt, va_list ap);
-void vwarnmsg(const char *fmt, va_list ap);
-void vinfomsg(const char *fmt, va_list ap);
-void vdbgmsg(const char *fmt, va_list ap);
+int errormsg(const char *fmt, ...);
+int warnmsg(const char *fmt, ...);
+int infomsg(const char *fmt, ...);
+int dbgmsg(const char *fmt, ...);
+
+int verrormsg(const char *fmt, va_list ap);
+int vwarnmsg(const char *fmt, va_list ap);
+int vinfomsg(const char *fmt, va_list ap);
+int vdbgmsg(const char *fmt, va_list ap);
#endif /* LOGGER_H_ */