Skip to content

Commit

Permalink
Long overdue update to new gint/fxsdk
Browse files Browse the repository at this point in the history
It seems to work fine, it even handles high overclocks

Signed-off-by: djpadbit <[email protected]>
  • Loading branch information
djpadbit committed Sep 15, 2020
1 parent 61b079e commit bb4df1f
Show file tree
Hide file tree
Showing 32 changed files with 210 additions and 301 deletions.
Binary file removed MainIcon.bmp
Binary file not shown.
Binary file added MainIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
LDFLAGS = `fxsdk --libs` -Tsections.ld
LDFLAGS = -T fx9860g.ld -lgint-fx -lgcc -Tsections.ld
#LDFLAGS += -Xlinker -Map=output.map
CC = sh3eb-elf-gcc
TOOLCHAIN = sh-elf
CC = $(TOOLCHAIN)-gcc
OBJCOPY = $(TOOLCHAIN)-objcopy
CFLAGS = -Wall -Ofast -fstrength-reduce -fthread-jumps -fcse-follow-jumps -fcse-skip-blocks -frerun-cse-after-loop -fexpensive-optimizations -fforce-addr -fomit-frame-pointer
CFLAGS += `fxsdk --cflags`
CFLAGS += -mb -ffreestanding -nostdlib -fstrict-volatile-bitfields -D FX9860G -m3 -I
INCLUDE = -Ignuboy/include -Ignuboy-fx/include
GNUBOYDIR = gnuboy
FX_GNUBOYDIR = gnuboy-fx
Expand All @@ -25,16 +27,16 @@ CFLAGS += -g
$(CC) $(INCLUDE) $(CFLAGS) -c -o $@ $<

fxgnuboy.elf: $(OBJS) $(FX_OBJS)
$(CC) $(OBJS) $(FX_OBJS) $(LDFLAGS) -o fxgnuboy.elf
$(CC) $(CFLAGS) $(OBJS) $(FX_OBJS) $(LDFLAGS) -o fxgnuboy.elf

fxgnuboy.bin: fxgnuboy.elf
sh3eb-elf-objcopy -R .comment -R .bss -R .magic_sec -O binary fxgnuboy.elf fxgnuboy.bin
$(OBJCOPY) -R .comment -R .bss -R .gint_bss -R .magic_sec -O binary fxgnuboy.elf fxgnuboy.bin

fxgnuboy.g1a: fxgnuboy.bin
g1a-wrapper fxgnuboy.bin -o fxgnuboy.g1a -i MainIcon.bmp
fxg1a fxgnuboy.bin -o fxgnuboy.g1a -i "MainIcon.png" -n "fxgnuboy" --internal="@GNUBOY"

dump: fxgnuboy.g1a
sh3eb-elf-objdump -d -C -S fxgnuboy.elf > dump
$(TOOLCHAIN)-objdump -d -C -S fxgnuboy.elf > dump
subl dump

clean:
Expand Down
Binary file modified fxgnuboy.g1a
Binary file not shown.
16 changes: 8 additions & 8 deletions gnuboy-fx/config.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <string.h>
#include <bfile.h>
#include <gint/std/stdlib.h>
#include <gint/std/string.h>
#include <gint/bfile.h>
#include "file.h"
#include "lcd.h"

Expand Down Expand Up @@ -41,13 +41,13 @@ struct config *config_read(struct config *cfg)
file_make_path(path,"fls0","",CONFIG_FILE);
int fd = BFile_Open(path,BFile_ReadOnly);
if (fd<0) return NULL;
int size = BFile_GetFileSize(fd);
if (size != CONFIG_SIZE) return NULL;
//int size = BFile_GetFileSize(fd);
//if (size != CONFIG_SIZE) return NULL;
if (!cfg) {
cfg = malloc(CONFIG_SIZE);
if (!cfg) return NULL;
}
BFile_Read(fd,cfg,size,0);
BFile_Read(fd,cfg,CONFIG_SIZE,0);
BFile_Close(fd);
return cfg;
}
Expand All @@ -58,11 +58,11 @@ int config_write(struct config *cfg)
file_make_path(path,"fls0","",CONFIG_FILE);
int fd = BFile_Open(path,BFile_WriteOnly);
if (fd<0) return 0;
int size = BFile_GetFileSize(fd);
/*int size = BFile_GetFileSize(fd);
if (size < CONFIG_SIZE) {
BFile_Close(fd);
return 0;
}
}*/
BFile_Write(fd,cfg,CONFIG_SIZE);
BFile_Close(fd);
return 1;
Expand Down
101 changes: 6 additions & 95 deletions gnuboy-fx/disp.c
Original file line number Diff line number Diff line change
@@ -1,98 +1,9 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "defs.h"
#include <keyboard.h>
#include <display.h>
#include <gray.h>
#include "lcd.h"
#include <gint/display.h>
#include "disp.h"

