Created
          August 8, 2020 03:09 
        
      - 
      
- 
        Save JettMonstersGoBoom/ef35c00506576fb39eacc18a22365b32 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // bytebytejump bytepusher implementation | |
| // build with | |
| // tcc bpush.c migr.dll | |
| #include "migr.h" | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| extern __declspec(dllimport) MIGR migr; | |
| // fake wav chunk for 8bit pcm, just the header | |
| signed char audio_buffer[368*2] = { | |
| 0x52, 0x49, 0x46, 0x46, 0x68, 0x01, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, | |
| 0x66, 0x6D, 0x74, 0x20, 0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 0x00, 0x3c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, | |
| 0x16, 0x00, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, | |
| 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71, | |
| 0x66, 0x61, 0x63, 0x74, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, | |
| 0x64, 0x61, 0x74, 0x61, 0x00, 0x01, 0x00, 0x00 | |
| }; | |
| // memory for VM | |
| unsigned char mem[0x1000008], *pc; | |
| // keys | |
| static const char keymap[] = { 'X', '1', '2', '3', 'Q', 'W', 'E', 'A','S', 'D', 'Z', 'C', '4', 'R', 'F', 'V'}; | |
| void main(int argc,char *argv[]) | |
| { | |
| image_t *byte_fb; | |
| uint8_t *original_buffer; | |
| // create window | |
| migr.Create("BytePusher",256,256,2,2); | |
| byte_fb = migr.ImageRaw(256,256,8); | |
| // keep the internal pointer safe to restore later | |
| original_buffer=byte_fb->image; | |
| // create palette | |
| memset(&byte_fb->clut[0],0,768); | |
| // create default palette | |
| for (int q=0;q<240;q++) | |
| { | |
| byte_fb->clut[(q*3)+2] = (q % 6) * 0x33; | |
| byte_fb->clut[(q*3)+1] = ((q/6) % 6) * 0x33; | |
| byte_fb->clut[(q*3)+0] = ((q/36) % 6) * 0x33; | |
| } | |
| // check for args | |
| if (argc==2) | |
| migr.Load_to(argv[1],&mem[0]); | |
| else | |
| migr.Load_to("assets/sine-scroll.bp",&mem[0]); | |
| // set a font | |
| migr.Font("assets/ascii.bmp",16,16); | |
| // set tint pen | |
| migr.Pen(255,255,255,255); | |
| void *wav = migr.WaveMem(&audio_buffer[0],368); | |
| // loop | |
| while(!migr.Update(NULL)) | |
| { | |
| // draw the buffer | |
| migr.Blit(byte_fb,0,0,0,0,256,256,0,true); | |
| migr.String(0,4,"FPS %d\nBPC %06X\nVID %06X\nAUD %06X",migr.fps,mem[2]<<16 | mem[3]<<8 | mem[4],mem[5]<<16,mem[6]<<16 | mem[7]<<8); | |
| // handle keyboard and update memory | |
| { | |
| uint16_t kb = 0; | |
| for (int q=0;q<16;q++) | |
| if (migr.Key(keymap[q])==1) | |
| kb|=1<<q; | |
| mem[0] = kb>>8; | |
| mem[1] = kb; | |
| } | |
| // run bytepusher | |
| pc = mem + (mem[2]<<16 | mem[3]<<8 | mem[4]); | |
| int i = 65536; | |
| do { | |
| mem[pc[3]<<16 | pc[4]<<8 | pc[5]] = mem[pc[0]<<16 | pc[1]<<8 | pc[2]]; | |
| pc = mem + (pc[6]<<16 | pc[7]<<8 | pc[8]); | |
| } while (--i); | |
| // get video address | |
| int address = (mem[5] << 16); | |
| // set our image to this buffer address | |
| byte_fb->image = &mem[address]; | |
| // get audio address | |
| address = mem[6]<<16 | mem[7]<<8; | |
| // upshift to wav | |
| for (int q=0;q<256;q++) | |
| audio_buffer[0x50 +q] = 128+mem[address+q]; | |
| // play it | |
| migr.WavePlay(wav); | |
| // dirty the image | |
| migr.DirtyImage(byte_fb); | |
| } | |
| // restore before closing | |
| byte_fb->image = original_buffer; | |
| migr.Close(); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment