Skip to content

Instantly share code, notes, and snippets.

@skeeto
Created September 5, 2025 01:53
Show Gist options
  • Save skeeto/0785c565a73f0f2a366f2ca7bd94d377 to your computer and use it in GitHub Desktop.
Save skeeto/0785c565a73f0f2a366f2ca7bd94d377 to your computer and use it in GitHub Desktop.
--- a/SRC/IO.H
+++ b/SRC/IO.H
@@ -3,3 +3,3 @@
-#include <_defs.h>
+//#include <_defs.h>
--- a/SRC/PSYMANDL.C
+++ b/SRC/PSYMANDL.C
@@ -1,4 +1,4 @@
-#include "vga.h"
-#include "keybrd.h"
-#include "io.h"
+#include "VGA.H"
+#include "KEYBRD.H"
+#include "IO.H"
--- a/SRC/VGA.H
+++ b/SRC/VGA.H
@@ -3,3 +3,3 @@
-#include <_defs.h>
+//#include <_defs.h>
// VGA GFX Mode
// $ eval cc main.c $(pkg-config --cflags --libs sdl2)
#define _Cdecl
#undef main // undo SDL_main from pkg-config
#define main appmain
#include "SRC/PSYMANDL.C"
#undef main
#include "SDL.h"
static SDL_Window *window;
static SDL_Renderer *renderer;
static SDL_Texture *texture;
static Uint8 vga[200][320];
static Sint32 palette_index;
static Sint32 palette[256];
void _setMode(int)
{
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(
"psymandl",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
320, 200, 0
);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC);
texture = SDL_CreateTexture(
renderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
320, 200
);
}
void _putpixel(int x, int y, char color)
{
vga[y][x] = color & 255;
}
void _outp(unsigned port, int value)
{
switch (port) {
case DAC_INDEX: palette_index = value;
break;
case DAC_DATA: int i = palette_index++;
int s = 16 - i % 3 * 8;
palette[i/3] &= ~(0xff << s);
palette[i/3] |= (value*4) << s;
break;
}
}
void _waitvretrace(void)
{
Sint32 buf[320*200];
for (int y = 0; y < 200; y++) {
for (int x = 0; x < 320; x++) {
Sint32 rgb = palette[vga[y][x]];
buf[y*320 + x] = rgb;
}
}
SDL_UpdateTexture(texture, 0, buf, 320*sizeof(Sint32));
SDL_RenderCopy(renderer, texture, 0, 0);
SDL_RenderPresent(renderer);
}
void kbInit(void) {}
void kbExit(void) {}
int kbHit(KeyCode c)
{
for (SDL_Event e = {0}; SDL_PollEvent(&e);) {
switch (e.type) {
case SDL_QUIT: return 1;
}
}
return 0;
}
int main(int, char **)
{
appmain();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment