@@ 2,7 2,7 @@
#include <stdlib.h>
#include "tema.h"
#include "screen.h"
-
+
void composite(TScreen *scr) {
uint8 *bg = scr->l0.data;
uint8 *fg = scr->l1.data;
@@ 41,17 41,15 @@ void display_write(TeMa *t,uint8 p,uint8 v) {
case 0x02: case 0x03: { // set tema display width
uint16 wid = BYTES2SHORT(d+0x02);
printf("display_write received display width: 0x%02X\n",wid);
- if(wid > MAXTWID) { printf("WARNING: display width of %d exceeds maximum of %d\n",wid,MAXTWID); break; }
+ if(wid > MAXWID) { printf("WARNING: display width of %d exceeds maximum of %d\n",wid,MAXWID); break; }
size_tscreen(wid,scr.hgt);
- //update_window();
break;
}
case 0x04: case 0x05: {
uint16 hgt = BYTES2SHORT(d+0x04);
printf("display_write received display height: 0x%02X\n",hgt);
- if(hgt > MAXTHGT) { printf("WARNING: display height of %d exceeds maximum of %d\n",hgt,MAXTHGT); break; }
+ if(hgt > MAXHGT) { printf("WARNING: display height of %d exceeds maximum of %d\n",hgt,MAXHGT); break; }
size_tscreen(scr.wid,hgt);
- //update_window();
break;
}
case 0x0E: { // cidx (and x, y position)
@@ 15,20 15,13 @@
// file 0xA0
// tmp debug 0xDB
-
-// The default resolution of the host window
-static uint16 whres = 640;
-static uint16 wvres = 480;
-
-//static uint8 bpp=4; // default bits per pixel
-static uint8 wresx = 1;
-void update_window();
-
-
+static uint8 zoomx = 1;
SDL_Renderer *renderer;
SDL_Window *window;
SDL_Texture *texture;
+void update_window();
+
void window_init(uint16 win_hres, uint16 win_vres, uint16 tema_hres, uint16 tema_vres) {
SDL_Init(SDL_INIT_VIDEO);
SDL_ShowCursor(SDL_DISABLE);
@@ 60,7 53,6 @@ static void host_write(TeMa *t,uint8 p,uint8 v) {
}
}
-
// console_read expects device pointer, port number.
static uint8 console_read(uint8 *d, uint8 p) {
FILE *f = stdin;
@@ 75,18 67,16 @@ static void console_write(uint8 p,uint8 v) {
fflush(f);
}
-
-
// TeMu -> TeMa
uint8 inbus(TeMa *r,uint8 x) {
uint8 dev = x & 0xF0;
uint8 p = x & 0x0F;
switch( dev ) {
- case 0x10: return console_read(&r->device[dev],p);
- case 0x20: break; // cannot read from display (yet>)
+ case 0x10: return console_read(&r->device[dev],p);
+ case 0x20: break; // cannot read from display (yet>)
case 0x80: break; // nothing to read yet
case 0x90: break; // nothing to read yet
- default: printf("inbus unhandled device 0x%02X\n",dev); break;
+ default: printf("inbus unhandled device 0x%02X\n",dev); break;
}
return 0;
}
@@ 152,6 142,7 @@ uint8 parse_key(uint8 sym) {
void update_bit(uint8* val, uint8 bit, uint8 set) {
*val = set ? *val | bit : *val & ~bit;
}
+
static uint8 controller_state = 0;
void update_controller(int sym, uint8* state, uint8 set) {
switch(sym) {
@@ 184,7 175,7 @@ int handle_events(TeMa* tema) {
case SDL_KEYDOWN: {
if(ev.key.repeat == 1 ) break;
// do check for host specific keys (like function keys)
- if(ev.key.keysym.sym == SDLK_F1) { wresx = wresx<<1; if(wresx>4) wresx = 1; update_window(); break; }
+ if(ev.key.keysym.sym == SDLK_F1) { zoomx = zoomx<<1; if(zoomx>4) zoomx = 1; update_window(); break; }
update_controller(ev.key.keysym.sym, &controller_state, 1);
tema->device[0x83] = controller_state;
@@ 254,7 245,7 @@ int temu_run(TeMa* tema) {
// should we read the vector outside the loop? It would mean TeMa could change it without effect, so probably no.
uint16 display_handler = BYTES2SHORT(&tema->device[0x20]);
- if(scr.bodge == 1) { printf("updating window\n"); update_window(); scr.bodge=0; }
+ if(scr.bodge == 1) { update_window(); scr.bodge=0; }
if(display_handler) {
run(tema, display_handler);
@@ 284,12 275,11 @@ int temu_run(TeMa* tema) {
}
void update_window() {
- printf("update_window !!!!!!!!!!\n");
uint16 thres = scr.wid; uint16 tvres = scr.hgt;
- whres = thres*wresx; wvres = tvres*wresx;
+ uint16 winwid = thres*zoomx; uint16 winhgt = tvres*zoomx;
if( texture != NULL ) SDL_DestroyTexture(texture);
- printf("wresx is %d: setting whres and wvres to %d,%d\n",wresx,whres,wvres);
+ printf("zoomx is %d: setting winwid and winhgt to %d,%d\n",zoomx,winwid,winhgt);
// renderer is the size of the insides of the host window.
SDL_RenderSetLogicalSize(renderer, thres, tvres);
@@ 302,7 292,7 @@ void update_window() {
printf("Error updating texture %s\n",SDL_GetError()); return;
}
- SDL_SetWindowSize(window,whres, wvres);
+ SDL_SetWindowSize(window,winwid, winhgt);
}
int main(int argc, char *argv[]) {
@@ 328,12 318,9 @@ int main(int argc, char *argv[]) {
//db_ramprint(tema.ram.data,0x0000, romsize,0x8);
// create display
- uint16 thres = scr.wid; uint16 tvres = scr.hgt;
- whres = thres*wresx; wvres = tvres*wresx;
- window_init(whres, wvres, thres, tvres);
- size_tscreen(thres, tvres);
- update_window();
-
+ uint16 scrwid = scr.wid; uint16 scrhgt = scr.hgt;
+ window_init(scrwid*zoomx, scrhgt*zoomx, scrwid, scrhgt);
+ size_tscreen(scrwid, scrhgt);
temu_run(&tema);