Tuesday, April 28, 2020

AMOS, 3 solutions for 3 different problems.

 

 3 solutions for 3 different problems.

AOZ is a web-based solution written in Javascript, intended to run on anything that supports web gl, and Web Assembly. Written
by author Francois lionet.

Amos Kittens a portable interpreter written in C / C ++, with the ability run native and has access to native filesystem and other resources, with the intent of remove EUAE from
the depenency, Amos Kittens was written by me Kjetil Hvalstrand, project was started around 2017.

Amos Proseronal a development tool meant for beginners in programming, created for Classic Amiga at 198x / 199x, with long history with many extensions. written by Francois lionet. the AGA version is being worked on by Frédéric Cordier.

Before Amos Kittens there was something called XAMOS, but it has no relation to Amos kittens project, XAMOS/JAMOS was written in C and Java, by
author Stephen Harvey-Brooks (Mequa), Stephen Harvey-Brooks passed away in 2015. project stopped,

So way AMOS in 2020, well it’s because there are people not like me who has little or no time, but wont be creative, and need safe simple to write programming language, that do not wont mess around programming language’s that crash or freeze the operating system, and just want have fun, playground bobs / sprites and collation detection.  

In addition to this Amiga community is fragmented, this makes hard for developers to make money, because you only can sell your product ¼ of the community, I wonted to give the developers to expand there market, and to become more successful.


By keeping Amos kittens open source, its now possible to see ports to MorphOS and AROS, becouse I'm only one person working on Amos Kittens, I'm focusing on AmigaOS4.1, AmigaOS1.3 - 3.9 has Amos Professional, of couse as prof of consept it be interesting to backport it AmgaOS1.3-3.9, and also for fun compare it the orginal Amos on same CPU, we need to cut down memory foot print, but should be doable. 



Normally C/C++ programs run slower and take more RAM then things written in assembler, but there are some advantages as its easier to work in C/C++ then its to work with 680x0 assembler, there many cases where source code is sold, but nothing is done because source code is impossible to read.

Saturday, May 5, 2018

Amos Kittens A new Amos interpreter for AmigaOS4.1

Typical way to run Amos under AmigaOS4.1 is by lots and lots onion layers.


Amos kittens removes two layers, hardware emulation and Classic AmigaDOS/Workbench.
And adds a new layer called RetroMode.library, that only simulates graphic but not exactly, first of all It's chunky not planar, it does not support dual playfields. Everything else should for the most part work similar.


You notice that Amos games now have closer access to AmigaOS4.1, this opens up a lot of opportunities, that we did not have when we were boxed into EUAE, USB support, AHI Support, long filename support, large disk support and all new stuff, that AmigaOS4.1 have, that AmigaOS3.x do not have.

The access from Amos game to AmigaOS is limited by only having access to old JMP tables, and only being able to execute 680x0 code, the AmigaOS4.1 hardware ranges from hardware that have Paula/Denice and hardware that don't, so it is extremely dangers to try to access hardware. 
This is way the lines are dotted.


Written small table to compare Amos Pro vs Amos kittens, 


