Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************/
- /******************************************************************************/
- //"VGA_stuff_2025-05-22\MAIN.C":
- #include "C:/home/kit_all.h"
- #include <hardware.h>
- #include <kit_std.h>
- #define delayMS delay
- #ifdef _DEBUG
- #define PRINT_SEED \
- printf("SEED = 0x%04X", seed>>16); \
- printf("%04X\n", seed&0xFFFF);
- #else
- #define PRINT_SEED
- #endif
- // From "SRC/MISC.C":
- void generatePalette(void);
- bool generateMaze(s8* map, s16 w, s16 h, s8 fillValue);
- Color24 hsv2rgb(f32 h, f32 s, f32 v);
- /*
- void draw_pointf(f32 xf, f32 yf,
- byte color)
- {
- s16 x = SCREEN_W/2;
- s16 y = SCREEN_H/2;
- if( xf<-1.0f | xf>1.0f |
- yf<-1.0f | yf>1.0f )
- {
- return;
- }
- x += (s16)(xf * ((xf>=0.0f) ? (SCREEN_W/2-1) : (SCREEN_W/2)));
- y += (s16)(yf * ((yf>=0.0f) ? (SCREEN_H/2-1) : (SCREEN_H/2)));
- VGA[x + y*SCREEN_W] = color;
- }
- */
- static s32 x,y,i;
- static Color24 prev_colors[256];
- #define MAPMAX_W 31
- #define MAPMAX_H 15
- static s8 map[MAPMAX_W*MAPMAX_H];
- static byte tiles[128];
- static KIT_fpoint3d pos;
- int main(/*int argc, char* argv[]*/)
- {
- u32 seed;
- byte prevVideoMode;
- seed = readPIT_Ch0();
- PRINT_SEED
- prevVideoMode = setVideoMode(0x13);
- for(i=0; i<256; ++i)
- prev_colors[i] = getPaletteColor(i);
- generatePalette();
- delayMS(seed%234); // A bit hacky
- seed <<= 16;
- seed |= readPIT_Ch0();
- PRINT_SEED
- KIT_srand((long int)seed);
- /*******/
- generateMaze(map, MAPMAX_W, MAPMAX_H, 1);
- pos.x = 1.5f;
- pos.y = 1.5f;
- pos.z = 0.0f;
- tiles[0] = 0x40;
- #define ITMAX 8
- for(i=0; i<ITMAX; ++i){
- draw_raycast_scene(map, MAPMAX_W, MAPMAX_H,
- pos, tiles,
- 0x20, 0x80,
- 50, 90.0f);
- pos.z += (1.0f/ITMAX)*M_2PIf;
- delayMS(1000);
- }
- /*******/
- for(i=0; i<256; ++i)
- setPaletteColor(i, prev_colors[i].v);
- setVideoMode(prevVideoMode);
- #ifdef _DEBUG
- //generateMaze(map, MAPMAX_W, MAPMAX_H, 1);
- for(i=0; i<(MAPMAX_W*MAPMAX_H); ++i){
- printf("%c", (map[i])?219:'.');
- if((i%MAPMAX_W) == (MAPMAX_W-1))
- printf("\n");
- }
- PRINT_SEED
- #endif
- return 0;
- }
- /******************************************************************************/
- /******************************************************************************/
- //"VGA_stuff_2025-05-22\SRC\HRDWRSRC.C":
- #include <draw.h>
- byte far * const VGA = VGA_FAR_PTR;
- // Returns the previous video mode
- byte setVideoMode(byte new_mode)
- {
- union REGS regs;
- byte prevVideoMode;
- regs.h.ah = 0x0F; // Get current mode
- int86(0x10, ®s, ®s);
- prevVideoMode = regs.h.al;
- regs.h.ah = 0x00; // Set current mode
- regs.h.al = new_mode;
- int86(0x10, ®s, ®s);
- return prevVideoMode;
- }
- Color24 getPaletteColor(byte which)
- {
- Color24 rgb;
- outp(0x3C7, which); // Set read index
- rgb.v = 0;
- rgb.v |= ((u32)inp(0x3C9)) << 16; // R
- rgb.v |= ((u32)inp(0x3C9)) << 8; // G
- rgb.v |= ((u32)inp(0x3C9)) << 0; // B
- return rgb;
- }
- void setPaletteColor(byte which, u32 rgb)
- {
- outp(0x3C6, 0xFF);
- outp(0x3C8, which); // Set write index
- outp(0x3C9, (rgb>>16)&0xFF); // R
- outp(0x3C9, (rgb>> 8)&0xFF); // G
- outp(0x3C9, (rgb>> 0)&0xFF); // B
- }
- u16 readPIT_Ch0(void)
- {
- u16 v;
- // Latch current count value for channel 0
- outp(0x43, 0x00); // 00h = latch command for channel 0
- // Read low and high byte from channel 0's data port
- v = inp(0x40);
- v |= ((u16)inp(0x40))<<8;
- return v;
- }
- /******************************************************************************/
- /******************************************************************************/
- //"VGA_stuff_2025-05-22\SRC\KIT_STDS.C":
- #include "C:/home/kit_all.h"
- #define BITSIZE_S31 (sizeof(s32)*8 - 1)
- long int KIT_labs(long int n)
- {
- const long int mask = n>>BITSIZE_S31;
- return (n+mask) ^ mask; // Branchless :D
- }
- float KIT_fabsf(float _x)
- {
- union {
- f32 f;
- u32 i;
- } x;
- x.f = _x;
- x.i &= 0x7FFFFFFF;
- return x.f;
- }
- void* KIT_memset(void* dst, int val, size_t len)
- {
- u8 val8, *dst8;
- u32 val32, *dst32;
- size_t remainder;
- if(!len) return dst;
- dst8 = (u8*)dst;
- val8 = (u8 )val;
- remainder = len%sizeof(u32);
- len -= remainder;
- while((remainder--) > 0)
- *(dst8++) = val8;
- dst32 = (u32*)dst8;
- val32 = (u32 )val8;
- val32 |= val32<< 8;
- val32 |= val32<<16;
- len /= sizeof(u32);
- while((len--) > 0)
- *(dst32++) = val32;
- return dst;
- }
- // (Uses a default seed)
- static u32 rand_state = 0x37C0FFEE;
- void KIT_srand(long int seed)
- {
- // Must be nonzero, otherwise
- // the xorshift doesn't work
- if(seed == 0) seed = 1;
- rand_state = (u32)seed;
- }
- long int KIT_lrand(void)
- {
- s32 LSb = rand_state&1;
- rand_state >>= 1;
- // Taps: 31, 21, 1, 0
- rand_state ^= 0x80200003L & (-LSb);
- return (long int)rand_state;
- }
- #define my_fmodf(x, y) \
- ( (x) - ((long int)((x)/(y)) * (y)) )
- float KIT_fmodf(float x, float y)
- {
- return my_fmodf(x, y);
- }
- // Uses Bhaskara I's sine approx. formula
- // (The rest is basically just domain manipulation)
- float KIT_sinf(float x)
- {
- float result;
- bool negative = x<0.0f;
- x = my_fmodf(x, M_2PIf);
- negative ^= x>=M_PIf;
- if(x >= M_PIf) x -= M_PIf; // x %= pi
- result = 16.0f*x * (M_PIf-x);
- result /= 5.0f*M_PIf*M_PIf - result*0.25f;
- return (negative) ? -result : result;
- }
- /******************************************************************************/
- /******************************************************************************/
- //"VGA_stuff_2025-05-22\SRC\MISC.C":
- #include "C:/home/kit_all.h"
- #include <hardware.h>
- #include <kit_std.h>
- #define MAZE_START_X 1
- #define MAZE_START_Y 1
- void generatePalette(void)
- {
- s32 i;
- Color8 clr_idx;
- Color24 clr_val;
- // Generate custom VGA palette
- //
- // (Channels have a depth of 6-bits, not 8-bits!)
- for(i=0; i<256; ++i){
- clr_idx.v = i;
- #define conv_b(_c) ((_c)*21)
- #define conv_rg(_c) ((u8)( (63.0f*((f32)(_c)/7)) + 0.5f ))
- clr_val.c.b = conv_b(clr_idx.c.b);
- clr_val.c.g = conv_rg(clr_idx.c.g);
- clr_val.c.r = conv_rg(clr_idx.c.r);
- setPaletteColor(i, clr_val.v);
- }
- // Grayscale portion of palette
- for(i=0; i<16; ++i){
- clr_val.v = i<<2;
- clr_val.v |= clr_val.v<< 8;
- clr_val.v |= clr_val.v<<16;
- setPaletteColor(i<<4, clr_val.v);
- }
- }
- // Direction vectors (up, right, down, left)
- const s16 d_x[] = { 0, 1, 0,-1};
- const s16 d_y[] = {-1, 0, 1, 0};
- static void carve(s16 x, s16 y,
- s8* map, s16 w, s16 h)
- {
- s16 i, j, tmp, nx, ny, which_a;//, which_b, cur;
- s16 dir[] = {0, 1, 2, 3};
- // Shuffle dir
- for(i=3; i>0; --i)
- {
- j = (s16)(KIT_rand() % (i+1));
- tmp = dir[i];
- dir[i] = dir[j];
- dir[j] = tmp;
- }
- // Macros to save a bit on stack space,
- // since this is a recursive function
- #define which_b j
- #define cur tmp
- for(i=0; i<4; ++i)
- {
- cur = dir[i];
- nx = x + (d_x[cur]<<1);
- ny = y + (d_y[cur]<<1);
- which_a = nx + ny*w;
- if( nx>0 && nx<w &&
- ny>0 && ny<h &&
- map[which_a]!=0)
- {
- which_b = nx-d_x[cur] + (ny-d_y[cur])*w;
- map[which_a] = 0;
- map[which_b] = 0;
- carve(nx, ny, map, w, h);
- }
- }
- #undef which_b
- #undef cur
- }
- // w & h must be odd, otherwise the
- // south-eastern edges will also be carved!
- bool generateMaze(s8* map, s16 w, s16 h,
- s8 fillValue)
- {
- s16 stepX, stepY;
- u32 x,y,i, numCells = ((u32)w)*((u32)h);
- if( map == NULL ||
- w<5 || h<5 ||
- fillValue==0 )
- {
- return false;
- }
- // Initialize all cells to fill value,
- // or at random up to -fillValue if negative
- if(fillValue > 0){
- for(i=0; i<numCells; ++i)
- map[i] = fillValue;
- } else {
- fillValue = -fillValue;
- for(i=0; i<numCells; ++i)
- map[i] = (s8)(1+KIT_rand()%fillValue);
- }
- map[MAZE_START_X + MAZE_START_Y*w] = 0;
- carve(MAZE_START_X, MAZE_START_Y, map, w, h);
- // In the event where carve doesn't make a
- // proper path to the exit, make one manually
- x = w-2;
- y = h-2;
- i = x + y*w;
- stepX = -(KIT_rand()&1);
- stepY = -(!stepX);
- while(map[i] != 0 &&
- x>0 && y>0)
- {
- map[i] = 0;
- x += stepX;
- y += stepY;
- i = x + y*w;
- }
- return true;
- }
- #define floor(v) 0
- Color24 hsv2rgb(f32 h, f32 s, f32 v)
- {
- int i;
- f32 f, p, q, t;
- f32 r, g, b;
- Color24 out;
- // Normalize values
- h /= 360.0f;
- s /= 100.0f;
- v /= 100.0f;
- // The rest is magic or something, idk
- i = floor(h*6);
- f = h * 6 - i;
- p = v * (1.0f - s);
- q = v * (1.0f - f * s);
- t = v * (1.0f - (1.0f-f) * s);
- switch(i%6){
- case 0: r = v, g = t, b = p; break;
- case 1: r = q, g = v, b = p; break;
- case 2: r = p, g = v, b = t; break;
- case 3: r = p, g = q, b = v; break;
- case 4: r = t, g = p, b = v; break;
- case 5: r = v, g = p, b = q; break;
- }
- // 63 instead of 255, since mode 13h palette colors use 6-bit channels
- out.c.r = r*63;
- out.c.g = g*63;
- out.c.b = b*63;
- out.c._ = 0;
- return out;
- }
- /******************************************************************************/
- /******************************************************************************/
- //"VGA_stuff_2025-05-22\SRC\DRAW\COLUMN.C":
- #include "C:/home/kit_all.h"
- extern byte far * const VGA;
- #define EPSILON 0.0001f
- #define SCREEN_Hh (SCREEN_H/2)
- void draw_column(u16 x, f32 height,
- byte color)
- {
- // Half of the column's height, in pixels,
- // multiplied by SCREEN_W
- s32 pixels_half;
- // The start and end pointers, respectively
- byte far* dst_a;
- byte far* dst_b;
- if(x >= SCREEN_W) return;
- if(height <= EPSILON) return;
- pixels_half = (s32)(SCREEN_Hh*MIN(height, 1.0f));
- pixels_half *= SCREEN_W;
- dst_a = VGA + x + SCREEN_Hh*SCREEN_W;
- dst_b = dst_a - SCREEN_W; // dst_a - 1 row
- dst_a -= pixels_half;
- dst_b += pixels_half;
- // (Increment dst_b, so I can use < in the for loop)
- ++dst_b;
- for(; dst_a<dst_b; dst_a+=SCREEN_W)
- *dst_a = color;
- }
- /******************************************************************************/
- /******************************************************************************/
- //"VGA_stuff_2025-05-22\SRC\DRAW\F_SCNLNE.C":
- #include "C:/home/kit_all.h"
- extern byte far * const VGA;
- typedef u32 far* u32fp;
- typedef u8 far* u8fp;
- void fill_scanlines(u16 y, u16 _len,
- byte color)
- {
- u32 far* dst_a;
- u32 far* dst_b;
- u32 len = _len;
- u32 color32 = color;
- color32 |= color32<< 8;
- color32 |= color32<<16;
- if(y >= SCREEN_H) return;
- if(len == 0 ) return;
- if(((u32)y+len) >= SCREEN_H)
- len = SCREEN_H-y;
- dst_a = (u32fp)(VGA + y*SCREEN_W);
- dst_b = (u32fp)((u8fp)dst_a + len*SCREEN_W);
- // (++dst_a means incrementing by sizeof(u32))
- for(; dst_a<dst_b; ++dst_a)
- *dst_a = color32;
- }
- /******************************************************************************/
- /******************************************************************************/
- //"VGA_stuff_2025-05-22\SRC\DRAW\LINE.C":
- #include "C:/home/kit_all.h"
- #include <kit_std.h>
- extern byte far * const VGA;
- void draw_line( s32 x_0, s32 y_0,
- const s32 x_1, const s32 y_1,
- const byte color)
- {
- const s32 d_x = KIT_labs(x_1 - x_0);
- const s32 d_y = -KIT_labs(y_1 - y_0);
- const s32 s_x = (x_0<x_1) ? 1 : -1;
- const s32 s_y = (y_0<y_1) ? 1 : -1;
- const s32 s_y_row = s_y*SCREEN_W;
- s32 err = d_x + d_y;
- s32 err2;
- byte far* dst = VGA + x_0 + y_0*SCREEN_W;
- while(true){
- if( (x_0>=0) && (x_0<SCREEN_W) &&
- (y_0>=0) && (y_0<SCREEN_H) )
- {
- *dst = color;
- }
- if(x_0==x_1 && y_0==y_1) break;
- err2 = err<<1;
- if(err2 >= d_y){
- err += d_y;
- x_0 += s_x;
- dst += s_x;
- }
- if(err2 <= d_x){
- err += d_x;
- y_0 += s_y;
- dst += s_y_row;
- }
- }
- }
- /******************************************************************************/
- /******************************************************************************/
- //"VGA_stuff_2025-05-22\SRC\DRAW\RCST_SCN.C":
- #include "C:/home/kit_all.h"
- #include <draw.h>
- #include <kit_std.h>
- KIT_fpoint create_vec2(f32 angleRads,
- f32 magnitude)
- {
- KIT_fpoint out;
- out.x = KIT_cosf(angleRads)*magnitude;
- out.y = KIT_sinf(angleRads)*magnitude;
- return out;
- }
- #define pos_angle pos.z
- void draw_raycast_scene(const s8* map, s16 map_w, s16 map_h,
- KIT_fpoint3d pos, // (pos.z is the angle in rads)
- const byte* tiles, // should be 128 in length
- byte colorFloor, byte colorCeiling,
- u16 renderDistance, f32 fov)
- {
- KIT_fpoint dir; // Player direction vector
- // Camera plane's orientation and size
- // (An FOV larger than 90 is inaccurate!)
- f32 plane_angle;
- f32 plane_magnitude;
- KIT_fpoint plane;
- KIT_fpoint rayDir; // Ray's direction and position
- KIT_fpoint deltaDist; // Length of ray from one x/y side to next x/y side
- KIT_fpoint sideDist; // Length of ray from current pos. to next x/y side
- KIT_spoint pos_map; // The tile the player is currently in
- f32 plane_offset; // x-coordinate along the camera plane
- KIT_spoint step; // What direction to step in x or y direction (-1 or 1)
- bool sideVert; // 'Was an EW (horiz.) or NS (vert.) tile hit?'
- s8 tileHit; // abs(tileHit) is the true index (make sure to cast to s16!)
- u16 x, i; // Iteration counters, of course
- u16 tileWhich; // Map index of the current tile, not the raw tile index!
- f32 perpWallDist; // Distance projected on camera direction
- f32 columnHeight; // Pixel column height for the current ray (0.0f -> 1.0f)
- Color8 color; // the color of the current ray
- if(!map || !tiles || map_w==0 || map_h==0) return;
- plane_angle = M_PI2f + pos_angle; // = pi/2 + pos.z
- plane_magnitude = (f32)CLAMP(fov, 1e-100, 90) / 90;
- plane = create_vec2(plane_angle, plane_magnitude);
- rayDir.x = rayDir.y = 0.0f;
- deltaDist.x = deltaDist.y = 0.0f;
- sideDist.x = sideDist.y = 0.0f;
- // Draw the ceiling and floor respectively
- fill_scanlines( 0, SCREEN_H/2, colorCeiling);
- fill_scanlines(SCREEN_H/2, SCREEN_H/2, colorFloor);
- if(renderDistance == 0) return; // Lol
- // For each column of pixels
- for(x=0; x<SCREEN_W; ++x)
- {
- // The tile the player's currently in
- pos_map.x = (s16)pos.x;
- pos_map.y = (s16)pos.y;
- // x-coordinate along the camera plane;
- plane_offset = (f32)(x<<1)/SCREEN_W - 1.0f; // -1.0f -> 1.0f
- // Ray's direction and position
- rayDir.x = dir.x + plane.x*plane_offset;
- rayDir.y = dir.y + plane.y*plane_offset;
- // (Replace number with 1e30 if it would otherwise divide by 0!)
- deltaDist.x = (rayDir.x) ? KIT_fabsf(1.0f/rayDir.x) : 1e30;
- deltaDist.y = (rayDir.y) ? KIT_fabsf(1.0f/rayDir.y) : 1e30;
- // Calculate step and initial sideDist
- if(rayDir.x < 0.0f){
- step.x = -1;
- sideDist.x = deltaDist.x * (pos.x - pos_map.x);
- } else {
- step.x = 1;
- sideDist.x = deltaDist.x * (pos_map.x+1 - pos.x);
- }
- if(rayDir.y < 0.0f){
- step.y = -1;
- sideDist.y = deltaDist.y * (pos.y - pos_map.y);
- } else {
- step.y = 1;
- sideDist.y = deltaDist.y * (pos_map.y+1 - pos.y);
- }
- tileHit = 0; // (Default of 0 means no tile was hit!)
- // For each step in the current ray (perform DDA)
- for(i=0; i<renderDistance; ++i)
- {
- // Jump to next map square, either in the x or y direction
- if(sideDist.x < sideDist.y){
- sideDist.x += deltaDist.x;
- pos_map.x += step.x;
- sideVert = false; // Closest tile is horizontal
- } else {
- sideDist.y += deltaDist.y;
- pos_map.y += step.y;
- sideVert = true; // Closest tile is vertical
- }
- tileWhich = pos_map.x + pos_map.y*map_w;
- // Check if ray has hit a wall
- if( pos_map.x>=0 && pos_map.x<map_w &&
- pos_map.y>=0 && pos_map.y<map_h &&
- map[tileWhich] != 0)
- {
- tileHit = map[tileWhich];
- break;
- }
- }
- // Calculate distance projected on camera direction,
- // because raw euclidean distance would give a fisheye effect!
- //
- // (In other words, perWallDist is the final length of the current ray)
- if(!sideVert) perpWallDist = (sideDist.x - deltaDist.x);
- else perpWallDist = (sideDist.y - deltaDist.y);
- if(tileHit != 0){
- // A multiplier for the height of the pixel column,
- // relative to the height of the framebuffer
- columnHeight = 1.0f/perpWallDist;
- // (-1 is applied to tileHit, so that tiles[0] can be accessed)
- if(tileHit < 0) tileHit = -tileHit;
- color.v = tiles[tileHit-1];
- // If sideVert, then modulate the
- // final color to be darker than normal
- if(sideVert){
- color.c.r >>= 1;
- color.c.g >>= 1;
- color.c.b >>= 1;
- }
- draw_column(x, columnHeight, color.v);
- }
- }
- }
- /******************************************************************************/
- /******************************************************************************/
- //"VGA_stuff_2025-05-22\KIT_ALL.H":
- #ifndef _KIT_ALL_H
- #define _KIT_ALL_H
- #include <dos.h>
- // (Mode 0x13 is 320x200 at 8bpp)
- #define SCREEN_W 320
- #define SCREEN_H 200
- #define MIN(a,b) (((a)<(b))?(a):(b))
- #define MAX(a,b) (((a)>(b))?(a):(b))
- #define CLAMP(n,mn,mx) MIN(MAX((n),(mn)),(mx))
- // Precise version
- #define LERP(v0,v1,t) ((1.0f-(t))*(v0)+(t)*(v1))
- // Imprecise (but potentially faster) version
- #define LERP2(v0,v1,t) ((v0)+(t)*((v1)-(v0)))
- // Integer bounds
- #define KIT_U8_MAX 0xFF
- #define KIT_U16_MAX 0xFFFF
- #define KIT_U24_MAX 0xFFFFFF
- #define KIT_U32_MAX 0xFFFFFFFF
- //
- #define KIT_S8_MAX 0x7F
- #define KIT_S16_MAX 0x7FFF
- #define KIT_S24_MAX 0x7FFFFF
- #define KIT_S32_MAX 0x7FFFFFFF
- // Most significant bits/bytes
- #define KIT_MSb_8 0x80
- #define KIT_MSb_16 0x8000
- #define KIT_MSb_24 0x800000
- #define KIT_MSb_32 0x80000000
- //
- #define KIT_MSB_8 0xFF
- #define KIT_MSB_16 0xFF00
- #define KIT_MSB_24 0xFF0000
- #define KIT_MSB_32 0xFF000000
- // Pi constants (a little overkill for
- // single-precision, but whatever.)
- #define M_PI2f 1.57079632679489661923f
- #define M_PIf 3.14159265358979323846f
- #define M_2PIf 6.28318530717958647692f
- #ifndef NULL
- #define NULL ((void*)0)
- #endif
- // (Is this one even necessary?)
- #ifndef NULL_FAR
- #define NULL_FAR ((void far*)0)
- #endif
- typedef unsigned char u8;
- typedef unsigned short u16;
- typedef unsigned long u32;
- typedef signed char s8;
- typedef signed short s16;
- typedef signed long s32;
- // (These should be analogous
- // to their signed counterparts)
- typedef char i8;
- typedef short i16;
- typedef long i32;
- typedef float f32;
- #define false 0
- #define true 1
- typedef u8 bool;
- typedef u8 byte;
- #ifndef _SIZE_T
- #define _SIZE_T
- typedef u32 size_t;
- #endif
- typedef struct KIT_bpoint { s8 x, y; } KIT_bpoint;
- typedef struct KIT_brect { s8 x, y, w, h; } KIT_brect;
- typedef struct KIT_bline { s8 x0, y0, x1, y1; } KIT_bline;
- typedef struct KIT_bcircle { s8 x, y, r; } KIT_bcircle;
- typedef struct KIT_bpoint3d { s8 x, y, z; } KIT_bpoint3d;
- typedef struct KIT_spoint { s16 x, y; } KIT_spoint;
- typedef struct KIT_srect { s16 x, y, w, h; } KIT_srect;
- typedef struct KIT_sline { s16 x0, y0, x1, y1; } KIT_sline;
- typedef struct KIT_scircle { s16 x, y, r; } KIT_scircle;
- typedef struct KIT_spoint3d { s16 x, y, z; } KIT_spoint3d;
- typedef struct KIT_point { s32 x, y; } KIT_point;
- typedef struct KIT_rect { s32 x, y, w, h; } KIT_rect;
- typedef struct KIT_line { s32 x0, y0, x1, y1; } KIT_line;
- typedef struct KIT_circle { s32 x, y, r; } KIT_circle;
- typedef struct KIT_point3d { s32 x, y, z; } KIT_point3d;
- typedef struct KIT_fpoint { f32 x, y; } KIT_fpoint;
- typedef struct KIT_frect { f32 x, y, w, h; } KIT_frect;
- typedef struct KIT_fline { f32 x0, y0, x1, y1; } KIT_fline;
- typedef struct KIT_fcircle { f32 x, y, r; } KIT_fcircle;
- typedef struct KIT_fpoint3d { f32 x, y, z; } KIT_fpoint3d;
- // Turns a byte into an integer that is printf'able
- // as a base 2 number with the format specifier "%08X".
- // (This is assuming you're able to print longs with "%X"!)
- #define bin_hex(n) \
- ( \
- (n&128) << 21 |\
- (n& 64) << 18 |\
- (n& 32) << 15 |\
- (n& 16) << 12 |\
- (n& 8) << 9 |\
- (n& 4) << 6 |\
- (n& 2) << 3 |\
- (n& 1) \
- )
- #define VGA_FAR_PTR ((byte far*)0xA0000000L)
- // (Including the entirety of stdio
- // just for this is unnecessarily slow,
- // even on a RAM disk!)
- int printf(const char* fmt, ...);
- #endif // _KIT_ALL_H
- /******************************************************************************/
- /******************************************************************************/
- //"VGA_stuff_2025-05-22\INCLUDE\DRAW.H":
- #ifndef _DRAW_H
- #define _DRAW_H
- #include "C:/home/kit_all.h"
- #define RGB_U8(r3,g3,b2) ((u8)((r3)<<5 | (g3)<<2 | (b2)))
- #define RGB_U32(r8,g8,b8) ((u32)((u32)(r8)<<16 | (u16)(g8)<<8 | (b8)))
- typedef union Color8 {
- u8 v;
- struct {
- u8 b : 2;
- u8 g : 3;
- u8 r : 3;
- } c;
- } Color8;
- typedef union Color24 {
- u32 v;
- struct {
- u8 b : 8;
- u8 g : 8;
- u8 r : 8;
- u8 _ : 8;
- } c;
- } Color24;
- void draw_line( s32 x_0, s32 y_0,
- const s32 x_1, const s32 y_1,
- const byte color);
- // height is a multiplier, from 0.0f -> 1.0f
- void draw_column(u16 x, f32 height, byte color);
- void fill_scanlines(u16 y, u16 len, byte color);
- KIT_fpoint create_vec2(f32 angleRads, f32 magnitude); // In "RCST_SCN.C"
- void draw_raycast_scene(const s8* map, s16 map_w, s16 map_h,
- KIT_fpoint3d pos, // (pos.z is the angle in rads)
- const byte* tiles, // should be 128 in length
- byte colorFloor, byte colorCeiling,
- u16 renderDistance, f32 fov);
- #endif // _DRAW_H
- /******************************************************************************/
- /******************************************************************************/
- //"VGA_stuff_2025-05-22\INCLUDE\HARDWARE.H":
- #ifndef _HARDWARE_H
- #define _HARDWARE_H
- #include "draw.h"
- extern byte far * const VGA;
- byte setVideoMode(byte new_mode);
- Color24 getPaletteColor(byte which);
- void setPaletteColor(byte which, u32 rgb);
- u16 readPIT_Ch0(void);
- #endif // _HARDWARE_H
- /******************************************************************************/
- /******************************************************************************/
- //"VGA_stuff_2025-05-22\INCLUDE\KIT_STD.H":
- #ifndef _KIT_STD_H
- #define _KIT_STD_H
- #include "C:/home/kit_all.h"
- long int KIT_labs(long int n);
- float KIT_fabsf(float x);
- // (Doesn't work on far pointers!)
- void* KIT_memset(void* dst, int val, size_t len);
- #define KIT_rand() ((int)KIT_lrand())
- void KIT_srand(long int seed);
- long int KIT_lrand(void);
- float KIT_fmodf(float x, float y);
- #define KIT_cosf(x) KIT_sinf((x)+M_PI2f)
- #define KIT_tanf(x) ( KIT_sinf(x)/KIT_cosf(x) )
- float KIT_sinf(float x);
- #endif // _KIT_STD_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement