1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-23 21:31:20 +00:00

astrocade: use aclib.s not aclib.c, rainbow, rotate; use AstroLibre

This commit is contained in:
Steven Hugg 2019-06-06 15:40:31 -04:00
parent baa9ed7482
commit cdc04a9cd5
20 changed files with 318 additions and 63 deletions

View File

@ -29,3 +29,6 @@ tsweb:
ifconfig | grep inet
$(TSC) -w &
python3 scripts/serveit.py 2>> http.out
astrolibre.b64.txt: astrolibre.rom
lzg -9 $< | base64 -w 0 > $@

View File

@ -149,7 +149,7 @@ void DECCTS(ContextBlock *ctx) {
// INTERPRETER
void INTPC(ContextBlock *ctx) {
while (ctx->params[0] != 2) { // 2 = exit
while (ctx->params[0] > 2) { // 0,2 = exit
SYSCALL(ctx);
}
ctx->params++; // skip EXIT opcode
@ -303,6 +303,25 @@ void RANGED(ContextBlock *ctx) {
}
}
void INDEXB(ContextBlock *ctx) {
word addr = _HL + _A;
_HL = addr;
_A = *((byte*)addr);
}
void INDEXW(ContextBlock *ctx) {
word addr = _HL + _A*2;
_HL = addr;
_DE = *((word*)addr);
}
void INDEXN(ContextBlock *ctx) {
byte ofs = _C;
word addr = _HL + ofs/2;
byte val = *((byte*)addr);
_A = (ofs & 1) ? (val>>4) : (val&0xf);
}
// input
extern const byte KCTASC_TABLE[25];
@ -394,11 +413,11 @@ const SysCallEntry SYSCALL_TABLE[64] = {
{ &PAWS, REG_B },
{ &NOOP, REG_E|REG_D|REG_C }, // DISTIM
{ &NOOP, REG_HL }, // INCSCR
{ &NOOP, REG_C|REG_HL }, // INDEXN
{ &INDEXN, REG_C|REG_HL }, // INDEXN
{ &NOOP, REG_HL }, // STOREN
/* 90 */
{ &NOOP, REG_A|REG_HL }, // INDEXW
{ &NOOP, REG_A|REG_HL }, // INDEXB
{ &INDEXW, REG_A|REG_HL }, // INDEXW
{ &INDEXB, REG_A|REG_HL }, // INDEXB
{ &MOVE, REG_DE|REG_BC|REG_HL },
{ &NOOP, 0 }, // SHIFTU
{ &BCDADD, REG_DE|REG_B|REG_HL },

View File

@ -6,17 +6,24 @@
#define LOCHAR 0x20
#define HICHAR 0x63
const byte LMASK[4] = {0xff, 0x3f, 0x0f, 0x03};
static void hline(byte x1, byte x2, byte y, byte pattern) {
byte xb1 = x1/4;
byte xb2 = x2/4;
byte* dest = &vmagic[y][xb1];
signed char nbytes = xb2 - xb1;
hw_magic = M_SHIFT(x1) | M_XOR;
while (--nbytes > 0) {
*dest++ = pattern;
byte* dest = &vidmem[y][xb1];
byte mask = LMASK[x1&3];
if (xb1 == xb2) {
mask &= ~LMASK[x2&3];
}
*dest = *dest & ~mask | (mask & pattern);
if (xb1 != xb2) {
dest++;
while (++xb1 < xb2) {
*dest++ = pattern;
}
*dest = *dest & LMASK[x2&3] | (~LMASK[x2&3] & pattern);
}
if (x2&3) *dest = 0;
// TODO
}
// Fill rect (E,D,C,B) color A
@ -181,11 +188,11 @@ void DISNUM(ContextBlock *ctx) {
// write pattern (E,D,C,B) magic A @ HL
void WRIT(ContextBlock *ctx) {
byte magic = _A;
byte w = _C;
byte h = _B;
byte x = _E;
byte y = _D;
byte magic = _A | (x & 3); // add X shift
byte* src = (byte*) _HL;
byte* dest = &vmagic[y][0]; // destination address
byte xb = (magic & M_FLOP) ? (39-(x>>2)) : (x>>2);

View File

@ -58,7 +58,13 @@ _main:
.db 72
.db 100
.db 4
.db 0xa5
.db 0xaa
DO RECTAN
.db 6
.db 74
.db 100
.db 4
.db 0x55
DO WRITR
.db 50
.db 80

View File

@ -1,5 +1,8 @@
; FAST SPRITE ROUTINES FOR ASTROCADE
; fast_sprite_8: 8 (2 bytes) by H pixels, unexpanded
; fast_sprite_16: 16 (4 bytes) by H pixels, unexpanded
; Pattern format: bytewidth height data...
.area _CODE_ACFAST
;void fast_sprite_8(const byte* src, byte* dst) {
@ -7,7 +10,7 @@
_fast_sprite_8:
push ix
ld ix,#0
add ix,sp
add ix,sp ; IX = arg pointer
ld l,4(ix) ; src (HL)
ld h,5(ix)
ld e,6(ix) ; dst (DE)
@ -16,7 +19,7 @@ _fast_sprite_8:
ld c,(hl) ; load height -> C
sla c ; C *= 2
ld b,#0 ; B always 0 (BC < 256)
inc hl ; move to pattern bytes
inc hl ; move HL to pattern start
001$:
ldi
ldi ; copy 2 bytes src to dst
@ -32,3 +35,37 @@ _fast_sprite_8:
002$:
pop ix
ret
;void fast_sprite_16(const byte* src, byte* dst) {
.globl _fast_sprite_16
_fast_sprite_16:
push ix
ld ix,#0
add ix,sp ; IX = arg pointer
ld l,4(ix) ; src (HL)
ld h,5(ix)
ld e,6(ix) ; dst (DE)
ld d,7(ix)
inc hl ; skip width
ld c,(hl) ; load height -> C
sla c
sla c ; C *= 4
ld b,#0 ; B always 0 (BC < 256)
inc hl ; move HL to pattern start
001$:
ldi
ldi
ldi
ldi ; copy 4 bytes src to dst
ld a,b ; 0 -> A, doesnt affect flags
ld (de),a ; copy 3rd 0 (for shifts)
jp po,002$ ; exit if BC == 0
ld a,e ; E -> A
add a,#36 ; next scanline (dest += 38)
ld e,a ; A -> E
jr nc,001$ ; loop unless lo byte overflow
inc d ; inc hi byte of dest. addr
jr 001$ ; loop to next line
002$:
pop ix
ret

View File

@ -1,26 +0,0 @@
#include <string.h>
#include "aclib.h"
#pragma opt_code_speed
// 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 {
palette;
__asm
ld bc,#0x80b ; B -> 8, C -> 0xb
otir ; write C bytes from HL to port[B]
__endasm;
}
// set entire sound registers at once (8 bytes to port 0x18)
// bytes in array should be in reverse
void set_sound_registers(byte regs[8]) __z88dk_fastcall {
regs;
__asm
ld bc,#0x818 ; B -> 8, C -> 0x18
otir ; write C bytes from HL to port[B]
__endasm;
}

View File

@ -78,4 +78,10 @@ byte __at (0x4000) vidmem[VTOTAL][VBWIDTH];
void set_palette(byte palette[8]) __z88dk_fastcall; // palette in reverse order
void set_sound_registers(byte regs[8]) __z88dk_fastcall; // in reverse too
// INTERRUPTS
typedef void (*t_interrupt_handler)(void) __interrupt;
void set_interrupt_vector(t_interrupt_handler*ih) __z88dk_fastcall;
#endif

37
presets/astrocade/aclib.s Normal file
View File

@ -0,0 +1,37 @@
.include "astrocade.inc"
;;; C functions
.area _CODE_ACLIB
; 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 {
.globl _set_palette
_set_palette:
ld bc,#0x80b ; B -> 8, C -> 0xb
otir ; write C bytes from HL to port[B]
ret
; set entire sound registers at once (8 bytes to port 0x18)
; bytes in array should be in reverse
;void set_sound_registers(byte regs[8]) __z88dk_fastcall {
.globl _set_sound_registers
_set_sound_registers:
ld bc,#0x818 ; B -> 8, C -> 0x18
otir ; write C bytes from HL to port[B]
ret
; set interrupt vector
; pass address of 16-bit pointer to routine
.globl _set_interrupt_vector
_set_interrupt_vector:
di
ld a,l
out (INFBK),a
ld a,h ; upper 8 bits of address
ld i,a ; -> I
im 2 ; mode 2
ei ; enable interrupts
ret

View File

@ -11,7 +11,7 @@
#include "acbios.h"
//#link "acbios.s"
#include "aclib.h"
//#link "aclib.c"
//#link "aclib.s"
#include "acextra.h"
//#link "acextra.c"
//#link "hdr_autostart.s"

View File

@ -1,7 +1,7 @@
//#resource "astrocade.inc"
#include "aclib.h"
//#link "aclib.c"
//#link "aclib.s"
#include "acbios.h"
//#link "acbios.s"
//#link "acfast.s"
@ -26,6 +26,7 @@ const byte SPRITE[] = {
};
extern void fast_sprite_8(const byte* pattern, byte* dst);
extern void fast_sprite_16(const byte* pattern, byte* dst);
#define MAX_SPRITES 8
@ -69,7 +70,7 @@ void main(void) {
// fill array
for (i=0; i<MAX_SPRITES; i++) {
actors[i].x = rand() & 0x7f;
actors[i].y = (i*4);
actors[i].y = (i*8) & 0x3f;
actors[i].pattern = SPRITE;
draw_actor(&actors[i]);
}

View File

@ -1,7 +1,7 @@
//#resource "astrocade.inc"
#include "aclib.h"
//#link "aclib.c"
//#link "aclib.s"
//#link "hdr_autostart.s"
#include "acbios.h"
//#link "acbios.s"
@ -28,11 +28,22 @@ const byte BALL[] = {
};
// BCD number
byte bcdnum[3] = {0x56,0x34,0x12};
byte bcdnum[3] = {0x96,0x99,0x09};
const byte bcdinc[3] = {0x01,0x00,0x00};
void _clear() {
}
byte music_stack[16];
const byte MUSICDATA[] = {
0x80,
0x20,0xB0,0xCC,0x0F,0x0C,0x7E,0x00,0x00,
0x0C,0x7E,0x00,0x00,0x24,0x5E,0x7E,0x96,
0x0C,0x54,0x64,0x7E,0x0E,0x4A,0x5E,0x7E,
0x10,0x46,0x54,0x7E,0x48,0x3E,0x4A,0x5E,
0x0E,0x5E,0x8D,0x70,0x10,0x54,0x8D,0x70,
0x36,0x4A,0x5E,0x70,0x12,0x46,0x54,0x7E,
0x24,0x54,0x64,0x7E,0x48,0x5E,0x96,0x7E,
0xE0,0x80,0x18,0x90,0xFD,0xB0,0xFF,0x1F,
0xF0,
};
void main(void) {
// setup palette
@ -70,6 +81,8 @@ void main(void) {
activate_interrupts();
// make sure screen doesn't black out
RESET_TIMEOUT();
// play music
//begin_music(music_stack, 0b11111100, MUSICDATA);
while (1) {
// wait for SENTRY result
word code;

View File

@ -1,6 +1,7 @@
//#resource "astrocade.inc"
#include "aclib.h"
//#link "aclib.c"
//#link "aclib.s"
#include "acbios.h"
#include "acextra.h"
//#link "acextra.c"

View File

@ -4,7 +4,7 @@
//#resource "astrocade.inc"
#include "aclib.h"
//#link "aclib.c"
//#link "aclib.s"
//#link "hdr_autostart.s"
#include "acbios.h"
//#link "acbios.s"
@ -87,7 +87,6 @@ void init_sound() {
}
void main() {
clrscr();
init_sound();
activate_interrupts();
while (1) {

View File

@ -0,0 +1,50 @@
//#resource "astrocade.inc"
#include "aclib.h"
//#link "aclib.s"
#include "acbios.h"
//#link "acbios.s"
//#link "hdr_autostart.s"
#include <stdlib.h>
#include <string.h>
#pragma opt_code_speed
// we have a special interrupt handler that sets
// palette colors every 4 lines
byte linenum = 0;
void inthandler(void) __interrupt {
byte i = linenum;
hw_col0l = i;
hw_col1l = i+1;
hw_col2l = i+2;
hw_col3l = i+3;
i += 4;
if (i > 200) i = 0;
hw_inlin = i;
linenum = i;
}
// pointer to the interrupt handler
const t_interrupt_handler const intvector = &inthandler;
// patterns to fill each 4-line scanline group
const byte FILLPATS[4] = { 0x00, 0x55, 0xaa, 0xff };
void main(void) {
// fill screen with colors 0-3 every 4 scanlines
for (byte i=0; i<89; i++) {
memset(&vidmem[i], FILLPATS[i&3], 40);
}
// set our custom interrupt vector
set_interrupt_vector(&intvector);
// set screen height
// set horizontal color split (position / 4)
// set interrupt status (on)
SYS_SETOUT(89*2, 20, 0x8);
// infinite loop
// let the interrupt handler do the work
while (1) ;
}

View File

@ -0,0 +1,70 @@
//#resource "astrocade.inc"
#include "aclib.h"
//#link "aclib.s"
//#link "hdr_autostart.s"
#include "acbios.h"
//#link "acbios.s"
#include <stdlib.h>
#include <string.h>
/*{pal:"astrocade",layout:"astrocade"}*/
const byte palette[8] = {
0x77, 0xD4, 0x35, 0x01,
0x07, 0xD4, 0x35, 0x01,
};
const byte BALL[] = {
0, 0, // x and y offset
1, 4, // width (bytes) and height (lines)
/*{w:4,h:4,bpp:2,brev:1}*/
0xA0,
0xD0,
0xC4,
0xC1
};
void draw_pattern(byte x) {
vmagic[0][x] = BALL[4];
vmagic[1][x] = BALL[5];
vmagic[2][x] = BALL[6];
vmagic[3][x] = BALL[7];
}
void draw_pattern_inv(byte x) {
vmagic[3][x] = BALL[4];
vmagic[2][x] = BALL[5];
vmagic[1][x] = BALL[6];
vmagic[0][x] = BALL[7];
}
void main(void) {
// 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*40, 0);
// draw pattern
hw_magic = M_ROTATE;
draw_pattern(0);
draw_pattern(2);
// draw pattern flopped
hw_magic = M_ROTATE|M_FLOP;
draw_pattern(4);
draw_pattern(6);
// draw pattern
hw_magic = M_ROTATE;
draw_pattern_inv(8);
draw_pattern_inv(10);
// draw pattern flopped
hw_magic = M_ROTATE|M_FLOP;
draw_pattern_inv(12);
draw_pattern_inv(14);
while (1) {
}
}

View File

@ -1,7 +1,7 @@
//#resource "astrocade.inc"
#include "aclib.h"
//#link "aclib.c"
//#link "aclib.s"
#include "acbios.h"
//#link "acbios.s"
//#link "hdr_autostart.s"

View File

@ -1,8 +1,9 @@
#include <string.h>
//#resource "astrocade.inc"
#include "aclib.h"
//#link "aclib.c"
//#link "aclib.s"
#include "acbios.h"
//#link "acbios.c"
#include "acextra.h"

View File

@ -3,7 +3,7 @@
//#resource "astrocade.inc"
#include "aclib.h"
//#link "aclib.c"
//#link "aclib.s"
#include "acbios.h"
//#link "acbios.s"
//#link "hdr_autostart.s"

File diff suppressed because one or more lines are too long

View File

@ -1751,6 +1751,7 @@ function startPlatform() {
// start platform and load file
replaceURLState();
platform.start();
// TODO: ordering of loads?
loadBIOSFromProject();
initProject();
loadProject(qs['file']);