summaryrefslogtreecommitdiff
path: root/source/zx81.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2006-10-09 00:32:14 +0000
committerIan C <ianc@noddybox.co.uk>2006-10-09 00:32:14 +0000
commita50b3820e29af6d12b86c55afb8be1aee9091558 (patch)
treea3e74e4706488db0701bc992b1eb75e29d52e7a1 /source/zx81.c
parent09a74c822519bae9d20f79b8e7808f19c5094e7f (diff)
Working version with a few games included
Diffstat (limited to 'source/zx81.c')
-rw-r--r--source/zx81.c117
1 files changed, 81 insertions, 36 deletions
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 <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include <nds.h>
#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<TXT_W*TXT_H;f++)
+ {
+ *s++=0;
+ }
+
+ s = screen;
+ f = 0;
+
+ while(*p)
+ {
+ switch(*p)
+ {
+ case '\n':
+ s+=32;
+ f=0;
+ break;
+
+ case '%':
+ inv^=0x40;
+ break;
+
+ default:
+ s[f++]=FromASCII(*p)|inv;
+ break;
+ }
+
+ p++;
+ }
+}
+
+
/* END OF FILE */