Skip to content

Commit

Permalink
Merge pull request pete-gordon#190 from jedeoric/twilighteboard_firm2
Browse files Browse the repository at this point in the history
Twilighteboard firmware 2 management and various fixes
  • Loading branch information
jedeoric authored Apr 10, 2023
2 parents c15d662 + 78331c9 commit 8cf6b98
Show file tree
Hide file tree
Showing 13 changed files with 351 additions and 120 deletions.
3 changes: 2 additions & 1 deletion gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,8 @@ void insertdisk( struct machine *oric, struct osdmenuitem *mitem, int drive )

if( oric->drivetype == DRV_NONE )
{
swapmach( oric, NULL, (DRV_MICRODISC<<16)|oric->type );
if (!oric->twilighteboard_activated)
swapmach( oric, NULL, (DRV_MICRODISC<<16)|oric->type );
// setemumode( oric, NULL, EM_DEBUG );
return;
}
Expand Down
39 changes: 36 additions & 3 deletions machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,14 @@ void atmoswrite( struct m6502 *cpu, unsigned short addr, unsigned char data )
ch376_oric_write(oric->ch376, addr, data);

else if(oric->twilighteboard_activated && ((0x342 <= addr && addr < 0x344 ) || (0x320 <= addr && addr < 0x330 )))
twilighteboard_oric_write(oric->twilighte,addr,0x00,data);
twilighteboard_oric_write(oric->twilighte,addr,0x00,data);

else if(oric->twilighteboard_activated && oric->twilighte->microdisc==SDL_TRUE && (0x310 <= addr && addr < 0x319 ))
{
if (addr==0x314)
twilighteboard_oric_write(oric->twilighte,addr,0x00,data);
microdisc_write( &oric->md, addr, data );
}

else
via_write( &oric->via, addr, data );
Expand Down Expand Up @@ -713,8 +720,18 @@ unsigned char atmosread( struct m6502 *cpu, unsigned short addr )
if( oric->ch376_activated && ( 0x340 <= addr ) && ( addr < 0x342 ) )
return ch376_oric_read(oric->ch376, addr);

if( oric->twilighteboard_activated && ((0x342 <= addr && addr < 0x344 ) || (0x320 <= addr && addr < 0x330 )))
return twilighteboard_oric_read(oric->twilighte,addr);
if( oric->twilighteboard_activated)
{
if ((0x342 <= addr && addr < 0x344 ) || (0x320 <= addr && addr < 0x330 ))
return twilighteboard_oric_read(oric->twilighte,addr);

if (oric->twilighte->microdisc==SDL_TRUE)
{
if (0x310 <= addr && addr < 0x319)
return microdisc_read( &oric->md, addr );
}

}

return via_read( &oric->via, addr );
}
Expand Down Expand Up @@ -1363,7 +1380,14 @@ SDL_bool emu_event( SDL_Event *ev, struct machine *oric, SDL_bool *needrender )
{
oric->ch376_activated=SDL_TRUE;
oric->twilighte=twilighte_oric_init();
if (oric->twilighte->microdisc==SDL_TRUE)
{
oric->drivetype = DRV_MICRODISC;
oric->disksyms = NULL;
microdisc_init( &oric->md, &oric->wddisk, oric );
}
}

