From 113fdd4099fbfa9136c77d574e66fc80e0293eab Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sun, 26 Aug 2018 00:17:02 -0400 Subject: [PATCH] apple2 has 64k now --- presets/apple2/cosmic.c | 17 +++++++++++++---- src/platform/apple2.ts | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/presets/apple2/cosmic.c b/presets/apple2/cosmic.c index 6e353071..9175ff44 100644 --- a/presets/apple2/cosmic.c +++ b/presets/apple2/cosmic.c @@ -1,3 +1,9 @@ + +/* + * An Apple ][ port of the Cosmic Impalas game + * described in the book + * "Making 8-bit Arcade Games in C" + */ #include #include @@ -14,6 +20,7 @@ typedef unsigned short word; #define PEEK(addr) (*(unsigned char*) (addr)) #define PEEKW(addr) (*(unsigned*) (addr)) #define STROBE(addr) __asm__ ("sta %w", addr) + // speaker click #define CLICK STROBE(0xc030) @@ -78,8 +85,6 @@ const byte MOD7[256] = { // bitmask table const byte BIT7[7] = { 1, 2, 4, 8, 16, 32, 64 }; -#pragma static-locals(on) - /// SOUND FUNCTIONS void tone(byte period, byte dur, sbyte mod) { @@ -93,6 +98,7 @@ void tone(byte period, byte dur, sbyte mod) { /// GRAPHICS FUNCTIONS +// clear screen and set graphics mode void clrscr() { STROBE(0xc052); // turn off mixed-mode STROBE(0xc054); // page 1 @@ -101,6 +107,7 @@ void clrscr() { memset((byte*)0x2000, 0, 0x2000); // clear page 1 } +// draw (xor) vertical line void xor_vline(byte x, byte y1, byte y2) { byte xb = DIV7[x]; // divide x by 7 byte mask = BIT7[MOD7[x]]; // lookup bitmask for remainder @@ -111,6 +118,7 @@ void xor_vline(byte x, byte y1, byte y2) { } } +// draw (xor) a pixel void xor_pixel(byte x, byte y) { xor_vline(x, y, y); // draw line with 1-pixel height } @@ -119,6 +127,7 @@ typedef enum { OP_DRAW, OP_XOR, OP_ERASE } GraphicsOperation; +// render a sprite with the given graphics operation byte render_sprite(const byte* src, byte x, byte y, byte op) { byte i,j; byte w = *src++; // get width from 1st byte of sprite @@ -481,9 +490,9 @@ void move_bomb() { byte leftover = xor_sprite(bomb_bitmap, bomb_x, bomb_y); // erase if (bomb_y > 192-12) { bomb_y = 0; - } else if (leftover) { + } else if (leftover & 0x7f) { // don't count hi bit erase_sprite(bomb_bitmap, bomb_x, bomb_y); // erase bunker - if (bomb_y > 192-22) { + if (bomb_y > 192-23) { // player was hit (probably) destroy_player(); } diff --git a/src/platform/apple2.ts b/src/platform/apple2.ts index 7b6a03de..9b5784a3 100644 --- a/src/platform/apple2.ts +++ b/src/platform/apple2.ts @@ -121,7 +121,7 @@ const _Apple2Platform = function(mainElement) { if (address == 0xc070) return noise() | 0x80; case 8: - return 0; // TODO doLanguageCardIO(address, value); + return doLanguageCardIO(address); case 9: case 10: case 11: case 12: case 13: case 14: case 15: return noise(); // return slots[slot-8].doIO(address, value); } @@ -281,7 +281,7 @@ const _Apple2Platform = function(mainElement) { } } - function doLanguageCardIO(address, value) + function doLanguageCardIO(address:number) { switch (address & 0x0f) { // Select aux RAM bank 2, write protected.