fixed nametab.B invalid address, and spr_submit with 0 sprites
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 13 Jan 2024 22:58:55 +0000 (00:58 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 13 Jan 2024 22:58:55 +0000 (00:58 +0200)
Makefile
src/hwregs.h
src/main.c
src/part_simba.c
src/sprite.S
src/sprite.c
src/sprite.h
src/vdp.S

index 6c173f8..d44e573 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ bin = $(name).bin
 
 warn = -pedantic -Wall
 dbg = -g
-opt = -O3
+#opt = -O3
 def = -D__NO_CTYPE
 inc = -I. -Isrc -Isrc/libc
 
@@ -91,6 +91,10 @@ install: $(bin)
        [ -f /media/usbmass/MEGA/MEGA.RBF ] || cp $(bin) /media/usbmass/MEGA/MEGA.BIN
        umount /media/usbmass
 
+.PHONY: debug
+debug: $(bin)
+       $(TC)gdb $(elf)
+
 # ---- tools ----
 PNGDUMP = tools/pngdump/pngdump
 
index 4455811..2ab7591 100644 (file)
 
 #define VDP_NA_ADDR(x) (((x) >> 10) & 0x38)
 #define VDP_NW_ADDR(x) (((x) >> 10) & 0x3e)
-#define VDP_NB_ADDR(x) ((x) >> 13)
+#define VDP_NB_ADDR(x) (((x) >> 13) & 7)
 #define VDP_SPRTAB_ADDR(x)     ((x) >> 9)
 #define VDP_HSTAB_ADDR(x)      ((x) >> 10)
 
index 29fb6d5..9478ee8 100644 (file)
@@ -30,7 +30,7 @@ int main(void)
        parts[0].update = dna_update;
        parts[1].start = simba_start;
        parts[1].update = simba_update;
-       part = parts + 1;
+       part = parts;
 
        part->start();
 
index 622bbbf..7c2611d 100644 (file)
@@ -27,7 +27,7 @@ void simba_start(void)
 
        /* setup tilemaps */
        src = simbabg_tmap;
-       vdp_setup_addr(VDP_VRAM, 0xd000);       /* nametable B */
+       vdp_setup_addr(VDP_VRAM, 0xe000);       /* nametable B */
        while(src < simbabg_tmap_end) {
                VDP_DATA = VDP_TILENAME(*src++, 2, 0);
        }
index 158aaac..d258d62 100644 (file)
@@ -8,11 +8,16 @@
 
        .globl spr_submit
 spr_submit:
-       move.l spr_count, %d0
-       lsl.l #2, %d0                   | 4 words per sprite
+       move.w spr_count, %d0
+       tst.w %d0
+       bne.s 0f
+       | if spr_count is zero, upload a single null sprite
+       addq.w #1, %d0
+0:     ext.l %d0
+       lsl.w #2, %d0                   | 4 words per sprite
        move.l %d0, -(%sp)
        pea spr_shadow
-       pea 0xe000.w                    | we placed the spirte table at e000
+       pea 0xd000.w                    | we placed the spirte table at d000
        jsr dma_systovram
        addq.l #8, %sp
        addq.l #4, %sp
index 63305f3..9a6c6e7 100644 (file)
@@ -3,7 +3,7 @@
 #include "vdp.h"
 
 struct hwsprite spr_shadow[MAX_HWSPRITES];
-int spr_count;
+short spr_count;
 
 void spr_begin(void)
 {
@@ -13,7 +13,7 @@ void spr_begin(void)
 
 void spr_add(int x, int y, unsigned int tile, int sprsz)
 {
-       int id;
+       short id;
        struct hwsprite *spr;
 
        if(spr_count >= MAX_HWSPRITES) {
index 17050e9..7b90506 100644 (file)
@@ -15,7 +15,7 @@ struct hwsprite {
 
 #define MAX_HWSPRITES  64
 extern struct hwsprite spr_shadow[MAX_HWSPRITES];
-extern int spr_count;
+extern short spr_count;
 
 void spr_begin(void);
 void spr_add(int x, int y, unsigned int tile, int sprsz);
index 990a3ef..c1cf6a2 100644 (file)
--- a/src/vdp.S
+++ b/src/vdp.S
@@ -70,8 +70,8 @@ def_reg_tab:
        .byte VDP_REG_MODE2, VDP_M2_INIT + VDP_M2_DISP  | 1: mode 2
        .byte VDP_REG_NAMEA, VDP_NA_ADDR(0xc000)        | 2: scroll A nametable addr.
        .byte VDP_REG_NAMEW, 0                          | 3: window nametable addr.
-       .byte VDP_REG_NAMEB, VDP_NB_ADDR(0xd000)        | 4: scroll B nametable addr.
-       .byte VDP_REG_SPR, VDP_SPRTAB_ADDR(0xe000)      | 5: sprite table addr.
+       .byte VDP_REG_NAMEB, VDP_NB_ADDR(0xe000)        | 4: scroll B nametable addr.
+       .byte VDP_REG_SPR, VDP_SPRTAB_ADDR(0xd000)      | 5: sprite table addr.
        .byte VDP_REG_BGCOL, 0                          | 7: bg color
        .byte VDP_REG_HINTR, 0                          | 10: horiz. interrupt interval
        .byte VDP_REG_MODE3, 0                          | 11: mode 3