diff options
author | Karl Kurbjun <kkurbjun@gmail.com> | 2007-06-24 16:00:55 +0000 |
---|---|---|
committer | Karl Kurbjun <kkurbjun@gmail.com> | 2007-06-24 16:00:55 +0000 |
commit | 78c45530fff6100240d08be77858350632000de9 (patch) | |
tree | 38d312e754cf87e1ea45ca1faf72fdd2d546fde2 | |
parent | 16ca78db033f86c482cceb25dd1eee32aae2ecfc (diff) | |
download | rockbox-78c45530fff6100240d08be77858350632000de9.tar.gz rockbox-78c45530fff6100240d08be77858350632000de9.zip |
Sound improvements for rockboy - players now sync the sound (The gigabeat now plays at a steady 60 fps as long as the frameskip is set properly). If a new sample is not available a blank buffer is used. All devices use 44.1 kHz for gameboy sound now so no more high pitched sounds. Added a screen rotation option. Removed unscaled code for devices with a screensize smaller than the gameboy. All buttons are now configurable. Scroll wheel devices still have button configuration problems though.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13698 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugins/rockboy/emu.c | 16 | ||||
-rw-r--r-- | apps/plugins/rockboy/lcd.c | 154 | ||||
-rw-r--r-- | apps/plugins/rockboy/menu.c | 66 | ||||
-rw-r--r-- | apps/plugins/rockboy/pcm.h | 2 | ||||
-rw-r--r-- | apps/plugins/rockboy/rbsound.c | 64 | ||||
-rw-r--r-- | apps/plugins/rockboy/rockboy.c | 146 | ||||
-rw-r--r-- | apps/plugins/rockboy/rockmacros.h | 5 | ||||
-rw-r--r-- | apps/plugins/rockboy/sound.c | 129 | ||||
-rw-r--r-- | apps/plugins/rockboy/sound.h | 1 | ||||
-rw-r--r-- | apps/plugins/rockboy/sys_rockbox.c | 43 |
10 files changed, 345 insertions, 281 deletions
diff --git a/apps/plugins/rockboy/emu.c b/apps/plugins/rockboy/emu.c index 7f24bde01e..02e5fa0b1c 100644 --- a/apps/plugins/rockboy/emu.c +++ b/apps/plugins/rockboy/emu.c | |||
@@ -35,7 +35,7 @@ void emu_run(void) | |||
35 | /*void *timer = sys_timer();*/ | 35 | /*void *timer = sys_timer();*/ |
36 | int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick; | 36 | int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick; |
37 | 37 | ||
38 | setvidmode(options.fullscreen); | 38 | setvidmode(); |
39 | vid_begin(); | 39 | vid_begin(); |
40 | lcd_begin(); | 40 | lcd_begin(); |
41 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 41 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
@@ -49,9 +49,19 @@ void emu_run(void) | |||
49 | emu_step(); | 49 | emu_step(); |
50 | 50 | ||
51 | rtc_tick(); /* RTC support not implemented */ | 51 | rtc_tick(); /* RTC support not implemented */ |
52 | 52 | ||
53 | if(options.sound || !plugbuf) | 53 | if (options.sound || !plugbuf) |
54 | { | ||
54 | sound_mix(); | 55 | sound_mix(); |
56 | pcm_submit(); | ||
57 | } | ||
58 | else | ||
59 | { | ||
60 | /* delay = framelen - sys_elapsed(timer); | ||
61 | sys_sleep(delay); | ||
62 | sys_elapsed(timer); | ||
63 | */ | ||
64 | } | ||
55 | 65 | ||
56 | doevents(); | 66 | doevents(); |
57 | vid_begin(); | 67 | vid_begin(); |
diff --git a/apps/plugins/rockboy/lcd.c b/apps/plugins/rockboy/lcd.c index 7fe531041c..bf44ccf136 100644 --- a/apps/plugins/rockboy/lcd.c +++ b/apps/plugins/rockboy/lcd.c | |||
@@ -833,40 +833,67 @@ void spr_scan(void) | |||
833 | #define DY ((LCD_HEIGHT<<16) / 144) | 833 | #define DY ((LCD_HEIGHT<<16) / 144) |
834 | #define DYI ((144<<16) / LCD_HEIGHT) | 834 | #define DYI ((144<<16) / LCD_HEIGHT) |
835 | 835 | ||
836 | #define DXR ((LCD_WIDTH<<16) / 144) | ||
837 | #define DXIR ((144<<16) / LCD_WIDTH) | ||
838 | #define DYR ((LCD_HEIGHT<<16) / 160) | ||
839 | #define DYIR ((160<<16) / LCD_HEIGHT) | ||
840 | |||
836 | void lcd_begin(void) | 841 | void lcd_begin(void) |
837 | { | 842 | { |
838 | 843 | ||
839 | #if (LCD_WIDTH>=160) && (LCD_HEIGHT>=144) | 844 | #if (LCD_WIDTH>=160) && (LCD_HEIGHT>=144) |
840 | #define S1 ((LCD_HEIGHT-144)/2)*LCD_WIDTH + ((LCD_WIDTH-160)/2) | 845 | #define S1 ((LCD_HEIGHT-144)/2)*LCD_WIDTH + ((LCD_WIDTH-160)/2) |
841 | #define S2 0 | 846 | #define S2 0 |
847 | #define S1R ((LCD_HEIGHT-160)/2)*LCD_WIDTH + ((LCD_WIDTH-144)/2)+144 | ||
848 | #define S2R (LCD_WIDTH-1) | ||
842 | 849 | ||
843 | #elif (LCD_WIDTH>=160) && (LCD_HEIGHT<=144) | 850 | #elif (LCD_WIDTH>=160) && (LCD_HEIGHT<=144) |
844 | #define S1 ((LCD_WIDTH-160)/2) | 851 | #define S1 0 |
845 | #define S2 ((LCD_WIDTH-160)/2) | 852 | #define S2 0 |
853 | #define S1R LCD_WIDTH-1 | ||
854 | #define S2R LCD_WIDTH-1 | ||
846 | 855 | ||
847 | #elif (LCD_WIDTH<=160) && (LCD_HEIGHT>=144) | 856 | #elif (LCD_WIDTH<=160) && (LCD_HEIGHT>=144) |
848 | #define S1 ((LCD_HEIGHT-144)/2)*LCD_WIDTH | 857 | #define S1 ((LCD_HEIGHT-144)/2)*LCD_WIDTH |
849 | #define S2 ((LCD_HEIGHT-144)/2)*LCD_WIDTH | 858 | #define S2 ((LCD_HEIGHT-144)/2)*LCD_WIDTH |
859 | #define S1R LCD_WIDTH-1 | ||
860 | #define S2R LCD_WIDTH-1 | ||
850 | 861 | ||
851 | #else | 862 | #else |
852 | #define S1 0 | 863 | #define S1 0 |
853 | #define S2 0 | 864 | #define S2 0 |
865 | #define S1R LCD_WIDTH-1 | ||
866 | #define S2R LCD_WIDTH-1 | ||
854 | #endif | 867 | #endif |
855 | 868 | ||
856 | #if (LCD_WIDTH>LCD_HEIGHT) | 869 | #if (LCD_WIDTH>LCD_HEIGHT) |
857 | #define S3 ((LCD_WIDTH-(160*LCD_HEIGHT/144))/2) | 870 | #define S3 ((LCD_WIDTH-((160*DY)>>16))/2) |
871 | #define S3R LCD_WIDTH-1 | ||
858 | #else | 872 | #else |
859 | #define S3 ((LCD_HEIGHT-(144*LCD_WIDTH/160))/2)*LCD_WIDTH | 873 | #define S3 ((LCD_HEIGHT-((144*DX)>>16))/2)*LCD_WIDTH |
874 | #define S3R ((LCD_HEIGHT-((160*DXR)>>16))/2)*LCD_WIDTH+LCD_WIDTH-1 | ||
860 | #endif | 875 | #endif |
861 | 876 | ||
862 | set_pal(); | 877 | set_pal(); |
863 | 878 | ||
864 | if(options.fullscreen == 0) | 879 | if(options.rotate) |
865 | vdest=fb.ptr+S1; | 880 | { |
866 | else if (options.fullscreen == 1) | 881 | if(options.fullscreen == 0) |
867 | vdest=fb.ptr+S2; | 882 | vdest=fb.ptr+S2R; |
883 | else if (options.fullscreen == 1) | ||
884 | vdest=fb.ptr+S3R; | ||
885 | else | ||
886 | vdest=fb.ptr+S1R; | ||
887 | } | ||
868 | else | 888 | else |
869 | vdest=fb.ptr+S3; | 889 | { |
890 | if(options.fullscreen == 0) | ||
891 | vdest=fb.ptr+S2; | ||
892 | else if (options.fullscreen == 1) | ||
893 | vdest=fb.ptr+S3; | ||
894 | else | ||
895 | vdest=fb.ptr+S1; | ||
896 | } | ||
870 | WY = R_WY; | 897 | WY = R_WY; |
871 | } | 898 | } |
872 | 899 | ||
@@ -874,50 +901,63 @@ int SCALEWL IDATA_ATTR=1<<16; | |||
874 | int SCALEWS IDATA_ATTR=1<<16; | 901 | int SCALEWS IDATA_ATTR=1<<16; |
875 | int SCALEHL IDATA_ATTR=1<<16; | 902 | int SCALEHL IDATA_ATTR=1<<16; |
876 | int SCALEHS IDATA_ATTR=1<<16; | 903 | int SCALEHS IDATA_ATTR=1<<16; |
877 | int swidth IDATA_ATTR=160; | 904 | int swidth IDATA_ATTR=160; |
878 | int sremain IDATA_ATTR=LCD_WIDTH-160; | 905 | int sremain IDATA_ATTR=LCD_WIDTH-160; |
879 | 906 | ||
880 | void setvidmode(int mode) | 907 | void setvidmode(void) |
881 | { | 908 | { |
882 | switch(mode) | 909 | switch(options.fullscreen) |
883 | { | 910 | { |
884 | case 1: | 911 | case 0: |
885 | #if (LCD_WIDTH>=160) && (LCD_HEIGHT>=144) /* Full screen scale */ | 912 | if(options.rotate) |
886 | SCALEWL=DX; | ||
887 | SCALEWS=DXI; | ||
888 | SCALEHL=DY; | ||
889 | SCALEHS=DYI; | ||
890 | #elif (LCD_WIDTH>=160) && (LCD_HEIGHT<144) /* scale the height */ | ||
891 | SCALEWL=1<<16; | ||
892 | SCALEWS=1<<16; | ||
893 | SCALEHL=DY; | ||
894 | SCALEHS=DYI; | ||
895 | #elif (LCD_WIDTH<160) && (LCD_HEIGHT>=144) /* scale the width */ | ||
896 | SCALEWL=DX; | ||
897 | SCALEWS=DXI; | ||
898 | SCALEHL=1<<16; | ||
899 | SCALEHS=1<<16; | ||
900 | #else | ||
901 | SCALEWL=DX; | ||
902 | SCALEWS=DXI; | ||
903 | SCALEHL=DY; | ||
904 | SCALEHS=DYI; | ||
905 | #endif | ||
906 | break; | ||
907 | case 2: /* Maintain Ratio */ | ||
908 | if (DY<DX) | ||
909 | { | 913 | { |
910 | SCALEWL=DY; | 914 | SCALEWL=DYR; |
911 | SCALEWS=DYI; | 915 | SCALEWS=DYIR; |
912 | SCALEHL=DY; | 916 | SCALEHL=DXR; |
913 | SCALEHS=DYI; | 917 | SCALEHS=DXIR; |
914 | } | 918 | } |
915 | else | 919 | else |
916 | { | 920 | { |
917 | SCALEWL=DX; | 921 | SCALEWL=DX; |
918 | SCALEWS=DXI; | 922 | SCALEWS=DXI; |
919 | SCALEHL=DX; | 923 | SCALEHL=DY; |
920 | SCALEHS=DXI; | 924 | SCALEHS=DYI; |
925 | } | ||
926 | break; | ||
927 | case 1: /* Maintain Ratio */ | ||
928 | if(options.rotate) | ||
929 | { | ||
930 | if (DYR<DXR) | ||
931 | { | ||
932 | SCALEWL=DYR; | ||
933 | SCALEWS=DYIR; | ||
934 | SCALEHL=DYR; | ||
935 | SCALEHS=DYIR; | ||
936 | } | ||
937 | else | ||
938 | { | ||
939 | SCALEWL=DXR; | ||
940 | SCALEWS=DXIR; | ||
941 | SCALEHL=DXR; | ||
942 | SCALEHS=DXIR; | ||
943 | } | ||
944 | } | ||
945 | else | ||
946 | { | ||
947 | if (DY<DX) | ||
948 | { | ||
949 | SCALEWL=DY; | ||
950 | SCALEWS=DYI; | ||
951 | SCALEHL=DY; | ||
952 | SCALEHS=DYI; | ||
953 | } | ||
954 | else | ||
955 | { | ||
956 | SCALEWL=DX; | ||
957 | SCALEWS=DXI; | ||
958 | SCALEHL=DX; | ||
959 | SCALEHS=DXI; | ||
960 | } | ||
921 | } | 961 | } |
922 | break; | 962 | break; |
923 | default: | 963 | default: |
@@ -927,7 +967,11 @@ void setvidmode(int mode) | |||
927 | SCALEHS=1<<16; | 967 | SCALEHS=1<<16; |
928 | } | 968 | } |
929 | swidth=(160*SCALEWL)>>16; | 969 | swidth=(160*SCALEWL)>>16; |
930 | sremain=LCD_WIDTH-swidth; | 970 | |
971 | if(options.rotate) | ||
972 | sremain=-(((160*SCALEWL)>>16)*LCD_WIDTH+1); | ||
973 | else | ||
974 | sremain=LCD_WIDTH-swidth; | ||
931 | } | 975 | } |
932 | 976 | ||
933 | void lcd_refreshline(void) | 977 | void lcd_refreshline(void) |
@@ -1015,24 +1059,14 @@ void lcd_refreshline(void) | |||
1015 | register unsigned int remain=sremain; | 1059 | register unsigned int remain=sremain; |
1016 | while(wcount--) | 1060 | while(wcount--) |
1017 | { | 1061 | { |
1018 | #if LCD_HEIGHT<144 /* cut off the bottom part of the screen that won't fit */ | 1062 | *vdest = PAL[BUF[srcpt>>16]]; |
1019 | if (options.fullscreen==0 && (hpt>>16)>LCD_HEIGHT) | 1063 | if (options.rotate) |
1020 | break; | 1064 | vdest+=LCD_WIDTH; |
1021 | #endif | 1065 | else |
1066 | vdest++; | ||
1022 | 1067 | ||
1023 | #if LCD_WIDTH<160 /* cut off the right part of the screen that won't fit */ | ||
1024 | if(options.fullscreen==0 && wcount<(160-LCD_WIDTH)) { | ||
1025 | vdest+=wcount; | ||
1026 | wcount = 0; | ||
1027 | } | ||
1028 | #endif | ||
1029 | |||
1030 | *vdest++ = PAL[BUF[srcpt>>16]]; | ||
1031 | srcpt+=SCALEWS; | 1068 | srcpt+=SCALEWS; |
1032 | } | 1069 | } |
1033 | #if LCD_HEIGHT<144 | ||
1034 | if (options.fullscreen!=0 || (hpt>>16)<(LCD_HEIGHT)) | ||
1035 | #endif | ||
1036 | vdest+=remain; | 1070 | vdest+=remain; |
1037 | } | 1071 | } |
1038 | 1072 | ||
diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c index ca15cba7b9..e358bafbb9 100644 --- a/apps/plugins/rockboy/menu.c +++ b/apps/plugins/rockboy/menu.c | |||
@@ -38,11 +38,14 @@ static void munge_name(char *buf, size_t bufsiz); | |||
38 | 38 | ||
39 | int getbutton(char *text) | 39 | int getbutton(char *text) |
40 | { | 40 | { |
41 | rb->lcd_putsxy(0, 0, text); | 41 | int fw, fh; |
42 | rb->lcd_clear_display(); | ||
43 | rb->font_getstringsize(text, &fw, &fh,0); | ||
44 | rb->lcd_putsxy(LCD_WIDTH/2-fw/2, LCD_HEIGHT/2-fh/2, text); | ||
42 | rb->lcd_update(); | 45 | rb->lcd_update(); |
43 | rb->sleep(30); | 46 | rb->sleep(30); |
44 | 47 | ||
45 | while (rb->button_get(false) != BUTTON_NONE) | 48 | while (rb->button_get(false) != BUTTON_NONE) |
46 | rb->yield(); | 49 | rb->yield(); |
47 | 50 | ||
48 | int button; | 51 | int button; |
@@ -51,31 +54,24 @@ int getbutton(char *text) | |||
51 | button = rb->button_get(true); | 54 | button = rb->button_get(true); |
52 | button=button&0x00000FFF; | 55 | button=button&0x00000FFF; |
53 | 56 | ||
54 | switch(button) | 57 | return button; |
55 | { | ||
56 | case MENU_BUTTON_LEFT: | ||
57 | case MENU_BUTTON_RIGHT: | ||
58 | case MENU_BUTTON_UP: | ||
59 | case MENU_BUTTON_DOWN: | ||
60 | break; | ||
61 | default: | ||
62 | return button; | ||
63 | break; | ||
64 | } | ||
65 | } | 58 | } |
66 | } | 59 | } |
67 | 60 | ||
68 | void setupkeys(void) | 61 | void setupkeys(void) |
69 | { | 62 | { |
70 | options.A=getbutton("Press A"); | 63 | options.UP=getbutton ("Press Up"); |
64 | options.DOWN=getbutton ("Press Down"); | ||
65 | options.LEFT=getbutton ("Press Left"); | ||
66 | options.RIGHT=getbutton ("Press Right"); | ||
71 | 67 | ||
72 | options.B=getbutton("Press B"); | 68 | options.A=getbutton ("Press A"); |
73 | 69 | options.B=getbutton ("Press B"); | |
74 | options.START=getbutton("Press Start"); | ||
75 | 70 | ||
71 | options.START=getbutton ("Press Start"); | ||
76 | options.SELECT=getbutton("Press Select"); | 72 | options.SELECT=getbutton("Press Select"); |
77 | 73 | ||
78 | options.MENU=getbutton("Press Menu"); | 74 | options.MENU=getbutton ("Press Menu"); |
79 | } | 75 | } |
80 | 76 | ||
81 | /* | 77 | /* |
@@ -330,12 +326,17 @@ static void do_opt_menu(void) | |||
330 | }; | 326 | }; |
331 | 327 | ||
332 | static const struct opt_items fullscreen[]= { | 328 | static const struct opt_items fullscreen[]= { |
333 | { "Unscaled", -1 }, | ||
334 | { "Scaled", -1 }, | 329 | { "Scaled", -1 }, |
335 | { "Scaled - Maintain Ratio", -1 }, | 330 | { "Scaled - Maintain Ratio", -1 }, |
331 | #if (LCD_WIDTH>=160) && (LCD_HEIGHT>=144) | ||
332 | { "Unscaled", -1 }, | ||
333 | #endif | ||
336 | }; | 334 | }; |
337 | 335 | ||
338 | static const struct opt_items frameskip[]= { | 336 | static const struct opt_items frameskip[]= { |
337 | { "0 Max", -1 }, | ||
338 | { "1 Max", -1 }, | ||
339 | { "2 Max", -1 }, | ||
339 | { "3 Max", -1 }, | 340 | { "3 Max", -1 }, |
340 | { "4 Max", -1 }, | 341 | { "4 Max", -1 }, |
341 | { "5 Max", -1 }, | 342 | { "5 Max", -1 }, |
@@ -368,7 +369,8 @@ static void do_opt_menu(void) | |||
368 | { "Max Frameskip", NULL }, | 369 | { "Max Frameskip", NULL }, |
369 | { "Sound" , NULL }, | 370 | { "Sound" , NULL }, |
370 | { "Stats" , NULL }, | 371 | { "Stats" , NULL }, |
371 | { "Screen Options" , NULL }, | 372 | { "Screen Size" , NULL }, |
373 | { "Screen Rotate" , NULL }, | ||
372 | { "Set Keys (Buggy)", NULL }, | 374 | { "Set Keys (Buggy)", NULL }, |
373 | #ifdef HAVE_LCD_COLOR | 375 | #ifdef HAVE_LCD_COLOR |
374 | { "Set Palette" , NULL }, | 376 | { "Set Palette" , NULL }, |
@@ -377,6 +379,8 @@ static void do_opt_menu(void) | |||
377 | 379 | ||
378 | m = menu_init(rb,items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); | 380 | m = menu_init(rb,items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); |
379 | 381 | ||
382 | options.dirty=1; /* Just assume that the settings have been changed */ | ||
383 | |||
380 | while(!done) | 384 | while(!done) |
381 | { | 385 | { |
382 | 386 | ||
@@ -385,9 +389,8 @@ static void do_opt_menu(void) | |||
385 | switch (result) | 389 | switch (result) |
386 | { | 390 | { |
387 | case 0: /* Frameskip */ | 391 | case 0: /* Frameskip */ |
388 | options.maxskip-=3; | 392 | rb->set_option(items[0].desc, &options.maxskip, INT, frameskip, |
389 | rb->set_option(items[0].desc, &options.maxskip, INT, frameskip, 4, NULL ); | 393 | sizeof(frameskip)/sizeof(*frameskip), NULL ); |
390 | options.maxskip+=3; | ||
391 | break; | 394 | break; |
392 | case 1: /* Sound */ | 395 | case 1: /* Sound */ |
393 | if(options.sound>1) options.sound=1; | 396 | if(options.sound>1) options.sound=1; |
@@ -397,16 +400,21 @@ static void do_opt_menu(void) | |||
397 | case 2: /* Stats */ | 400 | case 2: /* Stats */ |
398 | rb->set_option(items[2].desc, &options.showstats, INT, onoff, 2, NULL ); | 401 | rb->set_option(items[2].desc, &options.showstats, INT, onoff, 2, NULL ); |
399 | break; | 402 | break; |
400 | case 3: /* Fullscreen */ | 403 | case 3: /* Screen Size */ |
401 | rb->set_option(items[3].desc, &options.fullscreen, INT, fullscreen, 3, NULL ); | 404 | rb->set_option(items[3].desc, &options.fullscreen, INT, fullscreen, |
402 | setvidmode(options.fullscreen); | 405 | sizeof(fullscreen)/sizeof(*fullscreen), NULL ); |
406 | setvidmode(); | ||
407 | break; | ||
408 | case 4: /* Screen rotate */ | ||
409 | rb->set_option(items[4].desc, &options.rotate, INT, onoff, 2, NULL ); | ||
410 | setvidmode(); | ||
403 | break; | 411 | break; |
404 | case 4: /* Keys */ | 412 | case 5: /* Keys */ |
405 | setupkeys(); | 413 | setupkeys(); |
406 | break; | 414 | break; |
407 | #ifdef HAVE_LCD_COLOR | 415 | #ifdef HAVE_LCD_COLOR |
408 | case 5: /* Palette */ | 416 | case 6: /* Palette */ |
409 | rb->set_option(items[5].desc, &options.pal, INT, palette, 17, NULL ); | 417 | rb->set_option(items[6].desc, &options.pal, INT, palette, 17, NULL ); |
410 | set_pal(); | 418 | set_pal(); |
411 | break; | 419 | break; |
412 | #endif | 420 | #endif |
diff --git a/apps/plugins/rockboy/pcm.h b/apps/plugins/rockboy/pcm.h index a616ce9897..f009f5708c 100644 --- a/apps/plugins/rockboy/pcm.h +++ b/apps/plugins/rockboy/pcm.h | |||
@@ -9,7 +9,7 @@ struct pcm | |||
9 | { | 9 | { |
10 | int hz, len; | 10 | int hz, len; |
11 | int stereo; | 11 | int stereo; |
12 | byte *buf; | 12 | short *buf; |
13 | int pos; | 13 | int pos; |
14 | }; | 14 | }; |
15 | 15 | ||
diff --git a/apps/plugins/rockboy/rbsound.c b/apps/plugins/rockboy/rbsound.c index e671554e25..163c39aa66 100644 --- a/apps/plugins/rockboy/rbsound.c +++ b/apps/plugins/rockboy/rbsound.c | |||
@@ -5,21 +5,20 @@ | |||
5 | struct pcm pcm IBSS_ATTR; | 5 | struct pcm pcm IBSS_ATTR; |
6 | 6 | ||
7 | #define N_BUFS 2 | 7 | #define N_BUFS 2 |
8 | #define BUF_SIZE 1024 | 8 | #define BUF_SIZE 2048 |
9 | |||
10 | #if CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) | ||
11 | 9 | ||
12 | bool doneplay=1; | 10 | bool doneplay=1; |
11 | bool bufnum=0; | ||
13 | 12 | ||
14 | static unsigned char *buf=0; | 13 | static unsigned short *buf=0; |
15 | static unsigned short *gmbuf; | ||
16 | 14 | ||
17 | static bool newly_started; | 15 | static bool newly_started; |
18 | 16 | ||
19 | void get_more(unsigned char** start, size_t* size) | 17 | void get_more(unsigned char** start, size_t* size) |
20 | { | 18 | { |
21 | *start = (unsigned char*)(&gmbuf[pcm.len*doneplay]); | 19 | *start = (unsigned char*)(&buf[pcm.len*doneplay]); |
22 | *size = BUF_SIZE*sizeof(short); | 20 | *size = BUF_SIZE*sizeof(short); |
21 | doneplay=1; | ||
23 | } | 22 | } |
24 | 23 | ||
25 | void pcm_init(void) | 24 | void pcm_init(void) |
@@ -29,19 +28,17 @@ void pcm_init(void) | |||
29 | 28 | ||
30 | newly_started = true; | 29 | newly_started = true; |
31 | 30 | ||
32 | pcm.hz = 11025; | 31 | pcm.hz = SAMPR_44; |
33 | pcm.stereo = 1; | 32 | pcm.stereo = 1; |
34 | 33 | ||
35 | pcm.len = BUF_SIZE; | 34 | pcm.len = BUF_SIZE; |
36 | if(!buf) | 35 | if(!buf) |
37 | { | 36 | { |
38 | buf = my_malloc(pcm.len * N_BUFS); | 37 | buf = my_malloc(pcm.len * N_BUFS *sizeof(short)); |
39 | gmbuf = my_malloc(pcm.len * N_BUFS*sizeof (short)); | ||
40 | 38 | ||
41 | pcm.buf = buf; | 39 | pcm.buf = buf; |
42 | pcm.pos = 0; | 40 | pcm.pos = 0; |
43 | memset(gmbuf, 0, pcm.len * N_BUFS *sizeof(short)); | 41 | memset(buf, 0, pcm.len * N_BUFS*sizeof(short)); |
44 | memset(buf, 0, pcm.len * N_BUFS); | ||
45 | } | 42 | } |
46 | 43 | ||
47 | rb->pcm_play_stop(); | 44 | rb->pcm_play_stop(); |
@@ -52,7 +49,7 @@ void pcm_init(void) | |||
52 | rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); | 49 | rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); |
53 | #endif | 50 | #endif |
54 | 51 | ||
55 | rb->pcm_set_frequency(SAMPR_11); /* 44100 22050 11025 */ | 52 | rb->pcm_set_frequency(pcm.hz); /* 44100 22050 11025 */ |
56 | } | 53 | } |
57 | 54 | ||
58 | void pcm_close(void) | 55 | void pcm_close(void) |
@@ -65,50 +62,21 @@ void pcm_close(void) | |||
65 | 62 | ||
66 | int pcm_submit(void) | 63 | int pcm_submit(void) |
67 | { | 64 | { |
68 | register int i; | 65 | if (!pcm.buf) return 0; |
69 | |||
70 | if (pcm.pos < pcm.len) return 1; | 66 | if (pcm.pos < pcm.len) return 1; |
71 | 67 | ||
72 | doneplay=!doneplay; | ||
73 | |||
74 | if(doneplay) | ||
75 | pcm.buf = buf + pcm.len; | ||
76 | else | ||
77 | pcm.buf = buf; | ||
78 | |||
79 | pcm.pos = 0; | ||
80 | |||
81 | /* gotta convert the 8 bit buffer to 16 */ | ||
82 | for(i=0; i<pcm.len;i++) | ||
83 | gmbuf[i+pcm.len*doneplay] = (pcm.buf[i]<<8)-0x8000; | ||
84 | |||
85 | if(newly_started) | 68 | if(newly_started) |
86 | { | 69 | { |
87 | rb->pcm_play_data(&get_more,NULL,0); | 70 | rb->pcm_play_data(&get_more,NULL,0); |
88 | newly_started = false; | 71 | newly_started = false; |
89 | } | 72 | } |
90 | 73 | ||
91 | return 1; | 74 | while (!doneplay) |
92 | } | 75 | {rb->yield();} |
93 | #else | ||
94 | static byte buf1_unal[(BUF_SIZE / sizeof(short)) + 2]; /* 4 byte aligned */ | ||
95 | void pcm_init(void) | ||
96 | { | ||
97 | pcm.hz = 11025; | ||
98 | pcm.stereo = 1; | ||
99 | pcm.buf = buf1_unal; | ||
100 | pcm.len = (BUF_SIZE / sizeof(short)); | ||
101 | pcm.pos = 0; | ||
102 | } | ||
103 | 76 | ||
104 | void pcm_close(void) | 77 | doneplay=0; |
105 | { | 78 | |
106 | memset(&pcm, 0, sizeof pcm); | 79 | pcm.pos = 0; |
107 | } | 80 | return 1; |
108 | int pcm_submit(void) | ||
109 | { | ||
110 | pcm.pos =0; | ||
111 | return 0; | ||
112 | } | 81 | } |
113 | #endif | ||
114 | 82 | ||
diff --git a/apps/plugins/rockboy/rockboy.c b/apps/plugins/rockboy/rockboy.c index 6c99a3db18..46a0aa56c3 100644 --- a/apps/plugins/rockboy/rockboy.c +++ b/apps/plugins/rockboy/rockboy.c | |||
@@ -79,70 +79,101 @@ void setoptions (void) | |||
79 | 79 | ||
80 | snprintf(optionsave, sizeof(optionsave), "%s/%s", savedir, optionname); | 80 | snprintf(optionsave, sizeof(optionsave), "%s/%s", savedir, optionname); |
81 | 81 | ||
82 | fd = open(optionsave, O_RDONLY); | 82 | fd = open(optionsave, O_RDONLY); |
83 | if(fd < 0) /* no options to read, set defaults */ | 83 | if(fd < 0) /* no options to read, set defaults */ |
84 | { | 84 | { |
85 | options.LEFT=BUTTON_LEFT; | ||
86 | options.RIGHT=BUTTON_RIGHT; | ||
87 | |||
85 | #if (CONFIG_KEYPAD == IRIVER_H100_PAD) | 88 | #if (CONFIG_KEYPAD == IRIVER_H100_PAD) |
86 | options.A=BUTTON_ON; | 89 | options.UP=BUTTON_UP; |
87 | options.B=BUTTON_OFF; | 90 | options.DOWN=BUTTON_DOWN; |
88 | options.START=BUTTON_REC; | 91 | |
89 | options.SELECT=BUTTON_SELECT; | 92 | options.A=BUTTON_ON; |
90 | options.MENU=BUTTON_MODE; | 93 | options.B=BUTTON_OFF; |
94 | options.START=BUTTON_REC; | ||
95 | options.SELECT=BUTTON_SELECT; | ||
96 | options.MENU=BUTTON_MODE; | ||
91 | 97 | ||
92 | #elif (CONFIG_KEYPAD == IRIVER_H300_PAD) | 98 | #elif (CONFIG_KEYPAD == IRIVER_H300_PAD) |
93 | options.A=BUTTON_REC; | 99 | options.UP=BUTTON_UP; |
94 | options.B=BUTTON_MODE; | 100 | options.DOWN=BUTTON_DOWN; |
95 | options.START=BUTTON_ON; | 101 | |
96 | options.SELECT=BUTTON_SELECT; | 102 | options.A=BUTTON_REC; |
97 | options.MENU=BUTTON_OFF; | 103 | options.B=BUTTON_MODE; |
104 | options.START=BUTTON_ON; | ||
105 | options.SELECT=BUTTON_SELECT; | ||
106 | options.MENU=BUTTON_OFF; | ||
98 | 107 | ||
99 | #elif CONFIG_KEYPAD == RECORDER_PAD | 108 | #elif CONFIG_KEYPAD == RECORDER_PAD |
100 | options.A=BUTTON_F1; | 109 | options.UP=BUTTON_UP; |
101 | options.B=BUTTON_F2; | 110 | options.DOWN=BUTTON_DOWN; |
102 | options.START=BUTTON_F3; | 111 | |
103 | options.SELECT=BUTTON_PLAY; | 112 | options.A=BUTTON_F1; |
104 | options.MENU=BUTTON_OFF; | 113 | options.B=BUTTON_F2; |
114 | options.START=BUTTON_F3; | ||
115 | options.SELECT=BUTTON_PLAY; | ||
116 | options.MENU=BUTTON_OFF; | ||
105 | 117 | ||
106 | #elif CONFIG_KEYPAD == IPOD_4G_PAD | 118 | #elif CONFIG_KEYPAD == IPOD_4G_PAD |
107 | options.A=BUTTON_NONE; | 119 | options.UP=BUTTON_MENU; |
108 | options.B=BUTTON_NONE; | 120 | options.DOWN=BUTTON_PLAY; |
109 | options.START=BUTTON_SELECT; | 121 | |
110 | options.SELECT=BUTTON_NONE; | 122 | options.A=BUTTON_NONE; |
111 | options.MENU=(BUTTON_SELECT | BUTTON_REPEAT); | 123 | options.B=BUTTON_NONE; |
124 | options.START=BUTTON_SELECT; | ||
125 | options.SELECT=BUTTON_NONE; | ||
126 | options.MENU=(BUTTON_SELECT | BUTTON_REPEAT); | ||
112 | 127 | ||
113 | #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD | 128 | #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD |
114 | options.A=BUTTON_PLAY; | 129 | options.UP=BUTTON_UP; |
115 | options.B=BUTTON_EQ; | 130 | options.DOWN=BUTTON_DOWN; |
116 | options.START=BUTTON_MODE; | 131 | |
117 | options.SELECT=(BUTTON_SELECT | BUTTON_REL); | 132 | options.A=BUTTON_PLAY; |
118 | options.MENU=(BUTTON_SELECT | BUTTON_REPEAT); | 133 | options.B=BUTTON_EQ; |
134 | options.START=BUTTON_MODE; | ||
135 | options.SELECT=(BUTTON_SELECT | BUTTON_REL); | ||
136 | options.MENU=(BUTTON_SELECT | BUTTON_REPEAT); | ||
119 | 137 | ||
120 | #elif CONFIG_KEYPAD == GIGABEAT_PAD | 138 | #elif CONFIG_KEYPAD == GIGABEAT_PAD |
121 | options.A=BUTTON_VOL_UP; | 139 | options.UP=BUTTON_UP; |
122 | options.B=BUTTON_VOL_DOWN; | 140 | options.DOWN=BUTTON_DOWN; |
123 | options.START=BUTTON_A; | 141 | |
124 | options.SELECT=BUTTON_SELECT; | 142 | options.A=BUTTON_VOL_UP; |
125 | options.MENU=BUTTON_MENU; | 143 | options.B=BUTTON_VOL_DOWN; |
144 | options.START=BUTTON_A; | ||
145 | options.SELECT=BUTTON_SELECT; | ||
146 | options.MENU=BUTTON_MENU; | ||
126 | 147 | ||
127 | #elif CONFIG_KEYPAD == SANSA_E200_PAD | 148 | #elif CONFIG_KEYPAD == SANSA_E200_PAD |
128 | options.A=BUTTON_SELECT; | 149 | options.UP=BUTTON_UP; |
129 | options.B=BUTTON_REC; | 150 | options.DOWN=BUTTON_DOWN; |
130 | options.START=BUTTON_SCROLL_UP; | 151 | |
131 | options.SELECT=BUTTON_SCROLL_DOWN; | 152 | options.A=BUTTON_SELECT; |
132 | options.MENU=BUTTON_POWER; | 153 | options.B=BUTTON_REC; |
154 | options.START=BUTTON_SCROLL_UP; | ||
155 | options.SELECT=BUTTON_SCROLL_DOWN; | ||
156 | options.MENU=BUTTON_POWER; | ||
157 | |||
133 | #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD | 158 | #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD |
134 | options.A=BUTTON_PLAY; | 159 | options.UP=BUTTON_UP; |
135 | options.B=BUTTON_REC; | 160 | options.DOWN=BUTTON_DOWN; |
136 | options.START=BUTTON_SELECT; | 161 | |
137 | options.SELECT=BUTTON_NONE; | 162 | options.A=BUTTON_PLAY; |
138 | options.MENU=BUTTON_POWER; | 163 | options.B=BUTTON_REC; |
164 | options.START=BUTTON_SELECT; | ||
165 | options.SELECT=BUTTON_NONE; | ||
166 | options.MENU=BUTTON_POWER; | ||
139 | 167 | ||
140 | #elif CONFIG_KEYPAD == IRIVER_H10_PAD | 168 | #elif CONFIG_KEYPAD == IRIVER_H10_PAD |
141 | options.A=BUTTON_PLAY; | 169 | options.UP=BUTTON_SCROLL_UP; |
142 | options.B=BUTTON_FF; | 170 | options.DOWN=BUTTON_SCROLL_DOWN; |
143 | options.START=BUTTON_REW; | 171 | |
144 | options.SELECT=BUTTON_NONE; | 172 | options.A=BUTTON_PLAY; |
145 | options.MENU=BUTTON_POWER; | 173 | options.B=BUTTON_FF; |
174 | options.START=BUTTON_REW; | ||
175 | options.SELECT=BUTTON_NONE; | ||
176 | options.MENU=BUTTON_POWER; | ||
146 | #endif | 177 | #endif |
147 | 178 | ||
148 | options.maxskip=4; | 179 | options.maxskip=4; |
@@ -164,13 +195,17 @@ void setoptions (void) | |||
164 | 195 | ||
165 | void savesettings(void) | 196 | void savesettings(void) |
166 | { | 197 | { |
167 | int fd; | 198 | int fd; |
168 | char optionsave[sizeof(savedir)+sizeof(optionname)]; | 199 | char optionsave[sizeof(savedir)+sizeof(optionname)]; |
169 | 200 | ||
170 | snprintf(optionsave, sizeof(optionsave), "%s/%s", savedir, optionname); | 201 | if(options.dirty) |
171 | fd = open(optionsave, O_WRONLY|O_CREAT|O_TRUNC); | 202 | { |
172 | write(fd,&options, sizeof(options)); | 203 | options.dirty=0; |
173 | close(fd); | 204 | snprintf(optionsave, sizeof(optionsave), "%s/%s", savedir, optionname); |
205 | fd = open(optionsave, O_WRONLY|O_CREAT|O_TRUNC); | ||
206 | write(fd,&options, sizeof(options)); | ||
207 | close(fd); | ||
208 | } | ||
174 | } | 209 | } |
175 | 210 | ||
176 | /* this is the plugin entry point */ | 211 | /* this is the plugin entry point */ |
@@ -231,12 +266,11 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
231 | } | 266 | } |
232 | if(!rb->audio_status()) | 267 | if(!rb->audio_status()) |
233 | pcm_close(); | 268 | pcm_close(); |
234 | rb->splash(HZ/2, "Shutting down"); | 269 | rb->splash(HZ/2, "Closing Rockboy"); |
235 | 270 | ||
236 | savesettings(); | 271 | savesettings(); |
237 | 272 | ||
238 | cleanup(); | 273 | cleanup(); |
239 | 274 | ||
240 | |||
241 | return PLUGIN_OK; | 275 | return PLUGIN_OK; |
242 | } | 276 | } |
diff --git a/apps/plugins/rockboy/rockmacros.h b/apps/plugins/rockboy/rockmacros.h index d302fd04fe..ecf8a1ef6a 100644 --- a/apps/plugins/rockboy/rockmacros.h +++ b/apps/plugins/rockboy/rockmacros.h | |||
@@ -41,7 +41,7 @@ void ev_poll(void); | |||
41 | int do_user_menu(void); | 41 | int do_user_menu(void); |
42 | void loadstate(int fd); | 42 | void loadstate(int fd); |
43 | void savestate(int fd); | 43 | void savestate(int fd); |
44 | void setvidmode(int mode); | 44 | void setvidmode(void); |
45 | void set_pal(void); | 45 | void set_pal(void); |
46 | #if !defined(HAVE_LCD_COLOR) | 46 | #if !defined(HAVE_LCD_COLOR) |
47 | void vid_update(int scanline); | 47 | void vid_update(int scanline); |
@@ -116,9 +116,12 @@ void* memcpy(void* dst, const void* src, size_t size) ICODE_ATTR; | |||
116 | 116 | ||
117 | struct options { | 117 | struct options { |
118 | int A, B, START, SELECT, MENU; | 118 | int A, B, START, SELECT, MENU; |
119 | int UP, DOWN, LEFT, RIGHT; | ||
119 | int frameskip, fps, maxskip; | 120 | int frameskip, fps, maxskip; |
120 | int sound, fullscreen, showstats; | 121 | int sound, fullscreen, showstats; |
122 | int rotate; | ||
121 | int pal; | 123 | int pal; |
124 | int dirty; | ||
122 | }; | 125 | }; |
123 | 126 | ||
124 | bool plugbuf; | 127 | bool plugbuf; |
diff --git a/apps/plugins/rockboy/sound.c b/apps/plugins/rockboy/sound.c index 516b9c3f71..aba7f924b4 100644 --- a/apps/plugins/rockboy/sound.c +++ b/apps/plugins/rockboy/sound.c | |||
@@ -7,26 +7,41 @@ | |||
7 | #include "regs.h" | 7 | #include "regs.h" |
8 | #include "noise.h" | 8 | #include "noise.h" |
9 | 9 | ||
10 | static const byte dmgwave[16] = | ||
11 | { | ||
12 | 0xac, 0xdd, 0xda, 0x48, | ||
13 | 0x36, 0x02, 0xcf, 0x16, | ||
14 | 0x2c, 0x04, 0xe5, 0x2c, | ||
15 | 0xac, 0xdd, 0xda, 0x48 | ||
16 | }; | ||
17 | |||
18 | static const byte cgbwave[16] = | ||
19 | { | ||
20 | 0x00, 0xff, 0x00, 0xff, | ||
21 | 0x00, 0xff, 0x00, 0xff, | ||
22 | 0x00, 0xff, 0x00, 0xff, | ||
23 | 0x00, 0xff, 0x00, 0xff, | ||
24 | }; | ||
10 | 25 | ||
11 | static const byte sqwave[4][8] = | 26 | static const byte sqwave[4][8] = |
12 | { | 27 | { |
13 | { 0, 0,-1, 0, 0, 0, 0, 0 }, | 28 | { 0, 0,-1, 0, 0, 0, 0, 0 }, |
14 | { 0,-1,-1, 0, 0, 0, 0, 0 }, | 29 | { 0,-1,-1, 0, 0, 0, 0, 0 }, |
15 | { 0,-1,-1,-1,-1, 0, 0, 0 }, | 30 | { -1,-1,-1,-1, 0, 0, 0, 0 }, |
16 | { -1, 0, 0,-1,-1,-1,-1,-1 } | 31 | { -1, 0, 0,-1,-1,-1,-1,-1 } |
17 | }; | 32 | }; |
18 | 33 | ||
19 | static const int freqtab[8] = | 34 | static const int freqtab[8] = |
20 | { | 35 | { |
21 | (1<<18)*2, | 36 | (1<<14)*2, |
22 | (1<<18), | 37 | (1<<14), |
23 | (1<<18)/2, | 38 | (1<<14)/2, |
24 | (1<<18)/3, | 39 | (1<<14)/3, |
25 | (1<<18)/4, | 40 | (1<<14)/4, |
26 | (1<<18)/5, | 41 | (1<<14)/5, |
27 | (1<<18)/6, | 42 | (1<<14)/6, |
28 | (1<<18)/7 | 43 | (1<<14)/7 |
29 | }; | 44 | }; |
30 | 45 | ||
31 | struct snd snd IBSS_ATTR; | 46 | struct snd snd IBSS_ATTR; |
32 | 47 | ||
@@ -58,13 +73,14 @@ static void s2_freq(void) | |||
58 | static void s3_freq(void) | 73 | static void s3_freq(void) |
59 | { | 74 | { |
60 | int d = 2048 - (((R_NR34&7)<<8) + R_NR33); | 75 | int d = 2048 - (((R_NR34&7)<<8) + R_NR33); |
61 | if (RATE > d) S3.freq = 0; | 76 | if (RATE > (d<<3)) S3.freq = 0; |
62 | else S3.freq = (RATE << 21)/d; | 77 | else S3.freq = (RATE << 21)/d; |
63 | } | 78 | } |
64 | 79 | ||
65 | static void s4_freq(void) | 80 | static void s4_freq(void) |
66 | { | 81 | { |
67 | S4.freq = (freqtab[R_NR43&7] >> (R_NR43 >> 4)) * RATE; | 82 | S4.freq = (freqtab[R_NR43&7] >> (R_NR43 >> 4)) * RATE; |
83 | if (S4.freq >> 18) S4.freq = 1<<18; | ||
68 | } | 84 | } |
69 | 85 | ||
70 | void sound_dirty(void) | 86 | void sound_dirty(void) |
@@ -74,13 +90,13 @@ void sound_dirty(void) | |||
74 | S1.envol = R_NR12 >> 4; | 90 | S1.envol = R_NR12 >> 4; |
75 | S1.endir = (R_NR12>>3) & 1; | 91 | S1.endir = (R_NR12>>3) & 1; |
76 | S1.endir |= S1.endir - 1; | 92 | S1.endir |= S1.endir - 1; |
77 | S1.enlen = (R_NR12 & 3) << 15; | 93 | S1.enlen = (R_NR12 & 7) << 15; |
78 | s1_freq(); | 94 | s1_freq(); |
79 | S2.len = (64-(R_NR21&63)) << 13; | 95 | S2.len = (64-(R_NR21&63)) << 13; |
80 | S2.envol = R_NR22 >> 4; | 96 | S2.envol = R_NR22 >> 4; |
81 | S2.endir = (R_NR22>>3) & 1; | 97 | S2.endir = (R_NR22>>3) & 1; |
82 | S2.endir |= S2.endir - 1; | 98 | S2.endir |= S2.endir - 1; |
83 | S2.enlen = (R_NR22 & 3) << 15; | 99 | S2.enlen = (R_NR22 & 7) << 15; |
84 | s2_freq(); | 100 | s2_freq(); |
85 | S3.len = (256-R_NR31) << 20; | 101 | S3.len = (256-R_NR31) << 20; |
86 | s3_freq(); | 102 | s3_freq(); |
@@ -88,13 +104,12 @@ void sound_dirty(void) | |||
88 | S4.envol = R_NR42 >> 4; | 104 | S4.envol = R_NR42 >> 4; |
89 | S4.endir = (R_NR42>>3) & 1; | 105 | S4.endir = (R_NR42>>3) & 1; |
90 | S4.endir |= S4.endir - 1; | 106 | S4.endir |= S4.endir - 1; |
91 | S4.enlen = (R_NR42 & 3) << 15; | 107 | S4.enlen = (R_NR42 & 7) << 15; |
92 | s4_freq(); | 108 | s4_freq(); |
93 | } | 109 | } |
94 | 110 | ||
95 | void sound_reset(void) | 111 | void sound_off(void) |
96 | { | 112 | { |
97 | int i; | ||
98 | memset(&snd, 0, sizeof snd); | 113 | memset(&snd, 0, sizeof snd); |
99 | if (pcm.hz) snd.rate = (1<<21) / pcm.hz; | 114 | if (pcm.hz) snd.rate = (1<<21) / pcm.hz; |
100 | else snd.rate = 0; | 115 | else snd.rate = 0; |
@@ -115,11 +130,22 @@ void sound_reset(void) | |||
115 | R_NR44 = 0xBF; | 130 | R_NR44 = 0xBF; |
116 | R_NR50 = 0x77; | 131 | R_NR50 = 0x77; |
117 | R_NR51 = 0xF3; | 132 | R_NR51 = 0xF3; |
118 | R_NR52 = 0xF1; | 133 | R_NR52 = 0x70; |
119 | for (i = 0; i < 16; i++) WAVE[i] = -(i&1); | 134 | // for (i = 0; i < 16; i++) WAVE[i] = -(i&1); |
120 | sound_dirty(); | 135 | sound_dirty(); |
121 | } | 136 | } |
122 | 137 | ||
138 | void sound_reset() | ||
139 | { | ||
140 | memset(&snd, 0, sizeof snd); | ||
141 | if (pcm.hz) snd.rate = (1<<21) / pcm.hz; | ||
142 | else snd.rate = 0; | ||
143 | memcpy(WAVE, hw.cgb ? cgbwave : dmgwave, 16); | ||
144 | memcpy(ram.hi+0x30, WAVE, 16); | ||
145 | sound_off(); | ||
146 | R_NR52 = 0xF1; | ||
147 | } | ||
148 | |||
123 | void sound_mix(void) | 149 | void sound_mix(void) |
124 | { | 150 | { |
125 | int s, l, r, f, n; | 151 | int s, l, r, f, n; |
@@ -145,7 +171,8 @@ void sound_mix(void) | |||
145 | } | 171 | } |
146 | if (S1.swlen && (S1.swcnt += RATE) >= S1.swlen) | 172 | if (S1.swlen && (S1.swcnt += RATE) >= S1.swlen) |
147 | { | 173 | { |
148 | f = ((R_NR14 & 7) << 8) + R_NR13; | 174 | S1.swcnt -= S1.swlen; |
175 | f = S1.swfreq; | ||
149 | n = (R_NR10 & 7); | 176 | n = (R_NR10 & 7); |
150 | if (R_NR10 & 8) f -= (f >> n); | 177 | if (R_NR10 & 8) f -= (f >> n); |
151 | else f += (f >> n); | 178 | else f += (f >> n); |
@@ -153,14 +180,15 @@ void sound_mix(void) | |||
153 | S1.on = 0; | 180 | S1.on = 0; |
154 | else | 181 | else |
155 | { | 182 | { |
183 | S1.swfreq = f; | ||
156 | R_NR13 = f; | 184 | R_NR13 = f; |
157 | R_NR14 = (R_NR14 & 0xF8) | (f>>8); | 185 | R_NR14 = (R_NR14 & 0xF8) | (f>>8); |
158 | s1_freq_d(2048 - f); | 186 | s1_freq_d(2048 - f); |
159 | } | 187 | } |
160 | } | 188 | } |
161 | s <<= 2; | 189 | s <<= 2; |
162 | if (R_NR51 & 1) l += s; | 190 | if (R_NR51 & 1) r += s; |
163 | if (R_NR51 & 16) r += s; | 191 | if (R_NR51 & 16) l += s; |
164 | } | 192 | } |
165 | 193 | ||
166 | if (S2.on) | 194 | if (S2.on) |
@@ -177,8 +205,8 @@ void sound_mix(void) | |||
177 | if (S2.envol > 15) S2.envol = 15; | 205 | if (S2.envol > 15) S2.envol = 15; |
178 | } | 206 | } |
179 | s <<= 2; | 207 | s <<= 2; |
180 | if (R_NR51 & 2) l += s; | 208 | if (R_NR51 & 2) r += s; |
181 | if (R_NR51 & 32) r += s; | 209 | if (R_NR51 & 32) l += s; |
182 | } | 210 | } |
183 | 211 | ||
184 | if (S3.on) | 212 | if (S3.on) |
@@ -192,16 +220,16 @@ void sound_mix(void) | |||
192 | S3.on = 0; | 220 | S3.on = 0; |
193 | if (R_NR32 & 96) s <<= (3 - ((R_NR32>>5)&3)); | 221 | if (R_NR32 & 96) s <<= (3 - ((R_NR32>>5)&3)); |
194 | else s = 0; | 222 | else s = 0; |
195 | if (R_NR51 & 4) l += s; | 223 | if (R_NR51 & 4) r += s; |
196 | if (R_NR51 & 64) r += s; | 224 | if (R_NR51 & 64) l += s; |
197 | } | 225 | } |
198 | 226 | ||
199 | if (S4.on) | 227 | if (S4.on) |
200 | { | 228 | { |
201 | if (R_NR43 & 8) s = 1 & (noise7[ | 229 | if (R_NR43 & 8) s = 1 & (noise7[ |
202 | (S4.pos>>24)&15] >> ((S4.pos>>21)&7)); | 230 | (S4.pos>>20)&15] >> (7-((S4.pos>>17)&7))); |
203 | else s = 1 & (noise15[ | 231 | else s = 1 & (noise15[ |
204 | (S4.pos>>24)&4095] >> ((S4.pos>>21)&7)); | 232 | (S4.pos>>20)&4095] >> (7-((S4.pos>>17)&7))); |
205 | s = (-s) & S4.envol; | 233 | s = (-s) & S4.envol; |
206 | S4.pos += S4.freq; | 234 | S4.pos += S4.freq; |
207 | if ((R_NR44 & 64) && ((S4.cnt += RATE) >= S4.len)) | 235 | if ((R_NR44 & 64) && ((S4.cnt += RATE) >= S4.len)) |
@@ -213,9 +241,9 @@ void sound_mix(void) | |||
213 | if (S4.envol < 0) S4.envol = 0; | 241 | if (S4.envol < 0) S4.envol = 0; |
214 | if (S4.envol > 15) S4.envol = 15; | 242 | if (S4.envol > 15) S4.envol = 15; |
215 | } | 243 | } |
216 | s <<= 2; | 244 | s += s << 1; |
217 | if (R_NR51 & 8) l += s; | 245 | if (R_NR51 & 8) r += s; |
218 | if (R_NR51 & 128) r += s; | 246 | if (R_NR51 & 128) l += s; |
219 | } | 247 | } |
220 | 248 | ||
221 | l *= (R_NR50 & 0x07); | 249 | l *= (R_NR50 & 0x07); |
@@ -234,10 +262,10 @@ void sound_mix(void) | |||
234 | pcm_submit(); | 262 | pcm_submit(); |
235 | if (pcm.stereo) | 263 | if (pcm.stereo) |
236 | { | 264 | { |
237 | pcm.buf[pcm.pos++] = l+128; | 265 | pcm.buf[pcm.pos++] = ((signed char)(l))<<7; |
238 | pcm.buf[pcm.pos++] = r+128; | 266 | pcm.buf[pcm.pos++] = ((signed char)(r))<<7; |
239 | } | 267 | } |
240 | else pcm.buf[pcm.pos++] = ((l+r)>>1)+128; | 268 | else pcm.buf[pcm.pos++] = ((signed char)((l+r)>>1))<<7; |
241 | } | 269 | } |
242 | } | 270 | } |
243 | R_NR52 = (R_NR52&0xf0) | S1.on | (S2.on<<1) | (S3.on<<2) | (S4.on<<3); | 271 | R_NR52 = (R_NR52&0xf0) | S1.on | (S2.on<<1) | (S3.on<<2) | (S4.on<<3); |
@@ -256,12 +284,13 @@ byte sound_read(byte r) | |||
256 | void s1_init(void) | 284 | void s1_init(void) |
257 | { | 285 | { |
258 | S1.swcnt = 0; | 286 | S1.swcnt = 0; |
287 | S1.swfreq = ((R_NR14&7)<<8) + R_NR13; | ||
259 | S1.envol = R_NR12 >> 4; | 288 | S1.envol = R_NR12 >> 4; |
260 | S1.endir = (R_NR12>>3) & 1; | 289 | S1.endir = (R_NR12>>3) & 1; |
261 | S1.endir |= S1.endir - 1; | 290 | S1.endir |= S1.endir - 1; |
262 | S1.enlen = (R_NR12 & 7) << 15; | 291 | S1.enlen = (R_NR12 & 7) << 15; |
292 | if (!S1.on) S1.pos = 0; | ||
263 | S1.on = 1; | 293 | S1.on = 1; |
264 | S1.pos = 0; | ||
265 | S1.cnt = 0; | 294 | S1.cnt = 0; |
266 | S1.encnt = 0; | 295 | S1.encnt = 0; |
267 | } | 296 | } |
@@ -272,17 +301,20 @@ void s2_init(void) | |||
272 | S2.endir = (R_NR22>>3) & 1; | 301 | S2.endir = (R_NR22>>3) & 1; |
273 | S2.endir |= S2.endir - 1; | 302 | S2.endir |= S2.endir - 1; |
274 | S2.enlen = (R_NR22 & 7) << 15; | 303 | S2.enlen = (R_NR22 & 7) << 15; |
304 | if (!S2.on) S2.pos = 0; | ||
275 | S2.on = 1; | 305 | S2.on = 1; |
276 | S2.pos = 0; | ||
277 | S2.cnt = 0; | 306 | S2.cnt = 0; |
278 | S2.encnt = 0; | 307 | S2.encnt = 0; |
279 | } | 308 | } |
280 | 309 | ||
281 | void s3_init(void) | 310 | void s3_init(void) |
282 | { | 311 | { |
283 | S3.pos = 0; | 312 | int i; |
313 | if (!S3.on) S3.pos = 0; | ||
284 | S3.cnt = 0; | 314 | S3.cnt = 0; |
285 | S3.on = R_NR30 >> 7; | 315 | S3.on = R_NR30 >> 7; |
316 | if (S3.on) for (i = 0; i < 16; i++) | ||
317 | ram.hi[i+0x30] = 0x13 ^ ram.hi[i+0x31]; | ||
286 | } | 318 | } |
287 | 319 | ||
288 | void s4_init(void) | 320 | void s4_init(void) |
@@ -306,7 +338,8 @@ void sound_write(byte r, byte b) | |||
306 | if ((r & 0xF0) == 0x30) | 338 | if ((r & 0xF0) == 0x30) |
307 | { | 339 | { |
308 | if (S3.on) sound_mix(); | 340 | if (S3.on) sound_mix(); |
309 | if (!S3.on) WAVE[r - 0x30] = b; | 341 | if (!S3.on) |
342 | WAVE[r-0x30] = ram.hi[r] = b; | ||
310 | return; | 343 | return; |
311 | } | 344 | } |
312 | sound_mix(); | 345 | sound_mix(); |
@@ -314,6 +347,8 @@ void sound_write(byte r, byte b) | |||
314 | { | 347 | { |
315 | case RI_NR10: | 348 | case RI_NR10: |
316 | R_NR10 = b; | 349 | R_NR10 = b; |
350 | S1.swlen = ((R_NR10>>4) & 7) << 14; | ||
351 | S1.swfreq = ((R_NR14&7)<<8) + R_NR13; | ||
317 | break; | 352 | break; |
318 | case RI_NR11: | 353 | case RI_NR11: |
319 | R_NR11 = b; | 354 | R_NR11 = b; |
@@ -361,7 +396,7 @@ void sound_write(byte r, byte b) | |||
361 | break; | 396 | break; |
362 | case RI_NR31: | 397 | case RI_NR31: |
363 | R_NR31 = b; | 398 | R_NR31 = b; |
364 | S3.len = (256-R_NR31) << 20; | 399 | S3.len = (256-R_NR31) << 13; |
365 | break; | 400 | break; |
366 | case RI_NR32: | 401 | case RI_NR32: |
367 | R_NR32 = b; | 402 | R_NR32 = b; |
@@ -403,13 +438,9 @@ void sound_write(byte r, byte b) | |||
403 | case RI_NR52: | 438 | case RI_NR52: |
404 | R_NR52 = b; | 439 | R_NR52 = b; |
405 | if (!(R_NR52 & 128)) | 440 | if (!(R_NR52 & 128)) |
406 | sound_reset(); | 441 | sound_off(); |
407 | break; | 442 | break; |
408 | default: | 443 | default: |
409 | return; | 444 | return; |
410 | } | 445 | } |
411 | } | 446 | } |
412 | |||
413 | |||
414 | |||
415 | |||
diff --git a/apps/plugins/rockboy/sound.h b/apps/plugins/rockboy/sound.h index fe3557cd7e..88897ef9ce 100644 --- a/apps/plugins/rockboy/sound.h +++ b/apps/plugins/rockboy/sound.h | |||
@@ -9,6 +9,7 @@ struct sndchan | |||
9 | unsigned pos; | 9 | unsigned pos; |
10 | int cnt, encnt, swcnt; | 10 | int cnt, encnt, swcnt; |
11 | int len, enlen, swlen; | 11 | int len, enlen, swlen; |
12 | int swfreq; | ||
12 | int freq; | 13 | int freq; |
13 | int envol, endir; | 14 | int envol, endir; |
14 | }; | 15 | }; |
diff --git a/apps/plugins/rockboy/sys_rockbox.c b/apps/plugins/rockboy/sys_rockbox.c index 6cbbe523f7..60cac0a88d 100644 --- a/apps/plugins/rockboy/sys_rockbox.c +++ b/apps/plugins/rockboy/sys_rockbox.c | |||
@@ -24,36 +24,11 @@ | |||
24 | #include "hw.h" | 24 | #include "hw.h" |
25 | #include "config.h" | 25 | #include "config.h" |
26 | 26 | ||
27 | #if (CONFIG_KEYPAD == IPOD_4G_PAD) | 27 | #if (CONFIG_KEYPAD == SANSA_E200_PAD) |
28 | |||
29 | #define ROCKBOY_PAD_LEFT BUTTON_LEFT | ||
30 | #define ROCKBOY_PAD_RIGHT BUTTON_RIGHT | ||
31 | #define ROCKBOY_PAD_UP BUTTON_MENU | ||
32 | #define ROCKBOY_PAD_DOWN BUTTON_PLAY | ||
33 | |||
34 | #elif (CONFIG_KEYPAD == IRIVER_H10_PAD) | ||
35 | |||
36 | #define ROCKBOY_PAD_LEFT BUTTON_LEFT | ||
37 | #define ROCKBOY_PAD_RIGHT BUTTON_RIGHT | ||
38 | #define ROCKBOY_PAD_UP BUTTON_SCROLL_UP | ||
39 | #define ROCKBOY_PAD_DOWN BUTTON_SCROLL_DOWN | ||
40 | |||
41 | #elif (CONFIG_KEYPAD == SANSA_E200_PAD) | ||
42 | 28 | ||
43 | #define ROCKBOY_SCROLLWHEEL | 29 | #define ROCKBOY_SCROLLWHEEL |
44 | #define ROCKBOY_SCROLLWHEEL_CC BUTTON_SCROLL_UP | 30 | #define ROCKBOY_SCROLLWHEEL_CC BUTTON_SCROLL_UP |
45 | #define ROCKBOY_SCROLLWHEEL_CW BUTTON_SCROLL_DOWN | 31 | #define ROCKBOY_SCROLLWHEEL_CW BUTTON_SCROLL_DOWN |
46 | #define ROCKBOY_PAD_LEFT BUTTON_LEFT | ||
47 | #define ROCKBOY_PAD_RIGHT BUTTON_RIGHT | ||
48 | #define ROCKBOY_PAD_UP BUTTON_UP | ||
49 | #define ROCKBOY_PAD_DOWN BUTTON_DOWN | ||
50 | |||
51 | #else | ||
52 | |||
53 | #define ROCKBOY_PAD_LEFT BUTTON_LEFT | ||
54 | #define ROCKBOY_PAD_RIGHT BUTTON_RIGHT | ||
55 | #define ROCKBOY_PAD_UP BUTTON_UP | ||
56 | #define ROCKBOY_PAD_DOWN BUTTON_DOWN | ||
57 | 32 | ||
58 | #endif | 33 | #endif |
59 | 34 | ||
@@ -159,10 +134,10 @@ void ev_poll(void) | |||
159 | #else | 134 | #else |
160 | if(released) { | 135 | if(released) { |
161 | ev.type = EV_RELEASE; | 136 | ev.type = EV_RELEASE; |
162 | if(released & ROCKBOY_PAD_LEFT) { ev.code=PAD_LEFT; ev_postevent(&ev); } | 137 | if(released & options.LEFT) { ev.code=PAD_LEFT; ev_postevent(&ev); } |
163 | if(released & ROCKBOY_PAD_RIGHT) {ev.code=PAD_RIGHT; ev_postevent(&ev);} | 138 | if(released & options.RIGHT) {ev.code=PAD_RIGHT; ev_postevent(&ev);} |
164 | if(released & ROCKBOY_PAD_DOWN) { ev.code=PAD_DOWN; ev_postevent(&ev); } | 139 | if(released & options.DOWN) { ev.code=PAD_DOWN; ev_postevent(&ev); } |
165 | if(released & ROCKBOY_PAD_UP) { ev.code=PAD_UP; ev_postevent(&ev); } | 140 | if(released & options.UP) { ev.code=PAD_UP; ev_postevent(&ev); } |
166 | if(released & options.A) { ev.code=PAD_A; ev_postevent(&ev); } | 141 | if(released & options.A) { ev.code=PAD_A; ev_postevent(&ev); } |
167 | if(released & options.B) { ev.code=PAD_B; ev_postevent(&ev); } | 142 | if(released & options.B) { ev.code=PAD_B; ev_postevent(&ev); } |
168 | if(released & options.START) { | 143 | if(released & options.START) { |
@@ -176,10 +151,10 @@ void ev_poll(void) | |||
176 | } | 151 | } |
177 | if(pressed) { /* button press */ | 152 | if(pressed) { /* button press */ |
178 | ev.type = EV_PRESS; | 153 | ev.type = EV_PRESS; |
179 | if(pressed & ROCKBOY_PAD_LEFT) { ev.code=PAD_LEFT; ev_postevent(&ev); } | 154 | if(pressed & options.LEFT) { ev.code=PAD_LEFT; ev_postevent(&ev); } |
180 | if(pressed & ROCKBOY_PAD_RIGHT) { ev.code=PAD_RIGHT; ev_postevent(&ev);} | 155 | if(pressed & options.RIGHT) { ev.code=PAD_RIGHT; ev_postevent(&ev);} |
181 | if(pressed & ROCKBOY_PAD_DOWN) { ev.code=PAD_DOWN; ev_postevent(&ev); } | 156 | if(pressed & options.DOWN) { ev.code=PAD_DOWN; ev_postevent(&ev); } |
182 | if(pressed & ROCKBOY_PAD_UP) { ev.code=PAD_UP; ev_postevent(&ev); } | 157 | if(pressed & options.UP) { ev.code=PAD_UP; ev_postevent(&ev); } |
183 | if(pressed & options.A) { ev.code=PAD_A; ev_postevent(&ev); } | 158 | if(pressed & options.A) { ev.code=PAD_A; ev_postevent(&ev); } |
184 | if(pressed & options.B) { ev.code=PAD_B; ev_postevent(&ev); } | 159 | if(pressed & options.B) { ev.code=PAD_B; ev_postevent(&ev); } |
185 | if(pressed & options.START) { | 160 | if(pressed & options.START) { |