From 6513a329c0b984945a50735a871abc5b7f08ec46 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Thu, 14 Dec 2023 20:46:51 +0200 Subject: [PATCH] clear red --- src/hwregs.h | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/main.c | 4 +++ src/vdp.S | 71 ++++++++++++++++++++++++++++++++++++++++++++ src/vdp.h | 19 ++++++++++++ 4 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 src/vdp.S create mode 100644 src/vdp.h diff --git a/src/hwregs.h b/src/hwregs.h index 834be05..6dd8a74 100644 --- a/src/hwregs.h +++ b/src/hwregs.h @@ -1,16 +1,105 @@ #ifndef HWREGS_H_ #define HWREGS_H_ +#define VDP_DATA_PORT 0xc00000 +#define VDP_CTL_PORT 0xc00004 + +/* VDP access type */ +#define VDP_VRAM 0x40000000 +#define VDP_CRAM 0xc0000000 +#define VDP_VSRAM 0x40000010 + +#ifndef ASM #include #define REG16PTR(addr) (*(volatile uint16_t*)(addr)) +#define REG32PTR(addr) (*(volatile uint32_t*)(addr)) #define Z80_MEMMODE REG16PTR(0xa11000) #define Z80_BUSREQ REG16PTR(0xa11100) #define Z80_RESET REG16PTR(0xa11200) #define Z80_MEM ((uint8_t*)0xa00000) -#define VDP_PORT_DATA REG16PTR(0xc00000) -#define VDP_PORT_CTL REG16PTR(0xc00004) +#define VDP_DATA REG16PTR(VDP_DATA_PORT) +#define VDP_CTL REG16PTR(VDP_CTL_PORT) +#define VDP_CTL32 REG32PTR(VDP_CTL_PORT) +#define VDP_STAT VDP_CTL +#endif /* !def ASM */ + +#define VDP_REG_MODE1 0 +#define VDP_REG_MODE2 1 +#define VDP_REG_NAMEA 2 +#define VDP_REG_NAMEW 3 +#define VDP_REG_NAMEB 4 +#define VDP_REG_SPR 5 +#define VDP_REG_BGCOL 7 +#define VDP_REG_HINTR 10 +#define VDP_REG_MODE3 11 +#define VDP_REG_MODE4 12 +#define VDP_REG_HSCROLL 13 +#define VDP_REG_AUTOINC 15 +#define VDP_REG_SCROLLSZ 16 +#define VDP_REG_WINX 17 +#define VDP_REG_WINY 18 +#define VDP_REG_DMACNTL 19 +#define VDP_REG_DMACNTH 20 +#define VDP_REG_DMASRCL 21 +#define VDP_REG_DMASRCM 22 +#define VDP_REG_DMASRCH 23 + +#define VDP_ST_PAL 0x001 +#define VDP_ST_DMA 0x002 +#define VDP_ST_HBLANK 0x004 +#define VDP_ST_VBLANK 0x008 +#define VDP_ST_ODDFRM 0x010 +#define VDP_ST_COL 0x020 +#define VDP_ST_SPROVF 0x040 +#define VDP_ST_VINTR 0x080 +#define VDP_ST_FULL 0x100 +#define VDP_ST_EMPT 0x200 + +#define VDP_M1_INIT 0x04 +#define VDP_M1_HVSTOP 0x02 +#define VDP_M1_HINTR 0x10 + +#define VDP_M2_INIT 0x04 +#define VDP_M2_V30 0x08 +#define VDP_M2_DMA 0x10 +#define VDP_M2_VINTR 0x20 +#define VDP_M2_DISP 0x40 + +#define VDP_NA_ADDR(x) (((x) >> 14) & 0x38) +#define VDP_NW_ADDR(x) (((x) >> 14) & 0x3e) +#define VDP_NB_ADDR(x) ((x) >> 17) +#define VDP_SPRTAB_ADDR(x) ((x) >> 9) +#define VDP_HSTAB_ADDR(x) ((x) >> 10) + +#define VDP_BGCOL(pal, col) (((pal) << 4) | (col)) + +#define VDP_M3_HFULL 0 +#define VDP_M3_HCELL 0x02 +#define VDP_M3_HLINE 0x03 +#define VDP_M3_VFULL 0 +#define VDP_M3_V2CELL 0x04 +#define VDP_M3_EXTINTR 0x08 + +#define VDP_M4_H40 0x81 +#define VDP_M4_ILACE 0x02 +#define VDP_M4_ILACE2X 0x06 +#define VDP_M4_SHAD 0x08 + +#define VDP_SCR_H32 0 +#define VDP_SCR_H64 0x01 +#define VDP_SCR_H128 0x03 +#define VDP_SCR_V32 0 +#define VDP_SCR_V64 0x10 +#define VDP_SCR_V128 0x30 + +#define VDP_WINX_RIGHT 0x80 +#define VDP_WINY_DOWN 0x80 + +#define VDP_DMA_MEM 0 +#define VDP_DMA_FILL 0x80 +#define VDP_DMA_COPY 0xc0 #endif /* HWREGS_H_ */ diff --git a/src/main.c b/src/main.c index 34f8626..9816bda 100644 --- a/src/main.c +++ b/src/main.c @@ -1,8 +1,12 @@ #include "z80.h" +#include "vdp.h" int main(void) { z80_init(); + vdp_init(); + + vdp_setcolor(0, 0, 14, 0, 0); return 0; } diff --git a/src/vdp.S b/src/vdp.S new file mode 100644 index 0000000..b794d21 --- /dev/null +++ b/src/vdp.S @@ -0,0 +1,71 @@ + .text + +#define ASM +#include "hwregs.h" + + .globl vdp_init +vdp_init: + move.l #def_reg_tab, %a0 + move.w #0, %d1 +0: move.w %d1, %d0 + lsl.w #8, %d0 + or.w #0x8000, %d0 + move.b (%a0)+, %d0 + move.w %d0, VDP_CTL_PORT | VDP_CTL = 0x8000 | (reg << 8) | val + add.w #1, %d1 + cmp.w def_reg_tab_size, %d1 + bne.s 0b + rts + + | address in d0, type in d1 +setup_addr: + lsl.l #2, %d0 + lsr.w #2, %d0 + swap %d0 + or.l %d1, %d0 + move.l %d0, VDP_CTL_PORT + rts + + .globl vdp_setcolor +vdp_setcolor: + move.l 4(%sp), %d0 | palette number + lsl.l #4, %d0 + add.l 8(%sp), %d0 | add index + move.l #VDP_CRAM, %d1 + bsr setup_addr + move.w 22(%sp), %d0 | blue + lsl.w #4, %d0 + or.w 18(%sp), %d0 | green + lsl.w #4, %d0 + or.w 14(%sp), %d0 | red + and.w #0x0eee, %d0 + move.w %d0, VDP_DATA_PORT + rts + + .data +def_reg_tab: + .byte VDP_M1_INIT | 0: mode 1 + .byte VDP_M2_INIT + VDP_M2_DISP | 1: mode 2 + .byte VDP_NA_ADDR(0xc000) | 2: scroll A nametable addr. + .byte 0 | 3: window nametable addr. + .byte VDP_NB_ADDR(0xd000) | 4: scroll B nametable addr. + .byte VDP_SPRTAB_ADDR(0xe000) | 5: sprite table addr. + .byte 0 + .byte 0 | 7: bg color + .byte 0, 0 + .byte 0 | 10: horiz. interrupt interval + .byte 0 | 11: mode 3 + .byte VDP_M4_H40 | 12: mode 4 + .byte 0 | 13: hscroll table addr. + .byte 0 + .byte 2 | 15: autoincrement 2 bytes + .byte VDP_SCR_H64 | 16: scroll size (64x32) + .byte 0, 0 | 17,18: win x/y pos + .byte 0, 0, 0, 0, 0 | 19-23: DMA regs +def_reg_tab_end: + .align 2 +def_reg_tab_size: + .word def_reg_tab_end - def_reg_tab + + +| vi:ft=gas68k: diff --git a/src/vdp.h b/src/vdp.h new file mode 100644 index 0000000..74199a1 --- /dev/null +++ b/src/vdp.h @@ -0,0 +1,19 @@ +#ifndef VDP_H_ +#define VDP_H_ + +#include "hwregs.h" + +#define VDP_VRAM 0x40000000 +#define VDP_CRAM 0xc0000000 +#define VDP_VSRAM 0x40000010 + +#define vdp_setup_addr(type, addr) \ + (VDP_CTL32 = ((type) | (((addr) & 0x3fff) << 16) | (((addr) >> 14) & 3))) + +#define vdp_setreg(reg, val) \ + (VDP_CTL = 0x8000 | ((reg) << 8) | (val)) + +void vdp_init(void); +void vdp_setcolor(int pal, int cidx, int r, int g, int b); + +#endif /* VDP_H_ */ -- 1.7.10.4