1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-27 01:51:35 +00:00

astrocade: new stack layout for bios calls

This commit is contained in:
Steven Hugg 2019-05-28 20:50:06 -04:00
parent 642ba8176f
commit b7a8bf2a23
3 changed files with 39 additions and 37 deletions

View File

@ -16,12 +16,6 @@ typedef struct {
const FontDescriptor __at(0x206) FNTSYS; const FontDescriptor __at(0x206) FNTSYS;
const FontDescriptor __at(0x20d) FNTSML; const FontDescriptor __at(0x20d) FNTSML;
// STACK MANIPULATION
#define DECSP1 __asm__("dec sp")
#define DECSP2 __asm__("dec sp"); __asm__("dec sp")
#define DECSP3 __asm__("dec sp"); __asm__("dec sp"); __asm__("dec sp")
// BIOS COMMANDS // BIOS COMMANDS
#define STRDIS 0x34 #define STRDIS 0x34
@ -40,20 +34,9 @@ const FontDescriptor __at(0x20d) FNTSML;
void activate_interrupts(void); void activate_interrupts(void);
void wait_for_vsync(void); void wait_for_vsync(void);
void _display_string(byte x, byte y, byte options, const char* str); void display_string(byte x, byte y, byte options, const char* str);
#define display_string(x,y,opts,str) \ void paint_rectangle(byte x, byte y, byte w, byte h, byte colormask);
DECSP1; \ void write_relative(byte x, byte y, byte magic, const char* pattern);
_display_string(x,y,opts,str);
void _paint_rectangle(byte x, byte y, byte w, byte h, byte colormask);
#define paint_rectangle(x,y,w,h,colormask) \
DECSP1; \
_paint_rectangle(x,y,w,h,colormask);
void _write_relative(byte x, byte y, byte magic, const char* pattern);
#define write_relative(x,y,magic,pattern) \
DECSP1; \
_write_relative(x,y,magic,pattern);
// QUICK MACROS // QUICK MACROS

View File

@ -421,10 +421,10 @@ _wait_for_vsync:
; .db 1 ; .db 1
; build a SYSSUK block on the stack ; build a SYSSUK block on the stack
; the caller needs to dec SP before calling ; <return addr> <5 bytes>
; so we have room for a RET opcode ; <endsuk5> <oldret> rst <cmd> <5 bytes> ret
.globl __display_string .globl _display_string
__display_string: _display_string:
ld h,#(STRDIS+1) ld h,#(STRDIS+1)
syssuk5: syssuk5:
pop de ; return address pop de ; return address
@ -432,21 +432,36 @@ syssuk5:
push hl ; SYSSUK <command> push hl ; SYSSUK <command>
ld iy,#0 ld iy,#0
add iy,sp ; SP -> IY add iy,sp ; SP -> IY
ld ix,#7
add ix,sp ; SP+7 -> IX
push de ; push return addr push de ; push return addr
ld e,(ix) ; load what's there
push de ; push it
ld d,#0xc9 ; ret opcode ld d,#0xc9 ; ret opcode
ld 7(iy),d ; store after params ld (ix),d ; store after params
ld hl,#endsuk5
push hl
ld ix,#0x20d ; alternate font desc. ld ix,#0x20d ; alternate font desc.
jp (iy) ; jump to RST jp (iy) ; jump to RST
endsuk5:
pop de ; old ret value
pop hl ; return address
ld ix,#7
add ix,sp ; SP+7 -> IX
ld (ix),e ; restore old ret value
pop de ; get rid of SYSSUK cmd
jp (hl) ; caller takes care of rest
; RECTAN x y w h colormask ; RECTAN x y w h colormask
.globl __paint_rectangle .globl _paint_rectangle
__paint_rectangle: _paint_rectangle:
ld h,#(RECTAN+1) ld h,#(RECTAN+1)
jp syssuk5 jp syssuk5
; WRITP x y magic pattern ; WRITP x y magic pattern
.globl __write_relative .globl _write_relative
__write_relative: _write_relative:
ld h,#(WRITR+1) ld h,#(WRITR+1)
jp syssuk5 jp syssuk5

View File

@ -8,12 +8,15 @@
//#link "acbios.s" //#link "acbios.s"
const byte player_bitmap[] = const byte player_bitmap[] =
{3,14,/*{w:12,h:16,bpp:2,brev:1}*/0x00,0x3C,0x00,0x00,0x18,0x00,0x00,0x3C,0x00,0x00,0x18,0x00,0x04,0x18,0x20,0x0C,0x3C,0x30,0x3C,0x3C,0x3C,0x1F,0xE7,0xF4,0x1F,0x66,0xF4,0x17,0xE7,0xE4,0x17,0xE7,0xE4,0x1C,0x7E,0x34,0x1C,0xFF,0x34,0x3C,0x18,0x3C,0x0C,0x18,0x30,0x04,0x18,0x20}; {0,0, // X, Y offset
3,14, // width (bytes) and height (lines)
/*{w:12,h:16,bpp:2,brev:1}*/
0x00,0x3C,0x00,0x00,0x18,0x00,0x00,0x3C,0x00,0x00,0x18,0x00,0x04,0x18,0x20,0x0C,0x3C,0x30,0x3C,0x3C,0x3C,0x1F,0xE7,0xF4,0x1F,0x66,0xF4,0x17,0xE7,0xE4,0x17,0xE7,0xE4,0x1C,0x7E,0x34,0x1C,0xFF,0x34,0x3C,0x18,0x3C,0x0C,0x18,0x30,0x04,0x18,0x20};
/*{pal:"astrocade",layout:"astrocade"}*/ /*{pal:"astrocade",layout:"astrocade"}*/
const byte palette[8] = { const byte palette[8] = {
0x06, 0x62, 0xF1, 0x04, 0x07, 0xD4, 0x33, 0x01,
0x07, 0xD4, 0x35, 0x01, 0x07, 0xD4, 0x33, 0x01,
}; };
void setup_registers() { void setup_registers() {
@ -24,16 +27,17 @@ void setup_registers() {
void main() { void main() {
byte x,y; byte x,y;
x=10; x=20;
y=10; y=20;
setup_registers(); setup_registers();
clrscr(); clrscr();
activate_interrupts(); activate_interrupts();
while (1) { while (1) {
render_sprite(player_bitmap, x, y, M_MOVE); write_relative(x, y, M_MOVE, player_bitmap);
wait_for_vsync(); wait_for_vsync();
erase_sprite(player_bitmap, x, y);
x++; x++;
y++; // erase_sprite(player_bitmap, x, y);
// x++;
// y++;
} }
} }