среда, 8 мая 2013 г.

Rainbow Fuji

Another attempt to repeat the famous Atari rainbow Logo.
Here I'm trying to use PL65 internal assembler and GRAPHICS library.

At first, we need to draw Atari Fuji, thus we need to convert Polar to Decart and so we need INTEGER algorithm for Square Root calculation.
(Not float. Sic! No one really needs semipicsels!)

Something from Internet:
Let's begin to substruct ALL INCREASING INTEGER ODD NUMBERS, while the result is not negative...
And the quantity of steps will be the square root.

SQRT(32)=5
32-1=31 -> 31-3=28 -> 28-5=23 -> 23-7=16 -> 16-9=7 -> 7-11<0
   1          2          3          4          5

The PL65 Code of Sqrt() Function (in MATH.LIB):

! -----------------------------------
! Calculating Square Root from Integer
! On entry INP contains input Integer
! On exit OUT contains SQRT, OUT+1 contains Reminder
FUNC Sqrt(INT INP)
  INT OUT
BEGIN
  STX XSAVE
  LDY #$01; STY OUT; DEY; STY OUT+1
:again
  SEC
  LDA INP
  TAX
  SBC OUT STA INP
  LDA INP+1 SBC OUT+1 STA INP+1
  BCC nomore
  INY
  LDA OUT ADC #$01 STA OUT
  BCC again
  INC OUT+1 BNE again
:nomore STY OUT STX OUT+1
  LDX XSAVE
END OUT

Really, OUT is a temporary accumulative varyable ...

1 - The hard rule of PL65 is:
Using 6502 X-register in any way without it's previous saving will kill software stack pointer of PL65!!! (and your beloved program...)
THUS: Save X to XSAVE before!!! And restore it from XSAVE after ...

2 - When we ADC 1 with CARRY being previously set we adds CARRY value too!
Thus in fact we adds 2! And our numbers stay odd anyway!

3 - Using ; - sign in assembler part of PL65 prevents compiler from mixing for example assembler ;AND operator with high level PL65 AND statement!

The next assembler part is rainbow effect itself.

The Code!
! =================================
! ALOGO.PRG
! Draws Fuji with Raibow effect
! CopyLEFT (C) 2013 EZsoft
! Uses MATH.LIB & PEEKPOKE.LIB !!!
! =================================
INCLUDE D:MATH.LIB
INCLUDE D:PEEKPOKE.LIB
INCLUDE D:GRAPHICS.LIB
! -----------------------------------
! Draws rectangle Canvas
PROC Canvas(BYTE Col INT X0,X1 BYTE Y0,Y1)
BEGIN
  COLOR=Col
  PLOT(X0,Y1) DRAW(X1,Y1) DRAW(X1,Y0) DRAW(X0,Y0)
  POKE(765,3) ! Color of canvas frame
  GFILL(X0,Y1)
END
! -----------------------------------
! Draws ATARI Fuji Logo
PROC Fuji(BYTE Col)
  BYTE T,B INT R
BEGIN
  COLOR=Col T=20 B=76
  FOR R=80 TO 84 DO
    PLOT(R,T) DRAW(R,B) PLOT(160-R,T) DRAW(160-R,B)
  NEXT
 
  FOR R=86 TO 115 DO
    IF R>90 THEN T=43+Sqrt(626-(116-R)*(116-R)) ENDIF
    B=45+Sqrt(962-(116-R)*(116-R))
    PLOT(R,T) DRAW(R,B) PLOT(160-R,T) DRAW(160-R,B)
  NEXT
END
! -----------------------------------
! The famous Atari Rainbow effect
PROC Rainbow()
BEGIN
  REPEAT
    LDA $D200 ! POT0
    ADC $14   ! RTCLOK+2
    STA $D017 ! COLPF1
    LDA $D40B ! VCOUNT
    SBC $14   ! RTCLOK+2
    STA $D01A ! COLBK
    STA $D40A ! WSYNC
  UNTIL (PEEK(764)=28)
