Tunguska the ternary emulator

Balanced Ternary Numeral System - forum was moved from http://ternary.info

Moderator: haqreu

Mac Buster
Retired
Posts: 1474
Joined: 03 Aug 2003 22:37
Location: Moscow

Re: Tunguska the ternary emulator

Post by Mac Buster »

Here is code for my first simple program for Tunguska :lol: It just fills screen with pixels of different colors, kind of simple colours test table.

Code: Select all

; Kind of color table test for Tunguska
;
;  Assemble into demo.ternobj
;  Run 'tunguska image.ternobj -F demo.ternobj'
;  Type 'LOADSUB'
;

@ORG    %DDD000
        ; Bootstrap function
        ;
        ; Read page 2 from disk into page 2 in memory
        LDA     #2
        LDY     #2
        JSR     (jumpvector.fl_read_block)
        JMP     colortable

; These won't be copied. They are also present in the host at the same
; memory location. 

@ORG    %001000
jumpvector:
.getstring:     @DW     0
.feedscreen:    @DW     0
.putchar:       @DW     0
.putnon:        @DW     0
.puts:          @DW     0
.strcmp:        @DW     0
.strlen:        @DW     0
.index:         @DW     0
.strspn:        @DW     0
.strcspn:       @DW     0
.memset6:       @DW     0
.random:        @DW     0
.between:       @DW     0
.repaint:       @DW     0
.fl_read_block: @DW     0
.fl_write_block: @DW    0

@ORG    %002000
colortable:
                ; Enable raster mode
                LDA     #%00C
                STA     %DDDDDB

                ; Load screen buffer address
                LDX     #%DDB
                LDY     #%DDD
.mainloop:		
		LDA	.colornum
		INC	.colornum
		STA	X,Y
		INY
		JVC	.pass
		INX
.pass:			
		TXA
		CMP	#%CAB
		JNE	.mainloop
.idleloop:
		JMP	.idleloop

.colornum:
		@DW	%444
P.S. Raster mode isn't so fast :-(
Mac Buster
Retired
Posts: 1474
Joined: 03 Aug 2003 22:37
Location: Moscow

Re: Tunguska the ternary emulator

Post by Mac Buster »

Could you please add something to redirect text mode output to a regular text file ? Will be very useful for testing arithmetics functions.
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Tunguska the ternary emulator

Post by eudoxie »

--edit-- browser crashed and made two identical posts.
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Tunguska the ternary emulator

Post by eudoxie »

