My try at a SCREEN$ reader in SDL

Using dev++ in windoze
This commit is contained in:
Pedro de Oliveira 2014-08-31 04:24:01 +01:00
parent 26fef9a741
commit f7ef032910
9 changed files with 283 additions and 1 deletions

4
.gitignore vendored
View File

@ -1 +1,3 @@
*.tap
*.tap
*.o
*.exe

BIN
zxscr/MagiclandDizzy.scr Normal file

Binary file not shown.

33
zxscr/Makefile.win Normal file
View File

@ -0,0 +1,33 @@
# Project: zxscr
# Makefile created by Dev-C++ 4.9.9.2
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
RES = zxscr_private.res
OBJ = main.o $(RES)
LINKOBJ = main.o $(RES)
LIBS = -L"C:/Dev-Cpp/lib" -mwindows -lmingw32 -lSDLmain -lSDL
INCS = -I"C:/Dev-Cpp/include"
CXXINCS = -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
BIN = zxscr.exe
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS) -Dmain=SDL_main
RM = rm -f
.PHONY: all all-before all-after clean clean-custom
all: all-before zxscr.exe all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CC) $(LINKOBJ) -o "zxscr.exe" $(LIBS)
main.o: main.c
$(CC) -c main.c -o main.o $(CFLAGS)
zxscr_private.res: zxscr_private.rc
$(WINDRES) -i zxscr_private.rc --input-format=rc -o zxscr_private.res -O coff

159
zxscr/main.c Normal file
View File

@ -0,0 +1,159 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SDL/SDL.h>
#include <windows.h>
#define READ_BIT(x,n) (x>>n)&1
/* The screen surface */
SDL_Surface *screen = NULL;
#define BUFFER_SIZE 32
unsigned char buffer[192][BUFFER_SIZE];
int order[191] = {
0, 8, 16, 24, 32, 40, 48, 56,
1, 9, 17, 25, 33, 41, 49, 57,
2, 10, 18, 26, 34, 42, 50, 58,
3, 11, 19, 27, 35, 43, 51, 59,
4, 12, 20, 28, 36, 44, 52, 60,
5, 13, 21, 29, 37, 45, 53, 61,
6, 14, 22, 30, 38, 46, 54, 62,
7, 15, 23, 31, 39, 47, 55, 63,
// 64, 72, 80, 88, 96, 104, 112, 120,
// 65, 73, 81, 89, 97, 105, 113, 121,
// 66, 74, 82, 90, 98, 106, 114, 122,
// 67, 75, 83, 91, 99, 107, 115, 123,
};
//int order[191];
int pos = 0;
void add_item(int item)
{
order[pos] = item;
pos++;
}
void set_order() {
int i,z;
// First third of the screen
for (i = 0; i <= 7; i++) {
for (z = 0; z <= 7; z++) {
add_item(i + z*8);
}
}
// Second third of the screen
for (i = 65; i <= 72; i++) {
for (z = 0; z <= 7; z++) {
add_item(i + z*8);
}
}
}
/* This function draws to the screen; replace this with your own code! */
static void
draw ()
{
SDL_Rect rect;
Uint32 color;
int b,i,z,y;
unsigned char c;
/* Create a black background */
color = SDL_MapRGB (screen->format, 0, 0, 0);
SDL_FillRect (screen, NULL, color);
color = SDL_MapRGB (screen->format, 255, 255, 255);
for (b = 0; b <= 191; b++) { // Y
y = order[b];
for (i = 0; i <= 31; i++) { // X
c = buffer[y][i];
for (z = 7; z >= 0; z--) { // Position in X byte
if (READ_BIT(c,z)) {
rect.w = 1;
rect.h = 1;
rect.x = (i*8-z)+8;
rect.y = b;
SDL_FillRect (screen, &rect, color);
}
}
}
}
/* Make sure everything is displayed on screen */
SDL_Flip (screen);
}
int
main (int argc, char *argv[])
{
char *msg;
int done;
int i;
FILE *file_ptr;
/* Initialize SDL */
if (SDL_Init (SDL_INIT_VIDEO) < 0)
{
sprintf (msg, "Couldn't initialize SDL: %s\n", SDL_GetError ());
MessageBox (0, msg, "Error", MB_ICONHAND);
free (msg);
exit (1);
}
atexit (SDL_Quit);
/* Set 640x480 16-bits video mode */
screen = SDL_SetVideoMode (640, 480, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
if (screen == NULL)
{
sprintf (msg, "Couldn't set 640x480x16 video mode: %s\n",
SDL_GetError ());
MessageBox (0, msg, "Error", MB_ICONHAND);
free (msg);
exit (2);
}
SDL_WM_SetCaption ("SDL MultiMedia Application", NULL);
file_ptr = fopen("MagiclandDizzy.scr", "r");
for(i = 0; i <= 192; i++) {
fread(buffer[i], sizeof(unsigned char), BUFFER_SIZE, file_ptr);
}
//set_order();
done = 0;
while (!done)
{
SDL_Event event;
/* Check for events */
while (SDL_PollEvent (&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
break;
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}
/* Draw to screen */
draw ();
}
return 0;
}

59
zxscr/zxscr.dev Normal file
View File

@ -0,0 +1,59 @@
[Project]
FileName=zxscr.dev
Name=zxscr
UnitCount=1
Type=0
Ver=1
ObjFiles=
Includes=
Libs=
PrivateResource=
ResourceIncludes=
MakeIncludes=
Compiler=-Dmain=SDL_main
CppCompiler=
Linker=-lmingw32 -lSDLmain -lSDL
IsCpp=0
Icon=zxscr.ico
ExeOutput=
ObjectOutput=
OverrideOutput=0
OverrideOutputName=
HostApplication=
Folders=
CommandLine=
UseCustomMakefile=0
CustomMakefile=
IncludeVersionInfo=0
SupportXPThemes=0
CompilerSet=0
CompilerSettings=
[Unit1]
FileName=main.c
CompileCpp=0
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[VersionInfo]
Major=0
Minor=1
Release=1
Build=1
LanguageID=1033
CharsetID=1252
CompanyName=
FileVersion=
FileDescription=Developed using the Dev-C++ IDE
InternalName=
LegalCopyright=
LegalTrademarks=
OriginalFilename=
ProductName=
ProductVersion=
AutoIncBuildNr=0

BIN
zxscr/zxscr.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

23
zxscr/zxscr_private.h Normal file
View File

@ -0,0 +1,23 @@
/* THIS FILE WILL BE OVERWRITTEN BY DEV-C++ */
/* DO NOT EDIT ! */
#ifndef ZXSCR_PRIVATE_H
#define ZXSCR_PRIVATE_H
/* VERSION DEFINITIONS */
#define VER_STRING "0.1.1.1"
#define VER_MAJOR 0
#define VER_MINOR 1
#define VER_RELEASE 1
#define VER_BUILD 1
#define COMPANY_NAME ""
#define FILE_VERSION ""
#define FILE_DESCRIPTION "Developed using the Dev-C++ IDE"
#define INTERNAL_NAME ""
#define LEGAL_COPYRIGHT ""
#define LEGAL_TRADEMARKS ""
#define ORIGINAL_FILENAME ""
#define PRODUCT_NAME ""
#define PRODUCT_VERSION ""
#endif /*ZXSCR_PRIVATE_H*/

6
zxscr/zxscr_private.rc Normal file
View File

@ -0,0 +1,6 @@
/* THIS FILE WILL BE OVERWRITTEN BY DEV-C++ */
/* DO NOT EDIT! */
A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "zxscr.ico"

BIN
zxscr/zxscr_private.res Normal file

Binary file not shown.