--- /dev/null
+/* 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
--- /dev/null
+/* 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))
--- /dev/null
+/* 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) */
--- /dev/null
+/* 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
+++ /dev/null
-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
--- /dev/null
+/* 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 */
--- /dev/null
+/* 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
--- /dev/null
+/* 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
--- /dev/null
+/* 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)
--- /dev/null
+/* 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
--- /dev/null
+/* 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
/* #include <code16bit.h> */
-#include <wonderswan_mem.h>
+#include <memory.h>
void outport(c)
unsigned c;