Amos ProAmos KittensXAMOS
Project start199020172012 (ported from JAMOS)
ColorsPlanar 1bit to 6bit (64 color) / HAM6 (4096)Chunky 8bit (256 colors/RGB 4096), (future support for 32bit)True Color (32bit)
FontsBitmap fontsBitmaps fonts + Bullet fontsTrue type
Filesystem32 chars filenamesnow 32 chars, (128 chars in the future)N/A
Dual PlayfieldsYesNoN/A
Load iff/Save Iffloads iff files.Use datatypes loads any pictureN/A
JoyPorts2 x Game ports (planned support for cd32 gamepads)Amiga Input (USB gamepads) same commandsN/A
Color FlashyesyesN/A
Color cycleyesyesN/A
Rainbow effectsyesyesN/A
GraphicsOCSRetroMode.libraryRudimentary Amiga-style screen and scrolling engine
Assembler 680x0yes680x0 (using Exec.library/EmulateTags)No (Unlikely based on JAMOS)
Assembler PowerPCno(maybe in the future)No
Bobs/Spritesoftware bobs/hardware spritessoftware spries and bobsYes
Source code format Tokens (execute orginal source code)Tokens (execute orginal source code)ASCII / MequaScript (Not AMOS compatible syntax)
Extensions 68Kyes (680x0 assembler, hunk format)Not initially (Some help appreciated)N/A
Extensions PPCnoIn the future ".library" format (C lanuage)N/A
File size32bit / 2 Gbyte32bit (64bit in the future)N/A
AudioPaula 8bitAHI 16bit sterro (software mixed 4 channels 8bit)N/A
Max screen resolutionHires / interlaced (640x512)Standard P640x512 - Can be hacked up HD resolutions.N/A
FullscreenyesyesN/A
Window modenoyesN/A
iconifynoyes should be possibleN/A
workbench modenomaybe in the futureN/A
CrossDOSyesno, whats the point?N/A
Serial portyesno, use SER: deviceN/A
decimal precisionfloatread floats, math is done in doublesN/A
max string length65535, The strings are not required to be NULL terminated4 Giga bytes of chars, strings are compatible but always NULL terminated.N/A
ABK supportyesyesYes
3DSoftware 3DNo, Future maybe Warp3D Nova.N/A / (OpenGL)
"To" CommandCommands that use TO, the TO command most be used. (“TO” command is used inconsistent in commands, it can be confusing for beginner.)No requirement: Command TO is most often treated as a comma, and is not needed, it will depend on the command if its needed or not, make sure to use it if want to write compatible code.N/A
Text encodingASCIIASCIIUTF8
Cross platformNo (But the source code can be used in Amos Kittens)Yes, Open source code, can be ported to other systems.Yes, already runs on Windows, AmigaOS, Linux (OpenGL/SDL backend)
AmalYesYesYes,(XAMAL?)
Interface languageYesYesNo

Mequa32 youtube channel

https://www.youtube.com/user/Mequa32/videos

Friday, February 12, 2016

LiveForIt Music and UTF8.library

I have not really written a lot on blog lately, mostly just doing my own thing.

Anyway, I have finally found a program worth doing on AmigaOS, well actually there many programs, worth doing, it's just finishing the programs, and having the tools you need to write programs, is not always easy.

One of this tools is UTF8, is widely used text format that unlike ASCII preserves chares in a format can be shared on the internet, instead of chars, UTF8 uses glyphs or same numbering as used by your fonts, so you don't need to lookup glyphs from a code page table.

It's compact, and is compatible with ASCII 7bit, or US chars, 8bit is used for encoding, this allows 2 or 3 or more bytes, if required to store glyph numbers, it's sort of a compression, but as developer you don't need to think about that as long as you stick to UTF8 functions.

Besides being able to convert between ASCII and UTF8, you need a way to display the text format. This been totally lacking, in AmigaOS, and continues to be issue, today. But I don't need to wait for Hyperion and there slow progress, some things I can do myself.

But every attempt I have tried as failed until now, I blame bad documentation, and lack of simple examples. Every time I have asked for help, I have been pointed in direction of big hunk of code called NetSurf, that by the way hides just the part I need to know. In different file then one I was pointed two and it also hides, font engine part in macro, so what I was looking for was not really a different variable, but outline fount struct. That I had all along, coding can be frustrating some times, but so pleasing when find out way did not work.

Once I found a BlitzBasic2 example that tried translating, it was just a waste of time.

The other document I have looked at, was the page on the Amiga wiki, that suggest using bitmap fonts, the document is obsolete, and has more historical value then real value. Someone started the transaction of document but stopped half way in.

But as long as one don't give up there is hope, just keep on keeping on, like the Americans say.

The Amiga developer saying "Two more weeks" is not what I'm thinking of, that sort reminds me about when I wake up in the morning sleepy as hell, thinking I have time, I sleep just a few min more, and the I wake up 15 or 30 late for work, and wake up praying there no traffic. Lucky everyone else on road is also late for work so at least only a few people are driving under speed limit o_O.

