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)
and you can see it running in an emulator here
http://www.youtube.com/watch?v=5fyrwUIIZqUI 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:
;***************************************************************************
; 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
;***************************************************************************