code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
/* basic, incomplete SSP160x (SSP1601?) interpreter with SVP memory controller emu (c) Copyright 2008, Grazvydas "notaz" Ignotas Free for non-commercial use. For commercial use, separate licencing terms must be obtained. Modified for Genesis Plus GX (Eke-Eke): added BIG ENDIAN support, fixed addr/code inversion */ #ifndef _SVP_H_ #define _SVP_H_ #include "../../shared.h" #include "ssp16.h" typedef struct { unsigned char iram_rom[0x20000]; // IRAM (0-0x7ff) and program ROM (0x800-0x1ffff) unsigned char dram[0x20000]; ssp1601_t ssp1601; } svp_t; extern svp_t *svp; extern int16 SVP_cycles; extern void svp_init(void); extern void svp_reset(void); extern void svp_write_dram(uint32 address, uint32 data); extern uint32 svp_read_cell_1(uint32 address); extern uint32 svp_read_cell_2(uint32 address); #endif
zyking1987-genplus-droid
genplusgx/cart_hw/svp/svp.h
C
gpl2
877
/* basic, incomplete SSP160x (SSP1601?) interpreter with SVP memory controller emu (c) Copyright 2008, Grazvydas "notaz" Ignotas Free for non-commercial use. For commercial use, separate licencing terms must be obtained. Modified for Genesis Plus GX (Eke-Eke): added BIG ENDIAN support, fixed addr/code inversion */ #include "../../shared.h" svp_t *svp = NULL; int16 SVP_cycles = 800; void svp_init(void) { svp = (void *) ((char *)cart.rom + 0x200000); memset(svp, 0, sizeof(*svp)); } void svp_reset(void) { memcpy(svp->iram_rom + 0x800, cart.rom + 0x800, 0x20000 - 0x800); ssp1601_reset(&svp->ssp1601); } void svp_write_dram(uint32 address, uint32 data) { *(uint16 *)(svp->dram + (address & 0x1fffe)) = data; if ((address == 0x30fe06) && data) svp->ssp1601.emu_status &= ~SSP_WAIT_30FE06; if ((address == 0x30fe08) && data) svp->ssp1601.emu_status &= ~SSP_WAIT_30FE08; } uint32 svp_read_cell_1(uint32 address) { address >>= 1; address = (address & 0x7001) | ((address & 0x3e) << 6) | ((address & 0xfc0) >> 5); return *(uint16 *)(svp->dram + (address & 0x1fffe)); } uint32 svp_read_cell_2(uint32 address) { address >>= 1; address = (address & 0x7801) | ((address & 0x1e) << 6) | ((address & 0x7e0) >> 4); return *(uint16 *)(svp->dram + (address & 0x1fffe)); }
zyking1987-genplus-droid
genplusgx/cart_hw/svp/svp.c
C
gpl2
1,366
/* basic, incomplete SSP160x (SSP1601?) interpreter with SVP memory controller emu (c) Copyright 2008, Grazvydas "notaz" Ignotas Free for non-commercial use. For commercial use, separate licencing terms must be obtained. Modified for Genesis Plus GX (Eke-Eke): added BIG ENDIAN support, fixed addr/code inversion */ #ifndef _SSP16_H_ #define _SSP16_H_ /* emulation event logging (from Picodrive) */ #define EL_SVP 0x00004000 /* SVP stuff */ #define EL_ANOMALY 0x80000000 /* some unexpected conditions (during emulation) */ #ifdef LOG_SVP #define elprintf(w,f,...) error("%d(%d): " f "\n",frame_count,v_counter,##__VA_ARGS__); #else #define elprintf(w,f,...) #endif /* register names */ enum { SSP_GR0, SSP_X, SSP_Y, SSP_A, SSP_ST, SSP_STACK, SSP_PC, SSP_P, SSP_PM0, SSP_PM1, SSP_PM2, SSP_XST, SSP_PM4, SSP_gr13, SSP_PMC, SSP_AL }; typedef union { unsigned int v; struct { #ifdef LSB_FIRST unsigned short l; unsigned short h; #else unsigned short h; unsigned short l; #endif } u; } ssp_reg_t; typedef struct { union { unsigned short RAM[256*2]; // 2 internal RAM banks struct { unsigned short RAM0[256]; unsigned short RAM1[256]; } u; } ram; ssp_reg_t gr[16]; // general registers union { unsigned char r[8]; // BANK pointers struct { unsigned char r0[4]; unsigned char r1[4]; } u; } reg; unsigned short stack[6]; unsigned int pmac_read[6]; // read modes/addrs for PM0-PM5 unsigned int pmac_write[6]; // write ... #define SSP_PMC_HAVE_ADDR 0x0001 // address written to PMAC, waiting for mode #define SSP_PMC_SET 0x0002 // PMAC is set #define SSP_HANG 0x1000 // 68000 hangs SVP #define SSP_WAIT_PM0 0x2000 // bit1 in PM0 #define SSP_WAIT_30FE06 0x4000 // ssp tight loops on 30FE08 to become non-zero #define SSP_WAIT_30FE08 0x8000 // same for 30FE06 #define SSP_WAIT_MASK 0xf000 unsigned int emu_status; unsigned int pad[30]; } ssp1601_t; void ssp1601_reset(ssp1601_t *ssp); void ssp1601_run(int cycles); #endif
zyking1987-genplus-droid
genplusgx/cart_hw/svp/ssp16.h
C
gpl2
2,182
/* basic, incomplete SSP160x (SSP1601?) interpreter with SVP memory controller emu (c) Copyright 2008, Grazvydas "notaz" Ignotas Free for non-commercial use. For commercial use, separate licencing terms must be obtained. Modified for Genesis Plus GX (Eke-Eke), added big endian support, fixed mode & addr */ /* * Register info * * 0. "-" * size: 16 * desc: Constant register with all bits set (0xffff). * * 1. "X" * size: 16 * desc: Generic register. When set, updates P (P = X * Y * 2) * * 2. "Y" * size: 16 * desc: Generic register. When set, updates P (P = X * Y * 2) * * 3. "A" * size: 32 * desc: Accumulator. * * 4. "ST" * size: 16 * desc: Status register. From MAME: bits 0-9 are CONTROL, other FLAG * fedc ba98 7654 3210 * 210 - RPL (?) "Loop size". If non-zero, makes (rX+) and (rX-) respectively * modulo-increment and modulo-decrement. The value shows which * power of 2 to use, i.e. 4 means modulo by 16. * (e: fir16_32.sc, IIR_4B.SC, DECIM.SC) * 43 - RB (?) * 5 - GP0_0 (ST5?) Changed before acessing PM0 (affects banking?). * 6 - GP0_1 (ST6?) Cleared before acessing PM0 (affects banking?). Set after. * datasheet says these (5,6) bits correspond to hardware pins. * 7 - IE (?) Not directly used by SVP code (never set, but preserved)? * 8 - OP (?) Not used by SVP code (only cleared)? (MAME: saturated value * (probably means clamping? i.e. 0x7ffc + 9 -> 0x7fff)) * 9 - MACS (?) Not used by SVP code (only cleared)? (e: "mac shift") * a - GPI_0 Interrupt 0 enable/status? * b - GPI_1 Interrupt 1 enable/status? * c - L L flag. Carry? * d - Z Zero flag. * e - OV Overflow flag. * f - N Negative flag. * seen directly changing code sequences: * ldi ST, 0 ld A, ST ld A, ST ld A, ST ldi st, 20h * ldi ST, 60h ori A, 60h and A, E8h and A, E8h * ld ST, A ld ST, A ori 3 * ld ST, A * * 5. "STACK" * size: 16 * desc: hw stack of 6 levels (according to datasheet) * * 6. "PC" * size: 16 * desc: Program counter. * * 7. "P" * size: 32 * desc: multiply result register. P = X * Y * 2 * probably affected by MACS bit in ST. * * 8. "PM0" (PM from PMAR name from Tasco's docs) * size: 16? * desc: Programmable Memory access register. * On reset, or when one (both?) GP0 bits are clear, * acts as status for XST, mapped at 015004 at 68k side: * bit0: ssp has written something to XST (cleared when 015004 is read) * bit1: 68k has written something through a1500{0|2} (cleared on PM0 read) * * 9. "PM1" * size: 16? * desc: Programmable Memory access register. * This reg. is only used as PMAR. * * 10. "PM2" * size: 16? * desc: Programmable Memory access register. * This reg. is only used as PMAR. * * 11. "XST" * size: 16? * desc: eXternal STate. Mapped to a15000 and a15002 at 68k side. * Can be programmed as PMAR? (only seen in test mode code) * Affects PM0 when written to? * * 12. "PM4" * size: 16? * desc: Programmable Memory access register. * This reg. is only used as PMAR. The most used PMAR by VR. * * 13. (unused by VR) * * 14. "PMC" (PMC from PMAC name from Tasco's docs) * size: 32? * desc: Programmable Memory access Control. Set using 2 16bit writes, * first address, then mode word. After setting PMAC, PMAR sould * be blind accessed (ld -, PMx or ld PMx, -) to program it for * reading and writing respectively. * Reading the register also shifts it's state (from "waiting for * address" to "waiting for mode" and back). Reads always return * address related to last PMx register accressed. * (note: addresses do not wrap). * * 15. "AL" * size: 16 * desc: Accumulator Low. 16 least significant bits of accumulator. * (normally reading acc (ld X, A) you get 16 most significant bits). * * * There are 8 8-bit pointer registers rX. r0-r3 (ri) point to RAM0, r4-r7 (rj) point to RAM1. * They can be accessed directly, or 2 indirection levels can be used [ (rX), ((rX)) ], * which work similar to * and ** operators in C, only they use different memory banks and * ((rX)) also does post-increment. First indirection level (rX) accesses RAMx, second accesses * program memory at address read from (rX), and increments value in (rX). * * r0,r1,r2,r4,r5,r6 can be modified [ex: ldi r0, 5]. * 3 modifiers can be applied (optional): * + : post-increment [ex: ld a, (r0+) ]. Can be made modulo-increment by setting RPL bits in ST. * - : post-decrement. Can be made modulo-decrement by setting RPL bits in ST (not sure). * +!: post-increment, unaffected by RPL (probably). * These are only used on 1st indirection level, so things like [ld a, ((r0+))] and [ld X, r6-] * ar probably invalid. * * r3 and r7 are special and can not be changed (at least Samsung samples and SVP code never do). * They are fixed to the start of their RAM banks. (They are probably changeable for ssp1605+, * Samsung's old DSP page claims that). * 1 of these 4 modifiers must be used (short form direct addressing?): * |00: RAMx[0] [ex: (r3|00), 0] (based on sample code) * |01: RAMx[1] * |10: RAMx[2] ? maybe 10h? accortding to Div_c_dp.sc, 2 * |11: RAMx[3] * * * Instruction notes * * ld a, * doesn't affect flags! (e: A_LAW.SC, Div_c_dp.sc) * * mld (rj), (ri) [, b] * operation: A = 0; P = (rj) * (ri) * notes: based on IIR_4B.SC sample. flags? what is b??? * * mpya (rj), (ri) [, b] * name: multiply and add? * operation: A += P; P = (rj) * (ri) * * mpys (rj), (ri), b * name: multiply and subtract? * notes: not used by VR code. * * mod cond, op * mod cond, shr does arithmetic shift * * 'ld -, AL' and probably 'ld AL, -' are for dummy assigns * * memory map: * 000000 - 1fffff ROM, accessable by both * 200000 - 2fffff unused? * 300000 - 31ffff DRAM, both * 320000 - 38ffff unused? * 390000 - 3907ff IRAM. can only be accessed by ssp? * 390000 - 39ffff similar mapping to "cell arrange" in Sega CD, 68k only? * 3a0000 - 3affff similar mapping to "cell arrange" in Sega CD, a bit different * * 30fe02 - 0 if SVP busy, 1 if done (set by SVP, checked and cleared by 68k) * 30fe06 - also sync related. * 30fe08 - job number [1-12] for SVP. 0 means no job. Set by 68k, read-cleared by SVP. * * + figure out if 'op A, P' is 32bit (nearly sure it is) * * does mld, mpya load their operands into X and Y? * * OP simm * * Assumptions in this code * P is not directly writeable * flags correspond to full 32bit accumulator * only Z and N status flags are emulated (others unused by SVP) * modifiers for 'OP a, ri' are ignored (invalid?/not used by SVP) * 'ld d, (a)' loads from program ROM */ #include "../../shared.h" #define u32 unsigned int //#define USE_DEBUGGER // 0 #define rX ssp->gr[SSP_X].u.h #define rY ssp->gr[SSP_Y].u.h #define rA ssp->gr[SSP_A].u.h #define rST ssp->gr[SSP_ST].u.h // 4 #define rSTACK ssp->gr[SSP_STACK].u.h #define rPC ssp->gr[SSP_PC].u.h #define rP ssp->gr[SSP_P] #define rPM0 ssp->gr[SSP_PM0].u.h // 8 #define rPM1 ssp->gr[SSP_PM1].u.h #define rPM2 ssp->gr[SSP_PM2].u.h #define rXST ssp->gr[SSP_XST].u.h #define rPM4 ssp->gr[SSP_PM4].u.h // 12 // 13 #define rPMC ssp->gr[SSP_PMC] // will keep addr in .h, mode in .l #define rAL ssp->gr[SSP_A].u.l #define rA32 ssp->gr[SSP_A].v #define rIJ ssp->reg.r #define IJind (((op>>6)&4)|(op&3)) #define GET_PC() (PC - (unsigned short *)svp->iram_rom) #define GET_PPC_OFFS() ((unsigned int)PC - (unsigned int)svp->iram_rom - 2) #define SET_PC(d) PC = (unsigned short *)svp->iram_rom + d #define REG_READ(r) (((r) <= 4) ? ssp->gr[r].u.h : read_handlers[r]()) #define REG_WRITE(r,d) { \ int r1 = r; \ if (r1 >= 4) write_handlers[r1](d); \ else if (r1 > 0) ssp->gr[r1].u.h = d; \ } // flags #define SSP_FLAG_L (1<<0xc) #define SSP_FLAG_Z (1<<0xd) #define SSP_FLAG_V (1<<0xe) #define SSP_FLAG_N (1<<0xf) // update ZN according to 32bit ACC. #define UPD_ACC_ZN \ rST &= ~(SSP_FLAG_Z|SSP_FLAG_N); \ if (!rA32) rST |= SSP_FLAG_Z; \ else rST |= (rA32>>16)&SSP_FLAG_N; // it seems SVP code never checks for L and OV, so we leave them out. // rST |= (t>>4)&SSP_FLAG_L; #define UPD_LZVN \ rST &= ~(SSP_FLAG_L|SSP_FLAG_Z|SSP_FLAG_V|SSP_FLAG_N); \ if (!rA32) rST |= SSP_FLAG_Z; \ else rST |= (rA32>>16)&SSP_FLAG_N; // standard cond processing. // again, only Z and N is checked, as SVP doesn't seem to use any other conds. #define COND_CHECK \ switch (op&0xf0) { \ case 0x00: cond = 1; break; /* always true */ \ case 0x50: cond = !((rST ^ (op<<5)) & SSP_FLAG_Z); break; /* Z matches f(?) bit */ \ case 0x70: cond = !((rST ^ (op<<7)) & SSP_FLAG_N); break; /* N matches f(?) bit */ \ default:elprintf(EL_SVP|EL_ANOMALY, "ssp FIXME: unimplemented cond @ %04x", GET_PPC_OFFS()); break; \ } // ops with accumulator. // how is low word really affected by these? // nearly sure 'ld A' doesn't affect flags #define OP_LDA(x) \ rA = x #define OP_LDA32(x) \ rA32 = x #define OP_SUBA(x) { \ rA32 -= (x) << 16; \ UPD_LZVN \ } #define OP_SUBA32(x) { \ rA32 -= (x); \ UPD_LZVN \ } #define OP_CMPA(x) { \ u32 t = rA32 - ((x) << 16); \ rST &= ~(SSP_FLAG_L|SSP_FLAG_Z|SSP_FLAG_V|SSP_FLAG_N); \ if (!t) rST |= SSP_FLAG_Z; \ else rST |= (t>>16)&SSP_FLAG_N; \ } #define OP_CMPA32(x) { \ u32 t = rA32 - (x); \ rST &= ~(SSP_FLAG_L|SSP_FLAG_Z|SSP_FLAG_V|SSP_FLAG_N); \ if (!t) rST |= SSP_FLAG_Z; \ else rST |= (t>>16)&SSP_FLAG_N; \ } #define OP_ADDA(x) { \ rA32 += (x) << 16; \ UPD_LZVN \ } #define OP_ADDA32(x) { \ rA32 += (x); \ UPD_LZVN \ } #define OP_ANDA(x) \ rA32 &= (x) << 16; \ UPD_ACC_ZN #define OP_ANDA32(x) \ rA32 &= (x); \ UPD_ACC_ZN #define OP_ORA(x) \ rA32 |= (x) << 16; \ UPD_ACC_ZN #define OP_ORA32(x) \ rA32 |= (x); \ UPD_ACC_ZN #define OP_EORA(x) \ rA32 ^= (x) << 16; \ UPD_ACC_ZN #define OP_EORA32(x) \ rA32 ^= (x); \ UPD_ACC_ZN #define OP_CHECK32(OP) { \ if ((op & 0x0f) == SSP_P) { /* A <- P */ \ read_P(); /* update P */ \ OP(rP.v); \ break; \ } \ if ((op & 0x0f) == SSP_A) { /* A <- A */ \ OP(rA32); \ break; \ } \ } static ssp1601_t *ssp = NULL; static unsigned short *PC; static int g_cycles; #ifdef USE_DEBUGGER static int running = 0; static int last_iram = 0; #endif // ----------------------------------------------------- // register i/o handlers // 0-4, 13 static u32 read_unknown(void) { #ifdef LOG_SVP elprintf(EL_ANOMALY|EL_SVP, "ssp FIXME: unknown read @ %04x", GET_PPC_OFFS()); #endif return 0; } static void write_unknown(u32 d) { #ifdef LOG_SVP elprintf(EL_ANOMALY|EL_SVP, "ssp FIXME: unknown write @ %04x", GET_PPC_OFFS()); #endif } // 4 static void write_ST(u32 d) { //if ((rST ^ d) & 0x0007) elprintf(EL_SVP, "ssp RPL %i -> %i @ %04x", rST&7, d&7, GET_PPC_OFFS()); #ifdef LOG_SVP if ((rST ^ d) & 0x0f98) elprintf(EL_SVP|EL_ANOMALY, "ssp FIXME ST %04x -> %04x @ %04x", rST, d, GET_PPC_OFFS()); #endif rST = d; } // 5 static u32 read_STACK(void) { --rSTACK; if ((short)rSTACK < 0) { rSTACK = 5; #ifdef LOG_SVP elprintf(EL_ANOMALY|EL_SVP, "ssp FIXME: stack underflow! (%i) @ %04x", rSTACK, GET_PPC_OFFS()); #endif } return ssp->stack[rSTACK]; } static void write_STACK(u32 d) { if (rSTACK >= 6) { #ifdef LOG_SVP elprintf(EL_ANOMALY|EL_SVP, "ssp FIXME: stack overflow! (%i) @ %04x", rSTACK, GET_PPC_OFFS()); #endif rSTACK = 0; } ssp->stack[rSTACK++] = d; } // 6 static u32 read_PC(void) { //g_cycles--; return GET_PC(); } static void write_PC(u32 d) { SET_PC(d); g_cycles--; } // 7 static u32 read_P(void) { int m1 = (signed short)rX; int m2 = (signed short)rY; rP.v = (m1 * m2 * 2); return rP.u.h; } // ----------------------------------------------------- static int get_inc(int mode) { int inc = (mode >> 11) & 7; if (inc != 0) { if (inc != 7) inc--; //inc = (1<<16) << inc; // 0 1 2 4 8 16 32 128 inc = 1 << inc; // 0 1 2 4 8 16 32 128 if (mode & 0x8000) inc = -inc; // decrement mode } return inc; } #define overwite_write(dst, d) \ { \ if (d & 0xf000) { dst &= ~0xf000; dst |= d & 0xf000; } \ if (d & 0x0f00) { dst &= ~0x0f00; dst |= d & 0x0f00; } \ if (d & 0x00f0) { dst &= ~0x00f0; dst |= d & 0x00f0; } \ if (d & 0x000f) { dst &= ~0x000f; dst |= d & 0x000f; } \ } static u32 pm_io(int reg, int write, u32 d) { if (ssp->emu_status & SSP_PMC_SET) { // this MUST be blind r or w if ((*(PC-1) & 0xff0f) && (*(PC-1) & 0xfff0)) { #ifdef LOG_SVP elprintf(EL_SVP|EL_ANOMALY, "ssp FIXME: tried to set PM%i (%c) with non-blind i/o %08x @ %04x", reg, write ? 'w' : 'r', rPMC.v, GET_PPC_OFFS()); #endif ssp->emu_status &= ~SSP_PMC_SET; return 0; } #ifdef LOG_SVP elprintf(EL_SVP, "PM%i (%c) set to %08x @ %04x", reg, write ? 'w' : 'r', rPMC.v, GET_PPC_OFFS()); #endif ssp->pmac_read[write ? reg + 6 : reg] = rPMC.v; ssp->emu_status &= ~SSP_PMC_SET; #ifdef LOG_SVP if ((rPMC.v & 0x7f) == 0x1c && (rPMC.v & 0x7fff0000) == 0) { elprintf(EL_SVP, "ssp IRAM copy from %06x", (ssp->ram.u.RAM1[0]-1)<<1); #ifdef USE_DEBUGGER last_iram = (ssp->ram.u.RAM1[0]-1)<<1; #endif } #endif return 0; } // just in case if (ssp->emu_status & SSP_PMC_HAVE_ADDR) { #ifdef LOG_SVP elprintf(EL_SVP|EL_ANOMALY, "ssp FIXME: PM%i (%c) with only addr set @ %04x", reg, write ? 'w' : 'r', GET_PPC_OFFS()); #endif ssp->emu_status &= ~SSP_PMC_HAVE_ADDR; } if (reg == 4 || (rST & 0x60)) { #ifdef LOG_SVP #define CADDR ((((mode<<16)&0x7f0000)|addr)<<1) #endif unsigned short *dram = (unsigned short *)svp->dram; if (write) { /*int mode = ssp->pmac_write[reg]&0xffff; int addr = ssp->pmac_write[reg]>>16;*/ int addr = ssp->pmac_write[reg]&0xffff; int mode = ssp->pmac_write[reg]>>16; #ifdef LOG_SVP if ((mode & 0xb800) == 0xb800) elprintf(EL_SVP|EL_ANOMALY, "ssp FIXME: mode %04x", mode); #endif if ((mode & 0x43ff) == 0x0018) // DRAM { int inc = get_inc(mode); #ifdef LOG_SVP elprintf(EL_SVP, "ssp PM%i DRAM w [%06x] %04x (inc %i, ovrw %i)", reg, CADDR, d, inc >> 16, (mode>>10)&1); #endif if (mode & 0x0400) { overwite_write(dram[addr], d); } else dram[addr] = d; ssp->pmac_write[reg] += inc; } else if ((mode & 0xfbff) == 0x4018) // DRAM, cell inc { #ifdef LOG_SVP elprintf(EL_SVP, "ssp PM%i DRAM w [%06x] %04x (cell inc, ovrw %i) @ %04x", reg, CADDR, d, (mode>>10)&1, GET_PPC_OFFS()); #endif if (mode & 0x0400) { overwite_write(dram[addr], d); } else dram[addr] = d; //ssp->pmac_write[reg] += (addr&1) ? (31<<16) : (1<<16); ssp->pmac_write[reg] += (addr&1) ? 31 : 1; } else if ((mode & 0x47ff) == 0x001c) // IRAM { int inc = get_inc(mode); #ifdef LOG_SVP if ((addr&0xfc00) != 0x8000) elprintf(EL_SVP|EL_ANOMALY, "ssp FIXME: invalid IRAM addr: %04x", addr<<1); elprintf(EL_SVP, "ssp IRAM w [%06x] %04x (inc %i)", (addr<<1)&0x7ff, d, inc >> 16); #endif ((unsigned short *)svp->iram_rom)[addr&0x3ff] = d; ssp->pmac_write[reg] += inc; } #ifdef LOG_SVP else { elprintf(EL_SVP|EL_ANOMALY, "ssp FIXME: PM%i unhandled write mode %04x, [%06x] %04x @ %04x", reg, mode, CADDR, d, GET_PPC_OFFS()); } #endif } else { /*int mode = ssp->pmac_read[reg]&0xffff; int addr = ssp->pmac_read[reg]>>16;*/ int addr = ssp->pmac_read[reg]&0xffff; int mode = ssp->pmac_read[reg]>>16; if ((mode & 0xfff0) == 0x0800) // ROM, inc 1, verified to be correct { #ifdef LOG_SVP elprintf(EL_SVP, "ssp ROM r [%06x] %04x", CADDR, ((unsigned short *)cart.rom)[addr|((mode&0xf)<<16)]); #endif /*if ((signed int)ssp->pmac_read[reg] >> 16 == -1) ssp->pmac_read[reg]++; ssp->pmac_read[reg] += 1<<16;*/ if ((signed int)(ssp->pmac_read[reg] & 0xffff) == -1) ssp->pmac_read[reg] += 1<<16; ssp->pmac_read[reg] ++; d = ((unsigned short *)cart.rom)[addr|((mode&0xf)<<16)]; } else if ((mode & 0x47ff) == 0x0018) // DRAM { int inc = get_inc(mode); #ifdef LOG_SVP elprintf(EL_SVP, "ssp PM%i DRAM r [%06x] %04x (inc %i)", reg, CADDR, dram[addr], inc >> 16); #endif d = dram[addr]; ssp->pmac_read[reg] += inc; } else { #ifdef LOG_SVP elprintf(EL_SVP|EL_ANOMALY, "ssp FIXME: PM%i unhandled read mode %04x, [%06x] @ %04x", reg, mode, CADDR, GET_PPC_OFFS()); #endif d = 0; } } // PMC value corresponds to last PMR accessed (not sure). rPMC.v = ssp->pmac_read[write ? reg + 6 : reg]; return d; } return (u32)-1; } // 8 static u32 read_PM0(void) { u32 d = pm_io(0, 0, 0); if (d != (u32)-1) return d; #ifdef LOG_SVP elprintf(EL_SVP, "PM0 raw r %04x @ %04x", rPM0, GET_PPC_OFFS()); #endif d = rPM0; if (!(d & 2) && (GET_PPC_OFFS() == 0x800 || GET_PPC_OFFS() == 0x1851E)) { ssp->emu_status |= SSP_WAIT_PM0; #ifdef LOG_SVP elprintf(EL_SVP, "det TIGHT loop: PM0"); #endif } rPM0 &= ~2; // ? return d; } static void write_PM0(u32 d) { u32 r = pm_io(0, 1, d); if (r != (u32)-1) return; #ifdef LOG_SVP elprintf(EL_SVP, "PM0 raw w %04x @ %04x", d, GET_PPC_OFFS()); #endif rPM0 = d; } // 9 static u32 read_PM1(void) { u32 d = pm_io(1, 0, 0); if (d != (u32)-1) return d; // can be removed? #ifdef LOG_SVP elprintf(EL_SVP|EL_ANOMALY, "PM1 raw r %04x @ %04x", rPM1, GET_PPC_OFFS()); #endif return rPM1; } static void write_PM1(u32 d) { u32 r = pm_io(1, 1, d); if (r != (u32)-1) return; // can be removed? #ifdef LOG_SVP elprintf(EL_SVP|EL_ANOMALY, "PM1 raw w %04x @ %04x", d, GET_PPC_OFFS()); #endif rPM1 = d; } // 10 static u32 read_PM2(void) { u32 d = pm_io(2, 0, 0); if (d != (u32)-1) return d; // can be removed? #ifdef LOG_SVP elprintf(EL_SVP|EL_ANOMALY, "PM2 raw r %04x @ %04x", rPM2, GET_PPC_OFFS()); #endif return rPM2; } static void write_PM2(u32 d) { u32 r = pm_io(2, 1, d); if (r != (u32)-1) return; // can be removed? #ifdef LOG_SVP elprintf(EL_SVP|EL_ANOMALY, "PM2 raw w %04x @ %04x", d, GET_PPC_OFFS()); #endif rPM2 = d; } // 11 static u32 read_XST(void) { // can be removed? u32 d = pm_io(3, 0, 0); if (d != (u32)-1) return d; #ifdef LOG_SVP elprintf(EL_SVP, "XST raw r %04x @ %04x", rXST, GET_PPC_OFFS()); #endif return rXST; } static void write_XST(u32 d) { // can be removed? u32 r = pm_io(3, 1, d); if (r != (u32)-1) return; #ifdef LOG_SVP elprintf(EL_SVP, "XST raw w %04x @ %04x", d, GET_PPC_OFFS()); #endif rPM0 |= 1; rXST = d; } // 12 static u32 read_PM4(void) { u32 d = pm_io(4, 0, 0); if (d == 0) { switch (GET_PPC_OFFS()) { case 0x0854: ssp->emu_status |= SSP_WAIT_30FE08; #ifdef LOG_SVP elprintf(EL_SVP, "det TIGHT loop: [30fe08]"); #endif break; case 0x4f12: ssp->emu_status |= SSP_WAIT_30FE06; #ifdef LOG_SVP elprintf(EL_SVP, "det TIGHT loop: [30fe06]"); #endif break; } } if (d != (u32)-1) return d; // can be removed? #ifdef LOG_SVP elprintf(EL_SVP|EL_ANOMALY, "PM4 raw r %04x @ %04x", rPM4, GET_PPC_OFFS()); #endif return rPM4; } static void write_PM4(u32 d) { u32 r = pm_io(4, 1, d); if (r != (u32)-1) return; // can be removed? #ifdef LOG_SVP elprintf(EL_SVP|EL_ANOMALY, "PM4 raw w %04x @ %04x", d, GET_PPC_OFFS()); #endif rPM4 = d; } // 14 static u32 read_PMC(void) { #ifdef LOG_SVP elprintf(EL_SVP, "PMC r a %04x (st %c) @ %04x", rPMC.h, (ssp->emu_status & SSP_PMC_HAVE_ADDR) ? 'm' : 'a', GET_PPC_OFFS()); #endif if (ssp->emu_status & SSP_PMC_HAVE_ADDR) { //if (ssp->emu_status & SSP_PMC_SET) // elprintf(EL_ANOMALY|EL_SVP, "prev PMC not used @ %04x", GET_PPC_OFFS()); ssp->emu_status |= SSP_PMC_SET; ssp->emu_status &= ~SSP_PMC_HAVE_ADDR; //return ((rPMC.h << 4) & 0xfff0) | ((rPMC.h >> 4) & 0xf); return ((rPMC.u.l << 4) & 0xfff0) | ((rPMC.u.l >> 4) & 0xf); } else { ssp->emu_status |= SSP_PMC_HAVE_ADDR; //return rPMC.h; return rPMC.u.l; } } static void write_PMC(u32 d) { if (ssp->emu_status & SSP_PMC_HAVE_ADDR) { //if (ssp->emu_status & SSP_PMC_SET) // elprintf(EL_ANOMALY|EL_SVP, "prev PMC not used @ %04x", GET_PPC_OFFS()); ssp->emu_status |= SSP_PMC_SET; ssp->emu_status &= ~SSP_PMC_HAVE_ADDR; //rPMC.l = d; rPMC.u.h = d; #ifdef LOG_SVP elprintf(EL_SVP, "PMC w m %04x @ %04x", rPMC.u.l, GET_PPC_OFFS()); #endif } else { ssp->emu_status |= SSP_PMC_HAVE_ADDR; //rPMC.h = d; rPMC.u.l = d; #ifdef LOG_SVP elprintf(EL_SVP, "PMC w a %04x @ %04x", rPMC.u.h, GET_PPC_OFFS()); #endif } } // 15 static u32 read_AL(void) { if (*(PC-1) == 0x000f) { #ifdef LOG_SVP elprintf(EL_SVP, "ssp dummy PM assign %08x @ %04x", rPMC.v, GET_PPC_OFFS()); #endif ssp->emu_status &= ~(SSP_PMC_SET|SSP_PMC_HAVE_ADDR); // ? } return rAL; } static void write_AL(u32 d) { rAL = d; } typedef u32 (*read_func_t)(void); typedef void (*write_func_t)(u32 d); static read_func_t read_handlers[16] = { read_unknown, read_unknown, read_unknown, read_unknown, // -, X, Y, A read_unknown, // 4 ST read_STACK, read_PC, read_P, read_PM0, // 8 read_PM1, read_PM2, read_XST, read_PM4, // 12 read_unknown, // 13 gr13 read_PMC, read_AL }; static write_func_t write_handlers[16] = { write_unknown, write_unknown, write_unknown, write_unknown, // -, X, Y, A // write_unknown, // 4 ST write_ST, // 4 ST (debug hook) write_STACK, write_PC, write_unknown, // 7 P write_PM0, // 8 write_PM1, write_PM2, write_XST, write_PM4, // 12 write_unknown, // 13 gr13 write_PMC, write_AL }; // ----------------------------------------------------- // pointer register handlers // #define ptr1_read(op) ptr1_read_(op&3,(op>>6)&4,(op<<1)&0x18) static u32 ptr1_read_(int ri, int isj2, int modi3) { //int t = (op&3) | ((op>>6)&4) | ((op<<1)&0x18); u32 mask, add = 0, t = ri | isj2 | modi3; unsigned char *rp = NULL; switch (t) { // mod=0 (00) case 0x00: case 0x01: case 0x02: return ssp->ram.u.RAM0[ssp->reg.u.r0[t&3]]; case 0x03: return ssp->ram.u.RAM0[0]; case 0x04: case 0x05: case 0x06: return ssp->ram.u.RAM1[ssp->reg.u.r1[t&3]]; case 0x07: return ssp->ram.u.RAM1[0]; // mod=1 (01), "+!" case 0x08: case 0x09: case 0x0a: return ssp->ram.u.RAM0[ssp->reg.u.r0[t&3]++]; case 0x0b: return ssp->ram.u.RAM0[1]; case 0x0c: case 0x0d: case 0x0e: return ssp->ram.u.RAM1[ssp->reg.u.r1[t&3]++]; case 0x0f: return ssp->ram.u.RAM1[1]; // mod=2 (10), "-" case 0x10: case 0x11: case 0x12: rp = &ssp->reg.u.r0[t&3]; t = ssp->ram.u.RAM0[*rp]; if (!(rST&7)) { (*rp)--; return t; } add = -1; goto modulo; case 0x13: return ssp->ram.u.RAM0[2]; case 0x14: case 0x15: case 0x16: rp = &ssp->reg.u.r1[t&3]; t = ssp->ram.u.RAM1[*rp]; if (!(rST&7)) { (*rp)--; return t; } add = -1; goto modulo; case 0x17: return ssp->ram.u.RAM1[2]; // mod=3 (11), "+" case 0x18: case 0x19: case 0x1a: rp = &ssp->reg.u.r0[t&3]; t = ssp->ram.u.RAM0[*rp]; if (!(rST&7)) { (*rp)++; return t; } add = 1; goto modulo; case 0x1b: return ssp->ram.u.RAM0[3]; case 0x1c: case 0x1d: case 0x1e: rp = &ssp->reg.u.r1[t&3]; t = ssp->ram.u.RAM1[*rp]; if (!(rST&7)) { (*rp)++; return t; } add = 1; goto modulo; case 0x1f: return ssp->ram.u.RAM1[3]; } return 0; modulo: mask = (1 << (rST&7)) - 1; *rp = (*rp & ~mask) | ((*rp + add) & mask); return t; } static void ptr1_write(int op, u32 d) { int t = (op&3) | ((op>>6)&4) | ((op<<1)&0x18); switch (t) { // mod=0 (00) case 0x00: case 0x01: case 0x02: ssp->ram.u.RAM0[ssp->reg.u.r0[t&3]] = d; return; case 0x03: ssp->ram.u.RAM0[0] = d; return; case 0x04: case 0x05: case 0x06: ssp->ram.u.RAM1[ssp->reg.u.r1[t&3]] = d; return; case 0x07: ssp->ram.u.RAM1[0] = d; return; // mod=1 (01), "+!" // mod=3, "+" case 0x08: case 0x18: case 0x09: case 0x19: case 0x0a: case 0x1a: ssp->ram.u.RAM0[ssp->reg.u.r0[t&3]++] = d; return; case 0x0b: ssp->ram.u.RAM0[1] = d; return; case 0x0c: case 0x1c: case 0x0d: case 0x1d: case 0x0e: case 0x1e: ssp->ram.u.RAM1[ssp->reg.u.r1[t&3]++] = d; return; case 0x0f: ssp->ram.u.RAM1[1] = d; return; // mod=2 (10), "-" case 0x10: case 0x11: case 0x12: ssp->ram.u.RAM0[ssp->reg.u.r0[t&3]--] = d; return; case 0x13: ssp->ram.u.RAM0[2] = d; return; case 0x14: case 0x15: case 0x16: ssp->ram.u.RAM1[ssp->reg.u.r1[t&3]--] = d; return; case 0x17: ssp->ram.u.RAM1[2] = d; return; // mod=3 (11) case 0x1b: ssp->ram.u.RAM0[3] = d; return; case 0x1f: ssp->ram.u.RAM1[3] = d; return; } } static u32 ptr2_read(int op) { int mv = 0, t = (op&3) | ((op>>6)&4) | ((op<<1)&0x18); switch (t) { // mod=0 (00) case 0x00: case 0x01: case 0x02: mv = ssp->ram.u.RAM0[ssp->reg.u.r0[t&3]]++; break; case 0x03: mv = ssp->ram.u.RAM0[0]++; break; case 0x04: case 0x05: case 0x06: mv = ssp->ram.u.RAM1[ssp->reg.u.r1[t&3]]++; break; case 0x07: mv = ssp->ram.u.RAM1[0]++; break; // mod=1 (01) case 0x0b: mv = ssp->ram.u.RAM0[1]++; break; case 0x0f: mv = ssp->ram.u.RAM1[1]++; break; // mod=2 (10) case 0x13: mv = ssp->ram.u.RAM0[2]++; break; case 0x17: mv = ssp->ram.u.RAM1[2]++; break; // mod=3 (11) case 0x1b: mv = ssp->ram.u.RAM0[3]++; break; case 0x1f: mv = ssp->ram.u.RAM1[3]++; break; default: elprintf(EL_SVP|EL_ANOMALY, "ssp FIXME: invalid mod in ((rX))? @ %04x", GET_PPC_OFFS()); return 0; } return ((unsigned short *)svp->iram_rom)[mv]; } // ----------------------------------------------------- void ssp1601_reset(ssp1601_t *l_ssp) { ssp = l_ssp; ssp->emu_status = 0; ssp->gr[SSP_GR0].v = 0xffff0000; rPC = 0x400; rSTACK = 0; // ? using ascending stack rST = 0; } #ifdef USE_DEBUGGER static void debug_dump(void) { printf("GR0: %04x X: %04x Y: %04x A: %08x\n", ssp->gr[SSP_GR0].h, rX, rY, ssp->gr[SSP_A].v); printf("PC: %04x (%04x) P: %08x\n", GET_PC(), GET_PC() << 1, ssp->gr[SSP_P].v); printf("PM0: %04x PM1: %04x PM2: %04x\n", rPM0, rPM1, rPM2); printf("XST: %04x PM4: %04x PMC: %08x\n", rXST, rPM4, ssp->gr[SSP_PMC].v); printf(" ST: %04x %c%c%c%c, GP0_0 %i, GP0_1 %i\n", rST, rST&SSP_FLAG_N?'N':'n', rST&SSP_FLAG_V?'V':'v', rST&SSP_FLAG_Z?'Z':'z', rST&SSP_FLAG_L?'L':'l', (rST>>5)&1, (rST>>6)&1); printf("STACK: %i %04x %04x %04x %04x %04x %04x\n", rSTACK, ssp->stack[0], ssp->stack[1], ssp->stack[2], ssp->stack[3], ssp->stack[4], ssp->stack[5]); printf("r0-r2: %02x %02x %02x r4-r6: %02x %02x %02x\n", rIJ[0], rIJ[1], rIJ[2], rIJ[4], rIJ[5], rIJ[6]); elprintf(EL_SVP, "cycles: %i, emu_status: %x", g_cycles, ssp->emu_status); } static void debug_dump_mem(void) { int h, i; printf("RAM0\n"); for (h = 0; h < 32; h++) { if (h == 16) printf("RAM1\n"); printf("%03x:", h*16); for (i = 0; i < 16; i++) printf(" %04x", ssp->ram.RAM[h*16+i]); printf("\n"); } } static void debug_dump2file(const char *fname, void *mem, int len) { FILE *f = fopen(fname, "wb"); unsigned short *p = mem; int i; if (f) { for (i = 0; i < len/2; i++) p[i] = (p[i]<<8) | (p[i]>>8); fwrite(mem, 1, len, f); fclose(f); for (i = 0; i < len/2; i++) p[i] = (p[i]<<8) | (p[i]>>8); printf("dumped to %s\n", fname); } else printf("dump failed\n"); } static int bpts[10] = { 0, }; static void debug(unsigned int pc, unsigned int op) { static char buffo[64] = {0,}; char buff[64] = {0,}; int i; if (running) { for (i = 0; i < 10; i++) if (pc != 0 && bpts[i] == pc) { printf("breakpoint %i\n", i); running = 0; break; } } if (running) return; printf("%04x (%02x) @ %04x\n", op, op >> 9, pc<<1); while (1) { printf("dbg> "); fflush(stdout); fgets(buff, sizeof(buff), stdin); if (buff[0] == '\n') strcpy(buff, buffo); else strcpy(buffo, buff); switch (buff[0]) { case 0: exit(0); case 'c': case 'r': running = 1; return; case 's': case 'n': return; case 'x': debug_dump(); break; case 'm': debug_dump_mem(); break; case 'b': { char *baddr = buff + 2; i = 0; if (buff[3] == ' ') { i = buff[2] - '0'; baddr = buff + 4; } bpts[i] = strtol(baddr, NULL, 16) >> 1; printf("breakpoint %i set @ %04x\n", i, bpts[i]<<1); break; } case 'd': sprintf(buff, "iramrom_%04x.bin", last_iram); debug_dump2file(buff, svp->iram_rom, sizeof(svp->iram_rom)); debug_dump2file("dram.bin", svp->dram, sizeof(svp->dram)); break; default: printf("unknown command\n"); break; } } } #endif // USE_DEBUGGER void ssp1601_run(int cycles) { SET_PC(rPC); g_cycles = cycles; while (g_cycles > 0 && !(ssp->emu_status & SSP_WAIT_MASK)) { int op; u32 tmpv; op = *PC++; #ifdef USE_DEBUGGER debug(GET_PC()-1, op); #endif switch (op >> 9) { // ld d, s case 0x00: if (op == 0) break; // nop if (op == ((SSP_A<<4)|SSP_P)) { // A <- P // not sure. MAME claims that only hi word is transfered. read_P(); // update P rA32 = rP.v; } else { tmpv = REG_READ(op & 0x0f); REG_WRITE((op & 0xf0) >> 4, tmpv); } break; // ld d, (ri) case 0x01: tmpv = ptr1_read(op); REG_WRITE((op & 0xf0) >> 4, tmpv); break; // ld (ri), s case 0x02: tmpv = REG_READ((op & 0xf0) >> 4); ptr1_write(op, tmpv); break; // ldi d, imm case 0x04: tmpv = *PC++; REG_WRITE((op & 0xf0) >> 4, tmpv); break; // ld d, ((ri)) case 0x05: tmpv = ptr2_read(op); REG_WRITE((op & 0xf0) >> 4, tmpv); break; // ldi (ri), imm case 0x06: tmpv = *PC++; ptr1_write(op, tmpv); break; // ld adr, a case 0x07: ssp->ram.RAM[op & 0x1ff] = rA; break; // ld d, ri case 0x09: tmpv = rIJ[(op&3)|((op>>6)&4)]; REG_WRITE((op & 0xf0) >> 4, tmpv); break; // ld ri, s case 0x0a: rIJ[(op&3)|((op>>6)&4)] = REG_READ((op & 0xf0) >> 4); break; // ldi ri, simm case 0x0c: case 0x0d: case 0x0e: case 0x0f: rIJ[(op>>8)&7] = op; break; // call cond, addr case 0x24: { int cond = 0; COND_CHECK if (cond) { int new_PC = *PC++; write_STACK(GET_PC()); write_PC(new_PC); } else PC++; break; } // ld d, (a) case 0x25: tmpv = ((unsigned short *)svp->iram_rom)[rA]; REG_WRITE((op & 0xf0) >> 4, tmpv); break; // bra cond, addr case 0x26: { int cond = 0; COND_CHECK if (cond) { int new_PC = *PC++; write_PC(new_PC); } else PC++; break; } // mod cond, op case 0x48: { int cond = 0; COND_CHECK if (cond) { switch (op & 7) { case 2: rA32 = (signed int)rA32 >> 1; break; // shr (arithmetic) case 3: rA32 <<= 1; break; // shl case 6: rA32 = -(signed int)rA32; break; // neg case 7: if ((int)rA32 < 0) rA32 = -(signed int)rA32; break; // abs default: #ifdef LOG_SVP elprintf(EL_SVP|EL_ANOMALY, "ssp FIXME: unhandled mod %i @ %04x", op&7, GET_PPC_OFFS()); #endif break; } UPD_ACC_ZN // ? } break; } // mpys? case 0x1b: #ifdef LOG_SVP if (!(op&0x100)) elprintf(EL_SVP|EL_ANOMALY, "ssp FIXME: no b bit @ %04x", GET_PPC_OFFS()); #endif read_P(); // update P rA32 -= rP.v; // maybe only upper word? UPD_ACC_ZN // there checking flags after this rX = ptr1_read_(op&3, 0, (op<<1)&0x18); // ri (maybe rj?) rY = ptr1_read_((op>>4)&3, 4, (op>>3)&0x18); // rj break; // mpya (rj), (ri), b case 0x4b: #ifdef LOG_SVP if (!(op&0x100)) elprintf(EL_SVP|EL_ANOMALY, "ssp FIXME: no b bit @ %04x", GET_PPC_OFFS()); #endif read_P(); // update P rA32 += rP.v; // confirmed to be 32bit UPD_ACC_ZN // ? rX = ptr1_read_(op&3, 0, (op<<1)&0x18); // ri (maybe rj?) rY = ptr1_read_((op>>4)&3, 4, (op>>3)&0x18); // rj break; // mld (rj), (ri), b case 0x5b: #ifdef LOG_SVP if (!(op&0x100)) elprintf(EL_SVP|EL_ANOMALY, "ssp FIXME: no b bit @ %04x", GET_PPC_OFFS()); #endif rA32 = 0; rST &= 0x0fff; // ? rX = ptr1_read_(op&3, 0, (op<<1)&0x18); // ri (maybe rj?) rY = ptr1_read_((op>>4)&3, 4, (op>>3)&0x18); // rj break; // OP a, s case 0x10: OP_CHECK32(OP_SUBA32); tmpv = REG_READ(op & 0x0f); OP_SUBA(tmpv); break; case 0x30: OP_CHECK32(OP_CMPA32); tmpv = REG_READ(op & 0x0f); OP_CMPA(tmpv); break; case 0x40: OP_CHECK32(OP_ADDA32); tmpv = REG_READ(op & 0x0f); OP_ADDA(tmpv); break; case 0x50: OP_CHECK32(OP_ANDA32); tmpv = REG_READ(op & 0x0f); OP_ANDA(tmpv); break; case 0x60: OP_CHECK32(OP_ORA32 ); tmpv = REG_READ(op & 0x0f); OP_ORA (tmpv); break; case 0x70: OP_CHECK32(OP_EORA32); tmpv = REG_READ(op & 0x0f); OP_EORA(tmpv); break; // OP a, (ri) case 0x11: tmpv = ptr1_read(op); OP_SUBA(tmpv); break; case 0x31: tmpv = ptr1_read(op); OP_CMPA(tmpv); break; case 0x41: tmpv = ptr1_read(op); OP_ADDA(tmpv); break; case 0x51: tmpv = ptr1_read(op); OP_ANDA(tmpv); break; case 0x61: tmpv = ptr1_read(op); OP_ORA (tmpv); break; case 0x71: tmpv = ptr1_read(op); OP_EORA(tmpv); break; // OP a, adr case 0x03: tmpv = ssp->ram.RAM[op & 0x1ff]; OP_LDA (tmpv); break; case 0x13: tmpv = ssp->ram.RAM[op & 0x1ff]; OP_SUBA(tmpv); break; case 0x33: tmpv = ssp->ram.RAM[op & 0x1ff]; OP_CMPA(tmpv); break; case 0x43: tmpv = ssp->ram.RAM[op & 0x1ff]; OP_ADDA(tmpv); break; case 0x53: tmpv = ssp->ram.RAM[op & 0x1ff]; OP_ANDA(tmpv); break; case 0x63: tmpv = ssp->ram.RAM[op & 0x1ff]; OP_ORA (tmpv); break; case 0x73: tmpv = ssp->ram.RAM[op & 0x1ff]; OP_EORA(tmpv); break; // OP a, imm case 0x14: tmpv = *PC++; OP_SUBA(tmpv); break; case 0x34: tmpv = *PC++; OP_CMPA(tmpv); break; case 0x44: tmpv = *PC++; OP_ADDA(tmpv); break; case 0x54: tmpv = *PC++; OP_ANDA(tmpv); break; case 0x64: tmpv = *PC++; OP_ORA (tmpv); break; case 0x74: tmpv = *PC++; OP_EORA(tmpv); break; // OP a, ((ri)) case 0x15: tmpv = ptr2_read(op); OP_SUBA(tmpv); break; case 0x35: tmpv = ptr2_read(op); OP_CMPA(tmpv); break; case 0x45: tmpv = ptr2_read(op); OP_ADDA(tmpv); break; case 0x55: tmpv = ptr2_read(op); OP_ANDA(tmpv); break; case 0x65: tmpv = ptr2_read(op); OP_ORA (tmpv); break; case 0x75: tmpv = ptr2_read(op); OP_EORA(tmpv); break; // OP a, ri case 0x19: tmpv = rIJ[IJind]; OP_SUBA(tmpv); break; case 0x39: tmpv = rIJ[IJind]; OP_CMPA(tmpv); break; case 0x49: tmpv = rIJ[IJind]; OP_ADDA(tmpv); break; case 0x59: tmpv = rIJ[IJind]; OP_ANDA(tmpv); break; case 0x69: tmpv = rIJ[IJind]; OP_ORA (tmpv); break; case 0x79: tmpv = rIJ[IJind]; OP_EORA(tmpv); break; // OP simm case 0x1c: OP_SUBA(op & 0xff); #ifdef LOG_SVP if (op&0x100) elprintf(EL_SVP|EL_ANOMALY, "FIXME: simm with upper bit set"); #endif break; case 0x3c: OP_CMPA(op & 0xff); #ifdef LOG_SVP if (op&0x100) elprintf(EL_SVP|EL_ANOMALY, "FIXME: simm with upper bit set"); #endif break; case 0x4c: OP_ADDA(op & 0xff); #ifdef LOG_SVP if (op&0x100) elprintf(EL_SVP|EL_ANOMALY, "FIXME: simm with upper bit set"); #endif break; // MAME code only does LSB of top word, but this looks wrong to me. case 0x5c: OP_ANDA(op & 0xff); #ifdef LOG_SVP if (op&0x100) elprintf(EL_SVP|EL_ANOMALY, "FIXME: simm with upper bit set"); #endif break; case 0x6c: OP_ORA (op & 0xff); #ifdef LOG_SVP if (op&0x100) elprintf(EL_SVP|EL_ANOMALY, "FIXME: simm with upper bit set"); #endif break; case 0x7c: OP_EORA(op & 0xff); #ifdef LOG_SVP if (op&0x100) elprintf(EL_SVP|EL_ANOMALY, "FIXME: simm with upper bit set"); #endif break; default: #ifdef LOG_SVP elprintf(EL_ANOMALY|EL_SVP, "ssp FIXME unhandled op %04x @ %04x", op, GET_PPC_OFFS()); #endif break; } g_cycles--; } read_P(); // update P rPC = GET_PC(); #ifdef LOG_SVP if (ssp->gr[SSP_GR0].v != 0xffff0000) elprintf(EL_ANOMALY|EL_SVP, "ssp FIXME: REG 0 corruption! %08x", ssp->gr[SSP_GR0].v); #endif }
zyking1987-genplus-droid
genplusgx/cart_hw/svp/ssp16.c
C
gpl2
39,149
/**************************************************************************** * Genesis Plus * Mega Drive cartridge hardware support * * Copyright (C) 2007-2011 Eke-Eke (GCN/Wii port) * * Most cartridge protections documented by Haze * (http://haze.mameworld.info/) * * Realtec mapper documented by TascoDeluxe * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ #include "../shared.h" #include "../input_hw/gamepad.h" #define CART_CNT (44) /* Cart database entry */ typedef struct { uint16 chk_1; /* header checksum */ uint16 chk_2; /* real checksum */ uint8 bank_start; /* first mapped bank in $400000-$7fffff region */ uint8 bank_end; /* last mapped bank in $400000-$7fffff region */ T_CART_HW cart_hw; /* hardware description */ } T_CART_ENTRY; extern int emulate_address_error; /* Cartridge Hardware structure */ T_CART cart; /* Function prototypes */ static void mapper_sega_w(uint32 data); static void mapper_ssf2_w(uint32 address, uint32 data); static void mapper_realtec_w(uint32 address, uint32 data); static void mapper_seganet_w(uint32 address, uint32 data); static void mapper_32k_w(uint32 data); static void mapper_64k_w(uint32 data); static void mapper_64k_multi_w(uint32 address); static uint32 mapper_radica_r(uint32 address); static void default_time_w(uint32 address, uint32 data); static void default_regs_w(uint32 address, uint32 data); static uint32 default_regs_r(uint32 address); static uint32 default_regs_r_16(uint32 address); static void custom_regs_w(uint32 address, uint32 data); static void custom_alt_regs_w(uint32 address, uint32 data); static uint32 topshooter_read(uint32 address); static void topshooter_write(uint32 address, uint32 data); /* Games that need extra hardware emulation: - copy protection device - custom ROM banking device */ static const T_CART_ENTRY rom_database[CART_CNT] = { /* Funny World & Balloon Boy */ {0x0000,0x06ab,0x40,0x40,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},1,0,NULL,NULL,NULL,mapper_realtec_w}}, /* Whac-a-Critter */ {0xffff,0xf863,0x40,0x40,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},1,0,NULL,NULL,NULL,mapper_realtec_w}}, /* Earth Defense */ {0xffff,0x44fb,0x40,0x40,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},1,0,NULL,NULL,NULL,mapper_realtec_w}}, /* RADICA (Volume 1) */ {0x0000,0x2326,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,0,mapper_radica_r,NULL,NULL,NULL}}, /* RADICA (Volume 2) */ {0x4f10,0x0836,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,0,mapper_radica_r,NULL,NULL,NULL}}, /* RADICA (Volume 1) (byteswapped version) */ {0xf424,0x9f82,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,0,mapper_radica_r,NULL,NULL,NULL}}, /* Chinese Fighters III */ {0x9490,0x8180,0x40,0x6f,{{0x00,0x00,0x00,0x00},{0xf0000c,0xf0000c,0xf0000c,0xf0000c},{0x400000,0x400004,0x400008,0x40000c},0,1,NULL,NULL,default_regs_r,custom_alt_regs_w}}, /* Top Fighter */ {0x4eb9,0x5d8b,0x60,0x7f,{{0x00,0x00,0x00,0x00},{0xf00007,0xf00007,0xf00007,0xffffff},{0x600001,0x600003,0x600005,0x000000},0,1,NULL,NULL,default_regs_r,custom_regs_w}}, /* Mulan */ {0x0404,0x1b40,0x60,0x7f,{{0x00,0x00,0x00,0x00},{0xf00007,0xf00007,0xf00007,0xffffff},{0x600001,0x600003,0x600005,0x000000},0,1,NULL,NULL,default_regs_r,custom_regs_w}}, /* Pocket Monsters II */ {0x47f9,0x17e5,0x60,0x7f,{{0x00,0x00,0x00,0x00},{0xf00007,0xf00007,0xf00007,0xffffff},{0x600001,0x600003,0x600005,0x000000},0,1,NULL,NULL,default_regs_r,custom_regs_w}}, /* Lion King 3 */ {0x0000,0x507c,0x60,0x7f,{{0x00,0x00,0x00,0x00},{0xf00007,0xf00007,0xf00007,0xffffff},{0x600001,0x600003,0x600005,0x000000},0,1,NULL,NULL,default_regs_r,custom_regs_w}}, /* Super King Kong 99 */ {0x0000,0x7d6e,0x60,0x7f,{{0x00,0x00,0x00,0x00},{0xf00007,0xf00007,0xf00007,0xffffff},{0x600001,0x600003,0x600005,0x000000},0,1,NULL,NULL,default_regs_r,custom_regs_w}}, /* Pokemon Stadium */ {0x0000,0x843c,0x70,0x7f,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,1,NULL,NULL,NULL,custom_regs_w}}, /* Lion King 2 */ {0xffff,0x1d9b,0x40,0x40,{{0x00,0x00,0x00,0x00},{0xfffffd,0xfffffd,0xffffff,0xffffff},{0x400000,0x400004,0x000000,0x000000},0,0,NULL,NULL,default_regs_r,default_regs_w}}, /* Squirell King */ {0x0000,0x8ec8,0x40,0x40,{{0x00,0x00,0x00,0x00},{0xfffffd,0xfffffd,0xffffff,0xffffff},{0x400000,0x400004,0x000000,0x000000},0,0,NULL,NULL,default_regs_r,default_regs_w}}, /* Lian Huan Pao - Barver Battle Saga (registers accessed by Z80, related to sound engine ?) */ {0x30b9,0x1c2a,0x40,0x40,{{0x00,0x00,0x00,0x00},{0xfffffd,0xfffffd,0xffffff,0xffffff},{0x400000,0x400004,0x000000,0x000000},0,0,NULL,NULL,default_regs_r,default_regs_w}}, /* Shui Hu Zhuan (registers accessed by Z80, related to sound engine ?) */ {0x6001,0x0211,0x40,0x40,{{0x00,0x00,0x00,0x00},{0xfffffd,0xfffffd,0xffffff,0xffffff},{0x400000,0x400004,0x000000,0x000000},0,0,NULL,NULL,default_regs_r,default_regs_w}}, /* Feng Shen Ying Jie Chuan (registers accessed by Z80, related to sound engine ?) */ {0xffff,0x5d98,0x40,0x40,{{0x00,0x00,0x00,0x00},{0xfffffd,0xfffffd,0xffffff,0xffffff},{0x400000,0x400004,0x000000,0x000000},0,0,NULL,NULL,default_regs_r,default_regs_w}}, /* (*) Shui Hu - Feng Yun Zhuan (patched ROM, unused registers) */ {0x3332,0x872b,0x40,0x40,{{0x00,0x00,0x00,0x00},{0xfffffd,0xfffffd,0xffffff,0xffffff},{0x400000,0x400004,0x000000,0x000000},0,0,NULL,NULL,default_regs_r,default_regs_w}}, /* (*) Chao Ji Da Fu Weng (patched ROM, various words witten to register, long word also read from $7E0000, unknown banking hardware ?) */ {0xa697,0xa697,0x40,0x40,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x400000,0x000000,0x000000,0x000000},0,0,NULL,NULL,NULL,default_regs_w}}, /* (*) Aq Renkan Awa (patched ROM, ON/OFF bit sequence is written to register, unknown banking hardware ?) */ {0x8104,0x0517,0x40,0x40,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x400001,0x000000,0x000000,0x000000},0,0,NULL,NULL,NULL,default_regs_w}}, /* (*) Jiu Ji Ma Jiang II - Ye Yan Bian (patched ROM, using expected register value - $0f - crashes the game) (uses 16-bits reads) */ {0x0c44,0xba81,0x40,0x40,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x400006},0,0,NULL,NULL,default_regs_r_16,NULL}}, /* (*) Tun Shi Tian Di III (patched ROM, unused register) */ {0x0000,0x9c5e,0x40,0x40,{{0xab,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x400046,0x000000,0x000000,0x000000},0,0,NULL,NULL,default_regs_r,NULL}}, /* Ma Jiang Qing Ren - Ji Ma Jiang Zhi */ {0x0000,0x7037,0x40,0x40,{{0x90,0xd3,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x400000,0x401000,0x000000,0x000000},0,0,NULL,NULL,default_regs_r,NULL}}, /* 16 Zhang Ma Jiang (uses 16-bits reads) */ {0xfb40,0x4bed,0x40,0x40,{{0x00,0xaa,0x00,0xf0},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x400002,0x000000,0x400006},0,0,NULL,NULL,default_regs_r_16,NULL}}, /* King of Fighter 98 */ {0x0000,0xd0a0,0x48,0x4f,{{0x00,0x00,0xaa,0xf0},{0xffffff,0xffffff,0xfc0000,0xfc0000},{0x000000,0x000000,0x480000,0x4c0000},0,0,NULL,NULL,default_regs_r,NULL}}, /* Supper Bubble Bobble */ {0x0000,0x16cd,0x40,0x40,{{0x55,0x0f,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x400000,0x400002,0x000000,0x000000},0,0,NULL,NULL,default_regs_r,NULL}}, /* Huan Le Tao Qi Shu - Smart Mouse */ {0x0000,0x1a28,0x40,0x40,{{0x55,0x0f,0xaa,0xf0},{0xffffff,0xffffff,0xffffff,0xffffff},{0x400000,0x400002,0x400004,0x400006},0,0,NULL,NULL,default_regs_r,NULL}}, /* (*) Hei Tao 2 - Super Big 2 (patched ROM, unused registers) */ {0x0000,0x5843,0x40,0x40,{{0x55,0x0f,0xaa,0xf0},{0xffffff,0xffffff,0xffffff,0xffffff},{0x400000,0x400002,0x400004,0x400006},0,0,NULL,NULL,default_regs_r,NULL}}, /* Elf Wor */ {0x0080,0x3dba,0x40,0x40,{{0x55,0x0f,0xc9,0x18},{0xffffff,0xffffff,0xffffff,0xffffff},{0x400000,0x400002,0x400004,0x400006},0,0,NULL,NULL,default_regs_r,NULL}}, /* Ya-Se Chuanshuo */ {0xffff,0xd472,0x40,0x40,{{0x63,0x98,0xc9,0x18},{0xffffff,0xffffff,0xffffff,0xffffff},{0x400000,0x400002,0x400004,0x400006},0,0,NULL,NULL,default_regs_r,NULL}}, /* 777 Casino (For first one, 0x55 works as well. Other values are never used so they are guessed from on other unlicensed games using similar mapper) */ {0x0000,0xf8d9,0x40,0x40,{{0x63,0x98,0xc9,0x18},{0xffffff,0xffffff,0xffffff,0xffffff},{0x400000,0x400002,0x400004,0x400006},0,0,NULL,NULL,default_regs_r,NULL}}, /* Soul Blade */ {0x0000,0x0c5b,0x40,0x40,{{0x63,0x98,0xc9,0xf0},{0xffffff,0xffffff,0xffffff,0xffffff},{0x400000,0x400002,0x400004,0x400006},0,0,NULL,NULL,default_regs_r,NULL}}, /* Rockman X3 (half-patched ROM, two last register values are not used, 0xaa/0x18 works too) */ {0x0000,0x9d0e,0x40,0x40,{{0x0c,0x00,0xc9,0xf0},{0xffffff,0xffffff,0xffffff,0xffffff},{0xa13000,0x000000,0x400004,0x400006},0,0,default_regs_r,NULL,default_regs_r,NULL}}, /* (*) Tekken 3 Special (patched ROM, register value not used, unknown writes to $400000-$40000E, read from $400002) */ {0x0000,0x8c6e,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0xa13000,0x000000,0x000000,0x000000},0,0,default_regs_r,NULL,NULL,NULL}}, /* (*) Dragon Ball Final Bout (patched ROM, in original code, different switches occurs depending on returned value $00-$0f) */ {0xc65a,0xc65a,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0xa13000,0x000000,0x000000,0x000000},0,0,default_regs_r,NULL,NULL,NULL}}, /* (*) Yang Jia Jiang - Yang Warrior Family (patched ROM, register value unused) */ {0x0000,0x96b0,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0xa13000,0x000000,0x000000,0x000000},0,0,default_regs_r,NULL,NULL,NULL}}, /* Super Mario 2 1998 */ {0xffff,0x0474,0x00,0x00,{{0x0a,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0xa13000,0x000000,0x000000,0x000000},0,0,default_regs_r,NULL,NULL,NULL}}, /* Super Mario World */ {0x2020,0xb4eb,0x00,0x00,{{0x1c,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0xa13000,0x000000,0x000000,0x000000},0,0,default_regs_r,NULL,NULL,NULL}}, /* A Bug's Life */ {0x7f7f,0x2aad,0x00,0x00,{{0x28,0x1f,0x01,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0xa13000,0xa13002,0xa1303e,0x000000},0,0,default_regs_r,NULL,NULL,NULL}}, /* King of Fighter 99 */ {0x0000,0x021e,0x00,0x00,{{0x00,0x01,0x1f,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0xa13000,0xa13002,0xa1303e,0x000000},0,0,default_regs_r,NULL,NULL,NULL}}, /* Pocket Monster */ {0xd6fc,0x1eb1,0x00,0x00,{{0x00,0x01,0x1f,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0xa13000,0xa13002,0xa1303e,0x000000},0,0,default_regs_r,NULL,NULL,NULL}}, /* Game no Kanzume Otokuyou */ {0x0000,0xf9d1,0x00,0x00,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,0,NULL,mapper_seganet_w,NULL,NULL}}, /* Top Shooter (arcade hardware) */ {0xffff,0x3632,0x20,0x20,{{0x00,0x00,0x00,0x00},{0xffffff,0xffffff,0xffffff,0xffffff},{0x000000,0x000000,0x000000,0x000000},0,0,NULL,NULL,topshooter_read,topshooter_write}} }; /************************************************************ Cart Hardware initialization *************************************************************/ /* cart hardware detection */ void md_cart_init(void) { int i; /*************************************************************************************************************** CARTRIDGE ROM MIRRORING *************************************************************************************************************** Cartridge area is mapped to $000000-$3fffff: -> when accessing ROM, 68k address lines A1 to A21 are used by the internal cartridge hardware to decode the full 4MB address range. -> depending on the ROM total size, some address lines might be ignored, resulting in ROM mirroring. Cartridges can use either 8-bits (x2) or 16-bits (x1, x2) Mask ROM chips, each chip size is a factor of 2 bytes: -> two 8-bits chips are equivalent to one 16-bits chip, no specific address decoding is required, needed address lines are simply connected to each chip, upper address lines are ignored and data lines are connected appropriately to each chip (D0-D7 to one chip, D8-D15 to the other one). ROM is mirrored each N bytes where N=2^(k+1) is the total ROM size (ROM1+ROM2,ROM1+ROM2,...). -> one single 16-bits chip do not need specific address decoding, address lines are simply connected depending on the ROM size, upper address lines being ignored. ROM is mirrored each N bytes where N=2^k is the size of the ROM chip (ROM1,ROM1,ROM1,...). -> two 16-bits chips of the same size are equivalent to one chip of double size, address decoding generally is the same except that specific hardware is used (one address line is generally used for chip selection, lower ones being used to address the chips and upper ones being ignored). ROM is mirrored continuously each N bytes where N=2^(k+1) is the total ROM size (ROM1,ROM2,ROM1,ROM2,...). -> two 16-bits chips with different size are mapped differently. Address decoding is done the same way as above (one address line used for chip selection) but the ignored & required address lines differ from one chip to another, which makes ROM mirroring different. ROM2 size is generally half of ROM1 size and ROM are mirrored like that : ROM1,ROM2,ROM2,ROM1,ROM2,ROM2,... From the emulator point of view, we only need to distinguish 3 cases: 1/ total ROM size is a factor of 2: ROM is mirrored each 2^k bytes. 2/ total ROM size is not a factor of 2 and cartridge uses one or two chips of the same size (Type A): ROM is padded up to 2^k and mirrored each 2^k bytes. 3/ total ROM size is not a factor of 2 and cartridge uses two chips of different sizes (Type B): ROM is not padded and the first 2^(k-1) bytes are mirrored each 2^k bytes while the next 2^(k-2) bytes are mirrored in the last 2^(k-2) bytes. ******************************************************************************************************************/ /* calculate nearest size with factor of 2 */ unsigned int size = 0x10000; while (cart.romsize > size) size <<= 1; /* total ROM size is not a factor of 2 */ /* TODO: handle more possible ROM configurations (using cartridge database ???) */ if ((size < MAXROMSIZE) && (cart.romsize < size)) { /* two chips with different size */ if (config.romtype) { /* third ROM section is mirrored in the last section */ memcpy(cart.rom + cart.romsize, cart.rom + 2*cart.romsize - size, size - cart.romsize); } else { /* ROM is padded up to 2^k bytes */ memset(cart.rom + cart.romsize, 0xff, size - cart.romsize); } } /* special case: Sonic & Knuckles */ /* $200000-$3fffff is mapped to external cartridge */ if (strstr(rominfo.international,"SONIC & KNUCKLES") != NULL) { /* disable ROM mirroring */ size = 0x400000; } /* ROM is mirrored each 2^k bytes */ cart.mask = size - 1; /********************************************** DEFAULT CARTRIDGE MAPPING ***********************************************/ for (i=0; i<0x40; i++) { /* cartridge ROM */ m68k_memory_map[i].base = cart.rom + ((i<<16) & cart.mask); m68k_memory_map[i].read8 = NULL; m68k_memory_map[i].read16 = NULL; m68k_memory_map[i].write8 = m68k_unused_8_w; m68k_memory_map[i].write16 = m68k_unused_16_w; zbank_memory_map[i].read = NULL; zbank_memory_map[i].write = zbank_unused_w; } for (i=0x40; i<0x80; i++) { /* unused area */ m68k_memory_map[i].base = cart.rom + (i<<16); m68k_memory_map[i].read8 = m68k_read_bus_8; m68k_memory_map[i].read16 = m68k_read_bus_16; m68k_memory_map[i].write8 = m68k_unused_8_w; m68k_memory_map[i].write16 = m68k_unused_16_w; zbank_memory_map[i].read = zbank_unused_r; zbank_memory_map[i].write = zbank_unused_w; } /********************************************** BACKUP MEMORY ***********************************************/ sram_init(); eeprom_init(); if (sram.on) { if (sram.custom) { /* Serial EEPROM */ m68k_memory_map[eeprom.type.sda_out_adr >> 16].read8 = eeprom_read_byte; m68k_memory_map[eeprom.type.sda_out_adr >> 16].read16 = eeprom_read_word; m68k_memory_map[eeprom.type.sda_in_adr >> 16].read8 = eeprom_read_byte; m68k_memory_map[eeprom.type.sda_in_adr >> 16].read16 = eeprom_read_word; m68k_memory_map[eeprom.type.scl_adr >> 16].write8 = eeprom_write_byte; m68k_memory_map[eeprom.type.scl_adr >> 16].write16 = eeprom_write_word; zbank_memory_map[eeprom.type.sda_out_adr >> 16].read = eeprom_read_byte; zbank_memory_map[eeprom.type.sda_in_adr >> 16].read = eeprom_read_byte; zbank_memory_map[eeprom.type.scl_adr >> 16].write = eeprom_write_byte; } else { /* Static RAM (64k max.) */ m68k_memory_map[sram.start >> 16].base = sram.sram; m68k_memory_map[sram.start >> 16].read8 = NULL; m68k_memory_map[sram.start >> 16].read16 = NULL; m68k_memory_map[sram.start >> 16].write8 = NULL; m68k_memory_map[sram.start >> 16].write16 = NULL; zbank_memory_map[sram.start >> 16].read = NULL; zbank_memory_map[sram.start >> 16].write = NULL; } } /********************************************** SVP CHIP ***********************************************/ svp = NULL; if (strstr(rominfo.international,"Virtua Racing") != NULL) { svp_init(); m68k_memory_map[0x30].base = svp->dram; m68k_memory_map[0x30].read16 = NULL; m68k_memory_map[0x30].write16 = svp_write_dram; m68k_memory_map[0x31].base = svp->dram + 0x10000; m68k_memory_map[0x31].read16 = NULL; m68k_memory_map[0x31].write16 = svp_write_dram; m68k_memory_map[0x39].read16 = svp_read_cell_1; m68k_memory_map[0x3a].read16 = svp_read_cell_2; } /********************************************** SPECIFIC PERIPHERAL SUPPORT ***********************************************/ /* restore previous input settings */ if (old_system[0] != -1) { input.system[0] = old_system[0]; } if (old_system[1] != -1) { input.system[1] = old_system[1]; } /* default GUN settings */ input.x_offset = 0x00; input.y_offset = 0x00; /* SEGA Menacer */ if (strstr(rominfo.international,"MENACER") != NULL) { /* save current setting */ if (old_system[0] == -1) { old_system[0] = input.system[0]; } if (old_system[1] == -1) { old_system[1] = input.system[1]; } input.system[0] = SYSTEM_MD_GAMEPAD; input.system[1] = SYSTEM_MENACER; input.x_offset = 0x52; input.y_offset = 0x00; } else if (strstr(rominfo.international,"T2 ; THE ARCADE GAME") != NULL) { /* save current setting */ if (old_system[0] == -1) { old_system[0] = input.system[0]; } if (old_system[1] == -1) { old_system[1] = input.system[1]; } input.system[0] = SYSTEM_MD_GAMEPAD; input.system[1] = SYSTEM_MENACER; input.x_offset = 0x84; input.y_offset = 0x08; } else if (strstr(rominfo.international,"BODY COUNT") != NULL) { /* save current setting */ if (old_system[0] == -1) { old_system[0] = input.system[0]; } if (old_system[1] == -1) { old_system[1] = input.system[1]; } input.system[0] = SYSTEM_MOUSE; input.system[1] = SYSTEM_MENACER; input.x_offset = 0x44; input.y_offset = 0x18; } /* KONAMI Justifiers */ else if (strstr(rominfo.international,"LETHAL ENFORCERSII") != NULL) { /* save current setting */ if (old_system[0] == -1) { old_system[0] = input.system[0]; } if (old_system[1] == -1) { old_system[1] = input.system[1]; } input.system[0] = SYSTEM_MD_GAMEPAD; input.system[1] = SYSTEM_JUSTIFIER; input.x_offset = 0x18; input.y_offset = 0x00; } else if (strstr(rominfo.international,"LETHAL ENFORCERS") != NULL) { /* save current setting */ if (old_system[0] == -1) { old_system[0] = input.system[0]; } if (old_system[1] == -1) { old_system[1] = input.system[1]; } input.system[0] = SYSTEM_MD_GAMEPAD; input.system[1] = SYSTEM_JUSTIFIER; input.x_offset = 0x00; input.y_offset = 0x00; } cart.special = 0; /********************************************** J-CART ***********************************************/ if (((strstr(rominfo.product,"00000000") != NULL) && (rominfo.checksum == 0x168b)) || /* Super Skidmarks, Micro Machines Military*/ ((strstr(rominfo.product,"00000000") != NULL) && (rominfo.checksum == 0x165e)) || /* Pete Sampras Tennis (1991), Micro Machines 96 */ ((strstr(rominfo.product,"00000000") != NULL) && (rominfo.checksum == 0xcee0)) || /* Micro Machines Military (bad) */ ((strstr(rominfo.product,"00000000") != NULL) && (rominfo.checksum == 0x2c41)) || /* Micro Machines 96 (bad) */ ((strstr(rominfo.product,"XXXXXXXX") != NULL) && (rominfo.checksum == 0xdf39)) || /* Sampras Tennis 96 */ ((strstr(rominfo.product,"T-123456") != NULL) && (rominfo.checksum == 0x1eae)) || /* Sampras Tennis 96 */ ((strstr(rominfo.product,"T-120066") != NULL) && (rominfo.checksum == 0x16a4)) || /* Pete Sampras Tennis (1994)*/ (strstr(rominfo.product,"T-120096") != NULL)) /* Micro Machines 2 */ { if (cart.romsize <= 0x380000) /* just to be sure (checksum might not be enough) */ { cart.special |= HW_J_CART; /* set default port 1 setting */ if (input.system[1] != SYSTEM_WAYPLAY) { old_system[1] = input.system[1]; input.system[1] = SYSTEM_MD_GAMEPAD; } /* extra connectors mapped at $38xxxx or $3Fxxxx */ m68k_memory_map[0x38].read16 = jcart_read; m68k_memory_map[0x38].write16 = jcart_write; m68k_memory_map[0x3f].read16 = jcart_read; m68k_memory_map[0x3f].write16 = jcart_write; } } /********************************************** LOCK-ON ***********************************************/ /* clear existing patches */ ggenie_shutdown(); areplay_shutdown(); /* initialize extra hardware */ switch (config.lock_on) { case TYPE_GG: { ggenie_init(); break; } case TYPE_AR: { areplay_init(); break; } case TYPE_SK: { /* store S&K ROM above cartridge ROM + SRAM */ if (cart.romsize > 0x600000) break; /* load Sonic & Knuckles ROM (2 MBytes) */ FILE *f = fopen(SK_ROM,"r+b"); if (!f) break; int done = 0; while (done < 0x200000) { fread(cart.rom + 0x600000 + done, 2048, 1, f); done += 2048; } fclose(f); /* load Sonic 2 UPMEM ROM (256 KBytes) */ f = fopen(SK_UPMEM,"r+b"); if (!f) break; done = 0; while (done < 0x40000) { fread(cart.rom + 0x800000 + done, 2048, 1, f); done += 2048; } fclose(f); #ifdef LSB_FIRST /* Byteswap ROM */ int i; uint8 temp; for(i = 0; i < 0x240000; i += 2) { temp = cart.rom[i + 0x600000]; cart.rom[i + 0x600000] = cart.rom[i + 0x600000 + 1]; cart.rom[i + 0x600000 + 1] = temp; } #endif /*$000000-$1FFFFF is mapped to S&K ROM */ for (i=0x00; i<0x20; i++) { m68k_memory_map[i].base = (cart.rom + 0x600000) + (i<<16); } cart.special |= HW_LOCK_ON; break; } default: { break; } } /********************************************** Cartridge Extra Hardware ***********************************************/ memset(&cart.hw, 0, sizeof(T_CART_HW)); /* search for game into database */ for (i=0; i < CART_CNT + 1; i++) { /* known cart found ! */ if ((rominfo.checksum == rom_database[i].chk_1) && (rominfo.realchecksum == rom_database[i].chk_2)) { /* retrieve hardware information */ memcpy(&cart.hw, &(rom_database[i].cart_hw), sizeof(T_CART_HW)); /* initialize memory handlers for $400000-$7FFFFF region */ int j = rom_database[i].bank_start; while (j <= rom_database[i].bank_end) { if (cart.hw.regs_r) { m68k_memory_map[j].read8 = cart.hw.regs_r; m68k_memory_map[j].read16 = cart.hw.regs_r; zbank_memory_map[j].read = cart.hw.regs_r; } if (cart.hw.regs_w) { m68k_memory_map[j].write8 = cart.hw.regs_w; m68k_memory_map[j].write16 = cart.hw.regs_w; zbank_memory_map[j].write = cart.hw.regs_w; } j++; } /* leave loop */ i = CART_CNT + 1; } } /* Realtec mapper */ if (cart.hw.realtec) { /* 8k BOOT ROM */ for (i=0; i<8; i++) { memcpy(cart.rom + 0x900000 + i*0x2000, cart.rom + 0x7e000, 0x2000); } /* BOOT ROM is mapped to $000000-$3FFFFF */ for (i=0x00; i<0x40; i++) { m68k_memory_map[i].base = cart.rom + 0x900000; } } #if M68K_EMULATE_ADDRESS_ERROR /* default behavior */ emulate_address_error = config.addr_error; #endif /* detect special cartridges */ if (cart.romsize > 0x800000) { /* Ultimate MK3 (hack) */ for (i=0x40; i<0xA0; i++) { m68k_memory_map[i].base = cart.rom + (i<<16); m68k_memory_map[i].read8 = NULL; m68k_memory_map[i].read16 = NULL; zbank_memory_map[i].read = NULL; } #if M68K_EMULATE_ADDRESS_ERROR /* this game does not work properly on real hardware */ emulate_address_error = 0; #endif } else if (cart.romsize > 0x400000) { /* assume SSF2 mapper */ cart.hw.bankshift = 1; cart.hw.time_w = mapper_ssf2_w; } /* default write handler for !TIME range ($A130xx)*/ if (!cart.hw.time_w) { cart.hw.time_w = default_time_w; } } /* hardware that need to be reseted on power on */ void md_cart_reset(int hard_reset) { int i; /* reset cartridge mapping */ if (cart.hw.bankshift) { for (i=0x00; i<0x40; i++) { m68k_memory_map[i].base = cart.rom + ((i<<16) & cart.mask); } } /* SVP chip */ if (svp) svp_reset(); /* Lock-ON */ switch (config.lock_on) { case TYPE_GG: { ggenie_reset(hard_reset); break; } case TYPE_AR: { areplay_reset(hard_reset); break; } case TYPE_SK: { if (cart.special & HW_LOCK_ON) { /* disable UPMEM chip at $300000-$3fffff */ for (i=0x30; i<0x40; i++) { m68k_memory_map[i].base = cart.rom + ((i<<16) & cart.mask); } } break; } default: { break; } } /* save default cartridge slot mapping */ cart.base = m68k_memory_map[0].base; } int md_cart_context_save(uint8 *state) { int i; int bufferptr = 0; uint8 *base; /* cartridge mapping */ for (i=0; i<0x40; i++) { /* get base address */ base = m68k_memory_map[i].base; if (base == sram.sram) { /* SRAM */ state[bufferptr++] = 0xff; } else { /* ROM */ state[bufferptr++] = ((base - cart.rom) >> 16) & 0xff; } } /* hardware registers */ save_param(cart.hw.regs, sizeof(cart.hw.regs)); /* SVP */ if (svp) { save_param(svp->iram_rom, 0x800); save_param(svp->dram,sizeof(svp->dram)); save_param(&svp->ssp1601,sizeof(ssp1601_t)); } return bufferptr; } int md_cart_context_load(uint8 *state, char *version) { int i; int bufferptr = 0; uint8 offset; /* extended state (from 1.4.1 and above) */ if ((version[11] > 0x31) || (version[13] > 0x34) || (version[15] > 0x30)) { /* cartridge mapping */ for (i=0; i<0x40; i++) { /* get offset */ offset = state[bufferptr++]; if (offset == 0xff) { /* SRAM */ m68k_memory_map[i].base = sram.sram; } else { /* ROM */ m68k_memory_map[i].base = cart.rom + (offset << 16); } } /* hardware registers */ load_param(cart.hw.regs, sizeof(cart.hw.regs)); /* SVP */ if (svp) { load_param(svp->iram_rom, 0x800); load_param(svp->dram,sizeof(svp->dram)); load_param(&svp->ssp1601,sizeof(ssp1601_t)); } } return bufferptr; } /************************************************************ MAPPER handlers *************************************************************/ /* ROM/SRAM Bankswitch (Phantasy Star IV, Story of Thor/Beyond Oasis, Sonic 3 & Knuckles) */ static void mapper_sega_w(uint32 data) { int i; if (data & 1) { /* Only if SRAM is detected */ if (sram.on) { /* $200000-$3fffff is mapped to SRAM */ for (i=0x20; i<0x40; i++) { m68k_memory_map[i].base = sram.sram; } if (data & 2) { /* SRAM write disabled */ for (i=0x20; i<0x40; i++) { m68k_memory_map[i].write8 = m68k_unused_8_w; m68k_memory_map[i].write16 = m68k_unused_16_w; zbank_memory_map[i].write = zbank_unused_w; } } else { /* SRAM write enabled */ for (i=0x20; i<0x40; i++) { m68k_memory_map[i].write8 = NULL; m68k_memory_map[i].write16 = NULL; zbank_memory_map[i].write = NULL; } } } /* S&K lock-on chip */ if ((cart.special & HW_LOCK_ON) && (config.lock_on == TYPE_SK)) { /* $300000-$3fffff is mapped to S2K upmem chip */ for (i=0x30; i<0x40; i++) { m68k_memory_map[i].base = (cart.rom + 0x800000) + ((i & 3)<<16); } } } else { /* $200000-$3fffff is mapped to ROM */ for (i=0x20; i<0x40; i++) { m68k_memory_map[i].base = cart.rom + ((i<<16) & cart.mask); m68k_memory_map[i].write8 = m68k_unused_8_w; m68k_memory_map[i].write16 = m68k_unused_16_w; zbank_memory_map[i].write = zbank_unused_w; } } } /* Super Street Fighter 2 ROM Bankswitch documented by Bart Trzynadlowski (http://www.trzy.org/files/ssf2.txt) */ static void mapper_ssf2_w(uint32 address, uint32 data) { /* 8 x 512k banks */ uint32 dst = (address << 2) & 0x38; /* bank 0 remains unchanged */ if (dst) { uint32 i; uint8 *src = cart.rom + (data << 19); for (i=0; i<8; i++) { m68k_memory_map[dst++].base = src + (i<<16); } } } /* Realtec ROM Bankswitch (Earth Defend, Balloon Boy & Funny World, Whac-A-Critter) (Note: register usage is inverted in TascoDlx documentation) */ static void mapper_realtec_w(uint32 address, uint32 data) { switch (address) { case 0x402000: { /* number of mapped 64k blocks (the written value is a number of 128k blocks) */ cart.hw.regs[2] = data << 1; return; } case 0x404000: { /* 00000xxx */ cart.hw.regs[0] = data & 7; return; } case 0x400000: { /* 00000yy1 */ cart.hw.regs[1] = data & 6; /* mapped start address is 00yy xxx0 0000 0000 0000 0000 */ uint32 base = (cart.hw.regs[0] << 1) | (cart.hw.regs[1] << 3); /* ensure mapped size is not null */ if (cart.hw.regs[2]) { /* selected blocks are mirrored into the whole cartridge area */ int i; for (i=0x00; i<0x40; i++) m68k_memory_map[i].base = &cart.rom[(base + (i % cart.hw.regs[2])) << 16]; } return; } } } /* Game no Kanzume Otokuyou ROM Mapper */ static void mapper_seganet_w(uint32 address, uint32 data) { if ((address & 0xff) == 0xf1) { int i; if (data & 1) { /* ROM Write protected */ for (i=0; i<0x40; i++) { m68k_memory_map[i].write8 = m68k_unused_8_w; m68k_memory_map[i].write16 = m68k_unused_16_w; zbank_memory_map[i].write = zbank_unused_w; } } else { /* ROM Write enabled */ for (i=0; i<0x40; i++) { m68k_memory_map[i].write8 = NULL; m68k_memory_map[i].write16 = NULL; zbank_memory_map[i].write = NULL; } } } } /* Custom ROM Bankswitch used in Top Fighter, Mulan, Pocket Monsters II, Lion King 3, Super King Kong 99, Pokemon Stadium */ static void mapper_32k_w(uint32 data) { int i; /* 64 x 32k banks */ if (data) { /* unverified (Top Fighter writes $2A instead $2E) */ if (data >> 2) data |= 4; /* bank is mapped at $000000-$0FFFFF */ for (i=0; i<16; i++) { memcpy(cart.rom + 0x900000 + (i<<16), cart.rom + ((data & 0x3f) << 15), 0x8000); memcpy(cart.rom + 0x908000 + (i<<16), cart.rom + ((data & 0x3f) << 15), 0x8000); m68k_memory_map[i].base = cart.rom + 0x900000 + (i<<16); } } else { /* reset default $000000-$0FFFFF mapping */ for (i=0; i<16; i++) { m68k_memory_map[i].base = &cart.rom[i << 16]; } } } /* Custom ROM Bankswitch used in Chinese Fighter III */ static void mapper_64k_w(uint32 data) { int i; /* 16 x 64k banks */ if (data) { /* bank is mapped at $000000-$0FFFFF */ for (i=0; i<16; i++) { m68k_memory_map[i].base = &cart.rom[(data & 0xf) << 16]; } } else { /* reset default $000000-$0FFFFF mapping */ for (i=0; i<16; i++) { m68k_memory_map[i].base = &cart.rom[(i & 0xf) << 16]; } } } /* Custom ROM Bankswitch used in pirate "Multi-in-1" cartridges, A Bug's Life, King of Fighter 99, Pocket Monster, Rockman X3 */ static void mapper_64k_multi_w(uint32 address) { int i; /* 64 x 64k banks */ for (i=0; i<64; i++) { m68k_memory_map[i].base = &cart.rom[((address++) & 0x3f) << 16]; } } /* Custom ROM Bankswitch used in RADICA cartridges */ static uint32 mapper_radica_r(uint32 address) { int i = 0; address = (address >> 1); /* 64 x 64k banks */ for (i = 0; i < 64; i++) { m68k_memory_map[i].base = &cart.rom[((address++)& 0x3f)<< 16]; } return 0xffff; } /************************************************************ default !TIME signal handler *************************************************************/ static void default_time_w(uint32 address, uint32 data) { if (address < 0xa13040) { /* unlicensed cartridges mapper (default) */ mapper_64k_multi_w(address); return; } /* official cartridges mapper (default) */ mapper_sega_w(data); } /************************************************************ Internal register handlers *************************************************************/ static uint32 default_regs_r(uint32 address) { int i; for (i=0; i<4; i++) { if ((address & cart.hw.mask[i]) == cart.hw.addr[i]) { return cart.hw.regs[i]; } } return m68k_read_bus_8(address); } static uint32 default_regs_r_16(uint32 address) { int i; for (i=0; i<4; i++) { if ((address & cart.hw.mask[i]) == cart.hw.addr[i]) { return (cart.hw.regs[i] << 8); } } return m68k_read_bus_16(address); } static void default_regs_w(uint32 address, uint32 data) { int i; for (i=0; i<4; i++) { if ((address & cart.hw.mask[i]) == cart.hw.addr[i]) { cart.hw.regs[i] = data; return; } } m68k_unused_8_w(address, data); } /* custom register hardware (Top Fighter, Lion King III, Super Donkey Kong 99, Mulan, Pocket Monsters II, Pokemon Stadium) */ static void custom_regs_w(uint32 address, uint32 data) { /* ROM bankswitch */ if ((address >> 16) > 0x6f) { mapper_32k_w(data); return; } /* write register */ default_regs_w(address, data); /* bitswapping */ uint32 temp = cart.hw.regs[0]; switch (cart.hw.regs[1] & 3) { case 0: cart.hw.regs[2] = (temp << 1); break; case 1: cart.hw.regs[2] = (temp >> 1); return; case 2: cart.hw.regs[2] = ((temp >> 4) | ((temp & 0x0F) << 4)); return; default: cart.hw.regs[2] = (((temp >> 7) & 0x01) | ((temp >> 5) & 0x02) | ((temp >> 3) & 0x04) | ((temp >> 1) & 0x08) | ((temp << 1) & 0x10) | ((temp << 3) & 0x20) | ((temp << 5) & 0x40) | ((temp << 7) & 0x80)); return; } } /* alternate custom register hardware (Chinese Fighters III) */ static void custom_alt_regs_w(uint32 address, uint32 data) { /* ROM bankswitch */ if ((address >> 16) > 0x5f) { mapper_64k_w(data); return; } /* write regs */ default_regs_w(address, data); } static uint32 topshooter_read(uint32 address) { if (address < 0x202000) { uint8 temp = 0xff; switch (address & 0xff) { case 0x43: { if (input.pad[0] & INPUT_A) temp &= ~0x80; /* Shoot */ if (input.pad[0] & INPUT_B) temp &= ~0x10; /* Bet */ if (input.pad[0] & INPUT_START) temp &= ~0x20; /* Start */ break; } case 0x45: /* ??? (DOWN) & Service Mode (UP) */ { if (input.pad[0] & INPUT_UP) temp &= ~0x08; /* Service Mode */ if (input.pad[0] & INPUT_DOWN) temp &= ~0x10; /* ???, used in service menu to select next option */ break; } case 0x47: { if (input.pad[0] & INPUT_RIGHT) temp &= ~0x03; /* Insert 10 coins */ break; } case 0x49: { if (input.pad[0] & INPUT_LEFT) temp &= ~0x03; /* Clear coins */ if (input.pad[0] & INPUT_C) temp &= ~0x01; /* Insert XXX coins */ break; } case 0x51: { temp = 0xA5; break; } default: { temp = m68k_read_bus_8(address); break; } } return temp; } return READ_BYTE(sram.sram , address & 0xffff); } static void topshooter_write(uint32 address, uint32 data) { if (address >= 0x202000) { WRITE_BYTE(sram.sram , address & 0xffff, data); return; } m68k_unused_8_w(address, data); }
zyking1987-genplus-droid
genplusgx/cart_hw/md_cart.c
C
gpl2
40,731
/**************************************************************************** * Genesis Plus * DATEL Action Replay / Pro Action Replay emulation * * Copyright (C) 2009 Eke-Eke (GCN/Wii port) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ #ifndef _AREPLAY_H_ #define _AREPLAY_H_ #define AR_SWITCH_OFF (0) #define AR_SWITCH_ON (1) #define AR_SWITCH_TRAINER (2) extern void areplay_init(void); extern void areplay_shutdown(void); extern void areplay_reset(int hard); extern void areplay_set_status(int status); extern int areplay_get_status(void); #endif
zyking1987-genplus-droid
genplusgx/cart_hw/areplay.h
C
gpl2
1,366
/**************************************************************************** * Genesis Plus * Action Replay / Pro Action Replay emulation * * Copyright (C) 2009 Eke-Eke (GCN/Wii port) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ #include "../shared.h" #define TYPE_PRO1 0x12 #define TYPE_PRO2 0x22 static struct { uint8 enabled; uint8 status; uint8 *rom; uint8 *ram; uint16 regs[13]; uint16 old[4]; uint16 data[4]; uint32 addr[4]; } action_replay; static void ar_write_regs(uint32 address, uint32 data); static void ar_write_regs_2(uint32 address, uint32 data); static void ar_write_ram_8(uint32 address, uint32 data); void areplay_init(void) { memset(&action_replay,0,sizeof(action_replay)); if (cart.romsize > 0x800000) return; /* Open Action Replay ROM */ FILE *f = fopen(AR_ROM,"rb"); if (!f) return; /* store Action replay ROM + RAM above cartridge ROM + SRAM */ action_replay.rom = cart.rom + 0x800000; action_replay.ram = cart.rom + 0x810000; /* ROM size */ fseek(f, 0, SEEK_END); int size = ftell(f); fseek(f, 0, SEEK_SET); /* detect Action Replay board type */ switch (size) { case 0x8000: { /* normal Action Replay (32K) */ action_replay.enabled = TYPE_AR; /* internal registers mapped at $010000-$01ffff */ m68k_memory_map[0x01].write16 = ar_write_regs; break; } case 0x10000: case 0x20000: { /* read Stack Pointer */ uint8 sp[4]; fread(&sp, 4, 1, f); fseek(f, 0, SEEK_SET); /* Detect board version */ if (sp[1] == 0x42) { /* PRO Action Replay 1 (64/128K) */ action_replay.enabled = TYPE_PRO1; /* internal registers mapped at $010000-$01ffff */ m68k_memory_map[0x01].write16 = ar_write_regs; } else if (sp[1] == 0x60) { /* PRO Action Replay 2 (64K) */ action_replay.enabled = TYPE_PRO2; /* internal registers mapped at $100000-$10ffff */ m68k_memory_map[0x10].write16 = ar_write_regs_2; } /* internal RAM (64k), mapped at $420000-$42ffff or $600000-$60ffff */ if (action_replay.enabled) { m68k_memory_map[sp[1]].base = action_replay.ram; m68k_memory_map[sp[1]].read8 = NULL; m68k_memory_map[sp[1]].read16 = NULL; m68k_memory_map[sp[1]].write8 = ar_write_ram_8; m68k_memory_map[sp[1]].write16 = NULL; } break; } default: { break; } } if (action_replay.enabled) { /* Load ROM */ int i = 0; while (i < size) { fread(action_replay.rom+i,0x1000,1,f); i += 0x1000; } #ifdef LSB_FIRST /* Byteswap ROM */ uint8 temp; for(i = 0; i < size; i += 2) { temp = action_replay.rom[i]; action_replay.rom[i] = action_replay.rom[i+1]; action_replay.rom[i+1] = temp; } #endif } fclose(f); } void areplay_shutdown(void) { /* clear existing patches */ areplay_set_status(AR_SWITCH_OFF); /* disable device by default */ action_replay.enabled = 0; } void areplay_reset(int hard) { if (action_replay.enabled) { if (hard || (action_replay.status == AR_SWITCH_TRAINER)) { /* reset internal registers */ memset(action_replay.regs, 0, sizeof(action_replay.regs)); memset(action_replay.old, 0, sizeof(action_replay.old)); memset(action_replay.data, 0, sizeof(action_replay.data)); memset(action_replay.addr, 0, sizeof(action_replay.addr)); /* by default, internal ROM is mapped at $000000-$00FFFF */ m68k_memory_map[0].base = action_replay.rom; /* reset internal RAM on power-on */ if (hard) { memset(action_replay.ram,0xff,0x10000); } } } } int areplay_get_status(void) { if (action_replay.enabled) { return action_replay.status; } return -1; } void areplay_set_status(int status) { if (action_replay.enabled) { /* no Trainer mode for normal Action Replay */ if ((action_replay.enabled == TYPE_AR) && (status == AR_SWITCH_TRAINER)) { status = AR_SWITCH_OFF; } /* check status changes */ switch (status) { case AR_SWITCH_OFF: case AR_SWITCH_TRAINER: { /* check that patches were previously enabled */ if (action_replay.status == AR_SWITCH_ON) { /* restore original data */ *(uint16 *)(cart.rom + action_replay.addr[0]) = action_replay.old[0]; *(uint16 *)(cart.rom + action_replay.addr[1]) = action_replay.old[1]; *(uint16 *)(cart.rom + action_replay.addr[2]) = action_replay.old[2]; *(uint16 *)(cart.rom + action_replay.addr[3]) = action_replay.old[3]; } break; } case AR_SWITCH_ON: { /* check that patches were previously disabled */ if (action_replay.status != AR_SWITCH_ON) { /* decode patch data */ action_replay.data[0] = action_replay.regs[0]; action_replay.data[1] = action_replay.regs[4]; action_replay.data[2] = action_replay.regs[7]; action_replay.data[3] = action_replay.regs[10]; /* decode patch address ($000000-$7fffff) */ action_replay.addr[0] = (action_replay.regs[1] | ((action_replay.regs[2] & 0x3f00) << 8)) << 1; action_replay.addr[1] = (action_replay.regs[5] | ((action_replay.regs[6] & 0x3f00) << 8)) << 1; action_replay.addr[2] = (action_replay.regs[8] | ((action_replay.regs[9] & 0x3f00) << 8)) << 1; action_replay.addr[3] = (action_replay.regs[11] | ((action_replay.regs[12] & 0x3f00) << 8)) << 1; /* save original data */ action_replay.old[0] = *(uint16 *)(cart.rom + action_replay.addr[0]); action_replay.old[1] = *(uint16 *)(cart.rom + action_replay.addr[1]); action_replay.old[2] = *(uint16 *)(cart.rom + action_replay.addr[2]); action_replay.old[3] = *(uint16 *)(cart.rom + action_replay.addr[3]); /* patch new data */ *(uint16 *)(cart.rom + action_replay.addr[0]) = action_replay.data[0]; *(uint16 *)(cart.rom + action_replay.addr[1]) = action_replay.data[1]; *(uint16 *)(cart.rom + action_replay.addr[2]) = action_replay.data[2]; *(uint16 *)(cart.rom + action_replay.addr[3]) = action_replay.data[3]; } break; } default: { return; } } /* update status */ action_replay.status = status; } } static void ar_write_regs(uint32 address, uint32 data) { /* register offset */ int offset = (address & 0xffff) >> 1; if (offset > 12) { m68k_unused_16_w(address,data); return; } /* update internal register */ action_replay.regs[offset] = data; /* MODE register */ if (action_replay.regs[3] == 0xffff) { /* check switch status */ if (action_replay.status == AR_SWITCH_ON) { /* reset existing patches */ areplay_set_status(AR_SWITCH_OFF); areplay_set_status(AR_SWITCH_ON); } /* enable Cartridge ROM */ m68k_memory_map[0].base = cart.rom; } } static void ar_write_regs_2(uint32 address, uint32 data) { /* enable Cartridge ROM */ if (((address & 0xff) == 0x78) && (data == 0xffff)) { m68k_memory_map[0].base = cart.rom; } } static void ar_write_ram_8(uint32 address, uint32 data) { /* byte writes are handled as word writes, with LSB duplicated in MSB (/LWR is not used) */ *(uint16 *)(action_replay.ram + (address & 0xfffe)) = (data | (data << 8)); }
zyking1987-genplus-droid
genplusgx/cart_hw/areplay.c
C
gpl2
8,648
/*************************************************************************************** * Genesis Plus * Backup RAM support * * Copyright (C) 2007, 2008, 2009 Eke-Eke (GCN/Wii port) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _SRAM_H_ #define _SRAM_H_ typedef struct { uint8 detected; uint8 on; uint8 custom; uint32 start; uint32 end; uint32 crc; uint8 *sram; } T_SRAM; /* Function prototypes */ extern void sram_init (); /* global variables */ extern T_SRAM sram; #endif
zyking1987-genplus-droid
genplusgx/cart_hw/sram.h
C
gpl2
1,328
/**************************************************************************** * Genesis Plus * Game Genie Hardware emulation * * Copyright (C) 2009 Eke-Eke (GCN/Wii port) * * Based on documentation from Charles McDonald * (http://cgfm2.emuviews.com/txt/genie.txt) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ #ifndef _GGENIE_H_ #define _GGENIE_H_ /* Function prototypes */ extern void ggenie_init(void); extern void ggenie_shutdown(void); extern void ggenie_reset(int hard); extern void ggenie_switch(int enable); #endif
zyking1987-genplus-droid
genplusgx/cart_hw/ggenie.h
C
gpl2
1,331
/**************************************************************************** * Genesis Plus * Master System cartridge hardware support * * Copyright (C) 1998-2007 Charles MacDonald (SMS Plus original code) * Eke-Eke (2007-2011), additional code & fixes for the GCN/Wii port * * Realtec mapper has been figured out by TascoDeluxe * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ #ifndef _SMS_CART_H_ #define _SMS_CART_H_ /* Function prototypes */ extern void sms_cart_init(void); extern void sms_cart_reset(void); extern void sms_cart_switch(int enabled); extern int sms_cart_region_detect(void); extern int sms_cart_context_save(uint8 *state); extern int sms_cart_context_load(uint8 *state, char *version); #endif
zyking1987-genplus-droid
genplusgx/cart_hw/sms_cart.h
C
gpl2
1,528
/*************************************************************************************** * Genesis Plus * Virtual System emulation * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007-2011), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "shared.h" #include "sound/Fir_Resampler.h" #include "sound/eq.h" /* Global variables */ t_bitmap bitmap; t_snd snd; uint32 mcycles_vdp; uint32 mcycles_z80; uint32 mcycles_68k; uint8 system_hw; void (*system_frame)(int do_skip); static void system_frame_md(int do_skip); static void system_frame_sms(int do_skip); static int pause_b; static EQSTATE eq; static int32 llp,rrp; /**************************************************************** * Audio subsystem ****************************************************************/ extern unsigned char soundbuffer[2048*2]; int audio_init (int samplerate, float framerate) { /* Shutdown first */ audio_shutdown(); /* Clear the sound data context */ memset(&snd, 0, sizeof (snd)); /* Default settings */ snd.sample_rate = samplerate; snd.frame_rate = framerate; /* Calculate the sound buffer size (for one frame) */ snd.buffer_size = (int)(samplerate / framerate) + 32; /* SN76489 stream buffers */ snd.psg.buffer = (int16 *) malloc(snd.buffer_size * sizeof(int16)); if (!snd.psg.buffer) return (-1); /* YM2612 stream buffers */ snd.fm.buffer = (int32 *) malloc(snd.buffer_size * sizeof(int32) * 2); if (!snd.fm.buffer) return (-1); #ifndef NGC /* Output buffers */ snd.buffer[0] = (int16 *) malloc(snd.buffer_size * sizeof(int16)); snd.buffer[1] = (int16 *) malloc(snd.buffer_size * sizeof(int16)); if (!snd.buffer[0] || !snd.buffer[1]) return (-1); #endif /* Resampling buffer */ if (config.hq_fm && !Fir_Resampler_initialize(4096)) return (-1); /* Set audio enable flag */ snd.enabled = 1; /* Reset audio */ audio_reset(); return (0); } void audio_reset(void) { /* Low-Pass filter */ llp = 0; rrp = 0; /* 3 band EQ */ audio_set_equalizer(); /* Resampling buffer */ Fir_Resampler_clear(); /* Audio buffers */ snd.psg.pos = snd.psg.buffer; snd.fm.pos = snd.fm.buffer; if (snd.psg.buffer) memset (snd.psg.buffer, 0, snd.buffer_size * sizeof(int16)); if (snd.fm.buffer) memset (snd.fm.buffer, 0, snd.buffer_size * sizeof(int32) * 2); #ifndef NGC if (snd.buffer[0]) memset (snd.buffer[0], 0, snd.buffer_size * sizeof(int16)); if (snd.buffer[1]) memset (snd.buffer[1], 0, snd.buffer_size * sizeof(int16)); #endif } void audio_set_equalizer(void) { init_3band_state(&eq,config.low_freq,config.high_freq,snd.sample_rate); eq.lg = (double)(config.lg) / 100.0; eq.mg = (double)(config.mg) / 100.0; eq.hg = (double)(config.hg) / 100.0; } void audio_shutdown(void) { /* Sound buffers */ if (snd.fm.buffer) free(snd.fm.buffer); if (snd.psg.buffer) free(snd.psg.buffer); #ifndef NGC if (snd.buffer[0]) free(snd.buffer[0]); if (snd.buffer[1]) free(snd.buffer[1]); #endif /* Resampling buffer */ Fir_Resampler_shutdown(); } int audio_update (void) { int32 i, l, r; int32 ll = llp; int32 rr = rrp; int psg_preamp = config.psg_preamp; int fm_preamp = config.fm_preamp; int filter = config.filter; uint32 factora = (config.lp_range << 16) / 100; uint32 factorb = 0x10000 - factora; int32 *fm = snd.fm.buffer; int16 *psg = snd.psg.buffer; #ifdef NGC int16 *sb = (int16 *) soundbuffer[mixbuffer]; #else int16 *sb = (int16 *)soundbuffer; #endif /* get number of available samples */ int size = sound_update(mcycles_vdp); /* return an aligned number of samples */ size &= ~7; if (config.hq_fm) { /* resample into FM output buffer */ Fir_Resampler_read(fm, size); #ifdef LOGSOUND error("%d FM samples remaining\n",Fir_Resampler_written() >> 1); #endif } else { /* adjust remaining samples in FM output buffer*/ snd.fm.pos -= (size * 2); #ifdef LOGSOUND error("%d FM samples remaining\n",(snd.fm.pos - snd.fm.buffer)>>1); #endif } /* adjust remaining samples in PSG output buffer*/ snd.psg.pos -= size; #ifdef LOGSOUND error("%d PSG samples remaining\n",snd.psg.pos - snd.psg.buffer); #endif /* mix samples */ for (i = 0; i < size; i ++) { /* PSG samples (mono) */ l = r = (((*psg++) * psg_preamp) / 100); /* FM samples (stereo) */ l += ((*fm++ * fm_preamp) / 100); r += ((*fm++ * fm_preamp) / 100); /* filtering */ if (filter & 1) { /* single-pole low-pass filter (6 dB/octave) */ ll = (ll>>16)*factora + l*factorb; rr = (rr>>16)*factora + r*factorb; l = ll >> 16; r = rr >> 16; } else if (filter & 2) { /* 3 Band EQ */ l = do_3band(&eq,l); r = do_3band(&eq,r); } /* clipping (16-bit samples) */ if (l > 32767) l = 32767; else if (l < -32768) l = -32768; if (r > 32767) r = 32767; else if (r < -32768) r = -32768; /* update sound buffer */ #ifndef NGC //snd.buffer[0][i] = r; //snd.buffer[1][i] = l; *sb++ = r; *sb++ = l; #else *sb++ = r; *sb++ = l; #endif } /* save filtered samples for next frame */ llp = ll; rrp = rr; /* keep remaining samples for next frame */ memcpy(snd.fm.buffer, fm, (snd.fm.pos - snd.fm.buffer) * 4); memcpy(snd.psg.buffer, psg, (snd.psg.pos - snd.psg.buffer) * 2); #ifdef LOGSOUND error("%d samples returned\n\n",size); #endif return size; } /**************************************************************** * Virtual Genesis initialization ****************************************************************/ void system_init(void) { gen_init(); io_init(); vdp_init(); render_init(); sound_init(); system_frame = (system_hw == SYSTEM_PBC) ? system_frame_sms : system_frame_md; } /**************************************************************** * Virtual System emulation ****************************************************************/ void system_reset(void) { gen_reset(1); io_reset(); vdp_reset(); render_reset(); sound_reset(); audio_reset(); } void system_shutdown (void) { gen_shutdown(); SN76489_Shutdown(); } static void system_frame_md(int do_skip) { /* line counter */ int line = 0; /* Z80 interrupt flag */ int zirq = 1; /* reload H Counter */ int h_counter = reg[10]; /* reset line master cycle count */ mcycles_vdp = 0; /* reload V Counter */ v_counter = lines_per_frame - 1; /* reset VDP FIFO */ fifo_write_cnt = 0; fifo_lastwrite = 0; /* update 6-Buttons & Lightguns */ input_refresh(); /* display changed during VBLANK */ if (bitmap.viewport.changed & 2) { bitmap.viewport.changed &= ~2; /* interlaced mode */ int old_interlaced = interlaced; interlaced = (reg[12] & 0x02) >> 1; if (old_interlaced != interlaced) { im2_flag = ((reg[12] & 0x06) == 0x06); odd_frame = 1; bitmap.viewport.changed = 5; /* update rendering mode */ if (reg[1] & 0x04) { if (im2_flag) { render_bg = (reg[11] & 0x04) ? render_bg_m5_im2_vs : render_bg_m5_im2; render_obj = (reg[12] & 0x08) ? render_obj_m5_im2_ste : render_obj_m5_im2; } else { render_bg = (reg[11] & 0x04) ? render_bg_m5_vs : render_bg_m5; render_obj = (reg[12] & 0x08) ? render_obj_m5_ste : render_obj_m5; } } } /* active screen height */ if (reg[1] & 0x04) { bitmap.viewport.h = 224 + ((reg[1] & 0x08) << 1); bitmap.viewport.y = (config.overscan & 1) * ((240 + 48*vdp_pal - bitmap.viewport.h) >> 1); } else { bitmap.viewport.h = 192; bitmap.viewport.y = (config.overscan & 1) * 24 * (vdp_pal + 1); } /* active screen width */ bitmap.viewport.w = 256 + ((reg[12] & 0x01) << 6); } /* clear VBLANK, DMA, FIFO FULL & field flags */ status &= 0xFEE5; /* set FIFO EMPTY flag */ status |= 0x0200; /* even/odd field flag (interlaced modes only) */ odd_frame ^= 1; if (interlaced) { status |= (odd_frame << 4); } /* update VDP DMA */ if (dma_length) { vdp_dma_update(0); } /* render last line of overscan */ if (bitmap.viewport.y) { blank_line(v_counter, -bitmap.viewport.x, bitmap.viewport.w + 2*bitmap.viewport.x); } /* parse first line of sprites */ if (reg[1] & 0x40) { parse_satb(-1); } /* run 68k & Z80 */ m68k_run(MCYCLES_PER_LINE); if (zstate == 1) { z80_run(MCYCLES_PER_LINE); } else { mcycles_z80 = MCYCLES_PER_LINE; } /* run SVP chip */ if (svp) { ssp1601_run(SVP_cycles); } /* update line cycle count */ mcycles_vdp += MCYCLES_PER_LINE; /* Active Display */ do { /* update V Counter */ v_counter = line; /* update 6-Buttons & Lightguns */ input_refresh(); /* H Interrupt */ if(--h_counter < 0) { /* reload H Counter */ h_counter = reg[10]; /* interrupt level 4 */ hint_pending = 0x10; if (reg[0] & 0x10) { m68k_irq_state |= 0x14; } } /* update VDP DMA */ if (dma_length) { vdp_dma_update(mcycles_vdp); } /* render scanline */ if (!do_skip) { render_line(line); } /* run 68k & Z80 */ m68k_run(mcycles_vdp + MCYCLES_PER_LINE); if (zstate == 1) { z80_run(mcycles_vdp + MCYCLES_PER_LINE); } else { mcycles_z80 = mcycles_vdp + MCYCLES_PER_LINE; } /* run SVP chip */ if (svp) { ssp1601_run(SVP_cycles); } /* update line cycle count */ mcycles_vdp += MCYCLES_PER_LINE; } while (++line < bitmap.viewport.h); /* end of active display */ v_counter = line; /* set VBLANK flag */ status |= 0x08; /* overscan area */ int start = lines_per_frame - bitmap.viewport.y; int end = bitmap.viewport.h + bitmap.viewport.y; /* check viewport changes */ if ((bitmap.viewport.w != bitmap.viewport.ow) || (bitmap.viewport.h != bitmap.viewport.oh)) { bitmap.viewport.ow = bitmap.viewport.w; bitmap.viewport.oh = bitmap.viewport.h; bitmap.viewport.changed |= 1; } /* update 6-Buttons & Lightguns */ input_refresh(); /* H Interrupt */ if(--h_counter < 0) { /* reload H Counter */ h_counter = reg[10]; /* interrupt level 4 */ hint_pending = 0x10; if (reg[0] & 0x10) { m68k_irq_state |= 0x14; } } /* update VDP DMA */ if (dma_length) { vdp_dma_update(mcycles_vdp); } /* render overscan */ if (line < end) { blank_line(line, -bitmap.viewport.x, bitmap.viewport.w + 2*bitmap.viewport.x); } /* update inputs before VINT (Warriors of Eternal Sun) */ // HALSAFARosd_input_Update(); /* delay between VINT flag & V Interrupt (Ex-Mutants, Tyrant) */ m68k_run(mcycles_vdp + 588); status |= 0x80; /* delay between VBLANK flag & V Interrupt (Dracula, OutRunners, VR Troopers) */ m68k_run(mcycles_vdp + 788); if (zstate == 1) { z80_run(mcycles_vdp + 788); } else { mcycles_z80 = mcycles_vdp + 788; } /* V Interrupt */ vint_pending = 0x20; if (reg[1] & 0x20) { m68k_irq_state = 0x16; } /* assert Z80 interrupt */ Z80.irq_state = ASSERT_LINE; /* run 68k & Z80 until end of line */ m68k_run(mcycles_vdp + MCYCLES_PER_LINE); if (zstate == 1) { z80_run(mcycles_vdp + MCYCLES_PER_LINE); } else { mcycles_z80 = mcycles_vdp + MCYCLES_PER_LINE; } /* run SVP chip */ if (svp) { ssp1601_run(SVP_cycles); } /* update line cycle count */ mcycles_vdp += MCYCLES_PER_LINE; /* increment line count */ line++; /* Vertical Blanking */ do { /* update V Counter */ v_counter = line; /* update 6-Buttons & Lightguns */ input_refresh(); /* render overscan */ if ((line < end) || (line >= start)) { blank_line(line, -bitmap.viewport.x, bitmap.viewport.w + 2*bitmap.viewport.x); } if (zirq) { /* Z80 interrupt is asserted exactly for one line */ m68k_run(mcycles_vdp + 788); if (zstate == 1) { z80_run(mcycles_vdp + 788); } else { mcycles_z80 = mcycles_vdp + 788; } /* clear Z80 interrupt */ Z80.irq_state = CLEAR_LINE; zirq = 0; } /* run 68k & Z80 */ m68k_run(mcycles_vdp + MCYCLES_PER_LINE); if (zstate == 1) { z80_run(mcycles_vdp + MCYCLES_PER_LINE); } else { mcycles_z80 = mcycles_vdp + MCYCLES_PER_LINE; } /* run SVP chip */ if (svp) { ssp1601_run(SVP_cycles); } /* update line cycle count */ mcycles_vdp += MCYCLES_PER_LINE; } while (++line < (lines_per_frame - 1)); /* adjust 68k & Z80 cycle count for next frame */ mcycles_68k -= mcycles_vdp; mcycles_z80 -= mcycles_vdp; } static void system_frame_sms(int do_skip) { /* line counter */ int line = 0; /* reload H Counter */ int h_counter = reg[10]; /* reset line master cycle count */ mcycles_vdp = 0; /* reload V Counter */ v_counter = lines_per_frame - 1; /* reset VDP FIFO */ fifo_write_cnt = 0; fifo_lastwrite = 0; /* update 6-Buttons & Lightguns */ input_refresh(); /* display changed during VBLANK */ if (bitmap.viewport.changed & 2) { bitmap.viewport.changed &= ~2; /* interlaced mode */ int old_interlaced = interlaced; interlaced = (reg[12] & 0x02) >> 1; if (old_interlaced != interlaced) { im2_flag = ((reg[12] & 0x06) == 0x06); odd_frame = 1; bitmap.viewport.changed = 5; /* update rendering mode */ if (reg[1] & 0x04) { if (im2_flag) { render_bg = (reg[11] & 0x04) ? render_bg_m5_im2_vs : render_bg_m5_im2; render_obj = render_obj_m5_im2; } else { render_bg = (reg[11] & 0x04) ? render_bg_m5_vs : render_bg_m5; render_obj = render_obj_m5; } } } /* active screen height */ if (reg[1] & 0x04) { bitmap.viewport.h = 224 + ((reg[1] & 0x08) << 1); bitmap.viewport.y = (config.overscan & 1) * ((240 + 48*vdp_pal - bitmap.viewport.h) >> 1); } else { bitmap.viewport.h = 192; bitmap.viewport.y = (config.overscan & 1) * 24 * (vdp_pal + 1); } /* active screen width */ bitmap.viewport.w = 256 + ((reg[12] & 0x01) << 6); } /* Detect pause button input */ if (input.pad[0] & INPUT_START) { /* NMI is edge-triggered */ if (!pause_b) { pause_b = 1; z80_set_nmi_line(ASSERT_LINE); z80_set_nmi_line(CLEAR_LINE); } } else { pause_b = 0; } /* 3-D glasses faking: skip rendering of left lens frame */ do_skip |= (work_ram[0x1ffb] & cart.special); /* clear VBLANK, DMA, FIFO FULL & field flags */ status &= 0xFEE5; /* set FIFO EMPTY flag */ status |= 0x0200; /* even/odd field flag (interlaced modes only) */ odd_frame ^= 1; if (interlaced) { status |= (odd_frame << 4); } /* update VDP DMA */ if (dma_length) { vdp_dma_update(0); } /* render last line of overscan */ if (bitmap.viewport.y) { blank_line(v_counter, -bitmap.viewport.x, bitmap.viewport.w + 2*bitmap.viewport.x); } /* parse first line of sprites */ if (reg[1] & 0x40) { parse_satb(-1); } /* latch Horizontal Scroll register (if modified during VBLANK) */ hscroll = reg[0x08]; /* run Z80 */ z80_run(MCYCLES_PER_LINE); /* update line cycle count */ mcycles_vdp += MCYCLES_PER_LINE; /* latch Vertical Scroll register */ vscroll = reg[0x09]; /* Active Display */ do { /* update V Counter */ v_counter = line; /* update 6-Buttons & Lightguns */ input_refresh(); /* H Interrupt */ if(--h_counter < 0) { /* reload H Counter */ h_counter = reg[10]; /* interrupt level 4 */ hint_pending = 0x10; if (reg[0] & 0x10) { Z80.irq_state = ASSERT_LINE; } } /* update VDP DMA */ if (dma_length) { vdp_dma_update(mcycles_vdp); } /* render scanline */ if (!do_skip) { render_line(line); } /* run Z80 */ z80_run(mcycles_vdp + MCYCLES_PER_LINE); /* update line cycle count */ mcycles_vdp += MCYCLES_PER_LINE; } while (++line < bitmap.viewport.h); /* end of active display */ v_counter = line; /* set VBLANK flag */ status |= 0x08; /* overscan area */ int start = lines_per_frame - bitmap.viewport.y; int end = bitmap.viewport.h + bitmap.viewport.y; /* check viewport changes */ if ((bitmap.viewport.w != bitmap.viewport.ow) || (bitmap.viewport.h != bitmap.viewport.oh)) { bitmap.viewport.ow = bitmap.viewport.w; bitmap.viewport.oh = bitmap.viewport.h; bitmap.viewport.changed |= 1; } /* update 6-Buttons & Lightguns */ input_refresh(); /* H Interrupt */ if(--h_counter < 0) { /* reload H Counter */ h_counter = reg[10]; /* interrupt level 4 */ hint_pending = 0x10; if (reg[0] & 0x10) { Z80.irq_state = ASSERT_LINE; } } /* update VDP DMA */ if (dma_length) { vdp_dma_update(mcycles_vdp); } /* render overscan */ if (line < end) { blank_line(line, -bitmap.viewport.x, bitmap.viewport.w + 2*bitmap.viewport.x); } /* update inputs before VINT (Warriors of Eternal Sun) */ //HALSAFARosd_input_Update(); /* run Z80 until end of line */ z80_run(mcycles_vdp + MCYCLES_PER_LINE); /* VINT flag */ status |= 0x80; /* V Interrupt */ vint_pending = 0x20; if (reg[1] & 0x20) { Z80.irq_state = ASSERT_LINE; } /* update line cycle count */ mcycles_vdp += MCYCLES_PER_LINE; /* increment line count */ line++; /* Vertical Blanking */ do { /* update V Counter */ v_counter = line; /* update 6-Buttons & Lightguns */ input_refresh(); /* render overscan */ if ((line < end) || (line >= start)) { blank_line(line, -bitmap.viewport.x, bitmap.viewport.w + 2*bitmap.viewport.x); } /* run Z80 */ z80_run(mcycles_vdp + MCYCLES_PER_LINE); /* update line cycle count */ mcycles_vdp += MCYCLES_PER_LINE; } while (++line < (lines_per_frame - 1)); /* adjust Z80 cycle count for next frame */ mcycles_z80 -= mcycles_vdp; }
zyking1987-genplus-droid
genplusgx/system.c
C
gpl2
20,140
/*************************************************************************************** * Genesis Plus * ROM Loading Support * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007,2008,2009), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _LOADROM_H_ #define _LOADROM_H_ #define MAXROMSIZE 10485760 typedef struct { char consoletype[18]; /* Genesis or Mega Drive */ char copyright[18]; /* Copyright message */ char domestic[50]; /* Domestic name of ROM */ char international[50]; /* International name of ROM */ char ROMType[4]; /* Educational or Game */ char product[14]; /* Product serial number */ unsigned short checksum; /* ROM Checksum (header) */ unsigned short realchecksum; /* ROM Checksum (calculated) */ unsigned int romstart; /* ROM start address */ unsigned int romend; /* ROM end address */ char country[18]; /* Country flag */ uint16 peripherals; /* Supported peripherals */ } ROMINFO; /* Global variables */ extern ROMINFO rominfo; extern char rom_filename[256]; /* Function prototypes */ extern int load_rom(char *filename); extern void region_autodetect(void); extern char *get_company(void); extern char *get_peripheral(int index); #endif /* _LOADROM_H_ */
zyking1987-genplus-droid
genplusgx/loadrom.h
C
gpl2
2,254
#include "shared.h" /* * PKWare Zip Header - adopted into zip standard */ #define PKZIPID 0x504b0304 #define MAXROM 0x500000 #define ZIPCHUNK 2048 #define MAXROMSIZE 10*1024*1024 /* * Zip file header definition */ typedef struct { unsigned int zipid __attribute__ ((__packed__)); // 0x04034b50 unsigned short zipversion __attribute__ ((__packed__)); unsigned short zipflags __attribute__ ((__packed__)); unsigned short compressionMethod __attribute__ ((__packed__)); unsigned short lastmodtime __attribute__ ((__packed__)); unsigned short lastmoddate __attribute__ ((__packed__)); unsigned int crc32 __attribute__ ((__packed__)); unsigned int compressedSize __attribute__ ((__packed__)); unsigned int uncompressedSize __attribute__ ((__packed__)); unsigned short filenameLength __attribute__ ((__packed__)); unsigned short extraDataLength __attribute__ ((__packed__)); } PKZIPHEADER; /* * Zip files are stored little endian * Support functions for short and int types */ static unsigned int FLIP32 (unsigned int b) { unsigned int c; c = (b & 0xff000000) >> 24; c |= (b & 0xff0000) >> 8; c |= (b & 0xff00) << 8; c |= (b & 0xff) << 24; return c; } static unsigned short FLIP16 (unsigned short b) { unsigned short c; c = (b & 0xff00) >> 8; c |= (b & 0xff) << 8; return c; } /**************************************************************************** * IsZipFile * * Returns TRUE when PKZIPID is first four characters of buffer ****************************************************************************/ int IsZipFile (char *buffer) { unsigned int *check; check = (unsigned int *) buffer; if (check[0] == PKZIPID) return 1; return 0; } /***************************************************************************** * UnZipBuffer * * It should be noted that there is a limit of 5MB total size for any ROM ******************************************************************************/ int UnZipBuffer (unsigned char *outbuffer, FILE *fd) { PKZIPHEADER pkzip; int zipoffset = 0; int zipchunk = 0; char out[ZIPCHUNK]; z_stream zs; int res; int bufferoffset = 0; int have = 0; char readbuffer[ZIPCHUNK]; char msg[64]; /*** Read Zip Header ***/ fread(readbuffer, ZIPCHUNK, 1, fd); /*** Copy PKZip header to local, used as info ***/ memcpy (&pkzip, &readbuffer, sizeof (PKZIPHEADER)); if (FLIP32 (pkzip.uncompressedSize) > MAXROMSIZE) { printf("Error","File is too large !"); return 0; } sprintf (msg, "Unzipping %d bytes ...", FLIP32 (pkzip.uncompressedSize)); printf("Information",msg,1); /*** Prepare the zip stream ***/ memset (&zs, 0, sizeof (z_stream)); zs.zalloc = Z_NULL; zs.zfree = Z_NULL; zs.opaque = Z_NULL; zs.avail_in = 0; zs.next_in = Z_NULL; res = inflateInit2 (&zs, -MAX_WBITS); if (res != Z_OK) { printf("Error","Unable to unzip file !"); return 0; } /*** Set ZipChunk for first pass ***/ zipoffset = (sizeof (PKZIPHEADER) + FLIP16 (pkzip.filenameLength) + FLIP16 (pkzip.extraDataLength)); zipchunk = ZIPCHUNK - zipoffset; /*** Now do it! ***/ do { zs.avail_in = zipchunk; zs.next_in = (Bytef *) & readbuffer[zipoffset]; /*** Now inflate until input buffer is exhausted ***/ do { zs.avail_out = ZIPCHUNK; zs.next_out = (Bytef *) & out; res = inflate (&zs, Z_NO_FLUSH); if (res == Z_MEM_ERROR) { inflateEnd (&zs); printf("Error","Unable to unzip file !"); return 0; } have = ZIPCHUNK - zs.avail_out; if (have) { /*** Copy to normal block buffer ***/ memcpy (&outbuffer[bufferoffset], &out, have); bufferoffset += have; } } while (zs.avail_out == 0); /*** Readup the next 2k block ***/ zipoffset = 0; zipchunk = ZIPCHUNK; fread(readbuffer, ZIPCHUNK, 1, fd); } while (res != Z_STREAM_END); inflateEnd (&zs); if (res == Z_STREAM_END) { if (FLIP32 (pkzip.uncompressedSize) == (unsigned int) bufferoffset) return bufferoffset; else return FLIP32 (pkzip.uncompressedSize); } return 0; }
zyking1987-genplus-droid
genplusgx/unzip.c
C
gpl2
4,323
/*************************************************************************************** * Genesis Plus * Input peripherals support * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007-2011), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _INPUT_H_ #define _INPUT_H_ /* Max. number of devices */ #define MAX_DEVICES (8) /* Ports configuration */ #define NO_SYSTEM (0) /* unconnected port*/ #define SYSTEM_MD_GAMEPAD (1) /* single 3-buttons or 6-buttons Control Pad */ #define SYSTEM_MOUSE (2) /* Sega Mouse */ #define SYSTEM_MENACER (3) /* Sega Menacer (port B only) */ #define SYSTEM_JUSTIFIER (4) /* Konami Justifiers (port B only) */ #define SYSTEM_XE_A1P (5) /* XE-A1P analog controller (port A only) */ #define SYSTEM_ACTIVATOR (6) /* Sega Activator */ #define SYSTEM_MS_GAMEPAD (7) /* single 2-buttons Control Pad (Master System) */ #define SYSTEM_LIGHTPHASER (8) /* Sega Light Phaser (Master System) */ #define SYSTEM_PADDLE (9) /* Sega Paddle Control (Master System) */ #define SYSTEM_SPORTSPAD (10) /* Sega Sports Pad (Master System) */ #define SYSTEM_TEAMPLAYER (11) /* Sega TeamPlayer */ #define SYSTEM_WAYPLAY (12) /* EA 4-Way Play (use both ports) */ /* Device type */ #define DEVICE_PAD3B (0x00) /* 3-buttons Control Pad */ #define DEVICE_PAD6B (0x01) /* 6-buttons Control Pad */ #define DEVICE_MOUSE (0x02) /* Sega Mouse */ #define DEVICE_XE_A1P (0x03) /* XE-A1P analog controller */ #define DEVICE_ACTIVATOR (0x04) /* Activator */ #define DEVICE_LIGHTGUN (0x05) /* Sega Light Phaser, Menacer or Konami Justifiers */ #define DEVICE_PAD2B (0x06) /* 2-buttons Control Pad */ #define DEVICE_PADDLE (0x07) /* Sega Paddle Control */ #define DEVICE_SPORTSPAD (0x08) /* Sega Sports Pad */ #define DEVICE_TABLET (0x09) /* PICO tablet & pen */ #define NO_DEVICE (0xff) /* unconnected device */ /* Default Input bitmasks */ #define INPUT_MODE (0x0800) #define INPUT_X (0x0400) #define INPUT_Y (0x0200) #define INPUT_Z (0x0100) #define INPUT_START (0x0080) #define INPUT_A (0x0040) #define INPUT_C (0x0020) #define INPUT_B (0x0010) #define INPUT_RIGHT (0x0008) #define INPUT_LEFT (0x0004) #define INPUT_DOWN (0x0002) #define INPUT_UP (0x0001) /* Master System specific bitmasks */ #define INPUT_BUTTON2 (0x0020) #define INPUT_BUTTON1 (0x0010) /* Mouse specific bitmask */ #define INPUT_MOUSE_CENTER (0x0040) #define INPUT_MOUSE_RIGHT (0x0020) #define INPUT_MOUSE_LEFT (0x0010) /* XE-1AP specific bitmask */ #define INPUT_XE_E1 (0x0800) #define INPUT_XE_E2 (0x0400) #define INPUT_XE_START (0x0200) #define INPUT_XE_SELECT (0x0100) #define INPUT_XE_A (0x0080) #define INPUT_XE_B (0x0040) #define INPUT_XE_C (0x0020) #define INPUT_XE_D (0x0010) /* Activator specific bitmasks */ #define INPUT_ACTIVATOR_8U (0x8000) #define INPUT_ACTIVATOR_8L (0x4000) #define INPUT_ACTIVATOR_7U (0x2000) #define INPUT_ACTIVATOR_7L (0x1000) #define INPUT_ACTIVATOR_6U (0x0800) #define INPUT_ACTIVATOR_6L (0x0400) #define INPUT_ACTIVATOR_5U (0x0200) #define INPUT_ACTIVATOR_5L (0x0100) #define INPUT_ACTIVATOR_4U (0x0080) #define INPUT_ACTIVATOR_4L (0x0040) #define INPUT_ACTIVATOR_3U (0x0020) #define INPUT_ACTIVATOR_3L (0x0010) #define INPUT_ACTIVATOR_2U (0x0008) #define INPUT_ACTIVATOR_2L (0x0004) #define INPUT_ACTIVATOR_1U (0x0002) #define INPUT_ACTIVATOR_1L (0x0001) typedef struct { uint8 system[2]; /* can be one of the SYSTEM_* values */ uint8 dev[MAX_DEVICES]; /* can be one of the DEVICE_* values */ uint16 pad[MAX_DEVICES]; /* digital inputs (any of INPUT_* values) */ int16 analog[MAX_DEVICES][2]; /* analog inputs (x/y) */ uint8 x_offset; /* gun horizontal offset */ uint8 y_offset; /* gun vertical offset */ } t_input; /* Global variables */ extern t_input input; extern int old_system[2]; /* Function prototypes */ extern void input_init(void); extern void input_reset(void); extern void input_refresh(void); #endif
zyking1987-genplus-droid
genplusgx/input_hw/input.h
C
gpl2
5,185
/*************************************************************************************** * Genesis Plus * Sega Light Phaser, Menacer & Konami Justifiers support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "../shared.h" /************************************************************************************/ /* */ /* H-counter values returned in H40 & H32 modes */ /* */ /* Inside VDP, dot counter register is 9-bit, with only upper 8 bits being returned */ /* */ /* The number of dots per raster line is 342 in H32 mode and 420 in H40 mode */ /* */ /************************************************************************************/ static const uint8 hc_256[171] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF }; static const uint8 hc_320[210] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF }; static struct { uint8 State; uint8 Port; } lightgun; void lightgun_reset(int port) { input.analog[port][0] = bitmap.viewport.w >> 1; input.analog[port][1] = bitmap.viewport.h >> 1; lightgun.State = 0x40; lightgun.Port = 4; } void lightgun_refresh(int port) { /* Check that lightgun is enabled */ if (port == lightgun.Port) { /* check if line falls within current gun Y position */ if ((input.analog[port][1] == v_counter + input.y_offset)) { /* HL enabled ? */ if (io_reg[5] & 0x80) { /* External Interrupt ? */ if (reg[11] & 0x08) { m68k_irq_state |= 0x12; } /* HV Counter Latch: 1) some games does not enable HVC latch but instead use bigger X offset --> we force the HV counter value read by the gun routine 2) for games using H40 mode, the gun routine scales up the Hcounter value --> H-Counter range is approx. 290 dot clocks */ hvc_latch = 0x10000 | (v_counter << 8); if (reg[12] & 1) { hvc_latch |= hc_320[((input.analog[port][0] * 290) / (2 * 320) + input.x_offset) % 210]; } else { hvc_latch |= hc_256[(input.analog[port][0] / 2 + input.x_offset) % 171]; } } } } } /*--------------------------------------------------------------------------*/ /* Sega Phaser */ /*--------------------------------------------------------------------------*/ static inline unsigned char phaser_read(int port) { /* FIRE button status (active low) */ unsigned char temp = ~(input.pad[port] & 0x10); /* Check that TH is set as an input */ if (io_reg[0] & (0x02 << (port >> 1))) { /* Get current X position (phaser is only used in MS compatiblity mode) */ int hcounter = hctab[(mcycles_z80 + Z80_CYCLE_OFFSET) % MCYCLES_PER_LINE]; /* Compare with gun position */ int dx = input.analog[port][0] - (hcounter << 1); int dy = input.analog[port][1] - (v_counter); /* Check if current pixel is within lightgun spot ? */ if ((abs(dy) <= 5) && (abs(dx) <= 60)) { /* set TH low */ temp &= ~0x40; /* prevents multiple latch at each port read */ if (lightgun.State) { /* latch estimated HC value */ hvc_latch = 0x10000 | (input.x_offset + (input.analog[port][0] >> 1)); lightgun.State = 0; } else { lightgun.State = 1; } } } return temp & 0x7F; } unsigned char phaser_1_read(void) { return phaser_read(0); } unsigned char phaser_2_read(void) { return phaser_read(4); } /*--------------------------------------------------------------------------*/ /* Sega Menacer */ /*--------------------------------------------------------------------------*/ unsigned char menacer_read(void) { /* Return START,A,B,C buttons status in D0-D3 (active high) */ /* TL & TR pins always return 0 (normally set as output) */ return ((input.pad[4] >> 4) & 0x0F); } /*--------------------------------------------------------------------------*/ /* Konami Justifiers */ /*--------------------------------------------------------------------------*/ unsigned char justifier_read(void) { /* Gun detection */ if (lightgun.State & 0x40) { return 0x30; } /* Return A & START button status in D0-D1 (active low) */ /* TL & TR pins should always return 1 (normally set as output) */ /* LEFT & RIGHT pins should always return 0 */ return (((~input.pad[lightgun.Port] >> 6) & 0x03) | 0x70); } void justifier_write(unsigned char data, unsigned char mask) { /* update bits set as output only */ data = (lightgun.State & ~mask) | (data & mask); /* gun index */ lightgun.Port = 4 + ((data >> 5) & 1); /* update internal state */ lightgun.State = data; }
zyking1987-genplus-droid
genplusgx/input_hw/lightgun.c
C
gpl2
8,577
/*************************************************************************************** * Genesis Plus * Sega Sports Pad support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _SPORTSPAD_H_ #define _SPORTSPAD_H_ /* Function prototypes */ extern void sportspad_reset(int index); extern unsigned char sportspad_1_read(void); extern unsigned char sportspad_2_read(void); extern void sportspad_1_write(unsigned char data, unsigned char mask); extern void sportspad_2_write(unsigned char data, unsigned char mask); #endif
zyking1987-genplus-droid
genplusgx/input_hw/sportspad.h
C
gpl2
1,377
/*************************************************************************************** * Genesis Plus * Sega Activator support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _ACTIVATOR_H_ #define _ACTIVATOR_H_ /* Function prototypes */ extern void activator_reset(int index); extern unsigned char activator_1_read(void); extern unsigned char activator_2_read(void); extern void activator_1_write(unsigned char data, unsigned char mask); extern void activator_2_write(unsigned char data, unsigned char mask); #endif
zyking1987-genplus-droid
genplusgx/input_hw/activator.h
C
gpl2
1,376
/*************************************************************************************** * Genesis Plus * Sega Paddle Control support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _PADDLE_H_ #define _PADDLE_H_ /* Function prototypes */ extern void paddle_reset(int index); extern unsigned char paddle_1_read(void); extern unsigned char paddle_2_read(void); extern void paddle_1_write(unsigned char data, unsigned char mask); extern void paddle_2_write(unsigned char data, unsigned char mask); #endif
zyking1987-genplus-droid
genplusgx/input_hw/paddle.h
C
gpl2
1,360
/*************************************************************************************** * Genesis Plus * Sega Activator support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "../shared.h" static struct { uint8 State; uint8 Counter; } activator[2]; void activator_reset(int index) { activator[index].State = 0x40; activator[index].Counter = 0; } static inline unsigned char activator_read(int port) { /* IR sensors 1-16 data (active low) */ uint16 data = ~input.pad[port]; /* Device index */ port = port >> 2; /* D1 = D0 (data is ready) */ uint8 temp = (activator[port].State & 0x01) << 1; switch (activator[port].Counter) { case 0: /* x x x x 0 1 0 0 */ temp |= 0x04; break; case 1: /* x x l1 l2 l3 l4 1 1 */ temp |= ((data << 2) & 0x3C); break; case 2: /* x x l5 l6 l7 l8 0 0 */ temp |= ((data >> 2) & 0x3C); break; case 3: /* x x h1 h2 h3 h4 1 1 */ temp |= ((data >> 6) & 0x3C); break; case 4: /* x x h5 h6 h7 h8 0 0 */ temp |= ((data >> 10) & 0x3C); break; } return temp; } static inline void activator_write(int index, unsigned char data, unsigned char mask) { /* update bits set as output only */ data = (activator[index].State & ~mask) | (data & mask); /* TH transitions */ if ((activator[index].State ^ data) & 0x40) { /* reset sequence cycle */ activator[index].Counter = 0; } else { /* D0 transitions */ if ((activator[index].State ^ data) & 0x01) { /* increment sequence cycle */ if (activator[index].Counter < 4) { activator[index].Counter++; } } } /* update internal state */ activator[index].State = data; } unsigned char activator_1_read(void) { return activator_read(0); } unsigned char activator_2_read(void) { return activator_read(4); } void activator_1_write(unsigned char data, unsigned char mask) { activator_write(0, data, mask); } void activator_2_write(unsigned char data, unsigned char mask) { activator_write(1, data, mask); }
zyking1987-genplus-droid
genplusgx/input_hw/activator.c
C
gpl2
3,014
/*************************************************************************************** * Genesis Plus * Sega Paddle Control support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "../shared.h" static struct { uint8 State; } paddle[2]; void paddle_reset(int index) { input.analog[index << 2][0] = 128; paddle[index].State = 0x40; } static inline unsigned char paddle_read(int port) { /* FIRE button status (active low) */ unsigned char temp = ~(input.pad[port] & 0x10); /* Pad index */ int index = port >> 2; /* Clear low bits */ temp &= 0x70; /* Japanese model: automatic flip-flop */ if (region_code < REGION_USA) { paddle[index].State ^= 0x40; } if (paddle[index].State & 0x40) { /* return higher bits */ temp |= (input.analog[port][0] >> 4) & 0x0F; } else { /* return lower bits */ temp |= input.analog[port][0] & 0x0F; /* set TR low */ temp &= ~0x20; } return temp; } static inline void paddle_write(int index, unsigned char data, unsigned char mask) { /* update bits set as output only */ paddle[index].State = (paddle[index].State & ~mask) | (data & mask); } unsigned char paddle_1_read(void) { return paddle_read(0); } unsigned char paddle_2_read(void) { return paddle_read(4); } void paddle_1_write(unsigned char data, unsigned char mask) { paddle_write(0, data, mask); } void paddle_2_write(unsigned char data, unsigned char mask) { paddle_write(1, data, mask); }
zyking1987-genplus-droid
genplusgx/input_hw/paddle.c
C
gpl2
2,390
/*************************************************************************************** * Genesis Plus * XE-A1P analog controller support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _XE_A1PH_ #define _XE_A1PH_ /* Function prototypes */ extern void xe_a1p_reset(void); extern unsigned char xe_a1p_read(void); extern void xe_a1p_write(unsigned char data, unsigned char mask); #endif
zyking1987-genplus-droid
genplusgx/input_hw/xe_a1p.h
C
gpl2
1,242
/*************************************************************************************** * Genesis Plus * Sega Mouse support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "../shared.h" static struct { uint8 State; uint8 Counter; uint8 Wait; uint8 Port; } mouse; void mouse_reset(int port) { input.analog[port][0] = 0; input.analog[port][1] = 0; mouse.State = 0x60; mouse.Counter = 0; mouse.Wait = 0; mouse.Port = port; } unsigned char mouse_read() { unsigned int temp = 0x00; int x = input.analog[mouse.Port][0]; int y = input.analog[mouse.Port][1]; switch (mouse.Counter) { case 0: /* initial */ temp = 0x00; break; case 1: /* xxxx1011 */ temp = 0x0B; break; case 2: /* xxxx1111 */ temp = 0x0F; break; case 3: /* xxxx1111 */ temp = 0x0F; break; case 4: /* Axis sign & overflow (not emulated) bits */ temp |= (x < 0); temp |= (y < 0) << 1; /* temp |= (abs(x) > 255) << 2; temp |= (abs(y) > 255) << 3; */ break; case 5: /* START, A, B, C buttons state (active high) */ temp = (input.pad[mouse.Port] >> 4) & 0x0F; break; case 6: /* X Axis MSB */ temp = (x >> 4) & 0x0F; break; case 7: /* X Axis LSB */ temp = (x & 0x0F); break; case 8: /* Y Axis MSB */ temp = (y >> 4) & 0x0F; break; case 9: /* Y Axis LSB */ temp = (y & 0x0F); break; } /* TL = busy status */ if (mouse.Wait) { /* wait before ACK, fix some buggy mouse routine (Shangai 2, Wack World,...) */ mouse.Wait = 0; /* TL = !TR */ temp |= (~mouse.State & 0x20) >> 1; } else { /* TL = TR (data is ready) */ temp |= (mouse.State & 0x20) >> 1; } return temp; } void mouse_write(unsigned char data, unsigned char mask) { /* update bits set as output only */ data = (mouse.State & ~mask) | (data & mask); if (mouse.Counter == 0) { /* wait for TH 1->0 transition */ if ((mouse.State & 0x40) && !(data & 0x40)) { /* start acquisition */ mouse.Counter = 1; } } else { /* TR handshake */ if ((mouse.State ^ data) & 0x20) { /* increment phase */ if (mouse.Counter < 10) { mouse.Counter++; } /* input latency */ mouse.Wait = 1; } } /* end of acquisition (TH=1) */ if (data & 0x40) { mouse.Counter = 0; } /* update internal state */ mouse.State = data; }
zyking1987-genplus-droid
genplusgx/input_hw/mouse.c
C
gpl2
3,493
/*************************************************************************************** * Genesis Plus * Team Player support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "../shared.h" static struct { uint8 State; uint8 Counter; uint8 Table[12]; } teamplayer[2]; void teamplayer_init(int port) { int i,padnum; int index = 0; /* this table determines which gamepad input should be returned during acquisition sequence index = teamplayer read table index: 0=1st read, 1=2nd read, ... table = high bits are pad index, low bits are pad input shift: 0=RLDU, 4=SABC, 8=MXYZ */ for (i=0; i<4; i++) { padnum = (4 * port) + i; if (input.dev[padnum] == DEVICE_PAD3B) { padnum = padnum << 4; teamplayer[port].Table[index++] = padnum; teamplayer[port].Table[index++] = padnum | 4; } else { padnum = padnum << 4; teamplayer[port].Table[index++] = padnum; teamplayer[port].Table[index++] = padnum | 4; teamplayer[port].Table[index++] = padnum | 8; } } } void teamplayer_reset(int port) { teamplayer[port].State = 0x60; /* TH = 1, TR = 1 */ teamplayer[port].Counter = 0; } static inline unsigned int teamplayer_read(int port) { unsigned int counter = teamplayer[port].Counter; /* acquisition sequence */ switch (counter) { case 0: /* initial state: TH = 1, TR = 1 -> RLDU = 0011 */ { return 0x73; } case 1: /* start request: TH = 0, TR = 1 -> RLDU = 1111 */ { return 0x3F; } case 2: case 3: /* ack request: TH=0, TR=0/1 -> RLDU = 0000 */ { /* TL should match TR */ return ((teamplayer[port].State & 0x20) >> 1); } case 4: case 5: case 6: case 7: /* PAD type */ { unsigned int retval = input.dev[(port << 2) + (counter - 4)]; /* TL should match TR */ return (((teamplayer[port].State & 0x20) >> 1) | retval); } default: /* PAD status */ { unsigned int retval = 0x0F; /* SEGA teamplayer returns successively PAD1 -> PAD2 -> PAD3 -> PAD4 inputs */ unsigned int padnum = teamplayer[port].Table[counter - 8] >> 4; /* Each PAD inputs is obtained through 2 or 3 sequential reads: RLDU -> SACB -> MXYZ */ retval &= ~(input.pad[padnum] >> (teamplayer[port].Table[counter - 8] & 0x0F)); /* TL should match TR */ return (((teamplayer[port].State & 0x20) >> 1) | retval); } } } static inline void teamplayer_write(int port, unsigned char data, unsigned char mask) { /* update bits set as output only */ unsigned int state = (teamplayer[port].State & ~mask) | (data & mask); /* TH & TR handshaking */ if ((teamplayer[port].State ^ state) & 0x60) { if (state & 0x40) { /* TH high -> reset counter */ teamplayer[port].Counter = 0; } else { /* increment counter */ teamplayer[port].Counter++; } /* update internal state */ teamplayer[port].State = state; } } unsigned char teamplayer_1_read(void) { return teamplayer_read(0); } unsigned char teamplayer_2_read(void) { return teamplayer_read(1); } void teamplayer_1_write(unsigned char data, unsigned char mask) { teamplayer_write(0, data, mask); } void teamplayer_2_write(unsigned char data, unsigned char mask) { teamplayer_write(1, data, mask); }
zyking1987-genplus-droid
genplusgx/input_hw/teamplayer.c
C
gpl2
4,332
/*************************************************************************************** * Genesis Plus * Input peripherals support * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007-2011), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "../shared.h" #include "gamepad.h" #include "lightgun.h" #include "mouse.h" #include "activator.h" #include "xe_a1p.h" #include "teamplayer.h" #include "paddle.h" #include "sportspad.h" t_input input; int old_system[2] = {-1,-1}; void input_init(void) { int i; int player = 0; for (i=0; i<MAX_DEVICES; i++) { input.dev[i] = NO_DEVICE; input.pad[i] = 0; } /* PICO tablet & pen */ if (system_hw == SYSTEM_PICO) { input.dev[0] = DEVICE_TABLET; return; } switch (input.system[0]) { case SYSTEM_MS_GAMEPAD: { if (player == MAX_INPUTS) return; input.dev[0] = DEVICE_PAD2B; player++; break; } case SYSTEM_MD_GAMEPAD: { if (player == MAX_INPUTS) return; input.dev[0] = config.input[player].padtype; player++; break; } case SYSTEM_MOUSE: { if (player == MAX_INPUTS) return; input.dev[0] = DEVICE_MOUSE; player++; break; } case SYSTEM_ACTIVATOR: { if (player == MAX_INPUTS) return; input.dev[0] = DEVICE_ACTIVATOR; player++; break; } case SYSTEM_XE_A1P: { if (player == MAX_INPUTS) return; input.dev[0] = DEVICE_XE_A1P; player++; break; } case SYSTEM_WAYPLAY: { for (i=0; i< 4; i++) { if (player == MAX_INPUTS) return; input.dev[i] = config.input[player].padtype; player++; } break; } case SYSTEM_TEAMPLAYER: { for (i=0; i<4; i++) { if (player == MAX_INPUTS) return; input.dev[i] = config.input[player].padtype; player++; } teamplayer_init(0); break; } case SYSTEM_LIGHTPHASER: { if (player == MAX_INPUTS) return; input.dev[0] = DEVICE_LIGHTGUN; player++; break; } case SYSTEM_PADDLE: { if (player == MAX_INPUTS) return; input.dev[0] = DEVICE_PADDLE; player++; break; } case SYSTEM_SPORTSPAD: { if (player == MAX_INPUTS) return; input.dev[0] = DEVICE_SPORTSPAD; player++; break; } } switch (input.system[1]) { case SYSTEM_MS_GAMEPAD: { if (player == MAX_INPUTS) return; input.dev[4] = DEVICE_PAD2B; player++; break; } case SYSTEM_MD_GAMEPAD: { if (player == MAX_INPUTS) return; input.dev[1] = config.input[player].padtype; player++; break; } case SYSTEM_MOUSE: { if (player == MAX_INPUTS) return; input.dev[4] = DEVICE_MOUSE; player++; break; } case SYSTEM_ACTIVATOR: { if (player == MAX_INPUTS) return; input.dev[4] = DEVICE_ACTIVATOR; player++; break; } case SYSTEM_MENACER: { if (player == MAX_INPUTS) return; input.dev[4] = DEVICE_LIGHTGUN; player++; break; } case SYSTEM_JUSTIFIER: { for (i=4; i<6; i++) { if (player == MAX_INPUTS) return; input.dev[i] = DEVICE_LIGHTGUN; player++; } break; } case SYSTEM_TEAMPLAYER: { for (i=4; i<8; i++) { if (player == MAX_INPUTS) return; input.dev[i] = config.input[player].padtype; player++; } teamplayer_init(1); break; } case SYSTEM_LIGHTPHASER: { if (player == MAX_INPUTS) return; input.dev[4] = DEVICE_LIGHTGUN; player++; break; } case SYSTEM_PADDLE: { if (player == MAX_INPUTS) return; input.dev[4] = DEVICE_PADDLE; player++; break; } case SYSTEM_SPORTSPAD: { if (player == MAX_INPUTS) return; input.dev[4] = DEVICE_SPORTSPAD; player++; break; } } /* J-CART */ if (cart.special & HW_J_CART) { /* two additional gamepads */ for (i=5; i<7; i++) { if (player == MAX_INPUTS) return; input.dev[i] = config.input[player].padtype; player ++; } } } void input_reset(void) { /* Reset input devices */ int i; for (i=0; i<MAX_DEVICES; i++) { switch (input.dev[i]) { case DEVICE_PAD2B: case DEVICE_PAD3B: case DEVICE_PAD6B: { gamepad_reset(i); break; } case DEVICE_LIGHTGUN: { lightgun_reset(i); break; } case DEVICE_MOUSE: { mouse_reset(i); break; } case DEVICE_ACTIVATOR: { activator_reset(i >> 2); break; } case DEVICE_XE_A1P: { xe_a1p_reset(); break; } case DEVICE_PADDLE: { paddle_reset(i >> 2); break; } case DEVICE_SPORTSPAD: { sportspad_reset(i >> 2); break; } default: { break; } } } /* Team Player */ for (i=0; i<2; i++) { if (input.system[i] == SYSTEM_TEAMPLAYER) { teamplayer_reset(i); } } } void input_refresh(void) { int i; for (i=0; i<MAX_DEVICES; i++) { switch (input.dev[i]) { case DEVICE_PAD6B: { gamepad_refresh(i); break; } case DEVICE_LIGHTGUN: { lightgun_refresh(i); break; } } } }
zyking1987-genplus-droid
genplusgx/input_hw/input.c
C
gpl2
6,762
/*************************************************************************************** * Genesis Plus * Team Player support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _TEAMPLAYER_H_ #define _TEAMPLAYER_H_ /* Function prototypes */ extern void teamplayer_init(int port); extern void teamplayer_reset(int port); extern unsigned char teamplayer_1_read(void); extern unsigned char teamplayer_2_read(void); extern void teamplayer_1_write(unsigned char data, unsigned char mask); extern void teamplayer_2_write(unsigned char data, unsigned char mask); #endif
zyking1987-genplus-droid
genplusgx/input_hw/teamplayer.h
C
gpl2
1,419
/*************************************************************************************** * Genesis Plus * Sega Sports Pad support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "../shared.h" static struct { uint8 State; uint8 Counter; } sportspad[2]; void sportspad_reset(int index) { input.analog[index << 2][0] = 128; input.analog[index << 2][1] = 128; sportspad[index].State = 0x40; sportspad[index].Counter = 0; } static inline unsigned char sportspad_read(int port) { /* Buttons 1(B) & 2(C) status (active low) */ unsigned char temp = ~(input.pad[port] & 0x30); /* Pad index */ int index = port >> 2; /* Clear low bits */ temp &= 0x70; /* Detect current state */ switch (sportspad[index].Counter & 3) { case 1: { /* X position high bits */ temp |= (input.analog[port][0] >> 4) & 0x0F; break; } case 2: { /* X position low bits */ temp |= input.analog[port][0] & 0x0F; break; } case 3: { /* Y position high bits */ temp |= (input.analog[port][1] >> 4) & 0x0F; break; } default: { /* Y position low bits */ temp |= input.analog[port][1] & 0x0F; break; } } return temp; } static inline void sportspad_write(int index, unsigned char data, unsigned char mask) { /* update bits set as output only */ data = (sportspad[index].State & ~mask) | (data & mask); /* check TH transitions */ if ((data ^ sportspad[index].State) & 0x40) { sportspad[index].Counter++; } /* update internal state */ sportspad[index].State = data; } unsigned char sportspad_1_read(void) { return sportspad_read(0); } unsigned char sportspad_2_read(void) { return sportspad_read(4); } void sportspad_1_write(unsigned char data, unsigned char mask) { sportspad_write(0, data, mask); } void sportspad_2_write(unsigned char data, unsigned char mask) { sportspad_write(1, data, mask); }
zyking1987-genplus-droid
genplusgx/input_hw/sportspad.c
C
gpl2
2,894
/*************************************************************************************** * Genesis Plus * Sega Light Phaser, Menacer & Konami Justifiers support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _LIGHTGUN_H_ #define _LIGHTGUN_H_ /* Input devices port handlers */ extern void lightgun_reset(int index); extern void lightgun_refresh(int port); extern unsigned char phaser_1_read(void); extern unsigned char phaser_2_read(void); extern unsigned char menacer_read(void); extern unsigned char justifier_read(void); extern void justifier_write(unsigned char data, unsigned char mask); #endif
zyking1987-genplus-droid
genplusgx/input_hw/lightgun.h
C
gpl2
1,460
/*************************************************************************************** * Genesis Plus * XE-A1P analog controller support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "../shared.h" static struct { uint8 State; uint8 Counter; uint8 Latency; } xe_a1p; void xe_a1p_reset(void) { input.analog[0][0] = 128; input.analog[0][1] = 128; input.analog[1][0] = 128; xe_a1p.State = 0x40; xe_a1p.Counter = 0; xe_a1p.Latency = 0; } unsigned char xe_a1p_read() { unsigned int temp = 0x40; /* Left Stick X & Y analog values (bidirectional) */ int x = input.analog[0][0]; int y = input.analog[0][1]; /* Right Stick X or Y value (unidirectional) */ int z = input.analog[1][0]; /* Buttons status (active low) */ uint16 pad = ~input.pad[0]; /* Current 4-bit data cycle */ /* There are eight internal data cycle for each 5 acquisition sequence */ /* First 4 return the same 4-bit data, next 4 return next 4-bit data */ switch (xe_a1p.Counter >> 2) { case 0: temp |= ((pad >> 8) & 0x0F); /* E1 E2 Start Select */ break; case 1: temp |= ((pad >> 4) & 0x0F); /* A B C D */ break; case 2: temp |= ((x >> 4) & 0x0F); break; case 3: temp |= ((y >> 4) & 0x0F); break; case 4: break; case 5: temp |= ((z >> 4) & 0x0F); break; case 6: temp |= (x & 0x0F); break; case 7: temp |= (y & 0x0F); break; case 8: break; case 9: temp |= (z & 0x0F); break; } /* Get current internal cycle (0-7) */ unsigned int cycle = xe_a1p.Counter & 7; /* TL indicates which part of data is returned (0=1st part, 1=2nd part) */ temp |= ((cycle & 4) << 2); /* TR indicates if data is ready (0=ready, 1=not ready) */ /* Fastest One input routine actually expects this bit to switch between 0 & 1 */ /* so we make the first read of a data cycle return 1 then 0 for remaining reads */ temp |= (!(cycle & 3) << 5); /* Automatically increment data cycle on each read (within current acquisition sequence) */ cycle = (cycle + 1) & 7; /* Update internal cycle counter */ xe_a1p.Counter = (xe_a1p.Counter & ~7) | cycle; /* Update internal latency on each read */ xe_a1p.Latency++; return temp; } void xe_a1p_write(unsigned char data, unsigned char mask) { /* update bits set as output only */ data = (xe_a1p.State & ~mask) | (data & mask); /* look for TH 1->0 transitions */ if (!(data & 0x40) && (xe_a1p.State & 0x40)) { /* reset acquisition cycle */ xe_a1p.Latency = xe_a1p.Counter = 0; } else { /* some games immediately write new data to TH */ /* so we make sure first sequence has actually been handled */ if (xe_a1p.Latency > 2) { /* next acquisition sequence */ xe_a1p.Counter = (xe_a1p.Counter & ~7) + 8; /* 5 sequence max with 8 cycles each */ if (xe_a1p.Counter > 32) { xe_a1p.Counter = 32; } } } /* update internal state */ xe_a1p.State = data; }
zyking1987-genplus-droid
genplusgx/input_hw/xe_a1p.c
C
gpl2
4,020
/*************************************************************************************** * Genesis Plus * 3-Buttons & 6-Buttons pad support (incl. 4-WayPlay & J-Cart handlers) * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007-2011), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _GAMEPAD_H_ #define _GAMEPAD_H_ /* Function prototypes */ extern void gamepad_reset(int port); extern void gamepad_refresh(int port); extern unsigned char gamepad_1_read(void); extern unsigned char gamepad_2_read(void); extern unsigned char gamepad_2_read_2p(void); extern void gamepad_1_write(unsigned char data, unsigned char mask); extern void gamepad_2_write(unsigned char data, unsigned char mask); extern void gamepad_2_write_2p(unsigned char data, unsigned char mask); extern unsigned char wayplay_1_read(void); extern unsigned char wayplay_2_read(void); extern void wayplay_1_write(unsigned char data, unsigned char mask); extern void wayplay_2_write(unsigned char data, unsigned char mask); extern unsigned int jcart_read(unsigned int address); extern void jcart_write(unsigned int address, unsigned int data); #endif
zyking1987-genplus-droid
genplusgx/input_hw/gamepad.h
C
gpl2
2,044
/*************************************************************************************** * Genesis Plus * 3-Buttons & 6-Buttons pad support (incl. 4-WayPlay & J-Cart handlers) * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007-2011), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "../shared.h" #include "gamepad.h" static struct { uint8 State; uint8 Counter; uint8 Timeout; } gamepad[MAX_DEVICES]; static uint8 pad_index; void gamepad_reset(int port) { /* default state (Gouketsuji Ichizoku / Power Instinct, Samurai Spirits / Samurai Shodown) */ gamepad[port].State = 0x40; gamepad[port].Counter = 0; gamepad[port].Timeout = 0; /* reset pad index (4-WayPlay) */ pad_index = 0; } void gamepad_refresh(int port) { /* 6-buttons pad */ if (gamepad[port].Timeout++ > 25) { gamepad[port].Counter = 0; gamepad[port].Timeout = 0; } } static inline unsigned char gamepad_read(int port) { /* bit 7 is latched, returns current TH state */ unsigned int data = (gamepad[port].State & 0x40) | 0x3F; /* pad value */ unsigned int val = input.pad[port]; /* get current step (TH state) */ unsigned int step = (gamepad[port].Counter & 6) | ((data >> 6) & 1); switch (step) { case 1: /*** First High ***/ case 3: /*** Second High ***/ case 5: /*** Third High ***/ { /* TH = 1 : ?1CBRLDU */ data &= ~(val & 0x3F); break; } case 0: /*** First low ***/ case 2: /*** Second low ***/ { /* TH = 0 : ?0SA00DU */ data &= ~(val & 0x03); data &= ~((val >> 2) & 0x30); data &= ~0x0C; break; } /* 6buttons specific (taken from gen-hw.txt) */ /* A 6-button gamepad allows the extra buttons to be read based on how */ /* many times TH is switched from 1 to 0 (and not 0 to 1). Observe the */ /* following sequence */ /* TH = 1 : ?1CBRLDU 3-button pad return value TH = 0 : ?0SA00DU 3-button pad return value TH = 1 : ?1CBRLDU 3-button pad return value TH = 0 : ?0SA0000 D3-0 are forced to '0' TH = 1 : ?1CBMXYZ Extra buttons returned in D3-0 TH = 0 : ?0SA1111 D3-0 are forced to '1' */ case 4: /*** Third Low ***/ { /* TH = 0 : ?0SA0000 D3-0 are forced to '0'*/ data &= ~((val >> 2) & 0x30); data &= ~0x0F; break; } case 6: /*** Fourth Low ***/ { /* TH = 0 : ?0SA1111 D3-0 are forced to '1'*/ data &= ~((val >> 2) & 0x30); break; } case 7: /*** Fourth High ***/ { /* TH = 1 : ?1CBMXYZ Extra buttons returned in D3-0*/ data &= ~(val & 0x30); data &= ~((val >> 8) & 0x0F); break; } } return data; } static inline void gamepad_write(int port, unsigned char data, unsigned char mask) { /* update bits set as output only */ data = (gamepad[port].State & ~mask) | (data & mask); if (input.dev[port] == DEVICE_PAD6B) { /* check TH transitions */ if ((gamepad[port].State ^ data) & 0x40) { gamepad[port].Counter++; gamepad[port].Timeout = 0; } } /* update internal state */ gamepad[port].State = data; } /*--------------------------------------------------------------------------*/ /* Default ports handlers */ /*--------------------------------------------------------------------------*/ unsigned char gamepad_1_read(void) { return gamepad_read(0); } unsigned char gamepad_2_read_2p(void) { return gamepad_read(1); } unsigned char gamepad_2_read(void) { return gamepad_read(4); } void gamepad_1_write(unsigned char data, unsigned char mask) { gamepad_write(0, data, mask); } void gamepad_2_write(unsigned char data, unsigned char mask) { gamepad_write(4, data, mask); } void gamepad_2_write_2p(unsigned char data, unsigned char mask) { gamepad_write(1, data, mask); } /*--------------------------------------------------------------------------*/ /* 4-WayPlay ports handler */ /*--------------------------------------------------------------------------*/ unsigned char wayplay_1_read(void) { if (pad_index < 4) { return gamepad_read(pad_index); } /* multitap detection */ return 0x70; } unsigned char wayplay_2_read(void) { return 0x7F; } void wayplay_1_write(unsigned char data, unsigned char mask) { if (pad_index < 4) { gamepad_write(pad_index, data, mask); } } void wayplay_2_write(unsigned char data, unsigned char mask) { if ((mask & 0x70) == 0x70) { pad_index = (data & 0x70) >> 4; } } /*--------------------------------------------------------------------------*/ /* J-Cart memory handlers */ /*--------------------------------------------------------------------------*/ unsigned int jcart_read(unsigned int address) { /* TH2 output read is fixed to zero (fixes Micro Machines 2) */ return ((gamepad_read(5) & 0x7F) | ((gamepad_read(6) & 0x3F) << 8)); } void jcart_write(unsigned int address, unsigned int data) { gamepad_write(5, (data & 1) << 6, 0x40); gamepad_write(6, (data & 1) << 6, 0x40); return; }
zyking1987-genplus-droid
genplusgx/input_hw/gamepad.c
C
gpl2
6,329
/*************************************************************************************** * Genesis Plus * Sega Mouse support * * Copyright Eke-Eke (2007-2011) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _MOUSE_H_ #define _MOUSE_H_ /* Function prototypes */ extern void mouse_reset(int port); extern unsigned char mouse_read(void); extern void mouse_write(unsigned char data, unsigned char mask); #endif
zyking1987-genplus-droid
genplusgx/input_hw/mouse.h
C
gpl2
1,229
/*************************************************************************************** * Genesis Plus * Video Display Processor (Mode 4 & Mode 5 rendering) * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007-2011), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "shared.h" #include "ntsc/md_ntsc.h" #include "ntsc/sms_ntsc.h" /*** NTSC Filters ***/ extern md_ntsc_t *md_ntsc; extern sms_ntsc_t *sms_ntsc; /* Pixel priority look-up tables information */ #define LUT_MAX (6) #define LUT_SIZE (0x10000) #ifdef ALIGN_LONG /* Or change the names if you depend on these from elsewhere.. */ #undef READ_LONG #undef WRITE_LONG static __inline__ uint32 READ_LONG(void *address) { if ((uint32)address & 3) { #ifdef LSB_FIRST /* little endian version */ return ( *((uint8 *)address) + (*((uint8 *)address+1) << 8) + (*((uint8 *)address+2) << 16) + (*((uint8 *)address+3) << 24) ); #else /* big endian version */ return ( *((uint8 *)address+3) + (*((uint8 *)address+2) << 8) + (*((uint8 *)address+1) << 16) + (*((uint8 *)address) << 24) ); #endif /* LSB_FIRST */ } else return *(uint32 *)address; } static __inline__ void WRITE_LONG(void *address, uint32 data) { if ((uint32)address & 3) { #ifdef LSB_FIRST *((uint8 *)address) = data; *((uint8 *)address+1) = (data >> 8); *((uint8 *)address+2) = (data >> 16); *((uint8 *)address+3) = (data >> 24); #else *((uint8 *)address+3) = data; *((uint8 *)address+2) = (data >> 8); *((uint8 *)address+1) = (data >> 16); *((uint8 *)address) = (data >> 24); #endif /* LSB_FIRST */ return; } else *(uint32 *)address = data; } #endif /* ALIGN_LONG */ /* Draw 2-cell column (8-pixels high) */ /* Pattern cache base address: VHN NNNNNNNN NNYYYxxx with : x = Pattern Pixel (0-7) Y = Pattern Row (0-7) N = Pattern Number (0-2047) from pattern attribute H = Horizontal Flip bit from pattern attribute V = Vertical Flip bit from pattern attribute */ #define GET_LSB_TILE(ATTR, LINE) \ atex = atex_table[(ATTR >> 13) & 7]; \ src = (uint32 *)&bg_pattern_cache[(ATTR & 0x00001FFF) << 6 | (LINE)]; #define GET_MSB_TILE(ATTR, LINE) \ atex = atex_table[(ATTR >> 29) & 7]; \ src = (uint32 *)&bg_pattern_cache[(ATTR & 0x1FFF0000) >> 10 | (LINE)]; /* Draw 2-cell column (16 pixels high) */ /* Pattern cache base address: VHN NNNNNNNN NYYYYxxx with : x = Pattern Pixel (0-7) Y = Pattern Row (0-15) N = Pattern Number (0-1023) H = Horizontal Flip bit V = Vertical Flip bit */ #define GET_LSB_TILE_IM2(ATTR, LINE) \ atex = atex_table[(ATTR >> 13) & 7]; \ src = (uint32 *)&bg_pattern_cache[((ATTR & 0x000003FF) << 7 | (ATTR & 0x00001800) << 6 | (LINE)) ^ ((ATTR & 0x00001000) >> 6)]; #define GET_MSB_TILE_IM2(ATTR, LINE) \ atex = atex_table[(ATTR >> 29) & 7]; \ src = (uint32 *)&bg_pattern_cache[((ATTR & 0x03FF0000) >> 9 | (ATTR & 0x18000000) >> 10 | (LINE)) ^ ((ATTR & 0x10000000) >> 22)]; /* One column = 2 tiles Two pattern attributes are written in VRAM as two consecutives 16-bit words: P = priority bit C = color palette (2 bits) V = Vertical Flip bit H = Horizontal Flip bit N = Pattern Number (11 bits) (MSB) PCCVHNNN NNNNNNNN (LSB) (MSB) PCCVHNNN NNNNNNNN (LSB) PATTERN1 PATTERN2 Both pattern attributes are read from VRAM as one 32-bit word: LIT_ENDIAN: (MSB) PCCVHNNN NNNNNNNN PCCVHNNN NNNNNNNN (LSB) PATTERN2 PATTERN1 BIG_ENDIAN: (MSB) PCCVHNNN NNNNNNNN PCCVHNNN NNNNNNNN (LSB) PATTERN1 PATTERN2 In line buffers, one pixel = one byte: (msb) 0Pppcccc (lsb) with: P = priority bit (from pattern attribute) p = color palette (from pattern attribute) c = color data (from pattern cache) One pattern = 8 pixels = 8 bytes = two 32-bit writes per pattern */ #ifdef ALIGN_LONG #ifdef LSB_FIRST #define DRAW_COLUMN(ATTR, LINE) \ GET_LSB_TILE(ATTR, LINE) \ WRITE_LONG(dst, src[0] | atex); \ dst++; \ WRITE_LONG(dst, src[1] | atex); \ dst++; \ GET_MSB_TILE(ATTR, LINE) \ WRITE_LONG(dst, src[0] | atex); \ dst++; \ WRITE_LONG(dst, src[1] | atex); \ dst++; #define DRAW_COLUMN_IM2(ATTR, LINE) \ GET_LSB_TILE_IM2(ATTR, LINE) \ WRITE_LONG(dst, src[0] | atex); \ dst++; \ WRITE_LONG(dst, src[1] | atex); \ dst++; \ GET_MSB_TILE_IM2(ATTR, LINE) \ WRITE_LONG(dst, src[0] | atex); \ dst++; \ WRITE_LONG(dst, src[1] | atex); \ dst++; #else #define DRAW_COLUMN(ATTR, LINE) \ GET_MSB_TILE(ATTR, LINE) \ WRITE_LONG(dst, src[0] | atex); \ dst++; \ WRITE_LONG(dst, src[1] | atex); \ dst++; \ GET_LSB_TILE(ATTR, LINE) \ WRITE_LONG(dst, src[0] | atex); \ dst++; \ WRITE_LONG(dst, src[1] | atex); \ dst++; #define DRAW_COLUMN_IM2(ATTR, LINE) \ GET_MSB_TILE_IM2(ATTR, LINE) \ WRITE_LONG(dst, src[0] | atex); \ dst++; \ WRITE_LONG(dst, src[1] | atex); \ dst++; \ GET_LSB_TILE_IM2(ATTR, LINE) \ WRITE_LONG(dst, src[0] | atex); \ dst++; \ WRITE_LONG(dst, src[1] | atex); \ dst++; #endif #else /* NOT ALIGNED */ #ifdef LSB_FIRST #define DRAW_COLUMN(ATTR, LINE) \ GET_LSB_TILE(ATTR, LINE) \ *dst++ = (src[0] | atex); \ *dst++ = (src[1] | atex); \ GET_MSB_TILE(ATTR, LINE) \ *dst++ = (src[0] | atex); \ *dst++ = (src[1] | atex); #define DRAW_COLUMN_IM2(ATTR, LINE) \ GET_LSB_TILE_IM2(ATTR, LINE) \ *dst++ = (src[0] | atex); \ *dst++ = (src[1] | atex); \ GET_MSB_TILE_IM2(ATTR, LINE) \ *dst++ = (src[0] | atex); \ *dst++ = (src[1] | atex); #else #define DRAW_COLUMN(ATTR, LINE) \ GET_MSB_TILE(ATTR, LINE) \ *dst++ = (src[0] | atex); \ *dst++ = (src[1] | atex); \ GET_LSB_TILE(ATTR, LINE) \ *dst++ = (src[0] | atex); \ *dst++ = (src[1] | atex); #define DRAW_COLUMN_IM2(ATTR, LINE) \ GET_MSB_TILE_IM2(ATTR, LINE) \ *dst++ = (src[0] | atex); \ *dst++ = (src[1] | atex); \ GET_LSB_TILE_IM2(ATTR, LINE) \ *dst++ = (src[0] | atex); \ *dst++ = (src[1] | atex); #endif #endif /* ALIGN_LONG */ #ifdef ALT_RENDERER /* Draw background tiles directly using priority look-up table */ /* SRC_A = layer A rendered pixel line (4 bytes = 4 pixels at once) */ /* SRC_B = layer B cached pixel line (4 bytes = 4 pixels at once) */ /* Note: cache address is always aligned so no need to use READ_LONG macro */ /* This might be faster or slower than original method, depending on */ /* architecture (x86, PowerPC), cache size, memory access speed, etc... */ #ifdef LSB_FIRST #define DRAW_BG_TILE(SRC_A, SRC_B) \ *lb++ = table[((SRC_B << 8) & 0xff00) | (SRC_A & 0xff)]; \ *lb++ = table[(SRC_B & 0xff00) | ((SRC_A >> 8) & 0xff)]; \ *lb++ = table[((SRC_B >> 8) & 0xff00) | ((SRC_A >> 16) & 0xff)]; \ *lb++ = table[((SRC_B >> 16) & 0xff00) | ((SRC_A >> 24) & 0xff)]; #else #define DRAW_BG_TILE(SRC_A, SRC_B) \ *lb++ = table[((SRC_B >> 16) & 0xff00) | ((SRC_A >> 24) & 0xff)]; \ *lb++ = table[((SRC_B >> 8) & 0xff00) | ((SRC_A >> 16) & 0xff)]; \ *lb++ = table[(SRC_B & 0xff00) | ((SRC_A >> 8) & 0xff)]; \ *lb++ = table[((SRC_B << 8) & 0xff00) | (SRC_A & 0xff)]; #endif #ifdef ALIGN_LONG #ifdef LSB_FIRST #define DRAW_BG_COLUMN(ATTR, LINE, SRC_A, SRC_B) \ GET_LSB_TILE(ATTR, LINE) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ GET_MSB_TILE(ATTR, LINE) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) #define DRAW_BG_COLUMN_IM2(ATTR, LINE, SRC_A, SRC_B) \ GET_LSB_TILE_IM2(ATTR, LINE) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ GET_MSB_TILE_IM2(ATTR, LINE) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) #else #define DRAW_BG_COLUMN(ATTR, LINE, SRC_A, SRC_B) \ GET_MSB_TILE(ATTR, LINE) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ GET_LSB_TILE(ATTR, LINE) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) #define DRAW_BG_COLUMN_IM2(ATTR, LINE, SRC_A, SRC_B) \ GET_MSB_TILE_IM2(ATTR, LINE) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ GET_LSB_TILE_IM2(ATTR, LINE) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = READ_LONG((uint32 *)lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) #endif #else /* NOT ALIGNED */ #ifdef LSB_FIRST #define DRAW_BG_COLUMN(ATTR, LINE, SRC_A, SRC_B) \ GET_LSB_TILE(ATTR, LINE) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ GET_MSB_TILE(ATTR, LINE) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) #define DRAW_BG_COLUMN_IM2(ATTR, LINE, SRC_A, SRC_B) \ GET_LSB_TILE_IM2(ATTR, LINE) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ GET_MSB_TILE_IM2(ATTR, LINE) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) #else #define DRAW_BG_COLUMN(ATTR, LINE, SRC_A, SRC_B) \ GET_MSB_TILE(ATTR, LINE) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ GET_LSB_TILE(ATTR, LINE) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) #define DRAW_BG_COLUMN_IM2(ATTR, LINE, SRC_A, SRC_B) \ GET_MSB_TILE_IM2(ATTR, LINE) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ GET_LSB_TILE_IM2(ATTR, LINE) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[0] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) \ SRC_A = *(uint32 *)(lb); \ SRC_B = (src[1] | atex); \ DRAW_BG_TILE(SRC_A, SRC_B) #endif #endif /* ALIGN_LONG */ #endif /* ALT_RENDERER */ #define DRAW_SPRITE_TILE(WIDTH,ATTR,TABLE) \ for (i=0;i<WIDTH;i++) \ { \ temp = *src++; \ if (temp & 0x0f) \ { \ temp |= (lb[i] << 8); \ lb[i] = TABLE[temp | ATTR]; \ if (temp & 0x8000) \ { \ status |= 0x20; \ } \ } \ } /* Pixel conversion macros */ /* 4-bit color channels are either compressed to 2/3-bit or dithered to 5/6/8-bit equivalents */ /* 3:3:2 RGB */ #define MAKE_PIXEL_8(r,g,b) (((r) >> 1) << 5 | ((g) >> 1) << 2 | (b) >> 2) /* 5:5:5 RGB */ #define MAKE_PIXEL_15(r,g,b) ((r) << 11 | ((r) >> 3) << 10 | (g) << 6 | ((g) >> 3) << 5 | (b) << 1 | (b) >> 3) /* 5:6:5 RGB */ #define MAKE_PIXEL_16(r,g,b) ((r) << 12 | ((r) >> 3) << 11 | (g) << 7 | ((g) >> 2) << 5 | (b) << 1 | (b) >> 3) /* 8:8:8 RGB */ #ifdef HALDROID #define MAKE_PIXEL_32(r,g,b) ((b) << 20 | (b) << 16 | (g) << 12 | (g) << 8 | (r) << 4 | (r)) #else #define MAKE_PIXEL_32(r,g,b) ((r) << 20 | (r) << 16 | (g) << 12 | (g) << 8 | (b) << 4 | (b)) #endif /* Window & Plane A clipping */ static struct clip_t { uint8 left; uint8 right; uint8 enable; } clip[2]; /* Pattern attribute (priority + palette bits) expansion table */ static const uint32 atex_table[] = { 0x00000000, 0x10101010, 0x20202020, 0x30303030, 0x40404040, 0x50505050, 0x60606060, 0x70707070 }; /* Sprite pattern name offset look-up table (Mode 5) */ static uint8 name_lut[0x400]; /* Bitplane to packed pixel look-up table (Mode 4) */ static uint32 bp_lut[0x10000]; /* Layer priority pixel look-up tables */ static uint8 lut[LUT_MAX][LUT_SIZE]; #ifdef NGC /* 16-bit pixel color mapping */ static uint16 pixel[0x100]; static uint16 pixel_lut[3][0x200]; static uint16 pixel_lut_m4[0x40]; #else /* 8-bit pixel color mapping */ static uint8 pixel_8[0x100]; static uint8 pixel_8_lut[3][0x200]; static uint8 pixel_8_lut_m4[0x40]; /* 15-bit pixel color mapping */ static uint16 pixel_15[0x100]; static uint16 pixel_15_lut[3][0x200]; static uint16 pixel_15_lut_m4[0x40]; /* 16-bit pixel color mapping */ static uint16 pixel_16[0x100]; static uint16 pixel_16_lut[3][0x200]; static uint16 pixel_16_lut_m4[0x40]; /* 32-bit pixel color mapping */ static uint32 pixel_32[0x100]; static uint32 pixel_32_lut[3][0x200]; static uint32 pixel_32_lut_m4[0x40]; #endif /* Background & Sprite line buffers */ static uint8 linebuf[2][0x200]; /* Sprite limit flag */ static int spr_over = 0; /* Sprites parsing */ static struct { uint16 ypos; uint16 xpos; uint16 attr; uint16 size; } object_info[20]; uint8 object_count; /* Function pointers */ void (*render_bg)(int line, int width); void (*render_obj)(int max_width); void (*parse_satb)(int line); void (*update_bg_pattern_cache)(int index); #ifndef NGC void (*color_update)(int index, unsigned int data); #endif /*--------------------------------------------------------------------------*/ /* Sprite pattern name offset look-up table function (Mode 5) */ /*--------------------------------------------------------------------------*/ static void make_name_lut(void) { int vcol, vrow; int width, height; int flipx, flipy; int i; for (i = 0; i < 0x400; i += 1) { /* Sprite settings */ vcol = i & 3; vrow = (i >> 2) & 3; height = (i >> 4) & 3; width = (i >> 6) & 3; flipx = (i >> 8) & 1; flipy = (i >> 9) & 1; if ((vrow > height) || vcol > width) { /* Invalid settings (unused) */ name_lut[i] = -1; } else { /* Adjust column & row index if sprite is flipped */ if(flipx) vcol = (width - vcol); if(flipy) vrow = (height - vrow); /* Pattern offset (pattern order is up->down->left->right) */ name_lut[i] = vrow + (vcol * (height + 1)); } } } /*--------------------------------------------------------------------------*/ /* Bitplane to packed pixel look-up table function (Mode 4) */ /*--------------------------------------------------------------------------*/ static void make_bp_lut(void) { int x,i,j; uint32 out; /* ---------------------- */ /* Pattern color encoding */ /* -------------------------------------------------------------------------*/ /* 4 byteplanes are required to define one pattern line (8 pixels) */ /* A single pixel color is coded with 4 bits (c3 c2 c1 c0) */ /* Each bit is coming from byteplane bits, as explained below: */ /* pixel 0: c3 = bp3 bit 7, c2 = bp2 bit 7, c1 = bp1 bit 7, c0 = bp0 bit 7 */ /* pixel 1: c3 = bp3 bit 6, c2 = bp2 bit 6, c1 = bp1 bit 6, c0 = bp0 bit 6 */ /* ... */ /* pixel 7: c3 = bp3 bit 0, c2 = bp2 bit 0, c1 = bp1 bit 0, c0 = bp0 bit 0 */ /* -------------------------------------------------------------------------*/ for(i = 0; i < 0x100; i++) for(j = 0; j < 0x100; j++) { out = 0; for(x = 0; x < 8; x++) { /* pixel line data = hh00gg00ff00ee00dd00cc00bb00aa00 (32-bit) */ /* aa-hh = upper or lower 2-bit values of pixels 0-7 (shifted) */ out |= (j & (0x80 >> x)) ? (uint32)(8 << (x << 2)) : 0; out |= (i & (0x80 >> x)) ? (uint32)(4 << (x << 2)) : 0; } /* i = low byte in VRAM (bp0 or bp2) */ /* j = high byte in VRAM (bp1 or bp3) */ #ifdef LSB_FIRST bp_lut[(j << 8) | (i)] = out; #else bp_lut[(i << 8) | (j)] = out; #endif } } /*--------------------------------------------------------------------------*/ /* Layers priority pixel look-up tables functions */ /*--------------------------------------------------------------------------*/ /* Input (bx): d5-d0=color, d6=priority, d7=unused */ /* Input (ax): d5-d0=color, d6=priority, d7=unused */ /* Output: d5-d0=color, d6=priority, d7=zero */ static uint32 make_lut_bg(uint32 bx, uint32 ax) { int bf = (bx & 0x7F); int bp = (bx & 0x40); int b = (bx & 0x0F); int af = (ax & 0x7F); int ap = (ax & 0x40); int a = (ax & 0x0F); int c = (ap ? (a ? af : bf) : (bp ? (b ? bf : af) : (a ? af : bf))); /* Strip palette & priority bits from transparent pixels */ if((c & 0x0F) == 0x00) c &= 0x80; return (c); } /* Input (bx): d5-d0=color, d6=priority, d7=unused */ /* Input (sx): d5-d0=color, d6=priority, d7=unused */ /* Output: d5-d0=color, d6=priority, d7=intensity select (0=half/1=normal) */ static uint32 make_lut_bg_ste(uint32 bx, uint32 ax) { int bf = (bx & 0x7F); int bp = (bx & 0x40); int b = (bx & 0x0F); int af = (ax & 0x7F); int ap = (ax & 0x40); int a = (ax & 0x0F); int c = (ap ? (a ? af : bf) : (bp ? (b ? bf : af) : (a ? af : bf))); /* Half intensity when both pixels are low priority */ c |= ((ap | bp) << 1); /* Strip palette & priority bits from transparent pixels */ if((c & 0x0F) == 0x00) c &= 0x80; return (c); } /* Input (bx): d5-d0=color, d6=priority/1, d7=sprite pixel marker */ /* Input (sx): d5-d0=color, d6=priority, d7=unused */ /* Output: d5-d0=color, d6=priority, d7=sprite pixel marker */ static uint32 make_lut_obj(uint32 bx, uint32 sx) { int bf = (bx & 0x7F); int bs = (bx & 0x80); int sf = (sx & 0x7F); if((sx & 0x0F) == 0) return bx; int c = (bs ? bf : sf); /* Strip palette bits from transparent pixels */ if((c & 0x0F) == 0x00) c &= 0xC0; return (c | 0x80); } /* Input (bx): d5-d0=color, d6=priority, d7=opaque sprite pixel marker */ /* Input (sx): d5-d0=color, d6=priority, d7=unused */ /* Output: d5-d0=color, d6=zero/priority, d7=opaque sprite pixel marker */ static uint32 make_lut_bgobj(uint32 bx, uint32 sx) { int bf = (bx & 0x3F); int bs = (bx & 0x80); int bp = (bx & 0x40); int b = (bx & 0x0F); int sf = (sx & 0x3F); int sp = (sx & 0x40); int s = (sx & 0x0F); if(s == 0) return bx; /* Previous sprite has higher priority */ if(bs) return bx; int c = (sp ? sf : (bp ? (b ? bf : sf) : sf)); /* Strip palette & priority bits from transparent pixels */ if((c & 0x0F) == 0x00) c &= 0x80; return (c | 0x80); } /* Input (bx): d5-d0=color, d6=priority, d7=intensity (half/normal) */ /* Input (sx): d5-d0=color, d6=priority, d7=sprite marker */ /* Output: d5-d0=color, d6=intensity (half/normal), d7=(double/invalid) */ static uint32 make_lut_bgobj_ste(uint32 bx, uint32 sx) { int c; int bf = (bx & 0x3F); int bp = (bx & 0x40); int b = (bx & 0x0F); int bi = (bx & 0x80) >> 1; int sf = (sx & 0x3F); int sp = (sx & 0x40); int s = (sx & 0x0F); int si = sp | bi; if(sp) { if(s) { if((sf & 0x3E) == 0x3E) { if(sf & 1) { c = (bf | 0x00); } else { c = (bx & 0x80) ? (bf | 0x80) : (bf | 0x40); } } else { if(sf == 0x0E || sf == 0x1E || sf == 0x2E) { c = (sf | 0x40); } else { c = (sf | si); } } } else { c = (bf | bi); } } else { if(bp) { if(b) { c = (bf | bi); } else { if(s) { if((sf & 0x3E) == 0x3E) { if(sf & 1) { c = (bf | 0x00); } else { c = (bx & 0x80) ? (bf | 0x80) : (bf | 0x40); } } else { if(sf == 0x0E || sf == 0x1E || sf == 0x2E) { c = (sf | 0x40); } else { c = (sf | si); } } } else { c = (bf | bi); } } } else { if(s) { if((sf & 0x3E) == 0x3E) { if(sf & 1) { c = (bf | 0x00); } else { c = (bx & 0x80) ? (bf | 0x80) : (bf | 0x40); } } else { if(sf == 0x0E || sf == 0x1E || sf == 0x2E) { c = (sf | 0x40); } else { c = (sf | si); } } } else { c = (bf | bi); } } } if((c & 0x0f) == 0x00) c &= 0xC0; return (c); } /* Input (bx): d3-d0=color, d4=palette, d5=priority, d6=zero, d7=sprite pixel marker */ /* Input (sx): d3-d0=color, d7-d4=zero */ /* Output: d3-d0=color, d4=palette, d5=zero/priority, d6=zero, d7=sprite pixel marker */ static uint32 make_lut_bgobj_m4(uint32 bx, uint32 sx) { int bf = (bx & 0x3F); int bs = (bx & 0x80); int bp = (bx & 0x20); int b = (bx & 0x0F); int s = (sx & 0x0F); int sf = (s | 0x10); /* force palette bit */ if(s == 0) return bx; /* Previous sprite has higher priority */ if(bs) return bx; int c = (bp ? (b ? bf : sf) : sf); return (c | 0x80); } /*--------------------------------------------------------------------------*/ /* Pixel layer merging function */ /*--------------------------------------------------------------------------*/ static inline void merge(uint8 *srca, uint8 *srcb, uint8 *dst, uint8 *table, int width) { do { *dst++ = table[(*srcb++ << 8) | (*srca++)]; } while (--width); } #ifndef NGC /*--------------------------------------------------------------------------*/ /* Pixel color mapping functions */ /*--------------------------------------------------------------------------*/ static inline void remap_8(uint8 *src, uint8 *dst, int length) { do { *dst++ = pixel_8[*src++]; } while (--length); } static inline void remap_16(uint8 *src, uint16 *dst, int length) { do { *dst++ = pixel_16[*src++]; } while (--length); } static inline void remap_32(uint8 *src, uint32 *dst, int length) { do { *dst++ = pixel_32[*src++]; } while (--length); } #endif /*--------------------------------------------------------------------------*/ /* Pixel color lookup tables initialization */ /*--------------------------------------------------------------------------*/ static void palette_init(void) { int r, g, b, i; /************************************************/ /* Each R,G,B color channel is 4-bit with a */ /* total of 15 different intensity levels. */ /* */ /* Color intensity depends on the mode: */ /* */ /* normal : xxx0 (0-14) */ /* shadow : 0xxx (0-7) */ /* highlight: 1xxx - 1 (7-14) */ /* mode4 : xx00 ? (0-12) */ /* */ /* with x = original 2-bit or 3-bit CRAM value */ /************************************************/ /* Initialize Mode 5 pixel color look-up tables */ for (i = 0; i < 0x200; i++) { /* CRAM value in mode 5 (BBBGGGRRR) */ r = (i >> 0) & 7; g = (i >> 3) & 7; b = (i >> 6) & 7; /* Convert to output pixel format */ #ifdef NGC /* 5:6:5 RGB */ pixel_lut[0][i] = MAKE_PIXEL_16(r,g,b); pixel_lut[1][i] = MAKE_PIXEL_16(r<<1,g<<1,b<<1); pixel_lut[2][i] = MAKE_PIXEL_16(r+7,g+7,b+7); #else /* 3:3:2 RGB */ pixel_8_lut[0][i] = MAKE_PIXEL_8(r,g,b); pixel_8_lut[1][i] = MAKE_PIXEL_8(r<<1,g<<1,b<<1); pixel_8_lut[2][i] = MAKE_PIXEL_8(r+7,g+7,b+7); /* 5:5:5 RGB */ pixel_15_lut[0][i] = MAKE_PIXEL_15(r,g,b); pixel_15_lut[1][i] = MAKE_PIXEL_15(r<<1,g<<1,b<<1); pixel_15_lut[2][i] = MAKE_PIXEL_15(r+7,g+7,b+7); /* 5:6:5 RGB */ pixel_16_lut[0][i] = MAKE_PIXEL_16(r,g,b); pixel_16_lut[1][i] = MAKE_PIXEL_16(r<<1,g<<1,b<<1); pixel_16_lut[2][i] = MAKE_PIXEL_16(r+7,g+7,b+7); /* 8:8:8 RGB */ pixel_32_lut[0][i] = MAKE_PIXEL_32(r,g,b); pixel_32_lut[1][i] = MAKE_PIXEL_32(r<<1,g<<1,b<<1); pixel_32_lut[2][i] = MAKE_PIXEL_32(r+7,g+7,b+7); #endif } /* Initialize Mode 4 pixel color look-up table */ for (i = 0; i < 0x40; i++) { /* CRAM value in mode 4 (000BBGGRR) */ r = (i >> 0) & 3; g = (i >> 2) & 3; b = (i >> 4) & 3; /* Convert to output pixel format (expand to 4-bit for brighter colors ?) */ #ifdef NGC /* 5:6:5 RGB */ pixel_lut_m4[i] = MAKE_PIXEL_16(r << 2,g << 2,b<< 2); #else /* 3:3:2 RGB */ pixel_8_lut_m4[i] = MAKE_PIXEL_8(r << 2,g << 2,b<< 2); /* 5:5:5 RGB */ pixel_15_lut_m4[i] = MAKE_PIXEL_15(r << 2,g << 2,b<< 2); /* 5:6:5 RGB */ pixel_16_lut_m4[i] = MAKE_PIXEL_16(r << 2,g << 2,b<< 2); /* 8:8:8 RGB */ pixel_32_lut_m4[i] = MAKE_PIXEL_32(r << 2,g << 2,b<< 2); #endif } } /*--------------------------------------------------------------------------*/ /* Color palette update functions */ /*--------------------------------------------------------------------------*/ #ifndef NGC static void color_update_8(int index, unsigned int data) { /* Mode 5 */ if (reg[1] & 4) { /* VDP Palette Selection bit */ if (!(reg[0] & 4)) { /* Color value is limited to 00X00X00X */ data &= 0x49; } if(reg[12] & 8) { /* Mode 5 (Shadow/Normal/Highlight) */ pixel_8[0x00 | index] = pixel_8_lut[0][data]; pixel_8[0x40 | index] = pixel_8_lut[1][data]; pixel_8[0x80 | index] = pixel_8_lut[2][data]; } else { /* Mode 5 (Normal) */ data = pixel_8_lut[1][data]; /* Output pixel: xxiiiiii */ pixel_8[0x00 | index] = data; pixel_8[0x40 | index] = data; pixel_8[0x80 | index] = data; } } else { /* Test M4 bit */ if (reg[0] & 4) { /* Mode 4 */ data = pixel_8_lut_m4[data & 0x3F]; } else { /* Invalid Mode (black screen) */ data = 0x00; } /* Output pixel: x0xiiiii */ /* Backdrop pixel: 01000000 */ pixel_8[0x00 | index] = data; pixel_8[0x20 | index] = data; pixel_8[0x80 | index] = data; pixel_8[0xA0 | index] = data; } } static void color_update_15(int index, unsigned int data) { /* Mode 5 */ if (reg[1] & 4) { /* VDP Palette Selection bit */ if (!(reg[0] & 4)) { /* Color value is limited to 00X00X00X */ data &= 0x49; } if(reg[12] & 8) { /* Mode 5 (Shadow/Normal/Highlight) */ pixel_15[0x00 | index] = pixel_15_lut[0][data]; pixel_15[0x40 | index] = pixel_15_lut[1][data]; pixel_15[0x80 | index] = pixel_15_lut[2][data]; } else { /* Mode 5 (Normal) */ data = pixel_15_lut[1][data]; /* Output pixel: xxiiiiii */ pixel_15[0x00 | index] = data; pixel_15[0x40 | index] = data; pixel_15[0x80 | index] = data; } } else { /* Test M4 bit */ if (reg[0] & 4) { /* Mode 4 */ data = pixel_15_lut_m4[data & 0x3F]; } else { /* Invalid Mode (black screen) */ data = 0x00; } /* Output pixel: x0xiiiii */ /* Backdrop pixel: 01000000 */ pixel_15[0x00 | index] = data; pixel_15[0x20 | index] = data; pixel_15[0x80 | index] = data; pixel_15[0xA0 | index] = data; } } static void color_update_16(int index, unsigned int data) { /* Mode 5 */ if (reg[1] & 4) { /* VDP Palette Selection bit */ if (!(reg[0] & 4)) { /* Color value is limited to 00X00X00X */ data &= 0x49; } if(reg[12] & 8) { /* Mode 5 (Shadow/Normal/Highlight) */ pixel_16[0x00 | index] = pixel_16_lut[0][data]; pixel_16[0x40 | index] = pixel_16_lut[1][data]; pixel_16[0x80 | index] = pixel_16_lut[2][data]; } else { /* Mode 5 (Normal) */ data = pixel_16_lut[1][data]; /* Output pixel: xxiiiiii */ pixel_16[0x00 | index] = data; pixel_16[0x40 | index] = data; pixel_16[0x80 | index] = data; } } else { /* Test M4 bit */ if (reg[0] & 4) { /* Mode 4 */ data = pixel_16_lut_m4[data & 0x3F]; } else { /* Invalid Mode (black screen) */ data = 0x00; } /* Output pixel: x0xiiiii */ /* Backdrop pixel: 01000000 */ pixel_16[0x00 | index] = data; pixel_16[0x20 | index] = data; pixel_16[0x80 | index] = data; pixel_16[0xA0 | index] = data; } } static void color_update_32(int index, unsigned int data) { /* Mode 5 */ if (reg[1] & 4) { /* VDP Palette Selection bit */ if (!(reg[0] & 4)) { /* Color value is limited to 00X00X00X */ data &= 0x49; } if(reg[12] & 8) { /* Mode 5 (Shadow/Normal/Highlight) */ pixel_32[0x00 | index] = pixel_32_lut[0][data]; pixel_32[0x40 | index] = pixel_32_lut[1][data]; pixel_32[0x80 | index] = pixel_32_lut[2][data]; } else { /* Mode 5 (Normal) */ data = pixel_32_lut[1][data]; /* Output pixel: xxiiiiii */ pixel_32[0x00 | index] = data; pixel_32[0x40 | index] = data; pixel_32[0x80 | index] = data; } } else { /* Test M4 bit */ if (reg[0] & 4) { /* Mode 4 */ data = pixel_32_lut_m4[data & 0x3F]; } else { /* Invalid Mode (black screen) */ data = 0x00; } /* Output pixel: x0xiiiii */ /* Backdrop pixel: 01000000 */ pixel_32[0x00 | index] = data; pixel_32[0x20 | index] = data; pixel_32[0x80 | index] = data; pixel_32[0xA0 | index] = data; } } #else void color_update(int index, unsigned int data) { /* Mode 5 */ if (reg[1] & 4) { /* Palette selection */ if (!(reg[0] & 4)) { /* Color value is limited to 00X00X00X */ data &= 0x49; } if(reg[12] & 8) { /* Mode 5 (Shadow/Normal/Highlight) */ pixel[0x00 | index] = pixel_lut[0][data]; pixel[0x40 | index] = pixel_lut[1][data]; pixel[0x80 | index] = pixel_lut[2][data]; } else { /* Mode 5 (Normal) */ data = pixel_lut[1][data]; /* Output pixel: xxiiiiii */ pixel[0x00 | index] = data; pixel[0x40 | index] = data; pixel[0x80 | index] = data; } } else { /* Test M4 bit */ if (reg[0] & 4) { /* Mode 4 */ data = pixel_lut_m4[data & 0x3F]; } else { /* Invalid Mode (black screen) */ data = 0x00; } /* Output pixel: x0xiiiii */ /* Backdrop pixel: 01000000 */ pixel[0x00 | index] = data; pixel[0x20 | index] = data; pixel[0x80 | index] = data; pixel[0xA0 | index] = data; } } #endif /*--------------------------------------------------------------------------*/ /* Background layers rendering functions */ /*--------------------------------------------------------------------------*/ void render_bg_m4(int line, int width) { int column; uint32 attr, atex, *src; /* Horizontal scrolling */ int index = ((reg[0] & 0x40) && (line < 0x10)) ? 0x100 : hscroll; int shift = index & 7; /* Background line buffer */ uint32 *dst = (uint32 *)&linebuf[0][0x20 + shift]; /* Vertical scrolling */ int v_line = (line + vscroll) % 224; /* Pattern name table */ uint16 *nt = (uint16 *)&vram[((reg[2] << 10) & 0x3800) + ((v_line >> 3) << 6)]; /* Pattern row index */ v_line = (v_line & 7) << 3; /* Tile column index */ index = (0x100 - index) >> 3; /* Clip left-most column if required */ if (shift) { memset(&linebuf[0][0x20], 0, shift); index++; } /* Number of tiles to draw */ width >>= 3; /* Draw tiles (TODO: test what happens when H40 mode has been set while in Mode 5 */ for(column = 0; column < width; column++, index++) { /* Stop vertical scrolling for rightmost eight tiles */ if((column == 24) && (reg[0] & 0x80)) { /* Clear name table base */ nt = (uint16 *)&vram[((reg[2] << 10) & 0x3800) + ((line >> 3) << 6)]; /* Clear Pattern row index */ v_line = (line & 7) << 3; } /* Read name table attribute word */ attr = nt[index % width]; #ifndef LSB_FIRST attr = (((attr & 0xFF) << 8) | ((attr & 0xFF00) >> 8)); #endif /* Expand priority and palette bits */ atex = atex_table[(attr >> 11) & 3]; /* Cached pattern data line (4 bytes = 4 pixels at once) */ src = (uint32 *)&bg_pattern_cache[((attr & 0x7FF) << 6) | (v_line)]; /* Copy left & right half, adding the attribute bits in */ #ifdef ALIGN_DWORD WRITE_LONG(dst, src[0] | atex); dst++; WRITE_LONG(dst, src[1] | atex); dst++; #else *dst++ = (src[0] | atex); *dst++ = (src[1] | atex); #endif } /* latch horizontal scroll value */ hscroll = reg[0x08]; } #ifndef ALT_RENDERER void render_bg_m5(int line, int width) { int column; uint32 atex, atbuf, *src, *dst; /* Common data */ uint32 xscroll = *(uint32 *)&vram[hscb + ((line & hscroll_mask) << 2)]; uint32 yscroll = *(uint32 *)&vsram[0]; /* Plane B width */ int start = 0; int end = width >> 4; /* Plane B scroll */ #ifdef LSB_FIRST uint32 shift = (xscroll >> 16) & 0x0F; uint32 index = playfield_col_mask + 1 - ((xscroll >> 20) & playfield_col_mask); uint32 v_line = (line + ((yscroll >> 16) & 0x3FF)) & playfield_row_mask; #else uint32 shift = (xscroll & 0x0F); uint32 index = playfield_col_mask + 1 - ((xscroll >> 4) & playfield_col_mask); uint32 v_line = (line + (yscroll & 0x3FF)) & playfield_row_mask; #endif /* Plane B name table */ uint32 *nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << playfield_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (v_line & 7) << 3; if(shift) { /* Plane B line buffer */ dst = (uint32 *)&linebuf[0][0x10 + shift]; atbuf = nt[(index - 1) & playfield_col_mask]; DRAW_COLUMN(atbuf, v_line) } else { /* Plane B line buffer */ dst = (uint32 *)&linebuf[0][0x20]; } for(column = 0; column < end; column++, index++) { atbuf = nt[index & playfield_col_mask]; DRAW_COLUMN(atbuf, v_line) } /* Window & Plane A */ int a = (reg[18] & 0x1F) << 3; int w = (reg[18] >> 7) & 1; if (w == (line >= a)) { /* Window takes up entire line */ a = 0; w = 1; } else { /* Window and Plane A share the line */ a = clip[0].enable; w = clip[1].enable; } /* Plane A */ if (a) { /* Plane A width */ start = clip[0].left; end = clip[0].right; /* Plane A scroll */ #ifdef LSB_FIRST shift = (xscroll & 0x0F); index = playfield_col_mask + start + 1 - ((xscroll >> 4) & playfield_col_mask); v_line = (line + (yscroll & 0x3FF)) & playfield_row_mask; #else shift = (xscroll >> 16) & 0x0F; index = playfield_col_mask + start + 1 - ((xscroll >> 20) & playfield_col_mask); v_line = (line + ((yscroll >> 16) & 0x3FF)) & playfield_row_mask; #endif /* Plane A name table */ nt = (uint32 *)&vram[ntab + (((v_line >> 3) << playfield_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (v_line & 7) << 3; if(shift) { /* Plane A line buffer */ dst = (uint32 *)&linebuf[1][0x10 + shift + (start << 4)]; /* Window bug */ if (start) { atbuf = nt[index & playfield_col_mask]; } else { atbuf = nt[(index - 1) & playfield_col_mask]; } DRAW_COLUMN(atbuf, v_line) } else { /* Plane A line buffer */ dst = (uint32 *)&linebuf[1][0x20 + (start << 4)]; } for(column = start; column < end; column++, index++) { atbuf = nt[index & playfield_col_mask]; DRAW_COLUMN(atbuf, v_line) } /* Window width */ start = clip[1].left; end = clip[1].right; } /* Window */ if (w) { /* Window name table */ nt = (uint32 *)&vram[ntwb | ((line >> 3) << (6 + (reg[12] & 1)))]; /* Pattern row index */ v_line = (line & 7) << 3; /* Plane A line buffer */ dst = (uint32 *)&linebuf[1][0x20 + (start << 4)]; for(column = start; column < end; column++) { atbuf = nt[column]; DRAW_COLUMN(atbuf, v_line) } } } void render_bg_m5_vs(int line, int width) { int column; uint32 atex, atbuf, *src, *dst; uint32 v_line, *nt; /* Common data */ uint32 xscroll = *(uint32 *)&vram[hscb + ((line & hscroll_mask) << 2)]; uint32 yscroll = 0; uint32 pf_col_mask = playfield_col_mask; uint32 pf_row_mask = playfield_row_mask; uint32 pf_shift = playfield_shift; uint32 *vs = (uint32 *)&vsram[0]; /* Plane B width */ int start = 0; int end = width >> 4; /* Plane B horizontal scroll */ #ifdef LSB_FIRST uint32 shift = (xscroll >> 16) & 0x0F; uint32 index = pf_col_mask + 1 - ((xscroll >> 20) & pf_col_mask); #else uint32 shift = (xscroll & 0x0F); uint32 index = pf_col_mask + 1 - ((xscroll >> 4) & pf_col_mask); #endif /* Left-most column vertical scrolling when partially shown horizontally */ /* Same value for both planes, only in 40-cell mode, verified on PAL MD2 */ /* See Gynoug, Cutie Suzuki no Ringside Angel, Formula One, Kawasaki Superbike Challenge */ if (reg[12] & 1) { yscroll = vs[19] & (vs[19] >> 16); yscroll &= 0x3FF; } if(shift) { /* Plane B vertical scroll */ v_line = (line + yscroll) & pf_row_mask; /* Plane B name table */ nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (v_line & 7) << 3; /* Plane B line buffer */ dst = (uint32 *)&linebuf[0][0x10 + shift]; atbuf = nt[(index - 1) & pf_col_mask]; DRAW_COLUMN(atbuf, v_line) } else { /* Plane B line buffer */ dst = (uint32 *)&linebuf[0][0x20]; } for(column = 0; column < end; column++, index++) { /* Plane B vertical scroll */ #ifdef LSB_FIRST v_line = (line + ((vs[column] >> 16) & 0x3FF)) & pf_row_mask; #else v_line = (line + (vs[column] & 0x3FF)) & pf_row_mask; #endif /* Plane B name table */ nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (v_line & 7) << 3; atbuf = nt[index & pf_col_mask]; DRAW_COLUMN(atbuf, v_line) } /* Window & Plane A */ int a = (reg[18] & 0x1F) << 3; int w = (reg[18] >> 7) & 1; if (w == (line >= a)) { /* Window takes up entire line */ a = 0; w = 1; } else { /* Window and Plane A share the line */ a = clip[0].enable; w = clip[1].enable; } /* Plane A */ if (a) { /* Plane A width */ start = clip[0].left; end = clip[0].right; /* Plane A horizontal scroll */ #ifdef LSB_FIRST shift = (xscroll & 0x0F); index = pf_col_mask + start + 1 - ((xscroll >> 4) & pf_col_mask); #else shift = (xscroll >> 16) & 0x0F; index = pf_col_mask + start + 1 - ((xscroll >> 20) & pf_col_mask); #endif if(shift) { /* Plane A vertical scroll */ v_line = (line + yscroll) & pf_row_mask; /* Plane A name table */ nt = (uint32 *)&vram[ntab + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (v_line & 7) << 3; /* Plane A line buffer */ dst = (uint32 *)&linebuf[1][0x10 + shift + (start << 4)]; /* Window bug */ if (start) { atbuf = nt[index & pf_col_mask]; } else { atbuf = nt[(index - 1) & pf_col_mask]; } DRAW_COLUMN(atbuf, v_line) } else { /* Plane A line buffer */ dst = (uint32 *)&linebuf[1][0x20 + (start << 4)]; } for(column = start; column < end; column++, index++) { /* Plane A vertical scroll */ #ifdef LSB_FIRST v_line = (line + (vs[column] & 0x3FF)) & pf_row_mask; #else v_line = (line + ((vs[column] >> 16) & 0x3FF)) & pf_row_mask; #endif /* Plane A name table */ nt = (uint32 *)&vram[ntab + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (v_line & 7) << 3; atbuf = nt[index & pf_col_mask]; DRAW_COLUMN(atbuf, v_line) } /* Window width */ start = clip[1].left; end = clip[1].right; } /* Window */ if (w) { /* Window name table */ nt = (uint32 *)&vram[ntwb | ((line >> 3) << (6 + (reg[12] & 1)))]; /* Pattern row index */ v_line = (line & 7) << 3; /* Plane A line buffer */ dst = (uint32 *)&linebuf[1][0x20 + (start << 4)]; for(column = start; column < end; column++) { atbuf = nt[column]; DRAW_COLUMN(atbuf, v_line) } } } void render_bg_m5_im2(int line, int width) { int column; uint32 atex, atbuf, *src, *dst; /* Common data */ uint32 xscroll = *(uint32 *)&vram[hscb + ((line & hscroll_mask) << 2)]; uint32 yscroll = *(uint32 *)&vsram[0]; uint32 pf_col_mask = playfield_col_mask; uint32 pf_row_mask = playfield_row_mask; uint32 pf_shift = playfield_shift; int odd = odd_frame; /* Plane B width */ int start = 0; int end = width >> 4; /* Plane B scroll */ #ifdef LSB_FIRST uint32 shift = (xscroll >> 16) & 0x0F; uint32 index = pf_col_mask + 1 - ((xscroll >> 20) & pf_col_mask); uint32 v_line = (line + ((yscroll >> 17) & 0x3FF)) & pf_row_mask; #else uint32 shift = (xscroll & 0x0F); uint32 index = pf_col_mask + 1 - ((xscroll >> 4) & pf_col_mask); uint32 v_line = (line + ((yscroll >> 1) & 0x3FF)) & pf_row_mask; #endif /* Plane B name table */ uint32 *nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; if(shift) { /* Plane B line buffer */ dst = (uint32 *)&linebuf[0][0x10 + shift]; atbuf = nt[(index - 1) & pf_col_mask]; DRAW_COLUMN_IM2(atbuf, v_line) } else { /* Plane B line buffer */ dst = (uint32 *)&linebuf[0][0x20]; } for(column = 0; column < end; column++, index++) { atbuf = nt[index & pf_col_mask]; DRAW_COLUMN_IM2(atbuf, v_line) } /* Window & Plane A */ int a = (reg[18] & 0x1F) << 3; int w = (reg[18] >> 7) & 1; if (w == (line >= a)) { /* Window takes up entire line */ a = 0; w = 1; } else { /* Window and Plane A share the line */ a = clip[0].enable; w = clip[1].enable; } /* Plane A */ if (a) { /* Plane A width */ start = clip[0].left; end = clip[0].right; /* Plane A scroll */ #ifdef LSB_FIRST shift = (xscroll & 0x0F); index = pf_col_mask + start + 1 - ((xscroll >> 4) & pf_col_mask); v_line = (line + ((yscroll >> 1) & 0x3FF)) & pf_row_mask; #else shift = (xscroll >> 16) & 0x0F; index = pf_col_mask + start + 1 - ((xscroll >> 20) & pf_col_mask); v_line = (line + ((yscroll >> 17) & 0x3FF)) & pf_row_mask; #endif /* Plane A name table */ nt = (uint32 *)&vram[ntab + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; if(shift) { /* Plane A line buffer */ dst = (uint32 *)&linebuf[1][0x10 + shift + (start << 4)]; /* Window bug */ if (start) { atbuf = nt[index & pf_col_mask]; } else { atbuf = nt[(index - 1) & pf_col_mask]; } DRAW_COLUMN_IM2(atbuf, v_line) } else { /* Plane A line buffer */ dst = (uint32 *)&linebuf[1][0x20 + (start << 4)]; } for(column = start; column < end; column++, index++) { atbuf = nt[index & pf_col_mask]; DRAW_COLUMN_IM2(atbuf, v_line) } /* Window width */ start = clip[1].left; end = clip[1].right; } /* Window */ if (w) { /* Window name table */ nt = (uint32 *)&vram[ntwb | ((line >> 3) << (6 + (reg[12] & 1)))]; /* Pattern row index */ v_line = ((line & 7) << 1 | odd) << 3; /* Plane A line buffer */ dst = (uint32 *)&linebuf[1][0x20 + (start << 4)]; for(column = start; column < end; column++) { atbuf = nt[column]; DRAW_COLUMN_IM2(atbuf, v_line) } } } void render_bg_m5_im2_vs(int line, int width) { int column; uint32 atex, atbuf, *src, *dst; uint32 v_line, *nt; /* Common data */ uint32 xscroll = *(uint32 *)&vram[hscb + ((line & hscroll_mask) << 2)]; uint32 yscroll = 0; uint32 pf_col_mask = playfield_col_mask; uint32 pf_row_mask = playfield_row_mask; uint32 pf_shift = playfield_shift; uint32 *vs = (uint32 *)&vsram[0]; int odd = odd_frame; /* Plane B width */ int start = 0; int end = width >> 4; /* Plane B horizontal scroll */ #ifdef LSB_FIRST uint32 shift = (xscroll >> 16) & 0x0F; uint32 index = pf_col_mask + 1 - ((xscroll >> 20) & pf_col_mask); #else uint32 shift = (xscroll & 0x0F); uint32 index = pf_col_mask + 1 - ((xscroll >> 4) & pf_col_mask); #endif /* Left-most column vertical scrolling when partially shown horizontally */ /* Same value for both planes, only in 40-cell mode, verified on PAL MD2 */ /* See Gynoug, Cutie Suzuki no Ringside Angel, Formula One, Kawasaki Superbike Challenge */ if (reg[12] & 1) { /* only in 40-cell mode, verified on MD2 */ yscroll = (vs[19] >> 1) & (vs[19] >> 17); yscroll &= 0x3FF; } if(shift) { /* Plane B vertical scroll */ v_line = (line + yscroll) & pf_row_mask; /* Plane B name table */ nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; /* Plane B line buffer */ dst = (uint32 *)&linebuf[0][0x10 + shift]; atbuf = nt[(index - 1) & pf_col_mask]; DRAW_COLUMN_IM2(atbuf, v_line) } else { /* Plane B line buffer */ dst = (uint32 *)&linebuf[0][0x20]; } for(column = 0; column < end; column++, index++) { /* Plane B vertical scroll */ #ifdef LSB_FIRST v_line = (line + ((vs[column] >> 17) & 0x3FF)) & pf_row_mask; #else v_line = (line + ((vs[column] >> 1) & 0x3FF)) & pf_row_mask; #endif /* Plane B name table */ nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; atbuf = nt[index & pf_col_mask]; DRAW_COLUMN_IM2(atbuf, v_line) } /* Window & Plane A */ int a = (reg[18] & 0x1F) << 3; int w = (reg[18] >> 7) & 1; if (w == (line >= a)) { /* Window takes up entire line */ a = 0; w = 1; } else { /* Window and Plane A share the line */ a = clip[0].enable; w = clip[1].enable; } /* Plane A */ if (a) { /* Plane A width */ start = clip[0].left; end = clip[0].right; /* Plane A horizontal scroll */ #ifdef LSB_FIRST shift = (xscroll & 0x0F); index = pf_col_mask + start + 1 - ((xscroll >> 4) & pf_col_mask); #else shift = (xscroll >> 16) & 0x0F; index = pf_col_mask + start + 1 - ((xscroll >> 20) & pf_col_mask); #endif if(shift) { /* Plane A vertical scroll */ v_line = (line + yscroll) & pf_row_mask; /* Plane A name table */ nt = (uint32 *)&vram[ntab + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; /* Plane A line buffer */ dst = (uint32 *)&linebuf[1][0x10 + shift + (start << 4)]; /* Window bug */ if (start) { atbuf = nt[index & pf_col_mask]; } else { atbuf = nt[(index - 1) & pf_col_mask]; } DRAW_COLUMN_IM2(atbuf, v_line) } else { /* Plane A line buffer */ dst = (uint32 *)&linebuf[1][0x20 + (start << 4)]; } for(column = start; column < end; column++, index++) { /* Plane A vertical scroll */ #ifdef LSB_FIRST v_line = (line + ((vs[column] >> 1) & 0x3FF)) & pf_row_mask; #else v_line = (line + ((vs[column] >> 17) & 0x3FF)) & pf_row_mask; #endif /* Plane A name table */ nt = (uint32 *)&vram[ntab + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; atbuf = nt[index & pf_col_mask]; DRAW_COLUMN_IM2(atbuf, v_line) } /* Window width */ start = clip[1].left; end = clip[1].right; } /* Window */ if (w) { /* Window name table */ nt = (uint32 *)&vram[ntwb | ((line >> 3) << (6 + (reg[12] & 1)))]; /* Pattern row index */ v_line = ((line & 7) << 1 | odd) << 3; /* Plane A line buffer */ dst = (uint32 *)&linebuf[1][0x20 + (start << 4)]; for(column = start; column < end; column++) { atbuf = nt[column]; DRAW_COLUMN_IM2(atbuf, v_line) } } } #else void render_bg_m5(int line, int width) { int column, start, end; uint32 atex, atbuf, *src, *dst; uint32 shift, index, v_line, *nt; /* Scroll Planes common data */ uint32 xscroll = *(uint32 *)&vram[hscb + ((line & hscroll_mask) << 2)]; uint32 yscroll = *(uint32 *)&vsram[0]; uint32 pf_col_mask = playfield_col_mask; uint32 pf_row_mask = playfield_row_mask; uint32 pf_shift = playfield_shift; /* Layer priority table */ uint8 *table = lut[(reg[12] & 8) >> 2]; /* Window vertical range (cell 0-31) */ int a = (reg[18] & 0x1F) << 3; /* Window position (0=top, 1=bottom) */ int w = (reg[18] >> 7) & 1; /* Test against current line */ if (w == (line >= a)) { /* Window takes up entire line */ a = 0; w = 1; } else { /* Window and Plane A share the line */ a = clip[0].enable; w = clip[1].enable; } /* Number of columns to draw */ width >>= 4; /* Plane A */ if (a) { /* Plane A width */ start = clip[0].left; end = clip[0].right; /* Plane A scroll */ #ifdef LSB_FIRST shift = (xscroll & 0x0F); index = pf_col_mask + start + 1 - ((xscroll >> 4) & pf_col_mask); v_line = (line + (yscroll & 0x3FF)) & pf_row_mask; #else shift = (xscroll >> 16) & 0x0F; index = pf_col_mask + start + 1 - ((xscroll >> 20) & pf_col_mask); v_line = (line + ((yscroll >> 16) & 0x3FF)) & pf_row_mask; #endif /* Background line buffer */ dst = (uint32 *)&linebuf[0][0x20 + (start << 4) + shift]; /* Plane A name table */ nt = (uint32 *)&vram[ntab + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (v_line & 7) << 3; if(shift) { /* Left-most column is partially shown */ dst -= 4; /* Window bug */ if (start) { atbuf = nt[index & pf_col_mask]; } else { atbuf = nt[(index-1) & pf_col_mask]; } DRAW_COLUMN(atbuf, v_line) } for(column = start; column < end; column++, index++) { atbuf = nt[index & pf_col_mask]; DRAW_COLUMN(atbuf, v_line) } /* Window width */ start = clip[1].left; end = clip[1].right; } else { /* Window width */ start = 0; end = width; } /* Window Plane */ if (w) { /* Background line buffer */ dst = (uint32 *)&linebuf[0][0x20 + (start << 4)]; /* Window name table */ nt = (uint32 *)&vram[ntwb | ((line >> 3) << (6 + (reg[12] & 1)))]; /* Pattern row index */ v_line = (line & 7) << 3; for(column = start; column < end; column++) { atbuf = nt[column]; DRAW_COLUMN(atbuf, v_line) } } /* Plane B scroll */ #ifdef LSB_FIRST shift = (xscroll >> 16) & 0x0F; index = pf_col_mask + 1 - ((xscroll >> 20) & pf_col_mask); v_line = (line + ((yscroll >> 16) & 0x3FF)) & pf_row_mask; #else shift = (xscroll & 0x0F); index = pf_col_mask + 1 - ((xscroll >> 4) & pf_col_mask); v_line = (line + (yscroll & 0x3FF)) & pf_row_mask; #endif /* Plane B name table */ nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (v_line & 7) << 3; /* Background line buffer */ uint8 *lb = &linebuf[0][0x20]; if(shift) { /* Left-most column is partially shown */ lb -= (0x10 - shift); atbuf = nt[(index-1) & pf_col_mask]; DRAW_BG_COLUMN(atbuf, v_line, xscroll, yscroll) } for(column = 0; column < width; column++, index++) { atbuf = nt[index & pf_col_mask]; DRAW_BG_COLUMN(atbuf, v_line, xscroll, yscroll) } } void render_bg_m5_vs(int line, int width) { int column, start, end; uint32 atex, atbuf, *src, *dst; uint32 shift, index, v_line, *nt; /* Scroll Planes common data */ uint32 xscroll = *(uint32 *)&vram[hscb + ((line & hscroll_mask) << 2)]; uint32 yscroll = 0; uint32 pf_col_mask = playfield_col_mask; uint32 pf_row_mask = playfield_row_mask; uint32 pf_shift = playfield_shift; uint32 *vs = (uint32 *)&vsram[0]; /* Layer priority table */ uint8 *table = lut[(reg[12] & 8) >> 2]; /* Window vertical range (cell 0-31) */ int a = (reg[18] & 0x1F) << 3; /* Window position (0=top, 1=bottom) */ int w = (reg[18] >> 7) & 1; /* Test against current line */ if (w == (line >= a)) { /* Window takes up entire line */ a = 0; w = 1; } else { /* Window and Plane A share the line */ a = clip[0].enable; w = clip[1].enable; } /* Left-most column vertical scrolling when partially shown horizontally */ /* Same value for both planes, only in 40-cell mode, verified on PAL MD2 */ /* See Gynoug, Cutie Suzuki no Ringside Angel, Formula One, Kawasaki Superbike Challenge */ if (reg[12] & 1) { yscroll = vs[19] & (vs[19] >> 16); yscroll &= 0x3FF; } /* Number of columns to draw */ width >>= 4; /* Plane A*/ if (a) { /* Plane A width */ start = clip[0].left; end = clip[0].right; /* Plane A horizontal scroll */ #ifdef LSB_FIRST shift = (xscroll & 0x0F); index = pf_col_mask + start + 1 - ((xscroll >> 4) & pf_col_mask); #else shift = (xscroll >> 16) & 0x0F; index = pf_col_mask + start + 1 - ((xscroll >> 20) & pf_col_mask); #endif /* Background line buffer */ dst = (uint32 *)&linebuf[0][0x20 + (start << 4) + shift]; if(shift) { /* Left-most column is partially shown */ dst -= 4; /* Plane A vertical scroll */ v_line = (line + yscroll) & pf_row_mask; /* Plane A name table */ nt = (uint32 *)&vram[ntab + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (v_line & 7) << 3; /* Window bug */ if (start) { atbuf = nt[index & pf_col_mask]; } else { atbuf = nt[(index-1) & pf_col_mask]; } DRAW_COLUMN(atbuf, v_line) } for(column = start; column < end; column++, index++) { /* Plane A vertical scroll */ #ifdef LSB_FIRST v_line = (line + (vs[column] & 0x3FF)) & pf_row_mask; #else v_line = (line + ((vs[column] >> 16) & 0x3FF)) & pf_row_mask; #endif /* Plane A name table */ nt = (uint32 *)&vram[ntab + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (v_line & 7) << 3; atbuf = nt[index & pf_col_mask]; DRAW_COLUMN(atbuf, v_line) } /* Window width */ start = clip[1].left; end = clip[1].right; } else { /* Window width */ start = 0; end = width; } /* Window Plane */ if (w) { /* Background line buffer */ dst = (uint32 *)&linebuf[0][0x20 + (start << 4)]; /* Window name table */ nt = (uint32 *)&vram[ntwb | ((line >> 3) << (6 + (reg[12] & 1)))]; /* Pattern row index */ v_line = (line & 7) << 3; for(column = start; column < end; column++) { atbuf = nt[column]; DRAW_COLUMN(atbuf, v_line) } } /* Plane B horizontal scroll */ #ifdef LSB_FIRST shift = (xscroll >> 16) & 0x0F; index = pf_col_mask + 1 - ((xscroll >> 20) & pf_col_mask); #else shift = (xscroll & 0x0F); index = pf_col_mask + 1 - ((xscroll >> 4) & pf_col_mask); #endif /* Background line buffer */ uint8 *lb = &linebuf[0][0x20]; if(shift) { /* Left-most column is partially shown */ lb -= (0x10 - shift); /* Plane B vertical scroll */ v_line = (line + yscroll) & pf_row_mask; /* Plane B name table */ nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (v_line & 7) << 3; atbuf = nt[(index-1) & pf_col_mask]; DRAW_BG_COLUMN(atbuf, v_line, xscroll, yscroll) } for(column = 0; column < width; column++, index++) { /* Plane B vertical scroll */ #ifdef LSB_FIRST v_line = (line + ((vs[column] >> 16) & 0x3FF)) & pf_row_mask; #else v_line = (line + (vs[column] & 0x3FF)) & pf_row_mask; #endif /* Plane B name table */ nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (v_line & 7) << 3; atbuf = nt[index & pf_col_mask]; DRAW_BG_COLUMN(atbuf, v_line, xscroll, yscroll) } } void render_bg_m5_im2(int line, int width) { int column, start, end; uint32 atex, atbuf, *src, *dst; uint32 shift, index, v_line, *nt; /* Scroll Planes common data */ int odd = odd_frame; uint32 xscroll = *(uint32 *)&vram[hscb + ((line & hscroll_mask) << 2)]; uint32 yscroll = *(uint32 *)&vsram[0]; uint32 pf_col_mask = playfield_col_mask; uint32 pf_row_mask = playfield_row_mask; uint32 pf_shift = playfield_shift; /* Layer priority table */ uint8 *table = lut[(reg[12] & 8) >> 2]; /* Window vertical range (cell 0-31) */ int a = (reg[18] & 0x1F) << 3; /* Window position (0=top, 1=bottom) */ int w = (reg[18] >> 7) & 1; /* Test against current line */ if (w == (line >= a)) { /* Window takes up entire line */ a = 0; w = 1; } else { /* Window and Plane A share the line */ a = clip[0].enable; w = clip[1].enable; } /* Number of columns to draw */ width >>= 4; /* Plane A */ if (a) { /* Plane A width */ start = clip[0].left; end = clip[0].right; /* Plane A scroll */ #ifdef LSB_FIRST shift = (xscroll & 0x0F); index = pf_col_mask + start + 1 - ((xscroll >> 4) & pf_col_mask); v_line = (line + ((yscroll >> 1) & 0x3FF)) & pf_row_mask; #else shift = (xscroll >> 16) & 0x0F; index = pf_col_mask + start + 1 - ((xscroll >> 20) & pf_col_mask); v_line = (line + ((yscroll >> 17) & 0x3FF)) & pf_row_mask; #endif /* Background line buffer */ dst = (uint32 *)&linebuf[0][0x20 + (start << 4) + shift]; /* Plane A name table */ nt = (uint32 *)&vram[ntab + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; if(shift) { /* Left-most column is partially shown */ dst -= 4; /* Window bug */ if (start) { atbuf = nt[index & pf_col_mask]; } else { atbuf = nt[(index-1) & pf_col_mask]; } DRAW_COLUMN_IM2(atbuf, v_line) } for(column = start; column < end; column++, index++) { atbuf = nt[index & pf_col_mask]; DRAW_COLUMN_IM2(atbuf, v_line) } /* Window width */ start = clip[1].left; end = clip[1].right; } else { /* Window width */ start = 0; end = width; } /* Window Plane */ if (w) { /* Background line buffer */ dst = (uint32 *)&linebuf[0][0x20 + (start << 4)]; /* Window name table */ nt = (uint32 *)&vram[ntwb | ((line >> 3) << (6 + (reg[12] & 1)))]; /* Pattern row index */ v_line = ((line & 7) << 1 | odd) << 3; for(column = start; column < end; column++) { atbuf = nt[column]; DRAW_COLUMN_IM2(atbuf, v_line) } } /* Plane B scroll */ #ifdef LSB_FIRST shift = (xscroll >> 16) & 0x0F; index = pf_col_mask + 1 - ((xscroll >> 20) & pf_col_mask); v_line = (line + ((yscroll >> 17) & 0x3FF)) & pf_row_mask; #else shift = (xscroll & 0x0F); index = pf_col_mask + 1 - ((xscroll >> 4) & pf_col_mask); v_line = (line + ((yscroll >> 1) & 0x3FF)) & pf_row_mask; #endif /* Plane B name table */ nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; /* Background line buffer */ uint8 *lb = &linebuf[0][0x20]; if(shift) { /* Left-most column is partially shown */ lb -= (0x10 - shift); atbuf = nt[(index-1) & pf_col_mask]; DRAW_BG_COLUMN_IM2(atbuf, v_line, xscroll, yscroll) } for(column = 0; column < width; column++, index++) { atbuf = nt[index & pf_col_mask]; DRAW_BG_COLUMN_IM2(atbuf, v_line, xscroll, yscroll) } } void render_bg_m5_im2_vs(int line, int width) { int column, start, end; uint32 atex, atbuf, *src, *dst; uint32 shift, index, v_line, *nt; /* common data */ int odd = odd_frame; uint32 xscroll = *(uint32 *)&vram[hscb + ((line & hscroll_mask) << 2)]; uint32 yscroll = 0; uint32 pf_col_mask = playfield_col_mask; uint32 pf_row_mask = playfield_row_mask; uint32 pf_shift = playfield_shift; uint32 *vs = (uint32 *)&vsram[0]; /* Layer priority table */ uint8 *table = lut[(reg[12] & 8) >> 2]; /* Window vertical range (cell 0-31) */ uint32 a = (reg[18] & 0x1F) << 3; /* Window position (0=top, 1=bottom) */ uint32 w = (reg[18] >> 7) & 1; /* Test against current line */ if (w == (line >= a)) { /* Window takes up entire line */ a = 0; w = 1; } else { /* Window and Plane A share the line */ a = clip[0].enable; w = clip[1].enable; } /* Left-most column vertical scrolling when partially shown horizontally */ /* Same value for both planes, only in 40-cell mode, verified on PAL MD2 */ /* See Gynoug, Cutie Suzuki no Ringside Angel, Formula One, Kawasaki Superbike Challenge */ if (reg[12] & 1) { /* only in 40-cell mode, verified on MD2 */ yscroll = (vs[19] >> 1) & (vs[19] >> 17); yscroll &= 0x3FF; } /* Number of columns to draw */ width >>= 4; /* Plane A */ if (a) { /* Plane A width */ start = clip[0].left; end = clip[0].right; /* Plane A horizontal scroll */ #ifdef LSB_FIRST shift = (xscroll & 0x0F); index = pf_col_mask + start + 1 - ((xscroll >> 4) & pf_col_mask); #else shift = (xscroll >> 16) & 0x0F; index = pf_col_mask + start + 1 - ((xscroll >> 20) & pf_col_mask); #endif /* Background line buffer */ dst = (uint32 *)&linebuf[0][0x20 + (start << 4) + shift]; if(shift) { /* Left-most column is partially shown */ dst -= 4; /* Plane A vertical scroll */ v_line = (line + yscroll) & pf_row_mask; /* Plane A name table */ nt = (uint32 *)&vram[ntab + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; /* Window bug */ if (start) { atbuf = nt[index & pf_col_mask]; } else { atbuf = nt[(index-1) & pf_col_mask]; } DRAW_COLUMN_IM2(atbuf, v_line) } for(column = start; column < end; column++, index++) { /* Plane A vertical scroll */ #ifdef LSB_FIRST v_line = (line + ((vs[column] >> 1) & 0x3FF)) & pf_row_mask; #else v_line = (line + ((vs[column] >> 17) & 0x3FF)) & pf_row_mask; #endif /* Plane A name table */ nt = (uint32 *)&vram[ntab + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; atbuf = nt[index & pf_col_mask]; DRAW_COLUMN_IM2(atbuf, v_line) } /* Window width */ start = clip[1].left; end = clip[1].right; } else { /* Window width */ start = 0; end = width; } /* Window Plane */ if (w) { /* Background line buffer */ dst = (uint32 *)&linebuf[0][0x20 + (start << 4)]; /* Window name table */ nt = (uint32 *)&vram[ntwb | ((line >> 3) << (6 + (reg[12] & 1)))]; /* Pattern row index */ v_line = ((line & 7) << 1 | odd) << 3; for(column = start; column < end; column++) { atbuf = nt[column]; DRAW_COLUMN_IM2(atbuf, v_line) } } /* Plane B horizontal scroll */ #ifdef LSB_FIRST shift = (xscroll >> 16) & 0x0F; index = pf_col_mask + 1 - ((xscroll >> 20) & pf_col_mask); #else shift = (xscroll & 0x0F); index = pf_col_mask + 1 - ((xscroll >> 4) & pf_col_mask); #endif /* Background line buffer */ uint8 *lb = &linebuf[0][0x20]; if(shift) { /* Left-most column is partially shown */ lb -= (0x10 - shift); /* Plane B vertical scroll */ v_line = (line + yscroll) & pf_row_mask; /* Plane B name table */ nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; atbuf = nt[(index-1) & pf_col_mask]; DRAW_BG_COLUMN_IM2(atbuf, v_line, xscroll, yscroll) } for(column = 0; column < width; column++, index++) { /* Plane B vertical scroll */ #ifdef LSB_FIRST v_line = (line + ((vs[column] >> 17) & 0x3FF)) & pf_row_mask; #else v_line = (line + ((vs[column] >> 1) & 0x3FF)) & pf_row_mask; #endif /* Plane B name table */ nt = (uint32 *)&vram[ntbb + (((v_line >> 3) << pf_shift) & 0x1FC0)]; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; atbuf = nt[index & pf_col_mask]; DRAW_BG_COLUMN_IM2(atbuf, v_line, xscroll, yscroll) } } #endif /*--------------------------------------------------------------------------*/ /* Sprite layer rendering functions */ /*--------------------------------------------------------------------------*/ void render_obj_m4(int max_width) { int i, count, xpos, width; uint8 *src, *lb; uint16 temp; /* Set SOVR flag */ status |= spr_over; spr_over = 0; /* Draw sprites in front-to-back order */ for (count = 0; count < object_count; count++) { /* Sprite X position */ xpos = object_info[count].xpos; /* X position shift */ xpos -= (reg[0] & 0x08); if (xpos < 0) { /* Clip sprites on left edge */ width = xpos + 8; xpos = 0; } else if ((xpos + 8) > max_width) { /* Clip sprites on right edge */ width = max_width - xpos; } else { /* Sprite default width */ width = 8; } /* Pointer to line buffer */ lb = &linebuf[0][0x20 + xpos]; /* Sprite pattern index */ temp = object_info[count].attr; /* Add MSB of pattern name */ temp |= ((reg[6] & 0x04) << 6); /* Mask LSB for 8x16 sprites */ temp &= ~((reg[1] & 0x02) >> 1); /* Pointer to pattern cache line */ src = (uint8 *)&bg_pattern_cache[(temp << 6) | (object_info[count].ypos << 3)]; /* Draw sprite pattern */ DRAW_SPRITE_TILE(width,0,lut[5]) } } void render_obj_m5(int max_width) { int i, count, column; int xpos, width; int pixelcount = 0; int masked = 0; uint8 *src, *s, *lb; uint32 temp, v_line; uint32 attr, name, atex; #ifndef ALT_RENDERER /* Merge background layers */ merge(&linebuf[1][0x20], &linebuf[0][0x20], &linebuf[0][0x20], lut[0], max_width); #endif /* Draw sprites in front-to-back order */ for (count = 0; count < object_count; count++) { /* Sprite X position */ xpos = object_info[count].xpos; /* Sprite masking */ if (xpos) { /* Requires at least one sprite with xpos > 0 */ spr_over = 1; } else if (spr_over) { /* Remaining sprites are not drawn */ masked = 1; } /* Display area offset */ xpos = xpos - 0x80; /* Sprite size */ temp = object_info[count].size; /* Sprite width */ width = 8 + ((temp & 0x0C) << 1); /* Update pixel count (off-screen sprites are included) */ pixelcount += width; /* Is sprite across visible area ? */ if (((xpos + width) > 0) && (xpos < max_width) && !masked) { /* Sprite attributes */ attr = object_info[count].attr; /* Sprite vertical offset */ v_line = object_info[count].ypos; /* Sprite priority + palette bits */ atex = (attr >> 9) & 0x70; /* Pattern name base */ name = attr & 0x07FF; /* Mask vflip/hflip */ attr &= 0x1800; /* Pointer into pattern name offset look-up table */ s = &name_lut[((attr >> 3) & 0x300) | (temp << 4) | ((v_line & 0x18) >> 1)]; /* Pointer into line buffer */ lb = &linebuf[0][0x20 + xpos]; /* Adjust number of pixels to draw for sprite limit */ if (pixelcount > max_width) { width = width - pixelcount + max_width; } /* Number of tiles to draw */ width = width >> 3; /* Pattern row index */ v_line = (v_line & 7) << 3; /* Draw sprite patterns */ for(column = 0; column < width; column++, lb+=8) { temp = attr | ((name + s[column]) & 0x07FF); src = &bg_pattern_cache[(temp << 6) | (v_line)]; DRAW_SPRITE_TILE(8,atex,lut[1]) } } /* Sprite limit */ if (pixelcount >= max_width) { /* Sprite masking will be effective on next line */ spr_over = 1; /* Stop sprite rendering */ return; } } /* Clear sprite masking for next line */ spr_over = 0; } void render_obj_m5_ste(int max_width) { int i, count, column; int xpos, width; int pixelcount = 0; int masked = 0; uint8 *src, *s, *lb; uint32 temp, v_line; uint32 attr, name, atex; #ifndef ALT_RENDERER /* Merge background layers */ merge(&linebuf[1][0x20], &linebuf[0][0x20], &linebuf[0][0x20], lut[2], max_width); #endif /* Clear sprite line buffer */ memset(&linebuf[1][0], 0, max_width + 0x40); /* Draw sprites in front-to-back order */ for (count = 0; count < object_count; count++) { /* Sprite X position */ xpos = object_info[count].xpos; /* Sprite masking */ if (xpos) { /* Requires at least one sprite with xpos > 0 */ spr_over = 1; } else if (spr_over) { /* Remaining sprites are not drawn */ masked = 1; } /* Display area offset */ xpos = xpos - 0x80; /* Sprite size */ temp = object_info[count].size; /* Sprite width */ width = 8 + ((temp & 0x0C) << 1); /* Update pixel count (off-screen sprites are included) */ pixelcount += width; /* Is sprite across visible area ? */ if (((xpos + width) > 0) && (xpos < max_width) && !masked) { /* Sprite attributes */ attr = object_info[count].attr; /* Sprite vertical offset */ v_line = object_info[count].ypos; /* Sprite priority + palette bits */ atex = (attr >> 9) & 0x70; /* Pattern name base */ name = attr & 0x07FF; /* Mask vflip/hflip */ attr &= 0x1800; /* Pointer into pattern name offset look-up table */ s = &name_lut[((attr >> 3) & 0x300) | (temp << 4) | ((v_line & 0x18) >> 1)]; /* Pointer into line buffer */ lb = &linebuf[1][0x20 + xpos]; /* Adjust number of pixels to draw for sprite limit */ if (pixelcount > max_width) { width = width - pixelcount + max_width; } /* Number of tiles to draw */ width = width >> 3; /* Pattern row index */ v_line = (v_line & 7) << 3; /* Draw sprite patterns */ for(column = 0; column < width; column++, lb+=8) { temp = attr | ((name + s[column]) & 0x07FF); src = &bg_pattern_cache[(temp << 6) | (v_line)]; DRAW_SPRITE_TILE(8,atex,lut[3]) } } /* Sprite limit */ if (pixelcount >= max_width) { /* Sprite masking will be effective on next line */ spr_over = 1; /* Merge background & sprite layers */ merge(&linebuf[1][0x20],&linebuf[0][0x20],&linebuf[0][0x20],lut[4], max_width); /* Stop sprite rendering */ return; } } /* Clear sprite masking for next line */ spr_over = 0; /* Merge background & sprite layers */ merge(&linebuf[1][0x20],&linebuf[0][0x20],&linebuf[0][0x20],lut[4], max_width); } void render_obj_m5_im2(int max_width) { int i, count, column; int xpos, width; int pixelcount = 0; int masked = 0; int odd = odd_frame; uint8 *src, *s, *lb; uint32 temp, v_line; uint32 attr, name, atex; #ifndef ALT_RENDERER /* Merge background layers */ merge(&linebuf[1][0x20], &linebuf[0][0x20], &linebuf[0][0x20], lut[0], max_width); #endif /* Draw sprites in front-to-back order */ for (count = 0; count < object_count; count++) { /* Sprite X position */ xpos = object_info[count].xpos; /* Sprite masking */ if (xpos) { /* Requires at least one sprite with xpos > 0 */ spr_over = 1; } else if (spr_over) { /* Remaining sprites are not drawn */ masked = 1; } /* Display area offset */ xpos = xpos - 0x80; /* Sprite size */ temp = object_info[count].size; /* Sprite width */ width = 8 + ((temp & 0x0C) << 1); /* Update pixel count (off-screen sprites are included) */ pixelcount += width; /* Is sprite across visible area ? */ if (((xpos + width) > 0) && (xpos < max_width) && !masked) { /* Sprite attributes */ attr = object_info[count].attr; /* Sprite y offset */ v_line = object_info[count].ypos; /* Sprite priority + palette bits */ atex = (attr >> 9) & 0x70; /* Pattern name base */ name = attr & 0x03FF; /* Mask vflip/hflip */ attr &= 0x1800; /* Pattern name offset lookup table */ s = &name_lut[((attr >> 3) & 0x300) | (temp << 4) | ((v_line & 0x18) >> 1)]; /* Pointer into line buffer */ lb = &linebuf[0][0x20 + xpos]; /* Adjust width for sprite limit */ if (pixelcount > max_width) { width = width - pixelcount + max_width; } /* Number of tiles to draw */ width = width >> 3; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; /* Render sprite patterns */ for(column = 0; column < width; column ++, lb+=8) { temp = attr | (((name + s[column]) & 0x3ff) << 1); src = &bg_pattern_cache[((temp << 6) | (v_line)) ^ ((attr & 0x1000) >> 6)]; DRAW_SPRITE_TILE(8,atex,lut[1]) } } /* Sprite Limit */ if (pixelcount >= max_width) { /* Enable sprite masking for next line */ spr_over = 1; /* Stop sprite rendering */ return; } } /* Clear sprite masking for next line */ spr_over = 0; } void render_obj_m5_im2_ste(int max_width) { int i, count, column; int xpos, width; int pixelcount = 0; int masked = 0; int odd = odd_frame; uint8 *src, *s, *lb; uint32 temp, v_line; uint32 attr, name, atex; #ifndef ALT_RENDERER /* Merge background layers */ merge(&linebuf[1][0x20], &linebuf[0][0x20], &linebuf[0][0x20], lut[2], max_width); #endif /* Clear sprite line buffer */ memset(&linebuf[1][0], 0, max_width + 0x40); /* Draw sprites in front-to-back order */ for (count = 0; count < object_count; count++) { /* Sprite X position */ xpos = object_info[count].xpos; /* Sprite masking */ if (xpos) { /* Requires at least one sprite with xpos > 0 */ spr_over = 1; } else if (spr_over) { /* Remaining sprites are not drawn */ masked = 1; } /* Display area offset */ xpos = xpos - 0x80; /* Sprite size */ temp = object_info[count].size; /* Sprite width */ width = 8 + ((temp & 0x0C) << 1); /* Update pixel count (off-screen sprites are included) */ pixelcount += width; /* Is sprite across visible area ? */ if (((xpos + width) > 0) && (xpos < max_width) && !masked) { /* Sprite attributes */ attr = object_info[count].attr; /* Sprite y offset */ v_line = object_info[count].ypos; /* Sprite priority + palette bits */ atex = (attr >> 9) & 0x70; /* Pattern name base */ name = attr & 0x03FF; /* Mask vflip/hflip */ attr &= 0x1800; /* Pattern name offset lookup table */ s = &name_lut[((attr >> 3) & 0x300) | (temp << 4) | ((v_line & 0x18) >> 1)]; /* Pointer into line buffer */ lb = &linebuf[1][0x20 + xpos]; /* Adjust width for sprite limit */ if (pixelcount > max_width) { width = width - pixelcount + max_width; } /* Number of tiles to draw */ width = width >> 3; /* Pattern row index */ v_line = (((v_line & 7) << 1) | odd) << 3; /* Render sprite patterns */ for(column = 0; column < width; column ++, lb+=8) { temp = attr | (((name + s[column]) & 0x3ff) << 1); src = &bg_pattern_cache[((temp << 6) | (v_line)) ^ ((attr & 0x1000) >> 6)]; DRAW_SPRITE_TILE(8,atex,lut[3]) } } /* Sprite Limit */ if (pixelcount >= max_width) { /* Enable sprite masking for next line */ spr_over = 1; /* Merge background & sprite layers */ merge(&linebuf[1][0x20],&linebuf[0][0x20],&linebuf[0][0x20],lut[4], max_width); /* Stop sprite rendering */ return; } } /* Clear sprite masking for next line */ spr_over = 0; /* Merge background & sprite layers */ merge(&linebuf[1][0x20],&linebuf[0][0x20],&linebuf[0][0x20],lut[4], max_width); } /*--------------------------------------------------------------------------*/ /* Sprites Parsing functions */ /*--------------------------------------------------------------------------*/ void parse_satb_m4(int line) { int i; /* Pointer to sprite attribute table */ uint8 *st = &vram[(reg[5] << 7) & 0x3F00]; /* Sprite counter (64 max.) */ int count = 0; /* Y position */ int ypos; /* Sprite height (8x8 by default) */ int height = 8; /* Adjust height for 8x16 sprites */ height <<= ((reg[1] & 0x02) >> 1); /* Parse Sprite Table (64 entries) */ for(i = 0; i < 64; i++) { /* Sprite Y position */ ypos = st[i]; /* Found end of sprite list marker for non-extended modes? */ if(ypos == 208) { break; } /* Wrap Y coordinate for sprites > 240 */ if(ypos > 240) { ypos -= 256; } /* Y range */ ypos = line - ypos; /* Sprite is visble on this line ? */ if((ypos >= 0) && (ypos < height)) { /* Sprite overflow */ if(count == 8) { spr_over = 0x40; break; } /* Store sprite attributes for later processing */ object_info[count].ypos = ypos; object_info[count].xpos = st[0x80 + (i << 1)]; object_info[count].attr = st[0x81 + (i << 1)]; /* Increment Sprite count */ ++count; } } /* Update sprite count for next line */ object_count = count; } void parse_satb_m5(int line) { /* Y position */ int ypos; /* Sprite height (8,16,24,32 pixels)*/ int height; /* Sprite size data */ int size; /* Sprite link data */ int link = 0; /* Sprite counter */ int count = 0; /* 16 or 20 sprites max. per line */ int max = 16 + ((reg[12] & 1) << 2); /* 64 or 80 sprites max. */ int total = max << 2; /* Pointer to sprite attribute table */ uint16 *p = (uint16 *) &vram[satb]; /* Pointer to internal RAM */ uint16 *q = (uint16 *) &sat[0]; /* Adjust line offset */ line += 0x81; do { /* Read Y position & size from internal SAT */ ypos = (q[link] >> im2_flag) & 0x1FF; size = q[link + 1] >> 8; /* Sprite height */ height = 8 + ((size & 3) << 3); /* Y range */ ypos = line - ypos; /* Sprite is visble on this line ? */ if ((ypos >= 0) && (ypos < height)) { /* Sprite overflow */ if(count == max) { status |= 0x40; break; } /* Update sprite list */ /* name, attribute & xpos are parsed from VRAM */ object_info[count].attr = p[link + 2]; object_info[count].xpos = p[link + 3] & 0x1ff; object_info[count].ypos = ypos; object_info[count].size = size & 0x0f; ++count; } /* Read link data from internal SAT */ link = (q[link + 1] & 0x7F) << 2; /* Last sprite */ if(link == 0) break; } while (--total); /* Update sprite count for next line */ object_count = count; } /*--------------------------------------------------------------------------*/ /* Pattern cache update function */ /*--------------------------------------------------------------------------*/ void update_bg_pattern_cache_m4(int index) { int i; uint8 x, y, c; uint8 *dst; uint16 name, bp01, bp23; uint32 bp; for(i = 0; i < index; i++) { /* Get modified pattern name index */ name = bg_name_list[i]; /* Check modified lines */ for(y = 0; y < 8; y++) { if(bg_name_dirty[name] & (1 << y)) { /* Pattern cache base address */ dst = &bg_pattern_cache[name << 6]; /* Byteplane data */ bp01 = *(uint16 *)&vram[(name << 5) | (y << 2) | (0)]; bp23 = *(uint16 *)&vram[(name << 5) | (y << 2) | (2)]; /* Convert to pixel line data (4 bytes = 8 pixels)*/ /* (msb) p7p6 p5p4 p3p2 p1p0 (lsb) */ bp = (bp_lut[bp01] >> 2) | (bp_lut[bp23]); /* Update cached line (8 pixels = 8 bytes) */ for(x = 0; x < 8; x++) { /* Extract pixel data */ c = bp & 0x0F; /* Pattern cache data (one pattern = 8 bytes) */ /* byte0 <-> p0 p1 p2 p3 p4 p5 p6 p7 <-> byte7 (hflip = 0) */ /* byte0 <-> p7 p6 p5 p4 p3 p2 p1 p0 <-> byte7 (hflip = 1) */ dst[0x00000 | (y << 3) | (x)] = (c); /* vflip=0 & hflip=0 */ dst[0x08000 | (y << 3) | (x ^ 7)] = (c); /* vflip=0 & hflip=1 */ dst[0x10000 | ((y ^ 7) << 3) | (x)] = (c); /* vflip=1 & hflip=0 */ dst[0x18000 | ((y ^ 7) << 3) | (x ^ 7)] = (c); /* vflip=1 & hflip=1 */ /* Next pixel */ bp = bp >> 4; } } } /* Clear modified pattern flag */ bg_name_dirty[name] = 0; } } void update_bg_pattern_cache_m5(int index) { int i; uint8 x, y, c; uint8 *dst; uint16 name; uint32 bp; for(i = 0; i < index; i++) { /* Get modified pattern name index */ name = bg_name_list[i]; /* Check modified lines */ for(y = 0; y < 8; y ++) { if(bg_name_dirty[name] & (1 << y)) { /* Pattern cache base address */ dst = &bg_pattern_cache[name << 6]; /* Byteplane data (one pattern = 4 bytes) */ /* LIT_ENDIAN: byte0 (lsb) p2p3 p0p1 p6p7 p4p5 (msb) byte3 */ /* BIG_ENDIAN: byte0 (msb) p0p1 p2p3 p4p5 p6p7 (lsb) byte3 */ bp = *(uint32 *)&vram[(name << 5) | (y << 2)]; /* Update cached line (8 pixels = 8 bytes) */ for(x = 0; x < 8; x ++) { /* Extract pixel data */ c = bp & 0x0F; /* Pattern cache data (one pattern = 8 bytes) */ /* byte0 <-> p0 p1 p2 p3 p4 p5 p6 p7 <-> byte7 (hflip = 0) */ /* byte0 <-> p7 p6 p5 p4 p3 p2 p1 p0 <-> byte7 (hflip = 1) */ #ifdef LSB_FIRST /* Byteplane data = (msb) p4p5 p6p7 p0p1 p2p3 (lsb) */ dst[0x00000 | (y << 3) | (x ^ 3)] = (c); /* vflip=0, hflip=0 */ dst[0x20000 | (y << 3) | (x ^ 4)] = (c); /* vflip=0, hflip=1 */ dst[0x40000 | ((y ^ 7) << 3) | (x ^ 3)] = (c); /* vflip=1, hflip=0 */ dst[0x60000 | ((y ^ 7) << 3) | (x ^ 4)] = (c); /* vflip=1, hflip=1 */ #else /* Byteplane data = (msb) p0p1 p2p3 p4p5 p6p7 (lsb) */ dst[0x00000 | (y << 3) | (x ^ 7)] = (c); /* vflip=0, hflip=0 */ dst[0x20000 | (y << 3) | (x)] = (c); /* vflip=0, hflip=1 */ dst[0x40000 | ((y ^ 7) << 3) | (x ^ 7)] = (c); /* vflip=1, hflip=0 */ dst[0x60000 | ((y ^ 7) << 3) | (x)] = (c); /* vflip=1, hflip=1 */ #endif /* Next pixel */ bp = bp >> 4; } } } /* Clear modified pattern flag */ bg_name_dirty[name] = 0; } } /*--------------------------------------------------------------------------*/ /* Window & Plane A clipping update function */ /*--------------------------------------------------------------------------*/ void window_clip(unsigned int data, unsigned int sw) { /* Window size and invert flags */ int hp = (data & 0x1f); int hf = (data >> 7) & 1; /* Display width (16 or 20 columns) */ sw = 16 + (sw << 2); /* Perform horizontal clipping; the results are applied in reverse if the horizontal inversion flag is set */ int a = hf; int w = hf ^ 1; if(hp) { if(hp > sw) { /* Plane W takes up entire line */ clip[w].left = 0; clip[w].right = sw; clip[w].enable = 1; clip[a].enable = 0; } else { /* Plane W takes left side, Plane A takes right side */ clip[w].left = 0; clip[a].right = sw; clip[a].left = clip[w].right = hp; clip[0].enable = clip[1].enable = 1; } } else { /* Plane A takes up entire line */ clip[a].left = 0; clip[a].right = sw; clip[a].enable = 1; clip[w].enable = 0; } } /*--------------------------------------------------------------------------*/ /* Init, reset routines */ /*--------------------------------------------------------------------------*/ void render_init(void) { int bx, ax; /* Initialize layers priority pixel look-up tables */ uint16 index; for (bx = 0; bx < 0x100; bx++) { for (ax = 0; ax < 0x100; ax++) { index = (bx << 8) | (ax); lut[0][index] = make_lut_bg (bx, ax); lut[1][index] = make_lut_bgobj (bx, ax); lut[2][index] = make_lut_bg_ste (bx, ax); lut[3][index] = make_lut_obj (bx, ax); lut[4][index] = make_lut_bgobj_ste (bx, ax); lut[5][index] = make_lut_bgobj_m4 (bx,ax); } } /* Initialize pixel color look-up tables */ palette_init(); #ifndef NGC /* Set default color palette update function */ switch(bitmap.depth) { case 8: color_update = color_update_8; break; case 15: color_update = color_update_15; break; case 16: color_update = color_update_16; break; case 32: color_update = color_update_32; break; } #endif /* Make sprite pattern name index look-up table */ make_name_lut(); /* Make bitplane to pixel look-up table (Mode 4) */ make_bp_lut(); } void render_reset(void) { /* Clear display bitmap */ memset(bitmap.data, 0, bitmap.pitch * bitmap.height); /* Clear line buffers */ memset(linebuf, 0, sizeof(linebuf)); /* Clear color palettes */ #ifdef NGC memset(&pixel, 0, sizeof(pixel)); #else memset(&pixel_8, 0, sizeof(pixel_8)); memset(&pixel_15, 0, sizeof(pixel_15)); memset(&pixel_16, 0, sizeof(pixel_16)); memset(&pixel_32, 0, sizeof(pixel_32)); #endif } /*--------------------------------------------------------------------------*/ /* Line rendering functions */ /*--------------------------------------------------------------------------*/ void render_line(int line) { int width = bitmap.viewport.w; int x_offset = bitmap.viewport.x; /* Check display status */ if (reg[1] & 0x40) { /* Update pattern cache */ if (bg_list_index) { update_bg_pattern_cache(bg_list_index); bg_list_index = 0; } /* Render BG layer(s) */ render_bg(line, width); /* Render sprite layer */ render_obj(width); /* Left-most column blanking */ if(reg[0] & 0x20) { memset(&linebuf[0][0x20], 0x40, 8); } /* Horizontal borders */ if (x_offset) { memset(&linebuf[0][0x20 - x_offset], 0x40, x_offset); memset(&linebuf[0][0x20 + width], 0x40, x_offset); } /* Parse sprites for next line */ if (line < (bitmap.viewport.h - 1)) { parse_satb(line); } } else { /* Display disabled */ memset(&linebuf[0][0x20 - x_offset], 0x40, width + (x_offset << 1)); } /* Pixel color remapping */ remap_line(line); } void blank_line(int line, int offset, int width) { memset(&linebuf[0][0x20 + offset], 0x40, width); remap_line(line); } #include "common.h" void remap_line(int line) { /* Line width */ int x_offset = bitmap.viewport.x; int width = bitmap.viewport.w + (x_offset << 1); /* Adjust line offset in framebuffer */ line = (line + bitmap.viewport.y) % lines_per_frame; /* Adjust for interlaced output */ if (interlaced && config.render) { line = (line << 1) + odd_frame; } #ifdef NGC /* NTSC Filter */ if (config.ntsc) { if (reg[12]&1) { md_ntsc_blit(md_ntsc, ( MD_NTSC_IN_T const * )pixel, &linebuf[0][0x20 - x_offset], width, line); } else { sms_ntsc_blit(sms_ntsc, ( SMS_NTSC_IN_T const * )pixel, &linebuf[0][0x20 - x_offset], width, line); } } else { /* Directly fill a RGB565 texture */ /* One tile is 32 byte = 4x4 pixels */ /* Tiles are stored continuously in texture memory */ width >>= 2; uint8 *src = &linebuf[0][0x20 - x_offset]; uint16 *dst = (uint16 *) (texturemem + (((width << 5) * (line >> 2)) + ((line & 3) << 3))); do { *dst++ = pixel[*src++]; *dst++ = pixel[*src++]; *dst++ = pixel[*src++]; *dst++ = pixel[*src++]; /* next tile */ dst += 12; } while (--width); } #else void *out =((void *)&bitmap.data[(line * bitmap.pitch)]); switch(bitmap.depth) { case 8: remap_8(&linebuf[0][0x20 - x_offset], (uint8 *)out, width); break; case 15: remap_16(&linebuf[0][0x20 - x_offset], (uint16 *)out, width); break; case 16: remap_16(&linebuf[0][0x20 - x_offset], (uint16 *)out, width); break; case 32: remap_32(&linebuf[0][0x20 - x_offset], (uint32 *)out, width); break; } #endif }
zyking1987-genplus-droid
genplusgx/vdp_render.c
C
gpl2
96,031
#ifndef _MACROS_H_ #define _MACROS_H_ #ifdef LSB_FIRST #define READ_BYTE(BASE, ADDR) (BASE)[(ADDR)^1] #define READ_WORD(BASE, ADDR) (((BASE)[ADDR]<<8) | (BASE)[(ADDR)+1]) #define READ_WORD_LONG(BASE, ADDR) (((BASE)[(ADDR)+1]<<24) | \ ((BASE)[(ADDR)]<<16) | \ ((BASE)[(ADDR)+3]<<8) | \ (BASE)[(ADDR)+2]) #define WRITE_BYTE(BASE, ADDR, VAL) (BASE)[(ADDR)^1] = (VAL)&0xff #define WRITE_WORD(BASE, ADDR, VAL) (BASE)[ADDR] = ((VAL)>>8) & 0xff; \ (BASE)[(ADDR)+1] = (VAL)&0xff #define WRITE_WORD_LONG(BASE, ADDR, VAL) (BASE)[(ADDR+1)] = ((VAL)>>24) & 0xff; \ (BASE)[(ADDR)] = ((VAL)>>16)&0xff; \ (BASE)[(ADDR+3)] = ((VAL)>>8)&0xff; \ (BASE)[(ADDR+2)] = (VAL)&0xff #else #define READ_BYTE(BASE, ADDR) (BASE)[ADDR] #define READ_WORD(BASE, ADDR) *(uint16 *)((BASE) + (ADDR)) #define READ_WORD_LONG(BASE, ADDR) *(uint32 *)((BASE) + (ADDR)) #define WRITE_BYTE(BASE, ADDR, VAL) (BASE)[ADDR] = VAL & 0xff #define WRITE_WORD(BASE, ADDR, VAL) *(uint16 *)((BASE) + (ADDR)) = VAL & 0xffff #define WRITE_WORD_LONG(BASE, ADDR, VAL) *(uint32 *)((BASE) + (ADDR)) = VAL & 0xffffffff #endif #endif /* _MACROS_H_ */
zyking1987-genplus-droid
genplusgx/macros.h
C
gpl2
1,425
/*************************************************************************************** * Genesis Plus * Video Display Processor (68k & Z80 CPU interface) * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007-2011), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "shared.h" #include "hvc.h" /* Mark a pattern as dirty */ #define MARK_BG_DIRTY(addr) \ { \ name = (addr >> 5) & 0x7FF; \ if(bg_name_dirty[name] == 0) \ { \ bg_name_list[bg_list_index++] = name; \ } \ bg_name_dirty[name] |= (1 << ((addr >> 2) & 7)); \ } /* VDP context */ uint8 sat[0x400]; /* Internal copy of sprite attribute table */ uint8 vram[0x10000]; /* Video RAM (64K x 8-bit) */ uint8 cram[0x80]; /* On-chip color RAM (64 x 9-bit) */ uint8 vsram[0x80]; /* On-chip vertical scroll RAM (40 x 11-bit) */ uint8 reg[0x20]; /* Internal VDP registers (23 x 8-bit) */ uint8 hint_pending; /* 0= Line interrupt is pending */ uint8 vint_pending; /* 1= Frame interrupt is pending */ uint8 m68k_irq_state; /* 68K IRQ status */ uint16 status; /* VDP status flags */ uint32 dma_length; /* DMA remaining length */ /* Global variables */ uint16 ntab; /* Name table A base address */ uint16 ntbb; /* Name table B base address */ uint16 ntwb; /* Name table W base address */ uint16 satb; /* Sprite attribute table base address */ uint16 hscb; /* Horizontal scroll table base address */ uint8 bg_name_dirty[0x800]; /* 1= This pattern is dirty */ uint16 bg_name_list[0x800]; /* List of modified pattern indices */ uint16 bg_list_index; /* # of modified patterns in list */ uint8 bg_pattern_cache[0x80000]; /* Cached and flipped patterns */ uint8 hscroll_mask; /* Horizontal Scrolling line mask */ uint8 playfield_shift; /* Width of planes A, B (in bits) */ uint8 playfield_col_mask; /* Playfield column mask */ uint16 playfield_row_mask; /* Playfield row mask */ uint16 hscroll; /* Latched horizontal scroll value */ uint16 vscroll; /* Latched vertical scroll value */ uint8 odd_frame; /* 1: odd field, 0: even field */ uint8 im2_flag; /* 1= Interlace mode 2 is being used */ uint8 interlaced; /* 1: Interlaced mode 1 or 2 */ uint8 vdp_pal; /* 1: PAL , 0: NTSC (default) */ uint16 v_counter; /* Vertical counter */ uint16 vc_max; /* Vertical counter overflow value */ uint16 lines_per_frame; /* PAL: 313 lines, NTSC: 262 lines */ int32 fifo_write_cnt; /* VDP writes fifo count */ uint32 fifo_lastwrite; /* last VDP write cycle */ uint32 hvc_latch; /* latched HV counter */ const uint8 *hctab; /* pointer to H Counter table */ /* Function pointers */ void (*vdp_68k_data_w)(unsigned int data); void (*vdp_z80_data_w)(unsigned int data); unsigned int (*vdp_68k_data_r)(void); unsigned int (*vdp_z80_data_r)(void); /* Tables that define the playfield layout */ static const uint8 hscroll_mask_table[] = { 0x00, 0x07, 0xF8, 0xFF }; static const uint8 shift_table[] = { 6, 7, 0, 8 }; static const uint8 col_mask_table[] = { 0x0F, 0x1F, 0x0F, 0x3F }; static const uint16 row_mask_table[] = { 0x0FF, 0x1FF, 0x2FF, 0x3FF }; static uint8 border; /* Border color index */ static uint8 pending; /* Pending write flag */ static uint8 code; /* Code register */ static uint8 dma_type; /* DMA mode */ static uint16 dmafill; /* DMA Fill setup */ static uint16 addr; /* Address register */ static uint16 addr_latch; /* Latched A15, A14 of address */ static uint16 sat_base_mask; /* Base bits of SAT */ static uint16 sat_addr_mask; /* Index bits of SAT */ static uint32 dma_endCycles; /* 68k cycles to DMA end */ static uint32 fifo_latency; /* CPU access latency */ static int cached_write; /* 2nd part of 32-bit CTRL port write */ static uint16 fifo[4]; /* FIFO buffer */ static uint8 *irq_line; /* Z80 or 68k interrupt lines */ /* DMA Timings */ static const uint8 dma_timing[2][2] = { /* H32, H40 */ {16 , 18}, /* active display */ {167, 205} /* blank display */ }; /* Vertical counter overflow values (see hvc.h) */ static const uint16 vc_table[4][2] = { /* NTSC, PAL */ {0xDA , 0xF2}, /* Mode 4 (192 lines) */ {0xEA , 0x102}, /* Mode 5 (224 lines) */ {0xDA , 0xF2}, /* Mode 4 (192 lines) */ {0x106, 0x10A} /* Mode 5 (240 lines) */ }; /*--------------------------------------------------------------------------*/ /* Function prototypes */ /*--------------------------------------------------------------------------*/ static void vdp_68k_data_w_m4(unsigned int data); static void vdp_68k_data_w_m5(unsigned int data); static unsigned int vdp_68k_data_r_m4(void); static unsigned int vdp_68k_data_r_m5(void); static void vdp_z80_data_w_m4(unsigned int data); static void vdp_z80_data_w_m5(unsigned int data); static unsigned int vdp_z80_data_r_m4(void); static unsigned int vdp_z80_data_r_m5(void); static void vdp_bus_w(unsigned int data); static void vdp_fifo_update(unsigned int cycles); static void vdp_reg_w(unsigned int r, unsigned int d, unsigned int cycles); static void vdp_dma_copy(int length); static void vdp_dma_vbus(int length); static void vdp_dma_fill(unsigned int data, int length); /*--------------------------------------------------------------------------*/ /* Init, reset, context functions */ /*--------------------------------------------------------------------------*/ void vdp_init(void) { /* PAL/NTSC timings */ lines_per_frame = vdp_pal ? 313: 262; status = (status & ~1) | vdp_pal; /* CPU interrupt line(s)*/ irq_line = (system_hw == SYSTEM_PBC) ? &Z80.irq_state : &m68k_irq_state; } void vdp_reset(void) { memset ((char *) sat, 0, sizeof (sat)); memset ((char *) vram, 0, sizeof (vram)); memset ((char *) cram, 0, sizeof (cram)); memset ((char *) vsram, 0, sizeof (vsram)); memset ((char *) reg, 0, sizeof (reg)); addr = 0; addr_latch = 0; code = 0; pending = 0; hint_pending = 0; vint_pending = 0; m68k_irq_state = 0; dmafill = 0; dma_type = 0; dma_length = 0; dma_endCycles = 0; odd_frame = 0; im2_flag = 0; interlaced = 0; fifo_write_cnt = 0; fifo_lastwrite = 0; cached_write = -1; ntab = 0; ntbb = 0; ntwb = 0; satb = 0; hscb = 0; hscroll = 0; vscroll = 0; hscroll_mask = 0x00; playfield_shift = 6; playfield_col_mask = 0x0F; playfield_row_mask = 0x0FF; sat_base_mask = 0xFE00; sat_addr_mask = 0x01FF; /* clear pattern cache */ bg_list_index = 0; memset ((char *) bg_name_dirty, 0, sizeof (bg_name_dirty)); memset ((char *) bg_name_list, 0, sizeof (bg_name_list)); memset ((char *) bg_pattern_cache, 0, sizeof (bg_pattern_cache)); /* default HVC */ hvc_latch = 0x10000; hctab = cycle2hc32; vc_max = vc_table[0][vdp_pal]; v_counter = lines_per_frame - 1; /* default Window clipping */ window_clip(0,0); /* default FIFO timings */ fifo_latency = 214; /* reset VDP status (FIFO empty flag is set) */ status = vdp_pal | 0x200; /* default display area */ bitmap.viewport.w = 256; bitmap.viewport.h = 192; bitmap.viewport.ow = 256; bitmap.viewport.oh = 192; /* default overscan area */ bitmap.viewport.x = (config.overscan & 2) * 7; bitmap.viewport.y = (config.overscan & 1) * 24 * (vdp_pal + 1); /* default rendering mode */ render_bg = render_bg_m4; render_obj = render_obj_m4; parse_satb = parse_satb_m4; update_bg_pattern_cache = update_bg_pattern_cache_m4; /* default bus access mode */ vdp_68k_data_w = vdp_68k_data_w_m4; vdp_z80_data_w = vdp_z80_data_w_m4; vdp_68k_data_r = vdp_68k_data_r_m4; vdp_z80_data_r = vdp_z80_data_r_m4; /* initialize some registers if OS ROM is simulated */ if (config.tmss == 1) { vdp_reg_w(0 , 0x04, 0); /* Palette bit set */ vdp_reg_w(1 , 0x04, 0); /* Mode 5 enabled */ vdp_reg_w(10, 0xff, 0); /* HINT disabled */ vdp_reg_w(12, 0x81, 0); /* H40 mode */ vdp_reg_w(15, 0x02, 0); /* auto increment */ } } int vdp_context_save(uint8 *state) { int bufferptr = 0; save_param(sat, sizeof(sat)); save_param(vram, sizeof(vram)); save_param(cram, sizeof(cram)); save_param(vsram, sizeof(vsram)); save_param(reg, sizeof(reg)); save_param(&addr, sizeof(addr)); save_param(&addr_latch, sizeof(addr_latch)); save_param(&code, sizeof(code)); save_param(&pending, sizeof(pending)); save_param(&status, sizeof(status)); save_param(&dmafill, sizeof(dmafill)); save_param(&hint_pending, sizeof(hint_pending)); save_param(&vint_pending, sizeof(vint_pending)); save_param(&m68k_irq_state, sizeof(m68k_irq_state)); save_param(&dma_length, sizeof(dma_length)); save_param(&dma_type, sizeof(dma_type)); save_param(&cached_write, sizeof(cached_write)); return bufferptr; } int vdp_context_load(uint8 *state, char *version) { int i, bufferptr = 0; uint8 temp_reg[0x20]; load_param(sat, sizeof(sat)); load_param(vram, sizeof(vram)); load_param(cram, sizeof(cram)); load_param(vsram, sizeof(vsram)); load_param(temp_reg, sizeof(temp_reg)); load_param(&addr, sizeof(addr)); load_param(&addr_latch, sizeof(addr_latch)); load_param(&code, sizeof(code)); load_param(&pending, sizeof(pending)); load_param(&status, sizeof(status)); /* different size parameter starting from 1.5.0 */ if ((version[11] > 0x31) || (version[13] > 0x34)) { load_param(&dmafill, sizeof(dmafill)); } else { load_param(&dmafill, sizeof(uint8)); } load_param(&hint_pending, sizeof(hint_pending)); load_param(&vint_pending, sizeof(vint_pending)); load_param(&m68k_irq_state, sizeof(m68k_irq_state)); /* extended state (1.4.1 and above) */ if ((version[11] > 0x31) || (version[13] > 0x34) || (version[15] > 0x30)) { load_param(&dma_length, sizeof(dma_length)); load_param(&dma_type, sizeof(dma_type)); if ((version[11] == 0x31) && (version[13] == 0x34) && (version[15] == 0x31)) /* 1.4.1 only */ { uint16 temp; load_param(&temp, sizeof(temp)); } load_param(&cached_write, sizeof(cached_write)); } /* restore VDP registers */ for (i=0;i<0x20;i++) { vdp_reg_w(i, temp_reg[i], 0); } /* restore FIFO timings */ fifo_latency = 214 - (reg[12] & 1) * 24; fifo_latency <<= ((code & 0x0F) == 0x01); /* restore current NTSC/PAL mode */ status = (status & ~1) | vdp_pal; if (reg[1] & 0x04) { /* Mode 5 */ bg_list_index = 0x800; /* reinitialize palette */ color_update(0, *(uint16 *)&cram[border << 1]); for(i = 1; i < 0x40; i++) { color_update(i, *(uint16 *)&cram[i << 1]); } } else { /* Mode 4 */ bg_list_index = 0x200; /* reinitialize palette */ color_update(0x40, *(uint16 *)&cram[(0x10 | (border & 0x0F)) << 1]); for(i = 0; i < 0x20; i ++) { color_update(i, *(uint16 *)&cram[i << 1]); } } /* invalidate cache */ for (i=0;i<bg_list_index;i++) { bg_name_list[i]=i; bg_name_dirty[i]=0xFF; } return bufferptr; } /*--------------------------------------------------------------------------*/ /* DMA update function */ /*--------------------------------------------------------------------------*/ void vdp_dma_update(unsigned int cycles) { int dma_cycles; /* DMA transfer rate (bytes per line) According to the manual, here's a table that describes the transfer rates of each of the three DMA types: DMA Mode Width Display Transfer Count ----------------------------------------------------- 68K > VDP 32-cell Active 16 Blanking 167 40-cell Active 18 Blanking 205 VRAM Fill 32-cell Active 15 Blanking 166 40-cell Active 17 Blanking 204 VRAM Copy 32-cell Active 8 Blanking 83 40-cell Active 9 Blanking 102 'Active' is the active display period, 'Blanking' is either the vertical blanking period or when the display is forcibly blanked via register #1. The above transfer counts are all in bytes, unless the destination is CRAM or VSRAM for a 68K > VDP transfer, in which case it is in words. */ unsigned int rate = dma_timing[(status & 8) || !(reg[1] & 0x40)][reg[12] & 1]; /* Adjust for 68k bus DMA to VRAM (one word = 2 access) or DMA Copy (one read + one write = 2 access) */ rate = rate >> (dma_type & 1); /* Remaining DMA cycles */ if (status & 8) { /* Process DMA until the end of VBLANK (speed optimization) */ /* Note: This is not 100% accurate since rate could change if display width */ /* is changed during VBLANK but no games seem to do this. */ dma_cycles = (lines_per_frame * MCYCLES_PER_LINE) - cycles; } else { /* Process DMA until the end of current line */ dma_cycles = (mcycles_vdp + MCYCLES_PER_LINE) - cycles; } /* Remaining DMA bytes for that line */ int dma_bytes = (dma_cycles * rate) / MCYCLES_PER_LINE; #ifdef LOGVDP error("[%d(%d)][%d(%d)] DMA type %d (%d access/line)(%d cycles left)-> %d access (%d remaining) (%x)\n", v_counter, mcycles_68k/MCYCLES_PER_LINE, mcycles_68k, mcycles_68k%MCYCLES_PER_LINE,dma_type/4, rate, dma_cycles, dma_bytes, dma_length, m68k_get_reg (NULL, M68K_REG_PC)); #endif /* Check if DMA can be finished before the end of current line */ if (dma_length < dma_bytes) { /* Adjust remaining DMA bytes */ dma_bytes = dma_length; dma_cycles = (dma_bytes * MCYCLES_PER_LINE) / rate; } /* Update DMA timings */ if (dma_type < 2) { /* 68K is frozen during DMA from V-Bus */ mcycles_68k = cycles + dma_cycles; #ifdef LOGVDP error("-->CPU frozen for %d cycles\n", dma_cycles); #endif } else { /* Set DMA Busy flag */ status |= 0x02; /* 68K is still running, set DMA end cycle */ dma_endCycles = cycles + dma_cycles; #ifdef LOGVDP error("-->DMA ends in %d cycles\n", dma_cycles); #endif } /* Process DMA */ if (dma_bytes > 0) { /* Update DMA length */ dma_length -= dma_bytes; /* Select DMA operation */ switch (dma_type) { case 0: case 1: { /* 68K bus to VRAM, CRAM or VSRAM */ vdp_dma_vbus(dma_bytes); break; } case 2: { /* VRAM Fill */ vdp_dma_fill(dmafill, dma_bytes); break; } case 3: { /* VRAM Copy */ vdp_dma_copy(dma_bytes); break; } } /* Check if DMA is finished */ if (!dma_length) { /* Reset DMA length registers */ reg[19] = reg[20] = 0; /* Perform cached write, if any */ if (cached_write >= 0) { vdp_68k_ctrl_w(cached_write); cached_write = -1; } } } } /*--------------------------------------------------------------------------*/ /* Control port access functions */ /*--------------------------------------------------------------------------*/ void vdp_68k_ctrl_w(unsigned int data) { if (pending == 0) { /* A single long word write instruction could have started DMA with the first word */ if (dma_length) { /* 68k is frozen during 68k bus DMA */ /* Second word should be written after DMA completion */ /* See Formula One & Kawasaki Superbike Challenge */ if (dma_type < 2) { /* Latch second control word for later */ cached_write = data; return; } } if ((data & 0xC000) == 0x8000) { /* VDP register write */ vdp_reg_w((data >> 8) & 0x1F, data & 0xFF, mcycles_68k); } else { /* Set pending flag (Mode 5 only) */ pending = reg[1] & 4; } /* Update address and code registers */ addr = addr_latch | (data & 0x3FFF); code = ((code & 0x3C) | ((data >> 14) & 0x03)); } else { /* Clear pending flag */ pending = 0; /* Save address bits A15 and A14 */ addr_latch = (data & 3) << 14; /* Update address and code registers */ addr = addr_latch | (addr & 0x3FFF); code = ((code & 0x03) | ((data >> 2) & 0x3C)); /* Detect DMA operation */ if ((code & 0x20) && (reg[1] & 0x10)) { switch (reg[23] >> 6) { case 2: { /* VRAM write operation only (Williams Greatest Hits after soft reset) */ if ((code & 0x0F) == 1) { /* VRAM fill will be triggered by next write to DATA port */ dmafill = 0x100; } break; } case 3: { /* VRAM read/write operation only */ if ((code & 0x1F) == 0x10) { /* DMA length */ dma_length = (reg[20] << 8) | reg[19]; /* Zero DMA length */ if (!dma_length) { dma_length = 0x10000; } /* VRAM copy */ dma_type = 3; vdp_dma_update(mcycles_68k); } break; } default: { /* DMA length */ dma_length = (reg[20] << 8) | reg[19]; /* Zero DMA length */ if (!dma_length) { dma_length = 0x10000; } /* SVP RAM transfer latency */ reg[21] -= (svp && !(reg[23] & 0x60)); /* 68k to VDP DMA */ dma_type = (code & 0x06) ? 0 : 1; vdp_dma_update(mcycles_68k); break; } } } } /* FIFO emulation (Chaos Engine/Soldier of Fortune, Double Clutch, Sol Deace) -------------------------------------------------------------------------- CPU access per line is limited during active display: H32: 16 access --> 3420/16 = ~214 Mcycles between access H40: 18 access --> 3420/18 = ~190 Mcycles between access This is an approximation, on real hardware, the delay between access is more likely 16 pixels (128 or 160 Mcycles) with no access allowed during HBLANK (~860 Mcycles), H40 mode being probably a little more restricted. Each VRAM access is byte wide, so one VRAM write (word) need twice cycles. */ fifo_latency = 214 - (reg[12] & 1) * 24; fifo_latency <<= ((code & 0x0F) == 0x01); } void vdp_z80_ctrl_w(unsigned int data) { switch (pending) { case 0: { /* Latch LSB */ addr_latch = data; /* Set LSB pending flag */ pending = 1; return; } case 1: { /* Update address and code registers */ addr = (addr & 0xC000) | ((data & 0x3F) << 8) | addr_latch ; code = ((code & 0x3C) | ((data >> 6) & 0x03)); if ((code & 0x03) == 0x02) { /* VDP register write */ vdp_reg_w(data & 0x1F, addr_latch, mcycles_z80 + Z80_CYCLE_OFFSET); /* Clear pending flag */ pending = 0; return; } /* Set Mode 5 pending flag */ pending = (reg[1] & 4) >> 1; if (!pending && !(code & 0x03)) { /* Process VRAM read */ fifo[0] = vram[addr & 0x3FFF]; /* Increment address register */ addr += (reg[15] + 1); } return; } case 2: { /* Latch LSB */ addr_latch = data; /* Set LSB pending flag */ pending = 3; return; } case 3: { /* Clear pending flag */ pending = 0; /* Update address and code registers */ addr = ((addr_latch & 3) << 14) | (addr & 0x3FFF); code = ((code & 0x03) | ((addr_latch >> 2) & 0x3C)); /* Detect DMA operation */ if ((code & 0x20) && (reg[1] & 0x10)) { switch (reg[23] >> 6) { case 2: { /* VRAM write operation only (Williams Greatest Hits after soft reset) */ if ((code & 0x0F) == 1) { /* VRAM fill will be triggered by next write to DATA port */ dmafill = 0x100; } break; } case 3: { /* VRAM read/write operation only */ if ((code & 0x1F) == 0x10) { /* DMA length */ dma_length = (reg[20] << 8) | reg[19]; /* Zero DMA length */ if (!dma_length) { dma_length = 0x10000; } /* VRAM copy */ dma_type = 3; vdp_dma_update(mcycles_z80); } break; } default: { /* DMA from V-Bus does not work when Z80 is in control */ break; } } } } return; } } unsigned int vdp_ctrl_r(unsigned int cycles) { /* * Status register * * Bits * 0 NTSC(0)/PAL(1) * 1 DMA Busy * 2 During HBlank * 3 During VBlank * 4 0:1 even:odd field (interlaced modes only) * 5 Sprite collision * 6 Too many sprites per line * 7 v interrupt occurred * 8 Write FIFO full * 9 Write FIFO empty * 10 - 15 Open Bus */ /* Update FIFO flags */ vdp_fifo_update(cycles); /* Update DMA Busy flag */ if ((status & 2) && !dma_length && (cycles >= dma_endCycles)) { status &= 0xFFFD; } /* Return VDP status */ unsigned int temp = status; /* Display OFF: VBLANK flag is set */ if (!(reg[1] & 0x40)) { temp |= 0x08; } /* HBLANK flag (Sonic 3 and Sonic 2 "VS Modes", Lemmings 2, Mega Turrican, V.R Troopers, Gouketsuji Ichizoku,...) */ /* NB: this is not 100% accurate and need to be verified on real hardware */ if ((cycles % MCYCLES_PER_LINE) < 588) { temp |= 0x04; } /* Clear pending flag */ pending = 0; /* Clear SPR/SCOL flags */ status &= 0xFF9F; /* Mode 4 specific */ if (!(reg[1] & 4)) { /* Cycle-accurate VINT flag (required by some Master System games) */ if ((v_counter == bitmap.viewport.h) && ((cycles / MCYCLES_PER_LINE) > (v_counter + 1))) { temp |= 0x80; } /* Clear HINT & VINT pending flags */ hint_pending = vint_pending = 0; *irq_line = 0x10; /* Clear VINT flag */ status &= ~0x80; } #ifdef LOGVDP error("[%d(%d)][%d(%d)] VDP status read -> 0x%x (0x%x) (%x)\n", v_counter, cycles/MCYCLES_PER_LINE, cycles, cycles%MCYCLES_PER_LINE, temp, status, m68k_get_reg (NULL, M68K_REG_PC)); #endif return (temp); } /*--------------------------------------------------------------------------*/ /* HV Counters */ /*--------------------------------------------------------------------------*/ unsigned int vdp_hvc_r(unsigned int cycles) { /* VCounter */ int vc = (cycles / MCYCLES_PER_LINE) - 1; /* Check counter overflow */ if (vc > vc_max) { vc -= lines_per_frame; } /* Check interlaced modes */ if (interlaced) { /* Interlace mode 2 (Sonic the Hedgehog 2, Combat Cars) */ vc <<= im2_flag; /* Replace bit 0 with bit 8 */ vc = (vc & ~1) | ((vc >> 8) & 1); } /* Returned value */ unsigned int temp = (vc & 0xff) << 8; /* Check if HVC is frozen */ if (!hvc_latch) { /* Cycle-accurate HCounter (Striker, Mickey Mania, Skitchin, Road Rash I,II,III, Sonic 3D Blast...) */ temp |= hctab[cycles % MCYCLES_PER_LINE]; } else { if (reg[1] & 4) { /* Mode5: both counters are frozen (Lightgun games, Sunset Riders) */ temp = hvc_latch & 0xffff; } else { /* Mode 4: VCounter runs normally, HCounter is frozen */ temp |= (hvc_latch & 0xff); } } #ifdef LOGVDP error("[%d(%d)][%d(%d)] HVC read -> 0x%x (%x)\n", v_counter, cycles/MCYCLES_PER_LINE, cycles, cycles%MCYCLES_PER_LINE, temp, m68k_get_reg (NULL, M68K_REG_PC)); #endif return (temp); } /*--------------------------------------------------------------------------*/ /* Test registers */ /*--------------------------------------------------------------------------*/ void vdp_test_w(unsigned int data) { #ifdef LOGERROR error("Unused VDP Write 0x%x (%08x)\n", data, m68k_get_reg (NULL, M68K_REG_PC)); #endif } /*--------------------------------------------------------------------------*/ /* 68k interrupt handler (TODO: check how interrupts are handled in Mode 4) */ /*--------------------------------------------------------------------------*/ int vdp_68k_irq_ack(int int_level) { #ifdef LOGVDP error("[%d(%d)][%d(%d)] INT Level %d ack (%x)\n", v_counter, mcycles_68k/MCYCLES_PER_LINE, mcycles_68k, mcycles_68k%MCYCLES_PER_LINE,int_level, m68k_get_reg (NULL, M68K_REG_PC)); #endif /* VINT has higher priority */ if ((m68k_irq_state & 6) == 6) { #ifdef LOGVDP error("---> VINT cleared\n"); #endif /* Clear VINT pending flag */ vint_pending = 0; status &= ~0x80; /* Update IRQ status */ if (hint_pending & reg[0]) { m68k_irq_state = 0x14; } else { m68k_irq_state = 0; m68k_set_irq(0); } } else { #ifdef LOGVDP error("---> HINT cleared\n"); #endif /* Clear HINT pending flag */ hint_pending = 0; /* Update IRQ status */ if (vint_pending & reg[1]) { m68k_irq_state = 0x16; } else { m68k_irq_state = 0; m68k_set_irq(0); } } return M68K_INT_ACK_AUTOVECTOR; } /*--------------------------------------------------------------------------*/ /* Internal registers access function */ /*--------------------------------------------------------------------------*/ static void vdp_reg_w(unsigned int r, unsigned int d, unsigned int cycles) { #ifdef LOGVDP error("[%d(%d)][%d(%d)] VDP register %d write -> 0x%x (%x)\n", v_counter, cycles/MCYCLES_PER_LINE, cycles, cycles%MCYCLES_PER_LINE, r, d, m68k_get_reg (NULL, M68K_REG_PC)); #endif /* VDP registers #11 to #23 cannot be updated in Mode 4 (Captain Planet & Avengers, Bass Master Classic Pro Edition) */ if (!(reg[1] & 4) && (r > 10)) { return; } switch(r) { case 0: /* CTRL #1 */ { /* Look for changed bits */ r = d ^ reg[0]; reg[0] = d; /* Line Interrupt */ if ((r & 0x10) && hint_pending) { /* Update IRQ status */ *irq_line = 0x30; if (vint_pending & reg[1]) { *irq_line |= 0x06; } else if (d & 0x10) { *irq_line |= 0x04; } } /* Palette selection */ if (r & 0x04) { /* Reset color palette */ int i; if (reg[1] & 0x04) { /* Mode 5 */ color_update(0x00, *(uint16 *)&cram[border << 1]); for (i = 1; i < 0x40; i++) { color_update (i, *(uint16 *)&cram[i << 1]); } } else { /* Mode 4 */ color_update(0x40, *(uint16 *)&cram[(0x10 | (border & 0x0F)) << 1]); for (i = 0; i < 0x20; i++) { color_update (i, *(uint16 *)&cram[i << 1]); } } } /* HVC latch (Sunset Riders, Lightgun games) */ if (r & 0x02) { /* Mode 5 only */ if (reg[1] & 0x04) { if (d & 0x02) { /* Latch current HVC */ hvc_latch = vdp_hvc_r(cycles) | 0x10000; } else { /* Free-running HVC */ hvc_latch = 0; } } } break; } case 1: /* CTRL #2 */ { /* Look for changed bits */ r = d ^ reg[1]; reg[1] = d; /* Display status (modified during active display) */ if ((r & 0x40) && (v_counter < bitmap.viewport.h)) { /* Cycle offset vs HBLANK */ int offset = cycles - mcycles_vdp - 860; if (offset <= 0) { /* If display was disabled during HBLANK (Mickey Mania 3D level), sprite rendering is limited */ if ((d & 0x40) && (object_count > 5) && (offset >= -500)) { object_count = 5; } /* Redraw entire line (Legend of Galahad, Lemmings 2, Formula One, Kawasaki Super Bike, Deadly Moves,...) */ render_line(v_counter); #ifdef LOGVDP error("Line redrawn (%d sprites) \n",object_count); #endif } else { /* Active pixel offset */ if (reg[12] & 1) { /* dot clock = MCLK / 8 */ offset = (offset / 8); } else { /* dot clock = MCLK / 10 */ offset = (offset / 10) + 16; } /* Line is partially blanked (Nigel Mansell's World Championship Racing , Ren & Stimpy Show, ...) */ if (offset < bitmap.viewport.w) { #ifdef LOGVDP error("Line %d redrawn from pixel %d\n",v_counter,offset); #endif if (d & 0x40) { render_line(v_counter); blank_line(v_counter, 0, offset); } else { blank_line(v_counter, offset, bitmap.viewport.w - offset); } } } } /* Frame Interrupt */ if ((r & 0x20) && vint_pending) { /* Update IRQ status */ *irq_line = 0x30; if (d & 0x20) { *irq_line |= 0x06; } else if (hint_pending & reg[0]) { *irq_line |= 0x04; } } /* Active display height (Mode 5 only) */ if (r & 0x08) { /* Mode 5 only */ if (d & 0x04) { if (v_counter < bitmap.viewport.h) { /* Update active display height */ bitmap.viewport.h = 224 + ((d & 8) << 1); bitmap.viewport.y = (config.overscan & 1) * (8 - (d & 8) + 24*vdp_pal); } else { /* Changes should be applied on next frame */ bitmap.viewport.changed |= 2; } /* Update vertical counter max value */ vc_max = vc_table[(d >> 2) & 3][vdp_pal]; } } /* VDP Mode switch */ if (r & 0x04) { int i; if (d & 0x04) { /* Mode 5 rendering */ parse_satb = parse_satb_m5; update_bg_pattern_cache = update_bg_pattern_cache_m5; if (im2_flag) { render_bg = (reg[11] & 0x04) ? render_bg_m5_im2_vs : render_bg_m5_im2; render_obj = (reg[12] & 0x08) ? render_obj_m5_im2_ste : render_obj_m5_im2; } else { render_bg = (reg[11] & 0x04) ? render_bg_m5_vs : render_bg_m5; render_obj = (reg[12] & 0x08) ? render_obj_m5_ste : render_obj_m5; } /* Reset color palette */ color_update(0x00, *(uint16 *)&cram[border << 1]); for (i = 1; i < 0x40; i++) { color_update (i, *(uint16 *)&cram[i << 1]); } /* Mode 5 bus access */ vdp_68k_data_w = vdp_68k_data_w_m5; vdp_z80_data_w = vdp_z80_data_w_m5; vdp_68k_data_r = vdp_68k_data_r_m5; vdp_z80_data_r = vdp_z80_data_r_m5; /* Change display height */ if (v_counter < bitmap.viewport.h) { /* Update active display */ bitmap.viewport.h = 224 + ((d & 8) << 1); bitmap.viewport.y = (config.overscan & 1) * (8 - (d & 8) + 24*vdp_pal); } else { /* Changes should be applied on next frame */ bitmap.viewport.changed |= 2; } /* Clear HVC latched value */ hvc_latch = 0; /* Check if HVC latch bit is set */ if (reg[0] & 0x02) { /* Latch current HVC */ hvc_latch = vdp_hvc_r(cycles) | 0x10000; } /* max tiles to invalidate */ bg_list_index = 0x800; } else { /* Mode 4 rendering */ parse_satb = parse_satb_m4; update_bg_pattern_cache = update_bg_pattern_cache_m4; render_bg = render_bg_m4; render_obj = render_obj_m4; /* Reset color palette */ color_update(0x40, *(uint16 *)&cram[(0x10 | (border & 0x0F)) << 1]); for (i = 0; i < 0x20; i++) { color_update (i, *(uint16 *)&cram[i << 1]); } /* Mode 4 bus access */ vdp_68k_data_w = vdp_68k_data_w_m4; vdp_z80_data_w = vdp_z80_data_w_m4; vdp_68k_data_r = vdp_68k_data_r_m4; vdp_z80_data_r = vdp_z80_data_r_m4; if (v_counter < bitmap.viewport.h) { /* Update active display height */ bitmap.viewport.h = 192; bitmap.viewport.y = (config.overscan & 1) * 24 * (vdp_pal + 1); } else { /* Changes should be applied on next frame */ bitmap.viewport.changed |= 2; } /* Latch current HVC */ hvc_latch = vdp_hvc_r(cycles) | 0x10000; /* max tiles to invalidate */ bg_list_index = 0x200; } /* Invalidate pattern cache */ for (i=0;i<bg_list_index;i++) { bg_name_list[i] = i; bg_name_dirty[i] = 0xFF; } /* Update vertical counter max value */ vc_max = vc_table[(d >> 2) & 3][vdp_pal]; } break; } case 2: /* Plane A Name Table Base */ { reg[2] = d; ntab = (d << 10) & 0xE000; break; } case 3: /* Window Plane Name Table Base */ { reg[3] = d; if (reg[12] & 0x01) { ntwb = (d << 10) & 0xF000; } else { ntwb = (d << 10) & 0xF800; } break; } case 4: /* Plane B Name Table Base */ { reg[4] = d; ntbb = (d << 13) & 0xE000; break; } case 5: /* Sprite Attribute Table Base */ { reg[5] = d; satb = (d << 9) & sat_base_mask; break; } case 7: /* Backdrop color */ { reg[7] = d; /* Check if backdrop color changed */ d &= 0x3F; if (d != border) { /* Update backdrop color */ border = d; /* Reset palette entry */ if (reg[1] & 4) { /* Mode 5 */ color_update(0x00, *(uint16 *)&cram[d << 1]); } else { /* Mode 4 */ color_update(0x40, *(uint16 *)&cram[(0x10 | (d & 0x0F)) << 1]); } /* Backdrop color modified during HBLANK (Road Rash 1,2,3)*/ if ((v_counter < bitmap.viewport.h) && (cycles <= (mcycles_vdp + 860))) { /* remap entire line */ remap_line(v_counter); #ifdef LOGVDP error("Line remapped\n"); #endif } #ifdef LOGVDP else { error("Line NOT remapped\n"); } #endif } break; } case 8: /* HSCROLL (Mode 4) */ { reg[8] = d; /* HScroll is latched at the start of a line */ /* so make sure we are not already next line */ if ((cycles - Z80_CYCLE_OFFSET) < (mcycles_vdp + MCYCLES_PER_LINE - 4)) { /* Update Hscroll data for next line */ hscroll = d; } break; } case 11: /* CTRL #3 */ { reg[11] = d; /* Horizontal scrolling mode */ hscroll_mask = hscroll_mask_table[d & 0x03]; /* Vertical Scrolling mode */ if (d & 0x04) { render_bg = im2_flag ? render_bg_m5_im2_vs : render_bg_m5_vs; } else { render_bg = im2_flag ? render_bg_m5_im2 : render_bg_m5; } break; } case 12: /* CTRL #4 */ { /* Look for changed bits */ r = d ^ reg[12]; reg[12] = d; /* Shadow & Highlight mode */ if (r & 0x08) { /* Reset color palette */ int i; color_update(0x00, *(uint16 *)&cram[border << 1]); for (i = 1; i < 0x40; i++) { color_update (i, *(uint16 *)&cram[i << 1]); } /* Update sprite rendering function */ if (d & 0x08) { render_obj = im2_flag ? render_obj_m5_im2_ste : render_obj_m5_ste; } else { render_obj = im2_flag ? render_obj_m5_im2 : render_obj_m5; } } /* Interlaced modes */ if (r & 0x06) { /* changes should be applied on next frame */ bitmap.viewport.changed |= 2; } /* Active display width */ if (r & 0x01) { if (d & 0x01) { /* Update display-dependant registers */ ntwb = (reg[3] << 10) & 0xF000; satb = (reg[5] << 9) & 0xFC00; sat_base_mask = 0xFC00; sat_addr_mask = 0x03FF; /* Update HC table */ hctab = cycle2hc40; /* Update clipping */ window_clip(reg[17], 1); /* Update fifo timings */ fifo_latency = 190; } else { /* Update display-dependant registers */ ntwb = (reg[3] << 10) & 0xF800; satb = (reg[5] << 9) & 0xFE00; sat_base_mask = 0xFE00; sat_addr_mask = 0x01FF; /* Update HC table */ hctab = cycle2hc32; /* Update clipping */ window_clip(reg[17], 0); /* Update FIFO timings */ fifo_latency = 214; } /* Adjust FIFO timings for VRAM writes */ fifo_latency <<= ((code & 0x0F) == 0x01); /* Active display width modified during HBLANK (Bugs Bunny Double Trouble) */ if ((v_counter < bitmap.viewport.h) && (cycles <= (mcycles_vdp + 860))) { /* Update active display width */ bitmap.viewport.w = 256 + ((d & 1) << 6); /* Redraw entire line */ render_line(v_counter); } else { /* Changes should be applied on next frame (Golden Axe III intro) */ /* NB: This is not 100% accurate but is required by GCN/Wii port (GX texture direct mapping) */ /* and isn't noticeable anyway since display is generally disabled when active width is modified */ bitmap.viewport.changed |= 2; } } break; } case 13: /* HScroll Base Address */ { reg[13] = d; hscb = (d << 10) & 0xFC00; break; } case 16: /* Playfield size */ { reg[16] = d; playfield_shift = shift_table[(d & 3)]; playfield_col_mask = col_mask_table[(d & 3)]; playfield_row_mask = row_mask_table[(d >> 4) & 3]; break; } case 17: /* Window/Plane A vertical clipping */ { reg[17] = d; window_clip(d, reg[12] & 1); break; } default: { reg[r] = d; break; } } } /*--------------------------------------------------------------------------*/ /* FIFO update function */ /*--------------------------------------------------------------------------*/ static void vdp_fifo_update(unsigned int cycles) { if (fifo_write_cnt > 0) { /* Get number of FIFO reads */ int fifo_read = ((cycles - fifo_lastwrite) / fifo_latency); if (fifo_read > 0) { /* Process FIFO entries */ fifo_write_cnt -= fifo_read; /* Clear FIFO full flag */ status &= 0xFEFF; /* Check remaining FIFO entries */ if (fifo_write_cnt <= 0) { /* Set FIFO empty flag */ status |= 0x200; fifo_write_cnt = 0; } /* Update FIFO cycle count */ fifo_lastwrite += (fifo_read * fifo_latency); } } } /*--------------------------------------------------------------------------*/ /* Internal 16-bit data bus access function (Mode 5 only) */ /*--------------------------------------------------------------------------*/ static void vdp_bus_w(unsigned int data) { /* Check destination code */ switch (code & 0x0F) { case 0x01: /* VRAM */ { #ifdef LOGVDP error("[%d(%d)][%d(%d)] VRAM 0x%x write -> 0x%x (%x)\n", v_counter, mcycles_68k/MCYCLES_PER_LINE, mcycles_68k, mcycles_68k%MCYCLES_PER_LINE, addr, data, m68k_get_reg (NULL, M68K_REG_PC)); #endif /* Byte-swap data if A0 is set */ if (addr & 1) { data = ((data >> 8) | (data << 8)) & 0xFFFF; } /* VRAM address */ int index = addr & 0xFFFE; /* Pointer to VRAM */ uint16 *p = (uint16 *)&vram[index]; /* Intercept writes to Sprite Attribute Table */ if ((index & sat_base_mask) == satb) { /* Update internal SAT */ *(uint16 *) &sat[index & sat_addr_mask] = data; } /* Only write unique data to VRAM */ if (data != *p) { /* Write data to VRAM */ *p = data; /* Update pattern cache */ int name; MARK_BG_DIRTY (index); } break; } case 0x03: /* CRAM */ { #ifdef LOGVDP error("[%d(%d)][%d(%d)] CRAM 0x%x write -> 0x%x (%x)\n", v_counter, mcycles_68k/MCYCLES_PER_LINE, mcycles_68k, mcycles_68k%MCYCLES_PER_LINE, addr, data, m68k_get_reg (NULL, M68K_REG_PC)); #endif /* Pointer to CRAM 9-bit word */ uint16 *p = (uint16 *)&cram[addr & 0x7E]; /* Pack 16-bit bus data (BBB0GGG0RRR0) to 9-bit CRAM data (BBBGGGRRR) */ data = ((data & 0xE00) >> 3) | ((data & 0x0E0) >> 2) | ((data & 0x00E) >> 1); /* Check if CRAM data is being modified */ if (data != *p) { /* Write CRAM data */ *p = data; /* CRAM index (64 words) */ int index = (addr >> 1) & 0x3F; /* Color entry 0 of each palette is never displayed (transparent pixel) */ if (index & 0x0F) { /* Update color palette */ color_update(index, data); } /* Update backdrop color */ if (index == border) { color_update(0x00, data); } /* CRAM modified during HBLANK (Striker, Zero the Kamikaze, etc) */ if ((v_counter < bitmap.viewport.h) && (reg[1]& 0x40) && (mcycles_68k <= (mcycles_vdp + 860))) { /* Remap current line */ remap_line(v_counter); #ifdef LOGVDP error("Line remapped\n"); #endif } #ifdef LOGVDP else error("Line NOT remapped\n"); #endif } break; } case 0x05: /* VSRAM */ { #ifdef LOGVDP error("[%d(%d)][%d(%d)] VSRAM 0x%x write -> 0x%x (%x)\n", v_counter, mcycles_68k/MCYCLES_PER_LINE, mcycles_68k, mcycles_68k%MCYCLES_PER_LINE, addr, data, m68k_get_reg (NULL, M68K_REG_PC)); #endif *(uint16 *)&vsram[addr & 0x7E] = data; break; } #ifdef LOGVDP default: { error("[%d(%d)][%d(%d)] Unknown (%d) 0x%x write -> 0x%x (%x)\n", v_counter, mcycles_68k/MCYCLES_PER_LINE, mcycles_68k, mcycles_68k%MCYCLES_PER_LINE, code, addr, data, m68k_get_reg (NULL, M68K_REG_PC)); break; } #endif } /* Increment address register (TODO: see how address is incremented in Mode 4) */ addr += reg[15]; } /*--------------------------------------------------------------------------*/ /* 68k data port access functions (Genesis mode) */ /*--------------------------------------------------------------------------*/ static void vdp_68k_data_w_m4(unsigned int data) { /* Clear pending flag */ pending = 0; /* Check destination code */ if (code & 0x02) { /* CRAM index (32 words) */ int index = addr & 0x1F; /* Pointer to CRAM 9-bit word */ uint16 *p = (uint16 *)&cram[index << 1]; /* Pack 16-bit data (xxx000BBGGRR) to 9-bit CRAM data (xxxBBGGRR) */ data = ((data & 0xE00) >> 3) | (data & 0x3F); /* Check if CRAM data is being modified */ if (data != *p) { /* Write CRAM data */ *p = data; /* Update color palette */ color_update(index, data); /* Update backdrop color */ if (index == (0x10 | (border & 0x0F))) { color_update(0x40, data); } } } else { /* Byte-swap data if A0 is set */ if (addr & 1) { data = ((data >> 8) | (data << 8)) & 0xFFFF; } /* VRAM address (interleaved format) */ int index = ((addr << 1) & 0x3FC) | ((addr & 0x200) >> 8) | (addr & 0x3C00); /* Pointer to VRAM */ uint16 *p = (uint16 *)&vram[index]; /* Only write unique data to VRAM */ if (data != *p) { /* Write data to VRAM */ *p = data; /* Update the pattern cache */ int name; MARK_BG_DIRTY (index); } } /* Increment address register */ addr += (reg[15] + 1); } static void vdp_68k_data_w_m5(unsigned int data) { /* Clear pending flag */ pending = 0; /* Restricted VDP writes during active display */ if (!(status & 8) && (reg[1] & 0x40)) { /* Update VDP FIFO */ vdp_fifo_update(mcycles_68k); /* Clear FIFO empty flag */ status &= 0xFDFF; /* 4 words can be stored */ if (fifo_write_cnt < 4) { /* Increment FIFO counter */ fifo_write_cnt++; /* Set FIFO full flag if 4 words are stored */ status |= ((fifo_write_cnt & 4) << 6); } else { /* CPU is locked until last FIFO entry has been processed (Chaos Engine, Soldiers of Fortune, Double Clutch) */ fifo_lastwrite += fifo_latency; mcycles_68k = fifo_lastwrite; } } /* Write data */ vdp_bus_w(data); /* DMA Fill */ if (dmafill & 0x100) { /* Fill data (DMA fill flag is cleared) */ dmafill = data >> 8; /* DMA length */ dma_length = (reg[20] << 8) | reg[19]; /* Zero DMA length */ if (!dma_length) { dma_length = 0x10000; } /* Perform DMA Fill*/ dma_type = 2; vdp_dma_update(mcycles_68k); } } static unsigned int vdp_68k_data_r_m4(void) { /* Clear pending flag */ pending = 0; /* VRAM address (interleaved format) */ int index = ((addr << 1) & 0x3FC) | ((addr & 0x200) >> 8) | (addr & 0x3C00); /* Increment address register */ addr += (reg[15] + 1); /* Read VRAM data */ return *(uint16 *) &vram[index]; } static unsigned int vdp_68k_data_r_m5(void) { uint16 data = 0; /* Clear pending flag */ pending = 0; switch (code & 0x0F) { case 0x00: /* VRAM */ { /* Read data */ data = *(uint16 *)&vram[addr & 0xFFFE]; #ifdef LOGVDP error("[%d(%d)][%d(%d)] VRAM 0x%x read -> 0x%x (%x)\n", v_counter, mcycles_68k/MCYCLES_PER_LINE, mcycles_68k, mcycles_68k%MCYCLES_PER_LINE, addr, data, m68k_get_reg (NULL, M68K_REG_PC)); #endif break; } case 0x04: /* VSRAM */ { /* Read data */ data = *(uint16 *)&vsram[addr & 0x7E]; #ifdef LOGVDP error("[%d(%d)][%d(%d)] VSRAM 0x%x read -> 0x%x (%x)\n", v_counter, mcycles_68k/MCYCLES_PER_LINE, mcycles_68k, mcycles_68k%MCYCLES_PER_LINE, addr, data, m68k_get_reg (NULL, M68K_REG_PC)); #endif break; } case 0x08: /* CRAM */ { /* Read data */ data = *(uint16 *)&cram[addr & 0x7E]; /* Unpack 9-bit CRAM data (BBBGGGRRR) to 16-bit bus data (BBB0GGG0RRR0) */ data = ((data & 0x1C0) << 3) | ((data & 0x038) << 2) | ((data & 0x007) << 1); #ifdef LOGVDP error("[%d(%d)][%d(%d)] CRAM 0x%x read -> 0x%x (%x)\n", v_counter, mcycles_68k/MCYCLES_PER_LINE, mcycles_68k, mcycles_68k%MCYCLES_PER_LINE, addr, data, m68k_get_reg (NULL, M68K_REG_PC)); #endif break; } default: { /* Invalid code value */ #ifdef LOGVDP error("[%d(%d)][%d(%d)] Invalid (%d) 0x%x read (%x)\n", v_counter, mcycles_68k/MCYCLES_PER_LINE, mcycles_68k, mcycles_68k%MCYCLES_PER_LINE, code, addr, m68k_get_reg (NULL, M68K_REG_PC)); #endif break; } } /* Increment address register */ addr += reg[15]; /* Return data */ return data; } /*--------------------------------------------------------------------------*/ /* Z80 data port access functions (MS compatibilty mode) */ /*--------------------------------------------------------------------------*/ static void vdp_z80_data_w_m4(unsigned int data) { /* Clear pending flag */ pending = 0; /* Check destination code */ if (code & 0x02) { /* CRAM index (32 words) */ int index = addr & 0x1F; /* Pointer to CRAM 9-bit word */ uint16 *p = (uint16 *)&cram[index << 1]; /* Check if CRAM data is being modified */ if (data != *p) { /* Write CRAM data */ *p = data; /* Update color palette */ color_update(index, data); /* Update backdrop color */ if (index == (0x10 | (border & 0x0F))) { color_update(0x40, data); } } } else { /* VRAM address */ int index = addr & 0x3FFF; /* Only write unique data to VRAM */ if (data != vram[index]) { /* Write data */ vram[index] = data; /* Update pattern cache */ int name; MARK_BG_DIRTY (index); } } /* Increment address register */ addr += (reg[15] + 1); } static void vdp_z80_data_w_m5(unsigned int data) { /* Clear pending flag */ pending = 0; /* Check destination code */ switch (code & 0x0F) { case 0x01: /* VRAM */ { /* VRAM address (write low byte to even address & high byte to odd address) */ int index = addr ^ 1; /* Intercept writes to Sprite Attribute Table */ if ((index & sat_base_mask) == satb) { /* Update internal SAT */ WRITE_BYTE(sat, index & sat_addr_mask, data); } /* Only write unique data to VRAM */ if (data != READ_BYTE(vram, index)) { /* Write data */ WRITE_BYTE(vram, index, data); /* Update pattern cache */ int name; MARK_BG_DIRTY (index); } break; } case 0x03: /* CRAM */ { /* Pointer to CRAM 9-bit word */ uint16 *p = (uint16 *)&cram[addr & 0x7E]; /* Pack 8-bit value into 9-bit CRAM data */ if (addr & 1) { /* Write high byte (0000BBB0 -> BBBxxxxxx) */ data = (*p & 0x3F) | ((data & 0x0E) << 5); } else { /* Write low byte (GGG0RRR0 -> xxxGGGRRR) */ data = (*p & 0x1C0) | ((data & 0x0E) >> 1)| ((data & 0xE0) >> 2); } /* Check if CRAM data is being modified */ if (data != *p) { /* Write CRAM data */ *p = data; /* CRAM index (64 words) */ int index = (addr >> 1) & 0x3F; /* Color entry 0 of each palette is never displayed (transparent pixel) */ if (index & 0x0F) { /* Update color palette */ color_update(index, data); } /* Update backdrop color */ if (index == border) { color_update(0x00, data); } } break; } case 0x05: /* VSRAM */ { /* Write low byte to even address & high byte to odd address */ WRITE_BYTE(vsram, (addr & 0x7F) ^ 1, data); break; } } /* Increment address register */ addr += reg[15]; /* DMA Fill */ if (dmafill & 0x100) { /* Fill data (DMA fill flag is cleared) */ dmafill = data; /* DMA length */ dma_length = (reg[20] << 8) | reg[19]; /* Zero DMA length */ if (!dma_length) { dma_length = 0x10000; } /* Perform DMA Fill */ dma_type = 2; vdp_dma_update(mcycles_z80); } } static unsigned int vdp_z80_data_r_m4(void) { /* Clear pending flag */ pending = 0; /* Read buffer */ unsigned int data = fifo[0]; /* Process next read */ fifo[0] = vram[addr & 0x3FFF]; /* Increment address register */ addr += (reg[15] + 1); /* Return data */ return data; } static unsigned int vdp_z80_data_r_m5(void) { unsigned int data = 0; /* Clear pending flag */ pending = 0; switch (code & 0x0F) { case 0x00: /* VRAM */ { /* Return low byte from even address & high byte from odd address */ data = READ_BYTE(vram, addr ^ 1); break; } case 0x04: /* VSRAM */ { /* Return low byte from even address & high byte from odd address */ data = READ_BYTE(vsram, (addr & 0x7F) ^ 1); break; } case 0x08: /* CRAM */ { /* Read CRAM data */ data = *(uint16 *)&cram[addr & 0x7E]; /* Unpack 9-bit CRAM data (BBBGGGRRR) to 16-bit data (BBB0GGG0RRR0) */ data = ((data & 0x1C0) << 3) | ((data & 0x038) << 2) | ((data & 0x007) << 1); /* Return low byte from even address & high byte from odd address */ if (addr & 1) { data = data >> 8; } data &= 0xFF; break; } } /* Increment address register (TODO: see how address is incremented in Mode 5) */ addr += reg[15]; /* Return data */ return data; } /*--------------------------------------------------------------------------*/ /* DMA operations */ /*--------------------------------------------------------------------------*/ /* 68K bus to VRAM, VSRAM or CRAM */ static void vdp_dma_vbus(int length) { unsigned int data; unsigned int source = (reg[23] << 17 | reg[22] << 9 | reg[21] << 1) & 0xFFFFFE; unsigned int base = source; /* DMA source */ if ((source >> 17) == 0x50) { /* Z80 & I/O area ($A00000-$A1FFFF) */ do { /* Return $FFFF only when the Z80 isn't hogging the Z-bus. (e.g. Z80 isn't reset and 68000 has the bus) */ if (source <= 0xA0FFFF) { data = ((zstate ^ 3) ? *(uint16 *)(work_ram + (source & 0xFFFF)) : 0xFFFF); } /* The I/O chip and work RAM try to drive the data bus which results in both values being combined in random ways when read. We return the I/O chip values which seem to have precedence, */ else if (source <= 0xA1001F) { data = io_68k_read((source >> 1) & 0x0F); data = (data << 8 | data); } /* All remaining locations access work RAM */ else { data = *(uint16 *)(work_ram + (source & 0xFFFF)); } /* Increment source address */ source += 2; /* 128k DMA window (i.e reg #23 is not modified) */ source = ((base & 0xFE0000) | (source & 0x1FFFF)); /* Write data on internal bus */ vdp_bus_w(data); } while (--length); } else { do { /* Read from mapped memory (ROM/RAM) */ data = *(uint16 *)(m68k_memory_map[source>>16].base + (source & 0xFFFF)); /* Increment source address */ source += 2; /* 128k DMA window (i.e reg #23 is not modified) */ source = ((base & 0xFE0000) | (source & 0x1FFFF)); /* Write data on internal bus */ vdp_bus_w(data); } while (--length); } /* Update source address registers (reg #23 has not been modified) */ reg[21] = (source >> 1) & 0xFF; reg[22] = (source >> 9) & 0xFF; } /* VRAM Copy (TODO: check if CRAM or VSRAM copy is possible) */ static void vdp_dma_copy(int length) { int name; unsigned int temp; unsigned int source = (reg[22] << 8) | reg[21]; do { /* Read byte from source address */ temp = READ_BYTE(vram, source); /* Intercept writes to Sprite Attribute Table */ if ((addr & sat_base_mask) == satb) { /* Update internal SAT */ WRITE_BYTE(sat, addr & sat_addr_mask, temp); } /* Write byte to VRAM address */ WRITE_BYTE(vram, addr, temp); /* Update pattern cache */ MARK_BG_DIRTY(addr); /* Increment source address */ source = (source + 1) & 0xFFFF; /* Increment VRAM address */ addr += reg[15]; } while (--length); /* Update source address registers */ reg[21] = source & 0xFF; reg[22] = (source >> 8) & 0xFF; } /* VRAM Fill (TODO: check if CRAM or VSRAM fill is possible) */ static void vdp_dma_fill(unsigned int data, int length) { int name; do { /* Intercept writes to Sprite Attribute Table */ if ((addr & sat_base_mask) == satb) { /* Update internal SAT */ WRITE_BYTE(sat, (addr & sat_addr_mask) ^ 1, data); } /* Write byte to adjacent VRAM address */ WRITE_BYTE(vram, addr ^ 1, data); /* Update pattern cache */ MARK_BG_DIRTY (addr); /* Increment VRAM address */ addr += reg[15]; } while (--length); }
zyking1987-genplus-droid
genplusgx/vdp_ctrl.c
C
gpl2
60,535
/*************************************************************************************** * Genesis Plus * 68k bus controller * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007,2008,2009), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "m68k/m68kcpu.h" #include "shared.h" /*--------------------------------------------------------------------------*/ /* Unused area (return open bus data, i.e prefetched instruction word) */ /*--------------------------------------------------------------------------*/ unsigned int m68k_read_bus_8(unsigned int address) { #ifdef LOGERROR error("Unused read8 %08X (%08X)\n", address, m68k_get_reg (NULL, M68K_REG_PC)); #endif return m68k_read_pcrelative_8(REG_PC | (address & 1)); } unsigned int m68k_read_bus_16(unsigned int address) { #ifdef LOGERROR error("Unused read16 %08X (%08X)\n", address, m68k_get_reg (NULL, M68K_REG_PC)); #endif return m68k_read_pcrelative_16(REG_PC); } void m68k_unused_8_w (unsigned int address, unsigned int data) { #ifdef LOGERROR error("Unused write8 %08X = %02X (%08X)\n", address, data, m68k_get_reg (NULL, M68K_REG_PC)); #endif } void m68k_unused_16_w (unsigned int address, unsigned int data) { #ifdef LOGERROR error("Unused write16 %08X = %04X (%08X)\n", address, data, m68k_get_reg (NULL, M68K_REG_PC)); #endif } /*--------------------------------------------------------------------------*/ /* Illegal area (cause system to lock-up since !DTACK is not returned) */ /*--------------------------------------------------------------------------*/ void m68k_lockup_w_8 (unsigned int address, unsigned int data) { #ifdef LOGERROR error ("Lockup %08X = %02X (%08X)\n", address, data, m68k_get_reg (NULL, M68K_REG_PC)); #endif if (!config.force_dtack) { m68k_pulse_halt(); } } void m68k_lockup_w_16 (unsigned int address, unsigned int data) { #ifdef LOGERROR error ("Lockup %08X = %04X (%08X)\n", address, data, m68k_get_reg (NULL, M68K_REG_PC)); #endif if (!config.force_dtack) { m68k_pulse_halt(); } } unsigned int m68k_lockup_r_8 (unsigned int address) { #ifdef LOGERROR error ("Lockup %08X.b (%08X)\n", address, m68k_get_reg (NULL, M68K_REG_PC)); #endif if (!config.force_dtack) { m68k_pulse_halt(); } return m68k_read_pcrelative_8(REG_PC | (address & 1)); } unsigned int m68k_lockup_r_16 (unsigned int address) { #ifdef LOGERROR error ("Lockup %08X.w (%08X)\n", address, m68k_get_reg (NULL, M68K_REG_PC)); #endif if (!config.force_dtack) { m68k_pulse_halt(); } return m68k_read_pcrelative_16(REG_PC); } /*--------------------------------------------------------------------------*/ /* cartridge EEPROM */ /*--------------------------------------------------------------------------*/ unsigned int eeprom_read_byte(unsigned int address) { if (address == eeprom.type.sda_out_adr) { return eeprom_read(0); } return READ_BYTE(cart.rom, address); } unsigned int eeprom_read_word(unsigned int address) { if (address == (eeprom.type.sda_out_adr & 0xFFFFFE)) { return eeprom_read(1); } return *(uint16 *)(cart.rom + address); } void eeprom_write_byte(unsigned int address, unsigned int data) { if ((address == eeprom.type.sda_in_adr) || (address == eeprom.type.scl_adr)) { eeprom_write(address, data, 0); return; } m68k_unused_8_w(address, data); } void eeprom_write_word(unsigned int address, unsigned int data) { if ((address == (eeprom.type.sda_in_adr & 0xFFFFFE)) || (address == (eeprom.type.scl_adr & 0xFFFFFE))) { eeprom_write(address, data, 1); return; } m68k_unused_16_w (address, data); } /*--------------------------------------------------------------------------*/ /* Z80 bus (accessed through I/O chip) */ /*--------------------------------------------------------------------------*/ unsigned int z80_read_byte(unsigned int address) { switch ((address >> 13) & 3) { case 2: /* YM2612 */ { return fm_read(mcycles_68k, address & 3); } case 3: /* Misc */ { if ((address & 0xFF00) == 0x7F00) { /* VDP (through 68k bus) */ return m68k_lockup_r_8(address); } return (m68k_read_bus_8(address) | 0xFF); } default: /* ZRAM */ { return zram[address & 0x1FFF]; } } } unsigned int z80_read_word(unsigned int address) { unsigned int data = z80_read_byte(address); return (data | (data << 8)); } void z80_write_byte(unsigned int address, unsigned int data) { switch ((address >> 13) & 3) { case 2: /* YM2612 */ { fm_write(mcycles_68k, address & 3, data); return; } case 3: { switch ((address >> 8) & 0x7F) { case 0x60: /* Bank register */ { gen_zbank_w(data & 1); return; } case 0x7F: /* VDP */ { m68k_lockup_w_8(address, data); return; } default: { m68k_unused_8_w(address, data); return; } } } default: /* ZRAM */ { zram[address & 0x1FFF] = data; mcycles_68k += 8; /* ZRAM access latency (fixes Pacman 2: New Adventures) */ return; } } } void z80_write_word(unsigned int address, unsigned int data) { z80_write_byte(address, data >> 8); } /*--------------------------------------------------------------------------*/ /* I/O Control */ /*--------------------------------------------------------------------------*/ unsigned int ctrl_io_read_byte(unsigned int address) { switch ((address >> 8) & 0xFF) { case 0x00: /* I/O chip */ { if (!(address & 0xE0)) { return io_68k_read((address >> 1) & 0x0F); } return m68k_read_bus_8(address); } case 0x11: /* BUSACK */ { if (!(address & 1)) { unsigned int data = m68k_read_pcrelative_8(REG_PC) & 0xFE; if (zstate == 3) { return data; } return (data | 0x01); } return m68k_read_bus_8(address); } case 0x30: /* TIME */ { if (cart.hw.time_r) { unsigned int data = cart.hw.time_r(address); if (address & 1) { return (data & 0xFF); } return (data >> 8); } return m68k_read_bus_8(address); } case 0x41: /* OS ROM */ { if (address & 1) { unsigned int data = m68k_read_pcrelative_8(REG_PC) & 0xFE; return (gen_bankswitch_r() | data); } return m68k_read_bus_8(address); } case 0x10: /* MEMORY MODE */ case 0x12: /* RESET */ case 0x20: /* MEGA-CD */ case 0x40: /* TMSS */ case 0x44: /* RADICA */ case 0x50: /* SVP REGISTERS */ { return m68k_read_bus_8(address); } default: /* Invalid address */ { return m68k_lockup_r_8(address); } } } unsigned int ctrl_io_read_word(unsigned int address) { switch ((address >> 8) & 0xFF) { case 0x00: /* I/O chip */ { if (!(address & 0xE0)) { unsigned int data = io_68k_read((address >> 1) & 0x0F); return (data << 8 | data); } return m68k_read_bus_16(address); } case 0x11: /* BUSACK */ { unsigned int data = m68k_read_pcrelative_16(REG_PC) & 0xFEFF; if (zstate == 3) { return data; } return (data | 0x0100); } case 0x30: /* TIME */ { if (cart.hw.time_r) { return cart.hw.time_r(address); } return m68k_read_bus_16(address); } case 0x50: /* SVP */ { if ((address & 0xFD) == 0) { return svp->ssp1601.gr[SSP_XST].u.h; } if ((address & 0xFF) == 4) { unsigned int data = svp->ssp1601.gr[SSP_PM0].u.h; svp->ssp1601.gr[SSP_PM0].u.h &= ~1; return data; } return m68k_read_bus_16(address); } case 0x10: /* MEMORY MODE */ case 0x12: /* RESET */ case 0x20: /* MEGA-CD */ case 0x40: /* TMSS */ case 0x41: /* OS ROM */ case 0x44: /* RADICA */ { return m68k_read_bus_16(address); } default: /* Invalid address */ { return m68k_lockup_r_16(address); } } } void ctrl_io_write_byte(unsigned int address, unsigned int data) { switch ((address >> 8) & 0xFF) { case 0x00: /* I/O chip */ { if ((address & 0xE1) == 0x01) { /* get /LWR only */ io_68k_write((address >> 1) & 0x0F, data); return; } m68k_unused_8_w(address, data); return; } case 0x11: /* BUSREQ */ { if (!(address & 1)) { gen_zbusreq_w(data & 1, mcycles_68k); return; } m68k_unused_8_w(address, data); return; } case 0x12: /* RESET */ { if (!(address & 1)) { gen_zreset_w(data & 1, mcycles_68k); return; } m68k_unused_8_w(address, data); return; } case 0x30: /* TIME */ { cart.hw.time_w(address, data); return; } case 0x41: /* OS ROM */ { if (address & 1) { gen_bankswitch_w(data & 1); return; } m68k_unused_8_w(address, data); return; } case 0x10: /* MEMORY MODE */ case 0x20: /* MEGA-CD */ case 0x40: /* TMSS */ case 0x44: /* RADICA */ case 0x50: /* SVP REGISTERS */ { m68k_unused_8_w(address, data); return; } default: /* Invalid address */ { m68k_lockup_w_8(address, data); return; } } } void ctrl_io_write_word(unsigned int address, unsigned int data) { switch ((address >> 8) & 0xFF) { case 0x00: /* I/O chip */ { if (!(address & 0xE0)) { io_68k_write((address >> 1) & 0x0F, data & 0xFF); return; } m68k_unused_16_w(address, data); return; } case 0x11: /* BUSREQ */ { gen_zbusreq_w((data >> 8) & 1, mcycles_68k); return; } case 0x12: /* RESET */ { gen_zreset_w((data >> 8) & 1, mcycles_68k); return; } case 0x30: /* TIME */ { cart.hw.time_w(address, data); return; } case 0x40: /* TMSS */ { if (config.tmss & 1) { gen_tmss_w(address & 3, data); return; } m68k_unused_16_w(address, data); return; } case 0x50: /* SVP REGISTERS */ { if (!(address & 0xFD)) { svp->ssp1601.gr[SSP_XST].u.h = data; svp->ssp1601.gr[SSP_PM0].u.h |= 2; svp->ssp1601.emu_status &= ~SSP_WAIT_PM0; return; } m68k_unused_16_w(address, data); return; } case 0x10: /* MEMORY MODE */ case 0x20: /* MEGA-CD */ case 0x41: /* OS ROM */ case 0x44: /* RADICA */ { m68k_unused_16_w (address, data); return; } default: /* Invalid address */ { m68k_lockup_w_16 (address, data); return; } } } /*--------------------------------------------------------------------------*/ /* VDP */ /*--------------------------------------------------------------------------*/ unsigned int vdp_read_byte(unsigned int address) { switch (address & 0xFD) { case 0x00: /* DATA */ { return (vdp_68k_data_r() >> 8); } case 0x01: /* DATA */ { return (vdp_68k_data_r() & 0xFF); } case 0x04: /* CTRL */ { return (((vdp_ctrl_r(mcycles_68k) >> 8) & 3) | (m68k_read_pcrelative_8(REG_PC) & 0xFC)); } case 0x05: /* CTRL */ { return (vdp_ctrl_r(mcycles_68k) & 0xFF); } case 0x08: /* HVC */ case 0x0C: { return (vdp_hvc_r(mcycles_68k) >> 8); } case 0x09: /* HVC */ case 0x0D: { return (vdp_hvc_r(mcycles_68k) & 0xFF); } case 0x18: /* Unused */ case 0x19: case 0x1C: case 0x1D: { return m68k_read_bus_8(address); } default: /* Invalid address */ { return m68k_lockup_r_8(address); } } } unsigned int vdp_read_word(unsigned int address) { switch (address & 0xFC) { case 0x00: /* DATA */ { return vdp_68k_data_r(); } case 0x04: /* CTRL */ { return ((vdp_ctrl_r(mcycles_68k) & 0x3FF) | (m68k_read_pcrelative_16(REG_PC) & 0xFC00)); } case 0x08: /* HVC */ case 0x0C: { return vdp_hvc_r(mcycles_68k); } case 0x18: /* Unused */ case 0x1C: { return m68k_read_bus_16(address); } default: /* Invalid address */ { return m68k_lockup_r_16(address); } } } void vdp_write_byte(unsigned int address, unsigned int data) { switch (address & 0xFC) { case 0x00: /* Data port */ { vdp_68k_data_w(data << 8 | data); return; } case 0x04: /* Control port */ { vdp_68k_ctrl_w(data << 8 | data); return; } case 0x10: /* PSG */ case 0x14: { if (address & 1) { psg_write(mcycles_68k, data); return; } m68k_unused_8_w(address, data); return; } case 0x18: /* Unused */ { m68k_unused_8_w(address, data); return; } case 0x1C: /* TEST register */ { vdp_test_w(data << 8 | data); return; } default: /* Invalid address */ { m68k_lockup_w_8(address, data); return; } } } void vdp_write_word(unsigned int address, unsigned int data) { switch (address & 0xFC) { case 0x00: /* DATA */ { vdp_68k_data_w(data); return; } case 0x04: /* CTRL */ { vdp_68k_ctrl_w(data); return; } case 0x10: /* PSG */ case 0x14: { psg_write(mcycles_68k, data & 0xFF); return; } case 0x18: /* Unused */ { m68k_unused_16_w(address, data); return; } case 0x1C: /* Test register */ { vdp_test_w(data); return; } default: /* Invalid address */ { m68k_lockup_w_16 (address, data); return; } } } /******* PICO ************************************************/ unsigned int pico_read_byte(unsigned int address) { /* PICO */ switch (address & 0xFF) { case 0x01: /* VERSION register */ { return 0x40; } case 0x03: /* IO register */ { unsigned int retval = 0xFF; if (input.pad[0] & INPUT_B) retval &= ~0x10; if (input.pad[0] & INPUT_A) retval &= ~0x80; if (input.pad[0] & INPUT_UP) retval &= ~0x01; if (input.pad[0] & INPUT_DOWN) retval &= ~0x02; if (input.pad[0] & INPUT_LEFT) retval &= ~0x04; if (input.pad[0] & INPUT_RIGHT) retval &= ~0x08; retval &= ~0x20; retval &= ~0x40; return retval; } case 0x05: /* MSB PEN X coordinate */ { return (input.analog[0][0] >> 8); } case 0x07: /* LSB PEN X coordinate */ { return (input.analog[0][0] & 0xFF); } case 0x09: /* MSB PEN Y coordinate */ { return (input.analog[0][1] >> 8); } case 0x0B: /* LSB PEN Y coordinate */ { return (input.analog[0][1] & 0xFF); } case 0x0D: /* PAGE register (TODO) */ { return pico_page[pico_current]; } case 0x10: /* PCM registers (TODO) */ { return 0x80; } default: { return m68k_read_bus_8(address); } } } unsigned int pico_read_word(unsigned int address) { return (pico_read_byte(address | 1) | (m68k_read_bus_8(address) << 8)); }
zyking1987-genplus-droid
genplusgx/mem68k.c
C
gpl2
17,441
/*************************************************************************************** * Genesis Plus * Z80 bus controller (MD & MS compatibility mode) * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007-2011), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _MEMZ80_H_ #define _MEMZ80_H_ extern unsigned char z80_md_memory_r(unsigned int address); extern void z80_md_memory_w(unsigned int address, unsigned char data); extern unsigned char z80_sms_memory_r(unsigned int address); extern unsigned char z80_unused_port_r(unsigned int port); extern void z80_unused_port_w(unsigned int port, unsigned char data); extern unsigned char z80_sms_port_r(unsigned int port); extern void z80_sms_port_w(unsigned int port, unsigned char data); #endif /* _MEMZ80_H_ */
zyking1987-genplus-droid
genplusgx/memz80.h
C
gpl2
1,685
/*************************************************************************************** * Genesis Plus * I/O controller (MD & MS compatibility modes) * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007-2011), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _GEN_IO_H_ #define _GEN_IO_H_ #define REGION_JAPAN_NTSC 0x00 #define REGION_JAPAN_PAL 0x40 #define REGION_USA 0x80 #define REGION_EUROPE 0xC0 /* Global variables */ extern uint8 io_reg[0x10]; extern uint8 region_code; /* Function prototypes */ extern void io_init(void); extern void io_reset(void); extern void io_68k_write(unsigned int offset, unsigned int data); extern unsigned int io_68k_read(unsigned int offset); extern void io_z80_write(unsigned int data); extern unsigned int io_z80_read(unsigned int offset); #endif /* _IO_H_ */
zyking1987-genplus-droid
genplusgx/io_ctrl.h
C
gpl2
1,747
/* sms_ntsc 0.2.3. http://www.slack.net/~ant/ */ /* Common implementation of NTSC filters */ #include <assert.h> #include <math.h> /* Copyright (C) 2006 Shay Green. This module is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This module is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this module; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define DISABLE_CORRECTION 0 #undef PI #define PI 3.14159265358979323846f #ifndef LUMA_CUTOFF #define LUMA_CUTOFF 0.20 #endif #ifndef gamma_size #define gamma_size 1 #endif #ifndef rgb_bits #define rgb_bits 8 #endif #ifndef artifacts_max #define artifacts_max (artifacts_mid * 1.5f) #endif #ifndef fringing_max #define fringing_max (fringing_mid * 2) #endif #ifndef STD_HUE_CONDITION #define STD_HUE_CONDITION( setup ) 1 #endif #define ext_decoder_hue (std_decoder_hue + 15) #define rgb_unit (1 << rgb_bits) #define rgb_offset (rgb_unit * 2 + 0.5f) enum { burst_size = sms_ntsc_entry_size / burst_count }; enum { kernel_half = 16 }; enum { kernel_size = kernel_half * 2 + 1 }; typedef struct init_t { float to_rgb [burst_count * 6]; float to_float [gamma_size]; float contrast; float brightness; float artifacts; float fringing; float kernel [rescale_out * kernel_size * 2]; } init_t; #define ROTATE_IQ( i, q, sin_b, cos_b ) {\ float t;\ t = i * cos_b - q * sin_b;\ q = i * sin_b + q * cos_b;\ i = t;\ } static void init_filters( init_t* impl, sms_ntsc_setup_t const* setup ) { #if rescale_out > 1 float kernels [kernel_size * 2]; #else float* const kernels = impl->kernel; #endif /* generate luma (y) filter using sinc kernel */ { /* sinc with rolloff (dsf) */ float const rolloff = 1 + (float) setup->sharpness * (float) 0.032; float const maxh = 32; float const pow_a_n = (float) pow( rolloff, maxh ); float sum; int i; /* quadratic mapping to reduce negative (blurring) range */ float to_angle = (float) setup->resolution + 1; to_angle = PI / maxh * (float) LUMA_CUTOFF * (to_angle * to_angle + 1); kernels [kernel_size * 3 / 2] = maxh; /* default center value */ for ( i = 0; i < kernel_half * 2 + 1; i++ ) { int x = i - kernel_half; float angle = x * to_angle; /* instability occurs at center point with rolloff very close to 1.0 */ if ( x || pow_a_n > (float) 1.056 || pow_a_n < (float) 0.981 ) { float rolloff_cos_a = rolloff * (float) cos( angle ); float num = 1 - rolloff_cos_a - pow_a_n * (float) cos( maxh * angle ) + pow_a_n * rolloff * (float) cos( (maxh - 1) * angle ); float den = 1 - rolloff_cos_a - rolloff_cos_a + rolloff * rolloff; float dsf = num / den; kernels [kernel_size * 3 / 2 - kernel_half + i] = dsf - (float) 0.5; } } /* apply blackman window and find sum */ sum = 0; for ( i = 0; i < kernel_half * 2 + 1; i++ ) { float x = PI * 2 / (kernel_half * 2) * i; float blackman = 0.42f - 0.5f * (float) cos( x ) + 0.08f * (float) cos( x * 2 ); sum += (kernels [kernel_size * 3 / 2 - kernel_half + i] *= blackman); } /* normalize kernel */ sum = 1.0f / sum; for ( i = 0; i < kernel_half * 2 + 1; i++ ) { int x = kernel_size * 3 / 2 - kernel_half + i; kernels [x] *= sum; assert( kernels [x] == kernels [x] ); /* catch numerical instability */ } } /* generate chroma (iq) filter using gaussian kernel */ { float const cutoff_factor = -0.03125f; float cutoff = (float) setup->bleed; int i; if ( cutoff < 0 ) { /* keep extreme value accessible only near upper end of scale (1.0) */ cutoff *= cutoff; cutoff *= cutoff; cutoff *= cutoff; cutoff *= -30.0f / 0.65f; } cutoff = cutoff_factor - 0.65f * cutoff_factor * cutoff; for ( i = -kernel_half; i <= kernel_half; i++ ) kernels [kernel_size / 2 + i] = (float) exp( i * i * cutoff ); /* normalize even and odd phases separately */ for ( i = 0; i < 2; i++ ) { float sum = 0; int x; for ( x = i; x < kernel_size; x += 2 ) sum += kernels [x]; sum = 1.0f / sum; for ( x = i; x < kernel_size; x += 2 ) { kernels [x] *= sum; assert( kernels [x] == kernels [x] ); /* catch numerical instability */ } } } /* printf( "luma:\n" ); for ( i = kernel_size; i < kernel_size * 2; i++ ) printf( "%f\n", kernels [i] ); printf( "chroma:\n" ); for ( i = 0; i < kernel_size; i++ ) printf( "%f\n", kernels [i] ); */ /* generate linear rescale kernels */ #if rescale_out > 1 { float weight = 1.0f; float* out = impl->kernel; int n = rescale_out; do { float remain = 0; int i; weight -= 1.0f / rescale_in; for ( i = 0; i < kernel_size * 2; i++ ) { float cur = kernels [i]; float m = cur * weight; *out++ = m + remain; remain = cur - m; } } while ( --n ); } #endif } static float const default_decoder [6] = { 0.956f, 0.621f, -0.272f, -0.647f, -1.105f, 1.702f }; static void init( init_t* impl, sms_ntsc_setup_t const* setup ) { impl->brightness = (float) setup->brightness * (0.5f * rgb_unit) + rgb_offset; impl->contrast = (float) setup->contrast * (0.5f * rgb_unit) + rgb_unit; #ifdef default_palette_contrast if ( !setup->palette ) impl->contrast *= default_palette_contrast; #endif impl->artifacts = (float) setup->artifacts; if ( impl->artifacts > 0 ) impl->artifacts *= artifacts_max - artifacts_mid; impl->artifacts = impl->artifacts * artifacts_mid + artifacts_mid; impl->fringing = (float) setup->fringing; if ( impl->fringing > 0 ) impl->fringing *= fringing_max - fringing_mid; impl->fringing = impl->fringing * fringing_mid + fringing_mid; init_filters( impl, setup ); /* generate gamma table */ if ( gamma_size > 1 ) { float const to_float = 1.0f / (gamma_size - (gamma_size > 1)); float const gamma = 1.1333f - (float) setup->gamma * 0.5f; /* match common PC's 2.2 gamma to TV's 2.65 gamma */ int i; for ( i = 0; i < gamma_size; i++ ) impl->to_float [i] = (float) pow( i * to_float, gamma ) * impl->contrast + impl->brightness; } /* setup decoder matricies */ { float hue = (float) setup->hue * PI + PI / 180 * ext_decoder_hue; float sat = (float) setup->saturation + 1; float const* decoder = setup->decoder_matrix; if ( !decoder ) { decoder = default_decoder; if ( STD_HUE_CONDITION( setup ) ) hue += PI / 180 * (std_decoder_hue - ext_decoder_hue); } { float s = (float) sin( hue ) * sat; float c = (float) cos( hue ) * sat; float* out = impl->to_rgb; int n; n = burst_count; do { float const* in = decoder; int n = 3; do { float i = *in++; float q = *in++; *out++ = i * c - q * s; *out++ = i * s + q * c; } while ( --n ); if ( burst_count <= 1 ) break; ROTATE_IQ( s, c, 0.866025f, -0.5f ); /* +120 degrees */ } while ( --n ); } } } /* kernel generation */ #define RGB_TO_YIQ( r, g, b, y, i ) (\ (y = (r) * 0.299f + (g) * 0.587f + (b) * 0.114f),\ (i = (r) * 0.596f - (g) * 0.275f - (b) * 0.321f),\ ((r) * 0.212f - (g) * 0.523f + (b) * 0.311f)\ ) #define YIQ_TO_RGB( y, i, q, to_rgb, type, r, g ) (\ r = (type) (y + to_rgb [0] * i + to_rgb [1] * q),\ g = (type) (y + to_rgb [2] * i + to_rgb [3] * q),\ (type) (y + to_rgb [4] * i + to_rgb [5] * q)\ ) #define PACK_RGB( r, g, b ) ((r) << 21 | (g) << 11 | (b) << 1) enum { rgb_kernel_size = burst_size / alignment_count }; enum { rgb_bias = rgb_unit * 2 * sms_ntsc_rgb_builder }; typedef struct pixel_info_t { int offset; float negate; float kernel [4]; } pixel_info_t; #if rescale_in > 1 #define PIXEL_OFFSET_( ntsc, scaled ) \ (kernel_size / 2 + ntsc + (scaled != 0) + (rescale_out - scaled) % rescale_out + \ (kernel_size * 2 * scaled)) #define PIXEL_OFFSET( ntsc, scaled ) \ PIXEL_OFFSET_( ((ntsc) - (scaled) / rescale_out * rescale_in),\ (((scaled) + rescale_out * 10) % rescale_out) ),\ (1.0f - (((ntsc) + 100) & 2)) #else #define PIXEL_OFFSET( ntsc, scaled ) \ (kernel_size / 2 + (ntsc) - (scaled)),\ (1.0f - (((ntsc) + 100) & 2)) #endif extern pixel_info_t const sms_ntsc_pixels [alignment_count]; /* Generate pixel at all burst phases and column alignments */ static void gen_kernel( init_t* impl, float y, float i, float q, sms_ntsc_rgb_t* out ) { /* generate for each scanline burst phase */ float const* to_rgb = impl->to_rgb; int burst_remain = burst_count; y -= rgb_offset; do { /* Encode yiq into *two* composite signals (to allow control over artifacting). Convolve these with kernels which: filter respective components, apply sharpening, and rescale horizontally. Convert resulting yiq to rgb and pack into integer. Based on algorithm by NewRisingSun. */ pixel_info_t const* pixel = sms_ntsc_pixels; int alignment_remain = alignment_count; do { /* negate is -1 when composite starts at odd multiple of 2 */ float const yy = y * impl->fringing * pixel->negate; float const ic0 = (i + yy) * pixel->kernel [0]; float const qc1 = (q + yy) * pixel->kernel [1]; float const ic2 = (i - yy) * pixel->kernel [2]; float const qc3 = (q - yy) * pixel->kernel [3]; float const factor = impl->artifacts * pixel->negate; float const ii = i * factor; float const yc0 = (y + ii) * pixel->kernel [0]; float const yc2 = (y - ii) * pixel->kernel [2]; float const qq = q * factor; float const yc1 = (y + qq) * pixel->kernel [1]; float const yc3 = (y - qq) * pixel->kernel [3]; float const* k = &impl->kernel [pixel->offset]; int n; ++pixel; for ( n = rgb_kernel_size; n; --n ) { float i = k[0]*ic0 + k[2]*ic2; float q = k[1]*qc1 + k[3]*qc3; float y = k[kernel_size+0]*yc0 + k[kernel_size+1]*yc1 + k[kernel_size+2]*yc2 + k[kernel_size+3]*yc3 + rgb_offset; if ( rescale_out <= 1 ) k--; else if ( k < &impl->kernel [kernel_size * 2 * (rescale_out - 1)] ) k += kernel_size * 2 - 1; else k -= kernel_size * 2 * (rescale_out - 1) + 2; { int r, g, b = YIQ_TO_RGB( y, i, q, to_rgb, int, r, g ); *out++ = PACK_RGB( r, g, b ) - rgb_bias; } } } while ( alignment_count > 1 && --alignment_remain ); if ( burst_count <= 1 ) break; to_rgb += 6; ROTATE_IQ( i, q, -0.866025f, -0.5f ); /* -120 degrees */ } while ( --burst_remain ); } static void correct_errors( sms_ntsc_rgb_t color, sms_ntsc_rgb_t* out ); #if DISABLE_CORRECTION #define CORRECT_ERROR( a ) { out [i] += rgb_bias; } #define DISTRIBUTE_ERROR( a, b, c ) { out [i] += rgb_bias; } #else #define CORRECT_ERROR( a ) { out [a] += error; } #define DISTRIBUTE_ERROR( a, b, c ) {\ sms_ntsc_rgb_t fourth = (error + 2 * sms_ntsc_rgb_builder) >> 2;\ fourth &= (rgb_bias >> 1) - sms_ntsc_rgb_builder;\ fourth -= rgb_bias >> 2;\ out [a] += fourth;\ out [b] += fourth;\ out [c] += fourth;\ out [i] += error - (fourth * 3);\ } #endif #define RGB_PALETTE_OUT( rgb, out_ )\ {\ unsigned char* out = (out_);\ sms_ntsc_rgb_t clamped = (rgb);\ SMS_NTSC_CLAMP_( clamped, (8 - rgb_bits) );\ out [0] = (unsigned char) (clamped >> 21);\ out [1] = (unsigned char) (clamped >> 11);\ out [2] = (unsigned char) (clamped >> 1);\ } /* blitter related */ #ifndef restrict #if defined (__GNUC__) #define restrict __restrict__ #elif defined (_MSC_VER) && _MSC_VER > 1300 #define restrict __restrict #else /* no support for restricted pointers */ #define restrict #endif #endif #include <limits.h> #if SMS_NTSC_OUT_DEPTH <= 16 #if USHRT_MAX == 0xFFFF typedef unsigned short sms_ntsc_out_t; #else #error "Need 16-bit int type" #endif #else #if UINT_MAX == 0xFFFFFFFF typedef unsigned int sms_ntsc_out_t; #elif ULONG_MAX == 0xFFFFFFFF typedef unsigned long sms_ntsc_out_t; #else #error "Need 32-bit int type" #endif #endif
zyking1987-genplus-droid
genplusgx/ntsc/sms_ntsc_impl.h
C
gpl2
13,463
/* md_ntsc 0.1.2. http://www.slack.net/~ant/ */ /* Added a custom blitter to double the height md_ntsc_blit_y2 -- AamirM */ /* Added a custom blitter to work with Genesis Plus GX -- EkeEke*/ #include "../shared.h" #include "md_ntsc.h" /* Copyright (C) 2006 Shay Green. This module is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This module is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this module; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ md_ntsc_setup_t const md_ntsc_monochrome = { 0,-1, 0, 0,.2, 0, 0,-.2,-.2,-1, 0, 0 }; md_ntsc_setup_t const md_ntsc_composite = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; md_ntsc_setup_t const md_ntsc_svideo = { 0, 0, 0, 0, 0, 0,.2, -1, -1, 0, 0, 0 }; md_ntsc_setup_t const md_ntsc_rgb = { 0, 0, 0, 0,.2, 0,.7, -1, -1,-1, 0, 0 }; #define alignment_count 2 #define burst_count 1 #define rescale_in 1 #define rescale_out 1 #define artifacts_mid 0.40f #define fringing_mid 0.30f #define std_decoder_hue 0 #define gamma_size 8 #define artifacts_max 1.00f #define LUMA_CUTOFF 0.1974 #include "md_ntsc_impl.h" /* 2 input pixels -> 4 composite samples */ pixel_info_t const md_ntsc_pixels [alignment_count] = { { PIXEL_OFFSET( -4, -9 ), { 0.1f, 0.9f, 0.9f, 0.1f } }, { PIXEL_OFFSET( -2, -7 ), { 0.1f, 0.9f, 0.9f, 0.1f } }, }; static void correct_errors( md_ntsc_rgb_t color, md_ntsc_rgb_t* out ) { unsigned i; for ( i = 0; i < rgb_kernel_size / 4; i++ ) { md_ntsc_rgb_t error = color - out [i ] - out [i + 2 +16] - out [i + 4 ] - out [i + 6 +16] - out [i + 8] - out [(i+10)%16+16] - out [(i+12)%16] - out [(i+14)%16+16]; CORRECT_ERROR( i + 6 + 16 ); /*DISTRIBUTE_ERROR( 2+16, 4, 6+16 );*/ } } void md_ntsc_init( md_ntsc_t* ntsc, md_ntsc_setup_t const* setup ) { int entry; init_t impl; if ( !setup ) setup = &md_ntsc_composite; init( &impl, setup ); for ( entry = 0; entry < md_ntsc_palette_size; entry++ ) { float bb = impl.to_float [entry >> 6 & 7]; float gg = impl.to_float [entry >> 3 & 7]; float rr = impl.to_float [entry & 7]; float y, i, q = RGB_TO_YIQ( rr, gg, bb, y, i ); int r, g, b = YIQ_TO_RGB( y, i, q, impl.to_rgb, int, r, g ); md_ntsc_rgb_t rgb = PACK_RGB( r, g, b ); if ( setup->palette_out ) RGB_PALETTE_OUT( rgb, &setup->palette_out [entry * 3] ); if ( ntsc ) { gen_kernel( &impl, y, i, q, ntsc->table [entry] ); correct_errors( rgb, ntsc->table [entry] ); } } } #ifndef MD_NTSC_NO_BLITTERS /* modified blitters to work on a line basis with genesis plus renderer*/ void md_ntsc_blit( md_ntsc_t const* ntsc, MD_NTSC_IN_T const* table, unsigned char* input, int in_width, int vline) { int const chunk_count = in_width / md_ntsc_in_chunk - 1; MD_NTSC_IN_T border = table[0]; MD_NTSC_BEGIN_ROW( ntsc, border, MD_NTSC_ADJ_IN( table[*input++] ), MD_NTSC_ADJ_IN( table[*input++] ), MD_NTSC_ADJ_IN( table[*input++] ) ); #ifdef NGC /* directly fill the RGB565 texture */ /* one tile is 32 byte = 4x4 pixels */ /* tiles are stored continuously in texture memory */ in_width = MD_NTSC_OUT_WIDTH(in_width) >> 2; int offset = ((in_width << 5) * (vline >> 2)) + ((vline & 3) * 8); md_ntsc_out_t* restrict line_out = (md_ntsc_out_t*)(texturemem + offset); #else md_ntsc_out_t* restrict line_out = (md_ntsc_out_t*)(&bitmap.data[(vline * bitmap.pitch)]); #endif int n; for ( n = chunk_count; n; --n ) { /* order of input and output pixels must not be altered */ MD_NTSC_COLOR_IN( 0, ntsc, MD_NTSC_ADJ_IN( table[*input++] ) ); MD_NTSC_RGB_OUT( 0, *line_out++, MD_NTSC_OUT_DEPTH ); MD_NTSC_RGB_OUT( 1, *line_out++, MD_NTSC_OUT_DEPTH ); MD_NTSC_COLOR_IN( 1, ntsc, MD_NTSC_ADJ_IN( table[*input++] ) ); MD_NTSC_RGB_OUT( 2, *line_out++, MD_NTSC_OUT_DEPTH ); MD_NTSC_RGB_OUT( 3, *line_out++, MD_NTSC_OUT_DEPTH ); #ifdef NGC line_out += 12; #endif MD_NTSC_COLOR_IN( 2, ntsc, MD_NTSC_ADJ_IN( table[*input++] ) ); MD_NTSC_RGB_OUT( 4, *line_out++, MD_NTSC_OUT_DEPTH ); MD_NTSC_RGB_OUT( 5, *line_out++, MD_NTSC_OUT_DEPTH ); MD_NTSC_COLOR_IN( 3, ntsc, MD_NTSC_ADJ_IN( table[*input++] ) ); MD_NTSC_RGB_OUT( 6, *line_out++, MD_NTSC_OUT_DEPTH ); MD_NTSC_RGB_OUT( 7, *line_out++, MD_NTSC_OUT_DEPTH ); #ifdef NGC line_out += 12; #endif } /* finish final pixels */ MD_NTSC_COLOR_IN( 0, ntsc, MD_NTSC_ADJ_IN( table[*input++] ) ); MD_NTSC_RGB_OUT( 0, *line_out++, MD_NTSC_OUT_DEPTH ); MD_NTSC_RGB_OUT( 1, *line_out++, MD_NTSC_OUT_DEPTH ); MD_NTSC_COLOR_IN( 1, ntsc, border ); MD_NTSC_RGB_OUT( 2, *line_out++, MD_NTSC_OUT_DEPTH ); MD_NTSC_RGB_OUT( 3, *line_out++, MD_NTSC_OUT_DEPTH ); #ifdef NGC line_out += 12; #endif MD_NTSC_COLOR_IN( 2, ntsc, border ); MD_NTSC_RGB_OUT( 4, *line_out++, MD_NTSC_OUT_DEPTH ); MD_NTSC_RGB_OUT( 5, *line_out++, MD_NTSC_OUT_DEPTH ); MD_NTSC_COLOR_IN( 3, ntsc, border ); MD_NTSC_RGB_OUT( 6, *line_out++, MD_NTSC_OUT_DEPTH ); MD_NTSC_RGB_OUT( 7, *line_out++, MD_NTSC_OUT_DEPTH ); } #endif
zyking1987-genplus-droid
genplusgx/ntsc/md_ntsc.c
C
gpl2
5,796
/* Sega Genesis/Mega Drive NTSC video filter */ /* md_ntsc 0.1.2 */ #ifndef MD_NTSC_H #define MD_NTSC_H #include "md_ntsc_config.h" #ifdef __cplusplus extern "C" { #endif /* Image parameters, ranging from -1.0 to 1.0. Actual internal values shown in parenthesis and should remain fairly stable in future versions. */ typedef struct md_ntsc_setup_t { /* Basic parameters */ double hue; /* -1 = -180 degrees +1 = +180 degrees */ double saturation; /* -1 = grayscale (0.0) +1 = oversaturated colors (2.0) */ double contrast; /* -1 = dark (0.5) +1 = light (1.5) */ double brightness; /* -1 = dark (0.5) +1 = light (1.5) */ double sharpness; /* edge contrast enhancement/blurring */ /* Advanced parameters */ double gamma; /* -1 = dark (1.5) +1 = light (0.5) */ double resolution; /* image resolution */ double artifacts; /* artifacts caused by color changes */ double fringing; /* color artifacts caused by brightness changes */ double bleed; /* color bleed (color resolution reduction) */ float const* decoder_matrix; /* optional RGB decoder matrix, 6 elements */ unsigned char* palette_out; /* optional RGB palette out, 3 bytes per color */ } md_ntsc_setup_t; /* Video format presets */ extern md_ntsc_setup_t const md_ntsc_composite; /* color bleeding + artifacts */ extern md_ntsc_setup_t const md_ntsc_svideo; /* color bleeding only */ extern md_ntsc_setup_t const md_ntsc_rgb; /* crisp image */ extern md_ntsc_setup_t const md_ntsc_monochrome;/* desaturated + artifacts */ enum { md_ntsc_palette_size = 512 }; /* Initializes and adjusts parameters. Can be called multiple times on the same md_ntsc_t object. Can pass NULL for either parameter. */ typedef struct md_ntsc_t md_ntsc_t; void md_ntsc_init( md_ntsc_t* ntsc, md_ntsc_setup_t const* setup ); /* Filters one or more rows of pixels. Input pixel format is set by MD_NTSC_IN_FORMAT and output RGB depth is set by MD_NTSC_OUT_DEPTH. Both default to 16-bit RGB. In_row_width is the number of pixels to get to the next input row. Out_pitch is the number of *bytes* to get to the next output row. */ void md_ntsc_blit( md_ntsc_t const* ntsc, MD_NTSC_IN_T const* table, unsigned char* input, int in_width, int vline); /* Number of output pixels written by blitter for given input width. */ #define MD_NTSC_OUT_WIDTH( in_width ) \ (((in_width) - 3) / md_ntsc_in_chunk * md_ntsc_out_chunk + md_ntsc_out_chunk) /* Number of input pixels that will fit within given output width. Might be rounded down slightly; use MD_NTSC_OUT_WIDTH() on result to find rounded value. */ #define MD_NTSC_IN_WIDTH( out_width ) \ ((out_width) / md_ntsc_out_chunk * md_ntsc_in_chunk - md_ntsc_in_chunk + 3) /* Interface for user-defined custom blitters */ enum { md_ntsc_in_chunk = 4 }; /* number of input pixels read per chunk */ enum { md_ntsc_out_chunk = 8 }; /* number of output pixels generated per chunk */ enum { md_ntsc_black = 0 }; /* palette index for black */ /* Begin outputting row and start three pixels. First pixel will be cut off a bit. Use md_ntsc_black for unused pixels. Declares variables, so must be before first statement in a block (unless you're using C++). */ #define MD_NTSC_BEGIN_ROW( ntsc, pixel0, pixel1, pixel2, pixel3 ) \ unsigned const md_pixel0_ = (pixel0);\ md_ntsc_rgb_t const* kernel0 = MD_NTSC_IN_FORMAT( ntsc, md_pixel0_ );\ unsigned const md_pixel1_ = (pixel1);\ md_ntsc_rgb_t const* kernel1 = MD_NTSC_IN_FORMAT( ntsc, md_pixel1_ );\ unsigned const md_pixel2_ = (pixel2);\ md_ntsc_rgb_t const* kernel2 = MD_NTSC_IN_FORMAT( ntsc, md_pixel2_ );\ unsigned const md_pixel3_ = (pixel3);\ md_ntsc_rgb_t const* kernel3 = MD_NTSC_IN_FORMAT( ntsc, md_pixel3_ );\ md_ntsc_rgb_t const* kernelx0;\ md_ntsc_rgb_t const* kernelx1 = kernel0;\ md_ntsc_rgb_t const* kernelx2 = kernel0;\ md_ntsc_rgb_t const* kernelx3 = kernel0 /* Begin input pixel */ #define MD_NTSC_COLOR_IN( index, ntsc, color ) \ MD_NTSC_COLOR_IN_( index, color, MD_NTSC_IN_FORMAT, ntsc ) /* Generate output pixel. Bits can be 24, 16, 15, 32 (treated as 24), or 0: 24: RRRRRRRR GGGGGGGG BBBBBBBB 16: RRRRRGGG GGGBBBBB 15: RRRRRGG GGGBBBBB 0: xxxRRRRR RRRxxGGG GGGGGxxB BBBBBBBx (native internal format; x = junk bits) */ #define MD_NTSC_RGB_OUT( x, rgb_out, bits ) {\ md_ntsc_rgb_t raw_ =\ kernel0 [x+ 0] + kernel1 [(x+6)%8+16] + kernel2 [(x+4)%8 ] + kernel3 [(x+2)%8+16] +\ kernelx0 [x+ 8] + kernelx1 [(x+6)%8+24] + kernelx2 [(x+4)%8+8] + kernelx3 [(x+2)%8+24];\ MD_NTSC_CLAMP_( raw_, 0 );\ MD_NTSC_RGB_OUT_( rgb_out, bits, 0 );\ } /* private */ enum { md_ntsc_entry_size = 2 * 16 }; typedef unsigned long md_ntsc_rgb_t; struct md_ntsc_t { md_ntsc_rgb_t table [md_ntsc_palette_size] [md_ntsc_entry_size]; }; #define MD_NTSC_BGR9( ntsc, n ) (ntsc)->table [n & 0x1FF] #define MD_NTSC_RGB16( ntsc, n ) \ (md_ntsc_rgb_t*) ((char*) (ntsc)->table +\ ((n << 9 & 0x3800) | (n & 0x0700) | (n >> 8 & 0x00E0)) *\ (md_ntsc_entry_size * sizeof (md_ntsc_rgb_t) / 32)) /* common ntsc macros */ #define md_ntsc_rgb_builder ((1L << 21) | (1 << 11) | (1 << 1)) #define md_ntsc_clamp_mask (md_ntsc_rgb_builder * 3 / 2) #define md_ntsc_clamp_add (md_ntsc_rgb_builder * 0x101) #define MD_NTSC_CLAMP_( io, shift ) {\ md_ntsc_rgb_t sub = (io) >> (9-(shift)) & md_ntsc_clamp_mask;\ md_ntsc_rgb_t clamp = md_ntsc_clamp_add - sub;\ io |= clamp;\ clamp -= sub;\ io &= clamp;\ } #define MD_NTSC_COLOR_IN_( index, color, ENTRY, table ) {\ unsigned color_;\ kernelx##index = kernel##index;\ kernel##index = (color_ = (color), ENTRY( table, color_ ));\ } /* x is always zero except in snes_ntsc library */ #define MD_NTSC_RGB_OUT_( rgb_out, bits, x ) {\ rgb_out = (raw_>>(13-x)& 0xF800)|(raw_>>(8-x)&0x07E0)|(raw_>>(4-x)&0x001F);\ } #ifdef __cplusplus } #endif #endif
zyking1987-genplus-droid
genplusgx/ntsc/md_ntsc.h
C
gpl2
6,044
/* Configure library by modifying this file */ #ifndef SMS_NTSC_CONFIG_H #define SMS_NTSC_CONFIG_H /* Format of source pixels */ #define SMS_NTSC_IN_FORMAT SMS_NTSC_RGB16 /* #define SMS_NTSC_IN_FORMAT SMS_NTSC_RGB15 */ /* #define SMS_NTSC_IN_FORMAT SMS_NTSC_BGR12 */ /* The following affect the built-in blitter only; a custom blitter can handle things however it wants. */ /* Bits per pixel of output. Can be 15, 16, 32, or 24 (same as 32). */ #define SMS_NTSC_OUT_DEPTH 16 /* Type of input pixel values */ #define SMS_NTSC_IN_T unsigned short /* Each raw pixel input value is passed through this. You might want to mask the pixel index if you use the high bits as flags, etc. */ #define SMS_NTSC_ADJ_IN( in ) in /* For each pixel, this is the basic operation: output_color = SMS_NTSC_ADJ_IN( SMS_NTSC_IN_T ) */ #endif
zyking1987-genplus-droid
genplusgx/ntsc/sms_ntsc_config.h
C
gpl2
855
/* Configure library by modifying this file */ #ifndef MD_NTSC_CONFIG_H #define MD_NTSC_CONFIG_H /* Format of source pixels */ #define MD_NTSC_IN_FORMAT MD_NTSC_RGB16 //#define MD_NTSC_IN_FORMAT MD_NTSC_BGR9 /* The following affect the built-in blitter only; a custom blitter can handle things however it wants. */ /* Bits per pixel of output. Can be 15, 16, 32, or 24 (same as 32). */ #define MD_NTSC_OUT_DEPTH 16 /* Type of input pixel values */ #define MD_NTSC_IN_T unsigned short /* Each raw pixel input value is passed through this. You might want to mask the pixel index if you use the high bits as flags, etc. */ #define MD_NTSC_ADJ_IN( in ) in /* For each pixel, this is the basic operation: output_color = MD_NTSC_ADJ_IN( MD_NTSC_IN_T ) */ #endif
zyking1987-genplus-droid
genplusgx/ntsc/md_ntsc_config.h
C
gpl2
790
/* md_ntsc 0.1.2. http://www.slack.net/~ant/ */ /* Common implementation of NTSC filters */ #include <assert.h> #include <math.h> /* Copyright (C) 2006-2007 Shay Green. This module is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This module is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this module; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define DISABLE_CORRECTION 0 #undef PI #define PI 3.14159265358979323846f #ifndef LUMA_CUTOFF #define LUMA_CUTOFF 0.20 #endif #ifndef gamma_size #define gamma_size 1 #endif #ifndef rgb_bits #define rgb_bits 8 #endif #ifndef artifacts_max #define artifacts_max (artifacts_mid * 1.5f) #endif #ifndef fringing_max #define fringing_max (fringing_mid * 2) #endif #ifndef STD_HUE_CONDITION #define STD_HUE_CONDITION( setup ) 1 #endif #define ext_decoder_hue (std_decoder_hue + 15) #define rgb_unit (1 << rgb_bits) #define rgb_offset (rgb_unit * 2 + 0.5f) enum { burst_size = md_ntsc_entry_size / burst_count }; enum { kernel_half = 16 }; enum { kernel_size = kernel_half * 2 + 1 }; typedef struct init_t { float to_rgb [burst_count * 6]; float to_float [gamma_size]; float contrast; float brightness; float artifacts; float fringing; float kernel [rescale_out * kernel_size * 2]; } init_t; #define ROTATE_IQ( i, q, sin_b, cos_b ) {\ float t;\ t = i * cos_b - q * sin_b;\ q = i * sin_b + q * cos_b;\ i = t;\ } static void init_filters( init_t* impl, md_ntsc_setup_t const* setup ) { #if rescale_out > 1 float kernels [kernel_size * 2]; #else float* const kernels = impl->kernel; #endif /* generate luma (y) filter using sinc kernel */ { /* sinc with rolloff (dsf) */ float const rolloff = 1 + (float) setup->sharpness * (float) 0.032; float const maxh = 32; float const pow_a_n = (float) pow( rolloff, maxh ); float sum; int i; /* quadratic mapping to reduce negative (blurring) range */ float to_angle = (float) setup->resolution + 1; to_angle = PI / maxh * (float) LUMA_CUTOFF * (to_angle * to_angle + 1); kernels [kernel_size * 3 / 2] = maxh; /* default center value */ for ( i = 0; i < kernel_half * 2 + 1; i++ ) { int x = i - kernel_half; float angle = x * to_angle; /* instability occurs at center point with rolloff very close to 1.0 */ if ( x || pow_a_n > (float) 1.056 || pow_a_n < (float) 0.981 ) { float rolloff_cos_a = rolloff * (float) cos( angle ); float num = 1 - rolloff_cos_a - pow_a_n * (float) cos( maxh * angle ) + pow_a_n * rolloff * (float) cos( (maxh - 1) * angle ); float den = 1 - rolloff_cos_a - rolloff_cos_a + rolloff * rolloff; float dsf = num / den; kernels [kernel_size * 3 / 2 - kernel_half + i] = dsf - (float) 0.5; } } /* apply blackman window and find sum */ sum = 0; for ( i = 0; i < kernel_half * 2 + 1; i++ ) { float x = PI * 2 / (kernel_half * 2) * i; float blackman = 0.42f - 0.5f * (float) cos( x ) + 0.08f * (float) cos( x * 2 ); sum += (kernels [kernel_size * 3 / 2 - kernel_half + i] *= blackman); } /* normalize kernel */ sum = 1.0f / sum; for ( i = 0; i < kernel_half * 2 + 1; i++ ) { int x = kernel_size * 3 / 2 - kernel_half + i; kernels [x] *= sum; assert( kernels [x] == kernels [x] ); /* catch numerical instability */ } } /* generate chroma (iq) filter using gaussian kernel */ { float const cutoff_factor = -0.03125f; float cutoff = (float) setup->bleed; int i; if ( cutoff < 0 ) { /* keep extreme value accessible only near upper end of scale (1.0) */ cutoff *= cutoff; cutoff *= cutoff; cutoff *= cutoff; cutoff *= -30.0f / 0.65f; } cutoff = cutoff_factor - 0.65f * cutoff_factor * cutoff; for ( i = -kernel_half; i <= kernel_half; i++ ) kernels [kernel_size / 2 + i] = (float) exp( i * i * cutoff ); /* normalize even and odd phases separately */ for ( i = 0; i < 2; i++ ) { float sum = 0; int x; for ( x = i; x < kernel_size; x += 2 ) sum += kernels [x]; sum = 1.0f / sum; for ( x = i; x < kernel_size; x += 2 ) { kernels [x] *= sum; assert( kernels [x] == kernels [x] ); /* catch numerical instability */ } } } /* printf( "luma:\n" ); for ( i = kernel_size; i < kernel_size * 2; i++ ) printf( "%f\n", kernels [i] ); printf( "chroma:\n" ); for ( i = 0; i < kernel_size; i++ ) printf( "%f\n", kernels [i] ); */ /* generate linear rescale kernels */ #if rescale_out > 1 { float weight = 1.0f; float* out = impl->kernel; int n = rescale_out; do { float remain = 0; int i; weight -= 1.0f / rescale_in; for ( i = 0; i < kernel_size * 2; i++ ) { float cur = kernels [i]; float m = cur * weight; *out++ = m + remain; remain = cur - m; } } while ( --n ); } #endif } static float const default_decoder [6] = { 0.956f, 0.621f, -0.272f, -0.647f, -1.105f, 1.702f }; static void init( init_t* impl, md_ntsc_setup_t const* setup ) { impl->brightness = (float) setup->brightness * (0.5f * rgb_unit) + rgb_offset; impl->contrast = (float) setup->contrast * (0.5f * rgb_unit) + rgb_unit; #ifdef default_palette_contrast if ( !setup->palette ) impl->contrast *= default_palette_contrast; #endif impl->artifacts = (float) setup->artifacts; if ( impl->artifacts > 0 ) impl->artifacts *= artifacts_max - artifacts_mid; impl->artifacts = impl->artifacts * artifacts_mid + artifacts_mid; impl->fringing = (float) setup->fringing; if ( impl->fringing > 0 ) impl->fringing *= fringing_max - fringing_mid; impl->fringing = impl->fringing * fringing_mid + fringing_mid; init_filters( impl, setup ); /* generate gamma table */ if ( gamma_size > 1 ) { float const to_float = 1.0f / (gamma_size - (gamma_size > 1)); float const gamma = 1.1333f - (float) setup->gamma * 0.5f; /* match common PC's 2.2 gamma to TV's 2.65 gamma */ int i; for ( i = 0; i < gamma_size; i++ ) impl->to_float [i] = (float) pow( i * to_float, gamma ) * impl->contrast + impl->brightness; } /* setup decoder matricies */ { float hue = (float) setup->hue * PI + PI / 180 * ext_decoder_hue; float sat = (float) setup->saturation + 1; float const* decoder = setup->decoder_matrix; if ( !decoder ) { decoder = default_decoder; if ( STD_HUE_CONDITION( setup ) ) hue += PI / 180 * (std_decoder_hue - ext_decoder_hue); } { float s = (float) sin( hue ) * sat; float c = (float) cos( hue ) * sat; float* out = impl->to_rgb; int n; n = burst_count; do { float const* in = decoder; int n = 3; do { float i = *in++; float q = *in++; *out++ = i * c - q * s; *out++ = i * s + q * c; } while ( --n ); if ( burst_count <= 1 ) break; ROTATE_IQ( s, c, 0.866025f, -0.5f ); /* +120 degrees */ } while ( --n ); } } } /* kernel generation */ #define RGB_TO_YIQ( r, g, b, y, i ) (\ (y = (r) * 0.299f + (g) * 0.587f + (b) * 0.114f),\ (i = (r) * 0.596f - (g) * 0.275f - (b) * 0.321f),\ ((r) * 0.212f - (g) * 0.523f + (b) * 0.311f)\ ) #define YIQ_TO_RGB( y, i, q, to_rgb, type, r, g ) (\ r = (type) (y + to_rgb [0] * i + to_rgb [1] * q),\ g = (type) (y + to_rgb [2] * i + to_rgb [3] * q),\ (type) (y + to_rgb [4] * i + to_rgb [5] * q)\ ) #define PACK_RGB( r, g, b ) ((r) << 21 | (g) << 11 | (b) << 1) enum { rgb_kernel_size = burst_size / alignment_count }; enum { rgb_bias = rgb_unit * 2 * md_ntsc_rgb_builder }; typedef struct pixel_info_t { int offset; float negate; float kernel [4]; } pixel_info_t; #if rescale_in > 1 #define PIXEL_OFFSET_( ntsc, scaled ) \ (kernel_size / 2 + ntsc + (scaled != 0) + (rescale_out - scaled) % rescale_out + \ (kernel_size * 2 * scaled)) #define PIXEL_OFFSET( ntsc, scaled ) \ PIXEL_OFFSET_( ((ntsc) - (scaled) / rescale_out * rescale_in),\ (((scaled) + rescale_out * 10) % rescale_out) ),\ (1.0f - (((ntsc) + 100) & 2)) #else #define PIXEL_OFFSET( ntsc, scaled ) \ (kernel_size / 2 + (ntsc) - (scaled)),\ (1.0f - (((ntsc) + 100) & 2)) #endif extern pixel_info_t const md_ntsc_pixels [alignment_count]; /* Generate pixel at all burst phases and column alignments */ static void gen_kernel( init_t* impl, float y, float i, float q, md_ntsc_rgb_t* out ) { /* generate for each scanline burst phase */ float const* to_rgb = impl->to_rgb; int burst_remain = burst_count; y -= rgb_offset; do { /* Encode yiq into *two* composite signals (to allow control over artifacting). Convolve these with kernels which: filter respective components, apply sharpening, and rescale horizontally. Convert resulting yiq to rgb and pack into integer. Based on algorithm by NewRisingSun. */ pixel_info_t const* pixel = md_ntsc_pixels; int alignment_remain = alignment_count; do { /* negate is -1 when composite starts at odd multiple of 2 */ float const yy = y * impl->fringing * pixel->negate; float const ic0 = (i + yy) * pixel->kernel [0]; float const qc1 = (q + yy) * pixel->kernel [1]; float const ic2 = (i - yy) * pixel->kernel [2]; float const qc3 = (q - yy) * pixel->kernel [3]; float const factor = impl->artifacts * pixel->negate; float const ii = i * factor; float const yc0 = (y + ii) * pixel->kernel [0]; float const yc2 = (y - ii) * pixel->kernel [2]; float const qq = q * factor; float const yc1 = (y + qq) * pixel->kernel [1]; float const yc3 = (y - qq) * pixel->kernel [3]; float const* k = &impl->kernel [pixel->offset]; int n; ++pixel; for ( n = rgb_kernel_size; n; --n ) { float i = k[0]*ic0 + k[2]*ic2; float q = k[1]*qc1 + k[3]*qc3; float y = k[kernel_size+0]*yc0 + k[kernel_size+1]*yc1 + k[kernel_size+2]*yc2 + k[kernel_size+3]*yc3 + rgb_offset; if ( rescale_out <= 1 ) k--; else if ( k < &impl->kernel [kernel_size * 2 * (rescale_out - 1)] ) k += kernel_size * 2 - 1; else k -= kernel_size * 2 * (rescale_out - 1) + 2; { int r, g, b = YIQ_TO_RGB( y, i, q, to_rgb, int, r, g ); *out++ = PACK_RGB( r, g, b ) - rgb_bias; } } } while ( alignment_count > 1 && --alignment_remain ); if ( burst_count <= 1 ) break; to_rgb += 6; ROTATE_IQ( i, q, -0.866025f, -0.5f ); /* -120 degrees */ } while ( --burst_remain ); } static void correct_errors( md_ntsc_rgb_t color, md_ntsc_rgb_t* out ); #if DISABLE_CORRECTION #define CORRECT_ERROR( a ) { out [i] += rgb_bias; } #define DISTRIBUTE_ERROR( a, b, c ) { out [i] += rgb_bias; } #else #define CORRECT_ERROR( a ) { out [a] += error; } #define DISTRIBUTE_ERROR( a, b, c ) {\ md_ntsc_rgb_t fourth = (error + 2 * md_ntsc_rgb_builder) >> 2;\ fourth &= (rgb_bias >> 1) - md_ntsc_rgb_builder;\ fourth -= rgb_bias >> 2;\ out [a] += fourth;\ out [b] += fourth;\ out [c] += fourth;\ out [i] += error - (fourth * 3);\ } #endif #define RGB_PALETTE_OUT( rgb, out_ )\ {\ unsigned char* out = (out_);\ md_ntsc_rgb_t clamped = (rgb);\ MD_NTSC_CLAMP_( clamped, (8 - rgb_bits) );\ out [0] = (unsigned char) (clamped >> 21);\ out [1] = (unsigned char) (clamped >> 11);\ out [2] = (unsigned char) (clamped >> 1);\ } /* blitter related */ #ifndef restrict #if defined (__GNUC__) #define restrict __restrict__ #elif defined (_MSC_VER) && _MSC_VER > 1300 #define restrict #else /* no support for restricted pointers */ #define restrict #endif #endif #include <limits.h> #if MD_NTSC_OUT_DEPTH <= 16 #if USHRT_MAX == 0xFFFF typedef unsigned short md_ntsc_out_t; #else #error "Need 16-bit int type" #endif #else #if UINT_MAX == 0xFFFFFFFF typedef unsigned int md_ntsc_out_t; #elif ULONG_MAX == 0xFFFFFFFF typedef unsigned long md_ntsc_out_t; #else #error "Need 32-bit int type" #endif #endif
zyking1987-genplus-droid
genplusgx/ntsc/md_ntsc_impl.h
C
gpl2
13,356
/* sms_ntsc 0.2.3. http://www.slack.net/~ant/ */ #include "../shared.h" #include "sms_ntsc.h" /* Copyright (C) 2006-2007 Shay Green. This module is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This module is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this module; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* Added a custom blitter to work with Genesis Plus GX -- EkeEke*/ sms_ntsc_setup_t const sms_ntsc_monochrome = { 0,-1, 0, 0,.2, 0, .2,-.2,-.2,-1, 0, 0 }; sms_ntsc_setup_t const sms_ntsc_composite = { 0, 0, 0, 0, 0, 0,.25, 0, 0, 0, 0, 0 }; sms_ntsc_setup_t const sms_ntsc_svideo = { 0, 0, 0, 0, 0, 0,.25, -1, -1, 0, 0, 0 }; sms_ntsc_setup_t const sms_ntsc_rgb = { 0, 0, 0, 0,.2, 0,.70, -1, -1,-1, 0, 0 }; #define alignment_count 3 #define burst_count 1 #define rescale_in 8 #define rescale_out 7 #define artifacts_mid 0.4f #define artifacts_max 1.2f #define fringing_mid 0.8f #define std_decoder_hue 0 #define gamma_size 16 #include "sms_ntsc_impl.h" /* 3 input pixels -> 8 composite samples */ pixel_info_t const sms_ntsc_pixels [alignment_count] = { { PIXEL_OFFSET( -4, -9 ), { 1, 1, .6667f, 0 } }, { PIXEL_OFFSET( -2, -7 ), { .3333f, 1, 1, .3333f } }, { PIXEL_OFFSET( 0, -5 ), { 0, .6667f, 1, 1 } }, }; static void correct_errors( sms_ntsc_rgb_t color, sms_ntsc_rgb_t* out ) { unsigned i; for ( i = 0; i < rgb_kernel_size / 2; i++ ) { sms_ntsc_rgb_t error = color - out [i ] - out [(i+12)%14+14] - out [(i+10)%14+28] - out [i + 7] - out [i + 5 +14] - out [i + 3 +28]; CORRECT_ERROR( i + 3 + 28 ); } } void sms_ntsc_init( sms_ntsc_t* ntsc, sms_ntsc_setup_t const* setup ) { int entry; init_t impl; if ( !setup ) setup = &sms_ntsc_composite; init( &impl, setup ); for ( entry = 0; entry < sms_ntsc_palette_size; entry++ ) { float bb = impl.to_float [entry >> 8 & 0x0F]; float gg = impl.to_float [entry >> 4 & 0x0F]; float rr = impl.to_float [entry & 0x0F]; float y, i, q = RGB_TO_YIQ( rr, gg, bb, y, i ); int r, g, b = YIQ_TO_RGB( y, i, q, impl.to_rgb, int, r, g ); sms_ntsc_rgb_t rgb = PACK_RGB( r, g, b ); if ( setup->palette_out ) RGB_PALETTE_OUT( rgb, &setup->palette_out [entry * 3] ); if ( ntsc ) { gen_kernel( &impl, y, i, q, ntsc->table [entry] ); correct_errors( rgb, ntsc->table [entry] ); } } } #ifndef SMS_NTSC_NO_BLITTERS /* modified blitters to work on a line basis with genesis plus renderer*/ void sms_ntsc_blit( sms_ntsc_t const* ntsc, SMS_NTSC_IN_T const* table, unsigned char* input, int in_width, int vline) { int const chunk_count = in_width / sms_ntsc_in_chunk; /* handle extra 0, 1, or 2 pixels by placing them at beginning of row */ int const in_extra = in_width - chunk_count * sms_ntsc_in_chunk; unsigned const extra2 = (unsigned) -(in_extra >> 1 & 1); /* (unsigned) -1 = ~0 */ unsigned const extra1 = (unsigned) -(in_extra & 1) | extra2; SMS_NTSC_IN_T border = table[0]; SMS_NTSC_BEGIN_ROW( ntsc, border, (SMS_NTSC_ADJ_IN( table[input[0]] )) & extra2, (SMS_NTSC_ADJ_IN( table[input[extra2 & 1]] )) & extra1 ); #ifdef NGC /* directly fill the RGB565 texture */ /* one tile is 32 byte = 4x4 pixels */ /* tiles are stored continuously in texture memory */ in_width = SMS_NTSC_OUT_WIDTH(in_width) / 4; int offset = ((in_width * 32) * (vline / 4)) + ((vline & 3) * 8); sms_ntsc_out_t* restrict line_out = (sms_ntsc_out_t*)(texturemem + offset); offset = 0; #else sms_ntsc_out_t* restrict line_out = (sms_ntsc_out_t*)(&bitmap.data[(vline * bitmap.pitch)]); #endif int n; input += in_extra; for ( n = chunk_count; n; --n ) { /* order of input and output pixels must not be altered */ SMS_NTSC_COLOR_IN( 0, ntsc, SMS_NTSC_ADJ_IN( table[*input++] ) ); #ifdef NGC SMS_NTSC_RGB_OUT( 0, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; SMS_NTSC_RGB_OUT( 1, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; #else SMS_NTSC_RGB_OUT( 0, *line_out++, SMS_NTSC_OUT_DEPTH ); SMS_NTSC_RGB_OUT( 1, *line_out++, SMS_NTSC_OUT_DEPTH ); #endif SMS_NTSC_COLOR_IN( 1, ntsc, SMS_NTSC_ADJ_IN( table[*input++] ) ); #ifdef NGC SMS_NTSC_RGB_OUT( 2, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; SMS_NTSC_RGB_OUT( 3, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; #else SMS_NTSC_RGB_OUT( 2, *line_out++, SMS_NTSC_OUT_DEPTH ); SMS_NTSC_RGB_OUT( 3, *line_out++, SMS_NTSC_OUT_DEPTH ); #endif SMS_NTSC_COLOR_IN( 2, ntsc, SMS_NTSC_ADJ_IN( table[*input++] ) ); #ifdef NGC SMS_NTSC_RGB_OUT( 4, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; SMS_NTSC_RGB_OUT( 5, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; SMS_NTSC_RGB_OUT( 6, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; #else SMS_NTSC_RGB_OUT( 4, *line_out++, SMS_NTSC_OUT_DEPTH ); SMS_NTSC_RGB_OUT( 5, *line_out++, SMS_NTSC_OUT_DEPTH ); SMS_NTSC_RGB_OUT( 6, *line_out++, SMS_NTSC_OUT_DEPTH ); #endif } /* finish final pixels */ SMS_NTSC_COLOR_IN( 0, ntsc, border ); #ifdef NGC SMS_NTSC_RGB_OUT( 0, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; SMS_NTSC_RGB_OUT( 1, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; #else SMS_NTSC_RGB_OUT( 0, *line_out++, SMS_NTSC_OUT_DEPTH ); SMS_NTSC_RGB_OUT( 1, *line_out++, SMS_NTSC_OUT_DEPTH ); #endif SMS_NTSC_COLOR_IN( 1, ntsc, border ); #ifdef NGC SMS_NTSC_RGB_OUT( 2, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; SMS_NTSC_RGB_OUT( 3, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; #else SMS_NTSC_RGB_OUT( 2, *line_out++, SMS_NTSC_OUT_DEPTH ); SMS_NTSC_RGB_OUT( 3, *line_out++, SMS_NTSC_OUT_DEPTH ); #endif SMS_NTSC_COLOR_IN( 2, ntsc, border ); #ifdef NGC SMS_NTSC_RGB_OUT( 4, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; SMS_NTSC_RGB_OUT( 5, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; SMS_NTSC_RGB_OUT( 6, line_out[offset++], SMS_NTSC_OUT_DEPTH ); if ((offset % 4) == 0) offset += 12; #else SMS_NTSC_RGB_OUT( 4, *line_out++, SMS_NTSC_OUT_DEPTH ); SMS_NTSC_RGB_OUT( 5, *line_out++, SMS_NTSC_OUT_DEPTH ); SMS_NTSC_RGB_OUT( 6, *line_out++, SMS_NTSC_OUT_DEPTH ); #endif } #endif
zyking1987-genplus-droid
genplusgx/ntsc/sms_ntsc.c
C
gpl2
7,390
/* Sega Master System/Game Gear/TI 99/4A NTSC video filter */ /* sms_ntsc 0.2.3 */ #ifndef SMS_NTSC_H #define SMS_NTSC_H #include "sms_ntsc_config.h" #ifdef __cplusplus extern "C" { #endif /* Image parameters, ranging from -1.0 to 1.0. Actual internal values shown in parenthesis and should remain fairly stable in future versions. */ typedef struct sms_ntsc_setup_t { /* Basic parameters */ double hue; /* -1 = -180 degrees +1 = +180 degrees */ double saturation; /* -1 = grayscale (0.0) +1 = oversaturated colors (2.0) */ double contrast; /* -1 = dark (0.5) +1 = light (1.5) */ double brightness; /* -1 = dark (0.5) +1 = light (1.5) */ double sharpness; /* edge contrast enhancement/blurring */ /* Advanced parameters */ double gamma; /* -1 = dark (1.5) +1 = light (0.5) */ double resolution; /* image resolution */ double artifacts; /* artifacts caused by color changes */ double fringing; /* color artifacts caused by brightness changes */ double bleed; /* color bleed (color resolution reduction) */ float const* decoder_matrix; /* optional RGB decoder matrix, 6 elements */ unsigned char* palette_out; /* optional RGB palette out, 3 bytes per color */ } sms_ntsc_setup_t; /* Video format presets */ extern sms_ntsc_setup_t const sms_ntsc_composite; /* color bleeding + artifacts */ extern sms_ntsc_setup_t const sms_ntsc_svideo; /* color bleeding only */ extern sms_ntsc_setup_t const sms_ntsc_rgb; /* crisp image */ extern sms_ntsc_setup_t const sms_ntsc_monochrome;/* desaturated + artifacts */ enum { sms_ntsc_palette_size = 4096 }; /* Initializes and adjusts parameters. Can be called multiple times on the same sms_ntsc_t object. Can pass NULL for either parameter. */ typedef struct sms_ntsc_t sms_ntsc_t; void sms_ntsc_init( sms_ntsc_t* ntsc, sms_ntsc_setup_t const* setup ); /* Filters one or more rows of pixels. Input pixel format is set by SMS_NTSC_IN_FORMAT and output RGB depth is set by SMS_NTSC_OUT_DEPTH. Both default to 16-bit RGB. In_row_width is the number of pixels to get to the next input row. Out_pitch is the number of *bytes* to get to the next output row. */ void sms_ntsc_blit( sms_ntsc_t const* ntsc, SMS_NTSC_IN_T const* table, unsigned char* input, int in_width, int vline); /* Number of output pixels written by blitter for given input width. */ #define SMS_NTSC_OUT_WIDTH( in_width ) \ (((in_width) / sms_ntsc_in_chunk + 1) * sms_ntsc_out_chunk) /* Number of input pixels that will fit within given output width. Might be rounded down slightly; use SMS_NTSC_OUT_WIDTH() on result to find rounded value. */ #define SMS_NTSC_IN_WIDTH( out_width ) \ (((out_width) / sms_ntsc_out_chunk - 1) * sms_ntsc_in_chunk + 2) /* Interface for user-defined custom blitters */ enum { sms_ntsc_in_chunk = 3 }; /* number of input pixels read per chunk */ enum { sms_ntsc_out_chunk = 7 }; /* number of output pixels generated per chunk */ enum { sms_ntsc_black = 0 }; /* palette index for black */ /* Begins outputting row and starts three pixels. First pixel will be cut off a bit. Use sms_ntsc_black for unused pixels. Declares variables, so must be before first statement in a block (unless you're using C++). */ #define SMS_NTSC_BEGIN_ROW( ntsc, pixel0, pixel1, pixel2 ) \ SMS_NTSC_BEGIN_ROW_6_( pixel0, pixel1, pixel2, SMS_NTSC_IN_FORMAT, ntsc ) /* Begins input pixel */ #define SMS_NTSC_COLOR_IN( in_index, ntsc, color_in ) \ SMS_NTSC_COLOR_IN_( in_index, color_in, SMS_NTSC_IN_FORMAT, ntsc ) /* Generates output pixel. Bits can be 24, 16, 15, 32 (treated as 24), or 0: 24: RRRRRRRR GGGGGGGG BBBBBBBB (8-8-8 RGB) 16: RRRRRGGG GGGBBBBB (5-6-5 RGB) 15: RRRRRGG GGGBBBBB (5-5-5 RGB) 0: xxxRRRRR RRRxxGGG GGGGGxxB BBBBBBBx (native internal format; x = junk bits) */ #define SMS_NTSC_RGB_OUT( index, rgb_out, bits ) \ SMS_NTSC_RGB_OUT_14_( index, rgb_out, bits, 0 ) /* private */ enum { sms_ntsc_entry_size = 3 * 14 }; typedef unsigned long sms_ntsc_rgb_t; struct sms_ntsc_t { sms_ntsc_rgb_t table [sms_ntsc_palette_size] [sms_ntsc_entry_size]; }; #define SMS_NTSC_BGR12( ntsc, n ) (ntsc)->table [n & 0xFFF] #define SMS_NTSC_RGB16( ntsc, n ) \ (sms_ntsc_rgb_t const*) ((char const*) (ntsc)->table +\ ((n << 10 & 0x7800) | (n & 0x0780) | (n >> 9 & 0x0078)) *\ (sms_ntsc_entry_size * sizeof (sms_ntsc_rgb_t) / 8)) #define SMS_NTSC_RGB15( ntsc, n ) \ (sms_ntsc_rgb_t const*) ((char const*) (ntsc)->table +\ ((n << 9 & 0x3C00) | (n & 0x03C0) | (n >> 9 & 0x003C)) *\ (sms_ntsc_entry_size * sizeof (sms_ntsc_rgb_t) / 4)) /* common 3->7 ntsc macros */ #define SMS_NTSC_BEGIN_ROW_6_( pixel0, pixel1, pixel2, ENTRY, table ) \ unsigned const sms_ntsc_pixel0_ = (pixel0);\ sms_ntsc_rgb_t const* kernel0 = ENTRY( table, sms_ntsc_pixel0_ );\ unsigned const sms_ntsc_pixel1_ = (pixel1);\ sms_ntsc_rgb_t const* kernel1 = ENTRY( table, sms_ntsc_pixel1_ );\ unsigned const sms_ntsc_pixel2_ = (pixel2);\ sms_ntsc_rgb_t const* kernel2 = ENTRY( table, sms_ntsc_pixel2_ );\ sms_ntsc_rgb_t const* kernelx0;\ sms_ntsc_rgb_t const* kernelx1 = kernel0;\ sms_ntsc_rgb_t const* kernelx2 = kernel0 #define SMS_NTSC_RGB_OUT_14_( x, rgb_out, bits, shift ) {\ sms_ntsc_rgb_t raw_ =\ kernel0 [x ] + kernel1 [(x+12)%7+14] + kernel2 [(x+10)%7+28] +\ kernelx0 [(x+7)%14] + kernelx1 [(x+ 5)%7+21] + kernelx2 [(x+ 3)%7+35];\ SMS_NTSC_CLAMP_( raw_, shift );\ SMS_NTSC_RGB_OUT_( rgb_out, bits, shift );\ } /* common ntsc macros */ #define sms_ntsc_rgb_builder ((1L << 21) | (1 << 11) | (1 << 1)) #define sms_ntsc_clamp_mask (sms_ntsc_rgb_builder * 3 / 2) #define sms_ntsc_clamp_add (sms_ntsc_rgb_builder * 0x101) #define SMS_NTSC_CLAMP_( io, shift ) {\ sms_ntsc_rgb_t sub = (io) >> (9-(shift)) & sms_ntsc_clamp_mask;\ sms_ntsc_rgb_t clamp = sms_ntsc_clamp_add - sub;\ io |= clamp;\ clamp -= sub;\ io &= clamp;\ } #define SMS_NTSC_COLOR_IN_( index, color, ENTRY, table ) {\ unsigned color_;\ kernelx##index = kernel##index;\ kernel##index = (color_ = (color), ENTRY( table, color_ ));\ } /* x is always zero except in snes_ntsc library */ #define SMS_NTSC_RGB_OUT_( rgb_out, bits, x ) {\ rgb_out = (raw_>>(13-x)& 0xF800)|(raw_>>(8-x)&0x07E0)|(raw_>>(4-x)&0x001F);\ } #ifdef __cplusplus } #endif #endif
zyking1987-genplus-droid
genplusgx/ntsc/sms_ntsc.h
C
gpl2
6,526
/*************************************************************************************** * Genesis Plus * Video Display Processor (68k & Z80 CPU interface) * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007-2011), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _VDP_H_ #define _VDP_H_ /* VDP context */ extern uint8 reg[0x20]; extern uint8 sat[0x400]; extern uint8 vram[0x10000]; extern uint8 cram[0x80]; extern uint8 vsram[0x80]; extern uint8 hint_pending; extern uint8 vint_pending; extern uint8 m68k_irq_state; extern uint16 status; extern uint32 dma_length; /* Global variables */ extern uint16 ntab; extern uint16 ntbb; extern uint16 ntwb; extern uint16 satb; extern uint16 hscb; extern uint8 bg_name_dirty[0x800]; extern uint16 bg_name_list[0x800]; extern uint16 bg_list_index; extern uint8 bg_pattern_cache[0x80000]; extern uint8 hscroll_mask; extern uint8 playfield_shift; extern uint8 playfield_col_mask; extern uint16 playfield_row_mask; extern uint8 odd_frame; extern uint8 im2_flag; extern uint8 interlaced; extern uint8 vdp_pal; extern uint16 v_counter; extern uint16 vc_max; extern uint16 hscroll; extern uint16 vscroll; extern uint16 lines_per_frame; extern int32 fifo_write_cnt; extern uint32 fifo_lastwrite; extern uint32 hvc_latch; extern const uint8 *hctab; /* Function pointers */ extern void (*vdp_68k_data_w)(unsigned int data); extern void (*vdp_z80_data_w)(unsigned int data); extern unsigned int (*vdp_68k_data_r)(void); extern unsigned int (*vdp_z80_data_r)(void); /* Function prototypes */ extern void vdp_init(void); extern void vdp_reset(void); extern int vdp_context_save(uint8 *state); extern int vdp_context_load(uint8 *state, char *version); extern void vdp_dma_update(unsigned int cycles); extern void vdp_68k_ctrl_w(unsigned int data); extern void vdp_z80_ctrl_w(unsigned int data); extern unsigned int vdp_ctrl_r(unsigned int cycles); extern unsigned int vdp_hvc_r(unsigned int cycles); extern void vdp_test_w(unsigned int data); extern int vdp_68k_irq_ack(int int_level); #endif /* _VDP_H_ */
zyking1987-genplus-droid
genplusgx/vdp_ctrl.h
C
gpl2
3,012
/*************************************************************************************** * Genesis Plus * Savestate support * * Copyright (C) 2007-2011 Eke-Eke (GCN/Wii port) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _STATE_H_ #define _STATE_H_ #define STATE_SIZE 0x48100 #define STATE_VERSION "GENPLUS-GX 1.5.0" #define load_param(param, size) \ memcpy(param, &state[bufferptr], size); \ bufferptr+= size; #define save_param(param, size) \ memcpy(&state[bufferptr], param, size); \ bufferptr+= size; /* Function prototypes */ extern int state_load(unsigned char *buffer, int compression); extern int state_save(unsigned char *buffer, int compression); #endif
zyking1987-genplus-droid
genplusgx/state.h
C
gpl2
1,513
/****************************************************************************** * * unzip.c * * Zip Support * * Only partial support is included, in that only the first file within the archive * is considered to be a ROM image. * * Softdev (2006) * Eke-Eke (2007,2008) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #ifndef _UNZIP_H_ #define _UNZIP_H_ extern int IsZipFile (char *buffer); int UnZipBuffer (unsigned char *outbuffer, FILE *fd); #endif
zyking1987-genplus-droid
genplusgx/unzip.h
C
gpl2
1,286
/**************************************************************************** * gx_video.c * * Genesis Plus GX video & rendering support * * Softdev (2006) * Eke-Eke (2007,2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "shared.h" #include "font.h" #include "aram.h" #include "md_ntsc.h" #include "sms_ntsc.h" #include <png.h> #define TEX_WIDTH 720 #define TEX_HEIGHT 576 #define TEX_SIZE (TEX_WIDTH * TEX_HEIGHT * 2) #define DEFAULT_FIFO_SIZE 256 * 1024 #define HASPECT 320 #define VASPECT 240 /* libpng wrapper */ typedef struct { u8 *buffer; u32 offset; } png_image; extern const u8 Crosshair_p1_png[]; extern const u8 Crosshair_p2_png[]; /*** VI ***/ GXRModeObj *vmode; /* Default Video Mode */ u8 *texturemem; /* Texture Data */ u8 *screenshot; /* Texture Data */ /*** 50/60hz flag ***/ u32 gc_pal = 0; /*** NTSC Filters ***/ sms_ntsc_t *sms_ntsc; md_ntsc_t *md_ntsc; /*** GX FIFO ***/ static u8 gp_fifo[DEFAULT_FIFO_SIZE] ATTRIBUTE_ALIGN (32); /*** GX Textures ***/ static u32 vwidth,vheight; static gx_texture *crosshair[2]; /*** Framebuffers ***/ static u32 *xfb[2]; static u32 whichfb = 0; /***************************************************************************************/ /* Emulation video modes */ /***************************************************************************************/ static GXRModeObj *rmode; /* 288 lines progressive (PAL 50Hz) */ static GXRModeObj TV50hz_288p = { VI_TVMODE_PAL_DS, // viDisplayMode 640, // fbWidth 286, // efbHeight 286, // xfbHeight 0, // viXOrigin (VI_MAX_HEIGHT_PAL - 572)/2, // viYOrigin VI_MAX_WIDTH_PAL, // viWidth 572, // viHeight VI_XFBMODE_SF, // xFBmode GX_FALSE, // field_rendering GX_FALSE, // aa // sample points arranged in increasing Y order { {6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each {6,6},{6,6},{6,6}, // pix 1 {6,6},{6,6},{6,6}, // pix 2 {6,6},{6,6},{6,6} // pix 3 }, // vertical filter[7], 1/64 units, 6 bits each { 0, // line n-1 0, // line n-1 21, // line n 22, // line n 21, // line n 0, // line n+1 0 // line n+1 } }; /* 288 lines interlaced (PAL 50Hz) */ static GXRModeObj TV50hz_288i = { VI_TVMODE_PAL_INT, // viDisplayMode 640, // fbWidth 286, // efbHeight 286, // xfbHeight 0, // viXOrigin (VI_MAX_HEIGHT_PAL - 572)/2, // viYOrigin VI_MAX_WIDTH_PAL, // viWidth 572, // viHeight VI_XFBMODE_SF, // xFBmode GX_TRUE, // field_rendering GX_FALSE, // aa // sample points arranged in increasing Y order { {6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each {6,6},{6,6},{6,6}, // pix 1 {6,6},{6,6},{6,6}, // pix 2 {6,6},{6,6},{6,6} // pix 3 }, // vertical filter[7], 1/64 units, 6 bits each { 0, // line n-1 0, // line n-1 21, // line n 22, // line n 21, // line n 0, // line n+1 0 // line n+1 } }; /* 576 lines interlaced (PAL 50Hz, scaled) */ static GXRModeObj TV50hz_576i = { VI_TVMODE_PAL_INT, // viDisplayMode 640, // fbWidth 480, // efbHeight VI_MAX_HEIGHT_PAL, // xfbHeight 0, // viXOrigin 0, // viYOrigin VI_MAX_WIDTH_PAL, // viWidth VI_MAX_HEIGHT_PAL, // viHeight VI_XFBMODE_DF, // xFBmode GX_FALSE, // field_rendering GX_FALSE, // aa // sample points arranged in increasing Y order { {6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each {6,6},{6,6},{6,6}, // pix 1 {6,6},{6,6},{6,6}, // pix 2 {6,6},{6,6},{6,6} // pix 3 }, // vertical filter[7], 1/64 units, 6 bits each { 8, // line n-1 8, // line n-1 10, // line n 12, // line n 10, // line n 8, // line n+1 8 // line n+1 } }; /* 240 lines progressive (NTSC or PAL 60Hz) */ static GXRModeObj TV60hz_240p = { VI_TVMODE_EURGB60_DS, // viDisplayMode 640, // fbWidth VI_MAX_HEIGHT_NTSC/2, // efbHeight VI_MAX_HEIGHT_NTSC/2, // xfbHeight 0, // viXOrigin 0, // viYOrigin VI_MAX_WIDTH_NTSC, // viWidth VI_MAX_HEIGHT_NTSC, // viHeight VI_XFBMODE_SF, // xFBmode GX_FALSE, // field_rendering GX_FALSE, // aa // sample points arranged in increasing Y order { {6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each {6,6},{6,6},{6,6}, // pix 1 {6,6},{6,6},{6,6}, // pix 2 {6,6},{6,6},{6,6} // pix 3 }, // vertical filter[7], 1/64 units, 6 bits each { 0, // line n-1 0, // line n-1 21, // line n 22, // line n 21, // line n 0, // line n+1 0 // line n+1 } }; /* 240 lines interlaced (NTSC or PAL 60Hz) */ static GXRModeObj TV60hz_240i = { VI_TVMODE_EURGB60_INT, // viDisplayMode 640, // fbWidth VI_MAX_HEIGHT_NTSC/2, // efbHeight VI_MAX_HEIGHT_NTSC/2, // xfbHeight 0, // viXOrigin 0, // viYOrigin VI_MAX_WIDTH_NTSC, // viWidth VI_MAX_HEIGHT_NTSC, // viHeight VI_XFBMODE_SF, // xFBmode GX_TRUE, // field_rendering GX_FALSE, // aa // sample points arranged in increasing Y order { {3,2},{9,6},{3,10}, // pix 0, 3 sample points, 1/12 units, 4 bits each {3,2},{9,6},{3,10}, // pix 1 {9,2},{3,6},{9,10}, // pix 2 {9,2},{3,6},{9,10} // pix 3 }, // vertical filter[7], 1/64 units, 6 bits each { 0, // line n-1 0, // line n-1 21, // line n 22, // line n 21, // line n 0, // line n+1 0 // line n+1 } }; /* 480 lines interlaced (NTSC or PAL 60Hz) */ static GXRModeObj TV60hz_480i = { VI_TVMODE_EURGB60_INT,// viDisplayMode 640, // fbWidth VI_MAX_HEIGHT_NTSC, // efbHeight VI_MAX_HEIGHT_NTSC, // xfbHeight 0, // viXOrigin 0, // viYOrigin VI_MAX_WIDTH_NTSC, // viWidth VI_MAX_HEIGHT_NTSC, // viHeight VI_XFBMODE_DF, // xFBmode GX_FALSE, // field_rendering GX_FALSE, // aa // sample points arranged in increasing Y order { {6,6},{6,6},{6,6}, // pix 0, 3 sample points, 1/12 units, 4 bits each {6,6},{6,6},{6,6}, // pix 1 {6,6},{6,6},{6,6}, // pix 2 {6,6},{6,6},{6,6} // pix 3 }, // vertical filter[7], 1/64 units, 6 bits each { 8, // line n-1 8, // line n-1 10, // line n 12, // line n 10, // line n 8, // line n+1 8 // line n+1 } }; /* TV modes pointer table */ static GXRModeObj *tvmodes[6] = { /* 60hz modes */ &TV60hz_240p, &TV60hz_240i, &TV60hz_480i, /* 50Hz modes */ &TV50hz_288p, &TV50hz_288i, &TV50hz_576i }; /***************************************************************************************/ /* GX rendering engine */ /***************************************************************************************/ typedef struct tagcamera { guVector pos; guVector up; guVector view; } camera; /*** Square Matrix This structure controls the size of the image on the screen. Think of the output as a -80 x 80 by -60 x 60 graph. ***/ static s16 square[] ATTRIBUTE_ALIGN (32) = { /* * X, Y, Z * Values set are for roughly 4:3 aspect */ -HASPECT, VASPECT, 0, // 0 HASPECT, VASPECT, 0, // 1 HASPECT, -VASPECT, 0, // 2 -HASPECT, -VASPECT, 0, // 3 }; static camera cam = { {0.0F, 0.0F, -100.0F}, {0.0F, -1.0F, 0.0F}, {0.0F, 0.0F, 0.0F} }; /* VSYNC callback */ static void vi_callback(u32 cnt) { frameticker++; } /* Vertex Rendering */ static inline void draw_vert(u8 pos, f32 s, f32 t) { GX_Position1x8(pos); GX_TexCoord2f32(s, t); } /* textured quad rendering */ static inline void draw_square(void) { GX_Begin(GX_QUADS, GX_VTXFMT0, 4); draw_vert(3, 0.0, 0.0); draw_vert(2, 1.0, 0.0); draw_vert(1, 1.0, 1.0); draw_vert(0, 0.0, 1.0); GX_End (); } /* Initialize GX */ static void gxStart(void) { /*** Clear out FIFO area ***/ memset(&gp_fifo, 0, DEFAULT_FIFO_SIZE); /*** GX default ***/ GX_Init(&gp_fifo, DEFAULT_FIFO_SIZE); GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetCullMode(GX_CULL_NONE); GX_SetClipMode(GX_CLIP_DISABLE); GX_SetDispCopyGamma(GX_GM_1_0); GX_SetZMode(GX_FALSE, GX_ALWAYS, GX_FALSE); GX_SetColorUpdate(GX_TRUE); GX_SetAlphaUpdate(GX_FALSE); /* Modelview */ Mtx view; memset (&view, 0, sizeof (Mtx)); guLookAt(view, &cam.pos, &cam.up, &cam.view); GX_LoadPosMtxImm(view, GX_PNMTX0); GX_Flush(); } /* Reset GX rendering */ static void gxResetRendering(u8 type) { GX_ClearVtxDesc(); if (type) { /* uses direct positionning, alpha blending & color channel (menu rendering) */ GX_SetBlendMode(GX_BM_BLEND,GX_BL_SRCALPHA,GX_BL_INVSRCALPHA,GX_LO_CLEAR); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_S16, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetVtxDesc (GX_VA_CLR0, GX_DIRECT); /* Color.out = Color.rasterized*Color.texture Alpha.out = Alpha.rasterized*Alpha.texture */ GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); GX_SetNumTexGens(1); GX_SetNumChans(1); } else { /* uses array positionning, no alpha blending, no color channel (video emulation) */ GX_SetBlendMode(GX_BM_NONE,GX_BL_SRCALPHA,GX_BL_INVSRCALPHA,GX_LO_CLEAR); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_S16, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetVtxDesc(GX_VA_POS, GX_INDEX8); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetArray(GX_VA_POS, square, 3 * sizeof (s16)); /* Color.out = Color.texture Alpha.out = Alpha.texture */ GX_SetTevOp (GX_TEVSTAGE0, GX_REPLACE); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLORNULL); GX_SetNumTexGens(1); GX_SetNumChans(0); } GX_Flush(); } /* Reset GX rendering mode */ static void gxResetMode(GXRModeObj *tvmode) { Mtx44 p; f32 yScale = GX_GetYScaleFactor(tvmode->efbHeight, tvmode->xfbHeight); u16 xfbHeight = GX_SetDispCopyYScale(yScale); u16 xfbWidth = tvmode->fbWidth; if (xfbWidth & 15) // xfb width is 16 pixels aligned xfbWidth = (xfbWidth & ~15) + 16; GX_SetCopyClear((GXColor)BLACK,0x00ffffff); GX_SetViewport(0.0F, 0.0F, tvmode->fbWidth, tvmode->efbHeight, 0.0F, 1.0F); GX_SetScissor(0, 0, tvmode->fbWidth, tvmode->efbHeight); GX_SetDispCopySrc(0, 0, tvmode->fbWidth, tvmode->efbHeight); GX_SetDispCopyDst(xfbWidth, xfbHeight); GX_SetCopyFilter(tvmode->aa, tvmode->sample_pattern, (tvmode->xfbMode == VI_XFBMODE_SF) ? GX_FALSE : GX_TRUE, tvmode->vfilter); GX_SetFieldMode(tvmode->field_rendering, ((tvmode->viHeight == 2 * tvmode->xfbHeight) ? GX_ENABLE : GX_DISABLE)); guOrtho(p, tvmode->efbHeight/2, -(tvmode->efbHeight/2), -(tvmode->fbWidth/2), tvmode->fbWidth/2, 100, 1000); GX_LoadProjectionMtx(p, GX_ORTHOGRAPHIC); GX_Flush(); } /* Manage Aspect Ratio */ static void gxSetAspectRatio(int *xscale, int *yscale) { /* original aspect ratio */ /* the following values have been deducted from comparison with a real 50/60hz Mega Drive */ if (config.aspect) { /* vertical borders */ if (config.overscan & 1) { /* Genesis outputs 288(PAL) or 243(NTSC) lines */ /* Wii & Game Cube output 286/574(PAL50) or 240/480 (PAL60 & NTSC) lines */ *yscale = vdp_pal + ((gc_pal && !config.render) ? 143 : 120); } else { /* overscan is simulated (black) */ *yscale = bitmap.viewport.h / 2; if (vdp_pal && (!gc_pal || config.render)) *yscale = *yscale * 240 / 288; else if (!vdp_pal && gc_pal && !config.render) *yscale = *yscale * 288 / 240; } /* horizontal borders */ if (config.overscan & 2) { /* max visible range is ~712 pixels, not 720 */ *xscale = (reg[12] & 1) ? 356 : 360; } else { /* overscan is simulated (black) */ *xscale = 327; } /* 16/9 correction */ if (config.aspect & 2) { *xscale = (*xscale * 3) / 4; } } /* manual aspect ratio (default is unscaled raw) */ else { /* vertical borders */ if (config.overscan & 1) { *yscale = (gc_pal && !config.render) ? (vdp_pal ? (268*144 / bitmap.viewport.h):143) : (vdp_pal ? (224*144 / bitmap.viewport.h):120); } else { *yscale = (gc_pal && !config.render) ? 134 : 112; } /* horizontal borders */ if (config.overscan & 2) { *xscale = 348; } else { *xscale = 320; } /* add user scaling */ *xscale += config.xscale; *yscale += config.yscale; } } /* Reset GX/VI hardware scaler */ static void gxResetScaler(u32 width) { int xscale = 0; int yscale = 0; int offset = 0; /* retrieve screen aspect ratio */ gxSetAspectRatio(&xscale, &yscale); /* default EFB width */ rmode->fbWidth = 640; /* no filtering, disable GX horizontal scaling */ if (!config.bilinear && !config.ntsc) { if ((width * 2) <= 640) rmode->fbWidth = width * 2; else if (width <= 640) rmode->fbWidth = width; } /* configure VI width */ if ((xscale * 2) > rmode->fbWidth) { /* max width = 720 pixels */ if (xscale > 360) { /* save offset for later */ offset = ((xscale - 360) * rmode->fbWidth) / rmode->viWidth; /* maximal width */ xscale = 360; } /* enable VI upscaling */ rmode->viWidth = xscale * 2; rmode->viXOrigin = (720 - (xscale * 2)) / 2; /* default GX horizontal scaling */ xscale = (rmode->fbWidth / 2); /* handle additional upscaling */ if (offset) { /* no filtering, reduce EFB width to increase VI upscaling */ if (!config.bilinear && !config.ntsc) rmode->fbWidth -= (offset * 2); /* increase GX horizontal scaling */ else xscale += offset; } } else { /* VI horizontal scaling is disabled */ rmode->viWidth = rmode->fbWidth; rmode->viXOrigin = (720 - rmode->fbWidth) / 2; } /* Adjust screen position */ int xshift = (config.xshift * rmode->fbWidth) / rmode->viWidth; int yshift = (config.yshift * rmode->efbHeight) / rmode->viHeight; /* Double Resolution modes (480i/576i/480p) */ if (config.render) { yscale = yscale * 2; } /* Set GX scaler (Vertex Position matrix) */ square[6] = square[3] = xshift + xscale; square[0] = square[9] = xshift - xscale; square[4] = square[1] = yshift + yscale; square[7] = square[10] = yshift - yscale; DCFlushRange(square, 32); GX_InvVtxCache(); } static void gxDrawCrosshair(gx_texture *texture, int x, int y) { if (texture->data) { /* load texture object */ GXTexObj texObj; GX_InitTexObj(&texObj, texture->data, texture->width, texture->height, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_InitTexObjLOD(&texObj,GX_LINEAR,GX_LIN_MIP_LIN,0.0,10.0,0.0,GX_FALSE,GX_TRUE,GX_ANISO_4); GX_LoadTexObj(&texObj, GX_TEXMAP0); GX_InvalidateTexAll(); /* reset GX rendering */ gxResetRendering(1); /* adjust coordinates */ int w = (texture->width * rmode->fbWidth) / (rmode->viWidth); int h = (texture->height * rmode->efbHeight) / (rmode->viHeight); x = ((x * rmode->fbWidth) / bitmap.viewport.w) - w/2 - (rmode->fbWidth/2); y = ((y * rmode->efbHeight) / bitmap.viewport.h) - h/2 - (rmode->efbHeight/2); /* Draw textured quad */ GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position2s16(x,y+h); GX_Color4u8(0xff,0xff,0xff,0xff); GX_TexCoord2f32(0.0, 1.0); GX_Position2s16(x+w,y+h); GX_Color4u8(0xff,0xff,0xff,0xff); GX_TexCoord2f32(1.0, 1.0); GX_Position2s16(x+w,y); GX_Color4u8(0xff,0xff,0xff,0xff); GX_TexCoord2f32(1.0, 0.0); GX_Position2s16(x,y); GX_Color4u8(0xff,0xff,0xff,0xff); GX_TexCoord2f32(0.0, 0.0); GX_End (); /* restore GX rendering */ gxResetRendering(0); /* restore texture object */ GXTexObj texobj; GX_InitTexObj(&texobj, texturemem, vwidth, vheight, GX_TF_RGB565, GX_CLAMP, GX_CLAMP, GX_FALSE); if (!config.bilinear) GX_InitTexObjLOD(&texobj,GX_NEAR,GX_NEAR_MIP_NEAR,0.0,10.0,0.0,GX_FALSE,GX_FALSE,GX_ANISO_1); GX_LoadTexObj(&texobj, GX_TEXMAP0); GX_InvalidateTexAll(); } } void gxDrawRectangle(s32 x, s32 y, s32 w, s32 h, u8 alpha, GXColor color) { /* GX only use Color channel for rendering */ GX_SetTevOp (GX_TEVSTAGE0, GX_PASSCLR); GX_SetVtxDesc (GX_VA_TEX0, GX_NONE); GX_Flush(); /* vertex coordinate */ x -= (vmode->fbWidth/2); y -= (vmode->efbHeight/2); /* draw colored quad */ GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position2s16(x,y+h); GX_Color4u8(color.r,color.g,color.b,alpha); GX_Position2s16(x+w,y+h); GX_Color4u8(color.r,color.g,color.b,alpha); GX_Position2s16(x+w,y); GX_Color4u8(color.r,color.g,color.b,alpha); GX_Position2s16(x,y); GX_Color4u8(color.r,color.g,color.b,alpha); GX_End (); GX_DrawDone(); /* restore GX rendering */ GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetTevOp (GX_TEVSTAGE0, GX_MODULATE); GX_Flush(); } void gxDrawTexture(gx_texture *texture, s32 x, s32 y, s32 w, s32 h, u8 alpha) { if (!texture) return; if (texture->data) { /* load texture object */ GXTexObj texObj; GX_InitTexObj(&texObj, texture->data, texture->width, texture->height, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_InitTexObjLOD(&texObj,GX_LINEAR,GX_LIN_MIP_LIN,0.0,10.0,0.0,GX_FALSE,GX_TRUE,GX_ANISO_4); /* does this really change anything ? */ GX_LoadTexObj(&texObj, GX_TEXMAP0); GX_InvalidateTexAll(); /* vertex coordinate */ x -= (vmode->fbWidth/2); y -= (vmode->efbHeight/2); /* draw textured quad */ GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position2s16(x,y+h); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(0.0, 1.0); GX_Position2s16(x+w,y+h); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(1.0, 1.0); GX_Position2s16(x+w,y); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(1.0, 0.0); GX_Position2s16(x,y); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(0.0, 0.0); GX_End (); GX_DrawDone(); } } void gxDrawTextureRotate(gx_texture *texture, s32 x, s32 y, s32 w, s32 h, f32 angle, u8 alpha) { if (!texture) return; if (texture->data) { /* load texture object */ GXTexObj texObj; GX_InitTexObj(&texObj, texture->data, texture->width, texture->height, GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_InitTexObjLOD(&texObj,GX_LINEAR,GX_LIN_MIP_LIN,0.0,10.0,0.0,GX_FALSE,GX_TRUE,GX_ANISO_4); GX_LoadTexObj(&texObj, GX_TEXMAP0); GX_InvalidateTexAll(); /* vertex coordinate */ x -= (vmode->fbWidth/2); y -= (vmode->efbHeight/2); /* Modelview rotation */ Mtx m,mv; guVector axis = (guVector) {0,0,1}; guLookAt(mv, &cam.pos, &cam.up, &cam.view); guMtxRotAxisDeg (m, &axis, angle); guMtxTransApply(m,m, x+w/2,y+h/2,0); guMtxConcat(mv,m,mv); GX_LoadPosMtxImm(mv, GX_PNMTX0); GX_Flush(); /* draw textured quad */ GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position2s16(-w/2,-h/2); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(0.0, 0.0); GX_Position2s16(w/2,-h/2); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(1.0, 0.0); GX_Position2s16(w/2,h/2); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(1.0, 1.0); GX_Position2s16(-w/2,h/2); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(0.0, 1.0); GX_End (); GX_DrawDone(); /* restore default Modelview */ guLookAt(mv, &cam.pos, &cam.up, &cam.view); GX_LoadPosMtxImm(mv, GX_PNMTX0); GX_Flush(); } } void gxDrawTextureRepeat(gx_texture *texture, s32 x, s32 y, s32 w, s32 h, u8 alpha) { if (!texture) return; if (texture->data) { /* load texture object */ GXTexObj texObj; GX_InitTexObj(&texObj, texture->data, texture->width, texture->height, GX_TF_RGBA8, GX_REPEAT, GX_REPEAT, GX_FALSE); GX_LoadTexObj(&texObj, GX_TEXMAP0); GX_InvalidateTexAll(); /* vertex coordinate */ x -= (vmode->fbWidth/2); y -= (vmode->efbHeight/2); /* texture coordinates */ f32 s = (f32)w / (f32)texture->width; f32 t = (f32)h / (f32)texture->height; /* draw textured quad */ GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position2s16(x,y+h); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(0.0, t); GX_Position2s16(x+w,y+h); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(s, t); GX_Position2s16(x+w,y); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(s, 0.0); GX_Position2s16(x,y); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(0.0, 0.0); GX_End (); GX_DrawDone(); } } void gxDrawScreenshot(u8 alpha) { if (!rmode) return; /* get current game screen texture */ GXTexObj texobj; GX_InitTexObj(&texobj, texturemem, vwidth, vheight, GX_TF_RGB565, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_LoadTexObj(&texobj, GX_TEXMAP0); GX_InvalidateTexAll(); /* get current aspect ratio */ int xscale,yscale; gxSetAspectRatio(&xscale, &yscale); /* adjust horizontal scaling */ xscale = (xscale * vmode->fbWidth) / vmode->viWidth; /* adjust screen position */ int xshift = (config.xshift * vmode->fbWidth) / vmode->viWidth; int yshift = (config.yshift * vmode->efbHeight) / vmode->viHeight; /* set vertices position & size */ s32 x = xshift - xscale; s32 y = yshift - (yscale * 2); s32 w = xscale * 2; s32 h = yscale * 4; /* draw textured quad */ GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position2s16(x,y+h); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(0.0, 1.0); GX_Position2s16(x+w,y+h); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(1.0, 1.0); GX_Position2s16(x+w,y); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(1.0, 0.0); GX_Position2s16(x,y); GX_Color4u8(0xff,0xff,0xff,alpha); GX_TexCoord2f32(0.0, 0.0); GX_End (); GX_DrawDone(); } void gxCopyScreenshot(gx_texture *texture) { /* retrieve gamescreen texture */ GXTexObj texobj; GX_InitTexObj(&texobj, texturemem, vwidth, vheight, GX_TF_RGB565, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_LoadTexObj(&texobj, GX_TEXMAP0); GX_InvalidateTexAll(); /* scale texture to EFB width */ s32 w = bitmap.viewport.x ? 696 : 640; s32 h = (bitmap.viewport.h + 2*bitmap.viewport.y) * 2; s32 x = -w/2; s32 y = -(240+ 2*bitmap.viewport.y); /* draw textured quad */ GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position2s16(x,y+h); GX_Color4u8(0xff,0xff,0xff,0xff); GX_TexCoord2f32(0.0, 1.0); GX_Position2s16(x+w,y+h); GX_Color4u8(0xff,0xff,0xff,0xff); GX_TexCoord2f32(1.0, 1.0); GX_Position2s16(x+w,y); GX_Color4u8(0xff,0xff,0xff,0xff); GX_TexCoord2f32(1.0, 0.0); GX_Position2s16(x,y); GX_Color4u8(0xff,0xff,0xff,0xff); GX_TexCoord2f32(0.0, 0.0); GX_End (); /* copy EFB to texture */ texture->format = GX_TF_RGBA8; texture->width = 320; texture->height = bitmap.viewport.h; texture->data = screenshot; GX_SetTexCopySrc(0, 0, texture->width * 2, texture->height * 2); GX_SetTexCopyDst(texture->width, texture->height, texture->format, GX_TRUE); GX_DrawDone(); GX_CopyTex(texture->data, GX_TRUE); GX_Flush(); /* wait for copy operation to finish */ /* GX_PixModeSync is only useful if GX_ command follows */ /* we use dummy GX commands to stall CPU execution */ GX_PixModeSync(); GX_LoadTexObj(&texobj, GX_TEXMAP0); GX_InvalidateTexAll(); GX_Flush(); DCFlushRange(texture->data, texture->width * texture->height * 4); } /* Take Screenshot */ void gxSaveScreenshot(char *filename) { /* capture screenshot into a texture */ gx_texture texture; gxCopyScreenshot(&texture); /* open PNG file */ FILE *f = fopen(filename,"wb"); if (f) { /* encode screenshot into PNG file */ gxTextureWritePNG(&texture,f); fclose(f); } } void gxSetScreen(void) { GX_DrawDone(); GX_CopyDisp(xfb[whichfb], GX_FALSE); GX_Flush(); VIDEO_SetNextFramebuffer (xfb[whichfb]); VIDEO_Flush (); VIDEO_WaitVSync (); } void gxClearScreen(GXColor color) { whichfb ^= 1; GX_SetCopyClear(color,0x00ffffff); GX_CopyDisp(xfb[whichfb], GX_TRUE); GX_Flush(); } /***************************************************************************************/ /* GX Texture <-> LibPNG routines */ /***************************************************************************************/ /* libpng read callback function */ static void png_read_from_mem (png_structp png_ptr, png_bytep data, png_size_t length) { png_image *image = (png_image *)png_get_io_ptr(png_ptr); /* copy data from image buffer */ memcpy (data, image->buffer + image->offset, length); /* advance in the file */ image->offset += length; } /* convert PNG image (from file or data buffer) into RGBA8 texture */ gx_texture *gxTextureOpenPNG(const u8 *png_data, FILE *png_file) { int i; /* create a png read struct */ png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL); if (!png_ptr) return NULL; /* create a png info struct */ png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_read_struct(&png_ptr,NULL,NULL); return NULL; } if (png_data) { /* init PNG image structure */ png_image image; image.buffer = (u8 *) png_data; image.offset = 0; /* set callback for the read function */ png_set_read_fn(png_ptr,(png_voidp *)(&image),png_read_from_mem); } else if (png_file) { /* check for valid magic number */ png_byte magic[8]; if (fread (magic, 1, 8, png_file) != 8) { png_destroy_read_struct(&png_ptr,&info_ptr,NULL); return NULL; } if (png_sig_cmp (magic, 0, 8)) { png_destroy_read_struct(&png_ptr,&info_ptr,NULL); return NULL; } /* set IO callback for read function */ png_init_io (png_ptr, png_file); png_set_sig_bytes (png_ptr, 8); } else { png_destroy_read_struct(&png_ptr,&info_ptr,NULL); return NULL; } /* read png info */ png_read_info(png_ptr,info_ptr); /* retrieve image information */ u32 width = png_get_image_width(png_ptr,info_ptr); u32 height = png_get_image_height(png_ptr,info_ptr); u32 bit_depth = png_get_bit_depth(png_ptr,info_ptr); u32 color_type = png_get_color_type(png_ptr,info_ptr); /* ensure PNG file is in the supported format */ if (png_file) { /* support for RGBA8 textures ONLY !*/ if ((color_type != PNG_COLOR_TYPE_RGB_ALPHA) || (bit_depth != 8)) { png_destroy_read_struct(&png_ptr, &info_ptr,NULL); return NULL; } /* 4x4 tiles are required */ if ((width%4) || (height%4)) { png_destroy_read_struct(&png_ptr, &info_ptr, NULL); return NULL; } } /* allocate memory to store raw image data */ u32 stride = width << 2; u8 *img_data = memalign (32, stride * height); if (!img_data) { png_destroy_read_struct(&png_ptr,&info_ptr,NULL); return NULL; } /* allocate row pointer data */ png_bytep *row_pointers = (png_bytep *)memalign (32, sizeof (png_bytep) * height); if (!row_pointers) { free (img_data); png_destroy_read_struct(&png_ptr,&info_ptr,NULL); return NULL; } /* store raw image data */ for (i = 0; i < height; i++) { row_pointers[i] = img_data + (i * stride); } /* decode image */ png_read_image(png_ptr, row_pointers); /* finish decompression and release memory */ png_read_end(png_ptr, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); free(row_pointers); /* initialize texture */ gx_texture *texture = (gx_texture *)memalign(32, sizeof(gx_texture)); if (!texture) { free (img_data); return NULL; } /* initialize texture data */ texture->data = memalign(32, stride * height); if (!texture->data) { free (img_data); free(texture); return NULL; } memset(texture->data, 0, stride * height); texture->width = width; texture->height = height; texture->format = GX_TF_RGBA8; /* encode to GX_TF_RGBA8 format (4x4 pixels paired titles) */ u16 *dst_ar = (u16 *)(texture->data); u16 *dst_gb = (u16 *)(texture->data + 32); u32 *src1 = (u32 *)(img_data); u32 *src2 = (u32 *)(img_data + stride); u32 *src3 = (u32 *)(img_data + 2*stride); u32 *src4 = (u32 *)(img_data + 3*stride); u32 pixel,h,w; for (h=0; h<height; h+=4) { for (w=0; w<width; w+=4) { /* line N (4 pixels) */ for (i=0; i<4; i++) { pixel = *src1++; *dst_ar++= ((pixel << 8) & 0xff00) | ((pixel >> 24) & 0x00ff); *dst_gb++= (pixel >> 8) & 0xffff; } /* line N + 1 (4 pixels) */ for (i=0; i<4; i++) { pixel = *src2++; *dst_ar++= ((pixel << 8) & 0xff00) | ((pixel >> 24) & 0x00ff); *dst_gb++= (pixel >> 8) & 0xffff; } /* line N + 2 (4 pixels) */ for (i=0; i<4; i++) { pixel = *src3++; *dst_ar++= ((pixel << 8) & 0xff00) | ((pixel >> 24) & 0x00ff); *dst_gb++= (pixel >> 8) & 0xffff; } /* line N + 3 (4 pixels) */ for (i=0; i<4; i++) { pixel = *src4++; *dst_ar++= ((pixel << 8) & 0xff00) | ((pixel >> 24) & 0x00ff); *dst_gb++= (pixel >> 8) & 0xffff; } /* next paired tiles */ dst_ar += 16; dst_gb += 16; } /* next 4 lines */ src1 = src4; src2 = src1 + width; src3 = src2 + width; src4 = src3 + width; } /* release memory */ free(img_data); /* flush texture data from cache */ DCFlushRange(texture->data, height * stride); return texture; } /* Write RGBA8 Texture to PNG file */ void gxTextureWritePNG(gx_texture *texture, FILE *png_file) { /* allocate PNG data buffer */ u8 *img_data = (u8 *)memalign(32, texture->width * texture->height * 4); if(!img_data) return; /* decode GX_TF_RGBA8 format (4x4 pixels paired titles) */ u16 *ar = (u16 *)(texture->data); u16 *gb = (u16 *)(texture->data + 32); u32 *dst1 = (u32 *)(img_data); u32 *dst2 = dst1 + texture->width; u32 *dst3 = dst2 + texture->width; u32 *dst4 = dst3 + texture->width; u32 i,h,w,pixel; for (h=0; h<texture->height; h+=4) { for (w=0; w<texture->width; w+=4) { /* line N (4 pixels) */ for (i=0; i<4; i++) { pixel = ((*ar & 0xff) << 24) | (*gb << 8) | ((*ar & 0xff00) >> 8); *dst1++ = pixel; ar++; gb++; } /* line N + 1 (4 pixels) */ for (i=0; i<4; i++) { pixel = ((*ar & 0xff) << 24) | (*gb << 8) | ((*ar & 0xff00) >> 8); *dst2++ = pixel; ar++; gb++; } /* line N + 2 (4 pixels) */ for (i=0; i<4; i++) { pixel = ((*ar & 0xff) << 24) | (*gb << 8) | ((*ar & 0xff00) >> 8); *dst3++ = pixel; ar++; gb++; } /* line N + 3 (4 pixels) */ for (i=0; i<4; i++) { pixel = ((*ar & 0xff) << 24) | (*gb << 8) | ((*ar & 0xff00) >> 8); *dst4++ = pixel; ar++; gb++; } /* next paired tiles */ ar += 16; gb += 16; } /* next 4 lines */ dst1 = dst4; dst2 = dst1 + texture->width; dst3 = dst2 + texture->width; dst4 = dst3 + texture->width; } /* create a png write struct */ png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if(!png_ptr) { free(img_data); return; } /* create a png info struct */ png_infop info_ptr = png_create_info_struct (png_ptr); if (!info_ptr) { free(img_data); png_destroy_write_struct(&png_ptr, NULL); return; } /* set IO callback for the write function */ png_init_io(png_ptr, png_file); /* set PNG file properties */ png_set_IHDR(png_ptr, info_ptr, texture->width, texture->height, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); /* allocate row pointer data */ png_bytep *row_pointers = (png_bytep *)memalign (32, sizeof (png_bytep) * texture->height); if (!row_pointers) { free (img_data); png_destroy_write_struct(&png_ptr, &info_ptr); return; } /* store raw image data */ for (i = 0; i < texture->height; i++) { row_pointers[i] = img_data + (i * texture->width * 4); } /* configure libpng for image data */ png_set_rows(png_ptr,info_ptr,row_pointers); /* write data to PNG file */ png_write_png(png_ptr,info_ptr,PNG_TRANSFORM_IDENTITY,NULL); /* finish compression and release memory */ png_write_end(png_ptr, NULL); free(row_pointers); free(img_data); png_destroy_write_struct(&png_ptr, &info_ptr); } void gxTextureClose(gx_texture **p_texture) { gx_texture *texture = *p_texture; if (texture) { if (texture->data) free(texture->data); free(texture); *p_texture = NULL; } } /***************************************************************************************/ /* VIDEO engine */ /***************************************************************************************/ /* Emulation mode -> Menu mode */ void gx_video_Stop(void) { /* unallocate NTSC filters */ if (sms_ntsc) free(sms_ntsc); if (md_ntsc) free(md_ntsc); sms_ntsc = NULL; md_ntsc = NULL; /* lightgun textures */ gxTextureClose(&crosshair[0]); gxTextureClose(&crosshair[1]); /* GX menu rendering */ gxResetRendering(1); gxResetMode(vmode); /* display game snapshot */ gxClearScreen((GXColor)BLACK); gxDrawScreenshot(0xff); /* default VI settings */ VIDEO_SetPreRetraceCallback(NULL); VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu); #ifdef HW_RVL VIDEO_SetTrapFilter(1); VIDEO_SetGamma(VI_GM_1_0); #endif /* adjust TV width */ vmode->viWidth = config.screen_w; vmode->viXOrigin = (VI_MAX_WIDTH_NTSC - vmode->viWidth)/2; VIDEO_Configure(vmode); /* wait for VSYNC */ gxSetScreen(); } /* Menu mode -> Emulation mode */ void gx_video_Start(void) { /* 50Hz/60Hz mode */ if ((config.tv_mode == 1) || ((config.tv_mode == 2) && vdp_pal)) { gc_pal = 1; } else { gc_pal = 0; } #ifdef HW_RVL VIDEO_SetTrapFilter(config.trap); VIDEO_SetGamma((int)(config.gamma * 10.0)); #endif /* VSYNC callbacks */ /* in 60hz mode, frame emulation is synchronized with Video Interrupt */ if (!gc_pal && !vdp_pal) { VIDEO_SetPreRetraceCallback(vi_callback); } VIDEO_SetPostRetraceCallback(NULL); VIDEO_Flush(); /* set interlaced or progressive video mode */ if (config.render == 2) { tvmodes[2]->viTVMode = VI_TVMODE_NTSC_PROG; tvmodes[2]->xfbMode = VI_XFBMODE_SF; } else if (config.render == 1) { tvmodes[2]->viTVMode = tvmodes[0]->viTVMode & ~3; tvmodes[2]->xfbMode = VI_XFBMODE_DF; } /* force video update */ bitmap.viewport.changed = 3; /* NTSC filter */ if (config.ntsc) { /* allocate filters */ if (!sms_ntsc) { sms_ntsc = (sms_ntsc_t *)memalign(32,sizeof(sms_ntsc_t)); } if (!md_ntsc) { md_ntsc = (md_ntsc_t *)memalign(32,sizeof(md_ntsc_t)); } /* setup filters default configuration */ switch (config.ntsc) { case 1: sms_ntsc_init(sms_ntsc, &sms_ntsc_composite); md_ntsc_init(md_ntsc, &md_ntsc_composite); break; case 2: sms_ntsc_init(sms_ntsc, &sms_ntsc_svideo); md_ntsc_init(md_ntsc, &md_ntsc_svideo); break; case 3: sms_ntsc_init(sms_ntsc, &sms_ntsc_rgb); md_ntsc_init(md_ntsc, &md_ntsc_rgb); break; } } /* lightgun textures */ if (config.gun_cursor[0] && ((input.system[1] == SYSTEM_MENACER) || (input.system[1] == SYSTEM_JUSTIFIER) || (input.system[0] == SYSTEM_LIGHTPHASER))) { crosshair[0] = gxTextureOpenPNG(Crosshair_p1_png,0); } if (config.gun_cursor[1] && ((input.system[1] == SYSTEM_JUSTIFIER) || (input.system[1] == SYSTEM_LIGHTPHASER))) { crosshair[1] = gxTextureOpenPNG(Crosshair_p2_png,0); } /* GX emulation rendering */ gxResetRendering(0); /* resynchronize emulation with VSYNC*/ VIDEO_WaitVSync(); } /* GX render update */ void gx_video_Update(void) { int update = bitmap.viewport.changed & 1; /* check if display has changed during frame */ if (update) { /* update texture size */ vwidth = bitmap.viewport.w + (2 * bitmap.viewport.x); vheight = bitmap.viewport.h + (2 * bitmap.viewport.y); /* interlaced mode */ if (config.render && interlaced) { vheight = vheight << 1; } /* ntsc filter */ if (config.ntsc) { vwidth = (reg[12] & 1) ? MD_NTSC_OUT_WIDTH(vwidth) : SMS_NTSC_OUT_WIDTH(vwidth); } /* texels size must be multiple of 4 */ vwidth = (vwidth >> 2) << 2; vheight = (vheight >> 2) << 2; /* initialize texture object */ GXTexObj texobj; GX_InitTexObj(&texobj, texturemem, vwidth, vheight, GX_TF_RGB565, GX_CLAMP, GX_CLAMP, GX_FALSE); /* configure texture filtering */ if (!config.bilinear) { GX_InitTexObjLOD(&texobj,GX_NEAR,GX_NEAR_MIP_NEAR,0.0,10.0,0.0,GX_FALSE,GX_FALSE,GX_ANISO_1); } /* load texture object */ GX_LoadTexObj(&texobj, GX_TEXMAP0); /* update rendering mode */ if (config.render) { rmode = tvmodes[gc_pal*3 + 2]; } else { rmode = tvmodes[gc_pal*3 + interlaced]; } /* update aspect ratio */ gxResetScaler(vwidth); /* update GX rendering mode */ gxResetMode(rmode); /* update VI mode */ VIDEO_Configure(rmode); } /* texture is now directly mapped by the line renderer */ /* force texture cache update */ DCFlushRange(texturemem, TEX_SIZE); GX_InvalidateTexAll(); /* render textured quad */ draw_square(); /* Lightgun # 1 screen mark */ if (crosshair[0]) { if (input.system[0] == SYSTEM_LIGHTPHASER) { gxDrawCrosshair(crosshair[0], input.analog[0][0],input.analog[0][1]); } else { gxDrawCrosshair(crosshair[0], input.analog[4][0],input.analog[4][1]); } } /* Lightgun # 2 screen mark */ if (crosshair[1]) { if (input.system[1] == SYSTEM_LIGHTPHASER) { gxDrawCrosshair(crosshair[1], input.analog[1][0],input.analog[1][1]); } else { gxDrawCrosshair(crosshair[1], input.analog[5][0],input.analog[5][1]); } } /* swap XFB */ whichfb ^= 1; /* copy EFB to XFB */ GX_DrawDone(); GX_CopyDisp(xfb[whichfb], GX_TRUE); GX_Flush(); /* XFB is ready to be displayed */ VIDEO_SetNextFramebuffer(xfb[whichfb]); VIDEO_Flush(); if (update) { /* Clear update flags */ bitmap.viewport.changed &= ~1; /* field synchronization */ VIDEO_WaitVSync(); if (rmode->viTVMode & VI_NON_INTERLACE) { VIDEO_WaitVSync(); } else while (VIDEO_GetNextField() != odd_frame) { VIDEO_WaitVSync(); } /* audio & video resynchronization */ audioStarted = 0; } } /* Initialize VIDEO subsystem */ void gx_video_Init(void) { /* * Before doing anything else under libogc, * Call VIDEO_Init */ VIDEO_Init(); /* * Before any memory is allocated etc. * Rescue any tagged ROM in data 2 */ int *romptr = (int *)0x80700000; StartARAM(); cart.romsize = 0; if (memcmp((char *)romptr,"GENPLUSR",8) == 0) { cart.romsize = romptr[2]; ARAMPut((char *) 0x80700000 + 0x20, (char *) 0x8000, cart.romsize); } /* Get the current VIDEO mode then : - set menu VIDEO mode (480p, 480i or 576i) - set emulator rendering TV modes (PAL/MPAL/NTSC/EURGB60) */ vmode = VIDEO_GetPreferredMode(NULL); /* Adjust display settings */ switch (vmode->viTVMode >> 2) { case VI_PAL: /* 576 lines (PAL 50Hz) */ TV60hz_240p.viTVMode = VI_TVMODE_EURGB60_DS; TV60hz_240i.viTVMode = VI_TVMODE_EURGB60_INT; TV60hz_480i.viTVMode = VI_TVMODE_EURGB60_INT; config.tv_mode = 1; /* use harwdare vertical scaling to fill screen */ vmode = &TVPal574IntDfScale; break; case VI_NTSC: /* 480 lines (NTSC 60hz) */ TV60hz_240p.viTVMode = VI_TVMODE_NTSC_DS; TV60hz_240i.viTVMode = VI_TVMODE_NTSC_INT; TV60hz_480i.viTVMode = VI_TVMODE_NTSC_INT; config.tv_mode = 0; #ifndef HW_RVL /* force 480p on NTSC GameCube if the Component Cable is present */ if (VIDEO_HaveComponentCable()) vmode = &TVNtsc480Prog; #endif break; default: /* 480 lines (PAL 60Hz) */ TV60hz_240p.viTVMode = VI_TVMODE(vmode->viTVMode >> 2, VI_NON_INTERLACE); TV60hz_240i.viTVMode = VI_TVMODE(vmode->viTVMode >> 2, VI_INTERLACE); TV60hz_480i.viTVMode = VI_TVMODE(vmode->viTVMode >> 2, VI_INTERLACE); config.tv_mode = 2; break; } /* Configure VI */ VIDEO_Configure (vmode); /* Configure the framebuffers (double-buffering) */ xfb[0] = (u32 *) MEM_K0_TO_K1((u32 *) SYS_AllocateFramebuffer(&TV50hz_576i)); xfb[1] = (u32 *) MEM_K0_TO_K1((u32 *) SYS_AllocateFramebuffer(&TV50hz_576i)); /* Define a console */ console_init(xfb[0], 20, 64, 640, 574, 574 * 2); /* Clear framebuffers to black */ VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK); VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK); /* Set the framebuffer to be displayed at next VBlank */ VIDEO_SetNextFramebuffer(xfb[0]); /* Enable Video Interface */ VIDEO_SetBlack(FALSE); /* Update VIDEO settings for next VBlank */ VIDEO_Flush(); /* Wait for VBlank */ VIDEO_WaitVSync(); VIDEO_WaitVSync(); /* Initialize GX */ gxStart(); gxResetRendering(1); gxResetMode(vmode); /* initialize FONT */ if (!FONT_Init()) { #ifdef HW_RVL DI_Close(); SYS_ResetSystem(SYS_RESTART,0,0); #else SYS_ResetSystem(SYS_HOTRESET,0,0); #endif } /* Initialize textures */ texturemem = memalign(32, TEX_SIZE); screenshot = memalign(32, HASPECT*VASPECT*4); if (!texturemem || !screenshot) { FONT_writeCenter("Failed to allocate textures memory... Rebooting",18,0,640,200,(GXColor)WHITE); gxSetScreen(); sleep(2); gx_video_Shutdown(); #ifdef HW_RVL DI_Close(); SYS_ResetSystem(SYS_RESTART,0,0); #else SYS_ResetSystem(SYS_HOTRESET,0,0); #endif } } void gx_video_Shutdown(void) { if (texturemem) free(texturemem); if (screenshot) free(screenshot); FONT_Shutdown(); VIDEO_ClearFrameBuffer(vmode, xfb[whichfb], COLOR_BLACK); VIDEO_Flush(); VIDEO_WaitVSync(); }
zyking1987-genplus-droid
genplusgx/gx/gx_video.c
C
gpl2
46,362
/**************************************************************************** * gx_video.c * * Genesis Plus GX video support * * Softdev (2006) * Eke-Eke (2007,2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #ifndef _GC_VIDEO_H_ #define _GC_VIDEO_H_ /* EFB colors */ #define BLACK {0x00,0x00,0x00,0xff} #define DARK_GREY {0x22,0x22,0x22,0xff} #define LIGHT_BLUE {0xb8,0xc7,0xda,0xff} #define SKY_BLUE {0x99,0xcc,0xff,0xff} #define LIGHT_GREEN {0xa9,0xc7,0xc6,0xff} #define WHITE {0xff,0xff,0xff,0xff} /* image texture */ typedef struct { u8 *data; u16 width; u16 height; u8 format; } gx_texture; /* Global variables */ extern GXRModeObj *vmode; extern u8 *texturemem; extern u32 gc_pal; /* GX rendering */ extern void gxDrawRectangle(s32 x, s32 y, s32 w, s32 h, u8 alpha, GXColor color); extern void gxDrawTexture(gx_texture *texture, s32 x, s32 y, s32 w, s32 h, u8 alpha); extern void gxDrawTextureRepeat(gx_texture *texture, s32 x, s32 y, s32 w, s32 h, u8 alpha); extern void gxDrawTextureRotate(gx_texture *texture, s32 x, s32 y, s32 w, s32 h, f32 angle, u8 alpha); extern void gxDrawScreenshot(u8 alpha); extern void gxCopyScreenshot(gx_texture *texture); extern void gxSaveScreenshot(char *filename); extern void gxClearScreen(GXColor color); extern void gxSetScreen(void); /* PNG textures */ extern gx_texture *gxTextureOpenPNG(const u8 *png_data, FILE *png_file); extern void gxTextureWritePNG(gx_texture *p_texture, FILE *png_file); extern void gxTextureClose(gx_texture **p_texture); /* GX video engine */ extern void gx_video_Init(void); extern void gx_video_Shutdown(void); extern void gx_video_Start(void); extern void gx_video_Stop(void); extern void gx_video_Update(void); #endif
zyking1987-genplus-droid
genplusgx/gx/gx_video.h
C
gpl2
2,584
/**************************************************************************** * gx_input.c * * Genesis Plus GX input support * * Eke-Eke (2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "shared.h" #include "font.h" #include "gui.h" #include "cheats.h" #ifdef HW_RVL #include <ogc/usbmouse.h> #endif /* Analog sticks sensitivity */ #define ANALOG_SENSITIVITY 30 /* Delay before held keys triggering */ /* higher is the value, less responsive is the key update */ #define HELD_DELAY 30 /* Direction & selection update speed when a key is being held */ /* lower is the value, faster is the key update */ #define HELD_SPEED 4 /* Configurable keys */ #define KEY_BUTTONA 0 #define KEY_BUTTONB 1 #define KEY_BUTTONC 2 #define KEY_START 3 #define KEY_BUTTONX 4 #define KEY_BUTTONY 5 #define KEY_BUTTONZ 6 #define KEY_MODE 7 #ifdef HW_RVL #define PAD_UP 0 #define PAD_DOWN 1 #define PAD_LEFT 2 #define PAD_RIGHT 3 /* default directions mapping */ static u32 wpad_dirmap[3][4] = { {WPAD_BUTTON_RIGHT, WPAD_BUTTON_LEFT, WPAD_BUTTON_UP, WPAD_BUTTON_DOWN}, /* WIIMOTE */ {WPAD_BUTTON_UP, WPAD_BUTTON_DOWN, WPAD_BUTTON_LEFT, WPAD_BUTTON_RIGHT}, /* WIIMOTE + NUNCHUK */ {WPAD_CLASSIC_BUTTON_UP, WPAD_CLASSIC_BUTTON_DOWN, WPAD_CLASSIC_BUTTON_LEFT, WPAD_CLASSIC_BUTTON_RIGHT} /* CLASSIC */ }; #endif static char keyname[MAX_KEYS][16]; static int held_cnt = 0; /***************************************************************************************/ /* Gamecube PAD support */ /***************************************************************************************/ static void pad_config(int chan, int first_key, int last_key) { u16 p,key; char msg[64]; /* reset VSYNC callback */ VIDEO_SetPostRetraceCallback(NULL); VIDEO_Flush(); /* Check if PAD is connected */ if (!(PAD_ScanPads() & (1<<chan))) { /* restore inputs update callback */ VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu); VIDEO_Flush(); sprintf(msg, "PAD #%d is not connected !", chan+1); GUI_WaitPrompt("Error",msg); return; } /* Configure each keys */ do { /* remove any pending keys */ while (PAD_ButtonsHeld(chan)) { VIDEO_WaitVSync(); PAD_ScanPads(); } /* wait for user input */ sprintf(msg,"Press key for %s\n(D-PAD to return)",keyname[first_key]); GUI_MsgBoxUpdate(0,msg); key = 0; while (!key) { /* update PAD status */ VIDEO_WaitVSync(); PAD_ScanPads(); p = PAD_ButtonsDown(chan); /* find pressed key */ if (p & PAD_BUTTON_A) key = PAD_BUTTON_A; else if (p & PAD_BUTTON_B) key = PAD_BUTTON_B; else if (p & PAD_BUTTON_X) key = PAD_BUTTON_X; else if (p & PAD_BUTTON_Y) key = PAD_BUTTON_Y; else if (p & PAD_TRIGGER_R) key = PAD_TRIGGER_R; else if (p & PAD_TRIGGER_L) key = PAD_TRIGGER_L; else if (p & PAD_TRIGGER_Z) key = PAD_TRIGGER_Z; else if (p & PAD_BUTTON_START) key = PAD_BUTTON_START; else if (p) key = 0xff; } /* exit */ if (key == 0xff) break; /* update key mapping */ config.pad_keymap[chan][first_key] = key; } while (first_key++ < last_key); /* remove any pending keys */ while (PAD_ButtonsHeld(chan)) { VIDEO_WaitVSync(); PAD_ScanPads(); } /* restore inputs update callback */ VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu); VIDEO_Flush(); } static void pad_update(s8 chan, u8 i) { /* PAD status */ u16 p = PAD_ButtonsHeld(chan); s8 x = PAD_StickX (chan); s8 y = PAD_StickY (chan); /* Menu Combo */ if ((p & PAD_TRIGGER_Z) && (p & (PAD_BUTTON_UP | PAD_BUTTON_DOWN | PAD_BUTTON_LEFT | PAD_BUTTON_RIGHT))) { ConfigRequested = 1; return; } /* Retrieve current key mapping */ u16 *pad_keymap = config.pad_keymap[chan]; /* Emulated device */ switch (input.dev[i]) { case DEVICE_PAD6B: { /* Extra buttons */ if (p & pad_keymap[KEY_BUTTONX]) input.pad[i] |= INPUT_X; if (p & pad_keymap[KEY_BUTTONY]) input.pad[i] |= INPUT_Y; if (p & pad_keymap[KEY_BUTTONZ]) input.pad[i] |= INPUT_Z; if (p & pad_keymap[KEY_MODE]) input.pad[i] |= INPUT_MODE; } case DEVICE_PAD3B: { /* D-PAD */ if ((p & PAD_BUTTON_UP) || (y > ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_UP; else if ((p & PAD_BUTTON_DOWN) || (y < -ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_DOWN; if ((p & PAD_BUTTON_LEFT) || (x < -ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_LEFT; else if ((p & PAD_BUTTON_RIGHT) || (x > ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_RIGHT; /* Buttons */ if (p & pad_keymap[KEY_BUTTONA]) input.pad[i] |= INPUT_A; if (p & pad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_B; if (p & pad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_C; if (p & pad_keymap[KEY_START]) input.pad[i] |= INPUT_START; break; } case DEVICE_XE_A1P: { /* Left Stick analog position [0-255] */ input.analog[i][0] = (x + 128); input.analog[i][1] = y ? (127 - y) : (128 - y); /* Right Stick analog position [0-255] */ x = PAD_SubStickX(chan); y = PAD_SubStickY(chan); /* Emulated stick is unidirectional but can be rotated */ if (abs(x) > abs(y)) { input.analog[i+1][0] = (x + 128); } else { input.analog[i+1][0] = (y + 128); } /* Buttons */ if (p & pad_keymap[KEY_BUTTONA]) input.pad[i] |= INPUT_XE_A; if (p & pad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_XE_B; if (p & pad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_XE_C; if (p & pad_keymap[KEY_START]) input.pad[i] |= INPUT_XE_START; if (p & pad_keymap[KEY_BUTTONX]) input.pad[i] |= INPUT_XE_D; if (p & pad_keymap[KEY_BUTTONY]) input.pad[i] |= INPUT_XE_E1; if (p & pad_keymap[KEY_BUTTONZ]) input.pad[i] |= INPUT_XE_E2; if (p & pad_keymap[KEY_MODE]) input.pad[i] |= INPUT_XE_SELECT; break; } case DEVICE_SPORTSPAD: { /* Y analog position [0-255] */ input.analog[i][1] = y ? (127 - y) : (128 - y); } case DEVICE_PADDLE: { /* X analog position [0-255] */ input.analog[i][0] = (x + 128); /* Buttons */ if (p & pad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_BUTTON1; if (p & pad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_BUTTON2; if (p & pad_keymap[KEY_START]) input.pad[i] |= INPUT_START; break; } case DEVICE_PAD2B: { /* D-PAD */ if ((p & PAD_BUTTON_UP) || (y > ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_UP; else if ((p & PAD_BUTTON_DOWN) || (y < -ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_DOWN; if ((p & PAD_BUTTON_LEFT) || (x < -ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_LEFT; else if ((p & PAD_BUTTON_RIGHT) || (x > ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_RIGHT; /* Buttons */ if (p & pad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_BUTTON1; if (p & pad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_BUTTON2; if (p & pad_keymap[KEY_START]) input.pad[i] |= INPUT_START; break; } case DEVICE_LIGHTGUN: { /* Gun screen position (x,y) */ input.analog[i][0] += x / ANALOG_SENSITIVITY; input.analog[i][1] -= y / ANALOG_SENSITIVITY; /* Limits */ if (input.analog[i][0] < 0) input.analog[i][0] = 0; else if (input.analog[i][0] > bitmap.viewport.w) input.analog[i][0] = bitmap.viewport.w; if (input.analog[i][1] < 0) input.analog[i][1] = 0; else if (input.analog[i][1] > bitmap.viewport.h) input.analog[i][1] = bitmap.viewport.h; /* Buttons */ if (p & pad_keymap[KEY_BUTTONA]) input.pad[i] |= INPUT_A; if (p & pad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_B; if (p & pad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_C; if (p & pad_keymap[KEY_START]) input.pad[i] |= INPUT_START; break; } case DEVICE_MOUSE: { /* Mouse relative movement (-255,255) */ input.analog[i][0] = (x / ANALOG_SENSITIVITY) * 2; input.analog[i][1] = (y / ANALOG_SENSITIVITY) * 2; /* Y-Axis inversion */ if (config.invert_mouse) { input.analog[i][1] = -input.analog[i][1]; } /* Buttons */ if (p & pad_keymap[KEY_BUTTONA]) input.pad[i] |= INPUT_MOUSE_CENTER; if (p & pad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_MOUSE_LEFT; if (p & pad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_MOUSE_RIGHT; if (p & pad_keymap[KEY_START]) input.pad[i] |= INPUT_START; break; } case DEVICE_TABLET: { /* D-PAD */ if (p & PAD_BUTTON_UP) input.pad[i] |= INPUT_UP; else if (p & PAD_BUTTON_DOWN) input.pad[i] |= INPUT_DOWN; if (p & PAD_BUTTON_LEFT) input.pad[i] |= INPUT_LEFT; else if (p & PAD_BUTTON_RIGHT) input.pad[i] |= INPUT_RIGHT; /* PEN screen position (x,y) */ input.analog[0][0] += x / ANALOG_SENSITIVITY; input.analog[0][1] -= y / ANALOG_SENSITIVITY; /* Limits */ if (input.analog[0][0] < 0x17c) input.analog[0][0] = 0x17c; else if (input.analog[0][0] > 0x3c) input.analog[0][0] = 0x3c; if (input.analog[0][1] < 0x1fc) input.analog[0][1] = 0x1fc; else if (input.analog[0][1] > 0x3f3) input.analog[0][1] = 0x3f3; /* PEN & RED buttons */ if (p & pad_keymap[KEY_BUTTONA]) input.pad[i] |= INPUT_A; if (p & pad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_B; break; } case DEVICE_ACTIVATOR: { /* Left & right analog stick angle [0-360] */ float ang; /* Left stick values */ if ((abs(x) > ANALOG_SENSITIVITY) || (abs(y) > ANALOG_SENSITIVITY)) { /* Calculate angle (in degree) */ ang = 90.0 - (atan((float)y / (float)x) * 180.0 / M_PI); if (x < 0) ang += 180.0; /* 8 bottom sensors = 8 areas */ if ((ang > 22.5) && (ang <= 67.5)) input.pad[i] |= INPUT_ACTIVATOR_2L; else if ((ang > 67.5) && (ang <= 112.5)) input.pad[i] |= INPUT_ACTIVATOR_3L; else if ((ang > 112.5) && (ang <= 157.5)) input.pad[i] |= INPUT_ACTIVATOR_4L; else if ((ang > 157.5) && (ang <= 202.5)) input.pad[i] |= INPUT_ACTIVATOR_5L; else if ((ang > 202.5) && (ang <= 247.5)) input.pad[i] |= INPUT_ACTIVATOR_6L; else if ((ang > 247.5) && (ang <= 292.5)) input.pad[i] |= INPUT_ACTIVATOR_7L; else if ((ang > 292.5) && (ang <= 337.5)) input.pad[i] |= INPUT_ACTIVATOR_8L; else input.pad[i] |= INPUT_ACTIVATOR_1L; } /* Right stick values */ x = PAD_SubStickX(chan); y = PAD_SubStickY(chan); if ((abs(x) > ANALOG_SENSITIVITY) || (abs(y) > ANALOG_SENSITIVITY)) { /* Calculate angle (in degree) */ ang = 90.0 - (atan((float)y / (float)x) * 180.0 / M_PI); if (x < 0) ang += 180.0; /* 8 top sensors = 8 areas */ if ((ang > 22.5) && (ang <= 67.5)) input.pad[i] |= INPUT_ACTIVATOR_2U; else if ((ang > 67.5) && (ang <= 112.5)) input.pad[i] |= INPUT_ACTIVATOR_3U; else if ((ang > 112.5) && (ang <= 157.5)) input.pad[i] |= INPUT_ACTIVATOR_4U; else if ((ang > 157.5) && (ang <= 202.5)) input.pad[i] |= INPUT_ACTIVATOR_5U; else if ((ang > 202.5) && (ang <= 247.5)) input.pad[i] |= INPUT_ACTIVATOR_6U; else if ((ang > 247.5) && (ang <= 292.5)) input.pad[i] |= INPUT_ACTIVATOR_7U; else if ((ang > 292.5) && (ang <= 337.5)) input.pad[i] |= INPUT_ACTIVATOR_8U; else input.pad[i] |= INPUT_ACTIVATOR_1U; } break; } } } /***************************************************************************************/ /* Wii WPAD support */ /***************************************************************************************/ #ifdef HW_RVL static int wpad_StickX(WPADData *data, u8 right) { struct joystick_t* js = NULL; switch (data->exp.type) { case WPAD_EXP_NUNCHUK: js = right ? NULL : &data->exp.nunchuk.js; break; case WPAD_EXP_CLASSIC: js = right ? &data->exp.classic.rjs : &data->exp.classic.ljs; break; default: break; } if (js) { /* raw X value */ int x = js->pos.x; /* value returned is sometime above calibrated limits */ if (x > js->max.x) return 127; if (x < js->min.x) return -128; /* adjust against center position */ x -= js->center.x; /* return interpolated range [-128;127] */ if (x > 0) { return (int)(127.0 * ((float)x / (float)(js->max.x - js->center.x))); } { return (int)(128.0 * ((float)x / (float)(js->center.x - js->min.x))); } } return 0; } static int wpad_StickY(WPADData *data, u8 right) { struct joystick_t* js = NULL; switch (data->exp.type) { case WPAD_EXP_NUNCHUK: js = right ? NULL : &data->exp.nunchuk.js; break; case WPAD_EXP_CLASSIC: js = right ? &data->exp.classic.rjs : &data->exp.classic.ljs; break; default: break; } if (js) { /* raw Y value */ int y = js->pos.y; /* value returned is sometime above calibrated limits */ if (y > js->max.y) return 127; if (y < js->min.y) return -128; /* adjust against center position */ y -= js->center.y; /* return interpolated range [-128;127] */ if (y > 0) { return (int)(127.0 * ((float)y / (float)(js->max.y - js->center.y))); } { return (int)(128.0 * ((float)y / (float)(js->center.y - js->min.y))); } } return 0; } static void wpad_config(u8 exp, int chan, int first_key, int last_key) { char msg[64]; u32 key,p = 255; /* remove inputs update callback */ VIDEO_SetPostRetraceCallback(NULL); VIDEO_Flush(); /* Check if device is connected */ WPAD_Probe(chan, &p); if (((exp > WPAD_EXP_NONE) && (p != exp)) || (p == 255)) { /* restore inputs update callback */ VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu); VIDEO_Flush(); if (exp == WPAD_EXP_NONE) sprintf(msg, "WIIMOTE #%d is not connected !", chan+1); if (exp == WPAD_EXP_NUNCHUK) sprintf(msg, "NUNCHUK #%d is not connected !", chan+1); if (exp == WPAD_EXP_CLASSIC) sprintf(msg, "CLASSIC #%d is not connected !", chan+1); GUI_WaitPrompt("Error",msg); return; } /* loop on each mapped keys */ do { /* remove any pending buttons */ while (WPAD_ButtonsHeld(chan)) { WPAD_ScanPads(); VIDEO_WaitVSync(); } /* wait for user input */ sprintf(msg,"Press key for %s\n(HOME to return)",keyname[first_key]); GUI_MsgBoxUpdate(0,msg); /* wait for input */ key = 0; while (!key) { VIDEO_WaitVSync(); WPAD_ScanPads(); p = WPAD_ButtonsDown(chan); switch (exp) { /* Wiimote (TODO: add motion sensing !) */ case WPAD_EXP_NONE: { if (p & WPAD_BUTTON_HOME) key = 0xff; else if (p & WPAD_BUTTON_2) key = WPAD_BUTTON_2; else if (p & WPAD_BUTTON_1) key = WPAD_BUTTON_1; else if (p & WPAD_BUTTON_B) key = WPAD_BUTTON_B; else if (p & WPAD_BUTTON_A) key = WPAD_BUTTON_A; else if (p & WPAD_BUTTON_PLUS) key = WPAD_BUTTON_PLUS; else if (p & WPAD_BUTTON_MINUS) key = WPAD_BUTTON_MINUS; break; } /* Wiimote + Nunchuk (TODO: add motion sensing !) */ case WPAD_EXP_NUNCHUK: { if (p & WPAD_BUTTON_HOME) key = 0xff; else if (p & WPAD_BUTTON_2) key = WPAD_BUTTON_2; else if (p & WPAD_BUTTON_1) key = WPAD_BUTTON_1; else if (p & WPAD_BUTTON_B) key = WPAD_BUTTON_B; else if (p & WPAD_BUTTON_A) key = WPAD_BUTTON_A; else if (p & WPAD_BUTTON_PLUS) key = WPAD_BUTTON_PLUS; else if (p & WPAD_BUTTON_MINUS) key = WPAD_BUTTON_MINUS; else if (p & WPAD_NUNCHUK_BUTTON_Z) key = WPAD_NUNCHUK_BUTTON_Z; else if (p & WPAD_NUNCHUK_BUTTON_C) key = WPAD_NUNCHUK_BUTTON_C; break; } /* Classic Controller */ case WPAD_EXP_CLASSIC: { if (p & WPAD_CLASSIC_BUTTON_HOME) key = 0xff; else if (p & WPAD_CLASSIC_BUTTON_X) key = WPAD_CLASSIC_BUTTON_X; else if (p & WPAD_CLASSIC_BUTTON_A) key = WPAD_CLASSIC_BUTTON_A; else if (p & WPAD_CLASSIC_BUTTON_Y) key = WPAD_CLASSIC_BUTTON_Y; else if (p & WPAD_CLASSIC_BUTTON_B) key = WPAD_CLASSIC_BUTTON_B; else if (p & WPAD_CLASSIC_BUTTON_ZL) key = WPAD_CLASSIC_BUTTON_ZL; else if (p & WPAD_CLASSIC_BUTTON_ZR) key = WPAD_CLASSIC_BUTTON_ZR; else if (p & WPAD_CLASSIC_BUTTON_PLUS) key = WPAD_CLASSIC_BUTTON_PLUS; else if (p & WPAD_CLASSIC_BUTTON_MINUS) key = WPAD_CLASSIC_BUTTON_MINUS; else if (p & WPAD_CLASSIC_BUTTON_FULL_L) key = WPAD_CLASSIC_BUTTON_FULL_L; else if (p & WPAD_CLASSIC_BUTTON_FULL_R) key = WPAD_CLASSIC_BUTTON_FULL_R; break; } default: { key = 0xff; break; } } } /* exit */ if (key == 0xff) break; /* update key mapping */ config.wpad_keymap[exp + (chan * 3)][first_key] = key; } while (first_key++ < last_key); /* remove any pending buttons */ while (WPAD_ButtonsHeld(chan)) { WPAD_ScanPads(); VIDEO_WaitVSync(); } /* restore inputs update callback */ VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu); VIDEO_Flush(); } static void wpad_update(s8 chan, u8 i, u32 exp) { /* WPAD data */ WPADData *data = WPAD_Data(chan); /* WPAD status */ u32 p = data->btns_h; /* Menu Key */ if ((p & WPAD_BUTTON_HOME) || (p & WPAD_CLASSIC_BUTTON_HOME)) { ConfigRequested = 1; return; } /* Analog sticks */ s8 x = 0; s8 y = 0; if (exp != WPAD_EXP_NONE) { x = wpad_StickX(data,0); y = wpad_StickY(data,0); } /* Retrieve current key mapping */ u32 *wpad_keymap = config.wpad_keymap[exp + (chan * 3)]; /* Emulated device */ switch (input.dev[i]) { case DEVICE_PAD6B: { /* Extra buttons */ if (p & wpad_keymap[KEY_BUTTONX]) input.pad[i] |= INPUT_X; if (p & wpad_keymap[KEY_BUTTONY]) input.pad[i] |= INPUT_Y; if (p & wpad_keymap[KEY_BUTTONZ]) input.pad[i] |= INPUT_Z; if (p & wpad_keymap[KEY_MODE]) input.pad[i] |= INPUT_MODE; } case DEVICE_PAD3B: { /* D- PAD */ if ((p & wpad_dirmap[exp][PAD_UP]) || (y > ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_UP; else if ((p & wpad_dirmap[exp][PAD_DOWN]) || (y < -ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_DOWN; if ((p & wpad_dirmap[exp][PAD_LEFT]) || (x < -ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_LEFT; else if ((p & wpad_dirmap[exp][PAD_RIGHT]) || (x > ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_RIGHT; /* Buttons */ if (p & wpad_keymap[KEY_BUTTONA]) input.pad[i] |= INPUT_A; if (p & wpad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_B; if (p & wpad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_C; if (p & wpad_keymap[KEY_START]) input.pad[i] |= INPUT_START; break; } case DEVICE_XE_A1P: { /* Left Stick analog position [0-255] */ input.analog[i][0] = (x + 128); input.analog[i][1] = y ? (127 - y) : (128 - y); /* Right Stick analog position [0-255] */ if (exp == WPAD_EXP_CLASSIC) { /* Classic Controller right stick */ x = wpad_StickX(data,1); y = wpad_StickY(data,1); /* Emulated stick is unidirectional but can be rotated */ if (abs(x) > abs(y)) { input.analog[i+1][0] = (x + 128); } else { input.analog[i+1][0] = (y + 128); } } else { /* Wiimote D-PAD */ if ((p & wpad_dirmap[exp][PAD_DOWN]) || (p & wpad_dirmap[exp][PAD_LEFT])) input.analog[i+1][0]-=2; else if ((p & wpad_dirmap[exp][PAD_UP]) || (p & wpad_dirmap[exp][PAD_RIGHT])) input.analog[i+1][0]+=2; /* Limits */ if (input.analog[i+1][0] < 0) input.analog[i+1][0] = 0; else if (input.analog[i+1][0] > 255) input.analog[i+1][0] = 255; } /* Buttons */ if (p & wpad_keymap[KEY_BUTTONA]) input.pad[i] |= INPUT_XE_A; if (p & wpad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_XE_B; if (p & wpad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_XE_C; if (p & wpad_keymap[KEY_START]) input.pad[i] |= INPUT_XE_START; if (p & wpad_keymap[KEY_BUTTONX]) input.pad[i] |= INPUT_XE_D; if (p & wpad_keymap[KEY_BUTTONY]) input.pad[i] |= INPUT_XE_E1; if (p & wpad_keymap[KEY_BUTTONZ]) input.pad[i] |= INPUT_XE_E2; if (p & wpad_keymap[KEY_MODE]) input.pad[i] |= INPUT_XE_SELECT; break; } case DEVICE_SPORTSPAD: { /* X analog position [0-255] */ if (p & wpad_dirmap[exp][PAD_LEFT]) input.analog[i][0]-=2; else if (p & wpad_dirmap[exp][PAD_RIGHT]) input.analog[i][0]+=2; else input.analog[i][0] = (x + 128); /* Y analog position [0-255] */ if (p & wpad_dirmap[exp][PAD_UP]) input.analog[i][1]-=2; else if (p & wpad_dirmap[exp][PAD_DOWN]) input.analog[i][1]+=2; else input.analog[i][1] = y ? (127 - y) : (128 - y); /* Limits */ if (input.analog[i][0] < 0) input.analog[i][0] = 0; else if (input.analog[i][0] > 255) input.analog[i][0] = 255; if (input.analog[i][1] < 0) input.analog[i][1] = 0; else if (input.analog[i][1] > 255) input.analog[i][1] = 255; /* Buttons */ if (p & wpad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_BUTTON1; if (p & wpad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_BUTTON2; if (p & wpad_keymap[KEY_START]) input.pad[i] |= INPUT_START; break; } case DEVICE_PADDLE: { /* X analog position [0-255] */ if (exp == WPAD_EXP_NONE) { /* Wiimote D-PAD */ if (p & wpad_dirmap[exp][PAD_LEFT]) input.analog[i][0]-=2; else if (p & wpad_dirmap[exp][PAD_RIGHT]) input.analog[i][0]+=2; /* Limits */ if (input.analog[i][0] < 0) input.analog[i][0] = 0; else if (input.analog[i][0] > 255) input.analog[i][0] = 255; } else { /* Left analog stick */ input.analog[i][0] = (x + 128); } /* Buttons */ if (p & wpad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_BUTTON1; if (p & wpad_keymap[KEY_START]) input.pad[i] |= INPUT_START; break; } case DEVICE_PAD2B: { /* D-PAD */ if ((p & wpad_dirmap[exp][PAD_UP]) || (y > ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_UP; else if ((p & wpad_dirmap[exp][PAD_DOWN]) || (y < -ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_DOWN; if ((p & wpad_dirmap[exp][PAD_LEFT]) || (x < -ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_LEFT; else if ((p & wpad_dirmap[exp][PAD_RIGHT]) || (x > ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_RIGHT; /* Buttons */ if (p & wpad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_BUTTON1; if (p & wpad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_BUTTON2; if (p & wpad_keymap[KEY_START]) input.pad[i] |= INPUT_START; break; } case DEVICE_LIGHTGUN: { /* Gun screen position (x,y) */ if (exp != WPAD_EXP_CLASSIC) { /* Wiimote IR */ struct ir_t ir; WPAD_IR(chan, &ir); if (ir.valid) { /* screen position */ input.analog[i][0] = (ir.x * bitmap.viewport.w) / 640; input.analog[i][1] = (ir.y * bitmap.viewport.h) / 480; } else { /* lightgun should point outside screen area */ input.analog[i][0] = 512; input.analog[i][1] = 512; } } else { /* Classic Controller analog stick */ input.analog[i][0] += x / ANALOG_SENSITIVITY; input.analog[i][1] -= y / ANALOG_SENSITIVITY; /* Limits */ if (input.analog[i][0] < 0) input.analog[i][0] = 0; else if (input.analog[i][0] > bitmap.viewport.w) input.analog[i][0] = bitmap.viewport.w; if (input.analog[i][1] < 0) input.analog[i][1] = 0; else if (input.analog[i][1] > bitmap.viewport.h) input.analog[i][1] = bitmap.viewport.h; } /* Buttons */ if (p & wpad_keymap[KEY_BUTTONA]) input.pad[i] |= INPUT_A; if (p & wpad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_B; if (p & wpad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_C; if (p & wpad_keymap[KEY_START]) input.pad[i] |= INPUT_START; break; } case DEVICE_MOUSE: { /* Mouse relative movement (-255,255) */ input.analog[i][0] = (x / ANALOG_SENSITIVITY) * 2; input.analog[i][1] = (y / ANALOG_SENSITIVITY) * 2; /* Wiimote IR (buggy) */ if (exp != WPAD_EXP_CLASSIC) { struct ir_t ir; WPAD_IR(chan, &ir); /* Only if Wiimote is pointed to screen */ if(ir.smooth_valid) { input.analog[i][0] = (int)((ir.sx - 512) / 2 / ANALOG_SENSITIVITY); input.analog[i][1] = (int)((ir.sy - 384) * 2 / 3 / ANALOG_SENSITIVITY); } } /* USB mouse support */ if (MOUSE_IsConnected()) { /* read mouse data */ mouse_event event; MOUSE_GetEvent(&event); MOUSE_FlushEvents(); /* mouse position (-127;+127) -> (-255;+255) */ input.analog[i][0] = event.rx * 2; input.analog[i][1] = event.ry * 2; /* mouse buttons */ if (event.button & 1) input.pad[i] |= INPUT_MOUSE_RIGHT; if (event.button & 2) input.pad[i] |= INPUT_MOUSE_CENTER; if (event.button & 4) input.pad[i] |= INPUT_MOUSE_LEFT; } /* Y-Axis inversion */ if (config.invert_mouse) { input.analog[i][1] = -input.analog[i][1]; } /* Buttons */ if (p & wpad_keymap[KEY_BUTTONA]) input.pad[i] |= INPUT_MOUSE_CENTER; if (p & wpad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_MOUSE_LEFT; if (p & wpad_keymap[KEY_BUTTONC]) input.pad[i] |= INPUT_MOUSE_RIGHT; if (p & wpad_keymap[KEY_START]) input.pad[i] |= INPUT_START; break; } case DEVICE_TABLET: { /* D-PAD */ if (p & PAD_BUTTON_UP) input.pad[i] |= INPUT_UP; else if (p & PAD_BUTTON_DOWN) input.pad[i] |= INPUT_DOWN; if (p & PAD_BUTTON_LEFT) input.pad[i] |= INPUT_LEFT; else if (p & PAD_BUTTON_RIGHT) input.pad[i] |= INPUT_RIGHT; /* PEN screen position (x,y) */ input.analog[0][0] += x / ANALOG_SENSITIVITY; input.analog[0][1] -= y / ANALOG_SENSITIVITY; /* Limits */ if (input.analog[0][0] < 0x17c) input.analog[0][0] = 0x17c; else if (input.analog[0][0] > 0x3c) input.analog[0][0] = 0x3c; if (input.analog[0][1] < 0x1fc) input.analog[0][1] = 0x1fc; else if (input.analog[0][1] > 0x3f3) input.analog[0][1] = 0x3f3; /* Wiimote IR */ if (exp != WPAD_EXP_CLASSIC) { struct ir_t ir; WPAD_IR(chan, &ir); if (ir.valid) { input.analog[0][0] = 0x3c + (ir.x * (0x17c - 0x3c + 1)) / 640; input.analog[0][1] = 0x1fc + (ir.y * (0x3f3 - 0x1fc + 1)) / 480; } } /* PEN & RED buttons */ if (p & wpad_keymap[KEY_BUTTONA]) input.pad[i] |= INPUT_A; if (p & wpad_keymap[KEY_BUTTONB]) input.pad[i] |= INPUT_B; break; } case DEVICE_ACTIVATOR: { /* Classic Controller only */ if (exp == WPAD_EXP_CLASSIC) { /* Left stick */ float mag = data->exp.classic.ljs.mag; float ang = data->exp.classic.ljs.ang; if (mag > 0.5) { /* 8 bottom sensors = 8 areas */ if ((ang > 22.5) && (ang <= 67.5)) input.pad[i] |= INPUT_ACTIVATOR_2L; else if ((ang > 67.5) && (ang <= 112.5)) input.pad[i] |= INPUT_ACTIVATOR_3L; else if ((ang > 112.5) && (ang <= 157.5)) input.pad[i] |= INPUT_ACTIVATOR_4L; else if ((ang > 157.5) && (ang <= 202.5)) input.pad[i] |= INPUT_ACTIVATOR_5L; else if ((ang > 202.5) && (ang <= 247.5)) input.pad[i] |= INPUT_ACTIVATOR_6L; else if ((ang > 247.5) && (ang <= 292.5)) input.pad[i] |= INPUT_ACTIVATOR_7L; else if ((ang > 292.5) && (ang <= 337.5)) input.pad[i] |= INPUT_ACTIVATOR_8L; else input.pad[i] |= INPUT_ACTIVATOR_1L; } /* Right stick */ mag = data->exp.classic.rjs.mag; ang = data->exp.classic.rjs.ang; if (mag > 0.5) { /* 8 top sensors = 8 areas */ if ((ang > 22.5) && (ang <= 67.5)) input.pad[i] |= INPUT_ACTIVATOR_2U; else if ((ang > 67.5) && (ang <= 112.5)) input.pad[i] |= INPUT_ACTIVATOR_3U; else if ((ang > 112.5) && (ang <= 157.5)) input.pad[i] |= INPUT_ACTIVATOR_4U; else if ((ang > 157.5) && (ang <= 202.5)) input.pad[i] |= INPUT_ACTIVATOR_5U; else if ((ang > 202.5) && (ang <= 247.5)) input.pad[i] |= INPUT_ACTIVATOR_6U; else if ((ang > 247.5) && (ang <= 292.5)) input.pad[i] |= INPUT_ACTIVATOR_7U; else if ((ang > 292.5) && (ang <= 337.5)) input.pad[i] |= INPUT_ACTIVATOR_8U; else input.pad[i] |= INPUT_ACTIVATOR_1U; } } break; } } } #endif /***************************************************************************************/ /* GX Input interface */ /***************************************************************************************/ void gx_input_Init(void) { PAD_Init (); #ifdef HW_RVL WPAD_Init(); WPAD_SetIdleTimeout(60); WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(WPAD_CHAN_ALL,640,480); #endif VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu); VIDEO_Flush(); } int gx_input_FindDevices(void) { int i; #ifdef HW_RVL u32 wpad; #endif u32 pad = PAD_ScanPads(); int found = 0; int player = 0; for (i=0; i<MAX_DEVICES; i++) { /* check emulated peripheral */ if (input.dev[i] != NO_DEVICE) { /* test input device */ switch (config.input[player].device) { case 0: /* Gamecube Controller */ { if (pad & (1 << config.input[player].port)) { found++; } break; } #ifdef HW_RVL case 1: /* Wiimote */ { wpad = 255; WPAD_Probe(config.input[player].port, &wpad); if (wpad != 255) { found++; } break; } case 2: /* Expansion Controller */ case 3: { wpad = 255; WPAD_Probe(config.input[player].port, &wpad); if (wpad == (config.input[player].device - 1)) { found++; } break; } #endif default: { break; } } /* next configured player */ player ++; } } /* return number of connected devices */ return found; } void gx_input_SetDefault(void) { int i,j; u32 exp; /* set default key mapping for each type of devices */ for (i=0; i<4; i++) { config.pad_keymap[i][KEY_BUTTONA] = PAD_BUTTON_B; config.pad_keymap[i][KEY_BUTTONB] = PAD_BUTTON_A; config.pad_keymap[i][KEY_BUTTONC] = PAD_BUTTON_X; config.pad_keymap[i][KEY_START] = PAD_BUTTON_START; config.pad_keymap[i][KEY_BUTTONX] = PAD_TRIGGER_L; config.pad_keymap[i][KEY_BUTTONY] = PAD_BUTTON_Y; config.pad_keymap[i][KEY_BUTTONZ] = PAD_TRIGGER_R; config.pad_keymap[i][KEY_MODE] = 0; } #ifdef HW_RVL for (i=0; i<4; i++) { /* Wiimote */ config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_BUTTONA] = WPAD_BUTTON_A; config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_BUTTONB] = WPAD_BUTTON_2; config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_BUTTONC] = WPAD_BUTTON_1; config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_START] = WPAD_BUTTON_PLUS; config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_BUTTONX] = 0; config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_BUTTONY] = 0; config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_BUTTONZ] = 0; config.wpad_keymap[i*3 + WPAD_EXP_NONE][KEY_MODE] = 0; /* Wiimote + Nunchuk */ config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_BUTTONA] = WPAD_NUNCHUK_BUTTON_Z; config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_BUTTONB] = WPAD_BUTTON_A; config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_BUTTONC] = WPAD_BUTTON_B; config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_START] = WPAD_BUTTON_PLUS; config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_BUTTONX] = WPAD_NUNCHUK_BUTTON_C; config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_BUTTONY] = WPAD_BUTTON_1; config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_BUTTONZ] = WPAD_BUTTON_2; config.wpad_keymap[i*3 + WPAD_EXP_NUNCHUK][KEY_MODE] = WPAD_BUTTON_MINUS; /* Classic Controller */ config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_BUTTONA] = WPAD_CLASSIC_BUTTON_Y; config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_BUTTONB] = WPAD_CLASSIC_BUTTON_B; config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_BUTTONC] = WPAD_CLASSIC_BUTTON_A; config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_START] = WPAD_CLASSIC_BUTTON_PLUS; config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_BUTTONX] = WPAD_CLASSIC_BUTTON_ZL; config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_BUTTONY] = WPAD_CLASSIC_BUTTON_X; config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_BUTTONZ] = WPAD_CLASSIC_BUTTON_ZR; config.wpad_keymap[i*3 + WPAD_EXP_CLASSIC][KEY_MODE] = WPAD_CLASSIC_BUTTON_MINUS; } #endif /* Default player inputs */ for (i=0; i<MAX_INPUTS; i++) { config.input[i].device = -1; config.input[i].port = i%4; config.input[i].padtype = 0; } #ifdef HW_RVL /* Autodetect Wii Controllers */ VIDEO_WaitVSync(); for (i=0; i<4; i++) { /* try to autodetect connected controller */ exp = 255; WPAD_Probe(i, &exp); if (exp == WPAD_EXP_CLASSIC) { /* use Classic Controller */ config.input[i].device = 3; config.input[i].port = i; } else if (exp == WPAD_EXP_NUNCHUK) { /* use Wiimote + Nunchuk */ config.input[i].device = 2; config.input[i].port = i; } else if (exp <= EXP_MOTION_PLUS) { /* use Wiimote by default */ config.input[i].device = 1; config.input[i].port = i; } else { /* look for unused Wiimotes */ for (j=0; j<i; j++) { /* Classic Controller is assigned, which means Wiimote is free to use */ if (config.input[j].device == (WPAD_EXP_CLASSIC + 1)) { /* assign wiimote */ config.input[i].device = 1; config.input[i].port = j; } } } } #endif /* Autodetect Gamecube Controllers */ VIDEO_WaitVSync(); exp = PAD_ScanPads(); for (i=0; i<4; i++) { /* check if Gamecube Controller is connected */ if (exp & (1 << i)) { for (j=0; j<MAX_INPUTS; j++) { /* look for the first unassigned player */ if (config.input[j].device == -1) { config.input[j].device = 0; config.input[j].port = i; j = MAX_INPUTS; } } } } /* default emulated inputs */ input.system[0] = SYSTEM_MD_GAMEPAD; input.system[1] = (config.input[1].device != -1) ? SYSTEM_MD_GAMEPAD : NO_SYSTEM; } void gx_input_Config(u8 chan, u8 device, u8 type) { int first_key, last_key; /* emulated device */ switch (type) { case DEVICE_PADDLE: case DEVICE_PAD2B: case DEVICE_SPORTSPAD: { first_key = KEY_BUTTONB; last_key = KEY_START; sprintf(keyname[KEY_BUTTONB],"Button 1"); sprintf(keyname[KEY_BUTTONC],"Button 2"); sprintf(keyname[KEY_START],"PAUSE Button"); break; } case DEVICE_XE_A1P: { first_key = KEY_BUTTONA; last_key = KEY_MODE; sprintf(keyname[KEY_BUTTONA],"Button A"); sprintf(keyname[KEY_BUTTONB],"Button B"); sprintf(keyname[KEY_BUTTONC],"Button C"); sprintf(keyname[KEY_START],"START Button"); sprintf(keyname[KEY_BUTTONX],"Button D"); sprintf(keyname[KEY_BUTTONY],"Button E1"); sprintf(keyname[KEY_BUTTONZ],"Button E2"); sprintf(keyname[KEY_MODE],"SELECT Button"); break; } case DEVICE_MOUSE: { first_key = KEY_BUTTONA; last_key = KEY_START; sprintf(keyname[KEY_BUTTONA],"Middle Button"); sprintf(keyname[KEY_BUTTONB],"Left Button"); sprintf(keyname[KEY_BUTTONC],"Right Button"); sprintf(keyname[KEY_START],"START Button"); break; } case DEVICE_PAD3B: { first_key = KEY_BUTTONA; last_key = KEY_START; sprintf(keyname[KEY_BUTTONA],"Button A"); sprintf(keyname[KEY_BUTTONB],"Button B"); sprintf(keyname[KEY_BUTTONC],"Button C"); sprintf(keyname[KEY_START],"START Button"); break; } case DEVICE_PAD6B: { first_key = KEY_BUTTONA; last_key = KEY_MODE; sprintf(keyname[KEY_BUTTONA],"Button A"); sprintf(keyname[KEY_BUTTONB],"Button B"); sprintf(keyname[KEY_BUTTONC],"Button C"); sprintf(keyname[KEY_START],"START Button"); sprintf(keyname[KEY_BUTTONX],"Button X"); sprintf(keyname[KEY_BUTTONY],"Button Y"); sprintf(keyname[KEY_BUTTONZ],"Button Z"); sprintf(keyname[KEY_MODE],"MODE Button"); break; } case DEVICE_LIGHTGUN: { if ((input.system[1] == SYSTEM_MENACER) || (input.system[1] == SYSTEM_JUSTIFIER)) { first_key = KEY_BUTTONA; last_key = KEY_START; sprintf(keyname[KEY_BUTTONA],"Button A"); sprintf(keyname[KEY_BUTTONB],"Button B"); sprintf(keyname[KEY_BUTTONC],"Button C"); sprintf(keyname[KEY_START],"START Button"); } else { first_key = KEY_BUTTONB; last_key = KEY_START; sprintf(keyname[KEY_BUTTONB],"Button 1 (Fire)"); sprintf(keyname[KEY_BUTTONC],"Button 2"); sprintf(keyname[KEY_START],"PAUSE Button"); } break; } case DEVICE_TABLET: { first_key = KEY_BUTTONA; last_key = KEY_BUTTONB; sprintf(keyname[KEY_BUTTONA],"PEN Button"); sprintf(keyname[KEY_BUTTONB],"RED Button"); break; } default: { GUI_WaitPrompt("Info","Activator is not configurable !"); return; } } /* Input device */ switch (device) { case 0: { pad_config(chan, first_key, last_key); break; } default: { #ifdef HW_RVL wpad_config(device - 1, chan, first_key, last_key); #endif break; } } } void gx_input_UpdateEmu(void) { /* Update controllers */ PAD_ScanPads(); #ifdef HW_RVL WPAD_ScanPads(); #endif int i, player = 0; for (i=0; i<MAX_DEVICES; i++) { /* update inputs */ if (input.dev[i] != NO_DEVICE) { /* clear key status */ input.pad[i] = 0; if (config.input[player].device == 0) { pad_update(config.input[player].port, i); } #ifdef HW_RVL else if (config.input[player].device > 0) { wpad_update(config.input[player].port, i, config.input[player].device - 1); } #endif /* increment player index */ player ++; } } /* Update RAM patches */ CheatUpdate(); } /* Menu inputs update function (done by Video Interrupt callback) */ void gx_input_UpdateMenu(u32 cnt) { /* PAD status update */ PAD_ScanPads(); /* PAD pressed keys */ s16 pp = PAD_ButtonsDown(0); /* PAD held keys (direction/selection) */ s16 hp = PAD_ButtonsHeld(0) & (PAD_BUTTON_UP|PAD_BUTTON_DOWN|PAD_BUTTON_LEFT|PAD_BUTTON_RIGHT|PAD_BUTTON_A); /* PAD analog sticks (handled as PAD held direction keys) */ s8 x = PAD_StickX(0); s8 y = PAD_StickY(0); if (x > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_RIGHT; else if (x < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_LEFT; else if (y > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_UP; else if (y < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_DOWN; #ifdef HW_RVL /* WPAD status update */ WPAD_ScanPads(); WPADData *data = WPAD_Data(0); /* WPAD pressed keys */ u32 pw = data->btns_d; /* WPAD held keys (direction/selection) */ u32 hw = data->btns_h & (WPAD_CLASSIC_BUTTON_UP|WPAD_CLASSIC_BUTTON_DOWN|WPAD_CLASSIC_BUTTON_LEFT|WPAD_CLASSIC_BUTTON_RIGHT|WPAD_BUTTON_UP|WPAD_BUTTON_DOWN|WPAD_BUTTON_LEFT|WPAD_BUTTON_RIGHT|WPAD_BUTTON_A|WPAD_BUTTON_2); /* WPAD analog sticks (handled as PAD held direction keys) */ x = wpad_StickX(data, 0); y = wpad_StickY(data, 0); if (x > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_RIGHT; else if (x < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_LEFT; else if (y > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_UP; else if (y < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_DOWN; #endif /* check if any direction/selection key is being held or just being pressed/released */ #ifdef HW_RVL if (pp||pw) held_cnt = 0; else if (hp||hw) held_cnt++; else held_cnt = 0; #else if (pp) held_cnt = 0; else if (hp) held_cnt++; else held_cnt = 0; #endif /* initial delay (prevents triggering to start immediately) */ if (held_cnt > HELD_DELAY) { /* key triggering */ pp |= hp; #ifdef HW_RVL pw |= hw; #endif /* delay until next triggering (adjusts direction/selection update speed) */ held_cnt -= HELD_SPEED; } #ifdef HW_RVL /* Wiimote direction keys */ WPAD_IR(0, &m_input.ir); if (m_input.ir.valid) { /* Wiimote is handled vertically */ if (pw & WPAD_BUTTON_UP) pp |= PAD_BUTTON_UP; else if (pw & WPAD_BUTTON_DOWN) pp |= PAD_BUTTON_DOWN; else if (pw & WPAD_BUTTON_LEFT) pp |= PAD_BUTTON_LEFT; else if (pw & WPAD_BUTTON_RIGHT) pp |= PAD_BUTTON_RIGHT; } else { /* Wiimote is handled horizontally */ if (pw & WPAD_BUTTON_UP) pp |= PAD_BUTTON_LEFT; else if (pw & WPAD_BUTTON_DOWN) pp |= PAD_BUTTON_RIGHT; else if (pw & WPAD_BUTTON_LEFT) pp |= PAD_BUTTON_DOWN; else if (pw & WPAD_BUTTON_RIGHT) pp |= PAD_BUTTON_UP; } /* Classic Controller direction keys */ if (pw & WPAD_CLASSIC_BUTTON_UP) pp |= PAD_BUTTON_UP; else if (pw & WPAD_CLASSIC_BUTTON_DOWN) pp |= PAD_BUTTON_DOWN; else if (pw & WPAD_CLASSIC_BUTTON_LEFT) pp |= PAD_BUTTON_LEFT; else if (pw & WPAD_CLASSIC_BUTTON_RIGHT) pp |= PAD_BUTTON_RIGHT; /* WPAD buttons */ if (pw & WPAD_BUTTON_MINUS) pp |= PAD_TRIGGER_L; if (pw & WPAD_BUTTON_PLUS) pp |= PAD_TRIGGER_R; if (pw & WPAD_BUTTON_A) pp |= PAD_BUTTON_A; if (pw & WPAD_BUTTON_B) pp |= PAD_BUTTON_B; if (pw & WPAD_BUTTON_2) pp |= PAD_BUTTON_A; if (pw & WPAD_BUTTON_1) pp |= PAD_BUTTON_B; if (pw & WPAD_BUTTON_HOME) pp |= PAD_TRIGGER_Z; if (pw & WPAD_CLASSIC_BUTTON_FULL_L) pp |= PAD_TRIGGER_L; if (pw & WPAD_CLASSIC_BUTTON_FULL_R) pp |= PAD_TRIGGER_R; if (pw & WPAD_CLASSIC_BUTTON_A) pp |= PAD_BUTTON_A; if (pw & WPAD_CLASSIC_BUTTON_B) pp |= PAD_BUTTON_B; if (pw & WPAD_CLASSIC_BUTTON_HOME) pp |= PAD_TRIGGER_Z; #endif /* Update menu inputs */ m_input.keys = pp; }
zyking1987-genplus-droid
genplusgx/gx/gx_input.c
C
gpl2
45,637
/**************************************************************************** * gx_audio.c * * Genesis Plus GX audio support * * Softdev (2006) * Eke-Eke (2007,2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "shared.h" /* DMA soundbuffers (required to be 32-bytes aligned) Length is dimensionned for one frame of emulation (800/808 samples @60hz, 960 samples@50Hz) To prevent audio clashes, we use double buffering technique: one buffer is the active DMA buffer the other one is the current work buffer (updated during frame emulation) We do not need more since frame emulation and DMA operation are synchronized */ u8 soundbuffer[2][3840] ATTRIBUTE_ALIGN(32); /* Current work soundbuffer */ u32 mixbuffer; /* audio DMA status */ u32 audioStarted; /* Background music */ static u8 *Bg_music_ogg = NULL; static u32 Bg_music_ogg_size = 0; /***************************************************************************************/ /* Audio engine */ /***************************************************************************************/ /* Audio DMA callback */ static void ai_callback(void) { frameticker++; } /* AUDIO engine initialization */ void gx_audio_Init(void) { /* Initialize AUDIO processing library (ASNDLIB) */ /* AUDIO & DSP hardware are initialized */ /* Default samplerate is set to 48kHz */ ASND_Init(); /* Load background music from FAT device */ char fname[MAXPATHLEN]; sprintf(fname,"%s/Bg_music.ogg",DEFAULT_PATH); FILE *f = fopen(fname,"rb"); if (f) { struct stat filestat; stat(fname, &filestat); Bg_music_ogg_size = filestat.st_size; Bg_music_ogg = memalign(32,Bg_music_ogg_size); if (Bg_music_ogg) { fread(Bg_music_ogg,1,Bg_music_ogg_size,f); } fclose(f); } } /* AUDIO engine shutdown */ void gx_audio_Shutdown(void) { PauseOgg(1); StopOgg(); ASND_Pause(1); ASND_End(); if (Bg_music_ogg) { free(Bg_music_ogg); } } /*** gx_audio_Update This function retrieves samples for the frame then set the next DMA parameters Parameters will be taken in account only when current DMA operation is over ***/ void gx_audio_Update(void) { /* retrieve audio samples */ int size = audio_update() * 4; /* set next DMA soundbuffer */ s16 *sb = (s16 *)(soundbuffer[mixbuffer]); DCFlushRange((void *)sb, size); AUDIO_InitDMA((u32) sb, size); mixbuffer ^= 1; /* Start Audio DMA */ /* this is called once to kick-off DMA from external memory to audio interface */ /* DMA operation is automatically restarted when all samples have been sent. */ /* If DMA settings are not updated at that time, previous sound buffer will be used. */ /* Therefore we need to make sure frame emulation is completed before current DMA is */ /* completed, either by synchronizing frame emulation with DMA start or by syncing it */ /* with Vertical Interrupt and outputing a suitable number of samples per frame. */ /* */ /* In both cases, audio DMA need to be synchronized with VSYNC and therefore need to */ /* be resynchronized (restarted) every time video settings are changed (hopefully, */ /* this generally happens while no music is played. */ if (!audioStarted) { /* restart audio DMA */ AUDIO_StopDMA(); AUDIO_StartDMA(); audioStarted = 1; /* resynchronize emulation */ frameticker = 1; } } /*** gx_audio_Start This function restart the audio engine This is called when coming back from Main Menu ***/ void gx_audio_Start(void) { /* shutdown background music */ PauseOgg(1); StopOgg(); /* shutdown menu audio processing */ ASND_Pause(1); AUDIO_StopDMA(); AUDIO_RegisterDMACallback(NULL); DSP_Halt(); /* when not using 60hz mode, frame emulation is synchronized with Audio Interface DMA */ if (gc_pal | vdp_pal) { AUDIO_RegisterDMACallback(ai_callback); } /* reset emulation audio processing */ memset(soundbuffer, 0, 2 * 3840); audioStarted = 0; mixbuffer = 0; } /*** gx_audio_Stop This function stops current Audio DMA process This is called when going back to Main Menu DMA need to be restarted when going back to the game (see above) ***/ void gx_audio_Stop(void) { /* restart menu audio processing */ DSP_Unhalt(); ASND_Init(); ASND_Pause(0); /* play background music */ if (Bg_music_ogg && !Shutdown) { PauseOgg(0); PlayOgg((char *)Bg_music_ogg, Bg_music_ogg_size, 0, OGG_INFINITE_TIME); SetVolumeOgg(((int)config.bgm_volume * 255) / 100); } }
zyking1987-genplus-droid
genplusgx/gx/gx_audio.c
C
gpl2
5,764
/**************************************************************************** * main.c * * Genesis Plus GX * * Softdev (2006) * Eke-Eke (2007-2010) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "shared.h" #include "font.h" #include "gui.h" #include "menu.h" #include "aram.h" #include "history.h" #include "file_slot.h" #include "file_load.h" #include "filesel.h" #include "cheats.h" #include <fat.h> #ifdef HW_RVL #include <wiiuse/wpad.h> #endif /* audio "exact" samplerate, measured on real hardware */ #ifdef HW_RVL #define SAMPLERATE_48KHZ 48000 #else #define SAMPLERATE_48KHZ 48044 #endif u32 Shutdown = 0; u32 ConfigRequested = 1; #ifdef HW_RVL /**************************************************************************** * Power Button callback ***************************************************************************/ static void PowerOff_cb(void) { Shutdown = 1; ConfigRequested = 1; } #endif /**************************************************************************** * Reset Button callback ***************************************************************************/ static void Reset_cb(void) { gen_reset(0); } /*************************************************************************** * Genesis Plus Virtual Machine * ***************************************************************************/ static void load_bios(void) { /* clear BIOS detection flag */ config.tmss &= ~2; /* open BIOS file */ FILE *fp = fopen(OS_ROM, "rb"); if (fp == NULL) return; /* read file */ fread(bios_rom, 1, 0x800, fp); fclose(fp); /* check ROM file */ if (!strncmp((char *)(bios_rom + 0x120),"GENESIS OS", 10)) { /* valid BIOS detected */ config.tmss |= 2; } } static void init_machine(void) { /* allocate cart.rom here (10 MBytes) */ cart.rom = memalign(32, MAXROMSIZE); if (!cart.rom) { FONT_writeCenter("Failed to allocate ROM buffer... Rebooting",18,0,640,200,(GXColor)WHITE); gxSetScreen(); sleep(2); gx_audio_Shutdown(); gx_video_Shutdown(); #ifdef HW_RVL DI_Close(); SYS_ResetSystem(SYS_RESTART,0,0); #else SYS_ResetSystem(SYS_HOTRESET,0,0); #endif } /* BIOS support */ load_bios(); /* allocate global work bitmap */ memset (&bitmap, 0, sizeof (bitmap)); bitmap.width = 720; bitmap.height = 576; bitmap.depth = 16; bitmap.granularity = 2; bitmap.pitch = bitmap.width * bitmap.granularity; bitmap.viewport.w = 256; bitmap.viewport.h = 224; bitmap.viewport.x = 0; bitmap.viewport.y = 0; bitmap.data = texturemem; } static void run_emulation(void) { /* main emulation loop */ while (1) { /* Main Menu request */ if (ConfigRequested) { /* stop video & audio */ gx_audio_Stop(); gx_video_Stop(); /* show menu */ menu_execute(); ConfigRequested = 0; /* start video & audio */ gx_video_Start(); gx_audio_Start(); frameticker = 1; } /* automatic frame skipping */ if (frameticker > 1) { /* skip frame */ system_frame(1); frameticker = 1; } else { /* render frame */ frameticker = 0; system_frame(0); /* update video */ gx_video_Update(); } /* update audio */ gx_audio_Update(); /* check interlaced mode change */ if (bitmap.viewport.changed & 4) { /* in original 60hz modes, audio is synced with framerate */ if (!config.render && !vdp_pal && (config.tv_mode != 1)) { u8 *temp = memalign(32,YM2612GetContextSize()); if (temp) { /* save YM2612 context */ memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize()); /* framerate has changed, reinitialize audio timings */ audio_init(SAMPLERATE_48KHZ, interlaced ? 59.94 : (1000000.0/16715.0)); sound_init(); /* restore YM2612 context */ YM2612Restore(temp); free(temp); } } /* clear flag */ bitmap.viewport.changed &= ~4; } /* wait for next frame */ while (frameticker < 1) usleep(1); } } /************************************************** Load a new rom and performs some initialization ***************************************************/ void reloadrom (int size, char *name) { /* hot-swap previous & current cartridge */ bool hotswap = config.hot_swap && cart.romsize; /* ROM size */ cart.romsize = size; /* load ROM file */ load_rom(name); /* ROM filename without extension*/ sprintf(rom_filename,"%s",name); rom_filename[strlen(rom_filename) - 4] = 0; if (hotswap) { if (system_hw == SYSTEM_PBC) { sms_cart_init(); sms_cart_reset(); } else { md_cart_init(); md_cart_reset(1); } } else { /* initialize audio emulation */ /* To prevent any sound skipping, sound chips must run at the exact same speed as the rest of emulation (see sound.c) */ /* In 60hz video modes with NTSC emulation, we need perfect synchronization with video hardware interrupt (VSYNC) */ /* Wii & GC framerate has been measured to be exactly 59.94 fps in 240i/480i/480p video modes, ~59.825 fps in 240p */ /* In other modes, emulation is synchronized with audio hardware instead and we use default framerates (50Hz for PAL, 60Hz for NTSC). */ float framerate = vdp_pal ? 50.0 : ((config.tv_mode == 1) ? 60.0 : (config.render ? 59.94 : (1000000.0/16715.0))); /* output samplerate has been measured to be ~48044 samples/sec on GC, 48000 samples/sec on Wii */ audio_init(SAMPLERATE_48KHZ, framerate); /* system power ON */ system_init (); system_reset (); } /* load Cheats */ CheatLoad(); /* load SRAM */ if (config.s_auto & 1) { slot_autoload(0,config.s_device); } /* load State */ if (config.s_auto & 2) { slot_autoload(config.s_default,config.s_device); } } /************************************************** Shutdown everything properly ***************************************************/ void shutdown(void) { /* save current config */ config_save(); /* save current game state */ if (config.s_auto & 2) { slot_autosave(config.s_default,config.s_device); } /* shutdown emulation */ system_shutdown(); audio_shutdown(); free(cart.rom); gx_audio_Shutdown(); gx_video_Shutdown(); #ifdef HW_RVL DI_Close(); #endif } /*************************************************************************** * M A I N * ***************************************************************************/ u32 frameticker = 0; int main (int argc, char *argv[]) { char pathname[MAXPATHLEN]; #ifdef HW_RVL /* initialize DI interface */ DI_UseCache(0); DI_Init(); #endif /* initialize video engine */ gx_video_Init(); #ifdef HW_DOL /* initialize DVD interface */ DVD_Init (); #endif /* initialize input engine */ gx_input_Init(); /* initialize FAT devices */ int retry = 0; int fatMounted = 0; /* try to mount FAT devices during 3 seconds */ while (!fatMounted && (retry < 12)) { fatMounted = fatInitDefault(); usleep(250000); retry++; } if (fatMounted) { /* base directory */ sprintf (pathname, DEFAULT_PATH); DIR_ITER *dir = diropen(pathname); if (dir) dirclose(dir); else mkdir(pathname,S_IRWXU); /* default SRAM & Savestate files directory */ sprintf (pathname, "%s/saves",DEFAULT_PATH); dir = diropen(pathname); if (dir) dirclose(dir); else mkdir(pathname,S_IRWXU); /* default Snapshot files directory */ sprintf (pathname, "%s/snaps",DEFAULT_PATH); dir = diropen(pathname); if (dir) dirclose(dir); else mkdir(pathname,S_IRWXU); /* default Cheat files directory */ sprintf (pathname, "%s/cheats",DEFAULT_PATH); dir = diropen(pathname); if (dir) dirclose(dir); else mkdir(pathname,S_IRWXU); } /* initialize sound engine */ gx_audio_Init(); /* initialize genesis plus core */ legal(); config_default(); history_default(); init_machine(); /* run any injected rom */ if (cart.romsize) { int size = cart.romsize; cart.romsize = 0; ARAMFetch((char *)cart.rom, (void *)0x8000, size); reloadrom(size,"INJECT.bin"); ConfigRequested = 0; gx_video_Start(); gx_audio_Start(); frameticker = 1; } else if (config.autoload) { SILENT = 1; if (OpenDirectory(TYPE_RECENT)) { int size = LoadFile(cart.rom,0,pathname); if (size) { reloadrom(size,pathname); gx_video_Start(); gx_audio_Start(); frameticker = 1; ConfigRequested = 0; } } SILENT = 0; } #ifdef HW_RVL /* power button callback */ SYS_SetPowerCallback(PowerOff_cb); #endif /* reset button callback */ SYS_SetResetCallback(Reset_cb); /* main emulation loop */ run_emulation(); /* we should never return anyway */ return 0; }
zyking1987-genplus-droid
genplusgx/gx/main.c
C
gpl2
10,184
/**************************************************************************** * gui.c * * generic GUI Engine (using GX rendering) * * Eke-Eke (2009,2010) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "shared.h" #include "gui.h" #include "font.h" #ifdef HW_RVL gx_texture *w_pointer; #endif u8 SILENT = 0; /* message box */ static gui_message message_box; static lwp_t msgboxthread; /* background color */ static GXColor bg_color; /* various background colors */ static GXColor bg_colors[BG_COLOR_MAX]= { {0x00,0x00,0x00,0xff}, /* black */ {0xd4,0xd0,0xc8,0xff}, /* cream */ {0xbb,0xb0,0x99,0xff}, /* gold */ {0xd6,0xcb,0xba,0xff}, /* light gold */ {0xcc,0xcc,0xcc,0xff}, /* light grey */ {0x66,0x66,0x66,0xff}, /* faded grey */ {0x50,0x51,0x5b,0xff}, /* grey blue */ {0xb8,0xc7,0xda,0xff}, /* light blue */ {0xc0,0xcf,0xe7,0xff}, /* sky blue */ {0x98,0xb1,0xd8,0xff}, /* sea blue */ {0x7b,0x8c,0xa6,0xff}, /* violet */ {0xa9,0xc7,0xc6,0xff}, /* green blue */ {0x7d,0xa4,0x9f,0xff}, /* darker green blue */ {0x22,0x52,0x74,0xff}, /* dark blue */ {0x33,0x33,0x33,0xff} /* dark grey */ }; /*****************************************************************************/ /* Generic GUI routines */ /*****************************************************************************/ /* Allocate Menu texture images data */ void GUI_InitMenu(gui_menu *menu) { int i; gui_item *item; gui_butn *button; gui_image *image; /* background elements */ for (i=0; i<menu->max_images; i++) { image = &menu->bg_images[i]; image->texture = gxTextureOpenPNG(image->data,0); } for (i=0; i<2; i++) { /* key helpers */ item = menu->helpers[i]; if (item) item->texture = gxTextureOpenPNG(item->data,0); /* arrows */ button = menu->arrows[i]; if (button) { if (!button->data->texture[0]) button->data->texture[0] = gxTextureOpenPNG(button->data->image[0],0); if (!button->data->texture[1]) button->data->texture[1] = gxTextureOpenPNG(button->data->image[1],0); /* initial state */ button->state &= ~BUTTON_VISIBLE; if (((i==0) && (menu->offset != 0)) || ((i==1) && (menu->offset + menu->max_buttons) < menu->max_items)) button->state |= BUTTON_VISIBLE; } } /* menu buttons */ for (i=0; i<menu->max_buttons; i++) { button = &menu->buttons[i]; if (button->data) { if (!button->data->texture[0]) button->data->texture[0] = gxTextureOpenPNG(button->data->image[0],0); if (!button->data->texture[1]) button->data->texture[1] = gxTextureOpenPNG(button->data->image[1],0); } } /* menu items */ for (i=0; i<menu->max_items; i++) { item = &menu->items[i]; if (item->data) item->texture = gxTextureOpenPNG(item->data,0); } /* update message box */ message_box.parent = menu; } /* Release Menu allocated memory */ void GUI_DeleteMenu(gui_menu *menu) { int i; gui_butn *button; gui_item *item; gui_image *image; /* background elements */ for (i=0; i<menu->max_images; i++) { image = &menu->bg_images[i]; gxTextureClose(&image->texture); } for (i=0; i<2; i++) { /* key helpers */ item = menu->helpers[i]; if (item) gxTextureClose(&item->texture); /* arrows */ button = menu->arrows[i]; if (button) { gxTextureClose(&button->data->texture[0]); gxTextureClose(&button->data->texture[1]); } } /* menu buttons */ for (i=0; i<menu->max_buttons; i++) { button = &menu->buttons[i]; if (button->data) { gxTextureClose(&button->data->texture[0]); gxTextureClose(&button->data->texture[1]); } } /* menu items */ for (i=0; i<menu->max_items; i++) { item = &menu->items[i]; gxTextureClose(&item->texture); } } extern void gxSnapshot(void); /* Draw Menu */ void GUI_DrawMenu(gui_menu *menu) { int i; gui_item *item; gui_butn *button; gui_image *image; /* background color */ if (menu->screenshot) { gxClearScreen((GXColor)BLACK); gxDrawScreenshot(menu->screenshot); } else { gxClearScreen(bg_color); } /* background elements */ for (i=0; i<menu->max_images; i++) { image = &menu->bg_images[i]; if (image->state & IMAGE_VISIBLE) { if (image->state & IMAGE_REPEAT) gxDrawTextureRepeat(image->texture,image->x,image->y,image->w,image->h,image->alpha); else gxDrawTexture(image->texture,image->x,image->y,image->w,image->h,image->alpha); } } /* menu title */ FONT_write(menu->title, 22,10,56,640,(GXColor)WHITE); /* draw buttons + items */ for (i=0; i<menu->max_buttons; i++) { button = &menu->buttons[i]; if (button->state & BUTTON_VISIBLE) { /* item select (text or image) */ item = (menu->items) ? (&menu->items[menu->offset + i]) : NULL; /* draw button + items */ if ((i == menu->selected) || (button->state & BUTTON_SELECTED)) { if (button->data) gxDrawTexture(button->data->texture[1],button->x-4,button->y-4,button->w+8,button->h+8,255); if (item) { if (item->texture) { gxDrawTexture(item->texture, item->x-4,item->y-4,item->w+8,item->h+8,255); FONT_writeCenter(item->text,18,button->x+4,item->x-4,button->y+(button->h - 36)/2+18,(GXColor)DARK_GREY); } else { FONT_writeCenter(item->text,18,item->x-4,item->x+item->w+4,button->y+(button->h-18)/2+18,(GXColor)DARK_GREY); } } } else { if (button->data) gxDrawTexture(button->data->texture[0],button->x,button->y,button->w, button->h,255); if (item) { if (item->texture) { gxDrawTexture(item->texture,item->x,item->y,item->w,item->h,255); FONT_writeCenter(item->text,16,button->x+8,item->x,button->y+(button->h - 32)/2+16,(GXColor)DARK_GREY); } else { FONT_writeCenter(item->text,16,item->x,item->x+item->w,button->y+(button->h - 16)/2+16,(GXColor)DARK_GREY); } } } } } /* draw arrow */ for (i=0; i<2; i++) { button = menu->arrows[i]; if (button) { if (button->state & BUTTON_VISIBLE) { if (menu->selected == (menu->max_buttons + i)) gxDrawTexture(button->data->texture[1],button->x-2,button->y-2,button->w+4,button->h+4,255); else gxDrawTexture(button->data->texture[0],button->x,button->y,button->w, button->h,255); } } } /* left comment */ item = menu->helpers[0]; if (item) { if (item->data && strlen(item->comment)) { gxDrawTexture(item->texture,item->x,item->y,item->w,item->h,255); FONT_write(item->comment,16,item->x+item->w+6,item->y+(item->h-16)/2 + 16,640,(GXColor)WHITE); } } /* right comment */ item = menu->helpers[1]; if (item) { if (item->data && strlen(item->comment)) { gxDrawTexture(item->texture,item->x,item->y,item->w,item->h,255); FONT_alignRight(item->comment,16,item->x-6,item->y+(item->h-16)/2+16,(GXColor)WHITE); } } if (menu->cb) menu->cb(); } /* Draw Menu with transitions effects */ void GUI_DrawMenuFX(gui_menu *menu, u8 speed, u8 out) { int i,temp,xoffset,yoffset; int max_offset = 0; u8 item_alpha = 255; GXColor text_color = DARK_GREY; gui_item *item; gui_butn *button; gui_image *image; /* find maximal offset */ for (i=0; i<menu->max_images; i++) { image = &menu->bg_images[i]; if (image->state & IMAGE_SLIDE_LEFT) { temp = image->x + image->w; if (max_offset < temp) max_offset = temp; } else if (image->state & IMAGE_SLIDE_RIGHT) { temp = 640 - image->x; if (max_offset < temp) max_offset = temp; } if (image->state & IMAGE_SLIDE_TOP) { temp = image->y + image->h; if (max_offset < temp) max_offset = temp; } else if (image->state & IMAGE_SLIDE_BOTTOM) { temp = 480 - image->y; if (max_offset < temp) max_offset = temp; } } temp = max_offset; /* Alpha steps */ int alpha = 0; int alpha_step = (255 * speed) / max_offset; if (out) { alpha = 255; alpha_step = -alpha_step; } /* Let's loop until final position has been reached */ while (temp > 0) { /* background color */ if (menu->screenshot) { gxClearScreen((GXColor)BLACK); if (alpha >= menu->screenshot) gxDrawScreenshot(menu->screenshot); else gxDrawScreenshot(255 - alpha); } else { gxClearScreen(bg_color); } /* background images */ for (i=0; i<menu->max_images; i++) { image = &menu->bg_images[i]; /* X offset */ if (image->state & IMAGE_SLIDE_LEFT) xoffset = out ? (temp - max_offset) : (-temp); else if (image->state & IMAGE_SLIDE_RIGHT) xoffset = out ? (max_offset - temp) : (temp); else xoffset = 0; /* Y offset */ if (image->state & IMAGE_SLIDE_TOP) yoffset = out ? (temp - max_offset) : (-temp); else if (image->state & IMAGE_SLIDE_BOTTOM) yoffset = out ? (max_offset - temp) : (temp); else yoffset = 0; /* draw image */ if ((image->state & IMAGE_FADE) && ((out && (image->alpha > alpha)) || (!out && (image->alpha < alpha)))) { /* FADE In-Out */ if (image->state & IMAGE_VISIBLE) { if (image->state & IMAGE_REPEAT) gxDrawTextureRepeat(image->texture,image->x+xoffset,image->y+yoffset,image->w,image->h,alpha); else gxDrawTexture(image->texture,image->x+xoffset,image->y+yoffset,image->w,image->h,alpha); } } else { if (image->state & IMAGE_VISIBLE) { if (image->state & IMAGE_REPEAT) gxDrawTextureRepeat(image->texture,image->x+xoffset,image->y+yoffset,image->w,image->h,image->alpha); else gxDrawTexture(image->texture,image->x+xoffset,image->y+yoffset,image->w,image->h,image->alpha); } } } /* menu title */ if ((menu->bg_images[2].state & IMAGE_SLIDE_TOP) || (menu->bg_images[3].state & IMAGE_SLIDE_TOP)) FONT_write(menu->title, 22,10,out ? (56 + temp - max_offset) : (56 - temp),640,(GXColor)WHITE); else FONT_write(menu->title, 22,10,56,640,(GXColor)WHITE); /* draw buttons + items */ for (i=0; i<menu->max_buttons; i++) { button = &menu->buttons[i]; if (button->state & BUTTON_VISIBLE) { /* X offset */ if (button->state & BUTTON_SLIDE_LEFT) xoffset = out ? (temp - max_offset) : (-temp); else if (button->state & BUTTON_SLIDE_RIGHT) xoffset = out ? (max_offset - temp) : (temp); else xoffset = 0; /* Y offset */ if (button->state & BUTTON_SLIDE_TOP) yoffset = out ? (temp - max_offset) : (-temp); else if (button->state & BUTTON_SLIDE_BOTTOM) yoffset = out ? (max_offset - temp) : (temp); else yoffset = 0; /* Alpha transparency */ if (button->state & BUTTON_FADE) { item_alpha = alpha; text_color.a = alpha; } else { item_alpha = 255; text_color.a = 255; } /* item select (text or image) */ item = (menu->items) ? (&menu->items[menu->offset + i]) : NULL; /* draw button + items */ if ((i == menu->selected) || (button->state & BUTTON_SELECTED)) { if (button->data) gxDrawTexture(button->data->texture[1],button->x+xoffset-4,button->y+yoffset-4,button->w+8,button->h+8,item_alpha); if (item) { if (item->texture) { gxDrawTexture(item->texture, item->x+xoffset-4,item->y+yoffset-4,item->w+8,item->h+8,item_alpha); FONT_writeCenter(item->text,18,button->x+xoffset+4,item->x+xoffset-4,button->y+yoffset+(button->h - 36)/2+18,text_color); } else { FONT_writeCenter(item->text,18,item->x+xoffset+2,item->x+item->w+xoffset+2,button->y+yoffset+(button->h-18)/2+18,text_color); } } } else { if (button->data) gxDrawTexture(button->data->texture[0],button->x+xoffset,button->y+yoffset,button->w, button->h,item_alpha); if (item) { if (item->texture) { gxDrawTexture(item->texture,item->x+xoffset,item->y+yoffset,item->w,item->h,item_alpha); FONT_writeCenter(item->text,16,button->x+xoffset+8,item->x+xoffset,button->y+yoffset+(button->h - 32)/2+16,text_color); } else { FONT_writeCenter(item->text,16,item->x+xoffset,item->x+item->w+xoffset,button->y+yoffset+(button->h - 16)/2+16,text_color); } } } } } /* draw arrow */ for (i=0; i<2; i++) { button = menu->arrows[i]; if (button) { if (button->state & BUTTON_VISIBLE) { if (menu->selected == (menu->max_buttons + i)) gxDrawTexture(button->data->texture[1],button->x-2,button->y-2,button->w+4,button->h+4,255); else gxDrawTexture(button->data->texture[0],button->x,button->y,button->w, button->h,255); } } } if (!(menu->bg_images[3].state & IMAGE_SLIDE_BOTTOM) && !(menu->bg_images[4].state & IMAGE_SLIDE_BOTTOM)) { /* left comment */ item = menu->helpers[0]; if (item) { if (item->data && strlen(item->comment)) { gxDrawTexture(item->texture,item->x,item->y,item->w,item->h,255); FONT_write(item->comment,16,item->x+item->w+6,item->y+(item->h-16)/2 + 16,640,(GXColor)WHITE); } } /* right comment */ item = menu->helpers[1]; if (item) { if (item->data && strlen(item->comment)) { gxDrawTexture(item->texture,item->x,item->y,item->w,item->h,255); FONT_alignRight(item->comment,16,item->x-6,item->y+(item->h-16)/2+16,(GXColor)WHITE); } } } if (menu->cb) menu->cb(); /* update offset */ temp -= speed; /* update alpha */ alpha += alpha_step; if (alpha > 255) alpha = 255; else if (alpha < 0) alpha = 0; /* copy EFB to XFB */ gxSetScreen(); } /* final position */ if (!out) { GUI_DrawMenu(menu); gxSetScreen(); } else if (menu->screenshot) { gxClearScreen((GXColor)BLACK); gxDrawScreenshot(255); gxSetScreen(); } } /* Basic menu title slide effect */ void GUI_SlideMenuTitle(gui_menu *m, int title_offset) { #ifdef HW_RVL gui_butn *button; int i,x,y; #endif char title[64]; strcpy(title,m->title); while (title_offset > 0) { /* update title */ strcpy(m->title,title+title_offset); m->title[strlen(title)-title_offset-1] = 0; /* draw menu */ GUI_DrawMenu(m); #ifdef HW_RVL /* keep pointer active */ if (m_input.ir.valid) { /* get cursor position */ x = m_input.ir.x; y = m_input.ir.y; /* draw wiimote pointer */ gxDrawTextureRotate(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,m_input.ir.angle,255); /* check for valid buttons */ m->selected = m->max_buttons + 2; for (i=0; i<m->max_buttons; i++) { button = &m->buttons[i]; if ((button->state & BUTTON_ACTIVE)&&(x>=button->x)&&(x<=(button->x+button->w))&&(y>=button->y)&&(y<=(button->y+button->h))) { m->selected = i; break; } } for (i=0; i<2; i++) { button = m->arrows[i]; if (button) { if (button->state & BUTTON_VISIBLE) { if ((x<=(button->x+button->w))&&(y>=button->y)&&(y<=(button->y+button->h))) { m->selected = m->max_buttons + i; break; } } } } } #endif gxSetScreen(); usleep(6000); title_offset--; } strcpy(m->title,title); } /* Update current menu */ int GUI_UpdateMenu(gui_menu *menu) { u16 p; int ret = 0; int selected = menu->selected; int max_items = menu->max_items; int max_buttons = menu->max_buttons; gui_butn *button; #ifdef HW_RVL if (Shutdown) { GUI_DeleteMenu(menu); GUI_FadeOut(); shutdown(); SYS_ResetSystem(SYS_POWEROFF, 0, 0); } else if (m_input.ir.valid) { /* get cursor position */ int x = m_input.ir.x; int y = m_input.ir.y; /* draw wiimote pointer */ gxDrawTextureRotate(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,m_input.ir.angle,255); /* check for valid buttons */ selected = max_buttons + 2; int i; for (i=0; i<max_buttons; i++) { button = &menu->buttons[i]; if ((button->state & BUTTON_ACTIVE) && (button->state & BUTTON_VISIBLE)) { if((x>=button->x)&&(x<=(button->x+button->w))&&(y>=button->y)&&(y<=(button->y+button->h))) { selected = i; break; } } } for (i=0; i<2; i++) { button = menu->arrows[i]; if (button) { if ((button->state & BUTTON_ACTIVE) && (button->state & BUTTON_VISIBLE)) { if ((x<=(button->x+button->w))&&(y>=button->y)&&(y<=(button->y+button->h))) { selected = max_buttons + i; break; } } } } } else { /* reinitialize selection */ if (selected >= menu->max_buttons) { selected = 0; while ((selected < (menu->max_buttons + 2)) && (!(menu->buttons[selected].state & BUTTON_ACTIVE) || !(menu->buttons[selected].state & BUTTON_VISIBLE))) selected++; } } #endif /* update screen */ gxSetScreen(); /* update menu */ p = m_input.keys; if (selected < max_buttons) { button = &menu->buttons[selected]; if (p & PAD_BUTTON_UP) { selected -= button->shift[0]; if (selected < 0) { selected = 0; if (menu->offset) menu->offset --; } } else if (p & PAD_BUTTON_DOWN) { selected += button->shift[1]; if (selected >= max_buttons) { selected = max_buttons - 1; if ((menu->offset + selected) < (max_items - 1)) menu->offset ++; } } else if (p & PAD_BUTTON_LEFT) { selected -= button->shift[2]; if (selected < 0) { selected = 0; if (menu->offset) menu->offset --; } } else if (p & PAD_BUTTON_RIGHT) { selected += button->shift[3]; if (selected >= max_buttons) { selected = max_buttons - 1; if ((menu->offset + selected) < (max_items - 1)) menu->offset ++; } } } if (p & PAD_BUTTON_A) { if (selected < max_buttons) ret = 1; /* menu clicked */ else if (selected == max_buttons) menu->offset --; /* up arrow */ else if (selected == (max_buttons+1)) menu->offset ++; /* down arrow */ } else if ((p & PAD_BUTTON_B) || (p & PAD_TRIGGER_Z)) { /* quit menu */ ret = -1; } /* selected item has changed ? */ if (menu->selected != selected) { if (selected < max_buttons) { /* sound fx */ button = &menu->buttons[selected]; if (button->state & BUTTON_OVER_SFX) { ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size, ((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL); } } else if (selected < (max_buttons + 2)) { /* sound fx */ button = menu->arrows[selected-max_buttons]; if (button->state & BUTTON_OVER_SFX) { ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size, ((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL); } } /* update selection */ menu->selected = selected; } /* update helper comment */ if (menu->helpers[1]) { if ((menu->offset + selected) < max_items) { gui_item *item = &menu->items[menu->offset + selected]; strcpy(menu->helpers[1]->comment,item->comment); } else { strcpy(menu->helpers[1]->comment,""); } } if (ret > 0) { if (selected < max_buttons) { /* sound fx */ button = &menu->buttons[selected]; if (button->state & BUTTON_SELECT_SFX) { ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_select_pcm,button_select_pcm_size, ((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL); } } } return ret; } /* Generic routine to render & update menus */ int GUI_RunMenu(gui_menu *menu) { int update = 0; /* update menu */ while (!update) { GUI_DrawMenu(menu); update = GUI_UpdateMenu(menu); /* update arrows buttons status (items list) */ if (menu->arrows[0]) { if (menu->offset > 0) menu->arrows[0]->state |= BUTTON_VISIBLE; else menu->arrows[0]->state &= ~BUTTON_VISIBLE; } if (menu->arrows[1]) { if ((menu->offset + menu->max_buttons) < menu->max_items) menu->arrows[1]->state |= BUTTON_VISIBLE; else menu->arrows[1]->state &= ~BUTTON_VISIBLE; } } if (update == 2) return (-2-menu->offset-menu->selected); else if (update == 1) return (menu->offset + menu->selected); else return -1; } /* Text Window */ void GUI_TextWindow(gui_menu *parent, char *title, char items[][64], u8 nb_items, u8 fontsize) { int i, quit = 0; #ifdef HW_RVL int x,y; #endif /* initialize window */ gx_texture *window = gxTextureOpenPNG(Frame_s1_png,0); gx_texture *top = gxTextureOpenPNG(Frame_s1_title_png,0); /* window position */ int xwindow = (640 - window->width) /2; int ywindow = (480 - window->height)/2; /* text position */ int ypos = ywindow + top->height + (window->height - top->height - fontsize*nb_items) / 2 + fontsize/2; /* disable helper comment */ const u8 *data = NULL; if (parent->helpers[1]) { data = parent->helpers[1]->data; parent->helpers[1]->data = NULL; } /* slide in */ int yoffset = ywindow + window->height; while (yoffset > 0) { /* draw parent menu */ GUI_DrawMenu(parent); /* draw window */ gxDrawTexture(window,xwindow,ywindow-yoffset,window->width,window->height,230); gxDrawTexture(top,xwindow,ywindow-yoffset,top->width,top->height,255); /* draw title */ FONT_writeCenter(title,20,xwindow,xwindow+window->width,ywindow+(top->height-20)/2+20-yoffset,(GXColor)WHITE); /* draw text */ for (i=0; i<nb_items; i++) FONT_writeCenter(items[i],fontsize,xwindow,xwindow+window->width,ypos+i*fontsize-yoffset,(GXColor)WHITE); /* update display */ gxSetScreen(); /* slide speed */ yoffset -= 60; } /* draw menu + text window */ while (quit == 0) { /* draw parent menu */ GUI_DrawMenu(parent); /* draw window */ gxDrawTexture(window,xwindow,ywindow,window->width,window->height,230); gxDrawTexture(top,xwindow,ywindow,top->width,top->height,255); /* draw title */ FONT_writeCenter(title,20,xwindow,xwindow+window->width,ywindow+(top->height-20)/2+20,(GXColor)WHITE); /* draw text */ for (i=0; i<nb_items; i++) { FONT_writeCenter(items[i],fontsize,xwindow,xwindow+window->width,ypos+i*fontsize,(GXColor)WHITE); } #ifdef HW_RVL if (Shutdown) { gxTextureClose(&window); gxTextureClose(&top); gxTextureClose(&w_pointer); GUI_DeleteMenu(parent); GUI_FadeOut(); shutdown(); SYS_ResetSystem(SYS_POWEROFF, 0, 0); } else if (m_input.ir.valid) { /* get cursor position */ x = m_input.ir.x; y = m_input.ir.y; /* draw wiimote pointer */ gxDrawTextureRotate(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,m_input.ir.angle,255); } #endif /* update screen */ gxSetScreen(); /* wait for exit buttons */ if (m_input.keys) quit = 1; } /* reset initial vertical offset */ /* slide out */ yoffset = 0; while (yoffset < (ywindow + window->height)) { /* draw parent menu */ GUI_DrawMenu(parent); /* draw window */ gxDrawTexture(window,xwindow,ywindow-yoffset,window->width,window->height,230); gxDrawTexture(top,xwindow,ywindow-yoffset,top->width,top->height,255); /* draw title */ FONT_writeCenter(title,20,xwindow,xwindow+window->width,ywindow+(top->height-20)/2+20-yoffset,(GXColor)WHITE); /* draw text */ for (i=0; i<nb_items; i++) FONT_writeCenter(items[i],fontsize,xwindow,xwindow+window->width,ypos+i*fontsize-yoffset,(GXColor)WHITE); /* update display */ gxSetScreen(); /* slide speed */ yoffset += 60; } /* restore helper comment */ if (parent->helpers[1]) parent->helpers[1]->data = data; /* final position */ GUI_DrawMenu(parent); gxSetScreen(); /* close textures */ gxTextureClose(&window); gxTextureClose(&top); } /* Option Window (returns selected item) */ int GUI_OptionWindow(gui_menu *parent, char *title, char *items[], u8 nb_items) { int i, ret, quit = 0; int old, selected = 0; s16 p; butn_data button; #ifdef HW_RVL int x,y; #endif /* initialize buttons data */ button.texture[0] = gxTextureOpenPNG(Button_text_png,0); button.texture[1] = gxTextureOpenPNG(Button_text_over_png,0); /* initialize texture window */ gx_texture *window = gxTextureOpenPNG(Frame_s1_png,0); gx_texture *top = gxTextureOpenPNG(Frame_s1_title_png,0); /* get initial positions */ int w = button.texture[0]->width; int h = button.texture[0]->height; int xwindow = (640 - window->width)/2; int ywindow = (480 - window->height)/2; int xpos = xwindow + (window->width - w)/2; int ypos = (window->height - top->height - (h*nb_items) - (nb_items-1)*20)/2; ypos = ypos + ywindow + top->height; /* disable helper comment */ const u8 *data = NULL; if (parent->helpers[1]) { data = parent->helpers[1]->data; parent->helpers[1]->data = 0; } /* slide in */ int yoffset = ywindow + window->height; while (yoffset > 0) { /* draw parent menu */ GUI_DrawMenu(parent); /* draw window */ gxDrawTexture(window,xwindow,ywindow-yoffset,window->width,window->height,230); gxDrawTexture(top,xwindow,ywindow-yoffset,top->width,top->height,255); /* draw title */ FONT_writeCenter(title,20,xwindow,xwindow+window->width,ywindow+(top->height-20)/2+20-yoffset,(GXColor)WHITE); /* draw buttons + text */ for (i=0; i<nb_items; i++) { gxDrawTexture(button.texture[0],xpos,ypos+i*(20 + h)-yoffset,w,h,255); FONT_writeCenter(items[i],18,xpos,xpos+w,ypos+i*(20 + h)+(h + 18)/2- yoffset,(GXColor)DARK_GREY); } /* update display */ gxSetScreen(); /* slide speed */ yoffset -= 60; } /* draw menu */ while (quit == 0) { /* draw parent menu (should have been initialized first) */ GUI_DrawMenu(parent); /* draw window */ gxDrawTexture(window,xwindow,ywindow,window->width,window->height,230); gxDrawTexture(top,xwindow,ywindow,top->width,top->height,255); /* draw title */ FONT_writeCenter(title,20,xwindow,xwindow+window->width,ywindow+(top->height-20)/2+20,(GXColor)WHITE); /* draw buttons + text */ for (i=0; i<nb_items; i++) { if (i==selected) { gxDrawTexture(button.texture[1],xpos-4,ypos+i*(20+h)-4,w+8,h+8,255); FONT_writeCenter(items[i],22,xpos,xpos+w,ypos+i*(20+h)+(h+22)/2,(GXColor)DARK_GREY); } else { gxDrawTexture(button.texture[0],xpos,ypos+i*(20 + h),w,h,255); FONT_writeCenter(items[i],18,xpos,xpos+w,ypos+i*(20+h)+(h+18)/2,(GXColor)DARK_GREY); } } old = selected; p = m_input.keys; #ifdef HW_RVL if (Shutdown) { gxTextureClose(&window); gxTextureClose(&top); gxTextureClose(&button.texture[0]); gxTextureClose(&button.texture[1]); gxTextureClose(&w_pointer); GUI_DeleteMenu(parent); GUI_FadeOut(); shutdown(); SYS_ResetSystem(SYS_POWEROFF, 0, 0); } else if (m_input.ir.valid) { /* get cursor position */ x = m_input.ir.x; y = m_input.ir.y; /* draw wiimote pointer */ gxDrawTextureRotate(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,m_input.ir.angle,255); /* check for valid buttons */ selected = -1; for (i=0; i<nb_items; i++) { if ((x>=xpos)&&(x<=(xpos+w))&&(y>=ypos+i*(20 + h))&&(y<=(ypos+i*(20+h)+h))) { selected = i; break; } } } else { /* reinitialize selection */ if (selected == -1) selected = 0; } #endif /* update screen */ gxSetScreen(); /* update selection */ if (p & PAD_BUTTON_UP) { if (selected > 0) selected --; } else if (p & PAD_BUTTON_DOWN) { if (selected < (nb_items -1)) selected ++; } /* sound fx */ if (selected != old) { if (selected >= 0) { ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size, ((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL); } } if (p & PAD_BUTTON_A) { if (selected >= 0) { quit = 1; ret = selected; } } else if (p & PAD_BUTTON_B) { quit = 1; ret = -1; } } /* slide out */ yoffset = 0; while (yoffset < (ywindow + window->height)) { /* draw parent menu */ GUI_DrawMenu(parent); /* draw window + header */ gxDrawTexture(window,xwindow,ywindow-yoffset,window->width,window->height,230); gxDrawTexture(top,xwindow,ywindow-yoffset,top->width,top->height,255); /* draw title */ FONT_writeCenter(title,20,xwindow,xwindow+window->width,ywindow+(top->height-20)/2+20-yoffset,(GXColor)WHITE); /* draw buttons + text */ for (i=0; i<nb_items; i++) { gxDrawTexture(button.texture[0],xpos,ypos+i*(20+h)-yoffset,w,h,255); FONT_writeCenter(items[i],18,xpos,xpos+w,ypos+i*(20+h)+(h+18)/2-yoffset,(GXColor)WHITE); } /* update display */ gxSetScreen(); /* slide speed */ yoffset += 60; } /* restore helper comment */ if (parent->helpers[1]) parent->helpers[1]->data = data; /* final position */ GUI_DrawMenu(parent); gxSetScreen(); /* close textures */ gxTextureClose(&window); gxTextureClose(&top); gxTextureClose(&button.texture[0]); gxTextureClose(&button.texture[1]); return ret; } /* Option Box */ void GUI_OptionBox(gui_menu *parent, optioncallback cb, char *title, void *option, float step, float min, float max, u8 type) { gx_texture *arrow[2]; arrow[0] = gxTextureOpenPNG(Button_arrow_png,0); arrow[1] = gxTextureOpenPNG(Button_arrow_over_png,0); gx_texture *window = gxTextureOpenPNG(Frame_s2_png,0); gx_texture *top = gxTextureOpenPNG(Frame_s2_title_png,0); /* window position */ int xwindow = 166; int ywindow = 160; /* arrows position */ int xleft = 206; int xright = 392; int yleft = 238; int yright = 238; /* disable action button helper */ if (parent->helpers[1]) parent->helpers[1]->data = 0; /* slide in */ char msg[16]; int yoffset = ywindow + window->height; while (yoffset > 0) { /* draw parent menu */ GUI_DrawMenu(parent); /* draw window */ gxDrawTexture(window,xwindow,ywindow-yoffset,window->width,window->height,225); gxDrawTexture(top,xwindow,ywindow-yoffset,top->width,top->height,255); /* display title */ FONT_writeCenter(title,20,xwindow,xwindow+window->width,ywindow+(top->height-20)/2+20-yoffset,(GXColor)WHITE); /* update display */ gxSetScreen(); /* slide speed */ yoffset -= 60; } /* display option box */ int quit = 0; int modified = 0; int selected = -1; s16 p; #ifdef HW_RVL int x,y; #endif while (!quit) { /* draw parent menu */ GUI_DrawMenu(parent); /* draw window */ gxDrawTexture(window,xwindow,ywindow,window->width,window->height,225); gxDrawTexture(top,xwindow,ywindow,top->width,top->height,255); /* display title */ FONT_writeCenter(title,20,xwindow,xwindow+window->width,ywindow+(top->height-20)/2+20,(GXColor)WHITE); /* option type */ if (type) { /* integer type */ if (*(s16 *)option < 0) sprintf(msg,"-%d",abs(*(s16 *)option)); else sprintf(msg,"%d",abs(*(s16 *)option)); } else { /* float type */ if (*(float *)option < 0.0) sprintf(msg,"-%1.2f",fabs(*(float *)option)); else sprintf(msg,"%1.2f",fabs(*(float *)option)); } /* draw option text */ FONT_writeCenter(msg,24,xwindow,xwindow+window->width,272,(GXColor)WHITE); /* update inputs */ p = m_input.keys; /* draw buttons */ if (selected < 0) { /* nothing selected */ gxDrawTexture(arrow[0],xleft,yleft,arrow[0]->width,arrow[0]->height,255); gxDrawTextureRotate(arrow[0],xright,yright,arrow[0]->width,arrow[0]->height,180.0,255); } #ifdef HW_RVL else if (selected) { /* right button selected */ gxDrawTexture(arrow[0],xleft,yleft,arrow[0]->width,arrow[0]->height,255); gxDrawTextureRotate(arrow[1],xright-4,yright-4,arrow[1]->width+8,arrow[1]->height+8,180.0,255); } else { /* left button selected */ gxDrawTexture(arrow[1],xleft-4,yleft-4,arrow[1]->width+8,arrow[1]->height+8,255); gxDrawTextureRotate(arrow[0],xright,yright,arrow[0]->width,arrow[0]->height,180.0,255); } selected = -1; if (Shutdown) { gxTextureClose(&arrow[0]); gxTextureClose(&arrow[1]); gxTextureClose(&window); gxTextureClose(&top); gxTextureClose(&w_pointer); GUI_DeleteMenu(parent); GUI_FadeOut(); shutdown(); SYS_ResetSystem(SYS_POWEROFF, 0, 0); } else if (m_input.ir.valid) { /* get cursor position */ x = m_input.ir.x; y = m_input.ir.y; /* draw wiimote pointer */ gxDrawTextureRotate(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,m_input.ir.angle,255); /* check for valid buttons */ if ((x>=xleft)&&(x<=(xleft+arrow[0]->width))&&(y>=yleft)&&(y<=(yleft+arrow[0]->height))) { selected = 0; if (p & PAD_BUTTON_A) p |= PAD_BUTTON_LEFT; } else if ((x>=xright)&&(x<=(xright+arrow[0]->width))&&(y>=yright)&&(y<=(yright+arrow[0]->height))) { selected = 1; if (p & PAD_BUTTON_A) p |= PAD_BUTTON_RIGHT; } } #endif /* update screen */ gxSetScreen(); /* check input */ if (p&PAD_BUTTON_LEFT) { /* decrement option value */ if (type) { /* integer type */ *(s16 *)option -= (s16)step; if (*(s16 *)option < (s16)min) *(s16 *)option = (s16)max; } else { /* float type */ *(float *)option -= step; if (*(float *)option < min) *(float *)option = max; } modified = 1; } else if (p&PAD_BUTTON_RIGHT) { /* increment option value */ if (type) { /* integer type */ *(s16 *)option += (s16)step; if (*(s16 *)option > (s16)max) *(s16 *)option = (s16)min; } else { /* float type */ *(float *)option += step; if (*(float *)option > max) *(float *)option = min; } modified = 1; } else if (p & PAD_BUTTON_B) { quit = 1; } if (modified) { modified = 0; /* play sound effect */ ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size, ((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL); /* option callback */ if (cb) cb(); } } /* slide out */ yoffset = 0; ; while (yoffset < (ywindow + window->height)) { /* draw parent menu */ GUI_DrawMenu(parent); /* draw window */ gxDrawTexture(window,xwindow,ywindow-yoffset,window->width,window->height,225); gxDrawTexture(top,xwindow,ywindow-yoffset,top->width,top->height,255); /* display title */ FONT_writeCenter(title,20,xwindow,xwindow+window->width,ywindow+(top->height-20)/2+20-yoffset,(GXColor)WHITE); /* update display */ gxSetScreen(); /* slide speed */ yoffset += 60; } /* restore action button helper */ if (parent->helpers[1]) parent->helpers[1]->data = Key_A_png; /* final position */ GUI_DrawMenu(parent); gxSetScreen(); /* close textures */ gxTextureClose(&arrow[0]); gxTextureClose(&arrow[1]); gxTextureClose(&window); gxTextureClose(&top); } /* Option Box with two parameters */ void GUI_OptionBox2(gui_menu *parent, char *text_1, char *text_2, s16 *option_1, s16 *option_2, s16 step, s16 min, s16 max) { gx_texture *arrow[2]; arrow[0] = gxTextureOpenPNG(Button_arrow_png,0); arrow[1] = gxTextureOpenPNG(Button_arrow_over_png,0); gx_texture *window = gxTextureOpenPNG(Frame_s2_png,0); /* window position */ int xwindow = 166; int ywindow = 160; /* arrows position */ int arrow_pos[4][2] = { {144,218}, {452,218}, {298,138}, {298,298} }; /* disable action button helper */ if (parent->helpers[1]) parent->helpers[1]->data = 0; /* slide in */ char msg[16]; int yoffset = ywindow + window->height; while (yoffset > 0) { /* draw parent menu */ GUI_DrawMenu(parent); /* draw window */ gxDrawTexture(window,xwindow,ywindow-yoffset,window->width,window->height,225); /* update display */ gxSetScreen(); /* slide speed */ yoffset -= 60; } /* display option box */ int quit = 0; int modified = 0; s16 p; #ifdef HW_RVL int selected = -1; int i,x,y; #endif while (!quit) { /* draw parent menu */ GUI_DrawMenu(parent); /* draw window */ gxDrawTexture(window,xwindow,ywindow,window->width,window->height,225); /* draw options text */ if (*option_1 < 0) sprintf(msg,"%s: -%02d",text_1,abs(*option_1)); else sprintf(msg,"%s: +%02d",text_1,abs(*option_1)); FONT_writeCenter(msg,24,xwindow,xwindow+window->width,240,(GXColor)WHITE); if (*option_2 < 0) sprintf(msg,"%s: -%02d",text_2,abs(*option_2)); else sprintf(msg,"%s: +%02d",text_2,abs(*option_2)); FONT_writeCenter(msg,24,xwindow,xwindow+window->width,264,(GXColor)WHITE); /* update inputs */ p = m_input.keys; /* draw buttons */ #ifdef HW_RVL switch (selected) { case 0: /* left button */ gxDrawTexture(arrow[1],arrow_pos[0][0]-4,arrow_pos[0][1]-4,arrow[0]->width+8,arrow[0]->height+8,255); gxDrawTextureRotate(arrow[0],arrow_pos[1][0],arrow_pos[1][1],arrow[0]->width,arrow[0]->height,180.0,255); gxDrawTextureRotate(arrow[0],arrow_pos[2][0],arrow_pos[2][1],arrow[0]->width,arrow[0]->height,90.0,255); gxDrawTextureRotate(arrow[0],arrow_pos[3][0],arrow_pos[3][1],arrow[0]->width,arrow[0]->height,270.0,255); if (p & PAD_BUTTON_A) p |= PAD_BUTTON_LEFT; break; case 1: /* right button */ gxDrawTexture(arrow[0],arrow_pos[0][0],arrow_pos[0][1],arrow[0]->width,arrow[0]->height,255); gxDrawTextureRotate(arrow[1],arrow_pos[1][0]-4,arrow_pos[1][1]-4,arrow[0]->width+8,arrow[0]->height+8,180.0,255); gxDrawTextureRotate(arrow[0],arrow_pos[2][0],arrow_pos[2][1],arrow[0]->width,arrow[0]->height,90.0,255); gxDrawTextureRotate(arrow[0],arrow_pos[3][0],arrow_pos[3][1],arrow[0]->width,arrow[0]->height,270.0,255); if (p & PAD_BUTTON_A) p |= PAD_BUTTON_RIGHT; break; case 2: /* up button */ gxDrawTexture(arrow[0],arrow_pos[0][0],arrow_pos[0][1],arrow[0]->width,arrow[0]->height,255); gxDrawTextureRotate(arrow[0],arrow_pos[1][0],arrow_pos[1][1],arrow[0]->width,arrow[0]->height,180.0,255); gxDrawTextureRotate(arrow[1],arrow_pos[2][0]-4,arrow_pos[2][1]-4,arrow[0]->width+8,arrow[0]->height+8,90.0,255); gxDrawTextureRotate(arrow[0],arrow_pos[3][0],arrow_pos[3][1],arrow[0]->width,arrow[0]->height,270.0,255); if (p & PAD_BUTTON_A) p |= PAD_BUTTON_UP; break; case 3: /* down button */ gxDrawTexture(arrow[0],arrow_pos[0][0],arrow_pos[0][1],arrow[0]->width,arrow[0]->height,255); gxDrawTextureRotate(arrow[0],arrow_pos[1][0],arrow_pos[1][1],arrow[0]->width,arrow[0]->height,180.0,255); gxDrawTextureRotate(arrow[0],arrow_pos[2][0],arrow_pos[2][1],arrow[0]->width,arrow[0]->height,90.0,255); gxDrawTextureRotate(arrow[1],arrow_pos[3][0]-4,arrow_pos[3][1]-4,arrow[0]->width+8,arrow[0]->height+8,270.0,255); if (p & PAD_BUTTON_A) p |= PAD_BUTTON_DOWN; break; default: /* nothing selected */ gxDrawTexture(arrow[0],arrow_pos[0][0],arrow_pos[0][1],arrow[0]->width,arrow[0]->height,255); gxDrawTextureRotate(arrow[0],arrow_pos[1][0],arrow_pos[1][1],arrow[0]->width,arrow[0]->height,180.0,255); gxDrawTextureRotate(arrow[0],arrow_pos[2][0],arrow_pos[2][1],arrow[0]->width,arrow[0]->height,90.0,255); gxDrawTextureRotate(arrow[0],arrow_pos[3][0],arrow_pos[3][1],arrow[0]->width,arrow[0]->height,270.0,255); break; } if (Shutdown) { gxTextureClose(&arrow[0]); gxTextureClose(&arrow[1]); gxTextureClose(&window); gxTextureClose(&w_pointer); GUI_DeleteMenu(parent); GUI_FadeOut(); shutdown(); SYS_ResetSystem(SYS_POWEROFF, 0, 0); } /* update selection */ selected = -1; if (m_input.ir.valid) { /* get cursor position */ x = m_input.ir.x; y = m_input.ir.y; /* draw wiimote pointer */ gxDrawTextureRotate(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,m_input.ir.angle,255); /* check for valid buttons */ for (i=0; i<4; i++) { if ((x>=arrow_pos[i][0])&&(x<=(arrow_pos[i][0]+arrow[0]->width))&&(y>=arrow_pos[i][1])&&(y<=(arrow_pos[i][1]+arrow[0]->height))) selected = i; } } #else gxDrawTexture(arrow[0],arrow_pos[0][0],arrow_pos[0][1],arrow[0]->width,arrow[0]->height,255); gxDrawTextureRotate(arrow[0],arrow_pos[1][0],arrow_pos[1][1],arrow[0]->width,arrow[0]->height,180.0,255); gxDrawTextureRotate(arrow[0],arrow_pos[2][0],arrow_pos[2][1],arrow[0]->width,arrow[0]->height,90.0,255); gxDrawTextureRotate(arrow[0],arrow_pos[3][0],arrow_pos[3][1],arrow[0]->width,arrow[0]->height,270.0,255); #endif /* update screen */ gxSetScreen(); if (p&PAD_BUTTON_LEFT) { /* decrement option 1 value */ *option_1 -= step; if (*option_1 < min) *option_1 = max; modified = 1; } else if (p&PAD_BUTTON_RIGHT) { /* decrement option 1 value */ *option_1 += step; if (*option_1 > max) *option_1 = min; modified = 1; } else if (p&PAD_BUTTON_UP) { /* decrement option 2 value */ *option_2 -= step; if (*option_2 < min) *option_2 = max; modified = 1; } else if (p&PAD_BUTTON_DOWN) { /* increment option 2 value */ *option_2 += step; if (*option_2 > max) *option_2 = min; modified = 1; } else if (p & PAD_BUTTON_B) { quit = 1; } if (modified) { modified = 0; /* play sound effect */ ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size, ((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL); } } /* slide out */ yoffset = 0; ; while (yoffset < (ywindow + window->height)) { /* draw parent menu */ GUI_DrawMenu(parent); /* draw window */ gxDrawTexture(window,xwindow,ywindow-yoffset,window->width,window->height,225); /* update display */ gxSetScreen(); /* slide speed */ yoffset += 60; } /* restore action button helper */ if (parent->helpers[1]) parent->helpers[1]->data = Key_A_png; /* final position */ GUI_DrawMenu(parent); gxSetScreen(); /* close textures */ gxTextureClose(&arrow[0]); gxTextureClose(&arrow[1]); gxTextureClose(&window); } /* Interactive Message Box */ /* Message Box displays a message until a specific action is completed */ /* Message Box LWP Thread */ static void *MsgBox_Thread(gui_message *message_box) { while (message_box->refresh) { /* draw parent menu */ if (message_box->parent) { GUI_DrawMenu(message_box->parent); } else { gxClearScreen(bg_color); } /* draw window */ gxDrawTexture(message_box->window,166,160,message_box->window->width,message_box->window->height,230); gxDrawTexture(message_box->top,166,160,message_box->top->width,message_box->top->height,255); /* draw title */ if (message_box->title) FONT_writeCenter(message_box->title,20,166,166+message_box->window->width,160+(message_box->top->height-20)/2+20,(GXColor)WHITE); /* draw box message */ if (message_box->msg) FONT_writeCenter(message_box->msg,18,166,166+message_box->window->width,248,(GXColor)WHITE); /* draw throbber */ if (message_box->throbber) gxDrawTextureRotate(message_box->throbber,166+(message_box->window->width-message_box->throbber->width)/2,160+message_box->window->height-message_box->throbber->height-20,message_box->throbber->width,message_box->throbber->height,(message_box->progress * 360.0) / 100.0, 255); /* draw exit message */ if (message_box->buttonA) { FONT_writeCenter("Press to continue.",18,166,166+message_box->window->width,248+22,(GXColor)WHITE); gxDrawTexture(message_box->buttonA, 166+116, 248+4+(18-message_box->buttonA->height)/2,message_box->buttonA->width, message_box->buttonA->height,255); } /* update display */ gxSetScreen(); /* update progression */ message_box->progress++; if (message_box->progress > 100) message_box->progress = 0; usleep(10); } return 0; } /* update current Message Box */ void GUI_MsgBoxUpdate(char *title, char *msg) { if (title) strncpy(message_box.title,title,64); if (msg) strncpy(message_box.msg,msg,64); } /* setup current Message Box */ void GUI_MsgBoxOpen(char *title, char *msg, bool throbber) { if (SILENT) return; /* update text */ GUI_MsgBoxUpdate(title,msg); /* ensure we are not already running */ if (!message_box.refresh) { /* initialize default textures */ message_box.window = gxTextureOpenPNG(Frame_s2_png,0); message_box.top = gxTextureOpenPNG(Frame_s2_title_png,0); if (throbber) message_box.throbber = gxTextureOpenPNG(Frame_throbber_png,0); /* window position */ int xwindow = 166; int ywindow = 160; int ypos = 248; /* disable helper comments */ if (message_box.parent) { if (message_box.parent->helpers[0]) message_box.parent->helpers[0]->data = 0; if (message_box.parent->helpers[1]) message_box.parent->helpers[1]->data = 0; } /* slide in */ int yoffset = ywindow + message_box.window->height; while (yoffset > 0) { /* draw parent menu */ if (message_box.parent) { GUI_DrawMenu(message_box.parent); } else { gxClearScreen(bg_color); } /* draw window */ gxDrawTexture(message_box.window,xwindow,ywindow-yoffset,message_box.window->width,message_box.window->height,230); gxDrawTexture(message_box.top,xwindow,ywindow-yoffset,message_box.top->width,message_box.top->height,255); /* draw title */ if (title) FONT_writeCenter(title,20,xwindow,xwindow+message_box.window->width,ywindow+(message_box.top->height-20)/2+20-yoffset,(GXColor)WHITE); /* draw box message */ if (msg) FONT_writeCenter(msg,18,xwindow,xwindow+message_box.window->width,ypos-yoffset,(GXColor)WHITE); /* update display */ gxSetScreen(); /* slide speed */ yoffset -= 60; } /* create LWP thread for MessageBox refresh */ message_box.refresh = TRUE; LWP_CreateThread (&msgboxthread, (void *)MsgBox_Thread, &message_box, NULL, 0, 70); } } /* Close current messagebox */ void GUI_MsgBoxClose(void) { if (message_box.refresh) { /* suspend MessageBox refresh */ message_box.refresh = FALSE; LWP_JoinThread(msgboxthread, NULL); /* window position */ int xwindow = 166; int ywindow = 160; int ypos = 248; /* slide out */ int yoffset = 0; while (yoffset < (ywindow + message_box.window->height)) { /* draw parent menu */ if (message_box.parent) { GUI_DrawMenu(message_box.parent); } else { gxClearScreen(bg_color); } /* draw window */ gxDrawTexture(message_box.window,xwindow,ywindow-yoffset,message_box.window->width,message_box.window->height,230); gxDrawTexture(message_box.top,xwindow,ywindow-yoffset,message_box.top->width,message_box.top->height,255); /* draw title */ if (message_box.title) FONT_writeCenter(message_box.title,20,xwindow,xwindow+message_box.window->width,ywindow+(message_box.top->height-20)/2+20-yoffset,(GXColor)WHITE); /* draw text */ if (message_box.msg) FONT_writeCenter(message_box.msg,18,xwindow,xwindow+message_box.window->width,ypos-yoffset,(GXColor)WHITE); /* update display */ gxSetScreen(); /* slide speed */ yoffset += 60; } if (message_box.parent) { /* restore helper comment */ if (message_box.parent->helpers[0]) message_box.parent->helpers[0]->data = Key_B_png; if (message_box.parent->helpers[1]) message_box.parent->helpers[1]->data = Key_A_png; /* final position */ GUI_DrawMenu(message_box.parent); } else { gxClearScreen(bg_color); } gxSetScreen(); /* clear all textures */ gxTextureClose(&message_box.window); gxTextureClose(&message_box.top); gxTextureClose(&message_box.buttonA); gxTextureClose(&message_box.throbber); } } void GUI_WaitPrompt(char *title, char *msg) { if (SILENT) return; /* clear unused texture */ gxTextureClose(&message_box.throbber); /* open or update message box */ GUI_MsgBoxOpen(title, msg, 0); /* allocate texture */ message_box.buttonA = gxTextureOpenPNG(Key_A_png,0); /* wait for button A */ while (m_input.keys & PAD_BUTTON_A) VIDEO_WaitVSync(); while (!(m_input.keys & PAD_BUTTON_A)) VIDEO_WaitVSync(); /* always close message box */ GUI_MsgBoxClose(); } /* Basic Fading */ void GUI_FadeOut() { int alpha = 0; while (alpha < 256) { gxDrawRectangle(0, 0, 640, 480, alpha, (GXColor)BLACK); gxSetScreen(); alpha +=3; } } /* Return background color */ GXColor *GUI_GetBgColor(void) { return &bg_color; } /* Select background color */ void GUI_SetBgColor(u8 color) { if (color < BG_COLOR_MAX) { bg_color.r = bg_colors[color].r; bg_color.g = bg_colors[color].g; bg_color.b = bg_colors[color].b; bg_color.a = bg_colors[color].a; } }
zyking1987-genplus-droid
genplusgx/gx/gui/gui.c
C
gpl2
55,192
/**************************************************************************** * gui.c * * generic GUI Engine (using GX rendering) * * Eke-Eke (2009,2010) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #ifndef _GUI_H #define _GUI_H #ifdef HW_RVL #include <wiiuse/wpad.h> #endif #define BG_COLOR_MAX 15 /*****************************************************************************/ /* GUI Buttons state */ /*****************************************************************************/ #define BUTTON_VISIBLE 0x01 #define BUTTON_ACTIVE 0x02 #define BUTTON_SELECTED 0x04 #define BUTTON_OVER_SFX 0x08 #define BUTTON_SELECT_SFX 0x10 #define BUTTON_FADE 0x20 #define BUTTON_SLIDE_LEFT 0x40 #define BUTTON_SLIDE_RIGHT 0x80 #define BUTTON_SLIDE_TOP 0x100 #define BUTTON_SLIDE_BOTTOM 0x200 /*****************************************************************************/ /* GUI Image state */ /*****************************************************************************/ #define IMAGE_VISIBLE 0x01 #define IMAGE_REPEAT 0x02 #define IMAGE_FADE 0x04 #define IMAGE_SLIDE_LEFT 0x08 #define IMAGE_SLIDE_RIGHT 0x10 #define IMAGE_SLIDE_TOP 0x20 #define IMAGE_SLIDE_BOTTOM 0x40 /*****************************************************************************/ /* Generic GUI structures */ /*****************************************************************************/ /* Item descriptor*/ typedef struct { gx_texture *texture; /* temporary texture data */ const u8 *data; /* pointer to png image data (items icon only) */ char text[64]; /* item string (items list only) */ char comment[64]; /* item comment */ u16 x; /* item image or text X position (upper left corner) */ u16 y; /* item image or text Y position (upper left corner) */ u16 w; /* item image or text width */ u16 h; /* item image or text height */ } gui_item; /* Button Data descriptor */ typedef struct { gx_texture *texture[2]; /* temporary texture datas */ const u8 *image[2]; /* pointer to png image datas (default) */ } butn_data; /* Button descriptor */ typedef struct { butn_data *data; /* pointer to button image/texture data */ u16 state; /* button state (ACTIVE,VISIBLE,SELECTED...) */ u8 shift[4]; /* direction offsets */ u16 x; /* button image X position (upper left corner) */ u16 y; /* button image Y position (upper left corner) */ u16 w; /* button image pixels width */ u16 h; /* button image pixels height */ } gui_butn; /* Image descriptor */ typedef struct { gx_texture *texture; /* temporary texture data */ const u8 *data; /* pointer to png image data */ u8 state; /* image state (VISIBLE) */ u16 x; /* image X position (upper left corner) */ u16 y; /* image Y position (upper left corner) */ u16 w; /* image width */ u16 h; /* image height */ u8 alpha; /* alpha transparency */ } gui_image; /* Menu descriptor */ typedef struct { char title[64]; /* menu title */ s8 selected; /* index of selected item */ s8 offset; /* items list offset */ u8 max_items; /* total number of items */ u8 max_buttons; /* total number of buttons */ u8 max_images; /* total number of background images */ u8 screenshot; /* game screen background */ gui_item *items; /* menu items */ gui_butn *buttons; /* menu buttons */ gui_image *bg_images; /* background images */ gui_item *helpers[2]; /* left & right key comments */ gui_butn *arrows[2]; /* arrows buttons */ void (*cb)(void); /* specific draw callback */ } gui_menu; typedef struct { u32 progress; /* progress counter */ bool refresh; /* messagebox current state */ gui_menu *parent; /* parent menu */ char title[64]; /* box title */ char msg[64]; /* box message */ gx_texture *window; /* pointer to box texture */ gx_texture *top; /* pointer to box title texture */ gx_texture *buttonA; /* pointer to button A texture */ gx_texture *throbber; /* pointer to throbber texture */ } gui_message; /* Menu inputs */ struct t_input_menu { u16 keys; #ifdef HW_RVL struct ir_t ir; #endif } m_input; /* Optionbox callback */ typedef void (*optioncallback)(void); /* Generic textures*/ #ifdef HW_RVL extern gx_texture *w_pointer; #endif /* Generic backgrounds */ extern const u8 Bg_layer_png[]; extern const u8 Bg_main_png[]; extern const u8 Bg_main_2_png[]; extern const u8 Bg_overlay_png[]; extern const u8 Banner_main_png[]; extern const u8 Banner_bottom_png[]; extern const u8 Banner_top_png[]; extern const u8 Banner_main_2_png[]; extern const u8 Banner_bottom_2_png[]; extern const u8 Banner_top_2_png[]; extern const u8 Main_logo_png[]; /* Generic frames */ extern const u8 Frame_s1_png[]; extern const u8 Frame_s2_png[]; extern const u8 Frame_s3_png[]; extern const u8 Frame_s1_title_png[]; extern const u8 Frame_s2_title_png[]; extern const u8 Frame_throbber_png[]; /* Generic Buttons */ extern const u8 Button_text_png[]; extern const u8 Button_text_over_png[]; extern const u8 Button_icon_png[]; extern const u8 Button_icon_over_png[]; extern const u8 Button_icon_sm_png[]; extern const u8 Button_icon_sm_over_png[]; extern const u8 Button_up_png[]; extern const u8 Button_up_over_png[]; extern const u8 Button_down_png[]; extern const u8 Button_down_over_png[]; extern const u8 Button_arrow_png[]; extern const u8 Button_arrow_over_png[]; extern const u8 Button_digit_png[]; extern const u8 Button_digit_over_png[]; /* Generic images*/ #ifdef HW_RVL #define Key_A_png Key_A_wii_png #define Key_B_png Key_B_wii_png extern const u8 generic_point_png[]; extern const u8 Key_A_wii_png[]; extern const u8 Key_B_wii_png[]; #else #define Key_A_png Key_A_gcn_png #define Key_B_png Key_B_gcn_png extern const u8 Key_A_gcn_png[]; extern const u8 Key_B_gcn_png[]; #endif extern const u8 Star_full_png[]; extern const u8 Star_empty_png[]; extern const u8 Overlay_bar_png[]; /* Generic Sounds */ extern const u8 button_over_pcm[]; extern const u8 button_select_pcm[]; extern const u8 intro_pcm[]; extern const u32 button_select_pcm_size; extern const u32 button_over_pcm_size; extern const u32 intro_pcm_size; extern u8 SILENT; extern void GUI_InitMenu(gui_menu *menu); extern void GUI_DeleteMenu(gui_menu *menu); extern void GUI_DrawMenu(gui_menu *menu); extern void GUI_DrawMenuFX(gui_menu *menu, u8 speed, u8 out); extern void GUI_SlideMenuTitle(gui_menu *m, int title_offset); extern int GUI_UpdateMenu(gui_menu *menu); extern int GUI_RunMenu(gui_menu *menu); extern void GUI_TextWindow(gui_menu *parent, char *title, char items[][64], u8 nb_items, u8 fontsize); extern int GUI_OptionWindow(gui_menu *parent, char *title, char *items[], u8 nb_items); extern void GUI_OptionBox(gui_menu *parent, optioncallback cb, char *title, void *option, float step, float min, float max, u8 type); extern void GUI_OptionBox2(gui_menu *parent, char *text_1, char *text_2, s16 *option_1, s16 *option_2, s16 step, s16 min, s16 max); extern void GUI_MsgBoxOpen(char *title, char *msg, bool throbber); extern void GUI_MsgBoxUpdate(char *title, char *msg); extern void GUI_MsgBoxClose(void); extern void GUI_WaitPrompt(char *title, char *msg); extern void GUI_FadeOut(); extern GXColor *GUI_GetBgColor(void); extern void GUI_SetBgColor(u8 color); extern void GUI_Initialize(void); #endif
zyking1987-genplus-droid
genplusgx/gx/gui/gui.h
C
gpl2
9,476
/* * filesel.c * * ROM File Browser * * Eke-Eke (2009,2010) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #include "shared.h" #include "filesel.h" #include "font.h" #include "gui.h" #include "file_load.h" #include "file_slot.h" #ifdef HW_RVL #include <wiiuse/wpad.h> #endif #define BG_COLOR_1 {0x49,0x49,0x49,0xff} #define BG_COLOR_2 {0x66,0x66,0x66,0xff} extern const u8 Browser_dir_png[]; extern const u8 Snap_empty_png[]; extern const u8 Snap_frame_png[]; FILEENTRIES filelist[MAXFILES]; static int offset = 0; static int selection = 0; static int maxfiles = 0; static int string_offset = 0; static char prev_folder[MAXJOLIET]; static void selector_cb(void); /*****************************************************************************/ /* GUI Buttons data */ /*****************************************************************************/ static butn_data arrow_up_data = { {NULL,NULL}, {Button_up_png,Button_up_over_png} }; static butn_data arrow_down_data = { {NULL,NULL}, {Button_down_png,Button_down_over_png} }; /*****************************************************************************/ /* GUI Arrows button */ /*****************************************************************************/ static gui_butn arrow_up = {&arrow_up_data,BUTTON_VISIBLE|BUTTON_ACTIVE|BUTTON_OVER_SFX,{0,0,0,0},14,76,360,32}; static gui_butn arrow_down = {&arrow_down_data,BUTTON_VISIBLE|BUTTON_ACTIVE|BUTTON_OVER_SFX,{0,0,0,0},14,368,360,32}; /*****************************************************************************/ /* GUI helpers */ /*****************************************************************************/ static gui_item action_cancel = { NULL,Key_B_png,"","Previous Directory",10,422,28,28 }; static gui_item action_select = { NULL,Key_A_png,"","Load ROM file",602,422,28,28 }; /*****************************************************************************/ /* GUI Background images */ /*****************************************************************************/ static gui_image bg_filesel[10] = { {NULL,Bg_main_png,IMAGE_VISIBLE,374,140,284,288,255}, {NULL,Bg_overlay_png,IMAGE_VISIBLE|IMAGE_REPEAT,0,0,640,480,255}, {NULL,Banner_top_png,IMAGE_VISIBLE,0,0,640,108,255}, {NULL,Banner_bottom_png,IMAGE_VISIBLE,0,380,640,100,255}, {NULL,Main_logo_png,IMAGE_VISIBLE,466,40,152,44,255}, {NULL,Frame_s1_png,IMAGE_VISIBLE,8,70,372,336,152}, {NULL,Frame_s2_png,0,384,264,248,140,152}, {NULL,Snap_empty_png,IMAGE_VISIBLE,422,114,164,116,255}, {NULL,NULL,0,424,116,160,112,255}, {NULL,Snap_frame_png,IMAGE_VISIBLE,388,112,236,148,255} }; /*****************************************************************************/ /* GUI Descriptor */ /*****************************************************************************/ static gui_menu menu_selector = { "Game Selection", -1,-1, 0,0,10,0, NULL, NULL, bg_filesel, {&action_cancel, &action_select}, {&arrow_up,&arrow_down}, selector_cb }; static void selector_cb(void) { int i; char text[MAXPATHLEN]; int yoffset = 108; /* Initialize directory icon */ gui_image dir_icon; dir_icon.texture = gxTextureOpenPNG(Browser_dir_png,0); dir_icon.w = dir_icon.texture->width; dir_icon.h = dir_icon.texture->height; dir_icon.x = 26; dir_icon.y = (26 - dir_icon.h)/2; /* Initialize selection bar */ gui_image bar_over; bar_over.texture = gxTextureOpenPNG(Overlay_bar_png,0); bar_over.w = bar_over.texture->width; bar_over.h = bar_over.texture->height; bar_over.x = 16; bar_over.y = (26 - bar_over.h)/2; /* Draw browser array */ gxDrawRectangle(15, 108, 358, 26, 127, (GXColor)BG_COLOR_1); gxDrawRectangle(15, 134, 358, 26, 127, (GXColor)BG_COLOR_2); gxDrawRectangle(15, 160, 358, 26, 127, (GXColor)BG_COLOR_1); gxDrawRectangle(15, 186, 358, 26, 127, (GXColor)BG_COLOR_2); gxDrawRectangle(15, 212, 358, 26, 127, (GXColor)BG_COLOR_1); gxDrawRectangle(15, 238, 358, 26, 127, (GXColor)BG_COLOR_2); gxDrawRectangle(15, 264, 358, 26, 127, (GXColor)BG_COLOR_1); gxDrawRectangle(15, 290, 358, 26, 127, (GXColor)BG_COLOR_2); gxDrawRectangle(15, 316, 358, 26, 127, (GXColor)BG_COLOR_1); gxDrawRectangle(15, 342, 358, 26, 127, (GXColor)BG_COLOR_2); /* Draw Files list */ for (i = offset; (i < (offset + 10)) && (i < maxfiles); i++) { if (i == selection) { /* selection bar */ gxDrawTexture(bar_over.texture,bar_over.x,yoffset+bar_over.y,bar_over.w,bar_over.h,255); /* scrolling text */ if ((string_offset/10) >= strlen(filelist[i].filename)) { string_offset = 0; } if (string_offset) { sprintf(text,"%s ",filelist[i].filename+string_offset/10); strncat(text, filelist[i].filename, string_offset/10); } else { strcpy(text, filelist[i].filename); } /* print text */ if (filelist[i].flags) { /* directory icon */ gxDrawTexture(dir_icon.texture,dir_icon.x,yoffset+dir_icon.y,dir_icon.w,dir_icon.h,255); if (FONT_write(text,18,dir_icon.x+dir_icon.w+6,yoffset+22,bar_over.w-dir_icon.w-26,(GXColor)WHITE)) { /* string is too large -> scroll text */ string_offset ++; } } else { if (FONT_write(text,18,dir_icon.x,yoffset+22,bar_over.w-20,(GXColor)WHITE)) { /* text scrolling */ string_offset ++; } } } else { if (filelist[i].flags) { /* directory icon */ gxDrawTexture(dir_icon.texture,dir_icon.x,yoffset+dir_icon.y,dir_icon.w,dir_icon.h,255); FONT_write(filelist[i].filename,18,dir_icon.x+dir_icon.w+6,yoffset+22,bar_over.w-dir_icon.w-26,(GXColor)WHITE); } else { FONT_write(filelist[i].filename,18,dir_icon.x,yoffset+22,bar_over.w-20,(GXColor)WHITE); } } yoffset += 26; } gxTextureClose(&bar_over.texture); gxTextureClose(&dir_icon.texture); } /**************************************************************************** * FileSelector * * Browse directories and select a file from the file listing * return ROM size * ****************************************************************************/ int FileSelector(void) { short p; int i; int size = 0; int old = -1; char fname[MAXPATHLEN]; char text[MAXPATHLEN]; FILE *xml,*snap; gui_menu *m = &menu_selector; #ifdef HW_RVL int x,y; gui_butn *button; #endif /* background type */ if (config.bg_type > 0) { bg_filesel[0].state &= ~IMAGE_REPEAT; bg_filesel[0].data = (config.bg_type > 1) ? Bg_main_png : Bg_main_2_png; bg_filesel[0].x = 374; bg_filesel[0].y = 140; bg_filesel[0].w = 284; bg_filesel[0].h = 288; } else { bg_filesel[0].state |= IMAGE_REPEAT; bg_filesel[0].data = Bg_layer_png; bg_filesel[0].x = 0; bg_filesel[0].y = 0; bg_filesel[0].w = 640; bg_filesel[0].h = 480; } /* background overlay */ if (config.bg_overlay) { bg_filesel[1].state |= IMAGE_VISIBLE; } else { bg_filesel[1].state &= ~IMAGE_VISIBLE; } /* Initialize Menu */ GUI_InitMenu(m); string_offset = 0; while (1) { /* ROM file snapshot/database */ if (old != selection) { old = selection; string_offset = 0; /* delete previous texture if any */ gxTextureClose(&bg_filesel[8].texture); bg_filesel[8].state &= ~IMAGE_VISIBLE; bg_filesel[6].state &= ~IMAGE_VISIBLE; if (!filelist[selection].flags) { /* get ROM filename without extension */ sprintf (text, "%s", filelist[selection].filename); if (strlen(text) >= 4) text[strlen(text) - 4] = 0; /* ROM database informations */ sprintf (fname, "%s/db/%s.xml", DEFAULT_PATH, text); xml = fopen(fname, "rb"); if (xml) { bg_filesel[6].state |= IMAGE_VISIBLE; fclose(xml); /* TODO */ } /* open screenshot file */ sprintf (fname, "%s/snaps/%s.png", DEFAULT_PATH, text); snap = fopen(fname, "rb"); if (snap) { bg_filesel[8].texture = gxTextureOpenPNG(0,snap); if (bg_filesel[8].texture) bg_filesel[8].state |= IMAGE_VISIBLE; fclose(snap); } } } /* update helper */ if (m->selected != -1) { /* out of focus */ strcpy(action_select.comment,""); } else if (filelist[selection].flags) { /* this is a directory */ strcpy(action_select.comment,"Open Directory"); } else { /* this is a file */ strcpy(action_select.comment,"Load ROM File"); } /* Draw menu*/ GUI_DrawMenu(m); #ifdef HW_RVL if (Shutdown) { gxTextureClose(&w_pointer); GUI_DeleteMenu(m); GUI_FadeOut(); shutdown(); SYS_ResetSystem(SYS_POWEROFF, 0, 0); } else if (m_input.ir.valid) { /* get cursor position */ x = m_input.ir.x; y = m_input.ir.y; /* draw wiimote pointer */ gxDrawTextureRotate(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,m_input.ir.angle,255); /* ensure we are in the selectable area */ if ((x < 380) && (y >= 108) && (y <= 368)) { /* find selected item */ selection = (y - 108) / 26; if (selection > 9) selection = 9; selection += offset; if (selection >= maxfiles) selection = old; /* reset selection */ m->selected = -1; } else { /* disable selection */ m->selected = m->max_buttons + 2; /* find selected button */ for (i=0; i<2; i++) { button = m->arrows[i]; if (button) { if (button->state & BUTTON_VISIBLE) { if ((x>=button->x)&&(x<=(button->x+button->w))&&(y>=button->y)&&(y<=(button->y+button->h))) { m->selected = m->max_buttons + i; break; } } } } } } else { /* reset selection */ m->selected = -1; } #endif /* copy EFB to XFB */ gxSetScreen(); p = m_input.keys; /* highlight next item */ if (p & PAD_BUTTON_DOWN) { selection++; if (selection == maxfiles) selection = offset = 0; if ((selection - offset) >= 10) offset += 10; } /* highlight previous item */ else if (p & PAD_BUTTON_UP) { selection--; if (selection < 0) { selection = maxfiles - 1; offset = selection - 10 + 1; } if (selection < offset) offset -= 10; if (offset < 0) offset = 0; } /* go back one page */ else if (p & PAD_TRIGGER_L) { selection -= 10; if (selection < 0) { selection = maxfiles - 1; offset = selection - 10 + 1; } if (selection < offset) offset -= 10; if (offset < 0) offset = 0; } /* go forward one page */ else if (p & PAD_TRIGGER_R) { selection += 10; if (selection > maxfiles - 1) selection = offset = 0; if ((selection - offset) >= 10) offset += 10; } /* quit */ else if (p & PAD_TRIGGER_Z) { GUI_DeleteMenu(m); return 0; } /* previous directory */ else if (p & PAD_BUTTON_B) { string_offset = 0; /* update browser directory (and get current folder)*/ if (UpdateDirectory(1, prev_folder)) { /* get directory entries */ maxfiles = ParseDirectory(); /* clear selection by default */ selection = offset = 0; /* select previous directory */ for (i=0; i<maxfiles; i++) { if (filelist[i].flags && !strcmp(prev_folder,filelist[i].filename)) { selection = i; offset = (i / 10) * 10; i = maxfiles; } } } else { /* exit */ GUI_DeleteMenu(m); return 0; } } /* open selected file or directory */ else if (p & PAD_BUTTON_A) { string_offset = 0; #ifdef HW_RVL /* arrow buttons selected */ if (m->selected == m->max_buttons) { /* up arrow */ selection--; if (selection < 0) { selection = maxfiles - 1; offset = selection - 10 + 1; } if (selection < offset) offset -= 10; if (offset < 0) offset = 0; } else if (m->selected == (m->max_buttons+1)) { /* down arrow */ selection++; if (selection == maxfiles) selection = offset = 0; if ((selection - offset) >= 10) offset += 10; } #endif /* ensure we are in focus area */ if (m->selected < m->max_buttons) { if (filelist[selection].flags) { /* get new directory */ UpdateDirectory(0, filelist[selection].filename); /* get directory entries */ maxfiles = ParseDirectory(); /* clear selection by default */ selection = offset = 0; } else { /* clear existing patches before loading new ROM file */ ggenie_shutdown(); areplay_shutdown(); /* load ROM file from device */ size = LoadFile(cart.rom, selection, fname); /* exit menu */ GUI_DeleteMenu(m); /* load new game */ if (size) { /* save previous game state */ if (config.s_auto & 2) { slot_autosave(config.s_default,config.s_device); } /* reinitialize emulation */ reloadrom(size,fname); } return size; } } } } } void ClearSelector(u32 max) { maxfiles = max; offset = 0; selection = 0; }
zyking1987-genplus-droid
genplusgx/gx/gui/filesel.c
C
gpl2
15,707
/* * cheats.c * * Cheats menu * * Softdev (2006) * Eke-Eke (2010) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #ifndef _CHEATS_H #define _CHEATS_H extern void CheatMenu(void); extern void CheatLoad(void); extern void CheatUpdate(void); #endif
zyking1987-genplus-droid
genplusgx/gx/gui/cheats.h
C
gpl2
1,071
/**************************************************************************** * menu.c * * Genesis Plus GX menus * * Eke-Eke (2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #ifndef _MENU_H #define _MENU_H extern void menu_execute(void); extern void menu_configure(void); #endif
zyking1987-genplus-droid
genplusgx/gx/gui/menu.h
C
gpl2
1,090
/* * filesel.c * * ROM File Browser * * Eke-Eke (2009,2010) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #ifndef _FILESEL_H #define _FILESEL_H #define MAXJOLIET 256 #define MAXFILES 1000 /* Filelist structure */ typedef struct { char flags; char filename[MAXJOLIET]; }FILEENTRIES; /* Globals */ extern int FileSelector(void); extern void ClearSelector(u32 max); extern FILEENTRIES filelist[MAXFILES]; #endif
zyking1987-genplus-droid
genplusgx/gx/gui/filesel.h
C
gpl2
1,249
/***************************************************************************** * font.c * * IPL font engine (using GX rendering) * * Eke-Eke (2009,2010) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #include "shared.h" #include "font.h" #define _SHIFTR(v, s, w) \ ((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1))) typedef struct _yay0header { unsigned int id ATTRIBUTE_PACKED; unsigned int dec_size ATTRIBUTE_PACKED; unsigned int links_offset ATTRIBUTE_PACKED; unsigned int chunks_offset ATTRIBUTE_PACKED; } yay0header; u8 font_size[256]; int fheight; static u8 *fontImage; static u8 *fontTexture; static void *ipl_fontarea; static sys_fontheader *fontHeader; #ifndef HW_RVL /* disable Qoob Modchip before IPL access (emukiddid) */ static void ipl_set_config(unsigned char c) { volatile unsigned long* exi = (volatile unsigned long*)0xCC006800; unsigned long val,addr; addr=0xc0000000; val = c << 24; exi[0] = ((((exi[0]) & 0x405) | 256) | 48); //select IPL //write addr of IPL exi[0 * 5 + 4] = addr; exi[0 * 5 + 3] = ((4 - 1) << 4) | (1 << 2) | 1; while (exi[0 * 5 + 3] & 1); //write the ipl we want to send exi[0 * 5 + 4] = val; exi[0 * 5 + 3] = ((4 - 1) << 4) | (1 << 2) | 1; while (exi[0 * 5 + 3] & 1); exi[0] &= 0x405; //deselect IPL } #endif static void decode_szp(void *src,void *dest) { u32 i,k,link; u8 *dest8,*tmp; u32 loff,coff,roff; u32 size,cnt,cmask,bcnt; yay0header *header; dest8 = (u8*)dest; header = (yay0header*)src; size = header->dec_size; loff = header->links_offset; coff = header->chunks_offset; roff = sizeof(yay0header); cmask = 0; cnt = 0; bcnt = 0; do { if(!bcnt) { cmask = *(u32*)(src+roff); roff += 4; bcnt = 32; } if(cmask&0x80000000) { dest8[cnt++] = *(u8*)(src+coff); coff++; } else { link = *(u16*)(src+loff); loff += 2; tmp = dest8+(cnt-(link&0x0fff)-1); k = link>>12; if(k==0) { k = (*(u8*)(src+coff))+18; coff++; } else k += 2; for(i=0;i<k;i++) { dest8[cnt++] = tmp[i]; } } cmask <<= 1; bcnt--; } while(cnt<size); } static void expand_font(u8 *src,u8 *dest) { s32 cnt; u32 idx; u8 val1,val2; sys_fontheader *sys_fontdata = fontHeader; u8 *data = (u8*)sys_fontdata+44; if(sys_fontdata->sheet_format==0x0000) { cnt = (sys_fontdata->sheet_fullsize/2)-1; while(cnt>=0) { idx = _SHIFTR(src[cnt],6,2); val1 = data[idx]; idx = _SHIFTR(src[cnt],4,2); val2 = data[idx]; dest[(cnt<<1)+0] =((val1&0xf0)|(val2&0x0f)); idx = _SHIFTR(src[cnt],2,2); val1 = data[idx]; idx = _SHIFTR(src[cnt],0,2); val2 = data[idx]; dest[(cnt<<1)+1] =((val1&0xf0)|(val2&0x0f)); cnt--; } } DCStoreRange(dest,sys_fontdata->sheet_fullsize); } static void GetFontTexel(s32 c,void *image,s32 pos,s32 stride) { u32 sheets,rem; u32 xoff,yoff; u32 xpos,ypos; u8 *img_start; u8 *ptr1,*ptr2; sys_fontheader *sys_fontdata = fontHeader; if(c<sys_fontdata->first_char || c>sys_fontdata->last_char) c = sys_fontdata->inval_char; else c -= sys_fontdata->first_char; sheets = sys_fontdata->sheet_column*sys_fontdata->sheet_row; rem = c%sheets; sheets = c/sheets; xoff = (rem%sys_fontdata->sheet_column)*sys_fontdata->cell_width; yoff = (rem/sys_fontdata->sheet_column)*sys_fontdata->cell_height; img_start = fontImage+(sys_fontdata->sheet_size*sheets); ypos = 0; while(ypos<sys_fontdata->cell_height) { xpos = 0; while(xpos<sys_fontdata->cell_width) { ptr1 = img_start+(((sys_fontdata->sheet_width/8)<<5)*((ypos+yoff)/8)); ptr1 = ptr1+(((xpos+xoff)/8)<<5); ptr1 = ptr1+(((ypos+yoff)%8)<<2); ptr1 = ptr1+(((xpos+xoff)%8)/2); ptr2 = image+((ypos/8)*(((stride<<1)/8)<<5)); ptr2 = ptr2+(((xpos+pos)/8)<<5); ptr2 = ptr2+(((xpos+pos)%8)/2); ptr2 = ptr2+((ypos%8)<<2); *ptr2 = *ptr1; xpos += 2; } ypos++; } } static void DrawChar(unsigned char c, int xpos, int ypos, int size, GXColor color) { /* reintialize texture object */ GXTexObj texobj; GX_InitTexObj(&texobj, fontTexture, fontHeader->cell_width, fontHeader->cell_height, GX_TF_I4, GX_CLAMP, GX_CLAMP, GX_FALSE); GX_LoadTexObj(&texobj, GX_TEXMAP0); /* reinitialize font texture data */ memset(fontTexture,0,fontHeader->cell_width * fontHeader->cell_height / 2); GetFontTexel(c,fontTexture,0,fontHeader->cell_width/2); DCFlushRange(fontTexture, fontHeader->cell_width * fontHeader->cell_height / 2); GX_InvalidateTexAll(); /* adjust texture width */ s32 width = (fontHeader->cell_width * size) / fontHeader->cell_height; /* GX rendering */ GX_Begin(GX_QUADS, GX_VTXFMT0, 4); GX_Position2s16(xpos, ypos - size); GX_Color4u8(color.r, color.g, color.b, 0xff); GX_TexCoord2f32(0.0, 0.0); GX_Position2s16(xpos + width, ypos - size); GX_Color4u8(color.r, color.g, color.b, 0xff); GX_TexCoord2f32(1.0, 0.0); GX_Position2s16(xpos + width, ypos); GX_Color4u8(color.r, color.g, color.b, 0xff); GX_TexCoord2f32(1.0, 1.0); GX_Position2s16(xpos, ypos); GX_Color4u8(color.r, color.g, color.b, 0xff); GX_TexCoord2f32(0.0, 1.0); GX_End (); GX_DrawDone(); } /**************************************************************************** * IPL font support * ****************************************************************************/ extern void __SYS_ReadROM(void *buf,u32 len,u32 offset); int FONT_Init(void) { #ifndef HW_RVL /* --- Game Cube --- disable Qoob before accessing IPL */ ipl_set_config(6); #endif /* read IPL font (ASCII) from Mask ROM */ ipl_fontarea = memalign(32,131360); if (!ipl_fontarea) return 0; memset(ipl_fontarea,0,131360); __SYS_ReadROM(ipl_fontarea+119072,12288,0x1FCF00); /* YAY0 decompression */ decode_szp(ipl_fontarea+119072,ipl_fontarea); /* retrieve IPL font data */ fontHeader = (sys_fontheader*)ipl_fontarea; fontImage = (u8*)((((u32)ipl_fontarea+fontHeader->sheet_image)+31)&~31); /* expand to I4 format */ expand_font((u8*)ipl_fontarea+fontHeader->sheet_image,fontImage); /* character width table */ int i,c; for (i=0; i<256; ++i) { if ((i < fontHeader->first_char) || (i > fontHeader->last_char)) c = fontHeader->inval_char; else c = i - fontHeader->first_char; font_size[i] = ((u8*)fontHeader)[fontHeader->width_table + c]; } /* font height */ fheight = fontHeader->cell_height; /* initialize texture data */ fontTexture = memalign(32, fontHeader->cell_width * fontHeader->cell_height / 2); if (!fontTexture) { free(ipl_fontarea); return 0; } return 1; } void FONT_Shutdown(void) { if (fontHeader) free(ipl_fontarea); if (fontTexture) free(fontTexture); } int FONT_write(char *string, int size, int x, int y, int max_width, GXColor color) { x -= (vmode->fbWidth / 2); y -= (vmode->efbHeight / 2); int w, ox = x; while (*string && (*string != '\n')) { w = (font_size[(u8)*string] * size) / fheight; if ((x + w) > (ox + max_width)) return strlen(string); DrawChar(*string, x, y, size,color); x += w; string++; } if (*string == '\n') { string++; return FONT_write(string, size, ox + (vmode->fbWidth / 2), y + size + (vmode->efbHeight / 2), max_width, color); } return 0; } int FONT_writeCenter(char *string, int size, int x1, int x2, int y, GXColor color) { int i=0; int w = 0; while (string[i] && (string[i] != '\n')) { w += (font_size[(u8)string[i++]] * size) / fheight; } if ((x1 + w) > x2) w = x2 - x1; int x = x1 + (x2 - x1 - w - vmode->fbWidth) / 2; y -= (vmode->efbHeight / 2); x2 -= (vmode->fbWidth / 2); while (*string && (*string != '\n')) { w = (font_size[(u8)*string] * size) / fheight; if ((x + w) > x2) return strlen(string); DrawChar(*string, x, y, size,color); x += w; string++; } if (*string == '\n') { string++; return FONT_writeCenter(string, size, x1, x2 + (vmode->fbWidth / 2), y + size + (vmode->efbHeight / 2), color); } return 0; } int FONT_alignRight(char *string, int size, int x, int y, GXColor color) { int i; int w = 0; x -= (vmode->fbWidth / 2); y -= (vmode->efbHeight / 2); int ox = x; for (i=0; i<strlen(string); i++) { w += (font_size[(u8)string[i]] * size) / fheight; } x = ox - w; while (*string) { w = (font_size[(u8)*string] * size) / fheight; if ((x + w) > ox) return strlen(string); DrawChar(*string, x, y, size,color); x += w; string++; } return 0; }
zyking1987-genplus-droid
genplusgx/gx/gui/font.c
C
gpl2
9,628
/* * cheats.c * * Cheats menu * * Softdev (2006) * Eke-Eke (2010) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #include "shared.h" #include "cheats.h" #include "font.h" #include "gui.h" #ifdef HW_RVL #include <wiiuse/wpad.h> #endif #define BG_COLOR_1 {0x49,0x49,0x49,0xff} #define BG_COLOR_2 {0x66,0x66,0x66,0xff} #define MAX_CHEATS (250) #define MAX_DESC_LENGTH (63) #ifdef HW_RVL extern const u8 Key_Minus_wii_png[]; extern const u8 Key_Plus_wii_png[]; #else extern const u8 Key_L_gcn_png[]; extern const u8 Key_R_gcn_png[]; #endif extern const u8 Key_DPAD_png[]; typedef struct { char code[12]; char text[MAX_DESC_LENGTH]; u8 enable; u16 data; u16 old; u32 address; } CHEATENTRY; static u32 decode_cheat(char *string, u32 *address, u32 *data); static void apply_cheats(void); static void clear_cheats(void); static void cheatmenu_cb(void); static void switch_chars(void); static int string_offset = 0; static int selection = 0; static int offset = 0; static int type = 0; static int maxcheats = 0; static int maxRAMcheats = 0; static CHEATENTRY cheatlist[MAX_CHEATS]; static u8 RAMcheatlist[MAX_CHEATS]; /*****************************************************************************/ /* GUI Buttons data */ /*****************************************************************************/ static butn_data arrow_up_data = { {NULL,NULL}, {Button_up_png,Button_up_over_png} }; static butn_data arrow_down_data = { {NULL,NULL}, {Button_down_png,Button_down_over_png} }; static butn_data button_digit_data = { {NULL,NULL}, {Button_digit_png,Button_digit_over_png} }; /*****************************************************************************/ /* GUI Arrows button */ /*****************************************************************************/ static gui_butn arrow_up = {&arrow_up_data,BUTTON_VISIBLE|BUTTON_ACTIVE|BUTTON_OVER_SFX,{0,0,0,0},14,76,360,32}; static gui_butn arrow_down = {&arrow_down_data,BUTTON_VISIBLE|BUTTON_ACTIVE|BUTTON_OVER_SFX,{0,0,0,0},14,368,360,32}; /*****************************************************************************/ /* GUI helpers */ /*****************************************************************************/ static gui_item action_cancel = { NULL,Key_B_png,"","Exit",10,422,28,28 }; static gui_item action_select = { NULL,Key_A_png,"","Edit Entry",602,422,28,28 }; /*****************************************************************************/ /* GUI Background images */ /*****************************************************************************/ static gui_image bg_cheats[7] = { {NULL,Bg_main_png,IMAGE_VISIBLE,374,140,284,288,255}, {NULL,Bg_overlay_png,IMAGE_VISIBLE|IMAGE_REPEAT,0,0,640,480,255}, {NULL,Banner_top_png,IMAGE_VISIBLE|IMAGE_SLIDE_TOP,0,0,640,108,255}, {NULL,Banner_bottom_png,IMAGE_VISIBLE|IMAGE_SLIDE_BOTTOM,0,380,640,100,255}, {NULL,Main_logo_png,IMAGE_VISIBLE|IMAGE_SLIDE_TOP,466,40,152,44,255}, {NULL,Frame_s1_png,IMAGE_VISIBLE,8,70,372,336,152}, {NULL,Frame_s1_png,IMAGE_SLIDE_RIGHT,411,109,372,296,76}, }; /*****************************************************************************/ /* Menu Items description */ /*****************************************************************************/ static gui_item items_cheats[30] = { {NULL,NULL,"","Edit Entry",0,0,0,0}, {NULL,NULL,"","Edit Entry",0,0,0,0}, {NULL,NULL,"","Edit Entry",0,0,0,0}, {NULL,NULL,"","Edit Entry",0,0,0,0}, {NULL,NULL,"","Edit Entry",0,0,0,0}, {NULL,NULL,"","Edit Entry",0,0,0,0}, {NULL,NULL,"","Edit Entry",0,0,0,0}, {NULL,NULL,"","Edit Entry",0,0,0,0}, {NULL,NULL,"","Edit Entry",0,0,0,0}, {NULL,NULL,"","Edit Entry",0,0,0,0}, {NULL,NULL,"0","Add Character" ,440,136,40,40}, {NULL,NULL,"1","Add Character" ,486,136,40,40}, {NULL,NULL,"2","Add Character" ,532,136,40,40}, {NULL,NULL,"3","Add Character" ,578,136,40,40}, {NULL,NULL,"4","Add Character" ,440,182,40,40}, {NULL,NULL,"5","Add Character" ,486,182,40,40}, {NULL,NULL,"6","Add Character" ,532,182,40,40}, {NULL,NULL,"7","Add Character" ,578,182,40,40}, {NULL,NULL,"8","Add Character" ,440,228,40,40}, {NULL,NULL,"9","Add Character" ,486,228,40,40}, {NULL,NULL,"A","Add Character" ,532,228,40,40}, {NULL,NULL,"B","Add Character" ,578,228,40,40}, {NULL,NULL,"C","Add Character" ,440,274,40,40}, {NULL,NULL,"D","Add Character" ,486,274,40,40}, {NULL,NULL,"E","Add Character" ,532,274,40,40}, {NULL,NULL,"F","Add Character" ,578,274,40,40}, {NULL,NULL,"del","Delete Entry" ,440,338,40,40}, {NULL,NULL,":","Add Separator" ,486,338,40,40}, {NULL,NULL,"+","Next Characters",532,338,40,40}, {NULL,NULL,"ok","Save Entry" ,578,338,40,40} }; /*****************************************************************************/ /* Menu Buttons description */ /*****************************************************************************/ static gui_butn buttons_cheats[30] = { {NULL, BUTTON_VISIBLE|BUTTON_ACTIVE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,108,358,26}, {NULL, BUTTON_VISIBLE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,134,358,26}, {NULL, BUTTON_VISIBLE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,160,358,26}, {NULL, BUTTON_VISIBLE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,186,358,26}, {NULL, BUTTON_VISIBLE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,212,358,26}, {NULL, BUTTON_VISIBLE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,238,358,26}, {NULL, BUTTON_VISIBLE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,264,358,26}, {NULL, BUTTON_VISIBLE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,290,358,26}, {NULL, BUTTON_VISIBLE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,316,358,26}, {NULL, BUTTON_VISIBLE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,342,358,26}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{0,4,0,1},440,136,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{0,4,1,1},486,136,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{0,4,1,1},532,136,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{0,4,1,0},578,136,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,4,0,1},440,182,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,4,1,1},486,182,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,4,1,1},532,182,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,4,1,0},578,182,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,4,0,1},440,228,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,4,1,1},486,228,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,4,1,1},532,228,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,4,1,0},578,228,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,4,0,1},440,274,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,4,1,1},486,274,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,4,1,1},532,274,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,4,1,0},578,274,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,0,0,1},440,338,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,0,1,1},486,338,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,0,1,1},532,338,40,40}, {&button_digit_data ,BUTTON_ACTIVE|BUTTON_SLIDE_RIGHT|BUTTON_OVER_SFX,{4,0,1,0},578,338,40,40} }; /*****************************************************************************/ /* Menu description */ /*****************************************************************************/ static gui_menu menu_cheats = { "Cheats Manager", 0,0, 30,30,7,0, items_cheats, buttons_cheats, bg_cheats, {&action_cancel, &action_select}, {&arrow_up,&arrow_down}, cheatmenu_cb }; static char ggvalidchars[] = "ABCDEFGHJKLMNPRSTVWXYZ0123456789"; static char arvalidchars[] = "0123456789ABCDEF"; static u32 decode_cheat(char *string, u32 *address, u32 *data) { char *p; int i,n; /* reset address & data values */ *address = 0; *data = 0; /* Game Genie type code (XXXX-YYYY) */ if ((strlen(string) >= 9) && (string[4] == '-')) { for (i = 0; i < 8; i++) { if (i == 4) string++; p = strchr (ggvalidchars, *string++); if (p == NULL) return 0; n = p - ggvalidchars; switch (i) { case 0: *data |= n << 3; break; case 1: *data |= n >> 2; *address |= (n & 3) << 14; break; case 2: *address |= n << 9; break; case 3: *address |= (n & 0xF) << 20 | (n >> 4) << 8; break; case 4: *data |= (n & 1) << 12; *address |= (n >> 1) << 16; break; case 5: *data |= (n & 1) << 15 | (n >> 1) << 8; break; case 6: *data |= (n >> 3) << 13; *address |= (n & 7) << 5; break; case 7: *address |= n; break; } } /* return code length */ return 9; } /* Action Replay type code (AAAAAA:DDDD) */ else if ((strlen(string) >= 11) && (string[6] == ':')) { /* decode address */ for (i=0; i<6; i++) { p = strchr (arvalidchars, *string++); if (p == NULL) return 0; n = (p - arvalidchars) & 15; *address |= (n << ((5 - i) * 4)); } /* decode data */ string++; for (i=0; i<4; i++) { p = strchr (arvalidchars, *string++); if (p == NULL) return 0; n = p - arvalidchars; *data |= (n & 15) << ((3 - i) * 4); } /* return code length */ return 11; } return 0; } static void apply_cheats(void) { /* clear RAM patches counter */ maxRAMcheats = 0; int i; for (i = 0; i < maxcheats; i++) { if (cheatlist[i].enable) { if (cheatlist[i].address < cart.romsize) { /* patch ROM data */ cheatlist[i].old = *(u16 *)(cart.rom + (cheatlist[i].address & 0xFFFFFE)); *(u16 *)(cart.rom + (cheatlist[i].address & 0xFFFFFE)) = cheatlist[i].data; } else if (cheatlist[i].address >= 0xFF0000) { /* patch RAM data */ RAMcheatlist[maxRAMcheats++] = i; } } } } static void clear_cheats(void) { int i = maxcheats; /* disable cheats in reversed order in case the same address is used by multiple patches */ while (i > 0) { /* restore original ROM data */ if (cheatlist[i-1].enable && (cheatlist[i-1].address < cart.romsize)) { *(u16 *)(cart.rom + (cheatlist[i-1].address & 0xFFFFFE)) = cheatlist[i-1].old; } i--; } } static void switch_chars(void) { int i; gui_menu *m = &menu_cheats; if (m->items[10].text[0] == '0') { m->items[10].text[0] = 'G'; m->items[11].text[0] = 'H'; m->items[12].text[0] = 'J'; m->items[13].text[0] = 'K'; m->items[14].text[0] = 'L'; m->items[15].text[0] = 'M'; m->items[16].text[0] = 'N'; m->items[17].text[0] = 'P'; m->items[18].text[0] = 'R'; m->items[19].text[0] = 'S'; m->items[20].text[0] = 'T'; m->items[21].text[0] = 'V'; m->items[22].text[0] = 'W'; m->items[23].text[0] = 'X'; m->items[24].text[0] = 'Y'; m->items[25].text[0] = 'Z'; } else if (m->items[10].text[0] == 'G') { m->items[10].text[0] = '0'; m->items[11].text[0] = '1'; m->items[12].text[0] = '2'; m->items[13].text[0] = '3'; m->items[14].text[0] = '4'; m->items[15].text[0] = '5'; m->items[16].text[0] = '6'; m->items[17].text[0] = '7'; m->items[18].text[0] = '8'; m->items[19].text[0] = '9'; m->items[20].text[0] = 'A'; m->items[21].text[0] = 'B'; m->items[22].text[0] = 'C'; m->items[23].text[0] = 'D'; m->items[24].text[0] = 'E'; m->items[25].text[0] = 'F'; } else if (m->items[10].text[0] == 'A') { m->items[10].text[0] = 'Q'; m->items[11].text[0] = 'R'; m->items[12].text[0] = 'S'; m->items[13].text[0] = 'T'; m->items[14].text[0] = 'U'; m->items[15].text[0] = 'V'; m->items[16].text[0] = 'W'; m->items[17].text[0] = 'X'; m->items[18].text[0] = 'Y'; m->items[19].text[0] = 'Z'; m->items[20].text[0] = '0'; m->items[21].text[0] = '1'; m->items[22].text[0] = '2'; m->items[23].text[0] = '3'; m->items[24].text[0] = '4'; m->items[25].text[0] = '5'; } else if (m->items[10].text[0] == 'Q') { m->items[10].text[0] = '6'; m->items[11].text[0] = '7'; m->items[12].text[0] = '8'; m->items[13].text[0] = '9'; /* hide unused buttons */ for (i=14; i<26; i++) { m->buttons[i].state &= ~BUTTON_VISIBLE; } m->buttons[10].shift[1] = 16; m->buttons[11].shift[1] = 16; m->buttons[12].shift[1] = 16; m->buttons[13].shift[1] = 16; m->buttons[26].shift[0] = 16; m->buttons[27].shift[0] = 16; m->buttons[28].shift[0] = 16; m->buttons[29].shift[0] = 16; } else if (m->items[10].text[0] == '6') { m->items[10].text[0] = 'A'; m->items[11].text[0] = 'B'; m->items[12].text[0] = 'C'; m->items[13].text[0] = 'D'; m->items[14].text[0] = 'E'; m->items[15].text[0] = 'F'; m->items[16].text[0] = 'G'; m->items[17].text[0] = 'H'; m->items[18].text[0] = 'I'; m->items[19].text[0] = 'J'; m->items[20].text[0] = 'K'; m->items[21].text[0] = 'L'; m->items[22].text[0] = 'M'; m->items[23].text[0] = 'N'; m->items[24].text[0] = 'O'; m->items[25].text[0] = 'P'; /* show previously unused buttons */ for (i=14; i<26; i++) { m->buttons[i].state |= BUTTON_VISIBLE; } m->buttons[10].shift[1] = 4; m->buttons[11].shift[1] = 4; m->buttons[12].shift[1] = 4; m->buttons[13].shift[1] = 4; m->buttons[26].shift[0] = 4; m->buttons[27].shift[0] = 4; m->buttons[28].shift[0] = 4; m->buttons[29].shift[0] = 4; } } static void cheatmenu_cb(void) { int i; int yoffset = 108; gui_image bar_over; gui_image star; char temp[MAX_DESC_LENGTH]; /* Initialize textures */ bar_over.texture = gxTextureOpenPNG(Overlay_bar_png,0); star.texture = gxTextureOpenPNG(Star_full_png,0); /* Draw browser array */ gxDrawRectangle(15, 108, 358, 26, 127, (GXColor)BG_COLOR_1); gxDrawRectangle(15, 134, 358, 26, 127, (GXColor)BG_COLOR_2); gxDrawRectangle(15, 160, 358, 26, 127, (GXColor)BG_COLOR_1); gxDrawRectangle(15, 186, 358, 26, 127, (GXColor)BG_COLOR_2); gxDrawRectangle(15, 212, 358, 26, 127, (GXColor)BG_COLOR_1); gxDrawRectangle(15, 238, 358, 26, 127, (GXColor)BG_COLOR_2); gxDrawRectangle(15, 264, 358, 26, 127, (GXColor)BG_COLOR_1); gxDrawRectangle(15, 290, 358, 26, 127, (GXColor)BG_COLOR_2); gxDrawRectangle(15, 316, 358, 26, 127, (GXColor)BG_COLOR_1); gxDrawRectangle(15, 342, 358, 26, 127, (GXColor)BG_COLOR_2); /* Draw Cheat list */ for (i=0; ((offset + i) < maxcheats) && (i < 10); i++) { if (i == selection) { /* selection bar */ gxDrawTexture(bar_over.texture,16,yoffset+1,356,24,255); /* cheat description need to be specifically handled */ if (type) { /* check if text is being edited */ if (menu_cheats.bg_images[6].state & IMAGE_VISIBLE) { /* adjust offset so that last characters are visible */ string_offset += FONT_writeCenter(cheatlist[offset + i].text+string_offset,16,40,366,yoffset+21,(GXColor)WHITE); } else { /* scroll text (speed = 1/10 frame) */ if ((string_offset/10) >= strlen(cheatlist[offset + i].text)) { string_offset = 0; } if (string_offset) { sprintf(temp,"%s ",cheatlist[offset + i].text+string_offset/10); strncat(temp, cheatlist[offset + i].text, string_offset/10); } else { strcpy(temp, cheatlist[offset + i].text); } if (FONT_writeCenter(temp,16,40,366,yoffset+21,(GXColor)WHITE)) { /* scroll text if string does not fit */ string_offset ++; } } } else { FONT_writeCenter(cheatlist[offset + i].code,18,40,366,yoffset+22,(GXColor)WHITE); } } else { if (type) { FONT_writeCenter(cheatlist[offset + i].text,16,40,366,yoffset+21,(GXColor)WHITE); } else { FONT_writeCenter(cheatlist[offset + i].code,18,40,366,yoffset+22,(GXColor)WHITE); } } /* draw cheat enable mark */ if (cheatlist[offset + i].enable) { gxDrawTexture(star.texture,20,yoffset+5,16,16,255); } yoffset += 26; } /* New Entry */ if (i < 10) { if (i == selection) { /* selection bar */ gxDrawTexture(bar_over.texture,16,yoffset+1,356,24,255); /* check if new code is being edited */ if (menu_cheats.bg_images[6].state & IMAGE_VISIBLE) { FONT_writeCenter(cheatlist[offset + selection].code,18,40,366,yoffset+22,(GXColor)WHITE); } else { FONT_writeCenter("New Code",18,40,366,yoffset+22,(GXColor)WHITE); } } else { FONT_writeCenter("New Code",18,40,366,yoffset+22,(GXColor)WHITE); } } gxTextureClose(&bar_over.texture); gxTextureClose(&star.texture); /* Extra helpers */ if (maxcheats && !(menu_cheats.bg_images[6].state & IMAGE_VISIBLE)) { /* switch between cheat code & description preview */ gui_image key_switch; key_switch.texture = gxTextureOpenPNG(Key_DPAD_png,0); #ifdef HW_RVL gxDrawTexture(key_switch.texture,268,424,24,24,255); FONT_write(type ? "View\nCode":"View\nText",16,300,436,640,(GXColor)WHITE); #else gxDrawTexture(key_switch.texture,272,424,24,24,255); FONT_write(type ? "View\nCode":"View\nText",16,304,436,640,(GXColor)WHITE); #endif gxTextureClose(&key_switch.texture); /* delete & enable cheats */ if ((offset + selection) < maxcheats) { gui_image key_enable; gui_image key_delete; #ifdef HW_RVL key_delete.texture = gxTextureOpenPNG(Key_Minus_wii_png,0); key_enable.texture = gxTextureOpenPNG(Key_Plus_wii_png,0); gxDrawTexture(key_delete.texture,152,424,24,24,255); gxDrawTexture(key_enable.texture,372,424,24,24,255); FONT_write("Delete\nCheat",16,184,436,640,(GXColor)WHITE); FONT_write(cheatlist[offset + selection].enable ? "Disable\nCheat":"Enable\nCheat",16,404,436,640,(GXColor)WHITE); #else key_delete.texture = gxTextureOpenPNG(Key_L_gcn_png,0); key_enable.texture = gxTextureOpenPNG(Key_R_gcn_png,0); gxDrawTexture(key_delete.texture,136,426,44,20,255); gxDrawTexture(key_enable.texture,368,426,44,20,255); FONT_write("Delete\nCheat",16,188,436,640,(GXColor)WHITE); FONT_write(cheatlist[offset + selection].enable ? "Disable\nCheat":"Enable\nCheat",16,420,436,640,(GXColor)WHITE); #endif gxTextureClose(&key_enable.texture); gxTextureClose(&key_delete.texture); } } } /**************************************************************************** * CheatMenu * * Manage cheats for the currently loaded game * ****************************************************************************/ void CheatMenu(void) { int i, update = 0; int digit_cnt = 0; int max = 0; char temp[256]; char *str = NULL; u32 address, data; gui_menu *m = &menu_cheats; /* clear existing ROM patches */ clear_cheats(); /* reset scrolling */ string_offset = 0; /* background type */ if (config.bg_type > 0) { bg_cheats[0].state &= ~IMAGE_REPEAT; bg_cheats[0].data = (config.bg_type > 1) ? Bg_main_png : Bg_main_2_png; bg_cheats[0].x = 374; bg_cheats[0].y = 140; bg_cheats[0].w = 284; bg_cheats[0].h = 288; } else { bg_cheats[0].state |= IMAGE_REPEAT; bg_cheats[0].data = Bg_layer_png; bg_cheats[0].x = 0; bg_cheats[0].y = 0; bg_cheats[0].w = 640; bg_cheats[0].h = 480; } /* background overlay */ if (config.bg_overlay) { bg_cheats[1].state |= IMAGE_VISIBLE; } else { bg_cheats[1].state &= ~IMAGE_VISIBLE; } /* selected item */ m->selected = selection; /* slide-in menu */ GUI_InitMenu(m); GUI_DrawMenuFX(m,30,0); m->cb = cheatmenu_cb; /* lock background elements */ m->bg_images[2].state &= ~IMAGE_SLIDE_TOP; m->bg_images[3].state &= ~IMAGE_SLIDE_BOTTOM; m->bg_images[4].state &= ~IMAGE_SLIDE_TOP; while (update != -1) { /* update arrows buttons */ if (offset > 0) m->arrows[0]->state |= BUTTON_VISIBLE; else m->arrows[0]->state &= ~BUTTON_VISIBLE; if ((offset + 10) < (maxcheats + 1)) m->arrows[1]->state |= BUTTON_VISIBLE; else m->arrows[1]->state &= ~BUTTON_VISIBLE; /* draw menu */ GUI_DrawMenu(m); /* restore cheats offset */ if (!(menu_cheats.bg_images[6].state & IMAGE_VISIBLE)) { m->offset = offset; m->max_items = maxcheats + 1; m->max_buttons = 10; } /* update menu */ update = GUI_UpdateMenu(m); /* save offset then restore default */ if (!(menu_cheats.bg_images[6].state & IMAGE_VISIBLE)) { offset = m->offset; m->offset = 0; m->max_items = m->max_buttons = 30; } /* update selected cheat */ if ((m->selected < 10) && (selection != m->selected)) { selection = m->selected; string_offset = 0; } /* handle pressed buttons */ if (update > 0) { switch (m->selected) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: /* Edit cheat */ { if (type && ((selection + offset) != maxcheats)) { /* cheat description */ str = cheatlist[offset + selection].text; strcpy(temp, str); max = MAX_DESC_LENGTH - 2; digit_cnt = strlen(str); if (digit_cnt <= max) { str[digit_cnt] = '*'; str[digit_cnt+1] = 0; } /* init specific characters */ m->items[10].text[0] = '6'; m->items[27].text[0] = ' '; strcpy(m->items[27].comment,"Add White Space"); switch_chars(); } else { /* cheat code */ str = cheatlist[offset + selection].code; strcpy(temp, str); if ((offset + selection) == maxcheats) { /* initialize code */ max = 0; digit_cnt = 0; str[0] = '*'; str[1] = 0; } else { /* code type */ if (str[4] == '-') { /* GG code */ max = 8; } else { /* AR code */ max = 10; } digit_cnt = max + 1; } /* init specific characters */ m->items[10].text[0] = 'G'; m->items[27].text[0] = ':'; strcpy(m->items[27].comment,"Add Code Separator"); switch_chars(); } /* show digit buttons */ for (i=10; i<30; i++) m->buttons[i].state |= BUTTON_VISIBLE; /* show right window */ m->bg_images[6].state |= IMAGE_VISIBLE; /* disable left buttons */ for (i=0; i<10; i++) m->buttons[i].state &= ~BUTTON_ACTIVE; /* disable arrow buttons */ m->arrows[0]->state &= ~BUTTON_ACTIVE; m->arrows[1]->state &= ~BUTTON_ACTIVE; /* slide in right window */ GUI_DrawMenuFX(m,20,0); /* update helper */ strcpy(action_cancel.comment,"Cancel"); /* select first digit */ m->selected = 10; /* reset scrolling */ string_offset = 0; break; } case 26: /* Backspace */ { if (digit_cnt > 0) { /* delete last character */ str[digit_cnt--] = 0; /* code separator is being deleted */ if ((str[digit_cnt] == ':') || (str[digit_cnt] == '-')) { /* reset detected code type */ max = 0; } /* edit mark */ str[digit_cnt] = '*'; /* update scroll value if necessary */ if (string_offset > 0) string_offset--; } break; } case 27: { if (type && ((offset + selection) != maxcheats)) { /* SPACE character */ if (digit_cnt <= max) { str[digit_cnt++] = ' '; str[digit_cnt] = 0; if (digit_cnt <= max) { str[digit_cnt] = '*'; str[digit_cnt+1] = 0; } } } else { /* Separator character (only if code type has not yet been determined) */ if (max == 0) { if (digit_cnt == 4) { /* GG code */ max = 8; str[4] = '-'; str[5] = '*'; str[6] = 0; digit_cnt++; } else if (digit_cnt == 6) { /* AR code */ max = 10; str[6] = ':'; str[7] = '*'; str[8] = 0; digit_cnt++; } } } break; } case 28: /* Next character set */ { GUI_DrawMenuFX(m,40,1); switch_chars(); GUI_DrawMenuFX(m,40,0); break; } case 29: /* Validate entry */ { /* check if entry is valid */ if (type && ((offset + selection) != maxcheats)) { str[digit_cnt] = 0; update = -1; } else if (max && (digit_cnt > max)) { address = data = 0; if (decode_cheat(cheatlist[offset + selection].code, &address, &data)) { /* update cheat address & data values */ cheatlist[offset + selection].address = address; cheatlist[offset + selection].data = data; /* new cheat ? */ if ((offset + selection) == maxcheats) { /* increase cheat count */ maxcheats++; /* enable cheat by default */ cheatlist[offset + selection].enable = 1; /* no description by default */ strcpy(cheatlist[offset + selection].text,"No Description"); } /* return to cheat selection */ update = -1; } else { GUI_WaitPrompt("Error", "Invalid Cheat Code"); } } break; } default: /* Add Character */ { /* force code separator if none has been set yet */ if ((max == 0) && (digit_cnt == 6)) break; /* add character */ if ((digit_cnt <= max) || (max == 0)) { str[digit_cnt++] = m->items[m->selected].text[0]; str[digit_cnt] = 0; if ((digit_cnt <= max) || (max == 0)) { str[digit_cnt] = '*'; str[digit_cnt+1] = 0; } if (string_offset > 0) string_offset ++; } break; } } } else if (update < 0) { if (m->bg_images[6].state & IMAGE_VISIBLE) { /* Restore old entry */ strcpy(str, temp); } } else { if (maxcheats && !(m->bg_images[6].state & IMAGE_VISIBLE)) { if ((m_input.keys & PAD_BUTTON_LEFT) || (m_input.keys & PAD_BUTTON_RIGHT)) { /* Switch between cheat code & description */ type ^= 1; /* reset scrolling */ string_offset = 0; } if ((offset + selection) < maxcheats) { /* Special inputs */ if (m_input.keys & PAD_TRIGGER_L) { /* sort cheat list */ for (i = offset + selection + 1; i < maxcheats; i++) { strcpy(cheatlist[i-1].text,cheatlist[i].text); strcpy(cheatlist[i-1].code,cheatlist[i].code); cheatlist[i-1].address = cheatlist[i].address; cheatlist[i-1].data = cheatlist[i].data; cheatlist[i-1].enable = cheatlist[i].enable; } /* clear last cheat */ cheatlist[maxcheats-1].text[0] = 0; cheatlist[maxcheats-1].code[0] = 0; cheatlist[maxcheats-1].address = 0; cheatlist[maxcheats-1].data = 0; cheatlist[maxcheats-1].enable = 0; /* disable last button */ if ((maxcheats - offset) < 10) { m->buttons[maxcheats - offset].state &= ~BUTTON_ACTIVE; m->buttons[maxcheats - offset - 1].shift[1] = 0; } /* decrease cheat count */ maxcheats--; /* reset scrolling */ string_offset = 0; } else if (m_input.keys & PAD_TRIGGER_R) { /* cheat ON/OFF */ cheatlist[offset + selection].enable ^= 1; } } } } if (update < 0) { if (m->bg_images[6].state & IMAGE_VISIBLE) { /* slide out right window */ GUI_DrawMenuFX(m,20,1); /* hide digit buttons */ for (i=10; i<30; i++) m->buttons[i].state &= ~BUTTON_VISIBLE; /* hide right window */ m->bg_images[6].state &= ~IMAGE_VISIBLE; /* update left buttons */ for (i=0; i<10; i++) { if ((offset + i) < maxcheats) { m->buttons[i].state |= BUTTON_ACTIVE; m->buttons[i].shift[1] = 1; } else if ((offset + i) == maxcheats) { m->buttons[i].state |= BUTTON_ACTIVE; m->buttons[i].shift[1] = 0; } else { m->buttons[i].state &= ~BUTTON_ACTIVE; m->buttons[i].shift[1] = 0; } } /* enable arrow buttons */ m->arrows[0]->state |= BUTTON_ACTIVE; m->arrows[1]->state |= BUTTON_ACTIVE; /* restore helper */ strcpy(action_cancel.comment,"Back"); /* select current cheat */ m->selected = selection; /* stay in menu */ update = 0; } } } /* apply ROM patches */ apply_cheats(); /* save cheats to file */ sprintf(temp, "%s/cheats/%s.pat", DEFAULT_PATH, rom_filename); if (maxcheats) { /* open file */ FILE *f = fopen(temp, "w"); /* write cheats */ if (f) { for (i=0; i<maxcheats; i++) { fprintf(f, "%s\t%s\n", cheatlist[i].code, cheatlist[i].text); fprintf(f, "%s\n", cheatlist[i].enable ? "ON" : "OFF"); } fclose(f); } } else { /* delete cheat file */ remove(temp); } /* unlock background elements */ m->bg_images[2].state |= IMAGE_SLIDE_TOP; m->bg_images[3].state |= IMAGE_SLIDE_BOTTOM; m->bg_images[4].state |= IMAGE_SLIDE_TOP; /* leave menu */ m->cb = NULL; GUI_DeleteMenu(m); GUI_DrawMenuFX(m,30,1); } /**************************************************************************** * CheatLoad * * Load cheats from associated .pat file, called when loading a new game * ROM patches are automatically applied. * RAM patches are applied once per frame. * ****************************************************************************/ void CheatLoad(void) { int len; int cnt = 0; u32 address, data; char temp[256]; /* reset cheat count */ maxcheats = 0; /* make cheat filename */ sprintf(temp, "%s/cheats/%s.pat", DEFAULT_PATH, rom_filename); /* open file */ FILE *f = fopen(temp, "r"); if (f) { /* clear string */ memset(temp, 0, 256); /* read cheats from file (one line per cheat) */ while (fgets(temp, 256, f) && (maxcheats < MAX_CHEATS) && (cnt < MAX_CHEATS)) { /* remove CR & EOL chars */ if ((temp[strlen(temp) - 2] == 0x0d) || (temp[strlen(temp) - 2] == 0x0a)) temp[strlen(temp) - 2] = 0; else temp[strlen(temp) - 1] = 0; /* check cheat validty */ address = data = 0; len = decode_cheat(temp, &address, &data); if (len) { /* update cheat address & data values */ cheatlist[maxcheats].address = address; cheatlist[maxcheats].data = data; /* copy cheat code */ strncpy(cheatlist[maxcheats].code, temp, len); cheatlist[maxcheats].code[len] = 0; len++; /* jump TAB and SPACE characters */ while ((temp[len] == 0x20) || (temp[len] == 0x09)) len++; /* copy cheat description */ strncpy(cheatlist[maxcheats].text, &temp[len], MAX_DESC_LENGTH - 1); cheatlist[maxcheats].text[MAX_DESC_LENGTH - 1] = 0; /* increment cheat count */ maxcheats++; } else if (!strcmp(temp,"ON") && config.autocheat) { /* enable flag */ cheatlist[cnt++].enable = 1; } else if (!strcmp(temp,"OFF") && config.autocheat) { /* disable flag */ cheatlist[cnt++].enable = 0; } } /* by default, disable cheats that were not flagged */ while (cnt < maxcheats) cheatlist[cnt++].enable = 0; /* close file */ fclose(f); } /* apply ROM patches */ apply_cheats(); /* adjust menu buttons */ for (cnt=0; cnt<10; cnt++) { if (cnt < maxcheats) { menu_cheats.buttons[cnt].state |= BUTTON_ACTIVE; menu_cheats.buttons[cnt].shift[1] = 1; } else if (cnt == maxcheats) { menu_cheats.buttons[cnt].state |= BUTTON_ACTIVE; menu_cheats.buttons[cnt].shift[1] = 0; } else { menu_cheats.buttons[cnt].shift[1] = 0; menu_cheats.buttons[cnt].state &= ~BUTTON_ACTIVE; } } /* reset menu */ selection = offset = 0; } /**************************************************************************** * CheatUpdate * * Apply RAM patches * ****************************************************************************/ void CheatUpdate(void) { int index, cnt = maxRAMcheats; while (cnt) { /* get cheat index */ index = RAMcheatlist[--cnt]; /* apply RAM patch */ if (cheatlist[index].data & 0xFF00) { /* word patch */ *(u16 *)(work_ram + (cheatlist[index].address & 0xFFFE)) = cheatlist[index].data; } else { /* byte patch */ work_ram[cheatlist[index].address & 0xFFFF] = cheatlist[index].data; } } }
zyking1987-genplus-droid
genplusgx/gx/gui/cheats.c
C
gpl2
37,819
/**************************************************************************** * legal.c * * Genesis Plus GX Disclaimer * * Softdev (2006) * Eke-Eke (2007,2008,2009,2010) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "shared.h" #include "font.h" #include "gui.h" extern const u8 Bg_intro_c1_png[]; extern const u8 Bg_intro_c2_png[]; extern const u8 Bg_intro_c3_png[]; extern const u8 Bg_intro_c4_png[]; extern const u8 Bg_intro_c5_png[]; /* * This is the legal stuff - which must be shown at program startup * Any derivative work MUST include the same textual output. * * In other words, play nice and give credit where it's due. */ static void show_disclaimer(int ypos) { FONT_writeCenter ("DISCLAIMER",22,0,640,ypos,(GXColor)WHITE); ypos += 32; FONT_writeCenter ("This is free software, and you are welcome to",20,0,640,ypos,(GXColor)WHITE); ypos += 20; FONT_writeCenter ("redistribute it under the conditions of the",20,0,640,ypos,(GXColor)WHITE); ypos += 20; FONT_writeCenter ("GNU GENERAL PUBLIC LICENSE Version 2.",20,0,640,ypos,(GXColor)WHITE); ypos += 20; FONT_writeCenter ("Authors can not be held responsible for any damage or",20,0,640,ypos,(GXColor)WHITE); ypos += 20; FONT_writeCenter ("or dysfunction that could occur while using this port.",20,0,640,ypos,(GXColor)WHITE); ypos += 20; FONT_writeCenter ("You may not sell, lease, rent or generally use",20,0,640,ypos,(GXColor)WHITE); ypos += 20; FONT_writeCenter ("this software in any commercial product or activity.",20,0,640,ypos,(GXColor)WHITE); ypos += 20; FONT_writeCenter ("You may not distribute this software with any ROM image",20,0,640,ypos,(GXColor)WHITE); ypos += 20; FONT_writeCenter ("unless you have the legal right to distribute them.",20,0,640,ypos,(GXColor)WHITE); ypos += 20; FONT_writeCenter ("This software is not endorsed by or affiliated",20,0,640,ypos,(GXColor)WHITE); ypos += 20; FONT_writeCenter ("with Sega Enterprises Ltd or Nintendo Co Ltd.",20,0,640,ypos,(GXColor)WHITE); ypos += 20; FONT_writeCenter ("All trademarks and registered trademarks are",20,0,640,ypos,(GXColor)WHITE); ypos += 20; FONT_writeCenter ("the property of their respective owners.",20,0,640,ypos,(GXColor)WHITE); ypos += 38; } void legal () { int count = 2000; int vis = 0; #ifdef HW_RVL gx_texture *button = gxTextureOpenPNG(Key_A_wii_png,0); #else gx_texture *button = gxTextureOpenPNG(Key_A_gcn_png,0); #endif gx_texture *logo_left= gxTextureOpenPNG(Bg_intro_c5_png,0); gx_texture *logo_right = gxTextureOpenPNG(Bg_intro_c4_png,0); gxClearScreen((GXColor)BLACK); show_disclaimer(56); gxDrawTexture(logo_left, (640-logo_left->width-logo_right->width -32)/2, 480-logo_left->height-24, logo_left->width, logo_left->height,255); gxDrawTexture(logo_right, (640-logo_left->width-logo_right->width -32)/2+logo_left->width+32, 480-logo_right->height-24, logo_right->width, logo_right->height,255); gxSetScreen(); sleep(1); while (!(m_input.keys & PAD_BUTTON_A) && (count > 0)) { gxClearScreen((GXColor)BLACK); show_disclaimer(56); if (count%25 == 0) vis^=1; if (vis) { FONT_writeCenter("Press button to continue.",24,0,640,366,(GXColor)SKY_BLUE); gxDrawTexture(button, 220, 366-24+(24-button->height)/2, button->width, button->height,255); } gxDrawTexture(logo_left, (640-logo_left->width-logo_right->width -32)/2, 480-logo_left->height-24, logo_left->width, logo_left->height,255); gxDrawTexture(logo_right, (640-logo_left->width-logo_right->width -32)/2+logo_left->width+32, 480-logo_right->height-24, logo_right->width, logo_right->height,255); gxSetScreen(); count--; } gxTextureClose(&button); gxTextureClose(&logo_left); gxTextureClose(&logo_right); if (count > 0) { ASND_Init(); ASND_Pause(0); int voice = ASND_GetFirstUnusedVoice(); ASND_SetVoice(voice,VOICE_MONO_16BIT,44100,0,(u8 *)button_select_pcm,button_select_pcm_size,200,200,NULL); GUI_FadeOut(); ASND_Pause(1); ASND_End(); return; } gxClearScreen((GXColor)BLACK); gx_texture *texture = gxTextureOpenPNG(Bg_intro_c1_png,0); if (texture) { gxDrawTexture(texture, (640-texture->width)/2, (480-texture->height)/2, texture->width, texture->height,255); if (texture->data) free(texture->data); free(texture); } gxSetScreen(); sleep (1); gxClearScreen((GXColor)WHITE); texture = gxTextureOpenPNG(Bg_intro_c2_png,0); if (texture) { gxDrawTexture(texture, (640-texture->width)/2, (480-texture->height)/2, texture->width, texture->height,255); if (texture->data) free(texture->data); free(texture); } gxSetScreen(); sleep (1); gxClearScreen((GXColor)BLACK); texture = gxTextureOpenPNG(Bg_intro_c3_png,0); if (texture) { gxDrawTexture(texture, (640-texture->width)/2, (480-texture->height)/2, texture->width, texture->height,255); if (texture->data) free(texture->data); free(texture); } gxSetScreen(); ASND_Pause(0); int voice = ASND_GetFirstUnusedVoice(); ASND_SetVoice(voice,VOICE_MONO_16BIT,44100,0,(u8 *)intro_pcm,intro_pcm_size,200,200,NULL); sleep (2); ASND_Pause(1); }
zyking1987-genplus-droid
genplusgx/gx/gui/legal.c
C
gpl2
6,140
<html> <!-- Mirrored from genplus-gx.googlecode.com/svn/!svn/bc/427/trunk/source/gx/gui/ by HTTrack Website Copier/3.x [XR&CO'2010], Mon, 13 Dec 2010 08:08:08 GMT --> <!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack --> <head><title>genplus-gx - Revision 427: /trunk/source/gx/gui</title></head> <body> <h2>genplus-gx - Revision 427: /trunk/source/gx/gui</h2> <ul> <li><a href="../index.html">..</a></li> <li><a href="filesel.c">filesel.c</a></li> <li><a href="filesel.h">filesel.h</a></li> <li><a href="font.c">font.c</a></li> <li><a href="font.h">font.h</a></li> <li><a href="ggentry.c">ggentry.c</a></li> <li><a href="gui.c">gui.c</a></li> <li><a href="gui.h">gui.h</a></li> <li><a href="legal.c">legal.c</a></li> <li><a href="menu.c">menu.c</a></li> <li><a href="oggplayer.c">oggplayer.c</a></li> <li><a href="oggplayer.h">oggplayer.h</a></li> <li><a href="saveicon.h">saveicon.h</a></li> </ul> <hr noshade><em><a href="http://code.google.com/">Google Code</a> powered by <a href="http://subversion.apache.org/">Subversion</a></em> </body> <!-- Mirrored from genplus-gx.googlecode.com/svn/!svn/bc/427/trunk/source/gx/gui/ by HTTrack Website Copier/3.x [XR&CO'2010], Mon, 13 Dec 2010 08:08:23 GMT --> <!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack --> </html>
zyking1987-genplus-droid
genplusgx/gx/gui/index.html
HTML
gpl2
1,424
/**************************************************************************** * ggentry.c * * Genesis Plus GX Game Genie * * Softdev (2006) * Eke-Eke (2007,2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "shared.h" #include "font.h" #include "gui.h" #define MAXCODES 8 typedef struct { int address; unsigned short data; } GGPATCH; /*** Game Genie Codes Array ***/ unsigned char ggcodes[MAXCODES][10]; /*** Codes are entered as XXXX-XXXX ***/ int gghpos[MAXCODES]; /*** Edit positions ***/ int ggrow = 0; int editing = 0; char ggvalidchars[] = "ABCDEFGHJKLMNPRSTVWXYZ0123456789*"; GGPATCH ggpatch[8]; /**************************************************************************** * Decode Game Genie entries to memory patches ****************************************************************************/ void decode_genie (char *code, int which) { char *p; int n, i; for (i = 0; i < 8; i++) { /*** This should only happen if memory is corrupt! ***/ p = strchr (ggvalidchars, code[i]); if (p == NULL) { ggpatch[which].address = ggpatch[which].data = 0; return; } n = p - ggvalidchars; switch (i) { case 0: ggpatch[which].data |= n << 3; break; case 1: ggpatch[which].data |= n >> 2; ggpatch[which].address |= (n & 3) << 14; break; case 2: ggpatch[which].address |= n << 9; break; case 3: ggpatch[which].address |= (n & 0xF) << 20 | (n >> 4) << 8; break; case 4: ggpatch[which].data |= (n & 1) << 12; ggpatch[which].address |= (n >> 1) << 16; break; case 5: ggpatch[which].data |= (n & 1) << 15 | (n >> 1) << 8; break; case 6: ggpatch[which].data |= (n >> 3) << 13; ggpatch[which].address |= (n & 7) << 5; break; case 7: ggpatch[which].address |= n; break; } } } void decode_ggcodes () { int i, j; char thiscode[10]; /*** Clear out any old patches ***/ memset (&ggpatch[0], 0, 8 * sizeof (GGPATCH)); memset (&thiscode, 0, 10); j = 0; for (i = 0; i < 8; i++) { if (strcmp ((char *)ggcodes[i], "AAAA-AAAA")) { /*** Move the code into thiscode ***/ memcpy (&thiscode, &ggcodes[i], 4); memcpy (&thiscode[4], &ggcodes[i][5], 4); decode_genie (thiscode, j); j++; } } /*** And now apply the patches ***/ if (j) { for (i = 0; i < j; i++) { if (ggpatch[i].address < 0x400000) { /*** Patching ROM space ONLY (Game Genie does NOT have access to other memory areas) ***/ if (cart.rom) *(uint16 *)(cart.rom + ggpatch[i].address) = ggpatch[i].data & 0xffff; } } } } /**************************************************************************** * ClearGGCodes * * Should be called whenever a new rom is loaded ****************************************************************************/ void ClearGGCodes () { int i; for (i = 0; i < MAXCODES; i++) { strcpy ((char *)ggcodes[i], "AAAA-AAAA"); gghpos[i] = 0; } ggrow = 0; } /**************************************************************************** * DrawGGCodes * * Just draw the codes, with the current one highlighted. ****************************************************************************/ void DrawGGCodes () { int i,j; unsigned char c[2] = { 0, 0 }; gxClearScreen ((GXColor)BLACK); WriteCentre (134, "Game Genie Entry"); for (i = 0; i < MAXCODES; i++) { if (i == ggrow) { /*** Highlight selected ***/ WriteCentre_HL (i * fheight + 190, (char *)ggcodes[i]); /*** If editing, highlight the current character ***/ if (editing) { int hpos = 0; for (j=0; j<strlen ((char *)ggcodes[i]); j++) hpos += font_size[ggcodes[i][j]]; hpos = ((640 - hpos) >> 1); for (j=0; j<gghpos[i]; j++) hpos += font_size[ggcodes[i][j]]; c[0] = ggcodes[i][gghpos[i]]; fntDrawBoxFilled (hpos, (i * fheight) + 190, hpos + font_size[c[0]], ((i + 1) * fheight) + 190, COLOR_YELLOW); write_font (hpos, (i * fheight) + 190, (char *)c); } } else WriteCentre ((i * fheight) + 190, (char *)ggcodes[i]); } gxSetScreen(); } /**************************************************************************** * GGEditLine * * Up/Down traverses valid character array * Left/Right moves along current line * A exits edit mode ****************************************************************************/ void GGEditLine () { short p; char c[2] = { 0, 0 }; char *v; int redraw = 1; int quit = 0; editing = 1; while (quit == 0) { if (redraw) { DrawGGCodes (); redraw = 0; } p = m_input.keys; if (p & PAD_BUTTON_UP) { /*** Increment the entry ***/ redraw = 1; c[0] = ggcodes[ggrow][gghpos[ggrow]]; v = strstr (ggvalidchars, c); v++; if (*v == '*') ggcodes[ggrow][gghpos[ggrow]] = 'A'; else ggcodes[ggrow][gghpos[ggrow]] = *v; } if (p & PAD_BUTTON_DOWN) { /*** Decrement entry ***/ redraw = 1; c[0] = ggcodes[ggrow][gghpos[ggrow]]; v = strstr (ggvalidchars, c); if (*v == 'A') ggcodes[ggrow][gghpos[ggrow]] = '9'; else { v--; ggcodes[ggrow][gghpos[ggrow]] = *v; } } if (p & PAD_BUTTON_LEFT) { redraw = 1; gghpos[ggrow]--; if (gghpos[ggrow] == 4) gghpos[ggrow]--; } if (p & PAD_BUTTON_RIGHT) { redraw = 1; gghpos[ggrow]++; if (gghpos[ggrow] == 4) gghpos[ggrow]++; } if (gghpos[ggrow] < 0) gghpos[ggrow] = 8; if (gghpos[ggrow] > 8) gghpos[ggrow] = 0; if (p & PAD_BUTTON_A) quit = 1; } editing = 0; } /**************************************************************************** * GGSelectLine * * Select which line to edit ****************************************************************************/ void GGSelectLine () { int redraw = 1; int quit = 0; short j; /*** To select a line, just move up or down. Pressing A will enter edit mode. Pressing B will exit to caller. ***/ while (quit == 0) { if (redraw) { DrawGGCodes (); redraw = 0; } j = m_input.keys; if (j & PAD_BUTTON_UP) { ggrow--; redraw = 1; } if (j & PAD_BUTTON_DOWN) { ggrow++; redraw = 1; } if (ggrow < 0) ggrow = MAXCODES - 1; if (ggrow == MAXCODES) ggrow = 0; if (j & PAD_BUTTON_B) quit = 1; if (j & PAD_BUTTON_A) { GGEditLine (); redraw = 1; } if (j & PAD_TRIGGER_Z) { /* reset code */ strcpy ((char *)ggcodes[ggrow], "AAAA-AAAA"); gghpos[ggrow] = 0; redraw = 1; } } } /**************************************************************************** * GetGGEntries * * Screen to return encoded Game Genie codes. * No keyboard is available, so it's just a simple wrap round each line kind * of thing. ****************************************************************************/ void GetGGEntries () { editing = 0; GGSelectLine (); /* Apply Game Genie patches */ decode_ggcodes (); }
zyking1987-genplus-droid
genplusgx/gx/gui/ggentry.c
C
gpl2
8,395
/***************************************************************************** * font.c * * IPL font engine (using GX rendering) * * Eke-Eke (2009,2010) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #ifndef _FONT_H #define _FONT_H extern int FONT_Init(void); extern void FONT_Shutdown(void); extern int FONT_write(char *string, int size, int x, int y, int max_width, GXColor color); extern int FONT_writeCenter(char *string, int size, int x1, int x2, int y, GXColor color); extern int FONT_alignRight(char *string, int size, int x, int y, GXColor color); #endif
zyking1987-genplus-droid
genplusgx/gx/gui/font.h
C
gpl2
1,390
/*********************************************************** * Genesis Plus Save Icon * Made by Brakken (http://www.tehskeen.com) * ************************************************************/ unsigned short icon[1024] = { 0xFFFF, 0xFFFF, 0xFBDE, 0xFBDE, 0xFBDE, 0xFBDE, 0xFBDE, 0xEB5A, 0xFBDE, 0xFBDE, 0xFBDE, 0xBDCD, 0xFBDE, 0xF7BD, 0xF7BD, 0xAD49, 0xEB59, 0xB9AD, 0xC1EF, 0xC1EF, 0x9062, 0x8000, 0x8C41, 0x8C41, 0x8000, 0x9CE6, 0xA0E6, 0xA507, 0x8400, 0x9CC5, 0xA0E6, 0xA0E6, 0xC1EF, 0xC1EF, 0xC1EF, 0xC1EF, 0x8000, 0x8000, 0x8000, 0x8000, 0x9083, 0x8C63, 0x8C63, 0x9484, 0x8C63, 0x9083, 0x9484, 0x94A4, 0xC1EF, 0xC20F, 0xC20F, 0xBDCE, 0x8000, 0x8000, 0x8000, 0x8000, 0x9083, 0x8821, 0x8842, 0x8842, 0x8842, 0xA107, 0xB58C, 0xAD6B, 0xA529, 0x94A4, 0x9083, 0x94A4, 0x8000, 0x8000, 0x8400, 0x8400, 0x8842, 0x8842, 0x8842, 0x8821, 0xB18B, 0xA949, 0xA108, 0xA107, 0xA528, 0xB9AD, 0xC630, 0xCE51, 0x8000, 0x8000, 0x8000, 0x8000, 0x8821, 0x8821, 0x8821, 0x8400, 0xA108, 0xA529, 0xA108, 0xA529, 0xCA30, 0xC630, 0xCA30, 0xFBDE, 0x8000, 0x8000, 0x8000, 0xAD27, 0x8400, 0x9083, 0x8863, 0x8400, 0x9CE6, 0x8842, 0x8C63, 0x8C20, 0xFBDE, 0xFBDE, 0xFFFF, 0xFFFF, 0xFBDE, 0xFBDE, 0xFBDE, 0xFBDE, 0xDA92, 0xFBDE, 0xFBDE, 0xFBDE, 0xC1AB, 0xF7BD, 0xFBDE, 0xFBDE, 0xF7BD, 0xF7BD, 0xF7BD, 0xA0E6, 0xF7BD, 0xF7BD, 0xF39C, 0x9484, 0xF39C, 0xF39C, 0xDEF7, 0x8C41, 0xF39C, 0xEF7B, 0xD272, 0x8400, 0x8C42, 0x9CE6, 0xA507, 0xA0E6, 0x8C63, 0x9CC5, 0xA107, 0x9CE6, 0x9484, 0x98A5, 0x9CE6, 0x98C5, 0x9CC5, 0x98C5, 0xA0E7, 0x98C5, 0x8C42, 0x9083, 0x94A5, 0x9083, 0x8C42, 0x9083, 0x9084, 0x8C62, 0x8C62, 0x9083, 0x9084, 0x8C62, 0x8C63, 0x9083, 0x94A4, 0x8C63, 0x8842, 0x9CC6, 0xA107, 0xA0E7, 0x8842, 0x8842, 0xA108, 0xA54A, 0x8842, 0x8C63, 0xB5AD, 0xB5AD, 0x8C63, 0x8C62, 0x8842, 0x8C63, 0x98C5, 0xA528, 0xB5AC, 0xB5AC, 0xA52A, 0xBDEF, 0xC631, 0xCA52, 0xB9CE, 0xB9CE, 0xA94A, 0xAD6B, 0x8C63, 0x8821, 0x8821, 0x8821, 0xA529, 0x98C5, 0x98C5, 0xA0E6, 0xC210, 0xA529, 0xA529, 0xA529, 0xB5AD, 0xB5CD, 0xB5AD, 0xBDEF, 0x8400, 0x8821, 0x8C62, 0x8821, 0xA0E7, 0x8842, 0x8842, 0x8C41, 0x9083, 0x8842, 0x8842, 0x8842, 0x94A5, 0x8842, 0x8C62, 0x8C62, 0x8C42, 0x9083, 0x8C62, 0x8C62, 0xB548, 0xF7BD, 0xF7BD, 0xF7BD, 0xA4C4, 0xF7BD, 0xF7BD, 0xF7BD, 0x9461, 0xDED5, 0xF39C, 0xF39C, 0x8C20, 0xD271, 0xF39C, 0xF39C, 0xEF7B, 0xEF7B, 0xC610, 0x8400, 0xEF7B, 0xEB5A, 0xB9AC, 0x8000, 0xEB5A, 0xEB5A, 0xA528, 0x9CC5, 0xE739, 0xE739, 0x9CC6, 0x98A5, 0x98C5, 0x98C5, 0xA0E6, 0x94A4, 0x94A4, 0x98C5, 0x94A5, 0x9484, 0xA528, 0x98C5, 0x9CE6, 0xA0E7, 0x9CE6, 0xA4E6, 0x98A4, 0xA507, 0x8C62, 0x9083, 0x9484, 0x9083, 0x94A4, 0x94A5, 0x98C5, 0x98C5, 0xA107, 0xA107, 0xA107, 0xB18B, 0xA907, 0x9062, 0x9484, 0x9CE6, 0x8842, 0x94A4, 0x9484, 0x9084, 0x8C62, 0x8C63, 0x9CC5, 0x9CC5, 0x98C6, 0x8C63, 0x9484, 0xA0E6, 0x9CE6, 0x9084, 0x94A4, 0x90A5, 0x8C63, 0x8C42, 0x8C62, 0x8C62, 0x8C63, 0xA108, 0xA94A, 0xA528, 0x94A5, 0x8884, 0x8884, 0x8884, 0xB0A5, 0xBC84, 0xA483, 0xA484, 0x8C63, 0x8C42, 0x8C63, 0x9083, 0xA94A, 0x9083, 0x8C62, 0x94A4, 0x8884, 0x8063, 0x90A5, 0x94A4, 0xA483, 0xBC63, 0xA884, 0x8884, 0x9083, 0x8C63, 0x8C42, 0x8C63, 0x9084, 0x8842, 0x9083, 0x9084, 0x8C42, 0x8C62, 0x98C6, 0xAD6A, 0x9083, 0x8C63, 0x98C5, 0xA107, 0x8400, 0xC1ED, 0xEF7B, 0xEF7B, 0x8400, 0xAD27, 0xEF7B, 0xEF7B, 0x9CE6, 0x9CA4, 0xEB5A, 0xEB5A, 0x9CE6, 0x9062, 0xDAB4, 0xE739, 0xE739, 0xE318, 0x9483, 0x8C63, 0xE318, 0xCE72, 0x9062, 0x9CC5, 0xDEF7, 0xC20F, 0x8C41, 0x9CE6, 0xDAD6, 0xB9AC, 0x8C20, 0x9CC5, 0xA0E6, 0xA528, 0x9CC5, 0xA528, 0xA508, 0x94A5, 0x98C6, 0xA108, 0x9CE6, 0x9CC5, 0xA0E7, 0xA94A, 0xA0E6, 0xA0E7, 0xA507, 0xAD6B, 0xA107, 0x98C6, 0x9CE6, 0x9083, 0x98C6, 0xA108, 0xA107, 0x98C5, 0xB9CD, 0xB18B, 0xA107, 0x9CC6, 0xC210, 0xB9CE, 0xA528, 0x9CC6, 0x98C5, 0x94A5, 0x9084, 0x8884, 0x9CC6, 0x9CE6, 0x9CC6, 0x94A5, 0x9CE6, 0x9CE6, 0x9CE7, 0xA108, 0x98C5, 0x98C5, 0x98C6, 0x98C6, 0xB0C6, 0xD0C6, 0xD0C6, 0xD0C6, 0x90A4, 0x90A4, 0x98A5, 0x9CA4, 0x9CE6, 0x90A4, 0x9084, 0x9084, 0x98C6, 0x98C6, 0x98C6, 0x98C6, 0xD0A5, 0xD0A5, 0xA484, 0x8483, 0x9484, 0x9083, 0x8C83, 0x9084, 0x90A5, 0x94A5, 0x9CE6, 0x9CE6, 0x98C6, 0x98C6, 0x9CE6, 0x98C6, 0x8C63, 0x9084, 0x9484, 0x9083, 0x98C5, 0x98C5, 0x94A4, 0x94A5, 0x98C6, 0x98C6, 0x98C5, 0x98C5, 0x98C6, 0x98C6, 0x98C6, 0x98C6, 0x9084, 0x8821, 0xCE51, 0xE739, 0x94A5, 0x8C20, 0xBDCE, 0xE318, 0x98C5, 0x8821, 0xB18B, 0xE318, 0x98C6, 0x8842, 0xAD49, 0xDEF7, 0xDAD6, 0xAD49, 0x8C41, 0xA508, 0xD6B5, 0xBDCC, 0x8C20, 0x8C41, 0xD6B5, 0xD294, 0xB98A, 0xAD06, 0xD294, 0xCE73, 0xCE73, 0xCA52, 0xA94A, 0xB5AD, 0xB18C, 0xAD6B, 0x9062, 0x9062, 0x9062, 0x9062, 0xAD27, 0xAD06, 0xAD06, 0xAD06, 0xCA52, 0xC631, 0xC631, 0xC210, 0xA94B, 0xB18C, 0xB58D, 0xAD6B, 0x9062, 0x9484, 0x98A4, 0x98A4, 0xA906, 0xA906, 0xA506, 0xA907, 0xC210, 0xC210, 0xB9F0, 0xBDEF, 0xA94B, 0xA94B, 0xA94B, 0xA94B, 0x98A5, 0x98A5, 0x98A4, 0x98A4, 0xA907, 0xA907, 0xA907, 0xA506, 0xBDEF, 0xBDEF, 0xBDEF, 0xB1F2, 0xA94B, 0xA94A, 0xA54A, 0xA529, 0x9484, 0x9484, 0x9483, 0x9483, 0xA4E6, 0xA4E6, 0xA4E6, 0xA4E6, 0xBDEF, 0xBDEF, 0xBDEF, 0xBDEF, 0xA529, 0xA529, 0xA529, 0xA108, 0x9062, 0x8C63, 0x9062, 0x9062, 0xA4E6, 0x9CE6, 0xA0E6, 0xA506, 0xBDEF, 0xC210, 0xC210, 0xC210, 0xA108, 0x9CE7, 0x9CE7, 0x98C6, 0x8C41, 0x8C42, 0x8C41, 0x8C41, 0xA507, 0xA508, 0xAD27, 0xB127, 0xC631, 0xC631, 0xCA52, 0xCA52, 0x98C6, 0x8C63, 0xA0E6, 0xDAD6, 0x8C41, 0x8400, 0xB548, 0xDAD6, 0xB127, 0xB548, 0xD6B5, 0xD6B5, 0xCE73, 0xCE73, 0xD294, 0xD6B5, 0xD294, 0xCA74, 0xBA56, 0xB635, 0x9A3B, 0x81FF, 0x81FF, 0x81FF, 0x81FF, 0x8A1F, 0xA27F, 0xA27F, 0x81FF, 0xA27F, 0xFFFF, 0xFFFF, 0xB635, 0xB214, 0xB214, 0xBE11, 0x81FF, 0x81FF, 0x81FF, 0x81FF, 0xA27F, 0xA27F, 0xA27F, 0x8A1F, 0xFFFF, 0xFFFF, 0xFFFF, 0xDF7F, 0xA1F7, 0x91FA, 0x81FF, 0x95F9, 0x81FF, 0x81FF, 0x8A1F, 0x81FF, 0x81FF, 0xD75F, 0xBEFF, 0x81FF, 0x81FF, 0xFFFF, 0xBEFF, 0x81FF, 0xB9CE, 0xB9CE, 0x8DFC, 0x81FF, 0xA9D2, 0xA9D2, 0x81FF, 0x9A5F, 0x99D6, 0x99D6, 0x81FF, 0xBEFF, 0x99D6, 0x99D6, 0x81FF, 0xBEFF, 0x85FD, 0x95F9, 0xB5CF, 0xB1F1, 0x81FF, 0x81FF, 0x95F9, 0x81FF, 0xEFBF, 0x81FF, 0x85FD, 0x81FF, 0xFFFF, 0x81FF, 0x81FF, 0x81FF, 0xA5F5, 0xA5F5, 0xB5F2, 0xB214, 0x81FF, 0x81FF, 0x81FF, 0x81FF, 0xB2BF, 0xB2BF, 0x81FF, 0x9A5F, 0xDF7F, 0xDF7F, 0x81FF, 0xE79F, 0xA218, 0xA218, 0xA218, 0xA639, 0x81FF, 0x81FF, 0x81FF, 0x81FF, 0xBEFF, 0xBEFF, 0xBEFF, 0xBEFF, 0xF7DF, 0xDF7F, 0xDF7F, 0xDF7F, 0xA639, 0xB657, 0xCA75, 0xD294, 0x81FF, 0x81FF, 0x861E, 0xCA95, 0xBEFF, 0xAA9F, 0x81FF, 0xB658, 0xD75F, 0x8A1F, 0x81FF, 0xCA75, 0x81FF, 0xA27F, 0xFFFF, 0xA27F, 0x81FF, 0xA27F, 0xFFFF, 0xFFFF, 0x81FF, 0xA27F, 0xFFFF, 0xBADF, 0x81FF, 0xA27F, 0xFFFF, 0xA27F, 0x81FF, 0x81FF, 0xCF3F, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xBADF, 0xA27F, 0xA27F, 0xA27F, 0x81FF, 0x81FF, 0x81FF, 0x81FF, 0x81FF, 0x923F, 0xFFFF, 0xBEFF, 0x81FF, 0x81FF, 0xFFFF, 0xBEFF, 0x81FF, 0x81FF, 0xFFFF, 0xCF3F, 0xA27F, 0x81FF, 0xFFFF, 0xFFFF, 0xFFFF, 0x99D6, 0x99D6, 0x81FF, 0xBEFF, 0x81FF, 0x81FF, 0x81FF, 0xBEFF, 0xA27F, 0xA27F, 0x9A5F, 0xBADF, 0xFFFF, 0xFFFF, 0xA27F, 0x81FF, 0xFFFF, 0x81FF, 0x81FF, 0x81FF, 0xFFFF, 0x81FF, 0x81FF, 0x81FF, 0xFFFF, 0xBEFF, 0xBEFF, 0xBEFF, 0xC71F, 0xDF7F, 0xDF7F, 0xDF7F, 0xDF7F, 0xDF7F, 0x923F, 0xF7DF, 0xDF7F, 0xDF7F, 0x81FF, 0xAA9F, 0xEFBF, 0xC71F, 0x81FF, 0x9A5F, 0xCF3F, 0x81FF, 0x8A1F, 0xD75F, 0xE79F, 0xBEFF, 0xBEFF, 0xBEFF, 0xDF7F, 0xDF7F, 0xDF7F, 0xDF7F, 0xBEFF, 0xBEFF, 0xBEFF, 0xC71F, 0xDF7F, 0xDF7F, 0xDF7F, 0xDF7F, 0xBEFF, 0x81FF, 0x81FF, 0xB657, 0xFFFF, 0xC71F, 0x81FF, 0xA23A, 0xFFFF, 0xC71F, 0x81FF, 0xA23A, 0xD75F, 0x8A1F, 0x81FF, 0xB658, 0x81FF, 0x9A5F, 0xAA9F, 0x81FF, 0x921D, 0x81FF, 0x81FF, 0x85FE, 0xD294, 0xBE55, 0xB657, 0xC653, 0xD294, 0xD294, 0xCE73, 0xCA52, 0x8A1D, 0xB214, 0xB214, 0x8DFC, 0xBA34, 0xC631, 0xC210, 0xB612, 0xC631, 0xC631, 0xC631, 0xC210, 0xCA52, 0xCA52, 0xC631, 0xC631, 0x81FF, 0x81FF, 0x81FF, 0x81FF, 0x8DFC, 0x81FF, 0x81FF, 0x81FF, 0xC210, 0xBE10, 0xBDEF, 0xBDEF, 0xC210, 0xC210, 0xC210, 0xBE10, 0x81FF, 0x81FF, 0x81FF, 0x81FF, 0x81FF, 0x81FF, 0x8DFB, 0xA5D4, 0xBDEF, 0xB9CE, 0xB9CE, 0xB9CE, 0xBDEF, 0xBDEF, 0xBDEF, 0xBDEF, 0x81FF, 0x81FF, 0x81FF, 0x81FF, 0x99F8, 0x8DFB, 0x8DFB, 0x8DFB, 0xB9CE, 0xBDEF, 0xBDEF, 0xBDEF, 0xBDEF, 0xBDEF, 0xBE10, 0xC210, 0x81FF, 0x81FF, 0x81FF, 0x81FF, 0x95F9, 0xA5F5, 0xA1F7, 0x91FA, 0xBDEF, 0xBE10, 0xC210, 0xC210, 0xC210, 0xC210, 0xC631, 0xC631, 0x81FF, 0x81FF, 0x81FF, 0x81FF, 0x921C, 0x921C, 0x921C, 0x921C, 0xC631, 0xC631, 0xCA52, 0xCA52, 0xC631, 0xCA52, 0xCA52, 0xCE73, 0x81FF, 0x81FF, 0x9A3B, 0xD294, 0x961B, 0xAA39, 0xD294, 0xD294, 0xCE73, 0xCE73, 0xD294, 0xD6B5, 0xCE73, 0xD294, 0xD6B5, 0xD6B5, };
zyking1987-genplus-droid
genplusgx/gx/gui/saveicon.h
C
gpl2
8,816
<html> <!-- Mirrored from genplus-gx.googlecode.com/svn/!svn/bc/427/trunk/source/gx/sounds/ by HTTrack Website Copier/3.x [XR&CO'2010], Mon, 13 Dec 2010 08:09:22 GMT --> <!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack --> <head><title>genplus-gx - Revision 427: /trunk/source/gx/sounds</title></head> <body> <h2>genplus-gx - Revision 427: /trunk/source/gx/sounds</h2> <ul> <li><a href="../index.html">..</a></li> <li><a href="button_over.pcm">button_over.pcm</a></li> <li><a href="button_select.pcm">button_select.pcm</a></li> <li><a href="intro.pcm">intro.pcm</a></li> </ul> <hr noshade><em><a href="http://code.google.com/">Google Code</a> powered by <a href="http://subversion.apache.org/">Subversion</a></em> </body> <!-- Mirrored from genplus-gx.googlecode.com/svn/!svn/bc/427/trunk/source/gx/sounds/ by HTTrack Website Copier/3.x [XR&CO'2010], Mon, 13 Dec 2010 08:09:23 GMT --> <!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack --> </html>
zyking1987-genplus-droid
genplusgx/gx/sounds/index.html
HTML
gpl2
1,087
/**************************************************************************** * aram.c * * ARAM wrapper for libogc * * Softdev (2006) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "shared.h" #define ARAMSTART 0x8000 #define ARAM_READ 1 #define ARAM_WRITE 0 /** * StartARAM * This simply sets up the call to internal libOGC. * Passing NULL for array list, and 0 items to allocate. * Required so libOGC knows to handle any interrupts etc. */ void StartARAM () { AR_Init (NULL, 0); } /** * ARAMPut * * Move data from MAIN memory to ARAM */ void ARAMPut (char *src, char *dst, int len) { DCFlushRange (src, len); AR_StartDMA( ARAM_WRITE, (u32)src, (u32)dst, len); while (AR_GetDMAStatus()); } /** * ARAMFetch * * This function will move data from ARAM to MAIN memory */ void ARAMFetch (char *dst, char *src, int len) { DCInvalidateRange(dst, len); AR_StartDMA( ARAM_READ, (u32) dst, (u32) src, len); while (AR_GetDMAStatus()); }
zyking1987-genplus-droid
genplusgx/gx/aram.c
C
gpl2
1,813
/**************************************************************************** * aram.c * * ARAM wrapper for libogc * * Softdev (2006) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #ifndef _ARAM_H #define _ARAM_H extern void StartARAM (); extern void ARAMFetch (char *src, char *dst, int len); extern void ARAMPut (char *src, char *dst, int len); #endif
zyking1987-genplus-droid
genplusgx/gx/aram.h
C
gpl2
1,157
/**************************************************************************** * gx_input.c * * Genesis Plus GX input support * * Eke-Eke (2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #ifndef _GC_INPUT_H_ #define _GC_INPUT_H_ /* max. supported inputs */ #ifdef HW_DOL #define MAX_INPUTS 4 #else #define MAX_INPUTS 8 #endif /* Configurable keys */ #define MAX_KEYS 8 /* Key configuration structure */ typedef struct { s8 device; u8 port; u8 padtype; } t_input_config; extern void gx_input_Init(void); extern int gx_input_FindDevices(void); extern void gx_input_SetDefault(void); extern void gx_input_Config(u8 chan, u8 device, u8 type); extern void gx_input_UpdateEmu(void); extern void gx_input_UpdateMenu(u32 cnt); #endif
zyking1987-genplus-droid
genplusgx/gx/gx_input.h
C
gpl2
1,571
/* * file_slot.c * * FAT and Memory Card SRAM/Savestate files managment * * Softdev (2006) * Eke-Eke (2007,2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #ifndef _FILE_SLOT_H #define _FILE_SLOT_H typedef struct { int valid; u16 year; u8 month; u8 day; u8 hour; u8 min; } t_slot; extern void slot_autoload(int slot, int device); extern void slot_autosave(int slot, int device); extern void slot_autodetect(int slot, int device, t_slot *ptr); extern int slot_delete(int slot, int device); extern int slot_load(int slot, int device); extern int slot_save(int slot, int device); #endif
zyking1987-genplus-droid
genplusgx/gx/fileio/file_slot.h
C
gpl2
1,426
/* * file_load.c * * ROM File loading support * * Eke-Eke (2010) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #include "shared.h" #include "file_load.h" #include "gui.h" #include "history.h" #include "unzip.h" #include "filesel.h" #include <iso9660.h> #ifdef HW_RVL #include <di/di.h> #else #include <ogc/dvd.h> #endif /* device root directories */ #ifdef HW_RVL static const char rootdir[TYPE_RECENT][10] = {"sd:/","usb:/","dvd:/"}; #else static const char rootdir[TYPE_RECENT][10] = {"/","dvd:/"}; #endif /* DVD interface */ #ifdef HW_RVL static const DISC_INTERFACE* dvd = &__io_wiidvd; #else static const DISC_INTERFACE* dvd = &__io_gcdvd; #endif /* current directory */ static char *fileDir; /* current device */ static int deviceType = -1; /* DVD status flag */ static u8 dvd_mounted = 0; /*************************************************************************** * MountDVD * * return 0 on error, 1 on success ***************************************************************************/ static int MountDVD(void) { GUI_MsgBoxOpen("Information", "Mounting DVD ...",1); /* check if DVD is already mounted */ if (dvd_mounted) { /* unmount DVD */ ISO9660_Unmount("dvd:"); dvd_mounted = 0; } /* check if disc is found */ if(!dvd->isInserted()) { GUI_WaitPrompt("Error","No Disc inserted !"); return 0; } /* mount DVD */ if(!ISO9660_Mount("dvd",dvd)) { GUI_WaitPrompt("Error","Disc can not be read !"); return 0; } /* DVD is mounted */ dvd_mounted = 1; GUI_MsgBoxClose(); return 1; } /*************************************************************************** * FileSortCallback (code by Marty Disibio) * * Quick sort callback to sort file entries with the following order: * . * .. * <dirs> * <files> ***************************************************************************/ static int FileSortCallback(const void *f1, const void *f2) { /* Special case for implicit directories */ if(((FILEENTRIES *)f1)->filename[0] == '.' || ((FILEENTRIES *)f2)->filename[0] == '.') { if(strcmp(((FILEENTRIES *)f1)->filename, ".") == 0) { return -1; } if(strcmp(((FILEENTRIES *)f2)->filename, ".") == 0) { return 1; } if(strcmp(((FILEENTRIES *)f1)->filename, "..") == 0) { return -1; } if(strcmp(((FILEENTRIES *)f2)->filename, "..") == 0) { return 1; } } /* If one is a file and one is a directory the directory is first. */ if(((FILEENTRIES *)f1)->flags == 1 && ((FILEENTRIES *)f2)->flags == 0) return -1; if(((FILEENTRIES *)f1)->flags == 0 && ((FILEENTRIES *)f2)->flags == 1) return 1; return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename); } /*************************************************************************** * UpdateDirectory * * Update current browser directory * return zero if going up while in root * when going up, return previous dir name ***************************************************************************/ int UpdateDirectory(bool go_up, char *dirname) { /* go up to parent directory */ if (go_up) { /* special case */ if (deviceType == TYPE_RECENT) return 0; /* check if we already are at root directory */ if (!strcmp(rootdir[deviceType], (const char *)fileDir)) return 0; int size=0; char temp[MAXPATHLEN]; /* determine last folder name length */ strcpy(temp, fileDir); char *test= strtok(temp,"/"); while (test != NULL) { size = strlen(test); strncpy(dirname,test,size); dirname[size] = 0; test = strtok(NULL,"/"); } /* remove last folder from path */ size = strlen(fileDir) - size; fileDir[size - 1] = 0; } else { /* by default, simply append folder name */ sprintf(fileDir, "%s%s/",fileDir, dirname); } return 1; } /*************************************************************************** * ParseDirectory * * List files into one directory ***************************************************************************/ int ParseDirectory(void) { int nbfiles = 0; char filename[MAXPATHLEN]; struct stat filestat; /* open directory */ DIR_ITER *dir = diropen(fileDir); if (dir == NULL) { return -1; } /* list files */ while ((dirnext(dir, filename, &filestat) == 0) && (nbfiles < MAXFILES)) { if (filename[0] != '.') { memset(&filelist[nbfiles], 0, sizeof (FILEENTRIES)); sprintf(filelist[nbfiles].filename,"%s",filename); filelist[nbfiles].flags = (filestat.st_mode & S_IFDIR) ? 1 : 0; nbfiles++; } } /* close directory */ dirclose(dir); /* Sort the file list */ qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback); return nbfiles; } /**************************************************************************** * LoadFile * * This function will load a BIN, SMD or ZIP file into the ROM buffer. * This functions return the actual size of data copied into the buffer * ****************************************************************************/ int LoadFile(u8 *buffer, u32 selection, char *filename) { char fname[MAXPATHLEN]; char *filepath; int done = 0; struct stat filestat; /* file path */ filepath = (deviceType == TYPE_RECENT) ? history.entries[selection].filepath : fileDir; /* full filename */ sprintf(fname, "%s%s", filepath, filelist[selection].filename); /* retrieve file status */ if(stat(fname, &filestat) != 0) { /* only DVD hot swap is supported */ if (!strncmp(filepath, rootdir[TYPE_DVD], strlen(rootdir[TYPE_DVD]))) { /* mount DVD */ if (!MountDVD()) return 0; /* retrieve file status */ stat(fname, &filestat); } } /* get file length */ int length = filestat.st_size; if (length > 0) { /* open file */ FILE *fd = fopen(fname, "rb"); if (!fd) { GUI_WaitPrompt("Error","Unable to open file !"); return 0; } /* Read first data chunk */ unsigned char temp[FILECHUNK]; fread(temp, FILECHUNK, 1, fd); fseek(fd, 0, SEEK_SET); /* Determine file type */ if (!IsZipFile ((char *) temp)) { if (length > MAXROMSIZE) { GUI_WaitPrompt("Error","File is too large !"); return 0; } /* Read file */ sprintf((char *)temp,"Loading %d bytes ...", length); GUI_MsgBoxOpen("Information", (char *)temp, 1); while (length > FILECHUNK) { fread(buffer + done, FILECHUNK, 1, fd); length -= FILECHUNK; done += FILECHUNK; } fread(buffer + done, length, 1, fd); done += length; GUI_MsgBoxClose(); /* update ROM filename (with extension) */ sprintf(filename, "%s", filelist[selection].filename); } else { /* unzip file */ done = UnZipBuffer(buffer, fd, filename); } /* close file */ fclose(fd); if (done) { /* add/move the file to the top of the history. */ history_add_file(filepath, filelist[selection].filename); /* recent file list has changed */ if (deviceType == TYPE_RECENT) deviceType = -1; /* return loaded size */ return done; } } return 0; } /**************************************************************************** * OpenDir * * Function to open a directory and load ROM file list. ****************************************************************************/ int OpenDirectory(int device) { int max = 0; if (device == TYPE_RECENT) { /* fetch history list */ int i; for(i=0; i < NUM_HISTORY_ENTRIES; i++) { if(history.entries[i].filepath[0] > 0) { filelist[i].flags = 0; strncpy(filelist[i].filename,history.entries[i].filename, MAXJOLIET-1); filelist[i].filename[MAXJOLIET-1] = '\0'; max++; } else { /* Found the end of the list. */ break; } } } else { /* only DVD hot swap is supported */ if (device == TYPE_DVD) { /* try to access root directory */ DIR_ITER *dir = diropen(rootdir[TYPE_DVD]); if (dir == NULL) { /* mount DVD */ if (!MountDVD()) return 0; deviceType = -1; } else { dirclose(dir); } } /* parse last directory */ fileDir = config.lastdir[device]; max = ParseDirectory(); if (max <= 0) { /* parse root directory */ strcpy(fileDir, rootdir[device]); max = ParseDirectory(); if (max < 0) { GUI_WaitPrompt("Error","Unable to open directory !"); return 0; } deviceType = -1; } } if (max == 0) { GUI_WaitPrompt("Error","No files found !"); return 0; } /* check if device type has changed */ if (device != deviceType) { /* reset current device type */ deviceType = device; /* reset File selector */ ClearSelector(max); } return 1; }
zyking1987-genplus-droid
genplusgx/gx/fileio/file_load.c
C
gpl2
10,148
/* * dvd.c * * Low-level DVD access * * Softdev (2006) * Eke-Eke (2007,2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #ifndef _DVD_H_ #define _DVD_H_ extern u32 dvd_read (void *dst, u32 len, u64 offset); extern void dvd_motor_off (); #ifndef HW_RVL extern void uselessinquiry (); extern void dvd_drive_detect(); #endif #endif
zyking1987-genplus-droid
genplusgx/gx/fileio/dvd.h
C
gpl2
1,155
/* * file_dvd.c * * ISO9660/Joliet DVD loading support * * Softdev (2006) * Eke-Eke (2007,2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #include "shared.h" #include "gui.h" #include "dvd.h" #include "unzip.h" #include "filesel.h" #include "file_fat.h" #include "file_dvd.h" /** Minimal ISO Directory Definition **/ #define RECLEN 0 /* Record length */ #define EXTENT 6 /* Extent */ #define FILE_LENGTH 14 /* File length (BIG ENDIAN) */ #define FILE_FLAGS 25 /* File flags */ #define FILENAME_LENGTH 32 /* Filename length */ #define FILENAME 33 /* ASCIIZ filename */ /** Minimal Primary Volume Descriptor **/ #define PVDROOT 0x9c /** Static Variables **/ static u64 rootdir = 0; static u64 basedir = 0; static int rootdirlength = 0; static int IsJoliet = 0; static int diroffset = 0; static int haveDVDdir = 0; static char dvdbuffer[DVDCHUNK]; /**************************************************************************** * Primary Volume Descriptor * * The PVD should reside between sector 16 and 31. * This is for single session DVD only. ****************************************************************************/ static int getpvd() { int sector = 16; u32 rootdir32; basedir = rootdirlength = 0; IsJoliet = -1; /** Look for Joliet PVD first **/ while (sector < 32) { if (dvd_read (&dvdbuffer, DVDCHUNK, (u64)(sector << 11))) { if (memcmp (&dvdbuffer, "\2CD001\1", 8) == 0) { memcpy(&rootdir32, &dvdbuffer[PVDROOT + EXTENT], 4); basedir = (u64)rootdir32; memcpy (&rootdirlength, &dvdbuffer[PVDROOT + FILE_LENGTH], 4); basedir <<= 11; IsJoliet = 1; break; } } else return 0; /*** Can't read sector! ***/ sector++; } if (IsJoliet > 0) return 1; /*** Joliet PVD Found ? ***/ /*** Look for standard ISO9660 PVD ***/ sector = 16; while (sector < 32) { if (dvd_read (&dvdbuffer, DVDCHUNK, (u64)(sector << 11))) { if (memcmp (&dvdbuffer, "\1CD001\1", 8) == 0) { memcpy (&rootdir32, &dvdbuffer[PVDROOT + EXTENT], 4); basedir = (u64)rootdir32; memcpy (&rootdirlength, &dvdbuffer[PVDROOT + FILE_LENGTH], 4); IsJoliet = 0; basedir <<= 11; break; } } else return 0; /*** Can't read sector! ***/ sector++; } return (IsJoliet == 0); } /**************************************************************************** * getentry * * Support function to return the next file entry, if any * Declared static to avoid accidental external entry. ****************************************************************************/ static int getentry(int entrycount) { char fname[512]; /* Huge, but experience has determined this */ char *ptr; char *filename; char *filenamelength; char *rr; int j; u32 offset32; /* Basic checks */ if (entrycount >= MAXFILES) return 0; if (diroffset >= DVDCHUNK) return 0; /** Decode this entry **/ if (dvdbuffer[diroffset]) /* Record length available */ { /* Update offsets into sector buffer */ ptr = (char *) &dvdbuffer[0]; ptr += diroffset; filename = ptr + FILENAME; filenamelength = ptr + FILENAME_LENGTH; /* Check for wrap round - illegal in ISO spec, * but certain crap writers do it! */ if ((diroffset + dvdbuffer[diroffset]) > DVDCHUNK) return 0; if (*filenamelength) { memset (&fname, 0, 512); /*** Do ISO 9660 first ***/ if (!IsJoliet) strcpy (fname, filename); else { /*** The more tortuous unicode joliet entries ***/ for (j = 0; j < (*filenamelength >> 1); j++) { fname[j] = filename[j * 2 + 1]; } fname[j] = 0; if (strlen (fname) >= MAXJOLIET) fname[MAXJOLIET - 1] = 0; if (strlen (fname) == 0) fname[0] = filename[0]; } if (strlen (fname) == 0) strcpy (fname, "."); else { if (fname[0] == 1) strcpy (fname, ".."); else { /* * Move *filenamelength to t, * Only to stop gcc warning for noobs :) */ int t = *filenamelength; fname[t] = 0; } } /** Rockridge Check **/ rr = strstr (fname, ";"); if (rr != NULL) *rr = 0; strcpy (filelist[entrycount].filename, fname); memcpy (&offset32, &dvdbuffer[diroffset + EXTENT], 4); filelist[entrycount].offset = (u64)offset32; memcpy (&filelist[entrycount].length, &dvdbuffer[diroffset + FILE_LENGTH], 4); memcpy (&filelist[entrycount].flags, &dvdbuffer[diroffset + FILE_FLAGS], 1); filelist[entrycount].offset <<= 11; filelist[entrycount].flags = filelist[entrycount].flags & 2; /*** Prepare for next entry ***/ diroffset += dvdbuffer[diroffset]; return 1; } } return 0; } /*************************************************************************** * DVD_ClearDirectory * * Clear DVD directory flag ***************************************************************************/ void DVD_ClearDirectory(void) { haveDVDdir = 0; } /*************************************************************************** * DVD_UpdateDirectory * * Update DVD current root directory ***************************************************************************/ int DVD_UpdateDirectory(bool go_up, u64 offset, u32 length) { /* root has no parent directory */ if (go_up && (basedir == rootdir)) return 0; /* simply update current root directory */ rootdir = offset; rootdirlength = length; return 1; } /**************************************************************************** * DVD_ParseDirectory * * This function will parse the directory tree. * It relies on rootdir and rootdirlength being pre-populated by a call to * getpvd, a previous parse or a menu selection. * * The return value is number of files collected, or 0 on failure. ****************************************************************************/ int DVD_ParseDirectory(void) { int pdlength; u64 pdoffset; u64 rdoffset; int len = 0; int filecount = 0; pdoffset = rdoffset = rootdir; pdlength = rootdirlength; filecount = 0; /** Clear any existing values ***/ memset (&filelist, 0, sizeof (FILEENTRIES) * MAXFILES); /*** Get as many files as possible ***/ while (len < pdlength) { if (dvd_read (&dvdbuffer, DVDCHUNK, pdoffset) == 0) return 0; diroffset = 0; while (getentry (filecount)) { if (strcmp(filelist[filecount].filename,".") && (filecount < MAXFILES)) filecount++; } len += DVDCHUNK; pdoffset = rdoffset + len; } /* Sort the file list */ qsort(filelist, filecount, sizeof(FILEENTRIES), FileSortCallback); return filecount; } /**************************************************************************** * DVD_LoadFile * * This function will load a BIN, SMD or ZIP file from DVD into the ROM buffer. * The index values indicates the file position in filentry list * This functions return the actual size of data copied into the buffer * ****************************************************************************/ int DVD_LoadFile(u8 *buffer, u32 selection) { /* file size */ int length = filelist[selection].length; if (length > 0) { /* Read first data chunk */ char readbuffer[DVDCHUNK]; u64 discoffset = filelist[selection].offset; dvd_read (&readbuffer, DVDCHUNK, discoffset); /* determine file type */ if (!IsZipFile ((char *) readbuffer)) { if (length > MAXROMSIZE) { GUI_WaitPrompt("Error","File size not supported !"); return 0; } char msg[64]; sprintf(msg,"Loading %d bytes...", length); GUI_MsgBoxOpen("Information",msg,1); /* How many 2k blocks to read */ int blocks = length / DVDCHUNK; int readoffset = 0; int i; /* read data chunks */ for (i = 0; i < blocks; i++) { dvd_read(readbuffer, DVDCHUNK, discoffset); discoffset += DVDCHUNK; memcpy (buffer + readoffset, readbuffer, DVDCHUNK); readoffset += DVDCHUNK; } /* final read */ i = length % DVDCHUNK; if (i) { dvd_read (readbuffer, DVDCHUNK, discoffset); memcpy (buffer + readoffset, readbuffer, i); } return length; } else { return UnZipBuffer (buffer, discoffset, NULL); } } return 0; } /**************************************************************************** * DVD_Open * * Function to load a DVD directory and display to user. ****************************************************************************/ int DVD_Open(void) { /* is DVD mounted ? */ if (!getpvd()) { /* mount DVD */ GUI_MsgBoxOpen("Information", "Mounting DVD ...",1); #ifdef HW_RVL u32 val; DI_GetCoverRegister(&val); if(val & 0x1) { GUI_WaitPrompt("Error","No Disc inserted !"); return 0; } DI_Mount(); while(DI_GetStatus() & DVD_INIT) usleep(10); if (!(DI_GetStatus() & DVD_READY)) { char msg[64]; sprintf(msg, "DI Status Error: 0x%08X !\n",DI_GetStatus()); GUI_WaitPrompt("Error",msg); return 0; } #else DVD_Mount(); #endif haveDVDdir = 0; if (!getpvd()) { GUI_WaitPrompt("Error","Disc can not be read !"); return 0; } GUI_MsgBoxClose(); } if (haveDVDdir == 0) { /* reset root directory */ rootdir = basedir; /* parse root directory */ int max = DVD_ParseDirectory (); if (max) { /* set DVD as default */ haveDVDdir = 1; FAT_ClearDirectory(); /* reset File selector */ ClearSelector(max); return 1; } else { /* no entries found */ GUI_WaitPrompt("Error","No files found !"); return 0; } } return 1; }
zyking1987-genplus-droid
genplusgx/gx/fileio/file_dvd.c
C
gpl2
11,183
/* * file_mem.c * * FAT and Memory Card SRAM/Savestate files managment * * Softdev (2006) * Eke-Eke (2007,2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "shared.h" #include "file_mem.h" #include "file_fat.h" #include "dvd.h" #include "gui.h" #include "filesel.h" #include "saveicon.h" /* Global ROM filename */ char rom_filename[MAXJOLIET]; /* Support for MemCards */ /** * libOGC System Work Area */ static u8 SysArea[CARD_WORKAREA] ATTRIBUTE_ALIGN (32); static card_dir CardDir; static card_file CardFile; static card_stat CardStatus; /** * DMA Transfer Area. * Must be 32-byte aligned. * 64k SRAM + 2k Icon */ static u8 savebuffer[STATE_SIZE] ATTRIBUTE_ALIGN (32); /**************************************************************************** * SDCARD Access functions * * We use the same buffer as for Memory Card manager * Function returns TRUE on success. *****************************************************************************/ static int FAT_ManageFile(char *filename, u8 direction, u8 filetype) { char fname[MAXPATHLEN]; int done = 0; int filesize; /* build complete SDCARD filename */ sprintf (fname, "%s/saves/%s", DEFAULT_PATH, filename); /* open file */ FILE *fp = fopen(fname, direction ? "rb" : "wb"); if (fp == NULL) { GUI_WaitPrompt("Error","Unable to open file !"); return 0; } switch (direction) { case 0: /* SAVING */ if (filetype) /* SRAM */ { memcpy(savebuffer, sram.sram, 0x10000); sram.crc = crc32 (0, sram.sram, 0x10000); filesize = 0x10000; } else filesize = state_save(savebuffer); /* STATE */ /* write buffer (2k blocks) */ while (filesize > FATCHUNK) { fwrite(savebuffer + done, FATCHUNK, 1, fp); filesize -= FATCHUNK; done += FATCHUNK; } done += fwrite(savebuffer + done, filesize, 1, fp); fclose(fp); if (done < filesize) { GUI_WaitPrompt("Error","Unable to write file !"); return 0; } sprintf (fname, "Saved %d bytes successfully", done); GUI_WaitPrompt("Information",fname); return 1; case 1: /* LOADING */ /* read size */ fseek(fp , 0 , SEEK_END); filesize = ftell (fp); fseek(fp, 0, SEEK_SET); /* read into buffer (2k blocks) */ while (filesize > FATCHUNK) { fread(savebuffer + done, FATCHUNK, 1, fp); filesize -= FATCHUNK; done += FATCHUNK; } done += fread(savebuffer + done, filesize, 1, fp); fclose(fp); if (done < filesize) { GUI_WaitPrompt("Error","Unable to read file !"); return 0; } if (filetype) /* SRAM */ { memcpy(sram.sram, savebuffer, done); sram.crc = crc32 (0, sram.sram, 0x10000); } else { /* STATE */ if (!state_load(savebuffer)) { GUI_WaitPrompt("Error","File version is not compatible !"); return 0; } } sprintf (fname, "Loaded %d bytes successfully", done); GUI_WaitPrompt("Information",fname); return 1; } return 0; } /**************************************************************************** * MountTheCard * * libOGC provides the CARD_Mount function, and it should be all you need. * However, experience with previous emulators has taught me that you are * better off doing a little bit more than that! * * Function returns TRUE on success. *****************************************************************************/ static int MountTheCard (u8 slot) { int tries = 0; int CardError; *(unsigned long *) (0xcc006800) |= 1 << 13; /*** Disable Encryption ***/ #ifndef HW_RVL uselessinquiry (); #endif while (tries < 10) { VIDEO_WaitVSync (); CardError = CARD_Mount (slot, SysArea, NULL); /*** Don't need or want a callback ***/ if (CardError == 0) return 1; else EXI_ProbeReset (); tries++; } return 0; } /**************************************************************************** * CardFileExists * * Wrapper to search through the files on the card. * Returns TRUE if found. ****************************************************************************/ static int CardFileExists (char *filename, u8 slot) { int CardError = CARD_FindFirst (slot, &CardDir, TRUE); while (CardError != CARD_ERROR_NOFILE) { CardError = CARD_FindNext (&CardDir); if (strcmp ((char *) CardDir.filename, filename) == 0) return 1; } return 0; } /**************************************************************************** * FILE autoload (SRAM/FreezeState or Config File) * * *****************************************************************************/ void memfile_autoload(s8 autosram, s8 autostate) { /* this should be transparent to the user */ SILENT = 1; /* SRAM */ if (autosram != -1) ManageSRAM(1,autosram); /* STATE */ if (autostate != -1) ManageState(1,autostate); SILENT = 0; } void memfile_autosave(s8 autosram, s8 autostate) { int crccheck = crc32 (0, sram.sram, 0x10000); /* this should be transparent to the user */ SILENT = 1; /* SRAM */ if ((autosram != -1) && (crccheck != sram.crc)) ManageSRAM(0, autosram); /* STATE */ if (autostate != -1) ManageState(0,autostate); SILENT = 0; } /**************************************************************************** * ManageSRAM * * Here is the main SRAM Management stuff. * The output file contains an icon (2K), 64 bytes comment and the SRAM (64k). * As memcards are allocated in blocks of 8k or more, you have a around * 6k bytes to save/load any other data you wish without altering any of the * main save / load code. * * direction == 0 save, 1 load. ****************************************************************************/ int ManageSRAM (u8 direction, u8 device) { if (!cart.romsize) return 0; char filename[MAXJOLIET]; if (direction) GUI_MsgBoxOpen("Information","Loading SRAM ...",1); else GUI_MsgBoxOpen("Information","Saving SRAM ...",1); /* clean buffer */ memset(savebuffer, 0, STATE_SIZE); if (device == 0) { /* FAT support */ sprintf (filename, "%s.srm", rom_filename); return FAT_ManageFile(filename,direction,1); } /* Memory CARD support */ char action[80]; int CardError; unsigned int SectorSize; int blocks; char comment[2][32] = { {"Genesis Plus 1.2a"}, {"SRAM Save"} }; int outbytes = 0; int sbo; unsigned long inzipped,outzipped; /* First, build a filename */ sprintf (filename, "MD-%04X.srm", realchecksum); strcpy (comment[1], filename); /* set MCARD slot nr. */ u8 CARDSLOT = device - 1; /* Saving */ if (direction == 0) { /*** Build the output buffer ***/ memcpy (&savebuffer, &icon, 2048); memcpy (&savebuffer[2048], &comment[0], 64); inzipped = 0x10000; outzipped = 0x12000; compress2 ((Bytef *) &savebuffer[2112+sizeof(outzipped)], &outzipped, (Bytef *) &sram.sram, inzipped, 9); memcpy(&savebuffer[2112], &outzipped, sizeof(outzipped)); } outbytes = 2048 + 64 + outzipped + sizeof(outzipped); /*** Initialise the CARD system ***/ memset (&SysArea, 0, CARD_WORKAREA); CARD_Init ("GENP", "00"); /*** Attempt to mount the card ***/ CardError = MountTheCard (CARDSLOT); if (CardError) { /*** Retrieve the sector size ***/ CardError = CARD_GetSectorSize (CARDSLOT, &SectorSize); switch (direction) { case 0: /*** Saving ***/ /*** Determine number of blocks on this card ***/ blocks = (outbytes / SectorSize) * SectorSize; if (outbytes % SectorSize) blocks += SectorSize; /*** Check if a previous save exists ***/ if (CardFileExists (filename,CARDSLOT)) { CardError = CARD_Open (CARDSLOT, filename, &CardFile); if (CardError) { sprintf (action, "Unable to open file (%d)", CardError); GUI_WaitPrompt("Error",action); CARD_Unmount (CARDSLOT); return 0; } int size = CardFile.len; CARD_Close (&CardFile); if (size < blocks) { /* new size is bigger: check if there is enough space left */ CardError = CARD_Create (CARDSLOT, "TEMP", blocks-size, &CardFile); if (CardError) { sprintf (action, "Unable to create temporary file (%d)", CardError); GUI_WaitPrompt("Error",action); CARD_Unmount (CARDSLOT); return 0; } CARD_Close (&CardFile); CARD_Delete(CARDSLOT, "TEMP"); } /* always delete existing slot */ CARD_Delete(CARDSLOT, filename); } /*** Create a new slot ***/ CardError = CARD_Create (CARDSLOT, filename, blocks, &CardFile); if (CardError) { sprintf (action, "Unable to create new file (%d)", CardError); GUI_WaitPrompt("Error",action); CARD_Unmount (CARDSLOT); return 0; } /*** Continue and save ***/ CARD_GetStatus (CARDSLOT, CardFile.filenum, &CardStatus); CardStatus.icon_addr = 0x0; CardStatus.icon_fmt = 2; CardStatus.icon_speed = 1; CardStatus.comment_addr = 2048; CARD_SetStatus (CARDSLOT, CardFile.filenum, &CardStatus); /*** And write the blocks out ***/ sbo = 0; while (outbytes > 0) { CardError = CARD_Write (&CardFile, &savebuffer[sbo], SectorSize, sbo); outbytes -= SectorSize; sbo += SectorSize; } CARD_Close (&CardFile); CARD_Unmount (CARDSLOT); sram.crc = crc32 (0, &sram.sram[0], 0x10000); sprintf (action, "Saved %d bytes successfully", blocks); GUI_WaitPrompt("Information",action); return 1; default: /*** Loading ***/ if (!CardFileExists (filename,CARDSLOT)) { GUI_WaitPrompt("Error","File does not exist !"); CARD_Unmount (CARDSLOT); return 0; } memset (&CardFile, 0, sizeof (CardFile)); CardError = CARD_Open (CARDSLOT, filename, &CardFile); if (CardError) { sprintf (action, "Unable to open file (%d)", CardError); GUI_WaitPrompt("Error",action); CARD_Unmount (CARDSLOT); return 0; } blocks = CardFile.len; if (blocks < SectorSize) blocks = SectorSize; if (blocks % SectorSize) blocks++; /*** Just read the file back in ***/ sbo = 0; int size = blocks; while (blocks > 0) { CARD_Read (&CardFile, &savebuffer[sbo], SectorSize, sbo); sbo += SectorSize; blocks -= SectorSize; } CARD_Close (&CardFile); CARD_Unmount (CARDSLOT); /*** update SRAM ***/ memcpy(&inzipped,&savebuffer[2112],sizeof(inzipped)); outzipped = 0x10000; uncompress ((Bytef *) &sram.sram, &outzipped, (Bytef *) &savebuffer[2112+sizeof(inzipped)], inzipped); sram.crc = crc32 (0, &sram.sram[0], 0x10000); /*** Inform user ***/ sprintf (action, "Loaded %d bytes successfully", size); GUI_WaitPrompt("Information",action); return 1; } } GUI_WaitPrompt("Error","Unable to mount memory card"); return 0; } /**************************************************************************** * ManageState * * Here is the main Freeze File Management stuff. * The output file contains an icon (2K), 64 bytes comment and the STATE (~128k) * * direction == 0 save, 1 load. ****************************************************************************/ int ManageState (u8 direction, u8 device) { if (!cart.romsize) return 0; char filename[MAXJOLIET]; if (direction) GUI_MsgBoxOpen("Information","Loading State ...",1); else GUI_MsgBoxOpen("Information","Saving State ...",1); /* clean buffer */ memset(savebuffer, 0, STATE_SIZE); if (device == 0) { /* FAT support */ sprintf (filename, "%s.gpz", rom_filename); return FAT_ManageFile(filename,direction,0); } /* Memory CARD support */ char action[80]; int CardError; unsigned int SectorSize; int blocks; char comment[2][32] = { {"Genesis Plus 1.2a [FRZ]"}, {"Freeze State"} }; int outbytes = 0; int sbo; int state_size = 0; /* First, build a filename */ sprintf (filename, "MD-%04X.gpz", realchecksum); strcpy (comment[1], filename); /* set MCARD slot nr. */ u8 CARDSLOT = device - 1; /* Saving */ if (direction == 0) { /* Build the output buffer */ memcpy (&savebuffer, &icon, 2048); memcpy (&savebuffer[2048], &comment[0], 64); state_size = state_save(&savebuffer[2112]); } outbytes = 2048 + 64 + state_size; /*** Initialise the CARD system ***/ memset (&SysArea, 0, CARD_WORKAREA); CARD_Init ("GENP", "00"); /*** Attempt to mount the card ***/ CardError = MountTheCard (CARDSLOT); if (CardError) { /*** Retrieve the sector size ***/ CardError = CARD_GetSectorSize (CARDSLOT, &SectorSize); switch (direction) { case 0: /*** Saving ***/ /*** Determine number of blocks on this card ***/ blocks = (outbytes / SectorSize) * SectorSize; if (outbytes % SectorSize) blocks += SectorSize; /*** Check if a previous save exists ***/ if (CardFileExists (filename, CARDSLOT)) { CardError = CARD_Open (CARDSLOT, filename, &CardFile); if (CardError) { sprintf (action, "Unable to open file (%d)", CardError); GUI_WaitPrompt("Error",action); CARD_Unmount (CARDSLOT); return 0; } int size = CardFile.len; CARD_Close (&CardFile); if (size < blocks) { /* new size is bigger: check if there is enough space left */ CardError = CARD_Create (CARDSLOT, "TEMP", blocks-size, &CardFile); if (CardError) { sprintf (action, "Unable to create temporary file (%d)", CardError); GUI_WaitPrompt("Error",action); CARD_Unmount (CARDSLOT); return 0; } CARD_Close (&CardFile); CARD_Delete(CARDSLOT, "TEMP"); } /* always delete existing slot */ CARD_Delete(CARDSLOT, filename); } /*** Create a new slot ***/ CardError = CARD_Create (CARDSLOT, filename, blocks, &CardFile); if (CardError) { sprintf (action, "Unable to create new file (%d)", CardError); GUI_WaitPrompt("Error",action); CARD_Unmount (CARDSLOT); return 0; } /*** Continue and save ***/ CARD_GetStatus (CARDSLOT, CardFile.filenum, &CardStatus); CardStatus.icon_addr = 0x0; CardStatus.icon_fmt = 2; CardStatus.icon_speed = 1; CardStatus.comment_addr = 2048; CARD_SetStatus (CARDSLOT, CardFile.filenum, &CardStatus); /*** And write the blocks out ***/ sbo = 0; while (outbytes > 0) { CardError = CARD_Write (&CardFile, &savebuffer[sbo], SectorSize, sbo); outbytes -= SectorSize; sbo += SectorSize; } CARD_Close (&CardFile); CARD_Unmount (CARDSLOT); sprintf (action, "Saved %d bytes successfully", blocks); GUI_WaitPrompt("Information",action); return 1; default: /*** Loading ***/ if (!CardFileExists (filename, CARDSLOT)) { GUI_WaitPrompt("Error","File does not exist !"); CARD_Unmount (CARDSLOT); return 0; } memset (&CardFile, 0, sizeof (CardFile)); CardError = CARD_Open (CARDSLOT, filename, &CardFile); if (CardError) { sprintf (action, "Unable to open file (%d)", CardError); GUI_WaitPrompt("Error",action); CARD_Unmount (CARDSLOT); return 0; } blocks = CardFile.len; if (blocks < SectorSize) blocks = SectorSize; if (blocks % SectorSize) blocks++; /*** Just read the file back in ***/ sbo = 0; int size = blocks; while (blocks > 0) { CARD_Read (&CardFile, &savebuffer[sbo], SectorSize, sbo); sbo += SectorSize; blocks -= SectorSize; } CARD_Close (&CardFile); CARD_Unmount (CARDSLOT); /*** Load State ***/ state_load(&savebuffer[2112]); /*** Inform user ***/ sprintf (action, "Loaded %d bytes successfully", size); GUI_WaitPrompt("Information",action); return 1; } } GUI_WaitPrompt("Error","Unable to mount memory card !"); return 0; }
zyking1987-genplus-droid
genplusgx/gx/fileio/file_mem.c
C
gpl2
18,366
/* * file_fat.c * * FAT loading support * * Eke-Eke (2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #ifndef _FILE_FAT_H #define _FILE_FAT_H #define TYPE_RECENT 0 #define TYPE_SD 1 #ifdef HW_RVL #define TYPE_USB 2 #endif #define FATCHUNK (2048) extern void FAT_ClearDirectory(void); extern int FAT_UpdateDirectory(bool go_up, char *filename); extern int FAT_ParseDirectory(void); extern int FAT_LoadFile(u8* buffer,u32 selection); extern int FAT_Open(int type); #endif
zyking1987-genplus-droid
genplusgx/gx/fileio/file_fat.h
C
gpl2
1,314
/****************************************************************************** * * unzip.c * * Zip Support * * Only partial support is included, in that only the first file within the archive * is considered to be a ROM image. * * Softdev (2006) * Eke-Eke (2007,2008) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #include "shared.h" #include "gui.h" /* * PKWare Zip Header - adopted into zip standard */ #define PKZIPID 0x504b0304 #define MAXROM 0x500000 #define ZIPCHUNK 2048 /* * Zip file header definition */ typedef struct { unsigned int zipid __attribute__ ((__packed__)); // 0x04034b50 unsigned short zipversion __attribute__ ((__packed__)); unsigned short zipflags __attribute__ ((__packed__)); unsigned short compressionMethod __attribute__ ((__packed__)); unsigned short lastmodtime __attribute__ ((__packed__)); unsigned short lastmoddate __attribute__ ((__packed__)); unsigned int crc32 __attribute__ ((__packed__)); unsigned int compressedSize __attribute__ ((__packed__)); unsigned int uncompressedSize __attribute__ ((__packed__)); unsigned short filenameLength __attribute__ ((__packed__)); unsigned short extraDataLength __attribute__ ((__packed__)); } PKZIPHEADER; /* * Zip files are stored little endian * Support functions for short and int types */ static inline u32 FLIP32 (u32 b) { unsigned int c; c = (b & 0xff000000) >> 24; c |= (b & 0xff0000) >> 8; c |= (b & 0xff00) << 8; c |= (b & 0xff) << 24; return c; } static inline u16 FLIP16 (u16 b) { u16 c; c = (b & 0xff00) >> 8; c |= (b & 0xff) << 8; return c; } /**************************************************************************** * IsZipFile * * Returns TRUE when PKZIPID is first four characters of buffer ****************************************************************************/ int IsZipFile (char *buffer) { unsigned int *check; check = (unsigned int *) buffer; if (check[0] == PKZIPID) return 1; return 0; } /***************************************************************************** * UnZipBuffer * ******************************************************************************/ int UnZipBuffer (unsigned char *outbuffer, FILE *fd, char *filename) { PKZIPHEADER pkzip; int zipoffset = 0; int zipchunk = 0; char out[ZIPCHUNK]; z_stream zs; int res; int bufferoffset = 0; int have = 0; char readbuffer[ZIPCHUNK]; char msg[64]; /*** Read Zip Header ***/ fread(readbuffer, ZIPCHUNK, 1, fd); /*** Copy PKZip header to local, used as info ***/ memcpy (&pkzip, &readbuffer, sizeof (PKZIPHEADER)); if (FLIP32 (pkzip.uncompressedSize) > MAXROMSIZE) { GUI_WaitPrompt("Error","File is too large !"); return 0; } sprintf (msg, "Unzipping %d bytes ...", FLIP32 (pkzip.uncompressedSize)); GUI_MsgBoxOpen("Information",msg,1); /*** Prepare the zip stream ***/ memset (&zs, 0, sizeof (z_stream)); zs.zalloc = Z_NULL; zs.zfree = Z_NULL; zs.opaque = Z_NULL; zs.avail_in = 0; zs.next_in = Z_NULL; res = inflateInit2 (&zs, -MAX_WBITS); if (res != Z_OK) { GUI_WaitPrompt("Error","Unable to unzip file !"); return 0; } /*** Get file name (first file) ***/ int size = FLIP16 (pkzip.filenameLength); if (size > 255) size = 255; strncpy(filename, &readbuffer[sizeof(PKZIPHEADER)], size); filename[size] = 0; /*** Set ZipChunk for first pass ***/ zipoffset = (sizeof (PKZIPHEADER) + size + FLIP16 (pkzip.extraDataLength)); zipchunk = ZIPCHUNK - zipoffset; /*** Now do it! ***/ do { zs.avail_in = zipchunk; zs.next_in = (Bytef *) &readbuffer[zipoffset]; /*** Now inflate until input buffer is exhausted ***/ do { zs.avail_out = ZIPCHUNK; zs.next_out = (Bytef *) &out; res = inflate (&zs, Z_NO_FLUSH); if (res == Z_MEM_ERROR) { inflateEnd (&zs); GUI_WaitPrompt("Error","Unable to unzip file !"); return 0; } have = ZIPCHUNK - zs.avail_out; if (have) { /*** Copy to normal block buffer ***/ memcpy (&outbuffer[bufferoffset], &out, have); bufferoffset += have; } } while (zs.avail_out == 0); /*** Readup the next 2k block ***/ zipoffset = 0; zipchunk = ZIPCHUNK; fread(readbuffer, ZIPCHUNK, 1, fd); } while (res != Z_STREAM_END); inflateEnd (&zs); GUI_MsgBoxClose(); if (res == Z_STREAM_END) { if (FLIP32 (pkzip.uncompressedSize) == (u32) bufferoffset) return bufferoffset; else return FLIP32 (pkzip.uncompressedSize); } return 0; }
zyking1987-genplus-droid
genplusgx/gx/fileio/unzip.c
C
gpl2
5,576
/* * file_dvd.c * * ISO9660/Joliet DVD loading support * * Softdev (2006) * Eke-Eke (2007,2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #ifndef _FILE_DVD_H #define _FILE_DVD_H #define DVDCHUNK (2048) extern void DVD_ClearDirectory(void); extern int DVD_UpdateDirectory(bool go_up,u64 offset, u32 length); extern int DVD_ParseDirectory(void); extern int DVD_LoadFile(u8 *buffer,u32 selection); extern int DVD_Open(void); #endif
zyking1987-genplus-droid
genplusgx/gx/fileio/file_dvd.h
C
gpl2
1,255
/* * dvd.c * * Low-level DVD access * * Softdev (2006) * Eke-Eke (2007,2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #include "shared.h" #include "file_dvd.h" #include "gui.h" #ifndef HW_RVL static u64 DvdMaxOffset = 0x57057C00; /* 1.4 GB max. by default */ static vu32* const dvd = (u32*)0xCC006000; /* DVD I/O Address base */ static u8 *inquiry=(unsigned char *)0x80000004; /* pointer to drive ID */ #else static u64 DvdMaxOffset = 0x118244F00LL; /* 4.7 GB max. */ #endif static u8 DVDreadbuffer[2048] ATTRIBUTE_ALIGN (32); /* data buffer for all DVD operations */ /*************************************************************************** * dvd_read * * Read DVD disc sectors ***************************************************************************/ u32 dvd_read (void *dst, u32 len, u64 offset) { /*** We only allow 2k reads **/ if (len > DVDCHUNK) return 0; /*** Let's not read past end of DVD ***/ if(offset < DvdMaxOffset) { unsigned char *buffer = (unsigned char *) (unsigned int) DVDreadbuffer; DCInvalidateRange((void *)buffer, len); #ifndef HW_RVL dvd[0] = 0x2E; dvd[1] = 0; dvd[2] = 0xA8000000; dvd[3] = (u32)(offset >> 2); dvd[4] = len; dvd[5] = (u32) buffer; dvd[6] = len; dvd[7] = 3; /*** Enable reading with DMA ***/ while (dvd[7] & 1) usleep(10); memcpy (dst, buffer, len); /*** Ensure it has completed ***/ if (dvd[0] & 0x4) return 0; #else if (DI_ReadDVD(buffer, len >> 11, (u32)(offset >> 11))) return 0; memcpy (dst, buffer, len); #endif return 1; } return 0; } /**************************************************************************** * dvd_motor_off * * Stop the DVD Motor * * This can be used to prevent the Disc from spinning during playtime ****************************************************************************/ void dvd_motor_off( ) { GUI_MsgBoxOpen("Information", "Stopping DVD drive ...", 1); #ifndef HW_RVL dvd[0] = 0x2e; dvd[1] = 0; dvd[2] = 0xe3000000; dvd[3] = 0; dvd[4] = 0; dvd[5] = 0; dvd[6] = 0; dvd[7] = 1; // Do immediate while (dvd[7] & 1) usleep(10); /*** PSO Stops blackscreen at reload ***/ dvd[0] = 0x14; dvd[1] = 0; #else DI_StopMotor(); #endif GUI_MsgBoxClose(); } #ifndef HW_RVL /**************************************************************************** * uselessinquiry * * As the name suggests, this function is quite useless. * It's only purpose is to stop any pending DVD interrupts while we use the * memcard interface. * * libOGC tends to foul up if you don't, and sometimes does if you do! ****************************************************************************/ void uselessinquiry () { dvd[0] = 0; dvd[1] = 0; dvd[2] = 0x12000000; dvd[3] = 0; dvd[4] = 0x20; dvd[5] = 0x80000000; dvd[6] = 0x20; dvd[7] = 1; while (dvd[7] & 1) usleep(10); } /**************************************************************************** * dvd_drive_detect() * * Detect the DVD Drive Type * ****************************************************************************/ void dvd_drive_detect() { dvd[0] = 0x2e; dvd[1] = 0; dvd[2] = 0x12000000; dvd[3] = 0; dvd[4] = 0x20; dvd[5] = 0x80000000; dvd[6] = 0x20; dvd[7] = 3; while( dvd[7] & 1 ) usleep(10); DCFlushRange((void *)0x80000000, 32); int driveid = (int)inquiry[2]; if ((driveid == 4) || (driveid == 6) || (driveid == 8)) { /* Gamecube DVD Drive (1.4 GB)*/ DvdMaxOffset = 0x57057C00; } else { /* Wii DVD Drive (4.7GB) */ DvdMaxOffset = 0x118244F00LL; } } #endif
zyking1987-genplus-droid
genplusgx/gx/fileio/dvd.c
C
gpl2
4,615
/* * file_fat.c * * FAT loading support * * Eke-Eke (2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #ifndef _FILE_FAT_H #define _FILE_FAT_H #define TYPE_SD (0) #ifdef HW_RVL #define TYPE_USB (1) #define TYPE_DVD (2) #else #define TYPE_DVD (1) #endif #define TYPE_RECENT (TYPE_DVD + 1) #define FILECHUNK (2048) extern int OpenDirectory(int device); extern int UpdateDirectory(bool go_up, char *filename); extern int ParseDirectory(void); extern int LoadFile(u8* buffer,u32 selection, char *filename); #endif
zyking1987-genplus-droid
genplusgx/gx/fileio/file_load.h
C
gpl2
1,342
/****************************************************************************** * * unzip.c * * Zip Support * * Only partial support is included, in that only the first file within the archive * is considered to be a ROM image. * * Softdev (2006) * Eke-Eke (2007,2008) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #ifndef _UNZIP_H_ #define _UNZIP_H_ extern int IsZipFile (char *buffer); int UnZipBuffer (unsigned char *outbuffer, FILE *fd, char *filename); #endif
zyking1987-genplus-droid
genplusgx/gx/fileio/unzip.h
C
gpl2
1,302
/* * file_slot.c * * FAT and Memory Card SRAM/State slots managment * * Softdev (2006) * Eke-Eke (2007,2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "shared.h" #include "file_slot.h" #include "file_load.h" #include "gui.h" #include "filesel.h" #include "saveicon.h" /** * libOGC CARD System Work Area */ static u8 SysArea[CARD_WORKAREA] ATTRIBUTE_ALIGN (32); /**************************************************************************** * CardMount * * libOGC provides the CARD_Mount function, and it should be all you need. * However, experience with previous emulators has taught me that you are * better off doing a little bit more than that! * *****************************************************************************/ static int CardMount(int slot) { int tries = 0; #if defined(HW_DOL) *(unsigned long *) (0xCC006800) |= 1 << 13; /*** Disable Encryption ***/ #elif defined(HW_RVL) *(unsigned long *) (0xCD006800) |= 1 << 13; /*** Disable Encryption ***/ #endif while (tries < 10) { VIDEO_WaitVSync (); if (CARD_Mount(slot, SysArea, NULL) == CARD_ERROR_READY) return 1; else EXI_ProbeReset (); tries++; } return 0; } /**************************************************************************** * Slot Management * * ****************************************************************************/ void slot_autoload(int slot, int device) { if (!cart.romsize) return; SILENT = 1; slot_load(slot, device); SILENT = 0; } void slot_autosave(int slot, int device) { if (!cart.romsize) return; /* only save if SRAM changed */ if (!slot && (crc32(0, &sram.sram[0], 0x10000) == sram.crc)) return; SILENT = 1; slot_save(slot, device); SILENT = 0; } void slot_autodetect(int slot, int device, t_slot *ptr) { if (!ptr) return; char filename[MAXPATHLEN]; memset(ptr,0,sizeof(t_slot)); if (!device) { /* FAT support */ if (slot > 0) sprintf (filename,"%s/saves/%s.gp%d", DEFAULT_PATH, rom_filename, slot - 1); else sprintf (filename,"%s/saves/%s.srm", DEFAULT_PATH, rom_filename); /* Open file */ FILE *fp = fopen(filename, "rb"); if (fp) { /* Retrieve date & close */ struct stat filestat; stat(filename, &filestat); struct tm *timeinfo = localtime(&filestat.st_mtime); ptr->year = 1900 + timeinfo->tm_year; ptr->month = timeinfo->tm_mon; ptr->day = timeinfo->tm_mday; ptr->hour = timeinfo->tm_hour; ptr->min = timeinfo->tm_min; fclose(fp); ptr->valid = 1; } } else { /* Memory Card support */ if (slot > 0) sprintf(filename,"MD-%04X.gp%d", rominfo.realchecksum, slot - 1); else sprintf(filename,"MD-%04X.srm", rominfo.realchecksum); /* Initialise the CARD system */ memset(&SysArea, 0, CARD_WORKAREA); CARD_Init("GENP", "00"); /* CARD slot */ device--; /* Mount CARD */ if (CardMount(device)) { /* Open file */ card_file CardFile; if (CARD_Open(device, filename, &CardFile) == CARD_ERROR_READY) { /* Retrieve date & close */ card_stat CardStatus; CARD_GetStatus(device, CardFile.filenum, &CardStatus); time_t rawtime = CardStatus.time; struct tm *timeinfo = localtime(&rawtime); ptr->year = 1900 + timeinfo->tm_year; ptr->month = timeinfo->tm_mon; ptr->day = timeinfo->tm_mday; ptr->hour = timeinfo->tm_hour; ptr->min = timeinfo->tm_min; CARD_Close(&CardFile); ptr->valid = 1; } CARD_Unmount(device); } } } int slot_delete(int slot, int device) { char filename[MAXPATHLEN]; int ret = 0; if (!device) { /* FAT support */ if (slot > 0) { /* remove screenshot */ sprintf(filename,"%s/saves/%s__%d.png", DEFAULT_PATH, rom_filename, slot - 1); remove(filename); sprintf (filename,"%s/saves/%s.gp%d", DEFAULT_PATH, rom_filename, slot - 1); } else sprintf (filename,"%s/saves/%s.srm", DEFAULT_PATH, rom_filename); /* Delete file */ ret = remove(filename); } else { /* Memory Card support */ if (slot > 0) sprintf(filename,"MD-%04X.gp%d", rominfo.realchecksum, slot - 1); else sprintf(filename,"MD-%04X.srm", rominfo.realchecksum); /* Initialise the CARD system */ memset(&SysArea, 0, CARD_WORKAREA); CARD_Init("GENP", "00"); /* CARD slot */ device--; /* Mount CARD */ if (CardMount(device)) { /* Delete file */ ret = CARD_Delete(device,filename); CARD_Unmount(device); } } return ret; } int slot_load(int slot, int device) { char filename[MAXPATHLEN]; int filesize, done = 0; int offset = 0; u8 *savebuffer; if (slot > 0) { GUI_MsgBoxOpen("Information","Loading State ...",1); } else { if (!sram.on) { GUI_WaitPrompt("Error","SRAM is disabled !"); return 0; } GUI_MsgBoxOpen("Information","Loading SRAM ...",1); } if (!device) { /* FAT support */ if (slot > 0) sprintf (filename,"%s/saves/%s.gp%d", DEFAULT_PATH, rom_filename, slot - 1); else sprintf (filename,"%s/saves/%s.srm", DEFAULT_PATH, rom_filename); /* Open file */ FILE *fp = fopen(filename, "rb"); if (!fp) { GUI_WaitPrompt("Error","Unable to open file !"); return 0; } /* Read size */ fseek(fp, 0, SEEK_END); filesize = ftell(fp); fseek(fp, 0, SEEK_SET); /* allocate buffer */ savebuffer = (u8 *)memalign(32,filesize); if (!savebuffer) { GUI_WaitPrompt("Error","Unable to allocate memory !"); fclose(fp); return 0; } /* Read into buffer (2k blocks) */ while (filesize > FILECHUNK) { fread(savebuffer + done, FILECHUNK, 1, fp); done += FILECHUNK; filesize -= FILECHUNK; } /* Read remaining bytes */ fread(savebuffer + done, filesize, 1, fp); done += filesize; fclose(fp); } else { /* Memory Card support */ if (slot > 0) sprintf(filename, "MD-%04X.gp%d", rominfo.realchecksum, slot - 1); else sprintf(filename, "MD-%04X.srm", rominfo.realchecksum); /* Initialise the CARD system */ char action[64]; memset(&SysArea, 0, CARD_WORKAREA); CARD_Init("GENP", "00"); /* CARD slot */ device--; /* Attempt to mount the card */ if (!CardMount(device)) { GUI_WaitPrompt("Error","Unable to mount memory card"); return 0; } /* Retrieve the sector size */ u32 SectorSize = 0; int CardError = CARD_GetSectorSize(device, &SectorSize); if (!SectorSize) { sprintf(action, "Invalid sector size (%d)", CardError); GUI_WaitPrompt("Error",action); CARD_Unmount(device); return 0; } /* Open file */ card_file CardFile; CardError = CARD_Open(device, filename, &CardFile); if (CardError) { sprintf(action, "Unable to open file (%d)", CardError); GUI_WaitPrompt("Error",action); CARD_Unmount(device); return 0; } /* Retrieve file size */ filesize = CardFile.len; if (filesize % SectorSize) filesize = ((filesize / SectorSize) + 1) * SectorSize; /* Allocate buffer */ savebuffer = (u8 *)memalign(32,filesize); if (!savebuffer) { GUI_WaitPrompt("Error","Unable to allocate memory !"); CARD_Close(&CardFile); CARD_Unmount(device); return 0; } /* Read file sectors */ while (filesize > 0) { CARD_Read(&CardFile, &savebuffer[done], SectorSize, done); done += SectorSize; filesize -= SectorSize; } CARD_Close(&CardFile); CARD_Unmount(device); offset = 2112; } if (slot > 0) { /* Load state */ if (!state_load(&savebuffer[offset])) { free(savebuffer); GUI_WaitPrompt("Error","Unable to load state !"); return 0; } } else { /* Load SRAM & update CRC */ memcpy(sram.sram, &savebuffer[offset], 0x10000); sram.crc = crc32(0, sram.sram, 0x10000); } free(savebuffer); GUI_MsgBoxClose(); return 1; } int slot_save(int slot, int device) { char filename[MAXPATHLEN]; int filesize, done = 0; int offset = device ? 2112 : 0; u8 *savebuffer; if (slot > 0) { /* allocate buffer */ savebuffer = (u8 *)memalign(32,STATE_SIZE); if (!savebuffer) { GUI_WaitPrompt("Error","Unable to allocate memory !"); return 0; } GUI_MsgBoxOpen("Information","Saving State ...",1); filesize = state_save(&savebuffer[offset]); } else { if (!sram.on) { GUI_WaitPrompt("Error","SRAM is disabled !"); return 0; } /* allocate buffer */ savebuffer = (u8 *)memalign(32,0x10000+offset); if (!savebuffer) { GUI_WaitPrompt("Error","Unable to allocate memory !"); return 0; } GUI_MsgBoxOpen("Information","Saving SRAM ...",1); memcpy(&savebuffer[offset], sram.sram, 0x10000); sram.crc = crc32(0, sram.sram, 0x10000); filesize = 0x10000; } if (!device) { /* FAT support */ if (slot > 0) sprintf(filename, "%s/saves/%s.gp%d", DEFAULT_PATH, rom_filename, slot - 1); else sprintf(filename, "%s/saves/%s.srm", DEFAULT_PATH, rom_filename); /* Open file */ FILE *fp = fopen(filename, "wb"); if (!fp) { GUI_WaitPrompt("Error","Unable to open file !"); free(savebuffer); return 0; } /* Write from buffer (2k blocks) */ while (filesize > FILECHUNK) { fwrite(savebuffer + done, FILECHUNK, 1, fp); done += FILECHUNK; filesize -= FILECHUNK; } /* Write remaining bytes */ fwrite(savebuffer + done, filesize, 1, fp); done += filesize; fclose(fp); } else { /* Memory Card support */ if (slot > 0) sprintf(filename, "MD-%04X.gp%d", rominfo.realchecksum, slot - 1); else sprintf(filename, "MD-%04X.srm", rominfo.realchecksum); /* Initialise the CARD system */ char action[64]; memset(&SysArea, 0, CARD_WORKAREA); CARD_Init("GENP", "00"); /* CARD slot */ device--; /* Attempt to mount the card */ if (!CardMount(device)) { GUI_WaitPrompt("Error","Unable to mount memory card"); free(savebuffer); return 0; } /* Retrieve the sector size */ u32 SectorSize = 0; int CardError = CARD_GetSectorSize(device, &SectorSize); if (!SectorSize) { sprintf(action, "Invalid sector size (%d)", CardError); GUI_WaitPrompt("Error",action); CARD_Unmount(device); free(savebuffer); return 0; } /* Build the output buffer */ char comment[2][32] = { {"Genesis Plus GX"}, {"SRAM Save"} }; strcpy (comment[1], filename); memcpy (&savebuffer[0], &icon, 2048); memcpy (&savebuffer[2048], &comment[0], 64); /* Adjust file size */ filesize += 2112; if (filesize % SectorSize) filesize = ((filesize / SectorSize) + 1) * SectorSize; /* Check if file already exists */ card_file CardFile; if (CARD_Open(device, filename, &CardFile) == CARD_ERROR_READY) { int size = filesize - CardFile.len; CARD_Close(&CardFile); memset(&CardFile,0,sizeof(CardFile)); /* Check file new size */ if (size > 0) { CardError = CARD_Create(device, "TEMP", size, &CardFile); if (CardError) { sprintf(action, "Unable to increase file size (%d)", CardError); GUI_WaitPrompt("Error",action); CARD_Unmount(device); free(savebuffer); return 0; } /* delete temporary file */ CARD_Close(&CardFile); memset(&CardFile,0,sizeof(CardFile)); CARD_Delete(device, "TEMP"); } /* delete previously existing file */ CARD_Delete(device, filename); } /* Create a new file */ CardError = CARD_Create(device, filename, filesize, &CardFile); if (CardError) { sprintf(action, "Unable to create file (%d)", CardError); GUI_WaitPrompt("Error",action); CARD_Unmount(device); free(savebuffer); return 0; } /* Update file informations */ time_t rawtime; time(&rawtime); card_stat CardStatus; CARD_GetStatus(device, CardFile.filenum, &CardStatus); CardStatus.icon_addr = 0x0; CardStatus.icon_fmt = 2; CardStatus.icon_speed = 1; CardStatus.comment_addr = 2048; CardStatus.time = rawtime; CARD_SetStatus(device, CardFile.filenum, &CardStatus); /* Write file sectors */ while (filesize > 0) { CARD_Write(&CardFile, &savebuffer[done], SectorSize, done); filesize -= SectorSize; done += SectorSize; } /* Close file */ CARD_Close(&CardFile); CARD_Unmount(device); } GUI_MsgBoxClose(); free(savebuffer); /* Save screenshot */ if (slot && !device) { sprintf(filename,"%s/saves/%s__%d.png", DEFAULT_PATH, rom_filename, slot - 1); gxSaveScreenshot(filename); } return 1; }
zyking1987-genplus-droid
genplusgx/gx/fileio/file_slot.c
C
gpl2
14,493
/* * history.c * * Generic ROM history list managment * * Martin Disibio (6/17/08) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #include "shared.h" #include "history.h" t_history history; /**************************************************************************** * history_add_file * * Adds the given file path to the top of the history list, shifting each * existing entry in the history down one place. If given file path is * already in the list then the existing entry is (in effect) moved to the * top instead. ****************************************************************************/ void history_add_file(char *filepath, char *filename) { /* Create the new entry for this path. */ t_history_entry newentry; strncpy(newentry.filepath, filepath, MAXJOLIET - 1); strncpy(newentry.filename, filename, MAXJOLIET - 1); newentry.filepath[MAXJOLIET - 1] = '\0'; newentry.filename[MAXJOLIET - 1] = '\0'; t_history_entry oldentry; /* Old entry is the one being shuffled down a spot. */ t_history_entry currentry; /* Curr entry is the one that just replaced old path. */ /* Initially set curr entry to the new value. */ memcpy(&currentry, &newentry, sizeof(t_history_entry)); int i; for(i=0; i < NUM_HISTORY_ENTRIES; i++) { /* Save off the next entry. */ memcpy(&oldentry, &history.entries[i], sizeof(t_history_entry)); /* Overwrite with the previous entry. */ memcpy(&history.entries[i], &currentry, sizeof(t_history_entry)); /* Switch the old entry to the curr entry now. */ memcpy(&currentry, &oldentry, sizeof(t_history_entry)); /* If the entry in the list at this spot matches the new entry then do nothing and let this entry get deleted. */ if(strcmp(newentry.filepath, currentry.filepath) == 0 && strcmp(newentry.filename, currentry.filename) == 0) break; } /* now save to disk */ history_save(); } void history_save() { /* open file */ char fname[MAXPATHLEN]; sprintf (fname, "%s/history.ini", DEFAULT_PATH); FILE *fp = fopen(fname, "wb"); if (fp) { /* write file */ fwrite(&history, sizeof(history), 1, fp); fclose(fp); } } void history_load(void) { /* open file */ char fname[MAXPATHLEN]; sprintf (fname, "%s/history.ini", DEFAULT_PATH); FILE *fp = fopen(fname, "rb"); if (fp) { /* read file */ fread(&history, sizeof(history), 1, fp); fclose(fp); } } void history_default(void) { int i; for(i=0; i < NUM_HISTORY_ENTRIES; i++) memset(&history.entries[i], 0, sizeof(t_history_entry)); /* restore history */ history_load(); }
zyking1987-genplus-droid
genplusgx/gx/fileio/history.c
C
gpl2
3,525
/* * file_fat.c * * FAT loading support * * Eke-Eke (2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #include "shared.h" #include "gui.h" #include "history.h" #include "unzip.h" #include "filesel.h" #include "file_fat.h" #include "file_dvd.h" /* FAT directory has been updated */ static int haveFATdir = 0; /* current FAT directory */ static char fatdir[MAXPATHLEN]; /* current FAT device */ static int fat_type = 0; static int useHistory = 0; /*************************************************************************** * FAT_ClearDirectory * * Clear FAT directory flag ***************************************************************************/ void FAT_ClearDirectory(void) { haveFATdir = 0; } /*************************************************************************** * FAT_UpdateDirectory * * Update FAT current root directory ***************************************************************************/ int FAT_UpdateDirectory(bool go_up, char *filename) { int size=0; char *test; char temp[MAXPATHLEN]; /* go up to parent directory */ if (strcmp(filename,"..") == 0) { /* determine last subdirectory namelength */ sprintf(temp,"%s",fatdir); test= strtok(temp,"/"); while (test != NULL) { size = strlen(test); test = strtok(NULL,"/"); } /* remove last subdirectory name */ size = strlen(fatdir) - size; fatdir[size-1] = 0; } else if (go_up) { /* root has no parent directory */ return 0; } else { /* by default, simply append folder name */ sprintf(fatdir, "%s%s/",fatdir, filename); } return 1; } /*************************************************************************** * FAT_ParseDirectory * * List files into one FAT directory ***************************************************************************/ int FAT_ParseDirectory(void) { int nbfiles = 0; char filename[MAXPATHLEN]; struct stat filestat; /* open directory */ DIR_ITER *dir = diropen (fatdir); if (dir == NULL) { GUI_WaitPrompt("Error","Unable to open directory !"); return -1; } while ((dirnext(dir, filename, &filestat) == 0) && (nbfiles < MAXFILES)) { if (strcmp(filename,".") != 0) { memset(&filelist[nbfiles], 0, sizeof (FILEENTRIES)); sprintf(filelist[nbfiles].filename,"%s",filename); filelist[nbfiles].length = filestat.st_size; filelist[nbfiles].flags = (filestat.st_mode & S_IFDIR) ? 1 : 0; nbfiles++; } } dirclose(dir); /* Sort the file list */ qsort(filelist, nbfiles, sizeof(FILEENTRIES), FileSortCallback); return nbfiles; } /**************************************************************************** * FAT_LoadFile * * This function will load a BIN, SMD or ZIP file from DVD into the ROM buffer. * This functions return the actual size of data copied into the buffer * ****************************************************************************/ int FAT_LoadFile(u8 *buffer, u32 selection) { /* If loading from history then we need to setup a few more things. */ if(useHistory) { /* Get the parent folder for the file. */ strncpy(fatdir, history.entries[selection].filepath, MAXJOLIET-1); fatdir[MAXJOLIET-1] = '\0'; /* Get the length of the file. This has to be done * before calling LoadFile(). */ char filepath[MAXJOLIET]; struct stat filestat; snprintf(filepath, MAXJOLIET-1, "%s%s", history.entries[selection].filepath, history.entries[selection].filename); filepath[MAXJOLIET-1] = '\0'; if(stat(filepath, &filestat) == 0) { filelist[selection].length = filestat.st_size; } /* update filelist */ haveFATdir = 0; } /* file size */ int length = filelist[selection].length; if (length > 0) { /* Add/move the file to the top of the history. */ history_add_file(fatdir, filelist[selection].filename); /* full filename */ char fname[MAXPATHLEN]; sprintf(fname, "%s%s",fatdir,filelist[selection].filename); /* open file */ FILE *sdfile = fopen(fname, "rb"); if (sdfile == NULL) { GUI_WaitPrompt("Error","Unable to open file !"); haveFATdir = 0; return 0; } /* Read first data chunk */ unsigned char temp[FATCHUNK]; fread(temp, FATCHUNK, 1, sdfile); fclose(sdfile); /* determine file type */ if (!IsZipFile ((char *) temp)) { if (length > MAXROMSIZE) { GUI_WaitPrompt("Error","File size not supported !"); return 0; } /* re-open and read file */ sdfile = fopen(fname, "rb"); if (sdfile) { char msg[64]; sprintf(msg,"Loading %d bytes ...", length); GUI_MsgBoxOpen("Information",msg,1); int i = 0; while (length > FATCHUNK) { fread(buffer+i, FATCHUNK, 1, sdfile); length -= FATCHUNK; i += FATCHUNK; } fread(buffer+i, length, 1, sdfile); fclose(sdfile); return filelist[selection].length; } } else { /* unzip file */ return UnZipBuffer (buffer, 0, fname); } } return 0; } /**************************************************************************** * OpenFAT * * Function to load a FAT directory and display to user. ****************************************************************************/ int FAT_Open(int type) { int max = 0; char root[10] = ""; #ifdef HW_RVL /* FAT header */ if (type == TYPE_SD) sprintf (root, "sd:"); else if (type == TYPE_USB) sprintf (root, "usb:"); #endif /* if FAT device type changed, reload filelist */ if (fat_type != type) { fat_type = type; haveFATdir = 0; } /* update filelist */ if (haveFATdir == 0) { useHistory = 0; if (type == TYPE_RECENT) { /* fetch history list */ useHistory = 1; int i; for(i=0; i < NUM_HISTORY_ENTRIES; i++) { if(history.entries[i].filepath[0] > 0) { filelist[i].offset = 0; filelist[i].length = 0; filelist[i].flags = 0; strncpy(filelist[i].filename, history.entries[i].filename, MAXJOLIET-1); filelist[i].filename[MAXJOLIET-1] = '\0'; max++; } else { /* Found the end of the list. */ break; } } } else { /* reset root directory */ sprintf (fatdir, "%s%s/roms/", root, DEFAULT_PATH); /* if directory doesn't exist, use root as default */ DIR_ITER *dir = diropen(fatdir); if (dir == NULL) sprintf (fatdir, "%s/", root); else dirclose(dir); /* parse root directory */ max = FAT_ParseDirectory (); } if (max > 0) { /* FAT is default */ haveFATdir = 1; DVD_ClearDirectory(); /* reset File selector */ ClearSelector(max); return 1; } else { /* no entries found */ if (max == 0) GUI_WaitPrompt("Error","No files found !"); return 0; } } return 1; }
zyking1987-genplus-droid
genplusgx/gx/fileio/file_fat.c
C
gpl2
8,159
<html> <!-- Mirrored from genplus-gx.googlecode.com/svn/!svn/bc/427/trunk/source/gx/fileio/ by HTTrack Website Copier/3.x [XR&CO'2010], Mon, 13 Dec 2010 08:07:59 GMT --> <!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack --> <head><title>genplus-gx - Revision 427: /trunk/source/gx/fileio</title></head> <body> <h2>genplus-gx - Revision 427: /trunk/source/gx/fileio</h2> <ul> <li><a href="../index.html">..</a></li> <li><a href="dvd.c">dvd.c</a></li> <li><a href="dvd.h">dvd.h</a></li> <li><a href="file_dvd.c">file_dvd.c</a></li> <li><a href="file_dvd.h">file_dvd.h</a></li> <li><a href="file_fat.c">file_fat.c</a></li> <li><a href="file_fat.h">file_fat.h</a></li> <li><a href="file_mem.c">file_mem.c</a></li> <li><a href="file_mem.h">file_mem.h</a></li> <li><a href="history.c">history.c</a></li> <li><a href="history.h">history.h</a></li> <li><a href="unzip.c">unzip.c</a></li> <li><a href="unzip.h">unzip.h</a></li> </ul> <hr noshade><em><a href="http://code.google.com/">Google Code</a> powered by <a href="http://subversion.apache.org/">Subversion</a></em> </body> <!-- Mirrored from genplus-gx.googlecode.com/svn/!svn/bc/427/trunk/source/gx/fileio/ by HTTrack Website Copier/3.x [XR&CO'2010], Mon, 13 Dec 2010 08:08:07 GMT --> <!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack --> </html>
zyking1987-genplus-droid
genplusgx/gx/fileio/index.html
HTML
gpl2
1,452
/* * history.c * * Generic ROM history list managment * * Martin Disibio (6/17/08) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ********************************************************************************/ #ifndef _HISTORY_H #define _HISTORY_H #include "filesel.h" #define NUM_HISTORY_ENTRIES (10) /**************************************************************************** * ROM Play History * ****************************************************************************/ typedef struct { char filepath[MAXJOLIET]; char filename[MAXJOLIET]; } t_history_entry; typedef struct { t_history_entry entries[NUM_HISTORY_ENTRIES]; } t_history; extern t_history history; extern void history_add_file(char *filepath, char *filename); extern void history_save(void); extern void history_load(void); extern void history_default(void); #endif
zyking1987-genplus-droid
genplusgx/gx/fileio/history.h
C
gpl2
1,615
#ifndef _OSD_H_ #define _OSD_H_ #include <gccore.h> #include <ogcsys.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h> #include <sys/dir.h> #include <asndlib.h> #include <oggplayer.h> #ifdef HW_RVL #include <di/di.h> #include "vi_encoder.h" #endif #include "gx_input.h" #include "gx_audio.h" #include "gx_video.h" #include "config.h" #define DEFAULT_PATH "/genplus" #define GG_ROM "/genplus/ggenie.bin" #define AR_ROM "/genplus/areplay.bin" #define OS_ROM "/genplus/bios.bin" #define SK_ROM "/genplus/sk.bin" #define SK_UPMEM "/genplus/sk2chip.bin" #ifdef HW_RVL #define VERSION "Genesis Plus GX 1.5.0 (WII)" #else #define VERSION "Genesis Plus GX 1.5.0 (GCN)" #endif #define osd_input_Update() gx_input_UpdateEmu() /* globals */ extern void error(char *format, ...); extern void ClearGGCodes(); extern void GetGGEntries(); extern void legal(); extern void reloadrom (int size, char *name); extern void shutdown(); extern u32 frameticker; extern u32 Shutdown; extern u32 ConfigRequested; #endif /* _OSD_H_ */
zyking1987-genplus-droid
genplusgx/gx/osd.h
C
gpl2
1,137
/**************************************************************************** * vi_encoder.c * * Wii Audio/Video Encoder support * * Copyright (C) 2009 Hector Martin (marcan) * Additional code by Eke-Eke * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #ifdef HW_RVL #include <string.h> #include <gccore.h> #include <ogcsys.h> #include <ogc/machine/processor.h> #include "vi_encoder.h" /**************************************************************************** * I2C driver by Hector Martin (marcan) * ****************************************************************************/ #define _SHIFTL(v, s, w) \ ((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s))) #define _SHIFTR(v, s, w) \ ((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1))) extern void udelay(int us); static u32 i2cIdentFirst = 0; static u32 i2cIdentFlag = 1; static vu16* const _viReg = (u16*)0xCC002000; static vu32* const _i2cReg = (u32*)0xCD800000; static inline void __viOpenI2C(u32 channel) { u32 val = ((_i2cReg[49]&~0x8000)|0x4000); val |= _SHIFTL(channel,15,1); _i2cReg[49] = val; } static inline u32 __viSetSCL(u32 channel) { u32 val = (_i2cReg[48]&~0x4000); val |= _SHIFTL(channel,14,1); _i2cReg[48] = val; return 1; } static inline u32 __viSetSDA(u32 channel) { u32 val = (_i2cReg[48]&~0x8000); val |= _SHIFTL(channel,15,1); _i2cReg[48] = val; return 1; } static inline u32 __viGetSDA() { return _SHIFTR(_i2cReg[50],15,1); } static inline void __viCheckI2C() { __viOpenI2C(0); udelay(4); i2cIdentFlag = 0; if(__viGetSDA()!=0) i2cIdentFlag = 1; } static u32 __sendSlaveAddress(u8 addr) { u32 i; __viSetSDA(i2cIdentFlag^1); udelay(2); __viSetSCL(0); for(i=0;i<8;i++) { if(addr&0x80) __viSetSDA(i2cIdentFlag); else __viSetSDA(i2cIdentFlag^1); udelay(2); __viSetSCL(1); udelay(2); __viSetSCL(0); addr <<= 1; } __viOpenI2C(0); udelay(2); __viSetSCL(1); udelay(2); if(i2cIdentFlag==1 && __viGetSDA()!=0) return 0; __viSetSDA(i2cIdentFlag^1); __viOpenI2C(1); __viSetSCL(0); return 1; } static u32 __VISendI2CData(u8 addr,void *val,u32 len) { u8 c; s32 i,j; u32 level,ret; if(i2cIdentFirst==0) { __viCheckI2C(); i2cIdentFirst = 1; } _CPU_ISR_Disable(level); __viOpenI2C(1); __viSetSCL(1); __viSetSDA(i2cIdentFlag); udelay(4); ret = __sendSlaveAddress(addr); if(ret==0) { _CPU_ISR_Restore(level); return 0; } __viOpenI2C(1); for(i=0;i<len;i++) { c = ((u8*)val)[i]; for(j=0;j<8;j++) { if(c&0x80) __viSetSDA(i2cIdentFlag); else __viSetSDA(i2cIdentFlag^1); udelay(2); __viSetSCL(1); udelay(2); __viSetSCL(0); c <<= 1; } __viOpenI2C(0); udelay(2); __viSetSCL(1); udelay(2); if(i2cIdentFlag==1 && __viGetSDA()!=0) { _CPU_ISR_Restore(level); return 0; } __viSetSDA(i2cIdentFlag^1); __viOpenI2C(1); __viSetSCL(0); } __viOpenI2C(1); __viSetSDA(i2cIdentFlag^1); udelay(2); __viSetSDA(i2cIdentFlag); _CPU_ISR_Restore(level); return 1; } static void __VIWriteI2CRegister8(u8 reg, u8 data) { u8 buf[2]; buf[0] = reg; buf[1] = data; __VISendI2CData(0xe0,buf,2); udelay(2); } static void __VIWriteI2CRegister16(u8 reg, u16 data) { u8 buf[3]; buf[0] = reg; buf[1] = data >> 8; buf[2] = data & 0xFF; __VISendI2CData(0xe0,buf,3); udelay(2); } static void __VIWriteI2CRegister32(u8 reg, u32 data) { u8 buf[5]; buf[0] = reg; buf[1] = data >> 24; buf[2] = (data >> 16) & 0xFF; buf[3] = (data >> 8) & 0xFF; buf[4] = data & 0xFF; __VISendI2CData(0xe0,buf,5); udelay(2); } static void __VIWriteI2CRegisterBuf(u8 reg, int size, u8 *data) { u8 buf[0x100]; buf[0] = reg; memcpy(&buf[1], data, size); __VISendI2CData(0xe0,buf,size+1); udelay(2); } /**************************************************************************** * A/V functions support (Eke-Eke) * ****************************************************************************/ static const u8 gamma_coeffs[][33] = { /* GM_0_0 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* GM_0_1 */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x03, 0x97, 0x3B, 0x49, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x80, 0x1B, 0x80, 0xEB, 0x00 }, /* GM_0_2 */ { 0x00, 0x00, 0x00, 0x28, 0x00, 0x5A, 0x02, 0xDB, 0x0D, 0x8D, 0x30, 0x49, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x10, 0x00, 0x10, 0x40, 0x11, 0x00, 0x18, 0x80, 0x42, 0x00, 0xEB, 0x00 }, /* GM_0_3 */ { 0x00, 0x00, 0x00, 0x7A, 0x02, 0x3C, 0x07, 0x6D, 0x12, 0x9C, 0x27, 0x24, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x10, 0x00, 0x10, 0xC0, 0x15, 0x80, 0x29, 0x00, 0x62, 0x00, 0xEB, 0x00 }, /* GM_0_4 */ { 0x00, 0x4E, 0x01, 0x99, 0x05, 0x2D, 0x0B, 0x24, 0x14, 0x29, 0x20, 0xA4, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x00, 0x10, 0x10, 0x40, 0x12, 0xC0, 0x1D, 0xC0, 0x3B, 0x00, 0x78, 0xC0, 0xEB, 0x00 }, /* GM_0_5 */ { 0x00, 0xEC, 0x03, 0xD7, 0x08, 0x00, 0x0D, 0x9E, 0x14, 0x3E, 0x1B, 0xDB, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x10, 0xC0, 0x16, 0xC0, 0x27, 0xC0, 0x4B, 0x80, 0x89, 0x80, 0xEB, 0x00 }, /* GM_0_6 */ { 0x02, 0x76, 0x06, 0x66, 0x0A, 0x96, 0x0E, 0xF3, 0x13, 0xAC, 0x18, 0x49, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x12, 0x00, 0x1C, 0x00, 0x32, 0x80, 0x59, 0xC0, 0x96, 0x00, 0xEB, 0x00 }, /* GM_0_7 */ { 0x04, 0xEC, 0x08, 0xF5, 0x0C, 0x96, 0x0F, 0xCF, 0x12, 0xC6, 0x15, 0x80, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x14, 0x00, 0x22, 0x00, 0x3C, 0xC0, 0x66, 0x40, 0x9F, 0xC0, 0xEB, 0x00 }, /* GM_0_8 */ { 0x08, 0x00, 0x0B, 0xAE, 0x0E, 0x00, 0x10, 0x30, 0x11, 0xCB, 0x13, 0x49, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x16, 0x80, 0x28, 0xC0, 0x46, 0x80, 0x71, 0x00, 0xA7, 0x80, 0xEB, 0x00 }, /* GM_0_9 */ { 0x0B, 0xB1, 0x0E, 0x14, 0x0F, 0x2D, 0x10, 0x18, 0x10, 0xE5, 0x11, 0x80, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x19, 0x80, 0x2F, 0x80, 0x4F, 0xC0, 0x7A, 0x00, 0xAD, 0xC0, 0xEB, 0x00 }, /* GM_1_0 */ { 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xEB, 0x10, 0x00, 0x20, 0x00, 0x40, 0x00, 0x60, 0x00, 0x80, 0x00, 0xA0, 0x00, 0xEB, 0x00 }, /* GM_1_1 */ { 0x14, 0xEC, 0x11, 0xC2, 0x10, 0x78, 0x0F, 0xB6, 0x0F, 0x2F, 0x0E, 0xB6, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x21, 0x00, 0x3C, 0xC0, 0x5F, 0xC0, 0x89, 0x00, 0xB7, 0x80, 0xEB, 0x00 }, /* GM_1_2 */ { 0x19, 0xD8, 0x13, 0x33, 0x10, 0xD2, 0x0F, 0x6D, 0x0E, 0x5E, 0x0D, 0xA4, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x25, 0x00, 0x43, 0x00, 0x66, 0xC0, 0x8F, 0x40, 0xBB, 0x40, 0xEB, 0x00 }, /* GM_1_3 */ { 0x1E, 0xC4, 0x14, 0x7A, 0x11, 0x0F, 0xF, 0x0C, 0x0D, 0xA1, 0x0C, 0xB6, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x29, 0x00, 0x49, 0x00, 0x6D, 0x40, 0x94, 0xC0, 0xBE, 0x80, 0xEB, 0x00 }, /* GM_1_4 */ { 0x24, 0x00, 0x15, 0x70, 0x11, 0x0F, 0x0E, 0xAA, 0x0D, 0x0F, 0x0B, 0xDB, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x2D, 0x40, 0x4E, 0xC0, 0x73, 0x00, 0x99, 0x80, 0xC1, 0x80, 0xEB, 0x00 }, /* GM_1_5 */ { 0x29, 0x3B, 0x16, 0x3D, 0x11, 0x0F, 0x0E, 0x30, 0x0C, 0x7D, 0x0B, 0x24, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x31, 0x80, 0x54, 0x40, 0x78, 0x80, 0x9D, 0xC0, 0xC4, 0x00, 0xEB, 0x00 }, /* GM_1_6 */ { 0x2E, 0x27, 0x17, 0x0A, 0x10, 0xD2, 0x0D, 0xE7, 0x0B, 0xEB, 0x0A, 0x80, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x35, 0x80, 0x59, 0x80, 0x7D, 0x40, 0xA1, 0xC0, 0xC6, 0x40, 0xEB, 0x00 }, /* GM_1_7 */ { 0x33, 0x62, 0x17, 0x5C, 0x10, 0xD2, 0x0D, 0x6D, 0x0B, 0x6D, 0x09, 0xED, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x39, 0xC0, 0x5E, 0x40, 0x82, 0x00, 0xA5, 0x40, 0xC8, 0x40, 0xEB, 0x00 }, /* GM_1_8 */ { 0x38, 0x4E, 0x17, 0xAE, 0x10, 0xB4, 0x0D, 0x0C, 0x0A, 0xF0, 0x09, 0x6D, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x3D, 0xC0, 0x62, 0xC0, 0x86, 0x40, 0xA8, 0x80, 0xCA, 0x00, 0xEB, 0x00 }, /* GM_1_9 */ { 0x3D, 0x3B, 0x18, 0x00, 0x10, 0x5A, 0x0C, 0xC3, 0x0A, 0x72, 0x09, 0x00, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x41, 0xC0, 0x67, 0x40, 0x8A, 0x00, 0xAB, 0x80, 0xCB, 0x80, 0xEB, 0x00 }, /* GM_2_0 */ { 0x41, 0xD8, 0x18, 0x28, 0x10, 0x3C, 0x0C, 0x49, 0x0A, 0x1F, 0x08, 0x92, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x45, 0x80, 0x6B, 0x40, 0x8D, 0xC0, 0xAE, 0x00, 0xCD, 0x00, 0xEB, 0x00 }, /* GM_2_1 */ { 0x46, 0x76, 0x18, 0x51, 0x0F, 0xE1, 0x0C, 0x00, 0x09, 0xB6, 0x08, 0x36, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x49, 0x40, 0x6F, 0x40, 0x91, 0x00, 0xB0, 0x80, 0xCE, 0x40, 0xEB, 0x00 }, /* GM_2_2 */ { 0x4A, 0xC4, 0x18, 0x7A, 0x0F, 0xA5, 0x0B, 0x9E, 0x09, 0x63, 0x07, 0xDB, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x4C, 0xC0, 0x73, 0x00, 0x94, 0x40, 0xB2, 0xC0, 0xCF, 0x80, 0xEB, 0x00 }, /* GM_2_3 */ { 0x4F, 0x13, 0x18, 0x51, 0x0F, 0x69, 0x0B, 0x6D, 0x09, 0x0F, 0x07, 0x80, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x50, 0x40, 0x76, 0x40, 0x97, 0x00, 0xB5, 0x00, 0xD0, 0xC0, 0xEB, 0x00 }, /* GM_2_4 */ { 0x53, 0x13, 0x18, 0x7A, 0x0F, 0x0F, 0x0B, 0x24, 0x08, 0xBC, 0x07, 0x36, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x53, 0x80, 0x79, 0xC0, 0x99, 0xC0, 0xB7, 0x00, 0xD1, 0xC0, 0xEB, 0x00 }, /* GM_2_5 */ { 0x57, 0x13, 0x18, 0x51, 0x0E, 0xF0, 0x0A, 0xC3, 0x08, 0x7D, 0x06, 0xED, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x56, 0xC0, 0x7C, 0xC0, 0x9C, 0x80, 0xB8, 0xC0, 0xD2, 0xC0, 0xEB, 0x00 }, /* GM_2_6 */ { 0x5B, 0x13, 0x18, 0x28, 0x0E, 0x96, 0x0A, 0x92, 0x08, 0x29, 0x06, 0xB6, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x5A, 0x00, 0x7F, 0xC0, 0x9E, 0xC0, 0xBA, 0x80, 0xD3, 0x80, 0xEB, 0x00 }, /* GM_2_7 */ { 0x5E, 0xC4, 0x18, 0x00, 0x0E, 0x78, 0x0A, 0x30, 0x08, 0x00, 0x06, 0x6D, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x5D, 0x00, 0x82, 0x80, 0xA1, 0x40, 0xBC, 0x00, 0xD4, 0x80, 0xEB, 0x00 }, /* GM_2_8 */ { 0x62, 0x76, 0x17, 0xD7, 0x0E, 0x1E, 0x0A, 0x00, 0x07, 0xC1, 0x06, 0x36, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x60, 0x00, 0x85, 0x40, 0xA3, 0x40, 0xBD, 0x80, 0xD5, 0x40, 0xEB, 0x00 }, /* GM_2_9 */ { 0x65, 0xD8, 0x17, 0xAE, 0x0D, 0xE1, 0x09, 0xCF, 0x07, 0x82, 0x06, 0x00, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x62, 0xC0, 0x87, 0xC0, 0xA5, 0x40, 0xBF, 0x00, 0xD6, 0x00, 0xEB, 0x00 }, /* GM_3_0 */ { 0x69, 0x3B, 0x17, 0x85, 0x0D, 0xA5, 0x09, 0x86, 0x07, 0x43, 0x05, 0xDB, 0x10, 0x1D, 0x36, 0x58, 0x82, 0xB3, 0xEB, 0x10, 0x00, 0x65, 0x80, 0x8A, 0x40, 0xA7, 0x40, 0xC0, 0x40, 0xD6, 0x80, 0xEB, 0x00 } }; void __VISetTiming(u8 timing) { __VIWriteI2CRegister8(0x00,timing); } void __VISetYUVSEL(u8 dtvstatus) { u8 vdacFlagRegion = 0; u32 currTvMode = _SHIFTR(_viReg[1],8,2); if(currTvMode==VI_PAL || currTvMode==VI_EURGB60) vdacFlagRegion = 2; else if(currTvMode==VI_MPAL) vdacFlagRegion = 1; __VIWriteI2CRegister8(0x01, _SHIFTL(dtvstatus,5,3)|(vdacFlagRegion&0x1f)); } void __VISetVBICtrl(u16 data) { __VIWriteI2CRegister16(0x02, data); } void __VISetTrapFilter(u8 disable) { if (disable) __VIWriteI2CRegister8(0x03, 0); else __VIWriteI2CRegister8(0x03, 1); } void __VISet3in1Output(u8 enable) { __VIWriteI2CRegister8(0x04,enable); } void __VISetCGMS(u16 value) { __VIWriteI2CRegister16(0x05, value); } void __VISetWSS(u16 value) { __VIWriteI2CRegister16(0x08, value); } void __VISetRGBOverDrive(u8 value) { u32 currTvMode = _SHIFTR(_viReg[1],8,2); if (currTvMode == VI_DEBUG) __VIWriteI2CRegister8(0x0A,(value<<1)|1); else __VIWriteI2CRegister8(0x0A,0); } void __VISetOverSampling(void) { __VIWriteI2CRegister8(0x65,1); } void __VISetCCSEL(void) { __VIWriteI2CRegister8(0x6a,1); } void __VISetFilterEURGB60(u8 enable) { __VIWriteI2CRegister8(0x6e, enable); } void __VISetVolume(u16 value) { __VIWriteI2CRegister16(0x71,value); } void __VISetClosedCaption(u32 value) { __VIWriteI2CRegister32(0x7a, value); } void __VISetGamma(VIGamma gamma) { u8 *data = (u8 *)&gamma_coeffs[gamma][0]; __VIWriteI2CRegisterBuf(0x10, 0x21, data); } /* User Configurable */ void VIDEO_SetGamma(VIGamma gamma) { __VISetGamma(gamma); } void VIDEO_SetTrapFilter(bool enable) { if (enable) __VISetTrapFilter(0); else __VISetTrapFilter(1); } #endif
zyking1987-genplus-droid
genplusgx/gx/utils/vi_encoder.c
C
gpl2
14,087
/**************************************************************************** * vi_encoder.c * * Wii Audio/Video Encoder support * * Copyright (C) 2009 Hector Martin (marcan) * Additional code by Eke-Eke * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #ifdef HW_RVL typedef enum { VI_GM_0_1=1, VI_GM_0_2, VI_GM_0_3, VI_GM_0_4, VI_GM_0_5, VI_GM_0_6, VI_GM_0_7, VI_GM_0_8, VI_GM_0_9, VI_GM_1_0, VI_GM_1_1, VI_GM_1_2, VI_GM_1_3, VI_GM_1_4, VI_GM_1_5, VI_GM_1_6, VI_GM_1_7, VI_GM_1_8, VI_GM_1_9, VI_GM_2_0, VI_GM_2_1, VI_GM_2_2, VI_GM_2_3, VI_GM_2_4, VI_GM_2_5, VI_GM_2_6, VI_GM_2_7, VI_GM_2_8, VI_GM_2_9, VI_GM_3_0 } VIGamma; extern void VIDEO_SetGamma(VIGamma gamma); extern void VIDEO_SetTrapFilter(bool enable); #endif
zyking1987-genplus-droid
genplusgx/gx/utils/vi_encoder.h
C
gpl2
1,677
/**************************************************************************** * gx_audio.c * * Genesis Plus GX audio support * * Softdev (2006) * Eke-Eke (2007,2008,2009) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #ifndef _GC_AUDIO_H_ #define _GC_AUDIO_H_ extern u8 soundbuffer[2][3840]; extern u32 mixbuffer; extern u32 audioStarted; extern void gx_audio_Init(void); extern void gx_audio_Shutdown(void); extern void gx_audio_Start(void); extern void gx_audio_Stop(void); extern void gx_audio_Update(void); #endif
zyking1987-genplus-droid
genplusgx/gx/gx_audio.h
C
gpl2
1,331
<html> <!-- Mirrored from genplus-gx.googlecode.com/svn/!svn/bc/427/trunk/source/gx/ by HTTrack Website Copier/3.x [XR&CO'2010], Mon, 13 Dec 2010 08:07:20 GMT --> <!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack --> <head><title>genplus-gx - Revision 427: /trunk/source/gx</title></head> <body> <h2>genplus-gx - Revision 427: /trunk/source/gx</h2> <ul> <li><a href="../index.html">..</a></li> <li><a href="aram.c">aram.c</a></li> <li><a href="aram.h">aram.h</a></li> <li><a href="config.c">config.c</a></li> <li><a href="config.h">config.h</a></li> <li><a href="fileio/index.html">fileio/</a></li> <li><a href="gui/index.html">gui/</a></li> <li><a href="gx_audio.c">gx_audio.c</a></li> <li><a href="gx_audio.h">gx_audio.h</a></li> <li><a href="gx_input.c">gx_input.c</a></li> <li><a href="gx_input.h">gx_input.h</a></li> <li><a href="gx_video.c">gx_video.c</a></li> <li><a href="gx_video.h">gx_video.h</a></li> <li><a href="images/index.html">images/</a></li> <li><a href="main.c">main.c</a></li> <li><a href="osd.h">osd.h</a></li> <li><a href="sounds/index.html">sounds/</a></li> <li><a href="vi_encoder.c">vi_encoder.c</a></li> <li><a href="vi_encoder.h">vi_encoder.h</a></li> </ul> <hr noshade><em><a href="http://code.google.com/">Google Code</a> powered by <a href="http://subversion.apache.org/">Subversion</a></em> </body> <!-- Mirrored from genplus-gx.googlecode.com/svn/!svn/bc/427/trunk/source/gx/ by HTTrack Website Copier/3.x [XR&CO'2010], Mon, 13 Dec 2010 08:07:25 GMT --> <!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack --> </html>
zyking1987-genplus-droid
genplusgx/gx/index.html
HTML
gpl2
1,718
/**************************************************************************** * config.c * * Genesis Plus GX configuration file support * * Eke-Eke (2008) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #include "shared.h" #include "gui.h" #include "menu.h" #include "file_load.h" static int config_load(void) { /* open configuration file */ char fname[MAXPATHLEN]; sprintf (fname, "%s/config.ini", DEFAULT_PATH); FILE *fp = fopen(fname, "rb"); if (fp) { /* read version */ char version[16]; fread(version, 16, 1, fp); fclose(fp); if (strncmp(version,CONFIG_VERSION,16)) return 0; /* read file */ fp = fopen(fname, "rb"); if (fp) { fread(&config, sizeof(config), 1, fp); fclose(fp); return 1; } } return 0; } void config_save(void) { /* open configuration file */ char fname[MAXPATHLEN]; sprintf (fname, "%s/config.ini", DEFAULT_PATH); FILE *fp = fopen(fname, "wb"); if (fp) { /* write file */ fwrite(&config, sizeof(config), 1, fp); fclose(fp); } } void config_default(void) { /* version TAG */ strncpy(config.version,CONFIG_VERSION,16); /* sound options */ config.psg_preamp = 150; config.fm_preamp = 100; config.hq_fm = 1; config.psgBoostNoise = 0; config.filter = 1; config.lp_range = 50; config.low_freq = 880; config.high_freq = 5000; config.lg = 1.0; config.mg = 1.0; config.hg = 1.0; config.rolloff = 0.995; config.dac_bits = 14; /* system options */ config.region_detect = 0; config.force_dtack = 0; config.addr_error = 1; config.tmss = 0; config.lock_on = 0; config.romtype = 0; config.hot_swap = 0; /* video options */ config.xshift = 0; config.yshift = 0; config.xscale = 0; config.yscale = 0; config.aspect = 1; config.overscan = 3; config.ntsc = 0; if (VIDEO_HaveComponentCable()) { config.render = 2; config.bilinear = 1; #ifdef HW_RVL config.trap = 1; #endif } else { config.render = 0; config.bilinear = 0; #ifdef HW_RVL config.trap = 0; #endif } #ifdef HW_RVL config.gamma = VI_GM_1_0 / 10.0; #endif /* controllers options */ config.gun_cursor[0] = 1; config.gun_cursor[1] = 1; config.invert_mouse = 0; gx_input_SetDefault(); /* menu options */ config.autoload = 0; config.autocheat = 0; #ifdef HW_RVL config.s_auto = 1; #else config.s_auto = 0; #endif config.s_default = 1; config.s_device = 0; config.bg_type = 0; config.bg_overlay = 1; config.screen_w = 658; config.bgm_volume = 100.0; config.sfx_volume = 100.0; /* default ROM directories */ #ifdef HW_RVL sprintf (config.lastdir[TYPE_SD], "sd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[TYPE_USB], "usb:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); #else sprintf (config.lastdir[TYPE_SD], "%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); #endif /* try to restore settings from config file */ if (!config_load()) GUI_WaitPrompt("Info","Default Settings restored"); /* restore inputs */ input_init(); /* restore menu settings */ menu_configure(); }
zyking1987-genplus-droid
genplusgx/gx/config.c
C
gpl2
4,341
/**************************************************************************** * config.c * * Genesis Plus GX configuration file support * * Eke-Eke (2008) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ #ifndef _CONFIG_H_ #define _CONFIG_H_ #define CONFIG_VERSION "GENPLUS-GX 1.4.1" /**************************************************************************** * Config Option * ****************************************************************************/ typedef struct { char version[16]; uint8 hq_fm; uint8 filter; uint8 psgBoostNoise; uint8 dac_bits; int16 psg_preamp; int16 fm_preamp; int16 lp_range; int16 low_freq; int16 high_freq; int16 lg; int16 mg; int16 hg; float rolloff; uint8 region_detect; uint8 force_dtack; uint8 addr_error; uint8 tmss; uint8 lock_on; uint8 hot_swap; uint8 romtype; uint8 invert_mouse; uint8 gun_cursor[2]; uint8 overscan; uint8 ntsc; uint8 render; uint8 tv_mode; uint8 bilinear; uint8 aspect; int16 xshift; int16 yshift; int16 xscale; int16 yscale; #ifdef HW_RVL uint32 trap; float gamma; #endif t_input_config input[MAX_INPUTS]; uint16 pad_keymap[4][MAX_KEYS]; #ifdef HW_RVL uint32 wpad_keymap[4*3][MAX_KEYS]; #endif uint8 autoload; uint8 autocheat; uint8 s_auto; uint8 s_default; uint8 s_device; uint8 autocheats; int8 bg_type; int8 bg_overlay; int16 screen_w; float bgm_volume; float sfx_volume; #ifdef HW_RVL char lastdir[3][MAXPATHLEN]; #else char lastdir[2][MAXPATHLEN]; #endif } t_config; /* Global data */ t_config config; extern void config_save(void); extern void config_default(void); #endif /* _CONFIG_H_ */
zyking1987-genplus-droid
genplusgx/gx/config.h
C
gpl2
2,544
<html> <!-- Mirrored from genplus-gx.googlecode.com/svn/!svn/bc/427/trunk/source/gx/images/ by HTTrack Website Copier/3.x [XR&CO'2010], Mon, 13 Dec 2010 08:08:23 GMT --> <!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack --> <head><title>genplus-gx - Revision 427: /trunk/source/gx/images</title></head> <body> <h2>genplus-gx - Revision 427: /trunk/source/gx/images</h2> <ul> <li><a href="../index.html">..</a></li> <li><a href="Banner_bottom.png">Banner_bottom.png</a></li> <li><a href="Banner_main.png">Banner_main.png</a></li> <li><a href="Banner_top.png">Banner_top.png</a></li> <li><a href="Bg_credits.png">Bg_credits.png</a></li> <li><a href="Bg_intro_c1.png">Bg_intro_c1.png</a></li> <li><a href="Bg_intro_c2.png">Bg_intro_c2.png</a></li> <li><a href="Bg_intro_c3.png">Bg_intro_c3.png</a></li> <li><a href="Bg_intro_c4.png">Bg_intro_c4.png</a></li> <li><a href="Bg_intro_c5.png">Bg_intro_c5.png</a></li> <li><a href="Bg_main.png">Bg_main.png</a></li> <li><a href="Bg_overlay.png">Bg_overlay.png</a></li> <li><a href="Browser_dir.png">Browser_dir.png</a></li> <li><a href="Button_arrow.png">Button_arrow.png</a></li> <li><a href="Button_arrow_over.png">Button_arrow_over.png</a></li> <li><a href="Button_delete.png">Button_delete.png</a></li> <li><a href="Button_delete_over.png">Button_delete_over.png</a></li> <li><a href="Button_down.png">Button_down.png</a></li> <li><a href="Button_down_over.png">Button_down_over.png</a></li> <li><a href="Button_icon.png">Button_icon.png</a></li> <li><a href="Button_icon_over.png">Button_icon_over.png</a></li> <li><a href="Button_icon_sm.png">Button_icon_sm.png</a></li> <li><a href="Button_icon_sm_over.png">Button_icon_sm_over.png</a></li> <li><a href="Button_load.png">Button_load.png</a></li> <li><a href="Button_load_over.png">Button_load_over.png</a></li> <li><a href="Button_special.png">Button_special.png</a></li> <li><a href="Button_special_over.png">Button_special_over.png</a></li> <li><a href="Button_text.png">Button_text.png</a></li> <li><a href="Button_text_over.png">Button_text_over.png</a></li> <li><a href="Button_up.png">Button_up.png</a></li> <li><a href="Button_up_over.png">Button_up_over.png</a></li> <li><a href="Crosshair_p1.png">Crosshair_p1.png</a></li> <li><a href="Crosshair_p2.png">Crosshair_p2.png</a></li> <li><a href="Ctrl_4wayplay.png">Ctrl_4wayplay.png</a></li> <li><a href="Ctrl_config.png">Ctrl_config.png</a></li> <li><a href="Ctrl_gamepad.png">Ctrl_gamepad.png</a></li> <li><a href="Ctrl_justifiers.png">Ctrl_justifiers.png</a></li> <li><a href="Ctrl_menacer.png">Ctrl_menacer.png</a></li> <li><a href="Ctrl_mouse.png">Ctrl_mouse.png</a></li> <li><a href="Ctrl_none.png">Ctrl_none.png</a></li> <li><a href="Ctrl_pad3b.png">Ctrl_pad3b.png</a></li> <li><a href="Ctrl_pad6b.png">Ctrl_pad6b.png</a></li> <li><a href="Ctrl_player.png">Ctrl_player.png</a></li> <li><a href="Ctrl_player_none.png">Ctrl_player_none.png</a></li> <li><a href="Ctrl_player_over.png">Ctrl_player_over.png</a></li> <li><a href="Ctrl_teamplayer.png">Ctrl_teamplayer.png</a></li> <li><a href="Frame_s1.png">Frame_s1.png</a></li> <li><a href="Frame_s1_title.png">Frame_s1_title.png</a></li> <li><a href="Frame_s2.png">Frame_s2.png</a></li> <li><a href="Frame_s3.png">Frame_s3.png</a></li> <li><a href="Frame_s4.png">Frame_s4.png</a></li> <li><a href="Frame_s4_title.png">Frame_s4_title.png</a></li> <li><a href="Frame_throbber.png">Frame_throbber.png</a></li> <li><a href="Key_A_gcn.png">Key_A_gcn.png</a></li> <li><a href="Key_A_wii.png">Key_A_wii.png</a></li> <li><a href="Key_B_gcn.png">Key_B_gcn.png</a></li> <li><a href="Key_B_wii.png">Key_B_wii.png</a></li> <li><a href="Key_home.png">Key_home.png</a></li> <li><a href="Load_dvd.png">Load_dvd.png</a></li> <li><a href="Load_recent.png">Load_recent.png</a></li> <li><a href="Load_sd.png">Load_sd.png</a></li> <li><a href="Load_usb.png">Load_usb.png</a></li> <li><a href="Main_file.png">Main_file.png</a></li> <li><a href="Main_ggenie.png">Main_ggenie.png</a></li> <li><a href="Main_load.png">Main_load.png</a></li> <li><a href="Main_logo.png">Main_logo.png</a></li> <li><a href="Main_options.png">Main_options.png</a></li> <li><a href="Main_play_gcn.png">Main_play_gcn.png</a></li> <li><a href="Main_play_wii.png">Main_play_wii.png</a></li> <li><a href="Main_quit.png">Main_quit.png</a></li> <li><a href="Main_reset.png">Main_reset.png</a></li> <li><a href="Main_showinfo.png">Main_showinfo.png</a></li> <li><a href="Main_takeshot.png">Main_takeshot.png</a></li> <li><a href="Option_ctrl.png">Option_ctrl.png</a></li> <li><a href="Option_menu.png">Option_menu.png</a></li> <li><a href="Option_sound.png">Option_sound.png</a></li> <li><a href="Option_system.png">Option_system.png</a></li> <li><a href="Option_video.png">Option_video.png</a></li> <li><a href="Overlay_bar.png">Overlay_bar.png</a></li> <li><a href="Overlay_item.png">Overlay_item.png</a></li> <li><a href="Overlay_item_over.png">Overlay_item_over.png</a></li> <li><a href="Progress_bar.png">Progress_bar.png</a></li> <li><a href="Snap_empty.png">Snap_empty.png</a></li> <li><a href="Snap_frame.png">Snap_frame.png</a></li> <li><a href="Star_empty.png">Star_empty.png</a></li> <li><a href="Star_full.png">Star_full.png</a></li> <li><a href="ctrl_classic.png">ctrl_classic.png</a></li> <li><a href="ctrl_gamecube.png">ctrl_gamecube.png</a></li> <li><a href="ctrl_nunchuk.png">ctrl_nunchuk.png</a></li> <li><a href="ctrl_option_off.png">ctrl_option_off.png</a></li> <li><a href="ctrl_option_on.png">ctrl_option_on.png</a></li> <li><a href="ctrl_wiimote.png">ctrl_wiimote.png</a></li> <li><a href="generic_point.png">generic_point.png</a></li> </ul> <hr noshade><em><a href="http://code.google.com/">Google Code</a> powered by <a href="http://subversion.apache.org/">Subversion</a></em> </body> <!-- Mirrored from genplus-gx.googlecode.com/svn/!svn/bc/427/trunk/source/gx/images/ by HTTrack Website Copier/3.x [XR&CO'2010], Mon, 13 Dec 2010 08:09:21 GMT --> <!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack --> </html>
zyking1987-genplus-droid
genplusgx/gx/images/index.html
HTML
gpl2
6,308
/*************************************************************************************** * Genesis Plus * I/O controller (MD & MS compatibility modes) * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007-2011), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #include "shared.h" #include "input_hw/gamepad.h" #include "input_hw/lightgun.h" #include "input_hw/mouse.h" #include "input_hw/activator.h" #include "input_hw/xe_a1p.h" #include "input_hw/teamplayer.h" #include "input_hw/paddle.h" #include "input_hw/sportspad.h" uint8 io_reg[0x10]; uint8 region_code = REGION_USA; static struct port_t { void (*data_w)(unsigned char data, unsigned char mask); unsigned char (*data_r)(void); } port[3]; static void dummy_write(unsigned char data, unsigned char mask) { } static unsigned char dummy_read(void) { return 0x7F; } /***************************************************************************** * I/O chip functions * * * *****************************************************************************/ void io_init(void) { /* Initialize connected peripherals */ input_init(); /* Initialize IO Ports handlers & connected peripherals */ switch (input.system[0]) { case SYSTEM_MS_GAMEPAD: { port[0].data_w = dummy_write; port[0].data_r = gamepad_1_read; break; } case SYSTEM_MD_GAMEPAD: { port[0].data_w = gamepad_1_write; port[0].data_r = gamepad_1_read; break; } case SYSTEM_MOUSE: { port[0].data_w = mouse_write; port[0].data_r = mouse_read; break; } case SYSTEM_ACTIVATOR: { port[0].data_w = activator_1_write; port[0].data_r = activator_1_read; break; } case SYSTEM_XE_A1P: { port[0].data_w = xe_a1p_write; port[0].data_r = xe_a1p_read; break; } case SYSTEM_WAYPLAY: { port[0].data_w = wayplay_1_write; port[0].data_r = wayplay_1_read; break; } case SYSTEM_TEAMPLAYER: { port[0].data_w = teamplayer_1_write; port[0].data_r = teamplayer_1_read; break; } case SYSTEM_LIGHTPHASER: { port[0].data_w = dummy_write; port[0].data_r = phaser_1_read; break; } case SYSTEM_PADDLE: { port[0].data_w = paddle_1_write; port[0].data_r = paddle_1_read; break; } case SYSTEM_SPORTSPAD: { port[0].data_w = sportspad_1_write; port[0].data_r = sportspad_1_read; break; } default: { port[0].data_w = dummy_write; port[0].data_r = dummy_read; break; } } switch (input.system[1]) { case SYSTEM_MS_GAMEPAD: { port[1].data_w = dummy_write; port[1].data_r = gamepad_2_read_2p; break; } case SYSTEM_MD_GAMEPAD: { port[1].data_w = gamepad_2_write_2p; port[1].data_r = gamepad_2_read_2p; break; } case SYSTEM_MOUSE: { port[1].data_w = mouse_write; port[1].data_r = mouse_read; break; } case SYSTEM_ACTIVATOR: { port[1].data_w = activator_2_write; port[1].data_r = activator_2_read; break; } case SYSTEM_MENACER: { port[1].data_w = dummy_write; port[1].data_r = menacer_read; break; } case SYSTEM_JUSTIFIER: { port[1].data_w = justifier_write; port[1].data_r = justifier_read; break; } case SYSTEM_WAYPLAY: { port[1].data_w = wayplay_2_write; port[1].data_r = wayplay_2_read; break; } case SYSTEM_TEAMPLAYER: { port[1].data_w = teamplayer_2_write; port[1].data_r = teamplayer_2_read; break; } case SYSTEM_LIGHTPHASER: { port[1].data_w = dummy_write; port[1].data_r = phaser_2_read; break; } case SYSTEM_PADDLE: { port[1].data_w = paddle_2_write; port[1].data_r = paddle_2_read; break; } case SYSTEM_SPORTSPAD: { port[1].data_w = sportspad_2_write; port[1].data_r = sportspad_2_read; break; } default: { port[1].data_w = dummy_write; port[1].data_r = dummy_read; break; } } /* External Port (unconnected) */ port[2].data_w = dummy_write; port[2].data_r = dummy_read; } void io_reset(void) { /* Reset I/O registers */ if (system_hw == SYSTEM_PBC) { /* SMS compatibility mode control register */ io_reg[0x00] = 0xFF; } else { /* Genesis mode registers */ io_reg[0x00] = region_code | 0x20 | (config.tmss & 1); io_reg[0x01] = 0x00; io_reg[0x02] = 0x00; io_reg[0x03] = 0x00; io_reg[0x04] = 0x00; io_reg[0x05] = 0x00; io_reg[0x06] = 0x00; io_reg[0x07] = 0xFF; io_reg[0x08] = 0x00; io_reg[0x09] = 0x00; io_reg[0x0A] = 0xFF; io_reg[0x0B] = 0x00; io_reg[0x0C] = 0x00; io_reg[0x0D] = 0xFB; io_reg[0x0E] = 0x00; io_reg[0x0F] = 0x00; } /* Reset connected peripherals */ input_reset(); } void io_68k_write(unsigned int offset, unsigned int data) { switch (offset) { case 0x01: /* Port A Data */ case 0x02: /* Port B Data */ case 0x03: /* Port C Data */ { io_reg[offset] = data; port[offset-1].data_w(data, io_reg[offset + 3]); return; } case 0x04: /* Port A Ctrl */ case 0x05: /* Port B Ctrl */ case 0x06: /* Port C Ctrl */ { if (data != io_reg[offset]) { io_reg[offset] = data; port[offset-4].data_w(io_reg[offset-3], data); } return; } case 0x07: /* Port A TxData */ case 0x0A: /* Port B TxData */ case 0x0D: /* Port C TxData */ { io_reg[offset] = data; return; } case 0x09: /* Port A S-Ctrl */ case 0x0C: /* Port B S-Ctrl */ case 0x0F: /* Port C S-Ctrl */ { io_reg[offset] = data & 0xF8; return; } default: /* Read-only ports */ { return; } } } unsigned int io_68k_read(unsigned int offset) { switch(offset) { case 0x01: /* Port A Data */ case 0x02: /* Port B Data */ case 0x03: /* Port C Data */ { unsigned int mask = 0x80 | io_reg[offset + 3]; unsigned int data = port[offset-1].data_r(); return (io_reg[offset] & mask) | (data & ~mask); } default: /* return register value */ { return io_reg[offset]; } } } void io_z80_write(unsigned int data) { /* pins can't be configured as output on japanese models */ if (region_code & REGION_USA) { /* Bit Function -------------- D7 : Port B TH pin output level (1=high, 0=low) D6 : Port B TR pin output level (1=high, 0=low) D5 : Port A TH pin output level (1=high, 0=low) D4 : Port A TR pin output level (1=high, 0=low) D3 : Port B TH pin direction (1=input, 0=output) D2 : Port B TR pin direction (1=input, 0=output) D1 : Port A TH pin direction (1=input, 0=output) D0 : Port A TR pin direction (1=input, 0=output) */ /* Send TR/TH state to connected peripherals */ port[0].data_w((data << 1) & 0x60, (~io_reg[0] << 5) & 0x60); port[1].data_w((data >> 1) & 0x60, (~io_reg[0] << 3) & 0x60); /* Check for TH low-to-high transitions on both ports */ if ((!(io_reg[0] & 0x80) && (data & 0x80)) || (!(io_reg[0] & 0x20) && (data & 0x20))) { /* Latch new HVC */ hvc_latch = hctab[(mcycles_z80 + Z80_CYCLE_OFFSET) % MCYCLES_PER_LINE] | 0x10000; } } else { /* outputs return fixed value */ data &= 0x0F; } /* Update control register */ io_reg[0] = data; } unsigned int io_z80_read(unsigned int offset) { /* Read port A & port B input data */ unsigned int data = (port[0].data_r()) | (port[1].data_r() << 8); /* Read control register value */ unsigned int ctrl = io_reg[0]; /* I/O ports */ if (offset) { /* Bit Function -------------- D7 : Port B TH pin input D6 : Port A TH pin input D5 : Unused (0 on Mega Drive, 1 otherwise) D4 : RESET button (always 1 on Mega Drive) D3 : Port B TR pin input D2 : Port B TL pin input D1 : Port B Right pin input D0 : Port B Left pin input */ data = ((data >> 10) & 0x0F) | (data & 0x40) | ((data >> 7) & 0x80) | 0x10; /* Adjust port B TH state if configured as output */ if (!(ctrl & 0x08)) { data &= ~0x80; data |= (ctrl & 0x80); } /* Adjust port A TH state if configured as output */ if (!(ctrl & 0x02)) { data &= ~0x40; data |= ((ctrl & 0x20) << 1); } /* Adjust port B TR state if configured as output */ if (!(ctrl & 0x04)) { data &= ~0x08; data |= ((ctrl & 0x40) >> 3); } } else { /* Bit Function -------------- D7 : Port B Down pin input D6 : Port B Up pin input D5 : Port A TR pin input D4 : Port A TL pin input D3 : Port A Right pin input D2 : Port A Left pin input D1 : Port A Down pin input D0 : Port A Up pin input */ data = (data & 0x3F) | ((data >> 2) & 0xC0); /* Adjust port A TR state if configured as output */ if (!(ctrl & 0x01)) { data &= ~0x20; data |= ((ctrl & 0x10) << 1); } } return data; }
zyking1987-genplus-droid
genplusgx/io_ctrl.c
C
gpl2
10,749
/*************************************************************************************** * Genesis Plus * Virtual System Emulation * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * Eke-Eke (2007-2011), additional code & fixes for the GCN/Wii port * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************************/ #ifndef _SYSTEM_H_ #define _SYSTEM_H_ #define SYSTEM_PBC 0x00 #define SYSTEM_GENESIS 0x01 #define SYSTEM_MEGADRIVE 0x02 #define SYSTEM_PICO 0x03 #define MCYCLES_PER_LINE 3420 #define Z80_CYCLE_OFFSET 550 /* horizontal timings offset when running in SMS mode */ typedef struct { uint8 *data; /* Bitmap data */ int width; /* Bitmap width */ int height; /* Bitmap height */ int depth; /* Color depth (8-32 bits) */ int pitch; /* Width of bitmap in bytes */ int granularity; /* Size of each pixel in bytes */ int remap; /* 1= Translate pixel data */ struct { int x; /* X offset of viewport within bitmap */ int y; /* Y offset of viewport within bitmap */ int w; /* Width of viewport */ int h; /* Height of viewport */ int ow; /* Previous width of viewport */ int oh; /* Previous height of viewport */ int changed; /* 1= Viewport width or height have changed */ } viewport; } t_bitmap; typedef struct { int sample_rate; /* Output Sample rate (8000-48000) */ float frame_rate; /* Output Frame rate (usually 50 or 60 frames per second) */ int enabled; /* 1= sound emulation is enabled */ int buffer_size; /* Size of sound buffer (in bytes) */ int16 *buffer[2]; /* Signed 16-bit stereo sound data */ struct { int32 *pos; int32 *buffer; } fm; struct { int16 *pos; int16 *buffer; } psg; } t_snd; /* Global variables */ extern t_bitmap bitmap; extern t_snd snd; extern uint32 mcycles_z80; extern uint32 mcycles_68k; extern uint32 mcycles_vdp; extern uint8 system_hw; /* Function prototypes */ extern int audio_init(int samplerate,float framerate); extern void audio_reset(void); extern void audio_shutdown(void); extern int audio_update(void); extern void audio_set_equalizer(void); extern void system_init(void); extern void system_reset(void); extern void system_shutdown(void); extern void (*system_frame)(int do_skip); #endif /* _SYSTEM_H_ */
zyking1987-genplus-droid
genplusgx/system.h
C
gpl2
3,269
#include "shared.h" /* Load a normal file, or ZIP/GZ archive. Returns NULL if an error occured. */ int filesize(FILE *fp) { int pos,end; pos=ftell (fp); fseek (fp, 0, SEEK_END); end = ftell (fp); fseek (fp, pos, SEEK_SET); return end; } int check_zip(char *filename) { uint8 buf[2]; FILE *fd = NULL; fd = fopen(filename, "rb"); if(!fd) return (0); fread(buf, 2, 1, fd); fclose(fd); if(memcmp(buf, "PK", 2) == 0) return (1); return (0); } uint8 *load_archive(char *filename, int *file_size) { int size = 0; uint8 *buf = NULL; if(check_zip(filename)) { FILE *gd = NULL; buf = (uint8 *)malloc(4*1024*1024); printf("Zip detected %s\n",filename); /* Open file */ gd = fopen(filename, "rb"); if(!gd) return (0); *file_size = UnZipBuffer(buf,gd); /* Close file */ fclose(gd); }else{ FILE *gd = NULL; printf("Non Zip File %s\n",filename); /* Open file */ gd = fopen(filename, "rb"); if(!gd) return (0); /* Get file size */ size=filesize(gd); /* Allocate file data buffer */ buf = malloc(size); if(!buf) { fclose(gd); return (0); } /* Read file data */ fread(buf,size,1,gd); /* Close file */ fclose(gd); /* Update file size and return pointer to file data */ *file_size = size; } return (buf); }
zyking1987-genplus-droid
genplusgx/fileio.c
C
gpl2
1,553
#ifndef _FILEIO_H_ #define _FILEIO_H_ /* Global variables */ extern int cart_size; extern char cart_name[0x100]; /* Function prototypes */ uint8 *load_archive(char *filename, int *file_size); int load_cart(char *filename); int check_zip(char *filename); int gzsize(gzFile *gd); #endif /* _FILEIO_H_ */
zyking1987-genplus-droid
genplusgx/unused/dos/fileio.h
C
gpl2
319
#include "osd.h" FILE *error_log; struct { int enabled; int verbose; FILE *log; } t_error; void error_init(void) { #ifdef LOG_ERROR error_log = fopen("error.log","w"); #endif } void error_shutdown(void) { if(error_log) fclose(error_log); } void error(char *format, ...) { if (!log_error) return; va_list ap; va_start(ap, format); if(error_log) vfprintf(error_log, format, ap); va_end(ap); }
zyking1987-genplus-droid
genplusgx/unused/dos/error.c
C
gpl2
450
#ifndef _DOS_H_ #define _DOS_H_ #define LOGERROR 1 /* Function prototypes */ int load_file(char *filename, char *buf, int size); int save_file(char *filename, char *buf, int size); void dos_update_input(void); void dos_update_audio(void); void dos_update_palette(void); void dos_update_video(void); void init_machine(void); void trash_machine(void); void make_vdp_palette(void); void dos_change_mode(void); int check_key(int code); #define MAX_INPUTS 8 extern uint8 debug_on; extern uint8 log_error; #endif /* _DOS_H_ */
zyking1987-genplus-droid
genplusgx/unused/dos/dos.h
C
gpl2
554