Search
lxdream.org :: lxdream/src/bios.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/bios.c
changeset 87:11208d725b61
next102:844a3f2a76ff
author nkeynes
date Sun Jan 22 22:40:53 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Add dummied-up BIOS syscalls
file annotate diff log raw
nkeynes@87
     1
/**
nkeynes@87
     2
 * $Id: bios.c,v 1.1 2006-01-22 22:40:53 nkeynes Exp $
nkeynes@87
     3
 * 
nkeynes@87
     4
 * "Fake" BIOS functions, for operation without the actual BIOS.
nkeynes@87
     5
 *
nkeynes@87
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@87
     7
 *
nkeynes@87
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@87
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@87
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@87
    11
 * (at your option) any later version.
nkeynes@87
    12
 *
nkeynes@87
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@87
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@87
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@87
    16
 * GNU General Public License for more details.
nkeynes@87
    17
 */
nkeynes@87
    18
nkeynes@87
    19
#include "dream.h"
nkeynes@87
    20
#include "mem.h"
nkeynes@87
    21
#include "bios.h"
nkeynes@87
    22
#include "sh4/sh4core.h"
nkeynes@87
    23
nkeynes@87
    24
#define COMMAND_QUEUE_LENGTH 16
nkeynes@87
    25
nkeynes@87
    26
/* TODO: Check if these are the real ATAPI command codes or not */
nkeynes@87
    27
#define GD_CMD_PIOREAD     16
nkeynes@87
    28
#define GD_CMD_DMAREAD     17
nkeynes@87
    29
#define GD_CMD_GETTOC      18
nkeynes@87
    30
#define GD_CMD_GETTOC2     19
nkeynes@87
    31
#define GD_CMD_PLAY        20
nkeynes@87
    32
#define GD_CMD_PLAY2       21
nkeynes@87
    33
#define GD_CMD_PAUSE       22
nkeynes@87
    34
#define GD_CMD_RELEASE     23
nkeynes@87
    35
#define GD_CMD_INIT        24
nkeynes@87
    36
#define GD_CMD_SEEK        27
nkeynes@87
    37
#define GD_CMD_READ        28
nkeynes@87
    38
#define GD_CMD_STOP        33
nkeynes@87
    39
#define GD_CMD_GETSCD      34
nkeynes@87
    40
#define GD_CMD_GETSES      35
nkeynes@87
    41
nkeynes@87
    42
#define GD_CMD_STATUS_NONE 0
nkeynes@87
    43
#define GD_CMD_STATUS_ACTIVE 1
nkeynes@87
    44
#define GD_CMD_STATUS_DONE 2
nkeynes@87
    45
#define GD_CMD_STATUS_ABORT 3
nkeynes@87
    46
#define GD_CMD_STATUS_ERROR 4
nkeynes@87
    47
nkeynes@87
    48
#define GD_ERROR_OK          0
nkeynes@87
    49
#define GD_ERROR_NO_DISC     2
nkeynes@87
    50
#define GD_ERROR_DISC_CHANGE 6
nkeynes@87
    51
#define GD_ERROR_SYSTEM      1
nkeynes@87
    52
nkeynes@87
    53
nkeynes@87
    54
typedef struct gdrom_command {
nkeynes@87
    55
    int status;
nkeynes@87
    56
    uint32_t cmd_code;
nkeynes@87
    57
    char *data;
nkeynes@87
    58
    uint32_t result[4];
nkeynes@87
    59
} *gdrom_command_t;
nkeynes@87
    60
nkeynes@87
    61
static struct gdrom_command gdrom_cmd_queue[COMMAND_QUEUE_LENGTH];
nkeynes@87
    62
nkeynes@87
    63
static struct bios_gdrom_status {
nkeynes@87
    64
    uint32_t status;
nkeynes@87
    65
    uint32_t disk_type;
nkeynes@87
    66
} bios_gdrom_status;
nkeynes@87
    67
nkeynes@87
    68
void bios_gdrom_run_command( gdrom_command_t cmd )
nkeynes@87
    69
{
nkeynes@87
    70
    DEBUG( "BIOS GD command %d", cmd->cmd_code );
nkeynes@87
    71
    switch( cmd->cmd_code ) {
nkeynes@87
    72
    case GD_CMD_INIT:
nkeynes@87
    73
	/* *shrug* */
nkeynes@87
    74
	cmd->status = GD_CMD_STATUS_DONE;
nkeynes@87
    75
	break;
nkeynes@87
    76
    default:
nkeynes@87
    77
	cmd->status = GD_CMD_STATUS_ERROR;
nkeynes@87
    78
	cmd->result[0] = GD_ERROR_SYSTEM;
nkeynes@87
    79
	break;
nkeynes@87
    80
    }
nkeynes@87
    81
}
nkeynes@87
    82
nkeynes@87
    83
void bios_gdrom_init( void )
nkeynes@87
    84
{
nkeynes@87
    85
    memset( &gdrom_cmd_queue, 0, sizeof(gdrom_cmd_queue) );
nkeynes@87
    86
}
nkeynes@87
    87
nkeynes@87
    88
uint32_t bios_gdrom_enqueue( uint32_t cmd, char *ptr )
nkeynes@87
    89
{
nkeynes@87
    90
    int i;
nkeynes@87
    91
    for( i=0; i<COMMAND_QUEUE_LENGTH; i++ ) {
nkeynes@87
    92
	if( gdrom_cmd_queue[i].status != GD_CMD_STATUS_ACTIVE ) {
nkeynes@87
    93
	    gdrom_cmd_queue[i].status = GD_CMD_STATUS_ACTIVE;
nkeynes@87
    94
	    gdrom_cmd_queue[i].cmd_code = cmd;
nkeynes@87
    95
	    gdrom_cmd_queue[i].data = ptr;
nkeynes@87
    96
	    return i;
nkeynes@87
    97
	}
nkeynes@87
    98
    }
nkeynes@87
    99
    return -1;
nkeynes@87
   100
}
nkeynes@87
   101
nkeynes@87
   102
void bios_gdrom_run_queue( void ) 
nkeynes@87
   103
{
nkeynes@87
   104
    int i;
nkeynes@87
   105
    for( i=0; i<COMMAND_QUEUE_LENGTH; i++ ) {
nkeynes@87
   106
	if( gdrom_cmd_queue[i].status == GD_CMD_STATUS_ACTIVE ) {
nkeynes@87
   107
	    bios_gdrom_run_command( &gdrom_cmd_queue[i] );
nkeynes@87
   108
	}
nkeynes@87
   109
    }
nkeynes@87
   110
}
nkeynes@87
   111
nkeynes@87
   112
gdrom_command_t bios_gdrom_get_command( uint32_t id )
nkeynes@87
   113
{
nkeynes@87
   114
    if( id >= COMMAND_QUEUE_LENGTH ||
nkeynes@87
   115
	gdrom_cmd_queue[id].status == GD_CMD_STATUS_NONE )
nkeynes@87
   116
	return NULL;
nkeynes@87
   117
    return &gdrom_cmd_queue[id];
nkeynes@87
   118
}
nkeynes@87
   119
nkeynes@87
   120
void bios_install( void ) 
nkeynes@87
   121
{
nkeynes@87
   122
    bios_gdrom_init();
nkeynes@87
   123
    sh4_write_long( 0x8C0000B0, 0xFFFFFFB0 );
nkeynes@87
   124
    sh4_write_long( 0x8C0000B4, 0xFFFFFFB4 );
nkeynes@87
   125
    sh4_write_long( 0x8C0000B8, 0xFFFFFFB8 );
nkeynes@87
   126
    sh4_write_long( 0x8C0000BC, 0xFFFFFFBC );
nkeynes@87
   127
    sh4_write_long( 0x8C0000E0, 0xFFFFFFE0 );
nkeynes@87
   128
}
nkeynes@87
   129
nkeynes@87
   130
/**
nkeynes@87
   131
 * Syscall list courtesy of Marcus Comstedt
nkeynes@87
   132
 */
nkeynes@87
   133
nkeynes@87
   134
void bios_syscall( uint32_t syscallid )
nkeynes@87
   135
{
nkeynes@87
   136
    gdrom_command_t cmd;
nkeynes@87
   137
nkeynes@87
   138
    switch( syscallid ) {
nkeynes@87
   139
    case 0xB0: /* sysinfo */
nkeynes@87
   140
	break;
nkeynes@87
   141
    case 0xB4: /* Font */
nkeynes@87
   142
	break;
nkeynes@87
   143
    case 0xB8: /* Flash */
nkeynes@87
   144
	break;
nkeynes@87
   145
    case 0xBC: /* Misc/GD-Rom */
nkeynes@87
   146
	switch( sh4r.r[6] ) {
nkeynes@87
   147
	case 0: /* GD-Rom */
nkeynes@87
   148
	    switch( sh4r.r[7] ) {
nkeynes@87
   149
	    case 0: /* Send command */
nkeynes@87
   150
		if( sh4r.r[5] == 0 )
nkeynes@87
   151
		    sh4r.r[0] = bios_gdrom_enqueue( sh4r.r[4], NULL );
nkeynes@87
   152
		else
nkeynes@87
   153
		    sh4r.r[0] = bios_gdrom_enqueue( sh4r.r[4], mem_get_region(sh4r.r[5]) );
nkeynes@87
   154
		break;
nkeynes@87
   155
	    case 1:  /* Check command */
nkeynes@87
   156
		cmd = bios_gdrom_get_command( sh4r.r[4] );
nkeynes@87
   157
		if( cmd == NULL ) {
nkeynes@87
   158
		    sh4r.r[0] = GD_CMD_STATUS_NONE;
nkeynes@87
   159
		} else {
nkeynes@87
   160
		    sh4r.r[0] = cmd->status;
nkeynes@87
   161
		    if( cmd->status == GD_CMD_STATUS_ERROR &&
nkeynes@87
   162
			sh4r.r[5] != 0 ) {
nkeynes@87
   163
			mem_copy_to_sh4( sh4r.r[5], &cmd->result, sizeof(cmd->result) );
nkeynes@87
   164
		    }
nkeynes@87
   165
		}
nkeynes@87
   166
		break;
nkeynes@87
   167
	    case 2: /* Mainloop */
nkeynes@87
   168
		bios_gdrom_run_queue();
nkeynes@87
   169
		break;
nkeynes@87
   170
	    case 3: /* Init */
nkeynes@87
   171
		bios_gdrom_init();
nkeynes@87
   172
		break;
nkeynes@87
   173
	    case 4: /* Drive status */
nkeynes@87
   174
		if( sh4r.r[4] != 0 ) {
nkeynes@87
   175
		    mem_copy_to_sh4( sh4r.r[4], &bios_gdrom_status, 
nkeynes@87
   176
				      sizeof(bios_gdrom_status) );
nkeynes@87
   177
		}
nkeynes@87
   178
		sh4r.r[0] = 0;
nkeynes@87
   179
		break;
nkeynes@87
   180
	    case 8: /* Abort command */
nkeynes@87
   181
		cmd = bios_gdrom_get_command( sh4r.r[4] );
nkeynes@87
   182
		if( cmd == NULL || cmd->status != GD_CMD_STATUS_ACTIVE ) {
nkeynes@87
   183
		    sh4r.r[0] = -1;
nkeynes@87
   184
		} else {
nkeynes@87
   185
		    cmd->status = GD_CMD_STATUS_ABORT;
nkeynes@87
   186
		    sh4r.r[0] = 0;
nkeynes@87
   187
		}
nkeynes@87
   188
		break;
nkeynes@87
   189
	    case 9: /* Reset */
nkeynes@87
   190
		break;
nkeynes@87
   191
	    case 10: /* Set mode */
nkeynes@87
   192
		sh4r.r[0] = 0;
nkeynes@87
   193
		break;
nkeynes@87
   194
	    }
nkeynes@87
   195
	    break;
nkeynes@87
   196
	case -1: /* Misc */
nkeynes@87
   197
	    break;
nkeynes@87
   198
	default: /* ??? */
nkeynes@87
   199
	    break;
nkeynes@87
   200
	}
nkeynes@87
   201
	break;
nkeynes@87
   202
    case 0xE0: /* Menu */
nkeynes@87
   203
	switch( sh4r.r[7] ) {
nkeynes@87
   204
	case 0:
nkeynes@87
   205
	    WARN( "Entering main program" );
nkeynes@87
   206
	    break;
nkeynes@87
   207
	case 1:
nkeynes@87
   208
	    WARN( "Program aborted to DC menu");
nkeynes@87
   209
	    dreamcast_stop();
nkeynes@87
   210
	    break;
nkeynes@87
   211
	}
nkeynes@87
   212
    }
nkeynes@87
   213
}
.