Skip to content

Commit bbe37bc

Browse files
committed
fix pc-relative operands when 24-bit addresses are used. change snes example to use 24-bit bank base addresses, and use fastrom + lorom (hirom is neat but complicates things a bit). add 'far' to sublime keywords
1 parent 0ccb93a commit bbe37bc

File tree

9 files changed

+131
-119
lines changed

9 files changed

+131
-119
lines changed

examples/nes/shmup/main.wiz

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ in prg {
4343
// Wait for the second PPU vertical blank
4444
do {} while !nes.ppu.status$7;
4545

46+
// Read PPU status to reset the PPU high/low latch.
47+
a = nes.ppu.status;
48+
// Now setup the PPU for copying to the nametable.
49+
nes.ppu.address = a = >:nes.ppu.ADDRESS_NAMETABLE_DATA;
50+
nes.ppu.address = a = <:nes.ppu.ADDRESS_NAMETABLE_DATA;
51+
// Clear the nametable.
52+
x = >:nes.ppu.NAMETABLE_SIZE * 2;
53+
do {
54+
y = 0;
55+
do {
56+
nes.ppu.data = a;
57+
y++;
58+
} while !zero;
59+
60+
x--;
61+
} while !zero;
62+
4663
{
4764
y = 0;
4865
x = nes.ppu.PALETTE_SIZE * nes.ppu.PALETTE_COUNT;

examples/snes/hello/banks.wiz

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
config {
2+
map_mode = "lorom",
3+
fastrom = true,
4+
}
5+
16
bank zeropage @ 0x00 : [vardata; 256];
27
bank stack @ 0x100 : [vardata; 256];
3-
bank prg @ 0x8000 : [constdata; 0x8000];
8+
bank prg @ 0x808000 : [constdata; 0x8000];
49
bank far_ram @ 0xFE8000 : [vardata; 0x8000];

examples/snes/hello/main.wiz

Lines changed: 95 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ in prg {
9797
snes.dma.mdma_enable = a = snes.dma.ENABLE_0;
9898
}
9999

100-
far func bar() {}
101-
102100
#[fallthrough] func main() {
103101
nointerrupt = true;
104102
decimal = false;
@@ -111,109 +109,101 @@ in prg {
111109

112110
hardware_init();
113111

114-
/*a = *wow2;
115-
*wow2 = a;
116-
wow2[yy] = a;
117-
a = wow2[yy];
118-
while true {}
119-
goto bar;
120-
bar();
121-
goto (far &main as far func);
122-
goto wow3;
123-
^goto (&wow3 as func);
124-
goto *(&wow3 as *func);
125-
goto *((&wow3 as u16 + xx) as *func);
126-
(*((&wow3 as u16 + xx) as *func))();
127-
goto *(&wow4 as *far func);
128-
goto wow4; // FIXME: should be equivalent to 'goto *(&wow4 as *far func);'
129-
*/
130-
131-
w0 = xx = &spc_main[0] as u16;
132-
xx = 0x200;
133-
yy = spc_main.len - 2;
134-
snes2spc.transfer(xx, w0, yy);
135-
xx = *(&spc_main[spc_main.len - 2] as *u16);
136-
snes2spc.dispatch(xx);
137-
138-
snes.ppu.vram_control = a = snes.ppu.VRAM_CONTROL_INCREMENT_1 | snes.ppu.VRAM_CONTROL_SIZE_16;
139-
snes.ppu.vram_address_hl = xx = 0;
140-
141-
snes.dma0.control = a = snes.dma.CONTROL_MODE_AB;
142-
snes.dma0.mdma_dest = a = <:&snes.ppu.vram_write_data_l;
143-
snes.dma0.src_address_hl = xx = &hello_tiles_chr as u16;
144-
snes.dma0.src_address_bank = 0;
145-
snes.dma0.mdma_size_hl = xx = sizeof(typeof(hello_tiles_chr)) / sizeof(u16);
146-
147-
snes.ppu.cgram_address = 0;
148-
149-
snes.dma1.control = a = snes.dma.CONTROL_MODE_A;
150-
snes.dma1.mdma_dest = a = <:&snes.ppu.cgram_write_data;
151-
snes.dma1.src_address_hl = xx = &bkg_palette_data as u16;
152-
snes.dma1.src_address_bank = 0;
153-
snes.dma1.mdma_size_hl = xx = sizeof(typeof(bkg_palette_data));
154-
155-
snes.dma.mdma_enable = a = snes.dma.ENABLE_0 | snes.dma.ENABLE_1;
156-
157-
let BG1_TILEMAP_BASE_ADDRESS = 0x1000;
158-
let BG12_TILESET_BASE_ADDRESS = 0x0000;
159-
160-
let TEXT_X = 10;
161-
let TEXT_Y = 13;
162-
let TEXT_TILEMAP_DEST = BG1_TILEMAP_BASE_ADDRESS + TEXT_Y * 32 + TEXT_X;
163-
164-
snes.ppu.vram_control = a = snes.ppu.VRAM_CONTROL_INCREMENT_1 | snes.ppu.VRAM_CONTROL_SIZE_8;
165-
snes.ppu.vram_address_hl = xx = TEXT_TILEMAP_DEST;
166-
167-
snes.dma0.control = a = snes.dma.CONTROL_MODE_A;
168-
snes.dma0.mdma_dest = a = <:&snes.ppu.vram_write_data_l;
169-
snes.dma0.src_address_hl = xx = &message as u16;
170-
snes.dma0.src_address_bank = 0;
171-
snes.dma0.mdma_size_hl = xx = sizeof(typeof(message));
172-
173-
snes.dma.mdma_enable = a = snes.dma.ENABLE_0;
174-
175-
snes.ppu.bg1_tilemap = a = BG1_TILEMAP_BASE_ADDRESS >> snes.ppu.BG_TILEMAP_ADDRESS_BIT_ALIGN << snes.ppu.BG_TILEMAP_ADDRESS_SHIFT_LEFT;
176-
snes.ppu.bg12_tileset = a = BG12_TILESET_BASE_ADDRESS >> snes.ppu.BG_TILESET_ADDRESS_BIT_ALIGN;
177-
snes.ppu.bg_mode = a = 2;
178-
snes.ppu.screen_enable_mask = a = snes.ppu.SCREEN_ENABLE_BG1;
179-
snes.ppu.brightness = a = 0xF;
180-
181-
mosaic = 0;
182-
183-
while true {
184-
while !snes.ppu.hvbjoy_status $ snes.ppu.HVBJOY_STATUS_VBLANK_BIT {}
185-
186-
snes.ppu.mosaic = a = ((mosaic >>> 4) << 4) | 0x1;
187-
mosaic = a = mosaic + 0x08;
188-
189-
a = timer;
190-
191-
mem16();
192-
#[mem16] {
193-
aa &= 0xFF;
194-
yy = aa <<= 1;
195-
}
196-
mem8();
197-
198-
xx = *((&sine_table as u16 + yy) as *u16);
199-
w0 = xx;
200-
201-
mem16();
202-
#[mem16] {
203-
aa = w0;
204-
205-
inline for in 1 .. 10 { cmp(aa, 0x8000); aa >>>>#= 1; }
206-
207-
w0 = aa;
208-
}
209-
mem8();
210-
211-
snes.ppu.bg1_scroll_y = a = <:w0;
212-
snes.ppu.bg1_scroll_y = a = >:w0;
213-
++timer;
214-
215-
while snes.ppu.hvbjoy_status $ snes.ppu.HVBJOY_STATUS_VBLANK_BIT {}
112+
snes.rom.speed = a = snes.rom.SPEED_FAST;
113+
114+
push(a = 0x80);
115+
data_bank = pop();
116+
117+
return fast_main();
118+
}
119+
}
120+
121+
#[fallthrough, mem8, idx16] far func fast_main() {
122+
w0 = xx = &spc_main[0] as u16;
123+
xx = 0x200;
124+
yy = spc_main.len - 2;
125+
snes2spc.transfer(xx, w0, yy);
126+
xx = *(&spc_main[spc_main.len - 2] as *u16);
127+
snes2spc.dispatch(xx);
128+
129+
snes.ppu.vram_control = a = snes.ppu.VRAM_CONTROL_INCREMENT_1 | snes.ppu.VRAM_CONTROL_SIZE_16;
130+
snes.ppu.vram_address_hl = xx = 0;
131+
132+
snes.dma0.control = a = snes.dma.CONTROL_MODE_AB;
133+
snes.dma0.mdma_dest = a = <:&snes.ppu.vram_write_data_l;
134+
snes.dma0.src_address_hl = xx = &hello_tiles_chr as u16;
135+
snes.dma0.src_address_bank = 0;
136+
snes.dma0.mdma_size_hl = xx = sizeof(typeof(hello_tiles_chr)) / sizeof(u16);
137+
138+
snes.ppu.cgram_address = 0;
139+
140+
snes.dma1.control = a = snes.dma.CONTROL_MODE_A;
141+
snes.dma1.mdma_dest = a = <:&snes.ppu.cgram_write_data;
142+
snes.dma1.src_address_hl = xx = &bkg_palette_data as u16;
143+
snes.dma1.src_address_bank = 0;
144+
snes.dma1.mdma_size_hl = xx = sizeof(typeof(bkg_palette_data));
145+
146+
snes.dma.mdma_enable = a = snes.dma.ENABLE_0 | snes.dma.ENABLE_1;
147+
148+
let BG1_TILEMAP_BASE_ADDRESS = 0x1000;
149+
let BG12_TILESET_BASE_ADDRESS = 0x0000;
150+
151+
let TEXT_X = 10;
152+
let TEXT_Y = 13;
153+
let TEXT_TILEMAP_DEST = BG1_TILEMAP_BASE_ADDRESS + TEXT_Y * 32 + TEXT_X;
154+
155+
snes.ppu.vram_control = a = snes.ppu.VRAM_CONTROL_INCREMENT_1 | snes.ppu.VRAM_CONTROL_SIZE_8;
156+
snes.ppu.vram_address_hl = xx = TEXT_TILEMAP_DEST;
157+
158+
snes.dma0.control = a = snes.dma.CONTROL_MODE_A;
159+
snes.dma0.mdma_dest = a = <:&snes.ppu.vram_write_data_l;
160+
snes.dma0.src_address_hl = xx = &message as u16;
161+
snes.dma0.src_address_bank = 0;
162+
snes.dma0.mdma_size_hl = xx = sizeof(typeof(message));
163+
164+
snes.dma.mdma_enable = a = snes.dma.ENABLE_0;
165+
166+
snes.ppu.bg1_tilemap = a = BG1_TILEMAP_BASE_ADDRESS >> snes.ppu.BG_TILEMAP_ADDRESS_BIT_ALIGN << snes.ppu.BG_TILEMAP_ADDRESS_SHIFT_LEFT;
167+
snes.ppu.bg12_tileset = a = BG12_TILESET_BASE_ADDRESS >> snes.ppu.BG_TILESET_ADDRESS_BIT_ALIGN;
168+
snes.ppu.bg_mode = a = 2;
169+
snes.ppu.screen_enable_mask = a = snes.ppu.SCREEN_ENABLE_BG1;
170+
snes.ppu.brightness = a = 0xF;
171+
172+
mosaic = 0;
173+
174+
while true {
175+
while !snes.ppu.hvbjoy_status $ snes.ppu.HVBJOY_STATUS_VBLANK_BIT {}
176+
177+
snes.ppu.mosaic = a = ((mosaic >>> 4) << 4) | 0x1;
178+
mosaic = a = mosaic + 0x08;
179+
180+
a = timer;
181+
182+
mem16();
183+
#[mem16] {
184+
aa &= 0xFF;
185+
yy = aa <<= 1;
216186
}
187+
mem8();
188+
189+
xx = *((&sine_table as u16 + yy) as *u16);
190+
w0 = xx;
191+
192+
mem16();
193+
#[mem16] {
194+
aa = w0;
195+
196+
inline for in 1 .. 10 { cmp(aa, 0x8000); aa >>>>#= 1; }
197+
198+
w0 = aa;
199+
}
200+
mem8();
201+
202+
snes.ppu.bg1_scroll_y = a = <:w0;
203+
snes.ppu.bg1_scroll_y = a = >:w0;
204+
++timer;
205+
206+
while snes.ppu.hvbjoy_status $ snes.ppu.HVBJOY_STATUS_VBLANK_BIT {}
217207
}
218208
}
219209

