{"id":19297337,"url":"https://github.com/RevCurtisP/C02","last_synced_at":"2025-04-22T09:30:46.364Z","repository":{"id":82216718,"uuid":"119288438","full_name":"RevCurtisP/C02","owner":"RevCurtisP","description":"C syntax compiler optimized for the 6502 microprocessor","archived":false,"fork":false,"pushed_at":"2023-04-02T19:00:05.000Z","size":2612,"stargazers_count":54,"open_issues_count":1,"forks_count":9,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-11-09T23:02:29.040Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RevCurtisP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-28T19:02:40.000Z","updated_at":"2023-12-08T14:01:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"f28873ed-8eb0-4438-a206-43734a583d0d","html_url":"https://github.com/RevCurtisP/C02","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RevCurtisP%2FC02","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RevCurtisP%2FC02/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RevCurtisP%2FC02/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RevCurtisP%2FC02/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RevCurtisP","download_url":"https://codeload.github.com/RevCurtisP/C02/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250215003,"owners_count":21393707,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T23:01:51.986Z","updated_at":"2025-04-22T09:30:46.359Z","avatar_url":"https://github.com/RevCurtisP.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"![C02 6502 Compiler](https://github.com/RevCurtisP/C02/raw/master/art/logo.png)\n\nC02 is a simple C-syntax language designed to generate highly optimized\ncode for the 6502 microprocessor. The C02 specification is a highly\nspecific subset of the C standard with some modifications and extensions\n\nThe compiler generates assembly language code, currently targeted to the DASM assembler.\n\nSee the top-level [documentation](doc/c02.txt) for more information.\n\n## Building the Compiler\nIn Linux, use gcc and the [Makefile](./Makefile).\n\nIn Windows use the [Pelles C IDE](http://www.smorgasbordet.com/pellesc/) and the file [./C02.ppj](c02.ppj).\n\n## Compiling C02 programs\nAt a command line, cd into the appropriate directory, e.g. [py65](py65/) or [vic20](vic20/).\n\nExecute the c02 compiler from the parent directory using the c02 source file (without the .c02 extension) as an argument.\n\nFor example, to compile the program [conds.c02](py65/conds.c02), in the [py65](py65/) directory, use the command\n\n    ../c02 conds\n\nin Linux, or\n\n    ..\\c02 conds\n\nin Windows.\n \nSome of the subdirectories contain a c02.bat file, which will compile \nthe .c02 program, then run dasm to assemble the code. However, the path \nto dasm is hardcoded, so you will likely need to change it.\n\nThe file [c02.sh](./c02sh) provides the same functionality in Linux, \nbut it may not be in a working state.\n\n## Syntax Examples\n```\n/* Directives */\n#include \u003cheader.h02\u003e   //Include header from standard library\n#include \"inc/hdr.h02\"  //Include header from local directory\n#pragma origin 8192     //Set start address of object code\n#pragma zeropage $80    //Set start address of zero page variables \n\n/* Constants */\n#define TRUE = $FF ; //Constants\n#define FALSE = 0\nenum {BLACK, WHITE, RED, CYAN, PURPLE, GREEN, BLUE, YELLOW}; \n\n/* Structures */\nstruct record {char name[8]; char index;}; //Struct Definition\nstruct record rec;                         //Struct Declaration\n\n/* Variables and Array Declarations */\nchar b, c, d, e, f, g, h;    //8-bit Variables \nint i, j;                    //16-bit Variables\nzeropage char p, q;          //8-bit Variables in Page 0\nzeropage int u, v;           //16-bit Variables in Page 0\nconst char nine = 9;         //Const 8-bit variable set to decimal literal\nconst char maxsiz = $FF;     //Const 8-bit variable set to hexadecimal literal\nconst char flag = %01010101; //Const 8-bit variable set to binary literal\nconst char debug = #TRUE;    //Const 8-bit variable set to constant\nconst int k = $1234;         //Const 16-bit variable set to hexadecimal literal\nchar r[7];                   //8 byte Array (decimal dimension)\naligned char m[$FF];         //256 byte array aligned to page boundary\nconst char n = {1,2,3};      //Const array set to literal list\nconst char s = \"string\";     //Const array set to string literal\nconst char t = {\"one\", 1);   //Const array set to mixed list\n\n/* Functions Declarations */\nvoid myfunc(); //Forward declaration of function\nchar fnc(c) { /*function body */}     //One 8-bit Parameter\nchar fnd(c,d) { /*function body */}   //Two 8-bit Parameters\nchar fne(c,d,e) { /*function body */} //Three 8-bit Parameters\nchar fni(i) { /*function body */}     //One 16-bit Parameter\nchar fnj(c,i) { /*function body */}   //8-bit and 16-bit Parameters\n\n/* Returning from a Function */\nreturn c, d, e;    //Return up to three 8-bit values\nreturn c,j;        //Return an 8-bit an 16-bit value\nreturn i;          //Return a 16-bit value\nreturn;            //No explicit return values\n\n/* Assignments */\nhmove; s80vid;               //Implicit Assignments\nx = 0; y = a; a = 1;         //Register Assignments\nb = c + d - e \u0026 f | g ^ h;   //Assignment and Expression\nr[f] = m[g+1] \u0026 t[h-1];      //Array Indexing\nr[j] = r[a] + s[x] + t[y];   //Arrays Indexed by Register\nd = (e\u003ef) ? d[e] : e[f];     //Shortcut If\nb\u003c\u003c ;c[d]\u003e\u003e; x++; y--;       //Post-Operations\n\n/* Function Calls */\nb = abs(c); d = min(e,f), plot(b,c,d); //Up to Three Char Arguments\nb = div(c+d,e)) - f; c = mult(d+e, f); //Expression in First Arg Only \nj = swap(i); j = ishift(b, i);         //Pass Int or Char with Int\nputs(\"string\"); fputs(f, \u0026s);          //Passing Strings and Arrays\nsetdst(\u0026r); b = strcpy(\u0026s);            //Using Multiple String Arguments\nproc(@record, \u0026record);                //Pass Length and Address of Struct\nc = getc(); setptr(?,g,h);             //No Args and Skipped Arguments\nb,c = scnpos(); d,e,f = get3d();       //Plural Assignments\npush b,c; mult(); pop p;               //Pass Arguments via Stack\niprint(); inline \"Hello World\";        //Pass Inline String Argument\nirect(); inline 10,10,100,100;         //Pass Inline Char Arguments\nicpstr(); inline \u0026r, \u0026s;               //Pass Inline Address Arguments\n\n/* Control Structures */\nif (c = 27) goto end;\nif (b) e = div(f,g) else puts(\"Division by 0!\");\nif (b==0 || b\u003e10 \u0026\u0026 b\u003c20) fprint(n,\"input %d in range\"); \nc = 'A' ; while (c \u003c= 'Z') { putc(c); c++; }\nwhile() { c=rdkey; if (c=0) continue; putchr(c); if (c=13) break; }\ndo c = rdkey(); while (c=0);\ndo {c = getchr(); putchr(c);} while (c\u003c\u003e13)\nfor (c='A'; c\u003c='Z'; c++) putc(c);\nfor (i=strlen(s)-1;i:+;i--) putc(s[i]);\nfor (i=0;c\u003e0;i++) { c=getc(); s[i]=c }\nselect (getc()) {\n  case $0D: putln(\"The Enter key\");\n  case #ESCKEY: if (#NOESC) break; goto escape; \n  case 'A','a': putln (\"The letter A\");\n  default: putln(\"some other key\");\n}\nend: //Label\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRevCurtisP%2FC02","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRevCurtisP%2FC02","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRevCurtisP%2FC02/lists"}