Skip to content

Commit

Permalink
linecrunch
Browse files Browse the repository at this point in the history
  • Loading branch information
sehugg committed Oct 15, 2024
1 parent 87ae81c commit ff15581
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
96 changes: 96 additions & 0 deletions presets/c64/linecrunch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

#include "common.h"
//#link "common.c"

#include "rasterirq.h"
//#link "rasterirq.ca65"

#include "bcd.h"
//#link "bcd.c"

extern const unsigned char sinustable[0x100];
//#link "sinustable.c"

///// VARIABLES

byte frame = 0;
byte scroll_y = 0;
byte target_line = 0;

///// FUNCTIONS

void line_crunch() {
// load scroll y
asm("lda %v", scroll_y);
asm("and #7");
asm("ora #$18");
asm("tax");
// get current raster line
asm("lda $d012");
// wait for next raster line
asm("@loop:");
asm("cmp $d012");
asm("beq @loop");
// set y scroll (ctrl1)
asm("stx $d011");
}

void display_list(void) {

// set initial YSCROLL
VIC.ctrl1 = 0x18 | (scroll_y & 7);

// do line crunch?
if (scroll_y < 24) {
// wait for target line
target_line = 47 + (scroll_y & 7);
while (VIC.rasterline != target_line) { }
// increment YSCROLL
scroll_y++;
line_crunch();
// do additional line crunches?
if (scroll_y < 17) {
scroll_y++;
line_crunch();
if (scroll_y < 10) {
scroll_y++;
line_crunch();
}
}
}

VIC.bgcolor[0] = COLOR_CYAN;
VIC.bordercolor = COLOR_BLUE;

DLIST_RESTART(40);
}

void main() {
int i;

clrscr();

memset(COLOR_RAM, COLOR_BLUE, 1000);

for (i=0; i<40*25; i++)
POKE(0x400 + i, 205 + (rand() & 1));
for (i=40*25; i<1024; i++)
POKE(0x400 + i, i);
for (i=0; i<1024; i+=40)
POKE(0x400 + i, 122);

SET_VIC_BITMAP(0x1000);

// setup rasterirq library for scoreboard split
DLIST_SETUP(display_list);

// game loop, repeat forever
while (1) {
// wait for end of frame
waitvsync();

// animate and set scroll_y
frame += 4;
scroll_y = sinustable[frame] >> 3;
}
}
35 changes: 35 additions & 0 deletions presets/c64/sinustable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

const unsigned char sinustable[0x100] = {
0x80, 0x7d, 0x7a, 0x77, 0x74, 0x70, 0x6d, 0x6a,
0x67, 0x64, 0x61, 0x5e, 0x5b, 0x58, 0x55, 0x52,
0x4f, 0x4d, 0x4a, 0x47, 0x44, 0x41, 0x3f, 0x3c,
0x39, 0x37, 0x34, 0x32, 0x2f, 0x2d, 0x2b, 0x28,
0x26, 0x24, 0x22, 0x20, 0x1e, 0x1c, 0x1a, 0x18,
0x16, 0x15, 0x13, 0x11, 0x10, 0x0f, 0x0d, 0x0c,
0x0b, 0x0a, 0x08, 0x07, 0x06, 0x06, 0x05, 0x04,
0x03, 0x03, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03,
0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x0a,
0x0b, 0x0c, 0x0d, 0x0f, 0x10, 0x11, 0x13, 0x15,
0x16, 0x18, 0x1a, 0x1c, 0x1e, 0x20, 0x22, 0x24,
0x26, 0x28, 0x2b, 0x2d, 0x2f, 0x32, 0x34, 0x37,
0x39, 0x3c, 0x3f, 0x41, 0x44, 0x47, 0x4a, 0x4d,
0x4f, 0x52, 0x55, 0x58, 0x5b, 0x5e, 0x61, 0x64,
0x67, 0x6a, 0x6d, 0x70, 0x74, 0x77, 0x7a, 0x7d,
0x80, 0x83, 0x86, 0x89, 0x8c, 0x90, 0x93, 0x96,
0x99, 0x9c, 0x9f, 0xa2, 0xa5, 0xa8, 0xab, 0xae,
0xb1, 0xb3, 0xb6, 0xb9, 0xbc, 0xbf, 0xc1, 0xc4,
0xc7, 0xc9, 0xcc, 0xce, 0xd1, 0xd3, 0xd5, 0xd8,
0xda, 0xdc, 0xde, 0xe0, 0xe2, 0xe4, 0xe6, 0xe8,
0xea, 0xeb, 0xed, 0xef, 0xf0, 0xf1, 0xf3, 0xf4,
0xf5, 0xf6, 0xf8, 0xf9, 0xfa, 0xfa, 0xfb, 0xfc,
0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfe, 0xfd,
0xfd, 0xfc, 0xfb, 0xfa, 0xfa, 0xf9, 0xf8, 0xf6,
0xf5, 0xf4, 0xf3, 0xf1, 0xf0, 0xef, 0xed, 0xeb,
0xea, 0xe8, 0xe6, 0xe4, 0xe2, 0xe0, 0xde, 0xdc,
0xda, 0xd8, 0xd5, 0xd3, 0xd1, 0xce, 0xcc, 0xc9,
0xc7, 0xc4, 0xc1, 0xbf, 0xbc, 0xb9, 0xb6, 0xb3,
0xb1, 0xae, 0xab, 0xa8, 0xa5, 0xa2, 0x9f, 0x9c,
0x99, 0x96, 0x93, 0x90, 0x8c, 0x89, 0x86, 0x83
};
1 change: 1 addition & 0 deletions src/platform/c64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const C64_PRESETS : Preset[] = [
{id:'climber.c', name:'Climber Game'},
{id:'test_border_sprites.c', name:'Sprites in the Borders'},
{id:'sprite_stretch.c', name:'Sprite Stretching'},
{id:'linecrunch.c', name:'Linecrunch'},
{id:'plasma.c', name:'Plasma Demo'},
{id:'23matches.c', name:'23 Matches'},
{id:'tgidemo.c', name:'TGI Graphics Demo'},
Expand Down

0 comments on commit ff15581

Please sign in to comment.