1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
|
/* ScummVM - Scumm Interpreter
* Copyright (C) 2001 Ludvig Strigeus
* Copyright (C) 2001-2003 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$
*
*/
#include "backends/intern.h"
#include "scumm.h"
#include "common/scaler.h"
#include "start.h"
#include "palm.h"
#include "vibrate.h"
#include "cd_msa.h"
//#undef DISABLE_TAPWAVE
#ifndef DISABLE_TAPWAVE
#include "tapwave.h"
//#include "cd_zodiac.h"
#endif
#define EXITDELAY (500) // delay to exit : calc button : double tap 1/500 sec
#define ftrOverlayPtr (1000)
#define ftrBackupPtr (1001)
//#define SND_BLOCK (8192)
#define SND_BLOCK (3072)
OSystem *OSystem_PALMOS::create(UInt16 gfx_mode, bool full_screen) {
OSystem_PALMOS *syst = new OSystem_PALMOS();
syst->_mode = gfx_mode;
syst->_vibrate = gVars->vibrator;
syst->_fullscreen = (full_screen && (gVars->options & optHasWideMode));
return syst;
}
OSystem *OSystem_PALMOS_create(int gfx_mode, bool full_screen) {
return OSystem_PALMOS::create(gfx_mode, full_screen);
}
void OSystem_PALMOS::set_palette(const byte *colors, uint start, uint num) {
if (_quitCount)
return;
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;
}
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
};
// init screens
switch(_mode) {
case GFX_FLIPPING:
gVars->screenLocked = true;
_offScreenP = WinScreenLock(winLockErase) + _screenOffset.addr;
_screenP = _offScreenP;
_offScreenH = WinGetDisplayWindow();
_screenH = _offScreenH;
_renderer_proc = &update_screen__flipping;
break;
case GFX_WIDE:
case GFX_DOUBLEBUFFER:
_screenH = WinGetDisplayWindow();
_offScreenH = WinCreateOffscreenWindow(_screenWidth, _screenHeight,screenFormat, &e);
_offScreenP = (byte *)(BmpGetBits(WinGetBitmap(_offScreenH)));
if (_mode == GFX_WIDE) {
gVars->screenLocked = true;
_screenP = WinScreenLock(winLockErase) + _screenOffset.addr;
_renderer_proc = &update_screen__wide;
} else {
_screenP = (byte *)(BmpGetBits(WinGetBitmap(_screenH))) + _screenOffset.addr;
_renderer_proc = &update_screen__dbuffer;
_offScreenPitch = _screenWidth;
}
break;
case GFX_NORMAL:
default:
_offScreenH = WinGetDisplayWindow();
_screenH = _offScreenH;
_offScreenP = (byte *)(BmpGetBits(WinGetBitmap(_offScreenH))) + _screenOffset.addr;
_screenP = _offScreenP;
_renderer_proc = &update_screen__direct;
break;
}
// palette for preload dialog
set_palette(startupPalette,0,16);
// try to allocate on storage heap
FtrPtrNew(appFileCreator, ftrOverlayPtr, _screenWidth * _screenHeight, (void **)&_tmpScreenP);
FtrPtrNew(appFileCreator, ftrBackupPtr, _screenWidth * _screenHeight, (void **)&_tmpBackupP);
// failed ? dynamic heap
if (!_tmpScreenP) _tmpScreenP = (byte *)malloc(_screenWidth * _screenHeight);
if (!_tmpBackupP) _tmpBackupP = (byte *)malloc(_screenWidth * _screenHeight);
}
void OSystem_PALMOS::unload_gfx_mode() {
switch (_mode)
{
case GFX_FLIPPING:
WinScreenUnlock();
break;
case GFX_WIDE:
WinScreenUnlock();
// continue to GFX_DOUBLEBUFFER
case GFX_DOUBLEBUFFER:
WinDeleteWindow(_offScreenH,false);
break;
}
if (_tmpScreenP)
if (MemPtrDataStorage(_tmpScreenP))
FtrPtrFree(appFileCreator, ftrOverlayPtr);
else
free(_tmpScreenP);
if (_tmpBackupP)
if (MemPtrDataStorage(_tmpBackupP))
FtrPtrFree(appFileCreator, ftrBackupPtr);
else
free(_tmpBackupP);
}
void OSystem_PALMOS::init_size(uint w, uint h) {
_screenWidth = w;
_screenHeight = h;
_offScreenPitch = gVars->screenPitch; // direct screen / flipping use this, set later if double buffer
_screenPitch = gVars->screenPitch;
_overlayVisible = false;
_quitCount = 0;
if (OPTIONS(optIsCollapsible))
SysSetOrientationTriggerState(sysOrientationTriggerDisabled);
// check HiRes+
if (_mode == GFX_WIDE) {
if (gVars->slkRefNum != sysInvalidRefNum) {
if (!(w == 320 && h == 200 && gVars->slkVersion != vskVersionNum3)) { // only for 320x200 games and not for UX50 at this time
warning("Wide display not avalaible for this game, switching to GFX_NORMAL mode.");
_mode = GFX_NORMAL;
}
} else {
warning("HiRes+ not avalaible on this device, switching to GFX_NORMAL mode.");
_mode = GFX_NORMAL;
}
}
if (_fullscreen || _mode == GFX_WIDE) {
// Sony wide
if (gVars->slkRefNum != sysInvalidRefNum) {
if (gVars->slkVersion == vskVersionNum1) {
SilkLibEnableResize (gVars->slkRefNum);
SilkLibResizeDispWin(gVars->slkRefNum, silkResizeMax);
SilkLibDisableResize(gVars->slkRefNum);
} else {
VskSetState(gVars->slkRefNum, vskStateEnable, (gVars->slkVersion != vskVersionNum3 ? vskResizeVertically : vskResizeHorizontally));
VskSetState(gVars->slkRefNum, vskStateResize, vskResizeNone);
VskSetState(gVars->slkRefNum, vskStateEnable, vskResizeDisable);
}
// Tapwave Zodiac and other DIA compatible devices
} else if (OPTIONS(optHasWideMode)) {
/* UInt32 width = hrWidth;
UInt32 height= hrHeight;
UInt32 depth = 16;
Boolean color = true;
Err e;
e = WinScreenMode (winScreenModeSet, &width, &height, &depth, &color );
*/ //SysSetOrientation(sysOrientationLandscape);
PINSetInputAreaState(pinInputAreaClosed);
StatHide();
}
}
if (_mode == GFX_WIDE) {
_screenOffset.x = 0;
_screenOffset.y = 10;
_screenOffset.addr = _screenOffset.y;
} else {
_screenOffset.x = ((_fullscreen ? gVars->screenFullWidth : gVars->screenWidth) - w) >> 1;
_screenOffset.y = ((_fullscreen ? gVars->screenFullHeight : gVars->screenHeight) - h) >> 1;
_screenOffset.addr = _screenOffset.x + _screenOffset.y * _screenPitch;
}
set_mouse_pos(200,150);
_currentPalette = (RGBColorType*)calloc(sizeof(RGBColorType), 256);
_mouseBackupP = (byte*)malloc(MAX_MOUSE_W * MAX_MOUSE_H);
load_gfx_mode();
}
void OSystem_PALMOS::copy_rect(const byte *buf, int pitch, int x, int y, int w, int h) {
/* Clip the coordinates */
if (x < 0) {
w += x;
buf -= x;
x = 0;
}
if (y < 0) {
h += y;
buf -= y * pitch;
y = 0;
}
if (w > _screenWidth - x) {
w = _screenWidth - x;
}
if (h > _screenHeight - y) {
h = _screenHeight - y;
}
if (w <= 0 || h <= 0)
return;
/* FIXME: undraw mouse only if the draw rect intersects with the mouse rect */
if (_mouseDrawn)
undraw_mouse();
byte *dst = _offScreenP + y * _offScreenPitch + x;
if (_offScreenPitch == pitch && pitch == w) {
memcpy (dst, buf, h * w);
} else {
do {
memcpy(dst, buf, w);
dst += _offScreenPitch;
buf += pitch;
} while (--h);
}
}
// only avalaible for 320x200 games, so use values instead of vars
#define WIDE_PITCH 320
#define WIDE_HALF_HEIGHT 100 // 200 / 2
void OSystem_PALMOS::update_screen__wide() {
Coord x, y;
UInt32 next = _screenOffset.y << 1;
UInt8 *dst = _screenP;
UInt8 *src1 = _offScreenP + WIDE_PITCH - 1;
UInt8 *src2 = src1;
for (x = 0; x < _screenWidth >> 1; x++)
{
for (y = 0; y < WIDE_HALF_HEIGHT; y++)
{
*dst++ = *src1;
src1 += WIDE_PITCH;
*dst++ = *src1;
*dst++ = *src1;
src1 += WIDE_PITCH;
}
src1 = --src2;
dst += next;
for (y = 0; y < WIDE_HALF_HEIGHT; y++)
{
*dst++ = *src1;
src1 += WIDE_PITCH;
*dst++ = *src1;
*dst++ = *src1;
src1 += WIDE_PITCH;
}
src1 = --src2;
dst += next;
MemMove(dst, dst - WIDE_PITCH, 300); // 300 = 200 x 1.5
dst += WIDE_PITCH;
}
WinScreenUnlock();
_screenP = WinScreenLock(winLockCopy) + _screenOffset.addr;
}
void OSystem_PALMOS::update_screen__flipping() {
RectangleType r, dummy;
UInt8 *screen;
UInt32 size = _screenWidth * _screenHeight + 6400; // 10 pix top and bottom border, see TODO
Boolean shaked = false;
UInt32 move = 0;
// shake screen
if (_current_shake_pos != _new_shake_pos) {
if (_useHRmode) {
RctSetRectangle(&r, _screenOffset.x, _screenOffset.y - _new_shake_pos, _screenWidth, _screenHeight + (_new_shake_pos << 2));
HRWinScrollRectangle(gVars->HRrefNum, &r, winDown, _new_shake_pos, &dummy);
} else {
// TODO : need to change this to line copy if palm give us an HiRes+ device and change 3200/6400 value to the good one depending on the screen pitch
move = (_new_shake_pos * _screenWidth);
screen = _offScreenP - 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();
_offScreenP = WinScreenLock(winLockCopy) + _screenOffset.addr;
_screenP = _offScreenP;
if (shaked) {
if (_useHRmode) {
HRWinScrollRectangle(gVars->HRrefNum, &r, winUp, _new_shake_pos, &dummy);
} else {
// TODO : need to change this to line copy if palm give us an HiRes+ device
screen = _offScreenP - 3200;
MemMove(screen, screen + move, size);
}
}
}
void OSystem_PALMOS::update_screen__dbuffer() {
UInt32 move = 0;
UInt32 size = _screenWidth * _screenHeight;
// shake screen
if (_current_shake_pos != _new_shake_pos) {
move = (_new_shake_pos * _screenPitch);
// copy clear bottom of the screen to top to cover shaking image
if (_screenPitch == _screenWidth) {
MemMove(_screenP, _screenP + size , move);
MemMove(_screenP + move, _offScreenP, size - move);
} else if (_new_shake_pos != 0) {
UInt16 h = _new_shake_pos;
byte *src = _screenP + _screenPitch * _screenHeight;
byte *dst = _screenP;
do {
memcpy(dst, src, _screenWidth);
dst += _screenPitch;
src += _screenPitch;
} while (--h);
}
if (_vibrate) {
Boolean active = (_new_shake_pos >= 3);
HwrVibrateAttributes(1, kHwrVibrateActive, &active);
}
_current_shake_pos = _new_shake_pos;
}
// update screen
if (_screenPitch == _screenWidth) {
MemMove(_screenP + move, _offScreenP, size - move);
} else {
#ifndef DISABLE_TAPWAVE
Err e;
TwGfxSurfaceType *src;
TwGfxSurfaceType *dst;
TwGfxRectType d = {0,0,480,300}, s = {0,0,320,200};
TwGfxSurfaceInfoType t;
TwGfxPointType dd = {0,0};
t.size = sizeof(TwGfxSurfaceInfoType);
t.width = 320;
t.height = 200;
t.rowBytes = 640;
t.location = twGfxLocationAcceleratorMemory;
t.pixelFormat = twGfxPixelFormatRGB565_LE;
/*
ColorTableType table;
RGBColorType *rgb = ColorTableEntries (table);
table.numEntries = 256;
*rgb = _currentPalette;
*/
//BitmapType *newBmp =
TwGfxType *gfx;
e = TwGfxOpen(&gfx, NULL);
e = TwGfxAllocSurface(gfx, &src, &t);
e = TwGfxDrawPalmBitmap(src, &dd, WinGetBitmap(_offScreenH));
e = TwGfxGetPalmDisplaySurface(gfx, &dst);
e = TwGfxStretchBlt(dst, &d, src, &s);
e = TwGfxFreeSurface(src);
e = TwGfxClose(gfx);
#endif
//#if 0
byte *src = _offScreenP;
byte *dst = _screenP + move;
UInt16 h = _screenHeight - _new_shake_pos;
do {
memcpy(dst, src, _screenWidth);
dst += _screenPitch;
src += _offScreenPitch;
} while (--h);
//#endif
}
}
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;
}
}
#define MD_NONE 0
#define MD_CTRL 1
#define MD_ALT 2
static void drawKeyState(OSystem_PALMOS *sys, UInt8 state) {
UInt8 i,j;
UInt16 bmpID = 3000 + state - 1;
MemHandle hTemp;
BitmapType *bmTemp;
UInt32 *bmData;
UInt32 pitch = sys->_screenPitch;
UInt8 *scr = sys->_screenP + sys->_screenPitch * (sys->get_height() + 2) + 2;
hTemp = DmGetResource(bitmapRsc,bmpID);
if (hTemp) { // draw
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 += pitch - 32;
bmData++;
}
MemPtrUnlock(bmTemp);
DmReleaseResource(hTemp);
} else { // undraw
for (i = 0; i < 7; i++) {
for (j = 0; j < 32; j++) {
*scr++ = gVars->indicator.off;
}
scr += pitch - 32;
}
}
}
static void drawNumPad(OSystem_PALMOS *sys, UInt8 color) {
UInt8 i,j,k;
UInt16 bmpID = 3010; // numPadBitmap 64x34
MemHandle hTemp;
BitmapType *bmTemp;
UInt32 *bmData;
UInt32 pitch = sys->_screenPitch;
UInt8 *scr = sys->_screenP + sys->_screenPitch * (sys->get_height() + 2);
scr += (sys->get_width() >> 1) - 32;
hTemp = DmGetResource(bitmapRsc,bmpID);
if (hTemp) {
bmTemp = (BitmapType *)MemHandleLock(hTemp);
bmData = (UInt32 *)BmpGetBits(bmTemp);
for (i = 0; i < 34; i++) {
for (k = 0; k < 2; k++) {
for (j = 0; j < 32; j++) {
if (*bmData & (1 << (31-j)))
*scr++ = color;
else
*scr++ = 0;
}
bmData++;
}
scr += pitch - 64;
}
MemPtrUnlock(bmTemp);
DmReleaseResource(hTemp);
}
}
void OSystem_PALMOS::update_screen() {
if(_quitCount)
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) {
UInt8 oldCol;
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;
oldCol = gVars->indicator.on;
gVars->indicator.on = RGBToColor(0,255,0);
if (oldCol != gVars->indicator.on) {
// redraw if needed
if (_lastKeyModifier)
drawKeyState(this, _lastKeyModifier);
if(_useNumPad)
drawNumPad(this, gVars->indicator.on);
}
}
if (_overlayVisible) {
byte *src = _tmpScreenP;
byte *dst = _offScreenP;
UInt16 h = _screenHeight;
do {
memcpy(dst, src, _screenWidth);
dst += _offScreenPitch;
src += _screenWidth;
} while (--h);
}
// redraw the screen
((this)->*(_renderer_proc))();
}
bool OSystem_PALMOS::show_mouse(bool visible) {
if (_mouseVisible == visible)
return visible;
bool last = _mouseVisible;
_mouseVisible = visible;
if (visible)
draw_mouse();
else
undraw_mouse();
return last;
}
void OSystem_PALMOS::warp_mouse(int x, int y) {}
void OSystem_PALMOS::set_mouse_pos(int x, int y) {
if (x != _mouseCurState.x || y != _mouseCurState.y) {
_mouseCurState.x = x;
_mouseCurState.y = y;
undraw_mouse();
}
}
void OSystem_PALMOS::set_mouse_cursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y) {
_mouseCurState.w = w;
_mouseCurState.h = h;
_mouseHotspotX = hotspot_x;
_mouseHotspotY = hotspot_y;
_mouseDataP = (byte*)buf;
undraw_mouse();
}
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);
}
}
uint32 OSystem_PALMOS::get_msecs() {
uint32 ticks = TimGetTicks();
ticks *= (1000/SysTicksPerSecond());
return ticks;
}
void OSystem_PALMOS::delay_msecs(uint msecs) {
UInt32 delay = (SysTicksPerSecond() * msecs) / 1000;
if (delay)
SysTaskDelay(delay);
}
void OSystem_PALMOS::set_timer(TimerProc callback, int timer) {
if (callback != NULL) {
_timer.duration = timer;
_timer.nextExpiry = get_msecs() + timer;
_timer.callback = callback;
_timer.active = true;
} else {
_timer.active = false;
}
}
/* Mutex handling */
OSystem::MutexRef OSystem_PALMOS::create_mutex() {return NULL;}
void OSystem_PALMOS::lock_mutex(MutexRef mutex) {}
void OSystem_PALMOS::unlock_mutex(MutexRef mutex) {}
void OSystem_PALMOS::delete_mutex(MutexRef mutex) {}
void OSystem_PALMOS::SimulateArrowKeys(Event *event, Int8 iHoriz, Int8 iVert) {
Int16 x = _mouseCurState.x;
Int16 y = _mouseCurState.y;
if (_lastKeyPressed != -1) {
_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 >= _screenWidth ) ? _screenWidth - 1 : x;
y = (y < 0 ) ? 0 : y;
y = (y >= _screenHeight ) ? _screenHeight - 1 : y;
event->event_code = EVENT_MOUSEMOVE;
event->mouse.x = x;
event->mouse.y = y;
set_mouse_pos(x, y);
}
static void getCoordinates(EventPtr event, Boolean wide, Coord *x, Coord *y) {
if (wide) {
*y = (event->screenX << 2) / 3;
*x = 320 - (event->screenY << 2) / 3 - 1; // wide only for 320x200, so ...
} else {
*x = event->screenX << 1;
*y = event->screenY << 1;
}
}
bool OSystem_PALMOS::poll_event(Event *event) {
EventType ev;
Boolean handled;
UInt32 current_msecs;
UInt32 keyCurrentState;
Coord x, y;
if(_quitCount) {
if (_quitCount >= 10)
SysReset();
else
_quitCount++;
event->event_code = EVENT_QUIT;
exit(0); // resend an exit event
return false;
}
current_msecs = get_msecs();
// sound handler
if(_sound.active)
check_sound();
// timer handler
// if (_timer.active)
// _timer.callback(_timer.duration);
if (_timer.active && (current_msecs >= _timer.nextExpiry)) {
_timer.duration = _timer.callback(_timer.duration);
_timer.nextExpiry = current_msecs + _timer.duration;
}
/*
if (_timer.active) {
if (current_msecs - _timer.next_expiry >= 10)
_timer.sleep = false;
if (!_timer.sleep) {
_timer.sleep = true;
while (_timer.next_expiry < current_msecs) {
_timer.next_expiry += 10;
_timer.duration = _timer.callback(_timer.duration);
}
}
}
*/
if (_selfQuit)
quit();
for(;;) {
EvtGetEvent(&ev, evtNoWait);
// check for hardkey repeat
keyCurrentState = KeyCurrentState();
if (_lastKeyPressed != -1 && _lastKeyPressed != vchrCalc &&
!( (keyCurrentState & keyBitHard2) ||
(keyCurrentState & keyBitPageUp) ||
(keyCurrentState & keyBitPageDown) ||
(keyCurrentState & keyBitHard3)
)
) {
_lastKeyPressed = -1;
}
if (ev.eType == nilEvent)
return false;
if (ev.eType == keyDownEvent) {
switch (ev.data.keyDown.chr) {
case vchrLaunch:
_lastKeyPressed = -1;
event->event_code = EVENT_KEYDOWN;
event->kbd.keycode = 27;
event->kbd.ascii = 27;
event->kbd.flags = 0;
return true;
case vchrJogPushRepeat:
case vchrMenu:
_lastKeyPressed = -1;
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)) {
event->event_code = EVENT_QUIT;
_selfQuit = true;
}
_exit_delay = get_msecs();
_lastKeyPressed = vchrCalc;
return true;
// wheel
case vchrJogUp:
event->event_code = EVENT_WHEELUP;
return true;
case vchrJogDown:
event->event_code = EVENT_WHEELDOWN;
return true;
// if hotsync pressed
case vchrHardCradle:
case vchrHardCradle2:
_selfQuit = true;
}
// if (gVars->options & opt5WayNavigator)*/ {
// } else {
// mouse emulation for device without 5-Way navigator
switch (ev.data.keyDown.chr) {
case vchrJogBack:
case vchrHard4: // right button
event->event_code = EVENT_RBUTTONDOWN;
event->mouse.x = _mouseCurState.x;
event->mouse.y = _mouseCurState.y;
_lastKeyPressed = -1;
return true;
case vchrJogPush:
case vchrHard1: // left button
event->event_code = EVENT_LBUTTONDOWN;
event->mouse.x = _mouseCurState.x;
event->mouse.y = _mouseCurState.y;
_lastKeyPressed = -1;
return true;
case vchrHard2: // move left
SimulateArrowKeys(event, -1, 0);
_lastKeyPressed = vchrHard2;
return true;
case vchrPageUp: // move up
SimulateArrowKeys(event, 0, -1);
_lastKeyPressed = vchrPageUp;
return true;
case vchrPageDown: // move down
SimulateArrowKeys(event, 0, 1);
_lastKeyPressed = vchrPageDown;
return true;
case vchrHard3: // move right
SimulateArrowKeys(event, 1, 0);
_lastKeyPressed = vchrHard3;
return true;
// }
}
}
// 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, auto-off, etc...
if (!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 == vchrCommand && (ev.data.keyDown.modifiers & commandKeyMask)) {
_lastKeyModifier++;
_lastKeyModifier %= 3;
drawKeyState(this, _lastKeyModifier);
} else {
byte b = 0;
if (_lastKeyModifier == MD_CTRL) b = KBD_CTRL;
if (_lastKeyModifier == MD_ALT) b = KBD_ALT;
if ((ev.data.keyDown.chr == 'z' && b == KBD_CTRL) || (b == KBD_ALT && ev.data.keyDown.chr == 'x')) {
event->event_code = EVENT_QUIT;
_selfQuit = true;
} else if (ev.data.keyDown.chr == 'n' && b == KBD_CTRL) {
UInt8 *scr = _screenP + _screenWidth * (_screenHeight + 2);
_useNumPad = !_useNumPad;
drawNumPad(this, _useNumPad ? gVars->indicator.on : 0);
}
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(this, _lastKeyModifier);
}
return true;
}
case penMoveEvent:
getCoordinates(&ev, (_mode == GFX_WIDE), &x, &y);
if ((y - _screenOffset.y) > _screenHeight || (y - _screenOffset.y) < 0 || (x - _screenOffset.x) > _screenWidth || (x - _screenOffset.x) < 0)
return true;
if (_lastEvent != penMoveEvent && (abs(y - event->mouse.y) <= 2 || abs(x - event->mouse.x) <= 2)) // move only if
return true;
_lastEvent = penMoveEvent;
event->event_code = EVENT_MOUSEMOVE;
event->mouse.x = x - _screenOffset.x;
event->mouse.y = y - _screenOffset.y;
set_mouse_pos(event->mouse.x, event->mouse.y);
return true;
case penDownEvent:
getCoordinates(&ev, (_mode == GFX_WIDE), &x, &y);
if (_useNumPad) {
Coord x2 = _screenOffset.x + (_screenWidth >> 1) - 20; // - 64 / 2 + 12
Coord y2 = _screenOffset.y + _screenHeight + 2;
if (y >= y2 && y < (y2 + 34) && x >= x2 && x < (x2 + 64)) { // numpad location
UInt8 key = '1';
key += 9 - ( (3 - ((x - x2) / 13)) + (3 * ((y - y2) / 11)) );
_lastEvent = keyDownEvent;
_lastKeyPressed = -1;
event->event_code = EVENT_KEYDOWN;
event->kbd.keycode = key;
event->kbd.ascii = key;
event->kbd.flags = 0;
return true;
}
}
_lastEvent = penDownEvent;
if ((y - _screenOffset.y) > _screenHeight || (y - _screenOffset.y) < 0 || (x - _screenOffset.x) > _screenWidth || (x - _screenOffset.x) < 0)
return true;
event->event_code = EVENT_LBUTTONDOWN;
event->mouse.x = x - _screenOffset.x;
event->mouse.y = y - _screenOffset.y;
set_mouse_pos(event->mouse.x, event->mouse.y);
return true;
case penUpEvent:
getCoordinates(&ev, (_mode == GFX_WIDE), &x, &y);
event->event_code = EVENT_LBUTTONUP;
if ((y - _screenOffset.y) > _screenHeight || (y - _screenOffset.y) < 0 || (x - _screenOffset.x) > _screenWidth || (x - _screenOffset.x) < 0)
return true;
event->mouse.x = x - _screenOffset.x;
event->mouse.y = y - _screenOffset.y;
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_SET_WINDOW_CAPTION:
Char *caption = "Loading, please wait\0";
Coord h = FntLineHeight() + 2;
Coord w, y;
// quick erase the screen
WinScreenLock(winLockErase);
WinScreenUnlock();
WinSetTextColor(255);
WinSetForeColor(255);
if (_useHRmode) {
y = 160 - (h >> 1) - 10;
HRFntSetFont(gVars->HRrefNum,hrTinyBoldFont);
w = FntCharsWidth(caption,StrLen(caption));
w = (320 - w) >> 1;
HRWinDrawChars(gVars->HRrefNum, caption, StrLen(caption), w, y + h);
HRFntSetFont(gVars->HRrefNum,hrTinyFont);
w = FntCharsWidth(value->caption, StrLen(value->caption));
w = (320 - w) >> 1;
HRWinDrawChars(gVars->HRrefNum, value->caption, StrLen(value->caption), w, y);
} else {
Err e;
BitmapTypeV3 *bmp2P;
BitmapType *bmp1P = BmpCreate(320, (h << 1), 8, NULL, &e);
WinHandle tmpH = WinCreateBitmapWindow(bmp1P, &e);
WinSetDrawWindow(tmpH);
FntSetFont(boldFont);
y = 80 - (h >> 2) - 5;
w = FntCharsWidth(caption, StrLen(caption));
w = (320 - w) >> 1;
WinDrawChars(caption, StrLen(caption), w, 0 + h);
FntSetFont(stdFont);
w = FntCharsWidth(value->caption, StrLen(value->caption));
w = (320 - w) >> 1;
WinDrawChars(value->caption, StrLen(value->caption), w, 0);
WinSetDrawWindow(WinGetDisplayWindow());
bmp2P = BmpCreateBitmapV3(bmp1P, kDensityDouble, BmpGetBits(bmp1P), NULL);
WinDrawBitmap((BitmapPtr)bmp2P, 0, y);
BmpDelete((BitmapPtr)bmp2P);
WinDeleteWindow(tmpH,0);
BmpDelete(bmp1P);
}
return 1;
case PROP_OPEN_CD:
break;
case PROP_GET_SAMPLE_RATE:
return 8000;
}
return 0;
}
void OSystem_PALMOS::quit() {
// There is no exit(.) function under PalmOS, to exit an app
// we need to send an 'exit' event to the event handler
// and then the system return to the launcher. But this event
// is not handled by the main loop and so we need to force exit.
// In other systems like Windows ScummVM exit immediatly and so this doesn't appear.
if (_quitCount)
return;
if (_selfQuit && Scumm::g_scumm)
Scumm::g_scumm->_quit = true;
free(_currentPalette);
free(_mouseBackupP);
// free(_sndDataP);
free(_sndTempP);
if (_cdPlayer) {
_cdPlayer->release();
_cdPlayer = NULL;
}
unload_gfx_mode();
_quitCount++;
exit(1);
}
void OSystem_PALMOS::draw_mouse() {
if (_mouseDrawn || !_mouseVisible || _quitCount)
return;
_mouseCurState.y = _mouseCurState.y >= _screenHeight ? _screenHeight - 1 : _mouseCurState.y;
int x = _mouseCurState.x - _mouseHotspotX;
int y = _mouseCurState.y - _mouseHotspotY;
int w = _mouseCurState.w;
int h = _mouseCurState.h;
byte color;
byte *src = _mouseDataP; // Image representing the mouse
byte *bak = _mouseBackupP; // Surface used to backup the area obscured by the mouse
byte *dst; // Surface we are drawing into
int width;
// 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 * _mouseCurState.w;
y = 0;
}
if (w > _screenWidth - x)
w = _screenWidth - x;
if (h > _screenHeight - y)
h = _screenHeight - y;
// Quick check to see if anything has to be drawn at all
if (w <= 0 || h <= 0)
return;
// Store the bounding box so that undraw mouse can restore the area the
// mouse currently covers to its original content.
_mouseOldState.x = x;
_mouseOldState.y = y;
_mouseOldState.w = w;
_mouseOldState.h = h;
// Draw the mouse cursor; backup the covered area in "bak"
if (!_overlayVisible) {
dst = _offScreenP + y * _offScreenPitch + x;
while (h > 0) {
width = w;
while (width > 0) {
*bak++ = *dst;
color = *src++;
if (color != 0xFF) // 0xFF = transparent, don't draw
*dst = color;
dst++;
width--;
}
src += _mouseCurState.w - w;
bak += MAX_MOUSE_W - w;
dst += _offScreenPitch - w;
h--;
}
} else {
if (MemPtrDataStorage(_tmpScreenP)) {
int offset = y * _screenWidth + x;
dst = _tmpScreenP;
while (h > 0) {
width = w;
while (width > 0) {
*bak++ = *(dst + offset);
color = *src++;
if (color != 0xFF)
DmWrite(dst, offset, &color, 1);
offset++;
width--;
}
src += _mouseCurState.w - w;
bak += MAX_MOUSE_W - w;
offset += _screenWidth - w;
h--;
}
} else {
dst = _tmpScreenP + y * _screenWidth + x;
while (h > 0) {
width = w;
while (width > 0) {
*bak++ = *dst;
color = *src++;
if (color != 0xFF)
*dst = color;
dst++;
width--;
}
src += _mouseCurState.w - w;
bak += MAX_MOUSE_W - w;
dst += _screenWidth - w;
h--;
}
}
}
// Finally, set the flag to indicate the mouse has been drawn
_mouseDrawn = true;
}
void OSystem_PALMOS::undraw_mouse() {
if (!_mouseDrawn || _quitCount)
return;
_mouseDrawn = false;
byte *dst, *bak = _mouseBackupP;
const int old_mouse_x = _mouseOldState.x;
const int old_mouse_y = _mouseOldState.y;
const int old_mouse_w = _mouseOldState.w;
int old_mouse_h = _mouseOldState.h;
// No need to do clipping here, since draw_mouse() did that already
if (!_overlayVisible) {
dst = _offScreenP + old_mouse_y * _offScreenPitch + old_mouse_x;
do {
memcpy(dst, bak, old_mouse_w);
bak += MAX_MOUSE_W;
dst += _offScreenPitch;
} while (--old_mouse_h);
} else {
if (MemPtrDataStorage(_tmpScreenP)) {
int offset = old_mouse_y * _screenWidth + old_mouse_x;
do {
DmWrite(_tmpScreenP, offset, bak, old_mouse_w);
bak += MAX_MOUSE_W;
offset += _screenWidth;
} while (--old_mouse_h);
} else {
dst = _tmpScreenP + old_mouse_y * _screenWidth + old_mouse_x;
do {
memcpy(dst, bak, old_mouse_w);
bak += MAX_MOUSE_W;
dst += _screenWidth;
} while (--old_mouse_h);
}
}
}
void OSystem_PALMOS::stop_cdrom() {
if (!_cdPlayer)
return;
_cdPlayer->stop();
}
void OSystem_PALMOS::play_cdrom(int track, int num_loops, int start_frame, int duration) {
if (!_cdPlayer)
return;
_cdPlayer->play(track, num_loops, start_frame, duration);
}
bool OSystem_PALMOS::poll_cdrom() {
if (!_cdPlayer)
return false;
return _cdPlayer->poll();
}
void OSystem_PALMOS::update_cdrom() {
if (!_cdPlayer)
return;
_cdPlayer->update();
}
OSystem_PALMOS::OSystem_PALMOS() {
_quitCount = 0;
_selfQuit = false; // prevent illegal access to g_scumm
_current_shake_pos = 0;
_new_shake_pos = 0;
_paletteDirtyStart = 0;
_paletteDirtyEnd = 0;
memset(&_sound, 0, sizeof(SoundDataType));
_currentPalette = NULL;
_lastKeyPressed = -1;
_lastKeyRepeat = 100;
_lastKeyModifier = MD_NONE;
_useNumPad = false;
// mouse
memset(&_mouseOldState,0,sizeof(MousePos));
memset(&_mouseCurState,0,sizeof(MousePos));
_mouseDrawn = false;
_mouseBackupP = NULL;
_mouseVisible = false;
// overlay
_tmpScreenP = NULL;
_tmpBackupP = NULL;
// HiRes
_useHRmode = (gVars->HRrefNum != sysInvalidRefNum);
// enable cdrom ?
// TODO : defaultTrackLength player
_cdPlayer = NULL;
if (gVars->music.MP3) {
_cdPlayer = new MsaCDPlayer(this);
// _cdPlayer = new ZodiacCDPlayer(this);
_cdPlayer->init();
// TODO : use setDefaultTrackLength
// _isCDRomAvalaible = _cdPlayer->init();
// if (!_isCDRomAvalaible)
// _cdPlayer->release();
}
// sound
_isSndPlaying = false;
_sndTempP = (UInt8 *)calloc(SND_BLOCK,1);
_sndDataP = NULL;
}
void OSystem_PALMOS::move_screen(int dx, int dy, int height) {
// Short circuit check - do we have to do anything anyway?
if ((dx == 0 && dy == 0) || height <= 0)
return;
// Hide the mouse
if (_mouseDrawn)
undraw_mouse();
RectangleType r, dummy;
WinSetDrawWindow(_offScreenH);
RctSetRectangle(&r, ((_offScreenH != _screenH) ? 0 : _screenOffset.x), ((_offScreenH != _screenH) ? 0 : _screenOffset.y), _screenWidth, _screenHeight);
// FIXME : use this only if the Hi-Density feature is present ?
if (!_useHRmode) WinSetCoordinateSystem(kCoordinatesNative);
// vertical movement
if (dy > 0) {
// move down - copy from bottom to top
if (_useHRmode) {
// need to set the draw window
HRWinScrollRectangle(gVars->HRrefNum, &r, winDown, dy, &dummy);
} else {
WinScrollRectangle(&r, winDown, dy, &dummy);
}
} else if (dy < 0) {
// move up - copy from top to bottom
dy = -dy;
if (_useHRmode) {
// need to set the draw window
HRWinScrollRectangle(gVars->HRrefNum, &r, winUp, dy, &dummy);
} else {
WinScrollRectangle(&r, winUp, dy, &dummy);
}
}
// horizontal movement
if (dx > 0) {
// move right - copy from right to left
if (_useHRmode) {
// need to set the draw window
HRWinScrollRectangle(gVars->HRrefNum, &r, winRight, dx, &dummy);
} else {
WinScrollRectangle(&r, winRight, dx, &dummy);
}
} else if (dx < 0) {
// move left - copy from left to right
dx = -dx;
if (_useHRmode) {
// need to set the draw window
HRWinScrollRectangle(gVars->HRrefNum, &r, winLeft, dx, &dummy);
} else {
WinScrollRectangle(&r, winLeft, dx, &dummy);
}
}
// FIXME : use this only if the Hi-Density feature is present ?
if (!_useHRmode) WinSetCoordinateSystem(kCoordinatesStandard);
WinSetDrawWindow(_screenH);
// Prevent crash on Clie device using successive [HR]WinScrollRectangle !
SysTaskDelay(1);
}
/*
typedef struct {
bool played;
void *data;
UInt8 count;
} CallbackDataType;
CallbackDataType mycallback = {true, NULL, 0};
static Err sndCallback(void* UserDataP, SndStreamRef stream, void* bufferP, UInt32 frameCount) {
// SoundDataType *snd = (SoundDataType *)UserDataP;
// snd->proc(snd->param, (UInt8 *)bufferP, frameCount);
CallbackDataType *ptr = (CallbackDataType *)UserDataP;
MemSet(bufferP,frameCount,0);
if (!ptr->played) {
MemMove(bufferP, ptr->data, SND_BLOCK * 3);
ptr->played = true;
} else {
MemSet(bufferP,SND_BLOCK,0);
}
return errNone;
}
*/
//FILE *mf = NULL;
bool OSystem_PALMOS::set_sound_proc(SoundProc proc, void *param, SoundFormat format) {
_sound.active = true;
_sound.proc = proc;
_sound.param = param;
_sound.format = format;
/*
mycallback.data = _sndTempP;
Err e;
//_sound.active = false;
e = SndStreamCreate(&_sound.sndRefNum, sndOutput, 8000, sndInt16Big, sndStereo, sndCallback, &mycallback, SND_BLOCK *3, false);
e = SndStreamStart(_sound.sndRefNum);
//mf = fopen("/PALM/Programs/ScummVM/dump.wav","wb");
*/
return _sound.active;
}
void OSystem_PALMOS::clear_sound_proc() {
/* SndStreamStop(_sound.sndRefNum);
SndStreamDelete(_sound.sndRefNum);
*/
//fclose(mf);
_sound.active = false;
}
void OSystem_PALMOS::check_sound() {
// currently not supported
// but i need to use this function to prevent out of memory
// on games because the sound buffer growns and it's never
// freed.
// if (mycallback.played) {
_sound.proc(_sound.param, _sndTempP, SND_BLOCK);
/*
if (mycallback.count == 3) {
mycallback.played = false;
mycallback.count = 0;
}
//if (mf)
// fwrite(_sndTempP, SND_BLOCK, 1, mf);
}*/
}
void OSystem_PALMOS::show_overlay() {
// hide the mouse
undraw_mouse();
// save background
byte *src = _offScreenP;
byte *dst = _tmpBackupP;
int h = _screenHeight;
if (MemPtrDataStorage(_tmpScreenP)) {
UInt32 offset = 0;
do {
DmWrite(dst, offset, src, _screenWidth);
offset += _screenWidth;
src += _offScreenPitch;
} while (--h);
} else {
do {
memcpy(dst, src, _screenWidth);
dst += _screenWidth;
src += _offScreenPitch;
} while (--h);
}
_overlayVisible = true;
clear_overlay();
}
void OSystem_PALMOS::hide_overlay() {
// hide the mouse
undraw_mouse();
_overlayVisible = false;
copy_rect(_tmpBackupP, _screenWidth, 0, 0, _screenWidth, _screenHeight);
}
void OSystem_PALMOS::clear_overlay() {
if (!_overlayVisible)
return;
// hide the mouse
undraw_mouse();
// restore background
if (MemPtrDataStorage(_tmpScreenP))
DmWrite(_tmpScreenP, 0, _tmpBackupP, _screenWidth * _screenHeight);
else
MemMove(_tmpScreenP, _tmpBackupP, _screenWidth * _screenHeight);
}
void OSystem_PALMOS::grab_overlay(byte *buf, int pitch) {
if (!_overlayVisible)
return;
// hide the mouse
undraw_mouse();
byte *src = _tmpScreenP;
int h = _screenHeight;
do {
memcpy(buf, src, _screenWidth);
src += _screenWidth;
buf += pitch;
} while (--h);
}
void OSystem_PALMOS::copy_rect_overlay(const byte *buf, int pitch, int x, int y, int w, int h) {
if (!_overlayVisible)
return;
if (!_tmpScreenP)
return;
// Clip the coordinates
if (x < 0) {
w += x;
buf -= x;
x = 0;
}
if (y < 0) {
h += y; buf -= y * pitch;
y = 0;
}
if (w > _screenWidth - x) {
w = _screenWidth - x;
}
if (h > _screenHeight - y) {
h = _screenHeight - y;
}
if (w <= 0 || h <= 0)
return;
undraw_mouse();
if (MemPtrDataStorage(_tmpScreenP)) {
byte *dst = _tmpScreenP;
int offset = y * _screenWidth + x;
do {
DmWrite(dst, offset, buf, w);
offset += _screenWidth;
buf += pitch;
} while (--h);
} else {
byte *dst = _tmpScreenP + y * _screenWidth + x;
do {
memcpy(dst, buf, w);
dst += _screenWidth;
buf += pitch;
} while (--h);
}
}
int16 OSystem_PALMOS::get_height() {
return _screenHeight;
}
int16 OSystem_PALMOS::get_width() {
return _screenWidth;
}
byte OSystem_PALMOS::RGBToColor(uint8 r, uint8 g, uint8 b) {
byte color;
if (gVars->stdPalette) {
RGBColorType rgb = {0, r, g, b};
color = WinRGBToIndex(&rgb);
} else {
byte nearest = 255;
byte check;
byte r2, g2, b2;
color = 255;
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;
}
|