Search
lxdream.org :: lxdream/src/bios.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/bios.c
changeset 1100:50e702af9373
prev1099:566cdeb157ec
next1101:78e762cec843
author nkeynes
date Mon Feb 15 17:27:14 2010 +1000 (10 years ago)
permissions -rw-r--r--
last change Hook up the fake bios boot
Use fakebios if invoked with -b, or if there's no boot rom loaded
file annotate diff log raw
1.1 --- a/src/bios.c Wed Feb 10 18:16:19 2010 +1000
1.2 +++ b/src/bios.c Mon Feb 15 17:27:14 2010 +1000
1.3 @@ -3,7 +3,7 @@
1.4 *
1.5 * "Fake" BIOS functions, for operation without the actual BIOS.
1.6 *
1.7 - * Copyright (c) 2005 Nathan Keynes.
1.8 + * Copyright (c) 2005-2010 Nathan Keynes.
1.9 *
1.10 * This program is free software; you can redistribute it and/or modify
1.11 * it under the terms of the GNU General Public License as published by
1.12 @@ -19,6 +19,7 @@
1.13 #include "dream.h"
1.14 #include "mem.h"
1.15 #include "syscall.h"
1.16 +#include "asic.h"
1.17 #include "dreamcast.h"
1.18 #include "bootstrap.h"
1.19 #include "sh4/sh4.h"
1.20 @@ -26,51 +27,73 @@
1.21 #include "drivers/cdrom/isoread.h"
1.22 #include "gdrom/gdrom.h"
1.23
1.24 +/* Definitions from KOS */
1.25 #define COMMAND_QUEUE_LENGTH 16
1.26
1.27 -/* TODO: Check if these are the real ATAPI command codes or not */
1.28 -#define GD_CMD_PIOREAD 16
1.29 -#define GD_CMD_DMAREAD 17
1.30 +#define GD_CMD_PIOREAD 16 /* readcd */
1.31 +#define GD_CMD_DMAREAD 17 /* readcd */
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_GETTOC2 19 /* toc2 */
1.40 +#define GD_CMD_PLAY 20 /* playcd */
1.41 +#define GD_CMD_PLAY2 21 /* playcd */
1.42 +#define GD_CMD_PAUSE 22 /* No params */
1.43 +#define GD_CMD_RELEASE 23 /* No params */
1.44 +#define GD_CMD_INIT 24 /* No params */
1.45 #define GD_CMD_SEEK 27
1.46 #define GD_CMD_READ 28
1.47 -#define GD_CMD_STOP 33
1.48 +#define GD_CMD_STOP 33 /* No params */
1.49 #define GD_CMD_GETSCD 34
1.50 #define GD_CMD_GETSES 35
1.51
1.52 -#define GD_CMD_STATUS_NONE 0
1.53 +#define GD_CMD_STATUS_NONE 0
1.54 #define GD_CMD_STATUS_ACTIVE 1
1.55 -#define GD_CMD_STATUS_DONE 2
1.56 -#define GD_CMD_STATUS_ABORT 3
1.57 -#define GD_CMD_STATUS_ERROR 4
1.58 +#define GD_CMD_STATUS_DONE 2
1.59 +#define GD_CMD_STATUS_ABORT 3
1.60 +#define GD_CMD_STATUS_ERROR 4
1.61
1.62 #define GD_ERROR_OK 0
1.63 #define GD_ERROR_NO_DISC 2
1.64 #define GD_ERROR_DISC_CHANGE 6
1.65 #define GD_ERROR_SYSTEM 1
1.66
1.67 +typedef union gdrom_cmd_params {
1.68 + struct gdrom_toc2_params {
1.69 + uint32_t session;
1.70 + sh4addr_t buffer;
1.71 + } toc2;
1.72
1.73 -typedef struct gdrom_command {
1.74 + struct gdrom_readcd_params {
1.75 + cdrom_lba_t sector;
1.76 + cdrom_count_t count;
1.77 + sh4addr_t buffer;
1.78 + uint32_t unknown;
1.79 + } readcd;
1.80 +
1.81 + struct gdrom_playcd_params {
1.82 + cdrom_lba_t start;
1.83 + cdrom_lba_t end;
1.84 + uint32_t repeat;
1.85 + } playcd;
1.86 +} *gdrom_cmd_params_t;
1.87 +
1.88 +
1.89 +
1.90 +
1.91 +typedef struct gdrom_queue_entry {
1.92 int status;
1.93 uint32_t cmd_code;
1.94 sh4ptr_t data;
1.95 uint32_t result[4];
1.96 -} *gdrom_command_t;
1.97 +} *gdrom_queue_entry_t;
1.98
1.99 -static struct gdrom_command gdrom_cmd_queue[COMMAND_QUEUE_LENGTH];
1.100 +static struct gdrom_queue_entry gdrom_cmd_queue[COMMAND_QUEUE_LENGTH];
1.101
1.102 static struct bios_gdrom_status {
1.103 uint32_t status;
1.104 uint32_t disk_type;
1.105 } bios_gdrom_status;
1.106
1.107 -void bios_gdrom_run_command( gdrom_command_t cmd )
1.108 +void bios_gdrom_run_command( gdrom_queue_entry_t cmd )
1.109 {
1.110 DEBUG( "BIOS GD command %d", cmd->cmd_code );
1.111 switch( cmd->cmd_code ) {
1.112 @@ -114,7 +137,7 @@
1.113 }
1.114 }
1.115
1.116 -gdrom_command_t bios_gdrom_get_command( uint32_t id )
1.117 +gdrom_queue_entry_t bios_gdrom_get_command( uint32_t id )
1.118 {
1.119 if( id >= COMMAND_QUEUE_LENGTH ||
1.120 gdrom_cmd_queue[id].status == GD_CMD_STATUS_NONE )
1.121 @@ -128,7 +151,7 @@
1.122
1.123 void bios_syscall( uint32_t syscallid )
1.124 {
1.125 - gdrom_command_t cmd;
1.126 + gdrom_queue_entry_t cmd;
1.127
1.128 switch( syscallid ) {
1.129 case 0xB0: /* sysinfo */
1.130 @@ -211,7 +234,11 @@
1.131 {
1.132 /* Initialize hardware */
1.133 /* Boot disc if present */
1.134 - bios_boot_gdrom_disc();
1.135 + if( bios_boot_gdrom_disc() ) {
1.136 + sh4r.pr = sh4r.pc; /* Set the syscall return address to the bootstrap entry */
1.137 + } else {
1.138 + dreamcast_stop();
1.139 + }
1.140 }
1.141
1.142 void bios_install( void )
1.143 @@ -302,6 +329,7 @@
1.144 isofs_reader_destroy(iso);
1.145 return FALSE;
1.146 }
1.147 + asic_enable_ide_interface(TRUE);
1.148 } else {
1.149 /* Load the binary into a temp buffer */
1.150 unsigned char tmp[program_sectors*2048];
1.151 @@ -312,7 +340,9 @@
1.152 return FALSE;
1.153 }
1.154 bootprogram_unscramble(program, tmp, ent->size);
1.155 + asic_enable_ide_interface(FALSE);
1.156 }
1.157 isofs_reader_destroy(iso);
1.158 - dreamcast_program_loaded( "", BOOTSTRAP_LOAD_ADDR );
1.159 + dreamcast_program_loaded( "", BOOTSTRAP_ENTRY_ADDR );
1.160 + return TRUE;
1.161 }
.