Commit Graph

332 Commits

Author SHA1 Message Date
Virgil Dupras 51c977f2ed basic: allow multiple commands on the same line 2019-12-12 10:51:13 -05:00
Virgil Dupras 1710c865dc doc: refer to the new BASIC shell in example
ref #80
2019-12-11 14:57:07 -05:00
Virgil Dupras 25d25d017c Replace old shell with BASIC shell
fixes #80
2019-12-11 14:05:34 -05:00
Virgil Dupras 20151a97f8 recipes/rc2014/zasm: use BASIC shell
Also made Makefile actually portable.
2019-12-11 13:01:51 -05:00
Virgil Dupras 880775ae69 recipes/rc2014/sdcard: use BASIC shell 2019-12-11 11:18:32 -05:00
Virgil Dupras beaea6f978 basic: add puth command 2019-12-09 14:34:14 -05:00
Virgil Dupras 105acedab8 basic: improve README
markdown formatting was broken. Also, don't mark it as WIP.
2019-12-01 20:15:45 -05:00
Virgil Dupras 10864afa96 recipes/ti84: use the BASIC shell 2019-12-01 20:11:13 -05:00
Virgil Dupras 4c07639808 basic: make cmd table more compact
This shaves off quite a few bytes from the binary.
2019-11-30 21:36:34 -05:00
Virgil Dupras 4ba84dac5c basic: add getc/putc commands 2019-11-30 21:13:44 -05:00
Virgil Dupras 77485a0031 basic: change welcome prompt
This is becoming the new shell, it has to step up to its new responsibilities!
2019-11-30 20:50:34 -05:00
Virgil Dupras fc23a7c4a1 basic: do registers-to-vars transfer after pgm hook call 2019-11-25 23:16:15 -05:00
Virgil Dupras 264e72e0fd basic: add fnew and fdel commands 2019-11-25 22:49:24 -05:00
Virgil Dupras 7c893dada1 basic: can now execute user apps!
Shell replacement sequence beginning in 3, 2, 1...
2019-11-25 22:05:10 -05:00
Virgil Dupras b29073b01d basic: add fopen command 2019-11-25 21:41:37 -05:00
Virgil Dupras a0daed6812 basic: add usr command 2019-11-24 21:07:03 -05:00
Virgil Dupras 12bc120375 basic: add bsel, bseek, getb, putb commands 2019-11-24 20:34:23 -05:00
Virgil Dupras 8f1d942e5f basic: add addr command 2019-11-24 15:39:36 -05:00
Virgil Dupras 381d57a513 basic: make variable A the only input variable
Mechanism for assigning inputs to the specified variable is clumsy and uses
binary space. Always using A is much simpler and doesn't seem very limiting to
me. I do that because there's many more "input" commands I'd like to add.
2019-11-24 14:55:50 -05:00
Virgil Dupras e1df320d44 basic: add ldbas command 2019-11-24 14:26:32 -05:00
Virgil Dupras 13f935aa88 basic: add fls command
Also, add the new `bshell` emulated tool. BASIC is on its way to replace the
shell.
2019-11-24 10:24:15 -05:00
Virgil Dupras b7d4860acf basic: add in/out commands
Also, fixed the cmd matching algo to not accept partial matches. For example,
to stop matching "input" when the command was "in".
2019-11-23 20:38:56 -05:00
Virgil Dupras 7761cebb0a basic: add sleep command
also fix broken "peek"
2019-11-23 17:07:14 -05:00
Virgil Dupras 9602f9b983 basic: add peek/poke/deek/doke commands 2019-11-23 16:09:34 -05:00
Virgil Dupras a680fd3328 basic: add support for signed integers 2019-11-23 14:56:23 -05:00
Virgil Dupras 501fe96e07 lib/expr: use the IX register a bit less
It's an awkward register to use and avoiding its use allows us to strip the
resulting binary significantly. parseEXPR keeps the same signature though.
2019-11-22 19:56:08 -05:00
Virgil Dupras 2f71ad6d2f lib/expr: add left/right shifting operators 2019-11-22 18:35:10 -05:00
Virgil Dupras a03c5ac700 lib/expr: add bitwise operators 2019-11-22 17:16:51 -05:00
Virgil Dupras 972e8221f1 lib/expr: add division and modulo operators 2019-11-22 15:03:16 -05:00
Virgil Dupras 1b01f13105 lib/expr: refactor for easier operator addition 2019-11-22 14:45:12 -05:00
Virgil Dupras fd5b2ab856 Put app-common documentation in apps/README.md 2019-11-22 14:01:16 -05:00
Virgil Dupras e17dc1e1e1 basic: add input command 2019-11-21 20:17:55 -05:00
Virgil Dupras 982d20f895 basic: allow printing of quoted strings 2019-11-21 19:56:51 -05:00
Virgil Dupras 704d32279a basic: document better 2019-11-21 17:03:46 -05:00
Virgil Dupras 7262993f14 basic: add if 2019-11-21 16:06:14 -05:00
Virgil Dupras 3f3dd9141e basic: allow multiple args in print 2019-11-20 21:02:11 -05:00
Virgil Dupras 9c400ca642 basic: add goto
Things are getting super cereal...
2019-11-20 15:45:53 -05:00
Virgil Dupras 9d6cbe577c basic: add variables
Things are getting cereal...
2019-11-20 15:10:00 -05:00
Virgil Dupras 9c9484fb88 basic: add run command 2019-11-20 10:49:23 -05:00
Virgil Dupras 9d1003e7a2 basic: keep line index ordered and line numbers unique 2019-11-19 21:55:26 -05:00
Virgil Dupras 62138b12cf basic: add buffer line index 2019-11-19 20:43:01 -05:00
Virgil Dupras 4c6de413df basic: begin implementing a line buffer 2019-11-19 15:14:04 -05:00
Virgil Dupras f5b04fc02f basic: add expression support to print
Again, same thing as in zasm.
2019-11-18 15:52:44 -05:00
Virgil Dupras 0bd58fd178 basic: parse hex, binary and char literals
Same thing as in zasm.
2019-11-18 15:22:09 -05:00
Virgil Dupras 1cea6e71e0 basic: add a print cmd
It can only print a decimal literal. But still, that's a big step because
I hadn't implemented decimal formatting yet.
2019-11-18 13:40:23 -05:00
Virgil Dupras 019d05f64c Make the shell a userspace app
That's my mega-commit you've all been waiting for.

