1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-25 03:34:05 +00:00

c64: presets, reset keyboard

This commit is contained in:
Steven Hugg 2022-08-07 11:41:31 -05:00
parent 74a8795152
commit 9345fad794
4 changed files with 138 additions and 3 deletions

85
presets/c64/23matches.c Normal file
View File

@ -0,0 +1,85 @@
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <peekpoke.h>
#include <string.h>
#include <c64.h>
#include <cbm_petscii_charmap.h>
int matches; // number of matches remaining
int take; // # of matches to take on this turn
void print_matches() {
printf("\nThere are %d matches left.\n", matches);
}
void human_moves() {
print_matches();
// loop until we get a valid move
while (1) {
printf("\n>> Your turn. Take 1, 2, or 3 matches?");
// did we get exactly one input value?
if (scanf("%d", &take) == 1) {
// is it between 1 and 3?
if (take >= 1 && take <= 3) {
// are there not enough matches?
if (take > matches) {
printf("Not enough matches! Try again.\n");
continue; // go back to start of loop
} else {
// take the appropriate number of matches
printf("You took %d matches.\n", take);
matches -= take;
break; // break out of loop
}
}
}
printf("Bad input! Type a number from 1 to 3.\n");
}
}
void computer_moves() {
print_matches();
// simple AI: hard coded if 1-4 matches left
// otherwise take random number from 1 to 3
switch (matches) {
case 1: take = 1; break;
case 2: take = 1; break;
case 3: take = 2; break;
case 4: take = 3; break;
default: take = (rand() % 3) + 1; break;
}
printf("\n<< My turn. I'll take %d matches.\n", take);
matches -= take;
}
void play_game(void) {
printf(
"When it is your turn, you may take\n"
"1, 2 or 3 matches. I will do the same.\n\n"
"Whoever takes the last match loses.\n");
matches = 23;
// loop until no more matches
while (matches > 0) {
// move human, check if they lost
human_moves();
if (matches == 0) {
printf("You lose, turkey!\nBetter luck next time.\n");
break;
}
// move computer, check if they lost
computer_moves();
if (matches == 0) {
printf("I lost! You must be good!\n");
break;
}
}
}
void main(void) {
clrscr();
printf("*** 23 MATCHES ***\n\n");
play_game();
}

View File

@ -1,10 +1,14 @@
#include <stdio.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <peekpoke.h>
#include <string.h>
#include <c64.h>
#include <cbm_petscii_charmap.h>
void main(void) {
clrscr();
printf("\r\nHello World!\r\n");
printf("\nHello World!\n");
getchar();
}

46
presets/c64/sprite_test.c Normal file
View File

@ -0,0 +1,46 @@
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <peekpoke.h>
#include <string.h>
#include <c64.h>
#include <cbm_petscii_charmap.h>
/*{w:24,h:21,bpp:1,brev:1,count:1}*/
const char SPRITE_DATA[64] = {
0x0f,0xff,0x80,0x17,0xff,0x40,0x2b,0xfe,
0xa0,0x7f,0xff,0xf0,0xff,0xc0,0x3f,0xe0,
0x3f,0xc0,0x17,0xbe,0xc0,0x2d,0x7f,0xf0,
0x2b,0x7f,0xf8,0x2a,0xff,0xf8,0x15,0xf6,
0x00,0x3f,0xf8,0x00,0xfd,0xfc,0x00,0xfd,
0xff,0x00,0xfe,0xff,0x80,0xff,0x7f,0xc0,
0xff,0xff,0xc0,0xff,0xff,0xc0,0x0a,0xa8,
0x00,0x0f,0xf8,0x00,0x0f,0xff,0x80,0x03,
};
/*{w:12,h:21,bpp:2,brev:1,count:1,aspect:2}*/
const char SPRITE_MC_DATA[64] = {
0x0a,0xaa,0x80,0x0a,0xaa,0x80,0x2a,0xaa,
0xa0,0x2a,0xaa,0xa0,0xaa,0xaa,0xaa,0xff,
0xd5,0x40,0x0d,0xd7,0x40,0x3d,0xd5,0x54,
0x37,0x55,0x54,0x37,0x55,0x54,0x35,0x55,
0x00,0x3a,0xa0,0x00,0xea,0xa8,0x00,0xab,
0xaa,0x00,0xab,0xaa,0x00,0xab,0xaa,0x80,
0xaa,0xea,0x80,0xaa,0xaa,0x80,0x0f,0xfc,
0x00,0x0f,0xfc,0x00,0x0f,0xff,0xc0,0x83,
};
void main(void) {
// copy sprite pattern to RAM address 0x3800
memcpy((char*)0x3800, SPRITE_DATA, sizeof(SPRITE_DATA));
// set sprite shape entry (224)
POKE(0x400 + 0x3f8, 0x3800 / 64);
// set X and Y coordinate
VIC.spr_pos[0].x = 172;
VIC.spr_pos[0].y = 145;
// set color
VIC.spr_color[0] = COLOR_GREEN;
// enable sprite 0
VIC.spr_ena = 0b00000001;
}

View File

@ -33,7 +33,7 @@ export class C64_WASMMachine extends BaseWASMMachine implements Machine, Probeab
super.reset();
// clear keyboard
for (var ch=0; ch<128; ch++) {
this.setKeyInput(ch, 0, KeyFlags.KeyUp);
this.exports.machine_key_up(this.sys, ch);
}
// load rom
if (this.romptr && this.romlen) {