Search
lxdream.org :: lxdream/src/dcload.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/dcload.c
changeset 183:5938ecc01dc8
prev182:e3b513538548
next209:ff67a7b9aa17
author nkeynes
date Thu Jul 06 22:44:39 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Use r5 for the exit value, not r4 (that was dumb...)
file annotate diff log raw
nkeynes@102
     1
/**
nkeynes@183
     2
 * $Id: dcload.c,v 1.5 2006-07-06 22:44:39 nkeynes Exp $
nkeynes@102
     3
 * 
nkeynes@102
     4
 * DC-load syscall implementation.
nkeynes@102
     5
 *
nkeynes@102
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@102
     7
 *
nkeynes@102
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@102
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@102
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@102
    11
 * (at your option) any later version.
nkeynes@102
    12
 *
nkeynes@102
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@102
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@102
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@102
    16
 * GNU General Public License for more details.
nkeynes@102
    17
 */
nkeynes@102
    18
nkeynes@102
    19
#include <stdio.h>
nkeynes@102
    20
#include "dream.h"
nkeynes@182
    21
#include "dreamcast.h"
nkeynes@102
    22
#include "mem.h"
nkeynes@102
    23
#include "syscall.h"
nkeynes@102
    24
#include "sh4/sh4core.h"
nkeynes@102
    25
nkeynes@102
    26
#define SYS_READ 0
nkeynes@102
    27
#define SYS_WRITE 1
nkeynes@102
    28
#define SYS_OPEN 2
nkeynes@102
    29
#define SYS_CLOSE 3
nkeynes@102
    30
#define SYS_CREAT 4
nkeynes@102
    31
#define SYS_LINK 5
nkeynes@102
    32
#define SYS_UNLINK 6
nkeynes@102
    33
#define SYS_CHDIR 7
nkeynes@102
    34
#define SYS_CHMOD 8
nkeynes@102
    35
#define SYS_LSEEK 9
nkeynes@102
    36
#define SYS_FSTAT 10
nkeynes@102
    37
#define SYS_TIME 11
nkeynes@102
    38
#define SYS_STAT 12
nkeynes@102
    39
#define SYS_UTIME 13
nkeynes@102
    40
#define SYS_ASSIGNWRKMEM 14
nkeynes@102
    41
#define SYS_EXIT 15
nkeynes@102
    42
#define SYS_OPENDIR 16
nkeynes@102
    43
#define SYS_CLOSEDIR 17
nkeynes@102
    44
#define SYS_READDIR 18
nkeynes@102
    45
#define SYS_GETHOSTINFO 19
nkeynes@102
    46
nkeynes@102
    47
#define SYS_MAGIC 0xDEADBEEF
nkeynes@102
    48
#define SYS_MAGIC_ADDR 0x8c004004
nkeynes@102
    49
#define SYSCALL_ADDR 0x8c004008
nkeynes@102
    50
nkeynes@182
    51
static gboolean dcload_allow_exit = FALSE;
nkeynes@182
    52
nkeynes@182
    53
void dcload_set_allow_exit( gboolean allow )
nkeynes@182
    54
{
nkeynes@182
    55
    dcload_allow_exit = allow;
nkeynes@182
    56
}
nkeynes@182
    57
nkeynes@102
    58
void dcload_syscall( uint32_t syscall_id ) 
nkeynes@102
    59
{
nkeynes@102
    60
    uint32_t syscall = sh4r.r[4];
nkeynes@102
    61
    switch( sh4r.r[4] ) {
nkeynes@102
    62
    case SYS_READ:
nkeynes@102
    63
	if( sh4r.r[5] == 0 ) {
nkeynes@102
    64
	    char *buf = mem_get_region( sh4r.r[6] );
nkeynes@102
    65
	    int length = sh4r.r[7];
nkeynes@102
    66
	    sh4r.r[0] = read( 0, buf, length );
nkeynes@102
    67
	} else {
nkeynes@102
    68
	    sh4r.r[0] = -1;
nkeynes@102
    69
	}
nkeynes@102
    70
	break;
nkeynes@102
    71
    case SYS_WRITE:
nkeynes@102
    72
	if( sh4r.r[5] == 1 || sh4r.r[5] == 2 ) {
nkeynes@102
    73
	    char *buf = mem_get_region( sh4r.r[6] );
nkeynes@102
    74
	    int length = sh4r.r[7];
nkeynes@102
    75
	    sh4r.r[0] = write( sh4r.r[5], buf, length );
nkeynes@102
    76
	} else {
nkeynes@102
    77
	    sh4r.r[0] = -1;
nkeynes@102
    78
	}
nkeynes@102
    79
	break;
nkeynes@102
    80
    case SYS_EXIT:
nkeynes@182
    81
	if( dcload_allow_exit ) 
nkeynes@183
    82
	    exit( sh4r.r[5] );
nkeynes@182
    83
	else
nkeynes@182
    84
	    dreamcast_stop();
nkeynes@102
    85
    default:
nkeynes@102
    86
	sh4r.r[0] = -1;
nkeynes@102
    87
    }
nkeynes@102
    88
nkeynes@102
    89
}
nkeynes@102
    90
nkeynes@102
    91
void dcload_install() 
nkeynes@102
    92
{
nkeynes@102
    93
    syscall_add_hook_vector( 0xF0, SYSCALL_ADDR, dcload_syscall );
nkeynes@102
    94
    sh4_write_long( SYS_MAGIC_ADDR, SYS_MAGIC );
nkeynes@102
    95
}
.