2003-10-30 23:47:34 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Orginal from Vision-8 Emulator / Copyright (C) 1997-1999 Marcel de Kogel
|
|
|
|
* Modified for Archos by Blueloop (a.wenger@gmx.de)
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2003-10-30 23:47:34 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "plugin.h"
|
|
|
|
|
2010-08-24 14:30:46 +00:00
|
|
|
|
2006-01-15 18:20:18 +00:00
|
|
|
|
2005-07-06 18:38:25 +00:00
|
|
|
#define EXTERN static
|
|
|
|
#define STATIC static
|
|
|
|
#define memset rb->memset
|
|
|
|
#define memcpy rb->memcpy
|
|
|
|
#define printf DEBUGF
|
|
|
|
#define rand rb->rand
|
|
|
|
/* #define CHIP8_DEBUG */
|
2005-02-04 12:41:09 +00:00
|
|
|
|
2005-07-06 18:38:25 +00:00
|
|
|
#if (LCD_WIDTH >= 112) && (LCD_HEIGHT >= 64)
|
|
|
|
#define CHIP8_SUPER /* SCHIP even on the archos recorder (112x64) */
|
2004-10-17 00:54:09 +00:00
|
|
|
#endif
|
|
|
|
|
2005-07-06 18:38:25 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/** (S)CHIP-8 core emulation, from Vision-8 + mods by Fdy **/
|
|
|
|
/** The core is completely generic and can be used outside of Rockbox, **/
|
|
|
|
/** thus the STATIC, EXTERN etc. Please do not modify. **/
|
|
|
|
/****************************************************************************/
|
|
|
|
/** Vision8: CHIP8 emulator *************************************************/
|
|
|
|
/** **/
|
|
|
|
/** CHIP8.h **/
|
|
|
|
/** **/
|
|
|
|
/** This file contains the portable CHIP8 emulation engine definitions **/
|
|
|
|
/** **/
|
|
|
|
/** Copyright (C) Marcel de Kogel 1997 **/
|
|
|
|
/** You are not allowed to distribute this software commercially **/
|
|
|
|
/** Please, notify me, if you make any changes to this file **/
|
|
|
|
/****************************************************************************/
|
2003-10-30 23:47:34 +00:00
|
|
|
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifndef __CHIP8_H
|
|
|
|
#define __CHIP8_H
|
|
|
|
|
|
|
|
#ifndef EXTERN
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
2020-10-08 13:47:40 +00:00
|
|
|
|
2003-10-30 23:47:34 +00:00
|
|
|
typedef unsigned char byte; /* sizeof(byte)==1 */
|
|
|
|
typedef unsigned short word; /* sizeof(word)>=2 */
|
|
|
|
|
|
|
|
struct chip8_regs_struct
|
|
|
|
{
|
|
|
|
byte alg[16]; /* 16 general registers */
|
|
|
|
byte delay,sound; /* delay and sound timer */
|
|
|
|
word i; /* index register */
|
|
|
|
word pc; /* program counter */
|
|
|
|
word sp; /* stack pointer */
|
|
|
|
};
|
|
|
|
|
2005-07-06 18:38:25 +00:00
|
|
|
EXTERN struct chip8_regs_struct chip8_regs;
|
2003-10-30 23:47:34 +00:00
|
|
|
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_SUPER
|
|
|
|
#define CHIP8_WIDTH 128
|
|
|
|
#define CHIP8_HEIGHT 64
|
2010-01-02 22:51:29 +00:00
|
|
|
EXTERN byte chip8_super; /* != 0 if in SCHIP display mode */
|
2005-07-06 18:38:25 +00:00
|
|
|
#else
|
|
|
|
#define CHIP8_WIDTH 64
|
|
|
|
#define CHIP8_HEIGHT 32
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EXTERN byte chip8_iperiod; /* number of opcodes per */
|
2003-10-30 23:47:34 +00:00
|
|
|
/* timeslice (1/50sec.) */
|
2005-07-06 18:38:25 +00:00
|
|
|
EXTERN byte chip8_keys[16]; /* if 1, key is held down */
|
|
|
|
EXTERN byte chip8_display[CHIP8_WIDTH*CHIP8_HEIGHT];/* 0xff if pixel is set, */
|
|
|
|
/* 0x00 otherwise */
|
|
|
|
EXTERN byte chip8_mem[4096]; /* machine memory. program */
|
|
|
|
/* is loaded at 0x200 */
|
|
|
|
EXTERN byte chip8_running; /* if 0, emulation stops */
|
|
|
|
|
2010-01-03 13:01:19 +00:00
|
|
|
EXTERN void chip8_execute (void); /* execute chip8_iperiod */
|
2005-07-06 18:38:25 +00:00
|
|
|
/* opcodes */
|
2010-01-03 13:01:19 +00:00
|
|
|
EXTERN void chip8_reset (void); /* reset virtual machine */
|
|
|
|
EXTERN void chip8 (void); /* start chip8 emulation */
|
2005-07-06 18:38:25 +00:00
|
|
|
|
2010-01-03 13:01:19 +00:00
|
|
|
EXTERN void chip8_sound_on (void); /* turn sound on */
|
|
|
|
EXTERN void chip8_sound_off (void); /* turn sound off */
|
|
|
|
EXTERN void chip8_interrupt (void); /* update keyboard, */
|
2005-07-06 18:38:25 +00:00
|
|
|
/* display, etc. */
|
|
|
|
|
|
|
|
#ifdef CHIP8_DEBUG
|
|
|
|
EXTERN byte chip8_trace; /* if 1, call debugger */
|
|
|
|
/* every opcode */
|
|
|
|
EXTERN word chip8_trap; /* if pc==trap, set trace */
|
|
|
|
/* flag */
|
|
|
|
EXTERN void chip8_debug (word opcode,struct chip8_regs_struct *regs);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __CHIP8_H */
|
|
|
|
|
|
|
|
/** Vision8: CHIP8 emulator *************************************************/
|
|
|
|
/** **/
|
|
|
|
/** CHIP8.c **/
|
|
|
|
/** **/
|
|
|
|
/** This file contains the portable CHIP8 emulation engine **/
|
|
|
|
/** SCHIP emulation (C) Frederic Devernay 2005 **/
|
|
|
|
/** **/
|
|
|
|
/** Copyright (C) Marcel de Kogel 1997 **/
|
|
|
|
/** You are not allowed to distribute this software commercially **/
|
|
|
|
/** Please, notify me, if you make any changes to this file **/
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
/* you can
|
|
|
|
#define STATIC static
|
|
|
|
#define EXTERN static
|
|
|
|
and include this file for single-object generation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef STATIC
|
2010-01-02 22:51:29 +00:00
|
|
|
#include <stdlib.h> /* for memset, etc. */
|
2005-07-06 18:38:25 +00:00
|
|
|
#include <string.h>
|
|
|
|
#define STATIC
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CHIP8_DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
#define DBG_(_x) ((void)(_x))
|
|
|
|
#else
|
|
|
|
#define DBG_(_x) ((void)0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
STATIC struct chip8_regs_struct chip8_regs;
|
|
|
|
|
2003-10-30 23:47:34 +00:00
|
|
|
static byte chip8_key_pressed;
|
2005-07-06 18:38:25 +00:00
|
|
|
STATIC byte chip8_keys[16]; /* if 1, key is held down */
|
|
|
|
STATIC byte chip8_display[CHIP8_WIDTH*CHIP8_HEIGHT]; /* 0xff if pixel is set, */
|
2003-10-30 23:47:34 +00:00
|
|
|
/* 0x00 otherwise */
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_SUPER
|
2010-01-02 22:51:29 +00:00
|
|
|
STATIC byte chip8_super; /* != 0 if in SCHIP display mode */
|
2005-07-06 18:38:25 +00:00
|
|
|
#endif
|
|
|
|
STATIC byte chip8_mem[4096]; /* machine memory. program */
|
2003-10-30 23:47:34 +00:00
|
|
|
/* is loaded at 0x200 */
|
|
|
|
|
|
|
|
#define read_mem(a) (chip8_mem[(a)&4095])
|
|
|
|
#define write_mem(a,v) (chip8_mem[(a)&4095]=(v))
|
|
|
|
|
2005-07-06 18:38:25 +00:00
|
|
|
STATIC byte chip8_iperiod;
|
|
|
|
|
|
|
|
STATIC byte chip8_running; /* Flag for End-of-Emulation */
|
2003-10-30 23:47:34 +00:00
|
|
|
|
|
|
|
#define get_reg_offset(opcode) (chip8_regs.alg+(opcode>>8))
|
|
|
|
#define get_reg_value(opcode) (*get_reg_offset(opcode))
|
|
|
|
#define get_reg_offset_2(opcode) (chip8_regs.alg+((opcode>>4)&0x0f))
|
|
|
|
#define get_reg_value_2(opcode) (*get_reg_offset_2(opcode))
|
|
|
|
|
|
|
|
typedef void (*opcode_fn) (word opcode);
|
|
|
|
typedef void (*math_fn) (byte *reg1,byte reg2);
|
|
|
|
|
2004-01-30 22:43:37 +00:00
|
|
|
|
2003-10-30 23:47:34 +00:00
|
|
|
|
|
|
|
static void op_call (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
chip8_regs.sp--;
|
|
|
|
write_mem (chip8_regs.sp,chip8_regs.pc&0xff);
|
|
|
|
chip8_regs.sp--;
|
|
|
|
write_mem (chip8_regs.sp,chip8_regs.pc>>8);
|
|
|
|
chip8_regs.pc=opcode;
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_DEBUG
|
|
|
|
if(chip8_regs.sp < 0x1c0)
|
2010-01-02 22:51:29 +00:00
|
|
|
printf("warning: more than 16 subroutine calls, sp=%x\n", chip8_regs.sp);
|
2005-07-06 18:38:25 +00:00
|
|
|
#endif
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_jmp (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
chip8_regs.pc=opcode;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_key (word opcode)
|
|
|
|
{
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_DEBUG
|
|
|
|
static byte tested[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
#endif
|
|
|
|
byte key, key_value,cp_value;
|
|
|
|
if ((opcode&0xff)==0x9e) /* skp */
|
2004-01-08 13:03:04 +00:00
|
|
|
cp_value=1;
|
2005-07-06 18:38:25 +00:00
|
|
|
else if ((opcode&0xff)==0xa1) /* sknp */
|
2004-01-08 13:03:04 +00:00
|
|
|
cp_value=0;
|
2005-07-06 18:38:25 +00:00
|
|
|
else {
|
2010-01-02 22:51:29 +00:00
|
|
|
DBG_(printf("unhandled key opcode 0x%x\n", opcode));
|
|
|
|
return;
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
|
|
|
key = get_reg_value(opcode)&0x0f;
|
|
|
|
#ifdef CHIP8_DEBUG
|
|
|
|
if (!tested[key]) {
|
2010-01-02 22:51:29 +00:00
|
|
|
tested[key] = 1;
|
|
|
|
DBG_(printf("testing key %d\n", key));
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
key_value=chip8_keys[key];
|
2004-01-08 13:03:04 +00:00
|
|
|
if (cp_value==key_value)
|
|
|
|
chip8_regs.pc+=2;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_skeq_const (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
if (get_reg_value(opcode)==(opcode&0xff))
|
|
|
|
chip8_regs.pc+=2;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_skne_const (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
if (get_reg_value(opcode)!=(opcode&0xff))
|
|
|
|
chip8_regs.pc+=2;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_skeq_reg (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
if (get_reg_value(opcode)==get_reg_value_2(opcode))
|
|
|
|
chip8_regs.pc+=2;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_skne_reg (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
if (get_reg_value(opcode)!=get_reg_value_2(opcode))
|
|
|
|
chip8_regs.pc+=2;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_mov_const (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
*get_reg_offset(opcode)=opcode&0xff;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_add_const (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
*get_reg_offset(opcode)+=opcode&0xff;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_mvi (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
chip8_regs.i=opcode;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_jmi (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
chip8_regs.pc=opcode+chip8_regs.alg[0];
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_rand (word opcode)
|
|
|
|
{
|
2005-07-06 18:38:25 +00:00
|
|
|
*get_reg_offset(opcode)=rand()&(opcode&0xff);
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void math_or (byte *reg1,byte reg2)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
*reg1|=reg2;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void math_mov (byte *reg1,byte reg2)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
*reg1=reg2;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void math_nop (byte *reg1,byte reg2)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
(void)reg1;
|
|
|
|
(void)reg2;
|
2005-07-06 18:38:25 +00:00
|
|
|
DBG_(printf("Warning: math nop!\n"));
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void math_and (byte *reg1,byte reg2)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
*reg1&=reg2;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void math_xor (byte *reg1,byte reg2)
|
|
|
|
{
|
|
|
|
*reg1^=reg2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void math_add (byte *reg1,byte reg2)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
word tmp;
|
|
|
|
tmp=*reg1+reg2;
|
|
|
|
*reg1=(byte)tmp;
|
|
|
|
chip8_regs.alg[15]=tmp>>8;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void math_sub (byte *reg1,byte reg2)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
word tmp;
|
|
|
|
tmp=*reg1-reg2;
|
|
|
|
*reg1=(byte)tmp;
|
|
|
|
chip8_regs.alg[15]=((byte)(tmp>>8))+1;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void math_shr (byte *reg1,byte reg2)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
(void)reg2;
|
|
|
|
chip8_regs.alg[15]=*reg1&1;
|
|
|
|
*reg1>>=1;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void math_shl (byte *reg1,byte reg2)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
(void)reg2;
|
|
|
|
chip8_regs.alg[15]=*reg1>>7;
|
|
|
|
*reg1<<=1;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void math_rsb (byte *reg1,byte reg2)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
word tmp;
|
|
|
|
tmp=reg2-*reg1;
|
|
|
|
*reg1=(byte)tmp;
|
|
|
|
chip8_regs.alg[15]=((byte)(tmp>>8))+1;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_SUPER
|
|
|
|
/* SUPER: scroll down n lines (or half in CHIP8 mode) */
|
|
|
|
static void scroll_down(word opcode)
|
|
|
|
{
|
|
|
|
int n = opcode & 0xf;
|
|
|
|
byte *dst = chip8_display + CHIP8_WIDTH*CHIP8_HEIGHT -1;
|
|
|
|
byte *src = dst - n*CHIP8_WIDTH;
|
|
|
|
while(src >= chip8_display) {
|
2010-01-02 22:51:29 +00:00
|
|
|
*dst-- = *src--;
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
|
|
|
while(dst >= chip8_display) {
|
2010-01-02 22:51:29 +00:00
|
|
|
*dst-- = 0;
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* SUPER: scroll 4 pixels left! */
|
|
|
|
static void scroll_left(void)
|
|
|
|
{
|
|
|
|
byte *dst = chip8_display;
|
|
|
|
byte *src = dst;
|
|
|
|
byte *eol = chip8_display + CHIP8_WIDTH;
|
|
|
|
byte *eoi = chip8_display + CHIP8_WIDTH*CHIP8_HEIGHT;
|
|
|
|
while(eol <= eoi) {
|
2010-01-02 22:51:29 +00:00
|
|
|
src+=4;
|
|
|
|
while(src < eol) {
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
*dst++ = 0;
|
|
|
|
*dst++ = 0;
|
|
|
|
*dst++ = 0;
|
|
|
|
*dst++ = 0;
|
|
|
|
eol += CHIP8_WIDTH;
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static void scroll_right(void)
|
|
|
|
{
|
|
|
|
byte *dst = chip8_display + CHIP8_WIDTH*CHIP8_HEIGHT -1;
|
|
|
|
byte *src = dst;
|
|
|
|
byte *bol = chip8_display + CHIP8_WIDTH*(CHIP8_HEIGHT-1);
|
|
|
|
while(bol >= chip8_display) {
|
2010-01-02 22:51:29 +00:00
|
|
|
src-=4;
|
|
|
|
while(src >= bol) {
|
|
|
|
*dst-- = *src--;
|
|
|
|
}
|
|
|
|
*dst-- = 0;
|
|
|
|
*dst-- = 0;
|
|
|
|
*dst-- = 0;
|
|
|
|
*dst-- = 0;
|
|
|
|
bol -= CHIP8_WIDTH;
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-10-30 23:47:34 +00:00
|
|
|
static void op_system (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
switch ((byte)opcode)
|
|
|
|
{
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_SUPER
|
|
|
|
case 0xfb:
|
2010-01-02 22:51:29 +00:00
|
|
|
scroll_right();
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 0xfc:
|
2010-01-02 22:51:29 +00:00
|
|
|
scroll_left();
|
2020-10-08 13:47:40 +00:00
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 0xfd:
|
2010-01-02 22:51:29 +00:00
|
|
|
DBG_(printf("SUPER: quit the emulator\n"));
|
|
|
|
chip8_reset();
|
2020-10-08 13:47:40 +00:00
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 0xfe:
|
2010-01-02 22:51:29 +00:00
|
|
|
DBG_(printf("SUPER: set CHIP-8 graphic mode\n"));
|
|
|
|
memset (chip8_display,0,sizeof(chip8_display));
|
|
|
|
chip8_super = 0;
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 0xff:
|
2010-01-02 22:51:29 +00:00
|
|
|
DBG_(printf("SUPER: set SCHIP graphic mode\n"));
|
|
|
|
memset (chip8_display,0,sizeof(chip8_display));
|
|
|
|
chip8_super = 1;
|
2020-10-08 13:47:40 +00:00
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
#endif
|
2004-01-08 13:03:04 +00:00
|
|
|
case 0xe0:
|
2005-07-06 18:38:25 +00:00
|
|
|
memset (chip8_display,0,sizeof(chip8_display));
|
2004-01-08 13:03:04 +00:00
|
|
|
break;
|
|
|
|
case 0xee:
|
|
|
|
chip8_regs.pc=read_mem(chip8_regs.sp)<<8;
|
|
|
|
chip8_regs.sp++;
|
|
|
|
chip8_regs.pc+=read_mem(chip8_regs.sp);
|
|
|
|
chip8_regs.sp++;
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
default:
|
|
|
|
#ifdef CHIP8_SUPER
|
2010-01-02 22:51:29 +00:00
|
|
|
if ((opcode & 0xF0) == 0xC0)
|
|
|
|
scroll_down(opcode);
|
|
|
|
else
|
2005-07-06 18:38:25 +00:00
|
|
|
#endif
|
2010-01-02 22:51:29 +00:00
|
|
|
{
|
|
|
|
DBG_(printf("unhandled system opcode 0x%x\n", opcode));
|
|
|
|
chip8_running = 3;
|
|
|
|
}
|
|
|
|
break;
|
2004-01-08 13:03:04 +00:00
|
|
|
}
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_misc (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
byte *reg,i,j;
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_DEBUG
|
|
|
|
static byte firstwait = 1;
|
|
|
|
#endif
|
2004-01-08 13:03:04 +00:00
|
|
|
reg=get_reg_offset(opcode);
|
|
|
|
switch ((byte)opcode)
|
|
|
|
{
|
2010-01-02 22:51:29 +00:00
|
|
|
case 0x07: /* gdelay */
|
2004-01-08 13:03:04 +00:00
|
|
|
*reg=chip8_regs.delay;
|
|
|
|
break;
|
2010-01-02 22:51:29 +00:00
|
|
|
case 0x0a: /* key */
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_DEBUG
|
2010-01-02 22:51:29 +00:00
|
|
|
if(firstwait) {
|
|
|
|
printf("waiting for key press\n");
|
|
|
|
firstwait = 0;
|
|
|
|
}
|
2005-07-06 18:38:25 +00:00
|
|
|
#endif
|
2010-01-02 22:51:29 +00:00
|
|
|
if (chip8_key_pressed)
|
2004-01-08 13:03:04 +00:00
|
|
|
*reg=chip8_key_pressed-1;
|
|
|
|
else
|
|
|
|
chip8_regs.pc-=2;
|
|
|
|
break;
|
2010-01-02 22:51:29 +00:00
|
|
|
case 0x15: /* sdelay */
|
2004-01-08 13:03:04 +00:00
|
|
|
chip8_regs.delay=*reg;
|
|
|
|
break;
|
2010-01-02 22:51:29 +00:00
|
|
|
case 0x18: /* ssound */
|
2004-01-08 13:03:04 +00:00
|
|
|
chip8_regs.sound=*reg;
|
|
|
|
if (chip8_regs.sound)
|
|
|
|
chip8_sound_on();
|
|
|
|
break;
|
2010-01-02 22:51:29 +00:00
|
|
|
case 0x1e: /* adi */
|
2004-01-08 13:03:04 +00:00
|
|
|
chip8_regs.i+=(*reg);
|
|
|
|
break;
|
2010-01-02 22:51:29 +00:00
|
|
|
case 0x29: /* font */
|
2004-01-08 13:03:04 +00:00
|
|
|
chip8_regs.i=((word)(*reg&0x0f))*5;
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_SUPER
|
2010-01-02 22:51:29 +00:00
|
|
|
case 0x30: /* xfont */
|
2005-07-06 18:38:25 +00:00
|
|
|
chip8_regs.i=((word)(*reg&0x0f))*10+0x50;
|
2010-01-02 22:51:29 +00:00
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
#endif
|
2010-01-02 22:51:29 +00:00
|
|
|
case 0x33: /* bcd */
|
2004-01-08 13:03:04 +00:00
|
|
|
i=*reg;
|
|
|
|
for (j=0;i>=100;i-=100)
|
|
|
|
j++;
|
|
|
|
write_mem (chip8_regs.i,j);
|
|
|
|
for (j=0;i>=10;i-=10)
|
|
|
|
j++;
|
|
|
|
write_mem (chip8_regs.i+1,j);
|
|
|
|
write_mem (chip8_regs.i+2,i);
|
|
|
|
break;
|
2010-01-02 22:51:29 +00:00
|
|
|
case 0x55: /* str */
|
2004-01-08 13:03:04 +00:00
|
|
|
for (i=0,j=(opcode>>8)&0x0f; i<=j; ++i)
|
|
|
|
write_mem(chip8_regs.i+i,chip8_regs.alg[i]);
|
|
|
|
break;
|
2010-01-02 22:51:29 +00:00
|
|
|
case 0x65: /* ldr */
|
2004-01-08 13:03:04 +00:00
|
|
|
for (i=0,j=(opcode>>8)&0x0f; i<=j; ++i)
|
|
|
|
chip8_regs.alg[i]=read_mem(chip8_regs.i+i);
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_SUPER
|
|
|
|
case 0x75:
|
2010-01-02 22:51:29 +00:00
|
|
|
DBG_(printf("SUPER: save V0..V%x (X<8) in the HP48 flags\n", (opcode>>8)&0x0f));
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 0x85:
|
2010-01-02 22:51:29 +00:00
|
|
|
DBG_(printf("SUPER: load V0..V%x (X<8) from the HP48 flags\n", (opcode>>8)&0x0f));
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
#endif
|
|
|
|
default:
|
2010-01-02 22:51:29 +00:00
|
|
|
DBG_(printf("unhandled misc opcode 0x%x\n", opcode));
|
|
|
|
break;
|
2004-01-08 13:03:04 +00:00
|
|
|
}
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void op_sprite (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
byte *q;
|
|
|
|
byte n,x,x2,y,collision;
|
|
|
|
word p;
|
2005-07-06 18:38:25 +00:00
|
|
|
x=get_reg_value(opcode);
|
|
|
|
y=get_reg_value_2(opcode);
|
2004-01-08 13:03:04 +00:00
|
|
|
p=chip8_regs.i;
|
|
|
|
n=opcode&0x0f;
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_SUPER
|
|
|
|
if (chip8_super) {
|
2010-01-02 22:51:29 +00:00
|
|
|
/*printf("SUPER: sprite(%x)\n", opcode);*/
|
|
|
|
x &= 128-1;
|
|
|
|
y &= 64-1;
|
|
|
|
q=chip8_display+y*CHIP8_WIDTH;
|
|
|
|
if(n == 0)
|
|
|
|
{ /* 16x16 sprite */
|
|
|
|
n = 16;
|
|
|
|
if (n+y>64)
|
|
|
|
n=64-y;
|
|
|
|
for (collision=1;n;--n,q+=CHIP8_WIDTH)
|
|
|
|
{
|
|
|
|
/* first 8 bits */
|
|
|
|
for (y=read_mem(p++),x2=x;y;y<<=1,x2=(x2+1)&(CHIP8_WIDTH-1))
|
|
|
|
if (y&0x80)
|
|
|
|
collision&=(q[x2]^=0xff);
|
|
|
|
x2=(x+8)&(CHIP8_WIDTH-1);
|
|
|
|
/* last 8 bits */
|
|
|
|
for (y=read_mem(p++);y;y<<=1,x2=(x2+1)&(CHIP8_WIDTH-1))
|
|
|
|
if (y&0x80)
|
|
|
|
collision&=(q[x2]^=0xff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* 8xn sprite */
|
|
|
|
if (n+y>64)
|
|
|
|
n=64-y;
|
|
|
|
for (collision=1;n;--n,q+=CHIP8_WIDTH)
|
|
|
|
{
|
|
|
|
for (y=read_mem(p++),x2=x;y;y<<=1,x2=(x2+1)&(CHIP8_WIDTH-1))
|
|
|
|
if (y&0x80)
|
|
|
|
collision&=(q[x2]^=0xff);
|
|
|
|
}
|
|
|
|
}
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-01-02 22:51:29 +00:00
|
|
|
x &= 64-1;
|
|
|
|
y &= 32-1;
|
|
|
|
q=chip8_display+y*CHIP8_WIDTH*2;
|
2020-10-08 13:47:40 +00:00
|
|
|
if(n == 0)
|
2010-01-02 22:51:29 +00:00
|
|
|
n = 16;
|
|
|
|
if (n+y>32)
|
|
|
|
n=32-y;
|
|
|
|
for (collision=1;n;--n,q+=CHIP8_WIDTH*2)
|
|
|
|
{
|
|
|
|
for (y=read_mem(p++),x2=x*2;y;y<<=1,x2=(x2+2)&(CHIP8_WIDTH-1))
|
|
|
|
if (y&0x80) {
|
|
|
|
q[x2]^=0xff;
|
|
|
|
q[x2+1]^=0xff;
|
|
|
|
q[x2+CHIP8_WIDTH]^=0xff;
|
|
|
|
q[x2+CHIP8_WIDTH+1]^=0xff;
|
|
|
|
collision &= q[x2]|q[x2+1]|q[x2+CHIP8_WIDTH]|q[x2+CHIP8_WIDTH+1];
|
|
|
|
}
|
|
|
|
}
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
x &= 64-1;
|
|
|
|
y &= 32-1;
|
|
|
|
q=chip8_display+y*CHIP8_WIDTH;
|
2004-01-08 13:03:04 +00:00
|
|
|
if (n+y>32)
|
|
|
|
n=32-y;
|
2005-07-06 18:38:25 +00:00
|
|
|
for (collision=1;n;--n,q+=CHIP8_WIDTH)
|
2004-01-08 13:03:04 +00:00
|
|
|
{
|
2005-07-06 18:38:25 +00:00
|
|
|
for (y=read_mem(p++),x2=x;y;y<<=1,x2=(x2+1)&(CHIP8_WIDTH-1))
|
|
|
|
if (y&0x80)
|
2010-01-02 22:51:29 +00:00
|
|
|
collision&=(q[x2]^=0xff);
|
2004-01-08 13:03:04 +00:00
|
|
|
}
|
2005-07-06 18:38:25 +00:00
|
|
|
#endif
|
2004-01-08 13:03:04 +00:00
|
|
|
chip8_regs.alg[15]=collision^1;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
2010-01-03 13:01:19 +00:00
|
|
|
static const math_fn math_opcodes[16]=
|
2003-10-30 23:47:34 +00:00
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
math_mov,
|
|
|
|
math_or,
|
|
|
|
math_and,
|
|
|
|
math_xor,
|
|
|
|
math_add,
|
|
|
|
math_sub,
|
|
|
|
math_shr,
|
|
|
|
math_rsb,
|
|
|
|
math_nop,
|
|
|
|
math_nop,
|
|
|
|
math_nop,
|
|
|
|
math_nop,
|
|
|
|
math_nop,
|
|
|
|
math_nop,
|
|
|
|
math_shl,
|
|
|
|
math_nop
|
2003-10-30 23:47:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void op_math (word opcode)
|
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
(*(math_opcodes[opcode&0x0f]))
|
2003-10-30 23:47:34 +00:00
|
|
|
(get_reg_offset(opcode),get_reg_value_2(opcode));
|
|
|
|
}
|
|
|
|
|
2010-01-03 13:01:19 +00:00
|
|
|
static const opcode_fn main_opcodes[16]=
|
2003-10-30 23:47:34 +00:00
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
op_system,
|
|
|
|
op_jmp,
|
|
|
|
op_call,
|
|
|
|
op_skeq_const,
|
|
|
|
op_skne_const,
|
|
|
|
op_skeq_reg,
|
|
|
|
op_mov_const,
|
|
|
|
op_add_const,
|
|
|
|
op_math,
|
|
|
|
op_skne_reg,
|
|
|
|
op_mvi,
|
|
|
|
op_jmi,
|
|
|
|
op_rand,
|
|
|
|
op_sprite,
|
|
|
|
op_key,
|
|
|
|
op_misc
|
2003-10-30 23:47:34 +00:00
|
|
|
};
|
|
|
|
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_DEBUG
|
|
|
|
STATIC byte chip8_trace;
|
|
|
|
STATIC word chip8_trap;
|
|
|
|
|
2003-10-30 23:47:34 +00:00
|
|
|
/****************************************************************************/
|
2005-07-06 18:38:25 +00:00
|
|
|
/* This routine is called every opcode when chip8_trace==1. It prints the */
|
|
|
|
/* current register contents and the opcode being executed */
|
2003-10-30 23:47:34 +00:00
|
|
|
/****************************************************************************/
|
2005-07-06 18:38:25 +00:00
|
|
|
STATIC void chip8_debug (word opcode,struct chip8_regs_struct *regs)
|
2003-10-30 23:47:34 +00:00
|
|
|
{
|
2005-07-06 18:38:25 +00:00
|
|
|
int i;
|
2010-01-03 13:01:19 +00:00
|
|
|
static const byte hextable[16] = "0123456789ABCDEF";
|
2005-07-06 18:38:25 +00:00
|
|
|
byte v1[3] = "Vx\0";
|
|
|
|
byte v2[3] = "Vx\0";
|
|
|
|
v1[1] = hextable[(opcode>>8)&0x0f];
|
|
|
|
v2[1] = hextable[(opcode>>8)&0x0f];
|
|
|
|
printf ("PC=%04X: %04X - ",regs->pc,opcode);
|
|
|
|
switch (opcode>>12) {
|
|
|
|
case 0:
|
2010-01-02 22:51:29 +00:00
|
|
|
if ((opcode&0xff0) == 0xc0) {
|
|
|
|
printf ("SCD %01X ; Scroll down n lines",opcode&0xf);
|
|
|
|
}
|
|
|
|
else switch (opcode&0xfff) {
|
|
|
|
case 0xe0:
|
|
|
|
printf ("CLS ; Clear screen");
|
|
|
|
break;
|
|
|
|
case 0xee:
|
|
|
|
printf ("RET ; Return from subroutine call");
|
|
|
|
break;
|
|
|
|
case 0xfb:
|
|
|
|
printf("SCR ; Scroll right");
|
|
|
|
break;
|
|
|
|
case 0xfc:
|
|
|
|
printf("SCL ; Scroll left");
|
|
|
|
break;
|
|
|
|
case 0xfd:
|
|
|
|
printf("EXIT ; Terminate the interpreter");
|
|
|
|
break;
|
|
|
|
case 0xfe:
|
|
|
|
printf("LOW ; Disable extended screen mode");
|
|
|
|
break;
|
|
|
|
case 0xff:
|
|
|
|
printf("HIGH ; Enable extended screen mode");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf ("SYS %03X ; Unknown system call",opcode&0xff);
|
|
|
|
}
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 1:
|
2010-01-02 22:51:29 +00:00
|
|
|
printf ("JP %03X ; Jump to address",opcode&0xfff);
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 2:
|
2010-01-02 22:51:29 +00:00
|
|
|
printf ("CALL %03X ; Call subroutine",opcode&0xfff);
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 3:
|
2010-01-02 22:51:29 +00:00
|
|
|
printf ("SE %s,%02X ; Skip if register == constant",v1,opcode&0xff);
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 4:
|
2010-01-02 22:51:29 +00:00
|
|
|
printf ("SNE %s,%02X ; Skip if register <> constant",v1,opcode&0xff);
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 5:
|
2010-01-02 22:51:29 +00:00
|
|
|
printf ("SE %s,%s ; Skip if register == register",v1,v2);
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 6:
|
2010-01-02 22:51:29 +00:00
|
|
|
printf ("LD %s,%02X ; Set VX = Byte",v1,opcode&0xff);
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 7:
|
2010-01-02 22:51:29 +00:00
|
|
|
printf ("ADD %s,%02X ; Set VX = VX + Byte",v1,opcode&0xff);
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 8:
|
2010-01-02 22:51:29 +00:00
|
|
|
switch (opcode&0x0f) {
|
|
|
|
case 0:
|
|
|
|
printf ("LD %s,%s ; Set VX = VY, VF updates",v1,v2);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
printf ("OR %s,%s ; Set VX = VX | VY, VF updates",v1,v2);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
printf ("AND %s,%s ; Set VX = VX & VY, VF updates",v1,v2);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
printf ("XOR %s,%s ; Set VX = VX ^ VY, VF updates",v1,v2);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
printf ("ADD %s,%s ; Set VX = VX + VY, VF = carry",v1,v2);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
printf ("SUB %s,%s ; Set VX = VX - VY, VF = !borrow",v1,v2);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
printf ("SHR %s,%s ; Set VX = VX >> 1, VF = carry",v1,v2);
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
printf ("SUBN %s,%s ; Set VX = VY - VX, VF = !borrow",v1,v2);
|
|
|
|
break;
|
|
|
|
case 14:
|
|
|
|
printf ("SHL %s,%s ; Set VX = VX << 1, VF = carry",v1,v2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf ("Illegal opcode");
|
|
|
|
}
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 9:
|
2010-01-02 22:51:29 +00:00
|
|
|
printf ("SNE %s,%s ; Skip next instruction iv VX!=VY",v1,v2);
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 10:
|
2010-01-02 22:51:29 +00:00
|
|
|
printf ("LD I,%03X ; Set I = Addr",opcode&0xfff);
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 11:
|
2010-01-02 22:51:29 +00:00
|
|
|
printf ("JP V0,%03X ; Jump to Addr + V0",opcode&0xfff);
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 12:
|
2010-01-02 22:51:29 +00:00
|
|
|
printf ("RND %s,%02X ; Set VX = random & Byte",v1,opcode&0xff);
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 13:
|
2010-01-02 22:51:29 +00:00
|
|
|
printf ("DRW %s,%s,%X ; Draw n byte sprite stored at [i] at VX,VY. Set VF = collision",v1,v2,opcode&0x0f);
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 14:
|
2010-01-02 22:51:29 +00:00
|
|
|
switch (opcode&0xff) {
|
|
|
|
case 0x9e:
|
|
|
|
printf ("SKP %s ; Skip next instruction if key VX down",v1);
|
|
|
|
break;
|
|
|
|
case 0xa1:
|
|
|
|
printf ("SKNP %s ; Skip next instruction if key VX up",v1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf ("%04X ; Illegal opcode", opcode);
|
|
|
|
}
|
|
|
|
break;
|
2005-07-06 18:38:25 +00:00
|
|
|
case 15:
|
2010-01-02 22:51:29 +00:00
|
|
|
switch (opcode&0xff) {
|
|
|
|
case 0x07:
|
|
|
|
printf ("LD %s,DT ; Set VX = delaytimer",v1);
|
|
|
|
break;
|
|
|
|
case 0x0a:
|
|
|
|
printf ("LD %s,K ; Set VX = key, wait for keypress",v1);
|
|
|
|
break;
|
|
|
|
case 0x15:
|
|
|
|
printf ("LD DT,%s ; Set delaytimer = VX",v1);
|
|
|
|
break;
|
|
|
|
case 0x18:
|
|
|
|
printf ("LD ST,%s ; Set soundtimer = VX",v1);
|
|
|
|
break;
|
|
|
|
case 0x1e:
|
|
|
|
printf ("ADD I,%s ; Set I = I + VX",v1);
|
|
|
|
break;
|
|
|
|
case 0x29:
|
|
|
|
printf ("LD LF,%s ; Point I to 5 byte numeric sprite for value in VX",v1);
|
|
|
|
break;
|
|
|
|
case 0x30:
|
|
|
|
printf ("LD HF,%s ; Point I to 10 byte numeric sprite for value in VX",v1);
|
|
|
|
break;
|
|
|
|
case 0x33:
|
|
|
|
printf ("LD B,%s ; Store BCD of VX in [I], [I+1], [I+2]",v1);
|
|
|
|
break;
|
|
|
|
case 0x55:
|
|
|
|
printf ("LD [I],%s ; Store V0..VX in [I]..[I+X]",v1);
|
|
|
|
break;
|
|
|
|
case 0x65:
|
|
|
|
printf ("LD %s,[I] ; Read V0..VX from [I]..[I+X]",v1);
|
|
|
|
break;
|
|
|
|
case 0x75:
|
|
|
|
printf ("LD R,%s ; Store V0..VX in RPL user flags (X<=7)",v1);
|
|
|
|
break;
|
|
|
|
case 0x85:
|
|
|
|
printf ("LD %s,R ; Read V0..VX from RPL user flags (X<=7)",v1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf ("%04X ; Illegal opcode", opcode);
|
|
|
|
}
|
|
|
|
break;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
2005-07-06 18:38:25 +00:00
|
|
|
printf ("\n; Registers: ");
|
|
|
|
for (i=0;i<16;++i) printf ("%02x ",(regs->alg[i])&0xff);
|
|
|
|
printf ("\n; Index: %03x Stack:%03x Delay:%02x Sound:%02x\n",
|
2010-01-02 22:51:29 +00:00
|
|
|
regs->i&0xfff,regs->sp&0xfff,regs->delay&0xff,regs->sound&0xff);
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
2004-10-17 00:54:09 +00:00
|
|
|
#endif
|
2003-10-30 23:47:34 +00:00
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* Execute chip8_iperiod opcodes */
|
|
|
|
/****************************************************************************/
|
2005-07-06 18:38:25 +00:00
|
|
|
STATIC void chip8_execute(void)
|
2003-10-30 23:47:34 +00:00
|
|
|
{
|
2004-01-08 13:03:04 +00:00
|
|
|
byte i;
|
|
|
|
byte key_pressed=0;
|
|
|
|
word opcode;
|
|
|
|
for (i = chip8_iperiod ; i ;--i)
|
2005-07-06 18:38:25 +00:00
|
|
|
{
|
2010-01-02 22:51:29 +00:00
|
|
|
/* Fetch the opcode */
|
2004-01-08 13:03:04 +00:00
|
|
|
opcode=(read_mem(chip8_regs.pc)<<8)+read_mem(chip8_regs.pc+1);
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_DEBUG
|
2010-01-02 22:51:29 +00:00
|
|
|
/* Check if trap address has been reached */
|
|
|
|
if ((chip8_regs.pc&4095)==chip8_trap)
|
|
|
|
chip8_trace=1;
|
|
|
|
/* Call the debugger if chip8_trace!=0 */
|
|
|
|
if (chip8_trace)
|
|
|
|
chip8_debug (opcode,&chip8_regs);
|
2005-07-06 18:38:25 +00:00
|
|
|
#endif
|
2004-01-08 13:03:04 +00:00
|
|
|
chip8_regs.pc+=2;
|
|
|
|
(*(main_opcodes[opcode>>12]))(opcode&0x0fff); /* Emulate this opcode */
|
|
|
|
}
|
2005-07-06 18:38:25 +00:00
|
|
|
/* Update timers */
|
2004-01-08 13:03:04 +00:00
|
|
|
if (chip8_regs.delay)
|
|
|
|
--chip8_regs.delay;
|
|
|
|
if (chip8_regs.sound)
|
2005-07-06 18:38:25 +00:00
|
|
|
if (--chip8_regs.sound == 0)
|
2020-10-08 13:47:40 +00:00
|
|
|
chip8_sound_off();
|
2005-07-06 18:38:25 +00:00
|
|
|
|
|
|
|
/* Update the machine status */
|
|
|
|
chip8_interrupt ();
|
2004-01-08 13:03:04 +00:00
|
|
|
|
|
|
|
for (i=key_pressed=0;i<16;++i) /* check if a key was first */
|
2010-01-02 22:51:29 +00:00
|
|
|
if (chip8_keys[i]) /* pressed */
|
2005-07-06 18:38:25 +00:00
|
|
|
key_pressed=i+1;
|
2004-01-08 13:03:04 +00:00
|
|
|
if (key_pressed && key_pressed!=chip8_key_pressed)
|
|
|
|
chip8_key_pressed=key_pressed;
|
|
|
|
else
|
|
|
|
chip8_key_pressed=0;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* Reset the virtual chip8 machine */
|
|
|
|
/****************************************************************************/
|
2005-07-06 18:38:25 +00:00
|
|
|
STATIC void chip8_reset(void)
|
2003-10-30 23:47:34 +00:00
|
|
|
{
|
2010-01-03 13:01:19 +00:00
|
|
|
static const byte chip8_sprites[0x50]=
|
2004-01-08 13:03:04 +00:00
|
|
|
{
|
|
|
|
0xf9,0x99,0xf2,0x62,0x27,
|
|
|
|
0xf1,0xf8,0xff,0x1f,0x1f,
|
|
|
|
0x99,0xf1,0x1f,0x8f,0x1f,
|
|
|
|
0xf8,0xf9,0xff,0x12,0x44,
|
|
|
|
0xf9,0xf9,0xff,0x9f,0x1f,
|
|
|
|
0xf9,0xf9,0x9e,0x9e,0x9e,
|
|
|
|
0xf8,0x88,0xfe,0x99,0x9e,
|
|
|
|
0xf8,0xf8,0xff,0x8f,0x88,
|
2005-07-06 18:38:25 +00:00
|
|
|
}; /* 4x5 pixel hexadecimal character font patterns */
|
|
|
|
#ifdef CHIP8_SUPER
|
2010-01-03 13:01:19 +00:00
|
|
|
static const byte schip_sprites[10*10]=
|
2005-07-06 18:38:25 +00:00
|
|
|
{
|
2010-01-02 22:51:29 +00:00
|
|
|
0x3C, 0x7E, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0x7E, 0x3C, /* 0 */
|
|
|
|
0x18, 0x38, 0x58, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, /* 1 */
|
|
|
|
0x3E, 0x7F, 0xC3, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xFF, 0xFF, /* 2 */
|
|
|
|
0x3C, 0x7E, 0xC3, 0x03, 0x0E, 0x0E, 0x03, 0xC3, 0x7E, 0x3C, /* 3 */
|
|
|
|
0x06, 0x0E, 0x1E, 0x36, 0x66, 0xC6, 0xFF, 0xFF, 0x06, 0x06, /* 4 */
|
|
|
|
0xFF, 0xFF, 0xC0, 0xC0, 0xFC, 0xFE, 0x03, 0xC3, 0x7E, 0x3C, /* 5 */
|
|
|
|
0x3E, 0x7C, 0xC0, 0xC0, 0xFC, 0xFE, 0xC3, 0xC3, 0x7E, 0x3C, /* 6 */
|
|
|
|
0xFF, 0xFF, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x60, 0x60, /* 7 */
|
|
|
|
0x3C, 0x7E, 0xC3, 0xC3, 0x7E, 0x7E, 0xC3, 0xC3, 0x7E, 0x3C, /* 8 */
|
|
|
|
0x3C, 0x7E, 0xC3, 0xC3, 0x7F, 0x3F, 0x03, 0x03, 0x3E, 0x7C, /* 9 */
|
2005-07-06 18:38:25 +00:00
|
|
|
}; /* 8x10 pixel font patterns (only 10) */
|
|
|
|
#endif
|
2004-01-08 13:03:04 +00:00
|
|
|
byte i;
|
|
|
|
for (i=0;i<16*5;++i)
|
|
|
|
{
|
|
|
|
write_mem (i<<1,chip8_sprites[i]&0xf0);
|
|
|
|
write_mem ((i<<1)+1,chip8_sprites[i]<<4);
|
|
|
|
}
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_SUPER
|
|
|
|
/*
|
|
|
|
for (i=0; i<100; i++)
|
|
|
|
write_mem (i+0x50,schip_sprites[i]);
|
|
|
|
*/
|
|
|
|
memcpy(chip8_mem+0x50, schip_sprites, 100);
|
|
|
|
chip8_super = 0;
|
|
|
|
#endif
|
|
|
|
memset (chip8_regs.alg,0,sizeof(chip8_regs.alg));
|
|
|
|
memset (chip8_keys,0,sizeof(chip8_keys));
|
2004-01-08 13:03:04 +00:00
|
|
|
chip8_key_pressed=0;
|
2005-07-06 18:38:25 +00:00
|
|
|
memset (chip8_display,0,sizeof(chip8_display));
|
2004-01-08 13:03:04 +00:00
|
|
|
chip8_regs.delay=chip8_regs.sound=chip8_regs.i=0;
|
|
|
|
chip8_regs.sp=0x1e0;
|
|
|
|
chip8_regs.pc=0x200;
|
|
|
|
chip8_sound_off ();
|
|
|
|
chip8_running=1;
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifdef CHIP8_DEBUG
|
|
|
|
chip8_trace=0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* Start CHIP8 emulation */
|
|
|
|
/****************************************************************************/
|
|
|
|
STATIC void chip8 (void)
|
|
|
|
{
|
|
|
|
chip8_reset ();
|
|
|
|
while (chip8_running==1) chip8_execute ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/** END OF (S)CHIP-8 core emulation, from Vision-8 + mods by Fdy **/
|
|
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
/* size of the displayed area */
|
|
|
|
#if (CHIP8_WIDTH == 128) && (LCD_WIDTH < 128)
|
|
|
|
#define CHIP8_LCDWIDTH 112
|
|
|
|
#else
|
|
|
|
#define CHIP8_LCDWIDTH CHIP8_WIDTH
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (LCD_WIDTH > CHIP8_LCDWIDTH)
|
|
|
|
#define CHIP8_X ((LCD_WIDTH - CHIP8_LCDWIDTH)/2)
|
|
|
|
#else
|
|
|
|
#define CHIP8_X 0
|
|
|
|
#endif
|
|
|
|
#if (LCD_HEIGHT > CHIP8_HEIGHT)
|
|
|
|
#define CHIP8_Y (((LCD_HEIGHT - CHIP8_HEIGHT)>>4)<<3)
|
|
|
|
#else
|
|
|
|
#define CHIP8_Y 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* variable button definitions */
|
2020-07-15 23:40:55 +00:00
|
|
|
#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IRIVER_H300_PAD)
|
2005-12-14 01:31:37 +00:00
|
|
|
#define CHIP8_OFF BUTTON_OFF
|
2005-07-06 18:38:25 +00:00
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
|
|
|
|
2006-06-30 16:43:47 +00:00
|
|
|
#define CHIP8_RC_OFF BUTTON_RC_STOP
|
|
|
|
|
2006-02-24 20:54:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
|
2007-07-27 09:57:27 +00:00
|
|
|
(CONFIG_KEYPAD == IPOD_3G_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IPOD_1G2G_PAD)
|
2005-12-14 01:31:37 +00:00
|
|
|
#define CHIP8_OFF BUTTON_MENU
|
|
|
|
#define CHIP8_KEY2 BUTTON_SCROLL_BACK
|
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY8 BUTTON_SCROLL_FWD
|
|
|
|
|
2007-03-16 23:02:39 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
|
2006-01-18 11:09:06 +00:00
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
2006-02-24 15:06:25 +00:00
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
2006-01-18 11:09:06 +00:00
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
|
|
|
|
2006-02-24 15:42:52 +00:00
|
|
|
#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
|
2007-05-19 23:38:09 +00:00
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY1 BUTTON_MENU
|
2006-02-24 15:42:52 +00:00
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
2007-05-19 23:38:09 +00:00
|
|
|
#define CHIP8_KEY3 BUTTON_VOL_DOWN
|
2006-02-24 15:42:52 +00:00
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
2007-05-19 23:38:09 +00:00
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
2006-02-24 15:42:52 +00:00
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
2007-05-19 23:38:09 +00:00
|
|
|
#define CHIP8_KEY7 BUTTON_VOL_UP
|
2006-02-24 15:42:52 +00:00
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
2007-05-19 23:38:09 +00:00
|
|
|
#define CHIP8_KEY9 BUTTON_A
|
2006-02-24 15:42:52 +00:00
|
|
|
|
2009-01-04 23:33:15 +00:00
|
|
|
#elif CONFIG_KEYPAD == SANSA_E200_PAD || \
|
|
|
|
CONFIG_KEYPAD == SANSA_FUZE_PAD
|
2006-10-26 13:38:09 +00:00
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
2008-01-10 08:08:31 +00:00
|
|
|
#define CHIP8_KEY2 BUTTON_SCROLL_BACK
|
2006-10-26 13:38:09 +00:00
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
2008-01-10 08:08:31 +00:00
|
|
|
#define CHIP8_KEY8 BUTTON_SCROLL_FWD
|
2006-10-26 13:38:09 +00:00
|
|
|
|
2008-12-12 19:50:49 +00:00
|
|
|
#elif CONFIG_KEYPAD == SANSA_C200_PAD || \
|
|
|
|
CONFIG_KEYPAD == SANSA_CLIP_PAD || \
|
|
|
|
CONFIG_KEYPAD == SANSA_M200_PAD
|
2007-09-20 10:49:48 +00:00
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
2010-05-17 13:25:23 +00:00
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
2007-09-20 10:49:48 +00:00
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
2010-05-17 13:25:23 +00:00
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
2007-09-20 10:49:48 +00:00
|
|
|
|
2006-08-03 20:17:25 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
|
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY2 BUTTON_SCROLL_UP
|
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY8 BUTTON_SCROLL_DOWN
|
|
|
|
|
2008-02-17 12:23:02 +00:00
|
|
|
#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
|
|
|
|
#define CHIP8_OFF BUTTON_BACK
|
|
|
|
#define CHIP8_KEY1 BUTTON_MENU
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY3 BUTTON_VOL_DOWN
|
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY7 BUTTON_VOL_UP
|
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
|
|
|
#define CHIP8_KEY9 BUTTON_PLAY
|
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == MROBE100_PAD)
|
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY1 BUTTON_MENU
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY3 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY7 BUTTON_DISPLAY
|
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
|
|
|
|
2008-03-22 10:24:28 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
|
|
|
|
#define CHIP8_OFF BUTTON_RC_REC
|
|
|
|
#define CHIP8_KEY1 BUTTON_RC_MENU
|
|
|
|
#define CHIP8_KEY2 BUTTON_RC_VOL_UP
|
|
|
|
#define CHIP8_KEY3 BUTTON_RC_MODE
|
|
|
|
#define CHIP8_KEY4 BUTTON_RC_REW
|
|
|
|
#define CHIP8_KEY5 BUTTON_RC_PLAY
|
|
|
|
#define CHIP8_KEY6 BUTTON_RC_FF
|
|
|
|
#define CHIP8_KEY8 BUTTON_RC_VOL_DOWN
|
|
|
|
|
2009-12-15 20:51:41 +00:00
|
|
|
#elif (CONFIG_KEYPAD == COWON_D2_PAD)
|
2008-03-22 22:03:34 +00:00
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
|
2008-12-04 21:28:56 +00:00
|
|
|
#elif CONFIG_KEYPAD == CREATIVEZVM_PAD
|
2008-12-08 09:51:42 +00:00
|
|
|
#define CHIP8_OFF BUTTON_BACK
|
2008-12-04 21:28:56 +00:00
|
|
|
#define CHIP8_KEY1 BUTTON_MENU
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
2008-12-08 09:51:42 +00:00
|
|
|
#define CHIP8_KEY3 BUTTON_CUSTOM
|
2008-12-04 21:28:56 +00:00
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
2008-12-08 09:51:42 +00:00
|
|
|
#define CHIP8_KEY5 BUTTON_PLAY
|
2008-12-04 21:28:56 +00:00
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
2014-03-21 21:16:02 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == CREATIVE_ZENXFI3_PAD
|
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY1 BUTTON_VOL_UP
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY3 BUTTON_VOL_DOWN
|
|
|
|
#define CHIP8_KEY4 BUTTON_BACK
|
|
|
|
#define CHIP8_KEY5 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY6 BUTTON_MENU
|
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
2008-12-04 21:28:56 +00:00
|
|
|
|
2009-01-24 22:41:55 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
|
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY1 BUTTON_MENU
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY3 BUTTON_VOL_DOWN
|
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY7 BUTTON_VOL_UP
|
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
|
|
|
#define CHIP8_KEY9 BUTTON_VIEW
|
|
|
|
|
2010-11-02 23:18:41 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
|
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY1 BUTTON_PREV
|
|
|
|
#define CHIP8_KEY2 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY3 BUTTON_NEXT
|
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_UP
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY7 BUTTON_MENU
|
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
|
|
|
#define CHIP8_KEY9 BUTTON_VIEW
|
|
|
|
#define CHIP8_KEY0 BUTTON_VOL_DOWN
|
2020-10-08 13:47:40 +00:00
|
|
|
|
2009-12-07 18:23:25 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
|
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY1 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY3 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY4 BUTTON_PREV
|
|
|
|
#define CHIP8_KEY5 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY6 BUTTON_NEXT
|
|
|
|
#define CHIP8_KEY7 BUTTON_MENU
|
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
|
|
|
#define CHIP8_KEY9 BUTTON_VOL_UP
|
|
|
|
#define CHIP8_KEY0 BUTTON_VOL_DOWN
|
|
|
|
|
2009-08-31 21:11:32 +00:00
|
|
|
#elif (CONFIG_KEYPAD == ONDAVX747_PAD) || \
|
|
|
|
CONFIG_KEYPAD == ONDAVX777_PAD || \
|
|
|
|
CONFIG_KEYPAD == MROBE500_PAD
|
2009-04-07 23:41:44 +00:00
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
|
2014-05-22 21:34:52 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SAMSUNG_YH820_PAD) || \
|
2016-01-23 14:54:08 +00:00
|
|
|
(CONFIG_KEYPAD == SAMSUNG_YH92X_PAD)
|
2015-07-19 23:50:26 +00:00
|
|
|
#define CHIP8_OFF BUTTON_REW
|
|
|
|
#define CHIP8_KEY0 BUTTON_FFWD
|
2009-08-04 03:08:32 +00:00
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
2010-02-13 15:46:34 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
|
|
|
|
#define CHIP8_OFF BUTTON_REC
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY4 BUTTON_PREV
|
|
|
|
#define CHIP8_KEY5 BUTTON_OK
|
|
|
|
#define CHIP8_KEY6 BUTTON_NEXT
|
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
|
|
|
|
2010-04-26 21:40:00 +00:00
|
|
|
#elif CONFIG_KEYPAD == MPIO_HD200_PAD
|
|
|
|
|
|
|
|
#define CHIP8_OFF (BUTTON_REC|BUTTON_PLAY)
|
2012-02-02 13:42:42 +00:00
|
|
|
#define CHIP8_KEY1 BUTTON_REW
|
|
|
|
#define CHIP8_KEY2 BUTTON_FF
|
|
|
|
#define CHIP8_KEY3 BUTTON_FUNC
|
|
|
|
#define CHIP8_KEY4 BUTTON_REC
|
2010-04-26 21:40:00 +00:00
|
|
|
#define CHIP8_KEY5 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY6 BUTTON_VOL_DOWN
|
|
|
|
#define CHIP8_KEY8 BUTTON_VOL_UP
|
|
|
|
|
2010-11-30 10:52:14 +00:00
|
|
|
#elif CONFIG_KEYPAD == MPIO_HD300_PAD
|
|
|
|
|
2012-02-02 13:42:42 +00:00
|
|
|
#define CHIP8_OFF (BUTTON_MENU|BUTTON_REPEAT)
|
|
|
|
#define CHIP8_KEY1 BUTTON_REW
|
|
|
|
#define CHIP8_KEY2 BUTTON_FF
|
|
|
|
#define CHIP8_KEY3 BUTTON_MENU
|
|
|
|
#define CHIP8_KEY4 BUTTON_ENTER
|
|
|
|
#define CHIP8_KEY5 BUTTON_REC
|
|
|
|
#define CHIP8_KEY6 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY7 BUTTON_UP
|
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
2010-11-30 10:52:14 +00:00
|
|
|
|
2011-10-02 16:05:16 +00:00
|
|
|
#elif CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD
|
|
|
|
|
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
2013-07-17 16:43:33 +00:00
|
|
|
#define CHIP8_KEY0 BUTTON_VOL_DOWN
|
|
|
|
#define CHIP8_KEY1 BUTTON_BACK
|
2011-10-02 16:05:16 +00:00
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
2013-07-17 16:43:33 +00:00
|
|
|
#define CHIP8_KEY3 BUTTON_PLAYPAUSE
|
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY7 BUTTON_BOTTOMLEFT
|
|
|
|
#define CHIP8_KEY8 BUTTON_DOWN
|
|
|
|
#define CHIP8_KEY9 BUTTON_BOTTOMRIGHT
|
|
|
|
#define CHIP8_KEYA BUTTON_VOL_UP
|
2011-11-16 14:08:01 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == SANSA_CONNECT_PAD
|
|
|
|
|
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY1 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY3 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY4 BUTTON_DOWN
|
|
|
|
#define CHIP8_KEY5 BUTTON_NEXT
|
|
|
|
#define CHIP8_KEY6 BUTTON_PREV
|
|
|
|
#define CHIP8_KEY7 BUTTON_SELECT
|
|
|
|
#define CHIP8_KEY8 BUTTON_VOL_DOWN
|
2011-10-02 16:05:16 +00:00
|
|
|
#define CHIP8_KEY9 BUTTON_VOL_UP
|
|
|
|
|
Initial commit of the Samsung YP-R0 port.
This port is a hybrid native/RaaA port. It runs on a embedded linux system,
but is the only application. It therefore can implement lots of stuff that
native targets also implement, while leveraging the underlying linux kernel.
The port is quite advanced. User interface, audio playback, plugins work
mostly fine. Missing is e.g. power mangement and USB (see SamsungYPR0 wiki page).
Included in utils/ypr0tools are scripts and programs required to generate
a patched firmware. The patched firmware has the rootfs modified to load
Rockbox. It includes a early/safe USB mode.
This port needs a new toolchain, one that includes glibc headers and libraries.
rockboxdev.sh can generate it, but e.g. codesourcey and distro packages may
also work.
Most of the initial effort is done by Lorenzo Miori and others (on ABI),
including reverse engineering and patching of the original firmware,
initial drivers, and more. Big thanks to you.
Flyspray: FS#12348
Author: Lorenzo Miori, myself
Merry christmas to ypr0 owners! :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31415 a1c6a512-1295-4272-9138-f99709370657
2011-12-24 11:56:46 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
|
|
|
|
#define CHIP8_OFF (BUTTON_BACK|BUTTON_REPEAT)
|
|
|
|
#define CHIP8_KEY1 BUTTON_MENU
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY3 BUTTON_DOWN
|
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY7 BUTTON_BACK
|
|
|
|
#define CHIP8_KEY8 BUTTON_POWER
|
|
|
|
#define CHIP8_KEY9 BUTTON_USER
|
|
|
|
|
2012-03-23 18:32:50 +00:00
|
|
|
#elif (CONFIG_KEYPAD == HM60X_PAD)
|
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY4 BUTTON_DOWN
|
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY8 BUTTON_LEFT
|
|
|
|
|
2014-06-30 18:24:15 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SONY_NWZ_PAD)
|
|
|
|
#define CHIP8_OFF BUTTON_BACK
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY4 BUTTON_DOWN
|
|
|
|
#define CHIP8_KEY5 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY8 BUTTON_LEFT
|
|
|
|
|
2014-07-17 08:40:17 +00:00
|
|
|
#elif (CONFIG_KEYPAD == CREATIVE_ZEN_PAD)
|
|
|
|
#define CHIP8_OFF BUTTON_BACK
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY4 BUTTON_DOWN
|
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY8 BUTTON_LEFT
|
|
|
|
|
2012-04-06 16:17:27 +00:00
|
|
|
#elif (CONFIG_KEYPAD == HM801_PAD)
|
|
|
|
#define CHIP8_OFF (BUTTON_POWER|BUTTON_SELECT)
|
|
|
|
#define CHIP8_KEY1 BUTTON_PREV
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY3 BUTTON_DOWN
|
|
|
|
#define CHIP8_KEY4 BUTTON_LEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY7 BUTTON_NEXT
|
|
|
|
#define CHIP8_KEY8 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY9 BUTTON_POWER
|
|
|
|
|
2014-08-30 11:15:53 +00:00
|
|
|
#elif (CONFIG_KEYPAD == DX50_PAD)
|
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
|
2018-02-22 22:42:29 +00:00
|
|
|
#elif CONFIG_KEYPAD == CREATIVE_ZENXFI2_PAD
|
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY1 BUTTON_TOPLEFT
|
|
|
|
#define CHIP8_KEY2 BUTTON_TOPMIDDLE
|
|
|
|
#define CHIP8_KEY3 BUTTON_TOPRIGHT
|
|
|
|
#define CHIP8_KEY4 BUTTON_MIDLEFT
|
|
|
|
#define CHIP8_KEY5 BUTTON_CENTER
|
|
|
|
#define CHIP8_KEY6 BUTTON_MIDRIGHT
|
|
|
|
#define CHIP8_KEY7 BUTTON_BOTTOMLEFT
|
|
|
|
#define CHIP8_KEY8 BUTTON_BOTTOMMIDDLE
|
|
|
|
#define CHIP8_KEY9 BUTTON_BOTTOMRIGHT
|
|
|
|
|
2018-03-02 20:53:55 +00:00
|
|
|
#elif (CONFIG_KEYPAD == AGPTEK_ROCKER_PAD)
|
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY2 BUTTON_UP
|
|
|
|
#define CHIP8_KEY4 BUTTON_DOWN
|
|
|
|
#define CHIP8_KEY5 BUTTON_SELECT
|
|
|
|
#define CHIP8_KEY6 BUTTON_RIGHT
|
|
|
|
#define CHIP8_KEY8 BUTTON_LEFT
|
|
|
|
|
2020-10-08 13:47:40 +00:00
|
|
|
#elif CONFIG_KEYPAD == XDUOO_X3_PAD || CONFIG_KEYPAD == XDUOO_X3II_PAD || CONFIG_KEYPAD == XDUOO_X20_PAD
|
2018-11-05 12:01:55 +00:00
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY2 BUTTON_HOME
|
|
|
|
#define CHIP8_KEY4 BUTTON_PREV
|
|
|
|
#define CHIP8_KEY5 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY6 BUTTON_NEXT
|
|
|
|
#define CHIP8_KEY8 BUTTON_OPTION
|
|
|
|
|
2020-10-03 22:17:11 +00:00
|
|
|
#elif CONFIG_KEYPAD == FIIO_M3K_PAD
|
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY2 BUTTON_HOME
|
|
|
|
#define CHIP8_KEY4 BUTTON_PREV
|
|
|
|
#define CHIP8_KEY5 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY6 BUTTON_NEXT
|
|
|
|
#define CHIP8_KEY8 BUTTON_OPTION
|
|
|
|
|
2020-10-08 13:47:40 +00:00
|
|
|
#elif CONFIG_KEYPAD == IHIFI_770_PAD || CONFIG_KEYPAD == IHIFI_800_PAD
|
2018-06-29 20:09:28 +00:00
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY2 BUTTON_NEXT
|
|
|
|
#define CHIP8_KEY4 BUTTON_HOME
|
|
|
|
#define CHIP8_KEY5 BUTTON_VOL_UP
|
|
|
|
#define CHIP8_KEY6 BUTTON_VOL_DOWN
|
|
|
|
#define CHIP8_KEY8 BUTTON_PREV
|
|
|
|
|
2020-10-08 13:47:40 +00:00
|
|
|
#elif CONFIG_KEYPAD == EROSQ_PAD
|
2018-06-29 20:09:28 +00:00
|
|
|
#define CHIP8_OFF BUTTON_POWER
|
|
|
|
#define CHIP8_KEY2 BUTTON_NEXT
|
2020-10-08 13:47:40 +00:00
|
|
|
#define CHIP8_KEY4 BUTTON_MENU
|
|
|
|
#define CHIP8_KEY5 BUTTON_PLAY
|
|
|
|
#define CHIP8_KEY6 BUTTON_BACK
|
2018-06-29 20:09:28 +00:00
|
|
|
#define CHIP8_KEY8 BUTTON_PREV
|
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#else
|
|
|
|
#error No keymap defined!
|
2005-07-06 18:38:25 +00:00
|
|
|
#endif
|
|
|
|
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2008-04-27 15:30:19 +00:00
|
|
|
#ifndef CHIP8_OFF
|
|
|
|
#define CHIP8_OFF BUTTON_TOPLEFT
|
|
|
|
#endif
|
|
|
|
#ifndef CHIP8_KEY1
|
|
|
|
#define CHIP8_KEY1 BUTTON_TOPRIGHT
|
|
|
|
#endif
|
|
|
|
#ifndef CHIP8_KEY2
|
|
|
|
#define CHIP8_KEY2 BUTTON_TOPMIDDLE
|
|
|
|
#endif
|
|
|
|
#ifndef CHIP8_KEY3
|
|
|
|
#define CHIP8_KEY3 BUTTON_BOTTOMLEFT
|
|
|
|
#endif
|
|
|
|
#ifndef CHIP8_KEY4
|
|
|
|
#define CHIP8_KEY4 BUTTON_MIDLEFT
|
|
|
|
#endif
|
|
|
|
#ifndef CHIP8_KEY5
|
|
|
|
#define CHIP8_KEY5 BUTTON_CENTER
|
|
|
|
#endif
|
|
|
|
#ifndef CHIP8_KEY6
|
|
|
|
#define CHIP8_KEY6 BUTTON_MIDRIGHT
|
|
|
|
#endif
|
|
|
|
#ifndef CHIP8_KEY7
|
|
|
|
#define CHIP8_KEY7 BUTTON_BOTTOMRIGHT
|
|
|
|
#endif
|
|
|
|
#ifndef CHIP8_KEY8
|
|
|
|
#define CHIP8_KEY8 BUTTON_BOTTOMMIDDLE
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2005-07-06 18:38:25 +00:00
|
|
|
static byte chip8_virtual_keys[16];
|
|
|
|
static byte chip8_keymap[16];
|
|
|
|
|
|
|
|
static unsigned long starttimer; /* Timer value at the beginning */
|
|
|
|
static unsigned long cycles; /* Number of update cycles (50Hz) */
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* Turn sound on */
|
|
|
|
/****************************************************************************/
|
2020-10-08 13:47:40 +00:00
|
|
|
static void chip8_sound_on (void)
|
2005-07-06 18:38:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* Turn sound off */
|
|
|
|
/****************************************************************************/
|
2020-10-08 13:47:40 +00:00
|
|
|
static void chip8_sound_off (void)
|
|
|
|
{
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* Update the display */
|
|
|
|
/****************************************************************************/
|
|
|
|
static void chip8_update_display(void)
|
|
|
|
{
|
|
|
|
int x, lcd_x, y, i;
|
|
|
|
byte w;
|
|
|
|
byte* row;
|
|
|
|
/* frame buffer in hardware fomat */
|
|
|
|
unsigned char lcd_framebuf[CHIP8_HEIGHT/8][CHIP8_LCDWIDTH];
|
|
|
|
|
|
|
|
for (y=0;y<CHIP8_HEIGHT/8;++y)
|
|
|
|
{
|
|
|
|
row = lcd_framebuf[y];
|
|
|
|
for (x=0, lcd_x=0;x<CHIP8_WIDTH;++x,++lcd_x)
|
|
|
|
{
|
|
|
|
w = 0;
|
|
|
|
for (i=0;i<8;i++)
|
|
|
|
{
|
|
|
|
w = w >> 1;
|
|
|
|
if (chip8_display[x+(y*8+i)*CHIP8_WIDTH] != 0)
|
|
|
|
{
|
|
|
|
w += 128;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if (CHIP8_LCDWIDTH < 128) /* LCD_WIDTH between 112 and 127 */
|
|
|
|
if (x%8 == 1) {
|
|
|
|
row[-1] |= w; /* overlay on */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
*row++ = w;
|
|
|
|
}
|
|
|
|
}
|
2010-06-21 17:10:22 +00:00
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_HOSTED) || (LCD_DEPTH >= 4)
|
2005-07-06 18:38:25 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2008-03-24 00:35:53 +00:00
|
|
|
rb->lcd_mono_bitmap(lcd_framebuf[0], CHIP8_X, CHIP8_Y, CHIP8_LCDWIDTH,
|
|
|
|
CHIP8_HEIGHT);
|
2005-07-06 18:38:25 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
#else
|
2008-03-24 00:35:53 +00:00
|
|
|
rb->lcd_blit_mono(lcd_framebuf[0], CHIP8_X, CHIP8_Y>>3, CHIP8_LCDWIDTH,
|
|
|
|
CHIP8_HEIGHT>>3, CHIP8_LCDWIDTH);
|
2005-07-06 18:38:25 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void chip8_keyboard(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int button = rb->button_get(false);
|
|
|
|
switch (button)
|
|
|
|
{
|
2006-06-30 16:43:47 +00:00
|
|
|
#ifdef CHIP8_RC_OFF
|
|
|
|
case CHIP8_RC_OFF:
|
|
|
|
#endif
|
2005-12-14 01:31:37 +00:00
|
|
|
case CHIP8_OFF: /* Abort Emulator */
|
2005-07-06 18:38:25 +00:00
|
|
|
chip8_running = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHIP8_KEY2: chip8_virtual_keys[2] = 1; break;
|
|
|
|
case CHIP8_KEY2 | BUTTON_REL: chip8_virtual_keys[2] = 0; break;
|
|
|
|
case CHIP8_KEY4: chip8_virtual_keys[4] = 1; break;
|
|
|
|
case CHIP8_KEY4 | BUTTON_REL: chip8_virtual_keys[4] = 0; break;
|
|
|
|
case CHIP8_KEY6: chip8_virtual_keys[6] = 1; break;
|
|
|
|
case CHIP8_KEY6 | BUTTON_REL: chip8_virtual_keys[6] = 0; break;
|
|
|
|
case CHIP8_KEY8: chip8_virtual_keys[8] = 1; break;
|
|
|
|
case CHIP8_KEY8 | BUTTON_REL: chip8_virtual_keys[8] = 0; break;
|
|
|
|
case CHIP8_KEY5: chip8_virtual_keys[5] = 1; break;
|
|
|
|
case CHIP8_KEY5 | BUTTON_REL: chip8_virtual_keys[5] = 0; break;
|
|
|
|
#ifdef CHIP8_KEY1
|
|
|
|
case CHIP8_KEY1: chip8_virtual_keys[1] = 1; break;
|
|
|
|
case CHIP8_KEY1 | BUTTON_REL: chip8_virtual_keys[1] = 0; break;
|
|
|
|
#endif
|
|
|
|
#ifdef CHIP8_KEY3
|
|
|
|
case CHIP8_KEY3: chip8_virtual_keys[3] = 1; break;
|
|
|
|
case CHIP8_KEY3 | BUTTON_REL: chip8_virtual_keys[3] = 0; break;
|
|
|
|
#endif
|
|
|
|
#ifdef CHIP8_KEY7
|
|
|
|
case CHIP8_KEY7: chip8_virtual_keys[7] = 1; break;
|
|
|
|
case CHIP8_KEY7 | BUTTON_REL: chip8_virtual_keys[7] = 0; break;
|
|
|
|
#endif
|
|
|
|
#ifdef CHIP8_KEY9
|
|
|
|
case CHIP8_KEY9: chip8_virtual_keys[9] = 1; break;
|
|
|
|
case CHIP8_KEY9 | BUTTON_REL: chip8_virtual_keys[9] = 0; break;
|
|
|
|
#endif
|
2015-07-12 22:48:41 +00:00
|
|
|
#ifdef CHIP8_KEYA
|
|
|
|
case CHIP8_KEYA: chip8_virtual_keys[10] = 1; break;
|
|
|
|
case CHIP8_KEYA | BUTTON_REL: chip8_virtual_keys[10] = 0; break;
|
|
|
|
#endif
|
2005-07-06 18:38:25 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
chip8_running = 2; /* indicates stopped because of USB */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for(i=0; i<16; i++) {
|
|
|
|
chip8_keys[i] = chip8_virtual_keys[chip8_keymap[i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* Update keyboard and display, sync emulation with VDP clock */
|
|
|
|
/****************************************************************************/
|
|
|
|
static void chip8_interrupt (void)
|
|
|
|
{
|
2010-01-03 13:01:19 +00:00
|
|
|
unsigned long current_tick;
|
2005-07-06 18:38:25 +00:00
|
|
|
unsigned long timer, runtime;
|
|
|
|
|
|
|
|
chip8_update_display();
|
|
|
|
chip8_keyboard();
|
|
|
|
cycles ++;
|
|
|
|
runtime = cycles * HZ / 50;
|
|
|
|
timer = starttimer + runtime;
|
2010-01-03 13:01:19 +00:00
|
|
|
current_tick = *rb->current_tick;
|
|
|
|
if (TIME_AFTER(timer, current_tick))
|
2005-07-06 18:38:25 +00:00
|
|
|
{
|
2010-01-03 13:01:19 +00:00
|
|
|
rb->sleep(timer - current_tick);
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-02 22:51:29 +00:00
|
|
|
rb->yield();
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 09:57:56 +00:00
|
|
|
static bool chip8_init(const char* file)
|
2003-10-30 23:47:34 +00:00
|
|
|
{
|
|
|
|
int numread;
|
|
|
|
int fd;
|
2005-07-06 18:38:25 +00:00
|
|
|
int len;
|
|
|
|
int i;
|
2003-10-30 23:47:34 +00:00
|
|
|
|
|
|
|
fd = rb->open(file, O_RDONLY);
|
2009-12-06 13:52:28 +00:00
|
|
|
if (fd < 0) {
|
2010-01-02 22:51:29 +00:00
|
|
|
rb->lcd_puts(0, 6, "File Error.");
|
|
|
|
return false;
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
2003-10-30 23:47:34 +00:00
|
|
|
numread = rb->read(fd, chip8_mem+0x200, 4096-0x200);
|
2010-01-03 13:01:19 +00:00
|
|
|
rb->close(fd);
|
2005-07-06 18:38:25 +00:00
|
|
|
if (numread==-1) {
|
2010-01-02 22:51:29 +00:00
|
|
|
rb->lcd_puts(0, 6, "I/O Error.");
|
|
|
|
return false;
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
2003-10-30 23:47:34 +00:00
|
|
|
|
2005-07-06 18:38:25 +00:00
|
|
|
/* is there a c8k file (chip8 keys) ? */
|
2008-05-13 09:57:56 +00:00
|
|
|
char c8kname[MAX_PATH];
|
|
|
|
rb->strcpy(c8kname, file);
|
2005-07-06 18:38:25 +00:00
|
|
|
for(i=0; i<16; i++) {
|
2010-01-02 22:51:29 +00:00
|
|
|
chip8_virtual_keys[i] = 0;
|
|
|
|
chip8_keymap[i] = i;
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
2008-05-13 09:57:56 +00:00
|
|
|
len = rb->strlen(c8kname);
|
|
|
|
c8kname[len-2] = '8';
|
|
|
|
c8kname[len-1] = 'k';
|
|
|
|
fd = rb->open(c8kname, O_RDONLY);
|
2009-12-06 13:52:28 +00:00
|
|
|
if (fd >= 0) {
|
2010-01-02 22:51:29 +00:00
|
|
|
rb->lcd_puts(0, 6, "File&Keymap OK.");
|
|
|
|
numread = rb->read(fd, chip8_keymap, 16);
|
|
|
|
rb->close(fd);
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-02 22:51:29 +00:00
|
|
|
rb->lcd_puts(0, 6, "File OK.");
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
|
|
|
for(i=0; i<16; i++) {
|
2010-01-02 22:51:29 +00:00
|
|
|
if (chip8_keymap[i] >= '0'
|
|
|
|
&& chip8_keymap[i] <= '9')
|
|
|
|
chip8_keymap[i] -= '0';
|
|
|
|
else if (chip8_keymap[i] >= 'A'
|
|
|
|
&& chip8_keymap[i] <= 'F')
|
|
|
|
chip8_keymap[i] -= 'A' - 10;
|
|
|
|
else if (chip8_keymap[i] >= 'a'
|
|
|
|
&& chip8_keymap[i] <= 'f')
|
|
|
|
chip8_keymap[i] -= 'a' - 10;
|
|
|
|
else
|
|
|
|
chip8_keymap[i] %= 16;
|
2005-07-06 18:38:25 +00:00
|
|
|
}
|
2003-10-30 23:47:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-03 13:01:19 +00:00
|
|
|
static bool chip8_run(const char* file)
|
2003-10-30 23:47:34 +00:00
|
|
|
{
|
|
|
|
int ok;
|
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
2005-07-06 18:38:25 +00:00
|
|
|
rb->lcd_puts(0, 0, "SChip8 Emulator");
|
2003-10-30 23:47:34 +00:00
|
|
|
rb->lcd_puts(0, 1, " (c) by ");
|
|
|
|
rb->lcd_puts(0, 2, "Marcel de Kogel");
|
2005-07-06 18:38:25 +00:00
|
|
|
rb->lcd_puts(0, 3, " Rockbox: ");
|
|
|
|
rb->lcd_puts(0, 4, " Blueloop/Fdy ");
|
2003-10-30 23:47:34 +00:00
|
|
|
rb->lcd_puts(0, 5, "---------------");
|
2005-07-06 18:38:25 +00:00
|
|
|
ok = chip8_init(file);
|
2003-10-30 23:47:34 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
rb->sleep(HZ*1);
|
2005-07-06 18:38:25 +00:00
|
|
|
if (!ok)
|
|
|
|
return false;
|
2003-10-30 23:47:34 +00:00
|
|
|
rb->lcd_clear_display();
|
2005-07-06 18:38:25 +00:00
|
|
|
#if (CHIP8_X > 0) && (CHIP8_Y > 0)
|
|
|
|
rb->lcd_drawrect(CHIP8_X-1,CHIP8_Y-1,CHIP8_LCDWIDTH+2,CHIP8_HEIGHT+2);
|
|
|
|
#endif
|
2003-10-30 23:47:34 +00:00
|
|
|
rb->lcd_update();
|
2005-07-06 18:38:25 +00:00
|
|
|
starttimer = *rb->current_tick;
|
2004-01-30 22:43:37 +00:00
|
|
|
|
2005-07-06 18:38:25 +00:00
|
|
|
chip8_iperiod=15;
|
|
|
|
cycles = 0;
|
|
|
|
chip8();
|
2003-10-30 23:47:34 +00:00
|
|
|
|
2005-07-06 18:38:25 +00:00
|
|
|
if (chip8_running == 3) {
|
2010-01-02 22:51:29 +00:00
|
|
|
/* unsupported instruction */
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "Error: Unsupported"
|
2005-07-06 18:38:25 +00:00
|
|
|
#ifndef CHIP8_SUPER
|
2010-01-02 22:51:29 +00:00
|
|
|
" CHIP-8 instruction. (maybe S-CHIP)"
|
2005-07-06 18:38:25 +00:00
|
|
|
#else
|
|
|
|
" (S)CHIP-8 instruction."
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
return false;
|
2004-01-30 22:43:37 +00:00
|
|
|
}
|
|
|
|
|
2003-10-30 23:47:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************** Plugin Entry Point *****************/
|
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2003-10-30 23:47:34 +00:00
|
|
|
{
|
2008-05-13 09:57:56 +00:00
|
|
|
const char* filename;
|
2003-10-30 23:47:34 +00:00
|
|
|
|
|
|
|
if (parameter == NULL)
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "Play a .ch8 file!");
|
2003-10-30 23:47:34 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 13:47:40 +00:00
|
|
|
filename = (char*) parameter;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* now go ahead and have fun! */
|
2004-10-17 00:54:09 +00:00
|
|
|
if (chip8_run(filename))
|
|
|
|
if (chip8_running == 0)
|
|
|
|
return PLUGIN_OK;
|
|
|
|
else
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
else
|
|
|
|
return PLUGIN_ERROR;
|
2003-10-30 23:47:34 +00:00
|
|
|
}
|