Vic Rubasm

You need an actual VIC.

Moderator: Moderators

Post Reply
User avatar
R'zo
Vic 20 Nerd
Posts: 514
Joined: Fri Jan 16, 2015 11:48 pm

Vic Rubasm

Post by R'zo »

Title: Rubasm
Language: Ruby
Description: Assembler for the Vic-20
Author: Ryan Liston

I've been working on writing my own assembler using Ruby. I have completed the core of the assembler and have written my first working program.

Completed:
-optcodes
-program declaration
-data sets
-build
-hex and bin input

To Do:
-kernal calls
-petscii/character poke tables
-declaring constants for key addresses
-built in routines

download: rubasm

hello world

Code: Select all

require_relative 'rubasm'

new_prg "Hello World!",824
Ldy.im 0
label "loop"
Lda.ay "data"
Sta.ay 7680
Lda.im 0
Sta.ay 38400
Iny.ip
Cpy.im 12
Bne.rl "loop"
label "hold"
Jmp.ab "hold"
label "data"
data 8,5,12,12,15,32,23,15,18,12,4,33
build
er=gets
rubasm

Code: Select all

#DEFINE GLOBAL
def define_globals
	$prog_c=-1
	$pass_c=0
	$byte_c=[0,0]
	$cycle_c=[0,0]
	$assem=[0],[0,0] 
	$start_l_h=[0,0],[0,0]
	$prg_title=[0,0]
	$l_hash={"ryan liston"=>2021}
	#hex_table
	$hexdec={"0"=>0,"1"=>1,"2"=>2,"3"=>3,"4"=>4,"5"=>5,"6"=>6,"7"=>7,"8"=>8,"9"=>9,"a"=>10,"b"=>11,"c"=>12,"d"=>13,"e"=>14,"f"=>15}
	$e_call=["error! ","error! illegal quantity!","error! inappropriate addressing mode!"]
	end
define_globals

#print info line
#def pr_info op,x4,x5
#	$assem [$prog_c][$byte_c[$prog_c]]=x5
#	puts "#{x5}\t byte: #{$byte_c[$prog_c]}\t cycles: #{$opt_tab[op][2][x4]}\t total cycles: #{$cycle_c[$prog_c]}\t address: #{$s_start+$byte_c[$prog_c]}"    
#	$byte_c[$prog_c]+=1
#	end

#hex input
def hex h_string
	h_len=h_string.length
	dec_v=0
	while h_len>0
		h_len-=1
		dec_v+=$hexdec[h_string[h_len]]*16**(h_string.length-1-h_len)
		end
	return dec_v
	end	

#bin input
def bin b_string
	b_len=b_string.length
	dec_v=0
	while b_len>0
		b_len-=1
		dec_v+=b_string[b_len].to_i*2**(b_string.length-1-b_len)
		end
	return dec_v
	end	

#error report
def er_rpt e1
	puts "#{$e_call[0]} #{$e_call[e1]}"
		er=gets
	end
	
#DECLARE NEW PROGRAM
def new_prg title,s_start
	puts "...................................................................................................."
	$prog_c+=1
	$s_start=s_start
	$l_hash[title]=$s_start    #???????????????????????????????????????????????????
	$start_l_h[$prog_c][1]=$s_start/256
	$start_l_h[$prog_c][0]=$s_start-$start_l_h[$prog_c][1]*256
	
	$prg_title[$prog_c]=title
	puts $prg_title[$prog_c]
	puts "start adress=#{$s_start}"
	puts $start_l_h[$prog_c][0] 
	puts $start_l_h[$prog_c][1]

	$byte_c[$prog_c]=0
	$cycle_c[$prog_c]=0
	puts "...................................................................................................."
	puts $prg_title[$prog_c]
	end

#LABELS
def label l_name
	puts l_name
	$l_hash[l_name]=$s_start+$byte_c[$prog_c]
	end

#BUILD PROGRAM
def build
	puts "...................................................................................................."
	puts "building..."
	$p_count=$prog_c
	$prog_c=0
	for $prog_c in (0..$p_count)
		$b_count=0
	
		for $b_count in (0..$byte_c[$prog_c])
		
			if $assem[$prog_c][$b_count].is_a? String
				
				if $assem[$prog_c][$b_count]=="label"
				
					hi = $l_hash[$assem[$prog_c][$b_count+1]]/256
					low = $l_hash[$assem[$prog_c][$b_count+1]]-(hi*256)
				
					$assem[$prog_c][$b_count]=low
					$assem[$prog_c][$b_count+1]=hi
					$b_count+=1			
				
				elsif $assem[$prog_c][$b_count][0]=="!"
						$assem[$prog_c][$b_count][0]=""
						brn1=$l_hash[$assem[$prog_c][$b_count]]
						brn2=$start_l_h[$prog_c][1]*256+$start_l_h[$prog_c][0]+$b_count	
							
							
							if brn1>brn2							
							$assem[$prog_c][$b_count]=brn1-brn2
							
							else $assem[$prog_c][$b_count]=255-(brn2-brn1)
								
								end
							
				else $assem[$prog_c][$b_count]=$l_hash[$assem[$prog_c][$b_count]]
					
					if $assem[$prog_c][$b_count]>255
						puts $e_call[1]
						puts "@#{$assem[$prog_c][$b_count]}"
						er=gets
						end
					
					end	

				end
			end
		end
		

	$prog_c=0
	for $prog_c in (0..$p_count)
		puts "...................................................................................................."
		puts "Include start address for\n   #{$prg_title[$prog_c]}?\n     y=yes\n     n=no"
		er=gets.chomp
			if er=="y"
				$assem[$prog_c].insert(0,$start_l_h[$prog_c])
				end
		puts "...................................................................................................."
		puts "building #{$prg_title[$prog_c]}"
		puts "...................................................................................................."
		puts $assem[$prog_c]
		end
	
	puts "...................................................................................................."
	puts "build complete!"
	er=gets

	end	

def pr_info x4,x5
	
	$assem [$prog_c][$byte_c[$prog_c]]=x5
	puts "#{x5}\t byte: #{$byte_c[$prog_c]}\t cycles: #{x4}\t total cycles: #{$cycle_c[$prog_c]}\t address: #{$s_start+$byte_c[$prog_c]}"    
	
	$byte_c[$prog_c]+=1
	end

def data *d_val
	for t in (0...d_val.length)
		pr_info 0,d_val[t]
		end
	end

class Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	
	def self.out
		
		$cycle_c[$prog_c]+=@@cycle
		
		if $start_l_h[$prog_c][0]+@@byte>256
			$cycle_c[$prog_c]+=@@cycalt
			end	
	
		pr_info @@cycle,@@command
	
	
	
		if @@byte==3
			if @@value.is_a? String
				low="label"
				hi=@@value			
				else hi=@@value/256
					low=@@value-(hi*256)
				end	
		
			if low.is_a? Integer
				if low>255
					er_rep 1
					end
				end
		
				pr_info @@cycle,low
				@@value=hi
	
				elsif @@value.is_a? Integer
					if @@value>255
						er_rep 1
						end
			end
		if @@byte>1
			pr_info @@cycle,@@value
			
			end
		print "\n"	
	end	


	
	
	
=begin	def self.out
	puts @@command
	puts @@value
	puts @@cycle
	puts @@cycalt
	puts @@byte
		end
=end	
	def self.ix value
		er_rep 1
		er=gets
		end
	def self.zp value
		er_rep 1
		er=gets
		end
	def self.im value
		er_rep 1
		er=gets
		end
	def self.ab value
		er_rep 1
		er=gets
		end
	def self.iy value
		er_rep 1
		er=gets
		end
	def self.zy value
		er_rep 1
		er=gets
		end
	def self.zx value
		er_rep 1
		er=gets
		end
	def self.ay value
		er_rep 1
		er=gets
		end
	def self.ax value
		er_rep 1
		er=gets
		end
	def self.in value
		er_rep 1
		er=gets
		end
	def self.rl value
		er_rep 1
		er=gets
		end
	def self.ip
		er_rep 1
		er=gets
		end
	
	end
class Branch<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.rl value
		@@value=value
		@@cycle=2
		@@cycalt=1
		@@byte=2
		
		if @@value.is_a? String
			@@value="!" + @@value
			end
		Opcode.out ###switch to Branch.rl_out for relative addressing
		end
	end
class Adc<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ix value
		@@command=97
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.zp value
		@@command=101
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.im value
		@@command=105
		@@value=value
		@@cycle=2
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=109
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.iy value
		@@command=113
		@@value=value
		@@cycle=5
		@@cycalt=1
		@@byte=2
		Opcode.out
		end
	def self.zx value
		@@command=117
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ay value
		@@command=121
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	def self.ax value
		@@command=125
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	
	end
class And<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ix value
		@@command=33
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.zp value
		@@command=37
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.im value
		@@command=41
		@@value=value
		@@cycle=2
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=45
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.iy value
		@@command=49
		@@value=value
		@@cycle=5
		@@cycalt=
		@@byte=2
		Opcode.out
		end
	def self.zx value
		@@command=53
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ay value
		@@command=57
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	def self.ax value
		@@command=61
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	end
class Asl<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.zp value
		@@command=6
		@@value=value
		@@cycle=5
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ip
	    @@command=10
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	def self.ab value
		@@command=14
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.zx value
		@@command=22
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ax value
		@@command=30
		@@value=value
		@@cycle=7
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	end
class Bcc<Branch 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.rl value
		@@command=144
		super
		end
	end
class Bcs<Branch 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.rl value
		@@command=176
		super
		end
	end
class Beq<Branch 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.rl value
		@@command=240
		super
		end
	end
class Bit<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0

	def self.zp value
		@@command=36
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=44
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	end
class Bmi<Branch 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.rl value
		@@command=48
		super
		end
	end
class Bne<Branch 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.rl value
		@@command=208
		super
		end
	end
class Bpl<Branch 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.rl value
		@@command=16
		super
		end
	end
class Brk<Branch 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=0
		@@value=nil
		@@cycle=7
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Bvc<Branch 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.rl value
		@@command=80
		super
		end
	end
class Bvs<Branch 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.rl value
		@@command=112
		super
		end
	end
class Clc<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=24
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Cld<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=216
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Cli<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=88
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Clv<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=184
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Cmp<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ix value
		@@command=193
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.zp value
		@@command=197
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.im value
		@@command=201
		@@value=value
		@@cycle=2
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=205
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.iy value
		@@command=209
		@@value=value
		@@cycle=5
		@@cycalt=1
		@@byte=2
		Opcode.out
		end
	def self.zx value
		@@command=213
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ay value
		@@command=217
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	def self.ax value
		@@command=221
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	
	end
class Cpx<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.zp value
		@@command=228
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.im value
		@@command=224
		@@value=value
		@@cycle=2
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=236
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	end
class Cpy<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.zp value
		@@command=196
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.im value
		@@command=192
		@@value=value
		@@cycle=2
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=204
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	end
class Dec<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.zp value
		@@command=198
		@@value=value
		@@cycle=5
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.zx value
		@@command=214
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=206
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.ax value
		@@command=222
		@@value=value
		@@cycle=7
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	end
class Dex<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=202
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		end
	end
class Dey<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=136
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		end
	end
class Eor<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ix value
		@@command=65
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.zp value
		@@command=69
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.im value
	
		@@command=73
		@@value=value
		@@cycle=2
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=77
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.iy value
		@@command=81
		@@value=value
		@@cycle=5
		@@cycalt=1
		@@byte=2
		Opcode.out
		end
	def self.zx value
		@@command=85
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ay value
		@@command=89
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	def self.ax value
		@@command=93
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	
	end
class Inc<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.zp value
		@@command=230
		@@value=value
		@@cycle=5
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.zx value
		@@command=246
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=238
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.ax value
		@@command=254
		@@value=value
		@@cycle=7
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	end
class Inx<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=232
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		end
	end
class Iny<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=200
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Jmp<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ab value 
		@@command=76
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.in value 
		@@command=108
		@@value=value
		@@cycle=5
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	end
class Jsr<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ab value 
		@@command=32
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	end
class Lda<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ix value
		@@command=161
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.zp value
		@@command=165
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.im value
	
		@@command=169
		@@value=value
		@@cycle=2
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=173
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.iy value
		@@command=177
		@@value=value
		@@cycle=5
		@@cycalt=1
		@@byte=2
		Opcode.out
		end
	def self.zx value
		@@command=191
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ay value
		@@command=185
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	def self.ax value
		@@command=189
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	
	end
class Ldx<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.zp value
		@@command=166
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.im value
		@@command=162
		@@value=value
		@@cycle=2
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=174
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.zy value
		@@command=182
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ay value
		@@command=190
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	end
class Ldy<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.zp value
		@@command=164
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.im value
		@@command=160
		@@value=value
		@@cycle=2
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=172
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	
	def self.zx value
		@@command=180
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=2
		Opcode.out
		end

	def self.ax value
		@@command=188
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	
	end
class Lsr<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.zp value
		@@command=70
		@@value=value
		@@cycle=5
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ip
		@@command=74
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	def self.ab value
		@@command=78
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.zx value
		@@command=86
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ax value
		@@command=94
		@@value=value
		@@cycle=7
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	
	end
class Nop<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=234
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Ora<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ix value
		@@command=1
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.zp value
		@@command=5
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.im value
	    @@command=9
		@@value=value
		@@cycle=2
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=13
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.iy value
		@@command=17
		@@value=value
		@@cycle=5
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.zx value
		@@command=21
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ay value
		@@command=25
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	def self.ax value
		@@command=29
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	
	end
class Pha<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=72
		@@value=nil
		@@cycle=3
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Php<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=8
		@@value=nil
		@@cycle=3
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Pla<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=10
		@@value=nil
		@@cycle=4
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Plp<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=40
		@@value=nil
		@@cycle=4
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Rol<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.zp value
		@@command=38
		@@value=value
		@@cycle=5
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ip
	    @@command=42
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	def self.ab value
		@@command=6
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.zx value
		@@command=54
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ax value
		@@command=62
		@@value=value
		@@cycle=7
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	end
class Ror<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.zp value
		@@command=102
		@@value=value
		@@cycle=5
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ip
	    @@command=106
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	def self.ab value
		@@command=110
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.zx value
		@@command=118
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ax value
		@@command=126
		@@value=value
		@@cycle=7
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	end
class Rti<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=64
		@@value=nil
		@@cycle=6
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Rts<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=96
		@@value=nil
		@@cycle=6
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Sbc<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ix value
		@@command=225
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.zp value
		@@command=229
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.im value
		@@command=233
		@@value=value
		@@cycle=2
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=237
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.iy value
		@@command=241
		@@value=value
		@@cycle=5
		@@cycalt=1
		@@byte=2
		Opcode.out
		end
	def self.zx value
		@@command=245
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ay value
		@@command=249
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	def self.ax value
		@@command=253
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	
	end
class Sec<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=56
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Sed<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=248
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Sei<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=120
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Sta<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ix value
		@@command=129
		@@value=value
		@@cycle=6
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.zp value
		@@command=133
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=141
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.iy value
		@@command=145
		@@value=value
		@@cycle=6
		@@cycalt=1
		@@byte=2
		Opcode.out
		end
	def self.zx value
		@@command=149
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ay value
		@@command=153
		@@value=value
		@@cycle=4
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	def self.ax value
		@@command=157
		@@value=value
		@@cycle=5
		@@cycalt=1
		@@byte=3
		Opcode.out
		end
	
	end
class Stx<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.zp value
		@@command=134
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=141
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.zy value
		@@command=150
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	
	end
class Sty<Opcode 
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.zp value
		@@command=132
		@@value=value
		@@cycle=3
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	def self.ab value
		@@command=140
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=3
		Opcode.out
		end
	def self.zx value
		@@command=148
		@@value=value
		@@cycle=4
		@@cycalt=0
		@@byte=2
		Opcode.out
		end
	end
class Tax<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=170
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Tay<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=168
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Tsx<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=186
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		end
	end
class Txa<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=138
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Txs<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=154
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
class Tya<Opcode
	@@command=0
	@@value=0
	@@cycle=0
	@@cycalt=0
	@@byte=0
	def self.ip 
		@@command=152
		@@value=nil
		@@cycle=2
		@@cycalt=0
		@@byte=1
		Opcode.out
		end
	end
Attachments
RasmHW.PNG
Rubasm.PNG
Hworld.PNG
R'zo
I do not believe in obsolete...
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Vic Rubasm

Post by chysn »

It's a satisfying thing, isn't it, to write a program that successfully builds another program?
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
R'zo
Vic 20 Nerd
Posts: 514
Joined: Fri Jan 16, 2015 11:48 pm

Re: Vic Rubasm

Post by R'zo »

Very satisfying and surprisingly enjoyable to write.
R'zo
I do not believe in obsolete...
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Vic Rubasm

Post by chysn »

I don't know Ruby at all. But it looks like, instead of processing a traditional .asm file, you're writing 6502 as valid Ruby code, and 'rubasm' is a library containing all the 6502 instructions and pseudo-operations to make that possible. Is that right?

That's a really cool idea.
Last edited by chysn on Thu Feb 25, 2021 10:36 pm, edited 1 time in total.
User avatar
R'zo
Vic 20 Nerd
Posts: 514
Joined: Fri Jan 16, 2015 11:48 pm

Re: Vic Rubasm

Post by R'zo »

That is exactly correct.

The idea is that an assembler written within another language instead of with one would be able to take advantage of the functions of that language to make generating code easier. I can use methods and loops to generate blocks of code and data. I cant use complex formulas, variables, arrays, methods etc. within data sets (byte 5+1*8+9*16, 2+0*8+11*16, 3+1*8+0*16 ...for exp. would not build in cbm.)

I can also now create methods like this...

Code: Select all

def poke (address,value)
	Lda.im valuse
	Sta.ab address
	end
	
new_prg "poke test",824
poke 36878,5
poke 36874,190
poke 36875,200
poke 36876,220
poke 36874,140 
This would need more work to fully replicate the basic poke but you can see how this would help decrease future work load.

I should add here that you can declare multiple programs within a single file. Labels across all programs are calculated during prebuild and applied during build. This makes it easier to readdress and redefine multiple programs within a single project.

My current next step is to write a files declaring the vics kernal calls and common screen/character codes as constants that can be used as a library tool. I can then do things like set up PLOT and CHROUT in a method similar to the one above reducing the code typed in by the user to something like ... _print x, y, "string" ... where x and y are the starting coordinates fed into PLOT and "string" will be converted into ascii values and fed into CHROUT.

And of course I am planning on creating libraries for other platforms as well.
R'zo
I do not believe in obsolete...
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Vic Rubasm

Post by chysn »

