From 5a0865b02ce7610d8610b69071d17dbbec838c66 Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Sat, 13 Jan 2018 17:00:54 -0800 Subject: [PATCH] Quickly add new PLASMA aliases and data initialization. --- README.md | 63 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 3d5a9b9..06da45d 100755 --- a/README.md +++ b/README.md @@ -168,9 +168,9 @@ to run the module. You will be rewarded with `Hello, world.` printed to the scre and you should see the same screenful of gibberish you saw from the portable VM, but on the Apple II this time. Both VMs are running the exact same module binaries. To view the source of these modules refer to `PLASMA/src/samplesrc/hello.pla`, `PLASMA/src/samplesrc/test.pla`, and `PLASMA/src/samplesrc/testlib.pla`. To get even more insight into the compiled source, view the corresponding `.a` files. -## Target Hosted Compiler +## PLASMA Target Hosted Compiler -The PLASMA compiler is also self-hosted on the Apple II and III. The PLASMA system and development disks can be run on a real or emulated machine. It is recommended to copy the file to a hard disk, or similar mass storage device. Boot the PLASMA system and change the prefix to the development disk/directory. The 'HELLO.PLA' source file should be there. To compile the module, type: +The PLASMA compiler is also self-hosted on the Apple II and III. The PLASMA system and development disks can be run on a real or emulated machine. It is recommended to copy the files to a hard disk, or similar mass storage device. Boot the PLASMA system and change the prefix to the development disk/directory. The 'HELLO.PLA' source file should be there. To compile the module, type: ``` +PLASM HELLO.PLA @@ -196,11 +196,11 @@ Although the low-level PLASMA VM operations could easily by coded by hand, they ## PLASMA Modules -PLASMA programs are built up around modules: small, self contained, dynamically loaded and linked software components that provide a well defined interface to other modules. The module format extends the .REL file type originally defined by the EDASM assembler from the DOS/ProDOS Toolkit from Apple Computer, Inc. PLASMA extends the file format through a backwards compatible extension that the PLASMA loader recognizes to locate the PLASMA bytecode and provide for advanced dynamic loading of module dependencies. +PLASMA programs are built up around modules: small, self contained, dynamically loaded and linked software components that provide a well defined interface to other modules. The module format extends the .REL file type originally defined by the EDASM assembler from the DOS/ProDOS Toolkit from Apple Computer, Inc. PLASMA extends the file format through a backwards compatible extension that the PLASMA loader recognizes to locate the PLASMA bytecode and provide for advanced dynamic loading of module dependencies. Modules are first-class citizens in PLASMA: an imported module is assigned to a variable which can be accessed like any other. ## Data Types -PLASMA only defines two data types: `byte` and `word`. All operations take place on word-sized quantities, with the exception of loads and stores to byte sized addresses. The interpretation of a value can be an integer, an address, or anything that fits in 16 bits. There are a number of address operators to identify how an address value is to be interpreted. +PLASMA only defines two data types: `char`(or `byte`) and `var`(or `word`). All operations take place on word-sized quantities, with the exception of loads and stores to byte sized addresses. The interpretation of a value can be an integer, an address, or anything that fits in 16 bits. There are a number of address operators to identify how an address value is to be interpreted. ## Obligatory 'Hello World' @@ -276,8 +276,8 @@ end import testlib predef puti - byte testdata, teststring - word testarray + char testdata, teststring + var testarray end ``` @@ -319,9 +319,9 @@ There is a shortcut for defining constant offsets into structures: ``` struc t_entry - word id - byte[32] name - word next_entry + var id + char[32] name + var next_entry end ``` @@ -375,7 +375,7 @@ Strings are defined like Pascal strings, a length byte followed by the string ch // // An initialized string of 64 characters // -byte[64] txtfile = "UNTITLED" +char[64] txtfile = "UNTITLED" ``` ### Function Definitions @@ -464,7 +464,7 @@ Values can be treated as pointers by preceding them with a `^` for byte pointers ``` char[] hellostr = "Hello" -word srcstr, strlen +var srcstr, strlen srcstr = @hellostr // srcstr points to address of hellostr strlen = ^srcstr // the first byte srcstr points to is the string length @@ -474,8 +474,8 @@ Functions with parameters or expressions to be used as a function address to cal ``` predef keyin2plus -word keyin -byte key +var keyin +char key keyin = @keyin2plus // address-of keyin2plus function key = keyin() @@ -607,14 +607,14 @@ Here is an example using the `import`s from the previous examples to export an i ``` predef mydef(var) -export word[10] myfuncs = @putc, @mydef, $0000 +export var[10] myfuncs = @putc, @mydef, $0000 ``` Exporting functions is simple: ``` export def plot(x, y) - romcall(y, 0, x, 0, $F800) + call($F800, y, 0, x, 0) end ``` @@ -640,7 +640,7 @@ call(addr, aReg, xReg, yReg, statusReg) returns a pointer to a four-byte structu const xreg = 1 const getlin = $FD6A -numchars = call(getlin, 0, 0, 0, 0).xreg // return char count in X reg +numchars = call(getlin, 0, 0, 0, 0)->xreg // return char count in X reg ``` syscall(cmd, params) calls ProDOS, returning the status value. @@ -662,14 +662,14 @@ putc(char), puts(string), home, gotoxy(x,y), getc() and gets() are other handy u ``` putc('.') -byte okstr[] = "OK" +char okstr[] = "OK" puts(@okstr) ``` memset(addr, val, len) will fill memory with a 16-bit value. memcpy(dstaddr, srcaddr, len) will copy memory from one address to another, taking care to copy in the proper direction. ``` -byte nullstr[] = "" +char nullstr[] = "" memset(strlinbuf, @nullstr, maxfill * 2) // fill line buff with pointer to null string memcpy(scrnptr, strptr + ofst + 1, numchars) ``` @@ -737,8 +737,8 @@ predef myfunc byte smallarray[4] byte initbarray[] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 -byte string[64] = "Initialized string" -word wlabel[] +char string[64] = "Initialized string" +var wlabel[] word = 1000, 2000, 3000, 4000 // Anonymous array word funclist = @myfunc, $0000 ``` @@ -750,14 +750,33 @@ predef myfunc(var)#0 byte[4] smallarray byte[] initbarray = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 -byte[64] string = "Initialized string" -word[] wlabel +char[64] string = "Initialized string" +var[] wlabel word = 1000, 2000, 3000, 4000 // Anonymous array word funclist = @myfunc, $0000 ``` Arrays can be uninitialized and reserve a size, as in `smallarray` above. Initialized arrays without a size specified in the definition will take up as much data as is present, as in `initbarray` above. Strings are special arrays that include a hidden length byte in the beginning (Pascal strings). When specified with a size, a minimum size is reserved for the string value. Labels can be defined as arrays without size or initializers; this can be useful when overlapping labels with other arrays or defining the actual array data as anonymous arrays in following lines as in `wlabel` and following lines. Addresses of other data (must be defined previously) or function definitions (pre-defined with predef), including imported references, can be initializers. +The base array size can be used to initialize multiple variable of arbitrary size. Three, four byte values can be defined as such: + +``` +byte[4] a, b, c +``` + +All three variables will have 4 bytes reserved for them. If you combine a base size with an array size, you can define multiple large values. For instance, + +``` +byte[4] a[5] +``` + +will assign an array of five, four byte elements, for a total of 20 bytes. This may make more sense when we combine the alias for `byte`, `res` with structure definitions. An array of five structures would look like: + +``` +res[t_record] patient[20] +``` +The result would be to reserve 20 patient records. + #### Type Overrides Arrays are usually identified by the data type specifier, `byte` or `word` when the array is defined. However, this can be overridden with the type override specifiers: `:` and `.`. `:` overrides the type to be `word`, `.` overrides the type to be `byte`. An example of accessing a `word` array as `bytes`: