summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorKarl Kurbjun <kkurbjun@gmail.com>2006-06-19 01:47:45 +0000
committerKarl Kurbjun <kkurbjun@gmail.com>2006-06-19 01:47:45 +0000
commit6952f03a7dfef2424164762ecd98fb128b7e44eb (patch)
tree2fa98afcc33e145d3c88417be24eb58a6f90cc9a /apps/plugins
parentdb8316fa52ed8eeb55136bc3aad2c98b25d249fb (diff)
downloadrockbox-6952f03a7dfef2424164762ecd98fb128b7e44eb.tar.gz
rockbox-6952f03a7dfef2424164762ecd98fb128b7e44eb.zip
Update for Rockboy: - fix scaling for other color screens than H300 - full menu rewrite to display choices properly - some small tweaks to code - some formatting updates
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10137 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/rockboy/cpu.c7
-rw-r--r--apps/plugins/rockboy/cpucore.h12
-rw-r--r--apps/plugins/rockboy/cpuregs.h2
-rw-r--r--apps/plugins/rockboy/defs.h8
-rw-r--r--apps/plugins/rockboy/emu.c146
-rw-r--r--apps/plugins/rockboy/events.c8
-rw-r--r--apps/plugins/rockboy/fastmem.c4
-rw-r--r--apps/plugins/rockboy/hw.h8
-rw-r--r--apps/plugins/rockboy/lcd-gb.h2
-rw-r--r--apps/plugins/rockboy/lcd.c140
-rw-r--r--apps/plugins/rockboy/lcdc.c12
-rw-r--r--apps/plugins/rockboy/lcdc.h6
-rw-r--r--apps/plugins/rockboy/mem.h12
-rw-r--r--apps/plugins/rockboy/menu.c783
-rw-r--r--apps/plugins/rockboy/rc.h9
-rw-r--r--apps/plugins/rockboy/rcvars.c22
-rw-r--r--apps/plugins/rockboy/regs.h5
-rw-r--r--apps/plugins/rockboy/rockboy.c13
-rw-r--r--apps/plugins/rockboy/rockmacros.h2
-rw-r--r--apps/plugins/rockboy/sound.h11
-rw-r--r--apps/plugins/rockboy/sys_rockbox.c3
21 files changed, 453 insertions, 762 deletions
diff --git a/apps/plugins/rockboy/cpu.c b/apps/plugins/rockboy/cpu.c
index a09beafab6..3c295dcdf5 100644
--- a/apps/plugins/rockboy/cpu.c
+++ b/apps/plugins/rockboy/cpu.c
@@ -1,6 +1,3 @@
1
2
3
4#include "rockmacros.h" 1#include "rockmacros.h"
5#include "defs.h" 2#include "defs.h"
6#include "regs.h" 3#include "regs.h"
@@ -382,8 +379,8 @@ int cpu_emulate(int cycles)
382 byte op, cbop; 379 byte op, cbop;
383 int clen; 380 int clen;
384 static union reg acc; 381 static union reg acc;
385 static byte b; 382 static byte b IBSS_ATTR;
386 static word w; 383 static word w IBSS_ATTR;
387 384
388 i = cycles; 385 i = cycles;
389next: 386next:
diff --git a/apps/plugins/rockboy/cpucore.h b/apps/plugins/rockboy/cpucore.h
index a0c6a12f63..3e02f10c1a 100644
--- a/apps/plugins/rockboy/cpucore.h
+++ b/apps/plugins/rockboy/cpucore.h
@@ -276,15 +276,3 @@ static const byte daa_carry_table[64] ICONST_ATTR =
276 FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, 276 FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC,
277 FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, 00, FC, 277 FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, 00, FC,
278}; 278};
279
280
281
282
283
284
285
286
287
288
289
290
diff --git a/apps/plugins/rockboy/cpuregs.h b/apps/plugins/rockboy/cpuregs.h
index 3b7d5eda27..d741320d22 100644
--- a/apps/plugins/rockboy/cpuregs.h
+++ b/apps/plugins/rockboy/cpuregs.h
@@ -1,5 +1,3 @@
1
2
3#ifndef __CPUREGS_H__ 1#ifndef __CPUREGS_H__
4 2
5#define __CPUREGS_H__ 3#define __CPUREGS_H__
diff --git a/apps/plugins/rockboy/defs.h b/apps/plugins/rockboy/defs.h
index fc929635cf..e55e91deec 100644
--- a/apps/plugins/rockboy/defs.h
+++ b/apps/plugins/rockboy/defs.h
@@ -1,6 +1,3 @@
1
2
3
4#ifndef __DEFS_H__ 1#ifndef __DEFS_H__
5#define __DEFS_H__ 2#define __DEFS_H__
6 3
@@ -14,7 +11,6 @@
14#define HI 0 11#define HI 0
15#endif 12#endif
16 13
17
18typedef unsigned char byte; 14typedef unsigned char byte;
19 15
20typedef unsigned char un8; 16typedef unsigned char un8;
@@ -29,8 +25,4 @@ typedef un16 word;
29typedef word addr; 25typedef word addr;
30 26
31 27
32
33
34
35#endif 28#endif
36
diff --git a/apps/plugins/rockboy/emu.c b/apps/plugins/rockboy/emu.c
index b398bf497e..f639a62772 100644
--- a/apps/plugins/rockboy/emu.c
+++ b/apps/plugins/rockboy/emu.c
@@ -1,6 +1,3 @@
1
2
3
4#include "rockmacros.h" 1#include "rockmacros.h"
5#include "defs.h" 2#include "defs.h"
6#include "regs.h" 3#include "regs.h"
@@ -17,23 +14,15 @@ static int framecount;
17 14
18rcvar_t emu_exports[] = 15rcvar_t emu_exports[] =
19{ 16{
20 RCV_INT("framelen", &framelen), 17 RCV_INT("framelen", &framelen),
21 RCV_INT("framecount", &framecount), 18 RCV_INT("framecount", &framecount),
22 RCV_END 19 RCV_END
23}; 20};
24 21
25
26
27
28
29
30
31void emu_init(void) 22void emu_init(void)
32{ 23{
33
34} 24}
35 25
36
37/* 26/*
38 * emu_reset is called to initialize the state of the emulated 27 * emu_reset is called to initialize the state of the emulated
39 * system. It should set cpu registers, hardware registers, etc. to 28 * system. It should set cpu registers, hardware registers, etc. to
@@ -42,100 +31,79 @@ void emu_init(void)
42 31
43void emu_reset(void) 32void emu_reset(void)
44{ 33{
45 hw_reset(); 34 hw_reset();
46 lcd_reset(); 35 lcd_reset();
47 cpu_reset(); 36 cpu_reset();
48 mbc_reset(); 37 mbc_reset();
49 sound_reset(); 38 sound_reset();
50} 39}
51 40
52
53
54
55
56void emu_step(void) 41void emu_step(void)
57{ 42{
58 cpu_emulate(cpu.lcdc); 43 cpu_emulate(cpu.lcdc);
59} 44}
60 45
61struct options options;
62
63/* This mess needs to be moved to another module; it's just here to 46/* This mess needs to be moved to another module; it's just here to
64 * make things work in the mean time. */ 47 * make things work in the mean time. */
65//extern struct plugin_api* rb;
66void emu_run(void) 48void emu_run(void)
67{ 49{
68// void *timer = sys_timer(); 50// void *timer = sys_timer();
69 int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick; 51 int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick;
70// int delay; 52// int delay;
71 53
72 vid_begin(); 54 vid_begin();
73 lcd_begin(); 55 lcd_begin();
74#ifdef HAVE_ADJUSTABLE_CPU_FREQ 56#ifdef HAVE_ADJUSTABLE_CPU_FREQ
75 rb->cpu_boost(true); 57 rb->cpu_boost(true);
76#endif 58#endif
77 while(!shut) 59 while(!shut)
78 { 60 {
79 cpu_emulate(2280); 61 cpu_emulate(2280);
80 while (R_LY > 0 && R_LY < 144) 62 while (R_LY > 0 && R_LY < 144)
81 emu_step(); 63 emu_step();
82 64
83 rtc_tick(); 65 rtc_tick();
84 sound_mix(); 66 sound_mix();
85 if (!pcm_submit()) 67 if (!pcm_submit())
86 { 68 {
87/* delay = framelen - sys_elapsed(timer); 69/* delay = framelen - sys_elapsed(timer);
88 sys_sleep(delay); 70 sys_sleep(delay);
89 sys_elapsed(timer);*/ 71 sys_elapsed(timer);*/
90 } 72 }
91 73
92 doevents(); 74 doevents();
93 vid_begin(); 75 vid_begin();
94 76
95 if (!(R_LCDC & 0x80)) 77 if (!(R_LCDC & 0x80))
96 cpu_emulate(32832); 78 cpu_emulate(32832);
97 79
98 while (R_LY > 0) /* wait for next frame */ 80 while (R_LY > 0) /* wait for next frame */
99 emu_step(); 81 emu_step();
100 rb->yield(); 82 rb->yield();
101 83
102 frames++; 84 frames++;
103 framesin++; 85 framesin++;
104 86
105 if(*rb->current_tick-timeten>=20) 87 if(*rb->current_tick-timeten>=20)
106 { 88 {
107 timeten=*rb->current_tick; 89 timeten=*rb->current_tick;
108 if(framesin<12) options.frameskip++; 90 if(framesin<12) options.frameskip++;
109 if(framesin>12) options.frameskip--; 91 if(framesin>12) options.frameskip--;
110 if(options.frameskip>options.maxskip) options.frameskip=options.maxskip; 92 if(options.frameskip>options.maxskip) options.frameskip=options.maxskip;
111 if(options.frameskip<0) options.frameskip=0; 93 if(options.frameskip<0) options.frameskip=0;
112 framesin=0; 94 framesin=0;
113 } 95 }
114 96
115 if(options.showstats) 97 if(options.showstats)
116 { 98 if(*rb->current_tick-timehun>=100)
117 if(*rb->current_tick-timehun>=100) { 99 {
118 options.fps=frames; 100 options.fps=frames;
119 frames=0; 101 frames=0;
120 timehun=*rb->current_tick; 102 timehun=*rb->current_tick;
121 } 103 }
122 } 104 }
123
124 }
125 105
126#ifdef HAVE_ADJUSTABLE_CPU_FREQ 106#ifdef HAVE_ADJUSTABLE_CPU_FREQ
127 rb->cpu_boost(false); 107 rb->cpu_boost(false);
128#endif 108#endif
129} 109}
130
131
132
133
134
135
136
137
138
139
140
141
diff --git a/apps/plugins/rockboy/events.c b/apps/plugins/rockboy/events.c
index 5558dd86b2..5a34ce81e5 100644
--- a/apps/plugins/rockboy/events.c
+++ b/apps/plugins/rockboy/events.c
@@ -51,11 +51,3 @@ int ev_getevent(event_t *ev)
51 } 51 }
52 return 1; 52 return 1;
53} 53}
54
55
56
57
58
59
60
61
diff --git a/apps/plugins/rockboy/fastmem.c b/apps/plugins/rockboy/fastmem.c
index 7f5b0b445f..d883438ce1 100644
--- a/apps/plugins/rockboy/fastmem.c
+++ b/apps/plugins/rockboy/fastmem.c
@@ -14,7 +14,7 @@
14 14
15const byte himask[256]; 15const byte himask[256];
16 16
17const byte hi_rmap[256] ICONST_ATTR = 17const byte hi_rmap[256] =
18{ 18{
19 0, 0, R, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19 0, 0, R, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
20 S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, 20 S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
@@ -26,7 +26,7 @@ const byte hi_rmap[256] ICONST_ATTR =
26 C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 26 C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
27}; 27};
28 28
29const byte hi_wmap[256] ICONST_ATTR = 29const byte hi_wmap[256] =
30{ 30{
31 R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, 31 R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R,
32 S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, 32 S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
diff --git a/apps/plugins/rockboy/hw.h b/apps/plugins/rockboy/hw.h
index 5bc1230b3e..f1e632abdb 100644
--- a/apps/plugins/rockboy/hw.h
+++ b/apps/plugins/rockboy/hw.h
@@ -38,10 +38,10 @@ void hw_interrupt(byte i, byte mask) ICODE_ATTR;
38void hw_dma(byte b) ICODE_ATTR; 38void hw_dma(byte b) ICODE_ATTR;
39void hw_hdma_cmd(byte c) ICODE_ATTR; 39void hw_hdma_cmd(byte c) ICODE_ATTR;
40void hw_hdma(void) ICODE_ATTR; 40void hw_hdma(void) ICODE_ATTR;
41void pad_refresh(void)ICODE_ATTR; 41void pad_refresh(void) ICODE_ATTR;
42void pad_press(byte k)ICODE_ATTR; 42void pad_press(byte k) ICODE_ATTR;
43void pad_release(byte k)ICODE_ATTR; 43void pad_release(byte k) ICODE_ATTR;
44void pad_set(byte k, int st)ICODE_ATTR; 44void pad_set(byte k, int st) ICODE_ATTR;
45void hw_reset(void); 45void hw_reset(void);
46 46
47#endif 47#endif
diff --git a/apps/plugins/rockboy/lcd-gb.h b/apps/plugins/rockboy/lcd-gb.h
index c02e670dd2..aafeaec165 100644
--- a/apps/plugins/rockboy/lcd-gb.h
+++ b/apps/plugins/rockboy/lcd-gb.h
@@ -65,7 +65,7 @@ void spr_enum(void) ICODE_ATTR;
65void spr_scan(void) ICODE_ATTR; 65void spr_scan(void) ICODE_ATTR;
66void lcd_begin(void) ICODE_ATTR; 66void lcd_begin(void) ICODE_ATTR;
67void lcd_refreshline(void) ICODE_ATTR; 67void lcd_refreshline(void) ICODE_ATTR;
68void pal_write(int i, byte b); 68void pal_write(int i, byte b) ICODE_ATTR;
69void pal_write_dmg(int i, int mapnum, byte d) ICODE_ATTR; 69void pal_write_dmg(int i, int mapnum, byte d) ICODE_ATTR;
70void vram_write(int a, byte b) ICODE_ATTR; 70void vram_write(int a, byte b) ICODE_ATTR;
71void vram_dirty(void) ICODE_ATTR; 71void vram_dirty(void) ICODE_ATTR;
diff --git a/apps/plugins/rockboy/lcd.c b/apps/plugins/rockboy/lcd.c
index 55ae3eafba..f98b4f6935 100644
--- a/apps/plugins/rockboy/lcd.c
+++ b/apps/plugins/rockboy/lcd.c
@@ -1,5 +1,3 @@
1
2
3#include "rockmacros.h" 1#include "rockmacros.h"
4#include "defs.h" 2#include "defs.h"
5#include "regs.h" 3#include "regs.h"
@@ -102,9 +100,6 @@ fb_data *vdest;
102#define MEMCPY8(d, s) memcpy((d), (s), 8) 100#define MEMCPY8(d, s) memcpy((d), (s), 8)
103#endif 101#endif
104 102
105
106
107
108#ifndef ASM_UPDATEPATPIX 103#ifndef ASM_UPDATEPATPIX
109void updatepatpix(void) 104void updatepatpix(void)
110{ 105{
@@ -901,10 +896,11 @@ void spr_scan(void)
901// if (sprdebug) for (i = 0; i < NS; i++) BUF[i<<1] = 36; 896// if (sprdebug) for (i = 0; i < NS; i++) BUF[i<<1] = 36;
902} 897}
903 898
904 899// Scaling defines
905 900#define DX ((LCD_WIDTH<<16) / 160)
906 901#define DXI ((160<<16) / LCD_WIDTH)
907 902#define DY ((LCD_HEIGHT<<16) / 144)
903#define DYI ((144<<16) / LCD_HEIGHT)
908 904
909void lcd_begin(void) 905void lcd_begin(void)
910{ 906{
@@ -913,23 +909,70 @@ void lcd_begin(void)
913 if (rgb332) pal_set332(); 909 if (rgb332) pal_set332();
914 else pal_expire(); 910 else pal_expire();
915 } 911 }
916 while (scale * 160 > fb.w || scale * 144 > fb.h) scale--; */ 912*/
917 if(options.fullscreen) 913
918 vdest = fb.ptr; 914 if(options.fullscreen)
919 else 915 vdest = fb.ptr;
920 vdest = fb.ptr + ((LCD_HEIGHT-144)/2)*LCD_WIDTH + ((LCD_WIDTH-160)/2); 916 else
917 vdest=fb.ptr+((LCD_HEIGHT-144)/2)*LCD_WIDTH + ((LCD_WIDTH-160)/2);
921 918
922 WY = R_WY; 919 WY = R_WY;
923} 920}
924 921
925char frameout[25]; 922int SCALEWL IDATA_ATTR=DY;
926void lcd_refreshline(void) 923int SCALEWS IDATA_ATTR=DYI;
924int SCALEHL IDATA_ATTR=DY;
925int SCALEHS IDATA_ATTR=DYI;
926int swidth IDATA_ATTR=(160*DY)>>16;
927int sremain IDATA_ATTR=LCD_WIDTH-((160*DY)>>16);
928
929void setvidmode(int mode)
927{ 930{
928#if LCD_HEIGHT>=144 931 switch(mode)
929 int cnt=0, two; 932 {
933 case 1: /* Full screen scale */
934 SCALEWL=DX;
935 SCALEWS=DXI;
936 SCALEHL=DY;
937 SCALEHS=DYI;
938 break;
939 case 2: /* Maintain Ratio */
940 if (DY<DX)
941 {
942 SCALEWL=DY;
943 SCALEWS=DYI;
944 SCALEHL=DY;
945 SCALEHS=DYI;
946 }
947 else
948 {
949 SCALEWL=DX;
950 SCALEWS=DXI;
951 SCALEHL=DX;
952 SCALEHS=DXI;
953 }
954 break;
955 default: /* No Scaling (or fullscreen for smaller screens) */
956#if LCD_WIDTH>160
957 SCALEWL=1<<16;
958 SCALEWS=1<<16;
959 SCALEHL=1<<16;
960 SCALEHS=1<<16;
961#else
962 SCALEWL=DX;
963 SCALEWS=DXI;
964 SCALEHL=DY;
965 SCALEHS=DYI;
930#endif 966#endif
967 }
968 swidth=(160*SCALEWL)>>16;
969 sremain=LCD_WIDTH-swidth;
970}
971
931 972
932 if (!fb.enabled) return; 973char frameout[30];
974void lcd_refreshline(void)
975{
933 if(!insync) { 976 if(!insync) {
934 if(R_LY!=0) 977 if(R_LY!=0)
935 return; 978 return;
@@ -990,44 +1033,51 @@ void lcd_refreshline(void)
990 recolor(BUF+WX, 0x04, 160-WX); 1033 recolor(BUF+WX, 0x04, 160-WX);
991 } 1034 }
992 spr_scan(); 1035 spr_scan();
1036
1037#if !defined(HAVE_LCD_COLOR)
993#if LCD_DEPTH == 1 1038#if LCD_DEPTH == 1
994 if (scanline_ind == 7) 1039 if (scanline_ind == 7)
995#elif LCD_DEPTH == 2 1040#elif LCD_DEPTH == 2
996 if (scanline_ind == 3) 1041 if (scanline_ind == 3)
997#endif 1042#endif
998 { 1043 {
999#if LCD_HEIGHT < 144
1000 if(fb.mode!=3) 1044 if(fb.mode!=3)
1001 vid_update(L); 1045 vid_update(L);
1002 else 1046 else
1003 vid_update(L-((int)(L/9))); 1047 vid_update(L-((int)(L/9)));
1004#else 1048#else
1049 {
1050 /* Universial Scaling pulled from PrBoom and modified for rockboy */
1051 /* Needs some thought for screens smaller than the gameboy though */
1052
1053 static int hpt IDATA_ATTR=0x8000;
1054
1055 while((hpt>>16)<L+1)
1056 {
1057 hpt+=SCALEHS;
1058 register unsigned int srcpt=0x8000;
1059 register unsigned int wcount=swidth;
1060 register unsigned int remain=sremain;
1061 while(wcount--)
1062 {
1063 *vdest++ = scan.pal2[scan.buf[srcpt>>16]];
1064 srcpt+=SCALEWS;
1065 }
1066 vdest+=remain;
1067 }
1068
1069 if(L==143)
1070 {
1071 if(options.showstats)
1072 {
1073 snprintf(frameout,sizeof(frameout),"FPS: %d Frameskip: %d ",options.fps, options.frameskip);
1074 rb->lcd_putsxy(0,LCD_HEIGHT-10,frameout);
1075 }
1076
1077 hpt=0x8000;
1078 rb->lcd_update();
1079 }
1005 1080
1006 for(two=0;two<( (options.showstats ? (L&0x07)==0x05 : (L&0x07)==0x05 || (L&0x0F)==0x08) && options.fullscreen)+1;two++)
1007 {
1008 while (cnt < 160)
1009 {
1010 *vdest++ = scan.pal2[scan.buf[cnt++]];
1011 if( ((cnt&0x03)==0x03 || (cnt&0x07)==0x06) && options.fullscreen ) *vdest++ = scan.pal2[scan.buf[cnt]];
1012 }
1013
1014 if(!options.fullscreen)
1015 vdest+=(LCD_WIDTH-160);
1016 cnt=0;
1017 }
1018
1019 if(L==143)
1020 {
1021 if(options.showstats) {
1022 snprintf(frameout,sizeof(frameout),"FPS: %d \t %d ",options.fps, options.frameskip);
1023 if(options.fullscreen) rb->lcd_putsxy(0,166,frameout);
1024 else rb->lcd_putsxy((LCD_WIDTH-160)/2,(LCD_HEIGHT-144)/2,frameout);
1025 }
1026 if(options.fullscreen)
1027 rb->lcd_update();
1028 else
1029 rb->lcd_update_rect( (LCD_WIDTH-160)/2, (LCD_HEIGHT-144)/2, 160, 144 );
1030 }
1031#endif 1081#endif
1032 } 1082 }
1033#if LCD_DEPTH == 1 1083#if LCD_DEPTH == 1
diff --git a/apps/plugins/rockboy/lcdc.c b/apps/plugins/rockboy/lcdc.c
index 3c1cf9196d..3b7894d729 100644
--- a/apps/plugins/rockboy/lcdc.c
+++ b/apps/plugins/rockboy/lcdc.c
@@ -1,5 +1,3 @@
1
2
3#include "rockmacros.h" 1#include "rockmacros.h"
4 2
5#include "defs.h" 3#include "defs.h"
@@ -7,6 +5,7 @@
7#include "cpu-gb.h" 5#include "cpu-gb.h"
8#include "regs.h" 6#include "regs.h"
9#include "lcd-gb.h" 7#include "lcd-gb.h"
8#include "fb.h"
10 9
11 10
12#define C (cpu.lcdc) 11#define C (cpu.lcdc)
@@ -141,10 +140,11 @@ void lcdc_trans(void)
141 stat_trigger(); 140 stat_trigger();
142 break; 141 break;
143 case 2: 142 case 2:
144 lcd_refreshline(); 143 if (fb.enabled)
145 stat_change(3); 144 lcd_refreshline();
146 C += 86; 145 stat_change(3);
147 break; 146 C += 86;
147 break;
148 case 3: 148 case 3:
149 stat_change(0); 149 stat_change(0);
150 if (hw.hdma & 0x80) 150 if (hw.hdma & 0x80)
diff --git a/apps/plugins/rockboy/lcdc.h b/apps/plugins/rockboy/lcdc.h
index d8cb282e5a..9b6c80ea90 100644
--- a/apps/plugins/rockboy/lcdc.h
+++ b/apps/plugins/rockboy/lcdc.h
@@ -1,4 +1,4 @@
1void stat_trigger(void) ICODE_ATTR; 1void stat_trigger(void) ICODE_ATTR;
2void stat_write(byte b)ICODE_ATTR; 2void stat_write(byte b) ICODE_ATTR;
3void lcdc_change(byte b)ICODE_ATTR; 3void lcdc_change(byte b) ICODE_ATTR;
4void lcdc_trans(void)ICODE_ATTR; 4void lcdc_trans(void) ICODE_ATTR;
diff --git a/apps/plugins/rockboy/mem.h b/apps/plugins/rockboy/mem.h
index 36ea26e9f3..14d03d5ff5 100644
--- a/apps/plugins/rockboy/mem.h
+++ b/apps/plugins/rockboy/mem.h
@@ -1,4 +1,3 @@
1
2#ifndef __MEM_H__ 1#ifndef __MEM_H__
3#define __MEM_H__ 2#define __MEM_H__
4 3
@@ -48,10 +47,6 @@ extern struct mbc mbc;
48extern struct rom rom; 47extern struct rom rom;
49extern struct ram ram; 48extern struct ram ram;
50 49
51
52
53
54
55void mem_updatemap(void) ICODE_ATTR; 50void mem_updatemap(void) ICODE_ATTR;
56void ioreg_write(byte r, byte b) ICODE_ATTR; 51void ioreg_write(byte r, byte b) ICODE_ATTR;
57void mbc_write(int a, byte b) ICODE_ATTR; 52void mbc_write(int a, byte b) ICODE_ATTR;
@@ -60,7 +55,6 @@ byte mem_read(int a) ICODE_ATTR;
60void mbc_reset(void); 55void mbc_reset(void);
61 56
62 57
63
64#define READB(a) ( mbc.rmap[(a)>>12] \ 58#define READB(a) ( mbc.rmap[(a)>>12] \
65? mbc.rmap[(a)>>12][(a)] \ 59? mbc.rmap[(a)>>12][(a)] \
66: mem_read((a)) ) 60: mem_read((a)) )
@@ -71,10 +65,4 @@ void mbc_reset(void);
71: ( mem_write((a), (b)), (b) ) ) 65: ( mem_write((a), (b)), (b) ) )
72#define WRITEW(a, w) ( WRITEB((a), (w)&0xFF), WRITEB((a)+1, (w)>>8) ) 66#define WRITEW(a, w) ( WRITEB((a), (w)&0xFF), WRITEB((a)+1, (w)>>8) )
73 67
74
75
76
77#endif 68#endif
78
79
80
diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c
index 15f34582a6..e27be48e9b 100644
--- a/apps/plugins/rockboy/menu.c
+++ b/apps/plugins/rockboy/menu.c
@@ -4,8 +4,6 @@
4/* Note: this file only exposes one function: do_user_menu(). */ 4/* Note: this file only exposes one function: do_user_menu(). */
5/*********************************************************************/ 5/*********************************************************************/
6 6
7#include "stdlib.h"
8#include "string.h"
9#include "button.h" 7#include "button.h"
10#include "rockmacros.h" 8#include "rockmacros.h"
11#include "mem.h" 9#include "mem.h"
@@ -15,149 +13,68 @@
15#define MENU_BUTTON_DOWN BUTTON_SCROLL_FWD 13#define MENU_BUTTON_DOWN BUTTON_SCROLL_FWD
16#define MENU_BUTTON_LEFT BUTTON_LEFT 14#define MENU_BUTTON_LEFT BUTTON_LEFT
17#define MENU_BUTTON_RIGHT BUTTON_RIGHT 15#define MENU_BUTTON_RIGHT BUTTON_RIGHT
18#define MENU_BUTTON_CANCEL BUTTON_MENU
19#elif (CONFIG_KEYPAD == GIGABEAT_PAD) 16#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
20#define MENU_BUTTON_UP BUTTON_UP 17#define MENU_BUTTON_UP BUTTON_UP
21#define MENU_BUTTON_DOWN BUTTON_DOWN 18#define MENU_BUTTON_DOWN BUTTON_DOWN
22#define MENU_BUTTON_LEFT BUTTON_LEFT 19#define MENU_BUTTON_LEFT BUTTON_LEFT
23#define MENU_BUTTON_RIGHT BUTTON_RIGHT 20#define MENU_BUTTON_RIGHT BUTTON_RIGHT
24#define MENU_BUTTON_CANCEL BUTTON_A
25#else 21#else
26#define MENU_BUTTON_UP BUTTON_UP 22#define MENU_BUTTON_UP BUTTON_UP
27#define MENU_BUTTON_DOWN BUTTON_DOWN 23#define MENU_BUTTON_DOWN BUTTON_DOWN
28#define MENU_BUTTON_LEFT BUTTON_LEFT 24#define MENU_BUTTON_LEFT BUTTON_LEFT
29#define MENU_BUTTON_RIGHT BUTTON_RIGHT 25#define MENU_BUTTON_RIGHT BUTTON_RIGHT
30#define MENU_BUTTON_CANCEL BUTTON_OFF
31#endif 26#endif
32 27
28void setvidmode(int);
29
33/* load/save state function declarations */ 30/* load/save state function declarations */
34static void do_slot_menu(bool is_load);
35static void do_opt_menu(void); 31static void do_opt_menu(void);
32static void do_slot_menu(bool is_load);
36static void munge_name(char *buf, size_t bufsiz); 33static void munge_name(char *buf, size_t bufsiz);
37 34
38/* directory ROM save slots belong in */ 35/* directory ROM save slots belong in */
39#define STATE_DIR "/.rockbox/rockboy" 36#define STATE_DIR "/.rockbox/rockboy"
40 37
41#define MENU_CANCEL (-1)
42static int do_menu(char *title, char **items, size_t num_items, int sel_item);
43
44/* main menu items */
45#define MAIN_MENU_TITLE "Rockboy"
46typedef enum {
47 MM_ITEM_BACK,
48 MM_ITEM_LOAD,
49 MM_ITEM_SAVE,
50 MM_ITEM_OPT,
51 MM_ITEM_QUIT,
52 MM_ITEM_LAST
53} MainMenuItem;
54
55/* strings for the main menu */
56static const char *main_menu[] = {
57 "Back to Game",
58 "Load State...",
59 "Save State...",
60 "Options...",
61 "Quit RockBoy"
62};
63
64typedef enum {
65 SM_ITEM_SLOT1,
66 SM_ITEM_SLOT2,
67 SM_ITEM_SLOT3,
68 SM_ITEM_SLOT4,
69 SM_ITEM_SLOT5,
70 SM_ITEM_FILE,
71 SM_ITEM_BACK,
72 SM_ITEM_LAST
73} SlotMenuItem;
74
75/* this semi-evil, but we snprintf() into these strings later
76 * Note: if you want more save slots, just add more lines
77 * to this array */
78static const char *slot_menu[] = {
79 "1. ",
80 "2. ",
81 "3. ",
82 "4. ",
83 "5. ",
84 "Save to File... ",
85 "Previous Menu... "
86};
87
88#define OPT_MENU_TITLE "Options"
89typedef enum {
90 OM_ITEM_FS,
91 OM_ITEM_SOUND,
92 OM_ITEM_STATS,
93 OM_ITEM_FULLSCREEN,
94 OM_ITEM_KEYS,
95 OM_ITEM_BACK,
96 OM_MENU_LAST
97} OptMenuItem;
98
99static const char *opt_menu[] = {
100 "Frameskip",
101 "Sound ON/OFF",
102 "Stats ON/OFF",
103 "Fullscreen ON/OFF",
104 "Set Keys (BUGGY)",
105 "Previous Menu..."
106};
107
108#define FS_MENU_TITLE "Frameskip"
109typedef enum {
110 FS_ITEM_FS0,
111 FS_ITEM_FS1,
112 FS_ITEM_FS2,
113 FS_ITEM_FS3,
114 FS_ITEM_BACK,
115 FS_MENU_LAST
116} FSMenuItem;
117
118static const char *fs_menu[] = {
119 "Frameskip 3 Max",
120 "Frameskip 4 Max",
121 "Frameskip 5 Max",
122 "Frameskip 7 Max",
123 "Previous Menu..."
124};
125
126int getbutton(char *text) 38int getbutton(char *text)
127{ 39{
128 rb->lcd_putsxy(0, 0, text); 40 rb->lcd_putsxy(0, 0, text);
129 rb->lcd_update(); 41 rb->lcd_update();
130 rb->sleep(30); 42 rb->sleep(30);
131 while (rb->button_get(false) != BUTTON_NONE) 43
132 rb->yield(); 44 while (rb->button_get(false) != BUTTON_NONE)
133 int button; 45 rb->yield();
134 while(true){ 46
135 button = rb->button_get(true); 47 int button;
136 button=button&0x00000FFF; 48 while(true)
137 switch(button) { 49 {
138 case MENU_BUTTON_LEFT: 50 button = rb->button_get(true);
139 case MENU_BUTTON_RIGHT: 51 button=button&0x00000FFF;
140 case MENU_BUTTON_UP: 52
141 case MENU_BUTTON_DOWN: 53 switch(button)
142 break; 54 {
143 default: 55 case MENU_BUTTON_LEFT:
144 return button; 56 case MENU_BUTTON_RIGHT:
145 break; 57 case MENU_BUTTON_UP:
146 } 58 case MENU_BUTTON_DOWN:
147 } 59 break;
60 default:
61 return button;
62 break;
63 }
64 }
148} 65}
149 66
150void setupkeys(void) 67void setupkeys(void)
151{ 68{
152 options.A=getbutton("Press A"); 69 options.A=getbutton("Press A");
153 70
154 options.B=getbutton("Press B"); 71 options.B=getbutton("Press B");
155 72
156 options.START=getbutton("Press Start"); 73 options.START=getbutton("Press Start");
157 74
158 options.SELECT=getbutton("Press Select"); 75 options.SELECT=getbutton("Press Select");
159 76
160 options.MENU=getbutton("Press Menu"); 77 options.MENU=getbutton("Press Menu");
161} 78}
162 79
163/* 80/*
@@ -165,67 +82,74 @@ void setupkeys(void)
165 * 82 *
166 * Returns USER_MENU_QUIT if the user selected "quit", otherwise 83 * Returns USER_MENU_QUIT if the user selected "quit", otherwise
167 * returns zero. 84 * returns zero.
168 *
169 * Note: this is the only non-static function in this file at the
170 * moment. In the future I may turn do_menu/etc into a proper API, in
171 * which case they'll be exposed as well.
172 *
173 */ 85 */
174int do_user_menu(void) { 86int do_user_menu(void) {
175 int mi, ret, num_items; 87 bool done=false;
176 bool done = false; 88 int m, ret=0;
89 int result;
90
91 /* Clean out the button Queue */
92 while (rb->button_get(false) != BUTTON_NONE)
93 rb->yield();
94
95 static const struct menu_item items[] = {
96 {"Load Game", NULL },
97 {"Save Game", NULL },
98 {"Options", NULL },
99 {"Quit", NULL },
100 };
101
102 pcm_init();
103
104 m = rb->menu_init(items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL);
105
106 while(!done)
107 {
108 result=rb->menu_show(m);
109
110 switch (result)
111 {
112 case 0: /* Load Game */
113 do_slot_menu(true);
114 break;
115 case 1: /* Save Game */
116 do_slot_menu(false);
117 break;
118 case 2: /* Options */
119 do_opt_menu();
120 break;
121 case 3: /* Quit */
122 ret = USER_MENU_QUIT;
123 done=true;
124 break;
125 default:
126 done=true;
127 break;
128 }
129 }
177 130
178 pcm_init(); 131 rb->menu_exit(m);
179 132
180 /* set defaults */ 133 rb->lcd_setfont(0); /* Reset the font */
181 ret = 0; /* return value */ 134 rb->lcd_clear_display(); /* Clear display for screen size changes */
182 mi = 0; /* initial menu selection */ 135
183 num_items = sizeof(main_menu) / sizeof(char*); 136 return ret;
184
185 /* loop until we should exit menu */
186 while (!done) {
187 /* get item selection */
188 mi = do_menu(MAIN_MENU_TITLE, (char**) main_menu, num_items, mi);
189
190 /* handle selected menu item */
191 switch (mi) {
192 case MM_ITEM_QUIT:
193 ret = USER_MENU_QUIT;
194 case MENU_CANCEL:
195 case MM_ITEM_BACK:
196 done = true;
197 break;
198 case MM_ITEM_LOAD:
199 do_slot_menu(true);
200 break;
201 case MM_ITEM_SAVE:
202 do_slot_menu(false);
203 break;
204 case MM_ITEM_OPT:
205 do_opt_menu();
206 break;
207 }
208 }
209 rb->lcd_clear_display();
210 rb->lcd_update();
211 /* return somethin' */
212 return ret;
213} 137}
214 138
215/* 139/*
216 * munge_name - munge a string into a filesystem-safe name 140 * munge_name - munge a string into a filesystem-safe name
217 */ 141 */
218static void munge_name(char *buf, const size_t bufsiz) { 142static void munge_name(char *buf, const size_t bufsiz) {
219 unsigned int i, max; 143 unsigned int i, max;
220 144
221 /* check strlen */ 145 /* check strlen */
222 max = strlen(buf); 146 max = strlen(buf);
223 max = (max < bufsiz) ? max : bufsiz; 147 max = (max < bufsiz) ? max : bufsiz;
224 148
225 /* iterate over characters and munge them (if necessary) */ 149 /* iterate over characters and munge them (if necessary) */
226 for (i = 0; i < max; i++) 150 for (i = 0; i < max; i++)
227 if (!isalnum(buf[i])) 151 if (!isalnum(buf[i]))
228 buf[i] = '_'; 152 buf[i] = '_';
229} 153}
230 154
231/* 155/*
@@ -235,15 +159,15 @@ static void munge_name(char *buf, const size_t bufsiz) {
235 * checksum or something like that? 159 * checksum or something like that?
236 */ 160 */
237static void build_slot_path(char *buf, size_t bufsiz, size_t slot_id) { 161static void build_slot_path(char *buf, size_t bufsiz, size_t slot_id) {
238 char name_buf[40]; 162 char name_buf[40];
239 163
240 /* munge state file name */ 164 /* munge state file name */
241 strncpy(name_buf, rom.name, sizeof(name_buf)); 165 strncpy(name_buf, rom.name, 40);
242 name_buf[16] = '\0'; 166 name_buf[16] = '\0';
243 munge_name(name_buf, strlen(name_buf)); 167 munge_name(name_buf, strlen(name_buf));
244 168
245 /* glom the whole mess together */ 169 /* glom the whole mess together */
246 snprintf(buf, bufsiz, "%s/%s-%d.rbs", STATE_DIR, name_buf, slot_id + 1); 170 snprintf(buf, bufsiz, "%s/%s-%d.rbs", STATE_DIR, name_buf, slot_id + 1);
247} 171}
248 172
249/* 173/*
@@ -256,43 +180,46 @@ static void build_slot_path(char *buf, size_t bufsiz, size_t slot_id) {
256 * 180 *
257 */ 181 */
258static bool do_file(char *path, char *desc, bool is_load) { 182static bool do_file(char *path, char *desc, bool is_load) {
259 char buf[200], desc_buf[20]; 183 char buf[200], desc_buf[20];
260 int fd, file_mode; 184 int fd, file_mode;
261 185
262 /* set file mode */ 186 /* set file mode */
263 file_mode = is_load ? O_RDONLY : (O_WRONLY | O_CREAT); 187 file_mode = is_load ? O_RDONLY : (O_WRONLY | O_CREAT);
264 188
265 /* attempt to open file descriptor here */ 189 /* attempt to open file descriptor here */
266 if ((fd = open(path, file_mode)) <= 0) 190 if ((fd = open(path, file_mode)) <= 0)
267 return false; 191 return false;
268 192
269 /* load/save state */ 193 /* load/save state */
270 if (is_load) { 194 if (is_load)
271 /* load description */ 195 {
272 read(fd, desc_buf, 20); 196 /* load description */
273 197 read(fd, desc_buf, 20);
274 /* load state */ 198
275 loadstate(fd); 199 /* load state */
276 200 loadstate(fd);
277 /* print out a status message so the user knows the state loaded */ 201
278 snprintf(buf, sizeof(buf), "Loaded state from \"%s\"", path); 202 /* print out a status message so the user knows the state loaded */
279 rb->splash(HZ * 1, true, buf); 203 snprintf(buf, 200, "Loaded state from \"%s\"", path);
280 } else { 204 rb->splash(HZ * 1, true, buf);
281 /* build description buffer */ 205 }
282 memset(desc_buf, 0, sizeof(desc_buf)); 206 else
283 if (desc) 207 {
284 strncpy(desc_buf, desc, sizeof(desc_buf)); 208 /* build description buffer */
285 209 memset(desc_buf, 0, 20);
286 /* save state */ 210 if (desc)
287 write(fd, desc_buf, 20); 211 strncpy(desc_buf, desc, 20);
288 savestate(fd); 212
289 } 213 /* save state */
290 214 write(fd, desc_buf, 20);
291 /* close file descriptor */ 215 savestate(fd);
292 close(fd); 216 }
293 217
294 /* return true (for success) */ 218 /* close file descriptor */
295 return true; 219 close(fd);
220
221 /* return true (for success) */
222 return true;
296} 223}
297 224
298/* 225/*
@@ -301,339 +228,159 @@ static bool do_file(char *path, char *desc, bool is_load) {
301 * Returns true on success and false on failure. 228 * Returns true on success and false on failure.
302 */ 229 */
303static bool do_slot(size_t slot_id, bool is_load) { 230static bool do_slot(size_t slot_id, bool is_load) {
304 char path_buf[256], desc_buf[20]; 231 char path_buf[256], desc_buf[20];
305 232
306 /* build slot filename, clear desc buf */ 233 /* build slot filename, clear desc buf */
307 build_slot_path(path_buf, sizeof(path_buf), slot_id); 234 build_slot_path(path_buf, 256, slot_id);
308 memset(desc_buf, 0, sizeof(desc_buf)); 235 memset(desc_buf, 0, 20);
309 236
310 /* if we're saving to a slot, then get a brief description */ 237 /* if we're saving to a slot, then get a brief description */
311 if (!is_load) { 238 if (!is_load)
312 if (rb->kbd_input(desc_buf, sizeof(desc_buf)) || !strlen(desc_buf)) { 239 if (rb->kbd_input(desc_buf, 20) || !strlen(desc_buf))
313 memset(desc_buf, 0, sizeof(desc_buf)); 240 {
314 strncpy(desc_buf, "Untitled", sizeof(desc_buf)); 241 memset(desc_buf, 0, 20);
315 } 242 strncpy(desc_buf, "Untitled", 20);
316 } 243 }
317 244
318 /* load/save file */ 245 /* load/save file */
319 return do_file(path_buf, desc_buf, is_load); 246 return do_file(path_buf, desc_buf, is_load);
320} 247}
321 248
322/* 249/*
323 * get information on the given slot 250 * get information on the given slot
324 */ 251 */
325static void slot_info(char *info_buf, size_t info_bufsiz, size_t slot_id) { 252static void slot_info(char *info_buf, size_t info_bufsiz, size_t slot_id) {
326 char buf[256]; 253 char buf[256];
327 int fd; 254 int fd;
328 255
329 /* get slot file path */ 256 /* get slot file path */
330 build_slot_path(buf, sizeof(buf), slot_id); 257 build_slot_path(buf, 256, slot_id);
331 258
332 /* attempt to open slot */ 259 /* attempt to open slot */
333 if ((fd = open(buf, O_RDONLY)) >= 0) { 260 if ((fd = open(buf, O_RDONLY)) >= 0)
334 /* this slot has a some data in it, read it */ 261 {
335 if (read(fd, buf, 20) > 0) { 262 /* this slot has a some data in it, read it */
336 buf[20] = '\0'; 263 if (read(fd, buf, 20) > 0)
337 snprintf(info_buf, info_bufsiz, "%2d. %s", slot_id + 1, buf); 264 {
338 } else { 265 buf[20] = '\0';
339 snprintf(info_buf, info_bufsiz, "%2d. ERROR", slot_id + 1); 266 snprintf(info_buf, info_bufsiz, "%d. %s", slot_id + 1, buf);
267 }
268 else
269 snprintf(info_buf, info_bufsiz, "%d. ERROR", slot_id + 1);
270
271 close(fd);
272 }
273 else
274 {
275 /* if we couldn't open the file, then the slot is empty */
276 snprintf(info_buf, info_bufsiz, "%d. %s", slot_id + 1, "<Empty>");
340 } 277 }
341 close(fd);
342 } else {
343 /* if we couldn't open the file, then the slot is empty */
344 snprintf(info_buf, info_bufsiz, "%2d.", slot_id + 1);
345 }
346} 278}
347 279
348/* 280/*
349 * do_slot_menu - prompt the user for a load/save memory slot 281 * do_slot_menu - prompt the user for a load/save memory slot
350 */ 282 */
351static void do_slot_menu(bool is_load) { 283static void do_slot_menu(bool is_load) {
352 int i, mi, ret, num_items; 284 bool done=false;
353 bool done = false;
354 char *title, buf[256];
355
356 /* set defaults */
357 ret = 0; /* return value */
358 mi = 0; /* initial menu selection */
359 num_items = sizeof(slot_menu) / sizeof(char*);
360
361 /* create menu items (the last two are file and previous menu,
362 * so don't populate those) */
363 for (i = 0; i < num_items - 2; i++)
364 slot_info((char*) slot_menu[i], 20, i);
365
366 /* set text of file item */
367 snprintf((char*) slot_menu[SM_ITEM_FILE], 20, "%s File...", is_load ? "Load from" : "Save to");
368
369 /* set menu title */
370 title = is_load ? "Load State" : "Save State";
371
372 /* loop until we should exit menu */
373 while (!done) {
374 /* get item selection */
375 mi = do_menu(title, (char**) slot_menu, num_items, mi);
376
377 /* handle selected menu item */
378 done = true;
379 if (mi != MENU_CANCEL && mi != SM_ITEM_BACK) {
380 if (mi == SM_ITEM_FILE) {
381 char rom_name_buf[40];
382
383 /* munge rom name to valid filename */
384 strncpy(rom_name_buf, rom.name, 16);
385 munge_name(rom_name_buf, sizeof(rom_name_buf));
386
387 /* create default filename */
388 snprintf(buf, sizeof(buf), "/%s.rbs", rom_name_buf);
389
390 /* prompt for output filename, save to file */
391 if (!rb->kbd_input(buf, sizeof(buf)))
392 done = do_file(buf, NULL, is_load);
393 } else {
394 done = do_slot(mi, is_load);
395 }
396
397 /* if we couldn't save the state file, then print out an
398 * error message */
399 if (!is_load && !done)
400 rb->splash(HZ * 2, true, "Couldn't save state file.");
401 }
402 }
403}
404 285
405static void do_fs_menu(void) { 286 char buf[5][20];
406 int mi, ret, num_items;
407 bool done = false;
408 287
409 /* set defaults */ 288 int m;
410 ret = 0; /* return value */ 289 int result;
411 mi = 0; /* initial menu selection */ 290 int i;
412 num_items = sizeof(fs_menu) / sizeof(char*);
413
414 /* loop until we should exit menu */
415 while (!done) {
416 /* get item selection */
417 mi = do_menu(FS_MENU_TITLE, (char**) fs_menu, num_items, mi);
418
419 /* handle selected menu item */
420 switch (mi) {
421 case MENU_CANCEL:
422 case FS_ITEM_BACK:
423 done = true;
424 break;
425 case FS_ITEM_FS0:
426 options.maxskip=3;
427 break;
428 case FS_ITEM_FS1:
429 options.maxskip=4;
430 break;
431 case FS_ITEM_FS2:
432 options.maxskip=5;
433 break;
434 case FS_ITEM_FS3:
435 options.maxskip=7;
436 break;
437 }
438 }
439}
440 291
441static void do_opt_menu(void) { 292 struct menu_item items[] = {
442 int mi, num_items; 293 { buf[0] , NULL },
443 bool done = false; 294 { buf[1] , NULL },
295 { buf[2] , NULL },
296 { buf[3] , NULL },
297 { buf[4] , NULL },
298 };
444 299
445 /* set a couple of defaults */ 300 int num_items = sizeof(items) / sizeof(*items);
446 num_items = sizeof(opt_menu) / sizeof(char*);
447 mi = 0;
448
449 while (!done) {
450 mi = do_menu(OPT_MENU_TITLE, (char**) opt_menu, num_items, mi);
451 switch (mi) {
452 case OM_ITEM_FS:
453 do_fs_menu();
454 break;
455 case OM_ITEM_SOUND:
456 options.sound=!options.sound;
457 break;
458 case OM_ITEM_STATS:
459 options.showstats=!options.showstats;
460 break;
461 case OM_ITEM_FULLSCREEN:
462 options.fullscreen=!options.fullscreen;
463 break;
464 case OM_ITEM_KEYS:
465 setupkeys();
466 break;
467 case MENU_CANCEL:
468 case OM_ITEM_BACK:
469 done = true;
470 break;
471 }
472 }
473}
474 301
475/*********************************************************************/ 302 /* create menu items */
476/* MENU FUNCTIONS */ 303 for (i = 0; i < num_items; i++)
477/*********************************************************************/ 304 slot_info(buf[i], 20, i);
478/* at some point i'll make this a generic menu interface, but for now,
479 * these defines will suffice */
480#define MENU_X 10
481#define MENU_Y 8
482#define MENU_WIDTH (LCD_WIDTH - 2 * MENU_X)
483#define MENU_HEIGHT (LCD_HEIGHT - 2 * MENU_Y)
484#define MENU_RECT MENU_X, MENU_Y, MENU_WIDTH, MENU_HEIGHT
485#define SHADOW_RECT MENU_X + 1, MENU_Y + 1, MENU_WIDTH, MENU_HEIGHT
486#define MENU_ITEM_PAD 2
487
488/*
489 * select_item - select menu item (after deselecting current item)
490 */
491static void select_item(char *title, int curr_item, size_t item_i) {
492 int x, y, w, h;
493
494 /* get size of title, use that as height ofr all lines */
495 rb->lcd_getstringsize(title, &w, &h);
496 h += MENU_ITEM_PAD * 2;
497
498 /* calc x and width */
499 x = MENU_X + MENU_ITEM_PAD;
500 w = MENU_WIDTH - 2 * MENU_ITEM_PAD;
501
502 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
503 /* if there is a current item, then deselect it */
504 if (curr_item >= 0) {
505 /* deselect old item */
506 y = MENU_Y + h + MENU_ITEM_PAD * 2; /* account for title */
507 y += h * curr_item;
508 rb->lcd_fillrect(x, y, w, h);
509 }
510
511 /* select new item */
512 curr_item = item_i;
513
514 /* select new item */
515 y = MENU_Y + h + MENU_ITEM_PAD * 2; /* account for title */
516 y += h * curr_item;
517 rb->lcd_fillrect(x, y, w, h);
518 rb->lcd_set_drawmode(DRMODE_SOLID);
519
520 /* update the menu window */
521 rb->lcd_update_rect(MENU_RECT);
522}
523
524/*
525 * draw_menu - draw menu on screen
526 *
527 * Returns MENU_CANCEL if the user cancelled, or the item number of the
528 * selected item.
529 *
530 */
531static void draw_menu(char *title, char **items, size_t num_items) {
532 size_t i;
533 int x, y, w, h, by;
534 305
535 /* set to default? font */ 306 m = rb->menu_init(items, num_items, NULL, NULL, NULL, NULL);
536 rb->lcd_setfont(0);
537
538 /* draw the outline */
539 rb->lcd_fillrect(SHADOW_RECT);
540 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
541 rb->lcd_fillrect(MENU_RECT);
542 rb->lcd_set_drawmode(DRMODE_SOLID);
543 rb->lcd_drawrect(MENU_RECT);
544
545 /* calculate x/y */
546 x = MENU_X + MENU_ITEM_PAD;
547 y = MENU_Y + MENU_ITEM_PAD * 2;
548 rb->lcd_getstringsize(title, &w, &h);
549 h += MENU_ITEM_PAD * 2;
550
551 /* draw menu stipple */
552 for (i = MENU_Y; i < (size_t) y + h; i += 2)
553 rb->lcd_drawline(MENU_X, i, MENU_X + MENU_WIDTH, i);
554
555 /* clear title rect */
556 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
557 rb->lcd_fillrect((LCD_WIDTH - w) / 2 - 2, y - 2, w + 4, h);
558 rb->lcd_set_drawmode(DRMODE_SOLID);
559
560 /* draw centered title on screen */
561 rb->lcd_putsxy((LCD_WIDTH - w)/2, y, title);
562
563 /* calculate base Y for items */
564 by = y + h + MENU_ITEM_PAD;
565
566 /* iterate over each item and draw it on the screen */
567 for (i = 0; i < num_items; i++)
568 rb->lcd_putsxy(x, by + h * i, items[i]);
569 307
570 /* update the screen */ 308 while(!done)
571 rb->lcd_update(); 309 {
310 result=rb->menu_show(m);
311
312 if (result<num_items && result >= 0 )
313 done = do_slot(result, is_load);
314 else
315 done = true;
316 }
317 rb->menu_exit(m);
572} 318}
573 319
574/* 320static void do_opt_menu(void)
575 * do_menu - draw menu on screen. 321{
576 * 322 bool done=false;
577 * Draw a menu titled @title on the screen, with @num_items elements 323 int m;
578 * from @items, and select the @sel element. If in doubt, set @sel to 324 int result;
579 * -1 :). 325
580 * 326 static const struct opt_items onoff[2] = {
581 */ 327 { "Off", NULL },
582static int do_menu(char *title, char **items, size_t num_items, int sel) { 328 { "On" , NULL },
583 int btn, sel_item, ret, curr_item; 329 };
584 bool done = false; 330
585 ret = MENU_CANCEL; 331 static const struct opt_items fullscreen[]= {
586 332 { "Off", NULL },
587 /* draw menu on screen and select the first item */ 333 { "Fullscreen", NULL },
588 draw_menu(title, items, num_items); 334 { "Full - Maintain Ratio", NULL },
589 curr_item = -1; 335 };
590 select_item(title, curr_item, sel); 336
591 curr_item = sel; 337 static const struct opt_items frameskip[]= {
592 338 { "3 Max", NULL },
593 /* make sure button state is empty */ 339 { "4 Max", NULL },
594 while (rb->button_get(false) != BUTTON_NONE) 340 { "5 Max", NULL },
595 rb->yield(); 341 { "6 Max", NULL },
596 342 };
597 /* loop until the menu is finished */ 343
598 while (!done) { 344 static const struct menu_item items[] = {
599 /* grab a button */ 345 {"Max Frameskip", NULL },
600 btn = rb->button_get(true); 346 {"Sound" , NULL },
601 347 {"Stats" , NULL },
602 /* handle the button */ 348 {"Fullscreen" , NULL },
603 switch (btn) { 349 {"Set Keys (Buggy)", NULL },
604 case MENU_BUTTON_DOWN: 350 };
605 /* select next item in list */ 351
606 sel_item = curr_item + 1; 352 m = rb->menu_init(items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL);
607 if (sel_item >= (int) num_items) 353
608 sel_item = 0; 354 while(!done)
609 select_item(title, curr_item, sel_item); 355 {
610 curr_item = sel_item; 356
611 break; 357 result=rb->menu_show(m);
612 case MENU_BUTTON_UP:
613 /* select prev item in list */
614 sel_item = curr_item - 1;
615 if (sel_item < 0)
616 sel_item = num_items - 1;
617 select_item(title, curr_item, sel_item);
618 curr_item = sel_item;
619 break;
620 case MENU_BUTTON_RIGHT:
621 /* select current item */
622 ret = curr_item;
623 done = true;
624 break;
625 case MENU_BUTTON_LEFT:
626 case MENU_BUTTON_CANCEL:
627 /* cancel out of menu */
628 ret = MENU_CANCEL;
629 done = true;
630 break;
631 }
632 358
633 /* give the OS some love */ 359 switch (result)
634 rb->yield(); 360 {
635 } 361 case 0: /* Frameskip */
636 362 options.maxskip-=3;
637 /* return selected item */ 363 rb->set_option(items[0].desc, &options.maxskip, INT, frameskip, 4, NULL );
638 return ret; 364 options.maxskip+=3;
365 break;
366 case 1: /* Sound */
367 if(options.sound>1) options.sound=1;
368 rb->set_option(items[1].desc, &options.sound, INT, onoff, 2, NULL );
369 break;
370 case 2: /* Stats */
371 rb->set_option(items[2].desc, &options.showstats, INT, onoff, 2, NULL );
372 break;
373 case 3: /* Fullscreen */
374 rb->set_option(items[3].desc, &options.fullscreen, INT, fullscreen, 3, NULL );
375 setvidmode(options.fullscreen);
376 break;
377 case 4: /* Keys */
378 setupkeys();
379 break;
380 default:
381 done=true;
382 break;
383 }
384 }
385 rb->menu_exit(m);
639} 386}
diff --git a/apps/plugins/rockboy/rc.h b/apps/plugins/rockboy/rc.h
index 217b05f5c6..cb65d2a7cc 100644
--- a/apps/plugins/rockboy/rc.h
+++ b/apps/plugins/rockboy/rc.h
@@ -1,11 +1,6 @@
1
2
3
4#ifndef __RC_H__ 1#ifndef __RC_H__
5#define __RC_H__ 2#define __RC_H__
6 3
7
8
9typedef enum rctype 4typedef enum rctype
10{ 5{
11 rcv_end, 6 rcv_end,
@@ -65,7 +60,3 @@ void rc_dokey(int key, int st);
65int rc_command(char *line); 60int rc_command(char *line);
66 61
67#endif 62#endif
68
69
70
71
diff --git a/apps/plugins/rockboy/rcvars.c b/apps/plugins/rockboy/rcvars.c
index e37657dbad..a47794aa6f 100644
--- a/apps/plugins/rockboy/rcvars.c
+++ b/apps/plugins/rockboy/rcvars.c
@@ -1,26 +1,12 @@
1
2
3
4
5#include <string.h>
6#include "rockmacros.h" 1#include "rockmacros.h"
7 2
8#include "defs.h" 3#include "defs.h"
9#include "rc.h" 4#include "rc.h"
10 5
11
12
13
14
15
16static rcvar_t rcvars[150]; 6static rcvar_t rcvars[150];
17 7
18static int nvars; 8static int nvars;
19 9
20
21
22
23
24void rc_export(rcvar_t *v) 10void rc_export(rcvar_t *v)
25{ 11{
26 const rcvar_t end = RCV_END; 12 const rcvar_t end = RCV_END;
@@ -223,11 +209,3 @@ char *rc_getstr(char *name)
223{ 209{
224 return rc_getstr_n(rc_findvar(name)); 210 return rc_getstr_n(rc_findvar(name));
225} 211}
226
227
228
229
230
231
232
233
diff --git a/apps/plugins/rockboy/regs.h b/apps/plugins/rockboy/regs.h
index 4457fd90ed..f3d96b62d9 100644
--- a/apps/plugins/rockboy/regs.h
+++ b/apps/plugins/rockboy/regs.h
@@ -174,8 +174,3 @@
174 174
175 175
176#endif 176#endif
177
178
179
180
181
diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c
index 2e6560e845..05f1e4a852 100644
--- a/apps/plugins/rockboy/rockboy.c
+++ b/apps/plugins/rockboy/rockboy.c
@@ -47,6 +47,8 @@ void die(char *message, ...)
47 errormsg=message; 47 errormsg=message;
48} 48}
49 49
50struct options options IBSS_ATTR;
51
50void *audio_bufferbase; 52void *audio_bufferbase;
51void *audio_bufferpointer; 53void *audio_bufferpointer;
52unsigned int audio_buffer_free; 54unsigned int audio_buffer_free;
@@ -76,7 +78,10 @@ void setmallocpos(void *pointer)
76 audio_buffer_free = audio_bufferpointer - audio_bufferbase; 78 audio_buffer_free = audio_bufferpointer - audio_bufferbase;
77} 79}
78 80
79void setoptions (void) { 81void setvidmode(int);
82
83void setoptions (void)
84{
80 int fd; 85 int fd;
81 DIR* dir; 86 DIR* dir;
82 char optionsave[sizeof(savedir)+sizeof(optionname)]; 87 char optionsave[sizeof(savedir)+sizeof(optionname)];
@@ -144,6 +149,8 @@ void setoptions (void) {
144 else 149 else
145 read(fd,&options, sizeof(options)); 150 read(fd,&options, sizeof(options));
146 151
152 setvidmode(options.fullscreen);
153
147 close(fd); 154 close(fd);
148} 155}
149 156
@@ -167,6 +174,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
167 174
168 rb->lcd_setfont(0); 175 rb->lcd_setfont(0);
169 176
177 rb->lcd_set_foreground(LCD_WHITE);
178 rb->lcd_set_background(LCD_BLACK);
179 rb->lcd_clear_display();
180
170 if (!parameter) { 181 if (!parameter) {
171 rb->splash(HZ*3, true, "Play gameboy ROM file! (.gb/.gbc)"); 182 rb->splash(HZ*3, true, "Play gameboy ROM file! (.gb/.gbc)");
172 return PLUGIN_OK; 183 return PLUGIN_OK;
diff --git a/apps/plugins/rockboy/rockmacros.h b/apps/plugins/rockboy/rockmacros.h
index cefa0ad787..5de98deef7 100644
--- a/apps/plugins/rockboy/rockmacros.h
+++ b/apps/plugins/rockboy/rockmacros.h
@@ -105,7 +105,7 @@ void* memcpy(void* dst, const void* src, size_t size);
105struct options { 105struct options {
106 int A, B, START, SELECT, MENU; 106 int A, B, START, SELECT, MENU;
107 int frameskip, fps, maxskip; 107 int frameskip, fps, maxskip;
108 bool sound, fullscreen, showstats; 108 int sound, fullscreen, showstats;
109}; 109};
110 110
111extern struct options options; 111extern struct options options;
diff --git a/apps/plugins/rockboy/sound.h b/apps/plugins/rockboy/sound.h
index 682e6c1e94..a14b04c5a2 100644
--- a/apps/plugins/rockboy/sound.h
+++ b/apps/plugins/rockboy/sound.h
@@ -1,5 +1,3 @@
1
2
3#ifndef __SOUND_H__ 1#ifndef __SOUND_H__
4#define __SOUND_H__ 2#define __SOUND_H__
5 3
@@ -16,7 +14,6 @@ struct sndchan
16 int envol, endir; 14 int envol, endir;
17}; 15};
18 16
19
20struct snd 17struct snd
21{ 18{
22 int rate; 19 int rate;
@@ -24,7 +21,6 @@ struct snd
24 byte wave[16]; 21 byte wave[16];
25}; 22};
26 23
27
28extern struct snd snd; 24extern struct snd snd;
29 25
30#if defined(ICODE_ATTR) && defined(CPU_ARM) 26#if defined(ICODE_ATTR) && defined(CPU_ARM)
@@ -33,15 +29,14 @@ extern struct snd snd;
33#endif 29#endif
34 30
35byte sound_read(byte r) ICODE_ATTR; 31byte sound_read(byte r) ICODE_ATTR;
36void sound_write(byte r, byte b)ICODE_ATTR; 32void sound_write(byte r, byte b) ICODE_ATTR;
37void sound_dirty(void)ICODE_ATTR; 33void sound_dirty(void) ICODE_ATTR;
38void sound_off(void); 34void sound_off(void);
39void sound_reset(void); 35void sound_reset(void);
40void sound_mix(void)ICODE_ATTR; 36void sound_mix(void) ICODE_ATTR;
41void s1_init(void); 37void s1_init(void);
42void s2_init(void); 38void s2_init(void);
43void s3_init(void); 39void s3_init(void);
44void s4_init(void); 40void s4_init(void);
45 41
46#endif 42#endif
47
diff --git a/apps/plugins/rockboy/sys_rockbox.c b/apps/plugins/rockboy/sys_rockbox.c
index 077727352d..975a399965 100644
--- a/apps/plugins/rockboy/sys_rockbox.c
+++ b/apps/plugins/rockboy/sys_rockbox.c
@@ -185,7 +185,8 @@ void vid_init(void)
185#endif 185#endif
186} 186}
187 187
188#if LCD_HEIGHT<144 188#if !defined(HAVE_LCD_COLOR)
189/* Color targets are handled in lcd.c */
189fb_data *frameb; 190fb_data *frameb;
190void vid_update(int scanline) 191void vid_update(int scanline)
191{ 192{