Files
csteroids/crt.h

75 lines
1.9 KiB
C++

#pragma once
#include <cstdint>
#include <math.h>
#include <SDL2/SDL.h>
#define pi 3.141592653589793
// Tipos de Pascal
typedef double real;
typedef int integer;
typedef unsigned char byte;
typedef bool boolean;
typedef uint16_t word;
byte video[38400];
SDL_Window *sdlWindow;
SDL_Renderer *sdlRenderer;
SDL_Texture *sdlTexture;
SDL_Event sdlEvent;
Uint32 *pixels;
int pitch;
bool eixir = false;
void randomize() {
srand(SDL_GetTicks());
}
float random(int x) {
return float(rand() % x);
}
void mcga() {
SDL_Init(SDL_INIT_EVERYTHING);
sdlWindow = SDL_CreateWindow("Asteroids", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_PRESENTVSYNC);
sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, 640, 480);
}
void text() {
SDL_Quit();
}
bool shouldexit() { return eixir; }
void waitretrace() {
while (SDL_PollEvent(&sdlEvent)) {
if (sdlEvent.type == SDL_QUIT) { eixir = true; }
}
SDL_LockTexture(sdlTexture, NULL, (void**)&pixels, &pitch);
int pos=0;
for (int y=0; y<480;y++) {
for (int x=0; x<80;x++) {
pixels[pos++] = ((video[y*80+x]>>7)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x]>>6)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x]>>5)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x]>>4)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x]>>3)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x]>>2)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x]>>1)&1)?0xffffffff:0x000000ff;
pixels[pos++] = ((video[y*80+x] )&1)?0xffffffff:0x000000ff;
}
}
SDL_UnlockTexture(sdlTexture);
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
SDL_RenderPresent(sdlRenderer);
}
void gotoxy(int x, int y) {
}
void write(const char* text) {
}