Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //**********************************************************************************************
- //
- // Title: GB to Video
- // Author: FriendofMegaman
- //
- // Cleaned a bit by Jazzmarazz
- //
- //**********************************************************************************************
- //**********************************************************************************************
- //
- // Designate Pins with Names
- //
- //**********************************************************************************************
- // Reassign according to your pinout
- const int pVsync = 2;
- const int pClock = 3;
- const int pData0 = 4;
- const int pData1 = 5;
- const int pHsync = 6;
- //**********************************************************************************************
- //
- // Create them Variables
- //
- //**********************************************************************************************
- int vsync = 0;
- int clock = 0;
- unsigned char data0 = 0;
- unsigned char data1 = 0;
- int hsync = 0;
- int vsync_prev = 0;
- int clock_prev = 0;
- int hsync_prev = 0;
- unsigned char pixel = 0;
- int line = 0;
- int offset = 0;
- int array_offset = 0;
- int byte_offset = 0;
- int bit_offset;
- unsigned char frame[5760];
- void setup(){
- Serial.begin(1);
- memset(frame,0,sizeof(frame));
- }
- //**********************************************************************************************
- //
- // Main Loop
- //
- //**********************************************************************************************
- void loop() {
- vsync = digitalRead(pVsync),
- clock = digitalRead(pClock),
- data0 = digitalRead(pData0),
- data1 = digitalRead(pData1),
- hsync = digitalRead(pHsync);
- readClock();
- readHsync();
- readVsync();
- clock_prev = clock;
- vsync_prev = vsync;
- hsync_prev = hsync;
- }
- //**********************************************************************************************
- //
- // Read hsync
- //
- //**********************************************************************************************
- void readHsync(){
- // Read HSYNC (rising edge)
- if (hsync_prev == LOW && hsync == HIGH){
- // Next line
- line++;
- offset = 0;
- }
- return;
- }
- //**********************************************************************************************
- //
- // Read vsync
- //
- //**********************************************************************************************
- void readVsync(){
- if (vsync_prev==LOW && vsync==HIGH){
- // Next frame
- // Frame divider 0x1E001E00
- Serial.write(0x1E);
- Serial.write(0x00);
- Serial.write(0x1E);
- Serial.write(0x00);
- // Send and nullify frame data
- Serial.write(frame, 5760);
- memset(frame, 0, sizeof(frame));
- line = 0;
- offset = 0;
- }
- return;
- }
- //**********************************************************************************************
- //
- // Read clock
- //
- //**********************************************************************************************
- void readClock(){
- if (clock_prev == HIGH && clock == LOW){
- // Read pixels
- if (offset<160 && line<144){
- pixel = 2*data1+data0;
- // ************ IMPORTANT ************
- // This part could be implemented as 2-dimensional array, I'm just saving RAM. I tried to make it 2D and the result
- // was the same.
- // ****************************************
- // Offset in the frame bit map
- bit_offset = (line*320)+offset*2;
- // The actual char in the frame array
- array_offset = bit_offset/8;
- // The offset within one byte
- byte_offset = bit_offset%8;
- // Put the pixel into frame
- frame[array_offset]+=(pixel<<byte_offset);
- }
- offset++;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement