aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Murphy <alec@checksum.fail>2017-07-08 22:59:01 -0400
committerAlec Murphy <alec@checksum.fail>2017-07-08 22:59:01 -0400
commit235bda6a582099e134af299ce592796b520668b6 (patch)
treed05febe78a36c1280a31050e299b72e1bd093c6c
parentafb3915f3586df26ea2f7e8fe20d527cd20835a8 (diff)
Initial support for PC speaker sound, move LCDScale to Settings
-rw-r--r--LCD.HC7
-rw-r--r--Load.HC54
-rw-r--r--Run.HC9
-rw-r--r--Settings.HC4
-rwxr-xr-xSound.HC65
5 files changed, 113 insertions, 26 deletions
diff --git a/LCD.HC b/LCD.HC
index c606ee4..de81b5d 100644
--- a/LCD.HC
+++ b/LCD.HC
@@ -24,6 +24,7 @@ Bool sp0_e=FALSE;
Bool n_scan=FALSE;
// counters, tile-plane, bg, oam sprites
+I64 sp_trig=FALSE;
I64 tp_ctr;
I64 bg_tpos;
I64 bg_tctr;
@@ -371,7 +372,7 @@ U0 drawFrameBuffer()
{
// if sprites enabled, draw SP0 to framebuffer
-
+
GrBlot(fb,0,0,sp0);
// if (memory[0xFF40]>>1&1){ GrBlot(fb,0,0,sp0); };
// if bg enabled, draw BG rasterized to framebuffer
@@ -405,9 +406,9 @@ U0 renderSprites()
s_tile=0;
// Draw Sprites from OAM
- if (TRUE)
- //if (memory[0xFF40]>>1&1)
+ if (sp_trig || memory[0xFF40]>>1&1)
{
+ sp_trig=TRUE;
oam_ctr=156;
while(oam_ctr>-4)
{
diff --git a/Load.HC b/Load.HC
index 826c640..a70ed1b 100644
--- a/Load.HC
+++ b/Load.HC
@@ -14,13 +14,39 @@ I64 kLoad=0;
I64 kReset=0;
I64 kSave=0;
-I64 LCDScale=1;
I64 DisplayMsgTicks=0;
U8 DisplayMsg[32];
StrCpy(DisplayMsg,"");
U8 StateFile[512];
+U0 SetLCDScale()
+{
+ switch(LCDScale)
+ {
+ case 1:
+ Fs->win_left =0x1F;
+ Fs->win_right =0x32;
+ Fs->win_top =0x15;
+ Fs->win_bottom =0x26;
+ break;
+ case 2:
+ Fs->win_left =0x15;
+ Fs->win_right =0x3C;
+ Fs->win_top =0x0D;
+ Fs->win_bottom =0x30;
+ break;
+ case 3:
+ Fs->win_left =0x0A;
+ Fs->win_right =0x45;
+ Fs->win_top =0x03;
+ Fs->win_bottom =0x38;
+ break;
+ default:
+ break;
+ };
+}
+
U0 SetPal(U8 p, I64 *c0, I64 *c1, I64 *c2, I64 *c3)
{
I64 col[4];
@@ -1136,24 +1162,15 @@ U0 executeIteration()
case 0x02 + 0x80:
LCDScale=1;
- Fs->win_left =0x1F;
- Fs->win_right =0x32;
- Fs->win_top =0x15;
- Fs->win_bottom =0x26;
+ SetLCDScale;
break;
case 0x03 + 0x80:
LCDScale=2;
- Fs->win_left =0x15;
- Fs->win_right =0x3C;
- Fs->win_top =0x0D;
- Fs->win_bottom =0x30;
+ SetLCDScale;
break;
case 0x04 + 0x80:
LCDScale=3;
- Fs->win_left =0x0A;
- Fs->win_right =0x45;
- Fs->win_top =0x03;
- Fs->win_bottom =0x38;
+ SetLCDScale;
break;
case 0x4D:
joyPadState(0,TRUE);
@@ -1268,6 +1285,8 @@ U0 setupRAMBanks()
}
};
+#include "Sound";
+
U0 start()
{
for (keyCtr=0;keyCtr<8;keyCtr++) {
@@ -1276,16 +1295,14 @@ U0 start()
SettingsPush;
DocClear;
DCFill(lcd,15);
- Fs->win_left =0x1F;
- Fs->win_right =0x32;
- Fs->win_top =0x15;
- Fs->win_bottom =0x26;
+ SetLCDScale;
stopEmulator=1;
initEmulator;
frameskipAmount = 0; //Reset the frame skip setting.
initCart; // init cartridge bank type
setupRAMBanks;
initLCD; // init LCD
+ CTask *snd_task=Spawn(&GBSoundTask,&memory,,2);
// BG Palette $$FF47
SetPal(memory[0xFF47],&bgp0,&bgp1,&bgp2,&bgp3);
// OBP0 Palette $$FF48
@@ -1300,6 +1317,9 @@ U0 start()
Fs->draw_it=NULL;
DCFill;
SettingsPop;
+ CherubExit=TRUE;
+ Kill(snd_task);
+ SndRst;
Kill(Fs);
}
diff --git a/Run.HC b/Run.HC
index efe3604..b4f29ca 100644
--- a/Run.HC
+++ b/Run.HC
@@ -1,3 +1,4 @@
+Adam("I64 CherubExit=FALSE;");
CTask *cherub;
U8 *RunCmd=CAlloc(1024);
U8 *RomList=CAlloc(65536);
@@ -18,8 +19,6 @@ while (rom_f)
I64 rom_i = PopUpPickLst(RomList);
-"%d\n",rom_i;
-
I64 incr=0;
rom_f=roms;
@@ -32,10 +31,11 @@ if (rom_i>-1)
};
StrPrint(RunCmd,"Cd(\"%s\");\n#include \"Load\";\nRun(\"%s\");\n",DirCur,rom_f->full_name);
cherub=User(RunCmd);
- Sleep(300);
+ Sleep(100);
WinFocus(Fs);
- Sleep(300);
+ Sleep(100);
WinFocus(cherub);
+ while (!CherubExit) { Sleep(1); };
};
DirEntryDel(roms);
@@ -43,4 +43,3 @@ Free(RomList);
Free(RunCmd);
rom_f=NULL;
- \ No newline at end of file
diff --git a/Settings.HC b/Settings.HC
index 7a90713..a696eec 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;
@@ -10,6 +10,8 @@ I64 colorize = FALSE;
//Order: Right, Left, Up, Down, A, B, Select, Start
I64 keyboardButtonMap[8] = {'d', 'a', 'w', 's', ',', '.', 'n', 'm'};
+I64 LCDScale=3;
+
//Frameskip Amount (Auto frameskip setting allows the script to change this.)
I64 frameskipAmount = 0;
diff --git a/Sound.HC b/Sound.HC
new file mode 100755
index 0000000..0fd9a31
--- /dev/null
+++ b/Sound.HC
@@ -0,0 +1,65 @@
+
+U0 GBSoundTask(U8 *regs)
+{
+
+ I64 ch=0;
+ I64 chP=0;
+ I64 div;
+ I64 freq;
+ I64 x;
+ I64 prevX;
+ while (TRUE)
+ {
+ if(ch==0 && chP==FALSE)
+ {
+
+ if (memory[0xFF12]>0b10000)
+ {
+ x = memory[0xFF13];
+ x += ((memory[0xFF14] & 0b00000111)<<8);
+ if (x!=prevX)
+ {
+ freq=131072/(2048-x);
+ div=1193180/freq;
+ OutU8(0x43, 0xB6);
+ OutU8(0x42, div);
+ OutU8(0x42, div>>8);
+ OutU8(0x61,3|InU8(0x61));
+ prevX=x;
+ };
+ } else {
+ //SndRst;
+ }
+ };
+
+ if(ch==1)
+ {
+
+ if (memory[0xFF17]>0b10000)
+ {
+ x = memory[0xFF18];
+ x += ((memory[0xFF19] & 0b00000111)<<8);
+ if (x!=prevX)
+ {
+ freq=131072/(2048-x);
+ div=1193180/freq;
+ OutU8(0x43, 0xB6);
+ OutU8(0x42, div);
+ OutU8(0x42, div>>8);
+ OutU8(0x61,3|InU8(0x61));
+ prevX=x;
+ chP=TRUE;
+ };
+ } else {
+ chP=FALSE;
+ }
+ };
+
+
+
+ Sleep(2);
+
+ ch++;
+ if (ch>3) { ch=0; };
+ };
+}