That's neat! So the methods work sort of like inline functions in C++. More complex methods--which you might not want inlined to conserve memory--can generate a 6502 subroutine on first usage, and then set an address to indicate to subsequent calls that the subroutine has been generated.

I'll be interesting to see what problems come up and how you solve them. For example, it'll be a challenge to differentiate between variables that are interpolated at build time versus ones that need to be stored in and retrieved from memory at runtime.

But it's an awesome project.
User avatar
R'zo
Vic 20 Nerd
Posts: 514
Joined: Fri Jan 16, 2015 11:48 pm

Re: Vic Rubasm

Post by R'zo »

I now have Kernal calls, petscii codes, color pokes and some key memory locations programed in.

While researching I found that the Vic and the C64 have the same opcode a kernal calls values. With that here is a demonstration of the same code running on both machines (in emulation.)

Hello World 2

Code: Select all

require_relative 'rubasm'
require_relative 'vic_lib'

new_prg "Hello World 2",824
Ldy.im 0
label "loop"
Lda.ay "text"
Jsr.ab	CHROUT
Iny.ip
Cpy.im	14
Bne.rl "loop"
Rts.ip
label "text"
data CLEAR.ord,RED.ord,"H".ord,"E".ord,"L".ord,"L".ord,"O".ord," ".ord,"W".ord,"O".ord,"R".ord,"L".ord,"D".ord,"!".ord
build
er=gets
vic_lib

Code: Select all

#petscii codes
WHITE=5.chr
RED=28.chr
GREEN=30.chr
BLUE=31.chr
BLACK=144.chr
PURPLE=156.chr
YELLOW=158.chr
CYAN=159.chr

L_CASE=14.chr
U_CASE=142.chr
DOWN=17.chr
RIGHT=29.chr
UP=145.chr
LEFT=157.chr
SPACE=32.chr
SH_SPACE=160.chr
RETURN=13.chr
SH_RET=141.chr
REV_ON=18.chr
REV_OFF=146.chr
HOME=19.chr
DELETE=20.chr
CLEAR=147.chr
INSERT=148.chr

AR_UP=94.chr
AR_DOWN=95.chr
POUND=92.chr
SPADE=97.chr
HOLE=113.chr
HEART=115.chr
XING=118.chr
CIRCLE=119.chr
CLUB=120.chr
DIAMOND=122.chr
CROSS=123.chr
PI=126.chr

F1=133.chr
F2=137.chr
F3=134.chr
F4=138.chr
F5=135.chr
F6=139.chr
F7=136.chr
F8=140.chr

SC_OFF=8.chr
SC_ON=9.chr
 
#poke codes
Black=0
White=1
Red=2
Cyan=3
Purple=4
Green=5
Blue=6
Yellow=7
Orange=8
Lorange=9
Pink=10
Lcyan=11
Lpurple=12
Lgreen=13
Lblue=14
Lyellow=15

#key addresses
VOX_L=36874
VOX_M=36875
VOX_H=36876
VOX_N=36877
VOLUME=36878
AUX_C=VOLUME
SCREEN_C=36979
NMI=65530
RESET=65394
IRQ=65534
IRQX=60095

#keernal calls
ACPTR=63445
CHKIN=65478
CHKOUT=65481
CHRIN=65487
CHROUT=65490
CIOUT=65448
CLALL=65511
CLOSE=65475
CLRCHN=65484
GETIN=65508
IOBASE=65523
LISTEN=65457
LOAD=65493
MEMBOT=65436
MEMTOP=65433
OPEN=65472
PLOT=65520
RDTIM=65502
READST=65463
RESTOR=65418
SAVE=65496
SCNKEY=65439
SCREEN=65517
SECOND=65427
SETLFS=65466
SETMSG=65424
SETNAM=65469
SETTIM=65499
SETTMO=65442
STOP=65505
TALK=65460
TKSA=65430
UDTIM=65514
UNLSN=65454
UNTLK=65451
VECTOR=65421
Next steps: Built in routines and illegal opcodes.
Attachments
aa5.PNG
aa4.PNG
aa3.PNG
aa2.PNG
R'zo
I do not believe in obsolete...
User avatar
R'zo
Vic 20 Nerd
Posts: 514
Joined: Fri Jan 16, 2015 11:48 pm

Re: Vic Rubasm

Post by R'zo »

chysn wrote: Thu Feb 25, 2021 10:35 pm That's neat! So the methods work sort of like inline functions in C++. More complex methods--which you might not want inlined to conserve memory--can generate a 6502 subroutine on first usage, and then set an address to indicate to subsequent calls that the subroutine has been generated.

I'll be interesting to see what problems come up and how you solve them. For example, it'll be a challenge to differentiate between variables that are interpolated at build time versus ones that need to be stored in and retrieved from memory at runtime.

But it's an awesome project.
I'm just going to post this for now to tease your curiosity. I'll post more later describing what I'm doing with the variable system as well as the other commands and functions.

