Advertisement
LuigiBlood

64ddtest

Nov 5th, 2014
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include <libdragon.h>
  6.  
  7. static resolution_t res = RESOLUTION_320x240;
  8. static bitdepth_t bit = DEPTH_32_BPP;
  9.  
  10. uint32_t io_read_abs(uint32_t pi_address)
  11. {
  12.     //replacement for io_read to not use cart space
  13.     volatile uint32_t *uncached_address = (uint32_t *)pi_address;
  14.     uint32_t retval = 0;
  15.  
  16.     disable_interrupts();
  17.  
  18.     /* Wait until there isn't a DMA transfer and grab a word */
  19.     while (dma_busy()) ;
  20.     MEMORY_BARRIER();
  21.     retval = *uncached_address;
  22.     MEMORY_BARRIER();
  23.  
  24.     enable_interrupts();
  25.  
  26.     return retval;
  27. }
  28.  
  29. int detect64dd_ipl(void)
  30. {
  31.     //Look at 0x9FF00 from the IPL.
  32.     uint32_t test = io_read_abs(0x0609FF00);
  33.  
  34.     //Check if the highest byte is 0xC3
  35.     test &= 0xFF000000;
  36.     if (test == 0xC3000000)
  37.     return 1;   //if yes, then retail 64DD is present
  38.     else
  39.     return 0;   //if not, then there are no 64DD connected.
  40. }
  41.  
  42. int main(void)
  43. {
  44.     /* enable interrupts (on the CPU) */
  45.     init_interrupts();
  46.  
  47.     /* Initialize peripherals */
  48.     display_init( res, bit, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
  49.     console_init();
  50.     controller_init();
  51.  
  52.     console_set_render_mode(RENDER_MANUAL);
  53.  
  54.     //64DD IPL test
  55.     int dd_present = detect64dd_ipl();
  56.  
  57.     /* Main loop test */
  58.     while(1)
  59.     {
  60.         console_clear();
  61.  
  62.         /* To do initialize routines */
  63.         controller_scan();
  64.  
  65.     printf("64dd_test by LuigiBlood\n\n");
  66.  
  67.     if(dd_present == 1)
  68.         printf("Retail 64DD has been found (IPL)\n\n");
  69.     else
  70.         printf("Retail 64DD has NOT been found (IPL)\n\n");
  71.  
  72.         struct controller_data keys = get_keys_down();
  73.  
  74.         int controllers = get_controllers_present();
  75.  
  76.         printf( "Controller 1 %spresent\n", (controllers & CONTROLLER_1_INSERTED) ? "" : "not " );
  77.  
  78.         if( keys.c[0].A )
  79.         {
  80.             printf("YOU PRESSED A");
  81.         }
  82.  
  83.         console_render();
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement