From a79e318bcd105d07278e2581cb564a7782033788 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Mon, 3 Dec 2018 01:46:48 +0100 Subject: [PATCH] Working on Tetris. Implemented line removal. Fixed fragment error and added 2 missing fragments. --- ...c1_derefidx_vbuxx=pbuc1_derefidx_vbuyy.asm | 2 + ...c1_derefidx_vbuyy=pbuc1_derefidx_vbuxx.asm | 2 + src/main/fragment/vbuyy=vbuaa_minus_1.asm | 2 +- .../java/dk/camelot64/kickc/CompileLog.java | 4 +- .../dk/camelot64/kickc/test/TestPrograms.java | 2 +- src/test/kc/examples/tetris/tetris.kc | 53 ++++++++++++++++++- 6 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 src/main/fragment/pbuc1_derefidx_vbuxx=pbuc1_derefidx_vbuyy.asm create mode 100644 src/main/fragment/pbuc1_derefidx_vbuyy=pbuc1_derefidx_vbuxx.asm diff --git a/src/main/fragment/pbuc1_derefidx_vbuxx=pbuc1_derefidx_vbuyy.asm b/src/main/fragment/pbuc1_derefidx_vbuxx=pbuc1_derefidx_vbuyy.asm new file mode 100644 index 000000000..e8996ae51 --- /dev/null +++ b/src/main/fragment/pbuc1_derefidx_vbuxx=pbuc1_derefidx_vbuyy.asm @@ -0,0 +1,2 @@ +lda {c1},y +sta {c1},x \ No newline at end of file diff --git a/src/main/fragment/pbuc1_derefidx_vbuyy=pbuc1_derefidx_vbuxx.asm b/src/main/fragment/pbuc1_derefidx_vbuyy=pbuc1_derefidx_vbuxx.asm new file mode 100644 index 000000000..d7368c247 --- /dev/null +++ b/src/main/fragment/pbuc1_derefidx_vbuyy=pbuc1_derefidx_vbuxx.asm @@ -0,0 +1,2 @@ +lda {c1},x +sta {c1},y \ No newline at end of file diff --git a/src/main/fragment/vbuyy=vbuaa_minus_1.asm b/src/main/fragment/vbuyy=vbuaa_minus_1.asm index b9acd1471..20ed22a33 100644 --- a/src/main/fragment/vbuyy=vbuaa_minus_1.asm +++ b/src/main/fragment/vbuyy=vbuaa_minus_1.asm @@ -1,2 +1,2 @@ -tya +tay dey \ No newline at end of file diff --git a/src/main/java/dk/camelot64/kickc/CompileLog.java b/src/main/java/dk/camelot64/kickc/CompileLog.java index e90400437..732a94814 100644 --- a/src/main/java/dk/camelot64/kickc/CompileLog.java +++ b/src/main/java/dk/camelot64/kickc/CompileLog.java @@ -20,7 +20,7 @@ public class CompileLog { /** * Should fragment synthesis be verbose. */ - private boolean verboseFragmentLog = false; + private boolean verboseFragmentLog = true; /** * Should ASM optimization be verbose. @@ -66,7 +66,7 @@ public class CompileLog { /** * Should the log be output to System.out while being built */ - private boolean sysOut = false; + private boolean sysOut = true; public CompileLog() { this.log = new StringBuilder(); diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index a48653ab0..af4be820e 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -41,7 +41,7 @@ public class TestPrograms { public static void tearDown() { CompileLog log = new CompileLog(); log.setSysOut(true); - AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false); + AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, true, true); } @Test diff --git a/src/test/kc/examples/tetris/tetris.kc b/src/test/kc/examples/tetris/tetris.kc index f93b3b2d5..e67e8d9d3 100644 --- a/src/test/kc/examples/tetris/tetris.kc +++ b/src/test/kc/examples/tetris/tetris.kc @@ -16,6 +16,9 @@ byte[PLAYFIELD_LINES*PLAYFIELD_COLS] playfield; // Pointers to the playfield address for each playfield line byte*[PLAYFIELD_LINES] playfield_lines; +// Indixes into the playfield for each playfield line +byte[PLAYFIELD_LINES+1] playfield_lines_idx; + // The current moving piece. Points to the start of the piece definition. byte* current_piece = 0; @@ -105,6 +108,8 @@ byte play_move_down(byte key_event) { } else { // Lock current piece lock_current(); + // Check for new lines + remove_lines(); // Spawn a new piece spawn_current(); } @@ -232,6 +237,48 @@ void spawn_current() { current_piece_color = PIECES_COLORS[piece_idx]; } +// Look through the playfield for lines - and remove any lines found +void remove_lines() { + byte done = 0; + do { + byte line_ypos = find_line(); + if(line_ypos!=$ff) { + remove_line(line_ypos); + } else { + done = 1; + } + } while(done==0); +} + +// Look through the playfield for lines - and return the ypos of any filled line. +// Returns $ff if no line was found +byte find_line() { + byte i = 0; + for(byte y:0..PLAYFIELD_LINES-1) { + byte filled = 1; + for(byte x:0..PLAYFIELD_COLS-1) { + if(playfield[i++]==0) { + filled = 0; + } + } + if(filled==1) { + return y; + } + } + return $ff; +} + +// Remove a single line by scrolling all lines above it down and emptying the top line +void remove_line(byte ypos) { + byte i2 = playfield_lines_idx[ypos+1]-1; + byte i1 = playfield_lines_idx[ypos]-1; + for(byte y=ypos;y!=1;y--) { + for(byte x:0..PLAYFIELD_COLS-1) { + playfield[i2--] = playfield[i1--]; + } + } +} + // Initialize the screen and data tables void init() { // Clear the screen @@ -244,11 +291,15 @@ void init() { li += 40; } // Initialize the playfield line pointers; + byte idx = 0; byte* pli = playfield; for(byte j:0..PLAYFIELD_LINES-1) { playfield_lines[j<<1] = pli; - pli += 10; + playfield_lines_idx[j] = idx; + pli += PLAYFIELD_COLS; + idx += PLAYFIELD_COLS; } + playfield_lines_idx[PLAYFIELD_LINES] = PLAYFIELD_COLS*PLAYFIELD_LINES; // Prepare the playfield frame byte* line = COLS + 14; for(byte l:0..PLAYFIELD_LINES+1) {