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. --- 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 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 450 insertions(+), 133 deletions(-) create mode 100644 source/monitor.c create mode 100644 source/textmode.c (limited to 'source') 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