V-FORTH - Forth-83 for the VIC

Basic and Machine Language

Moderator: Moderators

User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: V-FORTH - Forth-83 for the VIC

Post by srowe »

funkheld wrote: Tue Dec 03, 2019 2:52 am can you translate this once with your assembler.fs from vforth

then I can learn from you also from the demo.
This should be your code converted to the FORTH assembler

Code: Select all

include assembler.fs

hex

code rightshift
    xsave stx,

    0 # ldx,
    begin,

    1400 ,x lda,
    .a lsr,
    1400 8 + ,x ror,
    1400 10 + ,x ror,
    1400 18 + ,x ror,
    1400 20 + ,x ror,
    1400 28 + ,x ror,
    1400 30 + ,x ror,
    1400 38 + ,x ror,
    1400 40 + ,x ror,
    1400 48 + ,x ror,
    1400 50 + ,x ror,
    1400 58 + ,x ror,
    1400 60 + ,x ror,
    1400 68 + ,x ror,
    1400 70 + ,x ror,
    1400 78 + ,x ror,
    1400 80 + ,x ror,
    1400 88 + ,x ror,
    1400 90 + ,x ror,
    1400 98 + ,x ror,
    1400 0a0 + ,x ror,
    1400 0a8 + ,x ror,
    1400 ,x ror,
    inx,
    8 # cpx,
    0= until,

    xsave ldx,
    next jmp,
    end-code
Beyond the usual RPN syntax it also uses begin, and until, to implement branches in loops. There are similar words for branches in if,then,else flows.

If you replace the .X register with .Y then there is no need to save the current value, and .Y is guaranteed to be set to zero.
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: V-FORTH - Forth-83 for the VIC

Post by funkheld »

Thanks a lot for your help.
I find no explanation for the forth-asm to the normal asm.
I miss a written help.

how is this written please:
"ldx 4608" for the forth-asm, 4608 is an address.

Thank you.
greetin
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: V-FORTH - Forth-83 for the VIC

Post by srowe »

The assembler was written by William Ragsdale and appeared in "Forth Dimensions" Vol III no. 5 http://www.forth.org/fd/FD-V03N5.pdf

Being FORTH the ordering of instructions is different to usual, a normal memory operation like ldx 4608 becomes

Code: Select all

4608 ldx,
note the comma at the end of the instruction, it is used because some instructions are ambiguous with hex numbers (e.g. add).
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: V-FORTH - Forth-83 for the VIC

Post by funkheld »

Hello, thanks for your help.
here a sprite always walks alone from left to right.

greeting

Code: Select all

include assembler.fs

variable charbase

5120 charbase !
8192 constant ramhi
32768 constant charset1

create daten
24  c,  24  c,  60  c,  126  c,  255  c,  24  c,  36  c,  66  c,

hex
code rightshift
xsave stx,
0 # ldx,
begin,
1400 ,x lda,
.a lsr,
1400 8 + ,x ror,
1400 10 + ,x ror,
1400 18 + ,x ror,
1400 20 + ,x ror,
1400 28 + ,x ror,
1400 30 + ,x ror,
1400 38 + ,x ror,
1400 40 + ,x ror,
1400 48 + ,x ror,
1400 50 + ,x ror,
1400 58 + ,x ror,
1400 60 + ,x ror,
1400 68 + ,x ror,
1400 70 + ,x ror,
1400 78 + ,x ror,
1400 80 + ,x ror,
1400 88 + ,x ror,
1400 90 + ,x ror,
1400 98 + ,x ror,
1400 0a0 + ,x ror,
1400 0a8 + ,x ror,
1400 ,x ror,
inx,
8 # cpx,
0= until,
xsave ldx,
next jmp,
end-code
decimal

: redefset  
charbase  @  ramhi  over  -  cmove
charbase  @  charbase !  ;

: cls
511 0 do 32 i 4096 + c! loop 
0 0 $plot ;

: ti 250 0 do loop ;

: text
12 36864 c! 22 36866 c! 174 36867 c! 192 36869 c! ;

: gehe 
charset1 redefset 
205 36869 c!

cls
2047 0 do 0 5120 i + c! loop 
8 0 do daten i + c@ 5120 i + c! loop 

22 0 do i i 4096 +  c! loop
22 0 do 4 i 37888 + c! loop

begin
ti
rightshift
197 c@ 
48 = if text then  ?terminal
until ;
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: V-FORTH - Forth-83 for the VIC

Post by funkheld »

Hi good afternoon.
I have now made a program in purebasic, which one
asm-source converted to "code".

the sprite program in grafikmodus just 596 bytes in vforth.
start with "go" and the sprite pixelwise right and left control with Q / W.

greeting

the vforth :

Code: Select all

variable start

create daten0 0 c, 0 c,

create daten
24  c,  24  c,  60  c,  126  c,  255  c,  24  c,  36  c,  66  c,
255 c,  129  c, 129  c,  129 c,  129  c,  129  c,  129  c,  255  c,

create daten1
255 c,  129  c, 129  c,  129 c,  129  c,  129  c,  129  c,  255  c,
255 c,  129  c, 129  c,  129 c,  129  c,  129  c,  129  c,  255  c,

hex
' lit 1a + constant next

: code create here dup body> ! ; immediate 

code shiftre 
 86 c, 4d c,
 a2 c, 0 c, bd c, 0 c, 11 c, 4a c, 7e c, 10 c, 11 c, 7e c,
 20 c, 11 c, 7e c, 30 c, 11 c, 7e c, 40 c, 11 c, 7e c, 50 c,
 11 c, 7e c, 60 c, 11 c, 7e c, 70 c, 11 c, 7e c, 80 c, 11 c,
 7e c, 90 c, 11 c, 7e c, a0 c, 11 c, 7e c, b0 c, 11 c, 7e c,
 c0 c, 11 c, 7e c, d0 c, 11 c, 7e c, e0 c, 11 c, 7e c, f0 c,
 11 c, 7e c, 0 c, 12 c, 7e c, 10 c, 12 c, 7e c, 20 c, 12 c,
 7e c, 30 c, 12 c, 7e c, 40 c, 12 c, 7e c, 0 c, 11 c, e8 c,
 e0 c, 10 c, d0 c, b8 c, a6 c, 4d c,
 4c c, next ,
 
 code shiftli 
 86 c, 4d c,
 a2 c, 0 c, bd c, 0 c, 11 c, bd c, 0 c, 11 c, a c, 3e c,
 40 c, 12 c, 3e c, 30 c, 12 c, 3e c, 20 c, 12 c, 3e c, 10 c,
 12 c, 3e c, 0 c, 12 c, 3e c, f0 c, 11 c, 3e c, e0 c, 11 c,
 3e c, d0 c, 11 c, 3e c, c0 c, 11 c, 3e c, b0 c, 11 c, 3e c,
 a0 c, 11 c, 3e c, 90 c, 11 c, 3e c, 80 c, 11 c, 3e c, 70 c,
 11 c, 3e c, 60 c, 11 c, 3e c, 50 c, 11 c, 3e c, 40 c, 11 c,
 3e c, 30 c, 11 c, 3e c, 20 c, 11 c, 3e c, 10 c, 11 c, 3e c,
 0 c, 11 c, e8 c, e0 c, 10 c, d0 c, b5 c, a6 c, 4d c,
 4c c, next ,
decimal

: grafikscr
8048 4352 do 0 i c! loop
151 36867 c! 21 36866 c! 204 36869 c! 14 36864 c!
256 16 do i 4096 i + 16 - c! loop
256 16 do 6 i 37888 + 16 - c! loop ;

: ti 500 0 do loop ;

: setze
4352 start !
16 0 do daten i + c@ start @ i + c! loop ;

: gehe
grafikscr
setze

begin
ti
197 c@ 
dup 48 = if shiftli then  
dup 49 = if shiftre then  
dup 9  = if  then 
41 = if  then
?terminal 
until  ;
the source-asm:

Code: Select all


!to "grafshiftli.p", cbm

	ldx #0
leftshift
	lda 4352,x
	lda 4352,x
	asl
	rol 4352+320 ,x
	rol 4352+304 ,x
	rol 4352+288 ,x
	rol 4352+272 ,x
	rol 4352+256 ,x
	rol 4352+240 ,x
	rol 4352+224 ,x
	rol 4352+208 ,x
	rol 4352+192 ,x
	rol 4352+176 ,x
	rol 4352+160 ,x
	rol 4352+144 ,x
	rol 4352+128 ,x
	rol 4352+112 ,x
	rol 4352+96 ,x
	rol 4352+80 ,x
	rol 4352+64 ,x
	rol 4352+48 ,x
	rol 4352+32 ,x
	rol 4352+16 ,x
	rol 4352,x
	inx
	cpx #16
	bne leftshift
	
	
!to "grafshiftre.p", cbm

	ldx #0
Rightshift
	lda 4352,x
	lsr
	ror 4352+16 ,x
	ror 4352+32 ,x
	ror 4352+48 ,x
	ror 4352+64 ,x
	ror 4352+80 ,x
	ror 4352+96 ,x
	ror 4352+112 ,x
	ror 4352+128 ,x
	ror 4352+144 ,x
	ror 4352+160 ,x
	ror 4352+176 ,x
	ror 4352+192 ,x
	ror 4352+208 ,x
	ror 4352+224 ,x
	ror 4352+240 ,x
	ror 4352+256 ,x
	ror 4352+272 ,x
	ror 4352+288 ,x
	ror 4352+304 ,x
	ror 4352+320 ,x
	ror 4352,x
	inx
	cpx #16
	bne Rightshift
Attachments
here.jpg
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: V-FORTH - Forth-83 for the VIC

Post by funkheld »

hallo, guten tag.

have 3696 byte saved from adresse $8000.

this is ok in the disk:
-----------------------------------
: save
$setnam
1 8 8 $setlfs
32768 36464 $save ?ioerr drop ;

: savegraf
s" daten.bin" save ;
----------------------------------

Now I want to load the address 4352.
how does that work? :
----------------------------------
: load
$setnam
1 8 8 $setlfs
4352 $load ?ioerr drop ; >>>>>> not ok.

: loadgraf
s" daten.bin" load ;
---------------------------------

greeting
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: V-FORTH - Forth-83 for the VIC

Post by srowe »

Confusingly for $load to load the data at an address different to that the file was saved as you must give set a secondary address of 0.
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: V-FORTH - Forth-83 for the VIC

Post by funkheld »

I saven the data.bin from $8000 but I would like to load the data.bin later to the address $1100.

Thank you.
greeting
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: V-FORTH - Forth-83 for the VIC

Post by srowe »

This should work

Code: Select all

: load
$setnam
0 8 8 $setlfs
4352 $load ?ioerr drop ;
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: V-FORTH - Forth-83 for the VIC

Post by funkheld »

Hi, Thank You.
the vforth becomes more and more perfect.

Thank you.
greeting
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: V-FORTH - Forth-83 for the VIC

Post by funkheld »

Hi good afternoon.

what can you please with vforth with the interrupt:
Make $0314 / $0315?

Thank you.
greeting
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: V-FORTH - Forth-83 for the VIC

Post by srowe »

funkheld wrote: Tue Dec 10, 2019 10:34 am what can you please with vforth with the interrupt:
Make $0314 / $0315?
Calling a machine code routine on an interrupt should work already, calling a FORTH word requires some changes to the system code

http://6502.org/tutorials/zero_overhead ... rupts.html

I haven't experimented with this, it is on my list of topics to look at.
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: V-FORTH - Forth-83 for the VIC

Post by funkheld »

Hello thanks for the information.

I am happy if you could do it.

Thank you.
greeting
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: V-FORTH - Forth-83 for the VIC

Post by srowe »

It also depends what you want it for. The linked implementation isn't a true ISR, it checks a flag inside NEXT and runs the interrupt word instead of what IP points to. It doesn't interrupt a primitive word (one written in machine code) so if you wanted it for something timing critical, like raster interrupts, there would be variation in the running your interrupt word.

A true interrupt system would be much harder to implement as you would need to preserve the internal state of the FORTH VM at the point the interrupt occurs.
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: V-FORTH - Forth-83 for the VIC

Post by funkheld »

hello, thanks for your info.

I do not do raster-interrupt.
I want to perform an interrupt task in the background. and continue with the normal program.

Thank you.
greeting
Post Reply