void mprint(int x,int y, const char* fmt, ...)
int text_length(const char *str)
{
if(x < 1 || x > 21 || y < 1 || y > 8) return;
char k[50];
va_list args;
va_start(args, fmt);
vsprintf(k,fmt,args);
va_end(args);
if (lcd_gray_enabled) gtext(x * 6 - 5, y * 8 - 8, k);
else dtext(x * 6 - 5, y * 8 - 8, k);
}

void mprintp(int x,int y, const char* fmt, ...)
{
if(x < 0 || x > 128 || y < 0 || y > 64) return;
char k[50];
va_list args;
va_start(args, fmt);
vsprintf(k,fmt,args);
va_end(args);
if (lcd_gray_enabled) gtext(x, y, k);
else dtext(x, y, k);
}

void mtext(int x, int y, const char *str)
{
if (lcd_gray_enabled) gtext(x, y, str);
else dtext(x, y, str);
}

void mclear()
{
if (lcd_gray_enabled) gclear();
else dclear();
}

void mupdate()
{
if (lcd_gray_enabled) gupdate();
else dupdate();
}

//Gint's gline and dline don't behave like they should so in the meantime i'll just use that
//https://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#C
void dline_oth(int x0, int y0, int x1, int y1,color_t op)
{
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
int err = (dx>dy ? dx : -dy)/2, e2;
for(;;){
dpixel(x0,y0,op);
if (x0==x1 && y0==y1) break;
e2 = err;
if (e2 >-dx) { err -= dy; x0 += sx; }
if (e2 < dy) { err += dx; y0 += sy; }
}
}

void gline_oth(int x0, int y0, int x1, int y1,color_t op)
{
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
int err = (dx>dy ? dx : -dy)/2, e2;
for(;;){
gpixel(x0,y0,op);
if (x0==x1 && y0==y1) break;
e2 = err;
if (e2 >-dx) { err -= dy; x0 += sx; }
if (e2 < dy) { err += dx; y0 += sy; }
}
}

void mline_oth(int x0, int y0, int x1, int y1,color_t op)
{
if (lcd_gray_enabled) gline_oth(x0,y0,x1,y1,op);
else dline_oth(x0,y0,x1,y1,op);
}

void mline(int x1, int y1, int x2, int y2, color_t _operator)
{
if (lcd_gray_enabled) gline(x1,y1,x2,y2,_operator);
else dline(x1,y1,x2,y2,_operator);
}

void mrect(int x1, int y1, int x2, int y2, color_t _operator)
{
if (lcd_gray_enabled) grect(x1,y1,x2,y2,_operator);
else drect(x1,y1,x2,y2,_operator);
int l;
dsize(str,NULL,&l,NULL);
return l;
}
20 changes: 9 additions & 11 deletions gnuboy-fx/disp.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#ifndef __DISP_H__
#define __DISP_H__

#include <display.h>
#include <gint/display.h>

void mprint(int x,int y, const char* fmt, ...);
void mprintp(int x,int y, const char* fmt, ...);
void mtext(int x, int y, const char *str);
void mclear();
void mupdate();
void dline_oth(int x0, int y0, int x1, int y1,color_t op);
void gline_oth(int x0, int y0, int x1, int y1,color_t op);
void mline_oth(int x0, int y0, int x1, int y1,color_t op);
void mline(int x1, int y1, int x2, int y2, color_t _operator);
void mrect(int x1, int y1, int x2, int y2, color_t _operator);
#define mprint(x,y,fmt, ...) dprint((x)*6-5, (y)*8-8, C_BLACK, fmt, ##__VA_ARGS__)
#define mprintp(x,y,fmt, ...) dprint(x, y, C_BLACK, fmt, ##__VA_ARGS__)
#define mclear() dclear(C_WHITE)
#define mupdate() dupdate()
#define mline(x0,y0,x1,y1,op) dline(x0,y0,x1,y1,op);
#define mrect(x0,y0,x1,y1,op) drect(x0,y0,x1,y1,op);

int text_length(const char *str);

#endif
4 changes: 2 additions & 2 deletions gnuboy-fx/file.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <gint/std/stdio.h>
#include <gint/std/string.h>
#include "file.h"

// The 3 functions below are based on EDIT's source code (see FilePath, Font2Char and Char2Font function)
Expand Down
28 changes: 0 additions & 28 deletions gnuboy-fx/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,8 @@

