filename | src/dcload.c |
changeset | 183:5938ecc01dc8 |
prev | 182:e3b513538548 |
next | 209:ff67a7b9aa17 |
author | nkeynes |
date | Sat Aug 05 00:18:21 2006 +0000 (17 years ago) |
permissions | -rw-r--r-- |
last change | Add error lines to tests with incomplete polys Split clip tests to separate data file Add tests for cmd bit 23 ("use list size field") |
view | annotate | diff | log | raw |
1 /**
2 * $Id: dcload.c,v 1.5 2006-07-06 22:44:39 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 "dreamcast.h"
22 #include "mem.h"
23 #include "syscall.h"
24 #include "sh4/sh4core.h"
26 #define SYS_READ 0
27 #define SYS_WRITE 1
28 #define SYS_OPEN 2
29 #define SYS_CLOSE 3
30 #define SYS_CREAT 4
31 #define SYS_LINK 5
32 #define SYS_UNLINK 6
33 #define SYS_CHDIR 7
34 #define SYS_CHMOD 8
35 #define SYS_LSEEK 9
36 #define SYS_FSTAT 10
37 #define SYS_TIME 11
38 #define SYS_STAT 12
39 #define SYS_UTIME 13
40 #define SYS_ASSIGNWRKMEM 14
41 #define SYS_EXIT 15
42 #define SYS_OPENDIR 16
43 #define SYS_CLOSEDIR 17
44 #define SYS_READDIR 18
45 #define SYS_GETHOSTINFO 19
47 #define SYS_MAGIC 0xDEADBEEF
48 #define SYS_MAGIC_ADDR 0x8c004004
49 #define SYSCALL_ADDR 0x8c004008
51 static gboolean dcload_allow_exit = FALSE;
53 void dcload_set_allow_exit( gboolean allow )
54 {
55 dcload_allow_exit = allow;
56 }
58 void dcload_syscall( uint32_t syscall_id )
59 {
60 uint32_t syscall = sh4r.r[4];
61 switch( sh4r.r[4] ) {
62 case SYS_READ:
63 if( sh4r.r[5] == 0 ) {
64 char *buf = mem_get_region( sh4r.r[6] );
65 int length = sh4r.r[7];
66 sh4r.r[0] = read( 0, buf, length );
67 } else {
68 sh4r.r[0] = -1;
69 }
70 break;
71 case SYS_WRITE:
72 if( sh4r.r[5] == 1 || sh4r.r[5] == 2 ) {
73 char *buf = mem_get_region( sh4r.r[6] );
74 int length = sh4r.r[7];
75 sh4r.r[0] = write( sh4r.r[5], buf, length );
76 } else {
77 sh4r.r[0] = -1;
78 }
79 break;
80 case SYS_EXIT:
81 if( dcload_allow_exit )
82 exit( sh4r.r[5] );
83 else
84 dreamcast_stop();
85 default:
86 sh4r.r[0] = -1;
87 }
89 }
91 void dcload_install()
92 {
93 syscall_add_hook_vector( 0xF0, SYSCALL_ADDR, dcload_syscall );
94 sh4_write_long( SYS_MAGIC_ADDR, SYS_MAGIC );
95 }
.