-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFB_NESTEA.bas
2799 lines (1952 loc) · 66.3 KB
/
FB_NESTEA.bas
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
#Include Once"windows.bi"
Dim shared As HWND hwnd
''using fbsound for audio for now WIP
'#include "../inc/fbsound.bi"
'the nes system starts here//////////
'#Include Once "nes/old/NES.bi" ' WITHOUT AUDIO
Dim shared CPU_CHOOSE as bool = false 'TRUE is old cpu olc6502.bi and olc6502.bas
'type cpu_type as olc6502
Type cpu_type as CPU 'NesJS CPU
Dim shared PPU_CHOOSE as bool = false 'TRUE is old PPU olc2C02.bi and olc2C02.bas
'type ppu_type as olc2C02
Type ppu_type as PPU
'dim shared CART_CHOOSE as bool = false 'TRUE is old cart cartridge.bi and cartridge.bas
'type cart_type as ????
'type cart_type as ????
Dim Shared keysenable As bool
'WITH AUDIO///////////////////////
#Include Once "nes\NES.bi"
'#include Once "NES\bus.bas"
'#include Once "NES\BUS_OLDFORTESTING.bas"
'#include Once "NES\Audio.bas"
'/////////////////////////////////
'///////////////////////////////////
Dim shared nes as bus
Dim shared audio_hndler as AudioHandler ptr
Dim shared elapsedMS as float
Dim shared as uint64_t end1
Dim shared as uint64_t start1
Dim shared frmenums as uint32_t
Dim shared emurun as boolean = false
'
'pattables(0)=ImageCreate(128,128,RGB(0,0,0),32)
'pattables(1)=ImageCreate(128,128,RGB(0,0,0),32)
#Define GET_X_LPARAM(LPARAM) LoWord(LPARAM)
#Define GET_Y_LPARAM(LPARAM) HiWord(LPARAM)
#Include Once"crt.bi"
#Include Once "win/commctrl.bi"
#Include Once "fbgfx.bi"
#Include "file.bi"
#Include "filesaveopen.bas"
#Include "resources.bi"
#Define SCREEN_WIDTH 640 ' // We want a 800 pixel width resolution
#Define SCREEN_HEIGHT 480 ' // We want a 600 pixel height resolution
#Define KEYDOWN(vk_code) (IIf(GetAsyncKeyState(vk_code) And &H8000), 1, 0)
#Define KEYUP(vk_code) (IIf(GetAsyncKeyState(vk_code) And &H8000),0, 1)
Const DEF_CX = 256
Const DEF_CY = 240
Using fb
Dim Shared fResidualTime As float
Dim Shared fElapsedTime As float
Dim Shared fElapsedstart As float
Dim SHARED ff As Integer
Dim SHARED fps As Integer
Dim SHARED start As Single
Dim SHARED bEmulationRun As bool = false
Dim SHARED bSingleFrame As bool = FALSE
Dim Shared isFpressed As bool = FALSE
Dim Shared ispressed As bool = FALSE
Dim Shared cart As String
Dim Shared pic1 As String
Dim Shared zoom_scrn As Integer = 2
Dim Shared nesrect As rect => (0,0,256*2 ,240*2) '*1.45
Dim Shared bFullScreen As bool = FALSE ' // Create a boolean and set it to false. If we choose full screen, set it to TRUE
Dim Shared hmenu As HMENU
Dim Shared hViewsub As HMENU
Dim Shared hFilesub As HMENU
Dim Shared hFile_Recent_sub As HMENU
Dim Shared hView_Zoom_sub As HMENU
Dim Shared my_pattables As uint32_t Ptr'(128*128)
Dim Shared As HMENU hFile_VidRecord_sub
Dim Shared As HMENU hFile_AudRecord_sub
fElapsedstart = Timer
Declare Function ChangeToFullScreen(width1 As Integer ,height1 As Integer ) As BOOL
Declare sub audioloop()
Declare sub debug1()
audio_hndler = new AudioHandler(48000,AUDIO_S16SYS,2048,16)
audio_hndler->start_aud()
dim shared thread1 as any ptr
'thread1 = threadcreate(@audioloop)
Dim shared quit as boolean = false
Dim shared muted as bool
MMapTemplate(UINT16T ,String)
Dim shared mapasm As MAPNODEUINT16TSTRING Ptr
Dim shared map As TMAPUINT16TSTRING
Dim Shared pat_imgdata(512*480) As uInteger
Dim Shared nme_imgdata(512*480) As UInteger
Sub drawtile(imgdata As UByte Ptr, x As Integer,y As Integer, num As Integer, col As Integer)
for i as integer = 0 To 8 - 1
' // for each row
dim lp As UByte = getmapper()->ppuPeak(num * 16 + i)
Dim hp As UByte = getmapper()->ppuPeak(num * 16 + i + 8)
for j as integer = 0 To 8 - 1
dim shift As UByte = 7 - j
Dim pixel As UByte = (lp shr shift) and 1
pixel Or= ((hp shr shift) and 1) Shl 1
dim pind As UByte = IIf (pixel = 0, 0, col * 4 + pixel)
Dim As Integer index = ((y + i) * 512 + (x + j)) * 4
Dim As UByte Ptr _color = Cast(UByte Ptr,@palScreen(nes.ppu.readPalette(pind) and &H3f)) '@Cast(UByte Ptr,@nes.ppu.nesPal(0,0))[0]
imgdata[index] = _color[0] '// r
imgdata[index + 1] = _color[1] '// g
imgdata[index + 2] = _color[2] '// b
imgdata[index + 3] = 255 '// a
Next
Next
End Sub
Sub fillrct(buf As UInteger Ptr, x1 As Integer,y1 As Integer,x2 As Integer,y2 As Integer,col As UByte Ptr)
For y As Integer = 0 To y2-1
For x As Integer = 0 To x2-1
pat_imgdata(((y +y1)*512) + (x+x1)) = rgba(col[2],col[1],col[0], 255) 'palScreen(nes.ppu.readPalette(0) and &H3f)
Next
Next
End Sub
Sub drawPatternsPals()
For x As integer = 0 To 16 -1
For y As Integer = 0 To 16 -1
drawTile(@pat_imgdata(0), x * 8, y * 8, y * 16 + x, 0)
Next
Next
For x As integer = 0 To 16 -1
For y As Integer = 0 To 16 -1
drawTile(@pat_imgdata(0),128 + (x * 8), y * 8, 256 + (y * 16 + x), 0)
Next
Next
For i As Integer = 0 To 16-1
Dim col As UByte Ptr = Cast(UByte Ptr,@palScreen(nes.ppu.readPalette(i) and &H3f))
fillrct(@pat_imgdata(0),i*16,128,16,16,col)
col = Cast(UByte Ptr,@palScreen(nes.ppu.readPalette(i+16) and &H3f))
fillrct(@pat_imgdata(0),i*16,144,16,16,col)
Next
End Sub
Sub drawNametables()
For x As Integer = 0 To 64 - 1
For y As Integer = 0 To 60 - 1
dim as UInteger ry = y + iif(y >= 30, 2, 0)
Dim As UInteger tileNumAdr = &H2000 + iif(ry > 31 , &H800 , 0) + iif(x > 31 , &H400 , 0)
tileNumAdr += ((ry and &H1f) shl 5) + (x And &H1f)
Dim As UByte tileNum = getmapper()->ppuPeak(tileNumAdr)
Dim As UInteger attAdr = &H23c0 + iif(ry > 31 , &H800 , 0) + iif(x > 31 , &H400 , 0)
attAdr += ((ry and &H1c) Shl 1) + ((x and &H1c) shr 2)
Dim As UByte atr = getmapper()->ppuPeak(attAdr)
if((ry and &H2) > 0) Then
' // bottom half
atr Shr= 4
End If
atr and= &Hf
if((x and &H2) > 0) Then
'// right half
atr Shr= 2
endif
atr And= &H3
drawTile(@nme_imgData(0), x * 8, y * 8, tileNum + iif(nes.ppu.bgPatternBase = 0, 0, 256), atr)
Next
Next
End Sub
Function hex1 (n As uint32_t, d As uint8_t) As string
Dim s As String = String(d, "0")
Dim i As Integer
'for (int i = d - 1; i >= 0; i--, n >>= 4)
i = d-1
While i >= 0
s[i] = Asc("0123456789ABCDEF", (n And &Hf)+1) '[n And &HF]
n shr= 4
i-=1
Wend
' s[i] = "0123456789ABCDEF"[n & &HF];
'Next
return s
End Function
Sub drawram(x1 as integer,y1 as integer,naddr as uint16_t,nRows as integer,ncolumns as integer)
dim nramx as integer = x1
dim nramy as integer = y1
color 255
for row as integer = 0 to nRows-1
dim sOffset as string = "$" + hex1(naddr,4)+":"
for col as integer = 0 to ncolumns-1
sOffset += " " + hex1(nes._read(nAddr), 2)
naddr+=1
Next
locate nramy,nramx
print sOffset
nRamy+=1
Next
End Sub
Sub drawcode(x as integer ,y as integer ,nLiplayer as integer,old as bool)
Dim nOff as uint16_t
'CHANGE WHEN NEEDED////////////////
If old then
nOff=nes.cpu.pc
else
nOff=nes.cpu.br(nes.cpu.pc)
end if
'//////////////////////////////////
mapasm = map.findaddr(nOff)
dim nLiney as Integer = (nLiplayer shr 1) * 1 + y
color 255
if mapasm <> null then
color 10
locate nLineY,x
print *mapasm->nData
'nOff+=1
color 255
while nliney < (nLiplayer *1) + y
nOff+=1
mapasm = map.findaddr(nOff)
if mapasm <> null then
nLineY += 1
locate nLineY,x
print *mapasm->nData
elseif nOff = &HFFFF then
nLineY += 1
locate nLineY,x
print
end if
wend
end if
'mapasm = map.findaddr(player.cpu.pc)
nliney = (nLiplayer shr 1) * 1 + y
'CHANGE WHEN NEEDED////////////////
if old then
nOff=nes.cpu.pc
else
nOff=nes.cpu.br(nes.cpu.pc)
end if
'//////////////////////////////////
if mapasm <> null then
while nliney > y
nOff-=1
mapasm = map.findaddr(nOff)
if mapasm <> null then
nLineY -= 1
locate nLineY,x
print *mapasm->nData
elseif nOff = &HFFFF then
nLineY -= 1
locate nLineY,x
print
' nOff-=1
'beep
end if
wend
end if
'next i
End Sub
Sub drawOAM(x1 as integer,y1 as integer)
dim s as string
'nes.ppu.oamRam(i*4+3)
LOCATE y1, x1
'26
for i as integer = 0 to 27-1
s = hex(i,2) + ": (" & str(nes.ppu.oamRam(i*4+3)) & _
", " & str(nes.ppu.oamRam(i*4+0)) + ") " & _
"ID: " & hex(i*4+1,2) & _
" AT: " & hex(nes.ppu.oamram(i*4+2),2)
'
's = hex(i,2) + ": (" & str(pOAM[i*4+3]) & _
' ", " & str(pOAM[i*4+0]) + ") " & _
' "ID: " & hex(pOAM[i*4+1],2) & _
' " AT: " & hex(pOAM[i*4+2],2)
'
'
LOCATE y1+i, x1
print s
Next
End Sub
Sub DrawCpu (x1 AS INTEGER, y1 AS INTEGER,old as bool)
LOCATE y1+1, x1
Color 255
'11
'CHANGE WHEN NEEDED/////////////////////////////////
If old then
Print " status: ";
Color(IIf(nes.cpu.status And olc6502.N,10,12))
PRINT " N ";
Color(IIf(nes.cpu.status And olc6502.V,10,12))
PRINT " V ";
Color(IIf(nes.cpu.status And olc6502.U,10,12))
PRINT " - ";
Color(IIf(nes.cpu.status And olc6502.B,10,12))
PRINT " B ";
Color(IIf(nes.cpu.status And olc6502.D,10,12))
PRINT " D ";
Color(IIf(nes.cpu.status And olc6502.I,10,12))
PRINT " I ";
Color(IIf(nes.cpu.status And olc6502.Z,10,12))
PRINT " Z ";
Color(IIf(nes.cpu.status And olc6502.C,10,12))
PRINT " C "
Color 255
Else
Print " status: ";
Color(IIf(NES.CPU.N,10,12))
PRINT " N ";
Color(IIf(NES.CPU.V,10,12))
PRINT " V ";
color 30
'Color(IIf(true,10,12))
PRINT " - ";
color 30
' Color(IIf(true,10,12))
PRINT " - ";
Color(IIf(NES.CPU.D,10,12))
PRINT " D ";
Color(IIf(NES.CPU.I,10,12))
PRINT " I ";
Color(IIf(NES.CPU.Z,10,12))
PRINT " Z ";
Color(IIf(NES.CPU.C,10,12))
PRINT " C "
Color 255
End if
'///////////////////////////////////////////////////////
'Locate , x
' PRINT " ";getflag(N);" ";getflag(V);" ";getflag(U);" "; getflag(B);" ";getflag(D);" ";getflag(I);" "; getflag(Z);" ";getflag(C)
' Locate , x
'CHANGE WHEN NEEDED/////////////////////////////////////////////
If old then
Locate y1+2, x1
PRINT " PC: $"; LTRIM$(hex1(nes.cpu.PC , 4)) + " [" + LTRIM$(STR$(nes.cpu.PC)) + "]"
Locate y1+3, x1
PRINT " A: $"; LTRIM$(hex1(nes.cpu.A, 2)) + " [" + LTRIM$(STR$(nes.cpu.A)) + "]"
Locate y1+4 , x1
PRINT " X: $"; LTRIM$(hex1(nes.cpu.X, 2)) + " [" + LTRIM$(STR$(nes.cpu.X)) + "]"
Locate y1+5, x1
PRINT " Y: $"; LTRIM$(hex1(nes.cpu.Y, 2)) + " [" + LTRIM$(STR$(nes.cpu.Y)) + "]"
LOCATE y1+6, x1
PRINT " Stack P: $"; LTRIM$(hex1(nes.cpu.stkp, 4)) + " [" + LTRIM$(STR$(nes.cpu.stkp)) + "]"
'LOCATE y1, x1+50
else
Locate y1+2, x1
PRINT " PC: $"; LTRIM$(hex1(nes.cpu.br(nes.cpu.PC), 4)) + " [" + LTRIM$(STR$(nes.cpu.br(nes.cpu.PC))) + "]"
Locate y1+3, x1
PRINT " A: $"; LTRIM$(hex1(nes.cpu.r(nes.cpu.A), 2)) + " [" + LTRIM$(STR$(nes.cpu.r(nes.cpu.A))) + "]"
Locate y1+4 , x1
PRINT " X: $"; LTRIM$(hex1(nes.cpu.r(nes.cpu.X), 2)) + " [" + LTRIM$(STR$(nes.cpu.r(nes.cpu.X))) + "]"
Locate y1+5, x1
PRINT " Y: $"; LTRIM$(hex1(nes.cpu.r(nes.cpu.Y), 2)) + " [" + LTRIM$(STR$(nes.cpu.r(nes.cpu.Y))) + "]"
LOCATE y1+6, x1
PRINT " Stack P: $"; LTRIM$(hex1(nes.cpu.r(nes.cpu.SP), 4)) + " [" + LTRIM$(STR$(nes.cpu.r(nes.cpu.SP))) + "]"
'LOCATE y1, x1+50
End if
'//////////////////////////////////////////////////////////////////////////////////////
'print "ppustatus: " & bin(nes._read(&H2002),8)
'print "cycles: " & nes.cpu.getcycles()' str(nes.nSystemClockCounter)
' LOCATE y1+1, x1+50
' print *mydata1'"banks: " & str(prgbanksptr[4])
' LOCATE y1+1, x1+50
'print "vblank: " & nes.ppu.invblank
End Sub
'declare Sub Process2 Cdecl (ByVal userdata As Any Ptr, ByVal audbuffer As Ubyte Ptr, ByVal audlen As Integer)
'Sub Process2 Cdecl (ByVal userdata As Any Ptr, ByVal audbuffer As Ubyte Ptr, ByVal audlen As Integer)
''
''while not(nes._clock)
''
''Wend
'
'
' '
' ' if(that->inputReadPos + 2048 > that->inputBufferPos) then
' ' 'we overran the buffer
' ' 'log("Audio buffer overran");
' ' that->inputReadPos = that->inputBufferPos - 2048
' ' end if
' '
' ' if(that->inputReadPos + 4096 < that->inputBufferPos) then
' ' '// we underran the buffer
' ' '//log("Audio buffer underran");
' ' that->inputReadPos += 2048
' ' end if
' '
' 'For n as integer = 0 to (audlen/2)-1
' ''that->x+=.010
' '
' ' dim sample as Sint16 ptr = cast(Sint16 ptr,audbuffer)
' '
' '
' ' 'that->sample = sin((that->x*4))*0.20'(rnd*2-1)*0.15
' '
' ' that->intSample = cast(Sint32, that->inputbuffer(that->inputReadPos and &HFFF) * that->maxAmplitude)
' '
' ' sample[n] = cast(Sint16,that->intSample)
' '
' '
' '
' ' that->inputReadPos+=1
'
' 'Next n
'
'End Sub
Sub fill_pal_rect(hdc As hdc,x1 As Integer,y1 As Integer,pal1 As uint8_t ,pix As uint8_t )
'fillrect(hdc,@Type<rect>(x1,y1,x1+6,y1+6),createsolidbrush(Cast(COLORREF,GetColourFromPaletteRamBGR(pal1,pix))))
Dim br As hbrush '= createsolidbrush(GetColourFromPaletteRamBGR(pal1,pix))
fillrect(hdc,@Type<rect>(x1,y1,x1+12,y1+12),br)
DeleteObject(br)
End Sub
Sub fill_pal_rect2(hdc As hdc,x1 As Integer,y1 As Integer,x2 As Integer,y2 As Integer,col as uint32_t )
'fillrect(hdc,@Type<rect>(x1,y1,x1+6,y1+6),createsolidbrush(Cast(COLORREF,GetColourFromPaletteRamBGR(pal1,pix))))
Dim br As hbrush = createsolidbrush(Cast(COLORREF,bgr(getRvalue(col),getGvalue(col),getBvalue(col))))
fillrect(hdc,@Type<rect>(x1,y1,x1+x2,y1+y2),br)
DeleteObject(br)
End Sub
Function caculateLineBytes(width1 As uint32_t) As uint32_t
'//********* Four-byte Alignment**********
return Int((24 * width1 + 31)/32) *4
'//********* Four-byte Alignment**********
End Function
Sub temp_apu_clock
if (nes.apu.framecounter = 29830 and nes.apu.step5Mode = 0) or _
nes.apu.framecounter = 37282 then
nes.apu.frameCounter = 0
end if
''
nes.apu.frameCounter+=1 ' works similar to nesjs's framecounter
''
nes.apu.handleFrameCounter()
''
nes.apu.cycleTriangle()
nes.apu.cyclePulse1()
nes.apu.cyclePulse2()
nes.apu.cycleNoise()
''''this.cycleDmc()
'''
nes.apu._output(nes.apu._outputOffset) = nes.apu.mix():nes.apu._outputOffset +=1
if nes.apu._outputOffset = 29781 then
nes.apu._outputOffset = 29780
end if
End Sub
'sub temp_clock1()
'
'
' do
'
'
' ppu_clock()
'
'
' if (nes.apu.framecounter = 29830 and nes.apu.step5Mode = 0) or _
' nes.apu.framecounter = 37282 then
' nes.apu.frameCounter = 0
' end if
'
' nes.apu.frameCounter+=1 ' works similar to nesjs's framecounter
'
' nes.apu.handleFrameCounter()
'
' nes.apu.cycleTriangle()
' nes.apu.cyclePulse1()
' nes.apu.cyclePulse2()
' nes.apu.cycleNoise()
' ''''this.cycleDmc()
'
' nes.apu._output(nes.apu._outputOffset) = nes.apu.mix():nes.apu._outputOffset +=1
' if nes.apu._outputOffset = 29781 then
' nes.apu._outputOffset = 29780
' end if
'
'
' if (nes.nSystemClockCounter mod 3 = 0) Then
' If nes.dma_transfer Then
' '
' If nes.dma_dummy Then
'
' if (nes.nSystemClockCounter mod 2 = 1) Then
' nes.dma_dummy = FALSE
' End If
' '
' Else
' if (nes.nSystemClockCounter mod 2 = 0) Then
' nes.dma_data = nes._read(nes.dma_page shl 8 or nes.dma_addr)
' Else
'
' pOAM[nes.dma_addr] = nes.dma_data
' nes.dma_addr+=1
'
' if nes.dma_addr = 0 Then
' nes.dma_transfer = FALSE
' nes.dma_dummy = TRUE
' EndIf
'
'
'
' End If
'
'
' End If
'
' Else
'
' nes.cpu._clock()
'
' End If
'
'
' End If
'
' 'dim bAudioSampleReady as bool = false
' 'this.dAudiotime += this.dAudioTimePerNESClock
' ' if (dAudioTime >= dAudioTimePerSystemSample) then
' 'this.dAudioTime -= this.dAudioTimePerSystemSample
' 'this.dAudioSample = apu.mix()
' 'bAudioSampleReady = true
' ' end if
' '
' If (getmapper()->irqState()) Then
'
' GetMapper()->irqClear()
' 'nes.cpu.irq()
' End If
' '
' if (ppu_nmi) Then
'
' ppu_nmi = false
' ' nes.cpu.nmi()
' End If
'
' nes.nSystemClockCounter+=1
'
' Loop while Not(frame_complete)
'
'End Sub
Sub SaveNESScrn(path As String,width1 as integer,height1 as integer,scrndata As uint32_t Ptr = NULL)
Dim bmpheader As BITMAPFILEHEADER
Dim bmpinfoheader As BITMAPINFOHEADER
bmpheader.bftype = &H4D42
bmpheader.bfReserved1 = 0
bmpheader.bfReserved1 = 0
bmpheader.bfOffBits = &H36
bmpinfoheader.bisize = SizeOf(bmpinfoheader)
bmpinfoheader.biwidth = width1
bmpinfoheader.biheight = -height1
bmpinfoheader.biXPelsPerMeter = 5000
bmpinfoheader.biYPelsPerMeter = 5000
bmpinfoheader.biClrUsed = 0
bmpinfoheader.biClrImportant = 0
bmpinfoheader.biPlanes = 1
bmpinfoheader.biBitCount = 24
Dim linebytes As uint32_t = caculateLineBytes(bmpinfoheader.biwidth)
bmpheader.bfsize = SizeOf(BitmapFileHeader) + sizeof(BitmapInfoHeader) + lineBytes * Abs(bmpinfoheader.biheight)
bmpinfoheader.biSizeImage =Int((bmpinfoheader.biwidth * bmpinfoheader.biBitCount/8)) * Abs(bmpinfoheader.biheight)
Dim savebmpfile As Integer = FreeFile
Open path For Binary As savebmpfile
Put # savebmpfile, ,*Cast(UByte Ptr,@bmpheader),SizeOf(BITMAPFILEHEADER)
Put # savebmpfile, ,*Cast(UByte Ptr,@bmpinfoheader),SizeOf(BITMAPINFOHEADER)
Dim pixels As uint8_t Ptr
pixels = New uint8_t[bmpinfoheader.biSizeImage]
'
'Print scrndata[0]
'Print scrndata[1]
'Print scrndata[2]
'Print scrndata[3]
Dim pos1 As uint32_t = 0
For i As uint32_t = 0 To bmpinfoheader.biSizeImage-1 Step 3
pixels[i+2] = RGBA_R(scrndata[pos1]) ' red
pixels[i+1] = RGBA_G(scrndata[pos1])'green
pixels[i+0] = RGBA_B(scrndata[pos1])'blue
pos1+=1
Next
Put # savebmpfile,,pixels[0],bmpinfoheader.biSizeImage
Close savebmpfile
Delete pixels
pixels = NULL
Dim bmpinfo As BITMAPINFOHEADER
End Sub
Sub init_rom
Dim bmp As String
Dim s As String
Print "choose a rom"
'return true '@this.vRAMStatic
While cart = ""
cart = file_opensave(NULL)
If cart = "" Then
Print "invalid rom file"
print " "
input "select another? y/n: ",s
If s = "Y" Or s = "y" Then
Print "choose a rom"
ElseIf s = "N" Or s = "n" Then
print " "
Print "press Any key To Quit"
sleep
if hwnd <> null then
SendMessage(hwnd, WM_CLOSE, 0, 0)
'return
else
Sleep
End
End If
end if
end if
Wend
' sleep
'return
'Print bmp
' bmp = file_opensave(NULL)
'Print bmp
'dim sram_save as integer = FreeFile
' open "Earthbound Zero.batt" for binary as sram_save
' '
' 'put # sram_save,,*cast(uint8_t ptr,@this.vRAMStatic[0]),32*1024
' '
' close sram_save
'if fileexists("Earthbound Zero.batt") then
'
' kill ("Earthbound Zero.batt")
'EndIf
'
' dim sram_save as integer = FreeFile
' '"C:\Users\Gamer\Desktop\Kirby's Adventure (USA)\" &
' open "Earthbound Zero.batt" for binary as sram_save
' '
' ' put # sram_save,,*cast(uint8_t ptr,@this.vRAMStatic[0]),32*1024
' '
' close sram_save
'
'
'mkdir("C:\NESTEA_BATTSAVES")
'chdir("C:\NESTEA_BATTSAVES")
'if fileexists("Earthbound Zero.batt") then
'
' kill ("Earthbound Zero.batt")
'EndIf
'
' dim sram_save as integer = FreeFile
' '"C:\Users\Gamer\Desktop\Kirby's Adventure (USA)\" &
' open "Earthbound Zero.batt" for binary as sram_save
' '
' ' put # sram_save,,*cast(uint8_t ptr,@this.vRAMStatic[0]),32*1024
' '
' close sram_save
'
'
setconsoletitle("OLC-NES-NESTEA-FB-V0.1")
'Print cart
'Input "enter rom path or drag file here: ", cart
insert_cartridge(cart,hwnd)
setconsoletitle("OLC-NES-NESTEA-FB-V0.1")
Input "fullscreen Y/N?: ", s
Cls
If s = "Y" Or s = "y" Then
bfullscreen = TRUE
'FreeConsole()
ElseIf s = "N" Or s = "n" Then
bfullscreen = FALSE
EndIf