I'm not 100% sure I know what "keep on keeping on" means, but it sort sound like stay focus on what you're doing, and don't give up. When write software it easy to get distracted and will not do something else, and that might be good thing some times, but it extremely easy to just forget about things, and they never get finished. You need to keep some focus on what you're doing.

And it's probably better to release something that is 90% finished then to never release the software at all. That is sort what I did with UTF8.library, it did have text formatting part done. More or less, now, it time up upload a new one, I need some time update the documentation.

Next is getting LiveForIt-music ready, as I was saying before I'm not on a dead line, I'm just making sure the things that should work works.

Wednesday, October 7, 2015

Curves

So what have I been work on lately, for some time now I have been working again, so less hours to experiment and work on things, actually feel the need turn off the computer sometimes.

Anyway, I'm a geek and geeks can't turn off the computer for too long before curiosity takes over.

Lately I have been investigating curves, I know what you are thinking, and It's not that, I'm not stupid, I know to keep my distance.

I'm talking about other types of curves, or mathematically draw curved lines.

Now you thinking maybe taking about y=(x*scalefactor)^2, or y=sin(x)*scalefactor.
No formulas like that only draws curves in y direction, you can't have diagonal curve, or curve between two random coordinates, using formulas like that.

So there is a video from Steven Wittens, on youtube, that I really enjoyed.

https://www.youtube.com/watch?v=Zkx1aKv2z8o&index=6&list=WL

Bezier curves!!!!

So way on earth is curves important, well you draw thing in paint program save image use that, no need to know how it was done, but realize the paint tools use curves.

Even the fonts I use for this text I have written, uses some curve, SVG image or vector images, use curves, flash videos, and lots of other things.

So the best way to play around with curves is a editor, or program you drag curves around, and this what I did, soon I complete the program, as simple toy.



So way not use library someone else has made, way spend this amount of time on something you get for free, well what is fun in that, coding is about figuring things out, and play with things, learn something, the most fun I have had is maybe programs I did not complete. Just experimenting on things.

So why don't you work on mplayer, well the answer is I need a break from mplayer, and it has become work, coding should be fun, so this way I doing this I guess.

Tuesday, August 11, 2015

PowerPC code optimization, experiment, code generator part 2.




Lately I have been experimenting, using sort of JIT engine to generate machine code, the graph above is example of what, I can do.

The graph test performance of the code deepening on x and y factor, to find the ideal condition for the best speed.

X axes is the number of unrolls / float point register used (unrolls), the Y axes is the max number of code block per loop.

The test runs 64000 int to float conversion with a float point scale factor.

So what you see is that number of unrolls help, but if the code in loops gets to big, the speed goes down.

This kind of test if I wrote it by head takes a month, but as I'm generating the code. I can try different combinations in a few seconds.

The same kind of code generator test can be done on any type of assembler code, it works on AltiVec, FPU or CPU instructions.


Sunday, July 26, 2015

PowerPC Machine Code generator Experiment.

PowerPC Machine Code generator Experiment.

I have been looking at ways to convert float to int fast, lately.
I have been thinking about this video.

https://www.youtube.com/watch?v=So-m4NUzKLw

C64 Demo coders trying to make C64 do more than they should able to do.
So there has been lots of talk about JIT compiler in Amiga community, EUAE jit compiler by Álmos Rajnai.

JIT compilers made a big difference in speed.

What I wont to find out.

1)
If the loops that GCC can't unroll, is unrolled by the machine code generator what difference does it make, to unroll the loops completely.

2)
So what I was wondering about is, if it was possible to generate code scaled to Instruction cache, to eliminate unnecessary machine code, and eliminate cache misses.

3)
Does it make difference to try unroll loops or not, in C code.

Disclaimer:

