diff --git a/doc/notes.txt b/doc/notes.txt index 7d353119..cc6d1818 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -102,6 +102,7 @@ TODO: - parse .incbin directives? - can't replace in hex directives - should maybe use same single-canvas editor for map + char editor + - Uncaught Expected 12 bytes; image has 6 (380:13): Expected 12 bytes; image has 6 ... over and over ... editing BALL - crt0.s compiled each time? - debug highlight doesn't go away when debugging -> running - show breakpoint of PC or highest address on stack diff --git a/presets/astrocade-bios/bios.c b/presets/astrocade-bios/bios.c index e68816c0..303c11c5 100644 --- a/presets/astrocade-bios/bios.c +++ b/presets/astrocade-bios/bios.c @@ -528,31 +528,47 @@ typedef struct { // write pattern (E,D,C,B) magic A @ HL void WRIT(ContextBlock *ctx) { - byte x = _E; - byte y = _D; + byte magic = _A; byte w = _C; byte h = _B; + byte x = _E; + byte y = _D; byte* src = (byte*) _HL; - byte* dest = &vmagic[y][x>>2];// destination address - byte i,j; - byte magic = _A; + byte* dest = &vmagic[y][0]; // destination address + byte xb = (magic & M_FLOP) ? (39-(x>>2)) : (x>>2); + byte i,j,b; + // iterate through all lines for (j=0; j + +#include "aclib.h" + +#define EXIT_CLIPDEST(addr) if ((((word)addr)&0xfff) >= 0xe10) return + +// clear screen and set graphics mode +void clrscr(void) { + memset(vidmem, 0, VHEIGHT*VBWIDTH); // clear page 1 +} + +// draw vertical line +void vline(byte x, byte y1, byte y2, byte col, byte op) { + byte* dest = &vmagic[y1][x>>2];// destination address + byte y; + hw_magic = M_SHIFT(x) | op; // set magic register + col <<= 6; // put color in high pixel + for (y=y1; y<=y2; y++) { + EXIT_CLIPDEST(dest); + *dest = col; // shift + xor color + dest += VBWIDTH; // dest address to next scanline + } +} + +// render a sprite with the given graphics operation +void render_sprite(const byte* src, byte x, byte y, byte op) { + byte i; + byte w = *src++; // get width from 1st byte of sprite + byte h = *src++; // get height from 2nd byte of sprite + byte* dest = &vmagic[y][x>>2];// destination address + hw_magic = M_SHIFT(x) | op; // set magic register + // y clipping off bottom + if (y+h >= VHEIGHT) { + if (y >= VHEIGHT) return; + h = VHEIGHT-y; + } + // memory copy loop + if (op != M_ERASE) { + while (h--) { + for (i=0; i>2]; // destination address + hw_magic = M_SHIFT(x) | M_XPAND | op; + for (byte i=0; i<8; i++) { + char b = *src++; + EXIT_CLIPDEST(dest); + *dest++ = b; // expand lower nibble -> 1st byte + *dest++ = b; // expand upper nibble -> 2nd byte + if (x & 3) { + *dest++ = 0; // leftover -> 3rd byte + *dest = 0; // reset upper/lower flag + } else { + dest++; + } + dest += VBWIDTH-3; // we incremented 3 bytes for this line + } +} + +void draw_string(byte x, byte y, byte options, const char* str) { + hw_xpand = XPAND_COLORS(0, options); + do { + byte ch = *str++; + if (!ch) break; + draw_char(ch, x, y, M_XOR); + x += 8; + } while (1); +} + +void draw_bcd_word(word bcd, byte x, byte y, byte op) { + byte j; + x += 3*8; + for (j=0; j<4; j++) { + draw_char('0'+(bcd&0xf), x, y, op); + x -= 8; + bcd >>= 4; + } +} + +// add two 16-bit BCD values +word bcd_add(word a, word b) __naked { + a; b; // to avoid warning +__asm + push ix + ld ix,#0 + add ix,sp + ld a,4 (ix) + add a, 6 (ix) + daa + ld c,a + ld a,5 (ix) + adc a, 7 (ix) + daa + ld b,a + ld l, c + ld h, b + pop ix + ret +__endasm; +} + diff --git a/presets/astrocade/acextra.h b/presets/astrocade/acextra.h new file mode 100644 index 00000000..8b6df575 --- /dev/null +++ b/presets/astrocade/acextra.h @@ -0,0 +1,19 @@ + +#ifndef _ACEXTRA_H +#define _ACEXTRA_H + +#include "aclib.h" + +void clrscr(); +void vline(byte x, byte y1, byte y2, byte col, byte op); +void pixel(byte x, byte y, byte col, byte op); +void render_sprite(const byte* src, byte x, byte y, byte op); +void draw_char(byte ch, byte x, byte y, byte op); +void draw_string(byte x, byte y, byte options, const char* str); +void draw_bcd_word(word bcd, byte x, byte y, byte op); +word bcd_add(word a, word b); + +#define pixel(x,y,color,op) vline(x, y, y, color, op); +#define erase_sprite(src,x,y) render_sprite(src,x,y,M_ERASE); + +#endif diff --git a/presets/astrocade/aclib.c b/presets/astrocade/aclib.c index 6dee4931..b0554607 100644 --- a/presets/astrocade/aclib.c +++ b/presets/astrocade/aclib.c @@ -2,13 +2,6 @@ #include #include "aclib.h" -#define EXIT_CLIPDEST(addr) if ((((word)addr)&0xfff) >= 0xe10) return - -// clear screen and set graphics mode -void clrscr(void) { - memset(vidmem, 0, VHEIGHT*VBWIDTH); // clear page 1 -} - // set entire palette at once (8 bytes to port 0xb) // bytes in array should be in reverse void set_palette(byte palette[8]) __z88dk_fastcall { @@ -31,113 +24,3 @@ __asm __endasm; } -// draw vertical line -void vline(byte x, byte y1, byte y2, byte col, byte op) { - byte* dest = &vmagic[y1][x>>2];// destination address - byte y; - hw_magic = M_SHIFT(x) | op; // set magic register - col <<= 6; // put color in high pixel - for (y=y1; y<=y2; y++) { - EXIT_CLIPDEST(dest); - *dest = col; // shift + xor color - dest += VBWIDTH; // dest address to next scanline - } -} - -// render a sprite with the given graphics operation -void render_sprite(const byte* src, byte x, byte y, byte op) { - byte i; - byte w = *src++; // get width from 1st byte of sprite - byte h = *src++; // get height from 2nd byte of sprite - byte* dest = &vmagic[y][x>>2];// destination address - hw_magic = M_SHIFT(x) | op; // set magic register - // y clipping off bottom - if (y+h >= VHEIGHT) { - if (y >= VHEIGHT) return; - h = VHEIGHT-y; - } - // memory copy loop - if (op != M_ERASE) { - while (h--) { - for (i=0; i>2]; // destination address - hw_magic = M_SHIFT(x) | M_XPAND | op; - for (byte i=0; i<8; i++) { - char b = *src++; - EXIT_CLIPDEST(dest); - *dest++ = b; // expand lower nibble -> 1st byte - *dest++ = b; // expand upper nibble -> 2nd byte - if (x & 3) { - *dest++ = 0; // leftover -> 3rd byte - *dest = 0; // reset upper/lower flag - } else { - dest++; - } - dest += VBWIDTH-3; // we incremented 3 bytes for this line - } -} - -void draw_string(byte x, byte y, byte options, const char* str) { - hw_xpand = XPAND_COLORS(0, options); - do { - byte ch = *str++; - if (!ch) break; - draw_char(ch, x, y, M_XOR); - x += 8; - } while (1); -} - -void draw_bcd_word(word bcd, byte x, byte y, byte op) { - byte j; - x += 3*8; - for (j=0; j<4; j++) { - draw_char('0'+(bcd&0xf), x, y, op); - x -= 8; - bcd >>= 4; - } -} - -// add two 16-bit BCD values -word bcd_add(word a, word b) __naked { - a; b; // to avoid warning -__asm - push ix - ld ix,#0 - add ix,sp - ld a,4 (ix) - add a, 6 (ix) - daa - ld c,a - ld a,5 (ix) - adc a, 7 (ix) - daa - ld b,a - ld l, c - ld h, b - pop ix - ret -__endasm; -} - diff --git a/presets/astrocade/aclib.h b/presets/astrocade/aclib.h index 13ba1a38..0ba1b5f8 100644 --- a/presets/astrocade/aclib.h +++ b/presets/astrocade/aclib.h @@ -79,18 +79,7 @@ byte __at (0x4000) vidmem[VTOTAL][VBWIDTH]; /// GRAPHICS FUNCTIONS -void clrscr(); void set_palette(byte palette[8]) __z88dk_fastcall; // palette in reverse order void set_sound_registers(byte regs[8]) __z88dk_fastcall; // in reverse too -void vline(byte x, byte y1, byte y2, byte col, byte op); -void pixel(byte x, byte y, byte col, byte op); -void render_sprite(const byte* src, byte x, byte y, byte op); -void draw_char(byte ch, byte x, byte y, byte op); -void draw_string(byte x, byte y, byte options, const char* str); -void draw_bcd_word(word bcd, byte x, byte y, byte op); -word bcd_add(word a, word b); - -#define pixel(x,y,color,op) vline(x, y, y, color, op); -#define erase_sprite(src,x,y) render_sprite(src,x,y,M_ERASE); #endif diff --git a/presets/astrocade/cosmic.c b/presets/astrocade/cosmic.c index edd76b52..41065464 100644 --- a/presets/astrocade/cosmic.c +++ b/presets/astrocade/cosmic.c @@ -9,6 +9,8 @@ #include "aclib.h" //#link "aclib.c" +#include "acextra.h" +//#link "acextra.c" //#link "hdr_autostart.s" diff --git a/presets/astrocade/hello.c b/presets/astrocade/hello.c index 8655e450..cce70b05 100644 --- a/presets/astrocade/hello.c +++ b/presets/astrocade/hello.c @@ -33,16 +33,16 @@ byte bcdnum[3] = {0x56,0x34,0x12}; byte bcdinc[3] = {0x01,0x00,0x00}; void main(void) { - // clear screen - clrscr(); // setup palette set_palette(palette); // set screen height // set horizontal color split (position / 4) // set interrupt status SYS_SETOUT(89*2, 23, 0); + // clear screen + SYS_FILL(0x4000, 89*2, 0); // display standard characters - display_string(2, 2, OPT_ON(1), "HELLO, WORLD!!"); + display_string(2, 2, OPT_ON(1), "HELLO, WORLD!\xb1\xb2\xb3\xb4\xb5"); // 2x2 must have X coordinate multiple of 2 display_string(4, 16, OPT_2x2|OPT_ON(2), "BIG TEXT!"); // 4x4 must have X coordinate multiple of 4 diff --git a/presets/astrocade/lines.c b/presets/astrocade/lines.c index f9c1d1dd..9b2281ce 100644 --- a/presets/astrocade/lines.c +++ b/presets/astrocade/lines.c @@ -1,6 +1,9 @@ #include "aclib.h" //#link "aclib.c" +#include "acbios.h" +#include "acextra.h" +//#link "acextra.c" //#link "hdr_autostart.s" #include @@ -28,17 +31,10 @@ const byte palette[8] = { 0x07, 0xD4, 0x35, 0x00, }; -void setup_registers() { - set_palette(palette); - // horizontal palette split - hw_horcb = 20; - // height of screen - hw_verbl = VHEIGHT*2; -} - void main() { - setup_registers(); - clrscr(); + set_palette(palette); + SYS_SETOUT(89*2, 20, 0); + SYS_FILL(0x4000, 89*2, 0); hw_xpand = XPAND_COLORS(0, 2); draw_string(2, 80, 0, "Hello, Lines!"); draw_line(0, 0, 159, 95, 1); diff --git a/presets/astrocade/sprites.c b/presets/astrocade/sprites.c index bb0b8f9f..b280dda7 100644 --- a/presets/astrocade/sprites.c +++ b/presets/astrocade/sprites.c @@ -3,6 +3,10 @@ #include "aclib.h" //#link "aclib.c" +#include "acbios.h" +//#link "acbios.c" +#include "acextra.h" +//#link "acextra.c" //#link "hdr_autostart.s" const byte player_bitmap[] = @@ -14,18 +18,13 @@ const byte palette[8] = { 0x07, 0xD4, 0x35, 0x01, }; -void setup_registers() { - set_palette(palette); - hw_horcb = 0; - hw_verbl = 102*2; -} - void main() { byte x,y; x=10; y=10; - setup_registers(); - clrscr(); + set_palette(palette); + SYS_SETOUT(102*2, 0, 0); + SYS_FILL(0x4000, 89*2, 0); while (1) { render_sprite(player_bitmap, x, y, M_MOVE); erase_sprite(player_bitmap, x, y); diff --git a/presets/astrocade/vsync.c b/presets/astrocade/vsync.c index 090a05d3..015305b1 100644 --- a/presets/astrocade/vsync.c +++ b/presets/astrocade/vsync.c @@ -4,9 +4,9 @@ //#resource "astrocade.inc" #include "aclib.h" //#link "aclib.c" -//#link "hdr_autostart.s" #include "acbios.h" //#link "acbios.s" +//#link "hdr_autostart.s" const byte player_bitmap[] = {0,0, // X, Y offset @@ -20,18 +20,13 @@ const byte palette[8] = { 0x07, 0xD4, 0x33, 0x01, }; -void setup_registers() { - set_palette(palette); - hw_horcb = 0; - hw_verbl = 102*2; -} - void main() { byte x,y; x=20; y=20; - setup_registers(); - clrscr(); + set_palette(palette); + SYS_SETOUT(98*2, 0, 0x0); + SYS_FILL(0x4000, 98*40, 0); // clear screen activate_interrupts(); while (1) { write_relative(x, y, M_MOVE, player_bitmap); diff --git a/src/platform/astrocade.ts b/src/platform/astrocade.ts index 390b28a4..0a7e66b8 100644 --- a/src/platform/astrocade.ts +++ b/src/platform/astrocade.ts @@ -136,12 +136,11 @@ const _BallyAstrocadePlatform = function(mainElement, arcade) { v = v2; // flop if (magicop & 0x40) { - var v2 = 0; - for (var i=0; i<4; i++) { - v2 |= (v & 3) << (6-i*2); - v >>= 2; - } - v = v2; + v = + ((v & 0x03) << 6) | + ((v & 0x0c) << 2) | + ((v & 0x30) >> 2) | + ((v & 0xc0) >> 6); } // or/xor if (magicop & 0x30) { @@ -435,6 +434,7 @@ const _BallyAstrocadePlatform = function(mainElement, arcade) { reset() { cpu.reset(); cpu.setTstates(0); + psg.reset(); // TODO? magicop = xpand = inmod = inlin = infbk = shift2 = horcb = 0; verbl = sheight; diff --git a/src/worker/workermain.ts b/src/worker/workermain.ts index 8d19881e..1cf40894 100644 --- a/src/worker/workermain.ts +++ b/src/worker/workermain.ts @@ -2027,7 +2027,6 @@ function executeBuildSteps() { ls.files = ls.files.concat(linkstep.files); ls.args = ls.args.concat(linkstep.args); } - console.log(ls); linkstep = null; break; }