From a50b3820e29af6d12b86c55afb8be1aee9091558 Mon Sep 17 00:00:00 2001 From: Ian C Date: Mon, 9 Oct 2006 00:32:14 +0000 Subject: Working version with a few games included --- source/zx81.c | 117 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 81 insertions(+), 36 deletions(-) (limited to 'source/zx81.c') diff --git a/source/zx81.c b/source/zx81.c index 5b8f6b7..2b81e2b 100644 --- a/source/zx81.c +++ b/source/zx81.c @@ -25,12 +25,12 @@ #include #include #include +#include #include #include "zx81.h" #include "zx81_bin.h" -#include "maze_bin.h" #ifndef TRUE #define TRUE 1 @@ -84,6 +84,11 @@ static Z80Word RAMLEN=0; #define WORD(a) (mem[a] | (Z80Word)mem[a+1]<<8) +/* Tape +*/ +static const Z80Byte *tape_image; +static int tape_len; + /* GFX vars */ static uint16 *screen; @@ -199,58 +204,52 @@ static void RomPatch(void) mem[0x02ec]=0; } -static char ToASCII(Z80Byte b) +static Z80Byte FromASCII(char c) { - if (b==0) /* SPACE */ - return ' '; - - if (b==22) /* Dash (-) */ - return '-'; - - if (b==27) /* Period (.) */ - return '.'; - - if (b>=28 && b<=37) /* 0-9 */ - return '0'+b-28; + switch(c) + { + case '\'': + case '"': + return 11; - if (b>=38 && b<=63) /* A-Z */ - return 'a'+b-38; + case '(': + return 16; - return 0; -} + case ')': + return 17; + case '-': + return 22; -static const char *ConvertFilename(Z80Word addr) -{ - static char buff[FILENAME_MAX]; - char *p; + case '*': + return 23; - p=buff; - *p=0; + case ',': + return 26; - if (addr>0x8000) - { - return buff; + case '.': + return 27; } - do - { - char c=ToASCII(mem[addr]&0x7f); + if (c>='0' && c<='9') + return (c-'0')+28; - if (c) - *p++=c; + if (c>='a' && c<='z') + return (c-'a')+38; - } while(mem[addr++]<0x80); + if (c>='A' && c<='Z') + return (c-'A')+38; - *p=0; - - return buff; + return 0; } static void LoadTape(Z80 *z80) { - memcpy(mem+0x4009,maze_bin,maze_bin_size); + if (tape_image) + { + memcpy(mem+0x4009,tape_image,tape_len); + } } @@ -630,4 +629,50 @@ void ZX81Reset(Z80 *z80) } +void ZX81SetTape(const Z80Byte *image, int len) +{ + tape_image=image; + tape_len=len; +} + + +void ZX81DisplayString(const char *p) +{ + uint16 *s; + uint16 inv=0; + int f; + + s = screen; + + for(f=0;f