Search
lxdream.org :: lxdream/src/dcload.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/dcload.c
changeset 120:7e4549476110
prev106:9048bac046c3
next182:e3b513538548
author nkeynes
date Thu Jun 15 10:33:08 2006 +0000 (17 years ago)
permissions -rw-r--r--
last change Remove superfluous logging
view annotate diff log raw
     1 /**
     2  * $Id: dcload.c,v 1.3 2006-03-20 11:59:57 nkeynes Exp $
     3  * 
     4  * DC-load syscall implementation.
     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 <stdio.h>
    20 #include "dream.h"
    21 #include "mem.h"
    22 #include "syscall.h"
    23 #include "sh4/sh4core.h"
    25 #define SYS_READ 0
    26 #define SYS_WRITE 1
    27 #define SYS_OPEN 2
    28 #define SYS_CLOSE 3
    29 #define SYS_CREAT 4
    30 #define SYS_LINK 5
    31 #define SYS_UNLINK 6
    32 #define SYS_CHDIR 7
    33 #define SYS_CHMOD 8
    34 #define SYS_LSEEK 9
    35 #define SYS_FSTAT 10
    36 #define SYS_TIME 11
    37 #define SYS_STAT 12
    38 #define SYS_UTIME 13
    39 #define SYS_ASSIGNWRKMEM 14
    40 #define SYS_EXIT 15
    41 #define SYS_OPENDIR 16
    42 #define SYS_CLOSEDIR 17
    43 #define SYS_READDIR 18
    44 #define SYS_GETHOSTINFO 19
    46 #define SYS_MAGIC 0xDEADBEEF
    47 #define SYS_MAGIC_ADDR 0x8c004004
    48 #define SYSCALL_ADDR 0x8c004008
    50 void dcload_syscall( uint32_t syscall_id ) 
    51 {
    52     uint32_t syscall = sh4r.r[4];
    53     switch( sh4r.r[4] ) {
    54     case SYS_READ:
    55 	if( sh4r.r[5] == 0 ) {
    56 	    char *buf = mem_get_region( sh4r.r[6] );
    57 	    int length = sh4r.r[7];
    58 	    sh4r.r[0] = read( 0, buf, length );
    59 	} else {
    60 	    sh4r.r[0] = -1;
    61 	}
    62 	break;
    63     case SYS_WRITE:
    64 	if( sh4r.r[5] == 1 || sh4r.r[5] == 2 ) {
    65 	    char *buf = mem_get_region( sh4r.r[6] );
    66 	    int length = sh4r.r[7];
    67 	    sh4r.r[0] = write( sh4r.r[5], buf, length );
    68 	} else {
    69 	    sh4r.r[0] = -1;
    70 	}
    71 	break;
    72     case SYS_EXIT:
    73 	/* exit( sh4r.r[4] ); */
    74 	dreamcast_stop();
    75     default:
    76 	sh4r.r[0] = -1;
    77     }
    79 }
    81 void dcload_install() 
    82 {
    83     syscall_add_hook_vector( 0xF0, SYSCALL_ADDR, dcload_syscall );
    84     sh4_write_long( SYS_MAGIC_ADDR, SYS_MAGIC );
    85 }
.