This is far from finished or fully tested and functional. I'm testing and editing the current code piece by piece and as I am going through it I am coming up with new ideas and seeing new possibilities.

The current test program is testing variable usage for 8-bit unsigned integers.

Here's the git for the project: RUBY_VIXX

The test code:

Code: Select all

=begin
FILE:VAR_TEST
AUTHOR:RYAN LISTON
DATE:5/26/2021
LANGUAGE:RUBY 3.0
REQUIREMENTS :RUBY INTERPRETER
DESCRIPTION:TEST FILE TESTING 8BIT UNSIGNED INTEGER ROUTINES IN RUBY_VIXX
=end

require_relative 'RUBY_VICXX'

# sys825 to run program
MODULE.new 'var test',0x338  #starts new program module named 'var test' at 0x338
VAR.block 'vars',['+hp',5]   #creates new variable block named 'vars' and declares +hp=5 

PRINT.str "#{CLEAR}#{sBLACK}VARIABLE TEST#{RETURN}8-BIT UNSIGNED#{RETURN}INTEGER#{RETURN}"

_Y2FAC $var['+hp']				#loads y with vlaue stored at +hp and tansfers integer in y to FAC
_PRNFAC								#prints FAC to screen
_CHROUT RETURN.ord				#prints RETURN (new line) 

LDA.ab $var['+hp']				#load accumulator with the value stored at +hp
CLC.ip								#clears the carry bit
ADC.ab $var['+hp']				#adds value stored at +hp to the value in the accumulator
TAY.ip								#tranfer accumulator to y

_Y2FAC								#transfers y to FAC 
_PRNFAC								#prints FAC to screen
_CHROUT RETURN.ord 				#prints RETURN (new line)

VAR.let '+hp',255					#lets +hp=255
_Y2FAC $var['+hp']				#loads y with vlaue stored at +hp and tansfers integer in y to FAC				
_PRNFAC								#prints FAC to screen

LABEL.new 'loop'					#creates label named 'loop'
JMP.ab 'loop'						#loops

BUILD::PROJECT.prg				#builds project to file
The test file var_test.prg will run with sys 825

And a screenshot of the resulting code in action in vice.

Image
R'zo
I do not believe in obsolete...
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Vic Rubasm

Post by chysn »

So, hp is a pointer to a floating point number, and it's used as an argument to external functions that deal with a FAC? That's quite nice. I like the idea of sort of abstracting away various functions. It sort of blurs the lines between assembly and a higher level language, but you'll eventually wind up with a totally new language!
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
R'zo
Vic 20 Nerd
Posts: 514
Joined: Fri Jan 16, 2015 11:48 pm

Re: Vic Rubasm

Post by R'zo »

chysn wrote: Fri May 28, 2021 5:26 am So, hp is a pointer to a floating point number, and it's used as an argument to external functions that deal with a FAC? That's quite nice. I like the idea of sort of abstracting away various functions. It sort of blurs the lines between assembly and a higher level language, but you'll eventually wind up with a totally new language!
First.... I was going to describe everything here but its just to much for a post so I'm working on a manual that goes over everything that I have implemented so far. So for now I will just clarify a little what my demo is demonstrating.

A higher level language has become the goal of this project. It started out as an assembler with some nice convenient extra features. As it turns out developing the higher level commands is not that difficult. And why not still be able to use opposes when the higher level commands are not exactly what you want? The real challenge is making those higher level commands versatile while keeping the outputted code efficient.

A good and simple example of this is the kernel based command (_CHROUT). by itself it only outputs
JSR.ab $CHROUT
Allowing you to set up the accumulator to your liking and just saving. You from having to type JSR.ab. You can give an ascii value as an argument (_CHROUT 32) and the output will be
LDA.im 32
JSR.ab $CHROUT
If the argument is (_CHROUT [0xa000]) you get
LDA.ab 0xa000
JSR.ab $CHROUT
or you can (_CHROUT [0xa000,:ay]
LDA.ay 0xa000
JSR.ab $CHROUT
And so on.

As for the variables...
First I'll have to explain ruby hash tables. The hash is an array that uses labels as pointers instead of numbers so instead of array[1]=42 you can have hash['label']=42.
So '+hp' is a hash label holding the start address for the correlated value or string. It is very much like using a constant to represent an address in most assemblers but passing it as a hash label allows for the assembler to be able to process the label as well as its value. With this I can determine the variable type and how to handle it based off of the label.

The variable type that I am demonstrating here is an unsigned 8-bit integer. It is the only one that is fully tested at the moment but I will make sure the rest are working after I type out the manual.
The variables I have support for so far are
+ 8bit unsigned integer
++ 16bit unsigned integer
% 8 bit signed integer
%%16 bit signed integer
~ Float
$ ascii string
? narrow pascal string
?? wide pascal string
@ narrow character index string
@@wide character index string

I do plan on implementing BASIC variables but for my typical uses basic variables are just to slow and take up alot of extra space.
R'zo
I do not believe in obsolete...
User avatar
R'zo
Vic 20 Nerd
Posts: 514
Joined: Fri Jan 16, 2015 11:48 pm

Re: Vic Rubasm

Post by R'zo »

Here is the command line output from the above listed code.

Code: Select all

ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x64-mingw32]

