Chris Dick / Mbed 2 deprecated Gameduino_Split_Screen_demo

Dependencies:   Gameduino mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "GD.h"
00003 
00004 #include "splitscreen.h"
00005 #include "shield.h"
00006 
00007 GDClass GD(ARD_MOSI, ARD_MISO, ARD_SCK, ARD_D9, USBTX, USBRX) ;
00008 
00009 /*
00010  For the splitscreen microprogram, the COMM area holds 8 short words
00011  that control the 3-way screen split:
00012 
00013  COMM+0   SCROLL_X for top section
00014  COMM+2   SCROLL_Y for top section
00015  COMM+4   Y-coordinate of start of middle section
00016  COMM+6   SCROLL_X for middle section
00017  COMM+8   SCROLL_Y for middle section
00018  COMM+10  Y-coordinate of start of bottom section
00019  COMM+12  SCROLL_X for bottom section
00020  COMM+14  SCROLL_Y for bottom section
00021 */
00022 
00023 #include "splitscreen_graphics.h"
00024 
00025 void setup()
00026 {
00027   GD.begin();
00028 
00029   GD.copy(RAM_PIC, splitscreen_pic, sizeof(splitscreen_pic));
00030   GD.copy(RAM_CHR, splitscreen_chr, sizeof(splitscreen_chr));
00031   GD.copy(RAM_PAL, splitscreen_pal, sizeof(splitscreen_pal));
00032 
00033   GD.wr16(COMM+0, 0);
00034   GD.wr16(COMM+2, 0);
00035   GD.wr16(COMM+4, 100);   // split at line 100
00036   GD.wr16(COMM+6, 0);
00037   GD.wr16(COMM+8, 140);
00038   GD.wr16(COMM+10, 200);   // split at line 200
00039   GD.wr16(COMM+12, 0);
00040   GD.wr16(COMM+14, (511 & (82 - 200))); // show line 82 at line 200
00041 
00042   GD.microcode(splitscreen_code, sizeof(splitscreen_code));
00043 }
00044 
00045 // Set the scroll registers for the middle screen secion to (x, y)
00046 static void scrollxy(uint16_t x, uint16_t y)
00047 {
00048   GD.wr16(COMM+6, x);
00049   GD.wr16(COMM+8, y);
00050 }
00051 
00052 int main()
00053 {
00054 setup();
00055 while (1){
00056   static int i;
00057   float th = i / 16.;
00058   scrollxy(55 + 50 * cos(th), 150 + 50 * sin(th));
00059   GD.wr16(COMM+12, i);
00060   i++;
00061   GD.waitvblank();
00062 }}