다마고치 연구소 한국어판 소스 공개
This commit is contained in:
commit
db23855630
661 files changed
+503597
No files matched your search
@@ -0,0 +1,81 @@
|
||||
/* Host: boot the V7 ROM, press keys, save screenshots. hrun <rom> [figure]; stdin: p A|B|C [s] | w s | s file | q */
|
||||
#include "../src/core/t7.h"
|
||||
#include <stdio.h>
|
||||
#include "../src/core/t7_internal.h"
|
||||
void host_set_rom(unsigned char *p, size_t n);
|
||||
void figure_rom_set_active(const unsigned char* p, unsigned int n);
|
||||
static unsigned char *rd(const char *f, size_t *n){ FILE*x=fopen(f,"rb"); fseek(x,0,2); *n=ftell(x); fseek(x,0,0); unsigned char*p=malloc(*n); if(fread(p,1,*n,x)){} fclose(x); return p; }
|
||||
#ifdef T7_STOP_DBG
|
||||
static long g_step; void t7_stop_dbg(int w){ static int n; if (getenv("SDBG") && n++ < 400) fprintf(stderr, "step %ld STOP 3007=%02x 3008=%02x keys=%x halted=%d irqmask=%02x%02x nmi=%02x\n", g_step, g_cpureg[7], g_cpureg[8], g_keys, g_t7_halted, g_cpureg[0x70], g_cpureg[0x71], g_cpureg[0x76]); (void)w; }
|
||||
#endif
|
||||
#ifdef T7_EEDBG
|
||||
static double g_now; void t7_eedbg(uint16_t a, uint8_t v){ static double last=-1; if (getenv("EEDBG") && g_now != last) { fprintf(stderr, "ee write at %.2f s: %03x=%02x\n", g_now, a, v); last = g_now; } }
|
||||
#endif
|
||||
static void frames(double s){ static int cyc; if(!cyc) cyc=getenv("CYC")?atoi(getenv("CYC")):40000; int n=(int)(s*100+0.5); for(int i=0;i<n;i++) { t7_step_cycles(cyc);
|
||||
#ifdef T7_EEDBG
|
||||
g_now += 0.01;
|
||||
#endif
|
||||
} }
|
||||
static void shot(const char *f){ uint8_t d[48*31], ic[10]; t7_get_display(d); t7_get_icons(ic);
|
||||
static const int pal[4]={0xE0,0xA0,0x60,0x20}; FILE*o=fopen(f,"wb"); fprintf(o,"P6 192 140 255\n");
|
||||
for(int y=0;y<140;y++) for(int x=0;x<192;x++){ int v=0xF0;
|
||||
if(y>=8&&y<132){ int yy=(y-8)/4, xx=x/4; if(yy<31) v=pal[d[yy*48+xx]]; }
|
||||
else { int k=x/(192/5)+(y>=132?5:0); v=ic[k]?pal[ic[k]]:0xF0; }
|
||||
fputc(v,o); fputc(v,o); fputc(v,o);} fclose(o); }
|
||||
int main(int c, char **v){ size_t n; unsigned char *rom=rd(v[1],&n); host_set_rom(rom,n);
|
||||
if(c>2){ size_t fn; unsigned char*f=rd(v[2],&fn); figure_rom_set_active(f,(unsigned)fn); t7_figure_set(1); }
|
||||
if (getenv("EE")) { size_t en; unsigned char *e=rd(getenv("EE"),&en); extern void persist_restore_page(int,const uint8_t*); for (int i=0;i<16 && (size_t)(i+1)*256<=en;i++) persist_restore_page(i,e+i*256); } /* EE=save: EEPROM from a file */
|
||||
if(!t7_init()){ printf("init failed\n"); return 1; }
|
||||
if (getenv("SND")) { extern void t7_snd_set_mode(int); t7_snd_set_mode(1); }
|
||||
#ifdef T7_JSR_HLE
|
||||
if (getenv("DARK")) g_t7_dark = 1; /* screen off as on the device */
|
||||
#endif
|
||||
char l[256]; while(fgets(l,sizeof l,stdin)){ char cmd[16],a[200]; double x=0; int k=sscanf(l,"%15s %199s %lf",cmd,a,&x); if(k<1) continue;
|
||||
if(!strcmp(cmd,"p")){ t7_set_buttons(a[0]=='A'?1:a[0]=='B'?2:4); frames(0.2); t7_set_buttons(0); frames(k>2?x:0.8); }
|
||||
else if(!strcmp(cmd,"w")) frames(atof(a));
|
||||
else if(!strcmp(cmd,"tl")){ /* tl <s>: tone list in 2 ms steps (hz x steps) */ extern uint32_t t7_snd_tone_hz(uint8_t*); uint32_t last=0xFFFFFFFF; int n=0; int m=(int)(atof(a)*500+0.5);
|
||||
for(int i=0;i<m;i++){ t7_step_cycles(8000); uint8_t lv; uint32_t hz=t7_snd_tone_hz(&lv); if(hz!=last){ if(n) printf("%u x%d\n",last,n); last=hz; n=0; } n++; } printf("%u x%d\nEND\n",last,n); }
|
||||
else if(!strcmp(cmd,"k")){ double g=0; sscanf(l,"%*s %*s %lf %lf",&x,&g); int m=a[0]=='A'?1:a[0]=='B'?2:4; /* k A hold gap: a quick press in 2 ms steps */
|
||||
t7_set_buttons(m); for(int i=0;i<(int)(x*500+0.5);i++) { t7_step_cycles(8000);
|
||||
#ifdef T7_STOP_DBG
|
||||
g_step++; if (getenv("TL")) fputc(g_t7_halted ? 'h' : 'r', stderr);
|
||||
#endif
|
||||
}
|
||||
#ifdef T7_STOP_DBG
|
||||
if (getenv("TL")) fputc('|', stderr);
|
||||
#endif
|
||||
t7_set_buttons(0); for(int i=0;i<(int)(g*500+0.5);i++) { t7_step_cycles(8000);
|
||||
#ifdef T7_STOP_DBG
|
||||
if (getenv("TL")) fputc(g_t7_halted ? 'H' : 'R', stderr);
|
||||
#endif
|
||||
}
|
||||
#ifdef T7_STOP_DBG
|
||||
if (getenv("TL")) fputc('\n', stderr);
|
||||
#endif
|
||||
}
|
||||
#ifdef T7_JSR_HLE
|
||||
else if(!strcmp(cmd,"dk")){ g_t7_dark=(uint8_t)atoi(a); } /* dk 1|0: screen off/on */
|
||||
#ifdef T7_WAKE_FRESH
|
||||
else if(!strcmp(cmd,"wake")){ extern uint32_t g_t7_blits; uint32_t b0=g_t7_blits, bt=0; int t=0; g_t7_dark=0; /* wake: on as T7_WAKE_FRESH (light after a drawn picture) */
|
||||
for(;;){ t7_step_cycles(8000); t+=2; if(g_t7_blits!=b0){ b0=g_t7_blits; bt=t; } if((bt && t-bt>=20) || t>=700) break; }
|
||||
printf("wake light after %d ms\n", t); }
|
||||
else if(!strcmp(cmd,"peek")){ extern uint32_t g_t7_blits; uint32_t b0=g_t7_blits, bt=0; int t=0; g_t7_dark=0; /* peek: one picture with the screen dark, then dark again */
|
||||
for(;;){ t7_step_cycles(8000); t+=2; if(g_t7_blits!=b0){ b0=g_t7_blits; bt=t; } if((bt && t-bt>=20) || t>=700) break; }
|
||||
g_t7_dark=1; shot(a); printf("peek %d ms\n", t); }
|
||||
#endif
|
||||
#endif
|
||||
else if(!strcmp(cmd,"i")){ uint8_t ic[10]; t7_get_icons(ic); printf("icons"); for(int i=0;i<10;i++) printf(" %d",ic[i]); printf("\n"); }
|
||||
else if(!strcmp(cmd,"s")) shot(a);
|
||||
else if(!strcmp(cmd,"t")) printf("time %02d:%02d:%02d day %d.%d\n", t7_ram_read(0x306),t7_ram_read(0x307),t7_ram_read(t7_rtc_sec_addr()),t7_ram_read(0x305),t7_ram_read(0x304));
|
||||
else if(!strcmp(cmd,"poke")){ t7_ram_write((uint16_t)strtol(a,0,16),(uint8_t)x); }
|
||||
else if(!strcmp(cmd,"d")){ FILE*o=fopen(a,"wb"); fwrite(g_wram,1,T7_WRAM_SIZE,o); fclose(o); }
|
||||
else if(!strcmp(cmd,"r")){ int a0=(int)strtol(a,0,16), m=x>0?(int)x:1; printf("ram %03x:",a0); for(int i=0;i<m;i++) printf(" %02x",t7_ram_read((uint16_t)(a0+i))); printf("\n"); }
|
||||
#ifdef T7_BLIT_CACHE
|
||||
else if(!strcmp(cmd,"bc")){ extern uint32_t g_bc_hit, g_bc_miss; printf("blit cache hit %u miss %u\n", g_bc_hit, g_bc_miss);
|
||||
#ifdef T7_BC_LOG
|
||||
{ extern void bc_print(void); bc_print(); }
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
else if(!strcmp(cmd,"q")) break; fflush(stdout); }
|
||||
return 0; }
|
||||
Reference in new issue
Block a user