C:\Users\Rylis>"D:\RUBY_VICXX\var_test.rb"
....................................................................................................
var test
start adress=824
56
3
....................................................................................................
var test
varable block
vars
+hp at 824 = 5
5        byte: 0         cycles: 0       total cycles: 0         address: 824

....................................................................................................
76       byte: 1         cycles: 3       total cycles: 3         address: 825
100      byte: 2         cycles: 3       total cycles: 3         address: 826
3        byte: 3         cycles: 3       total cycles: 3         address: 827

147      byte: 4         cycles: 0       total cycles: 3         address: 828
144      byte: 5         cycles: 0       total cycles: 3         address: 829
86       byte: 6         cycles: 0       total cycles: 3         address: 830
65       byte: 7         cycles: 0       total cycles: 3         address: 831
82       byte: 8         cycles: 0       total cycles: 3         address: 832
73       byte: 9         cycles: 0       total cycles: 3         address: 833
65       byte: 10        cycles: 0       total cycles: 3         address: 834
66       byte: 11        cycles: 0       total cycles: 3         address: 835
76       byte: 12        cycles: 0       total cycles: 3         address: 836
69       byte: 13        cycles: 0       total cycles: 3         address: 837
32       byte: 14        cycles: 0       total cycles: 3         address: 838
84       byte: 15        cycles: 0       total cycles: 3         address: 839
69       byte: 16        cycles: 0       total cycles: 3         address: 840
83       byte: 17        cycles: 0       total cycles: 3         address: 841
84       byte: 18        cycles: 0       total cycles: 3         address: 842
13       byte: 19        cycles: 0       total cycles: 3         address: 843
56       byte: 20        cycles: 0       total cycles: 3         address: 844
45       byte: 21        cycles: 0       total cycles: 3         address: 845
66       byte: 22        cycles: 0       total cycles: 3         address: 846
73       byte: 23        cycles: 0       total cycles: 3         address: 847
84       byte: 24        cycles: 0       total cycles: 3         address: 848
32       byte: 25        cycles: 0       total cycles: 3         address: 849
85       byte: 26        cycles: 0       total cycles: 3         address: 850
78       byte: 27        cycles: 0       total cycles: 3         address: 851
83       byte: 28        cycles: 0       total cycles: 3         address: 852
73       byte: 29        cycles: 0       total cycles: 3         address: 853
71       byte: 30        cycles: 0       total cycles: 3         address: 854
78       byte: 31        cycles: 0       total cycles: 3         address: 855
69       byte: 32        cycles: 0       total cycles: 3         address: 856
68       byte: 33        cycles: 0       total cycles: 3         address: 857
13       byte: 34        cycles: 0       total cycles: 3         address: 858
73       byte: 35        cycles: 0       total cycles: 3         address: 859
78       byte: 36        cycles: 0       total cycles: 3         address: 860
84       byte: 37        cycles: 0       total cycles: 3         address: 861
69       byte: 38        cycles: 0       total cycles: 3         address: 862
71       byte: 39        cycles: 0       total cycles: 3         address: 863
69       byte: 40        cycles: 0       total cycles: 3         address: 864
82       byte: 41        cycles: 0       total cycles: 3         address: 865
13       byte: 42        cycles: 0       total cycles: 3         address: 866
0        byte: 43        cycles: 0       total cycles: 3         address: 867

160      byte: 44        cycles: 2       total cycles: 5         address: 868
0        byte: 45        cycles: 2       total cycles: 5         address: 869

185      byte: 46        cycles: 4       total cycles: 9         address: 870
60       byte: 47        cycles: 4       total cycles: 9         address: 871
3        byte: 48        cycles: 4       total cycles: 9         address: 872

201      byte: 49        cycles: 2       total cycles: 11        address: 873
0        byte: 50        cycles: 2       total cycles: 11        address: 874

240      byte: 51        cycles: 2       total cycles: 13        address: 875
7        byte: 52        cycles: 2       total cycles: 13        address: 876

32       byte: 53        cycles: 6       total cycles: 19        address: 877
210      byte: 54        cycles: 6       total cycles: 19        address: 878
255      byte: 55        cycles: 6       total cycles: 19        address: 879

200      byte: 56        cycles: 2       total cycles: 21        address: 880

184      byte: 57        cycles: 2       total cycles: 23        address: 881

