aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Murphy <alec@checksum.fail>2017-06-11 00:23:47 -0400
committerAlec Murphy <alec@checksum.fail>2017-06-11 00:23:47 -0400
commitc7e71c57e014b4c816b65445d17f33398d029dcb (patch)
tree724a13aa1291412defd4d9dcb19bea69668ec2d7
parenteb0a45c306b47f2bd21f675273803cfa6979d9cc (diff)
Initial WINDOW support, init MBC RAM banks
-rw-r--r--Cartridge.HC2
-rw-r--r--LCD.HC153
-rw-r--r--LCDController.HC12
-rw-r--r--Load.HC24
-rw-r--r--Settings.HC2
5 files changed, 173 insertions, 20 deletions
diff --git a/Cartridge.HC b/Cartridge.HC
index 5ff5b1b..e6ed17a 100644
--- a/Cartridge.HC
+++ b/Cartridge.HC
@@ -109,4 +109,4 @@ U0 initCart() {
PressAKey;
break;
};
-} \ No newline at end of file
+} \ No newline at end of file
diff --git a/LCD.HC b/LCD.HC
index 7bd25fe..d6a26c8 100644
--- a/LCD.HC
+++ b/LCD.HC
@@ -4,7 +4,8 @@ CDC *lcd=DCNew(160,144);
CDC *bgr=DCNew(160,144);
CDC *bg_s=DCNew(256,1);
CDC *sp0_s=DCNew(256,1);
-CDC *sp_s;
+CDC *win_s=DCNew(256,1);
+
CDC *win=DCNew(256,256);
CDC *sp0=DCNew(160,144);
CDC *sp1=DCNew(160,144);
@@ -27,13 +28,18 @@ I64 bg_bx;
I64 bg_by;
I64 bg_px;
I64 bg_py;
-I64 bg_l=0;
I64 oam_ctr;
I64 sp_px;
I64 sp_py;
I64 sp_cx;
I64 sp_cy;
I64 sp_yf;
+I64 win_tpos;
+I64 win_tctr;
+I64 win_bx;
+I64 win_by;
+I64 win_px;
+I64 win_py;
// signed tile index & tile-planes
U8 s_tile;
@@ -49,7 +55,6 @@ U0 FreeLCD()
DCDel(bgr);
DCDel(bg_s);
DCDel(sp0_s);
- DCDel(sp_s);
DCDel(win);
DCDel(sp0);
DCDel(sp1);
@@ -177,6 +182,142 @@ U0 renderBG_ScanLine()
}
+U0 renderWIN_ScanLine()
+{
+
+
+ // Draw WIN
+ if (memory[0xFF40]>>0&5)
+ {
+ win_tpos=0x9800-0x8000;
+ if ((memory[0xFF40]>>6&1))
+ {
+ win_tpos=0x9C00-0x8000;
+ };
+
+ I64 win_tc_row=0;
+ I64 win_tc_ec=0;
+ I64 win_tc_tc=0;
+
+ win_tc_row=0;
+ win_tc_ec=0;
+
+ while (win_tc_tc<actualScanLine)
+ {
+ win_tc_tc++;
+ win_tc_ec++;
+ if (win_tc_ec>7) { win_tc_ec=0; win_tc_row++; };
+ };
+
+ win_tctr=(32*win_tc_row);
+ win_bx=0;
+ win_by=0;
+ win_px=0;
+ win_py=0;
+ while (win_tctr<((32*win_tc_row)+32))
+ {
+
+ tp_ctr=(2*win_tc_ec);
+ win_py=0;
+ win_px=0;
+ if (!(memory[0xFF40]>>4&1))
+ {
+ // $$8800 tileset uses signed tile data.
+ s_tile=-255+(127+memory[0x8000+win_tpos+win_tctr]);
+ if (s_tile<128) { s_tile+=256; };
+ tp0=memory[0x8000+(tp_ctr+(s_tile*16))+2048];
+ tp1=memory[0x8000+(tp_ctr+1+(s_tile*16))+2048];
+ }
+ else
+ {
+ // $$8000 uses normal (unsigned)
+ tp0=memory[0x8000+(tp_ctr+(memory[0x8000+win_tpos+win_tctr]*16))];
+ tp1=memory[0x8000+(tp_ctr+1+(memory[0x8000+win_tpos+win_tctr]*16))];
+ };
+ while(win_px<8)
+ {
+ if ((tp1>>win_px)&1) {
+ if((tp0>>win_px)&1){win_s->color=bgp3;}else{win_s->color=bgp2;};
+ } else {
+ if((tp0>>win_px)&1){win_s->color=bgp1;}else{win_s->color=TRANSPARENT;};
+ };
+ GrPlot(win_s,win_bx+(7-win_px),0);
+ win_px++;
+ };
+ win_bx+=8;
+ if (win_bx>255) { win_bx=0;win_by+=8; };
+ win_tctr++;
+ };
+ };
+
+ GrBlot(win,0,actualScanLine,win_s);
+
+};
+
+U0 renderWIN()
+{
+ // Draw WIN
+ if (memory[0xFF40]>>5&1)
+ {
+ win_tpos=0x9800-0x8000;
+ if ((memory[0xFF40]>>6&1))
+ {
+ win_tpos=0x9C00-0x8000;
+ };
+
+ win_tctr=0;
+ win_bx=0;
+ win_by=0;
+ win_px=0;
+ win_py=0;
+ while (win_tctr<1024)
+ {
+ tp_ctr=0;
+ win_py=0;
+ while (tp_ctr<16)
+ {
+ win_px=0;
+ if (!(memory[0xFF40]>>4&1))
+ {
+ // $$8800 tileset uses signed tile data.
+ s_tile=-255+(127+memory[0x8000+win_tpos+win_tctr]);
+ if (s_tile<128) { s_tile+=256; };
+ tp0=memory[0x8000+(tp_ctr+(s_tile*16))+2048];
+ tp1=memory[0x8000+(tp_ctr+1+(s_tile*16))+2048];
+ }
+ else
+ {
+ // $$8000 uses normal (unsigned)
+ tp0=memory[0x8000+(tp_ctr+(memory[0x8000+win_tpos+win_tctr]*16))];
+ tp1=memory[0x8000+(tp_ctr+1+(memory[0x8000+win_tpos+win_tctr]*16))];
+ };
+ while(win_px<8)
+ {
+ if ((tp1>>win_px)&1) {
+ if((tp0>>win_px)&1){win->color=bgp3;}else{win->color=bgp2;};
+ } else {
+ if((tp0>>win_px)&1){win->color=bgp1;}else{win->color=bgp0;};
+ };
+ GrPlot(win,win_bx+(7-win_px),win_by+win_py);
+ win_px++;
+ };
+ win_py++;
+ tp_ctr+=2;
+ };
+ win_bx+=8;
+ if (win_bx>255) { win_bx=0;win_by+=8; };
+ win_tctr++;
+ };
+ };
+}
+
+
+
+
+
+
+
+
U0 drawFrameBuffer()
{
@@ -185,6 +326,9 @@ U0 drawFrameBuffer()
// if bg enabled, draw BG rasterized to framebuffer
if (memory[0xFF40]>>0&1){ GrBlot(fb,0,0,bgr); };
// if sprites enabled, draw SP1 to framebuffer
+ if (memory[0xFF40]>>5&1){ GrBlot(fb,memory[0xFF4B]-7,memory[0xFF4A],win); };
+ // if sprites enabled, draw WIN to framebuffer
+
if (memory[0xFF40]>>1&1){ GrBlot(fb,0,0,sp1); };
// if LCD enabled, draw framebuffer to LCD
@@ -194,6 +338,7 @@ U0 drawFrameBuffer()
DCFill(lcd,15);
};
DCFill(bgr,TRANSPARENT);
+ DCFill(win,15);
};
U0 renderSprites()
@@ -250,7 +395,7 @@ U0 renderSprites()
tp3=0;
};
- if ((memory[0xFE00+oam_ctr+3]>>7)&1==0)
+ if ((memory[0xFE00+oam_ctr+3]>>7)&1==0)
{
odc=sp1;
} else {
diff --git a/LCDController.HC b/LCDController.HC
index 7c99618..502efb1 100644
--- a/LCDController.HC
+++ b/LCDController.HC
@@ -13,18 +13,10 @@ U0 matchLYC()
}
U0 notifyScanline()
{
- if (actualScanLine == 0) {
- windowSourceLine = 0;
- }
- // determine the left edge of the window (160 if window is inactive) **not implemented yet**
- I64 windowLeft = t((gfxWindowDisplay && memory[0xFF4A] <= actualScanLine),ToI64(Min(160, memory[0xFF4B] - 7)),160);
renderBG_ScanLine;
-
- if (windowLeft < 160) {
- ++windowSourceLine;
- }
-}
+ //renderWIN_ScanLine;
+}
U0 scanLineMode0()
{
diff --git a/Load.HC b/Load.HC
index 8d15ce0..fe93ca0 100644
--- a/Load.HC
+++ b/Load.HC
@@ -119,7 +119,7 @@ mc_ctr = 0xFF00;
while(mc_ctr<0xFFFF) { memory[mc_ctr]=0; mc_ctr++; };
//Switchable RAM (Used by games for more RAM) for the main memory range 0xA000 - 0xC000.
-I64 MBCRam[0x10000];
+I64 MBCRam[0x20000];
//MBC1 Type (4/32, 16/8)
Bool MBC1Mode = FALSE;
//MBC RAM Access Control.
@@ -234,7 +234,7 @@ Bool spritePriorityEnabled = TRUE;
I64 tileReadState[tileCount];
for(arrayCtr=0;arrayCtr<tileCount;arrayCtr++) { tileReadState[arrayCtr]=0;};
-I64 windowSourceLine = 0;
+//I64 windowSourceLine = 0;
//"Classic" GameBoy palette colors.
I64 colors[4] = {0x80EFFFDE, 0x80ADD794, 0x80529273, 0x80183442};
//Frame skip tracker
@@ -903,13 +903,15 @@ U0 updateCore()
audioTicks += timedTicks; //Not the same as the LCD timing (Cannot be altered by display on/off changes!!!).
//Are we past the granularity setting?
if (audioTicks >= audioGranularity) {
- sc=InU8(0x60);
//Emulator Timing (Timed against audio for optimization):
emulatorTicks += audioTicks;
if (emulatorTicks >= machineCyclesPerLoop) {
+ sc=InU8(0x60);
+
//LCD off takes at least 2 frames.
if (drewBlank == 0) {
+ renderWIN;
renderSprites;
drawFrameBuffer;
};
@@ -1101,6 +1103,19 @@ U0 initLCD()
#include "Cartridge";
+U0 setupRAMBanks()
+{
+ if (cMBC2) {
+ numRAMBanks = 1 / 16;
+ } else if (cMBC1 || cRUMBLE || cMBC3 || cHuC3) {
+ numRAMBanks = 4;
+ } else if (cMBC5) {
+ numRAMBanks = 16;
+ } else if (cSRAM) {
+ numRAMBanks = 1;
+ }
+};
+
U0 start()
{
for (keyCtr=0;keyCtr<8;keyCtr++) {
@@ -1117,6 +1132,7 @@ U0 start()
initEmulator;
frameskipAmount = 0; //Reset the frame skip setting.
initCart; // init cartridge bank type
+ setupRAMBanks;
initLCD; // init LCD
// BG Palette $$FF47
SetPal(memory[0xFF47],&bgp0,&bgp1,&bgp2,&bgp3);
@@ -1137,4 +1153,4 @@ U0 Run(U8 *rom_file)
{
ROM=FileRead(rom_file,&ROMSize);
start;
-} \ No newline at end of file
+}
diff --git a/Settings.HC b/Settings.HC
index 1f63648..7a90713 100644
--- a/Settings.HC
+++ b/Settings.HC
@@ -2,7 +2,7 @@ I64 audioGranularity = 20;
//Auto Frame Skip
I64 autoFrameskip = TRUE;
-
+
//Colorize GB mode? **No CGB support**
I64 colorize = FALSE;