Beginner Needs Help in 6809 code, but 6502 is fine too!

Programming the 6502 microprocessor and its relatives in assembly and other languages.
User avatar
Dr Jefyll
Posts: 3526
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: Beginner Needs Help in 6809 code, but 6502 is fine too!

Post by Dr Jefyll »

Thanks to the link Ed provided, I've been able to examine the Vectrex ramp-generation circuits, which I find to be delightfully sparse and elegant. Here is the Block Diagram (stitched together and annotated from pages of the pdf file):
schem.gif
This brings me back to my original supposition that, at the lowest level, the interface to the Vectrex accepts an X and a Y speed command from the CPU for each move of the dot (ie, the CRT's electron beam). In my previous post I assumed the Vectrex used coordinate-based commands, as apparently used by Cinematronics; I've since edited that post.

Referring to the Block Diagram, the signal ZERO can be used to discharge the integrator capacitors, returning the dot to 0,0 (screen center) and thus providing an initial reference. Except for this "calibration," the dot travels point-to-point in a series of relative motions. For each individual motion, a Y value from the DAC is latched into the Y Sample & Hold, after which the (unlatched) X value is written to the DAC. Then the CPU triggers timer 1 of the 6522 VIA, thus asserting the RAMP signal. For a controlled time interval, the integrators slew positive or negative at a rate proportional to the respective signed values of X and Y. At the end of the interval the dot freezes indefinitely; the integrator cap's "remember" the dot position until the next motion commences. (However, the calibration step would need to be repeated occasionally.)
Finn wrote:
the slower you move the beam the brighter or thicker the line, because it dwells longer on the screen.
Yes, exactly. But also: it is the X and Y speeds which, relative to one another, determine the direction (slope) for the line that's drawn. The line length is determined by speed and by the time interval. (At least that's how I see it; comments & corrections on any of this are welcome.)
Quote:
I dont know the exact hardware details because i am using BIOS functions to move the beam.
That totally makes sense -- for what you're doing you need to direct your attention to the BIOS calls. Others (like me) can't rest until they've grokked the hardware interface. :D

cheers
Jeff
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: Beginner Needs Help in 6809 code, but 6502 is fine too!

Post by BigEd »

Thanks for putting that diagram together! There are some official and unofficial docs here:
http://www.playvectrex.com/designit_f.htm
Cheers
Ed
Finn
Posts: 11
Joined: 05 Nov 2012

Re: Beginner Needs Help in 6809 code, but 6502 is fine too!

Post by Finn »

Dr Jefyll wrote:
That totally makes sense -- for what you're doing you need to direct your attention to the BIOS calls. Others (like me) can't rest until they've grokked the hardware interface. :D
haha yes i have no idea what you guys are talking about now ;)

I did look into the source code for Thrust and it seems that he (the author) does reset the vector beam to 0,0 before drawing most objects, although there are a couple he does relative. He has has also rewritten the bios function that moves the beam, and taken a delay out. No one seems to know why the delay is there (I read about this elsewhere on the net before) and since Thrust seems to run ok, it's obviously not necessary.

Something interesting is the vectrex beam drifts out of position so you would need to reset it anyway at some point even if you could somehow draw all objects relative to each other. The guy who wrote my tutorial says the beam on his Vectrex drifts about a 1cm every 10,0000 cycles. (there are 30,000 cycles in a frame assuming 50fps update)
Finn
Posts: 11
Joined: 05 Nov 2012

Re: Beginner Needs Help in 6809 code, but 6502 is fine too!

Post by Finn »

Thanks to everyone who helped me in this thread. I have finally written my first Vectrex Program now. It bounces 20 squares and 20 dots around the screen. Since I am new to all this it took me a while to actually understand what I was doing, and i had to overcome quite a lot of problems, but I got there in the end

Here is a screen shot (running in an emulator)

Image

and you can see it running in an emulator here

http://www.youtube.com/watch?v=5fyrwUIIZqU

I tried to record the best quality video i could but my video-recording software didn't really like the line graphics (it looks like the screen shot normally - not all shimmery like it does in the video) or the flashing text at the start . Also normally it runs totally smoothly but having the video-recording software running slowed it down a bit.