The code for the shell share more routines with userspace apps than with kernel
units, because, well, its behavior is that of a userspace app, not a device
driver.

This created a weird situation with libraries and jump tables. Some routine
belonging to the `kernel/` directory felt weird there.

And then comes `apps/basic`, which will likely share even more code with the
shell. I was seeing myself creating huge jump tables to reuse code from the
shell. It didn't feel right.

Moreover, we'll probably want basic-like apps to optionnally replace the shell.

So here I am with this huge change in the project structure. I didn't test all
recipes on hardware yet, I will do later. I might have broken some...

But now, the structure feels better and the line between what belongs to
`kernel` and what belongs to `apps` feels clearer.
2019-11-15 15:37:49 -05:00
Virgil Dupras cdd0b64570 Modify userspace .org and RAMSTART expectations
Instead of expecting a `USER_CODE` symbol to be set, we expect `.org` to be
set in all userspace glue code. This gives us more flexibility with regards to
how we manage that.

Moreover, instead of making `USER_RAMSTART` mandatory, we make it default to
the end of the binary, which is adequate in a majority of cases.

Will be useful for my upcoming mega-commit... :)
2019-11-15 10:33:13 -05:00
Virgil Dupras d74b85f146 zasm: allow .org to be specified from command line
Also important for upcoming mega commit...
2019-11-15 09:57:53 -05:00
Virgil Dupras e5255d22f9 zasm: make .org affect "@" symbol 2019-11-15 08:59:26 -05:00
Virgil Dupras 6e714875dc zasm: Constants now override labels at all times
Will be important for a mega-commit I'm preparing.
2019-11-14 21:16:36 -05:00
Virgil Dupras 7cf3ed38da Extract str.asm from core.asm and make core included by userspace
Most of register fiddling routines (which is now the only thing contained
in care.asm) are used by almost all userspace apps, often in inner loops.

That makes the penalty of using jump tables for those a bit too high.
Moreover, it burdens jump tables needlessly.

