-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtic80.go
More file actions
1299 lines (1102 loc) · 34.1 KB
/
tic80.go
File metadata and controls
1299 lines (1102 loc) · 34.1 KB
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
package tic80
import (
"reflect"
"unsafe"
)
// Memory Areas
var (
IO_RAM = (*[0x18000]byte)(unsafe.Pointer(uintptr(0x00000)))
FREE_RAM = (*[0x28000]byte)(unsafe.Pointer(uintptr(0x18000)))
)
// toTextData transforms a Go string into a form useable by TIC-80.
func toTextData(goString *string) unsafe.Pointer {
textData := new([]byte)
*textData = make([]byte, 0, len(*goString)+1)
for _, goRune := range *goString {
if goRune > 0 {
switch {
case goRune <= 0x7F:
*textData = append(*textData, byte(goRune))
default:
*textData = append(*textData, byte('?'))
}
}
}
*textData = append(*textData, 0)
buffer, _ := toByteData(textData)
return buffer
}
// toByteData transforms a Go slice of bytes into a form useable by TIC-80.
func toByteData(goBytes *[]byte) (buffer unsafe.Pointer, count int) {
if goBytes != nil {
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(goBytes))
buffer = unsafe.Pointer(sliceHeader.Data)
// See https://tinygo.org/docs/guides/compatibility/#reflectsliceheader-and-reflectstringheader.
count = int(sliceHeader.Len)
}
return
}
// paletteSet represents a subset of the color palette.
type paletteSet uint16
func (mask *paletteSet) Clear() {
*mask = 0
}
// AddColor adds a color to the set.
func (mask *paletteSet) AddColor(color int) {
*mask |= paletteSet(1 << (color % 16))
}
// RemoveColor removes a color from the set.
func (mask *paletteSet) RemoveColor(color int) {
*mask &^= paletteSet(1 << (color % 16))
}
// Colors returns a slice containing the colors.
func (mask *paletteSet) Colors() []byte {
if *mask > 0 {
set := make([]byte, 0, 16)
for color := 0; color < 16; color++ {
if *mask&paletteSet(1<<color) > 0 {
set = append(set, byte(color))
}
}
return set
}
return nil
}
// ButtonCode represents a button id for use with [tic80.Btn] and [tic80.Btnp]
type ButtonCode int
// Gamepad Players
const (
GAMEPAD_1 ButtonCode = 8 * iota
GAMEPAD_2
GAMEPAD_3
GAMEPAD_4
)
// Gamepad Buttons
const (
BUTTON_UP ButtonCode = iota
BUTTON_DOWN
BUTTON_LEFT
BUTTON_RIGHT
BUTTON_A
BUTTON_B
BUTTON_X
BUTTON_Y
)
// KeyCode represents a keyboard id for use with [tic80.Key] and [tic80.Keyp]
type KeyCode int
// Keyboard keys.
const (
KEY_A KeyCode = iota + 1
KEY_B
KEY_C
KEY_D
KEY_E
KEY_F
KEY_G
KEY_H
KEY_I
KEY_J
KEY_K
KEY_L
KEY_M
KEY_N
KEY_O
KEY_P
KEY_Q
KEY_R
KEY_S
KEY_T
KEY_U
KEY_V
KEY_W
KEY_X
KEY_Y
KEY_Z
KEY_ZERO
KEY_ONE
KEY_TWO
KEY_THREE
KEY_FOUR
KEY_FIVE
KEY_SIX
KEY_SEVEN
KEY_EIGHT
KEY_NINE
KEY_MINUS
KEY_EQUALS
KEY_LEFTBRACKET
KEY_RIGHTBRACKET
KEY_BACKSLASH
KEY_SEMICOLON
KEY_APOSTROPHE
KEY_GRAVE
KEY_COMMA
KEY_PERIOD
KEY_SLASH
KEY_SPACE
KEY_TAB
KEY_RETURN
KEY_BACKSPACE
KEY_DELETE
KEY_INSERT
KEY_PAGEUP
KEY_PAGEDOWN
KEY_HOME
KEY_END
KEY_UP
KEY_DOWN
KEY_LEFT
KEY_RIGHT
KEY_CAPSLOCK
KEY_CTRL
KEY_SHIFT
KEY_ALT
)
// FontOptions provides additional options to [tic80.Font].
type FontOptions struct {
transparentColors paletteSet
characterWidth int
characterHeight int
fixed bool
scale int
alternateFont bool
}
var defaultFontOptions FontOptions = FontOptions{
transparentColors: 0,
characterWidth: 8,
characterHeight: 8,
fixed: false,
scale: 1,
alternateFont: false,
}
// NewFontOptions constructs a [tic80.FontOptions] object with the defaults.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/font
func NewFontOptions() *FontOptions {
options := new(FontOptions)
*options = defaultFontOptions
return options
}
// AddTransparentColor adds an additional color to the list of colors to render as transparent.
func (options *FontOptions) AddTransparentColor(color int) *FontOptions {
options.transparentColors.AddColor(color)
return options
}
// RemoveTransparentColor removes a color to the list of colors to render as transparent.
func (options *FontOptions) RemoveTransparentColor(color int) *FontOptions {
options.transparentColors.RemoveColor(color)
return options
}
// SetOpaque removes all colors to render transparent.
func (options *FontOptions) SetOpaque() *FontOptions {
options.transparentColors.Clear()
return options
}
// SetCharacterSize sets the maximum size of each character in pixels.
func (options *FontOptions) SetCharacterSize(width, height int) *FontOptions {
options.characterWidth = width
options.characterHeight = height
return options
}
// SetScale sets the scale as a whole-number multiplier.
func (options *FontOptions) SetScale(scale int) *FontOptions {
options.scale = scale
return options
}
// ToggleFixed toggles monospacing.
func (options *FontOptions) ToggleFixed() *FontOptions {
options.fixed = !options.fixed
return options
}
// TogglePage toggles which font page to use (usually between large and small font).
func (options *FontOptions) TogglePage() *FontOptions {
options.alternateFont = !options.alternateFont
return options
}
// MapOptions provides additional options to [tic80.Map].
type MapOptions struct {
x int
y int
width int
height int
screenX int
screenY int
transparentColors paletteSet
scale int
}
var defaultMapOptions MapOptions = MapOptions{
x: 0,
y: 0,
width: 30,
height: 17,
screenX: 0,
screenY: 0,
transparentColors: 0,
scale: 1,
}
// NewMapOptions constructs a [tic80.MapOptions] object with the defaults.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/map
func NewMapOptions() *MapOptions {
options := new(MapOptions)
*options = defaultMapOptions
return options
}
// AddTransparentColor adds an additional color to the list of colors to render as transparent.
func (options *MapOptions) AddTransparentColor(color int) *MapOptions {
options.transparentColors.AddColor(color)
return options
}
// RemoveTransparentColor removes a color to the list of colors to render as transparent.
func (options *MapOptions) RemoveTransparentColor(color int) *MapOptions {
options.transparentColors.RemoveColor(color)
return options
}
// SetOpaque removes all colors to render transparent.
func (options *MapOptions) SetOpaque() *MapOptions {
options.transparentColors.Clear()
return options
}
// SetOffset sets the map coordinates in which to start drawing the map.
func (options *MapOptions) SetOffset(x, y int) *MapOptions {
options.x = x
options.y = y
return options
}
// SetSize sets the size of the map to draw.
func (options *MapOptions) SetSize(width, height int) *MapOptions {
options.width = width
options.height = height
return options
}
// SetPosition sets the screen coordinates to draw the map to.
func (options *MapOptions) SetPosition(x, y int) *MapOptions {
options.screenX = x
options.screenY = y
return options
}
// SetScale sets the scale as a whole-number multiplier.
func (options *MapOptions) SetScale(scale int) *MapOptions {
options.scale = scale
return options
}
// MusicOptions provides additional options to [tic80.Music]
type MusicOptions struct {
track int
frame int
row int
loop bool
sustain bool
tempo int
speed int
}
var defaultMusicOptions MusicOptions = MusicOptions{
track: -1,
frame: -1,
row: -1,
loop: true,
sustain: false,
tempo: -1,
speed: -1,
}
// NewMusicOptions constructs a [tic80.MusicOptions] object with the defaults.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/music
func NewMusicOptions() *MusicOptions {
options := new(MusicOptions)
*options = defaultMusicOptions
return options
}
// SetTrack sets the track index to start playing.
func (options *MusicOptions) SetTrack(track int) *MusicOptions {
options.track = track % 8
return options
}
// SetFrame sets the frame index to start playing.
func (options *MusicOptions) SetFrame(frame int) *MusicOptions {
options.frame = frame % 16
return options
}
// SetRow sets the row index to start playing.
func (options *MusicOptions) SetRow(row int) *MusicOptions {
options.row = row % 64
return options
}
// SetTempo sets the tempo in beats per minute.
func (options *MusicOptions) SetTempo(tempo int) *MusicOptions {
options.tempo = tempo%241 + 40
return options
}
// SetSpeed sets the speed.
func (options *MusicOptions) SetSpeed(speed int) *MusicOptions {
options.speed = speed%31 + 1
return options
}
// ToggleLooping toggles whether to loop the track.
func (options *MusicOptions) ToggleLooping() *MusicOptions {
options.loop = !options.loop
return options
}
// ToggleSustain toggles whether to sustain notes or not.
func (options *MusicOptions) ToggleSustain() *MusicOptions {
options.sustain = !options.sustain
return options
}
// PrintOptions provides additional options to [tic80.Print]
type PrintOptions struct {
color byte
fixed bool
scale int
alternateFont bool
}
var defaultPrintOptions PrintOptions = PrintOptions{
color: 15,
fixed: false,
scale: 1,
alternateFont: false,
}
// NewPrintOptions constructs a [tic80.PrintOptions] object with the defaults.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/print
func NewPrintOptions() *PrintOptions {
options := new(PrintOptions)
*options = defaultPrintOptions
return options
}
// SetColor sets the color of the text to print.
func (options *PrintOptions) SetColor(color int) *PrintOptions {
options.color = byte(color % 16)
return options
}
// SetScale sets the scale as a whole-number multiplier.
func (options *PrintOptions) SetScale(scale int) *PrintOptions {
options.scale = scale
return options
}
// ToggleFixed toggles monospacing.
func (options *PrintOptions) ToggleFixed() *PrintOptions {
options.fixed = !options.fixed
return options
}
// TogglePage toggles which font page to use (usually between large and small font).
func (options *PrintOptions) TogglePage() *PrintOptions {
options.alternateFont = !options.alternateFont
return options
}
// SoundEffectNote is an enumeration of music notes.
type SoundEffectNote int
const NOTE_NONE SoundEffectNote = -1
// Notes
const (
NOTE_C SoundEffectNote = iota
NOTE_C_SHARP
NOTE_D
NOTE_D_SHARP
NOTE_E
NOTE_F
NOTE_F_SHARP
NOTE_G
NOTE_G_SHARP
NOTE_A
NOTE_A_SHARP
NOTE_B
)
// SoundEffectOptions provides additional options for [tic80.Sfx]
type SoundEffectOptions struct {
id int
note int
octave int
duration int
channel int
leftVolume int
rightVolume int
speed int
}
var defaultSoundEffectOptions SoundEffectOptions = SoundEffectOptions{
id: -1,
note: -1,
octave: -1,
duration: -1,
channel: 0,
leftVolume: 15,
rightVolume: 15,
speed: 0,
}
// NewSoundEffectOptions constructs a [tic80.SoundEffectOptions] object with the defaults.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/sfx
func NewSoundEffectOptions() *SoundEffectOptions {
options := new(SoundEffectOptions)
*options = defaultSoundEffectOptions
return options
}
// SetId sets the id of the sound effect to play.
func (options *SoundEffectOptions) SetId(id int) *SoundEffectOptions {
options.id = id % 64
return options
}
// SetNote sets the note and octave to play the sound effect.
func (options *SoundEffectOptions) SetNote(note SoundEffectNote, octave int) *SoundEffectOptions {
options.note = int(note) % 12
options.octave = octave % 9
return options
}
// SetDuration sets the duration in frames to play the sound effect.
func (options *SoundEffectOptions) SetDuration(duration int) *SoundEffectOptions {
options.duration = duration
return options
}
// SetChannel sets the channel index to play the sound effect in.
func (options *SoundEffectOptions) SetChannel(channel int) *SoundEffectOptions {
options.channel = channel % 4
return options
}
// SetSpeed sets the speed of the sound effect.
func (options *SoundEffectOptions) SetSpeed(speed int) *SoundEffectOptions {
if speed < -4 {
options.speed = -4
} else if speed > 3 {
options.speed = 3
} else {
options.speed = speed
}
return options
}
// SetVolume sets the volume of both left and right speakers to the same level.
func (options *SoundEffectOptions) SetVolume(level int) *SoundEffectOptions {
level %= 16
options.leftVolume = level
options.rightVolume = level
return options
}
// SetStereoVolume sets the volume of left and right speakers independently.
func (options *SoundEffectOptions) SetStereoVolume(leftLevel, rightLevel int) *SoundEffectOptions {
options.leftVolume = leftLevel % 16
options.rightVolume = rightLevel % 16
return options
}
// SpriteOptions provides additional options to [tic80.Spr]
type SpriteOptions struct {
transparentColors paletteSet
scale int
flip int
rotate int
width int
height int
}
var defaultSpriteOptions SpriteOptions = SpriteOptions{
transparentColors: 0,
scale: 1,
flip: 0,
rotate: 0,
width: 1,
height: 1,
}
// NewSpriteOptions constructs a [tic80.SpriteOptions] object with the defaults.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/spr
func NewSpriteOptions() *SpriteOptions {
options := new(SpriteOptions)
*options = defaultSpriteOptions
return options
}
// AddTransparentColor adds an additional color to the list of colors to render as transparent.
func (options *SpriteOptions) AddTransparentColor(color int) *SpriteOptions {
options.transparentColors.AddColor(color)
return options
}
// RemoveTransparentColor removes a color to the list of colors to render as transparent.
func (options *SpriteOptions) RemoveTransparentColor(color int) *SpriteOptions {
options.transparentColors.RemoveColor(color)
return options
}
// SetOpaque removes all colors to render transparent.
func (options *SpriteOptions) SetOpaque() *SpriteOptions {
options.transparentColors.Clear()
return options
}
// SetScale sets the scale as a whole-number multiplier.
func (options *SpriteOptions) SetScale(scale int) *SpriteOptions {
options.scale = scale
return options
}
// FlipHorizontally toggles horizontally flipping.
func (options *SpriteOptions) FlipHorizontally() *SpriteOptions {
options.flip ^= 1
return options
}
// FlipVertically toggles vertical flipping.
func (options *SpriteOptions) FlipVertically() *SpriteOptions {
options.flip ^= 2
return options
}
// Rotate90CW rotates the sprite 90 degrees clockwise.
func (options *SpriteOptions) Rotate90CW() *SpriteOptions {
options.rotate = (options.rotate + 1) % 4
return options
}
// Rotate90CCW rotates the sprite 90 degrees counterclockwise.
func (options *SpriteOptions) Rotate90CCW() *SpriteOptions {
options.rotate = (options.rotate - 1) % 4
return options
}
// Rotate180 rotates the sprite 180 degrees.
func (options *SpriteOptions) Rotate180() *SpriteOptions {
options.rotate = (options.rotate + 2) % 4
return options
}
// SetSize sets the size of the sprite in 8x8 sub-sprites.
func (options *SpriteOptions) SetSize(width, height int) *SpriteOptions {
options.width = width
options.height = height
return options
}
// SyncMask is an enumeration of data banks.
type SyncMask int
const SYNC_ALL SyncMask = 0
// Banks
const (
SYNC_TILES SyncMask = 1 << iota
SYNC_SPRITES
SYNC_MAP
SYNC_SOUND_EFFECTS
SYNC_MUSIC
SYNC_PALETTE
SYNC_FLAGS
SYNC_SCREEN
)
// TexturedTriangleOptions provides additional options for [tic80.Ttri]
type TexturedTriangleOptions struct {
useTiles bool
transparentColors paletteSet
useDepthCalculations bool
z0 int
z1 int
z2 int
}
var defaultTexturedTriangleOptions TexturedTriangleOptions = TexturedTriangleOptions{
useTiles: false,
transparentColors: 0,
useDepthCalculations: false,
z0: 0,
z1: 0,
z2: 0,
}
// NewTexturedTriangleOptions constructs a [tic80.TexturedTriangleOptions] object with the defaults.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/ttri
func NewTexturedTriangleOptions() *TexturedTriangleOptions {
options := new(TexturedTriangleOptions)
*options = defaultTexturedTriangleOptions
return options
}
// AddTransparentColor adds an additional color to the list of colors to render as transparent.
func (options *TexturedTriangleOptions) AddTransparentColor(color int) *TexturedTriangleOptions {
options.transparentColors.AddColor(color)
return options
}
// RemoveTransparentColor removes a color to the list of colors to render as transparent.
func (options *TexturedTriangleOptions) RemoveTransparentColor(color int) *TexturedTriangleOptions {
options.transparentColors.RemoveColor(color)
return options
}
// SetOpaque removes all colors to render transparent.
func (options *TexturedTriangleOptions) SetOpaque() *TexturedTriangleOptions {
options.transparentColors.Clear()
return options
}
// SetTextureDepth enables z-depth consideration and sets the z-depth for each vertex of the triangle.
func (options *TexturedTriangleOptions) SetTextureDepth(z0, z1, z2 int) *TexturedTriangleOptions {
options.useDepthCalculations = true
options.z0 = z0
options.z1 = z1
options.z2 = z2
return options
}
// ToggleTextureSource toggles whether to use tiles or sprites for the texture source.
func (options *TexturedTriangleOptions) ToggleTextureSource() *TexturedTriangleOptions {
options.useTiles = !options.useTiles
return options
}
// TraceOptions provides additional options for [tic80.Trace]
type TraceOptions struct {
color byte
}
var defaultTraceOptions = TraceOptions{
color: 15,
}
// NewTraceOptions constructs a [tic80.TraceOptions] object with the defaults.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/trace
func NewTraceOptions() *TraceOptions {
options := new(TraceOptions)
*options = defaultTraceOptions
return options
}
// SetColor sets the color of the trace output.
func (options *TraceOptions) SetColor(color int) *TraceOptions {
options.color = byte(color % 16)
return options
}
//go:export btn
func rawBtn(id int32) int32
// Btn returns true if the controller button specified by the given id is pressed; false otherwise.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/btn
func Btn(id ButtonCode) bool {
return rawBtn(int32(id%32)) > 0
}
//go:export btnp
func rawBtnp(id, hold, period int32) bool
// Btnp returns true if the controller button specified by the given id was pressed the last frame, or after hold every period frames; false otherwise.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/btnp
func Btnp(id ButtonCode, hold, period int) bool {
return rawBtnp(int32(id%32), int32(hold), int32(period))
}
//go:export clip
func rawClip(x, y, width, height int32)
// Clip sets the clipping region for the screen.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/clip
func Clip(x, y, width, height int) {
rawClip(int32(x), int32(y), int32(width), int32(height))
}
//go:export cls
func rawCls(color int8)
// Cls fills the screen with the specified color to the screen.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/cls
func Cls(color int) {
rawCls(int8(color))
}
//go:export circ
func rawCirc(x, y, radius int32, color int8)
// Circ draws a filled circle with the specified color to the screen.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/circ
func Circ(x, y, radius, color int) {
rawCirc(int32(x), int32(y), int32(radius), int8(color%16))
}
//go:export circb
func rawCircb(x, y, radius int32, color int8)
// Circb draws a circle border with the specified color to the screen.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/circb
func Circb(x, y, radius, color int) {
rawCircb(int32(x), int32(y), int32(radius), int8(color%16))
}
//go:export elli
func rawElli(x, y, radiusX, radiusY int32, color int8)
// Elli draws a filled ellipse with the specified color to the screen.
func Elli(x, y, radiusX, radiusY, color int) {
rawElli(int32(x), int32(y), int32(radiusX), int32(radiusY), int8(color%16))
}
//go:export ellib
func rawEllib(x, y, radiusX, radiusY int32, color int8)
// Ellib draws an ellipse border with the specified color to the screen.
func Ellib(x, y, radiusX, radiusY, color int) {
rawEllib(int32(x), int32(y), int32(radiusX), int32(radiusY), int8(color%16))
}
//go:export exit
func rawExit()
// Exit closes TIC-80.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/exit
func Exit() {
rawExit()
}
//go:export fget
func rawFget(sprite int32, flag int8) bool
// Fget gets the status of the specified flag of the specified sprite.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/fget
func Fget(sprite, flag int) bool {
return rawFget(int32(sprite%512), int8(flag%8))
}
//go:export fset
func rawFset(sprite int32, flag int8, value bool)
// Fset sets the status of the specified flag of the specified sprite.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/fset
func Fset(sprite, flag int, value bool) {
rawFset(int32(sprite%512), int8(flag%8), value)
}
//go:export font
func rawFont(textBuffer unsafe.Pointer, x, y int32, transparentColorBuffer unsafe.Pointer, transparentColorCount int8, characterWidth, characterHeight int8, fixed bool, scale int8, useAlternateFontPage bool) int32
// Font draws text to the screen using sprite data.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/font
func Font(text string, x, y int, options *FontOptions) (textWidth int) {
if options == nil {
options = &defaultFontOptions
}
transparentColors := options.transparentColors.Colors()
transparentColorBuffer, transparentColorCount := toByteData(&transparentColors)
textBuffer := toTextData(&text)
return int(rawFont(textBuffer, int32(x), int32(y), transparentColorBuffer, int8(transparentColorCount), int8(options.characterWidth), int8(options.characterHeight), options.fixed, int8(options.scale), options.alternateFont))
}
//go:export key
func rawKey(id int32) int32
// Key returns true if keyboard key specified by the id was pressed; false otherwise.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/key
func Key(id KeyCode) bool {
return rawKey(int32(id)) > 0
}
//go:export keyp
func rawKeyp(id int8, hold, period int32) int32
// Keyp returns true if the keyboard key specified by the given id was pressed the last frame, or after hold every period frames; false otherwise.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/btnp
func Keyp(id KeyCode, hold, period int) bool {
return rawKeyp(int8(id), int32(hold), int32(period)) > 0
}
//go:export line
func rawLine(x0, y0, x1, y1 float32, color int8)
// Line draws a line with the specified color to the screen.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/line
func Line(x0, y0, x1, y1, color int) {
rawLine(float32(x0), float32(y0), float32(x1), float32(y1), int8(color))
}
//go:export map
func rawMap(x, y, width, height, screenX, screenY int32, transparentColorBuffer unsafe.Pointer, transparentColorCount int8, unused int32)
// Map draws a tile map to the screen.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/map
func Map(options *MapOptions) {
if options == nil {
options = &defaultMapOptions
}
transparentColors := options.transparentColors.Colors()
transparentColorBuffer, transparentColorCount := toByteData(&transparentColors)
rawMap(int32(options.x), int32(options.y), int32(options.width), int32(options.height), int32(options.screenX), int32(options.screenY), transparentColorBuffer, int8(transparentColorCount), 0)
}
//go:export memcpy
func rawMemcpy(destination, source, length int32)
// Memcpy copies a buffer of RAM to RAM.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/memcpy
func Memcpy(destination, source, length int) {
rawMemcpy(int32(destination), int32(source), int32(length))
}
//go:export memset
func rawMemset(address, value, length int32)
// Memset sets a buffer of RAM to one value.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/memset
func Memset(address, value, length int) {
rawMemset(int32(address), int32(value), int32(length))
}
//go:export mget
func rawMget(x, y int32) int32
// Mget gets the id of a tile given by the specified coordinates on the map.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/mget
func Mget(x, y int) int {
return int(rawMget(int32(x), int32(y)))
}
//go:export mset
func rawMset(x, y, value int32)
// Mset sets the specified id of a tile given by the specified coordinates on the map.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/mset
func Mset(x, y, value int) {
rawMset(int32(x), int32(y), int32(value))
}
type mouseData struct {
x int16
y int16
scrollX int8
scrollY int8
left bool
middle bool
right bool
}
var mouse *mouseData = new(mouseData)
//go:export mouse
func rawMouse(data *mouseData)
// Mouse returns the current state of the mouse.
// See the [API] for more details.
//
// [API]: https://github.com/nesbox/TIC-80/wiki/mouse
func Mouse() (x, y int, left, middle, right bool, scrollX, scrollY int) {
rawMouse(mouse)
x = int(mouse.x)
y = int(mouse.y)
left = mouse.left
middle = mouse.middle
right = mouse.right
scrollX = int(mouse.scrollX)
scrollY = int(mouse.scrollY)
return