Search
lxdream.org :: lxdream/src/dream.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/dream.h
changeset 135:2b05ea3d87c1
prev119:cef4d880123c
next180:e6dcf9b65658
author nkeynes
date Sun Apr 30 01:48:38 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Add max() macro (if it's not already defined)
file annotate diff log raw
nkeynes@31
     1
/**
nkeynes@135
     2
 * $Id: dream.h,v 1.9 2006-04-30 01:48:38 nkeynes Exp $
nkeynes@31
     3
 *
nkeynes@31
     4
 * Miscellaneous application-wide declarations (mainly logging atm)
nkeynes@31
     5
 *
nkeynes@31
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@31
     7
 *
nkeynes@31
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@31
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@31
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@31
    11
 * (at your option) any later version.
nkeynes@31
    12
 *
nkeynes@31
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@31
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@31
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@31
    16
 * GNU General Public License for more details.
nkeynes@1
    17
 */
nkeynes@31
    18
nkeynes@1
    19
#ifndef dream_H
nkeynes@1
    20
#define dream_H 1
nkeynes@1
    21
nkeynes@35
    22
#include <stdio.h>
nkeynes@9
    23
#include <stdlib.h>
nkeynes@2
    24
#include <stdint.h>
nkeynes@9
    25
#include <string.h>
nkeynes@30
    26
#include <glib/gtypes.h>
nkeynes@2
    27
nkeynes@1
    28
#ifdef __cplusplus
nkeynes@1
    29
extern "C" {
nkeynes@1
    30
#endif
nkeynes@35
    31
nkeynes@35
    32
/************************ Modules ********************************/
nkeynes@35
    33
/**
nkeynes@35
    34
 * Basic module structure defining the common operations across all
nkeynes@35
    35
 * modules, ie start, stop, reset, etc. 
nkeynes@35
    36
 */
nkeynes@35
    37
typedef struct dreamcast_module {
nkeynes@35
    38
    char *name;
nkeynes@35
    39
    /**
nkeynes@35
    40
     * Perform all initial module setup (ie register / allocate any
nkeynes@35
    41
     * memory required, etc). Only called once during DreamOn startup
nkeynes@35
    42
     */
nkeynes@35
    43
    void (*init)();
nkeynes@35
    44
    /**
nkeynes@35
    45
     * Reset the module into it's initial system boot state. Will be called
nkeynes@35
    46
     * once after init(), as well as whenever the user requests a reset.
nkeynes@35
    47
     */
nkeynes@35
    48
    void (*reset)();
nkeynes@35
    49
    /**
nkeynes@35
    50
     * Set the module into a running state (may be NULL)
nkeynes@35
    51
     */
nkeynes@35
    52
    void (*start)();
nkeynes@35
    53
    /**
nkeynes@35
    54
     * Execute one time-slice worth of operations, for the given number of
nkeynes@35
    55
     * nanoseconds.
nkeynes@35
    56
     * @return Number of nanoseconds actually executed
nkeynes@35
    57
     */
nkeynes@35
    58
    uint32_t (*run_time_slice)( uint32_t nanosecs );
nkeynes@35
    59
    /**
nkeynes@35
    60
     * Set the module into a stopped state (may be NULL)
nkeynes@35
    61
     */
nkeynes@35
    62
    void (*stop)();
nkeynes@35
    63
    /**
nkeynes@35
    64
     * Save the module state to the FILE stream. May be NULL, in which case
nkeynes@35
    65
     * the module is considered to have no state.
nkeynes@35
    66
     */
nkeynes@35
    67
    void (*save)(FILE *);
nkeynes@35
    68
    /**
nkeynes@35
    69
     * Load the saved module state from the FILE stream. May be NULL, in which
nkeynes@35
    70
     * case reset() will be called instead.
nkeynes@35
    71
     * @return 0 on success, nonzero on failure.
nkeynes@35
    72
     */
nkeynes@35
    73
    int (*load)(FILE *);
nkeynes@35
    74
} *dreamcast_module_t;
nkeynes@35
    75
nkeynes@35
    76
void dreamcast_register_module( dreamcast_module_t );
nkeynes@35
    77
nkeynes@35
    78
extern struct dreamcast_module mem_module;
nkeynes@35
    79
extern struct dreamcast_module sh4_module;
nkeynes@35
    80
extern struct dreamcast_module asic_module;
nkeynes@35
    81
extern struct dreamcast_module pvr2_module;
nkeynes@35
    82
extern struct dreamcast_module aica_module;
nkeynes@35
    83
extern struct dreamcast_module ide_module;
nkeynes@35
    84
extern struct dreamcast_module maple_module;
nkeynes@35
    85
extern struct dreamcast_module pvr2_module;
nkeynes@35
    86
extern struct dreamcast_module gui_module;
nkeynes@35
    87
extern struct dreamcast_module unknown_module;
nkeynes@35
    88
nkeynes@35
    89
/*************************** Logging **************************/
nkeynes@1
    90
nkeynes@1
    91
#define EMIT_FATAL 0
nkeynes@1
    92
#define EMIT_ERR 1
nkeynes@1
    93
#define EMIT_WARN 2
nkeynes@1
    94
#define EMIT_INFO 3
nkeynes@1
    95
#define EMIT_DEBUG 4
nkeynes@1
    96
#define EMIT_TRACE 5
nkeynes@1
    97
nkeynes@35
    98
#ifndef MODULE
nkeynes@35
    99
#define MODULE unknown_module
nkeynes@1
   100
#endif
nkeynes@1
   101
nkeynes@35
   102
void emit( void *, int level, const char *source, const char *msg, ... );
nkeynes@1
   103
nkeynes@35
   104
#define FATAL( ... ) emit( NULL, EMIT_FATAL, MODULE.name, __VA_ARGS__ )
nkeynes@35
   105
#define ERROR( ... ) emit( NULL, EMIT_ERR, MODULE.name, __VA_ARGS__ )
nkeynes@35
   106
#define WARN( ... ) emit( NULL, EMIT_WARN, MODULE.name, __VA_ARGS__ )
nkeynes@35
   107
#define INFO( ... ) emit( NULL, EMIT_INFO, MODULE.name, __VA_ARGS__ )
nkeynes@35
   108
#define DEBUG( ... ) emit( NULL, EMIT_DEBUG, MODULE.name, __VA_ARGS__ )
nkeynes@35
   109
#define TRACE( ... ) emit( NULL, EMIT_TRACE, MODULE.name, __VA_ARGS__ )
nkeynes@1
   110
nkeynes@1
   111
#define BIOS_PATH "../bios"
nkeynes@1
   112
nkeynes@35
   113
void fwrite_string( char *s, FILE *f );
nkeynes@35
   114
int fread_string( char *s, int maxlen, FILE *f );
nkeynes@119
   115
    void fwrite_dump( unsigned char *buf, unsigned int length, FILE *f );
nkeynes@35
   116
nkeynes@135
   117
#ifndef max
nkeynes@135
   118
#define max(a,b) ( (a) > (b) ? (a) : (b) )
nkeynes@135
   119
#endif
nkeynes@135
   120
nkeynes@1
   121
#ifdef __cplusplus
nkeynes@1
   122
}
nkeynes@1
   123
#endif
nkeynes@1
   124
#endif
.