Because this unit is very small (now that string routines are out), it makes
sense to always include it in binaries.
2019-11-14 10:14:15 -05:00
Virgil Dupras 82995eb346 zasm: have .fill generate an error on overflow
Can possibly avoid a lot of debugging pain.
2019-11-13 22:27:48 -05:00
Virgil Dupras 8d46895dd3 lib/parse: decimal ending with a whitespace are now valid
Also, make empty strings be parsed as invalid by parseDecimal.
2019-11-13 22:10:06 -05:00
Virgil Dupras 7274dccbe7 Move ASCII consts to ascii.h
And made them shorter in name. The new ascii.h file allow reuse in userspace
code.
2019-11-13 20:38:06 -05:00
Virgil Dupras f3992ed598 basic: begin an implementation from sratch
Let's see where it will lead us...
2019-11-13 15:28:16 -05:00
Virgil Dupras 0e9173a89a zasm: optimize handleRST a little bit 2019-11-12 19:45:56 -05:00
Virgil Dupras 4de2ce3ceb zasm: add RST instruction 2019-11-12 14:07:45 -05:00
Virgil Dupras 518df7a05e zasm: add poor man's indexing in instr table
There's a lot of looping through that table. At first, I wanted to add some
bisecting, but 16-bit additions and multiplications involved made the idea a
bit less appealing. I went with a very basic, hardcoded index which should
speed things quite a bit at a minimal complexity cost.
2019-11-11 20:59:26 -05:00
Virgil Dupras cbc6fb5931 zasm: clean up jump table requirements
There was a little bit of cruft.
2019-11-11 20:21:13 -05:00
Virgil Dupras 5f6b303e75 zasm: add IX/IY support to SRL, RR and RL 2019-11-10 22:03:18 -05:00
Virgil Dupras 506c3d0a96 zasm: generalize handling of IX/IY in 0xcb upcode family
There's a couple of bit fiddling instructions that didn't have their
IX/IY variant implemented yet and without this commit, each of them
would have required a special routine. Not anymore.
2019-11-10 21:02:18 -05:00
Virgil Dupras d9d6093287 zasm: simplify (IX/Y+d) handling
We now require less special handling.
2019-11-10 20:16:50 -05:00
Virgil Dupras 68ef686c3c zasm: fix 16-bit include lineno counting
It was actually counted in 8-bit mode...
2019-11-10 13:50:26 -05:00
Virgil Dupras 999ab56366 zasm: add generic handling of BIT argument
This reduces the need for special handling routine and will make my
life easier in my upcoming generic tratment of IX/IY prefix in upcodes
2019-11-10 10:24:36 -05:00
Virgil Dupras 553b346b92 zasm: getUpcode -> spitUpcode
Giving I/O responsibility to spitUpcode gives us wiggle room for
upcoming refactorings.
2019-11-10 09:28:10 -05:00
Virgil Dupras b745f49186 Rename blockdev's API routines to GetB/PutB
The goal is to avoid mixing those routines with "character devices"
(acia, vpd, kbd) which aren't block devices and have routines that
have different expectations.

This is a first step to fixing #64.
2019-10-30 16:59:35 -04:00
Clanmaster21 38333e9e07 Decimal parse optimisations (#45)
* Optimised parsing functions and other minor optimisations

UnsetZ has been reduced by a byte, and between 17 and 28 cycles saved based on branching. Since branching is based on a being 0, it shouldn't have to branch very often and so be 28 cycles saved most the time. Including the initial call, the old version was 60 cycles, so this should be nearly twice as fast. 
fmtHex has been reduced by 4 bytes and between 3 and 8 cycles based on branching.
fmtHexPair had a redundant "and" removed, saving two bytes and seven cycles.
parseHex has been reduced by 7 bytes. Due to so much branching, it's hard to say if it's faster, but it should be since it's fewer operations and now conditional returns are used which are a cycle faster than conditional jumps. I think there's more to improve here, but I haven't come up with anything yet.

* Major parsing optimisations

Totally reworked both parseDecimal and parseDecimalDigit
parseDecimalDigit no longer exists, as it could be replaced by an inline alternative in the 4 places it appeared. This saves one byte overall, as the inline version is 4 bytes, 1 byte more than a call, and removing the function saved 5 bytes. It has been reduced from between 52 and 35 cycles (35 on error, so we'd expect 52 cycles to be more common unless someone's really bad at programming) to 14 cycles, so 2-3 times faster.
parseDecimal has been reduced by a byte, and now the main loop is just about twice as fast, but with increased overhead. To put this into perspective, if we ignore error cases:
For decimals of length 1 it'll be 1.20x faster, for decimals of length 2, 1.41x faster, for length 3, 1.51x faster, for length 4, 1.57x faster, and for length 5 and above, at least 1.48x faster (even faster if there's leading zeroes or not the worst case scenario).
I believe there is still room for improvement, since the first iteration can be nearly replaced with "ld l, c" since 0*10=0, but when I tried this I could either add a zero check into the main loop, adding around 40 cycles and 10 bytes, or add 20 bytes to the overhead, and I don't think either of those options are worth it.

