# HG changeset patch # User John Tsiombikas # Date 1379776675 -10800 # Node ID 00d84ab1ef26310455f22c7dd2c8e174cf866fe3 # Parent 9c23bfe10745fdcf5666c3064ef10c9231e03b03 switched to wacom diff -r 9c23bfe10745 -r 00d84ab1ef26 .hgignore --- a/.hgignore Sat Sep 21 16:40:31 2013 +0300 +++ b/.hgignore Sat Sep 21 18:17:55 2013 +0300 @@ -1,5 +1,9 @@ \.o$ \.obj$ +\.OBJ$ \.d$ \.swp$ ^test$ +\.exe$ +\.EXE$ +^OBJECTS.LNK$ diff -r 9c23bfe10745 -r 00d84ab1ef26 Makefile.bcc --- a/Makefile.bcc Sat Sep 21 16:40:31 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -.AUTODEPEND - -obj = src\test.obj src\vga.obj src\timer.obj src\mouse.obj \ - src\mingl.obj src\mglrast.obj src\mglgen.obj \ - src\texture.obj src\palman.obj -bin = dos3d.exe - -CC = bcc - -# 386 instructions, x87 fpu code, large memory model, optimize for speed -CFLAGS = -3 -f287 -ml -O2 -G -Isrc - -$(bin): $(obj) - $(CC) @&&| -$(CFLAGS) -e$@ -$(obj) -| - -.SUFFIXES: .c .obj - -.c.obj: - $(CC) $(CFLAGS) -o$@ -c $< - -clean: - del src\*.obj - del $(bin) diff -r 9c23bfe10745 -r 00d84ab1ef26 Makefile.wac --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile.wac Sat Sep 21 18:17:55 2013 +0300 @@ -0,0 +1,21 @@ +obj = test.obj wvga.obj dpmi.obj timer.obj mouse.obj & + mingl.obj mglrast.obj mglgen.obj & + texture.obj palman.obj +bin = dos3d.exe + +CC = wcc386 +CFLAGS = -5 -fp5 -otexan -zq -bt=dos +LD = wlink + +$(bin): $(obj) + %write objects.lnk file { $(obj) } + $(LD) name $@ @objects $(LDFLAGS) + +.c: src\ + +.c.obj: .autodepend + $(CC) $(CFLAGS) $[* + +clean: .symbolic + del *.obj + del $(bin) diff -r 9c23bfe10745 -r 00d84ab1ef26 dos4gw.exe Binary file dos4gw.exe has changed diff -r 9c23bfe10745 -r 00d84ab1ef26 src/dpmi.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dpmi.c Sat Sep 21 18:17:55 2013 +0300 @@ -0,0 +1,55 @@ +#include "dpmi.h" + +void dpmi_real_int(int inum, struct dpmi_real_regs *regs) +{ + unsigned char int_num = (unsigned char)inum; + __asm { + mov eax, 0x300 + mov edi, regs + mov bl, int_num + mov bh, 0 + xor ecx, ecx + int 0x31 + } +} + +void *dpmi_mmap(uint32_t phys_addr, unsigned int size) +{ + uint16_t mem_high, mem_low; + uint16_t phys_high = phys_addr >> 16; + uint16_t phys_low = phys_addr & 0xffff; + uint16_t size_high = size >> 16; + uint16_t size_low = size & 0xffff; + unsigned int err, res = 0; + + __asm { + mov eax, 0x800 + mov bx, phys_high + mov cx, phys_low + mov si, size_high + mov di, size_low + int 0x31 + add res, 1 + mov err, eax + mov mem_high, bx + mov mem_low, cx + } + + if(res == 2) { + return 0; + } + return (void*)(((uint32_t)mem_high << 16) | ((uint32_t)mem_low)); +} + +void dpmi_munmap(void *addr) +{ + uint16_t mem_high = (uint32_t)addr >> 16; + uint16_t mem_low = (uint16_t)addr; + + __asm { + mov eax, 0x801 + mov bx, mem_high + mov cx, mem_low + int 0x31 + } +} diff -r 9c23bfe10745 -r 00d84ab1ef26 src/dpmi.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dpmi.h Sat Sep 21 18:17:55 2013 +0300 @@ -0,0 +1,26 @@ +#ifndef DPMI_H_ +#define DPMI_H_ + +#include "inttypes.h" + +struct dpmi_real_regs { + uint32_t edi, esi, ebp; + uint32_t reserved; + uint32_t ebx, edx, ecx, eax; + uint16_t flags; + uint16_t es, ds, fs, gs; + uint16_t ip, cs, sp, ss; +}; + +unsigned short dpmi_alloc(unsigned int par); +#pragma aux dpmi_alloc = \ + "mov eax, 0x100" \ + "int 0x31" \ + value[ax] parm[ebx]; + +void dpmi_real_int(int inum, struct dpmi_real_regs *regs); + +void *dpmi_mmap(uint32_t phys_addr, unsigned int size); +void dpmi_munmap(void *addr); + +#endif /* DPMI_H_ */ diff -r 9c23bfe10745 -r 00d84ab1ef26 src/inttypes.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/inttypes.h Sat Sep 21 18:17:55 2013 +0300 @@ -0,0 +1,12 @@ +#ifndef INT_TYPES_H_ +#define INT_TYPES_H_ + +typedef char int8_t; +typedef short int16_t; +typedef long int32_t; + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned long uint32_t; + +#endif /* INT_TYPES_H_ */ diff -r 9c23bfe10745 -r 00d84ab1ef26 src/mglgen.c --- a/src/mglgen.c Sat Sep 21 16:40:31 2013 +0300 +++ b/src/mglgen.c Sat Sep 21 18:17:55 2013 +0300 @@ -1,23 +1,7 @@ -/* -256-color 3D graphics hack for real-mode DOS. -Copyright (C) 2011 John Tsiombikas - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ #include #include #include "mingl.h" +#include "vmath.h" void mgl_cube(float sz) diff -r 9c23bfe10745 -r 00d84ab1ef26 src/mingl.c --- a/src/mingl.c Sat Sep 21 16:40:31 2013 +0300 +++ b/src/mingl.c Sat Sep 21 18:17:55 2013 +0300 @@ -1,26 +1,10 @@ -/* -256-color 3D graphics hack for real-mode DOS. -Copyright (C) 2011 John Tsiombikas - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ #include #include #include #include #include #include +#include "vmath.h" #include "mingl.h" #include "mglimpl.h" diff -r 9c23bfe10745 -r 00d84ab1ef26 src/mouse.c --- a/src/mouse.c Sat Sep 21 16:40:31 2013 +0300 +++ b/src/mouse.c Sat Sep 21 18:17:55 2013 +0300 @@ -1,4 +1,5 @@ #include "mouse.h" +#include "inttypes.h" #define INTR 0x33 @@ -13,8 +14,8 @@ int have_mouse(void) { - int res; - asm { + int16_t res; + __asm { mov ax, QUERY int INTR mov res, ax @@ -24,8 +25,8 @@ void show_mouse(int show) { - int cmd = show ? SHOW : HIDE; - asm { + int16_t cmd = show ? SHOW : HIDE; + __asm { mov ax, cmd int INTR } @@ -33,9 +34,9 @@ int read_mouse(int *xp, int *yp) { - int x, y, bn; + int16_t x, y, bn; - asm { + __asm { mov ax, READ int INTR mov bn, bx @@ -51,24 +52,24 @@ void set_mouse(int x, int y) { - asm { + __asm { mov ax, WRITE - mov cx, x - mov dx, y + mov ecx, x + mov edx, y int INTR } } void set_mouse_limits(int xmin, int ymin, int xmax, int ymax) { - asm { + __asm { mov ax, XLIM - mov cx, xmin - mov dx, xmax + mov ecx, xmin + mov edx, xmax int INTR mov ax, YLIM - mov cx, ymin - mov dx, ymax + mov ecx, ymin + mov edx, ymax int INTR } } diff -r 9c23bfe10745 -r 00d84ab1ef26 src/test.c --- a/src/test.c Sat Sep 21 16:40:31 2013 +0300 +++ b/src/test.c Sat Sep 21 18:17:55 2013 +0300 @@ -1,26 +1,9 @@ -/* -256-color 3D graphics hack for real-mode DOS. -Copyright (C) 2011 John Tsiombikas - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ #include #include #include #include #include -#include "vga.h" +#include "wvga.h" #include "mingl.h" #include "timer.h" #include "mouse.h" @@ -152,7 +135,7 @@ pal = palm_palette(); for(i=0; i #include +#include #include +#include #include "pit8254.h" #define PIT_TIMER_INTR 8 @@ -29,9 +31,10 @@ static void set_timer_reload(int reload_val); static void cleanup(void); -static void interrupt dos_timer_intr(); -static void interrupt timer_irq(); -static void interrupt (*prev_timer_intr)(); +static void __interrupt __far timer_irq(); +static void __interrupt __far dos_timer_intr(); + +static void (__interrupt __far *prev_timer_intr)(); static unsigned long ticks; static unsigned long tick_interval, ticks_per_dos_intr; @@ -39,8 +42,8 @@ void init_timer(int res_hz) { + _disable(); - disable(); if(res_hz > 0) { int reload_val = DIV_ROUND(OSC_FREQ_HZ, res_hz); set_timer_reload(reload_val); @@ -49,16 +52,16 @@ ticks_per_dos_intr = DIV_ROUND(65535L, reload_val); inum = PIT_TIMER_INTR; - prev_timer_intr = getvect(inum); - setvect(inum, timer_irq); + prev_timer_intr = _dos_getvect(inum); + _dos_setvect(inum, timer_irq); } else { tick_interval = 55; inum = DOS_TIMER_INTR; - prev_timer_intr = getvect(inum); - setvect(inum, dos_timer_intr); + prev_timer_intr = _dos_getvect(inum); + _dos_setvect(inum, dos_timer_intr); } - enable(); + _enable(); atexit(cleanup); } @@ -69,15 +72,15 @@ return; /* init hasn't ran, there's nothing to cleanup */ } - disable(); + _disable(); if(inum == PIT_TIMER_INTR) { /* restore the original timer frequency */ set_timer_reload(65535); } /* restore the original interrupt handler */ - setvect(inum, prev_timer_intr); - enable(); + _dos_setvect(inum, prev_timer_intr); + _enable(); } void reset_timer(void) @@ -92,15 +95,15 @@ static void set_timer_reload(int reload_val) { - outportb(PORT_CMD, CMD_CHAN0 | CMD_ACCESS_BOTH | CMD_OP_SQWAVE); - outportb(PORT_DATA0, reload_val & 0xff); - outportb(PORT_DATA0, (reload_val >> 8) & 0xff); + outp(PORT_CMD, CMD_CHAN0 | CMD_ACCESS_BOTH | CMD_OP_SQWAVE); + outp(PORT_DATA0, reload_val & 0xff); + outp(PORT_DATA0, (reload_val >> 8) & 0xff); } -static void interrupt dos_timer_intr() +static void __interrupt __far dos_timer_intr() { ticks++; - prev_timer_intr(); + _chain_intr(prev_timer_intr); /* DOES NOT RETURN */ } /* first PIC command port */ @@ -108,7 +111,7 @@ /* end of interrupt control word */ #define OCW2_EOI (1 << 5) -static void interrupt timer_irq() +static void __interrupt __far timer_irq() { static unsigned long dos_ticks; @@ -118,10 +121,11 @@ /* I suppose the dos irq handler does the EOI so I shouldn't * do it if I am to call the previous function */ - prev_timer_intr(); dos_ticks = 0; - } else { - /* send EOI to the PIC */ - outportb(PIC1_CMD, OCW2_EOI); + _chain_intr(prev_timer_intr); /* XXX DOES NOT RETURN */ + return; /* just for clarity */ } + + /* send EOI to the PIC */ + outp(PIC1_CMD, OCW2_EOI); } diff -r 9c23bfe10745 -r 00d84ab1ef26 src/vga.c --- a/src/vga.c Sat Sep 21 16:40:31 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* -256-color 3D graphics hack for real-mode DOS. -Copyright (C) 2011 John Tsiombikas - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ -#include -#include - -void set_video_mode(int mode) -{ - asm { - mov ax, mode - int 0x10 - } -} - -void set_palette(unsigned char c, unsigned char r, unsigned char g, unsigned char b) -{ - asm { - mov dx, 0x3c8 - mov al, c - out dx, al - inc dx - mov al, r - shr al, 2 - out dx, al - mov al, g - shr al, 2 - out dx, al - mov al, b - shr al, 2 - out dx, al - } -} - -void copy_frame(unsigned char *frame) -{ - _fmemcpy(MK_FP(0xa000, 0), frame, 64000); -} - -void wait_vsync(void) -{ - asm mov dx, 0x3da -l1: - asm { - in al, dx - and al, 0x8 - jnz l1 - } -l2: - asm { - in al, dx - and al, 0x8 - jz l2 - } -} diff -r 9c23bfe10745 -r 00d84ab1ef26 src/vga.h --- a/src/vga.h Sat Sep 21 16:40:31 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -/* -256-color 3D graphics hack for real-mode DOS. -Copyright (C) 2011 John Tsiombikas - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ -#ifndef VGA_H_ -#define VGA_H_ - -void set_video_mode(int mode); -void set_palette(unsigned char c, unsigned char r, unsigned char g, unsigned char b); -void copy_frame(unsigned char *frame); -void wait_vsync(void); - -#endif /* VGA_H_ */ diff -r 9c23bfe10745 -r 00d84ab1ef26 src/vmath.h --- a/src/vmath.h Sat Sep 21 16:40:31 2013 +0300 +++ b/src/vmath.h Sat Sep 21 18:17:55 2013 +0300 @@ -1,6 +1,12 @@ #ifndef VMATH_H_ #define VMATH_H_ +#include + +#ifndef M_PI +#define M_PI 3.1415926536 +#endif + typedef struct { float x, y, z, w; } vec4_t; diff -r 9c23bfe10745 -r 00d84ab1ef26 src/wvga.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/wvga.c Sat Sep 21 18:17:55 2013 +0300 @@ -0,0 +1,91 @@ +#include +#include +#include +#include "wvga.h" +#include "dpmi.h" + +/* VGA DAC registers used for palette setting in 8bpp modes */ +#define VGA_DAC_STATE 0x3c7 +#define VGA_DAC_ADDR_RD 0x3c7 +#define VGA_DAC_ADDR_WR 0x3c8 +#define VGA_DAC_DATA 0x3c9 + +static void *framebuffer; + +int set_video_mode(int mode) +{ + struct dpmi_real_regs regs; + + memset(®s, 0, sizeof regs); + regs.eax = mode; + dpmi_real_int(0x10, ®s); + + if(regs.eax == 0x100) { + return -1; + } + + if(mode != 3) { + framebuffer = dpmi_mmap(0xa0000, 64000); + } else { + dpmi_munmap((void*)0xa0000); + } + return 0; +} + +void set_palette(int idx, int *col, int count) +{ + int i; + + __asm { + mov dx, VGA_DAC_ADDR_WR + mov eax, idx + out dx, al + } + + for(i=0; i> 2; + unsigned char g = *col++ >> 2; + unsigned char b = *col++ >> 2; + + __asm { + mov dx, VGA_DAC_DATA + mov al, r + out dx, al + mov al, g + out dx, al + mov al, b + out dx, al + } + } +} + +void set_pal_entry(int idx, int r, int g, int b) +{ + int color[3]; + color[0] = r; + color[1] = g; + color[2] = b; + + set_palette(idx, color, 1); +} + +void copy_frame(void *pixels) +{ + memcpy(framebuffer, pixels, 64000); +} + + +void wait_vsync(void) +{ + __asm { + mov dx, 0x3da + l1: + in al, dx + and al, 0x8 + jnz l1 + l2: + in al, dx + and al, 0x8 + jz l2 + } +} diff -r 9c23bfe10745 -r 00d84ab1ef26 src/wvga.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/wvga.h Sat Sep 21 18:17:55 2013 +0300 @@ -0,0 +1,12 @@ +#ifndef WVGA_H_ +#define WVGA_H_ + + +int set_video_mode(int mode); +void set_palette(int idx, int *col, int count); +void set_pal_entry(int idx, int r, int g, int b); +void copy_frame(void *pixels); + +void wait_vsync(void); + +#endif /* WVGA_H_ */