Commit ea956674 authored by David Skywalker's avatar David Skywalker
Browse files

[loader] cleaned code, final tests.

parent 478b0de5
Pipeline #68486 passed with stages
in 1 minute and 43 seconds
......@@ -200,8 +200,6 @@ extern char cart_name[512];
#include "slots.h"
#include "errors.h"
#define VERSION_STRING "v4.2.0"
#define MSG_SNA_LOAD 32
#define MSG_SNA_SAVE 33
#define MSG_DSK_LOAD 34
......@@ -542,7 +540,7 @@ uint8_t z80_IN_handler (reg_pair port)
ret_val = bTapeLevel | // tape level when reading
(CPC.printer ? 0 : 0x40) | // ready line of connected printer
(CPC.jumpers & 0x7f) | // manufacturer + 50Hz
(CRTC.flag_invsync ? 1 : 0); // VSYNC status
(CRTC.flag_invsync ? 1 : 0); // VSYNC status
} else {
ret_val = PPI.portB; // return last programmed value
}
......@@ -1909,7 +1907,7 @@ void doCleanUp (void)
void emu_reset(void)
{
emulator_reset(false);
emulator_reset(false);
}
void emu_restart(void)
......@@ -1923,7 +1921,7 @@ void emu_restart(void)
void change_model(int val){
CPC.model=val;
CPC.model=val;
if ((CPC.model >= 2) && (CPC.ram_size < 128))
CPC.ram_size = 128; // minimum RAM size for CPC 6128 is 128KB
......@@ -1933,7 +1931,7 @@ void change_model(int val){
void change_ram(int val){
CPC.ram_size=val;
CPC.ram_size=val;
if ((CPC.model >= 2) && (CPC.ram_size < 128))
CPC.ram_size = 128; // minimum RAM size for CPC 6128 is 128KB
......@@ -1942,11 +1940,11 @@ void change_ram(int val){
}
uint8_t* get_ram_ptr() {
return pbRAM;
return pbRAM;
}
size_t get_ram_size(void) {
return CPC.ram_size * 1024;
return CPC.ram_size * 1024;
}
void change_lang(int val){
......@@ -1983,117 +1981,14 @@ int UnInitOSGLU(void)
return 0;
}
uint32_t dwSndDist;
int iExitCondition;
bool bolDone;
//FIXME RETRO
//AUTOBOOT TAKEN FROM CPCDROID
#include "cpc_cat.h"
static int cur_name_id = 0;
int cpc_dsk_system = 0;
int
cap32_disk_dir(char *FileName)
{
int error = cpc_dsk_dir(FileName);
if (! error) {
cpc_dsk_system = (cpc_dsk_type == DSK_TYPE_SYSTEM);
printf("INFO-DSK: num: %d sys(%d)\n", cpc_dsk_num_entry, cpc_dsk_system);
if (cpc_dsk_num_entry > 20) {
int index;
for (index = 0; index < cpc_dsk_num_entry; index++) {
int cpos = 0;
printf("INFO: DIR-INIT: i(%d) p(%d) = %x\n", index, cpos, cpc_dsk_dirent[index][cpos]);
for (cpos = 0; cpc_dsk_dirent[index][cpos]; cpos++) {
/* with no printable chars in first ? might be CPM */
if (cpc_dsk_dirent[index][cpos] < 32) {
if(!index) {
cpc_dsk_num_entry = 0;
} else {
// some filenames are loaded used it! -- fixed cracked custom DSKs
cpc_dsk_num_entry = index;
}
printf("DSK_LOAD INFO-SYS: dsk: i(%d) p(%d) = %d \n", index, cpos, cpc_dsk_dirent[index][cpos]);
break;
}
}
}
} else {
}
}
return error;
}
int retro_disk_auto()
{
char key_buffer[LOADER_MAX_SIZE];
/*
int index;
int found = 0;
int first_bas = -1;
int first_spc = -1;
int first_bin = -1;
*/
cur_name_id = 0;
loader_init();
loader_run(key_buffer);
/*
char *RunName = psp_run_search(CPC.cpc_save_name);
if (RunName != (char *)0 ) {
if (!strcasecmp(RunName, "|CPM")) strcpy(Buffer, "|CPM");
else snprintf(Buffer, MAX_PATH, "RUN\"%s", RunName);
} else {
for (index = 0; index < cpc_dsk_num_entry; index++) {
char* scan = strchr(cpc_dsk_dirent[index], '.');
if (scan) {
if (! strcasecmp(scan+1, "BAS")) {
if (first_bas == -1) first_bas = index;
found = 1;
} else
if (! strcasecmp(scan+1, "")) {
if (first_spc == -1) first_spc = index;
found = 1;
} else
if (! strcasecmp(scan+1, "BIN")) {
if (first_bin == -1) first_bin = index;
found = 1;
}
}
}
if (! found) {
if (cpc_dsk_system) {
strcpy(Buffer, "|CPM");
} else {
strcpy(Buffer, "CAT");
printf("autoload: file to load not found\n");
}
} else {
if (first_bas != -1) cur_name_id = first_bas;
else
if (first_spc != -1) cur_name_id = first_spc;
else
if (first_bin != -1) cur_name_id = first_bin;
// check added to avoid warning on gcc >= 8
if(snprintf(Buffer, sizeof(Buffer), "RUN\"%s", (const char*) &cpc_dsk_dirent[cur_name_id][0]) < 0)
{
printf("autoload: snprintf failed");
}
}
//}
*/
printf(" >>> \"%s\"\n",key_buffer);
strcat(key_buffer, "\n");
......@@ -2102,25 +1997,30 @@ int retro_disk_auto()
return 1;
}
// TO BE REMOVED
//#define OLD_LOADER
#ifdef OLD_LOADER
//AUTOBOOT TAKEN FROM CPCDROID
#include "cpc_cat.h"
#endif
int attach_disk(char *arv, int drive)
{
int result = 1;
if(!drive) {
if((result = dsk_load( arv, &driveA, 'A')) == 0)
{
sprintf(DISKA_NAME,"%s",arv);
//result = cap32_disk_dir(arv);
//if(result)
// printf("error dsk: %d\n", result);
}
} else {
if((result = dsk_load( arv, &driveB, 'B')) == 0)
{
sprintf(DISKB_NAME,"%s",arv);
cap32_disk_dir(arv);
}
int result = 1;
if(!drive) {
if((result = dsk_load( arv, &driveA, 'A')) == 0)
{
sprintf(DISKA_NAME,"%s",arv);
#ifdef OLD_LOADER
result = cpc_dsk_dir(arv);
#endif
}
} else {
if((result = dsk_load( arv, &driveB, 'B')) == 0)
{
sprintf(DISKB_NAME,"%s",arv);
}
}
return result;
}
......@@ -2143,19 +2043,10 @@ int detach_disk(int drive)
void retro_loop(void)
{
while(1)
{
if ((CPC.limit_speed) && (iExitCondition == EC_CYCLE_COUNT))
{
if (CPC.snd_enabled)
{
if (pbSndStream < CPC.snd_bufferptr)
dwSndDist = CPC.snd_bufferptr - pbSndStream; // determine distance between play and write cursors
else
dwSndDist = (pbSndBufferEnd - pbSndStream) + (CPC.snd_bufferptr - pbSndBuffer);
}
}
static int iExitCondition = EC_FRAME_COMPLETE;
while(1)
{
uint32_t dwOffset = CPC.scr_pos - CPC.scr_base; // offset in current surface row
if (VDU.scrln > 0)
CPC.scr_base = retro_getScreenPtr() + (VDU.scrln * CPC.scr_line_offs); // determine current position
......@@ -2217,9 +2108,6 @@ int capmain (int argc, char **argv)
dwTicksOffset = (int)(FRAME_PERIOD_MS / (double)(CPC.speed/CPC_BASE_FREQUENCY_MHZ));
iExitCondition = EC_FRAME_COMPLETE;
bolDone = false;
emu_status = COMPUTER_READY; // set computer init as completed
return 0;
......
......@@ -184,6 +184,9 @@ void sector_set_sizes(t_sector * sector, unsigned int size, unsigned int total_s
unsigned char* sector_get_read_data(t_sector * sector)
{
sector->weak_read_version = (sector->weak_read_version + 1) % sector->weak_versions;
#ifdef DEBUG_FDC
printf("sector_get_read_data: %u\n", sector->weak_read_version * sector->size);
#endif
return &sector->data[sector->weak_read_version * sector->size];
}
......@@ -254,6 +257,11 @@ t_sector *find_sector(uint8_t *requested_CHRN)
FDC.result[RES_ST2] &= ~0x10; // remove possible No Cylinder flag
}
active_drive->current_sector = idx; // update sector table index for active drive
#ifdef DEBUG_FDC
printf("sector: %u [%02x.%02x.%02x.%02x]\n", idx, requested_CHRN[0], requested_CHRN[1], requested_CHRN[2], requested_CHRN[3]);
#endif
return sector;
}
......@@ -338,6 +346,11 @@ loop:
else {
sector_size = 128 << FDC.command[CMD_N]; // determine number of bytes from N value
}
#ifdef DEBUG_FDC
printf("r:%u-%u\n",CMD_C, sector_size);
#endif
FDC.buffer_count = sector_size; // init number of bytes to transfer
FDC.buffer_ptr = sector_get_read_data(sector); // pointer to sector data (weak sector support)
FDC.buffer_endptr = active_track->data + active_track->size; // pointer beyond end of track data
......
......@@ -639,6 +639,8 @@ int read_track (int hd, int trk) // 0, 0
long n, pos;
int track_size;
printf(" read_track[trk=%i,hd=%i]\n", trk, hd);
if (trk == cur_trk && hd == cur_hd) {
return 0;
}
......@@ -655,6 +657,8 @@ int track_size;
if (pos==0)
return -1;
printf(" read_track[%i/%i]: seek=0x%04lx size=%i\n", trk, hd, pos, track_size);
n = my_lseek(pos,SEEK_SET);
if (n == -1L) {
//fprintf(stdout,"Image corrupt! I cannot position on track %d!", trk);
......@@ -904,6 +908,7 @@ uchar *sector_ptr;
hd = hd_calc (blk);*/
calc_t_s_h(blk, &trk, &sec, &hd);
printf("blk=%i trk=%i sec=%i hd=%i\n", blk, trk, sec, hd);
while (filled < dpb->BLS)
{
......@@ -1146,6 +1151,7 @@ int mask;
{
if ((directory[i].user!=0xE5) && (directory[i].first)) {
strncpy((char *)cpc_dsk_dirent[cpc_dsk_num_entry], (char *)directory[i].name, CPC_NAME_SIZE);
printf("dirent(%i) a(%i) [%s]\n", cpc_dsk_num_entry, i, cpc_dsk_dirent[cpc_dsk_num_entry]);
cpc_dsk_num_entry++;
if (cpc_dsk_num_entry >= CPC_MAX_ENTRY) break;
}
......
......@@ -46,59 +46,43 @@
#define DSK_NAME_SIZE 8
#define DSK_EXT_SIZE 3
//#define CAT_DEBUG 1
//#define CAT_DEBUG
char catalog_dirent[CAT_MAX_ENTRY][CAT_NAME_SIZE];
int catalog_entry = 0;
CatalogEntry * _catalog_init(unsigned short alloc_size) {
CatalogEntry *catalog = (CatalogEntry *) malloc(sizeof(CatalogEntry) * (alloc_size + 1));
if (catalog == NULL) {
return NULL;
}
for (int i = 0; i <= alloc_size; i++) {
catalog[i].valid = false;
memset(catalog[i].name, 0, 13);
}
#ifdef CAT_DEBUG
printf(" archive: created %u entries.\n", alloc_size);
#endif
return catalog;
}
DSKEntry * _catalog_entry(unsigned char pos, t_drive *drive)
DSKEntry * _catalog_entry(unsigned char pos, unsigned short track_offset, t_drive *drive)
{
int offset = pos * sizeof(DSKEntry);
int entry = pos % ENTRIES_PER_SECTOR;
int track = track_offset;
unsigned int sector_size = drive->track[0][0].sector[0].size;
unsigned int sector_size = drive->track[track][0].sector[0].size;
unsigned int sector = offset / sector_size;
#ifdef CAT_DEBUG
printf(" entry(%i): s[%u,%u] ==> %u a[%u] (%lu)\n",
printf(" entry(%i): s[%u,%u] ==> %u a[%u,%u] (%lu)\n",
pos,
sector,
sector_size,
offset,
entry,
track,
sizeof(DSKEntry)
);
#endif
DSKEntry * archive_info = (DSKEntry *) drive->track[0][0].sector[sector].data;
DSKEntry * archive_info = (DSKEntry *) drive->track[track][0].sector[sector].data;
archive_info += entry;
return archive_info;
}
bool _is_valid_extension(const char *ext) {
if (! strcasecmp(ext, "BAS"))
if (! strncasecmp(ext, "BAS", 3))
return true;
if (! strcasecmp(ext, "BIN"))
if (! strncasecmp(ext, "BIN", 3))
return true;
if (! strncmp(ext, " ", 3))
......@@ -107,40 +91,38 @@ bool _is_valid_extension(const char *ext) {
return false;
}
void _catalog_build_name(CatalogEntry * cat)
bool _catalog_build_name(char *name, char *raw_name, char *raw_ext)
{
int i, j;
char *buf = cat->name;
char *name = cat->raw_name;
char *ext = cat->raw_ext;
if(!_is_valid_extension(ext))
return;
if(!_is_valid_extension(raw_ext))
return false;
for (i = 0; i < DSK_NAME_SIZE; i++) {
if (name[i] == ' ')
if (raw_name[i] == ' ')
break;
buf[i] = name[i];
name[i] = raw_name[i];
}
buf[i] = '.';
name[i] = '.';
i ++;
// check extension
for (j = 0; j < DSK_EXT_SIZE; j++, i++) {
if (ext[j] == ' ')
if (raw_ext[j] == ' ')
break;
buf[i] = ext[j];
name[i] = raw_ext[j];
}
buf[i] = 0;
name[i] = 0;
// name > '.'
if (i > 1)
cat->valid = true;
if (i <= 1)
return false;
return true;
}
bool _catalog_exist_name(char * archive_name) {
......@@ -162,46 +144,37 @@ void _catalog_add(char * archive_name) {
catalog_entry ++;
}
void archive_init(unsigned short alloc_size, t_drive *drive)
void archive_init(unsigned short alloc_size, unsigned short track_offset, t_drive *drive)
{
int i = 0;
CatalogEntry *catalog = NULL;
catalog = _catalog_init(alloc_size);
if (catalog == NULL) {
return;
}
char raw_name[8 + 3];
char tmp_name[13]; /* <raw_name 8>+"."+<raw_ext 3>+"\0" */
for (i = 0; i <= alloc_size; i++) {
DSKEntry * archive_info = _catalog_entry(i, drive);
const DSKEntry * archive_info = _catalog_entry(i, track_offset, drive);
// ignore empty entries
if (archive_info->user == 0xE5)
continue;
// filter filename/extension using mask
for (int j = 0; j < 8; j++)
catalog[i].raw_name[j] = archive_info->raw_name[j] & 0x7F;
for (int j = 0; j < 8 + 3; j++)
raw_name[j] = archive_info->file.raw[j] & 0x7F;
for (int j=0; j < 3; j++)
catalog[i].raw_ext[j] = archive_info->raw_ext[j] & 0x7F;
_catalog_build_name(&catalog[i]);
#ifdef CAT_DEBUG
printf("entry[%i/%i] [%s]\n", i, alloc_size, raw_name);
#endif
if (!catalog[i].valid)
if(!_catalog_build_name(tmp_name, raw_name, raw_name + 8))
continue;
#ifdef CAT_DEBUG
printf(" drive_data(%i/%i): t[0][0] [%s] v[%u]\n\n",
i, alloc_size,
catalog[i].name,
catalog[i].valid
printf(" drive_data(%i/%i): t[%i][0] [%s]\n\n",
i, alloc_size, track_offset,
tmp_name
);
#endif
_catalog_add(catalog[i].name);
_catalog_add(tmp_name);
}
// free allocated info
free(catalog);
}
......@@ -43,8 +43,13 @@ typedef union {
unsigned char data[32];
struct {
unsigned char user;
char raw_name[8]; // raw filename
char raw_ext[3];
union {
char raw[8+3];
struct {
char raw_name[8]; // raw filename
char raw_ext[3];
};
} file;
unsigned char extent;
unsigned char unused[2];
unsigned char rec;
......@@ -52,12 +57,4 @@ typedef union {
};
} DSKEntry;
typedef struct {
char raw_name[8]; /* padded with space */
char raw_ext[3]; /* ditto */
char name[13]; /* <root 8>+"."+<ext 3>+"\0" (for globbing) */
bool valid; /* this entry is first */
} CatalogEntry;
void archive_init(unsigned short alloc_size, t_drive *drive);
\ No newline at end of file
void archive_init(unsigned short alloc_size, unsigned short track_offset, t_drive *drive);
\ No newline at end of file
......@@ -118,7 +118,7 @@ void loader_run (char * key_buffer) {
return;
}
archive_init(dpb->DRM, current_drive);
archive_init(dpb->DRM, dpb->OFS, current_drive);
if(!_loader_find(key_buffer)) {
loader_failed(key_buffer, dpb->SEC1_side1 == DSK_TYPE_SYSTEM);
}
......
......@@ -1229,7 +1229,7 @@ void retro_get_system_info(struct retro_system_info *info)
#ifndef GIT_VERSION
#define GIT_VERSION ""
#endif
info->library_version = "4.5" GIT_VERSION SCREENMODE_STR;
info->library_version = VERSION_STRING GIT_VERSION SCREENMODE_STR;
info->valid_extensions = "dsk|sna|zip|tap|cdt|voc|cpr|m3u";
info->need_fullpath = true;
info->block_extract = false;
......
......@@ -47,6 +47,8 @@
#include <stdio.h>
#include <stdbool.h>
#define VERSION_STRING "4.5.1"
// DEVICE AMSTRAD
#define RETRO_DEVICE_AMSTRAD_KEYBOARD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_KEYBOARD, 0)
#define RETRO_DEVICE_AMSTRAD_JOYSTICK RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment