From 6be2806499299bb13edde3481803f28416429902 Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 1 Mar 2007 00:36:54 +0000 Subject: Changed lower screen to 8-bits and added overlayed text mode. Monitor stub in place. Text mode helpers being developed. --- CHANGES | 3 + data/cpatrol_inlay.bin | Bin 28889 -> 7485 bytes data/keyb.bin | Bin 16390 -> 13447 bytes data/maze_inlay.bin | Bin 32392 -> 10654 bytes data/mazogs_inlay.bin | Bin 36155 -> 15329 bytes data/sabotage_inlay.bin | Bin 26323 -> 12794 bytes data/splashimg.bin | Bin 23615 -> 19171 bytes include/framebuffer.h | 69 ++++++++++++++--- include/monitor.h | 27 +++++++ include/textmode.h | 37 ++++++++++ include/z80_config.h | 2 +- include/zx81.h | 2 + source/framebuffer.c | 193 ++++++++++++++++++++++++++++++++++-------------- source/gui.c | 70 +++++++++--------- source/keyboard.c | 18 +++-- source/main.c | 105 +++++++++++++++++++------- source/monitor.c | 32 ++++++++ source/tapes.c | 19 +++-- source/textmode.c | 146 ++++++++++++++++++++++++++++++++++++ 19 files changed, 578 insertions(+), 145 deletions(-) create mode 100644 include/monitor.h create mode 100644 include/textmode.h create mode 100644 source/monitor.c create mode 100644 source/textmode.c diff --git a/CHANGES b/CHANGES index 9a0170f..513e4a5 100644 --- a/CHANGES +++ b/CHANGES @@ -34,3 +34,6 @@ Changes from V1.1a to V1.2 + Added file selector with LOAD "*" + Handling of 1K display files is a bit better. + Added option for RAM in place of ROM mirror. + + Changed lower screen to 8-bit deep so I can overlay a tiled mode. + * Added lower screen console routines. + * Added Machine Code Monitor. diff --git a/data/cpatrol_inlay.bin b/data/cpatrol_inlay.bin index af70c60..6349d6f 100644 Binary files a/data/cpatrol_inlay.bin and b/data/cpatrol_inlay.bin differ diff --git a/data/keyb.bin b/data/keyb.bin index 3759ec5..adbfd5d 100644 Binary files a/data/keyb.bin and b/data/keyb.bin differ diff --git a/data/maze_inlay.bin b/data/maze_inlay.bin index 26a7e97..d48cb22 100644 Binary files a/data/maze_inlay.bin and b/data/maze_inlay.bin differ diff --git a/data/mazogs_inlay.bin b/data/mazogs_inlay.bin index a725c57..1088716 100644 Binary files a/data/mazogs_inlay.bin and b/data/mazogs_inlay.bin differ diff --git a/data/sabotage_inlay.bin b/data/sabotage_inlay.bin index da3f094..904c29a 100644 Binary files a/data/sabotage_inlay.bin and b/data/sabotage_inlay.bin differ diff --git a/data/splashimg.bin b/data/splashimg.bin index 38161e4..de16798 100644 Binary files a/data/splashimg.bin and b/data/splashimg.bin differ diff --git a/include/framebuffer.h b/include/framebuffer.h index 7b04685..3055e51 100644 --- a/include/framebuffer.h +++ b/include/framebuffer.h @@ -22,17 +22,64 @@ #ifndef DS81_FRAMEBUFFER_H #define DS81_FRAMEBUFFER_H -#define FB_RGB(r,g,b) ((RGB15(r,g,b))|0x8000) - -void FB_Init(uint16 *vram); -void FB_Print(const char *text, int x, int y, int colour, int paper); -void FB_Centre(const char *text, int y, int colour, int paper); -void FB_printf(int x, int y, int colour, int paper, const char *format, ...); -void FB_HLine(int x1, int x2, int y, int colour); -void FB_VLine(int x, int y1, int y2, int colour); -void FB_Box(int x, int y, int w, int h, int colour); -void FB_FillBox(int x, int y, int w, int h, int colour); +/* Predefined colours. +*/ +typedef enum +{ + COL_TRANSPARENT = -1, + COL_BLACK = 0, + COL_WHITE = 240, + COL_RED = 241, + COL_GREEN = 242, + COL_BLUE = 243, + COL_GUISELECT = 244, + COL_GREY = 245, + COL_LIGHTGREY = 246, + COL_DARKGREY = 247, + COL_YELLOW = 248 +} FB_Colour; + + +/* Initialise 'framebuffer' code. vram is where the 8-bit framebuffer is. + palette is the palette to use/set. +*/ +void FB_Init(uint16 *vram, uint16 *palette); + +/* Load the internal framebuffer font as a set of ASCII tiles (starting with + space) at tiles. The tiles will use colour COL_WHITE. +*/ +void FB_LoadASCIITiles(uint16 *tiles); + +/* Print the text into the framebuffer. +*/ +void FB_Print(const char *text, int x, int y, + FB_Colour colour, FB_Colour paper); +void FB_Centre(const char *text, int y, + FB_Colour colour, FB_Colour paper); +void FB_printf(int x, int y, FB_Colour colour, FB_Colour paper, + const char *format, ...); + +/* Lines and boxes. +*/ +void FB_HLine(int x1, int x2, int y, FB_Colour colour); +void FB_VLine(int x, int y1, int y2, FB_Colour colour); +void FB_Box(int x, int y, int w, int h, FB_Colour colour); +void FB_FillBox(int x, int y, int w, int h, FB_Colour colour); + +/* Clear to background +*/ void FB_Clear(void); -void FB_Blit(sImage *img, int x, int y); + +/* Draw the image. The image must be an 8-bit image, but with only the first + 16 palette entries used. Just to complicate matters! + + The image is assumed to be an even number of pixels wide. Also the passed + X co-ord will be forced even. + + offset is used to give an offset into the palette to place colours from the + image. Palette entries 1 - 128 will always be safe to use (these routines + will never use them). +*/ +void FB_Blit(sImage *img, int x, int y, int offset); #endif /* DS81_FRAMEBUFFER_H */ diff --git a/include/monitor.h b/include/monitor.h new file mode 100644 index 0000000..5bbdc8b --- /dev/null +++ b/include/monitor.h @@ -0,0 +1,27 @@ +/* + ds81 - Nintendo DS ZX81 emulator. + + Copyright (C) 2007 Ian Cowburn + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + $Id$ +*/ +#ifndef DS81_MONITOR_H +#define DS81_MONITOR_H + +void MachineCodeMonitor(void); + +#endif /* DS81_MONITOR_H */ diff --git a/include/textmode.h b/include/textmode.h new file mode 100644 index 0000000..751ad05 --- /dev/null +++ b/include/textmode.h @@ -0,0 +1,37 @@ +/* + ds81 - Nintendo DS ZX81 emulator. + + Copyright (C) 2007 Ian Cowburn + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + $Id$ +*/ +#ifndef DS81_TEXTMODE_H +#define DS81_TEXTMODE_H + +/* Note that the co-ords are into the map -- the user is free to use this and + move the map around, scale it, blend it, do want they want with it... + + The routines assume they can write into this map using the ASCII code + with 32 subtracted for each char. +*/ +void TM_Init(uint16 *vram, int map_width, int map_height, int map_is_rotation); + +void TM_Cls(void); +void TM_Put(int x, int y, const char *str); +void TM_printf(int x, int y, const char *format, ...); + +#endif /* DS81_TEXTMODE_H */ diff --git a/include/z80_config.h b/include/z80_config.h index 8be062b..af36944 100644 --- a/include/z80_config.h +++ b/include/z80_config.h @@ -34,8 +34,8 @@ /* Define this to enable the disassembly interface -#define ENABLE_DISASSEM */ +#define ENABLE_DISASSEM /* Define this to enable the array-based memory model. In this mode diff --git a/include/zx81.h b/include/zx81.h index c50c1a4..2606c98 100644 --- a/include/zx81.h +++ b/include/zx81.h @@ -77,6 +77,8 @@ void ZX81WriteMem(Z80 *z80, Z80Word addr, Z80Byte val); Z80Byte ZX81ReadPort(Z80 *z80, Z80Word port); void ZX81WritePort(Z80 *z80, Z80Word port, Z80Byte val); +#define ZX81ReadDisassem ZX81ReadMem + #endif diff --git a/source/framebuffer.c b/source/framebuffer.c index 691862e..6d16529 100644 --- a/source/framebuffer.c +++ b/source/framebuffer.c @@ -25,12 +25,16 @@ #include #include +#include "framebuffer.h" + /* ---------------------------------------- STATIC DATA */ #define WIDTH 256 +#define SCAN 128 #define HEIGHT 192 -static uint16 *buff=0; +static uint16 *buff; +static uint16 *pal; static uint8 font[]= { @@ -132,60 +136,138 @@ static uint8 font[]= 0x3c, 0x42, 0x99, 0x85, 0x85, 0x99, 0x42, 0x3c }; + +/* ---------------------------------------- PRIVATE INTERFACES +*/ +static inline void Plot(int x, int y, int col) +{ + uint16 *base; + uint16 cur; + int odd; + + if (col == -1) + return; + + odd = x&1; + x /= 2; + + base = buff+x+y*SCAN; + cur = *base; + + if (odd) + { + cur = (cur & 0xff) | (col<<8); + } + else + { + cur = (cur & 0xff00) | col; + } + + *base = cur; +} + + /* ---------------------------------------- PUBLIC INTERFACES */ -void FB_Init(uint16 *vram) +void FB_Init(uint16 *vram, uint16 *palette) { - buff=vram; + buff = vram; + pal = palette; + + pal[COL_BLACK] = RGB15(0,0,0); + pal[COL_WHITE] = RGB15(31,31,31); + pal[COL_RED] = RGB15(31,0,0); + pal[COL_GREEN] = RGB15(0,31,0); + pal[COL_BLUE] = RGB15(0,0,31); + pal[COL_GUISELECT] = RGB15(8,8,31); + pal[COL_GREY] = RGB15(15,15,15); + pal[COL_LIGHTGREY] = RGB15(22,22,22); + pal[COL_DARKGREY] = RGB15(8,8,8); + pal[COL_YELLOW] = RGB15(31,31,0); } -void FB_Print(const char *text, int x, int y, int colour, int paper) +void FB_LoadASCIITiles(uint16 *tiles) { - uint16 *base; + uint8 *src; + int c; + int row; + int val; + int mask; - base=buff+y*WIDTH+x; + src = font; - while(*text) + for(c = 32; c < 127; c++) { - int x,y; - int ch; + for(row = 0; row < 8; row++) + { + for(mask = 1; mask < 0xff; mask<<=1) + { + if (*src & mask) + { + val = COL_WHITE; + } + else + { + val = 0; + } + + mask <<= 1; + + if (*src & mask) + { + val |= COL_WHITE << 8; + } + + *tiles++ = val; + } + + src++; + } + } +} + +void FB_Print(const char *text, int x, int y, FB_Colour colour, FB_Colour paper) +{ + int cx,cy; + int ch; + + while(*text) + { ch=((*text)-32)*8; - for(y=0;y<8;y++) + for(cy=0;cy<8;cy++) { - for(x=0;x<8;x++) + for(cx=0;cx<8;cx++) { - if (font[ch]&(1<width==WIDTH && img->height==HEIGHT) + uint16 *dest; + uint16 *row; + uint8 *src; + uint16 pix; + int hww; + int ht; + int f; + + x /= 2; + + ht = img->height; + hww = img->width / 2; + dest = buff+x+y*SCAN; + src = img->image.data8; + + for(f=0;f<16;f++) { - dmaCopy(img->image.data8,buff,SCREEN_WIDTH*SCREEN_HEIGHT*2); + pal[offset+f] = img->palette[f]; } - else + + while(ht--) { - int f; + row = dest; - for(f=0;fheight;f++) + for(f=0;fimage.data16+(f*img->width), - buff+x+(y+f)*WIDTH,img->width*2); + pix = *src++ + offset; + pix |= (*src++ + offset) << 8; + + *row++ = pix; } + + dest += SCAN; } } diff --git a/source/gui.c b/source/gui.c index 92f6836..2027a37 100644 --- a/source/gui.c +++ b/source/gui.c @@ -219,13 +219,13 @@ int GUI_Menu(const char *opts[]) { uint32 key=0; - FB_FillBox(x,y,w,h,FB_RGB(0,0,0)); - FB_Box(x,y,w,h,FB_RGB(31,31,31)); - FB_FillBox(x+1,y+sel*16+1,w-2,14,FB_RGB(8,8,31)); + FB_FillBox(x,y,w,h,COL_BLACK); + FB_Box(x,y,w,h,COL_WHITE); + FB_FillBox(x+1,y+sel*16+1,w-2,14,COL_GUISELECT); for(f=0;fline) { *d=0; - FB_Centre(line,h,FB_RGB(31,31,31),-1); + FB_Centre(line,h,COL_WHITE,COL_TRANSPARENT); h+=8; } if (!fatal) { - FB_Centre("PRESS ANY BUTTON OR SCREEN",h+16,FB_RGB(31,31,0),-1); + FB_Centre("PRESS ANY BUTTON OR SCREEN",h+16,COL_YELLOW,COL_TRANSPARENT); while(!keysDown()) { @@ -336,7 +336,7 @@ void GUI_Alert(int fatal, const char *text) } else { - FB_Centre("PLEASE RESET YOUR CONSOLE",h+16,FB_RGB(31,31,0),-1); + FB_Centre("PLEASE RESET YOUR CONSOLE",h+16,COL_YELLOW,COL_TRANSPARENT); while(1) { @@ -359,18 +359,18 @@ void GUI_Config(void) FB_Clear(); - FB_Centre("Up/Down to select",140,FB_RGB(31,31,0),-1); - FB_Centre("A to toggle",150,FB_RGB(31,31,0),-1); - FB_Centre("Or use touchscreen",160,FB_RGB(31,31,0),-1); - FB_Centre("START to finish",170,FB_RGB(31,31,0),-1); + FB_Centre("Up/Down to select",140,COL_YELLOW,COL_TRANSPARENT); + FB_Centre("A to toggle",150,COL_YELLOW,COL_TRANSPARENT); + FB_Centre("Or use touchscreen",160,COL_YELLOW,COL_TRANSPARENT); + FB_Centre("START to finish",170,COL_YELLOW,COL_TRANSPARENT); #ifndef DS81_DISABLE_FAT - FB_Centre("SELECT to finish and save",180,FB_RGB(31,31,0),-1); + FB_Centre("SELECT to finish and save",180,COL_YELLOW,COL_TRANSPARENT); #endif for(f=0;fHL.w); + TM_printf(0,23,"PC = %4.4x",z80->PC); + Z80Exec(z80); while(SK_GetEvent(&ev)) @@ -341,6 +392,10 @@ int main(int argc, char *argv[]) case MenuMapJoypad: MapJoypad(); break; + + case MenuMonitor: + MachineCodeMonitor(); + break; } SK_DisplayKeyboard(BG_GFX_SUB); diff --git a/source/monitor.c b/source/monitor.c new file mode 100644 index 0000000..62d5f3b --- /dev/null +++ b/source/monitor.c @@ -0,0 +1,32 @@ +/* + ds81 - Nintendo DS ZX81 emulator. + + Copyright (C) 2006 Ian Cowburn + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + $Id$ +*/ + +#include +#include + +#include "monitor.h" + +/* ---------------------------------------- PUBLIC INTERFACES +*/ +void MachineCodeMonitor(void) +{ +} diff --git a/source/tapes.c b/source/tapes.c index 8f141f9..b6df688 100644 --- a/source/tapes.c +++ b/source/tapes.c @@ -204,22 +204,21 @@ static void InitTapes(void) for(f=0;fimg,255-t->img.width,0); - - FB_Print("LEFT/RIGHT",0,0,FB_RGB(255,255,255),-1); - FB_Print("to choose",0,10,FB_RGB(255,255,255),-1); - FB_Print("A to select",0,30,FB_RGB(255,255,255),-1); - FB_Print("B to cancel",0,40,FB_RGB(255,255,255),-1); - FB_Print("REMEMBER TO",0,60,FB_RGB(255,255,255),-1); - FB_Print("LOAD \"\"",0,70,FB_RGB(255,255,255),-1); - FB_Print("ON THE ZX81!",0,80,FB_RGB(255,255,255),-1); + FB_Blit(&t->img,255-t->img.width,0,1); + + FB_Print("LEFT/RIGHT",0,0,COL_WHITE,COL_TRANSPARENT); + FB_Print("to choose",0,10,COL_WHITE,COL_TRANSPARENT); + FB_Print("A to select",0,30,COL_WHITE,COL_TRANSPARENT); + FB_Print("B to cancel",0,40,COL_WHITE,COL_TRANSPARENT); + FB_Print("REMEMBER TO",0,60,COL_WHITE,COL_TRANSPARENT); + FB_Print("LOAD \"\"",0,70,COL_WHITE,COL_TRANSPARENT); + FB_Print("ON THE ZX81!",0,80,COL_WHITE,COL_TRANSPARENT); ZX81DisplayString(t->text); } diff --git a/source/textmode.c b/source/textmode.c new file mode 100644 index 0000000..aa6de44 --- /dev/null +++ b/source/textmode.c @@ -0,0 +1,146 @@ +/* + ds81 - Nintendo DS ZX81 emulator. + + Copyright (C) 2007 Ian Cowburn + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + $Id$ +*/ + +#include +#include +#include +#include + +#include "textmode.h" + +/* ---------------------------------------- STATIC DATA +*/ +static int mapw; +static int maph; +static uint16 *text; +static int is_rot; +static void (*draw_string)(const char *str, int x, int y); + + +/* ---------------------------------------- PRIVATE INTERFACES +*/ +static inline void Plot_Text(int x, int y, int c) +{ + int xw; + int yw; + + xw = x/32; + yw = y/32; + x %= 32; + y %= 32; + + *(text + x + y*32 + (xw+yw) * 1024) = c; +} + + +static inline void Plot_RS(int x, int y, int c) +{ + int xw; + int yw; + + xw = x/32; + yw = y/32; + x %= 32; + y %= 32; + + *(text + x + y*32 + (xw+yw) * 1024) = c; +} + + +static void Text_Put(const char *str, int x, int y) +{ + while(*str && x