I'm no expert in PowerPC assembler, but I have some experience with assembler trying to code for MC68000  using inline assembler on Amiga500/BlitzBasic2, and from my school years at "VK2" Data Technical, and for 2 years at Technician school at Kongsberg, coding the Z80, 6802/6804 chips, as educational tool. I have some experience with PowerPC, trying to optimize things in Basilisk II, So I'm not hard core Machine code head.

If you ask me about name of some opcode, I will not know too many years ago, but fundamentals is the same, interrupts, machine code, thing stored, thing gets loaded, added, registers, flags.

The rules of the game.

So normally your write inline assembler, we let the compiler pick the registers, and handle saving and restoring registers, but we are not going to do this.

This how GCC normally generate code.

R0 is used for temporary storage.
R1 is revered for stack.
R2 is reserved, your not allowed to use this one.
R3 to R10 can be used for arguments.
R3 is also used as return value.

Using the optimization 3 in GCC or O3 flag, GCC expects R4 to R10 to be unchanged.
So this is the basic game rules we need to keep in mind.

Other things we need to think about is that memory going to execute need to be flagged for it to be executable, unlike on 680x0.

Before the memory is executed, we need to flush instruction cache. If we don't do that, we can't be sure the machine code in cache is correct. Unless we flush it.

So next, I'm going to explain the procedure, of finding the machine code, and understanding whats going on, the tools.

Well there is "GCC", write some C code, compile it, and then disassemble it, look at the result.
to disassemble, I use objdump.

objdump -d a.out
or
objdump -d -S a.out

So what you see.
The relative address, then the machine code, and then assembler name, command.

So to generate machine code, I need the machine code, the assembler name, is only useful to understand what machine code does, who remembers hex numbers?

Well you can look up IBM documentation, but they are not good, if you want to write code, they explain what assembler does, but not what assembler opcodes that goes with that, (there is no see also reference.)

So as noob you get stuck quickly, if you only try to read there documents.

Time for the code


So here is we have a typical function, so to convert x number of floats to int's.








This the same function, we have unrolled it, so that it takes fewer loops to execute, some people says this does not make any difference, that C compiler do that anyway, well we see :-)












This the typical machine code, you get when decompile a C program compiled with no optimization, I have added two machines codes extra to load R3 and R4, this because of GCC O3 flag.

When compiled with O3 flag, the stw, r3 and r4 is stripped away by the compiler, what stw does, is store the r3 and r4 registers on stack.
















This is the actual code, we need to run many times, again there are two extra machine codes I have added, to move to next source and destination address, the addi r3,r3,4 and addi r4,r4,4.

I was shocked at amount of instruction needed to do casting between float and int.
converting between int and float should be avoided at all cost on the PowerPC.











This is a for loop that is disassembled. Well I can't copy the code as it is, as the "blt-" opcode offsets, and "b" opcode offsets, need to be calculated.

Set_jit_loop() functions does this, the functions takes number of loops, and the amount of code that goes between the loop, so it can be inserted between the two tables.




















So this function alloc's memory for code,
the result is

"function start"
"float to int" * loops
"function end"





















So this function alloc's memory for code,
the result is

"function start"
"for n=1 to num_loops_needed"
"float to int" * in_cache
"next"
"float to int" * don’t_fith
"function end"

So this is bit smarts, we try find out what max number of float_to_int we can fit into instruction cache. What I found out is that its not the cache size that is the limiting factor, but max length of indirect jump, that is real limit :-/






















Just free the memory after we are done








The main code that runs all the tests










































Now for the results.















Trying to fit code inside the instruction cache made little difference, it mostly a waste of time trying to do it.

Assembler optimized the code, made a big difference compared to C code compiled without optimization flags.

Compiling standard C code with O3 flag, made big difference, there is almost no different between assembler optimized code and standard C code.

However, look at unrolled C function, it's was slower without being optimized, but with O3 is just beats everything.

I guess it is because GCC is able, to take advantage of out of order execution on PowerPC, GCC cannot unroll the normal C code, because the number of loops is not static constant, but variable number loops.

So conclusion is, what you write and how you compile the code, make the most difference, betting the C compiler is hard, even if you are an expert.