From 101f605c6cbb2667c6a24a7102ee69fe55004556 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sun, 19 Jul 2020 21:46:06 -0500 Subject: [PATCH] minor tweaks --- presets/atari8-5200/hello.a | 2 +- presets/atari8-5200/helloconio.c | 16 +++ presets/atari8-5200/siegegame.c | 238 +++++++++++++++++++++++++++++++ presets/zx/bios.c | 24 ++++ presets/zx/bios.h | 3 + scripts/sync-version-prod.sh | 2 +- src/platform/atari8.ts | 2 + 7 files changed, 285 insertions(+), 2 deletions(-) create mode 100644 presets/atari8-5200/helloconio.c create mode 100644 presets/atari8-5200/siegegame.c diff --git a/presets/atari8-5200/hello.a b/presets/atari8-5200/hello.a index fbcef34a..a61554c3 100644 --- a/presets/atari8-5200/hello.a +++ b/presets/atari8-5200/hello.a @@ -122,7 +122,7 @@ dlist .byte $70,$70,$70 ;Text data org $b100 -text1 .byte "Howdy Bagel! " +text1 .byte "Hello World! " .byte $a1,$a2,$a3 .byte 0 diff --git a/presets/atari8-5200/helloconio.c b/presets/atari8-5200/helloconio.c new file mode 100644 index 00000000..ac1683b1 --- /dev/null +++ b/presets/atari8-5200/helloconio.c @@ -0,0 +1,16 @@ + +#include +#include + +// Atari 5200 20x24 screen example + +int main() { + clrscr(); + // position the cursor, output text + gotoxy(0,0); + cputs("Hello Atari 5200"); + // draw a line + gotoxy(0,23); + chline(20); + return 0; +} diff --git a/presets/atari8-5200/siegegame.c b/presets/atari8-5200/siegegame.c new file mode 100644 index 00000000..b0c9489f --- /dev/null +++ b/presets/atari8-5200/siegegame.c @@ -0,0 +1,238 @@ + +#include +#include +#include +#include +#include +#include + +#define COLS 20 +#define ROWS 24 + +typedef unsigned char byte; +typedef signed char sbyte; +typedef unsigned short word; + +// pointer to screen memory +static byte** SAVMSC = (byte**) 0x1B; + +byte getchar(byte x, byte y) { + return (*SAVMSC)[x+y*COLS]; // lookup value @ cursor address +} + +void delay(byte count) { + while (count--) { + word i; + for (i=0; i<400; i++) ; + } +} + +////////// GAME DATA + +typedef struct { + byte x; + byte y; + byte dir; + word score; + char head_attr; + char tail_attr; + int collided:1; + int human:1; +} Player; + +Player players[2]; + +byte credits = 0; +byte frames_per_move; +byte gameover; + +#define START_SPEED 12 +#define MAX_SPEED 5 +#define MAX_SCORE 7 + +/////////// + +const char BOX_CHARS[8] = { '+', '+', '+', '+', + '-', '-', '!', '!'}; + +void draw_box(byte x, byte y, byte x2, byte y2, const char* chars) { + byte x1 = x; + cputcxy(x, y, chars[2]); + cputcxy(x2, y, chars[3]); + cputcxy(x, y2, chars[0]); + cputcxy(x2, y2, chars[1]); + while (++x < x2) { + cputcxy(x, y, chars[5]); + cputcxy(x, y2, chars[4]); + } + while (++y < y2) { + cputcxy(x1, y, chars[6]); + cputcxy(x2, y, chars[7]); + } +} + +void draw_playfield() { + draw_box(0,1,COLS-1,ROWS-1,BOX_CHARS); + cputsxy( 0, 0, "Plyr1:"); + cputsxy(10, 0, "Plyr2:"); + cputcxy( 7, 0, players[0].score+'0'); + cputcxy(17, 0, players[1].score+'0'); +} + +typedef enum { D_RIGHT, D_DOWN, D_LEFT, D_UP } dir_t; +const sbyte DIR_X[4] = { 1, 0, -1, 0 }; +const sbyte DIR_Y[4] = { 0, 1, 0, -1 }; + +void init_game() { + memset(players, 0, sizeof(players)); + players[0].head_attr = '1'; + players[1].head_attr = '2'; + players[0].tail_attr = '#'; + players[1].tail_attr = '*'; + frames_per_move = START_SPEED; +} + +void reset_players() { + players[0].x = players[0].y = 5; + players[0].dir = D_RIGHT; + players[1].x = COLS-6; + players[1].y = ROWS-6; + players[1].dir = D_LEFT; + players[0].collided = players[1].collided = 0; +} + +void draw_player(Player* p) { + cputcxy(p->x, p->y, p->head_attr); +} + +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) != 0) + p->collided = 1; + draw_player(p); +} + +void human_control(Player* p) { + byte dir = 0xff; + char joy; + if (!p->human) return; + joy = joy_read(0); + if (JOY_UP(joy)) dir = D_UP; + if (JOY_LEFT(joy)) dir = D_LEFT; + if (JOY_RIGHT(joy)) dir = D_RIGHT; + if (JOY_DOWN(joy)) dir = D_DOWN; + // don't let the player reverse direction + if (dir < 0x80 && dir != (p->dir ^ 2)) { + p->dir = dir; + } +} + +byte ai_try_dir(Player* p, dir_t dir, byte shift) { + byte x,y; + 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) == 0) { + p->dir = dir; + return 1; + } else { + return 0; + } +} + +void ai_control(Player* p) { + dir_t dir; + if (p->human) return; + dir = p->dir; + if (!ai_try_dir(p, dir, 0)) { + ai_try_dir(p, dir+1, 0); + ai_try_dir(p, dir-1, 0); + } else { + ai_try_dir(p, dir-1, 0) && ai_try_dir(p, dir-1, 1+(rand() & 3)); + ai_try_dir(p, dir+1, 0) && ai_try_dir(p, dir+1, 1+(rand() & 3)); + ai_try_dir(p, dir, rand() & 3); + } +} + +void flash_colliders() { + byte i; + // flash players that collided + for (i=0; i<56; i++) { + delay(2); +// revers(players[0].collided && (i&1)); + draw_player(&players[0]); +// revers(players[1].collided && (i&1)); + draw_player(&players[1]); + } + //revers(0); +} + +void make_move() { + byte i; + for (i=0; i MAX_SPEED) frames_per_move--; + // game over? + if (players[0].score != players[1].score) { + if (players[0].score >= MAX_SCORE) + declare_winner(0); + else if (players[1].score >= MAX_SCORE) + declare_winner(1); + } +} + +void play_game() { + gameover = 0; + init_game(); + players[0].human = 1; + while (!gameover) { + play_round(); + } +} + +void main() { + joy_install (joy_static_stddrv); + play_game(); +} diff --git a/presets/zx/bios.c b/presets/zx/bios.c index 3bf39af5..92b0c8d5 100644 --- a/presets/zx/bios.c +++ b/presets/zx/bios.c @@ -1,5 +1,6 @@ #include +#include "bios.h" #ifdef __MAIN__ @@ -50,11 +51,34 @@ int keyscan(void) { __endasm; } +void waitkey(int frames) { + frames; + __asm + ld c,4 (ix) + ld b,5 (ix) + call 0x1f3d + __endasm; +} + +void setpixel(unsigned char x, unsigned char y) { + x; + y; + __asm + ld c,4 (ix) + ld b,5 (ix) + call 0x22e5 + __endasm; +} + #ifdef __MAIN__ void main() { init_stdio(); printf("HELLO WORLD!\r"); + waitkey(50); + printf("Wait...\r"); + waitkey(50); + printf("Done!\r"); beep(1000,20); beep(750,20); beep(500,20); diff --git a/presets/zx/bios.h b/presets/zx/bios.h index 0fec53d0..b1503220 100644 --- a/presets/zx/bios.h +++ b/presets/zx/bios.h @@ -8,3 +8,6 @@ void init_stdio(void); int putchar(int ch); void beep(int divisor, int duration); int keyscan(void); +void waitkey(int frames); +void setpixel(unsigned char x, unsigned char y); + diff --git a/scripts/sync-version-prod.sh b/scripts/sync-version-prod.sh index b54bee28..f054756f 100755 --- a/scripts/sync-version-prod.sh +++ b/scripts/sync-version-prod.sh @@ -22,5 +22,5 @@ mkdir -p $TMPDIR git archive $VERSION | tar x -C $TMPDIR echo "Copying to $DESTPATH..." rsync --stats --exclude '.*' --exclude 'scripts/*' --exclude=node_modules --copy-dest=$DEVPATH -rilz --chmod=a+rx -e "ssh" $TMPDIR/ $SUBMODS $DESTPATH -rsync --stats -rpilvz --chmod=a+rx -e "ssh" --copy-dest=$DEVPATH ./gen config.js $DESTPATH/ +rsync --stats -rilvz --chmod=a+rx -e "ssh" --copy-dest=$DEVPATH ./gen config.js $DESTPATH/ echo "Done." diff --git a/src/platform/atari8.ts b/src/platform/atari8.ts index d000bd39..b09389b2 100644 --- a/src/platform/atari8.ts +++ b/src/platform/atari8.ts @@ -10,6 +10,8 @@ declare var jt; // for 6502 var Atari8_PRESETS = [ {id:'hello.a', name:'Hello World (ASM)'}, {id:'hellopm.a', name:'Hello Sprites (ASM)'}, + {id:'helloconio.c', name:'Text Mode (C)'}, + {id:'siegegame.c', name:'Siege Game (C)'}, ]; const ATARI8_KEYCODE_MAP = makeKeycodeMap([