From 64db016dc2fc75a5ff9c0da0471fe7a25333ee40 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Wed, 8 Jul 2020 01:06:39 +0200 Subject: [PATCH] Added working lazynes scroll.c --- .../fragment/cache/fragment-cache-mos6502.asm | 2 +- .../cache/fragment-cache-mos6502x.asm | 60 +++++++++---------- .../mos6502-common/vwum1=vwum1_plus_vbsaa.asm | 13 ++++ .../dk/camelot64/kickc/parser/KickCLexer.java | 4 +- .../camelot64/kickc/parser/KickCParser.java | 4 +- .../kickc/parser/KickCParserBaseListener.java | 2 +- .../kickc/parser/KickCParserBaseVisitor.java | 2 +- .../kickc/parser/KickCParserListener.java | 2 +- .../kickc/parser/KickCParserVisitor.java | 2 +- src/test/kc/complex/lazynes/lazynes.c | 26 +++++--- src/test/kc/complex/lazynes/lazynes.h | 18 +++--- src/test/kc/complex/lazynes/scroll.c | 46 ++++++++++++++ 12 files changed, 122 insertions(+), 59 deletions(-) create mode 100644 src/main/fragment/mos6502-common/vwum1=vwum1_plus_vbsaa.asm create mode 100644 src/test/kc/complex/lazynes/scroll.c diff --git a/src/main/fragment/cache/fragment-cache-mos6502.asm b/src/main/fragment/cache/fragment-cache-mos6502.asm index c8f402d23..06affc4ac 100644 --- a/src/main/fragment/cache/fragment-cache-mos6502.asm +++ b/src/main/fragment/cache/fragment-cache-mos6502.asm @@ -1,4 +1,4 @@ -//KICKC FRAGMENT CACHE 160b017651 +//KICKC FRAGMENT CACHE 160b015f22 //FRAGMENT vbuz1=vbuc1 lda #{c1} sta {z1} diff --git a/src/main/fragment/cache/fragment-cache-mos6502x.asm b/src/main/fragment/cache/fragment-cache-mos6502x.asm index c33dbfbda..9c251b42d 100644 --- a/src/main/fragment/cache/fragment-cache-mos6502x.asm +++ b/src/main/fragment/cache/fragment-cache-mos6502x.asm @@ -1,9 +1,34 @@ -//KICKC FRAGMENT CACHE 160b017651 -//FRAGMENT _deref_pbuc1=_inc__deref_pbuc1 -inc {c1} +//KICKC FRAGMENT CACHE 160b015f22 //FRAGMENT vbuz1=vbuc1 lda #{c1} sta {z1} +//FRAGMENT pbuc1_derefidx_vbuz1=_inc_pbuc1_derefidx_vbuz1 +ldx {z1} +inc {c1},x +//FRAGMENT vbuz1=_inc_vbuz1 +inc {z1} +//FRAGMENT pbuc1_derefidx_vbuaa=_inc_pbuc1_derefidx_vbuaa +tax +inc {c1},x +//FRAGMENT pbuc1_derefidx_vbuxx=_inc_pbuc1_derefidx_vbuxx +inc {c1},x +//FRAGMENT vbuaa=vbuc1 +lda #{c1} +//FRAGMENT vbuaa=_inc_vbuaa +clc +adc #1 +//FRAGMENT vbuxx=vbuc1 +ldx #{c1} +//FRAGMENT vbuxx=_inc_vbuxx +inx +//FRAGMENT vbuyy=vbuc1 +ldy #{c1} +//FRAGMENT pbuc1_derefidx_vbuyy=_inc_pbuc1_derefidx_vbuyy +tya +tax +inc {c1},x +//FRAGMENT vbuyy=_inc_vbuyy +iny //FRAGMENT pbuz1=pbuc1 lda #<{c1} sta {z1} @@ -45,8 +70,6 @@ lda {z2} sta {z1} lda {z2}+1 sta {z1}+1 -//FRAGMENT vbuz1=_inc_vbuz1 -inc {z1} //FRAGMENT vbuz1_neq_vbuc1_then_la1 lda #{c1} cmp {z1} @@ -255,12 +278,6 @@ tay txa and #{c1} tay -//FRAGMENT vbuaa=vbuc1 -lda #{c1} -//FRAGMENT vbuxx=vbuc1 -ldx #{c1} -//FRAGMENT vbuyy=vbuc1 -ldy #{c1} //FRAGMENT vbuaa=pbuc1_derefidx_vbuxx lda {c1},x //FRAGMENT vbuaa=pbuc1_derefidx_vbuyy @@ -1280,10 +1297,6 @@ ldy {z1}+1 //FRAGMENT vbuyy=vbuaa_band_vbuc1 and #{c1} tay -//FRAGMENT vbuxx=_inc_vbuxx -inx -//FRAGMENT vbuyy=_inc_vbuyy -iny //FRAGMENT vbuyy_neq_vbuc1_then_la1 cpy #{c1} bne {la1} @@ -1601,9 +1614,6 @@ sta {c1},x //FRAGMENT vbuaa_neq_vbuc1_then_la1 cmp #{c1} bne {la1} -//FRAGMENT vbuaa=_inc_vbuaa -clc -adc #1 //FRAGMENT _deref_pbuc1=_deref_pbuc1_bor_vbuc2 lda #{c2} ora {c1} @@ -1613,6 +1623,8 @@ lda #<{c2} sta {c1} lda #>{c2} sta {c1}+1 +//FRAGMENT _deref_pbuc1=_inc__deref_pbuc1 +inc {c1} //FRAGMENT _deref_pbuc1_lt_vbuc2_then_la1 lda {c1} cmp #{c2} @@ -8006,9 +8018,6 @@ ldy {z1} lda {c1},y cmp #{c2} beq {la1} -//FRAGMENT pbuc1_derefidx_vbuz1=_inc_pbuc1_derefidx_vbuz1 -ldx {z1} -inc {c1},x //FRAGMENT pbuc1_derefidx_vbuaa_eq_vbuc2_then_la1 tay lda {c1},y @@ -8022,12 +8031,6 @@ beq {la1} lda {c1},y cmp #{c2} beq {la1} -//FRAGMENT pbuc1_derefidx_vbuxx=_inc_pbuc1_derefidx_vbuxx -inc {c1},x -//FRAGMENT pbuc1_derefidx_vbuyy=_inc_pbuc1_derefidx_vbuyy -tya -tax -inc {c1},x //FRAGMENT vduz1=vduc1_plus_vbuz2 lda {z2} clc @@ -13791,9 +13794,6 @@ lda {z1} sta {c1} lda {z1}+1 sta {c1}+1 -//FRAGMENT pbuc1_derefidx_vbuaa=_inc_pbuc1_derefidx_vbuaa -tax -inc {c1},x //FRAGMENT vbuaa=vbuaa_bor_vbuc1 ora #{c1} //FRAGMENT vbuz1=_deref_pbuz2_rol_1 diff --git a/src/main/fragment/mos6502-common/vwum1=vwum1_plus_vbsaa.asm b/src/main/fragment/mos6502-common/vwum1=vwum1_plus_vbsaa.asm new file mode 100644 index 000000000..c4e5140d5 --- /dev/null +++ b/src/main/fragment/mos6502-common/vwum1=vwum1_plus_vbsaa.asm @@ -0,0 +1,13 @@ +sta $fe +ora #$7f +bmi !+ +lda #0 +!: +sta $ff +clc +lda {m1} +adc $fe +sta {m1} +lda {m1}+1 +adc $ff +sta {m1}+1 \ No newline at end of file diff --git a/src/main/java/dk/camelot64/kickc/parser/KickCLexer.java b/src/main/java/dk/camelot64/kickc/parser/KickCLexer.java index 7185d42f5..8e2f49230 100644 --- a/src/main/java/dk/camelot64/kickc/parser/KickCLexer.java +++ b/src/main/java/dk/camelot64/kickc/parser/KickCLexer.java @@ -1,4 +1,4 @@ -// Generated from C:/c64/kickc/src/main/java/dk/camelot64/kickc/parser\KickCLexer.g4 by ANTLR 4.7.2 +// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickCLexer.g4 by ANTLR 4.8 package dk.camelot64.kickc.parser; @@ -13,7 +13,7 @@ import org.antlr.v4.runtime.misc.*; @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) public class KickCLexer extends Lexer { - static { RuntimeMetaData.checkVersion("4.7.2", RuntimeMetaData.VERSION); } + static { RuntimeMetaData.checkVersion("4.8", RuntimeMetaData.VERSION); } protected static final DFA[] _decisionToDFA; protected static final PredictionContextCache _sharedContextCache = diff --git a/src/main/java/dk/camelot64/kickc/parser/KickCParser.java b/src/main/java/dk/camelot64/kickc/parser/KickCParser.java index d8f402276..f2cd898de 100644 --- a/src/main/java/dk/camelot64/kickc/parser/KickCParser.java +++ b/src/main/java/dk/camelot64/kickc/parser/KickCParser.java @@ -1,4 +1,4 @@ -// Generated from C:/c64/kickc/src/main/java/dk/camelot64/kickc/parser\KickCParser.g4 by ANTLR 4.7.2 +// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickCParser.g4 by ANTLR 4.8 package dk.camelot64.kickc.parser; @@ -13,7 +13,7 @@ import java.util.ArrayList; @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) public class KickCParser extends Parser { - static { RuntimeMetaData.checkVersion("4.7.2", RuntimeMetaData.VERSION); } + static { RuntimeMetaData.checkVersion("4.8", RuntimeMetaData.VERSION); } protected static final DFA[] _decisionToDFA; protected static final PredictionContextCache _sharedContextCache = diff --git a/src/main/java/dk/camelot64/kickc/parser/KickCParserBaseListener.java b/src/main/java/dk/camelot64/kickc/parser/KickCParserBaseListener.java index a7dca7510..45cde065f 100644 --- a/src/main/java/dk/camelot64/kickc/parser/KickCParserBaseListener.java +++ b/src/main/java/dk/camelot64/kickc/parser/KickCParserBaseListener.java @@ -1,4 +1,4 @@ -// Generated from C:/c64/kickc/src/main/java/dk/camelot64/kickc/parser\KickCParser.g4 by ANTLR 4.7.2 +// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickCParser.g4 by ANTLR 4.8 package dk.camelot64.kickc.parser; diff --git a/src/main/java/dk/camelot64/kickc/parser/KickCParserBaseVisitor.java b/src/main/java/dk/camelot64/kickc/parser/KickCParserBaseVisitor.java index 9e1643e4b..ee6a742a0 100644 --- a/src/main/java/dk/camelot64/kickc/parser/KickCParserBaseVisitor.java +++ b/src/main/java/dk/camelot64/kickc/parser/KickCParserBaseVisitor.java @@ -1,4 +1,4 @@ -// Generated from C:/c64/kickc/src/main/java/dk/camelot64/kickc/parser\KickCParser.g4 by ANTLR 4.7.2 +// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickCParser.g4 by ANTLR 4.8 package dk.camelot64.kickc.parser; diff --git a/src/main/java/dk/camelot64/kickc/parser/KickCParserListener.java b/src/main/java/dk/camelot64/kickc/parser/KickCParserListener.java index 20d6a7925..d6620d9bb 100644 --- a/src/main/java/dk/camelot64/kickc/parser/KickCParserListener.java +++ b/src/main/java/dk/camelot64/kickc/parser/KickCParserListener.java @@ -1,4 +1,4 @@ -// Generated from C:/c64/kickc/src/main/java/dk/camelot64/kickc/parser\KickCParser.g4 by ANTLR 4.7.2 +// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickCParser.g4 by ANTLR 4.8 package dk.camelot64.kickc.parser; diff --git a/src/main/java/dk/camelot64/kickc/parser/KickCParserVisitor.java b/src/main/java/dk/camelot64/kickc/parser/KickCParserVisitor.java index 371af315a..cdefcbd08 100644 --- a/src/main/java/dk/camelot64/kickc/parser/KickCParserVisitor.java +++ b/src/main/java/dk/camelot64/kickc/parser/KickCParserVisitor.java @@ -1,4 +1,4 @@ -// Generated from C:/c64/kickc/src/main/java/dk/camelot64/kickc/parser\KickCParser.g4 by ANTLR 4.7.2 +// Generated from /Users/jespergravgaard/c64/kickc/src/main/java/dk/camelot64/kickc/parser/KickCParser.g4 by ANTLR 4.8 package dk.camelot64.kickc.parser; diff --git a/src/test/kc/complex/lazynes/lazynes.c b/src/test/kc/complex/lazynes/lazynes.c index bbb0cf0f9..babb5b573 100644 --- a/src/test/kc/complex/lazynes/lazynes.c +++ b/src/test/kc/complex/lazynes/lazynes.c @@ -41,6 +41,8 @@ void main() { PPU->PPUCTRL = 0b10001000; // Enable sprite and tile rendering PPU->PPUMASK = 0b00011110; + // Reset scroll + scroll_x = scroll_y = 0; // Execute lazynes main code lnMain(); // Infinite loop @@ -69,13 +71,18 @@ volatile char sync_mode; // Signal when vblank occurs. The NMI sets this to zero. To wait for a vblank set this no non-zero and wait for it to become zero. volatile char vblank_signal; +// Scroll x-position +volatile char scroll_x; +// Scroll y-position +volatile char scroll_y; + // NMI Called when the PPU refreshes the screen (also known as the V-Blank period) interrupt(hardware_stack) void vblank() { // DMA transfer the entire sprite buffer to the PPU ppuSpriteBufferDmaTransfer(SPRITE_BUFFER); // Set scroll - PPU->PPUSCROLL = 0; - PPU->PPUSCROLL = 0; + PPU->PPUSCROLL = scroll_x; + PPU->PPUSCROLL = scroll_y; // count vblanks vblank_count++; // send vblank signal @@ -163,13 +170,14 @@ void lnPush(uword o, ubyte a, void* s) { // x: New horizotnal scrolling offset in pixels, allowed range: [0..511] // y: New vertical scrolling offset in pixels, allowed range: [0..479] // -// TODO: void lnScroll(uword x, uword y); - // - // remarks: - // - If a SPR0HIT based splitscreen is used, the 1st call of lnScroll() sets - // the scrolling offsets of the area above the split and the 2nd call of - // lnScroll() sets the scrolling offsets of the area below the split. - +// remarks: +// - If a SPR0HIT based splitscreen is used, the 1st call of lnScroll() sets +// the scrolling offsets of the area above the split and the 2nd call of +// lnScroll() sets the scrolling offsets of the area below the split. +void lnScroll(uword x, uword y) { + scroll_x = >6,0); // set scrolling offsets of area below split + hVel+=hDir; if (hVel>64 || hVel<-64) hDir=-hDir; + hScroll+=hVel; + lnSync(0); + } + + return 0; +}