romdevtools 0.71.1 → 0.84.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/AGENTS.md +19 -16
  2. package/CHANGELOG.md +184 -0
  3. package/README.md +5 -5
  4. package/examples/README.md +1 -0
  5. package/examples/gametank/templates/gt_draw.h +91 -0
  6. package/examples/gametank/templates/gt_hud.h +89 -0
  7. package/examples/gametank/templates/gt_palette.h +59 -0
  8. package/examples/gametank/templates/gt_sound.h +90 -0
  9. package/examples/gametank/templates/gt_sprites.h +53 -0
  10. package/examples/gametank/templates/platformer.c +318 -0
  11. package/examples/gametank/templates/puzzle.c +295 -0
  12. package/examples/gametank/templates/racing.c +139 -0
  13. package/examples/gametank/templates/shmup.c +277 -0
  14. package/examples/gametank/templates/sports.c +119 -0
  15. package/package.json +24 -22
  16. package/src/cores/capabilities.js +24 -0
  17. package/src/cores/registry.js +7 -1
  18. package/src/host/LibretroHost.js +90 -17
  19. package/src/host/callbacks.js +20 -2
  20. package/src/host/cpu-state.js +17 -0
  21. package/src/host/gametank-acp-state.js +53 -0
  22. package/src/http/skill-doc.js +10 -6
  23. package/src/mcp/tools/audio.js +1 -1
  24. package/src/mcp/tools/cart-parts.js +76 -0
  25. package/src/mcp/tools/lifecycle.js +1 -1
  26. package/src/mcp/tools/platform-tools.js +9 -1
  27. package/src/platforms/gametank/lib/gt/audio/acp_image.bin +0 -0
  28. package/src/platforms/gametank/lib/gt/audio/audio_coprocessor.c +55 -0
  29. package/src/platforms/gametank/lib/gt/audio/audio_coprocessor.h +34 -0
  30. package/src/platforms/gametank/lib/gt/audio/audio_fw.asm +223 -0
  31. package/src/platforms/gametank/lib/gt/audio/audio_fw_blob.s +8 -0
  32. package/src/platforms/gametank/lib/gt/audio/instruments.c +79 -0
  33. package/src/platforms/gametank/lib/gt/audio/instruments.h +25 -0
  34. package/src/platforms/gametank/lib/gt/audio/music.c +370 -0
  35. package/src/platforms/gametank/lib/gt/audio/music.h +35 -0
  36. package/src/platforms/gametank/lib/gt/audio/note_numbers.h +132 -0
  37. package/src/platforms/gametank/lib/gt/audio/scaled_sines.raw +0 -0
  38. package/src/platforms/gametank/lib/gt/audio/sine_256_-63_63.bin +0 -0
  39. package/src/platforms/gametank/lib/gt/banking.c +29 -0
  40. package/src/platforms/gametank/lib/gt/banking.h +8 -0
  41. package/src/platforms/gametank/lib/gt/banking2.s +41 -0
  42. package/src/platforms/gametank/lib/gt/crt0.s +102 -0
  43. package/src/platforms/gametank/lib/gt/draw_logo.s +55 -0
  44. package/src/platforms/gametank/lib/gt/feature/persist/persist.c +103 -0
  45. package/src/platforms/gametank/lib/gt/feature/persist/persist.h +13 -0
  46. package/src/platforms/gametank/lib/gt/feature/random/random.c +40 -0
  47. package/src/platforms/gametank/lib/gt/feature/random/random.h +18 -0
  48. package/src/platforms/gametank/lib/gt/feature/text/text.c +111 -0
  49. package/src/platforms/gametank/lib/gt/feature/text/text.h +25 -0
  50. package/src/platforms/gametank/lib/gt/gametank.c +12 -0
  51. package/src/platforms/gametank/lib/gt/gametank.h +80 -0
  52. package/src/platforms/gametank/lib/gt/gametank_logo.inc +393 -0
  53. package/src/platforms/gametank/lib/gt/gen/assets/assets_index.h +9 -0
  54. package/src/platforms/gametank/lib/gt/gen/assets/sdk_default.h +5 -0
  55. package/src/platforms/gametank/lib/gt/gen/bank_nums.h +11 -0
  56. package/src/platforms/gametank/lib/gt/gen/modules_enabled.h +4 -0
  57. package/src/platforms/gametank/lib/gt/gen/modules_enabled.inc +4 -0
  58. package/src/platforms/gametank/lib/gt/gfx/draw_direct.c +132 -0
  59. package/src/platforms/gametank/lib/gt/gfx/draw_direct.h +75 -0
  60. package/src/platforms/gametank/lib/gt/gfx/draw_queue.c +177 -0
  61. package/src/platforms/gametank/lib/gt/gfx/draw_queue.h +35 -0
  62. package/src/platforms/gametank/lib/gt/gfx/draw_util.s +157 -0
  63. package/src/platforms/gametank/lib/gt/gfx/gfx_sys.c +43 -0
  64. package/src/platforms/gametank/lib/gt/gfx/gfx_sys.h +46 -0
  65. package/src/platforms/gametank/lib/gt/gfx/sprites.c +216 -0
  66. package/src/platforms/gametank/lib/gt/gfx/sprites.h +41 -0
  67. package/src/platforms/gametank/lib/gt/init.c +9 -0
  68. package/src/platforms/gametank/lib/gt/input.c +26 -0
  69. package/src/platforms/gametank/lib/gt/input.h +20 -0
  70. package/src/platforms/gametank/lib/gt/interrupt.s +67 -0
  71. package/src/platforms/gametank/lib/gt/vectors.s +14 -0
  72. package/src/platforms/gametank/lib/gt/wait.s +53 -0
  73. package/src/playtest/playtest.js +174 -26
  74. package/src/toolchains/arm-none-eabi-gcc/gcc.js +39 -188
  75. package/src/toolchains/asar/asar.js +10 -15
  76. package/src/toolchains/cc65/cc65.js +82 -92
  77. package/src/toolchains/cc65/da65.js +12 -17
  78. package/src/toolchains/cc65/preset-resolver.js +13 -2
  79. package/src/toolchains/cc65/presets/gametank/gametank.h +80 -0
  80. package/src/toolchains/cc65/presets/gametank/sdk.cfg +32 -0
  81. package/src/toolchains/cc65/presets/gametank/sdk.crt0.s +61 -0
  82. package/src/toolchains/cc65/presets/gametank/sdk.vectors.s +11 -0
  83. package/src/toolchains/cc65/presets/gametank/single-bank.cfg +28 -0
  84. package/src/toolchains/cc65/presets/gametank/single-bank.crt0.s +71 -0
  85. package/src/toolchains/cc65/presets/gametank/single-bank.vectors.s +12 -0
  86. package/src/toolchains/common/c-build.js +109 -0
  87. package/src/toolchains/common/gcc-toolchain.js +164 -0
  88. package/src/toolchains/common/wasm-tool.js +101 -0
  89. package/src/toolchains/dasm/dasm.js +12 -18
  90. package/src/toolchains/gba-c/gba-c.js +253 -305
  91. package/src/toolchains/genesis-c/genesis-c.js +196 -225
  92. package/src/toolchains/index.js +58 -4
  93. package/src/toolchains/m68k-elf-gcc/gcc.js +39 -202
  94. package/src/toolchains/mips-c/mips-c.js +68 -78
  95. package/src/toolchains/mips-elf-gcc/gcc.js +55 -118
  96. package/src/toolchains/rgbds/rgbds.js +7 -19
  97. package/src/toolchains/sdcc/sdcc.js +35 -26
  98. package/src/toolchains/sh-c/sh-c.js +44 -52
  99. package/src/toolchains/sh-elf-gcc/gcc.js +55 -110
  100. package/src/toolchains/sjasm/sjasm.js +10 -14
  101. package/src/toolchains/snes-c/snes-c.js +125 -150
  102. package/src/toolchains/tcc816/tcc816.js +10 -15
  103. package/src/toolchains/vasm68k/vasm68k.js +11 -16
  104. package/src/toolchains/wladx/wladx.js +5 -17
  105. package/src/toolchains/z80/binutils.js +5 -11
@@ -0,0 +1,35 @@
1
+ #ifndef MUSIC_H
2
+ #define MUSIC_H
3
+
4
+ #include "audio_coprocessor.h"
5
+ #include "instruments.h"
6
+
7
+ #define REPEAT_NONE 0
8
+ #define REPEAT_LOOP 1
9
+ #define REPEAT_RESUME 2
10
+
11
+ #define SFX_PRIORITY(x) (x<<4)
12
+
13
+ void init_music();
14
+
15
+ void play_song(const unsigned char* song, char bank_num, char loop);
16
+
17
+ void tick_music();
18
+
19
+ void silence_all_channels();
20
+
21
+ void stop_music();
22
+
23
+ void pause_music();
24
+
25
+ void unpause_music();
26
+
27
+ void set_note(char ch, char n);
28
+
29
+ extern unsigned char audio_amplitudes[NUM_FM_OPS];
30
+
31
+ void load_instrument(char channel, const Instrument* instr);
32
+
33
+ void play_sound_effect(char sfx_id, char channel);
34
+
35
+ #endif
@@ -0,0 +1,132 @@
1
+ #ifndef NOTE_NUMBERS_H
2
+ #define NOTE_NUMBERS_H
3
+
4
+ #define RST 0
5
+ #define NUP 128
6
+
7
+ #define Cn1 24
8
+ #define Cs1 25
9
+ #define Df1 25
10
+ #define Dn1 26
11
+ #define Ds1 27
12
+ #define Ef1 27
13
+ #define En1 28
14
+ #define Fn1 29
15
+ #define Fs1 30
16
+ #define Gf1 30
17
+ #define Gn1 31
18
+ #define Gs1 32
19
+ #define Af1 32
20
+ #define An1 33
21
+ #define As1 34
22
+ #define Bf1 34
23
+ #define Bn1 35
24
+
25
+ #define Cn2 36
26
+ #define Cs2 37
27
+ #define Df2 37
28
+ #define Dn2 38
29
+ #define Ds2 39
30
+ #define Ef2 39
31
+ #define En2 40
32
+ #define Fn2 41
33
+ #define Fs2 42
34
+ #define Gf2 42
35
+ #define Gn2 43
36
+ #define Gs2 44
37
+ #define Af2 44
38
+ #define An2 45
39
+ #define As2 46
40
+ #define Bf2 46
41
+ #define Bn2 47
42
+
43
+ #define Cn3 48
44
+ #define Cs3 49
45
+ #define Df3 49
46
+ #define Dn3 50
47
+ #define Ds3 51
48
+ #define Ef3 51
49
+ #define En3 52
50
+ #define Fn3 53
51
+ #define Fs3 54
52
+ #define Gf3 54
53
+ #define Gn3 55
54
+ #define Gs3 56
55
+ #define Af3 56
56
+ #define An3 57
57
+ #define As3 58
58
+ #define Bf3 58
59
+ #define Bn3 59
60
+
61
+ #define Cn4 60
62
+ #define Cs4 61
63
+ #define Df4 61
64
+ #define Dn4 62
65
+ #define Ds4 63
66
+ #define Ef4 63
67
+ #define En4 64
68
+ #define Fn4 65
69
+ #define Fs4 66
70
+ #define Gf4 66
71
+ #define Gn4 67
72
+ #define Gs4 68
73
+ #define Af4 68
74
+ #define An4 69
75
+ #define As4 70
76
+ #define Bf4 70
77
+ #define Bn4 71
78
+
79
+ #define Cn5 72
80
+ #define Cs5 73
81
+ #define Df5 73
82
+ #define Dn5 74
83
+ #define Ds5 75
84
+ #define Ef5 75
85
+ #define En5 76
86
+ #define Fn5 77
87
+ #define Fs5 78
88
+ #define Gf5 78
89
+ #define Gn5 79
90
+ #define Gs5 80
91
+ #define Af5 80
92
+ #define An5 81
93
+ #define As5 82
94
+ #define Bf5 82
95
+ #define Bn5 83
96
+
97
+ #define Cn6 84
98
+ #define Cs6 85
99
+ #define Df6 85
100
+ #define Dn6 86
101
+ #define Ds6 87
102
+ #define Ef6 87
103
+ #define En6 88
104
+ #define Fn6 89
105
+ #define Fs6 90
106
+ #define Gf6 90
107
+ #define Gn6 91
108
+ #define Gs6 92
109
+ #define Af6 92
110
+ #define An6 93
111
+ #define As6 94
112
+ #define Bf6 94
113
+ #define Bn6 95
114
+
115
+ #define Cn7 96
116
+ #define Cs7 97
117
+ #define Df7 97
118
+ #define Dn7 98
119
+ #define Ds7 99
120
+ #define Ef7 99
121
+ #define En7 100
122
+ #define Fn7 101
123
+ #define Fs7 102
124
+ #define Gf7 102
125
+ #define Gn7 103
126
+ #define Gs7 104
127
+ #define Af7 104
128
+ #define An7 105
129
+ #define As7 106
130
+ #define Bf7 106
131
+ #define Bn7 107
132
+ #endif
@@ -0,0 +1,29 @@
1
+ #include "gametank.h"
2
+
3
+ //must be power of 2
4
+ #define BANK_STACK_SIZE 8
5
+ //must be BANK_STACK_SIZE-1
6
+ #define BANK_WRAP_MASK 7
7
+
8
+ unsigned char romBankMirror;
9
+ unsigned char romBankStack[BANK_STACK_SIZE];
10
+ unsigned char romBankStackIdx;
11
+
12
+ void bank_shift_out(unsigned char banknum);
13
+
14
+ void change_rom_bank(unsigned char banknum) {
15
+ if(banknum != romBankMirror)
16
+ bank_shift_out(banknum);
17
+ }
18
+
19
+ void push_rom_bank() {
20
+ romBankStackIdx = (romBankStackIdx + 1) & BANK_WRAP_MASK;
21
+ romBankStack[romBankStackIdx] = romBankMirror;
22
+ }
23
+
24
+ void pop_rom_bank() {
25
+ change_rom_bank(romBankStack[romBankStackIdx]);
26
+ if(romBankStackIdx == 0)
27
+ romBankStackIdx = BANK_STACK_SIZE;
28
+ --romBankStackIdx;
29
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef BANKING_H
2
+ #define BANKING_H
3
+
4
+ void push_rom_bank();
5
+ void change_rom_bank(unsigned char banknum);
6
+ void pop_rom_bank();
7
+
8
+ #endif
@@ -0,0 +1,41 @@
1
+ .export _bank_shift_out
2
+ .import _romBankMirror
3
+
4
+ ; ---------------------------------------------------------------
5
+ ; void __near__ bank_shift_out ()
6
+ ; ---------------------------------------------------------------
7
+
8
+ OutBits = $2801
9
+
10
+ .segment "CODE"
11
+
12
+ .proc _bank_shift_out: near
13
+ sta _romBankMirror;
14
+ stz OutBits
15
+ clc
16
+ rol
17
+ rol
18
+ rol
19
+ tay
20
+
21
+ .repeat 7
22
+ and #2
23
+ sta OutBits
24
+ ora #1
25
+ sta OutBits
26
+ tya
27
+ rol
28
+ tay
29
+ .endrepeat
30
+
31
+ and #2
32
+ sta OutBits
33
+ ora #1
34
+ sta OutBits
35
+ ora #4
36
+ sta OutBits
37
+ stz OutBits
38
+
39
+ rts
40
+
41
+ .endproc
@@ -0,0 +1,102 @@
1
+ ; ---------------------------------------------------------------------------
2
+ ; crt0.s
3
+ ; ---------------------------------------------------------------------------
4
+ ;
5
+ ; Startup code for cc65 (GameTank version)
6
+
7
+ .export _init, _exit
8
+ .import _main, _sdk_init
9
+
10
+ .export __STARTUP__ : absolute = 1 ; Mark as startup
11
+ .import __RAM_START__, __RAM_SIZE__ ; Linker generated
12
+
13
+ .import copydata, zerobss, initlib, donelib
14
+
15
+ .import _romBankMirror
16
+ .import _bankflip
17
+ .import _bank_shift_out
18
+
19
+ .export _AudioFWPkg
20
+
21
+ .PC02
22
+
23
+ BankReg = $2005
24
+ VIA = $2800
25
+ ORB = 0
26
+ ORAr = 1
27
+ DDRB = 2
28
+ DDRA = 3
29
+ T1C = 5
30
+ ACR = $B
31
+ PCR = $C
32
+ IFR = $D
33
+ IER = $E
34
+
35
+ .include "zeropage.inc"
36
+
37
+ ; ----------------------------------------------------------<.BANK (_sdk_init)----------------
38
+ ; Place the startup code in a special segment
39
+
40
+ .segment "STARTUP"
41
+
42
+ ; ---------------------------------------------------------------------------
43
+ ; A little light 6502 housekeeping
44
+
45
+ _init: LDX #$FF ; Initialize stack pointer to $01FF
46
+ TXS
47
+ CLD ; Clear decimal mode
48
+
49
+ ldx #0
50
+ viaWakeup:
51
+ inx
52
+ bne viaWakeup
53
+
54
+ LDA #40
55
+ STA BankReg
56
+ STA $1FFF
57
+ STZ BankReg
58
+ STZ $1FFF
59
+
60
+ LDA #%00000111
61
+ STA VIA+DDRA
62
+ LDA #$FF
63
+ STA VIA+ORAr
64
+ LDA #$FD
65
+ jsr _bank_shift_out
66
+
67
+
68
+ ; ---------------------------------------------------------------------------
69
+ ; Set cc65 argument stack pointer
70
+
71
+ LDA #<(__RAM_START__ + __RAM_SIZE__)
72
+ STA c_sp
73
+ LDA #>(__RAM_START__ + __RAM_SIZE__)
74
+ STA c_sp+1
75
+
76
+ ; ---------------------------------------------------------------------------
77
+ ; Initialize memory storage
78
+
79
+ JSR zerobss ; Clear BSS segment
80
+ JSR copydata ; Initialize DATA segment
81
+ JSR initlib ; Run constructors
82
+
83
+ STZ _bankflip
84
+
85
+ ; ---------------------------------------------------------------------------
86
+ ; Call main()
87
+
88
+ LDA #$FD
89
+ jsr _bank_shift_out
90
+
91
+ JSR _sdk_init
92
+ JSR _main
93
+
94
+ ; ---------------------------------------------------------------------------
95
+ ; Back from main (this is also the _exit entry): force a software break
96
+
97
+ _exit: JSR donelib ; Run destructors
98
+ BRK
99
+
100
+ .segment "COMMON"
101
+ _AudioFWPkg:
102
+ .incbin "build/assets/audio_fw.bin.deflate"
@@ -0,0 +1,55 @@
1
+ ; ---------------------------------------------------------------------------
2
+ ; draw_logo.s
3
+ ; ---------------------------------------------------------------------------
4
+ ;
5
+ ; Draw the GameTank logo
6
+
7
+ .export _draw_gametank_logo
8
+
9
+ DMA_VX = $4000
10
+ DMA_VY = $4001
11
+ DMA_GX = $4002
12
+ DMA_GY = $4003
13
+ DMA_WIDTH = $4004
14
+ DMA_HEIGHT = $4005
15
+ DMA_Start = $4006
16
+ DMA_Color = $4007
17
+
18
+ .segment "LOADERS"
19
+
20
+ ;includes labels LogoXVals and LogoWVals
21
+ .include "gametank_logo.inc"
22
+
23
+ .proc _draw_gametank_logo: near
24
+ PHY
25
+ LDY #1
26
+ STY DMA_HEIGHT
27
+ STA DMA_Color
28
+ LDX #0
29
+ LDY #56
30
+ DrawLoop:
31
+ LDA LogoWVals, x
32
+ DrawLoopSkipW:
33
+ BEQ NextLine
34
+ STA DMA_WIDTH
35
+ LDA LogoXVals, x
36
+ STA DMA_VX
37
+ LDA #1
38
+ STA DMA_Start
39
+ INX
40
+ BRA DrawLoop
41
+ NextLine:
42
+ INY
43
+ STY DMA_VY
44
+ INX
45
+ LDA LogoWVals, x
46
+ BEQ EndLoop
47
+ BRA DrawLoopSkipW
48
+ EndLoop:
49
+
50
+ SEI
51
+ CLI
52
+ PLY
53
+ RTS ; Return to caller
54
+
55
+ .endproc
@@ -0,0 +1,103 @@
1
+ #include "banking.h"
2
+ #include "gametank.h"
3
+ #include "persist.h"
4
+ #include "bank_nums.h"
5
+ #include "modules_enabled.h"
6
+
7
+ #define MAGIC_SAVE_NUM 0x42
8
+
9
+ #pragma rodata-name (push, "SAVE")
10
+ const char save_canary = MAGIC_SAVE_NUM;
11
+ #pragma rodata-name (pop)
12
+
13
+ #ifdef ENABLE_MODULE_PERSIST
14
+
15
+ char executing_from_rom() {
16
+ asm("PLX");
17
+ asm("PLA");
18
+ asm("PHA");
19
+ asm("PHX");
20
+ return __A__ > 0xC0;
21
+ }
22
+
23
+ #pragma code-name (push, "DATA")
24
+ #pragma optimize (push, on)
25
+
26
+ char i, k;
27
+ void clear_save_sector() {
28
+ if(executing_from_rom()) {
29
+ while(1) {}
30
+ }
31
+ *dma_flags = flagsMirror & ~(DMA_IRQ | DMA_NMI);
32
+ asm("SEI");
33
+ push_rom_bank();
34
+ change_rom_bank(BANK_SAVE);
35
+ //unlock
36
+ *((unsigned char*) 0x8AAA) = 0xAA;
37
+ *((unsigned char*) 0x8555) = 0x55;
38
+ //setup
39
+ *((unsigned char*) 0x8AAA) = 0x80;
40
+
41
+ //unlock
42
+ *((unsigned char*) 0x8AAA) = 0xAA;
43
+ *((unsigned char*) 0x8555) = 0x55;
44
+
45
+ //erase
46
+ *((unsigned char*) 0x8000) = 0x30;
47
+
48
+ i = *((unsigned char*) 0x8000);
49
+ k = *((unsigned char*) 0x8000);
50
+ while(i != k) {
51
+ i = k;
52
+ k = *((unsigned char*) 0x8000);
53
+ }
54
+ *dma_flags = flagsMirror;
55
+ asm("CLI");
56
+ pop_rom_bank();
57
+ }
58
+
59
+ void unlock_bypass() {
60
+ *((unsigned char*) 0x8AAA) = 0xAA;
61
+ *((unsigned char*) 0x8555) = 0x55;
62
+ *((unsigned char*) 0x8AAA) = 0x20;
63
+ }
64
+
65
+ void lock_bypass() {
66
+ *((unsigned char*) 0x8000) = 0x90;
67
+ *((unsigned char*) 0x8000) = 0x00;
68
+ }
69
+
70
+ //src assumed not Flash ROM
71
+ //dest assumned to be in Flash ROM
72
+ void save_write(void *src, void *dest, char len) {
73
+ if(executing_from_rom()) {
74
+ while(1) {}
75
+ }
76
+ *dma_flags = flagsMirror & ~(DMA_IRQ | DMA_NMI);
77
+ asm("SEI");
78
+ push_rom_bank();
79
+ change_rom_bank(BANK_SAVE);
80
+ i = 0;
81
+ k = len;
82
+ unlock_bypass();
83
+ while(k) {
84
+ *((unsigned char*) 0x8000) = 0xA0;
85
+ ((char *)dest)[i] = ((char *)src)[i];
86
+ while(((char *) dest)[i] != ((char *) src)[i]) {
87
+
88
+ }
89
+ i++;
90
+ k--;
91
+ }
92
+ lock_bypass();
93
+ *dma_flags = flagsMirror;
94
+ asm("CLI");
95
+ pop_rom_bank();
96
+ }
97
+
98
+
99
+ #pragma optimize (pop)
100
+ #pragma code-name (pop)
101
+
102
+
103
+ #endif
@@ -0,0 +1,13 @@
1
+ #ifndef PERSIST_H
2
+ #define PERSIST_H
3
+
4
+ #include "modules_enabled.h"
5
+
6
+ #ifndef ENABLE_MODULE_PERSIST
7
+ #error "Module PERSIST included but not enabled!"
8
+ #endif
9
+
10
+ void clear_save_sector();
11
+ void save_write(void *src, void *dest, char len);
12
+
13
+ #endif
@@ -0,0 +1,40 @@
1
+ #include "random.h"
2
+ #include "modules_enabled.h"
3
+
4
+ #ifdef ENABLE_MODULE_RANDOM
5
+
6
+ int xorshift16(int x) {
7
+ x |= x == 0; /* if x == 0, set x = 1 instead */
8
+ x ^= (x & 0x07ff) << 5;
9
+ x ^= x >> 7;
10
+ x ^= (x & 0x0003) << 14;
11
+ return x;
12
+ }
13
+
14
+ int rnd_seed = 234;
15
+
16
+ int rnd() {
17
+ rnd_seed = xorshift16(rnd_seed);
18
+ rnd_seed = xorshift16(rnd_seed);
19
+ rnd_seed = xorshift16(rnd_seed);
20
+ rnd_seed = xorshift16(rnd_seed);
21
+ rnd_seed = xorshift16(rnd_seed);
22
+ rnd_seed = xorshift16(rnd_seed);
23
+ rnd_seed = xorshift16(rnd_seed);
24
+ rnd_seed = xorshift16(rnd_seed);
25
+ rnd_seed = xorshift16(rnd_seed);
26
+ rnd_seed = xorshift16(rnd_seed);
27
+ rnd_seed = xorshift16(rnd_seed);
28
+ rnd_seed = xorshift16(rnd_seed);
29
+ rnd_seed = xorshift16(rnd_seed);
30
+ rnd_seed = xorshift16(rnd_seed);
31
+ rnd_seed = xorshift16(rnd_seed);
32
+ rnd_seed = xorshift16(rnd_seed);
33
+ return rnd_seed;
34
+ }
35
+
36
+ int rnd_range(int low, int high) {
37
+ return ((rnd() & 0x7FFF) % (high - low)) + low;
38
+ }
39
+
40
+ #endif
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Provides random numbers
3
+ */
4
+
5
+ #ifndef RANDOM_H
6
+ #define RANDOM_H
7
+
8
+ #include "modules_enabled.h"
9
+
10
+ #ifndef ENABLE_MODULE_RANDOM
11
+ #error "Module RANDOM included but not enabled!"
12
+ #endif
13
+
14
+ int rnd();
15
+
16
+ int rnd_range(int low, int high);
17
+
18
+ #endif
@@ -0,0 +1,111 @@
1
+ #include "text.h"
2
+
3
+ #include "gametank.h"
4
+ #include "banking.h"
5
+ #include "draw_direct.h"
6
+ #include "sdk_default.h"
7
+ #include "modules_enabled.h"
8
+ #include "bank_nums.h"
9
+
10
+ #define SPRITE_CHAR_W 8
11
+ #define SPRITE_CHAR_H 8
12
+ #define SPRITE_ROW_0_F 0x68
13
+ #define SPRITE_ROW_G_V 0x70
14
+ #define SPRITE_ROW_W_Z 0x78
15
+ #define SPRITE_CHAR_BLANK_X 0x70
16
+ #define SPRITE_CHAR_BLANK_Y 0x78
17
+
18
+ #define TEXT_CHAR_WIDTH 8
19
+ #define TEXT_CHAR_HEIGHT 8
20
+ #define TEXT_LINE_HEIGHT 8
21
+
22
+ #ifdef ENABLE_MODULE_TEXT
23
+
24
+ char font_slot;
25
+ char text_cursor_x, text_cursor_y;
26
+ char text_print_width, text_print_line_start;
27
+ unsigned char text_color;
28
+ char font_offset_x, font_offset_y;
29
+
30
+ void text_init() {
31
+ text_cursor_x = 0;
32
+ text_cursor_y = 0;
33
+ text_print_width = 128;
34
+ text_print_line_start = 0;
35
+ text_color = TEXT_COLOR_BLACK;
36
+ }
37
+
38
+ SpriteSlot text_load_font() {
39
+ font_slot = allocate_sprite(&ASSET__sdk_default__bios8_bmp_load_list);
40
+ font_offset_x = SPRITE_OFFSET_X(font_slot);
41
+ font_offset_y = SPRITE_OFFSET_Y(font_slot);
42
+ return font_slot;
43
+ }
44
+
45
+ char text_tmp;
46
+ void text_print_string(char* str) {
47
+ *dma_flags = (flagsMirror | DMA_GCARRY) & ~(DMA_COLORFILL_ENABLE | DMA_OPAQUE);
48
+ banksMirror = bankflip | GRAM_PAGE(font_slot);
49
+ *bank_reg = banksMirror;
50
+ vram[WIDTH] = TEXT_CHAR_WIDTH;
51
+ vram[HEIGHT] = TEXT_CHAR_HEIGHT;
52
+ vram[VY] = text_cursor_y;
53
+ while(*str != 0) {
54
+ switch(*str) {
55
+ case ' ':
56
+ text_cursor_x += TEXT_CHAR_WIDTH;
57
+ break;
58
+ case '\n':
59
+ text_cursor_y += TEXT_CHAR_HEIGHT;
60
+ vram[VY] = text_cursor_y;
61
+ break;
62
+ case '\r':
63
+ text_cursor_x = text_print_line_start;
64
+ break;
65
+ default:
66
+ text_tmp = *str + text_color;
67
+ if(text_cursor_x >= (text_print_width + text_print_line_start)) {
68
+ text_cursor_x -= text_print_width;
69
+ text_cursor_y += TEXT_CHAR_HEIGHT;
70
+ vram[VY] = text_cursor_y;
71
+ }
72
+ vram[VX] = text_cursor_x;
73
+ vram[GX] = ((text_tmp & 0x0F) << 3) | font_offset_x;
74
+ vram[GY] = ((text_tmp & 0xF0) >> 1) | font_offset_y;
75
+ vram[START] = 1;
76
+ text_cursor_x += TEXT_CHAR_WIDTH;
77
+ wait();
78
+ }
79
+
80
+ ++str;
81
+ }
82
+ }
83
+
84
+ #pragma rodata-name (push, "PROG0")
85
+
86
+ const unsigned char decimal_conversion_table[100] = {
87
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
88
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
89
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29,
90
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
91
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
92
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
93
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
94
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
95
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
96
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99
97
+ };
98
+
99
+ #pragma rodata-name (pop)
100
+
101
+ void text_sprint_num(char* s, unsigned char num) {
102
+ if(num > 99) return;
103
+ push_rom_bank();
104
+ change_rom_bank(BANK_PROG0);
105
+ num = decimal_conversion_table[num];
106
+ *s = (num >> 4) + '0';
107
+ *(s+1) = (num & 0xF) + '0';
108
+ pop_rom_bank();
109
+ }
110
+
111
+ #endif