# HG changeset patch # User John Tsiombikas # Date 1379776931 -10800 # Node ID f2c2e45e8edd64de4a773b54f1ebf6578fd52309 # Parent 1f26cc6c6204ba59d5fb0a1a08721804a702bb28 reverted the mistaken push from the deepstone branch diff -r 1f26cc6c6204 -r f2c2e45e8edd .hgignore --- a/.hgignore Sat Sep 21 18:18:31 2013 +0300 +++ b/.hgignore Sat Sep 21 18:22:11 2013 +0300 @@ -1,9 +1,5 @@ \.o$ \.obj$ -\.OBJ$ \.d$ \.swp$ ^test$ -\.exe$ -\.EXE$ -^OBJECTS.LNK$ diff -r 1f26cc6c6204 -r f2c2e45e8edd Makefile.bcc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile.bcc Sat Sep 21 18:22:11 2013 +0300 @@ -0,0 +1,26 @@ +.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 1f26cc6c6204 -r f2c2e45e8edd Makefile.wac --- a/Makefile.wac Sat Sep 21 18:18:31 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -obj = test.obj wvga.obj dpmi.obj timer.obj mouse.obj & - mingl.obj mglrast.obj mglgen.obj & - texture.obj palman.obj -bin = deepston.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 1f26cc6c6204 -r f2c2e45e8edd dos4gw.exe Binary file dos4gw.exe has changed diff -r 1f26cc6c6204 -r f2c2e45e8edd src/dpmi.c --- a/src/dpmi.c Sat Sep 21 18:18:31 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -#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 1f26cc6c6204 -r f2c2e45e8edd src/dpmi.h --- a/src/dpmi.h Sat Sep 21 18:18:31 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -#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 1f26cc6c6204 -r f2c2e45e8edd src/inttypes.h --- a/src/inttypes.h Sat Sep 21 18:18:31 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -#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 1f26cc6c6204 -r f2c2e45e8edd src/mglgen.c --- a/src/mglgen.c Sat Sep 21 18:18:31 2013 +0300 +++ b/src/mglgen.c Sat Sep 21 18:22:11 2013 +0300 @@ -1,7 +1,23 @@ +/* +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 1f26cc6c6204 -r f2c2e45e8edd src/mingl.c --- a/src/mingl.c Sat Sep 21 18:18:31 2013 +0300 +++ b/src/mingl.c Sat Sep 21 18:22:11 2013 +0300 @@ -1,10 +1,26 @@ +/* +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 1f26cc6c6204 -r f2c2e45e8edd src/mouse.c --- a/src/mouse.c Sat Sep 21 18:18:31 2013 +0300 +++ b/src/mouse.c Sat Sep 21 18:22:11 2013 +0300 @@ -1,5 +1,4 @@ #include "mouse.h" -#include "inttypes.h" #define INTR 0x33 @@ -14,8 +13,8 @@ int have_mouse(void) { - int16_t res; - __asm { + int res; + asm { mov ax, QUERY int INTR mov res, ax @@ -25,8 +24,8 @@ void show_mouse(int show) { - int16_t cmd = show ? SHOW : HIDE; - __asm { + int cmd = show ? SHOW : HIDE; + asm { mov ax, cmd int INTR } @@ -34,9 +33,9 @@ int read_mouse(int *xp, int *yp) { - int16_t x, y, bn; + int x, y, bn; - __asm { + asm { mov ax, READ int INTR mov bn, bx @@ -52,24 +51,24 @@ void set_mouse(int x, int y) { - __asm { + asm { mov ax, WRITE - mov ecx, x - mov edx, y + mov cx, x + mov dx, y int INTR } } void set_mouse_limits(int xmin, int ymin, int xmax, int ymax) { - __asm { + asm { mov ax, XLIM - mov ecx, xmin - mov edx, xmax + mov cx, xmin + mov dx, xmax int INTR mov ax, YLIM - mov ecx, ymin - mov edx, ymax + mov cx, ymin + mov dx, ymax int INTR } } diff -r 1f26cc6c6204 -r f2c2e45e8edd src/test.c --- a/src/test.c Sat Sep 21 18:18:31 2013 +0300 +++ b/src/test.c Sat Sep 21 18:22:11 2013 +0300 @@ -1,9 +1,26 @@ +/* +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 "wvga.h" +#include "vga.h" #include "mingl.h" #include "timer.h" #include "mouse.h" @@ -135,7 +152,7 @@ pal = palm_palette(); for(i=0; i #include -#include #include -#include #include "pit8254.h" #define PIT_TIMER_INTR 8 @@ -31,10 +29,9 @@ static void set_timer_reload(int reload_val); static void cleanup(void); -static void __interrupt __far timer_irq(); -static void __interrupt __far dos_timer_intr(); - -static void (__interrupt __far *prev_timer_intr)(); +static void interrupt dos_timer_intr(); +static void interrupt timer_irq(); +static void interrupt (*prev_timer_intr)(); static unsigned long ticks; static unsigned long tick_interval, ticks_per_dos_intr; @@ -42,8 +39,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); @@ -52,16 +49,16 @@ ticks_per_dos_intr = DIV_ROUND(65535L, reload_val); inum = PIT_TIMER_INTR; - prev_timer_intr = _dos_getvect(inum); - _dos_setvect(inum, timer_irq); + prev_timer_intr = getvect(inum); + setvect(inum, timer_irq); } else { tick_interval = 55; inum = DOS_TIMER_INTR; - prev_timer_intr = _dos_getvect(inum); - _dos_setvect(inum, dos_timer_intr); + prev_timer_intr = getvect(inum); + setvect(inum, dos_timer_intr); } - _enable(); + enable(); atexit(cleanup); } @@ -72,15 +69,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 */ - _dos_setvect(inum, prev_timer_intr); - _enable(); + setvect(inum, prev_timer_intr); + enable(); } void reset_timer(void) @@ -95,15 +92,15 @@ static void set_timer_reload(int reload_val) { - outp(PORT_CMD, CMD_CHAN0 | CMD_ACCESS_BOTH | CMD_OP_SQWAVE); - outp(PORT_DATA0, reload_val & 0xff); - outp(PORT_DATA0, (reload_val >> 8) & 0xff); + outportb(PORT_CMD, CMD_CHAN0 | CMD_ACCESS_BOTH | CMD_OP_SQWAVE); + outportb(PORT_DATA0, reload_val & 0xff); + outportb(PORT_DATA0, (reload_val >> 8) & 0xff); } -static void __interrupt __far dos_timer_intr() +static void interrupt dos_timer_intr() { ticks++; - _chain_intr(prev_timer_intr); /* DOES NOT RETURN */ + prev_timer_intr(); } /* first PIC command port */ @@ -111,7 +108,7 @@ /* end of interrupt control word */ #define OCW2_EOI (1 << 5) -static void __interrupt __far timer_irq() +static void interrupt timer_irq() { static unsigned long dos_ticks; @@ -121,11 +118,10 @@ /* 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; - _chain_intr(prev_timer_intr); /* XXX DOES NOT RETURN */ - return; /* just for clarity */ + } else { + /* send EOI to the PIC */ + outportb(PIC1_CMD, OCW2_EOI); } - - /* send EOI to the PIC */ - outp(PIC1_CMD, OCW2_EOI); } diff -r 1f26cc6c6204 -r f2c2e45e8edd src/vga.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/vga.c Sat Sep 21 18:22:11 2013 +0300 @@ -0,0 +1,68 @@ +/* +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 1f26cc6c6204 -r f2c2e45e8edd src/vga.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/vga.h Sat Sep 21 18:22:11 2013 +0300 @@ -0,0 +1,26 @@ +/* +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 1f26cc6c6204 -r f2c2e45e8edd src/vmath.h --- a/src/vmath.h Sat Sep 21 18:18:31 2013 +0300 +++ b/src/vmath.h Sat Sep 21 18:22:11 2013 +0300 @@ -1,12 +1,6 @@ #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 1f26cc6c6204 -r f2c2e45e8edd src/wvga.c --- a/src/wvga.c Sat Sep 21 18:18:31 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -#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 1f26cc6c6204 -r f2c2e45e8edd src/wvga.h --- a/src/wvga.h Sat Sep 21 18:18:31 2013 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -#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_ */