if (oric->twilighte==NULL)
{
oric->twilighteboard_activated=SDL_FALSE;
Expand Down Expand Up @@ -2017,7 +2041,16 @@ SDL_bool init_machine( struct machine *oric, int type, SDL_bool nukebreakpoints
{
oric->twilighte=twilighte_oric_init();
oric->ch376_activated=SDL_TRUE;

if (oric->twilighte->microdisc==SDL_TRUE)
{
oric->drivetype = DRV_MICRODISC;
oric->disksyms = NULL;
microdisc_init( &oric->md, &oric->wddisk, oric );
}

}

if (oric->twilighte==NULL) oric->twilighteboard_activated=SDL_FALSE;

m6502_reset( &oric->cpu );
Expand Down
8 changes: 5 additions & 3 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,17 +1653,19 @@ void mon_update_twil( struct machine *oric )

if ( oric->twilighteboard_activated )
{
int current_bank = oric->twilighte->current_bank & 0x07;
int is_ram = (current_bank == 0) || ((twilighteboard_oric_read(oric->twilighte, 0x342) & 0x20) && (current_bank < 5));
tzprintfpos( tz[TZ_TWIL], 2, 2, "Board version = %02X", (twilighteboard_oric_read(oric->twilighte, 0x342) & 0x07) );
tzprintfpos( tz[TZ_TWIL], 2, 4, "Bank set = %02X", twilighteboard_oric_read(oric->twilighte, 0x343) );
tzprintfpos( tz[TZ_TWIL], 2, 5, "Bank number = %02X", (twilighteboard_oric_read(oric->twilighte, 0x321) & 0x07));
tzprintfpos( tz[TZ_TWIL], 2, 6, "Bank type = %s" , (twilighteboard_oric_read(oric->twilighte, 0x342) & 0x20) ? "SRAM ": "EEPROM");
tzprintfpos( tz[TZ_TWIL], 2, 5, "Bank hardware number = %02X", twilighte_board_mapping_bank(oric->twilighte) );
tzprintfpos( tz[TZ_TWIL], 2, 6, "Bank software number = %02X", twilighte_board_mapping_software_bank(oric->twilighte) );
tzprintfpos( tz[TZ_TWIL], 2, 7, "Bank type = %s" , is_ram ? "SRAM ": "EEPROM");
tzprintfpos( tz[TZ_TWIL], 2, 9, "Twil register = %02X", twilighteboard_oric_read(oric->twilighte, 0x342) );
tzprintfpos( tz[TZ_TWIL], 2, 10, "Bank register = %02X", twilighteboard_oric_read(oric->twilighte, 0x343) );
tzprintfpos( tz[TZ_TWIL], 2, 12, "IORB = %02X", twilighteboard_oric_read(oric->twilighte, 0x320) );
tzprintfpos( tz[TZ_TWIL], 2, 13, "IORAh = %02X", twilighteboard_oric_read(oric->twilighte, 0x321) );
tzprintfpos( tz[TZ_TWIL], 2, 14, "DDRB = %02X", twilighteboard_oric_read(oric->twilighte, 0x322) );
tzprintfpos( tz[TZ_TWIL], 2, 15, "DDRA = %02X", twilighteboard_oric_read(oric->twilighte, 0x323) );

}

int offs = 8*tz[TZ_TWIL]->w+1;
Expand Down
2 changes: 1 addition & 1 deletion oricutron.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,4 @@ kbjoy2_fire3 = 'LALT'
; ch376 chip emulation. This chip can read a usbkey. For more information : http://orix.oric.org
; only available in telestrat mode
ch376 = no
twilighte_board=no
twilighte_board = no
126 changes: 103 additions & 23 deletions plugins/ch376/ch376.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
21.08.2017 - Jede : Added support for CMD_DIR_CREATE and CMD_FILE_ERASE (WIN32 only)
22.07.2017 - OffseT : Added support for CMD_DIR_CREATE and CMD_FILE_ERASE (Added related Amiga system APIs only)
01.02.2021 - Assinie: Fix time struct (Linux Only)
*/
02.04.2022 - Assinie: Added support for CMD_READ_VAR32 (FILE_SIZE and CURRENT_OFFSET only) (Linux Only)
10.03.2023 - Assinie: Fix bug : . and .. was reading as right entry. Now, it's skipped
*/
/* /// "Portable includes" */


Expand Down Expand Up @@ -78,7 +79,7 @@ extern struct Library *SysBase;
#define CH376_CMD_NONE 0x00
#define CH376_CMD_GET_IC_VER 0x01
#define CH376_CMD_CHECK_EXIST 0x06
#define CH376_CMD_GET_FILE_SIZE 0x0c
#define CH376_CMD_READ_VAR32 0x0c
#define CH376_CMD_SET_USB_MODE 0x15
#define CH376_CMD_GET_STATUS 0x22
#define CH376_CMD_RD_USB_DATA0 0x27
Expand All @@ -104,13 +105,17 @@ extern struct Library *SysBase;
#define CH376_ARG_SET_USB_MODE_SD_HOST 0x03
#define CH376_ARG_SET_USB_MODE_USB_HOST 0x06

// VAR32 offsets
#define CH376_VAR_FILE_SIZE 0x68
#define CH376_VAR_CURRENT_OFFSET 0x6c

// Status & errors
#define CH376_ERR_OPEN_DIR 0x41
#define CH376_ERR_MISS_FILE 0x42
#define CH376_ERR_FOUND_NAME 0x43

#define CH376_RET_SUCCESS 0x51
#define CH376_RET_ABORT 0x5f
#define CH376_RET_SUCCESS 0x51
#define CH376_RET_ABORT 0x5f

#define CH376_INT_SUCCESS 0x14
#define CH376_INT_DISK_READ 0x1d
Expand All @@ -120,7 +125,7 @@ extern struct Library *SysBase;

/* /// "CH376 data structures" */

#define CMD_DATA_REQ_SIZE 0xff
#define CMD_DATA_REQ_SIZE 0xff

// Attributes
#define DIR_ATTR_READ_ONLY 0x01
Expand Down Expand Up @@ -185,7 +190,7 @@ union CommandData
CH376_U8 CMD_FileReadWrite[2]; // [W/O] CH376_CMD_BYTE_READ, CH376_CMD_BYTE_WRITE
CH376_U8 CMD_IOBuffer[255]; // [R/W] CH376_CMD_BYTE_READ, CH376_CMD_BYTE_RD_GO, CH376_CMD_BYTE_WRITE, CH376_CMD_BYTE_WR_GO
CH376_U8 CMD_CheckByte; // [R/W] CH376_CMD_CHECK_EXIST
CH376_U8 CMD_FileSize[4]; // [R/W] CH376_CMD_GET_FILE_SIZE, CH376_CMD_SET_FILE_SIZE
CH376_U8 CMD_VAR32[4]; // [R/W] CH376_CMD_GET_FILE_SIZE, CH376_CMD_SET_FILE_SIZE
};

#pragma pack()
Expand Down Expand Up @@ -311,6 +316,9 @@ static void system_finish_examine_directory(CH376_CONTEXT *context, CH376_DIR fi
// Get the size of the current file
static CH376_S32 system_get_file_size(CH376_CONTEXT *context, CH376_FILE file);

// Get the offset position of the current file
static CH376_S32 system_get_file_offset(CH376_CONTEXT *context, CH376_FILE file);

/* /// */

#if defined(__MORPHOS__) || defined (__AMIGA__) || defined (__AROS__)
Expand Down Expand Up @@ -672,6 +680,20 @@ static CH376_S32 system_get_file_size(CH376_CONTEXT *context, CH376_FILE file)
return file_size;
}

static CH376_S32 system_get_file_offset(CH376_CONTEXT *context, CH376_FILE file)
{
CH376_S32 file_offset = 0xffffffff;

if (file)
{
dbg_printf("system_get_file_offset: unsupported error\n");
}
else
dbg_printf("system_get_file_offset: no file handle\n");

return file_offset;
}

/* /// */

#elif defined(WIN32)
Expand Down Expand Up @@ -1023,6 +1045,20 @@ static CH376_S32 system_get_file_size(CH376_CONTEXT *context, CH376_FILE file)
return file_size;
}

