Skip to content

Commit

Permalink
Boot loader v2.4, SDL lib source, updated SDL_image
Browse files Browse the repository at this point in the history
  • Loading branch information
DC-SWAT committed Feb 4, 2016
1 parent e6bd6c7 commit a5bf6c8
Show file tree
Hide file tree
Showing 255 changed files with 127,734 additions and 217 deletions.
20 changes: 0 additions & 20 deletions firmware/bios switch pic 12f675.hex

This file was deleted.

31 changes: 19 additions & 12 deletions firmware/bootloader/Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
#
# DreamShell boot loader
# (c)2011-2015 SWAT
# (c)2011-2016 SWAT
#

TARGET = loader
VERSION = 2.3
VERSION = 2.4
TARGET_NAME = DreamShell_boot_$(TARGET)_v$(VERSION)
TARGET_CD = cd/1DS_BOOT.BIN

all: rm-elf $(TARGET).elf

clean: rm-elf
-rm -f $(OBJS)

rm-elf:
-rm -f $(TARGET).elf $(TARGET).bin cd/1DS_CORE.BIN romdisk.*
-rm -f $(TARGET).elf $(TARGET).bin $(TARGET_CD) romdisk.*

include ../../sdk/Makefile.cfg

FATFS = $(DS_BASE)/src/fs/fat
DRIVERS = $(DS_BASE)/src/drivers
UTILS = $(DS_BASE)/src/utils

OBJS = src/main.o src/spiral.o src/menu.o $(DRIVERS)/spi.o $(DRIVERS)/sd.o \
OBJS = src/main.o src/spiral.o src/menu.o src/descramble.o \
$(DRIVERS)/spi.o $(DRIVERS)/sd.o $(DRIVERS)/rtc.o \
$(FATFS)/utils.o $(FATFS)/option/ccsbcs.o $(FATFS)/option/syscall.o \
$(FATFS)/ff.o $(FATFS)/dc.o $(FATFS)/../fs.o \
$(UTILS)/memcpy.op $(UTILS)/memset.op

KOS_CFLAGS += -I../../include -I../../include/fatfs -I./include
KOS_LDLAGS += -L../../lib
KOS_CFLAGS += -I$(DS_BASE)/include -I$(DS_BASE)/include/fatfs -I./include -DVERSION="$(VERSION)"

