Skip to content

Commit

Permalink
astrocade: use aclib.s not aclib.c, rainbow, rotate; use AstroLibre
Browse files Browse the repository at this point in the history
  • Loading branch information
sehugg committed Jun 7, 2019
1 parent baa9ed7 commit cdc04a9
Show file tree
Hide file tree
Showing 20 changed files with 318 additions and 63 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 > $@
27 changes: 23 additions & 4 deletions presets/astrocade-bios/bios.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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 },
Expand Down
23 changes: 15 additions & 8 deletions presets/astrocade-bios/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion presets/astrocade-bios/test1.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 40 additions & 3 deletions presets/astrocade/acfast.s
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@


; 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) {
.globl _fast_sprite_8
_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)
Expand All @@ -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
Expand All @@ -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
26 changes: 0 additions & 26 deletions presets/astrocade/aclib.c

This file was deleted.

6 changes: 6 additions & 0 deletions presets/astrocade/aclib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 37 additions & 0 deletions presets/astrocade/aclib.s
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion presets/astrocade/cosmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions presets/astrocade/fastsprites.c
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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]);
}
Expand Down
21 changes: 17 additions & 4 deletions presets/astrocade/hello.c
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion presets/astrocade/lines.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 1 addition & 2 deletions presets/astrocade/music.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -87,7 +87,6 @@ void init_sound() {
}

void main() {
clrscr();
init_sound();
activate_interrupts();
while (1) {
Expand Down

0 comments on commit cdc04a9

Please sign in to comment.