Skip to content

Commit

Permalink
added acme assembler
Browse files Browse the repository at this point in the history
vcslib: increased # of lines in kernel
  • Loading branch information
sehugg committed Nov 13, 2023
1 parent f6452a7 commit 33055cb
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 3 deletions.
7 changes: 7 additions & 0 deletions presets/c64/basicheader.acme
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

* = $0801
!word Start
!byte $00,$00,$9e
!text "2066"
!byte $00,$00,$00
* = $0812
18 changes: 18 additions & 0 deletions presets/c64/skeleton.acme
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

!src "basicheader.acme"

Start:
jsr $e544 ; clear screen
ldy #0
Loop:
lda Message,y ; load message byte
beq EOM ; 0 = end of string
sta $400+41,y ; store to screen
iny
bne Loop ; next character
EOM:
jmp EOM ; infinite loop

Message:
!scr "hello world!", 0

4 changes: 2 additions & 2 deletions presets/vcs/vcslib/vcslib.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ extern void tinyfont48_build(byte* dest, const char str[12]);
#define OVERSCAN_TIM64 _TIM64(_CYCLES(36))
#else
#define VBLANK_TIM64 _TIM64(_CYCLES(37))
#define KERNAL_TIM64 _TIM64(_CYCLES(194))
#define OVERSCAN_TIM64 _TIM64(_CYCLES(32))
#define KERNAL_TIM64 _TIM64(_CYCLES(198))
#define OVERSCAN_TIM64 _TIM64(_CYCLES(28))
#endif

#define JOY_UP(plyr) (!(RIOT.swcha & ((plyr) ? 0x1 : ~MOVE_UP)))
Expand Down
5 changes: 5 additions & 0 deletions src/ide/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ export class CodeProject {
while (m = re6.exec(text)) {
this.pushAllFiles(files, m[2]);
}
// for acme
let re7 = /^[!]src\s+"(.+?)"/gmi;
while (m = re7.exec(text)) {
this.pushAllFiles(files, m[1]);
}
}
return files;
}
Expand Down
4 changes: 4 additions & 0 deletions src/ide/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const TOOL_TO_SOURCE_STYLE = {
'remote:llvm-mos': 'text/x-csrc',
}