* Inlined parseDecimalDigit

See previous commit, and /lib/parse.asm, for details

* Fixed tabs and spacing

* Fixed tabs and spacing

* Better explanation and layout

* Corrected error in comments, and a new parseHex

5 bytes saved in parseHex, again hard to say what that does to speed, the shortest possible speed is probably a little slower but I think non-error cases should be around 9 cycles faster for decimal and 18 cycles faster for hex as there's now only two conditional returns and no compliment carries.

* Fixed the new parseHex

I accidentally did `add 0xe9` without specifying `a`

* Commented the use of daa

I made the comments surrounding my use of daa much clearer, so it isn't quite so mystical what's being done here.

* Removed skip leading zeroes, added skip first multiply

Now instead of skipping leading zeroes, the first digit is loaded directly into hl without first multiplying by 10. This means the first loop is skipped in the overhead, making the method 2-3 times faster overall, and is now faster for the more common fewer digit cases too. The number of bytes is exactly the same, and the inner loop is slightly faster too thanks to no longer needing to load a into c.
To be more precise about the speed increase over the current code, for decimals of length 1 it'll be 3.18x faster, for decimals of length 2, 2.50x faster, for length 3, 2.31x faster, for length 4, 2.22x faster, and for length 5 and above, at least 2.03x faster. In terms of cycles, this is around 100+(132*length) cycles saved per decimal.

* Fixed erroring out for all number >0x1999

I fixed the errors for numbers >0x1999, sadly it is now 6 bytes bigger, so 5 bytes larger than the original, but the speed increases should still hold.

* Fixed more errors, clearer choice of constants

* Clearer choice of constants

* Moved and indented comment about fmtHex's method

* Marked inlined parseDecimalDigit uses

* Renamed .error, removed trailing whitespace, more verbose comments.
2019-10-24 07:58:32 -04:00
Clanmaster21 cca3157c66 addHL and subHL affect flags, and are smaller (#30)
* addHL and subHL affect flags, and are smaller

Most importantly, addHL and subHL now affect the flags as you would expect from a 16 bit addition/subtraction. This seems like it'd be preferred behaviour, however I realise any code relying on it not affecting flags would break. One byte saved in addHL, and two bytes saved in subHL. Due to the branching nature of the original code, it's difficult to compare speeds, subHL is either 1 or 6 cycles faster depending on branching, and addHL is between -1 and 3 cycles faster. If the chance of a carry is 50%, addHL is expected to be a cycle faster, but for a chance of carry below 25% (so a < 0x40) this will be up to a cycle slower.

* Update core.asm

* Reworked one use of addHL

By essentially inlining both addHL and cpHLDE, 100 cycles are saved, but due to the registers not needing preserving, a byte is saved too.

* Corrected spelling error in comment

* Reworked second use of addHL

43 cycles saved, and no more addHL in critical loops. No bytes saved or used.

* Fixed tabs and spacing, and made a comment clearer.

* Clearer comments

* Adopted push/pop notation
2019-10-17 16:45:27 -04:00
Virgil Dupras f806786bd3 zasm: document lack of support for undocumented instructions 2019-10-17 15:52:59 -04:00
Virgil Dupras 3b1bbc1751 zasm: support negative displacement for IX/IY
Needed by #30.
2019-10-17 15:38:11 -04:00
luz.paz 6a635fddd9 Fix misc. source comment typos
Found via `codespell -q 3 -S ./tools -L splitted`
2019-10-09 11:12:08 -04:00
Virgil Dupras 83b314c450 zasm: lower RAM requirements
I've tested RAM usage when self-assembling and there weren't as high
as I thought. zasm's defaults now use less than 0x1800 bytes of RAM,
making it possible, theoretically for now, for a Sega Master System
to assemble Collapse OS from within itself.
2019-10-06 15:42:09 -04:00
Virgil Dupras e4732d79dc zasm: tighten directive detection a bit 2019-10-06 14:39:47 -04:00
Virgil Dupras f4b6c7637d zasm: rename #inc to .inc
scas, it's not needed any more.
2019-10-06 14:32:23 -04:00
Virgil Dupras 612323f714 zasm: add "last value" symbol (@) 2019-10-04 20:26:21 -04:00
Virgil Dupras 8db1bdb245 ed: add '.' and '$' support 2019-10-04 13:49:33 -04:00
Virgil Dupras c96c8e7df0 ed: update curline after a, i and d 2019-07-25 21:24:36 -04:00
Virgil Dupras d1735c3a73 zasm: remove last remnants of "old style" variables
This makes zasm suitable to run from ROM.
2019-07-25 14:02:04 -04:00
Virgil Dupras 1c6a7caeae recipes/sms/romasm: make zasm's memory usage fit the SMS 2019-07-23 16:50:19 -04:00
Virgil Dupras af0b6231ca recipes/sms/romasm: make ed's memory usage fit the SMS
Yup, that's ultimately why I've just made this whole big zasm
refactoring in the previous commits. To allow for this.

But also, zasm is in much better shape now...
2019-07-23 16:13:52 -04:00
Virgil Dupras c2d84563dd zasm: allow duplicate const definition
This will allow interesting override scenarios, adding flexibility.
2019-07-23 16:01:23 -04:00
Virgil Dupras 1dec33e02a zasm: make symbol registry a bit more straightforward
Instead of strings of variable length driving the iteration of the
registry, we do so through records that keep track of lengths and
counts.
2019-07-23 15:21:42 -04:00
Virgil Dupras 02c7eb0161 zasm: clarify strlen's API 2019-07-23 14:59:38 -04:00
Virgil Dupras cc7a4bae58 zasm: improve .equ duplicate detection handling
Things are a bit more straightforward now.
2019-07-23 14:00:01 -04:00
Virgil Dupras 9ea72dc1d0 zasm: add separate symbol registry for constants
This will allow me to make the ".org" treatment a bit less murky.
2019-07-23 13:59:55 -04:00
Virgil Dupras cdb206b7a5 zasm: fix nasty (iy+d) misparsing bug
*sob*...
2019-07-23 13:58:18 -04:00
Virgil Dupras b95f4c8c24 zasm: remove SYM_CTX_PTR 2019-07-22 16:34:40 -04:00
Virgil Dupras f4f91ebd79 zasm: remove SYM_CTX 2019-07-22 16:13:00 -04:00
Virgil Dupras 311d04e9aa zasm: make symbol registry easily parametrizable
I'm about to split the global registry in two (labels and consts)
and the previous state of registry selection made things murky.
Now it's much better.
2019-07-22 15:13:09 -04:00
Virgil Dupras 0237ff105f ed: fix 'd' going crazy when deleting last lines of buf 2019-07-21 19:43:45 -04:00
Virgil Dupras 0fd16a0bb6 ed: fix boken 'a' and 'd' cmds 2019-07-21 19:32:24 -04:00
Virgil Dupras 421d881fae ed: allow inserting in empty file 2019-07-21 15:06:03 -04:00
Virgil Dupras 34f499184d zasm: add ".bin" directive
Also, remove zasm/test7 because it changes too much all time time
(whenever zasm changes) and isn't precise enough. Too much noise,
not worth it.
2019-07-21 12:58:02 -04:00
Virgil Dupras 01031a780a ed: Add 'w' command 2019-07-21 11:40:26 -04:00
Virgil Dupras f6479486f2 ed: allow appending at the end of the file 2019-07-21 11:12:49 -04:00
Virgil Dupras 8d7abd9994 ed: fix broken buf insert logic 2019-07-21 10:53:11 -04:00
Virgil Dupras 1a5a1b9861 ed: make scratchpad memory only
The dual scraptchpad thing doesn't work. Things become very
complicated when it's time to write that back to the file. We
overwrite our contents and end up with garbage.
2019-07-21 10:45:58 -04:00
Virgil Dupras 942d2a952d ed: take filename as an argument
This hard-binds ed to the filesystem (I liked the idea of working
only with blockdevs though...), but this is necessary for the
upcoming `w` command. We need some kind of way to tell the
destination to write to truncate itself.

This only has a meaning in the filesystem, but it's necessary to
let the file know that its registered file size has possibly
shrunk.

I thought of alternatives that would have allowed me to keep ed
blkdev-centered, but they were all too hackish to my own taste.

Hence, this new hard-bind on files.
2019-07-20 19:43:07 -04:00
Virgil Dupras fe15bafeca zasm: fix bug with registry selection
During expression parsing, if a local label was parsed, it would
select the local registry and keep that selection, making
subsequent global labels register in the wrong place.
2019-07-20 18:07:52 -04:00
Virgil Dupras eefadc3917 ed: add support for 'a' and 'i' 2019-07-14 17:35:21 -04:00