hardware.h (5641B)
1/** @file sms/hardware.h 2 Defines that let the SMS/GG hardware registers be accessed 3 from C. 4*/ 5#ifndef _HARDWARE_H 6#define _HARDWARE_H 7 8#include <types.h> 9 10#define __BYTES extern UBYTE 11#define __BYTE_REG extern volatile UBYTE 12 13static volatile SFR AT(0x3E) MEMORY_CTL; 14 15#define MEMCTL_JOYON 0b00000000 16#define MEMCTL_JOYOFF 0b00000100 17#define MEMCTL_BASEON 0b00000000 18#define MEMCTL_BASEOFF 0b00001000 19#define MEMCTL_RAMON 0b00000000 20#define MEMCTL_RAMOFF 0b00010000 21#define MEMCTL_CROMON 0b00000000 22#define MEMCTL_CROMOFF 0b00100000 23#define MEMCTL_ROMON 0b00000000 24#define MEMCTL_ROMOFF 0b01000000 25#define MEMCTL_EXTON 0b00000000 26#define MEMCTL_EXTOFF 0b10000000 27 28static volatile SFR AT(0x3F) JOY_CTL; 29 30#define JOY_P1_LATCH 0b00000010 31#define JOY_P2_LATCH 0b00001000 32 33static volatile SFR AT(0x7E) VCOUNTER; 34 35static volatile SFR AT(0x7F) PSG; 36 37#define PSG_LATCH 0x80 38 39#define PSG_CH0 0b00000000 40#define PSG_CH1 0b00100000 41#define PSG_CH2 0b01000000 42#define PSG_CH3 0b01100000 43 44#define PSG_VOLUME 0b00010000 45 46static volatile SFR AT(0x7F) HCOUNTER; 47 48static volatile SFR AT(0xBE) VDP_DATA; 49static volatile SFR AT(0xBF) VDP_CMD; 50static volatile SFR AT(0xBF) VDP_STATUS; 51 52#define STATF_INT_VBL 0b10000000 53#define STATF_9_SPR 0b01000000 54#define STATF_SPR_COLL 0b00100000 55 56#define VDP_REG_MASK 0b10000000 57#define VDP_R0 0b10000000 58extern UBYTE shadow_VDP_R0; 59 60#define R0_VSCRL 0b00000000 61#define R0_VSCRL_INH 0b10000000 62#define R0_HSCRL 0b00000000 63#define R0_HSCRL_INH 0b01000000 64#define R0_NO_LCB 0b00000000 65#define R0_LCB 0b00100000 66#define R0_IE1_OFF 0b00000000 67#define R0_IE1 0b00010000 68#define R0_SS_OFF 0b00000000 69#define R0_SS 0b00001000 70#define R0_DEFAULT 0b00000110 71#define R0_ES_OFF 0b00000000 72#define R0_ES 0b00000001 73 74#define VDP_R1 0b10000001 75extern UBYTE shadow_VDP_R1; 76 77#define R1_DEFAULT 0b10000000 78#define R1_DISP_OFF 0b00000000 79#define R1_DISP_ON 0b01000000 80#define R1_IE_OFF 0b00000000 81#define R1_IE 0b00100000 82#define R1_SPR_8X8 0b00000000 83#define R1_SPR_8X16 0b00000010 84 85#define VDP_R2 0b10000010 86extern UBYTE shadow_VDP_R2; 87 88#define R2_MAP_0x3800 0xFF 89#define R2_MAP_0x3000 0xFD 90#define R2_MAP_0x2800 0xFB 91#define R2_MAP_0x2000 0xF9 92#define R2_MAP_0x1800 0xF7 93#define R2_MAP_0x1000 0xF5 94#define R2_MAP_0x0800 0xF3 95#define R2_MAP_0x0000 0xF1 96 97#define VDP_R3 0b10000011 98extern UBYTE shadow_VDP_R3; 99#define VDP_R4 0b10000100 100extern UBYTE shadow_VDP_R4; 101#define VDP_R5 0b10000101 102extern UBYTE shadow_VDP_R5; 103 104#define R5_SAT_0x3F00 0xFF 105#define R5_SAT_MASK 0b10000001 106 107#define VDP_R6 0b10000110 108extern UBYTE shadow_VDP_R6; 109 110#define R6_BANK0 0xFB 111#define R6_DATA_0x0000 0xFB 112#define R6_BANK1 0xFF 113#define R6_DATA_0x2000 0xFF 114 115#define VDP_R7 0b10000111 116extern UBYTE shadow_VDP_R7; 117#define VDP_RBORDER 0b10000111 118extern UBYTE shadow_VDP_RBORDER; 119 120#define R7_COLOR_MASK 0b11110000 121 122#define VDP_R8 0b10001000 123extern UBYTE shadow_VDP_R8; 124#define VDP_RSCX 0b10001000 125extern UBYTE shadow_VDP_RSCX; 126 127#define VDP_R9 0b10001001 128extern UBYTE shadow_VDP_R9; 129#define VDP_RSCY 0b10001001 130extern UBYTE shadow_VDP_RSCY; 131 132#define VDP_R10 0b10001010 133extern UBYTE shadow_VDP_R10; 134 135#define R10_INT_OFF 0xFF 136#define R10_INT_EVERY 0x00 137 138static volatile SFR AT(0xDC) JOY_PORT1; 139 140#define JOY_P1_UP 0b00000001 141#define JOY_P1_DOWN 0b00000010 142#define JOY_P1_LEFT 0b00000100 143#define JOY_P1_RIGHT 0b00001000 144#define JOY_P1_SW1 0b00010000 145#define JOY_P1_TRIGGER 0b00010000 146#define JOY_P1_SW2 0b00100000 147#define JOY_P2_UP 0b01000000 148#define JOY_P2_DOWN 0b10000000 149 150static volatile SFR AT(0xDD) JOY_PORT2; 151 152#define JOY_P2_LEFT 0b00000001 153#define JOY_P2_RIGHT 0b00000010 154#define JOY_P2_SW1 0b00000100 155#define JOY_P2_TRIGGER 0b00000100 156#define JOY_P2_SW2 0b00001000 157#define JOY_RESET 0b00010000 158#define JOY_P1_LIGHT 0b01000000 159#define JOY_P2_LIGHT 0b10000000 160 161static volatile SFR AT(0xF0) FMADDRESS; 162static volatile SFR AT(0xF1) FMDATA; 163static volatile SFR AT(0xF2) AUDIOCTRL; 164 165static volatile UBYTE AT(0xfffc) RAM_CONTROL; 166 167#define RAMCTL_BANK 0b00000100 168#define RAMCTL_ROM 0b00000000 169#define RAMCTL_RAM 0b00001000 170#define RAMCTL_RO 0b00010000 171#define RAMCTL_PROT 0b10000000 172 173static volatile UBYTE AT(0xfff8) GLASSES_3D; 174 175static volatile UBYTE AT(0xfffd) MAP_FRAME0; 176static volatile UBYTE AT(0xfffe) MAP_FRAME1; 177static volatile UBYTE AT(0xffff) MAP_FRAME2; 178 179extern const UBYTE _BIOS; 180 181extern const UBYTE _SYSTEM; 182 183#define SYSTEM_PAL 0x00 184#define SYSTEM_NTSC 0x01 185 186extern volatile UBYTE VDP_ATTR_SHIFT; 187 188#define VDP_SAT_TERM 0xD0 189 190#if defined(__TARGET_sms) 191#define DEVICE_SCREEN_X_OFFSET 0 192#define DEVICE_SCREEN_Y_OFFSET 0 193#define DEVICE_SCREEN_WIDTH 32 194#define DEVICE_SCREEN_HEIGHT 24 195#define DEVICE_SCREEN_BUFFER_WIDTH 32 196#define DEVICE_SCREEN_BUFFER_HEIGHT 28 197#define DEVICE_SCREEN_MAP_ENTRY_SIZE 2 198#define DEVICE_SPRITE_PX_OFFSET_X 0 199#define DEVICE_SPRITE_PX_OFFSET_Y -1 200#elif defined(__TARGET_gg) 201#define DEVICE_SCREEN_X_OFFSET 6 202#define DEVICE_SCREEN_Y_OFFSET 3 203#define DEVICE_SCREEN_WIDTH 20 204#define DEVICE_SCREEN_HEIGHT 18 205#define DEVICE_SCREEN_BUFFER_WIDTH 32 206#define DEVICE_SCREEN_BUFFER_HEIGHT 28 207#define DEVICE_SCREEN_MAP_ENTRY_SIZE 2 208#define DEVICE_SPRITE_PX_OFFSET_X 48 209#define DEVICE_SPRITE_PX_OFFSET_Y 23 210#else 211#error Unrecognized port 212#endif 213#define DEVICE_SCREEN_PX_WIDTH (DEVICE_SCREEN_WIDTH * 8) 214#define DEVICE_SCREEN_PX_HEIGHT (DEVICE_SCREEN_HEIGHT * 8) 215 216#endif