Skip to content

Commit

Permalink
#14 more register names in stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
velipso committed Mar 3, 2022
1 parent 317a0ac commit 5a46827
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export async function dis(

// TODO: if format is gba, then parse the GBA header

for (let i = 0; i < 200; i += 4) {
for (let i = 0; i < 200 && i < view.byteLength - 3; i += 4) {
const opcode = view.getUint32(i, true);
const res = parseArm(opcode);
if (res) {
Expand Down
2 changes: 2 additions & 0 deletions src/itest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { load as ifLoad } from './itests/if.ts';
import { load as structLoad } from './itests/struct.ts';
import { load as scriptLoad } from './itests/script.ts';
import { load as sinkLoad } from './itests/sink.ts';
import { load as stdlibLoad } from './itests/stdlib.ts';
import { makeFromFile } from './make.ts';
import * as sink from './sink.ts';
import { assertNever } from './util.ts';
Expand Down Expand Up @@ -268,6 +269,7 @@ export async function itest({ filters }: IItestArgs): Promise<number> {
structLoad(def);
scriptLoad(def);
sinkLoad(def);
stdlibLoad(def);

// execute the tests that match any filter
const indexDigits = Math.ceil(Math.log10(tests.length));
Expand Down
68 changes: 68 additions & 0 deletions src/itests/stdlib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// gvasm - Assembler and disassembler for Game Boy Advance homebrew
// by Sean Connelly (@velipso), https://sean.cm
// The Unlicense License
// Project Home: https://github.com/velipso/gvasm
//

import { ITest } from '../itest.ts';

export function load(def: (test: ITest) => void) {
def({
name: 'stdlib.registers',
desc: 'Validate register names are equal',
kind: 'make',
stdout: ['success'],
files: {
'/root/main': `
.stdlib
.script
for var dma: range 4
put ".if \\$REG_DMA\${dma}SAD != \\$REG_DMA\${dma}SRC"
put ' .error "DMASAD != DMASRC"'
put '.end'
put ".if \\$REG_DMA\${dma}DAD != \\$REG_DMA\${dma}DST"
put ' .error "DMADAD != DMADST"'
put '.end'
put ".if \\$REG_DMA\${dma}CNT_L != \\$REG_DMA\${dma}LEN"
put ' .error "DMACNT_L != DMALEN"'
put '.end'
put ".if \\$REG_DMA\${dma}CNT_H != \\$REG_DMA\${dma}CNT"
put ' .error "DMACNT_H != DMACNT"'
put '.end'
end
for var tm: range 4
put ".if \\$REG_TM\${tm}CNT_L != \\$REG_TM\${tm}D || \\$REG_TM\${tm}CNT_L != \\$REG_TM\${tm}VAL"
put ' .error "TMCNT_L != TMD != TMVAL"'
put '.end'
put ".if \\$REG_TM\${tm}CNT_H != \\$REG_TM\${tm}CNT"
put ' .error "TMCNT_H != TMCNT"'
put '.end'
end
.end
.if $REG_SIODATA32 != $REG_SIOMULTI0
.error "SIODATA32 != SIOMULTI0"
.end
.if $REG_SIOMLT_SEND != $REG_SIODATA8
.error "SIOMLT_SEND != SIODATA8"
.end
.if $REG_RCNT != $REG_SIOMODE2
.error "RCNT != SIOMODE2"
.end
.if $REG_JOYCNT != $REG_HS_CTRL
.error "JOYCNT != HS_CTRL"
.end
.if $REG_JOY_RECV != $REG_JOYRE
.error "JOY_RECV != JOYRE"
.end
.if $REG_JOY_TRANS != $REG_JOYTR
.error "JOY_TRANS != JOYTR"
.end
.if $REG_JOYSTAT != $REG_JSTAT
.error "JOYSTAT != JSTAT"
.end
.printf 'success'
`,
},
});
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IItestArgs, itest } from './itest.ts';
import { argParse, path } from './deps.ts';
import { lexKeyValue } from './lexer.ts';

export const version = 1006002;
export const version = 1006003;

function printVersion() {
const vmaj = Math.floor(version / 1000000) % 1000;
Expand Down
34 changes: 34 additions & 0 deletions src/stdlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const regs: [number, string][] = [
[0x050, 'BLDCNT'],
[0x052, 'BLDALPHA'],
[0x054, 'BLDY'],
[0x054, 'BLDVAL'],
[0x060, 'SOUND1CNT_L'],
[0x062, 'SOUND1CNT_H'],
[0x064, 'SOUND1CNT_X'],
Expand All @@ -61,28 +62,56 @@ const regs: [number, string][] = [
[0x0a0, 'FIFO_A'],
[0x0a4, 'FIFO_B'],
[0x0b0, 'DMA0SAD'],
[0x0b0, 'DMA0SRC'],
[0x0b4, 'DMA0DAD'],
[0x0b4, 'DMA0DST'],
[0x0b8, 'DMA0CNT_L'],
[0x0b8, 'DMA0LEN'],
[0x0ba, 'DMA0CNT_H'],
[0x0ba, 'DMA0CNT'],
[0x0bc, 'DMA1SAD'],
[0x0bc, 'DMA1SRC'],
[0x0c0, 'DMA1DAD'],
[0x0c0, 'DMA1DST'],
[0x0c4, 'DMA1CNT_L'],
[0x0c4, 'DMA1LEN'],
[0x0c6, 'DMA1CNT_H'],
[0x0c6, 'DMA1CNT'],
[0x0c8, 'DMA2SAD'],
[0x0c8, 'DMA2SRC'],
[0x0cc, 'DMA2DAD'],
[0x0cc, 'DMA2DST'],
[0x0d0, 'DMA2CNT_L'],
[0x0d0, 'DMA2LEN'],
[0x0d2, 'DMA2CNT_H'],
[0x0d2, 'DMA2CNT'],
[0x0d4, 'DMA3SAD'],
[0x0d4, 'DMA3SRC'],
[0x0d8, 'DMA3DAD'],
[0x0d8, 'DMA3DST'],
[0x0dc, 'DMA3CNT_L'],
[0x0dc, 'DMA3LEN'],
[0x0de, 'DMA3CNT_H'],
[0x0de, 'DMA3CNT'],
[0x100, 'TM0CNT_L'],
[0x100, 'TM0D'],
[0x100, 'TM0VAL'],
[0x102, 'TM0CNT_H'],
[0x102, 'TM0CNT'],
[0x104, 'TM1CNT_L'],
[0x104, 'TM1D'],
[0x104, 'TM1VAL'],
[0x106, 'TM1CNT_H'],
[0x106, 'TM1CNT'],
[0x108, 'TM2CNT_L'],
[0x108, 'TM2D'],
[0x108, 'TM2VAL'],
[0x10a, 'TM2CNT_H'],
[0x10a, 'TM2CNT'],
[0x10c, 'TM3CNT_L'],
[0x10c, 'TM3D'],
[0x10c, 'TM3VAL'],
[0x10e, 'TM3CNT_H'],
[0x10e, 'TM3CNT'],
[0x120, 'SIODATA32'],
[0x120, 'SIOMULTI0'],
Expand All @@ -95,10 +124,15 @@ const regs: [number, string][] = [
[0x130, 'KEYINPUT'],
[0x132, 'KEYCNT'],
[0x134, 'RCNT'],
[0x134, 'SIOMODE2'],
[0x140, 'JOYCNT'],
[0x140, 'HS_CTRL'],
[0x150, 'JOY_RECV'],
[0x150, 'JOYRE'],
[0x154, 'JOY_TRANS'],
[0x154, 'JOYTR'],
[0x158, 'JOYSTAT'],
[0x158, 'JSTAT'],
[0x200, 'IE'],
[0x202, 'IF'],
[0x204, 'WAITCNT'],
Expand Down

0 comments on commit 5a46827

Please sign in to comment.