Mac Buster wrote: Here is code for my first simple program for Tunguska :lol: It just fills screen with pixels of different colors, kind of simple colours test table.
Glad you got it working...
Mac Buster wrote: P.S. Raster mode isn't so fast :-(
Yeah, I know. It would be possible to add more raster modes at the same resolution but with fewer colors (I'm thinking three and nine colors, 18 and 36 memory pages respectively). This would probably amp up the drawing speed quite significantly (at those modes, anyways). For the nine color mode, it would probably be possible to use some sort of palette mechanism to allow for a wider range of colors.
Mac Buster wrote: Could you please add something to redirect text mode output to a regular text file ? Will be very useful for testing arithmetics functions.
I guess I could add functionality to the Print Screen button, so that it when it is pressed, the screen contents are written to the terminal (much like the original functionality of Print Screen button)
User avatar
Shaos
Admin
Posts: 24008
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Tunguska the ternary emulator

Post by Shaos »

eudoxie wrote: That's peculiar. Could you try compile some other automake-based package and see if it does the same? It attempts to install to /usr/local/bin on my system.

--edit--

I just released version 0.0.2.
This version uses /usr/local/bin

In CYGWIN it's configured, but not compiled - can't find SDL includes...
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Tunguska the ternary emulator

Post by eudoxie »

Cygwin is a special case I guess. For now, if you want to build ports, just use the CVS makefile (it seems to work, no?)

I added two new instructions to the CVS: BLS and BLT. They do page manipulation, so you can copy or set entire pages with one instruction. (Which is very useful in raster mode, since basically all the "slowness" isn't so much the screen drawing functions, but Tunguska itself not being able to process instructions fast enough)

I also added 3 color monochrome graphics as I discussed earlier.


--

I'm working on an experimental bitmap-based UI for tunguska to make it a little more inviting and easy to use. The light gray bars around the screen indicate where the raster-mode screen ends.


It's not in CVS yet, because I can't decide if I like it or not. There's something off about it, but I can't quite put my finger on it...

Image
User avatar
Shaos
Admin
Posts: 24008
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Tunguska the ternary emulator

Post by Shaos »

eudoxie wrote: Cygwin is a special case I guess. For now, if you want to build ports, just use the CVS makefile (it seems to work, no?)
Yes, it works. Another "unofficial" build for Windows is ready:

http://nedopc.org/ternary/tunguska/tung ... _1-win.zip (1.3M)

It includes colors.asm with bat-files for compilation and launching
Last edited by Shaos on 11 Nov 2012 17:40, edited 1 time in total.
Mac Buster
Retired
Posts: 1474
Joined: 03 Aug 2003 22:37
Location: Moscow

Re: Tunguska the ternary emulator

Post by Mac Buster »

I wrote yet another variation of color test for Tunguska. This one cyclicaly fill raster lines with a color. Looks like animation :)

Code: Select all

; Yet another color table for Tunguska, works in raster mode with 729 colors
;
;  Assemble into demo.ternobj
;  Run 'tunguska image.ternobj -F demo.ternobj'
;  Type 'LOADSUB'
;

@ORG    %DDD000
        ; Bootstrap function
        ;
        ; Read page 2 from disk into page 2 in memory
        LDA     #2
        LDY     #2
        JSR     (jumpvector.fl_read_block)
        JMP     colortable

; These won't be copied. They are also present in the host at the same
; memory location. 

@ORG    %001000
jumpvector:
.getstring:     @DW     0
.feedscreen:    @DW     0
.putchar:       @DW     0
.putnon:        @DW     0
.puts:          @DW     0
.strcmp:        @DW     0
.strlen:        @DW     0
.index:         @DW     0
.strspn:        @DW     0
.strcspn:       @DW     0
.memset6:       @DW     0
.random:        @DW     0
.between:       @DW     0
.repaint:       @DW     0
.fl_read_block: @DW     0
.fl_write_block: @DW    0

@ORG    %002000
colortable:
; Enable raster mode
                LDA     #%00C
                STA     %DDDDDB

; Load screen buffer address
.idleloop:
                LDX     #%DDB
                LDY     #%DDD

; Fill screen buffer with a color
		LDA	#0
		STA	.x
		STA	.y
.mainloop:		
		LDA		.c
		STA	X,Y
		INY
		JVC	.bypass
		INX
.bypass:
		INC	.x
		LDA	#324
		CMP	.x
		JNE	.mainloop
		INC	.c
		LDA	#0
		STA	.x
		INC	.y
		LDA	#243
		CMP	.y
		JNE	.mainloop
		LDA	#0
		STA	.y
		JMP	.idleloop
.x:
		@DW	0
.y:
		@DW	0
.c:
		@DW	0
Mac Buster
Retired
Posts: 1474
Joined: 03 Aug 2003 22:37
Location: Moscow

Re: Tunguska the ternary emulator

Post by Mac Buster »

I added two new instructions to the CVS: BLS and BLT. They do page manipulation, so you can copy or set entire pages with one instruction.
What about raster graphics oriented instructions ? These ones might be very useful:

- copy to and from a raster line
- fill a raster line with a color
- perform logical operation with whole or part of raster line and data in general memory
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Tunguska the ternary emulator

Post by eudoxie »

Mac Buster wrote:
I added two new instructions to the CVS: BLS and BLT. They do page manipulation, so you can copy or set entire pages with one instruction.
What about raster graphics oriented instructions ? These ones might be very useful:

- copy to and from a raster line
- fill a raster line with a color
- perform logical operation with whole or part of raster line and data in general memory
I don't think it's doable with the current addressing modes. It requires more arguments than operations can handle.

It could possibly be doable through hardware pseudo-instructions, like how the floppy-disk interface is implemented.
Mac Buster
Retired
Posts: 1474
Joined: 03 Aug 2003 22:37
Location: Moscow

Re: Tunguska the ternary emulator

Post by Mac Buster »

It could possibly be doable through hardware pseudo-instructions, like how the floppy-disk interface is implemented.
Well, it can be command or hardware feature as well.

P.S. In case of hardware feature it will reming me Amiga Copper custom chip that used to fill screen buffer according to data from special area called "copper list" ;)
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Tunguska the ternary emulator

Post by eudoxie »

I'm thinking it might be possible to design something like an auxiliary "coprocessor" to handle more advanced instructions, with 3 12 trit wide I/O "registers" in system memory.

Something like this:

DDD:DD0 OP
DDD:DD1/2 R1
DDD:DD3/4 R2
DDD:DCD/C R3

Then you set R1-R3 with appropriate values, and OP to the relevant operation code. You could have it do half-precision floating point arithmetics, advanced memory block operations, etc. Yeah, I'm liking the idea...


--edit--

I implemented part of this idea, and it seems to work pretty fine. Only implemented floating point arithmetics so far, but it seems to work pretty good.
Mac Buster
Retired
Posts: 1474
Joined: 03 Aug 2003 22:37
Location: Moscow

Re: Tunguska the ternary emulator

Post by Mac Buster »

I'm thinking it might be possible to design something like an auxiliary "coprocessor" to handle more advanced instructions, with 3 12 trit wide I/O "registers" in system memory.
Great thing! So now you probably have to move BLS and BLT from CPU command set to commands of that GPU (assuming auxiliary "coprocessor" as General data Processing Unit), right ?
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Tunguska the ternary emulator

Post by eudoxie »

I don't know, I might rename them to "PGS" and "PGT". They'll have significantly less overhead than the coprocoessor operations.

Compare:
LDA #0
STA R1+1
STA R2+1
LDA #page1
STX R1
LDA #page2
STX R2
LDA #0
STA R3
LDA #%444
STA R3+1
LDA #operation
STA COOP

With

LDA #page2
PGT #page1

--edit--

Just found a way of optimizing tunguska so that it runs almost twice as fast. Before I got about 500,000 operations per second, now I get just south of 1,000,000 8-)
Mac Buster
Retired
Posts: 1474
Joined: 03 Aug 2003 22:37
Location: Moscow

Re: Tunguska the ternary emulator

Post by Mac Buster »

eudoxie wrote: Just found a way of optimizing tunguska so that it runs almost twice as fast. Before I got about 500,000 operations per second, now I get just south of 1,000,000 8-)
Wow! Very impressive :)