$(TARGET).bin: $(TARGET).elf
$(TARGET).elf: $(OBJS) romdisk.o
$(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $(TARGET).elf $(KOS_START) \
$(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $(TARGET).elf \
$(OBJS) romdisk.o $(OBJEXTRA) -lkosext2fs -lz -lkmg $(KOS_LIBS)
$(KOS_STRIP) $(TARGET).elf
$(KOS_OBJCOPY) -R .stack -O binary $(TARGET).elf $(TARGET).bin
Expand All @@ -44,15 +46,20 @@ romdisk.img:
romdisk.o: romdisk.img
$(KOS_BASE)/utils/bin2o/bin2o romdisk.img romdisk romdisk.o

cdi:
$(TARGET_CD): $(TARGET).bin

cdi: $(TARGET_CD)
@mkdir -p ./cd
@$(DS_SDK)/bin/scramble $(TARGET).bin cd/1DS_CORE.BIN
@$(DS_SDK)/bin/mkisofs -V DreamShell -C 0,11702 -G $(DS_BUILD)/IP.BIN -joliet -rock -l -o $(TARGET).iso ./cd
@$(DS_SDK)/bin/scramble $(TARGET).bin $(TARGET_CD)
@$(DS_SDK)/bin/mkisofs -V DreamShell -G res/IP.BIN -joliet -rock -l -o $(TARGET).iso ./cd
@echo Convert ISO to CDI...
@-rm -f $(TARGET).cdi
@$(DS_SDK)/bin/cdi4dc $(TARGET).iso $(TARGET).cdi > cdi4dc.out
@$(DS_SDK)/bin/cdi4dc $(TARGET).iso $(TARGET).cdi -d > cdi4dc.out
@-rm -f $(TARGET).iso

#@$(DS_SDK)/bin/mkisofs -V DreamShell -C 0,11702 -G res/IP.BIN -joliet -rock -l -o $(TARGET).iso ./cd
#@$(DS_SDK)/bin/cdi4dc $(TARGET).iso $(TARGET).cdi > cdi4dc.out

release: all cdi
rm -f $(TARGET_NAME).elf $(TARGET_NAME).bin $(TARGET_NAME).cdi
mv $(TARGET).elf $(TARGET_NAME).elf
Expand All @@ -65,7 +72,7 @@ nulldc: all cdi
@cp $(TARGET).cdi $(DS_BASE)/DS.cdi
@run $(DS_BASE)/emu/nullDC.exe -serial "debug.log"

lxcd: all cdi
lxdream: all cdi
@echo Running...
@lxdream -p $(TARGET).cdi

Expand Down
1 change: 1 addition & 0 deletions firmware/bootloader/include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ int FileExists(const char *fn);
int DirExists(const char *dir);

int flashrom_get_region_only();
void descramble(uint8 *source, uint8 *dest, uint32 size);

extern const char title[28];
extern uint32 spiral_color;
Expand Down
Binary file modified firmware/bootloader/loader.bin
Binary file not shown.
Binary file modified firmware/bootloader/loader.cdi.7z
Binary file not shown.
82 changes: 82 additions & 0 deletions firmware/bootloader/src/descramble.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* DreamShell boot loader
* Descramble binary
* (c)2011-2016 SWAT <http://www.dc-swat.ru>
*/

#include "main.h"

#define MAXCHUNK 0x200000
static uint seed;

static inline void my_srand(uint n) {
seed = n & 0xffff;
}

static inline uint my_rand(void) {
seed = (seed * 2109 + 9273) & 0x7fff;
return (seed + 0xc000) & 0xffff;
}

static void load(uint8 *dest, uint32 size) {

static uint8 *source;

if (!size) {
source = dest;
return;
}

memcpy(dest, source, size);
source += size;
}

static inline void handle_chunk(uint8 *ptr, int sz) {

int idx[MAXCHUNK / 32];
int i;

/* Convert chunk size to number of slices */
sz /= 32;

/* Initialize index table with unity,
so that each slice gets loaded exactly once */
for(i = 0; i < sz; i++)
idx[i] = i;

for(i = sz-1; i >= 0; --i)
{
/* Select a replacement index */
int x = (my_rand() * i) >> 16;

/* Swap */
int tmp = idx[i];
idx[i] = idx[x];
idx[x] = tmp;

/* Load resulting slice */
load(ptr + 32 * idx[i], 32);
}
}

void descramble(uint8 *source, uint8 *dest, uint32 size) {

load(source, 0);
my_srand(size);

/* Descramble 2 meg blocks for as long as possible, then
gradually reduce the window down to 32 bytes (1 slice) */
for(uint32 chunksz = MAXCHUNK; chunksz >= 32; chunksz >>= 1)
{
while(size >= chunksz)
{
handle_chunk(dest, chunksz);
size -= chunksz;
dest += chunksz;
}
}

/* !!! Load final incomplete slice */
if(size)
load(dest, size);
}
76 changes: 23 additions & 53 deletions firmware/bootloader/src/main.c
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
/* DreamShell boot loader
main.c
(c) 2011-2014 SWAT
*/
/**
* DreamShell boot loader
* Main
* (c)2011-2016 SWAT <http://www.dc-swat.ru>
*/

#include "main.h"
#include "fs.h"


KOS_INIT_FLAGS(INIT_DEFAULT/* | INIT_NET*/);
extern uint8 romdisk[];
//KOS_INIT_ROMDISK(romdisk);

pvr_init_params_t params = {
{ PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_32, PVR_BINSIZE_0, PVR_BINSIZE_0 },
512*1024
512 * 1024
};

const char title[28] = "DreamShell boot loader v2.3";
const char title[28] = "DreamShell boot loader v"VERSION;

//#define EMU
//#define BIOS_MODE

#ifndef EMU
KOS_INIT_FLAGS(INIT_DEFAULT/* | INIT_NET*/);
#else
KOS_INIT_FLAGS(INIT_DEFAULT);
#endif


int FileSize(const char *fn) {
int size;
file_t f;

f = fs_open(fn, O_RDONLY);

if(f == FILEHND_INVALID) {
return -1;
}

size = fs_total(f);
fs_close(f);
return size;
}
//#define BIOS_MODE

int FileExists(const char *fn) {
file_t f;
Expand Down Expand Up @@ -106,8 +83,16 @@ int flashrom_get_region_only() {
}


int is_hacked_bios() {
return (*(uint16 *)0xa0000000) == 0xe6ff;
}

int is_custom_bios() {
return (*(uint16 *)0x80000004) != 0x6439;
return (*(uint16 *)0xa0000004) == 0x4318;
}

int is_no_syscalls() {
return (*(uint16 *)0xac000100) != 0x2f06;
}

#ifdef BIOS_MODE
Expand Down Expand Up @@ -186,41 +171,26 @@ int main(int argc, char **argv) {
cont_btn_callback(0, CONT_START, (cont_btn_callback_t)start_callback);

if(vid_check_cable() == CT_VGA) {

vid_set_mode(DM_640x480_VGA, PM_RGB565);

} else if(flashrom_get_region_only() == FLASHROM_REGION_EUROPE) {
vid_set_mode(DM_640x480_PAL_IL, PM_RGB565);
} else {

int region = flashrom_get_region_only();

switch(region) {
case FLASHROM_REGION_US:
case FLASHROM_REGION_JAPAN:
vid_set_mode(DM_640x480_NTSC_IL, PM_RGB565);
break;
case FLASHROM_REGION_EUROPE:
vid_set_mode(DM_640x480_PAL_IL, PM_RGB565);
break;
case FLASHROM_REGION_UNKNOWN:
default:
break;
}
vid_set_mode(DM_640x480_NTSC_IL, PM_RGB565);
}

#ifndef EMU

#ifdef BIOS_MODE


if(!fs_romdisk_mount(RES_PATH, (const uint8 *)romdisk, 0)) {

dbgio_dev_select("fb");
show_boot_message();

if(is_custom_bios()/* && is_no_syscalls()*/) {
setup_syscalls();
cdrom_init();
fs_iso9660_init();
// cdrom_init();
// fs_iso9660_init();
}

} else {
Expand Down
Loading

0 comments on commit a5bf6c8

Please sign in to comment.