I havent optimised or looked for duplication in the program yet (I'm sure there is some appalling programming in here, also Xman,Yman,Xv,Yv are no longer used) I was more concerned with actually getting it to run but here is the source code in case anyone else wants an easy way in to making Vectrex programs. The print routine was used for debugging, but not in the actual program

(this program is laid-out fine in notepad and here, but some lines move out of aligment when i actually publish the post. sorry)

Code: Select all

;***************************************************************************
; DEFINE SECTION
;***************************************************************************
                INCLUDE "VectBiosAdd.asm"		; vectrex function includes (BIOS Functions)
		INCLUDE	"RichMacros.asm"		;Macro File (not used in this program now)
;		
; start of vectrex memory with cartridge name...

;**************** ROUTINES

m_3 macro max,digit    ;Ville Krumlinde's routine to convert a binary number into decimal, must be less than 100
  cmpb #max-1
  bls tpd\1
  subb #max
  addb #'0'
  lda #'digit'
  std ,U
  bra tlsExit2
tpd\1:
  endm

;NOTE BIOS routines : Print_str_d trashes X REg, Wait_recal does too, intensity trashes D only


               ORG     0
;***************************************************************************
; HEADER SECTION
;***************************************************************************
                DB      "g GCE 2013", $80       ; 'g' is copyright sign
                DW      music1                  ; music from the rom
                DB      $F8, $50, $20, -$56     ; height, width, rel y, rel x
                                                ; (from 0,0)
                DB      "SQUARE ATTACK!!",$80        ; some game information,
                                                ; ending with $80
                DB      0                       ; end of game header

;***************************************************************************
; CODE SECTION
;***************************************************************************
; here the cartridge program starts off

main:
		LDA 	#0
		STA 	XMan
		STA	YMan
		STA	Yv
		LDA	#1
		STA	Xv

		LDA	#1
		STA	dl1
		LDA	#40
		STA	dl2

;move dot list to RAM (can't be chanaged while in ROM)

		
		LDB	#79	
		LDX 	#Objects
		LDY	#ObjectList

memloop	LDA	B,Y
		STA	B,X
		DECB
		BPL	memloop
		
		
loop:          		
		JSR     Wait_Recal              ; Vectrex BIOS recalibration
             
		LDX	#Objects		;Base address of dotlist in RAM, each entry is a byte
		LDY 	,X++			;Number of Objects into Y, Base address of Object list in RAM into X also increment X by a word so on next item
		
		STX	tempX			;Store X in temporary variable because a lot of BIOS routines use X register
		
ListLoop:		
;----------  MOVE OBJECTS
;---------- X Limits
		LDX 	tempX
		LDA	,X			;xposition of object to A
		ADDA	2,X			;add x-vector to A
		
		CMPA	#XLIM		;check if hits right side of screen
		BLE	chk2			
		LDA	#XLIM
		BRA	SetX
chk2:
		CMPA	#-XLIM              ;check if hits left side of screen
		BGE	fin
		LDA	#-XLIM
		
SetX:
		NEG	2,X			;two's complement X-vector (negate it)
fin:
		STA	,X			;store new X position

;---- Y limits
		LDA	1,X			;y position of object in A
		ADDA	3,X			;add yv to y position
		
		CMPA	#YLIM		;check if hits top of screen
		BLE	chk2y			
		LDA	#YLIM
		BRA	SetY
chk2y:
		CMPA	#-YLIM              ;check if hits bottom of screen
		BGE	finy
		LDA	#-YLIM
		
SetY:
		NEG	3,X			;two's complement XV
finy:
		STA	1,X

		LDX tempX
		
		
		LDA     #$7F            ;Set scale factor to $7F
                STA     <VIA_t1_cnt_lo

;---------------DRAW DOTS
		
		JSR	Intensity_7F		;brightest intensity for dots
		;LDA     #$F4                   ;Init dot dwell (brightness)
                ;STA     <Vec_Dot_Dwell
		LDX 	tempX
		
		
		JSR	Reset0Ref		;Reset pen to origin
		LDA     1,X	                ; relative Y position 
                LDB     ,X                   	; relative X position 
                                               ; register D = 256*A+B
		NEGA				;Dot positions are positioned at the inverted positions of the squares
		NEGB
                JSR     Moveto_d  		;move to position specified in 
						; d register
                JSR     Dot_here                ; Plot a dot at this position

;---------------DRAW SQUARES 

		;LDA     #$05            ;Init dot dwell (brightness)
                ;STA     <Vec_Dot_Dwell 

		JSR	Reset0Ref
		LDX	tempX
		
                LDA     1,X                      ; set y
                LDB     ,X                      ; set x
		
                JSR     Moveto_d                ; move the vector beam the
                                                ; relative position
		LDA     #$10                    ; scaling factor of $10 to A
                STA     VIA_t1_cnt_lo           ; move to time 1 lo, this
                                                ; means scaling
                JSR     Intensity_5F            ; Sets the intensity of the
                                                ; vector beam to $5f
                LDX     #square_line_list       ; load the address of the to be
                                                ; drawn vector list to X
                JSR     Draw_VLc                ; draw the shape 
                 
;------------
		LDX	tempX			;Retrieve X
		LEAX	4,X			;move to next item in list
		STX	tempX
		

		LEAY 	-1,Y			;Dec Y (number of items)
		BNE	ListLoop


;		LDY	#1			;Delay routine, uncomment to slow program down
;delay2:		
;		LDX	#25			
;delay:		LEAX	-1,X
;		BNE	delay
;		LEAY	-1,Y
;		BNE	delay2
		
                BRA     loop			; and repeat forever

Print_Text:					;Print text A=Text position relative Y  B=Text position relative X
		JSR     Text_ConvertX2		;Convert binary number to decimal
		JSR	Reset0Ref		
                JSR     Print_Str_d             ; Vectrex BIOS print routine
		RTS

Text_ConvertX2:           ;x holds value to be converted (max 99), u = destination buffer-2 (2 bytes needed)

tlsBelow100:

  m_3 90,9
  m_3 80,8
  m_3 70,7
  m_3 60,6
  m_3 50,5
  m_3 40,4
  m_3 30,3
  m_3 20,2
  m_3 10,1

  LDA#'0'
  ADDB #'0'
  STD ,U

tlsExit2:

	LDB	#$80             ;add end byte
	STB	2,U
	
  RTS


;***************************************************************************
; DATA SECTION
;***************************************************************************

XLIM		EQU	80
YLIM		EQU	122
XMan		EQU	$C880
YMan		EQU	$C881
Xv		EQU	$C882
Yv		EQU	$C883
dl1		EQU	$C884
dl2		EQU	$C885
temp_string	EQU	$C886
tempX		EQU	$C887 			;(allow 2 bytes to store X)
Objects		EQU	$C899			; store dotlist in RAM here so it can be altered
						         ; ROM cannot be written to!
User		EQU	$CAB9			;User Stack
ObjectList:
                
		DB 0,20                           ; number of objects (word, 2 bytes)
                DB  20,-20,-2,2
		DB  -20,-10,1,-2
		DB 10,10,-1,1
		DB -20,20,2,-1
		DB -40,30,3,1
		DB 40,-30,-2,-3
		DB 30,40,2,2
		DB 60,-20,1,3
		DB 35,-15,4,2
		DB -35,15,2,3
		DB 10,70,-1,-1
		DB -10,-70,2,1
		DB -5,16,1,3
		DB 5,19,4,1
		DB 12,-12,-3,-2
		DB 35,-14,-1,1
		DB 12,20,2,3
		DB -10,-10,2,-2
		DB 30,30,-3,-1
		DB -28,-26,-2,-2

SPRITE_BLOW_UP EQU 35
square_line_list:
                DB 3                           ; number of vectors - 1
                DB  2*SPRITE_BLOW_UP,  0*SPRITE_BLOW_UP
		DB  0*SPRITE_BLOW_UP,  2*SPRITE_BLOW_UP
		DB  -2*SPRITE_BLOW_UP,  0*SPRITE_BLOW_UP
		DB  0*SPRITE_BLOW_UP,  -2*SPRITE_BLOW_UP
;***************************************************************************
                END  main
;***************************************************************************
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: Beginner Needs Help in 6809 code, but 6502 is fine too!

Post by BigEd »

Great! Always good to see a "Hello World" program, although in this case it's all boxes...
Finn
Posts: 11
Joined: 05 Nov 2012

Re: Beginner Needs Help in 6809 code, but 6502 is fine too!

Post by Finn »

BigEd wrote:
Great! Always good to see a "Hello World" program, although in this case it's all boxes...
thank you BigEd :) Don't forget the dots, those boxes get all the attention...
Post Reply