This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Peephole optimization definitions | |
| // Simple assign-back | |
| SET A, B / SET B, A => SET A, B; | |
| // Stack assign-back | |
| SET "PUSH", A / SET A, "PEEK" => SET "PUSH", A; | |
| // Preserve-pop | |
| SET "PUSH", A / ADD "SP", "0x0001" => ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; var a = fib(6); | |
| SET A, 0x0006 | |
| JSR L1fib | |
| SET PUSH, A | |
| :L0main_footer | |
| SUB PC, 0x0001 | |
| ;DCPUC FUNCTION fib L1fib 1 | |
| ; function fib(n) | |
| :L1fib | |
| ; if (2 > n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| namespace DCPUC.Emulator | |
| { | |
| public enum Registers | |
| { | |
| A = 0, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct num32 | |
| { | |
| high; | |
| low; | |
| } | |
| function compare32(a:num32, b:num32) | |
| { | |
| if (a.high != b.high) return 0; | |
| if (a.low != b.low) return 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef DCPUC_DEFAULT_ENVIRONMENT | |
| #define DCPUC_DEFAULT_ENVIRONMENT | |
| #include lem.dc | |
| #include console.dc | |
| static lem; | |
| lem = detect_lem(); //Find a lem screen | |
| static lem_vram; | |
| lem_vram = __endofprogram; //Stick video ram at the end of the program. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SET J, SP | |
| ; Entering blocknode emit | |
| ; bypassed | |
| ; static lem_hardware_id[2] = { 0x7349, 0xf615 }; | |
| ; constant lem_vram_size = 384; | |
| ; constant console_size = 384; | |
| ; constant console_width = 32; | |
| ; static lem; | |
| ; lem = detect_lem(); | |
| JSR L6detect_lem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local screen = 0x8000; // This won't actually work without a lem device already initialized | |
| local hello = "Hello World!"; | |
| local i = 0; | |
| while (i < *hello) | |
| { | |
| screen[i] = 0xF000 | hello[i + 1]; | |
| i += 1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SET J, SP | |
| ; Entering blocknode emit | |
| ; bypassed | |
| ; static LEM_HARDWARE_ID[2] = { 0x7349, 0xf615 }; | |
| ; constant LEM_VRAM_SIZE = 384; | |
| ; constant CONSOLE_SIZE = 384; | |
| ; constant CONSOLE_WIDTH = 32; | |
| ; constant CONSOLE_HEIGHT = 12; | |
| ; static generic_keyboard_id[2] = { 0x30cf, 0x7406 }; | |
| ; local allocatable_memory = __endofprogram; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (lastarg | |
| (defun make-segment ^((arg route)(arg miles)(arg rboxes)(arg cboxes)) (record (route route ) (miles miles ) (rb rboxes ) (cb cboxes ) ) "Script-defined function") | |
| (defun make-route ^((arg number)(arg bf)(arg lf)(arg m)(arg r)(arg c)) (let ((route (record (n number ) (bf bf ) (lf lf ) ) ) ) (lastarg (set route segments ^((make-segment route m r c ) ) ) route ) ) "Script-defined function") | |
| (defun segment-value ^((arg segment)) (+ (* segment.miles 12.0 ) (* segment.rb (+ segment.route.bf segment.route.lf ) ) ) "Script-defined function") | |
| (defun proute ^((arg r)) (nop (printf "Route {0,3} BF:{1} LF:{2} Total Value:{3}\n" r.n r.bf r.lf (route-value r ) ) (mapi s r.segments (nop (printf "{0} - " s ) (psegment (index r.segments s ) ) ) ) ) "Script-defined function") | |
| (defun route-value ^((arg route)) (+ $(map seg route.segments (segment-value seg ) ) ) "Script-defined function") | |
| (defun psegment ^((arg s)) (printf "{0,5} : {1} | MILES:{2} RB:{3} CB:{4}\n" (segment-value s ) s.comment s.miles s.rb s.cb ) "Scrip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef DCPUB_LIB_FIXED | |
| #define DCPUC_LIB_FIXED | |
| #define fix_to_int(a) ((a) >> 8) | |
| #define fix_from_int(a) ((a) << 8) | |
| #define fix_add(a, b) ((a) + (b)) | |
| #define fix_sub(a, b) ((a) - (b)) | |
| function fix_mul(a, b) | |
| { |