80       byte: 58        cycles: 2       total cycles: 25        address: 882
242      byte: 59        cycles: 2       total cycles: 25        address: 883

172      byte: 60        cycles: 4       total cycles: 29        address: 884
56       byte: 61        cycles: 4       total cycles: 29        address: 885
3        byte: 62        cycles: 4       total cycles: 29        address: 886

32       byte: 63        cycles: 6       total cycles: 35        address: 887
162      byte: 64        cycles: 6       total cycles: 35        address: 888
211      byte: 65        cycles: 6       total cycles: 35        address: 889

32       byte: 66        cycles: 6       total cycles: 41        address: 890
215      byte: 67        cycles: 6       total cycles: 41        address: 891
221      byte: 68        cycles: 6       total cycles: 41        address: 892

169      byte: 69        cycles: 2       total cycles: 43        address: 893
13       byte: 70        cycles: 2       total cycles: 43        address: 894

32       byte: 71        cycles: 6       total cycles: 49        address: 895
210      byte: 72        cycles: 6       total cycles: 49        address: 896
255      byte: 73        cycles: 6       total cycles: 49        address: 897

173      byte: 74        cycles: 4       total cycles: 53        address: 898
56       byte: 75        cycles: 4       total cycles: 53        address: 899
3        byte: 76        cycles: 4       total cycles: 53        address: 900

24       byte: 77        cycles: 2       total cycles: 55        address: 901

109      byte: 78        cycles: 4       total cycles: 59        address: 902
56       byte: 79        cycles: 4       total cycles: 59        address: 903
3        byte: 80        cycles: 4       total cycles: 59        address: 904

168      byte: 81        cycles: 2       total cycles: 61        address: 905

32       byte: 82        cycles: 6       total cycles: 67        address: 906
162      byte: 83        cycles: 6       total cycles: 67        address: 907
211      byte: 84        cycles: 6       total cycles: 67        address: 908

32       byte: 85        cycles: 6       total cycles: 73        address: 909
215      byte: 86        cycles: 6       total cycles: 73        address: 910
221      byte: 87        cycles: 6       total cycles: 73        address: 911

169      byte: 88        cycles: 2       total cycles: 75        address: 912
13       byte: 89        cycles: 2       total cycles: 75        address: 913

32       byte: 90        cycles: 6       total cycles: 81        address: 914
210      byte: 91        cycles: 6       total cycles: 81        address: 915
255      byte: 92        cycles: 6       total cycles: 81        address: 916

169      byte: 93        cycles: 2       total cycles: 83        address: 917
255      byte: 94        cycles: 2       total cycles: 83        address: 918

141      byte: 95        cycles: 4       total cycles: 87        address: 919
56       byte: 96        cycles: 4       total cycles: 87        address: 920
3        byte: 97        cycles: 4       total cycles: 87        address: 921

172      byte: 98        cycles: 4       total cycles: 91        address: 922
56       byte: 99        cycles: 4       total cycles: 91        address: 923
3        byte: 100       cycles: 4       total cycles: 91        address: 924

32       byte: 101       cycles: 6       total cycles: 97        address: 925
162      byte: 102       cycles: 6       total cycles: 97        address: 926
211      byte: 103       cycles: 6       total cycles: 97        address: 927

32       byte: 104       cycles: 6       total cycles: 103       address: 928
215      byte: 105       cycles: 6       total cycles: 103       address: 929
221      byte: 106       cycles: 6       total cycles: 103       address: 930

loop
76       byte: 107       cycles: 3       total cycles: 106       address: 931
label    byte: 108       cycles: 3       total cycles: 106       address: 932
loop     byte: 109       cycles: 3       total cycles: 106       address: 933

....................................................................................................
building...
....................................................................................................
Include start address for
   var test?
     y=yes
     n=no
y
....................................................................................................
building var test
....................................................................................................
[56, 3, 5, 76, 100, 3, 147, 144, 86, 65, 82, 73, 65, 66, 76, 69, 32, 84, 69, 83, 84, 13, 56, 45, 66, 73, 84, 32, 85, 78, 83, 73, 71, 78, 69, 68, 13, 73, 78, 84, 69, 71, 69, 82, 13, 0, 160, 0, 185, 60, 3, 201, 0, 240, 7, 32, 210, 255, 200, 184, 80, 242, 172, 56, 3, 32, 162, 211, 32, 215, 221, 169, 13, 32, 210, 255, 173, 56, 3, 24, 109, 56, 3, 168, 32, 162, 211, 32, 215, 221, 169, 13, 32, 210, 255, 169, 255, 141, 56, 3, 172, 56, 3, 32, 162, 211, 32, 215, 221, 76, 163, 3]
....................................................................................................
saving var test.prg
var test.prg saved
build complete!
R'zo
I do not believe in obsolete...
Post Reply