aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2003-04-30 11:37:10 +0000
committerMax Horn2003-04-30 11:37:10 +0000
commit42f156ddada4c6f51e1612e9b0f18ec7c9dd9cee (patch)
treea2b7ba14f7f919987239902e513c1a646ca2e9f8
parent79ebda7613b3280ae644d67af50712deef8819d7 (diff)
downloadscummvm-rg350-42f156ddada4c6f51e1612e9b0f18ec7c9dd9cee.tar.gz
scummvm-rg350-42f156ddada4c6f51e1612e9b0f18ec7c9dd9cee.tar.bz2
scummvm-rg350-42f156ddada4c6f51e1612e9b0f18ec7c9dd9cee.zip
started to merge in Chrilith's PalmOS port
svn-id: r7219
-rw-r--r--backends/PalmOS/Rsc/Resource.Frk/Starter.rsrcbin0 -> 20925 bytes
-rw-r--r--backends/PalmOS/Rsc/Starter.rsrc0
-rw-r--r--backends/PalmOS/Rsc/StarterRsc.h233
-rw-r--r--backends/PalmOS/Src/extend.cpp89
-rw-r--r--backends/PalmOS/Src/extend.h15
-rw-r--r--backends/PalmOS/Src/extras.cpp217
-rw-r--r--backends/PalmOS/Src/extras.h134
-rw-r--r--backends/PalmOS/Src/globals.h35
-rw-r--r--backends/PalmOS/Src/init.cpp9
-rw-r--r--backends/PalmOS/Src/missing/_stdio.cpp344
-rw-r--r--backends/PalmOS/Src/missing/_stdlib.cpp213
-rw-r--r--backends/PalmOS/Src/missing/_string.cpp86
-rw-r--r--backends/PalmOS/Src/missing/_time.cpp38
-rw-r--r--backends/PalmOS/Src/missing/_unistd.cpp14
-rw-r--r--backends/PalmOS/Src/missing/assert.h1
-rw-r--r--backends/PalmOS/Src/missing/fcntl.h1
-rw-r--r--backends/PalmOS/Src/missing/math.h1
-rw-r--r--backends/PalmOS/Src/missing/stdio.h34
-rw-r--r--backends/PalmOS/Src/missing/stdlib.h38
-rw-r--r--backends/PalmOS/Src/missing/string.h22
-rw-r--r--backends/PalmOS/Src/missing/sys/stat.h1
-rw-r--r--backends/PalmOS/Src/missing/time.h18
-rw-r--r--backends/PalmOS/Src/missing/unistd.h3
-rw-r--r--backends/PalmOS/Src/palm.cpp1325
-rw-r--r--backends/PalmOS/Src/palm.h263
-rw-r--r--backends/PalmOS/Src/palmsave.cpp160
-rw-r--r--backends/PalmOS/Src/palmstart.cpp3180
-rw-r--r--backends/PalmOS/Src/saveslot.cpp92
-rw-r--r--backends/PalmOS/Src/scumm_globals.h50
-rw-r--r--backends/PalmOS/Src/skin.h55
-rw-r--r--backends/PalmOS/Src/vibrate.h61
-rw-r--r--backends/fs/palmos/palmos-fs.cpp155
32 files changed, 6887 insertions, 0 deletions
diff --git a/backends/PalmOS/Rsc/Resource.Frk/Starter.rsrc b/backends/PalmOS/Rsc/Resource.Frk/Starter.rsrc
new file mode 100644
index 0000000000..f8a4956806
--- /dev/null
+++ b/backends/PalmOS/Rsc/Resource.Frk/Starter.rsrc
Binary files differ
diff --git a/backends/PalmOS/Rsc/Starter.rsrc b/backends/PalmOS/Rsc/Starter.rsrc
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/backends/PalmOS/Rsc/Starter.rsrc
diff --git a/backends/PalmOS/Rsc/StarterRsc.h b/backends/PalmOS/Rsc/StarterRsc.h
new file mode 100644
index 0000000000..14c0a8cbc8
--- /dev/null
+++ b/backends/PalmOS/Rsc/StarterRsc.h
@@ -0,0 +1,233 @@
+// Header generated by Constructor for Palm OS (R) 1.9
+//
+// Generated at 16:39:35 on vendredi 25 avril 2003
+//
+// Generated for file: Starter.rsrc
+//
+// THIS IS AN AUTOMATICALLY GENERATED HEADER FILE
+// DO NOT EDIT - CHANGES MADE TO THIS FILE WILL BE LOST
+//
+// Palm App Name: "ScummVM"
+//
+// Palm App Version: "1.0"
+
+
+// Resource: tFRM 1000
+#define MainForm 1000 //(Left Origin = 0, Top Origin = 0, Width = 160, Height = 160, Usable = 1, Modal = 0, Save Behind = 0, Help ID = 0, Menu Bar ID = 1000, Default Button ID = 0)
+#define MainCardsButton 1003 //(Left Origin = 135, Top Origin = 1, Width = 12, Height = 12, Usable = 1, Anchor Left = 1, Frame = 0, Non-bold Frame = 0, Font = Standard)
+#define MainAboutButton 1012 //(Left Origin = 148, Top Origin = 1, Width = 12, Height = 12, Usable = 1, Anchor Left = 1, Frame = 0, Non-bold Frame = 1, Font = Standard)
+#define MainMSBitMap 1100 //(Left Origin = 135, Top Origin = 1, Bitmap Resource ID = 1100, Usable = 0)
+#define MainMSNoneBitMap 1110 //(Left Origin = 135, Top Origin = 1, Bitmap Resource ID = 1110, Usable = 0)
+#define MainUnnamed1010BitMap 2000 //(Left Origin = 148, Top Origin = 1, Bitmap Resource ID = 2000, Usable = 1)
+
+// Resource: tFRM 1100
+#define AboutForm 1100 //(Left Origin = 2, Top Origin = 2, Width = 156, Height = 156, Usable = 1, Modal = 1, Save Behind = 1, Help ID = 0, Menu Bar ID = 0, Default Button ID = 0)
+#define AboutOKButton 1105 //(Left Origin = 121, Top Origin = 139, Width = 30, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define AboutUnnamed1108BitMap 1000 //(Left Origin = 69, Top Origin = 15, Bitmap Resource ID = 1000, Usable = 1)
+#define AboutUnnamed1102Label 1102 //(Left Origin = 34, Top Origin = 49, Usable = 1, Font = Standard)
+#define AboutUnnamed1103Label 1103 //(Left Origin = 38, Top Origin = 67, Usable = 1, Font = Bold)
+#define AboutUnnamed1104Label 1104 //(Left Origin = 9, Top Origin = 106, Usable = 1, Font = Bold)
+#define AboutUnnamed1106Label 1106 //(Left Origin = 18, Top Origin = 116, Usable = 1, Font = Standard)
+#define AboutVersionLabel 1107 //(Left Origin = 4, Top Origin = 139, Usable = 1, Font = Standard)
+#define AboutUnnamed1109Label 1109 //(Left Origin = 54, Top Origin = 77, Usable = 1, Font = Standard)
+#define AboutUnnamed1110Label 1110 //(Left Origin = 8, Top Origin = 87, Usable = 1, Font = Standard)
+#define AboutUnnamed1111Label 1111 //(Left Origin = 26, Top Origin = 39, Usable = 1, Font = Standard)
+
+// Resource: tFRM 1300
+#define HelpForm 1300 //(Left Origin = 2, Top Origin = 2, Width = 156, Height = 156, Usable = 1, Modal = 1, Save Behind = 1, Help ID = 0, Menu Bar ID = 0, Default Button ID = 0)
+
+// Resource: tFRM 1200
+#define SkinsForm 1200 //(Left Origin = 2, Top Origin = 63, Width = 156, Height = 95, Usable = 1, Modal = 1, Save Behind = 1, Help ID = 0, Menu Bar ID = 0, Default Button ID = 1203)
+#define SkinsOKButton 1202 //(Left Origin = 5, Top Origin = 78, Width = 32, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define SkinsCancelButton 1203 //(Left Origin = 43, Top Origin = 78, Width = 32, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define SkinsSkinDeleteButton 1204 //(Left Origin = 115, Top Origin = 78, Width = 36, Height = 12, Usable = 0, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define SkinsDeleteButton 1205 //(Left Origin = 119, Top Origin = 78, Width = 32, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define SkinsBeamButton 1206 //(Left Origin = 81, Top Origin = 78, Width = 32, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define SkinsSkinList 1201 //(Left Origin = 5, Top Origin = 17, Width = 146, Usable = 1, Font = Standard, Visible Items = 5)
+
+// Resource: tFRM 1400
+#define EditGameForm 1400 //(Left Origin = 2, Top Origin = 2, Width = 156, Height = 156, Usable = 1, Modal = 1, Save Behind = 1, Help ID = 0, Menu Bar ID = 0, Default Button ID = 1411)
+#define EditGameOKButton 1410 //(Left Origin = 5, Top Origin = 139, Width = 36, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define EditGameCancelButton 1411 //(Left Origin = 46, Top Origin = 139, Width = 36, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define EditGameDeleteButton 1412 //(Left Origin = 115, Top Origin = 139, Width = 36, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define EditGameLoadSlotCheckbox 1413 //(Left Origin = 4, Top Origin = 85, Width = 85, Height = 12, Usable = 1, Selected = 0, Group ID = 0, Font = Standard)
+#define EditGameStartRoomCheckbox 1414 //(Left Origin = 4, Top Origin = 97, Width = 84, Height = 12, Usable = 1, Selected = 0, Group ID = 0, Font = Standard)
+#define EditGameAmigaCheckbox 1417 //(Left Origin = 4, Top Origin = 109, Width = 81, Height = 12, Usable = 1, Selected = 0, Group ID = 0, Font = Standard)
+#define EditGameSubtitlesCheckbox 1418 //(Left Origin = 4, Top Origin = 121, Width = 68, Height = 12, Usable = 1, Selected = 0, Group ID = 0, Font = Standard)
+#define EditGameTalkSpeedCheckbox 1421 //(Left Origin = 4, Top Origin = 73, Width = 66, Height = 12, Usable = 1, Selected = 0, Group ID = 0, Font = Standard)
+#define EditGameEntryNameField 1402 //(Left Origin = 4, Top Origin = 28, Width = 148, Height = 12, Usable = 1, Editable = 1, Underline = 1, Single Line = 1, Dynamic Size = 0, Left Justified = 1, Max Characters = 50, Font = Standard, Auto Shift = 0, Has Scroll Bar = 0, Numeric = 0)
+#define EditGamePathField 1404 //(Left Origin = 34, Top Origin = 42, Width = 118, Height = 12, Usable = 1, Editable = 1, Underline = 1, Single Line = 1, Dynamic Size = 0, Left Justified = 1, Max Characters = 150, Font = Standard, Auto Shift = 0, Has Scroll Bar = 0, Numeric = 0)
+#define EditGameGameField 1406 //(Left Origin = 34, Top Origin = 56, Width = 60, Height = 12, Usable = 1, Editable = 1, Underline = 1, Single Line = 1, Dynamic Size = 0, Left Justified = 1, Max Characters = 10, Font = Standard, Auto Shift = 0, Has Scroll Bar = 0, Numeric = 0)
+#define EditGameLoadSlotField 1415 //(Left Origin = 92, Top Origin = 85, Width = 12, Height = 12, Usable = 1, Editable = 1, Underline = 1, Single Line = 1, Dynamic Size = 0, Left Justified = 1, Max Characters = 2, Font = Standard, Auto Shift = 0, Has Scroll Bar = 0, Numeric = 1)
+#define EditGameStartRoomField 1416 //(Left Origin = 92, Top Origin = 97, Width = 18, Height = 12, Usable = 1, Editable = 1, Underline = 1, Single Line = 1, Dynamic Size = 0, Left Justified = 1, Max Characters = 4, Font = Standard, Auto Shift = 0, Has Scroll Bar = 0, Numeric = 1)
+#define EditGameTalkSpeedField 1423 //(Left Origin = 92, Top Origin = 73, Width = 18, Height = 12, Usable = 1, Editable = 1, Underline = 1, Single Line = 1, Dynamic Size = 0, Left Justified = 1, Max Characters = 3, Font = Standard, Auto Shift = 0, Has Scroll Bar = 0, Numeric = 1)
+#define EditGameUnnamed1407GraffitiShift 1407 //(Left Origin = 87, Top Origin = 140)
+#define EditGameUnnamed1401Label 1401 //(Left Origin = 4, Top Origin = 16, Usable = 1, Font = Bold)
+#define EditGameUnnamed1403Label 1403 //(Left Origin = 9, Top Origin = 42, Usable = 1, Font = Standard)
+#define EditGameUnnamed1405Label 1405 //(Left Origin = 4, Top Origin = 56, Usable = 1, Font = Standard)
+#define EditGameUnnamed1419Label 1419 //(Left Origin = 88, Top Origin = 85, Usable = 1, Font = Standard)
+#define EditGameUnnamed1420Label 1420 //(Left Origin = 88, Top Origin = 97, Usable = 1, Font = Standard)
+#define EditGameUnnamed1422Label 1422 //(Left Origin = 88, Top Origin = 73, Usable = 1, Font = Standard)
+#define EditGameGfxListList 1409 //(Left Origin = 95, Top Origin = 56, Width = 55, Usable = 0, Font = Standard, Visible Items = 3)
+#define EditGameGfxPopupPopTrigger 1408 //(Left Origin = 99, Top Origin = 56, Width = 53, Height = 12, Usable = 1, Anchor Left = 0, Font = Standard, List ID = 1409)
+
+// Resource: tFRM 1500
+#define CardSlotForm 1500 //(Left Origin = 30, Top Origin = 42, Width = 100, Height = 75, Usable = 1, Modal = 1, Save Behind = 1, Help ID = 0, Menu Bar ID = 0, Default Button ID = 0)
+#define CardSlotOkButton 1501 //(Left Origin = 31, Top Origin = 58, Width = 36, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define CardSlotSlotList 1502 //(Left Origin = 5, Top Origin = 17, Width = 90, Usable = 1, Font = Standard, Visible Items = 3)
+
+// Resource: tFRM 1600
+#define MiscOptionsForm 1600 //(Left Origin = 2, Top Origin = 28, Width = 156, Height = 130, Usable = 1, Modal = 1, Save Behind = 1, Help ID = 0, Menu Bar ID = 0, Default Button ID = 0)
+#define MiscOptionsOKButton 1608 //(Left Origin = 5, Top Origin = 113, Width = 36, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define MiscOptionsCancelButton 1609 //(Left Origin = 46, Top Origin = 113, Width = 36, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define MiscOptionsVibratorCheckbox 1602 //(Left Origin = 4, Top Origin = 28, Width = 128, Height = 12, Usable = 1, Selected = 0, Group ID = 0, Font = Standard)
+#define MiscOptionsNoAutoOffCheckbox 1603 //(Left Origin = 4, Top Origin = 40, Width = 152, Height = 12, Usable = 1, Selected = 0, Group ID = 0, Font = Standard)
+#define MiscOptionsStdPaletteCheckbox 1604 //(Left Origin = 4, Top Origin = 52, Width = 146, Height = 12, Usable = 1, Selected = 0, Group ID = 0, Font = Standard)
+#define MiscOptionsDebugCheckbox 1606 //(Left Origin = 4, Top Origin = 86, Width = 100, Height = 12, Usable = 1, Selected = 0, Group ID = 0, Font = Standard)
+#define MiscOptionsDebugLevelField 1607 //(Left Origin = 103, Top Origin = 86, Width = 12, Height = 12, Usable = 1, Editable = 1, Underline = 1, Single Line = 1, Dynamic Size = 0, Left Justified = 1, Max Characters = 1, Font = Standard, Auto Shift = 0, Has Scroll Bar = 0, Numeric = 1)
+#define MiscOptionsUnnamed1601Label 1601 //(Left Origin = 4, Top Origin = 16, Usable = 1, Font = Bold)
+#define MiscOptionsUnnamed1605Label 1605 //(Left Origin = 4, Top Origin = 74, Usable = 1, Font = Bold)
+
+// Resource: tFRM 1700
+#define VolumeForm 1700 //(Left Origin = 2, Top Origin = 2, Width = 156, Height = 156, Usable = 1, Modal = 1, Save Behind = 1, Help ID = 0, Menu Bar ID = 0, Default Button ID = 0)
+#define VolumeOKButton 1701 //(Left Origin = 5, Top Origin = 139, Width = 36, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define VolumeCancelButton 1702 //(Left Origin = 47, Top Origin = 139, Width = 36, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define VolumeUnnamed1704Label 1704 //(Left Origin = 4, Top Origin = 16, Usable = 1, Font = Bold)
+#define VolumeUnnamed1705Label 1705 //(Left Origin = 6, Top Origin = 46, Usable = 1, Font = Standard)
+#define VolumeUnnamed1709Label 1709 //(Left Origin = 18, Top Origin = 31, Usable = 1, Font = Standard)
+#define VolumeUnnamed1710Label 1710 //(Left Origin = 3, Top Origin = 68, Usable = 1, Font = Bold)
+#define VolumeUnnamed1712Label 1712 //(Left Origin = 21, Top Origin = 83, Usable = 1, Font = Standard)
+#define VolumeUnnamed1713Label 1713 //(Left Origin = 28, Top Origin = 98, Usable = 1, Font = Standard)
+#define VolumeUnnamed1714Label 1714 //(Left Origin = 14, Top Origin = 113, Usable = 1, Font = Standard)
+#define VolumeSpeakerSliderControl 1703 //(Left Origin = 60, Top Origin = 28, Width = 93, Height = 15, Usable = 1, Initial Value = 0, Minimum Value = 0, Maximum Value = 31, Page Jump Amount = 1, Thumb Bitmap = 0, Background Bitmap = 0)
+#define VolumeHeadphoneSliderControl 1706 //(Left Origin = 60, Top Origin = 43, Width = 93, Height = 15, Usable = 1, Initial Value = 0, Minimum Value = 0, Maximum Value = 31, Page Jump Amount = 1, Thumb Bitmap = 0, Background Bitmap = 0)
+#define VolumeMasterSliderControl 1707 //(Left Origin = 60, Top Origin = 80, Width = 93, Height = 15, Usable = 1, Initial Value = 0, Minimum Value = 0, Maximum Value = 255, Page Jump Amount = 1, Thumb Bitmap = 0, Background Bitmap = 0)
+#define VolumeMusicSliderControl 1708 //(Left Origin = 60, Top Origin = 95, Width = 93, Height = 15, Usable = 1, Initial Value = 0, Minimum Value = 0, Maximum Value = 255, Page Jump Amount = 1, Thumb Bitmap = 0, Background Bitmap = 0)
+#define VolumeSfxSliderControl 1711 //(Left Origin = 60, Top Origin = 110, Width = 93, Height = 15, Usable = 1, Initial Value = 0, Minimum Value = 0, Maximum Value = 255, Page Jump Amount = 1, Thumb Bitmap = 0, Background Bitmap = 0)
+
+// Resource: tFRM 1800
+#define SoundForm 1800 //(Left Origin = 2, Top Origin = 34, Width = 156, Height = 124, Usable = 1, Modal = 1, Save Behind = 1, Help ID = 0, Menu Bar ID = 0, Default Button ID = 0)
+#define SoundOKButton 1809 //(Left Origin = 5, Top Origin = 106, Width = 36, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define SoundCancelButton 1810 //(Left Origin = 47, Top Origin = 106, Width = 36, Height = 12, Usable = 1, Anchor Left = 1, Frame = 1, Non-bold Frame = 1, Font = Standard)
+#define SoundMusicCheckbox 1801 //(Left Origin = 4, Top Origin = 28, Width = 79, Height = 12, Usable = 1, Selected = 1, Group ID = 0, Font = Standard)
+#define SoundSfxCheckbox 1802 //(Left Origin = 4, Top Origin = 82, Width = 106, Height = 12, Usable = 1, Selected = 1, Group ID = 0, Font = Standard)
+#define SoundTempoField 1808 //(Left Origin = 64, Top Origin = 52, Width = 50, Height = 12, Usable = 1, Editable = 1, Underline = 1, Single Line = 1, Dynamic Size = 0, Left Justified = 1, Max Characters = 8, Font = Standard, Auto Shift = 0, Has Scroll Bar = 0, Numeric = 0)
+#define SoundUnnamed1803Label 1803 //(Left Origin = 4, Top Origin = 16, Usable = 1, Font = Bold)
+#define SoundUnnamed1804Label 1804 //(Left Origin = 21, Top Origin = 40, Usable = 1, Font = Standard)
+#define SoundUnnamed1806Label 1806 //(Left Origin = 18, Top Origin = 52, Usable = 1, Font = Standard)
+#define SoundUnnamed1807Label 1807 //(Left Origin = 4, Top Origin = 70, Usable = 1, Font = Bold)
+#define SoundDriverList 1811 //(Left Origin = 54, Top Origin = 40, Width = 70, Usable = 0, Font = Standard, Visible Items = 2)
+#define SoundDriverPopTrigger 1805 //(Left Origin = 54, Top Origin = 40, Width = 73, Height = 14, Usable = 1, Anchor Left = 1, Font = Standard, List ID = 1811)
+
+
+// Resource: Talt 1001
+#define RomIncompatibleAlert 1001
+#define RomIncompatibleOK 0
+
+// Resource: Talt 1000
+#define FrmWarnAlert 1000
+#define FrmWarnOK 0
+
+// Resource: Talt 1100
+#define FrmErrorAlert 1100
+#define FrmErrorCancel 0
+
+// Resource: Talt 1200
+#define FrmFatalErrorAlert 1200
+#define FrmFatalErrorReset 0
+
+// Resource: Talt 1300
+#define FrmDeleteAlert 1300
+#define FrmDeleteYes 0
+#define FrmDeleteNo 1
+
+// Resource: Talt 1400
+#define FrmInfoAlert 1400
+#define FrmInfoOK 0
+
+
+// Resource: MBAR 1000
+#define MainFormMenuBar 1000
+
+
+// Resource: MENU 1000
+#define MainOptionsMenu 1000
+#define MainOptionsVolumeControl 1000 // Command Key: V
+#define MainOptionsSoundPrefs 1001 // Command Key: S
+#define MainOptionsSkins 1003 // Command Key: K
+#define MainOptionsMiscellaneous 1004 // Command Key: M
+#define MainOptionsAbout 1006
+
+// Resource: MENU 1100
+#define MainGamesMenu 1100
+#define MainGamesNewEdit 1100 // Command Key: E
+#define MainGamesBeamScummVM 1101 // Command Key: B
+#define MainGamesChooseaCard 1103 // Command Key: C
+
+
+// Resource: tSTR 9991
+#define ClieCatString 9991 // "32779"
+
+// Resource: tSTR 9990
+#define ClieDescString 9990 // "Play your favorite LucasArts games"
+
+
+// Resource: PICT 1001
+#define Bitmap 1001
+
+// Resource: PICT 1002
+#define Bitmap2 1002
+
+// Resource: PICT 1008
+#define Bitmap3 1008
+
+// Resource: PICT 1011
+#define Bitmap4 1011
+
+// Resource: PICT 1012
+#define Bitmap5 1012
+
+// Resource: PICT 1018
+#define Bitmap6 1018
+
+// Resource: PICT 2000
+#define infoBitmap 2000
+
+// Resource: PICT 1100
+#define msOnBitmap 1100
+
+// Resource: PICT 1009
+#define Bitmap7 1009
+
+// Resource: PICT 1010
+#define Bitmap8 1010
+
+// Resource: PICT 1110
+#define msNoneBitmap 1110
+
+// Resource: PICT 3000
+#define ctrlKeyBitmap 3000
+
+// Resource: PICT 3001
+#define altKeyBitmap 3001
+
+
+// Resource: tbmf 1000
+#define Icon_infoBitmapFamily 1000
+
+// Resource: tbmf 1100
+#define MsOnBitmapFamily 1100
+
+// Resource: tbmf 2000
+#define InfoBitmapFamily 2000
+
+// Resource: tbmf 1110
+#define MsNoneBitmapFamily 1110
+
+
+// Resource: taif 1000
+#define Largeicons12and8bitsAppIconFamily 1000
+
+// Resource: taif 1001
+#define Smallicons12and8bitsAppIconFamily 1001
+
diff --git a/backends/PalmOS/Src/extend.cpp b/backends/PalmOS/Src/extend.cpp
new file mode 100644
index 0000000000..6270165acd
--- /dev/null
+++ b/backends/PalmOS/Src/extend.cpp
@@ -0,0 +1,89 @@
+#include <PalmOS.h>
+#include "extend.h"
+#include "string.h"
+#include "palm.h"
+/*
+//Sony clie PalmOS<5
+void BmpDrawDDBitmap(const FormType *formP, DmResID bitmapID)
+{
+ MemHandle hTemp;
+ BitmapType* bmTemp;
+ Coord x,y;
+
+ hTemp = DmGetResource(bitmapRsc,bitmapID);
+ bmTemp = (BitmapType*)MemHandleLock(hTemp);
+
+ FrmGetObjectPosition(formP, FrmGetObjectIndex(formP,bitmapID), &x, &y);
+ HRWinDrawBitmap(gHRrefNum,bmTemp, x*2, y*2);
+
+ MemHandleUnlock(hTemp);
+ DmReleaseResource(hTemp);
+ // palmos 5 : need to set the object to usable
+}
+*/
+UInt16 StrReplace(Char *ioStr, UInt16 inMaxLen, const Char *inParamStr, const Char *fndParamStr)
+{
+ Char *found;
+ Boolean quit = false;
+ UInt16 occurences = 0;
+ UInt16 newLength;
+ UInt16 l1 = StrLen(fndParamStr);
+ UInt16 l2 = 0;
+ UInt16 l3 = StrLen(ioStr);
+ UInt16 next = 0;
+
+ if (inParamStr)
+ l2 = StrLen(inParamStr); // can be null to know how many occur.
+
+ while (((found = StrStr(ioStr+next, fndParamStr)) != NULL) && (!quit))
+ {
+ occurences++;
+ newLength = (StrLen(ioStr) - l1 + l2);
+
+ if ( newLength > inMaxLen )
+ {
+ quit = true;
+ occurences--;
+ }
+ else if (inParamStr)
+ {
+ MemMove(found + l2, found + l1, inMaxLen-(found-ioStr+l2));
+ MemMove(found, inParamStr, l2);
+ next = found - ioStr + l2;
+ }
+ else
+ next = found - ioStr + l1;
+ }
+
+ if (inParamStr)
+ ioStr[l3 + l2*occurences - l1*occurences] = 0;
+
+ return occurences;
+}
+
+void WinDrawWarpChars(const Char *chars, Int16 len, Coord x, Coord y, Coord maxWidth)
+{
+ Char *part = (Char *)chars;
+ Coord x2 = x;
+ Int16 next;
+
+ if (part[StrLen(part)-1] == '\n')
+ part[StrLen(part)-1] = 0;
+
+ part = StrTok(part," ");
+
+ while ( part )
+ {
+ next = FntLineWidth (part, StrLen(part)) + FntLineWidth (" ",1);
+ if ((x2 + next - x) > maxWidth)
+ {
+ x2 = x;
+ y += FntLineHeight();
+ }
+ //HRWinDrawTruncChars(gHRrefNum, part, StrLen(part), x2, y, maxWidth - (x2-x));
+ WinDrawTruncChars(part, StrLen(part), x2, y, maxWidth - (x2-x));
+ x2 += next;
+
+ part = StrTok(NULL," ");
+ }
+} \ No newline at end of file
diff --git a/backends/PalmOS/Src/extend.h b/backends/PalmOS/Src/extend.h
new file mode 100644
index 0000000000..7e61b1fc11
--- /dev/null
+++ b/backends/PalmOS/Src/extend.h
@@ -0,0 +1,15 @@
+#ifndef EXTEND_H
+#define EXTEND_H
+
+extern const Char *SCUMMVM_SAVEPATH; // extras.cpp
+
+#define DISABLE_SKY
+#define DISABLE_SIMON
+
+#define OutputDebugString PalmFatalError
+
+void WinDrawWarpChars(const Char *chars, Int16 len, Coord x, Coord y, Coord maxWidth);
+UInt16 StrReplace(Char *ioStr, UInt16 inMaxLen, const Char *inParamStr, const Char *fndParamStr);
+void PalmFatalError(const Char *err);
+
+#endif \ No newline at end of file
diff --git a/backends/PalmOS/Src/extras.cpp b/backends/PalmOS/Src/extras.cpp
new file mode 100644
index 0000000000..1c4a92d46f
--- /dev/null
+++ b/backends/PalmOS/Src/extras.cpp
@@ -0,0 +1,217 @@
+//##############################################################################
+#include "extras.h"
+#include "StarterRsc.h"
+#include "mathlib.h"
+#include "globals.h"
+//#include "palm.h"
+//##############################################################################
+//UInt16 gVolRefNum = 0;
+//UInt16 HRrefNum,SndRefNum;
+
+//FileRef logfile;
+//Boolean _flipping = false;
+//Boolean _vibrator = false;
+//extern Boolean gFlipping;
+//extern FileRef gLogFile;
+//##############################################################################
+//##############################################################################
+void *memchr(const void *s, int c, UInt32 n)
+{
+ UInt32 chr;
+ for(chr = 0; chr < n;chr++,((UInt8 *)s)++)
+ if ( *((UInt8 *)s) == c)
+ return (void *)s;
+
+ return NULL;
+}
+/*
+
+UInt32 time(UInt32 *cur)
+{
+ UInt32 secs = TimGetTicks();
+
+ if (cur != NULL)
+ *cur = secs;
+
+ return secs;
+}
+*/
+
+///////////////////////////////////////////////////////////////////////////////
+
+
+const Char *SCUMMVM_SAVEPATH = "/PALM/Programs/ScummVM/Saved/";
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+Err SonySoundLib(UInt16 *refNumP)
+{
+ SonySysFtrSysInfoP sonySysFtrSysInfoP;
+ Err error = errNone;
+
+ if ((error = FtrGet(sonySysFtrCreator, sonySysFtrNumSysInfoP, (UInt32*)&sonySysFtrSysInfoP))) {
+ /* Not CLIE: maybe not available */
+ } else {
+ if (sonySysFtrSysInfoP->libr & sonySysFtrSysInfoLibrFm) {
+ /* Sound-Lib available */
+ if ((error = SysLibFind(sonySysLibNameSound, refNumP))) {
+ if (error == sysErrLibNotFound) {
+ /* couldn't find lib */
+ error = SysLibLoad( 'libr', sonySysFileCSoundLib, refNumP );
+ }
+ }
+
+ if ( error ) {
+ /* Now we can use Sound-Lib */
+ FrmCustomAlert(FrmWarnAlert,"Sound Lib not found.",0,0);
+ }
+ }
+ }
+
+ if (!error)
+ FrmCustomAlert(FrmWarnAlert,"Sound Lib ok",0,0);
+
+ return error;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+
+
+//UInt8 _indicatorColorOn = 255;
+//UInt8 _indicatorColorOff = 0;
+
+
+
+
+
+/*
+int getc(FILE *stream)
+{
+ UInt8 c;
+ DrawStatus(true);
+ Err error = VFSFileRead(*stream, 1, &c, NULL);
+ DrawStatus(false);
+
+ if (error == errNone || error == vfsErrFileEOF)
+ return c;
+
+#ifdef DEBUG
+ switch (error)
+ {
+ case expErrNotOpen:
+ FrmCustomAlert(FrmWarn,"expErrNotOpen",0,0);
+ break;
+ case vfsErrFileBadRef:
+ FrmCustomAlert(FrmWarn,"vfsErrFileBadRef",0,0);
+ break;
+ case vfsErrFileEOF:
+ FrmCustomAlert(FrmWarn,"vfsErrFileEOF",0,0);
+ break;
+ case vfsErrFilePermissionDenied:
+ FrmCustomAlert(FrmWarn,"vfsErrFilePermissionDenied",0,0);
+ break;
+ case vfsErrIsADirectory:
+ FrmCustomAlert(FrmWarn,"vfsErrIsADirectory",0,0);
+ break;
+ case vfsErrNoFileSystem:
+ FrmCustomAlert(FrmWarn,"vfsErrNoFileSystem",0,0);
+ break;
+ }
+#endif
+ return 0;
+}
+
+*/
+/*
+static Char *enumSaveLoad = NULL;
+
+
+void doEnumSaveLoad(const Char* path, const Char* game)
+{
+ if (enumSaveLoad)
+ return;
+
+ FileRef fileRef;
+ Err e = VFSFileOpen(gVars->volRefNum, path, vfsModeRead, &fileRef);
+
+ if (e != errNone)
+ return;
+
+ UInt32 dirEntryIterator = vfsIteratorStart;
+ Char file[32];
+ FileInfoType info = {0, file, 32};
+ UInt16 lenght;
+ UInt32 oldSize = 0;
+ UInt32 count = 0;
+
+ while (dirEntryIterator != vfsIteratorStop)
+ {
+ e = VFSDirEntryEnumerate (fileRef, &dirEntryIterator, &info);
+ if (e != expErrEnumerationEmpty)
+ {
+ if (StrNCaselessCompare(game, info.nameP, StrLen(game)) == 0)
+ {
+ lenght = StrLen(info.nameP);
+ if (!enumSaveLoad)
+ enumSaveLoad = (Char *)MemPtrNew(lenght+1);
+ else
+ {
+ oldSize = MemPtrSize(enumSaveLoad);
+ enumSaveLoad = (Char *)realloc(enumSaveLoad, oldSize + StrLen(info.nameP)+1);
+ }
+ TxtGlueLowerStr(info.nameP,StrLen(info.nameP));
+ StrCopy(enumSaveLoad+oldSize, info.nameP);
+ count++;
+ }
+ }
+ }
+
+ if (count == 0) { // if no files, create an empty list item to prevent ALL FILES EXIST
+ enumSaveLoad = (Char *)MemPtrNew(1);
+ enumSaveLoad[0] = 0;
+ }
+// if (count > 20)
+// endEnumSaveLoad(); // too manu files
+}
+
+void endEnumSaveLoad()
+{
+ if (!enumSaveLoad)
+ return;
+
+ MemPtrFree(enumSaveLoad);
+ enumSaveLoad = NULL;
+}
+
+Boolean fexists(const Char* filename)
+{
+ if (!enumSaveLoad)
+ return true;
+
+ Char *found;
+ UInt32 search = 0;
+ UInt32 size = MemPtrSize(enumSaveLoad);
+ UInt32 length = StrLen(filename);
+
+// Char find[256];
+// StrCopy(find,filename);
+ TxtGlueLowerStr((Char *)filename,length);
+
+ while (search < size)
+ {
+ found = StrStr(filename, enumSaveLoad+search);
+ if ( found && found == (filename+length-StrLen(enumSaveLoad+search)) )
+ return true;
+
+ search += StrLen(enumSaveLoad+search)+1;
+ }
+
+ return false;
+}*/
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
diff --git a/backends/PalmOS/Src/extras.h b/backends/PalmOS/Src/extras.h
new file mode 100644
index 0000000000..8fcb5b19e7
--- /dev/null
+++ b/backends/PalmOS/Src/extras.h
@@ -0,0 +1,134 @@
+//##############################################################################
+#include <PalmOS.h>
+#include <PalmOSGlue.h>
+#include "SonyClie.h"
+#include "VFSMgr.h"
+#include "mathlib.h"
+#include "vibrate.h"
+
+#include <stdarg.h>
+//##############################################################################
+//##############################################################################
+int main(int argc, char **argv);
+MemPtr realloc(MemPtr, UInt32);
+MemPtr calloc(UInt32, UInt32);
+void exit(int);
+
+//UInt16 parseCards(Boolean forceDisplay);
+
+Err CheckMathLib();
+//Err CheckHRmode(void);
+Err SonySoundLib(UInt16 *refNumP);
+UInt16 StrReplace(Char *ioStr, UInt16 inMaxLen, const Char *inParamStr, const Char *fndParamStr);
+Int16 vsprintf(Char* s, const Char* formatStr, _Palm_va_list argParam);
+Int16 sprintf(Char* s, const Char* formatStr, ...);
+Int16 printf(const Char* formatStr, ...);
+//void xsprintf(const Char* formatStr, ...);
+void PalmFatalError(const Char *err);
+
+typedef FileRef FILE;
+UInt16 FindFileSlot();
+FILE *fopen(const char *filename, const char *type);
+UInt16 fprintf(FILE *stream, const Char *format, ...);
+int feof(FILE *stream);
+void clearerr(FILE *stream);
+UInt32 fread(void *ptr, UInt32 size, UInt32 nitems, FILE *stream);
+int fseek(FILE *stream, long offset, int whence);
+int fclose(FILE *stream);
+char *fgets(char *s, UInt32 n, FILE *stream);
+int free(MemPtr ptr);
+UInt32 fwrite(void *ptr, UInt32 size, UInt32 nitems, FILE *stream);
+int ftell(FILE *stream);
+//int getc(FILE *stream);
+
+void *memchr(const void *s, int c, UInt32 n);
+Char *StrTok(Char *str, const Char *sep);
+void WinDrawWarpChars(const Char *chars, Int16 len, Coord x, Coord y, Coord maxWidth);
+
+Err HwrDisplayPalette(UInt8 operation, Int16 startIndex,
+ UInt16 paletteEntries, RGBColorType *tableP)
+ SYS_TRAP(sysTrapHwrDisplayPalette);
+
+//#define memNewChunkFlagNonMovable 0x0200
+#define memNewChunkFlagAllowLarge 0x1000 // this is not in the sdk *g*
+
+
+SysAppInfoPtr SysGetAppInfo(SysAppInfoPtr *uiAppPP, SysAppInfoPtr *actionCodeAppPP)
+ SYS_TRAP(sysTrapSysGetAppInfo);
+
+//##############################################################################
+//#define DEBUG
+#define MAXPATHLEN 255
+#define NONSTANDARD_SAVE // scumm.h
+////////////////////////////////////////////////////////////////////////////////
+/*
+extern UInt16 firstCard;
+extern UInt16 HRrefNum;
+extern UInt16 SndRefNum;
+
+extern FileRef logfile;
+extern Boolean _flipping;
+extern Boolean _vibrator;
+*/
+
+//extern UInt8 *screen_1;
+//extern UInt8 *screen_2;
+
+//extern Char **argvP;
+
+//#define assert(a)
+//#define fflush(a)
+
+//#define OutputDebugString PalmFatalError
+
+//#define SEEK_SET vfsOriginBeginning
+//#define SEEK_CUR vfsOriginCurrent
+//#define SEEK_END vfsOriginEnd
+
+//#define strtol(a,b,c) StrAToI(a)
+
+//#define abs fabs
+/*
+//#define malloc MemPtrNew
+//#define calloc(a,b) MemPtrNew(((UInt32)a)*((UInt32)b))
+#define memcpy MemMove
+#define memmove MemMove
+//#define free MemPtrFree
+#define strcmp StrCompare
+#define strncmp StrNCompare
+#define stricmp StrCaselessCompare
+#define atoi StrAToI
+#define tolower TxtGlueLowerChar
+#define strchr StrChr
+#define strcat StrCat
+//#define vsprintf StrVPrintF
+//#define sprintf StrPrintF
+#define strtok StrTok
+#define rand() SysRandom(0)
+#define strncpy MemMove
+
+
+#define stdin 0
+#define stdout &logfile
+#define stderr &logfile
+
+#define memset(ptr,value,numBytes) MemSet(ptr,numBytes,value)
+*/
+//typedef UInt32 time_t;
+//UInt32 time(UInt32 *cur);
+
+#define bool Boolean
+typedef unsigned int uint;
+typedef unsigned long uint32;
+// scumm protos
+///////////////
+struct AkosRenderer;
+// akos.cpp
+void akos_c1_0y_decode(AkosRenderer * ar);
+void akos_generic_decode(AkosRenderer * ar);
+void akos_c1_spec1(AkosRenderer * ar);
+// sound.cpp
+int CompDecode(unsigned char *src, unsigned char *dst);
+// simon.cpp
+void palette_fadeout(uint32 *pal_values,uint num);
+uint fileReadItemID(FILE *in);
diff --git a/backends/PalmOS/Src/globals.h b/backends/PalmOS/Src/globals.h
new file mode 100644
index 0000000000..f25ba9f547
--- /dev/null
+++ b/backends/PalmOS/Src/globals.h
@@ -0,0 +1,35 @@
+#ifndef GLOBALS_H
+#define GLOBALS_H
+
+typedef struct {
+ DmOpenRef globals[3];
+
+ UInt16 HRrefNum;
+ UInt16 volRefNum;
+ FileRef logFile;
+
+ Boolean screenLocked;
+ Boolean vibrator;
+ Boolean stdPalette;
+/*
+ struct {
+ UInt16 speaker;
+ UInt16 headphone;
+ } volume;
+*/
+ struct {
+ UInt8 on;
+ UInt8 off;
+ } indicator;
+
+ struct {
+ UInt8 *pageAddr1;
+ UInt8 *pageAddr2;
+ } flipping;
+
+} GlobalsDataType;
+
+extern GlobalsDataType *gVars;
+
+
+#endif \ No newline at end of file
diff --git a/backends/PalmOS/Src/init.cpp b/backends/PalmOS/Src/init.cpp
new file mode 100644
index 0000000000..f25c38e226
--- /dev/null
+++ b/backends/PalmOS/Src/init.cpp
@@ -0,0 +1,9 @@
+//#include <PalmOS.h>
+//#include "palm.h"
+//#include "starterrsc.h"
+
+//UInt16 gHRrefNum = 0;
+//Boolean gVibrator = false;
+//Boolean gFlipping = false;
+//Boolean gScreenLocked = false;
+
diff --git a/backends/PalmOS/Src/missing/_stdio.cpp b/backends/PalmOS/Src/missing/_stdio.cpp
new file mode 100644
index 0000000000..5d22b04bbc
--- /dev/null
+++ b/backends/PalmOS/Src/missing/_stdio.cpp
@@ -0,0 +1,344 @@
+#include "stdio.h"
+#include "extend.h"
+///////////////////////////////////////////////////////////////////////////////
+//FileRef gLogFile;
+
+static void DrawStatus(Boolean show)
+{
+ UInt8 x,y;
+ UInt8 *screen = (UInt8 *)(BmpGetBits(WinGetBitmap(WinGetDisplayWindow())));
+ UInt8 color = (show? gVars->indicator.on : gVars->indicator.off);
+
+ if (gVars->screenLocked)
+ if (screen == gVars->flipping.pageAddr1)
+ screen = gVars->flipping.pageAddr2;
+ else
+ screen = gVars->flipping.pageAddr1;
+
+ screen += 320 + 305;
+ for(y=0;y<3;y++)
+ {
+ for(x=0;x<14;x++)
+ screen[x] = color;
+ screen += 319;
+ }
+}
+///////////////////////////////////////////////////////////////////////////////
+UInt16 fclose(FileRef *stream)
+{
+ Err error = VFSFileClose(*stream);
+
+ if (error == errNone)
+ MemPtrFree(stream);
+
+#ifdef DEBUG
+ FrmCustomAlert(FrmWarnAlert,"error fclose",0,0);
+#endif
+ return error;
+}
+///////////////////////////////////////////////////////////////////////////////
+UInt16 feof(FileRef *stream)
+{
+ Err error = VFSFileEOF(*stream);
+
+#ifdef DEBUG
+ switch (error)
+ {
+ case vfsErrFileEOF:
+ FrmCustomAlert(FrmWarnAlert,"vfsErrFileEOF",0,0);
+ break;
+ case expErrNotOpen:
+ FrmCustomAlert(FrmWarnAlert,"expErrNotOpen",0,0);
+ break;
+ case vfsErrFileBadRef:
+ FrmCustomAlert(FrmWarnAlert,"vfsErrFileBadRef",0,0);
+ break;
+ case vfsErrIsADirectory:
+ FrmCustomAlert(FrmWarnAlert,"vfsErrIsADirectory",0,0);
+ break;
+ case vfsErrNoFileSystem:
+ FrmCustomAlert(FrmWarnAlert,"vfsErrNoFileSystem",0,0);
+ break;
+ }
+#endif
+
+ return error;
+}
+///////////////////////////////////////////////////////////////////////////////
+Char *fgets(Char *s, UInt32 n, FileRef *stream)
+{
+ UInt32 numBytesRead;
+ DrawStatus(true);
+ Err error = VFSFileRead(*stream, n, s, &numBytesRead);
+ DrawStatus(false);
+ if (error == errNone || error == vfsErrFileEOF) {
+ UInt32 reset = 0;
+ Char *endLine = StrChr(s, '\n');
+
+ if (endLine >= s) {
+ reset = (endLine - s);
+ s[reset] = 0;
+ reset = numBytesRead - (reset + 1);
+ VFSFileSeek(*stream, vfsOriginCurrent, -reset);
+ }
+
+ return s;
+ }
+#ifdef DEBUG
+ switch (error)
+ {
+ case expErrNotOpen:
+ FrmCustomAlert(FrmWarnAlert,"expErrNotOpen",0,0);
+ break;
+ case vfsErrFileBadRef:
+ FrmCustomAlert(FrmWarnAlert,"vfsErrFileBadRef",0,0);
+ break;
+ case vfsErrFileEOF:
+ FrmCustomAlert(FrmWarnAlert,"vfsErrFileEOF",0,0);
+ break;
+ case vfsErrFilePermissionDenied:
+ FrmCustomAlert(FrmWarnAlert,"vfsErrFilePermissionDenied",0,0);
+ break;
+ case vfsErrIsADirectory:
+ FrmCustomAlert(FrmWarnAlert,"vfsErrIsADirectory",0,0);
+ break;
+ case vfsErrNoFileSystem:
+ FrmCustomAlert(FrmWarnAlert,"vfsErrNoFileSystem",0,0);
+ break;
+ }
+#endif
+
+ return NULL;
+}
+///////////////////////////////////////////////////////////////////////////////
+FileRef *fopen(const Char *filename, const Char *type)
+{
+ Err err;
+ UInt16 openMode;
+ FileRef *fileRefP = (FileRef *)MemPtrNew(sizeof(FileRef *));
+
+ if (StrCompare(type,"r")==0)
+ openMode = vfsModeRead;
+ else if (StrCompare(type,"rb")==0)
+ openMode = vfsModeRead;
+ else if (StrCompare(type,"w")==0)
+ openMode = vfsModeCreate|vfsModeWrite;
+ else if (StrCompare(type,"wb")==0)
+ openMode = vfsModeCreate|vfsModeWrite;
+ else
+ openMode = vfsModeReadWrite;
+
+ if (openMode & vfsModeRead) {
+ // if read file :
+ // first try to load from the specfied card
+ err = VFSFileOpen (gVars->volRefNum, filename, openMode, fileRefP);
+ //if err (not found ?) parse each avalaible card for the specified file
+ if (err) {
+ UInt16 volRefNum;
+ UInt32 volIterator = vfsIteratorStart;
+ while (volIterator != vfsIteratorStop) {
+ err = VFSVolumeEnumerate(&volRefNum, &volIterator);
+
+ if (!err) {
+ err = VFSFileOpen (volRefNum, filename, openMode, fileRefP);
+ if (!err)
+ return fileRefP;
+ }
+ }
+ } else {
+ return fileRefP;
+ }
+ } else {
+ // if write file :
+ // use only the specified card
+ // FIXME : vfsModeCreate|vfsModeWrite will failed on OS3.5 Clié
+ err = VFSFileDelete(gVars->volRefNum, filename); // delete it if exists
+ err = VFSFileCreate(gVars->volRefNum, filename);
+ openMode = vfsModeWrite;
+ if (!err) {
+ err = VFSFileOpen (gVars->volRefNum, filename, openMode, fileRefP);
+ if (!err)
+ return fileRefP;
+ }
+ }
+
+#ifdef DEBUG
+ else
+ {
+ switch (err)
+ {
+ case expErrCardReadOnly:
+ FrmCustomAlert(FrmWarnAlert,"expErrCardReadOnly",0,0);
+ break;
+ case expErrNotOpen:
+ FrmCustomAlert(FrmWarnAlert,"expErrNotOpen",0,0);
+ break;
+ case vfsErrBadName:
+ FrmCustomAlert(FrmWarnAlert,"vfsErrBadName",0,0);
+ break;
+ case vfsErrFileNotFound:
+ FrmCustomAlert(FrmWarnAlert,"vfsErrFileNotFound",0,0);
+ break;
+ case vfsErrFilePermissionDenied:
+ FrmCustomAlert(FrmWarnAlert,"vfsErrFilePermissionDenied",0,0);
+ break;
+ case vfsErrVolumeBadRef:
+ FrmCustomAlert(FrmWarnAlert,"vfsErrVolumeBadRef",0,0);
+ break;
+ default:
+ FrmCustomAlert(FrmWarnAlert,"unknow",0,0);
+ break;
+ }
+ }
+#endif
+
+ MemPtrFree(fileRefP); // prevent memory leak
+ return NULL;
+}
+///////////////////////////////////////////////////////////////////////////////
+UInt32 fread(void *ptr, UInt32 size, UInt32 nitems, FileRef *stream)
+{
+ UInt32 numBytesRead;
+ DrawStatus(true);
+ Err error = VFSFileRead(*stream, size*nitems, ptr, &numBytesRead);
+ DrawStatus(false);
+ if (error == errNone || error == vfsErrFileEOF)
+ return (UInt32)(numBytesRead/size);
+
+#ifdef DEBUG
+ switch (error)
+ {
+ case expErrNotOpen:
+ FrmCustomAlert(FrmWarn,"expErrNotOpen",0,0);
+ break;
+ case vfsErrFileBadRef:
+ FrmCustomAlert(FrmWarn,"vfsErrFileBadRef",0,0);
+ break;
+ case vfsErrFileEOF:
+ FrmCustomAlert(FrmWarn,"vfsErrFileEOF",0,0);
+ break;
+ case vfsErrFilePermissionDenied:
+ FrmCustomAlert(FrmWarn,"vfsErrFilePermissionDenied",0,0);
+ break;
+ case vfsErrIsADirectory:
+ FrmCustomAlert(FrmWarn,"vfsErrIsADirectory",0,0);
+ break;
+ case vfsErrNoFileSystem:
+ FrmCustomAlert(FrmWarn,"vfsErrNoFileSystem",0,0);
+ break;
+ }
+#endif
+ return 0;
+}
+///////////////////////////////////////////////////////////////////////////////
+UInt32 fwrite(const void *ptr, UInt32 size, UInt32 nitems, FileRef *stream)
+{
+ UInt32 numBytesWritten;
+ DrawStatus(true);
+ Err error = VFSFileWrite(*stream, size*nitems, ptr, &numBytesWritten);
+ DrawStatus(false);
+
+ if (error == errNone || error == vfsErrFileEOF)
+ return (UInt32)(numBytesWritten/size);
+
+ return NULL;
+}
+///////////////////////////////////////////////////////////////////////////////
+Int32 fseek(FileRef *stream, Int32 offset, Int32 whence)
+{
+ Err error = VFSFileSeek(*stream, whence, offset);
+ return error;
+}
+///////////////////////////////////////////////////////////////////////////////
+UInt32 ftell(FileRef *stream)
+{
+ Err e;
+ UInt32 filePos;
+
+ e = VFSFileTell(*stream,&filePos);
+ if (e != errNone)
+ return e;
+
+ return filePos;
+}
+///////////////////////////////////////////////////////////////////////////////
+UInt16 fprintf(FileRef *stream, const Char *format, ...)
+{
+ if (!*stream)
+ return 0;
+
+ UInt32 numBytesWritten;
+ Char buf[256];
+ va_list va;
+
+ va_start(va, format);
+ vsprintf(buf, format, va);
+ va_end(va);
+
+ VFSFileWrite (*stream, StrLen(buf), buf, &numBytesWritten);
+ return numBytesWritten;
+}
+///////////////////////////////////////////////////////////////////////////////
+Int16 printf(const Char *format, ...)
+{
+ if (!*stdout)
+ return 0;
+
+ UInt32 numBytesWritten;
+ Char buf[256];
+// Char *buf = (Char *)MemPtrNew(256);
+ va_list va;
+
+ va_start(va, format);
+ vsprintf(buf, format, va);
+ va_end(va);
+
+ VFSFileWrite (*stdout, StrLen(buf), buf, &numBytesWritten);
+// MemPtrFree(buf);
+ return numBytesWritten;
+}
+///////////////////////////////////////////////////////////////////////////////
+Int16 sprintf(Char* s, const Char* formatStr, ...)
+{
+ Char buf[256];
+// Char *buf = (Char *)MemPtrNew(256);
+ Int16 count;
+ va_list va;
+
+ va_start(va, formatStr);
+ count = vsprintf(buf, formatStr, va);
+ va_end(va);
+
+ StrCopy(s,buf);
+// MemPtrFree(buf);
+ return count;
+}
+///////////////////////////////////////////////////////////////////////////////
+Int16 vsprintf(Char* s, const Char* formatStr, _Palm_va_list argParam)
+{
+ Char format[256];
+ // TODO : need a better modifier
+ StrCopy(format,formatStr);
+ StrReplace(format, 256, "%ld", "%d");
+ StrReplace(format, 256, "%li", "%i");
+ StrReplace(format, 256, "%lx", "%x");
+ StrReplace(format, 256, "%lx", "%X");
+ StrReplace(format, 256, "%2ld", "%2d");
+ StrReplace(format, 256, "%03ld","%.3d");
+ StrReplace(format, 256, "%02ld","%.2d");
+ StrReplace(format, 256, "%01ld","%.1d");
+ StrReplace(format, 256, "%02ld","%02d");
+
+ StrReplace(format, 256, "%2ld","%2d");
+ StrReplace(format, 256, "%3ld","%3d");
+ StrReplace(format, 256, "%4ld","%4d");
+ StrReplace(format, 256, "%5ld","%5d");
+ StrReplace(format, 256, "%6ld","%6d");
+ StrReplace(format, 256, "%02lx","%02x");
+
+ return StrVPrintF(s, format, argParam);;
+}
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
diff --git a/backends/PalmOS/Src/missing/_stdlib.cpp b/backends/PalmOS/Src/missing/_stdlib.cpp
new file mode 100644
index 0000000000..916987a5ca
--- /dev/null
+++ b/backends/PalmOS/Src/missing/_stdlib.cpp
@@ -0,0 +1,213 @@
+#include "stdlib.h"
+#include "MemGlue.h"
+///////////////////////////////////////////////////////////////////////////////
+/*void qsort(void *base, UInt32 nmemb, UInt32 size, ComparF *compar) {
+
+ SysQSort(base, nmemb, size, compar);
+}*/
+///////////////////////////////////////////////////////////////////////////////
+void *bsearch(const void *key, const void *base, UInt32 nmemb,
+ UInt32 size, int (*compar)(const void *, const void *)) {
+ UInt32 i;
+
+ for (i=0; i<nmemb; i++)
+ if (compar(key, (void*)((UInt32)base + size * i)) == 0)
+ return (void*)((UInt32)base + size * i);
+ return NULL;
+}
+///////////////////////////////////////////////////////////////////////////////
+static DmOpenRef gExtMemory = NULL;
+
+static UInt16 MemFindHeapID(UInt32 size)
+{
+ UInt32 nFree, maxChunk ;
+ UInt16 maxCards = 1; //MemNumCards(); process only first card for now
+ UInt16 heapID = -1; // no heap avaliable
+
+ UInt16 cardNo;
+ UInt16 maxHeaps, heapIndex;
+
+ for (cardNo = 0; cardNo < maxCards; cardNo++)
+ {
+ if (MemNumRAMHeaps(cardNo) > 0)
+ {
+ maxHeaps = MemNumHeaps(cardNo);
+ for (heapIndex = 0; heapIndex < maxHeaps; heapIndex++)
+ {
+ // Obtain the ID of the heap.
+ heapID = MemHeapID(cardNo, heapIndex);
+
+ if (!(MemHeapFlags(heapID) & memHeapFlagReadOnly))
+ {
+ MemHeapFreeBytes( heapID, &nFree, &maxChunk );
+ if (maxChunk > size)
+ return heapID;
+ }
+ }
+ }
+ }
+
+ return heapID;
+}
+
+void MemExtInit()
+{
+ if (!gExtMemory)
+ {
+ LocalID localID = DmFindDatabase(0, "ScummVM-Memory");
+ if (localID) DmDeleteDatabase(0, localID);
+
+ if (DmCreateDatabase (0, "ScummVM-Memory", 'ScVM', 'DATA', false) != errNone)
+ return;
+
+ localID = DmFindDatabase(0, "ScummVM-Memory");
+ gExtMemory = DmOpenDatabase(0, localID, dmModeReadWrite|dmModeExclusive);
+ }
+}
+
+void MemExtCleanup()
+{
+ if (gExtMemory) {
+ DmCloseDatabase(gExtMemory);
+ LocalID localID = DmFindDatabase(0, "ScummVM-Memory");
+ if (localID)
+ DmDeleteDatabase(0, localID);
+ }
+}
+//#define USE_EXTENDEDMEM
+#ifdef USE_EXTENDEDMEM
+
+MemPtr calloc(UInt32 nelem, UInt32 elsize)
+{
+ UInt32 size = nelem*elsize;
+ MemPtr newP = NULL;
+ UInt16 heapID = MemFindHeapID(size);
+
+ if (heapID != NO_HEAP_FOUND)
+ {
+ if (MemHeapDynamic(heapID) && size < 65536-8) // 8 = chunk header size
+ newP = MemPtrNew(size);
+ else
+ {
+ SysAppInfoPtr appInfoP;
+ UInt16 ownerID, large, nmovable;
+ UInt16 attr;
+
+ ownerID = ((SysAppInfoPtr)SysGetAppInfo(&appInfoP, &appInfoP))->memOwnerID;
+ large = ((size > 65536-8) ? memNewChunkFlagAllowLarge : 0);
+ nmovable= (MemHeapDynamic(heapID) ? memNewChunkFlagNonMovable : memNewChunkFlagPreLock);
+ attr = ownerID|large|nmovable;
+
+ //MEMORY_RESERVE_ACCESS
+ newP = MemChunkNew(heapID, size, attr);
+ //MEMORY_RELEASE_ACCESS
+
+ if (newP && MemPtrDataStorage(newP)) { // if storage heap ?
+ if (!gExtMemory) { // if memory DB doesn't exist
+ MemChunkFree(newP);
+ return NULL;
+ }
+
+ UInt16 index = dmMaxRecordIndex; // used for record purpose
+ MemHandle newH = MemPtrRecoverHandle(newP); // exists
+ if (DmAttachRecord(gExtMemory, &index, newH, NULL) != errNone) // attach to DB
+ {
+ MemChunkFree(newP); // error
+ return NULL;
+ }
+ }
+ }
+ }
+
+ if (newP)
+ MemSet(newP,size,0);
+
+ return newP;
+}
+
+#else
+
+MemPtr calloc(UInt32 nelem, UInt32 elsize)
+{
+ UInt32 size = nelem*elsize;
+ MemPtr newP = NULL;
+
+/* if (size < 65536-8) // 8 = chunk header size
+ newP = MemPtrNew(size);
+ else*/
+/* {
+ SysAppInfoPtr appInfoP;
+ UInt16 ownerID;
+ UInt16 attr;
+
+ ownerID = ((SysAppInfoPtr)SysGetAppInfo(&appInfoP, &appInfoP))->memOwnerID;
+ attr = ownerID|memNewChunkFlagAllowLarge|memNewChunkFlagNonMovable;
+
+ newP = MemChunkNew(0, size, attr);
+ }
+*/
+ newP = MemGluePtrNew(size);
+
+ if (newP)
+ MemSet(newP,size,0);
+
+ return newP;
+}
+
+#endif
+///////////////////////////////////////////////////////////////////////////////
+#ifdef USE_EXTENDEDMEM
+Err free(MemPtr memP)
+{
+ Err err = memErrInvalidParam;
+
+ if (!memP)
+ return err;
+
+ if (MemPtrDataStorage(memP)) { // if storage heap ?
+ if (gExtMemory) { // if memory DB exists
+ DmOpenRef where;
+ MemHandle newH = MemPtrRecoverHandle(memP);
+ UInt16 index = DmSearchRecord(newH, &where);
+ err = DmRemoveRecord(gExtMemory, index);
+ }
+ }
+ else
+ err = MemChunkFree(memP);
+
+ return err;
+}
+#else
+Err free(MemPtr memP)
+{
+ if (memP)
+ return MemPtrFree(memP);
+
+ return memErrInvalidParam;
+}
+#endif
+///////////////////////////////////////////////////////////////////////////////
+MemPtr realloc(MemPtr oldP, UInt32 size)
+{
+
+ if (oldP != NULL)
+ if (MemPtrResize(oldP,size) == 0)
+ return oldP;
+
+ MemPtr newP = MemPtrNew(size);
+
+ if (oldP!=NULL)
+ {
+ MemMove(newP,oldP,MemPtrSize(oldP));
+ MemPtrFree(oldP);
+ }
+ return newP;
+}
+///////////////////////////////////////////////////////////////////////////////
+void exit(Int16 status)
+{
+ // need to change this
+ EventType event;
+ event.eType = appStopEvent;
+ EvtAddEventToQueue (&event);
+} \ No newline at end of file
diff --git a/backends/PalmOS/Src/missing/_string.cpp b/backends/PalmOS/Src/missing/_string.cpp
new file mode 100644
index 0000000000..6f7ed9bb77
--- /dev/null
+++ b/backends/PalmOS/Src/missing/_string.cpp
@@ -0,0 +1,86 @@
+#include "string.h"
+
+Char *StrTokNext;
+///////////////////////////////////////////////////////////////////////////////
+Char *strtok(Char *str, const Char *sep)
+{
+ Char *position = NULL,
+ *found,
+ *end;
+
+ UInt16 loop = 0,
+ chars= StrLen(sep);
+
+ str = (str)?(str):(StrTokNext);
+ StrTokNext = NULL;
+
+ if (!str)
+ return NULL;
+
+ end = str+StrLen(str);
+
+ while (loop<chars)
+ {
+ found = StrChr(str,sep[loop]);
+ loop++;
+
+ if (found == str)
+ {
+ str++;
+ loop = 0;
+ }
+ else if (position == NULL || position > found)
+ position = found;
+ }
+
+ if (position == NULL)
+ if (str==end)
+ return NULL;
+ else
+ return str;
+
+ position[0] = 0;
+ StrTokNext = position+1;
+
+ return str;
+}
+///////////////////////////////////////////////////////////////////////////////
+Char *strpbrk(const Char *s1, const Char *s2)
+{
+ Char *found;
+ UInt32 n;
+
+ for (n=0; n <= StrLen(s2); n++) {
+ found = StrChr(s1, s2[n]);
+ if (found)
+ return found;
+ }
+
+ return NULL;
+}
+///////////////////////////////////////////////////////////////////////////////
+Char *strrchr(const Char *s, int c)
+{
+ UInt32 chr;
+ UInt32 n = StrLen(s);
+
+ for(chr = n; chr >= 0; chr--)
+ if ( *((UInt8 *)s+chr) == c)
+ return (Char *)(s+chr);
+
+ return NULL;
+}
+///////////////////////////////////////////////////////////////////////////////
+Char *strdup(const Char *s1)
+{
+ Char* buf = (Char *)MemPtrNew(StrLen(s1)+1);
+
+ if(buf)
+ StrCopy(buf, s1);
+
+ return buf;
+}
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
diff --git a/backends/PalmOS/Src/missing/_time.cpp b/backends/PalmOS/Src/missing/_time.cpp
new file mode 100644
index 0000000000..afac9bce10
--- /dev/null
+++ b/backends/PalmOS/Src/missing/_time.cpp
@@ -0,0 +1,38 @@
+#include "time.h"
+
+// ignore GMT, only device time
+
+time_t time(time_t *tloc) {
+ UInt32 secs = TimGetSeconds(); // since 1/1/1904 12AM.
+ DateTimeType Epoch = {0, 0, 0, 1, 1, 1970, 0}; // form 1/1/1904 12AM to 1/1/1970 12AM
+
+ secs -= TimDateTimeToSeconds (&Epoch);
+
+ if (tloc)
+ *tloc = secs;
+
+ return (secs);
+}
+
+
+struct tm *localtime(const time_t *timer) {
+ static struct tm tmDate;
+
+ DateTimeType dt;
+ UInt32 secs = *timer;
+ DateTimeType Epoch = {0, 0, 0, 1, 1, 1970, 0}; // form 1/1/1904 12AM to 1/1/1970 12AM
+ // timer supposed to be based on Epoch
+ secs += TimDateTimeToSeconds(&Epoch);
+
+ TimSecondsToDateTime (secs, &dt);
+
+ tmDate.tm_sec = dt.second;
+ tmDate.tm_min = dt.minute;
+ tmDate.tm_hour = dt.hour;
+ tmDate.tm_mday = dt.day;
+ tmDate.tm_mon = dt.month;
+ tmDate.tm_year = dt.year;
+ tmDate.tm_wday = dt.weekDay;
+
+ return &tmDate;
+} \ No newline at end of file
diff --git a/backends/PalmOS/Src/missing/_unistd.cpp b/backends/PalmOS/Src/missing/_unistd.cpp
new file mode 100644
index 0000000000..bf4e0da0d9
--- /dev/null
+++ b/backends/PalmOS/Src/missing/_unistd.cpp
@@ -0,0 +1,14 @@
+#include "unistd.h"
+#include "extend.h" // for SCUMMVM_SAVEPATH
+
+
+// currently used only to retreive savepath
+Char *getcwd(Char *buf, UInt32 size) {
+ Char *copy = buf;
+
+ if (!copy)
+ copy = (Char *)MemPtrNew(StrLen(SCUMMVM_SAVEPATH)); // this may never occured
+
+ StrCopy(copy, SCUMMVM_SAVEPATH);
+ return copy;
+} \ No newline at end of file
diff --git a/backends/PalmOS/Src/missing/assert.h b/backends/PalmOS/Src/missing/assert.h
new file mode 100644
index 0000000000..5f021cd6d3
--- /dev/null
+++ b/backends/PalmOS/Src/missing/assert.h
@@ -0,0 +1 @@
+#define assert(a) \ No newline at end of file
diff --git a/backends/PalmOS/Src/missing/fcntl.h b/backends/PalmOS/Src/missing/fcntl.h
new file mode 100644
index 0000000000..a6b5294568
--- /dev/null
+++ b/backends/PalmOS/Src/missing/fcntl.h
@@ -0,0 +1 @@
+/* nothing */ \ No newline at end of file
diff --git a/backends/PalmOS/Src/missing/math.h b/backends/PalmOS/Src/missing/math.h
new file mode 100644
index 0000000000..b527ffcf42
--- /dev/null
+++ b/backends/PalmOS/Src/missing/math.h
@@ -0,0 +1 @@
+#include "mathlib.h" \ No newline at end of file
diff --git a/backends/PalmOS/Src/missing/stdio.h b/backends/PalmOS/Src/missing/stdio.h
new file mode 100644
index 0000000000..5a42917d04
--- /dev/null
+++ b/backends/PalmOS/Src/missing/stdio.h
@@ -0,0 +1,34 @@
+#include <PalmOS.h>
+#include <VFSMgr.h>
+#include <stdarg.h>
+#include "globals.h"
+
+//extern UInt16 gVolRefNum;
+//extern FileRef gLogFile;
+
+typedef FileRef FILE;
+
+#define stdin 0
+#define stdout (&gVars->logFile)
+#define stderr (&gVars->logFile)
+
+#define clearerr(a)
+#define fflush(a)
+#define vsnprintf(a,b,c,d) vsprintf(a,c,d)
+
+#define SEEK_SET vfsOriginBeginning
+#define SEEK_CUR vfsOriginCurrent
+#define SEEK_END vfsOriginEnd
+
+UInt16 fclose(FileRef *stream);
+UInt16 feof(FileRef *stream);
+Char *fgets(Char *s, UInt32 n, FileRef *stream);
+FileRef *fopen(const Char *filename, const Char *type);
+UInt32 fread(void *ptr, UInt32 size, UInt32 nitems, FileRef *stream);
+UInt32 fwrite(const void *ptr, UInt32 size, UInt32 nitems, FileRef *stream);
+Int32 fseek(FileRef *stream, Int32 offset, Int32 whence);
+UInt32 ftell(FileRef *stream);
+UInt16 fprintf(FileRef *stream, const Char *format, ...);
+Int16 printf(const Char* formatStr, ...);
+Int16 sprintf(Char* s, const Char* formatStr, ...);
+Int16 vsprintf(Char* s, const Char* formatStr, _Palm_va_list argParam);
diff --git a/backends/PalmOS/Src/missing/stdlib.h b/backends/PalmOS/Src/missing/stdlib.h
new file mode 100644
index 0000000000..b0d0145be0
--- /dev/null
+++ b/backends/PalmOS/Src/missing/stdlib.h
@@ -0,0 +1,38 @@
+#ifndef STDLIB_H
+#define STDLIB_H
+
+#include <PalmOS.h>
+#include "mathlib.h"
+
+//#define memNewChunkFlagNonMovable 0x0200
+#define memNewChunkFlagAllowLarge 0x1000 // this is not in the sdk *g*
+#define memHeapFlagReadOnly 0x0001
+
+#define NO_HEAP_FOUND -1
+
+SysAppInfoPtr SysGetAppInfo(SysAppInfoPtr *uiAppPP, SysAppInfoPtr *actionCodeAppPP)
+ SYS_TRAP(sysTrapSysGetAppInfo);
+
+
+#define atoi StrAToI
+#define atol StrAToI
+#define abs(a) ((a) < 0 ? -(a) : (a))
+//#define abs fabs
+#define malloc(a) calloc(a,1)
+//#define free MemPtrFree
+#define strtol(a,b,c) StrAToI(a)
+#define qsort(a,b,c,d)
+#define rand() SysRandom(0)
+
+void MemExtInit();
+void MemExtCleanup();
+
+MemPtr realloc(MemPtr oldP, UInt32 size);
+MemPtr calloc(UInt32 nelem, UInt32 elsize);
+Err free(MemPtr memP);
+void exit(Int16 status);
+void *bsearch(const void *key, const void *base, UInt32 nmemb,
+ UInt32 size, int (*compar)(const void *, const void *));
+
+
+#endif \ No newline at end of file
diff --git a/backends/PalmOS/Src/missing/string.h b/backends/PalmOS/Src/missing/string.h
new file mode 100644
index 0000000000..f19e54ffa1
--- /dev/null
+++ b/backends/PalmOS/Src/missing/string.h
@@ -0,0 +1,22 @@
+#include <PalmOS.h>
+
+#define memcmp MemCmp
+#define memcpy MemMove
+#define memmove MemMove
+#define memset(a,b,c) MemSet(a,c,b)
+#define strcat StrCat
+#define strchr StrChr
+#define strcmp StrCompare
+#define strcpy StrCopy
+#define strncpy StrNCopy
+#define stricmp StrCaselessCompare
+#define strlen StrLen
+#define strncmp StrNCompare
+#define strstr StrStr
+
+Char *strtok(Char *str, const Char *sep);
+Char *strrchr(const Char *s, int c);
+Char *strdup(const Char *strSource);
+Char *strpbrk(const Char *s1, const Char *s2);
+
+#define StrTok strtok \ No newline at end of file
diff --git a/backends/PalmOS/Src/missing/sys/stat.h b/backends/PalmOS/Src/missing/sys/stat.h
new file mode 100644
index 0000000000..a6b5294568
--- /dev/null
+++ b/backends/PalmOS/Src/missing/sys/stat.h
@@ -0,0 +1 @@
+/* nothing */ \ No newline at end of file
diff --git a/backends/PalmOS/Src/missing/time.h b/backends/PalmOS/Src/missing/time.h
new file mode 100644
index 0000000000..df93e2cdd9
--- /dev/null
+++ b/backends/PalmOS/Src/missing/time.h
@@ -0,0 +1,18 @@
+#include <PalmOS.h>
+
+typedef UInt32 time_t;
+
+struct tm {
+ Int16 tm_sec; // seconds [0,61]
+ Int16 tm_min; // minutes [0,59]
+ Int16 tm_hour; // hour [0,23]
+ Int16 tm_mday; // day of month [1,31]
+ Int16 tm_mon; // month of year [0,11]
+ Int16 tm_year; // years since 1900
+ Int16 tm_wday; // day of week [0,6] (Sunday = 0)
+ Int16 tm_yday; // day of year [0,365]
+ Int16 tm_isdst; // daylight savings flag
+};
+
+time_t time(time_t *tloc);
+struct tm *localtime(const time_t *timer);
diff --git a/backends/PalmOS/Src/missing/unistd.h b/backends/PalmOS/Src/missing/unistd.h
new file mode 100644
index 0000000000..b5111cce98
--- /dev/null
+++ b/backends/PalmOS/Src/missing/unistd.h
@@ -0,0 +1,3 @@
+#include <PalmOS.h>
+
+Char *getcwd(Char *buf, UInt32 size);
diff --git a/backends/PalmOS/Src/palm.cpp b/backends/PalmOS/Src/palm.cpp
new file mode 100644
index 0000000000..6770ee0dc3
--- /dev/null
+++ b/backends/PalmOS/Src/palm.cpp
@@ -0,0 +1,1325 @@
+//##############################################################################
+//##############################################################################
+#include "stdafx.h"
+#include "scumm.h"
+#include "mididrv.h"
+#include "gameDetector.h"
+#include "common/scaler.h"
+//##############################################################################
+#include "palm.h"
+#include "starterrsc.h"
+#include "pa1lib.h"
+#include "sonychars.h"
+//extern UInt8 _indicatorColorOn,_indicatorColorOff;
+
+#define SAVEDELAY (5 * 60 * 1000) // five minutes
+//#define EXITDELAY (2 * 1000) // delay to exit : calc button
+#define EXITDELAY (100) // delay to exit : calc button : double tap 1/500 sec
+
+//OSystem_PALMOS *g_palm = NULL;
+//##############################################################################
+//##############################################################################
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+/*void OSystem_PALMOS::autosave()
+{
+ g_scumm->_doAutosave = true;
+}*/
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+OSystem *OSystem_PALMOS::create(UInt16 gfx_mode) {
+
+ OSystem_PALMOS *syst = new OSystem_PALMOS();
+ syst->_mode = gfx_mode;
+ syst->_vibrate = gVars->vibrator;
+// g_palm = syst;
+ return syst;
+}
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+OSystem *OSystem_PALMOS_create(int gfx_mode) {
+ return OSystem_PALMOS::create(gfx_mode);
+}
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::set_palette(const byte *colors, uint start, uint num) {
+ const byte *b = colors;
+ uint i;
+ RGBColorType *base = _currentPalette + start;
+ for(i=0; i < num; i++) {
+ base[i].r = b[0];
+ base[i].g = b[1];
+ base[i].b = b[2];
+ b += 4;
+ }
+
+ if (start < _paletteDirtyStart)
+ _paletteDirtyStart = start;
+
+ if (start + num > _paletteDirtyEnd)
+ _paletteDirtyEnd = start + num;
+}
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::load_gfx_mode() {
+ Err e;
+ const byte startupPalette[] = {
+ 0 ,0 ,0 ,0,
+ 0 ,0 ,171,0,
+ 0 ,171, 0 ,0,
+ 0 ,171,171,0,
+ 171 ,0 ,0 ,0,
+ 171 ,0 ,171,0,
+ 171 ,87 ,0 ,0,
+ 171 ,171,171,0,
+ 87 ,87 ,87 ,0,
+ 87 ,87 ,255,0,
+ 87 ,255,87 ,0,
+ 87 ,255,255,0,
+ 255 ,87 ,87 ,0,
+ 255 ,87 ,255,0,
+ 255 ,255,87 ,0,
+ 255 ,255,255,0
+ };
+
+ // palette for preload dialog
+ set_palette(startupPalette,0,16);
+
+ switch(_mode)
+ {
+ case GFX_FLIPPING:
+ palm_offscreen = WinScreenLock(winLockErase) + _screeny;
+ palm_screen = palm_offscreen;
+ gVars->screenLocked = true;
+ _renderer_proc = &update_screen__flipping;
+ break;
+ case GFX_DOUBLEBUFFER:
+ h_palm_screen = WinGetDisplayWindow();
+ palm_screen = (byte *)(BmpGetBits(WinGetBitmap(h_palm_screen))) + _screeny;
+ h_palm_offscreen= WinCreateOffscreenWindow(SCREEN_WIDTH, SCREEN_HEIGHT, screenFormat, &e);
+ palm_offscreen = (byte *)(BmpGetBits(WinGetBitmap(h_palm_offscreen)));
+ _renderer_proc = &update_screen__dbuffer;
+ break;
+ case GFX_NORMAL:
+ default:
+ h_palm_offscreen= WinGetDisplayWindow();
+ palm_offscreen = (byte *)(BmpGetBits(WinGetBitmap(h_palm_offscreen))) + _screeny;
+ palm_screen = palm_offscreen;
+ _renderer_proc = &update_screen__direct;
+ break;
+ }
+
+ h_palm_tmpscreen= WinCreateOffscreenWindow(SCREEN_WIDTH, SCREEN_HEIGHT, screenFormat, &e);
+ palm_tmpscreen = (byte *)(BmpGetBits(WinGetBitmap(h_palm_tmpscreen)));
+ _overlaySaved = false;
+
+}
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::unload_gfx_mode() {
+ switch (_mode)
+ {
+ case GFX_FLIPPING:
+ WinScreenUnlock();
+ break;
+ case GFX_DOUBLEBUFFER:
+ WinDeleteWindow(h_palm_offscreen,false);
+ break;
+ }
+
+ WinDeleteWindow(h_palm_tmpscreen,false);
+}
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::init_size(uint w, uint h) {
+
+ SCREEN_WIDTH = w;
+ SCREEN_HEIGHT = h;
+
+ _overlay_visible = false;
+ _quit = false;
+
+ _decaly = (320-h)/2;
+ _screeny= _decaly * 320;
+
+ set_mouse_pos(200,150);
+
+ _currentPalette = (RGBColorType*)calloc(sizeof(RGBColorType), 256);
+ _mouse_backup = (byte*)malloc(MAX_MOUSE_W * MAX_MOUSE_H);
+
+ load_gfx_mode();
+}
+
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::copy_rect(const byte *buf, int pitch, int x, int y, int w, int h) {
+
+ byte *dst;
+
+ /* FIXME: undraw mouse only if the draw rect intersects with the mouse rect */
+ if (_mouse_drawn)
+ undraw_mouse();
+
+ dst = palm_offscreen + y * SCREEN_WIDTH + x;
+
+ do {
+ memcpy(dst, buf, w);
+ dst += SCREEN_WIDTH;
+ buf += pitch;
+ } while (--h);
+}
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::update_screen__flipping()
+{
+ RectangleType r;
+ UInt8 *screen;
+ UInt32 size = SCREEN_WIDTH*SCREEN_HEIGHT + 6400; // 10 pix top and bottom border
+ Boolean shaked = false;
+ UInt32 move = 0;
+
+ // shake screen
+ if (_current_shake_pos != _new_shake_pos) {
+ if (gVars->HRrefNum) {
+ RctSetRectangle(&r, 0, _decaly - _new_shake_pos, SCREEN_WIDTH, SCREEN_HEIGHT + (_new_shake_pos << 2));
+ HRWinScrollRectangle(gVars->HRrefNum, &r, winDown, _new_shake_pos, NULL);
+ } else {
+ move = (_new_shake_pos * SCREEN_WIDTH);
+ screen = palm_offscreen - 3200;
+ MemMove(screen + move, screen, size);
+ }
+
+ if (_vibrate) {
+ Boolean active = (_new_shake_pos >= 3);
+ HwrVibrateAttributes(1, kHwrVibrateActive, &active);
+ }
+
+ _current_shake_pos = _new_shake_pos;
+ shaked = true;
+ }
+
+ // update screen
+ WinScreenUnlock();
+ palm_offscreen = WinScreenLock(winLockCopy) + _screeny;
+ palm_screen = palm_offscreen;
+ if (shaked) {
+ if (gVars->HRrefNum) {
+ HRWinScrollRectangle(gVars->HRrefNum, &r, winUp, _new_shake_pos, NULL);
+ } else {
+ screen = palm_offscreen - 3200;
+ MemMove(screen, screen + move, size);
+ }
+ }
+
+}
+
+void OSystem_PALMOS::update_screen__dbuffer()
+{
+ UInt32 move = 0;
+ UInt32 size = SCREEN_WIDTH*SCREEN_HEIGHT;
+
+ // shake screen
+ if (_current_shake_pos != _new_shake_pos) {
+ move = (_new_shake_pos * SCREEN_WIDTH);
+ // copy clear bottom of the screen to top to cover shaking image
+ MemMove(palm_screen, palm_screen + size , move);
+
+ if (_vibrate) {
+ Boolean active = (_new_shake_pos >= 3);
+ HwrVibrateAttributes(1, kHwrVibrateActive, &active);
+ }
+
+ _current_shake_pos = _new_shake_pos;
+ }
+ // update screen
+ MemMove(palm_screen + move, palm_offscreen, size - move);
+}
+
+void OSystem_PALMOS::update_screen__direct()
+{
+ if (_current_shake_pos != _new_shake_pos) {
+ if (_vibrate) {
+ Boolean active = (_new_shake_pos >= 3);
+ HwrVibrateAttributes(1, kHwrVibrateActive, &active);
+ }
+ _current_shake_pos = _new_shake_pos;
+ }
+}
+
+void OSystem_PALMOS::update_screen() {
+ if(_quit)
+ return;
+
+ // Make sure the mouse is drawn, if it should be drawn.
+ draw_mouse();
+
+ // Check whether the palette was changed in the meantime and update the
+ // screen surface accordingly.
+ if (_paletteDirtyEnd != 0) {
+ if (gVars->stdPalette) {
+ WinSetDrawWindow(WinGetDisplayWindow()); // hack by Doug
+ WinPalette(winPaletteSet, _paletteDirtyStart, _paletteDirtyEnd - _paletteDirtyStart,_currentPalette + _paletteDirtyStart);
+ } else {
+ HwrDisplayPalette(winPaletteSet, _paletteDirtyStart, _paletteDirtyEnd - _paletteDirtyStart,_currentPalette + _paletteDirtyStart);
+ }
+
+ _paletteDirtyEnd = 0;
+
+// _msg.color = RGBToColor(255,255,255);
+ gVars->indicator.on = RGBToColor(0,255,0);
+// gVars->indicator.off= 0; //RGBToColor(0,0,0);
+ if (lastKeyModifier)
+ drawKeyState();
+ }
+
+ ((this)->*(_renderer_proc))();
+}
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+bool OSystem_PALMOS::show_mouse(bool visible) {
+ if (_mouse_visible == visible)
+ return visible;
+
+ bool last = _mouse_visible;
+ _mouse_visible = visible;
+
+ if (visible)
+ draw_mouse();
+ else
+ undraw_mouse();
+
+ return last;
+}
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::warp_mouse(int x, int y) {
+}
+
+void OSystem_PALMOS::set_mouse_pos(int x, int y) {
+ if (x != _mouse_cur_state.x || y != _mouse_cur_state.y) {
+ _mouse_cur_state.x = x;
+ _mouse_cur_state.y = y;
+ undraw_mouse();
+ }
+}
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::set_mouse_cursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y) {
+ _mouse_cur_state.w = w;
+ _mouse_cur_state.h = h;
+
+ _mouse_hotspot_x = hotspot_x;
+ _mouse_hotspot_y = hotspot_y;
+
+ _mouse_data = (byte*)buf;
+
+ undraw_mouse();
+}
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::set_shake_pos(int shake_pos) {
+ _new_shake_pos = shake_pos;
+
+ if (shake_pos == 0 && _vibrate)
+ {
+ Boolean active = false;
+ HwrVibrateAttributes(1, kHwrVibrateActive, &active);
+ }
+}
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+uint32 OSystem_PALMOS::get_msecs() {
+ uint32 ticks = TimGetTicks();
+ ticks *= (1000/SysTicksPerSecond());
+ return ticks;
+
+}
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::delay_msecs(uint msecs) {
+ SysTaskDelay((SysTicksPerSecond()*msecs)/1000);
+}
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+void *OSystem_PALMOS::create_thread(ThreadProc *proc, void *param) {
+ _thread.active = true;
+ _thread.proc = proc;
+ _thread.param = param;
+
+ return 0;
+}
+//-- 03-01-20 --////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::set_timer(int timer, int (*callback)(int))
+{
+ if (callback != NULL) {
+ _timer.duration = timer;
+ _timer.next_expiry = get_msecs() + timer;
+ _timer.callback = callback;
+ _timer.active = true;
+ } else {
+ _timer.active = false;
+ }
+}
+
+/* Mutex handling */
+void *OSystem_PALMOS::create_mutex(void)
+{
+ return NULL;
+}
+
+void OSystem_PALMOS::lock_mutex(void *mutex)
+{
+}
+
+void OSystem_PALMOS::unlock_mutex(void *mutex)
+{
+}
+
+void OSystem_PALMOS::delete_mutex(void *mutex)
+{
+}
+////////////////////////////////////////////////////////////////////////////////
+/*
+static UInt32 GetOSFreeMem( UInt32* totalMemoryP, UInt32* dynamicMemoryP )
+{
+ #define memoryBlockSize (1024L)
+ UInt32 heapFree;
+ UInt32 max;
+ Int16 i;
+ Int16 nCards;
+ UInt16 cardNo;
+ UInt16 heapID;
+ UInt32 freeMemory = 0;
+ UInt32 totalMemory = 0;
+ UInt32 dynamicMemory = 0;
+
+ // Iterate through each card to support devices with multiple cards.
+ nCards = MemNumCards();
+ for (cardNo = 0; cardNo < nCards; cardNo++)
+ {
+ // Iterate through the RAM heaps on a card (excludes ROM).
+ for (i=0; i< MemNumRAMHeaps(cardNo); i++)
+ {
+ // Obtain the ID of the heap.
+ heapID = MemHeapID(cardNo, i);
+
+ // If the heap is dynamic, increment the dynamic memory total.
+ if (MemHeapDynamic(heapID))
+ {
+ dynamicMemory += MemHeapSize(heapID);
+ }
+
+ // The heap is nondynamic.
+ else
+ {
+ // Calculate the total memory and free memory of the heap.
+ totalMemory += MemHeapSize(heapID);
+ MemHeapFreeBytes(heapID, &heapFree, &max);
+ freeMemory += heapFree;
+ }
+ }
+ }
+
+ // Reduce the stats to KB. Round the results.
+ freeMemory = freeMemory / memoryBlockSize;
+ totalMemory = totalMemory / memoryBlockSize;
+ dynamicMemory = dynamicMemory / memoryBlockSize;
+
+ if (totalMemoryP) *totalMemoryP = totalMemory;
+ if (dynamicMemoryP) *dynamicMemoryP = dynamicMemory;
+
+ return (freeMemory);
+} // GetOSFreeMem
+
+*/
+void OSystem_PALMOS::SimulateArrowKeys(Event *event, Int8 iHoriz, Int8 iVert, Boolean repeat) {
+ Int16 x = _mouse_cur_state.x;
+ Int16 y = _mouse_cur_state.y;
+
+ if (repeat) {
+ lastKeyRepeat += 100;
+
+ if (lastKeyRepeat > 3200)
+ lastKeyRepeat = 3200;
+ }
+ else
+ lastKeyRepeat = 100;
+
+ x = x + iHoriz * (lastKeyRepeat/100);
+ y = y + iVert * (lastKeyRepeat/100);
+
+ x = (x < 0 ) ? 0 : x;
+ x = (x >= SCREEN_WIDTH ) ? SCREEN_WIDTH-1 : x;
+ y = (y < 0 ) ? 0 : y;
+ y = (y >= SCREEN_HEIGHT ) ? SCREEN_HEIGHT-1 : y;
+
+
+ event->event_code = EVENT_MOUSEMOVE;
+ event->mouse.x = x;
+ event->mouse.y = y;
+}
+
+#define MD_NONE 0
+#define MD_CTRL 1
+#define MD_ALT 2
+
+void OSystem_PALMOS::drawKeyState() {
+ UInt8 i,j;
+ UInt16 bmpID = 3000 + lastKeyModifier - 1;
+
+ MemHandle hTemp;
+ BitmapType *bmTemp;
+ UInt32 *bmData;
+ UInt8 *scr = palm_screen + SCREEN_WIDTH * (SCREEN_HEIGHT + 2) + 2;
+
+ hTemp = DmGetResource(bitmapRsc,bmpID);
+
+ if (hTemp) {
+ bmTemp = (BitmapType *)MemHandleLock(hTemp);
+ bmData = (UInt32 *)BmpGetBits(bmTemp);
+
+ for (i = 0; i < 7; i++) {
+ for (j = 0; j < 32; j++) {
+ if (*bmData & (1 << (31-j)))
+ *scr++ = gVars->indicator.on;
+ else
+ *scr++ = gVars->indicator.off;
+ }
+ scr += SCREEN_WIDTH - 32;
+ bmData++;
+ }
+
+ MemPtrUnlock(bmTemp);
+ DmReleaseResource(hTemp);
+ } else {
+ for (i = 0; i < 7; i++) {
+ for (j = 0; j < 32; j++) {
+ *scr++ = gVars->indicator.off;
+ }
+ scr += SCREEN_WIDTH - 32;
+ }
+ }
+}
+
+bool OSystem_PALMOS::poll_event(Event *event) {
+ EventType ev;
+ Boolean handled;
+// UInt32 button = 0;
+ uint32 current_msecs;
+ UInt32 keyCurrentState = 0;
+ Boolean funcButton = false;
+
+ /* First, handle timers */
+ for(;;) {
+ EvtGetEvent(&ev, 0);
+
+ keyCurrentState = KeyCurrentState();
+ current_msecs = get_msecs();
+
+ //thread handler
+ if (_thread.active)
+ _thread.proc(_thread.param);
+
+ // sound handler
+// if(_sound.active)
+// check_sound();
+
+// if (_msg.state != 0)
+// drawMessage();
+
+ // timer handler
+ if (_timer.active && (current_msecs >= _timer.next_expiry)) {
+ _timer.duration = _timer.callback(_timer.duration);
+ _timer.next_expiry = current_msecs + _timer.duration;
+ }
+
+ if (ev.eType == keyDownEvent) {
+ switch (ev.data.keyDown.chr) {
+ case vchrLaunch:
+ lastKeyPressed = -1;
+ funcButton = true;
+ event->event_code = EVENT_KEYDOWN;
+ event->kbd.keycode = 27;
+ event->kbd.ascii = 27;
+ event->kbd.flags = 0;
+ return true;
+
+ case vchrMenu:
+ lastKeyPressed = -1;
+ funcButton = true;
+ event->event_code = EVENT_KEYDOWN;
+ event->kbd.keycode = 319;
+ event->kbd.ascii = 319;
+ event->kbd.flags = 0;
+ return true;
+
+ case vchrBrightness:
+ case vchrContrast:
+ case vchrFind:
+ WinPalette(winPaletteSet, 0, 256, _currentPalette);
+ break;
+
+ case vchrCalc:
+ if (lastKeyPressed == vchrCalc)
+ if ((get_msecs() - _exit_delay) <= (EXITDELAY))
+ quit();
+
+ _exit_delay = get_msecs();
+ funcButton = true;
+ lastKeyPressed = vchrCalc;
+ return true;
+
+ // mouse emulation
+ case vchrHard1: // left button
+ event->event_code = EVENT_LBUTTONDOWN;
+ event->mouse.x = _mouse_cur_state.x;
+ event->mouse.y = _mouse_cur_state.y;
+ lastKeyPressed = -1;
+ return true;
+
+ case vchrHard2: // move left
+ SimulateArrowKeys(event, -1, 0, (lastKeyPressed == vchrHard2));
+ lastKeyPressed = vchrHard2;
+ return true;
+
+ case vchrPageUp: // move up
+ SimulateArrowKeys(event, 0, -1, (lastKeyPressed == vchrPageUp));
+ lastKeyPressed = vchrPageUp;
+ return true;
+
+ case vchrPageDown: // move down
+ SimulateArrowKeys(event, 0, 1, (lastKeyPressed == vchrPageDown));
+ lastKeyPressed = vchrPageDown;
+ return true;
+
+ case vchrHard3: // move right
+ SimulateArrowKeys(event, 1, 0, (lastKeyPressed == vchrHard3));
+ lastKeyPressed = vchrHard3;
+ return true;
+
+ case vchrHard4: // right button
+ event->event_code = EVENT_RBUTTONDOWN;
+ event->mouse.x = _mouse_cur_state.x;
+ event->mouse.y = _mouse_cur_state.y;
+ lastKeyPressed = -1;
+ return true;
+
+
+ case vchrJogUp:
+ event->event_code = EVENT_WHEELUP;
+ return true;
+
+ case vchrJogDown:
+ event->event_code = EVENT_WHEELDOWN;
+ return true;
+
+ case vchrHardCradle:
+ quit();
+ }
+ }
+ // check for hardkey repeat
+ if (lastKeyPressed != -1 && lastKeyPressed != vchrCalc &&
+ !( (keyCurrentState & keyBitHard2) ||
+ (keyCurrentState & keyBitPageUp) ||
+ (keyCurrentState & keyBitPageDown) ||
+ (keyCurrentState & keyBitHard3)
+ )
+ ) {
+ lastKeyPressed = -1;
+ }
+ // prevent crash when alarm is raised
+ handled = ((ev.eType == keyDownEvent) &&
+ (ev.data.keyDown.modifiers & commandKeyMask) &&
+ ((ev.data.keyDown.chr == vchrAttnStateChanged) ||
+ (ev.data.keyDown.chr == vchrAttnUnsnooze)));
+
+ // graffiti strokes, autooff, etc...
+ if (!funcButton && !handled)
+ if (SysHandleEvent(&ev))
+ continue;
+
+ // others events
+ switch(ev.eType) {
+
+ case keyDownEvent: {
+ lastEvent = keyDownEvent;
+ lastKeyPressed = -1;
+ //if (ev.data.keyDown.modifiers & shiftKeyMask) b |= KBD_SHIFT;
+
+ if (ev.data.keyDown.chr == 262 && (ev.data.keyDown.modifiers & commandKeyMask)) {
+ lastKeyModifier++;
+ lastKeyModifier %= 3;
+ drawKeyState();
+ } else {
+ byte b = 0;
+ if (lastKeyModifier == MD_CTRL) b = KBD_CTRL;
+ if (lastKeyModifier == MD_ALT) b = KBD_ALT;
+
+ event->event_code = EVENT_KEYDOWN;
+ event->kbd.keycode = ev.data.keyDown.chr;
+ event->kbd.ascii = (ev.data.keyDown.chr>='a' && ev.data.keyDown.chr<='z' && (event->kbd.flags & KBD_SHIFT)?ev.data.keyDown.chr &~ 0x20 : ev.data.keyDown.chr);
+ event->kbd.flags = b;
+ lastKeyModifier = MD_NONE;
+ drawKeyState();
+ }
+ return true;
+ }
+
+ case penMoveEvent:
+ if (ev.screenY*2-_decaly > SCREEN_HEIGHT || ev.screenY*2-_decaly < 0)
+ return true;
+
+ if (lastEvent != penMoveEvent && (abs(ev.screenY*2-event->mouse.y) <= 2 || abs(ev.screenX*2-event->mouse.x) <= 2)) // move only if
+ return true;
+
+ lastEvent = penMoveEvent;
+ event->event_code = EVENT_MOUSEMOVE;
+ event->mouse.x = ev.screenX*2;
+ event->mouse.y = ev.screenY*2 - _decaly;
+ return true;
+
+ case penDownEvent:
+ lastEvent = penDownEvent;
+
+ if (ev.screenY*2-_decaly > SCREEN_HEIGHT || ev.screenY*2-_decaly < 0)
+ return true;
+
+ event->event_code = EVENT_LBUTTONDOWN;
+ event->mouse.x = ev.screenX*2;
+ event->mouse.y = ev.screenY*2 - _decaly;
+ set_mouse_pos(event->mouse.x, event->mouse.y);
+ return true;
+
+ case penUpEvent:
+ event->event_code = EVENT_LBUTTONUP;
+
+ if (ev.screenY*2-_decaly > SCREEN_HEIGHT || ev.screenY*2-_decaly < 0)
+ return true;
+
+ event->mouse.x = ev.screenX*2;
+ event->mouse.y = ev.screenY*2 - _decaly;
+ set_mouse_pos(event->mouse.x, event->mouse.y);
+ return true;
+
+ default:
+ return false;
+ }
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+uint32 OSystem_PALMOS::property(int param, Property *value) {
+ switch(param) {
+/*
+ case PROP_TOGGLE_FULLSCREEN:
+ _full_screen ^= true;
+ g_scumm->_fullScreen = _full_screen;
+
+ if (!SDL_WM_ToggleFullScreen(sdl_hwscreen)) {
+ // if ToggleFullScreen fails, achieve the same effect with hotswap gfx mode //
+ hotswap_gfx_mode();
+ }
+ return 1;
+*/
+ case PROP_SET_WINDOW_CAPTION:
+/* RectangleType r;
+
+ RctSetRectangle(&r, 45, 60, 70 ,25);
+ WinEraseRectangle (&r,0);
+ RctSetRectangle(&r, 45 - 2, 60 - 2, 70 + 4 ,25 + 4);
+
+ WinSetForeColor (UIColorGetTableEntryIndex (UIFormFrame));
+ WinDrawRectangleFrame(dialogFrame, &r);
+ FntSetFont(boldFont);
+ WinSetForeColor (UIColorGetTableEntryIndex (UIObjectForeground));
+ WinDrawChars("Loading...", 10, 45 + 11, 60 + 7);
+*/
+ if (StrCaselessCompare(value->caption,"ScummVM") == 0)
+ return 1;
+
+ UInt16 w1 = FntCharsWidth(value->caption,StrLen(value->caption));
+
+ if (gVars->HRrefNum != sysInvalidRefNum) {
+ Char *caption = "Loading...\0";
+ UInt16 h0 = FntLineHeight() + 2;
+ UInt16 w1;
+
+ WinSetTextColor(255);
+ HRFntSetFont(gVars->HRrefNum,hrTinyBoldFont);
+ w1 = FntCharsWidth(caption,StrLen(caption)) * 1;
+ w1 = (320 - w1) / 2;
+ HRWinDrawChars(gVars->HRrefNum,caption,StrLen(caption),w1,80);
+
+ HRFntSetFont(gVars->HRrefNum,hrTinyFont);
+ w1 = FntCharsWidth(value->caption,StrLen(value->caption)) * 1;
+ w1 = (320 - w1) / 2;
+ HRWinDrawChars(gVars->HRrefNum,value->caption,StrLen(value->caption),w1,80 + h0);
+ } else {
+ Char *caption = "Loading...\0";
+ UInt16 w1;
+
+ WinSetTextColor(255);
+ FntSetFont(boldFont);
+ w1 = FntCharsWidth(caption,StrLen(caption));
+ w1 = (160 - w1) / 2;
+ WinDrawChars(caption,StrLen(caption),w1,40);
+// WinSetScalingMode(kTextScalingOff);
+// FntSetFont(stdFont);
+// WinDrawChars(value->caption,StrLen(value->caption),0,0);
+ }
+/*
+ IndexedColorType newColor, oldColor;
+
+ RectangleType r;
+ HRFntSetFont(gVars->HRrefNum,hrTinyFont);
+ UInt16 w0 = FntCharsWidth("Detected game :",StrLen("Detected game :"));
+ UInt16 w1 = FntCharsWidth(value->caption,StrLen(value->caption));
+ UInt16 h0 = FntLineHeight();
+
+ if (w0>w1) w1 = w0;
+ w0 = (w1 + 20) / 2;
+
+ oldColor = WinSetBackColor (256);
+ RctSetRectangle(&r,(160-w0)/2-1, (100)/2-1,w0+2,25+2);
+ WinEraseRectangle (&r,0);
+ newColor = UIColorGetTableEntryIndex (UIFormFrame);
+ oldColor = WinSetForeColor (newColor);
+ RctSetRectangle(&r,(160-w0)/2, (100)/2,w0,25);
+ WinDrawRectangleFrame(dialogFrame, &r);
+
+ HRWinDrawChars(gVars->HRrefNum,"Detected game :",15,(320-w1)/2,105);
+ HRWinDrawChars(gVars->HRrefNum,value->caption,StrLen(value->caption),(320-w1)/2,105+h0);
+
+ HRFntSetFont(gVars->HRrefNum,hrTinyBoldFont);
+ HRWinDrawChars(gVars->HRrefNum,"Initializing...",15,(320-w1)/2,110+h0*2);
+*/
+ return 1;
+
+ case PROP_OPEN_CD:
+ break;
+/* if (SDL_InitSubSystem(SDL_INIT_CDROM) == -1)
+ cdrom = NULL;
+ else {
+ cdrom = SDL_CDOpen(value->cd_num);
+ // Did if open? Check if cdrom is NULL //
+ if (!cdrom) {
+ warning("Couldn't open drive: %s\n", SDL_GetError());
+ }
+ }
+ break;
+
+ case PROP_SET_GFX_MODE:
+ if (value->gfx_mode >= 7)
+ return 0;
+
+ _mode = value->gfx_mode;
+ hotswap_gfx_mode();
+
+ return 1;
+
+ case PROP_SHOW_DEFAULT_CURSOR:
+ SDL_ShowCursor(value->show_cursor ? SDL_ENABLE : SDL_DISABLE);
+ break;
+*/
+ case PROP_GET_SAMPLE_RATE:
+ return SAMPLES_PER_SEC;
+ }
+
+ return 0;
+}
+///////////////////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::quit() {
+ exit(1);
+
+ if (_quit)
+ return;
+ if (g_scumm)
+ g_scumm->_quit = true;
+ if (_currentPalette)
+ free(_currentPalette);
+ if (_mouse_backup)
+ free(_mouse_backup);
+ if (_sndData)
+ MemPtrFree(_sndData);
+
+ unload_gfx_mode();
+
+ _quit = true;
+ _currentPalette = NULL;
+ _mouse_backup = NULL;
+}
+///////////////////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::draw_mouse() {
+ if (_mouse_drawn || !_mouse_visible || _quit)
+ return;
+
+ _mouse_cur_state.y = _mouse_cur_state.y>=SCREEN_HEIGHT ? SCREEN_HEIGHT-1 : _mouse_cur_state.y;
+
+ int x = _mouse_cur_state.x - _mouse_hotspot_x;
+ int y = _mouse_cur_state.y - _mouse_hotspot_y;
+ int w = _mouse_cur_state.w;
+ int h = _mouse_cur_state.h;
+ byte color;
+ byte *src = _mouse_data; // Image representing the mouse
+ byte *bak = _mouse_backup; // Surface used to backup the area obscured by the mouse
+ byte *dst; // Surface we are drawing into
+
+
+ // clip the mouse rect, and addjust the src pointer accordingly
+ if (x < 0) {
+ w += x;
+ src -= x;
+ x = 0;
+ }
+ if (y < 0) {
+ h += y;
+ src -= y * _mouse_cur_state.w;
+ y = 0;
+ }
+ if (w > SCREEN_WIDTH - x)
+ w = SCREEN_WIDTH - x;
+ if (h > SCREEN_HEIGHT - y)
+ h = SCREEN_HEIGHT - y;
+
+ // Store the bounding box so that undraw mouse can restore the area the
+ // mouse currently covers to its original content.
+ _mouse_old_state.x = x;
+ _mouse_old_state.y = y;
+ _mouse_old_state.w = w;
+ _mouse_old_state.h = h;
+
+ // Quick check to see if anything has to be drawn at all
+ if (w <= 0 || h <= 0)
+ return;
+
+ // Draw the mouse cursor; backup the covered area in "bak"
+ dst = palm_offscreen + y * SCREEN_WIDTH + x;
+ while (h > 0) {
+ int width = w;
+ while (width > 0) {
+ *bak++ = *dst;
+ color = *src++;
+ if (color != 0xFF) // 0xFF = transparent, don't draw
+ *dst = color;
+ dst++;
+ width--;
+ }
+ src += _mouse_cur_state.w - w;
+ bak += MAX_MOUSE_W - w;
+ dst += SCREEN_WIDTH - w;
+ h--;
+ }
+
+ // Finally, set the flag to indicate the mouse has been drawn
+ _mouse_drawn = true;
+}
+///////////////////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::undraw_mouse() {
+ if (!_mouse_drawn || _quit)
+ return;
+
+ _mouse_drawn = false;
+
+ byte *dst, *bak = _mouse_backup;
+ const int old_mouse_x = _mouse_old_state.x;
+ const int old_mouse_y = _mouse_old_state.y;
+ const int old_mouse_w = _mouse_old_state.w;
+ const int old_mouse_h = _mouse_old_state.h;
+ int x,y;
+
+ // No need to do clipping here, since draw_mouse() did that already
+
+ dst = palm_offscreen + old_mouse_y * SCREEN_WIDTH + old_mouse_x;
+ for (y = 0; y < old_mouse_h; ++y, bak += MAX_MOUSE_W, dst += SCREEN_WIDTH) {
+ for (x = 0; x < old_mouse_w; ++x) {
+ dst[x] = bak[x];
+ }
+ }
+}
+///////////////////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::stop_cdrom() {
+ return;
+}
+///////////////////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::play_cdrom(int track, int num_loops, int start_frame, int end_frame) {
+ return;
+}
+///////////////////////////////////////////////////////////////////////////////
+bool OSystem_PALMOS::poll_cdrom() {
+ return false;
+}
+///////////////////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::update_cdrom() {
+ return;
+}
+///////////////////////////////////////////////////////////////////////////////
+OSystem_PALMOS::OSystem_PALMOS()
+{
+ // cannot use memset beacuse of virtual ?
+
+ _quit = false;
+ _current_shake_pos = 0;
+ _new_shake_pos = 0;
+
+ memset(&_mouse_old_state,0,sizeof(MousePos));
+ memset(&_mouse_cur_state,0,sizeof(MousePos));
+
+ _msg.state = 0;
+
+ _paletteDirtyStart = 0;
+ _paletteDirtyEnd = 0;
+
+ _timer.active = false;
+ _thread.active = false;
+ _sound.active = false;
+
+ _currentPalette = NULL;
+ _mouse_backup = NULL;
+
+ lastKeyPressed = -1;
+ lastKeyRepeat = 100;
+ lastKeyModifier = MD_NONE;
+
+ _isPlaying = false;
+
+ _sndData = (UInt8 *)MemPtrNew(512);
+}
+///////////////////////////////////////////////////////////////////////////////
+void OSystem_PALMOS::move_screen(int dx, int dy, int height) {
+
+ if ((dx == 0) && (dy == 0))
+ return;
+
+ if (dx == 0) {
+ // vertical movement
+ if (dy > 0) {
+ // move down
+ // copy from bottom to top
+ for (int y = height - 1; y >= dy; y--)
+ copy_rect((byte *)palm_offscreen + SCREEN_WIDTH * (y - dy), SCREEN_WIDTH, 0, y, SCREEN_WIDTH, 1);
+ } else {
+ // move up
+ // copy from top to bottom
+ for (int y = 0; y < height + dx; y++)
+ copy_rect((byte *)palm_offscreen + SCREEN_WIDTH * (y - dy), SCREEN_WIDTH, 0, y, SCREEN_WIDTH, 1);
+ }
+ } else if (dy == 0) {
+ // horizontal movement
+ if (dx > 0) {
+ // move right
+ // copy from right to left
+ for (int x = SCREEN_WIDTH - 1; x >= dx; x--)
+ copy_rect((byte *)palm_offscreen + x - dx, SCREEN_WIDTH, x, 0, 1, height);
+ } else {
+ // move left
+ // copy from left to right
+ for (int x = 0; x < SCREEN_WIDTH; x++)
+ copy_rect((byte *)palm_offscreen + x - dx, SCREEN_WIDTH, x, 0, 1, height);
+ }
+ } else {
+ // free movement
+ // not neccessary for now
+ }
+}
+
+void OSystem_PALMOS::drawMessage() {
+ UInt32 msecs = get_msecs();
+
+ if ((msecs - _msg.time) >= _msg.wait) {
+ Int16 y = _msg.position * _msg.state + (_msg.state == -1 ? 320 : 308);
+ _msg.time = msecs;
+
+ WinSetDrawMode(winPaint);
+ WinSetBackColor(0);
+ WinSetTextColor(_msg.color);
+ HRFntSetFont(gVars->HRrefNum,hrTinyFont);
+ HRWinDrawChars(gVars->HRrefNum, _msg.text, StrLen(_msg.text), 2, y);
+
+ _msg.position += 2;
+ if (_msg.position > 12) {
+ _msg.position = 0;
+ _msg.state *= -1;
+ _msg.wait = 5000;
+ _msg.state = (_msg.state == -1 ? 0 : _msg.state);
+ } else {
+ _msg.wait = 100;
+ }
+ }
+}
+
+void OSystem_PALMOS::deleteMessage() {
+ if (_msg.state != 0) {
+ Int16 y = _msg.position * _msg.state + (_msg.state == -1 ? 320 : 308);
+ WinSetDrawMode(winPaint);
+ WinSetBackColor(0);
+ WinSetTextColor(0);
+ HRFntSetFont(gVars->HRrefNum,hrTinyFont);
+ HRWinDrawChars(gVars->HRrefNum, _msg.text, StrLen(_msg.text), 2, y);
+ }
+}
+
+void OSystem_PALMOS::addMessage(const Char *msg) {
+
+ if (_msg.state != 0)
+ deleteMessage();
+
+ _msg.state = -1;
+ _msg.position = 0;
+ StrCopy(_msg.text,msg);
+ _msg.time = get_msecs();
+ _msg.wait = 100;
+ _msg.color = RGBToColor(255,255,255);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+#define FRAG_SIZE 256
+///////////////////////////////////////////////////////////////////////////////
+/*
+void callback(UInt32 data) {
+
+ Pa1Lib_adpcmStop(g_palm->_sndHandle);
+ Pa1Lib_adpcmClose(g_palm->_sndHandle);
+ g_palm->_isPlaying = false;
+
+}
+*/
+////////////////////////////////////////////////////////////////////////////////
+/*
+
+UInt16 snd;
+
+Err SonySoundLibx(UInt16 *refNumP)
+{
+ SonySysFtrSysInfoP sonySysFtrSysInfoP;
+ Err error = errNone;
+
+ if ((error = FtrGet(sonySysFtrCreator, sonySysFtrNumSysInfoP, (UInt32*)&sonySysFtrSysInfoP))) {
+ // Not CLIE: maybe not available //
+ } else {
+ if (sonySysFtrSysInfoP->libr & sonySysFtrSysInfoLibrFm) {
+ // Sound-Lib available //
+ if ((error = SysLibFind(sonySysLibNameSound, refNumP))) {
+ if (error == sysErrLibNotFound) {
+ // couldn't find lib //
+ error = SysLibLoad( 'libr', sonySysFileCSoundLib, refNumP );
+ }
+ }
+
+ if ( error ) {
+ // Now we can use Sound-Lib //
+ FrmCustomAlert(FrmWarnAlert,"Sound Lib not found.",0,0);
+ }
+ }
+ }
+
+ return error;
+}
+*/
+/*
+typedef struct t_sound {
+ bool active;
+ OSystem::SoundProc *proc;
+ void *param;
+} t_sound;
+
+
+Err sound(void *userData, SndStreamRef stream, void *buffer, UInt32 frameCount) {
+ OSystem_PALMOS *s = (OSystem_PALMOS *)userData;
+
+ s->check_sound();
+ return 0;
+}
+*/
+bool OSystem_PALMOS::set_sound_proc(void *param, SoundProc *proc, byte format) {
+/*
+ _snd_format.formatTag = 0x0020;
+ _snd_format.numOfChan = 1;
+ _snd_format.samplePerSec = 8000;
+ _snd_format.bitPerSample = 4;
+ _snd_format.dataSize = FRAG_SIZE;
+
+ _snd_options.amplitude = 256;
+ _snd_options.dwStartMilliSec = 0;
+ _snd_options.dwEndMilliSec = 500;
+ _snd_options.interruptible = true;
+
+ _sound_proc_param = param;
+ _sound_proc = proc;
+
+ _sound = false;*/
+// Pa1Lib_Open();
+return false;
+
+ _sound.active = true;
+ _sound.proc = proc;
+ _sound.param = param;
+/*
+ SndStreamRef sndPref;
+
+ Err e = SndStreamCreate( &sndPref,
+ sndOutput, 22050,
+ sndInt16Big, sndMono,
+ &sound,
+ this, 512,
+ false);
+
+ SndStreamStart(sndPref);*/
+ return true;
+}
+
+/*
+UInt32 ADPCM_encoder16bit(UInt16 *dataP, UInt8 *saveP, UInt32 dataLength);*/
+void OSystem_PALMOS::check_sound() {
+
+// if (!Pa1Lib_sndEventProc()) {
+//if (!_isPlaying) {
+
+// CallbackInfoType callbackInfo;
+// UInt8 buf[512];
+// UInt8 *copy = _sndData;
+// callbackInfo.funcP = callback;
+// callbackInfo.dwUserData = 0;
+// UInt16 buf[512];
+// UInt16 *a = (UInt16 *)buf;
+
+// MemSet(_sndData,4096,0);
+ _sound.proc(_sound.param, _sndData, 512);
+/* int a = ADPCM_encoder16bit((UInt16 *)buf,_sndData, 512);
+
+// _sound.proc(_sound.param, (UInt8 *)buf, 512);
+
+ MemSet(_sndData,4096,0);
+
+ for (int n=0;n<256;n++) {
+ *copy = (UInt8)((*a++ >> 12) | ((*a++ >> 12) << 4));
+ copy++;
+ //a++;
+ }
+
+
+ if (_isPlaying) {
+ //Pa1Lib_adpcmStop(_sndHandle);
+ //Pa1Lib_adpcmClose(_sndHandle);
+ Pa1Lib_sndAdpcmStop();
+ }
+
+ //Pa1Lib_adpcmOpen(1, _sndData, 256, NULL, &_sndHandle);
+ //Pa1Lib_adpcmStart(_sndHandle,1);
+ Pa1Lib_sndAdpcmStart(1, _sndData, a, NULL);
+ _isPlaying = true;
+ }*/
+/*
+ e = SndPlayPcm(SndRefNum, NULL, cmd, sound_buffer, &_snd_format, &_snd_options, NULL, true);
+
+
+ switch (e) {
+ case errNone:
+ HRWinDrawChars(HRrefNum,"errNone",StrLen("errNone"),0,220);
+ break;
+ case sndErrBadParam:
+ HRWinDrawChars(HRrefNum,"sndErrBadParam",StrLen("sndErrBadParam"),0,220);
+ break;
+ case sndErrFormat:
+ HRWinDrawChars(HRrefNum,"sndErrFormat",StrLen("sndErrFormat"),0,220);
+ break;
+ case sndErrInterrupted:
+ HRWinDrawChars(HRrefNum,"sndErrInterrupted",StrLen("sndErrInterrupted"),0,220);
+ break;
+ default:
+ HRWinDrawChars(HRrefNum,"unknow",StrLen("unknow"),0,220);
+ break;
+ }*/
+}
+
+void OSystem_PALMOS::show_overlay()
+{
+ // hide the mouse
+ undraw_mouse();
+
+ _overlay_visible = true;
+ clear_overlay();
+}
+
+void OSystem_PALMOS::hide_overlay()
+{
+ // hide the mouse
+ undraw_mouse();
+
+ _overlay_visible = false;
+ _overlaySaved = false;
+ memmove(palm_offscreen, palm_tmpscreen, SCREEN_WIDTH*SCREEN_HEIGHT);
+}
+
+void OSystem_PALMOS::clear_overlay()
+{
+ if (!_overlay_visible)
+ return;
+
+ // hide the mouse
+ undraw_mouse();
+ if (!_overlaySaved)
+ { memmove(palm_tmpscreen, palm_offscreen, SCREEN_WIDTH*SCREEN_HEIGHT);
+ _overlaySaved = true;
+ }
+}
+
+void OSystem_PALMOS::grab_overlay(byte *buf, int pitch)
+{
+ if (!_overlay_visible)
+ return;
+
+ // hide the mouse
+ undraw_mouse();
+
+ byte *src = palm_tmpscreen;
+ int h = SCREEN_HEIGHT;
+
+ do {
+ memcpy(buf, src, SCREEN_WIDTH);
+ src += SCREEN_WIDTH;
+ buf += pitch;
+ } while (--h);
+}
+
+void OSystem_PALMOS::copy_rect_overlay(const byte *buf, int pitch, int x, int y, int w, int h)
+{
+ if (!_overlay_visible)
+ return;
+
+ undraw_mouse();
+
+ byte *dst = palm_offscreen + y * SCREEN_WIDTH + x;
+
+ do {
+ memcpy(dst, buf, w);
+ dst += SCREEN_WIDTH;
+ buf += pitch;
+ } while (--h);
+}
+
+
+int16 OSystem_PALMOS::get_height() {
+ return SCREEN_HEIGHT;
+}
+
+int16 OSystem_PALMOS::get_width() {
+ return SCREEN_WIDTH;
+}
+
+byte OSystem_PALMOS::RGBToColor(uint8 r, uint8 g, uint8 b)
+{
+ NewGuiColor color = 255;
+ byte nearest = 255;
+ byte check;
+ byte r2,g2,b2;
+
+ for (int i=0; i<256; i++)
+ {
+ r2 = _currentPalette[i].r;
+ g2 = _currentPalette[i].g;
+ b2 = _currentPalette[i].b;
+
+ check = (ABS(r2 - r) + ABS(g2 - g) + ABS(b2 - b))/3;
+
+ if (check == 0) // perfect match
+ return i;
+ else if (check<nearest) // else save and continue
+ {
+ color = i;
+ nearest = check;
+ }
+ }
+
+ return color;
+}
+
+void OSystem_PALMOS::ColorToRGB(byte color, uint8 &r, uint8 &g, uint8 &b)
+{
+ r = _currentPalette[color].r;
+ g = _currentPalette[color].g;
+ b = _currentPalette[color].b;
+} \ No newline at end of file
diff --git a/backends/PalmOS/Src/palm.h b/backends/PalmOS/Src/palm.h
new file mode 100644
index 0000000000..5733632081
--- /dev/null
+++ b/backends/PalmOS/Src/palm.h
@@ -0,0 +1,263 @@
+#ifndef PALM_H
+#define PALM_H
+
+#include <SonyClie.h>
+#include "SonySndLib.h"
+#include "vibrate.h"
+#include "globals.h"
+#include "system.h"
+/*
+typedef struct {
+
+ UInt16 HRrefNum;
+ UInt16 volRefNum;
+ FileRef logFile;
+
+ Boolean screenLocked;
+ Boolean vibrator;
+
+} GlobalsDataType;
+*/
+//extern UInt16 gHRrefNum;
+//extern Boolean gVibrator;
+//extern Boolean gFlipping;
+//extern Boolean gScreenLocked;
+//extern GlobalsDataType *gVars;
+
+//Err CheckHRmode();
+
+
+Err HwrDisplayPalette(UInt8 operation, Int16 startIndex,
+ UInt16 paletteEntries, RGBColorType *tableP)
+ SYS_TRAP(sysTrapHwrDisplayPalette);
+
+
+//-- 02-12-17 --////////////////////////////////////////////////////////////////
+class OSystem_PALMOS : public OSystem {
+public:
+ // Set colors of the palette
+ void set_palette(const byte *colors, uint start, uint num);
+
+ // Set the size of the video bitmap.
+ // Typically, 320x200
+ void init_size(uint w, uint h);
+
+ // Draw a bitmap to screen.
+ // The screen will not be updated to reflect the new bitmap
+ void copy_rect(const byte *buf, int pitch, int x, int y, int w, int h);
+
+ // Moves the screen content around by the given amount of pixels
+ // but only the top height pixel rows, the rest stays untouched
+ void move_screen(int dx, int dy, int height);
+
+ // Update the dirty areas of the screen
+ void update_screen();
+
+ // Either show or hide the mouse cursor
+ bool show_mouse(bool visible);
+
+ // Set the position of the mouse cursor
+ void set_mouse_pos(int x, int y);
+
+ // Warp the mouse cursor. Where set_mouse_pos() only informs the
+ // backend of the mouse cursor's current position, this function
+ // actually moves the cursor to the specified position.
+ void warp_mouse(int x, int y);
+
+
+ // Set the bitmap that's used when drawing the cursor.
+ void set_mouse_cursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y);
+
+ // Shaking is used in SCUMM. Set current shake position.
+ void set_shake_pos(int shake_pos);
+
+ // Get the number of milliseconds since the program was started.
+ uint32 get_msecs();
+
+ // Delay for a specified amount of milliseconds
+ void delay_msecs(uint msecs);
+
+ // Create a thread
+ void *create_thread(ThreadProc *proc, void *param);
+
+ // Get the next event.
+ // Returns true if an event was retrieved.
+ bool poll_event(Event *event);
+
+ void SimulateArrowKeys(Event *event, Int8 iHoriz, Int8 iVert, Boolean repeat);
+
+ // Set function that generates samples
+ bool set_sound_proc(void *param, SoundProc *proc, byte sound);
+
+ // Poll cdrom status
+ // Returns true if cd audio is playing
+ bool poll_cdrom();
+
+ // Play cdrom audio track
+ void play_cdrom(int track, int num_loops, int start_frame, int end_frame);
+
+ // Stop cdrom audio track
+ void stop_cdrom();
+
+ // Update cdrom audio status
+ void update_cdrom();
+
+ // Add a callback timer
+ void set_timer(int timer, int (*callback)(int));
+
+ // Mutex handling
+ void *create_mutex(void);
+ void lock_mutex(void *mutex);
+ void unlock_mutex(void *mutex);
+ void delete_mutex(void *mutex);
+
+ // Quit
+ void quit();
+ bool _quit;
+
+ // Overlay
+ void show_overlay();
+ void hide_overlay();
+ void clear_overlay();
+ void grab_overlay(byte *buf, int pitch);
+ void copy_rect_overlay(const byte *buf, int pitch, int x, int y, int w, int h);
+
+ int16 get_width();
+ int16 get_height();
+ byte RGBToColor(uint8 r, uint8 g, uint8 b);
+ void ColorToRGB(byte color, uint8 &r, uint8 &g, uint8 &b);
+ // Set a parameter
+ uint32 property(int param, Property *value);
+
+ // Savefile management
+ SaveFileManager *get_savefile_manager();
+
+ static OSystem *create(UInt16 gfx_mode);
+
+ UInt8 _sndHandle;
+ Boolean _isPlaying;
+
+protected:
+ bool _overlay_visible;
+
+private:
+ struct {
+ Int16 state;
+ Int16 position;
+ UInt32 time;
+ UInt32 wait;
+ UInt8 color;
+ Char text[100];
+ } _msg;
+
+ void addMessage(const Char *msg);
+ void drawMessage();
+ void deleteMessage();
+
+ typedef void (OSystem_PALMOS::*RendererProc)(void);
+ RendererProc _renderer_proc;
+
+ UInt8 *_sndData;
+
+ void update_screen__flipping();
+ void update_screen__dbuffer();
+ void update_screen__direct();
+
+ WinHandle h_palm_screen;
+ WinHandle h_palm_offscreen;
+ WinHandle h_palm_tmpscreen;
+
+ byte *palm_screen;
+ byte *palm_offscreen;
+ byte *palm_tmpscreen;
+
+ bool _mouse_visible;
+ bool _mouse_drawn;
+
+ enum {
+ MAX_MOUSE_W = 40,
+ MAX_MOUSE_H = 40
+ };
+
+ int SCREEN_WIDTH, SCREEN_HEIGHT;
+ bool _overlaySaved;
+
+ struct MousePos {
+ int16 x,y,w,h;
+ };
+
+ UInt16 _mode;
+ byte *_mouse_data;
+ byte *_mouse_backup;
+ MousePos _mouse_cur_state;
+ MousePos _mouse_old_state;
+ int16 _mouse_hotspot_x;
+ int16 _mouse_hotspot_y;
+ int _current_shake_pos;
+ int _new_shake_pos;
+
+ UInt16 _decaly, _screeny;
+ Boolean _vibrate;
+ UInt32 _exit_delay;
+
+ struct {
+ uint32 duration, next_expiry;
+ bool active;
+ int (*callback) (int);
+ } _timer;
+
+ struct {
+ bool active;
+ ThreadProc *proc;
+ void *param;
+
+ struct {
+ UInt32 value;
+ UInt32 status;
+ } sleep;
+
+ } _thread;
+
+ struct {
+ bool active;
+ SoundProc *proc;
+ void *param;
+ } _sound;
+
+ // Palette data
+ RGBColorType *_currentPalette;
+ uint _paletteDirtyStart, _paletteDirtyEnd;
+
+ void check_sound();
+
+ void draw_mouse();
+ void undraw_mouse();
+
+ void load_gfx_mode();
+ void unload_gfx_mode();
+/*
+ void hotswap_gfx_mode();
+
+ void get_320x200_image(byte *buf);
+*/ static void autosave();
+
+ // PALM spec
+
+ void drawKeyState();
+
+ Int32 lastKeyPressed;
+ UInt32 lastKeyRepeat;
+ UInt8 lastKeyModifier;
+
+ eventsEnum lastEvent;
+
+ // sound support
+ SndPcmFormatType _snd_format;
+ SndPcmOptionsType _snd_options;
+
+
+ OSystem_PALMOS();
+
+};
+
+#endif \ No newline at end of file
diff --git a/backends/PalmOS/Src/palmsave.cpp b/backends/PalmOS/Src/palmsave.cpp
new file mode 100644
index 0000000000..d90e23223f
--- /dev/null
+++ b/backends/PalmOS/Src/palmsave.cpp
@@ -0,0 +1,160 @@
+#include <ctype.h>
+#include "common/scummsys.h"
+//#include "common/stdafx.h"
+#include "common/engine.h"
+#include "scumm/saveload.h"
+#include "palm.h"
+//#include "gui/newgui.h"
+//#include "gui/message.h"
+
+#define MAX_BLOCK 64000
+
+// SaveFile class
+
+class PalmSaveFile : public SaveFile {
+public:
+ PalmSaveFile(const char *filename, const char *mode);
+ ~PalmSaveFile();
+
+ bool is_open() { return file != NULL; }
+ int fread(void *buf, int size, int cnt);
+ int fwrite(void *buf, int size, int cnt);
+// must be removed
+ int feof() { return ::feof(file); }
+
+private :
+ FILE *file;
+ UInt8 * _readWriteData;
+ UInt32 _readWritePos;
+ bool _needDump;
+};
+
+PalmSaveFile::PalmSaveFile(const char *filename, const char *mode) {
+ _readWriteData = NULL;
+ _readWritePos = 0;
+ _needDump = false;
+
+ file = ::fopen(filename, mode);
+}
+
+PalmSaveFile::~PalmSaveFile() {
+ if (file) {
+ if (_needDump && _readWriteData) {
+ ::fwrite(_readWriteData, _readWritePos, 1, file);
+ free(_readWriteData);
+ }
+
+ ::fclose(file);
+ }
+}
+
+int PalmSaveFile::fread(void *buf, int size, int cnt) {
+ return ::fread(buf, size, cnt, file);
+}
+
+int PalmSaveFile::fwrite(void *buf, int size, int cnt) {
+ UInt32 fullsize = size*cnt;
+
+ if (fullsize<=MAX_BLOCK)
+ {
+ if (!_readWriteData)
+ _readWriteData = (byte *)malloc(MAX_BLOCK);
+
+ if ((_readWritePos+fullsize)>MAX_BLOCK) {
+ ::fwrite(_readWriteData, _readWritePos, 1, file);
+ _readWritePos = 0;
+ _needDump = false;
+ }
+
+ MemMove(_readWriteData + _readWritePos, buf, fullsize);
+ _readWritePos += fullsize;
+ _needDump = true;
+
+ return cnt;
+ }
+
+ return ::fwrite(buf, size, cnt, file);
+}
+
+// SaveFileManager class
+
+class PalmSaveFileManager : public SaveFileManager {
+
+public:
+/* SaveFile *open_savefile(const char *filename,
+ bool saveOrLoad)
+ {
+ PalmSaveFile *sf = new PalmSaveFile(filename,
+ (saveOrLoad? "wb":"rb"));
+ if(!sf->is_open()) {
+ delete sf;
+ sf = NULL;
+ }
+ return sf;
+ }
+
+ void list_savefiles(const char *prefix,
+ bool *marks, int num)
+ {
+ memset(marks, true, num*sizeof(bool));
+ }
+*/
+ SaveFile *open_savefile(const char *filename, bool saveOrLoad);
+ void list_savefiles(const char *prefix, bool *marks, int num);
+};
+
+SaveFile *PalmSaveFileManager::open_savefile(const char *filename, bool saveOrLoad) {
+ PalmSaveFile *sf = new PalmSaveFile(filename, (saveOrLoad? "wb":"rb"));
+
+ if(!sf->is_open()) {
+ delete sf;
+ sf = NULL;
+ }
+
+ return sf;
+}
+
+void PalmSaveFileManager::list_savefiles(const char *prefix, bool *marks, int num) {
+ FileRef fileRef;
+ // try to open the dir
+ Err e = VFSFileOpen(gVars->volRefNum, SCUMMVM_SAVEPATH, vfsModeRead, &fileRef);
+ memset(marks, false, num*sizeof(bool));
+
+ if (e != errNone)
+ return;
+
+ // enumerate all files
+ Char *nameonly = strrchr(prefix,'/') + 1;
+ UInt32 dirEntryIterator = vfsIteratorStart;
+ Char filename[32];
+ FileInfoType info = {0, filename, 32};
+ UInt16 length = StrLen(nameonly);
+ int slot = 0;
+
+ while (dirEntryIterator != vfsIteratorStop) {
+ e = VFSDirEntryEnumerate (fileRef, &dirEntryIterator, &info);
+
+ if (e != expErrEnumerationEmpty) { // there is something
+
+ if (StrLen(info.nameP) == (length + 2)) { // consider max 99, filename length is ok
+ if (StrNCaselessCompare(nameonly, info.nameP, length) == 0) { // this seems to be a save file
+ if (isdigit(info.nameP[length]) && isdigit(info.nameP[length+1])) {
+
+ slot = StrAToI(filename + length);
+ if (slot >= 0 && slot < num)
+ *(marks+slot) = true;
+
+ }
+ }
+ }
+
+ }
+ }
+
+ VFSFileClose(fileRef);
+}
+
+// OSystem
+SaveFileManager *OSystem_PALMOS::get_savefile_manager() {
+ return new PalmSaveFileManager();
+}
diff --git a/backends/PalmOS/Src/palmstart.cpp b/backends/PalmOS/Src/palmstart.cpp
new file mode 100644
index 0000000000..31c559b80d
--- /dev/null
+++ b/backends/PalmOS/Src/palmstart.cpp
@@ -0,0 +1,3180 @@
+/******************************************************************************
+ *
+ * File: palmstart.cpp
+ *
+ *****************************************************************************/
+
+#include <PalmOS.h>
+#include <SonyClie.h>
+#include "StarterRsc.h"
+#include "extras.h"
+#include "skin.h"
+#include "globals.h"
+#include "pa1lib.h"
+#include "scumm_globals.h"
+#include "extend.h" // for disable state
+
+void MemExtInit();
+void MemExtCleanup();
+/***********************************************************************
+ *
+ * Entry Points
+ *
+ ***********************************************************************/
+//UInt8 *screen_1;
+//UInt8 *screen_2;
+//extern FileRef gLogFile;
+//extern UInt16 gHRrefNum;
+//extern UInt16 gVolRefNum;
+//extern Boolean gScreenLocked;
+//extern Boolean gFlipping;
+//extern Boolean gVibrator;
+/***********************************************************************
+ *
+ * Internal Structures
+ *
+ ***********************************************************************/
+typedef struct {
+ Char nameP[32];
+ UInt16 cardNo;
+ LocalID dbID;
+} SkinInfoType;
+
+typedef struct {
+ UInt32 version;
+ UInt16 icnID; // icon to display on the list
+ Boolean selected;
+
+ Char nameP[50]; // game name to display in list
+ Char pathP[150]; // path to the game files
+ Char gameP[10]; // scumm name of the game
+ UInt16 gfxMode;
+
+ Boolean autoLoad;
+ UInt16 loadSlot;
+ Boolean autoRoom;
+ UInt16 roomNum;
+ Boolean amiga;
+ Boolean subtitles;
+ Boolean talkSpeed;
+ UInt16 talkValue;
+
+} GameInfoType;
+
+typedef struct {
+
+ //skin params
+ SkinInfoType skin; // card where is located the skin
+ //
+ Boolean vibrator;
+ Boolean autoOff;
+
+ UInt16 listPosition;
+ UInt16 volRefNum;
+
+ Boolean debug;
+ UInt16 debugLevel;
+
+ Boolean stdPalette;
+
+ struct {
+ UInt16 speaker;
+ UInt16 headphone;
+
+ UInt16 master;
+ UInt16 music;
+ UInt16 sfx;
+ } volume;
+
+ struct {
+ Boolean music;
+ UInt8 driver;
+ UInt32 tempo;
+ Boolean sfx;
+ } sound;
+
+
+} GlobalsPreferenceType;
+
+typedef struct {
+ UInt16 volRefNum;
+ Char nameP[expCardInfoStringMaxLen+1];
+
+} CardInfoType;
+
+/***********************************************************************
+ *
+ * Global variables
+ *
+ ***********************************************************************/
+static GlobalsPreferenceType *gPrefs;
+//static SkinInfoType _skin;
+static DmOpenRef _dbP = NULL;
+static UInt16 _lstIndex = 0; // last index
+static UInt8 __editMode__;
+static UInt16 sknLastOn = skinButtonNone;
+
+GlobalsDataType *gVars;
+/***********************************************************************
+ *
+ * Internal Constants
+ *
+ ***********************************************************************/
+#define appFileCreator 'ScVM' // register your own at http://www.palmos.com/dev/creatorid/
+#define appVersionNum 0x01
+#define appPrefID 0x00
+#define appPrefVersionNum 0x01
+
+// Define the minimum OS version we support (3.5 for now).
+#define kOurMinVersion sysMakeROMVersion(3,5,0,sysROMStageRelease,0)
+#define kPalmOS10Version sysMakeROMVersion(1,0,0,sysROMStageRelease,0)
+#define kOS5Version sysMakeROMVersion(5,0,0,sysROMStageRelease,0)
+
+// edit game mode
+#define edtModeAdd 0
+#define edtModeEdit 1
+#define edtModeParams 2
+
+// skin
+#define sknInfoState 0
+#define sknInfoPosX 1
+#define sknInfoPosY 2
+
+#define sknInfoMaxWOrH 3
+#define sknInfoDrawMode 4
+#define sknInfoKeepXOrY1 5
+#define sknInfoKeepXOrY2 7
+
+#define sknInfoListWidth sknInfoMaxWOrH
+#define sknInfoListHeight sknInfoDrawMode
+#define sknInfoListSize sknInfoListHeight
+#define sknInfoListItemSize 12
+
+#define sknPosRsc 'sPos'
+#define sknColorsRsc 'sCol'
+
+#define sknStateNormal 0
+#define sknStateSelected 10
+#define sknStateDisabled 20
+
+#define sknSelectedState(bmp) (bmp + sknStateSelected)
+#define sknDisabledState(bmp) (bmp + sknStateDisabled)
+
+/***********************************************************************
+ *
+ * Internal Functions
+ *
+ ***********************************************************************/
+static void GBInitAll() {
+#ifndef DISABLE_SCUMM
+ IMuseDigital_initGlobals();
+ NewGui_initGlobals();
+ //Resource_initGlobals();
+ Codec47_initGlobals();
+ Gfx_initGlobals();
+#endif
+#ifndef DISABLE_SIMON
+ Simon_initGlobals();
+#endif
+}
+
+static void GBReleaseAll() {
+#ifndef DISABLE_SCUMM
+ IMuseDigital_releaseGlobals();
+ NewGui_releaseGlobals();
+ //Resource_releaseGlobals();
+ Codec47_releaseGlobals();
+ Gfx_releaseGlobals();
+#endif
+#ifndef DISABLE_SIMON
+ Simon_releaseGlobals();
+#endif
+}
+
+//TODO : use Boolean instead of void to check err
+static DmOpenRef GBOpenInternal(const Char *nameP) {
+ LocalID dbID = DmFindDatabase(0, nameP);
+ if (dbID) {
+ UInt32 dbType, dbCreator;
+ Err e = DmDatabaseInfo(0, dbID, 0, 0, 0, 0, 0, 0, 0, 0, 0, &dbType, &dbCreator);
+
+ if (!e && dbType == 'GLBS' && dbCreator == appFileCreator)
+ return DmOpenDatabase(0, dbID, dmModeReadOnly);
+ }
+ return NULL;
+}
+
+static void GBOpen() {
+ gVars->globals[GBVARS_SCUMM] = GBOpenInternal("Scumm-Globals");
+ gVars->globals[GBVARS_SIMON] = GBOpenInternal("Simon-Globals");
+ gVars->globals[GBVARS_SKY] = GBOpenInternal("Sky-Globals");
+}
+
+static void GBClose() {
+ if (gVars->globals[GBVARS_SCUMM])
+ DmCloseDatabase(gVars->globals[GBVARS_SCUMM]);
+ if (gVars->globals[GBVARS_SIMON])
+ DmCloseDatabase(gVars->globals[GBVARS_SIMON]);
+ if (gVars->globals[GBVARS_SKY])
+ DmCloseDatabase(gVars->globals[GBVARS_SKY]);
+}
+
+void *GBGetRecord(UInt16 index, UInt16 id) {
+ if (gVars->globals[id]) {
+ MemHandle recordH = DmQueryRecord(gVars->globals[id], index);
+ if (recordH)
+ return MemHandleLock(recordH);
+ }
+ return NULL;
+}
+
+void GBReleaseRecord(UInt16 index, UInt16 id) {
+ if (gVars->globals[id]) {
+ MemHandle recordH = DmQueryRecord(gVars->globals[id], index);
+ if (recordH)
+ MemHandleUnlock(recordH);
+ }
+}
+ /////////////////////////////////////////////////////////////////////////
+static DmOpenRef SknOpenSkin() {
+ return DmOpenDatabase(gPrefs->skin.cardNo, gPrefs->skin.dbID, dmModeReadOnly);
+}
+
+static void SknCloseSkin(DmOpenRef skinDBP) {
+ if (skinDBP)
+ DmCloseDatabase(skinDBP);
+}
+/*
+static void SknSetPalette() {
+ UInt16 palIndex;
+ ColorTableType *palTemp;
+ MemHandle palH;
+
+ DmOpenRef skinDBP = SknOpenSkin();
+
+ if (skinDBP) {
+ palIndex = DmFindResource (skinDBP, colorTableRsc, skinPalette, NULL);
+
+ if (palIndex != (UInt16)-1) {
+ palH = DmGetResourceIndex(skinDBP, palIndex);
+
+ if (palH) {
+ palTemp = (ColorTableType *)MemHandleLock(palH);
+ WinPalette(winPaletteSet, 0, 256, ColorTableEntries(palTemp));
+ MemPtrUnlock(palTemp);
+ DmReleaseResource(palH);
+ }
+ }
+ }
+
+ SknCloseSkin(skinDBP);
+}
+*/
+static void SknGetListColors(DmOpenRef skinDBP, DmResID resID, UInt8 *text, UInt8 *selected, UInt8 *background) {
+ UInt16 colIndex;
+ MemHandle colH;
+ UInt8 *colTemp;
+
+ // default
+ *text = UIColorGetTableEntryIndex (UIMenuForeground);
+ *selected = UIColorGetTableEntryIndex (UIMenuSelectedForeground);
+ *background = UIColorGetTableEntryIndex (UIMenuSelectedFill);
+
+ if (skinDBP) {
+ colIndex = DmFindResource (skinDBP, sknColorsRsc, resID, NULL);
+
+ if (colIndex != (UInt16)-1) {
+ colH = DmGetResourceIndex(skinDBP, colIndex);
+
+ if (colH) {
+ colTemp = (UInt8 *)MemHandleLock(colH);
+
+ *text = colTemp[0];
+ *selected = colTemp[1];
+ *background = colTemp[2];
+
+ MemPtrUnlock(colTemp);
+ DmReleaseResource(colH);
+ }
+ }
+ }
+}
+
+static void SknGetObjectBounds(DmOpenRef skinDBP, DmResID resID, RectangleType *rP) {
+
+ UInt16 bmpIndex, strIndex;
+ MemHandle hBmp, hStr;
+ BitmapType *bmpTemp;
+ UInt8 *strTemp;
+
+ RctSetRectangle(rP, 0, 0, 0, 0);
+
+ if (skinDBP) {
+ bmpIndex = DmFindResource (skinDBP, bitmapRsc, resID, NULL);
+
+ if (bmpIndex != (UInt16)-1) { // if bmp exists
+ strIndex = DmFindResource (skinDBP, sknPosRsc, resID, NULL);
+
+ if (strIndex != (UInt16)-1) { // if params exist
+ hBmp = DmGetResourceIndex(skinDBP,bmpIndex);
+
+ if (hBmp) {
+ hStr = DmGetResourceIndex(skinDBP,strIndex);
+
+ if (hStr) {
+ // buttons : state|x|y|w/h slider|draw mode|x1/y1 keep|x2/y2 keep slider
+ // list (160mode) : state|x|y|w|h|
+ bmpTemp = (BitmapType *)MemHandleLock(hBmp);
+ strTemp = (UInt8 *)MemHandleLock(hStr);
+
+ BmpGlueGetDimensions(bmpTemp, &(rP->extent.x), &(rP->extent.y), 0);
+ rP->topLeft.x = strTemp[sknInfoPosX] * 2;
+ rP->topLeft.y = strTemp[sknInfoPosY] * 2;
+
+ MemPtrUnlock(strTemp);
+ DmReleaseResource(hStr);
+ }
+
+ MemPtrUnlock(bmpTemp);
+ DmReleaseResource(hBmp);
+ }
+ }
+ }
+ }
+}
+
+static UInt8 SknGetState(DmOpenRef skinDBP, DmResID resID) {
+
+ UInt16 index;
+ MemHandle hStr;
+ UInt8 *strTemp;
+ UInt8 oldState = sknStateDisabled;
+
+ if (skinDBP) {
+ index = DmFindResource (skinDBP, sknPosRsc, resID, NULL);
+
+ if (index != (UInt16)-1) {
+ hStr = DmGetResourceIndex(skinDBP, index);
+
+ if (hStr) {
+ strTemp = (UInt8 *)MemHandleLock(hStr);
+ oldState = strTemp[sknInfoState];
+ MemPtrUnlock(strTemp);
+ DmReleaseResource(hStr);
+ }
+ }
+ }
+
+ return oldState;
+}
+
+static UInt8 SknSetState(DmOpenRef skinDBP, DmResID resID, UInt8 newState) {
+
+ UInt16 index;
+ MemHandle hStr;
+ UInt8 *strTemp;
+ UInt8 oldState = 0;
+
+ if (skinDBP) {
+ index = DmFindResource (skinDBP, sknPosRsc, resID, NULL);
+
+ if (index != (UInt16)-1) {
+ hStr = DmGetResourceIndex(skinDBP, index);
+
+ if (hStr) {
+ strTemp = (UInt8 *)MemHandleLock(hStr);
+ oldState = strTemp[sknInfoState];
+
+ if (oldState != newState) {
+ DmWrite(strTemp, 0, &newState, 1);
+ }
+
+ MemPtrUnlock(strTemp);
+ DmReleaseResource(hStr);
+ }
+ }
+ }
+
+ return oldState;
+}
+
+static void SknCopyBits(DmOpenRef skinDBP, DmResID bitmapID, const RectangleType *srcRect, Coord destX, Coord destY, Boolean standard) {
+ MemHandle hTemp;
+ BitmapPtr bmpTemp;
+ UInt16 index;
+ UInt8 *bmpData;
+// Err e;
+
+ Coord cx, cy, cw, ch, bw, bh;
+ UInt8 *dst, *src;
+
+ if (skinDBP) {
+ // find the bitmap
+ index = DmFindResource (skinDBP, bitmapRsc, bitmapID, NULL);
+
+ if (index != (UInt16)-1) {
+ hTemp = DmGetResourceIndex(skinDBP,index);
+
+ if (hTemp) {
+ bmpTemp = (BitmapType *)MemHandleLock(hTemp);
+ BmpGlueGetDimensions(bmpTemp, &bw, &bh, 0);
+
+ if (!srcRect)
+ {
+ cx = 0;
+ cy = 0;
+ cw = bw;
+ ch = bh;
+ }
+ else
+ {
+ cx = srcRect->topLeft.x;
+ cy = srcRect->topLeft.y;
+ cw = srcRect->extent.x;
+ ch = srcRect->extent.y;
+ }
+
+ if (ch) {
+ dst = (UInt8 *)BmpGetBits(WinGetBitmap(WinGetDisplayWindow()));
+ dst+= destX + destY * 320;
+ bmpData = (UInt8 *)BmpGetBits(bmpTemp);
+ src = bmpData + cx + cy * bw;
+
+ do {
+ MemMove(dst, src, cw);
+ dst += 320;
+ src += bw;
+ } while (--ch);
+ }
+
+ MemPtrUnlock(bmpTemp);
+ DmReleaseResource(hTemp);
+ }
+ }
+ }
+}
+
+static void SknShowObject(DmOpenRef skinDBP, DmResID resID) {
+
+ RectangleType r;
+ UInt8 state = SknGetState(skinDBP, resID);
+ SknGetObjectBounds(skinDBP, resID, &r);
+ SknCopyBits(skinDBP, resID + state, NULL, r.topLeft.x, r.topLeft.y, 0);
+}
+
+static UInt16 SknCheckClick(DmOpenRef skinDBP, Coord mx, Coord my)
+{
+ UInt16 resID;
+ RectangleType r;
+
+ mx *= 2;
+ my *= 2;
+
+ if (skinDBP) {
+ for (resID = 1100; resID <= 7000; resID += 100) {
+ if (SknGetState(skinDBP, resID) != sknStateDisabled) {
+ SknGetObjectBounds(skinDBP, resID, &r);
+ if (RctPtInRectangle(mx, my, &r)) {
+ return resID;
+ }
+ }
+ }
+
+ }
+
+ return 0;
+}
+
+
+// Callback for ExgDBWrite to send data with Exchange Manager
+static Err WriteDBData(const void* dataP, UInt32* sizeP, void* userDataP)
+{
+ Err err;
+ *sizeP = ExgSend((ExgSocketPtr)userDataP, (void*)dataP, *sizeP, &err);
+ return err;
+}
+
+static Err SendDatabase (UInt16 cardNo, LocalID dbID, Char *nameP, Char *descriptionP)
+{
+ ExgSocketType exgSocket;
+ Err err;
+
+ // Create exgSocket structure
+ MemSet(&exgSocket, sizeof(exgSocket), 0);
+ exgSocket.description = descriptionP;
+ exgSocket.name = nameP;
+
+ // Start an exchange put operation
+ err = ExgPut(&exgSocket);
+ if (!err) {
+ err = ExgDBWrite(WriteDBData, &exgSocket, NULL, dbID, cardNo);
+ err = ExgDisconnect(&exgSocket, err);
+ }
+
+ return err;
+}
+
+static Err BeamMe() {
+
+ UInt16 cardNo;
+ LocalID dbID;
+ Err err;
+
+ err = SysCurAppDatabase(&cardNo, &dbID);
+ if (dbID)
+ err = SendDatabase(0, dbID, "ScummVM.prc", "\nPlay your favorite LucasArts games");
+ else
+ err = DmGetLastErr();
+
+ return err;
+}
+/***********************************************************************
+ *
+ * FUNCTION: RomVersionCompatible
+ *
+ * DESCRIPTION: This routine checks that a ROM version is meet your
+ * minimum requirement.
+ *
+ * PARAMETERS: requiredVersion - minimum rom version required
+ * (see sysFtrNumROMVersion in SystemMgr.h
+ * for format)
+ * launchFlags - flags that indicate if the application
+ * UI is initialized.
+ *
+ * RETURNED: error code or zero if rom is compatible
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+static Err RomVersionCompatible(UInt32 requiredVersion, UInt16 launchFlags)
+{
+ UInt32 romVersion;
+
+ // See if we're on in minimum required version of the ROM or later.
+ FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
+ if (romVersion < requiredVersion)
+ {
+ if ((launchFlags & (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) ==
+ (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp))
+ {
+ FrmAlert (RomIncompatibleAlert);
+
+ // Palm OS 1.0 will continuously relaunch this app unless we switch to
+ // another safe one.
+ if (romVersion <= kPalmOS10Version)
+ {
+ AppLaunchWithCommand(sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL);
+ }
+ }
+ return sysErrRomIncompatible;
+ }
+
+ return errNone;
+}
+
+
+/***********************************************************************
+ *
+ * FUNCTION: GetObjectPtr
+ *
+ * DESCRIPTION: This routine returns a pointer to an object in the current
+ * form.
+ *
+ * PARAMETERS: formId - id of the form to display
+ *
+ * RETURNED: void *
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+static void * GetObjectPtr(UInt16 objectID)
+{
+ FormPtr frmP;
+
+ frmP = FrmGetActiveForm();
+ return FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, objectID));
+}
+
+static void FrmList(EventPtr eventP, UInt16 objectID)
+{
+ ListType *listP;
+ UInt16 listItem;
+
+ listP = (ListType *)GetObjectPtr(objectID);
+ listItem = LstPopupList(listP);
+ CtlSetLabel(eventP->data.ctlSelect.pControl, LstGetSelectionText(listP, LstGetSelection(listP)));
+}
+
+//#############################################################################
+//#############################################################################
+
+enum {
+ IcnNone = 255,
+ IcnInfo = 0,
+ IcnEdit = 1,
+ IcnDelt = 2,
+ IcnVibr = 3,
+ IcnAOff = 4,
+ IcnPlay = 5
+};
+
+enum {
+ ArwNone = 255,
+ ArwUp = 0,
+ ArwFUp = 1,
+ ArwFDwn = 2,
+ ArwDown = 3
+};
+/*
+//REMOVE
+static struct {
+ Boolean disabled;
+ Boolean selected;
+} iconState[6] = {0,0 ,0,0 ,0,0 ,1,0 ,0,0 ,0,0};
+//REMOVE
+static struct {
+ UInt16 position;
+ UInt8 last;
+ Boolean disabled[4];
+} ArrowManager = {0, ArwNone, 0,0,0,0};
+*/
+
+//#############################################################################
+//#############################################################################
+
+static Err GamOpenDatabase() {
+ Err err = errNone;
+
+ _dbP = DmOpenDatabaseByTypeCreator( 'DATA', appFileCreator, dmModeReadWrite);
+
+ if (!_dbP) {
+ err = DmCreateDatabase(0, "ScummVM-Data", appFileCreator, 'DATA', false);
+ if (!err) {
+ _dbP = DmOpenDatabaseByTypeCreator( 'DATA', appFileCreator, dmModeReadWrite);
+
+ if (!_dbP)
+ err = DmGetLastErr();
+ }
+ }
+
+ if (err)
+ FrmCustomAlert(FrmErrorAlert,"Cannot open/create games list DB !",0,0);
+ return err;
+}
+
+static void GamCloseDatabase() {
+ if (_dbP)
+ DmCloseDatabase(_dbP);
+ _dbP = NULL;
+}
+
+static Int16 GamCompare(GameInfoType *a, GameInfoType *b, SortRecordInfoPtr, SortRecordInfoPtr, MemHandle) {
+ return StrCompare(a->nameP, b->nameP);
+}
+static Err GamSortList() {
+ return DmQuickSort (_dbP, (DmComparF *)GamCompare, 0);
+}
+
+
+static UInt16 GamGetSelected()
+{
+ MemHandle record;
+ GameInfoType *game;
+ Boolean selected;
+ UInt16 index = DmNumRecords(_dbP)-1;
+
+ while (index != (UInt16)-1) {
+ record = DmQueryRecord(_dbP, index);
+ game = (GameInfoType *)MemHandleLock(record);
+ selected = game->selected;
+ MemHandleUnlock(record);
+
+ if (selected)
+ return index;
+
+ index--;
+ }
+
+ return dmMaxRecordIndex;
+}
+static void GamUnselect() {
+ GameInfoType modGame;
+ GameInfoType *game;
+
+ MemHandle recordH;
+ UInt16 index;
+
+ index = GamGetSelected();
+
+ if (index != dmMaxRecordIndex) {
+ recordH = DmGetRecord(_dbP, index);
+ game = (GameInfoType *)MemHandleLock(recordH);
+
+ MemMove(&modGame, game, sizeof(GameInfoType));
+ modGame.selected = !modGame.selected;
+ DmWrite(game, 0, &modGame, sizeof(GameInfoType));
+
+ MemHandleUnlock(recordH);
+ DmReleaseRecord (_dbP, index, 0);
+ }
+}
+
+static void IcnRedrawTools(DmOpenRef skinDBP)
+{
+ if (GamGetSelected() == dmMaxRecordIndex) {
+ if (SknGetState(skinDBP, skinButtonGameDelete) == sknStateNormal) {
+ SknSetState(skinDBP, skinButtonGameDelete,sknStateDisabled);
+ SknShowObject(skinDBP, skinButtonGameDelete);
+ }
+// if (SknGetState(skinDBP, skinButtonGameStart) == sknStateNormal) {
+// SknSetState(skinDBP, skinButtonGameStart,sknStateDisabled);
+// SknShowObject(skinDBP, skinButtonGameStart);
+// }
+ if (SknGetState(skinDBP, skinButtonGameEdit) == sknStateNormal) {
+ SknSetState(skinDBP, skinButtonGameEdit,sknStateDisabled);
+ SknShowObject(skinDBP, skinButtonGameEdit);
+ }
+
+ } else {
+ if (SknGetState(skinDBP, skinButtonGameDelete) == sknStateDisabled) {
+ SknSetState(skinDBP, skinButtonGameDelete,sknStateNormal);
+ SknShowObject(skinDBP, skinButtonGameDelete);
+ }
+// if (SknGetState(skinDBP, skinButtonGameStart) == sknStateDisabled) {
+// SknSetState(skinDBP, skinButtonGameStart,sknStateNormal);
+// SknShowObject(skinDBP, skinButtonGameStart);
+// }
+ if (SknGetState(skinDBP, skinButtonGameEdit) == sknStateDisabled) {
+ SknSetState(skinDBP, skinButtonGameEdit,sknStateNormal);
+ SknShowObject(skinDBP, skinButtonGameEdit);
+ }
+ }
+}
+
+static void ArwRedrawSlider(DmOpenRef skinDBP, UInt16 index, UInt16 maxIndex, UInt16 perPage)
+{
+ if (maxIndex <= perPage) {
+ if (SknGetState(skinDBP,skinSliderUpArrow) != sknStateDisabled) {
+ SknSetState(skinDBP,skinSliderUpArrow,sknStateDisabled);
+ SknShowObject(skinDBP,skinSliderUpArrow);
+ }
+ if (SknGetState(skinDBP,skinSliderDownArrow) != sknStateDisabled) {
+ SknSetState(skinDBP,skinSliderDownArrow,sknStateDisabled);
+ SknShowObject(skinDBP,skinSliderDownArrow);
+ }
+
+ } else {
+ if (SknGetState(skinDBP,skinSliderUpArrow) == sknStateDisabled) {
+ SknSetState(skinDBP,skinSliderUpArrow,sknStateNormal);
+ SknShowObject(skinDBP,skinSliderUpArrow);
+ }
+ if (SknGetState(skinDBP,skinSliderDownArrow) == sknStateDisabled) {
+ SknSetState(skinDBP,skinSliderDownArrow,sknStateNormal);
+ SknShowObject(skinDBP,skinSliderDownArrow);
+ }
+ }
+}
+
+static void GamGetListBounds(RectangleType *rAreaP, RectangleType *rArea2xP) {
+ DmOpenRef skinDBP;
+ UInt16 strIndex;
+ MemHandle hStr;
+ UInt8 *strTemp;
+ UInt16 x,y,w,h;
+
+ skinDBP = DmOpenDatabase(gPrefs->skin.cardNo, gPrefs->skin.dbID, dmModeReadOnly);
+ if (skinDBP) {
+ strIndex = DmFindResource (skinDBP, sknPosRsc, skinList, NULL);
+
+ if (strIndex != (UInt16)-1) { // if params exist
+ hStr = DmGetResourceIndex(skinDBP,strIndex);
+ if (hStr) {
+ strTemp = (UInt8 *)MemHandleLock(hStr);
+
+ x = strTemp[sknInfoPosX];
+ y = strTemp[sknInfoPosY];
+ w = strTemp[sknInfoListWidth];
+ h = strTemp[sknInfoListSize] * sknInfoListItemSize;
+
+ if (rAreaP)
+ RctSetRectangle(rAreaP ,x, y, w, h);
+ if (rArea2xP)
+ RctSetRectangle(rArea2xP, x+x, y+y, w+w, h+h);
+
+ MemHandleUnlock(hStr);
+ DmReleaseResource(hStr);
+
+ }
+ }
+
+ DmCloseDatabase(skinDBP);
+ }
+}
+
+static void GamUpdateList()
+{
+ MemHandle record;
+ UInt16 index, maxIndex, maxView;
+ GameInfoType *game;
+ RectangleType rArea, rField, rCopy, rArea2x;
+ DmOpenRef skinDBP;
+
+ UInt8 txtColor, norColor, selColor, bkgColor;
+ UInt16 x,y;
+
+ WinScreenLock(winLockCopy);
+ GamGetListBounds(&rArea, &rArea2x);
+ skinDBP = SknOpenSkin();
+ // set default bg
+ WinSetForeColor(UIColorGetTableEntryIndex (UIFormFill));
+ WinDrawRectangle(&rArea,0);
+ // copy top bg
+ SknGetObjectBounds(skinDBP, skinBackgroundImageTop, &rField);
+ RctGetIntersection(&rArea2x, &rField, &rCopy);
+ x = rCopy.topLeft.x;
+ y = rCopy.topLeft.y;
+ rCopy.topLeft.x -= rField.topLeft.x;
+ rCopy.topLeft.y -= rField.topLeft.y;
+ SknCopyBits(skinDBP, skinBackgroundImageTop, &rCopy, x, y, 0);
+ // copy bottom bg
+ SknGetObjectBounds(skinDBP, skinBackgroundImageBottom, &rField);
+ RctGetIntersection(&rArea2x, &rField, &rCopy);
+ x = rCopy.topLeft.x;
+ y = rCopy.topLeft.y;
+ rCopy.topLeft.x -= rField.topLeft.x;
+ rCopy.topLeft.y -= rField.topLeft.y;
+ SknCopyBits(skinDBP, skinBackgroundImageBottom, &rCopy, x, y, 0);
+
+ FntSetFont(stdFont);
+
+ index = gPrefs->listPosition;
+ maxIndex = DmNumRecords(_dbP);
+ maxView = rArea.extent.y / sknInfoListItemSize;
+
+ if (index > 0 && (index+maxView) > maxIndex) {
+ index -= (index+maxView) - maxIndex;
+ gPrefs->listPosition = index;
+ }
+ ArwRedrawSlider(skinDBP, index, maxIndex, maxView);
+ IcnRedrawTools(skinDBP);
+ SknGetListColors(skinDBP, skinColors, &norColor, &selColor, &bkgColor);
+
+ SknCloseSkin(skinDBP);
+
+ while (index < (gPrefs->listPosition + maxView) && index < maxIndex)
+ {
+ record = DmQueryRecord(_dbP, index);
+ game = (GameInfoType *)MemHandleLock(record);
+
+ // text box
+ RctSetRectangle(&rField, rArea.topLeft.x, (rArea.topLeft.y + 12 * (index - gPrefs->listPosition)), rArea.extent.x, sknInfoListItemSize);
+ WinSetClip(&rField);
+
+ if (game->selected) {
+ WinSetDrawMode(winPaint);
+ WinSetForeColor(bkgColor);
+ WinDrawRectangle(&rField,0);
+ txtColor = selColor;
+ }
+ else
+ txtColor = norColor;
+
+ // clipping
+ rField.topLeft.x += 2;
+ rField.extent.x -= 4;
+ WinSetClip(&rField);
+ // draw text mask
+ WinSetTextColor(255);
+ WinSetDrawMode(winMask);
+ WinPaintChars(game->nameP, StrLen(game->nameP), rField.topLeft.x, rField.topLeft.y);
+ // draw text
+ if (txtColor) {
+ WinSetTextColor(txtColor);
+ WinSetDrawMode(winOverlay);
+ WinPaintChars(game->nameP, StrLen(game->nameP), rField.topLeft.x, rField.topLeft.y);
+ }
+ MemHandleUnlock(record);
+ index++;
+ }
+
+ RctSetRectangle(&rArea,0,0,160,160);
+ WinSetClip(&rArea);
+ WinScreenUnlock();
+}
+
+static Boolean ArwProcessAction(UInt16 button)
+{
+ Boolean handled = false;
+
+ switch (button) {
+ case skinSliderUpArrow:
+ if (gPrefs->listPosition > 0) {
+ gPrefs->listPosition--;
+ GamUpdateList();
+ }
+ handled = true;
+ break;
+
+ case skinSliderDownArrow:
+ RectangleType rArea;
+ UInt16 maxView;
+
+ GamGetListBounds(&rArea, 0);
+ maxView = rArea.extent.y / sknInfoListItemSize;
+
+ if (gPrefs->listPosition < DmNumRecords(_dbP)-maxView) {
+ gPrefs->listPosition++;
+ GamUpdateList();
+ }
+ handled = true;
+ break;
+ }
+
+ return handled;
+}
+
+static void GamSelect(Coord x, Coord y) {
+ RectangleType rArea;
+ UInt16 x1,y1,x2,y2;
+
+ GamGetListBounds(&rArea,0);
+ x1 = rArea.topLeft.x;
+ x2 = rArea.topLeft.x + rArea.extent.x - 1;
+ y1 = rArea.topLeft.y;
+ y2 = rArea.topLeft.y + rArea.extent.y - 1;
+
+ if (y >= y1 && y <= y2 && x >= x1 && x <= x2) {
+ UInt16 index;
+ MemHandle record;
+ GameInfoType *game;
+ UInt16 oldIndex;
+
+ index = (y - y1) / sknInfoListItemSize + gPrefs->listPosition;
+
+ if (index == _lstIndex)
+ return;
+
+ if (index < DmNumRecords(_dbP))
+ {
+ GameInfoType modGame;
+
+ oldIndex = GamGetSelected();
+ record = DmGetRecord(_dbP, index);
+ game = (GameInfoType *)MemHandleLock(record);
+
+ MemMove(&modGame, game, sizeof(GameInfoType));
+ modGame.selected = !modGame.selected;
+ DmWrite(game, 0, &modGame, sizeof(GameInfoType));
+
+ MemHandleUnlock(record);
+ DmReleaseRecord (_dbP, index, 0);
+
+ if (oldIndex != index && oldIndex != dmMaxRecordIndex) {
+ record = DmGetRecord(_dbP, oldIndex);
+ game = (GameInfoType *)MemHandleLock(record);
+
+ MemMove(&modGame, game, sizeof(GameInfoType));
+ modGame.selected = false;
+ DmWrite(game, 0, &modGame, sizeof(GameInfoType));
+
+ MemHandleUnlock(record);
+ DmReleaseRecord (_dbP, oldIndex, 0);
+ }
+
+ _lstIndex = index;
+ GamUpdateList();
+ }
+ }
+}
+
+static void EditGameFormDelete(Boolean direct) {
+ UInt16 index = GamGetSelected();
+
+ if (index == dmMaxRecordIndex) {
+ FrmCustomAlert(FrmWarnAlert, "Select an entry first.",0,0);
+ return;
+
+ } else if (FrmAlert(FrmDeleteAlert) == 0) {
+ DmRemoveRecord(_dbP, index);
+ if (!direct)
+ FrmReturnToForm(MainForm);
+ GamSortList();
+ GamUpdateList();
+ }
+}
+
+static void FldTrimText(FieldType * fldP) {
+ MemHandle tmpH;
+ Char *tmpP;
+
+ tmpH = FldGetTextHandle(fldP);
+ FldSetTextHandle(fldP, NULL);
+ tmpP = (Char *)MemHandleLock(tmpH);
+ TxtGlueStripSpaces(tmpP, true, true);
+ MemHandleUnlock(tmpH);
+ FldSetTextHandle(fldP, tmpH);
+}
+
+
+/***********************************************************************
+ *
+ * FUNCTION: EditGameFormSave
+ * FUNCTION: EditGameFormInit
+ * FUNCTION: EditGameFormHandleEvent
+ *
+ * DESCRIPTION:
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+
+static void EditGameFormSave(UInt16 index) {
+
+ FieldType *fld1P, *fld2P, *fld3P, *fld4P, *fld5P, *fld6P; // need to change this with good names
+ ControlType *cck1P, *cck2P, *cck3P, *cck4P, *cck5P;
+ ListType *listP;
+ FormPtr frmP;
+
+ MemHandle recordH;
+ GameInfoType *gameInfo, newGameInfo;
+// UInt16 index;
+
+ listP = (ListType *)GetObjectPtr(EditGameGfxListList);
+ fld1P = (FieldType *)GetObjectPtr(EditGameEntryNameField);
+ fld2P = (FieldType *)GetObjectPtr(EditGamePathField);
+ fld3P = (FieldType *)GetObjectPtr(EditGameGameField);
+ fld4P = (FieldType *)GetObjectPtr(EditGameLoadSlotField);
+ fld5P = (FieldType *)GetObjectPtr(EditGameStartRoomField);
+ fld6P = (FieldType *)GetObjectPtr(EditGameTalkSpeedField);
+
+ cck1P = (ControlType *)GetObjectPtr(EditGameLoadSlotCheckbox);
+ cck2P = (ControlType *)GetObjectPtr(EditGameStartRoomCheckbox);
+ cck3P = (ControlType *)GetObjectPtr(EditGameAmigaCheckbox);
+ cck4P = (ControlType *)GetObjectPtr(EditGameSubtitlesCheckbox);
+ cck5P = (ControlType *)GetObjectPtr(EditGameTalkSpeedCheckbox);
+
+ frmP = FrmGetActiveForm();
+
+ FldTrimText(fld1P);
+ FldTrimText(fld2P);
+ FldTrimText(fld3P);
+
+ if (FldGetTextLength(fld1P) == 0) {
+ FrmCustomAlert(FrmWarnAlert,"You must specified an entry name.",0,0);
+ FrmSetFocus(frmP, FrmGetObjectIndex(frmP, EditGameEntryNameField));
+ return;
+ } else if (FldGetTextLength(fld2P) == 0) {
+ FrmCustomAlert(FrmWarnAlert,"You must specified a path.",0,0);
+ FrmSetFocus(frmP, FrmGetObjectIndex(frmP, EditGamePathField));
+ return;
+ } else if (FldGetTextLength(fld3P) == 0) {
+ FrmCustomAlert(FrmWarnAlert,"You must specified a game.",0,0);
+ FrmSetFocus(frmP, FrmGetObjectIndex(frmP, EditGameGameField));
+ return;
+ } else if (FldGetTextLength(fld5P) == 0 && CtlGetValue(cck2P) == 1) {
+ FrmCustomAlert(FrmWarnAlert,"You must specified a room number.",0,0);
+ FrmSetFocus(frmP, FrmGetObjectIndex(frmP, EditGameStartRoomField));
+ return;
+ } else if (FldGetTextLength(fld6P) == 0 && CtlGetValue(cck5P) == 1) {
+ FrmCustomAlert(FrmWarnAlert,"You must specified a talk speed.",0,0);
+ FrmSetFocus(frmP, FrmGetObjectIndex(frmP, EditGameTalkSpeedField));
+ return;
+ }
+
+ if (FldGetTextPtr(fld2P)[FldGetTextLength(fld2P)-1] != '/') {
+ FldGetTextPtr(fld2P)[FldGetTextLength(fld2P)+0] = '/';
+ FldGetTextPtr(fld2P)[FldGetTextLength(fld2P)+1] = 0;
+ }
+
+// index = GamGetSelected();
+
+ if (index != dmMaxRecordIndex) {
+ recordH = DmGetRecord(_dbP, index);
+ } else {
+ index = dmMaxRecordIndex;
+ GamUnselect();
+ recordH = DmNewRecord(_dbP, &index, sizeof(GameInfoType));
+ }
+
+ gameInfo = (GameInfoType *)MemHandleLock(recordH);
+
+ StrCopy(newGameInfo.nameP, FldGetTextPtr(fld1P));
+ StrCopy(newGameInfo.pathP, FldGetTextPtr(fld2P));
+ StrCopy(newGameInfo.gameP, FldGetTextPtr(fld3P));
+ newGameInfo.gfxMode = LstGetSelection(listP);
+ newGameInfo.selected = true;
+ newGameInfo.autoLoad = CtlGetValue(cck1P);
+ newGameInfo.loadSlot = StrAToI(FldGetTextPtr(fld4P));
+ newGameInfo.autoRoom = CtlGetValue(cck2P);
+ newGameInfo.roomNum = StrAToI(FldGetTextPtr(fld5P));
+ newGameInfo.amiga = CtlGetValue(cck3P);
+ newGameInfo.subtitles = !(CtlGetValue(cck4P));
+ newGameInfo.talkValue = StrAToI(FldGetTextPtr(fld6P));
+ newGameInfo.talkSpeed = CtlGetValue(cck5P);
+
+ DmWrite(gameInfo, 0, &newGameInfo, sizeof(GameInfoType));
+
+ MemHandleUnlock(recordH);
+ DmReleaseRecord (_dbP, index, 0);
+ GamSortList();
+ // update list position
+ {
+ RectangleType rArea;
+ UInt16 posIndex, maxIndex, maxView;
+
+ // get the sorted index
+ index = GamGetSelected();
+ // if new item is out of the list bounds, change current list pos
+ GamGetListBounds(&rArea, NULL);
+ maxView = rArea.extent.y / sknInfoListItemSize;
+ posIndex = gPrefs->listPosition;
+ maxIndex = DmNumRecords(_dbP);
+
+ if (index == 0 && posIndex > 0) {
+ gPrefs->listPosition = 0;
+ } else if ((maxView + posIndex) <= index) {
+ posIndex = index - (maxView - posIndex) + 1;
+ gPrefs->listPosition = posIndex;
+ }
+ }
+
+ FrmReturnToForm (MainForm);
+ GamUpdateList();
+}
+
+static void EditGameFormInit(UInt16 index) {
+
+ FieldType *fld1P, *fld2P, *fld3P, *fld4P, *fld5P, *fld6P;
+ FormPtr frmP;
+ ListType *listP;
+
+ Char *nameP, *pathP, *gameP, *loadP, *roomP, *talkP;
+ MemHandle nameH, pathH, gameH, loadH, roomH, talkH;
+
+ MemHandle recordH = NULL;
+ GameInfoType *game;
+
+ listP = (ListType *)GetObjectPtr(EditGameGfxListList);
+ fld1P = (FieldType *)GetObjectPtr(EditGameEntryNameField);
+ fld2P = (FieldType *)GetObjectPtr(EditGamePathField);
+ fld3P = (FieldType *)GetObjectPtr(EditGameGameField);
+ fld4P = (FieldType *)GetObjectPtr(EditGameLoadSlotField);
+ fld5P = (FieldType *)GetObjectPtr(EditGameStartRoomField);
+ fld6P = (FieldType *)GetObjectPtr(EditGameTalkSpeedField);
+
+ nameH = MemHandleNew(FldGetMaxChars(fld1P));
+ pathH = MemHandleNew(FldGetMaxChars(fld2P));
+ gameH = MemHandleNew(FldGetMaxChars(fld3P));
+ loadH = MemHandleNew(FldGetMaxChars(fld4P));
+ roomH = MemHandleNew(FldGetMaxChars(fld5P));
+ talkH = MemHandleNew(FldGetMaxChars(fld6P));
+
+ nameP = (Char *)MemHandleLock(nameH);
+ pathP = (Char *)MemHandleLock(pathH);
+ gameP = (Char *)MemHandleLock(gameH);
+ loadP = (Char *)MemHandleLock(loadH);
+ roomP = (Char *)MemHandleLock(roomH);
+ talkP = (Char *)MemHandleLock(talkH);
+
+// index = GamGetSelected();
+
+ if (index != dmMaxRecordIndex) {
+ recordH = DmQueryRecord(_dbP, index);
+ game = (GameInfoType *)MemHandleLock(recordH);
+ StrCopy(nameP, game->nameP);
+ StrCopy(pathP, game->pathP);
+ StrCopy(gameP, game->gameP);
+
+ LstSetSelection(listP, game->gfxMode);
+
+ StrIToA(loadP, game->loadSlot);
+ StrIToA(roomP, game->roomNum);
+ StrIToA(talkP, game->talkValue);
+
+ CtlSetValue((ControlType *)GetObjectPtr(EditGameLoadSlotCheckbox), game->autoLoad);
+ CtlSetValue((ControlType *)GetObjectPtr(EditGameStartRoomCheckbox), game->autoRoom);
+ CtlSetValue((ControlType *)GetObjectPtr(EditGameAmigaCheckbox), game->amiga);
+ CtlSetValue((ControlType *)GetObjectPtr(EditGameSubtitlesCheckbox), !game->subtitles);
+ CtlSetValue((ControlType *)GetObjectPtr(EditGameTalkSpeedCheckbox), game->talkSpeed);
+
+ MemHandleUnlock(recordH);
+ CtlSetUsable((ControlType *)GetObjectPtr(EditGameDeleteButton),true);
+ }
+ else {
+ MemSet(nameP,MemHandleSize(nameH),0);
+ MemSet(pathP,MemHandleSize(pathH),0);
+ MemSet(gameP,MemHandleSize(gameH),0);
+
+ StrIToA(loadP, 0);
+ StrIToA(roomP, 0);
+ StrIToA(talkP, 60);
+
+ CtlSetValue((ControlType *)GetObjectPtr(EditGameLoadSlotCheckbox), 0);
+ CtlSetValue((ControlType *)GetObjectPtr(EditGameStartRoomCheckbox), 0);
+ CtlSetValue((ControlType *)GetObjectPtr(EditGameAmigaCheckbox), 0);
+ CtlSetValue((ControlType *)GetObjectPtr(EditGameSubtitlesCheckbox), 0);
+ CtlSetValue((ControlType *)GetObjectPtr(EditGameTalkSpeedCheckbox), 0);
+
+ LstSetSelection(listP, 1);
+ CtlSetUsable((ControlType *)GetObjectPtr(EditGameDeleteButton),false);
+ }
+
+ MemHandleUnlock(nameH);
+ MemHandleUnlock(pathH);
+ MemHandleUnlock(gameH);
+ MemHandleUnlock(loadH);
+ MemHandleUnlock(roomH);
+ MemHandleUnlock(talkH);
+
+ FldSetTextHandle(fld1P, nameH);
+ FldSetTextHandle(fld2P, pathH);
+ FldSetTextHandle(fld3P, gameH);
+ FldSetTextHandle(fld4P, loadH);
+ FldSetTextHandle(fld5P, roomH);
+ FldSetTextHandle(fld6P, talkH);
+
+ CtlSetLabel((ControlType *)GetObjectPtr(EditGameGfxPopupPopTrigger), LstGetSelectionText(listP, LstGetSelection(listP)));
+
+ frmP = FrmGetActiveForm();
+ FrmDrawForm(frmP);
+}
+
+static Boolean EditGameFormHandleEvent(EventPtr eventP)
+{
+ Boolean handled = false;
+
+ switch (eventP->eType) {
+ case frmOpenEvent:
+ switch (__editMode__) {
+ case edtModeAdd:
+ EditGameFormInit(dmMaxRecordIndex);
+ break;
+ case edtModeEdit:
+ case edtModeParams:
+ default :
+ EditGameFormInit(GamGetSelected());
+ break;
+ }
+ handled = true;
+ break;
+
+ case ctlSelectEvent:
+ switch (eventP->data.ctlSelect.controlID)
+ {
+ case EditGameOKButton:
+ switch (__editMode__) {
+ case edtModeAdd:
+ EditGameFormSave(dmMaxRecordIndex);
+ break;
+ case edtModeEdit:
+ case edtModeParams:
+ default :
+ EditGameFormSave(GamGetSelected());
+ break;
+ }
+ break;
+
+ case EditGameCancelButton:
+ FrmReturnToForm(MainForm);
+ break;
+
+ case EditGameDeleteButton:
+ EditGameFormDelete(false);
+ break;
+
+ case EditGameGfxPopupPopTrigger:
+ FrmList(eventP, EditGameGfxListList);
+ break;
+ }
+ handled = true;
+ break;
+
+ default:
+ break;
+ }
+
+ return handled;
+}
+
+/***********************************************************************
+ *
+ * FUNCTION: VolumeFormSave
+ * FUNCTION: VolumeFormInit
+ * FUNCTION: VolumeFormHandleEvent
+ *
+ * DESCRIPTION:
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+
+static void VolumeFormSave() {
+ SliderControlType *slid1P, *slid2P, *slid3P, *slid4P, *slid5P;
+
+ slid1P = (SliderControlType *)GetObjectPtr(VolumeSpeakerSliderControl);
+ slid2P = (SliderControlType *)GetObjectPtr(VolumeHeadphoneSliderControl);
+
+ slid3P = (SliderControlType *)GetObjectPtr(VolumeMasterSliderControl);
+ slid4P = (SliderControlType *)GetObjectPtr(VolumeMusicSliderControl);
+ slid5P = (SliderControlType *)GetObjectPtr(VolumeSfxSliderControl);
+
+ CtlGetSliderValues ((ControlType *)slid1P, 0, 0, 0, &gPrefs->volume.speaker) ;
+ CtlGetSliderValues ((ControlType *)slid2P, 0, 0, 0, &gPrefs->volume.headphone) ;
+
+ CtlGetSliderValues ((ControlType *)slid3P, 0, 0, 0, &gPrefs->volume.master);
+ CtlGetSliderValues ((ControlType *)slid4P, 0, 0, 0, &gPrefs->volume.music);
+ CtlGetSliderValues ((ControlType *)slid5P, 0, 0, 0, &gPrefs->volume.sfx);
+
+ FrmReturnToForm (MainForm);
+}
+
+static void VolumeFormInit() {
+ SliderControlType *slid1P, *slid2P, *slid3P, *slid4P, *slid5P;
+ FormPtr frmP;
+ UInt16 value;
+
+ slid1P = (SliderControlType *)GetObjectPtr(VolumeSpeakerSliderControl);
+ slid2P = (SliderControlType *)GetObjectPtr(VolumeHeadphoneSliderControl);
+
+ slid3P = (SliderControlType *)GetObjectPtr(VolumeMasterSliderControl);
+ slid4P = (SliderControlType *)GetObjectPtr(VolumeMusicSliderControl);
+ slid5P = (SliderControlType *)GetObjectPtr(VolumeSfxSliderControl);
+
+ value = gPrefs->volume.speaker;
+ CtlSetSliderValues ((ControlType *)slid1P, 0, 0, 0, &value);
+ value = gPrefs->volume.headphone;
+ CtlSetSliderValues ((ControlType *)slid2P, 0, 0, 0, &value);
+
+ value = gPrefs->volume.master;
+ CtlSetSliderValues ((ControlType *)slid3P, 0, 0, 0, &value);
+ value = gPrefs->volume.music;
+ CtlSetSliderValues ((ControlType *)slid4P, 0, 0, 0, &value);
+ value = gPrefs->volume.sfx;
+ CtlSetSliderValues ((ControlType *)slid5P, 0, 0, 0, &value);
+
+ frmP = FrmGetActiveForm();
+ FrmDrawForm(frmP);
+}
+
+static Boolean VolumeFormHandleEvent(EventPtr eventP) {
+ Boolean handled = false;
+
+ switch (eventP->eType) {
+ case frmOpenEvent:
+ VolumeFormInit();
+ handled = true;
+ break;
+
+ case ctlSelectEvent:
+ switch (eventP->data.ctlSelect.controlID)
+ {
+ case VolumeOKButton:
+ VolumeFormSave();
+ break;
+
+ case VolumeCancelButton:
+ FrmReturnToForm(MainForm);
+ break;
+ }
+ handled = true;
+ break;
+
+ default:
+ break;
+ }
+
+ return handled;
+}
+
+static void SoundFormSave() {
+ ControlType *cck1P, *cck2P;
+ ListType *listP;
+ FieldType *fld1P;
+
+ fld1P = (FieldType *)GetObjectPtr(SoundTempoField);
+ cck1P = (ControlType *)GetObjectPtr(SoundMusicCheckbox);
+ cck2P = (ControlType *)GetObjectPtr(SoundSfxCheckbox);
+ listP = (ListType *)GetObjectPtr(SoundDriverList);
+
+ gPrefs->sound.music = CtlGetValue(cck1P);
+ gPrefs->sound.sfx = CtlGetValue(cck2P);
+ gPrefs->sound.driver = LstGetSelection(listP);
+
+ FrmReturnToForm (MainForm);
+}
+
+static void SoundFormInit() {
+ ControlType *cck1P, *cck2P;
+ ListType *listP;
+ FieldType *fld1P;
+ FormPtr frmP;
+
+ fld1P = (FieldType *)GetObjectPtr(SoundTempoField);
+ cck1P = (ControlType *)GetObjectPtr(SoundMusicCheckbox);
+ cck2P = (ControlType *)GetObjectPtr(SoundSfxCheckbox);
+ listP = (ListType *)GetObjectPtr(SoundDriverList);
+
+ CtlSetValue(cck1P, gPrefs->sound.music);
+ CtlSetValue(cck2P, gPrefs->sound.sfx);
+
+ LstSetSelection(listP, gPrefs->sound.driver);
+ CtlSetLabel((ControlType *)GetObjectPtr(SoundDriverPopTrigger), LstGetSelectionText(listP, LstGetSelection(listP)));
+
+ frmP = FrmGetActiveForm();
+ FrmDrawForm(frmP);
+}
+
+static Boolean SoundFormHandleEvent(EventPtr eventP) {
+ Boolean handled = false;
+
+ switch (eventP->eType) {
+ case frmOpenEvent:
+ SoundFormInit();
+ handled = true;
+ break;
+
+ case ctlSelectEvent:
+ switch (eventP->data.ctlSelect.controlID)
+ {
+ case SoundOKButton:
+ SoundFormSave();
+ break;
+
+ case SoundCancelButton:
+ FrmReturnToForm(MainForm);
+ break;
+
+ case SoundDriverPopTrigger:
+ FrmList(eventP, SoundDriverList);
+ break;
+
+ }
+ handled = true;
+ break;
+
+ default:
+ break;
+ }
+
+ return handled;
+}
+/***********************************************************************
+ *
+ * FUNCTION: MiscOptionsFormSave
+ * FUNCTION: MiscOptionsFormInit
+ * FUNCTION: MiscOptionsFormHandleEvent
+ *
+ * DESCRIPTION: Misc. Options form functions
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+
+static void MiscOptionsFormSave() {
+
+ FieldType *fld1P;
+ ControlType *cck1P, *cck2P, *cck3P, *cck4P;
+ FormPtr frmP;
+
+ fld1P = (FieldType *)GetObjectPtr(MiscOptionsDebugLevelField);
+
+ cck1P = (ControlType *)GetObjectPtr(MiscOptionsVibratorCheckbox);
+ cck2P = (ControlType *)GetObjectPtr(MiscOptionsNoAutoOffCheckbox);
+ cck3P = (ControlType *)GetObjectPtr(MiscOptionsStdPaletteCheckbox);
+ cck4P = (ControlType *)GetObjectPtr(MiscOptionsDebugCheckbox);
+
+ frmP = FrmGetActiveForm();
+
+ if (FldGetTextLength(fld1P) == 0 && CtlGetValue(cck4P) == 1) {
+ FrmCustomAlert(FrmWarnAlert,"You must specified a debug level.",0,0);
+ FrmSetFocus(frmP, FrmGetObjectIndex(frmP, MiscOptionsDebugLevelField));
+ return;
+ }
+
+ gPrefs->vibrator = CtlGetValue(cck1P);
+ gPrefs->autoOff = !CtlGetValue(cck2P);
+ gPrefs->stdPalette = CtlGetValue(cck3P);
+ gPrefs->debug = CtlGetValue(cck4P);
+ gPrefs->debugLevel = StrAToI(FldGetTextPtr(fld1P));
+
+ FrmReturnToForm (MainForm);
+}
+
+static void MiscOptionsFormInit() {
+
+ FieldType *fld1P;
+ FormPtr frmP;
+
+ Char *levelP;
+ MemHandle levelH;
+
+ CtlSetValue((ControlType *)GetObjectPtr(MiscOptionsVibratorCheckbox), gPrefs->vibrator);
+ CtlSetValue((ControlType *)GetObjectPtr(MiscOptionsNoAutoOffCheckbox), !gPrefs->autoOff);
+ CtlSetValue((ControlType *)GetObjectPtr(MiscOptionsStdPaletteCheckbox), gPrefs->stdPalette);
+ CtlSetValue((ControlType *)GetObjectPtr(MiscOptionsDebugCheckbox), gPrefs->debug);
+
+ fld1P = (FieldType *)GetObjectPtr(MiscOptionsDebugLevelField);
+
+ levelH = MemHandleNew(FldGetMaxChars(fld1P));
+ levelP = (Char *)MemHandleLock(levelH);
+ StrIToA(levelP, gPrefs->debugLevel);
+ MemHandleUnlock(levelH);
+
+ FldSetTextHandle(fld1P, levelH);
+ frmP = FrmGetActiveForm();
+ FrmDrawForm(frmP);
+}
+
+static Boolean MiscOptionsFormHandleEvent(EventPtr eventP) {
+ Boolean handled = false;
+
+ switch (eventP->eType) {
+ case frmOpenEvent:
+ MiscOptionsFormInit();
+ handled = true;
+ break;
+
+ case ctlSelectEvent:
+ switch (eventP->data.ctlSelect.controlID)
+ {
+ case MiscOptionsOKButton:
+ MiscOptionsFormSave();
+ break;
+
+ case MiscOptionsCancelButton:
+ FrmReturnToForm(MainForm);
+ break;
+ }
+ handled = true;
+ break;
+
+ default:
+ break;
+ }
+
+ return handled;
+}
+
+static UInt16 parseCards(Boolean forceDisplay) {
+
+ Err err;
+ UInt16 volRefNum;
+ UInt32 volIterator = vfsIteratorStart;
+ UInt8 counter = 0;
+
+ MemHandle cards = NULL;
+ CardInfoType *cardsInfo;
+ MemHandle items = NULL;
+ Char **itemsText = NULL;
+ UInt32 other = 1;
+
+ while (volIterator != vfsIteratorStop) {
+ err = VFSVolumeEnumerate(&volRefNum, &volIterator);
+
+ if (!err)
+ { Char labelP[expCardInfoStringMaxLen+1];
+ err = VFSVolumeGetLabel(volRefNum, labelP, expCardInfoStringMaxLen+1);
+
+ if (!err) {
+ if (StrLen(labelP) == 0) { // if no label try to retreive card type
+ VolumeInfoType volInfo;
+ err = VFSVolumeInfo(volRefNum, &volInfo);
+
+ if (!err) {
+ ExpCardInfoType info;
+ err = ExpCardInfo(volInfo.slotRefNum, &info);
+ StrCopy(labelP, info.deviceClassStr);
+ }
+
+ if (err != errNone) // if err default name
+ StrPrintF(labelP,"Other Card %ld", other++);
+ }
+
+ if (!cards)
+ cards = MemHandleNew(sizeof(CardInfoType));
+ else
+ MemHandleResize(cards, MemHandleSize(cards) + sizeof(CardInfoType));
+
+ cardsInfo = (CardInfoType *)MemHandleLock(cards);
+ cardsInfo[counter].volRefNum = volRefNum;
+ StrCopy(cardsInfo[counter].nameP, labelP);
+ MemHandleUnlock(cards);
+ counter++;
+ }
+ }
+ }
+
+ if (counter>0) {
+ cardsInfo = (CardInfoType *)MemHandleLock(cards);
+
+ if (forceDisplay) {
+ FormPtr frmP;
+ ListPtr listP;
+ Int16 selected = 0;
+ UInt16 index;
+
+ frmP = FrmInitForm (CardSlotForm);
+ listP = (ListType *)FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, CardSlotSlotList));
+
+ for (index = 0; index < counter; index++)
+ {
+ if (!items)
+ items = MemHandleNew(sizeof(Char *));
+ else
+ MemHandleResize(items, MemHandleSize(items) + sizeof(Char *));
+
+ itemsText = (Char **)MemHandleLock(items);
+ itemsText[index] = cardsInfo[index].nameP;
+ MemHandleUnlock(items);
+
+ if (cardsInfo[index].volRefNum == gPrefs->volRefNum)
+ selected = index;
+ }
+
+ itemsText = (Char **)MemHandleLock(items);
+ LstSetListChoices (listP, itemsText, counter);
+ LstSetSelection(listP, selected);
+ FrmDoDialog (frmP);
+ selected = LstGetSelection(listP);
+ MemHandleUnlock(items);
+ MemHandleFree(items);
+ FrmDeleteForm(frmP);
+
+ volRefNum = cardsInfo[selected].volRefNum;
+
+ } else {
+ volRefNum = cardsInfo[0].volRefNum; // return the first volref
+ }
+
+ MemHandleUnlock(cards);
+ MemHandleFree(cards);
+
+ } else if (forceDisplay) {
+ FrmCustomAlert(FrmWarnAlert, "No card found.\nPlease insert a memory card.", 0, 0);
+ volRefNum = sysInvalidRefNum;
+
+ } else {
+ volRefNum = sysInvalidRefNum;
+ }
+
+ FormPtr frmP = FrmGetActiveForm();
+
+ if (volRefNum != sysInvalidRefNum) { // if found try to create folders
+ VFSDirCreate(volRefNum, "/PALM");
+ VFSDirCreate(volRefNum, "/PALM/Programs");
+ VFSDirCreate(volRefNum, "/PALM/Programs/ScummVM");
+ VFSDirCreate(volRefNum, "/PALM/Programs/ScummVM/Games");
+ VFSDirCreate(volRefNum, "/PALM/Programs/ScummVM/Saved");
+
+ if (frmP)
+ FrmShowObject(frmP, FrmGetObjectIndex (frmP, MainMSBitMap));
+ } else {
+ if (frmP)
+ FrmShowObject(frmP, FrmGetObjectIndex (frmP, MainMSNoneBitMap));
+ }
+
+ return volRefNum;
+}
+
+//#############################################################################
+//#############################################################################
+// Skin manager
+//#############################################################################
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#define AppLastVersion "v0.2.97"
+#define AppLastYear "2003"
+
+static void SknApplySkin()
+{
+ DmOpenRef skinDBP;
+ RectangleType r;
+ FormPtr frmP = FrmGetActiveForm();
+
+ WinScreenLock(winLockErase);
+// SknSetPalette();
+ FrmDrawForm(frmP);
+
+ if (gPrefs->volRefNum != sysInvalidRefNum)
+ FrmShowObject(frmP, FrmGetObjectIndex (frmP, MainMSBitMap));
+ else
+ FrmShowObject(frmP, FrmGetObjectIndex (frmP, MainMSNoneBitMap));
+
+ WinSetForeColor(255);
+ WinSetDrawMode(winPaint);
+ WinDrawLine (0, 14, 159, 14);
+ WinDrawLine (0, 13, 159, 13);
+
+ skinDBP = SknOpenSkin();
+ SknGetObjectBounds(skinDBP, skinBackgroundImageTop, &r);
+ SknCopyBits(skinDBP, skinBackgroundImageTop, 0, r.topLeft.x, r.topLeft.y, 0);
+ SknGetObjectBounds(skinDBP, skinBackgroundImageBottom, &r);
+ SknCopyBits(skinDBP, skinBackgroundImageBottom, 0, r.topLeft.x, r.topLeft.y, 0);
+
+ for (UInt16 resID = 1100; resID <= 7000; resID += 100) {
+ SknSetState(skinDBP, resID, sknStateNormal);
+ SknShowObject(skinDBP, resID);
+ }
+
+ SknCloseSkin(skinDBP);
+ WinScreenUnlock();
+ GamUpdateList();
+}
+
+//#############################################################################
+//#############################################################################
+
+/***********************************************************************
+ *
+ * FUNCTION: MainFormInit
+ *
+ * DESCRIPTION: This routine initializes the MainForm form.
+ *
+ * PARAMETERS: frm - pointer to the MainForm form.
+ *
+ * RETURNED: nothing
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+static void MainFormInit()
+{
+ SknApplySkin();
+}
+
+/***********************************************************************
+ *
+ * FUNCTION: MainFormDoCommand
+ *
+ * DESCRIPTION: This routine performs the menu command specified.
+ *
+ * PARAMETERS: command - menu item id
+ *
+ * RETURNED: nothing
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+
+
+static Int16 SkinsFormCompare(SkinInfoType *a, SkinInfoType *b, SortRecordInfoPtr, SortRecordInfoPtr, MemHandle) {
+ return StrCompare(a->nameP, b->nameP);
+}
+
+static Char **itemsText = NULL;
+static void *itemsList = NULL;
+
+static void SkinsFormInit(Boolean bDraw) {
+ MemHandle skins = NULL;
+ SkinInfoType *skinsInfo;
+ UInt16 numSkins = 0;
+
+ FormPtr frmP;
+ ListType *listP;
+ MemHandle items = NULL;
+
+ DmSearchStateType stateInfo;
+ UInt16 cardNo;
+ LocalID dbID;
+
+ Err errInfo;
+ Char nameP[32];
+
+ itemsText = NULL;
+
+ // parse and save skins
+ Err err = DmGetNextDatabaseByTypeCreator(true, &stateInfo, 'skin', appFileCreator, false, &cardNo, &dbID);
+ while (!err && dbID) {
+ errInfo = DmDatabaseInfo (cardNo, dbID, nameP, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ if (!errInfo)
+ {
+ if (!skins)
+ skins = MemHandleNew(sizeof(SkinInfoType));
+ else
+ MemHandleResize(skins, MemHandleSize(skins) + sizeof(SkinInfoType));
+
+ skinsInfo = (SkinInfoType *)MemHandleLock(skins);
+ StrCopy(skinsInfo[numSkins].nameP, nameP);
+ skinsInfo[numSkins].cardNo = cardNo;
+ skinsInfo[numSkins].dbID = dbID;
+ MemHandleUnlock(skins);
+ numSkins++;
+ }
+ err = DmGetNextDatabaseByTypeCreator(false, &stateInfo, 'skin', appFileCreator, false, &cardNo, &dbID);
+ }
+
+ Int16 selected = -1;
+
+ listP = (ListType *)GetObjectPtr(SkinsSkinList);
+ skinsInfo = (SkinInfoType *)MemHandleLock(skins);
+ SysQSort(skinsInfo, numSkins, sizeof(SkinInfoType), (CmpFuncPtr)SkinsFormCompare, 0);
+
+ // create itemsText (TODO: create a custom draw function)
+ for (UInt16 index=0; index < numSkins; index++)
+ {
+ if (!items)
+ items = MemHandleNew(sizeof(Char *));
+ else
+ MemHandleResize(items, MemHandleSize(items) + sizeof(Char *));
+
+ itemsText = (Char **)MemHandleLock(items);
+ itemsText[index] = skinsInfo[index].nameP;
+ MemHandleUnlock(items);
+
+ if ( gPrefs->skin.cardNo == skinsInfo[index].cardNo &&
+ gPrefs->skin.dbID == skinsInfo[index].dbID &&
+ StrCompare(gPrefs->skin.nameP, skinsInfo[index].nameP) == 0)
+ selected = index;
+ }
+ // save globals and set list
+ itemsText = (Char **)MemHandleLock(items);
+ itemsList = (void *)skinsInfo;
+ LstSetListChoices (listP, itemsText, numSkins);
+ LstSetSelection(listP, selected);
+
+ if (bDraw) {
+ frmP = FrmGetActiveForm();
+ FrmDrawForm(frmP);
+ } else {
+ WinScreenLock(winLockCopy);
+ LstDrawList(listP);
+ WinScreenUnlock();
+// LstSetSelection(listP, 0);
+ }
+}
+
+
+
+static void SkinsFormExit(Boolean bSave) {
+ MemHandle skins;
+ MemHandle items;
+ SkinInfoType *skinsInfo;
+
+ ListType *listP;
+ Int16 selected;
+
+ listP = (ListType *)GetObjectPtr(SkinsSkinList);
+ selected = LstGetSelection(listP);
+
+ if (bSave && selected == -1) { // may never occured...
+ FrmCustomAlert(FrmWarnAlert, "You didn't select a skin.", 0, 0);
+ return;
+ }
+
+ skinsInfo = (SkinInfoType *)itemsList;
+ skins = MemPtrRecoverHandle(skinsInfo);
+ items = MemPtrRecoverHandle(itemsText);
+
+ itemsText = NULL;
+ itemsList = NULL;
+
+ if (bSave) {
+ StrCopy(gPrefs->skin.nameP, skinsInfo[selected].nameP);
+ gPrefs->skin.cardNo = skinsInfo[selected].cardNo;
+ gPrefs->skin.dbID = skinsInfo[selected].dbID;
+ }
+
+ FrmReturnToForm (MainForm);
+
+ MemHandleUnlock(items);
+ MemHandleUnlock(skins);
+ MemHandleFree(items);
+ MemHandleFree(skins);
+
+ if (bSave)
+ SknApplySkin();
+}
+
+static void SkinsFormBeam() {
+ SkinInfoType *skinsInfo;
+
+ ListType *listP;
+ Int16 selected;
+ Err err;
+
+ listP = (ListType *)GetObjectPtr(SkinsSkinList);
+ selected = LstGetSelection(listP);
+
+ if (selected == -1) { // may never occured...
+ FrmCustomAlert(FrmWarnAlert, "You didn't select a skin.", 0, 0);
+ return;
+ }
+
+ skinsInfo = (SkinInfoType *)itemsList;
+ err = SendDatabase(0, skinsInfo[selected].dbID, "skin.pdb", "\nScummVM Skin");
+
+// if (err)
+// FrmCustomAlert(FrmErrorAlert, "Unable to beam this skin.",0,0);
+}
+
+static void SkinsFormDelete() {
+ MemHandle skins;
+ MemHandle items;
+ SkinInfoType *skinsInfo;
+
+ ListType *listP;
+ Int16 selected;
+
+ listP = (ListType *)GetObjectPtr(SkinsSkinList);
+ selected = LstGetSelection(listP);
+
+ if (selected == -1) { // may never occured...
+ FrmCustomAlert(FrmInfoAlert, "You didn't select a skin.", 0, 0);
+ return;
+ }
+
+ skinsInfo = (SkinInfoType *)itemsList;
+ skins = MemPtrRecoverHandle(skinsInfo);
+ items = MemPtrRecoverHandle(itemsText);
+
+ if ( gPrefs->skin.cardNo == skinsInfo[selected].cardNo &&
+ gPrefs->skin.dbID == skinsInfo[selected].dbID &&
+ StrCompare(gPrefs->skin.nameP, skinsInfo[selected].nameP) == 0) {
+ FrmCustomAlert(FrmInfoAlert, "You cannot delete the active skin.",0,0);
+ return;
+
+ } else {
+ Err err = DmDeleteDatabase(0, skinsInfo[selected].dbID);
+ if (!err) {
+
+ itemsText = NULL;
+ itemsList = NULL;
+
+ MemHandleUnlock(items);
+ MemHandleUnlock(skins);
+ MemHandleFree(items);
+ MemHandleFree(skins);
+
+ SkinsFormInit(false);
+ } else {
+ FrmCustomAlert(FrmErrorAlert, "Skin deletion failed.",0,0);
+ }
+ }
+
+}
+static Boolean SkinsFormHandleEvent(EventPtr eventP) {
+ Boolean handled = false;
+
+ switch (eventP->eType) {
+
+ case frmOpenEvent:
+ SkinsFormInit(true);
+ handled = true;
+ break;
+
+ case frmCloseEvent:
+ SkinsFormExit(false);
+ handled = true;
+ break;
+
+ case ctlSelectEvent:
+ switch (eventP->data.ctlSelect.controlID)
+ {
+ case SkinsOKButton:
+ SkinsFormExit(true);
+ break;
+
+ case SkinsCancelButton:
+ SkinsFormExit(false);
+ break;
+
+ case SkinsBeamButton:
+ SkinsFormBeam();
+ break;
+
+ case SkinsDeleteButton:
+ SkinsFormDelete();
+ break;
+ }
+ handled = true;
+ break;
+
+ default:
+ break;
+ }
+
+ return handled;
+}
+/*
+
+static void SkinsFormDoDialog() {
+ MemHandle skins = NULL;
+ SkinInfoType *skinsInfo;
+ UInt16 numSkins = 0;
+
+ FormPtr frmP;
+ ListType *listP;
+ MemHandle items = NULL;
+ Char **itemsText = NULL;
+
+ DmSearchStateType stateInfo;
+ UInt16 cardNo;
+ LocalID dbID;
+
+ Err errInfo;
+ Char nameP[32];
+
+ Err err = DmGetNextDatabaseByTypeCreator(true, &stateInfo, 'skin', appFileCreator, false, &cardNo, &dbID);
+ while (!err && dbID) {
+ errInfo = DmDatabaseInfo (cardNo, dbID, nameP, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ if (!errInfo)
+ {
+ if (!skins)
+ skins = MemHandleNew(sizeof(SkinInfoType));
+ else
+ MemHandleResize(skins, MemHandleSize(skins) + sizeof(SkinInfoType));
+
+ skinsInfo = (SkinInfoType *)MemHandleLock(skins);
+ StrCopy(skinsInfo[numSkins].nameP, nameP);
+ skinsInfo[numSkins].cardNo = cardNo;
+ skinsInfo[numSkins].dbID = dbID;
+ MemHandleUnlock(skins);
+ numSkins++;
+ }
+ err = DmGetNextDatabaseByTypeCreator(false, &stateInfo, 'skin', appFileCreator, false, &cardNo, &dbID);
+ }
+
+ UInt16 button;
+ Int16 selected = -1;
+
+ frmP = FrmInitForm (SkinsForm);
+ listP = (ListType *)FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, SkinsSkinList));
+
+ skinsInfo = (SkinInfoType *)MemHandleLock(skins);
+ SysQSort(skinsInfo, numSkins, sizeof(SkinInfoType), (CmpFuncPtr)SkinsFormCompare, 0);
+ for (UInt16 index=0; index < numSkins; index++)
+ {
+ if (!items)
+ items = MemHandleNew(sizeof(Char *));
+ else
+ MemHandleResize(items, MemHandleSize(items) + sizeof(Char *));
+
+ itemsText = (Char **)MemHandleLock(items);
+ itemsText[index] = skinsInfo[index].nameP;
+ MemHandleUnlock(items);
+
+ if ( gPrefs->skin.cardNo == skinsInfo[index].cardNo &&
+ gPrefs->skin.dbID == skinsInfo[index].dbID &&
+ StrCompare(gPrefs->skin.nameP, skinsInfo[index].nameP) == 0)
+ selected = index;
+ }
+ itemsText = (Char **)MemHandleLock(items);
+ LstSetListChoices (listP, itemsText, numSkins);
+ LstSetSelection(listP, selected);
+ button = FrmDoDialog (frmP);
+ selected = LstGetSelection(listP);
+
+ switch (button) {
+ case SkinsOKButton:
+ StrCopy(gPrefs->skin.nameP, skinsInfo[selected].nameP);
+ gPrefs->skin.cardNo = skinsInfo[selected].cardNo;
+ gPrefs->skin.dbID = skinsInfo[selected].dbID;
+ SknApplySkin();
+ break;
+
+ case SkinsSkinDeleteButton:
+ FrmCustomAlert(FrmWarnAlert,"Not implemented !",0,0);
+ break;
+ }
+
+ FrmDeleteForm (frmP);
+ MemHandleUnlock(items);
+ MemHandleUnlock(skins);
+ MemHandleFree(items);
+ MemHandleFree(skins);
+}
+*/
+static Boolean MainFormDoCommand(UInt16 command)
+{
+ Boolean handled = false;
+ FormPtr frmP;
+
+ switch (command)
+ {
+ case MainGamesChooseaCard:
+ MenuEraseStatus(0);
+ gPrefs->volRefNum = parseCards(true);
+ handled = true;
+ break;
+
+ case MainGamesNewEdit:
+ MenuEraseStatus(0);
+ __editMode__ = edtModeParams;
+ FrmPopupForm(EditGameForm);
+ handled = true;
+ break;
+
+ case MainGamesBeamScummVM:
+ MenuEraseStatus(0);
+ BeamMe();
+ //if (BeamMe())
+ //FrmCustomAlert(FrmErrorAlert,"Unable to beam ScummVM for PalmOS.",0,0);
+ handled = true;
+ break;
+
+ case MainOptionsAbout:
+ MenuEraseStatus(0); // Clear the menu status from the display.
+ frmP = FrmInitForm (AboutForm);
+ FrmDoDialog (frmP); // Display the About Box.
+ FrmDeleteForm (frmP);
+ handled = true;
+ break;
+
+ case MainOptionsVolumeControl:
+ FrmPopupForm(VolumeForm);
+ handled = true;
+ break;
+
+ case MainOptionsSoundPrefs:
+ FrmPopupForm(SoundForm);
+ handled = true;
+ break;
+
+ case MainOptionsSkins:
+ MenuEraseStatus(0); // Clear the menu status from the display.
+ //SkinsFormDoDialog();
+ FrmPopupForm(SkinsForm);
+ handled = true;
+ break;
+
+ case MainOptionsMiscellaneous:
+ MenuEraseStatus(0); // Clear the menu status from the display.
+ FrmPopupForm(MiscOptionsForm);
+ handled = true;
+ break;
+ }
+
+ return handled;
+}
+
+
+static void SavePrefs() {
+ if (gPrefs) {
+ PrefSetAppPreferences(appFileCreator, appPrefID, appPrefVersionNum, gPrefs, sizeof (GlobalsPreferenceType), true);
+ MemPtrFree(gPrefs);
+ gPrefs = NULL;
+ }
+}
+
+static Boolean CheckVibratorExists() {
+ UInt32 romVersion;
+ Err err;
+ Boolean exists = false;
+
+ err = FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
+ if (!err) {
+ if (romVersion >= sysMakeROMVersion(4,0,0,sysROMStageRelease,0)) {
+ Boolean active = false;
+ err = HwrVibrateAttributes(0, kHwrVibrateActive, &active);
+ exists = (!err) ? true : exists;
+ }
+ }
+
+ return exists;
+}
+
+static void AddArg(Char **argvP, const Char *argP, const Char *parmP, UInt8 *countArgP)
+{
+ if (argP)
+ {
+ UInt16 len2 = 0;
+ UInt16 len1 = StrLen(argP);
+
+ if (len1 > 0)
+ {
+ if (parmP)
+ len2 = StrLen(parmP);
+
+ (*countArgP)++;
+ *argvP = (Char *)MemPtrNew(len1 + len2 + 1);
+ StrCopy(*argvP, argP);
+
+ if (parmP)
+ StrCat(*argvP, parmP);
+ }
+ }
+}
+
+// need to move this on a .h file
+#define sonySysFileCSystem 'SsYs' /* Sony overall System */
+#define sonySysFtrCreatorSystem sonySysFileCSystem
+
+#define sonySysFtrNumSystemBase 10000
+#define sonySysFtrNumSystemAOutSndStateOnHandlerP (sonySysFtrNumSystemBase + 4)
+#define sonySysFtrNumSystemAOutSndStateOffHandlerP (sonySysFtrNumSystemBase + 5)
+
+typedef void (*sndStateOnType)(UInt8 /* kind */, UInt8 /* L volume 0-31 */, UInt8 /* R volume 0-31 */);
+typedef void (*sndStateOffType)(UInt8 /* kind */);
+
+/* kind */
+#define aOutSndKindSp (0) /* Speaker volume */
+#define aOutSndKindHp (2) /* HeadPhone volume */
+////////////////////////////////////////////////////////////
+#define MAX_ARG 20
+static void StartScummVM()
+{
+ Char *argvP[MAX_ARG];
+ UInt8 argc = 0;
+ UInt8 count;
+
+ Boolean autoOff;
+ UInt16 autoOffDelay;
+ Boolean debug;
+ UInt16 musicDriver = sysInvalidRefNum; // for launch call
+
+ UInt16 index = GamGetSelected();
+/*
+ if (index == dmMaxRecordIndex) {
+ // TODO : enable "Continue anyway ?" to use ScummVM selector
+ FrmCustomAlert(FrmWarnAlert,"Error : No game was specified !",0,0);
+ return;
+ }
+*/
+ for(count = 0; count < MAX_ARG; count++)
+ argvP[count] = 0;
+
+ if (index != dmMaxRecordIndex) {
+ Char pathP[256];
+ Char num[4];
+ MemHandle recordH;
+ GameInfoType *gameInfoP;
+
+ recordH = DmQueryRecord(_dbP,index);
+ gameInfoP = (GameInfoType *)MemHandleLock(recordH);
+
+ // check path
+ StrCopy(pathP,"/Palm/Programs/ScummVM/Games/");
+ if (gameInfoP->pathP[0]=='/')
+ StrCopy(pathP,gameInfoP->pathP);
+ else
+ StrCat(pathP,gameInfoP->pathP);
+ /* {
+ FileRef tmpRef;
+ // TODO : enable empty path -> /Palm/Programs/ScummVM/Games/ as default
+ if (VFSFileOpen(gPrefs->volRefNum, pathP, vfsModeRead, &tmpRef) != errNone) {
+ MemHandleUnlock(recordH);
+ FrmCustomAlert(FrmErrorAlert,"The specified path was not found !",0,0);
+ return;
+ } else {
+ VFSFileClose(tmpRef);
+ }
+ }
+ */
+ AddArg(&argvP[argc], "ScummVM", NULL, &argc);
+ // AddArg(&argvP[argc], "-w", NULL, &argc);
+
+ // path
+ AddArg(&argvP[argc], "-p", pathP, &argc);
+
+ // gfx mode
+ gVars->flipping.pageAddr1 = (UInt8 *)(BmpGetBits(WinGetBitmap(WinGetDisplayWindow())));
+ gVars->flipping.pageAddr2 = gVars->flipping.pageAddr1; // default if not flipping mode
+ switch (gameInfoP->gfxMode)
+ {
+ case 1:
+ AddArg(&argvP[argc], "-g", "flipping", &argc);
+ gVars->flipping.pageAddr1 = (UInt8 *)WinScreenLock(winLockErase);
+ WinScreenUnlock();
+ break;
+ case 2:
+ AddArg(&argvP[argc], "-g", "dbuffer", &argc);
+ break;
+ default:
+ AddArg(&argvP[argc], "-g", "normal", &argc);
+ break;
+ }
+
+ // load state
+ if (gameInfoP->autoLoad) {
+ StrIToA(num, gameInfoP->loadSlot);
+ AddArg(&argvP[argc], "-x", num, &argc);
+ }
+ // start in room
+ if (gameInfoP->autoRoom) {
+ StrIToA(num, gameInfoP->roomNum);
+ AddArg(&argvP[argc], "-b", num, &argc);
+ }
+ // amiga palette
+ if (gameInfoP->amiga) {
+ AddArg(&argvP[argc], "-a", NULL, &argc);
+ }
+ // subtitles
+ if (!gameInfoP->subtitles) {
+ AddArg(&argvP[argc], "-n", NULL, &argc);
+ }
+ // talk speed
+ if (gameInfoP->talkSpeed) {
+ StrIToA(num, gameInfoP->talkValue);
+ AddArg(&argvP[argc], "-y", num, &argc);
+ }
+ // debug level
+ debug = gPrefs->debug;
+ if (gPrefs->debug) {
+ StrIToA(num, gPrefs->debugLevel);
+ AddArg(&argvP[argc], "-d", num, &argc);
+ }
+ // music driver
+ musicDriver = gPrefs->sound.music;
+ if (musicDriver) {
+ switch (gPrefs->sound.driver) {
+ case 0: // NULL
+ AddArg(&argvP[argc], "-e", "null", &argc);
+ break;
+ case 1: // yam ha Pa1
+ AddArg(&argvP[argc], "-e", "ypa1", &argc);
+ break;
+ }
+ }
+ else // NULL as default
+ AddArg(&argvP[argc], "-e", "null", &argc);
+
+ // volume control
+ StrIToA(num, gPrefs->volume.master);
+ AddArg(&argvP[argc], "-o", num, &argc);
+ StrIToA(num, gPrefs->volume.sfx);
+ AddArg(&argvP[argc], "-s", num, &argc);
+ StrIToA(num, gPrefs->volume.music);
+ AddArg(&argvP[argc], "-m", num, &argc);
+
+ // game name
+ AddArg(&argvP[argc], gameInfoP->gameP, NULL, &argc);
+
+ MemHandleUnlock(recordH);
+ }
+
+ GamCloseDatabase();
+ FrmCloseAllForms();
+
+ autoOff = gPrefs->autoOff;
+ if (!autoOff) {
+ autoOffDelay = SysSetAutoOffTime(0);
+ EvtResetAutoOffTimer();
+ }
+
+ // gVars values
+ //gVars->HRrefNum defined in checkHRmode on Clié OS4
+ //gVars->logFile defined bellow, must be defined only if debug option is checked
+ gVars->screenLocked = false;
+ gVars->volRefNum = gPrefs->volRefNum;
+ gVars->vibrator = gPrefs->vibrator;
+ gVars->stdPalette = gPrefs->stdPalette;
+// gVars->volume.speaker = gPrefs->volume.speaker;
+// gVars->volume.headphone = gPrefs->volume.headphone;
+
+ if (gVars->vibrator)
+ {
+ if (CheckVibratorExists()) {
+ UInt16 cycle = (SysTicksPerSecond())/2;
+ UInt32 pattern = 0xFF000000;
+ UInt16 delay = 1;
+ UInt16 repeat = 1;
+
+ HwrVibrateAttributes(1, kHwrVibrateRate, &cycle);
+ HwrVibrateAttributes(1, kHwrVibratePattern, &pattern);
+ HwrVibrateAttributes(1, kHwrVibrateDelay, &delay);
+ HwrVibrateAttributes(1, kHwrVibrateRepeatCount, &repeat);
+
+ } else {
+ gVars->vibrator = false;
+ }
+ }
+
+ if (debug) {
+ VFSFileDelete(gVars->volRefNum,"PALM/Programs/ScummVM/scumm.log");
+ VFSFileCreate(gVars->volRefNum,"PALM/Programs/ScummVM/scumm.log");
+ VFSFileOpen(gVars->volRefNum,"PALM/Programs/ScummVM/scumm.log",vfsModeWrite, &gVars->logFile);
+ }
+
+ void *sndStateOnFuncP = 0, *sndStateOffFuncP = 0;
+
+ if (musicDriver == 1 || musicDriver == sysInvalidRefNum) {
+
+ Pa1Lib_Open();
+
+ FtrGet(sonySysFtrCreatorSystem, sonySysFtrNumSystemAOutSndStateOnHandlerP, (UInt32*) &sndStateOnFuncP);
+ FtrGet(sonySysFtrCreatorSystem, sonySysFtrNumSystemAOutSndStateOffHandlerP, (UInt32*) &sndStateOffFuncP);
+
+ if (sndStateOnFuncP && sndStateOffFuncP) {
+ ((sndStateOnType)(sndStateOnFuncP))(aOutSndKindSp, gPrefs->volume.headphone, gPrefs->volume.headphone);
+ ((sndStateOnType)(sndStateOnFuncP))(aOutSndKindHp, gPrefs->volume.speaker, gPrefs->volume.speaker);
+
+ }
+
+ Pa1Lib_devHpVolume(gPrefs->volume.headphone, gPrefs->volume.headphone);
+ Pa1Lib_devSpVolume(gPrefs->volume.speaker);
+ // Pa1Lib_devEqVolume(gPrefs->volume.speaker);
+ }
+ SavePrefs(); // free globals pref memory
+ GBOpen();
+ GBInitAll();
+
+// MemExtInit();
+ main(argc, argvP);
+// MemExtCleanup();
+
+ GBReleaseAll();
+ GBClose();
+
+ if (musicDriver == 1 || musicDriver == sysInvalidRefNum) {
+ if (sndStateOnFuncP && sndStateOffFuncP) {
+ ((sndStateOffType)(sndStateOffFuncP))(aOutSndKindSp);
+ ((sndStateOffType)(sndStateOffFuncP))(aOutSndKindHp);
+ }
+ Pa1Lib_Close();
+ }
+
+ if (debug)
+ VFSFileClose(gVars->logFile);
+
+ for(count = 0; count < MAX_ARG; count++)
+ if (argvP[count])
+ MemPtrFree(argvP[count]);
+
+ if (gVars->vibrator) {
+ Boolean active = false;
+ HwrVibrateAttributes(1, kHwrVibrateActive, &active);
+ }
+
+ if (!autoOff) {
+ SysSetAutoOffTime(autoOffDelay);SystemPreferencesChoice
+ EvtResetAutoOffTimer();
+ }
+}
+
+void PalmFatalError(const Char *err)
+{
+ WinPalette(winPaletteSetToDefault,0,0,0);
+
+ if (gVars->screenLocked)
+ WinScreenUnlock();
+
+// MemExtCleanup();
+ WinEraseWindow();
+ FrmCustomAlert(FrmFatalErrorAlert, err, 0,0);
+ SysReset();
+}
+
+/*
+void DrawBitmap (DmResID resID, Coord x, Coord y, WinDrawOperation newMode)
+{
+ MemHandle hTemp;
+ BitmapType* bmTemp;
+ WinDrawOperation oldMode;
+
+ hTemp = DmGetResource(bitmapRsc,resID);
+ bmTemp = MemHandleLock(hTemp);
+
+ oldMode = WinSetDrawMode(newMode);
+ WinPaintBitmap(bmTemp, x, y);
+ WinSetDrawMode(oldMode);
+
+ MemHandleUnlock(hTemp);
+ DmReleaseResource((MemPtr)bmTemp);
+}
+*/
+
+/***********************************************************************
+ *
+ * FUNCTION: MainFormHandleEvent
+ *
+ * DESCRIPTION: This routine is the event handler for the
+ * "MainForm" of this application.
+ *
+ * PARAMETERS: eventP - a pointer to an EventType structure
+ *
+ * RETURNED: true if the event has handle and should not be passed
+ * to a higher level handler.
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+/*
+static void CheckCardPresent() {
+
+ if (gVolRefNum) {
+ Err err;
+ VolumeInfoType volInfo;
+ err = VFSVolumeInfo(gVolRefNum, &volInfo);
+
+ if (!err) {
+ err = ExpCardPresent(volInfo.slotRefNum);
+
+ if (err != errNone && err != expErrInvalidSlotRefNum) // expErrInvalidSlotRefNum -> error on palmSim with hostFS
+ gVolRefNum = 0;
+ }
+ }
+
+ if (!gVolRefNum) {
+ FormPtr frmP = FrmGetActiveForm();
+
+ if (frmP)
+ FrmHideObject(frmP, FrmGetObjectIndex (frmP, MainMSBitMap));
+ }
+}
+*/
+static Boolean penDownRepeat() {
+ Coord x,y;
+ Boolean penDown, handled = false;
+ EvtGetPen(&x, &y, &penDown);
+
+ if (penDown && sknLastOn) {
+ RectangleType r;
+ DmOpenRef skinDBP;
+
+ skinDBP = SknOpenSkin();
+ SknGetObjectBounds(skinDBP, sknLastOn, &r);
+
+ if (RctPtInRectangle(x*2, y*2, &r)) {
+ if (SknGetState(skinDBP, sknLastOn) != sknStateSelected) {
+ SknSetState(skinDBP, sknLastOn, sknStateSelected);
+ SknShowObject(skinDBP, sknLastOn);
+ }
+
+ switch (sknLastOn) {
+ case skinSliderUpArrow:
+ case skinSliderDownArrow:
+ handled = ArwProcessAction(sknLastOn);
+ break;
+ }
+
+ } else {
+ if (SknGetState(skinDBP, sknLastOn) != sknStateNormal) {
+ SknSetState(skinDBP, sknLastOn, sknStateNormal);
+ SknShowObject(skinDBP, sknLastOn);
+ }
+ }
+
+ SknCloseSkin(skinDBP);
+ }
+
+ return handled;
+}
+
+static Boolean MainFormHandleEvent(EventPtr eventP)
+{
+ Boolean handled = false;
+ FormPtr frmP;
+ Coord x,y;
+ DmOpenRef skinDBP;
+
+ switch (eventP->eType) {
+ case menuEvent:
+ return MainFormDoCommand(eventP->data.menu.itemID);
+
+ case frmOpenEvent:
+ MainFormInit();
+ handled = true;
+ break;
+
+ case ctlSelectEvent:
+ switch (eventP->data.ctlSelect.controlID)
+ {
+ case MainCardsButton:
+ gPrefs->volRefNum = parseCards(true);
+ break;
+
+ case MainAboutButton:
+ frmP = FrmInitForm (AboutForm);
+ FrmDoDialog (frmP); // Display the About Box.
+ FrmDeleteForm (frmP);
+ break;
+
+// case MainListTypeSelTrigger:
+// FrmList(eventP, MainListTypeList);
+// break;
+ }
+ handled = true;
+ break;
+
+ case frmUpdateEvent:
+ int a= 0;
+ // To do any custom drawing here, first call FrmDrawForm(), then do your
+ // drawing, and then set handled to true.
+ break;
+
+ case penUpEvent:
+ x = eventP->screenX;
+ y = eventP->screenY;
+
+ _lstIndex = dmMaxRecordIndex;
+
+ if (sknLastOn != skinButtonNone) {
+ RectangleType r;
+ skinDBP = SknOpenSkin();
+ SknGetObjectBounds(skinDBP, sknLastOn, &r);
+ SknSetState(skinDBP, sknLastOn, sknStateNormal);
+ SknShowObject(skinDBP, sknLastOn);
+ SknCloseSkin(skinDBP);
+
+ if (RctPtInRectangle(x*2, y*2, &r)) {
+ switch (sknLastOn) {
+ case skinButtonGameAdd:
+ __editMode__ = edtModeAdd;
+ FrmPopupForm(EditGameForm);
+ handled = true;
+ break;
+
+ case skinButtonGameEdit:
+ case skinButtonGameParams:
+ __editMode__ = edtModeParams;
+ FrmPopupForm(EditGameForm);
+ handled = true;
+ break;
+
+ case skinButtonGameStart:
+ if (gPrefs->volRefNum == sysInvalidRefNum)
+ FrmCustomAlert(FrmWarnAlert,"Please select/insert a memory card.", 0, 0);
+ else
+ StartScummVM();
+ handled = true;
+ break;
+
+ case skinButtonGameDelete:
+ EditGameFormDelete(true);
+ break;
+ }
+ }
+ sknLastOn = skinButtonNone;
+ }
+ break;
+
+ case penDownEvent:
+ case penMoveEvent:
+ if (sknLastOn == skinButtonNone) {
+ x = eventP->screenX;
+ y = eventP->screenY;
+ skinDBP = SknOpenSkin();
+
+ switch (sknLastOn = SknCheckClick(skinDBP, x,y)) {
+ case skinButtonNone:
+ break;
+ case skinSliderUpArrow:
+ case skinSliderDownArrow:
+ case skinButtonGameAdd:
+ case skinButtonGameEdit:
+ case skinButtonGameParams:
+ case skinButtonGameStart:
+ case skinButtonGameDelete:
+ SknSetState(skinDBP, sknLastOn, sknStateSelected);
+ SknShowObject(skinDBP, sknLastOn);
+ handled = true;
+ break;
+ default:
+ FrmCustomAlert(FrmWarnAlert,"Unknown button !",0,0);
+ }
+ SknCloseSkin(skinDBP);
+ GamSelect(x, y);
+ }
+ break;
+
+ default:
+ handled = penDownRepeat();
+ }
+
+ return handled;
+}
+
+/***********************************************************************
+ *
+ * FUNCTION: AppHandleEvent
+ *
+ * DESCRIPTION: This routine loads form resources and set the event
+ * handler for the form loaded.
+ *
+ * PARAMETERS: event - a pointer to an EventType structure
+ *
+ * RETURNED: true if the event has handle and should not be passed
+ * to a higher level handler.
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+static Boolean AppHandleEvent(EventPtr eventP)
+{
+ UInt16 formId;
+ FormPtr frmP;
+
+ if (eventP->eType == frmLoadEvent)
+ {
+ // Load the form resource.
+ formId = eventP->data.frmLoad.formID;
+ frmP = FrmInitForm(formId);
+ FrmSetActiveForm(frmP);
+
+ // Set the event handler for the form. The handler of the currently
+ // active form is called by FrmHandleEvent each time is receives an
+ // event.
+ switch (formId)
+ {
+ case MainForm:
+ FrmSetEventHandler(frmP, MainFormHandleEvent);
+ break;
+
+ case SkinsForm:
+ FrmSetEventHandler(frmP, SkinsFormHandleEvent);
+ break;
+
+ case EditGameForm:
+ FrmSetEventHandler(frmP, EditGameFormHandleEvent);
+ break;
+
+ case MiscOptionsForm:
+ FrmSetEventHandler(frmP, MiscOptionsFormHandleEvent);
+ break;
+
+ case VolumeForm:
+ FrmSetEventHandler(frmP, VolumeFormHandleEvent);
+ break;
+
+ case SoundForm:
+ FrmSetEventHandler(frmP, SoundFormHandleEvent);
+ break;
+
+ default:
+// ErrFatalDisplay("Invalid Form Load Event");
+ break;
+
+ }
+ return true;
+ }
+
+ return false;
+}
+
+
+/***********************************************************************
+ *
+ * FUNCTION: AppEventLoop
+ *
+ * DESCRIPTION: This routine is the event loop for the application.
+ *
+ * PARAMETERS: nothing
+ *
+ * RETURNED: nothing
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+static void AppEventLoop(void)
+{
+ UInt16 error;
+ EventType event;
+
+ do {
+ EvtGetEvent(&event, evtNoWait);
+
+ if (! SysHandleEvent(&event))
+ if (! MenuHandleEvent(0, &event, &error))
+ if (! AppHandleEvent(&event))
+ FrmDispatchEvent(&event);
+
+ } while (event.eType != appStopEvent);
+}
+
+
+/***********************************************************************
+ *
+ * FUNCTION: AppStart
+ *
+ * DESCRIPTION: Get the current application's preferences.
+ *
+ * PARAMETERS: nothing
+ *
+ * RETURNED: Err value 0 if nothing went wrong
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+static Err AppStartCheckHRmode()
+{
+ SonySysFtrSysInfoP sonySysFtrSysInfoP;
+ UInt32 version;
+ Err error = errNone;
+
+ // test if sonyHR is present
+ if (!(error = FtrGet(sonySysFtrCreator, sonySysFtrNumSysInfoP, (UInt32*)&sonySysFtrSysInfoP)))
+ {
+ if (sonySysFtrSysInfoP->libr & sonySysFtrSysInfoLibrHR) { /* HR available */
+
+ if ((error = SysLibFind(sonySysLibNameHR, &gVars->HRrefNum))) {
+ if (error == sysErrLibNotFound) /* couldn't find lib */
+ error = SysLibLoad( 'libr', sonySysFileCHRLib, &gVars->HRrefNum );
+ }
+
+ if (!error )
+ { /* Now we can use HR lib. Executes Open library. */
+ error = HROpen(gVars->HRrefNum);
+ }
+ }
+ }
+ // if not Hi-Density ?
+ if (error && !(error = FtrGet(sysFtrCreator, sysFtrNumWinVersion, &version)))
+ {
+ gVars->HRrefNum = sysInvalidRefNum; // Not sony HR
+ if (version<4)
+ error = 1;
+ }
+
+ if (!error) { /* Not error processing */
+ UInt32 width, height, depth;
+ Boolean color;
+
+ width = hrWidth;
+ height= hrHeight;
+ depth = 8;
+ color = true;
+
+ if (gVars->HRrefNum != sysInvalidRefNum)
+ error = HRWinScreenMode ( gVars->HRrefNum, winScreenModeSet, &width, &height, &depth, &color );
+ else
+ error = WinScreenMode ( winScreenModeSet, &width, &height, &depth, &color );
+
+ /* high-resolution mode entered from here if no error */
+ if (error != errNone)
+ FrmCustomAlert(FrmErrorAlert,"Your device doesn't seems to support 256 colors mode.",0,0);
+ }
+ else
+ FrmCustomAlert(FrmErrorAlert,"This device doesn't seems to support\nHi-Res mode.",0,0);
+
+ return error;
+}
+
+static void AppStopHRMode() {
+ if (gVars->HRrefNum != sysInvalidRefNum) {
+ HRClose(gVars->HRrefNum);
+ //SysLibRemove(gVars->HRrefNum);
+ }
+}
+
+static Err AppStartCheckNotify() {
+ UInt32 romVersion;
+ Err err;
+
+ err = FtrGet(sysFtrCreator, sysFtrNumNotifyMgrVersion, &romVersion);
+ if (!err) {
+ UInt16 cardNo;
+ LocalID dbID;
+
+ err = SysCurAppDatabase(&cardNo, &dbID);
+ if (!err) {
+ SysNotifyRegister(cardNo, dbID, sysNotifyVolumeMountedEvent, NULL, sysNotifyNormalPriority, NULL);
+ SysNotifyRegister(cardNo, dbID, sysNotifyVolumeUnmountedEvent, NULL, sysNotifyNormalPriority, NULL);
+ }
+ }
+
+ return err;
+}
+
+static Err AppStartLoadSkin() {
+ Err err = errNone;
+
+ // if skin defined, check if the db still exists
+ if (gPrefs->skin.dbID) {
+ UInt32 type, creator;
+
+ // remember to check version for next revision of the skin
+ err = DmDatabaseInfo (gPrefs->skin.cardNo, gPrefs->skin.dbID, gPrefs->skin.nameP, 0, 0, 0, 0, 0, 0, 0,0, &type, &creator);
+ if (!err)
+ if (type != 'skin' || creator != appFileCreator)
+ err = dmErrInvalidParam;
+
+ if (err)
+ MemSet(&(gPrefs->skin),sizeof(SkinInfoType),0);
+ }
+
+ // No skin ? try to get the first one
+ if (!gPrefs->skin.dbID) {
+ DmSearchStateType stateInfo;
+
+ err = DmGetNextDatabaseByTypeCreator(true, &stateInfo, 'skin', appFileCreator, false, &gPrefs->skin.cardNo, &gPrefs->skin.dbID);
+ if (!err)
+ err = DmDatabaseInfo (gPrefs->skin.cardNo, gPrefs->skin.dbID, gPrefs->skin.nameP, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ }
+
+ if (err)
+ FrmCustomAlert(FrmErrorAlert,"No skin found.\nPlease install a skin and restart ScummVM.",0,0);
+
+ return err;
+}
+
+static Err AppStartCheckMathLib()
+{
+ Err error = errNone;
+
+ if ((error = SysLibFind(MathLibName, &MathLibRef)))
+ if (error == sysErrLibNotFound) // couldn't find lib
+ error = SysLibLoad( LibType, MathLibCreator, &MathLibRef);
+
+ if (!error) {// Now we can use lib. Executes Open library.
+ error = MathLibOpen(MathLibRef, MathLibVersion);
+ if (error)
+ FrmCustomAlert(FrmErrorAlert,"Can't open MathLib !",0,0);
+
+ } else {
+ FrmCustomAlert(FrmErrorAlert,"Can't find MathLib.\nPlease install it first.",0,0);
+ }
+
+ return error;
+}
+
+static void AppStopMathLib() {
+ UInt16 useCount;
+
+ if (MathLibRef != sysInvalidRefNum) {
+ MathLibClose(MathLibRef, &useCount);
+
+ if (!useCount)
+ SysLibRemove(MathLibRef);
+ }
+}
+
+
+static Err AppStart(void)
+{
+ UInt16 dataSize;
+ Err error;
+
+ // allocate global variables space
+ dataSize = sizeof(GlobalsDataType);
+ gVars = (GlobalsDataType *)MemPtrNew(dataSize);
+ MemSet(gVars, dataSize, 0);
+
+ gVars->indicator.on = 255;
+ gVars->indicator.off = 0;
+ gVars->HRrefNum = sysInvalidRefNum;
+
+ // allocate prefs space
+ dataSize = sizeof(GlobalsPreferenceType);
+ gPrefs = (GlobalsPreferenceType *)MemPtrNew(dataSize);
+ MemSet(gPrefs, dataSize, 0);
+
+ // Read the saved preferences / saved-state information.
+ if (PrefGetAppPreferences(appFileCreator, appPrefID, gPrefs, &dataSize, true) == noPreferenceFound)
+ {
+ UInt32 romVersion;
+ FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
+
+ gPrefs->volRefNum = sysInvalidRefNum;
+
+ gPrefs->autoOff = true;
+ gPrefs->vibrator = CheckVibratorExists();
+ gPrefs->debug = false;
+ gPrefs->stdPalette = (romVersion >= kOS5Version);
+
+ gPrefs->volume.speaker = 16;
+ gPrefs->volume.headphone = 16;
+
+ gPrefs->volume.master = 192;
+ gPrefs->volume.music = 192;
+ gPrefs->volume.sfx = 192;
+
+/* if (gPrefs->skin.nameP)
+ StrCopy(_skin.nameP, prefs.skin.nameP);
+
+ _skin.cardNo = prefs.skin.cardNo;
+ _skin.dbID = prefs.skin.dbID;
+
+ gVibrator = prefs.vibrator;
+ gAutoOff = prefs.autoOff;
+ ArrowManager.position = prefs.listPosition;*/
+ }
+
+ error = AppStartCheckMathLib();
+ if (error) return (error);
+
+ error = AppStartCheckHRmode();
+ if (error) return (error);
+
+ error = AppStartLoadSkin();
+ if (error) return (error);
+
+ error = GamOpenDatabase();
+ if (error) return (error);
+
+ if (gPrefs->volRefNum != sysInvalidRefNum) { // if volref prviously defined, check if it's a valid one
+ VolumeInfoType volInfo;
+ Err err = VFSVolumeInfo(gPrefs->volRefNum, &volInfo);
+ if (err)
+ gPrefs->volRefNum = sysInvalidRefNum;
+ }
+ else
+ gPrefs->volRefNum = parseCards(0); // get first volref
+
+ AppStartCheckNotify(); // not fatal error if not avalaible
+
+ return error;
+}
+
+/***********************************************************************
+ *
+ * FUNCTION: AppStop
+ *
+ * DESCRIPTION: Save the current state of the application.
+ *
+ * PARAMETERS: nothing
+ *
+ * RETURNED: nothing
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+static Err AppStopCheckNotify()
+{
+ UInt32 romVersion;
+ Err err;
+
+ err = FtrGet(sysFtrCreator, sysFtrNumNotifyMgrVersion, &romVersion);
+ if (!err) {
+ UInt16 cardNo;
+ LocalID dbID;
+
+ err = SysCurAppDatabase(&cardNo, &dbID);
+ if (!err) {
+ SysNotifyUnregister(cardNo, dbID, sysNotifyVolumeUnmountedEvent, sysNotifyNormalPriority);
+ SysNotifyUnregister(cardNo, dbID, sysNotifyVolumeMountedEvent, sysNotifyNormalPriority);
+ }
+ }
+
+ return err;
+}
+
+static void AppStop(void)
+{
+ // Write the saved preferences / saved-state information. This data
+ // will saved during a HotSync backup.
+/*
+ StrCopy(prefs.skin.nameP,gPrefsskin.nameP);
+ prefs.skin.cardNo = _skin.cardNo;
+ prefs.skin.dbID = _skin.dbID;
+
+ prefs.vibrator = iconState[IcnVibr].selected;
+ prefs.autoOff = iconState[IcnAOff].selected;
+ prefs.listPosition = ArrowManager.position;
+*/
+ SavePrefs();
+ AppStopCheckNotify();
+ AppStopMathLib();
+ AppStopHRMode();
+/*
+ // Close all the open forms.
+*/ FrmCloseAllForms();
+ GamCloseDatabase();
+
+ if (gVars)
+ MemPtrFree(gVars);
+
+ WinPalette(winPaletteSetToDefault, 0, 256, NULL);
+}
+
+
+/***********************************************************************
+ *
+ * FUNCTION: ScummVMPalmMain
+ *
+ * DESCRIPTION: This is the main entry point for the application.
+ *
+ * PARAMETERS: cmd - word value specifying the launch code.
+ * cmdPB - pointer to a structure that is associated with the launch code.
+ * launchFlags - word value providing extra information about the launch.
+ *
+ * RETURNED: Result of launch
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+static void AppLaunchCmdNotify(UInt16 LaunchFlags, SysNotifyParamType * pData)
+{
+ switch (pData->notifyType)
+ {
+ case sysNotifyVolumeMountedEvent:
+ pData->handled = true; // don't switch
+
+ if (gPrefs->volRefNum == sysInvalidRefNum) {
+ FormPtr frmP = FrmGetActiveForm();
+ VFSAnyMountParamType *notifyDetailsP = (VFSAnyMountParamType *)pData->notifyDetailsP;
+ gPrefs->volRefNum = notifyDetailsP->volRefNum;
+
+ if (frmP && gPrefs->volRefNum != sysInvalidRefNum) {
+ MenuEraseStatus(0);
+ FrmShowObject(frmP, FrmGetObjectIndex (frmP, MainMSBitMap));
+ }
+ }
+
+ case sysNotifyVolumeUnmountedEvent:
+ if (gPrefs->volRefNum == (UInt16)pData->notifyDetailsP) {
+ FormPtr frmP = FrmGetActiveForm();
+ gPrefs->volRefNum = sysInvalidRefNum;
+
+ if (frmP) {
+ MenuEraseStatus(0);
+ FrmShowObject(frmP, FrmGetObjectIndex (frmP, MainMSNoneBitMap));
+ }
+ }
+ break;
+ }
+}
+
+static UInt32 ScummVMPalmMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
+{
+ Err error;
+
+ error = RomVersionCompatible (kOurMinVersion, launchFlags);
+ if (error) return (error);
+
+ switch (cmd)
+ {
+ case sysAppLaunchCmdNotify:
+ AppLaunchCmdNotify(launchFlags, (SysNotifyParamType *) cmdPBP);
+ break;
+
+ case sysAppLaunchCmdNormalLaunch:
+ error = AppStart();
+ if (error)
+ goto end;
+
+ FrmGotoForm(MainForm);
+ AppEventLoop();
+end:
+ AppStop();
+ break;
+
+ default:
+ break;
+
+ }
+
+ return error;
+}
+/***********************************************************************
+ *
+ * FUNCTION: PilotMain
+ *
+ * DESCRIPTION: This is the main entry point for the application.
+ *
+ * PARAMETERS: cmd - word value specifying the launch code.
+ * cmdPB - pointer to a structure that is associated with the launch code.
+ * launchFlags - word value providing extra information about the launch.
+ * RETURNED: Result of launch
+ *
+ * REVISION HISTORY:
+ *
+ *
+ ***********************************************************************/
+
+UInt32 PilotMain( UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
+{
+ return ScummVMPalmMain(cmd, cmdPBP, launchFlags);
+}
diff --git a/backends/PalmOS/Src/saveslot.cpp b/backends/PalmOS/Src/saveslot.cpp
new file mode 100644
index 0000000000..b8bd5bdeed
--- /dev/null
+++ b/backends/PalmOS/Src/saveslot.cpp
@@ -0,0 +1,92 @@
+//#include "extras.h"
+#include <string.h>
+#include "scummsys.h"
+#include "saveload.h"
+
+#define MAX_BLOCK 64000
+
+enum SaveLoadState {
+ STATE_LOAD,
+ STATE_SAVE,
+ STATE_NONE
+};
+
+class SaveLoadData {
+ public:
+ SaveLoadData();
+
+ SaveLoadState _currentState;
+ byte * _readWriteData;
+ uint32 _readWritePos;
+ bool _needDump;
+};
+
+SaveLoadData current;
+
+SaveLoadData::SaveLoadData()
+{
+ _currentState = STATE_NONE;
+ _readWritePos = 0;
+ _needDump = false;
+}
+
+bool SerializerStream::fopen(const char *filename, const char *mode)
+{
+ if (current._currentState != STATE_NONE)
+ fclose();
+
+ context = ::fopen(filename, mode);
+ if (context != NULL) {
+ current._currentState = ((strcmp(mode,"rb")==0) ? STATE_LOAD : STATE_SAVE);
+ return true;
+ }
+
+ return false;
+}
+
+int SerializerStream::fread(void *buf, int size, int cnt)
+{
+ return ::fread(buf, size, cnt, (FILE *)context);
+}
+
+int SerializerStream::fwrite(void *buf, int size, int cnt) {
+
+ int fullsize = size*cnt;
+
+ if (current._currentState == STATE_SAVE && fullsize<=MAX_BLOCK)
+ {
+ if (!current._readWriteData)
+ current._readWriteData = (byte *)malloc(MAX_BLOCK);
+
+ if ((current._readWritePos+fullsize)>MAX_BLOCK) {
+ ::fwrite(current._readWriteData, current._readWritePos, 1, (FILE *)context);
+ current._readWritePos = 0;
+ current._needDump = false;
+ }
+
+ memcpy(current._readWriteData + current._readWritePos, buf, fullsize);
+ current._readWritePos += fullsize;
+ current._needDump = true;
+
+ return cnt;
+ }
+
+ return ::fwrite(buf, size, cnt, (FILE *)context);
+}
+
+
+void SerializerStream::fclose()
+{
+ if (current._needDump && current._readWriteData != NULL) {
+ if (current._currentState == STATE_SAVE)
+ ::fwrite(current._readWriteData, current._readWritePos, 1, (FILE *)context);
+
+ free(current._readWriteData);
+ current._readWriteData = NULL;
+ }
+
+ current._readWritePos = 0;
+ current._needDump = false;
+ current._currentState = STATE_NONE;
+ ::fclose((FILE *)context);
+} \ No newline at end of file
diff --git a/backends/PalmOS/Src/scumm_globals.h b/backends/PalmOS/Src/scumm_globals.h
new file mode 100644
index 0000000000..dc5f04e0c2
--- /dev/null
+++ b/backends/PalmOS/Src/scumm_globals.h
@@ -0,0 +1,50 @@
+#define GBVARS_DIGSTATEMUSICMAP_INDEX 0
+#define GBVARS_DIGSTATEMUSICTABLE_INDEX 1
+#define GBVARS_COMISTATEMUSICTABLE_INDEX 2
+#define GBVARS_COMISEQMUSICTABLE_INDEX 3
+#define GBVARS_DIGSEQMUSICTABLE_INDEX 4
+#define GBVARS_FTSTATEMUSICTABLE_INDEX 5
+#define GBVARS_FTSEQMUSICTABLE_INDEX 6
+#define GBVARS_GUIFONT_INDEX 7
+#define GBVARS_OLD256MIDIHACK_INDEX 8 // fix me : sizeof is used on scummvm
+#define GBVARS_CODEC37TABLE_INDEX 9
+#define GBVARS_CODEC47TABLE_INDEX 10
+#define GBVARS_TRANSITIONEFFECTS_INDEX 11
+
+#define GBVARS_SIMON1SETTINGS_INDEX 0
+#define GBVARS_SIMON1AMIGASETTINGS_INDEX 1
+#define GBVARS_SIMON1DEMOSETTINGS_INDEX 2
+#define GBVARS_SIMON2WINSETTINGS_INDEX 3
+#define GBVARS_SIMON2MACSETTINGS_INDEX 4
+#define GBVARS_SIMON2DOSSETTINGS_INDEX 5
+#define GBVARS_HEBREWVIDEOFONT_INDEX 6
+#define GBVARS_SPANISHVIDEOFONT_INDEX 7
+#define GBVARS_VIDEOFONT_INDEX 8
+
+#define GBVARS_SCUMM 0
+#define GBVARS_SIMON 1
+#define GBVARS_SKY 2
+
+#define GSETPTR(var,index,format,id) var = (format *)GBGetRecord(index,id);
+#define GRELEASEPTR(index,id) GBReleaseRecord(index,id);
+
+void *GBGetRecord(UInt16 index, UInt16 id);
+void GBReleaseRecord(UInt16 index, UInt16 id);
+
+void IMuseDigital_initGlobals();
+void IMuseDigital_releaseGlobals();
+
+void Simon_initGlobals();
+void Simon_releaseGlobals();
+
+void NewGui_initGlobals();
+void NewGui_releaseGlobals();
+
+void Resource_initGlobals();
+void Resource_releaseGlobals();
+
+void Codec47_initGlobals();
+void Codec47_releaseGlobals();
+
+void Gfx_initGlobals();
+void Gfx_releaseGlobals(); \ No newline at end of file
diff --git a/backends/PalmOS/Src/skin.h b/backends/PalmOS/Src/skin.h
new file mode 100644
index 0000000000..c187142eb9
--- /dev/null
+++ b/backends/PalmOS/Src/skin.h
@@ -0,0 +1,55 @@
+#define skinList 500
+#define skinColors 600
+//#define skinPalette 510
+#define skinButtonNone 0
+
+#define skinSliderUpArrow 2000
+#define skinSliderDownArrow 2100
+
+#define skinButtonGameParams 3000
+#define skinButtonGameAdd 3100
+#define skinButtonGameEdit 3200
+#define skinButtonGameDelete 4000
+#define skinButtonGameStart 7000
+
+#define skinBackgroundImageTop 1000
+#define skinBackgroundImageBottom 1010
+///
+
+
+#define skinToolsBackground 1100
+
+#define skinListUpArrowNormal 1500
+#define skinListUpArrowOver 1510
+#define skinListUpArrowDisabled 1540
+
+#define skinListDownArrowNormal 1800
+#define skinListDownArrowOver 1810
+#define skinListDownArrowDisabled 1840
+
+#define skinButtonGameInfoNormal 2000
+#define skinButtonGameInfoOver 2010
+#define skinButtonGameInfoDisabled 2040
+
+#define skinButtonGameParamNormal 3000
+#define skinButtonGameParamOver 3010
+
+#define skinButtonGameDeleteNormal 4000
+#define skinButtonGameDeleteOver 4010
+#define skinButtonGameDeleteDisabled 4040
+
+#define skinButtonVibratorNormal 5000
+#define skinButtonVibratorOver 5010
+#define skinButtonVibratorSelected 5020
+#define skinButtonVibratorSelectedOver 5030
+#define skinButtonVibratorDisabled 5040
+
+
+#define skinButtonSleepNormal 6000
+#define skinButtonSleepOver 6010
+#define skinButtonSleepSelected 6020
+#define skinButtonSleepSelectedOver 9030
+
+#define skinButtonPlayNormal 7000
+#define skinButtonPlayOver 7010
+#define skinButtonPlayDisabled 7040 \ No newline at end of file
diff --git a/backends/PalmOS/Src/vibrate.h b/backends/PalmOS/Src/vibrate.h
new file mode 100644
index 0000000000..73b8a6104a
--- /dev/null
+++ b/backends/PalmOS/Src/vibrate.h
@@ -0,0 +1,61 @@
+/**********************************************************************
+** **
+** vibrate.h **
+** **
+** Definitions for setting/retrieving the state of the vibrator on **
+** PalmOS 4.x devices. These calls are not officially supported by **
+** Palm Inc and subsidiaries. It is not guaranteed that these calls **
+** will work at all or at least the same on every device. YOU ARE **
+** USING THESE ENTIRELY ON YOUR VERY OWN RISK ! **
+** **
+** Please send corrections to dseifert@dseifert.com **
+**********************************************************************/
+
+#include <PalmOS.h>
+
+/* HwrVibrateAttributes takes three arguments:
+** Boolean set Should the setting be set (1) or retrieved (0)
+** UInt32 setting what should be set
+** void* value pointer to the value to set, or to store the
+** retrieved setting
+*/
+
+Err HwrVibrateAttributes(Boolean set, UInt32 setting, void *value)
+ SYS_TRAP(sysTrapHwrVibrateAttributes);
+
+/* to determine whether the vibrator is supported on a specific device, you
+** need to make sure that you are running on PalmOS 4.x (so that the
+** trap exists), that the attention manager exists and you need to check
+** whether HwrVibrateAttributes(0, 1, &active) returns an error code of
+** 0. ('active' is a Boolean).
+*/
+
+
+/***************************************************************/
+/* For the second parameter, the following defines can be used */
+/***************************************************************/
+
+/* *value points to a Boolean stating the state of the vibrator */
+#define kHwrVibrateActive 1
+
+/* *value points to a UInt16, specifying the length of one cycle.
+** value is in ticks (1/100 seconds) */
+#define kHwrVibrateRate 2
+
+/* *value points to a UInt32, specifying the pattern of vibrating
+**
+** example:
+** 0xFFFFFFFF stay on, no vibrating
+** 0x0F0F0F0F vibrate four times in equal intervals
+** 0xAAAAAAAA vibrate really fast (not recommended)
+** 0x0F0F0000 vibrate twice, then pause
+*/
+#define kHwrVibratePattern 3
+
+/* *value points to a UInt16, specifying the delay between two
+** cycles in ticks */
+#define kHwrVibrateDelay 4
+
+/* *value points to a UInt16 specifying the amount of repeats. */
+#define kHwrVibrateRepeatCount 5
+
diff --git a/backends/fs/palmos/palmos-fs.cpp b/backends/fs/palmos/palmos-fs.cpp
new file mode 100644
index 0000000000..5f634a8ca9
--- /dev/null
+++ b/backends/fs/palmos/palmos-fs.cpp
@@ -0,0 +1,155 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2002 The ScummVM project
+ *
+ * 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.
+ *
+ * $Header$
+ */
+
+#if defined(__PALMOS_TRAPS__)
+
+#include "../fs.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+/*
+ * Implementation of the ScummVM file system API based on PalmOS VFS API.
+ */
+
+class PalmOSFilesystemNode : public FilesystemNode {
+protected:
+ String _displayName;
+ bool _isDirectory;
+ bool _isValid;
+ bool _isPseudoRoot;
+ String _path;
+
+public:
+ PalmOSFilesystemNode();
+ PalmOSFilesystemNode(const Char *path);
+ PalmOSFilesystemNode(const PalmOSFilesystemNode *node);
+
+ virtual String displayName() const { return _displayName; }
+ virtual bool isValid() const { return _isValid; }
+ virtual bool isDirectory() const { return _isDirectory; }
+ virtual String path() const { return _path; }
+
+ virtual FSList *listDir(ListMode) const;
+ virtual FilesystemNode *parent() const;
+ virtual FilesystemNode *clone() const { return new PalmOSFilesystemNode(this); }
+
+private:
+ static void addFile (FSList* list, ListMode mode, const Char *base, FileInfoType* find_data);
+};
+
+void PalmOSFilesystemNode::addFile (FSList* list, ListMode mode, const char *base, FileInfoType* find_data) {
+ PalmOSFilesystemNode entry;
+ bool isDirectory;
+
+ isDirectory = (find_data->attributes & vfsFileAttrDirectory);
+
+ if ((!isDirectory && mode == kListDirectoriesOnly) ||
+ (isDirectory && mode == kListFilesOnly))
+ return;
+
+ entry._isDirectory = isDirectory;
+ entry._displayName = find_data->nameP;
+ entry._path = base;
+ entry._path += find_data->nameP;
+ if (entry._isDirectory)
+ entry._path += "/";
+
+ entry._isValid = true;
+ entry._isPseudoRoot = false;
+ list->push_back(entry);
+}
+
+FilesystemNode *FilesystemNode::getRoot() {
+ return new PalmOSFilesystemNode();
+}
+
+PalmOSFilesystemNode::PalmOSFilesystemNode() {
+ _isDirectory = true;
+ _displayName = "Root";
+ _isValid = true;
+ _path = "/";
+ _isPseudoRoot = true;
+}
+
+PalmOSFilesystemNode::PalmOSFilesystemNode(const PalmOSFilesystemNode *node) {
+ _displayName = node->_displayName;
+ _isDirectory = node->_isDirectory;
+ _isValid = node->_isValid;
+ _isPseudoRoot = node->_isPseudoRoot;
+ _path = node->_path;
+}
+
+FSList *PalmOSFilesystemNode::listDir(ListMode mode) const {
+
+ FSList *myList = new FSList();
+ Err e;
+ Char nameP[256];
+ FileInfoType desc;
+ FileRef handle;
+ UInt32 dirIterator = expIteratorStart;
+
+ desc.nameP = nameP;
+ desc.nameBufLen = 256;
+ e = VFSFileOpen(gVars->volRefNum, _path.c_str(), vfsModeRead, &handle);
+
+ if (e)
+ return myList;
+
+ while(dirIterator != expIteratorStop) {
+ e = VFSDirEntryEnumerate(handle, &dirIterator, &desc);
+ if (!e) {
+ addFile(myList, mode, _path.c_str(), &desc);
+ }
+ }
+
+ VFSFileClose(handle);
+
+ return myList;
+}
+
+const char *lastPathComponent(const ScummVM::String &str) {
+ const char *start = str.c_str();
+ const char *cur = start + str.size() - 2;
+
+ while (cur > start && *cur != '/') {
+ --cur;
+ }
+
+ return cur+1;
+}
+
+FilesystemNode *PalmOSFilesystemNode::parent() const {
+
+ PalmOSFilesystemNode *p = new PalmOSFilesystemNode();
+
+ if (!_isPseudoRoot) {
+ const char *start = _path.c_str();
+ const char *end = lastPathComponent(_path);
+
+ p->_path = String(start, end - start);
+ p->_isValid = true;
+ p->_isDirectory = true;
+ p->_displayName = lastPathComponent(p->_path);
+ p->_isPseudoRoot =(p->_path == "/");
+ }
+ return p;
+}
+
+#endif // __PALMOS_TRAPS__