END
! -----------------------------------
! Main program
MAIN()
  BYTE Col INT X0,X1 BYTE Y0,Y1
BEGIN
  GRAPHICS(7+16)
  POKE(708,28) POKE(709,52) POKE(710,0) POKE(712,148)
  Col=1 X0=35 X1=125 Y0=12 Y1=85
  Canvas(Col,X0,X1,Y0,Y1)
  Col=2
  Fuji(Col)
  Rainbow()
END

It works!

суббота, 30 марта 2013 г.

I love this blog very much.

http://atariaction.tumblr.com/post/37174168567/day-1-getting-started-with-action
 
Kevin Savetz is a very good man trying to say us that there are MUCH more ways to think in a computer way than evidently posessed.

I'm trying only the next one attempt.
Seriously the reason to wrighting something here is my impression of his blog.

When I tried to convert ACTION! program to PL65 I've ran into the first problem...
There was no function in PL65 returning random value between 0 and 1.

So, it's my duty.

The Code:

FUNC RAND()
  CONST RANDOM=$D20A
  BYTE B
BEGIN
  B=PEEK(RANDOM)
  IF B>127 THEN B=1 ELSE B=0 ENDIF
END B


Here we get semirandom value from HW RANDOM register and as we know that it's between 0..255 then we set a border for making choice. 127 is a right value.

And the code of full program:

INCLUDE D8:TERMINAL.LIB
INCLUDE D8:PEEKPOKE.LIB

  INT X

FUNC RAND()
  CONST RANDOM=$D20A
  BYTE B
BEGIN
  B=PEEK(RANDOM)
  IF B>127 THEN B=1 ELSE B=0 ENDIF
END B

MAIN()
  BYTE B
BEGIN
  POKE(82,0)
  WRTSTR("GO") CR()

  REPEAT
    X=(6+RAND())
    PUT(0,X)
  UNTIL PEEK(764)=28
END


Here is TERMINAL - for I/O
PEEKPOKE - for ..?
Hmm! Peek and Poke!

And at last It's work!

суббота, 23 марта 2013 г.

To Learn

Being a clever boy (IMHO) I'm trying to investigate PL65 Libraries.
It's an only right way to learn languages!
And now - the most important - terminal.lib ...
FE Here it is a code of CIO utility!


(Not so sofisticated idea of filling memory from soft stack to previously counted place... Right?)

Do you like to keep LDA-STA in one text line?
Do you like :ioerr LABEL? (It calls from another subroutine...)
Here STACK - is active PL65 internal pointer to STACK beginning.
So XSAVE is Z-Page place to save 6502 X-Register.
RETURN - EXIT from routine.

Does anyone can say that it's no assembler?
- I can!

One of the last strings shows that it calls 'WRTSTR' - a high level function that is not assembler at all!

The asterisk after the name of function shows that it's a case of 'CLOASURE'.

The calling function calls another which needs calling function!
Alice in Wanderland!

Really 'WRTSTR' needs CIO for it's text output.
But CIO needs WRTSTR for ERROR indication!

Next...

Today I can't say that I understand a way how the internal assembler interacts with compiler.
I know how ML interacts with BASIC. I know how ML Interacts with ACEC or CC8.

