├── Register ├── Color_Data.dat ├── Font_GFX.dat ├── Sprite_Data.dat ├── register.txt ├── register.xls └── register_1.xls ├── System ├── System.xls ├── TODO └── system.txt ├── asm ├── README ├── asm.c ├── datagen ├── instr ├── mem.png ├── mkfile └── modes ├── codec ├── codec.c ├── codec.h ├── error.c ├── error.h └── main.c ├── cs400.features ├── AUTHORS ├── Makefile ├── Project ├── assembler │ ├── .gitignore │ ├── Makefile │ ├── README │ ├── assembler.h │ ├── data.h │ ├── main.c │ ├── pre.hs │ ├── pretest │ └── snes-memory-layout.png ├── compiler │ ├── Makefile │ ├── asm.lisp │ ├── c-analyze.lisp │ ├── c.lisp │ ├── compiler-lib.c.lisp │ ├── compiler.lisp │ ├── cs400-compiler.asd │ ├── inputs │ │ ├── asm │ │ ├── c │ │ └── colors.asm │ ├── lib.lisp │ ├── macroexpand-dammit.lisp │ ├── notes │ │ ├── c-examples.lisp │ │ ├── c.c │ │ ├── compilation-examples │ │ └── oo │ └── package.lisp ├── docs │ ├── Compiler.ppt.gz │ ├── Makefile │ ├── presentation-3 │ │ ├── Makefile │ │ ├── input1.c.lisp │ │ ├── input2.c.lisp │ │ ├── presentation-3.org │ │ └── show.lisp │ └── prospectus.tex ├── flashing-colors │ ├── Makefile │ └── flashing.c.lisp ├── jormungandr │ ├── JormungandrChar.dat │ ├── JormungandrColor.dat │ ├── JormungandrFloorMap.dat │ ├── JormungandrFrameMap.dat │ ├── JormungandrTrailMap.dat │ ├── Makefile │ └── jormungandr.asm └── phoenix │ ├── Makefile │ ├── Phoenix_Char.dat │ ├── Phoenix_Color.dat │ ├── Phoenix_Frame_BG_Map.dat │ ├── Phoenix_Star_BG_Map.dat │ └── phoenix.asm ├── cs400.master ├── AUTHORS ├── docs │ ├── Compiler.ppt.gz │ ├── Makefile │ ├── final-docs │ │ └── final-docs.org │ ├── presentation-3 │ │ ├── Makefile │ │ ├── input1.c.lisp │ │ ├── input2.c.lisp │ │ ├── presentation-3.org │ │ └── show.lisp │ └── prospectus.tex ├── games │ ├── flashing-colors │ │ ├── Makefile │ │ └── flashing.c.lisp │ ├── jormungandr │ │ ├── JormungandrChar.dat │ │ ├── JormungandrColor.dat │ │ ├── JormungandrFloorMap.dat │ │ ├── JormungandrFrameMap.dat │ │ ├── JormungandrTrailMap.dat │ │ ├── Makefile │ │ └── jormungandr.asm │ ├── phoenix │ │ ├── char.dat │ │ ├── color.dat │ │ ├── frame_bg_map.dat │ │ ├── mkfile │ │ ├── phoenix.asm │ │ └── star_bg_map.dat │ └── pong │ │ ├── Makefile │ │ ├── interrupt.asm │ │ ├── pong.asm │ │ ├── pong.h │ │ ├── snes-registers.h │ │ ├── temp.tar │ │ ├── temp.tgz │ │ └── toplevel.asm └── util │ ├── README │ ├── asm.c │ ├── asm.h │ ├── cc │ ├── Makefile │ ├── asm.lisp │ ├── c-analize.lisp │ ├── c-impl.lisp │ ├── c.lisp │ ├── compiler.lisp │ ├── cs400-compiler.asd │ ├── inputs │ │ ├── asm │ │ ├── c │ │ ├── colors.asm │ │ ├── pongChar.dat │ │ ├── pongFrame.dat │ │ ├── pongPallet.dat │ │ ├── reset.asm │ │ └── snes_registers.h │ ├── lib.lisp │ ├── macroexpand-dammit.lisp │ ├── notes │ │ ├── c-examples.lisp │ │ ├── c.c │ │ ├── compilation-examples │ │ └── oo │ └── package.lisp │ ├── data.rc │ ├── instr │ ├── mem.png │ ├── mkfile │ └── modes ├── cs400.passes ├── AUTHORS ├── Makefile ├── Project ├── assembler │ ├── .gitignore │ ├── Makefile │ ├── README │ ├── assembler.h │ ├── data.h │ ├── main.c │ ├── pre.hs │ ├── pretest │ └── snes-memory-layout.png ├── compiler │ ├── Makefile │ ├── asm.lisp │ ├── back.lisp │ ├── c-analize.lisp │ ├── c-impl.lisp │ ├── compiler.lisp │ ├── cs400-compiler.asd │ ├── far-back.lisp │ ├── front.lisp │ ├── inputs │ │ ├── asm │ │ ├── c │ │ ├── colors.asm │ │ ├── control-structures.c.lisp │ │ ├── pongChar.dat │ │ ├── pongFrame.dat │ │ ├── pongPallet.dat │ │ ├── reset.asm │ │ └── snes_registers.h │ ├── lib.lisp │ ├── macroexpand-dammit.lisp │ ├── notes │ │ ├── c-examples.lisp │ │ ├── c.c │ │ ├── compilation-examples │ │ └── oo │ ├── package.lisp │ ├── state.lisp │ ├── tag.lisp │ └── toplevel.lisp ├── docs │ ├── Compiler.ppt.gz │ ├── Makefile │ ├── final-docs │ │ └── final-docs.org │ ├── presentation-3 │ │ ├── Makefile │ │ ├── input1.c.lisp │ │ ├── input2.c.lisp │ │ ├── presentation-3.org │ │ └── show.lisp │ └── prospectus.tex ├── flashing-colors │ ├── Makefile │ └── flashing.c.lisp ├── jormungandr │ ├── JormungandrChar.dat │ ├── JormungandrColor.dat │ ├── JormungandrFloorMap.dat │ ├── JormungandrFrameMap.dat │ ├── JormungandrTrailMap.dat │ ├── Makefile │ └── jormungandr.asm ├── phoenix │ ├── Makefile │ ├── Phoenix_Char.dat │ ├── Phoenix_Color.dat │ ├── Phoenix_Frame_BG_Map.dat │ ├── Phoenix_Star_BG_Map.dat │ └── phoenix.asm └── pong │ ├── Makefile │ ├── interrupt.asm │ ├── pong.asm │ ├── pong.h │ ├── snes-registers.h │ ├── temp.tar │ ├── temp.tgz │ └── toplevel.asm ├── jormungandr ├── JormungandrChar.dat ├── JormungandrColor.dat ├── JormungandrFloorMap.dat ├── JormungandrFrameMap.dat ├── JormungandrTrailMap.dat ├── jormungandr.asm ├── jormungandr.srm └── mkfile ├── pallet ├── pallet.txt ├── pallet.xls ├── palletBgmap.dat ├── palletChar.dat ├── palletPallet.dat ├── pongChar.dat ├── pongFrame.dat └── pongPallet.dat └── phoenix ├── char.dat ├── color.dat ├── frame_bg_map.dat ├── mkfile ├── phoenix.asm └── star_bg_map.dat /Register/Color_Data.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/Register/Color_Data.dat -------------------------------------------------------------------------------- /Register/Font_GFX.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/Register/Font_GFX.dat -------------------------------------------------------------------------------- /Register/Sprite_Data.dat: -------------------------------------------------------------------------------- 1 | '()*+ ,($08@H PX`h%& ()*+ ,($08 @HPX`%& ()*+ ,($0 8@HP X`%& ()*+ ,($08@H 2 | PX `%& ()*+ ,($0 8@HP X%& ()*+ ,($0 8@HP X%& ()*+ ,($0 8@HP X%&  ()*+ ,($0 8@HP X%&  3 | ()*+ ,($0 8@HPX ` 4 | h%&  ()*+ ,($0 8@HPX ` 5 | h%&  ()*+ -($0 8@HPX`h%p&  ()*+ -($0 8@HPX`h%p&  ()*+ -($0 8@HPX`h%p& ()*+ -($0 8@HPX`h%p& ()*+ -($0 8@HPX`h%p& ()*+ -($0 8@HPX`h%p& ()*+ -($0 8@HPX`h%p& ()*+ -($0 8@HPX`h%p& ()*+ -($0 8@HPX`h%p& ()*+ -($0 8@HPX`h%p& ()*+ -($0 8@HPX`h%p& ()*+ -($0 8@HPX`h%p& ()*+ -($0 8@HPX`h%p& ()*+ -($0 8@HPX`h%p& ()*+ -($0 8@HPX`h%p& ()*+ -($0 8@HPX`h%p& ()*+ ,($08@HPX%&  6 | ()*+ -($08@ 7 | H%P&  ()*+ -($08@ 8 | H%P&  ()*+ -($08@ H%P&  ()*+ -($08@ H%P&  ()*+ -($08@ H%P&  ()*+ -($08@ H%P&  ()*+ -($08@ H%P& ()*+ -($08@ H%P& ()*+ -($08@!H%P& ()*+ -($08@!H%P& ()*+ -($08@"H%P& ()*+ -($08@"H%P& ()*+ ,($0 8@HPX`%& ()*+ ,($0 8@HPX`%& ()*+ ,($0 8@ HPX`h%& ()*+ ,($0 8@H%& ()*+ ,($0 8@H%& ()*+ ,($0 8@H%& ()*+ ,($0 8@H%&  ()*+ ,($0 8 @HPX`%&  9 | ()*+ ,($0 8@ HPX`h%&  ()*+ ,($08@%&  ()*+ ,($08@%&  ()*+ ,($08@ H%& ()*+ ,($08@ H%& ()*+ ,($0 8@H PX`h%& ()*+ ,($0 8@ 10 | H PX` h%& ()*+ ,($0 8@H P 11 | X` 12 | h%p& ()*+ ,($0 8@H P 13 | X` 14 | h%p& ()*+ ,($0 8@H P 15 | X` 16 | h%p & ()*+ ,($08@HPX`%&  -------------------------------------------------------------------------------- /Register/register.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/Register/register.xls -------------------------------------------------------------------------------- /System/System.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/System/System.xls -------------------------------------------------------------------------------- /System/TODO: -------------------------------------------------------------------------------- 1 | Debug Draw Sprite 2 | OAM.Open 3 | OAM.Close 4 | 5 | Add variable joy hold/cooldown timers 6 | Expand Sine/Cosine/Angle -------------------------------------------------------------------------------- /asm/datagen: -------------------------------------------------------------------------------- 1 | #!/usr/bin/rc 2 | 3 | cat <$target 14 | 15 | o.%: %.o 16 | c99 $prereq -o $target 17 | 18 | %.o: %.c data.h 19 | c99 $cflags -c $stem.c 20 | -------------------------------------------------------------------------------- /asm/modes: -------------------------------------------------------------------------------- 1 | IMP Implied 2 | A A Accumulator 3 | I # Immediate 4 | B b Direct 5 | BX b,X Direct X Indexed 6 | BY b,Y Direct Y Indexed 7 | BS b,S Stack Indexed 8 | BI (b) Direct Indirect 9 | BL [b] Direct Indirect Long 10 | BXI (b,X) Direct X Indexed Indirect 11 | BIY (b),Y Direct Indirect Y Indexed 12 | BLY [b],Y Direct Indirect Long Y Indexed 13 | BSIY (b,S),Y Stack Relative Indirect Y Indexed 14 | BM b,b Block Move 15 | W w Absolute 16 | WX w,X Absolute X Indexed 17 | WY w,Y Absolute Y Indexed 18 | WI (w) Absolute Indirect 19 | WL [w] Absolute Indirect Long 20 | WXI (w,X) Absolute X Indexed Indirect 21 | L l Long 22 | LX l,X Long X Indexed 23 | -------------------------------------------------------------------------------- /codec/codec.h: -------------------------------------------------------------------------------- 1 | #ifndef CODEC_H 2 | #define CODEC_H 3 | //============================================================// +-------+ 4 | // codec.h // | | | * | 5 | // // | |/ | 6 | // SNES S-DSP BRR Audio Codec // | |_| * | 7 | //============================================================// +-------+ 8 | //============================================================// 9 | // Struct // 10 | //============================================================// 11 | // BRR 12 | typedef struct{ // BRR data 13 | int shift; // Decode shift 14 | int filter; // Decode filter 15 | int loop; // Loop block flag 16 | int end; // End block flag 17 | int data[0x10]; // Encoded samples 18 | }block_s; 19 | 20 | typedef struct{ // BRR sound 21 | int size; // Block count 22 | block_s* blocks; // Blocks 23 | }brr_s; 24 | 25 | // PCM 26 | typedef struct{ // PCM sound 27 | int size; // Sample count 28 | int* data; // Samples 29 | }pcm_s; 30 | 31 | //============================================================// 32 | // Prototype // 33 | //============================================================// 34 | // BRR 35 | brr_s* brrMake (int size); // Make BRR 36 | void brrFree (brr_s*); // Free BRR 37 | brr_s* brrRead (FILE* in); // Read binary BRR data 38 | void brrWrite (brr_s*, FILE* out); // Write binary BRR date 39 | void brrPrint (brr_s*, FILE* out); // Print textual BRR data 40 | pcm_s* brrDecode (brr_s*); // BRR to PCM 41 | // PCM 42 | pcm_s* pcmMake (int size); // Make PCM 43 | void pcmFree (pcm_s*); // Free PCM 44 | pcm_s* pcmRead (FILE* in); // Read binary PCM data 45 | void pcmWrite (pcm_s*, FILE* out); // Write binary PCM data 46 | void pcmPrint (pcm_s*, FILE* out); // Print textual PCM data 47 | brr_s* pcmEncode (pcm_s*, int delta, int filter, int loop); // PCM to BRR 48 | 49 | //============================================================// 50 | // // 51 | // // 52 | // // 53 | //============================================================// 54 | #endif 55 | -------------------------------------------------------------------------------- /codec/error.c: -------------------------------------------------------------------------------- 1 | #ifndef ERROR_C 2 | #define ERROR_C 3 | //============================================================// +-------+ 4 | // error.c // | | | * | 5 | // // | |/ | 6 | // // | |_| * | 7 | //============================================================// +-------+ 8 | #include 9 | #include 10 | #include "error.h" 11 | 12 | //============================================================// 13 | // Globals // 14 | //============================================================// 15 | static int talk=1; // Print warnings flag 16 | 17 | //============================================================// 18 | // error() // 19 | //============================================================// 20 | void error(code_e c, error_e e, void* p){ 21 | if(ee||talk){ 22 | // Print error type 23 | ;;;; if(ERROR_0<=e&&e<=ERROR_custom) fprintf(stderr,"ERROR: " ); 24 | else if(WARNS_0<=e&&e<=WARNS_custom) fprintf(stderr,"WARNING: "); 25 | else if(FATAL_0<=e&&e<=FATAL_custom) fprintf(stderr,"FATAL: " ); 26 | // Print program name 27 | switch(c){ 28 | // Null 29 | case CODE_0 : break; 30 | // Main 31 | case CODE_main : fprintf(stderr,"main(): " ); break; 32 | // Audio codec 33 | case CODE_brrMake : fprintf(stderr,"brrMake(): " ); break; 34 | case CODE_brrFree : fprintf(stderr,"brrFree(): " ); break; 35 | case CODE_brrRead : fprintf(stderr,"brrRead(): " ); break; 36 | case CODE_brrWrite : fprintf(stderr,"brrWrite(): " ); break; 37 | case CODE_brrPrint : fprintf(stderr,"brrPrint(): " ); break; 38 | case CODE_brrDecode : fprintf(stderr,"brrDecode(): "); break; 39 | case CODE_pcmMake : fprintf(stderr,"pcmMake(): " ); break; 40 | case CODE_pcmFree : fprintf(stderr,"pcmFree(): " ); break; 41 | case CODE_pcmRead : fprintf(stderr,"pcmRead(): " ); break; 42 | case CODE_pcmWrite : fprintf(stderr,"pcmWrite(): " ); break; 43 | case CODE_pcmPrint : fprintf(stderr,"pcmPrint(): " ); break; 44 | case CODE_pcmEncode : fprintf(stderr,"pcmEncode(): "); break; 45 | // Default 46 | default : fprintf(stderr,"Unknown(): " ); break; 47 | } 48 | // Print error 49 | switch(e){ 50 | case ERROR_0 : break; 51 | case WARNS_data : fprintf(stderr,"Ignored %s" ,(char*)p); break; 52 | case FATAL_memory : fprintf(stderr,"Failed alloc(%s)",(char*)p); break; 53 | case FATAL_path : fprintf(stderr,"\"%s\" not found",(char*)p); break; 54 | default : fprintf(stderr,"Unknown" ); break; 55 | } 56 | fprintf(stderr,"\n\n"); 57 | // Exit if fatal 58 | if(FATAL_0<=e&&e<=FATAL_custom) for(;;); // exit(1); for for WINDOWS! 59 | } 60 | return; 61 | } 62 | 63 | //============================================================// 64 | // mute() // 65 | //============================================================// 66 | void mute(void){ 67 | talk=0; 68 | return; 69 | } 70 | 71 | //============================================================// 72 | // // 73 | // // 74 | // // 75 | //============================================================// 76 | #endif 77 | -------------------------------------------------------------------------------- /codec/error.h: -------------------------------------------------------------------------------- 1 | #ifndef ERROR_H 2 | #define ERROR_H 3 | //============================================================// +-------+ 4 | // error.h // | | | * | 5 | // // | |/ | 6 | // // | |_| * | 7 | //============================================================// +-------+ 8 | 9 | //============================================================// 10 | // Enum // 11 | //============================================================// 12 | // Programs 13 | typedef enum{ 14 | // Null 15 | CODE_0=0 , 16 | // Main 17 | CODE_main , 18 | // Audio codec 19 | CODE_brrMake , 20 | CODE_brrFree , 21 | CODE_brrRead , 22 | CODE_brrWrite , 23 | CODE_brrPrint , 24 | CODE_brrDecode , 25 | CODE_pcmMake , 26 | CODE_pcmFree , 27 | CODE_pcmRead , 28 | CODE_pcmWrite , 29 | CODE_pcmPrint , 30 | CODE_pcmEncode , 31 | }code_e; 32 | 33 | // Errors 34 | typedef enum{ 35 | // Error (Recovers) 36 | ERROR_0=0 , // Null error 37 | ERROR_custom , // Custom message 38 | // Warns (Recovers, mutable) 39 | WARNS_0 , // Null warns 40 | WARNS_data , // Bad data 41 | WARNS_custom , // Custom message 42 | // Fatal (Terminates) 43 | FATAL_0 , // Null fatal 44 | FATAL_memory , // Out of memory 45 | FATAL_path , // Bad pathname 46 | FATAL_custom , // Custom message 47 | }error_e; 48 | 49 | //============================================================// 50 | // Prototype // 51 | //============================================================// 52 | void error(code_e, error_e, void*); 53 | void mute (void); 54 | 55 | //============================================================// 56 | // // 57 | // // 58 | // // 59 | //============================================================// 60 | #endif 61 | -------------------------------------------------------------------------------- /codec/main.c: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_C 2 | #define MAIN_C 3 | //============================================================// +-------+ 4 | // codec.c // | | | * | 5 | // // | |/ | 6 | // SNES S-DSP BRR Audio Codec // | |_| * | 7 | //============================================================// +-------+ 8 | #include 9 | #include 10 | #include 11 | #include "codec.h" 12 | #include "error.h" 13 | 14 | //============================================================// 15 | // !!!DEBUG!!! Development Driver // 16 | //============================================================// 17 | int main(int argc, char *argv[]){ 18 | // Declarations 19 | FILE *in=0; 20 | FILE *out=0; 21 | FILE *report; 22 | pcm_s *p=0,*p2=0; 23 | brr_s *b=0,*b2=0; 24 | block_s *block,*block2; 25 | // Welcome 26 | fprintf(stderr,"+----------------------+\n" 27 | "| SNES BRR Audio Codec |\n" 28 | "| Registar v1.0 |\n" 29 | "+----------------------+\n\n"); 30 | // Prompt 31 | if(argc!=3){ 32 | fprintf(stderr,"Usage: %s [input.pcm][output.brr]\n",argv[0]); 33 | for(;;); // Windows 34 | exit(0); 35 | } 36 | /* 37 | // Identity Stress Test 38 | int i,j,k; 39 | int loop; 40 | int errors=0; 41 | srand(time(NULL)); 42 | for(i=0;i<1;i++) rand(); 43 | for(i=0; i<0x100; i++){ // Test Loop 44 | // Build random BRR 45 | b=brrMake(rand()%0x1000); 46 | loop=rand()%(b->size*0x10); 47 | fprintf(stderr,"Test: %0.4X brr[%0.4X]\n",i,b->size); 48 | for(j=0; jsize; j++){ // Build block 49 | block=&b->blocks[j]; 50 | block->shift =rand()%0xD; 51 | block->filter=rand()%4; 52 | block->loop=(0<=loop&&loop<=(j+1)*0x10?1:0); 53 | block->end=(j+1==b->size)?1:0; 54 | for(k=0; k<0x10; k++){ 55 | int r=rand(); 56 | block->data[k]=r&0x8?r|~0xF:r&0xF; 57 | } 58 | } 59 | // Decode, encode random BRR 60 | p =brrDecode(b); 61 | b2=pcmEncode(p,1,-1,loop); 62 | p2=brrDecode(b2); 63 | //brrPrint(b ,0); 64 | //brrPrint(b2,0); 65 | //pcmPrint(p ,0); 66 | //pcmPrint(p2,0); 67 | // Compare 68 | if(b->size==b2->size){ 69 | for(j=0; jsize; j++){ 70 | block =&b ->blocks[j]; 71 | block2=&b2->blocks[j]; 72 | int e=0; 73 | for(k=0; k<0x10; k++) 74 | if(p->data[j*0x10+k]!=p2->data[j*0x10+k]||block->loop!=block2->loop) e=1; 75 | if(e){ 76 | errors++; 77 | fprintf(stderr,"[%X][%X%X%X%X][",j,block->shift,block->filter,block->loop,block->end); 78 | for(k=0;k<0x10;k++) fprintf(stderr,"%X",block->data[k]&0xF); 79 | fprintf(stderr,"] => [%X%X%X%X][",block2->shift,block2->filter,block2->loop,block2->end); 80 | for(k=0;k<0x10;k++) fprintf(stderr,"%X",block2->data[k]&0xF); 81 | fprintf(stderr,"]\n"); 82 | } 83 | } 84 | }else{ 85 | fprintf(stderr,"Unequal sizes\n"); 86 | } 87 | brrFree(b); 88 | brrFree(b2); 89 | pcmFree(p); 90 | pcmFree(p2); 91 | } 92 | fprintf(stderr,"\nErrors: %i\n\n",errors); 93 | */ 94 | /* 95 | // BRR->PCM->BRR Test 96 | if(!(in=fopen(argv[1],"rb"))) error(CODE_main,FATAL_path,(char*)argv[1]); 97 | b=brrRead(in); 98 | fclose(in); 99 | //out=fopen("out.txt","w"); 100 | brrPrint(b,0); 101 | p=brrDecode(b); 102 | brrFree(b); 103 | pcmPrint(p,0); 104 | b=pcmEncode(p,1,-1,-1); 105 | pcmFree(p); 106 | brrPrint(b,0); 107 | //if(!(out=fopen(argv[2],"wb"))) error(CODE_main,FATAL_path,(char*)argv[2]); 108 | //brrWrite(b,out); 109 | //fclose(out); 110 | p=brrDecode(b); 111 | brrFree(b); 112 | pcmPrint(p,0); 113 | pcmFree(p); 114 | /* 115 | // PCM->BRR->PCM Test 116 | // Read PCM 117 | if(!(in=fopen(argv[1],"rb"))) error(CODE_main,FATAL_path,(char*)argv[1]); 118 | p=pcmRead(in); 119 | fclose(in); 120 | //pcmPrint(p,0); 121 | // Encode->Decode Test 122 | b=pcmEncode(p,1,-1,-1); 123 | pcmFree(p); 124 | brrPrint(b,0); 125 | p=brrDecode(b); 126 | //pcmPrint(p,0); 127 | pcmFree(p); 128 | // Write BRR 129 | if(!(out=fopen(argv[2],"wb"))) error(CODE_main,FATAL_path,(char*)argv[2]); 130 | brrWrite(b,out); 131 | fclose(out); 132 | brrFree(b); 133 | */ 134 | /* Decode Equations 135 | d0=(c<>1; 136 | p1=d0+ s1+(- s1>>4); 137 | p2=d0+2*s1+(- 3*s1>>5)-s2+( s2>>4); 138 | p3=d0+2*s1+(-13*s1>>6)-s2+(3*s2>>4); 139 | */ 140 | // Done 141 | fprintf(stderr,"-Done-\n\n"); 142 | for(;;); // Windows 143 | return 0; 144 | } 145 | 146 | //============================================================// 147 | // // 148 | // // 149 | // // 150 | //============================================================// 151 | #endif 152 | -------------------------------------------------------------------------------- /cs400.features/AUTHORS: -------------------------------------------------------------------------------- 1 | bsummer4@eecs.utk.edu Benjamin Summers 2 | josborn8@eecs.utk.edu James Osborne 3 | sgray10@eecs.utk.edu Stephen Gray 4 | ktrofatt@utk.edu Kenneth Parker Trofatter 5 | -------------------------------------------------------------------------------- /cs400.features/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | cd docs; make 3 | cd compiler; make 4 | cd assembler; make 5 | 6 | clean: 7 | cd docs; make clean 8 | cd compiler; make clean 9 | cd assembler; make clean 10 | -------------------------------------------------------------------------------- /cs400.features/Project: -------------------------------------------------------------------------------- 1 | project "cs400" 2 | to build do make 3 | to clean do {make clean} 4 | -------------------------------------------------------------------------------- /cs400.features/assembler/.gitignore: -------------------------------------------------------------------------------- 1 | 65816asm 2 | main.o 3 | pre 4 | pre.hi 5 | pre.o 6 | TAGS 7 | -------------------------------------------------------------------------------- /cs400.features/assembler/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CFLAGS = -D__DEBUG__ -g3 -std=gnu99 -W -Wall -Werror -pedantic 3 | HSFLAGS = -O3 -package parsec 4 | 5 | all: 65816asm pre 6 | clean:; rm -f *.hi *.o 65816asm pre readme.html 7 | docs: readme.html 8 | 9 | 65816asm: main.o; $(CC) $(CFLAGS) $^ -o $@ 10 | pre: pre.hs; ghc $(HSFLAGS) $^ -o $@ 11 | main.o: main.c assembler.h data.h; $(CC) $(CFLAGS) -c $< 12 | readme.html: README; markdown < $^ > $@ 13 | test: pre; ./pre pretest 14 | -------------------------------------------------------------------------------- /cs400.features/assembler/pretest: -------------------------------------------------------------------------------- 1 | asdlk#&{} ; ASM #$00 #tis s 2 | adfa asdfk ; ASM #$01 afa asldj asdf 3 | asdf asd fasdfj ; #Print 4 | asd 43 33 3 4 242 ; #File sfds 5 | ; #Data {$00 $80 Color_Data $0200} 6 | asdadfasdf ; ASM (x) adfadf ; YO 7 | ; ; ; ; 8 | ; #Data w Main_Program_PT 9 | ; {-} 10 | ; #LoROM 11 | ; # yo yo yo 12 | ; #Name endpretest 13 | -------------------------------------------------------------------------------- /cs400.features/assembler/snes-memory-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.features/assembler/snes-memory-layout.png -------------------------------------------------------------------------------- /cs400.features/compiler/Makefile: -------------------------------------------------------------------------------- 1 | CC = ./compiler.lisp 2 | ASM = ../assembler/65816asm 3 | 4 | all: compiler; 5 | clean:; rm -f *.fasl *.asm *.smc *~ compiler 6 | install: compiler; ln -f compiler ~/bin/scc 7 | 8 | ../assembler/65816asm:; cd ../assembler; make 9 | compiler: asm.lisp c.lisp compiler.lisp lib.lisp package.lisp Makefile 10 | sbcl --noinform \ 11 | --eval "(defvar *script?* nil)" \ 12 | --script "compiler.lisp" 13 | 14 | c.asm: inputs/c compiler; $(CC) < $< > $@ 15 | colors.asm: inputs/colors.asm compiler; cp $< $@ 16 | test: c.asm colors.asm $(ASM) 17 | $(ASM) colors.asm 18 | $(ASM) c.asm 19 | 20 | colors: test; snes9x colors.smc 21 | c: test; snes9x c.smc 22 | run: c colors 23 | -------------------------------------------------------------------------------- /cs400.features/compiler/asm.lisp: -------------------------------------------------------------------------------- 1 | "This is the code that actually creates the textual asm output. " 2 | 3 | (in-package #:cs400-compiler) 4 | 5 | (defparameter +addressing-modes-and-syntax+ 6 | '((:implied "") 7 | (:accumulator "A") 8 | (:immediate "#b") 9 | (:immediate-w "#w") 10 | #| TODO What are the other kinds of 'immediate's? |# 11 | (:direct "b") 12 | (:direct-x-indexed "b,X") 13 | (:direct-y-indexed "b,Y") 14 | (:stack-indexed "b,S") 15 | (:direct-indirect "(b)") 16 | (:direct-indirect-long "[b]") 17 | (:direct-x-indexed-indirect "(b,X)") 18 | (:direct-indirect-y-indexed "(b),Y") 19 | (:direct-indirect-long-y-indexed "[b],Y") 20 | (:stack-relative-indirect-y-indexed "(b,S),Y") 21 | (:block-move "b,b") 22 | (:absolute "w") 23 | (:absolute-x-indexed "w,X") 24 | (:absolute-y-indexed "w,Y") 25 | (:absolute-indirect "(w)") 26 | (:absolute-indirect-long "[w]") 27 | (:absolute-x-indexed-indirect "(w,X)") 28 | (:long "l") 29 | (:long-x-indexed "l,X"))) 30 | 31 | (defvar *emit-indentation* 0) 32 | 33 | (defun indent-chars () 34 | (collecting 35 | (dotimes (i (* 4 *emit-indentation*)) 36 | (collect #\space)))) 37 | 38 | (defun emit (string) 39 | (format t "~{~a~}; ~a~%" (indent-chars) string) 40 | (values)) 41 | 42 | (defmacro with-indent (name &body code) 43 | `(let ((*emit-indentation* (1+ *emit-indentation*))) 44 | (format t "~{~a~}~a~%" (rest (indent-chars)) ',name) 45 | ,@code)) 46 | 47 | (defun asm-subformat (format-char argument) 48 | (etypecase argument 49 | (symbol (symbol-name argument)) 50 | (number (format nil (ecase format-char 51 | (#\b "$~2,'0xb") 52 | (#\w "$~4,'0xw") 53 | (#\l "$~6,'0xl")) 54 | argument)))) 55 | 56 | (defun asm-format (format-string &rest arguments) 57 | "Take an asm form from +addressing-modes-and-syntax+ and some arguements, 58 | returning the corresponding asm syntax. " 59 | (coerce (flatten 60 | (loop for char across format-string 61 | collect (if (find char '(#\b #\w #\l)) 62 | (coerce (asm-subformat char (pop arguments)) 'list) 63 | (list char)))) 64 | 'string)) 65 | 66 | (defmacro asm (command mode &rest args) 67 | `(emit (format nil "~a ~a" 68 | ,(symbol-name command) 69 | (asm-format 70 | (car (elookup ,mode +addressing-modes-and-syntax+)) 71 | ,@args)))) 72 | 73 | 74 | "# Code Generation Routines" 75 | (defun %label (name) (emit (format nil "{~a}" name))) 76 | (defun %goto (label-name) (emit (format nil "BRA {~a}" label-name))) 77 | (defun %branch-if-not (label-name) 78 | (emit (format nil "BEQ {~a}" label-name))) 79 | 80 | (defun asm-code (symbol &key (prototype nil)) 81 | (emit 82 | (format nil (if prototype "#Code w ~a" "#Code w {~a}") 83 | (string-downcase 84 | (symbol-name symbol))))) 85 | 86 | (defmacro 16-bit-mode () `(asm rep :immediate #x30)) 87 | (defmacro 8-bit-mode () `(asm sep :immediate #x30)) 88 | (defun lda (integer) 89 | (declare (type integer integer)) 90 | (asm lda :immediate-w integer)) 91 | 92 | (defmacro write-w (addr value) 93 | `(progn (asm lda :immediate-w ,value) 94 | (asm sta :direct ,addr))) 95 | 96 | (defun set-reset-handler (value) 97 | (emit (format nil 98 | "#Data $00:FFFC _reset_handler {~a $0000}" 99 | value))) 100 | -------------------------------------------------------------------------------- /cs400.features/compiler/compiler-lib.c.lisp: -------------------------------------------------------------------------------- 1 | "## Compiler Defined C-Code" 2 | (c::subroutine c::reset 3 | (asm clc :implied) 4 | (asm xce :implied) 5 | (16-bit-mode) 6 | (c::main)) 7 | 8 | (set-reset-handler "reset") 9 | -------------------------------------------------------------------------------- /cs400.features/compiler/compiler.lisp: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sbcl --script 2 | 3 | " 4 | A unix interface to the c compiler. 5 | 6 | If you want to dump a core image, define *script?* to nil before 7 | loading this file. Otherwise we simply run the c-compiler as script. 8 | " 9 | 10 | (defvar *script?* t) 11 | 12 | (let ((*standard-output* *error-output*)) 13 | (require :cs400-compiler)) 14 | 15 | (in-package :cs400-compiler) 16 | 17 | (defun main (args) 18 | (declare (ignore args)) 19 | (repl) 20 | (cl:in-package :cs400-compiler) 21 | (compile-c "/home/ben/repositories/cs400/compiler/compiler-lib.c.lisp") 22 | 0) 23 | 24 | (defun top () 25 | (in-package :cs400-compiler) 26 | (sb-ext:quit 27 | :unix-status 28 | (handler-case (apply #'main sb-ext:*posix-argv*) 29 | (error (e) 30 | (format *error-output* "Fatal Error:~% ~a~%" e) 31 | 2) 32 | (t (s) 33 | (declare (ignore s)) 34 | 1)))) 35 | 36 | (if cl-user::*script?* 37 | (top) 38 | (sb-ext:save-lisp-and-die "compiler" 39 | :executable t 40 | :toplevel #'top 41 | :purify t)) 42 | -------------------------------------------------------------------------------- /cs400.features/compiler/cs400-compiler.asd: -------------------------------------------------------------------------------- 1 | (asdf:defsystem #:cs400-compiler 2 | :depends-on (:iterate :cl-match :split-sequence) 3 | :components ((:file "package") 4 | (:file "lib") 5 | (:file "macroexpand-dammit") 6 | (:file "c-analyze") 7 | (:file "asm") 8 | (:file "c")) 9 | :serial t) 10 | -------------------------------------------------------------------------------- /cs400.features/compiler/inputs/asm: -------------------------------------------------------------------------------- 1 | (asm lda :absolute 3) 2 | (asm clc :implied) 3 | (asm adc :direct 4) 4 | (asm adc :immediate 4) 5 | -------------------------------------------------------------------------------- /cs400.features/compiler/inputs/c: -------------------------------------------------------------------------------- 1 | (in-package :c) 2 | 3 | (s::emit "#LoROM") 4 | 5 | (proto set_background_color) 6 | 7 | (proc (main int) () 8 | 9 | "Set screen to max brightness" 10 | (s::8-bit-mode) 11 | (s::asm s::lda :immediate #x0F) 12 | (s::asm s::sta :absolute #x2100) 13 | (s::16-bit-mode) 14 | 15 | (var color int 0) 16 | (while (s::lda 1) 17 | 18 | "Get input from the controller" 19 | (s::asm s::lda :absolute #x4218) 20 | (if (s::asm s::and :immediate-w #x0100) ;; is right button depressed? 21 | (++ color) 22 | color) 23 | (set_background_color color #x0000))) 24 | 25 | (proc (set_background_color int) (color color_address) 26 | color_address 27 | (s::8-bit-mode) 28 | (s::asm s::sta :absolute #x2121) 29 | (s::16-bit-mode) 30 | 31 | color 32 | (s::8-bit-mode) 33 | (s::asm s::sta :absolute #x2122) 34 | (s::asm s::xba :implied) 35 | (s::asm s::sta :absolute #x2122) 36 | (s::16-bit-mode)) 37 | -------------------------------------------------------------------------------- /cs400.features/compiler/inputs/colors.asm: -------------------------------------------------------------------------------- 1 | ; #LoROM 2 | ; #Code w main 3 | ; CLC 4 | ; XCE 5 | ; SEP #$30b 6 | ; {yay704} 7 | ; LDA #$0Fb 8 | ; STA $2100w 9 | ; LDA #$00b 10 | ; STA $2121w 11 | ; REP #$30b 12 | ; INC $0000 13 | ; LDA $0000 14 | ; SEP #$30b 15 | ; STA $2122w 16 | ; XBA 17 | ; STA $2122w 18 | ; BRA {yay704} 19 | ; RTS 20 | ; #Data $00:FFFC {$8000 $0000} 21 | -------------------------------------------------------------------------------- /cs400.features/compiler/lib.lisp: -------------------------------------------------------------------------------- 1 | "Just some general utillity code. " 2 | 3 | (in-package #:cs400-compiler) 4 | 5 | (defun insult () (error "u is dumb")) 6 | (defun traceme (x) x) 7 | (defun flatten (lists) (apply #'append lists)) 8 | 9 | (defun filter (predicate seq) (remove-if-not predicate seq)) 10 | (defun in-table? (key table) 11 | (multiple-value-bind (value found?) (gethash key table) 12 | (declare (ignore value)) 13 | found?)) 14 | 15 | (defun hash-table->alist (table) 16 | (loop for key being the hash-keys of table 17 | collect (cons key (gethash key table)))) 18 | 19 | (defun alist-to-table (alist &optional (table (make-hash-table))) 20 | "Modifies table if one is passed; Otherwise return a new table with 21 | only the given mapping. " 22 | (loop for (key . value) in alist 23 | do (setf (gethash key table) value)) 24 | table) 25 | 26 | (defun non-unique-items (list) 27 | "Returns a list of all non-unique items" 28 | (let ((items (make-hash-table)) 29 | (duplicated-items)) 30 | (dolist (item list) 31 | (if (gethash item items) 32 | (setf duplicated-items (adjoin item duplicated-items)) 33 | (setf (gethash item items) t))) 34 | duplicated-items)) 35 | 36 | (defun proper-set? (list) (null (non-unique-items list))) 37 | 38 | ;; Macros 39 | (defmacro aif (form then &optional else) 40 | `(let ((it ,form)) 41 | ,(if else 42 | `(if it ,then ,else) 43 | `(if it ,then)))) 44 | 45 | (defun alist->plist (alist) 46 | (loop for (key . value) in alist 47 | collect key 48 | collect value)) 49 | 50 | (defun hash-table->plist (table) 51 | (alist->plist (hash-table->alist table))) 52 | 53 | (defmethod print-object ((table hash-table) stream) 54 | (format stream "[dict~{ ~s~}]" (hash-table->plist table))) 55 | 56 | (defun lookup (key alist) 57 | (aif (assoc key alist) 58 | (values (cdr it) t))) 59 | 60 | (defun elookup (key alist) 61 | (multiple-value-bind (result found?) (lookup key alist) 62 | (if found? result 63 | (error "key '~a was not found in alist '~a. " key alist)))) 64 | 65 | (defmacro match (expr &body forms) 66 | `(cl-match:match ,expr ,@forms)) 67 | 68 | (defmacro match? (form value) 69 | `(match ,value (,form t))) 70 | 71 | (defmacro with-gensyms (symbols &body code) 72 | `(let ,(mapcar (lambda (form) 73 | (match form 74 | ((as symbol (type symbol)) 75 | `(,symbol (gensym (symbol-name ',symbol)))) 76 | ((list symbol gensym-hint) 77 | `(,symbol (gensym ,gensym-hint))))) 78 | symbols) 79 | ,@code)) 80 | 81 | (defmacro ematch (expr &body forms) 82 | (with-gensyms (tmp) 83 | `(let ((,tmp ,expr)) 84 | (or (match ,tmp ,@forms) 85 | (error "no match found for ~a in patterns ~a" ,tmp 86 | ',(mapcar #'first forms)))))) 87 | 88 | (defun & (f &rest l) (apply f l)) 89 | (defmacro fn (lambda-list &body body) `(lambda ,lambda-list ,@body)) 90 | (defmacro fn1 (&body body) `(fn (!1) ,@body)) 91 | 92 | (defun eprint (object) (print object *error-output*)) 93 | 94 | (defmacro collecting (&body code) 95 | (with-gensyms (result) 96 | `(let ((,result)) 97 | (flet ((collect (obj) (push obj ,result))) 98 | ,@code) 99 | (nreverse ,result)))) 100 | 101 | (defun nice-gensym (obj) 102 | (gensym (string-right-trim 103 | "0123456789" 104 | (format nil "~a" obj)))) 105 | 106 | (defmacro with-symbol-alias-alist (alist-varname symbols &body code) 107 | "Generates unique names for all SYMBOLS, and binds an alist 108 | (GIVEN-NAME . UNIQUE-NAME) to ALIST_VARNAME. " 109 | `(let ((,alist-varname ',(mapcar (fn1 (cons !1 (nice-gensym !1))) 110 | symbols))) 111 | ,@code)) 112 | 113 | (defun lpartition (predicate list) 114 | "Returns (values (remove-if-not predicate list) 115 | (remove-if predicate list)), but in a single 116 | pass. " 117 | (iter (for item in list) 118 | (if (funcall predicate item) 119 | (collect item into good-list) 120 | (collect item into bad-list)) 121 | (finally (return (values good-list bad-list))))) 122 | 123 | (defun listify (obj) 124 | (typecase obj (list obj) (t (list obj)))) 125 | 126 | (defmacro pluralize-macro (macro newname) 127 | (with-gensyms (forms) 128 | `(defmacro ,newname (&body ,forms) 129 | `(progn 130 | ,@(mapcar (fn1 (cons ',macro (listify !1))) ,forms))))) 131 | 132 | (defun find-index (predicate list) 133 | (loop for item in list 134 | for index from 0 135 | when (& predicate item) 136 | return index 137 | finally (return nil))) 138 | 139 | (defun take (n l) 140 | (loop for x below n 141 | for i in l 142 | collect i)) 143 | 144 | (defun drop (n l) 145 | (loop for x to n 146 | for i on l 147 | finally (return i))) 148 | -------------------------------------------------------------------------------- /cs400.features/compiler/notes/c-examples.lisp: -------------------------------------------------------------------------------- 1 | " 2 | Here is a table of syntaxes for operators. I don't like some of the 3 | things I chose (like _ instead of |), so if you have some better ideas 4 | tell me. 5 | 6 | ========= ============ ================ 7 | C Sexp c More lispy 8 | ========= ============ ================ 9 | +a (+ a) (+ a) 10 | a + b (+ a b) (+ a b c ...) 11 | ++a (++* a) (preincr a) 12 | a++ (++ a) (incr a) 13 | a += b (+= a b) (incr a b) 14 | -a (- a) (- a) 15 | a - b (- a b) (- a b c) 16 | --a (--* a) (predecr a) 17 | a-- (-- a) (decr a) 18 | a -= b (-= a b) (decr a b) 19 | a * b (* a b) (* a b) 20 | a *= b (*= a b) (set * a b) 21 | a / b (/ a b) (/ a b) 22 | a /= b (/= a b) (set / a b) 23 | a % b (% a b) (mod a b) 24 | a %= b (%= a b) (set mod a b) 25 | a < b (< a b) (< a b ...) 26 | a <= b (<= a b) (<= a b ...) 27 | a > b (> a b) (> a b ...) 28 | a >= b (>= a b) (>= a b ...) 29 | a != b (!= a b) (!= a b ...) 30 | a == b (== a b) (== a b ...) 31 | !a (! a) (not a) 32 | a && b (&& a b) (and a b ...) 33 | a || b (or a b) (or a b ...) 34 | a << b (<< a b) (lshift a b) 35 | a <<= b (<<= a b) (set lshift a b) 36 | a >> b (>> a b) (rshift a b) 37 | a >>= b (>>= a b) (set rshift a b) 38 | ~a (~ a) (nnot a) 39 | a & b (& a b) (nand a b) 40 | a &= b (&= a b) (set nand a b) 41 | a | b (_ a b) (!or a b) 42 | a |= b (_= a b) (set !or a b) 43 | a ^ b (^ a b) (^ a b ...) 44 | a ^= b (^= a b) (set ^ a b ...) 45 | a = b (= a b) (set a b) 46 | a() (a) (a) 47 | a[b] ([] a b) (a b) 48 | *a (@ a) (a) 49 | &a (& a) (? a) 50 | a->b (-> a :b) (a :b) 51 | (type)a (type a) (type a) 52 | a , b (do a b) (do a b) 53 | a ? b : c (? a b c) (if a b c) 54 | sizeof a (sizeof a) (size a) 55 | ========= ============ ================ 56 | 57 | Some expressions: 58 | 59 | a.b.c[2] 60 | (a :b :c 2) 61 | ([] (@. (@. a :b) :c) 2) 62 | 63 | a->b.c[(x == 3) ? 1 : 2] + 3 + a->a 64 | (+ (a :b :c (if (== x 3) 1 2)) 3 (a :a)) 65 | (+ ([] (.@ (-> a :b) :c) (? f 1 2)) 3 (-> a a)) 66 | 67 | 68 | Some functions: 69 | 70 | C: 71 | 72 | char *strcpy(char *dest, const char *src) 73 | { 74 | char *save = dest; 75 | while (*dest++ = *src++); 76 | return save; 77 | } 78 | 79 | 80 | Sexp C: 81 | 82 | (defun strcpy (dest src) 83 | (type :*char (const :*char) -> :*char) 84 | (var save dest :*char) 85 | (while (== (@ (++ dest)) (@ (++ dest)))) 86 | (return save)) 87 | 88 | 89 | More lispy: 90 | 91 | (defun strcpy (dest src) 92 | (type :*char (const :*char) -> :*char) 93 | (let ((save dest)) 94 | (while (== ((++ dest)) ((++ src)))) 95 | save)) 96 | 97 | Another example 98 | 99 | void f (int n, char x[n]) 100 | { 101 | for (int i = 0; ii < n; ii++) { 102 | if (!(i % 3)) { 103 | x[i] = '\0' 104 | } 105 | } 106 | } 107 | 108 | (defun f (n x) 109 | (type :int (:char n)) 110 | (for ((var i 0 :int) (< ii n) (++ i)) 111 | (if (! (% i 3)) 112 | (= ([] x i) #\null)))) 113 | 114 | (defun f (n x) 115 | (type int (char n)) 116 | (iter (for i below n) 117 | (if (divisible i 3) 118 | (set (x i) #\null)))) 119 | " 120 | -------------------------------------------------------------------------------- /cs400.features/compiler/notes/c.c: -------------------------------------------------------------------------------- 1 | // despite the '.c' extensions, this file is just documentaion. It 2 | // explores the different namespaces of c and how various issues are 3 | // handled. 4 | 5 | // TODO This is not handled the same in tcc. Read the c standard and 6 | // see what is actuall the correct behavior. 7 | 8 | // Namespaces: 9 | // 1. Tagged types: 10 | // 11 | // 'struct c', 'enum c', and 'union c' are all in the same 12 | // namespace, but not the same namespaces as straight-up types like 13 | // 'int'. 14 | // 15 | // These are lexically scoped, there is a global scope, and every 16 | // block introduces a new scope. 17 | // 18 | // 2. Labels 19 | // 20 | // Lables use the functions scope. There is no scope nesting of 21 | // labels. There are no global lables, and 22 | // functions-definined-in-functions have their own, 23 | // completely-separate labels scope. 24 | // 25 | // 3. Everything else: 26 | // 27 | // - Types 28 | // - Variables 29 | // - Functions 30 | // 31 | // These are lexically scoped, there is a global scope, and every 32 | // block introduces a new scope. 33 | // 34 | // 4. Every Struct/union has it's own namespace within it. 35 | // 36 | // Aside from that 37 | 38 | struct f { int a; }; 39 | 40 | typedef int c; 41 | 42 | c see() { 43 | c c; 44 | switch ('a') { 45 | case 'a': break; 46 | default: return; } 47 | c: 48 | return c + c; } 49 | 50 | c main(void) { 51 | c cee(); 52 | c: 53 | return cee(); } 54 | 55 | c cee() { 56 | c C; 57 | typedef struct c { c c; } c; 58 | // int c; // This conflicts with the typedef above 59 | // typedef union c { c c; } see; // This conflicts with 'struct c' 60 | c: 61 | { c c; 62 | //c d; // Not cool. Using c as a type was fine above but not here 63 | // since the variable c hides it. 64 | if (!c.c) return 0; 65 | typedef struct c { int c; } C; 66 | // c: // Not cool. Label scopes don't nest 67 | C sea; 68 | struct c see() { 69 | c: // Nested functions have their own label scopes (although they 70 | // are not standard c). However, you can't goto labels in the 71 | // enclosing lexical scope. 72 | goto c; 73 | sea; }} 74 | c sea; 75 | return C; 76 | return see(sea.c); } 77 | -------------------------------------------------------------------------------- /cs400.features/compiler/notes/compilation-examples: -------------------------------------------------------------------------------- 1 | # Code Generation Examples 2 | ## (+ 3 4) 3 | 4 | ; LDA #3b 5 | ; CLC 6 | ; ADC #4b 7 | 8 | ## (+ x y) 9 | In the caller: 10 | 11 | ; LDA x Push x 12 | ; PHA 13 | ; LDA y Push y 14 | ; PHA 15 | ; TSC Make room for 1 byte of return space 16 | ; CLC 17 | ; ADC #1b 18 | ; TCS 19 | ; JSL whatever 20 | ; LDA 1,S Return value 21 | ; TSC Clean up the stack 22 | ; SEC 23 | ; SBC #3 24 | ; TCS 25 | 26 | 27 | In the callee: 28 | 29 | ; LDA 5,S First argument 30 | ; CLC 31 | ; ADC 4,S Second argument 32 | ; STA 3,S Return value 33 | ; RTS 34 | 35 | 36 | # Simple Code Example 37 | 38 | (var n char 0) 39 | 40 | (defun foo ((char x) (char y) -> char) 41 | (var z char 3) 42 | (return (+ x y z))) 43 | 44 | (defun main () 45 | (label loop) 46 | (if (!= n 10) 47 | (block (++ n) 48 | (goto loop)) 49 | (block (-- n))) 50 | (= n (foo 3 n))) 51 | 52 | Expands into... 53 | 54 | (defvar *type-sizes* '(char 1)) 55 | (defvar *globals* (make-hash-table)) 56 | 57 | (setf (gethash *globals* 'n) '(char)) 58 | 59 | 60 | (setf (gethash *functions* foo) 61 | '(progn (asm lda :immediate 3) 62 | (asm pha :implied) 63 | (asm clc :implied) 64 | (asm lda :stack-relative 1) 65 | (asm adc :stack-relative 4) 66 | (asm adc :stack-relative 5) 67 | (asm plx :implied) 68 | (asm rts :implied))) 69 | 70 | (setf (gethash *functions* main) 71 | '(progn (asm label loop) 72 | (asm lda :direct (global n)) 73 | (asm cmp :immediate 10) 74 | (asm beq :label else) 75 | (asm inc :direct (global n)) 76 | (asm bra :label loop) 77 | (asm bra :label end) 78 | (asm label else) 79 | (asm dec :direct (global n)) 80 | (asm label end) 81 | (asm lda :immediate 3) 82 | (asm pha :implied) 83 | (asm lda :direct (global n)) 84 | (asm pha :implied) 85 | (asm jsr :absolute (function foo)) 86 | (asm sta :direct (global _temp1)) 87 | (asm tsc :implied) 88 | (asm clc :implied) 89 | (asm adc :immediate 2) 90 | (asm tcs :implied) 91 | (asm lda :direct (global _temp1)) 92 | (asm sta :direct (global n)))) 93 | -------------------------------------------------------------------------------- /cs400.features/compiler/notes/oo: -------------------------------------------------------------------------------- 1 | # OO 2 | 3 | Some ideas for a light Object system on top of c. 4 | 5 | # Inheritance 6 | 7 | Instead of inheritence, we simply support struct includes: 8 | 9 | struct a { int one, two; } 10 | struct b { struct a; int three; } 11 | struct b b; 12 | return b.one; 13 | 14 | Note that including any struct more than once is impossible since the 15 | namespace would have conflicts. This lets us have simple method 16 | dispatch. 17 | 18 | # Methods 19 | 20 | Methods are definied externally to a struct. Method dispatch is done 21 | at compile time, and doesn't change the meaning of structs in any way. 22 | Methods are simply dispatched to the closest possible match, where 23 | includes mentioned earlier in a struct are considered closer matches. 24 | 25 | (generic + (a b -> c)) 26 | (method + ((a struct-a) (b struct-a) -> int) 27 | (return 4)) 28 | (method + ((a struct-b) (b struct-b) -> int) 29 | (return 5)) 30 | (var (a b) struct-a) 31 | (var (c d) struct-b) 32 | (+ a b) ;; => 4 33 | (+ c d) ;; => 5 34 | (+ a c) ;; => 4 35 | 36 | Here is some conceivable resulting c code: 37 | 38 | struct a { int one, two; } 39 | struct b { struct a __a; int three; } // __a is an include. 40 | return b.one; 41 | 42 | int plus_struct_a (struct a a, struct a b) { 43 | return 4; } 44 | int plus_struct_b (struct b a, struct b b) { 45 | return 5; } 46 | struct a a, b; 47 | struct b c, d; 48 | plus_struct_a(a, b) 49 | plus_struct_b(c, d) 50 | plus_struct_a(a, c.__a) 51 | -------------------------------------------------------------------------------- /cs400.features/compiler/package.lisp: -------------------------------------------------------------------------------- 1 | " 2 | This is just the package definition. It's really too small to 3 | justify having its own file, but I think it will grow. Eventualy we 4 | need to export symbols and stuff here. 5 | " 6 | 7 | (defpackage #:cs400-compiler 8 | (:use #:cl #:iterate #:cl-match #:split-sequence) 9 | (:shadow #:match) 10 | (:nicknames #:s)) 11 | 12 | (defpackage :c) 13 | 14 | (in-package #:cs400-compiler) 15 | (setf (readtable-case *readtable*) :invert) 16 | -------------------------------------------------------------------------------- /cs400.features/docs/Compiler.ppt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.features/docs/Compiler.ppt.gz -------------------------------------------------------------------------------- /cs400.features/docs/Makefile: -------------------------------------------------------------------------------- 1 | all: prospectus.pdf 2 | clean: cleanup; rm -f prospectus.pdf 3 | cleanup:; rm -f *.aux *.dvi *.log *~ 4 | %.pdf: %.tex; pdflatex -interaction batchmode $^ 5 | -------------------------------------------------------------------------------- /cs400.features/docs/presentation-3/Makefile: -------------------------------------------------------------------------------- 1 | clean:; rm -f *~ 2 | -------------------------------------------------------------------------------- /cs400.features/docs/presentation-3/input1.c.lisp: -------------------------------------------------------------------------------- 1 | (in-package :c) 2 | 3 | (proc (main int) ()) 4 | -------------------------------------------------------------------------------- /cs400.features/docs/presentation-3/input2.c.lisp: -------------------------------------------------------------------------------- 1 | (in-package :c) 2 | 3 | (proc (main int) () 4 | (var x int 1) 5 | (while x (++ x))) 6 | -------------------------------------------------------------------------------- /cs400.features/docs/presentation-3/presentation-3.org: -------------------------------------------------------------------------------- 1 | #+DRAWERS: SELFNOTE 2 | 3 | * CS400 Compiler 4 | [[./scratch]] 5 | 6 | ** Group Organization 7 | :SELFNOTE: 8 | - Beck asked which features we have make a decision not to 9 | implement. 10 | - Not really how we're thinking about it. 11 | :END: 12 | *** Goals 13 | :SELFNOTE: 14 | - Write a *useful* compiler for the SNES. 15 | - No fixed set of features. 16 | - Ultimate, unachievable Goal: Write a 17 | compiler that supports all of C99. 18 | - Wont happen so we increment towards it. 19 | :END: 20 | *** Incremental Approach 21 | :SELFNOTE: 22 | - Working compiler at all times. 23 | - Add the next-most-important 24 | approachable feature. 25 | :END: 26 | *** Some Features that We Need 27 | :SELFNOTE: 28 | - Before we have a useful compiler 29 | - Function Calls argument passing 30 | - Nested Expressions 31 | - Pointers and Arrays 32 | - Access to all of memory 33 | :END: 34 | *** Some Difficult Features 35 | :SELFNOTE: 36 | (puts these off because they are 37 | more difficult then they seem) 38 | - Type System 39 | - Optimization 40 | - Floating point (No HW support) 41 | - Nested Expressions 42 | + (+ (f 3 4) (g 4 (f 0 0))) 43 | :END: 44 | *** Meeting Organization 45 | :SELFNOTE: 46 | - Meet 3 times a week. 47 | - Most work is done as a group 48 | during this time. 49 | - We discuss how to implement a 50 | features, then I implement it on 51 | the projector. (Pick a feature; 52 | discuss; implement) 53 | :END: 54 | ** Compiler Implementation 55 | *** Approach Summary 56 | **** Normal Compiler Implementation 57 | :SELFNOTE: 58 | - Compiler | input file | output file 59 | - Compiler parses input file 60 | - Compiler performs a series of 61 | modifications to the AST. 62 | - Code generation and output 63 | :END: 64 | **** Our Implementation 65 | :SELFNOTE: 66 | - S-expression Syntax 67 | - Extend CL with macros. 68 | - This makes the inputs a executable 69 | Lisp program which outputs asm code. 70 | - Compiler is implemented as Common Lisp 71 | macros. 72 | - This really is a different paradigm. 73 | :END: 74 | [[/home/ben/repositories/sexp-syntaxes/midimsg.c.lisp][Syntax Example]] 75 | 76 | *** A Runnable Input Example 77 | [[../../compiler/inputs]] 78 | :SELFNOTE: 79 | Show compiler running as a Lisp 80 | Interpreter. 81 | 82 | 83 | :END: 84 | *** An Input Example 85 | [[./input1.c.lisp]] 86 | [[./input2.c.lisp]] 87 | 88 | :SELFNOTE: 89 | - Run C translator as Lisp Interpreter 90 | 91 | (in-package :c) 92 | (cl:defmacro sub (name cl:&body code) 93 | `(proc (,name void) () ,@code)) 94 | (sub hi (c::var x int 0)) 95 | 96 | - Generate C Code 97 | - Generate ASM Code 98 | - Partially Expanded Common Lisp Code 99 | :END: 100 | *** Our Implementation Approach 101 | :SELFNOTE: 102 | - Input file is actually 103 | a Common Lisp program 104 | - Compiler is a Common Lisp 105 | library (macros). 106 | - Input file has full access 107 | to Common Lisp, and can add 108 | anything it likes to the 109 | compiler. 110 | - The Common-Lisp macro 111 | expansion process can be 112 | seen as a series of AST 113 | transformations, except: 114 | + You don't think about it 115 | like that. 116 | + AST is valid CL at every 117 | step. 118 | - This is the way Common Lisp 119 | implementations work. 120 | - This is the way Common Lisp 121 | libraries work. 122 | :END: 123 | -------------------------------------------------------------------------------- /cs400.features/docs/presentation-3/show.lisp: -------------------------------------------------------------------------------- 1 | (in-package :cs400-compiler) 2 | 3 | (defmacro expand (code) 4 | `(let ((*package* (find-package :cs400-compiler))) 5 | (print (macroexpand ',code)))) 6 | -------------------------------------------------------------------------------- /cs400.features/flashing-colors/Makefile: -------------------------------------------------------------------------------- 1 | AC = ../assembler/65816asm 2 | SC = ../compiler/compiler 3 | 4 | all: flashing.smc 5 | clean:; rm -f flashing.smc flashing.asm 6 | test: all; snes9x flashing.smc 7 | 8 | $(AC):; cd ../assembler; make 9 | $(SC):; cd ../compiler; make 10 | %.smc: %.asm $(AC); $(AC) $< 11 | %.asm: %.c.lisp $(SC); $(SC) < $< > $@ 12 | -------------------------------------------------------------------------------- /cs400.features/flashing-colors/flashing.c.lisp: -------------------------------------------------------------------------------- 1 | (in-package :c) 2 | 3 | (s::emit "#LoROM") 4 | 5 | (proto set_background_color) 6 | 7 | (proc (main int) () 8 | 9 | "Set screen to max brightness" 10 | (s::8-bit-mode) 11 | (s::asm s::lda :immediate #x0F) 12 | (s::asm s::sta :absolute #x2100) 13 | (s::16-bit-mode) 14 | 15 | (var color int 0) 16 | (while (s::lda 1) 17 | 18 | "Get input from the controller" 19 | (s::asm s::lda :absolute #x4218) 20 | (if (s::asm s::and :immediate-w #x0100) ;; is right button depressed? 21 | (++ color) 22 | color) 23 | (set_background_color color #x0000))) 24 | 25 | (proc (set_background_color void) (color color_address) 26 | color_address 27 | (s::8-bit-mode) 28 | (s::asm s::sta :absolute #x2121) 29 | (s::16-bit-mode) 30 | 31 | color 32 | (s::8-bit-mode) 33 | (s::asm s::sta :absolute #x2122) 34 | (s::asm s::xba :implied) 35 | (s::asm s::sta :absolute #x2122) 36 | (s::16-bit-mode)) 37 | -------------------------------------------------------------------------------- /cs400.features/jormungandr/JormungandrChar.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.features/jormungandr/JormungandrChar.dat -------------------------------------------------------------------------------- /cs400.features/jormungandr/JormungandrColor.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.features/jormungandr/JormungandrColor.dat -------------------------------------------------------------------------------- /cs400.features/jormungandr/JormungandrFloorMap.dat: -------------------------------------------------------------------------------- 1 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -------------------------------------------------------------------------------- /cs400.features/jormungandr/JormungandrFrameMap.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.features/jormungandr/JormungandrFrameMap.dat -------------------------------------------------------------------------------- /cs400.features/jormungandr/JormungandrTrailMap.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.features/jormungandr/JormungandrTrailMap.dat -------------------------------------------------------------------------------- /cs400.features/jormungandr/Makefile: -------------------------------------------------------------------------------- 1 | data_files = JormungandrChar.dat JormungandrColor.dat JormungandrFloorMap.dat 2 | data_files += JormungandrFrameMap.dat JormungandrTrailMap.dat 3 | AC = ../assembler/65816asm 4 | 5 | all: jormungandr.smc 6 | $(AC):; cd ../assembler; make 7 | %.smc: %.asm $(data_files) $(AC); $(AC) $< 8 | clean:; rm -f jormungandr.smc 9 | test: all; snes9x jormungandr.smc 10 | -------------------------------------------------------------------------------- /cs400.features/phoenix/Makefile: -------------------------------------------------------------------------------- 1 | data_files = Phoenix_Color.dat Phoenix_Char.dat Phoenix_Frame_BG_Map.dat 2 | data_files += Phoenix_Star_BG_Map.dat 3 | AC = ../assembler/65816asm 4 | 5 | all: phoenix.smc 6 | $(AC):; cd ../assembler; make 7 | phoenix.smc: $(data_files) phoenix.asm $(AC); $(AC) phoenix.asm 8 | clean:; rm -f phoenix.smc 9 | test: all; snes9x phoenix.smc 10 | -------------------------------------------------------------------------------- /cs400.features/phoenix/Phoenix_Char.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.features/phoenix/Phoenix_Char.dat -------------------------------------------------------------------------------- /cs400.features/phoenix/Phoenix_Color.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.features/phoenix/Phoenix_Color.dat -------------------------------------------------------------------------------- /cs400.features/phoenix/Phoenix_Frame_BG_Map.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.features/phoenix/Phoenix_Frame_BG_Map.dat -------------------------------------------------------------------------------- /cs400.features/phoenix/Phoenix_Star_BG_Map.dat: -------------------------------------------------------------------------------- 1 | ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? = ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? < ; ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ; ? ? ? ? ? ? = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < > ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < = ? ? ? ? ? ? ? ? ; ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? = ? ? < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? > ? ? ; ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ; ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ; ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ; ? ? ? ? ? ? ? ? ? ? > ? ? ? < ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? -------------------------------------------------------------------------------- /cs400.master/AUTHORS: -------------------------------------------------------------------------------- 1 | bsummer4@eecs.utk.edu Benjamin Summers 2 | josborn8@eecs.utk.edu James Osborne 3 | sgray10@eecs.utk.edu Stephen Gray 4 | ktrofatt@utk.edu Kenneth Parker Trofatter 5 | -------------------------------------------------------------------------------- /cs400.master/docs/Compiler.ppt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.master/docs/Compiler.ppt.gz -------------------------------------------------------------------------------- /cs400.master/docs/Makefile: -------------------------------------------------------------------------------- 1 | all: prospectus.pdf 2 | clean: cleanup; rm -f prospectus.pdf 3 | cleanup:; rm -f *.aux *.dvi *.log *~ 4 | %.pdf: %.tex; pdflatex -interaction batchmode $^ 5 | -------------------------------------------------------------------------------- /cs400.master/docs/final-docs/final-docs.org: -------------------------------------------------------------------------------- 1 | * Compiler 2 | ** Progress; Working Demo (Pong) 3 | ** Evolution of Goals 4 | ** Group Organization 5 | ** Implementation 6 | *** Current Implementation 7 | *** Evolution of Implementation 8 | *** Hardware 9 | -------------------------------------------------------------------------------- /cs400.master/docs/presentation-3/Makefile: -------------------------------------------------------------------------------- 1 | clean:; rm -f *~ 2 | -------------------------------------------------------------------------------- /cs400.master/docs/presentation-3/input1.c.lisp: -------------------------------------------------------------------------------- 1 | (in-package :c) 2 | 3 | (proc (main int) ()) 4 | -------------------------------------------------------------------------------- /cs400.master/docs/presentation-3/input2.c.lisp: -------------------------------------------------------------------------------- 1 | (in-package :c) 2 | 3 | (proc (main int) () 4 | (var x int 1) 5 | (while x (++ x))) 6 | -------------------------------------------------------------------------------- /cs400.master/docs/presentation-3/presentation-3.org: -------------------------------------------------------------------------------- 1 | #+DRAWERS: SELFNOTE 2 | 3 | * CS400 Compiler 4 | [[./scratch]] 5 | 6 | ** Group Organization 7 | :SELFNOTE: 8 | - Beck asked which features we have make a decision not to 9 | implement. 10 | - Not really how we're thinking about it. 11 | :END: 12 | *** Goals 13 | :SELFNOTE: 14 | - Write a *useful* compiler for the SNES. 15 | - No fixed set of features. 16 | - Ultimate, unachievable Goal: Write a 17 | compiler that supports all of C99. 18 | - Wont happen so we increment towards it. 19 | :END: 20 | *** Incremental Approach 21 | :SELFNOTE: 22 | - Working compiler at all times. 23 | - Add the next-most-important 24 | approachable feature. 25 | :END: 26 | *** Some Features that We Need 27 | :SELFNOTE: 28 | - Before we have a useful compiler 29 | - Function Calls argument passing 30 | - Nested Expressions 31 | - Pointers and Arrays 32 | - Access to all of memory 33 | :END: 34 | *** Some Difficult Features 35 | :SELFNOTE: 36 | (puts these off because they are 37 | more difficult then they seem) 38 | - Type System 39 | - Optimization 40 | - Floating point (No HW support) 41 | - Nested Expressions 42 | + (+ (f 3 4) (g 4 (f 0 0))) 43 | :END: 44 | *** Meeting Organization 45 | :SELFNOTE: 46 | - Meet 3 times a week. 47 | - Most work is done as a group 48 | during this time. 49 | - We discuss how to implement a 50 | features, then I implement it on 51 | the projector. (Pick a feature; 52 | discuss; implement) 53 | :END: 54 | ** Compiler Implementation 55 | *** Approach Summary 56 | **** Normal Compiler Implementation 57 | :SELFNOTE: 58 | - Compiler | input file | output file 59 | - Compiler parses input file 60 | - Compiler performs a series of 61 | modifications to the AST. 62 | - Code generation and output 63 | :END: 64 | **** Our Implementation 65 | :SELFNOTE: 66 | - S-expression Syntax 67 | - Extend CL with macros. 68 | - This makes the inputs a executable 69 | Lisp program which outputs asm code. 70 | - Compiler is implemented as Common Lisp 71 | macros. 72 | - This really is a different paradigm. 73 | :END: 74 | [[/home/ben/repositories/sexp-syntaxes/midimsg.c.lisp][Syntax Example]] 75 | 76 | *** A Runnable Input Example 77 | [[../../compiler/inputs]] 78 | :SELFNOTE: 79 | Show compiler running as a Lisp 80 | Interpreter. 81 | 82 | 83 | :END: 84 | *** An Input Example 85 | [[./input1.c.lisp]] 86 | [[./input2.c.lisp]] 87 | 88 | :SELFNOTE: 89 | - Run C translator as Lisp Interpreter 90 | 91 | (in-package :c) 92 | (cl:defmacro sub (name cl:&body code) 93 | `(proc (,name void) () ,@code)) 94 | (sub hi (c::var x int 0)) 95 | 96 | - Generate C Code 97 | - Generate ASM Code 98 | - Partially Expanded Common Lisp Code 99 | :END: 100 | *** Our Implementation Approach 101 | :SELFNOTE: 102 | - Input file is actually 103 | a Common Lisp program 104 | - Compiler is a Common Lisp 105 | library (macros). 106 | - Input file has full access 107 | to Common Lisp, and can add 108 | anything it likes to the 109 | compiler. 110 | - The Common-Lisp macro 111 | expansion process can be 112 | seen as a series of AST 113 | transformations, except: 114 | + You don't think about it 115 | like that. 116 | + AST is valid CL at every 117 | step. 118 | - This is the way Common Lisp 119 | implementations work. 120 | - This is the way Common Lisp 121 | libraries work. 122 | :END: 123 | -------------------------------------------------------------------------------- /cs400.master/docs/presentation-3/show.lisp: -------------------------------------------------------------------------------- 1 | (in-package :cs400-compiler) 2 | 3 | (defmacro expand (code) 4 | `(let ((*package* (find-package :cs400-compiler))) 5 | (print (macroexpand ',code)))) 6 | -------------------------------------------------------------------------------- /cs400.master/games/flashing-colors/Makefile: -------------------------------------------------------------------------------- 1 | AC = ../assembler/65816asm 2 | SC = ../compiler/compiler 3 | 4 | all: flashing.smc 5 | clean:; rm -f flashing.smc flashing.asm 6 | test: all; snes9x flashing.smc 7 | 8 | $(AC):; cd ../assembler; make 9 | $(SC):; cd ../compiler; make 10 | %.smc: %.asm $(AC); $(AC) $< 11 | %.asm: %.c.lisp $(SC); $(SC) < $< > $@ 12 | -------------------------------------------------------------------------------- /cs400.master/games/flashing-colors/flashing.c.lisp: -------------------------------------------------------------------------------- 1 | (in-package :c) 2 | 3 | (s::emit "#LoROM") 4 | 5 | (proto set_background_color) 6 | 7 | (proc (main int) () 8 | 9 | "Set screen to max brightness" 10 | (s::8-bit-mode) 11 | (s::asm s::lda :immediate #x0F) 12 | (s::asm s::sta :absolute #x2100) 13 | (s::16-bit-mode) 14 | 15 | (var color int 0) 16 | (while (s::lda 1) 17 | 18 | "Get input from the controller" 19 | (s::asm s::lda :absolute #x4218) 20 | (if (s::asm s::and :immediate-w #x0100) ;; is right button depressed? 21 | (++ color) 22 | color) 23 | (set_background_color color #x0000))) 24 | 25 | (proc (set_background_color void) (color color_address) 26 | color_address 27 | (s::8-bit-mode) 28 | (s::asm s::sta :absolute #x2121) 29 | (s::16-bit-mode) 30 | 31 | color 32 | (s::8-bit-mode) 33 | (s::asm s::sta :absolute #x2122) 34 | (s::asm s::xba :implied) 35 | (s::asm s::sta :absolute #x2122) 36 | (s::16-bit-mode)) 37 | -------------------------------------------------------------------------------- /cs400.master/games/jormungandr/JormungandrChar.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.master/games/jormungandr/JormungandrChar.dat -------------------------------------------------------------------------------- /cs400.master/games/jormungandr/JormungandrColor.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.master/games/jormungandr/JormungandrColor.dat -------------------------------------------------------------------------------- /cs400.master/games/jormungandr/JormungandrFloorMap.dat: -------------------------------------------------------------------------------- 1 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -------------------------------------------------------------------------------- /cs400.master/games/jormungandr/JormungandrFrameMap.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.master/games/jormungandr/JormungandrFrameMap.dat -------------------------------------------------------------------------------- /cs400.master/games/jormungandr/JormungandrTrailMap.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.master/games/jormungandr/JormungandrTrailMap.dat -------------------------------------------------------------------------------- /cs400.master/games/jormungandr/Makefile: -------------------------------------------------------------------------------- 1 | data_files = JormungandrChar.dat JormungandrColor.dat JormungandrFloorMap.dat 2 | data_files += JormungandrFrameMap.dat JormungandrTrailMap.dat 3 | AC = ../assembler/65816asm 4 | 5 | all: jormungandr.smc 6 | $(AC):; cd ../assembler; make 7 | %.smc: %.asm $(data_files) $(AC); $(AC) $< 8 | clean:; rm -f jormungandr.smc 9 | test: all; snes9x jormungandr.smc 10 | -------------------------------------------------------------------------------- /cs400.master/games/phoenix/char.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.master/games/phoenix/char.dat -------------------------------------------------------------------------------- /cs400.master/games/phoenix/color.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.master/games/phoenix/color.dat -------------------------------------------------------------------------------- /cs400.master/games/phoenix/frame_bg_map.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.master/games/phoenix/frame_bg_map.dat -------------------------------------------------------------------------------- /cs400.master/games/phoenix/mkfile: -------------------------------------------------------------------------------- 1 | data = `{echo *.dat} 2 | 3 | all:V: phoenix.smc 4 | clean:V: 5 | rm -f phoenix.smc 6 | test:V: all 7 | bsnes phoenix.smc 8 | 9 | phoenix.smc: $data phoenix.asm 10 | 65816a phoenix.asm 11 | -------------------------------------------------------------------------------- /cs400.master/games/phoenix/star_bg_map.dat: -------------------------------------------------------------------------------- 1 | ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? = ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? < ; ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ; ? ? ? ? ? ? = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < > ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < = ? ? ? ? ? ? ? ? ; ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? = ? ? < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? > ? ? ; ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ; ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ; ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ; ? ? ? ? ? ? ? ? ? ? > ? ? ? < ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? -------------------------------------------------------------------------------- /cs400.master/games/pong/Makefile: -------------------------------------------------------------------------------- 1 | data_files = 2 | AC = ../assembler/65816asm 3 | 4 | all: pong.smc 5 | test: all; snes9x pong.smc 6 | clean:; rm -f pong.smc 7 | 8 | %.asm: %.c.lisp $(CC); $(CC) < $< > $@ 9 | %.smc: %.asm $(data_files) $(AC); $(AC) $< 10 | $(AC):; cd ../assembler; make 11 | -------------------------------------------------------------------------------- /cs400.master/games/pong/pong.h: -------------------------------------------------------------------------------- 1 | ; # WRAM $7E:0000-$7F:FFFF 2 | 3 | ; # Direct Page 4 | ; #Name $00 scratch_pad $10 5 | ; #Name $10 inidisp b 6 | ; #Name $11 objsel b 7 | ; #Name $12 oamadd w 8 | ; #Name $14 bgmode b 9 | ; #Name $15 mosaic b 10 | ; #Name $16 bg1sc b 11 | ; #Name $17 bg2sc b 12 | ; #Name $18 bg3sc b 13 | ; #Name $19 bg4sc b 14 | ; #Name $1A bg12nba b 15 | ; #Name $1B bg34nba b 16 | ; #Name $1C bg1hofs w 17 | ; #Name $1E bg1vofs w 18 | ; #Name $20 bg2hofs w 19 | ; #Name $22 bg2vofs w 20 | ; #Name $24 bg3hofs w 21 | ; #Name $26 bg3vofs w 22 | ; #Name $28 bg4hofs w 23 | ; #Name $2A bg4vofs w 24 | ; #Name $2C vmainc b 25 | ; #Name $2D vmadd w 26 | ; #Name $2F m7sel b 27 | ; #Name $30 m7a w 28 | ; #Name $32 m7b w 29 | ; #Name $34 m7c w 30 | ; #Name $36 m7d w 31 | ; #Name $38 m7x w 32 | ; #Name $3A m7y w 33 | ; #Name $3C cgadd b 34 | ; #Name $3D w12sel b 35 | ; #Name $3E w34sel b 36 | ; #Name $3F wobjsel b 37 | ; #Name $40 wh0 b 38 | ; #Name $41 wh1 b 39 | ; #Name $42 wh2 b 40 | ; #Name $43 wh3 b 41 | ; #Name $44 wbglog b 42 | ; #Name $45 wobjlog b 43 | ; #Name $46 tm b 44 | ; #Name $47 ts b 45 | ; #Name $48 tmw b 46 | ; #Name $49 tsw b 47 | ; #Name $4A cgswsel b 48 | ; #Name $4B cgadsub b 49 | ; #Name $4C coldata_blue b 50 | ; #Name $4D coldata_green b 51 | ; #Name $4E coldata_red b 52 | ; #Name $4F setini b 53 | ; #Name $50 ophct w 54 | ; #Name $52 opvct w 55 | ; #Name $54 stat77 b 56 | ; #Name $55 stat78 b 57 | ; #Name $56 apuio0 b 58 | ; #Name $57 apuio1 b 59 | ; #Name $58 apuio2 b 60 | ; #Name $59 apuio3 b 61 | ; #Name $5A wmadd l 62 | ; #Name $5D nmitimen b 63 | ; #Name $5E wrio b 64 | ; #Name $5F htime w 65 | ; #Name $61 vtime w 66 | ; #Name $63 mdmaen b 67 | ; #Name $64 hdmaen b 68 | ; #Name $65 memsel b 69 | ; #Name $66 rdnmi b 70 | ; #Name $67 timeup b 71 | ; #Name $68 hvbjoy b 72 | ; #Name $69 rdio b 73 | ; #Name $006A joy w[4] 74 | ; #Name $6A joy1 w 75 | ; #Name $6C joy2 w 76 | ; #Name $6E joy3 w 77 | ; #Name $70 joy4 w 78 | 79 | ; #Name $0072 joy.last w[4] 80 | ; #Name $72 joy1.last w 81 | ; #Name $74 joy2.last w 82 | ; #Name $76 joy3.last w 83 | ; #Name $78 joy4.last w 84 | ; #Name $007A joy.edge w[4] 85 | ; #Name $7A joy1.edge w 86 | ; #Name $7C joy2.edge w 87 | ; #Name $7E joy3.edge w 88 | ; #Name $80 joy4.edge w 89 | ; #Name $0082 joy.hold b[4] 90 | ; #Name $82 joy1.hold b 91 | ; #Name $83 joy2.hold b 92 | ; #Name $84 joy3.hold b 93 | ; #Name $85 joy4.hold b 94 | ; #Name $0086 joy.cool b[4] 95 | ; #Name $86 joy1.cool b 96 | ; #Name $87 joy2.cool b 97 | ; #Name $88 joy3.cool b 98 | ; #Name $89 joy4.cool b 99 | 100 | ; #Name $8A Nmi.ready b 101 | ; #Name $8B Nmi.count w 102 | ; #Name $8D Nmi.HDMA.data l 103 | ; #Name $90 Nmi.VRAM_DMA.data l 104 | ; #Name $93 Nmi.VRAM_DMA.data_i w 105 | ; #Name $95 Nmi.VRAM_Write.table_i w 106 | 107 | ; #Name $97 irq_program l 108 | 109 | ; #Name $9A Main.count w 110 | ; #Name $9C Main.program w 111 | ; #Name $9E Sub.program w 112 | 113 | ; #Name $A0 oam_i w 114 | ; #Name $A2 oam2_byte_i b 115 | ; #Name $A3 oam2_bit_i b 116 | 117 | ; #Name $A6 Rng.number w 118 | ; #Name $A8 pause b 119 | 120 | ; # Scratch Pad 121 | 122 | ; #Name $00 Multiply_16.m1 w 123 | ; #Name $02 Multiply_16.m2 w 124 | ; #Name $04 Multiply_16.p w 125 | 126 | ; #Name $00 Divide_16.n w // Numerator 127 | ; #Name $02 Divide_16.d w // Denomenator 128 | ; #Name $04 Divide_16.q w // Quotient 129 | ; #Name $08 Divide_16.r w // Remainder 130 | 131 | ; #Name $00 Draw_Sprite.data_i l 132 | ; #Name $02 Draw_Sprite.data_bank b 133 | ; #Name $03 Draw_Sprite.obj_count b 134 | ; #Name $04 Draw_Sprite.x b 135 | ; #Name $05 Draw_Sprite.y b 136 | ; #Name $06 Draw_Sprite.char_i w 137 | ; #Name $08 Draw_Sprite.obj_p_override b 138 | 139 | 140 | ; # WRAM $7E:0000-$7E:2000============= Size ==== 141 | ; #Name $0100 oam $200 142 | ; #Name $0100 oam.x b 143 | ; #Name $0101 oam.y b 144 | ; #Name $0102 oam.c b 145 | ; #Name $0103 oam.p b 146 | ; #Name $0300 oam2 $20 147 | 148 | ; #Name $0320 cgram $200 149 | 150 | ; #Name $0520 Nmi.VRAM_Write.table $E0 151 | ; #Name $0520 Nmi.VRAM_Write.addr w 152 | ; #Name $0522 Nmi.VRAM_Write.data w 153 | 154 | 155 | ; # Subroutine Prototypes 156 | ; #Code w RESET_Vector 157 | ; #Code w NMI_Vector 158 | ; #Code w IRQ_Vector 159 | ; #Code l Reset 160 | ; #Code w Reset.Registers 161 | ; #Code w Reset.VRAM 162 | ; #Code w Reset.OAM 163 | ; #Code w Reset.CGRAM 164 | ; #Code w Reset.APU 165 | 166 | ; #Code l Nmi.Wait 167 | ; #Code l Nmi 168 | ; #Code w Nmi.Registers 169 | ; #Code w Nmi.HDMA 170 | ; #Code w Nmi.VRAM_DMA 171 | ; #Code w Nmi.VRAM_Write 172 | 173 | ; #Code l Irq 174 | 175 | ; #Code l Main 176 | ; #Data w Main.programs 177 | ; #Code w Engine.Initiate 178 | ; #Code w Engine.Fadein 179 | ; #Code w Engine.Run 180 | ; #Code w Test_Joy 181 | ; #Code w Pause 182 | 183 | ; #Code w Ship 184 | ; #Data w Ship.programs 185 | 186 | ; #Code l Multiply_16 187 | ; #Code l Divide 188 | ; #Code l Immediate_DMA 189 | ; #Code l Ready_Oam 190 | ; #Code l Hide_Unused_Oam 191 | ; #Code l Draw_Sprite 192 | ; #Code l Rng 193 | 194 | ; #Data w ship_1_sprite 195 | ; #Data w ship_2_sprite 196 | ; #Data l sinusoid 197 | ; #Data l char_set 198 | ; #Data l frame_map 199 | ; #Data l floor_map 200 | ; #Data l color_set 201 | ; #Data l rom_header 202 | ; #Data l vector_table 203 | -------------------------------------------------------------------------------- /cs400.master/games/pong/snes-registers.h: -------------------------------------------------------------------------------- 1 | ; # SNES Registers 2 | ; #Name $2100 INIDISP b 3 | ; #Name $2101 OBJSEL b 4 | ; #Name $2102 OAMADD w 5 | ; #Name $2104 OAMDATA b,LH 6 | ; #Name $2105 BGMODE b 7 | ; #Name $2106 MOSAIC b 8 | ; #Name $2107 BG1SC b 9 | ; #Name $2108 BG2SC b 10 | ; #Name $2109 BG3SC b 11 | ; #Name $210A BG4SC b 12 | ; #Name $210B BG12NBA b 13 | ; #Name $210C BG34NBA b 14 | ; #Name $210D BG1HOFS b,LH 15 | ; #Name $210E BG1VOFS b,LH 16 | ; #Name $210F BG2HOFS b,LH 17 | ; #Name $2110 BG2VOFS b,LH 18 | ; #Name $2111 BG3HOFS b,LH 19 | ; #Name $2112 BG3VOFS b,LH 20 | ; #Name $2113 BG4HOFS b,LH 21 | ; #Name $2114 BG4VOFS b,LH 22 | ; #Name $2115 VMAINC b 23 | ; #Name $2116 VMADD w 24 | ; #Name $2118 VMDATA w 25 | ; #Name $211A M7SEL b 26 | ; #Name $211B M7A b,LH 27 | ; #Name $211C M7B b,LH 28 | ; #Name $211D M7C b,LH 29 | ; #Name $211E M7D b,LH 30 | ; #Name $211F M7X b,LH 31 | ; #Name $2120 M7Y b,LH 32 | ; #Name $2121 CGADD b 33 | ; #Name $2122 CGDATA b,LH 34 | ; #Name $2123 W12SEL b 35 | ; #Name $2124 W34SEL b 36 | ; #Name $2125 WOBJSEL b 37 | ; #Name $2126 WH0 b 38 | ; #Name $2127 WH1 b 39 | ; #Name $2128 WH2 b 40 | ; #Name $2129 WH3 b 41 | ; #Name $212A WBGLOG b 42 | ; #Name $212B WOBJLOG b 43 | ; #Name $212C TM b 44 | ; #Name $212D TS b 45 | ; #Name $212E TMW_ b 46 | ; #Name $212F TSW_ b 47 | ; #Name $2130 CGSWSEL b 48 | ; #Name $2131 CGADSUB b 49 | ; #Name $2132 COLDATA b 50 | ; #Name $2133 SETINI b 51 | ; #Name $2134 RDMPY24 l,ro 52 | ; #Name $2137 SLHV b,ro 53 | ; #Name $2138 RDOAMDATA b,ro,LH 54 | ; #Name $2139 RDVMDATA w,ro 55 | ; #Name $213B RDCGDATA b,ro,LH 56 | ; #Name $213C OPHCT b,ro,LH 57 | ; #Name $213D OPVCT b,ro,LH 58 | ; #Name $213E STAT77 b,ro 59 | ; #Name $213F STAT78 b,ro 60 | ; #Name $2140 APUIO0 b 61 | ; #Name $2141 APUIO1 b 62 | ; #Name $2142 APUIO2 b 63 | ; #Name $2143 APUIO3 b 64 | ; #Name $2180 WMDATA b 65 | ; #Name $2181 WMADD l 66 | ; #Name $4016 JOYIO w 67 | ; #Name $4200 NMITIMEN b 68 | ; #Name $4201 WRIO b 69 | ; #Name $4202 WRMPYA b 70 | ; #Name $4203 WRMPYB b 71 | ; #Name $4204 WRDIVA w 72 | ; #Name $4206 WRDIVB b 73 | ; #Name $4207 HTIME w 74 | ; #Name $4209 VTIME w 75 | ; #Name $420B MDMAEN b 76 | ; #Name $420C HDMAEN b 77 | ; #Name $420D MEMSEL b 78 | ; #Name $4210 RDNMI b,ro 79 | ; #Name $4211 TIMEUP b,ro 80 | ; #Name $4212 HVBJOY b,ro 81 | ; #Name $4213 RDIO b,ro 82 | ; #Name $4214 RDDIV w,ro 83 | ; #Name $4216 RDMPY16 w,ro 84 | ; #Name $4218 JOY1 w 85 | ; #Name $421A JOY2 w 86 | ; #Name $421C JOY3 w 87 | ; #Name $421E JOY4 w 88 | ; #Name $4300 DMAP b 89 | ; #Name $4301 DMAB b 90 | ; #Name $4302 DMAA l 91 | ; #Name $4305 DMAD l 92 | ; #Name $4308 DMAI w 93 | ; #Name $430A DMAL b 94 | ; #Name $4300 DMAP0 b 95 | ; #Name $4301 DMAB0 b 96 | ; #Name $4302 DMAA0 l 97 | ; #Name $4305 DMAD0 l 98 | ; #Name $4308 DMAI0 w 99 | ; #Name $430A DMAL0 b 100 | ; #Name $4310 DMAP1 b 101 | ; #Name $4311 DMAB1 b 102 | ; #Name $4312 DMAA1 l 103 | ; #Name $4315 DMAD1 l 104 | ; #Name $4318 DMAI1 w 105 | ; #Name $431A DMAL1 b 106 | ; #Name $4320 DMAP2 b 107 | ; #Name $4321 DMAB2 b 108 | ; #Name $4322 DMAA2 l 109 | ; #Name $4325 DMAD2 l 110 | ; #Name $4328 DMAI2 w 111 | ; #Name $432A DMAL2 b 112 | ; #Name $4330 DMAP3 b 113 | ; #Name $4331 DMAB3 b 114 | ; #Name $4332 DMAA3 l 115 | ; #Name $4335 DMAD3 l 116 | ; #Name $4338 DMAI3 w 117 | ; #Name $433A DMAL3 b 118 | ; #Name $4340 DMAP4 b 119 | ; #Name $4341 DMAB4 b 120 | ; #Name $4342 DMAA4 l 121 | ; #Name $4345 DMAD4 l 122 | ; #Name $4348 DMAI4 w 123 | ; #Name $434A DMAL4 b 124 | ; #Name $4350 DMAP5 b 125 | ; #Name $4351 DMAB5 b 126 | ; #Name $4352 DMAA5 l 127 | ; #Name $4355 DMAD5 l 128 | ; #Name $4358 DMAI5 w 129 | ; #Name $435A DMAL5 b 130 | ; #Name $4360 DMAP6 b 131 | ; #Name $4361 DMAB6 b 132 | ; #Name $4362 DMAA6 l 133 | ; #Name $4365 DMAD6 l 134 | ; #Name $4368 DMAI6 w 135 | ; #Name $436A DMAL6 b 136 | ; #Name $4370 DMAP7 b 137 | ; #Name $4371 DMAB7 b 138 | ; #Name $4372 DMAA7 l 139 | ; #Name $4375 DMAD7 l 140 | ; #Name $4378 DMAI7 w 141 | ; #Name $437A DMAL7 b 142 | -------------------------------------------------------------------------------- /cs400.master/games/pong/temp.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.master/games/pong/temp.tar -------------------------------------------------------------------------------- /cs400.master/games/pong/temp.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.master/games/pong/temp.tgz -------------------------------------------------------------------------------- /cs400.master/games/pong/toplevel.asm: -------------------------------------------------------------------------------- 1 | ; #LoROM 2 | ; #File interrupt.asm 3 | ; #File pong.asm 4 | 5 | {$0000 $0000 $8000 $8000 $8000 $8007 $0000 $8000 6 | $0000 $0000 $8000 $0000 $8000 $8000 $8000 $8000} 7 | -------------------------------------------------------------------------------- /cs400.master/util/asm.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "data.h" 5 | 6 | #define NAME_MAX 256 7 | struct File_s; 8 | struct Stat_s; 9 | struct Dll_n; 10 | struct Dll_file_s; 11 | struct Dll_link_s; 12 | struct Dll_name_s; 13 | 14 | // Token data type 15 | typedef enum Token_t_ 16 | { Token_null_t_ 17 | , Token_mnemonic_t_ 18 | , Token_name_t_ 19 | , Token_number_t_ 20 | , Token_string_t_ 21 | , Token_symbol_t_ 22 | } Token_t_; 23 | 24 | // File statistics 25 | typedef struct Stat_s { 26 | long line_c; // File line count 27 | long stmt_c; // Processed statment count 28 | long assm_c; // Assembly statment count 29 | long comp_c; // Compiler statment count 30 | long dire_c; // Directive statment count 31 | long link_c; // Link statment count 32 | long name_c; // Name directive count 33 | long code_c; // Code directive count 34 | long data_c; // Data directive count 35 | long code_s; // Code size 36 | long data_s; // Data size 37 | long file_s; // File size 38 | } Stat_s; 39 | 40 | // File structure 41 | typedef struct File_s { 42 | char *name; // File name 43 | FILE *file; // File pointer 44 | char *mode; // I/O mode 45 | char line[NAME_MAX+1]; // I/O line buffer 46 | Token_t_ type; // Data type 47 | long data; // Data value 48 | int size; // Data size (byte) 49 | int m; // Memory select 50 | int x; // Index select 51 | Stat_s *stat; // File statistics 52 | } File_s; 53 | 54 | // Dual Link List | 55 | typedef enum Dll_t_ 56 | { Dll_null_t_ // Null (unknown type) 57 | , Dll_head_t_ // List header 58 | , Dll_file_t_ // File 59 | , Dll_name_t_ // Name 60 | , Dll_link_t_ // Link 61 | } Dll_t_; 62 | 63 | typedef struct Dll_n { 64 | struct Dll_n *next, *prev; 65 | Dll_t_ type; // Datatype 66 | void *data; // Data pointer 67 | } Dll_n; 68 | 69 | typedef struct Dll_file_s { 70 | char *name; 71 | Stat_s *stat; 72 | } Dll_file_s; 73 | 74 | /* `size' is in bytes and `mode' is reserved. */ 75 | typedef struct Dll_name_s { 76 | char *name; 77 | long data; 78 | int mode, size; 79 | } Dll_name_s; 80 | 81 | /* `mode' is the invoking instruction. */ 82 | typedef struct Dll_link_s { 83 | char *name, *file; 84 | long addr; 85 | int mode; 86 | } Dll_link_s; 87 | 88 | void First_Pass (char *name); 89 | void Do_Assembly (File_s*); 90 | void Do_Compiler (File_s*); 91 | void Do_Link (File_s*); 92 | void Do_Directive (File_s*); 93 | void Dir_Block (File_s*); 94 | void Dir_Code (File_s*); 95 | void Dir_Cpu (File_s*); 96 | void Dir_Data (File_s*); 97 | void Dir_File (File_s*); 98 | void Dir_Halt (File_s*); 99 | void Dir_Name (File_s*); 100 | void Dir_PC (File_s*); 101 | void Dir_Print (File_s*); 102 | void Dir_Rom (File_s*); 103 | 104 | void Second_Pass(void); 105 | void Report (void); 106 | 107 | // General | 108 | // Error 109 | void Error(int program, int code, File_s *In, void *data); 110 | 111 | // File management 112 | File_s* New_File (char *name, char *mode); 113 | void Free_File(File_s*); 114 | 115 | // File format 116 | int Is_Whitespace (char); 117 | int Is_Numberspace(char); 118 | int Is_Namespace (char); 119 | int Is_Name (char*); 120 | 121 | // File scanning 122 | void Get_Token (File_s*); 123 | void Read_Operand(File_s*); 124 | 125 | // Program counter 126 | long PC_to_File(long); 127 | long File_to_PC(long); 128 | int Advance_PC(long); 129 | 130 | // Doubly-Linked Lists 131 | Dll_n* Dll_New (Dll_t_ type); 132 | void Dll_Free (Dll_n *list); 133 | void Dll_Insert(Dll_n *list, Dll_n *node); 134 | Dll_n* Dll_Find (Dll_n *list, Dll_n *node); 135 | void Dll_Push (Dll_n *list, Dll_n *node); 136 | Dll_n* Dll_Pull (Dll_n *list); 137 | void Dll_Print (Dll_n *list); 138 | int Dll_Size (Dll_n *list); 139 | -------------------------------------------------------------------------------- /cs400.master/util/cc/Makefile: -------------------------------------------------------------------------------- 1 | CC = ./compiler.lisp 2 | ASM = ../assembler/65816asm 3 | DAT = pongChar.dat pongFrame.dat pongPallet.dat 4 | 5 | all: compiler; 6 | clean:; rm -f *.fasl *.asm *.smc *~ compiler reset.asm snes_registers.h *.dat 7 | install: compiler; ln -f compiler ~/bin/scc 8 | 9 | ../assembler/65816asm:; cd ../assembler; make 10 | compiler: asm.lisp c.lisp c-impl.lisp compiler.lisp lib.lisp package.lisp Makefile 11 | sbcl --noinform \ 12 | --eval "(defvar *script?* nil)" \ 13 | --script "compiler.lisp" 14 | 15 | reset.asm:; cp -f inputs/reset.asm . 16 | snes_registers.h:; cp -f inputs/snes_registers.h . 17 | c.asm: inputs/c $(CC) reset.asm snes_registers.h $(DAT) 18 | $(CC) < $< > $@ 19 | colors.asm: inputs/colors.asm; cp $< $@ 20 | 21 | %.smc: %.asm $(ASM); $(ASM) $< 22 | %.dat: inputs/%.dat; cp $< $@ 23 | 24 | colors: colors.smc; snes9x colors.smc 25 | c: c.smc 26 | cp *.smc /home/ben/tmp/hydra-parker/www-home/hacking 27 | snes9x c.smc 28 | -------------------------------------------------------------------------------- /cs400.master/util/cc/asm.lisp: -------------------------------------------------------------------------------- 1 | "This is the code that actually creates the textual asm output. " 2 | 3 | (in-package #:cs400-compiler) 4 | 5 | (defparameter +addressing-modes-and-syntax+ 6 | '((:implied "") 7 | (:accumulator "A") 8 | (:immediate "#b") 9 | (:immediate-w "#w") 10 | #| TODO What are the other kinds of 'immediate's? |# 11 | (:direct "b") 12 | (:direct-x-indexed "b,X") 13 | (:direct-y-indexed "b,Y") 14 | (:stack-indexed "b,S") 15 | (:direct-indirect "(b)") 16 | (:direct-indirect-long "[b]") 17 | (:direct-x-indexed-indirect "(b,X)") 18 | (:direct-indirect-y-indexed "(b),Y") 19 | (:direct-indirect-long-y-indexed "[b],Y") 20 | (:stack-relative-indirect-y-indexed "(b,S),Y") 21 | (:block-move "b,b") 22 | (:absolute "w") 23 | (:absolute-x-indexed "w,X") 24 | (:absolute-y-indexed "w,Y") 25 | (:absolute-indirect "(w)") 26 | (:absolute-indirect-long "[w]") 27 | (:absolute-x-indexed-indirect "(w,X)") 28 | (:long "l") 29 | (:long-x-indexed "l,X"))) 30 | 31 | (defvar *emit-indentation* 0) 32 | 33 | (defun indent-chars () 34 | (collecting 35 | (dotimes (i (* 4 *emit-indentation*)) 36 | (collect #\space)))) 37 | 38 | (defun emit (string) 39 | (format t "~{~a~}; ~a~%" (indent-chars) string) 40 | (values)) 41 | 42 | (defmacro with-indent (name &body code) 43 | `(let ((*emit-indentation* (1+ *emit-indentation*))) 44 | (format t "~{~a~}~a~%" (rest (indent-chars)) ',name) 45 | ,@code)) 46 | 47 | (defun asm-subformat (format-char argument) 48 | (etypecase argument 49 | (symbol (symbol-name argument)) 50 | (number (format nil (ecase format-char 51 | (#\b "$~2,'0xb") 52 | (#\w "$~4,'0xw") 53 | (#\l "$~6,'0xl")) 54 | argument)))) 55 | 56 | (defun asm-format (format-string &rest arguments) 57 | "Take an asm form from +addressing-modes-and-syntax+ and some arguements, 58 | returning the corresponding asm syntax. " 59 | (coerce (flatten 60 | (loop for char across format-string 61 | collect (if (find char '(#\b #\w #\l)) 62 | (coerce (asm-subformat char (pop arguments)) 'list) 63 | (list char)))) 64 | 'string)) 65 | 66 | (defmacro asm (command mode &rest args) 67 | `(emit (format nil "~a ~a" 68 | ,(symbol-name command) 69 | (asm-format 70 | (car (elookup ,mode +addressing-modes-and-syntax+)) 71 | ,@args)))) 72 | 73 | 74 | "# Code Generation Routines" 75 | (defun %label (name) (emit (format nil "{~a}" name))) 76 | (defun %goto (label-name) (emit (format nil "BRA {~a}" label-name))) 77 | (defun %branch-if-not (label-name) 78 | (emit (format nil "BEQ {~a}" label-name))) 79 | 80 | (defun asm-code (symbol &key (prototype nil)) 81 | (emit 82 | (format nil (if prototype "#Code w ~a" "#Code w {~a}") 83 | (symbol-name symbol)))) 84 | 85 | (defmacro 16-bit-mode () `(asm rep :immediate #x30)) 86 | (defmacro 8-bit-mode () `(asm sep :immediate #x30)) 87 | (defun lda (integer) 88 | (declare (type integer integer)) 89 | (asm lda :immediate-w integer)) 90 | 91 | (defmacro write-w (addr value) 92 | `(progn (asm lda :immediate-w ,value) 93 | (asm sta :direct ,addr))) 94 | 95 | (defun set-reset-handler (value) 96 | (emit (format nil 97 | "#Data $00:FFFC _reset_handler {~a $0000}" 98 | value))) 99 | -------------------------------------------------------------------------------- /cs400.master/util/cc/c.lisp: -------------------------------------------------------------------------------- 1 | " 2 | # Syntax Analysis 3 | 4 | This exposes all the user-visible macros as thin macros over compiler 5 | primitives. 6 | 7 | The purpose of these macros is to handle funky syntax and to make the 8 | job of later transformations eaiser. The following rules apply to 9 | code in this file: 10 | 11 | 1. No macro may perform non-trivial transformations. 12 | 2. No knowledge of the target architecture is allowed. 13 | 3. (Possibly) only target macros defined in :CL and :IR. 14 | 15 | Here are the transformations that we do: 16 | 17 | - Tag expressions with (expr expr) 18 | - Expand Control Structures 19 | " 20 | 21 | (in-package #:cs400-compiler) 22 | 23 | (defmacro with-break (break-label &body code) 24 | `(with-goto-macrolet c::break ,break-label ,@code)) 25 | 26 | (defmacro with-continue (continue-label &body code) 27 | `(with-goto-macrolet c::continue ,continue-label ,@code)) 28 | 29 | 30 | (defmacro c::goto (label) `(c-goto ,label)) 31 | (defmacro c::label (name) `(c-label ,name)) 32 | (defmacro c::proto (name) `(c-proto ,name)) 33 | (defmacro c::proc ((name return-type) args &body code) 34 | (declare (symbol return-type name) (list args)) 35 | `(c-proc (,name ,return-type) ,args ,@code)) 36 | 37 | (defmacro c::var (name type &optional value) 38 | (declare (symbol name type)) 39 | (if value 40 | `(c-var ,name ,type ,value) 41 | `(c-var ,name ,type))) 42 | 43 | (defmacro c::block (&body code) `(c-block ,@code)) 44 | 45 | (defmacro c::if (test then-form &optional else-form) 46 | (with-gensyms ((else "if_else_") (end "if_end_")) 47 | `(with-indent "_if" 48 | ,test 49 | (c-goto- ,(if else-form else end)) 50 | (with-indent "_if_then" ,then-form) 51 | ,(when else-form `(c::goto ,end)) 52 | ,(when else-form `(c::label ,else)) 53 | (with-indent "_if_else" ,else-form) 54 | (c::label ,end)))) 55 | 56 | (defmacro c::while (test &body body) 57 | (with-gensyms ((top "while_label_top") (end "while_label_end")) 58 | `(with-break ,end 59 | (with-continue ,top 60 | (with-indent "_while" 61 | (c::label ,top) 62 | (c::if ,test 63 | (with-indent "_while_body" 64 | ,@body 65 | (c::goto ,top))) 66 | (c::label ,end)))))) 67 | 68 | (defmacro c::do-while (test &body body) 69 | (with-gensyms ((top "dowhile_label_repeat") 70 | (end "dowhile_label_end")) 71 | `(with-break ,end 72 | (with-continue ,top 73 | (with-indent "_do_while" 74 | (c::label ,top) 75 | (with-indent "_do_while_body" 76 | ,@body) 77 | (c::if ,test (c::goto ,top)) 78 | (c::label ,end)))))) 79 | 80 | (defmacro c::for ((setup test iterate) &body body) 81 | `(with-indent _for 82 | ,setup 83 | (c::while ,test 84 | ,@body 85 | ,iterate))) 86 | 87 | "## Switches" 88 | (always-eval 89 | (defun gen-switch-label (value) 90 | (match value 91 | ((type fixnum) (gensym (format nil "CASE_~a_" value))) 92 | ('c::default (nice-gensym value)) 93 | (_ (error "case ~s is not a number" value)))) 94 | 95 | (defun switch-case-values (cases) (mapcar #'first cases)) 96 | (defun switch-case-codes (cases) (mapcar #'rest cases)) 97 | 98 | (defun make-switch-target (target code) 99 | `(progn (c::label ,target) 100 | ,@code)) 101 | 102 | (defun switch-default-hack (jumps break-label) 103 | "The 'default' case must be 'goto'ed at the end of jump clauses, 104 | but it isn't required to be placed at the end of the switch. So, 105 | we look for the generated default clause (which looks like '(goto 106 | DEFAULT####)') and move it to the end. " 107 | (multiple-value-bind (defaults numbers) 108 | (lpartition (lambda (jump-form) 109 | (eq 'c::default (second jump-form))) 110 | jumps) 111 | (append numbers (or defaults 112 | `((c::goto ,break-label))))))) 113 | 114 | (defmacro switch-jump-entry (value target) 115 | (declare (type (or number (eql c::default)) value) 116 | (symbol target)) 117 | (case value 118 | (c::default `(c::goto ,target)) 119 | (t `(%switch-jump-entry ,value ',target)))) 120 | 121 | (defmacro c::switch (expr &body cases) 122 | "The output is 123 | - Each test in the order given a single test is of the form: 124 | (CMP num BEQ case_label) 125 | - The default test (BRA default_label) 126 | - each label (in the order given) and it's code" 127 | (with-gensyms (switch_end) 128 | (let* ((values (switch-case-values cases)) 129 | (codes (switch-case-codes cases)) 130 | (labels (mapcar #'gen-switch-label values))) 131 | `(with-indent _switch 132 | (with-break ,switch_end 133 | ,expr 134 | (with-indent _switch_tests 135 | ,@(switch-default-hack 136 | (mapcar (fn (v l) `(switch-jump-entry ,v ,l)) 137 | values labels) 138 | switch_end)) 139 | (with-indent _switch_targets 140 | ,@(mapcar #'make-switch-target labels codes)) 141 | (c::label ,switch_end)))))) 142 | 143 | ; '(c::+ c::- c::^ c::& c::band c::\| c::bor c::_ c::++ c::-- c::@ c::$) 144 | -------------------------------------------------------------------------------- /cs400.master/util/cc/compiler.lisp: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sbcl --script 2 | 3 | " 4 | A unix interface to the c compiler. 5 | 6 | If you want to dump a core image, define *script?* to nil before 7 | loading this file. Otherwise we simply run the c-compiler as script. 8 | " 9 | 10 | (defvar *script?* t) 11 | 12 | (let ((*standard-output* *error-output*)) 13 | (require :cs400-compiler)) 14 | 15 | (in-package :cs400-compiler) 16 | 17 | (defun main (args) 18 | (declare (ignore args)) 19 | (repl) 20 | (cl:in-package :cs400-compiler) 21 | 0) 22 | 23 | (defun top () 24 | (in-package :cs400-compiler) 25 | (sb-ext:quit 26 | :unix-status 27 | (handler-case (apply #'main sb-ext:*posix-argv*) 28 | (error (e) 29 | (format *error-output* "Fatal Error:~% ~a~%" e) 30 | 2) 31 | (t (s) 32 | (declare (ignore s)) 33 | 1)))) 34 | 35 | (if cl-user::*script?* 36 | (top) 37 | (sb-ext:save-lisp-and-die "compiler" 38 | :executable t 39 | :toplevel #'top 40 | :purify t)) 41 | -------------------------------------------------------------------------------- /cs400.master/util/cc/cs400-compiler.asd: -------------------------------------------------------------------------------- 1 | (asdf:defsystem #:cs400-compiler 2 | :depends-on (:iterate :cl-match :split-sequence) 3 | :components ((:file "package") 4 | (:file "lib") 5 | (:file "macroexpand-dammit") 6 | (:file "c-analize") 7 | (:file "asm") 8 | (:file "c-impl") 9 | (:file "c")) 10 | :serial t) 11 | -------------------------------------------------------------------------------- /cs400.master/util/cc/inputs/asm: -------------------------------------------------------------------------------- 1 | (asm lda :absolute 3) 2 | (asm clc :implied) 3 | (asm adc :direct 4) 4 | (asm adc :immediate 4) 5 | -------------------------------------------------------------------------------- /cs400.master/util/cc/inputs/c: -------------------------------------------------------------------------------- 1 | (cl:defmacro c::++ (x) `(c-++ ,x)) 2 | (cl:defmacro c::8-bit-mode () `(s::8-bit-mode)) 3 | (cl:defmacro c::16-bit-mode () `(s::16-bit-mode)) 4 | (cl:in-package :c) 5 | 6 | [#LoROM] 7 | [#Data l Zero] 8 | [#Data w pong_char] 9 | [#Data w pong_frame] 10 | [#Data w pong_pallet] 11 | [#File reset.asm] 12 | 13 | (proto set_background_color) 14 | 15 | (proc (cg_dma int) (status b-bus a-bank a-bus cg-addr num-bytes) 16 | (8-bit-mode) 17 | cg-addr 18 | [STA CGADD] 19 | status 20 | [STA DMAP] ;; DMA Status 21 | b-bus 22 | [STA DMAB] 23 | a-bank 24 | [STA DMAA.b] 25 | (16-bit-mode) 26 | a-bus 27 | [STA DMAA] 28 | num-bytes 29 | [STA DMAD] 30 | (8-bit-mode) 31 | [LDA #$01] 32 | [STA MDMAEN] 33 | (16-bit-mode)) 34 | 35 | (proc (vm_dma int) (status b-bus a-bank a-bus vm-addr num-bytes) 36 | vm-addr 37 | [STA VMADD] 38 | (8-bit-mode) 39 | status 40 | [STA DMAP] ;; DMA Status 41 | b-bus 42 | [STA DMAB] 43 | a-bank 44 | [STA DMAA.b] 45 | (16-bit-mode) 46 | a-bus 47 | [STA DMAA] 48 | num-bytes 49 | [STA DMAD] 50 | (8-bit-mode) 51 | [LDA #$01] 52 | [STA MDMAEN] 53 | (16-bit-mode)) 54 | 55 | (proc (main int) () 56 | (var hack int) 57 | [LDA #pong_pallet] 58 | (s::A-> hack) 59 | (cg_dma #x0002 #x0022 #x0000 hack #x0000 #x0200) 60 | [LDA #pong_char] 61 | (s::A-> hack) 62 | (vm_dma #x0001 #x0018 #x0000 hack #x0000 #x0800) 63 | [LDA #pong_frame] 64 | (s::A-> hack) 65 | (vm_dma #x0001 #x0018 #x0000 hack #x0400 #x0800) 66 | 67 | (8-bit-mode) 68 | "Set screen to max brightness" 69 | [LDA #$0F] 70 | [STA INIDISP] 71 | "Graphics Mode 1" 72 | [LDA #$01] 73 | [STA BGMODE] 74 | "" 75 | [LDA #$04] 76 | [STA BG1SC] 77 | [LDA #$00] 78 | [STA BG12NBA] 79 | [LDA #$01] 80 | [STA TM] 81 | (16-bit-mode) 82 | 83 | (var color int 0) 84 | (while 1 85 | "Get input from the controller" 86 | (s::asm s::lda :absolute #x4218) 87 | (if (s::asm s::and :immediate-w #x0100) ;; is right button depressed? 88 | (++ color) 89 | color) 90 | (set_background_color color #x0000) 91 | )) 92 | 93 | 94 | (proc (set_background_color void) (color color_address) 95 | color_address 96 | (8-bit-mode) 97 | (s::asm s::sta :absolute #x2121) 98 | (16-bit-mode) 99 | 100 | color 101 | (8-bit-mode) 102 | (s::asm s::sta :absolute #x2122) 103 | (s::asm s::xba :implied) 104 | (s::asm s::sta :absolute #x2122) 105 | (16-bit-mode)) 106 | 107 | (cl:in-package :s) 108 | 109 | (interrupt-handler :reset 110 | [SEI] 111 | [CLC] 112 | [XCE] 113 | [REP #$38] 114 | [PHK] 115 | [LDA #$0000] 116 | [TCD] 117 | [LDX #$1FFF] 118 | [TXS] 119 | [LDA #$0000] [TAX] [TAY] 120 | [JSR Reset.Registers] 121 | [JSR Reset.VRAM] 122 | [JSR Reset.OAM] 123 | [JSR Reset.CGRAM] 124 | (c-funcall c::main)) 125 | 126 | [#Data l Zero {$0000}] 127 | [#Data w pong_char {#pongChar.dat}] 128 | [#Data w pong_frame {#pongFrame.dat}] 129 | [#Data w pong_pallet {#pongPallet.dat}] 130 | 131 | (vector-table) 132 | -------------------------------------------------------------------------------- /cs400.master/util/cc/inputs/colors.asm: -------------------------------------------------------------------------------- 1 | ; #LoROM 2 | ; #Code w main 3 | ; CLC 4 | ; XCE 5 | ; SEP #$30b 6 | ; {yay704} 7 | ; LDA #$0Fb 8 | ; STA $2100w 9 | ; LDA #$00b 10 | ; STA $2121w 11 | ; REP #$30b 12 | ; INC $0000 13 | ; LDA $0000 14 | ; SEP #$30b 15 | ; STA $2122w 16 | ; XBA 17 | ; STA $2122w 18 | ; BRA {yay704} 19 | ; RTS 20 | ; #Data $00:FFFC {$8000 $0000} 21 | -------------------------------------------------------------------------------- /cs400.master/util/cc/inputs/pongChar.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.master/util/cc/inputs/pongChar.dat -------------------------------------------------------------------------------- /cs400.master/util/cc/inputs/pongFrame.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.master/util/cc/inputs/pongFrame.dat -------------------------------------------------------------------------------- /cs400.master/util/cc/inputs/pongPallet.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.master/util/cc/inputs/pongPallet.dat -------------------------------------------------------------------------------- /cs400.master/util/cc/inputs/reset.asm: -------------------------------------------------------------------------------- 1 | ; #File snes_registers.h 2 | 3 | ; #Code l {Immediate_DMA} 4 | ; PHP 5 | ; PHB 6 | ; SEP #$20 7 | ; LDA $05,S 8 | ; PHA 9 | ; PLB 10 | ; REP #$20 11 | ; LDA $03,S 12 | ; INC A 13 | ; TAX 14 | ; LDA $0000,X 15 | ; STA DMAP 16 | ; LDA $0002,X 17 | ; STA DMAA.l 18 | ; LDA $0004,X 19 | ; STA DMAA.b 20 | ; SEP #$20 21 | ; LDA $0006,X 22 | ; STA DMAD.h 23 | ; LDA #$01 24 | ; STA MDMAEN 25 | ; REP #$20 26 | ; TXA 27 | ; CLC 28 | ; ADC #$0006 29 | ; STA $03,S 30 | ; PLB 31 | ; PLP 32 | ; RTL 33 | 34 | ; #Code w {Reset.Registers} 35 | ; PHP 36 | ; SEP #$20 37 | ; LDA #$00 38 | ; STA MEMSEL 39 | ; LDA #$80 40 | ; STA INIDISP 41 | ; STZ OBJSEL 42 | ; STZ OAMADD.l 43 | ; STZ OAMADD.h 44 | ; STZ BGMODE 45 | ; STZ MOSAIC 46 | ; STZ BG1SC 47 | ; STZ BG2SC 48 | ; STZ BG3SC 49 | ; STZ BG4SC 50 | ; STZ BG12NBA 51 | ; STZ BG34NBA 52 | ; STZ BG1HOFS 53 | ; STZ BG1HOFS 54 | ; STZ BG1VOFS 55 | ; STZ BG1VOFS 56 | ; STZ BG2HOFS 57 | ; STZ BG2HOFS 58 | ; STZ BG2VOFS 59 | ; STZ BG2VOFS 60 | ; STZ BG3HOFS 61 | ; STZ BG3HOFS 62 | ; STZ BG3VOFS 63 | ; STZ BG3VOFS 64 | ; STZ BG4HOFS 65 | ; STZ BG4HOFS 66 | ; STZ BG4VOFS 67 | ; STZ BG4VOFS 68 | ; STZ VMAINC 69 | ; STZ VMADD.l 70 | ; STZ VMADD.h 71 | ; STZ M7SEL 72 | ; STZ M7A 73 | ; STZ M7A 74 | ; STZ M7B 75 | ; STZ M7B 76 | ; STZ M7C 77 | ; STZ M7C 78 | ; STZ M7D 79 | ; STZ M7D 80 | ; STZ M7X 81 | ; STZ M7X 82 | ; STZ M7Y 83 | ; STZ M7Y 84 | ; STZ CGADD 85 | ; STZ W12SEL 86 | ; STZ W34SEL 87 | ; STZ WOBJSEL 88 | ; STZ WH0 89 | ; STZ WH1 90 | ; STZ WH2 91 | ; STZ WH3 92 | ; STZ WBGLOG 93 | ; STZ WOBJLOG 94 | ; STZ TM 95 | ; STZ TS 96 | ; STZ TMW_ 97 | ; STZ TSW_ 98 | ; STZ CGSWSEL 99 | ; STZ CGADSUB 100 | ; STZ COLDATA 101 | ; STZ SETINI 102 | ; LDA STAT78 103 | ; STZ WMADD.l 104 | ; STZ WMADD.h 105 | ; STZ WMADD.b 106 | ; STZ NMITIMEN 107 | ; STZ WRIO 108 | ; STZ WRMPYA 109 | ; STZ WRMPYB 110 | ; STZ WRDIVA.l 111 | ; STZ WRDIVA.h 112 | ; STZ WRDIVB 113 | ; STZ HTIME.l 114 | ; STZ HTIME.h 115 | ; STZ VTIME.l 116 | ; STZ VTIME.h 117 | ; STZ MDMAEN 118 | ; STZ HDMAEN 119 | ; LDA RDNMI 120 | ; LDA TIMEUP 121 | ; PLP 122 | ; RTS 123 | 124 | ; #Code w {Reset.VRAM} 125 | ; PHP 126 | ; SEP #$20 127 | ; LDA #$80 128 | ; STA VMAINC 129 | ; REP #$20 130 | ; STZ VMADD 131 | ; JSL Immediate_DMA 132 | ; #Data {$09 $18 Zero $0000} 133 | ; PLP 134 | ; RTS 135 | 136 | ; #Code w {Reset.OAM} 137 | ; PHP 138 | ; REP #$20 139 | ; STZ OAMADD 140 | ; JSL Immediate_DMA 141 | ; #Data {$0A $04 Zero $0220} 142 | ; PLP 143 | ; RTS 144 | 145 | ; #Code w {Reset.CGRAM} 146 | ; PHP 147 | ; SEP #$20 148 | ; STZ CGADD 149 | ; JSL Immediate_DMA 150 | ; #Data {$0A $22 Zero $0200} 151 | ; PLP 152 | ; RTS 153 | 154 | ; #Code w {Reset.APU} 155 | ; RTS 156 | -------------------------------------------------------------------------------- /cs400.master/util/cc/inputs/snes_registers.h: -------------------------------------------------------------------------------- 1 | ; # SNES Registers 2 | ; #Name $2100 INIDISP b 3 | ; #Name $2101 OBJSEL b 4 | ; #Name $2102 OAMADD w 5 | ; #Name $2104 OAMDATA b,LH 6 | ; #Name $2105 BGMODE b 7 | ; #Name $2106 MOSAIC b 8 | ; #Name $2107 BG1SC b 9 | ; #Name $2108 BG2SC b 10 | ; #Name $2109 BG3SC b 11 | ; #Name $210A BG4SC b 12 | ; #Name $210B BG12NBA b 13 | ; #Name $210C BG34NBA b 14 | ; #Name $210D BG1HOFS b,LH 15 | ; #Name $210E BG1VOFS b,LH 16 | ; #Name $210F BG2HOFS b,LH 17 | ; #Name $2110 BG2VOFS b,LH 18 | ; #Name $2111 BG3HOFS b,LH 19 | ; #Name $2112 BG3VOFS b,LH 20 | ; #Name $2113 BG4HOFS b,LH 21 | ; #Name $2114 BG4VOFS b,LH 22 | ; #Name $2115 VMAINC b 23 | ; #Name $2116 VMADD w 24 | ; #Name $2118 VMDATA w 25 | ; #Name $211A M7SEL b 26 | ; #Name $211B M7A b,LH 27 | ; #Name $211C M7B b,LH 28 | ; #Name $211D M7C b,LH 29 | ; #Name $211E M7D b,LH 30 | ; #Name $211F M7X b,LH 31 | ; #Name $2120 M7Y b,LH 32 | ; #Name $2121 CGADD b 33 | ; #Name $2122 CGDATA b,LH 34 | ; #Name $2123 W12SEL b 35 | ; #Name $2124 W34SEL b 36 | ; #Name $2125 WOBJSEL b 37 | ; #Name $2126 WH0 b 38 | ; #Name $2127 WH1 b 39 | ; #Name $2128 WH2 b 40 | ; #Name $2129 WH3 b 41 | ; #Name $212A WBGLOG b 42 | ; #Name $212B WOBJLOG b 43 | ; #Name $212C TM b 44 | ; #Name $212D TS b 45 | ; #Name $212E TMW_ b 46 | ; #Name $212F TSW_ b 47 | ; #Name $2130 CGSWSEL b 48 | ; #Name $2131 CGADSUB b 49 | ; #Name $2132 COLDATA b 50 | ; #Name $2133 SETINI b 51 | ; #Name $2134 RDMPY24 l,ro 52 | ; #Name $2137 SLHV b,ro 53 | ; #Name $2138 RDOAMDATA b,ro,LH 54 | ; #Name $2139 RDVMDATA w,ro 55 | ; #Name $213B RDCGDATA b,ro,LH 56 | ; #Name $213C OPHCT b,ro,LH 57 | ; #Name $213D OPVCT b,ro,LH 58 | ; #Name $213E STAT77 b,ro 59 | ; #Name $213F STAT78 b,ro 60 | ; #Name $2140 APUIO0 b 61 | ; #Name $2141 APUIO1 b 62 | ; #Name $2142 APUIO2 b 63 | ; #Name $2143 APUIO3 b 64 | ; #Name $2180 WMDATA b 65 | ; #Name $2181 WMADD l 66 | ; #Name $4016 JOYIO w 67 | ; #Name $4200 NMITIMEN b 68 | ; #Name $4201 WRIO b 69 | ; #Name $4202 WRMPYA b 70 | ; #Name $4203 WRMPYB b 71 | ; #Name $4204 WRDIVA w 72 | ; #Name $4206 WRDIVB b 73 | ; #Name $4207 HTIME w 74 | ; #Name $4209 VTIME w 75 | ; #Name $420B MDMAEN b 76 | ; #Name $420C HDMAEN b 77 | ; #Name $420D MEMSEL b 78 | ; #Name $4210 RDNMI b,ro 79 | ; #Name $4211 TIMEUP b,ro 80 | ; #Name $4212 HVBJOY b,ro 81 | ; #Name $4213 RDIO b,ro 82 | ; #Name $4214 RDDIV w,ro 83 | ; #Name $4216 RDMPY16 w,ro 84 | ; #Name $4218 JOY1 w 85 | ; #Name $421A JOY2 w 86 | ; #Name $421C JOY3 w 87 | ; #Name $421E JOY4 w 88 | ; #Name $4300 DMAP b 89 | ; #Name $4301 DMAB b 90 | ; #Name $4302 DMAA l 91 | ; #Name $4305 DMAD l 92 | ; #Name $4308 DMAI w 93 | ; #Name $430A DMAL b 94 | ; #Name $4300 DMAP0 b 95 | ; #Name $4301 DMAB0 b 96 | ; #Name $4302 DMAA0 l 97 | ; #Name $4305 DMAD0 l 98 | ; #Name $4308 DMAI0 w 99 | ; #Name $430A DMAL0 b 100 | ; #Name $4310 DMAP1 b 101 | ; #Name $4311 DMAB1 b 102 | ; #Name $4312 DMAA1 l 103 | ; #Name $4315 DMAD1 l 104 | ; #Name $4318 DMAI1 w 105 | ; #Name $431A DMAL1 b 106 | ; #Name $4320 DMAP2 b 107 | ; #Name $4321 DMAB2 b 108 | ; #Name $4322 DMAA2 l 109 | ; #Name $4325 DMAD2 l 110 | ; #Name $4328 DMAI2 w 111 | ; #Name $432A DMAL2 b 112 | ; #Name $4330 DMAP3 b 113 | ; #Name $4331 DMAB3 b 114 | ; #Name $4332 DMAA3 l 115 | ; #Name $4335 DMAD3 l 116 | ; #Name $4338 DMAI3 w 117 | ; #Name $433A DMAL3 b 118 | ; #Name $4340 DMAP4 b 119 | ; #Name $4341 DMAB4 b 120 | ; #Name $4342 DMAA4 l 121 | ; #Name $4345 DMAD4 l 122 | ; #Name $4348 DMAI4 w 123 | ; #Name $434A DMAL4 b 124 | ; #Name $4350 DMAP5 b 125 | ; #Name $4351 DMAB5 b 126 | ; #Name $4352 DMAA5 l 127 | ; #Name $4355 DMAD5 l 128 | ; #Name $4358 DMAI5 w 129 | ; #Name $435A DMAL5 b 130 | ; #Name $4360 DMAP6 b 131 | ; #Name $4361 DMAB6 b 132 | ; #Name $4362 DMAA6 l 133 | ; #Name $4365 DMAD6 l 134 | ; #Name $4368 DMAI6 w 135 | ; #Name $436A DMAL6 b 136 | ; #Name $4370 DMAP7 b 137 | ; #Name $4371 DMAB7 b 138 | ; #Name $4372 DMAA7 l 139 | ; #Name $4375 DMAD7 l 140 | ; #Name $4378 DMAI7 w 141 | ; #Name $437A DMAL7 b 142 | -------------------------------------------------------------------------------- /cs400.master/util/cc/lib.lisp: -------------------------------------------------------------------------------- 1 | "Just some general utillity code. " 2 | 3 | (in-package #:cs400-compiler) 4 | 5 | (defun insult () (error "u is dumb")) 6 | (defun traceme (x) x) 7 | (defun flatten (lists) (apply #'append lists)) 8 | 9 | (defun filter (predicate seq) (remove-if-not predicate seq)) 10 | (defun in-table? (key table) 11 | (multiple-value-bind (value found?) (gethash key table) 12 | (declare (ignore value)) 13 | found?)) 14 | 15 | (defun hash-table->alist (table) 16 | (loop for key being the hash-keys of table 17 | collect (cons key (gethash key table)))) 18 | 19 | (defun alist-to-table (alist &optional (table (make-hash-table))) 20 | "Modifies table if one is passed; Otherwise return a new table with 21 | only the given mapping. " 22 | (loop for (key . value) in alist 23 | do (setf (gethash key table) value)) 24 | table) 25 | 26 | (defun non-unique-items (list) 27 | "Returns a list of all non-unique items" 28 | (let ((items (make-hash-table)) 29 | (duplicated-items)) 30 | (dolist (item list) 31 | (if (gethash item items) 32 | (setf duplicated-items (adjoin item duplicated-items)) 33 | (setf (gethash item items) t))) 34 | duplicated-items)) 35 | 36 | (defun proper-set? (list) (null (non-unique-items list))) 37 | 38 | 39 | ;; Macros 40 | (defmacro always-eval (&body code) 41 | "Wrap function definitions in this if the function is used by a 42 | macro definied in the same file. macros defined in the same 43 | file. " 44 | `(eval-when (:compile-toplevel :load-toplevel :execute) 45 | ,@code)) 46 | 47 | (defmacro aif (form then &optional else) 48 | `(let ((it ,form)) 49 | ,(if else 50 | `(if it ,then ,else) 51 | `(if it ,then)))) 52 | 53 | (defun alist->plist (alist) 54 | (loop for (key . value) in alist 55 | collect key 56 | collect value)) 57 | 58 | (defun hash-table->plist (table) 59 | (alist->plist (hash-table->alist table))) 60 | 61 | (defmethod print-object ((table hash-table) stream) 62 | (format stream "[dict~{ ~s~}]" (hash-table->plist table))) 63 | 64 | (defun lookup (key alist) 65 | (aif (assoc key alist) 66 | (values (cdr it) t))) 67 | 68 | (defun elookup (key alist) 69 | (multiple-value-bind (result found?) (lookup key alist) 70 | (if found? result 71 | (error "key '~a was not found in alist '~a. " key alist)))) 72 | 73 | (defmacro match (expr &body forms) 74 | `(cl-match:match ,expr ,@forms)) 75 | 76 | (defmacro match? (form value) 77 | `(match ,value (,form t))) 78 | 79 | (defmacro with-gensyms (symbols &body code) 80 | `(let ,(mapcar (lambda (form) 81 | (match form 82 | ((as symbol (type symbol)) 83 | `(,symbol (gensym (symbol-name ',symbol)))) 84 | ((list symbol gensym-hint) 85 | `(,symbol (gensym ,gensym-hint))))) 86 | symbols) 87 | ,@code)) 88 | 89 | (defmacro ematch (expr &body forms) 90 | (with-gensyms (tmp) 91 | `(let ((,tmp ,expr)) 92 | (or (match ,tmp ,@forms) 93 | (error "no match found for ~a in patterns ~a" ,tmp 94 | ',(mapcar #'first forms)))))) 95 | 96 | (defun & (f &rest l) (apply f l)) 97 | (defmacro fn (lambda-list &body body) `(lambda ,lambda-list ,@body)) 98 | (defmacro fn1 (&body body) `(fn (!1) ,@body)) 99 | 100 | (defun eprint (object) (print object *error-output*)) 101 | 102 | (defmacro collecting (&body code) 103 | (with-gensyms (result) 104 | `(let ((,result)) 105 | (flet ((collect (obj) (push obj ,result))) 106 | ,@code) 107 | (nreverse ,result)))) 108 | 109 | (defun nice-gensym (obj) 110 | (gensym (string-right-trim 111 | "0123456789" 112 | (format nil "~a" obj)))) 113 | 114 | (defmacro with-symbol-alias-alist (alist-varname symbols &body code) 115 | "Generates unique names for all SYMBOLS, and binds an alist 116 | (GIVEN-NAME . UNIQUE-NAME) to ALIST_VARNAME. " 117 | `(let ((,alist-varname ',(mapcar (fn1 (cons !1 (nice-gensym !1))) 118 | symbols))) 119 | ,@code)) 120 | 121 | (defun lpartition (predicate list) 122 | "Returns (values (remove-if-not predicate list) 123 | (remove-if predicate list)), but in a single 124 | pass. " 125 | (iter (for item in list) 126 | (if (funcall predicate item) 127 | (collect item into good-list) 128 | (collect item into bad-list)) 129 | (finally (return (values good-list bad-list))))) 130 | 131 | (defun listify (obj) 132 | (typecase obj (list obj) (t (list obj)))) 133 | 134 | (defmacro pluralize-macro (macro newname) 135 | (with-gensyms (forms) 136 | `(defmacro ,newname (&body ,forms) 137 | `(progn 138 | ,@(mapcar (fn1 (cons ',macro (listify !1))) ,forms))))) 139 | 140 | (defmacro define-constant (name value &optional doc) 141 | `(defconstant ,name (if (boundp ',name) (symbol-value ',name) ,value) 142 | ,@(when doc (list doc)))) 143 | -------------------------------------------------------------------------------- /cs400.master/util/cc/notes/c-examples.lisp: -------------------------------------------------------------------------------- 1 | " 2 | Here is a table of syntaxes for operators. I don't like some of the 3 | things I chose (like _ instead of |), so if you have some better ideas 4 | tell me. 5 | 6 | ========= ============ ================ 7 | C Sexp c More lispy 8 | ========= ============ ================ 9 | +a (+ a) (+ a) 10 | a + b (+ a b) (+ a b c ...) 11 | ++a (++* a) (preincr a) 12 | a++ (++ a) (incr a) 13 | a += b (+= a b) (incr a b) 14 | -a (- a) (- a) 15 | a - b (- a b) (- a b c) 16 | --a (--* a) (predecr a) 17 | a-- (-- a) (decr a) 18 | a -= b (-= a b) (decr a b) 19 | a * b (* a b) (* a b) 20 | a *= b (*= a b) (set * a b) 21 | a / b (/ a b) (/ a b) 22 | a /= b (/= a b) (set / a b) 23 | a % b (% a b) (mod a b) 24 | a %= b (%= a b) (set mod a b) 25 | a < b (< a b) (< a b ...) 26 | a <= b (<= a b) (<= a b ...) 27 | a > b (> a b) (> a b ...) 28 | a >= b (>= a b) (>= a b ...) 29 | a != b (!= a b) (!= a b ...) 30 | a == b (== a b) (== a b ...) 31 | !a (! a) (not a) 32 | a && b (&& a b) (and a b ...) 33 | a || b (or a b) (or a b ...) 34 | a << b (<< a b) (lshift a b) 35 | a <<= b (<<= a b) (set lshift a b) 36 | a >> b (>> a b) (rshift a b) 37 | a >>= b (>>= a b) (set rshift a b) 38 | ~a (~ a) (nnot a) 39 | a & b (& a b) (nand a b) 40 | a &= b (&= a b) (set nand a b) 41 | a | b (_ a b) (!or a b) 42 | a |= b (_= a b) (set !or a b) 43 | a ^ b (^ a b) (^ a b ...) 44 | a ^= b (^= a b) (set ^ a b ...) 45 | a = b (= a b) (set a b) 46 | a() (a) (a) 47 | a[b] ([] a b) (a b) 48 | *a (@ a) (a) 49 | &a (& a) (? a) 50 | a->b (-> a :b) (a :b) 51 | (type)a (type a) (type a) 52 | a , b (do a b) (do a b) 53 | a ? b : c (? a b c) (if a b c) 54 | sizeof a (sizeof a) (size a) 55 | ========= ============ ================ 56 | 57 | Some expressions: 58 | 59 | a.b.c[2] 60 | (a :b :c 2) 61 | ([] (@. (@. a :b) :c) 2) 62 | 63 | a->b.c[(x == 3) ? 1 : 2] + 3 + a->a 64 | (+ (a :b :c (if (== x 3) 1 2)) 3 (a :a)) 65 | (+ ([] (.@ (-> a :b) :c) (? f 1 2)) 3 (-> a a)) 66 | 67 | 68 | Some functions: 69 | 70 | C: 71 | 72 | char *strcpy(char *dest, const char *src) 73 | { 74 | char *save = dest; 75 | while (*dest++ = *src++); 76 | return save; 77 | } 78 | 79 | 80 | Sexp C: 81 | 82 | (defun strcpy (dest src) 83 | (type :*char (const :*char) -> :*char) 84 | (var save dest :*char) 85 | (while (== (@ (++ dest)) (@ (++ dest)))) 86 | (return save)) 87 | 88 | 89 | More lispy: 90 | 91 | (defun strcpy (dest src) 92 | (type :*char (const :*char) -> :*char) 93 | (let ((save dest)) 94 | (while (== ((++ dest)) ((++ src)))) 95 | save)) 96 | 97 | Another example 98 | 99 | void f (int n, char x[n]) 100 | { 101 | for (int i = 0; ii < n; ii++) { 102 | if (!(i % 3)) { 103 | x[i] = '\0' 104 | } 105 | } 106 | } 107 | 108 | (defun f (n x) 109 | (type :int (:char n)) 110 | (for ((var i 0 :int) (< ii n) (++ i)) 111 | (if (! (% i 3)) 112 | (= ([] x i) #\null)))) 113 | 114 | (defun f (n x) 115 | (type int (char n)) 116 | (iter (for i below n) 117 | (if (divisible i 3) 118 | (set (x i) #\null)))) 119 | " 120 | -------------------------------------------------------------------------------- /cs400.master/util/cc/notes/c.c: -------------------------------------------------------------------------------- 1 | // despite the '.c' extensions, this file is just documentaion. It 2 | // explores the different namespaces of c and how various issues are 3 | // handled. 4 | 5 | // TODO This is not handled the same in tcc. Read the c standard and 6 | // see what is actuall the correct behavior. 7 | 8 | // Namespaces: 9 | // 1. Tagged types: 10 | // 11 | // 'struct c', 'enum c', and 'union c' are all in the same 12 | // namespace, but not the same namespaces as straight-up types like 13 | // 'int'. 14 | // 15 | // These are lexically scoped, there is a global scope, and every 16 | // block introduces a new scope. 17 | // 18 | // 2. Labels 19 | // 20 | // Lables use the functions scope. There is no scope nesting of 21 | // labels. There are no global lables, and 22 | // functions-definined-in-functions have their own, 23 | // completely-separate labels scope. 24 | // 25 | // 3. Everything else: 26 | // 27 | // - Types 28 | // - Variables 29 | // - Functions 30 | // 31 | // These are lexically scoped, there is a global scope, and every 32 | // block introduces a new scope. 33 | // 34 | // 4. Every Struct/union has it's own namespace within it. 35 | // 36 | // Aside from that 37 | 38 | struct f { int a; }; 39 | 40 | typedef int c; 41 | 42 | c see() { 43 | c c; 44 | switch ('a') { 45 | case 'a': break; 46 | default: return; } 47 | c: 48 | return c + c; } 49 | 50 | c main(void) { 51 | c cee(); 52 | c: 53 | return cee(); } 54 | 55 | c cee() { 56 | c C; 57 | typedef struct c { c c; } c; 58 | // int c; // This conflicts with the typedef above 59 | // typedef union c { c c; } see; // This conflicts with 'struct c' 60 | c: 61 | { c c; 62 | //c d; // Not cool. Using c as a type was fine above but not here 63 | // since the variable c hides it. 64 | if (!c.c) return 0; 65 | typedef struct c { int c; } C; 66 | // c: // Not cool. Label scopes don't nest 67 | C sea; 68 | struct c see() { 69 | c: // Nested functions have their own label scopes (although they 70 | // are not standard c). However, you can't goto labels in the 71 | // enclosing lexical scope. 72 | goto c; 73 | sea; }} 74 | c sea; 75 | return C; 76 | return see(sea.c); } 77 | -------------------------------------------------------------------------------- /cs400.master/util/cc/notes/compilation-examples: -------------------------------------------------------------------------------- 1 | # Code Generation Examples 2 | ## (+ 3 4) 3 | 4 | ; LDA #3b 5 | ; CLC 6 | ; ADC #4b 7 | 8 | ## (+ x y) 9 | In the caller: 10 | 11 | ; LDA x Push x 12 | ; PHA 13 | ; LDA y Push y 14 | ; PHA 15 | ; TSC Make room for 1 byte of return space 16 | ; CLC 17 | ; ADC #1b 18 | ; TCS 19 | ; JSL whatever 20 | ; LDA 1,S Return value 21 | ; TSC Clean up the stack 22 | ; SEC 23 | ; SBC #3 24 | ; TCS 25 | 26 | 27 | In the callee: 28 | 29 | ; LDA 5,S First argument 30 | ; CLC 31 | ; ADC 4,S Second argument 32 | ; STA 3,S Return value 33 | ; RTS 34 | 35 | 36 | # Simple Code Example 37 | 38 | (var n char 0) 39 | 40 | (defun foo ((char x) (char y) -> char) 41 | (var z char 3) 42 | (return (+ x y z))) 43 | 44 | (defun main () 45 | (label loop) 46 | (if (!= n 10) 47 | (block (++ n) 48 | (goto loop)) 49 | (block (-- n))) 50 | (= n (foo 3 n))) 51 | 52 | Expands into... 53 | 54 | (defvar *type-sizes* '(char 1)) 55 | (defvar *globals* (make-hash-table)) 56 | 57 | (setf (gethash *globals* 'n) '(char)) 58 | 59 | 60 | (setf (gethash *functions* foo) 61 | '(progn (asm lda :immediate 3) 62 | (asm pha :implied) 63 | (asm clc :implied) 64 | (asm lda :stack-relative 1) 65 | (asm adc :stack-relative 4) 66 | (asm adc :stack-relative 5) 67 | (asm plx :implied) 68 | (asm rts :implied))) 69 | 70 | (setf (gethash *functions* main) 71 | '(progn (asm label loop) 72 | (asm lda :direct (global n)) 73 | (asm cmp :immediate 10) 74 | (asm beq :label else) 75 | (asm inc :direct (global n)) 76 | (asm bra :label loop) 77 | (asm bra :label end) 78 | (asm label else) 79 | (asm dec :direct (global n)) 80 | (asm label end) 81 | (asm lda :immediate 3) 82 | (asm pha :implied) 83 | (asm lda :direct (global n)) 84 | (asm pha :implied) 85 | (asm jsr :absolute (function foo)) 86 | (asm sta :direct (global _temp1)) 87 | (asm tsc :implied) 88 | (asm clc :implied) 89 | (asm adc :immediate 2) 90 | (asm tcs :implied) 91 | (asm lda :direct (global _temp1)) 92 | (asm sta :direct (global n)))) 93 | -------------------------------------------------------------------------------- /cs400.master/util/cc/notes/oo: -------------------------------------------------------------------------------- 1 | # OO 2 | 3 | Some ideas for a light Object system on top of c. 4 | 5 | # Inheritance 6 | 7 | Instead of inheritence, we simply support struct includes: 8 | 9 | struct a { int one, two; } 10 | struct b { struct a; int three; } 11 | struct b b; 12 | return b.one; 13 | 14 | Note that including any struct more than once is impossible since the 15 | namespace would have conflicts. This lets us have simple method 16 | dispatch. 17 | 18 | # Methods 19 | 20 | Methods are definied externally to a struct. Method dispatch is done 21 | at compile time, and doesn't change the meaning of structs in any way. 22 | Methods are simply dispatched to the closest possible match, where 23 | includes mentioned earlier in a struct are considered closer matches. 24 | 25 | (generic + (a b -> c)) 26 | (method + ((a struct-a) (b struct-a) -> int) 27 | (return 4)) 28 | (method + ((a struct-b) (b struct-b) -> int) 29 | (return 5)) 30 | (var (a b) struct-a) 31 | (var (c d) struct-b) 32 | (+ a b) ;; => 4 33 | (+ c d) ;; => 5 34 | (+ a c) ;; => 4 35 | 36 | Here is some conceivable resulting c code: 37 | 38 | struct a { int one, two; } 39 | struct b { struct a __a; int three; } // __a is an include. 40 | return b.one; 41 | 42 | int plus_struct_a (struct a a, struct a b) { 43 | return 4; } 44 | int plus_struct_b (struct b a, struct b b) { 45 | return 5; } 46 | struct a a, b; 47 | struct b c, d; 48 | plus_struct_a(a, b) 49 | plus_struct_b(c, d) 50 | plus_struct_a(a, c.__a) 51 | -------------------------------------------------------------------------------- /cs400.master/util/cc/package.lisp: -------------------------------------------------------------------------------- 1 | " 2 | This is just the package definition. It's really too small to 3 | justify having its own file, but I think it will grow. Eventualy we 4 | need to export symbols and stuff here. 5 | " 6 | 7 | (defpackage #:cs400-compiler 8 | (:use #:cl #:iterate #:cl-match #:split-sequence) 9 | (:shadow #:match) 10 | (:nicknames #:s)) 11 | 12 | (defpackage :c) 13 | 14 | (in-package #:cs400-compiler) 15 | (setf (readtable-case *readtable*) :invert) 16 | 17 | (defconstant +asm-syntax-start+ #\[) 18 | (defconstant +asm-syntax-stop+ #\]) 19 | 20 | (defun parse-asm (stream depth chars) 21 | (if (zerop depth) 22 | (coerce (nreverse (cdr chars)) 'string) 23 | (let* ((c (read-char stream)) 24 | (depth (cond 25 | ((char= c +asm-syntax-start+) (1+ depth)) 26 | ((char= c +asm-syntax-stop+) (1- depth)) 27 | (t depth)))) 28 | (cons c depth) 29 | (parse-asm stream depth (cons c chars))))) 30 | 31 | (set-macro-character #\[ (lambda (s c) 32 | (declare (ignore c)) 33 | `(emit ,(parse-asm s 1 nil)))) 34 | -------------------------------------------------------------------------------- /cs400.master/util/data.rc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/rc 2 | 3 | cat <$target 13 | 14 | o.%: %.o 15 | c99 $prereq -o $target 16 | 17 | %.o: %.c data.h 18 | c99 $CFLAGS -c $stem.c 19 | -------------------------------------------------------------------------------- /cs400.master/util/modes: -------------------------------------------------------------------------------- 1 | IMP Implied 2 | A A Accumulator 3 | I # Immediate 4 | B b Direct 5 | BX b,X Direct X Indexed 6 | BY b,Y Direct Y Indexed 7 | BS b,S Stack Indexed 8 | BI (b) Direct Indirect 9 | BL [b] Direct Indirect Long 10 | BXI (b,X) Direct X Indexed Indirect 11 | BIY (b),Y Direct Indirect Y Indexed 12 | BLY [b],Y Direct Indirect Long Y Indexed 13 | BSIY (b,S),Y Stack Relative Indirect Y Indexed 14 | BM b,b Block Move 15 | W w Absolute 16 | WX w,X Absolute X Indexed 17 | WY w,Y Absolute Y Indexed 18 | WI (w) Absolute Indirect 19 | WL [w] Absolute Indirect Long 20 | WXI (w,X) Absolute X Indexed Indirect 21 | L l Long 22 | LX l,X Long X Indexed 23 | -------------------------------------------------------------------------------- /cs400.passes/AUTHORS: -------------------------------------------------------------------------------- 1 | bsummer4@eecs.utk.edu Benjamin Summers 2 | josborn8@eecs.utk.edu James Osborne 3 | sgray10@eecs.utk.edu Stephen Gray 4 | ktrofatt@utk.edu Kenneth Parker Trofatter 5 | -------------------------------------------------------------------------------- /cs400.passes/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | cd docs; make 3 | cd compiler; make 4 | cd assembler; make 5 | 6 | clean: 7 | cd docs; make clean 8 | cd compiler; make clean 9 | cd assembler; make clean 10 | -------------------------------------------------------------------------------- /cs400.passes/Project: -------------------------------------------------------------------------------- 1 | project "cs400" 2 | to build do make 3 | to clean do {make clean} 4 | -------------------------------------------------------------------------------- /cs400.passes/assembler/.gitignore: -------------------------------------------------------------------------------- 1 | 65816asm 2 | main.o 3 | pre 4 | pre.hi 5 | pre.o 6 | TAGS 7 | -------------------------------------------------------------------------------- /cs400.passes/assembler/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CFLAGS = -D__DEBUG__ -g3 -std=gnu99 -W -Wall -Werror -pedantic 3 | HSFLAGS = -O3 -package parsec 4 | 5 | all: 65816asm pre 6 | clean:; rm -f *.hi *.o 65816asm pre readme.html 7 | docs: readme.html 8 | 9 | 65816asm: main.o; $(CC) $(CFLAGS) $^ -o $@ 10 | pre: pre.hs; ghc $(HSFLAGS) $^ -o $@ 11 | main.o: main.c assembler.h data.h; $(CC) $(CFLAGS) -c $< 12 | readme.html: README; markdown < $^ > $@ 13 | test: pre; ./pre pretest 14 | -------------------------------------------------------------------------------- /cs400.passes/assembler/pretest: -------------------------------------------------------------------------------- 1 | asdlk#&{} ; ASM #$00 #tis s 2 | adfa asdfk ; ASM #$01 afa asldj asdf 3 | asdf asd fasdfj ; #Print 4 | asd 43 33 3 4 242 ; #File sfds 5 | ; #Data {$00 $80 Color_Data $0200} 6 | asdadfasdf ; ASM (x) adfadf ; YO 7 | ; ; ; ; 8 | ; #Data w Main_Program_PT 9 | ; {-} 10 | ; #LoROM 11 | ; # yo yo yo 12 | ; #Name endpretest 13 | -------------------------------------------------------------------------------- /cs400.passes/assembler/snes-memory-layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/assembler/snes-memory-layout.png -------------------------------------------------------------------------------- /cs400.passes/compiler/Makefile: -------------------------------------------------------------------------------- 1 | CC = ./compiler.lisp 2 | ASM = ../assembler/65816asm 3 | DAT = pongChar.dat pongFrame.dat pongPallet.dat 4 | LISP = asm.lisp back.lisp c-analize.lisp c-impl.lisp compiler.lisp 5 | LISP += far-back.lisp front.lisp lib.lisp macroexpand-dammit.lisp package.lisp 6 | LISP += state.lisp tag.lisp toplevel.lisp 7 | 8 | all: compiler; 9 | clean:; rm -f *.fasl *.asm *.smc *~ compiler reset.asm snes_registers.h *.dat 10 | install: compiler; ln -f compiler ~/bin/scc 11 | 12 | ../assembler/65816asm:; cd ../assembler; make 13 | compiler: $(LISP) Makefile 14 | sbcl --noinform \ 15 | --eval "(defvar *script?* nil)" \ 16 | --script "compiler.lisp" 17 | 18 | reset.asm:; cp -f inputs/reset.asm . 19 | snes_registers.h:; cp -f inputs/snes_registers.h . 20 | c.asm: inputs/c $(CC) reset.asm snes_registers.h $(DAT) 21 | $(CC) < $< > $@ 22 | colors.asm: inputs/colors.asm; cp $< $@ 23 | 24 | %.smc: %.asm $(ASM); $(ASM) $< 25 | %.dat: inputs/%.dat; cp $< $@ 26 | 27 | colors: colors.smc; snes9x colors.smc 28 | c: c.smc 29 | cp inputs/c c.asm c.smc /home/ben/tmp/hydra-parker/www-home/hacking 30 | snes9x c.smc 31 | -------------------------------------------------------------------------------- /cs400.passes/compiler/back.lisp: -------------------------------------------------------------------------------- 1 | " 2 | # Expression Flattening -- The Third Compiler Pass 3 | 4 | This pass simply expands out control structures. Maybe some more 5 | stuff... Who knows? 6 | 7 | TODO ++, -- need to be moved to the end of an expression 8 | " 9 | 10 | 11 | 12 | (in-package #:cs400-compiler) 13 | (defpackage :codegen) 14 | (define-constant +back-tags+ 15 | '((back::goto label) 16 | (back::label name) 17 | (back::global-variable-declaration) 18 | (back::global-variable-initialization) 19 | (back::local-variable-declaration) 20 | (back::local-variable-initialization) 21 | (back::expr expr))) 22 | 23 | (define-constant +back-operator-names+ 24 | (mapcar #'front->cs400-compiler +front-operator-names+)) 25 | 26 | "# Utillities" 27 | (require :memoize) 28 | (memoize:def-memoized-function temporary-variable (number) 29 | "Returns a gensymed symbol. Always returns the same symbol (EQ) 30 | given the same input. " 31 | (gensym (format nil "TEMP_~d-" number))) 32 | 33 | (defmacro spill (temp-var-num) 34 | (let ((var (temporary-variable temp-var-num))) 35 | `(progn 36 | (far-back::local-variable-declaration ,var c::int) 37 | (far-back::store-variable ,var)))) 38 | 39 | (defun primitive? (x) 40 | (typecase x (symbol t) (number t) 41 | (t (match x 42 | ((list 'temp (type number)) t))))) 43 | 44 | (defun all-primitive? (xs) 45 | (equalp xs (remove-if-not #'primitive? xs))) 46 | 47 | (defun compound-forms (xs) (remove-if #'primitive? xs)) 48 | 49 | (defun replace-compounds-with-temps (forms used-temps) 50 | (iter (for form in forms) 51 | (if (primitive? form) 52 | (collect form) 53 | (collect (temporary-variable (incf used-temps)))))) 54 | 55 | (defun transform-operator (operator args used-temps &key funcall?) 56 | (let ((nice-op-name (package-change operator :far-back))) 57 | (if (all-primitive? args) 58 | (if funcall? 59 | `(far-back::funcall ,operator ,@args) 60 | `(,nice-op-name ,@args)) 61 | `(progn 62 | ,@(let ((used-temps used-temps)) 63 | (iter (for form in (compound-forms args)) 64 | (collect `(expr ,form ,used-temps)) 65 | (collect `(spill ,(incf used-temps))))) 66 | (expr (,operator 67 | ,@(replace-compounds-with-temps 68 | args 69 | used-temps)) 70 | ,used-temps))))) 71 | 72 | (always-eval 73 | #.`(define-pass back 74 | ,@(mapcar #'list +back-tags+) 75 | ((back::proc name return-type args body) 76 | -> `(far-back::proc ,name ,return-type ,args 77 | ,(apply-pass (taggify-form body 78 | 'back) 79 | 'back))))) 80 | 81 | (defun back->far-back (symbol) 82 | (package-change symbol :far-back)) 83 | 84 | (define-predicated-transformation (back-passthrough 85 | #l(let ((first (first !1))) 86 | (and 87 | (symbolp first) 88 | (symbol-in-package? first :back))) 89 | back) 90 | (head &rest tail) 91 | "Any tagged forms we don't otherwise handle are simply passed off 92 | to the 'back pass. " 93 | `(,(back->far-back head) ,@tail)) 94 | 95 | (define-tag-substitution (expr back::expr back) 96 | (expr &optional (used-temps 0)) 97 | (fare-matcher:match expr 98 | ((of-type number) `(far-back::load-number ,expr)) 99 | ((of-type symbol) (when expr `(far-back::load-variable ,expr))) 100 | ((of-type string) `(far-back::comment ,expr)) 101 | ((list* (and operator 102 | (when (member operator +back-operator-names+))) 103 | args) 104 | (fare-matcher:match expr 105 | (`(++ ,x) 106 | (if (symbolp x) `(far-back::increment ,x) (wtf expr))) 107 | (`(-- ,x) 108 | (if (symbolp x) `(far-back::decrement ,x) (wtf expr))) 109 | (`(= ,x ,y) 110 | (if (symbolp x) 111 | `(progn 112 | (expr ,y ,used-temps) 113 | (far-back::store-variable ,x)) 114 | (error 115 | "We don't handle non-trivial left-hand-sides. So '~s is invalid. " 116 | expr))) 117 | (`(&& ,x ,y) 118 | (with-gensyms ((skip "and_skip")) 119 | `(progn 120 | (expr (goto-if-not ,x ,skip) ,used-temps) 121 | (expr ,y ,used-temps) 122 | (far-back::label ,skip)))) 123 | ;; TODO (`(|| ,x ,y) 124 | ;; TODO (`(and ,x ,y) 125 | ;; TODO (`(or ,x ,y) 126 | 127 | (`(< ,x ,y) 128 | (with-gensyms ((skip "compare_skip") (end "compare_end")) 129 | `(progn 130 | (expr (goto-if->= ,x ,y ,skip) ,used-temps) 131 | (expr 1) 132 | (far-back::goto ,end) 133 | (far-back::label ,skip) 134 | (expr 0) 135 | (far-back::label ,end)))) 136 | 137 | ;; TODO Other comparisons 138 | ;; TODO goto-if-not should be optimized here instead of in 139 | ;; c::front 140 | 141 | (* (transform-operator operator args used-temps)))) 142 | ((list* (and fn (of-type symbol)) args) 143 | (transform-operator fn args used-temps :funcall? t)) 144 | (x (wtf x)))) 145 | -------------------------------------------------------------------------------- /cs400.passes/compiler/c-analize.lisp: -------------------------------------------------------------------------------- 1 | " 2 | ## Code Analitics 3 | 4 | This has a bunch of functions for scanning a code body looking for 5 | certain forms. We need to be able to, for example, find all the 6 | labels or variable declarations in a function body. 7 | " 8 | 9 | (in-package :cs400-compiler) 10 | (defun preexpand (expr) 11 | (macroexpand-dammit:macroexpand-dammit expr)) 12 | 13 | (defun code-walk (function code) 14 | "Like calls FUNCTION on any non-special-from code fragments. 15 | Currently only these special forms are recognized: 16 | (LET FLET MACROLET IF PROGN)" 17 | ;; TODO Support all special forms 18 | (flet ((recur (code) (code-walk function code))) 19 | (match code 20 | ((list* 'let forms body) `(let ,forms 21 | ,@(mapcar #'recur body))) 22 | ((list* 'flet forms body) `(flet ,forms 23 | ,@(mapcar #'recur body))) 24 | ((list* 'macrolet forms body) `(macrolet ,forms 25 | ,@(mapcar #'recur body))) 26 | ((list 'if expr then) `(if ,expr ,(recur then))) 27 | ((list 'if expr then else) `(if ,expr 28 | ,(recur then) 29 | ,(recur else))) 30 | ((list* 'progn body) `(progn ,@(mapcar #'recur body))) 31 | ((as form *) (& function form))))) 32 | 33 | (defun tree-walk (function tree) 34 | (flet ((recur (code) (tree-walk function code))) 35 | (etypecase tree 36 | (list (funcall function (mapcar #'recur tree))) 37 | (t (& function tree))))) 38 | 39 | (defun find-forms (predicate code) 40 | (collecting 41 | (code-walk (fn1 (if (& predicate !1) 42 | (collect !1)) 43 | (values)) 44 | code))) 45 | 46 | (defun c-symbol? (symbol) 47 | (eq (symbol-package symbol) (find-package :c))) 48 | 49 | (defun call-space-request? (form) 50 | (match form 51 | ((list 'need-call-space (type number)) 52 | t))) 53 | 54 | (defun funcall-form? (expr) 55 | (match expr 56 | ((list* (as f (type symbol)) xs) 57 | (and (c-symbol? f) 58 | (not (fboundp f)))))) 59 | 60 | (defun var-ref-form? (expr) 61 | (match expr 62 | ((type symbol) (c-symbol? expr)))) 63 | 64 | (set-fn label-form? (match? (list 'c-label (type symbol)))) 65 | 66 | (defun var-form? (expr) 67 | (match expr 68 | ((list 'c-var (type symbol) (type symbol)) t) 69 | ((list 'c-var (type symbol) (type symbol) (type number)) t))) 70 | 71 | (defun find-labels (code) 72 | "Returns all label names in the code block. If a label is multiply 73 | defined, an error is signaled. " 74 | (let ((labels (mapcar #'second 75 | (find-forms #'label-form? code)))) 76 | (aif (non-unique-items labels) 77 | (error 78 | "The following labels appear more than once in the same scope: ~a" 79 | it) 80 | labels))) 81 | 82 | (defun find-vars (code) 83 | (let* ((var-forms (find-forms #'var-form? code)) 84 | (var-names (mapcar #'second var-forms)) 85 | (var-types (mapcar #'third var-forms))) 86 | (aif (non-unique-items var-names) 87 | (error 88 | "The following variables are declared more than once in the 89 | same scope: ~a" it) 90 | (mapcar #'cons var-names var-types)))) 91 | 92 | (defun find-spills (code) 93 | (mapcar #'second 94 | (find-forms (lambda (form) 95 | (match form 96 | ((list 'spill (type number)) t))) 97 | code))) 98 | 99 | (defun range* (x) (loop for x from 1 to x collect x)) 100 | 101 | (defun max-temp-variable (code) 102 | (apply #'max (or (find-spills code) '(0)))) 103 | 104 | (defun find-temp-variables (code) 105 | (mapcar (fn1 (cons (%temp !1) 'c-int)) 106 | (range* (max-temp-variable code)))) 107 | 108 | (defun primitive? (x) 109 | (typecase x (symbol t) (number t) 110 | (t (match x 111 | ((list 'temp (type number)) t))))) 112 | 113 | (defun compound-forms (xs) (remove-if #'primitive? xs)) 114 | (defun all-primitive? (xs) 115 | (equalp xs (remove-if-not #'primitive? xs))) 116 | 117 | ;; TODO Make these unique 118 | (defun %temp (num) (intern (format nil "tmp~d" num) :s)) 119 | (defmacro temp (num) `(->A ,(%temp num))) 120 | (defmacro spill (num) `(A-> ,(%temp num))) 121 | 122 | (defun replace-compounds-with-temps (forms used-temps) 123 | (iter (for form in forms) 124 | (if (primitive? form) 125 | (collect form) 126 | (collect (%temp (incf used-temps)))))) 127 | 128 | ;; TODO This isn't quite right, but it works for now. 129 | (defun macro? (symbol) (fboundp symbol)) 130 | 131 | (defun %expr (expr used-temps) 132 | (match expr 133 | ((type number) `(lda ,expr)) 134 | ((type symbol) (when expr `(->A ,expr))) 135 | ((type string) `(format t "~{~a~}_~a~%" (indent-chars) ,expr)) 136 | ((list* (as f (type symbol)) args) 137 | (cond 138 | ((macro? f) expr) 139 | ((all-primitive? args) 140 | `(c-funcall ,f ,@args)) 141 | (t `(progn 142 | ,@(let ((used-temps used-temps)) 143 | (iter (for form in (compound-forms args)) 144 | (collect `(expr ,form :used-temps ,used-temps)) 145 | (collect `(spill ,(incf used-temps))))) 146 | (expr (,f ,@(replace-compounds-with-temps 147 | args used-temps))))))))) 148 | 149 | (defmacro expr (expr &key (used-temps 0)) 150 | (%expr expr used-temps)) 151 | 152 | (defun transform-expr (expr) 153 | (cond ((funcall-form? expr) `(c-funcall ,@expr)) 154 | ((var-ref-form? expr) `(->A ,expr)) 155 | ((numberp expr) `(->A ,expr)) 156 | (t expr))) 157 | 158 | (defun transform-c-syntax (block) 159 | (code-walk (fn1 `(expr ,!1)) block)) 160 | -------------------------------------------------------------------------------- /cs400.passes/compiler/c-impl.lisp: -------------------------------------------------------------------------------- 1 | #| 2 | (defmacro def-simple-binary-operator (operator mnemonic &key prelude) 3 | `(defmacro ,operator (operand-1 operand-2) 4 | `(nice-block ,',(symbol-name operator) 5 | ,',prelude 6 | (->A ,operand-1) 7 | ,(etypecase operand-2 8 | (symbol `(asm ,',mnemonic (var-addr-mode ',operand-2) 9 | (var-addr ',operand-2))) 10 | (number `(asm ,',mnemonic :immediate-w ,operand-2)))))) 11 | 12 | (pluralize-macro def-simple-binary-operator def-simple-binary-operators) 13 | 14 | (def-simple-binary-operators 15 | (c-+ adc :prelude (asm clc :implied)) 16 | (c-- sbc :prelude (asm sec :implied)) 17 | (c-^ eor) 18 | (c-& and) 19 | (c-band and) 20 | (c-\| ora) 21 | (c-bor ora)) 22 | 23 | (defmacro c-@ (operand) 24 | "Address of a variable" 25 | (declare (type symbol operand)) 26 | `(nice-block ,(format nil "address_of_~a" operand) 27 | (case (var-addr-mode ',operand) 28 | (:stack-indexed 29 | (asm clc :implied) 30 | (asm tsc :implied) 31 | (asm adc :immediate-w (var-addr ',operand))) 32 | (:absolute (var-addr ',operand))))) 33 | 34 | (defmacro c-$ (operand) 35 | "Pointer dereference. " 36 | `(nice-block 'dereference 37 | (->A ,operand) 38 | (asm sta :immediate-w 00) 39 | (asm lda :direct-indirect 00))) 40 | |# 41 | -------------------------------------------------------------------------------- /cs400.passes/compiler/compiler.lisp: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sbcl --script 2 | 3 | " 4 | A unix interface to the c compiler. 5 | 6 | If you want to dump a core image, define *script?* to nil before 7 | loading this file. Otherwise we simply run the c-compiler as script. 8 | " 9 | 10 | (defvar *script?* t) 11 | 12 | (let ((*standard-output* *error-output*)) 13 | (require :cs400-compiler)) 14 | 15 | (in-package :cs400-compiler) 16 | 17 | (defun repl () 18 | (let ((eof '#.(gensym "EOF-"))) 19 | (loop for x = (read *standard-input* nil eof) 20 | until (eq x eof) do (eval x) 21 | do (force-output)))) 22 | 23 | (defun main (args) 24 | (declare (ignore args)) 25 | (repl) 26 | (cl:in-package :cs400-compiler) 27 | 0) 28 | 29 | (defun top () 30 | (in-package :cs400-compiler) 31 | (sb-ext:quit 32 | :unix-status 33 | (handler-case (apply #'main sb-ext:*posix-argv*) 34 | (error (e) 35 | (format *error-output* "Fatal Error:~% ~a~%" e) 36 | 2) 37 | (t (s) 38 | (declare (ignore s)) 39 | 1)))) 40 | 41 | (if cl-user::*script?* 42 | (top) 43 | (sb-ext:save-lisp-and-die "compiler" 44 | :executable t 45 | :toplevel #'top 46 | :purify t)) 47 | -------------------------------------------------------------------------------- /cs400.passes/compiler/cs400-compiler.asd: -------------------------------------------------------------------------------- 1 | (asdf:defsystem #:cs400-compiler 2 | :depends-on (:iterate :cl-match :split-sequence :fare-matcher 3 | :memoize :alexandria) 4 | :components ((:file "package") 5 | (:file "lib") 6 | (:file "macroexpand-dammit") 7 | (:file "c-analize") 8 | (:file "asm") 9 | (:file "state") 10 | (:file "tag") 11 | (:file "c-impl") 12 | (:file "toplevel") 13 | (:file "front") 14 | (:file "back") 15 | (:file "far-back")) 16 | :serial t) 17 | -------------------------------------------------------------------------------- /cs400.passes/compiler/inputs/asm: -------------------------------------------------------------------------------- 1 | (asm lda :absolute 3) 2 | (asm clc :implied) 3 | (asm adc :direct 4) 4 | (asm adc :immediate 4) 5 | -------------------------------------------------------------------------------- /cs400.passes/compiler/inputs/c: -------------------------------------------------------------------------------- 1 | (in-package :c) 2 | 3 | (cl:defmacro 8-bit-mode () `(s::8-bit-mode)) 4 | (cl:defmacro 16-bit-mode () `(s::16-bit-mode)) 5 | (cl:defmacro funcall (f) `(s::%jsr ',f)) 6 | (cl:defmacro => (var) `(far-back::store-variable ,var)) 7 | (cl:defmacro finalize () `(s::vector-table)) 8 | 9 | [#LoROM] 10 | [#Data l Zero] 11 | [#Data w pong_char] 12 | [#Data w pong_frame] 13 | [#Data w pong_pallet] 14 | [#File reset.asm] 15 | 16 | (proto set_background_color void ()) 17 | 18 | (proc (cg_dma int) (status b-bus a-bank a-bus cg-addr num-bytes) 19 | (8-bit-mode) 20 | cg-addr 21 | [STA CGADD] 22 | status 23 | [STA DMAP] ;; DMA Status 24 | b-bus 25 | [STA DMAB] 26 | a-bank 27 | [STA DMAA.b] 28 | (16-bit-mode) 29 | a-bus 30 | [STA DMAA] 31 | num-bytes 32 | [STA DMAD] 33 | (8-bit-mode) 34 | [LDA #$01] 35 | [STA MDMAEN] 36 | (16-bit-mode)) 37 | 38 | (proc (vm_dma int) (status b-bus a-bank a-bus vm-addr num-bytes) 39 | vm-addr 40 | [STA VMADD] 41 | (8-bit-mode) 42 | status 43 | [STA DMAP] ;; DMA Status 44 | b-bus 45 | [STA DMAB] 46 | a-bank 47 | [STA DMAA.b] 48 | (16-bit-mode) 49 | a-bus 50 | [STA DMAA] 51 | num-bytes 52 | [STA DMAD] 53 | (8-bit-mode) 54 | [LDA #$01] 55 | [STA MDMAEN] 56 | (16-bit-mode)) 57 | 58 | (proc (main int) () 59 | (var hack int) 60 | [LDA #pong_pallet] 61 | (=> hack) 62 | (cg_dma #x0002 #x0022 #x0000 hack #x0000 #x0200) 63 | [LDA #pong_char] 64 | (=> hack) 65 | (vm_dma #x0001 #x0018 #x0000 hack #x0000 #x0800) 66 | [LDA #pong_frame] 67 | (=> hack) 68 | (vm_dma #x0001 #x0018 #x0000 hack #x0400 #x0800) 69 | 70 | (8-bit-mode) 71 | "Set screen to max brightness" 72 | [LDA #$0F] 73 | [STA INIDISP] 74 | "Graphics Mode 1" 75 | [LDA #$01] 76 | [STA BGMODE] 77 | "" 78 | [LDA #$04] 79 | [STA BG1SC] 80 | [LDA #$00] 81 | [STA BG12NBA] 82 | [LDA #$01] 83 | [STA TM] 84 | (16-bit-mode) 85 | 86 | (var color int 0) 87 | (while 1 88 | "Get input from the controller" 89 | [LDA $4218] 90 | (if [AND #$0100w] ;; is right button depressed? 91 | (++ color) 92 | color) 93 | (set_background_color color #x0000))) 94 | 95 | (proc (set_background_color void) (color color_address) 96 | color_address 97 | (8-bit-mode) 98 | [STA $2121w] 99 | (16-bit-mode) 100 | 101 | color 102 | (8-bit-mode) 103 | [STA $2122w] 104 | [XBA] 105 | [STA $2122w] 106 | (16-bit-mode)) 107 | 108 | (interrupt-handler :reset 109 | [SEI] 110 | [CLC] 111 | [XCE] 112 | [REP #$38] 113 | [PHK] 114 | [LDA #$0000] 115 | [TCD] 116 | [LDX #$1FFF] 117 | [TXS] 118 | [LDA #$0000] [TAX] [TAY] 119 | [JSR Reset.Registers] 120 | [JSR Reset.VRAM] 121 | [JSR Reset.OAM] 122 | [JSR Reset.CGRAM] 123 | (funcall main)) 124 | 125 | [#Data l Zero {$0000}] 126 | [#Data w pong_char {#pongChar.dat}] 127 | [#Data w pong_frame {#pongFrame.dat}] 128 | [#Data w pong_pallet {#pongPallet.dat}] 129 | (finalize) 130 | -------------------------------------------------------------------------------- /cs400.passes/compiler/inputs/colors.asm: -------------------------------------------------------------------------------- 1 | ; #LoROM 2 | ; #Code w main 3 | ; CLC 4 | ; XCE 5 | ; SEP #$30b 6 | ; {yay704} 7 | ; LDA #$0Fb 8 | ; STA $2100w 9 | ; LDA #$00b 10 | ; STA $2121w 11 | ; REP #$30b 12 | ; INC $0000 13 | ; LDA $0000 14 | ; SEP #$30b 15 | ; STA $2122w 16 | ; XBA 17 | ; STA $2122w 18 | ; BRA {yay704} 19 | ; RTS 20 | ; #Data $00:FFFC {$8000 $0000} 21 | -------------------------------------------------------------------------------- /cs400.passes/compiler/inputs/control-structures.c.lisp: -------------------------------------------------------------------------------- 1 | (in-package :c) 2 | 3 | (cl:defmacro 8-bit-mode () `(s::8-bit-mode)) 4 | (cl:defmacro 16-bit-mode () `(s::16-bit-mode)) 5 | (cl:defmacro funcall (f) `(s::%jsr ',f)) 6 | (cl:defmacro => (var) `(far-back::store-variable ,var)) 7 | (cl:defmacro finalize () `(s::vector-table)) 8 | 9 | [#LoROM] 10 | 11 | (var z int 0) 12 | (proc (main int) (x) 13 | (var y int 0) 14 | (if (> x y) (++ z)) 15 | (if (>= x y) (++ x)) 16 | (if (< x y) (++ z)) 17 | (if (<= x y) (++ x)) 18 | (for ((= x (+ (- 1 -1) 0)) (&& 1 (< x (+ 1 9))) (++ y)) 19 | (switch x 20 | (0 (main x)) 21 | (1 (main (+ x (+ 1 3)))) 22 | (2) 23 | (3 (main (main (main (main (++ x)))))) 24 | (default (do-while x (+ 1 (-- x)))) 25 | (4 (continue)))) 26 | (return (+ x y))) 27 | 28 | 29 | (interrupt-handler :reset 30 | [INC A] 31 | (funcall main)) 32 | 33 | (finalize) 34 | -------------------------------------------------------------------------------- /cs400.passes/compiler/inputs/pongChar.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/compiler/inputs/pongChar.dat -------------------------------------------------------------------------------- /cs400.passes/compiler/inputs/pongFrame.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/compiler/inputs/pongFrame.dat -------------------------------------------------------------------------------- /cs400.passes/compiler/inputs/pongPallet.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/compiler/inputs/pongPallet.dat -------------------------------------------------------------------------------- /cs400.passes/compiler/inputs/reset.asm: -------------------------------------------------------------------------------- 1 | ; #File snes_registers.h 2 | 3 | ; #Code l {Immediate_DMA} 4 | ; PHP 5 | ; PHB 6 | ; SEP #$20 7 | ; LDA $05,S 8 | ; PHA 9 | ; PLB 10 | ; REP #$20 11 | ; LDA $03,S 12 | ; INC A 13 | ; TAX 14 | ; LDA $0000,X 15 | ; STA DMAP 16 | ; LDA $0002,X 17 | ; STA DMAA.l 18 | ; LDA $0004,X 19 | ; STA DMAA.b 20 | ; SEP #$20 21 | ; LDA $0006,X 22 | ; STA DMAD.h 23 | ; LDA #$01 24 | ; STA MDMAEN 25 | ; REP #$20 26 | ; TXA 27 | ; CLC 28 | ; ADC #$0006 29 | ; STA $03,S 30 | ; PLB 31 | ; PLP 32 | ; RTL 33 | 34 | ; #Code w {Reset.Registers} 35 | ; PHP 36 | ; SEP #$20 37 | ; LDA #$00 38 | ; STA MEMSEL 39 | ; LDA #$80 40 | ; STA INIDISP 41 | ; STZ OBJSEL 42 | ; STZ OAMADD.l 43 | ; STZ OAMADD.h 44 | ; STZ BGMODE 45 | ; STZ MOSAIC 46 | ; STZ BG1SC 47 | ; STZ BG2SC 48 | ; STZ BG3SC 49 | ; STZ BG4SC 50 | ; STZ BG12NBA 51 | ; STZ BG34NBA 52 | ; STZ BG1HOFS 53 | ; STZ BG1HOFS 54 | ; STZ BG1VOFS 55 | ; STZ BG1VOFS 56 | ; STZ BG2HOFS 57 | ; STZ BG2HOFS 58 | ; STZ BG2VOFS 59 | ; STZ BG2VOFS 60 | ; STZ BG3HOFS 61 | ; STZ BG3HOFS 62 | ; STZ BG3VOFS 63 | ; STZ BG3VOFS 64 | ; STZ BG4HOFS 65 | ; STZ BG4HOFS 66 | ; STZ BG4VOFS 67 | ; STZ BG4VOFS 68 | ; STZ VMAINC 69 | ; STZ VMADD.l 70 | ; STZ VMADD.h 71 | ; STZ M7SEL 72 | ; STZ M7A 73 | ; STZ M7A 74 | ; STZ M7B 75 | ; STZ M7B 76 | ; STZ M7C 77 | ; STZ M7C 78 | ; STZ M7D 79 | ; STZ M7D 80 | ; STZ M7X 81 | ; STZ M7X 82 | ; STZ M7Y 83 | ; STZ M7Y 84 | ; STZ CGADD 85 | ; STZ W12SEL 86 | ; STZ W34SEL 87 | ; STZ WOBJSEL 88 | ; STZ WH0 89 | ; STZ WH1 90 | ; STZ WH2 91 | ; STZ WH3 92 | ; STZ WBGLOG 93 | ; STZ WOBJLOG 94 | ; STZ TM 95 | ; STZ TS 96 | ; STZ TMW_ 97 | ; STZ TSW_ 98 | ; STZ CGSWSEL 99 | ; STZ CGADSUB 100 | ; STZ COLDATA 101 | ; STZ SETINI 102 | ; LDA STAT78 103 | ; STZ WMADD.l 104 | ; STZ WMADD.h 105 | ; STZ WMADD.b 106 | ; STZ NMITIMEN 107 | ; STZ WRIO 108 | ; STZ WRMPYA 109 | ; STZ WRMPYB 110 | ; STZ WRDIVA.l 111 | ; STZ WRDIVA.h 112 | ; STZ WRDIVB 113 | ; STZ HTIME.l 114 | ; STZ HTIME.h 115 | ; STZ VTIME.l 116 | ; STZ VTIME.h 117 | ; STZ MDMAEN 118 | ; STZ HDMAEN 119 | ; LDA RDNMI 120 | ; LDA TIMEUP 121 | ; PLP 122 | ; RTS 123 | 124 | ; #Code w {Reset.VRAM} 125 | ; PHP 126 | ; SEP #$20 127 | ; LDA #$80 128 | ; STA VMAINC 129 | ; REP #$20 130 | ; STZ VMADD 131 | ; JSL Immediate_DMA 132 | ; #Data {$09 $18 Zero $0000} 133 | ; PLP 134 | ; RTS 135 | 136 | ; #Code w {Reset.OAM} 137 | ; PHP 138 | ; REP #$20 139 | ; STZ OAMADD 140 | ; JSL Immediate_DMA 141 | ; #Data {$0A $04 Zero $0220} 142 | ; PLP 143 | ; RTS 144 | 145 | ; #Code w {Reset.CGRAM} 146 | ; PHP 147 | ; SEP #$20 148 | ; STZ CGADD 149 | ; JSL Immediate_DMA 150 | ; #Data {$0A $22 Zero $0200} 151 | ; PLP 152 | ; RTS 153 | 154 | ; #Code w {Reset.APU} 155 | ; RTS 156 | -------------------------------------------------------------------------------- /cs400.passes/compiler/inputs/snes_registers.h: -------------------------------------------------------------------------------- 1 | ; # SNES Registers 2 | ; #Name $2100 INIDISP b 3 | ; #Name $2101 OBJSEL b 4 | ; #Name $2102 OAMADD w 5 | ; #Name $2104 OAMDATA b,LH 6 | ; #Name $2105 BGMODE b 7 | ; #Name $2106 MOSAIC b 8 | ; #Name $2107 BG1SC b 9 | ; #Name $2108 BG2SC b 10 | ; #Name $2109 BG3SC b 11 | ; #Name $210A BG4SC b 12 | ; #Name $210B BG12NBA b 13 | ; #Name $210C BG34NBA b 14 | ; #Name $210D BG1HOFS b,LH 15 | ; #Name $210E BG1VOFS b,LH 16 | ; #Name $210F BG2HOFS b,LH 17 | ; #Name $2110 BG2VOFS b,LH 18 | ; #Name $2111 BG3HOFS b,LH 19 | ; #Name $2112 BG3VOFS b,LH 20 | ; #Name $2113 BG4HOFS b,LH 21 | ; #Name $2114 BG4VOFS b,LH 22 | ; #Name $2115 VMAINC b 23 | ; #Name $2116 VMADD w 24 | ; #Name $2118 VMDATA w 25 | ; #Name $211A M7SEL b 26 | ; #Name $211B M7A b,LH 27 | ; #Name $211C M7B b,LH 28 | ; #Name $211D M7C b,LH 29 | ; #Name $211E M7D b,LH 30 | ; #Name $211F M7X b,LH 31 | ; #Name $2120 M7Y b,LH 32 | ; #Name $2121 CGADD b 33 | ; #Name $2122 CGDATA b,LH 34 | ; #Name $2123 W12SEL b 35 | ; #Name $2124 W34SEL b 36 | ; #Name $2125 WOBJSEL b 37 | ; #Name $2126 WH0 b 38 | ; #Name $2127 WH1 b 39 | ; #Name $2128 WH2 b 40 | ; #Name $2129 WH3 b 41 | ; #Name $212A WBGLOG b 42 | ; #Name $212B WOBJLOG b 43 | ; #Name $212C TM b 44 | ; #Name $212D TS b 45 | ; #Name $212E TMW_ b 46 | ; #Name $212F TSW_ b 47 | ; #Name $2130 CGSWSEL b 48 | ; #Name $2131 CGADSUB b 49 | ; #Name $2132 COLDATA b 50 | ; #Name $2133 SETINI b 51 | ; #Name $2134 RDMPY24 l,ro 52 | ; #Name $2137 SLHV b,ro 53 | ; #Name $2138 RDOAMDATA b,ro,LH 54 | ; #Name $2139 RDVMDATA w,ro 55 | ; #Name $213B RDCGDATA b,ro,LH 56 | ; #Name $213C OPHCT b,ro,LH 57 | ; #Name $213D OPVCT b,ro,LH 58 | ; #Name $213E STAT77 b,ro 59 | ; #Name $213F STAT78 b,ro 60 | ; #Name $2140 APUIO0 b 61 | ; #Name $2141 APUIO1 b 62 | ; #Name $2142 APUIO2 b 63 | ; #Name $2143 APUIO3 b 64 | ; #Name $2180 WMDATA b 65 | ; #Name $2181 WMADD l 66 | ; #Name $4016 JOYIO w 67 | ; #Name $4200 NMITIMEN b 68 | ; #Name $4201 WRIO b 69 | ; #Name $4202 WRMPYA b 70 | ; #Name $4203 WRMPYB b 71 | ; #Name $4204 WRDIVA w 72 | ; #Name $4206 WRDIVB b 73 | ; #Name $4207 HTIME w 74 | ; #Name $4209 VTIME w 75 | ; #Name $420B MDMAEN b 76 | ; #Name $420C HDMAEN b 77 | ; #Name $420D MEMSEL b 78 | ; #Name $4210 RDNMI b,ro 79 | ; #Name $4211 TIMEUP b,ro 80 | ; #Name $4212 HVBJOY b,ro 81 | ; #Name $4213 RDIO b,ro 82 | ; #Name $4214 RDDIV w,ro 83 | ; #Name $4216 RDMPY16 w,ro 84 | ; #Name $4218 JOY1 w 85 | ; #Name $421A JOY2 w 86 | ; #Name $421C JOY3 w 87 | ; #Name $421E JOY4 w 88 | ; #Name $4300 DMAP b 89 | ; #Name $4301 DMAB b 90 | ; #Name $4302 DMAA l 91 | ; #Name $4305 DMAD l 92 | ; #Name $4308 DMAI w 93 | ; #Name $430A DMAL b 94 | ; #Name $4300 DMAP0 b 95 | ; #Name $4301 DMAB0 b 96 | ; #Name $4302 DMAA0 l 97 | ; #Name $4305 DMAD0 l 98 | ; #Name $4308 DMAI0 w 99 | ; #Name $430A DMAL0 b 100 | ; #Name $4310 DMAP1 b 101 | ; #Name $4311 DMAB1 b 102 | ; #Name $4312 DMAA1 l 103 | ; #Name $4315 DMAD1 l 104 | ; #Name $4318 DMAI1 w 105 | ; #Name $431A DMAL1 b 106 | ; #Name $4320 DMAP2 b 107 | ; #Name $4321 DMAB2 b 108 | ; #Name $4322 DMAA2 l 109 | ; #Name $4325 DMAD2 l 110 | ; #Name $4328 DMAI2 w 111 | ; #Name $432A DMAL2 b 112 | ; #Name $4330 DMAP3 b 113 | ; #Name $4331 DMAB3 b 114 | ; #Name $4332 DMAA3 l 115 | ; #Name $4335 DMAD3 l 116 | ; #Name $4338 DMAI3 w 117 | ; #Name $433A DMAL3 b 118 | ; #Name $4340 DMAP4 b 119 | ; #Name $4341 DMAB4 b 120 | ; #Name $4342 DMAA4 l 121 | ; #Name $4345 DMAD4 l 122 | ; #Name $4348 DMAI4 w 123 | ; #Name $434A DMAL4 b 124 | ; #Name $4350 DMAP5 b 125 | ; #Name $4351 DMAB5 b 126 | ; #Name $4352 DMAA5 l 127 | ; #Name $4355 DMAD5 l 128 | ; #Name $4358 DMAI5 w 129 | ; #Name $435A DMAL5 b 130 | ; #Name $4360 DMAP6 b 131 | ; #Name $4361 DMAB6 b 132 | ; #Name $4362 DMAA6 l 133 | ; #Name $4365 DMAD6 l 134 | ; #Name $4368 DMAI6 w 135 | ; #Name $436A DMAL6 b 136 | ; #Name $4370 DMAP7 b 137 | ; #Name $4371 DMAB7 b 138 | ; #Name $4372 DMAA7 l 139 | ; #Name $4375 DMAD7 l 140 | ; #Name $4378 DMAI7 w 141 | ; #Name $437A DMAL7 b 142 | -------------------------------------------------------------------------------- /cs400.passes/compiler/notes/c-examples.lisp: -------------------------------------------------------------------------------- 1 | " 2 | Here is a table of syntaxes for operators. I don't like some of the 3 | things I chose (like _ instead of |), so if you have some better ideas 4 | tell me. 5 | 6 | ========= ============ ================ 7 | C Sexp c More lispy 8 | ========= ============ ================ 9 | +a (+ a) (+ a) 10 | a + b (+ a b) (+ a b c ...) 11 | ++a (++* a) (preincr a) 12 | a++ (++ a) (incr a) 13 | a += b (+= a b) (incr a b) 14 | -a (- a) (- a) 15 | a - b (- a b) (- a b c) 16 | --a (--* a) (predecr a) 17 | a-- (-- a) (decr a) 18 | a -= b (-= a b) (decr a b) 19 | a * b (* a b) (* a b) 20 | a *= b (*= a b) (set * a b) 21 | a / b (/ a b) (/ a b) 22 | a /= b (/= a b) (set / a b) 23 | a % b (% a b) (mod a b) 24 | a %= b (%= a b) (set mod a b) 25 | a < b (< a b) (< a b ...) 26 | a <= b (<= a b) (<= a b ...) 27 | a > b (> a b) (> a b ...) 28 | a >= b (>= a b) (>= a b ...) 29 | a != b (!= a b) (!= a b ...) 30 | a == b (== a b) (== a b ...) 31 | !a (! a) (not a) 32 | a && b (&& a b) (and a b ...) 33 | a || b (or a b) (or a b ...) 34 | a << b (<< a b) (lshift a b) 35 | a <<= b (<<= a b) (set lshift a b) 36 | a >> b (>> a b) (rshift a b) 37 | a >>= b (>>= a b) (set rshift a b) 38 | ~a (~ a) (nnot a) 39 | a & b (& a b) (nand a b) 40 | a &= b (&= a b) (set nand a b) 41 | a | b (_ a b) (!or a b) 42 | a |= b (_= a b) (set !or a b) 43 | a ^ b (^ a b) (^ a b ...) 44 | a ^= b (^= a b) (set ^ a b ...) 45 | a = b (= a b) (set a b) 46 | a() (a) (a) 47 | a[b] ([] a b) (a b) 48 | *a (@ a) (a) 49 | &a (& a) (? a) 50 | a->b (-> a :b) (a :b) 51 | (type)a (type a) (type a) 52 | a , b (do a b) (do a b) 53 | a ? b : c (? a b c) (if a b c) 54 | sizeof a (sizeof a) (size a) 55 | ========= ============ ================ 56 | 57 | Some expressions: 58 | 59 | a.b.c[2] 60 | (a :b :c 2) 61 | ([] (@. (@. a :b) :c) 2) 62 | 63 | a->b.c[(x == 3) ? 1 : 2] + 3 + a->a 64 | (+ (a :b :c (if (== x 3) 1 2)) 3 (a :a)) 65 | (+ ([] (.@ (-> a :b) :c) (? f 1 2)) 3 (-> a a)) 66 | 67 | 68 | Some functions: 69 | 70 | C: 71 | 72 | char *strcpy(char *dest, const char *src) 73 | { 74 | char *save = dest; 75 | while (*dest++ = *src++); 76 | return save; 77 | } 78 | 79 | 80 | Sexp C: 81 | 82 | (defun strcpy (dest src) 83 | (type :*char (const :*char) -> :*char) 84 | (var save dest :*char) 85 | (while (== (@ (++ dest)) (@ (++ dest)))) 86 | (return save)) 87 | 88 | 89 | More lispy: 90 | 91 | (defun strcpy (dest src) 92 | (type :*char (const :*char) -> :*char) 93 | (let ((save dest)) 94 | (while (== ((++ dest)) ((++ src)))) 95 | save)) 96 | 97 | Another example 98 | 99 | void f (int n, char x[n]) 100 | { 101 | for (int i = 0; ii < n; ii++) { 102 | if (!(i % 3)) { 103 | x[i] = '\0' 104 | } 105 | } 106 | } 107 | 108 | (defun f (n x) 109 | (type :int (:char n)) 110 | (for ((var i 0 :int) (< ii n) (++ i)) 111 | (if (! (% i 3)) 112 | (= ([] x i) #\null)))) 113 | 114 | (defun f (n x) 115 | (type int (char n)) 116 | (iter (for i below n) 117 | (if (divisible i 3) 118 | (set (x i) #\null)))) 119 | " 120 | -------------------------------------------------------------------------------- /cs400.passes/compiler/notes/c.c: -------------------------------------------------------------------------------- 1 | // despite the '.c' extensions, this file is just documentaion. It 2 | // explores the different namespaces of c and how various issues are 3 | // handled. 4 | 5 | // TODO This is not handled the same in tcc. Read the c standard and 6 | // see what is actuall the correct behavior. 7 | 8 | // Namespaces: 9 | // 1. Tagged types: 10 | // 11 | // 'struct c', 'enum c', and 'union c' are all in the same 12 | // namespace, but not the same namespaces as straight-up types like 13 | // 'int'. 14 | // 15 | // These are lexically scoped, there is a global scope, and every 16 | // block introduces a new scope. 17 | // 18 | // 2. Labels 19 | // 20 | // Lables use the functions scope. There is no scope nesting of 21 | // labels. There are no global lables, and 22 | // functions-definined-in-functions have their own, 23 | // completely-separate labels scope. 24 | // 25 | // 3. Everything else: 26 | // 27 | // - Types 28 | // - Variables 29 | // - Functions 30 | // 31 | // These are lexically scoped, there is a global scope, and every 32 | // block introduces a new scope. 33 | // 34 | // 4. Every Struct/union has it's own namespace within it. 35 | // 36 | // Aside from that 37 | 38 | struct f { int a; }; 39 | 40 | typedef int c; 41 | 42 | c see() { 43 | c c; 44 | switch ('a') { 45 | case 'a': break; 46 | default: return; } 47 | c: 48 | return c + c; } 49 | 50 | c main(void) { 51 | c cee(); 52 | c: 53 | return cee(); } 54 | 55 | c cee() { 56 | c C; 57 | typedef struct c { c c; } c; 58 | // int c; // This conflicts with the typedef above 59 | // typedef union c { c c; } see; // This conflicts with 'struct c' 60 | c: 61 | { c c; 62 | //c d; // Not cool. Using c as a type was fine above but not here 63 | // since the variable c hides it. 64 | if (!c.c) return 0; 65 | typedef struct c { int c; } C; 66 | // c: // Not cool. Label scopes don't nest 67 | C sea; 68 | struct c see() { 69 | c: // Nested functions have their own label scopes (although they 70 | // are not standard c). However, you can't goto labels in the 71 | // enclosing lexical scope. 72 | goto c; 73 | sea; }} 74 | c sea; 75 | return C; 76 | return see(sea.c); } 77 | -------------------------------------------------------------------------------- /cs400.passes/compiler/notes/compilation-examples: -------------------------------------------------------------------------------- 1 | # Code Generation Examples 2 | ## (+ 3 4) 3 | 4 | ; LDA #3b 5 | ; CLC 6 | ; ADC #4b 7 | 8 | ## (+ x y) 9 | In the caller: 10 | 11 | ; LDA x Push x 12 | ; PHA 13 | ; LDA y Push y 14 | ; PHA 15 | ; TSC Make room for 1 byte of return space 16 | ; CLC 17 | ; ADC #1b 18 | ; TCS 19 | ; JSL whatever 20 | ; LDA 1,S Return value 21 | ; TSC Clean up the stack 22 | ; SEC 23 | ; SBC #3 24 | ; TCS 25 | 26 | 27 | In the callee: 28 | 29 | ; LDA 5,S First argument 30 | ; CLC 31 | ; ADC 4,S Second argument 32 | ; STA 3,S Return value 33 | ; RTS 34 | 35 | 36 | # Simple Code Example 37 | 38 | (var n char 0) 39 | 40 | (defun foo ((char x) (char y) -> char) 41 | (var z char 3) 42 | (return (+ x y z))) 43 | 44 | (defun main () 45 | (label loop) 46 | (if (!= n 10) 47 | (block (++ n) 48 | (goto loop)) 49 | (block (-- n))) 50 | (= n (foo 3 n))) 51 | 52 | Expands into... 53 | 54 | (defvar *type-sizes* '(char 1)) 55 | (defvar *globals* (make-hash-table)) 56 | 57 | (setf (gethash *globals* 'n) '(char)) 58 | 59 | 60 | (setf (gethash *functions* foo) 61 | '(progn (asm lda :immediate 3) 62 | (asm pha :implied) 63 | (asm clc :implied) 64 | (asm lda :stack-relative 1) 65 | (asm adc :stack-relative 4) 66 | (asm adc :stack-relative 5) 67 | (asm plx :implied) 68 | (asm rts :implied))) 69 | 70 | (setf (gethash *functions* main) 71 | '(progn (asm label loop) 72 | (asm lda :direct (global n)) 73 | (asm cmp :immediate 10) 74 | (asm beq :label else) 75 | (asm inc :direct (global n)) 76 | (asm bra :label loop) 77 | (asm bra :label end) 78 | (asm label else) 79 | (asm dec :direct (global n)) 80 | (asm label end) 81 | (asm lda :immediate 3) 82 | (asm pha :implied) 83 | (asm lda :direct (global n)) 84 | (asm pha :implied) 85 | (asm jsr :absolute (function foo)) 86 | (asm sta :direct (global _temp1)) 87 | (asm tsc :implied) 88 | (asm clc :implied) 89 | (asm adc :immediate 2) 90 | (asm tcs :implied) 91 | (asm lda :direct (global _temp1)) 92 | (asm sta :direct (global n)))) 93 | -------------------------------------------------------------------------------- /cs400.passes/compiler/notes/oo: -------------------------------------------------------------------------------- 1 | # OO 2 | 3 | Some ideas for a light Object system on top of c. 4 | 5 | # Inheritance 6 | 7 | Instead of inheritence, we simply support struct includes: 8 | 9 | struct a { int one, two; } 10 | struct b { struct a; int three; } 11 | struct b b; 12 | return b.one; 13 | 14 | Note that including any struct more than once is impossible since the 15 | namespace would have conflicts. This lets us have simple method 16 | dispatch. 17 | 18 | # Methods 19 | 20 | Methods are definied externally to a struct. Method dispatch is done 21 | at compile time, and doesn't change the meaning of structs in any way. 22 | Methods are simply dispatched to the closest possible match, where 23 | includes mentioned earlier in a struct are considered closer matches. 24 | 25 | (generic + (a b -> c)) 26 | (method + ((a struct-a) (b struct-a) -> int) 27 | (return 4)) 28 | (method + ((a struct-b) (b struct-b) -> int) 29 | (return 5)) 30 | (var (a b) struct-a) 31 | (var (c d) struct-b) 32 | (+ a b) ;; => 4 33 | (+ c d) ;; => 5 34 | (+ a c) ;; => 4 35 | 36 | Here is some conceivable resulting c code: 37 | 38 | struct a { int one, two; } 39 | struct b { struct a __a; int three; } // __a is an include. 40 | return b.one; 41 | 42 | int plus_struct_a (struct a a, struct a b) { 43 | return 4; } 44 | int plus_struct_b (struct b a, struct b b) { 45 | return 5; } 46 | struct a a, b; 47 | struct b c, d; 48 | plus_struct_a(a, b) 49 | plus_struct_b(c, d) 50 | plus_struct_a(a, c.__a) 51 | -------------------------------------------------------------------------------- /cs400.passes/compiler/package.lisp: -------------------------------------------------------------------------------- 1 | " 2 | This is just the package definition. It's really too small to 3 | justify having its own file, but I think it will grow. Eventualy we 4 | need to export symbols and stuff here. 5 | " 6 | 7 | (defpackage #:cs400-compiler 8 | (:use #:cl #:iterate #:cl-match #:split-sequence) 9 | (:shadow #:match) 10 | (:nicknames #:s)) 11 | 12 | (import '(fare-matcher::of-type alexandria:mappend) :cs400-compiler) 13 | 14 | (defpackage :c) 15 | (defpackage #:tag (:export #:tag #:def #:defs #:let #:tag? #:.form 16 | #:replace #:find)) 17 | (defpackage #:front) 18 | (defpackage #:back) 19 | (defpackage #:far-back) 20 | (in-package #:cs400-compiler) 21 | (setf (readtable-case *readtable*) :invert) 22 | 23 | (defconstant +asm-syntax-start+ #\[) 24 | (defconstant +asm-syntax-stop+ #\]) 25 | 26 | (defun parse-asm (stream depth chars) 27 | (if (zerop depth) 28 | (coerce (nreverse (cdr chars)) 'string) 29 | (let* ((c (read-char stream)) 30 | (depth (cond 31 | ((char= c +asm-syntax-start+) (1+ depth)) 32 | ((char= c +asm-syntax-stop+) (1- depth)) 33 | (t depth)))) 34 | (cons c depth) 35 | (parse-asm stream depth (cons c chars))))) 36 | 37 | (set-macro-character #\[ (lambda (s c) 38 | (declare (ignore c)) 39 | `(emit ,(parse-asm s 1 nil)))) 40 | -------------------------------------------------------------------------------- /cs400.passes/compiler/state.lisp: -------------------------------------------------------------------------------- 1 | (in-package :cs400-compiler) 2 | 3 | (defstruct transformation predicate function) 4 | (defstruct compiler-pass name tags macros transformations) 5 | (defstruct c-variable 6 | (type nil :read-only t :type (member c::int c::void)) 7 | (address nil :read-only t :type (or symbol fixnum)) 8 | initial-value) 9 | 10 | (defstruct c-function 11 | (type nil :read-only t :type t) 12 | (asm-name nil :read-only t :type symbol) 13 | (prototype nil :read-only nil :type boolean)) 14 | 15 | (defun c-variable (type address) 16 | (make-c-variable :type type :address address)) 17 | 18 | (defun c-function (prototype? type name) 19 | (declare (symbol name) (boolean prototype?)) 20 | "Name is the name in the c world not the asm name. " 21 | (make-c-function :type type 22 | :asm-name (gensym (format nil "fn.~a" name)) 23 | :prototype prototype?)) 24 | 25 | (defclass compiler () 26 | ((passes :accessor .passes :initform (make-hash-table)) 27 | (globals :accessor .globals :initform (make-hash-table)) 28 | (next-available-address :accessor .next :initform #x0100))) 29 | 30 | (defparameter *compiler* (make-instance 'compiler)) 31 | 32 | "# Convient access to compiler state" 33 | (defun alloc (size) 34 | (prog1 (.next *compiler*) 35 | (incf (.next *compiler*) size))) 36 | 37 | (defun get-id (identifier) 38 | "Returns NIL if unbound" 39 | (declare (symbol identifier)) 40 | (gethash identifier (.globals *compiler*))) 41 | 42 | (defun set-id (identifier value) 43 | "Returns NIL if unbound" 44 | (declare (symbol identifier)) 45 | (setf (gethash identifier (.globals *compiler*)) 46 | value)) 47 | 48 | (defun type->size (type) 49 | (match type 50 | ('c::int 2) 51 | ('c::void 0) 52 | (_ (error "Unknown type: ~a" type)))) 53 | 54 | (defun set-var (id var) 55 | (etypecase (get-id id) 56 | (c-variable (error "Redefining variable ~a" id)) 57 | ((eql nil) (setf (gethash id (.globals *compiler*)) var)) 58 | (t (error "~a is bound so somthing that's not a variable" id)))) 59 | 60 | (defun get-var (identifier) 61 | (let ((it (get-id identifier))) 62 | (etypecase it 63 | (c-variable it) 64 | ((eql nil) (error "Unbound identifier ~a" identifier)) 65 | (t (error "~a is bound so somthing that's not a variable" identifier))))) 66 | 67 | (defun alloc-variable (name type) 68 | (set-var name 69 | (c-variable type (alloc (type->size type))))) 70 | 71 | (defun init-variable (name value) 72 | (setf (c-variable-initial-value (get-var name)) 73 | value)) 74 | 75 | (defun get-transformations (pass-name) 76 | (compiler-pass-transformations 77 | (or (gethash pass-name (.passes *compiler*)) 78 | (error "undefined compiler pass ~a" pass-name)))) 79 | 80 | (defun add-transformation (transformation pass-name) 81 | (push transformation 82 | (compiler-pass-transformations 83 | (gethash pass-name (.passes *compiler*))))) 84 | 85 | (defun get-tags (pass-name) 86 | (slot-value 87 | (gethash pass-name (.passes *compiler*)) 88 | 'tags)) 89 | 90 | (defun %get-fn (id) 91 | (declare (symbol id)) 92 | (let ((fn (get-id id))) 93 | (typecase fn 94 | (c-function fn) 95 | (c-variable (error "id is bound to something not a function: ~s" id)) 96 | (t nil)))) 97 | 98 | (defun c-fn-unique-name (name) 99 | (let ((fn (get-id name))) 100 | (typecase fn 101 | (c-function (c-function-asm-name fn)) 102 | (c-variable (error "~a is not a function" name)) 103 | (t (error "Undefined identifier: ~s" name))))) 104 | 105 | (defun prototype-fn (name type) 106 | (aif (%get-fn name) 107 | (if (equalp type (c-function-type it)) 108 | it 109 | (error 110 | "Incompatible types between two declarations of ~s: (~s ~s)" 111 | name type (c-function-type it))) 112 | (progn 113 | (set-id name (c-function t type name)) 114 | (%asm-code (c-fn-unique-name name) :prototype t) 115 | (get-id name)))) 116 | 117 | (defun instantiate-fn (name type) 118 | (let ((fn (prototype-fn name type))) 119 | ;; TODO This shouldn't be commented but it's annoying for 120 | ;; debugging: 121 | ;; (unless (c-function-prototype fn) 122 | ;; (error "Multiple definition of function ~a" name)) 123 | (setf (c-function-prototype fn) nil) 124 | (%asm-code (c-fn-unique-name name)))) 125 | -------------------------------------------------------------------------------- /cs400.passes/compiler/tag.lisp: -------------------------------------------------------------------------------- 1 | " 2 | A tag is a way of separating macroexpansions in layers. Basically, a 3 | tag is some code of the form (tag:tag '()). Since tag:tag is 4 | undefined, this code will be an error if it is EVALuated. The point 5 | is that another macro can PREEXPAND your code and replace tags with 6 | some real code. This allows you to use PREEXPAND without it replacing 7 | you shit. 8 | " 9 | 10 | (in-package :s) 11 | 12 | (defun lambda-list-modifier? (symbol) 13 | (char= (elt (symbol-name symbol) 0) #\&)) 14 | 15 | (defun neg (f) 16 | (fn (&rest args) 17 | (not (apply f args)))) 18 | 19 | (defmacro tag:def (name pass-name &rest lambda-list) 20 | (declare (ignore lambda-list)) 21 | `(progn 22 | (push ',name (slot-value 23 | (gethash ',pass-name (.passes *compiler*)) 24 | 'tags)))) 25 | 26 | (defmacro tag:let ((name &rest lambda-list) &body body) 27 | (declare (ignore lambda-list)) 28 | `(macrolet 29 | ((,name (&rest args) 30 | `(tag:tag ,`(quote ,(cons ',name args))))) 31 | ,@body)) 32 | 33 | (pluralize-macro tag:def tag:defs) 34 | 35 | (defun tag:.form (tag) (second (second tag))) 36 | (defun tag:tag? (form) 37 | (match form 38 | ((list 'tag:tag _) t))) 39 | 40 | (defun tag:replace (function form) 41 | "Replace instances of (tag:tag '(&rest SUBFORM)) anywhere in FORM. 42 | FUNCTION is called with SUBFORM." 43 | (tree-walk 44 | (fn (subform) 45 | (match subform 46 | ((list 'tag:tag (list 'quote subsubform)) 47 | (& function subsubform)) 48 | (_ subform))) 49 | form)) 50 | 51 | (defun tag:find (predicate form) 52 | (collecting 53 | (tag:replace #l(progn 54 | (when (& predicate !1) 55 | (collect !1)) 56 | !1) 57 | form))) 58 | 59 | "# Pass definition macros" 60 | (defun transform-rule (rule invalid pass-name) 61 | (match rule 62 | ((list (list* name lambda-list)) 63 | (print `(tag:def ,name ,pass-name ,@lambda-list)) 64 | `(tag:def ,name ,pass-name ,@lambda-list)) 65 | ((list (list* name lambda-list) '-> body) 66 | (typecase body 67 | (list `(defmacro ,name ,lambda-list ,body)) 68 | (symbol `(defmacro ,name (&rest args) 69 | `(,',body ,@args))) 70 | (t (& invalid rule)))) 71 | (_ (& invalid rule)))) 72 | 73 | (defmacro define-pass (pass-name &body toplevel-rules) 74 | (declare (symbol pass-name)) 75 | (flet ((invalid (rule) 76 | (error 77 | "Invalid transformation rule:~% ~s~%~%in pass:~% ~s~%~%" 78 | rule `(define-pass ,pass-name ,@toplevel-rules)))) 79 | `(progn 80 | (setf (gethash ',pass-name (slot-value *compiler* 'passes)) 81 | (make-compiler-pass :name ',pass-name)) 82 | ,@(mapcar 83 | (fn1 (transform-rule !1 #'invalid pass-name)) 84 | toplevel-rules)))) 85 | 86 | 87 | "# Transformations" 88 | (defmacro define-predicated-transformation 89 | ((function-name predicate pass-name) 90 | lambda-list &body code) 91 | "PREDICATED-TRANSFORMATIONs are given a chance to tranform a 92 | tagged-form if there is no NAMED-TRANSFORMATION. 93 | 94 | A PREDICATED-TRANSFORMATION must return (VALUES FORM USE?), if USE? 95 | if NIL, then the transformation is not used, and the next 96 | predicated transformation will be tried. If no transformation 97 | applies to a tagged form, then it will not be transformated, and 98 | thus will be left tagged. " 99 | (declare (symbol function-name pass-name)) 100 | `(progn 101 | (defun ,function-name ,lambda-list 102 | ,@code) 103 | (add-transformation (make-transformation 104 | :predicate ,predicate 105 | :function #',function-name) 106 | ',pass-name))) 107 | 108 | (defmacro define-tag-substitution ((macro-name tag pass-name) 109 | lambda-list &body code) 110 | (declare (symbol macro-name pass-name tag)) 111 | `(progn 112 | (defmacro ,macro-name ,lambda-list 113 | ,@code) 114 | (add-transformation (make-transformation 115 | :predicate (fn1 (eq (car !1) ',tag)) 116 | :function (fn (&rest form) 117 | `(,',macro-name ,@(cdr form)))) 118 | ',pass-name))) 119 | 120 | 121 | 122 | (defun taggify-form (form pass-name) 123 | (let ((tags (get-tags pass-name))) 124 | (tree-walk (fn1 125 | (if (and (listp !1) 126 | (member (car !1) tags)) 127 | (tag-quote !1) 128 | !1)) 129 | form))) 130 | 131 | (defun tag-quote (form) `(tag:tag ,`(quote ,form))) 132 | 133 | (defun transform-tag-form (form pass-name) 134 | (iter (for ts in (get-transformations pass-name)) 135 | (with-slots (predicate function) ts 136 | (when (& predicate form) 137 | (return (apply function form)))) 138 | (finally (return (tag-quote form))))) 139 | 140 | (defun progn-clean (code) 141 | (tree-walk #'progn-flatten code)) 142 | 143 | (defun apply-pass (form pass-name) 144 | (progn-clean 145 | (preexpand 146 | (tag:replace (fn1 (transform-tag-form !1 pass-name)) 147 | (preexpand form))))) 148 | 149 | (defun c->front (symbol) 150 | (declare (symbol symbol)) 151 | (assert (eq (symbol-package symbol) 152 | (find-package :c))) 153 | (intern (symbol-name symbol) (find-package :front))) 154 | -------------------------------------------------------------------------------- /cs400.passes/compiler/toplevel.lisp: -------------------------------------------------------------------------------- 1 | " 2 | # Toplevel -- The First Compiler Pass 3 | 4 | This defines the interface that is exposed to the C programmer. 5 | Mostly this layer exists as a way to make invalid toplevel c code 6 | invalid, and to document the general approach to layering. All 7 | interface code for this pass is defined in the :C package. 8 | 9 | A pass interface in this compiler consists of a set of tags and a set 10 | of toplevel macros. Toplevel macros are responsible for doing the 11 | transformations and passing control on to the next pass. There are a 12 | fixed set of toplevel macros that are defined in all passes. They 13 | are: 14 | 15 | - proc 16 | - var 17 | - proto 18 | - interrupt-handler 19 | " 20 | 21 | (in-package #:cs400-compiler) 22 | 23 | (define-constant +c-operators+ 24 | '((c::+ x y) 25 | (c::- x y) 26 | (c::^ x y) 27 | (c::& x y) 28 | (c::band x y) 29 | (c::\| x y) 30 | (c::bor x y) 31 | (c::&& x y) 32 | (c::|\|\|| x y) 33 | (c::and x y) 34 | (c::or x y) 35 | (c::_ x y) 36 | (c::++ x) 37 | (c::-- x) 38 | (c::= x y) 39 | (c::== x y) 40 | (c::< x y) 41 | (c::> x y) 42 | (c::>= x y) 43 | (c::<= x y) 44 | (c::@ x) 45 | (c::$ x))) 46 | 47 | (define-constant +c-operator-names+ 48 | '#.(mapcar #'first +c-operators+)) 49 | 50 | (define-constant +c-control-structures+ 51 | '((c::block &body code) 52 | (c::if test then-form &optional else-form) 53 | (c::while test &body body) 54 | (c::do-while test &body body) 55 | (c::break) 56 | (c::continue) 57 | (c::return x) 58 | (c::for ((setup test iterate) &body body)) 59 | (c::switch expr &body cases) 60 | (c::goto label) 61 | (c::label name))) 62 | 63 | (define-constant +c-declarations+ '((c::proto name))) 64 | 65 | (define-constant +c-tags+ 66 | '#.(append 67 | +c-declarations+ 68 | +c-operators+ 69 | +c-control-structures+)) 70 | 71 | (define-constant +c-tag-names+ 72 | (cons 'c::var 73 | #.`(quote 74 | ,(mapcar #'first +c-tags+)))) 75 | 76 | 77 | "# Utillity Functions" 78 | (defun c-proc (code) 79 | (preexpand 80 | `(tag:let (c::var name type &optional value) 81 | ,code))) 82 | 83 | (defun c-tag? (symbol) 84 | (declare (symbol symbol)) 85 | (member symbol +c-tag-names+)) 86 | 87 | "# Pass Definition" 88 | (always-eval 89 | #.`(define-pass toplevel 90 | ,@(mapcar #'list +c-tags+) 91 | ((c::var name type &optional value) -> 92 | `(progn 93 | (front::global-variable-declaration ,name ,type) 94 | ,(when value 95 | `(front::global-variable-initialization ,name ,value)))) 96 | ((c::proto name type args) -> front::proto) 97 | ((c::proc (name type) args &body code) 98 | -> `(front::proc ,name ,type ,args 99 | ,(apply-pass 100 | (c-proc (taggify-form 101 | `(progn ,@code) 102 | 'toplevel)) 103 | 'toplevel))) 104 | ((c::interrupt-handler name &body code) 105 | -> front::interrupt-handler))) 106 | 107 | "TODO predicates defined later have higher priority. " 108 | (define-predicated-transformation (pass-to-front 109 | (fn1 110 | (c-tag? (first !1))) 111 | toplevel) 112 | (tagname &rest args) 113 | "this is the fallback transformation. it just renames tags to be in 114 | the :front package. " 115 | `(,(c->front tagname) ,@args)) 116 | 117 | (define-tag-substitution (c-var c::var toplevel) 118 | (name type &optional value) 119 | `(progn 120 | (front::local-variable-declaration ,name ,type) 121 | ,(when value 122 | `(front::local-variable-initialization ,name ,value)))) 123 | -------------------------------------------------------------------------------- /cs400.passes/docs/Compiler.ppt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/docs/Compiler.ppt.gz -------------------------------------------------------------------------------- /cs400.passes/docs/Makefile: -------------------------------------------------------------------------------- 1 | all: prospectus.pdf 2 | clean: cleanup; rm -f prospectus.pdf 3 | cleanup:; rm -f *.aux *.dvi *.log *~ 4 | %.pdf: %.tex; pdflatex -interaction batchmode $^ 5 | -------------------------------------------------------------------------------- /cs400.passes/docs/final-docs/final-docs.org: -------------------------------------------------------------------------------- 1 | * Compiler 2 | ** Progress; Working Demo (Pong) 3 | ** Evolution of Goals 4 | ** Group Organization 5 | ** Implementation 6 | *** Current Implementation 7 | *** Evolution of Implementation 8 | *** Hardware 9 | -------------------------------------------------------------------------------- /cs400.passes/docs/presentation-3/Makefile: -------------------------------------------------------------------------------- 1 | clean:; rm -f *~ 2 | -------------------------------------------------------------------------------- /cs400.passes/docs/presentation-3/input1.c.lisp: -------------------------------------------------------------------------------- 1 | (in-package :c) 2 | 3 | (proc (main int) ()) 4 | -------------------------------------------------------------------------------- /cs400.passes/docs/presentation-3/input2.c.lisp: -------------------------------------------------------------------------------- 1 | (in-package :c) 2 | 3 | (proc (main int) () 4 | (var x int 1) 5 | (while x (++ x))) 6 | -------------------------------------------------------------------------------- /cs400.passes/docs/presentation-3/presentation-3.org: -------------------------------------------------------------------------------- 1 | #+DRAWERS: SELFNOTE 2 | 3 | * CS400 Compiler 4 | [[./scratch]] 5 | 6 | ** Group Organization 7 | :SELFNOTE: 8 | - Beck asked which features we have make a decision not to 9 | implement. 10 | - Not really how we're thinking about it. 11 | :END: 12 | *** Goals 13 | :SELFNOTE: 14 | - Write a *useful* compiler for the SNES. 15 | - No fixed set of features. 16 | - Ultimate, unachievable Goal: Write a 17 | compiler that supports all of C99. 18 | - Wont happen so we increment towards it. 19 | :END: 20 | *** Incremental Approach 21 | :SELFNOTE: 22 | - Working compiler at all times. 23 | - Add the next-most-important 24 | approachable feature. 25 | :END: 26 | *** Some Features that We Need 27 | :SELFNOTE: 28 | - Before we have a useful compiler 29 | - Function Calls argument passing 30 | - Nested Expressions 31 | - Pointers and Arrays 32 | - Access to all of memory 33 | :END: 34 | *** Some Difficult Features 35 | :SELFNOTE: 36 | (puts these off because they are 37 | more difficult then they seem) 38 | - Type System 39 | - Optimization 40 | - Floating point (No HW support) 41 | - Nested Expressions 42 | + (+ (f 3 4) (g 4 (f 0 0))) 43 | :END: 44 | *** Meeting Organization 45 | :SELFNOTE: 46 | - Meet 3 times a week. 47 | - Most work is done as a group 48 | during this time. 49 | - We discuss how to implement a 50 | features, then I implement it on 51 | the projector. (Pick a feature; 52 | discuss; implement) 53 | :END: 54 | ** Compiler Implementation 55 | *** Approach Summary 56 | **** Normal Compiler Implementation 57 | :SELFNOTE: 58 | - Compiler | input file | output file 59 | - Compiler parses input file 60 | - Compiler performs a series of 61 | modifications to the AST. 62 | - Code generation and output 63 | :END: 64 | **** Our Implementation 65 | :SELFNOTE: 66 | - S-expression Syntax 67 | - Extend CL with macros. 68 | - This makes the inputs a executable 69 | Lisp program which outputs asm code. 70 | - Compiler is implemented as Common Lisp 71 | macros. 72 | - This really is a different paradigm. 73 | :END: 74 | [[/home/ben/repositories/sexp-syntaxes/midimsg.c.lisp][Syntax Example]] 75 | 76 | *** A Runnable Input Example 77 | [[../../compiler/inputs]] 78 | :SELFNOTE: 79 | Show compiler running as a Lisp 80 | Interpreter. 81 | 82 | 83 | :END: 84 | *** An Input Example 85 | [[./input1.c.lisp]] 86 | [[./input2.c.lisp]] 87 | 88 | :SELFNOTE: 89 | - Run C translator as Lisp Interpreter 90 | 91 | (in-package :c) 92 | (cl:defmacro sub (name cl:&body code) 93 | `(proc (,name void) () ,@code)) 94 | (sub hi (c::var x int 0)) 95 | 96 | - Generate C Code 97 | - Generate ASM Code 98 | - Partially Expanded Common Lisp Code 99 | :END: 100 | *** Our Implementation Approach 101 | :SELFNOTE: 102 | - Input file is actually 103 | a Common Lisp program 104 | - Compiler is a Common Lisp 105 | library (macros). 106 | - Input file has full access 107 | to Common Lisp, and can add 108 | anything it likes to the 109 | compiler. 110 | - The Common-Lisp macro 111 | expansion process can be 112 | seen as a series of AST 113 | transformations, except: 114 | + You don't think about it 115 | like that. 116 | + AST is valid CL at every 117 | step. 118 | - This is the way Common Lisp 119 | implementations work. 120 | - This is the way Common Lisp 121 | libraries work. 122 | :END: 123 | -------------------------------------------------------------------------------- /cs400.passes/docs/presentation-3/show.lisp: -------------------------------------------------------------------------------- 1 | (in-package :cs400-compiler) 2 | 3 | (defmacro expand (code) 4 | `(let ((*package* (find-package :cs400-compiler))) 5 | (print (macroexpand ',code)))) 6 | -------------------------------------------------------------------------------- /cs400.passes/flashing-colors/Makefile: -------------------------------------------------------------------------------- 1 | AC = ../assembler/65816asm 2 | SC = ../compiler/compiler 3 | 4 | all: flashing.smc 5 | clean:; rm -f flashing.smc flashing.asm 6 | test: all; snes9x flashing.smc 7 | 8 | $(AC):; cd ../assembler; make 9 | $(SC):; cd ../compiler; make 10 | %.smc: %.asm $(AC); $(AC) $< 11 | %.asm: %.c.lisp $(SC); $(SC) < $< > $@ 12 | -------------------------------------------------------------------------------- /cs400.passes/flashing-colors/flashing.c.lisp: -------------------------------------------------------------------------------- 1 | (in-package :c) 2 | 3 | (s::emit "#LoROM") 4 | 5 | (proto set_background_color) 6 | 7 | (proc (main int) () 8 | 9 | "Set screen to max brightness" 10 | (s::8-bit-mode) 11 | (s::asm s::lda :immediate #x0F) 12 | (s::asm s::sta :absolute #x2100) 13 | (s::16-bit-mode) 14 | 15 | (var color int 0) 16 | (while (s::lda 1) 17 | 18 | "Get input from the controller" 19 | (s::asm s::lda :absolute #x4218) 20 | (if (s::asm s::and :immediate-w #x0100) ;; is right button depressed? 21 | (++ color) 22 | color) 23 | (set_background_color color #x0000))) 24 | 25 | (proc (set_background_color void) (color color_address) 26 | color_address 27 | (s::8-bit-mode) 28 | (s::asm s::sta :absolute #x2121) 29 | (s::16-bit-mode) 30 | 31 | color 32 | (s::8-bit-mode) 33 | (s::asm s::sta :absolute #x2122) 34 | (s::asm s::xba :implied) 35 | (s::asm s::sta :absolute #x2122) 36 | (s::16-bit-mode)) 37 | -------------------------------------------------------------------------------- /cs400.passes/jormungandr/JormungandrChar.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/jormungandr/JormungandrChar.dat -------------------------------------------------------------------------------- /cs400.passes/jormungandr/JormungandrColor.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/jormungandr/JormungandrColor.dat -------------------------------------------------------------------------------- /cs400.passes/jormungandr/JormungandrFloorMap.dat: -------------------------------------------------------------------------------- 1 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -------------------------------------------------------------------------------- /cs400.passes/jormungandr/JormungandrFrameMap.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/jormungandr/JormungandrFrameMap.dat -------------------------------------------------------------------------------- /cs400.passes/jormungandr/JormungandrTrailMap.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/jormungandr/JormungandrTrailMap.dat -------------------------------------------------------------------------------- /cs400.passes/jormungandr/Makefile: -------------------------------------------------------------------------------- 1 | data_files = JormungandrChar.dat JormungandrColor.dat JormungandrFloorMap.dat 2 | data_files += JormungandrFrameMap.dat JormungandrTrailMap.dat 3 | AC = ../assembler/65816asm 4 | 5 | all: jormungandr.smc 6 | $(AC):; cd ../assembler; make 7 | %.smc: %.asm $(data_files) $(AC); $(AC) $< 8 | clean:; rm -f jormungandr.smc 9 | test: all; snes9x jormungandr.smc 10 | -------------------------------------------------------------------------------- /cs400.passes/phoenix/Makefile: -------------------------------------------------------------------------------- 1 | data_files = Phoenix_Color.dat Phoenix_Char.dat Phoenix_Frame_BG_Map.dat 2 | data_files += Phoenix_Star_BG_Map.dat 3 | AC = ../assembler/65816asm 4 | 5 | all: phoenix.smc 6 | $(AC):; cd ../assembler; make 7 | phoenix.smc: $(data_files) phoenix.asm $(AC); $(AC) phoenix.asm 8 | clean:; rm -f phoenix.smc 9 | test: all; snes9x phoenix.smc 10 | -------------------------------------------------------------------------------- /cs400.passes/phoenix/Phoenix_Char.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/phoenix/Phoenix_Char.dat -------------------------------------------------------------------------------- /cs400.passes/phoenix/Phoenix_Color.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/phoenix/Phoenix_Color.dat -------------------------------------------------------------------------------- /cs400.passes/phoenix/Phoenix_Frame_BG_Map.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/phoenix/Phoenix_Frame_BG_Map.dat -------------------------------------------------------------------------------- /cs400.passes/phoenix/Phoenix_Star_BG_Map.dat: -------------------------------------------------------------------------------- 1 | ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? = ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? < ; ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ; ? ? ? ? ? ? = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < > ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < = ? ? ? ? ? ? ? ? ; ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? = ? ? < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? > ? ? ; ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ; ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ; ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ; ? ? ? ? ? ? ? ? ? ? > ? ? ? < ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? -------------------------------------------------------------------------------- /cs400.passes/pong/Makefile: -------------------------------------------------------------------------------- 1 | data_files = 2 | AC = ../assembler/65816asm 3 | 4 | all: pong.smc 5 | test: all; snes9x pong.smc 6 | clean:; rm -f pong.smc 7 | 8 | %.asm: %.c.lisp $(CC); $(CC) < $< > $@ 9 | %.smc: %.asm $(data_files) $(AC); $(AC) $< 10 | $(AC):; cd ../assembler; make 11 | -------------------------------------------------------------------------------- /cs400.passes/pong/pong.h: -------------------------------------------------------------------------------- 1 | ; # WRAM $7E:0000-$7F:FFFF 2 | 3 | ; # Direct Page 4 | ; #Name $00 scratch_pad $10 5 | ; #Name $10 inidisp b 6 | ; #Name $11 objsel b 7 | ; #Name $12 oamadd w 8 | ; #Name $14 bgmode b 9 | ; #Name $15 mosaic b 10 | ; #Name $16 bg1sc b 11 | ; #Name $17 bg2sc b 12 | ; #Name $18 bg3sc b 13 | ; #Name $19 bg4sc b 14 | ; #Name $1A bg12nba b 15 | ; #Name $1B bg34nba b 16 | ; #Name $1C bg1hofs w 17 | ; #Name $1E bg1vofs w 18 | ; #Name $20 bg2hofs w 19 | ; #Name $22 bg2vofs w 20 | ; #Name $24 bg3hofs w 21 | ; #Name $26 bg3vofs w 22 | ; #Name $28 bg4hofs w 23 | ; #Name $2A bg4vofs w 24 | ; #Name $2C vmainc b 25 | ; #Name $2D vmadd w 26 | ; #Name $2F m7sel b 27 | ; #Name $30 m7a w 28 | ; #Name $32 m7b w 29 | ; #Name $34 m7c w 30 | ; #Name $36 m7d w 31 | ; #Name $38 m7x w 32 | ; #Name $3A m7y w 33 | ; #Name $3C cgadd b 34 | ; #Name $3D w12sel b 35 | ; #Name $3E w34sel b 36 | ; #Name $3F wobjsel b 37 | ; #Name $40 wh0 b 38 | ; #Name $41 wh1 b 39 | ; #Name $42 wh2 b 40 | ; #Name $43 wh3 b 41 | ; #Name $44 wbglog b 42 | ; #Name $45 wobjlog b 43 | ; #Name $46 tm b 44 | ; #Name $47 ts b 45 | ; #Name $48 tmw b 46 | ; #Name $49 tsw b 47 | ; #Name $4A cgswsel b 48 | ; #Name $4B cgadsub b 49 | ; #Name $4C coldata_blue b 50 | ; #Name $4D coldata_green b 51 | ; #Name $4E coldata_red b 52 | ; #Name $4F setini b 53 | ; #Name $50 ophct w 54 | ; #Name $52 opvct w 55 | ; #Name $54 stat77 b 56 | ; #Name $55 stat78 b 57 | ; #Name $56 apuio0 b 58 | ; #Name $57 apuio1 b 59 | ; #Name $58 apuio2 b 60 | ; #Name $59 apuio3 b 61 | ; #Name $5A wmadd l 62 | ; #Name $5D nmitimen b 63 | ; #Name $5E wrio b 64 | ; #Name $5F htime w 65 | ; #Name $61 vtime w 66 | ; #Name $63 mdmaen b 67 | ; #Name $64 hdmaen b 68 | ; #Name $65 memsel b 69 | ; #Name $66 rdnmi b 70 | ; #Name $67 timeup b 71 | ; #Name $68 hvbjoy b 72 | ; #Name $69 rdio b 73 | ; #Name $006A joy w[4] 74 | ; #Name $6A joy1 w 75 | ; #Name $6C joy2 w 76 | ; #Name $6E joy3 w 77 | ; #Name $70 joy4 w 78 | 79 | ; #Name $0072 joy.last w[4] 80 | ; #Name $72 joy1.last w 81 | ; #Name $74 joy2.last w 82 | ; #Name $76 joy3.last w 83 | ; #Name $78 joy4.last w 84 | ; #Name $007A joy.edge w[4] 85 | ; #Name $7A joy1.edge w 86 | ; #Name $7C joy2.edge w 87 | ; #Name $7E joy3.edge w 88 | ; #Name $80 joy4.edge w 89 | ; #Name $0082 joy.hold b[4] 90 | ; #Name $82 joy1.hold b 91 | ; #Name $83 joy2.hold b 92 | ; #Name $84 joy3.hold b 93 | ; #Name $85 joy4.hold b 94 | ; #Name $0086 joy.cool b[4] 95 | ; #Name $86 joy1.cool b 96 | ; #Name $87 joy2.cool b 97 | ; #Name $88 joy3.cool b 98 | ; #Name $89 joy4.cool b 99 | 100 | ; #Name $8A Nmi.ready b 101 | ; #Name $8B Nmi.count w 102 | ; #Name $8D Nmi.HDMA.data l 103 | ; #Name $90 Nmi.VRAM_DMA.data l 104 | ; #Name $93 Nmi.VRAM_DMA.data_i w 105 | ; #Name $95 Nmi.VRAM_Write.table_i w 106 | 107 | ; #Name $97 irq_program l 108 | 109 | ; #Name $9A Main.count w 110 | ; #Name $9C Main.program w 111 | ; #Name $9E Sub.program w 112 | 113 | ; #Name $A0 oam_i w 114 | ; #Name $A2 oam2_byte_i b 115 | ; #Name $A3 oam2_bit_i b 116 | 117 | ; #Name $A6 Rng.number w 118 | ; #Name $A8 pause b 119 | 120 | ; # Scratch Pad 121 | 122 | ; #Name $00 Multiply_16.m1 w 123 | ; #Name $02 Multiply_16.m2 w 124 | ; #Name $04 Multiply_16.p w 125 | 126 | ; #Name $00 Divide_16.n w // Numerator 127 | ; #Name $02 Divide_16.d w // Denomenator 128 | ; #Name $04 Divide_16.q w // Quotient 129 | ; #Name $08 Divide_16.r w // Remainder 130 | 131 | ; #Name $00 Draw_Sprite.data_i l 132 | ; #Name $02 Draw_Sprite.data_bank b 133 | ; #Name $03 Draw_Sprite.obj_count b 134 | ; #Name $04 Draw_Sprite.x b 135 | ; #Name $05 Draw_Sprite.y b 136 | ; #Name $06 Draw_Sprite.char_i w 137 | ; #Name $08 Draw_Sprite.obj_p_override b 138 | 139 | 140 | ; # WRAM $7E:0000-$7E:2000============= Size ==== 141 | ; #Name $0100 oam $200 142 | ; #Name $0100 oam.x b 143 | ; #Name $0101 oam.y b 144 | ; #Name $0102 oam.c b 145 | ; #Name $0103 oam.p b 146 | ; #Name $0300 oam2 $20 147 | 148 | ; #Name $0320 cgram $200 149 | 150 | ; #Name $0520 Nmi.VRAM_Write.table $E0 151 | ; #Name $0520 Nmi.VRAM_Write.addr w 152 | ; #Name $0522 Nmi.VRAM_Write.data w 153 | 154 | 155 | ; # Subroutine Prototypes 156 | ; #Code w RESET_Vector 157 | ; #Code w NMI_Vector 158 | ; #Code w IRQ_Vector 159 | ; #Code l Reset 160 | ; #Code w Reset.Registers 161 | ; #Code w Reset.VRAM 162 | ; #Code w Reset.OAM 163 | ; #Code w Reset.CGRAM 164 | ; #Code w Reset.APU 165 | 166 | ; #Code l Nmi.Wait 167 | ; #Code l Nmi 168 | ; #Code w Nmi.Registers 169 | ; #Code w Nmi.HDMA 170 | ; #Code w Nmi.VRAM_DMA 171 | ; #Code w Nmi.VRAM_Write 172 | 173 | ; #Code l Irq 174 | 175 | ; #Code l Main 176 | ; #Data w Main.programs 177 | ; #Code w Engine.Initiate 178 | ; #Code w Engine.Fadein 179 | ; #Code w Engine.Run 180 | ; #Code w Test_Joy 181 | ; #Code w Pause 182 | 183 | ; #Code w Ship 184 | ; #Data w Ship.programs 185 | 186 | ; #Code l Multiply_16 187 | ; #Code l Divide 188 | ; #Code l Immediate_DMA 189 | ; #Code l Ready_Oam 190 | ; #Code l Hide_Unused_Oam 191 | ; #Code l Draw_Sprite 192 | ; #Code l Rng 193 | 194 | ; #Data w ship_1_sprite 195 | ; #Data w ship_2_sprite 196 | ; #Data l sinusoid 197 | ; #Data l char_set 198 | ; #Data l frame_map 199 | ; #Data l floor_map 200 | ; #Data l color_set 201 | ; #Data l rom_header 202 | ; #Data l vector_table 203 | -------------------------------------------------------------------------------- /cs400.passes/pong/snes-registers.h: -------------------------------------------------------------------------------- 1 | ; # SNES Registers 2 | ; #Name $2100 INIDISP b 3 | ; #Name $2101 OBJSEL b 4 | ; #Name $2102 OAMADD w 5 | ; #Name $2104 OAMDATA b,LH 6 | ; #Name $2105 BGMODE b 7 | ; #Name $2106 MOSAIC b 8 | ; #Name $2107 BG1SC b 9 | ; #Name $2108 BG2SC b 10 | ; #Name $2109 BG3SC b 11 | ; #Name $210A BG4SC b 12 | ; #Name $210B BG12NBA b 13 | ; #Name $210C BG34NBA b 14 | ; #Name $210D BG1HOFS b,LH 15 | ; #Name $210E BG1VOFS b,LH 16 | ; #Name $210F BG2HOFS b,LH 17 | ; #Name $2110 BG2VOFS b,LH 18 | ; #Name $2111 BG3HOFS b,LH 19 | ; #Name $2112 BG3VOFS b,LH 20 | ; #Name $2113 BG4HOFS b,LH 21 | ; #Name $2114 BG4VOFS b,LH 22 | ; #Name $2115 VMAINC b 23 | ; #Name $2116 VMADD w 24 | ; #Name $2118 VMDATA w 25 | ; #Name $211A M7SEL b 26 | ; #Name $211B M7A b,LH 27 | ; #Name $211C M7B b,LH 28 | ; #Name $211D M7C b,LH 29 | ; #Name $211E M7D b,LH 30 | ; #Name $211F M7X b,LH 31 | ; #Name $2120 M7Y b,LH 32 | ; #Name $2121 CGADD b 33 | ; #Name $2122 CGDATA b,LH 34 | ; #Name $2123 W12SEL b 35 | ; #Name $2124 W34SEL b 36 | ; #Name $2125 WOBJSEL b 37 | ; #Name $2126 WH0 b 38 | ; #Name $2127 WH1 b 39 | ; #Name $2128 WH2 b 40 | ; #Name $2129 WH3 b 41 | ; #Name $212A WBGLOG b 42 | ; #Name $212B WOBJLOG b 43 | ; #Name $212C TM b 44 | ; #Name $212D TS b 45 | ; #Name $212E TMW_ b 46 | ; #Name $212F TSW_ b 47 | ; #Name $2130 CGSWSEL b 48 | ; #Name $2131 CGADSUB b 49 | ; #Name $2132 COLDATA b 50 | ; #Name $2133 SETINI b 51 | ; #Name $2134 RDMPY24 l,ro 52 | ; #Name $2137 SLHV b,ro 53 | ; #Name $2138 RDOAMDATA b,ro,LH 54 | ; #Name $2139 RDVMDATA w,ro 55 | ; #Name $213B RDCGDATA b,ro,LH 56 | ; #Name $213C OPHCT b,ro,LH 57 | ; #Name $213D OPVCT b,ro,LH 58 | ; #Name $213E STAT77 b,ro 59 | ; #Name $213F STAT78 b,ro 60 | ; #Name $2140 APUIO0 b 61 | ; #Name $2141 APUIO1 b 62 | ; #Name $2142 APUIO2 b 63 | ; #Name $2143 APUIO3 b 64 | ; #Name $2180 WMDATA b 65 | ; #Name $2181 WMADD l 66 | ; #Name $4016 JOYIO w 67 | ; #Name $4200 NMITIMEN b 68 | ; #Name $4201 WRIO b 69 | ; #Name $4202 WRMPYA b 70 | ; #Name $4203 WRMPYB b 71 | ; #Name $4204 WRDIVA w 72 | ; #Name $4206 WRDIVB b 73 | ; #Name $4207 HTIME w 74 | ; #Name $4209 VTIME w 75 | ; #Name $420B MDMAEN b 76 | ; #Name $420C HDMAEN b 77 | ; #Name $420D MEMSEL b 78 | ; #Name $4210 RDNMI b,ro 79 | ; #Name $4211 TIMEUP b,ro 80 | ; #Name $4212 HVBJOY b,ro 81 | ; #Name $4213 RDIO b,ro 82 | ; #Name $4214 RDDIV w,ro 83 | ; #Name $4216 RDMPY16 w,ro 84 | ; #Name $4218 JOY1 w 85 | ; #Name $421A JOY2 w 86 | ; #Name $421C JOY3 w 87 | ; #Name $421E JOY4 w 88 | ; #Name $4300 DMAP b 89 | ; #Name $4301 DMAB b 90 | ; #Name $4302 DMAA l 91 | ; #Name $4305 DMAD l 92 | ; #Name $4308 DMAI w 93 | ; #Name $430A DMAL b 94 | ; #Name $4300 DMAP0 b 95 | ; #Name $4301 DMAB0 b 96 | ; #Name $4302 DMAA0 l 97 | ; #Name $4305 DMAD0 l 98 | ; #Name $4308 DMAI0 w 99 | ; #Name $430A DMAL0 b 100 | ; #Name $4310 DMAP1 b 101 | ; #Name $4311 DMAB1 b 102 | ; #Name $4312 DMAA1 l 103 | ; #Name $4315 DMAD1 l 104 | ; #Name $4318 DMAI1 w 105 | ; #Name $431A DMAL1 b 106 | ; #Name $4320 DMAP2 b 107 | ; #Name $4321 DMAB2 b 108 | ; #Name $4322 DMAA2 l 109 | ; #Name $4325 DMAD2 l 110 | ; #Name $4328 DMAI2 w 111 | ; #Name $432A DMAL2 b 112 | ; #Name $4330 DMAP3 b 113 | ; #Name $4331 DMAB3 b 114 | ; #Name $4332 DMAA3 l 115 | ; #Name $4335 DMAD3 l 116 | ; #Name $4338 DMAI3 w 117 | ; #Name $433A DMAL3 b 118 | ; #Name $4340 DMAP4 b 119 | ; #Name $4341 DMAB4 b 120 | ; #Name $4342 DMAA4 l 121 | ; #Name $4345 DMAD4 l 122 | ; #Name $4348 DMAI4 w 123 | ; #Name $434A DMAL4 b 124 | ; #Name $4350 DMAP5 b 125 | ; #Name $4351 DMAB5 b 126 | ; #Name $4352 DMAA5 l 127 | ; #Name $4355 DMAD5 l 128 | ; #Name $4358 DMAI5 w 129 | ; #Name $435A DMAL5 b 130 | ; #Name $4360 DMAP6 b 131 | ; #Name $4361 DMAB6 b 132 | ; #Name $4362 DMAA6 l 133 | ; #Name $4365 DMAD6 l 134 | ; #Name $4368 DMAI6 w 135 | ; #Name $436A DMAL6 b 136 | ; #Name $4370 DMAP7 b 137 | ; #Name $4371 DMAB7 b 138 | ; #Name $4372 DMAA7 l 139 | ; #Name $4375 DMAD7 l 140 | ; #Name $4378 DMAI7 w 141 | ; #Name $437A DMAL7 b 142 | -------------------------------------------------------------------------------- /cs400.passes/pong/temp.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/pong/temp.tar -------------------------------------------------------------------------------- /cs400.passes/pong/temp.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/cs400.passes/pong/temp.tgz -------------------------------------------------------------------------------- /cs400.passes/pong/toplevel.asm: -------------------------------------------------------------------------------- 1 | ; #LoROM 2 | ; #File interrupt.asm 3 | ; #File pong.asm 4 | 5 | {$0000 $0000 $8000 $8000 $8000 $8007 $0000 $8000 6 | $0000 $0000 $8000 $0000 $8000 $8000 $8000 $8000} 7 | -------------------------------------------------------------------------------- /jormungandr/JormungandrChar.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/jormungandr/JormungandrChar.dat -------------------------------------------------------------------------------- /jormungandr/JormungandrColor.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/jormungandr/JormungandrColor.dat -------------------------------------------------------------------------------- /jormungandr/JormungandrFloorMap.dat: -------------------------------------------------------------------------------- 1 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -------------------------------------------------------------------------------- /jormungandr/JormungandrFrameMap.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/jormungandr/JormungandrFrameMap.dat -------------------------------------------------------------------------------- /jormungandr/JormungandrTrailMap.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/jormungandr/JormungandrTrailMap.dat -------------------------------------------------------------------------------- /jormungandr/jormungandr.srm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/jormungandr/jormungandr.srm -------------------------------------------------------------------------------- /jormungandr/mkfile: -------------------------------------------------------------------------------- 1 | data = `{echo *.dat} 2 | 3 | all:V: jormungandr.smc 4 | clean:V: 5 | rm -f jormungandr.smc 6 | test:V: all 7 | bsnes jormungandr.smc 8 | 9 | jormungandr.smc: $data jormungandr.asm 10 | 65816a jormungandr.asm 11 | -------------------------------------------------------------------------------- /pallet/pallet.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/pallet/pallet.xls -------------------------------------------------------------------------------- /pallet/palletBgmap.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/pallet/palletBgmap.dat -------------------------------------------------------------------------------- /pallet/palletChar.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/pallet/palletChar.dat -------------------------------------------------------------------------------- /pallet/palletPallet.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/pallet/palletPallet.dat -------------------------------------------------------------------------------- /pallet/pongChar.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/pallet/pongChar.dat -------------------------------------------------------------------------------- /pallet/pongFrame.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/pallet/pongFrame.dat -------------------------------------------------------------------------------- /pallet/pongPallet.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/pallet/pongPallet.dat -------------------------------------------------------------------------------- /phoenix/char.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/phoenix/char.dat -------------------------------------------------------------------------------- /phoenix/color.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/phoenix/color.dat -------------------------------------------------------------------------------- /phoenix/frame_bg_map.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsummer4/snes/bb044152f4793a1535c964169f2f594396b44a55/phoenix/frame_bg_map.dat -------------------------------------------------------------------------------- /phoenix/mkfile: -------------------------------------------------------------------------------- 1 | data = `{echo *.dat} 2 | 3 | all:V: phoenix.smc 4 | clean:V: 5 | rm -f phoenix.smc 6 | test:V: all 7 | bsnes phoenix.smc 8 | 9 | phoenix.smc: $data phoenix.asm 10 | 65816a phoenix.asm 11 | -------------------------------------------------------------------------------- /phoenix/star_bg_map.dat: -------------------------------------------------------------------------------- 1 | ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? = ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? < ; ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ; ? ? ? ? ? ? = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < > ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < = ? ? ? ? ? ? ? ? ; ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? = ? ? < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? > ? ? ; ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ; ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; < ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ; ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ; ? ? ? ? ? ? ? ? ? ? > ? ? ? < ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ; ? ? ? ? ? ? ? ? ? ? ? > ? ? ? ? ? ? ? --------------------------------------------------------------------------------