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