Θεόδουλος Λιοντάκης

Δάσκαλος Πληροφορικής ΠΕ86

Στατιστικά

Εμφανίσεις Άρθρων
17421

 

I was seeking for a stronger and faster than Tiny Basic computer language for my FPGA CPU and system.

I was searching for an easy to port C compiler, but there was none without a long boring learning curve.

Then I thought what about other languages, java compilers produce an intermediate code "bytecodes" that run on virtual machines in different computer architectures and it is possible to compile it to produce native assembly.

I was lucky that Michael Kohn has done this in a very nice open source project named java-grinder for many CPU and systems. I studied this project and in a few days I was able to run the first java programs at Lion computer.

I made a generator that produces relocatable Lion assembly source code and a API with the necessary routines.

29/8/2018 Lion java integers are 16bit so I added static long variable (32bit) support and the relative operations (+,-,*,/,%, int_to_long, long_to_int, long compare), and print_long api routine.

21/9/2018 Added static floating point arithmetic (32bit) +,-,*,/, print_float(), float compare, float_to_int, int_to float, long_to_float, float_to_long, sin, cos, sqrt, log, exp, pow (raise number to power approximation)

20/9/2019 Added load and save routines,  for transfers between a byte array and a file in sd. Also added a delete file routine.

 

  a simple asteroids style game:

 

and a galaxians clone:


 

current API routines include:

  public static void cls()
  public static void putChar(int y, int x, char c)
  public static void screen(int back, int fore)
  public static void out(int address, int word)
  public static void outb(int address, int b)
  public static int inp(int address)
  public static int inkey()
  public static void print_str(int y, int x, String s)
  public static void print_num(int y, int x, int n)
  public static void print_unum(int y, int x, int n)
  public static void print_long(int y, int x, long n)
  public static void print_float(int y, int x, float f)
  public static int timer()
  public static void scroll_up()
  public static void plot(int x, int y, int mode)
  public static void sound(int channel_no, int freq, int duration)
  public static int isplaying(int channel_no)
  public static int joy1()
  public static int joy2()
  public static void noise(int onoff)
  public static int rnd(int num)
  public static void poke(int address, int word)
  public static int peek(int address)
  public static float sin(float rad)
  public static float cos(float rad)
  public static float sqrt(float rad)
  public static float log(float x)
  public static float exp(float x)
  public static float pow(float x, float y) 
  public static int loadbin(String fname, byte buffer[] )
  public static int savebin(String fname, byte buffer[], int size )
  public static void deletefile(String fname)
  public static void vscroll(int l1, int llen, int p1, int plen, int lines)
  public static void hscroll(int l1, int llen, int p1, int plen, int pixels)
  public static int abs(int i)
  public static int sign(int i)
 

Sample program that runs on Lion:

 import net.mikekohn.java_grinder.Lionsys;

public class Testing
{
  public static String strMsg = "Hello Lion from JAVA";
 
  static public void main()
  {
    Lionsys.cls();
    Lionsys.screen( 4, 7);
    Lionsys.print_str( 12, 10, strMsg);
    int key=0;
    while (key==0)
    { key=Lionsys.inkey(); }
  }
}

and produces the following code:


; .Lion
heap_ptr equ 46000
ram_start equ 46002
strMsg EQU 46004   ; Ljava/lang/String;


ORG         0  

start:
  ;; Set up heap and static initializers
  MOV  (heap_ptr),46006
  GADR A7, _strMsg
  MOV (strMsg), A7

main:
  PUSH A1
  PUSH A2
  PUSH A3
  PUSH A4
  PUSH A5
  PUSH A6
  PUSH A7
  PUSHX
  SUB SP, 2
  MOV A6,SP
  ADDI A6,2
  ; cls
  MOVI A0,3
  INT 4
  PUSH $0004
  PUSH $0007
  ;screen
  POP A1
  POP A0
  SLL A1,3
  ADD A1,A0
  SETX 1983
  MOV A0,61152
  Label_0: OUT.B A0,A1
  INC A0
  JRX Label_0
  PUSH $000c
  PUSH $000a
  ; get static
  PUSH (strMsg)
  ;; putSTR
  POP A1
  POP A0
  POP A2
  MOVHL A2,A0
  MOVI A0,5
  INT 4
  ;; set_integer_local(0,0)
  MOV    A3,A6
  ADD    A3,0
  MOV    (A3), $0000
main_21:
  ;; push_local_var_int(0)
  MOV    A3,A6
  ADD    A3,0
  PUSH (A3)
  ;; jump_cond(main_32, ne)
  POP A7
  CMPI A7,0
  JRNZ  main_32
  ; inkey
  MOVI A1,0
  MOVI A0,0
  INT 4
  BTST A0,1
  JRNZ Label_1
  MOVI A0,7
  INT 4
  BTST A0,2
  JRZ    Label_1
  MOVI A0,10
  INT 4
Label_1:
  PUSH A1
  ;; pop_local_var_int(0)
  POP A7
  MOV    A3,A6
  ADD    A3,0
  MOV (A3),A7
  JR main_21
main_32:
  ;; return_void(1)
  ADD SP,2
  ; pop all
  POPX
  POP A7
  POP A6
  POP A5
  POP A4
  POP A3
  POP A2
  POP A1
  RET

  XY_ DW 0
print_xy:
  PUSH A2
  PUSH A0
  MOVR A2,(XY_)
  MOVI A0,4
  INT 4
  CMP A2,63
  JRZ 6
  ADD A2,$0100
  MOVR (XY_),A2
  POP A0
  POP A2
  RET

  DW 20
_strMsg:
  TEXT "Hello Lion from JAVA"
  DW 0