@@ -234,5 +224,5 @@ in prg {
234224
const minirpg_sprites_chr = embed "minirpg_sprites.chr";
235225
const spc_main = embed "spc_main.bin";
236226

237-
const @ 0xFFFC = main;
227+
const @ 0x80FFFC = main;
238228
}

src/wiz/platform/gb_platform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ namespace wiz {
181181
[](Report* report, const Bank* bank, std::vector<std::uint8_t>& buffer, const InstructionOptions& options, const std::vector<std::vector<const InstructionOperand*>>& captureLists, SourceLocation location) {
182182
buffer.insert(buffer.end(), options.opcode.begin(), options.opcode.end());
183183

184-
const auto base = static_cast<int>(bank->getAddress().absolutePosition.get());
185-
const auto dest = static_cast<int>(captureLists[options.parameter[0]][0]->variant.get<InstructionOperand::Integer>().value);
184+
const auto base = static_cast<std::int32_t>(bank->getAddress().absolutePosition.get() & 0xFFFF);
185+
const auto dest = static_cast<std::int32_t>(captureLists[options.parameter[0]][0]->variant.get<InstructionOperand::Integer>().value);
186186
const auto offset = dest - base - 2;
187187
if (offset >= -128 && offset <= 127) {
188188
buffer.push_back(offset < 0

src/wiz/platform/mos6502_platform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ namespace wiz {
225225
[](Report* report, const Bank* bank, std::vector<std::uint8_t>& buffer, const InstructionOptions& options, const std::vector<std::vector<const InstructionOperand*>>& captureLists, SourceLocation location) {
226226
buffer.insert(buffer.end(), options.opcode.begin(), options.opcode.end());
227227

228-
const auto base = static_cast<int>(bank->getAddress().absolutePosition.get());
229-
const auto dest = static_cast<int>(captureLists[options.parameter[0]][0]->variant.get<InstructionOperand::Integer>().value);
228+
const auto base = static_cast<std::int32_t>(bank->getAddress().absolutePosition.get() & 0xFFFF);
229+
const auto dest = static_cast<std::int32_t>(captureLists[options.parameter[0]][0]->variant.get<InstructionOperand::Integer>().value);
230230
const auto offset = dest - base - 2;
231231
if (offset >= -128 && offset <= 127) {
232232
buffer.push_back(offset < 0

src/wiz/platform/pokemon_mini_platform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ namespace wiz {
226226
[](Report* report, const Bank* bank, std::vector<std::uint8_t>& buffer, const InstructionOptions& options, const std::vector<std::vector<const InstructionOperand*>>& captureLists, SourceLocation location) {
227227
buffer.insert(buffer.end(), options.opcode.begin(), options.opcode.end());
228228

229-
const auto base = static_cast<int>(bank->getAddress().absolutePosition.get());
230-
const auto dest = static_cast<int>(captureLists[options.parameter[0]][0]->variant.get<InstructionOperand::Integer>().value);
229+
const auto base = static_cast<std::int32_t>(bank->getAddress().absolutePosition.get() & 0xFFFF);
230+
const auto dest = static_cast<std::int32_t>(captureLists[options.parameter[0]][0]->variant.get<InstructionOperand::Integer>().value);
231231
const auto offset = dest - base - 2;
232232
if (offset >= -128 && offset <= 127) {
233233
buffer.push_back(offset < 0

src/wiz/platform/spc700_platform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ namespace wiz {
273273
[](Report* report, const Bank* bank, std::vector<std::uint8_t>& buffer, const InstructionOptions& options, const std::vector<std::vector<const InstructionOperand*>>& captureLists, SourceLocation location) {
274274
buffer.insert(buffer.end(), options.opcode.begin(), options.opcode.end());
275275

276-
const auto base = static_cast<int>(bank->getAddress().absolutePosition.get());
277-
const auto dest = static_cast<int>(captureLists[options.parameter[0]][0]->variant.get<InstructionOperand::Integer>().value);
276+
const auto base = static_cast<std::int32_t>(bank->getAddress().absolutePosition.get() & 0xFFFF);
277+
const auto dest = static_cast<std::int32_t>(captureLists[options.parameter[0]][0]->variant.get<InstructionOperand::Integer>().value);
278278
const auto offset = dest - base - 2;
279279
if (offset >= -128 && offset <= 127) {
280280
buffer.push_back(offset < 0

src/wiz/platform/wdc65816_platform.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ namespace wiz {
601601
[](Report* report, const Bank* bank, std::vector<std::uint8_t>& buffer, const InstructionOptions& options, const std::vector<std::vector<const InstructionOperand*>>& captureLists, SourceLocation location) {
602602
buffer.insert(buffer.end(), options.opcode.begin(), options.opcode.end());
603603

604-
const auto base = static_cast<int>(bank->getAddress().absolutePosition.get());
605-
const auto dest = static_cast<int>(captureLists[options.parameter[0]][0]->variant.get<InstructionOperand::Integer>().value);
604+
const auto base = static_cast<std::int32_t>(bank->getAddress().absolutePosition.get() & 0xFFFF);
605+
const auto dest = static_cast<std::int32_t>(captureLists[options.parameter[0]][0]->variant.get<InstructionOperand::Integer>().value);
606606
const auto offset = dest - base - 2;
607607
if (offset >= -128 && offset <= 127) {
608608
buffer.push_back(offset < 0
@@ -623,7 +623,7 @@ namespace wiz {
623623
[](Report* report, const Bank* bank, std::vector<std::uint8_t>& buffer, const InstructionOptions& options, const std::vector<std::vector<const InstructionOperand*>>& captureLists, SourceLocation location) {
624624
buffer.insert(buffer.end(), options.opcode.begin(), options.opcode.end());
625625

626-
const auto base = static_cast<std::int32_t>(bank->getAddress().absolutePosition.get());
626+
const auto base = static_cast<std::int32_t>(bank->getAddress().absolutePosition.get() & 0xFFFF);
627627
const auto dest = static_cast<std::int32_t>(captureLists[options.parameter[0]][0]->variant.get<InstructionOperand::Integer>().value);
628628
const auto offset = dest - base - 3;
629629
if (offset >= -32768 && offset <= 32767) {

src/wiz/platform/z80_platform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ namespace wiz {
207207
[](Report* report, const Bank* bank, std::vector<std::uint8_t>& buffer, const InstructionOptions& options, const std::vector<std::vector<const InstructionOperand*>>& captureLists, SourceLocation location) {
208208
buffer.insert(buffer.end(), options.opcode.begin(), options.opcode.end());
209209

210-
const auto base = static_cast<int>(bank->getAddress().absolutePosition.get());
211-
const auto dest = static_cast<int>(captureLists[options.parameter[0]][0]->variant.get<InstructionOperand::Integer>().value);
210+
const auto base = static_cast<std::int32_t>(bank->getAddress().absolutePosition.get() & 0xFFFF);
211+
const auto dest = static_cast<std::int32_t>(captureLists[options.parameter[0]][0]->variant.get<InstructionOperand::Integer>().value);
212212
const auto offset = dest - base - 2;
213213
if (offset >= -128 && offset <= 127) {
214214
buffer.push_back(offset < 0

0 commit comments

Comments
 (0)