static CH376_S32 system_get_file_offset(CH376_CONTEXT *context, CH376_FILE file)
{
CH376_S32 file_offset = 0xffffffff;

if (file)
{
dbg_printf("system_get_file_offset: unsupported error\n");
}
else
dbg_printf("system_get_file_offset: no file handle\n");

return file_offset;
}

/* /// */

#elif defined(__unix__) || defined(__APPLE__) || defined(__HAIKU__)
Expand Down Expand Up @@ -1430,6 +1466,25 @@ static CH376_S32 system_get_file_size(CH376_CONTEXT *context, CH376_FILE file)
return file_size;
}

static CH376_S32 system_get_file_offset(CH376_CONTEXT *context, CH376_FILE file)
{
CH376_S32 file_offset = 0xffffffff;

if (file)
{
file_offset = ftell(file);

if(file_offset == -1)
{
dbg_printf("system_get_file_offset: error\n");
}
}
else
dbg_printf("system_get_file_offset: no file handle\n");

return file_offset;
}

/* /// */

#else
Expand Down Expand Up @@ -1511,6 +1566,13 @@ static const char * normalize_file_name(const char *file_name, char *normalized_

dbg_printf("normalize_file_name: %s\n", file_name);

// '.' or '..'
if(file_name[0] == '.')
{
if( (file_name[1] == '\0') || (file_name[1] == '.' && file_name[2] == '\0'))
return NULL;
}

while(file_name[i] != '\0' && file_name[i] != '.' && j < 8)
{
c = normalize_char(file_name[i++]);
Expand Down Expand Up @@ -1785,14 +1847,14 @@ CH376_U8 ch376_read_data_port(struct ch376 *ch376)
dbg_printf("[READ][DATA][CH376_CMD_CHECK_EXIST] setting data port to &%02x\n", data_out);
break;

case CH376_CMD_GET_FILE_SIZE:
case CH376_CMD_READ_VAR32:
if(ch376->nb_bytes_in_cmd_data)
{
if(ch376->nb_bytes_in_cmd_data != ch376->pos_rw_in_cmd_data)
{
data_out = ch376->cmd_data.CMD_FileSize[ch376->pos_rw_in_cmd_data];
data_out = ch376->cmd_data.CMD_VAR32[ch376->pos_rw_in_cmd_data];

dbg_printf("[READ][DATA][CH376_CMD_GET_FILE_SIZE] read &%02x from i/o buffer at position &%02x\n", data_out, ch376->pos_rw_in_cmd_data);
dbg_printf("[READ][DATA][CH376_CMD_READ_VAR32] read &%02x from i/o buffer at position &%02x\n", data_out, ch376->pos_rw_in_cmd_data);

if(++ch376->pos_rw_in_cmd_data == ch376->nb_bytes_in_cmd_data)
ch376->nb_bytes_in_cmd_data = 0;
Expand All @@ -1801,7 +1863,7 @@ CH376_U8 ch376_read_data_port(struct ch376 *ch376)
else
{
data_out = 0;
dbg_printf("[READ][DATA][CH376_CMD_GET_FILE_SIZE] nothing to read from i/o buffer\n");
dbg_printf("[READ][DATA][CH376_CMD_READ_VAR32] nothing to read from i/o buffer\n");
}

break;
Expand Down Expand Up @@ -1910,9 +1972,9 @@ void ch376_write_command_port(struct ch376 *ch376, CH376_U8 command)
dbg_printf("[WRITE][COMMAND][CH376_CMD_CHECK_EXIST] waiting for check byte\n");
break;

case CH376_CMD_GET_FILE_SIZE:
ch376->command = CH376_CMD_GET_FILE_SIZE;
dbg_printf("[WRITE][COMMAND][CH376_CMD_GET_FILE_SIZE] wait for &68 byte\n");
case CH376_CMD_READ_VAR32:
ch376->command = CH376_CMD_READ_VAR32;
dbg_printf("[WRITE][COMMAND][CH376_CMD_READ_VAR32] wait for var offset byte\n");
break;

case CH376_CMD_GET_IC_VER:
Expand Down Expand Up @@ -2396,18 +2458,18 @@ void ch376_write_data_port(struct ch376 *ch376, CH376_U8 data)
dbg_printf("[WRITE][DATA][CH376_CMD_CHECK_EXIST] got check byte &%02x\n", data);
break;

case CH376_CMD_GET_FILE_SIZE:
case CH376_CMD_READ_VAR32:
// dbg_printf("[WRITE][DATA][CH376_CMD_GET_FILE_SIZE] got &%02x byte\n", data);
if (data == 0x68)
if (data == CH376_VAR_FILE_SIZE)
{
CH376_S32 file_size = system_get_file_size(&ch376->context, ch376->current_file);

ch376->cmd_data.CMD_FileSize[0] = (CH376_U8)((file_size & 0x000000ff) >> 0);
ch376->cmd_data.CMD_FileSize[1] = (CH376_U8)((file_size & 0x0000ff00) >> 8);
ch376->cmd_data.CMD_FileSize[2] = (CH376_U8)((file_size & 0x00ff0000) >> 16);
ch376->cmd_data.CMD_FileSize[3] = (CH376_U8)((file_size & 0xff000000) >> 24);
ch376->cmd_data.CMD_VAR32[0] = (CH376_U8)((file_size & 0x000000ff) >> 0);
ch376->cmd_data.CMD_VAR32[1] = (CH376_U8)((file_size & 0x0000ff00) >> 8);
ch376->cmd_data.CMD_VAR32[2] = (CH376_U8)((file_size & 0x00ff0000) >> 16);
ch376->cmd_data.CMD_VAR32[3] = (CH376_U8)((file_size & 0xff000000) >> 24);

ch376->nb_bytes_in_cmd_data = sizeof(ch376->cmd_data.CMD_FileSize);
ch376->nb_bytes_in_cmd_data = sizeof(ch376->cmd_data.CMD_VAR32);
ch376->pos_rw_in_cmd_data = 0;

dbg_printf("[WRITE][DATA][CH376_CMD_GET_FILE_SIZE] done, file size is %d, waiting for data read\n", file_size);
Expand All @@ -2416,9 +2478,27 @@ void ch376_write_data_port(struct ch376 *ch376, CH376_U8 data)
ch376->interface_status = 127;
ch376->command_status = CH376_INT_SUCCESS;
}
else if(data == CH376_VAR_CURRENT_OFFSET)
{
CH376_S32 file_offset = system_get_file_offset(&ch376->context, ch376->current_file);

ch376->cmd_data.CMD_VAR32[0] = (CH376_U8)((file_offset & 0x000000ff) >> 0);
ch376->cmd_data.CMD_VAR32[1] = (CH376_U8)((file_offset & 0x0000ff00) >> 8);
ch376->cmd_data.CMD_VAR32[2] = (CH376_U8)((file_offset & 0x00ff0000) >> 16);
ch376->cmd_data.CMD_VAR32[3] = (CH376_U8)((file_offset & 0xff000000) >> 24);

ch376->nb_bytes_in_cmd_data = sizeof(ch376->cmd_data.CMD_VAR32);
ch376->pos_rw_in_cmd_data = 0;

dbg_printf("[WRITE][DATA][CH376_CMD_GET_FILE_OFFSET] done, file position is %d, waiting for data read\n", file_offset);

// Lignes suivantes utiles?
ch376->interface_status = 127;
ch376->command_status = CH376_INT_SUCCESS;
}
else
{
dbg_printf("[WRITE][DATA][CH376_CMD_GET_FILE_SIZE] wrong command byte: looking for &68, got &%02x\n", data);
dbg_printf("[WRITE][DATA][CH376_CMD_READ_VAR32] wrong command byte: looking for &68 or &6c, got &%02x\n", data);

ch376->interface_status = 0;
ch376->command_status = CH376_RET_ABORT;
Expand Down Expand Up @@ -2654,4 +2734,4 @@ const char * ch376_get_usb_drive_path(struct ch376 *ch376)
{
return ch376->usb_drive_path;
}
/* /// */
/* /// */
1 change: 0 additions & 1 deletion plugins/ch376/oric_ch376_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void ch376_oric_write(struct ch376 *ch376, Uint16 addr, Uint8 data)
ch376_write_command_port(ch376, data);
}
}


unsigned char ch376_oric_read(struct ch376 *ch376, Uint16 addr)
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/ch376/oric_ch376_plugin.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct ch376 * ch376_oric_init(void);
void ch376_oric_reset(struct ch376 *ch376);
void ch376_oric_write(struct ch376 *ch376, Uint16 addr, Uint8 data);
void ch376_oric_write(struct ch376 *ch376, Uint16 addr, Uint8 data);
unsigned char ch376_oric_read(struct ch376 *ch376, Uint16 addr);
void ch376_oric_config(struct ch376 *ch376);
void ch376_oric_destroy(struct ch376 *ch376);
Expand Down
7 changes: 7 additions & 0 deletions plugins/twilighte_board/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Twilighte board emulation

## Firmware 1 vs Firmware 2

Firmware 2 manage a mirroring of ram overlay management in $314.

It means that firmware 2, when $314 select internal ram overlay in the oric, it selects instead bank 0 (RAM) of the twilighte board.
Loading

0 comments on commit 8cf6b98

Please sign in to comment.