1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/bios.c Mon Mar 13 12:37:06 2006 +0000
1.5 + * $Id: bios.c,v 1.1 2006-01-22 22:40:53 nkeynes Exp $
1.7 + * "Fake" BIOS functions, for operation without the actual BIOS.
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.25 +#include "sh4/sh4core.h"
1.27 +#define COMMAND_QUEUE_LENGTH 16
1.29 +/* TODO: Check if these are the real ATAPI command codes or not */
1.30 +#define GD_CMD_PIOREAD 16
1.31 +#define GD_CMD_DMAREAD 17
1.32 +#define GD_CMD_GETTOC 18
1.33 +#define GD_CMD_GETTOC2 19
1.34 +#define GD_CMD_PLAY 20
1.35 +#define GD_CMD_PLAY2 21
1.36 +#define GD_CMD_PAUSE 22
1.37 +#define GD_CMD_RELEASE 23
1.38 +#define GD_CMD_INIT 24
1.39 +#define GD_CMD_SEEK 27
1.40 +#define GD_CMD_READ 28
1.41 +#define GD_CMD_STOP 33
1.42 +#define GD_CMD_GETSCD 34
1.43 +#define GD_CMD_GETSES 35
1.45 +#define GD_CMD_STATUS_NONE 0
1.46 +#define GD_CMD_STATUS_ACTIVE 1
1.47 +#define GD_CMD_STATUS_DONE 2
1.48 +#define GD_CMD_STATUS_ABORT 3
1.49 +#define GD_CMD_STATUS_ERROR 4
1.51 +#define GD_ERROR_OK 0
1.52 +#define GD_ERROR_NO_DISC 2
1.53 +#define GD_ERROR_DISC_CHANGE 6
1.54 +#define GD_ERROR_SYSTEM 1
1.57 +typedef struct gdrom_command {
1.59 + uint32_t cmd_code;
1.61 + uint32_t result[4];
1.62 +} *gdrom_command_t;
1.64 +static struct gdrom_command gdrom_cmd_queue[COMMAND_QUEUE_LENGTH];
1.66 +static struct bios_gdrom_status {
1.68 + uint32_t disk_type;
1.69 +} bios_gdrom_status;
1.71 +void bios_gdrom_run_command( gdrom_command_t cmd )
1.73 + DEBUG( "BIOS GD command %d", cmd->cmd_code );
1.74 + switch( cmd->cmd_code ) {
1.77 + cmd->status = GD_CMD_STATUS_DONE;
1.80 + cmd->status = GD_CMD_STATUS_ERROR;
1.81 + cmd->result[0] = GD_ERROR_SYSTEM;
1.86 +void bios_gdrom_init( void )
1.88 + memset( &gdrom_cmd_queue, 0, sizeof(gdrom_cmd_queue) );
1.91 +uint32_t bios_gdrom_enqueue( uint32_t cmd, char *ptr )
1.94 + for( i=0; i<COMMAND_QUEUE_LENGTH; i++ ) {
1.95 + if( gdrom_cmd_queue[i].status != GD_CMD_STATUS_ACTIVE ) {
1.96 + gdrom_cmd_queue[i].status = GD_CMD_STATUS_ACTIVE;
1.97 + gdrom_cmd_queue[i].cmd_code = cmd;
1.98 + gdrom_cmd_queue[i].data = ptr;
1.105 +void bios_gdrom_run_queue( void )
1.108 + for( i=0; i<COMMAND_QUEUE_LENGTH; i++ ) {
1.109 + if( gdrom_cmd_queue[i].status == GD_CMD_STATUS_ACTIVE ) {
1.110 + bios_gdrom_run_command( &gdrom_cmd_queue[i] );
1.115 +gdrom_command_t bios_gdrom_get_command( uint32_t id )
1.117 + if( id >= COMMAND_QUEUE_LENGTH ||
1.118 + gdrom_cmd_queue[id].status == GD_CMD_STATUS_NONE )
1.120 + return &gdrom_cmd_queue[id];
1.123 +void bios_install( void )
1.125 + bios_gdrom_init();
1.126 + sh4_write_long( 0x8C0000B0, 0xFFFFFFB0 );
1.127 + sh4_write_long( 0x8C0000B4, 0xFFFFFFB4 );
1.128 + sh4_write_long( 0x8C0000B8, 0xFFFFFFB8 );
1.129 + sh4_write_long( 0x8C0000BC, 0xFFFFFFBC );
1.130 + sh4_write_long( 0x8C0000E0, 0xFFFFFFE0 );
1.134 + * Syscall list courtesy of Marcus Comstedt
1.137 +void bios_syscall( uint32_t syscallid )
1.139 + gdrom_command_t cmd;
1.141 + switch( syscallid ) {
1.142 + case 0xB0: /* sysinfo */
1.144 + case 0xB4: /* Font */
1.146 + case 0xB8: /* Flash */
1.148 + case 0xBC: /* Misc/GD-Rom */
1.149 + switch( sh4r.r[6] ) {
1.150 + case 0: /* GD-Rom */
1.151 + switch( sh4r.r[7] ) {
1.152 + case 0: /* Send command */
1.153 + if( sh4r.r[5] == 0 )
1.154 + sh4r.r[0] = bios_gdrom_enqueue( sh4r.r[4], NULL );
1.156 + sh4r.r[0] = bios_gdrom_enqueue( sh4r.r[4], mem_get_region(sh4r.r[5]) );
1.158 + case 1: /* Check command */
1.159 + cmd = bios_gdrom_get_command( sh4r.r[4] );
1.160 + if( cmd == NULL ) {
1.161 + sh4r.r[0] = GD_CMD_STATUS_NONE;
1.163 + sh4r.r[0] = cmd->status;
1.164 + if( cmd->status == GD_CMD_STATUS_ERROR &&
1.165 + sh4r.r[5] != 0 ) {
1.166 + mem_copy_to_sh4( sh4r.r[5], &cmd->result, sizeof(cmd->result) );
1.170 + case 2: /* Mainloop */
1.171 + bios_gdrom_run_queue();
1.173 + case 3: /* Init */
1.174 + bios_gdrom_init();
1.176 + case 4: /* Drive status */
1.177 + if( sh4r.r[4] != 0 ) {
1.178 + mem_copy_to_sh4( sh4r.r[4], &bios_gdrom_status,
1.179 + sizeof(bios_gdrom_status) );
1.183 + case 8: /* Abort command */
1.184 + cmd = bios_gdrom_get_command( sh4r.r[4] );
1.185 + if( cmd == NULL || cmd->status != GD_CMD_STATUS_ACTIVE ) {
1.188 + cmd->status = GD_CMD_STATUS_ABORT;
1.192 + case 9: /* Reset */
1.194 + case 10: /* Set mode */
1.199 + case -1: /* Misc */
1.201 + default: /* ??? */
1.205 + case 0xE0: /* Menu */
1.206 + switch( sh4r.r[7] ) {
1.208 + WARN( "Entering main program" );
1.211 + WARN( "Program aborted to DC menu");
1.212 + dreamcast_stop();