6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Tue Sep 24, 2024 12:23 pm

All times are UTC




Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Sat Nov 10, 2012 11:13 pm 
Offline

Joined: Mon Nov 05, 2012 4:40 pm
Posts: 11
White Flame wrote:
Finn wrote:
EDIT: I think i have got that AND wrong. what should it be to detect 32 or -32? is this possible?


It's true that if AND #$1f is zero, then it's exactly a multiple of 32, including negatives. However, zero is also a multiple of 32.

One of the shortest ways I can think of to do a range test is this:

Code:
; Pseudo arch
add #32
cmp #65
bcs outOfBounds

Offset the value from -32,+32 range to 0,64, and do an unsigned comparison (branch if >= 65). If it were -32,+31, then you'd be able to do bit masking here, but it still comes out to the same number of instructions.


Thanks White Flame, i realised mine was detecting zero last night, i think i could do it with an extra bit operation though like you say . Yours looks good! i dont quite understand it yet. I understand the changing the range to 0 to 64. going to get a piece of paper out and go through it...

Dr Jefyll wrote:
There does seem to be some confusion. The Wikipedia article says, "The vector generator is an all analog design using two integrators: X and Y. The computer sets the integration rates using a digital-to-analog converter. [...] Voltage ramps are produced that the monitor uses to steer the electron-beam over the face of the phosphor screen of the cathode ray tube." To me this says the commands from the CPU aren't relative or absolute coordinates for the dot on the CRT, but instead specify signed speeds for the dot -- its rate of motion in the X and Y axes. For example (dealing just with the X axis), a command of 5 might cause moderate motion in one direction, and a command of -20 would cause rapid motion in the opposite direction. Of course there's got to be more to it than that. For one thing there'd have to be some sort of absolute reference (perhaps zeroing the dot to screen center) before all the motions begin. But understanding this integrator (ramp generator) business sounds like a crucial piece of the puzzle.


Well i think you are quite close. I dont know the exact hardware details because i am using BIOS functions to move the beam. Most of the functions seem to move it relative to the previous position which does make sense from a hardware point of view. The tutorial i was going through said some of the functions were absolute but i suspect like you say that these reset the vector beam position to zero first anyway. All i know so far is there is a speed to the beam and also time, and the slower you move the beam the brighter or thicker the line, because it dwells longer on the screen. There is a bios dissassembly i printed off and it shows you exactly what is going on, but i have only glanced over it so far. I am going to check out what Ville Krumlindee did in his Thrust program. In a way its a shame there isn't some kind of hardware chip to move the beam independent of the 6809 because it must use up a lot of processor cycles moving it about and delaying it in places. but i suppose this way is simpler

My Weapons (Thrust source code and a 6809 book)


Image


Dr Jefyll wrote:
what seems to be the problem with your Vectrex (which you describe as "in the process of breaking")?


It doesnt seem to detect the '1' button on controller 1, which starts the games in most cases. Its weird because if i can get it to work then this button seems to work fine in the game. e.g if it's used for shooting or thrusting. I have 2 controllers so i have tried them both and have the same problem so i assume its a problem in the vectrex. Also the volume knob crackles at certain positions and you can't always get sound in certain positions. I think that will get worse over time. these are probably simple things to fix for someone who knows hardware but i have no idea how to fix anything, unless its a (very) simple solder-job. I used to have a second vectrex which was mint condition but i sold it for space reasons, wish i had kept hold of it now.

Thanks for all the help everyone!


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 11, 2012 3:54 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
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):
Attachment:
schem.gif
schem.gif [ 101.68 KiB | Viewed 1120 times ]
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


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 11, 2012 8:49 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Thanks for putting that diagram together! There are some official and unofficial docs here:
http://www.playvectrex.com/designit_f.htm
Cheers
Ed


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 12, 2012 9:54 pm 
Offline

Joined: Mon Nov 05, 2012 4:40 pm
Posts: 11
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)


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 16, 2013 5:20 pm 
Offline

Joined: Mon Nov 05, 2012 4:40 pm
Posts: 11
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:
;***************************************************************************
; 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
;***************************************************************************


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 16, 2013 6:29 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Great! Always good to see a "Hello World" program, although in this case it's all boxes...


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 17, 2013 8:52 pm 
Offline

Joined: Mon Nov 05, 2012 4:40 pm
Posts: 11
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...


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 35 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: