Search
lxdream.org :: lxdream/src/bios.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/bios.c
changeset 102:844a3f2a76ff
prev87:11208d725b61
next422:61a0598e07ff
author nkeynes
date Mon Mar 13 12:38:39 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Refactor bios into more generic syscall structure. Add initial hooks for
dc-load functions
file annotate diff log raw
nkeynes@87
     1
/**
nkeynes@102
     2
 * $Id: bios.c,v 1.2 2006-03-13 12:38:34 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@102
    21
#include "syscall.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
/**
nkeynes@87
   121
 * Syscall list courtesy of Marcus Comstedt
nkeynes@87
   122
 */
nkeynes@87
   123
nkeynes@87
   124
void bios_syscall( uint32_t syscallid )
nkeynes@87
   125
{
nkeynes@87
   126
    gdrom_command_t cmd;
nkeynes@87
   127
nkeynes@87
   128
    switch( syscallid ) {
nkeynes@87
   129
    case 0xB0: /* sysinfo */
nkeynes@87
   130
	break;
nkeynes@87
   131
    case 0xB4: /* Font */
nkeynes@87
   132
	break;
nkeynes@87
   133
    case 0xB8: /* Flash */
nkeynes@87
   134
	break;
nkeynes@87
   135
    case 0xBC: /* Misc/GD-Rom */
nkeynes@87
   136
	switch( sh4r.r[6] ) {
nkeynes@87
   137
	case 0: /* GD-Rom */
nkeynes@87
   138
	    switch( sh4r.r[7] ) {
nkeynes@87
   139
	    case 0: /* Send command */
nkeynes@87
   140
		if( sh4r.r[5] == 0 )
nkeynes@87
   141
		    sh4r.r[0] = bios_gdrom_enqueue( sh4r.r[4], NULL );
nkeynes@87
   142
		else
nkeynes@87
   143
		    sh4r.r[0] = bios_gdrom_enqueue( sh4r.r[4], mem_get_region(sh4r.r[5]) );
nkeynes@87
   144
		break;
nkeynes@87
   145
	    case 1:  /* Check command */
nkeynes@87
   146
		cmd = bios_gdrom_get_command( sh4r.r[4] );
nkeynes@87
   147
		if( cmd == NULL ) {
nkeynes@87
   148
		    sh4r.r[0] = GD_CMD_STATUS_NONE;
nkeynes@87
   149
		} else {
nkeynes@87
   150
		    sh4r.r[0] = cmd->status;
nkeynes@87
   151
		    if( cmd->status == GD_CMD_STATUS_ERROR &&
nkeynes@87
   152
			sh4r.r[5] != 0 ) {
nkeynes@87
   153
			mem_copy_to_sh4( sh4r.r[5], &cmd->result, sizeof(cmd->result) );
nkeynes@87
   154
		    }
nkeynes@87
   155
		}
nkeynes@87
   156
		break;
nkeynes@87
   157
	    case 2: /* Mainloop */
nkeynes@87
   158
		bios_gdrom_run_queue();
nkeynes@87
   159
		break;
nkeynes@87
   160
	    case 3: /* Init */
nkeynes@87
   161
		bios_gdrom_init();
nkeynes@87
   162
		break;
nkeynes@87
   163
	    case 4: /* Drive status */
nkeynes@87
   164
		if( sh4r.r[4] != 0 ) {
nkeynes@87
   165
		    mem_copy_to_sh4( sh4r.r[4], &bios_gdrom_status, 
nkeynes@87
   166
				      sizeof(bios_gdrom_status) );
nkeynes@87
   167
		}
nkeynes@87
   168
		sh4r.r[0] = 0;
nkeynes@87
   169
		break;
nkeynes@87
   170
	    case 8: /* Abort command */
nkeynes@87
   171
		cmd = bios_gdrom_get_command( sh4r.r[4] );
nkeynes@87
   172
		if( cmd == NULL || cmd->status != GD_CMD_STATUS_ACTIVE ) {
nkeynes@87
   173
		    sh4r.r[0] = -1;
nkeynes@87
   174
		} else {
nkeynes@87
   175
		    cmd->status = GD_CMD_STATUS_ABORT;
nkeynes@87
   176
		    sh4r.r[0] = 0;
nkeynes@87
   177
		}
nkeynes@87
   178
		break;
nkeynes@87
   179
	    case 9: /* Reset */
nkeynes@87
   180
		break;
nkeynes@87
   181
	    case 10: /* Set mode */
nkeynes@87
   182
		sh4r.r[0] = 0;
nkeynes@87
   183
		break;
nkeynes@87
   184
	    }
nkeynes@87
   185
	    break;
nkeynes@87
   186
	case -1: /* Misc */
nkeynes@87
   187
	    break;
nkeynes@87
   188
	default: /* ??? */
nkeynes@87
   189
	    break;
nkeynes@87
   190
	}
nkeynes@87
   191
	break;
nkeynes@87
   192
    case 0xE0: /* Menu */
nkeynes@87
   193
	switch( sh4r.r[7] ) {
nkeynes@87
   194
	case 0:
nkeynes@87
   195
	    WARN( "Entering main program" );
nkeynes@87
   196
	    break;
nkeynes@87
   197
	case 1:
nkeynes@87
   198
	    WARN( "Program aborted to DC menu");
nkeynes@87
   199
	    dreamcast_stop();
nkeynes@87
   200
	    break;
nkeynes@87
   201
	}
nkeynes@87
   202
    }
nkeynes@87
   203
}
nkeynes@102
   204
nkeynes@102
   205
void bios_install( void ) 
nkeynes@102
   206
{
nkeynes@102
   207
    bios_gdrom_init();
nkeynes@102
   208
    syscall_add_hook_vector( 0xB0, 0x8C0000B0, bios_syscall );
nkeynes@102
   209
    syscall_add_hook_vector( 0xB4, 0x8C0000B4, bios_syscall );
nkeynes@102
   210
    syscall_add_hook_vector( 0xB8, 0x8C0000B8, bios_syscall );
nkeynes@102
   211
    syscall_add_hook_vector( 0xBC, 0x8C0000BC, bios_syscall );
nkeynes@102
   212
    syscall_add_hook_vector( 0xE0, 0x8C0000E0, bios_syscall );
nkeynes@102
   213
}
.