(It doesn't quite work properly.)
CC = gcc
WARNINGS = -Wall -Wextra -pedantic
CFLAGS = $(WARNINGS) -march=armv7 -O3
CC = gcc
WARNINGS = -Wall -Wextra -pedantic
CFLAGS = $(WARNINGS) -march=armv7 -O3
-LFLAGS = $(WARNINGS) -lSDL2
+LFLAGS = $(WARNINGS) `sdl2-config --libs`
TARGET = $(EXENAME)$(EXE)
TARGET = $(EXENAME)$(EXE)
printf("Failed to open keyboard event source.\n");
}
printf("Failed to open keyboard event source.\n");
}
- sched_setscheduler(0, SCHED_FIFO, &priority);
- mlockall(MCL_CURRENT); // lock in memory to keep us from paging out
-
InitGayle();
signal(SIGINT, sigint_handler);
InitGayle();
signal(SIGINT, sigint_handler);
#include <SDL2/SDL.h>
#include <stdio.h>
#include <stdint.h>
#include <SDL2/SDL.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <pthread.h>
#include <unistd.h>
#include <pthread.h>
+#include <string.h>
+#include "rtg.h"
#define RTG_INIT_ERR(a) { printf(a); *data->running = 0; }
#define RTG_INIT_ERR(a) { printf(a); *data->running = 0; }
-uint8_t busy = 0, rtg_on = 0;
+uint8_t busy = 0, rtg_on = 0, rtg_initialized = 0;
extern uint8_t *rtg_mem;
extern uint32_t framebuffer_addr;
extern uint8_t *rtg_mem;
extern uint32_t framebuffer_addr;
SDL_Texture *img = NULL;
struct rtg_shared_data rtg_share_data;
SDL_Texture *img = NULL;
struct rtg_shared_data rtg_share_data;
+static uint32_t palette[256];
void rtg_update_screen() {}
void rtg_update_screen() {}
+uint32_t rtg_to_sdl2[RTGFMT_NUM] = {
+ SDL_PIXELFORMAT_BGRA8888,
+ SDL_PIXELFORMAT_RGB565,
+ SDL_PIXELFORMAT_BGRA8888,
+ SDL_PIXELFORMAT_RGB555,
+};
+
void *rtgThread(void *args) {
printf("RTG thread running\n");
fflush(stdout);
void *rtgThread(void *args) {
printf("RTG thread running\n");
fflush(stdout);
+ uint32_t *indexed_buf;
+
rtg_share_data.format = &rtg_display_format;
rtg_share_data.width = &rtg_display_width;
rtg_share_data.height = &rtg_display_height;
rtg_share_data.format = &rtg_display_format;
rtg_share_data.width = &rtg_display_width;
rtg_share_data.height = &rtg_display_height;
rtg_share_data.addr = &framebuffer_addr;
struct rtg_shared_data *data = &rtg_share_data;
rtg_share_data.addr = &framebuffer_addr;
struct rtg_shared_data *data = &rtg_share_data;
+ uint16_t width = rtg_display_width;
+ uint16_t height = rtg_display_height;
+ uint16_t format = rtg_display_format;
+ uint16_t pitch = rtg_pitch;
+
printf("Initializing SDL2...\n");
if (SDL_Init(0) < 0) {
printf("Failed to initialize SDL2.\n");
printf("Initializing SDL2...\n");
if (SDL_Init(0) < 0) {
printf("Failed to initialize SDL2.\n");
printf("Failed to initialize SDL2 Video..\n");
}
printf("Failed to initialize SDL2 Video..\n");
}
- printf("Creating %dx%d SDL2 window...\n", *data->width, *data->height);
- win = SDL_CreateWindow("Pistorm RTG", 0, 0, *data->width, *data->height, 0);
+reinit_sdl:;
+ if (reinit) {
+ printf("Reinitializing SDL2...\n");
+ width = rtg_display_width;
+ height = rtg_display_height;
+ format = rtg_display_format;
+ pitch = rtg_pitch;
+ if (indexed_buf) {
+ free(indexed_buf);
+ indexed_buf = NULL;
+ }
+ reinit = 0;
+ }
+
+ printf("Creating %dx%d SDL2 window...\n", width, height);
+ win = SDL_CreateWindow("Pistorm RTG", 0, 0, width, height, 0);
if (!win) {
RTG_INIT_ERR("Failed create SDL2 window.\n");
}
else {
if (!win) {
RTG_INIT_ERR("Failed create SDL2 window.\n");
}
else {
- printf("Created %dx%d window.\n", *data->width, *data->height);
+ printf("Created %dx%d window.\n", width, height);
}
printf("Creating SDL2 renderer...\n");
}
printf("Creating SDL2 renderer...\n");
}
printf("Creating SDL2 texture...\n");
}
printf("Creating SDL2 texture...\n");
- img = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_TARGET, *data->width, *data->height);
+ img = SDL_CreateTexture(renderer, rtg_to_sdl2[format], SDL_TEXTUREACCESS_TARGET, width, height);
if (!img) {
RTG_INIT_ERR("Failed create SDL2 texture.\n");
}
else {
if (!img) {
RTG_INIT_ERR("Failed create SDL2 texture.\n");
}
else {
- printf("Created %dx%d texture.\n", *data->width, *data->height);
+ printf("Created %dx%d texture.\n", width, height);
+ }
+
+ if (format == RTGFMT_8BIT) {
+ indexed_buf = calloc(1, width * height * 4);
+ pitch = width * 4;
}
while (1) {
if (renderer && win && img) {
}
while (1) {
if (renderer && win && img) {
- SDL_UpdateTexture(img, NULL, &data->memory[*data->addr + (*data->offset_x << *data->format) + (*data->offset_y * *data->pitch)], *data->pitch);
SDL_RenderClear(renderer);
SDL_RenderClear(renderer);
- SDL_RenderCopy(renderer, img, NULL, NULL);
+ if (*data->running) {
+ SDL_UpdateTexture(img, NULL, (format != RTGFMT_8BIT) ? &data->memory[*data->addr] : (uint8_t *)indexed_buf, pitch);
+ SDL_RenderCopy(renderer, img, NULL, NULL);
+ }
SDL_RenderPresent(renderer);
usleep(16667); //ghetto 60hz
SDL_RenderPresent(renderer);
usleep(16667); //ghetto 60hz
+ if (height != *data->height || width != *data->width || format != *data->format) {
+ printf("Reinitializing due to something change.\n");
+ reinit = 1;
+ goto shutdown_sdl;
+ }
+ if (format == RTGFMT_8BIT) {
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ indexed_buf[x + (y * width)] = palette[data->memory[*data->addr + x + (y * width)]];
+ }
+ }
+ }
printf("RTG thread shut down.\n");
printf("RTG thread shut down.\n");
+shutdown_sdl:;
+ if (img) SDL_DestroyTexture(img);
+ if (renderer) SDL_DestroyRenderer(renderer);
+ if (win) SDL_DestroyWindow(win);
+
+ win = NULL;
+ img = NULL;
+ renderer = NULL;
+
+ if (reinit)
+ goto reinit_sdl;
+
+ SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ SDL_Quit();
+
return args;
}
void rtg_set_clut_entry(uint8_t index, uint8_t r, uint8_t g, uint8_t b) {
return args;
}
void rtg_set_clut_entry(uint8_t index, uint8_t r, uint8_t g, uint8_t b) {
+ //int r = (int)((float)rtg_u8[1] / 255.0f * 31.0f);
+ //int g = (int)((float)rtg_u8[2] / 255.0f * 63.0f);
+ //int b = (int)((float)rtg_u8[3] / 255.0f * 31.0f);
+ palette[index] = (r << 24) | (g << 16) | (b << 8) | 0xFF;
}
void rtg_init_display() {
int err;
rtg_on = 1;
}
void rtg_init_display() {
int err;
rtg_on = 1;
- err = pthread_create(&thread_id, NULL, &rtgThread, (void *)&rtg_share_data);
- if (err != 0) {
- rtg_on = 0;
- printf("can't create RTG thread :[%s]", strerror(err));
- }
- else {
- printf("RTG Thread created successfully\n");
- printf("RTG display enabled.\n");
+ if (!rtg_initialized) {
+ err = pthread_create(&thread_id, NULL, &rtgThread, (void *)&rtg_share_data);
+ if (err != 0) {
+ rtg_on = 0;
+ printf("can't create RTG thread :[%s]", strerror(err));
+ }
+ else {
+ rtg_initialized = 1;
+ printf("RTG Thread created successfully\n");
+ }
+ printf("RTG display enabled.\n");
}
void rtg_shutdown_display() {
printf("RTG display disabled.\n");
rtg_on = 0;
}
void rtg_shutdown_display() {
printf("RTG display disabled.\n");
rtg_on = 0;
-
- if (img) SDL_DestroyTexture(img);
- if (renderer) SDL_DestroyRenderer(renderer);
- if (win) SDL_DestroyWindow(win);
#include "rtg.h"
#include "../../../config_file/config_file.h"
#include "rtg.h"
#include "../../../config_file/config_file.h"
-static uint16_t palette[256];
-
static uint8_t rtg_u8[4];
static uint16_t rtg_x[3], rtg_y[3];
static uint16_t rtg_format;
static uint32_t rtg_address[2];
static uint32_t rtg_rgb[2];
static uint8_t rtg_u8[4];
static uint16_t rtg_x[3], rtg_y[3];
static uint16_t rtg_format;
static uint32_t rtg_address[2];
static uint32_t rtg_rgb[2];
-static uint8_t display_enabled;
+static uint8_t display_enabled = 0xFF;
uint16_t rtg_display_width, rtg_display_height;
uint16_t rtg_display_format;
uint16_t rtg_display_width, rtg_display_height;
uint16_t rtg_display_format;
return (rtg_mem[address - PIGFX_REG_SIZE]);
break;
case OP_TYPE_WORD:
return (rtg_mem[address - PIGFX_REG_SIZE]);
break;
case OP_TYPE_WORD:
- return *(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE]));
+ return be16toh(*(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE])));
break;
case OP_TYPE_LONGWORD:
break;
case OP_TYPE_LONGWORD:
- return *(( uint32_t *) (&rtg_mem[address - PIGFX_REG_SIZE]));
+ return be32toh(*(( uint32_t *) (&rtg_mem[address - PIGFX_REG_SIZE])));
break;
default:
return 0;
break;
default:
return 0;
rtg_mem[address - PIGFX_REG_SIZE] = value;
break;
case OP_TYPE_WORD:
rtg_mem[address - PIGFX_REG_SIZE] = value;
break;
case OP_TYPE_WORD:
- *(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = value;
+ *(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = htobe16(value);
break;
case OP_TYPE_LONGWORD:
break;
case OP_TYPE_LONGWORD:
- *(( uint32_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = value;
+ *(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE] + 2)) = htobe16(value & 0xFFFF);
+ *(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = htobe16((value >> 16));
+ //*(( uint32_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = htobe32(value);
- if (rtg_on) {
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &f2);
- if (diff(f1,f2).tv_nsec / 1000000.0 > 100.00) {
- rtg_update_screen();
- f1 = f2;
- }
- }
-
rtg_pitch = rtg_x[1];
rtg_total_rows = rtg_y[1];
}
rtg_pitch = rtg_x[1];
rtg_total_rows = rtg_y[1];
}
- //printf("Set RTG mode:\n");
- //printf("%dx%d pixels\n", rtg_display_width, rtg_display_height);
- //printf("Pixel format: %s\n", rtg_format_names[rtg_display_format]);
+ printf("Set RTG mode:\n");
+ printf("%dx%d pixels\n", rtg_display_width, rtg_display_height);
+ printf("Pixel format: %s\n", rtg_format_names[rtg_display_format]);
break;
case RTGCMD_SETPAN:
//printf("Command: SetPan.\n");
break;
case RTGCMD_SETPAN:
//printf("Command: SetPan.\n");
- framebuffer_addr = rtg_address[0] - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
rtg_offset_x = rtg_x[1];
rtg_offset_y = rtg_y[1];
rtg_pitch = (rtg_x[0] << rtg_display_format);
rtg_offset_x = rtg_x[1];
rtg_offset_y = rtg_y[1];
rtg_pitch = (rtg_x[0] << rtg_display_format);
- //printf("Set panning to $%.8X\n", framebuffer_addr);
- //printf("Offset X/Y: %d/%d\n", rtg_offset_x, rtg_offset_y);
- //printf("Pitch: %d (%d bytes)\n", rtg_x[0], rtg_pitch);
+ framebuffer_addr = rtg_address[0] - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
+ framebuffer_addr += (rtg_offset_x << rtg_display_format) + (rtg_offset_y * rtg_pitch);
+ printf("Set panning to $%.8X\n", framebuffer_addr);
+ printf("Offset X/Y: %d/%d\n", rtg_offset_x, rtg_offset_y);
+ printf("Pitch: %d (%d bytes)\n", rtg_x[0], rtg_pitch);
break;
case RTGCMD_SETCLUT: {
//printf("Command: SetCLUT.\n");
break;
case RTGCMD_SETCLUT: {
//printf("Command: SetCLUT.\n");
- //printf("Set palette entry %d to %d, %d, %d\n", rtg_u8[0], rtg_u8[1], rtg_u8[2], rtg_u8[3]);
- /*int r = (int)((float)rtg_u8[1] / 255.0f * 31.0f);
- int g = (int)((float)rtg_u8[2] / 255.0f * 63.0f);
- int b = (int)((float)rtg_u8[3] / 255.0f * 31.0f);
- palette[rtg_u8[0]] = ((r & 0x1F) << 11) | ((g & 0x3F) << 6) | (b & 0x1F);*/
+ printf("Set palette entry %d to %d, %d, %d\n", rtg_u8[0], rtg_u8[1], rtg_u8[2], rtg_u8[3]);
rtg_set_clut_entry(rtg_u8[0], rtg_u8[1], rtg_u8[2], rtg_u8[3]);
break;
}
case RTGCMD_SETDISPLAY:
rtg_set_clut_entry(rtg_u8[0], rtg_u8[1], rtg_u8[2], rtg_u8[3]);
break;
}
case RTGCMD_SETDISPLAY:
+ //printf("RTG SetDisplay %s\n", (rtg_u8[1]) ? "enabled" : "disabled");
// I remeber wrongs.
//printf("Command: SetDisplay.\n");
break;
case RTGCMD_ENABLE:
case RTGCMD_SETSWITCH:
// I remeber wrongs.
//printf("Command: SetDisplay.\n");
break;
case RTGCMD_ENABLE:
case RTGCMD_SETSWITCH:
- if (display_enabled != rtg_u8[1]) {
- //printf("RTG Display %s\n", (rtg_u8[1]) ? "enabled" : "disabled");
- display_enabled = rtg_u8[1];
+ printf("RTG SetSwitch %s\n", ((rtg_x[0]) & 0x01) ? "enabled" : "disabled");
+ printf("LAL: %.4X\n", rtg_x[0]);
+ if (display_enabled != ((rtg_x[0]) & 0x01)) {
+ display_enabled = ((rtg_x[0]) & 0x01);
if (display_enabled) {
rtg_init_display();
if (display_enabled) {
rtg_init_display();
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &f1);
}
else
rtg_shutdown_display();
}
else
rtg_shutdown_display();
}
void rtg_fillrect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color, uint16_t pitch, uint16_t format, uint8_t mask) {
}
void rtg_fillrect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color, uint16_t pitch, uint16_t format, uint8_t mask) {
+ if (mask || pitch) {}
+ uint8_t *dptr = &rtg_mem[framebuffer_addr + (x << format) + (y * rtg_pitch)];
+ case RTGFMT_8BIT: {
+ for (int xs = 0; xs < w; xs++) {
+ dptr[xs] = color & 0xFF;
+ }
- uint16_t *ptr = (uint16_t *)&rtg_mem[framebuffer_addr + (x << format) + (y * pitch)];
+ uint16_t *ptr = (uint16_t *)dptr;
for (int xs = 0; xs < w; xs++) {
for (int xs = 0; xs < w; xs++) {
- ptr[xs] = (color >> 16);
- }
- for (int ys = 1; ys < h; ys++) {
- ptr += (rtg_pitch >> format);
- memcpy(ptr, (void *)(size_t)(ptr - (rtg_pitch >> format)), rtg_pitch);
+ ptr[xs] = (color & 0xFFFF);
+ case RTGFMT_RGB32: {
+ uint32_t *ptr = (uint32_t *)dptr;
+ for (int xs = 0; xs < w; xs++) {
+ ptr[xs] = color;
+ }
+ }
+ }
+ for (int ys = 1; ys < h; ys++) {
+ dptr += rtg_pitch;
+ memcpy(dptr, (void *)(size_t)(dptr - rtg_pitch), (w << format));
void SetGC (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(BOOL border));
void SetColorArray (__REGA0(struct BoardInfo *b), __REGD0(UWORD start), __REGD1(UWORD num));
void SetPanning (__REGA0(struct BoardInfo *b), __REGA1(UBYTE *addr), __REGD0(UWORD width), __REGD1(WORD x_offset), __REGD2(WORD y_offset), __REGD7(RGBFTYPE format));
void SetGC (__REGA0(struct BoardInfo *b), __REGA1(struct ModeInfo *mode_info), __REGD0(BOOL border));
void SetColorArray (__REGA0(struct BoardInfo *b), __REGD0(UWORD start), __REGD1(UWORD num));
void SetPanning (__REGA0(struct BoardInfo *b), __REGA1(UBYTE *addr), __REGD0(UWORD width), __REGD1(WORD x_offset), __REGD2(WORD y_offset), __REGD7(RGBFTYPE format));
-BOOL SetSwitch (__REGA0(struct BoardInfo *b), __REGD0(BOOL enabled));
-BOOL SetDisplay (__REGA0(struct BoardInfo *b), __REGD0(BOOL enabled));
+UWORD SetSwitch (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled));
+UWORD SetDisplay (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled));
UWORD CalculateBytesPerRow (__REGA0(struct BoardInfo *b), __REGD0(UWORD width), __REGD7(RGBFTYPE format));
APTR CalculateMemory (__REGA0(struct BoardInfo *b), __REGA1(unsigned int addr), __REGD7(RGBFTYPE format));
UWORD CalculateBytesPerRow (__REGA0(struct BoardInfo *b), __REGD0(UWORD width), __REGD7(RGBFTYPE format));
APTR CalculateMemory (__REGA0(struct BoardInfo *b), __REGA1(unsigned int addr), __REGD7(RGBFTYPE format));
WRITESHORT(RTG_COMMAND, RTGCMD_SETGC);
}
WRITESHORT(RTG_COMMAND, RTGCMD_SETGC);
}
-int setswitch = 0;
-BOOL SetSwitch (__REGA0(struct BoardInfo *b), __REGD0(BOOL enabled)) {
- WRITEBYTE(RTG_U81, (unsigned char)enabled);
- WRITESHORT(RTG_COMMAND, RTGCMD_SETSWITCH);
+int setswitch = -1;
+UWORD SetSwitch (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled)) {
if (setswitch != enabled) {
if (setswitch != enabled) {
- b->MoniSwitch = setswitch;
+
+ WRITEBYTE(RTG_U81, setswitch);
+ WRITESHORT(RTG_X1, setswitch);
+ WRITESHORT(RTG_COMMAND, RTGCMD_SETSWITCH);
}
void SetPanning (__REGA0(struct BoardInfo *b), __REGA1(UBYTE *addr), __REGD0(UWORD width), __REGD1(WORD x_offset), __REGD2(WORD y_offset), __REGD7(RGBFTYPE format)) {
}
void SetPanning (__REGA0(struct BoardInfo *b), __REGA1(UBYTE *addr), __REGD0(UWORD width), __REGD1(WORD x_offset), __REGD2(WORD y_offset), __REGD7(RGBFTYPE format)) {
}
APTR CalculateMemory (__REGA0(struct BoardInfo *b), __REGA1(unsigned int addr), __REGD7(RGBFTYPE format)) {
}
APTR CalculateMemory (__REGA0(struct BoardInfo *b), __REGA1(unsigned int addr), __REGD7(RGBFTYPE format)) {
return (APTR)addr;
if (addr > (unsigned int)b->MemoryBase && addr < (((unsigned int)b->MemoryBase) + b->MemorySize)) {
addr = ((addr + 0x1000) & 0xFFFFF000);
return (APTR)addr;
if (addr > (unsigned int)b->MemoryBase && addr < (((unsigned int)b->MemoryBase) + b->MemorySize)) {
addr = ((addr + 0x1000) & 0xFFFFF000);
}
static int display_enabled = 0;
}
static int display_enabled = 0;
-BOOL SetDisplay (__REGA0(struct BoardInfo *b), __REGD0(BOOL enabled)) {
- if (!b)
- return 0;
-
+UWORD SetDisplay (__REGA0(struct BoardInfo *b), __REGD0(UWORD enabled)) {
// Enables or disables the display.
WRITEBYTE(RTG_U82, (unsigned char)enabled);
WRITESHORT(RTG_COMMAND, RTGCMD_SETDISPLAY);
// Enables or disables the display.
WRITEBYTE(RTG_U82, (unsigned char)enabled);
WRITESHORT(RTG_COMMAND, RTGCMD_SETDISPLAY);