don't click here

Sieve of Eratosthenes MD

Discussion in 'Technical Discussion' started by snkenjoi, Aug 5, 2009.

  1. snkenjoi

    snkenjoi

    Tech Member
    89
    7
    8
    This is the first MD ROM I've written from scratch. It's a simple Sieve of Eratosthenes implemented in C.

    [​IMG]

    Download

    I've gotta say thanks to Stef for the great DevKit I used to make this. It's the first one I've come across that I've been actually able to compile shit with :)

    Have some source;

    Code (Text):
    1. #include "genesis.h"
    2. #include "x.h"
    3.  
    4. const u16 pal_yellow[16] =
    5. {
    6.     0x0000,
    7.     0x0022,
    8.     0x0044,
    9.     0x0066,
    10.     0x0088,
    11.     0x00AA,
    12.     0x00CC,
    13.     0x00EE,
    14.  
    15.     0x0EEE,
    16.     0x0EEE,
    17.     0x0EEE,
    18.     0x0EEE,
    19.     0x0EEE,
    20.     0x0EEE,
    21.     0x0EEE,
    22.     0x0EEE
    23. };
    24.  
    25. static void eratosthenes();
    26.  
    27. int main()
    28. {
    29.     VDP_setPalette(0, pal_yellow);
    30.     VDP_drawText(APLAN, "Sieve of Eratosthenes MD", 0x8000, 1, 1);
    31.     VDP_drawText(APLAN, "by  snkenjoi", 0x8000, 24, 25);
    32.     setBitmapMode(BITMAP_WIDTH, BITMAP_HEIGHT);
    33.     loadGenBmp16ToBitmap(x, 21, 10, 0x10);
    34.     eratosthenes();
    35.     return 0;
    36. }
    37.  
    38. void eratosthenes()
    39. {
    40.     char str[255];
    41.     int I,k,j = 0;
    42.     int arr[15999]; //15999
    43.     int max = (sizeof(arr)/sizeof(arr[0]));
    44.  
    45.  
    46. &nbsp;&nbsp;&nbsp;&nbsp;for (I = 0;I<max;I+=2) {
    47. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arr[I] = 1;
    48. &nbsp;&nbsp;&nbsp;&nbsp;}
    49. &nbsp;&nbsp;&nbsp;&nbsp;
    50. &nbsp;&nbsp;&nbsp;&nbsp;VDP_drawText(APLAN, "2", 0x8000, 1, 2);
    51. &nbsp;&nbsp;&nbsp;&nbsp;
    52. &nbsp;&nbsp;&nbsp;&nbsp;for (k = 0;k<max;k++){
    53. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (I = 0;I<max;I++) {
    54. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(arr[I] == 0) {arr[I] = 1; j = I;wait(5000);intToStr(I+2, str, 1);VDP_drawText(APLAN, str, 0x8000, 1, 2);break;}
    55. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    56. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (I = j;I<max;I+=j+2) { arr[I] = 1; }
    57. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (j*j>max+2){break;}
    58. &nbsp;&nbsp;&nbsp;&nbsp;}
    59. &nbsp;&nbsp;&nbsp;&nbsp;for (I = 0;I<max;I++) {
    60. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(arr[I] == 0) {arr[I] = 1;wait(5000);intToStr(I+2, str, 1);VDP_drawText(APLAN, str, 0x8000, 1, 2);};
    61. &nbsp;&nbsp;&nbsp;&nbsp;}
    62. }
    Maybe I'll make something useful next time ;)
     
  2. Andlabs

    Andlabs

    「いっきまーす」 Wiki Sysop
    2,175
    1
    0
    Writing my own MD/Genesis sound driver :D
    You're welcome (for linking you to the devkit on IRC). And this is interesting. Perhaps now the Genesis can be used for cryptography? :v:

    And shameless self-advertising, thanks to Doug McIllroy: http://plan9.bell-labs.com/sources/contrib/pietro/sieve.c. Put that on the Genesis :v:
     
  3. TmEE

    TmEE

    Master of OPL3-SA2/3 Tech Member
    1,726
    2
    18
    Estonia, Rapla City
    T-04YBSC-A !
    well, this works nicely on real HW :)
     
  4. Overlord

    Overlord

    Now playable in Smash Bros Ultimate Moderator
    19,241
    974
    93
    Long-term happiness
    A C devkit for Megadrive? Nice.

    Good work on the ROM, too =P Is it supposed to just count up to 15991 in the top left, though, or do a list like the wiki page?
     
  5. Andlabs

    Andlabs

    「いっきまーす」 Wiki Sysop
    2,175
    1
    0
    Writing my own MD/Genesis sound driver :D
    C devkits have existed for a while now: SGCC and XGCC have been around for years. But this is the first to have a full programming API.
     
  6. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,718
    1
    0
    being an asshole =P
    Moreover, there's a C devkit for MD from back to 1994. Not to mention that Sega also had its own C devkit (Sonic Spinball, anyone?).
     
  7. Overlord

    Overlord

    Now playable in Smash Bros Ultimate Moderator
    19,241
    974
    93
    Long-term happiness
    Well, yes. But did the public have access to that? No =P

    I must admit I was unaware of those 2. But by the sound of it this one is better anyway :)
     
  8. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,718
    1
    0
    being an asshole =P
    The one from 1994? Yes. Spinball was released on 1993 so that should make it obvious that it wasn't the one I was talking about :P
     
  9. Overlord

    Overlord

    Now playable in Smash Bros Ultimate Moderator
    19,241
    974
    93
    Long-term happiness
    HUSH >=P

    Fair point, but this one still stands as the most fully featured.
     
  10. Yuzu

    Yuzu

    Member
    2,548
    51
    28
    I wonder what C dev kit Megaman: The Wily Wars used. According to Protoman the game was coded in C(he gave up disassembling it for that reason) and was released in late 1994 for all regions.
     
  11. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,718
    1
    0
    being an asshole =P
    Once Oerg was messing up with his Mega Drive hardware (overclocking I think) and he tried a game from 1995. The game threw out a "not enough memory available" error and was emitted by some kind of library made by Sega (I don't remember the exact message right now). So I guess Sega made a C library for the Mega Drive.