Friday, August 28, 2020

Asteroid Game

Screenshot of the remake of the classic game Asteroid with SDL2 in pure C.

[+] Code:
First commit and subsequent development: 

[+] Game Structure:






Monday, August 6, 2018

One version of kbhit() using windows API


Here is one version of kbhit() using windows API (GetAsyncKeyState). It runs through 255 possible key scancodes in pulses. If a key is pressed, it returns 1 and the value of the key pressed by reference.
This can be used to make a rudimentary keylogger in Windows.
Proof of concept:  Keylogger Source code

#include <windows.h>
Prototype: int kbhit(char *ch); 
Call:
int keypressed=0;
char ch=0;

keypressed = kbhit(&ch);







Saturday, July 21, 2018

Listing files recursively in C in a menu with scroll.


One of the most complex programs I've ever written which makes use of my latest development with list boxes in C. You can navigate and change path while the different files and directories in the new path are added to the dynamic list for scroll.


>> SOURCE CODE <<

Saturday, July 14, 2018

Segmentation Fault - C Pointers


Segmentation Fault!!!

I have seen this phrase so many times I may end up having nightmares with it. But I got there in the end!! In my experience,  it seems the only way to learn how to use pointers properly is through trial and error. :D

This time I've used them to develop a ListBox in C with scroll capabilities.
As usual you can find it in my github repository. (Code available for Linux, Windows and DOS).

Cheers!

Demo:



Sunday, March 4, 2018

C-Edit (In progress)


I'm working on developing an editor in C for Linux in the fashion of the old MS-DOS edit.com.
Features (so far):

  • Double screen buffer in memory for greater display control.
  • ANSI functions for changing color output, hide cursor, box-like characters, etc.
  • No Ncurses. 
  • Kbhit() so that I can loop without stopping the program (eg: display current time).
  • Drop-down menus with a circular linked list.

You can find it on my Github Page. Screen caps:




Sunday, September 24, 2017

A Very Simple Double Screen Buffer

The reason for creating a screen buffer is to have greater control over how things are displayed on  screen. It acts as an 'intermediary' step in memory before printing the final result to the terminal. If you have another copy of the buffer in memory, you can revert to previous stages.
Imagine you want to display a window to the user. Before doing so, you push the current screen to the old buffer. You show the new screen with the window on it and finally you pop or recover the previous screen from the old buffer. If you just update to screen the characters that have changed you can avoid any flickering effects that will come about by updating the whole screen every time.

In the old days of DOS, this could be achieved by accessing an absolute address in memory $B800:$0000.

[Old buffer] ----> [Current Buffer] -----> [Final Display]

To create the buffer, we need to know the terminal dimensions in rows and columns. (See previous post). Because the terminal dimensions vary, we cannot predict before execution how large the buffer will be. That's why we need a dynamic structure in memory. My version uses a single linked list composed of cells. Each cell accounts for every 'pixel' on screen and records some attributes in a structure form -  namely, the character to be displayed along with its background and foreground colors. The size of our list will be determined by rows x columns. This representation in memory of the screen will need subroutines to control the display. Everything you want to show on screen will be printed to the buffer first. Then the update routine will finally show the final composition to the user. An additional buffer, called old_buffer, will help us revert to previous screens so as to show, for instance, a window area to the user and then closing it without affecting the text or screen portion that was behind it prior to the window being shown. The next step will be to create dynamic windows that store the information behind them in their structure. 


Structure detail + Screen caps:


















Dropdown menu in text-mode/terminal coded in C for linux.
Source code:
https://mega.nz/file/cP1ABB5Z#IgZ2C-rR8R6Tw3LoLao8EMJbaIXTkKjNvrQk3KEpajw

Instructions: Download, uncompress and type make to build. Execute: ./test1

Saturday, September 23, 2017

YET MORE ANSI FUNCTIONS + TERMINAL DIMENSIONS


I'm working on creating a double screen buffer in C to have greater control of the display on the terminal. In the meantime, more useful functions useful to that end. :)

Show/Hide cursor:
void hide_cursor()
{
  printf("\e[?25l");
}

void show_cursor()
{
  printf("\e[?25h");
}

Draw box-like characters on Linux Terminal:
ASCII characters change from 106 to 121.
printf("%c(0", 0x1b); // Border chars on
printf("%c(B", 0x1b); // border chars off

Get Terminal Dimensions:

#include <sys/ioctl.h>
#include <stdio.h>

struct winsize max;
int get_terminal_dimensions(int *rows, int *columns)
{
//Get dimensions of screen and pass them by value.
  ioctl(0, TIOCGWINSZ , &max);
  *columns = max.ws_col;
  *rows = max.ws_row;
   return 0;
}