// TODO: move into tool class
const TOOL_TO_HELPURL = {
'dasm': 'https://raw.githubusercontent.com/sehugg/dasm/master/doc/dasm.txt',
'cc65': 'https://cc65.github.io/doc/cc65.html',
Expand All @@ -142,6 +143,7 @@ const TOOL_TO_HELPURL = {
'zmac': "https://raw.githubusercontent.com/sehugg/zmac/master/doc.txt",
'cmoc': "http://perso.b2b2c.ca/~sarrazip/dev/cmoc.html",
'remote:llvm-mos': 'https://llvm-mos.org/wiki/Welcome',
'acme': 'https://raw.githubusercontent.com/sehugg/acme/main/docs/QuickRef.txt',
}

function gaEvent(category:string, action:string, label?:string, value?:string) {
Expand Down Expand Up @@ -1895,6 +1897,8 @@ function _addIncludeFile() {
addFileToProject("Include", ".wiz", (s) => { return 'import "'+s+'";' });
else if (tool == 'ecs')
addFileToProject("Include", ".ecs", (s) => { return 'import "'+s+'"' });
else if (tool == 'acme')
addFileToProject("Include", ".acme", (s) => { return '!src "'+s+'"' });
else
alertError("Can't add include file to this project type (" + tool + ")");
}
Expand Down
1 change: 1 addition & 0 deletions src/platform/vcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function getToolForFilename_vcs(fn: string) {
if (fn.endsWith(".wiz")) return "wiz";
if (fn.endsWith(".bb") || fn.endsWith(".bas")) return "bataribasic";
if (fn.endsWith(".ca65")) return "ca65";
if (fn.endsWith(".acme")) return "acme";
//if (fn.endsWith(".inc")) return "ca65";
if (fn.endsWith(".c")) return "cc65";
//if (fn.endsWith(".h")) return "cc65";
Expand Down
96 changes: 96 additions & 0 deletions src/worker/tools/acme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { CodeListing, CodeListingMap } from "../../common/workertypes";
import { BuildStep, BuildStepResult, emglobal, execMain, fixParamsWithDefines, gatherFiles, loadNative, makeErrorMatcher, moduleInstFn, msvcErrorMatcher, populateFiles, print_fn, putWorkFile, setupFS, staleFiles } from "../workermain";
import { EmscriptenModule } from "../workermain"

function parseACMESymbolTable(text: string) {
var symbolmap = {};
var lines = text.split("\n");
for (var i = 0; i < lines.length; ++i) {
var line = lines[i].trim();
// init_text = $81b ; ?
var m = line.match(/(\w+)\s*=\s*[$]([0-9a-f]+)/i);
if (m) {
symbolmap[m[1]] = parseInt(m[2], 16);
}
}
return symbolmap;
}

function parseACMEReportFile(text: string) {
var listings : CodeListingMap = {};
var listing : CodeListing;
var lines = text.split("\n");
for (var i = 0; i < lines.length; ++i) {
var line = lines[i].trim();
// ; ******** Source: hello.acme
var m1 = line.match(/^;\s*[*]+\s*Source: (.+)$/);
if (m1) {
var file = m1[1];
listings[file] = listing = {
lines: [],
};
continue;
}
// 15 0815 201b08 jsr init_text ; write line of text
var m2 = line.match(/^(\d+)\s+([0-9a-f]+)\s+([0-9a-f]+)/i);
if (m2) {
if (listing) {
listing.lines.push({
line: parseInt(m2[1]),
offset: parseInt(m2[2], 16),
insns: m2[3],
});
}
}
}
return listings;
}

export function assembleACME(step: BuildStep): BuildStepResult {
loadNative("acme");
var errors = [];
gatherFiles(step, { mainFilePath: "main.acme" });
var binpath = step.prefix + ".bin";
var lstpath = step.prefix + ".lst";
var sympath = step.prefix + ".sym";
if (staleFiles(step, [binpath, lstpath])) {
var binout, lstout, symout;
var ACME: EmscriptenModule = emglobal.acme({
instantiateWasm: moduleInstFn('acme'),
noInitialRun: true,
print: print_fn,
printErr: msvcErrorMatcher(errors),
//printErr: makeErrorMatcher(errors, /(Error|Warning) - File (.+?), line (\d+)[^:]+: (.+)/, 3, 4, step.path, 2),
});
var FS = ACME.FS;
populateFiles(step, FS);
fixParamsWithDefines(step.path, step.params);
var args = ['--msvc', '--initmem', '0', '-o', binpath, '-r', lstpath, '-l', sympath, step.path];
if (step.params?.acmeargs) {
args.unshift.apply(args, step.params.acmeargs);
} else {
args.unshift.apply(args, ['-f', 'plain']);
}
args.unshift.apply(args, ["-D__8BITWORKSHOP__=1"]);
if (step.mainfile) {
args.unshift.apply(args, ["-D__MAIN__=1"]);
}
execMain(step, ACME, args);
if (errors.length) {
let listings: CodeListingMap = {};
return { errors, listings };
}
binout = FS.readFile(binpath, { encoding: 'binary' });
lstout = FS.readFile(lstpath, { encoding: 'utf8' });
symout = FS.readFile(sympath, { encoding: 'utf8' });
putWorkFile(binpath, binout);
putWorkFile(lstpath, lstout);
putWorkFile(sympath, symout);
return {
output: binout,
listings: parseACMEReportFile(lstout),
errors: errors,
symbolmap: parseACMESymbolTable(symout),
};
}
}
21 changes: 21 additions & 0 deletions src/worker/wasm/acme.js

Large diffs are not rendered by default.

Binary file added src/worker/wasm/acme.wasm
Binary file not shown.
7 changes: 6 additions & 1 deletion src/worker/workermain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,14 @@ var PLATFORM_PARAMS = {
libargs: [ '--lib-path', '/share/target/apple2/drv', '-D', '__EXEHDR__=0', 'apple2.lib'],
__CODE_RUN__: 16384,
code_start: 0x803,
acmeargs: ['-f', 'apple'],
},
'apple2-e': {
arch: '6502',
define: ['__APPLE2__'],
cfgfile: 'apple2.cfg',
libargs: ['apple2.lib'],
acmeargs: ['-f', 'apple'],
},
'atari8-800xl.disk': {
arch: '6502',
Expand Down Expand Up @@ -327,13 +329,15 @@ var PLATFORM_PARAMS = {
define: ['__CBM__', '__C64__'],
cfgfile: 'c64.cfg', // SYS 2061
libargs: ['c64.lib'],
acmeargs: ['-f', 'cbm'],
//extra_link_files: ['c64-cart.cfg'],
},
'vic20': {
arch: '6502',
define: ['__CBM__', '__VIC20__'],
cfgfile: 'vic20.cfg',
libargs: ['vic20.lib'],
acmeargs: ['-f', 'cbm'],
//extra_link_files: ['c64-cart.cfg'],
},
'kim1': {
Expand Down Expand Up @@ -1135,10 +1139,11 @@ import * as x86 from './tools/x86'
import * as arm from './tools/arm'
import * as ecs from './tools/ecs'
import * as remote from './tools/remote'
import * as acme from './tools/acme'

var TOOLS = {
'dasm': dasm.assembleDASM,
//'acme': assembleACME,
'acme': acme.assembleACME,
'cc65': cc65.compileCC65,
'ca65': cc65.assembleCA65,
'ld65': cc65.linkLD65,
Expand Down

0 comments on commit 33055cb

Please sign in to comment.