-//////////////////////////////////////////////////////////////////////////////
//
-//////////////////////////////////////////////////////////////////////////////
+// CD BIOS core
//
-// 20.02.2002: fixed sector to msf conversion
-// 19.02.2002: fixed a bug in toc encoding function
+// by cal2
+// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)
+// Cleanups by James L. Hammons
//
+// cal2:
+// 02/20/2002: fixed sector to msf conversion
+// 02/19/2002: fixed a bug in toc encoding function
//
-//
-//////////////////////////////////////////////////////////////////////////////
-#include "include/cdbios.h"
+
+#include "cdbios.h"
/* Added by SDLEMU (http://sdlemu.ngemu.com */
/* Some GCC UNIX includes */
#ifdef __GCCUNIX__
- #include <unistd.h>
+#include <unistd.h>
#endif
#define ERR_FLAG 0x3e00
#define CD_TOC 0x2c00
#define BIOS_VER 0x3004
-
#define CDBIOS_INIT 0
#define CDBIOS_INITM 1
#define CDBIOS_INITF 2
-
-
#define CD_INIT 0x3000
#define CD_MODE 0x3006
#define CD_ACK 0x300C
#define CD_INITM 0x3060
#define CD_INITF 0x3066
-
-char *cdbios_command[]={"init","mode","ack","jeri","spin","stop","mute","umute","pause","upause",
- "read","uread","setup","ptr","osamp","getoc","initm","initf",
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+char * cdbios_command[] =
+ { "init", "mode", "ack", "jeri", "spin", "stop", "mute", "umute", "pause", "upause",
+ "read", "uread", "setup", "ptr", "osamp", "getoc", "initm", "initf",
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
#define CDROM_AUDIO_MODE 0
#define CDROM_DATA_MODE 1
#define CDROM_STATUS_OK 0
#define CDROM_STATUS_ERROR 1
-
uint32 cdrom_mode = CDROM_DATA_MODE;
uint32 cdrom_speed = CDROM_SINGLE_SPEED;
uint32 cdrom_oversample_factor = 1;
-uint32 cdbios_session=0;
+uint32 cdbios_session = 0;
uint32 cdrom_destination_buffer_beginning;
uint32 cdrom_destination_buffer_end;
uint32 cdrom_circular_buffer_size;
uint32 cdbios_init_type;
-uint32 *cdbios_sector_lut;
-uint32 cdbios_init_done=0;
+uint32 * cdbios_sector_lut;
+uint32 cdbios_init_done = 0;
+
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
void cdbios_build_sector_lut(void)
{
uint32 last_sector=0;
}
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_get_time(uint32 sectors, uint32 *mm, uint32 *ss, uint32 *ff)
{
uint32 _sectors=sectors;
// fprintf(log_get(),"[%.2i:%.2i:%.2i]\n",_mm,_ss,_ff);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_encode_toc(void)
{
int i;
}
}
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_decode_toc(void)
{
uint32 addr=0x2c00;
nb_tracks--;
}
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cd_bios_boot(char *filename)
{
cd_bios_init();
// fprintf(log_get(),"cdbios: boot code:\n");
// jaguar_dasm(cdi_load_address, cdi_code_length);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cd_bios_init(void)
{
fprintf(log_get(),"cd_bios: initializing\n");
cd_bios_reset();
cdbios_init_done=1;
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cd_bios_reset(void)
{
fprintf(log_get(), "cd_bios: reset\n");
cdrom_oversample_factor = 1;
cdbios_session = 0;
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cd_bios_done(void)
{
- fprintf(log_get(),"cd_bios: done\n");
close(cdi_fp);
+ fprintf(log_get(), "CD BIOS: Done.\n");
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_init(void)
{
cdbios_init_type = CDBIOS_INIT;
jaguar_word_write(ERR_FLAG, CDROM_STATUS_OK);
fprintf(log_get(), "cdbios: init(0x%.8x)\n", m68k_get_reg(NULL, M68K_REG_A0));
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_mode(void)
{
// uint32 data = s68000context.dreg[0];
// fprintf(log_get(),"cdbios: %s\n",(cdrom_mode==CDROM_AUDIO_MODE)?"audio mode":"data mode");
// fprintf(log_get(),"cdbios: %s\n",(cdrom_speed==CDROM_DOUBLE_SPEED)?"double speed":"single speed");
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_ack(void)
{
jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_jeri(void)
{
jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_spin(void)
{
// uint16 spin=(1<<(s68000context.dreg[0]&0xffff));
jaguar_word_write(ERR_FLAG, CDROM_STATUS_OK);
// fprintf(log_get(),"cdbios: switching to session %i\n",spin);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_stop(void)
{
jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_mute(void)
{
jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_umute(void)
{
jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_pause(void)
{
jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_upause(void)
{
jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK);
count--;
}
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_read(void)
{
static uint8 cdbios_sector[2352];
}
jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_uread(void)
{
// stop the recording started with a cd_read command
// for now, there is nothing to do
jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_setup(void)
{
// initialize the cd system
jaguar_word_write(ERR_FLAG, CDROM_STATUS_OK);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_ptr(void)
{
// s68000context.areg[0]=cdrom_destination_buffer_end+4;
m68k_set_reg(M68K_REG_A0, cdrom_destination_buffer_end + 4);
jaguar_word_write(ERR_FLAG, CDROM_STATUS_OK);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_osamp(void)
{
// cdrom_oversample_factor=(1<<(s68000context.dreg[0]&0xffff));
cdrom_oversample_factor = 1 << (m68k_get_reg(NULL, M68K_REG_D0) & 0xFFFF);
jaguar_word_write(ERR_FLAG, CDROM_STATUS_OK);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_gettoc(void)
{
jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_initm(void)
{
cdbios_init_type = CDBIOS_INITM;
// fprintf(log_get(),"cdbios: initm(0x%.8x)\n",s68000context.areg[0]);
fprintf(log_get(), "cdbios: initm(0x%.8x)\n", m68k_get_reg(NULL, M68K_REG_A0));
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cdbios_cmd_initf(void)
{
cdbios_init_type = CDBIOS_INITF;
// fprintf(log_get(),"cdbios: initf(0x%.8x)\n",s68000context.areg[0]);
fprintf(log_get(), "cdbios: initf(0x%.8x)\n", m68k_get_reg(NULL, M68K_REG_A0));
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cd_bios_process(uint32 offset)
{
if (!cdbios_init_done)
m68k_set_reg(M68K_REG_PC, jaguar_long_read(m68k_get_reg(NULL, M68K_REG_A7)));
m68k_set_reg(M68K_REG_A7, (m68k_get_reg(NULL, M68K_REG_A7) + 4) & 0xFFFFFFFF);
}
-//////////////////////////////////////////////////////////////////////////////
-//
-//////////////////////////////////////////////////////////////////////////////
-//
-//
-//
-//
-//
-//
-//////////////////////////////////////////////////////////////////////////////
+
void cd_bios_exec(uint32 scanline)
{
// single speed mode: 150 Kb/s (153600 bytes/s)