Search
lxdream.org :: lxdream/src/dream.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/dream.h
changeset 180:e6dcf9b65658
prev135:2b05ea3d87c1
next220:f72f8a7dff88
author nkeynes
date Sun Jul 02 04:59:00 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Merge changes made on the MILESTONE1 branch back into head (mostly
release touchups)
file annotate diff log raw
nkeynes@31
     1
/**
nkeynes@180
     2
 * $Id: dream.h,v 1.10 2006-07-02 04:59:00 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@180
    32
#define APP_NAME "lxDream"
nkeynes@180
    33
nkeynes@35
    34
/************************ Modules ********************************/
nkeynes@35
    35
/**
nkeynes@35
    36
 * Basic module structure defining the common operations across all
nkeynes@35
    37
 * modules, ie start, stop, reset, etc. 
nkeynes@35
    38
 */
nkeynes@35
    39
typedef struct dreamcast_module {
nkeynes@35
    40
    char *name;
nkeynes@35
    41
    /**
nkeynes@35
    42
     * Perform all initial module setup (ie register / allocate any
nkeynes@180
    43
     * memory required, etc). Only called once during system startup
nkeynes@35
    44
     */
nkeynes@35
    45
    void (*init)();
nkeynes@35
    46
    /**
nkeynes@35
    47
     * Reset the module into it's initial system boot state. Will be called
nkeynes@35
    48
     * once after init(), as well as whenever the user requests a reset.
nkeynes@35
    49
     */
nkeynes@35
    50
    void (*reset)();
nkeynes@35
    51
    /**
nkeynes@35
    52
     * Set the module into a running state (may be NULL)
nkeynes@35
    53
     */
nkeynes@35
    54
    void (*start)();
nkeynes@35
    55
    /**
nkeynes@35
    56
     * Execute one time-slice worth of operations, for the given number of
nkeynes@35
    57
     * nanoseconds.
nkeynes@35
    58
     * @return Number of nanoseconds actually executed
nkeynes@35
    59
     */
nkeynes@35
    60
    uint32_t (*run_time_slice)( uint32_t nanosecs );
nkeynes@35
    61
    /**
nkeynes@35
    62
     * Set the module into a stopped state (may be NULL)
nkeynes@35
    63
     */
nkeynes@35
    64
    void (*stop)();
nkeynes@35
    65
    /**
nkeynes@35
    66
     * Save the module state to the FILE stream. May be NULL, in which case
nkeynes@35
    67
     * the module is considered to have no state.
nkeynes@35
    68
     */
nkeynes@35
    69
    void (*save)(FILE *);
nkeynes@35
    70
    /**
nkeynes@35
    71
     * Load the saved module state from the FILE stream. May be NULL, in which
nkeynes@35
    72
     * case reset() will be called instead.
nkeynes@35
    73
     * @return 0 on success, nonzero on failure.
nkeynes@35
    74
     */
nkeynes@35
    75
    int (*load)(FILE *);
nkeynes@35
    76
} *dreamcast_module_t;
nkeynes@35
    77
nkeynes@35
    78
void dreamcast_register_module( dreamcast_module_t );
nkeynes@35
    79
nkeynes@35
    80
extern struct dreamcast_module mem_module;
nkeynes@35
    81
extern struct dreamcast_module sh4_module;
nkeynes@35
    82
extern struct dreamcast_module asic_module;
nkeynes@35
    83
extern struct dreamcast_module pvr2_module;
nkeynes@35
    84
extern struct dreamcast_module aica_module;
nkeynes@35
    85
extern struct dreamcast_module ide_module;
nkeynes@35
    86
extern struct dreamcast_module maple_module;
nkeynes@35
    87
extern struct dreamcast_module pvr2_module;
nkeynes@35
    88
extern struct dreamcast_module gui_module;
nkeynes@35
    89
extern struct dreamcast_module unknown_module;
nkeynes@35
    90
nkeynes@35
    91
/*************************** Logging **************************/
nkeynes@1
    92
nkeynes@1
    93
#define EMIT_FATAL 0
nkeynes@1
    94
#define EMIT_ERR 1
nkeynes@1
    95
#define EMIT_WARN 2
nkeynes@1
    96
#define EMIT_INFO 3
nkeynes@1
    97
#define EMIT_DEBUG 4
nkeynes@1
    98
#define EMIT_TRACE 5
nkeynes@1
    99
nkeynes@35
   100
#ifndef MODULE
nkeynes@35
   101
#define MODULE unknown_module
nkeynes@1
   102
#endif
nkeynes@1
   103
nkeynes@35
   104
void emit( void *, int level, const char *source, const char *msg, ... );
nkeynes@1
   105
nkeynes@35
   106
#define FATAL( ... ) emit( NULL, EMIT_FATAL, MODULE.name, __VA_ARGS__ )
nkeynes@35
   107
#define ERROR( ... ) emit( NULL, EMIT_ERR, MODULE.name, __VA_ARGS__ )
nkeynes@35
   108
#define WARN( ... ) emit( NULL, EMIT_WARN, MODULE.name, __VA_ARGS__ )
nkeynes@35
   109
#define INFO( ... ) emit( NULL, EMIT_INFO, MODULE.name, __VA_ARGS__ )
nkeynes@35
   110
#define DEBUG( ... ) emit( NULL, EMIT_DEBUG, MODULE.name, __VA_ARGS__ )
nkeynes@35
   111
#define TRACE( ... ) emit( NULL, EMIT_TRACE, MODULE.name, __VA_ARGS__ )
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
.