Today I know that PL65 uses programmed (it's own) stack. I don't know how it does...

Sorry, but now I'm working on bitwise and screen libraries and I can't 'goto' realy fast asm version of them. I'm learning only PL65 now!!! No ASM.

And now - my impressions about PL65...

Anyway it saves my nerves in a way that it taking care of memory utilization like BASIC.
Someway strange, someway right... Anyway I feel it!

(Really I feel that 90% of test programs are good and another is my own errors.
anyway in 'C' it-s not so good. I'm not a programmer at all! )
Now I think that inspite of abylity to create BYTE variables etc.,
PL65 uses ONLY INT's !!! ... and drops MSB's in case of BYTE.
Anyway it's 'counting' variables (FOR ... NEXT... FE) all are INT!!!

You can't write:
FOR I=1 TO 2 WRTSTR("I Love YOU!!!") CR() NEXT

You previously MUST say that:
INT I

(So you must think that your own abylity to love 'someone' goes to 65536 times !!!)
At a boy!!!

- It's PL65!

CUL8R

воскресенье, 17 марта 2013 г.

Let's begin.


Let's begin.

 After more then 30 years of working my beloved Atari 130XE lost it's memory.
Memory chips are broaken. Full sclerosis!

So I was forced to work with emulators.
They all are perfect enough but my personal preference is Altirra.

IMHO the most valuable feature of Altirra is that even in "Warp Speed" mode it stays the speed of emulated keyboard on Windows responcibility (what saving standard Atari keyboard speed) instead of WarpSpeeding of Atari keyboard what leads to keystrokes like this:
DDDDDDDDDDDDDDIIIIIIIIIIIIRRRRRRRRRRRRRR
and then terrible "File not found"...

Then lets begin.
Today I worked on creating useful ATR disk image for investigating PL65.
These efforts are documented here.

My goal was to determinate the cummulative comfort of PL65 as Integrated Programming Environment.
I prefere SpartaDOS as Atari Operating system. But I'm not sufficiantly qualified for SDX memory adjustment and thus the first memory problem will became the last.
I'm using Sparta, which can recognize H6: device of Altirra (This device converting ATASCII to ASCII and vice versa automatically thus I can write my codes in Windows and I can read it from emulator as standard Atary text.) Fortunately PL65 compiles from plain text instead of using tagged symbols.
And of course this DOS must be compatible with PL65 itself.

Here is the directory of disk:


Some more about utilities... I'm using AC.COM from "MAD TEAM" as the best file manager and txt/doc viewer, EDIT.COM as very useful text editor, DESEG.COM as file desegmentator (Both are created by great FJC), SHELL.COM and SFX.COM (by famous Tom Hunt) as PATH saver and selfextractor, and CHVOL.COM (May be Tom Hunt's too.) as volume renaming tool for Sparta and, at all I,m using HYPRAM.COM as 1088mb Ramdisk. That's all.
It's amusing that first time I have launched PL65.COM for obvious "Hello world!" compiling I saw this picture after all:


Noahsoft exhaustively working on PL65 have forgot about returning HW Atari cursor into scene. And this is a case of the need for programming in PL65!

I have launched Editor and after editing code and pressing a SECRET COMBINATION of OPTION+Escape tried to Compile the program.

Here is the result. Bad code:


It is a working PL65 code:


! CURSOR.COM
! The utility for restoring HW-cursor
MAIN()
  BYTE CRSINH=752
BEGIN
  CRSINH=0
END

And as the result:

PL65 Noahsoft(C)1987

Some words about Noahsoft(c)1987 PL65.

At first It’s a compiler for 8-bit 6502 computers. I even don’t know was it designed for other then Atari 8-bit machines or not. Anyway I love Atari 8-bit from early 90-th.
This Programming Language has nothing concerned with well known respectable PL/1.  If you ask me what’s it like?  I’ll be in some kind of trouble.  The fact is that PL65 was born earlier then C.  And there were times when no one knew exactly how to design a programming language.  Seriously it looks like mostly ALGOL, then C and BASIC with ASSEMBLER simultaneously. I think it was an eclectic mixture of all of them with the purpose of giving to programmers their benefits.  Thus you can realize that Noahsoft gave not only benefits but their shortcomings too.

Certainly  it is a high level programming language with extensive system of structuring but it has BASIC’s rudiments like “GOTO label” and also fully featured 6502 assembler and pointers of some kind like in C.
Well, are you intrigued enough now?
Some words about me.
I’m Russian.  My English is too bad for normal conversation.  But be aware that my Russian is much better.  No mean. I only want to learn PL65 and English of course too.

So your advices concerning programming or learning English will be highly appreciated.