diff --git a/presets/c64/23matches.c b/presets/c64/23matches.c index 1b9d2be8..186856b7 100644 --- a/presets/c64/23matches.c +++ b/presets/c64/23matches.c @@ -1,10 +1,5 @@ -#include -#include -#include -#include -#include -#include +#include "common.h" #include int matches; // number of matches remaining diff --git a/presets/c64/climber.c b/presets/c64/climber.c index c776ea3f..b33d70ff 100644 --- a/presets/c64/climber.c +++ b/presets/c64/climber.c @@ -1,26 +1,20 @@ -#include -#include - -#include -#include - //#resource "c64-sid.cfg" #define CFGFILE c64-sid.cfg +#include "common.h" +//#link "common.c" + +#include "sidplaysfx.h" //#resource "sidmusic1.bin" //#link "sidplaysfx.ca65" -#include "sidplaysfx.h" -//#link "rasterirq.ca65" #include "rasterirq.h" +//#link "rasterirq.ca65" #include "bcd.h" //#link "bcd.c" -#include "common.h" -//#link "common.c" - #include "scrolling.h" //#link "scrolling.c" diff --git a/presets/c64/common.h b/presets/c64/common.h index 2ff9501a..4ed05d4c 100644 --- a/presets/c64/common.h +++ b/presets/c64/common.h @@ -1,8 +1,14 @@ #ifndef _COMMON_H #define _COMMON_H -#include +#include +#include +#include #include +#include +#include +#include +#include typedef uint8_t byte; typedef uint16_t word; @@ -14,8 +20,9 @@ typedef enum { false, true } bool; #define DEFAULT_SCREEN ((void*)0x400) +#define wait_vblank waitvsync + void raster_wait(byte line); -void wait_vblank(void); char* get_vic_bank_start(void); diff --git a/presets/c64/joymove.c b/presets/c64/joymove.c index 3a8177fe..470ea76b 100644 --- a/presets/c64/joymove.c +++ b/presets/c64/joymove.c @@ -1,12 +1,5 @@ -#include -#include -#include -#include -#include -#include -#include -#include +#include "common.h" /*{w:24,h:21,bpp:1,brev:1,count:1}*/ const char SPRITE_DATA[64] = { diff --git a/presets/c64/multilines.c b/presets/c64/multilines.c index a9980f25..e49d3157 100644 --- a/presets/c64/multilines.c +++ b/presets/c64/multilines.c @@ -1,8 +1,3 @@ -#include -#include -#include -#include -#include #include "common.h" //#link "common.c" diff --git a/presets/c64/musicplayer.c b/presets/c64/musicplayer.c index 267a63dd..90d0740f 100644 --- a/presets/c64/musicplayer.c +++ b/presets/c64/musicplayer.c @@ -3,10 +3,6 @@ A simple music player. */ -#include -#include -#include <_sid.h> - #include "common.h" //#link "common.c" diff --git a/presets/c64/scroll1.c b/presets/c64/scroll1.c index 7541250f..ac704802 100644 --- a/presets/c64/scroll1.c +++ b/presets/c64/scroll1.c @@ -1,17 +1,6 @@ -#include -#include -#include -#include -#include -#include - -typedef unsigned char byte; -typedef unsigned short word; - -void rasterWait(unsigned char line) { - while (VIC.rasterline < line) ; -} +#include "common.h" +//#link "common.c" byte x = 0; // x scroll position byte y = 0; // y scroll position @@ -39,7 +28,7 @@ void main(void) { VIC.ctrl2 = VIC.ctrl2 & 0xf8; VIC.ctrl2 |= (x & 7); // wait for vsync - rasterWait(255); + waitvsync(); // every 8 pixels, move screen cells if ((x & 7) == 0) { memcpy(scrnbuf, scrnbuf+1, 40*8-1); diff --git a/presets/c64/scroll2.c b/presets/c64/scroll2.c index 0ba906da..95d90f70 100644 --- a/presets/c64/scroll2.c +++ b/presets/c64/scroll2.c @@ -1,17 +1,6 @@ -#include -#include -#include -#include -#include -#include - -typedef unsigned char byte; -typedef unsigned short word; - -void rasterWait(unsigned char line) { - while (VIC.rasterline < line) ; -} +#include "common.h" +//#link "common.c" byte x = 0; // x scroll position byte y = 0; // y scroll position @@ -49,7 +38,7 @@ void main(void) { src = scrnbuf[frame&1] + (x&7)*128; dst = scrnbuf[frame&1^1] + (x&7)*128; // wait for vsync - rasterWait(255); + waitvsync(); // scroll hidden buffer memcpy(dst, src+1, 128); // every 8 pixels, switch farmes diff --git a/presets/c64/scroll3.c b/presets/c64/scroll3.c index dcbf6091..400b677e 100644 --- a/presets/c64/scroll3.c +++ b/presets/c64/scroll3.c @@ -1,27 +1,6 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -typedef uint8_t byte; -typedef uint16_t word; -typedef int8_t sbyte; - -#define COLS 40 -#define ROWS 25 - -void raster_wait(unsigned char line) { - while (VIC.rasterline < line) ; -} - -void wait_vblank() { - raster_wait(255); // TODO -} +#include "common.h" +//#link "common.c" sbyte scroll_fine_x = 0; sbyte scroll_fine_y = 0; @@ -129,7 +108,7 @@ void main(void) { if (JOY_RIGHT(joy)) scroll_horiz(1); if (JOY_DOWN(joy)) scroll_vert(1); // update regs - wait_vblank(); + waitvsync(); scroll_update_regs(); } } diff --git a/presets/c64/scroll4.c b/presets/c64/scroll4.c index ca859611..d8dbc5e6 100644 --- a/presets/c64/scroll4.c +++ b/presets/c64/scroll4.c @@ -1,13 +1,4 @@ -#include -#include -#include -#include -#include -#include -#include -#include - #include "common.h" //#link "common.c" @@ -92,7 +83,7 @@ void main(void) { sprite_draw(0, n++, 70, 192); sprite_draw(0, 172, 145, 192); // wait for vblank - wait_vblank(); + waitvsync(); // update scroll registers // and swap screens if we must scroll_update(); diff --git a/presets/c64/scroll5.c b/presets/c64/scroll5.c index b9fab836..071aa0c5 100644 --- a/presets/c64/scroll5.c +++ b/presets/c64/scroll5.c @@ -1,13 +1,4 @@ -#include -#include -#include -#include -#include -#include -#include -#include - #include "common.h" //#link "common.c" @@ -124,8 +115,8 @@ void main(void) { slowframe = swap_needed; // animate sprite in shadow sprite ram update_player(); - // wait for vblank - wait_vblank(); + // wait for end of frame + waitvsync(); // then update sprite registers sprite_update(visbuf); // update scroll registers diff --git a/presets/c64/siddemo.c b/presets/c64/siddemo.c index afc86dee..8d98f20c 100644 --- a/presets/c64/siddemo.c +++ b/presets/c64/siddemo.c @@ -1,9 +1,6 @@ -#include -#include -#include -#include -#include +#include "common.h" +//#link "common.c" //#resource "c64-sid.cfg" #define CFGFILE c64-sid.cfg diff --git a/presets/c64/siegegame.c b/presets/c64/siegegame.c index 33c22de5..f0bd1e5c 100644 --- a/presets/c64/siegegame.c +++ b/presets/c64/siegegame.c @@ -3,33 +3,20 @@ Text-based version of a Blockade-style game. For more information, see "Making Arcade Games in C". */ -#include -#include -#include -#include -#include -#include -#include - -#define COLS 40 -#define ROWS 24 - -typedef unsigned char byte; -typedef signed char sbyte; -typedef unsigned short word; +#include "common.h" // BASL = text address of cursor position static byte** BASL = (byte**) 0xD1; -byte getchar(byte x, byte y) { +// get the character at a specfic x/y position +byte readcharxy(byte x, byte y) { gotoxy(x,y); // set cursor position return (*BASL)[x]; // lookup value @ cursor address } void delay(byte count) { while (count--) { - word i; - for (i=0; i<200; i++) ; + waitvsync(); } } @@ -115,7 +102,7 @@ void move_player(Player* p) { cputcxy(p->x, p->y, p->tail_attr); p->x += DIR_X[p->dir]; p->y += DIR_Y[p->dir]; - if ((getchar(p->x, p->y) & 0x7f) != ' ') + if ((readcharxy(p->x, p->y) & 0x7f) != ' ') p->collided = 1; draw_player(p); } @@ -141,7 +128,8 @@ byte ai_try_dir(Player* p, dir_t dir, byte shift) { dir &= 3; x = p->x + (DIR_X[dir] << shift); y = p->y + (DIR_Y[dir] << shift); - if (x < COLS && y < ROWS && (getchar(x, y) & 0x7f) == ' ') { + if (x < COLS && y < ROWS + && (readcharxy(x, y) & 0x7f) == ' ') { p->dir = dir; return 1; } else { diff --git a/presets/c64/sprite_collision.c b/presets/c64/sprite_collision.c index fe051da7..c456b88d 100644 --- a/presets/c64/sprite_collision.c +++ b/presets/c64/sprite_collision.c @@ -1,12 +1,4 @@ -#include -#include -#include -#include -#include -#include -#include - #include "common.h" //#link "common.c" diff --git a/presets/c64/sprite_test.c b/presets/c64/sprite_test.c index 85e6d54c..d07f2cd1 100644 --- a/presets/c64/sprite_test.c +++ b/presets/c64/sprite_test.c @@ -1,11 +1,5 @@ -#include -#include -#include -#include -#include -#include -#include +#include "common.h" /*{w:24,h:21,bpp:1,brev:1,count:1}*/ const char SPRITE_DATA[64] = { diff --git a/presets/c64/spritesinborder.c b/presets/c64/spritesinborder.c index 6c741168..ab7ce4a2 100644 --- a/presets/c64/spritesinborder.c +++ b/presets/c64/spritesinborder.c @@ -1,9 +1,4 @@ -#include -#include -#include -#include - //#link "common.c" #include "common.h" @@ -13,6 +8,8 @@ //#link "sprites.c" #include "sprites.h" +#include + /*{w:24,h:21,bpp:1,brev:1}*/ const char spriteshape[3*21] = { 0x00,0x7F,0x00,0x01,0xFF,0xC0,0x03,0xFF,0xE0, diff --git a/presets/c64/upandaway.c b/presets/c64/upandaway.c index 21932336..cf6a9b9d 100644 --- a/presets/c64/upandaway.c +++ b/presets/c64/upandaway.c @@ -1,11 +1,7 @@ // ported from // https://odensskjegg.home.blog/2018/12/29/recreating-the-commodore-64-user-guide-code-samples-in-cc65-part-three-sprites/ -#include -#include -#include -#include -#include +#include "common.h" /*{w:24,h:21,bpp:1,brev:1}*/ const char sprite[3*21] = {