#include <stdint.h>

// From SDK, temporary, will get removed when BFile_Find... are added to gint

// file info types
#define DT_DIRECTORY 0x0 // Directory
#define DT_FILE 0x1 // File
#define DT_ADDIN_APP 0x2 // Add-In application
#define DT_EACT 0x3 // eActivity
#define DT_LANGUAGE 0x4 // Language
#define DT_BITMAP 0x5 // Bitmap
#define DT_MAINMEM 0x6 // Main Memory data
#define DT_TEMP 0x7 // Temporary data
#define DT_DOT 0x8 // . (Current directory)
#define DT_DOTDOT 0x9 // .. (Parent directory)
#define DT_VOLUME 0xA // Volume label

typedef struct
{
unsigned short id;
unsigned short type;
unsigned long fsize;
unsigned long dsize;
unsigned int property;
unsigned long address;
} bfile_info;

void file_fc_to_char(uint16_t *src, char *dst);
void file_char_to_fc(char *src, uint16_t *dst);
void file_make_path(uint16_t* dst,char* root,char *fold,char *fn);
int BFile_FindFirst(const uint16_t *path, int *findhandle, uint16_t *foundfile, bfile_info *fileinfo);
int BFile_FindNext(int findhandle, uint16_t *foundfile, bfile_info *fileinfo);
int BFile_FindClose(int findhandle);

#endif
34 changes: 0 additions & 34 deletions gnuboy-fx/file_syscall.s

This file was deleted.

43 changes: 21 additions & 22 deletions gnuboy-fx/fxsys.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gint/std/stdio.h>
#include <gint/std/stdlib.h>
#include <gint/std/string.h>
#include <stdarg.h>
#include <time.h>
#include <gint/timer.h>
#include <gint/clock.h>
#include <hw.h>
#include "emu.h"
#include <events.h>
#include <keyboard.h>
#include <display.h>
#include <ctype.h>
#include <gray.h>
#include <gint/keyboard.h>
#include <gint/display.h>
//#include <ctype.h>
#include <gint/gray.h>
#include "fxsys.h"
#include "lcd.h"
#include "menu.h"
Expand All @@ -22,11 +22,12 @@ unsigned long timertime = 0;
// 2 -> scaling adjust
static int input_mode = 0;
//static int cbid;
static timer_t *htimer = NULL;
static int htimer;

static void timer_callback()
static int timer_callback()
{
timertime++;
return TIMER_CONTINUE;
}

static void timer_sleepus(unsigned int delay)
Expand All @@ -36,12 +37,11 @@ static void timer_sleepus(unsigned int delay)
while (timertime<sleep_tar) sleep();
}

void timer_setup()
void timer_startup()
{
//cbid = rtc_cb_add(rtc_freq_256Hz,timer_callback,0);
uint32_t delay = clock_setting(TIMER_FREQ, clock_Hz);
htimer = htimer_setup(timer_user, delay, timer_Po_4, 0);
timer_attach(htimer, timer_callback, NULL);
uint32_t delay = timer_delay(2, TIMER_DELAY_US, TIMER_Pphi_4);
htimer = timer_setup(2, delay, timer_callback);
timer_start(htimer);
}

Expand Down Expand Up @@ -93,15 +93,14 @@ int sys_handle_input() {
// Will be kept between function calls
static uint8_t keypress[4];
int ret;
event_t e;
e = pollevent();
key_event_t e = pollevent();
while(1)
{
if (e.type == event_none)
if (e.type == KEYEV_NONE)
break;

if (e.type == event_key_press) {
switch (e.key.code) {
if (e.type == KEYEV_DOWN) {
switch (e.key) {
case KEY_SHIFT:
if (!input_mode) hw.pad|=PAD_A;
break;
Expand Down Expand Up @@ -152,8 +151,8 @@ int sys_handle_input() {
}
}

else if (e.type == event_key_release) {
switch (e.key.code) {
else if (e.type == KEYEV_UP) {
switch (e.key) {
case KEY_SHIFT:
if (!input_mode) hw.pad^=PAD_A;
break;
Expand Down
4 changes: 2 additions & 2 deletions gnuboy-fx/fxsys.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef __FXSYS_H__
#define __FXSYS_H__

#include <ctype.h>
//#include <ctype.h>

#define TIMER_FREQ 2000
#define TIMER_DELAY_US ((1.0/(double)TIMER_FREQ)*1000000.0)

extern unsigned long timertime;

void timer_setup();
void timer_startup();
void timer_cleanup();

#endif
Loading

0 comments on commit bb4df1f

Please sign in to comment.