Last active
November 25, 2020 19:50
-
-
Save kisssko/e7e5520ab306944d2b90a63b4f5189ee to your computer and use it in GitHub Desktop.
ZX-Spectrum useful definition stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef SDCC_ZX_H | |
#define SDCC_ZX_H | |
#include <stdint.h> | |
// ### __z88dk_fastcall call convention in SDCC ### | |
// 32 bit: input - DEHL, output - DEHL. | |
// 16 bit: input - HL, output - HL. | |
// 8 bit: input - L, output - L. | |
#define fastcall __z88dk_fastcall | |
#define DEFPORT16(P,N) __sfr __banked __at(P) N | |
#define DEFPORT8(P,N) __sfr __at(P) N | |
#define DEFVAR_AT(A,T,N) __at A T N | |
#define FORCE_USE(VAR) VAR|=0 | |
#define ARG2FC(A,B) (((uint16_t)(A)) << 8 | ((uint16_t)(B))) | |
#define _ROWAB(A,B) (((A) << 3) | (B)) | |
#define _ROWAY(A,Y) _ROWAB(A+0,Y), _ROWAB(A+1,Y), \ | |
_ROWAB(A+2,Y), _ROWAB(A+3,Y) | |
#define _ROWA(A) _ROWAY(0, A), _ROWAY(4, A) | |
#define _ROWH(H) _ROWA(H+0), _ROWA(H+1), \ | |
_ROWA(H+2), _ROWA(H+3) | |
#define _ROWTAB _ROWH(0), _ROWH(4) | |
#define DEF_ROWTAB(N) const uint8_t N[64] = {_ROWTAB} | |
typedef union | |
{ | |
struct | |
{ | |
unsigned char ink :4; | |
unsigned char paper :3; | |
unsigned char flash :1; | |
}; | |
unsigned char val; | |
} attr_t; | |
typedef uint8_t pixels_t[192][32]; | |
typedef attr_t attrs_t[24][32]; | |
typedef uint8_t symdef_t[8]; | |
typedef uint8_t u24_t[3]; | |
typedef uint8_t kstate_t[8]; | |
typedef struct | |
{ | |
pixels_t p; | |
attrs_t a; | |
} screen_t; | |
typedef union | |
{ | |
struct | |
{ | |
uint8_t r:1; | |
uint8_t l:1; | |
uint8_t d:1; | |
uint8_t u:1; | |
uint8_t f:1; | |
uint8_t o:3; | |
}; | |
uint8_t byte; | |
} kempston_t; | |
typedef union | |
{ | |
struct | |
{ | |
uint8_t page:3; | |
uint8_t screen:1; | |
uint8_t rom:1; | |
uint8_t lock:1; | |
uint8_t other:2; | |
}; | |
uint8_t byte; | |
} port_7ffd_t; | |
typedef union | |
{ | |
struct | |
{ | |
uint8_t keys:5; | |
uint8_t d5:1; | |
uint8_t ear:1; | |
uint8_t d7:1; | |
} r; | |
struct | |
{ | |
uint8_t border:3; | |
uint8_t mic:1; | |
uint8_t beep:1; | |
uint8_t d5:1; | |
uint8_t d6:1; | |
uint8_t d7:1; | |
} w; | |
uint8_t byte; | |
} portb_t; | |
typedef struct {uint8_t x,y;} point_t; | |
// SCREEN | |
DEFVAR_AT(0x4000, screen_t, SCREEN); // 16384 | |
// SYS VARS | |
DEFVAR_AT(0x5C00, kstate_t, KSTATE); // IY-58 | |
DEFVAR_AT(0x5C0B, uint8_t*, DEFADD); // IY-47 | |
DEFVAR_AT(0x5C3A, uint8_t, ERR_NR); // IY+0 | |
DEFVAR_AT(0x5C48, uint8_t, BORDCR); // IY+14 | |
DEFVAR_AT(0x5C4B, uint8_t*, __VARS); // IY+17 | |
DEFVAR_AT(0x5C53, uint8_t*, __PROG); // IY+25 | |
DEFVAR_AT(0x5C61, uint8_t*, WORKSP); // IY+39 | |
DEFVAR_AT(0x5C76, uint16_t, __SEED); // IY+60 | |
DEFVAR_AT(0x5C78, u24_t, FRAMES); // IY+62 | |
DEFVAR_AT(0x5C7B, uint8_t*, ___UDG); // IY+65 | |
DEFVAR_AT(0x5C7D, point_t, COORDS); // IY+66 | |
DEFVAR_AT(0x5C84, uint8_t*, _DF_CC); // IY+74 | |
DEFVAR_AT(0x5C84, attr_t, ATTR_P); // IY+83 | |
DEFVAR_AT(0x5CB0, void*, NMIADD); // IY+118 | |
DEFVAR_AT(0x5CB2, uint8_t*, RAMTOP); // IY+120 | |
DEFPORT8(0x001F, kempjoy); // Kempston joystick | |
DEFPORT16(0x7FFD, memctl); // ZX 128K memory control | |
DEFPORT16(0xFFFE, portb); // border, tape, beep. | |
DEFPORT16(0x7FFE, kbd0); | |
DEFPORT16(0xBFFE, kbd1); | |
DEFPORT16(0xDFFE, kbd2); | |
DEFPORT16(0xEFFE, kbd3); | |
DEFPORT16(0xF7FE, kbd4); | |
DEFPORT16(0xFBFE, kbd5); | |
DEFPORT16(0xFDFE, kbd6); | |
DEFPORT16(0xFEFE, kbd7); | |
#define _ei() __asm ei __endasm | |
#define _di() __asm di __endasm | |
#define _halt() __asm halt __endasm | |
#define _push(REG) __asm push REG __endasm | |
#define _pop(REG) __asm pop REG __endasm | |
#define _call(ADDR) __asm call ADDR __endasm | |
#define _ret() __asm ret __endasm | |
#define _reti() __asm reti __endasm | |
#define _retn() __asm retn __endasm | |
#endif // SDCC_ZX_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment