From a4a31695f8e7d1261f4e42daff9376635d75c582 Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Sun, 5 Jun 2022 16:21:28 +0200 Subject: [PATCH] inc: cleanup and organize header files --- inc/comm.h | 10 ++++++ inc/config.h | 17 ++++++++++ inc/dma_snd.h | 55 +++++++++++++++++++++++++++++++++ inc/eeprom.h | 10 ++++++ inc/init.inc | 15 --------- inc/interrupt.h | 42 +++++++++++++++++++++++++ inc/keypad.h | 12 ++++++++ inc/memory.h | 18 +++++++++++ inc/romheader.h | 21 +++++++++++++ inc/rtc.h | 8 +++++ inc/video.h | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 2 +- 12 files changed, 290 insertions(+), 16 deletions(-) create mode 100644 inc/comm.h create mode 100644 inc/config.h create mode 100644 inc/dma_snd.h create mode 100644 inc/eeprom.h delete mode 100644 inc/init.inc create mode 100644 inc/interrupt.h create mode 100644 inc/keypad.h create mode 100644 inc/memory.h create mode 100644 inc/romheader.h create mode 100644 inc/rtc.h create mode 100644 inc/video.h diff --git a/inc/comm.h b/inc/comm.h new file mode 100644 index 0000000..b621375 --- /dev/null +++ b/inc/comm.h @@ -0,0 +1,10 @@ +/* serial port communication */ +#define IO_COMM_DATA 0xB1 +#define IO_COMM_DIR 0xB3 +#define COMM_RECEIVE_INT_GEN 0x80 +#define COMM_SPEED_9600 0x00 +#define COMM_SPEED_38400 0x40 +#define COMM_SEND_INT_GEN 0x20 +#define COMM_SEND_COMPLETE 0x04 +#define COMM_ERROR 0x02 +#define COMM_RECEIVE_COMPLETE 0x01 diff --git a/inc/config.h b/inc/config.h new file mode 100644 index 0000000..165e474 --- /dev/null +++ b/inc/config.h @@ -0,0 +1,17 @@ +/* stack relative position */ +#define WS_STACK (WS_TILE_BANK - 2) +#define WSC_STACK (WSC_PALETTES - 2) + +/* sizes et al */ +#define MAP_SIZE 0x800 +#define SPR_TABLE_SIZE 0x200 +#define SCREEN_WIDTH 224 +#define SCREEN_HEIGHT 144 +#define SCREEN_TWIDTH (SCREEN_WIDTH / 8) +#define SCREEN_THEIGHT (SCREEN_HEIGHT / 8) +#define MAP_WIDTH 256 +#define MAP_HEIGHT 256 +#define MAP_TWIDTH (MAP_WIDTH / 8) +#define MAP_THEIGHT (MAP_HEIGHT / 8) + +#define BG_CHR(tile,pal,bank,hflip,vflip) (((vflip) << 15) | ((hflip) << 14) | ((bank) << 13) | ((pal) << 9) | (tile)) diff --git a/inc/dma_snd.h b/inc/dma_snd.h new file mode 100644 index 0000000..a918e65 --- /dev/null +++ b/inc/dma_snd.h @@ -0,0 +1,55 @@ +/* dma and sound peripheral */ +#define IOw_DMA_SRC 0x40 +#define IO_DMA_SRC_BANK 0x42 +#define IO_DMA_DST_BANK 0x43 +#define IOw_DMA_DST 0x44 +#define IOw_DMA_SIZE 0x46 +#define IO_DMA_CTRL 0x48 + +#define IOw_SNDDMA_SRC 0x4A +#define IO_SNDDMA_BANK 0x4C +#define IOw_SNDDMA_SIZE 0x4E +#define IO_SNDDMA_CTRL 0x52 + +#define IOw_AUDIO1_FREQ 0x80 +#define IOw_AUDIO2_FREQ 0x82 +#define IOw_AUDIO3_FREQ 0x84 +#define IOw_AUDIO4_FREQ 0x86 +#define IO_AUDIO1_VOL 0x88 +#define IO_AUDIO2_VOL 0x89 +#define IO_AUDIO3_VOL 0x8A +#define IO_AUDIO4_VOL 0x8B +#define IO_AUDIO_SWEEP_VAL 0x8C +#define IO_AUDIO_SWEEP_STEP 0x8D +#define IO_AUDIO_NOISE_CTRL 0x8E +#define IO_AUDIO_SAMPLE 0x8F + +#define DMA_START 0x80 +#define DMA_CHECK 0x80 + +#define NOISE_TYPE(a) (a) +#define NOISE_RESET 0x08 +#define NOISE_ENABLE 0x10 +#define AUDIO_SAMPLE(a) (a >> 6) + +#define IO_AUDIO_CTRL 0x90 + +#define AUDIO_1_ON 0x01 +#define AUDIO_1_OFF 0x00 +#define AUDIO_2_ON 0x02 +#define AUDIO_2_OFF 0x00 +#define AUDIO_3_ON 0x04 +#define AUDIO_3_OFF 0x00 +#define AUDIO_4_ON 0x08 +#define AUDIO_4_OFF 0x00 +#define AUDIO_2_VOICE 0x20 +#define AUDIO_3_SWEEP 0x40 +#define AUDIO_4_NOISE 0x80 + +#define IO_AUDIO_OUTPUT 0x91 +#define AUDIO_OUT_MONO 0x01 +#define AUDIO_OUT_STEREO 0x08 +#define AUDIO_OUT_VOLUME(a) ((a & 0x03) << 1) + +#define IOw_AUDIO_NOISE_CNT 0x92 +#define IO_AUDIO_VOLUME 0x94 /* Global Volume (4 bits) */ diff --git a/inc/eeprom.h b/inc/eeprom.h new file mode 100644 index 0000000..515b66d --- /dev/null +++ b/inc/eeprom.h @@ -0,0 +1,10 @@ +/* eeprom */ +#define IOw_INTERNAL_EEPROM_DATA 0xBA +#define IOw_INTERNAL_EEPROM_ADDRESS 0xBC +#define IOw_INTERNAL_EEPROM_CTRL 0xBE +#define IEEPROM_INIT 0x80 +#define IEEPROM_PROTECT 0x40 +#define IEEPROM_WRITE 0x20 +#define IEEPROM_READ 0x10 +#define IEEPROM_WRITE_COMPLETE 0x02 +#define IEEPROM_READ_COMPLETE 0x01 diff --git a/inc/init.inc b/inc/init.inc deleted file mode 100644 index dce53da..0000000 --- a/inc/init.inc +++ /dev/null @@ -1,15 +0,0 @@ -WS_RAM_BASE equ 0x0000 -WS_TILE_BANK equ 0x2000 -WS_STACK equ WS_TILE_BANK-2 - -WSC_TILE_BANK1 equ 0x4000 -WSC_TILE_BANK2 equ 0x8000 -WSC_RAM_BASE2 equ 0xC000 -WSC_PALETTES equ 0xFE00 -WSC_STACK equ WSC_PALETTES-2 - -MAP_SIZE equ 0x800 -SPR_TABLE_SIZE equ 0x200 - -IO_HARDWARE_TYPE equ 0xA0 -WS_COLOR equ 0x02 diff --git a/inc/interrupt.h b/inc/interrupt.h new file mode 100644 index 0000000..59b1f32 --- /dev/null +++ b/inc/interrupt.h @@ -0,0 +1,42 @@ +/* interrupt vector */ +#define INTVEC_HBLANK_TIMER 7 +#define INTVEC_VBLANK_START 6 +#define INTVEC_VBLANK_TIMER 5 +#define INTVEC_DRAWING_LINE 4 +#define INTVEC_SERIAL_RECEIVE 3 +#define INTVEC_RTC_ALARM 2 +#define INTVEC_KEY_PRESS 1 +#define INTVEC_SERIAL_SEND 0 + +/* timer interrupt */ +#define IO_TIMER_CTRL 0xA2 +#define HBLANK_TIMER_ON 0x01 +#define HBLANK_TIMER_OFF 0x00 +#define HBLANK_TIMER_MODE_ONESHOT 0x00 +#define HBLANK_TIMER_MODE_AUTOPRESET 0x02 +#define VBLANK_TIMER_ON 0x04 +#define VBLANK_TIMER_OFF 0x00 +#define VBLANK_TIMER_MODE_ONESHOT 0x00 +#define VBLANK_TIMER_MODE_AUTOPRESET 0x08 + +#define IOw_HBLANK_FREQ 0xA4 +#define IOw_VBLANK_FREQ 0xA6 +#define IO_HBLANK_CNT1 0xA8 /* Hblank Counter - 1/12000s */ +#define IO_HBLANK_CNT2 0xA9 /*; Hblank Counter - 1/(12000>>8)s */ +#define IO_VBLANK_CNT1 0xAA /* Vblank Counter - 1/75s */ +#define IO_VBLANK_CNT2 0xAB /* Vblank Counter - 1/(75>>8)s */ + +#define IO_INT_BASE 0xB0 +#define INT_BASE 0x20 + +#define IO_INT_ENABLE 0xB2 +#define INT_HBLANK_TIMER 0x80 +#define INT_VBLANK_START 0x40 +#define INT_VBLANK_TIMER 0x20 +#define INT_DRAWING_LINE 0x10 +#define INT_SERIAL_RECEIVE 0x08 +#define INT_RTC_ALARM 0x04 +#define INT_KEY_PRESS 0x02 +#define INT_SERIAL_SEND 0x01 + +#define IO_INT_ACK 0xB6 /* See IO_INT_ENABLE */ diff --git a/inc/keypad.h b/inc/keypad.h new file mode 100644 index 0000000..257e161 --- /dev/null +++ b/inc/keypad.h @@ -0,0 +1,12 @@ +/* keypad */ +#define IO_KEYPAD 0xB5 +#define KEYPAD_READ_ARROWS_V 0x10 +#define KEYPAD_READ_ARROWS_H 0x20 +#define KEYPAD_READ_BUTTONS 0x40 +#define PAD_UP 0x01 +#define PAD_RIGHT 0x02 +#define PAD_DOWN 0x04 +#define PAD_LEFT 0x08 +#define PAD_START 0x02 +#define PAD_A 0x04 +#define PAD_B 0x08 diff --git a/inc/memory.h b/inc/memory.h new file mode 100644 index 0000000..335b10b --- /dev/null +++ b/inc/memory.h @@ -0,0 +1,18 @@ +/* memory addresses */ +#define WS_RAM_BASE 0x0000 +#define WS_TILE_BANK 0x2000 +#define WSC_TILE_BANK1 0x4000 +#define WSC_TILE_BANK2 0x8000 +#define WSC_RAM_BASE2 0xC000 +#define WSC_PALETTES 0xFE00 + +/* hardware device id */ +#define IO_HARDWARE_TYPE 0xA0 +#define WS_COLOR 0x02 +#define WS_MONO 0x00 + +/* banks */ +#define IO_ROM_BASE_BANK 0xC0 +#define IO_SRAM_BANK 0xC1 +#define IO_ROM_BANK_SEGMENT2 0xC2 +#define IO_ROM_BANK_SEGMENT3 0xC3 diff --git a/inc/romheader.h b/inc/romheader.h new file mode 100644 index 0000000..b91b37d --- /dev/null +++ b/inc/romheader.h @@ -0,0 +1,21 @@ +/* romheader */ +#define RH_ROM_4MBITS 0x02 +#define RH_ROM_8MBITS 0x03 +#define RH_ROM_16MBITS 0x04 +#define RH_ROM_32MBITS 0x06 +#define RH_ROM_64MBITS 0x08 +#define RH_ROM_128MBITS 0x09 +#define RH_NO_SRAM 0x00 +#define RH_SRAM_64KBITS 0x01 +#define RH_SRAM_256KBITS 0x02 +#define RH_SRAM_1MBITS 0x03 +#define RH_SRAM_2MBITS 0x04 +#define RH_SRAM_1KBITS 0x10 +#define RH_SRAM_16KBITS 0x20 +#define RH_SRAM_8KBITS 0x50 +#define RH_WS_MONO 0x00 +#define RH_WS_COLOR 0x01 +#define RH_NO_RTC 0x00 +#define RH_RTC 0x01 +#define RH_HORIZONTAL (0x04 + 0x00) +#define RH_VERTICAL (0x04 + 0x01) diff --git a/inc/rtc.h b/inc/rtc.h new file mode 100644 index 0000000..7c46c3a --- /dev/null +++ b/inc/rtc.h @@ -0,0 +1,8 @@ +/* real time clock */ +#define IO_RTC_COMMAND 0xCA +#define RTC_COMMAND_RESET 0x10 +#define RTC_COMMAND_ALARM 0x12 +#define RTC_COMMAND_SET_TIME 0x14 +#define RTC_COMMAND_GET_TIME 0x15 +#define RTC_COMMAND_ACK 0x80 +#define IO_RTC_DATA 0xCB diff --git a/inc/video.h b/inc/video.h new file mode 100644 index 0000000..7a294fb --- /dev/null +++ b/inc/video.h @@ -0,0 +1,96 @@ +/* video peripheral IO */ +#define IO_DISPLAY_CTRL 0x00 +#define IO_BG_PAL 0x01 +#define IO_CUR_LINE 0x02 +#define IO_LINE_COMP 0x03 +#define IO_SPR_TABLE 0x04 +#define IO_SPR_START 0x05 +#define IO_SPR_STOP 0x06 +#define IO_FGBG_MAP 0x07 +#define IO_FG_WIN_X0 0x08 +#define IO_FG_WIN_Y0 0x09 +#define IO_FG_WIN_X1 0x0A +#define IO_FG_WIN_Y1 0x0B +#define IO_SPR_WIN_X0 0x0C +#define IO_SPR_WIN_Y0 0x0D +#define IO_SPR_WIN_X1 0x0E +#define IO_SPR_WIN_Y1 0x0F +#define IO_BG_X 0x10 +#define IO_BG_Y 0x11 +#define IO_FG_X 0x12 +#define IO_FG_Y 0x13 +#define IO_LCD_CTRL 0x14 +#define IO_LCD_ICONS 0x15 + +/* settings */ +#define BG_ON 0x01 +#define BG_OFF 0x00 +#define FG_ON 0x02 +#define FG_OFF 0x00 +#define SPR_ON 0x04 +#define SPR_OFF 0x00 +#define SPR_WIN_ON 0x08 +#define SPR_WIN_OFF 0x00 +#define FG_IN_OUT_WIN 0x00 +#define FG_IN_WIN 0x10 +#define FG_OUT_WIN 0x30 +#define BG_COLOR(a) (a) +#define BG_PAL(a) (a << 4) +#define SPR_TABLE(a) (a >> 9) /* Sprite Table Address must be 512 bytes aligned */ +#define FG_MAP(a) ((a >> 11) << 4) /* FG Map Address must be 2048 bytes aligned */ +#define BG_MAP(a) (a >> 11) /* BG Map Address must be 2048 bytes aligned */ + +#define IO_VIDEO_MODE 0x60 +#define VMODE_16C_CHK 0xE0 /* 16 colors per tile chunky mode */ +#define VMODE_16C_PLN 0xC0 /* 16 colors per tile planar mode */ +#define VMODE_4C 0x40 /* 4 colors per tile color */ +#define VMODE_4C_MONO 0x00 /* 4 colors per tile mono */ +#define VMODE_CLEANINIT 0x0C /*(?) from FF2 */ + +#define LCD_ON 0x01 +#define LCD_OFF 0x00 + +#define LCD_ICON_SLEEP 0x01 +#define LCD_ICON_VERTI 0x02 +#define LCD_ICON_HORIZ 0x04 +#define LCD_ICON_DOT1 0x08 +#define LCD_ICON_DOT2 0x10 +#define LCD_ICON_DOT3 0x20 + +/* PAL modes */ +#define IO_PALSHADE_10 0x1C +#define IO_PALSHADE_32 0x1D +#define IO_PALSHADE_54 0x1E +#define IO_PALSHADE_76 0x1F +#define IO_WS_PAL_00 0x20 +#define IO_WS_PAL_01 0x21 +#define IO_WS_PAL_10 0x22 +#define IO_WS_PAL_11 0x23 +#define IO_WS_PAL_20 0x24 +#define IO_WS_PAL_21 0x25 +#define IO_WS_PAL_30 0x26 +#define IO_WS_PAL_31 0x27 +#define IO_WS_PAL_40 0x28 +#define IO_WS_PAL_41 0x29 +#define IO_WS_PAL_50 0x2A +#define IO_WS_PAL_51 0x2B +#define IO_WS_PAL_60 0x2C +#define IO_WS_PAL_61 0x2D +#define IO_WS_PAL_70 0x2E +#define IO_WS_PAL_71 0x2F +#define IO_WS_PAL_80 0x30 +#define IO_WS_PAL_81 0x31 +#define IO_WS_PAL_90 0x32 +#define IO_WS_PAL_91 0x33 +#define IO_WS_PAL_A0 0x34 +#define IO_WS_PAL_A1 0x35 +#define IO_WS_PAL_B0 0x36 +#define IO_WS_PAL_B1 0x37 +#define IO_WS_PAL_C0 0x38 +#define IO_WS_PAL_C1 0x39 +#define IO_WS_PAL_D0 0x3A +#define IO_WS_PAL_D1 0x3B +#define IO_WS_PAL_E0 0x3C +#define IO_WS_PAL_E1 0x3D +#define IO_WS_PAL_F0 0x3E +#define IO_WS_PAL_F1 0x3F diff --git a/src/main.c b/src/main.c index 1ce8228..375b587 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,5 @@ /* #include */ -#include +#include void outport(c) unsigned c; -- 2.7.4